diff --git a/.travis.yml b/.travis.yml index 22ba9fecbab..f55cd23512d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,8 +11,8 @@ env: # to boost's .tar.gz. - LCOV_ROOT=$HOME/lcov - GDB_ROOT=$HOME/gdb - - BOOST_ROOT=$HOME/boost_1_60_0 - - BOOST_URL='http://sourceforge.net/projects/boost/files/boost/1.60.0/boost_1_60_0.tar.gz' + - BOOST_ROOT=$HOME/boost_1_66_0 + - BOOST_URL='http://sourceforge.net/projects/boost/files/boost/1.66.0/boost_1_66_0.tar.gz' # Travis is timing out on Trusty. So, for now, use Precise. July 2017 dist: precise diff --git a/Builds/CMake/CMakeFuncs.cmake b/Builds/CMake/CMakeFuncs.cmake index 34cbc1dcc44..a629a120301 100644 --- a/Builds/CMake/CMakeFuncs.cmake +++ b/Builds/CMake/CMakeFuncs.cmake @@ -357,6 +357,12 @@ macro(use_boost) if(NOT Boost_FOUND) message(WARNING "Boost directory found, but not all components. May not be able to build.") endif() + if(MSVC14) + # VS2017 with boost <= 1.66.0 requires a flag to suppress warnings + if(NOT Boost_VERSION VERSION_GREATER 106600) + add_definitions(-DBOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE) + endif() + endif() include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) link_directories(${Boost_LIBRARY_DIRS}) else() @@ -383,9 +389,13 @@ macro(use_openssl openssl_min) endif() if (WIN32) - if (DEFINED ENV{OPENSSL_ROOT}) - include_directories($ENV{OPENSSL_ROOT}/include) - link_directories($ENV{OPENSSL_ROOT}/lib) + if ((NOT DEFINED OPENSSL_ROOT) AND (DEFINED ENV{OPENSSL_ROOT})) + set(OPENSSL_ROOT $ENV{OPENSSL_ROOT}) + endif() + file(TO_CMAKE_PATH "${OPENSSL_ROOT}" OPENSSL_ROOT) + if (DEFINED OPENSSL_ROOT) + include_directories(${OPENSSL_ROOT}/include) + link_directories(${OPENSSL_ROOT}/lib) endif() else() if (static) diff --git a/Builds/VisualStudio2015/RippleD.vcxproj b/Builds/VisualStudio2015/RippleD.vcxproj index 5e0e2db0d40..1cf57dded6b 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj +++ b/Builds/VisualStudio2015/RippleD.vcxproj @@ -87,7 +87,7 @@ HAVE_USLEEP=1;SOCI_CXX_C11=1;_WIN32_WINNT=0x6000;BOOST_COROUTINES_NO_DEPRECATION_WARNING;BOOST_COROUTINE_NO_DEPRECATION_WARNING;BOOST_NO_AUTO_PTR;DEBUG;DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER;NOMINMAX;OPENSSL_NO_SSL2;WIN32_CONSOLE;_CRTDBG_MAP_ALLOC;_CRT_SECURE_NO_WARNINGS;_DEBUG;_SCL_SECURE_NO_WARNINGS;_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS;%(PreprocessorDefinitions) - ..\..\build\proto;..\..\src;..\..\src\beast;..\..\src\beast\extras;..\..\src\beast\include;..\..\src\nudb\include;..\..\src\protobuf\src;..\..\src\protobuf\vsprojects;..\..\src\soci\include;..\..\src\soci\src;%(AdditionalIncludeDirectories) + ..\..\build\proto;..\..\src;..\..\src\beast;..\..\src\beast\extras;..\..\src\nudb\include;..\..\src\protobuf\src;..\..\src\protobuf\vsprojects;..\..\src\soci\include;..\..\src\soci\src;%(AdditionalIncludeDirectories) 4800;4244;4267;4503;4018 Async MultiThreadedDebug @@ -124,7 +124,7 @@ HAVE_USLEEP=1;SOCI_CXX_C11=1;_WIN32_WINNT=0x6000;BOOST_COROUTINES_NO_DEPRECATION_WARNING;BOOST_COROUTINE_NO_DEPRECATION_WARNING;BOOST_NO_AUTO_PTR;DEBUG;DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER;NOMINMAX;OPENSSL_NO_SSL2;WIN32_CONSOLE;_CRTDBG_MAP_ALLOC;_CRT_SECURE_NO_WARNINGS;_DEBUG;_SCL_SECURE_NO_WARNINGS;_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS;%(PreprocessorDefinitions) - ..\..\build\proto;..\..\src;..\..\src\beast;..\..\src\beast\extras;..\..\src\beast\include;..\..\src\nudb\include;..\..\src\protobuf\src;..\..\src\protobuf\vsprojects;..\..\src\soci\include;..\..\src\soci\src;%(AdditionalIncludeDirectories) + ..\..\build\proto;..\..\src;..\..\src\beast;..\..\src\beast\extras;..\..\src\nudb\include;..\..\src\protobuf\src;..\..\src\protobuf\vsprojects;..\..\src\soci\include;..\..\src\soci\src;%(AdditionalIncludeDirectories) 4800;4244;4267;4503;4018 Async MultiThreadedDebug @@ -161,7 +161,7 @@ HAVE_USLEEP=1;SOCI_CXX_C11=1;_WIN32_WINNT=0x6000;BOOST_COROUTINES_NO_DEPRECATION_WARNING;BOOST_COROUTINE_NO_DEPRECATION_WARNING;BOOST_NO_AUTO_PTR;DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER;NDEBUG;NOMINMAX;OPENSSL_NO_SSL2;WIN32_CONSOLE;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS;%(PreprocessorDefinitions) - ..\..\build\proto;..\..\src;..\..\src\beast;..\..\src\beast\extras;..\..\src\beast\include;..\..\src\nudb\include;..\..\src\protobuf\src;..\..\src\protobuf\vsprojects;..\..\src\soci\include;..\..\src\soci\src;%(AdditionalIncludeDirectories) + ..\..\build\proto;..\..\src;..\..\src\beast;..\..\src\beast\extras;..\..\src\nudb\include;..\..\src\protobuf\src;..\..\src\protobuf\vsprojects;..\..\src\soci\include;..\..\src\soci\src;%(AdditionalIncludeDirectories) 4800;4244;4267;4503;4018 Async Precise @@ -196,7 +196,7 @@ HAVE_USLEEP=1;SOCI_CXX_C11=1;_WIN32_WINNT=0x6000;BOOST_COROUTINES_NO_DEPRECATION_WARNING;BOOST_COROUTINE_NO_DEPRECATION_WARNING;BOOST_NO_AUTO_PTR;DEPRECATED_IN_MAC_OS_X_VERSION_10_7_AND_LATER;NDEBUG;NOMINMAX;OPENSSL_NO_SSL2;WIN32_CONSOLE;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS;%(PreprocessorDefinitions) - ..\..\build\proto;..\..\src;..\..\src\beast;..\..\src\beast\extras;..\..\src\beast\include;..\..\src\nudb\include;..\..\src\protobuf\src;..\..\src\protobuf\vsprojects;..\..\src\soci\include;..\..\src\soci\src;%(AdditionalIncludeDirectories) + ..\..\build\proto;..\..\src;..\..\src\beast;..\..\src\beast\extras;..\..\src\nudb\include;..\..\src\protobuf\src;..\..\src\protobuf\vsprojects;..\..\src\soci\include;..\..\src\soci\src;%(AdditionalIncludeDirectories) 4800;4244;4267;4503;4018 Async Precise @@ -264,258 +264,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Builds/VisualStudio2015/RippleD.vcxproj.filters b/Builds/VisualStudio2015/RippleD.vcxproj.filters index 90f32e1ee82..7e847ccbc38 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2015/RippleD.vcxproj.filters @@ -7,24 +7,6 @@ {6DD9EDCB-63DB-D377-3F12-12825FA8437E} - - {3CBEFECB-9A7C-B235-BA05-30D41AB8827D} - - - {79EFD023-52CA-3A59-E21D-E73328FA46EA} - - - {2A1F4F78-5521-936E-8CE2-BA798D578A14} - - - {7138D215-DA65-98D5-EF7D-C9896685201E} - - - {3E84AA4C-CB48-99F0-EB35-5603FF633A51} - - - {932F732F-F09E-5C50-C8A1-D62342CCAA1F} - {0ED4CDBE-296D-2599-04B3-095BFD1668A4} @@ -34,24 +16,6 @@ {AC49CD8A-C2A7-FBEC-CA36-635A5303E73E} - - {D05C2DB7-CE99-9326-23E6-4C7828632E0E} - - - {FB0BEDED-4C83-F0AF-0450-3DB01A05BD0B} - - - {A7FC9CC0-AB8D-4252-CCB2-B67F7BE99CF5} - - - {9455431B-BD48-F8C8-B53B-D9BCAF355341} - - - {508136FB-F124-7376-5A6F-F28EDEB18389} - - - {F85F4A52-7A2A-700C-4804-97FFC11E99FD} - {9DEED977-2072-A182-5BD9-CEBF206E8C91} @@ -585,384 +549,6 @@ beast\unit_test - - beast - - - beast\core - - - beast\core - - - beast\core - - - beast\core - - - beast\core - - - beast\core - - - beast\core\detail - - - beast\core\detail - - - beast\core\detail - - - beast\core\detail - - - beast\core\detail - - - beast\core\detail - - - beast\core\detail - - - beast\core\detail - - - beast\core\detail - - - beast\core\detail - - - beast\core\detail - - - beast\core\detail - - - beast\core\detail - - - beast\core\detail - - - beast\core - - - beast\core - - - beast\core - - - beast\core - - - beast\core - - - beast\core - - - beast\core - - - beast\core - - - beast\core\impl - - - beast\core\impl - - - beast\core\impl - - - beast\core\impl - - - beast\core\impl - - - beast\core\impl - - - beast\core\impl - - - beast\core\impl - - - beast\core\impl - - - beast\core\impl - - - beast\core\impl - - - beast\core\impl - - - beast\core\impl - - - beast\core - - - beast\core - - - beast\core - - - beast\core - - - beast\core - - - beast\core - - - beast\core - - - beast\core - - - beast\core - - - beast - - - beast\http - - - beast\http - - - beast\http\detail - - - beast\http\detail - - - beast\http\detail - - - beast\http\detail - - - beast\http\detail - - - beast\http - - - beast\http - - - beast\http - - - beast\http - - - beast\http - - - beast\http - - - beast\http\impl - - - beast\http\impl - - - beast\http\impl - - - beast\http\impl - - - beast\http\impl - - - beast\http\impl - - - beast\http\impl - - - beast\http\impl - - - beast\http\impl - - - beast\http\impl - - - beast\http\impl - - - beast\http\impl - - - beast\http\impl - - - beast\http - - - beast\http - - - beast\http - - - beast\http - - - beast\http - - - beast\http - - - beast\http - - - beast\http - - - beast\http - - - beast\http - - - beast\http - - - beast\http - - - beast - - - beast - - - beast\websocket\detail - - - beast\websocket\detail - - - beast\websocket\detail - - - beast\websocket\detail - - - beast\websocket\detail - - - beast\websocket\detail - - - beast\websocket\detail - - - beast\websocket - - - beast\websocket\impl - - - beast\websocket\impl - - - beast\websocket\impl - - - beast\websocket\impl - - - beast\websocket\impl - - - beast\websocket\impl - - - beast\websocket\impl - - - beast\websocket\impl - - - beast\websocket\impl - - - beast\websocket\impl - - - beast\websocket\impl - - - beast\websocket - - - beast\websocket - - - beast\websocket - - - beast\websocket - - - beast\websocket - - - beast\zlib - - - beast\zlib\detail - - - beast\zlib\detail - - - beast\zlib\detail - - - beast\zlib\detail - - - beast\zlib\detail - - - beast\zlib - - - beast\zlib\impl - - - beast\zlib - - - beast\zlib - ed25519-donna diff --git a/Builds/VisualStudio2017/CMakeSettings-example.json b/Builds/VisualStudio2017/CMakeSettings-example.json new file mode 100644 index 00000000000..b2889ddf504 --- /dev/null +++ b/Builds/VisualStudio2017/CMakeSettings-example.json @@ -0,0 +1,45 @@ +{ + // See https://go.microsoft.com//fwlink//?linkid=834763 for more information about this file. + "configurations": [ + { + "name": "x64-Debug", + "generator": "Visual Studio 15 2017 Win64", + "configurationType": "Debug", + "inheritEnvironments": [ "msvc_x64_x64" ], + "buildRoot": "${thisFileDir}\\build\\${name}", + "cmakeCommandArgs": "", + "buildCommandArgs": "-v:minimal", + "ctestCommandArgs": "", + "variables": [ + { + "name": "BOOST_ROOT", + "value": "C:\\lib\\boost" + }, + { + "name": "OPENSSL_ROOT", + "value": "C:\\lib\\OpenSSL-Win64" + } + ] + }, + { + "name": "x64-Release", + "generator": "Visual Studio 15 2017 Win64", + "configurationType": "Release", + "inheritEnvironments": [ "msvc_x64_x64" ], + "buildRoot": "${thisFileDir}\\build\\${name}", + "cmakeCommandArgs": "", + "buildCommandArgs": "-v:minimal", + "ctestCommandArgs": "", + "variables": [ + { + "name": "BOOST_ROOT", + "value": "C:\\lib\\boost" + }, + { + "name": "OPENSSL_ROOT", + "value": "C:\\lib\\OpenSSL-Win64" + } + ] + } + ] +} diff --git a/Builds/VisualStudio2017/README.md b/Builds/VisualStudio2017/README.md new file mode 100644 index 00000000000..38c32036329 --- /dev/null +++ b/Builds/VisualStudio2017/README.md @@ -0,0 +1,263 @@ +# Visual Studio 2017 Build Instructions + +## Important + +We do not recommend Windows for rippled production use at this time. Currently, +the Ubuntu platform has received the highest level of quality assurance, +testing, and support. Additionally, 32-bit Windows versions are not supported. + +## Prerequisites + +To clone the source code repository, create branches for inspection or +modification, build rippled under Visual Studio, and run the unit tests you will +need these software components + +| Component | Minimum Recommended Version | +|-----------|-----------------------| +| [Visual Studio 2017](README.md#install-visual-studio-2017)| 15.5.4 | +| [Git for Windows](README.md#install-git-for-windows)| 2.16.1| +| [Google Protocol Buffers Compiler](README.md#install-google-protocol-buffers-compiler) | 2.5.1| +| [OpenSSL Library](README.md#install-openssl) | 1.0.2n | +| [Boost library](README.md#build-boost) | 1.66.0 | +| [CMake for Windows](README.md#optional-install-cmake-for-windows)* | 3.10.2 | + +\* Only needed if not using the integrated CMake in VS 2017 and prefer generating dedicated project/solution files. + +## Install Software + +### Install Visual Studio 2017 + +If not already installed on your system, download your choice of installer from +the [Visual Studio 2017 +Download](https://www.visualstudio.com/downloads/download-visual-studio-vs) +page, run the installer, and follow the directions. **You may need to choose the +`Desktop development with C++` workload to install all necessary C++ features.** + +Any version of Visual Studio 2017 may be used to build rippled. The **Visual +Studio 2017 Community** edition is available free of charge (see [the product +page](https://www.visualstudio.com/products/visual-studio-community-vs) for +licensing details), while paid editions may be used for an initial free-trial +period. + +### Install Git for Windows + +Git is a distributed revision control system. The Windows version also provides +the bash shell and many Windows versions of Unix commands. While there are other +varieties of Git (such as TortoiseGit, which has a native Windows interface and +integrates with the Explorer shell), we recommend installing [Git for +Windows](https://git-scm.com/) since it provides a Unix-like command line +environment useful for running shell scripts. Use of the bash shell under +Windows is mandatory for running the unit tests. + +### Install Google Protocol Buffers Compiler + +Building rippled requires **protoc.exe** version 2. Version 3 is not currently +supported.. At your option you may build it yourself from the sources in the +[Google Protocol Buffers](https://github.com/google/protobuf) repository, or you +may download a +[protoc.exe](https://ripple.github.io/Downloads/protoc/2.5.1/protoc.exe) +([alternate +link](https://github.com/ripple/Downloads/raw/gh-pages/protoc/2.5.1/protoc.exe)) +precompiled Windows executable from the [Ripple +Organization](https://github.com/ripple). + +Either way, once you have the required version of **protoc.exe**, copy it into a +standard location that is in your command line `%PATH%`. + +* **NOTE:** If you use an older version of the compiler, the build will fail + with errors related to a mismatch of the version of protocol buffer headers + versus the compiler. Likewise, if you use version 3 or newer, the build will + fail. + +### Install OpenSSL + +[Download OpenSSL.](http://slproweb.com/products/Win32OpenSSL.html) There will +four `Win64` bit variants available, you want the non-light `v1.0` line. As of +this writing, you **should** select + +* Win64 OpenSSL v1.0.2n. + +and should **not** select + +* Win64 OpenSSL v1.0.2n light +* Win64 OpenSSL v1.1.0g +* Win64 OpenSSL v1.1.0g light + +Run the installer, and choose an appropriate location for your OpenSSL +installation. In this guide we use `C:\lib\OpenSSL-Win64` as the destination +location. + +You may be informed on running the installer that "Visual C++ 2008 +Redistributables" must first be installed first. If so, download it from the +[same page](http://slproweb.com/products/Win32OpenSSL.html), again making sure +to get the correct 32-/64-bit variant. + +* NOTE: Since rippled links statically to OpenSSL, it does not matter where the + OpenSSL .DLL files are placed, or what version they are. rippled does not use + or require any external .DLL files to run other than the standard operating + system ones. + +### Build Boost + +After [downloading boost](http://www.boost.org/users/download/) and unpacking it +to `c:\lib`. As of this writing, the most recent version of boost is 1.66.0, +which will unpack into a directory named `boost_1_66_0`. We recommended either +renaming this directory to `boost`, or creating a junction link `mklink /J boost +boost_1_66_0`, so that you can more easily switch between versions. + +Next, open **Developer Command Prompt** and type the following commands + +```powershell +cd C:\lib\boost +bootstrap +``` + +The rippled application is linked statically to the standard runtimes and +external dependencies on Windows, to ensure that the behavior of the executable +is not affected by changes in outside files. Therefore, it is necessary to build +the required boost static libraries using this command: + +```powershell +bjam -j --toolset=msvc-14.1 address-model=64 architecture=x86 link=static threading=multi runtime-link=shared,static stage +``` + +where you should replace `` with the number of parallel +invocations to use build, e.g. `bjam -j4 ...` would use up to 4 concurrent build +shell commands for the build. + +Building the boost libraries may take considerable time. When the build process +is completed, take note of both the reported compiler include paths and linker +library paths as they will be required later. + +### (Optional) Install CMake for Windows + +[CMake](http://cmake.org) is a cross platform build system generator. Visual +Studio 2017 includes an integrated version of CMake that avoids having to +manually run CMake, but it is undergoing continuous improvement. Users that +prefer to use standard Visual Studio project and solution files need to install +a dedicated version of Cmake to generate them. The latest version can be found +at the [CMake download site](https://cmake.org/download/). It is recommended you +select the install option to add CMake to your path. + +As of this writing, the latest version of CMake for windows is 3.10.2. + +## Clone the rippled repository + +If you are familiar with cloning github repositories, just follow your normal +process and clone `git@github.com:ripple/rippled.git`. Otherwise follow this +section for instructions. + +1. If you don't have a github account, sign up for one at + [github.com](https://github.com/). +2. Make sure you have Github ssh keys. For help see + [generating-ssh-keys](https://help.github.com/articles/generating-ssh-keys). + +Open the "Git Bash" shell that was installed with "Git for Windows" in the step +above. Navigate to the directory where you want to clone rippled (git bash uses +`/c` for windows's `C:` and forward slash where windows uses backslash, so +`C:\Users\joe\projs` would be `/c/Users/joe/projs` in git bash). Now clone the +repository and optionally switch to the *master* branch. Type the following at +the bash prompt: + +```powershell +git clone git@github.com:ripple/rippled.git +cd rippled +``` +If you receive an error about not having the "correct access rights" make sure +you have Github ssh keys, as described above. + +For a stable release, choose the `master` branch or one of the tagged releases +listed on [rippled's GitHub page](https://github.com/ripple/rippled/releases). + +``` +git checkout master +``` + +To test the latest release candidate, choose the `release` branch. + +``` +git checkout release +``` + +If you are doing development work and want the latest set of untested features, +you can consider using the `develop` branch instead. + +``` +git checkout develop +``` + +# Build using Visual Studio integrated CMake + +In Visual Studio 2017, Microsoft added [integrated IDE support for +cmake](https://blogs.msdn.microsoft.com/vcblog/2016/10/05/cmake-support-in-visual-studio/). +To begin, simply: + +1. Launch Visual Studio and choose **File | Open | Folder**, navigating to the + cloned rippled folder. +2. Right-click on `CMakeLists.txt` in the **Solution Explorer - Folder View** to + generate a `CMakeSettings.json` file. A sample settings file is provided + [here](/Builds/VisualStudio2017/CMakeSettings-example.json). Customize the + settings for `BOOST_ROOT`, `OPENSSL_ROOT` to match the install paths if they + differ from those in the file. +4. Select either the `x64-Release` or `x64-Debug` configuration from the + **Project Setings** drop-down. This should invoke the built-in CMake project + generator. If not, you can right-click on the `CMakeLists.txt` file and + choose **Cache | Generate Cache**. +5. Select either the `rippled.exe` (unity) or `rippled_classic.exe` (non-unity) + option in the **Select Startup Item** drop-down. This will be the target + built when you press F7. Alternatively, you can choose a target to build from + the top-level **CMake | Build** menu. Note that at this time, there are other + targets listed that come from third party visual studio files embedded in the + rippled repo, e.g. `datagen.vcxproj`. Please ignore them. + +For details on configuring debugging sessions or further customization of CMake, +please refer to the [CMake tools for VS +documentation](https://docs.microsoft.com/en-us/cpp/ide/cmake-tools-for-visual-cpp). + +If using the provided `CMakeSettings.json` file, the executable will be in +``` +.\build\x64-Release\Release\rippled(_classic).exe +``` +or +``` +.\build\x64-Debug\Debug\rippled(_classic).exe +``` +where these paths are relative to your cloned git repository. + +# Build using stand-alone CMake + +This requires having installed [CMake for +Windows](README.md#optional-install-cmake-for-windows). We do not recommend +mixing this method with the integrated CMake method for the same repository +clone. Assuming you included the cmake executable folder in your path, +execute the following commands within your `rippled` cloned repository: + +``` +mkdir build\cmake +cd build\cmake +cmake ..\.. -G"Visual Studio 15 2017 Win64" -DBOOST_ROOT="C:\lib\boost_1_66_0" -DOPENSSL_ROOT="C:\lib\OpenSSL-Win64" +``` +Now launch Visual Studio 2017 and select **File | Open | Project/Solution**. +Navigate to the `build\cmake` folder created above and select the `rippled.sln` +file. You can then choose whether to build the `Debug` or `Release` solution +configuration. Within the **Solution Explorer**, selected either the `rippled` +(unity build) project or the `rippled_classic` (non-unity) project, and +right-click to build. + +The executable will be in +``` +.\build\cmake\Release\rippled(_classic).exe +``` + or +```` +.\build\cmake\Debug\rippled(_classic).exe +```` +where these paths are relative to your cloned git repository. + +# Unit Test (Recommended) + +`rippled` builds a set of unit tests into the server executable. To run these +unit tests after building, pass the `--unittest` option to the compiled +`rippled` executable. The executable will exit with summary info after running +the unit tests. + diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f4c0ec722c..b4c9e5c5438 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,7 +130,6 @@ check_gcc4_abi() include_directories( src src/beast - src/beast/include src/beast/extras src/nudb/include src/soci/src diff --git a/Jenkinsfile b/Jenkinsfile index b2be9324b57..74dfa1cb13b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -127,6 +127,7 @@ try { withEnv(["CCACHE_BASEDIR=${cdir}", "CCACHE_NOHASHDIR=true", 'LCOV_ROOT=""', + 'BOOST_ROOT=/opt/local/boost_1_66_0', "TARGET=${target}", "CC=${compiler}", 'BUILD=cmake', diff --git a/SConstruct b/SConstruct index 4dfabdd3c18..4e1dd554876 100644 --- a/SConstruct +++ b/SConstruct @@ -806,7 +806,6 @@ config_base(base) base.Append(CPPPATH=[ 'src', os.path.join('src', 'beast'), - os.path.join('src', 'beast', 'include'), os.path.join('src', 'beast', 'extras'), os.path.join('src', 'nudb', 'include'), os.path.join(build_dir, 'proto'), diff --git a/appveyor.yml b/appveyor.yml index 0ee42c68764..9e3b40490d9 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -6,7 +6,7 @@ environment: # that it's a small download. We also use appveyor's free cache, avoiding fees # downloading from S3 each time. # TODO: script to create this package. - RIPPLED_DEPS_PATH: rippled_deps17.01 + RIPPLED_DEPS_PATH: rippled_deps17.02 RIPPLED_DEPS_URL: https://ripple.github.io/Downloads/appveyor/%RIPPLED_DEPS_PATH%.zip # Other dependencies we just download each time. diff --git a/src/beast/.gitattributes b/src/beast/.gitattributes deleted file mode 100644 index 8d9c7343dce..00000000000 --- a/src/beast/.gitattributes +++ /dev/null @@ -1,12 +0,0 @@ -# Set default behaviour, in case users don't have core.autocrlf set. -* text=auto - -# Github -.md text eol=lf - -# Visual Studio -*.sln text eol=crlf -*.vcproj text eol=crlf -*.vcxproj text eol=crlf -*.props text eol=crlf -*.filters text eol=crlf diff --git a/src/beast/.github/ISSUE_TEMPLATE.md b/src/beast/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index b342a0d7ac1..00000000000 --- a/src/beast/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,23 +0,0 @@ -PLEASE DON'T FORGET TO "STAR" THIS REPOSITORY :) - -When reporting a bug please include the following: - -### Version of Beast - -You can find the version number in -or using the command "git log -1". - -### Steps necessary to reproduce the problem - -A small compiling program is the best. If your code is -public, you can provide a link to the repository. - -### All relevant compiler information - -If you are unable to compile please include the type and -version of compiler you are using as well as all compiler -output including the error message, file, and line numbers -involved. - -The more information you provide the sooner your issue -can get resolved! diff --git a/src/beast/.gitignore b/src/beast/.gitignore deleted file mode 100644 index 1740b535d7c..00000000000 --- a/src/beast/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -bin/ -bin64/ - -# Because of CMake and VS2017 -Win32/ -x64/ - diff --git a/src/beast/.travis.yml b/src/beast/.travis.yml deleted file mode 100644 index 6a6ab527f1b..00000000000 --- a/src/beast/.travis.yml +++ /dev/null @@ -1,130 +0,0 @@ -sudo: false -language: cpp - -env: - global: - - LLVM_VERSION=3.8.0 - # Maintenance note: to move to a new version - # of boost, update both BOOST_ROOT and BOOST_URL. - # Note that for simplicity, BOOST_ROOT's final - # namepart must match the folder name internal - # to boost's .tar.gz. - - LCOV_ROOT=$HOME/lcov - - VALGRIND_ROOT=$HOME/valgrind-install - - BOOST_ROOT=$HOME/boost_1_58_0 - - BOOST_URL='http://sourceforge.net/projects/boost/files/boost/1.58.0/boost_1_58_0.tar.gz' - -addons: - apt: - sources: &base_sources - - ubuntu-toolchain-r-test - packages: &base_packages - - python-software-properties - - libffi-dev - - libstdc++6 - - binutils-gold - # Provides a backtrace if the unittests crash - - gdb - # Needed for installing valgrind - - subversion - - automake - - autotools-dev - - libc6-dbg - -matrix: - include: - # gcc coverage - - compiler: gcc - env: - - GCC_VER=6 - - VARIANT=coverage - - ADDRESS_MODEL=64 - - DO_VALGRIND=false - - BUILD_SYSTEM=cmake - - PATH=$PWD/cmake/bin:$PATH - addons: - apt: - packages: - - gcc-6 - - g++-6 - - libssl-dev - - *base_packages - sources: - - *base_sources - - # older GCC, release - - compiler: gcc - env: - - GCC_VER=4.8 - - VARIANT=release - - DO_VALGRIND=false - - ADDRESS_MODEL=64 - addons: - apt: - packages: - - gcc-4.8 - - g++-4.8 - - *base_packages - sources: - - *base_sources - - # later GCC - - compiler: gcc - env: - - GCC_VER=5 - - VARIANT=release - - DO_VALGRIND=true - - ADDRESS_MODEL=64 - - BUILD_SYSTEM=cmake - - PATH=$PWD/cmake/bin:$PATH - addons: - apt: - packages: - - gcc-5 - - g++-5 - - libssl-dev - - *base_packages - sources: - - *base_sources - - # clang ubsan+asan - - compiler: clang - env: - - GCC_VER=5 - - VARIANT=ubasan - - CLANG_VER=3.8 - - DO_VALGRIND=false - - ADDRESS_MODEL=64 - - UBSAN_OPTIONS='print_stacktrace=1' - - BUILD_SYSTEM=cmake - - PATH=$PWD/cmake/bin:$PATH - - PATH=$PWD/llvm-$LLVM_VERSION/bin:$PATH - addons: - apt: - packages: - - gcc-5 - - g++-5 - - libssl-dev - - *base_packages - sources: - - *base_sources - -cache: - directories: - - $BOOST_ROOT - - $VALGRIND_ROOT - - llvm-$LLVM_VERSION - - cmake - -before_install: &base_before_install - - scripts/install-dependencies.sh - -script: - - travis_retry scripts/build-and-test.sh - -after_script: - - cat nohup.out || echo "nohup.out already deleted" - -notifications: - email: - false diff --git a/src/beast/CHANGELOG.md b/src/beast/CHANGELOG.md deleted file mode 100644 index 803c8014ecc..00000000000 --- a/src/beast/CHANGELOG.md +++ /dev/null @@ -1,1227 +0,0 @@ -Version 79: - -* Remove spurious fallthrough guidance - --------------------------------------------------------------------------------- - -Version 78: - -* Add span -* Documentation work -* Use make_unique_noinit -* Fix warning in zlib -* Header file tidying -* Tidy up FieldsReader doc -* Add Boost.Locale utf8 benchmark comparison -* Tidy up dstream for existing Boost versions -* Tidy up file_posix unused variable -* Fix warning in root ca declaration - -HTTP: - -* Tidy up basic_string_body -* Add vector_body -* span, string, vector bodies are public -* Fix spurious uninitialized warning -* fields temp string uses allocator - -API Changes: - -* Add message::keep_alive() -* Add message::chunked() and message::content_length() -* Remove string_view_body - -Actions Required: - -* Change user defined implementations of Fields and - FieldsReader to meet the new requirements. - -* Use span_body instead of string_view_body - --------------------------------------------------------------------------------- - -Version 77: - -* file_posix works without large file support - --------------------------------------------------------------------------------- - -Version 76: - -* Always go through write_some -* Use Boost.Config -* BodyReader may construct from a non-const message -* Add serializer::get -* Add serializer::chunked -* Serializer members are not const -* serializing file_body is not const -* Add file_body_win32 -* Fix parse illegal characters in obs-fold -* Disable SSE4.2 optimizations - -API Changes: - -* Rename to serializer::keep_alive -* BodyReader, BodyWriter use two-phase init - -Actions Required: - -* Use serializer::keep_alive instead of serializer::close and - take the logical NOT of the return value. - -* Modify instances of user-defined BodyReader and BodyWriter - types to perfrom two-phase initialization, as per the - updated documented type requirements. - --------------------------------------------------------------------------------- - -Version 75: - -* Use file_body for valid requests, string_body otherwise. -* Construct buffer_prefix_view in-place -* Shrink serializer buffers using buffers_ref -* Tidy up BEAST_NO_BIG_VARIANTS -* Shrink serializer buffers using buffers_ref -* Add serializer::limit -* file_body tests -* Using SSE4.2 intrinsics in basic_parser if available - --------------------------------------------------------------------------------- - -Version 74: - -* Add file_stdio and File concept -* Add file_win32 -* Add file_body -* Remove common/file_body.hpp -* Add file_posix -* Fix Beast include directories for cmake targets -* remove redundant flush() from example - --------------------------------------------------------------------------------- - -Version 73: - -* Jamroot tweak -* Verify certificates in SSL clients -* Adjust benchmarks -* Initialize local variable in basic_parser -* Fixes for gcc-4.8 - -HTTP: - -* basic_parser optimizations -* Add basic_parser tests - -API Changes: - -* Refactor header and message constructors -* serializer::next replaces serializer::get - -Actions Required: - -* Evaluate each message constructor call site and - adjust the constructor argument list as needed. - -* Use serializer::next instead of serializer::get at call sites - --------------------------------------------------------------------------------- - -Version 72: - -HTTP: - -* Tidy up set payload in http-server-fast -* Refine Body::size specification -* Newly constructed responses have a 200 OK result -* Refactor file_body for best practices -* Add http-server-threaded example -* Documentation tidying -* Various improvements to http_server_fast.cpp - -WebSocket: - -* Add websocket-server-async example - - --------------------------------------------------------------------------------- - -Version 71: - -* Fix extra ; warning -* Documentation revision -* Fix spurious on_chunk invocation -* Call prepare_payload in HTTP example -* Check trailers in test -* Fix buffer overflow handling for string_body and mutable_body -* Concept check in basic_dynamic_body -* Tidy up http_sync_port error check -* Tidy up Jamroot /permissive- - -WebSockets: - -* Fine tune websocket op asserts -* Refactor websocket composed ops -* Allow close, ping, and write to happen concurrently -* Fix race in websocket read op -* Fix websocket write op -* Add cmake options for examples and tests - -API Changes: - -* Return `std::size_t` from `Body::writer::put` - -Actions Required: - -* Return the number of bytes actually transferred from the - input buffers in user defined `Body::writer::put` functions. - --------------------------------------------------------------------------------- - -Version 70: - -* Serialize in one step when possible -* Add basic_parser header and body limits -* Add parser::on_header to set a callback -* Fix BEAST_FALLTHROUGH -* Fix HEAD response in file_service - -API Changes: - -* Rename to message::base -* basic_parser default limits are now 1MB/8MB - -Actions Required: - -* Change calls to message::header_part() with message::base() - -* Call body_limit and/or header_limit as needed to adjust the - limits to suitable values if the defaults are insufficient. - --------------------------------------------------------------------------------- - -Version 69: - -* basic_parser optimizations -* Use BEAST_FALLTHROUGH to silence warnings -* Add /permissive- to msvc toolchain - --------------------------------------------------------------------------------- - -Version 68: - -* Split common tests to a new project -* Small speed up in fields comparisons -* Adjust buffer size in fast server -* Use string_ref in older Boost versions -* Optimize field lookups -* Add const_body, mutable_body to examples -* Link statically on cmake MSVC - -API Changes: - -* Change BodyReader, BodyWriter requirements -* Remove BodyReader::is_deferred -* http::error::bad_target replaces bad_path - -Actions Required: - -* Change user defined instances of BodyReader and BodyWriter - to meet the new requirements. - -* Replace references to http::error::bad_path with http::error::bad_target - --------------------------------------------------------------------------------- - -Version 67: - -* Fix doc example link -* Add http-server-small example -* Merge stream_base to stream and tidy -* Use boost::string_view -* Rename to http-server-fast -* Appveyor use Boost 1.64.0 -* Group common example headers - -API Changes: - -* control_callback replaces ping_callback - -Actions Required: - -* Change calls to websocket::stream::ping_callback to use - websocket::stream::control_callback - -* Change user defined ping callbacks to have the new - signature and adjust the callback definition appropriately. - --------------------------------------------------------------------------------- - -Version 66: - -* string_param optimizations -* Add serializer request/response aliases -* Make consuming_buffers smaller -* Fix costly potential value-init in parser -* Fix unused parameter warning -* Handle bad_alloc in parser -* Tidy up message piecewise ctors -* Add header aliases -* basic_fields optimizations -* Add http-server example -* Squelch spurious warning on gcc - --------------------------------------------------------------------------------- - -Version 65: - -* Enable narrowing warning on msvc cmake -* Fix integer types in deflate_stream::bi_reverse -* Fix narrowing in static_ostream -* Fix narrowing in ostream -* Fix narrowing in inflate_stream -* Fix narrowing in deflate_stream -* Fix integer warnings -* Enable unused variable warning on msvc cmake - --------------------------------------------------------------------------------- - -Version 64: - -* Simplify buffered_read_stream composed op -* Simplify ssl teardown composed op -* Simplify websocket write_op -* Exemplars are compiled code -* Better User-Agent in examples -* async_write requires a non-const message -* Doc tidying -* Add link_directories to cmake - -API Changes: - -* Remove make_serializer - -Actions Required: - -* Replace calls to make_serializer with variable declarations - --------------------------------------------------------------------------------- - -Version 63: - -* Use std::to_string instead of lexical_cast -* Don't use cached Boost -* Put num_jobs back up on Travis -* Only build and run tests in variant=coverage -* Move benchmarks to a separate project -* Only run the tests under ubasan -* Tidy up CMakeLists.txt -* Tidy up Jamfiles -* Control running with valgrind explicitly - --------------------------------------------------------------------------------- - -Version 62: - -* Remove libssl-dev from a Travis matrix item -* Increase detail::static_ostream coverage -* Add server-framework tests -* Doc fixes and tidy -* Tidy up namespaces in examples -* Clear the error faster -* Avoid explicit operator bool for error -* Add http::is_fields trait -* Squelch harmless not_connected errors -* Put slow tests back for coverage builds - -API Changes: - -* parser requires basic_fields -* Refine FieldsReader concept -* message::prepare_payload replaces message::prepare - -Actions Required: - -* Callers using `parser` with Fields types other than basic_fields - will need to create their own subclass of basic_parser to work - with their custom fields type. - -* Implement chunked() and keep_alive() for user defined FieldsReader types. - -* Change calls to msg.prepare to msg.prepare_payload. For messages - with a user-defined Fields, provide the function prepare_payload_impl - in the fields type according to the Fields requirements. - --------------------------------------------------------------------------------- - -Version 61: - -* Remove Spirit dependency -* Use generic_cateogry for errno -* Reorganize SSL examples -* Tidy up some integer conversion warnings -* Add message::header_part() -* Tidy up names in error categories -* Flush the output stream in the example -* Clean close in Secure WebSocket client -* Add server-framework SSL HTTP and WebSocket ports -* Fix shadowing warnings -* Tidy up http-crawl example -* Add multi_port to server-framework -* Tidy up resolver calls -* Use one job on CI -* Don't run slow tests on certain targets - -API Changes: - -* header::version is unsigned -* status-codes is unsigned - --------------------------------------------------------------------------------- - -Version 60: - -* String comparisons are public interfaces -* Fix response message type in async websocket accept -* New server-framework, full featured server example - --------------------------------------------------------------------------------- - -Version 59: - -* Integrated Beast INTERFACE (cmake) -* Fix base64 alphabet -* Remove obsolete doc/README.md - -API Changes: - -* Change Body::size signature (API Change): - -Actions Required: - -* For any user-defined models of Body, change the function signature - to accept `value_type const&` and modify the function definition - accordingly. - --------------------------------------------------------------------------------- - -Version 58: - -* Fix unaligned reads in utf8-checker -* Qualify size_t in message template -* Reorganize examples -* Specification for http read -* Avoid `std::string` in websocket -* Fix basic_fields insert ordering -* basic_fields::set optimization -* basic_parser::put doc -* Use static string in basic_fields::reader -* Remove redundant code -* Fix parsing chunk size with leading zeroes -* Better message formal parameter names - -API Changes: - -* `basic_fields::set` renamed from `basic_fields::replace` - -Actions Required: - -* Rename calls to `basic_fields::replace` to `basic_fields::set` - --------------------------------------------------------------------------------- - -Version 57: - -* Fix message.hpp javadocs -* Fix warning in basic_parser.cpp -* Integrate docca for documentation and tidy - --------------------------------------------------------------------------------- - -Version 56: - -* Add provisional IANA header field names -* Add string_view_body -* Call on_chunk when the extension is empty -* HTTP/1.1 is the default version -* Try harder to find Boost (cmake) -* Reset error codes -* More basic_parser tests -* Add an INTERFACE cmake target -* Convert buffer in range loops - --------------------------------------------------------------------------------- - -Version 55: - -* Don't allocate memory to handle obs-fold -* Avoid a parser allocation using non-flat buffer -* read_size replaces read_size_helper - --------------------------------------------------------------------------------- - -Version 54: - -* static_buffer coverage -* flat_buffer coverage -* multi_buffer coverage -* consuming_buffers members and coverage -* basic_fields members and coverage -* Add string_param -* Retain ownership when reading using a message -* Fix incorrect use of [[fallthrough]] - -API Changes: - -* basic_fields refactor - --------------------------------------------------------------------------------- - -Version 53: - -* Fix basic_parser::maybe_flatten -* Fix read_size_helper usage - --------------------------------------------------------------------------------- - -Version 52: - -* flat_buffer is an AllocatorAwareContainer -* Add drain_buffer class - -API Changes: - -* `auto_fragment` is a member of `stream` -* `binary`, `text` are members of `stream` -* read_buffer_size is a member of `stream` -* read_message_max is a member of `stream` -* `write_buffer_size` is a member of `stream` -* `ping_callback` is a member of stream -* Remove `opcode` from `read`, `async_read` -* `read_frame` returns `bool` fin -* `opcode` is private -* finish(error_code&) is a BodyReader requirement - -Actions Required: - -* Change call sites which use `auto_fragment` with `set_option` - to call `stream::auto_fragment` instead. - -* Change call sites which use message_type with `set_option` - to call `stream::binary` or `stream::text` instead. - -* Change call sites which use `read_buffer_size` with `set_option` to - call `stream::read_buffer_size` instead. - -* Change call sites which use `read_message_max` with `set_option` to - call `stream::read_message_max` instead. - -* Change call sites which use `write_buffer_size` with `set_option` to - call `stream::write_buffer_size` instead. - -* Change call sites which use `ping_callback1 with `set_option` to - call `stream::ping_callback` instead. - -* Remove the `opcode` reference parameter from calls to synchronous - and asynchronous read functions, replace the logic with calls to - `stream::got_binary` and `stream::got_text` instead. - -* Remove the `frame_info` parameter from all read frame call sites - -* Check the return value 'fin' for calls to `read_frame` - -* Change ReadHandlers passed to `async_read_frame` to have - the signature `void(error_code, bool fin)`, use the `bool` - to indicate if the frame is the last frame. - -* Remove all occurrences of the `opcode` enum at call sites - --------------------------------------------------------------------------------- - -Version 51 - -* Fix operator<< for header -* Tidy up file_body -* Fix file_body::get() not setting the more flag correctly -* Use BOOST_FALLTHROUGH -* Use BOOST_STRINGIZE -* DynamicBuffer benchmarks -* Add construct, destroy to handler_alloc -* Fix infinite loop in basic_parser - -API Changes: - -* Tune up static_buffer -* multi_buffer implementation change - -Actions Required: - -* Call sites passing a number to multi_buffer's constructor - will need to be adjusted, see the corresponding commit message. - --------------------------------------------------------------------------------- - -Version 50 - -* parser is constructible from other body types -* Add field enumeration -* Use allocator more in basic_fields -* Fix basic_fields allocator awareness -* Use field in basic_fields and call sites -* Use field in basic_parser -* Tidy up basic_fields, header, and field concepts -* Fields concept work -* Body documentation work -* Add missing handler_alloc nested types -* Fix chunk delimiter parsing -* Fix test::pipe read_size -* Fix chunk header parsing - -API Changes: - -* Remove header_parser -* Add verb to on_request for parsers -* Refactor prepare -* Protect basic_fields special members -* Remove message connection settings -* Remove message free functions -* Remove obsolete serializer allocator -* http read_some, async_read_some don't return bytes - --------------------------------------------------------------------------------- - -Version 49 - -* Use instead of - -HTTP: - -* Add HEAD request example - -API Changes: - -* Refactor method and verb -* Canonicalize string_view parameter types -* Tidy up empty_body writer error -* Refactor header status, reason, and target - --------------------------------------------------------------------------------- - -Version 48 - -* Make buffer_prefix_view public -* Remove detail::sync_ostream -* Tidy up core type traits - -API Changes: - -* Tidy up chunk decorator -* Rename to buffer_cat_view -* Consolidate parsers to parser.hpp -* Rename to parser - --------------------------------------------------------------------------------- - -Version 47 - -* Disable operator<< for buffer_body -* buffer_size overload for basic_multi_buffer::const_buffers_type -* Fix undefined behavior in pausation -* Fix leak in basic_flat_buffer - -API Changes: - -* Refactor treatment of request-method -* Refactor treatment of status code and obsolete reason -* Refactor HTTP serialization and parsing - --------------------------------------------------------------------------------- - -Version 46 - -* Add test::pipe -* Documentation work - -API Changes: - -* Remove HTTP header aliases -* Refactor HTTP serialization -* Refactor type traits - --------------------------------------------------------------------------------- - -Version 45 - -* Workaround for boost::asio::basic_streambuf type check -* Fix message doc image -* Better test::enable_yield_to -* Fix header::reason -* Documentation work -* buffer_view skips empty buffer sequences -* Disable reverse_iterator buffer_view test - --------------------------------------------------------------------------------- - -Version 44 - -* Use BOOST_THROW_EXCEPTION -* Tidy up read_size_helper and dynamic buffers -* Require Boost 1.58.0 or later -* Tidy up and make get_lowest_layer public -* Use BOOST_STATIC_ASSERT -* Fix async return values in docs -* Fix README websocket example -* Add buffers_adapter regression test -* Tidy up is_dynamic_buffer traits test -* Make buffers_adapter meet requirements - --------------------------------------------------------------------------------- - -Version 43 - -* Require Boost 1.64.0 -* Fix strict aliasing warnings in buffers_view -* Tidy up buffer_prefix overloads and test -* Add write limit to test::string_ostream -* Additional constructors for consuming_buffers - --------------------------------------------------------------------------------- - -Version 42 - -* Fix javadoc typo -* Add formal review notes -* Make buffers_view a public interface - --------------------------------------------------------------------------------- - -Version 41 - -* Trim Appveyor matrix rows -* Concept revision and documentation -* Remove coveralls integration -* Tidy up formal parameter names - -WebSocket - -* Tidy up websocket::close_code enum and constructors - -API Changes - -* Return http::error::end_of_stream on HTTP read eof -* Remove placeholders -* Rename prepare_buffer(s) to buffer_prefix -* Remove handler helpers, tidy up hook invocations - --------------------------------------------------------------------------------- - -Version 40 - -* Add to_static_string -* Consolidate get_lowest_layer in type_traits.hpp -* Fix basic_streambuf movable trait -* Tidy up .travis.yml - --------------------------------------------------------------------------------- - -Version 39 - -Beast versions are now identified by a single integer which -is incremented on each merge. The macro BEAST_VERSION -identifies the version number, currently at 39. A version -setting commit will always be at the tip of the master -and develop branches. - -* Use beast::string_view alias -* Fixed braced-init error with older gcc - -HTTP - -* Tidy up basic_parser javadocs - -WebSocket: - -* Add websocket async echo ssl server test: -* Fix eof error on ssl::stream shutdown - -API Changes: - -* Refactor http::header contents -* New ostream() returns dynamic buffer output stream -* New buffers() replaces to_string() -* Rename to multi_buffer, basic_multi_buffer -* Rename to flat_buffer, basic_flat_buffer -* Rename to static_buffer, static_buffer_n -* Rename to buffered_read_stream -* Harmonize concepts and identifiers with net-ts -* Tidy up HTTP reason_string - --------------------------------------------------------------------------------- - -1.0.0-b38 - -* Refactor static_string -* Refactor base64 -* Use static_string for WebSocket handshakes -* Simplify get_lowest_layer test -* Add test_allocator to extras/test -* More flat_streambuf tests -* WebSocket doc work -* Prevent basic_fields operator[] assignment - -API Changes: - -* Refactor WebSocket error codes -* Remove websocket::keep_alive option - --------------------------------------------------------------------------------- - -1.0.0-b37 - -* CMake hide command lines in .vcxproj Output windows" -* Rename to detail::is_invocable -* Rename project to http-bench -* Fix flat_streambuf -* Add ub sanitizer blacklist -* Add -funsigned-char to asan build target -* Fix narrowing warning in table constants - -WebSocket: - -* Add is_upgrade() free function -* Document websocket::stream thread safety -* Rename to websocket::detail::pausation - -API Changes: - -* Provide websocket::stream accept() overloads -* Refactor websocket decorators -* Move everything in basic_fields.hpp to fields.hpp -* Rename to http::dynamic_body, consolidate header - --------------------------------------------------------------------------------- - -1.0.0-b36 - -* Update README.md - --------------------------------------------------------------------------------- - -1.0.0-b35 - -* Add Appveyor build scripts and badge -* Tidy up MSVC CMake configuration -* Make close_code a proper enum -* Add flat_streambuf -* Rename to BEAST_DOXYGEN -* Update .gitignore for VS2017 -* Fix README.md CMake instructions - -API Changes: - -* New HTTP interfaces -* Remove http::empty_body - --------------------------------------------------------------------------------- - -1.0.0-b34 - -* Fix and tidy up CMake build scripts - --------------------------------------------------------------------------------- - -1.0.0-b33 - -* Require Visual Studio 2015 Update 3 or later - -HTTP - -* Use fwrite return value in file_body - -WebSocket - -* Set internal state correctly when writing frames -* Add decorator unit test -* Add write_frames unit test - --------------------------------------------------------------------------------- - -1.0.0-b32 - -* Add io_service completion invariants test -* Update CMake scripts for finding packages - -API Changes: - -* Remove http Writer suspend and resume feature - --------------------------------------------------------------------------------- - -1.0.0-b31 - -* Tidy up build settings -* Add missing dynabuf_readstream member - -WebSocket - -* Move the handler, don't copy it - --------------------------------------------------------------------------------- - -1.0.0-b30 - -WebSocket - -* Fix race in pings during reads -* Fix race in close frames during reads -* Fix race when write suspends -* Allow concurrent websocket async ping and writes - --------------------------------------------------------------------------------- - -1.0.0-b29 - -* Fix compilation error in non-template class -* Document type-pun in buffer_cat -* Correctly check ostream modifier (/extras) - -HTTP - -* Fix Body requirements doc -* Fix illegal HTTP characters accepted as hex zero -* Fix Writer return value documentation - -WebSocket - -* Fix race in writes during reads -* Fix doc link typo - --------------------------------------------------------------------------------- - -1.0.0-b28 - -* Split out and rename test stream classes -* Restyle async result constructions -* Fix HTTP split parse edge case - --------------------------------------------------------------------------------- - -1.0.0-b27 - -* Tidy up tests and docs -* Add documentation building instructions - -API Changes: - -* Invoke callback on pings and pongs -* Move basic_streambuf to streambuf.hpp - --------------------------------------------------------------------------------- - -1.0.0-b26 - -* Tidy up warnings and tests - --------------------------------------------------------------------------------- - -1.0.0-b25 - -* Fixes for WebSocket echo server -* Fix 32-bit arm7 warnings -* Remove unnecessary include -* WebSocket server examples and test tidying -* Fix deflate setup bug - -API Changes: - -* Better handler_ptr - --------------------------------------------------------------------------------- - -1.0.0-b24 - -* bjam use clang on MACOSX -* Simplify Travis package install specification -* Add optional yield_to arguments -* Make decorator copyable -* Add WebSocket permessage-deflate extension support - --------------------------------------------------------------------------------- - -1.0.0-b23 - -* Tune websocket echo server for performance -* Add file and line number to thrown exceptions -* Better logging in async echo server -* Add copy special members -* Fix message constructor and special members -* Travis CI improvements - --------------------------------------------------------------------------------- - -1.0.0-b22 - -* Fix broken Intellisense -* Implement the Asio deallocation-before-invocation guarantee -* Add handler helpers -* Avoid copies in handler_alloc -* Update README.md example programs -* Fix websocket stream read documentation -* Disable Boost.Coroutine deprecation warning -* Update documentation examples - --------------------------------------------------------------------------------- - -1.0.0-b21 - -* Remove extraneous includes - --------------------------------------------------------------------------------- - -1.0.0-b20 - -ZLib - -* Add ZLib module - -API Changes: - -* Rename HTTP identifiers - --------------------------------------------------------------------------------- - -1.0.0-b19 - -* Boost library min/max guidance -* Improvements to code coverage -* Use boost::lexical_cast instead of std::to_string -* Fix prepare_buffers value_type -* Fix consuming_buffers value_type -* Better buffer_cat - -HTTP - -* Make chunk_encode public -* Add write, async_write, operator<< for message_headers -* Add read, async_read for message_headers -* Fix with_body example - -WebSocket - -* Optimize utf8 validation -* Optimize mask operations - -API Changes: - -* Refactor message and message_headers declarations -* prepared_buffers is private -* consume_buffers is removed - --------------------------------------------------------------------------------- - -1.0.0-b18 - -* Increase optimization settings for MSVC builds - -HTTP - -* Check invariants in parse_op: -* Clean up message docs - -WebSocket - -* Write buffer option does not change capacity -* Close connection during async_read on close frame -* Add pong, async pong to stream - -Core - -* Meet DynamicBuffer requirements for static_streambuf -* Fix write_frame masking and auto-fragment handling - -Extras - -* unit_test::suite fixes: - - New overload of fail() specifies file and line - - BEAST_EXPECTS only evaluates the reason string on a failure -* Add zlib module - --------------------------------------------------------------------------------- - -1.0.0-b17 - -* Change implicit to default value in example -* Tidy up some declarations -* Fix basic_streambuf::capacity -* Add basic_streambuf::alloc_size -* Parser callbacks may not throw -* Fix Reader concept doc typo -* Add is_Reader trait -* Tidy up basic_headers for documentation -* Tidy up documentation -* Add basic_parser_v1::reset -* Fix handling of body_what::pause in basic_parser_v1 -* Add headers_parser -* Engaged invokable is destructible -* Improve websocket example in README.md -* Refactor read_size_helper - -API Changes: - -* Added init() to Reader requirements -* Reader must be nothrow constructible -* Reader is now constructed right before reading the body - - The message passed on construction is filled in -* Rework HTTP concepts: - - Writer uses write instead of operator() - - Refactor traits to use void_t - - Remove is_ReadableBody, is_WritableBody - - Add has_reader, has_writer, is_Reader, is_Writer - - More friendly compile errors on failed concept checks -* basic_parser_v1 requires all callbacks present -* on_headers parser callback now returns void -* on_body_what is a new required parser callback returning body_what - --------------------------------------------------------------------------------- - -1.0.0-b16 - -* Make value optional in param-list -* Frame processing routines are member functions -* Fix on_headers called twice from basic_parser_v1 -* Constrain parser_v1 constructor -* Improve first line serialization -* Add pause option to on_headers interface -* Refactor base_parser_v1 callback traits: -* Refine Parser concept -* Relax ForwardIterator requirements in FieldSequence -* Fix websocket failure testing -* Refine Writer concept and fix exemplar in documentation - -API Changes: - -* Rename mask_buffer_size to write_buffer_size -* Make auto_fragment a boolean option - -The message class hierarchy is refactored (breaking change): - -* One message class now models both HTTP/1 and HTTP/2 messages -* message_v1, request_v1, response_v1 removed -* New classes basic_request and basic_response model - messages without the body. - - Error resolution: Callers should use message, request, - and response instead of message_v1, request_v1, and - response_v1 respectively. - --------------------------------------------------------------------------------- - -1.0.0-b15 - -* rfc7230 section 3.3.2 compliance -* Add HTTPS example -* Add Secure WebSocket example -* Fix message_v1 constructor -* Tidy up DynamicBuffer requirements -* Tidy up error types and headers -* Fix handling empty HTTP headers in parser_v1 - --------------------------------------------------------------------------------- - -1.0.0-b14 - -* Add missing rebind to handler_alloc -* Fix error handling in http server examples -* Fix CMake scripts for MinGW -* Use BOOST_ASSERT -* Better WebSocket decorator -* Update and tidy documentation - --------------------------------------------------------------------------------- - -1.0.0-b13 - -* dstream improvements -* Remove bin and bin64 directories -* Tidy up .vcxproj file groupings - --------------------------------------------------------------------------------- - -1.0.0-b12 - -* Use -p to print suites from unit test main. -* BEAST_EXPECTS to add a reason string to test failures -* Fix unit test runner to output all case names -* Update README for build requirements -* Rename to CHANGELOG.md - --------------------------------------------------------------------------------- - -1.0.0-b11 - -* Set URI in generated WebSocket Upgrade requests -* Rename echo server class and file names -* Rename to DynamicBuffer in some code and documentation -* Fix integer warnings in Windows builds -* Add 32 and 64 bit Windows build support -* Update README for build instructions and more -* Add repository and documention banners - --------------------------------------------------------------------------------- - -1.0.0-b10 - -* Fix compilation warnings -* Add websocketpp comparison to HTML documentation - --------------------------------------------------------------------------------- - -1.0.0-b9 - -* Fix CMakeLists.txt - --------------------------------------------------------------------------------- - -1.0.0-b8 - -* Fix include in example code -* Fix basic_headers rfc2616 Section 4.2 compliance - --------------------------------------------------------------------------------- - -1.0.0-b7 - -* Fix prepare by calling init. prepare() can throw depending on the - implementation of Writer. Publicly provided beast::http writers never throw. -* Fixes to example HTTP server -* Fully qualify ambiguous calls to read and parse -* Remove deprecated http::stream wrapper -* Example HTTP server now calculates the MIME-type -* Fixes and documentation for teardown and use with SSL: -* Add example code to rfc7230 javadocs -* Remove extraneous header file -* Add skip_body parser option - --------------------------------------------------------------------------------- - -1.0.0-b6 - -* Use SFINAE on return values -* Use beast::error_code instead of nested types -* Tidy up use of GENERATING_DOCS -* Remove obsolete RFC2616 functions -* Add message swap members and free functions -* Add HTTP field value parser containers: ext_list, param_list, token_list -* Fixes for some corner cases in basic_parser_v1 -* Configurable limits on headers and body sizes in basic_parser_v1 - -API Changes: - -* ci_equal is moved to beast::http namespace, in rfc7230.hpp - -* "DynamicBuffer","dynabuf" renamed from "Streambuf", "streambuf". See: - http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4478.html#requirements.dynamic_buffers - -* basic_parser_v1 adheres to rfc7230 as strictly as possible - --------------------------------------------------------------------------------- diff --git a/src/beast/CMakeLists.txt b/src/beast/CMakeLists.txt deleted file mode 100644 index fa2cee17eb3..00000000000 --- a/src/beast/CMakeLists.txt +++ /dev/null @@ -1,194 +0,0 @@ -# Part of Beast - -cmake_minimum_required (VERSION 3.5.2) - -project (Beast VERSION 79) - -set_property (GLOBAL PROPERTY USE_FOLDERS ON) -option (Beast_BUILD_EXAMPLES "Build examples" ON) -option (Beast_BUILD_TESTS "Build tests" ON) - -if (MSVC) - set (CMAKE_VERBOSE_MAKEFILE FALSE) - - add_definitions (-D_WIN32_WINNT=0x0601) - add_definitions (-D_SCL_SECURE_NO_WARNINGS=1) - add_definitions (-D_CRT_SECURE_NO_WARNINGS=1) - - set (Boost_USE_STATIC_LIBS ON) - set (Boost_USE_STATIC_RUNTIME ON) - - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /W4 /bigobj /permissive-") - set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") - set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Ob2 /Oi /Ot /GL /MT") - set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /Oi /Ot /MT") - - set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO") - set (CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG") - - # for RelWithDebInfo builds, disable incremental linking - # since CMake sets it ON by default for that build type and it - # causes warnings - # - string (REPLACE "/INCREMENTAL" "/INCREMENTAL:NO" replacement_flags - ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}) - set (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO ${replacement_flags}) - -else() - set (THREADS_PREFER_PTHREAD_FLAG ON) - find_package (Threads) - - set( CMAKE_CXX_FLAGS - "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -Wpedantic -Wno-unused-parameter") - - if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wrange-loop-analysis") - endif () -endif() - -#------------------------------------------------------------------------------- -# -# Boost -# - -option (Boost_USE_STATIC_LIBS "Use static libraries for boost" ON) - -set(BOOST_COMPONENTS system) -if (Beast_BUILD_EXAMPLES OR Beast_BUILD_TESTS) - list(APPEND BOOST_COMPONENTS coroutine context filesystem program_options thread) -endif() -find_package (Boost 1.58.0 REQUIRED COMPONENTS ${BOOST_COMPONENTS}) - -link_directories(${Boost_LIBRARY_DIRS}) - -if (MINGW) - link_libraries(ws2_32 mswsock) -endif() - -#------------------------------------------------------------------------------- -# -# OpenSSL -# - -if (APPLE AND NOT DEFINED ENV{OPENSSL_ROOT_DIR}) - find_program(HOMEBREW brew) - if (NOT HOMEBREW STREQUAL "HOMEBREW-NOTFOUND") - execute_process(COMMAND brew --prefix openssl - OUTPUT_VARIABLE OPENSSL_ROOT_DIR - OUTPUT_STRIP_TRAILING_WHITESPACE) - endif() -endif() - -find_package(OpenSSL) - -if (OPENSSL_FOUND) - add_definitions (-DBEAST_USE_OPENSSL=1) - -else() - add_definitions (-DBEAST_USE_OPENSSL=0) - message("OpenSSL not found.") -endif() - -# -#------------------------------------------------------------------------------- - -function(DoGroupSources curdir rootdir folder) - file (GLOB children RELATIVE ${PROJECT_SOURCE_DIR}/${curdir} ${PROJECT_SOURCE_DIR}/${curdir}/*) - foreach (child ${children}) - if (IS_DIRECTORY ${PROJECT_SOURCE_DIR}/${curdir}/${child}) - DoGroupSources(${curdir}/${child} ${rootdir} ${folder}) - elseif (${child} STREQUAL "CMakeLists.txt") - source_group("" FILES ${PROJECT_SOURCE_DIR}/${curdir}/${child}) - else() - string(REGEX REPLACE ^${rootdir} ${folder} groupname ${curdir}) - string(REPLACE "/" "\\" groupname ${groupname}) - source_group(${groupname} FILES ${PROJECT_SOURCE_DIR}/${curdir}/${child}) - endif() - endforeach() -endfunction() - -function(GroupSources curdir folder) - DoGroupSources (${curdir} ${curdir} ${folder}) -endfunction() - -#------------------------------------------------------------------------------- - -if ("${VARIANT}" STREQUAL "coverage") - if (MSVC) - else() - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2 -fprofile-arcs -ftest-coverage") - set (CMAKE_BUILD_TYPE RELWITHDEBINFO) - set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lgcov") - endif() - -elseif ("${VARIANT}" STREQUAL "ubasan") - if (MSVC) - else() - set (CMAKE_CXX_FLAGS - "${CMAKE_CXX_FLAGS} -DBEAST_NO_SLOW_TESTS=1 -msse4.2 -funsigned-char -fno-omit-frame-pointer -fsanitize=address,undefined -fsanitize-blacklist=${PROJECT_SOURCE_DIR}/scripts/blacklist.supp") - set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address,undefined") - set (CMAKE_BUILD_TYPE RELWITHDEBINFO) - endif() - -elseif ("${VARIANT}" STREQUAL "debug") - set (CMAKE_BUILD_TYPE DEBUG) - -elseif ("${VARIANT}" STREQUAL "release") - set (CMAKE_BUILD_TYPE RELEASE) - -endif() - -#------------------------------------------------------------------------------- -# -# Library interface -# - -add_library (${PROJECT_NAME} INTERFACE) -target_link_libraries (${PROJECT_NAME} INTERFACE ${Boost_SYSTEM_LIBRARY}) -if (NOT MSVC) - target_link_libraries (${PROJECT_NAME} INTERFACE Threads::Threads) -endif() -target_compile_definitions (${PROJECT_NAME} INTERFACE BOOST_COROUTINES_NO_DEPRECATION_WARNING=1) -target_include_directories(${PROJECT_NAME} INTERFACE ${PROJECT_SOURCE_DIR}/include) -target_include_directories(${PROJECT_NAME} SYSTEM INTERFACE ${Boost_INCLUDE_DIRS}) - -#------------------------------------------------------------------------------- -# -# Tests and examples -# - -include_directories (.) -include_directories (extras) -include_directories (include) - -if (OPENSSL_FOUND) - include_directories (${OPENSSL_INCLUDE_DIR}) -endif() - -file(GLOB_RECURSE BEAST_INCLUDES - ${PROJECT_SOURCE_DIR}/include/beast/*.hpp - ${PROJECT_SOURCE_DIR}/include/beast/*.ipp -) - -file(GLOB_RECURSE COMMON_INCLUDES - ${PROJECT_SOURCE_DIR}/example/common/*.hpp - ) - -file(GLOB_RECURSE EXAMPLE_INCLUDES - ${PROJECT_SOURCE_DIR}/example/*.hpp - ) - -file(GLOB_RECURSE EXTRAS_INCLUDES - ${PROJECT_SOURCE_DIR}/extras/beast/*.hpp - ${PROJECT_SOURCE_DIR}/extras/beast/*.ipp -) - -if (Beast_BUILD_TESTS) - add_subdirectory (test) -endif() - -if (Beast_BUILD_EXAMPLES AND - (NOT "${VARIANT}" STREQUAL "coverage") AND - (NOT "${VARIANT}" STREQUAL "ubasan")) - add_subdirectory (example) -endif() diff --git a/src/beast/Jamroot b/src/beast/Jamroot deleted file mode 100644 index a35ffbb5de9..00000000000 --- a/src/beast/Jamroot +++ /dev/null @@ -1,115 +0,0 @@ -# -# Copyright (c) 2013-2016 Vinnie Falco (vinnie dot falco at gmail dot com) -# -# 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) -# - -import os ; -import feature ; -import boost ; -import modules ; -import testing ; - -boost.use-project ; - -if [ os.name ] = SOLARIS -{ - lib socket ; - lib nsl ; -} -else if [ os.name ] = NT -{ - lib ws2_32 ; - lib mswsock ; -} -else if [ os.name ] = HPUX -{ - lib ipv6 ; -} -else if [ os.name ] = QNXNTO -{ - lib socket ; -} -else if [ os.name ] = HAIKU -{ - lib network ; -} - -if [ os.name ] = NT -{ - lib ssl : : ssleay32 ; - lib crypto : : libeay32 ; -} -else -{ - lib ssl ; - lib crypto ; -} - -if [ os.name ] = MACOSX -{ - using clang : : ; -} - -variant coverage : - release - : - "-msse4.2 -fprofile-arcs -ftest-coverage" - "-lgcov" - ; - -variant ubasan - : - release - : - "-msse4.2 -funsigned-char -fno-omit-frame-pointer -fsanitize=address,undefined -fsanitize-blacklist=scripts/blacklist.supp" - "-fsanitize=address,undefined" - ; - -project beast - : requirements - /boost//headers - . - ./extras - ./include - #/boost//headers - /boost/system//boost_system - /boost/coroutine//boost_coroutine - /boost/filesystem//boost_filesystem - /boost/program_options//boost_program_options - BOOST_ALL_NO_LIB=1 - BOOST_COROUTINES_NO_DEPRECATION_WARNING=1 - multi - shared - on - gcc:-std=c++11 - gcc:-Wno-unused-parameter - gcc:-Wno-unused-variable # Temporary until we can figure out -isystem - clang:-std=c++11 - clang:-Wno-unused-parameter - clang:-Wno-unused-variable # Temporary until we can figure out -isystem - clang:-Wrange-loop-analysis - msvc:_SCL_SECURE_NO_WARNINGS=1 - msvc:_CRT_SECURE_NO_WARNINGS=1 - msvc:"/permissive- /bigobj" - msvc:release:"/Ob2 /Oi /Ot" - LINUX:_XOPEN_SOURCE=600 - LINUX:_GNU_SOURCE=1 - SOLARIS:_XOPEN_SOURCE=500 - SOLARIS:__EXTENSIONS__ - SOLARIS:socket - SOLARIS:nsl - NT:_WIN32_WINNT=0x0601 - NT,cw:ws2_32 - NT,cw:mswsock - NT,gcc:ws2_32 - NT,gcc:mswsock - NT,gcc-cygwin:__USE_W32_SOCKETS - : usage-requirements - : - build-dir bin - ; - -build-project test ; -build-project example ; diff --git a/src/beast/LICENSE_1_0.txt b/src/beast/LICENSE_1_0.txt deleted file mode 100644 index 36b7cd93cdf..00000000000 --- a/src/beast/LICENSE_1_0.txt +++ /dev/null @@ -1,23 +0,0 @@ -Boost Software License - Version 1.0 - August 17th, 2003 - -Permission is hereby granted, free of charge, to any person or organization -obtaining a copy of the software and accompanying documentation covered by -this license (the "Software") to use, reproduce, display, distribute, -execute, and transmit the Software, and to prepare derivative works of the -Software, and to permit third-parties to whom the Software is furnished to -do so, all subject to the following: - -The copyright notices in the Software and this entire statement, including -the above license grant, this restriction and the following disclaimer, -must be included in all copies of the Software, in whole or in part, and -all derivative works of the Software, unless such copies or derivative -works are solely in the form of machine-executable object code generated by -a source language processor. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/src/beast/README.md b/src/beast/README.md deleted file mode 100644 index 9b854e8a6cf..00000000000 --- a/src/beast/README.md +++ /dev/null @@ -1,206 +0,0 @@ -Beast - -# HTTP and WebSocket built on Boost.Asio in C++11 - -Branch | Build | Coverage | Documentation -------------|---------------|----------------|--------------- -[master](https://github.com/vinniefalco/Beast/tree/master) | [![Build Status](https://travis-ci.org/vinniefalco/Beast.svg?branch=master)](https://travis-ci.org/vinniefalco/Beast) [![Build status](https://ci.appveyor.com/api/projects/status/g0llpbvhpjuxjnlw/branch/master?svg=true)](https://ci.appveyor.com/project/vinniefalco/beast/branch/master) | [![codecov](https://codecov.io/gh/vinniefalco/Beast/branch/master/graph/badge.svg)](https://codecov.io/gh/vinniefalco/Beast/branch/master) | [![Documentation](https://img.shields.io/badge/documentation-master-brightgreen.svg)](http://vinniefalco.github.io/beast/) -[develop](https://github.com/vinniefalco/Beast/tree/develop) | [![Build Status](https://travis-ci.org/vinniefalco/Beast.svg?branch=develop)](https://travis-ci.org/vinniefalco/Beast) [![Build status](https://ci.appveyor.com/api/projects/status/g0llpbvhpjuxjnlw/branch/develop?svg=true)](https://ci.appveyor.com/project/vinniefalco/beast/branch/develop) | [![codecov](https://codecov.io/gh/vinniefalco/Beast/branch/develop/graph/badge.svg)](https://codecov.io/gh/vinniefalco/Beast/branch/develop) | [![Documentation](https://img.shields.io/badge/documentation-develop-brightgreen.svg)](http://vinniefalco.github.io/stage/beast/develop) - -## Contents - -- [Introduction](#introduction) -- [Appearances](#appearances) -- [Description](#description) -- [Requirements](#requirements) -- [Building](#building) -- [Usage](#usage) -- [Licence](#licence) -- [Contact](#contact) -- [Contributing](#Contributing) - -## Introduction - -Beast is a C++ header-only library serving as a foundation for writing -interoperable networking libraries by providing **low-level HTTP/1, -WebSocket, and networking protocol** vocabulary types and algorithms -using the consistent asynchronous model of Boost.Asio. - -This library is designed for: - -* **Symmetry:** Algorithms are role-agnostic; build clients, servers, or both. - -* **Ease of Use:** Boost.Asio users will immediately understand Beast. - -* **Flexibility:** Users make the important decisions such as buffer or - thread management. - -* **Performance:** Build applications handling thousands of connections or more. - -* **Basis for Further Abstraction.** Components are well-suited for building upon. - -## Appearances - -| CppCast 2017 | CppCon 2016 | -| ------------ | ----------- | -| Vinnie Falco | Beast | - -## Description - -This software is currently in beta: interfaces may change. -For recent changes see the [CHANGELOG](CHANGELOG.md). -The library has been submitted to the -[Boost Library Incubator](http://rrsd.com/blincubator.com/bi_library/beast-2/?gform_post_id=1579) - -* [Project Site](http://vinniefalco.github.io/) -* [Repository](https://github.com/vinniefalco/Beast) -* [Project Documentation](http://vinniefalco.github.io/beast/) -* [Autobahn.testsuite results](http://vinniefalco.github.io/autobahn/index.html) - -## Requirements - -This library is for programmers familiar with Boost.Asio. Users -who wish to use asynchronous interfaces should already know how to -create concurrent network programs using callbacks or coroutines. - -* **C++11:** Robust support for most language features. -* **Boost:** Boost.Asio and some other parts of Boost. -* **OpenSSL:** Optional, for using TLS/Secure sockets. - -When using Microsoft Visual C++, Visual Studio 2015 Update 3 or later is required. - -These components are required in order to build the tests and examples: - -* CMake 3.7.2 or later -* Properly configured bjam/b2 - -## Building - -Beast is header-only so there are no libraries to build or link with. -To use Beast in your project, simply copy the Beast sources to your -project's source tree (alternatively, bring Beast into your Git repository -using the `git subtree` or `git submodule` commands). Then, edit your - build scripts to add the `include/` directory to the list of paths checked - by the C++ compiler when searching for includes. Beast `#include` lines - will look like this: -```C++ -#include -#include -``` - -To link your program successfully, you'll need to add the Boost.System -library to link with. If you use coroutines you'll also need the -Boost.Coroutine library. Please visit the Boost documentation for -instructions on how to do this for your particular build system. - -For the examples and tests, Beast provides build scripts for Boost.Build (bjam) -and CMake. It is possible to generate Microsoft Visual Studio or Apple -Xcode project files using CMake by executing these commands from -the root of the repository: - -``` -mkdir bin -cd bin -cmake .. # for 32-bit Windows builds -cmake -G Xcode .. # for Apple Xcode builds - -cd .. -mkdir bin64 -cd bin64 -cmake -G"Visual Studio 14 2015 Win64" .. # for 64-bit Windows builds (VS2015) -cmake -G"Visual Studio 15 2017 Win64" .. # for 64-bit Windows builds (VS2017) - -``` - -To build with Boost.Build, it is necessary to have the bjam executable -in your path. And bjam needs to know how to find the Boost sources. The -easiest way to do this is make sure that the version of bjam in your path -is the one at the root of the Boost source tree, which is built when -running `bootstrap.sh` (or `bootstrap.bat` on Windows). - -Once bjam is in your path, simply run bjam in the root of the Beast -repository to automatically build the required Boost libraries if they -are not already built, build the examples, then build and run the unit -tests. - -The files in the repository are laid out thusly: - -``` -./ - bin/ Create this to hold executables and project files - bin64/ Create this to hold 64-bit Windows executables and project files - doc/ Source code and scripts for the documentation - include/ Add this to your compiler includes - beast/ - extras/ Additional APIs, may change - example/ Self contained example programs - test/ Unit tests and benchmarks -``` - - -## Usage - -These examples are complete, self-contained programs that you can build -and run yourself (they are in the `example` directory). - -http://vinniefalco.github.io/beast/beast/quick_start.html - -## License - -Distributed under the Boost Software License, Version 1.0. -(See accompanying file [LICENSE_1_0.txt](LICENSE_1_0.txt) or copy at -http://www.boost.org/LICENSE_1_0.txt) - -## Contact - -Please report issues or questions here: -https://github.com/vinniefalco/Beast/issues - - ---- - -## Contributing (We Need Your Help!) - -If you would like to contribute to Beast and help us maintain high -quality, consider performing code reviews on active pull requests. -Any feedback from users and stakeholders, even simple questions about -how things work or why they were done a certain way, carries value -and can be used to improve the library. Code review provides these -benefits: - -* Identify bugs -* Documentation proof-reading -* Adjust interfaces to suit use-cases -* Simplify code - -You can look through the Closed pull requests to get an idea of how -reviews are performed. To give a code review just sign in with your -GitHub account and then add comments to any open pull requests below, -don't be shy! -

https://github.com/vinniefalco/Beast/pulls

- -Here are some resources to learn more about -code reviews: - -* Top 10 Pull Request Review Mistakes -* Best Kept Secrets of Peer Code Review (pdf) -* 11 Best Practices for Peer Code Review (pdf) -* Code Review Checklist – To Perform Effective Code Reviews -* Code review guidelines -* C++ Core Guidelines -* C++ Coding Standards (Sutter & Andrescu) - -Beast thrives on code reviews and any sort of feedback from users and -stakeholders about its interfaces. Even if you just have questions, -asking them in the code review or in issues provides valuable information -that can be used to improve the library - do not hesitate, no question -is insignificant or unimportant! - -While code reviews are the preferred form of donation, if you simply -must donate money to support the library, please do so -using Bitcoin sent to this address: -1DaPsDvv6MjFUSnsxXSHzeYKSjzrWrQY7T - - - diff --git a/src/beast/appveyor.yml b/src/beast/appveyor.yml deleted file mode 100644 index e6f93604fc0..00000000000 --- a/src/beast/appveyor.yml +++ /dev/null @@ -1,102 +0,0 @@ -# Copyright 2016 Peter Dimov -# Distributed under the Boost Software License, Version 1.0. -# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt) - -#version: 1.0.{build}-{branch} -version: "{branch} (#{build})" - -shallow_clone: true - -platform: - #- x86 - - x64 - -configuration: - #- Debug - - Release - -install: - - cd .. - - git clone https://github.com/boostorg/boost.git boost - - cd boost -# - git checkout boost-1.64.0 - - xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\beast\ - - git submodule update --init tools/build - - git submodule update --init libs/config - - git submodule update --init tools/boostdep -# - python tools/boostdep/depinst/depinst.py beast - - git submodule update --init libs/any - - git submodule update --init libs/asio - - git submodule update --init libs/algorithm - - git submodule update --init libs/array - - git submodule update --init libs/assert - - git submodule update --init libs/atomic - - git submodule update --init libs/bind - - git submodule update --init libs/chrono - - git submodule update --init libs/concept_check - - git submodule update --init libs/config - - git submodule update --init libs/container - - git submodule update --init libs/context - - git submodule update --init libs/conversion - - git submodule update --init libs/core - - git submodule update --init libs/coroutine - - git submodule update --init libs/date_time - - git submodule update --init libs/detail - - git submodule update --init libs/endian - - git submodule update --init libs/exception - - git submodule update --init libs/filesystem - - git submodule update --init libs/foreach - - git submodule update --init libs/function - - git submodule update --init libs/function_types - - git submodule update --init libs/functional - - git submodule update --init libs/fusion - - git submodule update --init libs/integer - - git submodule update --init libs/intrusive - - git submodule update --init libs/io - - git submodule update --init libs/iostreams - - git submodule update --init libs/iterator - - git submodule update --init libs/lambda - - git submodule update --init libs/lexical_cast - - git submodule update --init libs/locale - - git submodule update --init libs/logic - - git submodule update --init libs/math - - git submodule update --init libs/move - - git submodule update --init libs/mpl - - git submodule update --init libs/numeric/conversion - - git submodule update --init libs/optional -# - git submodule update --init libs/phoenix - - git submodule update --init libs/pool - - git submodule update --init libs/predef - - git submodule update --init libs/preprocessor - - git submodule update --init libs/program_options - - git submodule update --init libs/proto - - git submodule update --init libs/random - - git submodule update --init libs/range - - git submodule update --init libs/ratio - - git submodule update --init libs/rational - - git submodule update --init libs/regex - - git submodule update --init libs/serialization - - git submodule update --init libs/smart_ptr -# - git submodule update --init libs/spirit - - git submodule update --init libs/static_assert - - git submodule update --init libs/system - - git submodule update --init libs/thread - - git submodule update --init libs/throw_exception - - git submodule update --init libs/tokenizer - - git submodule update --init libs/tti - - git submodule update --init libs/tuple - - git submodule update --init libs/type_index - - git submodule update --init libs/type_traits - - git submodule update --init libs/typeof - - git submodule update --init libs/unordered - - git submodule update --init libs/utility - - git submodule update --init libs/variant - - git submodule update --init libs/winapi - - bootstrap - - b2 headers - -build: off - -test_script: - - b2 libs/beast/example toolset=msvc-14.0 - - b2 libs/beast/test toolset=msvc-14.0 diff --git a/src/beast/doc/.gitignore b/src/beast/doc/.gitignore deleted file mode 100644 index b775bdcfd90..00000000000 --- a/src/beast/doc/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -html -temp -reference.qbk -out.txt diff --git a/src/beast/doc/0_main.qbk b/src/beast/doc/0_main.qbk deleted file mode 100644 index 90de1b15bbc..00000000000 --- a/src/beast/doc/0_main.qbk +++ /dev/null @@ -1,113 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[library Beast - [quickbook 1.6] - [copyright 2013 - 2017 Vinnie Falco] - [purpose Networking Protocol Library] - [license - 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]) - ] - [authors [Falco, Vinnie]] - [category template] - [category generic] -] - -[template mdash[] '''— '''] -[template indexterm1[term1] ''''''[term1]''''''] -[template indexterm2[term1 term2] ''''''[term1]''''''[term2]''''''] -[template repo_file[path] ''''''[path]''''''] -[template include_file[path][^<''''''[path]''''''>]] - -[def __N3747__ [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3747.pdf [*N3747]]] -[def __N4588__ [@http://cplusplus.github.io/networking-ts/draft.pdf [*N4588]]] -[def __rfc6455__ [@https://tools.ietf.org/html/rfc6455 rfc6455]] -[def __rfc7230__ [@https://tools.ietf.org/html/rfc7230 rfc7230]] - -[def __Asio__ [@http://www.boost.org/doc/html/boost_asio.html Boost.Asio]] - -[def __asio_handler_invoke__ [@http://www.boost.org/doc/html/boost_asio/reference/asio_handler_invoke.html `asio_handler_invoke`]] -[def __asio_handler_allocate__ [@http://www.boost.org/doc/html/boost_asio/reference/asio_handler_allocate.html `asio_handler_allocate`]] -[def __io_service__ [@http://www.boost.org/doc/html/boost_asio/reference/io_service.html `io_service`]] -[def __socket__ [@http://www.boost.org/doc/html/boost_asio/reference/ip__tcp/socket.html `boost::asio::ip::tcp::socket`]] -[def __ssl_stream__ [@http://www.boost.org/doc/html/boost_asio/reference/ssl__stream.html `boost::asio::ssl::stream`]] -[def __streambuf__ [@http://www.boost.org/doc/html/boost_asio/reference/streambuf.html `boost::asio::streambuf`]] -[def __use_future__ [@http://www.boost.org/doc/html/boost_asio/reference/use_future_t.html `boost::asio::use_future`]] -[def __void_or_deduced__ [@http://www.boost.org/doc/html/boost_asio/reference/asynchronous_operations.html#boost_asio.reference.asynchronous_operations.return_type_of_an_initiating_function ['void-or-deduced]]] -[def __yield_context__ [@http://www.boost.org/doc/html/boost_asio/reference/yield_context.html `boost::asio::yield_context`]] - -[def __AsyncReadStream__ [@http://www.boost.org/doc/html/boost_asio/reference/AsyncReadStream.html [*AsyncReadStream]]] -[def __AsyncWriteStream__ [@http://www.boost.org/doc/html/boost_asio/reference/AsyncWriteStream.html [*AsyncWriteStream]]] -[def __CompletionHandler__ [@http://www.boost.org/doc/html/boost_asio/reference/CompletionHandler.html [*CompletionHandler]]] -[def __ConstBufferSequence__ [@http://www.boost.org/doc/html/boost_asio/reference/ConstBufferSequence.html [*ConstBufferSequence]]] -[def __Handler__ [@http://www.boost.org/doc/html/boost_asio/reference/Handler.html [*Handler]]] -[def __MutableBufferSequence__ [@http://www.boost.org/doc/html/boost_asio/reference/MutableBufferSequence.html [*MutableBufferSequence]]] -[def __SyncReadStream__ [@http://www.boost.org/doc/html/boost_asio/reference/SyncReadStream.html [*SyncReadStream]]] -[def __SyncWriteStream__ [@http://www.boost.org/doc/html/boost_asio/reference/SyncWriteStream.html [*SyncWriteStream]]] - -[def __async_initfn__ [@http://www.boost.org/doc/html/boost_asio/reference/asynchronous_operations.html initiating function]] - -[def __AsyncStream__ [link beast.concept.streams.AsyncStream [*AsyncStream]]] -[def __Body__ [link beast.concept.Body [*Body]]] -[def __BodyReader__ [link beast.concept.BodyReader [*BodyReader]]] -[def __BodyWriter__ [link beast.concept.BodyWriter [*BodyWriter]]] -[def __DynamicBuffer__ [link beast.concept.DynamicBuffer [*DynamicBuffer]]] -[def __Fields__ [link beast.concept.Fields [*Fields]]] -[def __FieldsReader__ [link beast.concept.FieldsReader [*FieldsReader]]] -[def __File__ [link beast.concept.File [*File]]] -[def __Stream__ [link beast.concept.streams [*Stream]]] -[def __SyncStream__ [link beast.concept.streams.SyncStream [*SyncStream]]] - -[def __basic_fields__ [link beast.ref.beast__http__basic_fields `basic_fields`]] -[def __basic_multi_buffer__ [link beast.ref.beast__basic_multi_buffer `basic_multi_buffer`]] -[def __basic_parser__ [link beast.ref.beast__http__basic_parser `basic_parser`]] -[def __buffer_body__ [link beast.ref.beast__http__buffer_body `buffer_body`]] -[def __fields__ [link beast.ref.beast__http__fields `fields`]] -[def __flat_buffer__ [link beast.ref.beast__flat_buffer `flat_buffer`]] -[def __header__ [link beast.ref.beast__http__header `header`]] -[def __message__ [link beast.ref.beast__http__message `message`]] -[def __multi_buffer__ [link beast.ref.beast__multi_buffer `multi_buffer`]] -[def __parser__ [link beast.ref.beast__http__parser `parser`]] -[def __serializer__ [link beast.ref.beast__http__serializer `serializer`]] -[def __static_buffer__ [link beast.ref.beast__static_buffer `static_buffer`]] -[def __static_buffer_n__ [link beast.ref.beast__static_buffer_n `static_buffer_n`]] - -[import ../example/common/detect_ssl.hpp] -[import ../example/doc/http_examples.hpp] -[import ../example/echo-op/echo_op.cpp] -[import ../example/http-client/http_client.cpp] -[import ../example/websocket-client/websocket_client.cpp] - -[import ../include/beast/http/file_body.hpp] - -[import ../test/exemplars.cpp] -[import ../test/core/doc_snippets.cpp] -[import ../test/http/doc_snippets.cpp] -[import ../test/websocket/doc_snippets.cpp] - -[include 1_intro.qbk] -[include 2_examples.qbk] -[include 3_0_core.qbk] -[include 5_00_http.qbk] -[include 6_0_http_examples.qbk] -[include 7_0_websocket.qbk] -[include 8_concepts.qbk] -[include 9_0_design.qbk] - -[section:quickref Reference] -[xinclude quickref.xml] -[endsect] - -[block'''This Page Intentionally Left Blank 1/2'''] -[section:ref This Page Intentionally Left Blank 2/2] -[include reference.qbk] -[endsect] -[block''''''] - -[xinclude index.xml] diff --git a/src/beast/doc/1_intro.qbk b/src/beast/doc/1_intro.qbk deleted file mode 100644 index 3927ebddb53..00000000000 --- a/src/beast/doc/1_intro.qbk +++ /dev/null @@ -1,96 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section:intro Introduction] - -Beast is a C++ header-only library serving as a foundation for writing -interoperable networking libraries by providing [*low-level HTTP/1, -WebSocket, and networking protocol] vocabulary types and algorithms -using the consistent asynchronous model of __Asio__. - -This library is designed for: - -* [*Symmetry:] Algorithms are role-agnostic; build clients, servers, or both. - -* [*Ease of Use:] __Asio__ users will immediately understand Beast. - -* [*Flexibility:] Users make the important decisions such as buffer or - thread management. - -* [*Performance:] Build applications handling thousands of connections or more. - -* [*Basis for Further Abstraction.] Components are well-suited for building upon. - -Beast is not an HTTP client or HTTP server, but it can be used to build -those things. - -[heading Motivation] - -Beast empowers users to create their own libraries, clients, and servers -using HTTP/1 and WebSocket. Code will be easier and faster to implement, -understand, and maintain, because Beast takes care of the low-level -protocol details. -The HTTP and WebSocket protocols drive most of the World Wide Web. -Every web browser implements these protocols to load webpages and -to enable client side programs (often written in JavaScript) to -communicate interactively. C++ benefits greatly from having a -standardized implementation of these protocols. - -[heading Requirements] - -[important - This library is for programmers familiar with __Asio__. Users who - wish to use asynchronous interfaces should already know how to - create concurrent network programs using callbacks or coroutines. -] - -Beast requires: - -* [*C++11:] Robust support for most language features. -* [*Boost:] Beast only works with Boost, not stand-alone Asio -* [*OpenSSL:] Optional, for using TLS/Secure sockets. - -Supported compilers: msvc-14+, gcc 4.8+, clang 3.6+ - -Sources are [*header-only]. To link a program using Beast successfully, add the -[@http://www.boost.org/libs/system/doc/reference.html Boost.System] -library to the list of linked libraries. If you use coroutines -you'll also need the -[@http://www.boost.org/libs/coroutine/doc/html/index.html Boost.Coroutine] -library. Please visit the -[@http://www.boost.org/doc/ Boost documentation] -for instructions on how to do this for your particular build system. - -[heading Credits] - -Boost.Asio is the inspiration behind which all of the interfaces and -implementation strategies are built. Some parts of the documentation are -written to closely resemble the wording and presentation of Boost.Asio -documentation. Credit goes to -[@https://github.com/chriskohlhoff Christopher Kohlhoff] -for his wonderful Asio library and the ideas in __N4588__ which power Beast. - -Beast would not be possible without the support of -[@https://www.ripple.com Ripple] -during the library's early development, or the ideas, time and patience -contributed by -[@https://github.com/JoelKatz David Schwartz], -[@https://github.com/ximinez Edward Hennis], -[@https://github.com/howardhinnant Howard Hinnant], -[@https://github.com/miguelportilla Miguel Portilla], -[@https://github.com/nbougalis Nik Bougalis], -[@https://github.com/seelabs Scott Determan], -[@https://github.com/scottschurr Scott Schurr], -Many thanks to -[@https://github.com/K-ballo Agustín Bergé], -[@http://www.boost.org/users/people/glen_fernandes.html Glen Fernandes], -and -[@https://github.com/pdimov Peter Dimov] -for tirelessly answering questions on -[@https://cpplang.slack.com/ Cpplang-Slack]. - -[endsect] diff --git a/src/beast/doc/2_examples.qbk b/src/beast/doc/2_examples.qbk deleted file mode 100644 index 31cd55650e3..00000000000 --- a/src/beast/doc/2_examples.qbk +++ /dev/null @@ -1,192 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section:quickstart Quick Start] -[block''''''] - -These complete programs are intended to quickly impress upon readers -the flavor of the library. Source code and build scripts for them are -located in the example/ directory. - -[section HTTP Client] - -Use HTTP to make a GET request to a website and print the response: - -File: [repo_file example/http-client/http_client.cpp] - -[example_http_client] - -[endsect] - -[section WebSocket Client] - -Establish a WebSocket connection, send a message and receive the reply: - -File: [repo_file example/websocket-client/websocket_client.cpp] - -[example_websocket_client] - -[endsect] - -[endsect] - - - -[section:examples Examples] -[block''''''] - -Source code and build scripts for these programs are located -in the example/ directory. - - - -[section HTTP Crawl] - -This example retrieves the page at each of the most popular domains -as measured by Alexa. - -* [repo_file example/http-crawl/http_crawl.cpp] - -[endsect] - - - -[section HTTP Client (with SSL)] - -This example demonstrates sending and receiving HTTP messages -over a TLS connection. Requires OpenSSL to build. - -* [repo_file example/http-client-ssl/http_client_ssl.cpp] - -[endsect] - - - -[section HTTP Server (Fast)] - -This example implements a very simple HTTP server with -some optimizations suitable for calculating benchmarks. - -* [repo_file example/http-server-fast/fields_alloc.hpp] -* [repo_file example/http-server-fast/http_server_fast.cpp] - -[endsect] - - - -[section HTTP Server (Small)] - -This example implements a very simple HTTP server -suitable as a starting point on an embedded device. - -* [repo_file example/http-server-small/http_server_small.cpp] - -[endsect] - - - -[section HTTP Server (Threaded)] - -This example implements a very simple HTTP server using -synchronous interfaces and using one thread per connection: - -* [repo_file example/http-server-threaded/http_server_threaded.cpp] - -[endsect] - - - -[section WebSocket Client (with SSL)] - -Establish a WebSocket connection over an encrypted TLS connection, -send a message and receive the reply. Requires OpenSSL to build. - -* [repo_file example/websocket-client-ssl/websocket_client_ssl.cpp] - -[endsect] - - - -[section WebSocket Server (Asynchronous)] - -This program implements a WebSocket echo server using asynchronous -interfaces and a configurable number of threads. - -* [repo_file example/websocket-server-async/websocket_server_async.cpp] - -[endsect] - - - -[section Documentation Samples] - -Here are all of the example functions and classes presented -throughout the documentation, they can be included and used -in your program without modification - -* [repo_file example/doc/http_examples.hpp] - -[endsect] - - - -[section Composed Operations] - -This program shows how to use Beast's network foundations to build a -composable asynchronous initiation function with associated composed -operation implementation. This is a complete, runnable version of -the example described in the Core Foundations document section. - -* [repo_file example/echo-op/echo_op.cpp] - -[endsect] - - - -[section Common Code] - -This code is reused between some of the examples. The header files -stand alone can be directly included in your projects. - -* [repo_file example/common/detect_ssl.hpp] -* [repo_file example/common/helpers.hpp] -* [repo_file example/common/mime_types.hpp] -* [repo_file example/common/rfc7231.hpp] -* [repo_file example/common/ssl_stream.hpp] -* [repo_file example/common/write_msg.hpp] - -[endsect] - - - -[section Server Framework] - -This is a complete program and framework of classes implementing -a general purpose server that users may copy to use as the basis -for writing their own servers. It serves both HTTP and WebSocket. - -* [repo_file example/server-framework/file_service.hpp] -* [repo_file example/server-framework/framework.hpp] -* [repo_file example/server-framework/http_async_port.hpp] -* [repo_file example/server-framework/http_base.hpp] -* [repo_file example/server-framework/http_sync_port.hpp] -* [repo_file example/server-framework/https_ports.hpp] -* [repo_file example/server-framework/main.cpp] -* [repo_file example/server-framework/multi_port.hpp] -* [repo_file example/server-framework/server.hpp] -* [repo_file example/server-framework/service_list.hpp] -* [repo_file example/server-framework/ssl_certificate.hpp] -* [repo_file example/server-framework/ws_async_port.hpp] -* [repo_file example/server-framework/ws_sync_port.hpp] -* [repo_file example/server-framework/ws_upgrade_service.hpp] -* [repo_file example/server-framework/wss_ports.hpp] - -[endsect] - - - -[endsect] diff --git a/src/beast/doc/3_0_core.qbk b/src/beast/doc/3_0_core.qbk deleted file mode 100644 index 634c730ed85..00000000000 --- a/src/beast/doc/3_0_core.qbk +++ /dev/null @@ -1,33 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section:using_io Using I/O] - -This library makes I/O primitives used by the implementation publicly -available so users can take advantage of them in their own libraries. -These primitives include traits, buffers, buffer algorithms, files, -and helpers for implementing asynchronous operations compatible with -__Asio__ and described in __N3747__. This section lists these facilities -by group, with descriptions. - -[important - This documentation assumes familiarity with __Asio__. Sample - code and identifiers used throughout are written as if the - following declarations are in effect: - - [snippet_core_1a] - [snippet_core_1b] -] - -[include 3_1_asio.qbk] -[include 3_2_streams.qbk] -[include 3_3_buffers.qbk] -[include 3_4_files.qbk] -[include 3_5_composed.qbk] -[include 3_6_detect_ssl.qbk] - -[endsect] diff --git a/src/beast/doc/3_1_asio.qbk b/src/beast/doc/3_1_asio.qbk deleted file mode 100644 index 9070dac7c1e..00000000000 --- a/src/beast/doc/3_1_asio.qbk +++ /dev/null @@ -1,62 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section Asio Refresher] - -[warning - Beast does not manage sockets, make outgoing connections, - accept incoming connections, handle timeouts, close endpoints, - do name lookups, deal with TLS certificates, perform authentication, - or otherwise handle any aspect of connection management. This is - left to the interfaces already existing on the underlying streams. -] - -Library stream algorithms require a __socket__, __ssl_stream__, or other -__Stream__ object that has already established communication with an -endpoint. This example is provided as a reminder of how to work with -sockets: - -[snippet_core_2] - -Throughout this documentation identifiers with the following names have -special meaning: - -[table Global Variables -[[Name][Description]] -[[ - [@http://www.boost.org/doc/html/boost_asio/reference/io_service.html [*`ios`]] -][ - A variable of type - [@http://www.boost.org/doc/html/boost_asio/reference/io_service.html `boost::asio::io_service`] - which is running on one separate thread, and upon which a - [@http://www.boost.org/doc/html/boost_asio/reference/io_service__work.html `boost::asio::io_service::work`] - object has been constructed. -]] -[[ - [@http://www.boost.org/doc/html/boost_asio/reference/ip__tcp/socket.html [*`sock`]] -][ - A variable of type - [@http://www.boost.org/doc/html/boost_asio/reference/ip__tcp/socket.html `boost::asio::ip::tcp::socket`] - which has already been connected to a remote host. -]] -[[ - [@http://www.boost.org/doc/html/boost_asio/reference/ssl__stream.html [*`ssl_sock`]] -][ - A variable of type - [@http://www.boost.org/doc/html/boost_asio/reference/ssl__stream.html `boost::asio::ssl::stream`] - which is already connected and has handshaked with a remote host. -]] -[[ - [link beast.ref.beast__websocket__stream [*`ws`]] -][ - A variable of type - [link beast.ref.beast__websocket__stream `websocket::stream`] - which is already connected with a remote host. -]] -] - -[endsect] diff --git a/src/beast/doc/3_2_streams.qbk b/src/beast/doc/3_2_streams.qbk deleted file mode 100644 index 1778dff5010..00000000000 --- a/src/beast/doc/3_2_streams.qbk +++ /dev/null @@ -1,120 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section Stream Types] - -A __Stream__ is a communication channel where data is transferred as -an ordered sequence of octet buffers. Streams are either synchronous -or asynchronous, and may allow reading, writing, or both. Note that -a particular type may model more than one concept. For example, the -Asio types __socket__ and __ssl_stream__ support both __SyncStream__ -and __AsyncStream__. All stream algorithms in Beast are declared as -template functions using these concepts: - -[table Stream Concepts -[[Concept][Description]] -[ - [__SyncReadStream__] - [ - Supports buffer-oriented blocking reads. - ] -][ - [__SyncWriteStream__] - [ - Supports buffer-oriented blocking writes. - ] -][ - [__SyncStream__] - [ - A stream supporting buffer-oriented blocking reads and writes. - ] -][ - [__AsyncReadStream__] - [ - Supports buffer-oriented asynchronous reads. - ] -][ - [__AsyncWriteStream__] - [ - Supports buffer-oriented asynchronous writes. - ] -][ - [__AsyncStream__] - [ - A stream supporting buffer-oriented asynchronous reads and writes. - ] -] -] - -These template metafunctions check whether a given type meets the -requirements for the various stream concepts, and some additional -useful utilities. The library uses these type checks internally -and also provides them as public interfaces so users may use the -same techniques to augment their own code. The use of these type -checks helps provide more concise errors during compilation: - -[table Stream Type Checks -[[Name][Description]] -[[ - [link beast.ref.beast__get_lowest_layer `get_lowest_layer`] -][ - Returns `T::lowest_layer_type` if it exists, else returns `T`. -]] -[[ - [link beast.ref.beast__has_get_io_service `has_get_io_service`] -][ - Determine if the `get_io_service` member function is present, - and returns an __io_service__. -]] -[[ - [link beast.ref.beast__is_async_read_stream `is_async_read_stream`] -][ - Determine if a type meets the requirements of __AsyncReadStream__. -]] -[[ - [link beast.ref.beast__is_async_stream `is_async_stream`] -][ - Determine if a type meets the requirements of both __AsyncReadStream__ - and __AsyncWriteStream__. -]] -[[ - [link beast.ref.beast__is_async_write_stream `is_async_write_stream`] -][ - Determine if a type meets the requirements of __AsyncWriteStream__. -]] -[[ - [link beast.ref.beast__is_completion_handler `is_completion_handler`] -][ - Determine if a type meets the requirements of __CompletionHandler__, - and is callable with a specified signature. -]] -[[ - [link beast.ref.beast__is_sync_read_stream `is_sync_read_stream`] -][ - Determine if a type meets the requirements of __SyncReadStream__. -]] -[[ - [link beast.ref.beast__is_sync_stream `is_sync_stream`] -][ - Determine if a type meets the requirements of both __SyncReadStream__ - and __SyncWriteStream__. -]] -[[ - [link beast.ref.beast__is_sync_write_stream `is_sync_write_stream`] -][ - Determine if a type meets the requirements of __SyncWriteStream__. -]] -] - -Using the type checks with `static_assert` on function or class template -types will provide users with helpful error messages and prevent undefined -behaviors. This example shows how a template function which writes to a -synchronous stream may check its argument: - -[snippet_core_3] - -[endsect] diff --git a/src/beast/doc/3_3_buffers.qbk b/src/beast/doc/3_3_buffers.qbk deleted file mode 100644 index 21d9df3ed05..00000000000 --- a/src/beast/doc/3_3_buffers.qbk +++ /dev/null @@ -1,161 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section Buffer Types] - -__Asio__ provides the __ConstBufferSequence__ and __MutableBufferSequence__ -concepts, whose models provide ranges of buffers, as well as the __streambuf__ -class which encapsulates memory storage that may be automatically resized as -required, where the memory is divided into an input sequence followed by an -output sequence. The Networking TS (__N4588__) generalizes this `streambuf` -interface into the __DynamicBuffer__ concept. Beast algorithms which require -resizable buffers accept dynamic buffer objects as templated parameters. -These metafunctions check if types match the buffer concepts: - -[table Buffer Type Checks -[[Name][Description]] -[[ - [link beast.ref.beast__is_dynamic_buffer `is_dynamic_buffer`] -][ - Determine if a type meets the requirements of __DynamicBuffer__. -]] -[[ - [link beast.ref.beast__is_const_buffer_sequence `is_const_buffer_sequence`] -][ - Determine if a type meets the requirements of __ConstBufferSequence__. -]] -[[ - [link beast.ref.beast__is_mutable_buffer_sequence `is_mutable_buffer_sequence`] -][ - Determine if a type meets the requirements of __MutableBufferSequence__. -]] -] - -Beast provides several dynamic buffer implementations for a variety -of scenarios: - -[table Dynamic Buffer Implementations -[[Name][Description]] -[[ - [link beast.ref.beast__buffers_adapter `buffers_adapter`] -][ - This wrapper adapts any __MutableBufferSequence__ into a - __DynamicBuffer__ with an upper limit on the total size of the input and - output areas equal to the size of the underlying mutable buffer sequence. - The implementation does not perform heap allocations. -]] -[[ - [link beast.ref.beast__drain_buffer `drain_buffer`] -][ - A drain buffer has a small internal buffer and maximum size that - uses no dynamic allocation. It always has a size of zero, and - silently discards its input. This buffer may be passed to functions - which store data in a dynamic buffer when the caller wishes to - efficiently discard the data. -]] -[[ - [link beast.ref.beast__flat_buffer `flat_buffer`] - [link beast.ref.beast__basic_flat_buffer `basic_flat_buffer`] -][ - Guarantees that input and output areas are buffer sequences with - length one. Upon construction an optional upper limit to the total - size of the input and output areas may be set. The basic container - is an - [@http://en.cppreference.com/w/cpp/concept/AllocatorAwareContainer [*AllocatorAwareContainer]]. -]] -[[ - [link beast.ref.beast__multi_buffer `multi_buffer`] - [link beast.ref.beast__basic_multi_buffer `basic_multi_buffer`] -][ - Uses a sequence of one or more character arrays of varying sizes. - Additional character array objects are appended to the sequence to - accommodate changes in the size of the character sequence. The basic - container is an - [@http://en.cppreference.com/w/cpp/concept/AllocatorAwareContainer [*AllocatorAwareContainer]]. -]] -[[ - [link beast.ref.beast__static_buffer `static_buffer`] - [link beast.ref.beast__static_buffer `static_buffer_n`] -][ - Provides the facilities of a dynamic buffer, subject to an upper - limit placed on the total size of the input and output areas defined - by a constexpr template parameter. The storage for the sequences are - kept in the class; the implementation does not perform heap allocations. -]] -] - -Network applications frequently need to manipulate buffer sequences. To -facilitate working with buffers the library treats these sequences as -a special type of range. Algorithms and wrappers are provided which -transform these ranges efficiently using lazy evaluation. No memory -allocations are used in the transformations; instead, they create -lightweight iterators over the existing, unmodified memory buffers. -Control of buffers is retained by the caller; ownership is not -transferred. - -[table Buffer Algorithms and Types -[[Name][Description]] -[[ - [link beast.ref.beast__buffer_cat `buffer_cat`] -][ - This functions returns a new buffer sequence which, when iterated, - traverses the sequence which would be formed if all of the input buffer - sequences were concatenated. With this routine, multiple calls to a - stream's `write_some` function may be combined into one, eliminating - expensive system calls. -]] -[[ - [link beast.ref.beast__buffer_cat_view `buffer_cat_view`] -][ - This class represents the buffer sequence formed by concatenating - two or more buffer sequences. This is type of object returned by - [link beast.ref.beast__buffer_cat `buffer_cat`]. -]] -[[ - [link beast.ref.beast__buffer_prefix `buffer_prefix`] -][ - This function returns a new buffer or buffer sequence which represents - a prefix of the original buffers. -]] -[[ - [link beast.ref.beast__buffer_prefix_view `buffer_prefix_view`] -][ - This class represents the buffer sequence formed from a prefix of - an existing buffer sequence. This is the type of buffer returned by - [link beast.ref.beast__buffer_prefix.overload3 `buffer_prefix`]. -]] -[[ - [link beast.ref.beast__consuming_buffers `consuming_buffers`] -][ - This class wraps the underlying memory of an existing buffer sequence - and presents a suffix of the original sequence. The length of the suffix - may be progressively shortened. This lets callers work with sequential - increments of a buffer sequence. -]] -] - -These two functions facilitate buffer interoperability with standard -output streams. - -[table Buffer Output Streams -[[Name][Description]] -[[ - [link beast.ref.beast__buffers `buffers`] -][ - This function wraps a __ConstBufferSequence__ so it may be - used with `operator<<` and `std::ostream`. -]] -[[ - [link beast.ref.beast__ostream `ostream`] -][ - This function returns a `std::ostream` which wraps a dynamic buffer. - Characters sent to the stream using `operator<<` are stored in the - dynamic buffer. -]] -] - -[endsect] diff --git a/src/beast/doc/3_4_files.qbk b/src/beast/doc/3_4_files.qbk deleted file mode 100644 index 020875f0b41..00000000000 --- a/src/beast/doc/3_4_files.qbk +++ /dev/null @@ -1,38 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section:files Files] - -Often when implementing network algorithms such as servers, it is necessary -to interact with files on the system. Beast defines the __File__ concept -and several models to facilitate cross-platform interaction with the -underlying filesystem: - -[table File Types -[[Name][Description]] -[[ - [link beast.ref.beast__file_stdio `file_stdio`] -][ - This implementation of __File__ uses the C++ standard library - facilities obtained by including ``. -]] -[[ - [link beast.ref.beast__file_win32 `file_win32`] -][ - This implements a __File__ for the Win32 API. It provides low level - access to the native file handle when necessary. -]] -[[ - [link beast.ref.beast__file_posix `file_posix`] -][ - For POSIX systems, this class provides a suitable implementation - of __File__ which wraps the native file descriptor and provides - it if necessary. -]] -] - -[endsect] diff --git a/src/beast/doc/3_5_composed.qbk b/src/beast/doc/3_5_composed.qbk deleted file mode 100644 index 4d3eaa1ef1c..00000000000 --- a/src/beast/doc/3_5_composed.qbk +++ /dev/null @@ -1,236 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section Writing Composed Operations] -[block''''''] - -Asynchronous operations are started by calling a free function or member -function known as an asynchronous ['__async_initfn__]. This function accepts -parameters specific to the operation as well as a "completion token." The -token is either a completion handler, or a type defining how the caller is -informed of the asynchronous operation result. __Asio__ comes with the -special tokens __use_future__ and __yield_context__ for using futures -and coroutines respectively. This system of customizing the return value -and method of completion notification is known as the -['Extensible Asynchronous Model] described in __N3747__, and a built in -to __N4588__. Here is an example of an initiating function which reads a -line from the stream and echoes it back. This function is developed -further in the next section: - -[example_core_echo_op_1] - -Authors using Beast can reuse the library's primitives to create their -own initiating functions for performing a series of other, intermediate -asynchronous operations before invoking a final completion handler. -The set of intermediate actions produced by an initiating function is -known as a -[@http://blog.think-async.com/2009/08/composed-operations-coroutines-and-code.html ['composed operation]]. -To ensure full interoperability and well-defined behavior, __Asio__ imposes -requirements on the implementation of composed operations. These classes -and functions make it easier to develop initiating functions and their -composed operations: - -[table Asynchronous Helpers -[[Name][Description]] -[[ - [link beast.ref.beast__async_completion `async_completion`] -][ - This class aggregates the completion handler customization point and - the asynchronous initiation function return value customization point - into a single object which exposes the appropriate output types for the - given input types, and also contains boilerplate that is necessary to - implement an initiation function using the Extensible Model. -]] -[[ - [link beast.ref.beast__async_return_type `async_return_type`] -][ - This template alias determines the return value of an asynchronous - initiation function given the completion token and signature. It is used - by asynchronous initiation functions to meet the requirements of the - Extensible Asynchronous Model. -]] -[[ - [link beast.ref.beast__bind_handler `bind_handler`] -][ - This function returns a new, nullary completion handler which when - invoked with no arguments invokes the original completion handler with a - list of bound arguments. The invocation is made from the same implicit - or explicit strand as that which would be used to invoke the original - handler. This is accomplished by using the correct overload of - `asio_handler_invoke` associated with the original completion handler. - -]] -[[ - [link beast.ref.beast__handler_alloc `handler_alloc`] -][ - This class meets the requirements of [*Allocator], and uses any custom - memory allocation and deallocation hooks associated with a given handler. - It is useful for when a composed operation requires temporary dynamic - allocations to achieve its result. Memory allocated using this allocator - must be freed before the final completion handler is invoked. -]] -[[ - [link beast.ref.beast__handler_ptr `handler_ptr`] -][ - This is a smart pointer container used to manage the internal state of a - composed operation. It is useful when the state is non trivial. For example - when the state has non-copyable or expensive to copy types. The container - takes ownership of the final completion handler, and provides boilerplate - to invoke the final handler in a way that also deletes the internal state. - The internal state is allocated using the final completion handler's - associated allocator, benefiting from all handler memory management - optimizations transparently. -]] -[[ - [link beast.ref.beast__handler_type `handler_type`] -][ - This template alias converts a completion token and signature to the - correct completion handler type. It is used in the implementation of - asynchronous initiation functions to meet the requirements of the - Extensible Asynchronous Model. -]] -] - - - -[section Echo] - -This example develops an initiating function called [*echo]. -The operation will read up to the first newline on a stream, and -then write the same line including the newline back on the stream. -The implementation performs both reading and writing, and has a -non-trivially-copyable state. -First we define the input parameters and results, then declare our -initiation function. For our echo operation the only inputs are the -stream and the completion token. The output is the error code which -is usually included in all completion handler signatures. - -[example_core_echo_op_2] - -Now that we have a declaration, we will define the body of the function. -We want to achieve the following goals: perform static type checking on -the input parameters, set up the return value as per __N3747__, and launch -the composed operation by constructing the object and invoking it. - -[example_core_echo_op_3] - -The initiating function contains a few relatively simple parts. There is -the customization of the return value type, static type checking, building -the return value type using the helper, and creating and launching the -composed operation object. The [*`echo_op`] object does most of the work -here, and has a somewhat non-trivial structure. This structure is necessary -to meet the stringent requirements of composed operations (described in more -detail in the __Asio__ documentation). We will touch on these requirements -without explaining them in depth. - -Here is the boilerplate present in all composed operations written -in this style: - -[example_core_echo_op_4] - -Next is to implement the function call operator. Our strategy is to make our -composed object meet the requirements of a completion handler by being copyable -(also movable), and by providing the function call operator with the correct -signature. Rather than using `std::bind` or `boost::bind`, which destroys -the type information and therefore breaks the allocation and invocation -hooks, we will simply pass `std::move(*this)` as the completion handler -parameter for any operations that we initiate. For the move to work correctly, -care must be taken to ensure that no access to data members are made after the -move takes place. Here is the implementation of the function call operator for -this echo operation: - -[example_core_echo_op_5] - -This is the most important element of writing a composed operation, and -the part which is often neglected or implemented incorrectly. It is the -declaration and definition of the "handler hooks". There are four hooks: - -[table Handler Hooks -[[Name][Description]] -[[ - [@http://www.boost.org/doc/html/boost_asio/reference/asio_handler_invoke.html `asio_handler_invoke`] -][ - Default invoke function for handlers. This hooking function ensures - that the invoked method used for the final handler is accessible at - each intermediate step. -]] -[[ - [@http://www.boost.org/doc/html/boost_asio/reference/asio_handler_allocate.html `asio_handler_allocate`] -][ - Default allocation function for handlers. Implement `asio_handler_allocate` - and `asio_handler_deallocate` for your own handlers to provide custom - allocation for temporary objects. -]] -[[ - [@http://www.boost.org/doc/html/boost_asio/reference/asio_handler_deallocate.html `asio_handler_deallocate`] -][ - Default deallocation function for handlers. Implement `asio_handler_allocate` - and `asio_handler_deallocate` for your own handlers to provide custom - allocation for temporary objects. -]] -[[ - [@http://www.boost.org/doc/html/boost_asio/reference/asio_handler_is_continuation.html `asio_handler_is_continuation`] -][ - Default continuation function for handlers. Implement - `asio_handler_is_continuation` for your own handlers to indicate when - a handler represents a continuation. -]] -] - -Our composed operation stores the final handler and performs its own -intermediate asynchronous operations. To ensure that I/O objects, in this -case the stream, are accessed safely it is important to use the same method -to invoke intermediate handlers as that used to invoke the final handler. -Similarly, for the memory allocation hooks our composed operation should use -the same hooks as those used by the final handler. And finally for the -`asio_is_continuation` hook, we want to return `true` for any intermediate -asynchronous operations we perform after the first one, since those represent -continuations. For the first asynchronous operation we perform, the hook should -return `true` only if the final handler also represents a continuation. Our -implementation of the hooks will forward the call to the corresponding -overloads of the final handler: - -[example_core_echo_op_6] - -There are some common mistakes that should be avoided when writing -composed operations: - -* Type erasing the final handler. This will cause undefined behavior. - -* Not using `std::addressof` to get the address of the handler. - -* Forgetting to include a return statement after calling an - initiating function. - -* Calling a synchronous function by accident. In general composed - operations should not block for long periods of time, since this - ties up a thread running on the __io_service__. - -* Forgetting to overload `asio_handler_invoke` for the composed - operation. This will cause undefined behavior if someone calls - the initiating function with a strand-wrapped function object, - and there is more than thread running on the `io_service`. - -* For operations which complete immediately (i.e. without calling an - intermediate initiating function), forgetting to use `io_service::post` - to invoke the final handler. This breaks the following initiating - function guarantee: ['Regardless of whether the asynchronous operation - completes immediately or not, the handler will not be invoked from - within this function. Invocation of the handler will be performed - in a manner equivalent to using `boost::asio::io_service::post`]. - The function - [link beast.ref.beast__bind_handler `bind_handler`] - is provided for this purpose. - -A complete, runnable version of this example may be found in the examples -directory. - -[endsect] - - - -[endsect] diff --git a/src/beast/doc/3_6_detect_ssl.qbk b/src/beast/doc/3_6_detect_ssl.qbk deleted file mode 100644 index da6350b8236..00000000000 --- a/src/beast/doc/3_6_detect_ssl.qbk +++ /dev/null @@ -1,67 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section Example: Detect SSL] - -In this example we will build a simple function to detect the presence -of the SSL handshake given an input buffer sequence. Then we build on -the example by adding a synchronous stream algorithm. Finally, we -implemement an asynchronous detection function using a composed operation. -This SSL detector may be used to allow a server to accept both SSL/TLS and -unencrypted connections at the same port. - -Here is the declaration for a function to detect the SSL client handshake. -The input to the function is simply a buffer sequence, no stream. This -allows the detection algorithm to be used elsewhere. - -[example_core_detect_ssl_1] - -The implementation checks the buffer for the presence of the SSL -Handshake message octet sequence and returns an apporopriate value: - -[example_core_detect_ssl_2] - -Now we define a stream operation. We start with the simple, -synchronous version which takes the stream and buffer as input: - -[example_core_detect_ssl_3] - -The synchronous algorithm is the model for building the asynchronous -operation which has more boilerplate. First, we declare the asynchronous -initiating function: - -[example_core_detect_ssl_4] - -The implementation of the initiating function is straightforward -and contains mostly boilerplate. It is to construct the return -type customization helper to obtain the actual handler, and -then create the composed operation and launch it. The actual -code for interacting with the stream is in the composed operation, -which is written as a separate class. - -[example_core_detect_ssl_5] - -Now we will declare our composed operation. There is a considerable -amount of necessary boilerplate to get this right, but the result -is worth the effort. - -[example_core_detect_ssl_6] - -The boilerplate is all done, and now we need to implement the function -call operator that turns this composed operation a completion handler -with the signature `void(error_code, std::size_t)` which is exactly -the signature needed when performing asynchronous reads. This function -is a transformation of the synchronous version of `detect_ssl` above, -but with the inversion of flow that characterizes code written in the -callback style: - -[example_core_detect_ssl_7] - -This SSL detector is used by the server framework in the example -directory. - -[endsect] diff --git a/src/beast/doc/5_00_http.qbk b/src/beast/doc/5_00_http.qbk deleted file mode 100644 index 6a90c066a3d..00000000000 --- a/src/beast/doc/5_00_http.qbk +++ /dev/null @@ -1,91 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section Using HTTP] - -[warning - Higher level functions such as Basic - Authentication, mime/multipart encoding, cookies, automatic handling - of redirects, gzipped transfer encodings, caching, or proxying (to name - a few) are not directly provided, but nothing stops users from creating - these features using Beast's HTTP message types. -] - -This library offers programmers simple and performant models of HTTP messages -and their associated operations including synchronous, asynchronous, and -buffer-oriented parsing and serialization of messages in the HTTP/1 wire -format using __Asio__. Specifically, the library provides: - -[variablelist -[ - [Message Containers] - [ - Complete HTTP messages are modeled using the __message__ class, - with possible user customizations. - ] -][ - [Stream Reading] - [ - The functions - [link beast.ref.beast__http__read `read`], - [link beast.ref.beast__http__read_header `read_header`], - [link beast.ref.beast__http__read_some `read_some`], - [link beast.ref.beast__http__async_read `async_read`], - [link beast.ref.beast__http__async_read_header `async_read_header`], and - [link beast.ref.beast__http__async_read_some `async_read_some`] - read HTTP/1 message data from a - [link beast.concept.streams stream]. -] -][ - [Stream Writing] - [ - The functions - [link beast.ref.beast__http__write `write`], - [link beast.ref.beast__http__write_header `write_header`], - [link beast.ref.beast__http__write_some `write_some`], - [link beast.ref.beast__http__async_write `async_write`], - [link beast.ref.beast__http__async_write_header `async_write_header`], and - [link beast.ref.beast__http__async_write_some `async_write_some`] - write HTTP/1 message data to a - [link beast.concept.streams stream]. - ] -][ - [Serialization] - [ - The __serializer__ produces a series of octet buffers - conforming to the __rfc7230__ wire representation of - a __message__. - ] -][ - [Parsing] - [ - The __parser__ attempts to convert a series of octet - buffers into a __message__. - ] -] -] - -[note - This documentation assumes some familiarity with __Asio__ and - the HTTP protocol specification described in __rfc7230__. Sample - code and identifiers mentioned in this section is written as if - these declarations are in effect: - - [http_snippet_1] -] - -[include 5_01_primer.qbk] -[include 5_02_message.qbk] -[include 5_03_streams.qbk] -[include 5_04_serializer_streams.qbk] -[include 5_05_parser_streams.qbk] -[include 5_06_serializer_buffers.qbk] -[include 5_07_parser_buffers.qbk] -[include 5_08_custom_body.qbk] -[include 5_09_custom_parsers.qbk] - -[endsect] diff --git a/src/beast/doc/5_01_primer.qbk b/src/beast/doc/5_01_primer.qbk deleted file mode 100644 index 78bd5d051e9..00000000000 --- a/src/beast/doc/5_01_primer.qbk +++ /dev/null @@ -1,153 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section Protocol Primer] - -The HTTP protocol defines the -[@https://tools.ietf.org/html/rfc7230#section-2.1 client and server roles]: -clients send requests and servers send back responses. When a client and -server have established a connection, the client sends a series of requests -while the server sends back at least one response for each received request -in the order those requests were received. - -A request or response is an -[@https://tools.ietf.org/html/rfc7230#section-3 HTTP message] -(referred to hereafter as "message") having two parts: -a header with structured metadata and an optional variable-length body -holding arbitrary data. A serialized header is one or more text lines -where each line ends in a carriage return followed by linefeed (`"\r\n"`). -An empty line marks the end of the header. The first line in the header -is called the ['start-line]. The contents of the start line contents are -different for requests and responses. - -Every message contains a set of zero or more field name/value pairs, -collectively called "fields". The names and values are represented using -text strings with various requirements. A serialized field contains the -field name, then a colon followed by a space (`": "`), and finally the field -value with a trailing CRLF. - -[heading Requests] - -Clients send requests, which contain a -[@https://tools.ietf.org/html/rfc7230#section-3.1.1 method] -and -[@https://tools.ietf.org/html/rfc7230#section-5.3 request-target], -and -[@https://tools.ietf.org/html/rfc7230#section-2.6 HTTP-version]. -The method identifies the operation to be performed while the target -identifies the object on the server to which the operation applies. -The version is almost always 1.1, but older programs sometimes use 1.0. - -[table -[[Serialized Request][Description]] -[[ -``` - GET / HTTP/1.1\r\n - User-Agent: Beast\r\n - \r\n -``` -][ - This request has a method of "GET", a target of "/", and indicates - HTTP version 1.1. It contains a single field called "User-Agent" - whose value is "Beast". There is no message body. -]] -] - -[heading Responses] - -Servers send responses, which contain a -[@https://tools.ietf.org/html/rfc7231#section-6 status-code], -[@https://tools.ietf.org/html/rfc7230#section-3.1.2 reason-phrase], and -[@https://tools.ietf.org/html/rfc7230#section-2.6 HTTP-version]. -The reason phrase is -[@https://tools.ietf.org/html/rfc7230#section-3.1.2 obsolete]: -clients SHOULD ignore the reason-phrase content. Here is a response which -includes a body. The special -[@https://tools.ietf.org/html/rfc7230#section-3.3.2 Content-Length] -field informs the remote host of the size of the body which follows. - -[table -[[Serialized Response][Description]] -[[ -``` - HTTP/1.1 200 OK\r\n - Server: Beast\r\n - Content-Length: 13\r\n - \r\n - Hello, world! -``` -][ - This response has a - [@https://tools.ietf.org/html/rfc7231#section-6 200 status code] - meaning the operation requested completed successfully. The obsolete - reason phrase is "OK". It specifies HTTP version 1.1, and contains - a body 13 octets in size with the text "Hello, world!". -]] -] - -[heading Body] - -Messages may optionally carry a body. The size of the message body -is determined by the semantics of the message and the special fields -Content-Length and Transfer-Encoding. -[@https://tools.ietf.org/html/rfc7230#section-3.3 rfc7230 section 3.3] -provides a comprehensive description for how the body length is -determined. - -[heading Special Fields] - -Certain fields appearing in messages are special. The library understands -these fields when performing serialization and parsing, taking automatic -action as needed when the fields are parsed in a message and also setting -the fields if the caller requests it. - -[table Special Fields -[[Field][Description]] -[ - [ - [@https://tools.ietf.org/html/rfc7230#section-6.1 [*`Connection`]] - - [@https://tools.ietf.org/html/rfc7230#appendix-A.1.2 [*`Proxy-Connection`]] - ][ - This field allows the sender to indicate desired control options - for the current connection. Common values include "close", - "keep-alive", and "upgrade". - ] -][ - [ - [@https://tools.ietf.org/html/rfc7230#section-3.3.2 [*`Content-Length`]] - ][ - When present, this field informs the recipient about the exact - size in bytes of the body which follows the message header. - ] -][ - [ - [@https://tools.ietf.org/html/rfc7230#section-3.3.1 [*`Transfer-Encoding`]] - ][ - This optional field lists the names of the sequence of transfer codings - that have been (or will be) applied to the content payload to form - the message body. - - Beast understands the "chunked" coding scheme when it is the last - (outermost) applied coding. The library will automatically apply - chunked encoding when the content length is not known ahead of time - during serialization, and the library will automatically remove chunked - encoding from parsed messages when present. - ] -][ - [ - [@https://tools.ietf.org/html/rfc7230#section-6.7 [*`Upgrade`]] - ][ - The Upgrade header field provides a mechanism to transition from - HTTP/1.1 to another protocol on the same connection. For example, it - is the mechanism used by WebSocket's initial HTTP handshake to - establish a WebSocket connection. - ] -] -] - -[endsect] diff --git a/src/beast/doc/5_02_message.qbk b/src/beast/doc/5_02_message.qbk deleted file mode 100644 index f9f4a3decbd..00000000000 --- a/src/beast/doc/5_02_message.qbk +++ /dev/null @@ -1,231 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section Message Containers] - -Beast provides a single class template __message__ and some aliases which -model HTTP/1 and -[@https://tools.ietf.org/html/rfc7540 HTTP/2] -messages: - -[table Message -[[Name][Description]] -[[ - __message__ -][ - ``` - /// An HTTP message - template< - bool isRequest, // `true` for requests, `false` for responses - class Body, // Controls the container and algorithms used for the body - class Fields = fields> // The type of container to store the fields - class message; - ``` -]] -[[ - [link beast.ref.beast__http__request `request`] -][ - ``` - /// A typical HTTP request - template - using request = message; - ``` -]] -[[ - [link beast.ref.beast__http__response `response`] -][ - ``` - /// A typical HTTP response - template - using response = message; - ``` -]] -] - -The container offers value semantics including move and copy if supported -by __Body__ and __Fields__. User defined template function parameters can -accept any message, or can use partial specialization to accept just -requests or responses. The default __fields__ is a provided associative -container using the standard allocator and supporting modification and -inspection of fields. As per __rfc7230__, a non-case-sensitive comparison -is used for field names. User defined types for fields are possible. -The `Body` type determines the type of the container used to represent the -body as well as the algorithms for transferring buffers to and from the -the container. The library comes with a collection of common body types. -As with fields, user defined body types are possible. - -Sometimes it is desired to only work with a header. Beast provides a single -class template __header__ and some aliases to model HTTP/1 and HTTP/2 headers: - -[table Header -[[Name][Description]] -[[ - __header__ -][ - ``` - /// An HTTP header - template< - bool isRequest, // `true` for requests, `false` for responses - class Fields = fields> // The type of container to store the fields - class header; - ``` -]] -[[ - [link beast.ref.beast__http__request_header `request_header`] -][ - ``` - /// A typical HTTP request header - template - using request_header = header; - ``` -]] -[[ - [link beast.ref.beast__http__response_header `response_header`] -][ - ``` - /// A typical HTTP response header - template - using response_header = header; - ``` -]] -] - -Requests and responses share the version, fields, and body but have -a few members unique to the type. This is implemented by declaring the -header classes as partial specializations of `isRequest`. __message__ -is derived from __header__; a message may be passed as an argument to -a function taking a suitably typed header as a parameter. Additionally, -`header` is publicly derived from `Fields`; a message inherits all the -member functions of `Fields`. This diagram shows the inheritance -relationship between header and message, along with some of the -notable differences in members in each partial specialization: - -[$images/message.png [width 730px] [height 410px]] - -[heading:body Body Types] - -Beast defines the __Body__ concept, which determines both the type of -the [link beast.ref.beast__http__message.body `message::body`] member -(as seen in the diagram above) and may also include algorithms for -transferring buffers in and out. These algorithms are used during -parsing and serialization. Users may define their own body types which -meet the requirements, or use the ones that come with the library: - -[table -[[Name][Description]] -[[ - [link beast.ref.beast__http__buffer_body `buffer_body`] -][ - A body whose - [link beast.ref.beast__http__buffer_body__value_type `value_type`] - holds a raw pointer and size to a caller-provided buffer. - This allows for serialization of body data coming from - external sources, and incremental parsing of message body - content using a fixed size buffer. -]] -[[ - [link beast.ref.beast__http__dynamic_body `dynamic_body`] - - [link beast.ref.beast__http__basic_dynamic_body `basic_dynamic_body`] -][ - A body whose `value_type` is a __DynamicBuffer__. It inherits - the insertion complexity of the underlying choice of dynamic buffer. - Messages with this body type may be serialized and parsed. -]] -[[ - [link beast.ref.beast__http__empty_body `empty_body`] -][ - A special body with an empty `value_type` indicating that the - message has no body. Messages with this body may be serialized - and parsed; however, body octets received while parsing a message - with this body will generate a unique error. -]] -[[ - [link beast.ref.beast__http__file_body `file_body`] -][ - This body is represented by a file opened for either reading or - writing. Messages with this body may be serialized and parsed. - HTTP algorithms will use the open file for reading and writing, - for streaming and incremental sends and receives. -]] -[[ - [link beast.ref.beast__http__span_body `span_body`] -][ - A body whose `value_type` is a - [link beast.ref.beast__span `span`], - a non-owning reference to a single linear buffer of bytes. - Messages with this body type may be serialized and parsed. -]] -[[ - [link beast.ref.beast__http__basic_string_body `basic_string_body`] - - [link beast.ref.beast__http__string_body `string_body`] -][ - A body whose `value_type` is `std::basic_string` or `std::string`. - Insertion complexity is amortized constant time, while capacity - grows geometrically. Messages with this body type may be serialized - and parsed. This is the type of body used in the examples. -]] -[[ - [link beast.ref.beast__http__vector_body `vector_body`] -][ - A body whose `value_type` is `std::vector`. Insertion complexity - is amortized constant time, while capacity grows geometrically. - Messages with this body type may be serialized and parsed. -]] -] - -[heading Usage] - -These examples show how to create and fill in request and response -objects: Here we build an -[@https://tools.ietf.org/html/rfc7231#section-4.3.1 HTTP GET] -request with an empty message body: - -[table Create Request -[[Statements] [Serialized Result]] -[[ - [http_snippet_2] -][ -``` - GET /index.htm HTTP/1.1\r\n - Accept: text/html\r\n - User-Agent: Beast\r\n - \r\n -``` -]] -] - -In this code we create an HTTP response with a status code indicating success. -This message has a body with a non-zero length. The function -[link beast.ref.beast__http__message.prepare_payload `message::prepare_payload`] -automatically sets the Content-Length or Transfer-Encoding field -depending on the content and type of the `body` member. Use of this function -is optional; these fields may also be set explicitly. - -[table Create Response -[[Statements] [Serialized Result]] -[[ - [http_snippet_3] -][ -``` - HTTP/1.1 200 OK\r\n - Server: Beast\r\n - Content-Length: 13\r\n - \r\n - Hello, world! -``` -]] -] - -The implementation will automatically fill in the obsolete -[@https://tools.ietf.org/html/rfc7230#section-3.1.2 reason-phrase] -from the status code when serializing a message. Or it may -be set directly using -[link beast.ref.beast__http__header.reason.overload2 `header::reason`]. - -[endsect] diff --git a/src/beast/doc/5_03_streams.qbk b/src/beast/doc/5_03_streams.qbk deleted file mode 100644 index 31cd8abc651..00000000000 --- a/src/beast/doc/5_03_streams.qbk +++ /dev/null @@ -1,107 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section Message Stream Operations] - -Beast provides synchronous and asynchronous algorithms to parse and -serialize HTTP/1 wire format messages on streams. These functions form -the message-oriented stream interface: - -[table Message Stream Operations -[[Name][Description]] -[[ - [link beast.ref.beast__http__read.overload3 [*read]] -][ - Read a __message__ from a __SyncReadStream__. -]] -[[ - [link beast.ref.beast__http__async_read.overload2 [*async_read]] -][ - Read a __message__ from an __AsyncReadStream__. -]] -[[ - [link beast.ref.beast__http__write.overload1 [*write]] -][ - Write a __message__ to a __SyncWriteStream__. -]] -[[ - [link beast.ref.beast__http__async_write [*async_write]] -][ - Write a __message__ to an __AsyncWriteStream__. -]] -] - -All synchronous stream operations come in two varieties. One which throws -an exception upon error, and another which accepts as the last parameter an -argument of type [link beast.ref.beast__error_code `error_code&`]. If an error -occurs this argument will be set to contain the error code. - - - -[heading Reading] - -Because a serialized header is not length-prefixed, algorithms which -parse messages from a stream may read past the end of a message for -efficiency. To hold this surplus data, all stream read operations use -a passed-in __DynamicBuffer__ which must be persisted between calls. -Each read operation may consume bytes remaining in the buffer, and -leave behind new bytes. In this example we declare the buffer and a -message variable, then read a complete HTTP request synchronously: - -[http_snippet_4] - -This example uses __flat_buffer__. Beast's __basic_parser__ is -optimized for structured HTTP data located in a single contiguous -(['flat]) memory buffer. When not using a flat buffer the implementation -may perform an additional memory allocations to restructure the input -into a single buffer for parsing. - -[tip - Other Implementations of __DynamicBuffer__ may avoid parser - memory allocation by always returning buffer sequences of - length one. -] - -Messages may also be read asynchronously. When performing asynchronous -stream read operations the stream, buffer, and message variables must -remain valid until the operation has completed. Beast asynchronous -initiation functions use Asio's completion handler model. This call -reads a message asynchronously and report the error code upon -completion: - -[http_snippet_5] - -If a read stream algorithm cannot complete its operation without exceeding -the maximum specified size of the dynamic buffer provided, the error -[link beast.ref.beast__http__error `buffer_overflow`] -is returned. This may be used to impose a limit on the maximum size of an -HTTP message header for protection from buffer overflow attacks. The -following code will print the error message: - -[http_snippet_6] - - - -[heading Writing] - -A set of free functions allow serialization of an entire HTTP message to -a stream. If a response has no declared content length and no chunked -transfer encoding, then the end of the message is indicated by the server -closing the connection. When sending such a response, Beast will return the -[link beast.ref.beast__http__error `error::end_of_stream`] -from the write algorithm to indicate -to the caller that the connection should be closed. This example -constructs and sends a response whose body length is determined by -the number of octets received prior to the server closing the connection: - -[http_snippet_7] - -The asynchronous version could be used instead: - -[http_snippet_8] - -[endsect] diff --git a/src/beast/doc/5_04_serializer_streams.qbk b/src/beast/doc/5_04_serializer_streams.qbk deleted file mode 100644 index 62a556ac290..00000000000 --- a/src/beast/doc/5_04_serializer_streams.qbk +++ /dev/null @@ -1,150 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section Serializer Stream Operations] - -Non-trivial algorithms need to do more than send entire messages -at once, such as: - -* Send the header first, and the body later. - -* Set chunk extensions or trailers using a chunk decorator. - -* Send a message incrementally: bounded work in each I/O cycle. - -* Use a series of caller-provided buffers to represent the body. - -These tasks may be performed by using the serializer stream interfaces. -To use these interfaces, first construct a suitable object with -the message to be sent: - -[table Serializer -[[Name][Description]] -[[ - __serializer__ -][ - ``` - /// Provides buffer oriented HTTP message serialization functionality. - template< - bool isRequest, - class Body, - class Fields = fields, - class ChunkDecorator = no_chunk_decorator - > - class serializer; - ``` -]] -[[ - [link beast.ref.beast__http__request_serializer `request_serializer`] -][ - ``` - /// A serializer for HTTP/1 requests - template< - class Body, - class Fields = fields, - class ChunkDecorator = no_chunk_decorator> - using request_serializer = serializer; - ``` -]] -[[ - [link beast.ref.beast__http__response_serializer `response_serializer`] -][ - ``` - /// A serializer for HTTP/1 responses - template< - class Body, - class Fields = fields, - class ChunkDecorator = no_chunk_decorator> - using response_serializer = serializer; - ``` -]] -] - -The choices for template types must match the message passed on construction. -This code creates an HTTP response and the corresponding serializer: - -[http_snippet_10] - -The stream operations which work on serializers are: - -[table Serializer Stream Operations -[[Name][Description]] -[[ - [link beast.ref.beast__http__write.overload1 [*write]] -][ - Send everything in a __serializer__ to a __SyncWriteStream__. -]] -[[ - [link beast.ref.beast__http__async_write.overload1 [*async_write]] -][ - Send everything in a __serializer__ asynchronously to an __AsyncWriteStream__. -]] -[[ - [link beast.ref.beast__http__write_header.overload1 [*write_header]] -][ - Send only the header from a __serializer__ to a __SyncWriteStream__. -]] -[[ - [link beast.ref.beast__http__async_write_header [*async_write_header]] -][ - Send only the header from a __serializer__ asynchronously to an __AsyncWriteStream__. -]] -[[ - [link beast.ref.beast__http__write_some.overload1 [*write_some]] -][ - Send part of a __serializer__ to a __SyncWriteStream__. -]] -[[ - [link beast.ref.beast__http__async_write_some [*async_write_some]] -][ - Send part of a __serializer__ asynchronously to an __AsyncWriteStream__. -]] -] - -Here is an example of using a serializer to send a message on a stream -synchronously. This performs the same operation as calling `write(stream, m)`: - -[http_snippet_12] - -[heading Chunk Decorators] - -When the message used to construct the serializer indicates the chunked -transfer encoding, the serializer will automatically generate the proper -encoding in the output buffers. __rfc7230__ defines additional fields -called the -[@https://tools.ietf.org/html/rfc7230#section-4.1.1 chunk extensions] -in chunks with body octets, and the -[@https://tools.ietf.org/html/rfc7230#section-4.1.2 chunked trailer part] -for the final chunk. Applications that wish to emit chunk extensions -and trailers may instantiate the serializer with a "chunk decorator" type, -and pass an instance of the type upon construction. This decorator is -a function object which, when invoked with a __ConstBufferSequence__, -returns a -[link beast.ref.beast__string_view `string_view`] containing either the extensions -or the trailer. For chunks containing body data, the passed buffer will -contain one or more corresponding body octets. The decorator may use this -information as needed. For example, to compute a digest on the data and -store it as a chunk extension. For the trailers, the serializer will -invoke the decorator with a buffer sequence of size zero. Or more -specifically, with an object of type -[@http://www.boost.org/doc/html/boost_asio/reference/null_buffers.html `boost::asio::null_buffers`]. - -For body chunks the string returned by the decorator must follow the -[@https://tools.ietf.org/html/rfc7230#section-4.1.1 correct syntax] -for the entire chunk extension. For the trailer, the returned string -should consist of zero or more lines ending in a CRLF and containing -a field name/value pair in the format prescribed by __rfc7230__. It -is the responsibility of the decorator to manage returned string buffers. -The implementation guarantees it will not reference previous strings -after subsequent calls. - -This defines a decorator which sets an extension variable `x` equal -to the size of the chunk in bytes, and returns a single trailer field: - -[http_snippet_17] - -[endsect] diff --git a/src/beast/doc/5_05_parser_streams.qbk b/src/beast/doc/5_05_parser_streams.qbk deleted file mode 100644 index 465e1a9fb7e..00000000000 --- a/src/beast/doc/5_05_parser_streams.qbk +++ /dev/null @@ -1,138 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section Parser Stream Operations] - -Non-trivial algorithms need to do more than receive entire messages -at once, such as: - - -* Receive the header first and body later. - -* Receive a large body using a fixed-size buffer. - -* Receive a message incrementally: bounded work in each I/O cycle. - -* Defer the commitment to a __Body__ type until after reading the header. - -These types of operations require callers to manage the lifetime of -associated state, by constructing a class derived from __basic_parser__. -Beast comes with the derived instance __parser__ which creates complete -__message__ objects using the __basic_fields__ Fields container. - -[table Parser -[[Name][Description]] -[[ - __parser__ -][ - ``` - /// An HTTP/1 parser for producing a message. - template< - bool isRequest, // `true` to parse an HTTP request - class Body, // The Body type for the resulting message - class Allocator = std::allocator> // The type of allocator for the header - class parser - : public basic_parser<...>; - ``` -]] -[[ - [link beast.ref.beast__http__request_parser `request_parser`] -][ - ``` - /// An HTTP/1 parser for producing a request message. - template> - using request_parser = parser; - ``` -]] -[[ - [link beast.ref.beast__http__response_parser `response_parser`] -][ - ``` - /// An HTTP/1 parser for producing a response message. - template> - using response_parser = parser; - ``` -]] -] - -[note - The __basic_parser__ and classes derived from it handle octet streams - serialized in the HTTP/1 format described in __rfc7230__. -] - -The stream operations which work on parsers are: - -[table Parser Stream Operations -[[Name][Description]] -[[ - [link beast.ref.beast__http__read.overload1 [*read]] -][ - Read everything into a parser from a __SyncWriteStream__. -]] -[[ - [link beast.ref.beast__http__async_read.overload1 [*async_read]] -][ - Read everything into a parser asynchronously from an __AsyncWriteStream__. -]] -[[ - [link beast.ref.beast__http__read_header.overload1 [*read_header]] -][ - Read only the header octets into a parser from a __SyncWriteStream__. -]] -[[ - [link beast.ref.beast__http__async_read_header [*async_read_header]] -][ - Read only the header octets into a parser asynchronously from an __AsyncWriteStream__. -]] -[[ - [link beast.ref.beast__http__read_some.overload1 [*read_some]] -][ - Read some octets into a parser from a __SyncReadStream__. -]] -[[ - [link beast.ref.beast__http__async_read_some [*async_read_some]] -][ - Read some octets into a parser asynchronously from an __AsyncWriteStream__. -]] -] - -As with message stream operations, parser stream operations require a -persisted __DynamicBuffer__ for holding unused octets from the stream. -The basic parser implementation is optimized for the case where this dynamic -buffer stores its input sequence in a single contiguous memory buffer. It is -advised to use an instance of __flat_buffer__, __static_buffer__, or -__static_buffer_n__ for this purpose, although a user defined instance of -__DynamicBuffer__ which produces input sequences of length one is also suitable. - -The parser contains a message constructed internally. Arguments passed -to the parser's constructor are forwarded into the message container. -The caller can access the message inside the parser by calling -[link beast.ref.beast__http__parser.get `parser::get`]. -If the `Fields` and `Body` types are [*MoveConstructible], the caller -can take ownership of the message by calling -[link beast.ref.beast__http__parser.release `parser::release`]. In this example -we read an HTTP response with a string body using a parser, then print -the response: - -[http_snippet_13] - - - -[section Incremental Read] - -This function uses -[link beast.ref.beast__http__buffer_body `buffer_body`] -and parser stream operations to read a message body progressively -using a small, fixed-size buffer: - -[example_incremental_read] - -[endsect] - - - -[endsect] diff --git a/src/beast/doc/5_06_serializer_buffers.qbk b/src/beast/doc/5_06_serializer_buffers.qbk deleted file mode 100644 index 8e2446e3b98..00000000000 --- a/src/beast/doc/5_06_serializer_buffers.qbk +++ /dev/null @@ -1,79 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section Buffer-Oriented Serializing] -[block''''''] - -An instance of __serializer__ can be invoked directly, without using -the provided stream operations. This could be useful for implementing -algorithms on objects whose interface does not conform to __Stream__. -For example, a -[@https://github.com/libuv/libuv *libuv* socket]. -The serializer interface is interactive; the caller invokes it repeatedly -to produce buffers until all of the buffers have been generated. Then the -serializer is destroyed. - -To obtain the serialized next buffer sequence, call -[link beast.ref.beast__http__serializer.next `serializer::next`]. -Then, call -[link beast.ref.beast__http__serializer.consume `serializer::consume`] -to indicate the number of bytes consumed. This updates the next -set of buffers to be returned, if any. -`serializer::next` takes an error code parameter and invokes a visitor -argument with the error code and buffer of unspecified type. In C++14 -this is easily expressed with a generic lambda. The function -[link beast.ref.beast__http__serializer.is_done `serializer::is_done`] -will return `true` when all the buffers have been produced. This C++14 -example prints the buffers to standard output: - -[http_snippet_14] - -Generic lambda expressions are only available in C++14 or later. A functor -with a templated function call operator is necessary to use C++11 as shown: - -[http_snippet_15] - -[heading Split Serialization] - -In some cases, such as the handling of the -[@https://tools.ietf.org/html/rfc7231#section-5.1.1 Expect: 100-continue] -field, it may be desired to first serialize the header, perform some other -action, and then continue with serialization of the body. This is -accomplished by calling -[link beast.ref.beast__http__serializer.split `serializer::split`] -with a boolean indicating that when buffers are produced, the last buffer -containing serialized header octets will not contain any octets corresponding -to the body. The function -[link beast.ref.beast__http__serializer.is_header_done `serializer::is_header_done`] -informs the caller whether the header been serialized fully. In this -C++14 example we print the header first, followed by the body: - -[http_snippet_16] - - - -[section Write To std::ostream] - -The standard library provides the type `std::ostream` for performing high -level write operations on character streams. The variable `std::cout` is -based on this output stream. This example uses the buffer oriented interface -of __serializer__ to write an HTTP message to a `std::ostream`: - -[example_http_write_ostream] - -[tip - Serializing to a `std::ostream` could be implemented using an alternate - strategy: adapt the `std::ostream` interface to a __SyncWriteStream__, - enabling use with the library's existing stream algorithms. This is - left as an exercise for the reader. -] - -[endsect] - - - -[endsect] diff --git a/src/beast/doc/5_07_parser_buffers.qbk b/src/beast/doc/5_07_parser_buffers.qbk deleted file mode 100644 index 11be8576c4e..00000000000 --- a/src/beast/doc/5_07_parser_buffers.qbk +++ /dev/null @@ -1,107 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section Buffer-Oriented Parsing] -[block''''''] - -A subclass of __basic_parser__ can be invoked directly, without using -the provided stream operations. This could be useful for implementing -algorithms on objects whose interface does not conform to __Stream__. -For example, a -[@http://zeromq.org/ *ZeroMQ* socket]. -The basic parser interface is interactive; the caller invokes the function -[link beast.ref.beast__http__basic_parser.put `basic_parser::put`] -repeatedly with buffers until an error occurs or the parsing is done. The -function -[link beast.ref.beast__http__basic_parser.put_eof `basic_parser::put_eof`] -Is used when the caller knows that there will never be more data (for example, -if the underlying connection is closed), - -[heading Parser Options] - -The parser provides a few options which may be set before parsing begins: - -[table Parser Options -[[Name][Default][Description]] -[[ - [link beast.ref.beast__http__basic_parser.eager.overload2 `eager`] -][ - `false` -][ - Normally the parser returns after successfully parsing a structured - element (header, chunk header, or chunk body) even if there are octets - remaining in the input. This is necessary when attempting to parse the - header first, or when the caller wants to inspect information which may - be invalidated by subsequent parsing, such as a chunk extension. The - `eager` option controls whether the parser keeps going after parsing - structured element if there are octets remaining in the buffer and no - error occurs. This option is automatically set or cleared during certain - stream operations to improve performance with no change in functionality. -]] -[[ - [link beast.ref.beast__http__basic_parser.skip.overload2 `skip`] -][ - `false` -][ - This option controls whether or not the parser expects to see an HTTP - body, regardless of the presence or absence of certain fields such as - Content-Length or a chunked Transfer-Encoding. Depending on the request, - some responses do not carry a body. For example, a 200 response to a - [@https://tools.ietf.org/html/rfc7231#section-4.3.6 CONNECT] request - from a tunneling proxy, or a response to a - [@https://tools.ietf.org/html/rfc7231#section-4.3.2 HEAD] request. - In these cases, callers may use this function inform the parser that - no body is expected. The parser will consider the message complete - after the header has been received. -]] -[[ - [link beast.ref.beast__http__basic_parser.body_limit `body_limit`] -][ - 1MB/8MB -][ - This function sets the maximum allowed size of the content body. - When a body larger than the specified size is detected, an error - is generated and parsing terminates. This setting helps protect - servers from resource exhaustion attacks. The default limit when - parsing requests is 1MB, and for parsing responses 8MB. -]] -[[ - [link beast.ref.beast__http__basic_parser.header_limit `header_limit`] -][ - 8KB -][ - This function sets the maximum allowed size of the header - including all field name, value, and delimiter characters - and also including the CRLF sequences in the serialized - input. -]] -] - - - -[section Read From std::istream] - -The standard library provides the type `std::istream` for performing high -level read operations on character streams. The variable `std::cin` is based -on this input stream. This example uses the buffer oriented interface of -__basic_parser__ to build a stream operation which parses an HTTP message -from a `std::istream`: - -[example_http_read_istream] - -[tip - Parsing from a `std::istream` could be implemented using an alternate - strategy: adapt the `std::istream` interface to a __SyncReadStream__, - enabling use with the library's existing stream algorithms. This is - left as an exercise for the reader. -] - -[endsect] - - - -[endsect] diff --git a/src/beast/doc/5_08_custom_body.qbk b/src/beast/doc/5_08_custom_body.qbk deleted file mode 100644 index b209ac5d034..00000000000 --- a/src/beast/doc/5_08_custom_body.qbk +++ /dev/null @@ -1,158 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section Custom Body Types] -[block''''''] - -User-defined types are possible for the message body, where the type meets the -__Body__ requirements. This simplified class declaration -shows the customization points available to user-defined body types: -``` -/// Defines a Body type -struct body -{ - /// This determines the type of the `message::body` member - using value_type = ...; - - /// An optional function, returns the body's payload size - static - std::uint64_t - size(value_type const& v); - - /// The algorithm used for extracting buffers - class reader; - - /// The algorithm used for inserting buffers - class writer; -} -``` - -The meaning of the nested types is as follows - -[table Body Type Members -[[Name][Description]] -[ - [`value_type`] - [ - Determines the type of the - [link beast.ref.beast__http__message.body `message::body`] - member. - ] -][ - [`reader`] - [ - An optional nested type meeting the requirements of __BodyReader__, - which provides the algorithm for converting the body representation - to a forward range of buffer sequences. - If present this body type may be used with a __serializer__. - ] -][ - [`writer`] - [ - An optional nested type meeting the requirements of __BodyWriter__, - which provides the algorithm for storing a forward range of buffer - sequences in the body representation. - If present, this body type may be used with a __parser__. - ] -] -] - -[heading Value Type] - -The `value_type` nested type allows the body to define the declaration of -the body type as it appears in the message. This can be any type. For -example, a body's value type may specify `std::vector` or even -`std::list`. A custom body may even set the value type to -something that is not a container for body octets, such as a -[@http://www.boost.org/libs/filesystem/doc/reference.html#class-path `boost::filesystem::path`]. -Or, a more structured container may be chosen. This declares a body's -value type as a JSON tree structure produced from a -[@http://www.boost.org/doc/html/property_tree/parsers.html#property_tree.parsers.json_parser `json_parser`]: -``` -#include -#include - -struct Body -{ - using value_type = boost::property_tree::ptree; - - class reader; - - class writer; - - // Optional member - static - std::uint64_t - size(value_type const&); -}; -``` - -As long as a suitable reader or writer is available to provide the -algorithm for transferring buffers in and out of the value type, -those bodies may be serialized or parsed. - - - -[section File Body] - -Use of the flexible __Body__ concept customization point enables authors to -preserve the self-contained nature of the __message__ object while allowing -domain specific behaviors. Common operations for HTTP servers include sending -responses which deliver file contents, and allowing for file uploads. In this -example we build the `basic_file_body` type which supports both reading and -writing to a file on the file system. The interface is a class templated -on the type of file used to access the file system, which must meet the -requirements of __File__. - -First we declare the type with its nested types: - -[example_http_file_body_1] - -We will start with the definition of the `value_type`. Our strategy -will be to store the file object directly in the message container -through the `value_type` field. To use this body it will be necessary -to call `msg.body.file().open()` first with the required information -such as the path and open mode. This ensures that the file exists -throughout the operation and prevent the race condition where the -file is removed from the file system in between calls. - -[example_http_file_body_2] - -Our implementation of __BodyReader__ will contain a small buffer -from which the file contents are read. The buffer is provided to -the implementation on each call until everything has been read in. - -[example_http_file_body_3] - -And here are the definitions for the functions we have declared: - -[example_http_file_body_4] - -Files can be read now, and the next step is to allow writing to files -by implementing the __BodyWriter__. The style is similar to the reader, -except that buffers are incoming instead of outgoing. Here's the -declaration: - -[example_http_file_body_5] - -Finally, here is the implementation of the writer member functions: - -[example_http_file_body_6] - -We have created a full featured body type capable of reading and -writing files on the filesystem, integrating seamlessly with the -HTTP algorithms and message container. The body type works with -any file implementation meeting the requirements of __File__ so -it may be transparently used with solutions optimized for particular -platforms. Example HTTP servers which use file bodies are available -in the example directory. - -[endsect] - - - -[endsect] diff --git a/src/beast/doc/5_09_custom_parsers.qbk b/src/beast/doc/5_09_custom_parsers.qbk deleted file mode 100644 index 610dc167396..00000000000 --- a/src/beast/doc/5_09_custom_parsers.qbk +++ /dev/null @@ -1,39 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section Custom Parsers] - -While the parsers included in the library will handle a broad number of -use-cases, the __basic_parser__ interface can be subclassed to implement -custom parsing strategies: the basic parser processes the incoming octets -into elements according to the HTTP/1 protocol specification, while the -derived class decides what to do with those elements. In particular, users -who create exotic containers for [*Fields] may need to also create their -own parser. Custom parsers will work with all of the stream read operations -that work on parsers, as those algorithms use only the basic parser -interface. Some use cases for implementing custom parsers are: - -* Inspect incoming header fields and keep or discard them. - -* Use a container provided by an external interface. - -* Store header data in a user-defined __Fields__ type. - -The basic parser uses the Curiously Recurring Template Pattern -([@https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern CRTP]). -To declare your user defined parser, derive it from __basic_parser__. -The interface to the parser is event-driven. Member functions of the derived -class (termed "callbacks" in this context) are invoked with parsed elements -as they become available, requiring either the `friend` declaration as shown -above or that the member functions are declared public (not recommended). -Buffers provided by the parser are non-owning references; it is the -responsibility of the derived class to copy any information it needs before -returning from the callback. - -[example_http_custom_parser] - -[endsect] diff --git a/src/beast/doc/6_0_http_examples.qbk b/src/beast/doc/6_0_http_examples.qbk deleted file mode 100644 index de7b50618f8..00000000000 --- a/src/beast/doc/6_0_http_examples.qbk +++ /dev/null @@ -1,143 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section More Examples] - -These examples in this section are working functions that may be found -in the examples directory. They demonstrate the usage of the library for -a variety of scenarios. - - - -[section Change Body Type] - -Sophisticated servers may wish to defer the choice of the Body template type -until after the header is available. Then, a body type may be chosen -depending on the header contents. For example, depending on the verb, -target path, or target query parameters. To accomplish this, a parser -is declared to read in the header only, using a trivial body type such as -[link beast.ref.beast__http__empty_body `empty_body`]. Then, a new parser is constructed -from this existing parser where the body type is conditionally determined -by information from the header or elsewhere. - -This example illustrates how a server may make the commitment of a body -type depending on the method verb: - -[example_http_defer_body] - -[endsect] - - - -[section Expect 100-continue (Client)] - -The Expect field with the value "100-continue" in a request is special. It -indicates that the after sending the message header, a client desires an -immediate informational response before sending the the message body, which -presumably may be expensive to compute or large. This behavior is described in -[@https://tools.ietf.org/html/rfc7231#section-5.1.1 rfc7231 section 5.1.1]. -Invoking the 100-continue behavior is implemented easily in a client by -constructing a __serializer__ to send the header first, then receiving -the server response, and finally conditionally send the body using the same -serializer instance. A synchronous, simplified version (no timeout) of -this client action looks like this: - -[example_http_send_expect_100_continue] - -[endsect] - - - -[section Expect 100-continue (Server)] - -The Expect field with the value "100-continue" in a request is special. It -indicates that the after sending the message header, a client desires an -immediate informational response before sending the the message body, which -presumably may be expensive to compute or large. This behavior is described in -[@https://tools.ietf.org/html/rfc7231#section-5.1.1 rfc7231 section 5.1.1]. -Handling the Expect field can be implemented easily in a server by constructing -a __parser__ to read the header first, then send an informational HTTP -response, and finally read the body using the same parser instance. A -synchronous version of this server action looks like this: - -[example_http_receive_expect_100_continue] - -[endsect] - - - -[section HEAD request (Client)] - -The -[@https://tools.ietf.org/html/rfc7231#section-4.3.2 HEAD request] -method indicates to the server that the client wishes to receive the -entire header that would be delivered if the method was GET, except -that the body is omitted. - -[example_http_do_head_request] - -[endsect] - - - -[section HEAD response (Server)] - -When a server receives a -[@https://tools.ietf.org/html/rfc7231#section-4.3.2 HEAD request], -the response should contain the entire header that would be delivered -if the method was GET, except that the body is omitted. - -[example_http_do_head_response] - -[endsect] - - - -[section HTTP Relay] - -An HTTP proxy acts as a relay between client and server. The proxy reads a -request from the client and sends it to the server, possibly adjusting some -of the headers and representation of the body along the way. Then, the -proxy reads a response from the server and sends it back to the client, -also with the possibility of changing the headers and body representation. - -The example that follows implements a synchronous HTTP relay. It uses a -fixed size buffer, to avoid reading in the entire body so that the upstream -connection sees a header without unnecessary latency. This example brings -together all of the concepts discussed so far, it uses both a __serializer__ -and a __parser__ to achieve its goal: - -[example_http_relay] - -[endsect] - - - -[section Send Child Process Output] - -Sometimes it is necessary to send a message whose body is not conveniently -described by a single container. For example, when implementing an HTTP relay -function a robust implementation needs to present body buffers individually -as they become available from the downstream host. These buffers should be -fixed in size, otherwise creating the unnecessary and inefficient burden of -reading the complete message body before forwarding it to the upstream host. - -To enable these use-cases, the body type __buffer_body__ is provided. This -body uses a caller-provided pointer and size instead of an owned container. -To use this body, instantiate an instance of the serializer and fill in -the pointer and size fields before calling a stream write function. - -This example reads from a child process and sends the output back in an -HTTP response. The output of the process is sent as it becomes available: - -[example_http_send_cgi_response] - -[endsect] - - - -[endsect] diff --git a/src/beast/doc/7_0_websocket.qbk b/src/beast/doc/7_0_websocket.qbk deleted file mode 100644 index 7e2e03a5a37..00000000000 --- a/src/beast/doc/7_0_websocket.qbk +++ /dev/null @@ -1,38 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section Using WebSocket] - -The WebSocket Protocol enables two-way communication between a client -running untrusted code in a controlled environment to a remote host that has -opted-in to communications from that code. The protocol consists of an opening -handshake followed by basic message framing, layered over TCP. The goal of -this technology is to provide a mechanism for browser-based applications -needing two-way communication with servers without relying on opening multiple -HTTP connections. - -Beast provides developers with a robust WebSocket implementation built on -Boost.Asio with a consistent asynchronous model using a modern C++ approach. - -[note - This documentation assumes familiarity with __Asio__ and - the protocol specification described in __rfc6455__. - Sample code and identifiers appearing in this section is written - as if these declarations are in effect: - - [ws_snippet_1] -] - -[include 7_1_streams.qbk] -[include 7_2_connect.qbk] -[include 7_3_client.qbk] -[include 7_4_server.qbk] -[include 7_5_messages.qbk] -[include 7_6_control.qbk] -[include 7_7_notes.qbk] - -[endsect] diff --git a/src/beast/doc/7_1_streams.qbk b/src/beast/doc/7_1_streams.qbk deleted file mode 100644 index 002f09321a5..00000000000 --- a/src/beast/doc/7_1_streams.qbk +++ /dev/null @@ -1,64 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section Creating Streams] - -The interface to the WebSocket implementation is a single template class -[link beast.ref.beast__websocket__stream `stream`] -which wraps an existing network transport object or other type of -octet oriented stream. The wrapped object is called the "next layer" -and must meet the requirements of __SyncStream__ if synchronous -operations are performed, __AsyncStream__ if asynchronous operations -are performed, or both. Any arguments supplied during construction of -the stream wrapper are passed to next layer's constructor. - -Here we declare a websocket stream over a TCP/IP socket with ownership -of the socket. The `io_service` argument is forwarded to the wrapped -socket's constructor: - -[ws_snippet_2] - -[heading Using SSL] - -To use WebSockets over SSL, use an instance of the `boost::asio::ssl::stream` -class template as the template type for the stream. The required `io_service` -and `ssl::context` arguments are forwarded to the wrapped stream's constructor: - -[wss_snippet_1] -[wss_snippet_2] - -[important - Code which declares websocket stream objects using Asio SSL types - must include the file [include_file beast/websocket/ssl.hpp]. -] - -[heading Non-owning References] - -If a socket type supports move construction, a websocket stream may be -constructed around the already existing socket by invoking the move -constructor signature: - -[ws_snippet_3] - -Or, the wrapper can be constructed with a non-owning reference. In -this case, the caller is responsible for managing the lifetime of the -underlying socket being wrapped: - -[ws_snippet_4] - -Once the WebSocket stream wrapper is created, the wrapped object may be -accessed by calling -[link beast.ref.beast__websocket__stream.next_layer.overload1 `stream::next_layer`]: - -[ws_snippet_5] - -[warning - Initiating operations on the next layer while websocket - operations are being performed may result in undefined behavior. -] - -[endsect] diff --git a/src/beast/doc/7_2_connect.qbk b/src/beast/doc/7_2_connect.qbk deleted file mode 100644 index a7f8f233a58..00000000000 --- a/src/beast/doc/7_2_connect.qbk +++ /dev/null @@ -1,32 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section Establishing Connections] - -Connections are established by invoking functions directly on the next layer -object. For example, to make an outgoing connection using a standard TCP/IP -socket: - -[ws_snippet_6] - -Similarly, to accept an incoming connection using a standard TCP/IP -socket, pass the next layer object to the acceptor: - -[ws_snippet_7] - -When using SSL, which itself wraps a next layer object that is usually a -TCP/IP socket, multiple calls to retrieve the next layer may be required. -In this example, the websocket stream wraps the SSL stream which wraps -the TCP/IP socket: - -[wss_snippet_3] - -[note - Examples use synchronous interfaces for clarity of exposition. -] - -[endsect] diff --git a/src/beast/doc/7_3_client.qbk b/src/beast/doc/7_3_client.qbk deleted file mode 100644 index 65a0e651c45..00000000000 --- a/src/beast/doc/7_3_client.qbk +++ /dev/null @@ -1,95 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section Handshaking (Clients)] - -A WebSocket session begins when a client sends the HTTP/1 -[@https://tools.ietf.org/html/rfc7230#section-6.7 Upgrade] -request for -[@https://tools.ietf.org/html/rfc6455#section-1.3 websocket], -and the server sends an appropriate response indicating that -the request was accepted and that the connection has been upgraded. -The Upgrade request must include the -[@https://tools.ietf.org/html/rfc7230#section-5.4 Host] -field, and the -[@https://tools.ietf.org/html/rfc7230#section-5.3 target] -of the resource to request. The stream member functions -[link beast.ref.beast__websocket__stream.handshake.overload1 `handshake`] and -[link beast.ref.beast__websocket__stream.async_handshake.overload1 `async_handshake`] -are used to send the request with the required host and target strings. - -[ws_snippet_8] - -The implementation will create and send a request that typically -looks like this: - -[table WebSocket Upgrade HTTP Request -[[Serialized Octets][Description]] -[[ -``` - GET / HTTP/1.1 - Host: localhost - Upgrade: websocket - Connection: upgrade - Sec-WebSocket-Key: 2pGeTR0DsE4dfZs2pH+8MA== - Sec-WebSocket-Version: 13 - User-Agent: Beast -``` -][ - The host and target parameters become part of the Host field - and request-target in the resulting HTTP request. The key is - generated by the implementation. Callers may add fields or - modify fields by providing a ['decorator], described below. -]]] - -[heading Decorators] - -If the caller wishes to add or modify fields, the member functions -[link beast.ref.beast__websocket__stream.handshake_ex `handshake_ex`] and -[link beast.ref.beast__websocket__stream.async_handshake_ex `async_handshake_ex`] -are provided which allow an additional function object, called a -['decorator], to be passed. The decorator is invoked to modify -the HTTP Upgrade request as needed. This example sets a subprotocol -on the request: - -[ws_snippet_9] - -The HTTP Upgrade request produced by the previous call will look thusly: - -[table Decorated WebSocket Upgrade HTTP Request -[[Serialized Octets][Description]] -[[ - ``` - GET / HTTP/1.1 - Host: localhost - Upgrade: websocket - Connection: upgrade - Sec-WebSocket-Key: 2pGeTR0DsE4dfZs2pH+8MA== - Sec-WebSocket-Version: 13 - Sec-WebSocket-Protocol: xmpp;ws-chat - User-Agent: Beast - ``` -][ - Undefined behavior results if the decorator modifies the fields - specific to perform the WebSocket Upgrade , such as the Upgrade - and Connection fields. -]]] - -[heading Filtering] - -When a client receives an HTTP Upgrade response from the server indicating -a successful upgrade, the caller may wish to perform additional validation -on the received HTTP response message. For example, to check that the -response to a basic authentication challenge is valid. To achieve this, -overloads of the handshake member function allow the caller to store the -received HTTP message in an output reference argument as -[link beast.ref.beast__websocket__response_type `response_type`] -as follows: - -[ws_snippet_10] - -[endsect] diff --git a/src/beast/doc/7_4_server.qbk b/src/beast/doc/7_4_server.qbk deleted file mode 100644 index f32b3105e10..00000000000 --- a/src/beast/doc/7_4_server.qbk +++ /dev/null @@ -1,116 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section Handshaking (Servers)] - -A -[link beast.ref.beast__websocket__stream `stream`] -automatically handles receiving and processing the HTTP response to the -handshake request. The call to handshake is successful if a HTTP response -is received with the 101 "Switching Protocols" status code. On failure, -an error is returned or an exception is thrown. Depending on the keep alive -setting, the connection may remain open for a subsequent handshake attempt. - -Performing a handshake for an incoming websocket upgrade request operates -similarly. If the handshake fails, an error is returned or exception thrown: - -[ws_snippet_11] - -Successful WebSocket Upgrade responses generated by the implementation will -typically look like this: - -[table Decorated WebSocket Upgrade HTTP Request -[[Serialized Octets][Description]] -[[ - ``` - HTTP/1.1 101 Switching Protocols - Upgrade: websocket - Connection: upgrade - Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo= - Server: Beast/40 - ``` -][ - The Sec-WebSocket-Accept field value is generated from the - request in a fashion specified by the WebSocket protocol. -]]] - -[heading Decorators] - -If the caller wishes to add or modify fields, the member functions -[link beast.ref.beast__websocket__stream.accept_ex `accept_ex`] and -[link beast.ref.beast__websocket__stream.async_accept_ex `async_accept_ex`] -are provided which allow an additional function object, called a -['decorator], to be passed. The decorator is invoked to modify -the HTTP Upgrade request as needed. This example sets the Server -field on the response: - -[ws_snippet_12] - -The HTTP Upgrade response produced by the previous call looks like this: - -[table Decorated WebSocket Upgrade HTTP Request -[[Serialized Octets][Description]] -[[ - ``` - HTTP/1.1 101 Switching Protocols - Upgrade: websocket - Connection: upgrade - Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo= - Server: AcmeServer - ``` -][ - When the Upgrade request fails, the implementation will still invoke - the decorator to modify the response. In this case, the response - object will have a status code other than 101. - - Undefined behavior results when the upgrade request is successful - and the decorator modifies the fields specific to perform the - WebSocket Upgrade, such as the Upgrade and Connection fields. -]]] - -[heading Passing HTTP Requests] - -When implementing an HTTP server that also supports WebSocket, the -server usually reads the HTTP request from the client. To detect when -the incoming HTTP request is a WebSocket Upgrade request, the function -[link beast.ref.beast__websocket__is_upgrade `is_upgrade`] may be used. - -Once the caller determines that the HTTP request is a WebSocket Upgrade, -additional overloads of -[link beast.ref.beast__websocket__stream.accept `accept`], -[link beast.ref.beast__websocket__stream.accept_ex `accept_ex`], -[link beast.ref.beast__websocket__stream.async_accept `async_accept`], and -[link beast.ref.beast__websocket__stream.async_accept_ex `async_accept_ex`] -are provided which receive the entire HTTP request header as an object -to perform the handshake. In this example, the request is first read -in using the HTTP algorithms, and then passed to a newly constructed -stream: - -[ws_snippet_13] - -[heading Buffered Handshakes] - -Sometimes a server implementation wishes to read octets on the stream -in order to route the incoming request. For example, a server may read -the first 6 octets after accepting an incoming connection to determine -if a TLS protocol is being negotiated, and choose a suitable implementation -at run-time. In the case where the server wishes to accept the incoming -request as an HTTP WebSocket Upgrade request, additional overloads of -[link beast.ref.beast__websocket__stream.accept `accept`], -[link beast.ref.beast__websocket__stream.accept_ex `accept_ex`], -[link beast.ref.beast__websocket__stream.async_accept `async_accept`], and -[link beast.ref.beast__websocket__stream.async_accept_ex `async_accept_ex`] -are provided which receive the additional buffered octets and consume -them as part of the handshake. - -In this example, the server reads the initial HTTP message into the -specified dynamic buffer as an octet sequence in the buffer's output -area, and later uses those octets to attempt an HTTP WebSocket Upgrade: - -[ws_snippet_14] - -[endsect] diff --git a/src/beast/doc/7_5_messages.qbk b/src/beast/doc/7_5_messages.qbk deleted file mode 100644 index 9518d37a646..00000000000 --- a/src/beast/doc/7_5_messages.qbk +++ /dev/null @@ -1,36 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section Send and Receive Messages] - -After the WebSocket handshake is accomplished, callers may send and receive -messages using the message oriented interface. This interface requires that -all of the buffers representing the message are known ahead of time: - -[ws_snippet_15] - -[important - Calls to [link beast.ref.beast__websocket__stream.set_option `set_option`] - must be made from the same implicit or explicit strand as that used - to perform other operations. -] - -[heading Frames] - -Some use-cases make it impractical or impossible to buffer the entire -message ahead of time: - -* Streaming multimedia to an endpoint. -* Sending a message that does not fit in memory at once. -* Providing incremental results as they become available. - -For these cases, the frame oriented interface may be used. This -example reads and echoes a complete message using this interface: - -[ws_snippet_16] - -[endsect] diff --git a/src/beast/doc/7_6_control.qbk b/src/beast/doc/7_6_control.qbk deleted file mode 100644 index fb1de84dcbd..00000000000 --- a/src/beast/doc/7_6_control.qbk +++ /dev/null @@ -1,113 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section Control Frames] - -Control frames are small (less than 128 bytes) messages entirely contained -in an individual WebSocket frame. They may be sent at any time by either -peer on an established connection, and can appear in between continuation -frames for a message. There are three types of control frames: ping, pong, -and close. - -A sent ping indicates a request that the sender wants to receive a pong. A -pong is a response to a ping. Pongs may be sent unsolicited, at any time. -One use for an unsolicited pong is to inform the remote peer that the -session is still active after a long period of inactivity. A close frame -indicates that the remote peer wishes to close the WebSocket connection. -The connection is considered gracefully closed when each side has sent -and received a close frame. - -During read operations, Beast automatically reads and processes control -frames. If a control callback is registered, the callback is notified of -the incoming control frame. The implementation will respond to pings -automatically. The receipt of a close frame initiates the WebSocket -close procedure, eventually resulting in the error code -[link beast.ref.beast__websocket__error `error::closed`] -being delivered to the caller in a subsequent read operation, assuming -no other error takes place. - -A consequence of this automatic behavior is that caller-initiated read -operations can cause socket writes. However, these writes will not -compete with caller-initiated write operations. For the purposes of -correctness with respect to the stream invariants, caller-initiated -read operations still only count as a read. This means that callers can -have a simultaneously active read, write, and ping/pong operation in -progress, while the implementation also automatically handles control -frames. - -[heading Control Callback] - -Ping, pong, and close messages are control frames which may be sent at -any time by either peer on an established WebSocket connection. They -are sent using the functions -[link beast.ref.beast__websocket__stream.ping `ping`], -[link beast.ref.beast__websocket__stream.pong `pong`]. -and -[link beast.ref.beast__websocket__stream.close `close`]. -To be notified of control frames, callers may register a -['control callback] using -[link beast.ref.beast__websocket__stream.control_callback `control_callback`]. -The object provided with this option should be callable with the following -signature: - -[ws_snippet_17] - -When a control callback is registered, it will be invoked for all pings, -pongs, and close frames received through either synchronous read functions -or asynchronous read functions. The type of frame and payload text are -passed as parameters to the control callback. If the frame is a close -frame, the close reason may be obtained by calling -[link beast.ref.beast__websocket__stream.reason `reason`]. - -Unlike regular completion handlers used in calls to asynchronous initiation -functions, the control callback only needs to be set once. The callback is -not reset after being called. The same callback is used for both synchronous -and asynchronous reads. The callback is passive; in order to be called, -a stream read operation must be active. - -[note - When an asynchronous read function receives a control frame, the - control callback is invoked in the same manner as that used to - invoke the final completion handler of the corresponding read - function. -] - -[heading Close Frames] - -The WebSocket protocol defines a procedure and control message for initiating -a close of the session. Handling of close initiated by the remote end of the -connection is performed automatically. To manually initiate a close, use -the -[link beast.ref.beast__websocket__stream.close `close`] function: - -[ws_snippet_18] - -When the remote peer initiates a close by sending a close frame, Beast -will handle it for you by causing the next read to return `error::closed`. -When this error code is delivered, it indicates to the application that -the WebSocket connection has been closed cleanly, and that the TCP/IP -connection has been closed. After initiating a close, it is necessary to -continue reading messages until receiving the error `error::closed`. This -is because the remote peer may still be sending message and control frames -before it receives and responds to the close frame. - -[important - To receive the - [link beast.ref.beast__websocket__error `error::closed`] - error, a read operation is required. -] - -[heading Auto-fragment] - -To ensure timely delivery of control frames, large messages can be broken up -into smaller sized frames. The automatic fragment option turns on this -feature, and the write buffer size option determines the maximum size of -the fragments: - -[ws_snippet_19] - -[endsect] diff --git a/src/beast/doc/7_7_notes.qbk b/src/beast/doc/7_7_notes.qbk deleted file mode 100644 index 2444072c8d7..00000000000 --- a/src/beast/doc/7_7_notes.qbk +++ /dev/null @@ -1,55 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section Notes] - -Because calls to read data may return a variable amount of bytes, the -interface to calls that read data require an object that meets the requirements -of __DynamicBuffer__. This concept is modeled on __streambuf__. - -The implementation does not perform queueing or buffering of messages. If -desired, these features should be provided by callers. The impact of this -design is that library users are in full control of the allocation strategy -used to store data and the back-pressure applied on the read and write side -of the underlying TCP/IP connection. - -[heading Asynchronous Operations] - -Asynchronous versions are available for all functions: - -[ws_snippet_20] - -Calls to asynchronous initiation functions support the extensible asynchronous -model developed by the Boost.Asio author, allowing for traditional completion -handlers, stackful or stackless coroutines, and even futures: - -[ws_snippet_21] - -[heading The io_service] - -The creation and operation of the __io_service__ associated with the -underlying stream is left to the callers, permitting any implementation -strategy including one that does not require threads for environments -where threads are unavailable. Beast WebSocket itself does not use -or require threads. - -[heading Thread Safety] - -Like a regular __Asio__ socket, a -[link beast.ref.beast__websocket__stream `stream`] -is not thread safe. Callers are responsible for synchronizing operations on -the socket using an implicit or explicit strand, as per the Asio documentation. -The asynchronous interface supports one active read and one active write -simultaneously. Undefined behavior results if two or more reads or two or -more writes are attempted concurrently. Caller initiated WebSocket ping, pong, -and close operations each count as an active write. - -The implementation uses composed asynchronous operations internally; a high -level read can cause both reads and writes to take place on the underlying -stream. This behavior is transparent to callers. - -[endsect] diff --git a/src/beast/doc/8_concepts.qbk b/src/beast/doc/8_concepts.qbk deleted file mode 100644 index 7d1f23831b6..00000000000 --- a/src/beast/doc/8_concepts.qbk +++ /dev/null @@ -1,22 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section:concept Concepts] - -This section describes all of the concepts defined by the library. - -[include concept/Body.qbk] -[include concept/BodyReader.qbk] -[include concept/BodyWriter.qbk] -[include concept/BufferSequence.qbk] -[include concept/DynamicBuffer.qbk] -[include concept/Fields.qbk] -[include concept/FieldsReader.qbk] -[include concept/File.qbk] -[include concept/Streams.qbk] - -[endsect] diff --git a/src/beast/doc/9_0_design.qbk b/src/beast/doc/9_0_design.qbk deleted file mode 100644 index 8b4c0a0dfc8..00000000000 --- a/src/beast/doc/9_0_design.qbk +++ /dev/null @@ -1,58 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section Design Choices] - -The implementations were originally driven by business needs of cryptocurrency -server applications (e.g. [@https://github.com/ripple/rippled rippled]), -written in C++. These needs were not met by existing solutions so Beast -was written from scratch as a solution. Beast's design philosophy avoids -flaws exhibited by other libraries: - -* Don't try to do too much. - -* Don't sacrifice performance. - -* Mimic __Asio__; familiarity breeds confidence. - -* Role-symmetric interfaces; client and server the same (or close to it). - -* Leave important decisions, such as allocating memory or - managing flow control, to the user. - -Beast uses the __DynamicBuffer__ concept presented in the Networking TS -(__N4588__), and relies heavily on the __ConstBufferSequence__ and -__MutableBufferSequence__ concepts for passing buffers to functions. -The authors have found the dynamic buffer and buffer sequence interfaces to -be optimal for interacting with Asio, and for other tasks such as incremental -parsing of data in buffers (for example, parsing websocket frames stored -in a [link beast.ref.beast__static_buffer `static_buffer`]). - -During the development of Beast the authors have studied other software -packages and in particular the comments left during the Boost Review process -of other packages offering similar functionality. In this section and the -FAQs that follow we attempt to answer those questions that are also applicable -to Beast. - -For HTTP we model the message to maximize flexibility of implementation -strategies while allowing familiar verbs such as [*`read`] and [*`write`]. -The HTTP interface is further driven by the needs of the WebSocket module, -as a WebSocket session requires a HTTP Upgrade handshake exchange at the -start. Other design goals: - -* Keep it simple. - -* Stay low level; don't invent a whole web server or client. - -* Allow for customizations, if the user needs it. - -[include 9_1_http_message.qbk] -[include 9_2_http_comparison.qbk] -[include 9_3_websocket_zaphoyd.qbk] -[include 9_4_faq.qbk] - -[endsect] diff --git a/src/beast/doc/9_1_http_message.qbk b/src/beast/doc/9_1_http_message.qbk deleted file mode 100644 index af1f36c67c2..00000000000 --- a/src/beast/doc/9_1_http_message.qbk +++ /dev/null @@ -1,340 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section HTTP Message Container] - -In this section we describe the problem of modeling HTTP messages and explain -how the library arrived at its solution, with a discussion of the benefits -and drawbacks of the design choices. The goal for creating a message model -is to create a container with value semantics, possibly movable and/or -copyable, that contains all the information needed to serialize, or all -of the information captured during parsing. More formally, given: - -* `m` is an instance of an HTTP message container - -* `x` is a series of octets describing a valid HTTP message in - the serialized format described in __rfc7230__. - -* `S(m)` is a serialization function which produces a series of octets - from a message container. - -* `P(x)` is a parsing function which produces a message container from - a series of octets. - -These relations are true: - -* `S(m) == x` - -* `P(S(m)) == m` - -We would also like our message container to have customization points -permitting the following: allocator awareness, user-defined containers -to represent header fields, and user-defined types and algorithms to -represent the body. And finally, because requests and responses have -different fields in the ['start-line], we would like the containers for -requests and responses to be represented by different types for function -overloading. - -Here is our first attempt at declaring some message containers: - -[table -[[ -``` -/// An HTTP request -template -struct request -{ - int version; - std::string method; - std::string target; - Fields fields; - - typename Body::value_type body; -}; -``` -][ -``` -/// An HTTP response -template -struct response -{ - int version; - int status; - std::string reason; - Fields fields; - - typename Body::value_type body; -}; -``` -]] -] - -These containers are capable of representing everything in the model -of HTTP requests and responses described in __rfc7230__. Request and -response objects are different types. The user can choose the container -used to represent the fields. And the user can choose the [*Body] type, -which is a concept defining not only the type of `body` member but also -the algorithms used to transfer information in and out of that member -when performing serialization and parsing. - -However, a problem arises. How do we write a function which can accept -an object that is either a request or a response? As written, the only -obvious solution is to make the message a template type. Additional traits -classes would then be needed to make sure that the passed object has a -valid type which meets the requirements. These unnecessary complexities -are bypassed by making each container a partial specialization: -``` -/// An HTTP message -template -struct message; - -/// An HTTP request -template -struct message -{ - int version; - std::string method; - std::string target; - Fields fields; - - typename Body::value_type body; -}; - -/// An HTTP response -template -struct message -{ - int version; - int status; - std::string reason; - Fields fields; - - typename Body::value_type body; -}; -``` - -Now we can declare a function which takes any message as a parameter: -``` -template -void f(message& msg); -``` - -This function can manipulate the fields common to requests and responses. -If it needs to access the other fields, it can use overloads with -partial specialization, or in C++17 a `constexpr` expression: -``` -template -void f(message& msg) -{ - if constexpr(isRequest) - { - // call msg.method(), msg.target() - } - else - { - // call msg.result(), msg.reason() - } -} -``` - -Often, in non-trivial HTTP applications, we want to read the HTTP header -and examine its contents before choosing a type for [*Body]. To accomplish -this, there needs to be a way to model the header portion of a message. -And we'd like to do this in a way that allows functions which take the -header as a parameter, to also accept a type representing the whole -message (the function will see just the header part). This suggests -inheritance, by splitting a new base class off of the message: -``` -/// An HTTP message header -template -struct header; -``` - -Code which accesses the fields has to laboriously mention the `fields` -member, so we'll not only make `header` a base class but we'll make -a quality of life improvement and derive the header from the fields -for notational convenience. In order to properly support all forms -of construction of [*Fields] there will need to be a set of suitable -constructor overloads (not shown): -``` -/// An HTTP request header -template -struct header : Fields -{ - int version; - std::string method; - std::string target; -}; - -/// An HTTP response header -template -struct header : Fields -{ - int version; - int status; - std::string reason; -}; - -/// An HTTP message -template -struct message : header -{ - typename Body::value_type body; - - /// Construct from a `header` - message(header&& h); -}; - -``` - -Note that the `message` class now has a constructor allowing messages -to be constructed from a similarly typed `header`. This handles the case -where the user already has the header and wants to make a commitment to the -type for [*Body]. A function can be declared which accepts any header: -``` -template -void f(header& msg); -``` - -Until now we have not given significant consideration to the constructors -of the `message` class. But to achieve all our goals we will need to make -sure that there are enough constructor overloads to not only provide for -the special copy and move members if the instantiated types support it, -but also allow the fields container and body container to be constructed -with arbitrary variadic lists of parameters. This allows the container -to fully support allocators. - -The solution used in the library is to treat the message like a `std::pair` -for the purposes of construction, except that instead of `first` and `second` -we have the `Fields` base class and `message::body` member. This means that -single-argument constructors for those fields should be accessible as they -are with `std::pair`, and that a mechanism identical to the pair's use of -`std::piecewise_construct` should be provided. Those constructors are too -complex to repeat here, but interested readers can view the declarations -in the corresponding header file. - -There is now significant progress with our message container but a stumbling -block remains. There is no way to control the allocator for the `std::string` -members. We could add an allocator to the template parameter list of the -header and message classes, use it for those strings. This is unsatisfying -because of the combinatorial explosion of constructor variations needed to -support the scheme. It also means that request messages could have [*four] -different allocators: two for the fields and body, and two for the method -and target strings. A better solution is needed. - -To get around this we make an interface modification and then add -a requirement to the [*Fields] type. First, the interface change: -``` -/// An HTTP request header -template -struct header : Fields -{ - int version; - - verb method() const; - string_view method_string() const; - void method(verb); - void method(string_view); - - string_view target(); const; - void target(string_view); - -private: - verb method_; -}; - -/// An HTTP response header -template -struct header : Fields -{ - int version; - int result; - string_view reason() const; - void reason(string_view); -}; -``` - -The start-line data members are replaced traditional accessors using -non-owning references to string buffers. The method is stored using -a simple integer instead of the entire string, for the case where -the method is recognized from the set of known verb strings. - -Now we add a requirement to the fields type: management of the -corresponding string is delegated to the [*Fields] container, which can -already be allocator aware and constructed with the necessary allocator -parameter via the provided constructor overloads for `message`. The -delegation implementation looks like this (only the response header -specialization is shown): -``` -/// An HTTP response header -template -struct header : Fields -{ - int version; - int status; - - string_view - reason() const - { - return this->reason_impl(); // protected member of Fields - } - - void - reason(string_view s) - { - this->reason_impl(s); // protected member of Fields - } -}; -``` - -Now that we've accomplished our initial goals and more, there are a few -more quality of life improvements to make. Users will choose different -types for `Body` far more often than they will for `Fields`. Thus, we -swap the order of these types and provide a default. Then, we provide -type aliases for requests and responses to soften the impact of using -`bool` to choose the specialization: - -``` -/// An HTTP header -template -struct header; - -/// An HTTP message -template -struct message; - -/// An HTTP request -template -using request = message; - -/// An HTTP response -template -using response = message; -``` - -This allows concise specification for the common cases, while -allowing for maximum customization for edge cases: -``` -request req; - -response res; -``` - -This container is also capable of representing complete HTTP/2 messages. -Not because it was explicitly designed for, but because the IETF wanted to -preserve message compatibility with HTTP/1. Aside from version specific -fields such as Connection, the contents of HTTP/1 and HTTP/2 messages are -identical even though their serialized representation is considerably -different. The message model presented in this library is ready for HTTP/2. - -In conclusion, this representation for the message container is well thought -out, provides comprehensive flexibility, and avoids the necessity of defining -additional traits classes. User declarations of functions that accept headers -or messages as parameters are easy to write in a variety of ways to accomplish -different results, without forcing cumbersome SFINAE declarations everywhere. - -[endsect] diff --git a/src/beast/doc/9_2_http_comparison.qbk b/src/beast/doc/9_2_http_comparison.qbk deleted file mode 100644 index e181fcb51a5..00000000000 --- a/src/beast/doc/9_2_http_comparison.qbk +++ /dev/null @@ -1,454 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section HTTP Comparison to Other Libraries] - -There are a few C++ published libraries which implement some of the HTTP -protocol. We analyze the message model chosen by those libraries and discuss -the advantages and disadvantages relative to Beast. - -The general strategy used by the author to evaluate external libraries is -as follows: - -* Review the message model. Can it represent a complete request or - response? What level of allocator support is present? How much - customization is possible? - -* Review the stream abstraction. This is the type of object, such as - a socket, which may be used to parse or serialize (i.e. read and write). - Can user defined types be specified? What's the level of conformance to - to Asio or Networking-TS concepts? - -* Check treatment of buffers. Does the library manage the buffers - or can users provide their own buffers? - -* How does the library handle corner cases such as trailers, - Expect: 100-continue, or deferred commitment of the body type? - -[note - Declarations examples from external libraries have been edited: - portions have been removed for simplification. -] - - - -[heading cpp-netlib] - -[@https://github.com/cpp-netlib/cpp-netlib/tree/092cd570fb179d029d1865aade9f25aae90d97b9 [*cpp-netlib]] -is a network programming library previously intended for Boost but not -having gone through formal review. As of this writing it still uses the -Boost name, namespace, and directory structure although the project states -that Boost acceptance is no longer a goal. The library is based on Boost.Asio -and bills itself as ['"a collection of network related routines/implementations -geared towards providing a robust cross-platform networking library"]. It -cites ['"Common Message Type"] as a feature. As of the branch previous -linked, it uses these declarations: -``` -template -struct basic_message { - public: - typedef Tag tag; - - typedef typename headers_container::type headers_container_type; - typedef typename headers_container_type::value_type header_type; - typedef typename string::type string_type; - - headers_container_type& headers() { return headers_; } - headers_container_type const& headers() const { return headers_; } - - string_type& body() { return body_; } - string_type const& body() const { return body_; } - - string_type& source() { return source_; } - string_type const& source() const { return source_; } - - string_type& destination() { return destination_; } - string_type const& destination() const { return destination_; } - - private: - friend struct detail::directive_base; - friend struct detail::wrapper_base >; - - mutable headers_container_type headers_; - mutable string_type body_; - mutable string_type source_; - mutable string_type destination_; -}; -``` - -This container is the base class template used to represent HTTP messages. -It uses a "tag" type style specializations for a variety of trait classes, -allowing for customization of the various parts of the message. For example, -a user specializes `headers_container` to determine what container type -holds the header fields. We note some problems with the container declaration: - -* The header and body containers may only be default-constructed. - -* No stateful allocator support. - -* There is no way to defer the commitment of the type for `body_` to - after the headers are read in. - -* The message model includes a "source" and "destination." This is - extraneous metadata associated with the connection which is not part - of the HTTP protocol specification and belongs elsewhere. - -* The use of `string_type` (a customization point) for source, - destination, and body suggests that `string_type` models a - [*ForwardRange] whose `value_type` is `char`. This representation - is less than ideal, considering that the library is built on - Boost.Asio. Adapting a __DynamicBuffer__ to the required forward - range destroys information conveyed by the __ConstBufferSequence__ - and __MutableBufferSequence__ used in dynamic buffers. The consequence - is that cpp-netlib implementations will be less efficient than an - equivalent __N4588__ conforming implementation. - -* The library uses specializations of `string` to change the type - of string used everywhere, including the body, field name and value - pairs, and extraneous metadata such as source and destination. The - user may only choose a single type: field name, field values, and - the body container will all use the same string type. This limits - utility of the customization point. The library's use of the string - trait is limited to selecting between `std::string` and `std::wstring`. - We do not find this use-case compelling given the limitations. - -* The specialized trait classes generate a proliferation of small - additional framework types. To specialize traits, users need to exit - their namespace and intrude into the `boost::network::http` namespace. - The way the traits are used in the library limits the usefulness - of the traits to trivial purpose. - -* The `string customization point constrains user defined body types - to few possible strategies. There is no way to represent an HTTP message - body as a filename with accompanying algorithms to store or retrieve data - from the file system. - -The design of the message container in this library is cumbersome -with its system of customization using trait specializations. The -use of these customizations is extremely limited due to the way they -are used in the container declaration, making the design overly -complex without corresponding benefit. - - - -[heading Boost.HTTP] - -[@https://github.com/BoostGSoC14/boost.http/tree/45fc1aa828a9e3810b8d87e669b7f60ec100bff4 [*boost.http]] -is a library resulting from the 2014 Google Summer of Code. It was submitted -for a Boost formal review and rejected in 2015. It is based on Boost.Asio, -and development on the library has continued to the present. As of the branch -previously linked, it uses these message declarations: -``` -template -struct basic_message -{ - typedef Headers headers_type; - typedef Body body_type; - - headers_type &headers(); - - const headers_type &headers() const; - - body_type &body(); - - const body_type &body() const; - - headers_type &trailers(); - - const headers_type &trailers() const; - -private: - headers_type headers_; - body_type body_; - headers_type trailers_; -}; - -typedef basic_message> message; - -template -struct is_message>: public std::true_type {}; -``` - -* This container cannot model a complete message. The ['start-line] items - (method and target for requests, reason-phrase for responses) are - communicated out of band, as is the ['http-version]. A function that - operates on the message including the start line requires additional - parameters. This is evident in one of the - [@https://github.com/BoostGSoC14/boost.http/blob/45fc1aa828a9e3810b8d87e669b7f60ec100bff4/example/basic_router.cpp#L81 example programs]. - The `500` and `"OK"` arguments represent the response ['status-code] and - ['reason-phrase] respectively: - ``` - ... - http::message reply; - ... - self->socket.async_write_response(500, string_ref("OK"), reply, yield); - ``` - -* `headers_`, `body_`, and `trailers_` may only be default-constructed, - since there are no explicitly declared constructors. - -* There is no way to defer the commitment of the [*Body] type to after - the headers are read in. This is related to the previous limitation - on default-construction. - -* No stateful allocator support. This follows from the previous limitation - on default-construction. Buffers for start-line strings must be - managed externally from the message object since they are not members. - -* The trailers are stored in a separate object. Aside from the combinatorial - explosion of the number of additional constructors necessary to fully - support arbitrary forwarded parameter lists for each of the headers, body, - and trailers members, the requirement to know in advance whether a - particular HTTP field will be located in the headers or the trailers - poses an unnecessary complication for general purpose functions that - operate on messages. - -* The declarations imply that `std::vector` is a model of [*Body]. - More formally, that a body is represented by the [*ForwardRange] - concept whose `value_type` is an 8-bit integer. This representation - is less than ideal, considering that the library is built on - Boost.Asio. Adapting a __DynamicBuffer__ to the required forward range - destroys information conveyed by the __ConstBufferSequence__ and - __MutableBufferSequence__ used in dynamic buffers. The consequence is - that Boost.HTTP implementations will be less efficient when dealing - with body containers than an equivalent __N4588__ conforming - implementation. - -* The [*Body] customization point constrains user defined types to - very limited implementation strategies. For example, there is no way - to represent an HTTP message body as a filename with accompanying - algorithms to store or retrieve data from the file system. - -This representation addresses a narrow range of use cases. It has -limited potential for customization and performance. It is more difficult -to use because it excludes the start line fields from the model. - - - -[heading C++ REST SDK (cpprestsdk)] - -[@https://github.com/Microsoft/cpprestsdk/tree/381f5aa92d0dfb59e37c0c47b4d3771d8024e09a [*cpprestsdk]] -is a Microsoft project which ['"...aims to help C++ developers connect to and -interact with services"]. It offers the most functionality of the libraries -reviewed here, including support for Websocket services using its websocket++ -dependency. It can use native APIs such as HTTP.SYS when building Windows -based applications, and it can use Boost.Asio. The WebSocket module uses -Boost.Asio exclusively. - -As cpprestsdk is developed by a large corporation, it contains quite a bit -of functionality and necessarily has more interfaces. We will break down -the interfaces used to model messages into more manageable pieces. This -is the container used to store the HTTP header fields: -``` -class http_headers -{ -public: - ... - -private: - std::map m_headers; -}; -``` - -This declaration is quite bare-bones. We note the typical problems of -most field containers: - -* The container may only be default-constructed. - -* No support for allocators, stateful or otherwise. - -* There are no customization points at all. - -Now we analyze the structure of -the larger message container. The library uses a handle/body idiom. There -are two public message container interfaces, one for requests (`http_request`) -and one for responses (`http_response`). Each interface maintains a private -shared pointer to an implementation class. Public member function calls -are routed to the internal implementation. This is the first implementation -class, which forms the base class for both the request and response -implementations: -``` -namespace details { - -class http_msg_base -{ -public: - http_headers &headers() { return m_headers; } - - _ASYNCRTIMP void set_body(const concurrency::streams::istream &instream, const utf8string &contentType); - - /// Set the stream through which the message body could be read - void set_instream(const concurrency::streams::istream &instream) { m_inStream = instream; } - - /// Set the stream through which the message body could be written - void set_outstream(const concurrency::streams::ostream &outstream, bool is_default) { m_outStream = outstream; m_default_outstream = is_default; } - - const pplx::task_completion_event & _get_data_available() const { return m_data_available; } - -protected: - /// Stream to read the message body. - concurrency::streams::istream m_inStream; - - /// stream to write the msg body - concurrency::streams::ostream m_outStream; - - http_headers m_headers; - bool m_default_outstream; - - /// The TCE is used to signal the availability of the message body. - pplx::task_completion_event m_data_available; -}; -``` - -To understand these declarations we need to first understand that cpprestsdk -uses the asynchronous model defined by Microsoft's -[@https://msdn.microsoft.com/en-us/library/dd504870.aspx [*Concurrency Runtime]]. -Identifiers from the [@https://msdn.microsoft.com/en-us/library/jj987780.aspx [*`pplx` namespace]] -define common asynchronous patterns such as tasks and events. The -`concurrency::streams::istream` parameter and `m_data_available` data member -indicates a lack of separation of concerns. The representation of HTTP messages -should not be conflated with the asynchronous model used to serialize or -parse those messages in the message declarations. - -The next declaration forms the complete implementation class referenced by the -handle in the public interface (which follows after): -``` -/// Internal representation of an HTTP request message. -class _http_request final : public http::details::http_msg_base, public std::enable_shared_from_this<_http_request> -{ -public: - _ASYNCRTIMP _http_request(http::method mtd); - - _ASYNCRTIMP _http_request(std::unique_ptr server_context); - - http::method &method() { return m_method; } - - const pplx::cancellation_token &cancellation_token() const { return m_cancellationToken; } - - _ASYNCRTIMP pplx::task reply(const http_response &response); - -private: - - // Actual initiates sending the response, without checking if a response has already been sent. - pplx::task _reply_impl(http_response response); - - http::method m_method; - - std::shared_ptr m_progress_handler; -}; - -} // namespace details -``` - -As before, we note that the implementation class for HTTP requests concerns -itself more with the mechanics of sending the message asynchronously than -it does with actually modeling the HTTP message as described in __rfc7230__: - -* The constructor accepting `std::unique_ptrmethod(); } - - void set_method(const http::method &method) const { _m_impl->method() = method; } - - /// Extract the body of the request message as a string value, checking that the content type is a MIME text type. - /// A body can only be extracted once because in some cases an optimization is made where the data is 'moved' out. - pplx::task extract_string(bool ignore_content_type = false) - { - auto impl = _m_impl; - return pplx::create_task(_m_impl->_get_data_available()).then([impl, ignore_content_type](utility::size64_t) { return impl->extract_string(ignore_content_type); }); - } - - /// Extracts the body of the request message into a json value, checking that the content type is application/json. - /// A body can only be extracted once because in some cases an optimization is made where the data is 'moved' out. - pplx::task extract_json(bool ignore_content_type = false) const - { - auto impl = _m_impl; - return pplx::create_task(_m_impl->_get_data_available()).then([impl, ignore_content_type](utility::size64_t) { return impl->_extract_json(ignore_content_type); }); - } - - /// Sets the body of the message to the contents of a byte vector. If the 'Content-Type' - void set_body(const std::vector &body_data); - - /// Defines a stream that will be relied on to provide the body of the HTTP message when it is - /// sent. - void set_body(const concurrency::streams::istream &stream, const utility::string_t &content_type = _XPLATSTR("application/octet-stream")); - - /// Defines a stream that will be relied on to hold the body of the HTTP response message that - /// results from the request. - void set_response_stream(const concurrency::streams::ostream &stream); - { - return _m_impl->set_response_stream(stream); - } - - /// Defines a callback function that will be invoked for every chunk of data uploaded or downloaded - /// as part of the request. - void set_progress_handler(const progress_handler &handler); - -private: - friend class http::details::_http_request; - friend class http::client::http_client; - - std::shared_ptr _m_impl; -}; -``` - -It is clear from this declaration that the goal of the message model in -this library is driven by its use-case (interacting with REST servers) -and not to model HTTP messages generally. We note problems similar to -the other declarations: - -* There are no compile-time customization points at all. The only - customization is in the `concurrency::streams::istream` and - `concurrency::streams::ostream` reference parameters. Presumably, - these are abstract interfaces which may be subclassed by users - to achieve custom behaviors. - -* The extraction of the body is conflated with the asynchronous model. - -* No way to define an allocator for the container used when extracting - the body. - -* A body can only be extracted once, limiting the use of this container - when using a functional programming style. - -* Setting the body requires either a vector or a `concurrency::streams::istream`. - No user defined types are possible. - -* The HTTP request container conflates HTTP response behavior (see the - `set_response_stream` member). Again this is likely purpose-driven but - the lack of separation of concerns limits this library to only the - uses explicitly envisioned by the authors. - -The general theme of the HTTP message model in cpprestsdk is "no user -definable customizations". There is no allocator support, and no -separation of concerns. It is designed to perform a specific set of -behaviors. In other words, it does not follow the open/closed principle. - -Tasks in the Concurrency Runtime operate in a fashion similar to -`std::future`, but with some improvements such as continuations which -are not yet in the C++ standard. The costs of using a task based -asynchronous interface instead of completion handlers is well -documented: synchronization points along the call chain of composed -task operations which cannot be optimized away. See: -[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3747.pdf -[*A Universal Model for Asynchronous Operations]] (Kohlhoff). - -[endsect] diff --git a/src/beast/doc/9_3_websocket_zaphoyd.qbk b/src/beast/doc/9_3_websocket_zaphoyd.qbk deleted file mode 100644 index 80fbe793b15..00000000000 --- a/src/beast/doc/9_3_websocket_zaphoyd.qbk +++ /dev/null @@ -1,445 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section Comparison to Zaphoyd Studios WebSocket++] - -[variablelist - -[[ - How does this compare to [@https://www.zaphoyd.com/websocketpp websocketpp], - an alternate header-only WebSocket implementation? -][ -[variablelist - -[[1. Synchronous Interface][ - -Beast offers full support for WebSockets using a synchronous interface. It -uses the same style of interfaces found in Boost.Asio: versions that throw -exceptions, or versions that return the error code in a reference parameter: - -[table - [ - [[@https://github.com/vinniefalco/Beast/blob/6c8b4b2f8dde72b01507e4ac7fde4ffea57ebc99/include/beast/websocket/stream.hpp#L774 Beast]] - [websocketpp] - ][ - [``` - template - void - read(DynamicBuffer& dynabuf) - ```] - [ - // - ] -]]]] - -[[2. Connection Model][ - -websocketpp supports multiple transports by utilizing a trait, the `config::transport_type` -([@https://github.com/zaphoyd/websocketpp/blob/378437aecdcb1dfe62096ffd5d944bf1f640ccc3/websocketpp/transport/asio/connection.hpp#L60 asio transport example]) -To get an idea of the complexity involved with implementing a transport, -compare the asio transport to the -[@https://github.com/zaphoyd/websocketpp/blob/378437aecdcb1dfe62096ffd5d944bf1f640ccc3/websocketpp/transport/iostream/connection.hpp#L59 `iostream` transport] -(a layer that allows websocket communication over a `std::iostream`). - -In contrast, Beast abstracts the transport by defining just one [*`NextLayer`] -template argument The type requirements for [*`NextLayer`] are -already familiar to users as they are documented in Asio: -__AsyncReadStream__, __AsyncWriteStream__, __SyncReadStream__, __SyncWriteStream__. - -The type requirements for instantiating `beast::websocket::stream` versus -`websocketpp::connection` with user defined types are vastly reduced -(18 functions versus 2). Note that websocketpp connections are passed by -`shared_ptr`. Beast does not use `shared_ptr` anywhere in its public interface. -A `beast::websocket::stream` is constructible and movable in a manner identical -to a `boost::asio::ip::tcp::socket`. Callers can put such objects in a -`shared_ptr` if they want to, but there is no requirement to do so. - -[table - [ - [[@https://github.com/vinniefalco/Beast/blob/6c8b4b2f8dde72b01507e4ac7fde4ffea57ebc99/include/beast/websocket/stream.hpp Beast]] - [[@https://github.com/zaphoyd/websocketpp/blob/378437aecdcb1dfe62096ffd5d944bf1f640ccc3/websocketpp/connection.hpp#L234 websocketpp]] - ][ - [``` - template - class stream - { - NextLayer next_layer_; - ... - } - ```] - [``` - template - class connection - : public config::transport_type::transport_con_type - , public config::connection_base - { - public: - typedef lib::shared_ptr ptr; - ... - } - ```] -]]]] - -[[3. Client and Server Role][ - -websocketpp provides multi-role support through a hierarchy of -different classes. A `beast::websocket::stream` is role-agnostic, it -offers member functions to perform both client and server handshakes -in the same class. The same types are used for client and server -streams. - -[table - [ - [Beast] - [[@https://github.com/zaphoyd/websocketpp/blob/378437aecdcb1dfe62096ffd5d944bf1f640ccc3/websocketpp/roles/server_endpoint.hpp#L39 websocketpp], - [@https://github.com/zaphoyd/websocketpp/blob/378437aecdcb1dfe62096ffd5d944bf1f640ccc3/websocketpp/roles/client_endpoint.hpp#L42 also]] - ][ - [ - // - ] - [``` - template - class client : public endpoint,config>; - template - class server : public endpoint,config>; - ```] -]]]] - -[[4. Thread Safety][ - -websocketpp uses mutexes to protect shared data from concurrent -access. In contrast, Beast does not use mutexes anywhere in its -implementation. Instead, it follows the Asio pattern. Calls to -asynchronous initiation functions use the same method to invoke -intermediate handlers as the method used to invoke the final handler, -through the __asio_handler_invoke__ mechanism. - -The only requirement in Beast is that calls to asynchronous initiation -functions are made from the same implicit or explicit strand. For -example, if the `io_service` associated with a `beast::websocket::stream` -is single threaded, this counts as an implicit strand and no performance -costs associated with mutexes are incurred. - -[table - [ - [[@https://github.com/vinniefalco/Beast/blob/6c8b4b2f8dde72b01507e4ac7fde4ffea57ebc99/include/beast/websocket/impl/read_frame_op.ipp#L118 Beast]] - [[@https://github.com/zaphoyd/websocketpp/blob/378437aecdcb1dfe62096ffd5d944bf1f640ccc3/websocketpp/transport/iostream/connection.hpp#L706 websocketpp]] - ][ - [``` - template - friend - void asio_handler_invoke(Function&& f, read_frame_op* op) - { - return boost_asio_handler_invoke_helpers::invoke(f, op->d_->h); - } - ```] - [``` - mutex_type m_read_mutex; - ```] -]]]] - -[[5. Callback Model][ - -websocketpp requires a one-time call to set the handler for each event -in its interface (for example, upon message receipt). The handler is -represented by a `std::function` equivalent. Its important to recognize -that the websocketpp interface performs type-erasure on this handler. - -In comparison, Beast handlers are specified in a manner identical to -Boost.Asio. They are function objects which can be copied or moved but -most importantly they are not type erased. The compiler can see -through the type directly to the implementation, permitting -optimization. Furthermore, Beast follows the Asio rules for treatment -of handlers. It respects any allocation, continuation, or invocation -customizations associated with the handler through the use of argument -dependent lookup overloads of functions such as `asio_handler_allocate`. - -The Beast completion handler is provided at the call site. For each -call to an asynchronous initiation function, it is guaranteed that -there will be exactly one final call to the handler. This functions -exactly the same way as the asynchronous initiation functions found in -Boost.Asio, allowing the composition of higher level abstractions. - -[table - [ - [[@https://github.com/vinniefalco/Beast/blob/6c8b4b2f8dde72b01507e4ac7fde4ffea57ebc99/include/beast/websocket/stream.hpp#L834 Beast]] - [[@https://github.com/zaphoyd/websocketpp/blob/378437aecdcb1dfe62096ffd5d944bf1f640ccc3/websocketpp/connection.hpp#L281 websocketpp], - [@https://github.com/zaphoyd/websocketpp/blob/378437aecdcb1dfe62096ffd5d944bf1f640ccc3/websocketpp/connection.hpp#L473 also]] - ][ - [``` - template< - class DynamicBuffer, // Supports user defined types - class ReadHandler // Handler is NOT type-erased - > - typename async_completion< // Return value customization - ReadHandler, // supports futures and coroutines - void(error_code) - >::result_type - async_read( - DynamicBuffer& dynabuf, - ReadHandler&& handler); - ```] - [``` - typedef lib::function< - void(connection_hdl,message_ptr) - > message_handler; - void set_message_handler(message_handler h); - ```] -]]]] - -[[6. Extensible Asynchronous Model][ - -Beast fully supports the -[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3896.pdf Extensible Asynchronous Model] -developed by Christopher Kohlhoff, author of Boost.Asio (see Section 8). - -Beast websocket asynchronous interfaces may be used seamlessly with -`std::future` stackful/stackless coroutines, or user defined customizations. - -[table - [ - [[@https://github.com/vinniefalco/Beast/blob/6c8b4b2f8dde72b01507e4ac7fde4ffea57ebc99/include/beast/websocket/impl/stream.ipp#L378 Beast]] - [websocketpp] - ][ - [``` - beast::async_completion< - ReadHandler, - void(error_code)> completion{handler}; - read_op< - DynamicBuffer, decltype(completion.handler)>{ - completion.handler, *this, op, buffer}; - - return completion.result.get(); // Customization point - ```] - [ - // - ] -]]]] - -[[7. Message Buffering][ - -websocketpp defines a message buffer, passed in arguments by -`shared_ptr`, and an associated message manager which permits -aggregation and reuse of memory. The implementation of -`websocketpp::message` uses a `std::string` to hold the payload. If an -incoming message is broken up into multiple frames, the string may be -reallocated for each continuation frame. The `std::string` always uses -the standard allocator, it is not possible to customize the choice of -allocator. - -Beast allows callers to specify the object for receiving the message -or frame data, which is of any type meeting the requirements of -__DynamicBuffer__ (modeled after `boost::asio::streambuf`). - -Beast comes with the class __basic_multi_buffer__, an efficient -implementation of the __DynamicBuffer__ concept which makes use of multiple -allocated octet arrays. If an incoming message is broken up into -multiple pieces, no reallocation occurs. Instead, new allocations are -appended to the sequence when existing allocations are filled. Beast -does not impose any particular memory management model on callers. The -__basic_multi_buffer__ provided by beast supports standard allocators through -a template argument. Use the __DynamicBuffer__ that comes with beast, -customize the allocator if you desire, or provide your own type that -meets the requirements. - -[table - [ - [[@https://github.com/vinniefalco/Beast/blob/6c8b4b2f8dde72b01507e4ac7fde4ffea57ebc99/include/beast/websocket/stream.hpp#L774 Beast]] - [[@https://github.com/zaphoyd/websocketpp/blob/378437aecdcb1dfe62096ffd5d944bf1f640ccc3/websocketpp/message_buffer/message.hpp#L78 websocketpp]] - ][ - [``` - template - read(DynamicBuffer& dynabuf); - ```] - [``` - template class con_msg_manager> - class message { - public: - typedef lib::shared_ptr ptr; - ... - std::string m_payload; - ... - }; - ```] -]]]] - -[[8. Sending Messages][ - -When sending a message, websocketpp requires that the payload is -packaged in a `websocketpp::message` object using `std::string` as the -storage, or it requires a copy of the caller provided buffer by -constructing a new message object. Messages are placed onto an -outgoing queue. An asynchronous write operation runs in the background -to clear the queue. No user facing handler can be registered to be -notified when messages or frames have completed sending. - -Beast doesn't allocate or make copies of buffers when sending data. The -caller's buffers are sent in-place. You can use any object meeting the -requirements of -[@http://www.boost.org/doc/html/boost_asio/reference/ConstBufferSequence.html ConstBufferSequence], -permitting efficient scatter-gather I/O. - -The [*ConstBufferSequence] interface allows callers to send data from -memory-mapped regions (not possible in websocketpp). Callers can also -use the same buffers to send data to multiple streams, for example -broadcasting common subscription data to many clients at once. For -each call to `async_write` the completion handler is called once when -the data finishes sending, in a manner identical to `boost::asio::async_write`. - -[table - [ - [[@https://github.com/vinniefalco/Beast/blob/6c8b4b2f8dde72b01507e4ac7fde4ffea57ebc99/include/beast/websocket/stream.hpp#L1048 Beast]] - [[@https://github.com/zaphoyd/websocketpp/blob/378437aecdcb1dfe62096ffd5d944bf1f640ccc3/websocketpp/connection.hpp#L672 websocketpp]] - ][ - [``` - template - void - write(ConstBufferSequence const& buffers); - ```] - [``` - lib::error_code send(std::string const & payload, - frame::opcode::value op = frame::opcode::text); - ... - lib::error_code send(message_ptr msg); - ```] -]]]] - -[[9. Streaming Messages][ - -websocketpp requires that the entire message fit into memory, and that -the size is known ahead of time. - -Beast allows callers to compose messages in individual frames. This is -useful when the size of the data is not known ahead of time or if it -is not desired to buffer the entire message in memory at once before -sending it. For example, sending periodic output of a database query -running on a coroutine. Or sending the contents of a file in pieces, -without bringing it all into memory. - -[table - [ - [[@https://github.com/vinniefalco/Beast/blob/6c8b4b2f8dde72b01507e4ac7fde4ffea57ebc99/include/beast/websocket/stream.hpp#L1151 Beast]] - [websocketpp] - ][ - [``` - template - void - write_frame(bool fin, - ConstBufferSequence const& buffers); - ```] - [ - // - ] -]]]] - -[[10. Flow Control][ - -The websocketpp read implementation continuously reads asynchronously -from the network and buffers message data. To prevent unbounded growth -and leverage TCP/IP's flow control mechanism, callers can periodically -turn this 'read pump' off and back on. - -In contrast a `beast::websocket::stream` does not independently begin -background activity, nor does it buffer messages. It receives data only -when there is a call to an asynchronous initiation function (for -example `beast::websocket::stream::async_read`) with an associated handler. -Applications do not need to implement explicit logic to regulate the -flow of data. Instead, they follow the traditional model of issuing a -read, receiving a read completion, processing the message, then -issuing a new read and repeating the process. - -[table - [ - [Beast] - [[@https://github.com/zaphoyd/websocketpp/blob/378437aecdcb1dfe62096ffd5d944bf1f640ccc3/websocketpp/connection.hpp#L728 websocketpp]] - ][ - [ - // - ] - [``` - lib::error_code pause_reading(); - lib::error_code resume_reading(); - ```] -]]]] - -[[11. Connection Establishment][ - -websocketpp offers the `endpoint` class which can handle binding and -listening to a port, and spawning connection objects. - -Beast does not reinvent the wheel here, callers use the interfaces -already in `boost::asio` for receiving incoming connections resolving -host names, or establishing outgoing connections. After the socket (or -`boost::asio::ssl::stream`) is connected, the `beast::websocket::stream` -is constructed around it and the WebSocket handshake can be performed. - -Beast users are free to implement their own "connection manager", but -there is no requirement to do so. - -[table - [ - [[@http://www.boost.org/doc/html/boost_asio/reference/async_connect.html Beast], - [@http://www.boost.org/doc/html/boost_asio/reference/basic_socket_acceptor/async_accept.html also]] - [[@https://github.com/zaphoyd/websocketpp/blob/378437aecdcb1dfe62096ffd5d944bf1f640ccc3/websocketpp/transport/asio/endpoint.hpp#L52 websocketpp]] - ][ - [``` - #include - ```] - [``` - template - class endpoint : public config::socket_type; - ```] -]]]] - -[[12. WebSocket Handshaking][ - -Callers invoke `beast::websocket::accept` to perform the WebSocket -handshake, but there is no requirement to use this function. Advanced -users can perform the WebSocket handshake themselves. Beast WebSocket -provides the tools for composing the request or response, and the -Beast HTTP interface provides the container and algorithms for sending -and receiving HTTP/1 messages including the necessary HTTP Upgrade -request for establishing the WebSocket session. - -Beast allows the caller to pass the incoming HTTP Upgrade request for -the cases where the caller has already received an HTTP message. -This flexibility permits novel and robust implementations. For example, -a listening socket that can handshake in multiple protocols on the -same port. - -Sometimes callers want to read some bytes on the socket before reading -the WebSocket HTTP Upgrade request. Beast allows these already-received -bytes to be supplied to an overload of the accepting function to permit -sophisticated features. For example, a listening socket that can -accept both regular WebSocket and Secure WebSocket (SSL) connections. - -[table - [ - [[@https://github.com/vinniefalco/Beast/blob/6c8b4b2f8dde72b01507e4ac7fde4ffea57ebc99/include/beast/websocket/stream.hpp#L501 Beast], - [@https://github.com/vinniefalco/Beast/blob/6c8b4b2f8dde72b01507e4ac7fde4ffea57ebc99/include/beast/websocket/stream.hpp#L401 also]] - [websocketpp] - ][ - [``` - template - void - accept(ConstBufferSequence const& buffers); - - template - void - accept(http::header> const& req); - ```] - [ - // - ] -]]]] - -] -]] - -] - -[endsect] diff --git a/src/beast/doc/9_4_faq.qbk b/src/beast/doc/9_4_faq.qbk deleted file mode 100644 index 99ba6c20af4..00000000000 --- a/src/beast/doc/9_4_faq.qbk +++ /dev/null @@ -1,283 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section FAQ] - -To set realistic expectations and prevent a litany of duplicate review -statements, these notes address the most common questions and comments -about Beast and other HTTP libraries that have gone through formal review. - -[variablelist -[[ - "Beast requires too much user code to do anything!" -][ - It is not the intention of the library to provide turn-key - solutions for specific HTTP or WebSocket use-cases. - Instead, it is a sensible protocol layering on top of - Boost.Asio which retains the Boost.Asio memory - management style and asynchronous model. -]] -[[ - "Beast does not offer an HTTP server?" -][ - Beast has a functional HTTP server in the example directory. The - server supports both HTTP and WebSocket using synchronous and - asynchronous shared or dedicated ports. In addition, the server - supports encrypted TLS connections if OpenSSL is available, on - dedicated ports. And the server comes with a "multi-port", a - flexible single port which supports both encrypted and unencrypted - connections, both HTTP and WebSocket, all on the same port. The - server is not part of Beast's public interfaces, as that - functionality is outside the scope of the library. The author - feels that attempting to broaden the scope of the library will - reduce its appeal for standardization. -]] -[[ - "Beast does not offer an HTTP client?" -][ - "I just want to download a resource using HTTP" is a common - cry from users and reviewers. Such functionality is beyond - the scope of Beast. Building a full featured HTTP client is - a difficult task and large enough to deserve its own library. - There are many things to deal with such as the various message - body encodings, complex parsing of headers, difficult header - semantics such as Range and Cache-Control, redirection, - Expect:100-continue, connection retrying, domain name - resolution, TLS, and much, much more. It is the author's - position that Boost first needs a common set of nouns and - verbs for manipulating HTTP at the protocol level; Beast - provides that language. -]] -[[ - "There's no HTTP/2 support yet!" -][ - Many reviewers feel that HTTP/2 support is an essential feature of - a HTTP library. The authors agree that HTTP/2 is important but also - feel that the most sensible implementation is one that does not re-use - the same network reading and writing interface for 2 as that for 1.0 - and 1.1. - - The Beast HTTP message model was designed with the new protocol - in mind and should be evaluated in that context. There are plans - to add HTTP/2 in the future, but there is no rush to do so. - Users can work with HTTP/1 now; we should not deny them that - functionality today to wait for a newer protocol tomorrow. - It is the author's position that there is sufficient value in - Beast's HTTP/1-only implementation that the lack of HTTP/2 - should not be a barrier to acceptance. - - The Beast HTTP message model is suitable for HTTP/2 and can be re-used. - The IETF HTTP Working Group adopted message compatibility with HTTP/1.x - as an explicit goal. A parser can simply emit full headers after - decoding the compressed HTTP/2 headers. The stream ID is not logically - part of the message but rather message metadata and should be - communicated out-of-band (see below). HTTP/2 sessions begin with a - traditional HTTP/1.1 Upgrade similar in fashion to the WebSocket - upgrade. An HTTP/2 implementation can use existing Beast.HTTP primitives - to perform this handshake. -]] -[[ - "This should work with standalone-Asio!" -][ - Beast uses more than Boost.Asio, it depends on various other parts - of Boost. The standalone Asio is currently farther ahead than the - Boost version. Keeping Beast maintained against both versions of - Asio is beyond the resources of the author at the present time. - Compatibility with non-Boost libraries should not be an acceptance - criteria. Beast is currently designed to be a part of Boost: - nothing more, nothing less. Looking at the bigger picture, it - is the author's goal to propose this library for standardization. - A logical track for achieving this is as follows: - - [ordered_list - [ - Boost library acceptance. - ][ - Port to the Boost.Asio version of Networking-TS (This has to wait - until Boost's version of Asio is updated). - ][ - Wait for Networking-TS to become an official part of C++. - ][ - Port to the standard library versions of networking (gcc, clang, msvc). - ][ - Develop proposed language (This can happen concurrently with steps 3 and 4) - ]] -]] -[[ - "You need benchmarks!" -][ - The energy invested in Beast went into the design of the interfaces, - not performance. That said, the most sensitive parts of Beast have - been optimized or designed with optimization in mind. The slow parts - of WebSocket processing have been optimized, and the HTTP parser design - is lifted from another extremely popular project which has performance - as a design goal (see [@https://github.com/h2o/picohttpparser]). - - From: [@http://www.boost.org/development/requirements.html] - - "Aim first for clarity and correctness; optimization should - be only a secondary concern in most Boost libraries." - - As the library matures it will undergo optimization passes; benchmarks - will logically accompany this process. There is a small benchmarking - program included in the tests which compares the performance of - Beast's parser to the NodeJS reference parser, as well as some - benchmarks which compare the performance of various Beast dynamic - buffer implementations against Asio's. -]] -[[ - "Beast is a terrible name!" -][ - The name "Boost.Http" or "Boost.WebSocket" would mislead users into - believing they could perform an HTTP request on a URL or put up a - WebSocket client or server in a couple of lines of code. Where - would the core utilities go? Very likely it would step on the - owner of Boost.Asio's toes to put things in the boost/asio - directory; at the very least, it would create unrequested, - additional work for the foreign repository. - - "Beast" is sufficiently vague as to not suggest any particular - functionality, while acting as a memorable umbrella term for a - family of low level containers and algorithms. People in the know - or with a need for low-level network protocol operations will - have no trouble finding it, and the chances of luring a novice - into a bad experience are greatly reduced. - There is precedent for proper names: "Hana", "Fusion", "Phoenix", - and "Spirit" come to mind. Is "Beast" really any worse than say, - "mp11" for example? - Beast also already has a growing body of users and attention from - the open source community, the name Beast comes up in reddit posts - and StackOverflow as the answer to questions about which HTTP or - WebSocket library to use. -]] - - - -[[ - "Some more advanced examples, e.g. including TLS with client/server - certificates would help." -][ - The server-framework example demonstrates how to implement a server - that supports TLS using certificates. There are also websocket and - HTTP client examples which use TLS. Furthermore, management of - certificates is beyond the scope of the public interfaces of the - library. Asio already provides documentation, interfaces, and - examples for performing these tasks - Beast does not intend to - reinvent them or to redundantly provide this information. -]] - -[[ - "A built-in HTTP router?" -][ - We presume this means a facility to match expressions against the URI - in HTTP requests, and dispatch them to calling code. The authors feel - that this is a responsibility of higher level code. Beast does - not try to offer a web server. That said, the server-framework - example has a concept of request routing called a Service. Two - services are provided, one for serving files and the other for - handling WebSocket upgrade requests. -]] - -[[ - "HTTP Cookies? Forms/File Uploads?" -][ - Cookies, or managing these types of HTTP headers in general, is the - responsibility of higher levels. Beast just tries to get complete - messages to and from the calling code. It deals in the HTTP headers just - enough to process the message body and leaves the rest to callers. However, - for forms and file uploads the symmetric interface of the message class - allows HTTP requests to include arbitrary body types including those needed - to upload a file or fill out a form. -]] - -[[ - "...supporting TLS (is this a feature? If not this would be a show-stopper), - etc." -][ - Beast works with the Stream concept, so it automatically works with the - `boost::asio::ssl::stream` that you have already set up through Asio. -]] - -[[ - "There should also be more examples of how to integrate the http service - with getting files from the file system, generating responses CGI-style" -][ - The design goal for the library is to not try to invent a web server. - We feel that there is a strong need for a basic implementation that - models the HTTP message and provides functions to send and receive them - over Asio. Such an implementation should serve as a building block upon - which higher abstractions such as the aforementioned HTTP service or - cgi-gateway can be built. - - There are several HTTP servers in the example directory which deliver - files, as well as some tested and compiled code snippets which can be - used as a starting point for interfacing with other processes. -]] - -[[ - "You should send a 100-continue to ask for the rest of the body if required." -][ - Deciding on whether to send the "Expect: 100-continue" header or - how to handle it on the server side is the caller's responsibility; - Beast provides the functionality to send or inspect the header before - sending or reading the body. -]] - - - -[[ - "I would also like to see instances of this library being used - in production. That would give some evidence that the design - works in practice." -][ - Beast has already been on public servers receiving traffic and handling - hundreds of millions of dollars' worth of financial transactions daily. - The servers run [*rippled], open source software - ([@https://github.com/ripple/rippled repository]) - implementing the - [@https://ripple.com/files/ripple_consensus_whitepaper.pdf [*Ripple Consensus Protocol]], - technology provided by [@http://ripple.com Ripple]. - - Furthermore, the repository has grown significantly in popularity in - 2017. There are many users, and some of them participate directly in - the repository by reporting issues, performing testing, and in some - cases submitting pull requests with code contributions. -]] - - - -[[ - What about WebSocket message compression? -][ - Beast WebSocket supports the permessage-deflate extension described in - [@https://tools.ietf.org/html/draft-ietf-hybi-permessage-compression-00 draft-ietf-hybi-permessage-compression-00]. - The library comes with a header-only, C++11 port of ZLib's "deflate" codec - used in the implementation of the permessage-deflate extension. -]] -[[ - Where is the WebSocket TLS/SSL interface? -][ - The `websocket::stream` wraps the socket or stream that you provide - (for example, a `boost::asio::ip::tcp::socket` or a - `boost::asio::ssl::stream`). You establish your TLS connection using the - interface on `ssl::stream` like shown in all of the Asio examples, then - construct your `websocket::stream` around it. It works perfectly fine; - Beast comes with an `ssl_stream` wrapper in the example directory which - allows the SSL stream to be moved, overcoming an Asio limitation. - - The WebSocket implementation [*does] provide support for shutting down - the TLS connection through the use of the ADL compile-time virtual functions - [link beast.ref.beast__websocket__teardown `teardown`] and - [link beast.ref.beast__websocket__async_teardown `async_teardown`]. These will - properly close the connection as per rfc6455 and overloads are available - for TLS streams. Callers may provide their own overloads of these functions - for user-defined next layer types. -]] - -] - -[endsect] diff --git a/src/beast/doc/Dockerfile b/src/beast/doc/Dockerfile deleted file mode 100644 index 46ba0ee33ec..00000000000 --- a/src/beast/doc/Dockerfile +++ /dev/null @@ -1,22 +0,0 @@ -FROM ubuntu:16.04 - -RUN apt-get update -RUN apt-get -y install build-essential g++ git libbz2-dev wget python-dev - -# Install Boost -ENV BOOST_SHA 440a59f8bc4023dbe6285c9998b0f7fa288468b889746b1ef00e8b36c559dce1 -RUN wget https://sourceforge.net/projects/boost/files/boost/1.62.0/boost_1_62_0.tar.gz -RUN echo "$BOOST_SHA boost_1_62_0.tar.gz" | sha256sum -c -RUN tar xzf boost_1_62_0.tar.gz -RUN cd boost_1_62_0 && ./bootstrap.sh --prefix=/usr/local -RUN cd boost_1_62_0 && ./b2 install -ENV BOOST_ROOT=/boost_1_62_0 - -# Install dependencies -RUN apt-get -y install doxygen -RUN apt-get -y install xsltproc - -CMD cd /opt/beast/doc && \ - chmod +x makeqbk.sh && \ - ./makeqbk.sh && \ - $BOOST_ROOT/b2 diff --git a/src/beast/doc/Jamfile b/src/beast/doc/Jamfile deleted file mode 100644 index 24b2cf7e401..00000000000 --- a/src/beast/doc/Jamfile +++ /dev/null @@ -1,81 +0,0 @@ -# -# Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -# -# 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) -# - -import os ; - -local broot = [ os.environ BOOST_ROOT ] ; - -project beast/doc ; - -using boostbook ; -using quickbook ; -using doxygen ; - -import quickbook ; - -path-constant out : . ; - -install stylesheets - : - $(broot)/doc/src/boostbook.css - : - $(out)/html - ; - -explicit stylesheets ; - -install images - : - [ glob $(broot)/doc/src/images/*.png ] - images/beast.png - images/message.png - : - $(out)/html/images - ; - -explicit images ; - -install callouts - : - [ glob $(broot)/doc/src/images/callouts/*.png ] - : - $(out)/html/images/callouts - ; - -explicit callout ; - -xml doc - : - 0_main.qbk - : - temp - $(broot)/tools/boostbook/dtd - ; - -boostbook boostdoc - : - doc - : - boost.root=$(broot) - boost.image.src=images/beast.png - boost.image.alt="Beast Logo" - boost.image.w=1330 - boost.image.h=80 - chapter.autolabel=0 - chunk.section.depth=8 # Depth to which sections should be chunked - chunk.first.sections=1 # Chunk the first top-level section? - toc.section.depth=8 # How deep should recursive sections appear in the TOC? - toc.max.depth=8 # How many levels should be created for each TOC? - generate.section.toc.level=8 # Control depth of TOC generation in sections - generate.toc="chapter toc,title section nop reference nop" - $(broot)/tools/boostbook/dtd - : - temp - images - stylesheets - ; - diff --git a/src/beast/doc/boostbook.dtd b/src/beast/doc/boostbook.dtd deleted file mode 100644 index bd4c3f871ee..00000000000 --- a/src/beast/doc/boostbook.dtd +++ /dev/null @@ -1,439 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -%DocBook; diff --git a/src/beast/doc/concept/Body.qbk b/src/beast/doc/concept/Body.qbk deleted file mode 100644 index 5421286afe6..00000000000 --- a/src/beast/doc/concept/Body.qbk +++ /dev/null @@ -1,105 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section:Body Body] - -A [*Body] type is supplied as a template argument to the __message__ class. It -controls both the type of the data member of the resulting message object, and -the algorithms used during parsing and serialization. - -In this table: - -* `X` is a type meeting the requirements of [*Body]. - -* `m` is a value of type `message` where `b` is a `bool` value - and `F` is a type meeting the requirements of [*Fields]. - -[table Body requirements -[[expression] [type] [semantics, pre/post-conditions]] -[ - [`X::value_type`] - [] - [ - The type of the `message::body` member. - If this is not movable or not copyable, the containing message - will be not movable or not copyable. - ] -][ - [`X::writer`] - [] - [ - If present, indicates that the body can hold a message body - parsing result. The type must meet the requirements of - __BodyWriter__. The implementation constructs an object of - this type to obtain buffers into which parsed body octets - are placed. - ] -][ - [`X::reader`] - [] - [ - If present, indicates that the body is serializable. The type - must meet the requirements of __BodyReader__. The implementation - constructs an object of this type to obtain buffers representing - the message body for serialization. - ] -][ - [`X::size(X::value_type v)`] - [`std::uint64_t`] - [ - This static member function is optional. It returns the payload - size of `v` not including any chunked transfer encoding. The - function shall not exit via an exception. - - When this function is present: - - * The function shall not fail - - * A call to - [link beast.ref.beast__http__message.payload_size `message::payload_size`] - will return the same value as `size`. - - * A call to - [link beast.ref.beast__http__message.prepare_payload `message::prepare_payload`] - will remove "chunked" from the Transfer-Encoding field if it appears - as the last encoding, and will set the Content-Length field to the - returned value. - - Otherwise, when the function is omitted: - - * A call to - [link beast.ref.beast__http__message.payload_size `message::payload_size`] - will return `boost::none`. - - * A call to - [link beast.ref.beast__http__message.prepare_payload `message::prepare_payload`] - will erase the Content-Length field, and add "chunked" as the last - encoding in the Transfer-Encoding field if it is not already present. - ] -][ - [`is_body`] - [`std::true_type`] - [ - An alias for `std::true_type` for `X`, otherwise an alias - for `std::false_type`. - ] -] -] - -[heading Exemplar] - -[concept_Body] - -[heading Models] - -* [link beast.ref.beast__http__basic_dynamic_body `basic_dynamic_body`] -* [link beast.ref.beast__http__buffer_body `buffer_body`] -* [link beast.ref.beast__http__dynamic_body `dynamic_body`] -* [link beast.ref.beast__http__empty_body `empty_body`] -* [link beast.ref.beast__http__string_body `string_body`] - -[endsect] diff --git a/src/beast/doc/concept/BodyReader.qbk b/src/beast/doc/concept/BodyReader.qbk deleted file mode 100644 index ec13aa1632e..00000000000 --- a/src/beast/doc/concept/BodyReader.qbk +++ /dev/null @@ -1,117 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section:BodyReader BodyReader] - -A [*BodyReader] provides an online algorithm to obtain a sequence of zero -or more buffers from a body during serialization. The implementation creates -an instance of this type when needed, and calls into it one or more times to -retrieve buffers holding body octets. The interface of [*BodyReader] is -intended to obtain buffers for these scenarios: - -* A body that does not entirely fit in memory. -* A body produced incrementally from coroutine output. -* A body represented by zero or more buffers already in memory. -* A body whose size is not known ahead of time. -* Body data generated dynamically from other threads. -* Body data computed algorithmically. - -In this table: - -* `X` denotes a type meeting the requirements of [*BodyReader]. - -* `B` denotes a __Body__ where - `std::is_same::value == true`. - -* `a` denotes a value of type `X`. - -* `m` denotes a possibly const value of type `message&` where - `std::is_same:value == true`. - -* `ec` is a value of type [link beast.ref.beast__error_code `error_code&`]. - -* `R` is the type `boost::optional>`. - -[heading Associated Types] - -* __Body__ - -* [link beast.ref.beast__http__is_body_reader `is_body_reader`] - -[heading BodyReader requirements] -[table Valid Expressions -[[Expression] [Type] [Semantics, Pre/Post-conditions]] -[ - [`X::const_buffers_type`] - [] - [ - A type which meets the requirements of __ConstBufferSequence__. - This is the type of buffer returned by `X::get`. - ] -][ - [`X(m);`] - [] - [ - Constructible from `m`. The lifetime of `m` is guaranteed - to end no earlier than after the `X` is destroyed. - The reader shall not access the contents of `m` before the - first call to `init`, permitting lazy construction of the - message. - - The constructor may optionally require that `m` is const, which - has these consequences: - - * If `X` requires that `m` is a const reference, then serializers - constructed for messages with this body type will also require a - const reference to a message, otherwise: - - * If `X` requires that `m` is a non-const reference, then serializers - constructed for messages with this body type will aso require - a non-const reference to a message. - ] -][ - [`a.init(ec)`] - [] - [ - Called once to fully initialize the object before any calls to - `get`. The message body becomes valid before entering this function, - and remains valid until the reader is destroyed. - The function will ensure that `!ec` is `true` if there was - no error or set to the appropriate error code if there was one. - ] -][ - [`a.get(ec)`] - [`R`] - [ - Called one or more times after `init` succeeds. This function - returns `boost::none` if all buffers representing the body have - been returned in previous calls or if it sets `ec` to indicate an - error. Otherwise, if there are buffers remaining the function - should return a pair with the first element containing a non-zero - length buffer sequence representing the next set of octets in - the body, while the second element is a `bool` meaning `true` - if there may be additional buffers returned on a subsequent call, - or `false` if the buffer returned on this call is the last - buffer representing the body. - The function will ensure that `!ec` is `true` if there was - no error or set to the appropriate error code if there was one. - ] -] -] - -[heading Exemplar] - -[concept_BodyReader] - -[heading Models] - -* [link beast.ref.beast__http__basic_dynamic_body.reader `basic_dynamic_body::reader`] -* [link beast.ref.beast__http__basic_file_body__reader `basic_file_body::reader`] -* [link beast.ref.beast__http__basic_string_body.reader `basic_string_body::reader`] -* [link beast.ref.beast__http__empty_body.reader `empty_body::reader`] - -[endsect] diff --git a/src/beast/doc/concept/BodyWriter.qbk b/src/beast/doc/concept/BodyWriter.qbk deleted file mode 100644 index 54c93fdcba3..00000000000 --- a/src/beast/doc/concept/BodyWriter.qbk +++ /dev/null @@ -1,119 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section:BodyWriter BodyWriter] - -A [*BodyWriter] provides an online algorithm to transfer a series of zero -or more buffers containing parsed body octets into a message container. The -__parser__ creates an instance of this type when needed, and calls into -it zero or more times to transfer buffers. The interface of [*BodyWriter] -is intended to allow the conversion of buffers into these scenarios for -representation: - -* Storing a body in a dynamic buffer -* Storing a body in a user defined container with a custom allocator -* Transformation of incoming body data before storage, for example - to compress it first. -* Saving body data to a file - -In this table: - -* `X` denotes a type meeting the requirements of [*BodyWriter]. - -* `B` denotes a __Body__ where - `std::is_same::value == true`. - -* `a` denotes a value of type `X`. - -* `b` is an object whose type meets the requirements of __ConstBufferSequence__ - -* `m` denotes a value of type `message&` where - `std::is_same::value == true`. - -* `n` is a value of type `boost::optional`. - -* `ec` is a value of type [link beast.ref.beast__error_code `error_code&`]. - -[heading Associated Types] - -* __Body__ -* [link beast.ref.beast__http__is_body_writer `is_body_writer`] - -[table Writer requirements -[[expression] [type] [semantics, pre/post-conditions]] -[ - [`X(m);`] - [] - [ - Constructible from `m`. The lifetime of `m` is guaranteed to - end no earlier than after the `X` is destroyed. The constructor - will be called after a complete header is stored in `m`, and - before parsing body octets for messages indicating that a body - is present The writer shall not access the contents of `m` before - the first call to `init`, permitting lazy construction of the - message. - - The function will ensure that `!ec` is `true` if there was - no error or set to the appropriate error code if there was one. - ] -][ - [`a.init(n, ec)`] - [] - [ - Called once to fully initialize the object before any calls to - `put`. The message body is valid before entering this function, - and remains valid until the writer is destroyed. - The value of `n` will be set to the content length of the - body if known, otherwise `n` will be equal to `boost::none`. - Implementations of [*BodyWriter] may use this information to - optimize allocation. - - The function will ensure that `!ec` is `true` if there was - no error or set to the appropriate error code if there was one. - ] -][ - [`a.put(b,ec)`] - [`std::size_t`] - [ - This function is called to append some or all of the buffers - specified by `b` into the body representation. The number of - bytes inserted from `b` is returned. If the number of bytes - inserted is less than the total input, the remainder of the - input will be presented in the next call to `put`. - The function will ensure that `!ec` is `true` if there was - no error or set to the appropriate error code if there was one. - ] -][ - [`a.finish(ec)`] - [] - [ - This function is called when no more body octets are remaining. - The function will ensure that `!ec` is `true` if there was - no error or set to the appropriate error code if there was one. - ] -][ - [`is_body_writer`] - [`std::true_type`] - [ - An alias for `std::true_type` for `B`, otherwise an alias - for `std::false_type`. - ] -] -] - -[heading Exemplar] - -[concept_BodyWriter] - -[heading Models] - -* [link beast.ref.beast__http__basic_dynamic_body.writer `basic_dynamic_body::writer`] -* [link beast.ref.beast__http__basic_file_body__reader `basic_file_body::writer`] -* [link beast.ref.beast__http__basic_string_body.writer `basic_string_body::writer`] -* [link beast.ref.beast__http__empty_body.writer `empty_body::writer`] - -[endsect] diff --git a/src/beast/doc/concept/BufferSequence.qbk b/src/beast/doc/concept/BufferSequence.qbk deleted file mode 100644 index 812d92ffb51..00000000000 --- a/src/beast/doc/concept/BufferSequence.qbk +++ /dev/null @@ -1,15 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section:BufferSequence BufferSequence] - -A [*BufferSequence] is a type meeting either of the following requirements: - -* __ConstBufferSequence__ -* __MutableBufferSequence__ - -[endsect] diff --git a/src/beast/doc/concept/DynamicBuffer.qbk b/src/beast/doc/concept/DynamicBuffer.qbk deleted file mode 100644 index c9abd7df363..00000000000 --- a/src/beast/doc/concept/DynamicBuffer.qbk +++ /dev/null @@ -1,136 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section:DynamicBuffer DynamicBuffer] - -A dynamic buffer encapsulates memory storage that may be automatically resized -as required, where the memory is divided into an input sequence followed by an -output sequence. These memory regions are internal to the dynamic buffer, but -direct access to the elements is provided to permit them to be efficiently used -with I/O operations, such as the send or receive operations of a socket. Data -written to the output sequence of a dynamic buffer object is appended to the -input sequence of the same object. - -The interface to this concept is intended to permit the following -implementation strategies: - -* A single contiguous octet array, which is reallocated as necessary to - accommodate changes in the size of the octet sequence. This is the - implementation approach currently offered by __flat_buffer__. - -* A sequence of one or more octet arrays, where each array is of the same - size. Additional octet array objects are appended to the sequence to - accommodate changes in the size of the octet sequence. - -* A sequence of one or more octet arrays of varying sizes. Additional octet - array objects are appended to the sequence to accommodate changes in the - size of the character sequence. This is the implementation approach - currently offered by __multi_buffer__. - -In this table: - -* `X` denotes a dynamic buffer class. -* `a` denotes a value of type `X`. -* `c` denotes a (possibly const) value of type `X`. -* `n` denotes a value of type `std::size_t`. -* `T` denotes a type meeting the requirements for __ConstBufferSequence__. -* `U` denotes a type meeting the requirements for __MutableBufferSequence__. - -[table DynamicBuffer requirements -[[expression] [type] [semantics, pre/post-conditions]] -[ - [`X::const_buffers_type`] - [`T`] - [ - This type represents the memory associated with the input sequence. - ] -] -[ - [`X::mutable_buffers_type`] - [`U`] - [ - This type represents the memory associated with the output sequence. - ] -] -[ - [`c.size()`] - [`std::size_t`] - [ - Returns the size, in bytes, of the input sequence. - ] -] -[ - [`c.max_size()`] - [`std::size_t`] - [ - Returns the permitted maximum of the sum of the sizes of the input - sequence and output sequence. - ] -] -[ - [`c.capacity()`] - [`std::size_t`] - [ - Returns the maximum sum of the sizes of the input sequence and output - sequence that the dynamic buffer can hold without requiring reallocation. - ] -] -[ - [`c.data()`] - [`X::const_buffers_type`] - [ - Returns a constant buffer sequence u that represents the memory - associated with the input sequence, and where `buffer_size(u) == size()`. - ] -] -[ - [`a.prepare(n)`] - [`X::mutable_buffers_type`] - [ - Returns a mutable buffer sequence u representing the output sequence, - and where `buffer_size(u) == n`. The dynamic buffer reallocates memory - as required. All constant or mutable buffer sequences previously - obtained using `data()` or `prepare()` are invalidated. - - Throws: `length_error` if `size() + n` exceeds `max_size()`. - ] -] -[ - [`a.commit(n)`] - [ ] - [ - Appends `n` bytes from the start of the output sequence to the end of - the input sequence. The remainder of the output sequence is discarded. - If `n` is greater than the size of the output sequence, the entire - output sequence is appended to the input sequence. All constant or - mutable buffer sequences previously obtained using `data()` or - `prepare()` are invalidated. - ] -] -[ - [`a.consume(n)`] - [ ] - [ - Removes `n` bytes from beginning of the input sequence. If `n` is - greater than the size of the input sequence, the entire input sequence - is removed. All constant or mutable buffer sequences previously - obtained using `data()` or `prepare()` are invalidated. - ] -] -] - -[heading Models] - -* [link beast.ref.beast__basic_flat_buffer `basic_flat_buffer`] -* [link beast.ref.beast__basic_multi_buffer `basic_multi_buffer`] -* [link beast.ref.beast__drain_buffer `drain_buffer`] -* [link beast.ref.beast__flat_buffer `flat_buffer`] -* [link beast.ref.beast__multi_buffer `multi_buffer`] -* [link beast.ref.beast__static_buffer `static_buffer`] -* [link beast.ref.beast__static_buffer_n `static_buffer_n`] - -[endsect] diff --git a/src/beast/doc/concept/Fields.qbk b/src/beast/doc/concept/Fields.qbk deleted file mode 100644 index a66a4282c06..00000000000 --- a/src/beast/doc/concept/Fields.qbk +++ /dev/null @@ -1,225 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section:Fields Fields] - -An instance of [*Fields] is a container for holding HTTP header fields -and their values. The implementation also calls upon the container to -store the request target and non-standard strings for method and obsolete -reason phrase as needed. Types which meet these requirements can always -be serialized. - -[heading Associated Types] - -* __FieldsReader__ - -* [link beast.ref.beast__http__is_fields `is_fields`] - -[heading Requirements] - -In this table: - -* `F` denotes a type that meets the requirements of [*Fields]. - -* `R` denotes a type meeting the requirements of __FieldsReader__. - -* `a` denotes a value of type `F`. - -* `c` denotes a (possibly const) value of type `F`. - -* `b` is a value of type `bool` - -* `n` is a value of type `boost::optional`. - -* `s` is a value of type [link beast.ref.beast__string_view `string_view`]. - -* `v` is a value of type `unsigned int` representing the HTTP-version. - -[table Valid expressions -[[Expression] [Type] [Semantics, Pre/Post-conditions]] -[ - [`F::reader`] - [`R`] - [ - A type which meets the requirements of __FieldsReader__. - ] -][ - [`c.get_method_impl()`] - [`string_view`] - [ - Returns the method text. - The implementation only calls this function for request - headers when retrieving the method text previously set - with a call to `set_method_impl` using a non-empty string. - ] -][ - [`c.get_target_impl()`] - [`string_view`] - [ - Returns the target string. - The implementation only calls this function for request headers. - ] -][ - [`c.get_reason_impl()`] - [`string_view`] - [ - Returns the obsolete request text. - The implementation only calls this for response headers when - retrieving the reason text previously set with a call to - `set_reason_impl` using a non-empty string. - ] -][ - [`c.get_chunked_impl()`] - [`bool`] - [ - Returns `true` if the - [@https://tools.ietf.org/html/rfc7230#section-3.3.1 [*Transfer-Encoding]] - field value indicates that the payload is chunk encoded. Both - of these conditions must be true: - [itemized_list - [ - The Transfer-Encoding field is present in the message. - ][ - The last item the value of the field is "chunked". - ]] - ] -][ - [`c.get_keep_alive_impl(v)`] - [`bool`] - [ - Returns `true` if the semantics of the - [@https://tools.ietf.org/html/rfc7230#section-6.1 [*Connection]] - field and version indicate that the connection should remain - open after the corresponding response is transmitted or received: - - [itemized_list - [ - If `(v < 11)` the function returns `true` if the "keep-alive" - token is present in the Connection field value. Otherwise the - function returns `false`. - ][ - If `(v == 11)`, the function returns `false` if the "close" - token is present in the Connection field value. Otherwise the - function returns `true`. - ]] - ] -][ - [`a.set_method_impl(s)`] - [] - [ - Stores a copy of `s` as the method text, or erases the previously - stored value if `s` is empty. - The implementation only calls this function for request headers. - This function may throw `std::invalid_argument` if the operation - is not supported by the container. - ] -][ - [`a.set_target_impl(s)`] - [] - [ - Stores a copy of `s` as the target, or erases the previously - stored value if `s` is empty. - The implementation only calls this function for request headers. - This function may throw `std::invalid_argument` if the operation - is not supported by the container. - ] -][ - [`a.set_reason_impl(s)`] - [] - [ - Stores a copy of `s` as the reason text, or erases the previously - stored value of the reason text if `s` is empty. - The implementation only calls this function for request headers. - This function may throw `std::invalid_argument` if the operation - is not supported by the container. - ] -][ - [`a.set_chunked_impl(b)`] - [] - [ - Adjusts the - [@https://tools.ietf.org/html/rfc7230#section-3.3.1 [*Transfer-Encoding]] - field as follows: - - [itemized_list - [ - If `b` is `true`, the "chunked" token is appended - to the list of encodings if it does not already appear - last in the list. - If the Transfer-Encoding field is absent, the field will - be inserted to the container with the value "chunked". - ][ - If `b` is `false, the "chunked" token is removed from the - list of encodings if it appears last in the list. - If the result of the removal leaves the list of encodings - empty, the Transfer-Encoding field shall not appear when - the associated __FieldsReader__ serializes the fields. - ]] - ] - -][ - [`a.set_content_length_impl(n)`] - [] - [ - Adjusts the - [@https://tools.ietf.org/html/rfc7230#section-3.3.2 [*Content-Length]] - field as follows: - - [itemized_list - [ - If `n` contains a value, the Content-Length field - will be set to the text representation of the value. - Any previous Content-Length fields are removed from - the container. - ][ - If `n` does not contain a value, any present Content-Length - fields are removed from the container. - ]] - ] - -][ - [`a.set_keep_alive_impl(v,b)`] - [] - [ - Adjusts the - [@https://tools.ietf.org/html/rfc7230#section-6.1 [*Connection]] - field value depending on the values of `v` and `b`. The field - value is treated as - [@https://tools.ietf.org/html/rfc7230#section-6.1 ['connection-option]] - (rfc7230). - - [itemized_list - [ - If `(v < 11 && b)`, then all "close" tokens present in the - value are removed, and the "keep-alive" token is added to - the valueif it is not already present. - ][ - If `(v < 11 && ! b)`, then all "close" and "keep-alive" - tokens present in the value are removed. - - ][ - If `(v == 11 && b)`, then all "keep-alive" and "close" - tokens present in the value are removed. - ][ - If `(v == 11 && ! b)`, then all "keep-alive" tokens present - in the value are removed, and the "close" token is added to - the value if it is not already present. - ]] - ] - -]] - -[heading Exemplar] - -[concept_Fields] - -[heading Models] - -* [link beast.ref.beast__http__basic_fields `basic_fields`] -* [link beast.ref.beast__http__fields `fields`] - -[endsect] diff --git a/src/beast/doc/concept/FieldsReader.qbk b/src/beast/doc/concept/FieldsReader.qbk deleted file mode 100644 index f7fa5fd45fb..00000000000 --- a/src/beast/doc/concept/FieldsReader.qbk +++ /dev/null @@ -1,84 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section:FieldsReader FieldsReader] - -A [*FieldsReader] provides a algorithm to obtain a sequence of buffers -representing the complete serialized HTTP/1 header for a set of fields. -The implementation constructs an instance of this type when needed, and -calls into it once to retrieve the buffers. - -[heading Associated Types] - -* __FieldsReader__ - -[heading Requirements] - -In this table: - -* `X` denotes a type that meets the requirements of [*FieldsReader]. - -* `F` denotes a __Fields__ where - `std::is_same::value == true`. - -* `a` is a value of type `X`. - -* `f` is a value of type `F`. - -* `v` is an `unsigned` value representing the HTTP version. - -* `c` is an `unsigned` representing the HTTP status-code. - -* `m` is a value of type [link beast.ref.beast__http__verb `verb`]. - -[table Valid expressions -[[expression][type][semantics, pre/post-conditions]] -[ - [`X::const_buffers_type`] - [] - [ - A type which meets the requirements of __ConstBufferSequence__. - This is the type of buffer returned by `X::get`. - ] -][ - [`X(f,v,m)`] - [] - [ - The implementation calls this constructor to indicate - that the fields being serialized form part of an HTTP - request. The lifetime of `f` is guaranteed - to end no earlier than after the `X` is destroyed. - ] -][ - [`X(f,v,c)`] - [] - [ - The implementation calls this constructor to indicate - that the fields being serialized form part of an HTTP - response. The lifetime of `f` is guaranteed - to end no earlier than after the `X` is destroyed. - ] -][ - [`a.get()`] - [`X::const_buffers_type`] - [ - Called once after construction, this function returns - a constant buffer sequence containing the serialized - representation of the HTTP request or response including - the final carriage return linefeed sequence (`"\r\n"`). - ] -]] - -[heading Exemplar] - -[concept_FieldsReader] - -[heading Models] - -* [link beast.ref.beast__http__basic_fields.reader `basic_fields::reader`] - -[endsect] diff --git a/src/beast/doc/concept/File.qbk b/src/beast/doc/concept/File.qbk deleted file mode 100644 index 35decc654db..00000000000 --- a/src/beast/doc/concept/File.qbk +++ /dev/null @@ -1,173 +0,0 @@ -[/ - Copyright (c) 2013-2016 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section:File File] - -The [*File] concept abstracts access to files in the underlying file system. -To support other platform interfaces, users may author their own [*File] -types which meet these requirements. - -In this table: - -* `F` is a [*File] type -* `f` is an instance of `F` -* `p` is a value of type `char const*` which points to a null - terminated utf-8 encoded string. -* `m` is an instance of [link beast.ref.beast__file_mode `file_mode`] -* `n` is a number of bytes, convertible to `std::size_t` -* `o` is a byte offset in the file, convertible to `std::uint64_t` -* `b` is any non-const pointer to memory -* `c` is any possibly-const pointer to memory -* `ec` is a reference of type [link beast.ref.beast__error_code `error_code`] - -[heading Associated Types] - -* [link beast.ref.beast__file_mode `file_mode`] -* [link beast.ref.beast__is_file `is_file`] - -[heading File Requirements] -[table Valid Expressions -[[Operation] [Return Type] [Semantics, Pre/Post-conditions]] -[ - [`F()`] - [ ] - [ - Default constructable - ] -] -[ - [`f.~F()`] - [ ] - [ - Destructible. - If `f` refers to an open file, it is first closed - as if by a call to `close` with the error ignored. - ] -] -[ - [`f.is_open()`] - [`bool`] - [ - Returns `true` if `f` refers to an open file, `false` otherwise. - ] -] -[ - [`f.close(ec)`] - [] - [ - If `f` refers to an open file, thie function attempts to - close the file. - Regardless of whether an error occurs or not, a subsequent - call to `f.is_open()` will return `false`. - The function will ensure that `!ec` is `true` if there was - no error or set to the appropriate error code if an error - occurred. - ] -] -[ - [`f.open(p,m,ec)`] - [] - [ - Attempts to open the file at the path specified by `p` - with the mode specified by `m`. - Upon success, a subsequent call to `f.is_open()` will - return `true`. - If `f` refers to an open file, it is first closed - as if by a call to `close` with the error ignored. - The function will ensure that `!ec` is `true` if there was - no error or set to the appropriate error code if an error - occurred. - - ] -] -[ - [`f.size(ec)`] - [`std::uint64_t`] - [ - If `f` refers to an open file, this function attempts to - determine the file size and return its value. - If `f` does not refer to an open file, the function will - set `ec` to `errc::invalid_argument` and return 0. - The function will ensure that `!ec` is `true` if there was - no error or set to the appropriate error code if an error - occurred. - ] -] -[ - [`f.pos(ec)`] - [`std::uint64_t`] - [ - If `f` refers to an open file, this function attempts to - determine the current file offset and return it. - If `f` does not refer to an open file, the function will - set `ec` to `errc::invalid_argument` and return 0. - The function will ensure that `!ec` is `true` if there was - no error or set to the appropriate error code if an error - occurred. - ] -] -[ - [`f.seek(o,ec)`] - [] - [ - Attempts to reposition the current file offset to the value - `o`, which represents a byte offset relative to the beginning - of the file. - If `f` does not refer to an open file, the function will - set `ec` to `errc::invalid_argument` and return immediately. - The function will ensure that `!ec` is `true` if there was - no error or set to the appropriate error code if an error - occurred. - ] -] -[ - [`f.read(b,n,ec)`] - [`std::size_t`] - [ - Attempts to read `n` bytes starting at the current file offset - from the open file referred to by `f`. - Bytes read are stored in the memory buffer at address `b` which - must be at least `n` bytes in size. - The function advances the file offset by the amount read, and - returns the number of bytes actually read, which may be less - than `n`. - If `f` does not refer to an open file, the function will - set `ec` to `errc::invalid_argument` and return immediately. - The function will ensure that `!ec` is `true` if there was - no error or set to the appropriate error code if an error - occurred. - ] -] -[ - [`f.write(c,n,ec)`] - [`std::size_t`] - [ - Attempts to write `n` bytes from the buffer pointed to by `c` to - the current file offset of the open file referred to by `f`. - The memory buffer at `c` must point to storage of at least `n` - bytes meant to be copied to the file. - The function advances the file offset by the amount written, - and returns the number of bytes actually written, which may be - less than `n`. - If `f` does not refer to an open file, the function will - set `ec` to `errc::invalid_argument` and return immediately. - The function will ensure that `!ec` is `true` if there was - no error or set to the appropriate error code if an error - occurred. - ] -] -] - -[heading Exemplar] - -[concept_File] - -[heading Models] - -* [link beast.ref.beast__file_stdio `file_stdio`] - -[endsect] diff --git a/src/beast/doc/concept/Streams.qbk b/src/beast/doc/concept/Streams.qbk deleted file mode 100644 index d55322daa6f..00000000000 --- a/src/beast/doc/concept/Streams.qbk +++ /dev/null @@ -1,34 +0,0 @@ -[/ - Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[section:streams Stream] - -Stream types represent objects capable of performing synchronous or -asynchronous I/O. They are based on concepts from `boost::asio`. - -[heading:Stream Stream] - -A type modeling [*Stream] meets either or both of the following requirements: - -* [*AsyncStream] -* [*SyncStream] - -[heading:AsyncStream AsyncStream] - -A type modeling [*AsyncStream] meets the following requirements: - -* __AsyncReadStream__ -* __AsyncWriteStream__ - -[heading:SyncStream SyncStream] - -A type modeling [*SyncStream] meets the following requirements: - -* __SyncReadStream__ -* __SyncWriteStream__ - -[endsect] diff --git a/src/beast/doc/docca/README.md b/src/beast/doc/docca/README.md deleted file mode 100644 index ab7aa9ef0ae..00000000000 --- a/src/beast/doc/docca/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# docca -Boost.Book XSLT C++ documentation system - -[Example Documentation](http://vinniefalco.github.io/docca/) diff --git a/src/beast/doc/docca/example/.gitignore b/src/beast/doc/docca/example/.gitignore deleted file mode 100644 index fc40be018b9..00000000000 --- a/src/beast/doc/docca/example/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -bin -html -temp -reference.qbk -out.txt diff --git a/src/beast/doc/docca/example/Jamfile b/src/beast/doc/docca/example/Jamfile deleted file mode 100644 index 61d564f0761..00000000000 --- a/src/beast/doc/docca/example/Jamfile +++ /dev/null @@ -1,65 +0,0 @@ -# -# Copyright (c) 2013-2016 Vinnie Falco (vinnie dot falco at gmail dot com) -# -# 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) -# - -import os ; - -local broot = [ os.environ BOOST_ROOT ] ; - -project docca/doc ; - -using boostbook ; -using quickbook ; -using doxygen ; - -xml docca_bb : main.qbk ; - -path-constant out : . ; - -install stylesheets - : - $(broot)/doc/src/boostbook.css - : - $(out)/html - ; - -explicit stylesheets ; - -install images - : - [ glob $(broot)/doc/src/images/*.png ] - : - $(out)/html/images - ; - -explicit images ; - -install callouts - : - [ glob $(broot)/doc/src/images/callouts/*.png ] - : - $(out)/html/images/callouts - ; - -explicit callout ; - -boostbook doc - : - docca_bb - : - chapter.autolabel=0 - boost.root=$(broot) - chapter.autolabel=0 - chunk.first.sections=1 # Chunk the first top-level section? - chunk.section.depth=8 # Depth to which sections should be chunked - generate.section.toc.level=1 # Control depth of TOC generation in sections - toc.max.depth=2 # How many levels should be created for each TOC? - toc.section.depth=2 # How deep should recursive sections appear in the TOC? - : - temp - stylesheets - images - ; diff --git a/src/beast/doc/docca/example/boostbook.dtd b/src/beast/doc/docca/example/boostbook.dtd deleted file mode 100644 index bd4c3f871ee..00000000000 --- a/src/beast/doc/docca/example/boostbook.dtd +++ /dev/null @@ -1,439 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -%DocBook; diff --git a/src/beast/doc/docca/example/include/docca/example.hpp b/src/beast/doc/docca/example/include/docca/example.hpp deleted file mode 100644 index daf1a47565f..00000000000 --- a/src/beast/doc/docca/example/include/docca/example.hpp +++ /dev/null @@ -1,851 +0,0 @@ -// -// Copyright (c) 2015-2016 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef EXAMPLE_HPP -#define EXAMPLE_HPP - -#include -#include - -// This is a sample header file to show docca XLST results -// -// namespace, enum, type alias, global, static global, -// function, static function, struct/class - -namespace example { - -/** Enum - - Description -*/ -enum enum_t -{ - /// 0 - zero, - - /// 1 - one, - - /// 2 - two -}; - -/** Enum class - - Description -*/ -enum class enum_c -{ - /// aaa - aaa, - - /// bbb - bbb, - - /// ccc - ccc -}; - -/** Type alias - - Description -*/ -using type = std::string; - -/** Template type alias - - Description -*/ -template -using t_type = std::vector; - -/** Void or deduced - - Description -*/ -using vod = void_or_deduced; - -/** Implementation-defined - - Description -*/ -using impdef = implementation_defined; - -/** Variable - - Description -*/ -extern std::size_t var; - -/** Static variable - - Description -*/ -static std::size_t s_var = 0; - -/** Brief with @b bold text. - - Function returning @ref type. - - @return The type - - @see t_func. - - @throw std::exception on error - @throw std::domain_error on bad parameters - - @par Thread Safety - - Cannot be called concurrently. - - @note Additional notes. - - @param arg1 Function parameter 1 - @param arg2 Function parameter 2 -*/ -type -func(int arg1, std::string arg2); - -/** Brief for function starting with _ - - @return @ref type - - @see func -*/ -type -_func(float arg1, std::size arg2); - -/** Brief. - - Function description. - - See @ref func. - - @tparam T Template parameter 1 - @tparam U Template parameter 2 - @tparam V Template parameter 3 - - @param t Function parameter 1 - @param u Function parameter 2 - @param v Function parameter 3 - - @return nothing -*/ -template -void -t_func(T t, U const& u, V&& v); - -/** Overloaded function 1 - - Description - - @param arg1 Parameter 1 -*/ -void -overload(int arg1); - -/** Overloaded function 2 - - Description - - @param arg1 Parameter 1 - @param arg2 Parameter 2 -*/ -void -overload(int arg1, int arg2); - -/** Overloaded function 3 - - Description - - @param arg1 Parameter 1 - @param arg2 Parameter 2 - @param arg3 Parameter 3 -*/ -void -overload(int arg1, int arg2, int arg3); - -/** Markdown examples - - @par List - - 1. Lists with extra long lines that can *span* multiple lines - and overflow even the longest of buffers. - 2. With Numbers - + Or not - + Nesting - 1. Deeply - + And returning `here`. - - Another list I enjoy: - - -# 1 - - 1.a - -# 1.a.1 - -# 1.a.2 - - 1.b - -# 2 - - 2.a - - 2.b - -# 2.b.1 - -# 2.b.2 - - 2.b.2.a - - 2.b.2.b - - @par Table - - First Header | Second Header - ------------- | ------------- - Content Cell | Content Cell - Content Cell | Content Cell -*/ -void markdown(); - -//------------------------------------------------------------------------------ - -namespace detail { - -/** Detail class - - Description -*/ -struct detail_type -{ -}; - -/** Detail function - - Description -*/ -void -detail_function(); - -} // detail - -//------------------------------------------------------------------------------ - -/// Nested namespace -namespace nested { - -/** Enum - - Description -*/ -enum enum_t -{ - /// 0 - zero, - - /// 1 - one, - - /// 2 - two -}; - -/** Enum class - - Description -*/ -enum class enum_c -{ - /// aaa - aaa, - - /// bbb - bbb, - - /// ccc - ccc -}; - -/** Type alias - - Description -*/ -using type = std::string; - -/** Template type alias - - Description -*/ -template -using t_type = std::vector; - -/** Variable - - Description -*/ -extern std::size_t var; - -/** Static variable - - Description -*/ -static std::size_t s_var = 0; - -/** Brief with @b bold text. - - Function returning @ref type. - - @return The type - - @see t_func. - - @throw std::exception on error - @throw std::domain_error on bad parameters - - @par Thread Safety - - Cannot be called concurrently. - - @note Additional notes. - - @param arg1 Function parameter 1 - @param arg2 Function parameter 2 -*/ -type -func(int arg1, std::string arg2); - -/** Brief for function starting with _ - -@return @ref type - -@see func -*/ -type -_func(float arg1, std::size arg2); - -/** Brief. - - Function description. - - See @ref func. - - @tparam T Template parameter 1 - @tparam U Template parameter 2 - @tparam V Template parameter 3 - - @param t Function parameter 1 - @param u Function parameter 2 - @param v Function parameter 3 - - @return nothing -*/ -template -void -t_func(T t, U const& u, V&& v); - -/** Overloaded function 1 - - Description - - @param arg1 Parameter 1 -*/ -void -overload(int arg1); - -/** Overloaded function 2 - - Description - - @param arg1 Parameter 1 - @param arg2 Parameter 2 -*/ -void -overload(int arg1, int arg2); - -/** Overloaded function 3 - - Description - - @param arg1 Parameter 1 - @param arg2 Parameter 2 - @param arg3 Parameter 3 -*/ -void -overload(int arg1, int arg2, int arg3); - -} // nested - -/// Overloads operators -struct Num -{ - - /// Addition - friend - Num - operator +(Num, Num); - - /// Subtraction - friend - Num - operator -(Num, Num); - - /// Multiplication - friend - Num - operator *(Num, Num); - - /// Division - friend - Num - operator /(Num, Num); - -}; - -/// @ref Num addition -Num -operator +(Num, Num); - -/// @ref Num subtraction -Num -operator -(Num, Num); - -/// @ref Num multiplication -Num -operator *(Num, Num); - -/// @ref Num division -Num -operator /(Num, Num); - -/** Template class type. - - Description. - - @tparam T Template parameter 1 - @tparam U Template parameter 2 -*/ -template -class class_type -{ -public: - /** Enum - - Description - */ - enum enum_t - { - /// 0 - zero, - - /// 1 - one, - - /// 2 - two, - - /// _3 - _three - }; - - /** Enum class - - Description - */ - enum class enum_c - { - /// aaa - aaa, - - /// bbb - bbb, - - /// ccc - ccc, - - /// _ddd - _ddd - }; - - /** Type alias - - Description - */ - using type = std::string; - - /** Template type alias - - Description - */ - template - using t_type = std::vector; - - /** Variable - - Description - */ - extern std::size_t var; - - /** Static variable - - Description - */ - static std::size_t s_var = 0; - - /** Default Ctor - - Description - */ - class_type(); - - /** Dtor - - Description - */ - ~class_type(); - - /** Brief with @b bold text. - - Function returning @ref type. - - @return The type - - @see t_func. - - @throw std::exception on error - @throw std::domain_error on bad parameters - - @par Thread Safety - - Cannot be called concurrently. - - @note Additional notes. - - @param arg1 Function parameter 1 - @param arg2 Function parameter 2 - */ - type - func(int arg1, std::string arg2); - - /** Brief. - - Function description. - - See @ref func. - - @tparam T Template parameter 1 - @tparam U Template parameter 2 - @tparam V Template parameter 3 - - @param t Function parameter 1 - @param u Function parameter 2 - @param v Function parameter 3 - - @return nothing - */ - template - void - t_func(T t, U const& u, V&& v); - - /** Overloaded function 1 - - Description - - @param arg1 Parameter 1 - */ - void - overload(int arg1); - - /** Overloaded function 2 - - Description - - @param arg1 Parameter 1 - @param arg2 Parameter 2 - */ - void - overload(int arg1, int arg2); - - /** Overloaded function 3 - - Description - - @param arg1 Parameter 1 - @param arg2 Parameter 2 - @param arg3 Parameter 3 - */ - void - overload(int arg1, int arg2, int arg3); - - /** Less-than operator - - Description - */ - bool - operator< (class_type const& rhs) const; - - /** Greater-than operator - - Description - */ - bool - operator> (class_type const& rhs) const; - - /** Less-than-or-equal-to operator - - Description - */ - bool - operator<= (class_type const& rhs) const; - - /** Greater-than-or-equal-to operator - - Description - */ - bool - operator>= (class_type const& rhs) const; - - /** Equality operator - - Description - */ - bool - operator== (class_type const& rhs) const; - - /** Inequality operator - - Description - */ - bool - operator!= (class_type const& rhs) const; - - /** Arrow operator - - Description - */ - std::size_t operator->() const; - - /** Index operator - - Description - */ - enum_c& operator[](std::size_t); - - /** Index operator - - Description - */ - enum_c operator[](std::size_t) const; - - /// Public data - std::size_t pub_data_; - - /// Public static data - static std::size_t pub_sdata_; - -protected: - /** Protected data - - Description - */ - std::size_t prot_data_; - - /** Protected enum - - Description - */ - enum_c _prot_enum; - - /** Static protected data - - Description - */ - static std::size_t prot_sdata_; - - /** Protected type - - Description - */ - struct prot_type - { - }; - - /** Protected function - - Description - */ - void prot_memfn(); - - /** Protected function returning @ref prot_type - - Description - */ - prot_type prot_rvmemfn(); - - /** Protected static member function - - Description - */ - static void static_prot_memfn(); - -private: - /** Private data - - Description - */ - std::size_t priv_data_; - - /** Static private data - - Description - */ - static std::size_t priv_sdata_; - - /** Private type - - Description - */ - struct priv_type - { - }; - - /** Private function - - Description - */ - void priv_memfn(); - - /** Private function returning *ref priv_type - - Description - */ - priv_type priv_rvmemfn(); - - /** Static private member function - - Description - */ - static void static_priv_memfn(); - - /** Friend class - - Description - */ - friend friend_class; -}; - -/// Other base class 1 -class other_base_class1 -{ -}; - -/// Other base class 2 -class other_base_class2 -{ -}; - -/** Derived type - - Description -*/ -template -class derived_type : - public class_type, - protected other_base_class1, - private other_base_class2 -{ -}; - -/** References to all identifiers: - - Description one @ref one - - @par See Also - - @li @ref type - - @li @ref t_type - - @li @ref vod - - @li @ref impdef - - @li @ref var - - @li @ref s_var - - @li @ref func - - @li @ref t_func - - @li @ref overload - - @li @ref nested::enum_t : @ref nested::zero @ref nested::one @ref nested::two - - @li @ref nested::enum_c : nested::enum_c::aaa @ref nested::enum_c::bbb @ref nested::enum_c::ccc - - @li @ref nested::type - - @li @ref nested::t_type - - @li @ref nested::var - - @li @ref nested::s_var - - @li @ref nested::func - - @li @ref nested::t_func - - @li @ref nested::overload - - @li @ref class_type - - @li @ref class_type::enum_t : @ref class_type::zero @ref class_type::one @ref class_type::two @ref class_type::_three - - @li @ref class_type::enum_c : class_type::enum_c::aaa @ref class_type::enum_c::bbb @ref class_type::enum_c::ccc class_type::enum_c::_ddd - - @li @ref class_type::type - - @li @ref class_type::t_type - - @li @ref class_type::var - - @li @ref class_type::s_var - - @li @ref class_type::class_type - - @li @ref class_type::func - - @li @ref class_type::t_func - - @li @ref class_type::overload - - @li @ref class_type::pub_data_ - - @li @ref class_type::pub_sdata_ - - @li @ref class_type::_prot_enum - - @li @ref class_type::prot_type - - @li @ref class_type::priv_type - - @li @ref derived_type - - @li @ref Num - -*/ -void all_ref(); - -} // example - -namespace other { - -/// other function -void func(); - -/// other class -struct class_type -{ -}; - - -} // other - -#endif diff --git a/src/beast/doc/docca/example/index.xml b/src/beast/doc/docca/example/index.xml deleted file mode 100644 index c364e4ed268..00000000000 --- a/src/beast/doc/docca/example/index.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - -
- Index - -
diff --git a/src/beast/doc/docca/example/main.qbk b/src/beast/doc/docca/example/main.qbk deleted file mode 100644 index 43ddf6ae18d..00000000000 --- a/src/beast/doc/docca/example/main.qbk +++ /dev/null @@ -1,28 +0,0 @@ -[/ - Copyright (c) 2013-2016 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - -[library docca - [quickbook 1.6] - [copyright 2016 Vinnie Falco] - [purpose Documentation Library] - [license - 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]) - ] - [category template] - [category generic] -] - -[template mdash[] '''— '''] -[template indexterm1[term1] ''''''[term1]''''''] -[template indexterm2[term1 term2] ''''''[term1]''''''[term2]''''''] - -[section:ref Reference] -[include reference.qbk] -[endsect] -[xinclude index.xml] diff --git a/src/beast/doc/docca/example/makeqbk.sh b/src/beast/doc/docca/example/makeqbk.sh deleted file mode 100644 index e6fa0c30a7f..00000000000 --- a/src/beast/doc/docca/example/makeqbk.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/bash - -# Copyright (c) 2013-2016 Vinnie Falco (vinnie dot falco at gmail dot com) -# -# 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) - -mkdir -p temp -doxygen source.dox -cd temp -xsltproc combine.xslt index.xml > all.xml -xsltproc ../reference.xsl all.xml > ../reference.qbk - diff --git a/src/beast/doc/docca/example/reference.xsl b/src/beast/doc/docca/example/reference.xsl deleted file mode 100644 index de567529433..00000000000 --- a/src/beast/doc/docca/example/reference.xsl +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/src/beast/doc/docca/example/source.dox b/src/beast/doc/docca/example/source.dox deleted file mode 100644 index c55616ee7b2..00000000000 --- a/src/beast/doc/docca/example/source.dox +++ /dev/null @@ -1,333 +0,0 @@ -#--------------------------------------------------------------------------- -# Project related configuration options -#--------------------------------------------------------------------------- -DOXYFILE_ENCODING = UTF-8 -PROJECT_NAME = "docca" -PROJECT_NUMBER = -PROJECT_BRIEF = Documentation Library -PROJECT_LOGO = -OUTPUT_DIRECTORY = -CREATE_SUBDIRS = NO -ALLOW_UNICODE_NAMES = NO -OUTPUT_LANGUAGE = English -BRIEF_MEMBER_DESC = YES -REPEAT_BRIEF = YES -ABBREVIATE_BRIEF = -ALWAYS_DETAILED_SEC = YES -INLINE_INHERITED_MEMB = YES -FULL_PATH_NAMES = NO -STRIP_FROM_PATH = include/ -STRIP_FROM_INC_PATH = -SHORT_NAMES = NO -JAVADOC_AUTOBRIEF = YES -QT_AUTOBRIEF = NO -MULTILINE_CPP_IS_BRIEF = YES -INHERIT_DOCS = YES -SEPARATE_MEMBER_PAGES = NO -TAB_SIZE = 4 -ALIASES = -TCL_SUBST = -OPTIMIZE_OUTPUT_FOR_C = NO -OPTIMIZE_OUTPUT_JAVA = NO -OPTIMIZE_FOR_FORTRAN = NO -OPTIMIZE_OUTPUT_VHDL = NO -EXTENSION_MAPPING = -MARKDOWN_SUPPORT = YES -AUTOLINK_SUPPORT = YES -BUILTIN_STL_SUPPORT = NO -CPP_CLI_SUPPORT = NO -SIP_SUPPORT = NO -IDL_PROPERTY_SUPPORT = YES -DISTRIBUTE_GROUP_DOC = NO -GROUP_NESTED_COMPOUNDS = NO -SUBGROUPING = YES -INLINE_GROUPED_CLASSES = NO -INLINE_SIMPLE_STRUCTS = NO -TYPEDEF_HIDES_STRUCT = NO -LOOKUP_CACHE_SIZE = 0 - -#--------------------------------------------------------------------------- -# Build related configuration options -#--------------------------------------------------------------------------- -EXTRACT_ALL = YES -EXTRACT_PRIVATE = YES -EXTRACT_PACKAGE = NO -EXTRACT_STATIC = YES -EXTRACT_LOCAL_CLASSES = NO -EXTRACT_LOCAL_METHODS = NO -EXTRACT_ANON_NSPACES = NO -HIDE_UNDOC_MEMBERS = NO -HIDE_UNDOC_CLASSES = NO -HIDE_FRIEND_COMPOUNDS = NO -HIDE_IN_BODY_DOCS = NO -INTERNAL_DOCS = NO -CASE_SENSE_NAMES = YES -HIDE_SCOPE_NAMES = NO -HIDE_COMPOUND_REFERENCE= NO -SHOW_INCLUDE_FILES = NO -SHOW_GROUPED_MEMB_INC = NO -FORCE_LOCAL_INCLUDES = NO -INLINE_INFO = NO -SORT_MEMBER_DOCS = NO -SORT_BRIEF_DOCS = NO -SORT_MEMBERS_CTORS_1ST = YES -SORT_GROUP_NAMES = NO -SORT_BY_SCOPE_NAME = NO -STRICT_PROTO_MATCHING = NO -GENERATE_TODOLIST = NO -GENERATE_TESTLIST = NO -GENERATE_BUGLIST = NO -GENERATE_DEPRECATEDLIST= NO -ENABLED_SECTIONS = -MAX_INITIALIZER_LINES = 30 -SHOW_USED_FILES = NO -SHOW_FILES = NO -SHOW_NAMESPACES = NO -FILE_VERSION_FILTER = -LAYOUT_FILE = -CITE_BIB_FILES = - -#--------------------------------------------------------------------------- -# Configuration options related to warning and progress messages -#--------------------------------------------------------------------------- -QUIET = NO -WARNINGS = YES -WARN_IF_UNDOCUMENTED = YES -WARN_IF_DOC_ERROR = YES -WARN_NO_PARAMDOC = NO -WARN_AS_ERROR = NO -WARN_FORMAT = "$file:$line: $text" -WARN_LOGFILE = - -#--------------------------------------------------------------------------- -# Configuration options related to the input files -#--------------------------------------------------------------------------- -INPUT = include/docca/example.hpp - -INPUT_ENCODING = UTF-8 -FILE_PATTERNS = -RECURSIVE = NO -EXCLUDE = -EXCLUDE_SYMLINKS = NO -EXCLUDE_PATTERNS = -EXCLUDE_SYMBOLS = -EXAMPLE_PATH = -EXAMPLE_PATTERNS = -EXAMPLE_RECURSIVE = YES -IMAGE_PATH = -INPUT_FILTER = -FILTER_PATTERNS = -FILTER_SOURCE_FILES = NO -FILTER_SOURCE_PATTERNS = -USE_MDFILE_AS_MAINPAGE = - -#--------------------------------------------------------------------------- -# Configuration options related to source browsing -#--------------------------------------------------------------------------- -SOURCE_BROWSER = NO -INLINE_SOURCES = NO -STRIP_CODE_COMMENTS = YES -REFERENCED_BY_RELATION = NO -REFERENCES_RELATION = NO -REFERENCES_LINK_SOURCE = YES -SOURCE_TOOLTIPS = YES -USE_HTAGS = NO -VERBATIM_HEADERS = YES -CLANG_ASSISTED_PARSING = NO -CLANG_OPTIONS = - -#--------------------------------------------------------------------------- -# Configuration options related to the alphabetical class index -#--------------------------------------------------------------------------- -ALPHABETICAL_INDEX = YES -COLS_IN_ALPHA_INDEX = 1 -IGNORE_PREFIX = - -#--------------------------------------------------------------------------- -# Configuration options related to the HTML output -#--------------------------------------------------------------------------- -GENERATE_HTML = NO -HTML_OUTPUT = dhtm -HTML_FILE_EXTENSION = .html -HTML_HEADER = -HTML_FOOTER = -HTML_STYLESHEET = -HTML_EXTRA_STYLESHEET = -HTML_EXTRA_FILES = -HTML_COLORSTYLE_HUE = 220 -HTML_COLORSTYLE_SAT = 100 -HTML_COLORSTYLE_GAMMA = 80 -HTML_TIMESTAMP = NO -HTML_DYNAMIC_SECTIONS = NO -HTML_INDEX_NUM_ENTRIES = 100 -GENERATE_DOCSET = NO -DOCSET_FEEDNAME = "Doxygen generated docs" -DOCSET_BUNDLE_ID = org.doxygen.Project -DOCSET_PUBLISHER_ID = org.doxygen.Publisher -DOCSET_PUBLISHER_NAME = Publisher -GENERATE_HTMLHELP = NO -CHM_FILE = -HHC_LOCATION = -GENERATE_CHI = NO -CHM_INDEX_ENCODING = -BINARY_TOC = NO -TOC_EXPAND = NO -GENERATE_QHP = NO -QCH_FILE = -QHP_NAMESPACE = org.doxygen.Project -QHP_VIRTUAL_FOLDER = doc -QHP_CUST_FILTER_NAME = -QHP_CUST_FILTER_ATTRS = -QHP_SECT_FILTER_ATTRS = -QHG_LOCATION = -GENERATE_ECLIPSEHELP = NO -ECLIPSE_DOC_ID = org.doxygen.Project -DISABLE_INDEX = NO -GENERATE_TREEVIEW = NO -ENUM_VALUES_PER_LINE = 4 -TREEVIEW_WIDTH = 250 -EXT_LINKS_IN_WINDOW = NO -FORMULA_FONTSIZE = 10 -FORMULA_TRANSPARENT = YES -USE_MATHJAX = NO -MATHJAX_FORMAT = HTML-CSS -MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest -MATHJAX_EXTENSIONS = -MATHJAX_CODEFILE = -SEARCHENGINE = YES -SERVER_BASED_SEARCH = NO -EXTERNAL_SEARCH = NO -SEARCHENGINE_URL = -SEARCHDATA_FILE = searchdata.xml -EXTERNAL_SEARCH_ID = -EXTRA_SEARCH_MAPPINGS = - -#--------------------------------------------------------------------------- -# Configuration options related to the LaTeX output -#--------------------------------------------------------------------------- -GENERATE_LATEX = NO -LATEX_OUTPUT = latex -LATEX_CMD_NAME = latex -MAKEINDEX_CMD_NAME = makeindex -COMPACT_LATEX = NO -PAPER_TYPE = a4 -EXTRA_PACKAGES = -LATEX_HEADER = -LATEX_FOOTER = -LATEX_EXTRA_STYLESHEET = -LATEX_EXTRA_FILES = -PDF_HYPERLINKS = YES -USE_PDFLATEX = YES -LATEX_BATCHMODE = NO -LATEX_HIDE_INDICES = NO -LATEX_SOURCE_CODE = NO -LATEX_BIB_STYLE = plain -LATEX_TIMESTAMP = NO - -#--------------------------------------------------------------------------- -# Configuration options related to the RTF output -#--------------------------------------------------------------------------- -GENERATE_RTF = NO -RTF_OUTPUT = rtf -COMPACT_RTF = NO -RTF_HYPERLINKS = NO -RTF_STYLESHEET_FILE = -RTF_EXTENSIONS_FILE = -RTF_SOURCE_CODE = NO - -#--------------------------------------------------------------------------- -# Configuration options related to the man page output -#--------------------------------------------------------------------------- -GENERATE_MAN = NO -MAN_OUTPUT = man -MAN_EXTENSION = .3 -MAN_SUBDIR = -MAN_LINKS = NO - -#--------------------------------------------------------------------------- -# Configuration options related to the XML output -#--------------------------------------------------------------------------- -GENERATE_XML = YES -XML_OUTPUT = temp/ -XML_PROGRAMLISTING = NO - -#--------------------------------------------------------------------------- -# Configuration options related to the DOCBOOK output -#--------------------------------------------------------------------------- -GENERATE_DOCBOOK = NO -DOCBOOK_OUTPUT = docbook -DOCBOOK_PROGRAMLISTING = NO - -#--------------------------------------------------------------------------- -# Configuration options for the AutoGen Definitions output -#--------------------------------------------------------------------------- -GENERATE_AUTOGEN_DEF = NO -GENERATE_PERLMOD = NO -PERLMOD_LATEX = NO -PERLMOD_PRETTY = YES -PERLMOD_MAKEVAR_PREFIX = - -#--------------------------------------------------------------------------- -# Configuration options related to the preprocessor -#--------------------------------------------------------------------------- -ENABLE_PREPROCESSING = YES -MACRO_EXPANSION = YES -EXPAND_ONLY_PREDEF = YES -SEARCH_INCLUDES = YES -INCLUDE_PATH = -INCLUDE_FILE_PATTERNS = -PREDEFINED = DOXYGEN \ - GENERATING_DOCS \ - _MSC_VER - -EXPAND_AS_DEFINED = -SKIP_FUNCTION_MACROS = YES - -#--------------------------------------------------------------------------- -# Configuration options related to external references -#--------------------------------------------------------------------------- -TAGFILES = -GENERATE_TAGFILE = -ALLEXTERNALS = NO -EXTERNAL_GROUPS = YES -EXTERNAL_PAGES = YES -PERL_PATH = /usr/bin/perl - -#--------------------------------------------------------------------------- -# Configuration options related to the dot tool -#--------------------------------------------------------------------------- -CLASS_DIAGRAMS = NO -MSCGEN_PATH = -DIA_PATH = -HIDE_UNDOC_RELATIONS = YES -HAVE_DOT = NO -DOT_NUM_THREADS = 0 -DOT_FONTNAME = Helvetica -DOT_FONTSIZE = 10 -DOT_FONTPATH = -CLASS_GRAPH = YES -COLLABORATION_GRAPH = YES -GROUP_GRAPHS = YES -UML_LOOK = NO -UML_LIMIT_NUM_FIELDS = 10 -TEMPLATE_RELATIONS = NO -INCLUDE_GRAPH = YES -INCLUDED_BY_GRAPH = YES -CALL_GRAPH = NO -CALLER_GRAPH = NO -GRAPHICAL_HIERARCHY = YES -DIRECTORY_GRAPH = YES -DOT_IMAGE_FORMAT = png -INTERACTIVE_SVG = NO -DOT_PATH = -DOTFILE_DIRS = -MSCFILE_DIRS = -DIAFILE_DIRS = -PLANTUML_JAR_PATH = -PLANTUML_INCLUDE_PATH = -DOT_GRAPH_MAX_NODES = 50 -MAX_DOT_GRAPH_DEPTH = 0 -DOT_TRANSPARENT = NO -DOT_MULTI_TARGETS = NO -GENERATE_LEGEND = YES -DOT_CLEANUP = YES diff --git a/src/beast/doc/docca/include/docca/doxygen.xsl b/src/beast/doc/docca/include/docca/doxygen.xsl deleted file mode 100644 index aca6707c57a..00000000000 --- a/src/beast/doc/docca/include/docca/doxygen.xsl +++ /dev/null @@ -1,1954 +0,0 @@ - - - - - - - - - - - - - - - - - - [/ - Copyright (c) 2013-2016 Vinnie Falco (vinnie dot falco at gmail dot com) - - 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) -] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * - - - - & - - - - &... - - - - && - - - - &&... - - - - - - - - - - - - - - - - - - - - - - - - - - - ``['implementation-defined]`` - - - ``[@http://www.boost.org/doc/libs/1_60_0/doc/html/boost_asio/reference/asynchronous_operations.html#boost_asio.reference.asynchronous_operations.return_type_of_an_initiating_function ['void-or-deduced]]`` - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [heading - - ] - - - - - [@ - - - - ] - - - - - - - - - - - - - `` - - - - - - `` - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ` - - ` - - - - ` - - ` - - - - - - - - - - - - - - - - - - - - - - # - - - * - - - - - -[*] - -['] - - - - - - [heading Exceptions] - [table [[Type][Thrown On]] - - - [heading Parameters] - [table [[Name][Description]] - - - [heading Template Parameters] - [table [[Type][Description]] - - - [table [[Name][Description]] - - - - ] - - - - - [[` - - `][ - - ]] - - - - - [table - - ] - - - - [ - - ] - - - - [ - - ] - - - - - - - [heading Return Value] - - - - [heading See Also] - - - - [heading Remarks] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \_ - - - - - - - - - - - - - - - - - \[ - - - - - - - \] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - :: - - - - - - - |1a| - [link - - ` - - `] - - [heading Debug] [table [[name][value]] - - - - - - - - - - - - - - - - - - - - - - - - :: - - - - - - - - - |1b| - [link - - ` - - `] - - - |1c| - [link - - ` - - `] - - - [role red - |1| - - - ] - - - - [heading Debug] [table [[name][value]] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |2| - [link - - ` - - `] - - - [role red - |2| - - ] - - - - [heading Debug] [table [[name][value]] - - - - - - - - - - - - - - - [role red - |6| - - ] - - - - - - - - - - - - - - - - - - - - - - - - - - [link - - - - - - - - - ` - - `] - - - [link - - ` - - `] - - - [role red - |8| - - ] - - - - - [role red - |9| - - ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [section: - - - - ] - - [heading Synopsis] - - - - ``` - - - - - - : - - - - - - - - - - , - - - - ``` - - - - - [heading Description] - - - - - - - - - -[endsect] - - - - - - - [heading Types] - [table [[Name][Description]] - - - [ - - - [[link - - - . - - [* - - ]]] [ - - - - ] - - - - - - - - - - - - - - [[link - - [* - - ]]] [ - - ] - - - ] - - ] - - - [heading Member Functions] - [table [[Name][Description]] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [ - [[link - . - [* - - ]]] [ - - - - - - - - ] ] - - - ] - - - [heading Protected Member Functions] - [table [[Name][Description]] - - - - - - - - - - - - - - - - - - - - - - - - - [ - [[link - . - [* - - ]]] [ - - - - - - - - ] ] - - - ] - - - [heading Private Member Functions] - [table [[Name][Description]] - - - - - - - - - - - - - - - - - - - - - - - - - [ - [[link - . - [* - - ]]] [ - - - - - - - - ] ] - - - ] - - - [heading Data Members] - [table [[Name][Description]] - - - [ - [[link - . - [* - - ]]] [ - - ] ] - - ] - - - [heading Protected Data Members] - [table [[Name][Description]] - - - [ - [[link - . - [* - - ]]] [ - - ] ] - - ] - - - [heading Private Data Members] - [table [[Name][Description]] - - - [ - [[link - . - [* - - ]]] [ - - ] ] - - ] - - - [heading Friends] - [table [[Name][Description]] - - - - - - - - - - - - - - - - - - - - - - - - - [ - [[link - . - [* - - ]]] [ - - - - - - - - ] ] - - - ] - - - [heading Related Functions] - [table [[Name][Description]] - - - - - - - - - - - - - - - - - - - - - - - - - [ - [[link . - [*]]] - [ - - - - - - - - - ] - ] - - - - ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [section: - - - - :: - - ] - [indexterm2 - - .. - - ] - - ``` - - - - - ``` - - ``` - - - - explicit - friend - static - virtual - - - - - - - - - - ``[link - - . - - .overload - - - - ]``( - - ) - - const - - ; - - ``[''''&raquo;''' - [link - - . - - .overload - - more...]]`` - - - - ``` - - - - [section: - - - - - overload - - - - - :: - - - ( - - of - - overloads) - - ] - - - - (Inherited from ` - - - - - `) - - - - [indexterm2 - - .. - - ] - - - [heading Synopsis] - - - - - - - - - - - - - - - - - - - - - ``` - - ``` - - - ``` - - ``` - - - [heading Description] - - - - - - - - - [endsect] [endsect] - - - [endsect] - - - - - - - - - ``` using - - = - - - - - - - - - ; ``` - - - - - - - - - - - - - - - - - - - - - - - - - - - - ``` - - static - - - - - - - - - ; ``` - - - - - - - ``` - enum - - ``` - - - - [indexterm2 - - .. - - ] - - - [heading Values] - [table [[Name][Description]] - - [[[^ - - ]][ - - - - ]] - - ] - - - - - - - - - - - - - - - - - - - - - - - static - virtual - - - - - - ( - - ) - const - ; - - - - - - template< - - > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - = - - - - , - - - - - - - - - (& - - ) - - - - - - - - - - - - - - = - - - - , - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [section: - - - - ] - [indexterm1 - - ] - - - - - - - - - - - - ``` - - - - - ``` - - ``` - - - - - - - - - - - - - ``[link - - .overload - - - - ]``( - - ); - - ``[''''&raquo;''' - [link - - .overload - - more...]]`` - - - - ``` - - - - - - [section: - - - - [section: - overload - - - - - - ( - - of - - overloads) - - ] - - [indexterm1 - - ] - - - [heading Synopsis] - - - - - - - - - - - - - - - - - - - - - - - ``` - - ``` - - - [heading Description] - - - [heading Debug] [table [[name][value]] - - - - - - - - - - - - - - - - - - [endsect] [endsect] - - - [endsect] - - - - - diff --git a/src/beast/doc/images/AlfaSlabOne-Regular.ttf b/src/beast/doc/images/AlfaSlabOne-Regular.ttf deleted file mode 100644 index ad70ebc75d0..00000000000 Binary files a/src/beast/doc/images/AlfaSlabOne-Regular.ttf and /dev/null differ diff --git a/src/beast/doc/images/CppCon2016.pdf b/src/beast/doc/images/CppCon2016.pdf deleted file mode 100644 index 464b63a0995..00000000000 Binary files a/src/beast/doc/images/CppCon2016.pdf and /dev/null differ diff --git a/src/beast/doc/images/CppCon2016.png b/src/beast/doc/images/CppCon2016.png deleted file mode 100644 index 2f169593c0f..00000000000 Binary files a/src/beast/doc/images/CppCon2016.png and /dev/null differ diff --git a/src/beast/doc/images/SIL Open Font License.txt b/src/beast/doc/images/SIL Open Font License.txt deleted file mode 100644 index 1cde0c6a7d5..00000000000 --- a/src/beast/doc/images/SIL Open Font License.txt +++ /dev/null @@ -1,43 +0,0 @@ -Copyright (c) 2011 JM Sole (info@jmsole.cl), with Reserved Font Name "Alfa Slab One" - -This Font Software is licensed under the SIL Open Font License, Version 1.1. -This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL - ------------------------------------------------------------ -SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 ------------------------------------------------------------ - -PREAMBLE -The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others. - -The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives. - -DEFINITIONS -"Font Software" refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation. - -"Reserved Font Name" refers to any names specified as such after the copyright statement(s). - -"Original Version" refers to the collection of Font Software components as distributed by the Copyright Holder(s). - -"Modified Version" refers to any derivative made by adding to, deleting, or substituting -- in part or in whole -- any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment. - -"Author" refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software. - -PERMISSION & CONDITIONS -Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions: - -1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself. - -2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user. - -3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users. - -4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission. - -5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software. - -TERMINATION -This license becomes null and void if any of the above conditions are not met. - -DISCLAIMER -THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE. \ No newline at end of file diff --git a/src/beast/doc/images/beast.png b/src/beast/doc/images/beast.png deleted file mode 100644 index eb7528ec9d5..00000000000 Binary files a/src/beast/doc/images/beast.png and /dev/null differ diff --git a/src/beast/doc/images/beast.psd b/src/beast/doc/images/beast.psd deleted file mode 100644 index dcb11f3fbe6..00000000000 Binary files a/src/beast/doc/images/beast.psd and /dev/null differ diff --git a/src/beast/doc/images/btc_qr2.png b/src/beast/doc/images/btc_qr2.png deleted file mode 100644 index 06380d6e99d..00000000000 Binary files a/src/beast/doc/images/btc_qr2.png and /dev/null differ diff --git a/src/beast/doc/images/message.png b/src/beast/doc/images/message.png deleted file mode 100644 index b1675df8cae..00000000000 Binary files a/src/beast/doc/images/message.png and /dev/null differ diff --git a/src/beast/doc/images/message.psd b/src/beast/doc/images/message.psd deleted file mode 100644 index 1f6ceaac531..00000000000 Binary files a/src/beast/doc/images/message.psd and /dev/null differ diff --git a/src/beast/doc/images/readme.png b/src/beast/doc/images/readme.png deleted file mode 100644 index 44b53c2e6c7..00000000000 Binary files a/src/beast/doc/images/readme.png and /dev/null differ diff --git a/src/beast/doc/images/server.png b/src/beast/doc/images/server.png deleted file mode 100644 index fc609800562..00000000000 Binary files a/src/beast/doc/images/server.png and /dev/null differ diff --git a/src/beast/doc/images/server.psd b/src/beast/doc/images/server.psd deleted file mode 100644 index cf9d4452575..00000000000 Binary files a/src/beast/doc/images/server.psd and /dev/null differ diff --git a/src/beast/doc/index.xml b/src/beast/doc/index.xml deleted file mode 100644 index 5029fc9129d..00000000000 --- a/src/beast/doc/index.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - -
- Index - -
diff --git a/src/beast/doc/makeqbk.sh b/src/beast/doc/makeqbk.sh deleted file mode 100755 index b742a28bf38..00000000000 --- a/src/beast/doc/makeqbk.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh - -# Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -# -# 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) - -mkdir -p temp -doxygen source.dox -cd temp -xsltproc combine.xslt index.xml > all.xml -cp ../docca/include/docca/doxygen.xsl doxygen.xsl -sed -i -e '//{r ../xsl/class_detail.xsl' -e 'd}' doxygen.xsl -sed -i -e '//{r ../xsl/includes.xsl' -e 'd}' doxygen.xsl -sed -i -e '//{r ../xsl/includes_foot.xsl' -e 'd}' doxygen.xsl -xsltproc ../xsl/reference.xsl all.xml > ../reference.qbk diff --git a/src/beast/doc/quickref.xml b/src/beast/doc/quickref.xml deleted file mode 100644 index 3a0f5961a87..00000000000 --- a/src/beast/doc/quickref.xml +++ /dev/null @@ -1,296 +0,0 @@ - - - - - - - - - - - - - - - HTTP - - - WebSocket - - - - - - - Classes - - basic_dynamic_body - basic_file_body - basic_fields - basic_parser - basic_string_body - buffer_body - dynamic_body - empty_body - fields - header - message - parser - no_chunk_decorator - request - request_header - request_parser - request_serializer - response - response_header - response_parser - response_serializer - serializer - span_body - string_body - vector_body - - - - Functions - - async_read - async_read_header - async_read_some - async_write - async_write_header - async_write_some - int_to_status - obsolete_reason - operator<< - read - read_header - read_some - string_to_field - string_to_verb - swap - to_string - to_status_class - write - write_header - write_some - - rfc7230 - - ext_list - opt_token_list - param_list - token_list - - - - Constants - - error - field - status - status_class - verb - - Type Traits - - is_body - is_body_writer - is_body_reader - is_fields - - Concepts - - Body - BodyReader - BodyWriter - Fields - FieldsReader - - - - Classes - - close_reason - ping_data - stream - reason_string - - Functions - - async_teardown - is_upgrade - teardown - - Options - - permessage_deflate - - Constants - - close_code - error - frame_type - - - - - - - - - - - - - - - Core - - - ZLib - - - - - - - Classes - - async_completion - async_result - async_return_type - basic_flat_buffer - basic_multi_buffer - buffer_cat_view - buffer_prefix_view - buffered_read_stream - buffers_adapter - consuming_buffers - drain_buffer - error_category - error_code - error_condition - file - file_mode - - - -   - - file_posix - file_stdio - file_win32 - flat_buffer - handler_alloc - handler_ptr - handler_type - iequal - iless - multi_buffer - span - static_buffer - static_buffer_n - static_string - string_param - string_view - system_error - - - - Functions - - bind_handler - buffer_cat - buffer_prefix - buffers - generic_category - iequals - ostream - read_size - read_size_or_throw - system_category - to_static_string - - Constants - - errc - file_mode - - - - Type Traits - - get_lowest_layer - has_get_io_service - is_async_read_stream - is_async_write_stream - is_async_stream - is_completion_handler - is_const_buffer_sequence - is_dynamic_buffer - is_file - is_mutable_buffer_sequence - is_sync_read_stream - is_sync_stream - is_sync_write_stream - - - - Concepts - - AsyncStream - BufferSequence - DynamicBuffer - File - Stream - SyncStream - - - - Classes - - deflate_stream - inflate_stream - z_params - - Functions - - deflate_upper_bound - - Constants - - error - Flush - Strategy - - - - - - - - - - - Diagnostic - - - - - - - - doc_debug - nested_doc_debug - - - - - - diff --git a/src/beast/doc/source.dox b/src/beast/doc/source.dox deleted file mode 100644 index 7ead3bb099f..00000000000 --- a/src/beast/doc/source.dox +++ /dev/null @@ -1,341 +0,0 @@ -#--------------------------------------------------------------------------- -# Project related configuration options -#--------------------------------------------------------------------------- -DOXYFILE_ENCODING = UTF-8 -PROJECT_NAME = "Beast" -PROJECT_NUMBER = -PROJECT_BRIEF = C++ Library -PROJECT_LOGO = images/beast.png -OUTPUT_DIRECTORY = -CREATE_SUBDIRS = NO -ALLOW_UNICODE_NAMES = NO -OUTPUT_LANGUAGE = English -BRIEF_MEMBER_DESC = YES -REPEAT_BRIEF = YES -ABBREVIATE_BRIEF = -ALWAYS_DETAILED_SEC = NO -INLINE_INHERITED_MEMB = YES -FULL_PATH_NAMES = NO -STRIP_FROM_PATH = ../include/ -STRIP_FROM_INC_PATH = -SHORT_NAMES = NO -JAVADOC_AUTOBRIEF = YES -QT_AUTOBRIEF = NO -MULTILINE_CPP_IS_BRIEF = NO -INHERIT_DOCS = YES -SEPARATE_MEMBER_PAGES = NO -TAB_SIZE = 4 -ALIASES = -TCL_SUBST = -OPTIMIZE_OUTPUT_FOR_C = NO -OPTIMIZE_OUTPUT_JAVA = NO -OPTIMIZE_FOR_FORTRAN = NO -OPTIMIZE_OUTPUT_VHDL = NO -EXTENSION_MAPPING = -MARKDOWN_SUPPORT = YES -AUTOLINK_SUPPORT = YES -BUILTIN_STL_SUPPORT = NO -CPP_CLI_SUPPORT = NO -SIP_SUPPORT = NO -IDL_PROPERTY_SUPPORT = YES -DISTRIBUTE_GROUP_DOC = NO -GROUP_NESTED_COMPOUNDS = NO -SUBGROUPING = YES -INLINE_GROUPED_CLASSES = NO -INLINE_SIMPLE_STRUCTS = NO -TYPEDEF_HIDES_STRUCT = NO -LOOKUP_CACHE_SIZE = 0 - -#--------------------------------------------------------------------------- -# Build related configuration options -#--------------------------------------------------------------------------- -EXTRACT_ALL = YES -EXTRACT_PRIVATE = YES -EXTRACT_PACKAGE = NO -EXTRACT_STATIC = NO -EXTRACT_LOCAL_CLASSES = NO -EXTRACT_LOCAL_METHODS = NO -EXTRACT_ANON_NSPACES = NO -HIDE_UNDOC_MEMBERS = NO -HIDE_UNDOC_CLASSES = NO -HIDE_FRIEND_COMPOUNDS = NO -HIDE_IN_BODY_DOCS = NO -INTERNAL_DOCS = NO -CASE_SENSE_NAMES = YES -HIDE_SCOPE_NAMES = NO -HIDE_COMPOUND_REFERENCE= NO -SHOW_INCLUDE_FILES = NO -SHOW_GROUPED_MEMB_INC = NO -FORCE_LOCAL_INCLUDES = NO -INLINE_INFO = NO -SORT_MEMBER_DOCS = NO -SORT_BRIEF_DOCS = NO -SORT_MEMBERS_CTORS_1ST = YES -SORT_GROUP_NAMES = NO -SORT_BY_SCOPE_NAME = NO -STRICT_PROTO_MATCHING = NO -GENERATE_TODOLIST = NO -GENERATE_TESTLIST = NO -GENERATE_BUGLIST = NO -GENERATE_DEPRECATEDLIST= NO -ENABLED_SECTIONS = -MAX_INITIALIZER_LINES = 30 -SHOW_USED_FILES = NO -SHOW_FILES = NO -SHOW_NAMESPACES = NO -FILE_VERSION_FILTER = -LAYOUT_FILE = -CITE_BIB_FILES = - -#--------------------------------------------------------------------------- -# Configuration options related to warning and progress messages -#--------------------------------------------------------------------------- -QUIET = NO -WARNINGS = YES -WARN_IF_UNDOCUMENTED = YES -WARN_IF_DOC_ERROR = YES -WARN_NO_PARAMDOC = NO -WARN_AS_ERROR = NO -WARN_FORMAT = "$file:$line: $text" -WARN_LOGFILE = - -#--------------------------------------------------------------------------- -# Configuration options related to the input files -#--------------------------------------------------------------------------- -INPUT = \ - ../include/beast/ \ - ../include/beast/core \ - ../include/beast/http \ - ../include/beast/websocket \ - ../include/beast/zlib \ - ../extras/beast/doc_debug.hpp - -INPUT_ENCODING = UTF-8 -FILE_PATTERNS = -RECURSIVE = NO -EXCLUDE = -EXCLUDE_SYMLINKS = NO -EXCLUDE_PATTERNS = -EXCLUDE_SYMBOLS = -EXAMPLE_PATH = -EXAMPLE_PATTERNS = -EXAMPLE_RECURSIVE = NO -IMAGE_PATH = -INPUT_FILTER = -FILTER_PATTERNS = -FILTER_SOURCE_FILES = NO -FILTER_SOURCE_PATTERNS = -USE_MDFILE_AS_MAINPAGE = - -#--------------------------------------------------------------------------- -# Configuration options related to source browsing -#--------------------------------------------------------------------------- -SOURCE_BROWSER = NO -INLINE_SOURCES = NO -STRIP_CODE_COMMENTS = YES -REFERENCED_BY_RELATION = NO -REFERENCES_RELATION = NO -REFERENCES_LINK_SOURCE = YES -SOURCE_TOOLTIPS = YES -USE_HTAGS = NO -VERBATIM_HEADERS = YES -CLANG_ASSISTED_PARSING = NO -CLANG_OPTIONS = - -#--------------------------------------------------------------------------- -# Configuration options related to the alphabetical class index -#--------------------------------------------------------------------------- -ALPHABETICAL_INDEX = YES -COLS_IN_ALPHA_INDEX = 5 -IGNORE_PREFIX = - -#--------------------------------------------------------------------------- -# Configuration options related to the HTML output -#--------------------------------------------------------------------------- -GENERATE_HTML = NO -HTML_OUTPUT = dhtm -HTML_FILE_EXTENSION = .html -HTML_HEADER = -HTML_FOOTER = -HTML_STYLESHEET = -HTML_EXTRA_STYLESHEET = -HTML_EXTRA_FILES = -HTML_COLORSTYLE_HUE = 220 -HTML_COLORSTYLE_SAT = 100 -HTML_COLORSTYLE_GAMMA = 80 -HTML_TIMESTAMP = NO -HTML_DYNAMIC_SECTIONS = NO -HTML_INDEX_NUM_ENTRIES = 100 -GENERATE_DOCSET = NO -DOCSET_FEEDNAME = "Doxygen generated docs" -DOCSET_BUNDLE_ID = org.doxygen.Project -DOCSET_PUBLISHER_ID = org.doxygen.Publisher -DOCSET_PUBLISHER_NAME = Publisher -GENERATE_HTMLHELP = NO -CHM_FILE = -HHC_LOCATION = -GENERATE_CHI = NO -CHM_INDEX_ENCODING = -BINARY_TOC = NO -TOC_EXPAND = NO -GENERATE_QHP = NO -QCH_FILE = -QHP_NAMESPACE = org.doxygen.Project -QHP_VIRTUAL_FOLDER = doc -QHP_CUST_FILTER_NAME = -QHP_CUST_FILTER_ATTRS = -QHP_SECT_FILTER_ATTRS = -QHG_LOCATION = -GENERATE_ECLIPSEHELP = NO -ECLIPSE_DOC_ID = org.doxygen.Project -DISABLE_INDEX = NO -GENERATE_TREEVIEW = NO -ENUM_VALUES_PER_LINE = 4 -TREEVIEW_WIDTH = 250 -EXT_LINKS_IN_WINDOW = NO -FORMULA_FONTSIZE = 10 -FORMULA_TRANSPARENT = YES -USE_MATHJAX = NO -MATHJAX_FORMAT = HTML-CSS -MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest -MATHJAX_EXTENSIONS = -MATHJAX_CODEFILE = -SEARCHENGINE = YES -SERVER_BASED_SEARCH = NO -EXTERNAL_SEARCH = NO -SEARCHENGINE_URL = -SEARCHDATA_FILE = searchdata.xml -EXTERNAL_SEARCH_ID = -EXTRA_SEARCH_MAPPINGS = - -#--------------------------------------------------------------------------- -# Configuration options related to the LaTeX output -#--------------------------------------------------------------------------- -GENERATE_LATEX = NO -LATEX_OUTPUT = latex -LATEX_CMD_NAME = latex -MAKEINDEX_CMD_NAME = makeindex -COMPACT_LATEX = NO -PAPER_TYPE = a4 -EXTRA_PACKAGES = -LATEX_HEADER = -LATEX_FOOTER = -LATEX_EXTRA_STYLESHEET = -LATEX_EXTRA_FILES = -PDF_HYPERLINKS = YES -USE_PDFLATEX = YES -LATEX_BATCHMODE = NO -LATEX_HIDE_INDICES = NO -LATEX_SOURCE_CODE = NO -LATEX_BIB_STYLE = plain -LATEX_TIMESTAMP = NO - -#--------------------------------------------------------------------------- -# Configuration options related to the RTF output -#--------------------------------------------------------------------------- -GENERATE_RTF = NO -RTF_OUTPUT = rtf -COMPACT_RTF = NO -RTF_HYPERLINKS = NO -RTF_STYLESHEET_FILE = -RTF_EXTENSIONS_FILE = -RTF_SOURCE_CODE = NO - -#--------------------------------------------------------------------------- -# Configuration options related to the man page output -#--------------------------------------------------------------------------- -GENERATE_MAN = NO -MAN_OUTPUT = man -MAN_EXTENSION = .3 -MAN_SUBDIR = -MAN_LINKS = NO - -#--------------------------------------------------------------------------- -# Configuration options related to the XML output -#--------------------------------------------------------------------------- -GENERATE_XML = YES -XML_OUTPUT = temp/ -XML_PROGRAMLISTING = YES - -#--------------------------------------------------------------------------- -# Configuration options related to the DOCBOOK output -#--------------------------------------------------------------------------- -GENERATE_DOCBOOK = NO -DOCBOOK_OUTPUT = docbook -DOCBOOK_PROGRAMLISTING = NO - -#--------------------------------------------------------------------------- -# Configuration options for the AutoGen Definitions output -#--------------------------------------------------------------------------- -GENERATE_AUTOGEN_DEF = NO -GENERATE_PERLMOD = NO -PERLMOD_LATEX = NO -PERLMOD_PRETTY = YES -PERLMOD_MAKEVAR_PREFIX = - -#--------------------------------------------------------------------------- -# Configuration options related to the preprocessor -#--------------------------------------------------------------------------- -ENABLE_PREPROCESSING = YES -MACRO_EXPANSION = YES -EXPAND_ONLY_PREDEF = YES -SEARCH_INCLUDES = YES -INCLUDE_PATH = ../ -INCLUDE_FILE_PATTERNS = - -PREDEFINED = \ - BEAST_DOXYGEN \ - BEAST_USE_POSIX_FILE=1 \ - BEAST_USE_WIN32_FILE=1 - -EXPAND_AS_DEFINED = -SKIP_FUNCTION_MACROS = YES - -#--------------------------------------------------------------------------- -# Configuration options related to external references -#--------------------------------------------------------------------------- -TAGFILES = -GENERATE_TAGFILE = -ALLEXTERNALS = NO -EXTERNAL_GROUPS = YES -EXTERNAL_PAGES = YES -PERL_PATH = /usr/bin/perl - -#--------------------------------------------------------------------------- -# Configuration options related to the dot tool -#--------------------------------------------------------------------------- -CLASS_DIAGRAMS = NO -MSCGEN_PATH = -DIA_PATH = -HIDE_UNDOC_RELATIONS = YES -HAVE_DOT = NO -DOT_NUM_THREADS = 0 -DOT_FONTNAME = Helvetica -DOT_FONTSIZE = 10 -DOT_FONTPATH = -CLASS_GRAPH = YES -COLLABORATION_GRAPH = YES -GROUP_GRAPHS = YES -UML_LOOK = NO -UML_LIMIT_NUM_FIELDS = 10 -TEMPLATE_RELATIONS = NO -INCLUDE_GRAPH = YES -INCLUDED_BY_GRAPH = YES -CALL_GRAPH = NO -CALLER_GRAPH = NO -GRAPHICAL_HIERARCHY = YES -DIRECTORY_GRAPH = YES -DOT_IMAGE_FORMAT = png -INTERACTIVE_SVG = NO -DOT_PATH = -DOTFILE_DIRS = -MSCFILE_DIRS = -DIAFILE_DIRS = -PLANTUML_JAR_PATH = -PLANTUML_INCLUDE_PATH = -DOT_GRAPH_MAX_NODES = 50 -MAX_DOT_GRAPH_DEPTH = 0 -DOT_TRANSPARENT = NO -DOT_MULTI_TARGETS = NO -GENERATE_LEGEND = YES -DOT_CLEANUP = YES diff --git a/src/beast/doc/xsl/class_detail.xsl b/src/beast/doc/xsl/class_detail.xsl deleted file mode 100644 index 1120891e7fe..00000000000 --- a/src/beast/doc/xsl/class_detail.xsl +++ /dev/null @@ -1,51 +0,0 @@ - - - class ``[link beast.concept.streams.AsyncStream [*AsyncStream]]`` - - - class __AsyncReadStream__ - - - class __AsyncWriteStream__ - - - class ``[link beast.concept.Body [*Body]]`` - - - class ``[link beast.concept.BufferSequence [*BufferSequence]]`` - - - - ``[link beast.concept.BufferSequence [*BufferSequence]]`` - - - class __CompletionHandler__ - - - class __ConstBufferSequence__ - - - class ``[link beast.concept.DynamicBuffer [*DynamicBuffer]]`` - - - class ``[link beast.concept.Fields [*Fields]]`` - - - class __Handler__ - - - class __MutableBufferSequence__ - - - class ``[link beast.concept.streams.Stream [*Stream]]`` - - - class ``[link beast.concept.streams.SyncStream [*SyncStream]]`` - - - class __SyncReadStream__ - - - class __SyncWriteStream__ - - diff --git a/src/beast/doc/xsl/includes.xsl b/src/beast/doc/xsl/includes.xsl deleted file mode 100644 index 6f48e5fe5b5..00000000000 --- a/src/beast/doc/xsl/includes.xsl +++ /dev/null @@ -1,5 +0,0 @@ - - Defined in header [include_file - - ] - diff --git a/src/beast/doc/xsl/includes_foot.xsl b/src/beast/doc/xsl/includes_foot.xsl deleted file mode 100644 index ba723c06d8d..00000000000 --- a/src/beast/doc/xsl/includes_foot.xsl +++ /dev/null @@ -1,16 +0,0 @@ - - - - Convenience header [include_file beast/core.hpp] - - - Convenience header [include_file beast/http.hpp] - - - Convenience header [include_file beast/websocket.hpp] - - - Convenience header [include_file beast/zlib.hpp] - - - diff --git a/src/beast/doc/xsl/reference.xsl b/src/beast/doc/xsl/reference.xsl deleted file mode 100644 index 90a7c0e870b..00000000000 --- a/src/beast/doc/xsl/reference.xsl +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/src/beast/example/CMakeLists.txt b/src/beast/example/CMakeLists.txt deleted file mode 100644 index cfaad504ba2..00000000000 --- a/src/beast/example/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -# Part of Beast - -add_subdirectory (echo-op) -add_subdirectory (http-client) -add_subdirectory (http-crawl) -add_subdirectory (http-server-fast) -add_subdirectory (http-server-small) -add_subdirectory (http-server-threaded) -add_subdirectory (server-framework) -add_subdirectory (websocket-client) -add_subdirectory (websocket-server-async) - -if (OPENSSL_FOUND) - add_subdirectory (http-client-ssl) - add_subdirectory (websocket-client-ssl) -endif() diff --git a/src/beast/example/Jamfile b/src/beast/example/Jamfile deleted file mode 100644 index 61c87b8f463..00000000000 --- a/src/beast/example/Jamfile +++ /dev/null @@ -1,20 +0,0 @@ -# -# Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -# -# 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) -# - -build-project echo-op ; -build-project http-client ; -build-project http-crawl ; -build-project http-server-fast ; -build-project http-server-small ; -build-project http-server-threaded ; -build-project server-framework ; -build-project websocket-client ; -build-project websocket-server-async ; - -# VFALCO How do I make this work on Windows and if OpenSSL is not available? -#build-project ssl-http-client ; -#build-project ssl-websocket-client ; diff --git a/src/beast/example/common/detect_ssl.hpp b/src/beast/example/common/detect_ssl.hpp deleted file mode 100644 index 298a644baae..00000000000 --- a/src/beast/example/common/detect_ssl.hpp +++ /dev/null @@ -1,481 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_EXAMPLE_COMMON_DETECT_SSL_HPP -#define BEAST_EXAMPLE_COMMON_DETECT_SSL_HPP - -#include -#include - -//------------------------------------------------------------------------------ -// -// Example: Detect TLS/SSL -// -//------------------------------------------------------------------------------ - -//[example_core_detect_ssl_1 - -#include -#include - -/** Return `true` if a buffer contains a TLS/SSL client handshake. - - This function returns `true` if the beginning of the buffer - indicates that a TLS handshake is being negotiated, and that - there are at least four octets in the buffer. - - If the content of the buffer cannot possibly be a TLS handshake - request, the function returns `false`. Otherwise, if additional - octets are required, `boost::indeterminate` is returned. - - @param buffer The input buffer to inspect. This type must meet - the requirements of @b ConstBufferSequence. - - @return `boost::tribool` indicating whether the buffer contains - a TLS client handshake, does not contain a handshake, or needs - additional octets. - - @see - - http://www.ietf.org/rfc/rfc2246.txt - 7.4. Handshake protocol -*/ -template -boost::tribool -is_ssl_handshake(ConstBufferSequence const& buffers); - -//] - -using namespace beast; - -//[example_core_detect_ssl_2 - -template< - class ConstBufferSequence> -boost::tribool -is_ssl_handshake( - ConstBufferSequence const& buffers) -{ - // Make sure buffers meets the requirements - static_assert(is_const_buffer_sequence::value, - "ConstBufferSequence requirements not met"); - - // We need at least one byte to really do anything - if(boost::asio::buffer_size(buffers) < 1) - return boost::indeterminate; - - // Extract the first byte, which holds the - // "message" type for the Handshake protocol. - unsigned char v; - boost::asio::buffer_copy(boost::asio::buffer(&v, 1), buffers); - - // Check that the message type is "SSL Handshake" (rfc2246) - if(v != 0x16) - { - // This is definitely not a handshake - return false; - } - - // At least four bytes are needed for the handshake - // so make sure that we get them before returning `true` - if(boost::asio::buffer_size(buffers) < 4) - return boost::indeterminate; - - // This can only be a TLS/SSL handshake - return true; -} - -//] - -//[example_core_detect_ssl_3 - -/** Detect a TLS/SSL handshake on a stream. - - This function reads from a stream to determine if a TLS/SSL - handshake is being received. The function call will block - until one of the following conditions is true: - - @li The disposition of the handshake is determined - - @li An error occurs - - Octets read from the stream will be stored in the passed dynamic - buffer, which may be used to perform the TLS handshake if the - detector returns true, or otherwise consumed by the caller based - on the expected protocol. - - @param stream The stream to read from. This type must meet the - requirements of @b SyncReadStream. - - @param buffer The dynamic buffer to use. This type must meet the - requirements of @b DynamicBuffer. - - @param ec Set to the error if any occurred. - - @return `boost::tribool` indicating whether the buffer contains - a TLS client handshake, does not contain a handshake, or needs - additional octets. If an error occurs, the return value is - undefined. -*/ -template< - class SyncReadStream, - class DynamicBuffer> -boost::tribool -detect_ssl( - SyncReadStream& stream, - DynamicBuffer& buffer, - error_code& ec) -{ - // Make sure arguments meet the requirements - static_assert(is_sync_read_stream::value, - "SyncReadStream requirements not met"); - static_assert(is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - - // Loop until an error occurs or we get a definitive answer - for(;;) - { - // There could already be data in the buffer - // so we do this first, before reading from the stream. - auto const result = is_ssl_handshake(buffer.data()); - - // If we got an answer, return it - if(! boost::indeterminate(result)) - { - ec = {}; // indicate no error - return result; - } - - // The algorithm should never need more than 4 bytes - BOOST_ASSERT(buffer.size() < 4); - - // Create up to 4 bytes of space in the buffer's output area. - auto const mutable_buffer = buffer.prepare(4 - buffer.size()); - - // Try to fill our buffer by reading from the stream - std::size_t const bytes_transferred = stream.read_some(mutable_buffer, ec); - - // Check for an error - if(ec) - break; - - // Commit what we read into the buffer's input area. - buffer.commit(bytes_transferred); - } - - // error - return false; -} - -//] - -//[example_core_detect_ssl_4 - -/** Detect a TLS/SSL handshake asynchronously on a stream. - - This function is used to asynchronously determine if a TLS/SSL - handshake is being received. - The function call always returns immediately. The asynchronous - operation will continue until one of the following conditions - is true: - - @li The disposition of the handshake is determined - - @li An error occurs - - This operation is implemented in terms of zero or more calls to - the next layer's `async_read_some` function, and is known as a - composed operation. The program must ensure that the - stream performs no other operations until this operation completes. - - Octets read from the stream will be stored in the passed dynamic - buffer, which may be used to perform the TLS handshake if the - detector returns true, or otherwise consumed by the caller based - on the expected protocol. - - @param stream The stream to read from. This type must meet the - requirements of @b AsyncReadStream. - - @param buffer The dynamic buffer to use. This type must meet the - requirements of @b DynamicBuffer. - - @param handler The handler to be called when the request - completes. Copies will be made of the handler as required. - The equivalent function signature of the handler must be: - @code - void handler( - error_code const& error, // Set to the error, if any - boost::tribool result // The result of the detector - ); - @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. -*/ -template< - class AsyncReadStream, - class DynamicBuffer, - class CompletionToken> -async_return_type< /*< The [link beast.ref.beast__async_return_type `async_return_type`] customizes the return value based on the completion token >*/ - CompletionToken, - void(error_code, boost::tribool)> /*< This is the signature for the completion handler >*/ -async_detect_ssl( - AsyncReadStream& stream, - DynamicBuffer& buffer, - CompletionToken&& token); - -//] - -//[example_core_detect_ssl_5 - -// This is the composed operation. -template< - class AsyncReadStream, - class DynamicBuffer, - class Handler> -class detect_ssl_op; - -// Here is the implementation of the asynchronous initation function -template< - class AsyncReadStream, - class DynamicBuffer, - class CompletionToken> -async_return_type< - CompletionToken, - void(error_code, boost::tribool)> -async_detect_ssl( - AsyncReadStream& stream, - DynamicBuffer& buffer, - CompletionToken&& token) -{ - // Make sure arguments meet the requirements - static_assert(is_async_read_stream::value, - "SyncReadStream requirements not met"); - static_assert(is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - - // This helper manages some of the handler's lifetime and - // uses the result and handler specializations associated with - // the completion token to help customize the return value. - // - beast::async_completion< - CompletionToken, void(beast::error_code, boost::tribool)> init{token}; - - // Create the composed operation and launch it. This is a constructor - // call followed by invocation of operator(). We use handler_type - // to convert the completion token into the correct handler type, - // allowing user defined specializations of the async result template - // to take effect. - // - detect_ssl_op>{ - stream, buffer, init.completion_handler}( - beast::error_code{}, 0); - - // This hook lets the caller see a return value when appropriate. - // For example this might return std::future if - // CompletionToken is boost::asio::use_future. - // - // If a coroutine is used for the token, the return value from - // this function will be the `boost::tribool` representing the result. - // - return init.result.get(); -} - -//] - -//[example_core_detect_ssl_6 - -// Read from a stream to invoke is_tls_handshake asynchronously -// -template< - class AsyncReadStream, - class DynamicBuffer, - class Handler> -class detect_ssl_op -{ - // This composed operation has trivial state, - // so it is just kept inside the class and can - // be cheaply copied as needed by the implementation. - - // Indicates what step in the operation's state - // machine to perform next, starting from zero. - int step_ = 0; - - AsyncReadStream& stream_; - DynamicBuffer& buffer_; - Handler handler_; - boost::tribool result_ = false; - -public: - // Boost.Asio requires that handlers are CopyConstructible. - // The state for this operation is cheap to copy. - detect_ssl_op(detect_ssl_op const&) = default; - - // The constructor just keeps references the callers varaibles. - // - template - detect_ssl_op(AsyncReadStream& stream, - DynamicBuffer& buffer, DeducedHandler&& handler) - : stream_(stream) - , buffer_(buffer) - , handler_(std::forward(handler)) - { - } - - // Determines if the next asynchronous operation represents a - // continuation of the asynchronous flow of control associated - // with the final handler. If we are past step two, it means - // we have performed an asynchronous operation therefore any - // subsequent operation would represent a continuation. - // Otherwise, we propagate the handler's associated value of - // is_continuation. Getting this right means the implementation - // may schedule the invokation of the invoked functions more - // efficiently. - // - friend bool asio_handler_is_continuation(detect_ssl_op* op) - { - // This next call is structured to permit argument - // dependent lookup to take effect. - using boost::asio::asio_handler_is_continuation; - - // Always use std::addressof to pass the pointer to the handler, - // otherwise an unwanted overload of operator& may be called instead. - return op->step_ > 2 || - asio_handler_is_continuation(std::addressof(op->handler_)); - } - - // Handler hook forwarding. These free functions invoke the hooks - // associated with the final completion handler. In effect, they - // make the Asio implementation treat our composed operation the - // same way it would treat the final completion handler for the - // purpose of memory allocation and invocation. - // - // Our implementation just passes through the call to the hook - // associated with the final handler. - - friend void* asio_handler_allocate(std::size_t size, detect_ssl_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate(size, std::addressof(op->handler_)); - } - - friend void asio_handler_deallocate(void* p, std::size_t size, detect_ssl_op* op) - { - using boost::asio::asio_handler_deallocate; - return asio_handler_deallocate(p, size, std::addressof(op->handler_)); - } - - template - friend void asio_handler_invoke(Function&& f, detect_ssl_op* op) - { - using boost::asio::asio_handler_invoke; - return asio_handler_invoke(f, std::addressof(op->handler_)); - } - - // Our main entry point. This will get called as our - // intermediate operations complete. Definition below. - // - void operator()(beast::error_code ec, std::size_t bytes_transferred); -}; - -//] - -//[example_core_detect_ssl_7 - -// detect_ssl_op is callable with the signature -// void(error_code, bytes_transferred), -// allowing `*this` to be used as a ReadHandler -// -template< - class AsyncStream, - class DynamicBuffer, - class Handler> -void -detect_ssl_op:: -operator()(beast::error_code ec, std::size_t bytes_transferred) -{ - // Execute the state machine - switch(step_) - { - // Initial state - case 0: - // See if we can detect the handshake - result_ = is_ssl_handshake(buffer_.data()); - - // If there's a result, call the handler - if(! boost::indeterminate(result_)) - { - // We need to invoke the handler, but the guarantee - // is that the handler will not be called before the - // call to async_detect_ssl returns, so we must post - // the operation to the io_service. The helper function - // `bind_handler` lets us bind arguments in a safe way - // that preserves the type customization hooks of the - // original handler. - step_ = 1; - return stream_.get_io_service().post( - bind_handler(std::move(*this), ec, 0)); - } - - // The algorithm should never need more than 4 bytes - BOOST_ASSERT(buffer_.size() < 4); - - step_ = 2; - - do_read: - // We need more bytes, but no more than four total. - return stream_.async_read_some(buffer_.prepare(4 - buffer_.size()), std::move(*this)); - - case 1: - // Call the handler - break; - - case 2: - // Set this so that asio_handler_is_continuation knows that - // the next asynchronous operation represents a continuation - // of the initial asynchronous operation. - step_ = 3; - BOOST_FALLTHROUGH; - - case 3: - if(ec) - { - // Deliver the error to the handler - result_ = false; - - // We don't need bind_handler here because we were invoked - // as a result of an intermediate asynchronous operation. - break; - } - - // Commit the bytes that we read - buffer_.commit(bytes_transferred); - - // See if we can detect the handshake - result_ = is_ssl_handshake(buffer_.data()); - - // If it is detected, call the handler - if(! boost::indeterminate(result_)) - { - // We don't need bind_handler here because we were invoked - // as a result of an intermediate asynchronous operation. - break; - } - - // Read some more - goto do_read; - } - - // Invoke the final handler. - handler_(ec, result_); -} - -//] - -#endif diff --git a/src/beast/example/common/helpers.hpp b/src/beast/example/common/helpers.hpp deleted file mode 100644 index 784adc567e5..00000000000 --- a/src/beast/example/common/helpers.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_EXAMPLE_COMMON_HELPERS_HPP -#define BEAST_EXAMPLE_COMMON_HELPERS_HPP - -#include -#include -#include -#include - -/// Block until SIGINT or SIGTERM is received. -inline -void -sig_wait() -{ - boost::asio::io_service ios{1}; - boost::asio::signal_set signals(ios, SIGINT, SIGTERM); - signals.async_wait([&](boost::system::error_code const&, int){}); - ios.run(); -} - -namespace detail { - -inline -void -print_1(std::ostream&) -{ -} - -template -void -print_1(std::ostream& os, T1 const& t1, TN const&... tn) -{ - os << t1; - print_1(os, tn...); -} - -} // detail - -// compose a string to std::cout or std::cerr atomically -// -template -void -print(std::ostream& os, Args const&... args) -{ - std::stringstream ss; - detail::print_1(ss, args...); - os << ss.str() << std::endl; -} - -#endif diff --git a/src/beast/example/common/mime_types.hpp b/src/beast/example/common/mime_types.hpp deleted file mode 100644 index 65f646f983f..00000000000 --- a/src/beast/example/common/mime_types.hpp +++ /dev/null @@ -1,46 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_EXAMPLE_COMMON_MIME_TYPES_HPP -#define BEAST_EXAMPLE_COMMON_MIME_TYPES_HPP - -#include -#include - -// Return a reasonable mime type based on the extension of a file. -// -template -beast::string_view -mime_type(boost::filesystem::path const& path) -{ - using beast::iequals; - auto const ext = path.extension().string(); - if(iequals(ext, ".txt")) return "text/plain"; - if(iequals(ext, ".htm")) return "text/html"; - if(iequals(ext, ".html")) return "text/html"; - if(iequals(ext, ".php")) return "text/html"; - if(iequals(ext, ".css")) return "text/css"; - if(iequals(ext, ".js")) return "application/javascript"; - if(iequals(ext, ".json")) return "application/json"; - if(iequals(ext, ".xml")) return "application/xml"; - if(iequals(ext, ".swf")) return "application/x-shockwave-flash"; - if(iequals(ext, ".flv")) return "video/x-flv"; - if(iequals(ext, ".png")) return "image/png"; - if(iequals(ext, ".jpe")) return "image/jpeg"; - if(iequals(ext, ".jpeg")) return "image/jpeg"; - if(iequals(ext, ".jpg")) return "image/jpeg"; - if(iequals(ext, ".gif")) return "image/gif"; - if(iequals(ext, ".bmp")) return "image/bmp"; - if(iequals(ext, ".ico")) return "image/vnd.microsoft.icon"; - if(iequals(ext, ".tiff")) return "image/tiff"; - if(iequals(ext, ".tif")) return "image/tiff"; - if(iequals(ext, ".svg")) return "image/svg+xml"; - if(iequals(ext, ".svgz")) return "image/svg+xml"; - return "application/text"; -} - -#endif diff --git a/src/beast/example/common/rfc7231.hpp b/src/beast/example/common/rfc7231.hpp deleted file mode 100644 index 1ee20441267..00000000000 --- a/src/beast/example/common/rfc7231.hpp +++ /dev/null @@ -1,39 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_EXAMPLE_COMMON_RFC7231_HPP -#define BEAST_EXAMPLE_COMMON_RFC7231_HPP - -#include -#include - -namespace rfc7231 { - -// This aggregates a collection of algorithms -// corresponding to specifications in rfc7231: -// -// https://tools.ietf.org/html/rfc7231 -// - -/** Returns `true` if the message specifies Expect: 100-continue - - @param req The request to check - - @see https://tools.ietf.org/html/rfc7231#section-5.1.1 -*/ -template -bool -is_expect_100_continue(beast::http::request< - Body, beast::http::basic_fields> const& req) -{ - return beast::iequals( - req[beast::http::field::expect], "100-continue"); -} - -} // rfc7231 - -#endif diff --git a/src/beast/example/common/root_certificates.hpp b/src/beast/example/common/root_certificates.hpp deleted file mode 100644 index 7d935a56645..00000000000 --- a/src/beast/example/common/root_certificates.hpp +++ /dev/null @@ -1,118 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_EXAMPLE_COMMON_ROOT_CERTIFICATES_HPP -#define BEAST_EXAMPLE_COMMON_ROOT_CERTIFICATES_HPP - -#include -#include - -namespace ssl = boost::asio::ssl; // from - -namespace detail { - -// The template argument is gratuituous, to -// allow the implementation to be header-only. -// -template -void -load_root_certificates(ssl::context& ctx, boost::system::error_code& ec) -{ - std::string const cert = - /* This is the DigiCert root certificate. - - CN = DigiCert High Assurance EV Root CA - OU = www.digicert.com - O = DigiCert Inc - C = US - - Valid to: Sunday, ?November ?9, ?2031 5:00:00 PM - - Thumbprint(sha1): - 5f b7 ee 06 33 e2 59 db ad 0c 4c 9a e6 d3 8f 1a 61 c7 dc 25 - */ - "-----BEGIN CERTIFICATE-----\n" - "MIIDxTCCAq2gAwIBAgIQAqxcJmoLQJuPC3nyrkYldzANBgkqhkiG9w0BAQUFADBs\n" - "MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n" - "d3cuZGlnaWNlcnQuY29tMSswKQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFzc3VyYW5j\n" - "ZSBFViBSb290IENBMB4XDTA2MTExMDAwMDAwMFoXDTMxMTExMDAwMDAwMFowbDEL\n" - "MAkGA1UEBhMCVVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZMBcGA1UECxMQd3d3\n" - "LmRpZ2ljZXJ0LmNvbTErMCkGA1UEAxMiRGlnaUNlcnQgSGlnaCBBc3N1cmFuY2Ug\n" - "RVYgUm9vdCBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMbM5XPm\n" - "+9S75S0tMqbf5YE/yc0lSbZxKsPVlDRnogocsF9ppkCxxLeyj9CYpKlBWTrT3JTW\n" - "PNt0OKRKzE0lgvdKpVMSOO7zSW1xkX5jtqumX8OkhPhPYlG++MXs2ziS4wblCJEM\n" - "xChBVfvLWokVfnHoNb9Ncgk9vjo4UFt3MRuNs8ckRZqnrG0AFFoEt7oT61EKmEFB\n" - "Ik5lYYeBQVCmeVyJ3hlKV9Uu5l0cUyx+mM0aBhakaHPQNAQTXKFx01p8VdteZOE3\n" - "hzBWBOURtCmAEvF5OYiiAhF8J2a3iLd48soKqDirCmTCv2ZdlYTBoSUeh10aUAsg\n" - "EsxBu24LUTi4S8sCAwEAAaNjMGEwDgYDVR0PAQH/BAQDAgGGMA8GA1UdEwEB/wQF\n" - "MAMBAf8wHQYDVR0OBBYEFLE+w2kD+L9HAdSYJhoIAu9jZCvDMB8GA1UdIwQYMBaA\n" - "FLE+w2kD+L9HAdSYJhoIAu9jZCvDMA0GCSqGSIb3DQEBBQUAA4IBAQAcGgaX3Nec\n" - "nzyIZgYIVyHbIUf4KmeqvxgydkAQV8GK83rZEWWONfqe/EW1ntlMMUu4kehDLI6z\n" - "eM7b41N5cdblIZQB2lWHmiRk9opmzN6cN82oNLFpmyPInngiK3BD41VHMWEZ71jF\n" - "hS9OMPagMRYjyOfiZRYzy78aG6A9+MpeizGLYAiJLQwGXFK3xPkKmNEVX58Svnw2\n" - "Yzi9RKR/5CYrCsSXaQ3pjOLAEFe4yHYSkVXySGnYvCoCWw9E1CAx2/S6cCZdkGCe\n" - "vEsXCS+0yx5DaMkHJ8HSXPfqIbloEpw8nL+e/IBcm2PN7EeqJSdnoDfzAIJ9VNep\n" - "+OkuE6N36B9K\n" - "-----END CERTIFICATE-----\n" - /* This is the GeoTrust root certificate. - - CN = GeoTrust Global CA - O = GeoTrust Inc. - C = US - Valid to: Friday, ‎May ‎20, ‎2022 9:00:00 PM - - Thumbprint(sha1): - ‎de 28 f4 a4 ff e5 b9 2f a3 c5 03 d1 a3 49 a7 f9 96 2a 82 12 - */ - "-----BEGIN CERTIFICATE-----\n" - "MIIDxTCCAq2gAwIBAgIQAqxcJmoLQJuPC3nyrkYldzANBgkqhkiG9w0BAQUFADBs\n" - "MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n" - "d3cuZGlnaWNlcnQuY29tMSswKQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFzc3VyYW5j\n" - "ZSBFViBSb290IENBMB4XDTA2MTExMDAwMDAwMFoXDTMxMTExMDAwMDAwMFowbDEL\n" - "MAkGA1UEBhMCVVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZMBcGA1UECxMQd3d3\n" - "LmRpZ2ljZXJ0LmNvbTErMCkGA1UEAxMiRGlnaUNlcnQgSGlnaCBBc3N1cmFuY2Ug\n" - "RVYgUm9vdCBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMbM5XPm\n" - "+9S75S0tMqbf5YE/yc0lSbZxKsPVlDRnogocsF9ppkCxxLeyj9CYpKlBWTrT3JTW\n" - "PNt0OKRKzE0lgvdKpVMSOO7zSW1xkX5jtqumX8OkhPhPYlG++MXs2ziS4wblCJEM\n" - "xChBVfvLWokVfnHoNb9Ncgk9vjo4UFt3MRuNs8ckRZqnrG0AFFoEt7oT61EKmEFB\n" - "Ik5lYYeBQVCmeVyJ3hlKV9Uu5l0cUyx+mM0aBhakaHPQNAQTXKFx01p8VdteZOE3\n" - "hzBWBOURtCmAEvF5OYiiAhF8J2a3iLd48soKqDirCmTCv2ZdlYTBoSUeh10aUAsg\n" - "EsxBu24LUTi4S8sCAwEAAaNjMGEwDgYDVR0PAQH/BAQDAgGGMA8GA1UdEwEB/wQF\n" - "MAMBAf8wHQYDVR0OBBYEFLE+w2kD+L9HAdSYJhoIAu9jZCvDMB8GA1UdIwQYMBaA\n" - "FLE+w2kD+L9HAdSYJhoIAu9jZCvDMA0GCSqGSIb3DQEBBQUAA4IBAQAcGgaX3Nec\n" - "nzyIZgYIVyHbIUf4KmeqvxgydkAQV8GK83rZEWWONfqe/EW1ntlMMUu4kehDLI6z\n" - "eM7b41N5cdblIZQB2lWHmiRk9opmzN6cN82oNLFpmyPInngiK3BD41VHMWEZ71jF\n" - "hS9OMPagMRYjyOfiZRYzy78aG6A9+MpeizGLYAiJLQwGXFK3xPkKmNEVX58Svnw2\n" - "Yzi9RKR/5CYrCsSXaQ3pjOLAEFe4yHYSkVXySGnYvCoCWw9E1CAx2/S6cCZdkGCe\n" - "vEsXCS+0yx5DaMkHJ8HSXPfqIbloEpw8nL+e/IBcm2PN7EeqJSdnoDfzAIJ9VNep\n" - "+OkuE6N36B9K\n" - "-----END CERTIFICATE-----\n" - ; - - ctx.add_certificate_authority( - boost::asio::buffer(cert.data(), cert.size()), ec); - if(ec) - return; -} - -} // detail - -// Load the root certificates into an ssl::context -// -// This function is inline so that its easy to take -// the address and there's nothing weird like a -// gratuituous template argument; thus it appears -// like a "normal" function. -// -inline -void -load_root_certificates(ssl::context& ctx, boost::system::error_code& ec) -{ - detail::load_root_certificates(ctx, ec); -} - -#endif diff --git a/src/beast/example/common/ssl_stream.hpp b/src/beast/example/common/ssl_stream.hpp deleted file mode 100644 index 4238ecdeaec..00000000000 --- a/src/beast/example/common/ssl_stream.hpp +++ /dev/null @@ -1,334 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_EXAMPLE_COMMON_SSL_STREAM_HPP -#define BEAST_EXAMPLE_COMMON_SSL_STREAM_HPP - -// This include is necessary to work with `ssl::stream` and `beast::websocket::stream` -#include - -#include -#include -#include -#include -#include -#include - -/** C++11 enabled SSL socket wrapper - - This wrapper provides an interface identical to `boost::asio::ssl::stream`, - with the following additional properties: - - @li Satisfies @b MoveConstructible - - @li Satisfies @b MoveAssignable - - @li Constructible from a moved socket. -*/ -template -class ssl_stream - : public boost::asio::ssl::stream_base -{ - // only works for boost::asio::ip::tcp::socket - // for now because of the move limitations - static_assert(std::is_same::value, - "NextLayer requirements not met"); - - using stream_type = boost::asio::ssl::stream; - - std::unique_ptr p_; - boost::asio::ssl::context* ctx_; - -public: - /// The native handle type of the SSL stream. - using native_handle_type = typename stream_type::native_handle_type; - - /// Structure for use with deprecated impl_type. - using impl_struct = typename stream_type::impl_struct; - - /// (Deprecated: Use native_handle_type.) The underlying implementation type. - using impl_type = typename stream_type::impl_type; - - /// The type of the next layer. - using next_layer_type = typename stream_type::next_layer_type; - - /// The type of the lowest layer. - using lowest_layer_type = typename stream_type::lowest_layer_type; - - ssl_stream(boost::asio::ip::tcp::socket&& sock, boost::asio::ssl::context& ctx) - : p_(new stream_type{sock.get_io_service(), ctx}) - , ctx_(&ctx) - { - p_->next_layer() = std::move(sock); - } - - ssl_stream(ssl_stream&& other) - : p_(new stream_type(other.get_io_service(), *other.ctx_)) - , ctx_(other.ctx_) - { - using std::swap; - swap(p_, other.p_); - } - - ssl_stream& operator=(ssl_stream&& other) - { - std::unique_ptr p( - new stream_type{other.get_io_service(), other.ctx_}); - using std::swap; - swap(p_, p); - swap(p_, other.p_); - ctx_ = other.ctx_; - return *this; - } - - boost::asio::io_service& - get_io_service() - { - return p_->get_io_service(); - } - - native_handle_type - native_handle() - { - return p_->native_handle(); - } - - impl_type - impl() - { - return p_->impl(); - } - - next_layer_type const& - next_layer() const - { - return p_->next_layer(); - } - - next_layer_type& - next_layer() - { - return p_->next_layer(); - } - - lowest_layer_type& - lowest_layer() - { - return p_->lowest_layer(); - } - - lowest_layer_type const& - lowest_layer() const - { - return p_->lowest_layer(); - } - - void - set_verify_mode(boost::asio::ssl::verify_mode v) - { - p_->set_verify_mode(v); - } - - boost::system::error_code - set_verify_mode(boost::asio::ssl::verify_mode v, - boost::system::error_code& ec) - { - return p_->set_verify_mode(v, ec); - } - - void - set_verify_depth(int depth) - { - p_->set_verify_depth(depth); - } - - boost::system::error_code - set_verify_depth( - int depth, boost::system::error_code& ec) - { - return p_->set_verify_depth(depth, ec); - } - - template - void - set_verify_callback(VerifyCallback callback) - { - p_->set_verify_callback(callback); - } - - template - boost::system::error_code - set_verify_callback(VerifyCallback callback, - boost::system::error_code& ec) - { - return p_->set_verify_callback(callback, ec); - } - - void - handshake(handshake_type type) - { - p_->handshake(type); - } - - boost::system::error_code - handshake(handshake_type type, - boost::system::error_code& ec) - { - return p_->handshake(type, ec); - } - - template - void - handshake( - handshake_type type, ConstBufferSequence const& buffers) - { - p_->handshake(type, buffers); - } - - template - boost::system::error_code - handshake(handshake_type type, - ConstBufferSequence const& buffers, - boost::system::error_code& ec) - { - return p_->handshake(type, buffers, ec); - } - - template - BOOST_ASIO_INITFN_RESULT_TYPE(HandshakeHandler, - void(boost::system::error_code)) - async_handshake(handshake_type type, - BOOST_ASIO_MOVE_ARG(HandshakeHandler) handler) - { - return p_->async_handshake(type, - BOOST_ASIO_MOVE_CAST(HandshakeHandler)(handler)); - } - - template - BOOST_ASIO_INITFN_RESULT_TYPE(BufferedHandshakeHandler, - void (boost::system::error_code, std::size_t)) - async_handshake(handshake_type type, ConstBufferSequence const& buffers, - BOOST_ASIO_MOVE_ARG(BufferedHandshakeHandler) handler) - { - return p_->async_handshake(type, buffers, - BOOST_ASIO_MOVE_CAST(BufferedHandshakeHandler)(handler)); - } - - void - shutdown() - { - p_->shutdown(); - } - - boost::system::error_code - shutdown(boost::system::error_code& ec) - { - return p_->shutdown(ec); - } - - template - BOOST_ASIO_INITFN_RESULT_TYPE(ShutdownHandler, - void (boost::system::error_code)) - async_shutdown(BOOST_ASIO_MOVE_ARG(ShutdownHandler) handler) - { - return p_->async_shutdown( - BOOST_ASIO_MOVE_CAST(ShutdownHandler)(handler)); - } - - template - std::size_t - write_some(ConstBufferSequence const& buffers) - { - return p_->write_some(buffers); - } - - template - std::size_t - write_some(ConstBufferSequence const& buffers, - boost::system::error_code& ec) - { - return p_->write_some(buffers, ec); - } - - template - BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler, - void (boost::system::error_code, std::size_t)) - async_write_some(ConstBufferSequence const& buffers, - BOOST_ASIO_MOVE_ARG(WriteHandler) handler) - { - return p_->async_write_some(buffers, - BOOST_ASIO_MOVE_CAST(WriteHandler)(handler)); - } - - template - std::size_t - read_some(MutableBufferSequence const& buffers) - { - return p_->read_some(buffers); - } - - template - std::size_t - read_some(MutableBufferSequence const& buffers, - boost::system::error_code& ec) - { - return p_->read_some(buffers, ec); - } - - template - BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler, - void(boost::system::error_code, std::size_t)) - async_read_some(MutableBufferSequence const& buffers, - BOOST_ASIO_MOVE_ARG(ReadHandler) handler) - { - return p_->async_read_some(buffers, - BOOST_ASIO_MOVE_CAST(ReadHandler)(handler)); - } - - template - friend - void - teardown(beast::websocket::teardown_tag, - ssl_stream& stream, - boost::system::error_code& ec); - - template - friend - void - async_teardown(beast::websocket::teardown_tag, - ssl_stream& stream, TeardownHandler&& handler); -}; - -// These hooks are used to inform beast::websocket::stream on -// how to tear down the connection as part of the WebSocket -// protocol specifications - -template -inline -void -teardown(beast::websocket::teardown_tag, - ssl_stream& stream, - boost::system::error_code& ec) -{ - // Just forward it to the wrapped ssl::stream - using beast::websocket::teardown; - teardown(beast::websocket::teardown_tag{}, *stream.p_, ec); -} - -template -inline -void -async_teardown(beast::websocket::teardown_tag, - ssl_stream& stream, TeardownHandler&& handler) -{ - // Just forward it to the wrapped ssl::stream - using beast::websocket::async_teardown; - async_teardown(beast::websocket::teardown_tag{}, - *stream.p_, std::forward(handler)); -} - -#endif diff --git a/src/beast/example/common/write_msg.hpp b/src/beast/example/common/write_msg.hpp deleted file mode 100644 index 038df599f12..00000000000 --- a/src/beast/example/common/write_msg.hpp +++ /dev/null @@ -1,228 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_EXAMPLE_COMMON_WRITE_MSG_HPP -#define BEAST_EXAMPLE_COMMON_WRITE_MSG_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace detail { - -/** Composed operation to send an HTTP message - - This implements the composed operation needed for the - @ref async_write_msg function. -*/ -template< - class AsyncWriteStream, - class Handler, - bool isRequest, class Body, class Fields> -class write_msg_op -{ - // This composed operation has a state which is not trivial - // to copy (msg) so we need to store the state in an allocated - // object. - // - struct data - { - // The stream we are writing to - AsyncWriteStream& stream; - - // The message we are sending. Note that this composed - // operation takes ownership of the message and destroys - // it when it is done. - // - beast::http::message msg; - - // Serializer for the message - beast::http::serializer sr; - - data( - Handler& handler, - AsyncWriteStream& stream_, - beast::http::message&& msg_) - : stream(stream_) - , msg(std::move(msg_)) - , sr(msg) - { - boost::ignore_unused(handler); - } - }; - - // `handler_ptr` is a utility which helps to manage a composed - // operation's state. It is similar to a shared pointer, but - // it uses handler allocation hooks to allocate and free memory, - // and it also helps to meet Asio's deallocate-before-invocation - // guarantee. - // - beast::handler_ptr d_; - -public: - // Asio can move and copy the handler, we support both - write_msg_op(write_msg_op&&) = default; - write_msg_op(write_msg_op const&) = default; - - // Constructor - // - // We take the handler as a template type to - // support both const and rvalue references. - // - template< - class DeducedHandler, - class... Args> - write_msg_op( - DeducedHandler&& h, - AsyncWriteStream& s, - Args&&... args) - : d_(std::forward(h), - s, std::forward(args)...) - { - } - - // Entry point - // - // The initiation function calls this to start the operation - // - void - operator()() - { - auto& d = *d_; - beast::http::async_write( - d.stream, d.sr, std::move(*this)); - } - - // Completion handler - // - // This gets called when beast::http::async_write completes - // - void - operator()(beast::error_code ec) - { - d_.invoke(ec); - } - - // - // These hooks are necessary for Asio - // - // The meaning is explained in the Beast documentation - // - - friend - void* asio_handler_allocate( - std::size_t size, write_msg_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->d_.handler())); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, write_msg_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->d_.handler())); - } - - friend - bool asio_handler_is_continuation(write_msg_op* op) - { - using boost::asio::asio_handler_is_continuation; - return asio_handler_is_continuation(std::addressof(op->d_.handler())); - } - - template - friend - void asio_handler_invoke(Function&& f, write_msg_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->d_.handler())); - } -}; - -} // detail - -/** Write an HTTP message to a stream asynchronously - - This function is used to write a complete message to a stream asynchronously - using HTTP/1. The function call always returns immediately. The asynchronous - operation will continue until one of the following conditions is true: - - @li The entire message is written. - - @li An error occurs. - - This operation is implemented in terms of zero or more calls to the stream's - `async_write_some` function, and is known as a composed operation. - The program must ensure that the stream performs no other write operations - until this operation completes. The algorithm will use a temporary - @ref serializer with an empty chunk decorator to produce buffers. If - the semantics of the message indicate that the connection should be - closed after the message is sent, the error delivered by this function - will be @ref error::end_of_stream - - @param stream The stream to which the data is to be written. - The type must support the @b AsyncWriteStream concept. - - @param msg The message to write. The function will take ownership - of the object as if by move constrction. - - @param handler The handler to be called when the operation - completes. Copies will be made of the handler as required. - The equivalent function signature of the handler must be: - @code void handler( - error_code const& error // result of operation - ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. -*/ -template< - class AsyncWriteStream, - bool isRequest, class Body, class Fields, - class WriteHandler> -beast::async_return_type -async_write_msg( - AsyncWriteStream& stream, - beast::http::message&& msg, - WriteHandler&& handler) -{ - static_assert( - beast::is_async_write_stream::value, - "AsyncWriteStream requirements not met"); - - static_assert(beast::http::is_body::value, - "Body requirements not met"); - - static_assert(beast::http::is_body_reader::value, - "BodyReader requirements not met"); - - beast::async_completion init{handler}; - - ::detail::write_msg_op< - AsyncWriteStream, - beast::handler_type, - isRequest, Body, Fields>{ - init.completion_handler, - stream, - std::move(msg)}(); - - return init.result.get(); -} - -#endif diff --git a/src/beast/example/doc/http_examples.hpp b/src/beast/example/doc/http_examples.hpp deleted file mode 100644 index 7371e15daaf..00000000000 --- a/src/beast/example/doc/http_examples.hpp +++ /dev/null @@ -1,1060 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#include -#include - -/* This file contains the functions and classes found in the documentation - - They are compiled and run as part of the unit tests, so you can copy - the code and use it in your own projects as a starting point for - building a network application. -*/ - -// The documentation assumes the beast::http namespace -namespace beast { -namespace http { - -//------------------------------------------------------------------------------ -// -// Example: Expect 100-continue -// -//------------------------------------------------------------------------------ - -//[example_http_send_expect_100_continue - -/** Send a request with Expect: 100-continue - - This function will send a request with the Expect: 100-continue - field by first sending the header, then waiting for a successful - response from the server before continuing to send the body. If - a non-successful server response is received, the function - returns immediately. - - @param stream The remote HTTP server stream. - - @param buffer The buffer used for reading. - - @param req The request to send. This function modifies the object: - the Expect header field is inserted into the message if it does - not already exist, and set to "100-continue". - - @param ec Set to the error, if any occurred. -*/ -template< - class SyncStream, - class DynamicBuffer, - class Body, class Allocator> -void -send_expect_100_continue( - SyncStream& stream, - DynamicBuffer& buffer, - request>& req, - error_code& ec) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - - static_assert(is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - - // Insert or replace the Expect field - req.set(field::expect, "100-continue"); - - // Create the serializer - request_serializer> sr{req}; - - // Send just the header - write_header(stream, sr, ec); - if(ec) - return; - - // Read the response from the server. - // A robust client could set a timeout here. - { - response res; - read(stream, buffer, res, ec); - if(ec) - return; - if(res.result() != status::continue_) - { - // The server indicated that it will not - // accept the request, so skip sending the body. - return; - } - } - - // Server is OK with the request, send the body - write(stream, sr, ec); -} - -//] - -//[example_http_receive_expect_100_continue - -/** Receive a request, handling Expect: 100-continue if present. - - This function will read a request from the specified stream. - If the request contains the Expect: 100-continue field, a - status response will be delivered. - - @param stream The remote HTTP client stream. - - @param buffer The buffer used for reading. - - @param ec Set to the error, if any occurred. -*/ -template< - class SyncStream, - class DynamicBuffer> -void -receive_expect_100_continue( - SyncStream& stream, - DynamicBuffer& buffer, - error_code& ec) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - - static_assert(is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - - // Declare a parser for a request with a string body - request_parser parser; - - // Read the header - read_header(stream, buffer, parser, ec); - if(ec) - return; - - // Check for the Expect field value - if(parser.get()[field::expect] == "100-continue") - { - // send 100 response - response res; - res.version = 11; - res.result(status::continue_); - res.set(field::server, "test"); - write(stream, res, ec); - if(ec) - return; - } - - // Read the rest of the message. - // - // We use parser.base() to return a basic_parser&, to avoid an - // ambiguous function error (from boost::asio::read). Another - // solution is to qualify the call, e.g. `beast::http::read` - // - read(stream, buffer, parser.base(), ec); -} - -//] - -//------------------------------------------------------------------------------ -// -// Example: Send Child Process Output -// -//------------------------------------------------------------------------------ - -//[example_http_send_cgi_response - -/** Send the output of a child process as an HTTP response. - - The output of the child process comes from a @b SyncReadStream. Data - will be sent continuously as it is produced, without the requirement - that the entire process output is buffered before being sent. The - response will use the chunked transfer encoding. - - @param input A stream to read the child process output from. - - @param output A stream to write the HTTP response to. - - @param ec Set to the error, if any occurred. -*/ -template< - class SyncReadStream, - class SyncWriteStream> -void -send_cgi_response( - SyncReadStream& input, - SyncWriteStream& output, - error_code& ec) -{ - static_assert(is_sync_read_stream::value, - "SyncReadStream requirements not met"); - - static_assert(is_sync_write_stream::value, - "SyncWriteStream requirements not met"); - - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - - // Set up the response. We use the buffer_body type, - // allowing serialization to use manually provided buffers. - response res; - - res.result(status::ok); - res.version = 11; - res.set(field::server, "Beast"); - res.set(field::transfer_encoding, "chunked"); - - // No data yet, but we set more = true to indicate - // that it might be coming later. Otherwise the - // serializer::is_done would return true right after - // sending the header. - res.body.data = nullptr; - res.body.more = true; - - // Create the serializer. - response_serializer sr{res}; - - // Send the header immediately. - write_header(output, sr, ec); - if(ec) - return; - - // Alternate between reading from the child process - // and sending all the process output until there - // is no more output. - do - { - // Read a buffer from the child process - char buffer[2048]; - auto bytes_transferred = input.read_some( - boost::asio::buffer(buffer, sizeof(buffer)), ec); - if(ec == boost::asio::error::eof) - { - ec = {}; - - // `nullptr` indicates there is no buffer - res.body.data = nullptr; - - // `false` means no more data is coming - res.body.more = false; - } - else - { - if(ec) - return; - - // Point to our buffer with the bytes that - // we received, and indicate that there may - // be some more data coming - res.body.data = buffer; - res.body.size = bytes_transferred; - res.body.more = true; - } - - // Write everything in the body buffer - write(output, sr, ec); - - // This error is returned by body_buffer during - // serialization when it is done sending the data - // provided and needs another buffer. - if(ec == error::need_buffer) - { - ec = {}; - continue; - } - if(ec) - return; - } - while(! sr.is_done()); -} - -//] - -//-------------------------------------------------------------------------- -// -// Example: HEAD Request -// -//-------------------------------------------------------------------------- - -//[example_http_do_head_response - -/** Handle a HEAD request for a resource. -*/ -template< - class SyncStream, - class DynamicBuffer -> -void do_server_head( - SyncStream& stream, - DynamicBuffer& buffer, - error_code& ec) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - static_assert(is_dynamic_buffer::value, - "DynamicBuffer requirments not met"); - - // We deliver this payload for all GET requests - static std::string const payload = "Hello, world!"; - - // Read the request - request req; - read(stream, buffer, req, ec); - if(ec) - return; - - // Set up the response, starting with the common fields - response res; - res.version = 11; - res.set(field::server, "test"); - - // Now handle request-specific fields - switch(req.method()) - { - case verb::head: - case verb::get: - { - // A HEAD request is handled by delivering the same - // set of headers that would be sent for a GET request, - // including the Content-Length, except for the body. - res.result(status::ok); - res.set(field::content_length, payload.size()); - - // For GET requests, we include the body - if(req.method() == verb::get) - { - // We deliver the same payload for GET requests - // regardless of the target. A real server might - // deliver a file based on the target. - res.body = payload; - } - break; - } - - default: - { - // We return responses indicating an error if - // we do not recognize the request method. - res.result(status::bad_request); - res.set(field::content_type, "text/plain"); - res.body = "Invalid request-method '" + req.method_string().to_string() + "'"; - res.prepare_payload(); - break; - } - } - - // Send the response - write(stream, res, ec); - if(ec) - return; -} - -//] - -//[example_http_do_head_request - -/** Send a HEAD request for a resource. - - This function submits a HEAD request for the specified resource - and returns the response. - - @param res The response. This is an output parameter. - - @param stream The synchronous stream to use. - - @param buffer The buffer to use. - - @param target The request target. - - @param ec Set to the error, if any occurred. - - @throws std::invalid_argument if target is empty. -*/ -template< - class SyncStream, - class DynamicBuffer -> -response -do_head_request( - SyncStream& stream, - DynamicBuffer& buffer, - string_view target, - error_code& ec) -{ - // Do some type checking to be a good citizen - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - static_assert(is_dynamic_buffer::value, - "DynamicBuffer requirments not met"); - - // The interfaces we are using are low level and do not - // perform any checking of arguments; so we do it here. - if(target.empty()) - throw std::invalid_argument("target may not be empty"); - - // Build the HEAD request for the target - request req; - req.version = 11; - req.method(verb::head); - req.target(target); - req.set(field::user_agent, "test"); - - // A client MUST send a Host header field in all HTTP/1.1 request messages. - // https://tools.ietf.org/html/rfc7230#section-5.4 - req.set(field::host, "localhost"); - - // Now send it - write(stream, req, ec); - if(ec) - return {}; - - // Create a parser to read the response. - // Responses to HEAD requests MUST NOT include - // a body, so we use the `empty_body` type and - // only attempt to read the header. - parser p; - read_header(stream, buffer, p, ec); - if(ec) - return {}; - - // Transfer ownership of the response to the caller. - return p.release(); -} - -//] - -//------------------------------------------------------------------------------ -// -// Example: HTTP Relay -// -//------------------------------------------------------------------------------ - -//[example_http_relay - -/** Relay an HTTP message. - - This function efficiently relays an HTTP message from a downstream - client to an upstream server, or from an upstream server to a - downstream client. After the message header is read from the input, - a user provided transformation function is invoked which may change - the contents of the header before forwarding to the output. This may - be used to adjust fields such as Server, or proxy fields. - - @param output The stream to write to. - - @param input The stream to read from. - - @param buffer The buffer to use for the input. - - @param transform The header transformation to apply. The function will - be called with this signature: - @code - template - void transform(message< - isRequest, Body, Fields>&, // The message to transform - error_code&); // Set to the error, if any - @endcode - - @param ec Set to the error if any occurred. - - @tparam isRequest `true` to relay a request. - - @tparam Fields The type of fields to use for the message. -*/ -template< - bool isRequest, - class SyncWriteStream, - class SyncReadStream, - class DynamicBuffer, - class Transform> -void -relay( - SyncWriteStream& output, - SyncReadStream& input, - DynamicBuffer& buffer, - error_code& ec, - Transform&& transform) -{ - static_assert(is_sync_write_stream::value, - "SyncWriteStream requirements not met"); - - static_assert(is_sync_read_stream::value, - "SyncReadStream requirements not met"); - - // A small buffer for relaying the body piece by piece - char buf[2048]; - - // Create a parser with a buffer body to read from the input. - parser p; - - // Create a serializer from the message contained in the parser. - serializer sr{p.get()}; - - // Read just the header from the input - read_header(input, buffer, p, ec); - if(ec) - return; - - // Apply the caller's header tranformation - transform(p.get(), ec); - if(ec) - return; - - // Send the transformed message to the output - write_header(output, sr, ec); - if(ec) - return; - - // Loop over the input and transfer it to the output - do - { - if(! p.is_done()) - { - // Set up the body for writing into our small buffer - p.get().body.data = buf; - p.get().body.size = sizeof(buf); - - // Read as much as we can - read(input, buffer, p, ec); - - // This error is returned when buffer_body uses up the buffer - if(ec == error::need_buffer) - ec = {}; - if(ec) - return; - - // Set up the body for reading. - // This is how much was parsed: - p.get().body.size = sizeof(buf) - p.get().body.size; - p.get().body.data = buf; - p.get().body.more = ! p.is_done(); - } - else - { - p.get().body.data = nullptr; - p.get().body.size = 0; - } - - // Write everything in the buffer (which might be empty) - write(output, sr, ec); - - // This error is returned when buffer_body uses up the buffer - if(ec == error::need_buffer) - ec = {}; - if(ec) - return; - } - while(! p.is_done() && ! sr.is_done()); -} - -//] - -//------------------------------------------------------------------------------ -// -// Example: Serialize to std::ostream -// -//------------------------------------------------------------------------------ - -//[example_http_write_ostream - -// The detail namespace means "not public" -namespace detail { - -// This helper is needed for C++11. -// When invoked with a buffer sequence, writes the buffers `to the std::ostream`. -template -class write_ostream_helper -{ - Serializer& sr_; - std::ostream& os_; - -public: - write_ostream_helper(Serializer& sr, std::ostream& os) - : sr_(sr) - , os_(os) - { - } - - // This function is called by the serializer - template - void - operator()(error_code& ec, ConstBufferSequence const& buffers) const - { - // These asio functions are needed to access a buffer's contents - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - - // Error codes must be cleared on success - ec = {}; - - // Keep a running total of how much we wrote - std::size_t bytes_transferred = 0; - - // Loop over the buffer sequence - for(auto it = buffers.begin(); it != buffers.end(); ++ it) - { - // This is the next buffer in the sequence - boost::asio::const_buffer const buffer = *it; - - // Write it to the std::ostream - os_.write( - buffer_cast(buffer), - buffer_size(buffer)); - - // If the std::ostream fails, convert it to an error code - if(os_.fail()) - { - ec = make_error_code(errc::io_error); - return; - } - - // Adjust our running total - bytes_transferred += buffer_size(buffer); - } - - // Inform the serializer of the amount we consumed - sr_.consume(bytes_transferred); - } -}; - -} // detail - -/** Write a message to a `std::ostream`. - - This function writes the serialized representation of the - HTTP/1 message to the sream. - - @param os The `std::ostream` to write to. - - @param msg The message to serialize. - - @param ec Set to the error, if any occurred. -*/ -template< - bool isRequest, - class Body, - class Fields> -void -write_ostream( - std::ostream& os, - message& msg, - error_code& ec) -{ - // Create the serializer instance - serializer sr{msg}; - - // This lambda is used as the "visit" function - detail::write_ostream_helper lambda{sr, os}; - do - { - // In C++14 we could use a generic lambda but since we want - // to require only C++11, the lambda is written out by hand. - // This function call retrieves the next serialized buffers. - sr.next(ec, lambda); - if(ec) - return; - } - while(! sr.is_done()); -} - -//] - -//------------------------------------------------------------------------------ -// -// Example: Parse from std::istream -// -//------------------------------------------------------------------------------ - -//[example_http_read_istream - -/** Read a message from a `std::istream`. - - This function attempts to parse a complete HTTP/1 message from the stream. - - @param is The `std::istream` to read from. - - @param buffer The buffer to use. - - @param msg The message to store the result. - - @param ec Set to the error, if any occurred. -*/ -template< - class Allocator, - bool isRequest, - class Body> -void -read_istream( - std::istream& is, - basic_flat_buffer& buffer, - message& msg, - error_code& ec) -{ - // Create the message parser - // - // Arguments passed to the parser's constructor are - // forwarded to the message constructor. Here, we use - // a move construction in case the caller has constructed - // their message in a non-default way. - // - parser p{std::move(msg)}; - - do - { - // Extract whatever characters are presently available in the istream - if(is.rdbuf()->in_avail() > 0) - { - // Get a mutable buffer sequence for writing - auto const mb = buffer.prepare( - static_cast(is.rdbuf()->in_avail())); - - // Now get everything we can from the istream - buffer.commit(static_cast(is.readsome( - boost::asio::buffer_cast(mb), - boost::asio::buffer_size(mb)))); - } - else if(buffer.size() == 0) - { - // Our buffer is empty and we need more characters, - // see if we've reached the end of file on the istream - if(! is.eof()) - { - // Get a mutable buffer sequence for writing - auto const mb = buffer.prepare(1024); - - // Try to get more from the istream. This might block. - is.read( - boost::asio::buffer_cast(mb), - boost::asio::buffer_size(mb)); - - // If an error occurs on the istream then return it to the caller. - if(is.fail() && ! is.eof()) - { - // We'll just re-use io_error since std::istream has no error_code interface. - ec = make_error_code(errc::io_error); - return; - } - - // Commit the characters we got to the buffer. - buffer.commit(static_cast(is.gcount())); - } - else - { - // Inform the parser that we've reached the end of the istream. - p.put_eof(ec); - if(ec) - return; - break; - } - } - - // Write the data to the parser - auto const bytes_used = p.put(buffer.data(), ec); - - // This error means that the parser needs additional octets. - if(ec == error::need_more) - ec = {}; - if(ec) - return; - - // Consume the buffer octets that were actually parsed. - buffer.consume(bytes_used); - } - while(! p.is_done()); - - // Transfer ownership of the message container in the parser to the caller. - msg = p.release(); -} - -//] - -//------------------------------------------------------------------------------ -// -// Example: Deferred Body Type -// -//------------------------------------------------------------------------------ - -//[example_http_defer_body - -/** Handle a form PUT request, choosing a body type depending on the Content-Type. - - This reads a request from the input stream. If the method is POST, and - the Content-Type is "application/x-www-form-urlencoded " or - "multipart/form-data", a `string_body` is used to receive and store - the message body. Otherwise, a `dynamic_body` is used to store the message - body. After the request is received, the handler will be invoked with the - request. - - @param stream The stream to read from. - - @param buffer The buffer to use for reading. - - @param handler The handler to invoke when the request is complete. - The handler must be invokable with this signature: - @code - template - void handler(request&& req); - @endcode - - @throws system_error Thrown on failure. -*/ -template< - class SyncReadStream, - class DynamicBuffer, - class Handler> -void -do_form_request( - SyncReadStream& stream, - DynamicBuffer& buffer, - Handler&& handler) -{ - // Start with an empty_body parser - request_parser req0; - - // Read just the header. Otherwise, the empty_body - // would generate an error if body octets were received. - read_header(stream, buffer, req0); - - // Choose a body depending on the method verb - switch(req0.get().method()) - { - case verb::post: - { - // If this is not a form upload then use a string_body - if( req0.get()[field::content_type] != "application/x-www-form-urlencoded" && - req0.get()[field::content_type] != "multipart/form-data") - goto do_string_body; - - // Commit to string_body as the body type. - // As long as there are no body octets in the parser - // we are constructing from, no exception is thrown. - request_parser req{std::move(req0)}; - - // Finish reading the message - read(stream, buffer, req); - - // Call the handler. It can take ownership - // if desired, since we are calling release() - handler(req.release()); - break; - } - - do_string_body: - default: - { - // Commit to dynamic_body as the body type. - // As long as there are no body octets in the parser - // we are constructing from, no exception is thrown. - request_parser req{std::move(req0)}; - - // Finish reading the message - read(stream, buffer, req); - - // Call the handler. It can take ownership - // if desired, since we are calling release() - handler(req.release()); - break; - } - } -} - -//] - - - -//------------------------------------------------------------------------------ -// -// Example: Custom Parser -// -//------------------------------------------------------------------------------ - -//[example_http_custom_parser - -template -class custom_parser - : public basic_parser> -{ - // The friend declaration is needed, - // otherwise the callbacks must be made public. - friend class basic_parser; - - /// Called after receiving the request-line (isRequest == true). - void - on_request( - verb method, // The method verb, verb::unknown if no match - string_view method_str, // The method as a string - string_view target, // The request-target - int version, // The HTTP-version - error_code& ec); // The error returned to the caller, if any - - /// Called after receiving the start-line (isRequest == false). - void - on_response( - int code, // The status-code - string_view reason, // The obsolete reason-phrase - int version, // The HTTP-version - error_code& ec); // The error returned to the caller, if any - - /// Called after receiving a header field. - void - on_field( - field f, // The known-field enumeration constant - string_view name, // The field name string. - string_view value, // The field value - error_code& ec); // The error returned to the caller, if any - - /// Called after the complete header is received. - void - on_header( - error_code& ec); // The error returned to the caller, if any - - /// Called just before processing the body, if a body exists. - void - on_body(boost::optional< - std::uint64_t> const& - content_length, // Content length if known, else `boost::none` - error_code& ec); // The error returned to the caller, if any - - /** Called for each piece of the body, if a body exists. - - If present, the chunked Transfer-Encoding will be removed - before this callback is invoked. The function returns - the number of bytes consumed from the input buffer. - Any input octets not consumed will be will be presented - on subsequent calls. - */ - std::size_t - on_data( - string_view s, // A portion of the body - error_code& ec); // The error returned to the caller, if any - - /// Called for each chunk header. - void - on_chunk( - std::uint64_t size, // The size of the upcoming chunk - string_view extension, // The chunk-extension (may be empty) - error_code& ec); // The error returned to the caller, if any - - /// Called when the complete message is parsed. - void - on_complete(error_code& ec); - -public: - custom_parser() = default; -}; - -//] - -// Definitions are not part of the docs but necessary to link - -template -void custom_parser:: -on_request(verb method, string_view method_str, - string_view path, int version, error_code& ec) -{ - boost::ignore_unused(method, method_str, path, version); - ec = {}; -} - -template -void custom_parser:: -on_response(int status, string_view reason, - int version, error_code& ec) -{ - boost::ignore_unused(status, reason, version); - ec = {}; -} - -template -void custom_parser:: -on_field(field f, string_view name, - string_view value, error_code& ec) -{ - boost::ignore_unused(f, name, value); - ec = {}; -} - -template -void custom_parser:: -on_header(error_code& ec) -{ - ec = {}; -} - -template -void custom_parser:: -on_body(boost::optional const& content_length, - error_code& ec) -{ - boost::ignore_unused(content_length); - ec = {}; -} - -template -std::size_t custom_parser:: -on_data(string_view s, error_code& ec) -{ - boost::ignore_unused(s); - ec = {}; - return s.size(); -} - -template -void custom_parser:: -on_chunk(std::uint64_t size, - string_view extension, error_code& ec) -{ - boost::ignore_unused(size, extension); - ec = {}; -} - -template -void custom_parser:: -on_complete(error_code& ec) -{ - ec = {}; -} - -//------------------------------------------------------------------------------ -// -// Example: Incremental Read -// -//------------------------------------------------------------------------------ - -//[example_incremental_read - -/* This function reads a message using a fixed size buffer to hold - portions of the body, and prints the body contents to a `std::ostream`. -*/ -template< - bool isRequest, - class SyncReadStream, - class DynamicBuffer> -void -read_and_print_body( - std::ostream& os, - SyncReadStream& stream, - DynamicBuffer& buffer, - error_code& ec) -{ - parser p; - read_header(stream, buffer, p, ec); - if(ec) - return; - while(! p.is_done()) - { - char buf[512]; - p.get().body.data = buf; - p.get().body.size = sizeof(buf); - read(stream, buffer, p, ec); - if(ec == error::need_buffer) - ec.assign(0, ec.category()); - if(ec) - return; - os.write(buf, sizeof(buf) - p.get().body.size); - } -} - -//] - -} // http -} // beast diff --git a/src/beast/example/echo-op/CMakeLists.txt b/src/beast/example/echo-op/CMakeLists.txt deleted file mode 100644 index d6af84394c9..00000000000 --- a/src/beast/example/echo-op/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -# Part of Beast - -GroupSources(include/beast beast) - -GroupSources(example/echo-op "/") - -add_executable (echo-op - ${BEAST_INCLUDES} - echo_op.cpp -) - -target_link_libraries(echo-op Beast) diff --git a/src/beast/example/echo-op/Jamfile b/src/beast/example/echo-op/Jamfile deleted file mode 100644 index cfc32495a85..00000000000 --- a/src/beast/example/echo-op/Jamfile +++ /dev/null @@ -1,13 +0,0 @@ -# -# Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -# -# 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) -# - -exe echo-op : - echo_op.cpp - : - coverage:no - ubasan:no - ; diff --git a/src/beast/example/echo-op/echo_op.cpp b/src/beast/example/echo-op/echo_op.cpp deleted file mode 100644 index 150c76fc480..00000000000 --- a/src/beast/example/echo-op/echo_op.cpp +++ /dev/null @@ -1,356 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#include -#include -#include -#include -#include -#include - -//[example_core_echo_op_1 - -template< - class AsyncStream, - class CompletionToken> -auto -async_echo(AsyncStream& stream, CompletionToken&& token) - -//] - -> beast::async_return_type; - -//[example_core_echo_op_2 - -/** Asynchronously read a line and echo it back. - - This function is used to asynchronously read a line ending - in a carriage-return ("CR") from the stream, and then write - it back. The function call always returns immediately. The - asynchronous operation will continue until one of the - following conditions is true: - - @li A line was read in and sent back on the stream - - @li An error occurs. - - This operation is implemented in terms of one or more calls to - the stream's `async_read_some` and `async_write_some` functions, - and is known as a composed operation. The program must - ensure that the stream performs no other operations until this - operation completes. The implementation may read additional octets - that lie past the end of the line being read. These octets are - silently discarded. - - @param The stream to operate on. The type must meet the - requirements of @b AsyncReadStream and @AsyncWriteStream - - @param token The completion token to use. If this is a - completion handler, copies will be made as required. - The equivalent signature of the handler must be: - @code - void handler( - error_code ec // result of operation - ); - @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. -*/ -template< - class AsyncStream, - class CompletionToken> -beast::async_return_type< /*< The [link beast.ref.beast__async_return_type `async_return_type`] customizes the return value based on the completion token >*/ - CompletionToken, - void(beast::error_code)> /*< This is the signature for the completion handler >*/ -async_echo( - AsyncStream& stream, - CompletionToken&& token); - -//] - -//[example_core_echo_op_4 - -// This composed operation reads a line of input and echoes it back. -// -template -class echo_op -{ - // This holds all of the state information required by the operation. - struct state - { - // The stream to read and write to - AsyncStream& stream; - - // Indicates what step in the operation's state machine - // to perform next, starting from zero. - int step = 0; - - // The buffer used to hold the input and output data. - // - // We use a custom allocator for performance, this allows - // the implementation of the io_service to make efficient - // re-use of memory allocated by composed operations during - // a continuation. - // - boost::asio::basic_streambuf> buffer; - - // handler_ptr requires that the first parameter to the - // contained object constructor is a reference to the - // managed final completion handler. - // - explicit state(Handler& handler, AsyncStream& stream_) - : stream(stream_) - , buffer((std::numeric_limits::max)(), - beast::handler_alloc{handler}) - { - } - }; - - // The operation's data is kept in a cheap-to-copy smart - // pointer container called `handler_ptr`. This efficiently - // satisfies the CopyConstructible requirements of completion - // handlers. - // - // `handler_ptr` uses these memory allocation hooks associated - // with the final completion handler, in order to allocate the - // storage for `state`: - // - // asio_handler_allocate - // asio_handler_deallocate - // - beast::handler_ptr p_; - -public: - // Boost.Asio requires that handlers are CopyConstructible. - // In some cases, it takes advantage of handlers that are - // MoveConstructible. This operation supports both. - // - echo_op(echo_op&&) = default; - echo_op(echo_op const&) = default; - - // The constructor simply creates our state variables in - // the smart pointer container. - // - template - echo_op(AsyncStream& stream, DeducedHandler&& handler) - : p_(std::forward(handler), stream) - { - } - - // The entry point for this handler. This will get called - // as our intermediate operations complete. Definition below. - // - void operator()(beast::error_code ec, std::size_t bytes_transferred); - - // The next four functions are required for our class - // to meet the requirements for composed operations. - // Definitions and exposition will follow. - - template - friend void asio_handler_invoke( - Function&& f, echo_op* op); - - template - friend void* asio_handler_allocate( - std::size_t size, echo_op* op); - - template - friend void asio_handler_deallocate( - void* p, std::size_t size, echo_op* op); - - template - friend bool asio_handler_is_continuation( - echo_op* op); -}; - -//] - -//[example_core_echo_op_5 - -// echo_op is callable with the signature void(error_code, bytes_transferred), -// allowing `*this` to be used as both a ReadHandler and a WriteHandler. -// -template -void echo_op:: -operator()(beast::error_code ec, std::size_t bytes_transferred) -{ - // Store a reference to our state. The address of the state won't - // change, and this solves the problem where dereferencing the - // data member is undefined after a move. - auto& p = *p_; - - // Now perform the next step in the state machine - switch(ec ? 2 : p.step) - { - // initial entry - case 0: - // read up to the first newline - p.step = 1; - return boost::asio::async_read_until(p.stream, p.buffer, "\r", std::move(*this)); - - case 1: - // write everything back - p.step = 2; - // async_read_until could have read past the newline, - // use buffer_prefix to make sure we only send one line - return boost::asio::async_write(p.stream, - beast::buffer_prefix(bytes_transferred, p.buffer.data()), std::move(*this)); - - case 2: - p.buffer.consume(bytes_transferred); - break; - } - - // Invoke the final handler. The implementation of `handler_ptr` - // will deallocate the storage for the state before the handler - // is invoked. This is necessary to provide the - // destroy-before-invocation guarantee on handler memory - // customizations. - // - // If we wanted to pass any arguments to the handler which come - // from the `state`, they would have to be moved to the stack - // first or else undefined behavior results. - // - p_.invoke(ec); - return; -} - -//] - -//[example_core_echo_op_6 - -// Handler hook forwarding. These free functions invoke the hooks -// associated with the final completion handler. In effect, they -// make the Asio implementation treat our composed operation the -// same way it would treat the final completion handler for the -// purpose of memory allocation and invocation. -// -// Our implementation just passes the call through to the hook -// associated with the final handler. The "using" statements are -// structured to permit argument dependent lookup. Always use -// `std::addressof` or its equivalent to pass the pointer to the -// handler, otherwise an unwanted overload of `operator&` may be -// called instead. - -template -void asio_handler_invoke( - Function&& f, echo_op* op) -{ - using boost::asio::asio_handler_invoke; - return asio_handler_invoke(f, std::addressof(op->p_.handler())); -} - -template -void* asio_handler_allocate( - std::size_t size, echo_op* op) -{ - using boost::asio::asio_handler_allocate; - return asio_handler_allocate(size, std::addressof(op->p_.handler())); -} - -template -void asio_handler_deallocate( - void* p, std::size_t size, echo_op* op) -{ - using boost::asio::asio_handler_deallocate; - return asio_handler_deallocate(p, size, - std::addressof(op->p_.handler())); -} - -// Determines if the next asynchronous operation represents a -// continuation of the asynchronous flow of control associated -// with the final handler. If we are past step one, it means -// we have performed an asynchronous operation therefore any -// subsequent operation would represent a continuation. -// Otherwise, we propagate the handler's associated value of -// is_continuation. Getting this right means the implementation -// may schedule the invokation of the invoked functions more -// efficiently. -// -template -bool asio_handler_is_continuation(echo_op* op) -{ - // This next call is structured to permit argument - // dependent lookup to take effect. - using boost::asio::asio_handler_is_continuation; - - // Always use std::addressof to pass the pointer to the handler, - // otherwise an unwanted overload of operator& may be called instead. - return op->p_->step > 1 || - asio_handler_is_continuation(std::addressof(op->p_.handler())); -} - -//] - -//[example_core_echo_op_3 - -template -class echo_op; - -// Read a line and echo it back -// -template -beast::async_return_type -async_echo(AsyncStream& stream, CompletionToken&& token) -{ - // Make sure stream meets the requirements. We use static_assert - // to cause a friendly message instead of an error novel. - // - static_assert(beast::is_async_stream::value, - "AsyncStream requirements not met"); - - // This helper manages some of the handler's lifetime and - // uses the result and handler specializations associated with - // the completion token to help customize the return value. - // - beast::async_completion init{token}; - - // Create the composed operation and launch it. This is a constructor - // call followed by invocation of operator(). We use handler_type - // to convert the completion token into the correct handler type, - // allowing user-defined specializations of the async_result template - // to be used. - // - echo_op>{ - stream, init.completion_handler}(beast::error_code{}, 0); - - // This hook lets the caller see a return value when appropriate. - // For example this might return std::future if - // CompletionToken is boost::asio::use_future, or this might - // return an error code if CompletionToken specifies a coroutine. - // - return init.result.get(); -} - -//] - -int main(int, char** argv) -{ - using address_type = boost::asio::ip::address; - using socket_type = boost::asio::ip::tcp::socket; - using endpoint_type = boost::asio::ip::tcp::endpoint; - - // Create a listening socket, accept a connection, perform - // the echo, and then shut everything down and exit. - boost::asio::io_service ios; - socket_type sock{ios}; - boost::asio::ip::tcp::acceptor acceptor{ios}; - endpoint_type ep{address_type::from_string("0.0.0.0"), 0}; - acceptor.open(ep.protocol()); - acceptor.bind(ep); - acceptor.listen(); - acceptor.accept(sock); - async_echo(sock, - [&](beast::error_code ec) - { - if(ec) - std::cerr << argv[0] << ": " << ec.message() << std::endl; - }); - ios.run(); - return 0; -} diff --git a/src/beast/example/http-client-ssl/CMakeLists.txt b/src/beast/example/http-client-ssl/CMakeLists.txt deleted file mode 100644 index 3abb8b8d5cc..00000000000 --- a/src/beast/example/http-client-ssl/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -# Part of Beast - -GroupSources(include/beast beast) -GroupSources(example/common common) -GroupSources(example/http-client-ssl "/") - -add_executable (http-client-ssl - ${BEAST_INCLUDES} - ${COMMON_INCLUDES} - http_client_ssl.cpp -) - -target_link_libraries(http-client-ssl - Beast - ${OPENSSL_LIBRARIES} - ) diff --git a/src/beast/example/http-client-ssl/Jamfile b/src/beast/example/http-client-ssl/Jamfile deleted file mode 100644 index d322b946a6c..00000000000 --- a/src/beast/example/http-client-ssl/Jamfile +++ /dev/null @@ -1,51 +0,0 @@ -# -# Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -# -# 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) -# - -import os ; - -if [ os.name ] = SOLARIS -{ - lib socket ; - lib nsl ; -} -else if [ os.name ] = NT -{ - lib ws2_32 ; - lib mswsock ; -} -else if [ os.name ] = HPUX -{ - lib ipv6 ; -} -else if [ os.name ] = HAIKU -{ - lib network ; -} - -if [ os.name ] = NT -{ - lib ssl : : ssleay32 ; - lib crypto : : libeay32 ; -} -else -{ - lib ssl ; - lib crypto ; -} - -project - : requirements - ssl - crypto - ; - -exe http-client-ssl : - http_client_ssl.cpp - : - coverage:no - ubasan:no - ; diff --git a/src/beast/example/http-client-ssl/http_client_ssl.cpp b/src/beast/example/http-client-ssl/http_client_ssl.cpp deleted file mode 100644 index 046b21fcf79..00000000000 --- a/src/beast/example/http-client-ssl/http_client_ssl.cpp +++ /dev/null @@ -1,104 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#include "../common/root_certificates.hpp" - -#include -#include -#include -#include -#include -#include -#include - -using tcp = boost::asio::ip::tcp; // from -namespace ssl = boost::asio::ssl; // from -namespace http = beast::http; // from - -int main() -{ - // A helper for reporting errors - auto const fail = - [](std::string what, beast::error_code ec) - { - std::cerr << what << ": " << ec.message() << std::endl; - std::cerr.flush(); - return EXIT_FAILURE; - }; - - boost::system::error_code ec; - - // Normal boost::asio setup - boost::asio::io_service ios; - tcp::resolver r{ios}; - tcp::socket sock{ios}; - - // Look up the domain name - std::string const host = "www.example.com"; - auto const lookup = r.resolve({host, "https"}, ec); - if(ec) - return fail("resolve", ec); - - // Make the connection on the IP address we get from a lookup - boost::asio::connect(sock, lookup, ec); - if(ec) - return fail("connect", ec); - - // Create the required ssl context - ssl::context ctx{ssl::context::sslv23_client}; - - // This holds the root certificate used for verification - load_root_certificates(ctx, ec); - if(ec) - return fail("certificate", ec); - - // Wrap the now-connected socket in an SSL stream - ssl::stream stream{sock, ctx}; - stream.set_verify_mode(ssl::verify_peer | ssl::verify_fail_if_no_peer_cert); - - // Perform SSL handshaking - stream.handshake(ssl::stream_base::client, ec); - if(ec) - return fail("handshake", ec); - - // Set up an HTTP GET request message - http::request req; - req.method(http::verb::get); - req.target("/"); - req.version = 11; - req.set(http::field::host, host + ":" + - std::to_string(sock.remote_endpoint().port())); - req.set(http::field::user_agent, BEAST_VERSION_STRING); - req.prepare_payload(); - - // Write the HTTP request to the remote host - http::write(stream, req, ec); - if(ec) - return fail("write", ec); - - // This buffer is used for reading and must be persisted - beast::flat_buffer b; - - // Declare a container to hold the response - http::response res; - - // Read the response - http::read(stream, b, res, ec); - if(ec) - return fail("read", ec); - - // Write the message to standard out - std::cout << res << std::endl; - - // Shut down SSL on the stream - stream.shutdown(ec); - if(ec && ec != boost::asio::error::eof) - fail("ssl_shutdown ", ec); - - // If we get here then the connection is closed gracefully - return EXIT_SUCCESS; -} diff --git a/src/beast/example/http-client/CMakeLists.txt b/src/beast/example/http-client/CMakeLists.txt deleted file mode 100644 index 59044b4744f..00000000000 --- a/src/beast/example/http-client/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -# Part of Beast - -GroupSources(include/beast beast) - -GroupSources(example/http-client "/") - -add_executable (http-client - ${BEAST_INCLUDES} - ${EXTRAS_INCLUDES} - http_client.cpp -) - -target_link_libraries(http-client Beast) diff --git a/src/beast/example/http-client/Jamfile b/src/beast/example/http-client/Jamfile deleted file mode 100644 index a39360eaed0..00000000000 --- a/src/beast/example/http-client/Jamfile +++ /dev/null @@ -1,13 +0,0 @@ -# -# Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -# -# 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) -# - -exe http-client : - http_client.cpp - : - coverage:no - ubasan:no - ; diff --git a/src/beast/example/http-client/http_client.cpp b/src/beast/example/http-client/http_client.cpp deleted file mode 100644 index ff4b2039f50..00000000000 --- a/src/beast/example/http-client/http_client.cpp +++ /dev/null @@ -1,88 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -//[example_http_client - -#include -#include -#include -#include -#include -#include -#include - -using tcp = boost::asio::ip::tcp; // from -namespace http = beast::http; // from - -int main() -{ - // A helper for reporting errors - auto const fail = - [](std::string what, beast::error_code ec) - { - std::cerr << what << ": " << ec.message() << std::endl; - return EXIT_FAILURE; - }; - - beast::error_code ec; - - // Set up an asio socket - boost::asio::io_service ios; - tcp::resolver r{ios}; - tcp::socket sock{ios}; - - // Look up the domain name - std::string const host = "www.example.com"; - auto const lookup = r.resolve({host, "http"}, ec); - if(ec) - return fail("resolve", ec); - - // Make the connection on the IP address we get from a lookup - boost::asio::connect(sock, lookup, ec); - if(ec) - return fail("connect", ec); - - // Set up an HTTP GET request message - http::request req{http::verb::get, "/", 11}; - req.set(http::field::host, host + ":" + - std::to_string(sock.remote_endpoint().port())); - req.set(http::field::user_agent, BEAST_VERSION_STRING); - req.prepare_payload(); - - // Write the HTTP request to the remote host - http::write(sock, req, ec); - if(ec) - return fail("write", ec); - - // This buffer is used for reading and must be persisted - beast::flat_buffer b; - - // Declare a container to hold the response - http::response res; - - // Read the response - http::read(sock, b, res, ec); - if(ec) - return fail("read", ec); - - // Write the message to standard out - std::cout << res << std::endl; - - // Gracefully close the socket - sock.shutdown(tcp::socket::shutdown_both, ec); - - // not_connected happens sometimes - // so don't bother reporting it. - // - if(ec && ec != beast::errc::not_connected) - return fail("shutdown", ec); - - // If we get here then the connection is closed gracefully - return EXIT_SUCCESS; -} - -//] diff --git a/src/beast/example/http-crawl/CMakeLists.txt b/src/beast/example/http-crawl/CMakeLists.txt deleted file mode 100644 index 477f699c875..00000000000 --- a/src/beast/example/http-crawl/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -# Part of Beast - -GroupSources(include/beast beast) - -GroupSources(example/http-crawl "/") - -add_executable (http-crawl - ${BEAST_INCLUDES} - ${EXTRAS_INCLUDES} - urls_large_data.hpp - urls_large_data.cpp - http_crawl.cpp -) - -target_link_libraries(http-crawl Beast) diff --git a/src/beast/example/http-crawl/Jamfile b/src/beast/example/http-crawl/Jamfile deleted file mode 100644 index 180be9ec07b..00000000000 --- a/src/beast/example/http-crawl/Jamfile +++ /dev/null @@ -1,14 +0,0 @@ -# -# Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -# -# 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) -# - -exe http-crawl : - http_crawl.cpp - urls_large_data.cpp - : - coverage:no - ubasan:no - ; diff --git a/src/beast/example/http-crawl/http_crawl.cpp b/src/beast/example/http-crawl/http_crawl.cpp deleted file mode 100644 index 03ae5172774..00000000000 --- a/src/beast/example/http-crawl/http_crawl.cpp +++ /dev/null @@ -1,137 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#include "urls_large_data.hpp" - -#include -#include -#include -#include -#include -#include - -using tcp = boost::asio::ip::tcp; // from -namespace http = beast::http; // from - -template -void -err(beast::error_code const& ec, String const& what) -{ - std::cerr << what << ": " << ec.message() << std::endl; -} - -/* This simple program just visits a list with a few - thousand domain names and tries to retrieve and print - the home page of each site. -*/ -int -main(int, char const*[]) -{ - // A helper for reporting errors - auto const fail = - [](std::string what, beast::error_code ec) - { - std::cerr << what << ": " << ec.message() << std::endl; - std::cerr.flush(); - return EXIT_FAILURE; - }; - - // Obligatory Asio variable - boost::asio::io_service ios; - - // Loop over all the URLs - for(auto const& host : urls_large_data()) - { - beast::error_code ec; - - // Look up the domain name - tcp::resolver r(ios); - auto lookup = r.resolve({host, "http"}, ec); - if(ec) - { - fail("resolve", ec); - continue; - } - - // Now create a socket and connect - tcp::socket sock(ios); - boost::asio::connect(sock, lookup, ec); - if(ec) - { - fail("connect", ec); - continue; - } - - // Grab the remote endpoint - auto ep = sock.remote_endpoint(ec); - if(ec) - { - fail("remote_endpoint", ec); - continue; - } - - // Set up an HTTP GET request - http::request req{http::verb::get, "/", 11}; - req.set(http::field::host, host + std::string(":") + std::to_string(ep.port())); - req.set(http::field::user_agent, BEAST_VERSION_STRING); - - // Set the Connection: close field, this way the server will close - // the connection. This consumes less resources (no TIME_WAIT) because - // of the graceful close. It also makes things go a little faster. - // - req.set(http::field::connection, "close"); - - // Send the GET request - http::write(sock, req, ec); - if(ec == http::error::end_of_stream) - { - // This special error received on a write indicates that the - // semantics of the sent message are such that the connection - // should be closed after the response is done. We do a TCP/IP - // "half-close" here to shut down our end. - // - sock.shutdown(tcp::socket::shutdown_send, ec); - if(ec && ec != beast::errc::not_connected) - return fail("shutdown", ec); - } - if(ec) - { - fail("write", ec); - continue; - } - - // This buffer is needed for reading - beast::multi_buffer b; - - // The response will go into this object - http::response res; - - // Read the response - http::read(sock, b, res, ec); - if(ec == http::error::end_of_stream) - { - // This special error means that the other end closed the socket, - // which is what we want since we asked for Connection: close. - // However, we are going through a rather large number of servers - // and sometimes they misbehave. - ec = {}; - } - else if(ec) - { - fail("read", ec); - continue; - } - - // Now we do the other half of the close, - // which is to shut down the receiver. - sock.shutdown(tcp::socket::shutdown_receive, ec); - if(ec && ec != beast::errc::not_connected) - return fail("shutdown", ec); - - std::cout << res << std::endl; - } -} diff --git a/src/beast/example/http-crawl/urls_large_data.cpp b/src/beast/example/http-crawl/urls_large_data.cpp deleted file mode 100644 index 61d68ba457a..00000000000 --- a/src/beast/example/http-crawl/urls_large_data.cpp +++ /dev/null @@ -1,10019 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#include "urls_large_data.hpp" - -// Data from Alexa top 1 million sites -// http://s3.amazonaws.com/alexa-static/top-1m.csv.zip -// -std::vector const& -urls_large_data() -{ - static std::vector const urls ({ - "google.com", - "facebook.com", - "youtube.com", - "yahoo.com", - "baidu.com", - "wikipedia.org", - "qq.com", - "linkedin.com", - "taobao.com", - "twitter.com", - "live.com", - "amazon.com", - "sina.com.cn", - "google.co.in", - "hao123.com", - "blogspot.com", - "weibo.com", - "wordpress.com", - "yandex.ru", - "yahoo.co.jp", - "tmall.com", - "bing.com", - "vk.com", - "ebay.com", - "360.cn", - "google.de", - "sohu.com", - "pinterest.com", - "google.co.uk", - "ask.com", - "google.fr", - "msn.com", - "163.com", - "soso.com", - "tumblr.com", - "google.co.jp", - "instagram.com", - "mail.ru", - "google.com.br", - "microsoft.com", - "paypal.com", - "google.ru", - "xvideos.com", - "google.es", - "imdb.com", - "apple.com", - "google.it", - "adcash.com", - "craigslist.org", - "stackoverflow.com", - "amazon.co.jp", - "neobux.com", - "google.com.hk", - "imgur.com", - "ifeng.com", - "cnn.com", - "google.com.mx", - "xhamster.com", - "xinhuanet.com", - "gmw.cn", - "reddit.com", - "bbc.co.uk", - "blogger.com", - "google.ca", - "fc2.com", - "vube.com", - "go.com", - "akamaihd.net", - "alipay.com", - "about.com", - "people.com.cn", - "t.co", - "googleusercontent.com", - "wordpress.org", - "odnoklassniki.ru", - "alibaba.com", - "google.com.tr", - "aliexpress.com", - "youku.com", - "conduit.com", - "huffingtonpost.com", - "godaddy.com", - "flickr.com", - "pornhub.com", - "google.com.au", - "amazon.de", - "blogspot.in", - "kickass.to", - "ebay.de", - "netflix.com", - "google.pl", - "thepiratebay.se", - "bp.blogspot.com", - "adobe.com", - "dailymotion.com", - "china.com", - "vimeo.com", - "dailymail.co.uk", - "cnet.com", - "rakuten.co.jp", - "espn.go.com", - "ku6.com", - "ebay.co.uk", - "themeforest.net", - "xnxx.com", - "livejasmin.com", - "indiatimes.com", - "aol.com", - "redtube.com", - "dropbox.com", - "amazonaws.com", - "uol.com.br", - "weather.com", - "m2newmedia.com", - "amazon.co.uk", - "google.com.ar", - "google.com.sa", - "pixnet.net", - "nytimes.com", - "slideshare.net", - "youporn.com", - "google.com.eg", - "buzzfeed.com", - "wikimedia.org", - "booking.com", - "livejournal.com", - "globo.com", - "fiverr.com", - "adf.ly", - "secureserver.net", - "mozilla.org", - "google.com.pk", - "google.com.tw", - "google.nl", - "yelp.com", - "sogou.com", - "ameblo.jp", - "directrev.com", - "clkmon.com", - "hootsuite.com", - "deviantart.com", - "blogfa.com", - "wikia.com", - "outbrain.com", - "flipkart.com", - "wikihow.com", - "etsy.com", - "google.co.th", - "soundcloud.com", - "google.co.za", - "avg.com", - "w3schools.com", - "theguardian.com", - "stumbleupon.com", - "espncricinfo.com", - "livedoor.com", - "forbes.com", - "archive.org", - "4shared.com", - "foxnews.com", - "files.wordpress.com", - "answers.com", - "bankofamerica.com", - "chase.com", - "google.co.ve", - "mediafire.com", - "torrentz.eu", - "badoo.com", - "salesforce.com", - "aweber.com", - "sourceforge.net", - "bbc.com", - "addthis.com", - "liveinternet.ru", - "china.com.cn", - "indeed.com", - "reference.com", - "github.com", - "skype.com", - "hostgator.com", - "google.gr", - "bet365.com", - "spiegel.de", - "ask.fm", - "so.com", - "statcounter.com", - "gameforge.com", - "onet.pl", - "naver.com", - "google.com.co", - "developunit.info", - "google.com.vn", - "google.co.id", - "nicovideo.jp", - "shutterstock.com", - "walmart.com", - "google.be", - "mailchimp.com", - "softonic.com", - "stackexchange.com", - "google.com.ng", - "google.com.ua", - "popads.net", - "allegro.pl", - "gamer.com.tw", - "wordreference.com", - "wellsfargo.com", - "loading-delivery1.com", - "zillow.com", - "tripadvisor.com", - "quikr.com", - "pandora.com", - "wsj.com", - "goo.ne.jp", - "bild.de", - "tube8.com", - "wix.com", - "google.se", - "coccoc.com", - "google.ro", - "suning.com", - "photobucket.com", - "weebly.com", - "tianya.cn", - "warriorforum.com", - "telegraph.co.uk", - "google.dz", - "naver.jp", - "php.net", - "ups.com", - "rambler.ru", - "zedo.com", - "reuters.com", - "google.at", - "media.tumblr.com", - "taringa.net", - "google.com.ph", - "chinaz.com", - "mashable.com", - "blogspot.com.es", - "hurriyet.com.tr", - "google.com.pe", - "bleacherreport.com", - "gmx.net", - "wp.pl", - "goodreads.com", - "leboncoin.fr", - "rutracker.org", - "lenta.ru", - "babylon.com", - "domaintools.com", - "sharelive.net", - "rediff.com", - "google.ch", - "comcast.net", - "twitch.tv", - "avito.ru", - "kaskus.co.id", - "nbcnews.com", - "onclickads.net", - "businessinsider.com", - "ikea.com", - "codecanyon.net", - "ndtv.com", - "usps.com", - "google.cl", - "doublepimp.com", - "moz.com", - "google.com.sg", - "usatoday.com", - "dmm.co.jp", - "amazon.fr", - "google.pt", - "ucoz.ru", - "rt.com", - "milliyet.com.tr", - "xuite.net", - "samsung.com", - "fedex.com", - "uploaded.net", - "pcpop.com", - "google.com.bd", - "bitly.com", - "goodgamestudios.com", - "ettoday.net", - "baomihua.com", - "39.net", - "web.de", - "rbc.ru", - "9gag.com", - "disqus.com", - "snapdeal.com", - "xcar.com.cn", - "washingtonpost.com", - "bloomberg.com", - "scribd.com", - "hp.com", - "constantcontact.com", - "4dsply.com", - "gsmarena.com", - "intuit.com", - "meetup.com", - "nih.gov", - "americanexpress.com", - "ehow.com", - "infusionsoft.com", - "google.cz", - "mercadolivre.com.br", - "myntra.com", - "varzesh3.com", - "mobile01.com", - "hardsextube.com", - "goal.com", - "thefreecamsecret.com", - "thefreedictionary.com", - "douban.com", - "iqiyi.com", - "it168.com", - "mama.cn", - "tmz.com", - "time.com", - "olx.in", - "microsoftonline.com", - "hulu.com", - "enet.com.cn", - "speedtest.net", - "orange.fr", - "free.fr", - "detik.com", - "bluehost.com", - "libero.it", - "histats.com", - "webmd.com", - "eazel.com", - "hudong.com", - "extratorrent.cc", - "google.co.kr", - "chaturbate.com", - "huanqiu.com", - "cnzz.com", - "daum.net", - "xing.com", - "force.com", - "jrj.com.cn", - "pchome.net", - "cj.com", - "youjizz.com", - "delta-search.com", - "techcrunch.com", - "motherless.com", - "tinyurl.com", - "beeg.com", - "kooora.com", - "google.cn", - "clickbank.com", - "yandex.ua", - "ad6media.fr", - "google.no", - "amazon.cn", - "zippyshare.com", - "acesse.com", - "google.co.hu", - "google.ae", - "hdfcbank.com", - "nba.com", - "zendesk.com", - "blogspot.co.uk", - "bestbuy.com", - "accuweather.com", - "getresponse.com", - "repubblica.it", - "xywy.com", - "ci123.com", - "ebay.in", - "in.com", - "ign.com", - "groupon.com", - "yesky.com", - "elpais.com", - "marca.com", - "kwejk.pl", - "caijing.com.cn", - "google.ie", - "cloudfront.net", - "intoday.in", - "wideinfo.org", - "pof.com", - "kakaku.com", - "bitauto.com", - "life.com.tw", - "xe.com", - "goo.gl", - "google.az", - "feedly.com", - "tagged.com", - "amazon.in", - "list-manage.com", - "w3.org", - "quora.com", - "ixxx.com", - "mysearchdial.com", - "dell.com", - "seznam.cz", - "t-online.de", - "plugrush.com", - "nydailynews.com", - "okcupid.com", - "istockphoto.com", - "snapdo.com", - "abcnews.go.com", - "target.com", - "latimes.com", - "mywebsearch.com", - "joomla.org", - "odesk.com", - "surveymonkey.com", - "elmundo.es", - "siteadvisor.com", - "aili.com", - "uimserv.net", - "ebay.com.au", - "doubleclick.com", - "zeobit.com", - "google.co.il", - "fbcdn.net", - "ero-advertising.com", - "issuu.com", - "naukri.com", - "gazeta.pl", - "ck101.com", - "udn.com", - "google.dk", - "ce.cn", - "capitalone.com", - "att.com", - "drudgereport.com", - "blackhatworld.com", - "adrotator.se", - "retailmenot.com", - "justdial.com", - "icicibank.com", - "likes.com", - "elance.com", - "cntv.cn", - "ameba.jp", - "java.com", - "lifehacker.com", - "jabong.com", - "gizmodo.com", - "ebay.it", - "lenovo.com", - "hypergames.net", - "google.fi", - "doorblog.jp", - "blogspot.de", - "jimdo.com", - "probux.com", - "blogspot.it", - "habrahabr.ru", - "webmoney.ru", - "irctc.co.in", - "sahibinden.com", - "github.io", - "informer.com", - "mysearchresults.com", - "upworthy.com", - "pch.com", - "eyny.com", - "canadaalltax.com", - "b5m.com", - "freelancer.com", - "match.com", - "searchfun.in", - "adnxs.com", - "sberbank.ru", - "ig.com.br", - "trulia.com", - "subscene.com", - "corriere.it", - "livescore.com", - "irs.gov", - "twoo.com", - "clixsense.com", - "4399.com", - "xda-developers.com", - "iminent.com", - "google.com.my", - "onlinesbi.com", - "empowernetwork.com", - "zing.vn", - "youdao.com", - "systweak.com", - "flipora.com", - "ning.com", - "engadget.com", - "abril.com.br", - "exoclick.com", - "semrush.com", - "commentcamarche.net", - "shareasale.com", - "vnexpress.net", - "battle.net", - "youm7.com", - "digg.com", - "rapidgator.net", - "expedia.com", - "twimg.com", - "newegg.com", - "lady8844.com", - "xgo.com.cn", - "pcgames.com.cn", - "fotolia.com", - "rednet.cn", - "inspsearch.com", - "lemonde.fr", - "adultfriendfinder.com", - "typepad.com", - "mercadolibre.com.ar", - "homedepot.com", - "chip.de", - "lefigaro.fr", - "swagbucks.com", - "taleo.net", - "kinopoisk.ru", - "oracle.com", - "who.is", - "2ch.net", - "qtrax.com", - "eonline.com", - "sochi2014.com", - "myfreecams.com", - "pcbaby.com.cn", - "gome.com.cn", - "amazon.it", - "timeanddate.com", - "bestusefuldownloads.com", - "foursquare.com", - "telexfree.com", - "gc.ca", - "58.com", - "hubspot.com", - "backpage.com", - "examiner.com", - "ria.ru", - "google.sk", - "opensiteexplorer.org", - "awesomehp.com", - "sexlog.com", - "gutefrage.net", - "steampowered.com", - "slate.com", - "marketwatch.com", - "beva.com", - "shaadi.com", - "v1.cn", - "teensdigest.com", - "blogspot.ru", - "taboola.com", - "citrixonline.com", - "hatena.ne.jp", - "seesaa.net", - "houzz.com", - "bodybuilding.com", - "webs.com", - "chexun.com", - "ya.ru", - "citibank.com", - "viralnova.com", - "2345.com", - "ashleyrnadison.com", - "verizonwireless.com", - "55bbs.com", - "theblaze.com", - "123rf.com", - "gotomeeting.com", - "kijiji.ca", - "linkbucks.com", - "haber7.com", - "pravda.com.ua", - "altervista.org", - "mihanblog.com", - "terra.com.br", - "soku.com", - "urbandictionary.com", - "mercadolibre.com.mx", - "pixiv.net", - "oneindia.in", - "yellowpages.com", - "hotels.com", - "drtuber.com", - "scoop.it", - "blogspot.jp", - "cbslocal.com", - "movie4k.to", - "cpmterra.com", - "hubpages.com", - "mobile.de", - "yaolan.com", - "etao.com", - "hidemyass.com", - "ca.gov", - "dreamstime.com", - "firedrive.com", - "searchengines.ru", - "m-w.com", - "ebay.fr", - "templatemonster.com", - "evernote.com", - "fastdailyfind.com", - "amazon.es", - "gateable.com", - "hupu.com", - "y8.com", - "blogspot.com.tr", - "tokobagus.com", - "azlyrics.com", - "website-unavailable.com", - "r10.net", - "wiktionary.org", - "bongacams.com", - "focus.de", - "linksynergy.com", - "steamcommunity.com", - "vk.me", - "sakura.ne.jp", - "foxsports.com", - "optmd.com", - "tabelog.com", - "narod.ru", - "glassdoor.com", - "outlook.com", - "europa.eu", - "viadeo.com", - "leadpages.net", - "ouedkniss.com", - "facenama.com", - "lpcloudsvr302.com", - "agoda.com", - "qvo6.com", - "majesticseo.com", - "mirror.co.uk", - "google.com.kw", - "filehippo.com", - "moneycontrol.com", - "duckduckgo.com", - "npr.org", - "coupons.com", - "mynet.com", - "allrecipes.com", - "priceline.com", - "liveleak.com", - "jqw.com", - "slickdeals.net", - "webcrawler.com", - "babytree.com", - "amung.us", - "tomshardware.com", - "openadserving.com", - "independent.co.uk", - "kompas.com", - "turbobit.net", - "google.kz", - "leo.org", - "yandex.com.tr", - "mp3skull.com", - "nordstrom.com", - "news.com.au", - "traidnt.net", - "wunderground.com", - "cnbc.com", - "jquery.com", - "dict.cc", - "persianblog.ir", - "clarin.com", - "all-free-download.com", - "fhserve.com", - "sape.ru", - "asos.com", - "addmefast.com", - "lequipe.fr", - "lapatilla.com", - "ancestry.com", - "stockstar.com", - "monster.com", - "people.com", - "gawker.com", - "howstuffworks.com", - "tradedoubler.com", - "over-blog.com", - "cbc.ca", - "fishcod.com", - "yoka.com", - "macys.com", - "gazeta.ru", - "free-tv-video-online.me", - "google.bg", - "google.lk", - "southwest.com", - "realtor.com", - "custhelp.com", - "bhaskar.com", - "softpedia.com", - "farsnews.com", - "cy-pr.com", - "theverge.com", - "tudou.com", - "youboy.com", - "porn.com", - "wetransfer.com", - "virgilio.it", - "mega.co.nz", - "sfgate.com", - "delta-homes.com", - "squarespace.com", - "watchseries.lt", - "overstock.com", - "nifty.com", - "jvzoo.com", - "lanacion.com.ar", - "prntscr.com", - "vesti.ru", - "zimbio.com", - "adscale.de", - "google.co.nz", - "yac.mx", - "tickld.com", - "kayak.com", - "youth.cn", - "jd.com", - "shopclues.com", - "allocine.fr", - "cracked.com", - "eventbrite.com", - "behance.net", - "youtube-mp3.org", - "bankmellat.ir", - "echo.msk.ru", - "autohome.com.cn", - "yandex.kz", - "sex.com", - "smh.com.au", - "digikala.com", - "mackolik.com", - "rottentomatoes.com", - "renren.com", - "wired.com", - "imageshack.us", - "interia.pl", - "zanox.com", - "eastday.com", - "fool.com", - "chinabyte.com", - "haberturk.com", - "hespress.com", - "wow.com", - "jobrapido.com", - "idnes.cz", - "qinbei.com", - "pr-cy.ru", - "klikbca.com", - "17ok.com", - "gamefaqs.com", - "immobilienscout24.de", - "biblegateway.com", - "espnfc.com", - "ehowenespanol.com", - "tabnak.ir", - "avazutracking.net", - "sapo.pt", - "welt.de", - "google.com.ec", - "sears.com", - "pcmag.com", - "nownews.com", - "kickstarter.com", - "pixlr.com", - "hongkiat.com", - "chinatimes.com", - "zoho.com", - "reverso.net", - "indianrail.gov.in", - "privatehomeclips.com", - "cbssports.com", - "entrepreneur.com", - "sporx.com", - "bhphotovideo.com", - "fatakat.com", - "xunlei.com", - "nikkei.com", - "chron.com", - "24h.com.vn", - "basecamp.com", - "airtel.in", - "dealshark.com", - "shopify.com", - "babycenter.com", - "letitbit.net", - "nuvid.com", - "yts.re", - "aparat.com", - "r2games.com", - "prestashop.com", - "alarabiya.net", - "india.com", - "magentocommerce.com", - "heise.de", - "sulekha.com", - "mpnrs.com", - "ibm.com", - "cbsnews.com", - "searchengineland.com", - "mapquest.com", - "ccb.com", - "zappos.com", - "rightmove.co.uk", - "sahadan.com", - "milanuncios.com", - "wenku.baidu.com/user/reg", - "ovh.net", - "screencast.com", - "ahrefs.com", - "6.cn", - "businessweek.com", - "linternaute.com", - "dafont.com", - "bestblackhatforum.com", - "streamcloud.eu", - "as.com", - "gtmetrix.com", - "wmmail.ru", - "spankwire.com", - "google.com.do", - "jeuxvideo.com", - "digitalpoint.com", - "amazon.ca", - "mlb.com", - "weheartit.com", - "list.ru", - "leagueoflegends.com", - "56.com", - "bloglovin.com", - "payoneer.com", - "nokia.com", - "aizhan.com", - "novinky.cz", - "ustream.tv", - "getbootstrap.com", - "seekingalpha.com", - "codwide.com", - "vice.com", - "usmagazine.com", - "primewire.ag", - "cam4.com", - "thehindu.com", - "deezer.com", - "graphicriver.net", - "dmm.com", - "biglobe.ne.jp", - "google.rs", - "z5x.net", - "tutsplus.com", - "icicibank.co.in", - "indiamart.com", - "gap.com", - "ensonhaber.com", - "sitepoint.com", - "rutor.org", - "chinanews.com", - "brainyquote.com", - "keepvid.com", - "censor.net.ua", - "subito.it", - "tablica.pl", - "onlylady.com", - "zulily.com", - "squidoo.com", - "change.org", - "sh.st", - "webhostingtalk.com", - "9gag.tv", - "nairaland.com", - "gulfup.com", - "staples.com", - "gamespot.com", - "woorank.com", - "box.com", - "infobae.com", - "elegantthemes.com", - "104.com.tw", - "aftonbladet.se", - "google.hr", - "myegy.com", - "noticias24.com", - "eastmoney.com", - "lowes.com", - "xtube.com", - "worldstarhiphop.com", - "glispa.com", - "verizon.com", - "united.com", - "linkwithin.com", - "google.com.ly", - "whitepages.com", - "games.la", - "dmoz.org", - "imagebam.com", - "careerbuilder.com", - "sky.com", - "instructables.com", - "mercadolibre.com.ve", - "makemytrip.com", - "pinimg.com", - "pingdom.com", - "foodnetwork.com", - "orf.at", - "android.com", - "wiocha.pl", - "csdn.net", - "appledaily.com.tw", - "nike.com", - "eluniversal.com.mx", - "delta.com", - "ezinearticles.com", - "sueddeutsche.de", - "woothemes.com", - "comcast.com", - "gismeteo.ru", - "lotour.com", - "nfl.com", - "xbox.com", - "almanar.com.lb", - "disney.go.com", - "ctrip.com", - "forexfactory.com", - "clicksvenue.com", - "nhl.com", - "ted.com", - "gstatic.com", - "forobeta.com", - "ovh.com", - "mystart.com", - "maktoob.com", - "nouvelobs.com", - "hindustantimes.com", - "billdesk.com", - "1und1.de", - "zhaopin.com", - "weather.gov", - "kioskea.net", - "myspace.com", - "firstpost.com", - "picmonkey.com", - "grooveshark.com", - "exblog.jp", - "pantip.com", - "earthlink.net", - "styletv.com.cn", - "icloud.com", - "manta.com", - "google.by", - "mediaset.it", - "searchenginewatch.com", - "japanpost.jp", - "postimg.org", - "mbc.net", - "cheezburger.com", - "workercn.cn", - "directadvert.ru", - "nationzoom.com", - "caixa.gov.br", - "gumtree.com", - "51job.com", - "viooz.co", - "usbank.com", - "wmtransfer.com", - "fidelity.com", - "gogetlinks.net", - "office365.com", - "pchome.com.tw", - "feedburner.com", - "mp3truck.net", - "sfr.fr", - "junglee.com", - "keezmovies.com", - "binarysystem4u.com", - "way2sms.com", - "oyunskor.com", - "peyvandha.ir", - "ticketmaster.com", - "lacaixa.es", - "video-one.com", - "yomiuri.co.jp", - "popcash.net", - "nypost.com", - "dubizzle.com", - "wpmudev.org", - "mgid.com", - "google.lt", - "zazzle.com", - "nbcolympics.com", - "battlefield.com", - "avast.com", - "jsfiddle.net", - "namecheap.com", - "css-tricks.com", - "friv.com", - "6park.com", - "xhamstercams.com", - "mysql.com", - "dx.com", - "thechive.com", - "vsuch.com", - "souq.com", - "anyoption.com", - "dantri.com.vn", - "ebay.es", - "abc.es", - "whatsapp.com", - "bitshare.com", - "savefrom.net", - "beytoote.com", - "xiaomi.com", - "prweb.com", - "prothom-alo.com", - "pagesjaunes.fr", - "bbb.org", - "eenadu.net", - "tinypic.com", - "whois.com", - "sourtimes.org", - "adk2.com", - "criteo.com", - "tistory.com", - "ilyke.net", - "ruten.com.tw", - "skysports.com", - "makeuseof.com", - "p5w.net", - "hh.ru", - "nationalgeographic.com", - "pornmd.com", - "rakuten.ne.jp", - "idealo.de", - "telegraaf.nl", - "barnesandnoble.com", - "mynavi.jp", - "4chan.org", - "media-fire.org", - "crunchbase.com", - "bravotube.net", - "myfitnesspal.com", - "today.com", - "mit.edu", - "cnmo.com", - "nu.nl", - "tripadvisor.co.uk", - "spotify.com", - "homeway.com.cn", - "dianping.com", - "costco.com", - "pastebin.com", - "dhgate.com", - "windowsphone.com", - "stagram.com", - "investopedia.com", - "ninemsn.com.au", - "excite.co.jp", - "22find.com", - "google.iq", - "hi5.com", - "ad4game.com", - "kohls.com", - "online.sh.cn", - "geocities.jp", - "investing.com", - "haberler.com", - "ft.com", - "weblio.jp", - "google.tn", - "list-manage1.com", - "hsbc.co.uk", - "ppstream.com", - "cloob.com", - "korrespondent.net", - "ucoz.com", - "1and1.com", - "mail.com", - "fotostrana.ru", - "accountonline.com", - "forgeofempires.com", - "dribbble.com", - "city-data.com", - "drupal.org", - "tunein.com", - "51fanli.com", - "ibtimes.com", - "intel.com", - "polyvore.com", - "cbs.com", - "bab.la", - "imobile.com.cn", - "bestadbid.com", - "eztv.it", - "smashingmagazine.com", - "skyrock.com", - "copyscape.com", - "cookpad.com", - "smallseotools.com", - "asus.com", - "anysex.com", - "nbcsports.com", - "kinox.to", - "mbank.com.pl", - "500px.com", - "sofanti.com", - "marktplaats.nl", - "cpanel.net", - "hm.com", - "chicagotribune.com", - "ultimate-guitar.com", - "infolinks.com", - "merdeka.com", - "yandex.by", - "tribalfusion.com", - "livedoor.biz", - "prezi.com", - "last.fm", - "sznews.com", - "junbi-tracker.com", - "so-net.ne.jp", - "cocolog-nifty.com", - "ocn.ne.jp", - "perezhilton.com", - "yaplakal.com", - "championat.com", - "ebay.ca", - "mangareader.net", - "donanimhaber.com", - "miniclip.com", - "vcommission.com", - "noaa.gov", - "imagefap.com", - "gumtree.com.au", - "liveperson.net", - "gfycat.com", - "hollywoodreporter.com", - "dropboxusercontent.com", - "akhbarak.net", - "sou300.com", - "kicker.de", - "livestream.com", - "tribunnews.com", - "kp.ru", - "techradar.com", - "315che.com", - "dw.de", - "codeproject.com", - "newsru.com", - "pconline.com.cn", - "aa.com", - "usaa.com", - "asahi.com", - "themetapicture.com", - "quicksprout.com", - "piriform.com", - "888poker.com", - "gittigidiyor.com", - "nhk.or.jp", - "statigr.am", - "ipage.com", - "gazzetta.it", - "letv.com", - "yourlust.com", - "freepik.com", - "trello.com", - "mixi.jp", - "livememe.com", - "ew.com", - "seosprint.net", - "doisongphapluat.com", - "autotrader.com", - "docstoc.com", - "viva.co.id", - "livestrong.com", - "inc.com", - "hunantv.com", - "bahn.de", - "depositphotos.com", - "rackspace.com", - "flippa.com", - "norton.com", - "lynda.com", - "teamviewer.com", - "vip.com", - "ksl.com", - "solarmovie.so", - "klout.com", - "pikabu.ru", - "vporn.com", - "apache.org", - "sportbox.ru", - "correios.com.br", - "toptenreviews.com", - "ea.com", - "thenextweb.com", - "superuser.com", - "delicious.com", - "zoosk.com", - "inbox.com", - "kongregate.com", - "starbaby.cn", - "888casino.com", - "brazzers.com", - "sockshare.com", - "megashare.info", - "vistaprint.com", - "porntube.com", - "seriesyonkis.com", - "20minutos.es", - "jagran.com", - "programme-tv.net", - "elcomercio.pe", - "blogspot.kr", - "t411.me", - "googleapis.com", - "blog.com", - "qingdaonews.com", - "sedo.com", - "itmedia.co.jp", - "mtv.com", - "ynet.co.il", - "playstation.com", - "pornhublive.com", - "thedailybeast.com", - "r7.com", - "sabah.com.tr", - "126.com", - "topix.com", - "liga.net", - "marriott.com", - "tvn24.pl", - "sitesell.com", - "netdna-cdn.com", - "startimes.com", - "hstpnetwork.com", - "blogspot.com.au", - "17u.cn", - "subscribe.ru", - "woot.com", - "rozblog.com", - "wimp.com", - "vg.no", - "t-mobile.com", - "bmi.ir", - "kankan.com", - "tsn.ua", - "gumtree.co.za", - "googleadservices.com", - "pnc.com", - "cars.com", - "soccerway.com", - "o2.pl", - "zeit.de", - "zopim.com", - "cloudflare.com", - "givemesport.com", - "statscrop.com", - "gravatar.com", - "flightradar24.com", - "ubuntu.com", - "salon.com", - "ytimg.com", - "trovigo.com", - "sunporno.com", - "libertagia.com", - "mihanwebads.com", - "shopathome.com", - "cdiscount.com", - "commbank.com.au", - "elwatannews.com", - "discovercard.com", - "infowars.com", - "blogimg.jp", - "portaldosites.com", - "fixya.com", - "drom.ru", - "fastpic.ru", - "pbs.org", - "kandao.com", - "okwave.jp", - "faz.net", - "sbnation.com", - "hilton.com", - "duba.com", - "homeshop18.com", - "ultimasnoticias.com.ve", - "bankrate.com", - "megasesso.com", - "studiopress.com", - "sports.ru", - "asriran.com", - "etoro.com", - "cafemom.com", - "dhl.de", - "indiegogo.com", - "tdcanadatrust.com", - "1tv.ru", - "gogvo.com", - "bt.com", - "blogspot.tw", - "zergnet.com", - "garanti.com.tr", - "privatbank.ua", - "sanook.com", - "travelocity.com", - "networksolutions.com", - "thqafawe3lom.com", - "trklnks.com", - "torchbrowser.com", - "logmein.com", - "williamhill.com", - "zhihu.com", - "auto.ru", - "craigslist.ca", - "olx.com.pk", - "smi2.ru", - "ukr.net", - "dpreview.com", - "boston.com", - "folha.uol.com.br", - "name.com", - "ashemaletube.com", - "slimspots.com", - "envato.com", - "6pm.com", - "fandango.com", - "sozcu.com.tr", - "nikkeibp.co.jp", - "aufeminin.com", - "baiducontent.com", - "buscape.com.br", - "funnyordie.com", - "337.com", - "sakshi.com", - "airasia.com", - "samanyoluhaber.com", - "picofile.com", - "blackberry.com", - "google.com.gt", - "io9.com", - "easyhits4u.com", - "qianyan001.com", - "flashx.tv", - "zap2it.com", - "dnsrsearch.com", - "patch.com", - "staticflickr.com", - "clicksor.com", - "mcafee.com", - "zerohedge.com", - "zara.com", - "freelotto.com", - "tutorialspoint.com", - "qone8.com", - "olx.com.br", - "axisbank.com", - "marketgid.com", - "your-server.de", - "game321.com", - "harvard.edu", - "indianexpress.com", - "fatwallet.com", - "nudevista.com", - "paper.li", - "opera.com", - "serving-sys.com", - "nowvideo.sx", - "theatlantic.com", - "cisco.com", - "bookmyshow.com", - "webmasterworld.com", - "metro.co.uk", - "leparisien.fr", - "orbitz.com", - "h2porn.com", - "4cdn.org", - "itar-tass.com", - "nasa.gov", - "macrumors.com", - "google.si", - "usnews.com", - "premierleague.com", - "largeporntube.com", - "blogsky.com", - "bufferapp.com", - "zeroredirect1.com", - "sendspace.com", - "stanford.edu", - "state.gov", - "yjc.ir", - "abc.net.au", - "pornsharing.com", - "4pda.ru", - "52pk.net", - "meituan.com", - "mmgp.ru", - "sponichi.co.jp", - "masrawy.com", - "whatismyipaddress.com", - "onlinewebfind.com", - "news24.com", - "zdnet.com", - "imagevenue.com", - "gameaholic.com", - "mediaplex.com", - "clip.vn", - "2mdn.net", - "nmisr.com", - "musica.com", - "networkedblogs.com", - "metrolyrics.com", - "chacha.com", - "internetdownloadmanager.com", - "legacy.com", - "wwe.com", - "icbc.com.cn", - "ny.gov", - "chomikuj.pl", - "alexa.com", - "pcworld.com", - "overthumbs.com", - "adp.com", - "ad2games.com", - "adme.ru", - "bidvertiser.com", - "rtl.de", - "sweetim.com", - "gaana.com", - "7k7k.com", - "livingsocial.com", - "netteller.com", - "rakuten.com", - "chess.com", - "blackboard.com", - "thekitchn.com", - "ilfattoquotidiano.it", - "20minutes.fr", - "soufun.com", - "nerdbux.com", - "breitbart.com", - "webtretho.com", - "tvguide.com", - "miralinks.ru", - "weather.com.cn", - "zalando.de", - "dangdang.com", - "bubblews.com", - "thoughtcatalog.com", - "114la.com", - "msn.ca", - "blogmura.com", - "americanas.com.br", - "elitedaily.com", - "lightinthebox.com", - "bizjournals.com", - "yixun.com", - "itau.com.br", - "51.la", - "doodle.com", - "arabyonline.com", - "opencart.com", - "bomnegocio.com", - "lego.com", - "pclady.com.cn", - "metacafe.com", - "kimiss.com", - "journaldunet.com", - "gnavi.co.jp", - "51auto.com", - "clickey.com", - "chekb.com", - "searchnu.com", - "diply.com", - "walgreens.com", - "descargar.es", - "mirrorcreator.com", - "pornerbros.com", - "askmen.com", - "shop.com", - "inmotionhosting.com", - "filmweb.pl", - "kbb.com", - "appround.biz", - "aljazeera.com", - "lumosity.com", - "sweet-page.com", - "pole-emploi.fr", - "fishki.net", - "rollingstone.com", - "kapanlagi.com", - "yandex.com", - "cnblogs.com", - "plaintube.com", - "intentmedia.net", - "about.me", - "torrentz.in", - "01net.com", - "gyazo.com", - "nic.ru", - "juicyads.com", - "trend.az", - "askubuntu.com", - "unam.mx", - "tradus.com", - "tigerdirect.com", - "letras.mus.br", - "imagetwist.com", - "perfectmoney.is", - "wpbeginner.com", - "thepiratetrader.com", - "victoriassecret.com", - "images-amazon.com", - "tusfiles.net", - "chefkoch.de", - "ojooo.com", - "alphaporno.com", - "betfair.com", - "tympanus.net", - "td.com", - "4tube.com", - "phonearena.com", - "bankmandiri.co.id", - "cox.net", - "ozon.ru", - "perfectgirls.net", - "asana.com", - "sprint.com", - "berniaga.com", - "vente-privee.com", - "ing.nl", - "finn.no", - "atwiki.jp", - "toysrus.com", - "petflow.com", - "reverbnation.com", - "freeones.com", - "abc.go.com", - "bradesco.com.br", - "yenisafak.com.tr", - "profit-partner.ru", - "redfin.com", - "mangafox.me", - "appnexus.com", - "sxc.hu", - "speedanalysis.net", - "n-tv.de", - "qidian.com", - "teespring.com", - "break.com", - "nailedhard.com", - "jalan.net", - "authorize.net", - "adultadworld.com", - "sootoo.com", - "roboform.com", - "kotaku.com", - "multitran.ru", - "food.com", - "twitpic.com", - "pogo.com", - "sabq.org", - "priceminister.com", - "lexpress.fr", - "livetv.sx", - "nikkansports.com", - "securepaynet.net", - "vodoumedia.com", - "airbnb.com", - "trafficholder.com", - "rr.com", - "expireddomains.net", - "bandcamp.com", - "wayfair.com", - "tut.by", - "maybank2u.com.my", - "similarweb.com", - "zol.com.cn", - "247realmedia.com", - "asp.net", - "lonelyplanet.com", - "seopult.ru", - "whois.net", - "academia.edu", - "univision.com", - "interfax.ru", - "amarillasinternet.com", - "miercn.com", - "barclays.co.uk", - "societe.com", - "khabaronline.ir", - "unity3d.com", - "nyaa.se", - "euronews.com", - "verizon.net", - "rutube.ru", - "wetter.com", - "imlive.com", - "ggpht.com", - "docin.com", - "yify-torrents.com", - "yhd.com", - "citibank.co.in", - "xdating.com", - "roblox.com", - "voyages-sncf.com", - "189.cn", - "identi.li", - "bayt.com", - "medicinenet.com", - "wmaraci.com", - "stern.de", - "eluniversal.com", - "zoopla.co.uk", - "easyjet.com", - "dhl.com", - "freakshare.com", - "rojadirecta.me", - "sp.gov.br", - "friendfeed.com", - "beamtele.com", - "searchenginejournal.com", - "nocookie.net", - "reliancenetconnect.co.in", - "google.co.ma", - "fanpop.com", - "adk2.co", - "tagesschau.de", - "nate.com", - "ole.com.ar", - "index.hu", - "aruba.it", - "eltiempo.com", - "resellerclub.com", - "qip.ru", - "xossip.com", - "siteground.com", - "royalbank.com", - "advfn.com", - "tebyan.net", - "iciba.com", - "bigcartel.com", - "sciencedirect.com", - "hepsiburada.com", - "cpasbien.me", - "alfabank.ru", - "microsoftstore.com", - "discogs.com", - "onliner.by", - "socialmediaexaminer.com", - "seasonvar.ru", - "tripadvisor.in", - "360doc.com", - "chinabroadcast.cn", - "realestate.com.au", - "avira.com", - "herokuapp.com", - "downloadsetup.net", - "torcache.net", - "uefa.com", - "rg.ru", - "qianlong.com", - "hugedomains.com", - "arstechnica.com", - "fifa.com", - "ryanair.com", - "i.ua", - "axisbank.co.in", - "alimama.com", - "wanggou.com", - "radikal.com.tr", - "echoroukonline.com", - "unian.net", - "slashdot.org", - "dmv.org", - "mayoclinic.org", - "newsmax.com", - "google.com.et", - "icontact.com", - "vanguardngr.com", - "infojobs.net", - "say-move.org", - "ileehoo.com", - "mirtesen.ru", - "yam.com", - "e-hentai.org", - "wikimapia.org", - "shop-pro.jp", - "bukalapak.com", - "jcpenney.com", - "ilmeteo.it", - "iltasanomat.fi", - "telecomitalia.it", - "kariyer.net", - "shutterfly.com", - "santabanta.com", - "softlayer.com", - "complex.com", - "mamba.ru", - "netshoes.com.br", - "theweathernetwork.com", - "politico.com", - "advego.ru", - "eroprofile.com", - "mainichi.jp", - "nta.go.jp", - "sfimg.com", - "ap.org", - "webex.com", - "hinet.net", - "skyscrapercity.com", - "affili.net", - "adplxmd.com", - "iltalehti.fi", - "impress.co.jp", - "jezebel.com", - "extremetube.com", - "digitaltrends.com", - "one.com", - "ranker.com", - "qiwi.com", - "collegehumor.com", - "nbc.com", - "boursorama.com", - "watch32.com", - "meetcheap.com", - "forums.wordpress.com", - "cvs.com", - "kenh14.vn", - "yallakora.com", - "plurk.com", - "xtool.ru", - "airtel.com", - "wp.com", - "sftimes.co", - "economist.com", - "rapidshare.com", - "redbox.com", - "audible.com", - "kissmetrics.com", - "atpanel.com", - "wargaming.net", - "1337x.org", - "shahrekhabar.com", - "bdnews24.com", - "tvrain.ru", - "wykop.pl", - "mts.ru", - "nnm-club.me", - "schwab.com", - "elconfidencial.com", - "modelmayhem.com", - "zhidao.baidu.com/user/admin", - "aastocks.com", - "tiscali.it", - "qadabra.com", - "autoscout24.de", - "vatanim.com.tr", - "gotowebinar.com", - "edmunds.com", - "ebaumsworld.com", - "megafilmeshd.net", - "poste.it", - "mcssl.com", - "aljazeera.net", - "netvibes.com", - "sme.sk", - "tesco.com", - "525j.com.cn", - "tf1.fr", - "ccidnet.com", - "ldblog.jp", - "blockchain.info", - "played.to", - "nthwall.com", - "justanswer.com", - "clickbank.net", - "fnac.com", - "gmarket.co.kr", - "clipconverter.cc", - "nextmedia.com", - "bb.com.br", - "learntotradethemarket.com", - "pornoid.com", - "downloadha.com", - "hellporno.com", - "ooo-sex.com", - "blocket.se", - "tubeplus.me", - "seek.com.au", - "filestube.to", - "ceneo.pl", - "walmart.com.br", - "sonymobile.com", - "dyndns.org", - "ulmart.ru", - "vrbo.com", - "sport.pl", - "ashleymadison.com", - "el-wlid.com", - "boredpanda.com", - "udemy.com", - "mobogenie.com", - "tubegalore.com", - "theglobeandmail.com", - "bancobrasil.com.br", - "888.com", - "adreactor.com", - "zomato.com", - "depositfiles.com", - "moneysavingexpert.com", - "dofus.com", - "oanda.com", - "sport1.de", - "justhost.com", - "longhoo.net", - "otomoto.pl", - "techrepublic.com", - "westpac.com.au", - "dreamhost.com", - "ilsole24ore.com", - "clubic.com", - "gamme.com.tw", - "doctissimo.fr", - "isna.ir", - "s2d6.com", - "tdbank.com", - "zwaar.net", - "slando.ua", - "segodnya.ua", - "appannie.com", - "bartarinha.ir", - "egotastic.com", - "ed.gov", - "lg.com", - "120ask.com", - "hostmonster.com", - "super.cz", - "mercola.com", - "bayproxy.me", - "day.az", - "dummies.com", - "azet.sk", - "huffingtonpost.co.uk", - "okezone.com", - "medu.ir", - "lavanguardia.com", - "espreso.tv", - "nymag.com", - "autotrader.co.uk", - "socialmediatoday.com", - "wn.com", - "rtbpop.com", - "99designs.com", - "sanspo.com", - "proboards.com", - "virginmedia.com", - "99acres.com", - "blic.rs", - "pingomatic.com", - "prnewswire.com", - "sony.com", - "seobuilding.ru", - "www.gov.uk", - "jugem.jp", - "watchtower.com", - "seoprofiler.com", - "centrum.cz", - "techbrowsing.com", - "almasryalyoum.com", - "lolking.net", - "nipic.com", - "fanfiction.net", - "bwin.com", - "anyporn.com", - "sulit.com.ph", - "quickmeme.com", - "carview.co.jp", - "haizhangs.com", - "airtelforum.com", - "flirt4free.com", - "billboard.com", - "trademe.co.nz", - "rapgenius.com", - "pchouse.com.cn", - "beforeitsnews.com", - "peopleperhour.com", - "basecamphq.com", - "onlinedown.net", - "bet365.es", - "fucked-tube.com", - "santander.co.uk", - "speedbit.com", - "gi-akademie.com", - "google.com.pr", - "winupdatevideos.com", - "bizrate.com", - "xxxbunker.com", - "coursera.org", - "zoominfo.com", - "rarbg.com", - "ahram.org.eg", - "howtogeek.com", - "focus.cn", - "duden.de", - "mufg.jp", - "ex.ua", - "titan24.com", - "greatandhra.com", - "qqbaobao.com", - "rtve.es", - "yandex.net", - "yle.fi", - "panoramio.com", - "google.com.af", - "scol.com.cn", - "gamestop.com", - "xiami.com", - "webpagetest.org", - "creativecommons.org", - "archive.is", - "timesjobs.com", - "centurylink.com", - "wowhead.com", - "wordstream.com", - "lloydsbank.co.uk", - "incredibar.com", - "vagalume.com.br", - "installerapplicationusa.com", - "shinobi.jp", - "ruvr.ru", - "natwest.com", - "roulettebotplus.com", - "wildberries.ru", - "huaban.com", - "buenosearch.com", - "reg.ru", - "tempo.co", - "qvc.com", - "mangahere.com", - "tv.com", - "boc.cn", - "fnb.co.za", - "made-in-china.com", - "eleconomista.es", - "ubuntuforums.org", - "derstandard.at", - "xml-sitemaps.com", - "jang.com.pk", - "jiayuan.com", - "credit-agricole.fr", - "androidcentral.com", - "urbanspoon.com", - "pornoxo.com", - "regnum.ru", - "bedbathandbeyond.com", - "skladchik.com", - "daily.co.jp", - "n-mobile.net", - "suntrust.com", - "justjared.com", - "vid2c.com", - "gettyimages.com", - "tubecup.com", - "kinogo.net", - "similarsites.com", - "fling.com", - "vine.co", - "banglanews24.com", - "pudelek.pl", - "support.wordpress.com", - "cox.com", - "xkcd.com", - "adbooth.com", - "anz.com", - "adxcore.com", - "google.com.sv", - "indeed.co.in", - "scottrade.com", - "v9.com", - "isohunt.to", - "srclick.ru", - "gharreh.com", - "zaman.com.tr", - "monsterindia.com", - "delfi.lt", - "chewen.com", - "empowernetwork.com/QUbsgqDwpjjbkpOgwgOeaw==", - "state.tx.us", - "segundamano.es", - "utro.ru", - "sitescout.com", - "justclick.ru", - "wnd.com", - "cosmopolitan.com", - "local.com", - "anitube.se", - "sport.es", - "google.com.qa", - "ads-id.com", - "google.lv", - "capitalone360.com", - "hattrick.org", - "qualtrics.com", - "inagist.com", - "filgoal.com", - "incredibar-search.com", - "adslgate.com", - "directv.com", - "ilivid.com", - "warthunder.ru", - "jasmin.com", - "cyberciti.biz", - "msn.co.jp", - "canalblog.com", - "boerse.bz", - "tnaflix.com", - "apa.az", - "prchecker.info", - "reclameaqui.com.br", - "onlyworldnews.com", - "submarino.com.br", - "kuronekoyamato.co.jp", - "paipai.com", - "realitykings.com", - "deadspin.com", - "islamweb.net", - "no-ip.com", - "lostfilm.tv", - "wattpad.com", - "wav.tv", - "citi.com", - "buysellads.com", - "prezentacya.ru", - "forocoches.com", - "donga.com", - "drive2.ru", - "netsuite.com", - "privalia.com", - "bidorbuy.co.za", - "cmbchina.com", - "searchresultsguide.com", - "odatv.com", - "skrill.com", - "en.wordpress.com", - "dojki.com", - "unibet.com", - "hotpepper.jp", - "simplyhired.com", - "vesti.ua", - "ibtimes.co.uk", - "creativebloq.com", - "filmesonlinegratis.net", - "videohive.net", - "kmart.com", - "metacritic.com", - "rikunabi.com", - "zozo.jp", - "venturebeat.com", - "1and1.es", - "banesconline.com", - "internethaber.com", - "rae.es", - "planetsuzy.org", - "wpengine.com", - "kizi.com", - "armorgames.com", - "argos.co.uk", - "dtiblog.com", - "diigo.com", - "forever21.com", - "flashscore.com", - "vedomosti.ru", - "ccavenue.com", - "att.net", - "esporte.uol.com.br", - "empowernetwork.com/PXQ7Uz1Kyg+LR1APrG7pKQ==", - "to8to.com", - "hotwire.com", - "all.biz", - "info.com", - "xhamster.com/user/video", - "000webhost.com", - "worldoftanks.ru", - "dagbladet.no", - "computerbild.de", - "nasdaq.com", - "chitika.com", - "ipeen.com.tw", - "abola.pt", - "wiley.com", - "lpcloudsvr303.com", - "tinsao.net", - "mehrnews.com", - "hugesex.tv", - "christian-dogma.com", - "search.us.com", - "garmin.com", - "tgbus.com", - "iherb.com", - "torntv-tvv.org", - "chosun.com", - "kinozal.tv", - "berkeley.edu", - "techtarget.com", - "labanquepostale.fr", - "fitbit.com", - "folkd.com", - "theonion.com", - "idealista.com", - "oscar.go.com", - "jiji.com", - "anonym.to", - "allabout.co.jp", - "wufoo.com", - "rantlifestyle.com", - "google.com.bo", - "28.com", - "rocketnews24.com", - "hotspotshield.com", - "opentable.com", - "admngronline.com", - "naturalnews.com", - "zeroredirect2.com", - "ero-video.net", - "dinamalar.com", - "fl.ru", - "mtsindia.in", - "kapook.com", - "theage.com.au", - "allmyvideos.net", - "dinodirect.com", - "videodownloadconverter.com", - "tripleclicks.com", - "brassring.com", - "fapdu.com", - "cafepress.com", - "infospace.com", - "express.com.pk", - "fumu.com", - "infibeam.com", - "etrade.com", - "meneame.net", - "seroundtable.com", - "bigpoint.com", - "chinadaily.com.cn", - "myfonts.com", - "ezdownloadpro.info", - "codeplex.com", - "xl.pt", - "kaspersky.com", - "khabarfarsi.com", - "admitad.com", - "flirchi.com", - "dpstream.net", - "miniinthebox.com", - "samsclub.com", - "charter.net", - "techbang.com", - "tiu.ru", - "fanpage.it", - "spokeo.com", - "imageshack.com", - "ijreview.com", - "bc.vc", - "lazada.co.id", - "gofirstrow.eu", - "uptobox.com", - "newsnow.co.uk", - "symantec.com", - "editor.wix.com", - "avaxhome.cc", - "canalplus.fr", - "copyblogger.com", - "vetogate.com", - "yahoo-mbga.jp", - "manoramaonline.com", - "ah-me.com", - "elheddaf.com", - "bitcointalk.org", - "haqaik.com", - "bbandt.com", - "linguee.de", - "blogspot.nl", - "minus.com", - "amarujala.com", - "openclassrooms.com", - "bigmir.net", - "koramgame.com", - "commonfloor.com", - "gayromeo.com", - "cleartrip.com", - "kompasiana.com", - "tankionline.com", - "google.co.tz", - "springer.com", - "lifenews.ru", - "sify.com", - "tvoyauda4a.ru", - "dfiles.ru", - "technorati.com", - "myorderbox.com", - "fanatik.com.tr", - "activesearchresults.com", - "laposte.net", - "whirlpool.net.au", - "stockcharts.com", - "leadimpact.com", - "cardekho.com", - "ryushare.com", - "blog.jp", - "fastcompany.com", - "eurosport.fr", - "emirates.com", - "lb.ua", - "serverfault.com", - "forbes.ru", - "bfmtv.com", - "google.jo", - "17173.com", - "wikispaces.com", - "tokopedia.com", - "liberation.fr", - "a10.com", - "kdnet.net", - "variety.com", - "blog.me", - "homeaway.com", - "ameritrade.com", - "adult-empire.com", - "national.com.au", - "haraj.com.sa", - "timewarnercable.com", - "casino.com", - "sheknows.com", - "google.com.uy", - "abv.bg", - "liputan6.com", - "etxt.ru", - "bigstockphoto.com", - "strato.de", - "cashtasks.com", - "columbia.edu", - "zdf.de", - "pptv.com", - "cricbuzz.com", - "sharesuper.info", - "radaronline.com", - "pornolab.net", - "google.ba", - "opensubtitles.org", - "abclocal.go.com", - "ansa.it", - "pbskids.org", - "vz.ru", - "iconfinder.com", - "vitaminl.tv", - "ntv.ru", - "peliculasyonkis.com", - "foto-hd.com", - "paytm.com", - "rantsports.com", - "optimum.net", - "postbank.de", - "index.hr", - "smugmug.com", - "haivl.com", - "arbeitsagentur.de", - "dailycaller.com", - "freshbooks.com", - "genieo.com", - "alnaddy.com", - "britishairways.com", - "20min.ch", - "findthebest.com", - "autoblog.com", - "warez-bb.org", - "iza.ne.jp", - "filmaffinity.com", - "megogo.net", - "soccermanager.com", - "dawanda.com", - "parallels.com", - "clickjogos.uol.com.br", - "12306.cn", - "jstv.com", - "cliphunter.com", - "pixabay.com", - "milenio.com", - "keybinary.com", - "suumo.jp", - "mediatakeout.com", - "vodafone.in", - "cheapoair.com", - "seobook.com", - "videoyoum7.com", - "yr.no", - "gofundme.com", - "ixbt.com", - "starbucks.com", - "conferenceplus.com", - "media1first.com", - "sergey-mavrodi.com", - "rafflecopter.com", - "591.com.tw", - "mangapanda.com", - "huffingtonpost.fr", - "tiboo.cn", - "bancomer.com.mx", - "handelsblatt.com", - "hpylgr.com", - "psu.edu", - "bancomercantil.com", - "sport-express.ru", - "codepen.io", - "foundationapi.com", - "ow.ly", - "vatgia.com", - "kommersant.ru", - "srvsinf.com", - "telderi.ru", - "mercadolibre.com.co", - "hsbc.com.hk", - "t3n.de", - "magicbricks.com", - "shopstyle.com", - "mudah.my", - "punchng.com", - "therichest.com", - "fansshare.com", - "lepoint.fr", - "vipzona.info", - "globaltestmarket.com", - "jqueryui.com", - "bcsh.com", - "mundodeportivo.com", - "newyorker.com", - "funnyjunk.com", - "gongchang.com", - "a8.net", - "ecollege.com", - "newhdplugin.net", - "befuck.com", - "elespectador.com", - "drugs.com", - "abplive.in", - "feelcars.com", - "psychologytoday.com", - "instaforex.com", - "strtsrv.com", - "atpworldtour.com", - "incruit.com", - "starwoodhotels.com", - "zone-telechargement.com", - "songspk.name", - "hatenablog.com", - "enfemenino.com", - "msnbc.com", - "freebitco.in", - "akairan.com", - "discovery.com", - "angieslist.com", - "lesechos.fr", - "transfermarkt.de", - "sephora.com", - "come.in", - "dailykos.com", - "deutsche-bank.de", - "warriorplus.com", - "awwwards.com", - "lomadee.com", - "365jia.cn", - "lotterypost.com", - "egrana.com.br", - "rivals.com", - "literotica.com", - "myfreshnet.com", - "ihg.com", - "fazenda.gov.br", - "tomnod.com", - "filesharefanatic.com", - "hotukdeals.com", - "bitsnoop.com", - "tenpay.com", - "putlocker.bz", - "ziddu.com", - "ntvmsnbc.com", - "surveyzrewardcenter.com", - "aliyun.com", - "media.net", - "comdirect.de", - "yoox.com", - "hotelscombined.com", - "vgsgaming-ads.com", - "robokassa.ru", - "webdesignerdepot.com", - "rotoworld.com", - "jmw.com.cn", - "seloger.com", - "dsdomination.com", - "affiliatewindow.com", - "abs-cbnnews.com", - "bmo.com", - "iconarchive.com", - "funshion.com", - "admin5.com", - "playhe.com", - "bigcommerce.com", - "yodobashi.com", - "bigfishgames.com", - "onlinecreditcenter6.com", - "homes.co.jp", - "gameninja.com", - "ebates.com", - "banamex.com.mx", - "google.com.lb", - "2chblog.jp", - "entertainment-factory.com", - "asg.to", - "walla.co.il", - "mktmobi.com", - "opensooq.com", - "adam4adam.com", - "expressen.se", - "elephanttube.com", - "ingdirect.es", - "clicrbs.com.br", - "seriespepito.com", - "skyscanner.net", - "shine.com", - "appround.us", - "washingtontimes.com", - "nrk.no", - "1stwebdesigner.com", - "gucheng.com", - "ghanaweb.com", - "jzip.com", - "rozetka.com.ua", - "wiziwig.tv", - "jobsdb.com", - "kitco.com", - "rpp.com.pe", - "aljaras.com", - "telecinco.es", - "storify.com", - "netease.com", - "business-standard.com", - "babble.com", - "noticias.uol.com.br", - "alice.it", - "bizdec.ru", - "voanews.com", - "freejobalert.com", - "origo.hu", - "list-manage2.com", - "gavick.com", - "national-lottery.co.uk", - "gazzetta.gr", - "freevideodownloadforpc.com", - "xmarks.com", - "wikibooks.org", - "sexad.net", - "alc.co.jp", - "emol.com", - "careesma.in", - "cdc.gov", - "toshiba.com", - "imgchili.net", - "rbcroyalbank.com", - "indowebster.com", - "zynga.com", - "telekom.com", - "jiameng.com", - "adsmarket.com", - "utorrent.com", - "aarp.org", - "cityadspix.com", - "ekstrabladet.dk", - "doc88.com", - "fetlife.com", - "fh21.com.cn", - "cambridge.org", - "tune.pk", - "auction.co.kr", - "patheos.com", - "search-results.com", - "lds.org", - "webrankinfo.com", - "newsit.gr", - "techtudo.com.br", - "moviepilot.com", - "mercador.ro", - "nguoiduatin.vn", - "tripadvisor.it", - "lurkmore.to", - "europapress.es", - "uspto.gov", - "excelsior.com.mx", - "myvideo.de", - "jetblue.com", - "camfrog.com", - "blick.ch", - "batepapo.uol.com.br", - "manager.co.th", - "goibibo.com", - "cornell.edu", - "apetube.com", - "nation.com", - "allmusic.com", - "naughtyamerica.com", - "obozrevatel.com", - "telegrafi.com", - "neimanmarcus.com", - "yabancidiziizle1.com", - "globalewallet.com", - "beeline.ru", - "hinkhoj.com", - "sitemeter.com", - "almesryoon.com", - "localmoxie.com", - "grotal.com", - "knowyourmeme.com", - "qiwi.ru", - "yieldmanager.com", - "yimg.com", - "horoscopedays.com", - "gfy.com", - "mxtoolbox.com", - "searchgol.com", - "inquirer.net", - "hollywoodlife.com", - "ebrun.com", - "shopbop.com", - "mysmartprice.com", - "kijiji.it", - "visual.ly", - "mop.com", - "1fichier.com", - "prlog.org", - "xjtour.com", - "shorouknews.com", - "thegioinet.net", - "hln.be", - "enom.com", - "thaqafnafsak.com", - "wahuu.com", - "ganji.com", - "russianpost.ru", - "myplaycity.com", - "dzone.com", - "dns-shop.ru", - "aif.ru", - "ssisurveys.com", - "uploadboy.com", - "madpandatv.net", - "pcauto.com.cn", - "meinestadt.de", - "tasnimnews.com", - "rockettheme.com", - "imesh.com", - "home.pl", - "lindaikeji.blogspot.com", - "zamunda.net", - "with2.net", - "calameo.com", - "myonlinearcade.com", - "xcams.com", - "unicredit.it", - "clip2net.com", - "mediatemple.net", - "nosub.tv", - "click.in", - "alluc.to", - "thestar.com.my", - "niksalehi.com", - "lastampa.it", - "itv.com", - "hihi2.com", - "digitalocean.com", - "tripadvisor.fr", - "willhaben.at", - "laodong.com.vn", - "591hx.com", - "tineye.com", - "ptt.cc", - "beatport.com", - "infoseek.co.jp", - "avangate.com", - "indiaproperty.com", - "books.com.tw", - "nj.com", - "avaaz.org", - "wikitravel.org", - "direct.gov.uk", - "wangtu.com", - "discover.com", - "slon.ru", - "startpage.com", - "thestar.com", - "meishichina.com", - "finanzen.net", - "estadao.com.br", - "indeed.co.uk", - "expansion.com", - "irpopup.ir", - "arvixe.com", - "secureinternetbank.com", - "csmonitor.com", - "carwale.com", - "mtime.com", - "ceconline.com", - "abchina.com", - "cgbchina.com.cn", - "mediotiempo.com", - "vic.gov.au", - "cnbeta.com", - "alarab.net", - "vietnamnet.vn", - "gay.com", - "watchmygf.net", - "myanimelist.net", - "bannersbroker.com", - "asklaila.com", - "heureka.cz", - "grepolis.com", - "meteofrance.com", - "bol.com", - "hasoffers.com", - "bigrock.in", - "ibanking-services.com", - "nos.nl", - "google.com.gh", - "beppegrillo.it", - "nhaccuatui.com", - "hamariweb.com", - "wikiquote.org", - "evite.com", - "jobdiagnosis.com", - "17track.net", - "baixing.com", - "awempire.com", - "healthgrades.com", - "unifiedlayer.com", - "thisav.com", - "himado.in", - "zcool.com.cn", - "tsn.ca", - "atlassian.net", - "binary500.com", - "alotporn.com", - "dnaindia.com", - "sherdog.com", - "www.nhs.uk", - "gruposantander.es", - "quantcast.com", - "usearchmedia.com", - "merchantcircle.com", - "blog.hu", - "wallstcheatsheet.com", - "iptorrents.com", - "apsense.com", - "redirsvc.com", - "indiarailinfo.com", - "mobile.ir", - "xvideo-jp.com", - "boxofficemojo.com", - "scamadviser.com", - "rotapost.ru", - "someecards.com", - "mydealz.de", - "lvye.cn", - "videoweed.es", - "xlovecam.com", - "pepperjamnetwork.com", - "khabarpu.com", - "mathrubhumi.com", - "online-convert.com", - "b92.net", - "tiptopsoft.org", - "el-balad.com", - "qihoo.com", - "iheart.com", - "campaign-archive1.com", - "photodune.net", - "labnol.org", - "kotobank.jp", - "medium.com", - "google.lu", - "tm1111.com", - "gigazine.net", - "mypcbackup.com", - "instantcheckmate.com", - "seemorgh.com", - "topky.sk", - "puu.sh", - "aeriagames.com", - "whatismyip.com", - "rising.cn", - "scotiabank.com", - "wo.com.cn", - "yootheme.com", - "channel4.com", - "heavy-r.com", - "omgpm.com", - "milli.az", - "bnpparibas.net", - "vmware.com", - "diretta.it", - "skycn.com", - "sap.com", - "zyalt.livejournal.com", - "bookryanair.com", - "kkbox.com", - "subtitleseeker.com", - "abckj123.com", - "mashreghnews.ir", - "websitewelcome.com", - "2ch-c.net", - "health.com", - "uproxx.com", - "uast.ac.ir", - "bol.uol.com.br", - "feedsportal.com", - "ip-adress.com", - "sedty.com", - "ilsistemabinario.com", - "nabble.com", - "hightail.com", - "superjob.ru", - "tokyo.jp", - "hrblock.com", - "china.cn", - "tsetmc.com", - "unfranchise.com.tw", - "bhg.com", - "htmlbook.ru", - "stardoll.com", - "crictime.com", - "hsn.com", - "royalmail.com", - "globallshare.com", - "wikiwiki.jp", - "petardas.com", - "usembassy.gov", - "rakuten-bank.co.jp", - "golem.de", - "stepstone.de", - "aucfan.com", - "stubhub.com", - "rbcdaily.ru", - "ro2.biz", - "huffingtonpost.ca", - "timeout.com", - "digitalspy.co.uk", - "foreningssparbanken.se", - "autodesk.com", - "98ia.com", - "gtbank.com", - "runetki.com", - "freshdesk.com", - "ieee.org", - "getpocket.com", - "jutarnji.hr", - "caisse-epargne.fr", - "profitcentr.com", - "51.com", - "oi.com.br", - "sina.com.tw", - "fontspace.com", - "dynamicdrive.com", - "maduradas.com", - "ligtv.com.tr", - "sport24.gr", - "stargazete.com", - "bola.net", - "template-help.com", - "codecademy.com", - "officedepot.com", - "researchgate.net", - "17u.com", - "gfxtra.com", - "weiphone.com", - "shoutmeloud.com", - "hc360.com", - "lintas.me", - "mk.ru", - "wplocker.com", - "thumbtack.com", - "szn.cz", - "yatra.com", - "societegenerale.fr", - "wyborcza.pl", - "demotywatory.pl", - "thomann.de", - "imperiaonline.org", - "magento.com", - "skillpages.com", - "cam4ads.com", - "spiceworks.com", - "homestead.com", - "locanto.in", - "hotelurbano.com", - "sinaimg.cn", - "chetxia.com", - "menshealth.com", - "ideacellular.com", - "snopes.com", - "newgrounds.com", - "autosottocosto.com", - "admob.com", - "linguee.fr", - "net-a-porter.com", - "text.ru", - "sharebeast.com", - "televisionfanatic.com", - "netlog.com", - "lufthansa.com", - "ngoisao.net", - "3911.net", - "worldssl.net", - "rabobank.nl", - "lvmama.com", - "sharethis.com", - "sambaporno.com", - "mci.ir", - "inosmi.ru", - "joyreactor.cc", - "cartfill.in", - "cooltext.com", - "qz.com", - "onthe.io", - "citilink.ru", - "apartmenttherapy.com", - "lloydsbank.com", - "metroer.com", - "koyotesoft.com", - "subdivx.com", - "alriyadh.com", - "backlinkwatch.com", - "coindesk.com", - "porntube1.xxx", - "zovi.com", - "thestreet.com", - "rtbstream.com", - "etnet.com.hk", - "creditkarma.com", - "lifebuzz.com", - "opodo.co.uk", - "developpez.net", - "tinydeal.com", - "nature.com", - "oxforddictionaries.com", - "anchorfree.net", - "tn.com.ar", - "findicons.com", - "joomlart.com", - "hmrc.gov.uk", - "btc-e.com", - "extra.com.br", - "ad.nl", - "megafon.ru", - "qafqazinfo.az", - "shahvani.com", - "googlecode.com", - "milliyet.tv", - "deadline.com", - "grindtv.com", - "logitech.com", - "nzherald.co.nz", - "ninisite.com", - "webgains.com", - "oschina.net", - "webmasters.ru", - "filmix.net", - "seowhy.com", - "met-art.com", - "discart.ru", - "keywordblocks.com", - "vodly.to", - "redvak.com", - "tomshardware.co.uk", - "2shared.com", - "zoznam.sk", - "icims.com", - "virtapay.com", - "blomaga.jp", - "wasu.cn", - "carsensor.net", - "sportsdirect.com", - "uservoice.com", - "livescience.com", - "gamebase.com.tw", - "persiangig.com", - "livesmi.com", - "eharmony.com", - "banorte.com", - "radiojavan.com", - "startv.com.tr", - "coolmath-games.com", - "downloadquick.net", - "worldoftanks.eu", - "filelist.ro", - "fontsquirrel.com", - "superpages.com", - "yolasite.com", - "funnie.st", - "51cto.com", - "goo-net.com", - "builtwith.com", - "shaparak.ir", - "nuomi.com", - "omegle.com", - "poringa.net", - "lan.com", - "desi-tashan.com", - "shabdkosh.com", - "freedigitalphotos.net", - "betradar.com", - "womenshealthmag.com", - "realsimple.com", - "maxbounty.com", - "bbva.es", - "sweetpacks.com", - "pinoy-ako.info", - "jobstreet.com", - "cafe24.com", - "goldenbirds.biz", - "anandtech.com", - "mapion.co.jp", - "rawstory.com", - "streamate.com", - "celebuzz.com", - "freepornvs.com", - "divyabhaskar.co.in", - "lifehack.org", - "holidaycheck.de", - "quizlet.com", - "zhibo8.cc", - "askmefast.com", - "manageflitter.com", - "campaign-archive2.com", - "cityheaven.net", - "uniqlo.com", - "seoclerks.com", - "tecmundo.com.br", - "the-binary-options-guide.com", - "gigaom.com", - "mywot.com", - "playcast.ru", - "tatadocomo.com", - "csfd.cz", - "ganool.com", - "kaschpo.ru", - "webdunia.com", - "philly.com", - "doctoroz.com", - "jumei.com", - "poponclick.com", - "rueducommerce.fr", - "fararu.com", - "po.st", - "nextag.com", - "manhunt.net", - "sistrix.com", - "woman.ru", - "appbank.net", - "iobit.com", - "joins.com", - "vidtomp3.com", - "un.org", - "volusion.com", - "lipsum.com", - "afkarnews.ir", - "goldenline.pl", - "clickansave.net", - "softgozar.com", - "thefind.com", - "mozzi.com", - "wenxuecity.com", - "up2c.com", - "searchfunmoods.com", - "cabelas.com", - "coffetube.com", - "otto.de", - "webalta.ru", - "tataindicom.com", - "ctvnews.ca", - "inlinkz.com", - "kajabi.com", - "greatergood.com", - "whmcs.com", - "telekom.de", - "christianpost.com", - "fiducia.de", - "bancsabadell.com", - "pirateproxy.net", - "woobox.com", - "google.cm", - "noulinx.com", - "nick.com", - "moviehuts.com", - "mvideo.ru", - "couchtuner.eu", - "wyborcza.biz", - "tradeindia.com", - "girlsgogames.com", - "healthcare.gov", - "videolan.org", - "sky.it", - "tuniu.com", - "ime.nu", - "n4g.com", - "cyberforum.ru", - "justin.tv", - "createspace.com", - "joemonster.org", - "registro.br", - "elkhabar.com", - "open24news.tv", - "irr.ru", - "sanjesh.org", - "standardbank.co.za", - "neogaf.com", - "doyo.cn", - "am15.net", - "ana.co.jp", - "amd.com", - "gidonlinekino.com", - "sitetalk.com", - "nesn.com", - "arabseed.com", - "ingbank.pl", - "webpronews.com", - "saavn.com", - "yourdictionary.com", - "mobile9.com", - "jagranjosh.com", - "www.net.cn", - "computerbase.de", - "3djuegos.com", - "htc.com", - "the-binary-theorem.com", - "google.com.np", - "n11.com", - "vivastreet.com", - "mthai.com", - "seomastering.com", - "mercadolibre.cl", - "searchmetrics.com", - "mentalfloss.com", - "russia.tv", - "ubi.com", - "dwnews.com", - "ecplaza.net", - "trafficfactory.biz", - "loopnet.com", - "refinery29.com", - "minecraftforum.net", - "moviefone.com", - "bom.gov.au", - "google.com.bh", - "eltiempo.es", - "cuantarazon.com", - "2258.com", - "google.ee", - "nwolb.com", - "bezaat.com", - "eelly.com", - "icmwebserv.com", - "techsmith.com", - "timeweb.ru", - "johnlewis.com", - "independent.ie", - "bankia.es", - "dkb.de", - "gilt.com", - "duolingo.com", - "3file.info", - "cam4.de.com", - "pcanalysis.net", - "br.de", - "vodlocker.com", - "adfoc.us", - "ymlp.com", - "dailyfx.com", - "business2community.com", - "banki.ru", - "yell.com", - "smartresponder.ru", - "yaske.to", - "bokra.net", - "mercadolibre.com", - "viewster.com", - "recipesfinder.com", - "rei.com", - "dogpile.com", - "caf.fr", - "sbrf.ru", - "soha.vn", - "voila.fr", - "rp-online.de", - "members.webs.com", - "duvamis.com", - "nazwa.pl", - "google.com.ni", - "ilovemobi.com", - "retrogamer.com", - "blogtalkradio.com", - "utexas.edu", - "sonyentertainmentnetwork.com", - "dr.dk", - "jjwxc.net", - "service-public.fr", - "care2.com", - "musavat.com", - "h12-media.com", - "smartfren.com", - "immowelt.de", - "discuz.net", - "m1905.com", - "cas.sk", - "bitcoinwisdom.com", - "monografias.com", - "mindbodygreen.com", - "getfirebug.com", - "godlikeproductions.com", - "mydrivers.com", - "voc.com.cn", - "truecaller.com", - "livemook.com", - "i8ti.com", - "agame.com", - "kurir-info.rs", - "urbanoutfitters.com", - "shopping.uol.com.br", - "2ip.ru", - "91.com", - "banquepopulaire.fr", - "rappler.com", - "mint.com", - "jz123.cn", - "zurb.com", - "sport.cz", - "justunfollow.com", - "billionuploads.com", - "thaivisa.com", - "seitwert.de", - "ciudad.com.ar", - "archdaily.com", - "jalopnik.com", - "1news.az", - "dailyfinance.com", - "okitspace.com", - "dn.se", - "el-nacional.com", - "larousse.fr", - "mojo-themes.com", - "draugiem.lv", - "teamtreehouse.com", - "xiu.com", - "ennaharonline.com", - "oricon.co.jp", - "openoffice.org", - "tny.cz", - "forumfree.it", - "youthwant.com.tw", - "khamsat.com", - "vitacost.com", - "alrakoba.net", - "marmiton.org", - "yebhi.com", - "the-binary-trader.biz", - "dominos.com", - "dice.com", - "like4like.org", - "tvmuse.com", - "standardchartered.com", - "bitbucket.org", - "driveropti.net", - "google.hn", - "indiblogger.in", - "torrenthound.com", - "wolframalpha.com", - "experienceproject.com", - "nsw.gov.au", - "olx.pt", - "sciencedaily.com", - "viglink.com", - "plala.or.jp", - "sxsw.com", - "mileroticos.com", - "namejet.com", - "1hai.cn", - "skroutz.gr", - "bilibili.tv", - "travelzoo.com", - "saksfifthavenue.com", - "get-a-fuck-tonight.com", - "barclaycardus.com", - "withgoogle.com", - "whitehouse.gov", - "oprah.com", - "fishwrapper.com", - "softbank.jp", - "slutload.com", - "latercera.cl", - "100bestbuy.com", - "nur.kz", - "topit.me", - "computerhope.com", - "snob.ru", - "rackcdn.com", - "3158.cn", - "artlebedev.ru", - "yobt.com", - "rai.it", - "hs.fi", - "tinhte.vn", - "fotocasa.es", - "nyu.edu", - "dawn.com", - "series.ly", - "movshare.net", - "fineartamerica.com", - "westernunion.com", - "leaseweb.com", - "wayn.com", - "ivi.ru", - "bloomingdales.com", - "pons.com", - "rapidtrk.com", - "bama.ir", - "hackforums.net", - "dfiles.eu", - "intercambiosvirtuales.org", - "sdo.com", - "homes.com", - "colissimo.fr", - "discuss.com.hk", - "afreeca.com", - "rbc.ua", - "novamov.com", - "jungle.gr", - "iol.co.za", - "btcclicks.com", - "mapsofindia.com", - "propellerads.com", - "fab.com", - "princeton.edu", - "reliancebroadband.co.in", - "xdf.cn", - "mako.co.il", - "protothema.gr", - "booloo.com", - "livrariasaraiva.com.br", - "efukt.com", - "acrobat.com", - "globovision.com", - "xero.com", - "sevenforums.com", - "semalt.com", - "audiojungle.net", - "e1.ru", - "quoka.de", - "chinaiiss.com", - "gonzoxxxmovies.com", - "wallpaperswide.com", - "fapvid.com", - "trk4.com", - "forosdelweb.com", - "fark.com", - "my.tv.sohu.com/user/video", - "kaixin001.com", - "ntvspor.net", - "mobafire.com", - "zigwheels.com", - "filmifullizle.com", - "8tracks.com", - "readmanga.eu", - "lelong.com.my", - "planetromeo.com", - "192.com", - "republika.co.id", - "in.gr", - "televisao.uol.com.br", - "kalerkantho.com", - "usairways.com", - "malaysiakini.com", - "anonymouse.org", - "xxxhost.me", - "stuff.co.nz", - "dek-d.com", - "bbvanet.com.mx", - "watchseries-online.eu", - "malaysiaairlines.com", - "policymic.com", - "serviporno.com", - "aprod.hu", - "gelocal.it", - "tradetracker.com", - "cibc.com", - "umich.edu", - "smartshe.com", - "sony.jp", - "taobaocdn.com", - "bestgfx.biz", - "irib.ir", - "aliimg.com", - "esuteru.com", - "healthline.com", - "cnnamador.com", - "sat.gob.mx", - "childsafedownloadx.asia", - "playmillion.com", - "strawberrynet.com", - "alnilin.com", - "trustedreviews.com", - "21cn.com", - "persianv.com", - "baomoi.com", - "firestorage.jp", - "google.co.ke", - "admaimai.com", - "sbnlife.com", - "surveyrouter.com", - "megaindex.ru", - "intodns.com", - "yiqifa.com", - "mixcloud.com", - "softonic.fr", - "bakecaincontrii.com", - "payu.in", - "rakuten-card.co.jp", - "almaany.com", - "grantland.com", - "ricardo.ch", - "heavy.com", - "niusnews.com", - "canstockphoto.com", - "acunn.com", - "diythemes.com", - "canalrcnmsn.com", - "ngs.ru", - "rassd.com", - "groupon.co.in", - "depositfiles.org", - "mango.com", - "theregister.co.uk", - "worldfree4u.com", - "f-lite.ru", - "boingboing.net", - "bangbros.com", - "neteller.com", - "tonicmovies.com", - "p2up.ir", - "cartoonnetwork.com", - "lun.com", - "nk.pl", - "webry.info", - "burningcamel.com", - "mplife.com", - "nationalreview.com", - "williamhill.es", - "sssc.cn", - "col3negoriginal.lk", - "yoast.com", - "svyaznoy.ru", - "chengdu.cn", - "listverse.com", - "lastminute.com", - "guardianlv.com", - "39yst.com", - "bahseazad.ir", - "debian.org", - "tokyo-porn-tube.com", - "ilbe.com", - "upsocl.com", - "balatarin.com", - "charter97.org", - "wpexplorer.com", - "immi.gov.au", - "yokamen.cn", - "esmas.com", - "hbr.org", - "livechatinc.com", - "crazyegg.com", - "palcomp3.com", - "calottery.com", - "wistia.com", - "locaweb.com.br", - "techspot.com", - "bit.ly", - "yammer.com", - "uscis.gov", - "bramjnet.com", - "linio.com.mx", - "tharunaya.co.uk", - "desirulez.net", - "madmimi.com", - "everydayhealth.com", - "secondlife.com", - "ceskatelevize.cz", - "enter.ru", - "glopart.ru", - "woso.cn", - "pitlap.info", - "worldoftanks.com", - "videarn.com", - "dafiti.com.br", - "segundamano.mx", - "eamroomsnacks.com", - "vulture.com", - "humblebundle.com", - "rockstargames.com", - "wsodownloads.info", - "yazete.com", - "pcadvisor.co.uk", - "07073.com", - "modcloth.com", - "attracta.com", - "iol.pt", - "travideos.com", - "sparkpeople.com", - "rankingsandreviews.com", - "entekhab.ir", - "goarticles.com", - "wonderhowto.com", - "kankanews.com", - "rzb.ir", - "p30download.com", - "infojobs.it", - "socialspark.com", - "picstopin.com", - "celebritynetworth.com", - "tweakers.net", - "gi-backoffice.com", - "isbank.com.tr", - "qiyou.com", - "templatic.com", - "cyberpresse.ca", - "consumerreports.org", - "focalprice.com", - "linkpad.ru", - "svd.se", - "desitvforum.net", - "bulbagarden.net", - "showup.tv", - "webgozar.com", - "3dnews.ru", - "spyfu.com", - "bikhir.ma", - "trovaprezzi.it", - "autov.com.cn", - "podnapisi.net", - "tocmai.ro", - "realitatea.net", - "geico.com", - "joydownload.com", - "kddi.com", - "unbounce.com", - "meb.gov.tr", - "anchorfree.us", - "gumtree.pl", - "dbs.com", - "ebayimg.com", - "ptcsolution.com", - "clip.dj", - "samplicio.us", - "47news.jp", - "todo1.com", - "anspress.com", - "24sata.hr", - "cineblog01.tv", - "sport-fm.gr", - "unetenet.com", - "tenki.jp", - "jia.com", - "filefactory.com", - "onedio.com", - "gendai.net", - "nickjr.com", - "finviz.com", - "bytes.com", - "inkthemes.com", - "oriflame.com", - "aporrea.org", - "mazika2day.com", - "baimao.com", - "logme.in", - "downloadactivate.com", - "vista.ir", - "duowan.com", - "sinaapp.com", - "proceso.com.mx", - "xxxconnect.com", - "dvdvideosoft.com", - "nomorerack.com", - "almubasher.com.sa", - "afisha.ru", - "clicksure.com", - "11st.co.kr", - "turkishairlines.com", - "freekaamaal.com", - "findwide.com", - "sbisec.co.jp", - "mythemeshop.com", - "webnode.com", - "cumhuriyet.com.tr", - "morningstar.com", - "trafficshop.com", - "gopro.com", - "jeevansathi.com", - "dasoertliche.de", - "markets.com", - "absa.co.za", - "ikman.lk", - "fmworld.net", - "hyatt.com", - "virgin-atlantic.com", - "tfl.gov.uk", - "immonet.de", - "haodf.com", - "thewrap.com", - "appgame.com", - "hdwallpapers.in", - "canon.com", - "newsle.com", - "jorudan.co.jp", - "pcwelt.de", - "coinbase.com", - "yourgirlfriends.com", - "djmaza.info", - "findagrave.com", - "lainformacion.com", - "teacup.com", - "ezilon.com", - "redbubble.com", - "guru.com", - "brothersoft.com", - "coinmarketcap.com", - "mediabistro.com", - "elfagr.org", - "glavcom.ua", - "jino.ru", - "1e100.net", - "g9g.com", - "join.me", - "ynet.com", - "news247.gr", - "rcom.co.in", - "baby.ru", - "argentglobalnetwork.com", - "hsselite.com", - "foxbusiness.com", - "cookmates.com", - "lidl.de", - "timesofindia.com", - "fakt.pl", - "bgr.com", - "ghatreh.com", - "woxikon.de", - "pontofrio.com.br", - "gizmag.com", - "signup.wordpress.com", - "tre.it", - "gardenweb.com", - "alfalfalfa.com", - "prcm.jp", - "freemail.hu", - "iteye.com", - "katproxy.com", - "kickassunblock.info", - "wisegeek.com", - "zaobao.com", - "vpsdomain4.eu", - "naij.com", - "olx.co.za", - "mihanstore.org", - "gezinti.com", - "vistaprint.in", - "dastelefonbuch.de", - "blackhatteam.com", - "yummly.com", - "minecraft.net", - "justcloud.com", - "biblehub.com", - "argentinawarez.com", - "gandul.info", - "trialpay.com", - "paruvendu.fr", - "khanacademy.org", - "topsy.com", - "angelfire.com", - "nseindia.com", - "seositecheckup.com", - "hostelworld.com", - "zalukaj.tv", - "animeflv.net", - "laptopmag.com", - "tripadvisor.de", - "sec.gov", - "tripadvisor.es", - "oreilly.com", - "kanald.com.tr", - "halifax-online.co.uk", - "extremetracking.com", - "reimageplus.com", - "jal.co.jp", - "vuiviet.net", - "yeslibertin.com", - "pichunter.com", - "empowernetwork.com/aI3zkH7s3g6tZH8TDmh8LA==", - "reforma.com", - "singlessalad.com", - "upenn.edu", - "1ting.com", - "hsbc.com.mx", - "sulia.com", - "yepporn.com", - "scrubtheweb.com", - "e-autopay.com", - "rechargeitnow.com", - "ppomppu.co.kr", - "zemtv.com", - "gofeminin.de", - "peoplestylewatch.com", - "france24.com", - "comodo.com", - "openmace.net", - "maultalk.com", - "fancy.com", - "vodafone.it", - "pokerstrategy.com", - "crunchyroll.com", - "aipai.com", - "3dcartstores.com", - "leancy.com", - "myblogguest.com", - "papajohns.com", - "tuolar.com", - "junkmail.co.za", - "nyc.gov", - "rentalcars.com", - "sovsport.ru", - "marketo.com", - "smbc.co.jp", - "yale.edu", - "pitchfork.com", - "thetoptens.com", - "joyme.com", - "linuxquestions.org", - "htmlgoodies.com", - "laredoute.fr", - "0427d7.se", - "journaldesfemmes.com", - "xici.net", - "alwafd.org", - "daniweb.com", - "mtgox.com", - "jetstar.com", - "plotek.pl", - "jobvite.com", - "adage.com", - "aukro.cz", - "ford.com", - "problogger.net", - "518.com.tw", - "blogbigtime.com", - "nieuwsblad.be", - "register.com", - "24tv.ua", - "aftenposten.no", - "weightwatchers.com", - "smartpassiveincome.com", - "radiosvoboda.org", - "web.com", - "caixin.com", - "digitalmarketer.com", - "soup.io", - "soft98.ir", - "muzofon.com", - "gao7.com", - "freefilmshd.com", - "hsbc.com", - "xhamsterhq.com", - "my.tv.sohu.com/user/reg", - "trade65.com", - "chow.com", - "google.com.kh", - "inps.it", - "seesaa.jp", - "hoovers.com", - "peru21.pe", - "sdpnoticias.com", - "schema.org", - "linode.com", - "theknot.com", - "blesk.cz", - "google.ci", - "loltrk.com", - "vod.pl", - "geenstijl.nl", - "moneymakergroup.com", - "tupaki.com", - "huvrtech.com", - "metafilter.com", - "jumia.com.ng", - "newsvine.com", - "mylant.com", - "accenture.com", - "feedjit.com", - "twipple.jp", - "getgoodlinks.ru", - "radiofarda.com", - "informador.com.mx", - "wisc.edu", - "windows.net", - "zamzar.com", - "nationalpost.com", - "epnet.com", - "naaptol.com", - "x-art.com", - "ebookbrowsee.net", - "marketingland.com", - "thedailyshow.com", - "s-oman.net", - "theme-fusion.com", - "immobiliare.it", - "allvoices.com", - "adroll.com", - "francetvinfo.fr", - "callandput.com", - "entireweb.com", - "instructure.com", - "megacinema.fr", - "djelfa.info", - "flightaware.com", - "magazineluiza.com.br", - "ighome.com", - "mature-beauty.com", - "yuku.com", - "peerfly.com", - "hardware.fr", - "dcinside.com", - "telerik.com", - "pengpeng.com", - "gazetaexpress.com", - "publico.es", - "nwsource.com", - "oneandone.co.uk", - "qoo10.sg", - "aboutus.org", - "adsupplyads.com", - "wa.gov", - "google.co.cr", - "benchmarkemail.com", - "valuedealshopper.com", - "hola.com", - "mizuhobank.co.jp", - "zzstream.li", - "kriesi.at", - "exist.ru", - "nvidia.com", - "giallozafferano.it", - "jusbrasil.com.br", - "konga.com", - "avclub.com", - "reed.co.uk", - "advertig.com", - "ripoffreport.com", - "gooddrama.net", - "pornyaz.com", - "budsgunshop.com", - "78.cn", - "livesurf.ru", - "99114.com", - "pornorama.com", - "marksandspencer.com", - "vmall.com", - "fatcow.com", - "mylife.com", - "irishtimes.com", - "medicalnewstoday.com", - "uiuc.edu", - "groupon.it", - "washington.edu", - "addictinggames.com", - "anonymz.com", - "kindgirls.com", - "jne.co.id", - "guiamais.com.br", - "lyricsfreak.com", - "uloz.to", - "tagesanzeiger.ch", - "fashionandyou.com", - "bollywoodhungama.com", - "nationwide.co.uk", - "kboing.com.br", - "python.org", - "theladbible.com", - "eurosport.com", - "webinarjam.com", - "theme.wordpress.com", - "myfxbook.com", - "allwomenstalk.com", - "ucla.edu", - "opendns.com", - "pornbb.org", - "money.pl", - "domain.com.au", - "standaard.be", - "wanelo.com", - "express.co.uk", - "exam8.com", - "zum.com", - "amtrak.com", - "boots.com", - "800notes.com", - "fabfurnish.com", - "amoureux.com", - "ebizmba.com", - "ujian.cc", - "stargames.at", - "panasonic.com", - "ge.tt", - "scout.com", - "tiexue.net", - "nanapi.jp", - "eclipse.org", - "searchquotes.com", - "wetplace.com", - "lpcloudbox300.com", - "hollyscoop.com", - "bdjobs.com", - "larepublica.pe", - "hizliresim.com", - "yepme.com", - "bitcoincharts.com", - "bsnl.co.in", - "ucwan87.net", - "tianji.com", - "hgtv.com", - "cleanfiles.net", - "moonsy.com", - "tomsguide.com", - "datpiff.com", - "net.hr", - "orange.pl", - "bankrate.com.cn", - "mafiashare.net", - "giaoduc.net.vn", - "sucuri.net", - "ringcentral.com", - "gamingwonderland.com", - "freenet.de", - "cian.ru", - "gayboystube.com", - "gog.com", - "gruenderszene.de", - "econsultancy.com", - "aktuality.sk", - "webrankstats.com", - "j-cast.com", - "popsugar.com", - "mr-guangdong.com", - "on.cc", - "jb51.net", - "lamoda.ru", - "sprashivai.ru", - "animoto.com", - "winzip.com", - "vanityfair.com", - "svt.se", - "noyapps.com", - "mnn.com", - "lancenet.com.br", - "e-monsite.com", - "gazeta.ua", - "cari.com.my", - "coub.com", - "veoh.com", - "kienthuc.net.vn", - "eldorado.ru", - "overclock.net", - "meetic.fr", - "tam.com.br", - "alfemminile.com", - "telmex.com", - "newsbomb.gr", - "funda.nl", - "netcoc.com", - "bhinneka.com", - "layalina.com", - "clubpenguin.com", - "talktalk.co.uk", - "dumpert.nl", - "almastba.com", - "clker.com", - "adweek.com", - "gigya.com", - "disponivel.uol.com.br", - "tomoson.com", - "w.org", - "rfi.fr", - "imgbox.com", - "omniture.com", - "n24.de", - "webdesignrazzi.com", - "medscape.com", - "playboy.com", - "usda.gov", - "cuevana.tv", - "trenitalia.com", - "explosm.net", - "mail.uol.com.br", - "delfi.lv", - "elektroda.pl", - "hulkshare.com", - "kotak.com", - "gi-akademie.ning.com", - "yelp.de", - "lrytas.lt", - "couchsurfing.org", - "drugstore.com", - "ssa.gov", - "seriescoco.com", - "iran-tejarat.com", - "hafiz.gov.sa", - "intellicast.com", - "sub.jp", - "paginasamarillas.es", - "anime44.com", - "babyschool.com.cn", - "advertisernets.com", - "vpsdomain2.eu", - "arcor.de", - "video2mp3.net", - "marthastewart.com", - "hawahome.com", - "articlesbase.com", - "spanishdict.com", - "meilishuo.com", - "grammarly.com", - "sportlemon.tv", - "zend.com", - "bigideamastermind.com", - "hawaaworld.com", - "pagseguro.uol.com.br", - "keywordspy.com", - "7search.com", - "cnki.net", - "aamaadmiparty.org", - "javaplayer.info", - "sidereel.com", - "azcentral.com", - "passportindia.gov.in", - "memurlar.net", - "bouyguestelecom.fr", - "buenastareas.com", - "ernmoneynow.com", - "eurosport.ru", - "blog.163.com", - "pizzahut.com", - "bossip.com", - "webdeveloper.com", - "add-anime.net", - "pimptubed.com", - "movistar.es", - "megashare.sh", - "empireavenue.com", - "btemplates.com", - "amkspor.com", - "payza.com", - "farfesh.com", - "mcgraw-hill.com", - "motor-talk.de", - "purepeople.com", - "i-gamer.net", - "sotmarket.ru", - "anthropologie.com", - "google.org", - "rai.tv", - "wikidot.com", - "canoe.ca", - "orange.es", - "umn.edu", - "emag.ro", - "webutations.org", - "ykb.com", - "canadapost.ca", - "zhubajie.com", - "nextcar.cn", - "next.co.uk", - "freemovie-hd.com", - "telegraf.com.ua", - "ajc.com", - "xsrv.jp", - "vanguard.com", - "mybroadband.co.za", - "999120.net", - "panet.co.il", - "bellemaison.jp", - "fonearena.com", - "playvid.com", - "purdue.edu", - "thesuperficial.com", - "114so.cn", - "irna.ir", - "websitetonight.com", - "edublogs.org", - "provincial.com", - "jahaniha.com", - "heroturko.me", - "dynadot.com", - "txtsrving.info", - "adclickxpress.com", - "sammobile.com", - "ebay.at", - "yaplog.jp", - "imtranslator.net", - "fotor.com", - "myvidster.com", - "williamhill.it", - "argaam.com", - "zoomby.ru", - "tcsbank.ru", - "origin.com", - "vov.vn", - "wrapbootstrap.com", - "imvu.com", - "fbsbx.com", - "elcorteingles.es", - "cerdas.com", - "google.com.om", - "dramasonline.com", - "businesswire.com", - "serpbook.com", - "santanderrio.com.ar", - "meta.ua", - "kenhgioitre.com", - "watchcartoononline.com", - "athome.co.jp", - "2checkout.com", - "moheet.com", - "jeu.info", - "ankieta-online.pl", - "triberr.com", - "wordtracker.com", - "blogher.com", - "colourlovers.com", - "maalaimalar.com", - "bakeca.it", - "thepostgame.com", - "beget.ru", - "abebooks.com", - "certified-toolbar.com", - "publico.pt", - "footmercato.net", - "indiabix.com", - "zakzak.co.jp", - "hotfile.com", - "virustotal.com", - "usgs.gov", - "tukif.com", - "banglamail24.com", - "graphicstock.com", - "svpressa.ru", - "sanalpazar.com", - "logsoku.com", - "loteriasyapuestas.es", - "youjizzlive.com", - "all-inkl.com", - "arcot.com", - "blogspot.fi", - "inbox.lv", - "anno-online.com", - "tikona.in", - "newsru.ua", - "centerblog.net", - "jahannews.com", - "joxi.ru", - "proxybay.eu", - "2gis.ru", - "indeed.fr", - "novayagazeta.ru", - "intelius.com", - "hosteurope.de", - "autoscout24.it", - "postjoint.com", - "pulsk.com", - "biobiochile.cl", - "homevv.com", - "zapbux.com", - "gsp.ro", - "priyo.com", - "jamnews.ir", - "addtoany.com", - "lookbook.nu", - "e-travel.com", - "themelock.com", - "bestsocialfeed.com", - "eqla3.com", - "klm.com", - "realtor.ca", - "tv2.no", - "jqueryrain.com", - "seo-fast.ru", - "academic.ru", - "clicksia.com", - "lpcloudbox30.com", - "worldpay.com", - "gogoanime.com", - "photoshelter.com", - "mlive.com", - "wetteronline.de", - "jkforum.net", - "secure.ipage.com", - "antena3.com", - "elsevier.com", - "thaiseoboard.com", - "addic7ed.com", - "rookee.ru", - "jstor.org", - "rajanews.com", - "uline.com", - "o2online.de", - "fbdownloader.com", - "wetpaint.com", - "nnm.me", - "50onred.com", - "tvtropes.org", - "philips.com", - "watchseries.to", - "perfectinter.net", - "progressive.com", - "stcn.com", - "golsearch.com", - "sarayanews.com", - "screenrant.com", - "macworld.com", - "classifiedads.com", - "ip138.com", - "izlesene.com", - "ovguide.com", - "gametop.com", - "urlm.co", - "isitdownrightnow.com", - "redhat.com", - "stafaband.info", - "biglion.ru", - "twitterfeed.com", - "ttnet.com.tr", - "panasonic.jp", - "loc.gov", - "telstra.com.au", - "jiathis.com", - "perfil.com.ar", - "inquisitr.com", - "ratp.fr", - "libertaddigital.com", - "bni.co.id", - "ycombinator.com", - "paginegialle.it", - "momoshop.com.tw", - "theweek.com", - "tuoitre.vn", - "scriptmafia.org", - "megavod.fr", - "indiavisiontv.com", - "history.com", - "flyeralarm.com", - "salespider.com", - "ard.de", - "dslreports.com", - "tokyo-tube.com", - "brazzersnetwork.com", - "bonanza.com", - "storenvy.com", - "37signals.com", - "jxnews.com.cn", - "1sale.com", - "allanalpass.com", - "yiiframework.com", - "kimsufi.com", - "nastygal.com", - "immoral.jp", - "icq.com", - "loxblog.com", - "jcrew.com", - "diamond.jp", - "nissen.co.jp", - "fxstreet.com", - "15min.lt", - "lifo.gr", - "alef.ir", - "iis.net", - "giphy.com", - "mypopup.ir", - "bsnl.in", - "distractify.com", - "foro20.com", - "chachaba.com", - "fx-trend.com", - "imanhua.com", - "playxn.com", - "gocomics.com", - "lcl.fr", - "hsw.cn", - "ellislab.com", - "persiantools.com", - "coupondunia.in", - "fengniao.com", - "coinmill.com", - "freelancer.in", - "blogdetik.com", - "data.com", - "trafficjunky.net", - "neverblue.com", - "flvto.com", - "lijit.com", - "zaycev.net", - "salamnews.org", - "siliconrus.com", - "dv37.com", - "conrad.de", - "ascii.jp", - "yesfreeporn.com", - "globalpost.com", - "d4000.com", - "dobreprogramy.pl", - "hammihan.com", - "wjunction.com", - "liverpoolfc.tv", - "nordea.fi", - "mail2web.com", - "songkick.com", - "comicbookresources.com", - "jwplayer.com", - "moi.gov.sa", - "iranecar.com", - "kayako.com", - "listal.com", - "technet.com", - "infonews.com", - "fun698.com", - "frys.com", - "vectorstock.com", - "vbox7.com", - "leroymerlin.fr", - "gpotato.eu", - "gulfnews.com", - "hot-sex-tube.com", - "buzzle.com", - "uludagsozluk.com", - "onlinefastpaydayloan.com", - "forumcommunity.net", - "potins.net", - "bwin.es", - "lobstertube.com", - "katestube.com", - "endomondo.com", - "navalny.livejournal.com", - "wayport.net", - "dealspl.us", - "pixhost.org", - "webopedia.com", - "flagcounter.com", - "hotnewhiphop.com", - "matomy.com", - "privat24.ua", - "fuq.com", - "readserver.net", - "haiwainet.cn", - "light-dark.net", - "decolar.com", - "tlbb8.com", - "tomtom.com", - "fontanka.ru", - "tchibo.de", - "slutfinder.com", - "rbc.cn", - "pepperfry.com", - "freshersworld.com", - "mob.org", - "brobible.com", - "phim3s.net", - "parsiblog.com", - "link-assistant.com", - "smotri.com", - "flyertalk.com", - "iefimerida.gr", - "pornyeah.com", - "trustpilot.com", - "wowslider.com", - "sekindo.com", - "shape.com", - "pizap.com", - "bluedart.com", - "cmu.edu", - "shueisha.co.jp", - "royal-search.com", - "123greetings.com", - "albawabhnews.com", - "holiday-weather.com", - "4travel.jp", - "lpcloudsvr203.com", - "panorama.com.ve", - "htcmania.com", - "skorer.tv", - "mymovies.it", - "fileice.net", - "1and1.fr", - "legiaodosherois.com.br", - "tomsguide.fr", - "baymirror.com", - "thesun.co.uk", - "huffingtonpost.es", - "61baobao.com", - "juegos.com", - "joyclub.de", - "qatarairways.com", - "ayosdito.ph", - "translate.ru", - "yithemes.com", - "buyvip.com", - "pearltrees.com", - "thinkprogress.org", - "twitcasting.tv", - "lusongsong.com", - "irecommend.ru", - "aukro.ua", - "eldiario.es", - "pop-music.ir", - "libertytimes.com.tw", - "themalaysianinsider.com", - "paddypower.it", - "delfi.ee", - "appthemes.com", - "tdameritrade.com", - "flashback.org", - "tubelib.com", - "claro.com.br", - "jotform.com", - "bigresource.com", - "libsyn.com", - "sendgrid.com", - "silikonvadisi.tv", - "geo.tv", - "pricegrabber.com", - "futhead.com", - "testberichte.de", - "skybet.com", - "wpcentral.com", - "lesnumeriques.com", - "clientoo.com", - "mathsisfun.com", - "expert.ru", - "maxptp.com", - "mediaite.com", - "regions.com", - "fast-torrent.ru", - "enlacespepito.com", - "redtram.com", - "benesse.ne.jp", - "jappy.de", - "wizzair.com", - "adevarul.ro", - "mhlw.go.jp", - "dev-point.com", - "ibtimes.co.in", - "coinwarz.com", - "slidesharecdn.com", - "classmates.com", - "tsite.jp", - "niazerooz.com", - "jma.go.jp", - "motherjones.com", - "easports.com", - "elbotola.com", - "tripadvisor.com.au", - "rozee.pk", - "vivanuncios.com.mx", - "lashou.com", - "theaustralian.com.au", - "superstarmagazine.com", - "zedge.net", - "hardwarezone.com.sg", - "yyets.com", - "nowgamez.com", - "blogspot.ch", - "gq.com", - "adidas.com", - "uyan.cc", - "dailydot.com", - "xenforo.com", - "ilmessaggero.it", - "state.nj.us", - "16888.com", - "searchengines.guru", - "nascar.com", - "dnb.no", - "smosh.com", - "shinyinnovation.com", - "who.int", - "mybet.com", - "yoo7.com", - "xrea.com", - "fotolog.net", - "smartprix.com", - "esquire.com", - "google.com.cy", - "santander.com.br", - "realclearpolitics.com", - "financereports24.com", - "onlinesoccermanager.com", - "noticiaaldia.com", - "kelkoo.com", - "drakulastream.eu", - "vodafone.de", - "bt.dk", - "greenwichmeantime.com", - "ufc.com", - "webstatsdomain.org", - "taoche.com", - "thinkgeek.com", - "caranddriver.com", - "123-reg.co.uk", - "translit.ru", - "w3school.com.cn", - "zwinky.com", - "inboxdollars.com", - "gratka.pl", - "vecernji.hr", - "taikang.com", - "bolshoyvopros.ru", - "urbita.com", - "api.ning.com", - "alltop.com", - "readwrite.com", - "medhelp.org", - "totaljobs.com", - "accorhotels.com", - "prom.ua", - "cuny.edu", - "livemint.com", - "berlin.de", - "blogspot.hk", - "orkut.com.br", - "lzjl.com", - "metric-conversions.org", - "nationalrail.co.uk", - "oxu.az", - "mql5.com", - "chinaluxus.com", - "linguee.es", - "saudiairlines.com", - "standardmedia.co.ke", - "alkislarlayasiyorum.com", - "apk.tw", - "lesoir.be", - "whatculture.com", - "indiewire.com", - "pccomponentes.com", - "paytm.in", - "ebaypartnernetwork.com", - "haivl.tv", - "e-junkie.com", - "tvp.pl", - "ifilez.org", - "aristeguinoticias.com", - "bangkokpost.com", - "whatmobile.com.pk", - "prodavalnik.com", - "arsenal.com", - "buyma.com", - "torrentday.com", - "sammydress.com", - "blogcu.com", - "imore.com", - "shitaraba.com", - "pasadrexam2014.in", - "songspk.at", - "eforosh.com", - "nocoty.pl", - "koreus.com", - "verticalresponse.com", - "arte.tv", - "ocnk.net", - "cryptsy.com", - "haaretz.com", - "straitstimes.com", - "2domains.ru", - "usnetads.com", - "pracuj.pl", - "edreams.it", - "sba.gov", - "instabang.com", - "domainnamesales.com", - "teensnow.com", - "visualwebsiteoptimizer.com", - "blogos.com", - "santander.com.mx", - "solidfiles.com", - "authorstream.com", - "teslamotors.com", - "tema.livejournal.com", - "kolesa.kz", - "startribune.com", - "vevo.com", - "clien.net", - "3asq.com", - "tvnet.lv", - "mouthshut.com", - "binary-machine.com", - "adultwork.com", - "hypebeast.com", - "itrack.it", - "network-tools.com", - "brandsoftheworld.com", - "comedycentral.com", - "hotscripts.com", - "meristation.com", - "rlsbb.com", - "uzai.com", - "volkskrant.nl", - "terra.com.mx", - "howtoforge.com", - "178.com", - "wickedfire.com", - "dilandau.eu", - "seriales.us", - "xataka.com", - "hktdc.com", - "express.pk", - "surfcanyon.com", - "buildhr.com", - "ouest-france.fr", - "stltoday.com", - "alternet.org", - "site5.com", - "payserve.com", - "society6.com", - "douguo.com", - "prosieben.de", - "verywed.com", - "enikos.gr", - "tubewolf.com", - "openrice.com", - "blankrefer.com", - "gouv.qc.ca", - "torrentfreak.com", - "craveonline.com", - "unfollowers.com", - "deser.pl", - "quanjing.com", - "runetki.tv", - "yepi.com", - "socialbakers.com", - "webmotors.com.br", - "mmo-champion.com", - "globososo.com", - "whois.sc", - "sportskeeda.com", - "socialblade.com", - "jin115.com", - "avjavjav.com", - "thenewstribe.com", - "pinkrod.com", - "blox.pl", - "mediamarkt.de", - "vivo.com.br", - "facilisimo.com", - "sinarharian.com.my", - "leguide.com", - "voegol.com.br", - "j.gs", - "okgj.com", - "revolveclothing.com", - "lolinez.com", - "go2cloud.org", - "vmoptions.com", - "myip.ms", - "ay.gy", - "liquidweb.com", - "sbi.co.in", - "alamaula.com", - "reshareable.tv", - "stirileprotv.ro", - "siriusxm.com", - "banvenez.com", - "sergey-mavrodi-mmm.net", - "ocj.com.cn", - "elderscrollsonline.com", - "webaslan.com", - "dereferer.org", - "newsbeast.gr", - "778669.com", - "yeucahat.com", - "guitarcenter.com", - "mercurynews.com", - "channeladvisor.com", - "go2000.com", - "google.ge", - "pandora.tv", - "haqqin.az", - "google.tt", - "32d1d3b9c.se", - "sexdatenow.net", - "befunky.com", - "micromaxinfo.com", - "jquerymobile.com", - "radikal.ru", - "wigetmedia.com", - "girlsplay.com", - "pureleverage.com", - "mathxl.com", - "themefuse.com", - "giga.de", - "freevideo.cz", - "stylebistro.com", - "iwriter.com", - "winporn.com", - "tripadvisor.ca", - "atresplayer.com", - "igma.tv", - "ravelry.com", - "semana.com", - "verycd.com", - "sblo.jp", - "fansided.com", - "goalunited.org", - "petfinder.com", - "worthofweb.com", - "memuruz.net", - "njuskalo.hr", - "yellowpages.ca", - "91jm.com", - "webconfs.com", - "interpals.net", - "erepublik.com", - "akismet.com", - "gaadi.com", - "casasbahia.com.br", - "techsupportalert.com", - "bostonglobe.com", - "uploadable.ch", - "smartprofitsystem.com", - "cimbclicks.com.my", - "uwants.com", - "gamestar.de", - "neowin.net", - "inilah.com", - "toster.ru", - "gosuslugi.ru", - "windguru.cz", - "3366.com", - "beinsports.net", - "vector.co.jp", - "memecenter.com", - "hotnews.ro", - "webgame.web.id", - "llnw.com", - "jobstreet.co.id", - "congratulations-you-won.com", - "libertatea.ro", - "app111.com", - "scientificamerican.com", - "strava.com", - "iranjib.ir", - "coneco.net", - "fdrmx.com", - "nps.gov", - "businessinsider.in", - "uniblue.com", - "proporn.com", - "dm5.com", - "qld.gov.au", - "nexusmods.com", - "mandatory.com", - "moskva.fm", - "prosperityteam.com", - "lent.az", - "appbrain.com", - "24smi.org", - "avaxsearch.com", - "gorillavid.in", - "realgm.com", - "favicon.cc", - "astro.com", - "joomlaforum.ru", - "joystiq.com", - "computerworld.com", - "tvspielfilm.de", - "centos.org", - "bugun.com.tr", - "amctv.com", - "relianceada.com", - "papystreaming.com", - "clickindia.com", - "sayyac.com", - "q.gs", - "bravoerotica.com", - "bibsonomy.org", - "netload.in", - "shopatron.com", - "iautos.cn", - "banggood.com", - "commerzbanking.de", - "legacyclix.com", - "intesasanpaolo.com", - "awesomescreenshot.com", - "desidime.com", - "eporner.com", - "alwatanvoice.com", - "ok.ru", - "europe1.fr", - "karnaval.com", - "tornn-tv.com", - "frmtr.com", - "pulscen.ru", - "groupon.co.uk", - "tradera.com", - "comingsoon.net", - "speckyboy.com", - "cargurus.com", - "citysearch.com", - "brother.com", - "acfun.tv", - "jamejamonline.ir", - "enterprise.com", - "elotrolado.net", - "userscripts.org", - "confirmit.com", - "compete.com", - "auctiva.com", - "potterybarn.com", - "ivoox.com", - "multiupload.nl", - "glavnoe.ua", - "p30world.com", - "snapnames.com", - "filmon.com", - "flipkey.com", - "rhhbschool.com", - "worldbank.org", - "proz.com", - "docusign.net", - "akakce.com", - "empflix.com", - "androidforums.com", - "mos.ru", - "contenko.com", - "malwarebytes.org", - "voyeurhit.com", - "filmvz.com", - "windowsazure.com", - "rlslog.net", - "zulagames.com", - "onlinefinder.net", - "blekko.com", - "tvb.com", - "mojomarketplace.com", - "warnerbros.com", - "rogers.com", - "sparkasse.at", - "bigcinema.tv", - "mattcutts.com", - "vemale.com", - "pgatour.com", - "bakusai.com", - "lavozdegalicia.es", - "style.com", - "torrentino.com", - "activeden.net", - "sweetpacks-search.com", - "pcstore.com.tw", - "starmedia.com", - "lycos.com", - "uncomo.com", - "caribbeancom.com", - "googleping.com", - "sondakika.com", - "premiumwp.com", - "tribune.com.pk", - "sc.com", - "91mobiles.com", - "elle.com", - "motortrend.com", - "starsports.com", - "otlan.com", - "planetminecraft.com", - "oregonlive.com", - "publichd.se", - "financialexpress.com", - "huxiu.com", - "hotwords.com", - "asda.com", - "impiego24.it", - "tunisia-sat.com", - "xojane.com", - "shiftdelete.net", - "hamshahrionline.ir", - "mp3.es", - "minutebuzz.com", - "footlocker.com", - "rusnovosti.ru", - "defencenet.gr", - "ndr.de", - "blogosfera.uol.com.br", - "quibids.com", - "soft32.com", - "davidwalsh.name", - "blogun.ru", - "webbirga.net", - "dict.cn", - "groupon.jp", - "abovetopsecret.com", - "contra.gr", - "zn.ua", - "jetbrains.com", - "myus.com", - "redbus.in", - "creativemarket.com", - "uainfo.org", - "rtbf.be", - "forexpf.ru", - "mainlink.ru", - "fantasti.cc", - "usagc.org", - "narutoget.com", - "trendyol.com", - "carsales.com.au", - "fujitv.co.jp", - "dardarkom.com", - "corrieredellosport.it", - "mcanime.net", - "nolo.com", - "beareyes.com.cn", - "familysearch.org", - "eprice.com.tw", - "indonetwork.co.id", - "geizhals.at", - "watchfreemovies.ch", - "siweiw.com", - "elnuevoherald.com", - "codecupdaters.com", - "p1.com", - "imhonet.ru", - "spox.com", - "spreadshirt.com", - "bittorrent.com", - "airberlin.com", - "epicurious.com", - "adverstitial.com", - "researchnow.com", - "lolnexus.com", - "xbabe.com", - "designmodo.com", - "hamusoku.com", - "radioshack.com", - "teamliquid.net", - "helpster.de", - "globalsources.com", - "fasttech.com", - "dickssportinggoods.com", - "j-sen.jp", - "smashwords.com", - "adversal.com", - "musiciansfriend.com", - "whoishostingthis.com", - "ads8.com", - "trend4pay.com", - "tribune.com", - "xsrving.com", - "youngleafs.com", - "gamersky.com", - "podio.com", - "state.pa.us", - "iphoneogram.com", - "datehookup.com", - "hbs.edu", - "ally.com", - "mitbbs.com", - "siasat.pk", - "miratuserie.tv", - "active.com", - "ricardoeletro.com.br", - "html.it", - "minnano-av.com", - "meetly.in", - "denverpost.com", - "supersport.com", - "grupobancolombia.com", - "freemake.com", - "bankier.pl", - "instapaper.com", - "derwesten.de", - "blogspot.hu", - "tamindir.com", - "play.pl", - "warthunder.com", - "team-bhp.com", - "freepeople.com", - "laposte.fr", - "cnews.ru", - "fayerwayer.com", - "hitta.se", - "hao123.com.eg", - "it-ebooks.info", - "freep.com", - "newser.com", - "lexilogos.com", - "polldaddy.com", - "auspost.com.au", - "aib.ie", - "cs.com.cn", - "providesupport.com", - "unblocksit.es", - "twittercounter.com", - "luisaviaroma.com", - "imgbabes.com", - "tharunee.lk", - "nexon.com", - "airliners.net", - "srf.ch", - "angel.co", - "tokyo-sports.co.jp", - "mt5.com", - "down1oads.com", - "vodonet.net", - "axar.az", - "taknaz.ir", - "google.com.py", - "ss.lv", - "stuffgate.com", - "giveawayoftheday.com", - "climatempo.com.br", - "xnxxmovies.com", - "heartinternet.co.uk", - "digikey.com", - "zimbra.free.fr", - "line.me", - "talkingpointsmemo.com", - "dyn.com", - "exacttarget.com", - "yourtango.com", - "shopping.com", - "king.com", - "crackberry.com", - "sm3na.com", - "matchesfashion.com", - "rk.com", - "ems.com.cn", - "xiaomi.cn", - "hillnews.com", - "geforce.com", - "internetslang.com", - "theoldreader.com", - "digitaljournal.com", - "aol.co.uk", - "straightdope.com", - "farfetch.com", - "lupoporno.com", - "ilgiornale.it", - "binzhi.com", - "loveplanet.ru", - "sogi.com.tw", - "googlevideo.com", - "nintendo.com", - "jreast.co.jp", - "coinad.com", - "keek.com", - "chegg.com", - "sparknotes.com", - "mywapblog.com", - "idlebrain.com", - "boardgamegeek.com", - "daserste.de", - "nicozon.net", - "ampnetzwerk.de", - "agenziaentrate.gov.it", - "apec.fr", - "redbull.com", - "listentoyoutube.com", - "diepresse.com", - "gohappy.com.tw", - "morguefile.com", - "dallasnews.com", - "adxpansion.com", - "almos3a.com", - "updatetube.com", - "lowyat.net", - "lolipop.jp", - "terafile.co", - "eversave.com", - "sportingnews.com", - "517dv.com", - "milfmovs.com", - "myflorida.com", - "brooonzyah.net", - "cdn-cachefront.net", - "ig.com", - "indiapost.gov.in", - "hangame.co.jp", - "ithemes.com", - "monova.org", - "udmserve.net", - "impactradius.com", - "teasernet.com", - "gmx.at", - "mmotraffic.com", - "citehr.com", - "viator.com", - "rt.ru", - "japannetbank.co.jp", - "zonealarm.com", - "ebayclassifieds.com", - "safecart.com", - "proptp.net", - "51hejia.com", - "telkomsel.com", - "deutschepost.de", - "startpagina.nl", - "alexaboostup.com", - "istgah.com", - "aufreeads.com", - "thinkstockphotos.com", - "similarsitesearch.com", - "gossiplankanews.com", - "venere.com", - "javascriptkit.com", - "square-enix.com", - "tvtoday.de", - "netaffiliation.com", - "computrabajo.com.mx", - "arioo.com", - "fromdoctopdf.com", - "lookany.com", - "bleepingcomputer.com", - "perfectmoney.com", - "dorkly.com", - "macmillandictionary.com", - "fotka.pl", - "porntubevidz.com", - "rj.gov.br", - "1.1.1.1", - "ebay.be", - "divxplanet.com", - "cyworld.com", - "biography.com", - "p1.cn", - "bazos.sk", - "55.la", - "lockerdome.com", - "yola.com", - "ccbill.com", - "groupon.de", - "okazii.ro", - "izismile.com", - "velvet.hu", - "news-postseven.com", - "ardmediathek.de", - "sagawa-exp.co.jp", - "sarzamindownload.com", - "pdfonline.com", - "gaaks.com", - "azhibo.com", - "pensador.uol.com.br", - "surveygizmo.com", - "familydoctor.com.cn", - "lazada.vn", - "guokr.com", - "enjoydressup.com", - "sky.de", - "afp.com", - "imujer.com", - "livescore.net", - "xinnet.com", - "mypageresults.com", - "safaribooksonline.com", - "extremetech.com", - "ecnavi.jp", - "babyblog.ru", - "practicalecommerce.com", - "vidspot.net", - "studymode.com", - "nation.co.ke", - "cpmrocket.com", - "es.wix.com", - "google.com.cu", - "pravda.ru", - "cda.pl", - "appszoom.com", - "selfhtml.org", - "zmovie.tw", - "dba.dk", - "domain.com", - "brightcove.com", - "lol55.com", - "textsale.ru", - "casualclub.com", - "gudvin.tv", - "torrentreactor.net", - "downloadcamp.com", - "eset.com", - "softonic.it", - "internations.org", - "retre.org", - "3quan.com", - "companieshouse.gov.uk", - "hautelook.com", - "edx.org", - "ono.es", - "jango.com", - "7sur7.be", - "spinrewriter.com", - "hqxnxx.com", - "elperiodico.com", - "arabiaweather.com", - "liansuo.com", - "pcgamer.com", - "offervault.com", - "mytheresa.com", - "memegenerator.net", - "gsm.ir", - "britannica.com", - "mensfitness.com", - "flaticon.com", - "newrelic.com", - "greatmmos.com", - "ifixit.com", - "aiyellow.com", - "my.tv.sohu.com/user/card", - "ce4arab.com", - "news-us.jp", - "slando.kz", - "redflagdeals.com", - "gsmhosting.com", - "raiffeisen.at", - "tagesspiegel.de", - "epravda.com.ua", - "bell.ca", - "sleazyneasy.com", - "dhnet.be", - "webcars.com.cn", - "freepik.es", - "androidpolice.com", - "cbr.ru", - "thanhnien.com.vn", - "shoptime.com.br", - "dailytelegraph.com.au", - "fastcodesign.com", - "full-stream.net", - "google.al", - "creativecow.net", - "centrum24.pl", - "openstat.ru", - "unfollowed.me", - "brb.to", - "babal.net", - "ibotoolbox.com", - "torrentdownloads.me", - "miami.com", - "mubasher.info", - "patient.co.uk", - "ayudawordpress.com", - "makepolo.com", - "exactseek.com", - "echosign.com", - "epson.com", - "somo.vn", - "tripadvisor.jp", - "bikroy.com", - "postimees.ee", - "band.uol.com.br", - "adopteunmec.com", - "imgserve.net", - "toofab.com", - "neeu.com", - "mailjet.com", - "kinja.com", - "qwertypay.com", - "cosme.net", - "dreammovies.com", - "avvo.com", - "wenyard.com", - "dir.bg", - "digital-photography-school.com", - "peru.com", - "thomsonreuters.com", - "grazia.com.cn", - "vivastreet.co.in", - "officemax.com", - "creditmutuel.fr", - "themify.me", - "ait-themes.com", - "share-links.biz", - "graphixshare.com", - "theoutnet.com", - "revolvermaps.com", - "careers360.com", - "tyroodr.com", - "escapistmagazine.com", - "ofreegames.com", - "surveryewadcentrez.eu", - "notebookcheck.net", - "k2s.cc", - "barstoolsports.com", - "townhall.com", - "mk.co.kr", - "epochtimes.com", - "arduino.cc", - "blogcms.jp", - "udacity.com", - "habervaktim.com", - "funweek.it", - "techtunes.com.bd", - "shopzilla.com", - "sun-sentinel.com", - "tfile.me", - "novafile.com", - "eurogamer.net", - "thenewporn.com", - "tuttosport.com", - "sverve.com", - "simplemachines.org", - "nginx.org", - "kepu.com.cn", - "jxedt.com", - "southparkstudios.com", - "gusuwang.com", - "utrace.de", - "peperonity.de", - "hvg.hu", - "cairodar.com", - "mappy.com", - "kouclo.com", - "my.tv.sohu.com/user/lucky", - "lushstories.com", - "stocktwits.com", - "atlantico.fr", - "baihe.com", - "wowkeren.com", - "v7n.com", - "mozilla.com", - "centurylink.net", - "1001freefonts.com", - "pubdirecte.com", - "mercadolibre.com.pe", - "vandelaydesign.com", - "cpaelites.com", - "wanyh.com", - "propertyguru.com.sg", - "esy.es", - "torrentbutler.eu", - "final.ir", - "53.com", - "clips4sale.com", - "freerepublic.com", - "huffingtonpost.de", - "boards.ie", - "fluege.de", - "parents.com", - "gimp.org", - "adorocinema.com", - "yelp.ca", - "twicsy.com", - "kuaibo.com", - "gnu.org", - "parsine.com", - "jpc.com", - "cloudapp.net", - "expatriates.com", - "sproutsocial.com", - "natemat.pl", - "livingrichwithcoupons.com", - "x-ho.com", - "adv-adserver.com", - "downloadchop.com", - "sagepub.com", - "eleconomista.com.mx", - "formula1.com", - "quackit.com", - "dlsite.com", - "powned.tv", - "stream-tv.me", - "mindbodyonline.com", - "mindmeister.com", - "twitlonger.com", - "ebay.ie", - "deccanchronicle.com", - "domaintuno.com", - "thethirdmedia.com", - "laiguana.tv", - "flurry.com", - "eloqua.com", - "createsend.com", - "hrloo.com", - "interfax.com.ua", - "admin.ch", - "zgzcw.com", - "bancoestado.cl", - "fda.gov", - "chinayes.com", - "beslist.nl", - "crossfit.com", - "skai.gr", - "covers.com", - "antpoker.com", - "perfectworld.com", - "momdot.com", - "1c-bitrix.ru", - "feiren.com", - "navitime.co.jp", - "siliconindia.com", - "warning.or.kr", - "qatarliving.com", - "uber.com", - "ing-diba.de", - "boldsky.com", - "animeid.tv", - "tom.com", - "whatsmyserp.com", - "ftbpro.com", - "yobt.tv", - "toluna.com", - "burrp.com", - "viber.com", - "df.eu", - "vatera.hu", - "songmeanings.com", - "smbc-card.com", - "hip2save.com", - "wmzona.com", - "banamex.com", - "chinaacc.com", - "t-online.hu", - "indianpornvideos.com", - "runescape.com", - "wapka.mobi", - "115.com", - "blogspot.no", - "aksam.com.tr", - "bankcomm.com", - "giantbomb.com", - "maxcdn.com", - "topshop.com", - "livescores.com", - "rosbalt.ru", - "gandi.net", - "ioffer.com", - "mihandownload.com", - "eweb4.com", - "britishcouncil.org", - "cheetahmail.com", - "vbulletin.com", - "bradsdeals.com", - "empowernetwork.com/commissionloophole", - "vueling.com", - "raventools.com", - "yext.com", - "everychina.com", - "reduxmediia.com", - "openstreetmap.org", - "wed114.cn", - "dzwww.com", - "miibeian.gov.cn", - "ufl.edu", - "deseretnews.com", - "presstv.ir", - "copy.com", - "fourhourworkweek.com", - "buzztheme.net", - "bollywoodlife.com", - "redtubelive.com", - "pengyou.com", - "antaranews.com", - "selectornews.com", - "lavoz.com.ar", - "avm.de", - "flalottery.com", - "jmp9.com", - "baltimoresun.com", - "mozillazine.org", - "dnevnik.hr", - "aebn.net", - "mightydeals.com", - "livescore.eu", - "publipt.com", - "xbmc.org", - "scmp.com", - "sbobet.com", - "alpari.ru", - "harborfreight.com", - "linio.com.pe", - "2500sz.com", - "rdio.com", - "bearshare.com", - "thetrainline.com", - "888poker.es", - "filecrop.com", - "twiends.com", - "elnuevodia.com", - "rasekhoon.net", - "36.cn", - "axeso5.com", - "mzamin.com", - "webmastersitesi.com", - "thinkdigit.com", - "lifescript.com", - "experian.com", - "adorama.com", - "d1net.com", - "torrentz.pro", - "fullhdfilmizle.org", - "space.com", - "collider.com", - "zalando.it", - "slate.fr", - "carmax.com", - "recode.net", - "gfan.com", - "fonts.com", - "honda.com", - "ecwid.com", - "debate.com.mx", - "bmail.uol.com.br", - "santandernet.com.br", - "coderanch.com", - "lyricsmode.com", - "gametrailers.com", - "3600.com", - "designboom.com", - "131.com", - "finam.ru", - "df.gob.mx", - "85dcf732d593.se", - "coches.net", - "dhs.gov", - "neurs.com", - "poppen.de", - "public-api.wordpress.com", - "magnovideo.com", - "squareup.com", - "balagana.net", - "goodsearch.com", - "blog.ir", - "ne10.uol.com.br", - "di.se", - "sinembargo.mx", - "k618.cn", - "eventim.de", - "mysavings.com", - "futureshop.ca", - "spinding.com", - "landsend.com", - "oqenadserving.com", - "here.com", - "upi.com", - "picresize.com", - "abnamro.nl", - "filenuke.com", - "yxku.com", - "mypearson.com", - "dinakaran.com", - "correos.es", - "hotchatdirect.com", - "markafoni.com", - "gofuckbiz.com", - "webfindpage.com", - "cancan.ro", - "hostgator.in", - "latribune.fr", - "adxite.com", - "mofos.com", - "bluewin.ch", - "24ur.com", - "dion.ne.jp", - "vpsdomain3.eu", - "newsweek.com", - "oasgames.com", - "mtv3.fi", - "internetworld.de", - "yatedo.com", - "globaltimes.cn", - "paddypower.com", - "berlin1.de", - "norwegian.com", - "opteck.com", - "zenfolio.com", - "kakprosto.ru", - "ecosia.org", - "check24.de", - "idbibank.co.in", - "zoomit.ir", - "notebooksbilliger.de", - "torontosun.com", - "egopay.com", - "cnnexpansion.com", - "emoneyspace.com", - "rsport.ru", - "fok.nl", - "mql4.com", - "inhabitat.com", - "tqn.com", - "noticierodigital.com", - "wrike.com", - "bazos.cz", - "phonegap.com", - "microlancer.com", - "anipo.jp", - "fotocommunity.de", - "kuwo.cn", - "chinacaipu.com", - "terra.cl", - "500px.org", - "qantas.com.au", - "advertising.com", - "push2check.net", - "livefyre.com", - "philstar.com", - "erail.in", - "mywebgrocer.com", - "der-postillon.com", - "ru-board.com", - "saramin.co.kr", - "yjbys.com", - "aaa.com", - "flavorwire.com", - "fcbarcelona.com", - "lacentrale.fr", - "googlegroups.com", - "luck4.me", - "catho.com.br", - "centauro.com.br", - "sia.az", - "forumactif.com", - "paltalk.com", - "beyond.com", - "occ.com.mx", - "stamps.com", - "getoffmyinternets.net", - "mbok.jp", - "cleveland.com", - "ucdavis.edu", - "tielabs.com", - "hkgolden.com", - "vandal.net", - "lyst.com", - "mrskin.com", - "bunshun.jp", - "netcarshow.com", - "b1.org", - "hromadske.tv", - "sf-express.com", - "pirateproxy.ca", - "getcashforsurveys.com", - "clikz4freakz.com", - "adsupply.com", - "truste.org", - "boxuu.com", - "webartex.ru", - "usc.edu", - "moo.com", - "winkal.com", - "deloitte.com", - "xvideos-field5.com", - "suomi24.fi", - "flexmls.com", - "weeklystandard.com", - "debenhams.com", - "mejortorrent.com", - "vconnect.com", - "ligatus.com", - "skynewsarabia.com", - "herschina.com", - "92lux.cn", - "care.com", - "chip.com.tr", - "tangdou.com", - "vatanbilgisayar.com", - "uppit.com", - "metronews.fr", - "parenting.com.tw", - "meteo.gr", - "meetgee.com", - "ldlc.com", - "ubs.com", - "elcolombiano.com", - "mafengwo.cn", - "moodle.org", - "asiaone.com", - "huffingtonpost.it", - "ipas2free.com", - "casa.it", - "kaiserpermanente.org", - "listindiario.com", - "treehugger.com", - "payeer.com", - "mypoints.com", - "pjmedia.com", - "foreca.com", - "luxup.ru", - "halifax.co.uk", - "webinarjam.net", - "webmeup.com", - "webdesignledger.com", - "rte.ie", - "18andabused.com", - "vbulletin.org", - "apne.tv", - "immoweb.be", - "colonelcassad.livejournal.com", - "atlassian.com", - "investors.com", - "globalbux.net", - "wechat.com", - "kanoon.ir", - "mawaly.com", - "self.com", - "drive.ru", - "autozone.com", - "creditonebank.com", - "fdj.fr", - "hsbc.com.br", - "desk.com", - "dlvr.it", - "wpml.org", - "newmobilelife.com", - "crosswalk.com", - "thehun.com", - "hobbyking.com", - "tiantian.com", - "hichina.com", - "cyanogenmod.org", - "horoscope.com", - "bizsugar.com", - "popularmechanics.com", - "egaliteetreconciliation.fr", - "eol.cn", - "rzd.ru", - "escalatenetwork.net", - "yad2.co.il", - "cna.com.tw", - "zi-m.com", - "leonardo.it", - "ap.gov.in", - "rakuten.de", - "wallsave.com", - "netzwelt.de", - "bitrix24.ru", - "techinasia.com", - "bitstamp.net", - "hostelbookers.com", - "shoplocal.com", - "200please.com", - "tune-up.com", - "mapy.cz", - "dealnews.com", - "livescore.co.uk", - "seocentro.com", - "rstyle.me", - "neoseeker.com", - "kaban.tv", - "visualstudio.com", - "cinetux.org", - "groupon.com.br", - "lastpass.com", - "rincondelvago.com", - "popsci.com", - "2144.cn", - "clickfair.com", - "dsebd.org", - "banesco.com", - "spi0n.com", - "blogspot.cz", - "tnews.ir", - "nme.com", - "paperblog.com", - "firstcry.com", - "tophotels.ru", - "liepin.com", - "korabia.com", - "ifttt.com", - "aemet.es", - "alot.com", - "manutd.com", - "edreams.es", - "turkcell.com.tr", - "eva.vn", - "techpowerup.com", - "vkrugudruzei.ru", - "feed2all.eu", - "thehindubusinessline.com", - "express.de", - "ixquick.com", - "thrillist.com", - "iqilu.com", - "seriouseats.com", - "edgesuite.net", - "telexads.com", - "alza.cz", - "en-japan.com", - "al.com", - "dota2lounge.com", - "totalping.com", - "seocheki.net", - "iceporn.com", - "col3negoriginel.lk", - "porsyar.com", - "property24.com", - "madamenoire.com", - "markethealth.com", - "alphacoders.com", - "webempresa.com", - "empireonline.com", - "downforeveryoneorjustme.com", - "lankadeepa.lk", - "darty.com", - "census.gov", - "wapka.me", - "kdslife.com", - "jpost.com", - "cricfree.tv", - "7xxxtube.com", - "businesscatalyst.com", - "dilbert.com", - "gaymaletube.com", - "bellanaija.com", - "renfe.es", - "equifax.com", - "pornmaki.com", - "lolesports.com", - "yunfan.com", - "everybitcity.com", - "9yao.com", - "avantlink.com", - "paginebianche.it", - "xrosview.com", - "newsday.com", - "usportnews.com", - "petapixel.com", - "pistonheads.com", - "lidovky.cz", - "cvent.com", - "adlandpro.com", - "wikisource.org", - "ename.com", - "prosport.ro", - "sharebuilder.com", - "prisjakt.nu", - "cw.com.tw", - "datafilehost.com", - "aircanada.com", - "osu.edu", - "linuxmint.com", - "toyota.com", - "google.am", - "adobeconnect.com", - "h33t.to", - "companycheck.co.uk", - "juno.com", - "beitaichufang.com", - "alaskaair.com", - "tipsandtricks-hq.com", - "yourstory.com", - "wow-impulse.ru", - "wishpond.com", - "promosite.ru", - "weddingwire.com", - "icicidirect.com", - "mouser.com", - "shopstyle.co.uk", - "sinemalar.com", - "addurl.nu", - "seccionamarilla.com.mx", - "yllix.com", - "motorola.com", - "huawei.com", - "mp3juices.com", - "fitday.com", - "pakwheels.com", - "uploading.com", - "snapwidget.com", - "rsb.ru", - "mturk.com", - "libreoffice.org", - "acer.com", - "rd.com", - "aa.com.tr", - "glamour.com", - "docnhat.net", - "cnbb.com.cn", - "piwik.org", - "mycompanyadmin.com", - "ohozaa.com", - "fox.com", - "mastercard.com.au", - "microsofttranslator.com", - "myhabit.com", - "acesso.uol.com.br", - "cqnews.net", - "default-search.net", - "juntadeandalucia.es", - "carigold.com", - "tweepi.com", - "gamedog.cn", - "videomega.tv", - "softarchive.net", - "akamai.com", - "adorika.net", - "zorpia.com", - "bitdefender.com", - "formstack.com", - "al3abbarq.com", - "ruelala.com", - "andhrajyothy.com", - "siteheart.com", - "spankbang.com", - "buxp.org", - "subtlepatterns.com", - "cucirca.eu", - "apontador.com.br", - "sbs.co.kr", - "rong360.com", - "billmelater.com", - "nowdownload.ch", - "pingmyurl.com", - "main.jp", - "allabolag.se", - "fastspring.com", - "20d625b48e.se", - "wpzoom.com", - "dl-protect.com", - "onvista.de", - "iberia.com", - "learni.st", - "minijuegos.com", - "ae.com", - "india-forums.com", - "port.hu", - "truelocal.com.au", - "ziprecruiter.com", - "toyokeizai.net", - "24timezones.com", - "tzetze.it", - "the-village.ru", - "ptcapusa.com", - "indiaresults.com", - "desjardins.com", - "nchsoftware.com", - "yasdl.com", - "delo.ua", - "baskino.com", - "salary.com", - "freecontact.com", - "wumii.com", - "ssc.nic.in", - "synology.com", - "nttdocomo.co.jp", - "racing-games.com", - "freeonlinegames.com", - "aftabnews.ir", - "zumi.pl", - "efshop.com.tw", - "hawamer.com", - "eastbay.com", - "izvestia.ru", - "mosaiquefm.net", - "twitchy.com", - "slaati.com", - "bookingbuddy.com", - "networksolutionsemail.com", - "etsystatic.com", - "sina.com", - "asiandatingbeauties.com", - "blogs.com", - "france3.fr", - "healthcentral.com", - "downloadatoz.com", - "matthewwoodward.co.uk", - "legalzoom.com", - "phun.org", - "campaignmonitor.com", - "cifraclub.com.br", - "hir24.hu", - "twoplustwo.com", - "hotshame.com", - "arvixededicated.com", - "designcrowd.com", - "mrexcel.com", - "blu-ray.com", - "bundesliga.de", - "comments.ua", - "filmstarts.de", - "3sk.tv", - "donedeal.ie", - "natunbarta.com", - "forex-mmcis.com", - "lifehacker.ru", - "sitepronews.com", - "tudogostoso.com.br", - "titanfall.com", - "brainpickings.org", - "saharareporters.com", - "vidto.me", - "mlit.go.jp", - "terapeak.com", - "techweb.com.cn", - "premiere.fr", - "kanui.com.br", - "asianetnews.tv", - "cric.lk", - "exxxtrasmall.com", - "hiphopdx.com", - "5617.com", - "namepros.com", - "humanmetrics.com", - "allin1convert.com", - "ox.ac.uk", - "msecnd.net", - "cathaypacific.com", - "bet365affiliates.com", - "tcs.com", - "trafficestimate.com", - "lmgtfy.com", - "finance.ua", - "find404.com", - "pagesperso-orange.fr", - "curbed.com", - "tasteofhome.com", - "ar15.com", - "mydigitallife.info", - "promiflash.de", - "technobuffalo.com", - "gamestorrents.com", - "labirint.ru", - "pclab.pl", - "indiatvnews.com", - "finya.de", - "redmondpie.com", - "rabota.ru", - "share-online.biz", - "packtpub.com", - "techgig.com", - "shaw.ca", - "apkmania.co", - "bet-at-home.com", - "barclaycard.co.uk", - "onefloorserve.com", - "raiffeisen.ru", - "t-nation.com", - "mbalib.com", - "staseraintv.com", - "uswitch.com", - "smartadserver.com", - "bbcgoodfood.com", - "elitetorrent.net", - "backlinko.com", - "naszemiasto.pl", - "submitexpress.com", - "savings.com", - "gem.pl", - "ahlamontada.com", - "fotomac.com.tr", - "gougou.com", - "payamsara.com", - "klix.ba", - "doostiha.ir", - "bibliocommons.com", - "wealthyaffiliate.com", - "emgn.com", - "sifyitest.com", - "washingtonexaminer.com", - "rakuten-sec.co.jp", - "mysurvey.com", - "uuu9.com", - "uscourts.gov", - "showroomprive.com", - "cargocollective.com", - "hsoub.com", - "afterbuy.de", - "marunadanmalayali.com", - "jumponhottie.com", - "avon.com", - "lazada.com.my", - "51netu.com.cn", - "ria.com", - "sankakucomplex.com", - "tvline.com", - "devshed.com", - "superherohype.com", - "tv-series.me", - "stylecraze.com", - "wizards.com", - "linkcollider.com", - "xinjunshi.com", - "bestchange.ru", - "1111.com.tw", - "fakenamegenerator.com", - "newsmth.net", - "noupe.com", - "marketingprofs.com", - "bluestacks.com", - "jemtube.com", - "bestbuy.ca", - "backcountry.com", - "designshack.net", - "pond5.com", - "highsnobiety.com", - "rtl.fr", - "pearsoncmg.com", - "hellowork.go.jp", - "koimoi.com", - "soali.ir", - "incentria.com", - "vagas.com.br", - "huaxi100.com", - "cheaa.com", - "lohaco.jp", - "gov.on.ca", - "fabthemes.com", - "pipl.com", - "comscore.com", - "pcfinancial.ca", - "craigslist.co.in", - "michaels.com", - "jibjab.com", - "sankeibiz.jp", - "dominos.co.in", - "supermoney.eu", - "itusozluk.com", - "sdchina.com", - "allkpop.com", - "cam4.com.br", - "stayfriends.de", - "futbol24.com", - "searchina.net", - "sgcpanel.com", - "informe21.com", - "alsacreations.com", - "crateandbarrel.com", - "alliancewarfare.com", - "filerio.in", - "emailsrvr.com", - "reventmedia.com", - "vietcombank.com.vn", - "rxlist.com", - "acidcow.com", - "orange.co.uk", - "hellocoton.fr", - "boldchat.com", - "psychcentral.com", - "surfline.com", - "xxxkinky.com", - "es.wordpress.com", - "publika.az", - "shufoo.net", - "hertz.com", - "businessweekly.com.tw", - "virgula.uol.com.br", - "linkis.com", - "ixwebhosting.com", - "usa.gov", - "linguee.com", - "yengo.com", - "huffingtonpost.jp", - "1x3x.com", - "mediametrics.ru", - "ec21.com", - "80018.cn", - "get-tune.net", - "yupoo.com", - "moviepilot.de", - "ihned.cz", - "fio.cz", - "pubted.com", - "cinemablend.com", - "stooorage.com", - "thevault.bz", - "journaldugeek.com", - "sommer-sommer.com", - "travelchannel.com", - "softonic.de", - "petsmart.com", - "ufxmarkets.com", - "e24.no", - "spirit.com", - "dabi.ir", - "admin5.net", - "serialu.net", - "vancouversun.com", - "submanga.com", - "sbicard.com", - "affaritaliani.it", - "idownloadblog.com", - "castorama.fr", - "sudouest.fr", - "payscale.com", - "serebii.net", - "storypick.com", - "jobkorea.co.kr", - "gowildcasino.com", - "hmetro.com.my", - "parimatch.com", - "51pinwei.com", - "globalnews.ca", - "mercadopago.com", - "sixrevisions.com", - "saisoncard.co.jp", - "gov.kz", - "gossip-tv.gr", - "zbozi.cz", - "aliorbank.pl", - "huanqiuauto.com", - "okaz.com.sa", - "cplusplus.com", - "mochimedia.com", - "google.sn", - "jquery-plugins.net", - "peoplesmart.com", - "mmafighting.com", - "ponpare.jp", - "porsche.com", - "charter.com", - "scrabblefinder.com", - "unpcn.com", - "loveaholics.com", - "geocities.co.jp", - "ladbrokes.com", - "52che.com", - "swansonvitamins.com", - "sweetwater.com", - "ali213.net", - "savenkeep.com", - "hotair.com", - "orgasmatrix.com", - "runrun.es", - "filezilla-project.org", - "looti.net", - "pagesix.com", - "twentytwowords.com", - "gingersoftware.com", - "youxiduo.com", - "isimtescil.net", - "rui.jp", - "d1g.com", - "2dbook.com", - "zigzig.ir", - "123telugu.com", - "wdr.de", - "hankyung.com", - "pr.com", - "search.ch", - "iranproud.com", - "raaga.com", - "alt1040.com", - "okpay.com", - "recordchina.co.jp", - "dreamincode.net", - "bendibao.com", - "creativelive.com", - "socialoomph.com", - "cssdeck.com", - "taxactonline.com", - "pb.com", - "fnac.es", - "ucsd.edu", - "tmart.com", - "whorush.com", - "spicejet.com", - "socialadr.com", - "tutorialzine.com", - "christianmingle.com", - "torrentleech.org", - "statefarm.com", - "orkut.com", - "whoscored.com", - "truthaboutonlinesluts.com", - "32red.com", - "wp-themes.com", - "adpost.com", - "cnr.cn", - "180upload.com", - "snagajob.com", - "textbroker.com", - "freshome.com", - "talkgold.com", - "dudamobile.com", - "weblancer.net", - "newone.org", - "nacion.com", - "takepart.com", - "voici.fr", - "gizmodo.jp", - "viki.com", - "symbaloo.com", - "topface.com", - "businessdictionary.com", - "adtech.info", - "elandroidelibre.com", - "fux.com", - "21-sun.com", - "cpmfx.com", - "siemens.com", - "edmodo.com", - "notitarde.com", - "babypips.com", - "silkroad.com", - "onextrapixel.com", - "notdoppler.com", - "walmart.ca", - "marvel.com", - "groupon.fr", - "us1.com", - "bunte.de", - "findlaw.com", - "topito.com", - "carrefour.fr", - "aawsat.com", - "super.ae", - "kicktipp.de", - "simplyrecipes.com", - "i-mobile.co.jp", - "podrobnosti.ua", - "snn.ir", - "successfactors.com", - "paixie.net", - "wiwo.de", - "glowgaze.com", - "mapsofworld.com", - "limetorrents.com", - "plarium.com", - "tvi.ua", - "corel.com", - "adhitprofits.com", - "findthecompany.com", - "noticiasaldiayalahora.co", - "160by2.com", - "jobberman.com", - "rus.ec", - "fujitsu.com", - "ladepeche.fr", - "pravda.sk", - "wwtdd.com", - "b9dm.com", - "marathonbet.com", - "sexlunch.com", - "komputronik.pl", - "gutenberg.org", - "dizo.com.cn", - "comunio.de", - "naked.com", - "gamesradar.com", - "moneysupermarket.com", - "cheaptickets.com", - "assembla.com", - "timesonline.co.uk", - "mckinsey.com", - "ebook3000.com", - "videoblocks.com", - "ruseller.com", - "pideo.net", - "joomlacode.org", - "pciconcursos.com.br", - "channelnewsasia.com", - "cnnturk.com", - "consultant.ru", - "michigan.gov", - "manoto1.com", - "10010.com", - "wholefoodsmarket.com", - "globalgrind.com", - "pichak.net", - "morpakampus.com", - "crazydomains.com.au", - "uptodown.com", - "polygon.com", - "raspberrypi.org", - "atmarkit.co.jp", - "heftig.co", - "informationweek.com", - "trendhunter.com", - "state.ny.us", - "pornpros.com", - "tnt.com", - "sportal.bg", - "spritzinc.com", - "theladders.com", - "lulu.com", - "applesfera.com", - "qoo10.jp", - "notebookreview.com", - "startertv.fr", - "healthkart.com", - "imgsin.com", - "mp3olimp.net", - "readms.com", - "casadellibro.com", - "nalog.ru", - "4gamer.net", - "jquery4u.com", - "betfred.com", - "3dwwwgame.com", - "appleinsider.com", - "dailystar.co.uk", - "swalif.com", - "hushmail.com", - "worldtimebuddy.com", - "sportschau.de", - "mediatraffic.com", - "gismeteo.ua", - "record.com.mx", - "putnik1.livejournal.com", - "nextbigwhat.com", - "vinescope.com", - "jarchi.ir", - "yidio.com", - "dunyanews.tv", - "hangseng.com", - "interpark.com", - "scholastic.com", - "penny-arcade.com", - "geilundlive.com", - "budbi.com", - "stop55.com", - "jaidefinichon.com", - "smartsheet.com", - "vector.me", - "farecompare.com", - "vodafone.com.eg", - "craftsy.com", - "theresumator.com", - "downloadab.com", - "abendzeitung-muenchen.de", - "dicio.com.br", - "fobshanghai.com", - "2dehands.be", - "thethao247.vn", - "cams.com", - "gothamist.com", - "moneynews.com", - "zocdoc.com", - "rol.ro", - "nic.ar", - "avenues.info", - "cleverbridge.com", - "usajobs.gov", - "divxstage.eu", - "jsticket.net", - "himasoku.com", - "thrivethemes.com", - "orientaltrading.com", - "premiumpress.com", - "house365.com", - "drugoi.livejournal.com", - "monster.co.uk", - "quickanddirtytips.com", - "virtuemart.net", - "huffpost.com", - "real.com", - "teacherspayteachers.com", - "t24.com.tr", - "zakon.kz", - "shoppinglifestyle.com", - "trendmicro.com", - "surfingbird.ru", - "cam.ac.uk", - "navyfederal.org", - "rateyourmusic.com", - "bravenet.com", - "polo.com", - "cl.ly", - "nanacast.com", - "cnfol.com", - "24option.com", - "myscienceacademy.org", - "getsoftfree.com", - "cba.pl", - "templateism.com", - "actudesfinances.org", - "1.254.254.254", - "jobtalk.jp", - "barbie.com", - "rahnama.com", - "gigporno.com", - "buddypress.org", - "corporationwiki.com", - "enorth.com.cn", - "thepioneerwoman.com", - "cam4ultimate.com", - "phpclasses.org", - "uplus.metroer.com/~content", - "komando.com", - "iha.com.tr", - "televisa.com", - "tmtpost.com", - "classifiedsgiant.com", - "sportinglife.com", - "askul.co.jp", - "travelagency.travel", - "jqueryscript.net", - "rusfolder.com", - "netcq.net", - "irangrand.ir", - "interaztv.com", - "downvids.net", - "mongodb.org", - "nasgo.net", - "thesitewizard.com", - "songspk.cc", - "travelandleisure.com", - "d-h.st", - "wasanga.com", - "cgg.gov.in", - "silverclix.com", - "almogaz.com", - "sexmob.es", - "mistreci.com", - "nukistream.com", - "postaffiliatepro.com", - "dish.com", - "ulta.com", - "worldcat.org", - "crackle.com", - "cineblog01.net", - "parispornmovies.com", - "avito.ma", - "nethouse.ru", - "elfinanciero.com.mx", - "ab-in-den-urlaub.de", - "pixeden.com", - "thetimenow.com", - "divar.ir", - "coolrom.com", - "akbank.com", - "saturn.de", - "dstv.com", - "mttbsystem.com", - "hujiang.com", - "bash.im", - "sextgem.com", - "subaonet.com", - "cnsnews.com", - "informationng.com", - "utoronto.ca", - "hetzner.de", - "vend-o.com", - "cybozu.com", - "autotimes.com.cn", - "5giay.vn", - "theepochtimes.com", - "penesalud.com", - "livenation.com", - "qoinpro.com", - "myway.com", - "safe-swaps.com", - "elephantjournal.com", - "curse.com", - "17zwd.com", - "hitleap.com", - "mec.gov.br", - "freewebcams.com", - "westelm.com", - "imagegals.com", - "streeteasy.com", - "ekitan.com", - "git-scm.com", - "p30day.com", - "kapaza.be", - "svoboda.org", - "google.mg", - "timesofisrael.com", - "roodo.com", - "malwaretips.com", - "dumpaday.com", - "dha.com.tr", - "diary.ru", - "epa.gov", - "jonloomer.com", - "holidaylettings.co.uk", - "oem.com.mx", - "oxfordjournals.org", - "3bmeteo.com", - "iwebtool.com", - "yinyuetai.com", - "ixl.com", - "rezultati.com", - "51sole.com", - "moudamepo.com", - "macromill.com", - "nzz.ch", - "buzznet.com", - "roku.com", - "posta.com.tr", - "letsbonus.com", - "theoatmeal.com", - "artofmanliness.com", - "tubepornkiss.com", - "aviny.com", - "sabresonicweb.com", - "tech-wd.com", - "qbank.ru", - "getsatisfaction.com", - "prokerala.com", - "ebc.com.br", - "typiol.com", - "photo.net", - "rockpapershotgun.com", - "netgear.com", - "mg.co.za", - "impressrd.jp", - "jkbk.cn", - "bakufu.jp", - "lgmi.com", - "tnt-online.ru", - "frequency.com", - "zip-codes.com", - "sport.ro", - "wolfram.com", - "pgmediaserve.com", - "icann.org", - "twistedsifter.com", - "mopo.de", - "vogue.co.uk", - "chatrandom.com", - "checkpagerank.net", - "colorzilla.com", - "autobip.com", - "laban.vn", - "pricecheck.co.za", - "notimex.com.mx", - "pik.ba", - "monster.de", - "google.cd", - "economia.uol.com.br", - "vsnl.net.in", - "futura-sciences.com", - "appstorm.net", - "icefilms.info", - "dicelacancion.com", - "hypovereinsbank.de", - "piratestreaming.tv", - "101domain.com", - "google.mn", - "rutgers.edu", - "behindwoods.com", - "downloadmaster.ru", - "smartinsights.com", - "wiziq.com", - "ftc.gov", - "animenewsnetwork.com", - "tandfonline.com", - "seagate.com", - "famitsu.com", - "onekingslane.com", - "zalando.fr", - "convio.com", - "seochat.com", - "qq163.com", - "capital.gr", - "tamin.ir", - "phpfreaks.com", - "cricketcountry.com", - "ubersuggest.org", - "ntv.co.jp", - "olark.com", - "1001fonts.com", - "appsgeyser.com", - "elsiglodetorreon.com.mx", - "lyricsmint.com", - "tovima.gr", - "petco.com", - "campograndenews.com.br", - "amadeus.com", - "tinychat.com", - "astrology.com", - "idg.se", - "nordea.se", - "gelbeseiten.de", - "nrc.nl", - "houseoffraser.co.uk", - "hepsibahis3.com", - "empowernetwork.com/almostasecret", - "phpnuke.org", - "xfwed.com", - "gulte.com", - "msi.com", - "netfirms.com", - "ovcanada.com", - "smzdm.com", - "wwwhatsnew.com", - "mydomainadvisor.com", - "newindianexpress.com", - "luxtarget.com", - "evz.ro", - "otodom.pl", - "linkin.net", - "moneysavingmom.com", - "uploadbaz.com", - "egyup.com", - "three.co.uk", - "co-operativebank.co.uk", - "redad.ru", - "ipsosinteractive.com", - "all-union.com", - "trustlink.ru", - "softango.com", - "toucharcade.com", - "tv2.dk", - "thisissouthwales.co.uk", - "jra.go.jp", - "alfavita.gr", - "ibigdan.livejournal.com", - "gtarcade.com", - "jc001.cn", - "microcenter.com", - "optimizepress.com", - "beyebe.com", - "muyzorras.com", - "expedia.co.uk", - "volvocars.com", - "lyd.com.cn", - "korben.info", - "disput.az", - "aeroflot.ru", - "betanews.com", - "avangard.ru", - "wrzko.eu", - "cakephp.org", - "majorgeeks.com", - "dreamteammoney.com", - "foroactivo.com", - "ut.ac.ir", - "eonet.jp", - "vn-zoom.com", - "footytube.com", - "expedia.de", - "barneys.com", - "lieyunwang.com", - "gartner.com", - "lazada.com.ph", - "ourtime.com", - "ohnotheydidnt.livejournal.com", - "e-rewards.com", - "updatestar.com", - "cafef.vn", - "cookinglight.com", - "expressdownload.net", - "shockmansion.com", - "adserverpub.com", - "ipko.pl", - "gsa-online.de", - "car.gr", - "cqcounter.com", - "thenews.com.pk", - "gnc.com", - "teambeachbody.com", - "kobobooks.com", - "cwan.com", - "ca.com", - "list.ly", - "baijob.com", - "gunbroker.com", - "rtl.be", - "myadvertisingpays.com", - "mediapost.com", - "groupalia.com", - "anquan.org", - "mixshowblast.com", - "myscore.ru", - "bancochile.cl", - "a2hosting.com", - "hayneedle.com", - "myfc.ir", - "aktifhaber.com", - "eater.com", - "anymeeting.com", - "cylex.de", - "sayidaty.net", - "synonym.com", - "comprendrechoisir.com", - "prlog.ru", - "solidtrustpay.com", - "cinejosh.com", - "yelp.co.uk", - "olx.com.ar", - "dihitt.com", - "donkeymails.com", - "chainreactioncycles.com", - "wearehairy.com", - "ebuyer.com", - "bplans.com", - "ponparemall.com", - "readthedocs.org", - "tehparadox.com", - "source-wave.com", - "tbs.co.jp", - "redcoon.de", - "francetv.fr", - "freelogoservices.com", - "ogone.com", - "jeanmarcmorandini.com", - "lasexta.com", - "sponsoredreviews.com", - "govome.com", - "vecteezy.com", - "alhayat.com", - "cnhubei.com", - "mumayi.com", - "webfail.com", - "eluniverso.com", - "moddb.com", - "gaiaonline.com", - "gordonua.com", - "liveadexchanger.com", - "zhe800.com", - "softonic.com.br", - "cnyes.com", - "cumlouder.com", - "krakow.pl", - "nullrefer.com", - "zaluu.com", - "diretube.com", - "seattlepi.com", - "eanswers.com", - "gostorego.com", - "play.com", - "lenskart.com", - "unblog.fr", - "chatwork.com", - "bronto.com", - "jobisjob.co.in", - "mercadolibre.com.uy", - "overdrive.com", - "runkeeper.com", - "smartshopping.com", - "getrichradio.com", - "grader.com", - "101greatgoals.com", - "elbilad.net", - "kopp-verlag.de", - "ranksignals.com", - "trome.pe", - "jobstreet.com.my", - "farnell.com", - "fastmail.fm", - "faithit.com", - "blogdohotelurbano.com", - "sencha.com", - "daisycon.com", - "random.org", - "tportal.hr", - "rkanr.com", - "fc2-erodouga.com", - "youngpornvideos.com", - "bravoteens.com", - "mobile.free.fr", - "mitele.es", - "edis.at", - "questionablecontent.net", - "indiangilma.com", - "comunio.es", - "bitnami.com", - "sliptalk.com", - "sourceforge.jp", - "lyoness.net", - "nespresso.com", - "ultrafarma.com.br", - "lik.cl", - "jsoftj.com", - "metoffice.gov.uk", - "androidauthority.com", - "360safe.com", - "wikimart.ru", - "tutu.ru", - "truetwit.com", - "xinruijunshi.com", - "online-sweepstakes.com", - "singaporeair.com", - "cwtv.com", - "politiken.dk", - "alaan.tv", - "tuttomercatoweb.com", - "imagehost123.com", - "drakensang.com", - "frenchweb.fr", - "syosetu.com", - "zhifang.com", - "viptube.com", - "theme123.net", - "statista.com", - "51bi.com", - "clickz.com", - "kingworldnews.com", - "qunar.com", - "pimpandhost.com", - "pagina12.com.ar", - "xinmin.cn", - "kidshealth.org", - "pics.livejournal.com", - "kabum.com.br", - "anandabazar.com", - "pnu.ac.ir", - "scene7.com", - "paperpkads.com", - "mylikes.com", - "longtailvideo.com", - "firmy.cz", - "bitcoinity.org", - "inopressa.ru", - "expat-blog.com", - "governmentjobs.com", - "airdroid.com", - "mid-day.com", - "frandroid.com", - "webceo.com", - "cadenaser.com", - "minutouno.com", - "onamae.com", - "onlinekhabar.com", - "williams-sonoma.com", - "freewebsubmission.com", - "vozforums.com", - "bigpicture.ru", - "mymodernmet.com", - "presseportal.de", - "licindia.in", - "ismedia.jp", - "depor.pe", - "sing365.com", - "v2cigs.com", - "postimage.org", - "gencat.cat", - "west263.com", - "alohatube.com", - "eenadupratibha.net", - "terra.com", - "bri.co.id", - "silktide.com", - "anyang.gov.cn", - "speedanalysis.com", - "bitcoin.org", - "toodledo.com", - "topgear.com", - "rtvslo.si", - "hotpads.com", - "nedsecure.co.za", - "expedia.ca", - "thairath.co.th", - "gizbot.com", - "naukrigulf.com", - "guffins.com", - "twilio.com", - "avsforum.com", - "sharpnews.ru", - "inoreader.com", - "stgeorge.com.au", - "shoebuy.com", - "sbwire.com", - "bfm.ru", - "dongtaiwang.com", - "mandrillapp.com", - "176.com", - "olx.com", - "trustpilot.co.uk", - "tgju.org", - "pap.fr", - "iphonehacks.com", - "gry-online.pl", - "mp3xd.com", - "viabcp.com", - "bizcommunity.com", - "chillingeffects.org", - "thomasnet.com", - "performersoft.com", - "paymaster.ru", - "comdotgame.com", - "bseindia.com", - "foodgawker.com", - "clicktale.com", - "dot.tk", - "smbc-comics.com", - "vvmembers.co", - "c-sharpcorner.com", - "acdcads.com", - "goldporntube.com", - "abakus-internet-marketing.de", - "babbel.com", - "fzg360.com", - "99inf.com", - "cduniverse.com", - "autobild.de", - "tvrage.com", - "phoenix.edu", - "hurriyetemlak.com", - "va.gov", - "maxmind.com", - "lifehacker.jp", - "nola.com", - "niroensani.ir", - "ihotelier.com", - "mianbao.com", - "powerball.com", - "express.com", - "freshdesignweb.com", - "o2.co.uk", - "utusan.com.my", - "overclockers.ru", - "fsiblog.com", - "launchpad.net", - "prizee.com", - "alalam.ir", - "imtalk.org", - "vavel.com", - "nyc.ny.us", - "youmob.com", - "dailythanthi.com", - "ksu.edu.sa", - "nlayer.net", - "kurier.at", - "expert-offers.com", - "marry52.com", - "cityads.ru", - "darkorbit.com", - "cio.com", - "a9.com", - "symfony.com", - "crobo.com", - "shatel.ir", - "opposingviews.com", - "myvoffice.com", - "vkmag.com", - "starpulse.com", - "bls.gov", - "lifebettering.com", - "fanhuan.com", - "upload7.ir", - "infoplease.com", - "suruga-ya.jp", - "deredactie.be", - "shangdu.com", - "portail.free.fr", - "smartaddons.com", - "w3layouts.com", - "wallstreet-online.de", - "yapo.cl", - "standard.co.uk", - "atlas.sk", - "seowizard.ru", - "currys.co.uk", - "nova.cz", - "mygully.com", - "favstar.fm", - "themuse.com", - "yudu.com", - "urlopener.com", - "ellentv.com", - "imgsrc.ru", - "km.ru", - "guildwars2.com", - "google.mu", - "androidpit.de", - "mrporter.com", - "ttt4.com", - "cbox.ws", - "hf365.com", - "1mobile.com", - "punjabkesari.in", - "msu.edu", - "grasscity.com", - "abduzeedo.com", - "sublimetext.com", - "jtb.co.jp", - "mensxp.com", - "myheritage.com", - "onvasortir.com", - "safeway.com", - "comicvine.com", - "cpubenchmark.net", - "nn.ru", - "animefreak.tv", - "angularjs.org", - "managewp.com", - "ameli.fr", - "merrjep.com", - "christianbook.com", - "nubiles.net", - "klmty.net", - "247sports.com", - "aramex.com", - "tubent.com", - "cognitiveseo.com", - "bankpasargad.com", - "pingler.com", - "compareja.com.br", - "surveyzrewardcenter.eu", - "allyes.com", - "graaam.com", - "poriborton.com", - "seslisozluk.net", - "shopyourway.com", - "awd.ru", - "wa.gov.au", - "slrclub.com", - "apollo.lv", - "girls-ly.com", - "totalfilm.com", - "cam4.it", - "gogecapital.com", - "sketchup.com", - "muscleandfitness.com", - "m24.ru", - "blinklist.com", - "artisteer.com", - "nettavisen.no", - "enjin.com", - "pc6.com", - "citrix.com", - "indgovtjobs.in", - "phpbb.com", - "laughingsquid.com", - "fblife.com", - "stansberryresearch.com", - "hugefiles.net", - "mp3monkey.net", - "mcdonalds.com", - "vodafone.co.uk", - "t-mobile.de", - "tp-link.com.cn", - "iflscience.com", - "nst.com.my", - "zoom.com.br", - "dsw.com", - "tigerair.com", - "doityourself.com", - "bongdainfo.com", - "imacros.net", - "paperlesspost.com", - "sprinthost.ru", - "lovoo.net", - "kadinlarkulubu.com", - "championselect.net", - "jcb.co.jp", - "miui.com", - "impots.gouv.fr", - "linkshop.com.cn", - "pando.com", - "ckeditor.com", - "arabylife.com", - "ml.com", - "sheldonsfans.com", - "freecharge.in", - "magicmovies.com", - "laweekly.com", - "highrisehq.com", - "tr.gg", - "vidbull.com", - "diy.com", - "yieldtraffic.com", - "cima4u.com", - "gendama.jp", - "netpnb.com", - "kannaway.com", - "soft112.com", - "die-boersenformel.com", - "movie25.so", - "footyroom.com", - "dostor.org", - "aol.de", - "desimartini.com", - "themeko.org", - "danarimedia.com", - "toroporno.com", - "stylemepretty.com", - "urlm.de", - "demotivation.me", - "gentside.com", - "carfax.com", - "huzhou.gov.cn", - "hotline.ua", - "fullmoneysystem.com", - "pornomovies.com", - "fsymbols.com", - "blog.de", - "clickpoint.com", - "tv-asahi.co.jp", - "flightstats.com", - "sonico.com", - "afamily.vn", - "anadolu.edu.tr", - "rs-online.com", - "androidpit.com", - "a-telecharger.com", - "wikifeet.com", - "nix.ru", - "tvmao.com", - "groupon.es", - "hitfix.com", - "weathernews.jp", - "dig.do", - "googledrive.com", - "fodors.com", - "melon.com", - "testflightapp.com", - "markt.de", - "mahua.com", - "sedo.co.uk", - "tuenti.com", - "comm100.com", - "olx.co.id", - "lefrecce.it", - "gov.cl", - "wplift.com", - "unn.com.ua", - "arizona.edu", - "msn.com.cn", - "k7x.com", - "techz.vn", - "jobomas.com", - "extranetinvestment.com", - "tengrinews.kz", - "comicbookmovie.com", - "4porn.com", - "rubiconproject.com", - "gametracker.com", - "otcmarkets.com", - "mismarcadores.com", - "trojmiasto.pl", - "cleverreach.com", - "contactform7.com", - "weloveshopping.com", - "runnersworld.com", - "falabella.com", - "airtelbroadband.in", - "twistys.com", - "ebesucher.de", - "belastingdienst.nl", - "orlandosentinel.com", - "th3professional.com", - "duke.edu", - "opensubtitles.us", - "clickme.net", - "infor.pl", - "unesco.org", - "socialfabric.us", - "ename.net", - "alternativeto.net", - "rotahaber.com", - "johnchow.com", - "pervclips.com", - "linkfeed.ru", - "dtvideo.com", - "kinoman.tv", - "siteprice.org", - "lacuerda.net", - "amulyam.in", - "mandghomebusiness.com", - "infojobs.com.br", - "hirufm.lk", - "mybloggertricks.com", - "athemes.com", - "moikrug.ru", - "fybersearch.com", - "wine-searcher.com", - "davidicke.com", - "dotabuff.com", - "sainsburys.co.uk", - "ovaustralia.com", - "updatesoftnow.com", - "desarrolloweb.com", - "elaph.com", - "icc-cricket.com", - "gaytube.com", - "di.fm", - "99wed.com", - "c-and-a.com", - "mlxchange.com", - "realgfporn.com", - "synxis.com", - "optymalizacja.com", - "ibtesama.com", - "hankooki.com", - "shiksha.com", - "anoox.com", - "seamless.com", - "stripe.com", - "ets.org", - "fresherslive.com", - "webcoinpay.net", - "oscommerce.com", - "gratisprogramas.org", - "football365.com", - "mkyong.com", - "antichat.ru", - "spamarrest.com", - "ubc.ca", - "36kr.com", - "startv.in", - "shoutcast.com", - "heureka.sk", - "entheosweb.com", - "51wan.com", - "madadsmedia.com", - "parse.com", - "ngacn.cc", - "techbargains.com", - "tvmovie.de", - "cpmstar.com", - "torproject.org", - "residentadvisor.net", - "genbeta.com", - "hulu.jp", - "pluralsight.com", - "postini.com", - "zombie.jp", - "skimlinks.com", - "liverail.com", - "phys.org", - "slashfilm.com", - "livemaster.ru", - "idwebgame.com", - "pho.to", - "dealfish.co.th", - "s1979.com", - "designfloat.com", - "live365.com", - "pbase.com", - "eniro.se", - "irannaz.com", - "socialmonkee.com", - "uidai.gov.in", - "joomlashine.com", - "allhyipmon.ru", - "upbulk.com", - "diapers.com", - "flypgs.com", - "hotmart.com.br", - "globus-inter.com", - "airfrance.fr", - "t3.com", - "unetepubli.com", - "yahoo-help.jp", - "iphones.ru", - "95559.com.cn", - "glamsham.com", - "gophoto.it", - "statmyweb.com", - "aftermarket.pl", - "forumotion.com", - "iafd.com", - "hotlog.ru", - "drclix.com", - "wawa-mania.ec", - "nichepursuits.com", - "imp.free.fr", - "baofeng.com", - "binsearch.info", - "neswangy.net", - "parperfeito.com.br", - "theeroticreview.com", - "sabayacafe.com", - "maplestage.com", - "icook.tw", - "customerhub.net", - "uid.me", - "viperchill.com", - "askfrank.net", - "juegosjuegos.com", - "debonairblog.com", - "coingeneration.com", - "onetravel.com", - "slutroulette.com", - "jetpack.me", - "embedupload.com", - "bancodevenezuela.com", - "mysavingsmedia.net", - "smallbiztrends.com", - "emirates247.com", - "bu.edu", - "fineco.it", - "netbarg.com", - "gatech.edu", - "zik.ua", - "peliculascoco.com", - "hkjc.com", - "turkiyegazetesi.com.tr", - "cooperativa.cl", - "challenges.fr", - "usingenglish.com", - "vouchercodes.co.uk", - "bonprix.de", - "disneylatino.com", - "townwork.net", - "rentanything.com", - "krypt.com", - "wral.com", - "globes.co.il", - "designtaxi.com", - "mp-success.com", - "invisionpower.com", - "liontravel.com", - "classicrummy.com", - "mt.co.kr", - "inccel.com", - "santander.cl", - "afip.gov.ar", - "yellowpages.com.au", - "osclass.org", - "couriermail.com.au", - "stream.cz", - "wizaz.pl", - "linkresearchtools.com", - "cam4.co.uk", - "allafrica.com", - "gezginler.net", - "free-ebooks.net", - "hopesandfears.com", - "ticketmaster.com.mx", - "ohio.gov", - "liberoquotidiano.it", - "neurs.net", - "forumophilia.com", - "odnako.org", - "gamekult.com", - "vh1.com", - "zxart.cn", - "mass.gov", - "tv-tokyo.co.jp", - "mundopromocion.com", - "theme-junkie.com", - "asu.edu", - "lalibre.be", - "pornokopilka.info", - "fx678.com", - "netbeans.org", - "chinabidding.com.cn", - "lunapic.com", - "dramafever.com", - "hbogo.com", - "torrents.net", - "woopra.com", - "justfab.com", - "fitnessmagazine.com", - "tripadvisor.com.mx", - "183.com.cn", - "adscendmedia.com", - "geek.com", - "thepetitionsite.com", - "skyscanner.ru", - "morningpost.com.cn", - "concursolutions.com", - "camplace.com", - "smarturl.it", - "browsershots.org", - "piktochart.com", - "elcorreo.com", - "collegeboard.org", - "kasikornbank.com", - "adsoftheworld.com", - "fakku.net", - "jpn.org", - "sahafah.net", - "rubias19.com", - "fc2web.com", - "redsurf.ru", - "iproperty.com.my", - "browsersafeguard.com", - "mmajunkie.com", - "bangkokbank.com", - "ovi.com", - "fap.to", - "filmygyan.in", - "edaily.vn", - "affilorama.com", - "valuecommerce.ne.jp", - "softaculous.com", - "exchanger.ru", - "html-color-codes.info", - "hd-xvideos.com", - "realself.com", - "geocaching.com", - "mom.me", - "stc.com.sa", - "video-i365.com", - "umd.edu", - "jeffbullas.com", - "kora.com", - "cyberchimps.com", - "popupads.ir", - "chatango.com", - "gearslutz.com", - "fout.jp", - "contactmusic.com", - "linkcrypt.ws", - "sophos.com", - "forum-auto.com", - "svtplay.se", - "newsbusters.org", - "fileswap.com", - "phpfox.com", - "denic.de", - "riverisland.com", - "encuentra24.com", - "foxnewsinsider.com", - "dtdc.com", - "tayyar.org", - "thepushbuttonmillionaire.com", - "brokenlinkcheck.com", - "ju51.com", - "stihi.ru", - "psdgraphics.com", - "mommyfucktube.com", - "mangocity.com", - "routard.com", - "whicdn.com", - "socialtriggers.com", - "e-bookspdf.org", - "songspk3.in", - "paginasamarillas.com", - "webgame.in.th", - "xxxdessert.com", - "materiel.net", - "skillshare.com", - "tubepleasure.com", - "paypal.de", - "yeahmobi.com", - "torrentz-proxy.com", - "aircel.com", - "openask.com", - "trafficg.com", - "anthem.com", - "aleseriale.pl", - "f-page.ru", - "hrsmart.com", - "cbengine.com", - "startlap.com", - "spamhaus.org", - "trovit.com", - "sporcle.com", - "xs8.cn", - "romwe.com", - "powtoon.com", - "cybozulive.com", - "zbiornik.com", - "cebit.de", - "flipboard.com", - "news.am", - "wm-panel.com", - "topnews.ru", - "usp.br", - "realmadrid.com", - "fastdist.net", - "unian.ua", - "youtube.com/user/PewDiePie", - "unc.edu", - "tamu.edu", - "ip2location.com", - "americanapparel.net", - "virtualedge.com", - "vikatan.com", - "goodlayers.com", - "feedblitz.com", - "dateinasia.com", - "freepdfconvert.com", - "iweb.com", - "lachainemeteo.com", - "aetna.com", - "ti.com", - "gratisjuegos.org", - "webhostinghub.com", - "preev.com", - "holidayiq.com", - "elpais.com.uy", - "uchicago.edu", - "telcel.com", - "feebbo.com", - "webhallen.com", - "dmir.ru", - "emailmg.ipage.com", - "hrs.de", - "propakistani.pk", - "theme.co", - "bigpara.com", - "finishline.com", - "fardanews.com", - "nat.gov.tw", - "stoloto.ru", - "sermepa.es", - "radaris.com", - "softportal.com", - "turkiye.gov.tr", - "nnn.ru", - "e-familynet.com", - "wenkang.cn", - "teamworkpm.net", - "videohelp.com", - "pixmania.com", - "games.com", - "guns.ru", - "plus28.com", - "pf.pl", - "pbworks.com", - "sedo.de", - "freedownloadscenter.com", - "backpackers.com.tw", - "mycokerewards.com", - "chinaunix.net", - "invisionapp.com", - "wordhippo.com", - "unitezz.com", - "yan.vn", - "sonhoo.com", - "spielaffe.de", - "d.pr", - "technologyreview.com", - "democraticunderground.com", - "molotok.ru", - "watchever.de", - "wdc.com", - "torg.com", - "ivillage.com", - "portableapps.com", - "ovh.es", - "vse.kz", - "alrajhibank.com.sa", - "dhl-usa.com", - "pingan.com", - "excite.com", - "cincodias.com", - "marksdailyapple.com", - "bter.com", - "nationaljournal.com", - "fao.org", - "oddee.com", - "digitalriver.com", - "livescore.in", - "siilu.com", - "gofirstrowus.eu", - "alquds.co.uk", - "autoevolution.com", - "zerx.ru", - "trovit.it", - "hvylya.org", - "carters.com", - "shejis.com", - "radio-canada.ca", - "vodafone.es", - "sky.fm", - "maturetube.com", - "virtualtourist.com", - "line25.com", - "rzeczpospolita.pl", - "megacurioso.com.br", - "beliefnet.com", - "eklablog.com", - "hbo.com", - "bsi.ir", - "fastweb.it", - "webrazzi.com", - "telam.com.ar", - "downloadming.me", - "bluefly.com", - "thewire.com", - "erotube.org", - "vt.edu", - "jsbin.com", - "ibosocial.com", - "brides.com.cn", - "jn.pt", - "togetter.com", - "olhardigital.uol.com.br", - "ebookee.org", - "socialgamenet.com", - "romaniatv.net", - "epweike.com", - "pronto.com", - "blog.pl", - "top81.cn", - "flagfox.wordpress.com", - "unionbank.com", - "visitkorea.or.kr", - "blogspot.dk", - "fermasosedi.ru", - "inmobi.com", - "abc.com.py", - "iqoo.me", - "17k.com", - "onlineapplicationsdownloads.com", - "komli.com", - "tala.ir", - "videopremium.me", - "job.ru", - "sunbiz.org", - "tw116.com", - "browserstack.com", - "youtu.be", - "yardbarker.com", - "flvmplayer.com", - "kulichki.net", - "gravity.com", - "levelclix.com", - "kissanime.com", - "insightexpressai.com", - "colorhexa.com", - "citizensbankonline.com", - "hjenglish.com", - "voeazul.com.br", - "paraskhnio.gr", - "es.tl", - "busuu.com", - "appsumo.com", - "metacrawler.com", - "ciku5.com", - "android-hilfe.de", - "laterooms.com", - "google.com.bn", - "gamefront.com", - "rev2pub.com", - "bharatiyamobile.com", - "publicidees.com", - "jossandmain.com", - "babycentre.co.uk", - "zetabux.com", - "movieweb.com", - "timescity.com", - "dnevnik.ru", - "nlcafe.hu", - "magazine3k.com", - "irancell.ir", - "kalaydo.de", - "e5.ru", - "lecai.com", - "sbs.com.au", - "sierratradingpost.com", - "girlfriendvideos.com", - "ink361.com", - "corporate-ir.net", - "allgameshome.com", - "povarenok.ru", - "typo3.org", - "turbosquid.com", - "miniurls.co", - "thinkwithgoogle.com", - "haber3.com", - "newsmeback.com", - "sipse.com", - "osxdaily.com", - "9lessons.info", - "cyclopaedia.net", - "reallifecam.com", - "gameblog.fr", - "colourbox.com", - "mixedmartialarts.com", - "prostoporno.net", - "chanel.com", - "maxim.com", - "cam4.es", - "olx.com.mx", - "newscientist.com", - "netcombo.com.br", - "serienjunkies.org", - "shablol.com", - "bnpparibasfortis.be", - "canada.com", - "timeslive.co.za", - "cinematoday.jp", - "21cineplex.com", - "bodisparking.com", - "cruisecritic.com", - "vertoz.com", - "glosbe.com", - "nstarikov.ru", - "epinions.com", - "colbertnation.com", - "marketglory.com", - "emailmeform.com", - "angloinfo.com", - "filfan.com", - "yougetsignal.com", - "broker.to", - "quickbux.net", - "gottabemobile.com", - "beyondtherack.com", - "tripadvisor.ru", - "jschina.com.cn", - "registraduria.gov.co", - "thisoldhouse.com", - "appcelerator.com", - "noticias24carabobo.com", - "skelbiu.lt", - "ru.wix.com", - "iransong.com", - "i-sux.com", - "telerama.fr", - "mydala.com", - "pia.jp", - "fusebux.com", - "biquge.com", - "microworkers.com", - "onlywire.com", - "fanbox.com", - "ambitoweb.com", - "tripadvisor.com.br", - "postgresql.org", - "telenet.be", - "thegeekstuff.com", - "primelocation.com", - "ee.co.uk", - "phoenixads.co.in", - "brigitte.de", - "360kad.com", - "kathimerini.gr", - "batoto.net", - "babebuns.com", - "webimpresion.com", - "olx.com.ng", - "which.co.uk", - "f5haber.com", - "cic.fr", - "talkfusion.com", - "ctrlq.org", - "caracol.com.co", - "wer-weiss-was.de", - "invisionzone.com", - "head-fi.org", - "thingiverse.com", - "manager-magazin.de", - "bzwbk.pl", - "f1news.ru", - "tweetreach.com", - "sj998.com", - "streetdirectory.com", - "asos.fr", - "kalahari.com", - "classiccars.com", - "bitacoras.com", - "bravotv.com", - "beanfun.com", - "bonappetit.com", - "fashionara.com", - "techdirt.com", - "newlook.com", - "iyinet.com", - "mogujie.com", - "carros.com.br", - "starfall.com", - "rp5.ru", - "pocket-lint.com", - "homeadvisor.com", - "webhostbox.net", - "cameraboys.com", - "pricerunner.com", - "worldcarfans.com", - "meganovosti.net", - "taxheaven.gr", - "freewebsitetemplates.com", - "mr90.ir", - "cheapflights.co.uk", - "bankinter.com", - "euroresidentes.com", - "bettycrocker.com", - "filmey.com", - "sheinside.com", - "2ememain.be", - "tu.tv", - "kugou.com", - "destructoid.com", - "todoist.com", - "karmaloop.com", - "appadvice.com", - "html5rocks.com", - "osdir.com", - "webisgreat.info", - "dailyblogtips.com", - "mca.gov.in", - "e-estekhdam.com", - "hlntv.com", - "proprofs.com", - "his-j.com", - "im286.com", - "mmorpg.com", - "shooshtime.com", - "terra.es", - "lpcloudbox301.com", - "tubepornstars.com", - "tableausoftware.com", - "soccersuck.com", - "websurf.ru", - "indiafreestuff.in", - "pimei.com", - "colatour.com.tw", - "fssnet.co.in", - "maxpark.com", - "foodandwine.com", - "apachefriends.org", - "standardchartered.co.in", - "waveapps.com", - "gosong.net", - "spring.me", - "weatherbug.com", - "iw33.com", - "apserver.net", - "thenationonlineng.net", - "tjournal.ru", - "greatschools.net", - "3movs.com", - "61.com", - "directpaybiz.com", - "w3snoop.com", - "jsonline.com", - "grainger.com", - "prevention.com", - "blizzard.com", - "baseball-reference.com", - "cjn.cn", - "fasthosts.co.uk", - "kym-cdn.com", - "cuponation.in", - "cam4.fr", - "lalawan67.net", - "videovantage.co", - "elimparcial.com", - "edlen24.com", - "donya-e-eqtesad.com", - "englishforums.com", - "dom2.ru", - "cinepolis.com", - "healthtap.com", - "astroawani.com", - "autosport.com", - "finalfantasyxiv.com", - "valueclickmedia.com", - "vitaminshoppe.com", - "apartmentguide.com", - "notjustok.com", - "gratispeliculas.org", - "intporn.com", - "eroticbeauties.net", - "egloos.com", - "nujij.nl", - "godvine.com", - "punishtube.com", - "wisegeek.org", - "somuch.com", - "taz.de", - "zetaboards.com", - "gravityforms.com", - "telegraf.rs", - "odn.ne.jp", - "topeleven.com", - "peekyou.com", - "razerzone.com", - "furaffinity.net", - "mobikwik.com", - "eventful.com", - "sextube.fm", - "treccani.it", - "phatograph.com", - "feedthebot.com", - "netdoctor.co.uk", - "collarme.com", - "reformal.ru", - "hemnet.se", - "jacquieetmicheltv.net", - "9ku.com", - "kraloyun.com", - "directadmin.com", - "bongda.com.vn", - "ddizi.org", - "tedata.net", - "fb.org", - "pagemodo.com", - "satu.kz", - "nodejs.org", - "tiberiumalliances.com", - "wallst.com", - "dezeen.com", - "rense.com", - "hawkhost.com", - "vonage.com", - "zjol.com.cn", - "housefun.com.tw", - "ad1.ru", - "myredbook.com", - "rarlab.com", - "audiopoisk.com", - "pbebank.com", - "whocallsme.com", - "playground.ru", - "tnr.com", - "firstdirect.com", - "xinhua.jp", - "gmane.org", - "verseriesynovelas.com", - "broadwayworld.com", - "thefrisky.com", - "rapmls.com", - "skapiec.pl", - "wholesale-dress.net", - "alison.com", - "n4hr.com", - "prefiles.com", - "vtc.vn", - "coral.co.uk", - "azyya.com", - "smithsonianmag.com", - "ticksy.com", - "theync.com", - "pcinpact.com", - "eventbrite.co.uk", - "buenosaires.gob.ar", - "a5cee7.se", - "bazingamob.com", - "pp.cc", - "shortnews.de", - "responsinator.com", - "filepost.com", - "securefreedom.com", - "notepad-plus-plus.org", - "thekrazycouponlady.com", - "apktops.ir", - "nr2.ru", - "timinternet.it", - "man.lv", - "forexpeacearmy.com", - "plius.lt", - "vcp.ir", - "mysitecost.ru", - "yourfiledownloader.com", - "dealguardian.com", - "sql.ru", - "laravel.com", - "shape5.com", - "visa.com", - "vocus.com", - "stackthatmoney.com", - "pornicom.com", - "my.tv.sohu.com/user/cc128", - "urban-rivals.com", - "robotstxt.org", - "colorlabsproject.com", - "mg.gov.br", - "local.ch", - "adbooth.net", - "se.pl", - "al-akhbar.com", - "he.net", - "covoiturage.fr", - "sakshieducation.com", - "thisdaylive.com", - "thestudentroom.co.uk", - "pzy.be", - "designyoutrust.com", - "forbes.ua", - "fandongxi.com", - "expertreviews.co.uk", - "dream-demo.com", - "barchart.com", - "ht.ly", - "burbuja.info", - "edgecastcdn.net", - "amazinglytimedphotos.com", - "value-domain.com", - "shareaholic.com", - "promptfile.com", - "voetbalzone.nl", - "ziare.com", - "trafficbroker.com", - "coolsport.tv", - "vanguardia.com.mx", - "makeshop.jp", - "mobilism.org", - "rebelmouse.com", - "brisbanetimes.com.au", - "publimetro.com.mx", - "coolkora.com", - "realsparrow.com", - "honda.co.jp", - "dealcatcher.com", - "sinoptik.ua", - "lefeng.com", - "mamaclub.com", - "bezuzyteczna.pl", - "smn.gov.ar", - "manhub.com", - "pcgameshardware.de", - "shipstation.com", - "zive.cz", - "disneystore.com", - "despegar.com.mx", - "addictivetips.com", - "path.com", - "pathofexile.com", - "seitenreport.de", - "pardot.com", - "decathlon.fr", - "flvrunner.com", - "xat.com", - "matchendirect.fr", - "roem.ru", - "wat.tv", - "edline.net", - "znds.com", - "northwestern.edu", - "friendscout24.de", - "movoto.com", - "dengiprosto.info", - "dlisted.com", - "sports.fr", - "maxifoot.fr", - "hubspot.net", - "natalie.mu", - "tabloidpulsa.co.id", - "polki.pl", - "gamasutra.com", - "matomeantena.com", - "adwords-community.com", - "gallup.com", - "redtubenacional.com", - "mangastream.com", - "zulutrade.com", - "wunderlist.com", - "taste.com.au", - "myhosting.com", - "totalbeauty.com", - "8pic.ir", - "sltrib.com", - "88db.com", - "minikoyuncu.com", - "net4.in", - "nuevoloquo.com", - "cago365.com", - "afip.gob.ar", - "keep2share.cc", - "kw.com", - "terra.com.pe", - "profi-forex.org", - "filecloud.io", - "peliculas4.com", - "mysitemyway.com", - "ilmattino.it", - "geizhals.de", - "sheershanews.com", - "whatwpthemeisthat.com", - "teknosa.com", - "myshopping.com.au", - "teamskeet.com", - "gandalfporn.com", - "2670.com", - "peoplefinders.com", - "elo7.com.br", - "sofoot.com", - "uhaul.com", - "sagepay.com", - "unb.br", - "jhu.edu", - "barrons.com", - "hasznaltauto.hu", - "winfxstrategy.com", - "spamcop.net", - "az.pl", - "op.fi", - "istruzione.it", - "eveonline.com", - "imgnip.com", - "jjoobb.cn", - "itesm.mx", - "wptavern.com", - "kproxy.com", - "pulptastic.com", - "quidco.com", - "ekantipur.com", - "joann.com", - "whattoexpect.com", - "tomshw.it", - "internetbookshop.it", - "followerwonk.com", - "cisionpoint.com", - "cint.com", - "quondos.com", - "suntimes.com", - "saveinter.net", - "eiga.com", - "jdzj.com", - "goldprice.org", - "websitemagazine.com", - "051jk.com", - "inweb24.com", - "gamgos.ae", - "elog-ch.com", - "trovit.com.mx", - "webnode.cz", - "ethnos.gr", - "oodle.com", - "subtitulos.es", - "gameinformer.com", - "9to5mac.com", - "youwatch.org", - "ibps.in", - "biggerpockets.com", - "sport24.co.za", - "my.tv.sohu.com/user/cc133", - "capsulecrm.com", - "fuett.mx", - "poznan.pl", - "melateiran.com", - "divxtotal.com", - "aftabir.com", - "cyberlink.com", - "ulozto.cz", - "jetswap.com", - "premium.wix.com", - "eprize.com", - "huntington.com", - "careerlink.vn", - "allhyipmonitors.com", - "autorambler.ru", - "jamieoliver.com", - "minube.com", - "credomatic.com", - "oddschecker.com", - "listia.com", - "mrrebates.com", - "8684.cn", - "kabam.com", - "tripit.com", - "gry.pl", - "ecvv.com", - "utanbaby.com", - "lavoixdunord.fr", - "just-eat.co.uk", - "go-for-files.com", - "afpbb.com", - "mybb.com", - "madmoizelle.com", - "sensacine.com", - "jtl-software.de", - "worldtimeserver.com", - "sunmaker.com", - "marieforleo.com", - "123sdfsdfsdfsd.ru", - "duga.jp", - "avery.com", - "tvguide.co.uk", - "salliemae.com", - "zap.com.br", - "my.tv.sohu.com/user/cc112", - "bookmark4you.com", - "twodollarclick.com", - "encontreinarede.com", - "joomshaper.com", - "marinetraffic.com", - "feedermatrix.com", - "nowvideo.at", - "millenium.org", - "newalbumreleases.net", - "frankkern.com", - "onlineconversion.com", - "ahlalhdeeth.com", - "mediawiki.org", - "xseo.in", - "generation-nt.com", - "naftemporiki.gr", - "hardforum.com", - "hornbunny.com", - "my.tv.sohu.com/user/cc124", - "housing.com", - "vogue.es", - "safemls.net", - "cuisineaz.com", - "estekhtam.com", - "coqnu.com", - "despegar.com.ar", - "fedoraproject.org", - "france2.fr", - "autovit.ro", - "tradetang.com", - "levelupgames.uol.com.br", - "dnforum.com", - "homebank.kz", - "carnival.com", - "hzycsj.com", - "army.mil", - "bootsnipp.com", - "istockimg.com", - "po-kaki-to.com", - "qiushibaike.com", - "tsb.co.uk", - "gzmama.com", - "aitnews.com", - "tripwiremagazine.com", - "torrenty.org", - "djangoproject.com", - "chelseafc.com", - "gamesgames.com", - "herold.at", - "baur.de", - "kauppalehti.fi", - "nrelate.com", - "clickwebinar.com", - "entropay.com", - "gridserver.com", - "virginia.gov", - "tuan800.com", - "trueactivist.com", - "caras.uol.com.br", - "fontawesome.io", - "haodou.com", - "reshareworthy.com", - "royalcaribbean.com", - "crakrevenue.com", - "motika.com.mk", - "xovi.de", - "deutsche-startups.de", - "inven.co.kr", - "atrapalo.com", - "ictv.ua", - "muji.net", - "kingplayer.com", - "adworkmedia.com", - "xjtu.edu.cn", - "thenounproject.com", - "professionali.ru", - "xizhi.com", - "boo-box.com", - "customink.com", - "groupon.my", - "spartoo.com", - "bannersdontwork.com", - "ncore.cc", - "reklama5.mk", - "macrojuegos.com", - "zenhabits.net", - "te3p.com", - "utah.gov", - "telesurtv.net", - "101.ru", - "5yi.com", - "lide.cz", - "ancestry.co.uk", - "sana.sy", - "siteslike.com", - "vg247.com", - "tyzhden.ua", - "ncsu.edu", - "apherald.com", - "taaza.com", - "traffic-delivery.com", - "uuyoyo.com", - "hwupgrade.it", - "game-debate.com", - "jetpack.wordpress.com", - "anycodes.com", - "femina.hu", - "zattoo.com", - "acm.org", - "comenity.net", - "tarot.com", - "azadliq.org", - "advertiserdigital.com", - "osym.gov.tr", - "empornium.me", - "netzero.net", - "myfico.com", - "nolix.ru", - "cnwnews.com", - "springpad.com", - "ahangestan.in", - "localbitcoins.com", - "nikkei.co.jp", - "youlikehits.com", - "boyfriendtv.com", - "wampserver.com", - "elnorte.com", - "codeschool.com", - "si.edu", - "nosis.com", - "downloadhelper.net", - "global-free-classified-ads.com", - "flagmantube.com", - "elnuevodiario.com.ni", - "handelsbanken.se", - "sverigesradio.se", - "femjoy.com", - "444.hu", - "calcalist.co.il", - "asiatech.ir", - "tv.nu", - "installmac.com", - "programmableweb.com", - "fotki.com", - "vidivodo.com", - "websquash.com", - "selfgrowth.com", - "wehkamp.nl", - "amawebs.com", - "3dlat.com", - "comunidades.net", - "streamin.to", - "idbi.com", - "cshtracker.com", - "cdbaby.com", - "mycommerce.com", - "united-domains.de", - "tradingview.com", - "niniweblog.com", - "avn.info.ve", - "apa.tv", - "pinnaclesports.com", - "adafruit.com", - "ipower.com", - "lebuteur.com", - "utah.edu", - "mobeoffice.com", - "lingualeo.com", - "fuub.net", - "tvmongol.com", - "namasthetelangaana.com", - "secretsearchenginelabs.com", - "whowhatwear.com", - "hiapk.com", - "torrentz.sx", - "php.su", - "sodahead.com", - "sbb.ch", - "k12.ca.us", - "jecontacte.com", - "thehollywoodgossip.com", - "pekao24.pl", - "yourtest-india.com", - "screwfix.com", - "humoron.com", - "yiwugou.com", - "mulher.uol.com.br", - "thehackernews.com", - "shopmania.ro", - "dlink.com", - "despegar.com", - "archlinux.org", - "nielsen.com", - "rosnet.ru", - "appsapk.com", - "funfarsi.ir", - "4over.com", - "subscribe.wordpress.com", - "lewrockwell.com", - "portalnet.cl", - "antenam.info", - "letribunaldunet.fr", - "see-tube.com", - "tureng.com", - "topcashback.co.uk", - "contactcars.com", - "jeux.fr", - "khan.co.kr", - "ffffound.com", - "gmail.com", - "laprensa.com.ni", - "jizzhut.com", - "liilas.com", - "muare.vn", - "kting.cn", - "heteml.jp", - "genericsteps.com", - "searchcompletion.com", - "dwayir.com", - "dicionarioinformal.com.br", - "vcita.com", - "fitsugar.com", - "kleiderkreisel.de", - "collective-evolution.com", - "ethz.ch", - "sendreach.com", - "abidjan.net", - "islamicfinder.org", - "elong.com", - "yonhapnews.co.kr", - "seratnews.ir", - "stream2watch.me", - "content-watch.ru", - "seotechnocrat.com", - "todaoferta.uol.com.br", - "toyota.jp", - "purevid.com", - "incredimail.com", - "kia.com", - "intensedebate.com", - "kaufmich.com", - "servis24.cz", - "brusheezy.com", - "rtbtraf.com", - "tejiawang.com", - "expedia.co.in", - "food52.com", - "top-channel.tv", - "jpnn.com", - "desitorrents.com", - "faxingw.cn", - "crutchfield.com", - "seneweb.com", - "usenet.nl", - "aviasales.ru", - "nesine.com", - "appshopper.com", - "dressupgamesite.com", - "lowendtalk.com", - "muslima.com", - "v-webs.com", - "linkomanija.net", - "geniuzz.com", - "caringbridge.org", - "gooya.com", - "dospy.com", - "siol.net", - "games.co.id", - "archiveofourown.org", - "rocketlawyer.com", - "free-downloadz.net", - "pastemagazine.com", - "invest-system.net", - "el-ahly.com", - "todayhumor.co.kr", - "racingpost.com", - "stereogum.com", - "soompi.com", - "pof.com.br", - "brainabundance.com", - "fontpalace.com", - "canon.jp", - "eldeforma.com", - "sacbee.com", - "jobscore.com", - "fashionista.com", - "mywork.vn", - "thisis50.com", - "cubadebate.cu", - "healthguru.com", - "instatheme.com", - "apotheken-umschau.de", - "blizko.ru", - "tinymce.com", - "virtualbox.org", - "tehran.ir", - "pr.gov.br", - "mlmleadsystempro.com", - "resbux.com", - "komonews.com", - "childrensplace.com", - "yoyopress.com", - "cloudify.cc", - "24livenewspaper.com", - "w4.com", - "islamway.net", - "fantagazzetta.com", - "imgspice.com", - "bovada.lv", - "payback.de", - "peb.pl", - "hotnigerianjobs.com", - "dev7studios.com", - "tejaratbank.net", - "takuhai.jp", - "travelmath.com", - "cultofmac.com", - "wakeupnow.com", - "insidefacebook.com", - "mediamarkt.es", - "500wan.com", - "rumah123.com", - "contentmarketinginstitute.com", - "ed.ac.uk", - "phimvang.com", - "womansday.com", - "lookatme.ru", - "citizensbank.com", - "esam.ir", - "phandroid.com", - "canadiantire.ca", - "serienjunkies.de", - "bbspink.com", - "yaranehkala.ir", - "vesti.bg", - "el-carabobeno.com", - "smarty.net", - "6tie.com", - "antpedia.com", - "p-world.co.jp", - "camelcamelcamel.com", - "sudu.cn", - "priberam.pt", - "infoworld.com", - "myrecipes.com", - "metrodeal.com", - "widgetbox.com", - "krone.at", - "outfox.tv", - "mymp4.in", - "685wo.com", - "sadanduseless.com", - "cgd.pt", - "mrmlsmatrix.com", - "parenting.com", - "tradepub.com", - "linkvehicle.com", - "mobiledia.com", - "rghost.ru", - "xxsy.net", - "goanimate.com", - "pikacn.com", - "metropcs.com", - "byu.edu", - "bitelia.com", - "designscrazed.com", - "wpde.org", - "paheal.net", - "nulled.cc", - "hmv.co.jp", - "openx.com", - "hyundai.com", - "vvvdj.com", - "reason.com", - "livesports.pl", - "polskieradio.pl", - "oszone.net", - "chinhphu.vn", - "performancehorizon.com", - "internetretailer.com", - "skoob.com.br", - "mediaworld.it", - "imgrind.com", - "bancopopular.es", - "seogadget.ru", - "m6.fr", - "rongbay.com", - "niazpardaz.com", - "rewity.com", - "ssense.com", - "sky-fire.com", - "flibusta.net", - "eat24hours.com", - "lotto.pl", - "cnw.com.cn", - "takvim.com.tr", - "englishtown.com", - "letudiant.fr", - "peliculasmas.com", - "askme.com", - "linksmanagement.com", - "webseoanalytics.com", - "presse-citron.net", - "eldiariodeamerica.com", - "instantshift.com", - "ampxchange.com", - "xe.gr", - "experts-exchange.com", - "sportcategory.com", - "sharecash.org", - "linksys.com", - "yninfo.com", - "onlinelic.in", - "aflamneek.com", - "22.cn", - "ubuntu-fr.org", - "cjs.com.cn", - "mp3clan.com", - "grani.ru", - "zen-cart.com", - "shippingchina.com", - "jsfor.net", - "wanadoo.es", - "zurker.com", - "chotot.vn", - "masaladesi.com", - "insight.ly", - "trivago.de", - "neue-sexpartner.com", - "boe.es", - "military.com", - "moonbasa.com", - "langlaoda.com", - "tnooz.com", - "zacks.com", - "liverpool.com.mx", - "internic.net", - "ecuavisa.com", - "autonews.ru", - "mcafeesecure.com", - "peopleclick.com", - "madthumbs.com", - "hot-live-chat.com", - "sugarcrm.com", - "notonthehighstreet.com", - "linio.com.co", - "smartbrief.com", - "auto-motor-und-sport.de", - "kyivpost.com", - "instantteleseminar.com", - "dillards.com", - "5i5j.com", - "runtastic.com", - "danawa.com", - "ladunliadi.blogspot.com", - "getnews.jp", - "romedic.ro", - "rodfile.com", - "instyle.com", - "swoodoo.com", - "bannersnack.com", - "evolife.cn", - "ktonanovenkogo.ru", - "office.com", - "zamalekfans.com", - "magiran.com", - "ithome.com", - "ktrmr.com", - "spoonful.com", - "olleh.com", - "bgr.in", - "industrialthemes.com", - "adbkm.com", - "tsa-algerie.com", - "bloggang.com", - "mojang.com", - "geoiptool.com", - "autocarindia.com", - "ajansspor.com", - "onmeda.de", - "midwayusa.com", - "alicdn.com", - "sportdog.gr", - "ideeli.com", - "haspa.de", - "gladbux.com", - "porn-star.com", - "experiandirect.com", - "yicheshi.com", - "acervoamador.com", - "designwall.com", - "balkanweb.com", - "response.jp", - "nettoos.com", - "beruby.com", - "manageyourloans.com", - "kidstaff.com.ua", - "indeed.co.za", - "monoprice.com", - "chsi.com.cn", - "boorsekala.com", - "mstaml.com", - "trafficvance.com", - "tatatele.in", - "startbootstrap.com", - "graphicburger.com", - "ad-vid-webs.com", - "jp.dk", - "one.co.il", - "athensvoice.gr", - "payu2blog.com", - "epidemz.net", - "dondominio.com", - "doviz.com", - "disquscdn.com", - "work.ua", - "vsemayki.ru", - "ikyu.com", - "songlyrics.com", - "onlinebank.com", - "thebump.com", - "travian.com.tr", - "java2s.com", - "twittmate.com", - "ignou.ac.in", - "relink.us", - "4738.com", - "printvenue.com", - "tekstowo.pl", - "natro.com", - "dengi-tut.info", - "freeservers.com", - "inbound.org", - "free-press-release.com", - "mydirtyhobby.com", - "gamefly.com", - "overclockers.co.uk", - "eci.nic.in", - "196.1.211.6", - "versus.com", - "batdongsan.com.vn", - "vrisko.gr", - "albayan.ae", - "trendcounter.com", - "500.com", - "pagomiscuentas.com", - "wankoz.com", - "duote.com", - "javascript.ru", - "chevrolet.com", - "coach.com", - "decidatriunfar.net", - "rememberthemilk.com", - "virginmobileusa.com", - "google.com.jm", - "ucm.es", - "ninja.co.jp", - "rqzao.com", - "periodistadigital.com", - "heritage.org", - "momtubesex.xxx", - "vocabulary.com", - "kupujemprodajem.com", - "e-cigarette-forum.com", - "paxum.com", - "ilpost.it", - "abercrombie.com", - "pearsonmylabandmastering.com", - "echoecho.com", - "expedia.co.jp", - "ticketfly.com", - "colostate.edu", - "sjtu.edu.cn", - "seobudget.ru", - "gigabyte.com", - "gsmspain.com", - "misr5.com", - "enterfactory.com", - "ciao.de", - "wuv.de", - "dagospia.com", - "slashgear.com", - "urdupoint.com", - "themepunch.com", - "travian.com", - "discuz.com", - "pixroute.com", - "otzovik.com", - "ubergizmo.com", - "edreams.fr", - "internet-positif.org", - "asmcentral.com", - "copadomundo.uol.com.br", - "adjal.com", - "gotomypc.com", - "partycity.com", - "leggo.it", - "blogosfere.it", - "teamcoco.com", - "pricedealsindia.com", - "glennbeck.com", - "allyou.com", - "china.org.cn", - "xitek.com", - "photoshopessentials.com", - "infopraca.pl", - "boardingarea.com", - "geni.com", - "rotaban.ru", - "foxtab.com", - "sadistic.pl", - "socialbro.com", - "tradesparq.com", - "itp.ne.jp", - "swefilmer.com", - "jobsite.co.uk", - "topwar.ru", - "yemeksepeti.com", - "tokfm.pl", - "businessinsider.com.au", - "moe.gov.eg", - "swedbank.lt", - "jxgdw.com", - "bayern.de", - "alistapart.com", - "bebinin.com", - "annunci69.it", - "plimus.com", - "cuevana2.tv", - "viamichelin.fr", - "whatsmydns.net", - "tarad.com", - "hostgator.com.br", - "hasbro.com", - "hi-chic.com", - "driverscollection.com", - "onetad.com", - "game2.com.cn", - "elitepvpers.com", - "tvuol.uol.com.br", - "caclubindia.com", - "diariocorreo.pe", - "c-rewards.com", - "business.gov.au", - "chooseauto.com.cn", - "timetrade.com", - "alternate.de", - "syracuse.com", - "advanceautoparts.com", - "shopware.de", - "newpct.com", - "proranktracker.com", - "cex.io", - "thebot.net", - "tradekorea.com", - "legifrance.gouv.fr", - "cpan.org", - "rightel.ir", - "247wallst.com", - "goldentowns.com", - "bankifsccode.com", - "color-hex.com", - "consumerist.com", - "juegosdiarios.com", - "on24.com", - "stockfreeimages.com", - "m4.cn", - "sponsoredtweets.com", - "open.ac.uk", - "bilyoner.com", - "lexisnexis.com", - "gsu.edu", - "popscreen.com", - "stiftung-warentest.de", - "education.com", - "leckerficken.de", - "hostinger.ru", - "staples.ca", - "greenpeace.org", - "mes-meilleurs-films.fr", - "delish.com", - "register.it", - "idiva.com", - "static.squarespace.com", - "ololo.fm", - "basketball-reference.com", - "tro-ma-ktiko.blogspot.gr", - "arabianbusiness.com", - "avianca.com", - "watchuseek.com", - "6play.fr", - "kora-online.tv", - "armagedomfilmes.biz", - "531314.com", - "craigslist.co.uk", - "inchallah.com", - "bongdaso.com", - "toprankblog.com", - "k12.com", - "itimes.com", - "html.net", - "utsandiego.com", - "gyakorikerdesek.hu", - "viddyhddownload.com", - "wannonce.com", - "qudong.com", - "ibicn.com", - "w3resource.com", - "socialsecurity.gov", - "tvn.pl", - "momsexclipz.com", - "fstoppers.com", - "kafeteria.pl", - "boulanger.fr", - "guj.nic.in", - "divaina.com", - "desktopnexus.com", - "topseda.ir", - "payumoney.com", - "klicktel.de", - "foxtv.es", - "cuatro.com", - "publix.com", - "astrosage.com", - "kompass.com", - "web-hosting.com", - "nus.edu.sg", - "jamiiforums.com", - "lancers.jp", - "peixeurbano.com.br", - "buysub.com", - "yp.com", - "enstage.com", - "6eat.com", - "1ent.com.cn", - "unionpaysecure.com", - "pcgames.de", - "ccidcom.com", - "lavenir.net", - "novaposhta.ua", - "hotpornshow.com", - "telebank.ru", - "avaz.ba", - "doit.com.cn", - "setlinks.ru", - "zagat.com", - "sportmaster.ru", - "utarget.ru", - "lingualeo.ru", - "compucalitv.com", - "anastasiadate.com", - "webmaster-rank.info", - "fastcoexist.com", - "lavasoft.com", - "ppvguru.com", - "greatist.com", - "knack.be", - "wowwiki.com", - "ilcorsaronero.info", - "jword.jp", - "750g.com", - "pantipmarket.com", - "top.de", - "photofunia.com", - "dryicons.com", - "alweeam.com.sa", - "dnfight.com", - "wpolityce.pl", - "vimeocdn.com", - "visit-x.net", - "takungpao.com", - "perfectworld.eu", - "kat.ph", - "hefei.cc", - "cmse.ru", - "virginia.edu", - "fudan.edu.cn", - "sethgodin.typepad.com", - "caracaschronicles.com", - "18qt.com", - "be2.com.br", - "rakuten.tw", - "bukkit.org", - "miss-no1.com", - "nts.org.pk", - "ulozto.net", - "mixpanel.com", - "glavred.info", - "vui.vn", - "mindspark.com", - "worldmarket.com", - "walmart.com.mx", - "deperu.com", - "taxact.com", - "m5zn.com", - "navy.mil", - "hibapress.com", - "cpasbien.com", - "interjet.com.mx", - "llbean.com", - "kenrockwell.com", - "japan-guide.com", - "financialpost.com", - "rankingsinstitute.com", - "master-x.com", - "pandawill.com", - "marketingweek.co.uk", - "freeforums.org", - "ysear.ch", - "pokerstars.com", - "wired.co.uk", - "amino.dk", - "rapidcrush.com", - "vivanuncios.com", - "blogsvertise.com", - "cwb.gov.tw", - "piter.tv", - "gistmania.com", - "topdocumentaryfilms.com", - "shoghlanty.com", - "bankmillennium.pl", - "burberry.com", - "youporngay.com", - "webresourcesdepot.com", - "beachbody.com", - "asstr.org", - "pwc.com", - "competitor.com", - "rss2search.com", - "vocuspr.com", - "behindthename.com", - "moniker.com", - "jayde.com", - "opensuse.org", - "poemhunter.com", - "toranoana.jp", - "interaksyon.com", - "aeon.co.jp", - "gungho.jp", - "fgov.be", - "xpg.uol.com.br", - "logic-immo.com", - "worldsex.com", - "watchonlineseries.eu", - "google.co.mz", - "discas.net", - "chmail.ir", - "consumercomplaints.in", - "allstate.com", - "twelveskip.com", - "ibibo.com", - "noelshack.com", - "bonprix.ru", - "directupload.net", - "equipobimlatino.com", - "weather2umbrella.com", - "aibang.com", - "blog.wordpress.com", - "turner.com", - "mediapart.fr", - "bloog.pl", - "monotaro.com", - "online.net", - "bodmillenium.com", - "distancesfrom.com", - "naosalvo.com.br", - "ap7am.com", - "focus.ua", - "cokeandpopcorn.ch", - "qwant.com", - "megaplan.ru", - "sinhvienit.net", - "dream-marriage.com", - "voicefive.com", - "forex.com.cn", - "xabbs.com", - "netmums.com", - "tuxboard.com", - "cs-cart.com", - "bitcoin.it", - "boblil.com", - "nirsoft.net", - "neopets.com", - "spin.com", - "costco.ca", - "mirraw.com", - "ara.cat", - "klamm.de", - "glam.com", - "guenstiger.de", - "citruspay.com", - "dnslink.com", - "guyism.com", - "shopotam.ru", - "tim.it", - "3suisses.fr", - "gooroops.com", - "kau.edu.sa", - "ukbusinessforums.co.uk", - "gree.jp", - "komikid.com", - "redakcja.pl", - "qpic.cn", - "voyeurweb.com", - "mathworks.com", - "monster.fr", - "seniat.gob.ve", - "computrabajo.com.co", - "xilu.com", - "madrid.org", - "ostraining.com", - "bharian.com.my", - "telegram.org", - "sumofus.org", - "whosdatedwho.com", - "moreofit.com", - "meetic.it", - "femina.mk", - "itworld.com", - "indiaglitz.com", - "cheatcc.com", - "filmfanatic.com", - "the-bux.net", - "very.co.uk", - "fetishshrine.com", - "speakingtree.in", - "iu.edu", - "modern.az", - "tak.ru", - "internetmarketingninjas.com", - "example.com", - "sportgeza.hu", - "wrestlezone.com", - "jameda.de", - "caikuu.com", - "gioco.it", - "yourtv.com.au", - "euro.com.pl", - "anz.co.nz", - "daft.ie", - "tirerack.com", - "vivareal.com.br", - "definebabe.com", - "ittefaq.com.bd", - "lastfm.es", - "zocalo.com.mx", - "dpd.de", - "somethingawful.com", - "virgin.com", - "shtyle.fm", - "viralforest.com", - "dntrck.com", - "its-mo.com", - "q.cc", - "kinghost.net", - "elpais.com.co", - "joomlaspanish.org", - "sopitas.com", - "wallbase.cc", - "cpalead.com", - "torrentfunk.com", - "bizcom.com.ru", - "quizony.com", - "rcgroups.com", - "spring.io", - "kuaidi100.com", - "xatakandroid.com", - "mlstatic.com", - "borsaat.com", - "jagobd.com", - "cosmiq.de", - "crucial.com", - "cdstm.cn", - "betclic.fr", - "telewebion.com", - "exhentai.org", - "gnezdo.ru", - "cebupacificair.com", - "fusionmls.com", - "shafaf.ir", - "ticketmaster.co.uk", - "adslzone.net", - "k8.cn", - "recipdonor.com", - "in.gov", - "mforos.com", - "asscj.com", - "linkconnector.com", - "ohfreesex.com", - "cntraveler.com", - "scambioetico.org", - "ladenzeile.de", - "ntn24.com", - "beyazperde.com", - "motherearthnews.com", - "yupptv.com", - "220tube.com", - "fizzle.co", - "lakii.com", - "deutsche-wirtschafts-nachrichten.de", - "saaid.net", - "bimlatino.com", - "verisign.com", - "funpatogh.com", - "matadornetwork.com", - "seatguru.com", - "lululemon.com", - "uzise.com", - "networkworld.com", - "hottube.me", - "jobsdb.com.hk", - "life.hu", - "bonusvid.com", - "incometaxindiaefiling.gov.in", - "ey.com", - "alraimedia.com", - "allposters.com", - "authorityroi.com", - "bmwusa.com", - "ebaystatic.com", - "entertainmentcrave.com", - "ehow.com.br", - "prisonplanet.com", - "elnashra.com", - "email.cz", - "yes123.com.tw", - "uitzendinggemist.nl", - "mindtools.com", - "atv.com.tr", - "shoes.net.cn", - "joomlaportal.de", - "themoneyconverter.com", - "meteomedia.com", - "bankaustria.at", - "advertise.com", - "trafficswarm.com", - "aztecaporno.com", - "fourseasons.com", - "movie-blog.org", - "govdelivery.com", - "didigames.com", - "invideo.biz", - "linux.org.ru", - "omelete.uol.com.br", - "babybus.cn", - "oursogo.com", - "ero-an.com", - "mediafax.ro", - "football.ua", - "sii.cl", - "dreamamateurs.com", - "cheaperthandirt.com", - "iplocation.net", - "insideview.com", - "hihe.vn", - "stop-sex.com", - "fubiz.net", - "url.org", - "greenmangaming.com", - "pornup.me", - "indofeed.com", - "forumhouse.ru", - "restaurant.com", - "key.com", - "windstream.net", - "brightedge.com", - "foreignpolicy.com", - "noticiasdatv.uol.com.br", - "logopond.com", - "datemule.com", - "webrootanywhere.com", - "stomp.com.sg", - "trthaber.com", - "bitterstrawberry.com", - "turbo.az", - "kbs.co.kr", - "joblo.com", - "seatimes.com.vn", - "kuwait.tt", - "258.com", - "kp.ua", - "moviesmobile.net", - "flamingtext.com", - "youngt.com", - "etradenow.cn", - "copart.com", - "tuanweihui.com", - "zinkwaphd.com", - "adsl.free.fr", - "infomaniak.ch", - "re-direcciona.me", - "mejorenvo.com", - "instantservice.com", - "harpersbazaar.com", - "colorado.edu", - "belboon.com", - "telelistas.net", - "photofans.cn", - "51seer.com", - "danjur.com", - "wunderweib.de", - "extratorrentlive.com", - "serpfox.com", - "androidkade.com", - "raja.ir", - "tampabay.com", - "ser-mujer.org", - "imasters.com.br", - "coachfactory.com", - "mojopages.com", - "makezine.com", - "forexschoolonline.com", - "bochk.com", - "siamsport.co.th", - "mdpr.jp", - "serialssolutions.com", - "videosexarchive.com", - "enlnks.com", - "cision.com", - "scratchinginfo.com", - "skidrowgames.net", - "optimizely.com", - "video2brain.com", - "ariva.de", - "audiomack.com", - "pimproll.com", - "house.gov", - "acs.org", - "pijamasurf.com", - "autoc-one.jp", - "southcn.com", - "vesti.az", - "300mbfilms.com", - "speedmystream.com", - "wooservers.com", - "siteliner.com", - "tinmoi.vn", - "extremepornvideos.com", - "cqsq.com", - "hello-today.com", - "turkcealtyazi.org", - "tvyo.com", - "dealmoon.com", - "openenglish.com", - "golfchannel.com", - "irancloob.com", - "ebs.in", - "portalcorreio.uol.com.br", - "beemp3s.org", - "condenast.com", - "mtwebcenters.com.tw", - "hatelabo.jp", - "pathci.net", - "mamsy.ru", - "noticiasdelmundo.org", - "guru3d.com", - "logomaker.com", - "adhitz.com", - "swiki.jp", - "turnitin.com", - "patoghu.com", - "carnaval.uol.com.br", - "cancer.org", - "clickprime8.com", - "fahrinfo-berlin.de", - "unisender.com", - "flashkhor.com", - "goodfon.ru", - "ethiotube.net", - "cunbang.com", - "ti-da.net", - "1phads.com", - "bien.hu", - "home77.com", - "mbabycare.com", - "vudu.com", - "fantasy8.com", - "landrover.com", - "opencartforum.ru", - "antena3.ro", - "getapp.com", - "torlock.com", - "wind.it", - "expatads.com", - "bloglines.com", - "sexytube.me", - "frontier.com", - "asandownload.com", - "groupon.pl", - "storesonlinepro.com", - "brands4friends.de", - "infogr.am", - "webeffector.ru", - "google.com.mm", - "ppchero.com", - "privacystar.com", - "ocregister.com", - "liex.ru", - "kopatheme.com", - "toggl.com", - "raywenderlich.com", - "hecha.cn", - "vpls.net", - "manpianyi.com", - "1881.no", - "scbeasy.com", - "plex.tv", - "selfridges.com", - "anumex.com", - "postplanner.com", - "thisiscolossal.com", - "you-will-date.com", - "idealist.org", - "emarketer.com", - "anibis.ch", - "dansmovies.com", - "footballitarin.com", - "fragrantica.com", - "10minutemail.com", - "ntu.edu.tw", - "clasicooo.com", - "onsugar.com", - "vr-zone.com", - "walkerplus.com", - "easymobilerecharge.com", - "cz001.com.cn", - "sportsseoul.com", - "inazumanews2.com", - "marketingdirecto.com", - "chartboost.com", - "unblocked.co", - "rhymezone.com", - "portalinmobiliario.com", - "afrointroductions.com", - "transunion.com", - "panorama.it", - "powershow.com", - "avval.ir", - "onlinemeetingnow.com", - "xoom.com", - "wnbc.com", - "tlen.pl", - "jetairways.com", - "vtb24.ru", - "offcn.com", - "crx7601.com", - "adverts.ie", - "kasserver.com", - "minhavida.com.br", - "jkpj.com", - "123contactform.com", - "imgtiger.com", - "folha.com.br", - "npcgo.com", - "semprot.com", - "moonfruit.com", - "jizzbell.com", - "online-stopwatch.com", - "allhiphop.com", - "hackaday.com", - "digitalplayground.com", - "careers24.com", - "cwq.com", - "wondershare.com", - "filesend.to", - "puromarketing.com", - "workopolis.com", - "mudainodocument.com", - "home.ne.jp", - "shorte.st", - "tanea.gr", - "sporza.be", - "vgorode.ua", - "google.co.zm", - "argumentua.com", - "3m.com", - "komputerswiat.pl", - "bongdaplus.vn", - "supersonicads.com", - "soundclick.com", - "lollipop-network.com", - "lpcloudsvr304.com", - "313.cn", - "rtl2.de", - "ts.cn", - "mglradio.com", - "diynetwork.com", - "komikcaps.net", - "all-that-is-interesting.com", - "ultipro.com", - "frombar.com", - "sitedeals.nl", - "codingforums.com", - "kansascity.com", - "twtrland.com", - "cengage.com", - "lolspotsarticles.com", - "jackthreads.com", - "jobstreet.com.sg", - "diffen.com", - "eme2000.com", - "superbru.com", - "droid-life.com", - "itb-berlin.de", - "estibot.com", - "yourepeat.com", - "112.ua", - "70e.com", - "grid.mk", - "cromaretail.com", - "jobstreet.com.ph", - "gloadmarket.com", - "gemius.com", - "huuto.net", - "vogue.it", - "divxonline.info", - "mytoys.de", - "cashnhits.com", - "minkchan.com", - "talabat.com", - "helpareporter.com", - "grandascent.com", - "catalunyacaixa.com", - "sparwelt.de", - "tvboxnow.com", - "imagecurl.org", - "coocan.jp", - "eatingwell.com", - "truelife.com", - "binaryoptionsbrands.com", - "foxsportsla.com", - "jjshouse.com", - "makaan.com", - "yamaha.com", - "activerain.com", - "excelforum.com", - "mobinnet.ir", - "kasikornbankgroup.com", - "googleplex.com", - "medianama.com", - "fullsail.edu", - "makeupandbeauty.com", - "marketwired.com", - "beachbodycoach.com", - "taloussanomat.fi", - "youngliving.us", - "dana.ir", - "adsgostar.com", - "esquire.com.cn", - "meyerweb.com", - "positivemed.com", - "harvestapp.com", - "tim.com.br", - "sumorobo.net", - "zbigz.com", - "schulferien.org", - "quzhao.com", - "tsinghua.edu.cn", - "vogue.com", - "ecrater.com", - "internetbs.net", - "oper.ru", - "kingstone.com.tw", - "olympic.org", - "code.org", - "wp.tv", - "adchakra.net", - "passarela.com.br", - "damn.com", - "spn.com.cn", - "sacitaslan.com", - "uplod.ir", - "kununu.com", - "englishclub.com", - "ibood.com", - "buzzfed.com", - "peopledaily.com.cn", - "vivastreet.it", - "adshostnet.com", - "npmjs.org", - "lovethatsex.com", - "garena.tw", - "hq-sex-tube.com", - "tvsubtitles.net", - "trademarkia.com", - "96down.com", - "morhipo.com", - "chuguoqu.com", - "free-css.com", - "getsecuredfiles.com", - "justia.com", - "paypal-community.com", - "wezoner.com", - "google-analytics.com", - "outsideonline.com", - "simplymeasured.com", - "wattsupwiththat.com", - "vancl.com", - "leadership.ng", - "plaisio.gr", - "fastcocreate.com", - "fewo-direkt.de", - "dedecms.com", - "bostonherald.com", - "elmundo.com.ve", - "idhostinger.com", - "animaljam.com", - "infoq.com", - "exler.ru", - "leprosorium.ru", - "avis.com", - "ulusalpost.com", - "namnak.com", - "goindigo.in", - "activeboard.com", - "fatsecret.com", - "4umf.com", - "porn-w.org", - "sarkariexam.co.in", - "patagonia.com", - "3u5.net", - "roshd.ir", - "netechangisme.com", - "ojogo.pt", - "ujipin.com", - "topuniversities.com", - "consequenceofsound.net", - "no-ip.biz", - "webdesignerwall.com", - "fin24.com", - "openculture.com", - "pbh2.com", - "dota2.com", - "secureupload.eu", - "alfajertv.com", - "canlidizihdtv.com", - "muffingroup.com", - "imageforum.com", - "paris.fr", - "kaufda.de", - "pelis24.com", - "ixian.cn", - "ebenpagan.com", - "sportsauthority.com", - "wish.com", - "ganeshaspeaks.com", - "meritnation.com", - "ijie.com", - "vodafone.com.tr", - "trovit.es", - "farsisubtitle.com", - "musawvir.com", - "resellerratings.com", - "soyentrepreneur.com", - "samakal.net", - "dietnavi.com", - "55tuan.com", - "elcomercio.com", - "hereisthecity.com", - "buienradar.nl", - "arenabg.com", - "indiansexstories.net", - "slideboom.com", - "findsection.net", - "rankrecon.com", - "e-radio.gr", - "cnn.co.jp", - "gucci.com", - "natura.net", - "googlesyndication.com", - "advancedwebranking.com", - "lib.ru", - "sfora.pl", - "uci.edu", - "haaretz.co.il", - "ing.be", - "yokboylebirsey.com.tr", - "myfact.tv", - "yenibiris.com", - "stuff.tv", - "dn.pt", - "whydontyoutrythis.com", - "nediyor.com", - "worldoftanks.asia", - "megamillions.com", - "elemanonline.net", - "computrabajo.com.pe", - "arxiv.org", - "livescore.tv", - "aintitcool.com", - "girlschannel.net", - "madbid.com", - "tadawul.com.sa", - "liqpay.com", - "softonic.jp", - "alhilal.com", - "bizpowa.com", - "thatguywiththeglasses.com", - "yemeneconomist.com", - "pazar3.mk", - "repai.com", - "1jux.net", - "solvusoft.com", - "yotpo.com", - "cuantocabron.com", - "ba.gov.br", - "arin.net", - "loginza.ru", - "homebank.ro", - "0755car.com", - "carscoops.com", - "antarvasna.com", - "tizag.com", - "offerpop.com", - "techmeme.com", - "ipress.ua", - "emuparadise.me", - "sexvidx.com", - "whatseek.com", - "become.co.jp", - "snapfish.com", - "gsis.gr", - "speedyshare.com", - "uncrate.com", - "doda.jp", - "straighttalk.com", - "rsjoomla.com", - "vozpopuli.com", - "gotprint.net", - "finansbank.com.tr", - "chinatrust.com.tw", - "stratoserver.net", - "icnetwork.co.uk", - "getpopcornti.me", - "pornper.com", - "3dmgame.com", - "squirt.org", - "mbusa.com", - "katespade.com", - "skat.dk", - "radiko.jp", - "dexonline.ro", - "bicaps.net", - "bitsoma.com", - "brasil247.com", - "alittlemarket.com", - "bd-pratidin.com", - "amorincontro.com", - "bigxvideos.com", - "nissan.co.jp", - "incomediary.com", - "theranking.com", - "el7l.co", - "webcamtoy.com", - "steamgifts.com", - "miles-and-more.com", - "szonline.net", - "blocked-website.com", - "kaztorka.org", - "avforums.com", - "indulgy.com", - "extendcp.co.uk", - "yonkis.com", - "ad1111.com", - "unionbankph.com", - "job.com", - "samanepay.com", - "aceona.com", - "kar.nic.in", - "tipico.com", - "sa.ae", - "froma.com", - "songza.com", - "calciomercato.com", - "besaba.com", - "x-rates.com", - "arsys.es", - "sisal.it", - "amateur.tv", - "designyourway.net", - "alpha.gr", - "nimble.com", - "livefreefun.com", - "wipo.int", - "webssearches.com", - "vodjk.com", - "91tiger.com", - "swisscom.com", - "tuvaro.com", - "parsonline.net", - "uolhost.com.br", - "cnwest.com", - "roksa.pl", - "socialmention.com", - "unibytes.com", - "screamingfrog.co.uk", - "owncloud.org", - "jacquielawson.com", - "openclipart.org", - "zimbra.com", - "poczta-polska.pl", - "hayah.cc", - "ringtonematcher.com", - "emai.com", - "wealink.com", - "celebzen.com", - "pichost.me", - "rediffmail.com", - "dinos.co.jp", - "netvasco.com.br", - "meilele.com", - "career.ru", - "signupgenius.com", - "screencast-o-matic.com", - "nav.no", - "reactiongifs.com", - "italki.com", - "mo.gov", - "bandsintown.com", - "elwatan.com", - "jdate.com", - "quiente.net", - "skynet.be", - "googlekeywordtool.com", - "nubilefilms.com", - "memedeportes.com", - "rewardingzonez.com", - "litmus.com", - "iyaxin.com", - "collegeconfidential.com", - "semperplugins.com", - "sofort.com", - "ineedhits.com", - "live24.gr", - "acronymfinder.com", - "jobui.com", - "9show.com", - "thedirty.com", - "tsutaya.co.jp", - "9787.com", - "brighthouse.com", - "boxingscene.com", - "indeed.com.br", - "morazzia.com", - "privatejobshub.blogspot.in", - "searchenginepeople.com", - "pozdravok.ru", - "watchstore.com.cn", - "rts.ch", - "pluska.sk", - "villagevoice.com", - "sprintrade.com", - "conversionxl.com", - "evsuite.com", - "bci.cl", - "lampsplus.com", - "gossipcop.com", - "valuecommerce.com", - "zalora.co.id", - "fastshop.com.br", - "hockeysfuture.com", - "bootply.com", - "chinavasion.com", - "menards.com", - "kinobar.net", - "tokyodisneyresort.jp", - "knownhost.com", - "ozbargain.com.au", - "olx.com.ve", - "sgk.gov.tr", - "berliner-sparkasse.de", - "bancogalicia.com.ar", - "joomla-master.org", - "augsburger-allgemeine.de", - "kroger.com", - "pulse.ng", - "putlocker.com", - "jrtj.com", - "tapuz.co.il", - "madhyamam.com", - "donews.com", - "showhaber.com", - "allxnxx.com", - "uned.es", - "adsharebux.com", - "d-addicts.com", - "banki.ir", - "levi.com", - "e97527f0.se", - "entertainmentwise.com", - "xvideos-field.com", - "naver.net", - "urbia.de", - "fashionsfriend.com", - "emuch.net", - "yelp.fr", - "metatube.com", - "sina.com.hk", - "omb100.com", - "grameenphone.com", - "stylebook.de", - "funny-games.biz", - "googlewebmastercentral.blogspot.com", - "vogella.com", - "surveymonkey.net", - "forex4you.org", - "mex.tl", - "online-fish-games.com", - "millenniumbcp.pt", - "fileom.com", - "friendorfollow.com", - "downloads.nl", - "typekit.com", - "gongkong.com", - "iqoption.com", - "tori.fi", - "smartsource.com", - "1616.net", - "1shoppingcart.com", - "novosti.rs", - "yofond.com", - "idokep.hu", - "motor.ru", - "xbiao.com", - "colorcombos.com", - "pway.cn", - "egynews.net", - "elshaab.org", - "telus.com", - "olx.com.co", - "cctvcj.com", - "kpopstarz.com", - "razorsocial.com", - "ncrypt.in", - "zonetheme.com", - "gumroad.com", - "e-shop.gr", - "kugli.com", - "levif.be", - "bookfi.org", - "globalresearch.ca", - "sas.com", - "cloudaccess.net", - "uplooder.net", - "exposedwebcams.com", - "1prime.ru", - "webappers.com", - "crocko.com", - "remax.com", - "ikco.com", - "dinside.no", - "winbank.gr", - "mijnwoordenboek.nl", - "weatherzone.com.au", - "allday2.com", - "sunat.gob.pe", - "getit.in", - "entrance-exam.net", - "i2ya.com", - "tlife.gr", - "qyer.com", - "calibre-ebook.com", - "internetcorkboard.com", - "unitedhyipleague.com", - "spyrestudios.com", - "metal-archives.com", - "aeromexico.com", - "cv-library.co.uk", - "bdr1.net", - "aremo.com.br", - "blip.tv", - "afilio.com.br", - "renewalcoupons.com", - "proxfree.com", - "magix.com", - "jobs.net", - "souism.com", - "adtcstrk.com", - "goodhousekeeping.com", - "lastfm.ru", - "sharecare.com", - "porn.xxx", - "deathandtaxesmag.com", - "unocero.com", - "wer-kennt-wen.de", - "hotfrog.com", - "intraship.de", - "press24.mk", - "yournewscorner.com", - "rbc.com", - "eventure.com", - "minglebox.com", - "legendas.tv", - "drp.su", - "voicefrom.me", - "venezuelaaldia.com", - "cooks.com", - "numbeo.com", - "chilehardware.cl", - "cryptocointalk.com", - "venusfactor.com", - "recruitmentcareer.in", - "larazon.es", - "sptechs.com", - "asx.com.au", - "ahlife.com", - "st001.com", - "actudesfinances.info", - "talkarcades.com", - "nitori-net.jp", - "chinahr.com", - "websitetestlink.com", - "hypem.com", - "demorgen.be", - "sharefile.com", - "prensalibre.com", - "eldia.com.ar", - "billiger.de", - "3docean.net", - "streamsend.com", - "tuaw.com", - "portafolio.co", - "trivago.com", - "olxpix.com", - "geotrust.com", - "torrentgun.net", - "enha.kr", - "pcastuces.com", - "t.cn", - "dimsemenov.com", - "cam4.nl", - "basspro.com", - "macupdate.com", - "strawpoll.me", - "elintransigente.com", - "homeaway.co.uk", - "my.ecwid.com", - "graphpaperpress.com", - "architonic.com", - "flowplayer.org", - "syshl.com", - "18schoolgirlz.com" - }); - - return urls; -} diff --git a/src/beast/example/http-crawl/urls_large_data.hpp b/src/beast/example/http-crawl/urls_large_data.hpp deleted file mode 100644 index da4d8eb5337..00000000000 --- a/src/beast/example/http-crawl/urls_large_data.hpp +++ /dev/null @@ -1,16 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_EXAMPLE_HTTP_CRAWL_URLS_LARGE_DATA_HPP -#define BEAST_EXAMPLE_HTTP_CRAWL_URLS_LARGE_DATA_HPP - -#include - -std::vector const& -urls_large_data(); - -#endif diff --git a/src/beast/example/http-server-fast/CMakeLists.txt b/src/beast/example/http-server-fast/CMakeLists.txt deleted file mode 100644 index 5668ec1bd20..00000000000 --- a/src/beast/example/http-server-fast/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -# Part of Beast - -GroupSources(include/beast beast) -GroupSources(example/common common) -GroupSources(example/http-server-fast "/") - -add_executable (http-server-fast - ${BEAST_INCLUDES} - ${COMMON_INCLUDES} - fields_alloc.hpp - http_server_fast.cpp -) - -target_link_libraries(http-server-fast - Beast - ${Boost_FILESYSTEM_LIBRARY} - ) - diff --git a/src/beast/example/http-server-fast/Jamfile b/src/beast/example/http-server-fast/Jamfile deleted file mode 100644 index 3285b7ac175..00000000000 --- a/src/beast/example/http-server-fast/Jamfile +++ /dev/null @@ -1,13 +0,0 @@ -# -# Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -# -# 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) -# - -exe http-server-fast : - http_server_fast.cpp - : - coverage:no - ubasan:no - ; diff --git a/src/beast/example/http-server-fast/fields_alloc.hpp b/src/beast/example/http-server-fast/fields_alloc.hpp deleted file mode 100644 index 7550ccb00d7..00000000000 --- a/src/beast/example/http-server-fast/fields_alloc.hpp +++ /dev/null @@ -1,195 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_EXAMPLE_FIELDS_ALLOC_HPP -#define BEAST_EXAMPLE_FIELDS_ALLOC_HPP - -#include -#include -#include -#include - -namespace detail { - -struct static_pool -{ - std::size_t size_; - std::size_t refs_ = 1; - std::size_t count_ = 0; - char* p_; - - char* - end() - { - return reinterpret_cast(this+1) + size_; - } - - explicit - static_pool(std::size_t size) - : size_(size) - , p_(reinterpret_cast(this+1)) - { - } - -public: - static - static_pool& - construct(std::size_t size) - { - auto p = new char[sizeof(static_pool) + size]; - return *(new(p) static_pool{size}); - } - - static_pool& - share() - { - ++refs_; - return *this; - } - - void - destroy() - { - if(refs_--) - return; - this->~static_pool(); - delete[] reinterpret_cast(this); - } - - void* - alloc(std::size_t n) - { - auto last = p_ + n; - if(last >= end()) - BOOST_THROW_EXCEPTION(std::bad_alloc{}); - ++count_; - auto p = p_; - p_ = last; - return p; - } - - void - dealloc() - { - if(--count_) - return; - p_ = reinterpret_cast(this+1); - } -}; - -} // detail - -/** A non-thread-safe allocator optimized for @ref basic_fields. - - This allocator obtains memory from a pre-allocated memory block - of a given size. It does nothing in deallocate until all - previously allocated blocks are deallocated, upon which it - resets the internal memory block for re-use. - - To use this allocator declare an instance persistent to the - connection or session, and construct with the block size. - A good rule of thumb is 20% more than the maximum allowed - header size. For example if the application only allows up - to an 8,000 byte header, the block size could be 9,600. - - Then, for every instance of `message` construct the header - with a copy of the previously declared allocator instance. -*/ -template -struct fields_alloc -{ - detail::static_pool& pool_; - -public: - using value_type = T; - using is_always_equal = std::false_type; - using pointer = T*; - using reference = T&; - using const_pointer = T const*; - using const_reference = T const&; - using size_type = std::size_t; - using difference_type = std::ptrdiff_t; - - template - struct rebind - { - using other = fields_alloc; - }; - - explicit - fields_alloc(std::size_t size) - : pool_(detail::static_pool::construct(size)) - { - } - - fields_alloc(fields_alloc const& other) - : pool_(other.pool_.share()) - { - } - - template - fields_alloc(fields_alloc const& other) - : pool_(other.pool_.share()) - { - } - - ~fields_alloc() - { - pool_.destroy(); - } - - value_type* - allocate(size_type n) - { - return static_cast( - pool_.alloc(n * sizeof(T))); - } - - void - deallocate(value_type*, size_type) - { - pool_.dealloc(); - } - -#if defined(BOOST_LIBSTDCXX_VERSION) && BOOST_LIBSTDCXX_VERSION < 60000 - template - void - construct(U* ptr, Args&&... args) - { - ::new((void*)ptr) U(std::forward(args)...); - } - - template - void - destroy(U* ptr) - { - ptr->~U(); - } -#endif - - template - friend - bool - operator==( - fields_alloc const& lhs, - fields_alloc const& rhs) - { - return &lhs.pool_ == &rhs.pool_; - } - - template - friend - bool - operator!=( - fields_alloc const& lhs, - fields_alloc const& rhs) - { - return ! (lhs == rhs); - } -}; - -#endif diff --git a/src/beast/example/http-server-fast/http_server_fast.cpp b/src/beast/example/http-server-fast/http_server_fast.cpp deleted file mode 100644 index bdcea2843fd..00000000000 --- a/src/beast/example/http-server-fast/http_server_fast.cpp +++ /dev/null @@ -1,310 +0,0 @@ -// -// Copyright (c) 2017 Christopher M. Kohlhoff (chris at kohlhoff dot com) -// -// 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) -// - -#include "fields_alloc.hpp" - -#include "../common/mime_types.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace ip = boost::asio::ip; // from -using tcp = boost::asio::ip::tcp; // from -namespace http = beast::http; // from - -class http_worker -{ -public: - http_worker(http_worker const&) = delete; - http_worker& operator=(http_worker const&) = delete; - - http_worker(tcp::acceptor& acceptor, const std::string& doc_root) : - acceptor_(acceptor), - doc_root_(doc_root) - { - } - - void start() - { - accept(); - check_deadline(); - } - -private: - using alloc_t = fields_alloc; - using request_body_t = http::basic_dynamic_body>; - - // The acceptor used to listen for incoming connections. - tcp::acceptor& acceptor_; - - // The path to the root of the document directory. - std::string doc_root_; - - // The socket for the currently connected client. - tcp::socket socket_{acceptor_.get_io_service()}; - - // The buffer for performing reads - beast::static_buffer_n<8192> buffer_; - - // The allocator used for the fields in the request and reply. - alloc_t alloc_{8192}; - - // The parser for reading the requests - boost::optional> parser_; - - // The timer putting a time limit on requests. - boost::asio::basic_waitable_timer request_deadline_{ - acceptor_.get_io_service(), (std::chrono::steady_clock::time_point::max)()}; - - // The string-based response message. - boost::optional>> string_response_; - - // The string-based response serializer. - boost::optional>> string_serializer_; - - // The file-based response message. - boost::optional>> file_response_; - - // The file-based response serializer. - boost::optional>> file_serializer_; - - void accept() - { - // Clean up any previous connection. - beast::error_code ec; - socket_.close(ec); - buffer_.consume(buffer_.size()); - - acceptor_.async_accept( - socket_, - [this](beast::error_code ec) - { - if (ec) - { - accept(); - } - else - { - // Request must be fully processed within 60 seconds. - request_deadline_.expires_from_now( - std::chrono::seconds(60)); - - read_request(); - } - }); - } - - void read_request() - { - // On each read the parser needs to be destroyed and - // recreated. We store it in a boost::optional to - // achieve that. - // - // Arguments passed to the parser constructor are - // forwarded to the message object. A single argument - // is forwarded to the body constructor. - // - // We construct the dynamic body with a 1MB limit - // to prevent vulnerability to buffer attacks. - // - parser_.emplace( - std::piecewise_construct, - std::make_tuple(), - std::make_tuple(alloc_)); - - http::async_read( - socket_, - buffer_, - *parser_, - [this](beast::error_code ec) - { - if (ec) - accept(); - else - process_request(parser_->get()); - }); - } - - void process_request(http::request> const& req) - { - switch (req.method()) - { - case http::verb::get: - send_file(req.target()); - break; - - default: - // We return responses indicating an error if - // we do not recognize the request method. - send_bad_response( - http::status::bad_request, - "Invalid request-method '" + req.method_string().to_string() + "'\r\n"); - break; - } - } - - void send_bad_response( - http::status status, - std::string const& error) - { - string_response_.emplace( - std::piecewise_construct, - std::make_tuple(), - std::make_tuple(alloc_)); - - string_response_->result(status); - string_response_->set(http::field::server, "Beast"); - string_response_->set(http::field::connection, "close"); - string_response_->set(http::field::content_type, "text/plain"); - string_response_->body = error; - string_response_->prepare_payload(); - - string_serializer_.emplace(*string_response_); - - http::async_write( - socket_, - *string_serializer_, - [this](beast::error_code ec) - { - socket_.shutdown(tcp::socket::shutdown_send, ec); - string_serializer_.reset(); - string_response_.reset(); - accept(); - }); - } - - void send_file(beast::string_view target) - { - // Request path must be absolute and not contain "..". - if (target.empty() || target[0] != '/' || target.find("..") != std::string::npos) - { - send_bad_response( - http::status::not_found, - "File not found\r\n"); - return; - } - - std::string full_path = doc_root_; - full_path.append( - target.data(), - target.size()); - - http::file_body::value_type file; - beast::error_code ec; - file.open( - full_path.c_str(), - beast::file_mode::read, - ec); - if(ec) - { - send_bad_response( - http::status::not_found, - "File not found\r\n"); - return; - } - - file_response_.emplace( - std::piecewise_construct, - std::make_tuple(), - std::make_tuple(alloc_)); - - file_response_->result(http::status::ok); - file_response_->set(http::field::server, "Beast"); - file_response_->set(http::field::connection, "close"); - file_response_->set(http::field::content_type, mime_type(target.to_string())); - file_response_->body = std::move(file); - file_response_->prepare_payload(); - - file_serializer_.emplace(*file_response_); - - http::async_write( - socket_, - *file_serializer_, - [this](beast::error_code ec) - { - socket_.shutdown(tcp::socket::shutdown_send, ec); - file_serializer_.reset(); - file_response_.reset(); - accept(); - }); - } - - void check_deadline() - { - // The deadline may have moved, so check it has really passed. - if (request_deadline_.expires_at() <= std::chrono::steady_clock::now()) - { - // Close socket to cancel any outstanding operation. - beast::error_code ec; - socket_.close(); - - // Sleep indefinitely until we're given a new deadline. - request_deadline_.expires_at( - std::chrono::steady_clock::time_point::max()); - } - - request_deadline_.async_wait( - [this](beast::error_code) - { - check_deadline(); - }); - } -}; - -int main(int argc, char* argv[]) -{ - try - { - // Check command line arguments. - if (argc != 6) - { - std::cerr << "Usage: http_server_fast
{spin|block}\n"; - std::cerr << " For IPv4, try:\n"; - std::cerr << " http_server_fast 0.0.0.0 80 . 100 block\n"; - std::cerr << " For IPv6, try:\n"; - std::cerr << " http_server_fast 0::0 80 . 100 block\n"; - return EXIT_FAILURE; - } - - auto address = ip::address::from_string(argv[1]); - unsigned short port = static_cast(std::atoi(argv[2])); - std::string doc_root = argv[3]; - int num_workers = std::atoi(argv[4]); - bool spin = (std::strcmp(argv[5], "spin") == 0); - - boost::asio::io_service ios{1}; - tcp::acceptor acceptor{ios, {address, port}}; - - std::list workers; - for (int i = 0; i < num_workers; ++i) - { - workers.emplace_back(acceptor, doc_root); - workers.back().start(); - } - - if (spin) - for (;;) ios.poll(); - else - ios.run(); - } - catch (const std::exception& e) - { - std::cerr << "Exception: " << e.what() << std::endl; - return EXIT_FAILURE; - } -} diff --git a/src/beast/example/http-server-small/CMakeLists.txt b/src/beast/example/http-server-small/CMakeLists.txt deleted file mode 100644 index dfb1ade71c1..00000000000 --- a/src/beast/example/http-server-small/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -# Part of Beast - -GroupSources(include/beast beast) - -GroupSources(example/http-server-small "/") - -add_executable (http-server-small - ${BEAST_INCLUDES} - http_server_small.cpp -) - -target_link_libraries(http-server-small - Beast - ) - diff --git a/src/beast/example/http-server-small/Jamfile b/src/beast/example/http-server-small/Jamfile deleted file mode 100644 index 2acfe2cb116..00000000000 --- a/src/beast/example/http-server-small/Jamfile +++ /dev/null @@ -1,13 +0,0 @@ -# -# Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -# -# 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) -# - -exe http-server-small : - http_server_small.cpp - : - coverage:no - ubasan:no - ; diff --git a/src/beast/example/http-server-small/http_server_small.cpp b/src/beast/example/http-server-small/http_server_small.cpp deleted file mode 100644 index f73c7734b0f..00000000000 --- a/src/beast/example/http-server-small/http_server_small.cpp +++ /dev/null @@ -1,240 +0,0 @@ -// -// Copyright (c) 2017 Christopher M. Kohlhoff (chris at kohlhoff dot com) -// -// 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) -// - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace ip = boost::asio::ip; // from -using tcp = boost::asio::ip::tcp; // from -namespace http = beast::http; // from - -namespace my_program_state -{ - std::size_t - request_count() - { - static std::size_t count = 0; - return ++count; - } - - std::time_t - now() - { - return std::time(0); - } -} - -class http_connection : public std::enable_shared_from_this -{ -public: - http_connection(tcp::socket socket) - : socket_(std::move(socket)) - { - } - - // Initiate the asynchronous operations associated with the connection. - void - start() - { - read_request(); - check_deadline(); - } - -private: - // The socket for the currently connected client. - tcp::socket socket_; - - // The buffer for performing reads. - beast::flat_buffer buffer_{8192}; - - // The request message. - http::request request_; - - // The response message. - http::response response_; - - // The timer for putting a deadline on connection processing. - boost::asio::basic_waitable_timer deadline_{ - socket_.get_io_service(), std::chrono::seconds(60)}; - - // Asynchronously receive a complete request message. - void - read_request() - { - auto self = shared_from_this(); - - http::async_read( - socket_, - buffer_, - request_, - [self](beast::error_code ec) - { - if(!ec) - self->process_request(); - }); - } - - // Determine what needs to be done with the request message. - void - process_request() - { - response_.version = 11; - response_.set(http::field::connection, "close"); - - switch(request_.method()) - { - case http::verb::get: - response_.result(http::status::ok); - response_.set(http::field::server, "Beast"); - create_response(); - break; - - default: - // We return responses indicating an error if - // we do not recognize the request method. - response_.result(http::status::bad_request); - response_.set(http::field::content_type, "text/plain"); - beast::ostream(response_.body) - << "Invalid request-method '" - << request_.method_string().to_string() - << "'"; - break; - } - - write_response(); - } - - // Construct a response message based on the program state. - void - create_response() - { - if(request_.target() == "/count") - { - response_.set(http::field::content_type, "text/html"); - beast::ostream(response_.body) - << "\n" - << "Request count\n" - << "\n" - << "

Request count

\n" - << "

There have been " - << my_program_state::request_count() - << " requests so far.

\n" - << "\n" - << "\n"; - } - else if(request_.target() == "/time") - { - response_.set(http::field::content_type, "text/html"); - beast::ostream(response_.body) - << "\n" - << "Current time\n" - << "\n" - << "

Current time

\n" - << "

The current time is " - << my_program_state::now() - << " seconds since the epoch.

\n" - << "\n" - << "\n"; - } - else - { - response_.result(http::status::not_found); - response_.set(http::field::content_type, "text/plain"); - beast::ostream(response_.body) << "File not found\r\n"; - } - } - - // Asynchronously transmit the response message. - void - write_response() - { - auto self = shared_from_this(); - - response_.set(http::field::content_length, response_.body.size()); - - http::async_write( - socket_, - response_, - [self](beast::error_code ec) - { - self->socket_.shutdown(tcp::socket::shutdown_send, ec); - self->deadline_.cancel(); - }); - } - - // Check whether we have spent enough time on this connection. - void - check_deadline() - { - auto self = shared_from_this(); - - deadline_.async_wait( - [self](beast::error_code ec) - { - if(!ec) - { - // Close socket to cancel any outstanding operation. - self->socket_.close(ec); - } - }); - } -}; - -// "Loop" forever accepting new connections. -void -http_server(tcp::acceptor& acceptor, tcp::socket& socket) -{ - acceptor.async_accept(socket, - [&](beast::error_code ec) - { - if(!ec) - std::make_shared(std::move(socket))->start(); - http_server(acceptor, socket); - }); -} - -int -main(int argc, char* argv[]) -{ - try - { - // Check command line arguments. - if(argc != 3) - { - std::cerr << "Usage: " << argv[0] << "
\n"; - std::cerr << " For IPv4, try:\n"; - std::cerr << " receiver 0.0.0.0 80\n"; - std::cerr << " For IPv6, try:\n"; - std::cerr << " receiver 0::0 80\n"; - return EXIT_FAILURE; - } - - auto address = ip::address::from_string(argv[1]); - unsigned short port = static_cast(std::atoi(argv[2])); - - boost::asio::io_service ios{1}; - - tcp::acceptor acceptor{ios, {address, port}}; - tcp::socket socket{ios}; - http_server(acceptor, socket); - - ios.run(); - } - catch(std::exception const& e) - { - std::cerr << "Exception: " << e.what() << std::endl; - return EXIT_FAILURE; - } -} diff --git a/src/beast/example/http-server-threaded/CMakeLists.txt b/src/beast/example/http-server-threaded/CMakeLists.txt deleted file mode 100644 index a11dbfa055e..00000000000 --- a/src/beast/example/http-server-threaded/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# Part of Beast - -GroupSources(include/beast beast) -GroupSources(example/common common) -GroupSources(example/http-server-threaded "/") - -add_executable (http-server-threaded - ${BEAST_INCLUDES} - ${COMMON_INCLUDES} - http_server_threaded.cpp -) - -target_link_libraries(http-server-threaded - Beast - ${Boost_FILESYSTEM_LIBRARY} - ) - diff --git a/src/beast/example/http-server-threaded/Jamfile b/src/beast/example/http-server-threaded/Jamfile deleted file mode 100644 index f2f5f16e544..00000000000 --- a/src/beast/example/http-server-threaded/Jamfile +++ /dev/null @@ -1,13 +0,0 @@ -# -# Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -# -# 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) -# - -exe http-server-threaded : - http_server_threaded.cpp - : - coverage:no - ubasan:no - ; diff --git a/src/beast/example/http-server-threaded/http_server_threaded.cpp b/src/beast/example/http-server-threaded/http_server_threaded.cpp deleted file mode 100644 index e75b3796b62..00000000000 --- a/src/beast/example/http-server-threaded/http_server_threaded.cpp +++ /dev/null @@ -1,227 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#include "../common/mime_types.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//------------------------------------------------------------------------------ -// -// Example: HTTP server, synchronous, one thread per connection -// -//------------------------------------------------------------------------------ - -namespace ip = boost::asio::ip; // from -using tcp = boost::asio::ip::tcp; // from -namespace http = beast::http; // from - -class connection - : public std::enable_shared_from_this -{ - tcp::socket sock_; - beast::string_view root_; - -public: - explicit - connection(tcp::socket&& sock, beast::string_view root) - : sock_(std::move(sock)) - , root_(root) - { - } - - void - run() - { - // Bind a shared_ptr to *this into the thread. - // When the thread exits, the connection object - // will be destroyed. - // - std::thread{&connection::do_run, shared_from_this()}.detach(); - } - -private: - // Send a client error response - http::response> - client_error(http::status result, beast::string_view text) - { - http::response> res{result, 11}; - res.set(http::field::server, BEAST_VERSION_STRING); - res.set(http::field::content_type, "text/plain"); - res.set(http::field::connection, "close"); - res.body = text; - res.prepare_payload(); - return res; - } - - // Return an HTTP Not Found response - // - http::response - not_found() const - { - http::response res{http::status::not_found, 11}; - res.set(http::field::server, BEAST_VERSION_STRING); - res.set(http::field::content_type, "text/html"); - res.set(http::field::connection, "close"); - res.body = "The file was not found"; - res.prepare_payload(); - return res; - } - - // Return an HTTP Server Error - // - http::response - server_error(beast::error_code const& ec) const - { - http::response res{http::status::internal_server_error, 11}; - res.set(http::field::server, BEAST_VERSION_STRING); - res.set(http::field::content_type, "text/html"); - res.set(http::field::connection, "close"); - res.body = "Error: " + ec.message(); - res.prepare_payload(); - return res; - } - - // Return a file response to an HTTP GET request - // - http::response - get(boost::filesystem::path const& full_path, - beast::error_code& ec) const - { - http::response res; - res.set(http::field::server, BEAST_VERSION_STRING); - res.set(http::field::content_type, mime_type(full_path)); - res.set(http::field::connection, "close"); - res.body.open(full_path.string().c_str(), beast::file_mode::scan, ec); - if(ec) - return res; - res.set(http::field::content_length, res.body.size()); - return res; - } - - // Handle a request - template - void - do_request(http::request const& req, beast::error_code& ec) - { - // verb must be get - if(req.method() != http::verb::get) - { - http::write(sock_, client_error(http::status::bad_request, "Unsupported method"), ec); - return; - } - - // Request path must be absolute and not contain "..". - if( req.target().empty() || - req.target()[0] != '/' || - req.target().find("..") != std::string::npos) - { - http::write(sock_, client_error(http::status::not_found, "File not found"), ec); - return; - } - - auto full_path = root_.to_string(); - full_path.append(req.target().data(), req.target().size()); - - beast::error_code file_ec; - auto res = get(full_path, file_ec); - - if(file_ec == beast::errc::no_such_file_or_directory) - { - http::write(sock_, not_found(), ec); - } - else if(ec) - { - http::write(sock_, server_error(file_ec), ec); - } - else - { - http::serializer sr{res}; - http::write(sock_, sr, ec); - } - } - - void - do_run() - { - try - { - beast::error_code ec; - beast::flat_buffer buffer; - for(;;) - { - http::request_parser parser; - parser.header_limit(8192); - parser.body_limit(1024 * 1024); - http::read(sock_, buffer, parser, ec); - if(ec == http::error::end_of_stream) - break; - if(ec) - throw beast::system_error{ec}; - do_request(parser.get(), ec); - if(ec) - { - if(ec != http::error::end_of_stream) - throw beast::system_error{ec}; - break; - } - } - sock_.shutdown(tcp::socket::shutdown_both, ec); - if(ec && ec != boost::asio::error::not_connected) - throw beast::system_error{ec}; - } - catch (const std::exception& e) - { - std::cerr << "Exception: " << e.what() << std::endl; - } - } -}; - -int main(int argc, char* argv[]) -{ - try - { - // Check command line arguments. - if (argc != 4) - { - std::cerr << "Usage: http_server
\n"; - std::cerr << " For IPv4, try:\n"; - std::cerr << " receiver 0.0.0.0 80 .\n"; - std::cerr << " For IPv6, try:\n"; - std::cerr << " receiver 0::0 80 .\n"; - return EXIT_FAILURE; - } - - auto address = ip::address::from_string(argv[1]); - unsigned short port = static_cast(std::atoi(argv[2])); - std::string doc_root = argv[3]; - - boost::asio::io_service ios{1}; - tcp::acceptor acceptor{ios, {address, port}}; - for(;;) - { - tcp::socket sock{ios}; - acceptor.accept(sock); - std::make_shared(std::move(sock), doc_root)->run(); - } - } - catch (const std::exception& e) - { - std::cerr << "Exception: " << e.what() << std::endl; - return EXIT_FAILURE; - } -} diff --git a/src/beast/example/server-framework/CMakeLists.txt b/src/beast/example/server-framework/CMakeLists.txt deleted file mode 100644 index c111c3529b8..00000000000 --- a/src/beast/example/server-framework/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -# Part of Beast - -GroupSources(include/beast beast) - -GroupSources(example/server-framework "/") -GroupSources(example/common "common") - -file(GLOB_RECURSE SERVER_INCLUDES - ${PROJECT_SOURCE_DIR}/example/server-framework/*.hpp - ) - -add_executable (server-framework - ${BEAST_INCLUDES} - ${COMMON_INCLUDES} - ${SERVER_INCLUDES} - main.cpp -) - -target_link_libraries( - server-framework - Beast - ${Boost_PROGRAM_OPTIONS_LIBRARY} - ${Boost_FILESYSTEM_LIBRARY}) - -if (OPENSSL_FOUND) - target_link_libraries(server-framework ${OPENSSL_LIBRARIES}) -endif() diff --git a/src/beast/example/server-framework/Jamfile b/src/beast/example/server-framework/Jamfile deleted file mode 100644 index 80d0406ba9c..00000000000 --- a/src/beast/example/server-framework/Jamfile +++ /dev/null @@ -1,13 +0,0 @@ -# -# Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -# -# 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) -# - -exe server-framework : - main.cpp - : - coverage:no - ubasan:no - ; diff --git a/src/beast/example/server-framework/README.md b/src/beast/example/server-framework/README.md deleted file mode 100644 index 25bdc411517..00000000000 --- a/src/beast/example/server-framework/README.md +++ /dev/null @@ -1,159 +0,0 @@ -Beast - -# HTTP and WebSocket built on Boost.Asio in C++11 - -## Server-Framework - -This example is a complete, multi-threaded server built with Beast. -It contains the following components - -* WebSocket ports (synchronous and asynchronous) - - Echoes back any message received - - Plain or SSL (if OpenSSL available) - -* HTTP ports (synchronous and asynchronous) - - Serves files from a configurable directory on GET request - - Responds to HEAD requests with the appropriate result - - Routes WebSocket Upgrade requests to a WebSocket port - - Handles Expect: 100-continue - - Supports pipelined requests - - Plain or SSL (if OpenSSL available) - -* Multi-Port: Plain, OpenSSL, HTTP, WebSocket **All on the same port!** - -The server is designed to use modular components that users may simply copy -into their own project to get started quickly. Two concepts are introduced: - -## PortHandler - -The **PortHandler** concept defines an algorithm for handling incoming -connections received on a listening socket. The example comes with a -total of *nine* port handlers! - -| Type | Plain | SSL | -| ----- | ----------------- | ------------------ | -| Sync | `http_sync_port` | `https_sync_port` | -| | `ws_sync_port` | `wss_sync_port` | -| Async | `http_async_port` | `https_async_port` | -| | `wss_sync_port` | `wss_async_port` | -| | `multi_port` | `multi_port` | - - -A port handler takes the stream object resulting form an incoming connection -request and constructs a handler-specific connection object which provides -the desired behavior. - -The HTTP ports which come with the example have a system built in which allows -installation of framework and user-defined "HTTP services". These services -inform connections using the port on how to handle specific requests. This is -similar in concept to an "HTTP router" which is an element of most modern -servers. - -These HTTP services are represented by the **Service** concept, and managed -in a container holding a type-list, called a `service_list`. Each HTTP port -allows the sevice list to be defined at compile-time and initialized at run -time. The framework provides these services: - -* `file_service` Produces HTTP responses delivering files from a system path - -* `ws_upgrade_service` Transports a connection requesting a WebSocket Upgrade -to a websocket port handler. - -## Relationship - -This diagram shows the relationship of the server object, to the nine -ports created in the example program, and the HTTP services contained by -the HTTP ports: - -ServerFramework - -## PortHandler Requirements -```C++ -/** An synchronous WebSocket @b PortHandler which implements echo. - - This is a port handler which accepts WebSocket upgrade HTTP - requests and implements the echo protocol. All received - WebSocket messages will be echoed back to the remote host. -*/ -struct PortHandler -{ - /** Accept a TCP/IP socket. - - This function is called when the server has accepted an - incoming connection. - - @param sock The connected socket. - - @param ep The endpoint of the remote host. - */ - void - on_accept( - socket_type&& sock, - endpoint_type ep); -}; -``` - -## Service Requirements - -```C++ -struct Service -{ - /** Initialize the service - - @param ec Set to the error, if any occurred - */ - void - init(error_code& ec); - - /** Maybe respond to an HTTP request - - Upon handling the response, the service may optionally - take ownership of either the stream, the request, or both. - - @param stream The stream representing the connection - - @param ep The remote endpoint of the stream - - @param req The HTTP request - - @param send A function object which operates on a single - argument of type beast::http::message. The function object - has this equivalent signature: - @code - template - void send(beast::http::response&& res); - @endcode - - @return `true` if the service handled the response. - */ - template< - class Stream, - class Body, class Fields, - class Send> - bool - respond( - Stream&& stream, - endpoint_type const& ep, - beast::http::request&& req, - Send const& send) const -}; -``` - -## Upgrade Service Requirements - -To work with the `ws_upgrade_service`, a port or handler needs -this signature: -```C++ - -struct UpgradePort -{ - template - void - on_upgrade( - Stream&& stream, - endpoint_type ep, - beast::http::request&& req); - -``` diff --git a/src/beast/example/server-framework/file_service.hpp b/src/beast/example/server-framework/file_service.hpp deleted file mode 100644 index 8c7056d8d30..00000000000 --- a/src/beast/example/server-framework/file_service.hpp +++ /dev/null @@ -1,279 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_EXAMPLE_SERVER_FILE_SERVICE_HPP -#define BEAST_EXAMPLE_SERVER_FILE_SERVICE_HPP - -#include "framework.hpp" -#include "../common/mime_types.hpp" - -#include -#include -#include -#include -#include - -#include - -#include - -namespace framework { - -/** An HTTP service which delivers files from a root directory. - - This service will accept GET and HEAD requests for files, - and deliver them as responses. The service constructs with - the location on the file system to act as the root for the - tree of files to serve. - - Meets the requirements of @b Service -*/ -class file_service -{ - // The path to serve files from - boost::filesystem::path root_; - - // The name to use in the Server HTTP field - std::string server_; - -public: - /** Constructor - - @param root A path with files to serve. A GET request - for "/" will try to deliver the file "/index.html". - - @param The string to use in the Server HTTP field. - */ - explicit - file_service( - boost::filesystem::path const& root, - beast::string_view server) - : root_(root) - , server_(server) - { - } - - /** Initialize the service. - - This provides an opportunity for the service to perform - initialization which may fail, while reporting an error - code instead of throwing an exception from the constructor. - - @note This is needed for to meet the requirements for @b Service - */ - void - init(error_code& ec) - { - // This is required by the error_code specification - // - ec = {}; - } - - /** Try to handle a file request. - - @param stream The stream belonging to the connection. - Ownership is not transferred. - - @param ep The remote endpoint of the connection - corresponding to the stream. - - @param req The request message to attempt handling. - Ownership is not transferred. - - @param send The function to invoke with the response. - The function will have this equivalent signature: - - @code - - template - void - send(response&&); - - @endcode - - In C++14 this can be expressed using a generic lambda. In - C++11 it will require a template member function of an invocable - object. - - @return `true` if the request was handled by the service. - */ - template< - class Stream, - class Body, class Fields, - class Send> - bool - respond( - Stream&&, - endpoint_type const& ep, - beast::http::request&& req, - Send const& send) const - { - boost::ignore_unused(ep); - - // Determine our action based on the method - switch(req.method()) - { - case beast::http::verb::get: - { - // For GET requests we deliver the actual file - boost::filesystem::path rel_path(req.target().to_string()); - - // Give them the root web page if the target is "/" - if(rel_path == "/") - rel_path = "/index.html"; - - // Calculate full path from root - boost::filesystem::path full_path = root_ / rel_path; - - beast::error_code ec; - auto res = get(req, full_path, ec); - - if(ec == beast::errc::no_such_file_or_directory) - { - send(not_found(req, rel_path)); - } - else if(ec) - { - send(server_error(req, rel_path, ec)); - } - else - { - send(std::move(*res)); - } - - // Indicate that we handled the request - return true; - } - - case beast::http::verb::head: - { - // We are just going to give them the headers they - // would otherwise get, but without the body. - boost::filesystem::path rel_path(req.target().to_string()); - if(rel_path == "/") - rel_path = "/index.html"; - - // Calculate full path from root - boost::filesystem::path full_path = root_ / rel_path; - - beast::error_code ec; - auto res = head(req, full_path, ec); - - if(ec == beast::errc::no_such_file_or_directory) - { - send(not_found(req, rel_path)); - } - else if(ec) - { - send(server_error(req, rel_path, ec)); - } - else - { - send(std::move(*res)); - } - - // Indicate that we handled the request - return true; - } - - default: - break; - } - - // We didn't handle this request, so return false to - // inform the service list to try the next service. - // - return false; - } - -private: - // Return an HTTP Not Found response - // - template - beast::http::response - not_found( - beast::http::request const& req, - boost::filesystem::path const& rel_path) const - { - boost::ignore_unused(rel_path); - beast::http::response res; - res.version = req.version; - res.result(beast::http::status::not_found); - res.set(beast::http::field::server, server_); - res.set(beast::http::field::content_type, "text/html"); - res.body = "The file was not found"; // VFALCO append rel_path - res.prepare_payload(); - return res; - } - - // Return an HTTP Server Error - // - template - beast::http::response - server_error( - beast::http::request const& req, - boost::filesystem::path const& rel_path, - error_code const& ec) const - { - boost::ignore_unused(rel_path); - beast::http::response res; - res.version = req.version; - res.result(beast::http::status::internal_server_error); - res.set(beast::http::field::server, server_); - res.set(beast::http::field::content_type, "text/html"); - res.body = "Error: " + ec.message(); - res.prepare_payload(); - return res; - } - - // Return a file response to an HTTP GET request - // - template - boost::optional> - get( - beast::http::request const& req, - boost::filesystem::path const& full_path, - beast::error_code& ec) const - { - beast::http::response res; - res.version = req.version; - res.set(beast::http::field::server, server_); - res.set(beast::http::field::content_type, mime_type(full_path)); - res.body.open(full_path.string().c_str(), beast::file_mode::scan, ec); - if(ec) - return boost::none; - res.set(beast::http::field::content_length, res.body.size()); - return {std::move(res)}; - } - - // Return a response to an HTTP HEAD request - // - template - boost::optional> - head( - beast::http::request const& req, - boost::filesystem::path const& full_path, - beast::error_code& ec) const - { - beast::http::response res; - res.version = req.version; - res.set(beast::http::field::server, server_); - res.set(beast::http::field::content_type, mime_type(full_path)); - - // Use a manual file body here - beast::http::file_body::value_type body; - body.open(full_path.string().c_str(), beast::file_mode::scan, ec); - if(ec) - return boost::none; - res.set(beast::http::field::content_length, body.size()); - return {std::move(res)}; - } -}; - -} // framework - -#endif diff --git a/src/beast/example/server-framework/framework.hpp b/src/beast/example/server-framework/framework.hpp deleted file mode 100644 index 6c288c93ab0..00000000000 --- a/src/beast/example/server-framework/framework.hpp +++ /dev/null @@ -1,53 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_EXAMPLE_SERVER_FRAMEWORK_HPP -#define BEAST_EXAMPLE_SERVER_FRAMEWORK_HPP - -#include -#include -#include -#include -#include - -/** The framework namespace - - This namespace contains all of the identifiers in the - server-framework system. Here we import some commonly - used types for brevity. -*/ -namespace framework { - -// This is our own base from member idiom written for C++11 -// which is simple and works around a glitch in boost's version. -// -template -class base_from_member -{ -public: - template - explicit - base_from_member(Args&&... args) - : member(std::forward(args)...) - { - } - -protected: - T member; -}; - -using error_code = boost::system::error_code; -using socket_type = boost::asio::ip::tcp::socket; -using strand_type = boost::asio::io_service::strand; -using address_type = boost::asio::ip::address_v4; -using endpoint_type = boost::asio::ip::tcp::endpoint; -using acceptor_type = boost::asio::ip::tcp::acceptor; -using io_service_type = boost::asio::io_service; - -} // framework - -#endif diff --git a/src/beast/example/server-framework/http_async_port.hpp b/src/beast/example/server-framework/http_async_port.hpp deleted file mode 100644 index 7231ca7c418..00000000000 --- a/src/beast/example/server-framework/http_async_port.hpp +++ /dev/null @@ -1,653 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_EXAMPLE_SERVER_HTTP_ASYNC_PORT_HPP -#define BEAST_EXAMPLE_SERVER_HTTP_ASYNC_PORT_HPP - -#include "server.hpp" - -#include "http_base.hpp" -#include "service_list.hpp" - -#include "../common/rfc7231.hpp" -#include "../common/write_msg.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace framework { - -// Base class for a type-erased, queued asynchronous HTTP write operation -// -struct queued_http_write -{ - // Destructor must be virtual since we delete a - // derived class through a pointer to the base! - // - virtual ~queued_http_write() = default; - - // When invoked, performs the write operation. - virtual void invoke() = 0; -}; - -/* This implements an object which, when invoked, writes an HTTP - message asynchronously to the stream. These objects are used - to form a queue of outgoing messages for pipelining. The base - class type-erases the message so the queue can hold messsages - of different types. -*/ -template< - class Stream, - bool isRequest, class Body, class Fields, - class Handler> -class queued_http_write_impl : public queued_http_write -{ - // The stream to write to - Stream& stream_; - - // The message to send, which we acquire by move or copy - beast::http::message msg_; - - // The handler to invoke when the send completes. - Handler handler_; - -public: - // Constructor. - // - // Ownership of the message is transferred into the object - // - template - queued_http_write_impl( - Stream& stream, - beast::http::message&& msg, - DeducedHandler&& handler) - : stream_(stream) - , msg_(std::move(msg)) - , handler_(std::forward(handler)) - { - } - - // Writes the stored message. - // - // The caller must make sure this invocation represents - // a continuation of an asynchronous operation which is - // already in the right context. For example, already - // running on the associated strand. - // - void - invoke() override - { - async_write_msg( - stream_, - std::move(msg_), - std::move(handler_)); - } -}; - -// This helper function creates a queued_http_write -// object and returns it inside a unique_ptr. -// -template< - class Stream, - bool isRequest, class Body, class Fields, - class Handler> -std::unique_ptr -make_queued_http_write( - Stream& stream, - beast::http::message&& msg, - Handler&& handler) -{ - return std::unique_ptr{ - new queued_http_write_impl< - Stream, - isRequest, Body, Fields, - typename std::decay::type>{ - stream, - std::move(msg), - std::forward(handler)}}; -} - -//------------------------------------------------------------------------------ - -/** An asynchronous HTTP connection. - - This base class implements an HTTP connection object using - asynchronous calls. - - It uses the Curiously Recurring Template pattern (CRTP) where - we refer to the derived class in order to access the stream object - to use for reading and writing. This lets the same class be used - for plain and SSL stream objects. - - @tparam Services The list of services this connection will support. -*/ -template -class async_http_con_base : public http_base -{ -protected: - // This function lets us access members of the derived class - Derived& - impl() - { - return static_cast(*this); - } - - // The stream to use for logging - std::ostream& log_; - - // The services configured for the port - service_list const& services_; - - // A small unique integer for logging - std::size_t id_; - - // The remote endpoint. We cache it here because - // calls to remote_endpoint() can fail / throw. - // - endpoint_type ep_; - - // The buffer for performing reads - beast::flat_buffer buffer_; - - // The parser for reading the requests - boost::optional> parser_; - - // This is the queue of outgoing messages - std::vector> queue_; - - // Indicates if we have a write active. - bool writing_ = false; - - // The strand makes sure that our data is - // accessed from only one thread at a time. - // - strand_type strand_; - -public: - // Constructor - async_http_con_base( - beast::string_view server_name, - std::ostream& log, - service_list const& services, - std::size_t id, - endpoint_type const& ep) - : http_base(server_name) - , log_(log) - , services_(services) - , id_(id) - , ep_(ep) - - // The buffer has a limit of 8192, otherwise - // the server is vulnerable to a buffer attack. - // - , buffer_(8192) - - , strand_(impl().stream().get_io_service()) - { - } - - // Called to start the object after the listener accepts - // an incoming connection, when no bytes have been read yet. - // - void - run() - { - // Just call run with an empty buffer - run(boost::asio::null_buffers{}); - } - - // Called to start the object after the - // listener accepts an incoming connection. - // - template - void - run(ConstBufferSequence const& buffers) - { - // Copy the data into the buffer for performing - // HTTP reads, so that the bytes get used. - // - buffer_.commit(boost::asio::buffer_copy( - buffer_.prepare(boost::asio::buffer_size(buffers)), - buffers)); - - // Give the derived class a chance to do stuff - // - impl().do_handshake(); - } - -protected: - void - do_run() - { - do_read_header(); - } - - // Called when a failure occurs - // - void - fail(std::string what, error_code ec) - { - // Don't log operation aborted since those happen normally. - // - if(ec && ec != boost::asio::error::operation_aborted) - { - log_ << - "[#" << id_ << " " << ep_ << "] " << - what << ": " << ec.message() << std::endl; - } - } - - // Perform an asynchronous read for the next request header - // - void - do_read_header() - { - // On each read the parser needs to be destroyed and - // recreated. We store it in a boost::optional to - // achieve that. - // - // Arguments passed to the parser constructor are - // forwarded to the message object. A single argument - // is forwarded to the body constructor. - // - // We construct the dynamic body with a 1MB limit - // to prevent vulnerability to buffer attacks. - // - parser_.emplace(std::piecewise_construct, std::make_tuple(1024 * 1024)); - - // Read just the header - beast::http::async_read_header( - impl().stream(), - buffer_, - *parser_, - strand_.wrap(std::bind( - &async_http_con_base::on_read_header, - impl().shared_from_this(), - std::placeholders::_1))); - } - - // This lambda is passed to the service list to handle - // the case of sending request objects of varying types. - // In C++14 this is more easily accomplished using a generic - // lambda, but we want C+11 compatibility so we manually - // write the lambda out. - // - struct send_lambda - { - // holds "this" - async_http_con_base& self_; - - public: - // capture "this" - explicit - send_lambda(async_http_con_base& self) - : self_(self) - { - } - - // sends a message - template - void - operator()(beast::http::response&& res) const - { - self_.do_write(std::move(res)); - } - }; - - // Called when the header has been read in - void - on_read_header(error_code ec) - { - // This happens when the other end closes gracefully - // - if(ec == beast::http::error::end_of_stream) - { - // VFALCO what about the write queue? - return impl().do_shutdown(); - } - - // On failure we just return, the shared_ptr that is bound - // into the completion will go out of scope and eventually - // this will get destroyed. - // - if(ec) - return fail("on_read", ec); - - // The parser holds the request object, - // at this point it only has the header in it. - auto& req = parser_->get(); - - send_lambda send{*this}; - - // See if they are specifying Expect: 100-continue - // - if(rfc7231::is_expect_100_continue(req)) - { - // They want to know if they should continue, - // so send the appropriate response. - // - send(this->continue_100(req)); - } - - // Read the rest of the message, if any. - // - beast::http::async_read( - impl().stream(), - buffer_, - *parser_, - strand_.wrap(std::bind( - &async_http_con_base::on_read, - impl().shared_from_this(), - std::placeholders::_1))); - } - - // Called when the message is complete - void - on_read(error_code ec) - { - // Shouldn't be getting end_of_stream here; - // that would mean that we got an incomplete - // message, counting as an error. - // - if(ec) - return fail("on_read", ec); - - // Grab a reference to the request again - auto& req = parser_->get(); - - // Create a variable for our send - // lambda since we use it more than once. - // - send_lambda send{*this}; - - // Give each service a chance to handle the request - // - if(! services_.respond( - std::move(impl().stream()), - ep_, - std::move(req), - send)) - { - // No service handled the request, - // send a Bad Request result to the client. - // - send(this->bad_request(req)); - } - else - { - // See if the service that handled the - // response took ownership of the stream. - // - if(! impl().stream().lowest_layer().is_open()) - { - // They took ownership so just return and - // let this async_http_con_base object get destroyed. - // - return; - } - } - - // VFALCO Right now we do unlimited pipelining which - // can lead to unbounded resource consumption. - // A more sophisticated server might only issue - // this read when the queue is below some limit. - // - - // Start reading another header - do_read_header(); - } - - // This function either queues a message or - // starts writing it if no other writes are taking place. - // - template - void - do_write(beast::http::response&& res) - { - // See if a write is in progress - if(! writing_) - { - // An assert or two to keep things sane when - // writing asynchronous code can be very helpful. - BOOST_ASSERT(queue_.empty()); - - // We're going to be writing so set the flag - writing_ = true; - - // And now perform the write - return async_write_msg( - impl().stream(), - std::move(res), - strand_.wrap(std::bind( - &async_http_con_base::on_write, - impl().shared_from_this(), - std::placeholders::_1))); - } - - // Queue is not empty, so append this message to the queue. - // It will be sent late when the queue empties. - // - queue_.emplace_back(make_queued_http_write( - impl().stream(), - std::move(res), - strand_.wrap(std::bind( - &async_http_con_base::on_write, - impl().shared_from_this(), - std::placeholders::_1)))); - } - - // Called when a message finishes writing - void - on_write(error_code ec) - { - // Make sure our state is what we think it is - BOOST_ASSERT(writing_); - - // This happens when we send an HTTP message - // whose semantics indicate that the connection - // should be closed afterwards. For example if - // we send a Connection: close. - // - if(ec == beast::http::error::end_of_stream) - return impl().do_shutdown(); - - // On failure just log and return - if(ec) - return fail("on_write", ec); - - // See if the queue is empty - if(queue_.empty()) - { - // Queue was empty so clear the flag... - writing_ = false; - - // ...and return - return; - } - - // Queue was not empty, so invoke the object - // at the head of the queue. This will start - // another wrte. - queue_.front()->invoke(); - - // Delete the item since we used it - queue_.erase(queue_.begin()); - } -}; - -//------------------------------------------------------------------------------ - -// This class represents an asynchronous HTTP connection which -// uses a plain TCP/IP socket (no encryption) as the stream. -// -template -class async_http_con - - // Give this object the enable_shared_from_this, and have - // the base class call impl().shared_from_this(). The reason - // is so that the shared_ptr has the correct type. This lets - // the derived class (this class) use its members in calls to - // `std::bind`, without an ugly call to `dynamic_downcast` or - // other nonsense. - // - : public std::enable_shared_from_this> - - // The stream should be created before the base class so - // use the "base from member" idiom. - // - , public base_from_member - - // Constructs last, destroys first - // - , public async_http_con_base, Services...> -{ -public: - // Constructor - // - // Additional arguments are forwarded to the base class - // - template - async_http_con( - socket_type&& sock, - Args&&... args) - : base_from_member(std::move(sock)) - , async_http_con_base, Services...>( - std::forward(args)...) - { - } - - // Returns the stream. - // - // The base class calls this to obtain the object to use for - // reading and writing HTTP messages. This allows the same base - // class to work with different return types for `stream()` such - // as a `boost::asio::ip::tcp::socket&` or a `boost::asio::ssl::stream&` - // - socket_type& - stream() - { - return this->member; - } - -private: - // Base class needs to be a friend to call our private members - friend class async_http_con_base, Services...>; - - // This is called by the base before running the main loop. - // - void - do_handshake() - { - // Run the main loop right away - // - this->do_run(); - } - - // This is called when the other end closes the connection gracefully. - // - void - do_shutdown() - { - error_code ec; - stream().shutdown(socket_type::shutdown_both, ec); - - // not_connected happens under normal - // circumstances so don't bother reporting it. - // - if(ec && ec != beast::errc::not_connected) - return this->fail("shutdown", ec); - } -}; - -//------------------------------------------------------------------------------ - -/* An asynchronous HTTP port handler - - This type meets the requirements of @b PortHandler. It supports - variable list of HTTP services in its template parameter list, - and provides a synchronous connection implementation to service -*/ -template -class http_async_port -{ - // Reference to the server instance that made us - server& instance_; - - // The stream to log to - std::ostream& log_; - - // The list of services connections created from this port will support - service_list services_; - -public: - /** Constructor - - @param instance The server instance which owns this port - - @param log The stream to use for logging - */ - http_async_port( - server& instance, - std::ostream& log) - : instance_(instance) - , log_(log) - { - } - - /** Initialize a service - - Every service in the list must be initialized exactly once. - - @param args Optional arguments forwarded to the service - constructor. - - @tparam Index The 0-based index of the service to initialize. - - @return A reference to the service list. This permits - calls to be chained in a single expression. - */ - template - void - init(error_code& ec, Args&&... args) - { - services_.template init( - ec, - std::forward(args)...); - } - - /** Called by the server to provide ownership of the socket for a new connection - - @param sock The socket whose ownership is to be transferred - - @ep The remote endpoint - */ - void - on_accept(socket_type&& sock, endpoint_type ep) - { - // Create a plain http connection object - // and transfer ownership of the socket. - // - std::make_shared>( - std::move(sock), - "http_async_port", - log_, - services_, - instance_.next_id(), - ep)->run(); - } -}; - -} // framework - -#endif diff --git a/src/beast/example/server-framework/http_base.hpp b/src/beast/example/server-framework/http_base.hpp deleted file mode 100644 index 6dddb079a4e..00000000000 --- a/src/beast/example/server-framework/http_base.hpp +++ /dev/null @@ -1,77 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_EXAMPLE_SERVER_HTTP_BASE_HPP -#define BEAST_EXAMPLE_SERVER_HTTP_BASE_HPP - -#include -#include -#include -#include -#include -#include -#include - -namespace framework { - -/* Base class for HTTP PortHandlers - - This holds the server name and has some shared - routines for building typical HTTP responses. -*/ -class http_base -{ - beast::string_view server_name_; - -public: - explicit - http_base(beast::string_view server_name) - : server_name_(server_name) - { - } - -protected: - // Returns a bad request result response - // - template - beast::http::response - bad_request(beast::http::request const& req) const - { - beast::http::response res; - - // Match the version to the request - res.version = req.version; - - res.result(beast::http::status::bad_request); - res.set(beast::http::field::server, server_name_); - res.set(beast::http::field::content_type, "text/html"); - res.body = "Bad request"; - res.prepare_payload(); - return res; - } - - // Returns a 100 Continue result response - // - template - beast::http::response - continue_100(beast::http::request const& req) const - { - beast::http::response res; - - // Match the version to the request - res.version = req.version; - - res.result(beast::http::status::continue_); - res.set(beast::http::field::server, server_name_); - - return res; - } -}; - -} // framework - -#endif diff --git a/src/beast/example/server-framework/http_sync_port.hpp b/src/beast/example/server-framework/http_sync_port.hpp deleted file mode 100644 index 2cd20477bbc..00000000000 --- a/src/beast/example/server-framework/http_sync_port.hpp +++ /dev/null @@ -1,477 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_EXAMPLE_SERVER_HTTP_SYNC_PORT_HPP -#define BEAST_EXAMPLE_SERVER_HTTP_SYNC_PORT_HPP - -#include "server.hpp" - -#include "http_base.hpp" -#include "service_list.hpp" - -#include "../common/rfc7231.hpp" -#include "../common/write_msg.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace framework { - -/** A synchronous HTTP connection. - - This base class implements an HTTP connection object using - synchronous calls. - - It uses the Curiously Recurring Template pattern (CRTP) where - we refer to the derived class in order to access the stream object - to use for reading and writing. This lets the same class be used - for plain and SSL stream objects. - - @tparam Services The list of services this connection will support. -*/ -template -class sync_http_con_base - : public http_base -{ - // This function lets us access members of the derived class - Derived& - impl() - { - return static_cast(*this); - } - - // The stream to use for logging - std::ostream& log_; - - // The services configured for the port - service_list const& services_; - - // A small unique integer for logging - std::size_t id_; - - // The remote endpoint. We cache it here because - // calls to remote_endpoint() can fail / throw. - // - endpoint_type ep_; - - // The buffer for performing reads - beast::flat_buffer buffer_; - -public: - /// Constructor - sync_http_con_base( - beast::string_view server_name, - std::ostream& log, - service_list const& services, - std::size_t id, - endpoint_type const& ep) - : http_base(server_name) - , log_(log) - , services_(services) - , id_(id) - , ep_(ep) - - // The buffer has a limit of 8192, otherwise - // the server is vulnerable to a buffer attack. - // - , buffer_(8192) - { - } - - // This is called to start the connection after - // it is accepted. - // - void - run() - { - // Bind a shared pointer into the lambda for the - // thread, so the sync_http_con_base is destroyed after - // the thread function exits. - // - std::thread{ - &sync_http_con_base::do_run, - impl().shared_from_this() - }.detach(); - } - -protected: - // Called when a failure occurs - // - void - fail(std::string what, error_code ec) - { - if(ec) - { - log_ << - "[#" << id_ << " " << ep_ << "] " << - what << ": " << ec.message() << std::endl; - } - } - -private: - // This lambda is passed to the service list to handle - // the case of sending request objects of varying types. - // In C++14 this is more easily accomplished using a generic - // lambda, but we want C+11 compatibility so we manually - // write the lambda out. - // - struct send_lambda - { - // holds "this" - sync_http_con_base& self_; - - // holds the captured error code - error_code& ec_; - - public: - // Constructor - // - // Capture "this" and "ec" - // - send_lambda(sync_http_con_base& self, error_code& ec) - : self_(self) - , ec_(ec) - { - } - - // Sends a message - // - // Since this is a synchronous implementation we - // just call the write function and block. - // - template - void - operator()( - beast::http::response&& res) const - { - beast::http::serializer sr{res}; - beast::http::write(self_.impl().stream(), sr, ec_); - } - }; - - void - do_run() - { - error_code ec; - - // Give the derived class a chance to do stuff before we - // enter the main loop. This is for SSL connections really. - // - impl().do_handshake(ec); - - if(ec) - return fail("handshake", ec); - - // The main connection loop, we alternate between - // reading a request and sending a response. On - // error we log and return, which destroys the thread - // and the stream (thus closing the connection) - // - for(;;) - { - // Arguments passed to the parser constructor are - // forwarded to the message object. A single argument - // is forwarded to the body constructor. - // - // We construct the dynamic body with a 1MB limit - // to prevent vulnerability to buffer attacks. - // - beast::http::request_parser parser( - std::piecewise_construct, std::make_tuple(1024* 1024)); - - // Read the header first - beast::http::read_header(impl().stream(), buffer_, parser, ec); - - // This happens when the other end closes gracefully - // - if(ec == beast::http::error::end_of_stream) - { - // Give the derived class a chance to do stuff - impl().do_shutdown(ec); - if(ec && ec != beast::errc::not_connected) - return fail("shutdown", ec); - return; - } - - // Any other error and we fail the connection - if(ec) - return fail("read_header", ec); - - send_lambda send{*this, ec}; - - auto& req = parser.get(); - - // See if they are specifying Expect: 100-continue - // - if(rfc7231::is_expect_100_continue(req)) - { - // They want to know if they should continue, - // so send the appropriate response synchronously. - // - send(this->continue_100(req)); - - // This happens when we send an HTTP message - // whose semantics indicate that the connection - // should be closed afterwards. For example if - // we send a Connection: close. - // - if(ec == beast::http::error::end_of_stream) - { - // Give the derived class a chance to do stuff - impl().do_shutdown(ec); - if(ec && ec != beast::errc::not_connected) - return fail("shutdown", ec); - return; - } - - // Have to check the error every time we call the lambda - // - if(ec) - return fail("write", ec); - } - - // Read the rest of the message, if any. - // - beast::http::read(impl().stream(), buffer_, parser, ec); - - // Shouldn't be getting end_of_stream here; - // that would mean that we got an incomplete - // message, counting as an error. - // - if(ec) - return fail("read", ec); - - // Give each service a chance to handle the request - // - if(! services_.respond( - std::move(impl().stream()), - ep_, - std::move(req), - send)) - { - // No service handled the request, - // send a Bad Request result to the client. - // - send(this->bad_request(req)); - - // This happens when we send an HTTP message - // whose semantics indicate that the connection - // should be closed afterwards. For example if - // we send a Connection: close. - // - if(ec == beast::http::error::end_of_stream) - { - // Give the derived class a chance to do stuff - impl().do_shutdown(ec); - if(ec && ec != beast::errc::not_connected) - return fail("shutdown", ec); - return; - } - - // Have to check the error every time we call the lambda - // - if(ec) - return fail("write", ec); - } - else - { - // This happens when we send an HTTP message - // whose semantics indicate that the connection - // should be closed afterwards. For example if - // we send a Connection: close. - // - if(ec == beast::http::error::end_of_stream) - { - // Give the derived class a chance to do stuff - if(ec && ec != beast::errc::not_connected) - return fail("shutdown", ec); - return; - } - - // Have to check the error every time we call the lambda - // - if(ec) - return fail("write", ec); - - // See if the service that handled the - // response took ownership of the stream. - if(! impl().stream().lowest_layer().is_open()) - { - // They took ownership so just return and - // let this sync_http_con_base object get destroyed. - return; - } - } - - // Theres no pipelining possible in a synchronous server - // because we can't do reads and writes at the same time. - } - } -}; - -//------------------------------------------------------------------------------ - -// This class represents a synchronous HTTP connection which -// uses a plain TCP/IP socket (no encryption) as the stream. -// -template -class sync_http_con - - // Give this object the enable_shared_from_this, and have - // the base class call impl().shared_from_this(). The reason - // is so that the shared_ptr has the correct type. This lets - // the derived class (this class) use its members in calls to - // `std::bind`, without an ugly call to `dynamic_downcast` or - // other nonsense. - // - : public std::enable_shared_from_this> - - // The stream should be created before the base class so - // use the "base from member" idiom. - // - , public base_from_member - - // Constructs last, destroys first - // - , public sync_http_con_base, Services...> -{ -public: - // Constructor - // - // Additional arguments are forwarded to the base class - // - template - sync_http_con( - socket_type&& sock, - Args&&... args) - : base_from_member(std::move(sock)) - , sync_http_con_base, Services...>( - std::forward(args)...) - { - } - - // Returns the stream. - // - // The base class calls this to obtain the object to use for - // reading and writing HTTP messages. This allows the same base - // class to work with different return types for `stream()` such - // as a `boost::asio::ip::tcp::socket&` or a `boost::asio::ssl::stream&` - // - socket_type& - stream() - { - return this->member; - } - -private: - // Base class needs to be a friend to call our private members - friend class sync_http_con_base, Services...>; - - // This is called by the base before running the main loop. - // There's nothing to do for a plain connection. - // - void - do_handshake(error_code& ec) - { - // This is required by the specifications for error_code - // - ec = {}; - } - - // This is called when the other end closes the connection gracefully. - // - void - do_shutdown(error_code& ec) - { - stream().shutdown(socket_type::shutdown_both, ec); - } -}; - -//------------------------------------------------------------------------------ - -/* A synchronous HTTP port handler - - This type meets the requirements of @b PortHandler. It supports - variable list of HTTP services in its template parameter list, - and provides a synchronous connection implementation to service -*/ -template -class http_sync_port -{ - server& instance_; - std::ostream& log_; - service_list services_; - -public: - /** Constructor - - @param instance The server instance which owns this port - - @param log The stream to use for logging - */ - http_sync_port( - server& instance, - std::ostream& log) - : instance_(instance) - , log_(log) - { - } - - /** Initialize a service - - Every service in the list must be initialized exactly once. - - @param ec Set to the error, if any occurred - - @param args Optional arguments forwarded to the service - constructor. - - @tparam Index The 0-based index of the service to initialize. - */ - template - void - init(error_code& ec, Args&&... args) - { - services_.template init( - ec, - std::forward(args)...); - } - - /** Called by the server to provide ownership of the socket for a new connection - - @param sock The socket whose ownership is to be transferred - - @ep The remote endpoint - */ - void - on_accept(socket_type&& sock, endpoint_type ep) - { - // Create a plain http connection object - // and transfer ownership of the socket. - // - std::make_shared>( - std::move(sock), - "http_sync_port", - log_, - services_, - instance_.next_id(), - ep)->run(); - } -}; - -} // framework - -#endif diff --git a/src/beast/example/server-framework/https_ports.hpp b/src/beast/example/server-framework/https_ports.hpp deleted file mode 100644 index 8a4a5c2450d..00000000000 --- a/src/beast/example/server-framework/https_ports.hpp +++ /dev/null @@ -1,426 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_EXAMPLE_SERVER_HTTPS_PORTS_HPP -#define BEAST_EXAMPLE_SERVER_HTTPS_PORTS_HPP - -#include "http_sync_port.hpp" -#include "http_async_port.hpp" - -#include "../common/ssl_stream.hpp" - -#include - -namespace framework { - -//------------------------------------------------------------------------------ - -// This class represents a synchronous HTTP connection which -// uses an OpenSSL socket as the stream. -// -template -class sync_https_con - - // Give this object the enable_shared_from_this, and have - // the base class call impl().shared_from_this(). The reason - // is so that the shared_ptr has the correct type. This lets - // the derived class (this class) use its members in calls to - // `std::bind`, without an ugly call to `dynamic_downcast` or - // other nonsense. - // - : public std::enable_shared_from_this> - - // The stream should be created before the base class so - // use the "base from member" idiom. - // - , public base_from_member> - - // Constructs last, destroys first - // - , public sync_http_con_base, Services...> -{ -public: - // Constructor - // - // Additional arguments are forwarded to the base class - // - template - sync_https_con( - socket_type&& sock, - boost::asio::ssl::context& ctx, - Args&&... args) - : base_from_member>(std::move(sock), ctx) - , sync_http_con_base, Services...>( - std::forward(args)...) - { - } - - // Returns the stream. - // - // The base class calls this to obtain the object to use for - // reading and writing HTTP messages. This allows the same base - // class to work with different return types for `stream()` such - // as a `boost::asio::ip::tcp::socket&` or a `boost::asio::ssl::stream&` - // - ssl_stream& - stream() - { - return this->member; - } - -private: - friend class sync_http_con_base, Services...>; - - // This is called by the base before running the main loop. - // - void - do_handshake(error_code& ec) - { - // Perform the SSL handshake - // - stream().handshake(boost::asio::ssl::stream_base::server, ec); - } - - // This is called when the other end closes the connection gracefully. - // - void - do_shutdown(error_code& ec) - { - // Note that this is an SSL shutdown - // - stream().shutdown(ec); - if(ec) - return this->fail("ssl_shutdown", ec); - } -}; - -//------------------------------------------------------------------------------ - -// This class represents an asynchronous HTTP connection which -// uses an OpenSSL socket as the stream. -// -template -class async_https_con - - // Give this object the enable_shared_from_this, and have - // the base class call impl().shared_from_this(). The reason - // is so that the shared_ptr has the correct type. This lets - // the derived class (this class) use its members in calls to - // `std::bind`, without an ugly call to `dynamic_downcast` or - // other nonsense. - // - : public std::enable_shared_from_this> - - // The stream should be created before the base class so - // use the "base from member" idiom. - // - , public base_from_member> - - // Constructs last, destroys first - // - , public async_http_con_base, Services...> -{ -public: - // Constructor - // - // Additional arguments are forwarded to the base class - // - template - async_https_con( - socket_type&& sock, - boost::asio::ssl::context& ctx, - Args&&... args) - : base_from_member>(std::move(sock), ctx) - , async_http_con_base, Services...>( - std::forward(args)...) - { - } - - // Returns the stream. - // - // The base class calls this to obtain the object to use for - // reading and writing HTTP messages. This allows the same base - // class to work with different return types for `stream()` such - // as a `boost::asio::ip::tcp::socket&` or a `boost::asio::ssl::stream&` - // - ssl_stream& - stream() - { - return this->member; - } - - // Called by the multi-port after reading some - // bytes from the stream and detecting SSL. - // - template - void - handshake(ConstBufferSequence const& buffers) - { - // Copy the caller's bytes into the buffer we - // use for reading HTTP messages, otherwise - // the memory pointed to by buffers will go out - // of scope. - // - this->buffer_.commit( - boost::asio::buffer_copy( - this->buffer_.prepare(boost::asio::buffer_size(buffers)), - buffers)); - - // Perform SSL handshake. We use the "buffered" - // overload which lets us pass those extra bytes. - // - stream().async_handshake( - boost::asio::ssl::stream_base::server, - buffers, - this->strand_.wrap( - std::bind( - &async_https_con::on_buffered_handshake, - this->shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); - } - -private: - friend class async_http_con_base, Services...>; - - // Called by the base class before starting the main loop. - // - void - do_handshake() - { - // This is SSL so perform the handshake - // - stream().async_handshake( - boost::asio::ssl::stream_base::server, - this->strand_.wrap( - std::bind( - &async_https_con::on_handshake, - this->shared_from_this(), - std::placeholders::_1))); - } - - // Called when the SSL handshake completes - void - on_handshake(error_code ec) - { - if(ec) - return this->fail("on_handshake", ec); - - // No error so run the main loop - this->do_run(); - } - - // Called when the buffered SSL handshake completes - void - on_buffered_handshake(error_code ec, std::size_t bytes_transferred) - { - if(ec) - return this->fail("on_handshake", ec); - - // Consume what was read but leave the rest - this->buffer_.consume(bytes_transferred); - - // No error so run the main loop - this->do_run(); - } - - // Called when the end of stream is reached - void - do_shutdown() - { - // This is an SSL shutdown - // - stream().async_shutdown( - this->strand_.wrap( - std::bind( - &async_https_con::on_shutdown, - this->shared_from_this(), - std::placeholders::_1))); - } - - // Called when the SSL shutdown completes - void - on_shutdown(error_code ec) - { - if(ec) - return this->fail("on_shutdown", ec); - } -}; - -//------------------------------------------------------------------------------ - -/* A synchronous HTTPS port handler - - This type meets the requirements of @b PortHandler. It supports - variable list of HTTP services in its template parameter list, - and provides a synchronous connection implementation to service -*/ -template -class https_sync_port -{ - // Reference to the server instance that made us - server& instance_; - - // The stream to log to - std::ostream& log_; - - // The list of services connections created from this port will support - service_list services_; - - // The SSL context containing the server's credentials - boost::asio::ssl::context& ctx_; - -public: - /** Constructor - - @param instance The server instance which owns this port - - @param log The stream to use for logging - - @param ctx The SSL context holding the SSL certificates to use - */ - https_sync_port( - server& instance, - std::ostream& log, - boost::asio::ssl::context& ctx) - : instance_(instance) - , log_(log) - , ctx_(ctx) - { - } - - /** Initialize a service - - Every service in the list must be initialized exactly once. - - @param args Optional arguments forwarded to the service - constructor. - - @tparam Index The 0-based index of the service to initialize. - - @return A reference to the service list. This permits - calls to be chained in a single expression. - */ - template - void - init(error_code& ec, Args&&... args) - { - services_.template init( - ec, - std::forward(args)...); - } - - /** Called by the server to provide ownership of the socket for a new connection - - @param sock The socket whose ownership is to be transferred - - @ep The remote endpoint - */ - void - on_accept(socket_type&& sock, endpoint_type ep) - { - // Create an HTTPS connection object - // and transfer ownership of the socket. - // - std::make_shared>( - std::move(sock), - ctx_, - "https_sync_port", - log_, - services_, - instance_.next_id(), - ep)->run(); - } -}; - -//------------------------------------------------------------------------------ - -/* An asynchronous HTTPS port handler - - This type meets the requirements of @b PortHandler. It supports - variable list of HTTP services in its template parameter list, - and provides a synchronous connection implementation to service -*/ -template -class https_async_port -{ - // Reference to the server instance that made us - server& instance_; - - // The stream to log to - std::ostream& log_; - - // The list of services connections created from this port will support - service_list services_; - - // The SSL context containing the server's credentials - boost::asio::ssl::context& ctx_; - -public: - /** Constructor - - @param instance The server instance which owns this port - - @param log The stream to use for logging - */ - https_async_port( - server& instance, - std::ostream& log, - boost::asio::ssl::context& ctx) - : instance_(instance) - , log_(log) - , ctx_(ctx) - { - } - - /** Initialize a service - - Every service in the list must be initialized exactly once. - - @param args Optional arguments forwarded to the service - constructor. - - @tparam Index The 0-based index of the service to initialize. - - @return A reference to the service list. This permits - calls to be chained in a single expression. - */ - template - void - init(error_code& ec, Args&&... args) - { - services_.template init( - ec, - std::forward(args)...); - } - - /** Called by the server to provide ownership of the socket for a new connection - - @param sock The socket whose ownership is to be transferred - - @ep The remote endpoint - */ - void - on_accept(socket_type&& sock, endpoint_type ep) - { - // Create an SSL connection object - // and transfer ownership of the socket. - // - std::make_shared>( - std::move(sock), - ctx_, - "https_async_port", - log_, - services_, - instance_.next_id(), - ep)->run(); - } -}; - -} // framework - -#endif diff --git a/src/beast/example/server-framework/main.cpp b/src/beast/example/server-framework/main.cpp deleted file mode 100644 index fcaffa8ce73..00000000000 --- a/src/beast/example/server-framework/main.cpp +++ /dev/null @@ -1,446 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#include "server.hpp" - -#include "http_async_port.hpp" -#include "http_sync_port.hpp" -#include "ws_async_port.hpp" -#include "ws_sync_port.hpp" - -#if BEAST_USE_OPENSSL -#include "https_ports.hpp" -#include "multi_port.hpp" -#include "wss_ports.hpp" -#include "ssl_certificate.hpp" -#endif - -#include "file_service.hpp" -#include "ws_upgrade_service.hpp" - -#include - -#include - -/// Block until SIGINT or SIGTERM is received. -void -sig_wait() -{ - // Create our own io_service for this - boost::asio::io_service ios; - - // Get notified on the signals we want - boost::asio::signal_set signals( - ios, SIGINT, SIGTERM); - - // Now perform the asynchronous call - signals.async_wait( - [&](boost::system::error_code const&, int) - { - }); - - // Block the current thread on run(), when the - // signal is received then this call will return. - ios.run(); -} - -/** Set the options on a WebSocket stream. - - This is used by the websocket server port handlers. - It is called every time a new websocket stream is - created, to provide the opportunity to set settings - for the connection. -*/ -class set_ws_options -{ - beast::websocket::permessage_deflate pmd_; - -public: - set_ws_options(beast::websocket::permessage_deflate const& pmd) - : pmd_(pmd) - { - } - - template - void - operator()(beast::websocket::stream& ws) const - { - ws.auto_fragment(false); - ws.set_option(pmd_); - ws.read_message_max(64 * 1024 * 1024); - } -}; - -int -main( - int ac, - char const* av[]) -{ - using namespace framework; - using namespace beast::http; - - // Helper for reporting failures - // - auto const fail = - [&]( - std::string const& what, - error_code const& ec) - { - std::cerr << - av[0] << ": " << - what << " failed, " << - ec.message() << - std::endl; - return EXIT_FAILURE; - }; - - namespace po = boost::program_options; - po::options_description desc("Options"); - - desc.add_options() - ("root,r", po::value()->default_value("."), - "Set the root directory for serving files") - ("port,p", po::value()->default_value(1000), - "Set the base port number for the server") - ("ip", po::value()->default_value("0.0.0.0"), - "Set the IP address to bind to, \"0.0.0.0\" for all") - ("threads,n", po::value()->default_value(4), - "Set the number of threads to use") - ; - po::variables_map vm; - po::store(po::parse_command_line(ac, av, desc), vm); - - // Get the IP address from the options - std::string const ip = vm["ip"].as(); - - // Get the port number from the options - std::uint16_t const port = vm["port"].as(); - - // Build an endpoint from the address and port - address_type const addr{address_type::from_string(ip)}; - - // Get the number of threads from the command line - std::size_t const threads = vm["threads"].as(); - - // Get the root path from the command line - boost::filesystem::path const root = vm["root"].as(); - - // These settings will be applied to all new websocket connections - beast::websocket::permessage_deflate pmd; - pmd.client_enable = true; - pmd.server_enable = true; - pmd.compLevel = 3; - - error_code ec; - - // Create our server instance with the specified number of threads - server instance{threads}; - - //-------------------------------------------------------------------------- - // - // Synchronous WebSocket HTTP - // - // port + 0 port + 1 - // - //-------------------------------------------------------------------------- - { - // Create a WebSocket port - // - auto wsp = instance.make_port( - ec, - endpoint_type{addr,static_cast(port + 0)}, - instance, - std::cout, - set_ws_options{pmd}); - - if(ec) - return fail("ws_sync_port", ec); - - // Create an HTTP port - // - auto sp = instance.make_port, - file_service - >>( - ec, - endpoint_type{addr,static_cast(port + 1)}, - instance, - std::cout); - - if(ec) - return fail("http_sync_port", ec); - - // Init the ws_upgrade_service to - // forward upgrades to the WebSocket port. - // - sp->template init<0>( - ec, - *wsp // The WebSocket port handler - ); - - if(ec) - return fail("http_sync_port/ws_upgrade_service", ec); - - // Init the file_service to point to the root path. - // - sp->template init<1>( - ec, - root, // The root path - "http_sync_port" // The value for the Server field - ); - - if(ec) - return fail("http_sync_port/file_service", ec); - } - - //-------------------------------------------------------------------------- - // - // Asynchronous WebSocket HTTP - // - // port + 2 port + 3 - // - //-------------------------------------------------------------------------- - { - // Create a WebSocket port - // - auto wsp = instance.make_port( - ec, - endpoint_type{addr, - static_cast(port + 2)}, - instance, - std::cout, - set_ws_options{pmd} - ); - - if(ec) - return fail("ws_async_port", ec); - - // Create an HTTP port - // - auto sp = instance.make_port, - file_service - >>( - ec, - endpoint_type{addr, - static_cast(port + 3)}, - instance, - std::cout); - - if(ec) - return fail("http_async_port", ec); - - // Init the ws_upgrade_service to - // forward upgrades to the WebSocket port. - // - sp->template init<0>( - ec, - *wsp // The websocket port handler - ); - - if(ec) - return fail("http_async_port/ws_upgrade_service", ec); - - // Init the file_service to point to the root path. - // - sp->template init<1>( - ec, - root, // The root path - "http_async_port" // The value for the Server field - ); - - if(ec) - return fail("http_async_port/file_service", ec); - } - - // - // The next section supports encrypted connections and requires - // an installed and configured OpenSSL as part of the build. - // - -#if BEAST_USE_OPENSSL - - ssl_certificate cert; - - //-------------------------------------------------------------------------- - // - // Synchronous Secure WebSocket HTTPS - // - // port + 4 port + 5 - // - //-------------------------------------------------------------------------- - { - // Create a WebSocket port - // - auto wsp = instance.make_port( - ec, - endpoint_type{addr, - static_cast(port + 4)}, - instance, - std::cout, - cert.get(), - set_ws_options{pmd}); - - if(ec) - return fail("wss_sync_port", ec); - - // Create an HTTP port - // - auto sp = instance.make_port, - file_service - >>( - ec, - endpoint_type{addr, - static_cast(port + 5)}, - instance, - std::cout, - cert.get()); - - if(ec) - return fail("https_sync_port", ec); - - // Init the ws_upgrade_service to - // forward upgrades to the WebSocket port. - // - sp->template init<0>( - ec, - *wsp // The websocket port handler - ); - - if(ec) - return fail("http_sync_port/ws_upgrade_service", ec); - - // Init the file_service to point to the root path. - // - sp->template init<1>( - ec, - root, // The root path - "http_sync_port" // The value for the Server field - ); - - if(ec) - return fail("https_sync_port/file_service", ec); - } - - //-------------------------------------------------------------------------- - // - // Asynchronous Secure WebSocket HTTPS - // - // port + 6 port + 7 - // - //-------------------------------------------------------------------------- - { - // Create a WebSocket port - // - auto wsp = instance.make_port( - ec, - endpoint_type{addr, - static_cast(port + 6)}, - instance, - std::cout, - cert.get(), - set_ws_options{pmd} - ); - - if(ec) - return fail("ws_async_port", ec); - - // Create an HTTP port - // - auto sp = instance.make_port, - file_service - >>( - ec, - endpoint_type{addr, - static_cast(port + 7)}, - instance, - std::cout, - cert.get()); - - if(ec) - return fail("https_async_port", ec); - - // Init the ws_upgrade_service to - // forward upgrades to the WebSocket port. - // - sp->template init<0>( - ec, - *wsp // The websocket port handler - ); - - if(ec) - return fail("https_async_port/ws_upgrade_service", ec); - - // Init the file_service to point to the root path. - // - sp->template init<1>( - ec, - root, // The root path - "https_async_port" // The value for the Server field - ); - - if(ec) - return fail("https_async_port/file_service", ec); - } - - //-------------------------------------------------------------------------- - // - // Multi-Port HTTP, WebSockets, - // HTTPS Secure WebSockets - // - // Asynchronous, all on the same port! - // - // port + 8 - // - //-------------------------------------------------------------------------- - { - // Create a multi_port - // - auto sp = instance.make_port, - file_service - >>( - ec, - endpoint_type{addr, - static_cast(port + 8)}, - instance, - std::cout, - cert.get(), - set_ws_options{pmd}); - - if(ec) - return fail("multi_port", ec); - - // Init the ws_upgrade_service to forward requests to the multi_port. - // - sp->template init<0>( - ec, - *sp // The websocket port handler - ); - - if(ec) - return fail("multi_port/ws_upgrade_service", ec); - - // Init the ws_upgrade_service to - // forward upgrades to the Multi port. - // - sp->template init<1>( - ec, - root, // The root path - "multi_port" // The value for the Server field - ); - - if(ec) - return fail("multi_port/file_service", ec); - } - -#endif - - sig_wait(); -} diff --git a/src/beast/example/server-framework/multi_port.hpp b/src/beast/example/server-framework/multi_port.hpp deleted file mode 100644 index 37741332291..00000000000 --- a/src/beast/example/server-framework/multi_port.hpp +++ /dev/null @@ -1,397 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_EXAMPLE_SERVER_MULTI_PORT_HPP -#define BEAST_EXAMPLE_SERVER_MULTI_PORT_HPP - -#include "ws_async_port.hpp" -#include "http_async_port.hpp" -#include "https_ports.hpp" -#include "wss_ports.hpp" - -#include "../common/detect_ssl.hpp" - -#include - -#include - -namespace framework { - -// A connection that detects an opening SSL handshake -// -// If the SSL handshake is detected, then an HTTPS connection object -// is move constructed from this object. Otherwise, this object continues -// as a normal unencrypted HTTP connection. If the underlying port has -// the ws_upgrade_service configured, the connection may be optionally -// be upgraded to WebSocket by the client. -// -template -class multi_con - - // Give this object the enable_shared_from_this, and have - // the base class call impl().shared_from_this(). The reason - // is so that the shared_ptr has the correct type. This lets - // the derived class (this class) use its members in calls to - // `std::bind`, without an ugly call to `dynamic_downcast` or - // other nonsense. - // - : public std::enable_shared_from_this> - - // The stream should be created before the base class so - // use the "base from member" idiom. - // - , public base_from_member - - // Constructs last, destroys first - // - , public async_http_con_base, Services...> -{ - // Context to use if we get an SSL handshake - boost::asio::ssl::context& ctx_; - - // Holds the data we read during ssl detection - beast::static_buffer_n<6> buffer_; - -public: - // Constructor - // - // Additional arguments are simply forwarded to the base class - // - template - multi_con( - socket_type&& sock, - boost::asio::ssl::context& ctx, - Args&&... args) - : base_from_member(std::move(sock)) - , async_http_con_base, Services...>(std::forward(args)...) - , ctx_(ctx) - { - } - - // Returns the stream. - // - // The base class calls this to obtain the object to use for - // reading and writing HTTP messages. This allows the same base - // class to work with different return types for `stream()` such - // as a `boost::asio::ip::tcp::socket&` or a `boost::asio::ssl::stream&` - // - socket_type& - stream() - { - return this->member; - } - - // Called by the port to launch the connection in detect mode - void - detect() - { - // The detect function operates asynchronously by reading - // in some data from the stream to figure out if its an SSL - // handshake. When it completes, it informs us of the result - // and also stores the bytes it read in the buffer. - // - async_detect_ssl( - stream(), - buffer_, - this->strand_.wrap( - std::bind( - &multi_con::on_detect, - this->shared_from_this(), - std::placeholders::_1, - std::placeholders::_2))); - } - -private: - // Base class needs to be a friend to call our private members - friend class async_http_con_base, Services...>; - - // Called when the handshake detection is complete - // - void - on_detect( - error_code ec, - boost::tribool result) - { - // Report failures if any - if(ec) - return this->fail("on_detect", ec); - - // Was an SSL handshake detected? - if(result) - { - // Yes, get the remote endpoint since it is - // needed to construct the new connection. - // - endpoint_type ep = stream().remote_endpoint(ec); - if(ec) - return this->fail("remote_endpoint", ec); - - // Now launch our new connection object - // - std::make_shared>( - std::move(stream()), - ctx_, - "multi_port", - this->log_, - this->services_, - this->id_, - ep)->handshake(buffer_.data()); - - // When we return the last shared pointer to this - // object will go away and `*this` will be destroyed. - // - return; - } - - // No SSL handshake, so start the HTTP connection normally. - // - // Since we read some bytes from the connection that might - // contain an HTTP request, we pass the buffer holding those - // bytes to the base class so it can use them. - // - this->run(buffer_.data()); - } - - // This is called by the base before running the main loop. - // - void - do_handshake() - { - // Just run the main loop right away. - // - this->do_run(); - } - - // This is called when the other end closes the connection gracefully. - // - void - do_shutdown() - { - // Attempt a clean TCP/IP shutdown - // - error_code ec; - stream().shutdown( - socket_type::shutdown_both, - ec); - - // not_connected happens under normal - // circumstances so don't bother reporting it. - // - if(ec && ec != beast::errc::not_connected) - return this->fail("shutdown", ec); - } -}; - -//------------------------------------------------------------------------------ - -/* An asynchronous HTTP and WebSocket port handler, plain or SSL - - This type meets the requirements of @b PortHandler. It supports a - variable list of HTTP services in its template parameter list, - and provides a synchronous connection implementation to service. - - The port will automatically detect OpenSSL handshakes and establish - encrypted connections, otherwise will use a plain unencrypted - connection. This all happens through the same port. - - In addition this port can process WebSocket upgrade requests by - launching them as a new asynchronous WebSocket connection using - either plain or OpenSSL transport. - - This class is split up into two parts, the multi_port_base, - and the multi_port, to avoid a recursive type reference when - we name the type of the ws_upgrade_service. -*/ -class multi_port_base -{ -protected: - // VFALCO We use boost::function to work around a compiler - // crash with gcc and clang using libstdc++ - - // The types of the on_stream callback - using on_new_stream_cb1 = boost::function&)>; - using on_new_stream_cb2 = boost::function>&)>; - - // Reference to the server instance that made us - server& instance_; - - // The stream to log to - std::ostream& log_; - - // The context holds the SSL certificates the server uses - boost::asio::ssl::context& ctx_; - - // Called for each new websocket stream - on_new_stream_cb1 cb1_; - on_new_stream_cb2 cb2_; - -public: - /** Constructor - - @param instance The server instance which owns this port - - @param log The stream to use for logging - - @param ctx The SSL context holding the SSL certificates to use - - @param cb A callback which will be invoked for every new - WebSocket connection. This provides an opportunity to change - the settings on the stream before it is used. The callback - should have this equivalent signature: - @code - template - void callback(beast::websocket::stream&); - @endcode - In C++14 this can be accomplished with a generic lambda. In - C++11 it will be necessary to write out a lambda manually, - with a templated operator(). - */ - template - multi_port_base( - server& instance, - std::ostream& log, - boost::asio::ssl::context& ctx, - Callback const& cb) - : instance_(instance) - , log_(log) - , ctx_(ctx) - , cb1_(cb) - , cb2_(cb) - { - } - - /** Accept a WebSocket upgrade request. - - This is used to accept a connection that has already - delivered the handshake. - - @param stream The stream corresponding to the connection. - - @param ep The remote endpoint. - - @param req The upgrade request. - */ - template - void - on_upgrade( - socket_type&& sock, - endpoint_type ep, - beast::http::request&& req) - { - // Create the connection and call the version of - // run that takes the request since we have it already - // - std::make_shared( - std::move(sock), - "multi_port", - log_, - instance_.next_id(), - ep, - cb1_ - )->run(std::move(req)); - } - - /** Accept a WebSocket upgrade request. - - This is used to accept a connection that has already - delivered the handshake. - - @param stream The stream corresponding to the connection. - - @param ep The remote endpoint. - - @param req The upgrade request. - */ - template - void - on_upgrade( - ssl_stream&& stream, - endpoint_type ep, - beast::http::request&& req) - { - std::make_shared( - std::move(stream), - "multi_port", - log_, - instance_.next_id(), - ep, - cb2_)->run(std::move(req)); - } -}; - -/* An asynchronous HTTP and WebSocket port handler, plain or SSL - - This class is the other half of multi_port_base. It gets the - Services... variadic type list and owns the service list. -*/ -template -class multi_port : public multi_port_base -{ - // The list of services connections created from this port will support - service_list services_; - -public: - /** Constructor - - All arguments are forwarded to the multi_port_base constructor. - */ - template - multi_port(Args&&... args) - : multi_port_base(std::forward(args)...) - { - } - - /** Initialize a service - - Every service in the list must be initialized exactly once. - - @param args Optional arguments forwarded to the service - constructor. - - @tparam Index The 0-based index of the service to initialize. - - @return A reference to the service list. This permits - calls to be chained in a single expression. - */ - template - void - init(error_code& ec, Args&&... args) - { - services_.template init( - ec, - std::forward(args)...); - } - - /** Called by the server to provide ownership of the socket for a new connection - - @param sock The socket whose ownership is to be transferred - - @ep The remote endpoint - */ - void - on_accept( - socket_type&& sock, - endpoint_type ep) - { - // Create a plain http connection object by transferring - // ownership of the socket, then launch it to perform - // the SSL handshake detection. - // - std::make_shared>( - std::move(sock), - ctx_, - "multi_port", - log_, - services_, - instance_.next_id(), - ep)->detect(); - } -}; - -} // framework - -#endif diff --git a/src/beast/example/server-framework/server.hpp b/src/beast/example/server-framework/server.hpp deleted file mode 100644 index 6157714c0f2..00000000000 --- a/src/beast/example/server-framework/server.hpp +++ /dev/null @@ -1,266 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_EXAMPLE_FRAMEWORK_SERVER_HPP -#define BEAST_EXAMPLE_FRAMEWORK_SERVER_HPP - -#include "framework.hpp" - -#include -#include -#include -#include -#include -#include -#include - -namespace framework { - -/** A server instance that accepts TCP/IP connections. - - This is a general purpose TCP/IP server which contains - zero or more user defined "ports". Each port represents - a listening socket whose behavior is defined by an - instance of the @b PortHandler concept. - - To use the server, construct the class and then add the - ports that you want using @ref make_port. - - @par Example - - @code - - // Create a server with 4 threads - // - framework::server si(4); - - // Create a port that echoes everything back. - // Bind all available interfaces on port 1000. - // - framework::error_code ec; - si.make_port( - ec, - server::endpoint_type{ - server::address_type::from_string("0.0.0.0"), 1000} - ); - - ... - - // Close all connections, shut down the server - si.stop(); - - @endcode -*/ -class server -{ - io_service_type ios_; - std::vector tv_; - boost::optional work_; - -public: - server(server const&) = delete; - server& operator=(server const&) = delete; - - /** Constructor - - @param n The number of threads to run on the `io_service`, - which must be greater than zero. - */ - explicit - server(std::size_t n = 1) - : work_(ios_) - { - if(n < 1) - throw std::invalid_argument{"threads < 1"}; - tv_.reserve(n); - while(n--) - tv_.emplace_back( - [&] - { - ios_.run(); - }); - } - - /** Destructor - - Upon destruction, the `io_service` will be stopped - and all pending completion handlers destroyed. - */ - ~server() - { - work_ = boost::none; - ios_.stop(); - for(auto& t : tv_) - t.join(); - } - - /// Return the `io_service` associated with the server - boost::asio::io_service& - get_io_service() - { - return ios_; - } - - /** Return a new, small integer unique id - - These ids are used to uniquely identify connections - in log output. - */ - std::size_t - next_id() - { - static std::atomic id_{0}; - return ++id_; - } - - /** Create a listening port. - - @param ec Set to the error, if any occurred. - - @param ep The address and port to bind to. - - @param args Optional arguments, forwarded to the - port handler's constructor. - - @tparam PortHandler The port handler to use for handling - incoming connections on this port. This handler must meet - the requirements of @b PortHandler. A model of PortHandler - is as follows: - - @code - - struct PortHandler - { - void - on_accept( - endpoint_type ep, // address of the remote endpoint - socket_type&& sock, // the connected socket - ); - }; - - @endcode - */ - template - std::shared_ptr - make_port( - error_code& ec, - endpoint_type const& ep, - Args&&... args); -}; - -//------------------------------------------------------------------------------ - -/* This implementation class wraps the PortHandler and - manages the listening socket. Upon an incoming connection - it transfers ownership of the socket to the PortHandler. -*/ -template -class port - : public std::enable_shared_from_this< - port> -{ - server& instance_; - PortHandler handler_; - endpoint_type ep_; - strand_type strand_; - acceptor_type acceptor_; - socket_type sock_; - -public: - // Constructor - // - // args are forwarded to the PortHandler - // - template - explicit - port(server& instance, Args&&... args) - : instance_(instance) - , handler_(std::forward(args)...) - , strand_(instance.get_io_service()) - , acceptor_(instance.get_io_service()) - , sock_(instance.get_io_service()) - { - } - - // Return the PortHandler wrapped in a shared_ptr - // - std::shared_ptr - handler() - { - // This uses a feature of std::shared_ptr invented by - // Peter Dimov where the managed object piggy backs off - // the reference count of another object containing it. - // - return std::shared_ptr( - this->shared_from_this(), &handler_); - } - - // Open the listening socket - // - void - open(endpoint_type const& ep, error_code& ec) - { - acceptor_.open(ep.protocol(), ec); - if(ec) - return; - acceptor_.set_option( - boost::asio::socket_base::reuse_address{true}); - acceptor_.bind(ep, ec); - if(ec) - return; - acceptor_.listen( - boost::asio::socket_base::max_connections, ec); - if(ec) - return; - acceptor_.async_accept(sock_, ep_, - std::bind(&port::on_accept, this->shared_from_this(), - std::placeholders::_1)); - } - -private: - // Called when an incoming connection is accepted - // - void - on_accept(error_code ec) - { - if(! acceptor_.is_open()) - return; - if(ec == boost::asio::error::operation_aborted) - return; - if(! ec) - { - // Transfer ownership of the socket to the PortHandler - // - handler_.on_accept(std::move(sock_), ep_); - } - acceptor_.async_accept(sock_, ep_, - std::bind(&port::on_accept, this->shared_from_this(), - std::placeholders::_1)); - } -}; - -//------------------------------------------------------------------------------ - -template -std::shared_ptr -server:: -make_port( - error_code& ec, - endpoint_type const& ep, - Args&&... args) -{ - auto sp = std::make_shared>( - *this, std::forward(args)...); - sp->open(ep, ec); - if(ec) - return nullptr; - return sp->handler(); -} - -} // framework - -#endif diff --git a/src/beast/example/server-framework/service_list.hpp b/src/beast/example/server-framework/service_list.hpp deleted file mode 100644 index 71d73ae7937..00000000000 --- a/src/beast/example/server-framework/service_list.hpp +++ /dev/null @@ -1,192 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_EXAMPLE_SERVER_SERVICE_LIST_HPP -#define BEAST_EXAMPLE_SERVER_SERVICE_LIST_HPP - -#include "framework.hpp" - -#include -#include -#include - -namespace framework { - -/** A list of HTTP services which may process requests. - - When a service is invoked, it is provided with the stream and - endpoint metadata in addtion to an HTTP request. The service - decides whether or not the process the request, returning - `true` if the request is processed or `false` if it does not - process the request. - - @see file_service, ws_upgrade_service -*/ -template -class service_list -{ - // This helper is for tag-dispatching tuple index - template - using C = std::integral_constant; - - // Each service is wrapped in a boost::optional so we - // can construct them one by one later, instead of - // having to construct them all at once. - // - std::tuple...> list_; - -public: - /// Constructor - service_list() = default; - - /// Constructor - service_list(service_list&&) = default; - - /// Constructor - service_list(service_list const&) = default; - - /** Initialize a service. - - Every service in the list must be initialized exactly once - before the service list is invoked. - - @param args Optional arguments forwarded to the service - constructor. - - @tparam Index The 0-based index of the service to initialize. - - @return A reference to the service list. This permits - calls to be chained in a single expression. - */ - template - void - init(error_code& ec, Args&&... args) - { - // First, construct the service inside the optional - std::get(list_).emplace(std::forward(args)...); - - // Now allow the service to finish the initialization - std::get(list_)->init(ec); - } - - /** Handle a request. - - This function attempts to process the given HTTP request by - invoking each service one at a time starting with the first - service in the list. When a service indicates that it handles - the request, by returning `true`, the function stops and - returns the value `true`. Otherwise, if no service handles - the request then the function returns the value `false`. - - @param stream The stream belonging to the connection. A service - which handles the request may optionally take ownership of the - stream. - - @param ep The remote endpoint of the connection corresponding - to the stream. - - @param req The request message to attempt handling. A service - which handles the request may optionally take ownership of the - message. - - @param send The function to invoke with the response. The function - should have this equivalent signature: - - @code - - template - void - send(response&&); - - @endcode - - In C++14 this can be expressed using a generic lambda. In - C++11 it will require a template member function of an invocable - object. - - @return `true` if the request was handled by a service. - */ - template< - class Stream, - class Body, - class Send> - bool - respond( - Stream&& stream, - endpoint_type const& ep, - beast::http::request&& req, - Send const& send) const - { - return try_respond( - std::move(stream), - ep, - std::move(req), - send, C<0>{}); - } - -private: - /* The implementation of `try_respond` is implemented using - tail recursion which can usually be optimized away to - something resembling a switch statement. - */ - template< - class Stream, - class Body, - class Send> - bool - try_respond( - Stream&&, - endpoint_type const&, - beast::http::request&&, - Send const&, - C const&) const - { - // This function breaks the recursion for the case where - // where the Index is one past the last type in the list. - // - return false; - } - - // Invoke the I-th type in the type list - // - template< - class Stream, - class Body, - class Send, - std::size_t I> - bool - try_respond( - Stream&& stream, - endpoint_type const& ep, - beast::http::request&& req, - Send const& send, - C const&) const - { - // If the I-th service handles the request then return - // - if(std::get(list_)->respond( - std::move(stream), - ep, - std::move(req), - send)) - return true; - - // Try the I+1th service. If I==sizeof...(Services) - // then we call the other overload and return false. - // - return try_respond( - std::move(stream), - ep, - std::move(req), - send, - C{}); - } -}; - -} // framework - -#endif diff --git a/src/beast/example/server-framework/ssl_certificate.hpp b/src/beast/example/server-framework/ssl_certificate.hpp deleted file mode 100644 index aaa2e0b8536..00000000000 --- a/src/beast/example/server-framework/ssl_certificate.hpp +++ /dev/null @@ -1,146 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_EXAMPLE_SERVER_SSL_CERTIFICATE_HPP -#define BEAST_EXAMPLE_SERVER_SSL_CERTIFICATE_HPP - -#include -#include -#include -#include - -namespace framework { - -// This sets up the self-signed certificate that the server -// uses for its encrypted connections - -class ssl_certificate -{ - // The template argument is gratuitous, to - // make the definition header-only without - // also making it inline. - // - template - void - construct(); - - boost::asio::ssl::context ctx_; - -public: - ssl_certificate() - : ctx_(boost::asio::ssl::context::sslv23) - { - construct(); - } - - boost::asio::ssl::context& - get() - { - return ctx_; - } -}; - -template -void -ssl_certificate::construct() -{ - /* - The certificate was generated from CMD.EXE on Windows 10 using: - - winpty openssl dhparam -out dh.pem 2048 - winpty openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 10000 -out cert.pem -subj "//C=US\ST=CA\L=Los Angeles\O=Beast\CN=www.example.com" - */ - - std::string const cert = - "-----BEGIN CERTIFICATE-----\n" - "MIIDaDCCAlCgAwIBAgIJAO8vBu8i8exWMA0GCSqGSIb3DQEBCwUAMEkxCzAJBgNV\n" - "BAYTAlVTMQswCQYDVQQIDAJDQTEtMCsGA1UEBwwkTG9zIEFuZ2VsZXNPPUJlYXN0\n" - "Q049d3d3LmV4YW1wbGUuY29tMB4XDTE3MDUwMzE4MzkxMloXDTQ0MDkxODE4Mzkx\n" - "MlowSTELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMS0wKwYDVQQHDCRMb3MgQW5n\n" - "ZWxlc089QmVhc3RDTj13d3cuZXhhbXBsZS5jb20wggEiMA0GCSqGSIb3DQEBAQUA\n" - "A4IBDwAwggEKAoIBAQDJ7BRKFO8fqmsEXw8v9YOVXyrQVsVbjSSGEs4Vzs4cJgcF\n" - "xqGitbnLIrOgiJpRAPLy5MNcAXE1strVGfdEf7xMYSZ/4wOrxUyVw/Ltgsft8m7b\n" - "Fu8TsCzO6XrxpnVtWk506YZ7ToTa5UjHfBi2+pWTxbpN12UhiZNUcrRsqTFW+6fO\n" - "9d7xm5wlaZG8cMdg0cO1bhkz45JSl3wWKIES7t3EfKePZbNlQ5hPy7Pd5JTmdGBp\n" - "yY8anC8u4LPbmgW0/U31PH0rRVfGcBbZsAoQw5Tc5dnb6N2GEIbq3ehSfdDHGnrv\n" - "enu2tOK9Qx6GEzXh3sekZkxcgh+NlIxCNxu//Dk9AgMBAAGjUzBRMB0GA1UdDgQW\n" - "BBTZh0N9Ne1OD7GBGJYz4PNESHuXezAfBgNVHSMEGDAWgBTZh0N9Ne1OD7GBGJYz\n" - "4PNESHuXezAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQCmTJVT\n" - "LH5Cru1vXtzb3N9dyolcVH82xFVwPewArchgq+CEkajOU9bnzCqvhM4CryBb4cUs\n" - "gqXWp85hAh55uBOqXb2yyESEleMCJEiVTwm/m26FdONvEGptsiCmF5Gxi0YRtn8N\n" - "V+KhrQaAyLrLdPYI7TrwAOisq2I1cD0mt+xgwuv/654Rl3IhOMx+fKWKJ9qLAiaE\n" - "fQyshjlPP9mYVxWOxqctUdQ8UnsUKKGEUcVrA08i1OAnVKlPFjKBvk+r7jpsTPcr\n" - "9pWXTO9JrYMML7d+XRSZA1n3856OqZDX4403+9FnXCvfcLZLLKTBvwwFgEFGpzjK\n" - "UEVbkhd5qstF6qWK\n" - "-----END CERTIFICATE-----\n"; - - std::string const key = - "-----BEGIN PRIVATE KEY-----\n" - "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDJ7BRKFO8fqmsE\n" - "Xw8v9YOVXyrQVsVbjSSGEs4Vzs4cJgcFxqGitbnLIrOgiJpRAPLy5MNcAXE1strV\n" - "GfdEf7xMYSZ/4wOrxUyVw/Ltgsft8m7bFu8TsCzO6XrxpnVtWk506YZ7ToTa5UjH\n" - "fBi2+pWTxbpN12UhiZNUcrRsqTFW+6fO9d7xm5wlaZG8cMdg0cO1bhkz45JSl3wW\n" - "KIES7t3EfKePZbNlQ5hPy7Pd5JTmdGBpyY8anC8u4LPbmgW0/U31PH0rRVfGcBbZ\n" - "sAoQw5Tc5dnb6N2GEIbq3ehSfdDHGnrvenu2tOK9Qx6GEzXh3sekZkxcgh+NlIxC\n" - "Nxu//Dk9AgMBAAECggEBAK1gV8uETg4SdfE67f9v/5uyK0DYQH1ro4C7hNiUycTB\n" - "oiYDd6YOA4m4MiQVJuuGtRR5+IR3eI1zFRMFSJs4UqYChNwqQGys7CVsKpplQOW+\n" - "1BCqkH2HN/Ix5662Dv3mHJemLCKUON77IJKoq0/xuZ04mc9csykox6grFWB3pjXY\n" - "OEn9U8pt5KNldWfpfAZ7xu9WfyvthGXlhfwKEetOuHfAQv7FF6s25UIEU6Hmnwp9\n" - "VmYp2twfMGdztz/gfFjKOGxf92RG+FMSkyAPq/vhyB7oQWxa+vdBn6BSdsfn27Qs\n" - "bTvXrGe4FYcbuw4WkAKTljZX7TUegkXiwFoSps0jegECgYEA7o5AcRTZVUmmSs8W\n" - "PUHn89UEuDAMFVk7grG1bg8exLQSpugCykcqXt1WNrqB7x6nB+dbVANWNhSmhgCg\n" - "VrV941vbx8ketqZ9YInSbGPWIU/tss3r8Yx2Ct3mQpvpGC6iGHzEc/NHJP8Efvh/\n" - "CcUWmLjLGJYYeP5oNu5cncC3fXUCgYEA2LANATm0A6sFVGe3sSLO9un1brA4zlZE\n" - "Hjd3KOZnMPt73B426qUOcw5B2wIS8GJsUES0P94pKg83oyzmoUV9vJpJLjHA4qmL\n" - "CDAd6CjAmE5ea4dFdZwDDS8F9FntJMdPQJA9vq+JaeS+k7ds3+7oiNe+RUIHR1Sz\n" - "VEAKh3Xw66kCgYB7KO/2Mchesu5qku2tZJhHF4QfP5cNcos511uO3bmJ3ln+16uR\n" - "GRqz7Vu0V6f7dvzPJM/O2QYqV5D9f9dHzN2YgvU9+QSlUeFK9PyxPv3vJt/WP1//\n" - "zf+nbpaRbwLxnCnNsKSQJFpnrE166/pSZfFbmZQpNlyeIuJU8czZGQTifQKBgHXe\n" - "/pQGEZhVNab+bHwdFTxXdDzr+1qyrodJYLaM7uFES9InVXQ6qSuJO+WosSi2QXlA\n" - "hlSfwwCwGnHXAPYFWSp5Owm34tbpp0mi8wHQ+UNgjhgsE2qwnTBUvgZ3zHpPORtD\n" - "23KZBkTmO40bIEyIJ1IZGdWO32q79nkEBTY+v/lRAoGBAI1rbouFYPBrTYQ9kcjt\n" - "1yfu4JF5MvO9JrHQ9tOwkqDmNCWx9xWXbgydsn/eFtuUMULWsG3lNjfst/Esb8ch\n" - "k5cZd6pdJZa4/vhEwrYYSuEjMCnRb0lUsm7TsHxQrUd6Fi/mUuFU/haC0o0chLq7\n" - "pVOUFq5mW8p0zbtfHbjkgxyF\n" - "-----END PRIVATE KEY-----\n"; - - std::string const dh = - "-----BEGIN DH PARAMETERS-----\n" - "MIIBCAKCAQEArzQc5mpm0Fs8yahDeySj31JZlwEphUdZ9StM2D8+Fo7TMduGtSi+\n" - "/HRWVwHcTFAgrxVdm+dl474mOUqqaz4MpzIb6+6OVfWHbQJmXPepZKyu4LgUPvY/\n" - "4q3/iDMjIS0fLOu/bLuObwU5ccZmDgfhmz1GanRlTQOiYRty3FiOATWZBRh6uv4u\n" - "tff4A9Bm3V9tLx9S6djq31w31Gl7OQhryodW28kc16t9TvO1BzcV3HjRPwpe701X\n" - "oEEZdnZWANkkpR/m/pfgdmGPU66S2sXMHgsliViQWpDCYeehrvFRHEdR9NV+XJfC\n" - "QMUk26jPTIVTLfXmmwU0u8vUkpR7LQKkwwIBAg==\n" - "-----END DH PARAMETERS-----\n"; - - ctx_.set_password_callback( - [](std::size_t, - boost::asio::ssl::context_base::password_purpose) - { - return "test"; - }); - - ctx_.set_options( - boost::asio::ssl::context::default_workarounds | - boost::asio::ssl::context::no_sslv2 | - boost::asio::ssl::context::single_dh_use); - - ctx_.use_certificate_chain( - boost::asio::buffer(cert.data(), cert.size())); - - ctx_.use_private_key( - boost::asio::buffer(key.data(), key.size()), - boost::asio::ssl::context::file_format::pem); - - ctx_.use_tmp_dh( - boost::asio::buffer(dh.data(), dh.size())); -} - -} // framework - -#endif diff --git a/src/beast/example/server-framework/ws_async_port.hpp b/src/beast/example/server-framework/ws_async_port.hpp deleted file mode 100644 index c799ab9f89b..00000000000 --- a/src/beast/example/server-framework/ws_async_port.hpp +++ /dev/null @@ -1,374 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_EXAMPLE_SERVER_WS_ASYNC_PORT_HPP -#define BEAST_EXAMPLE_SERVER_WS_ASYNC_PORT_HPP - -#include "server.hpp" - -#include -#include -#include -#include -#include - -namespace framework { - -// This object holds the state of the connection -// including, most importantly, the socket or stream. -// -// -template -class async_ws_con_base -{ - // This function lets us access members of the derived class - Derived& - impl() - { - return static_cast(*this); - } - - // The string used to set the Server http field - std::string server_name_; - - // The stream to use for logging - std::ostream& log_; - - // A small unique integer for logging - std::size_t id_; - - // The remote endpoint. We cache it here because - // calls to remote_endpoint() can fail / throw. - // - endpoint_type ep_; - - // This is used to hold the message data - beast::multi_buffer buffer_; - -protected: - // The strand makes sure that our data is - // accessed from only one thread at a time. - // - strand_type strand_; - -public: - // Constructor - template - async_ws_con_base( - beast::string_view server_name, - std::ostream& log, - std::size_t id, - endpoint_type const& ep, - Callback const& cb) - : server_name_(server_name) - , log_(log) - , id_(id) - , ep_(ep) - - // Limit of 1MB on messages - , buffer_(1024 * 1024) - - , strand_(impl().stream().get_io_service()) - { - cb(impl().stream()); - } - - // Run the connection - // - void - run() - { - impl().do_handshake(); - } - - // Run the connection. - // - // This overload handles the case where we - // already have the WebSocket Upgrade request. - // - template - void - run(beast::http::request const& req) - { - // Call the overload of accept() which takes - // the request by parameter, instead of reading - // it from the network. - // - impl().stream().async_accept_ex(req, - [&](beast::websocket::response_type& res) - { - res.set(beast::http::field::server, server_name_); - }, - strand_.wrap(std::bind( - &async_ws_con_base::on_accept, - impl().shared_from_this(), - std::placeholders::_1))); - } - -protected: - // Performs the WebSocket handshake - void - do_accept() - { - // Read the WebSocket upgrade request and attempt - // to send back the response. - // - impl().stream().async_accept_ex( - [&](beast::websocket::response_type& res) - { - res.set(beast::http::field::server, server_name_); - }, - strand_.wrap(std::bind( - &async_ws_con_base::on_accept, - impl().shared_from_this(), - std::placeholders::_1))); - } - - // This helper reports failures - // - void - fail(std::string what, error_code ec) - { - if(ec != beast::websocket::error::closed) - log_ << - "[#" << id_ << " " << ep_ << "] " << - what << ": " << ec.message() << std::endl; - } - -private: - // Called when accept_ex completes - // - void - on_accept(error_code ec) - { - if(ec) - return fail("async_accept", ec); - do_read(); - } - - // Read the next WebSocket message - // - void - do_read() - { - impl().stream().async_read( - buffer_, - strand_.wrap(std::bind( - &async_ws_con_base::on_read, - impl().shared_from_this(), - std::placeholders::_1))); - } - - // Called when the message read completes - // - void - on_read(error_code ec) - { - if(ec) - return fail("on_read", ec); - - // Set the outgoing message type. We will use - // the same setting as the message we just read. - // - impl().stream().binary(impl().stream().got_binary()); - - // Now echo back the message - // - impl().stream().async_write( - buffer_.data(), - strand_.wrap(std::bind( - &async_ws_con_base::on_write, - impl().shared_from_this(), - std::placeholders::_1))); - } - - // Called when the message write completes - // - void - on_write(error_code ec) - { - if(ec) - return fail("on_write", ec); - - // Empty out the contents of the message buffer - // to prepare it for the next call to read. - // - buffer_.consume(buffer_.size()); - - // Now read another message - // - do_read(); - } -}; - -//------------------------------------------------------------------------------ - -// This class represents an asynchronous WebSocket connection -// which uses a plain TCP/IP socket (no encryption) as the stream. -// -class async_ws_con - - // Give this object the enable_shared_from_this, and have - // the base class call impl().shared_from_this(). The reason - // is so that the shared_ptr has the correct type. This lets - // the derived class (this class) use its members in calls to - // `std::bind`, without an ugly call to `dynamic_downcast` or - // other nonsense. - // - : public std::enable_shared_from_this - - // The stream should be created before the base class so - // use the "base from member" idiom. - // - , public base_from_member> - - // Constructs last, destroys first - // - , public async_ws_con_base -{ -public: - // Constructor - // - // Additional arguments are forwarded to the base class - // - template - explicit - async_ws_con( - socket_type&& sock, - Args&&... args) - : base_from_member>(std::move(sock)) - , async_ws_con_base(std::forward(args)...) - { - } - - // Returns the stream. - // - // The base class calls this to obtain the object to use for - // reading and writing HTTP messages. This allows the same base - // class to work with different return types for `stream()` such - // as a `boost::asio::ip::tcp::socket&` or a `boost::asio::ssl::stream&` - // - beast::websocket::stream& - stream() - { - return this->member; - } - -private: - // Base class needs to be a friend to call our private members - friend async_ws_con_base; - - void - do_handshake() - { - do_accept(); - } -}; - -//------------------------------------------------------------------------------ - -/** An asynchronous WebSocket @b PortHandler which implements echo. - - This is a port handler which accepts WebSocket upgrade HTTP - requests and implements the echo protocol. All received - WebSocket messages will be echoed back to the remote host. -*/ -class ws_async_port -{ - // The type of the on_new_stream callback - // - using on_new_stream_cb = - boost::function&)>; - - server& instance_; - std::ostream& log_; - on_new_stream_cb cb_; - -public: - /** Constructor - - @param instance The server instance which owns this port - - @param log The stream to use for logging - - @param cb A callback which will be invoked for every new - WebSocket connection. This provides an opportunity to change - the settings on the stream before it is used. The callback - should have this equivalent signature: - @code - template - void callback(beast::websocket::stream&); - @endcode - In C++14 this can be accomplished with a generic lambda. In - C++11 it will be necessary to write out a lambda manually, - with a templated operator(). - */ - template - ws_async_port( - server& instance, - std::ostream& log, - Callback const& cb) - : instance_(instance) - , log_(log) - , cb_(cb) - { - } - - /** Accept a TCP/IP connection. - - This function is called when the server has accepted an - incoming connection. - - @param sock The connected socket. - - @param ep The endpoint of the remote host. - */ - void - on_accept( - socket_type&& sock, - endpoint_type ep) - { - std::make_shared( - std::move(sock), - "ws_async_port", - log_, - instance_.next_id(), - ep, - cb_)->run(); - } - - /** Accept a WebSocket upgrade request. - - This is used to accept a connection that has already - delivered the handshake. - - @param stream The stream corresponding to the connection. - - @param ep The remote endpoint. - - @param req The upgrade request. - */ - template - void - on_upgrade( - socket_type&& sock, - endpoint_type ep, - beast::http::request&& req) - { - std::make_shared( - std::move(sock), - "ws_async_port", - log_, - instance_.next_id(), - ep, - cb_)->run(std::move(req)); - } -}; - -} // framework - -#endif diff --git a/src/beast/example/server-framework/ws_sync_port.hpp b/src/beast/example/server-framework/ws_sync_port.hpp deleted file mode 100644 index 4ebea95fa55..00000000000 --- a/src/beast/example/server-framework/ws_sync_port.hpp +++ /dev/null @@ -1,432 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_EXAMPLE_SERVER_WS_SYNC_PORT_HPP -#define BEAST_EXAMPLE_SERVER_WS_SYNC_PORT_HPP - -#include "server.hpp" - -#include -#include -#include -#include -#include -#include - -namespace framework { - -/** A synchronous WebSocket connection. - - This base class implements a WebSocket connection object using - synchronous calls over an unencrypted connection. - - It uses the Curiously Recurring Template pattern (CRTP) where - we refer to the derived class in order to access the stream object - to use for reading and writing. This lets the same class be used - for plain and SSL stream objects. -*/ -template -class sync_ws_con_base -{ - // This function lets us access members of the derived class - Derived& - impl() - { - return static_cast(*this); - } - - // The string used to set the Server http field - std::string server_name_; - - // The stream to use for logging - std::ostream& log_; - - // A small unique integer for logging - std::size_t id_; - - // The remote endpoint. We cache it here because - // calls to remote_endpoint() can fail / throw. - // - endpoint_type ep_; - -public: - // Constructor - // - // Additional arguments are forwarded to the base class - // - template - sync_ws_con_base( - beast::string_view server_name, - std::ostream& log, - std::size_t id, - endpoint_type const& ep, - Callback const& cb) - : server_name_(server_name) - , log_(log) - , id_(id) - , ep_(ep) - { - cb(impl().stream()); - } - - // Run the connection. This is called for the case - // where we have not received the upgrade request yet. - // - void - run() - { - // We run the do_run function in its own thread, - // and bind a shared pointer to the connection object - // into the function. The last reference to the shared - // pointer will go away when the thread exits, thus - // destroying the connection object. - // - std::thread{ - &sync_ws_con_base::do_accept, - impl().shared_from_this() - }.detach(); - } - - // Run the connection from an already-received Upgrade request. - // - template - void - run(beast::http::request&& req) - { - BOOST_ASSERT(beast::websocket::is_upgrade(req)); - - // We need to transfer ownership of the request object into - // the lambda, but there's no C++14 lambda capture - // so we have to write it out by manually specifying the lambda. - // - std::thread{ - lambda{ - impl().shared_from_this(), - std::move(req) - }}.detach(); - } - -protected: - // Called when a failure occurs - // - void - fail(std::string what, error_code ec) - { - // Don't report the "closed" error since that - // happens under normal circumstances. - // - if(ec && ec != beast::websocket::error::closed) - { - log_ << - "[#" << id_ << " " << ep_ << "] " << - what << ": " << ec.message() << std::endl; - log_.flush(); - } - } - -private: - // This function performs the WebSocket handshake - // and runs the main loop upon success. - void - do_accept() - { - error_code ec; - - // Give the derived class a chance to do stuff before we - // enter the main loop. This is for SSL connections really. - // - impl().do_handshake(ec); - - if(ec) - return fail("handshake", ec); - - // Read the WebSocket upgrade request and attempt - // to send back the response. - // - impl().stream().accept_ex( - [&](beast::websocket::response_type& res) - { - res.insert(beast::http::field::server, server_name_); - }, - ec); - - if(ec) - return fail("accept", ec); - - // Run the connection - // - do_run(); - } - - // This is the lambda used when launching a connection from - // an already-received request. In C++14 we could simply use - // a lambda capture but this example requires only C++11 so - // we write out the lambda ourselves. This is similar to what - // the compiler would generate anyway. - // - template - class lambda - { - std::shared_ptr self_; - beast::http::request req_; - - public: - // Constructor - // - // This is the equivalent of the capture section of the lambda. - // - lambda( - std::shared_ptr self, - beast::http::request&& req) - : self_(std::move(self)) - , req_(std::move(req)) - { - BOOST_ASSERT(beast::websocket::is_upgrade(req_)); - } - - // Invoke the lambda - // - void - operator()() - { - BOOST_ASSERT(beast::websocket::is_upgrade(req_)); - error_code ec; - { - // Move the message to the stack so we can get - // rid of resources, otherwise it will linger - // for the lifetime of the connection. - // - auto req = std::move(req_); - - // Call the overload of accept() which takes - // the request by parameter, instead of reading - // it from the network. - // - self_->impl().stream().accept_ex(req, - [&](beast::websocket::response_type& res) - { - res.insert(beast::http::field::server, self_->server_name_); - }, - ec); - } - - if(ec) - return self_->fail("accept", ec); - - self_->do_run(); - } - }; - - void - do_run() - { - error_code ec; - - // Loop, reading messages and echoing them back. - // - for(;;) - { - // This buffer holds the message. We place a one - // megabyte limit on the size to prevent abuse. - // - beast::multi_buffer buffer{1024*1024}; - - // Read the message - // - impl().stream().read(buffer, ec); - - if(ec) - return fail("read", ec); - - // Set the outgoing message type. We will use - // the same setting as the message we just read. - // - impl().stream().binary(impl().stream().got_binary()); - - // Now echo back the message - // - impl().stream().write(buffer.data(), ec); - - if(ec) - return fail("write", ec); - } - } -}; - -//------------------------------------------------------------------------------ - -// This class represents a synchronous WebSocket connection -// which uses a plain TCP/IP socket (no encryption) as the stream. -// -class sync_ws_con - - // Give this object the enable_shared_from_this, and have - // the base class call impl().shared_from_this(). The reason - // is so that the shared_ptr has the correct type. This lets - // the derived class (this class) use its members in calls to - // `std::bind`, without an ugly call to `dynamic_downcast` or - // other nonsense. - // - : public std::enable_shared_from_this - - // The stream should be created before the base class so - // use the "base from member" idiom. - // - , public base_from_member> - - // Constructs last, destroys first - // - , public sync_ws_con_base -{ -public: - // Construct the plain connection. - // - template - explicit - sync_ws_con( - socket_type&& sock, - Args&&... args) - : base_from_member>(std::move(sock)) - , sync_ws_con_base(std::forward(args)...) - { - } - - // Returns the stream. - // - // The base class calls this to obtain the object to use for - // reading and writing HTTP messages. This allows the same base - // class to work with different return types for `stream()` such - // as a `boost::asio::ip::tcp::socket&` or a `boost::asio::ssl::stream&` - // - beast::websocket::stream& - stream() - { - return this->member; - } - -private: - // Base class needs to be a friend to call our private members - friend class sync_ws_con_base; - - // This is called by the base before running the main loop. - // There's nothing to do for a plain connection. - // - void - do_handshake(error_code& ec) - { - // This is required by the specifications for error_code - // - ec = {}; - } -}; - -//------------------------------------------------------------------------------ - -/** A synchronous WebSocket @b PortHandler which implements echo. - - This is a port handler which accepts WebSocket upgrade HTTP - requests and implements the echo protocol. All received - WebSocket messages will be echoed back to the remote host. -*/ -class ws_sync_port -{ - // The type of the on_new_stream callback - // - using on_new_stream_cb = - boost::function&)>; - - server& instance_; - std::ostream& log_; - on_new_stream_cb cb_; - -public: - /** Constructor - - @param instance The server instance which owns this port - - @param log The stream to use for logging - - @param cb A callback which will be invoked for every new - WebSocket connection. This provides an opportunity to change - the settings on the stream before it is used. The callback - should have this equivalent signature: - @code - template - void callback(beast::websocket::stream&); - @endcode - In C++14 this can be accomplished with a generic lambda. In - C++11 it will be necessary to write out a lambda manually, - with a templated operator(). - */ - template - ws_sync_port( - server& instance, - std::ostream& log, - Callback const& cb) - : instance_(instance) - , log_(log) - , cb_(cb) - { - } - - /** Accept a TCP/IP connection. - - This function is called when the server has accepted an - incoming connection. - - @param sock The connected socket. - - @param ep The endpoint of the remote host. - */ - void - on_accept(socket_type&& sock, endpoint_type ep) - { - // Create our connection object and run it - // - std::make_shared( - std::move(sock), - "ws_sync_port", - log_, - instance_.next_id(), - ep, - cb_)->run(); - } - - /** Accept a WebSocket upgrade request. - - This is used to accept a connection that has already - delivered the handshake. - - @param stream The stream corresponding to the connection. - - @param ep The remote endpoint. - - @param req The upgrade request. - */ - template - void - on_upgrade( - socket_type&& sock, - endpoint_type ep, - beast::http::request&& req) - { - // Create the connection object and run it, - // transferring ownership of the ugprade request. - // - std::make_shared( - std::move(sock), - "ws_sync_port", - log_, - instance_.next_id(), - ep, - cb_)->run(std::move(req)); - } -}; - -} // framework - -#endif diff --git a/src/beast/example/server-framework/ws_upgrade_service.hpp b/src/beast/example/server-framework/ws_upgrade_service.hpp deleted file mode 100644 index d4d8f5d614a..00000000000 --- a/src/beast/example/server-framework/ws_upgrade_service.hpp +++ /dev/null @@ -1,101 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_EXAMPLE_SERVER_WS_UPGRADE_SERVICE_HPP -#define BEAST_EXAMPLE_SERVER_WS_UPGRADE_SERVICE_HPP - -#include "framework.hpp" - -#include -#include -#include - -namespace framework { - -/** An HTTP service which transfers WebSocket upgrade request to another port handler. - - @tparam PortHandler The type of port handler. The service will - handle WebSocket Upgrade requests by transferring ownership - of the stream and request to a port handler of this type. -*/ -template -class ws_upgrade_service -{ - PortHandler& handler_; - -public: - /** Constructor - - @param handler A shared pointer to the @b PortHandler to - handle WebSocket upgrade requests. - */ - explicit - ws_upgrade_service(PortHandler& handler) - : handler_(handler) - { - } - - /** Initialize the service. - - This provides an opportunity for the service to perform - initialization which may fail, while reporting an error - code instead of throwing an exception from the constructor. - */ - void - init(error_code& ec) - { - // This is required by the error_code specification - // - ec = {}; - } - - /** Handle a WebSocket Upgrade request. - - If the request is an upgrade request, ownership of the - stream and request will be transferred to the corresponding - WebSocket port handler. - - @param stream The stream corresponding to the connection. - - @param ep The remote endpoint associated with the stream. - - @req The request to check. - */ - template< - class Stream, - class Body, - class Send> - bool - respond( - Stream&& stream, - endpoint_type const& ep, - beast::http::request&& req, - Send const&) const - { - // If its not an upgrade request, return `false` - // to indicate that we are not handling it. - // - if(! beast::websocket::is_upgrade(req)) - return false; - - // Its an ugprade request, so transfer ownership - // of the stream and request to the port handler. - // - handler_.on_upgrade( - std::move(stream), - ep, - std::move(req)); - - // Tell the service list that we handled the request. - // - return true; - } -}; - -} // framework - -#endif diff --git a/src/beast/example/server-framework/wss_ports.hpp b/src/beast/example/server-framework/wss_ports.hpp deleted file mode 100644 index ff7f87e1aef..00000000000 --- a/src/beast/example/server-framework/wss_ports.hpp +++ /dev/null @@ -1,438 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_EXAMPLE_SERVER_WSS_PORTS_HPP -#define BEAST_EXAMPLE_SERVER_WSS_PORTS_HPP - -#include "ws_sync_port.hpp" -#include "ws_async_port.hpp" - -#include "../common/ssl_stream.hpp" - -#include -#include - -namespace framework { - -//------------------------------------------------------------------------------ - -// A synchronous WebSocket connection over an SSL connection -// -class sync_wss_con - - // Give this object the enable_shared_from_this, and have - // the base class call impl().shared_from_this(). The reason - // is so that the shared_ptr has the correct type. This lets - // the derived class (this class) use its members in calls to - // `std::bind`, without an ugly call to `dynamic_downcast` or - // other nonsense. - // - : public std::enable_shared_from_this - - // The stream should be created before the base class so - // use the "base from member" idiom. - // - , public base_from_member>> - - // Constructs last, destroys first - // - , public sync_ws_con_base -{ -public: - // Constructor - // - // Additional arguments are forwarded to the base class - // - template - explicit - sync_wss_con( - socket_type&& sock, - boost::asio::ssl::context& ctx, - Args&&... args) - : base_from_member>>(std::move(sock), ctx) - , sync_ws_con_base(std::forward(args)...) - { - } - - // Construct from an existing, handshaked SSL stream - // - template - sync_wss_con( - ssl_stream&& stream, - Args&&... args) - : base_from_member>>(std::move(stream)) - , sync_ws_con_base(std::forward(args)...) - { - } - - // Returns the stream. - // - // The base class calls this to obtain the object to use for - // reading and writing HTTP messages. This allows the same base - // class to work with different return types for `stream()` such - // as a `boost::asio::ip::tcp::socket&` or a `boost::asio::ssl::stream&` - // - beast::websocket::stream>& - stream() - { - return this->member; - } - -private: - friend class sync_ws_con_base; - - // This is called by the base before running the main loop. - // - void - do_handshake(error_code& ec) - { - // Perform the SSL handshake - // - // We use next_layer() to get at the underlying ssl_stream - // - stream().next_layer().handshake(boost::asio::ssl::stream_base::server, ec); - } -}; - -//------------------------------------------------------------------------------ - -// An asynchronous WebSocket connection over an SSL connection -// -class async_wss_con - - // Give this object the enable_shared_from_this, and have - // the base class call impl().shared_from_this(). The reason - // is so that the shared_ptr has the correct type. This lets - // the derived class (this class) use its members in calls to - // `std::bind`, without an ugly call to `dynamic_downcast` or - // other nonsense. - // - : public std::enable_shared_from_this - - // The stream should be created before the base class so - // use the "base from member" idiom. - // - , public base_from_member>> - - // Constructs last, destroys first - // - , public async_ws_con_base -{ -public: - // Constructor - // - // Additional arguments are forwarded to the base class - // - template - async_wss_con( - socket_type&& sock, - boost::asio::ssl::context& ctx, - Args&&... args) - : base_from_member>>(std::move(sock), ctx) - , async_ws_con_base(std::forward(args)...) - { - } - - // Construct from an existing, handshaked SSL stream - // - template - async_wss_con( - ssl_stream&& stream, - Args&&... args) - : base_from_member>>(std::move(stream)) - , async_ws_con_base(std::forward(args)...) - { - } - - // Returns the stream. - // - // The base class calls this to obtain the object to use for - // reading and writing HTTP messages. This allows the same base - // class to work with different return types for `stream()` such - // as a `boost::asio::ip::tcp::socket&` or a `boost::asio::ssl::stream&` - // - beast::websocket::stream>& - stream() - { - return this->member; - } - -private: - friend class async_ws_con_base; - - // Called by the port to start the connection - // after creating the object - // - void - do_handshake() - { - // This is SSL so perform the handshake first - // - stream().next_layer().async_handshake( - boost::asio::ssl::stream_base::server, - this->strand_.wrap( - std::bind( - &async_wss_con::on_handshake, - this->shared_from_this(), - std::placeholders::_1))); - } - - // Called when the SSL handshake completes - // - void - on_handshake(error_code ec) - { - if(ec) - return this->fail("on_handshake", ec); - - // Move on to accepting the WebSocket handshake - // - this->do_accept(); - } -}; - -//------------------------------------------------------------------------------ - -/** A synchronous Secure WebSocket @b PortHandler which implements echo. - - This is a port handler which accepts Secure WebSocket upgrade - HTTP requests and implements the echo protocol. All received - WebSocket messages will be echoed back to the remote host. -*/ -class wss_sync_port -{ - // VFALCO We use boost::function to work around a compiler - // crash with gcc and clang using libstdc++ - - // The types of the on_new_stream callbacks - // - using on_new_stream_cb1 = - boost::function&)>; - - using on_new_stream_cb2 = - boost::function>&)>; - - server& instance_; - std::ostream& log_; - boost::asio::ssl::context& ctx_; - on_new_stream_cb1 cb1_; - on_new_stream_cb2 cb2_; - -public: - /** Constructor - - @param instance The server instance which owns this port - - @param log The stream to use for logging - - @param ctx The SSL context holding the SSL certificates to use - - @param cb A callback which will be invoked for every new - WebSocket connection. This provides an opportunity to change - the settings on the stream before it is used. The callback - should have this equivalent signature: - @code - template - void callback(beast::websocket::stream&); - @endcode - In C++14 this can be accomplished with a generic lambda. In - C++11 it will be necessary to write out a lambda manually, - with a templated operator(). - */ - template - wss_sync_port( - server& instance, - std::ostream& log, - boost::asio::ssl::context& ctx, - Callback const& cb) - : instance_(instance) - , log_(log) - , ctx_(ctx) - , cb1_(cb) - , cb2_(cb) - { - } - - /** Accept a TCP/IP connection. - - This function is called when the server has accepted an - incoming connection. - - @param sock The connected socket. - - @param ep The endpoint of the remote host. - */ - void - on_accept(socket_type&& sock, endpoint_type ep) - { - // Create our connection object and run it - // - std::make_shared( - std::move(sock), - ctx_, - "wss_sync_port", - log_, - instance_.next_id(), - ep, - cb2_)->run(); - } - - /** Accept a WebSocket upgrade request. - - This is used to accept a connection that has already - delivered the handshake. - - @param stream The stream corresponding to the connection. - - @param ep The remote endpoint. - - @param req The upgrade request. - */ - template - void - on_upgrade( - ssl_stream&& stream, - endpoint_type ep, - beast::http::request&& req) - { - // Create the connection object and run it, - // transferring ownership of the ugprade request. - // - std::make_shared( - std::move(stream), - "wss_sync_port", - log_, - instance_.next_id(), - ep, - cb2_)->run(std::move(req)); - } -}; - -//------------------------------------------------------------------------------ - -/** An asynchronous WebSocket @b PortHandler which implements echo. - - This is a port handler which accepts WebSocket upgrade HTTP - requests and implements the echo protocol. All received - WebSocket messages will be echoed back to the remote host. -*/ -class wss_async_port -{ - // VFALCO We use boost::function to work around a compiler - // crash with gcc and clang using libstdc++ - - // The types of the on_new_stream callbacks - // - using on_new_stream_cb1 = - boost::function&)>; - - using on_new_stream_cb2 = - boost::function>&)>; - - // Reference to the server instance that made us - server& instance_; - - // The stream to log to - std::ostream& log_; - - // The context holds the SSL certificates the server uses - boost::asio::ssl::context& ctx_; - - // Called for each new websocket stream - on_new_stream_cb1 cb1_; - on_new_stream_cb2 cb2_; - -public: - /** Constructor - - @param instance The server instance which owns this port - - @param log The stream to use for logging - - @param ctx The SSL context holding the SSL certificates to use - - @param cb A callback which will be invoked for every new - WebSocket connection. This provides an opportunity to change - the settings on the stream before it is used. The callback - should have this equivalent signature: - @code - template - void callback(beast::websocket::stream&); - @endcode - In C++14 this can be accomplished with a generic lambda. In - C++11 it will be necessary to write out a lambda manually, - with a templated operator(). - */ - template - wss_async_port( - server& instance, - std::ostream& log, - boost::asio::ssl::context& ctx, - Callback const& cb) - : instance_(instance) - , log_(log) - , ctx_(ctx) - , cb1_(cb) - , cb2_(cb) - { - } - - /** Accept a TCP/IP connection. - - This function is called when the server has accepted an - incoming connection. - - @param sock The connected socket. - - @param ep The endpoint of the remote host. - */ - void - on_accept( - socket_type&& sock, - endpoint_type ep) - { - std::make_shared( - std::move(sock), - ctx_, - "wss_async_port", - log_, - instance_.next_id(), - ep, - cb2_)->run(); - } - - /** Accept a WebSocket upgrade request. - - This is used to accept a connection that has already - delivered the handshake. - - @param stream The stream corresponding to the connection. - - @param ep The remote endpoint. - - @param req The upgrade request. - */ - template - void - on_upgrade( - ssl_stream&& stream, - endpoint_type ep, - beast::http::request&& req) - { - std::make_shared( - std::move(stream), - "wss_async_port", - log_, - instance_.next_id(), - ep, - cb2_)->run(std::move(req)); - } -}; - -} // framework - -#endif diff --git a/src/beast/example/websocket-client-ssl/CMakeLists.txt b/src/beast/example/websocket-client-ssl/CMakeLists.txt deleted file mode 100644 index 676c2784c36..00000000000 --- a/src/beast/example/websocket-client-ssl/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -# Part of Beast - -GroupSources(include/beast beast) - -GroupSources(example/websocket-client-ssl "/") - -add_executable (websocket-client-ssl - ${BEAST_INCLUDES} - websocket_client_ssl.cpp -) - -target_link_libraries(websocket-client-ssl - Beast - ${OPENSSL_LIBRARIES} - ) diff --git a/src/beast/example/websocket-client-ssl/Jamfile b/src/beast/example/websocket-client-ssl/Jamfile deleted file mode 100644 index a0a0a2a75d2..00000000000 --- a/src/beast/example/websocket-client-ssl/Jamfile +++ /dev/null @@ -1,51 +0,0 @@ -# -# Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -# -# 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) -# - -import os ; - -if [ os.name ] = SOLARIS -{ - lib socket ; - lib nsl ; -} -else if [ os.name ] = NT -{ - lib ws2_32 ; - lib mswsock ; -} -else if [ os.name ] = HPUX -{ - lib ipv6 ; -} -else if [ os.name ] = HAIKU -{ - lib network ; -} - -if [ os.name ] = NT -{ - lib ssl : : ssleay32 ; - lib crypto : : libeay32 ; -} -else -{ - lib ssl ; - lib crypto ; -} - -project - : requirements - ssl - crypto - ; - -exe ssl-websocket-client : - ssl_websocket_client.cpp - : - coverage:no - ubasan:no - ; diff --git a/src/beast/example/websocket-client-ssl/websocket_client_ssl.cpp b/src/beast/example/websocket-client-ssl/websocket_client_ssl.cpp deleted file mode 100644 index eb739f03021..00000000000 --- a/src/beast/example/websocket-client-ssl/websocket_client_ssl.cpp +++ /dev/null @@ -1,119 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#include "../common/root_certificates.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include - -using tcp = boost::asio::ip::tcp; // from -namespace ssl = boost::asio::ssl; // from -namespace websocket = beast::websocket; // from - -int main() -{ - // A helper for reporting errors - auto const fail = - [](std::string what, beast::error_code ec) - { - std::cerr << what << ": " << ec.message() << std::endl; - std::cerr.flush(); - return EXIT_FAILURE; - }; - - boost::system::error_code ec; - - // Set up an asio socket to connect to a remote host - boost::asio::io_service ios; - tcp::resolver r{ios}; - tcp::socket sock{ios}; - - // Look up the domain name - std::string const host = "echo.websocket.org"; - auto const lookup = r.resolve({host, "https"}, ec); - if(ec) - return fail("resolve", ec); - - // Make the connection on the IP address we get from a lookup - boost::asio::connect(sock, lookup, ec); - if(ec) - return fail("connect", ec); - - // Create the required ssl context - ssl::context ctx{ssl::context::sslv23_client}; - - // This holds the root certificate used for verification - load_root_certificates(ctx, ec); - if(ec) - return fail("certificate", ec); - - // Wrap the now-connected socket in an SSL stream - using stream_type = ssl::stream; - stream_type stream{sock, ctx}; - stream.set_verify_mode(ssl::verify_none); - - // Perform SSL handshaking - stream.handshake(ssl::stream_base::client, ec); - if(ec) - return fail("ssl handshake", ec); - - // Now wrap the handshaked SSL stream in a websocket stream - websocket::stream ws{stream}; - - // Perform the websocket handshake - ws.handshake(host, "/", ec); - if(ec) - return fail("handshake", ec); - - // Send a message - ws.write(boost::asio::buffer("Hello, world!"), ec); - if(ec) - return fail("write", ec); - - // This buffer will hold the incoming message - beast::multi_buffer b; - - // Read the message into our buffer - ws.read(b, ec); - if(ec) - return fail("read", ec); - - // Send a "close" frame to the other end, this is a websocket thing - ws.close(websocket::close_code::normal, ec); - if(ec) - return fail("close", ec); - - // The buffers() function helps print a ConstBufferSequence - std::cout << beast::buffers(b.data()) << std::endl; - - // WebSocket says that to close a connection you have - // to keep reading messages until you receive a close frame. - // Beast delivers the close frame as an error from read. - // - beast::drain_buffer drain; // Throws everything away efficiently - for(;;) - { - // Keep reading messages... - ws.read(drain, ec); - - // ...until we get the special error code - if(ec == websocket::error::closed) - break; - - // Some other error occurred, report it and exit. - if(ec) - return fail("close", ec); - } - - return EXIT_SUCCESS; -} diff --git a/src/beast/example/websocket-client/CMakeLists.txt b/src/beast/example/websocket-client/CMakeLists.txt deleted file mode 100644 index 0e97d947500..00000000000 --- a/src/beast/example/websocket-client/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -# Part of Beast - -GroupSources(include/beast beast) - -GroupSources(example/websocket-client "/") - -add_executable (websocket-client - ${BEAST_INCLUDES} - ${EXTRAS_INCLUDES} - websocket_client.cpp -) - -target_link_libraries(websocket-client Beast) diff --git a/src/beast/example/websocket-client/Jamfile b/src/beast/example/websocket-client/Jamfile deleted file mode 100644 index 9dc2a5d440d..00000000000 --- a/src/beast/example/websocket-client/Jamfile +++ /dev/null @@ -1,13 +0,0 @@ -# -# Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -# -# 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) -# - -exe websocket-client : - websocket_client.cpp - : - coverage:no - ubasan:no - ; diff --git a/src/beast/example/websocket-client/websocket_client.cpp b/src/beast/example/websocket-client/websocket_client.cpp deleted file mode 100644 index 642bfe6f1de..00000000000 --- a/src/beast/example/websocket-client/websocket_client.cpp +++ /dev/null @@ -1,101 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -//[example_websocket_client - -#include -#include -#include -#include -#include -#include - -using tcp = boost::asio::ip::tcp; // from -namespace websocket = beast::websocket; // from - -int main() -{ - // A helper for reporting errors - auto const fail = - [](std::string what, beast::error_code ec) - { - std::cerr << what << ": " << ec.message() << std::endl; - std::cerr.flush(); - return EXIT_FAILURE; - }; - - boost::system::error_code ec; - - // Set up an asio socket - boost::asio::io_service ios; - tcp::resolver r{ios}; - tcp::socket sock{ios}; - - // Look up the domain name - std::string const host = "echo.websocket.org"; - auto const lookup = r.resolve({host, "http"}, ec); - if(ec) - return fail("resolve", ec); - - // Make the connection on the IP address we get from a lookup - boost::asio::connect(sock, lookup, ec); - if(ec) - return fail("connect", ec); - - // Wrap the now-connected socket in a websocket stream - websocket::stream ws{sock}; - - // Perform the websocket handshake - ws.handshake(host, "/", ec); - if(ec) - return fail("handshake", ec); - - // Send a message - ws.write(boost::asio::buffer(std::string("Hello, world!")), ec); - if(ec) - return fail("write", ec); - - // This buffer will hold the incoming message - beast::multi_buffer b; - - // Read the message into our buffer - ws.read(b, ec); - if(ec) - return fail("read", ec); - - // Send a "close" frame to the other end, this is a websocket thing - ws.close(websocket::close_code::normal, ec); - if(ec) - return fail("close", ec); - - // The buffers() function helps print a ConstBufferSequence - std::cout << beast::buffers(b.data()) << std::endl; - - // WebSocket says that to close a connection you have - // to keep reading messages until you receive a close frame. - // Beast delivers the close frame as an error from read. - // - beast::drain_buffer drain; // Throws everything away efficiently - for(;;) - { - // Keep reading messages... - ws.read(drain, ec); - - // ...until we get the special error code - if(ec == websocket::error::closed) - break; - - // Some other error occurred, report it and exit. - if(ec) - return fail("close", ec); - } - - // If we get here the connection was cleanly closed - return EXIT_SUCCESS; -} - -//] diff --git a/src/beast/example/websocket-server-async/CMakeLists.txt b/src/beast/example/websocket-server-async/CMakeLists.txt deleted file mode 100644 index b0f5ad18547..00000000000 --- a/src/beast/example/websocket-server-async/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -# Part of Beast - -GroupSources(include/beast beast) -GroupSources(example/websocket-server-async "/") - -add_executable (websocket-server-async - ${BEAST_INCLUDES} - websocket_server_async.cpp -) - -target_link_libraries(websocket-server-async - Beast - ) diff --git a/src/beast/example/websocket-server-async/Jamfile b/src/beast/example/websocket-server-async/Jamfile deleted file mode 100644 index 59571f2fd82..00000000000 --- a/src/beast/example/websocket-server-async/Jamfile +++ /dev/null @@ -1,13 +0,0 @@ -# -# Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -# -# 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) -# - -exe websocket-server-async : - websocket_server_async.cpp - : - coverage:no - ubasan:no - ; diff --git a/src/beast/example/websocket-server-async/websocket_server_async.cpp b/src/beast/example/websocket-server-async/websocket_server_async.cpp deleted file mode 100644 index 55978f0ab3a..00000000000 --- a/src/beast/example/websocket-server-async/websocket_server_async.cpp +++ /dev/null @@ -1,463 +0,0 @@ -// -// Copyright (c) 2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#include "../common/helpers.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace http = beast::http; // from -namespace websocket = beast::websocket; // from -namespace ip = boost::asio::ip; // from -using tcp = boost::asio::ip::tcp; // from - -//------------------------------------------------------------------------------ -// -// Example: WebSocket echo server, asynchronous -// -//------------------------------------------------------------------------------ - -/** WebSocket asynchronous echo server - - The server holds the listening socket, the io_service, and - the threads calling io_service::run -*/ -class server -{ - using error_code = beast::error_code; // Saves typing - using clock_type = - std::chrono::steady_clock; // For the timer - using stream_type = - websocket::stream; // The type of our websocket stream - std::ostream* log_; // Used for diagnostic output, may be null - boost::asio::io_service ios_; // The io_service, required - tcp::socket sock_; // Holds accepted connections - tcp::endpoint ep_; // The remote endpoint during accept - std::vector thread_; // Threads for the io_service - boost::asio::ip::tcp::acceptor acceptor_; // The listening socket - std::function mod_; // Called on new stream - boost::optional< - boost::asio::io_service::work> work_; // Keeps io_service::run from returning - - //-------------------------------------------------------------------------- - - class connection : public std::enable_shared_from_this - { - std::ostream* log_; // Where to log, may be null - tcp::endpoint ep_; // The remote endpoing - stream_type ws_; // The websocket stream - boost::asio::basic_waitable_timer< - clock_type> timer_; // Needed for timeouts - boost::asio::io_service::strand strand_;// Needed when threads > 1 - beast::multi_buffer buffer_; // Stores the current message - beast::drain_buffer drain_; // Helps discard data on close - std::size_t id_; // A small unique id - - public: - /// Constructor - connection( - server& parent, - tcp::endpoint const& ep, - tcp::socket&& sock) - : log_(parent.log_) - , ep_(ep) - , ws_(std::move(sock)) - , timer_(ws_.get_io_service(), (clock_type::time_point::max)()) - , strand_(ws_.get_io_service()) - , id_([] - { - static std::atomic n{0}; - return ++n; - }()) - { - // Invoke the callback for new connections if set. - // This allows the settings on the websocket stream - // to be adjusted. For example to turn compression - // on or off or adjust the read and write buffer sizes. - // - if(parent.mod_) - parent.mod_(ws_); - } - - // Called immediately after the connection is created. - // We keep this separate from the constructor because - // shared_from_this may not be called from constructors. - void run() - { - // Run the timer - on_timer({}); - - // Put the handshake on the timer - timer_.expires_from_now(std::chrono::seconds(15)); - - // Read the websocket handshake and send the response - ws_.async_accept_ex( - [](websocket::response_type& res) - { - res.insert(http::field::server, "websocket-server-async"); - }, - strand_.wrap(std::bind( - &connection::on_accept, - shared_from_this(), - std::placeholders::_1))); - } - - private: - // Called when the timer expires. - // We operate the timer continuously this simplifies the code. - // - void on_timer(error_code ec) - { - if(ec && ec != boost::asio::error::operation_aborted) - return fail("timer", ec); - - // Verify that the timer really expired - // since the deadline may have moved. - // - if(timer_.expires_at() <= clock_type::now()) - { - // Closing the socket cancels all outstanding - // operations. They will complete with - // boost::asio::error::operation_aborted - // - ws_.next_layer().close(ec); - return; - } - - // Wait on the timer - timer_.async_wait( - strand_.wrap(std::bind( - &connection::on_timer, - shared_from_this(), - std::placeholders::_1))); - } - - // Called after the handshake is performed - void on_accept(error_code ec) - { - if(ec) - return fail("accept", ec); - do_read(); - } - - // Read a message from the websocket stream - void do_read() - { - // Put the read on the timer - timer_.expires_from_now(std::chrono::seconds(15)); - - // Read a message - ws_.async_read(buffer_, - strand_.wrap(std::bind( - &connection::on_read, - shared_from_this(), - std::placeholders::_1))); - } - - // Called after the message read completes - void on_read(error_code ec) - { - // This error means the other side - // closed the websocket stream. - if(ec == websocket::error::closed) - return; - - if(ec) - return fail("read", ec); - - // Put the write on the timer - timer_.expires_from_now(std::chrono::seconds(15)); - - // Write the received message back - ws_.binary(ws_.got_binary()); - ws_.async_write(buffer_.data(), - strand_.wrap(std::bind( - &connection::on_write, - shared_from_this(), - std::placeholders::_1))); - } - - // Called after the message write completes - void on_write(error_code ec) - { - if(ec) - return fail("write", ec); - - // Empty out the buffer. This is - // needed if we want to do another read. - // - buffer_.consume(buffer_.size()); - - // This shows how the server can close the - // connection. Alternatively we could call - // do_read again and the connection would - // stay open until the other side closes it. - // - do_close(); - } - - // Sends a websocket close frame - void do_close() - { - // Put the close frame on the timer - timer_.expires_from_now(std::chrono::seconds(15)); - - // Send the close frame - ws_.async_close({}, - strand_.wrap(std::bind( - &connection::on_close, - shared_from_this(), - std::placeholders::_1))); - } - - // Called when writing the close frame completes - void on_close(error_code ec) - { - if(ec) - return fail("close", ec); - - on_drain({}); - } - - // Read and discard any leftover message data - void on_drain(error_code ec) - { - if(ec == websocket::error::closed) - { - // the connection has been closed gracefully - return; - } - - if(ec) - return fail("drain", ec); - - // WebSocket says that to close a connection you have - // to keep reading messages until you receive a close frame. - // Beast delivers the close frame as an error from read. - // - ws_.async_read(drain_, - strand_.wrap(std::bind( - &connection::on_drain, - shared_from_this(), - std::placeholders::_1))); - } - - // Pretty-print an error to the log - void fail(std::string what, error_code ec) - { - if(log_) - if(ec != boost::asio::error::operation_aborted) - print(*log_, "[#", id_, " ", ep_, "] ", what, ": ", ec.message()); - } - }; - - //-------------------------------------------------------------------------- - - // Pretty-print an error to the log - void fail(std::string what, error_code ec) - { - if(log_) - print(*log_, what, ": ", ec.message()); - } - - // Initiates an accept - void do_accept() - { - acceptor_.async_accept(sock_, ep_, - std::bind(&server::on_accept, this, - std::placeholders::_1)); - } - - // Called when receiving an incoming connection - void on_accept(error_code ec) - { - // This can happen during exit - if(! acceptor_.is_open()) - return; - - // This can happen during exit - if(ec == boost::asio::error::operation_aborted) - return; - - if(ec) - fail("accept", ec); - - // Create the connection and run it - std::make_shared(*this, ep_, std::move(sock_))->run(); - - // Initiate another accept - do_accept(); - } - -public: - /** Constructor. - - @param log A pointer to a stream to log to, or `nullptr` - to disable logging. - - @param threads The number of threads in the io_service. - */ - server(std::ostream* log, std::size_t threads) - : log_(log) - , sock_(ios_) - , acceptor_(ios_) - , work_(ios_) - { - thread_.reserve(threads); - for(std::size_t i = 0; i < threads; ++i) - thread_.emplace_back( - [&]{ ios_.run(); }); - } - - /// Destructor. - ~server() - { - work_ = boost::none; - ios_.dispatch([&] - { - error_code ec; - acceptor_.close(ec); - }); - for(auto& t : thread_) - t.join(); - } - - /// Return the listening endpoint. - tcp::endpoint - local_endpoint() const - { - return acceptor_.local_endpoint(); - } - - /** Set a handler called for new streams. - - This function is called for each new stream. - It is used to set options for every connection. - */ - template - void - on_new_stream(F const& f) - { - mod_ = f; - } - - /** Open a listening port. - - @param ep The address and port to bind to. - - @param ec Set to the error, if any occurred. - */ - void - open(tcp::endpoint const& ep, error_code& ec) - { - acceptor_.open(ep.protocol(), ec); - if(ec) - return fail("open", ec); - acceptor_.set_option( - boost::asio::socket_base::reuse_address{true}); - acceptor_.bind(ep, ec); - if(ec) - return fail("bind", ec); - acceptor_.listen( - boost::asio::socket_base::max_connections, ec); - if(ec) - return fail("listen", ec); - do_accept(); - } -}; - -//------------------------------------------------------------------------------ - -// This helper will apply some settings to a WebSocket -// stream. The server applies it to all new connections. -// -class set_stream_options -{ - websocket::permessage_deflate pmd_; - -public: - set_stream_options(set_stream_options const&) = default; - - explicit - set_stream_options( - websocket::permessage_deflate const& pmd) - : pmd_(pmd) - { - } - - template - void - operator()(websocket::stream& ws) const - { - ws.set_option(pmd_); - - // Turn off the auto-fragment option. - // This improves Autobahn performance. - // - ws.auto_fragment(false); - - // 64MB message size limit. - // The high limit is needed for Autobahn. - ws.read_message_max(64 * 1024 * 1024); - } -}; - -int main(int argc, char* argv[]) -{ - // Check command line arguments. - if(argc != 4) - { - std::cerr << - "Usage: " << argv[0] << "
\n" - " For IPv4, try: " << argv[0] << " 0.0.0.0 8080 1\n" - " For IPv6, try: " << argv[0] << " 0::0 8080 1\n" - ; - return EXIT_FAILURE; - } - - // Decode command line options - auto address = ip::address::from_string(argv[1]); - unsigned short port = static_cast(std::atoi(argv[2])); - unsigned short threads = static_cast(std::atoi(argv[3])); - - // Allow permessage-deflate - // compression on all connections - websocket::permessage_deflate pmd; - pmd.client_enable = true; - pmd.server_enable = true; - pmd.compLevel = 3; - - // Create our server - server s{&std::cout, threads}; - s.on_new_stream(set_stream_options{pmd}); - - // Open the listening port - beast::error_code ec; - s.open(tcp::endpoint{address, port}, ec); - if(ec) - { - std::cerr << "Error: " << ec.message(); - return EXIT_FAILURE; - } - - // Wait for CTRL+C. After receiving CTRL+C, - // the server should shut down cleanly. - // - sig_wait(); - - return EXIT_SUCCESS; -} diff --git a/src/beast/include/beast.hpp b/src/beast/include/beast.hpp deleted file mode 100644 index fe5add2cf49..00000000000 --- a/src/beast/include/beast.hpp +++ /dev/null @@ -1,19 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HPP -#define BEAST_HPP - -#include - -#include -#include -#include -#include -#include - -#endif diff --git a/src/beast/include/beast/config.hpp b/src/beast/include/beast/config.hpp deleted file mode 100644 index 9c92df041fe..00000000000 --- a/src/beast/include/beast/config.hpp +++ /dev/null @@ -1,33 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_CONFIG_HPP -#define BEAST_CONFIG_HPP - -#include - -// Available to every header -#include -#include - -/* - _MSC_VER and _MSC_FULL_VER by version: - - 14.0 (2015) 1900 190023026 - 14.0 (2015 Update 1) 1900 190023506 - 14.0 (2015 Update 2) 1900 190023918 - 14.0 (2015 Update 3) 1900 190024210 -*/ - -#ifdef BOOST_MSVC -#if BOOST_MSVC_FULL_VER < 190024210 -static_assert(false, - "This library requires Visual Studio 2015 Update 3 or later"); -#endif -#endif - -#endif diff --git a/src/beast/include/beast/core.hpp b/src/beast/include/beast/core.hpp deleted file mode 100644 index 3084c3e8869..00000000000 --- a/src/beast/include/beast/core.hpp +++ /dev/null @@ -1,40 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_CORE_HPP -#define BEAST_CORE_HPP - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#endif diff --git a/src/beast/include/beast/core/async_result.hpp b/src/beast/include/beast/core/async_result.hpp deleted file mode 100644 index 8465ba0bc21..00000000000 --- a/src/beast/include/beast/core/async_result.hpp +++ /dev/null @@ -1,205 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_ASYNC_COMPLETION_HPP -#define BEAST_ASYNC_COMPLETION_HPP - -#include -#include -#include -#include -#include -#include - -namespace beast { - -/** An interface for customising the behaviour of an asynchronous initiation function. - - This class is used for determining: - - @li The concrete completion handler type to be called at the end of the - asynchronous operation; - - @li the initiating function return type; and - - @li how the return value of the initiating function is obtained. - - The trait allows the handler and return types to be determined at the point - where the specific completion handler signature is known. - - This template takes advantage of specializations of both - `boost::asio::async_result` and `boost::asio::handler_type` for user-defined - completion token types. The primary template assumes that the - @b CompletionToken is the completion handler. - - @par Example - - The example shows how to define an asynchronous initiation function - whose completion handler receives an error code: - - @code - template< - class AsyncStream, // A stream supporting asynchronous read and write - class Handler // The handler to call with signature void(error_code) - > - async_return_type< // This provides the return type customization - Handler, void(error_code)> - do_async( - AsyncStream& stream, // The stream to work on - Handler&& handler) // Could be an rvalue or const reference - { - // Make sure we have an async stream - static_assert(is_async_stream::value, - "AsyncStream requirements not met"); - - // This helper converts the handler into the real handler type - async_completion init{handler}; - - ... // Create and invoke the composed operation - - // This provides the return value and executor customization - return init.result.get(); - } - @endcode - - @see @ref async_completion, @ref async_return_type, @ref handler_type -*/ -template -class async_result -{ - BOOST_STATIC_ASSERT( - ! std::is_reference::value); - - boost::asio::async_result::type> impl_; - - async_result(async_result const&) = delete; - async_result& operator=(async_result const&) = delete; - -public: - /// The concrete completion handler type for the specific signature. - using completion_handler_type = - typename boost::asio::handler_type< - CompletionToken, Signature>::type; - - /// The return type of the initiating function. - using return_type = - typename boost::asio::async_result< - completion_handler_type>::type; - - /** Construct an async result from a given handler. - - When using a specalised async_result, the constructor has - an opportunity to initialise some state associated with the - completion handler, which is then returned from the initiating - function. - */ - explicit - async_result(completion_handler_type& h) - : impl_(h) - { - } - - /// Obtain the value to be returned from the initiating function. - return_type - get() - { - return impl_.get(); - } -}; - -/** Helper for customizing the return type of asynchronous initiation functions. - - This class template is used to transform caller-provided completion - handlers in calls to asynchronous initiation functions. The transformation - allows customization of the return type of the initiating function, and the - function signature of the final handler. - - Example: - @code - ... - template - typename async_completion::result_type - async_initfn(..., CompletionToken&& handler) - { - async_completion completion{handler}; - ... - return completion.result.get(); - } - @endcode - - @tparam CompletionToken Specifies the model used to obtain the result of - the asynchronous operation. - - @tparam Signature The call signature for the completion handler type invoked - on completion of the asynchronous operation. - - @note See - Working Draft, C++ Extensions for Networking - - @see @ref async_return_type, @ref handler_type -*/ -template -struct async_completion -{ - /** The type of the final handler called by the asynchronous initiation function. - - Objects of this type will be callable with the specified signature. - */ - using completion_handler_type = typename async_result< - typename std::decay::type, - Signature>::completion_handler_type; - - /** Constructor - - The constructor creates the concrete completion handler and - makes the link between the handler and the asynchronous - result. - - @param token The completion token. If this is a regular completion - handler, copies may be made as needed. If the handler is movable, - it may also be moved. - */ - explicit - async_completion(CompletionToken& token) - : completion_handler(static_cast::value, - completion_handler_type&, CompletionToken&&>::type>(token)) - , result(completion_handler) - { - // CompletionToken is not invokable with the given signature - static_assert(is_completion_handler< - completion_handler_type, Signature>::value, - "CompletionToken requirements not met: signature mismatch"); - } - - /// The final completion handler, callable with the specified signature. - typename std::conditional::value, - completion_handler_type&, - completion_handler_type - >::type completion_handler; - - /// The return value of the asynchronous initiation function. - async_result::type, Signature> result; -}; - -template -using handler_type = typename beast::async_result< - typename std::decay::type, - Signature>::completion_handler_type; - -template -using async_return_type = typename beast::async_result< - typename std::decay::type, - Signature>::return_type; - -} // beast - -#endif diff --git a/src/beast/include/beast/core/bind_handler.hpp b/src/beast/include/beast/core/bind_handler.hpp deleted file mode 100644 index a4a30280a6f..00000000000 --- a/src/beast/include/beast/core/bind_handler.hpp +++ /dev/null @@ -1,70 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_BIND_HANDLER_HPP -#define BEAST_BIND_HANDLER_HPP - -#include -#include -#include -#include -#include - -namespace beast { - -/** Bind parameters to a completion handler, creating a new handler. - - This function creates a new handler which, when invoked with no - parameters, calls the original handler with the list of bound - arguments. The passed handler and arguments are forwarded into - the returned handler, which provides the same `io_service` - execution guarantees as the original handler. - - Unlike `boost::asio::io_service::wrap`, the returned handler can - be used in a subsequent call to `boost::asio::io_service::post` - instead of `boost::asio::io_service::dispatch`, to ensure that - the handler will not be invoked immediately by the calling - function. - - Example: - - @code - template - void - signal_aborted(AsyncReadStream& stream, ReadHandler&& handler) - { - stream.get_io_service().post( - bind_handler(std::forward(handler), - boost::asio::error::operation_aborted, 0)); - } - @endcode - - @param handler The handler to wrap. - - @param args A list of arguments to bind to the handler. The - arguments are forwarded into the returned object. -*/ -template -#if BEAST_DOXYGEN -implementation_defined -#else -detail::bound_handler< - typename std::decay::type, Args...> -#endif -bind_handler(Handler&& handler, Args&&... args) -{ - static_assert(is_completion_handler< - Handler, void(Args...)>::value, - "Handler requirements not met"); - return detail::bound_handler::type, Args...>(std::forward< - Handler>(handler), std::forward(args)...); -} - -} // beast - -#endif diff --git a/src/beast/include/beast/core/buffer_cat.hpp b/src/beast/include/beast/core/buffer_cat.hpp deleted file mode 100644 index ba33731e7e6..00000000000 --- a/src/beast/include/beast/core/buffer_cat.hpp +++ /dev/null @@ -1,119 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_BUFFER_CAT_HPP -#define BEAST_BUFFER_CAT_HPP - -#include -#include -#include - -namespace beast { - -/** A buffer sequence representing a concatenation of buffer sequences. - - @see @ref buffer_cat -*/ -template -class buffer_cat_view -{ -#if 0 - static_assert( - detail::is_all_const_buffer_sequence::value, - "BufferSequence requirements not met"); -#endif - - std::tuple bn_; - -public: - /** The type of buffer returned when dereferencing an iterator. - - If every buffer sequence in the view is a @b MutableBufferSequence, - then `value_type` will be `boost::asio::mutable_buffer`. - Otherwise, `value_type` will be `boost::asio::const_buffer`. - */ - using value_type = - #if BEAST_DOXYGEN - implementation_defined; - #else - typename detail::common_buffers_type::type; - #endif - - /// The type of iterator used by the concatenated sequence - class const_iterator; - - /// Move constructor - buffer_cat_view(buffer_cat_view&&) = default; - - /// Copy constructor - buffer_cat_view(buffer_cat_view const&) = default; - - /// Move assignment - buffer_cat_view& operator=(buffer_cat_view&&) = default; - - // Copy assignment - buffer_cat_view& operator=(buffer_cat_view const&) = default; - - /** Constructor - - @param buffers The list of buffer sequences to concatenate. - Copies of the arguments will be made; however, the ownership - of memory is not transferred. - */ - explicit - buffer_cat_view(Buffers const&... buffers); - - /// Return an iterator to the beginning of the concatenated sequence. - const_iterator - begin() const; - - /// Return an iterator to the end of the concatenated sequence. - const_iterator - end() const; -}; - -/** Concatenate 2 or more buffer sequences. - - This function returns a constant or mutable buffer sequence which, - when iterated, efficiently concatenates the input buffer sequences. - Copies of the arguments passed will be made; however, the returned - object does not take ownership of the underlying memory. The - application is still responsible for managing the lifetime of the - referenced memory. - - @param buffers The list of buffer sequences to concatenate. - - @return A new buffer sequence that represents the concatenation of - the input buffer sequences. This buffer sequence will be a - @b MutableBufferSequence if each of the passed buffer sequences is - also a @b MutableBufferSequence; otherwise the returned buffer - sequence will be a @b ConstBufferSequence. - - @see @ref buffer_cat_view -*/ -#if BEAST_DOXYGEN -template -buffer_cat_view -buffer_cat(BufferSequence const&... buffers) -#else -template -inline -buffer_cat_view -buffer_cat(B1 const& b1, B2 const& b2, Bn const&... bn) -#endif -{ - static_assert( - detail::is_all_const_buffer_sequence::value, - "BufferSequence requirements not met"); - return buffer_cat_view{b1, b2, bn...}; -} - -} // beast - -#include - -#endif diff --git a/src/beast/include/beast/core/buffer_prefix.hpp b/src/beast/include/beast/core/buffer_prefix.hpp deleted file mode 100644 index 1450504f78f..00000000000 --- a/src/beast/include/beast/core/buffer_prefix.hpp +++ /dev/null @@ -1,208 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_BUFFER_PREFIX_HPP -#define BEAST_BUFFER_PREFIX_HPP - -#include -#include -#include -#include -#include -#include - -namespace beast { - -/** A buffer sequence adapter that shortens the sequence size. - - The class adapts a buffer sequence to efficiently represent - a shorter subset of the original list of buffers starting - with the first byte of the original sequence. - - @tparam BufferSequence The buffer sequence to adapt. -*/ -template -class buffer_prefix_view -{ - using buffers_type = typename - std::decay::type; - - using iter_type = typename buffers_type::const_iterator; - - BufferSequence bs_; - iter_type back_; - iter_type end_; - std::size_t size_; - - template - buffer_prefix_view(Deduced&& other, - std::size_t nback, std::size_t nend) - : bs_(std::forward(other).bs_) - , back_(std::next(bs_.begin(), nback)) - , end_(std::next(bs_.begin(), nend)) - , size_(other.size_) - { - } - - void - setup(std::size_t n); - -public: - /// The type for each element in the list of buffers. - using value_type = typename std::conditional< - std::is_convertible::value_type, - boost::asio::mutable_buffer>::value, - boost::asio::mutable_buffer, - boost::asio::const_buffer>::type; - -#if BEAST_DOXYGEN - /// A bidirectional iterator type that may be used to read elements. - using const_iterator = implementation_defined; - -#else - class const_iterator; - -#endif - - /// Move constructor. - buffer_prefix_view(buffer_prefix_view&&); - - /// Copy constructor. - buffer_prefix_view(buffer_prefix_view const&); - - /// Move assignment. - buffer_prefix_view& operator=(buffer_prefix_view&&); - - /// Copy assignment. - buffer_prefix_view& operator=(buffer_prefix_view const&); - - /** Construct a buffer sequence prefix. - - @param n The maximum number of bytes in the prefix. - If this is larger than the size of passed, buffers, - the resulting sequence will represent the entire - input sequence. - - @param buffers The buffer sequence to adapt. A copy of - the sequence will be made, but ownership of the underlying - memory is not transferred. - */ - buffer_prefix_view(std::size_t n, BufferSequence const& buffers); - - /** Construct a buffer sequence prefix in-place. - - @param n The maximum number of bytes in the prefix. - If this is larger than the size of passed, buffers, - the resulting sequence will represent the entire - input sequence. - - @param args Arguments forwarded to the contained buffers constructor. - */ - template - buffer_prefix_view(std::size_t n, - boost::in_place_init_t, Args&&... args); - - /// Get a bidirectional iterator to the first element. - const_iterator - begin() const; - - /// Get a bidirectional iterator to one past the last element. - const_iterator - end() const; -}; - -/** Returns a prefix of a constant buffer. - - The returned buffer points to the same memory as the - passed buffer, but with a size that is equal to or less - than the size of the original buffer. - - @param n The size of the returned buffer. - - @param buffer The buffer to shorten. The underlying - memory is not modified. - - @return A new buffer that points to the first `n` bytes - of the original buffer. -*/ -inline -boost::asio::const_buffer -buffer_prefix(std::size_t n, - boost::asio::const_buffer buffer) -{ - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - return { buffer_cast(buffer), - (std::min)(n, buffer_size(buffer)) }; -} - -/** Returns a prefix of a mutable buffer. - - The returned buffer points to the same memory as the - passed buffer, but with a size that is equal to or less - than the size of the original buffer. - - @param n The size of the returned buffer. - - @param buffer The buffer to shorten. The underlying - memory is not modified. - - @return A new buffer that points to the first `n` bytes - of the original buffer. -*/ -inline -boost::asio::mutable_buffer -buffer_prefix(std::size_t n, - boost::asio::mutable_buffer buffer) -{ - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - return { buffer_cast(buffer), - (std::min)(n, buffer_size(buffer)) }; -} - -/** Returns a prefix of a buffer sequence. - - This function returns a new buffer sequence which when iterated, - presents a shorter subset of the original list of buffers starting - with the first byte of the original sequence. - - @param n The maximum number of bytes in the wrapped - sequence. If this is larger than the size of passed, - buffers, the resulting sequence will represent the - entire input sequence. - - @param buffers An instance of @b ConstBufferSequence or - @b MutableBufferSequence to adapt. A copy of the sequence - will be made, but ownership of the underlying memory is - not transferred. -*/ -template -#if BEAST_DOXYGEN -buffer_prefix_view -#else -inline -typename std::enable_if< - ! std::is_same::value && - ! std::is_same::value, - buffer_prefix_view>::type -#endif -buffer_prefix(std::size_t n, BufferSequence const& buffers) -{ - static_assert( - is_const_buffer_sequence::value || - is_mutable_buffer_sequence::value, - "BufferSequence requirements not met"); - return buffer_prefix_view(n, buffers); -} - -} // beast - -#include - -#endif diff --git a/src/beast/include/beast/core/buffered_read_stream.hpp b/src/beast/include/beast/core/buffered_read_stream.hpp deleted file mode 100644 index a365babe016..00000000000 --- a/src/beast/include/beast/core/buffered_read_stream.hpp +++ /dev/null @@ -1,356 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_BUFFERED_READ_STREAM_HPP -#define BEAST_BUFFERED_READ_STREAM_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { - -/** A @b Stream with attached @b DynamicBuffer to buffer reads. - - This wraps a @b Stream implementation so that calls to write are - passed through to the underlying stream, while calls to read will - first consume the input sequence stored in a @b DynamicBuffer which - is part of the object. - - The use-case for this class is different than that of the - `boost::asio::buffered_readstream`. It is designed to facilitate - the use of `boost::asio::read_until`, and to allow buffers - acquired during detection of handshakes to be made transparently - available to callers. A hypothetical implementation of the - buffered version of `boost::asio::ssl::stream::async_handshake` - could make use of this wrapper. - - Uses: - - @li Transparently leave untouched input acquired in calls - to `boost::asio::read_until` behind for subsequent callers. - - @li "Preload" a stream with handshake input data acquired - from other sources. - - Example: - @code - // Process the next HTTP header on the stream, - // leaving excess bytes behind for the next call. - // - template - void process_http_message( - buffered_read_stream& stream) - { - // Read up to and including the end of the HTTP - // header, leaving the sequence in the stream's - // buffer. read_until may read past the end of the - // headers; the return value will include only the - // part up to the end of the delimiter. - // - std::size_t bytes_transferred = - boost::asio::read_until( - stream.next_layer(), stream.buffer(), "\r\n\r\n"); - - // Use buffer_prefix() to limit the input - // sequence to only the data up to and including - // the trailing "\r\n\r\n". - // - auto header_buffers = buffer_prefix( - bytes_transferred, stream.buffer().data()); - - ... - - // Discard the portion of the input corresponding - // to the HTTP headers. - // - stream.buffer().consume(bytes_transferred); - - // Everything we read from the stream - // is part of the content-body. - } - @endcode - - @tparam Stream The type of stream to wrap. - - @tparam DynamicBuffer The type of stream buffer to use. -*/ -template -class buffered_read_stream -{ - static_assert(is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - - template - class read_some_op; - - DynamicBuffer sb_; - std::size_t capacity_ = 0; - Stream next_layer_; - -public: - /// The type of the internal buffer - using buffer_type = DynamicBuffer; - - /// The type of the next layer. - using next_layer_type = - typename std::remove_reference::type; - - /// The type of the lowest layer. - using lowest_layer_type = - typename get_lowest_layer::type; - - /** Move constructor. - - @note The behavior of move assignment on or from streams - with active or pending operations is undefined. - */ - buffered_read_stream(buffered_read_stream&&) = default; - - /** Move assignment. - - @note The behavior of move assignment on or from streams - with active or pending operations is undefined. - */ - buffered_read_stream& operator=(buffered_read_stream&&) = default; - - /** Construct the wrapping stream. - - @param args Parameters forwarded to the `Stream` constructor. - */ - template - explicit - buffered_read_stream(Args&&... args); - - /// Get a reference to the next layer. - next_layer_type& - next_layer() - { - return next_layer_; - } - - /// Get a const reference to the next layer. - next_layer_type const& - next_layer() const - { - return next_layer_; - } - - /// Get a reference to the lowest layer. - lowest_layer_type& - lowest_layer() - { - return next_layer_.lowest_layer(); - } - - /// Get a const reference to the lowest layer. - lowest_layer_type const& - lowest_layer() const - { - return next_layer_.lowest_layer(); - } - - /// Get the io_service associated with the object. - boost::asio::io_service& - get_io_service() - { - return next_layer_.get_io_service(); - } - - /** Access the internal buffer. - - The internal buffer is returned. It is possible for the - caller to break invariants with this function. For example, - by causing the internal buffer size to increase beyond - the caller defined maximum. - */ - DynamicBuffer& - buffer() - { - return sb_; - } - - /// Access the internal buffer - DynamicBuffer const& - buffer() const - { - return sb_; - } - - /** Set the maximum buffer size. - - This changes the maximum size of the internal buffer used - to hold read data. No bytes are discarded by this call. If - the buffer size is set to zero, no more data will be buffered. - - Thread safety: - The caller is responsible for making sure the call is - made from the same implicit or explicit strand. - - @param size The number of bytes in the read buffer. - - @note This is a soft limit. If the new maximum size is smaller - than the amount of data in the buffer, no bytes are discarded. - */ - void - capacity(std::size_t size) - { - capacity_ = size; - } - - /** Read some data from the stream. - - This function is used to read data from the stream. - The function call will block until one or more bytes of - data has been read successfully, or until an error occurs. - - @param buffers One or more buffers into which the data will be read. - - @return The number of bytes read. - - @throws system_error Thrown on failure. - */ - template - std::size_t - read_some(MutableBufferSequence const& buffers); - - /** Read some data from the stream. - - This function is used to read data from the stream. - The function call will block until one or more bytes of - data has been read successfully, or until an error occurs. - - @param buffers One or more buffers into which the data will be read. - - @param ec Set to the error, if any occurred. - - @return The number of bytes read, or 0 on error. - */ - template - std::size_t - read_some(MutableBufferSequence const& buffers, - error_code& ec); - - /** Start an asynchronous read. - - This function is used to asynchronously read data from - the stream. The function call always returns immediately. - - @param buffers One or more buffers into which the data - will be read. Although the buffers object may be copied - as necessary, ownership of the underlying memory blocks - is retained by the caller, which must guarantee that they - remain valid until the handler is called. - - @param handler The handler to be called when the operation - completes. Copies will be made of the handler as required. - The equivalent function signature of the handler must be: - @code void handler( - error_code const& error, // result of operation - std::size_t bytes_transferred // number of bytes transferred - ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. - */ - template -#if BEAST_DOXYGEN - void_or_deduced -#else - async_return_type -#endif - async_read_some(MutableBufferSequence const& buffers, - ReadHandler&& handler); - - /** Write some data to the stream. - - This function is used to write data to the stream. - The function call will block until one or more bytes of the - data has been written successfully, or until an error occurs. - - @param buffers One or more data buffers to be written to the stream. - - @return The number of bytes written. - - @throws system_error Thrown on failure. - */ - template - std::size_t - write_some(ConstBufferSequence const& buffers) - { - static_assert(is_sync_write_stream::value, - "SyncWriteStream requirements not met"); - return next_layer_.write_some(buffers); - } - - /** Write some data to the stream. - - This function is used to write data to the stream. - The function call will block until one or more bytes of the - data has been written successfully, or until an error occurs. - - @param buffers One or more data buffers to be written to the stream. - - @param ec Set to the error, if any occurred. - - @return The number of bytes written. - */ - template - std::size_t - write_some(ConstBufferSequence const& buffers, - error_code& ec) - { - static_assert(is_sync_write_stream::value, - "SyncWriteStream requirements not met"); - return next_layer_.write_some(buffers, ec); - } - - /** Start an asynchronous write. - - This function is used to asynchronously write data from - the stream. The function call always returns immediately. - - @param buffers One or more data buffers to be written to - the stream. Although the buffers object may be copied as - necessary, ownership of the underlying memory blocks is - retained by the caller, which must guarantee that they - remain valid until the handler is called. - - @param handler The handler to be called when the operation - completes. Copies will be made of the handler as required. - The equivalent function signature of the handler must be: - @code void handler( - error_code const& error, // result of operation - std::size_t bytes_transferred // number of bytes transferred - ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. - */ - template -#if BEAST_DOXYGEN - void_or_deduced -#else - async_return_type -#endif - async_write_some(ConstBufferSequence const& buffers, - WriteHandler&& handler); -}; - -} // beast - -#include - -#endif diff --git a/src/beast/include/beast/core/buffers_adapter.hpp b/src/beast/include/beast/core/buffers_adapter.hpp deleted file mode 100644 index 6cff9923ca5..00000000000 --- a/src/beast/include/beast/core/buffers_adapter.hpp +++ /dev/null @@ -1,158 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_BUFFERS_ADAPTER_HPP -#define BEAST_BUFFERS_ADAPTER_HPP - -#include -#include -#include -#include - -namespace beast { - -/** Adapts a @b MutableBufferSequence into a @b DynamicBuffer. - - This class wraps a @b MutableBufferSequence to meet the requirements - of @b DynamicBuffer. Upon construction the input and output sequences are - empty. A copy of the mutable buffer sequence object is stored; however, - ownership of the underlying memory is not transferred. The caller is - responsible for making sure that referenced memory remains valid - for the duration of any operations. - - The size of the mutable buffer sequence determines the maximum - number of bytes which may be prepared and committed. - - @tparam MutableBufferSequence The type of mutable buffer sequence to wrap. -*/ -template -class buffers_adapter -{ - static_assert(is_mutable_buffer_sequence::value, - "MutableBufferSequence requirements not met"); - - using iter_type = typename MutableBufferSequence::const_iterator; - - MutableBufferSequence bs_; - iter_type begin_; - iter_type out_; - iter_type end_; - std::size_t max_size_; - std::size_t in_pos_ = 0; // offset in *begin_ - std::size_t in_size_ = 0; // size of input sequence - std::size_t out_pos_ = 0; // offset in *out_ - std::size_t out_end_ = 0; // output end offset - - template - buffers_adapter(Deduced&& other, - std::size_t nbegin, std::size_t nout, - std::size_t nend) - : bs_(std::forward(other).bs_) - , begin_(std::next(bs_.begin(), nbegin)) - , out_(std::next(bs_.begin(), nout)) - , end_(std::next(bs_.begin(), nend)) - , max_size_(other.max_size_) - , in_pos_(other.in_pos_) - , in_size_(other.in_size_) - , out_pos_(other.out_pos_) - , out_end_(other.out_end_) - { - } - -public: -#if BEAST_DOXYGEN - /// The type used to represent the input sequence as a list of buffers. - using const_buffers_type = implementation_defined; - - /// The type used to represent the output sequence as a list of buffers. - using mutable_buffers_type = implementation_defined; - -#else - class const_buffers_type; - - class mutable_buffers_type; - -#endif - - /// Move constructor. - buffers_adapter(buffers_adapter&& other); - - /// Copy constructor. - buffers_adapter(buffers_adapter const& other); - - /// Move assignment. - buffers_adapter& operator=(buffers_adapter&& other); - - /// Copy assignment. - buffers_adapter& operator=(buffers_adapter const&); - - /** Construct a buffers adapter. - - @param buffers The mutable buffer sequence to wrap. A copy of - the object will be made, but ownership of the memory is not - transferred. - */ - explicit - buffers_adapter(MutableBufferSequence const& buffers); - - /// Returns the largest size output sequence possible. - std::size_t - max_size() const - { - return max_size_; - } - - /// Get the size of the input sequence. - std::size_t - size() const - { - return in_size_; - } - - /// Returns the maximum sum of the sizes of the input sequence and output sequence the buffer can hold without requiring reallocation. - std::size_t - capacity() const - { - return max_size_; - } - - /** Get a list of buffers that represents the output sequence, with the given size. - - @throws std::length_error if the size would exceed the limit - imposed by the underlying mutable buffer sequence. - - @note Buffers representing the input sequence acquired prior to - this call remain valid. - */ - mutable_buffers_type - prepare(std::size_t n); - - /** Move bytes from the output sequence to the input sequence. - - @note Buffers representing the input sequence acquired prior to - this call remain valid. - */ - void - commit(std::size_t n); - - /** Get a list of buffers that represents the input sequence. - - @note These buffers remain valid across subsequent calls to `prepare`. - */ - const_buffers_type - data() const; - - /// Remove bytes from the input sequence. - void - consume(std::size_t n); -}; - -} // beast - -#include - -#endif diff --git a/src/beast/include/beast/core/consuming_buffers.hpp b/src/beast/include/beast/core/consuming_buffers.hpp deleted file mode 100644 index 6baffaa470d..00000000000 --- a/src/beast/include/beast/core/consuming_buffers.hpp +++ /dev/null @@ -1,134 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_CONSUMING_BUFFERS_HPP -#define BEAST_CONSUMING_BUFFERS_HPP - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { - -/** Adapter to trim the front of a `BufferSequence`. - - This adapter wraps a buffer sequence to create a new sequence - which may be incrementally consumed. Bytes consumed are removed - from the front of the buffer. The underlying memory is not changed, - instead the adapter efficiently iterates through a subset of - the buffers wrapped. - - The wrapped buffer is not modified, a copy is made instead. - Ownership of the underlying memory is not transferred, the application - is still responsible for managing its lifetime. - - @tparam BufferSequence The buffer sequence to wrap. -*/ -template -class consuming_buffers -{ - using iter_type = - typename BufferSequence::const_iterator; - - BufferSequence bs_; - iter_type begin_; - std::size_t skip_ = 0; - - template - consuming_buffers(Deduced&& other, std::size_t nbegin) - : bs_(std::forward(other).bs_) - , begin_(std::next(bs_.begin(), nbegin)) - , skip_(other.skip_) - { - } - -public: - /** The type for each element in the list of buffers. - - If the buffers in the underlying sequence are convertible to - `boost::asio::mutable_buffer`, then this type will be - `boost::asio::mutable_buffer`, else this type will be - `boost::asio::const_buffer`. - */ -#if BEAST_DOXYGEN - using value_type = ...; -#else - using value_type = typename std::conditional< - std::is_convertible::value_type, - boost::asio::mutable_buffer>::value, - boost::asio::mutable_buffer, - boost::asio::const_buffer>::type; -#endif - -#if BEAST_DOXYGEN - /// A bidirectional iterator type that may be used to read elements. - using const_iterator = implementation_defined; - -#else - class const_iterator; - -#endif - - /// Constructor - consuming_buffers(); - - /// Move constructor - consuming_buffers(consuming_buffers&&); - - /// Copy constructor - consuming_buffers(consuming_buffers const&); - - /** Construct to represent a buffer sequence. - - A copy of the buffer sequence is made. Ownership of the - underlying memory is not transferred or copied. - */ - explicit - consuming_buffers(BufferSequence const& buffers); - - /** Construct a buffer sequence in-place. - - @param args Arguments forwarded to the contained buffers constructor. - */ - template - consuming_buffers(boost::in_place_init_t, Args&&... args); - - /// Move assignment - consuming_buffers& operator=(consuming_buffers&&); - - /// Copy assignmen - consuming_buffers& operator=(consuming_buffers const&); - - /// Get a bidirectional iterator to the first element. - const_iterator - begin() const; - - /// Get a bidirectional iterator to one past the last element. - const_iterator - end() const; - - /** Remove bytes from the beginning of the sequence. - - @param n The number of bytes to remove. If this is - larger than the number of bytes remaining, all the - bytes remaining are removed. - */ - void - consume(std::size_t n); -}; - -} // beast - -#include - -#endif diff --git a/src/beast/include/beast/core/detail/base64.hpp b/src/beast/include/beast/core/detail/base64.hpp deleted file mode 100644 index 31b426a61e5..00000000000 --- a/src/beast/include/beast/core/detail/base64.hpp +++ /dev/null @@ -1,247 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -/* - Portions from http://www.adp-gmbh.ch/cpp/common/base64.html - Copyright notice: - - base64.cpp and base64.h - - Copyright (C) 2004-2008 René Nyffenegger - - This source code is provided 'as-is', without any express or implied - warranty. In no event will the author be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this source code must not be misrepresented; you must not - claim that you wrote the original source code. If you use this source code - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original source code. - - 3. This notice may not be removed or altered from any source distribution. - - René Nyffenegger rene.nyffenegger@adp-gmbh.ch - -*/ - -#ifndef BEAST_DETAIL_BASE64_HPP -#define BEAST_DETAIL_BASE64_HPP - -#include -#include -#include - -namespace beast { -namespace detail { - -namespace base64 { - -inline -char const* -get_alphabet() -{ - static char constexpr tab[] = { - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" - }; - return &tab[0]; -} - -inline -signed char const* -get_inverse() -{ - static signed char constexpr tab[] = { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0-15 - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 16-31 - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, // 32-47 - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, // 48-63 - -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, // 64-79 - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, // 80-95 - -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, // 96-111 - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1, // 112-127 - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 128-143 - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 144-159 - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 160-175 - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 176-191 - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 192-207 - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 208-223 - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 224-239 - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 // 240-255 - }; - return &tab[0]; -} - - -/// Returns max chars needed to encode a base64 string -inline -std::size_t constexpr -encoded_size(std::size_t n) -{ - return 4 * ((n + 2) / 3); -} - -/// Returns max bytes needed to decode a base64 string -inline -std::size_t constexpr -decoded_size(std::size_t n) -{ - return n / 4 * 3; // requires n&3==0, smaller - //return 3 * n / 4; -} - -/** Encode a series of octets as a padded, base64 string. - - The resulting string will not be null terminated. - - @par Requires - - The memory pointed to by `out` points to valid memory - of at least `encoded_size(len)` bytes. - - @return The number of characters written to `out`. This - will exclude any null termination. -*/ -template -std::size_t -encode(void* dest, void const* src, std::size_t len) -{ - char* out = static_cast(dest); - char const* in = static_cast(src); - auto const tab = base64::get_alphabet(); - - for(auto n = len / 3; n--;) - { - *out++ = tab[ (in[0] & 0xfc) >> 2]; - *out++ = tab[((in[0] & 0x03) << 4) + ((in[1] & 0xf0) >> 4)]; - *out++ = tab[((in[2] & 0xc0) >> 6) + ((in[1] & 0x0f) << 2)]; - *out++ = tab[ in[2] & 0x3f]; - in += 3; - } - - switch(len % 3) - { - case 2: - *out++ = tab[ (in[0] & 0xfc) >> 2]; - *out++ = tab[((in[0] & 0x03) << 4) + ((in[1] & 0xf0) >> 4)]; - *out++ = tab[ (in[1] & 0x0f) << 2]; - *out++ = '='; - break; - - case 1: - *out++ = tab[ (in[0] & 0xfc) >> 2]; - *out++ = tab[((in[0] & 0x03) << 4)]; - *out++ = '='; - *out++ = '='; - break; - - case 0: - break; - } - - return out - static_cast(dest); -} - -/** Decode a padded base64 string into a series of octets. - - @par Requires - - The memory pointed to by `out` points to valid memory - of at least `decoded_size(len)` bytes. - - @return The number of octets written to `out`, and - the number of characters read from the input string, - expressed as a pair. -*/ -template -std::pair -decode(void* dest, char const* src, std::size_t len) -{ - char* out = static_cast(dest); - auto in = reinterpret_cast(src); - unsigned char c3[3], c4[4]; - int i = 0; - int j = 0; - - auto const inverse = base64::get_inverse(); - - while(len-- && *in != '=') - { - auto const v = inverse[*in]; - if(v == -1) - break; - ++in; - c4[i] = v; - if(++i == 4) - { - c3[0] = (c4[0] << 2) + ((c4[1] & 0x30) >> 4); - c3[1] = ((c4[1] & 0xf) << 4) + ((c4[2] & 0x3c) >> 2); - c3[2] = ((c4[2] & 0x3) << 6) + c4[3]; - - for(i = 0; i < 3; i++) - *out++ = c3[i]; - i = 0; - } - } - - if(i) - { - c3[0] = ( c4[0] << 2) + ((c4[1] & 0x30) >> 4); - c3[1] = ((c4[1] & 0xf) << 4) + ((c4[2] & 0x3c) >> 2); - c3[2] = ((c4[2] & 0x3) << 6) + c4[3]; - - for(j = 0; j < i - 1; j++) - *out++ = c3[j]; - } - - return {out - static_cast(dest), - in - reinterpret_cast(src)}; -} - -} // base64 - -template -std::string -base64_encode (std::uint8_t const* data, - std::size_t len) -{ - std::string dest; - dest.resize(base64::encoded_size(len)); - dest.resize(base64::encode(&dest[0], data, len)); - return dest; -} - -inline -std::string -base64_encode(std::string const& s) -{ - return base64_encode (reinterpret_cast < - std::uint8_t const*> (s.data()), s.size()); -} - -template -std::string -base64_decode(std::string const& data) -{ - std::string dest; - dest.resize(base64::decoded_size(data.size())); - auto const result = base64::decode( - &dest[0], data.data(), data.size()); - dest.resize(result.first); - return dest; -} - -} // detail -} // beast - -#endif diff --git a/src/beast/include/beast/core/detail/bind_handler.hpp b/src/beast/include/beast/core/detail/bind_handler.hpp deleted file mode 100644 index ad9f4e48c7d..00000000000 --- a/src/beast/include/beast/core/detail/bind_handler.hpp +++ /dev/null @@ -1,119 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_BIND_DETAIL_HANDLER_HPP -#define BEAST_BIND_DETAIL_HANDLER_HPP - -#include -#include -#include -#include -#include - -namespace beast { -namespace detail { - -/* Nullary handler that calls Handler with bound arguments. - - The bound handler provides the same io_service execution - guarantees as the original handler. -*/ -template -class bound_handler -{ -private: - using args_type = std::tuple< - typename std::decay::type...>; - - Handler h_; - args_type args_; - - template - static void invoke(Handler& h, Tuple& args, - index_sequence) - { - h(std::get(args)...); - } - -public: - using result_type = void; - - template - explicit - bound_handler( - DeducedHandler&& handler, Args&&... args) - : h_(std::forward(handler)) - , args_(std::forward(args)...) - { - } - - void - operator()() - { - invoke(h_, args_, - index_sequence_for()); - } - - void - operator()() const - { - invoke(h_, args_, - index_sequence_for()); - } - - friend - void* - asio_handler_allocate( - std::size_t size, bound_handler* h) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(h->h_)); - } - - friend - void - asio_handler_deallocate( - void* p, std::size_t size, bound_handler* h) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(h->h_)); - } - - friend - bool - asio_handler_is_continuation(bound_handler* h) - { - using boost::asio::asio_handler_is_continuation; - return asio_handler_is_continuation(std::addressof(h->h_)); - } - - template - friend - void - asio_handler_invoke(F&& f, bound_handler* h) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(h->h_)); - } -}; - -} // detail -} // beast - -#include - -namespace std { -template -void -bind(beast::detail::bound_handler< - Handler, Args...>, ...) = delete; -} // std - -#endif diff --git a/src/beast/include/beast/core/detail/buffers_ref.hpp b/src/beast/include/beast/core/detail/buffers_ref.hpp deleted file mode 100644 index 92fe9f53563..00000000000 --- a/src/beast/include/beast/core/detail/buffers_ref.hpp +++ /dev/null @@ -1,61 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_DETAIL_BUFFERS_REF_HPP -#define BEAST_DETAIL_BUFFERS_REF_HPP - -#include - -namespace beast { -namespace detail { - -// A very lightweight reference to a buffer sequence -template -class buffers_ref -{ - BufferSequence const& buffers_; - -public: - using value_type = - typename BufferSequence::value_type; - - using const_iterator = - typename BufferSequence::const_iterator; - - buffers_ref(buffers_ref const&) = default; - - explicit - buffers_ref(BufferSequence const& buffers) - : buffers_(buffers) - { - } - - const_iterator - begin() const - { - return buffers_.begin(); - } - - const_iterator - end() const - { - return buffers_.end(); - } -}; - -// Return a reference to a buffer sequence -template -buffers_ref -make_buffers_ref(BufferSequence const& buffers) -{ - return buffers_ref(buffers); -} - -} // detail -} // beast - -#endif diff --git a/src/beast/include/beast/core/detail/clamp.hpp b/src/beast/include/beast/core/detail/clamp.hpp deleted file mode 100644 index 21afeaaaffd..00000000000 --- a/src/beast/include/beast/core/detail/clamp.hpp +++ /dev/null @@ -1,40 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_CORE_DETAIL_CLAMP_HPP -#define BEAST_CORE_DETAIL_CLAMP_HPP - -#include -#include - -namespace beast { -namespace detail { - -template -static -std::size_t -clamp(UInt x) -{ - if(x >= (std::numeric_limits::max)()) - return (std::numeric_limits::max)(); - return static_cast(x); -} - -template -static -std::size_t -clamp(UInt x, std::size_t limit) -{ - if(x >= limit) - return limit; - return static_cast(x); -} - -} // detail -} // beast - -#endif diff --git a/src/beast/include/beast/core/detail/config.hpp b/src/beast/include/beast/core/detail/config.hpp deleted file mode 100644 index 461ca38bf80..00000000000 --- a/src/beast/include/beast/core/detail/config.hpp +++ /dev/null @@ -1,20 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_CORE_DETAIL_CONFIG_HPP -#define BEAST_CORE_DETAIL_CONFIG_HPP - -#include -#include - -#if BOOST_VERSION >= 106500 || ! defined(BOOST_GCC) || BOOST_GCC < 70000 -# define BEAST_FALLTHROUGH BOOST_FALLTHROUGH -#else -# define BEAST_FALLTHROUGH __attribute__((fallthrough)) -#endif - -#endif diff --git a/src/beast/include/beast/core/detail/cpu_info.hpp b/src/beast/include/beast/core/detail/cpu_info.hpp deleted file mode 100644 index 3a1e24cb38f..00000000000 --- a/src/beast/include/beast/core/detail/cpu_info.hpp +++ /dev/null @@ -1,95 +0,0 @@ -// -// Copyright (c) 2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_DETAIL_CPU_INFO_HPP -#define BEAST_DETAIL_CPU_INFO_HPP - -#include - -#ifndef BEAST_NO_INTRINSICS -# if defined(BOOST_MSVC) || ((defined(BOOST_GCC) || defined(BOOST_CLANG)) && defined(__SSE4_2__)) -# define BEAST_NO_INTRINSICS 0 -# else -# define BEAST_NO_INTRINSICS 1 -# endif -#endif - -#if ! BEAST_NO_INTRINSICS - -#ifdef BOOST_MSVC -#include // __cpuid -#else -#include // __get_cpuid -#endif - -namespace beast { -namespace detail { - -/* Portions from Boost, - Copyright Andrey Semashev 2007 - 2015. -*/ -template -void -cpuid( - std::uint32_t id, - std::uint32_t& eax, - std::uint32_t& ebx, - std::uint32_t& ecx, - std::uint32_t& edx) -{ -#ifdef BOOST_MSVC - int regs[4]; - __cpuid(regs, id); - eax = regs[0]; - ebx = regs[1]; - ecx = regs[2]; - edx = regs[3]; -#else - __get_cpuid(id, &eax, &ebx, &ecx, &edx); -#endif -} - -struct cpu_info -{ - bool sse42 = false; - - cpu_info(); -}; - -inline -cpu_info:: -cpu_info() -{ - constexpr std::uint32_t SSE42 = 1 << 20; - - std::uint32_t eax = 0; - std::uint32_t ebx = 0; - std::uint32_t ecx = 0; - std::uint32_t edx = 0; - - cpuid(0, eax, ebx, ecx, edx); - if(eax >= 1) - { - cpuid(1, eax, ebx, ecx, edx); - sse42 = (ecx & SSE42) != 0; - } -} - -template -cpu_info const& -get_cpu_info() -{ - static cpu_info const ci; - return ci; -} - -} // detail -} // beast - -#endif - -#endif diff --git a/src/beast/include/beast/core/detail/empty_base_optimization.hpp b/src/beast/include/beast/core/detail/empty_base_optimization.hpp deleted file mode 100644 index a0ca44460ab..00000000000 --- a/src/beast/include/beast/core/detail/empty_base_optimization.hpp +++ /dev/null @@ -1,94 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_DETAIL_EMPTY_BASE_OPTIMIZATION_HPP -#define BEAST_DETAIL_EMPTY_BASE_OPTIMIZATION_HPP - -#include -#include - -namespace beast { -namespace detail { - -template -struct empty_base_optimization_decide - : std::integral_constant ::value -#ifdef __clang__ - && !__is_final(T) -#endif - > -{ -}; - -template< - class T, - int UniqueID = 0, - bool ShouldDeriveFrom = - empty_base_optimization_decide::value -> -class empty_base_optimization : private T -{ -public: - empty_base_optimization() = default; - - empty_base_optimization(T const& t) - : T (t) - {} - - empty_base_optimization(T&& t) - : T (std::move (t)) - {} - - T& member() noexcept - { - return *this; - } - - T const& member() const noexcept - { - return *this; - } -}; - -//------------------------------------------------------------------------------ - -template< - class T, - int UniqueID -> -class empty_base_optimization -{ -public: - empty_base_optimization() = default; - - empty_base_optimization(T const& t) - : m_t (t) - {} - - empty_base_optimization(T&& t) - : m_t (std::move (t)) - {} - - T& member() noexcept - { - return m_t; - } - - T const& member() const noexcept - { - return m_t; - } - -private: - T m_t; -}; - -} // detail -} // beast - -#endif diff --git a/src/beast/include/beast/core/detail/in_place_init.hpp b/src/beast/include/beast/core/detail/in_place_init.hpp deleted file mode 100644 index 2a0ab615f91..00000000000 --- a/src/beast/include/beast/core/detail/in_place_init.hpp +++ /dev/null @@ -1,41 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_DETAIL_IN_PLACE_INIT_HPP -#define BEAST_DETAIL_IN_PLACE_INIT_HPP - -#include -#include - -// Provide boost::in_place_init_t and boost::in_place_init -// for Boost versions earlier than 1.63.0. - -#if BOOST_VERSION < 106300 - -namespace boost { - -namespace optional_ns { - -// a tag for in-place initialization of contained value -struct in_place_init_t -{ - struct init_tag{}; - explicit in_place_init_t(init_tag){} -}; -const in_place_init_t in_place_init ((in_place_init_t::init_tag())); - -} // namespace optional_ns - -using optional_ns::in_place_init_t; -using optional_ns::in_place_init; - -} - -#endif - -#endif - diff --git a/src/beast/include/beast/core/detail/integer_sequence.hpp b/src/beast/include/beast/core/detail/integer_sequence.hpp deleted file mode 100644 index 6d0cc8a7f38..00000000000 --- a/src/beast/include/beast/core/detail/integer_sequence.hpp +++ /dev/null @@ -1,139 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_DETAIL_INTEGER_SEQUENCE_HPP -#define BEAST_DETAIL_INTEGER_SEQUENCE_HPP - -#include -#include -#include -#include - -namespace beast { -namespace detail { - -template -struct integer_sequence -{ - using value_type = T; - BOOST_STATIC_ASSERT(std::is_integral::value); - - static std::size_t constexpr static_size = sizeof...(Ints); - - static std::size_t constexpr size() - { - return sizeof...(Ints); - } -}; - -template -using index_sequence = integer_sequence; - -// This workaround is needed for broken sizeof... -template -struct sizeof_workaround -{ - static std::size_t constexpr size = sizeof... (Args); -}; - -#ifdef BOOST_MSVC - -// This implementation compiles on real MSVC and clang but not gcc - -template -struct make_integer_sequence_unchecked; - -template -struct make_integer_sequence_unchecked< - T, N, integer_sequence> -{ - using type = typename make_integer_sequence_unchecked< - T, N-1, integer_sequence>::type; -}; - -template -struct make_integer_sequence_unchecked< - T, 0, integer_sequence> -{ - using type = integer_sequence; -}; - -template -struct make_integer_sequence_checked -{ - BOOST_STATIC_ASSERT(std::is_integral::value); - BOOST_STATIC_ASSERT(N >= 0); - - using type = typename make_integer_sequence_unchecked< - T, N, integer_sequence>::type; -}; - -template -using make_integer_sequence = - typename make_integer_sequence_checked::type; - -template -using make_index_sequence = make_integer_sequence; - -template -using index_sequence_for = - make_index_sequence::size>; - -#else - -// This implementation compiles on gcc but not MSVC - -template -struct index_tuple -{ - using next = index_tuple; - -}; - -template -struct build_index_tuple -{ - using type = typename build_index_tuple::type::next; -}; - -template<> -struct build_index_tuple<0> -{ - using type = index_tuple<>; -}; - -template::type -> -struct integer_sequence_helper; - -template -struct integer_sequence_helper> -{ - BOOST_STATIC_ASSERT(std::is_integral::value); - BOOST_STATIC_ASSERT(N >= 0); - - using type = integer_sequence (Ints)...>; -}; - -template -using make_integer_sequence = - typename integer_sequence_helper::type; - -template -using make_index_sequence = make_integer_sequence; - -template -using index_sequence_for = - make_index_sequence::size>; - -#endif - -} // detail -} // beast - -#endif diff --git a/src/beast/include/beast/core/detail/ostream.hpp b/src/beast/include/beast/core/detail/ostream.hpp deleted file mode 100644 index c02211246d4..00000000000 --- a/src/beast/include/beast/core/detail/ostream.hpp +++ /dev/null @@ -1,318 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_DETAIL_OSTREAM_HPP -#define BEAST_DETAIL_OSTREAM_HPP - -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace detail { - -template -class buffers_helper -{ - Buffers b_; - -public: - explicit - buffers_helper(Buffers const& b) - : b_(b) - { - } - - template - friend - std::ostream& - operator<<(std::ostream& os, - buffers_helper const& v); -}; - -template -std::ostream& -operator<<(std::ostream& os, - buffers_helper const& v) -{ - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - for(boost::asio::const_buffer b : v.b_) - os.write(buffer_cast(b), - buffer_size(b)); - return os; -} - -//------------------------------------------------------------------------------ - -struct basic_streambuf_movable_helper : - std::basic_streambuf> -{ - basic_streambuf_movable_helper( - basic_streambuf_movable_helper&&) = default; -}; - -using basic_streambuf_movable = - std::is_move_constructible; - -//------------------------------------------------------------------------------ - -template -class ostream_buffer; - -template -class ostream_buffer - - : public std::basic_streambuf -{ - using int_type = typename - std::basic_streambuf::int_type; - - using traits_type = typename - std::basic_streambuf::traits_type; - - static std::size_t constexpr max_size = 512; - - DynamicBuffer& buf_; - -public: - ostream_buffer(ostream_buffer&&) = default; - ostream_buffer(ostream_buffer const&) = delete; - - ~ostream_buffer() noexcept - { - sync(); - } - - explicit - ostream_buffer(DynamicBuffer& buf) - : buf_(buf) - { - prepare(); - } - - int_type - overflow(int_type ch) override - { - if(! Traits::eq_int_type(ch, Traits::eof())) - { - Traits::assign(*this->pptr(), - static_cast(ch)); - flush(1); - prepare(); - return ch; - } - flush(); - return traits_type::eof(); - } - - int - sync() override - { - flush(); - prepare(); - return 0; - } - -private: - void - prepare() - { - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - auto mbs = buf_.prepare( - read_size_or_throw(buf_, max_size)); - auto const mb = *mbs.begin(); - auto const p = buffer_cast(mb); - this->setp(p, - p + buffer_size(mb) / sizeof(CharT) - 1); - } - - void - flush(int extra = 0) - { - buf_.commit( - (this->pptr() - this->pbase() + extra) * - sizeof(CharT)); - } -}; - -// This nonsense is all to work around a glitch in libstdc++ -// where std::basic_streambuf copy constructor is private: -// https://github.com/gcc-mirror/gcc/blob/gcc-4_8-branch/libstdc%2B%2B-v3/include/std/streambuf#L799 - -template -class ostream_buffer - - : public std::basic_streambuf -{ - using int_type = typename - std::basic_streambuf::int_type; - - using traits_type = typename - std::basic_streambuf::traits_type; - - static std::size_t constexpr max_size = 512; - - DynamicBuffer& buf_; - -public: - ostream_buffer(ostream_buffer&&) = delete; - ostream_buffer(ostream_buffer const&) = delete; - - ~ostream_buffer() noexcept - { - sync(); - } - - explicit - ostream_buffer(DynamicBuffer& buf) - : buf_(buf) - { - prepare(); - } - - int_type - overflow(int_type ch) override - { - if(! Traits::eq_int_type(ch, Traits::eof())) - { - Traits::assign(*this->pptr(), - static_cast(ch)); - flush(1); - prepare(); - return ch; - } - flush(); - return traits_type::eof(); - } - - int - sync() override - { - flush(); - prepare(); - return 0; - } - -private: - void - prepare() - { - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - auto mbs = buf_.prepare( - read_size_or_throw(buf_, max_size)); - auto const mb = *mbs.begin(); - auto const p = buffer_cast(mb); - this->setp(p, - p + buffer_size(mb) / sizeof(CharT) - 1); - } - - void - flush(int extra = 0) - { - buf_.commit( - (this->pptr() - this->pbase() + extra) * - sizeof(CharT)); - } -}; - -//------------------------------------------------------------------------------ - -template -class ostream_helper; - -template -class ostream_helper< - DynamicBuffer, CharT, Traits, true> - : public std::basic_ostream -{ - ostream_buffer< - DynamicBuffer, CharT, Traits, true> osb_; - -public: - explicit - ostream_helper(DynamicBuffer& buf); - - ostream_helper(ostream_helper&& other); -}; - -template -ostream_helper:: -ostream_helper(DynamicBuffer& buf) - : std::basic_ostream( - &this->osb_) - , osb_(buf) -{ -} - -template -ostream_helper:: -ostream_helper( - ostream_helper&& other) - : std::basic_ostream(&osb_) - , osb_(std::move(other.osb_)) -{ -} - -// This work-around is for libstdc++ versions that -// don't have a movable std::basic_streambuf - -template -class ostream_helper_base -{ -protected: - std::unique_ptr member; - - ostream_helper_base( - ostream_helper_base&&) = default; - - explicit - ostream_helper_base(T* t) - : member(t) - { - } -}; - -template -class ostream_helper< - DynamicBuffer, CharT, Traits, false> - : private ostream_helper_base> - , public std::basic_ostream -{ -public: - explicit - ostream_helper(DynamicBuffer& buf) - : ostream_helper_base>( - new ostream_buffer(buf)) - , std::basic_ostream(this->member.get()) - { - } - - ostream_helper(ostream_helper&& other) - : ostream_helper_base>( - std::move(other)) - , std::basic_ostream(this->member.get()) - { - } -}; - -} // detail -} // beast - -#endif diff --git a/src/beast/include/beast/core/detail/sha1.hpp b/src/beast/include/beast/core/detail/sha1.hpp deleted file mode 100644 index 7e8e6383b1a..00000000000 --- a/src/beast/include/beast/core/detail/sha1.hpp +++ /dev/null @@ -1,309 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_DETAIL_SHA1_HPP -#define BEAST_DETAIL_SHA1_HPP - -#include -#include -#include - -// Based on https://github.com/vog/sha1 -/* - Original authors: - Steve Reid (Original C Code) - Bruce Guenter (Small changes to fit into bglibs) - Volker Grabsch (Translation to simpler C++ Code) - Eugene Hopkinson (Safety improvements) - Vincent Falco (beast adaptation) -*/ - -namespace beast { -namespace detail { - -namespace sha1 { - -static std::size_t constexpr BLOCK_INTS = 16; -static std::size_t constexpr BLOCK_BYTES = 64; -static std::size_t constexpr DIGEST_BYTES = 20; - -inline -std::uint32_t -rol(std::uint32_t value, std::size_t bits) -{ - return (value << bits) | (value >> (32 - bits)); -} - -inline -std::uint32_t -blk(std::uint32_t block[BLOCK_INTS], std::size_t i) -{ - return rol( - block[(i+13)&15] ^ block[(i+8)&15] ^ - block[(i+2)&15] ^ block[i], 1); -} - -inline -void -R0(std::uint32_t block[BLOCK_INTS], std::uint32_t v, - std::uint32_t &w, std::uint32_t x, std::uint32_t y, - std::uint32_t &z, std::size_t i) -{ - z += ((w&(x^y))^y) + block[i] + 0x5a827999 + rol(v, 5); - w = rol(w, 30); -} - - -inline -void -R1(std::uint32_t block[BLOCK_INTS], std::uint32_t v, - std::uint32_t &w, std::uint32_t x, std::uint32_t y, - std::uint32_t &z, std::size_t i) -{ - block[i] = blk(block, i); - z += ((w&(x^y))^y) + block[i] + 0x5a827999 + rol(v, 5); - w = rol(w, 30); -} - -inline -void -R2(std::uint32_t block[BLOCK_INTS], std::uint32_t v, - std::uint32_t &w, std::uint32_t x, std::uint32_t y, - std::uint32_t &z, std::size_t i) -{ - block[i] = blk(block, i); - z += (w^x^y) + block[i] + 0x6ed9eba1 + rol(v, 5); - w = rol(w, 30); -} - -inline -void -R3(std::uint32_t block[BLOCK_INTS], std::uint32_t v, - std::uint32_t &w, std::uint32_t x, std::uint32_t y, - std::uint32_t &z, std::size_t i) -{ - block[i] = blk(block, i); - z += (((w|x)&y)|(w&x)) + block[i] + 0x8f1bbcdc + rol(v, 5); - w = rol(w, 30); -} - -inline -void -R4(std::uint32_t block[BLOCK_INTS], std::uint32_t v, - std::uint32_t &w, std::uint32_t x, std::uint32_t y, - std::uint32_t &z, std::size_t i) -{ - block[i] = blk(block, i); - z += (w^x^y) + block[i] + 0xca62c1d6 + rol(v, 5); - w = rol(w, 30); -} - -inline -void -make_block(std::uint8_t const* p, - std::uint32_t block[BLOCK_INTS]) -{ - for(std::size_t i = 0; i < BLOCK_INTS; i++) - block[i] = - (static_cast(p[4*i+3])) | - (static_cast(p[4*i+2]))<< 8 | - (static_cast(p[4*i+1]))<<16 | - (static_cast(p[4*i+0]))<<24; -} - -template -void -transform( - std::uint32_t digest[], std::uint32_t block[BLOCK_INTS]) -{ - std::uint32_t a = digest[0]; - std::uint32_t b = digest[1]; - std::uint32_t c = digest[2]; - std::uint32_t d = digest[3]; - std::uint32_t e = digest[4]; - - R0(block, a, b, c, d, e, 0); - R0(block, e, a, b, c, d, 1); - R0(block, d, e, a, b, c, 2); - R0(block, c, d, e, a, b, 3); - R0(block, b, c, d, e, a, 4); - R0(block, a, b, c, d, e, 5); - R0(block, e, a, b, c, d, 6); - R0(block, d, e, a, b, c, 7); - R0(block, c, d, e, a, b, 8); - R0(block, b, c, d, e, a, 9); - R0(block, a, b, c, d, e, 10); - R0(block, e, a, b, c, d, 11); - R0(block, d, e, a, b, c, 12); - R0(block, c, d, e, a, b, 13); - R0(block, b, c, d, e, a, 14); - R0(block, a, b, c, d, e, 15); - R1(block, e, a, b, c, d, 0); - R1(block, d, e, a, b, c, 1); - R1(block, c, d, e, a, b, 2); - R1(block, b, c, d, e, a, 3); - R2(block, a, b, c, d, e, 4); - R2(block, e, a, b, c, d, 5); - R2(block, d, e, a, b, c, 6); - R2(block, c, d, e, a, b, 7); - R2(block, b, c, d, e, a, 8); - R2(block, a, b, c, d, e, 9); - R2(block, e, a, b, c, d, 10); - R2(block, d, e, a, b, c, 11); - R2(block, c, d, e, a, b, 12); - R2(block, b, c, d, e, a, 13); - R2(block, a, b, c, d, e, 14); - R2(block, e, a, b, c, d, 15); - R2(block, d, e, a, b, c, 0); - R2(block, c, d, e, a, b, 1); - R2(block, b, c, d, e, a, 2); - R2(block, a, b, c, d, e, 3); - R2(block, e, a, b, c, d, 4); - R2(block, d, e, a, b, c, 5); - R2(block, c, d, e, a, b, 6); - R2(block, b, c, d, e, a, 7); - R3(block, a, b, c, d, e, 8); - R3(block, e, a, b, c, d, 9); - R3(block, d, e, a, b, c, 10); - R3(block, c, d, e, a, b, 11); - R3(block, b, c, d, e, a, 12); - R3(block, a, b, c, d, e, 13); - R3(block, e, a, b, c, d, 14); - R3(block, d, e, a, b, c, 15); - R3(block, c, d, e, a, b, 0); - R3(block, b, c, d, e, a, 1); - R3(block, a, b, c, d, e, 2); - R3(block, e, a, b, c, d, 3); - R3(block, d, e, a, b, c, 4); - R3(block, c, d, e, a, b, 5); - R3(block, b, c, d, e, a, 6); - R3(block, a, b, c, d, e, 7); - R3(block, e, a, b, c, d, 8); - R3(block, d, e, a, b, c, 9); - R3(block, c, d, e, a, b, 10); - R3(block, b, c, d, e, a, 11); - R4(block, a, b, c, d, e, 12); - R4(block, e, a, b, c, d, 13); - R4(block, d, e, a, b, c, 14); - R4(block, c, d, e, a, b, 15); - R4(block, b, c, d, e, a, 0); - R4(block, a, b, c, d, e, 1); - R4(block, e, a, b, c, d, 2); - R4(block, d, e, a, b, c, 3); - R4(block, c, d, e, a, b, 4); - R4(block, b, c, d, e, a, 5); - R4(block, a, b, c, d, e, 6); - R4(block, e, a, b, c, d, 7); - R4(block, d, e, a, b, c, 8); - R4(block, c, d, e, a, b, 9); - R4(block, b, c, d, e, a, 10); - R4(block, a, b, c, d, e, 11); - R4(block, e, a, b, c, d, 12); - R4(block, d, e, a, b, c, 13); - R4(block, c, d, e, a, b, 14); - R4(block, b, c, d, e, a, 15); - - digest[0] += a; - digest[1] += b; - digest[2] += c; - digest[3] += d; - digest[4] += e; -} - -} // sha1 - -struct sha1_context -{ - static unsigned int constexpr block_size = sha1::BLOCK_BYTES; - static unsigned int constexpr digest_size = 20; - - std::size_t buflen; - std::size_t blocks; - std::uint32_t digest[5]; - std::uint8_t buf[block_size]; -}; - -template -void -init(sha1_context& ctx) noexcept -{ - ctx.buflen = 0; - ctx.blocks = 0; - ctx.digest[0] = 0x67452301; - ctx.digest[1] = 0xefcdab89; - ctx.digest[2] = 0x98badcfe; - ctx.digest[3] = 0x10325476; - ctx.digest[4] = 0xc3d2e1f0; -} - -template -void -update(sha1_context& ctx, - void const* message, std::size_t size) noexcept -{ - auto p = reinterpret_cast< - std::uint8_t const*>(message); - for(;;) - { - auto const n = (std::min)( - size, sizeof(ctx.buf) - ctx.buflen); - std::memcpy(ctx.buf + ctx.buflen, p, n); - ctx.buflen += n; - if(ctx.buflen != 64) - return; - p += n; - size -= n; - ctx.buflen = 0; - std::uint32_t block[sha1::BLOCK_INTS]; - sha1::make_block(ctx.buf, block); - sha1::transform(ctx.digest, block); - ++ctx.blocks; - } -} - -template -void -finish(sha1_context& ctx, void* digest) noexcept -{ - using sha1::BLOCK_INTS; - using sha1::BLOCK_BYTES; - - std::uint64_t total_bits = - (ctx.blocks*64 + ctx.buflen) * 8; - // pad - ctx.buf[ctx.buflen++] = 0x80; - auto const buflen = ctx.buflen; - while(ctx.buflen < 64) - ctx.buf[ctx.buflen++] = 0x00; - std::uint32_t block[BLOCK_INTS]; - sha1::make_block(ctx.buf, block); - if(buflen > BLOCK_BYTES - 8) - { - sha1::transform(ctx.digest, block); - for(size_t i = 0; i < BLOCK_INTS - 2; i++) - block[i] = 0; - } - - /* Append total_bits, split this uint64_t into two uint32_t */ - block[BLOCK_INTS - 1] = total_bits & 0xffffffff; - block[BLOCK_INTS - 2] = (total_bits >> 32); - sha1::transform(ctx.digest, block); - for(std::size_t i = 0; i < sha1::DIGEST_BYTES/4; i++) - { - std::uint8_t* d = - reinterpret_cast(digest) + 4 * i; - d[3] = ctx.digest[i] & 0xff; - d[2] = (ctx.digest[i] >> 8) & 0xff; - d[1] = (ctx.digest[i] >> 16) & 0xff; - d[0] = (ctx.digest[i] >> 24) & 0xff; - } -} - -} // detail -} // beast - -#endif diff --git a/src/beast/include/beast/core/detail/static_ostream.hpp b/src/beast/include/beast/core/detail/static_ostream.hpp deleted file mode 100644 index 99f4282d916..00000000000 --- a/src/beast/include/beast/core/detail/static_ostream.hpp +++ /dev/null @@ -1,138 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_DETAIL_STATIC_OSTREAM_HPP -#define BEAST_DETAIL_STATIC_OSTREAM_HPP - -#include -#include -#include - -namespace beast { -namespace detail { - -// http://www.mr-edd.co.uk/blog/beginners_guide_streambuf - -class static_ostream_buffer - : public std::basic_streambuf -{ - using CharT = char; - using Traits = std::char_traits; - using int_type = typename - std::basic_streambuf::int_type; - using traits_type = typename - std::basic_streambuf::traits_type; - - char* data_; - std::size_t size_; - std::size_t len_ = 0; - std::string s_; - -public: - static_ostream_buffer(static_ostream_buffer&&) = delete; - static_ostream_buffer(static_ostream_buffer const&) = delete; - - static_ostream_buffer(char* data, std::size_t size) - : data_(data) - , size_(size) - { - this->setp(data_, data_ + size - 1); - } - - ~static_ostream_buffer() noexcept - { - } - - string_view - str() const - { - if(! s_.empty()) - return {s_.data(), len_}; - return {data_, len_}; - } - - int_type - overflow(int_type ch) override - { - if(! Traits::eq_int_type(ch, Traits::eof())) - { - Traits::assign(*this->pptr(), - static_cast(ch)); - flush(1); - prepare(); - return ch; - } - flush(); - return traits_type::eof(); - } - - int - sync() override - { - flush(); - prepare(); - return 0; - } - -private: - void - prepare() - { - static auto const growth_factor = 1.5; - - if(len_ < size_ - 1) - { - this->setp( - data_ + len_, data_ + size_ - 2); - return; - } - if(s_.empty()) - { - s_.resize(static_cast( - growth_factor * len_)); - Traits::copy(&s_[0], data_, len_); - } - else - { - s_.resize(static_cast( - growth_factor * len_)); - } - this->setp(&s_[len_], &s_[len_] + - s_.size() - len_ - 1); - } - - void - flush(int extra = 0) - { - len_ += static_cast( - this->pptr() - this->pbase() + extra); - } -}; - -class static_ostream : public std::basic_ostream -{ - static_ostream_buffer osb_; - -public: - static_ostream(char* data, std::size_t size) - : std::basic_ostream(&this->osb_) - , osb_(data, size) - { - imbue(std::locale::classic()); - } - - string_view - str() const - { - return osb_.str(); - } -}; - -} // detail -} // beast - -#endif diff --git a/src/beast/include/beast/core/detail/static_string.hpp b/src/beast/include/beast/core/detail/static_string.hpp deleted file mode 100644 index 7ded7fff0fb..00000000000 --- a/src/beast/include/beast/core/detail/static_string.hpp +++ /dev/null @@ -1,131 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_DETAIL_STATIC_STRING_HPP -#define BEAST_DETAIL_STATIC_STRING_HPP - -#include -#include -#include -#include - -namespace beast { -namespace detail { - -// Because k-ballo said so -template -using is_input_iterator = - std::integral_constant::value>; - -template -int -lexicographical_compare( - CharT const* s1, std::size_t n1, - CharT const* s2, std::size_t n2) -{ - if(n1 < n2) - return Traits::compare( - s1, s2, n1) <= 0 ? -1 : 1; - if(n1 > n2) - return Traits::compare( - s1, s2, n2) >= 0 ? 1 : -1; - return Traits::compare(s1, s2, n1); -} - -template -inline -int -lexicographical_compare( - basic_string_view s1, - CharT const* s2, std::size_t n2) -{ - return lexicographical_compare( - s1.data(), s1.size(), s2, n2); -} - -template -inline -int -lexicographical_compare( - basic_string_view s1, - basic_string_view s2) -{ - return lexicographical_compare( - s1.data(), s1.size(), s2.data(), s2.size()); -} - -// Maximum number of characters in the decimal -// representation of a binary number. This includes -// the potential minus sign. -// -inline -std::size_t constexpr -max_digits(std::size_t bytes) -{ - return static_cast( - bytes * 2.41) + 1 + 1; -} - -template -CharT* -raw_to_string( - CharT* buf, Integer x, std::true_type) -{ - if(x == 0) - { - Traits::assign(*--buf, '0'); - return buf; - } - if(x < 0) - { - x = -x; - for(;x > 0; x /= 10) - Traits::assign(*--buf , - "0123456789"[x % 10]); - Traits::assign(*--buf, '-'); - return buf; - } - for(;x > 0; x /= 10) - Traits::assign(*--buf , - "0123456789"[x % 10]); - return buf; -} - -template -CharT* -raw_to_string( - CharT* buf, Integer x, std::false_type) -{ - if(x == 0) - { - *--buf = '0'; - return buf; - } - for(;x > 0; x /= 10) - Traits::assign(*--buf , - "0123456789"[x % 10]); - return buf; -} - -template< - class CharT, - class Integer, - class Traits = std::char_traits> -CharT* -raw_to_string(CharT* last, std::size_t size, Integer i) -{ - boost::ignore_unused(size); - BOOST_ASSERT(size >= max_digits(sizeof(Integer))); - return raw_to_string( - last, i, std::is_signed{}); -} - -} // detail -} // beast - -#endif diff --git a/src/beast/include/beast/core/detail/type_traits.hpp b/src/beast/include/beast/core/detail/type_traits.hpp deleted file mode 100644 index e375b976d8e..00000000000 --- a/src/beast/include/beast/core/detail/type_traits.hpp +++ /dev/null @@ -1,264 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_DETAIL_TYPE_TRAITS_HPP -#define BEAST_DETAIL_TYPE_TRAITS_HPP - -#include -#include -#include -#include -#include -#include -#include - -// A few workarounds to keep things working - -namespace boost { -namespace asio { - -// for has_get_io_service -class io_service; - -// for is_dynamic_buffer -template -class basic_streambuf; - -namespace detail { - -// for is_buffer_sequence -template -class consuming_buffers; - -} // detail - -} // asio -} // boost - -//------------------------------------------------------------------------------ - -namespace beast { -namespace detail { - -// -// utilities -// - -template -struct make_void -{ - using type = void; -}; - -template -using void_t = typename make_void::type; - -template -inline -void -accept_rv(T){} - -template -std::size_t constexpr -max_sizeof() -{ - return sizeof(U); -} - -template -std::size_t constexpr -max_sizeof() -{ - return - max_sizeof() > max_sizeof() ? - max_sizeof() : max_sizeof(); -} - -template -struct repeat_tuple_impl -{ - using type = typename repeat_tuple_impl< - N - 1, T, T, Tn...>::type; -}; - -template -struct repeat_tuple_impl<0, T, Tn...> -{ - using type = std::tuple; -}; - -template -struct repeat_tuple -{ - using type = - typename repeat_tuple_impl::type; -}; - -template -struct repeat_tuple<0, T> -{ - using type = std::tuple<>; -}; - -template -auto -is_invocable_test(C&& c, int, A&& ...a) - -> decltype(std::is_convertible< - decltype(c(a...)), R>::value || - std::is_same::value, - std::true_type()); - -template -std::false_type -is_invocable_test(C&& c, long, A&& ...a); - -/** Metafunction returns `true` if F callable as R(A...) - - Example: - - @code - is_invocable - @endcode -*/ -/** @{ */ -template -struct is_invocable : std::false_type -{ -}; - -template -struct is_invocable - : decltype(is_invocable_test( - std::declval(), 1, std::declval()...)) -{ -}; -/** @} */ - -// for span -template -struct is_contiguous_container: std::false_type {}; - -template -struct is_contiguous_container() = std::declval().size(), - std::declval() = std::declval().data(), - (void)0), - typename std::enable_if< - std::is_same< - typename std::remove_cv::type, - typename std::remove_cv< - typename std::remove_pointer< - decltype(std::declval().data()) - >::type - >::type - >::value - >::type>>: std::true_type -{}; - -//------------------------------------------------------------------------------ - -// -// buffer concepts -// - -// Types that meet the requirements, -// for use with std::declval only. -template -struct BufferSequence -{ - using value_type = BufferType; - using const_iterator = BufferType const*; - ~BufferSequence(); - BufferSequence(BufferSequence const&) = default; - const_iterator begin() const noexcept; - const_iterator end() const noexcept; -}; -using ConstBufferSequence = - BufferSequence; -using MutableBufferSequence = - BufferSequence; - -template -struct is_buffer_sequence : std::false_type {}; - -template -struct is_buffer_sequence(), - std::declval() = - std::declval().begin(), - std::declval() = - std::declval().end(), - (void)0)>> : std::integral_constant::value && -#if 0 - std::is_base_of::iterator_category>::value -#else - // workaround: - // boost::asio::detail::consuming_buffers::const_iterator - // is not bidirectional - std::is_base_of::iterator_category>::value -#endif - > -{ -}; - -#if 0 -// workaround: -// boost::asio::detail::consuming_buffers::const_iterator -// is not bidirectional -template -struct is_buffer_sequence< - boost::asio::detail::consuming_buffers> - : std::true_type -{ -}; -#endif - -template -struct is_all_const_buffer_sequence - : std::integral_constant::value && - is_all_const_buffer_sequence::value> -{ -}; - -template -struct is_all_const_buffer_sequence - : is_buffer_sequence -{ -}; - -template -struct common_buffers_type -{ - using type = typename std::conditional< - std::is_convertible, - typename repeat_tuple::type>::value, - boost::asio::mutable_buffer, - boost::asio::const_buffer>::type; -}; - -// Types that meet the requirements, -// for use with std::declval only. -struct StreamHandler -{ - StreamHandler(StreamHandler const&) = default; - void operator()(error_code ec, std::size_t); -}; -using ReadHandler = StreamHandler; -using WriteHandler = StreamHandler; - -} // detail -} // beast - -#endif diff --git a/src/beast/include/beast/core/drain_buffer.hpp b/src/beast/include/beast/core/drain_buffer.hpp deleted file mode 100644 index 15f89a694f5..00000000000 --- a/src/beast/include/beast/core/drain_buffer.hpp +++ /dev/null @@ -1,122 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_DRAIN_BUFFER_HPP -#define BEAST_DRAIN_BUFFER_HPP - -#include -#include -#include - -namespace beast { - -/** A @b DynamicBuffer which does not retain its input sequence. - - This object implements a dynamic buffer with a fixed size - output area, not dynamically allocated, and whose input - sequence is always length zero. Bytes committed from the - output area to the input area are always discarded. This - is useful for calling interfaces that require a dynamic - buffer for storage, but where the caller does not want - to retain the data. -*/ -class drain_buffer -{ - char buf_[512]; - std::size_t n_ = 0; - -public: - /// The type used to represent the input sequence as a list of buffers. - using const_buffers_type = boost::asio::null_buffers; - - /// The type used to represent the output sequence as a list of buffers. - using mutable_buffers_type = boost::asio::mutable_buffers_1; - - /// Constructor - drain_buffer() = default; - - /// Copy constructor - drain_buffer(drain_buffer const&) - { - // Previously returned ranges are invalidated - } - - /// Copy assignment - drain_buffer& - operator=(drain_buffer const&) - { - n_ = 0; - return *this; - } - - /// Return the size of the input sequence. - std::size_t - size() const - { - return 0; - } - - /// Return the maximum sum of the input and output sequence sizes. - std::size_t - max_size() const - { - return sizeof(buf_); - } - - /// Return the maximum sum of input and output sizes that can be held without an allocation. - std::size_t - capacity() const - { - return max_size(); - } - - /** Get a list of buffers that represent the input sequence. - - @note These buffers remain valid across subsequent calls to `prepare`. - */ - const_buffers_type - data() const - { - return {}; - } - - /** Get a list of buffers that represent the output sequence, with the given size. - - @throws std::length_error if the size would exceed the buffer limit - */ - mutable_buffers_type - prepare(std::size_t n) - { - if(n > sizeof(buf_)) - BOOST_THROW_EXCEPTION(std::length_error{ - "buffer overflow"}); - n_ = n; - return {buf_, n_}; - } - - /** Move bytes from the output sequence to the input sequence. - - This call always discards the output sequence. - The size of the input sequence will remain at zero. - */ - void - commit(std::size_t) - { - } - - /** Remove bytes from the input sequence. - - This call has no effect. - */ - void - consume(std::size_t) const - { - } -}; -} // beast - -#endif diff --git a/src/beast/include/beast/core/error.hpp b/src/beast/include/beast/core/error.hpp deleted file mode 100644 index f98f6d7af65..00000000000 --- a/src/beast/include/beast/core/error.hpp +++ /dev/null @@ -1,53 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_ERROR_HPP -#define BEAST_ERROR_HPP - -#include -#include -#include - -namespace beast { - -/// The type of error code used by the library -using error_code = boost::system::error_code; - -/// The type of system error thrown by the library -using system_error = boost::system::system_error; - -/// The type of error category used by the library -using error_category = boost::system::error_category; - -/// A function to return the generic error category used by the library -#if BEAST_DOXYGEN -error_category const& -generic_category(); -#else -using boost::system::generic_category; -#endif - -/// A function to return the system error category used by the library -#if BEAST_DOXYGEN -error_category const& -system_category(); -#else -using boost::system::system_category; -#endif - -/// The type of error condition used by the library -using error_condition = boost::system::error_condition; - -/// The set of constants used for cross-platform error codes -#if BEAST_DOXYGEN -enum errc{}; -#else -namespace errc = boost::system::errc; -#endif -} // beast - -#endif diff --git a/src/beast/include/beast/core/file.hpp b/src/beast/include/beast/core/file.hpp deleted file mode 100644 index 8b3eecc874a..00000000000 --- a/src/beast/include/beast/core/file.hpp +++ /dev/null @@ -1,41 +0,0 @@ -// -// Copyright (c) 2015-2016 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_CORE_FILE_HPP -#define BEAST_CORE_FILE_HPP - -#include -#include -#include -#include -#include -#include - -namespace beast { - -/** An implementation of File. - - This alias is set to the best available implementation - of @b File given the platform and build settings. -*/ -#if BEAST_DOXYGEN -struct file : file_stdio -{ -}; -#else -#if BEAST_USE_WIN32_FILE -using file = file_win32; -#elif BEAST_USE_POSIX_FILE -using file = file_posix; -#else -using file = file_stdio; -#endif -#endif - -} // beast - -#endif diff --git a/src/beast/include/beast/core/file_base.hpp b/src/beast/include/beast/core/file_base.hpp deleted file mode 100644 index d39ebb520fa..00000000000 --- a/src/beast/include/beast/core/file_base.hpp +++ /dev/null @@ -1,88 +0,0 @@ -// -// Copyright (c) 2015-2016 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_CORE_FILE_BASE_HPP -#define BEAST_CORE_FILE_BASE_HPP - -#include -#include - -namespace beast { - -/// The type of file path used by the library -using file_path = string_view; - -/** File open modes - - These modes are used when opening files using - instances of the @b File concept. - - @see file_stdio -*/ -enum class file_mode -{ - /// Random reading - read, - - /// Sequential reading - scan, - - /** Random writing to a new or truncated file - - @li If the file does not exist, it is created. - - @li If the file exists, it is truncated to - zero size upon opening. - */ - write, - - /** Random writing to new file only - - If the file exists, an error is generated. - */ - write_new, - - /** Random writing to existing file - - If the file does not exist, an error is generated. - */ - write_existing, - - /** Appending to a new or truncated file - - The current file position shall be set to the end of - the file prior to each write. - - @li If the file does not exist, it is created. - - @li If the file exists, it is truncated to - zero size upon opening. - */ - append, - - /** Appending to a new file only - - The current file position shall be set to the end of - the file prior to each write. - - If the file exists, an error is generated. - */ - append_new, - - /** Appending to an existing file - - The current file position shall be set to the end of - the file prior to each write. - - If the file does not exist, an error is generated. - */ - append_existing -}; - -} // beast - -#endif diff --git a/src/beast/include/beast/core/file_posix.hpp b/src/beast/include/beast/core/file_posix.hpp deleted file mode 100644 index 7e675f24024..00000000000 --- a/src/beast/include/beast/core/file_posix.hpp +++ /dev/null @@ -1,171 +0,0 @@ -// -// Copyright (c) 2015-2016 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_CORE_FILE_POSIX_HPP -#define BEAST_CORE_FILE_POSIX_HPP - -#include - -#if ! defined(BEAST_NO_POSIX_FILE) -# if ! defined(__APPLE__) && ! defined(__linux__) -# define BEAST_NO_POSIX_FILE -# endif -#endif - -#if ! defined(BEAST_USE_POSIX_FILE) -# if ! defined(BEAST_NO_POSIX_FILE) -# define BEAST_USE_POSIX_FILE 1 -# else -# define BEAST_USE_POSIX_FILE 0 -# endif -#endif - -#if BEAST_USE_POSIX_FILE - -#include -#include -#include - -namespace beast { - -/** An implementation of File for POSIX systems. - - This class implements a @b File using POSIX interfaces. -*/ -class file_posix -{ - int fd_ = -1; - -public: - /** The type of the underlying file handle. - - This is platform-specific. - */ - using native_handle_type = int; - - /** Destructor - - If the file is open it is first closed. - */ - ~file_posix(); - - /** Constructor - - There is no open file initially. - */ - file_posix() = default; - - /** Constructor - - The moved-from object behaves as if default constructed. - */ - file_posix(file_posix&& other); - - /** Assignment - - The moved-from object behaves as if default constructed. - */ - file_posix& operator=(file_posix&& other); - - /// Returns the native handle associated with the file. - native_handle_type - native_handle() const - { - return fd_; - } - - /** Set the native handle associated with the file. - - If the file is open it is first closed. - - @param fd The native file handle to assign. - */ - void - native_handle(native_handle_type fd); - - /// Returns `true` if the file is open - bool - is_open() const - { - return fd_ != -1; - } - - /** Close the file if open - - @param ec Set to the error, if any occurred. - */ - void - close(error_code& ec); - - /** Open a file at the given path with the specified mode - - @param path The utf-8 encoded path to the file - - @param mode The file mode to use - - @param ec Set to the error, if any occurred - */ - void - open(char const* path, file_mode mode, error_code& ec); - - /** Return the size of the open file - - @param ec Set to the error, if any occurred - - @return The size in bytes - */ - std::uint64_t - size(error_code& ec) const; - - /** Return the current position in the open file - - @param ec Set to the error, if any occurred - - @return The offset in bytes from the beginning of the file - */ - std::uint64_t - pos(error_code& ec) const; - - /** Adjust the current position in the open file - - @param offset The offset in bytes from the beginning of the file - - @param ec Set to the error, if any occurred - */ - void - seek(std::uint64_t offset, error_code& ec); - - /** Read from the open file - - @param buffer The buffer for storing the result of the read - - @param n The number of bytes to read - - @param ec Set to the error, if any occurred - */ - std::size_t - read(void* buffer, std::size_t n, error_code& ec) const; - - /** Write to the open file - - @param buffer The buffer holding the data to write - - @param n The number of bytes to write - - @param ec Set to the error, if any occurred - */ - std::size_t - write(void const* buffer, std::size_t n, error_code& ec); -}; - -} // beast - -#include - -#endif - -#endif diff --git a/src/beast/include/beast/core/file_stdio.hpp b/src/beast/include/beast/core/file_stdio.hpp deleted file mode 100644 index 5b8753c6094..00000000000 --- a/src/beast/include/beast/core/file_stdio.hpp +++ /dev/null @@ -1,154 +0,0 @@ -// -// Copyright (c) 2015-2016 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_CORE_FILE_STDIO_HPP -#define BEAST_CORE_FILE_STDIO_HPP - -#include -#include -#include -#include -#include - -namespace beast { - -/** An implementation of File which uses cstdio. - - This class implements a file using the interfaces present - in the C++ Standard Library, in ``. -*/ -class file_stdio -{ - FILE* f_ = nullptr; - -public: - /** The type of the underlying file handle. - - This is platform-specific. - */ - using native_handle_type = FILE*; - - /** Destructor - - If the file is open it is first closed. - */ - ~file_stdio(); - - /** Constructor - - There is no open file initially. - */ - file_stdio() = default; - - /** Constructor - - The moved-from object behaves as if default constructed. - */ - file_stdio(file_stdio&& other); - - /** Assignment - - The moved-from object behaves as if default constructed. - */ - file_stdio& operator=(file_stdio&& other); - - /// Returns the native handle associated with the file. - FILE* - native_handle() const - { - return f_; - } - - /** Set the native handle associated with the file. - - If the file is open it is first closed. - - @param f The native file handle to assign. - */ - void - native_handle(FILE* f); - - /// Returns `true` if the file is open - bool - is_open() const - { - return f_ != nullptr; - } - - /** Close the file if open - - @param ec Set to the error, if any occurred. - */ - void - close(error_code& ec); - - /** Open a file at the given path with the specified mode - - @param path The utf-8 encoded path to the file - - @param mode The file mode to use - - @param ec Set to the error, if any occurred - */ - void - open(char const* path, file_mode mode, error_code& ec); - - /** Return the size of the open file - - @param ec Set to the error, if any occurred - - @return The size in bytes - */ - std::uint64_t - size(error_code& ec) const; - - /** Return the current position in the open file - - @param ec Set to the error, if any occurred - - @return The offset in bytes from the beginning of the file - */ - std::uint64_t - pos(error_code& ec) const; - - /** Adjust the current position in the open file - - @param offset The offset in bytes from the beginning of the file - - @param ec Set to the error, if any occurred - */ - void - seek(std::uint64_t offset, error_code& ec); - - /** Read from the open file - - @param buffer The buffer for storing the result of the read - - @param n The number of bytes to read - - @param ec Set to the error, if any occurred - */ - std::size_t - read(void* buffer, std::size_t n, error_code& ec) const; - - /** Write to the open file - - @param buffer The buffer holding the data to write - - @param n The number of bytes to write - - @param ec Set to the error, if any occurred - */ - std::size_t - write(void const* buffer, std::size_t n, error_code& ec); -}; - -} // beast - -#include - -#endif diff --git a/src/beast/include/beast/core/file_win32.hpp b/src/beast/include/beast/core/file_win32.hpp deleted file mode 100644 index 8aafd3450ff..00000000000 --- a/src/beast/include/beast/core/file_win32.hpp +++ /dev/null @@ -1,173 +0,0 @@ -// -// Copyright (c) 2015-2016 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_CORE_FILE_WIN32_HPP -#define BEAST_CORE_FILE_WIN32_HPP - -#include - -#if ! defined(BEAST_USE_WIN32_FILE) -# ifdef BOOST_MSVC -# define BEAST_USE_WIN32_FILE 1 -# else -# define BEAST_USE_WIN32_FILE 0 -# endif -#endif - -#if BEAST_USE_WIN32_FILE - -#include -#include -#include -#include -#include -#include - -namespace beast { - -/** An implementation of File for Win32. - - This class implements a @b File using Win32 native interfaces. -*/ -class file_win32 -{ - boost::detail::winapi::HANDLE_ h_ = - boost::detail::winapi::INVALID_HANDLE_VALUE_; - -public: - /** The type of the underlying file handle. - - This is platform-specific. - */ -#if BEAST_DOXYGEN - using native_handle_type = HANDLE; -#else - using native_handle_type = boost::detail::winapi::HANDLE_; -#endif - - /** Destructor - - If the file is open it is first closed. - */ - ~file_win32(); - - /** Constructor - - There is no open file initially. - */ - file_win32() = default; - - /** Constructor - - The moved-from object behaves as if default constructed. - */ - file_win32(file_win32&& other); - - /** Assignment - - The moved-from object behaves as if default constructed. - */ - file_win32& operator=(file_win32&& other); - - /// Returns the native handle associated with the file. - native_handle_type - native_handle() - { - return h_; - } - - /** Set the native handle associated with the file. - - If the file is open it is first closed. - - @param h The native file handle to assign. - */ - void - native_handle(native_handle_type h); - - /// Returns `true` if the file is open - bool - is_open() const - { - return h_ != boost::detail::winapi::INVALID_HANDLE_VALUE_; - } - - /** Close the file if open - - @param ec Set to the error, if any occurred. - */ - void - close(error_code& ec); - - /** Open a file at the given path with the specified mode - - @param path The utf-8 encoded path to the file - - @param mode The file mode to use - - @param ec Set to the error, if any occurred - */ - void - open(char const* path, file_mode mode, error_code& ec); - - /** Return the size of the open file - - @param ec Set to the error, if any occurred - - @return The size in bytes - */ - std::uint64_t - size(error_code& ec) const; - - /** Return the current position in the open file - - @param ec Set to the error, if any occurred - - @return The offset in bytes from the beginning of the file - */ - std::uint64_t - pos(error_code& ec); - - /** Adjust the current position in the open file - - @param offset The offset in bytes from the beginning of the file - - @param ec Set to the error, if any occurred - */ - void - seek(std::uint64_t offset, error_code& ec); - - /** Read from the open file - - @param buffer The buffer for storing the result of the read - - @param n The number of bytes to read - - @param ec Set to the error, if any occurred - */ - std::size_t - read(void* buffer, std::size_t n, error_code& ec); - - /** Write to the open file - - @param buffer The buffer holding the data to write - - @param n The number of bytes to write - - @param ec Set to the error, if any occurred - */ - std::size_t - write(void const* buffer, std::size_t n, error_code& ec); -}; - -} // beast - -#include - -#endif - -#endif diff --git a/src/beast/include/beast/core/flat_buffer.hpp b/src/beast/include/beast/core/flat_buffer.hpp deleted file mode 100644 index 3d19b71db31..00000000000 --- a/src/beast/include/beast/core/flat_buffer.hpp +++ /dev/null @@ -1,341 +0,0 @@ -// -// Copyright (c) 2013-2016 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_FLAT_BUFFER_HPP -#define BEAST_FLAT_BUFFER_HPP - -#include -#include -#include -#include -#include - -namespace beast { - -/** A linear dynamic buffer. - - Objects of this type meet the requirements of @b DynamicBuffer - and offer additional invariants: - - @li Buffer sequences returned by @ref data and @ref prepare - will always be of length one. - - @li A configurable maximum buffer size may be set upon - construction. Attempts to exceed the buffer size will throw - `std::length_error`. - - Upon construction, a maximum size for the buffer may be - specified. If this limit is exceeded, the `std::length_error` - exception will be thrown. - - @note This class is designed for use with algorithms that - take dynamic buffers as parameters, and are optimized - for the case where the input sequence or output sequence - is stored in a single contiguous buffer. -*/ -template -class basic_flat_buffer -#if ! BEAST_DOXYGEN - : private detail::empty_base_optimization< - typename std::allocator_traits:: - template rebind_alloc> -#endif -{ -public: -#if BEAST_DOXYGEN - /// The type of allocator used. - using allocator_type = Allocator; -#else - using allocator_type = typename - std::allocator_traits:: - template rebind_alloc; -#endif - -private: - enum - { - min_size = 512 - }; - - template - friend class basic_flat_buffer; - - using alloc_traits = - std::allocator_traits; - - static - inline - std::size_t - dist(char const* first, char const* last) - { - return static_cast(last - first); - } - - char* begin_; - char* in_; - char* out_; - char* last_; - char* end_; - std::size_t max_; - -public: - /// The type used to represent the input sequence as a list of buffers. - using const_buffers_type = boost::asio::const_buffers_1; - - /// The type used to represent the output sequence as a list of buffers. - using mutable_buffers_type = boost::asio::mutable_buffers_1; - - /// Destructor - ~basic_flat_buffer(); - - /** Constructor - - Upon construction, capacity will be zero. - */ - basic_flat_buffer(); - - /** Constructor - - Upon construction, capacity will be zero. - - @param limit The setting for @ref max_size. - */ - explicit - basic_flat_buffer(std::size_t limit); - - /** Constructor - - Upon construction, capacity will be zero. - - @param alloc The allocator to construct with. - */ - explicit - basic_flat_buffer(Allocator const& alloc); - - /** Constructor - - Upon construction, capacity will be zero. - - @param limit The setting for @ref max_size. - - @param alloc The allocator to use. - */ - basic_flat_buffer( - std::size_t limit, Allocator const& alloc); - - /** Move constructor - - After the move, `*this` will have an empty output sequence. - - @param other The object to move from. After the move, - The object's state will be as if constructed using - its current allocator and limit. - */ - basic_flat_buffer(basic_flat_buffer&& other); - - /** Move constructor - - After the move, `*this` will have an empty output sequence. - - @param other The object to move from. After the move, - The object's state will be as if constructed using - its current allocator and limit. - - @param alloc The allocator to use. - */ - basic_flat_buffer( - basic_flat_buffer&& other, Allocator const& alloc); - - /** Copy constructor - - @param other The object to copy from. - */ - basic_flat_buffer(basic_flat_buffer const& other); - - /** Copy constructor - - @param other The object to copy from. - - @param alloc The allocator to use. - */ - basic_flat_buffer(basic_flat_buffer const& other, - Allocator const& alloc); - - /** Copy constructor - - @param other The object to copy from. - */ - template - basic_flat_buffer( - basic_flat_buffer const& other); - - /** Copy constructor - - @param other The object to copy from. - - @param alloc The allocator to use. - */ - template - basic_flat_buffer( - basic_flat_buffer const& other, - Allocator const& alloc); - - /** Move assignment - - After the move, `*this` will have an empty output sequence. - - @param other The object to move from. After the move, - The object's state will be as if constructed using - its current allocator and limit. - */ - basic_flat_buffer& - operator=(basic_flat_buffer&& other); - - /** Copy assignment - - After the copy, `*this` will have an empty output sequence. - - @param other The object to copy from. - */ - basic_flat_buffer& - operator=(basic_flat_buffer const& other); - - /** Copy assignment - - After the copy, `*this` will have an empty output sequence. - - @param other The object to copy from. - */ - template - basic_flat_buffer& - operator=(basic_flat_buffer const& other); - - /// Returns a copy of the associated allocator. - allocator_type - get_allocator() const - { - return this->member(); - } - - /// Returns the size of the input sequence. - std::size_t - size() const - { - return dist(in_, out_); - } - - /// Return the maximum sum of the input and output sequence sizes. - std::size_t - max_size() const - { - return max_; - } - - /// Return the maximum sum of input and output sizes that can be held without an allocation. - std::size_t - capacity() const - { - return dist(begin_, end_); - } - - /// Get a list of buffers that represent the input sequence. - const_buffers_type - data() const - { - return {in_, dist(in_, out_)}; - } - - /** Get a list of buffers that represent the output sequence, with the given size. - - @throws std::length_error if `size() + n` exceeds `max_size()`. - - @note All previous buffers sequences obtained from - calls to @ref data or @ref prepare are invalidated. - */ - mutable_buffers_type - prepare(std::size_t n); - - /** Move bytes from the output sequence to the input sequence. - - @param n The number of bytes to move. If this is larger than - the number of bytes in the output sequences, then the entire - output sequences is moved. - - @note All previous buffers sequences obtained from - calls to @ref data or @ref prepare are invalidated. - */ - void - commit(std::size_t n) - { - out_ += (std::min)(n, dist(out_, last_)); - } - - /** Remove bytes from the input sequence. - - If `n` is greater than the number of bytes in the input - sequence, all bytes in the input sequence are removed. - - @note All previous buffers sequences obtained from - calls to @ref data or @ref prepare are invalidated. - */ - void - consume(std::size_t n); - - /** Reallocate the buffer to fit the input sequence. - - @note All previous buffers sequences obtained from - calls to @ref data or @ref prepare are invalidated. - */ - void - shrink_to_fit(); - - /// Exchange two flat buffers - template - friend - void - swap( - basic_flat_buffer& lhs, - basic_flat_buffer& rhs); - -private: - void - reset(); - - template - void - copy_from(DynamicBuffer const& other); - - void - move_assign(basic_flat_buffer&, std::true_type); - - void - move_assign(basic_flat_buffer&, std::false_type); - - void - copy_assign(basic_flat_buffer const&, std::true_type); - - void - copy_assign(basic_flat_buffer const&, std::false_type); - - void - swap(basic_flat_buffer&); - - void - swap(basic_flat_buffer&, std::true_type); - - void - swap(basic_flat_buffer&, std::false_type); -}; - -using flat_buffer = - basic_flat_buffer>; - -} // beast - -#include - -#endif diff --git a/src/beast/include/beast/core/handler_alloc.hpp b/src/beast/include/beast/core/handler_alloc.hpp deleted file mode 100644 index b7656a88358..00000000000 --- a/src/beast/include/beast/core/handler_alloc.hpp +++ /dev/null @@ -1,158 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HANDLER_ALLOC_HPP -#define BEAST_HANDLER_ALLOC_HPP - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { - -// Guidance from -// http://howardhinnant.github.io/allocator_boilerplate.html - -/** An allocator that uses handler customizations. - - This allocator uses the handler customizations `asio_handler_allocate` - and `asio_handler_deallocate` to manage memory. It meets the requirements - of @b Allocator and can be used anywhere a `std::allocator` is - accepted. - - @tparam T The type of objects allocated by the allocator. - - @tparam Handler The type of handler. - - @note Memory allocated by this allocator must be freed before - the handler is invoked or undefined behavior results. This behavior - is described as the "deallocate before invocation" Asio guarantee. -*/ -#if BEAST_DOXYGEN -template -class handler_alloc; -#else -template -class handler_alloc -{ -private: - // We want a partial template specialization as a friend - // but that isn't allowed so we friend all versions. This - // should produce a compile error if Handler is not - // constructible from H. - // - template - friend class handler_alloc; - - Handler& h_; - -public: - using value_type = T; - using is_always_equal = std::true_type; - using pointer = T*; - using reference = T&; - using const_pointer = T const*; - using const_reference = T const&; - using size_type = std::size_t; - using difference_type = std::ptrdiff_t; - - template - struct rebind - { - using other = handler_alloc; - }; - - handler_alloc() = delete; - handler_alloc(handler_alloc&&) = default; - handler_alloc(handler_alloc const&) = default; - handler_alloc& operator=(handler_alloc&&) = default; - handler_alloc& operator=(handler_alloc const&) = default; - - /** Construct the allocator. - - A reference of the handler is stored. The handler must - remain valid for at least the lifetime of the allocator. - */ - explicit - handler_alloc(Handler& h) - : h_(h) - { - } - - /// Copy constructor - template - handler_alloc( - handler_alloc const& other) - : h_(other.h_) - { - } - - value_type* - allocate(size_type n) - { - auto const size = n * sizeof(T); - using boost::asio::asio_handler_allocate; - return static_cast( - asio_handler_allocate(size, std::addressof(h_))); - } - - void - deallocate(value_type* p, size_type n) - { - auto const size = n * sizeof(T); - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate(p, size, std::addressof(h_)); - } - -//#if BOOST_WORKAROUND(BOOST_GCC, < 60000) // Works, but too coarse - -#if defined(BOOST_LIBSTDCXX_VERSION) && BOOST_LIBSTDCXX_VERSION < 60000 - template - void - construct(U* ptr, Args&&... args) - { - ::new((void*)ptr) U(std::forward(args)...); - } - - template - void - destroy(U* ptr) - { - ptr->~U(); - } -#endif - - template - friend - bool - operator==( - handler_alloc const&, - handler_alloc const&) - { - return true; - } - - template - friend - bool - operator!=( - handler_alloc const& lhs, - handler_alloc const& rhs) - { - return ! (lhs == rhs); - } -}; -#endif - -} // beast - -#endif diff --git a/src/beast/include/beast/core/handler_ptr.hpp b/src/beast/include/beast/core/handler_ptr.hpp deleted file mode 100644 index c288c4d1f91..00000000000 --- a/src/beast/include/beast/core/handler_ptr.hpp +++ /dev/null @@ -1,209 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HANDLER_PTR_HPP -#define BEAST_HANDLER_PTR_HPP - -#include -#include -#include -#include -#include -#include - -namespace beast { - -/** A smart pointer container with associated completion handler. - - This is a smart pointer that retains shared ownership of an - object through a pointer. Memory is managed using the allocation - and deallocation functions associated with a completion handler, - which is also stored in the object. The managed object is - destroyed and its memory deallocated when one of the following - happens: - - @li The function @ref invoke is called. - - @li The function @ref release_handler is called. - - @li The last remaining container owning the object is destroyed. - - Objects of this type are used in the implementation of - composed operations. Typically the composed operation's shared - state is managed by the @ref handler_ptr and an allocator - associated with the final handler is used to create the managed - object. - - @note The reference count is stored using a 16 bit unsigned - integer. Making more than 2^16 copies of one object results - in undefined behavior. - - @tparam T The type of the owned object. - - @tparam Handler The type of the completion handler. -*/ -template -class handler_ptr -{ - struct P - { - T* t; - std::atomic n; - - // There's no way to put the handler anywhere else - // without exposing ourselves to race conditions - // and all sorts of ugliness. - // See: - // https://github.com/vinniefalco/Beast/issues/215 - Handler handler; - - template - P(DeducedHandler&& handler, Args&&... args); - }; - - P* p_; - -public: - /// The type of element this object stores - using element_type = T; - - /// The type of handler this object stores - using handler_type = Handler; - - /// Copy assignment (disallowed). - handler_ptr& operator=(handler_ptr const&) = delete; - - /** Destructs the owned object if no more @ref handler_ptr link to it. - - If `*this` owns an object and it is the last @ref handler_ptr - owning it, the object is destroyed and the memory deallocated - using the associated deallocator. - */ - ~handler_ptr(); - - /** Move constructor. - - When this call returns, the moved-from container - will have no owned object. - */ - handler_ptr(handler_ptr&& other); - - /// Copy constructor - handler_ptr(handler_ptr const& other); - - /** Construct a new @ref handler_ptr - - This creates a new @ref handler_ptr with an owned object - of type `T`. The allocator associated with the handler will - be used to allocate memory for the owned object. The constructor - for the owned object will be called thusly: - - @code - T(handler, std::forward(args)...) - @endcode - - @param handler The handler to associate with the owned - object. The argument will be moved. - - @param args Optional arguments forwarded to - the owned object's constructor. - */ - template - handler_ptr(Handler&& handler, Args&&... args); - - /** Construct a new @ref handler_ptr - - This creates a new @ref handler_ptr with an owned object - of type `T`. The allocator associated with the handler will - be used to allocate memory for the owned object. The constructor - for the owned object will be called thusly: - - @code - T(handler, std::forward(args)...) - @endcode - - @param handler The handler to associate with the owned - object. The argument will be copied. - - @param args Optional arguments forwarded to - the owned object's constructor. - */ - template - handler_ptr(Handler const& handler, Args&&... args); - - /// Returns a reference to the handler - handler_type& - handler() const - { - return p_->handler; - } - - /// Returns `true` if `*this` owns an object. - explicit - operator bool() const - { - return p_ && p_->t; - } - - /** Returns a pointer to the owned object. - - If `*this` owns an object, a pointer to the - object is returned, else `nullptr` is returned. - */ - T* - get() const - { - return p_ ? p_->t : nullptr; - } - - /// Return a reference to the owned object. - T& - operator*() const - { - return *p_->t; - } - - /// Return a pointer to the owned object. - T* - operator->() const - { - return p_->t; - } - - /** Release ownership of the handler - - If `*this` owns an object, it is first destroyed. - - @return The released handler. - */ - handler_type - release_handler(); - - /** Invoke the handler in the owned object. - - This function invokes the handler in the owned object - with a forwarded argument list. Before the invocation, - the owned object is destroyed, satisfying the - deallocation-before-invocation Asio guarantee. All - instances of @ref handler_ptr which refer to the - same owned object will be reset, including this instance. - - @note Care must be taken when the arguments are themselves - stored in the owned object. Such arguments must first be - moved to the stack or elsewhere, and then passed, or else - undefined behavior will result. - */ - template - void - invoke(Args&&... args); -}; - -} // beast - -#include - -#endif diff --git a/src/beast/include/beast/core/impl/buffer_cat.ipp b/src/beast/include/beast/core/impl/buffer_cat.ipp deleted file mode 100644 index f0f9d45eaf2..00000000000 --- a/src/beast/include/beast/core/impl/buffer_cat.ipp +++ /dev/null @@ -1,497 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_IMPL_BUFFER_CAT_IPP -#define BEAST_IMPL_BUFFER_CAT_IPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { - -template -class buffer_cat_view::const_iterator -{ -#if 0 - static_assert( - detail::is_all_const_buffer_sequence::value, - "BufferSequence requirements not met"); -#endif - - std::size_t n_; - std::tuple const* bn_; - std::array()> buf_; - - friend class buffer_cat_view; - - template - using C = std::integral_constant; - - template - using iter_t = typename std::tuple_element< - I, std::tuple>::type::const_iterator; - - template - iter_t& - iter() - { - // type-pun - return *reinterpret_cast< - iter_t*>(static_cast(buf_.data())); - } - - template - iter_t const& - iter() const - { - // type-pun - return *reinterpret_cast< - iter_t const*>(static_cast< - void const*>(buf_.data())); - } - -public: - using value_type = typename - detail::common_buffers_type::type; - using pointer = value_type const*; - using reference = value_type; - using difference_type = std::ptrdiff_t; - using iterator_category = - std::bidirectional_iterator_tag; - - ~const_iterator(); - const_iterator(); - const_iterator(const_iterator&& other); - const_iterator(const_iterator const& other); - const_iterator& operator=(const_iterator&& other); - const_iterator& operator=(const_iterator const& other); - - bool - operator==(const_iterator const& other) const; - - bool - operator!=(const_iterator const& other) const - { - return ! (*this == other); - } - - reference - operator*() const; - - pointer - operator->() const = delete; - - const_iterator& - operator++(); - - const_iterator - operator++(int); - - const_iterator& - operator--(); - - const_iterator - operator--(int); - -private: - const_iterator( - std::tuple const& bn, bool at_end); - - void - construct(C const&) - { - auto constexpr I = sizeof...(Bn); - n_ = I; - } - - template - void - construct(C const&) - { - if(boost::asio::buffer_size( - std::get(*bn_)) != 0) - { - n_ = I; - new(&buf_[0]) iter_t{ - std::get(*bn_).begin()}; - return; - } - construct(C{}); - } - - void - rconstruct(C<0> const&) - { - auto constexpr I = 0; - if(boost::asio::buffer_size( - std::get(*bn_)) != 0) - { - n_ = I; - new(&buf_[0]) iter_t{ - std::get(*bn_).end()}; - return; - } - BOOST_THROW_EXCEPTION(std::logic_error{ - "invalid iterator"}); - } - - template - void - rconstruct(C const&) - { - if(boost::asio::buffer_size( - std::get(*bn_)) != 0) - { - n_ = I; - new(&buf_[0]) iter_t{ - std::get(*bn_).end()}; - return; - } - rconstruct(C{}); - } - - void - destroy(C const&) - { - return; - } - - template - void - destroy(C const&) - { - if(n_ == I) - { - using Iter = iter_t; - iter().~Iter(); - return; - } - destroy(C{}); - } - - void - move(const_iterator&&, - C const&) - { - } - - template - void - move(const_iterator&& other, - C const&) - { - if(n_ == I) - { - new(&buf_[0]) iter_t{ - std::move(other.iter())}; - return; - } - move(std::move(other), C{}); - } - - void - copy(const_iterator const&, - C const&) - { - } - - template - void - copy(const_iterator const& other, - C const&) - { - if(n_ == I) - { - new(&buf_[0]) iter_t{ - other.iter()}; - return; - } - copy(other, C{}); - } - - bool - equal(const_iterator const&, - C const&) const - { - return true; - } - - template - bool - equal(const_iterator const& other, - C const&) const - { - if(n_ == I) - return iter() == other.iter(); - return equal(other, C{}); - } - - [[noreturn]] - reference - dereference(C const&) const - { - BOOST_THROW_EXCEPTION(std::logic_error{ - "invalid iterator"}); - } - - template - reference - dereference(C const&) const - { - if(n_ == I) - return *iter(); - return dereference(C{}); - } - - [[noreturn]] - void - increment(C const&) - { - BOOST_THROW_EXCEPTION(std::logic_error{ - "invalid iterator"}); - } - - template - void - increment(C const&) - { - if(n_ == I) - { - if(++iter() != - std::get(*bn_).end()) - return; - using Iter = iter_t; - iter().~Iter(); - return construct(C{}); - } - increment(C{}); - } - - void - decrement(C const&) - { - auto constexpr I = sizeof...(Bn); - if(n_ == I) - rconstruct(C{}); - decrement(C{}); - } - - template - void - decrement(C const&) - { - if(n_ == I) - { - if(iter() != std::get(*bn_).begin()) - { - --iter(); - return; - } - --n_; - using Iter = iter_t; - iter().~Iter(); - rconstruct(C{}); - } - decrement(C{}); - } - - void - decrement(C<0> const&) - { - auto constexpr I = 0; - if(iter() != std::get(*bn_).begin()) - { - --iter(); - return; - } - BOOST_THROW_EXCEPTION(std::logic_error{ - "invalid iterator"}); - } -}; - -//------------------------------------------------------------------------------ - -template -buffer_cat_view:: -const_iterator::~const_iterator() -{ - destroy(C<0>{}); -} - -template -buffer_cat_view:: -const_iterator::const_iterator() - : n_(sizeof...(Bn)) - , bn_(nullptr) -{ -} - -template -buffer_cat_view:: -const_iterator::const_iterator( - std::tuple const& bn, bool at_end) - : bn_(&bn) -{ - if(at_end) - n_ = sizeof...(Bn); - else - construct(C<0>{}); -} - -template -buffer_cat_view:: -const_iterator::const_iterator(const_iterator&& other) - : n_(other.n_) - , bn_(other.bn_) -{ - move(std::move(other), C<0>{}); -} - -template -buffer_cat_view:: -const_iterator::const_iterator(const_iterator const& other) - : n_(other.n_) - , bn_(other.bn_) -{ - copy(other, C<0>{}); -} - -template -auto -buffer_cat_view:: -const_iterator::operator=(const_iterator&& other) -> - const_iterator& -{ - if(&other == this) - return *this; - destroy(C<0>{}); - n_ = other.n_; - bn_ = other.bn_; - // VFALCO What about exceptions? - move(std::move(other), C<0>{}); - return *this; -} - -template -auto -buffer_cat_view:: -const_iterator::operator=(const_iterator const& other) -> -const_iterator& -{ - if(&other == this) - return *this; - destroy(C<0>{}); - n_ = other.n_; - bn_ = other.bn_; - // VFALCO What about exceptions? - copy(other, C<0>{}); - return *this; -} - -template -bool -buffer_cat_view:: -const_iterator::operator==(const_iterator const& other) const -{ - if(bn_ != other.bn_) - return false; - if(n_ != other.n_) - return false; - return equal(other, C<0>{}); -} - -template -auto -buffer_cat_view:: -const_iterator::operator*() const -> - reference -{ - return dereference(C<0>{}); -} - -template -auto -buffer_cat_view:: -const_iterator::operator++() -> - const_iterator& -{ - increment(C<0>{}); - return *this; -} - -template -auto -buffer_cat_view:: -const_iterator::operator++(int) -> - const_iterator -{ - auto temp = *this; - ++(*this); - return temp; -} - -template -auto -buffer_cat_view:: -const_iterator::operator--() -> - const_iterator& -{ - decrement(C{}); - return *this; -} - -template -auto -buffer_cat_view:: -const_iterator::operator--(int) -> - const_iterator -{ - auto temp = *this; - --(*this); - return temp; -} - -//------------------------------------------------------------------------------ - -template -buffer_cat_view:: -buffer_cat_view(Bn const&... bn) - : bn_(bn...) -{ -} - - -template -inline -auto -buffer_cat_view::begin() const -> - const_iterator -{ - return const_iterator{bn_, false}; -} - -template -inline -auto -buffer_cat_view::end() const -> - const_iterator -{ - return const_iterator{bn_, true}; -} - -} // beast - -#endif diff --git a/src/beast/include/beast/core/impl/buffer_prefix.ipp b/src/beast/include/beast/core/impl/buffer_prefix.ipp deleted file mode 100644 index b3aa55782a6..00000000000 --- a/src/beast/include/beast/core/impl/buffer_prefix.ipp +++ /dev/null @@ -1,290 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_IMPL_BUFFER_PREFIX_IPP -#define BEAST_IMPL_BUFFER_PREFIX_IPP - -#include -#include -#include -#include -#include -#include - -namespace beast { - -namespace detail { - -inline -boost::asio::const_buffer -buffer_prefix(std::size_t n, - boost::asio::const_buffer buffer) -{ - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - return { buffer_cast(buffer), - (std::min)(n, buffer_size(buffer)) }; -} - -inline -boost::asio::mutable_buffer -buffer_prefix(std::size_t n, - boost::asio::mutable_buffer buffer) -{ - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - return { buffer_cast(buffer), - (std::min)(n, buffer_size(buffer)) }; -} - -} // detail - -template -class buffer_prefix_view::const_iterator -{ - friend class buffer_prefix_view; - - buffer_prefix_view const* b_ = nullptr; - iter_type it_; - -public: - using value_type = typename std::conditional< - std::is_convertible::value_type, - boost::asio::mutable_buffer>::value, - boost::asio::mutable_buffer, - boost::asio::const_buffer>::type; - using pointer = value_type const*; - using reference = value_type; - using difference_type = std::ptrdiff_t; - using iterator_category = - std::bidirectional_iterator_tag; - - const_iterator() = default; - const_iterator(const_iterator&& other); - const_iterator(const_iterator const& other); - const_iterator& operator=(const_iterator&& other); - const_iterator& operator=(const_iterator const& other); - - bool - operator==(const_iterator const& other) const - { - return b_ == other.b_ && it_ == other.it_; - } - - bool - operator!=(const_iterator const& other) const - { - return !(*this == other); - } - - reference - operator*() const - { - if(it_ == b_->back_) - return detail::buffer_prefix(b_->size_, *it_); - return *it_; - } - - pointer - operator->() const = delete; - - const_iterator& - operator++() - { - ++it_; - return *this; - } - - const_iterator - operator++(int) - { - auto temp = *this; - ++(*this); - return temp; - } - - const_iterator& - operator--() - { - --it_; - return *this; - } - - const_iterator - operator--(int) - { - auto temp = *this; - --(*this); - return temp; - } - -private: - const_iterator(buffer_prefix_view const& b, - bool at_end) - : b_(&b) - , it_(at_end ? b.end_ : b.bs_.begin()) - { - } -}; - -template -void -buffer_prefix_view:: -setup(std::size_t n) -{ - for(end_ = bs_.begin(); end_ != bs_.end(); ++end_) - { - auto const len = - boost::asio::buffer_size(*end_); - if(n <= len) - { - size_ = n; - back_ = end_++; - return; - } - n -= len; - } - size_ = 0; - back_ = end_; -} - -template -buffer_prefix_view:: -const_iterator:: -const_iterator(const_iterator&& other) - : b_(other.b_) - , it_(std::move(other.it_)) -{ -} - -template -buffer_prefix_view:: -const_iterator:: -const_iterator(const_iterator const& other) - : b_(other.b_) - , it_(other.it_) -{ -} - -template -auto -buffer_prefix_view:: -const_iterator:: -operator=(const_iterator&& other) -> - const_iterator& -{ - b_ = other.b_; - it_ = std::move(other.it_); - return *this; -} - -template -auto -buffer_prefix_view:: -const_iterator:: -operator=(const_iterator const& other) -> - const_iterator& -{ - if(&other == this) - return *this; - b_ = other.b_; - it_ = other.it_; - return *this; -} - -template -buffer_prefix_view:: -buffer_prefix_view(buffer_prefix_view&& other) - : buffer_prefix_view(std::move(other), - std::distance(other.bs_.begin(), other.back_), - std::distance(other.bs_.begin(), other.end_)) -{ -} - -template -buffer_prefix_view:: -buffer_prefix_view(buffer_prefix_view const& other) - : buffer_prefix_view(other, - std::distance(other.bs_.begin(), other.back_), - std::distance(other.bs_.begin(), other.end_)) -{ -} - -template -auto -buffer_prefix_view:: -operator=(buffer_prefix_view&& other) -> - buffer_prefix_view& -{ - auto const nback = std::distance( - other.bs_.begin(), other.back_); - auto const nend = std::distance( - other.bs_.begin(), other.end_); - bs_ = std::move(other.bs_); - back_ = std::next(bs_.begin(), nback); - end_ = std::next(bs_.begin(), nend); - size_ = other.size_; - return *this; -} - -template -auto -buffer_prefix_view:: -operator=(buffer_prefix_view const& other) -> - buffer_prefix_view& -{ - auto const nback = std::distance( - other.bs_.begin(), other.back_); - auto const nend = std::distance( - other.bs_.begin(), other.end_); - bs_ = other.bs_; - back_ = std::next(bs_.begin(), nback); - end_ = std::next(bs_.begin(), nend); - size_ = other.size_; - return *this; -} - -template -buffer_prefix_view:: -buffer_prefix_view(std::size_t n, BufferSequence const& bs) - : bs_(bs) -{ - setup(n); -} - -template -template -buffer_prefix_view:: -buffer_prefix_view(std::size_t n, - boost::in_place_init_t, Args&&... args) - : bs_(std::forward(args)...) -{ - setup(n); -} - -template -inline -auto -buffer_prefix_view::begin() const -> - const_iterator -{ - return const_iterator{*this, false}; -} - -template -inline -auto -buffer_prefix_view::end() const -> - const_iterator -{ - return const_iterator{*this, true}; -} - -} // beast - -#endif diff --git a/src/beast/include/beast/core/impl/buffered_read_stream.ipp b/src/beast/include/beast/core/impl/buffered_read_stream.ipp deleted file mode 100644 index d78c136149b..00000000000 --- a/src/beast/include/beast/core/impl/buffered_read_stream.ipp +++ /dev/null @@ -1,241 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_IMPL_BUFFERED_READ_STREAM_IPP -#define BEAST_IMPL_BUFFERED_READ_STREAM_IPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { - -template -template -class buffered_read_stream< - Stream, DynamicBuffer>::read_some_op -{ - int step_ = 0; - buffered_read_stream& s_; - MutableBufferSequence b_; - Handler h_; - -public: - read_some_op(read_some_op&&) = default; - read_some_op(read_some_op const&) = default; - - template - read_some_op(DeducedHandler&& h, - buffered_read_stream& s, - MutableBufferSequence const& b) - : s_(s) - , b_(b) - , h_(std::forward(h)) - { - } - - void - operator()(error_code const& ec, - std::size_t bytes_transferred); - - friend - void* asio_handler_allocate( - std::size_t size, read_some_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->h_)); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, read_some_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->h_)); - } - - friend - bool asio_handler_is_continuation(read_some_op* op) - { - using boost::asio::asio_handler_is_continuation; - return asio_handler_is_continuation( - std::addressof(op->h_)); - } - - template - friend - void asio_handler_invoke(Function&& f, read_some_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke(f, std::addressof(op->h_)); - } -}; - -template -template -void -buffered_read_stream:: -read_some_op::operator()( - error_code const& ec, std::size_t bytes_transferred) -{ - switch(step_) - { - case 0: - if(s_.sb_.size() == 0) - { - if(s_.capacity_ == 0) - { - // read (unbuffered) - step_ = 1; - return s_.next_layer_.async_read_some( - b_, std::move(*this)); - } - - // read - step_ = 2; - return s_.next_layer_.async_read_some( - s_.sb_.prepare(s_.capacity_), - std::move(*this)); - - } - step_ = 3; - s_.get_io_service().post( - bind_handler(std::move(*this), ec, 0)); - return; - - case 1: - // upcall - break; - - case 2: - s_.sb_.commit(bytes_transferred); - BEAST_FALLTHROUGH; - - case 3: - bytes_transferred = - boost::asio::buffer_copy(b_, s_.sb_.data()); - s_.sb_.consume(bytes_transferred); - break; - } - h_(ec, bytes_transferred); -} - -//------------------------------------------------------------------------------ - -template -template -buffered_read_stream:: -buffered_read_stream(Args&&... args) - : next_layer_(std::forward(args)...) -{ -} - -template -template -auto -buffered_read_stream:: -async_write_some(ConstBufferSequence const& buffers, - WriteHandler&& handler) -> - async_return_type -{ - static_assert(is_async_write_stream::value, - "AsyncWriteStream requirements not met"); - static_assert(is_const_buffer_sequence< - ConstBufferSequence>::value, - "ConstBufferSequence requirements not met"); - static_assert(is_completion_handler::value, - "WriteHandler requirements not met"); - return next_layer_.async_write_some(buffers, - std::forward(handler)); -} - -template -template -std::size_t -buffered_read_stream:: -read_some( - MutableBufferSequence const& buffers) -{ - static_assert(is_sync_read_stream::value, - "SyncReadStream requirements not met"); - static_assert(is_mutable_buffer_sequence< - MutableBufferSequence>::value, - "MutableBufferSequence requirements not met"); - error_code ec; - auto n = read_some(buffers, ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); - return n; -} - -template -template -std::size_t -buffered_read_stream:: -read_some(MutableBufferSequence const& buffers, - error_code& ec) -{ - static_assert(is_sync_read_stream::value, - "SyncReadStream requirements not met"); - static_assert(is_mutable_buffer_sequence< - MutableBufferSequence>::value, - "MutableBufferSequence requirements not met"); - using boost::asio::buffer_size; - using boost::asio::buffer_copy; - if(sb_.size() == 0) - { - if(capacity_ == 0) - return next_layer_.read_some(buffers, ec); - sb_.commit(next_layer_.read_some( - sb_.prepare(capacity_), ec)); - if(ec) - return 0; - } - else - { - ec.assign(0, ec.category()); - } - auto bytes_transferred = - buffer_copy(buffers, sb_.data()); - sb_.consume(bytes_transferred); - return bytes_transferred; -} - -template -template -auto -buffered_read_stream:: -async_read_some(MutableBufferSequence const& buffers, - ReadHandler&& handler) -> - async_return_type -{ - static_assert(is_async_read_stream::value, - "Stream requirements not met"); - static_assert(is_mutable_buffer_sequence< - MutableBufferSequence>::value, - "MutableBufferSequence requirements not met"); - async_completion init{handler}; - read_some_op>{ - init.completion_handler, *this, buffers}( - error_code{}, 0); - return init.result.get(); -} - -} // beast - -#endif diff --git a/src/beast/include/beast/core/impl/buffers_adapter.ipp b/src/beast/include/beast/core/impl/buffers_adapter.ipp deleted file mode 100644 index 3216667f1b1..00000000000 --- a/src/beast/include/beast/core/impl/buffers_adapter.ipp +++ /dev/null @@ -1,505 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_IMPL_BUFFERS_ADAPTER_IPP -#define BEAST_IMPL_BUFFERS_ADAPTER_IPP - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { - -template -class buffers_adapter:: - const_buffers_type -{ - buffers_adapter const* ba_; - -public: - using value_type = boost::asio::const_buffer; - - class const_iterator; - - const_buffers_type() = delete; - const_buffers_type( - const_buffers_type const&) = default; - const_buffers_type& operator=( - const_buffers_type const&) = default; - - const_iterator - begin() const; - - const_iterator - end() const; - -private: - friend class buffers_adapter; - - const_buffers_type(buffers_adapter const& ba) - : ba_(&ba) - { - } -}; - -template -class buffers_adapter:: - const_buffers_type::const_iterator -{ - iter_type it_; - buffers_adapter const* ba_ = nullptr; - -public: - using value_type = boost::asio::const_buffer; - using pointer = value_type const*; - using reference = value_type; - using difference_type = std::ptrdiff_t; - using iterator_category = - std::bidirectional_iterator_tag; - - const_iterator() = default; - const_iterator(const_iterator&& other) = default; - const_iterator(const_iterator const& other) = default; - const_iterator& operator=(const_iterator&& other) = default; - const_iterator& operator=(const_iterator const& other) = default; - - bool - operator==(const_iterator const& other) const - { - return ba_ == other.ba_ && - it_ == other.it_; - } - - bool - operator!=(const_iterator const& other) const - { - return !(*this == other); - } - - reference - operator*() const - { - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - return value_type{buffer_cast(*it_), - (ba_->out_ == ba_->bs_.end() || - it_ != ba_->out_) ? buffer_size(*it_) : ba_->out_pos_} + - (it_ == ba_->begin_ ? ba_->in_pos_ : 0); - } - - pointer - operator->() const = delete; - - const_iterator& - operator++() - { - ++it_; - return *this; - } - - const_iterator - operator++(int) - { - auto temp = *this; - ++(*this); - return temp; - } - - const_iterator& - operator--() - { - --it_; - return *this; - } - - const_iterator - operator--(int) - { - auto temp = *this; - --(*this); - return temp; - } - -private: - friend class const_buffers_type; - - const_iterator(buffers_adapter const& ba, - iter_type iter) - : it_(iter) - , ba_(&ba) - { - } -}; - -template -inline -auto -buffers_adapter::const_buffers_type::begin() const -> - const_iterator -{ - return const_iterator{*ba_, ba_->begin_}; -} - -template -inline -auto -buffers_adapter::const_buffers_type::end() const -> - const_iterator -{ - return const_iterator{*ba_, ba_->out_ == - ba_->end_ ? ba_->end_ : std::next(ba_->out_)}; -} - -//------------------------------------------------------------------------------ - -template -class buffers_adapter:: -mutable_buffers_type -{ - buffers_adapter const* ba_; - -public: - using value_type = boost::asio::mutable_buffer; - - class const_iterator; - - mutable_buffers_type() = delete; - mutable_buffers_type( - mutable_buffers_type const&) = default; - mutable_buffers_type& operator=( - mutable_buffers_type const&) = default; - - const_iterator - begin() const; - - const_iterator - end() const; - -private: - friend class buffers_adapter; - - mutable_buffers_type( - buffers_adapter const& ba) - : ba_(&ba) - { - } -}; - -template -class buffers_adapter:: -mutable_buffers_type::const_iterator -{ - iter_type it_; - buffers_adapter const* ba_ = nullptr; - -public: - using value_type = boost::asio::mutable_buffer; - using pointer = value_type const*; - using reference = value_type; - using difference_type = std::ptrdiff_t; - using iterator_category = - std::bidirectional_iterator_tag; - - const_iterator() = default; - const_iterator(const_iterator&& other) = default; - const_iterator(const_iterator const& other) = default; - const_iterator& operator=(const_iterator&& other) = default; - const_iterator& operator=(const_iterator const& other) = default; - - bool - operator==(const_iterator const& other) const - { - return ba_ == other.ba_ && - it_ == other.it_; - } - - bool - operator!=(const_iterator const& other) const - { - return !(*this == other); - } - - reference - operator*() const - { - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - return value_type{buffer_cast(*it_), - it_ == std::prev(ba_->end_) ? - ba_->out_end_ : buffer_size(*it_)} + - (it_ == ba_->out_ ? ba_->out_pos_ : 0); - } - - pointer - operator->() const = delete; - - const_iterator& - operator++() - { - ++it_; - return *this; - } - - const_iterator - operator++(int) - { - auto temp = *this; - ++(*this); - return temp; - } - - const_iterator& - operator--() - { - --it_; - return *this; - } - - const_iterator - operator--(int) - { - auto temp = *this; - --(*this); - return temp; - } - -private: - friend class mutable_buffers_type; - - const_iterator(buffers_adapter const& ba, - iter_type iter) - : it_(iter) - , ba_(&ba) - { - } -}; - -template -inline -auto -buffers_adapter::mutable_buffers_type::begin() const -> - const_iterator -{ - return const_iterator{*ba_, ba_->out_}; -} - -template -inline -auto -buffers_adapter::mutable_buffers_type::end() const -> - const_iterator -{ - return const_iterator{*ba_, ba_->end_}; -} - -//------------------------------------------------------------------------------ - -template -buffers_adapter::buffers_adapter( - buffers_adapter&& other) - : buffers_adapter(std::move(other), - std::distance(other.bs_.begin(), other.begin_), - std::distance(other.bs_.begin(), other.out_), - std::distance(other.bs_.begin(), other.end_)) -{ -} - -template -buffers_adapter::buffers_adapter( - buffers_adapter const& other) - : buffers_adapter(other, - std::distance(other.bs_.begin(), other.begin_), - std::distance(other.bs_.begin(), other.out_), - std::distance(other.bs_.begin(), other.end_)) -{ -} - -template -auto -buffers_adapter::operator=( - buffers_adapter&& other) -> buffers_adapter& -{ - auto const nbegin = std::distance( - other.bs_.begin(), other.begin_); - auto const nout = std::distance( - other.bs_.begin(), other.out_); - auto const nend = std::distance( - other.bs_.begin(), other.end_); - bs_ = std::move(other.bs_); - begin_ = std::next(bs_.begin(), nbegin); - out_ = std::next(bs_.begin(), nout); - end_ = std::next(bs_.begin(), nend); - max_size_ = other.max_size_; - in_pos_ = other.in_pos_; - in_size_ = other.in_size_; - out_pos_ = other.out_pos_; - out_end_ = other.out_end_; - return *this; -} - -template -auto -buffers_adapter::operator=( - buffers_adapter const& other) -> buffers_adapter& -{ - auto const nbegin = std::distance( - other.bs_.begin(), other.begin_); - auto const nout = std::distance( - other.bs_.begin(), other.out_); - auto const nend = std::distance( - other.bs_.begin(), other.end_); - bs_ = other.bs_; - begin_ = std::next(bs_.begin(), nbegin); - out_ = std::next(bs_.begin(), nout); - end_ = std::next(bs_.begin(), nend); - max_size_ = other.max_size_; - in_pos_ = other.in_pos_; - in_size_ = other.in_size_; - out_pos_ = other.out_pos_; - out_end_ = other.out_end_; - return *this; -} - -template -buffers_adapter::buffers_adapter( - MutableBufferSequence const& bs) - : bs_(bs) - , begin_(bs_.begin()) - , out_(bs_.begin()) - , end_(bs_.begin()) - , max_size_(boost::asio::buffer_size(bs_)) -{ -} - -template -auto -buffers_adapter::prepare(std::size_t n) -> - mutable_buffers_type -{ - using boost::asio::buffer_size; - end_ = out_; - if(end_ != bs_.end()) - { - auto size = buffer_size(*end_) - out_pos_; - if(n > size) - { - n -= size; - while(++end_ != bs_.end()) - { - size = buffer_size(*end_); - if(n < size) - { - out_end_ = n; - n = 0; - ++end_; - break; - } - n -= size; - out_end_ = size; - } - } - else - { - ++end_; - out_end_ = out_pos_ + n; - n = 0; - } - } - if(n > 0) - BOOST_THROW_EXCEPTION(std::length_error{ - "buffer overflow"}); - return mutable_buffers_type{*this}; -} - -template -void -buffers_adapter::commit(std::size_t n) -{ - using boost::asio::buffer_size; - if(out_ == end_) - return; - auto const last = std::prev(end_); - while(out_ != last) - { - auto const avail = - buffer_size(*out_) - out_pos_; - if(n < avail) - { - out_pos_ += n; - in_size_ += n; - max_size_ -= n; - return; - } - ++out_; - n -= avail; - out_pos_ = 0; - in_size_ += avail; - max_size_ -= avail; - } - - n = (std::min)(n, out_end_ - out_pos_); - out_pos_ += n; - in_size_ += n; - max_size_ -= n; - if(out_pos_ == buffer_size(*out_)) - { - ++out_; - out_pos_ = 0; - out_end_ = 0; - } -} - -template -inline -auto -buffers_adapter::data() const -> - const_buffers_type -{ - return const_buffers_type{*this}; -} - -template -void -buffers_adapter::consume(std::size_t n) -{ - using boost::asio::buffer_size; - while(begin_ != out_) - { - auto const avail = - buffer_size(*begin_) - in_pos_; - if(n < avail) - { - in_size_ -= n; - in_pos_ += n; - return; - } - n -= avail; - in_size_ -= avail; - in_pos_ = 0; - ++begin_; - } - auto const avail = out_pos_ - in_pos_; - if(n < avail) - { - in_size_ -= n; - in_pos_ += n; - } - else - { - in_size_ -= avail; - in_pos_ = out_pos_; - } -} - -} // beast - -#endif diff --git a/src/beast/include/beast/core/impl/consuming_buffers.ipp b/src/beast/include/beast/core/impl/consuming_buffers.ipp deleted file mode 100644 index fca247ef136..00000000000 --- a/src/beast/include/beast/core/impl/consuming_buffers.ipp +++ /dev/null @@ -1,235 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_IMPL_CONSUMING_BUFFERS_IPP -#define BEAST_IMPL_CONSUMING_BUFFERS_IPP - -#include -#include -#include -#include -#include -#include - -namespace beast { - -template -class consuming_buffers::const_iterator -{ - friend class consuming_buffers; - - using iter_type = - typename Buffers::const_iterator; - - iter_type it_; - consuming_buffers const* b_ = nullptr; - -public: - using value_type = typename std::conditional< - std::is_convertible::value_type, - boost::asio::mutable_buffer>::value, - boost::asio::mutable_buffer, - boost::asio::const_buffer>::type; - using pointer = value_type const*; - using reference = value_type; - using difference_type = std::ptrdiff_t; - using iterator_category = - std::bidirectional_iterator_tag; - - const_iterator() = default; - const_iterator(const_iterator&& other) = default; - const_iterator(const_iterator const& other) = default; - const_iterator& operator=(const_iterator&& other) = default; - const_iterator& operator=(const_iterator const& other) = default; - - bool - operator==(const_iterator const& other) const - { - return b_ == other.b_ && it_ == other.it_; - } - - bool - operator!=(const_iterator const& other) const - { - return !(*this == other); - } - - reference - operator*() const - { - return it_ == b_->begin_ - ? value_type{*it_} + b_->skip_ - : *it_; - } - - pointer - operator->() const = delete; - - const_iterator& - operator++() - { - ++it_; - return *this; - } - - const_iterator - operator++(int) - { - auto temp = *this; - ++(*this); - return temp; - } - - const_iterator& - operator--() - { - --it_; - return *this; - } - - const_iterator - operator--(int) - { - auto temp = *this; - --(*this); - return temp; - } - -private: - const_iterator(consuming_buffers const& b, - iter_type it) - : it_(it) - , b_(&b) - { - } -}; - -//------------------------------------------------------------------------------ - -template -consuming_buffers:: -consuming_buffers() - : begin_(bs_.begin()) -{ -} - -template -consuming_buffers:: -consuming_buffers(consuming_buffers&& other) - : consuming_buffers(std::move(other), - std::distance( - other.bs_.begin(), other.begin_)) -{ -} - -template -consuming_buffers:: -consuming_buffers(consuming_buffers const& other) - : consuming_buffers(other, - std::distance( - other.bs_.begin(), other.begin_)) -{ -} - -template -consuming_buffers:: -consuming_buffers(Buffers const& bs) - : bs_(bs) - , begin_(bs_.begin()) -{ - static_assert( - is_const_buffer_sequence::value|| - is_mutable_buffer_sequence::value, - "BufferSequence requirements not met"); -} - -template -template -consuming_buffers:: -consuming_buffers(boost::in_place_init_t, Args&&... args) - : bs_(std::forward(args)...) - , begin_(bs_.begin()) -{ - static_assert(sizeof...(Args) > 0, - "Missing constructor arguments"); - static_assert( - std::is_constructible::value, - "Buffers not constructible from arguments"); -} - -template -auto -consuming_buffers:: -operator=(consuming_buffers&& other) -> - consuming_buffers& -{ - auto const nbegin = std::distance( - other.bs_.begin(), other.begin_); - bs_ = std::move(other.bs_); - begin_ = std::next(bs_.begin(), nbegin); - skip_ = other.skip_; - return *this; -} - -template -auto -consuming_buffers:: -operator=(consuming_buffers const& other) -> - consuming_buffers& -{ - auto const nbegin = std::distance( - other.bs_.begin(), other.begin_); - bs_ = other.bs_; - begin_ = std::next(bs_.begin(), nbegin); - skip_ = other.skip_; - return *this; -} - -template -inline -auto -consuming_buffers:: -begin() const -> - const_iterator -{ - return const_iterator{*this, begin_}; -} - -template -inline -auto -consuming_buffers:: -end() const -> - const_iterator -{ - return const_iterator{*this, bs_.end()}; -} - -template -void -consuming_buffers:: -consume(std::size_t n) -{ - using boost::asio::buffer_size; - for(;n > 0 && begin_ != bs_.end(); ++begin_) - { - auto const len = - buffer_size(*begin_) - skip_; - if(n < len) - { - skip_ += n; - break; - } - n -= len; - skip_ = 0; - } -} - -} // beast - -#endif diff --git a/src/beast/include/beast/core/impl/file_posix.ipp b/src/beast/include/beast/core/impl/file_posix.ipp deleted file mode 100644 index f0a7279bb63..00000000000 --- a/src/beast/include/beast/core/impl/file_posix.ipp +++ /dev/null @@ -1,331 +0,0 @@ -// -// Copyright (c) 2015-2016 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_CORE_IMPL_FILE_POSIX_IPP -#define BEAST_CORE_IMPL_FILE_POSIX_IPP - -#include -#include -#include -#include -#include -#include -#include - -namespace beast { - -namespace detail { - -inline -int -file_posix_close(int fd) -{ - for(;;) - { - if(! ::close(fd)) - break; - int const ev = errno; - if(errno != EINTR) - return ev; - } - return 0; -} - -} // detail - -inline -file_posix:: -~file_posix() -{ - if(fd_ != -1) - detail::file_posix_close(fd_); -} - -inline -file_posix:: -file_posix(file_posix&& other) - : fd_(other.fd_) -{ - other.fd_ = -1; -} - -inline -file_posix& -file_posix:: -operator=(file_posix&& other) -{ - if(&other == this) - return *this; - if(fd_ != -1) - detail::file_posix_close(fd_); - fd_ = other.fd_; - other.fd_ = -1; - return *this; -} - -inline -void -file_posix:: -native_handle(native_handle_type fd) -{ - if(fd_ != -1) - detail::file_posix_close(fd_); - fd_ = fd; -} - -inline -void -file_posix:: -close(error_code& ec) -{ - if(fd_ != -1) - { - auto const ev = - detail::file_posix_close(fd_); - if(ev) - ec.assign(ev, generic_category()); - else - ec.assign(0, ec.category()); - fd_ = -1; - } - else - { - ec.assign(0, ec.category()); - } -} - -inline -void -file_posix:: -open(char const* path, file_mode mode, error_code& ec) -{ - if(fd_ != -1) - { - auto const ev = - detail::file_posix_close(fd_); - if(ev) - ec.assign(ev, generic_category()); - else - ec.assign(0, ec.category()); - fd_ = -1; - } - int f = 0; -#ifndef __APPLE__ - int advise = 0; -#endif - switch(mode) - { - default: - case file_mode::read: - f = O_RDONLY; - #ifndef __APPLE__ - advise = POSIX_FADV_RANDOM; - #endif - break; - case file_mode::scan: - f = O_RDONLY; - #ifndef __APPLE__ - advise = POSIX_FADV_SEQUENTIAL; - #endif - break; - - case file_mode::write: - f = O_RDWR | O_CREAT | O_TRUNC; - #ifndef __APPLE__ - advise = POSIX_FADV_RANDOM; - #endif - break; - - case file_mode::write_new: - f = O_RDWR | O_CREAT | O_EXCL; - #ifndef __APPLE__ - advise = POSIX_FADV_RANDOM; - #endif - break; - - case file_mode::write_existing: - f = O_RDWR | O_EXCL; - #ifndef __APPLE__ - advise = POSIX_FADV_RANDOM; - #endif - break; - - case file_mode::append: - f = O_RDWR | O_CREAT | O_TRUNC; - #ifndef __APPLE__ - advise = POSIX_FADV_SEQUENTIAL; - #endif - break; - - case file_mode::append_new: - f = O_RDWR | O_CREAT | O_EXCL; - #ifndef __APPLE__ - advise = POSIX_FADV_SEQUENTIAL; - #endif - break; - - case file_mode::append_existing: - f = O_RDWR | O_EXCL; - #ifndef __APPLE__ - advise = POSIX_FADV_SEQUENTIAL; - #endif - break; - } - for(;;) - { - fd_ = ::open(path, f, 0644); - if(fd_ != -1) - break; - auto const ev = errno; - if(ev != EINTR) - { - ec.assign(ev, generic_category()); - return; - } - } -#ifndef __APPLE__ - if(::posix_fadvise(fd_, 0, 0, advise)) - { - auto const ev = errno; - detail::file_posix_close(fd_); - fd_ = -1; - ec.assign(ev, generic_category()); - return; - } -#endif - ec.assign(0, ec.category()); -} - -inline -std::uint64_t -file_posix:: -size(error_code& ec) const -{ - if(fd_ == -1) - { - ec.assign(errc::invalid_argument, generic_category()); - return 0; - } - struct stat st; - if(::fstat(fd_, &st) != 0) - { - ec.assign(errno, generic_category()); - return 0; - } - ec.assign(0, ec.category()); - return st.st_size; -} - -inline -std::uint64_t -file_posix:: -pos(error_code& ec) const -{ - if(fd_ == -1) - { - ec.assign(errc::invalid_argument, generic_category()); - return 0; - } - auto const result = ::lseek(fd_, 0, SEEK_CUR); - if(result == (off_t)-1) - { - ec.assign(errno, generic_category()); - return 0; - } - ec.assign(0, ec.category()); - return result; -} - -inline -void -file_posix:: -seek(std::uint64_t offset, error_code& ec) -{ - if(fd_ == -1) - { - ec.assign(errc::invalid_argument, generic_category()); - return; - } - auto const result = ::lseek(fd_, offset, SEEK_SET); - if(result == static_cast(-1)) - { - ec.assign(errno, generic_category()); - return; - } - ec.assign(0, ec.category()); -} - -inline -std::size_t -file_posix:: -read(void* buffer, std::size_t n, error_code& ec) const -{ - if(fd_ == -1) - { - ec.assign(errc::invalid_argument, generic_category()); - return 0; - } - std::size_t nread = 0; - while(n > 0) - { - auto const amount = static_cast((std::min)( - n, static_cast(SSIZE_MAX))); - auto const result = ::read(fd_, buffer, amount); - if(result == -1) - { - auto const ev = errno; - if(ev == EINTR) - continue; - ec.assign(ev, generic_category()); - return nread; - } - if(result == 0) - { - // short read - return nread; - } - n -= result; - nread += result; - buffer = reinterpret_cast(buffer) + result; - } - return nread; -} - -inline -std::size_t -file_posix:: -write(void const* buffer, std::size_t n, error_code& ec) -{ - if(fd_ == -1) - { - ec.assign(errc::invalid_argument, generic_category()); - return 0; - } - std::size_t nwritten = 0; - while(n > 0) - { - auto const amount = static_cast((std::min)( - n, static_cast(SSIZE_MAX))); - auto const result = ::write(fd_, buffer, amount); - if(result == -1) - { - auto const ev = errno; - if(ev == EINTR) - continue; - ec.assign(ev, generic_category()); - return nwritten; - } - n -= result; - nwritten += result; - buffer = reinterpret_cast(buffer) + result; - } - return nwritten; -} - -} // beast - -#endif diff --git a/src/beast/include/beast/core/impl/file_stdio.ipp b/src/beast/include/beast/core/impl/file_stdio.ipp deleted file mode 100644 index 1738e48daad..00000000000 --- a/src/beast/include/beast/core/impl/file_stdio.ipp +++ /dev/null @@ -1,225 +0,0 @@ -// -// Copyright (c) 2015-2016 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_CORE_IMPL_FILE_STDIO_IPP -#define BEAST_CORE_IMPL_FILE_STDIO_IPP - -#include - -namespace beast { - -inline -file_stdio:: -~file_stdio() -{ - if(f_) - fclose(f_); -} - -inline -file_stdio:: -file_stdio(file_stdio&& other) - : f_(other.f_) -{ - other.f_ = nullptr; -} - -inline -file_stdio& -file_stdio:: -operator=(file_stdio&& other) -{ - if(&other == this) - return *this; - if(f_) - fclose(f_); - f_ = other.f_; - other.f_ = nullptr; - return *this; -} - -inline -void -file_stdio:: -native_handle(FILE* f) -{ - if(f_) - fclose(f_); - f_ = f; -} - -inline -void -file_stdio:: -close(error_code& ec) -{ - if(f_) - { - int failed = fclose(f_); - f_ = nullptr; - if(failed) - { - ec.assign(errno, generic_category()); - return; - } - } - ec.assign(0, ec.category()); -} - -inline -void -file_stdio:: -open(char const* path, file_mode mode, error_code& ec) -{ - if(f_) - { - fclose(f_); - f_ = nullptr; - } - char const* s; - switch(mode) - { - default: - case file_mode::read: s = "rb"; break; - case file_mode::scan: s = "rb"; break; - case file_mode::write: s = "wb"; break; - case file_mode::write_new: s = "wbx"; break; - case file_mode::write_existing: s = "wb"; break; - case file_mode::append: s = "ab"; break; - case file_mode::append_new: s = "abx"; break; - case file_mode::append_existing: s = "ab"; break; - } - f_ = std::fopen(path, s); - if(! f_) - { - ec.assign(errno, generic_category()); - return; - } - ec.assign(0, ec.category()); -} - -inline -std::uint64_t -file_stdio:: -size(error_code& ec) const -{ - if(! f_) - { - ec.assign(errc::invalid_argument, generic_category()); - return 0; - } - long pos = std::ftell(f_); - if(pos == -1L) - { - ec.assign(errno, generic_category()); - return 0; - } - int result = std::fseek(f_, 0, SEEK_END); - if(result != 0) - { - ec.assign(errno, generic_category()); - return 0; - } - long size = std::ftell(f_); - if(size == -1L) - { - ec.assign(errno, generic_category()); - std::fseek(f_, pos, SEEK_SET); - return 0; - } - result = std::fseek(f_, pos, SEEK_SET); - if(result != 0) - ec.assign(errno, generic_category()); - else - ec.assign(0, ec.category()); - return size; -} - -inline -std::uint64_t -file_stdio:: -pos(error_code& ec) const -{ - if(! f_) - { - ec.assign(errc::invalid_argument, generic_category()); - return 0; - } - long pos = std::ftell(f_); - if(pos == -1L) - { - ec.assign(errno, generic_category()); - return 0; - } - ec.assign(0, ec.category()); - return pos; -} - -inline -void -file_stdio:: -seek(std::uint64_t offset, error_code& ec) -{ - if(! f_) - { - ec.assign(errc::invalid_argument, generic_category()); - return; - } - if(offset > (std::numeric_limits::max)()) - { - ec = make_error_code(errc::invalid_seek); - return; - } - int result = std::fseek(f_, - static_cast(offset), SEEK_SET); - if(result != 0) - ec.assign(errno, generic_category()); - else - ec.assign(0, ec.category()); -} - -inline -std::size_t -file_stdio:: -read(void* buffer, std::size_t n, error_code& ec) const -{ - if(! f_) - { - ec.assign(errc::invalid_argument, generic_category()); - return 0; - } - auto nread = std::fread(buffer, 1, n, f_); - if(std::ferror(f_)) - { - ec.assign(errno, generic_category()); - return 0; - } - return nread; -} - -inline -std::size_t -file_stdio:: -write(void const* buffer, std::size_t n, error_code& ec) -{ - if(! f_) - { - ec.assign(errc::invalid_argument, generic_category()); - return 0; - } - auto nwritten = std::fwrite(buffer, 1, n, f_); - if(std::ferror(f_)) - { - ec.assign(errno, generic_category()); - return 0; - } - return nwritten; -} - -} // beast - -#endif diff --git a/src/beast/include/beast/core/impl/file_win32.ipp b/src/beast/include/beast/core/impl/file_win32.ipp deleted file mode 100644 index 5b7a16470ff..00000000000 --- a/src/beast/include/beast/core/impl/file_win32.ipp +++ /dev/null @@ -1,356 +0,0 @@ -// -// Copyright (c) 2015-2016 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_CORE_IMPL_FILE_WIN32_IPP -#define BEAST_CORE_IMPL_FILE_WIN32_IPP - -#include -#include -#include -#include -#include -#include - -namespace beast { - -namespace detail { - -// VFALCO Can't seem to get boost/detail/winapi to work with -// this so use the non-Ex version for now. -inline -boost::detail::winapi::BOOL_ -set_file_pointer_ex( - boost::detail::winapi::HANDLE_ hFile, - boost::detail::winapi::LARGE_INTEGER_ lpDistanceToMove, - boost::detail::winapi::PLARGE_INTEGER_ lpNewFilePointer, - boost::detail::winapi::DWORD_ dwMoveMethod) -{ - auto dwHighPart = lpDistanceToMove.u.HighPart; - auto dwLowPart = boost::detail::winapi::SetFilePointer( - hFile, - lpDistanceToMove.u.LowPart, - &dwHighPart, - dwMoveMethod); - if(dwLowPart == boost::detail::winapi::INVALID_SET_FILE_POINTER_) - return 0; - if(lpNewFilePointer) - { - lpNewFilePointer->u.LowPart = dwLowPart; - lpNewFilePointer->u.HighPart = dwHighPart; - } - return 1; -} - -} // detail - -inline -file_win32:: -~file_win32() -{ - if(h_ != boost::detail::winapi::INVALID_HANDLE_VALUE_) - boost::detail::winapi::CloseHandle(h_); -} - -inline -file_win32:: -file_win32(file_win32&& other) - : h_(other.h_) -{ - other.h_ = boost::detail::winapi::INVALID_HANDLE_VALUE_; -} - -inline -file_win32& -file_win32:: -operator=(file_win32&& other) -{ - if(&other == this) - return *this; - if(h_) - boost::detail::winapi::CloseHandle(h_); - h_ = other.h_; - other.h_ = boost::detail::winapi::INVALID_HANDLE_VALUE_; - return *this; -} - -inline -void -file_win32:: -native_handle(native_handle_type h) -{ - if(h_ != boost::detail::winapi::INVALID_HANDLE_VALUE_) - boost::detail::winapi::CloseHandle(h_); - h_ = h; -} - -inline -void -file_win32:: -close(error_code& ec) -{ - if(h_ != boost::detail::winapi::INVALID_HANDLE_VALUE_) - { - if(! boost::detail::winapi::CloseHandle(h_)) - ec.assign(boost::detail::winapi::GetLastError(), - system_category()); - else - ec.assign(0, ec.category()); - h_ = boost::detail::winapi::INVALID_HANDLE_VALUE_; - } - else - { - ec.assign(0, ec.category()); - } -} - -inline -void -file_win32:: -open(char const* path, file_mode mode, error_code& ec) -{ - if(h_ != boost::detail::winapi::INVALID_HANDLE_VALUE_) - { - boost::detail::winapi::CloseHandle(h_); - h_ = boost::detail::winapi::INVALID_HANDLE_VALUE_; - } - boost::detail::winapi::DWORD_ dw1 = 0; - boost::detail::winapi::DWORD_ dw2 = 0; - boost::detail::winapi::DWORD_ dw3 = 0; -/* - | When the file... - This argument: | Exists Does not exist - -------------------------+------------------------------------------------------ - CREATE_ALWAYS | Truncates Creates - CREATE_NEW +-----------+ Fails Creates - OPEN_ALWAYS ===| does this |===> Opens Creates - OPEN_EXISTING +-----------+ Opens Fails - TRUNCATE_EXISTING | Truncates Fails -*/ - switch(mode) - { - default: - case file_mode::read: - dw1 = boost::detail::winapi::GENERIC_READ_; - dw2 = boost::detail::winapi::OPEN_EXISTING_; - dw3 = 0x10000000; // FILE_FLAG_RANDOM_ACCESS - break; - - case file_mode::scan: - dw1 = boost::detail::winapi::GENERIC_READ_; - dw2 = boost::detail::winapi::OPEN_EXISTING_; - dw3 = 0x08000000; // FILE_FLAG_SEQUENTIAL_SCAN - break; - - case file_mode::write: - dw1 = boost::detail::winapi::GENERIC_READ_ | - boost::detail::winapi::GENERIC_WRITE_; - dw2 = boost::detail::winapi::CREATE_ALWAYS_; - dw3 = 0x10000000; // FILE_FLAG_RANDOM_ACCESS - break; - - case file_mode::write_new: - dw1 = boost::detail::winapi::GENERIC_READ_ | - boost::detail::winapi::GENERIC_WRITE_; - dw2 = boost::detail::winapi::CREATE_NEW_; - dw3 = 0x10000000; // FILE_FLAG_RANDOM_ACCESS - break; - - case file_mode::write_existing: - dw1 = boost::detail::winapi::GENERIC_READ_ | - boost::detail::winapi::GENERIC_WRITE_; - dw2 = boost::detail::winapi::OPEN_EXISTING_; - dw3 = 0x10000000; // FILE_FLAG_RANDOM_ACCESS - break; - - case file_mode::append: - dw1 = boost::detail::winapi::GENERIC_READ_ | - boost::detail::winapi::GENERIC_WRITE_; - dw2 = boost::detail::winapi::CREATE_ALWAYS_; - dw3 = 0x08000000; // FILE_FLAG_SEQUENTIAL_SCAN - break; - - case file_mode::append_new: - dw1 = boost::detail::winapi::GENERIC_READ_ | - boost::detail::winapi::GENERIC_WRITE_; - dw2 = boost::detail::winapi::CREATE_NEW_; - dw3 = 0x08000000; // FILE_FLAG_SEQUENTIAL_SCAN - break; - - case file_mode::append_existing: - dw1 = boost::detail::winapi::GENERIC_READ_ | - boost::detail::winapi::GENERIC_WRITE_; - dw2 = boost::detail::winapi::OPEN_EXISTING_; - dw3 = 0x08000000; // FILE_FLAG_SEQUENTIAL_SCAN - break; - } - h_ = ::CreateFileA( - path, - dw1, - 0, - NULL, - dw2, - dw3, - NULL); - if(h_ == boost::detail::winapi::INVALID_HANDLE_VALUE_) - ec.assign(boost::detail::winapi::GetLastError(), - system_category()); - else - ec.assign(0, ec.category()); -} - -inline -std::uint64_t -file_win32:: -size(error_code& ec) const -{ - if(h_ == boost::detail::winapi::INVALID_HANDLE_VALUE_) - { - ec.assign(errc::invalid_argument, generic_category()); - return 0; - } - boost::detail::winapi::LARGE_INTEGER_ fileSize; - if(! boost::detail::winapi::GetFileSizeEx(h_, &fileSize)) - { - ec.assign(boost::detail::winapi::GetLastError(), - system_category()); - return 0; - } - ec.assign(0, ec.category()); - return fileSize.QuadPart; -} - -inline -std::uint64_t -file_win32:: -pos(error_code& ec) -{ - if(h_ == boost::detail::winapi::INVALID_HANDLE_VALUE_) - { - ec.assign(errc::invalid_argument, generic_category()); - return 0; - } - boost::detail::winapi::LARGE_INTEGER_ in; - boost::detail::winapi::LARGE_INTEGER_ out; - in.QuadPart = 0; - if(! detail::set_file_pointer_ex(h_, in, &out, - boost::detail::winapi::FILE_CURRENT_)) - { - ec.assign(boost::detail::winapi::GetLastError(), - system_category()); - return 0; - } - ec.assign(0, ec.category()); - return out.QuadPart; -} - -inline -void -file_win32:: -seek(std::uint64_t offset, error_code& ec) -{ - if(h_ == boost::detail::winapi::INVALID_HANDLE_VALUE_) - { - ec.assign(errc::invalid_argument, generic_category()); - return; - } - boost::detail::winapi::LARGE_INTEGER_ in; - in.QuadPart = offset; - if(! detail::set_file_pointer_ex(h_, in, 0, - boost::detail::winapi::FILE_BEGIN_)) - { - ec.assign(boost::detail::winapi::GetLastError(), - system_category()); - return; - } - ec.assign(0, ec.category()); -} - -inline -std::size_t -file_win32:: -read(void* buffer, std::size_t n, error_code& ec) -{ - if(h_ == boost::detail::winapi::INVALID_HANDLE_VALUE_) - { - ec.assign(errc::invalid_argument, generic_category()); - return 0; - } - std::size_t nread = 0; - while(n > 0) - { - boost::detail::winapi::DWORD_ amount; - if(n > (std::numeric_limits< - boost::detail::winapi::DWORD_>::max)()) - amount = (std::numeric_limits< - boost::detail::winapi::DWORD_>::max)(); - else - amount = static_cast< - boost::detail::winapi::DWORD_>(n); - boost::detail::winapi::DWORD_ bytesRead; - if(! ::ReadFile(h_, buffer, amount, &bytesRead, 0)) - { - auto const dwError = ::GetLastError(); - if(dwError != boost::detail::winapi::ERROR_HANDLE_EOF_) - ec.assign(::GetLastError(), system_category()); - else - ec.assign(0, ec.category()); - return nread; - } - if(bytesRead == 0) - return nread; - n -= bytesRead; - nread += bytesRead; - buffer = reinterpret_cast(buffer) + bytesRead; - } - ec.assign(0, ec.category()); - return nread; -} - -inline -std::size_t -file_win32:: -write(void const* buffer, std::size_t n, error_code& ec) -{ - if(h_ == boost::detail::winapi::INVALID_HANDLE_VALUE_) - { - ec.assign(errc::invalid_argument, generic_category()); - return 0; - } - std::size_t nwritten = 0; - while(n > 0) - { - boost::detail::winapi::DWORD_ amount; - if(n > (std::numeric_limits< - boost::detail::winapi::DWORD_>::max)()) - amount = (std::numeric_limits< - boost::detail::winapi::DWORD_>::max)(); - else - amount = static_cast< - boost::detail::winapi::DWORD_>(n); - boost::detail::winapi::DWORD_ bytesWritten; - if(! ::WriteFile(h_, buffer, amount, &bytesWritten, 0)) - { - auto const dwError = ::GetLastError(); - if(dwError != boost::detail::winapi::ERROR_HANDLE_EOF_) - ec.assign(::GetLastError(), system_category()); - else - ec.assign(0, ec.category()); - return nwritten; - } - if(bytesWritten == 0) - return nwritten; - n -= bytesWritten; - nwritten += bytesWritten; - buffer = reinterpret_cast(buffer) + bytesWritten; - } - ec.assign(0, ec.category()); - return nwritten; -} - -} // beast - -#endif diff --git a/src/beast/include/beast/core/impl/flat_buffer.ipp b/src/beast/include/beast/core/impl/flat_buffer.ipp deleted file mode 100644 index b7a938ed1d7..00000000000 --- a/src/beast/include/beast/core/impl/flat_buffer.ipp +++ /dev/null @@ -1,471 +0,0 @@ -// -// Copyright (c) 2013-2016 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_IMPL_FLAT_BUFFER_HPP -#define BEAST_IMPL_FLAT_BUFFER_HPP - -#include -#include -#include - -namespace beast { - -/* Memory is laid out thusly: - - begin_ ..|.. in_ ..|.. out_ ..|.. last_ ..|.. end_ -*/ - -template -basic_flat_buffer:: -~basic_flat_buffer() -{ - if(begin_) - alloc_traits::deallocate( - this->member(), begin_, dist(begin_, end_)); -} - -template -basic_flat_buffer:: -basic_flat_buffer() - : begin_(nullptr) - , in_(nullptr) - , out_(nullptr) - , last_(nullptr) - , end_(nullptr) - , max_((std::numeric_limits::max)()) -{ -} - -template -basic_flat_buffer:: -basic_flat_buffer(std::size_t limit) - : begin_(nullptr) - , in_(nullptr) - , out_(nullptr) - , last_(nullptr) - , end_(nullptr) - , max_(limit) -{ -} - -template -basic_flat_buffer:: -basic_flat_buffer(Allocator const& alloc) - : detail::empty_base_optimization(alloc) - , begin_(nullptr) - , in_(nullptr) - , out_(nullptr) - , last_(nullptr) - , end_(nullptr) - , max_((std::numeric_limits::max)()) -{ -} - -template -basic_flat_buffer:: -basic_flat_buffer(std::size_t limit, Allocator const& alloc) - : detail::empty_base_optimization(alloc) - , begin_(nullptr) - , in_(nullptr) - , out_(nullptr) - , last_(nullptr) - , end_(nullptr) - , max_(limit) -{ -} - -template -basic_flat_buffer:: -basic_flat_buffer(basic_flat_buffer&& other) - : detail::empty_base_optimization( - std::move(other.member())) - , begin_(other.begin_) - , in_(other.in_) - , out_(other.out_) - , last_(out_) - , end_(other.end_) - , max_(other.max_) -{ - other.begin_ = nullptr; - other.in_ = nullptr; - other.out_ = nullptr; - other.last_ = nullptr; - other.end_ = nullptr; -} - -template -basic_flat_buffer:: -basic_flat_buffer(basic_flat_buffer&& other, - Allocator const& alloc) - : detail::empty_base_optimization(alloc) -{ - if(this->member() != other.member()) - { - begin_ = nullptr; - in_ = nullptr; - out_ = nullptr; - last_ = nullptr; - end_ = nullptr; - max_ = other.max_; - copy_from(other); - other.reset(); - } - else - { - begin_ = other.begin_; - in_ = other.in_; - out_ = other.out_; - last_ = out_; - end_ = other.end_; - max_ = other.max_; - other.begin_ = nullptr; - other.in_ = nullptr; - other.out_ = nullptr; - other.last_ = nullptr; - other.end_ = nullptr; - } -} - -template -basic_flat_buffer:: -basic_flat_buffer(basic_flat_buffer const& other) - : detail::empty_base_optimization( - alloc_traits::select_on_container_copy_construction( - other.member())) - , begin_(nullptr) - , in_(nullptr) - , out_(nullptr) - , last_(nullptr) - , end_(nullptr) - , max_(other.max_) -{ - copy_from(other); -} - -template -basic_flat_buffer:: -basic_flat_buffer(basic_flat_buffer const& other, - Allocator const& alloc) - : detail::empty_base_optimization(alloc) - , begin_(nullptr) - , in_(nullptr) - , out_(nullptr) - , last_(nullptr) - , end_(nullptr) - , max_(other.max_) -{ - copy_from(other); -} - -template -template -basic_flat_buffer:: -basic_flat_buffer( - basic_flat_buffer const& other) - : begin_(nullptr) - , in_(nullptr) - , out_(nullptr) - , last_(nullptr) - , end_(nullptr) - , max_(other.max_) -{ - copy_from(other); -} - -template -template -basic_flat_buffer:: -basic_flat_buffer(basic_flat_buffer const& other, - Allocator const& alloc) - : detail::empty_base_optimization(alloc) - , begin_(nullptr) - , in_(nullptr) - , out_(nullptr) - , last_(nullptr) - , end_(nullptr) - , max_(other.max_) -{ - copy_from(other); -} - -template -auto -basic_flat_buffer:: -operator=(basic_flat_buffer&& other) -> - basic_flat_buffer& -{ - if(this != &other) - move_assign(other, - typename alloc_traits::propagate_on_container_move_assignment{}); - return *this; -} - -template -auto -basic_flat_buffer:: -operator=(basic_flat_buffer const& other) -> - basic_flat_buffer& -{ - if(this != &other) - copy_assign(other, - typename alloc_traits::propagate_on_container_copy_assignment{}); - return *this; -} - -template -template -auto -basic_flat_buffer:: -operator=(basic_flat_buffer const& other) -> - basic_flat_buffer& -{ - reset(); - max_ = other.max_; - copy_from(other); - return *this; -} - -//------------------------------------------------------------------------------ - -template -auto -basic_flat_buffer:: -prepare(std::size_t n) -> - mutable_buffers_type -{ - if(n <= dist(out_, end_)) - { - // existing capacity is sufficient - last_ = out_ + n; - return{out_, n}; - } - auto const len = size(); - if(n <= capacity() - len) - { - // after a memmove, - // existing capacity is sufficient - if(len > 0) - std::memmove(begin_, in_, len); - in_ = begin_; - out_ = in_ + len; - last_ = out_ + n; - return {out_, n}; - } - // enforce maximum capacity - if(n > max_ - len) - BOOST_THROW_EXCEPTION(std::length_error{ - "basic_flat_buffer overflow"}); - // allocate a new buffer - auto const new_size = std::min( - max_, - std::max(2 * len, len + n)); - auto const p = alloc_traits::allocate( - this->member(), new_size); - if(begin_) - { - BOOST_ASSERT(p); - BOOST_ASSERT(in_); - std::memcpy(p, in_, len); - alloc_traits::deallocate( - this->member(), begin_, capacity()); - } - begin_ = p; - in_ = begin_; - out_ = in_ + len; - last_ = out_ + n; - end_ = begin_ + new_size; - return {out_, n}; -} - -template -void -basic_flat_buffer:: -consume(std::size_t n) -{ - if(n >= dist(in_, out_)) - { - in_ = begin_; - out_ = begin_; - return; - } - in_ += n; -} - -template -void -basic_flat_buffer:: -shrink_to_fit() -{ - auto const len = size(); - if(len == capacity()) - return; - char* p; - if(len > 0) - { - BOOST_ASSERT(begin_); - BOOST_ASSERT(in_); - p = alloc_traits::allocate( - this->member(), len); - std::memcpy(p, in_, len); - } - else - { - p = nullptr; - } - alloc_traits::deallocate( - this->member(), begin_, dist(begin_, end_)); - begin_ = p; - in_ = begin_; - out_ = begin_ + len; - last_ = out_; - end_ = out_; -} - -//------------------------------------------------------------------------------ - -template -inline -void -basic_flat_buffer:: -reset() -{ - consume(size()); - shrink_to_fit(); -} - -template -template -inline -void -basic_flat_buffer:: -copy_from(DynamicBuffer const& buffer) -{ - if(buffer.size() == 0) - return; - using boost::asio::buffer_copy; - commit(buffer_copy( - prepare(buffer.size()), buffer.data())); -} - -template -inline -void -basic_flat_buffer:: -move_assign(basic_flat_buffer& other, std::true_type) -{ - reset(); - this->member() = std::move(other.member()); - begin_ = other.begin_; - in_ = other.in_; - out_ = other.out_; - last_ = out_; - end_ = other.end_; - max_ = other.max_; - other.begin_ = nullptr; - other.in_ = nullptr; - other.out_ = nullptr; - other.last_ = nullptr; - other.end_ = nullptr; -} - -template -inline -void -basic_flat_buffer:: -move_assign(basic_flat_buffer& other, std::false_type) -{ - reset(); - if(this->member() != other.member()) - { - copy_from(other); - other.reset(); - } - else - { - move_assign(other, std::true_type{}); - } -} - -template -inline -void -basic_flat_buffer:: -copy_assign(basic_flat_buffer const& other, std::true_type) -{ - reset(); - max_ = other.max_; - this->member() = other.member(); - copy_from(other); -} - -template -inline -void -basic_flat_buffer:: -copy_assign(basic_flat_buffer const& other, std::false_type) -{ - reset(); - max_ = other.max_; - copy_from(other); -} - -template -inline -void -basic_flat_buffer:: -swap(basic_flat_buffer& other) -{ - swap(other, typename - alloc_traits::propagate_on_container_swap{}); -} - -template -inline -void -basic_flat_buffer:: -swap(basic_flat_buffer& other, std::true_type) -{ - using std::swap; - swap(this->member(), other.member()); - swap(max_, other.max_); - swap(begin_, other.begin_); - swap(in_, other.in_); - swap(out_, other.out_); - last_ = this->out_; - other.last_ = other.out_; - swap(end_, other.end_); -} - -template -inline -void -basic_flat_buffer:: -swap(basic_flat_buffer& other, std::false_type) -{ - BOOST_ASSERT(this->member() == other.member()); - using std::swap; - swap(max_, other.max_); - swap(begin_, other.begin_); - swap(in_, other.in_); - swap(out_, other.out_); - last_ = this->out_; - other.last_ = other.out_; - swap(end_, other.end_); -} - -template -void -swap( - basic_flat_buffer& lhs, - basic_flat_buffer& rhs) -{ - lhs.swap(rhs); -} - -} // beast - -#endif diff --git a/src/beast/include/beast/core/impl/handler_ptr.ipp b/src/beast/include/beast/core/impl/handler_ptr.ipp deleted file mode 100644 index a882acf9db6..00000000000 --- a/src/beast/include/beast/core/impl/handler_ptr.ipp +++ /dev/null @@ -1,133 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_IMPL_HANDLER_PTR_HPP -#define BEAST_IMPL_HANDLER_PTR_HPP - -#include -#include -#include -#include -#include - -namespace beast { - -template -template -inline -handler_ptr::P:: -P(DeducedHandler&& h, Args&&... args) - : n(1) - , handler(std::forward(h)) -{ - using boost::asio::asio_handler_allocate; - t = reinterpret_cast( - asio_handler_allocate( - sizeof(T), std::addressof(handler))); - try - { - t = new(t) T{handler, - std::forward(args)...}; - } - catch(...) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - t, sizeof(T), std::addressof(handler)); - throw; - } -} - -template -handler_ptr:: -~handler_ptr() -{ - if(! p_) - return; - if(--p_->n) - return; - if(p_->t) - { - p_->t->~T(); - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p_->t, sizeof(T), std::addressof(p_->handler)); - } - delete p_; -} - -template -handler_ptr:: -handler_ptr(handler_ptr&& other) - : p_(other.p_) -{ - other.p_ = nullptr; -} - -template -handler_ptr:: -handler_ptr(handler_ptr const& other) - : p_(other.p_) -{ - if(p_) - ++p_->n; -} - -template -template -handler_ptr:: -handler_ptr(Handler&& handler, Args&&... args) - : p_(new P{std::move(handler), - std::forward(args)...}) -{ - BOOST_STATIC_ASSERT(! std::is_array::value); -} - -template -template -handler_ptr:: -handler_ptr(Handler const& handler, Args&&... args) - : p_(new P{handler, std::forward(args)...}) -{ - BOOST_STATIC_ASSERT(! std::is_array::value); -} - -template -auto -handler_ptr:: -release_handler() -> - handler_type -{ - BOOST_ASSERT(p_); - BOOST_ASSERT(p_->t); - p_->t->~T(); - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p_->t, sizeof(T), std::addressof(p_->handler)); - p_->t = nullptr; - return std::move(p_->handler); -} - -template -template -void -handler_ptr:: -invoke(Args&&... args) -{ - BOOST_ASSERT(p_); - BOOST_ASSERT(p_->t); - p_->t->~T(); - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p_->t, sizeof(T), std::addressof(p_->handler)); - p_->t = nullptr; - p_->handler(std::forward(args)...); -} - -} // beast - -#endif diff --git a/src/beast/include/beast/core/impl/multi_buffer.ipp b/src/beast/include/beast/core/impl/multi_buffer.ipp deleted file mode 100644 index aed523a43c6..00000000000 --- a/src/beast/include/beast/core/impl/multi_buffer.ipp +++ /dev/null @@ -1,1051 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_IMPL_MULTI_BUFFER_IPP -#define BEAST_IMPL_MULTI_BUFFER_IPP - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { - -/* These diagrams illustrate the layout and state variables. - -1 Input and output contained entirely in one element: - - 0 out_ - |<-------------+------------------------------------------->| - in_pos_ out_pos_ out_end_ - - -2 Output contained in first and second elements: - - out_ - |<------+----------+------->| |<----------+-------------->| - in_pos_ out_pos_ out_end_ - - -3 Output contained in the second element: - - out_ - |<------------+------------>| |<----+-------------------->| - in_pos_ out_pos_ out_end_ - - -4 Output contained in second and third elements: - - out_ - |<-----+-------->| |<-------+------>| |<--------------->| - in_pos_ out_pos_ out_end_ - - -5 Input sequence is empty: - - out_ - |<------+------------------>| |<-----------+------------->| - out_pos_ out_end_ - in_pos_ - - -6 Output sequence is empty: - - out_ - |<------+------------------>| |<------+------------------>| - in_pos_ out_pos_ - out_end_ - - -7 The end of output can point to the end of an element. - But out_pos_ should never point to the end: - - out_ - |<------+------------------>| |<------+------------------>| - in_pos_ out_pos_ out_end_ - - -8 When the input sequence entirely fills the last element and - the output sequence is empty, out_ will point to the end of - the list of buffers, and out_pos_ and out_end_ will be 0: - - - |<------+------------------>| out_ == list_.end() - in_pos_ out_pos_ == 0 - out_end_ == 0 -*/ - -template -class basic_multi_buffer::element - : public boost::intrusive::list_base_hook< - boost::intrusive::link_mode< - boost::intrusive::normal_link>> -{ - using size_type = typename std::allocator_traits::size_type; - - size_type const size_; - -public: - element(element const&) = delete; - element& operator=(element const&) = delete; - - explicit - element(size_type n) - : size_(n) - { - } - - size_type - size() const - { - return size_; - } - - char* - data() const - { - return const_cast( - reinterpret_cast(this+1)); - } -}; - -template -class basic_multi_buffer::const_buffers_type -{ - basic_multi_buffer const* b_; - - friend class basic_multi_buffer; - - explicit - const_buffers_type(basic_multi_buffer const& b); - -public: - // Why? - using value_type = boost::asio::const_buffer; - - class const_iterator; - - const_buffers_type() = delete; - const_buffers_type(const_buffers_type const&) = default; - const_buffers_type& operator=(const_buffers_type const&) = default; - - const_iterator - begin() const; - - const_iterator - end() const; - - friend - std::size_t - buffer_size(const_buffers_type const& buffers) - { - return buffers.b_->size(); - } -}; - -template -class basic_multi_buffer::mutable_buffers_type -{ - basic_multi_buffer const* b_; - - friend class basic_multi_buffer; - - explicit - mutable_buffers_type(basic_multi_buffer const& b); - -public: - using value_type = mutable_buffer; - - class const_iterator; - - mutable_buffers_type() = delete; - mutable_buffers_type(mutable_buffers_type const&) = default; - mutable_buffers_type& operator=(mutable_buffers_type const&) = default; - - const_iterator - begin() const; - - const_iterator - end() const; -}; - -//------------------------------------------------------------------------------ - -template -class basic_multi_buffer::const_buffers_type::const_iterator -{ - basic_multi_buffer const* b_ = nullptr; - typename list_type::const_iterator it_; - -public: - using value_type = - typename const_buffers_type::value_type; - using pointer = value_type const*; - using reference = value_type; - using difference_type = std::ptrdiff_t; - using iterator_category = - std::bidirectional_iterator_tag; - - const_iterator() = default; - const_iterator(const_iterator&& other) = default; - const_iterator(const_iterator const& other) = default; - const_iterator& operator=(const_iterator&& other) = default; - const_iterator& operator=(const_iterator const& other) = default; - - const_iterator(basic_multi_buffer const& b, - typename list_type::const_iterator const& it) - : b_(&b) - , it_(it) - { - } - - bool - operator==(const_iterator const& other) const - { - return b_ == other.b_ && it_ == other.it_; - } - - bool - operator!=(const_iterator const& other) const - { - return !(*this == other); - } - - reference - operator*() const - { - auto const& e = *it_; - return value_type{e.data(), - (b_->out_ == b_->list_.end() || - &e != &*b_->out_) ? e.size() : b_->out_pos_} + - (&e == &*b_->list_.begin() ? b_->in_pos_ : 0); - } - - pointer - operator->() const = delete; - - const_iterator& - operator++() - { - ++it_; - return *this; - } - - const_iterator - operator++(int) - { - auto temp = *this; - ++(*this); - return temp; - } - - const_iterator& - operator--() - { - --it_; - return *this; - } - - const_iterator - operator--(int) - { - auto temp = *this; - --(*this); - return temp; - } -}; - -template -basic_multi_buffer:: -const_buffers_type:: -const_buffers_type( - basic_multi_buffer const& b) - : b_(&b) -{ -} - -template -auto -basic_multi_buffer:: -const_buffers_type:: -begin() const -> - const_iterator -{ - return const_iterator{*b_, b_->list_.begin()}; -} - -template -auto -basic_multi_buffer:: -const_buffers_type:: -end() const -> - const_iterator -{ - return const_iterator{*b_, b_->out_ == - b_->list_.end() ? b_->list_.end() : - std::next(b_->out_)}; -} - -//------------------------------------------------------------------------------ - -template -class basic_multi_buffer::mutable_buffers_type::const_iterator -{ - basic_multi_buffer const* b_ = nullptr; - typename list_type::const_iterator it_; - -public: - using value_type = - typename mutable_buffers_type::value_type; - using pointer = value_type const*; - using reference = value_type; - using difference_type = std::ptrdiff_t; - using iterator_category = - std::bidirectional_iterator_tag; - - const_iterator() = default; - const_iterator(const_iterator&& other) = default; - const_iterator(const_iterator const& other) = default; - const_iterator& operator=(const_iterator&& other) = default; - const_iterator& operator=(const_iterator const& other) = default; - - const_iterator(basic_multi_buffer const& b, - typename list_type::const_iterator const& it) - : b_(&b) - , it_(it) - { - } - - bool - operator==(const_iterator const& other) const - { - return b_ == other.b_ && it_ == other.it_; - } - - bool - operator!=(const_iterator const& other) const - { - return !(*this == other); - } - - reference - operator*() const - { - auto const& e = *it_; - return value_type{e.data(), - &e == &*std::prev(b_->list_.end()) ? - b_->out_end_ : e.size()} + - (&e == &*b_->out_ ? b_->out_pos_ : 0); - } - - pointer - operator->() const = delete; - - const_iterator& - operator++() - { - ++it_; - return *this; - } - - const_iterator - operator++(int) - { - auto temp = *this; - ++(*this); - return temp; - } - - const_iterator& - operator--() - { - --it_; - return *this; - } - - const_iterator - operator--(int) - { - auto temp = *this; - --(*this); - return temp; - } -}; - -template -basic_multi_buffer:: -mutable_buffers_type:: -mutable_buffers_type( - basic_multi_buffer const& b) - : b_(&b) -{ -} - -template -auto -basic_multi_buffer:: -mutable_buffers_type:: -begin() const -> - const_iterator -{ - return const_iterator{*b_, b_->out_}; -} - -template -auto -basic_multi_buffer:: -mutable_buffers_type:: -end() const -> - const_iterator -{ - return const_iterator{*b_, b_->list_.end()}; -} - -//------------------------------------------------------------------------------ - -template -basic_multi_buffer:: -~basic_multi_buffer() -{ - delete_list(); -} - -template -basic_multi_buffer:: -basic_multi_buffer() - : out_(list_.end()) -{ -} - -template -basic_multi_buffer:: -basic_multi_buffer(std::size_t limit) - : max_(limit) - , out_(list_.end()) -{ -} - -template -basic_multi_buffer:: -basic_multi_buffer(Allocator const& alloc) - : detail::empty_base_optimization< - allocator_type>(alloc) - , out_(list_.end()) -{ -} - -template -basic_multi_buffer:: -basic_multi_buffer(std::size_t limit, - Allocator const& alloc) - : detail::empty_base_optimization< - allocator_type>(alloc) - , max_(limit) - , out_(list_.end()) -{ -} - -template -basic_multi_buffer:: -basic_multi_buffer(basic_multi_buffer&& other) - : detail::empty_base_optimization( - std::move(other.member())) - , max_(other.max_) - , in_size_(other.in_size_) - , in_pos_(other.in_pos_) - , out_pos_(other.out_pos_) - , out_end_(other.out_end_) -{ - auto const at_end = - other.out_ == other.list_.end(); - list_ = std::move(other.list_); - out_ = at_end ? list_.end() : other.out_; - other.in_size_ = 0; - other.out_ = other.list_.end(); - other.in_pos_ = 0; - other.out_pos_ = 0; - other.out_end_ = 0; -} - -template -basic_multi_buffer:: -basic_multi_buffer(basic_multi_buffer&& other, - Allocator const& alloc) - : detail::empty_base_optimization(alloc) - , max_(other.max_) -{ - if(this->member() != other.member()) - { - out_ = list_.end(); - copy_from(other); - other.reset(); - } - else - { - auto const at_end = - other.out_ == other.list_.end(); - list_ = std::move(other.list_); - out_ = at_end ? list_.end() : other.out_; - in_size_ = other.in_size_; - in_pos_ = other.in_pos_; - out_pos_ = other.out_pos_; - out_end_ = other.out_end_; - other.in_size_ = 0; - other.out_ = other.list_.end(); - other.in_pos_ = 0; - other.out_pos_ = 0; - other.out_end_ = 0; - } -} - -template -basic_multi_buffer:: -basic_multi_buffer(basic_multi_buffer const& other) - : detail::empty_base_optimization( - alloc_traits::select_on_container_copy_construction(other.member())) - , max_(other.max_) - , out_(list_.end()) -{ - copy_from(other); -} - -template -basic_multi_buffer:: -basic_multi_buffer(basic_multi_buffer const& other, - Allocator const& alloc) - : detail::empty_base_optimization(alloc) - , max_(other.max_) - , out_(list_.end()) -{ - copy_from(other); -} - -template -template -basic_multi_buffer:: -basic_multi_buffer( - basic_multi_buffer const& other) - : out_(list_.end()) -{ - copy_from(other); -} - -template -template -basic_multi_buffer:: -basic_multi_buffer( - basic_multi_buffer const& other, - allocator_type const& alloc) - : detail::empty_base_optimization(alloc) - , max_(other.max_) - , out_(list_.end()) -{ - copy_from(other); -} - -template -auto -basic_multi_buffer:: -operator=(basic_multi_buffer&& other) -> - basic_multi_buffer& -{ - if(this == &other) - return *this; - reset(); - max_ = other.max_; - move_assign(other, typename - alloc_traits::propagate_on_container_move_assignment{}); - return *this; -} - -template -auto -basic_multi_buffer:: -operator=(basic_multi_buffer const& other) -> -basic_multi_buffer& -{ - if(this == &other) - return *this; - copy_assign(other, typename - alloc_traits::propagate_on_container_copy_assignment{}); - return *this; -} - -template -template -auto -basic_multi_buffer:: -operator=( - basic_multi_buffer const& other) -> - basic_multi_buffer& -{ - reset(); - max_ = other.max_; - copy_from(other); - return *this; -} - -template -std::size_t -basic_multi_buffer:: -capacity() const -{ - auto pos = out_; - if(pos == list_.end()) - return in_size_; - auto n = pos->size() - out_pos_; - while(++pos != list_.end()) - n += pos->size(); - return in_size_ + n; -} - -template -auto -basic_multi_buffer:: -data() const -> - const_buffers_type -{ - return const_buffers_type(*this); -} - -template -auto -basic_multi_buffer:: -prepare(size_type n) -> - mutable_buffers_type -{ - if(in_size_ + n > max_) - BOOST_THROW_EXCEPTION(std::length_error{ - "dynamic buffer overflow"}); - list_type reuse; - std::size_t total = in_size_; - // put all empty buffers on reuse list - if(out_ != list_.end()) - { - total += out_->size() - out_pos_; - if(out_ != list_.iterator_to(list_.back())) - { - out_end_ = out_->size(); - reuse.splice(reuse.end(), list_, - std::next(out_), list_.end()); - #if BEAST_MULTI_BUFFER_DEBUG_CHECK - debug_check(); - #endif - } - auto const avail = out_->size() - out_pos_; - if(n > avail) - { - out_end_ = out_->size(); - n -= avail; - } - else - { - out_end_ = out_pos_ + n; - n = 0; - } - #if BEAST_MULTI_BUFFER_DEBUG_CHECK - debug_check(); - #endif - } - // get space from reuse buffers - while(n > 0 && ! reuse.empty()) - { - auto& e = reuse.front(); - reuse.erase(reuse.iterator_to(e)); - list_.push_back(e); - total += e.size(); - if(n > e.size()) - { - out_end_ = e.size(); - n -= e.size(); - } - else - { - out_end_ = n; - n = 0; - } - #if BEAST_MULTI_BUFFER_DEBUG_CHECK - debug_check(); - #endif - } - BOOST_ASSERT(total <= max_); - for(auto it = reuse.begin(); it != reuse.end();) - { - auto& e = *it++; - reuse.erase(list_.iterator_to(e)); - delete_element(e); - } - if(n > 0) - { - static auto const growth_factor = 2.0f; - auto const size = - std::min( - max_ - total, - std::max({ - static_cast( - in_size_ * growth_factor - in_size_), - 512, - n})); - auto& e = *reinterpret_cast(static_cast< - void*>(alloc_traits::allocate(this->member(), - sizeof(element) + size))); - alloc_traits::construct(this->member(), &e, size); - list_.push_back(e); - if(out_ == list_.end()) - out_ = list_.iterator_to(e); - out_end_ = n; - #if BEAST_MULTI_BUFFER_DEBUG_CHECK - debug_check(); - #endif - } - return mutable_buffers_type(*this); -} - -template -void -basic_multi_buffer:: -commit(size_type n) -{ - if(list_.empty()) - return; - if(out_ == list_.end()) - return; - auto const back = - list_.iterator_to(list_.back()); - while(out_ != back) - { - auto const avail = - out_->size() - out_pos_; - if(n < avail) - { - out_pos_ += n; - in_size_ += n; - #if BEAST_MULTI_BUFFER_DEBUG_CHECK - debug_check(); - #endif - return; - } - ++out_; - n -= avail; - out_pos_ = 0; - in_size_ += avail; - #if BEAST_MULTI_BUFFER_DEBUG_CHECK - debug_check(); - #endif - } - - n = (std::min)(n, out_end_ - out_pos_); - out_pos_ += n; - in_size_ += n; - if(out_pos_ == out_->size()) - { - ++out_; - out_pos_ = 0; - out_end_ = 0; - } -#if BEAST_MULTI_BUFFER_DEBUG_CHECK - debug_check(); -#endif -} - -template -void -basic_multi_buffer:: -consume(size_type n) -{ - if(list_.empty()) - return; - for(;;) - { - if(list_.begin() != out_) - { - auto const avail = - list_.front().size() - in_pos_; - if(n < avail) - { - in_size_ -= n; - in_pos_ += n; - #if BEAST_MULTI_BUFFER_DEBUG_CHECK - debug_check(); - #endif - break; - } - n -= avail; - in_size_ -= avail; - in_pos_ = 0; - auto& e = list_.front(); - list_.erase(list_.iterator_to(e)); - delete_element(e); - #if BEAST_MULTI_BUFFER_DEBUG_CHECK - debug_check(); - #endif - } - else - { - auto const avail = out_pos_ - in_pos_; - if(n < avail) - { - in_size_ -= n; - in_pos_ += n; - } - else - { - in_size_ = 0; - if(out_ != list_.iterator_to(list_.back()) || - out_pos_ != out_end_) - { - in_pos_ = out_pos_; - } - else - { - // Input and output sequences are empty, reuse buffer. - // Alternatively we could deallocate it. - in_pos_ = 0; - out_pos_ = 0; - out_end_ = 0; - } - } - #if BEAST_MULTI_BUFFER_DEBUG_CHECK - debug_check(); - #endif - break; - } - } -} - -template -inline -void -basic_multi_buffer:: -delete_element(element& e) -{ - auto const len = sizeof(e) + e.size(); - alloc_traits::destroy(this->member(), &e); - alloc_traits::deallocate(this->member(), - reinterpret_cast(&e), len); -} - -template -inline -void -basic_multi_buffer:: -delete_list() -{ - for(auto iter = list_.begin(); iter != list_.end();) - delete_element(*iter++); -} - -template -inline -void -basic_multi_buffer:: -reset() -{ - delete_list(); - list_.clear(); - out_ = list_.end(); - in_size_ = 0; - in_pos_ = 0; - out_pos_ = 0; - out_end_ = 0; -} - -template -template -inline -void -basic_multi_buffer:: -copy_from(DynamicBuffer const& buffer) -{ - if(buffer.size() == 0) - return; - using boost::asio::buffer_copy; - commit(buffer_copy( - prepare(buffer.size()), buffer.data())); -} - -template -inline -void -basic_multi_buffer:: -move_assign(basic_multi_buffer& other, std::false_type) -{ - if(this->member() != other.member()) - { - copy_from(other); - other.reset(); - } - else - { - move_assign(other, std::true_type{}); - } -} - -template -inline -void -basic_multi_buffer:: -move_assign(basic_multi_buffer& other, std::true_type) -{ - this->member() = std::move(other.member()); - auto const at_end = - other.out_ == other.list_.end(); - list_ = std::move(other.list_); - out_ = at_end ? list_.end() : other.out_; - - in_size_ = other.in_size_; - in_pos_ = other.in_pos_; - out_pos_ = other.out_pos_; - out_end_ = other.out_end_; - - other.in_size_ = 0; - other.out_ = other.list_.end(); - other.in_pos_ = 0; - other.out_pos_ = 0; - other.out_end_ = 0; -} - -template -inline -void -basic_multi_buffer:: -copy_assign( - basic_multi_buffer const& other, std::false_type) -{ - reset(); - max_ = other.max_; - copy_from(other); -} - -template -inline -void -basic_multi_buffer:: -copy_assign( - basic_multi_buffer const& other, std::true_type) -{ - reset(); - max_ = other.max_; - this->member() = other.member(); - copy_from(other); -} - -template -inline -void -basic_multi_buffer:: -swap(basic_multi_buffer& other) -{ - swap(other, typename - alloc_traits::propagate_on_container_swap{}); -} - -template -inline -void -basic_multi_buffer:: -swap(basic_multi_buffer& other, std::true_type) -{ - using std::swap; - auto const at_end0 = - out_ == list_.end(); - auto const at_end1 = - other.out_ == other.list_.end(); - swap(this->member(), other.member()); - swap(list_, other.list_); - swap(out_, other.out_); - if(at_end1) - out_ = list_.end(); - if(at_end0) - other.out_ = other.list_.end(); - swap(in_size_, other.in_size_); - swap(in_pos_, other.in_pos_); - swap(out_pos_, other.out_pos_); - swap(out_end_, other.out_end_); -} - -template -inline -void -basic_multi_buffer:: -swap(basic_multi_buffer& other, std::false_type) -{ - BOOST_ASSERT(this->member() == other.member()); - using std::swap; - auto const at_end0 = - out_ == list_.end(); - auto const at_end1 = - other.out_ == other.list_.end(); - swap(list_, other.list_); - swap(out_, other.out_); - if(at_end1) - out_ = list_.end(); - if(at_end0) - other.out_ = other.list_.end(); - swap(in_size_, other.in_size_); - swap(in_pos_, other.in_pos_); - swap(out_pos_, other.out_pos_); - swap(out_end_, other.out_end_); -} - -template -void -swap( - basic_multi_buffer& lhs, - basic_multi_buffer& rhs) -{ - lhs.swap(rhs); -} - -template -void -basic_multi_buffer:: -debug_check() const -{ -#ifndef NDEBUG - using boost::asio::buffer_size; - BOOST_ASSERT(buffer_size(data()) == in_size_); - if(list_.empty()) - { - BOOST_ASSERT(in_pos_ == 0); - BOOST_ASSERT(in_size_ == 0); - BOOST_ASSERT(out_pos_ == 0); - BOOST_ASSERT(out_end_ == 0); - BOOST_ASSERT(out_ == list_.end()); - return; - } - - auto const& front = list_.front(); - - BOOST_ASSERT(in_pos_ < front.size()); - - if(out_ == list_.end()) - { - BOOST_ASSERT(out_pos_ == 0); - BOOST_ASSERT(out_end_ == 0); - } - else - { - auto const& out = *out_; - auto const& back = list_.back(); - - BOOST_ASSERT(out_end_ <= back.size()); - BOOST_ASSERT(out_pos_ < out.size()); - BOOST_ASSERT(&out != &front || out_pos_ >= in_pos_); - BOOST_ASSERT(&out != &front || out_pos_ - in_pos_ == in_size_); - BOOST_ASSERT(&out != &back || out_pos_ <= out_end_); - } -#endif -} - -} // beast - -#endif diff --git a/src/beast/include/beast/core/impl/read_size.ipp b/src/beast/include/beast/core/impl/read_size.ipp deleted file mode 100644 index 56bc81c758a..00000000000 --- a/src/beast/include/beast/core/impl/read_size.ipp +++ /dev/null @@ -1,75 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_IMPL_READ_SIZE_IPP -#define BEAST_IMPL_READ_SIZE_IPP - -namespace beast { - -namespace detail { - -template -struct has_read_size_helper : std::false_type {}; - -template -struct has_read_size_helper(), 512), - (void)0)> : std::true_type -{ -}; - -template -std::size_t -read_size(DynamicBuffer& buffer, - std::size_t max_size, std::true_type) -{ - return read_size_helper(buffer, max_size); -} - -template -std::size_t -read_size(DynamicBuffer& buffer, - std::size_t max_size, std::false_type) -{ - static_assert(is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - BOOST_ASSERT(max_size >= 1); - auto const size = buffer.size(); - auto const limit = buffer.max_size() - size; - BOOST_ASSERT(size <= buffer.max_size()); - return std::min( - std::max(512, buffer.capacity() - size), - std::min(max_size, limit)); -} - -} // detail - -template -inline -std::size_t -read_size( - DynamicBuffer& buffer, std::size_t max_size) -{ - return detail::read_size(buffer, max_size, - detail::has_read_size_helper{}); -} - -template -std::size_t -read_size_or_throw( - DynamicBuffer& buffer, std::size_t max_size) -{ - auto const n = read_size(buffer, max_size); - if(n == 0) - BOOST_THROW_EXCEPTION(std::length_error{ - "buffer overflow"}); - return n; -} - -} // beast - -#endif diff --git a/src/beast/include/beast/core/impl/static_buffer.ipp b/src/beast/include/beast/core/impl/static_buffer.ipp deleted file mode 100644 index 13652ca56f7..00000000000 --- a/src/beast/include/beast/core/impl/static_buffer.ipp +++ /dev/null @@ -1,129 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_IMPL_STATIC_BUFFER_IPP -#define BEAST_IMPL_STATIC_BUFFER_IPP - -#include -#include -#include -#include -#include -#include -#include - -namespace beast { - -/* Memory is laid out thusly: - - begin_ ..|.. in_ ..|.. out_ ..|.. last_ ..|.. end_ -*/ - -inline -auto -static_buffer:: -data() const -> - const_buffers_type -{ - return {in_, dist(in_, out_)}; -} - -inline -auto -static_buffer:: -prepare(std::size_t n) -> - mutable_buffers_type -{ - return prepare_impl(n); -} - -inline -void -static_buffer:: -reset(void* p, std::size_t n) -{ - reset_impl(p, n); -} - -template -void -static_buffer:: -reset_impl(void* p, std::size_t n) -{ - begin_ = - reinterpret_cast(p); - in_ = begin_; - out_ = begin_; - last_ = begin_; - end_ = begin_ + n; -} - -template -auto -static_buffer:: -prepare_impl(std::size_t n) -> - mutable_buffers_type -{ - if(n <= dist(out_, end_)) - { - last_ = out_ + n; - return {out_, n}; - } - auto const len = size(); - if(n > capacity() - len) - BOOST_THROW_EXCEPTION(std::length_error{ - "buffer overflow"}); - if(len > 0) - std::memmove(begin_, in_, len); - in_ = begin_; - out_ = in_ + len; - last_ = out_ + n; - return {out_, n}; -} - -template -void -static_buffer:: -consume_impl(std::size_t n) -{ - if(n >= size()) - { - in_ = begin_; - out_ = in_; - return; - } - in_ += n; -} - -//------------------------------------------------------------------------------ - -template -static_buffer_n:: -static_buffer_n(static_buffer_n const& other) - : static_buffer(buf_, N) -{ - using boost::asio::buffer_copy; - this->commit(buffer_copy( - this->prepare(other.size()), other.data())); -} - -template -auto -static_buffer_n:: -operator=(static_buffer_n const& other) -> - static_buffer_n& -{ - using boost::asio::buffer_copy; - this->consume(this->size()); - this->commit(buffer_copy( - this->prepare(other.size()), other.data())); - return *this; -} - -} // beast - -#endif diff --git a/src/beast/include/beast/core/impl/static_string.ipp b/src/beast/include/beast/core/impl/static_string.ipp deleted file mode 100644 index 6bab53b5d24..00000000000 --- a/src/beast/include/beast/core/impl/static_string.ipp +++ /dev/null @@ -1,614 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_IMPL_STATIC_STRING_IPP -#define BEAST_IMPL_STATIC_STRING_IPP - -#include -#include -#include - -namespace beast { - -// -// (constructor) -// - -template -static_string:: -static_string() -{ - n_ = 0; - term(); -} - -template -static_string:: -static_string(size_type count, CharT ch) -{ - assign(count, ch); -} - -template -template -static_string:: -static_string(static_string const& other, - size_type pos) -{ - assign(other, pos); -} - -template -template -static_string:: -static_string(static_string const& other, - size_type pos, size_type count) -{ - assign(other, pos, count); -} - -template -static_string:: -static_string(CharT const* s, size_type count) -{ - assign(s, count); -} - -template -static_string:: -static_string(CharT const* s) -{ - assign(s); -} - -template -template -static_string:: -static_string(InputIt first, InputIt last) -{ - assign(first, last); -} - -template -static_string:: -static_string(static_string const& s) -{ - assign(s); -} - -template -template -static_string:: -static_string(static_string const& s) -{ - assign(s); -} - -template -static_string:: -static_string(std::initializer_list init) -{ - assign(init.begin(), init.end()); -} - -template -static_string:: -static_string(string_view_type sv) -{ - assign(sv); -} - -template -template -static_string:: -static_string(T const& t, size_type pos, size_type n) -{ - assign(t, pos, n); -} - -// -// (assignment) -// - -template -auto -static_string:: -assign(size_type count, CharT ch) -> - static_string& -{ - if(count > max_size()) - BOOST_THROW_EXCEPTION(std::length_error{ - "count > max_size()"}); - n_ = count; - Traits::assign(&s_[0], n_, ch); - term(); - return *this; -} - -template -auto -static_string:: -assign(static_string const& str) -> - static_string& -{ - n_ = str.n_; - Traits::copy(&s_[0], &str.s_[0], n_ + 1); - return *this; -} - -template -template -auto -static_string:: -assign(static_string const& str, - size_type pos, size_type count) -> - static_string& -{ - auto const ss = str.substr(pos, count); - return assign(ss.data(), ss.size()); -} - -template -auto -static_string:: -assign(CharT const* s, size_type count) -> - static_string& -{ - if(count > max_size()) - BOOST_THROW_EXCEPTION(std::length_error{ - "count > max_size()"}); - n_ = count; - Traits::copy(&s_[0], s, n_); - term(); - return *this; -} - -template -template -auto -static_string:: -assign(InputIt first, InputIt last) -> - static_string& -{ - std::size_t const n = std::distance(first, last); - if(n > max_size()) - BOOST_THROW_EXCEPTION(std::length_error{ - "n > max_size()"}); - n_ = n; - for(auto it = &s_[0]; first != last; ++it, ++first) - Traits::assign(*it, *first); - term(); - return *this; -} - -template -template -auto -static_string:: -assign(T const& t, size_type pos, size_type count) -> - typename std::enable_if::value, static_string&>::type -{ - auto const sv = string_view_type(t).substr(pos, count); - if(sv.size() > max_size()) - BOOST_THROW_EXCEPTION(std::length_error{ - "sv.size() > max_size()"}); - n_ = sv.size(); - Traits::copy(&s_[0], &sv[0], n_); - term(); - return *this; -} - -// -// Element access -// - -template -auto -static_string:: -at(size_type pos) -> - reference -{ - if(pos >= size()) - BOOST_THROW_EXCEPTION(std::out_of_range{ - "pos >= size()"}); - return s_[pos]; -} - -template -auto -static_string:: -at(size_type pos) const -> - const_reference -{ - if(pos >= size()) - BOOST_THROW_EXCEPTION(std::out_of_range{ - "pos >= size()"}); - return s_[pos]; -} - -// -// Capacity -// - -template -void -static_string:: -reserve(std::size_t n) -{ - if(n > max_size()) - BOOST_THROW_EXCEPTION(std::length_error{ - "n > max_size()"}); -} - -// -// Operations -// - -template -void -static_string:: -clear() -{ - n_ = 0; - term(); -} - -template -auto -static_string:: -insert(size_type index, size_type count, CharT ch) -> - static_string& -{ - if(index > size()) - BOOST_THROW_EXCEPTION(std::out_of_range{ - "index > size()"}); - insert(begin() + index, count, ch); - return *this; -} - -template -auto -static_string:: -insert(size_type index, CharT const* s, size_type count) -> - static_string& -{ - if(index > size()) - BOOST_THROW_EXCEPTION(std::out_of_range{ - "index > size()"}); - if(size() + count > max_size()) - BOOST_THROW_EXCEPTION(std::length_error{ - "size() + count > max_size()"}); - Traits::move( - &s_[index + count], &s_[index], size() - index); - n_ += count; - Traits::copy(&s_[index], s, count); - term(); - return *this; -} - -template -template -auto -static_string:: -insert(size_type index, - static_string const& str, - size_type index_str, size_type count) -> - static_string& -{ - auto const ss = str.substr(index_str, count); - return insert(index, ss.data(), ss.size()); -} - -template -auto -static_string:: -insert(const_iterator pos, size_type count, CharT ch) -> - iterator -{ - if(size() + count > max_size()) - BOOST_THROW_EXCEPTION(std::length_error{ - "size() + count() > max_size()"}); - auto const index = pos - &s_[0]; - Traits::move( - &s_[index + count], &s_[index], size() - index); - n_ += count; - Traits::assign(&s_[index], count, ch); - term(); - return &s_[index]; -} - -template -template -auto -static_string:: -insert(const_iterator pos, InputIt first, InputIt last) -> - typename std::enable_if< - detail::is_input_iterator::value, - iterator>::type -{ - std::size_t const count = std::distance(first, last); - if(size() + count > max_size()) - BOOST_THROW_EXCEPTION(std::length_error{ - "size() + count > max_size()"}); - std::size_t const index = pos - begin(); - Traits::move( - &s_[index + count], &s_[index], size() - index); - n_ += count; - for(auto it = begin() + index; - first != last; ++it, ++first) - Traits::assign(*it, *first); - term(); - return begin() + index; -} - -template -template -auto -static_string:: -insert(size_type index, const T& t, - size_type index_str, size_type count) -> - typename std::enable_if::value && - ! std::is_convertible::value, - static_string&>::type -{ - auto const str = - string_view_type(t).substr(index_str, count); - return insert(index, str.data(), str.size()); -} - -template -auto -static_string:: -erase(size_type index, size_type count) -> - static_string& -{ - if(index > size()) - BOOST_THROW_EXCEPTION(std::out_of_range{ - "index > size()"}); - auto const n = (std::min)(count, size() - index); - Traits::move( - &s_[index], &s_[index + n], size() - (index + n) + 1); - n_ -= n; - return *this; -} - -template -auto -static_string:: -erase(const_iterator pos) -> - iterator -{ - erase(pos - begin(), 1); - return begin() + (pos - begin()); -} - -template -auto -static_string:: -erase(const_iterator first, const_iterator last) -> - iterator -{ - erase(first - begin(), - std::distance(first, last)); - return begin() + (first - begin()); -} - -template -void -static_string:: -push_back(CharT ch) -{ - if(size() >= max_size()) - BOOST_THROW_EXCEPTION(std::length_error{ - "size() >= max_size()"}); - Traits::assign(s_[n_++], ch); - term(); -} - -template -template -auto -static_string:: -append(static_string const& str, - size_type pos, size_type count) -> - static_string& -{ - // Valid range is [0, size) - if(pos >= str.size()) - BOOST_THROW_EXCEPTION(std::out_of_range{ - "pos > str.size()"}); - string_view_type const ss{&str.s_[pos], - (std::min)(count, str.size() - pos)}; - insert(size(), ss.data(), ss.size()); - return *this; -} - -template -auto -static_string:: -substr(size_type pos, size_type count) const -> - string_view_type -{ - if(pos > size()) - BOOST_THROW_EXCEPTION(std::out_of_range{ - "pos > size()"}); - return{&s_[pos], (std::min)(count, size() - pos)}; -} - -template -auto -static_string:: -copy(CharT* dest, size_type count, size_type pos) const -> - size_type -{ - auto const str = substr(pos, count); - Traits::copy(dest, str.data(), str.size()); - return str.size(); -} - -template -void -static_string:: -resize(std::size_t n) -{ - if(n > max_size()) - BOOST_THROW_EXCEPTION(std::length_error{ - "n > max_size()"}); - n_ = n; - term(); -} - -template -void -static_string:: -resize(std::size_t n, CharT c) -{ - if(n > max_size()) - BOOST_THROW_EXCEPTION(std::length_error{ - "n > max_size()"}); - if(n > n_) - Traits::assign(&s_[n_], n - n_, c); - n_ = n; - term(); -} - -template -void -static_string:: -swap(static_string& str) -{ - static_string tmp(str); - str.n_ = n_; - Traits::copy(&str.s_[0], &s_[0], n_ + 1); - n_ = tmp.n_; - Traits::copy(&s_[0], &tmp.s_[0], n_ + 1); -} - -template -template -void -static_string:: -swap(static_string& str) -{ - if(size() > str.max_size()) - BOOST_THROW_EXCEPTION(std::length_error{ - "size() > str.max_size()"}); - if(str.size() > max_size()) - BOOST_THROW_EXCEPTION(std::length_error{ - "str.size() > max_size()"}); - static_string tmp(str); - str.n_ = n_; - Traits::copy(&str.s_[0], &s_[0], n_ + 1); - n_ = tmp.n_; - Traits::copy(&s_[0], &tmp.s_[0], n_ + 1); -} - - -template -auto -static_string:: -assign_char(CharT ch, std::true_type) -> - static_string& -{ - n_ = 1; - Traits::assign(s_[0], ch); - term(); - return *this; -} - -template -auto -static_string:: -assign_char(CharT, std::false_type) -> - static_string& -{ - BOOST_THROW_EXCEPTION(std::length_error{ - "max_size() == 0"}); -} - -namespace detail { - -template -static_string -to_static_string(Integer x, std::true_type) -{ - if(x == 0) - return {'0'}; - static_string s; - if(x < 0) - { - x = -x; - char buf[max_digits(sizeof(x))]; - char* p = buf; - for(;x > 0; x /= 10) - *p++ = "0123456789"[x % 10]; - s.resize(1 + p - buf); - s[0] = '-'; - auto d = &s[1]; - while(p > buf) - *d++ = *--p; - } - else - { - char buf[max_digits(sizeof(x))]; - char* p = buf; - for(;x > 0; x /= 10) - *p++ = "0123456789"[x % 10]; - s.resize(p - buf); - auto d = &s[0]; - while(p > buf) - *d++ = *--p; - } - return s; -} - -template -static_string -to_static_string(Integer x, std::false_type) -{ - if(x == 0) - return {'0'}; - char buf[max_digits(sizeof(x))]; - char* p = buf; - for(;x > 0; x /= 10) - *p++ = "0123456789"[x % 10]; - static_string s; - s.resize(p - buf); - auto d = &s[0]; - while(p > buf) - *d++ = *--p; - return s; -} - -} // detail - -template -static_string -to_static_string(Integer x) -{ - using CharT = char; - using Traits = std::char_traits; - BOOST_STATIC_ASSERT(std::is_integral::value); - char buf[detail::max_digits(sizeof(Integer))]; - auto last = buf + sizeof(buf); - auto it = detail::raw_to_string< - CharT, Integer, Traits>(last, sizeof(buf), x); - static_string s; - s.resize(static_cast(last - it)); - auto p = s.data(); - while(it < last) - Traits::assign(*p++, *it++); - return s; -} - -} // beast - -#endif diff --git a/src/beast/include/beast/core/impl/string_param.ipp b/src/beast/include/beast/core/impl/string_param.ipp deleted file mode 100644 index 8bcccca4c69..00000000000 --- a/src/beast/include/beast/core/impl/string_param.ipp +++ /dev/null @@ -1,104 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_IMPL_STRING_PARAM_IPP -#define BEAST_IMPL_STRING_PARAM_IPP - -namespace beast { - -template -typename std::enable_if< - std::is_integral::value>::type -string_param:: -print(T const& t) -{ - auto const last = buf_ + sizeof(buf_); - auto const it = detail::raw_to_string< - char, T, std::char_traits>( - last, sizeof(buf_), t); - sv_ = {it, static_cast( - last - it)}; -} - -template -typename std::enable_if< - ! std::is_integral::value && - ! std::is_convertible::value ->::type -string_param:: -print(T const& t) -{ - os_.emplace(buf_, sizeof(buf_)); - *os_ << t; - os_->flush(); - sv_ = os_->str(); -} - -inline -void -string_param:: -print(string_view const& sv) -{ - sv_ = sv; -} - -template -typename std::enable_if< - std::is_integral::value>::type -string_param:: -print_1(T const& t) -{ - char buf[detail::max_digits(sizeof(T))]; - auto const last = buf + sizeof(buf); - auto const it = detail::raw_to_string< - char, T, std::char_traits>( - last, sizeof(buf), t); - *os_ << string_view{it, - static_cast(last - it)}; -} - -template -typename std::enable_if< - ! std::is_integral::value>::type -string_param:: -print_1(T const& t) -{ - *os_ << t; -} - -template -void -string_param:: -print_n(T0 const& t0, TN const&... tn) -{ - print_1(t0); - print_n(tn...); -} - -template -void -string_param:: -print(T0 const& t0, T1 const& t1, TN const&... tn) -{ - os_.emplace(buf_, sizeof(buf_)); - print_1(t0); - print_1(t1); - print_n(tn...); - os_->flush(); - sv_ = os_->str(); -} - -template -string_param:: -string_param(Args const&... args) -{ - print(args...); -} - -} // beast - -#endif diff --git a/src/beast/include/beast/core/multi_buffer.hpp b/src/beast/include/beast/core/multi_buffer.hpp deleted file mode 100644 index 4b961756fca..00000000000 --- a/src/beast/include/beast/core/multi_buffer.hpp +++ /dev/null @@ -1,323 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_MULTI_BUFFER_HPP -#define BEAST_MULTI_BUFFER_HPP - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { - -/** A @b DynamicBuffer that uses multiple buffers internally. - - The implementation uses a sequence of one or more character arrays - of varying sizes. Additional character array objects are appended to - the sequence to accommodate changes in the size of the character - sequence. - - @note Meets the requirements of @b DynamicBuffer. - - @tparam Allocator The allocator to use for managing memory. -*/ -template -class basic_multi_buffer -#if ! BEAST_DOXYGEN - : private detail::empty_base_optimization< - typename std::allocator_traits:: - template rebind_alloc> -#endif -{ -public: -#if BEAST_DOXYGEN - /// The type of allocator used. - using allocator_type = Allocator; -#else - using allocator_type = typename - std::allocator_traits:: - template rebind_alloc; -#endif - -private: - // Storage for the list of buffers representing the input - // and output sequences. The allocation for each element - // contains `element` followed by raw storage bytes. - class element; - - using alloc_traits = std::allocator_traits; - using list_type = typename boost::intrusive::make_list>::type; - using iterator = typename list_type::iterator; - using const_iterator = typename list_type::const_iterator; - - using size_type = typename std::allocator_traits::size_type; - using const_buffer = boost::asio::const_buffer; - using mutable_buffer = boost::asio::mutable_buffer; - - static_assert(std::is_base_of::iterator_category>::value, - "BidirectionalIterator requirements not met"); - - static_assert(std::is_base_of::iterator_category>::value, - "BidirectionalIterator requirements not met"); - - std::size_t max_ = - (std::numeric_limits::max)(); - list_type list_; // list of allocated buffers - iterator out_; // element that contains out_pos_ - size_type in_size_ = 0; // size of the input sequence - size_type in_pos_ = 0; // input offset in list_.front() - size_type out_pos_ = 0; // output offset in *out_ - size_type out_end_ = 0; // output end offset in list_.back() - -public: -#if BEAST_DOXYGEN - /// The type used to represent the input sequence as a list of buffers. - using const_buffers_type = implementation_defined; - - /// The type used to represent the output sequence as a list of buffers. - using mutable_buffers_type = implementation_defined; - -#else - class const_buffers_type; - - class mutable_buffers_type; - -#endif - - /// Destructor - ~basic_multi_buffer(); - - /** Constructor - - Upon construction, capacity will be zero. - */ - basic_multi_buffer(); - - /** Constructor. - - @param limit The setting for @ref max_size. - */ - explicit - basic_multi_buffer(std::size_t limit); - - /** Constructor. - - @param alloc The allocator to use. - */ - basic_multi_buffer(Allocator const& alloc); - - /** Constructor. - - @param limit The setting for @ref max_size. - - @param alloc The allocator to use. - */ - basic_multi_buffer( - std::size_t limit, Allocator const& alloc); - - /** Move constructor - - After the move, `*this` will have an empty output sequence. - - @param other The object to move from. After the move, - The object's state will be as if constructed using - its current allocator and limit. - */ - basic_multi_buffer(basic_multi_buffer&& other); - - /** Move constructor - - After the move, `*this` will have an empty output sequence. - - @param other The object to move from. After the move, - The object's state will be as if constructed using - its current allocator and limit. - - @param alloc The allocator to use. - */ - basic_multi_buffer(basic_multi_buffer&& other, - Allocator const& alloc); - - /** Copy constructor. - - @param other The object to copy from. - */ - basic_multi_buffer(basic_multi_buffer const& other); - - /** Copy constructor - - @param other The object to copy from. - - @param alloc The allocator to use. - */ - basic_multi_buffer(basic_multi_buffer const& other, - Allocator const& alloc); - - /** Copy constructor. - - @param other The object to copy from. - */ - template - basic_multi_buffer(basic_multi_buffer< - OtherAlloc> const& other); - - /** Copy constructor. - - @param other The object to copy from. - - @param alloc The allocator to use. - */ - template - basic_multi_buffer(basic_multi_buffer< - OtherAlloc> const& other, allocator_type const& alloc); - - /** Move assignment - - After the move, `*this` will have an empty output sequence. - - @param other The object to move from. After the move, - The object's state will be as if constructed using - its current allocator and limit. - */ - basic_multi_buffer& - operator=(basic_multi_buffer&& other); - - /** Copy assignment - - After the copy, `*this` will have an empty output sequence. - - @param other The object to copy from. - */ - basic_multi_buffer& operator=(basic_multi_buffer const& other); - - /** Copy assignment - - After the copy, `*this` will have an empty output sequence. - - @param other The object to copy from. - */ - template - basic_multi_buffer& operator=( - basic_multi_buffer const& other); - - /// Returns a copy of the associated allocator. - allocator_type - get_allocator() const - { - return this->member(); - } - - /// Returns the size of the input sequence. - size_type - size() const - { - return in_size_; - } - - /// Returns the permitted maximum sum of the sizes of the input and output sequence. - size_type - max_size() const - { - return max_; - } - - /// Returns the maximum sum of the sizes of the input sequence and output sequence the buffer can hold without requiring reallocation. - std::size_t - capacity() const; - - /** Get a list of buffers that represents the input sequence. - - @note These buffers remain valid across subsequent calls to `prepare`. - */ - const_buffers_type - data() const; - - /** Get a list of buffers that represents the output sequence, with the given size. - - @note Buffers representing the input sequence acquired prior to - this call remain valid. - */ - mutable_buffers_type - prepare(size_type n); - - /** Move bytes from the output sequence to the input sequence. - - @note Buffers representing the input sequence acquired prior to - this call remain valid. - */ - void - commit(size_type n); - - /// Remove bytes from the input sequence. - void - consume(size_type n); - - template - friend - void - swap( - basic_multi_buffer& lhs, - basic_multi_buffer& rhs); - -private: - template - friend class basic_multi_buffer; - - void - delete_element(element& e); - - void - delete_list(); - - void - reset(); - - template - void - copy_from(DynamicBuffer const& other); - - void - move_assign(basic_multi_buffer& other, std::false_type); - - void - move_assign(basic_multi_buffer& other, std::true_type); - - void - copy_assign(basic_multi_buffer const& other, std::false_type); - - void - copy_assign(basic_multi_buffer const& other, std::true_type); - - void - swap(basic_multi_buffer&); - - void - swap(basic_multi_buffer&, std::true_type); - - void - swap(basic_multi_buffer&, std::false_type); - - void - debug_check() const; -}; - -/// A typical multi buffer -using multi_buffer = basic_multi_buffer>; - -} // beast - -#include - -#endif diff --git a/src/beast/include/beast/core/ostream.hpp b/src/beast/include/beast/core/ostream.hpp deleted file mode 100644 index 49cbd69aae3..00000000000 --- a/src/beast/include/beast/core/ostream.hpp +++ /dev/null @@ -1,99 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_WRITE_OSTREAM_HPP -#define BEAST_WRITE_OSTREAM_HPP - -#include -#include -#include -#include -#include -#include - -namespace beast { - -/** Return an object representing a @b ConstBufferSequence. - - This function wraps a reference to a buffer sequence and permits - the following operation: - - @li `operator<<` to `std::ostream`. No character translation is - performed; unprintable and null characters will be transferred - as-is to the output stream. - - @par Example - @code - multi_buffer b; - ... - std::cout << buffers(b.data()) << std::endl; - @endcode - - @param b An object meeting the requirements of @b ConstBufferSequence - to be streamed. The implementation will make a copy of this object. - Ownership of the underlying memory is not transferred, the application - is still responsible for managing its lifetime. -*/ -template -#if BEAST_DOXYGEN -implementation_defined -#else -detail::buffers_helper -#endif -buffers(ConstBufferSequence const& b) -{ - static_assert(is_const_buffer_sequence< - ConstBufferSequence>::value, - "ConstBufferSequence requirements not met"); - return detail::buffers_helper< - ConstBufferSequence>{b}; -} - -/** Return an output stream that formats values into a @b DynamicBuffer. - - This function wraps the caller provided @b DynamicBuffer into - a `std::ostream` derived class, to allow `operator<<` stream style - formatting operations. - - @par Example - @code - ostream(buffer) << "Hello, world!" << std::endl; - @endcode - - @note Calling members of the underlying buffer before the output - stream is destroyed results in undefined behavior. - - @param buffer An object meeting the requirements of @b DynamicBuffer - into which the formatted output will be placed. - - @return An object derived from `std::ostream` which redirects output - The wrapped dynamic buffer is not modified, a copy is made instead. - Ownership of the underlying memory is not transferred, the application - is still responsible for managing its lifetime. The caller is - responsible for ensuring the dynamic buffer is not destroyed for the - lifetime of the output stream. -*/ -template -#if BEAST_DOXYGEN -implementation_defined -#else -detail::ostream_helper< - DynamicBuffer, char, std::char_traits, - detail::basic_streambuf_movable::value> -#endif -ostream(DynamicBuffer& buffer) -{ - static_assert(is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - return detail::ostream_helper< - DynamicBuffer, char, std::char_traits, - detail::basic_streambuf_movable::value>{buffer}; -} - -} // beast - -#endif diff --git a/src/beast/include/beast/core/read_size.hpp b/src/beast/include/beast/core/read_size.hpp deleted file mode 100644 index 326877f4a2f..00000000000 --- a/src/beast/include/beast/core/read_size.hpp +++ /dev/null @@ -1,60 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_READ_SIZE_HELPER_HPP -#define BEAST_READ_SIZE_HELPER_HPP - -#include -#include -#include - -namespace beast { - -/** Returns a natural read size. - - This function inspects the capacity, size, and maximum - size of the dynamic buffer. Then it computes a natural - read size given the passed-in upper limit. It favors - a read size that does not require a reallocation, subject - to a reasonable minimum to avoid tiny reads. - - @param buffer The dynamic buffer to inspect. - - @param max_size An upper limit on the returned value. - - @note If the buffer is already at its maximum size, zero - is returned. -*/ -template -std::size_t -read_size(DynamicBuffer& buffer, std::size_t max_size); - -/** Returns a natural read size or throw if the buffer is full. - - This function inspects the capacity, size, and maximum - size of the dynamic buffer. Then it computes a natural - read size given the passed-in upper limit. It favors - a read size that does not require a reallocation, subject - to a reasonable minimum to avoid tiny reads. - - @param buffer The dynamic buffer to inspect. - - @param max_size An upper limit on the returned value. - - @throws std::length_error if `max_size > 0` and the buffer - is full. -*/ -template -std::size_t -read_size_or_throw(DynamicBuffer& buffer, - std::size_t max_size); - -} // beast - -#include - -#endif diff --git a/src/beast/include/beast/core/span.hpp b/src/beast/include/beast/core/span.hpp deleted file mode 100644 index 1d465ce42fa..00000000000 --- a/src/beast/include/beast/core/span.hpp +++ /dev/null @@ -1,211 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_CORE_SPAN_HPP -#define BEAST_CORE_SPAN_HPP - -#include -#include -#include -#include -#include -#include - -namespace beast { - -/** A range of bytes expressed as a ContiguousContainer - - This class implements a non-owning reference to a storage - area of a certain size and having an underlying integral - type with size of 1. - - @tparam T The type pointed to by span iterators -*/ -template -class span -{ - T* data_ = nullptr; - std::size_t size_ = 0; - -public: - /// The type of value, including cv qualifiers - using element_type = T; - - /// The type of value of each span element - using value_type = typename std::remove_const::type; - - /// The type of integer used to index the span - using index_type = std::ptrdiff_t; - - /// A pointer to a span element - using pointer = T*; - - /// A reference to a span element - using reference = T&; - - /// The iterator used by the container - using iterator = pointer; - - /// The const pointer used by the container - using const_pointer = T const*; - - /// The const reference used by the container - using const_reference = T const&; - - /// The const iterator used by the container - using const_iterator = const_pointer; - - /// Constructor - span() = default; - - /// Constructor - span(span const&) = default; - - /// Assignment - span& operator=(span const&) = default; - - /** Constructor - - @param data A pointer to the beginning of the range of elements - - @param size The number of elements pointed to by `data` - */ - span(T* data, std::size_t size) - : data_(data), size_(size) - { - } - - /** Constructor - - @param container The container to construct from - */ - template::value>::type -#endif - > - explicit - span(ContiguousContainer&& container) - : data_(container.data()) - , size_(container.size()) - { - } - -#if ! BEAST_DOXYGEN - template - explicit - span(std::basic_string& s) - : data_(&s[0]) - , size_(s.size()) - { - } - - template - explicit - span(std::basic_string const& s) - : data_(s.data()) - , size_(s.size()) - { - } -#endif - - /** Assignment - - @param container The container to assign from - */ - template -#if BEAST_DOXYGEN - span& -#else - typename std::enable_if::value, - span&>::type -#endif - operator=(ContiguousContainer&& container) - { - data_ = container.data(); - size_ = container.size(); - return *this; - } - -#if ! BEAST_DOXYGEN - template - span& - operator=(std::basic_string< - CharT, Traits, Allocator>& s) - { - data_ = &s[0]; - size_ = s.size(); - return *this; - } - - template - span& - operator=(std::basic_string< - CharT, Traits, Allocator> const& s) - { - data_ = s.data(); - size_ = s.size(); - return *this; - } -#endif - - /// Returns `true` if the span is empty - bool - empty() const - { - return size_ == 0; - } - - /// Returns a pointer to the beginning of the span - T* - data() const - { - return data_; - } - - /// Returns the number of elements in the span - std::size_t - size() const - { - return size_; - } - - /// Returns an iterator to the beginning of the span - const_iterator - begin() const - { - return data_; - } - - /// Returns an iterator to the beginning of the span - const_iterator - cbegin() const - { - return data_; - } - - /// Returns an iterator to one past the end of the span - const_iterator - end() const - { - return data_ + size_; - } - - /// Returns an iterator to one past the end of the span - const_iterator - cend() const - { - return data_ + size_; - } -}; - -} // beast - -#endif diff --git a/src/beast/include/beast/core/static_buffer.hpp b/src/beast/include/beast/core/static_buffer.hpp deleted file mode 100644 index 1f86c3364e4..00000000000 --- a/src/beast/include/beast/core/static_buffer.hpp +++ /dev/null @@ -1,218 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_STATIC_BUFFER_HPP -#define BEAST_STATIC_BUFFER_HPP - -#include -#include -#include -#include -#include - -namespace beast { - -/** A @b DynamicBuffer with a fixed size internal buffer. - - Ownership of the underlying storage belongs to the derived class. - - @note Variables are usually declared using the template class - @ref static_buffer_n; however, to reduce the number of instantiations - of template functions receiving static stream buffer arguments in a - deduced context, the signature of the receiving function should use - @ref static_buffer. - - When used with @ref static_buffer_n this implements a dynamic - buffer using no memory allocations. - - @see @ref static_buffer_n -*/ -class static_buffer -{ - char* begin_; - char* in_; - char* out_; - char* last_; - char* end_; - - static_buffer(static_buffer const& other) = delete; - static_buffer& operator=(static_buffer const&) = delete; - -public: - /// The type used to represent the input sequence as a list of buffers. - using const_buffers_type = boost::asio::const_buffers_1; - - /// The type used to represent the output sequence as a list of buffers. - using mutable_buffers_type = boost::asio::mutable_buffers_1; - - /** Constructor. - - This creates a dynamic buffer using the provided storage area. - - @param p A pointer to valid storage of at least `n` bytes. - - @param n The number of valid bytes pointed to by `p`. - */ - static_buffer(void* p, std::size_t n) - { - reset_impl(p, n); - } - - /// Return the size of the input sequence. - std::size_t - size() const - { - return out_ - in_; - } - - /// Return the maximum sum of the input and output sequence sizes. - std::size_t - max_size() const - { - return dist(begin_, end_); - } - - /// Return the maximum sum of input and output sizes that can be held without an allocation. - std::size_t - capacity() const - { - return max_size(); - } - - /** Get a list of buffers that represent the input sequence. - - @note These buffers remain valid across subsequent calls to `prepare`. - */ - const_buffers_type - data() const; - - /** Get a list of buffers that represent the output sequence, with the given size. - - @throws std::length_error if the size would exceed the limit - imposed by the underlying mutable buffer sequence. - - @note Buffers representing the input sequence acquired prior to - this call remain valid. - */ - mutable_buffers_type - prepare(std::size_t n); - - /** Move bytes from the output sequence to the input sequence. - - @note Buffers representing the input sequence acquired prior to - this call remain valid. - */ - void - commit(std::size_t n) - { - out_ += std::min(n, last_ - out_); - } - - /// Remove bytes from the input sequence. - void - consume(std::size_t n) - { - consume_impl(n); - } - -protected: - /** Default constructor. - - The buffer will be in an undefined state. It is necessary - for the derived class to call @ref reset in order to - initialize the object. - */ - static_buffer(); - - /** Reset the pointed-to buffer. - - This function resets the internal state to the buffer provided. - All input and output sequences are invalidated. This function - allows the derived class to construct its members before - initializing the static buffer. - - @param p A pointer to valid storage of at least `n` bytes. - - @param n The number of valid bytes pointed to by `p`. - */ - void - reset(void* p, std::size_t n); - -private: - static - inline - std::size_t - dist(char const* first, char const* last) - { - return static_cast(last - first); - } - - template - void - reset_impl(void* p, std::size_t n); - - template - mutable_buffers_type - prepare_impl(std::size_t n); - - template - void - consume_impl(std::size_t n); -}; - -//------------------------------------------------------------------------------ - -/** A @b DynamicBuffer with a fixed size internal buffer. - - This implements a dynamic buffer using no memory allocations. - - @tparam N The number of bytes in the internal buffer. - - @note To reduce the number of template instantiations when passing - objects of this type in a deduced context, the signature of the - receiving function should use @ref static_buffer instead. - - @see @ref static_buffer -*/ -template -class static_buffer_n : public static_buffer -{ - char buf_[N]; - -public: - /// Copy constructor - static_buffer_n(static_buffer_n const&); - - /// Copy assignment - static_buffer_n& operator=(static_buffer_n const&); - - /// Construct a static buffer. - static_buffer_n() - : static_buffer(buf_, N) - { - } - - /// Returns the @ref static_buffer portion of this object - static_buffer& - base() - { - return *this; - } - - /// Returns the @ref static_buffer portion of this object - static_buffer const& - base() const - { - return *this; - } -}; - -} // beast - -#include - -#endif diff --git a/src/beast/include/beast/core/static_string.hpp b/src/beast/include/beast/core/static_string.hpp deleted file mode 100644 index 0d0dc8f201c..00000000000 --- a/src/beast/include/beast/core/static_string.hpp +++ /dev/null @@ -1,1108 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_STATIC_STRING_HPP -#define BEAST_STATIC_STRING_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { - -/** A modifiable string with a fixed-size storage area. - - These objects behave like `std::string` except that the storage - is not dynamically allocated but rather fixed in size. - - These strings offer performance advantages when a protocol - imposes a natural small upper limit on the size of a value. - - @note The stored string is always null-terminated. - - @see @ref to_static_string -*/ -template< - std::size_t N, - class CharT = char, - class Traits = std::char_traits> -class static_string -{ - template - friend class static_string; - - void - term() - { - Traits::assign(s_[n_], 0); - } - - std::size_t n_; - CharT s_[N+1]; - -public: - // - // Member types - // - - using traits_type = Traits; - using value_type = typename Traits::char_type; - using size_type = std::size_t; - using difference_type = std::ptrdiff_t; - using pointer = value_type*; - using reference = value_type&; - using const_pointer = value_type const*; - using const_reference = value_type const&; - using iterator = value_type*; - using const_iterator = value_type const*; - using reverse_iterator = - std::reverse_iterator; - using const_reverse_iterator = - std::reverse_iterator; - - /// The type of `string_view` returned by the interface - using string_view_type = - beast::basic_string_view; - - // - // Constants - // - - /// Maximum size of the string excluding the null terminator - static std::size_t constexpr max_size_n = N; - - /// A special index - static constexpr size_type npos = size_type(-1); - - // - // (constructor) - // - - /// Default constructor (empty string). - static_string(); - - /** Construct with count copies of character `ch`. - - The behavior is undefined if `count >= npos` - */ - static_string(size_type count, CharT ch); - - /// Construct with a substring (pos, other.size()) of `other`. - template - static_string(static_string const& other, - size_type pos); - - /// Construct with a substring (pos, count) of `other`. - template - static_string(static_string const& other, - size_type pos, size_type count); - - /// Construct with the first `count` characters of `s`, including nulls. - static_string(CharT const* s, size_type count); - - /// Construct from a null terminated string. - static_string(CharT const* s); - - /// Construct from a range of characters - template - static_string(InputIt first, InputIt last); - - /// Copy constructor. - static_string(static_string const& other); - - /// Copy constructor. - template - static_string(static_string const& other); - - /// Construct from an initializer list - static_string(std::initializer_list init); - - /// Construct from a `string_view` - explicit - static_string(string_view_type sv); - - /** Construct from any object convertible to `string_view_type`. - - The range (pos, n) is extracted from the value - obtained by converting `t` to `string_view_type`, - and used to construct the string. - */ -#if BEAST_DOXYGEN - template -#else - template::value>::type> -#endif - static_string(T const& t, size_type pos, size_type n); - - // - // (assignment) - // - - /// Copy assignment. - static_string& - operator=(static_string const& str) - { - return assign(str); - } - - /// Copy assignment. - template - static_string& - operator=(static_string const& str) - { - return assign(str); - } - - /// Assign from null-terminated string. - static_string& - operator=(CharT const* s) - { - return assign(s); - } - - /// Assign from single character. - static_string& - operator=(CharT ch) - { - return assign_char(ch, - std::integral_constant0)>{}); - } - - /// Assign from initializer list. - static_string& - operator=(std::initializer_list init) - { - return assign(init); - } - - /// Assign from `string_view_type`. - static_string& - operator=(string_view_type sv) - { - return assign(sv); - } - - /// Assign `count` copies of `ch`. - static_string& - assign(size_type count, CharT ch); - - /// Assign from another `static_string` - static_string& - assign(static_string const& str); - - // VFALCO NOTE this could come in two flavors, - // N>M and NM - - /// Assign from another `static_string` - template - static_string& - assign(static_string const& str) - { - return assign(str.data(), str.size()); - } - - /// Assign `count` characterss starting at `npos` from `other`. - template - static_string& - assign(static_string const& str, - size_type pos, size_type count = npos); - - /// Assign the first `count` characters of `s`, including nulls. - static_string& - assign(CharT const* s, size_type count); - - /// Assign a null terminated string. - static_string& - assign(CharT const* s) - { - return assign(s, Traits::length(s)); - } - - /// Assign from an iterator range of characters. - template - static_string& - assign(InputIt first, InputIt last); - - /// Assign from initializer list. - static_string& - assign(std::initializer_list init) - { - return assign(init.begin(), init.end()); - } - - /// Assign from `string_view_type`. - static_string& - assign(string_view_type str) - { - return assign(str.data(), str.size()); - } - - /** Assign from any object convertible to `string_view_type`. - - The range (pos, n) is extracted from the value - obtained by converting `t` to `string_view_type`, - and used to assign the string. - */ - template -#if BEAST_DOXYGEN - static_string& -#else - typename std::enable_if::value, static_string&>::type -#endif - assign(T const& t, - size_type pos, size_type count = npos); - - // - // Element access - // - - /// Access specified character with bounds checking. - reference - at(size_type pos); - - /// Access specified character with bounds checking. - const_reference - at(size_type pos) const; - - /// Access specified character. - reference - operator[](size_type pos) - { - return s_[pos]; - } - - /// Access specified character. - const_reference - operator[](size_type pos) const - { - return s_[pos]; - } - - /// Accesses the first character. - CharT& - front() - { - return s_[0]; - } - - /// Accesses the first character. - CharT const& - front() const - { - return s_[0]; - } - - /// Accesses the last character. - CharT& - back() - { - return s_[n_-1]; - } - - /// Accesses the last character. - CharT const& - back() const - { - return s_[n_-1]; - } - - /// Returns a pointer to the first character of a string. - CharT* - data() - { - return &s_[0]; - } - - /// Returns a pointer to the first character of a string. - CharT const* - data() const - { - return &s_[0]; - } - - /// Returns a non-modifiable standard C character array version of the string. - CharT const* - c_str() const - { - return data(); - } - - /// Convert a static string to a `string_view_type` - operator string_view_type() const - { - return basic_string_view< - CharT, Traits>{data(), size()}; - } - - // - // Iterators - // - - /// Returns an iterator to the beginning. - iterator - begin() - { - return &s_[0]; - } - - /// Returns an iterator to the beginning. - const_iterator - begin() const - { - return &s_[0]; - } - - /// Returns an iterator to the beginning. - const_iterator - cbegin() const - { - return &s_[0]; - } - - /// Returns an iterator to the end. - iterator - end() - { - return &s_[n_]; - } - - /// Returns an iterator to the end. - const_iterator - end() const - { - return &s_[n_]; - } - - /// Returns an iterator to the end. - const_iterator - cend() const - { - return &s_[n_]; - } - - /// Returns a reverse iterator to the beginning. - reverse_iterator - rbegin() - { - return reverse_iterator{end()}; - } - - /// Returns a reverse iterator to the beginning. - const_reverse_iterator - rbegin() const - { - return const_reverse_iterator{cend()}; - } - - /// Returns a reverse iterator to the beginning. - const_reverse_iterator - crbegin() const - { - return const_reverse_iterator{cend()}; - } - - /// Returns a reverse iterator to the end. - reverse_iterator - rend() - { - return reverse_iterator{begin()}; - } - - /// Returns a reverse iterator to the end. - const_reverse_iterator - rend() const - { - return const_reverse_iterator{cbegin()}; - } - - /// Returns a reverse iterator to the end. - const_reverse_iterator - crend() const - { - return const_reverse_iterator{cbegin()}; - } - - // - // Capacity - // - - /// Returns `true` if the string is empty. - bool - empty() const - { - return n_ == 0; - } - - /// Returns the number of characters, excluding the null terminator. - size_type - size() const - { - return n_; - } - - /// Returns the number of characters, excluding the null terminator. - size_type - length() const - { - return size(); - } - - /// Returns the maximum number of characters that can be stored, excluding the null terminator. - size_type constexpr - max_size() const - { - return N; - } - - /** Reserves storage. - - This actually just throws an exception if `n > N`, - otherwise does nothing since the storage is fixed. - */ - void - reserve(std::size_t n); - - /// Returns the number of characters that can be held in currently allocated storage. - size_type constexpr - capacity() const - { - return max_size(); - } - - /** Reduces memory usage by freeing unused memory. - - This actually does nothing, since the storage is fixed. - */ - void - shrink_to_fit() - { - } - - // - // Operations - // - - /// Clears the contents. - void - clear(); - - static_string& - insert(size_type index, size_type count, CharT ch); - - static_string& - insert(size_type index, CharT const* s) - { - return insert(index, s, Traits::length(s)); - } - - static_string& - insert(size_type index, CharT const* s, size_type count); - - template - static_string& - insert(size_type index, - static_string const& str) - { - return insert(index, str.data(), str.size()); - } - - template - static_string& - insert(size_type index, - static_string const& str, - size_type index_str, size_type count = npos); - - iterator - insert(const_iterator pos, CharT ch) - { - return insert(pos, 1, ch); - } - - iterator - insert(const_iterator pos, size_type count, CharT ch); - - template -#if BEAST_DOXYGEN - iterator -#else - typename std::enable_if< - detail::is_input_iterator::value, - iterator>::type -#endif - insert(const_iterator pos, InputIt first, InputIt last); - - iterator - insert(const_iterator pos, std::initializer_list init) - { - return insert(pos, init.begin(), init.end()); - } - - static_string& - insert(size_type index, string_view_type str) - { - return insert(index, str.data(), str.size()); - } - - template -#if BEAST_DOXYGEN - static_string& -#else - typename std::enable_if< - std::is_convertible::value && - ! std::is_convertible::value, - static_string&>::type -#endif - insert(size_type index, T const& t, - size_type index_str, size_type count = npos); - - static_string& - erase(size_type index = 0, size_type count = npos); - - iterator - erase(const_iterator pos); - - iterator - erase(const_iterator first, const_iterator last); - - void - push_back(CharT ch); - - void - pop_back() - { - Traits::assign(s_[--n_], 0); - } - - static_string& - append(size_type count, CharT ch) - { - insert(end(), count, ch); - return *this; - } - - template - static_string& - append(static_string const& str) - { - insert(size(), str); - return *this; - } - - template - static_string& - append(static_string const& str, - size_type pos, size_type count = npos); - - static_string& - append(CharT const* s, size_type count) - { - insert(size(), s, count); - return *this; - } - - static_string& - append(CharT const* s) - { - insert(size(), s); - return *this; - } - - template -#if BEAST_DOXYGEN - static_string& -#else - typename std::enable_if< - detail::is_input_iterator::value, - static_string&>::type -#endif - append(InputIt first, InputIt last) - { - insert(end(), first, last); - return *this; - } - - static_string& - append(std::initializer_list init) - { - insert(end(), init); - return *this; - } - - static_string& - append(string_view_type sv) - { - insert(size(), sv); - return *this; - } - - template - typename std::enable_if< - std::is_convertible::value && - ! std::is_convertible::value, - static_string&>::type - append(T const& t, size_type pos, size_type count = npos) - { - insert(size(), t, pos, count); - return *this; - } - - template - static_string& - operator+=(static_string const& str) - { - return append(str.data(), str.size()); - } - - static_string& - operator+=(CharT ch) - { - push_back(ch); - return *this; - } - - static_string& - operator+=(CharT const* s) - { - return append(s); - } - - static_string& - operator+=(std::initializer_list init) - { - return append(init); - } - - static_string& - operator+=(string_view_type const& str) - { - return append(str); - } - - template - int - compare(static_string const& str) const - { - return detail::lexicographical_compare( - &s_[0], n_, &str.s_[0], str.n_); - } - - template - int - compare(size_type pos1, size_type count1, - static_string const& str) const - { - return detail::lexicographical_compare( - substr(pos1, count1), str.data(), str.size()); - } - - template - int - compare(size_type pos1, size_type count1, - static_string const& str, - size_type pos2, size_type count2 = npos) const - { - return detail::lexicographical_compare( - substr(pos1, count1), str.substr(pos2, count2)); - } - - int - compare(CharT const* s) const - { - return detail::lexicographical_compare( - &s_[0], n_, s, Traits::length(s)); - } - - int - compare(size_type pos1, size_type count1, - CharT const* s) const - { - return detail::lexicographical_compare( - substr(pos1, count1), s, Traits::length(s)); - } - - int - compare(size_type pos1, size_type count1, - CharT const*s, size_type count2) const - { - return detail::lexicographical_compare( - substr(pos1, count1), s, count2); - } - - int - compare(string_view_type str) const - { - return detail::lexicographical_compare( - &s_[0], n_, str.data(), str.size()); - } - - int - compare(size_type pos1, size_type count1, - string_view_type str) const - { - return detail::lexicographical_compare( - substr(pos1, count1), str); - } - - template -#if BEAST_DOXYGEN - int -#else - typename std::enable_if< - std::is_convertible::value && - ! std::is_convertible::value, - int>::type -#endif - compare(size_type pos1, size_type count1, - T const& t, size_type pos2, - size_type count2 = npos) const - { - return compare(pos1, count1, - string_view_type(t).substr(pos2, count2)); - } - - string_view_type - substr(size_type pos = 0, size_type count = npos) const; - - /// Copy a substring (pos, pos+count) to character string pointed to by `dest`. - size_type - copy(CharT* dest, size_type count, size_type pos = 0) const; - - /** Changes the number of characters stored. - - If the resulting string is larger, the new - characters are uninitialized. - */ - void - resize(std::size_t n); - - /** Changes the number of characters stored. - - If the resulting string is larger, the new - characters are initialized to the value of `c`. - */ - void - resize(std::size_t n, CharT c); - - /// Exchange the contents of this string with another. - void - swap(static_string& str); - - /// Exchange the contents of this string with another. - template - void - swap(static_string& str); - - // - // Search - // - -private: - static_string& - assign_char(CharT ch, std::true_type); - - static_string& - assign_char(CharT ch, std::false_type); -}; - -// -// Disallowed operations -// - -// These operations are explicitly deleted since -// there is no reasonable implementation possible. - -template -void -operator+( - static_stringconst& lhs, - static_stringconst& rhs) = delete; - -template -void -operator+(CharT const* lhs, - static_stringconst& rhs) = delete; - -template -void -operator+(CharT lhs, - static_string const& rhs) = delete; - -template -void -operator+(static_string const& lhs, - CharT const* rhs) = delete; - -template -void -operator+(static_string const& lhs, - CharT rhs) = delete; - -// -// Non-member functions -// - -template -bool -operator==( - static_string const& lhs, - static_string const& rhs) -{ - return lhs.compare(rhs) == 0; -} - -template -bool -operator!=( - static_string const& lhs, - static_string const& rhs) -{ - return lhs.compare(rhs) != 0; -} - -template -bool -operator<( - static_string const& lhs, - static_string const& rhs) -{ - return lhs.compare(rhs) < 0; -} - -template -bool -operator<=( - static_string const& lhs, - static_string const& rhs) -{ - return lhs.compare(rhs) <= 0; -} - -template -bool -operator>( - static_string const& lhs, - static_string const& rhs) -{ - return lhs.compare(rhs) > 0; -} - -template -bool -operator>=( - static_string const& lhs, - static_string const& rhs) -{ - return lhs.compare(rhs) >= 0; -} - -template -bool -operator==( - CharT const* lhs, - static_string const& rhs) -{ - return detail::lexicographical_compare( - lhs, Traits::length(lhs), - rhs.data(), rhs.size()) == 0; -} - -template -bool -operator==( - static_string const& lhs, - CharT const* rhs) -{ - return detail::lexicographical_compare( - lhs.data(), lhs.size(), - rhs, Traits::length(rhs)) == 0; -} - -template -bool -operator!=( - CharT const* lhs, - static_string const& rhs) -{ - return detail::lexicographical_compare( - lhs, Traits::length(lhs), - rhs.data(), rhs.size()) != 0; -} - -template -bool -operator!=( - static_string const& lhs, - CharT const* rhs) -{ - return detail::lexicographical_compare( - lhs.data(), lhs.size(), - rhs, Traits::length(rhs)) != 0; -} - -template -bool -operator<( - CharT const* lhs, - static_string const& rhs) -{ - return detail::lexicographical_compare( - lhs, Traits::length(lhs), - rhs.data(), rhs.size()) < 0; -} - -template -bool -operator<( - static_string const& lhs, - CharT const* rhs) -{ - return detail::lexicographical_compare( - lhs.data(), lhs.size(), - rhs, Traits::length(rhs)) < 0; -} - -template -bool -operator<=( - CharT const* lhs, - static_string const& rhs) -{ - return detail::lexicographical_compare( - lhs, Traits::length(lhs), - rhs.data(), rhs.size()) <= 0; -} - -template -bool -operator<=( - static_string const& lhs, - CharT const* rhs) -{ - return detail::lexicographical_compare( - lhs.data(), lhs.size(), - rhs, Traits::length(rhs)) <= 0; -} - -template -bool -operator>( - CharT const* lhs, - static_string const& rhs) -{ - return detail::lexicographical_compare( - lhs, Traits::length(lhs), - rhs.data(), rhs.size()) > 0; -} - -template -bool -operator>( - static_string const& lhs, - CharT const* rhs) -{ - return detail::lexicographical_compare( - lhs.data(), lhs.size(), - rhs, Traits::length(rhs)) > 0; -} - -template -bool -operator>=( - CharT const* lhs, - static_string const& rhs) -{ - return detail::lexicographical_compare( - lhs, Traits::length(lhs), - rhs.data(), rhs.size()) >= 0; -} - -template -bool -operator>=( - static_string const& lhs, - CharT const* rhs) -{ - return detail::lexicographical_compare( - lhs.data(), lhs.size(), - rhs, Traits::length(rhs)) >= 0; -} - -// -// swap -// - -template -void -swap( - static_string& lhs, - static_string& rhs) -{ - lhs.swap(rhs); -} - -template -void -swap( - static_string& lhs, - static_string& rhs) -{ - lhs.swap(rhs); -} - -// -// Input/Output -// - -template -std::basic_ostream& -operator<<(std::basic_ostream& os, - static_string const& str) -{ - return os << static_cast< - beast::basic_string_view>(str); -} - -// -// Numeric conversions -// - -/** Returns a static string representing an integer as a decimal. - - @param x The signed or unsigned integer to convert. - This must be an integral type. - - @return A @ref static_string with an implementation defined - maximum size large enough to hold the longest possible decimal - representation of any integer of the given type. -*/ -template -static_string -to_static_string(Integer x); - -} // beast - -#include - -#endif diff --git a/src/beast/include/beast/core/string.hpp b/src/beast/include/beast/core/string.hpp deleted file mode 100644 index 601160982ba..00000000000 --- a/src/beast/include/beast/core/string.hpp +++ /dev/null @@ -1,151 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_STRING_HPP -#define BEAST_STRING_HPP - -#include -#include -#ifndef BEAST_NO_BOOST_STRING_VIEW -# if BOOST_VERSION >= 106400 -# define BEAST_NO_BOOST_STRING_VIEW 0 -# else -# define BEAST_NO_BOOST_STRING_VIEW 1 -# endif -#endif - -#if BEAST_NO_BOOST_STRING_VIEW -#include -#else -#include -#endif - -#include - -namespace beast { - -#if BEAST_NO_BOOST_STRING_VIEW -/// The type of string view used by the library -using string_view = boost::string_ref; - -/// The type of basic string view used by the library -template -using basic_string_view = - boost::basic_string_ref; -#else -/// The type of string view used by the library -using string_view = boost::string_view; - -/// The type of basic string view used by the library -template -using basic_string_view = - boost::basic_string_view; -#endif - -namespace detail { - -inline -char -ascii_tolower(char c) -{ - if(c >= 'A' && c <= 'Z') - c += 'a' - 'A'; - return c; -} - -template -bool -iequals( - beast::string_view const& lhs, - beast::string_view const& rhs) -{ - auto n = lhs.size(); - if(rhs.size() != n) - return false; - auto p1 = lhs.data(); - auto p2 = rhs.data(); - char a, b; - while(n--) - { - a = *p1++; - b = *p2++; - if(a != b) - goto slow; - } - return true; - - while(n--) - { - slow: - if(ascii_tolower(a) != ascii_tolower(b)) - return false; - a = *p1++; - b = *p2++; - } - return true; -} - -} // detail - -/** Returns `true` if two strings are equal, using a case-insensitive comparison. - - The case-comparison operation is defined only for low-ASCII characters. - - @param lhs The string on the left side of the equality - - @param rhs The string on the right side of the equality -*/ -inline -bool -iequals( - beast::string_view const& lhs, - beast::string_view const& rhs) -{ - return detail::iequals(lhs, rhs); -} - -/** A case-insensitive less predicate for strings. - - The case-comparison operation is defined only for low-ASCII characters. -*/ -struct iless -{ - bool - operator()( - string_view const& lhs, - string_view const& rhs) const - { - using std::begin; - using std::end; - return std::lexicographical_compare( - begin(lhs), end(lhs), begin(rhs), end(rhs), - [](char c1, char c2) - { - return detail::ascii_tolower(c1) < detail::ascii_tolower(c2); - } - ); - } -}; - -/** A case-insensitive equality predicate for strings. - - The case-comparison operation is defined only for low-ASCII characters. -*/ -struct iequal -{ - bool - operator()( - string_view const& lhs, - string_view const& rhs) const - { - return iequals(lhs, rhs); - } -}; - -} // beast - -#endif diff --git a/src/beast/include/beast/core/string_param.hpp b/src/beast/include/beast/core/string_param.hpp deleted file mode 100644 index dedd060aae7..00000000000 --- a/src/beast/include/beast/core/string_param.hpp +++ /dev/null @@ -1,109 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_STRING_PARAM_HPP -#define BEAST_STRING_PARAM_HPP - -#include -#include -#include -#include -#include -#include - -namespace beast { - -/** A function parameter which efficiently converts to string. - - This is used as a function parameter type to allow callers - notational convenience: objects other than strings may be - passed in contexts where a string is expected. The conversion - to string is made using `operator<<` to a non-dynamically - allocated static buffer if possible, else to a `std::string` - on overflow. -*/ -class string_param -{ - string_view sv_; - char buf_[128]; - boost::optional os_; - - template - typename std::enable_if< - std::is_integral::value>::type - print(T const&); - - template - typename std::enable_if< - ! std::is_integral::value && - ! std::is_convertible::value - >::type - print(T const&); - - void - print(string_view const&); - - template - typename std::enable_if< - std::is_integral::value>::type - print_1(T const&); - - template - typename std::enable_if< - ! std::is_integral::value>::type - print_1(T const&); - - void - print_n() - { - } - - template - void - print_n(T0 const&, TN const&...); - - template - void - print(T0 const&, T1 const&, TN const&...); - -public: - /// Copy constructor (disallowed) - string_param(string_param const&) = delete; - - /// Copy assignment (disallowed) - string_param& operator=(string_param const&) = delete; - - /** Constructor - - This function constructs a string as if by concatenating - the result of streaming each argument in order into an - output stream. It is used as a notational convenience - at call sites which expect a parameter with the semantics - of a @ref string_view. - - The implementation uses a small, internal static buffer - to avoid memory allocations especially for the case where - the list of arguments to be converted consists of a single - integral type. - - @param args One or more arguments to convert - */ - template - string_param(Args const&... args); - - /// Implicit conversion to @ref string_view - operator string_view const() const - { - return sv_; - } -}; - -} // beast - -#include - -#endif diff --git a/src/beast/include/beast/core/type_traits.hpp b/src/beast/include/beast/core/type_traits.hpp deleted file mode 100644 index 2624ee66802..00000000000 --- a/src/beast/include/beast/core/type_traits.hpp +++ /dev/null @@ -1,633 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_TYPE_TRAITS_HPP -#define BEAST_TYPE_TRAITS_HPP - -#include -#include -#include -#include -#include - -namespace beast { - -//------------------------------------------------------------------------------ -// -// Buffer concepts -// -//------------------------------------------------------------------------------ - -/** Determine if `T` meets the requirements of @b ConstBufferSequence. - - Metafunctions are used to perform compile time checking of template - types. This type will be `std::true_type` if `T` meets the requirements, - else the type will be `std::false_type`. - - @par Example - - Use with `static_assert`: - - @code - template - void f(ConstBufferSequence const& buffers) - { - static_assert(is_const_buffer_sequence::value, - "ConstBufferSequence requirements not met"); - ... - @endcode - - Use with `std::enable_if` (SFINAE): - - @code - template - typename std::enable_if::value>::type - f(ConstBufferSequence const& buffers); - @endcode -*/ -template -#if BEAST_DOXYGEN -struct is_const_buffer_sequence : std::integral_constant -#else -struct is_const_buffer_sequence : - detail::is_buffer_sequence -#endif -{ -}; - -/** Determine if `T` meets the requirements of @b MutableBufferSequence. - - Metafunctions are used to perform compile time checking of template - types. This type will be `std::true_type` if `T` meets the requirements, - else the type will be `std::false_type`. - - @par Example - - Use with `static_assert`: - - @code - template - void f(MutableBufferSequence const& buffers) - { - static_assert(is_const_buffer_sequence::value, - "MutableBufferSequence requirements not met"); - ... - @endcode - - Use with `std::enable_if` (SFINAE): - - @code - template - typename std::enable_if::value>::type - f(MutableBufferSequence const& buffers); - @endcode -*/ -template -#if BEAST_DOXYGEN -struct is_mutable_buffer_sequence : std::integral_constant -#else -struct is_mutable_buffer_sequence : - detail::is_buffer_sequence -#endif -{ -}; - -/** Determine if `T` meets the requirements of @b DynamicBuffer. - - Metafunctions are used to perform compile time checking of template - types. This type will be `std::true_type` if `T` meets the requirements, - else the type will be `std::false_type`. - - @par Example - - Use with `static_assert`: - - @code - template - void f(DynamicBuffer& buffer) - { - static_assert(is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - ... - @endcode - - Use with `std::enable_if` (SFINAE): - - @code - template - typename std::enable_if::value>::type - f(DynamicBuffer const& buffer); - @endcode -*/ -#if BEAST_DOXYGEN -template -struct is_dynamic_buffer : std::integral_constant {}; -#else -template -struct is_dynamic_buffer : std::false_type {}; - -template -struct is_dynamic_buffer() = - std::declval().size(), - std::declval() = - std::declval().max_size(), - std::declval() = - std::declval().capacity(), - std::declval().commit(std::declval()), - std::declval().consume(std::declval()), - (void)0)> > : std::integral_constant::value && - is_mutable_buffer_sequence< - typename T::mutable_buffers_type>::value && - std::is_same().data())>::value && - std::is_same().prepare( - std::declval()))>::value - > -{ -}; - -// Special case for Boost.Asio which doesn't adhere to -// net-ts but still provides a read_size_helper so things work -template -struct is_dynamic_buffer< - boost::asio::basic_streambuf> : std::true_type -{ -}; -#endif - -//------------------------------------------------------------------------------ -// -// Handler concepts -// -//------------------------------------------------------------------------------ - -/** Determine if `T` meets the requirements of @b CompletionHandler. - - This trait checks whether a type meets the requirements for a completion - handler, and is also callable with the specified signature. - Metafunctions are used to perform compile time checking of template - types. This type will be `std::true_type` if `T` meets the requirements, - else the type will be `std::false_type`. - - @par Example - - Use with `static_assert`: - - @code - struct handler - { - void operator()(error_code&); - }; - - static_assert(is_completion_handler::value, - "Not a completion handler"); - @endcode -*/ -template -#if BEAST_DOXYGEN -using is_completion_handler = std::integral_constant; -#else -using is_completion_handler = std::integral_constant::type>::value && - detail::is_invocable::value>; -#endif - -//------------------------------------------------------------------------------ -// -// Stream concepts -// -//------------------------------------------------------------------------------ - -/** Determine if `T` has the `get_io_service` member. - - Metafunctions are used to perform compile time checking of template - types. This type will be `std::true_type` if `T` has the member - function with the correct signature, else type will be `std::false_type`. - - @par Example - - Use with tag dispatching: - - @code - template - void maybe_hello(T& t, std::true_type) - { - t.get_io_service().post([]{ std::cout << "Hello, world!" << std::endl; }); - } - - template - void maybe_hello(T&, std::false_type) - { - // T does not have get_io_service - } - - template - void maybe_hello(T& t) - { - maybe_hello(t, has_get_io_service{}); - } - @endcode - - Use with `static_assert`: - - @code - struct stream - { - boost::asio::io_service& get_io_service(); - }; - - static_assert(has_get_io_service::value, - "Missing get_io_service member"); - @endcode -*/ -#if BEAST_DOXYGEN -template -struct has_get_io_service : std::integral_constant{}; -#else -template -struct has_get_io_service : std::false_type {}; - -template -struct has_get_io_service( - std::declval().get_io_service()), - (void)0)>> : std::true_type {}; -#endif - -/** Returns `T::lowest_layer_type` if it exists, else `T` - - This will contain a nested `type` equal to `T::lowest_layer_type` - if it exists, else `type` will be equal to `T`. - - @par Example - - Declaring a wrapper: - - @code - template - struct stream_wrapper - { - using next_layer_type = typename std::remove_reference::type; - using lowest_layer_type = typename get_lowest_layer::type; - }; - @endcode - - Defining a metafunction: - - @code - /// Alias for `std::true_type` if `T` wraps another stream - template - using is_stream_wrapper : std::integral_constant::type>::value> {}; - @endcode -*/ -#if BEAST_DOXYGEN -template -struct get_lowest_layer; -#else -template -struct get_lowest_layer -{ - using type = T; -}; - -template -struct get_lowest_layer> -{ - using type = typename T::lowest_layer_type; -}; -#endif - -/** Determine if `T` meets the requirements of @b AsyncReadStream. - - Metafunctions are used to perform compile time checking of template - types. This type will be `std::true_type` if `T` meets the requirements, - else the type will be `std::false_type`. - - @par Example - - Use with `static_assert`: - - @code - template - void f(AsyncReadStream& stream) - { - static_assert(is_async_read_stream::value, - "AsyncReadStream requirements not met"); - ... - @endcode - - Use with `std::enable_if` (SFINAE): - - @code - template - typename std::enable_if::value>::type - f(AsyncReadStream& stream); - @endcode -*/ -#if BEAST_DOXYGEN -template -struct is_async_read_stream : std::integral_constant{}; -#else -template -struct is_async_read_stream : std::false_type {}; - -template -struct is_async_read_stream().async_read_some( - std::declval(), - std::declval()), - (void)0)>> : std::integral_constant::value - > {}; -#endif - -/** Determine if `T` meets the requirements of @b AsyncWriteStream. - - Metafunctions are used to perform compile time checking of template - types. This type will be `std::true_type` if `T` meets the requirements, - else the type will be `std::false_type`. - - @par Example - - Use with `static_assert`: - - @code - template - void f(AsyncWriteStream& stream) - { - static_assert(is_async_write_stream::value, - "AsyncWriteStream requirements not met"); - ... - @endcode - - Use with `std::enable_if` (SFINAE): - - @code - template - typename std::enable_if::value>::type - f(AsyncWriteStream& stream); - @endcode -*/ -#if BEAST_DOXYGEN -template -struct is_async_write_stream : std::integral_constant{}; -#else -template -struct is_async_write_stream : std::false_type {}; - -template -struct is_async_write_stream().async_write_some( - std::declval(), - std::declval()), - (void)0)>> : std::integral_constant::value - > {}; -#endif - -/** Determine if `T` meets the requirements of @b SyncReadStream. - - Metafunctions are used to perform compile time checking of template - types. This type will be `std::true_type` if `T` meets the requirements, - else the type will be `std::false_type`. - - @par Example - - Use with `static_assert`: - - @code - template - void f(SyncReadStream& stream) - { - static_assert(is_sync_read_stream::value, - "SyncReadStream requirements not met"); - ... - @endcode - - Use with `std::enable_if` (SFINAE): - - @code - template - typename std::enable_if::value>::type - f(SyncReadStream& stream); - @endcode -*/ -#if BEAST_DOXYGEN -template -struct is_sync_read_stream : std::integral_constant{}; -#else -template -struct is_sync_read_stream : std::false_type {}; - -template -struct is_sync_read_stream() = std::declval().read_some( - std::declval()), - std::declval() = std::declval().read_some( - std::declval(), - std::declval()), - (void)0)>> : std::integral_constant::value - > {}; -#endif - -/** Determine if `T` meets the requirements of @b SyncWriterStream. - - Metafunctions are used to perform compile time checking of template - types. This type will be `std::true_type` if `T` meets the requirements, - else the type will be `std::false_type`. - - @par Example - - Use with `static_assert`: - - @code - template - void f(SyncReadStream& stream) - { - static_assert(is_sync_read_stream::value, - "SyncReadStream requirements not met"); - ... - @endcode - - Use with `std::enable_if` (SFINAE): - - @code - template - typename std::enable_if::value>::type - f(SyncReadStream& stream); - @endcode -*/ -#if BEAST_DOXYGEN -template -struct is_sync_write_stream : std::integral_constant{}; -#else -template -struct is_sync_write_stream : std::false_type {}; - -template -struct is_sync_write_stream() = std::declval().write_some( - std::declval()), - std::declval() = std::declval().write_some( - std::declval(), - std::declval()), - (void)0)>> : std::integral_constant::value - > {}; -#endif - -/** Determine if `T` meets the requirements of @b AsyncStream. - - Metafunctions are used to perform compile time checking of template - types. This type will be `std::true_type` if `T` meets the requirements, - else the type will be `std::false_type`. - - @par Example - - Use with `static_assert`: - - @code - template - void f(AsyncStream& stream) - { - static_assert(is_async_stream::value, - "AsyncStream requirements not met"); - ... - @endcode - - Use with `std::enable_if` (SFINAE): - - @code - template - typename std::enable_if::value>::type - f(AsyncStream& stream); - @endcode -*/ -#if BEAST_DOXYGEN -template -struct is_async_stream : std::integral_constant{}; -#else -template -using is_async_stream = std::integral_constant::value && is_async_write_stream::value>; -#endif - -/** Determine if `T` meets the requirements of @b SyncStream. - - Metafunctions are used to perform compile time checking of template - types. This type will be `std::true_type` if `T` meets the requirements, - else the type will be `std::false_type`. - - @par Example - - Use with `static_assert`: - - @code - template - void f(SyncStream& stream) - { - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - ... - @endcode - - Use with `std::enable_if` (SFINAE): - - @code - template - typename std::enable_if::value>::type - f(SyncStream& stream); - @endcode -*/ -#if BEAST_DOXYGEN -template -struct is_sync_stream : std::integral_constant{}; -#else -template -using is_sync_stream = std::integral_constant::value && is_sync_write_stream::value>; -#endif - -//------------------------------------------------------------------------------ -// -// File concepts -// -//------------------------------------------------------------------------------ - -/** Determine if `T` meets the requirements of @b File. - - Metafunctions are used to perform compile time checking of template - types. This type will be `std::true_type` if `T` meets the requirements, - else the type will be `std::false_type`. - - @par Example - - Use with `static_assert`: - - @code - template - void f(File& file) - { - static_assert(is_file::value, - "File requirements not met"); - ... - @endcode - - Use with `std::enable_if` (SFINAE): - - @code - template - typename std::enable_if::value>::type - f(File& file); - @endcode -*/ -#if BEAST_DOXYGEN -template -struct is_file : std::integral_constant{}; -#else -template -struct is_file : std::false_type {}; - -template -struct is_file() = std::declval().is_open(), - std::declval().close(std::declval()), - std::declval().open( - std::declval(), - std::declval(), - std::declval()), - std::declval() = std::declval().size( - std::declval()), - std::declval() = std::declval().pos( - std::declval()), - std::declval().seek( - std::declval(), - std::declval()), - std::declval() = std::declval().read( - std::declval(), - std::declval(), - std::declval()), - std::declval() = std::declval().write( - std::declval(), - std::declval(), - std::declval()), - (void)0)>> : std::integral_constant::value && - std::is_destructible::value - > {}; -#endif - -} // beast - -#endif diff --git a/src/beast/include/beast/http.hpp b/src/beast/include/beast/http.hpp deleted file mode 100644 index 4f13500e4f8..00000000000 --- a/src/beast/include/beast/http.hpp +++ /dev/null @@ -1,34 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_HPP -#define BEAST_HTTP_HPP - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#endif diff --git a/src/beast/include/beast/http/basic_parser.hpp b/src/beast/include/beast/http/basic_parser.hpp deleted file mode 100644 index 16de78ef81e..00000000000 --- a/src/beast/include/beast/http/basic_parser.hpp +++ /dev/null @@ -1,509 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_BASIC_PARSER_HPP -#define BEAST_HTTP_BASIC_PARSER_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -/** A parser for decoding HTTP/1 wire format messages. - - This parser is designed to efficiently parse messages in the - HTTP/1 wire format. It allocates no memory when input is - presented as a single contiguous buffer, and uses minimal - state. It will handle chunked encoding and it understands - the semantics of the Connection, Content-Length, and Upgrade - fields. - The parser is optimized for the case where the input buffer - sequence consists of a single contiguous buffer. The - @ref beast::flat_buffer class is provided, which guarantees - that the input sequence of the stream buffer will be represented - by exactly one contiguous buffer. To ensure the optimum performance - of the parser, use @ref beast::flat_buffer with HTTP algorithms - such as @ref beast::http::read, @ref beast::http::read_some, - @ref beast::http::async_read, and @ref beast::http::async_read_some. - Alternatively, the caller may use custom techniques to ensure that - the structured portion of the HTTP message (header or chunk header) - is contained in a linear buffer. - - The interface uses CRTP (Curiously Recurring Template Pattern). - To use this class directly, derive from @ref basic_parser. When - bytes are presented, the implementation will make a series of zero - or more calls to derived class members functions (termed "callbacks" - in this context) matching a specific signature. - - Every callback must be provided by the derived class, or else - a compilation error will be generated. This exemplar shows - the signature and description of the callbacks required in - the derived class. - For each callback, the function will ensure that `!ec` is `true` - if there was no error or set to the appropriate error code if - there was one. If an error is set, the value is propagated to - the caller of the parser. - - @tparam isRequest A `bool` indicating whether the parser will be - presented with request or response message. - - @tparam Derived The derived class type. This is part of the - Curiously Recurring Template Pattern interface. - - @note If the parser encounters a field value with obs-fold - longer than 4 kilobytes in length, an error is generated. -*/ -template -class basic_parser - : private detail::basic_parser_base -{ - template - friend class basic_parser; - - // limit on the size of the stack flat buffer - static std::size_t constexpr max_stack_buffer = 8192; - - // Message will be complete after reading header - static unsigned constexpr flagSkipBody = 1<< 0; - - // Consume input buffers across semantic boundaries - static unsigned constexpr flagEager = 1<< 1; - - // The parser has read at least one byte - static unsigned constexpr flagGotSome = 1<< 2; - - // Message semantics indicate a body is expected. - // cleared if flagSkipBody set - // - static unsigned constexpr flagHasBody = 1<< 3; - - static unsigned constexpr flagHTTP11 = 1<< 4; - static unsigned constexpr flagNeedEOF = 1<< 5; - static unsigned constexpr flagExpectCRLF = 1<< 6; - static unsigned constexpr flagConnectionClose = 1<< 7; - static unsigned constexpr flagConnectionUpgrade = 1<< 8; - static unsigned constexpr flagConnectionKeepAlive = 1<< 9; - static unsigned constexpr flagContentLength = 1<< 10; - static unsigned constexpr flagChunked = 1<< 11; - static unsigned constexpr flagUpgrade = 1<< 12; - static unsigned constexpr flagFinalChunk = 1<< 13; - - static - std::uint64_t - default_body_limit(std::true_type) - { - // limit for requests - return 1 * 1024 * 1024; // 1MB - } - - static - std::uint64_t - default_body_limit(std::false_type) - { - // limit for responses - return 8 * 1024 * 1024; // 8MB - } - - std::uint64_t body_limit_; // max payload body - std::uint64_t len_; // size of chunk or body - std::unique_ptr buf_; // temp storage - std::size_t buf_len_ = 0; // size of buf_ - std::size_t skip_ = 0; // resume search here - std::uint32_t - header_limit_ = 8192; // max header size - unsigned short status_; // response status - state state_ = // initial state - state::nothing_yet; - unsigned f_ = 0; // flags - -public: - /// `true` if this parser parses requests, `false` for responses. - using is_request = - std::integral_constant; - - /// Copy constructor (disallowed) - basic_parser(basic_parser const&) = delete; - - /// Copy assignment (disallowed) - basic_parser& operator=(basic_parser const&) = delete; - - /// Destructor - ~basic_parser() = default; - - /// Default constructor - basic_parser(); - - /** Move constructor - - After the move, the only valid operation on the - moved-from object is destruction. - */ - template - basic_parser(basic_parser&&); - - /** Returns a reference to this object as a @ref basic_parser. - - This is used to pass a derived class where a base class is - expected, to choose a correct function overload when the - resolution would be ambiguous. - */ - basic_parser& - base() - { - return *this; - } - - /** Returns a constant reference to this object as a @ref basic_parser. - - This is used to pass a derived class where a base class is - expected, to choose a correct function overload when the - resolution would be ambiguous. - */ - basic_parser const& - base() const - { - return *this; - } - - /// Returns `true` if the parser has received at least one byte of input. - bool - got_some() const - { - return state_ != state::nothing_yet; - } - - /** Returns `true` if the message is complete. - - The message is complete after the full header is prduced - and one of the following is true: - - @li The skip body option was set. - - @li The semantics of the message indicate there is no body. - - @li The semantics of the message indicate a body is expected, - and the entire body was parsed. - */ - bool - is_done() const - { - return state_ == state::complete; - } - - /** Returns `true` if a the parser has produced the full header. - */ - bool - is_header_done() const - { - return state_ > state::fields; - } - - /** Returns `true` if the message is an upgrade message. - - @note The return value is undefined unless - @ref is_header_done would return `true`. - */ - bool - is_upgrade() const - { - return (f_ & flagConnectionUpgrade) != 0; - } - - /** Returns `true` if the last value for Transfer-Encoding is "chunked". - - @note The return value is undefined unless - @ref is_header_done would return `true`. - */ - bool - is_chunked() const - { - return (f_ & flagChunked) != 0; - } - - /** Returns `true` if the message has keep-alive connection semantics. - - @note The return value is undefined unless - @ref is_header_done would return `true`. - */ - bool - is_keep_alive() const; - - /** Returns the optional value of Content-Length if known. - - @note The return value is undefined unless - @ref is_header_done would return `true`. - */ - boost::optional - content_length() const; - - /** Returns `true` if the message semantics require an end of file. - - Depending on the contents of the header, the parser may - require and end of file notification to know where the end - of the body lies. If this function returns `true` it will be - necessary to call @ref put_eof when there will never be additional - data from the input. - */ - bool - need_eof() const - { - return (f_ & flagNeedEOF) != 0; - } - - /** Set the limit on the payload body. - - This function sets the maximum allowed size of the payload body, - before any encodings except chunked have been removed. Depending - on the message semantics, one of these cases will apply: - - @li The Content-Length is specified and exceeds the limit. In - this case the result @ref error::body_limit is returned - immediately after the header is parsed. - - @li The Content-Length is unspecified and the chunked encoding - is not specified as the last encoding. In this case the end of - message is determined by the end of file indicator on the - associated stream or input source. If a sufficient number of - body payload octets are presented to the parser to exceed the - configured limit, the parse fails with the result - @ref error::body_limit - - @li The Transfer-Encoding specifies the chunked encoding as the - last encoding. In this case, when the number of payload body - octets produced by removing the chunked encoding exceeds - the configured limit, the parse fails with the result - @ref error::body_limit. - - Setting the limit after any body octets have been parsed - results in undefined behavior. - - The default limit is 1MB for requests and 8MB for responses. - - @param v The payload body limit to set - */ - void - body_limit(std::uint64_t v) - { - body_limit_ = v; - } - - /** Set a limit on the total size of the header. - - This function sets the maximum allowed size of the header - including all field name, value, and delimiter characters - and also including the CRLF sequences in the serialized - input. If the end of the header is not found within the - limit of the header size, the error @ref error::header_limit - is returned by @ref put. - - Setting the limit after any header octets have been parsed - results in undefined behavior. - */ - void - header_limit(std::uint32_t v) - { - header_limit_ = v; - } - - /// Returns `true` if the eager parse option is set. - bool - eager() const - { - return (f_ & flagEager) != 0; - } - - /** Set the eager parse option. - - Normally the parser returns after successfully parsing a structured - element (header, chunk header, or chunk body) even if there are octets - remaining in the input. This is necessary when attempting to parse the - header first, or when the caller wants to inspect information which may - be invalidated by subsequent parsing, such as a chunk extension. The - `eager` option controls whether the parser keeps going after parsing - structured element if there are octets remaining in the buffer and no - error occurs. This option is automatically set or cleared during certain - stream operations to improve performance with no change in functionality. - - The default setting is `false`. - - @param v `true` to set the eager parse option or `false` to disable it. - */ - void - eager(bool v) - { - if(v) - f_ |= flagEager; - else - f_ &= ~flagEager; - } - - /// Returns `true` if the skip parse option is set. - bool - skip() - { - return (f_ & flagSkipBody) != 0; - } - - /** Set the skip parse option. - - This option controls whether or not the parser expects to see an HTTP - body, regardless of the presence or absence of certain fields such as - Content-Length or a chunked Transfer-Encoding. Depending on the request, - some responses do not carry a body. For example, a 200 response to a - CONNECT request from a tunneling proxy, or a response to a HEAD request. - In these cases, callers may use this function inform the parser that - no body is expected. The parser will consider the message complete - after the header has been received. - - @param v `true` to set the skip body option or `false` to disable it. - - @note This function must called before any bytes are processed. - */ - void - skip(bool v); - - /** Write a buffer sequence to the parser. - - This function attempts to incrementally parse the HTTP - message data stored in the caller provided buffers. Upon - success, a positive return value indicates that the parser - made forward progress, consuming that number of - bytes. - - In some cases there may be an insufficient number of octets - in the input buffer in order to make forward progress. This - is indicated by the code @ref error::need_more. When - this happens, the caller should place additional bytes into - the buffer sequence and call @ref put again. - - The error code @ref error::need_more is special. When this - error is returned, a subsequent call to @ref put may succeed - if the buffers have been updated. Otherwise, upon error - the parser may not be restarted. - - @param buffers An object meeting the requirements of - @b ConstBufferSequence that represents the next chunk of - message data. If the length of this buffer sequence is - one, the implementation will not allocate additional memory. - The class @ref flat_buffer is provided as one way to - meet this requirement - - @param ec Set to the error, if any occurred. - - @return The number of octets consumed in the buffer - sequence. The caller should remove these octets even if the - error is set. - */ - template - std::size_t - put(ConstBufferSequence const& buffers, error_code& ec); - -#if ! BEAST_DOXYGEN - std::size_t - put(boost::asio::const_buffers_1 const& buffer, - error_code& ec); -#endif - - /** Inform the parser that the end of stream was reached. - - In certain cases, HTTP needs to know where the end of - the stream is. For example, sometimes servers send - responses without Content-Length and expect the client - to consume input (for the body) until EOF. Callbacks - and errors will still be processed as usual. - - This is typically called when a read from the - underlying stream object sets the error code to - `boost::asio::error::eof`. - - @note Only valid after parsing a complete header. - - @param ec Set to the error, if any occurred. - */ - void - put_eof(error_code& ec); - -private: - inline - Derived& - impl() - { - return *static_cast(this); - } - - template - std::size_t - put_from_stack(std::size_t size, - ConstBufferSequence const& buffers, - error_code& ec); - - void - maybe_need_more( - char const* p, std::size_t n, - error_code& ec); - - void - parse_start_line( - char const*& p, char const* last, - error_code& ec, std::true_type); - - void - parse_start_line( - char const*& p, char const* last, - error_code& ec, std::false_type); - - void - parse_fields( - char const*& p, char const* last, - error_code& ec); - - void - finish_header( - error_code& ec, std::true_type); - - void - finish_header( - error_code& ec, std::false_type); - - void - parse_body(char const*& p, - std::size_t n, error_code& ec); - - void - parse_body_to_eof(char const*& p, - std::size_t n, error_code& ec); - - void - parse_chunk_header(char const*& p, - std::size_t n, error_code& ec); - - void - parse_chunk_body(char const*& p, - std::size_t n, error_code& ec); - - void - do_field(field f, - string_view value, error_code& ec); -}; - -} // http -} // beast - -#include - -#endif diff --git a/src/beast/include/beast/http/buffer_body.hpp b/src/beast/include/beast/http/buffer_body.hpp deleted file mode 100644 index 61a99f178fc..00000000000 --- a/src/beast/include/beast/http/buffer_body.hpp +++ /dev/null @@ -1,224 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_BUFFER_BODY_HPP -#define BEAST_HTTP_BUFFER_BODY_HPP - -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -/** A @b Body using a caller provided buffer - - Messages using this body type may be serialized and parsed. - To use this class, the caller must initialize the members - of @ref buffer_body::value_type to appropriate values before - each call to read or write during a stream operation. -*/ -struct buffer_body -{ - /// The type of the body member when used in a message. - struct value_type - { - /** A pointer to a contiguous area of memory of @ref size octets, else `nullptr`. - - @par When Serializing - - If this is `nullptr` and `more` is `true`, the error - @ref error::need_buffer will be returned from @ref serializer::get - Otherwise, the serializer will use the memory pointed to - by `data` having `size` octets of valid storage as the - next buffer representing the body. - - @par When Parsing - - If this is `nullptr`, the error @ref error::need_buffer - will be returned from @ref parser::put. Otherwise, the - parser will store body octets into the memory pointed to - by `data` having `size` octets of valid storage. After - octets are stored, the `data` and `size` members are - adjusted: `data` is incremented to point to the next - octet after the data written, while `size` is decremented - to reflect the remaining space at the memory location - pointed to by `data`. - */ - void* data = nullptr; - - /** The number of octets in the buffer pointed to by @ref data. - - @par When Serializing - - If `data` is `nullptr` during serialization, this value - is ignored. Otherwise, it represents the number of valid - body octets pointed to by `data`. - - @par When Parsing - - The value of this field will be decremented during parsing - to indicate the number of remaining free octets in the - buffer pointed to by `data`. When it reaches zero, the - parser will return @ref error::need_buffer, indicating to - the caller that the values of `data` and `size` should be - updated to point to a new memory buffer. - */ - std::size_t size = 0; - - /** `true` if this is not the last buffer. - - @par When Serializing - - If this is `true` and `data` is `nullptr`, the error - @ref error::need_buffer will be returned from @ref serializer::get - - @par When Parsing - - This field is not used during parsing. - */ - bool more = true; - }; - - /** The algorithm for serializing the body - - Meets the requirements of @b BodyReader. - */ -#if BEAST_DOXYGEN - using reader = implementation_defined; -#else - class reader - { - bool toggle_ = false; - value_type const& body_; - - public: - using const_buffers_type = - boost::asio::const_buffers_1; - - template - explicit - reader(message const& msg) - : body_(msg.body) - { - } - - void - init(error_code& ec) - { - ec.assign(0, ec.category()); - } - - boost::optional< - std::pair> - get(error_code& ec) - { - if(toggle_) - { - if(body_.more) - { - toggle_ = false; - ec = error::need_buffer; - } - else - { - ec.assign(0, ec.category()); - } - return boost::none; - } - if(body_.data) - { - ec.assign(0, ec.category()); - toggle_ = true; - return {{const_buffers_type{ - body_.data, body_.size}, body_.more}}; - } - if(body_.more) - ec = error::need_buffer; - else - ec.assign(0, ec.category()); - return boost::none; - } - }; -#endif - - /** The algorithm for parsing the body - - Meets the requirements of @b BodyReader. - */ -#if BEAST_DOXYGEN - using writer = implementation_defined; -#else - class writer - { - value_type& body_; - - public: - template - explicit - writer(message& m) - : body_(m.body) - { - } - - void - init(boost::optional const&, error_code& ec) - { - ec.assign(0, ec.category()); - } - - template - std::size_t - put(ConstBufferSequence const& buffers, - error_code& ec) - { - using boost::asio::buffer_size; - using boost::asio::buffer_copy; - if(! body_.data) - { - ec = error::need_buffer; - return 0; - } - auto const bytes_transferred = - buffer_copy(boost::asio::buffer( - body_.data, body_.size), buffers); - body_.data = reinterpret_cast( - body_.data) + bytes_transferred; - body_.size -= bytes_transferred; - if(bytes_transferred == buffer_size(buffers)) - ec.assign(0, ec.category()); - else - ec = error::need_buffer; - return bytes_transferred; - } - - void - finish(error_code& ec) - { - ec.assign(0, ec.category()); - } - }; -#endif -}; - -#if ! BEAST_DOXYGEN -// operator<< is not supported for buffer_body -template -std::ostream& -operator<<(std::ostream& os, message const& msg) = delete; -#endif - -} // http -} // beast - -#endif diff --git a/src/beast/include/beast/http/detail/basic_parsed_list.hpp b/src/beast/include/beast/http/detail/basic_parsed_list.hpp deleted file mode 100644 index 98f9acae17c..00000000000 --- a/src/beast/include/beast/http/detail/basic_parsed_list.hpp +++ /dev/null @@ -1,194 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_DETAIL_BASIC_PARSED_LIST_HPP -#define BEAST_HTTP_DETAIL_BASIC_PARSED_LIST_HPP - -#include -#include -#include -#include - -namespace beast { -namespace http { -namespace detail { - -/** A list parser which presents the sequence as a container. -*/ -template -class basic_parsed_list -{ - string_view s_; - -public: - /// The type of policy this list uses for parsing. - using policy_type = Policy; - - /// The type of each element in the list. - using value_type = typename Policy::value_type; - - /// A constant iterator to a list element. -#if BEAST_DOXYGEN - using const_iterator = implementation_defined; -#else - class const_iterator; -#endif - - class const_iterator - : private beast::detail:: - empty_base_optimization - { - basic_parsed_list const* list_ = nullptr; - char const* it_ = nullptr; - typename Policy::value_type v_; - bool error_ = false; - - public: - using value_type = - typename Policy::value_type; - using reference = value_type const&; - using pointer = value_type const*; - using difference_type = std::ptrdiff_t; - using iterator_category = - std::forward_iterator_tag; - - const_iterator() = default; - - bool - operator==( - const_iterator const& other) const - { - return - other.list_ == list_ && - other.it_ == it_; - } - - bool - operator!=( - const_iterator const& other) const - { - return ! (*this == other); - } - - reference - operator*() const - { - return v_; - } - - const_iterator& - operator++() - { - increment(); - return *this; - } - - const_iterator - operator++(int) - { - auto temp = *this; - ++(*this); - return temp; - } - - bool - error() const - { - return error_; - } - - private: - friend class basic_parsed_list; - - const_iterator( - basic_parsed_list const& list, bool at_end) - : list_(&list) - , it_(at_end ? nullptr : - list.s_.begin()) - { - if(! at_end) - increment(); - } - - void - increment() - { - if(! this->member()( - v_, it_, list_->s_)) - { - it_ = nullptr; - error_ = true; - } - } - }; - - /// Construct a list from a string - explicit - basic_parsed_list(string_view s) - : s_(s) - { - } - - /// Return a const iterator to the beginning of the list - const_iterator begin() const; - - /// Return a const iterator to the end of the list - const_iterator end() const; - - /// Return a const iterator to the beginning of the list - const_iterator cbegin() const; - - /// Return a const iterator to the end of the list - const_iterator cend() const; -}; - -template -inline -auto -basic_parsed_list:: -begin() const -> - const_iterator -{ - return const_iterator{*this, false}; -} - -template -inline -auto -basic_parsed_list:: -end() const -> - const_iterator -{ - return const_iterator{*this, true}; -} - -template -inline -auto -basic_parsed_list:: -cbegin() const -> - const_iterator -{ - return const_iterator{*this, false}; -} - -template -inline -auto -basic_parsed_list:: -cend() const -> - const_iterator -{ - return const_iterator{*this, true}; -} - -} // detail -} // http -} // beast - -#endif - diff --git a/src/beast/include/beast/http/detail/basic_parser.hpp b/src/beast/include/beast/http/detail/basic_parser.hpp deleted file mode 100644 index d61a32dc932..00000000000 --- a/src/beast/include/beast/http/detail/basic_parser.hpp +++ /dev/null @@ -1,718 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_DETAIL_BASIC_PARSER_HPP -#define BEAST_HTTP_DETAIL_BASIC_PARSER_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace http { -namespace detail { - -class basic_parser_base -{ -protected: - // limit on the size of the obs-fold buffer - // - // https://stackoverflow.com/questions/686217/maximum-on-http-header-values - // - static std::size_t constexpr max_obs_fold = 4096; - - enum class state - { - nothing_yet = 0, - start_line, - fields, - body0, - body, - body_to_eof0, - body_to_eof, - chunk_header0, - chunk_header, - chunk_body, - complete - }; - - static - bool - is_pathchar(char c) - { - // VFALCO This looks the same as the one below... - - // TEXT = - static bool constexpr tab[256] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16 - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 32 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 48 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 64 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 80 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 96 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, // 112 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 128 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 144 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 160 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 176 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 192 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 208 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 224 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // 240 - }; - return tab[static_cast(c)]; - } - - static - inline - bool - unhex(unsigned char& d, char c) - { - static signed char constexpr tab[256] = { - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 0 - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 16 - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 32 - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1, // 48 - -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 64 - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 80 - -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1, // 96 - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 // 112 - - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 // 128 - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 // 144 - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 // 160 - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 // 176 - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 // 192 - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 // 208 - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 // 224 - -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 // 240 - }; - d = static_cast( - tab[static_cast(c)]); - return d != static_cast(-1); - } - - static - bool - is_digit(char c) - { - return static_cast(c-'0') < 10; - } - - static - bool - is_print(char c) - { - return static_cast(c-32) < 95; - } - - template - static - FwdIt - trim_front(FwdIt it, FwdIt const& end) - { - while(it != end) - { - if(*it != ' ' && *it != '\t') - break; - ++it; - } - return it; - } - - template - static - RanIt - trim_back( - RanIt it, RanIt const& first) - { - while(it != first) - { - auto const c = it[-1]; - if(c != ' ' && c != '\t') - break; - --it; - } - return it; - } - - static - string_view - make_string(char const* first, char const* last) - { - return {first, static_cast< - std::size_t>(last - first)}; - } - - //-------------------------------------------------------------------------- - - std::pair - find_fast( - char const* buf, - char const* buf_end, - char const* ranges, - size_t ranges_size) - { - bool found = false; - boost::ignore_unused(buf_end, ranges, ranges_size); - return {buf, found}; - } - - // VFALCO Can SIMD help this? - static - char const* - find_eol( - char const* it, char const* last, - error_code& ec) - { - for(;;) - { - if(it == last) - { - ec.assign(0, ec.category()); - return nullptr; - } - if(*it == '\r') - { - if(++it == last) - { - ec.assign(0, ec.category()); - return nullptr; - } - if(*it != '\n') - { - ec = error::bad_line_ending; - return nullptr; - } - ec.assign(0, ec.category()); - return ++it; - } - // VFALCO Should we handle the legacy case - // for lines terminated with a single '\n'? - ++it; - } - } - - // VFALCO Can SIMD help this? - static - char const* - find_eom(char const* p, char const* last) - { - for(;;) - { - if(p + 4 > last) - return nullptr; - if(p[3] != '\n') - { - if(p[3] == '\r') - ++p; - else - p += 4; - } - else if(p[2] != '\r') - { - p += 4; - } - else if(p[1] != '\n') - { - p += 2; - } - else if(p[0] != '\r') - { - p += 2; - } - else - { - return p + 4; - } - } - } - - //-------------------------------------------------------------------------- - - char const* - parse_token_to_eol( - char const* p, - char const* last, - char const*& token_last, - error_code& ec) - { - for(;; ++p) - { - if(p >= last) - { - ec = error::need_more; - return p; - } - if(BOOST_UNLIKELY(! is_print(*p))) - if((BOOST_LIKELY(static_cast< - unsigned char>(*p) < '\040') && - BOOST_LIKELY(*p != '\011')) || - BOOST_UNLIKELY(*p == '\177')) - goto found_control; - } - found_control: - if(BOOST_LIKELY(*p == '\r')) - { - if(++p >= last) - { - ec = error::need_more; - return last; - } - if(*p++ != '\n') - { - ec = error::bad_line_ending; - return last; - } - token_last = p - 2; - } - #if 0 - // VFALCO This allows `\n` by itself - // to terminate a line - else if(*p == '\n') - { - token_last = p; - ++p; - } - #endif - else - { - // invalid character - return nullptr; - } - return p; - } - - template - static - bool - parse_dec(Iter it, Iter last, Unsigned& v) - { - if(! is_digit(*it)) - return false; - v = *it - '0'; - for(;;) - { - if(! is_digit(*++it)) - break; - auto const d = *it - '0'; - if(v > ((std::numeric_limits< - Unsigned>::max)() - 10) / 10) - return false; - v = 10 * v + d; - } - return it == last; - } - - template - bool - parse_hex(Iter& it, Unsigned& v) - { - unsigned char d; - if(! unhex(d, *it)) - return false; - v = d; - for(;;) - { - if(! unhex(d, *++it)) - break; - auto const v0 = v; - v = 16 * v + d; - if(v < v0) - return false; - } - return true; - } - - static - bool - parse_crlf(char const*& it) - { - if( it[0] != '\r' || it[1] != '\n') - return false; - it += 2; - return true; - } - - static - void - parse_method( - char const*& it, char const* last, - string_view& result, error_code& ec) - { - // parse token SP - auto const first = it; - for(;; ++it) - { - if(it + 1 > last) - { - ec = error::need_more; - return; - } - if(! detail::is_tchar(*it)) - break; - } - if(it + 1 > last) - { - ec = error::need_more; - return; - } - if(*it != ' ') - { - ec = error::bad_method; - return; - } - if(it == first) - { - // cannot be empty - ec = error::bad_method; - return; - } - result = make_string(first, it++); - } - - static - void - parse_target( - char const*& it, char const* last, - string_view& result, error_code& ec) - { - // parse target SP - auto const first = it; - for(;; ++it) - { - if(it + 1 > last) - { - ec = error::need_more; - return; - } - if(! is_pathchar(*it)) - break; - } - if(it + 1 > last) - { - ec = error::need_more; - return; - } - if(*it != ' ') - { - ec = error::bad_target; - return; - } - if(it == first) - { - // cannot be empty - ec = error::bad_target; - return; - } - result = make_string(first, it++); - } - - static - void - parse_version( - char const*& it, char const* last, - int& result, error_code& ec) - { - if(it + 8 > last) - { - ec = error::need_more; - return; - } - if(*it++ != 'H') - { - ec = error::bad_version; - return; - } - if(*it++ != 'T') - { - ec = error::bad_version; - return; - } - if(*it++ != 'T') - { - ec = error::bad_version; - return; - } - if(*it++ != 'P') - { - ec = error::bad_version; - return; - } - if(*it++ != '/') - { - ec = error::bad_version; - return; - } - if(! is_digit(*it)) - { - ec = error::bad_version; - return; - } - result = 10 * (*it++ - '0'); - if(*it++ != '.') - { - ec = error::bad_version; - return; - } - if(! is_digit(*it)) - { - ec = error::bad_version; - return; - } - result += *it++ - '0'; - } - - static - void - parse_status( - char const*& it, char const* last, - unsigned short& result, error_code& ec) - { - // parse 3(digit) SP - if(it + 4 > last) - { - ec = error::need_more; - return; - } - if(! is_digit(*it)) - { - ec = error::bad_status; - return; - } - result = 100 * (*it++ - '0'); - if(! is_digit(*it)) - { - ec = error::bad_status; - return; - } - result += 10 * (*it++ - '0'); - if(! is_digit(*it)) - { - ec = error::bad_status; - return; - } - result += *it++ - '0'; - if(*it++ != ' ') - { - ec = error::bad_status; - return; - } - } - - void - parse_reason( - char const*& it, char const* last, - string_view& result, error_code& ec) - { - auto const first = it; - char const* token_last = nullptr; - auto p = parse_token_to_eol( - it, last, token_last, ec); - if(ec) - return; - if(! p) - { - ec = error::bad_reason; - return; - } - result = make_string(first, token_last); - it = p; - } - - template - void - parse_field( - char const*& p, - char const* last, - string_view& name, - string_view& value, - static_string& buf, - error_code& ec) - { - /* header-field = field-name ":" OWS field-value OWS - - field-name = token - field-value = *( field-content / obs-fold ) - field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ] - field-vchar = VCHAR / obs-text - - obs-fold = CRLF 1*( SP / HTAB ) - ; obsolete line folding - ; see Section 3.2.4 - - token = 1* - CHAR = - sep = "(" | ")" | "<" | ">" | "@" - | "," | ";" | ":" | "\" | <"> - | "/" | "[" | "]" | "?" | "=" - | "{" | "}" | SP | HT - */ - static char const* is_token = - "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" - "\0\1\0\1\1\1\1\1\0\0\1\1\0\1\1\0\1\1\1\1\1\1\1\1\1\1\0\0\0\0\0\0" - "\0\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\0\0\0\1\1" - "\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\0\1\0\1\0" - "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" - "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" - "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" - "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; - - // name - BOOST_ALIGNMENT(16) static const char ranges1[] = - "\x00 " /* control chars and up to SP */ - "\"\"" /* 0x22 */ - "()" /* 0x28,0x29 */ - ",," /* 0x2c */ - "//" /* 0x2f */ - ":@" /* 0x3a-0x40 */ - "[]" /* 0x5b-0x5d */ - "{\377"; /* 0x7b-0xff */ - auto first = p; - bool found; - std::tie(p, found) = find_fast( - p, last, ranges1, sizeof(ranges1)-1); - if(! found && p >= last) - { - ec = error::need_more; - return; - } - for(;;) - { - if(*p == ':') - break; - if(! is_token[static_cast< - unsigned char>(*p)]) - { - ec = error::bad_field; - return; - } - ++p; - if(p >= last) - { - ec = error::need_more; - return; - } - } - if(p == first) - { - // empty name - ec = error::bad_field; - return; - } - name = make_string(first, p); - ++p; // eat ':' - char const* token_last; - for(;;) - { - // eat leading ' ' and '\t' - for(;;++p) - { - if(p + 1 > last) - { - ec = error::need_more; - return; - } - if(! (*p == ' ' || *p == '\t')) - break; - } - // parse to CRLF - first = p; - p = parse_token_to_eol(p, last, token_last, ec); - if(ec) - return; - if(! p) - { - ec = error::bad_value; - return; - } - // Look 1 char past the CRLF to handle obs-fold. - if(p + 1 > last) - { - ec = error::need_more; - return; - } - token_last = - trim_back(token_last, first); - if(*p != ' ' && *p != '\t') - { - value = make_string(first, token_last); - return; - } - ++p; - if(token_last != first) - break; - } - buf.resize(0); - buf.append(first, token_last); - BOOST_ASSERT(! buf.empty()); - try - { - for(;;) - { - // eat leading ' ' and '\t' - for(;;++p) - { - if(p + 1 > last) - { - ec = error::need_more; - return; - } - if(! (*p == ' ' || *p == '\t')) - break; - } - // parse to CRLF - first = p; - p = parse_token_to_eol(p, last, token_last, ec); - if(ec) - return; - if(! p) - { - ec = error::bad_value; - return; - } - // Look 1 char past the CRLF to handle obs-fold. - if(p + 1 > last) - { - ec = error::need_more; - return; - } - token_last = trim_back(token_last, first); - if(first != token_last) - { - buf.push_back(' '); - buf.append(first, token_last); - } - if(*p != ' ' && *p != '\t') - { - value = {buf.data(), buf.size()}; - return; - } - ++p; - } - } - catch(std::length_error const&) - { - ec = error::header_limit; - return; - } - } -}; - -} // detail -} // http -} // beast - -#endif diff --git a/src/beast/include/beast/http/detail/chunk_encode.hpp b/src/beast/include/beast/http/detail/chunk_encode.hpp deleted file mode 100644 index 8b4a2e08c49..00000000000 --- a/src/beast/include/beast/http/detail/chunk_encode.hpp +++ /dev/null @@ -1,157 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_DETAIL_CHUNK_ENCODE_HPP -#define BEAST_HTTP_DETAIL_CHUNK_ENCODE_HPP - -#include -#include -#include -#include - -namespace beast { -namespace http { -namespace detail { - -/** A buffer sequence containing a chunk-encoding header -*/ -class chunk_header -{ - boost::asio::const_buffer cb_; - - // Storage for the longest hex string we might need - char buf_[2 * sizeof(std::size_t)]; - - template - void - copy(chunk_header const& other); - - template - void - prepare_impl(std::size_t n); - - template - static - OutIter - to_hex(OutIter last, std::size_t n) - { - if(n == 0) - { - *--last = '0'; - return last; - } - while(n) - { - *--last = "0123456789abcdef"[n&0xf]; - n>>=4; - } - return last; - } - -public: - using value_type = boost::asio::const_buffer; - - using const_iterator = value_type const*; - - /** Constructor (default) - - Default-constructed chunk headers are in an - undefined state. - */ - chunk_header() = default; - - /// Copy constructor - chunk_header(chunk_header const& other) - { - copy(other); - } - - /// Copy assignment - chunk_header& operator=(chunk_header const& other) - { - if (this != &other) - copy(other); - return *this; - } - - /** Construct a chunk header - - @param n The number of octets in this chunk. - */ - explicit - chunk_header(std::size_t n) - { - prepare_impl(n); - } - - const_iterator - begin() const - { - return &cb_; - } - - const_iterator - end() const - { - return begin() + 1; - } - - void - prepare(std::size_t n) - { - prepare_impl(n); - } -}; - -template -void -chunk_header:: -copy(chunk_header const& other) -{ - using boost::asio::buffer_copy; - auto const n = - boost::asio::buffer_size(other.cb_); - auto const mb = boost::asio::mutable_buffers_1( - &buf_[sizeof(buf_) - n], n); - cb_ = *mb.begin(); - buffer_copy(mb, - boost::asio::const_buffers_1(other.cb_)); -} - -template -void -chunk_header:: -prepare_impl(std::size_t n) -{ - auto const end = &buf_[sizeof(buf_)]; - auto it = to_hex(end, n); - cb_ = boost::asio::const_buffer{&*it, - static_cast( - std::distance(it, end))}; -} - -/// Returns a buffer sequence holding a CRLF for chunk encoding -inline -boost::asio::const_buffers_1 -chunk_crlf() -{ - return {"\r\n", 2}; -} - -/// Returns a buffer sequence holding a final chunk header -inline -boost::asio::const_buffers_1 -chunk_final() -{ - return {"0\r\n", 3}; -} - -} // detail -} // http -} // beast - -#endif diff --git a/src/beast/include/beast/http/detail/rfc7230.hpp b/src/beast/include/beast/http/detail/rfc7230.hpp deleted file mode 100644 index cd7093d9efe..00000000000 --- a/src/beast/include/beast/http/detail/rfc7230.hpp +++ /dev/null @@ -1,469 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_DETAIL_RFC7230_HPP -#define BEAST_HTTP_DETAIL_RFC7230_HPP - -#include -#include -#include - -namespace beast { -namespace http { -namespace detail { - -inline -bool -is_digit(char c) -{ - return c >= '0' && c <= '9'; -} - -inline -char -is_alpha(char c) -{ - static char constexpr tab[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 32 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 48 - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 64 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, // 80 - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 96 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, // 112 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 128 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 144 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 160 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 176 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 192 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 208 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 224 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // 240 - }; - BOOST_STATIC_ASSERT(sizeof(tab) == 256); - return tab[static_cast(c)]; -} - -inline -char -is_text(char c) -{ - // TEXT = - static char constexpr tab[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, // 0 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 32 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 48 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 64 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 80 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 96 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, // 112 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 128 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 144 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 160 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 176 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 192 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 208 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 224 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // 240 - }; - BOOST_STATIC_ASSERT(sizeof(tab) == 256); - return tab[static_cast(c)]; -} - -inline -char -is_tchar(char c) -{ - /* - tchar = "!" | "#" | "$" | "%" | "&" | - "'" | "*" | "+" | "-" | "." | - "^" | "_" | "`" | "|" | "~" | - DIGIT | ALPHA - */ - static char constexpr tab[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16 - 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, // 32 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, // 48 - 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 64 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, // 80 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 96 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, // 112 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 128 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 144 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 160 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 176 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 192 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 208 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 224 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // 240 - }; - BOOST_STATIC_ASSERT(sizeof(tab) == 256); - return tab[static_cast(c)]; -} - -inline -char -is_qdchar(char c) -{ - /* - qdtext = HTAB / SP / "!" / %x23-5B ; '#'-'[' / %x5D-7E ; ']'-'~' / obs-text - */ - static char constexpr tab[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, // 0 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16 - 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 32 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 48 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 64 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, // 80 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 96 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, // 112 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 128 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 144 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 160 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 176 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 192 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 208 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 224 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // 240 - }; - BOOST_STATIC_ASSERT(sizeof(tab) == 256); - return tab[static_cast(c)]; -} - -inline -char -is_qpchar(char c) -{ - /* - quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text ) - obs-text = %x80-FF - */ - static char constexpr tab[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, // 0 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 32 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 48 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 64 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 80 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 96 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, // 112 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 128 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 144 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 160 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 176 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 192 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 208 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 224 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // 240 - }; - BOOST_STATIC_ASSERT(sizeof(tab) == 256); - return tab[static_cast(c)]; -} - -// converts to lower case, -// returns 0 if not a valid text char -// -inline -char -to_value_char(char c) -{ - // TEXT = - static unsigned char constexpr tab[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, // 0 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16 - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, // 32 - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, // 48 - 64, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, // 64 - 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 91, 92, 93, 94, 95, // 80 - 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, // 96 - 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 0, // 112 - 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, // 128 - 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, // 144 - 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, // 160 - 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, // 176 - 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, // 192 - 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, // 208 - 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, // 224 - 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255 // 240 - }; - BOOST_STATIC_ASSERT(sizeof(tab) == 256); - return static_cast(tab[static_cast(c)]); -} - -// VFALCO TODO Make this return unsigned? -inline -std::int8_t -unhex(char c) -{ - static signed char constexpr tab[] = { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0 - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 16 - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 32 - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, // 48 - -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 64 - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 80 - -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 96 - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 112 - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 128 - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 144 - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 160 - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 176 - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 192 - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 208 - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 224 - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 // 240 - }; - BOOST_STATIC_ASSERT(sizeof(tab) == 256); - return tab[static_cast(c)]; -} - -template -inline -void -skip_ows(FwdIt& it, FwdIt const& end) -{ - while(it != end) - { - if(*it != ' ' && *it != '\t') - break; - ++it; - } -} - -template -inline -void -skip_ows_rev( - RanIt& it, RanIt const& first) -{ - while(it != first) - { - auto const c = it[-1]; - if(c != ' ' && c != '\t') - break; - --it; - } -} - -// obs-fold = CRLF 1*( SP / HTAB ) -// return `false` on parse error -// -template -inline -bool -skip_obs_fold( - FwdIt& it, FwdIt const& last) -{ - for(;;) - { - if(*it != '\r') - return true; - if(++it == last) - return false; - if(*it != '\n') - return false; - if(++it == last) - return false; - if(*it != ' ' && *it != '\t') - return false; - for(;;) - { - if(++it == last) - return true; - if(*it != ' ' && *it != '\t') - return true; - } - } -} - -template -void -skip_token(FwdIt& it, FwdIt const& last) -{ - while(it != last && is_tchar(*it)) - ++it; -} - -inline -string_view -trim(string_view s) -{ - auto first = s.begin(); - auto last = s.end(); - skip_ows(first, last); - while(first != last) - { - auto const c = *std::prev(last); - if(c != ' ' && c != '\t') - break; - --last; - } - if(first == last) - return {}; - return {&*first, - static_cast(last - first)}; -} - -struct param_iter -{ - using iter_type = string_view::const_iterator; - - iter_type it; - iter_type first; - iter_type last; - std::pair v; - - bool - empty() const - { - return first == it; - } - - template - void - increment(); -}; - -template -void -param_iter:: -increment() -{ -/* - param-list = *( OWS ";" OWS param ) - param = token OWS [ "=" OWS ( token / quoted-string ) ] - quoted-string = DQUOTE *( qdtext / quoted-pair ) DQUOTE - qdtext = HTAB / SP / "!" / %x23-5B ; '#'-'[' / %x5D-7E ; ']'-'~' / obs-text - quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text ) - obs-text = %x80-FF -*/ - auto const err = - [&] - { - it = first; - }; - v.first.clear(); - v.second.clear(); - detail::skip_ows(it, last); - first = it; - if(it == last) - return err(); - if(*it != ';') - return err(); - ++it; - detail::skip_ows(it, last); - if(it == last) - return err(); - // param - if(! detail::is_tchar(*it)) - return err(); - auto const p0 = it; - skip_token(++it, last); - auto const p1 = it; - v.first = { &*p0, static_cast(p1 - p0) }; - detail::skip_ows(it, last); - if(it == last) - return; - if(*it == ';') - return; - if(*it != '=') - return err(); - ++it; - detail::skip_ows(it, last); - if(it == last) - return; - if(*it == '"') - { - // quoted-string - auto const p2 = it; - ++it; - for(;;) - { - if(it == last) - return err(); - auto c = *it++; - if(c == '"') - break; - if(detail::is_qdchar(c)) - continue; - if(c != '\\') - return err(); - if(it == last) - return err(); - c = *it++; - if(! detail::is_qpchar(c)) - return err(); - } - v.second = { &*p2, static_cast(it - p2) }; - } - else - { - // token - if(! detail::is_tchar(*it)) - return err(); - auto const p2 = it; - skip_token(++it, last); - v.second = { &*p2, static_cast(it - p2) }; - } -} - -/* - #token = [ ( "," / token ) *( OWS "," [ OWS token ] ) ] -*/ -struct opt_token_list_policy -{ - using value_type = string_view; - - bool - operator()(value_type& v, - char const*& it, string_view s) const - { - v = {}; - auto need_comma = it != s.begin(); - for(;;) - { - detail::skip_ows(it, s.end()); - if(it == s.end()) - { - it = nullptr; - return true; - } - auto const c = *it; - if(detail::is_tchar(c)) - { - if(need_comma) - return false; - auto const p0 = it; - for(;;) - { - ++it; - if(it == s.end()) - break; - if(! detail::is_tchar(*it)) - break; - } - v = string_view{&*p0, - static_cast(it - p0)}; - return true; - } - if(c != ',') - return false; - need_comma = false; - ++it; - } - } -}; - -} // detail -} // http -} // beast - -#endif - diff --git a/src/beast/include/beast/http/detail/type_traits.hpp b/src/beast/include/beast/http/detail/type_traits.hpp deleted file mode 100644 index bb10a2d7f50..00000000000 --- a/src/beast/include/beast/http/detail/type_traits.hpp +++ /dev/null @@ -1,188 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_DETAIL_TYPE_TRAITS_HPP -#define BEAST_HTTP_DETAIL_TYPE_TRAITS_HPP - -#include -#include -#include - -namespace beast { -namespace http { - -template -struct header; - -template -struct message; - -template -class parser; - -namespace detail { - -template -class is_header_impl -{ - template - static std::true_type check( - header const*); - static std::false_type check(...); -public: - using type = decltype(check((T*)0)); -}; - -template -using is_header = typename is_header_impl::type; - -template -struct is_parser : std::false_type {}; - -template -struct is_parser> : std::true_type {}; - -struct fields_model -{ - string_view method() const; - string_view reason() const; - string_view target() const; - -protected: - string_view get_method_impl() const; - string_view get_target_impl() const; - string_view get_reason_impl() const; - bool get_chunked_impl() const; - bool get_keep_alive_impl(unsigned) const; - void set_method_impl(string_view); - void set_target_impl(string_view); - void set_reason_impl(string_view); - void set_chunked_impl(bool); - void set_content_length_impl(boost::optional); - void set_keep_alive_impl(unsigned, bool); -}; - -template> -struct has_value_type : std::false_type {}; - -template -struct has_value_type > : std::true_type {}; - -/** Determine if a @b Body type has a size - - This metafunction is equivalent to `std::true_type` if - Body contains a static member function called `size`. -*/ -template -struct is_body_sized : std::false_type {}; - -template -struct is_body_sized() = - T::size(std::declval()), - (void)0)>> : std::true_type {}; - -template -struct is_fields_helper : T -{ - template - static auto f1(int) -> decltype( - std::declval() = std::declval().get_method_impl(), - std::true_type()); - static auto f1(...) -> std::false_type; - using t1 = decltype(f1(0)); - - template - static auto f2(int) -> decltype( - std::declval() = std::declval().get_target_impl(), - std::true_type()); - static auto f2(...) -> std::false_type; - using t2 = decltype(f2(0)); - - template - static auto f3(int) -> decltype( - std::declval() = std::declval().get_reason_impl(), - std::true_type()); - static auto f3(...) -> std::false_type; - using t3 = decltype(f3(0)); - - template - static auto f4(int) -> decltype( - std::declval() = std::declval().get_chunked_impl(), - std::true_type()); - static auto f4(...) -> std::false_type; - using t4 = decltype(f4(0)); - - template - static auto f5(int) -> decltype( - std::declval() = std::declval().get_keep_alive_impl( - std::declval()), - std::true_type()); - static auto f5(...) -> std::false_type; - using t5 = decltype(f5(0)); - - template - static auto f6(int) -> decltype( - void(std::declval().set_method_impl(std::declval())), - std::true_type()); - static auto f6(...) -> std::false_type; - using t6 = decltype(f6(0)); - - template - static auto f7(int) -> decltype( - void(std::declval().set_target_impl(std::declval())), - std::true_type()); - static auto f7(...) -> std::false_type; - using t7 = decltype(f7(0)); - - template - static auto f8(int) -> decltype( - void(std::declval().set_reason_impl(std::declval())), - std::true_type()); - static auto f8(...) -> std::false_type; - using t8 = decltype(f8(0)); - - template - static auto f9(int) -> decltype( - void(std::declval().set_chunked_impl(std::declval())), - std::true_type()); - static auto f9(...) -> std::false_type; - using t9 = decltype(f9(0)); - - template - static auto f10(int) -> decltype( - void(std::declval().set_content_length_impl( - std::declval>())), - std::true_type()); - static auto f10(...) -> std::false_type; - using t10 = decltype(f10(0)); - - template - static auto f11(int) -> decltype( - void(std::declval().set_keep_alive_impl( - std::declval(), - std::declval())), - std::true_type()); - static auto f11(...) -> std::false_type; - using t11 = decltype(f11(0)); - - using type = std::integral_constant; -}; - -} // detail -} // http -} // beast - -#endif diff --git a/src/beast/include/beast/http/dynamic_body.hpp b/src/beast/include/beast/http/dynamic_body.hpp deleted file mode 100644 index c51420848e5..00000000000 --- a/src/beast/include/beast/http/dynamic_body.hpp +++ /dev/null @@ -1,168 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_DYNAMIC_BODY_HPP -#define BEAST_HTTP_DYNAMIC_BODY_HPP - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -/** A @b Body using a @b DynamicBuffer - - This body uses a @b DynamicBuffer as a memory-based container - for holding message payloads. Messages using this body type - may be serialized and parsed. -*/ -template -struct basic_dynamic_body -{ - static_assert(is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - - /** The type of container used for the body - - This determines the type of @ref message::body - when this body type is used with a message container. - */ - using value_type = DynamicBuffer; - - /** Returns the payload size of the body - - When this body is used with @ref message::prepare_payload, - the Content-Length will be set to the payload size, and - any chunked Transfer-Encoding will be removed. - */ - static - std::uint64_t - size(value_type const& v) - { - return v.size(); - } - - /** The algorithm for serializing the body - - Meets the requirements of @b BodyReader. - */ -#if BEAST_DOXYGEN - using reader = implementation_defined; -#else - class reader - { - DynamicBuffer const& body_; - - public: - using const_buffers_type = - typename DynamicBuffer::const_buffers_type; - - template - explicit - reader(message const& m) - : body_(m.body) - { - } - - void - init(error_code& ec) - { - ec.assign(0, ec.category()); - } - - boost::optional> - get(error_code& ec) - { - ec.assign(0, ec.category()); - return {{body_.data(), false}}; - } - }; -#endif - - /** The algorithm for parsing the body - - Meets the requirements of @b BodyReader. - */ -#if BEAST_DOXYGEN - using writer = implementation_defined; -#else - class writer - { - value_type& body_; - - public: - template - explicit - writer(message& msg) - : body_(msg.body) - { - } - - void - init(boost::optional const&, error_code& ec) - { - ec.assign(0, ec.category()); - } - - template - std::size_t - put(ConstBufferSequence const& buffers, - error_code& ec) - { - using boost::asio::buffer_copy; - using boost::asio::buffer_size; - auto const n = buffer_size(buffers); - if(body_.size() > body_.max_size() - n) - { - ec = error::buffer_overflow; - return 0; - } - boost::optional b; - try - { - b.emplace(body_.prepare((std::min)(n, - body_.max_size() - body_.size()))); - } - catch(std::length_error const&) - { - ec = error::buffer_overflow; - return 0; - } - ec.assign(0, ec.category()); - auto const bytes_transferred = - buffer_copy(*b, buffers); - body_.commit(bytes_transferred); - return bytes_transferred; - } - - void - finish(error_code& ec) - { - ec.assign(0, ec.category()); - } - }; -#endif -}; - -/** A dynamic message body represented by a @ref multi_buffer - - Meets the requirements of @b Body. -*/ -using dynamic_body = basic_dynamic_body; - -} // http -} // beast - -#endif diff --git a/src/beast/include/beast/http/empty_body.hpp b/src/beast/include/beast/http/empty_body.hpp deleted file mode 100644 index 2db58a011b4..00000000000 --- a/src/beast/include/beast/http/empty_body.hpp +++ /dev/null @@ -1,128 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_EMPTY_BODY_HPP -#define BEAST_HTTP_EMPTY_BODY_HPP - -#include -#include -#include -#include - -namespace beast { -namespace http { - -/** An empty @b Body - - This body is used to represent messages which do not have a - message body. If this body is used with a parser, and the - parser encounters octets corresponding to a message body, - the parser will fail with the error @ref http::unexpected_body. - - The Content-Length of this body is always 0. -*/ -struct empty_body -{ - /** The type of container used for the body - - This determines the type of @ref message::body - when this body type is used with a message container. - */ - struct value_type - { - }; - - /** Returns the payload size of the body - - When this body is used with @ref message::prepare_payload, - the Content-Length will be set to the payload size, and - any chunked Transfer-Encoding will be removed. - */ - static - std::uint64_t - size(value_type) - { - return 0; - } - - /** The algorithm for serializing the body - - Meets the requirements of @b BodyReader. - */ -#if BEAST_DOXYGEN - using reader = implementation_defined; -#else - struct reader - { - using const_buffers_type = - boost::asio::null_buffers; - - template - explicit - reader(message const&) - { - } - - void - init(error_code& ec) - { - ec.assign(0, ec.category()); - } - - boost::optional> - get(error_code& ec) - { - ec.assign(0, ec.category()); - return boost::none; - } - }; -#endif - - /** The algorithm for parsing the body - - Meets the requirements of @b BodyReader. - */ -#if BEAST_DOXYGEN - using writer = implementation_defined; -#else - struct writer - { - template - explicit - writer(message&) - { - } - - void - init(boost::optional const&, error_code& ec) - { - ec.assign(0, ec.category()); - } - - template - std::size_t - put(ConstBufferSequence const&, - error_code& ec) - { - ec = error::unexpected_body; - return 0; - } - - void - finish(error_code& ec) - { - ec.assign(0, ec.category()); - } - }; -#endif -}; - -} // http -} // beast - -#endif diff --git a/src/beast/include/beast/http/error.hpp b/src/beast/include/beast/http/error.hpp deleted file mode 100644 index 861620e3421..00000000000 --- a/src/beast/include/beast/http/error.hpp +++ /dev/null @@ -1,150 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_ERROR_HPP -#define BEAST_HTTP_ERROR_HPP - -#include -#include - -namespace beast { -namespace http { - -/// Error codes returned from HTTP algorithms and operations. -enum class error -{ - /** The end of the stream was reached. - - This error is returned under the following conditions: - - @li When attempting to read HTTP data from a stream and the stream - read returns the error `boost::asio::error::eof` before any new octets - have been received. - - @li When sending a complete HTTP message at once and the semantics of - the message are that the connection should be closed to indicate the - end of the message. - */ - end_of_stream = 1, - - /** The incoming message is incomplete. - - This happens when the end of stream is reached during - parsing and some octets have been received, but not the - entire message. - */ - partial_message, - - /** Additional buffers are required. - - This error is returned during parsing when additional - octets are needed. The caller should append more data - to the existing buffer and retry the parse operaetion. - */ - need_more, - - /** An unexpected body was encountered during parsing. - - This error is returned when attempting to parse body - octets into a message container which has the - @ref empty_body body type. - - @see @ref empty_body - */ - unexpected_body, - - /** Additional buffers are required. - - This error is returned under the following conditions: - - @li During serialization when using @ref buffer_body. - The caller should update the body to point to a new - buffer or indicate that there are no more octets in - the body. - - @li During parsing when using @ref buffer_body. - The caller should update the body to point to a new - storage area to receive additional body octets. - */ - need_buffer, - - /** Buffer maximum exceeded. - - This error is returned when reading HTTP content - into a dynamic buffer, and the operation would - exceed the maximum size of the buffer. - */ - buffer_overflow, - - /** Header limit exceeded. - - The parser detected an incoming message header which - exceeded a configured limit. - */ - header_limit, - - /** Body limit exceeded. - - The parser detected an incoming message body which - exceeded a configured limit. - */ - body_limit, - - /** A memory allocation failed. - - When basic_fields throws std::bad_alloc, it is - converted into this error by @ref parser. - */ - bad_alloc, - - // - // (parser errors) - // - - /// The line ending was malformed - bad_line_ending, - - /// The method is invalid. - bad_method, - - /// The request-target is invalid. - bad_target, - - /// The HTTP-version is invalid. - bad_version, - - /// The status-code is invalid. - bad_status, - - /// The reason-phrase is invalid. - bad_reason, - - /// The field name is invalid. - bad_field, - - /// The field value is invalid. - bad_value, - - /// The Content-Length is invalid. - bad_content_length, - - /// The Transfer-Encoding is invalid. - bad_transfer_encoding, - - /// The chunk syntax is invalid. - bad_chunk, - - /// An obs-fold exceeded an internal limit. - bad_obs_fold -}; - -} // http -} // beast - -#include - -#endif diff --git a/src/beast/include/beast/http/field.hpp b/src/beast/include/beast/http/field.hpp deleted file mode 100644 index 62d6a3f7bf3..00000000000 --- a/src/beast/include/beast/http/field.hpp +++ /dev/null @@ -1,405 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_FIELD_HPP -#define BEAST_HTTP_FIELD_HPP - -#include -#include -#include - -namespace beast { -namespace http { - -enum class field : unsigned short -{ - unknown = 0, - - a_im, - accept, - accept_additions, - accept_charset, - accept_datetime, - accept_encoding, - accept_features, - accept_language, - accept_patch, - accept_post, - accept_ranges, - access_control, - access_control_allow_credentials, - access_control_allow_headers, - access_control_allow_methods, - access_control_allow_origin, - access_control_max_age, - access_control_request_headers, - access_control_request_method, - age, - allow, - alpn, - also_control, - alt_svc, - alt_used, - alternate_recipient, - alternates, - apparently_to, - apply_to_redirect_ref, - approved, - archive, - archived_at, - article_names, - article_updates, - authentication_control, - authentication_info, - authentication_results, - authorization, - auto_submitted, - autoforwarded, - autosubmitted, - base, - bcc, - body, - c_ext, - c_man, - c_opt, - c_pep, - c_pep_info, - cache_control, - caldav_timezones, - cancel_key, - cancel_lock, - cc, - close, - comments, - compliance, - connection, - content_alternative, - content_base, - content_description, - content_disposition, - content_duration, - content_encoding, - content_features, - content_id, - content_identifier, - content_language, - content_length, - content_location, - content_md5, - content_range, - content_return, - content_script_type, - content_style_type, - content_transfer_encoding, - content_type, - content_version, - control, - conversion, - conversion_with_loss, - cookie, - cookie2, - cost, - dasl, - date, - date_received, - dav, - default_style, - deferred_delivery, - delivery_date, - delta_base, - depth, - derived_from, - destination, - differential_id, - digest, - discarded_x400_ipms_extensions, - discarded_x400_mts_extensions, - disclose_recipients, - disposition_notification_options, - disposition_notification_to, - distribution, - dkim_signature, - dl_expansion_history, - downgraded_bcc, - downgraded_cc, - downgraded_disposition_notification_to, - downgraded_final_recipient, - downgraded_from, - downgraded_in_reply_to, - downgraded_mail_from, - downgraded_message_id, - downgraded_original_recipient, - downgraded_rcpt_to, - downgraded_references, - downgraded_reply_to, - downgraded_resent_bcc, - downgraded_resent_cc, - downgraded_resent_from, - downgraded_resent_reply_to, - downgraded_resent_sender, - downgraded_resent_to, - downgraded_return_path, - downgraded_sender, - downgraded_to, - ediint_features, - eesst_version, - encoding, - encrypted, - errors_to, - etag, - expect, - expires, - expiry_date, - ext, - followup_to, - forwarded, - from, - generate_delivery_report, - getprofile, - hobareg, - host, - http2_settings, - if_, - if_match, - if_modified_since, - if_none_match, - if_range, - if_schedule_tag_match, - if_unmodified_since, - im, - importance, - in_reply_to, - incomplete_copy, - injection_date, - injection_info, - jabber_id, - keep_alive, - keywords, - label, - language, - last_modified, - latest_delivery_time, - lines, - link, - list_archive, - list_help, - list_id, - list_owner, - list_post, - list_subscribe, - list_unsubscribe, - list_unsubscribe_post, - location, - lock_token, - man, - max_forwards, - memento_datetime, - message_context, - message_id, - message_type, - meter, - method_check, - method_check_expires, - mime_version, - mmhs_acp127_message_identifier, - mmhs_authorizing_users, - mmhs_codress_message_indicator, - mmhs_copy_precedence, - mmhs_exempted_address, - mmhs_extended_authorisation_info, - mmhs_handling_instructions, - mmhs_message_instructions, - mmhs_message_type, - mmhs_originator_plad, - mmhs_originator_reference, - mmhs_other_recipients_indicator_cc, - mmhs_other_recipients_indicator_to, - mmhs_primary_precedence, - mmhs_subject_indicator_codes, - mt_priority, - negotiate, - newsgroups, - nntp_posting_date, - nntp_posting_host, - non_compliance, - obsoletes, - opt, - optional, - optional_www_authenticate, - ordering_type, - organization, - origin, - original_encoded_information_types, - original_from, - original_message_id, - original_recipient, - original_sender, - original_subject, - originator_return_address, - overwrite, - p3p, - path, - pep, - pep_info, - pics_label, - position, - posting_version, - pragma, - prefer, - preference_applied, - prevent_nondelivery_report, - priority, - privicon, - profileobject, - protocol, - protocol_info, - protocol_query, - protocol_request, - proxy_authenticate, - proxy_authentication_info, - proxy_authorization, - proxy_connection, - proxy_features, - proxy_instruction, - public_, - public_key_pins, - public_key_pins_report_only, - range, - received, - received_spf, - redirect_ref, - references, - referer, - referer_root, - relay_version, - reply_by, - reply_to, - require_recipient_valid_since, - resent_bcc, - resent_cc, - resent_date, - resent_from, - resent_message_id, - resent_reply_to, - resent_sender, - resent_to, - resolution_hint, - resolver_location, - retry_after, - return_path, - safe, - schedule_reply, - schedule_tag, - sec_websocket_accept, - sec_websocket_extensions, - sec_websocket_key, - sec_websocket_protocol, - sec_websocket_version, - security_scheme, - see_also, - sender, - sensitivity, - server, - set_cookie, - set_cookie2, - setprofile, - sio_label, - sio_label_history, - slug, - soapaction, - solicitation, - status_uri, - strict_transport_security, - subject, - subok, - subst, - summary, - supersedes, - surrogate_capability, - surrogate_control, - tcn, - te, - timeout, - title, - to, - topic, - trailer, - transfer_encoding, - ttl, - ua_color, - ua_media, - ua_pixels, - ua_resolution, - ua_windowpixels, - upgrade, - urgency, - uri, - user_agent, - variant_vary, - vary, - vbr_info, - version, - via, - want_digest, - warning, - www_authenticate, - x_archived_at, - x_device_accept, - x_device_accept_charset, - x_device_accept_encoding, - x_device_accept_language, - x_device_user_agent, - x_frame_options, - x_mittente, - x_pgp_sig, - x_ricevuta, - x_riferimento_message_id, - x_tiporicevuta, - x_trasporto, - x_verificasicurezza, - x400_content_identifier, - x400_content_return, - x400_content_type, - x400_mts_identifier, - x400_originator, - x400_received, - x400_recipients, - x400_trace, - xref, -}; - -/** Convert a field enum to a string. - - @param f The field to convert -*/ -string_view -to_string(field f); - -/** Attempt to convert a string to a field enum. - - The string comparison is case-insensitive. - - @return The corresponding field, or @ref field::unknown - if no known field matches. -*/ -field -string_to_field(string_view s); - -/// Write the text for a field name to an output stream. -inline -std::ostream& -operator<<(std::ostream& os, field f) -{ - return os << to_string(f); -} - -} // http -} // beast - -#include - -#endif diff --git a/src/beast/include/beast/http/fields.hpp b/src/beast/include/beast/http/fields.hpp deleted file mode 100644 index 005c4ab2dba..00000000000 --- a/src/beast/include/beast/http/fields.hpp +++ /dev/null @@ -1,717 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_FIELDS_HPP -#define BEAST_HTTP_FIELDS_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -/** A container for storing HTTP header fields. - - This container is designed to store the field value pairs that make - up the fields and trailers in an HTTP message. Objects of this type - are iterable, with each element holding the field name and field - value. - - Field names are stored as-is, but comparisons are case-insensitive. - The container behaves as a `std::multiset`; there will be a separate - value for each occurrence of the same field name. When the container - is iterated the fields are presented in the order of insertion, with - fields having the same name following each other consecutively. - - Meets the requirements of @b Fields - - @tparam Allocator The allocator to use. This must meet the - requirements of @b Allocator. -*/ -template -class basic_fields -{ - static std::size_t constexpr max_static_buffer = 4096; - - using off_t = std::uint16_t; - -public: - /// The type of allocator used. - using allocator_type = Allocator; - - /// The type of element used to represent a field - class value_type - { - friend class basic_fields; - - boost::asio::const_buffer - buffer() const; - - value_type(field name, - string_view sname, string_view value); - - boost::intrusive::list_member_hook< - boost::intrusive::link_mode< - boost::intrusive::normal_link>> - list_hook_; - boost::intrusive::set_member_hook< - boost::intrusive::link_mode< - boost::intrusive::normal_link>> - set_hook_; - off_t off_; - off_t len_; - field f_; - - public: - /// Returns the field enum, which can be @ref field::unknown - field - name() const; - - /// Returns the field name as a string - string_view - name_string() const; - - /// Returns the value of the field - string_view - value() const; - }; - - /** A strictly less predicate for comparing keys, using a case-insensitive comparison. - - The case-comparison operation is defined only for low-ASCII characters. - */ - struct key_compare : beast::iless - { - /// Returns `true` if lhs is less than rhs using a strict ordering - template - bool - operator()(String const& lhs, value_type const& rhs) const - { - if(lhs.size() < rhs.name_string().size()) - return true; - if(lhs.size() > rhs.name_string().size()) - return false; - return iless::operator()(lhs, rhs.name_string()); - } - - /// Returns `true` if lhs is less than rhs using a strict ordering - template - bool - operator()(value_type const& lhs, String const& rhs) const - { - if(lhs.name_string().size() < rhs.size()) - return true; - if(lhs.name_string().size() > rhs.size()) - return false; - return iless::operator()(lhs.name_string(), rhs); - } - - /// Returns `true` if lhs is less than rhs using a strict ordering - bool - operator()(value_type const& lhs, value_type const& rhs) const - { - if(lhs.name_string().size() < rhs.name_string().size()) - return true; - if(lhs.name_string().size() > rhs.name_string().size()) - return false; - return iless::operator()(lhs.name_string(), rhs.name_string()); - } - }; - - /// The algorithm used to serialize the header -#if BEAST_DOXYGEN - using reader = implementation_defined; -#else - class reader; -#endif - -private: - using list_t = typename boost::intrusive::make_list< - value_type, boost::intrusive::member_hook< - value_type, boost::intrusive::list_member_hook< - boost::intrusive::link_mode< - boost::intrusive::normal_link>>, - &value_type::list_hook_>, - boost::intrusive::constant_time_size< - false>>::type; - - using set_t = typename boost::intrusive::make_multiset< - value_type, boost::intrusive::member_hook>, - &value_type::set_hook_>, - boost::intrusive::constant_time_size, - boost::intrusive::compare>::type; - - -protected: - friend class fields_test; // for `header` - - /// Destructor - ~basic_fields(); - - /// Constructor. - basic_fields() = default; - - /** Constructor. - - @param alloc The allocator to use. - */ - explicit - basic_fields(Allocator const& alloc); - - /** Move constructor. - - The state of the moved-from object is - as if constructed using the same allocator. - */ - basic_fields(basic_fields&&); - - /** Move constructor. - - The state of the moved-from object is - as if constructed using the same allocator. - - @param alloc The allocator to use. - */ - basic_fields(basic_fields&&, Allocator const& alloc); - - /// Copy constructor. - basic_fields(basic_fields const&); - - /** Copy constructor. - - @param alloc The allocator to use. - */ - basic_fields(basic_fields const&, Allocator const& alloc); - - /// Copy constructor. - template - basic_fields(basic_fields const&); - - /** Copy constructor. - - @param alloc The allocator to use. - */ - template - basic_fields(basic_fields const&, - Allocator const& alloc); - - /** Move assignment. - - The state of the moved-from object is - as if constructed using the same allocator. - */ - basic_fields& operator=(basic_fields&&); - - /// Copy assignment. - basic_fields& operator=(basic_fields const&); - - /// Copy assignment. - template - basic_fields& operator=(basic_fields const&); - -public: - /// A constant iterator to the field sequence. -#if BEAST_DOXYGEN - using const_iterator = implementation_defined; -#else - using const_iterator = typename list_t::const_iterator; -#endif - - /// A constant iterator to the field sequence. - using iterator = const_iterator; - - /// Return a copy of the allocator associated with the container. - allocator_type - get_allocator() const - { - return typename std::allocator_traits< - Allocator>::template rebind_alloc< - value_type>(alloc_); - } - - //-------------------------------------------------------------------------- - // - // Element access - // - //-------------------------------------------------------------------------- - - /** Returns the value for a field, or throws an exception. - - @param name The name of the field. - - @return The field value. - - @throws std::out_of_range if the field is not found. - */ - string_view - at(field name) const; - - /** Returns the value for a field, or throws an exception. - - @param name The name of the field. - - @return The field value. - - @throws std::out_of_range if the field is not found. - */ - string_view - at(string_view name) const; - - /** Returns the value for a field, or `""` if it does not exist. - - If more than one field with the specified name exists, the - first field defined by insertion order is returned. - - @param name The name of the field. - */ - string_view - operator[](field name) const; - - /** Returns the value for a case-insensitive matching header, or `""` if it does not exist. - - If more than one field with the specified name exists, the - first field defined by insertion order is returned. - - @param name The name of the field. - */ - string_view - operator[](string_view name) const; - - //-------------------------------------------------------------------------- - // - // Iterators - // - //-------------------------------------------------------------------------- - - /// Return a const iterator to the beginning of the field sequence. - const_iterator - begin() const - { - return list_.cbegin(); - } - - /// Return a const iterator to the end of the field sequence. - const_iterator - end() const - { - return list_.cend(); - } - - /// Return a const iterator to the beginning of the field sequence. - const_iterator - cbegin() const - { - return list_.cbegin(); - } - - /// Return a const iterator to the end of the field sequence. - const_iterator - cend() const - { - return list_.cend(); - } - - //-------------------------------------------------------------------------- - // - // Capacity - // - //-------------------------------------------------------------------------- - -private: - // VFALCO Since the header and message derive from Fields, - // what does the expression m.empty() mean? Its confusing. - bool - empty() const - { - return list_.empty(); - } -public: - - //-------------------------------------------------------------------------- - // - // Modifiers - // - //-------------------------------------------------------------------------- - -private: - // VFALCO But this leaves behind the method, target, and reason! - /** Remove all fields from the container - - All references, pointers, or iterators referring to contained - elements are invalidated. All past-the-end iterators are also - invalidated. - */ - void - clear(); -public: - - /** Insert a field. - - If one or more fields with the same name already exist, - the new field will be inserted after the last field with - the matching name, in serialization order. - - @param name The field name. - - @param value The value of the field, as a @ref string_param - */ - void - insert(field name, string_param const& value); - - /** Insert a field. - - If one or more fields with the same name already exist, - the new field will be inserted after the last field with - the matching name, in serialization order. - - @param name The field name. - - @param value The value of the field, as a @ref string_param - */ - void - insert(string_view name, string_param const& value); - - /** Insert a field. - - If one or more fields with the same name already exist, - the new field will be inserted after the last field with - the matching name, in serialization order. - - @param name The field name. - - @param name_string The literal text corresponding to the - field name. If `name != field::unknown`, then this value - must be equal to `to_string(name)` using a case-insensitive - comparison, otherwise the behavior is undefined. - - @param value The value of the field, as a @ref string_param - */ - void - insert(field name, string_view name_string, - string_param const& value); - - /** Set a field value, removing any other instances of that field. - - First removes any values with matching field names, then - inserts the new field value. - - @param name The field name. - - @param value The value of the field, as a @ref string_param - - @return The field value. - */ - void - set(field name, string_param const& value); - - /** Set a field value, removing any other instances of that field. - - First removes any values with matching field names, then - inserts the new field value. - - @param name The field name. - - @param value The value of the field, as a @ref string_param - */ - void - set(string_view name, string_param const& value); - - /** Remove a field. - - References and iterators to the erased elements are - invalidated. Other references and iterators are not - affected. - - @param pos An iterator to the element to remove. - - @return An iterator following the last removed element. - If the iterator refers to the last element, the end() - iterator is returned. - */ - const_iterator - erase(const_iterator pos); - - /** Remove all fields with the specified name. - - All fields with the same field name are erased from the - container. - References and iterators to the erased elements are - invalidated. Other references and iterators are not - affected. - - @param name The field name. - - @return The number of fields removed. - */ - std::size_t - erase(field name); - - /** Remove all fields with the specified name. - - All fields with the same field name are erased from the - container. - References and iterators to the erased elements are - invalidated. Other references and iterators are not - affected. - - @param name The field name. - - @return The number of fields removed. - */ - std::size_t - erase(string_view name); - - /// Swap this container with another - void - swap(basic_fields& other); - - /// Swap two field containers - template - friend - void - swap(basic_fields& lhs, basic_fields& rhs); - - //-------------------------------------------------------------------------- - // - // Lookup - // - //-------------------------------------------------------------------------- - - /** Return the number of fields with the specified name. - - @param name The field name. - */ - std::size_t - count(field name) const; - - /** Return the number of fields with the specified name. - - @param name The field name. - */ - std::size_t - count(string_view name) const; - - /** Returns an iterator to the case-insensitive matching field. - - If more than one field with the specified name exists, the - first field defined by insertion order is returned. - - @param name The field name. - - @return An iterator to the matching field, or `end()` if - no match was found. - */ - const_iterator - find(field name) const; - - /** Returns an iterator to the case-insensitive matching field name. - - If more than one field with the specified name exists, the - first field defined by insertion order is returned. - - @param name The field name. - - @return An iterator to the matching field, or `end()` if - no match was found. - */ - const_iterator - find(string_view name) const; - - /** Returns a range of iterators to the fields with the specified name. - - @param name The field name. - - @return A range of iterators to fields with the same name, - otherwise an empty range. - */ - std::pair - equal_range(field name) const; - - /** Returns a range of iterators to the fields with the specified name. - - @param name The field name. - - @return A range of iterators to fields with the same name, - otherwise an empty range. - */ - std::pair - equal_range(string_view name) const; - - //-------------------------------------------------------------------------- - // - // Observers - // - //-------------------------------------------------------------------------- - - /// Returns a copy of the key comparison function - key_compare - key_comp() const - { - return key_compare{}; - } - -protected: - /** Returns the request-method string. - - @note Only called for requests. - */ - string_view - get_method_impl() const; - - /** Returns the request-target string. - - @note Only called for requests. - */ - string_view - get_target_impl() const; - - /** Returns the response reason-phrase string. - - @note Only called for responses. - */ - string_view - get_reason_impl() const; - - /** Returns the chunked Transfer-Encoding setting - */ - bool - get_chunked_impl() const; - - /** Returns the keep-alive setting - */ - bool - get_keep_alive_impl(unsigned version) const; - - /** Set or clear the method string. - - @note Only called for requests. - */ - void - set_method_impl(string_view s); - - /** Set or clear the target string. - - @note Only called for requests. - */ - void - set_target_impl(string_view s); - - /** Set or clear the reason string. - - @note Only called for responses. - */ - void - set_reason_impl(string_view s); - - /** Adjusts the chunked Transfer-Encoding value - */ - void - set_chunked_impl(bool value); - - /** Sets or clears the Content-Length field - */ - void - set_content_length_impl( - boost::optional const& value); - - /** Adjusts the Connection field - */ - void - set_keep_alive_impl( - unsigned version, bool keep_alive); - -private: - template - friend class basic_fields; - - using alloc_type = typename - std::allocator_traits:: - template rebind_alloc; - - using alloc_traits = - std::allocator_traits; - - using size_type = - typename std::allocator_traits::size_type; - - value_type& - new_element(field name, - string_view sname, string_view value); - - void - delete_element(value_type& e); - - void - set_element(value_type& e); - - void - realloc_string(string_view& dest, string_view s); - - void - realloc_target( - string_view& dest, string_view s); - - template - void - copy_all(basic_fields const&); - - void - clear_all(); - - void - delete_list(); - - void - move_assign(basic_fields&, std::true_type); - - void - move_assign(basic_fields&, std::false_type); - - void - copy_assign(basic_fields const&, std::true_type); - - void - copy_assign(basic_fields const&, std::false_type); - - void - swap(basic_fields& other, std::true_type); - - void - swap(basic_fields& other, std::false_type); - - alloc_type alloc_; - set_t set_; - list_t list_; - string_view method_; - string_view target_or_reason_; -}; - -/// A typical HTTP header fields container -using fields = basic_fields>; - -} // http -} // beast - -#include - -#endif diff --git a/src/beast/include/beast/http/file_body.hpp b/src/beast/include/beast/http/file_body.hpp deleted file mode 100644 index bcc3ab407ce..00000000000 --- a/src/beast/include/beast/http/file_body.hpp +++ /dev/null @@ -1,522 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_FILE_BODY_HPP -#define BEAST_HTTP_FILE_BODY_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -//[example_http_file_body_1 - -/** A message body represented by a file on the filesystem. - - Messages with this type have bodies represented by a - file on the file system. When parsing a message using - this body type, the data is stored in the file pointed - to by the path, which must be writable. When serializing, - the implementation will read the file and present those - octets as the body content. This may be used to serve - content from a directory as part of a web service. - - @tparam File The implementation to use for accessing files. - This type must meet the requirements of @b File. -*/ -template -struct basic_file_body -{ - static_assert(is_file::value, - "File requirements not met"); - - /// The type of File this body uses - using file_type = File; - - /** Algorithm for retrieving buffers when serializing. - - Objects of this type are created during serialization - to extract the buffers representing the body. - */ - class reader; - - /** Algorithm for storing buffers when parsing. - - Objects of this type are created during parsing - to store incoming buffers representing the body. - */ - class writer; - - /** The type of the @ref message::body member. - - Messages declared using `basic_file_body` will have this - type for the body member. This rich class interface - allow the file to be opened with the file handle - maintained directly in the object, which is attached - to the message. - */ - class value_type; - - /** Returns the size of the body - - @param v The file body to use - */ - static - std::uint64_t - size(value_type const& v); -}; - -//] - -//[example_http_file_body_2 - -// The body container holds a handle to the file when -// it is open, and also caches the size when set. -// -template -class basic_file_body::value_type -{ - friend class reader; - friend class writer; - friend struct basic_file_body; - - // This represents the open file - File file_; - - // The cached file size - std::uint64_t file_size_ = 0; - -public: - /** Destructor. - - If the file is open, it is closed first. - */ - ~value_type() = default; - - /// Constructor - value_type() = default; - - /// Constructor - value_type(value_type&& other) = default; - - /// Move assignment - value_type& operator=(value_type&& other) = default; - - /// Returns `true` if the file is open - bool - is_open() const - { - return file_.is_open(); - } - - /// Returns the size of the file if open - std::uint64_t - size() const - { - return file_size_; - } - - /// Close the file if open - void - close(); - - /** Open a file at the given path with the specified mode - - @param path The utf-8 encoded path to the file - - @param mode The file mode to use - - @param ec Set to the error, if any occurred - */ - void - open(char const* path, file_mode mode, error_code& ec); - - /** Set the open file - - This function is used to set the open - */ - void - reset(File&& file, error_code& ec); -}; - -template -void -basic_file_body:: -value_type:: -close() -{ - error_code ignored; - file_.close(ignored); -} - -template -void -basic_file_body:: -value_type:: -open(char const* path, file_mode mode, error_code& ec) -{ - // Open the file - file_.open(path, mode, ec); - if(ec) - return; - - // Cache the size - file_size_ = file_.size(ec); - if(ec) - { - close(); - return; - } -} - -template -void -basic_file_body:: -value_type:: -reset(File&& file, error_code& ec) -{ - // First close the file if open - if(file_.is_open()) - { - error_code ignored; - file_.close(ignored); - } - - // Take ownership of the new file - file_ = std::move(file); - - // Cache the size - file_size_ = file_.size(ec); -} - -// This is called from message::payload_size -template -std::uint64_t -basic_file_body:: -size(value_type const& v) -{ - // Forward the call to the body - return v.size(); -} - -//] - -//[example_http_file_body_3 - -template -class basic_file_body::reader -{ - value_type& body_; // The body we are reading from - std::uint64_t remain_; // The number of unread bytes - char buf_[4096]; // Small buffer for reading - -public: - // The type of buffer sequence returned by `get`. - // - using const_buffers_type = - boost::asio::const_buffers_1; - - // Constructor. - // - // `m` holds the message we are sending, which will - // always have the `file_body` as the body type. - // - // Note that the message is passed by non-const reference. - // This is intentional, because reading from the file - // changes its "current position" which counts makes the - // operation logically not-const (although it is bitwise - // const). - // - // The BodyReader concept allows the reader to choose - // whether to take the message by const reference or - // non-const reference. Depending on the choice, a - // serializer constructed using that body type will - // require the same const or non-const reference to - // construct. - // - // Readers which accept const messages usually allow - // the same body to be serialized by multiple threads - // concurrently, while readers accepting non-const - // messages may only be serialized by one thread at - // a time. - // - template - reader(message< - isRequest, basic_file_body, Fields>& m); - - // Initializer - // - // This is called before the body is serialized and - // gives the reader a chance to do something that might - // need to return an error code. - // - void - init(error_code& ec); - - // This function is called zero or more times to - // retrieve buffers. A return value of `boost::none` - // means there are no more buffers. Otherwise, - // the contained pair will have the next buffer - // to serialize, and a `bool` indicating whether - // or not there may be additional buffers. - boost::optional> - get(error_code& ec); -}; - -//] - -//[example_http_file_body_4 - -// Here we just stash a reference to the path for later. -// Rather than dealing with messy constructor exceptions, -// we save the things that might fail for the call to `init`. -// -template -template -basic_file_body:: -reader:: -reader(message& m) - : body_(m.body) -{ - // The file must already be open - BOOST_ASSERT(body_.file_.is_open()); - - // Get the size of the file - remain_ = body_.file_size_; -} - -// Initializer -template -void -basic_file_body:: -reader:: -init(error_code& ec) -{ - // The error_code specification requires that we - // either set the error to some value, or set it - // to indicate no error. - // - // We don't do anything fancy so set "no error" - ec.assign(0, ec.category()); -} - -// This function is called repeatedly by the serializer to -// retrieve the buffers representing the body. Our strategy -// is to read into our buffer and return it until we have -// read through the whole file. -// -template -auto -basic_file_body:: -reader:: -get(error_code& ec) -> - boost::optional> -{ - // Calculate the smaller of our buffer size, - // or the amount of unread data in the file. - auto const amount = remain_ > sizeof(buf_) ? - sizeof(buf_) : static_cast(remain_); - - // Handle the case where the file is zero length - if(amount == 0) - { - // Modify the error code to indicate success - // This is required by the error_code specification. - // - // NOTE We use the existing category instead of calling - // into the library to get the generic category because - // that saves us a possibly expensive atomic operation. - // - ec.assign(0, ec.category()); - return boost::none; - } - - // Now read the next buffer - auto const nread = body_.file_.read(buf_, amount, ec); - if(ec) - return boost::none; - - // Make sure there is forward progress - BOOST_ASSERT(nread != 0); - BOOST_ASSERT(nread <= remain_); - - // Update the amount remaining based on what we got - remain_ -= nread; - - // Return the buffer to the caller. - // - // The second element of the pair indicates whether or - // not there is more data. As long as there is some - // unread bytes, there will be more data. Otherwise, - // we set this bool to `false` so we will not be called - // again. - // - ec.assign(0, ec.category()); - return {{ - const_buffers_type{buf_, nread}, // buffer to return. - remain_ > 0 // `true` if there are more buffers. - }}; -} - -//] - -//[example_http_file_body_5 - -template -class basic_file_body::writer -{ - value_type& body_; // The body we are writing to - -public: - // Constructor. - // - // This is called after the header is parsed and - // indicates that a non-zero sized body may be present. - // `m` holds the message we are receiving, which will - // always have the `file_body` as the body type. - // - template - explicit - writer( - message& m); - - // Initializer - // - // This is called before the body is parsed and - // gives the writer a chance to do something that might - // need to return an error code. It informs us of - // the payload size (`content_length`) which we can - // optionally use for optimization. - // - void - init(boost::optional const&, error_code& ec); - - // This function is called one or more times to store - // buffer sequences corresponding to the incoming body. - // - template - std::size_t - put(ConstBufferSequence const& buffers, - error_code& ec); - - // This function is called when writing is complete. - // It is an opportunity to perform any final actions - // which might fail, in order to return an error code. - // Operations that might fail should not be attemped in - // destructors, since an exception thrown from there - // would terminate the program. - // - void - finish(error_code& ec); -}; - -//] - -//[example_http_file_body_6 - -// We don't do much in the writer constructor since the -// file is already open. -// -template -template -basic_file_body:: -writer:: -writer(message& m) - : body_(m.body) -{ -} - -template -void -basic_file_body:: -writer:: -init( - boost::optional const& content_length, - error_code& ec) -{ - // The file must already be open for writing - BOOST_ASSERT(body_.file_.is_open()); - - // We don't do anything with this but a sophisticated - // application might check available space on the device - // to see if there is enough room to store the body. - boost::ignore_unused(content_length); - - // The error_code specification requires that we - // either set the error to some value, or set it - // to indicate no error. - // - // We don't do anything fancy so set "no error" - ec.assign(0, ec.category()); -} - -// This will get called one or more times with body buffers -// -template -template -std::size_t -basic_file_body:: -writer:: -put(ConstBufferSequence const& buffers, error_code& ec) -{ - // This function must return the total number of - // bytes transferred from the input buffers. - std::size_t nwritten = 0; - - // Loop over all the buffers in the sequence, - // and write each one to the file. - for(boost::asio::const_buffer buffer : buffers) - { - // Write this buffer to the file - nwritten += body_.file_.write( - boost::asio::buffer_cast(buffer), - boost::asio::buffer_size(buffer), - ec); - if(ec) - return nwritten; - } - - // Indicate success - // This is required by the error_code specification - ec.assign(0, ec.category()); - - return nwritten; -} - -// Called after writing is done when there's no error. -template -void -basic_file_body:: -writer:: -finish(error_code& ec) -{ - // This has to be cleared before returning, to - // indicate no error. The specification requires it. - ec.assign(0, ec.category()); -} - -//] - -/// A message body represented by a file on the filesystem. -using file_body = basic_file_body; - -} // http -} // beast - -#include - -#endif diff --git a/src/beast/include/beast/http/impl/basic_parser.ipp b/src/beast/include/beast/http/impl/basic_parser.ipp deleted file mode 100644 index 9ea02bae0ae..00000000000 --- a/src/beast/include/beast/http/impl/basic_parser.ipp +++ /dev/null @@ -1,932 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_IMPL_BASIC_PARSER_IPP -#define BEAST_HTTP_IMPL_BASIC_PARSER_IPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -template -basic_parser:: -basic_parser() - : body_limit_( - default_body_limit(is_request{})) -{ -} - -template -template -basic_parser:: -basic_parser(basic_parser< - isRequest, OtherDerived>&& other) - : body_limit_(other.body_limit_) - , len_(other.len_) - , buf_(std::move(other.buf_)) - , buf_len_(other.buf_len_) - , skip_(other.skip_) - , state_(other.state_) - , f_(other.f_) -{ -} - -template -bool -basic_parser:: -is_keep_alive() const -{ - BOOST_ASSERT(is_header_done()); - if(f_ & flagHTTP11) - { - if(f_ & flagConnectionClose) - return false; - } - else - { - if(! (f_ & flagConnectionKeepAlive)) - return false; - } - return (f_ & flagNeedEOF) == 0; -} - -template -boost::optional -basic_parser:: -content_length() const -{ - BOOST_ASSERT(is_header_done()); - if(! (f_ & flagContentLength)) - return boost::none; - return len_; -} - -template -void -basic_parser:: -skip(bool v) -{ - BOOST_ASSERT(! got_some()); - if(v) - f_ |= flagSkipBody; - else - f_ &= ~flagSkipBody; -} - -template -template -std::size_t -basic_parser:: -put(ConstBufferSequence const& buffers, - error_code& ec) -{ - static_assert(is_const_buffer_sequence< - ConstBufferSequence>::value, - "ConstBufferSequence requirements not met"); - using boost::asio::buffer_cast; - using boost::asio::buffer_copy; - using boost::asio::buffer_size; - auto const p = buffers.begin(); - auto const last = buffers.end(); - if(p == last) - { - ec.assign(0, ec.category()); - return 0; - } - if(std::next(p) == last) - { - // single buffer - auto const b = *p; - return put(boost::asio::const_buffers_1{ - buffer_cast(b), - buffer_size(b)}, ec); - } - auto const size = buffer_size(buffers); - if(size <= max_stack_buffer) - return put_from_stack(size, buffers, ec); - if(size > buf_len_) - { - // reallocate - buf_ = boost::make_unique_noinit(size); - buf_len_ = size; - } - // flatten - buffer_copy(boost::asio::buffer( - buf_.get(), buf_len_), buffers); - return put(boost::asio::const_buffers_1{ - buf_.get(), buf_len_}, ec); -} - -template -std::size_t -basic_parser:: -put(boost::asio::const_buffers_1 const& buffer, - error_code& ec) -{ - BOOST_ASSERT(state_ != state::complete); - using boost::asio::buffer_size; - auto p = boost::asio::buffer_cast< - char const*>(*buffer.begin()); - auto n = buffer_size(*buffer.begin()); - auto const p0 = p; - auto const p1 = p0 + n; - ec.assign(0, ec.category()); -loop: - switch(state_) - { - case state::nothing_yet: - if(n == 0) - { - ec = error::need_more; - return 0; - } - state_ = state::start_line; - BEAST_FALLTHROUGH; - - case state::start_line: - { - maybe_need_more(p, n, ec); - if(ec) - goto done; - parse_start_line(p, p + std::min( - header_limit_, n), ec, is_request{}); - if(ec) - { - if(ec == error::need_more) - { - if(n >= header_limit_) - { - ec = error::header_limit; - goto done; - } - if(p + 3 <= p1) - skip_ = static_cast< - std::size_t>(p1 - p - 3); - } - goto done; - } - BOOST_ASSERT(! is_done()); - n = static_cast(p1 - p); - if(p >= p1) - { - ec = error::need_more; - goto done; - } - BEAST_FALLTHROUGH; - } - - case state::fields: - maybe_need_more(p, n, ec); - if(ec) - goto done; - parse_fields(p, p + std::min( - header_limit_, n), ec); - if(ec) - { - if(ec == error::need_more) - { - if(n >= header_limit_) - { - ec = error::header_limit; - goto done; - } - if(p + 3 <= p1) - skip_ = static_cast< - std::size_t>(p1 - p - 3); - } - goto done; - } - finish_header(ec, is_request{}); - break; - - case state::body0: - BOOST_ASSERT(! skip_); - impl().on_body(content_length(), ec); - if(ec) - goto done; - state_ = state::body; - BEAST_FALLTHROUGH; - - case state::body: - BOOST_ASSERT(! skip_); - parse_body(p, n, ec); - if(ec) - goto done; - break; - - case state::body_to_eof0: - BOOST_ASSERT(! skip_); - impl().on_body(content_length(), ec); - if(ec) - goto done; - state_ = state::body_to_eof; - BEAST_FALLTHROUGH; - - case state::body_to_eof: - BOOST_ASSERT(! skip_); - parse_body_to_eof(p, n, ec); - if(ec) - goto done; - break; - - case state::chunk_header0: - impl().on_body(content_length(), ec); - if(ec) - goto done; - state_ = state::chunk_header; - BEAST_FALLTHROUGH; - - case state::chunk_header: - parse_chunk_header(p, n, ec); - if(ec) - goto done; - break; - - case state::chunk_body: - parse_chunk_body(p, n, ec); - if(ec) - goto done; - break; - - case state::complete: - ec.assign(0, ec.category()); - goto done; - } - if(p < p1 && ! is_done() && eager()) - { - n = static_cast(p1 - p); - goto loop; - } -done: - return static_cast(p - p0); -} - -template -void -basic_parser:: -put_eof(error_code& ec) -{ - BOOST_ASSERT(got_some()); - if( state_ == state::start_line || - state_ == state::fields) - { - ec = error::partial_message; - return; - } - if(f_ & (flagContentLength | flagChunked)) - { - if(state_ != state::complete) - { - ec = error::partial_message; - return; - } - ec.assign(0, ec.category()); - return; - } - impl().on_complete(ec); - if(ec) - return; - state_ = state::complete; -} - -template -template -std::size_t -basic_parser:: -put_from_stack(std::size_t size, - ConstBufferSequence const& buffers, - error_code& ec) -{ - char buf[max_stack_buffer]; - using boost::asio::buffer; - using boost::asio::buffer_copy; - buffer_copy(buffer(buf, sizeof(buf)), buffers); - return put(boost::asio::const_buffers_1{ - buf, size}, ec); -} - -template -inline -void -basic_parser:: -maybe_need_more( - char const* p, std::size_t n, - error_code& ec) -{ - if(skip_ == 0) - return; - if( n > header_limit_) - n = header_limit_; - if(n < skip_ + 4) - { - ec = error::need_more; - return; - } - auto const term = - find_eom(p + skip_, p + n); - if(! term) - { - skip_ = n - 3; - if(skip_ + 4 > header_limit_) - { - ec = error::header_limit; - return; - } - ec = error::need_more; - return; - } - skip_ = 0; -} - -template -inline -void -basic_parser:: -parse_start_line( - char const*& in, char const* last, - error_code& ec, std::true_type) -{ -/* - request-line = method SP request-target SP HTTP-version CRLF - method = token -*/ - auto p = in; - - string_view method; - parse_method(p, last, method, ec); - if(ec) - return; - - string_view target; - parse_target(p, last, target, ec); - if(ec) - return; - - int version = 0; - parse_version(p, last, version, ec); - if(ec) - return; - if(version < 10 || version > 11) - { - ec = error::bad_version; - return; - } - - if(p + 2 > last) - { - ec = error::need_more; - return; - } - if(p[0] != '\r' || p[1] != '\n') - { - ec = error::bad_version; - return; - } - p += 2; - - if(version >= 11) - f_ |= flagHTTP11; - - impl().on_request(string_to_verb(method), - method, target, version, ec); - if(ec) - return; - - in = p; - state_ = state::fields; -} - -template -inline -void -basic_parser:: -parse_start_line( - char const*& in, char const* last, - error_code& ec, std::false_type) -{ -/* - status-line = HTTP-version SP status-code SP reason-phrase CRLF - status-code = 3*DIGIT - reason-phrase = *( HTAB / SP / VCHAR / obs-text ) -*/ - auto p = in; - - int version = 0; - parse_version(p, last, version, ec); - if(ec) - return; - if(version < 10 || version > 11) - { - ec = error::bad_version; - return; - } - - // SP - if(p + 1 > last) - { - ec = error::need_more; - return; - } - if(*p++ != ' ') - { - ec = error::bad_version; - return; - } - - parse_status(p, last, status_, ec); - if(ec) - return; - - // parse reason CRLF - string_view reason; - parse_reason(p, last, reason, ec); - if(ec) - return; - - if(version >= 11) - f_ |= flagHTTP11; - - impl().on_response( - status_, reason, version, ec); - if(ec) - return; - - in = p; - state_ = state::fields; -} - -template -void -basic_parser:: -parse_fields(char const*& in, - char const* last, error_code& ec) -{ - string_view name; - string_view value; - // https://stackoverflow.com/questions/686217/maximum-on-http-header-values - static_string buf; - auto p = in; - for(;;) - { - if(p + 2 > last) - { - ec = error::need_more; - return; - } - if(p[0] == '\r') - { - if(p[1] != '\n') - ec = error::bad_line_ending; - in = p + 2; - return; - } - parse_field(p, last, name, value, buf, ec); - if(ec) - return; - auto const f = string_to_field(name); - do_field(f, value, ec); - if(ec) - return; - impl().on_field(f, name, value, ec); - if(ec) - return; - in = p; - } -} - -template -inline -void -basic_parser:: -finish_header(error_code& ec, std::true_type) -{ - // RFC 7230 section 3.3 - // https://tools.ietf.org/html/rfc7230#section-3.3 - - if(f_ & flagSkipBody) - { - state_ = state::complete; - } - else if(f_ & flagContentLength) - { - if(len_ > 0) - { - f_ |= flagHasBody; - state_ = state::body0; - } - else - { - state_ = state::complete; - } - } - else if(f_ & flagChunked) - { - f_ |= flagHasBody; - state_ = state::chunk_header0; - } - else - { - len_ = 0; - state_ = state::complete; - } - - impl().on_header(ec); - if(ec) - return; - if(state_ == state::complete) - { - impl().on_complete(ec); - if(ec) - return; - } -} - -template -inline -void -basic_parser:: -finish_header(error_code& ec, std::false_type) -{ - // RFC 7230 section 3.3 - // https://tools.ietf.org/html/rfc7230#section-3.3 - - if( (f_ & flagSkipBody) || // e.g. response to a HEAD request - status_ / 100 == 1 || // 1xx e.g. Continue - status_ == 204 || // No Content - status_ == 304) // Not Modified - { - state_ = state::complete; - return; - } - - if(f_ & flagContentLength) - { - if(len_ > 0) - { - f_ |= flagHasBody; - state_ = state::body0; - } - else - { - state_ = state::complete; - } - } - else if(f_ & flagChunked) - { - f_ |= flagHasBody; - state_ = state::chunk_header0; - } - else - { - f_ |= flagHasBody; - f_ |= flagNeedEOF; - state_ = state::body_to_eof0; - } - - impl().on_header(ec); - if(ec) - return; - if(state_ == state::complete) - { - impl().on_complete(ec); - if(ec) - return; - } -} - -template -inline -void -basic_parser:: -parse_body(char const*& p, - std::size_t n, error_code& ec) -{ - n = impl().on_data(string_view{p, - beast::detail::clamp(len_, n)}, ec); - p += n; - len_ -= n; - if(ec) - return; - if(len_ > 0) - return; - impl().on_complete(ec); - if(ec) - return; - state_ = state::complete; -} - -template -inline -void -basic_parser:: -parse_body_to_eof(char const*& p, - std::size_t n, error_code& ec) -{ - if(n > body_limit_) - { - ec = error::body_limit; - return; - } - body_limit_ = body_limit_ - n; - n = impl().on_data(string_view{p, n}, ec); - p += n; - if(ec) - return; -} - -template -void -basic_parser:: -parse_chunk_header(char const*& p0, - std::size_t n, error_code& ec) -{ -/* - chunked-body = *chunk last-chunk trailer-part CRLF - - chunk = chunk-size [ chunk-ext ] CRLF chunk-data CRLF - last-chunk = 1*("0") [ chunk-ext ] CRLF - trailer-part = *( header-field CRLF ) - - chunk-size = 1*HEXDIG - chunk-data = 1*OCTET ; a sequence of chunk-size octets - chunk-ext = *( ";" chunk-ext-name [ "=" chunk-ext-val ] ) - chunk-ext-name = token - chunk-ext-val = token / quoted-string -*/ - - auto p = p0; - auto const pend = p + n; - char const* eol; - - if(! (f_ & flagFinalChunk)) - { - if(n < skip_ + 2) - { - ec = error::need_more; - return; - } - if(f_ & flagExpectCRLF) - { - // Treat the last CRLF in a chunk as - // part of the next chunk, so p can - // be parsed in one call instead of two. - if(! parse_crlf(p)) - { - ec = error::bad_chunk; - return; - } - } - eol = find_eol(p0 + skip_, pend, ec); - if(ec) - return; - if(! eol) - { - ec = error::need_more; - skip_ = n - 1; - return; - } - skip_ = static_cast< - std::size_t>(eol - 2 - p0); - - std::uint64_t v; - if(! parse_hex(p, v)) - { - ec = error::bad_chunk; - return; - } - if(v != 0) - { - if(v > body_limit_) - { - ec = error::body_limit; - return; - } - body_limit_ -= v; - if(*p == ';') - { - // VFALCO TODO Validate extension - impl().on_chunk(v, make_string( - p, eol - 2), ec); - if(ec) - return; - } - else if(p == eol - 2) - { - impl().on_chunk(v, {}, ec); - if(ec) - return; - } - else - { - ec = error::bad_chunk; - return; - } - len_ = v; - skip_ = 2; - p0 = eol; - f_ |= flagExpectCRLF; - state_ = state::chunk_body; - return; - } - - f_ |= flagFinalChunk; - } - else - { - BOOST_ASSERT(n >= 5); - if(f_ & flagExpectCRLF) - BOOST_VERIFY(parse_crlf(p)); - std::uint64_t v; - BOOST_VERIFY(parse_hex(p, v)); - eol = find_eol(p, pend, ec); - BOOST_ASSERT(! ec); - } - - auto eom = find_eom(p0 + skip_, pend); - if(! eom) - { - BOOST_ASSERT(n >= 3); - skip_ = n - 3; - ec = error::need_more; - return; - } - - if(*p == ';') - { - // VFALCO TODO Validate extension - impl().on_chunk(0, make_string( - p, eol - 2), ec); - if(ec) - return; - } - p = eol; - parse_fields(p, eom, ec); - if(ec) - return; - BOOST_ASSERT(p == eom); - p0 = eom; - - impl().on_complete(ec); - if(ec) - return; - state_ = state::complete; -} - -template -inline -void -basic_parser:: -parse_chunk_body(char const*& p, - std::size_t n, error_code& ec) -{ - n = impl().on_data(string_view{p, - beast::detail::clamp(len_, n)}, ec); - p += n; - len_ -= n; - if(ec) - return; - if(len_ > 0) - return; - state_ = state::chunk_header; -} - -template -void -basic_parser:: -do_field(field f, - string_view value, error_code& ec) -{ - // Connection - if(f == field::connection || - f == field::proxy_connection) - { - auto const list = opt_token_list{value}; - if(! validate_list(list)) - { - // VFALCO Should this be a field specific error? - ec = error::bad_value; - return; - } - for(auto const& s : list) - { - if(iequals({"close", 5}, s)) - { - f_ |= flagConnectionClose; - continue; - } - - if(iequals({"keep-alive", 10}, s)) - { - f_ |= flagConnectionKeepAlive; - continue; - } - - if(iequals({"upgrade", 7}, s)) - { - f_ |= flagConnectionUpgrade; - continue; - } - } - ec.assign(0, ec.category()); - return; - } - - // Content-Length - if(f == field::content_length) - { - if(f_ & flagContentLength) - { - // duplicate - ec = error::bad_content_length; - return; - } - - if(f_ & flagChunked) - { - // conflicting field - ec = error::bad_content_length; - return; - } - - std::uint64_t v; - if(! parse_dec( - value.begin(), value.end(), v)) - { - ec = error::bad_content_length; - return; - } - - if(v > body_limit_) - { - ec = error::body_limit; - return; - } - - ec.assign(0, ec.category()); - len_ = v; - f_ |= flagContentLength; - return; - } - - // Transfer-Encoding - if(f == field::transfer_encoding) - { - if(f_ & flagChunked) - { - // duplicate - ec = error::bad_transfer_encoding; - return; - } - - if(f_ & flagContentLength) - { - // conflicting field - ec = error::bad_transfer_encoding; - return; - } - - ec.assign(0, ec.category()); - auto const v = token_list{value}; - auto const p = std::find_if(v.begin(), v.end(), - [&](typename token_list::value_type const& s) - { - return iequals({"chunked", 7}, s); - }); - if(p == v.end()) - return; - if(std::next(p) != v.end()) - return; - len_ = 0; - f_ |= flagChunked; - return; - } - - // Upgrade - if(f == field::upgrade) - { - ec.assign(0, ec.category()); - f_ |= flagUpgrade; - return; - } - - ec.assign(0, ec.category()); -} - -} // http -} // beast - -#endif diff --git a/src/beast/include/beast/http/impl/error.ipp b/src/beast/include/beast/http/impl/error.ipp deleted file mode 100644 index fc2438513d5..00000000000 --- a/src/beast/include/beast/http/impl/error.ipp +++ /dev/null @@ -1,115 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_IMPL_ERROR_IPP -#define BEAST_HTTP_IMPL_ERROR_IPP - -#include - -namespace boost { -namespace system { -template<> -struct is_error_code_enum -{ - static bool const value = true; -}; -} // system -} // boost - -namespace beast { -namespace http { -namespace detail { - -class http_error_category : public error_category -{ -public: - const char* - name() const noexcept override - { - return "beast.http"; - } - - std::string - message(int ev) const override - { - switch(static_cast(ev)) - { - case error::end_of_stream: return "end of stream"; - case error::partial_message: return "partial message"; - case error::need_more: return "need more"; - case error::unexpected_body: return "unexpected body"; - case error::need_buffer: return "need buffer"; - case error::buffer_overflow: return "buffer overflow"; - case error::header_limit: return "header limit exceeded"; - case error::body_limit: return "body limit exceeded"; - case error::bad_alloc: return "bad alloc"; - case error::bad_line_ending: return "bad line ending"; - case error::bad_method: return "bad method"; - case error::bad_target: return "bad target"; - case error::bad_version: return "bad version"; - case error::bad_status: return "bad status"; - case error::bad_reason: return "bad reason"; - case error::bad_field: return "bad field"; - case error::bad_value: return "bad value"; - case error::bad_content_length: return "bad Content-Length"; - case error::bad_transfer_encoding: return "bad Transfer-Encoding"; - case error::bad_chunk: return "bad chunk"; - case error::bad_obs_fold: return "bad obs-fold"; - - default: - return "beast.http error"; - } - } - - error_condition - default_error_condition( - int ev) const noexcept override - { - return error_condition{ev, *this}; - } - - bool - equivalent(int ev, - error_condition const& condition - ) const noexcept override - { - return condition.value() == ev && - &condition.category() == this; - } - - bool - equivalent(error_code const& error, - int ev) const noexcept override - { - return error.value() == ev && - &error.category() == this; - } -}; - -inline -error_category const& -get_http_error_category() -{ - static http_error_category const cat{}; - return cat; -} - -} // detail - -inline -error_code -make_error_code(error ev) -{ - return error_code{ - static_cast::type>(ev), - detail::get_http_error_category()}; -} - -} // http -} // beast - -#endif diff --git a/src/beast/include/beast/http/impl/field.ipp b/src/beast/include/beast/http/impl/field.ipp deleted file mode 100644 index 6d4f2c50294..00000000000 --- a/src/beast/include/beast/http/impl/field.ipp +++ /dev/null @@ -1,557 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_IMPL_FIELD_IPP -#define BEAST_HTTP_IMPL_FIELD_IPP - -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -namespace detail { - -struct field_table -{ - using array_type = - std::array; - - struct hash - { - std::size_t - operator()(string_view const& s) const - { - auto const n = s.size(); - return - beast::detail::ascii_tolower(s[0]) * - beast::detail::ascii_tolower(s[n/2]) ^ - beast::detail::ascii_tolower(s[n-1]); // hist[] = 331, 10, max_load_factor = 0.15f - } - }; - - struct iequal - { - // assumes inputs have equal length - bool - operator()( - string_view const& lhs, - string_view const& rhs) const - { - auto p1 = lhs.data(); - auto p2 = rhs.data(); - auto pend = lhs.end(); - char a, b; - while(p1 < pend) - { - a = *p1++; - b = *p2++; - if(a != b) - goto slow; - } - return true; - - while(p1 < pend) - { - slow: - if( beast::detail::ascii_tolower(a) != - beast::detail::ascii_tolower(b)) - return false; - a = *p1++; - b = *p2++; - } - return true; - } - }; - - using map_type = std::unordered_map< - string_view, field, hash, iequal>; - - array_type by_name_; - std::vector by_size_; -/* - From: - - https://www.iana.org/assignments/message-headers/message-headers.xhtml -*/ - field_table() - : by_name_({{ - "", - "A-IM", - "Accept", - "Accept-Additions", - "Accept-Charset", - "Accept-Datetime", - "Accept-Encoding", - "Accept-Features", - "Accept-Language", - "Accept-Patch", - "Accept-Post", - "Accept-Ranges", - "Access-Control", - "Access-Control-Allow-Credentials", - "Access-Control-Allow-Headers", - "Access-Control-Allow-Methods", - "Access-Control-Allow-Origin", - "Access-Control-Max-Age", - "Access-Control-Request-Headers", - "Access-Control-Request-Method", - "Age", - "Allow", - "ALPN", - "Also-Control", - "Alt-Svc", - "Alt-Used", - "Alternate-Recipient", - "Alternates", - "Apparently-To", - "Apply-To-Redirect-Ref", - "Approved", - "Archive", - "Archived-At", - "Article-Names", - "Article-Updates", - "Authentication-Control", - "Authentication-Info", - "Authentication-Results", - "Authorization", - "Auto-Submitted", - "Autoforwarded", - "Autosubmitted", - "Base", - "Bcc", - "Body", - "C-Ext", - "C-Man", - "C-Opt", - "C-PEP", - "C-PEP-Info", - "Cache-Control", - "CalDAV-Timezones", - "Cancel-Key", - "Cancel-Lock", - "Cc", - "Close", - "Comments", - "Compliance", - "Connection", - "Content-Alternative", - "Content-Base", - "Content-Description", - "Content-Disposition", - "Content-Duration", - "Content-Encoding", - "Content-features", - "Content-ID", - "Content-Identifier", - "Content-Language", - "Content-Length", - "Content-Location", - "Content-MD5", - "Content-Range", - "Content-Return", - "Content-Script-Type", - "Content-Style-Type", - "Content-Transfer-Encoding", - "Content-Type", - "Content-Version", - "Control", - "Conversion", - "Conversion-With-Loss", - "Cookie", - "Cookie2", - "Cost", - "DASL", - "Date", - "Date-Received", - "DAV", - "Default-Style", - "Deferred-Delivery", - "Delivery-Date", - "Delta-Base", - "Depth", - "Derived-From", - "Destination", - "Differential-ID", - "Digest", - "Discarded-X400-IPMS-Extensions", - "Discarded-X400-MTS-Extensions", - "Disclose-Recipients", - "Disposition-Notification-Options", - "Disposition-Notification-To", - "Distribution", - "DKIM-Signature", - "DL-Expansion-History", - "Downgraded-Bcc", - "Downgraded-Cc", - "Downgraded-Disposition-Notification-To", - "Downgraded-Final-Recipient", - "Downgraded-From", - "Downgraded-In-Reply-To", - "Downgraded-Mail-From", - "Downgraded-Message-Id", - "Downgraded-Original-Recipient", - "Downgraded-Rcpt-To", - "Downgraded-References", - "Downgraded-Reply-To", - "Downgraded-Resent-Bcc", - "Downgraded-Resent-Cc", - "Downgraded-Resent-From", - "Downgraded-Resent-Reply-To", - "Downgraded-Resent-Sender", - "Downgraded-Resent-To", - "Downgraded-Return-Path", - "Downgraded-Sender", - "Downgraded-To", - "EDIINT-Features", - "Eesst-Version", - "Encoding", - "Encrypted", - "Errors-To", - "ETag", - "Expect", - "Expires", - "Expiry-Date", - "Ext", - "Followup-To", - "Forwarded", - "From", - "Generate-Delivery-Report", - "GetProfile", - "Hobareg", - "Host", - "HTTP2-Settings", - "If", - "If-Match", - "If-Modified-Since", - "If-None-Match", - "If-Range", - "If-Schedule-Tag-Match", - "If-Unmodified-Since", - "IM", - "Importance", - "In-Reply-To", - "Incomplete-Copy", - "Injection-Date", - "Injection-Info", - "Jabber-ID", - "Keep-Alive", - "Keywords", - "Label", - "Language", - "Last-Modified", - "Latest-Delivery-Time", - "Lines", - "Link", - "List-Archive", - "List-Help", - "List-ID", - "List-Owner", - "List-Post", - "List-Subscribe", - "List-Unsubscribe", - "List-Unsubscribe-Post", - "Location", - "Lock-Token", - "Man", - "Max-Forwards", - "Memento-Datetime", - "Message-Context", - "Message-ID", - "Message-Type", - "Meter", - "Method-Check", - "Method-Check-Expires", - "MIME-Version", - "MMHS-Acp127-Message-Identifier", - "MMHS-Authorizing-Users", - "MMHS-Codress-Message-Indicator", - "MMHS-Copy-Precedence", - "MMHS-Exempted-Address", - "MMHS-Extended-Authorisation-Info", - "MMHS-Handling-Instructions", - "MMHS-Message-Instructions", - "MMHS-Message-Type", - "MMHS-Originator-PLAD", - "MMHS-Originator-Reference", - "MMHS-Other-Recipients-Indicator-CC", - "MMHS-Other-Recipients-Indicator-To", - "MMHS-Primary-Precedence", - "MMHS-Subject-Indicator-Codes", - "MT-Priority", - "Negotiate", - "Newsgroups", - "NNTP-Posting-Date", - "NNTP-Posting-Host", - "Non-Compliance", - "Obsoletes", - "Opt", - "Optional", - "Optional-WWW-Authenticate", - "Ordering-Type", - "Organization", - "Origin", - "Original-Encoded-Information-Types", - "Original-From", - "Original-Message-ID", - "Original-Recipient", - "Original-Sender", - "Original-Subject", - "Originator-Return-Address", - "Overwrite", - "P3P", - "Path", - "PEP", - "Pep-Info", - "PICS-Label", - "Position", - "Posting-Version", - "Pragma", - "Prefer", - "Preference-Applied", - "Prevent-NonDelivery-Report", - "Priority", - "Privicon", - "ProfileObject", - "Protocol", - "Protocol-Info", - "Protocol-Query", - "Protocol-Request", - "Proxy-Authenticate", - "Proxy-Authentication-Info", - "Proxy-Authorization", - "Proxy-Connection", - "Proxy-Features", - "Proxy-Instruction", - "Public", - "Public-Key-Pins", - "Public-Key-Pins-Report-Only", - "Range", - "Received", - "Received-SPF", - "Redirect-Ref", - "References", - "Referer", - "Referer-Root", - "Relay-Version", - "Reply-By", - "Reply-To", - "Require-Recipient-Valid-Since", - "Resent-Bcc", - "Resent-Cc", - "Resent-Date", - "Resent-From", - "Resent-Message-ID", - "Resent-Reply-To", - "Resent-Sender", - "Resent-To", - "Resolution-Hint", - "Resolver-Location", - "Retry-After", - "Return-Path", - "Safe", - "Schedule-Reply", - "Schedule-Tag", - "Sec-WebSocket-Accept", - "Sec-WebSocket-Extensions", - "Sec-WebSocket-Key", - "Sec-WebSocket-Protocol", - "Sec-WebSocket-Version", - "Security-Scheme", - "See-Also", - "Sender", - "Sensitivity", - "Server", - "Set-Cookie", - "Set-Cookie2", - "SetProfile", - "SIO-Label", - "SIO-Label-History", - "SLUG", - "SoapAction", - "Solicitation", - "Status-URI", - "Strict-Transport-Security", - "Subject", - "SubOK", - "Subst", - "Summary", - "Supersedes", - "Surrogate-Capability", - "Surrogate-Control", - "TCN", - "TE", - "Timeout", - "Title", - "To", - "Topic", - "Trailer", - "Transfer-Encoding", - "TTL", - "UA-Color", - "UA-Media", - "UA-Pixels", - "UA-Resolution", - "UA-Windowpixels", - "Upgrade", - "Urgency", - "URI", - "User-Agent", - "Variant-Vary", - "Vary", - "VBR-Info", - "Version", - "Via", - "Want-Digest", - "Warning", - "WWW-Authenticate", - "X-Archived-At", - "X-Device-Accept", - "X-Device-Accept-Charset", - "X-Device-Accept-Encoding", - "X-Device-Accept-Language", - "X-Device-User-Agent", - "X-Frame-Options", - "X-Mittente", - "X-PGP-Sig", - "X-Ricevuta", - "X-Riferimento-Message-ID", - "X-TipoRicevuta", - "X-Trasporto", - "X-VerificaSicurezza", - "X400-Content-Identifier", - "X400-Content-Return", - "X400-Content-Type", - "X400-MTS-Identifier", - "X400-Originator", - "X400-Received", - "X400-Recipients", - "X400-Trace", - "Xref" - }}) - { - // find the longest field length - std::size_t high = 0; - for(auto const& s : by_name_) - if(high < s.size()) - high = s.size(); - // build by_size map - // skip field::unknown - by_size_.resize(high + 1); - for(auto& map : by_size_) - map.max_load_factor(.15f); - for(std::size_t i = 1; - i < by_name_.size(); ++i) - { - auto const& s = by_name_[i]; - by_size_[s.size()].emplace( - s, static_cast(i)); - } - -#if 0 - // This snippet calculates the performance - // of the hash function and map settings - { - std::vector hist; - for(auto const& map : by_size_) - { - for(std::size_t i = 0; i < map.bucket_count(); ++i) - { - auto const n = map.bucket_size(i); - if(n > 0) - { - if(hist.size() < n) - hist.resize(n); - ++hist[n-1]; - } - } - } - } -#endif - } - - field - string_to_field(string_view s) const - { - if(s.size() >= by_size_.size()) - return field::unknown; - auto const& map = by_size_[s.size()]; - if(map.empty()) - return field::unknown; - auto it = map.find(s); - if(it == map.end()) - return field::unknown; - return it->second; - } - - // - // Deprecated - // - - using const_iterator = - array_type::const_iterator; - - std::size_t - size() const - { - return by_name_.size(); - } - - const_iterator - begin() const - { - return by_name_.begin(); - } - - const_iterator - end() const - { - return by_name_.end(); - } -}; - -inline -field_table const& -get_field_table() -{ - static field_table const tab; - return tab; -} - -template -string_view -to_string(field f) -{ - auto const& v = get_field_table(); - BOOST_ASSERT(static_cast(f) < v.size()); - return v.begin()[static_cast(f)]; -} - -} // detail - -inline -string_view -to_string(field f) -{ - return detail::to_string(f); -} - -inline -field -string_to_field(string_view s) -{ - return detail::get_field_table().string_to_field(s); -} - -} // http -} // beast - -#endif diff --git a/src/beast/include/beast/http/impl/fields.ipp b/src/beast/include/beast/http/impl/fields.ipp deleted file mode 100644 index 44df4c6e5ff..00000000000 --- a/src/beast/include/beast/http/impl/fields.ipp +++ /dev/null @@ -1,1346 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_IMPL_FIELDS_IPP -#define BEAST_HTTP_IMPL_FIELDS_IPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined(BOOST_LIBSTDCXX_VERSION) && BOOST_LIBSTDCXX_VERSION < 60000 - // Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56437 -#ifndef BEAST_HTTP_NO_FIELDS_BASIC_STRING_ALLOCATOR -#define BEAST_HTTP_NO_FIELDS_BASIC_STRING_ALLOCATOR -#endif -#endif - -namespace beast { -namespace http { - -template -class basic_fields::reader -{ -public: - using iter_type = typename list_t::const_iterator; - - struct field_iterator - { - iter_type it_; - - using value_type = boost::asio::const_buffer; - using pointer = value_type const*; - using reference = value_type const; - using difference_type = std::ptrdiff_t; - using iterator_category = - std::bidirectional_iterator_tag; - - field_iterator() = default; - field_iterator(field_iterator&& other) = default; - field_iterator(field_iterator const& other) = default; - field_iterator& operator=(field_iterator&& other) = default; - field_iterator& operator=(field_iterator const& other) = default; - - explicit - field_iterator(iter_type it) - : it_(it) - { - } - - bool - operator==(field_iterator const& other) const - { - return it_ == other.it_; - } - - bool - operator!=(field_iterator const& other) const - { - return !(*this == other); - } - - reference - operator*() const - { - return it_->buffer(); - } - - field_iterator& - operator++() - { - ++it_; - return *this; - } - - field_iterator - operator++(int) - { - auto temp = *this; - ++(*this); - return temp; - } - - field_iterator& - operator--() - { - --it_; - return *this; - } - - field_iterator - operator--(int) - { - auto temp = *this; - --(*this); - return temp; - } - }; - - class field_range - { - field_iterator first_; - field_iterator last_; - - public: - using const_iterator = - field_iterator; - - using value_type = - typename const_iterator::value_type; - - field_range(iter_type first, iter_type last) - : first_(first) - , last_(last) - { - } - - const_iterator - begin() const - { - return first_; - } - - const_iterator - end() const - { - return last_; - } - }; - - basic_fields const& f_; - boost::asio::const_buffer cb_[3]; - char buf_[13]; - -public: - using const_buffers_type = - buffer_cat_view< - boost::asio::const_buffers_1, - boost::asio::const_buffers_1, - boost::asio::const_buffers_1, - field_range, - boost::asio::const_buffers_1>; - - reader(basic_fields const& f, - unsigned version, verb v); - - reader(basic_fields const& f, - unsigned version, unsigned code); - - const_buffers_type - get() const - { - return buffer_cat( - boost::asio::const_buffers_1{cb_[0]}, - boost::asio::const_buffers_1{cb_[1]}, - boost::asio::const_buffers_1{cb_[2]}, - field_range(f_.list_.begin(), f_.list_.end()), - detail::chunk_crlf()); - } -}; - -template -basic_fields::reader:: -reader(basic_fields const& f, - unsigned version, verb v) - : f_(f) -{ -/* - request - "" - " " - " HTTP/X.Y\r\n" (11 chars) -*/ - string_view sv; - if(v == verb::unknown) - sv = f_.get_method_impl(); - else - sv = to_string(v); - cb_[0] = {sv.data(), sv.size()}; - - // target_or_reason_ has a leading SP - cb_[1] = { - f_.target_or_reason_.data(), - f_.target_or_reason_.size()}; - - buf_[0] = ' '; - buf_[1] = 'H'; - buf_[2] = 'T'; - buf_[3] = 'T'; - buf_[4] = 'P'; - buf_[5] = '/'; - buf_[6] = '0' + static_cast(version / 10); - buf_[7] = '.'; - buf_[8] = '0' + static_cast(version % 10); - buf_[9] = '\r'; - buf_[10]= '\n'; - cb_[2] = {buf_, 11}; -} - -template -basic_fields::reader:: -reader(basic_fields const& f, - unsigned version, unsigned code) - : f_(f) -{ -/* - response - "HTTP/X.Y ### " (13 chars) - "" - "\r\n" -*/ - buf_[0] = 'H'; - buf_[1] = 'T'; - buf_[2] = 'T'; - buf_[3] = 'P'; - buf_[4] = '/'; - buf_[5] = '0' + static_cast(version / 10); - buf_[6] = '.'; - buf_[7] = '0' + static_cast(version % 10); - buf_[8] = ' '; - buf_[9] = '0' + static_cast(code / 100); - buf_[10]= '0' + static_cast((code / 10) % 10); - buf_[11]= '0' + static_cast(code % 10); - buf_[12]= ' '; - cb_[0] = {buf_, 13}; - - string_view sv; - if(! f_.target_or_reason_.empty()) - sv = f_.target_or_reason_; - else - sv = obsolete_reason(static_cast(code)); - cb_[1] = {sv.data(), sv.size()}; - - cb_[2] = detail::chunk_crlf(); -} - -//------------------------------------------------------------------------------ - -template -basic_fields:: -value_type:: -value_type(field name, - string_view sname, string_view value) - : off_(static_cast(sname.size() + 2)) - , len_(static_cast(value.size())) - , f_(name) -{ - //BOOST_ASSERT(name == field::unknown || - // iequals(sname, to_string(name))); - char* p = reinterpret_cast(this + 1); - p[off_-2] = ':'; - p[off_-1] = ' '; - p[off_ + len_] = '\r'; - p[off_ + len_ + 1] = '\n'; - std::memcpy(p, sname.data(), sname.size()); - std::memcpy(p + off_, value.data(), value.size()); -} - -template -inline -field -basic_fields:: -value_type:: -name() const -{ - return f_; -} - -template -inline -string_view -basic_fields:: -value_type:: -name_string() const -{ - return {reinterpret_cast< - char const*>(this + 1), - static_cast(off_ - 2)}; -} - -template -inline -string_view -basic_fields:: -value_type:: -value() const -{ - return {reinterpret_cast< - char const*>(this + 1) + off_, - static_cast(len_)}; -} - -template -inline -boost::asio::const_buffer -basic_fields:: -value_type:: -buffer() const -{ - return boost::asio::const_buffer{ - reinterpret_cast(this + 1), - static_cast(off_) + len_ + 2}; -} - -//------------------------------------------------------------------------------ - -template -basic_fields:: -~basic_fields() -{ - delete_list(); - realloc_string(method_, {}); - realloc_string( - target_or_reason_, {}); -} - -template -basic_fields:: -basic_fields(Allocator const& alloc) - : alloc_(alloc) -{ -} - -template -basic_fields:: -basic_fields(basic_fields&& other) - : alloc_(std::move(other.alloc_)) - , set_(std::move(other.set_)) - , list_(std::move(other.list_)) - , method_(other.method_) - , target_or_reason_(other.target_or_reason_) -{ - other.method_.clear(); - other.target_or_reason_.clear(); -} - -template -basic_fields:: -basic_fields(basic_fields&& other, Allocator const& alloc) - : alloc_(alloc) -{ - if(alloc_ != other.alloc_) - { - copy_all(other); - other.clear_all(); - } - else - { - set_ = std::move(other.set_); - list_ = std::move(other.list_); - method_ = other.method_; - target_or_reason_ = other.target_or_reason_; - } -} - -template -basic_fields:: -basic_fields(basic_fields const& other) - : alloc_(alloc_traits:: - select_on_container_copy_construction(other.alloc_)) -{ - copy_all(other); -} - -template -basic_fields:: -basic_fields(basic_fields const& other, - Allocator const& alloc) - : alloc_(alloc) -{ - copy_all(other); -} - -template -template -basic_fields:: -basic_fields(basic_fields const& other) -{ - copy_all(other); -} - -template -template -basic_fields:: -basic_fields(basic_fields const& other, - Allocator const& alloc) - : alloc_(alloc) -{ - copy_all(other); -} - -template -auto -basic_fields:: -operator=(basic_fields&& other) -> - basic_fields& -{ - if(this == &other) - return *this; - move_assign(other, typename alloc_traits:: - propagate_on_container_move_assignment{}); - return *this; -} - -template -auto -basic_fields:: -operator=(basic_fields const& other) -> - basic_fields& -{ - copy_assign(other, typename alloc_traits:: - propagate_on_container_copy_assignment{}); - return *this; -} - -template -template -auto -basic_fields:: -operator=(basic_fields const& other) -> - basic_fields& -{ - clear_all(); - copy_all(other); - return *this; -} - -//------------------------------------------------------------------------------ -// -// Element access -// -//------------------------------------------------------------------------------ - -template -string_view -basic_fields:: -at(field name) const -{ - BOOST_ASSERT(name != field::unknown); - auto const it = find(name); - if(it == end()) - BOOST_THROW_EXCEPTION(std::out_of_range{ - "field not found"}); - return it->value(); -} - -template -string_view -basic_fields:: -at(string_view name) const -{ - auto const it = find(name); - if(it == end()) - BOOST_THROW_EXCEPTION(std::out_of_range{ - "field not found"}); - return it->value(); -} - -template -string_view -basic_fields:: -operator[](field name) const -{ - BOOST_ASSERT(name != field::unknown); - auto const it = find(name); - if(it == end()) - return {}; - return it->value(); -} - -template -string_view -basic_fields:: -operator[](string_view name) const -{ - auto const it = find(name); - if(it == end()) - return {}; - return it->value(); -} - -//------------------------------------------------------------------------------ -// -// Modifiers -// -//------------------------------------------------------------------------------ - -template -void -basic_fields:: -clear() -{ - delete_list(); - set_.clear(); - list_.clear(); -} - -template -inline -void -basic_fields:: -insert(field name, string_param const& value) -{ - BOOST_ASSERT(name != field::unknown); - insert(name, to_string(name), value); -} - -template -void -basic_fields:: -insert(string_view sname, string_param const& value) -{ - auto const name = - string_to_field(sname); - insert(name, sname, value); -} - -template -void -basic_fields:: -insert(field name, - string_view sname, string_param const& value) -{ - auto& e = new_element(name, sname, - static_cast(value)); - auto const before = - set_.upper_bound(sname, key_compare{}); - if(before == set_.begin()) - { - BOOST_ASSERT(count(sname) == 0); - set_.insert_before(before, e); - list_.push_back(e); - return; - } - auto const last = std::prev(before); - // VFALCO is it worth comparing `field name` first? - if(! iequals(sname, last->name_string())) - { - BOOST_ASSERT(count(sname) == 0); - set_.insert_before(before, e); - list_.push_back(e); - return; - } - // keep duplicate fields together in the list - set_.insert_before(before, e); - list_.insert(++list_.iterator_to(*last), e); -} - -template -void -basic_fields:: -set(field name, string_param const& value) -{ - BOOST_ASSERT(name != field::unknown); - set_element(new_element(name, to_string(name), - static_cast(value))); -} - -template -void -basic_fields:: -set(string_view sname, string_param const& value) -{ - set_element(new_element( - string_to_field(sname), sname, - static_cast(value))); -} - -template -auto -basic_fields:: -erase(const_iterator pos) -> - const_iterator -{ - auto next = pos.iter(); - auto& e = *next++; - set_.erase(e); - list_.erase(e); - delete_element(e); - return next; -} - -template -std::size_t -basic_fields:: -erase(field name) -{ - BOOST_ASSERT(name != field::unknown); - return erase(to_string(name)); -} - -template -std::size_t -basic_fields:: -erase(string_view name) -{ - std::size_t n =0; - set_.erase_and_dispose(name, key_compare{}, - [&](value_type* e) - { - ++n; - list_.erase(list_.iterator_to(*e)); - delete_element(*e); - }); - return n; -} - -template -void -basic_fields:: -swap(basic_fields& other) -{ - swap(other, typename alloc_traits:: - propagate_on_container_swap{}); -} - -template -void -swap( - basic_fields& lhs, - basic_fields& rhs) -{ - lhs.swap(rhs); -} - -//------------------------------------------------------------------------------ -// -// Lookup -// -//------------------------------------------------------------------------------ - -template -inline -std::size_t -basic_fields:: -count(field name) const -{ - BOOST_ASSERT(name != field::unknown); - return count(to_string(name)); -} - -template -std::size_t -basic_fields:: -count(string_view name) const -{ - return set_.count(name, key_compare{}); -} - -template -inline -auto -basic_fields:: -find(field name) const -> - const_iterator -{ - BOOST_ASSERT(name != field::unknown); - return find(to_string(name)); -} - -template -auto -basic_fields:: -find(string_view name) const -> - const_iterator -{ - auto const it = set_.find( - name, key_compare{}); - if(it == set_.end()) - return list_.end(); - return list_.iterator_to(*it); -} - -template -inline -auto -basic_fields:: -equal_range(field name) const -> - std::pair -{ - BOOST_ASSERT(name != field::unknown); - return equal_range(to_string(name)); -} - -template -auto -basic_fields:: -equal_range(string_view name) const -> - std::pair -{ - auto const result = - set_.equal_range(name, key_compare{}); - return { - list_.iterator_to(result->first), - list_.iterator_to(result->second)}; -} - -//------------------------------------------------------------------------------ - -namespace detail { - -// Filter a token list -// -template -void -filter_token_list( - String& s, - string_view const& value, - Pred&& pred) -{ - token_list te{value}; - auto it = te.begin(); - auto last = te.end(); - if(it == last) - return; - while(pred(*it)) - if(++it == last) - return; - s.append(it->data(), it->size()); - while(++it != last) - { - if(! pred(*it)) - { - s.append(", "); - s.append(it->data(), it->size()); - } - } -} - -// Filter the last item in a token list -template -void -filter_token_list_last( - String& s, - string_view const& value, - Pred&& pred) -{ - token_list te{value}; - if(te.begin() != te.end()) - { - auto it = te.begin(); - auto next = std::next(it); - if(next == te.end()) - { - if(! pred(*it)) - s.append(it->data(), it->size()); - return; - } - s.append(it->data(), it->size()); - for(;;) - { - it = next; - next = std::next(it); - if(next == te.end()) - { - if(! pred(*it)) - { - s.append(", "); - s.append(it->data(), it->size()); - } - return; - } - s.append(", "); - s.append(it->data(), it->size()); - } - } -} - -template -void -keep_alive_impl( - String& s, string_view const& value, - unsigned version, bool keep_alive) -{ - if(version < 11) - { - if(keep_alive) - { - // remove close - filter_token_list(s, value, - [](string_view s) - { - return iequals(s, "close"); - }); - // add keep-alive - if(s.empty()) - s.append("keep-alive"); - else if(! token_list{value}.exists("keep-alive")) - s.append(", keep-alive"); - } - else - { - // remove close and keep-alive - filter_token_list(s, value, - [](string_view s) - { - return - iequals(s, "close") || - iequals(s, "keep-alive"); - }); - } - } - else - { - if(keep_alive) - { - // remove close and keep-alive - filter_token_list(s, value, - [](string_view s) - { - return - iequals(s, "close") || - iequals(s, "keep-alive"); - }); - } - else - { - // remove keep-alive - filter_token_list(s, value, - [](string_view s) - { - return iequals(s, "keep-alive"); - }); - // add close - if(s.empty()) - s.append("close"); - else if(! token_list{value}.exists("close")) - s.append(", close"); - } - } -} - -} // detail - -//------------------------------------------------------------------------------ - -// Fields - -template -inline -string_view -basic_fields:: -get_method_impl() const -{ - return method_; -} - -template -inline -string_view -basic_fields:: -get_target_impl() const -{ - if(target_or_reason_.empty()) - return target_or_reason_; - return { - target_or_reason_.data() + 1, - target_or_reason_.size() - 1}; -} - -template -inline -string_view -basic_fields:: -get_reason_impl() const -{ - return target_or_reason_; -} - -template -bool -basic_fields:: -get_chunked_impl() const -{ - auto const te = token_list{ - (*this)[field::transfer_encoding]}; - for(auto it = te.begin(); it != te.end();) - { - auto const next = std::next(it); - if(next == te.end()) - return iequals(*it, "chunked"); - it = next; - } - return false; -} - -template -bool -basic_fields:: -get_keep_alive_impl(unsigned version) const -{ - auto const it = find(field::connection); - if(version < 11) - { - if(it == end()) - return false; - return token_list{ - it->value()}.exists("keep-alive"); - } - if(it == end()) - return true; - return ! token_list{ - it->value()}.exists("close"); -} - -template -inline -void -basic_fields:: -set_method_impl(string_view s) -{ - realloc_string(method_, s); -} - -template -inline -void -basic_fields:: -set_target_impl(string_view s) -{ - realloc_target( - target_or_reason_, s); -} - -template -inline -void -basic_fields:: -set_reason_impl(string_view s) -{ - realloc_string( - target_or_reason_, s); -} - -template -void -basic_fields:: -set_chunked_impl(bool value) -{ - auto it = find(field::transfer_encoding); - if(value) - { - // append "chunked" - if(it == end()) - { - set(field::transfer_encoding, "chunked"); - return; - } - auto const te = token_list{it->value()}; - for(auto itt = te.begin();;) - { - auto const next = std::next(itt); - if(next == te.end()) - { - if(iequals(*itt, "chunked")) - return; // already set - break; - } - itt = next; - } - static_string buf; - if(it->value().size() <= buf.size() + 9) - { - buf.append(it->value().data(), it->value().size()); - buf.append(", chunked", 9); - set(field::transfer_encoding, buf); - } - else - { - #ifdef BEAST_HTTP_NO_FIELDS_BASIC_STRING_ALLOCATOR - // Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56437 - std::string s; - #else - using rebind_type = - typename std::allocator_traits< - Allocator>::template rebind_alloc; - std::basic_string< - char, - std::char_traits, - rebind_type> s{rebind_type{alloc_}}; - #endif - s.reserve(it->value().size() + 9); - s.append(it->value().data(), it->value().size()); - s.append(", chunked", 9); - set(field::transfer_encoding, s); - } - return; - } - // filter "chunked" - if(it == end()) - return; - try - { - static_string buf; - detail::filter_token_list_last(buf, it->value(), - [](string_view const& s) - { - return iequals(s, "chunked"); - }); - if(! buf.empty()) - set(field::transfer_encoding, buf); - else - erase(field::transfer_encoding); - } - catch(std::length_error const&) - { - #ifdef BEAST_HTTP_NO_FIELDS_BASIC_STRING_ALLOCATOR - // Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56437 - std::string s; - #else - using rebind_type = - typename std::allocator_traits< - Allocator>::template rebind_alloc; - std::basic_string< - char, - std::char_traits, - rebind_type> s{rebind_type{alloc_}}; - #endif - s.reserve(it->value().size()); - detail::filter_token_list_last(s, it->value(), - [](string_view const& s) - { - return iequals(s, "chunked"); - }); - if(! s.empty()) - set(field::transfer_encoding, s); - else - erase(field::transfer_encoding); - } -} - -template -void -basic_fields:: -set_content_length_impl( - boost::optional const& value) -{ - if(! value) - erase(field::content_length); - else - set(field::content_length, *value); -} - -template -void -basic_fields:: -set_keep_alive_impl( - unsigned version, bool keep_alive) -{ - // VFALCO What about Proxy-Connection ? - auto const value = (*this)[field::connection]; - try - { - static_string buf; - detail::keep_alive_impl( - buf, value, version, keep_alive); - if(buf.empty()) - erase(field::connection); - else - set(field::connection, buf); - } - catch(std::length_error const&) - { - #ifdef BEAST_HTTP_NO_FIELDS_BASIC_STRING_ALLOCATOR - // Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56437 - std::string s; - #else - using rebind_type = - typename std::allocator_traits< - Allocator>::template rebind_alloc; - std::basic_string< - char, - std::char_traits, - rebind_type> s{rebind_type{alloc_}}; - #endif - s.reserve(value.size()); - detail::keep_alive_impl( - s, value, version, keep_alive); - if(s.empty()) - erase(field::connection); - else - set(field::connection, s); - } -} - -//------------------------------------------------------------------------------ - -template -auto -basic_fields:: -new_element(field name, - string_view sname, string_view value) -> - value_type& -{ - if(sname.size() + 2 > - (std::numeric_limits::max)()) - BOOST_THROW_EXCEPTION(std::length_error{ - "field name too large"}); - if(value.size() + 2 > - (std::numeric_limits::max)()) - BOOST_THROW_EXCEPTION(std::length_error{ - "field value too large"}); - value = detail::trim(value); - std::uint16_t const off = - static_cast(sname.size() + 2); - std::uint16_t const len = - static_cast(value.size()); - auto const p = alloc_traits::allocate(alloc_, - 1 + (off + len + 2 + sizeof(value_type) - 1) / - sizeof(value_type)); - // VFALCO allocator can't call the constructor because its private - //alloc_traits::construct(alloc_, p, name, sname, value); - new(p) value_type{name, sname, value}; - return *p; -} - -template -void -basic_fields:: -delete_element(value_type& e) -{ - auto const n = 1 + (e.off_ + e.len_ + 2 + - sizeof(value_type) - 1) / sizeof(value_type); - alloc_traits::destroy(alloc_, &e); - alloc_traits::deallocate(alloc_, &e, n); -} - -template -void -basic_fields:: -set_element(value_type& e) -{ - auto it = set_.lower_bound( - e.name_string(), key_compare{}); - if(it == set_.end() || ! iequals( - e.name_string(), it->name_string())) - { - set_.insert_before(it, e); - list_.push_back(e); - return; - } - for(;;) - { - auto next = it; - ++next; - set_.erase(it); - list_.erase(list_.iterator_to(*it)); - delete_element(*it); - it = next; - if(it == set_.end() || - ! iequals(e.name_string(), it->name_string())) - break; - } - set_.insert_before(it, e); - list_.push_back(e); -} - -template -void -basic_fields:: -realloc_string(string_view& dest, string_view s) -{ - if(dest.empty() && s.empty()) - return; - auto a = typename std::allocator_traits< - Allocator>::template rebind_alloc< - char>(alloc_); - if(! dest.empty()) - { - a.deallocate(const_cast( - dest.data()), dest.size()); - dest.clear(); - } - if(! s.empty()) - { - auto const p = a.allocate(s.size()); - std::memcpy(p, s.data(), s.size()); - dest = {p, s.size()}; - } -} - -template -void -basic_fields:: -realloc_target( - string_view& dest, string_view s) -{ - // The target string are stored with an - // extra space at the beginning to help - // the reader class. - if(dest.empty() && s.empty()) - return; - auto a = typename std::allocator_traits< - Allocator>::template rebind_alloc< - char>(alloc_); - if(! dest.empty()) - { - a.deallocate(const_cast( - dest.data()), dest.size()); - dest.clear(); - } - if(! s.empty()) - { - auto const p = a.allocate(1 + s.size()); - p[0] = ' '; - std::memcpy(p + 1, s.data(), s.size()); - dest = {p, 1 + s.size()}; - } -} - -template -template -void -basic_fields:: -copy_all(basic_fields const& other) -{ - for(auto const& e : other.list_) - insert(e.name(), e.name_string(), e.value()); - realloc_string(method_, other.method_); - realloc_string(target_or_reason_, - other.target_or_reason_); -} - -template -void -basic_fields:: -clear_all() -{ - clear(); - realloc_string(method_, {}); - realloc_string(target_or_reason_, {}); -} - -template -void -basic_fields:: -delete_list() -{ - for(auto it = list_.begin(); it != list_.end();) - delete_element(*it++); -} - -//------------------------------------------------------------------------------ - -template -inline -void -basic_fields:: -move_assign(basic_fields& other, std::true_type) -{ - clear_all(); - set_ = std::move(other.set_); - list_ = std::move(other.list_); - method_ = other.method_; - target_or_reason_ = other.target_or_reason_; - other.method_.clear(); - other.target_or_reason_.clear(); - alloc_ = other.alloc_; -} - -template -inline -void -basic_fields:: -move_assign(basic_fields& other, std::false_type) -{ - clear_all(); - if(alloc_ != other.alloc_) - { - copy_all(other); - other.clear_all(); - } - else - { - set_ = std::move(other.set_); - list_ = std::move(other.list_); - method_ = other.method_; - target_or_reason_ = other.target_or_reason_; - other.method_.clear(); - other.target_or_reason_.clear(); - } -} - -template -inline -void -basic_fields:: -copy_assign(basic_fields const& other, std::true_type) -{ - clear_all(); - alloc_ = other.alloc_; - copy_all(other); -} - -template -inline -void -basic_fields:: -copy_assign(basic_fields const& other, std::false_type) -{ - clear_all(); - copy_all(other); -} - -template -inline -void -basic_fields:: -swap(basic_fields& other, std::true_type) -{ - using std::swap; - swap(alloc_, other.alloc_); - swap(set_, other.set_); - swap(list_, other.list_); - swap(method_, other.method_); - swap(target_or_reason_, other.target_or_reason_); -} - -template -inline -void -basic_fields:: -swap(basic_fields& other, std::false_type) -{ - BOOST_ASSERT(alloc_ == other.alloc_); - using std::swap; - swap(set_, other.set_); - swap(list_, other.list_); - swap(method_, other.method_); - swap(target_or_reason_, other.target_or_reason_); -} - -} // http -} // beast - -#endif diff --git a/src/beast/include/beast/http/impl/file_body_win32.ipp b/src/beast/include/beast/http/impl/file_body_win32.ipp deleted file mode 100644 index 03734339fe5..00000000000 --- a/src/beast/include/beast/http/impl/file_body_win32.ipp +++ /dev/null @@ -1,579 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_IMPL_FILE_BODY_WIN32_IPP -#define BEAST_HTTP_IMPL_FILE_BODY_WIN32_IPP - -#if BEAST_USE_WIN32_FILE - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -namespace detail { -template -class write_some_win32_op; -} // detail - -template<> -struct basic_file_body -{ - using file_type = file_win32; - - class reader; - class writer; - - //-------------------------------------------------------------------------- - - class value_type - { - friend class reader; - friend class writer; - friend struct basic_file_body; - - template - friend class detail::write_some_win32_op; - template - friend - void - write_some( - boost::asio::basic_stream_socket& sock, - serializer, - Fields, Decorator>& sr, - error_code& ec); - - file_win32 file_; - std::uint64_t size_ = 0; // cached file size - std::uint64_t first_; // starting offset of the range - std::uint64_t last_; // ending offset of the range - - public: - ~value_type() = default; - value_type() = default; - value_type(value_type&& other) = default; - value_type& operator=(value_type&& other) = default; - - bool - is_open() const - { - return file_.is_open(); - } - - std::uint64_t - size() const - { - return size_; - } - - void - close(); - - void - open(char const* path, file_mode mode, error_code& ec); - - void - reset(file_win32&& file, error_code& ec); - }; - - //-------------------------------------------------------------------------- - - class reader - { - template - friend class detail::write_some_win32_op; - template - friend - void - write_some( - boost::asio::basic_stream_socket& sock, - serializer, - Fields, Decorator>& sr, - error_code& ec); - - value_type& body_; // The body we are reading from - std::uint64_t pos_; // The current position in the file - char buf_[4096]; // Small buffer for reading - - public: - using const_buffers_type = - boost::asio::const_buffers_1; - - template - reader(message, Fields>& m) - : body_(m.body) - { - } - - void - init(error_code&) - { - BOOST_ASSERT(body_.file_.is_open()); - pos_ = body_.first_; - } - - boost::optional> - get(error_code& ec) - { - std::size_t const n = (std::min)(sizeof(buf_), - beast::detail::clamp(body_.last_ - pos_)); - if(n == 0) - { - ec.assign(0, ec.category()); - return boost::none; - } - auto const nread = body_.file_.read(buf_, n, ec); - if(ec) - return boost::none; - BOOST_ASSERT(nread != 0); - pos_ += nread; - ec.assign(0, ec.category()); - return {{ - {buf_, nread}, // buffer to return. - pos_ < body_.last_}}; // `true` if there are more buffers. - } - }; - - //-------------------------------------------------------------------------- - - class writer - { - value_type& body_; - - public: - template - explicit - writer(message& m) - : body_(m.body) - { - } - - void - init(boost::optional< - std::uint64_t> const& content_length, - error_code& ec) - { - // VFALCO We could reserve space in the file - boost::ignore_unused(content_length); - BOOST_ASSERT(body_.file_.is_open()); - ec.assign(0, ec.category()); - } - - template - std::size_t - put(ConstBufferSequence const& buffers, - error_code& ec) - { - std::size_t nwritten = 0; - for(boost::asio::const_buffer buffer : buffers) - { - nwritten += body_.file_.write( - boost::asio::buffer_cast(buffer), - boost::asio::buffer_size(buffer), - ec); - if(ec) - return nwritten; - } - ec.assign(0, ec.category()); - return nwritten; - } - - void - finish(error_code& ec) - { - ec.assign(0, ec.category()); - } - }; - - //-------------------------------------------------------------------------- - - static - std::uint64_t - size(value_type const& body) - { - return body.size(); - } -}; - -//------------------------------------------------------------------------------ - -inline -void -basic_file_body:: -value_type:: -close() -{ - error_code ignored; - file_.close(ignored); -} - -inline -void -basic_file_body:: -value_type:: -open(char const* path, file_mode mode, error_code& ec) -{ - file_.open(path, mode, ec); - if(ec) - return; - size_ = file_.size(ec); - if(ec) - { - close(); - return; - } - first_ = 0; - last_ = size_; -} - -inline -void -basic_file_body:: -value_type:: -reset(file_win32&& file, error_code& ec) -{ - if(file_.is_open()) - { - error_code ignored; - file_.close(ignored); - } - file_ = std::move(file); - if(file_.is_open()) - { - size_ = file_.size(ec); - if(ec) - { - close(); - return; - } - first_ = 0; - last_ = size_; - } -} - -//------------------------------------------------------------------------------ - -namespace detail { - -template -inline -boost::detail::winapi::DWORD_ -lowPart(Unsigned n) -{ - return static_cast< - boost::detail::winapi::DWORD_>( - n & 0xffffffff); -} - -template -inline -boost::detail::winapi::DWORD_ -highPart(Unsigned n, std::true_type) -{ - return static_cast< - boost::detail::winapi::DWORD_>( - (n>>32)&0xffffffff); -} - -template -inline -boost::detail::winapi::DWORD_ -highPart(Unsigned, std::false_type) -{ - return 0; -} - -template -inline -boost::detail::winapi::DWORD_ -highPart(Unsigned n) -{ - return highPart(n, std::integral_constant< - bool, (sizeof(Unsigned)>4)>{}); -} - -class null_lambda -{ -public: - template - void - operator()(error_code&, - ConstBufferSequence const&) const - { - BOOST_ASSERT(false); - } -}; - -//------------------------------------------------------------------------------ - -#if BOOST_ASIO_HAS_WINDOWS_OVERLAPPED_PTR - -template -class write_some_win32_op -{ - boost::asio::basic_stream_socket& sock_; - serializer, - Fields, Decorator>& sr_; - bool header_ = false; - Handler h_; - -public: - write_some_win32_op(write_some_win32_op&&) = default; - write_some_win32_op(write_some_win32_op const&) = default; - - template - write_some_win32_op( - DeducedHandler&& h, - boost::asio::basic_stream_socket& s, - serializer, - Fields, Decorator>& sr) - : sock_(s) - , sr_(sr) - , h_(std::forward(h)) - { - } - - void - operator()(); - - void - operator()(error_code ec, - std::size_t bytes_transferred = 0); - - friend - void* asio_handler_allocate( - std::size_t size, write_some_win32_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->h_)); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, write_some_win32_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->h_)); - } - - friend - bool asio_handler_is_continuation(write_some_win32_op* op) - { - using boost::asio::asio_handler_is_continuation; - return asio_handler_is_continuation( - std::addressof(op->h_)); - } - - template - friend - void asio_handler_invoke(Function&& f, write_some_win32_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->h_)); - } -}; - -template -void -write_some_win32_op< - Protocol, Handler, isRequest, Fields, Decorator>:: -operator()() -{ - if(! sr_.is_header_done()) - { - header_ = true; - sr_.split(true); - return detail::async_write_some( - sock_, sr_, std::move(*this)); - } - if(sr_.chunked()) - { - return detail::async_write_some( - sock_, sr_, std::move(*this)); - } - auto& r = sr_.reader_impl(); - boost::detail::winapi::DWORD_ const nNumberOfBytesToWrite = - std::min( - beast::detail::clamp(std::min( - r.body_.last_ - r.pos_, sr_.limit())), - 2147483646); - boost::asio::windows::overlapped_ptr overlapped{ - sock_.get_io_service(), *this}; - auto& ov = *overlapped.get(); - ov.Offset = lowPart(r.pos_); - ov.OffsetHigh = highPart(r.pos_); - auto const bSuccess = ::TransmitFile( - sock_.native_handle(), - sr_.get().body.file_.native_handle(), - nNumberOfBytesToWrite, - 0, - overlapped.get(), - nullptr, - 0); - auto const dwError = ::GetLastError(); - if(! bSuccess && dwError != - boost::detail::winapi::ERROR_IO_PENDING_) - { - // completed immediately - overlapped.complete(error_code{static_cast( - boost::detail::winapi::GetLastError()), - system_category()}, 0); - return; - } - overlapped.release(); -} - -template -void -write_some_win32_op< - Protocol, Handler,isRequest, Fields, Decorator>:: -operator()(error_code ec, std::size_t bytes_transferred) -{ - if(! ec) - { - if(header_) - { - header_ = false; - return (*this)(); - } - auto& r = sr_.reader_impl(); - r.pos_ += bytes_transferred; - BOOST_ASSERT(r.pos_ <= r.body_.last_); - if(r.pos_ >= r.body_.last_) - { - sr_.next(ec, null_lambda{}); - BOOST_ASSERT(! ec); - BOOST_ASSERT(sr_.is_done()); - if(! sr_.keep_alive()) - ec = error::end_of_stream; - } - } - h_(ec); -} - -#endif - -} // detail - -//------------------------------------------------------------------------------ - -template -void -write_some( - boost::asio::basic_stream_socket& sock, - serializer, - Fields, Decorator>& sr, - error_code& ec) -{ - if(! sr.is_header_done()) - { - sr.split(true); - detail::write_some(sock, sr, ec); - if(ec) - return; - return; - } - if(sr.chunked()) - { - detail::write_some(sock, sr, ec); - if(ec) - return; - return; - } - auto& r = sr.reader_impl(); - r.body_.file_.seek(r.pos_, ec); - if(ec) - return; - boost::detail::winapi::DWORD_ const nNumberOfBytesToWrite = - std::min( - beast::detail::clamp(std::min( - r.body_.last_ - r.pos_, sr.limit())), - 2147483646); - auto const bSuccess = ::TransmitFile( - sock.native_handle(), - r.body_.file_.native_handle(), - nNumberOfBytesToWrite, - 0, - nullptr, - nullptr, - 0); - if(! bSuccess) - { - ec.assign(static_cast( - boost::detail::winapi::GetLastError()), - system_category()); - return; - } - r.pos_ += nNumberOfBytesToWrite; - BOOST_ASSERT(r.pos_ <= r.body_.last_); - if(r.pos_ < r.body_.last_) - { - ec.assign(0, ec.category()); - } - else - { - sr.next(ec, detail::null_lambda{}); - BOOST_ASSERT(! ec); - BOOST_ASSERT(sr.is_done()); - if(! sr.keep_alive()) - ec = error::end_of_stream; - } -} - -#if BOOST_ASIO_HAS_WINDOWS_OVERLAPPED_PTR - -template< - class Protocol, - bool isRequest, class Fields, class Decorator, - class WriteHandler> -async_return_type -async_write_some( - boost::asio::basic_stream_socket& sock, - serializer, - Fields, Decorator>& sr, - WriteHandler&& handler) -{ - async_completion init{handler}; - detail::write_some_win32_op, isRequest, Fields, - Decorator>{init.completion_handler, sock, sr}(); - return init.result.get(); -} - -#endif - -} // http -} // beast - -#endif - -#endif diff --git a/src/beast/include/beast/http/impl/message.ipp b/src/beast/include/beast/http/impl/message.ipp deleted file mode 100644 index 68af2345e99..00000000000 --- a/src/beast/include/beast/http/impl/message.ipp +++ /dev/null @@ -1,415 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_IMPL_MESSAGE_IPP -#define BEAST_HTTP_IMPL_MESSAGE_IPP - -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -template -template -header:: -header(Arg1&& arg1, ArgN&&... argn) - : Fields(std::forward(arg1), - std::forward(argn)...) -{ -} - -template -inline -verb -header:: -method() const -{ - return method_; -} - -template -void -header:: -method(verb v) -{ - if(v == verb::unknown) - BOOST_THROW_EXCEPTION( - std::invalid_argument{"unknown method"}); - method_ = v; - this->set_method_impl({}); -} - -template -string_view -header:: -method_string() const -{ - if(method_ != verb::unknown) - return to_string(method_); - return this->get_method_impl(); -} - -template -void -header:: -method_string(string_view s) -{ - method_ = string_to_verb(s); - if(method_ != verb::unknown) - this->set_method_impl({}); - else - this->set_method_impl(s); -} - -template -inline -string_view -header:: -target() const -{ - return this->get_target_impl(); -} - -template -inline -void -header:: -target(string_view s) -{ - this->set_target_impl(s); -} - -template -void -swap( - header& h1, - header& h2) -{ - using std::swap; - swap( - static_cast(h1), - static_cast(h2)); - swap(h1.version, h2.version); - swap(h1.method_, h2.method_); -} - -//------------------------------------------------------------------------------ - -template -template -header:: -header(Arg1&& arg1, ArgN&&... argn) - : Fields(std::forward(arg1), - std::forward(argn)...) -{ -} - -#if 0 -template -template -header:: -header(status result, unsigned version_, Args&&... args) - : Fields(std::forward(args)...) - , version(version_) - , result_(result) -{ -} -#endif - -template -inline -status -header:: -result() const -{ - return int_to_status( - static_cast(result_)); -} - -template -inline -void -header:: -result(status v) -{ - result_ = v; -} - -template -inline -void -header:: -result(unsigned v) -{ - if(v > 999) - BOOST_THROW_EXCEPTION( - std::invalid_argument{ - "invalid status-code"}); - result_ = static_cast(v); -} - -template -inline -unsigned -header:: -result_int() const -{ - return static_cast(result_); -} - -template -string_view -header:: -reason() const -{ - auto const s = this->get_reason_impl(); - if(! s.empty()) - return s; - return obsolete_reason(result_); -} - -template -inline -void -header:: -reason(string_view s) -{ - this->set_reason_impl(s); -} - -template -void -swap( - header& h1, - header& h2) -{ - using std::swap; - swap( - static_cast(h1), - static_cast(h2)); - swap(h1.version, h2.version); - swap(h1.result_, h2.result_); -} - -//------------------------------------------------------------------------------ - -template -template -message:: -message(header_type&& h, BodyArgs&&... body_args) - : header_type(std::move(h)) - , body(std::forward(body_args)...) -{ -} - -template -template -message:: -message(header_type const& h, BodyArgs&&... body_args) - : header_type(h) - , body(std::forward(body_args)...) -{ -} - -template -template -message:: -message(verb method, string_view target, Version version) - : header_type(method, target, version) -{ -} - -template -template -message:: -message(verb method, string_view target, - Version version, BodyArg&& body_arg) - : header_type(method, target, version) - , body(std::forward(body_arg)) -{ -} - -template -template -message:: -message( - verb method, string_view target, Version version, - BodyArg&& body_arg, - FieldsArg&& fields_arg) - : header_type(method, target, version, - std::forward(fields_arg)) - , body(std::forward(body_arg)) -{ -} - -template -template -message:: -message(status result, Version version) - : header_type(result, version) -{ -} - -template -template -message:: -message(status result, Version version, - BodyArg&& body_arg) - : header_type(result, version) - , body(std::forward(body_arg)) -{ -} - -template -template -message:: -message(status result, Version version, - BodyArg&& body_arg, FieldsArg&& fields_arg) - : header_type(result, version, - std::forward(fields_arg)) - , body(std::forward(body_arg)) -{ -} - -template -message:: -message(std::piecewise_construct_t) -{ -} - -template -template -message:: -message(std::piecewise_construct_t, - std::tuple body_args) - : message(std::piecewise_construct, - body_args, - beast::detail::make_index_sequence< - sizeof...(BodyArgs)>{}) -{ -} - -template -template -message:: -message(std::piecewise_construct_t, - std::tuple body_args, - std::tuple fields_args) - : message(std::piecewise_construct, - body_args, - fields_args, - beast::detail::make_index_sequence< - sizeof...(BodyArgs)>{}, - beast::detail::make_index_sequence< - sizeof...(FieldsArgs)>{}) -{ -} - -template -void -message:: -chunked(bool value) -{ - this->set_chunked_impl(value); - this->set_content_length_impl(boost::none); -} - -template -void -message:: -content_length( - boost::optional const& value) -{ - this->set_content_length_impl(value); - this->set_chunked_impl(false); -} - -template -boost::optional -message:: -payload_size() const -{ - return payload_size(detail::is_body_sized{}); -} - -template -void -message:: -prepare_payload(std::true_type) -{ - auto const n = payload_size(); - if(this->method() == verb::trace && (! n || *n > 0)) - BOOST_THROW_EXCEPTION(std::invalid_argument{ - "invalid request body"}); - if(n) - { - if(*n > 0 || - this->method() == verb::options || - this->method() == verb::put || - this->method() == verb::post) - { - this->content_length(n); - } - else - { - this->chunked(false); - } - } - else if(this->version >= 11) - { - this->chunked(true); - } - else - { - this->chunked(false); - } -} - -template -void -message:: -prepare_payload(std::false_type) -{ - auto const n = payload_size(); - if((status_class(this->result()) == status_class::informational || - this->result() == status::no_content || - this->result() == status::not_modified)) - { - if(! n || *n > 0) - // The response body MUST BE empty for this case - BOOST_THROW_EXCEPTION(std::invalid_argument{ - "invalid response body"}); - } - if(n) - this->content_length(n); - else - this->chunked(true); -} - -//------------------------------------------------------------------------------ - -template -void -swap( - message& m1, - message& m2) -{ - using std::swap; - swap( - static_cast&>(m1), - static_cast&>(m2)); - swap(m1.body, m2.body); -} - -} // http -} // beast - -#endif diff --git a/src/beast/include/beast/http/impl/parser.ipp b/src/beast/include/beast/http/impl/parser.ipp deleted file mode 100644 index 73bacd9ad7c..00000000000 --- a/src/beast/include/beast/http/impl/parser.ipp +++ /dev/null @@ -1,51 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_IMPL_PARSER_IPP -#define BEAST_HTTP_IMPL_PARSER_IPP - -#include -#include - -namespace beast { -namespace http { - -template -parser:: -parser() - : wr_(m_) -{ -} - -template -template -parser:: -parser(Arg1&& arg1, ArgN&&... argn) - : m_(std::forward(arg1), - std::forward(argn)...) - , wr_(m_) -{ -} - -template -template -parser:: -parser(parser&& p, - Args&&... args) - : base_type(std::move(p)) - , m_(p.release(), std::forward(args)...) - , wr_(m_) -{ - if(wr_inited_) - BOOST_THROW_EXCEPTION(std::invalid_argument{ - "moved-from parser has a body"}); -} - -} // http -} // beast - -#endif diff --git a/src/beast/include/beast/http/impl/read.ipp b/src/beast/include/beast/http/impl/read.ipp deleted file mode 100644 index 08e7c552d37..00000000000 --- a/src/beast/include/beast/http/impl/read.ipp +++ /dev/null @@ -1,777 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_IMPL_READ_IPP_HPP -#define BEAST_HTTP_IMPL_READ_IPP_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -namespace detail { - -//------------------------------------------------------------------------------ - -template -class read_some_op -{ - int state_ = 0; - Stream& s_; - DynamicBuffer& b_; - basic_parser& p_; - boost::optional mb_; - Handler h_; - -public: - read_some_op(read_some_op&&) = default; - read_some_op(read_some_op const&) = default; - - template - read_some_op(DeducedHandler&& h, Stream& s, - DynamicBuffer& b, basic_parser& p) - : s_(s) - , b_(b) - , p_(p) - , h_(std::forward(h)) - { - } - - void - operator()(error_code ec, std::size_t bytes_transferred); - - friend - void* asio_handler_allocate( - std::size_t size, read_some_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->h_)); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, read_some_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->h_)); - } - - friend - bool asio_handler_is_continuation(read_some_op* op) - { - using boost::asio::asio_handler_is_continuation; - return op->state_ >= 2 ? true : - asio_handler_is_continuation( - std::addressof(op->h_)); - } - - template - friend - void asio_handler_invoke(Function&& f, read_some_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->h_)); - } -}; - -template -void -read_some_op:: -operator()(error_code ec, std::size_t bytes_transferred) -{ - switch(state_) - { - case 0: - state_ = 1; - if(b_.size() == 0) - goto do_read; - goto do_parse; - - case 1: - state_ = 2; - case 2: - if(ec == boost::asio::error::eof) - { - BOOST_ASSERT(bytes_transferred == 0); - if(p_.got_some()) - { - // caller sees EOF on next read - ec.assign(0, ec.category()); - p_.put_eof(ec); - if(ec) - goto upcall; - BOOST_ASSERT(p_.is_done()); - goto upcall; - } - ec = error::end_of_stream; - goto upcall; - } - if(ec) - goto upcall; - b_.commit(bytes_transferred); - - do_parse: - b_.consume(p_.put(b_.data(), ec)); - if(! ec || ec != http::error::need_more) - goto do_upcall; - ec.assign(0, ec.category()); - - do_read: - try - { - mb_.emplace(b_.prepare( - read_size_or_throw(b_, 65536))); - } - catch(std::length_error const&) - { - ec = error::buffer_overflow; - goto do_upcall; - } - return s_.async_read_some(*mb_, std::move(*this)); - - do_upcall: - if(state_ >= 2) - goto upcall; - state_ = 3; - return s_.get_io_service().post( - bind_handler(std::move(*this), ec, 0)); - - case 3: - break; - } -upcall: - h_(ec); -} - -//------------------------------------------------------------------------------ - -struct parser_is_done -{ - template - bool - operator()(basic_parser< - isRequest, Derived> const& p) const - { - return p.is_done(); - } -}; - -struct parser_is_header_done -{ - template - bool - operator()(basic_parser< - isRequest, Derived> const& p) const - { - return p.is_header_done(); - } -}; - -template -class read_op -{ - int state_ = 0; - Stream& s_; - DynamicBuffer& b_; - basic_parser& p_; - Handler h_; - -public: - read_op(read_op&&) = default; - read_op(read_op const&) = default; - - template - read_op(DeducedHandler&& h, Stream& s, - DynamicBuffer& b, basic_parser& p) - : s_(s) - , b_(b) - , p_(p) - , h_(std::forward(h)) - { - } - - void - operator()(error_code ec); - - friend - void* asio_handler_allocate( - std::size_t size, read_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->h_)); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, read_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->h_)); - } - - friend - bool asio_handler_is_continuation(read_op* op) - { - using boost::asio::asio_handler_is_continuation; - return op->state_ >= 3 ? true : - asio_handler_is_continuation( - std::addressof(op->h_)); - } - - template - friend - void asio_handler_invoke(Function&& f, read_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->h_)); - } -}; - -template -void -read_op:: -operator()(error_code ec) -{ - switch(state_) - { - case 0: - if(Condition{}(p_)) - { - state_ = 1; - return s_.get_io_service().post( - bind_handler(std::move(*this), ec)); - } - state_ = 2; - - do_read: - return async_read_some( - s_, b_, p_, std::move(*this)); - - case 1: - goto upcall; - - case 2: - case 3: - if(ec) - goto upcall; - if(Condition{}(p_)) - goto upcall; - state_ = 3; - goto do_read; - } -upcall: - h_(ec); -} - -//------------------------------------------------------------------------------ - -template -class read_msg_op -{ - using parser_type = - parser; - - using message_type = - typename parser_type::value_type; - - struct data - { - int state = 0; - Stream& s; - DynamicBuffer& b; - message_type& m; - parser_type p; - - data(Handler&, Stream& s_, - DynamicBuffer& b_, message_type& m_) - : s(s_) - , b(b_) - , m(m_) - , p(std::move(m)) - { - p.eager(true); - } - }; - - handler_ptr d_; - -public: - read_msg_op(read_msg_op&&) = default; - read_msg_op(read_msg_op const&) = default; - - template - read_msg_op(DeducedHandler&& h, Stream& s, Args&&... args) - : d_(std::forward(h), - s, std::forward(args)...) - { - } - - void - operator()(error_code ec); - - friend - void* asio_handler_allocate( - std::size_t size, read_msg_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->d_.handler())); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, read_msg_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->d_.handler())); - } - - friend - bool asio_handler_is_continuation(read_msg_op* op) - { - using boost::asio::asio_handler_is_continuation; - return op->d_->state >= 2 ? true : - asio_handler_is_continuation( - std::addressof(op->d_.handler())); - } - - template - friend - void asio_handler_invoke(Function&& f, read_msg_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->d_.handler())); - } -}; - -template -void -read_msg_op:: -operator()(error_code ec) -{ - auto& d = *d_; - switch(d.state) - { - case 0: - d.state = 1; - - do_read: - return async_read_some( - d.s, d.b, d.p, std::move(*this)); - - case 1: - case 2: - if(ec) - goto upcall; - if(d.p.is_done()) - { - d.m = d.p.release(); - goto upcall; - } - d.state = 2; - goto do_read; - } -upcall: - d_.invoke(ec); -} - -} // detail - -//------------------------------------------------------------------------------ - -template< - class SyncReadStream, - class DynamicBuffer, - bool isRequest, class Derived> -void -read_some( - SyncReadStream& stream, - DynamicBuffer& buffer, - basic_parser& parser) -{ - static_assert(is_sync_read_stream::value, - "SyncReadStream requirements not met"); - static_assert(is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - BOOST_ASSERT(! parser.is_done()); - error_code ec; - read_some(stream, buffer, parser, ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); -} - -template< - class SyncReadStream, - class DynamicBuffer, - bool isRequest, class Derived> -void -read_some( - SyncReadStream& stream, - DynamicBuffer& buffer, - basic_parser& parser, - error_code& ec) -{ - static_assert(is_sync_read_stream::value, - "SyncReadStream requirements not met"); - static_assert(is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - BOOST_ASSERT(! parser.is_done()); - if(buffer.size() == 0) - goto do_read; - for(;;) - { - // invoke parser - buffer.consume(parser.put(buffer.data(), ec)); - if(! ec) - break; - if(ec != http::error::need_more) - break; - do_read: - boost::optional b; - try - { - b.emplace(buffer.prepare( - read_size_or_throw(buffer, 65536))); - } - catch(std::length_error const&) - { - ec = error::buffer_overflow; - return; - } - auto const bytes_transferred = - stream.read_some(*b, ec); - if(ec == boost::asio::error::eof) - { - BOOST_ASSERT(bytes_transferred == 0); - if(parser.got_some()) - { - // caller sees EOF on next read - parser.put_eof(ec); - if(ec) - break; - BOOST_ASSERT(parser.is_done()); - break; - } - ec = error::end_of_stream; - break; - } - if(ec) - break; - buffer.commit(bytes_transferred); - } -} - -template< - class AsyncReadStream, - class DynamicBuffer, - bool isRequest, class Derived, - class ReadHandler> -async_return_type< - ReadHandler, void(error_code)> -async_read_some( - AsyncReadStream& stream, - DynamicBuffer& buffer, - basic_parser& parser, - ReadHandler&& handler) -{ - static_assert(is_async_read_stream::value, - "AsyncReadStream requirements not met"); - static_assert(is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - BOOST_ASSERT(! parser.is_done()); - async_completion init{handler}; - detail::read_some_op>{ - init.completion_handler, stream, buffer, parser}( - error_code{}, 0); - return init.result.get(); -} - -//------------------------------------------------------------------------------ - -template< - class SyncReadStream, - class DynamicBuffer, - bool isRequest, class Derived> -void -read_header( - SyncReadStream& stream, - DynamicBuffer& buffer, - basic_parser& parser) -{ - static_assert(is_sync_read_stream::value, - "SyncReadStream requirements not met"); - static_assert(is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - error_code ec; - read_header(stream, buffer, parser, ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); -} - -template< - class SyncReadStream, - class DynamicBuffer, - bool isRequest, class Derived> -void -read_header( - SyncReadStream& stream, - DynamicBuffer& buffer, - basic_parser& parser, - error_code& ec) -{ - static_assert(is_sync_read_stream::value, - "SyncReadStream requirements not met"); - static_assert(is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - parser.eager(false); - if(parser.is_header_done()) - { - ec.assign(0, ec.category()); - return; - } - do - { - read_some(stream, buffer, parser, ec); - if(ec) - return; - } - while(! parser.is_header_done()); -} - -template< - class AsyncReadStream, - class DynamicBuffer, - bool isRequest, class Derived, - class ReadHandler> -async_return_type -async_read_header( - AsyncReadStream& stream, - DynamicBuffer& buffer, - basic_parser& parser, - ReadHandler&& handler) -{ - static_assert(is_async_read_stream::value, - "AsyncReadStream requirements not met"); - static_assert(is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - parser.eager(false); - async_completion init{handler}; - detail::read_op>{ - init.completion_handler, stream, buffer, parser}( - error_code{}); - return init.result.get(); -} - -//------------------------------------------------------------------------------ - -template< - class SyncReadStream, - class DynamicBuffer, - bool isRequest, class Derived> -void -read( - SyncReadStream& stream, - DynamicBuffer& buffer, - basic_parser& parser) -{ - static_assert(is_sync_read_stream::value, - "SyncReadStream requirements not met"); - static_assert(is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - error_code ec; - read(stream, buffer, parser, ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); -} - -template< - class SyncReadStream, - class DynamicBuffer, - bool isRequest, class Derived> -void -read( - SyncReadStream& stream, - DynamicBuffer& buffer, - basic_parser& parser, - error_code& ec) -{ - static_assert(is_sync_read_stream::value, - "SyncReadStream requirements not met"); - static_assert(is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - parser.eager(true); - if(parser.is_done()) - { - ec.assign(0, ec.category()); - return; - } - do - { - read_some(stream, buffer, parser, ec); - if(ec) - return; - } - while(! parser.is_done()); -} - -template< - class AsyncReadStream, - class DynamicBuffer, - bool isRequest, class Derived, - class ReadHandler> -async_return_type -async_read( - AsyncReadStream& stream, - DynamicBuffer& buffer, - basic_parser& parser, - ReadHandler&& handler) -{ - static_assert(is_async_read_stream::value, - "AsyncReadStream requirements not met"); - static_assert(is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - parser.eager(true); - async_completion init{handler}; - detail::read_op>{ - init.completion_handler, stream, buffer, parser}( - error_code{}); - return init.result.get(); -} - -//------------------------------------------------------------------------------ - -template< - class SyncReadStream, - class DynamicBuffer, - bool isRequest, class Body, class Allocator> -void -read( - SyncReadStream& stream, - DynamicBuffer& buffer, - message>& msg) -{ - static_assert(is_sync_read_stream::value, - "SyncReadStream requirements not met"); - static_assert(is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - static_assert(is_body::value, - "Body requirements not met"); - static_assert(is_body_writer::value, - "BodyWriter requirements not met"); - error_code ec; - read(stream, buffer, msg, ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); -} - -template< - class SyncReadStream, - class DynamicBuffer, - bool isRequest, class Body, class Allocator> -void -read( - SyncReadStream& stream, - DynamicBuffer& buffer, - message>& msg, - error_code& ec) -{ - static_assert(is_sync_read_stream::value, - "SyncReadStream requirements not met"); - static_assert(is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - static_assert(is_body::value, - "Body requirements not met"); - static_assert(is_body_writer::value, - "BodyWriter requirements not met"); - parser p{std::move(msg)}; - p.eager(true); - read(stream, buffer, p.base(), ec); - if(ec) - return; - msg = p.release(); -} - -template< - class AsyncReadStream, - class DynamicBuffer, - bool isRequest, class Body, class Allocator, - class ReadHandler> -async_return_type -async_read( - AsyncReadStream& stream, - DynamicBuffer& buffer, - message>& msg, - ReadHandler&& handler) -{ - static_assert(is_async_read_stream::value, - "AsyncReadStream requirements not met"); - static_assert(is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - static_assert(is_body::value, - "Body requirements not met"); - static_assert(is_body_writer::value, - "BodyWriter requirements not met"); - async_completion init{handler}; - detail::read_msg_op>{ - init.completion_handler, stream, buffer, msg}( - error_code{}); - return init.result.get(); -} - -} // http -} // beast - -#endif diff --git a/src/beast/include/beast/http/impl/rfc7230.ipp b/src/beast/include/beast/http/impl/rfc7230.ipp deleted file mode 100644 index bce0ec856b1..00000000000 --- a/src/beast/include/beast/http/impl/rfc7230.ipp +++ /dev/null @@ -1,568 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_IMPL_RFC7230_IPP -#define BEAST_HTTP_IMPL_RFC7230_IPP - -#include -#include - -namespace beast { -namespace http { - -class param_list::const_iterator -{ - using iter_type = string_view::const_iterator; - - std::string s_; - detail::param_iter pi_; - -public: - using value_type = param_list::value_type; - using pointer = value_type const*; - using reference = value_type const&; - using difference_type = std::ptrdiff_t; - using iterator_category = std::input_iterator_tag; - - const_iterator() = default; - - bool - operator==(const_iterator const& other) const - { - return - other.pi_.it == pi_.it && - other.pi_.last == pi_.last && - other.pi_.first == pi_.first; - } - - bool - operator!=(const_iterator const& other) const - { - return !(*this == other); - } - - reference - operator*() const - { - return pi_.v; - } - - pointer - operator->() const - { - return &*(*this); - } - - const_iterator& - operator++() - { - increment(); - return *this; - } - - const_iterator - operator++(int) - { - auto temp = *this; - ++(*this); - return temp; - } - -private: - friend class param_list; - - const_iterator(iter_type first, iter_type last) - { - pi_.it = first; - pi_.first = first; - pi_.last = last; - increment(); - } - - template - static - std::string - unquote(string_view sr); - - template - void - increment(); -}; - -inline -auto -param_list:: -begin() const -> - const_iterator -{ - return const_iterator{s_.begin(), s_.end()}; -} - -inline -auto -param_list:: -end() const -> - const_iterator -{ - return const_iterator{s_.end(), s_.end()}; -} - -inline -auto -param_list:: -cbegin() const -> - const_iterator -{ - return const_iterator{s_.begin(), s_.end()}; -} - -inline -auto -param_list:: -cend() const -> - const_iterator -{ - return const_iterator{s_.end(), s_.end()}; -} - -template -std::string -param_list::const_iterator:: -unquote(string_view sr) -{ - std::string s; - s.reserve(sr.size()); - auto it = sr.begin() + 1; - auto end = sr.end() - 1; - while(it != end) - { - if(*it == '\\') - ++it; - s.push_back(*it); - ++it; - } - return s; -} - -template -void -param_list::const_iterator:: -increment() -{ - s_.clear(); - pi_.increment(); - if(pi_.empty()) - { - pi_.it = pi_.last; - pi_.first = pi_.last; - } - else if(! pi_.v.second.empty() && - pi_.v.second.front() == '"') - { - s_ = unquote(pi_.v.second); - pi_.v.second = string_view{ - s_.data(), s_.size()}; - } -} - -//------------------------------------------------------------------------------ - -class ext_list::const_iterator -{ - ext_list::value_type v_; - iter_type it_; - iter_type first_; - iter_type last_; - -public: - using value_type = ext_list::value_type; - using pointer = value_type const*; - using reference = value_type const&; - using difference_type = std::ptrdiff_t; - using iterator_category = std::forward_iterator_tag; - - const_iterator() = default; - - bool - operator==(const_iterator const& other) const - { - return - other.it_ == it_ && - other.first_ == first_ && - other.last_ == last_; - } - - bool - operator!=(const_iterator const& other) const - { - return !(*this == other); - } - - reference - operator*() const - { - return v_; - } - - pointer - operator->() const - { - return &*(*this); - } - - const_iterator& - operator++() - { - increment(); - return *this; - } - - const_iterator - operator++(int) - { - auto temp = *this; - ++(*this); - return temp; - } - -private: - friend class ext_list; - - const_iterator(iter_type begin, iter_type end) - { - it_ = begin; - first_ = begin; - last_ = end; - increment(); - } - - template - void - increment(); -}; - -inline -auto -ext_list:: -begin() const -> - const_iterator -{ - return const_iterator{s_.begin(), s_.end()}; -} - -inline -auto -ext_list:: -end() const -> - const_iterator -{ - return const_iterator{s_.end(), s_.end()}; -} - -inline -auto -ext_list:: -cbegin() const -> - const_iterator -{ - return const_iterator{s_.begin(), s_.end()}; -} - -inline -auto -ext_list:: -cend() const -> - const_iterator -{ - return const_iterator{s_.end(), s_.end()}; -} - -template -auto -ext_list:: -find(T const& s) -> - const_iterator -{ - return std::find_if(begin(), end(), - [&s](value_type const& v) - { - return iequals(s, v.first); - }); -} - -template -bool -ext_list:: -exists(T const& s) -{ - return find(s) != end(); -} - -template -void -ext_list::const_iterator:: -increment() -{ - /* - ext-list = *( "," OWS ) ext *( OWS "," [ OWS ext ] ) - ext = token param-list - param-list = *( OWS ";" OWS param ) - param = token OWS "=" OWS ( token / quoted-string ) - - chunked;a=b;i=j,gzip;windowBits=12 - x,y - ,,,,,chameleon - */ - auto const err = - [&] - { - it_ = last_; - first_ = last_; - }; - auto need_comma = it_ != first_; - v_.first = {}; - first_ = it_; - for(;;) - { - detail::skip_ows(it_, last_); - if(it_ == last_) - return err(); - auto const c = *it_; - if(detail::is_tchar(c)) - { - if(need_comma) - return err(); - auto const p0 = it_; - for(;;) - { - ++it_; - if(it_ == last_) - break; - if(! detail::is_tchar(*it_)) - break; - } - v_.first = string_view{&*p0, - static_cast(it_ - p0)}; - detail::param_iter pi; - pi.it = it_; - pi.first = it_; - pi.last = last_; - for(;;) - { - pi.increment(); - if(pi.empty()) - break; - } - v_.second = param_list{string_view{&*it_, - static_cast(pi.it - it_)}}; - it_ = pi.it; - return; - } - if(c != ',') - return err(); - need_comma = false; - ++it_; - } -} - -//------------------------------------------------------------------------------ - -class token_list::const_iterator -{ - token_list::value_type v_; - iter_type it_; - iter_type first_; - iter_type last_; - -public: - using value_type = token_list::value_type; - using pointer = value_type const*; - using reference = value_type const&; - using difference_type = std::ptrdiff_t; - using iterator_category = std::forward_iterator_tag; - - const_iterator() = default; - - bool - operator==(const_iterator const& other) const - { - return - other.it_ == it_ && - other.first_ == first_ && - other.last_ == last_; - } - - bool - operator!=(const_iterator const& other) const - { - return !(*this == other); - } - - reference - operator*() const - { - return v_; - } - - pointer - operator->() const - { - return &*(*this); - } - - const_iterator& - operator++() - { - increment(); - return *this; - } - - const_iterator - operator++(int) - { - auto temp = *this; - ++(*this); - return temp; - } - -private: - friend class token_list; - - const_iterator(iter_type begin, iter_type end) - { - it_ = begin; - first_ = begin; - last_ = end; - increment(); - } - - template - void - increment(); -}; - -inline -auto -token_list:: -begin() const -> - const_iterator -{ - return const_iterator{s_.begin(), s_.end()}; -} - -inline -auto -token_list:: -end() const -> - const_iterator -{ - return const_iterator{s_.end(), s_.end()}; -} - -inline -auto -token_list:: -cbegin() const -> - const_iterator -{ - return const_iterator{s_.begin(), s_.end()}; -} - -inline -auto -token_list:: -cend() const -> - const_iterator -{ - return const_iterator{s_.end(), s_.end()}; -} - -template -void -token_list::const_iterator:: -increment() -{ - /* - token-list = *( "," OWS ) token *( OWS "," [ OWS ext ] ) - */ - auto const err = - [&] - { - it_ = last_; - first_ = last_; - }; - auto need_comma = it_ != first_; - v_ = {}; - first_ = it_; - for(;;) - { - detail::skip_ows(it_, last_); - if(it_ == last_) - return err(); - auto const c = *it_; - if(detail::is_tchar(c)) - { - if(need_comma) - return err(); - auto const p0 = it_; - for(;;) - { - ++it_; - if(it_ == last_) - break; - if(! detail::is_tchar(*it_)) - break; - } - v_ = string_view{&*p0, - static_cast(it_ - p0)}; - return; - } - if(c != ',') - return err(); - need_comma = false; - ++it_; - } -} - -template -bool -token_list:: -exists(T const& s) -{ - return std::find_if(begin(), end(), - [&s](value_type const& v) - { - return iequals(s, v); - } - ) != end(); -} - -template -bool -validate_list(detail::basic_parsed_list< - Policy> const& list) -{ - auto const last = list.end(); - auto it = list.begin(); - if(it.error()) - return false; - while(it != last) - { - ++it; - if(it.error()) - return false; - if(it == last) - break; - } - return true; -} - -} // http -} // beast - -#endif - diff --git a/src/beast/include/beast/http/impl/serializer.ipp b/src/beast/include/beast/http/impl/serializer.ipp deleted file mode 100644 index cc288f683ac..00000000000 --- a/src/beast/include/beast/http/impl/serializer.ipp +++ /dev/null @@ -1,496 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_IMPL_SERIALIZER_IPP -#define BEAST_HTTP_IMPL_SERIALIZER_IPP - -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -template -void -serializer:: -frdinit(std::true_type) -{ - frd_.emplace(m_, m_.version, m_.method()); -} - -template -void -serializer:: -frdinit(std::false_type) -{ - frd_.emplace(m_, m_.version, m_.result_int()); -} - -template -template -inline -void -serializer:: -do_visit(error_code& ec, Visit& visit) -{ - // VFALCO work-around for missing variant::emplace - pv_.~variant(); - new(&pv_) decltype(pv_){ - T1{limit_, boost::get(v_)}}; - visit(ec, beast::detail::make_buffers_ref( - boost::get(pv_))); -} - -//------------------------------------------------------------------------------ - -template -serializer:: -serializer(value_type& m) - : m_(m) - , rd_(m_) -{ -} - -template -serializer:: -serializer(value_type& m, ChunkDecorator const& d) - : m_(m) - , rd_(m_) - , d_(d) -{ -} - -template -template -void -serializer:: -next(error_code& ec, Visit&& visit) -{ - using boost::asio::buffer_size; - using beast::detail::make_buffers_ref; - switch(s_) - { - case do_construct: - { - frdinit(std::integral_constant{}); - keep_alive_ = m_.keep_alive(); - chunked_ = m_.chunked(); - if(chunked_) - goto go_init_c; - s_ = do_init; - BEAST_FALLTHROUGH; - } - - case do_init: - { - rd_.init(ec); - if(ec) - return; - if(split_) - goto go_header_only; - auto result = rd_.get(ec); - if(ec == error::need_more) - goto go_header_only; - if(ec) - return; - if(! result) - goto go_header_only; - more_ = result->second; - v_ = cb2_t{ - boost::in_place_init, - frd_->get(), - result->first}; - s_ = do_header; - BEAST_FALLTHROUGH; - } - - case do_header: - do_visit(ec, visit); - break; - - go_header_only: - v_ = cb1_t{frd_->get()}; - s_ = do_header_only; - case do_header_only: - do_visit(ec, visit); - break; - - case do_body: - s_ = do_body + 1; - BEAST_FALLTHROUGH; - - case do_body + 1: - { - auto result = rd_.get(ec); - if(ec) - return; - if(! result) - goto go_complete; - more_ = result->second; - v_ = cb3_t{result->first}; - s_ = do_body + 2; - BEAST_FALLTHROUGH; - } - - case do_body + 2: - do_visit(ec, visit); - break; - - //---------------------------------------------------------------------- - - go_init_c: - s_ = do_init_c; - case do_init_c: - { - rd_.init(ec); - if(ec) - return; - if(split_) - goto go_header_only_c; - auto result = rd_.get(ec); - if(ec == error::need_more) - goto go_header_only_c; - if(ec) - return; - if(! result) - goto go_header_only_c; - more_ = result->second; - #ifndef BEAST_NO_BIG_VARIANTS - if(! more_) - { - // do it all in one buffer - v_ = cb7_t{ - boost::in_place_init, - frd_->get(), - detail::chunk_header{ - buffer_size(result->first)}, - [&]() - { - auto sv = d_(result->first); - return boost::asio::const_buffers_1{ - sv.data(), sv.size()}; - - }(), - detail::chunk_crlf(), - result->first, - detail::chunk_crlf(), - detail::chunk_final(), - [&]() - { - auto sv = d_( - boost::asio::null_buffers{}); - return boost::asio::const_buffers_1{ - sv.data(), sv.size()}; - - }(), - detail::chunk_crlf()}; - goto go_all_c; - } - #endif - v_ = cb4_t{ - boost::in_place_init, - frd_->get(), - detail::chunk_header{ - buffer_size(result->first)}, - [&]() - { - auto sv = d_(result->first); - return boost::asio::const_buffers_1{ - sv.data(), sv.size()}; - - }(), - detail::chunk_crlf(), - result->first, - detail::chunk_crlf()}; - s_ = do_header_c; - BEAST_FALLTHROUGH; - } - - case do_header_c: - do_visit(ec, visit); - break; - - go_header_only_c: - v_ = cb1_t{frd_->get()}; - s_ = do_header_only_c; - case do_header_only_c: - do_visit(ec, visit); - break; - - case do_body_c: - s_ = do_body_c + 1; - BEAST_FALLTHROUGH; - - case do_body_c + 1: - { - auto result = rd_.get(ec); - if(ec) - return; - if(! result) - goto go_final_c; - more_ = result->second; - #ifndef BEAST_NO_BIG_VARIANTS - if(! more_) - { - // do it all in one buffer - v_ = cb6_t{ - boost::in_place_init, - detail::chunk_header{ - buffer_size(result->first)}, - [&]() - { - auto sv = d_(result->first); - return boost::asio::const_buffers_1{ - sv.data(), sv.size()}; - - }(), - detail::chunk_crlf(), - result->first, - detail::chunk_crlf(), - detail::chunk_final(), - [&]() - { - auto sv = d_( - boost::asio::null_buffers{}); - return boost::asio::const_buffers_1{ - sv.data(), sv.size()}; - - }(), - detail::chunk_crlf()}; - goto go_body_final_c; - } - #endif - v_ = cb5_t{ - boost::in_place_init, - detail::chunk_header{ - buffer_size(result->first)}, - [&]() - { - auto sv = d_(result->first); - return boost::asio::const_buffers_1{ - sv.data(), sv.size()}; - - }(), - detail::chunk_crlf(), - result->first, - detail::chunk_crlf()}; - s_ = do_body_c + 2; - BEAST_FALLTHROUGH; - } - - case do_body_c + 2: - do_visit(ec, visit); - break; - -#ifndef BEAST_NO_BIG_VARIANTS - go_body_final_c: - s_ = do_body_final_c; - case do_body_final_c: - do_visit(ec, visit); - break; - - go_all_c: - s_ = do_all_c; - case do_all_c: - do_visit(ec, visit); - break; -#endif - - go_final_c: - case do_final_c: - v_ = cb8_t{ - boost::in_place_init, - detail::chunk_final(), - [&]() - { - auto sv = d_( - boost::asio::null_buffers{}); - return boost::asio::const_buffers_1{ - sv.data(), sv.size()}; - - }(), - detail::chunk_crlf()}; - s_ = do_final_c + 1; - BEAST_FALLTHROUGH; - - case do_final_c + 1: - do_visit(ec, visit); - break; - - //---------------------------------------------------------------------- - - default: - case do_complete: - BOOST_ASSERT(false); - break; - - go_complete: - s_ = do_complete; - break; - } -} - -template -void -serializer:: -consume(std::size_t n) -{ - using boost::asio::buffer_size; - switch(s_) - { - case do_header: - BOOST_ASSERT(n <= buffer_size( - boost::get(v_))); - boost::get(v_).consume(n); - if(buffer_size(boost::get(v_)) > 0) - break; - header_done_ = true; - v_ = boost::blank{}; - if(! more_) - goto go_complete; - s_ = do_body + 1; - break; - - case do_header_only: - BOOST_ASSERT(n <= buffer_size( - boost::get(v_))); - boost::get(v_).consume(n); - if(buffer_size(boost::get(v_)) > 0) - break; - frd_ = boost::none; - header_done_ = true; - if(! split_) - goto go_complete; - s_ = do_body; - break; - - case do_body + 2: - { - BOOST_ASSERT(n <= buffer_size( - boost::get(v_))); - boost::get(v_).consume(n); - if(buffer_size(boost::get(v_)) > 0) - break; - v_ = boost::blank{}; - if(! more_) - goto go_complete; - s_ = do_body + 1; - break; - } - - //---------------------------------------------------------------------- - - case do_header_c: - BOOST_ASSERT(n <= buffer_size( - boost::get(v_))); - boost::get(v_).consume(n); - if(buffer_size(boost::get(v_)) > 0) - break; - header_done_ = true; - v_ = boost::blank{}; - if(more_) - s_ = do_body_c + 1; - else - s_ = do_final_c; - break; - - case do_header_only_c: - { - BOOST_ASSERT(n <= buffer_size( - boost::get(v_))); - boost::get(v_).consume(n); - if(buffer_size(boost::get(v_)) > 0) - break; - frd_ = boost::none; - header_done_ = true; - if(! split_) - { - s_ = do_final_c; - break; - } - s_ = do_body_c; - break; - } - - case do_body_c + 2: - BOOST_ASSERT(n <= buffer_size( - boost::get(v_))); - boost::get(v_).consume(n); - if(buffer_size(boost::get(v_)) > 0) - break; - v_ = boost::blank{}; - if(more_) - s_ = do_body_c + 1; - else - s_ = do_final_c; - break; - -#ifndef BEAST_NO_BIG_VARIANTS - case do_body_final_c: - { - auto& b = boost::get(v_); - BOOST_ASSERT(n <= buffer_size(b)); - b.consume(n); - if(buffer_size(b) > 0) - break; - v_ = boost::blank{}; - s_ = do_complete; - break; - } - - case do_all_c: - { - auto& b = boost::get(v_); - BOOST_ASSERT(n <= buffer_size(b)); - b.consume(n); - if(buffer_size(b) > 0) - break; - header_done_ = true; - v_ = boost::blank{}; - s_ = do_complete; - break; - } -#endif - - case do_final_c + 1: - BOOST_ASSERT(buffer_size( - boost::get(v_))); - boost::get(v_).consume(n); - if(buffer_size(boost::get(v_)) > 0) - break; - v_ = boost::blank{}; - goto go_complete; - - //---------------------------------------------------------------------- - - default: - BOOST_ASSERT(false); - case do_complete: - break; - - go_complete: - s_ = do_complete; - break; - } -} - -} // http -} // beast - -#endif diff --git a/src/beast/include/beast/http/impl/status.ipp b/src/beast/include/beast/http/impl/status.ipp deleted file mode 100644 index 671547c92cd..00000000000 --- a/src/beast/include/beast/http/impl/status.ipp +++ /dev/null @@ -1,248 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_IMPL_STATUS_IPP -#define BEAST_HTTP_IMPL_STATUS_IPP - -#include -#include - -namespace beast { -namespace http { -namespace detail { - -template -status -int_to_status(unsigned v) -{ - switch(static_cast(v)) - { - // 1xx - case status::continue_: - case status::switching_protocols: - case status::processing: - BEAST_FALLTHROUGH; - - // 2xx - case status::ok: - case status::created: - case status::accepted: - case status::non_authoritative_information: - case status::no_content: - case status::reset_content: - case status::partial_content: - case status::multi_status: - case status::already_reported: - case status::im_used: - BEAST_FALLTHROUGH; - - // 3xx - case status::multiple_choices: - case status::moved_permanently: - case status::found: - case status::see_other: - case status::not_modified: - case status::use_proxy: - case status::temporary_redirect: - case status::permanent_redirect: - BEAST_FALLTHROUGH; - - // 4xx - case status::bad_request: - case status::unauthorized: - case status::payment_required: - case status::forbidden: - case status::not_found: - case status::method_not_allowed: - case status::not_acceptable: - case status::proxy_authentication_required: - case status::request_timeout: - case status::conflict: - case status::gone: - case status::length_required: - case status::precondition_failed: - case status::payload_too_large: - case status::uri_too_long: - case status::unsupported_media_type: - case status::range_not_satisfiable: - case status::expectation_failed: - case status::misdirected_request: - case status::unprocessable_entity: - case status::locked: - case status::failed_dependency: - case status::upgrade_required: - case status::precondition_required: - case status::too_many_requests: - case status::request_header_fields_too_large: - case status::connection_closed_without_response: - case status::unavailable_for_legal_reasons: - case status::client_closed_request: - BEAST_FALLTHROUGH; - - // 5xx - case status::internal_server_error: - case status::not_implemented: - case status::bad_gateway: - case status::service_unavailable: - case status::gateway_timeout: - case status::http_version_not_supported: - case status::variant_also_negotiates: - case status::insufficient_storage: - case status::loop_detected: - case status::not_extended: - case status::network_authentication_required: - case status::network_connect_timeout_error: - return static_cast(v); - - default: - break; - } - return status::unknown; -} - -template -string_view -status_to_string(unsigned v) -{ - switch(static_cast(v)) - { - // 1xx - case status::continue_: return "Continue"; - case status::switching_protocols: return "Switching Protocols"; - case status::processing: return "Processing"; - - // 2xx - case status::ok: return "OK"; - case status::created: return "Created"; - case status::accepted: return "Accepted"; - case status::non_authoritative_information: return "Non-Authoritative Information"; - case status::no_content: return "No Content"; - case status::reset_content: return "Reset Content"; - case status::partial_content: return "Partial Content"; - case status::multi_status: return "Multi-Status"; - case status::already_reported: return "Already Reported"; - case status::im_used: return "IM Used"; - - // 3xx - case status::multiple_choices: return "Multiple Choices"; - case status::moved_permanently: return "Moved Permanently"; - case status::found: return "Found"; - case status::see_other: return "See Other"; - case status::not_modified: return "Not Modified"; - case status::use_proxy: return "Use Proxy"; - case status::temporary_redirect: return "Temporary Redirect"; - case status::permanent_redirect: return "Permanent Redirect"; - - // 4xx - case status::bad_request: return "Bad Request"; - case status::unauthorized: return "Unauthorized"; - case status::payment_required: return "Payment Required"; - case status::forbidden: return "Forbidden"; - case status::not_found: return "Not Found"; - case status::method_not_allowed: return "Method Not Allowed"; - case status::not_acceptable: return "Not Acceptable"; - case status::proxy_authentication_required: return "Proxy Authentication Required"; - case status::request_timeout: return "Request Timeout"; - case status::conflict: return "Conflict"; - case status::gone: return "Gone"; - case status::length_required: return "Length Required"; - case status::precondition_failed: return "Precondition Failed"; - case status::payload_too_large: return "Payload Too Large"; - case status::uri_too_long: return "URI Too Long"; - case status::unsupported_media_type: return "Unsupported Media Type"; - case status::range_not_satisfiable: return "Range Not Satisfiable"; - case status::expectation_failed: return "Expectation Failed"; - case status::misdirected_request: return "Misdirected Request"; - case status::unprocessable_entity: return "Unprocessable Entity"; - case status::locked: return "Locked"; - case status::failed_dependency: return "Failed Dependency"; - case status::upgrade_required: return "Upgrade Required"; - case status::precondition_required: return "Precondition Required"; - case status::too_many_requests: return "Too Many Requests"; - case status::request_header_fields_too_large: return "Request Header Fields Too Large"; - case status::connection_closed_without_response: return "Connection Closed Without Response"; - case status::unavailable_for_legal_reasons: return "Unavailable For Legal Reasons"; - case status::client_closed_request: return "Client Closed Request"; - // 5xx - case status::internal_server_error: return "Internal Server Error"; - case status::not_implemented: return "Not Implemented"; - case status::bad_gateway: return "Bad Gateway"; - case status::service_unavailable: return "Service Unavailable"; - case status::gateway_timeout: return "Gateway Timeout"; - case status::http_version_not_supported: return "HTTP Version Not Supported"; - case status::variant_also_negotiates: return "Variant Also Negotiates"; - case status::insufficient_storage: return "Insufficient Storage"; - case status::loop_detected: return "Loop Detected"; - case status::not_extended: return "Not Extended"; - case status::network_authentication_required: return "Network Authentication Required"; - case status::network_connect_timeout_error: return "Network Connect Timeout Error"; - - default: - break; - } - return ""; -} - -template -status_class -to_status_class(unsigned v) -{ - switch(v / 100) - { - case 1: return status_class::informational; - case 2: return status_class::successful; - case 3: return status_class::redirection; - case 4: return status_class::client_error; - case 5: return status_class::server_error; - default: - break; - } - return status_class::unknown; -} - -} // detail - -inline -status -int_to_status(unsigned v) -{ - return detail::int_to_status(v); -} - -inline -status_class -to_status_class(unsigned v) -{ - return detail::to_status_class(v); -} - -inline -status_class -to_status_class(status v) -{ - return to_status_class(static_cast(v)); -} - -inline -string_view -obsolete_reason(status v) -{ - return detail::status_to_string( - static_cast(v)); -} - -inline -std::ostream& -operator<<(std::ostream& os, status v) -{ - return os << obsolete_reason(v); -} - -} // http -} // beast - -#endif diff --git a/src/beast/include/beast/http/impl/verb.ipp b/src/beast/include/beast/http/impl/verb.ipp deleted file mode 100644 index ad0f1b5ca87..00000000000 --- a/src/beast/include/beast/http/impl/verb.ipp +++ /dev/null @@ -1,333 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_IMPL_VERB_IPP -#define BEAST_HTTP_IMPL_VERB_IPP - -#include -#include -#include - -namespace beast { -namespace http { - -namespace detail { - -template -inline -string_view -verb_to_string(verb v) -{ - switch(v) - { - case verb::delete_: return "DELETE"; - case verb::get: return "GET"; - case verb::head: return "HEAD"; - case verb::post: return "POST"; - case verb::put: return "PUT"; - case verb::connect: return "CONNECT"; - case verb::options: return "OPTIONS"; - case verb::trace: return "TRACE"; - - case verb::copy: return "COPY"; - case verb::lock: return "LOCK"; - case verb::mkcol: return "MKCOL"; - case verb::move: return "MOVE"; - case verb::propfind: return "PROPFIND"; - case verb::proppatch: return "PROPPATCH"; - case verb::search: return "SEARCH"; - case verb::unlock: return "UNLOCK"; - case verb::bind: return "BIND"; - case verb::rebind: return "REBIND"; - case verb::unbind: return "UNBIND"; - case verb::acl: return "ACL"; - - case verb::report: return "REPORT"; - case verb::mkactivity: return "MKACTIVITY"; - case verb::checkout: return "CHECKOUT"; - case verb::merge: return "MERGE"; - - case verb::msearch: return "M-SEARCH"; - case verb::notify: return "NOTIFY"; - case verb::subscribe: return "SUBSCRIBE"; - case verb::unsubscribe: return "UNSUBSCRIBE"; - - case verb::patch: return "PATCH"; - case verb::purge: return "PURGE"; - - case verb::mkcalendar: return "MKCALENDAR"; - - case verb::link: return "LINK"; - case verb::unlink: return "UNLINK"; - - case verb::unknown: - return ""; - } - - BOOST_THROW_EXCEPTION(std::invalid_argument{"unknown verb"}); -} - -template -verb -string_to_verb(string_view v) -{ -/* - ACL - BIND - CHECKOUT - CONNECT - COPY - DELETE - GET - HEAD - LINK - LOCK - M-SEARCH - MERGE - MKACTIVITY - MKCALENDAR - MKCOL - MOVE - NOTIFY - OPTIONS - PATCH - POST - PROPFIND - PROPPATCH - PURGE - PUT - REBIND - REPORT - SEARCH - SUBSCRIBE - TRACE - UNBIND - UNLINK - UNLOCK - UNSUBSCRIBE -*/ - if(v.size() < 3) - return verb::unknown; - // s must be null terminated - auto const eq = - [](string_view sv, char const* s) - { - auto p = sv.data(); - for(;;) - { - if(*s != *p) - return false; - ++s; - ++p; - if(! *s) - return p == sv.end(); - } - }; - auto c = v[0]; - v.remove_prefix(1); - switch(c) - { - case 'A': - if(v == "CL") - return verb::acl; - break; - - case 'B': - if(v == "IND") - return verb::bind; - break; - - case 'C': - c = v[0]; - v.remove_prefix(1); - switch(c) - { - case 'H': - if(eq(v, "ECKOUT")) - return verb::checkout; - break; - - case 'O': - if(eq(v, "NNECT")) - return verb::connect; - if(eq(v, "PY")) - return verb::copy; - BEAST_FALLTHROUGH; - - default: - break; - } - break; - - case 'D': - if(eq(v, "ELETE")) - return verb::delete_; - break; - - case 'G': - if(eq(v, "ET")) - return verb::get; - break; - - case 'H': - if(eq(v, "EAD")) - return verb::head; - break; - - case 'L': - if(eq(v, "INK")) - return verb::link; - if(eq(v, "OCK")) - return verb::lock; - break; - - case 'M': - c = v[0]; - v.remove_prefix(1); - switch(c) - { - case '-': - if(eq(v, "SEARCH")) - return verb::msearch; - break; - - case 'E': - if(eq(v, "RGE")) - return verb::merge; - break; - - case 'K': - if(eq(v, "ACTIVITY")) - return verb::mkactivity; - if(v[0] == 'C') - { - v.remove_prefix(1); - if(eq(v, "ALENDAR")) - return verb::mkcalendar; - if(eq(v, "OL")) - return verb::mkcol; - break; - } - break; - - case 'O': - if(eq(v, "VE")) - return verb::move; - BEAST_FALLTHROUGH; - - default: - break; - } - break; - - case 'N': - if(eq(v, "OTIFY")) - return verb::notify; - break; - - case 'O': - if(eq(v, "PTIONS")) - return verb::options; - break; - - case 'P': - c = v[0]; - v.remove_prefix(1); - switch(c) - { - case 'A': - if(eq(v, "TCH")) - return verb::patch; - break; - - case 'O': - if(eq(v, "ST")) - return verb::post; - break; - - case 'R': - if(eq(v, "OPFIND")) - return verb::propfind; - if(eq(v, "OPPATCH")) - return verb::proppatch; - break; - - case 'U': - if(eq(v, "RGE")) - return verb::purge; - if(eq(v, "T")) - return verb::put; - BEAST_FALLTHROUGH; - - default: - break; - } - break; - - case 'R': - if(v[0] != 'E') - break; - v.remove_prefix(1); - if(eq(v, "BIND")) - return verb::rebind; - if(eq(v, "PORT")) - return verb::report; - break; - - case 'S': - if(eq(v, "EARCH")) - return verb::search; - if(eq(v, "UBSCRIBE")) - return verb::subscribe; - break; - - case 'T': - if(eq(v, "RACE")) - return verb::trace; - break; - - case 'U': - if(v[0] != 'N') - break; - v.remove_prefix(1); - if(eq(v, "BIND")) - return verb::unbind; - if(eq(v, "LINK")) - return verb::unlink; - if(eq(v, "LOCK")) - return verb::unlock; - if(eq(v, "SUBSCRIBE")) - return verb::unsubscribe; - break; - - default: - break; - } - - return verb::unknown; -} - -} // detail - -inline -string_view -to_string(verb v) -{ - return detail::verb_to_string(v); -} - -inline -verb -string_to_verb(string_view s) -{ - return detail::string_to_verb(s); -} - -} // http -} // beast - -#endif diff --git a/src/beast/include/beast/http/impl/write.ipp b/src/beast/include/beast/http/impl/write.ipp deleted file mode 100644 index 1060a4f081c..00000000000 --- a/src/beast/include/beast/http/impl/write.ipp +++ /dev/null @@ -1,878 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_IMPL_WRITE_IPP -#define BEAST_HTTP_IMPL_WRITE_IPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace http { -namespace detail { - -template -class write_some_op -{ - Stream& s_; - serializer& sr_; - Handler h_; - - class lambda - { - write_some_op& op_; - - public: - bool invoked = false; - - explicit - lambda(write_some_op& op) - : op_(op) - { - } - - template - void - operator()(error_code& ec, - ConstBufferSequence const& buffers) - { - invoked = true; - ec.assign(0, ec.category()); - return op_.s_.async_write_some( - buffers, std::move(op_)); - } - }; - -public: - write_some_op(write_some_op&&) = default; - write_some_op(write_some_op const&) = default; - - template - write_some_op(DeducedHandler&& h, - Stream& s, serializer& sr) - : s_(s) - , sr_(sr) - , h_(std::forward(h)) - { - } - - void - operator()(); - - void - operator()(error_code ec, - std::size_t bytes_transferred); - - friend - void* asio_handler_allocate( - std::size_t size, write_some_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->h_)); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, write_some_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->h_)); - } - - friend - bool asio_handler_is_continuation(write_some_op* op) - { - using boost::asio::asio_handler_is_continuation; - return asio_handler_is_continuation( - std::addressof(op->h_)); - } - - template - friend - void asio_handler_invoke(Function&& f, write_some_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke(f, std::addressof(op->h_)); - } -}; - -template -void -write_some_op:: -operator()() -{ - error_code ec; - if(! sr_.is_done()) - { - lambda f{*this}; - sr_.next(ec, f); - if(ec) - { - BOOST_ASSERT(! f.invoked); - return s_.get_io_service().post( - bind_handler(std::move(*this), ec, 0)); - } - if(f.invoked) - { - // *this has been moved from, - // cannot access members here. - return; - } - // What else could it be? - BOOST_ASSERT(sr_.is_done()); - } - return s_.get_io_service().post( - bind_handler(std::move(*this), ec, 0)); -} - -template -void -write_some_op:: -operator()( - error_code ec, std::size_t bytes_transferred) -{ - if(! ec) - { - sr_.consume(bytes_transferred); - if(sr_.is_done()) - if(! sr_.keep_alive()) - ec = error::end_of_stream; - } - h_(ec); -} - -//------------------------------------------------------------------------------ - -struct serializer_is_header_done -{ - template - bool - operator()(serializer& sr) const - { - return sr.is_header_done(); - } -}; - -struct serializer_is_done -{ - template - bool - operator()(serializer& sr) const - { - return sr.is_done(); - } -}; - -//------------------------------------------------------------------------------ - -template< - class Stream, class Handler, class Predicate, - bool isRequest, class Body, - class Fields, class Decorator> -class write_op -{ - int state_ = 0; - Stream& s_; - serializer& sr_; - Handler h_; - -public: - write_op(write_op&&) = default; - write_op(write_op const&) = default; - - template - write_op(DeducedHandler&& h, Stream& s, - serializer& sr) - : s_(s) - , sr_(sr) - , h_(std::forward(h)) - { - } - - void - operator()(error_code ec); - - friend - void* asio_handler_allocate( - std::size_t size, write_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->h_)); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, write_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->h_)); - } - - friend - bool asio_handler_is_continuation(write_op* op) - { - using boost::asio::asio_handler_is_continuation; - return op->state_ >= 3 || - asio_handler_is_continuation( - std::addressof(op->h_)); - } - - template - friend - void asio_handler_invoke(Function&& f, write_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->h_)); - } -}; - -template< - class Stream, class Handler, class Predicate, - bool isRequest, class Body, - class Fields, class Decorator> -void -write_op:: -operator()(error_code ec) -{ - if(ec) - goto upcall; - switch(state_) - { - case 0: - { - if(Predicate{}(sr_)) - { - state_ = 1; - return s_.get_io_service().post( - bind_handler(std::move(*this), ec)); - } - state_ = 2; - return beast::http::async_write_some( - s_, sr_, std::move(*this)); - } - - case 1: - goto upcall; - - case 2: - state_ = 3; - BEAST_FALLTHROUGH; - - case 3: - { - if(Predicate{}(sr_)) - goto upcall; - return beast::http::async_write_some( - s_, sr_, std::move(*this)); - } - } -upcall: - h_(ec); -} - -//------------------------------------------------------------------------------ - -template -class write_msg_op -{ - struct data - { - Stream& s; - serializer sr; - - data(Handler&, Stream& s_, message< - isRequest, Body, Fields>& m_) - : s(s_) - , sr(m_, no_chunk_decorator{}) - { - } - }; - - handler_ptr d_; - -public: - write_msg_op(write_msg_op&&) = default; - write_msg_op(write_msg_op const&) = default; - - template - write_msg_op(DeducedHandler&& h, Stream& s, Args&&... args) - : d_(std::forward(h), - s, std::forward(args)...) - { - } - - void - operator()(); - - void - operator()(error_code ec); - - friend - void* asio_handler_allocate( - std::size_t size, write_msg_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->d_.handler())); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, write_msg_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->d_.handler())); - } - - friend - bool asio_handler_is_continuation(write_msg_op* op) - { - using boost::asio::asio_handler_is_continuation; - return asio_handler_is_continuation( - std::addressof(op->d_.handler())); - } - - template - friend - void asio_handler_invoke(Function&& f, write_msg_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->d_.handler())); - } -}; - -template -void -write_msg_op< - Stream, Handler, isRequest, Body, Fields>:: -operator()() -{ - auto& d = *d_; - return async_write(d.s, d.sr, std::move(*this)); -} - -template -void -write_msg_op< - Stream, Handler, isRequest, Body, Fields>:: -operator()(error_code ec) -{ - d_.invoke(ec); -} - -//------------------------------------------------------------------------------ - -template -class write_some_lambda -{ - Stream& stream_; - -public: - bool invoked = false; - std::size_t bytes_transferred = 0; - - explicit - write_some_lambda(Stream& stream) - : stream_(stream) - { - } - - template - void - operator()(error_code& ec, - ConstBufferSequence const& buffers) - { - invoked = true; - bytes_transferred = - stream_.write_some(buffers, ec); - } -}; - -template -class write_lambda -{ - Stream& stream_; - -public: - bool invoked = false; - std::size_t bytes_transferred = 0; - - explicit - write_lambda(Stream& stream) - : stream_(stream) - { - } - - template - void - operator()(error_code& ec, - ConstBufferSequence const& buffers) - { - invoked = true; - bytes_transferred = boost::asio::write( - stream_, buffers, ec); - } -}; - -} // detail - -//------------------------------------------------------------------------------ - -namespace detail { - -template< - class SyncWriteStream, - bool isRequest, class Body, class Fields, class Decorator> -void -write_some( - SyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator>& sr, - error_code& ec) -{ - if(! sr.is_done()) - { - write_some_lambda f{stream}; - sr.next(ec, f); - if(ec) - return; - if(f.invoked) - sr.consume(f.bytes_transferred); - if(sr.is_done()) - if(! sr.keep_alive()) - ec = error::end_of_stream; - return; - } - if(! sr.keep_alive()) - ec = error::end_of_stream; - else - ec.assign(0, ec.category()); -} - -template -async_return_type -async_write_some(AsyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator>& sr, - WriteHandler&& handler) -{ - async_completion init{handler}; - detail::write_some_op, - isRequest, Body, Fields, Decorator>{ - init.completion_handler, stream, sr}(); - return init.result.get(); -} - -} // detail - -template -void -write_some(SyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator>& sr) -{ - static_assert(is_sync_write_stream::value, - "SyncWriteStream requirements not met"); - static_assert(is_body::value, - "Body requirements not met"); - static_assert(is_body_reader::value, - "BodyReader requirements not met"); - error_code ec; - write_some(stream, sr, ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); -} - -template -void -write_some(SyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator>& sr, - error_code& ec) -{ - static_assert(is_sync_write_stream::value, - "SyncWriteStream requirements not met"); - static_assert(is_body::value, - "Body requirements not met"); - static_assert(is_body_reader::value, - "BodyReader requirements not met"); - detail::write_some(stream, sr, ec); -} - -template -async_return_type -async_write_some(AsyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator>& sr, - WriteHandler&& handler) -{ - static_assert(is_async_write_stream< - AsyncWriteStream>::value, - "AsyncWriteStream requirements not met"); - static_assert(is_body::value, - "Body requirements not met"); - static_assert(is_body_reader::value, - "BodyReader requirements not met"); - return detail::async_write_some(stream, sr, - std::forward(handler)); -} - -//------------------------------------------------------------------------------ - -template -void -write_header(SyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator>& sr) -{ - static_assert(is_sync_write_stream::value, - "SyncWriteStream requirements not met"); - static_assert(is_body::value, - "Body requirements not met"); - static_assert(is_body_reader::value, - "BodyReader requirements not met"); - error_code ec; - write_header(stream, sr, ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); -} - -template -void -write_header(SyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator>& sr, - error_code& ec) -{ - static_assert(is_sync_write_stream::value, - "SyncWriteStream requirements not met"); - static_assert(is_body::value, - "Body requirements not met"); - static_assert(is_body_reader::value, - "BodyReader requirements not met"); - sr.split(true); - if(! sr.is_header_done()) - { - detail::write_lambda f{stream}; - do - { - sr.next(ec, f); - if(ec) - return; - BOOST_ASSERT(f.invoked); - sr.consume(f.bytes_transferred); - } - while(! sr.is_header_done()); - } - else - { - ec.assign(0, ec.category()); - } -} - -template -async_return_type -async_write_header(AsyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator>& sr, - WriteHandler&& handler) -{ - static_assert(is_async_write_stream< - AsyncWriteStream>::value, - "AsyncWriteStream requirements not met"); - static_assert(is_body::value, - "Body requirements not met"); - static_assert(is_body_reader::value, - "BodyReader requirements not met"); - sr.split(true); - async_completion init{handler}; - detail::write_op, - detail::serializer_is_header_done, - isRequest, Body, Fields, Decorator>{ - init.completion_handler, stream, sr}( - error_code{}, 0); - return init.result.get(); -} - -//------------------------------------------------------------------------------ - -template< - class SyncWriteStream, - bool isRequest, class Body, - class Fields, class Decorator> -void -write( - SyncWriteStream& stream, - serializer& sr) -{ - static_assert(is_sync_write_stream::value, - "SyncWriteStream requirements not met"); - error_code ec; - write(stream, sr, ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); -} - -template< - class SyncWriteStream, - bool isRequest, class Body, - class Fields, class Decorator> -void -write( - SyncWriteStream& stream, - serializer& sr, - error_code& ec) -{ - static_assert(is_sync_write_stream::value, - "SyncWriteStream requirements not met"); - sr.split(false); - for(;;) - { - write_some(stream, sr, ec); - if(ec) - return; - if(sr.is_done()) - break; - } -} - -template -async_return_type -async_write(AsyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator>& sr, - WriteHandler&& handler) -{ - static_assert(is_async_write_stream< - AsyncWriteStream>::value, - "AsyncWriteStream requirements not met"); - static_assert(is_body::value, - "Body requirements not met"); - static_assert(is_body_reader::value, - "BodyReader requirements not met"); - sr.split(false); - async_completion init{handler}; - detail::write_op, - detail::serializer_is_done, - isRequest, Body, Fields, Decorator>{ - init.completion_handler, stream, sr}( - error_code{}); - return init.result.get(); -} - -//------------------------------------------------------------------------------ - -template -void -write(SyncWriteStream& stream, - message const& msg) -{ - static_assert(is_sync_write_stream::value, - "SyncWriteStream requirements not met"); - static_assert(is_body::value, - "Body requirements not met"); - static_assert(is_body_reader::value, - "BodyReader requirements not met"); - error_code ec; - write(stream, msg, ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); -} - -template -void -write(SyncWriteStream& stream, - message const& msg, - error_code& ec) -{ - static_assert(is_sync_write_stream::value, - "SyncWriteStream requirements not met"); - static_assert(is_body::value, - "Body requirements not met"); - static_assert(is_body_reader::value, - "BodyReader requirements not met"); - serializer sr{msg}; - write(stream, sr, ec); -} - -template -async_return_type< - WriteHandler, void(error_code)> -async_write(AsyncWriteStream& stream, - message& msg, - WriteHandler&& handler) -{ - static_assert( - is_async_write_stream::value, - "AsyncWriteStream requirements not met"); - static_assert(is_body::value, - "Body requirements not met"); - static_assert(is_body_reader::value, - "BodyReader requirements not met"); - async_completion init{handler}; - detail::write_msg_op, isRequest, - Body, Fields>{init.completion_handler, - stream, msg}(); - return init.result.get(); -} - -//------------------------------------------------------------------------------ - -namespace detail { - -template -class write_ostream_lambda -{ - std::ostream& os_; - Serializer& sr_; - -public: - write_ostream_lambda(std::ostream& os, - Serializer& sr) - : os_(os) - , sr_(sr) - { - } - - template - void - operator()(error_code& ec, - ConstBufferSequence const& buffers) const - { - ec.assign(0, ec.category()); - if(os_.fail()) - return; - std::size_t bytes_transferred = 0; - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - for(auto it = buffers.begin(); - it != buffers.end(); ++it) - { - boost::asio::const_buffer b = *it; - auto const n = buffer_size(b); - os_.write(buffer_cast(b), n); - if(os_.fail()) - return; - bytes_transferred += n; - } - sr_.consume(bytes_transferred); - } -}; - -} // detail - -template -std::ostream& -operator<<(std::ostream& os, - header const& h) -{ - typename Fields::reader fr{ - h, h.version, h.method()}; - return os << buffers(fr.get()); -} - -template -std::ostream& -operator<<(std::ostream& os, - header const& h) -{ - typename Fields::reader fr{ - h, h.version, h.result_int()}; - return os << buffers(fr.get()); -} - -template -std::ostream& -operator<<(std::ostream& os, - message const& msg) -{ - static_assert(is_body::value, - "Body requirements not met"); - static_assert(is_body_reader::value, - "BodyReader requirements not met"); - serializer sr{msg}; - error_code ec; - detail::write_ostream_lambda f{os, sr}; - do - { - sr.next(ec, f); - if(os.fail()) - break; - if(ec == error::end_of_stream) - ec.assign(0, ec.category()); - if(ec) - { - os.setstate(std::ios::failbit); - break; - } - } - while(! sr.is_done()); - return os; -} - -} // http -} // beast - -#endif diff --git a/src/beast/include/beast/http/message.hpp b/src/beast/include/beast/http/message.hpp deleted file mode 100644 index 4c3fd644828..00000000000 --- a/src/beast/include/beast/http/message.hpp +++ /dev/null @@ -1,841 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_MESSAGE_HPP -#define BEAST_HTTP_MESSAGE_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -/** A container for an HTTP request or response header. - - This container is derived from the `Fields` template type. - To understand all of the members of this class it is necessary - to view the declaration for the `Fields` type. When using - the default fields container, those declarations are in - @ref fields. - - Newly constructed header objects have version set to - HTTP/1.1. Newly constructed response objects also have - result code set to @ref status::ok. - - A `header` includes the start-line and header-fields. -*/ -#if BEAST_DOXYGEN -template -struct header : Fields - -#else -template -struct header; - -template -struct header : Fields -#endif -{ - static_assert(is_fields::value, - "Fields requirements not met"); - - /// Indicates if the header is a request or response. -#if BEAST_DOXYGEN - using is_request = std::integral_constant; -#else - using is_request = std::true_type; -#endif - - /// The type representing the fields. - using fields_type = Fields; - - /** The HTTP-version. - - This holds both the major and minor version numbers, - using these formulas: - @code - unsigned major = version / 10; - unsigned minor = version % 10; - @endcode - - Newly constructed headers will use HTTP/1.1 by default. - */ - unsigned version = 11; - - /// Default constructor - header() = default; - - /// Move constructor - header(header&&) = default; - - /// Copy constructor - header(header const&) = default; - - /// Move assignment - header& operator=(header&&) = default; - - /// Copy assignment - header& operator=(header const&) = default; - - /** Return the request-method verb. - - If the request-method is not one of the recognized verbs, - @ref verb::unknown is returned. Callers may use @ref method_string - to retrieve the exact text. - - @note This function is only available when `isRequest == true`. - - @see @ref method_string - */ - verb - method() const; - - /** Set the request-method. - - This function will set the method for requests to a known verb. - - @param v The request method verb to set. - This may not be @ref verb::unknown. - - @throws std::invalid_argument when `v == verb::unknown`. - - @note This function is only available when `isRequest == true`. - */ - void - method(verb v); - - /** Return the request-method as a string. - - @note This function is only available when `isRequest == true`. - - @see @ref method - */ - string_view - method_string() const; - - /** Set the request-method. - - This function will set the request-method a known verb - if the string matches, otherwise it will store a copy of - the passed string. - - @param s A string representing the request-method. - - @note This function is only available when `isRequest == true`. - */ - void - method_string(string_view s); - - /** Returns the request-target string. - - @note This function is only available when `isRequest == true`. - */ - string_view - target() const; - - /** Set the request-target string. - - @param s A string representing the request-target. - - @note This function is only available when `isRequest == true`. - */ - void - target(string_view s); - - // VFALCO Don't rearrange these declarations or - // ifdefs, or else the documentation will break. - - /** Constructor - - @param args Arguments forwarded to the `Fields` - base class constructor. - - @note This constructor participates in overload - resolution if and only if the first parameter is - not convertible to @ref header, @ref verb, or - @ref status. - */ -#if BEAST_DOXYGEN - template - explicit - header(Args&&... args); - -#else - template::type, header>::value && - ! std::is_convertible::type, verb>::value && - ! std::is_convertible::type, header>::value - >::type> - explicit - header(Arg1&& arg1, ArgN&&... argn); - -private: - template - friend struct message; - - template - friend - void - swap(header& m1, header& m2); - - template - header( - verb method, - string_view target_, - unsigned version_, - FieldsArgs&&... fields_args) - : Fields(std::forward(fields_args)...) - , version(version_) - , method_(method) - { - target(target_); - } - - verb method_ = verb::unknown; -}; - -/** A container for an HTTP request or response header. - - A `header` includes the start-line and header-fields. -*/ -template -struct header : Fields -{ - static_assert(is_fields::value, - "Fields requirements not met"); - - /// Indicates if the header is a request or response. - using is_request = std::false_type; - - /// The type representing the fields. - using fields_type = Fields; - - /** The HTTP version. - - This holds both the major and minor version numbers, - using these formulas: - @code - unsigned major = version / 10; - unsigned minor = version % 10; - @endcode - - Newly constructed headers will use HTTP/1.1 by default - unless otherwise specified. - */ - unsigned version = 11; - - /// Default constructor. - header() = default; - - /// Move constructor - header(header&&) = default; - - /// Copy constructor - header(header const&) = default; - - /// Move assignment - header& operator=(header&&) = default; - - /// Copy assignment - header& operator=(header const&) = default; - - /** Constructor - - @param args Arguments forwarded to the `Fields` - base class constructor. - - @note This constructor participates in overload - resolution if and only if the first parameter is - not convertible to @ref header, @ref verb, or - @ref status. - */ - template::type, status>::value && - ! std::is_convertible::type, header>::value - >::type> - explicit - header(Arg1&& arg1, ArgN&&... argn); -#endif - - /** The response status-code result. - - If the actual status code is not a known code, this - function returns @ref status::unknown. Use @ref result_int - to return the raw status code as a number. - - @note This member is only available when `isRequest == false`. - */ - status - result() const; - - /** Set the response status-code. - - @param v The code to set. - - @note This member is only available when `isRequest == false`. - */ - void - result(status v); - - /** Set the response status-code as an integer. - - This sets the status code to the exact number passed in. - If the number does not correspond to one of the known - status codes, the function @ref result will return - @ref status::unknown. Use @ref result_int to obtain the - original raw status-code. - - @param v The status-code integer to set. - - @throws std::invalid_argument if `v > 999`. - */ - void - result(unsigned v); - - /** The response status-code expressed as an integer. - - This returns the raw status code as an integer, even - when that code is not in the list of known status codes. - - @note This member is only available when `isRequest == false`. - */ - unsigned - result_int() const; - - /** Return the response reason-phrase. - - The reason-phrase is obsolete as of rfc7230. - - @note This function is only available when `isRequest == false`. - */ - string_view - reason() const; - - /** Set the response reason-phrase (deprecated) - - This function sets a custom reason-phrase to a copy of - the string passed in. Normally it is not necessary to set - the reason phrase on an outgoing response object; the - implementation will automatically use the standard reason - text for the corresponding status code. - - To clear a previously set custom phrase, pass an empty - string. This will restore the default standard reason text - based on the status code used when serializing. - - The reason-phrase is obsolete as of rfc7230. - - @param s The string to use for the reason-phrase. - - @note This function is only available when `isRequest == false`. - */ - void - reason(string_view s); - -private: -#if ! BEAST_DOXYGEN - template - friend struct message; - - template - friend - void - swap(header& m1, header& m2); - - template - header( - status result, - unsigned version_, - FieldsArgs&&... fields_args) - : Fields(std::forward(fields_args)...) - , version(version_) - , result_(result) - { - } - - status result_ = status::ok; -#endif -}; - -/// A typical HTTP request header -template -using request_header = header; - -/// A typical HTTP response header -template -using response_header = header; - -/** A container for a complete HTTP message. - - This container is derived from the `Fields` template type. - To understand all of the members of this class it is necessary - to view the declaration for the `Fields` type. When using - the default fields container, those declarations are in - @ref fields. - - A message can be a request or response, depending on the - `isRequest` template argument value. Requests and responses - have different types; functions may be overloaded based on - the type if desired. - - The `Body` template argument type determines the model used - to read or write the content body of the message. - - Newly constructed messages objects have version set to - HTTP/1.1. Newly constructed response objects also have - result code set to @ref status::ok. - - @tparam isRequest `true` if this represents a request, - or `false` if this represents a response. Some class data - members are conditionally present depending on this value. - - @tparam Body A type meeting the requirements of Body. - - @tparam Fields The type of container used to hold the - field value pairs. -*/ -template -struct message : header -{ - /// The base class used to hold the header portion of the message. - using header_type = header; - - /** The type providing the body traits. - - The @ref message::body member will be of type `body_type::value_type`. - */ - using body_type = Body; - - /// A value representing the body. - typename Body::value_type body; - - /// Constructor - message() = default; - - /// Constructor - message(message&&) = default; - - /// Constructor - message(message const&) = default; - - /// Assignment - message& operator=(message&&) = default; - - /// Assignment - message& operator=(message const&) = default; - - /** Constructor - - @param h The header to move construct from. - - @param body_args Optional arguments forwarded - to the `body` constructor. - */ - template - explicit - message(header_type&& h, BodyArgs&&... body_args); - - /** Constructor. - - @param h The header to copy construct from. - - @param body_args Optional arguments forwarded - to the `body` constructor. - */ - template - explicit - message(header_type const& h, BodyArgs&&... body_args); - - /** Constructor - - @param method The request-method to use - - @param target The request-target. - - @param version The HTTP-version - - @note This function is only available when `isRequest == true`. - */ -#if BEAST_DOXYGEN - message(verb method, string_view target, unsigned version); -#else - template::value>::type> - message(verb method, string_view target, Version version); -#endif - - /** Constructor - - @param method The request-method to use - - @param target The request-target. - - @param version The HTTP-version - - @param body_arg An argument forwarded to the `body` constructor. - - @note This function is only available when `isRequest == true`. - */ -#if BEAST_DOXYGEN - template - message(verb method, string_view target, - unsigned version, BodyArg&& body_arg); -#else - template::value>::type> - message(verb method, string_view target, - Version version, BodyArg&& body_arg); -#endif - - /** Constructor - - @param method The request-method to use - - @param target The request-target. - - @param version The HTTP-version - - @param body_arg An argument forwarded to the `body` constructor. - - @param fields_arg An argument forwarded to the `Fields` constructor. - - @note This function is only available when `isRequest == true`. - */ -#if BEAST_DOXYGEN - template - message(verb method, string_view target, unsigned version, - BodyArg&& body_arg, FieldsArg&& fields_arg); -#else - template::value>::type> - message(verb method, string_view target, Version version, - BodyArg&& body_arg, FieldsArg&& fields_arg); -#endif - - /** Constructor - - @param result The status-code for the response - - @param version The HTTP-version - - @note This member is only available when `isRequest == false`. - */ -#if BEAST_DOXYGEN - message(status result, unsigned version); -#else - template::value>::type> - message(status result, Version version); -#endif - - /** Constructor - - @param result The status-code for the response - - @param version The HTTP-version - - @param body_arg An argument forwarded to the `body` constructor. - - @note This member is only available when `isRequest == false`. - */ -#if BEAST_DOXYGEN - template - message(status result, unsigned version, BodyArg&& body_arg); -#else - template::value>::type> - message(status result, Version version, BodyArg&& body_arg); -#endif - - /** Constructor - - @param result The status-code for the response - - @param version The HTTP-version - - @param body_arg An argument forwarded to the `body` constructor. - - @param fields_arg An argument forwarded to the `Fields` base class constructor. - - @note This member is only available when `isRequest == false`. - */ -#if BEAST_DOXYGEN - template - message(status result, unsigned version, - BodyArg&& body_arg, FieldsArg&& fields_arg); -#else - template::value>::type> - message(status result, Version version, - BodyArg&& body_arg, FieldsArg&& fields_arg); -#endif - - /** Constructor - - The header and body are default-constructed. - */ - explicit - message(std::piecewise_construct_t); - - /** Construct a message. - - @param body_args A tuple forwarded as a parameter - pack to the body constructor. - */ - template - message(std::piecewise_construct_t, - std::tuple body_args); - - /** Construct a message. - - @param body_args A tuple forwarded as a parameter - pack to the body constructor. - - @param fields_args A tuple forwarded as a parameter - pack to the `Fields` constructor. - */ - template - message(std::piecewise_construct_t, - std::tuple body_args, - std::tuple fields_args); - - /// Returns the header portion of the message - header_type const& - base() const - { - return *this; - } - - /// Returns the header portion of the message - header_type& - base() - { - return *this; - } - - /// Returns `true` if the chunked Transfer-Encoding is specified - bool - chunked() const - { - return this->get_chunked_impl(); - } - - /** Set or clear the chunked Transfer-Encoding - - This function will set or removed the "chunked" transfer - encoding as the last item in the list of encodings in the - field. - - If the result of removing the chunked token results in an - empty string, the field is erased. - - The Content-Length field is erased unconditionally. - */ - void - chunked(bool value); - - /** Set or clear the Content-Length field - - This function adjusts the Content-Length field as follows: - - @li If `value` specifies a value, the Content-Length field - is set to the value. Otherwise - - @li The Content-Length field is erased. - - If "chunked" token appears as the last item in the - Transfer-Encoding field it is unconditionally removed. - - @param value The value to set for Content-Length. - */ - void - content_length(boost::optional const& value); - - /** Returns `true` if the message semantics indicate keep-alive - - The value depends on the version in the message, which must - be set to the final value before this function is called or - else the return value is unreliable. - */ - bool - keep_alive() const - { - return this->get_keep_alive_impl(this->version); - } - - /** Set the keep-alive message semantic option - - This function adjusts the Connection field to indicate - whether or not the connection should be kept open after - the corresponding response. The result depends on the - version set on the message, which must be set to the - final value before making this call. - - @param value `true` if the connection should persist. - */ - void - keep_alive(bool value) - { - this->set_keep_alive_impl(this->version, value); - } - - /** Returns the payload size of the body in octets if possible. - - This function invokes the @b Body algorithm to measure - the number of octets in the serialized body container. If - there is no body, this will return zero. Otherwise, if the - body exists but is not known ahead of time, `boost::none` - is returned (usually indicating that a chunked Transfer-Encoding - will be used). - - @note The value of the Content-Length field in the message - is not inspected. - */ - boost::optional - payload_size() const; - - /** Prepare the message payload fields for the body. - - This function will adjust the Content-Length and - Transfer-Encoding field values based on the properties - of the body. - - @par Example - @code - request req{verb::post, "/"}; - req.set(field::user_agent, "Beast"); - req.body = "Hello, world!"; - req.prepare_payload(); - @endcode - */ - void - prepare_payload() - { - prepare_payload(typename header_type::is_request{}); - } - -private: - static_assert(is_body::value, - "Body requirements not met"); - - template< - class... BodyArgs, - std::size_t... IBodyArgs> - message( - std::piecewise_construct_t, - std::tuple& body_args, - beast::detail::index_sequence) - : body(std::forward( - std::get(body_args))...) - { - boost::ignore_unused(body_args); - } - - template< - class... BodyArgs, - class... FieldsArgs, - std::size_t... IBodyArgs, - std::size_t... IFieldsArgs> - message( - std::piecewise_construct_t, - std::tuple& body_args, - std::tuple& fields_args, - beast::detail::index_sequence, - beast::detail::index_sequence) - : header_type(std::forward( - std::get(fields_args))...) - , body(std::forward( - std::get(body_args))...) - { - boost::ignore_unused(body_args); - boost::ignore_unused(fields_args); - } - - boost::optional - payload_size(std::true_type) const - { - return Body::size(body); - } - - boost::optional - payload_size(std::false_type) const - { - return boost::none; - } - - void - prepare_payload(std::true_type); - - void - prepare_payload(std::false_type); -}; - -/// A typical HTTP request -template -using request = message; - -/// A typical HTTP response -template -using response = message; - -//------------------------------------------------------------------------------ - -#if BEAST_DOXYGEN -/** Swap two header objects. - - @par Requirements - `Fields` is @b Swappable. -*/ -template -void -swap( - header& m1, - header& m2); -#endif - -/** Swap two message objects. - - @par Requirements: - `Body::value_type` and `Fields` are @b Swappable. -*/ -template -void -swap( - message& m1, - message& m2); - -} // http -} // beast - -#include - -#endif diff --git a/src/beast/include/beast/http/parser.hpp b/src/beast/include/beast/http/parser.hpp deleted file mode 100644 index 108223ef3c1..00000000000 --- a/src/beast/include/beast/http/parser.hpp +++ /dev/null @@ -1,322 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_PARSER_HPP -#define BEAST_HTTP_PARSER_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -/** An HTTP/1 parser for producing a message. - - This class uses the basic HTTP/1 wire format parser to convert - a series of octets into a @ref message using the @ref basic_fields - container to represent the fields. - - @tparam isRequest Indicates whether a request or response - will be parsed. - - @tparam Body The type used to represent the body. This must - meet the requirements of @b Body. - - @tparam Allocator The type of allocator used with the - @ref basic_fields container. - - @note A new instance of the parser is required for each message. -*/ -template< - bool isRequest, - class Body, - class Allocator = std::allocator> -class parser - : public basic_parser> -{ - static_assert(is_body::value, - "Body requirements not met"); - - static_assert(is_body_writer::value, - "BodyWriter requirements not met"); - - template - friend class parser; - - using base_type = basic_parser>; - - message> m_; - typename Body::writer wr_; - std::function cb_; - bool wr_inited_ = false; - -public: - /// The type of message returned by the parser - using value_type = - message>; - - /// Constructor - parser(); - - /// Copy constructor (disallowed) - parser(parser const&) = delete; - - /// Copy assignment (disallowed) - parser& operator=(parser const&) = delete; - - /** Move constructor. - - After the move, the only valid operation - on the moved-from object is destruction. - */ - parser(parser&& other) = default; - - /** Constructor - - @param args Optional arguments forwarded to the - @ref http::header constructor. - - @note This function participates in overload - resolution only if the first argument is not a - @ref parser. - */ -#if BEAST_DOXYGEN - template - explicit - parser(Args&&... args); -#else - template::type>::value>::type> - explicit - parser(Arg1&& arg1, ArgN&&... argn); -#endif - - /** Construct a parser from another parser, changing the Body type. - - This constructs a new parser by move constructing the - header from another parser with a different body type. The - constructed-from parser must not have any parsed body octets or - initialized @b BodyWriter, otherwise an exception is generated. - - @par Example - @code - // Deferred body type commitment - request_parser req0; - ... - request_parser req{std::move(req0)}; - @endcode - - If an exception is thrown, the state of the constructed-from - parser is undefined. - - @param parser The other parser to construct from. After - this call returns, the constructed-from parser may only - be destroyed. - - @param args Optional arguments forwarded to the message - constructor. - - @throws std::invalid_argument Thrown when the constructed-from - parser has already initialized a body writer. - - @note This function participates in overload resolution only - if the other parser uses a different body type. - */ -#if BEAST_DOXYGEN - template -#else - template::value>::type> -#endif - explicit - parser(parser&& parser, Args&&... args); - - /** Returns the parsed message. - - Depending on the parser's progress, - parts of this object may be incomplete. - */ - value_type const& - get() const - { - return m_; - } - - /** Returns the parsed message. - - Depending on the parser's progress, - parts of this object may be incomplete. - */ - value_type& - get() - { - return m_; - } - - /** Returns ownership of the parsed message. - - Ownership is transferred to the caller. - Depending on the parser's progress, - parts of this object may be incomplete. - - @par Requires - - @ref value_type is @b MoveConstructible - */ - value_type - release() - { - static_assert(std::is_move_constructible::value, - "MoveConstructible requirements not met"); - return std::move(m_); - } - - /** Set the on_header callback. - - When the callback is set, it is called after the parser - receives a complete header. The function must be invocable with - this signature: - @code - void callback( - parser& p, // `*this` - error_code& ec) // Set to the error, if any - @endcode - The callback will ensure that `!ec` is `true` if there was - no error or set to the appropriate error code if there was one. - - The callback may not call @ref put or @ref put_eof, or - else the behavior is undefined. - */ - void - on_header(std::function cb) - { - cb_ = std::move(cb); - } - -private: - friend class basic_parser; - - void - on_request(verb method, string_view method_str, - string_view target, int version, error_code& ec) - { - try - { - m_.target(target); - if(method != verb::unknown) - m_.method(method); - else - m_.method_string(method_str); - ec.assign(0, ec.category()); - } - catch(std::bad_alloc const&) - { - ec = error::bad_alloc; - } - m_.version = version; - } - - void - on_response(int code, - string_view reason, - int version, error_code& ec) - { - m_.result(code); - m_.version = version; - try - { - m_.reason(reason); - ec.assign(0, ec.category()); - } - catch(std::bad_alloc const&) - { - ec = error::bad_alloc; - } - } - - void - on_field(field name, string_view name_string, - string_view value, error_code& ec) - { - try - { - m_.insert(name, name_string, value); - ec.assign(0, ec.category()); - } - catch(std::bad_alloc const&) - { - ec = error::bad_alloc; - } - } - - void - on_header(error_code& ec) - { - if(cb_) - cb_(*this, ec); - else - ec.assign(0, ec.category()); - } - - void - on_body(boost::optional< - std::uint64_t> const& content_length, - error_code& ec) - { - wr_.init(content_length, ec); - wr_inited_ = true; - } - - std::size_t - on_data(string_view s, error_code& ec) - { - return wr_.put(boost::asio::buffer( - s.data(), s.size()), ec); - } - - void - on_chunk(std::uint64_t, - string_view, error_code& ec) - { - ec.assign(0, ec.category()); - } - - void - on_complete(error_code& ec) - { - wr_.finish(ec); - } -}; - -/// An HTTP/1 parser for producing a request message. -template> -using request_parser = parser; - -/// An HTTP/1 parser for producing a response message. -template> -using response_parser = parser; - -} // http -} // beast - -#include - -#endif diff --git a/src/beast/include/beast/http/read.hpp b/src/beast/include/beast/http/read.hpp deleted file mode 100644 index 72fea92ff77..00000000000 --- a/src/beast/include/beast/http/read.hpp +++ /dev/null @@ -1,757 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_READ_HPP -#define BEAST_HTTP_READ_HPP - -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -/** Read part of a message from a stream using a parser. - - This function is used to read part of a message from a stream into a - subclass of @ref basic_parser. - The call will block until one of the following conditions is true: - - @li A call to @ref basic_parser::put with a non-empty buffer sequence - is successful. - - @li An error occurs. - - This operation is implemented in terms of one or - more calls to the stream's `read_some` function. - The implementation may read additional octets that lie past the - end of the message being read. This additional data is stored - in the dynamic buffer, which must be retained for subsequent reads. - - If the stream returns the error `boost::asio::error::eof` indicating the - end of file during a read, the error returned from this function will be: - - @li @ref error::end_of_stream if no octets were parsed, or - - @li @ref error::partial_message if any octets were parsed but the - message was incomplete, otherwise: - - @li A successful result. A subsequent attempt to read will - return @ref error::end_of_stream - - @param stream The stream from which the data is to be read. - The type must support the @b SyncReadStream concept. - - @param buffer A @b DynamicBuffer holding additional bytes - read by the implementation from the stream. This is both - an input and an output parameter; on entry, any data in the - dynamic buffer's input sequence will be given to the parser - first. - - @param parser The parser to use. - - @throws system_error Thrown on failure. -*/ -template< - class SyncReadStream, - class DynamicBuffer, - bool isRequest, class Derived> -void -read_some( - SyncReadStream& stream, - DynamicBuffer& buffer, - basic_parser& parser); - -/** Read part of a message from a stream using a parser. - - This function is used to read part of a message from a stream into a - subclass of @ref basic_parser. - The call will block until one of the following conditions is true: - - @li A call to @ref basic_parser::put with a non-empty buffer sequence - is successful. - - @li An error occurs. - - This operation is implemented in terms of one or - more calls to the stream's `read_some` function. - The implementation may read additional octets that lie past the - end of the message being read. This additional data is stored - in the dynamic buffer, which must be retained for subsequent reads. - - If the stream returns the error `boost::asio::error::eof` indicating the - end of file during a read, the error returned from this function will be: - - @li @ref error::end_of_stream if no octets were parsed, or - - @li @ref error::partial_message if any octets were parsed but the - message was incomplete, otherwise: - - @li A successful result. A subsequent attempt to read will - return @ref error::end_of_stream - - The function returns the number of bytes processed from the dynamic - buffer. The caller should remove these bytes by calling `consume` on - the dynamic buffer, regardless of any error. - - @param stream The stream from which the data is to be read. - The type must support the @b SyncReadStream concept. - - @param buffer A @b DynamicBuffer holding additional bytes - read by the implementation from the stream. This is both - an input and an output parameter; on entry, any data in the - dynamic buffer's input sequence will be given to the parser - first. - - @param parser The parser to use. - - @param ec Set to the error, if any occurred. -*/ -template< - class SyncReadStream, - class DynamicBuffer, - bool isRequest, class Derived> -void -read_some( - SyncReadStream& stream, - DynamicBuffer& buffer, - basic_parser& parser, - error_code& ec); - -/** Read part of a message asynchronously from a stream using a parser. - - This function is used to asynchronously read part of a message from - a stream into a subclass of @ref basic_parser. - The function call always returns immediately. The asynchronous operation - will continue until one of the following conditions is true: - - @li A call to @ref basic_parser::put with a non-empty buffer sequence - is successful. - - @li An error occurs. - - This operation is implemented in terms of zero or more calls to - the next layer's `async_read_some` function, and is known as a - composed operation. The program must ensure that the - stream performs no other operations until this operation completes. - The implementation may read additional octets that lie past the - end of the object being parsed. This additional data is stored - in the stream buffer, which may be used in subsequent calls. - - If the stream returns the error `boost::asio::error::eof` indicating the - end of file during a read, the error returned from this function will be: - - @li @ref error::end_of_stream if no octets were parsed, or - - @li @ref error::partial_message if any octets were parsed but the - message was incomplete, otherwise: - - @li A successful result. A subsequent attempt to read will - return @ref error::end_of_stream - - @param stream The stream from which the data is to be read. - The type must support the @b AsyncReadStream concept. - - @param buffer A @b DynamicBuffer holding additional bytes - read by the implementation from the stream. This is both - an input and an output parameter; on entry, any data in the - dynamic buffer's input sequence will be given to the parser - first. - - @param parser The parser to use. - The object must remain valid at least until the - handler is called; ownership is not transferred. - - @param handler The handler to be called when the request - completes. Copies will be made of the handler as required. - The equivalent function signature of the handler must be: - @code void handler( - error_code const& error // result of operation - ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. - - The completion handler will receive as a parameter the number - of octets processed from the dynamic buffer. The octets should - be removed by calling `consume` on the dynamic buffer after - the read completes, regardless of any error. -*/ -template< - class AsyncReadStream, - class DynamicBuffer, - bool isRequest, class Derived, - class ReadHandler> -#if BEAST_DOXYGEN - void_or_deduced -#else -async_return_type< - ReadHandler, void(error_code)> -#endif -async_read_some( - AsyncReadStream& stream, - DynamicBuffer& buffer, - basic_parser& parser, - ReadHandler&& handler); - -//------------------------------------------------------------------------------ - -/** Read a header from a stream using a parser. - - This function is used to read a header from a stream into a subclass - of @ref basic_parser. - The call will block until one of the following conditions is true: - - @li @ref basic_parser::is_header_done returns `true` - - @li An error occurs. - - This operation is implemented in terms of one or - more calls to the stream's `read_some` function. - The implementation may read additional octets that lie past the - end of the message being read. This additional data is stored - in the dynamic buffer, which must be retained for subsequent reads. - - If the stream returns the error `boost::asio::error::eof` indicating the - end of file during a read, the error returned from this function will be: - - @li @ref error::end_of_stream if no octets were parsed, or - - @li @ref error::partial_message if any octets were parsed but the - message was incomplete, otherwise: - - @li A successful result. A subsequent attempt to read will - return @ref error::end_of_stream - - @param stream The stream from which the data is to be read. - The type must support the @b SyncReadStream concept. - - @param buffer A @b DynamicBuffer holding additional bytes - read by the implementation from the stream. This is both - an input and an output parameter; on entry, any data in the - dynamic buffer's input sequence will be given to the parser - first. - - @param parser The parser to use. - - @throws system_error Thrown on failure. - - @note The implementation will call @ref basic_parser::eager - with the value `false` on the parser passed in. -*/ -template< - class SyncReadStream, - class DynamicBuffer, - bool isRequest, class Derived> -void -read_header( - SyncReadStream& stream, - DynamicBuffer& buffer, - basic_parser& parser); - -/** Read a header from a stream using a parser. - - This function is used to read a header from a stream into a subclass - of @ref basic_parser. - The call will block until one of the following conditions is true: - - @li @ref basic_parser::is_header_done returns `true` - - @li An error occurs. - - This operation is implemented in terms of one or - more calls to the stream's `read_some` function. - The implementation may read additional octets that lie past the - end of the message being read. This additional data is stored - in the dynamic buffer, which must be retained for subsequent reads. - - If the stream returns the error `boost::asio::error::eof` indicating the - end of file during a read, the error returned from this function will be: - - @li @ref error::end_of_stream if no octets were parsed, or - - @li @ref error::partial_message if any octets were parsed but the - message was incomplete, otherwise: - - @li A successful result. A subsequent attempt to read will - return @ref error::end_of_stream - - @param stream The stream from which the data is to be read. - The type must support the @b SyncReadStream concept. - - @param buffer A @b DynamicBuffer holding additional bytes - read by the implementation from the stream. This is both - an input and an output parameter; on entry, any data in the - dynamic buffer's input sequence will be given to the parser - first. - - @param parser The parser to use. - - @param ec Set to the error, if any occurred. - - @note The implementation will call @ref basic_parser::eager - with the value `false` on the parser passed in. -*/ -template< - class SyncReadStream, - class DynamicBuffer, - bool isRequest, class Derived> -void -read_header( - SyncReadStream& stream, - DynamicBuffer& buffer, - basic_parser& parser, - error_code& ec); - -/** Read a header from a stream asynchronously using a parser. - - This function is used to asynchronously read a header from a stream - into a subclass of @ref basic_parser. - The function call always returns immediately. The asynchronous operation - will continue until one of the following conditions is true: - - @li @ref basic_parser::is_header_done returns `true` - - @li An error occurs. - - This operation is implemented in terms of one or more calls to - the stream's `async_read_some` function, and is known as a - composed operation. The program must ensure that the - stream performs no other operations until this operation completes. - The implementation may read additional octets that lie past the - end of the message being read. This additional data is stored - in the dynamic buffer, which must be retained for subsequent reads. - - If the stream returns the error `boost::asio::error::eof` indicating the - end of file during a read, the error returned from this function will be: - - @li @ref error::end_of_stream if no octets were parsed, or - - @li @ref error::partial_message if any octets were parsed but the - message was incomplete, otherwise: - - @li A successful result. A subsequent attempt to read will - return @ref error::end_of_stream - - @param stream The stream from which the data is to be read. - The type must support the @b AsyncReadStream concept. - - @param buffer A @b DynamicBuffer holding additional bytes - read by the implementation from the stream. This is both - an input and an output parameter; on entry, any data in the - dynamic buffer's input sequence will be given to the parser - first. - - @param parser The parser to use. - The object must remain valid at least until the - handler is called; ownership is not transferred. - - @param handler The handler to be called when the request - completes. Copies will be made of the handler as required. - The equivalent function signature of the handler must be: - @code void handler( - error_code const& error // result of operation - ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. - - @note The implementation will call @ref basic_parser::eager - with the value `false` on the parser passed in. -*/ -template< - class AsyncReadStream, - class DynamicBuffer, - bool isRequest, class Derived, - class ReadHandler> -#if BEAST_DOXYGEN - void_or_deduced -#else -async_return_type< - ReadHandler, void(error_code)> -#endif -async_read_header( - AsyncReadStream& stream, - DynamicBuffer& buffer, - basic_parser& parser, - ReadHandler&& handler); - -//------------------------------------------------------------------------------ - -/** Read a complete message from a stream using a parser. - - This function is used to read a complete message from a stream into a - subclass of @ref basic_parser. - The call will block until one of the following conditions is true: - - @li @ref basic_parser::is_done returns `true` - - @li An error occurs. - - This operation is implemented in terms of one or - more calls to the stream's `read_some` function. - The implementation may read additional octets that lie past the - end of the message being read. This additional data is stored - in the dynamic buffer, which must be retained for subsequent reads. - - If the stream returns the error `boost::asio::error::eof` indicating the - end of file during a read, the error returned from this function will be: - - @li @ref error::end_of_stream if no octets were parsed, or - - @li @ref error::partial_message if any octets were parsed but the - message was incomplete, otherwise: - - @li A successful result. A subsequent attempt to read will - return @ref error::end_of_stream - - @param stream The stream from which the data is to be read. - The type must support the @b SyncReadStream concept. - - @param buffer A @b DynamicBuffer holding additional bytes - read by the implementation from the stream. This is both - an input and an output parameter; on entry, any data in the - dynamic buffer's input sequence will be given to the parser - first. - - @param parser The parser to use. - - @throws system_error Thrown on failure. - - @note The implementation will call @ref basic_parser::eager - with the value `true` on the parser passed in. -*/ -template< - class SyncReadStream, - class DynamicBuffer, - bool isRequest, class Derived> -void -read( - SyncReadStream& stream, - DynamicBuffer& buffer, - basic_parser& parser); - -/** Read a complete message from a stream using a parser. - - This function is used to read a complete message from a stream into a - subclass of @ref basic_parser. - The call will block until one of the following conditions is true: - - @li @ref basic_parser::is_done returns `true` - - @li An error occurs. - - This operation is implemented in terms of one or - more calls to the stream's `read_some` function. - The implementation may read additional octets that lie past the - end of the message being read. This additional data is stored - in the dynamic buffer, which must be retained for subsequent reads. - - If the stream returns the error `boost::asio::error::eof` indicating the - end of file during a read, the error returned from this function will be: - - @li @ref error::end_of_stream if no octets were parsed, or - - @li @ref error::partial_message if any octets were parsed but the - message was incomplete, otherwise: - - @li A successful result. A subsequent attempt to read will - return @ref error::end_of_stream - - @param stream The stream from which the data is to be read. - The type must support the @b SyncReadStream concept. - - @param buffer A @b DynamicBuffer holding additional bytes - read by the implementation from the stream. This is both - an input and an output parameter; on entry, any data in the - dynamic buffer's input sequence will be given to the parser - first. - - @param parser The parser to use. - - @param ec Set to the error, if any occurred. - - @note The implementation will call @ref basic_parser::eager - with the value `true` on the parser passed in. -*/ -template< - class SyncReadStream, - class DynamicBuffer, - bool isRequest, class Derived> -void -read( - SyncReadStream& stream, - DynamicBuffer& buffer, - basic_parser& parser, - error_code& ec); - -/** Read a complete message from a stream asynchronously using a parser. - - This function is used to asynchronously read a complete message from a - stream into a subclass of @ref basic_parser. - The function call always returns immediately. The asynchronous operation - will continue until one of the following conditions is true: - - @li @ref basic_parser::is_done returns `true` - - @li An error occurs. - - This operation is implemented in terms of one or more calls to - the stream's `async_read_some` function, and is known as a - composed operation. The program must ensure that the - stream performs no other operations until this operation completes. - The implementation may read additional octets that lie past the - end of the message being read. This additional data is stored - in the dynamic buffer, which must be retained for subsequent reads. - - If the stream returns the error `boost::asio::error::eof` indicating the - end of file during a read, the error returned from this function will be: - - @li @ref error::end_of_stream if no octets were parsed, or - - @li @ref error::partial_message if any octets were parsed but the - message was incomplete, otherwise: - - @li A successful result. A subsequent attempt to read will - return @ref error::end_of_stream - - @param stream The stream from which the data is to be read. - The type must support the @b AsyncReadStream concept. - - @param buffer A @b DynamicBuffer holding additional bytes - read by the implementation from the stream. This is both - an input and an output parameter; on entry, any data in the - dynamic buffer's input sequence will be given to the parser - first. - - @param parser The parser to use. - The object must remain valid at least until the - handler is called; ownership is not transferred. - - @param handler The handler to be called when the request - completes. Copies will be made of the handler as required. - The equivalent function signature of the handler must be: - @code void handler( - error_code const& error // result of operation - ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. - - @note The implementation will call @ref basic_parser::eager - with the value `true` on the parser passed in. -*/ -template< - class AsyncReadStream, - class DynamicBuffer, - bool isRequest, class Derived, - class ReadHandler> -#if BEAST_DOXYGEN - void_or_deduced -#else -async_return_type< - ReadHandler, void(error_code)> -#endif -async_read( - AsyncReadStream& stream, - DynamicBuffer& buffer, - basic_parser& parser, - ReadHandler&& handler); - -//------------------------------------------------------------------------------ - -/** Read a complete message from a stream. - - This function is used to read a complete message from a stream using HTTP/1. - The call will block until one of the following conditions is true: - - @li The entire message is read. - - @li An error occurs. - - This operation is implemented in terms of one or - more calls to the stream's `read_some` function. - The implementation may read additional octets that lie past the - end of the message being read. This additional data is stored - in the dynamic buffer, which must be retained for subsequent reads. - - If the stream returns the error `boost::asio::error::eof` indicating the - end of file during a read, the error returned from this function will be: - - @li @ref error::end_of_stream if no octets were parsed, or - - @li @ref error::partial_message if any octets were parsed but the - message was incomplete, otherwise: - - @li A successful result. A subsequent attempt to read will - return @ref error::end_of_stream - - @param stream The stream from which the data is to be read. - The type must support the @b SyncReadStream concept. - - @param buffer A @b DynamicBuffer holding additional bytes - read by the implementation from the stream. This is both - an input and an output parameter; on entry, any data in the - dynamic buffer's input sequence will be given to the parser - first. - - @param msg An object in which to store the message contents. - This object should not have previous contents, otherwise - the behavior is undefined. - The type must be @b MoveAssignable and @b MoveConstructible. - - @throws system_error Thrown on failure. -*/ -template< - class SyncReadStream, - class DynamicBuffer, - bool isRequest, class Body, class Allocator> -void -read( - SyncReadStream& stream, - DynamicBuffer& buffer, - message>& msg); - -/** Read a complete message from a stream. - - This function is used to read a complete message from a stream using HTTP/1. - The call will block until one of the following conditions is true: - - @li The entire message is read. - - @li An error occurs. - - This operation is implemented in terms of one or - more calls to the stream's `read_some` function. - The implementation may read additional octets that lie past the - end of the message being read. This additional data is stored - in the dynamic buffer, which must be retained for subsequent reads. - - If the stream returns the error `boost::asio::error::eof` indicating the - end of file during a read, the error returned from this function will be: - - @li @ref error::end_of_stream if no octets were parsed, or - - @li @ref error::partial_message if any octets were parsed but the - message was incomplete, otherwise: - - @li A successful result. A subsequent attempt to read will - return @ref error::end_of_stream - - @param stream The stream from which the data is to be read. - The type must support the @b SyncReadStream concept. - - @param buffer A @b DynamicBuffer holding additional bytes - read by the implementation from the stream. This is both - an input and an output parameter; on entry, any data in the - dynamic buffer's input sequence will be given to the parser - first. - - @param msg An object in which to store the message contents. - This object should not have previous contents, otherwise - the behavior is undefined. - The type must be @b MoveAssignable and @b MoveConstructible. - - @param ec Set to the error, if any occurred. -*/ -template< - class SyncReadStream, - class DynamicBuffer, - bool isRequest, class Body, class Allocator> -void -read( - SyncReadStream& stream, - DynamicBuffer& buffer, - message>& msg, - error_code& ec); - -/** Read a complete message from a stream asynchronously. - - This function is used to asynchronously read a complete message from a - stream using HTTP/1. - The function call always returns immediately. The asynchronous operation - will continue until one of the following conditions is true: - - @li The entire message is read. - - @li An error occurs. - - This operation is implemented in terms of one or more calls to - the stream's `async_read_some` function, and is known as a - composed operation. The program must ensure that the - stream performs no other operations until this operation completes. - The implementation may read additional octets that lie past the - end of the message being read. This additional data is stored - in the dynamic buffer, which must be retained for subsequent reads. - - If the stream returns the error `boost::asio::error::eof` indicating the - end of file during a read, the error returned from this function will be: - - @li @ref error::end_of_stream if no octets were parsed, or - - @li @ref error::partial_message if any octets were parsed but the - message was incomplete, otherwise: - - @li A successful result. A subsequent attempt to read will - return @ref error::end_of_stream - - @param stream The stream from which the data is to be read. - The type must support the @b AsyncReadStream concept. - - @param buffer A @b DynamicBuffer holding additional bytes - read by the implementation from the stream. This is both - an input and an output parameter; on entry, any data in the - dynamic buffer's input sequence will be given to the parser - first. - - @param msg An object in which to store the message contents. - This object should not have previous contents, otherwise - the behavior is undefined. - The type must be @b MoveAssignable and @b MoveConstructible. - - The object must remain valid at least until the - handler is called; ownership is not transferred. - - @param handler The handler to be called when the operation - completes. Copies will be made of the handler as required. - The equivalent function signature of the handler must be: - @code void handler( - error_code const& error // result of operation - ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. -*/ -template< - class AsyncReadStream, - class DynamicBuffer, - bool isRequest, class Body, class Allocator, - class ReadHandler> -#if BEAST_DOXYGEN - void_or_deduced -#else -async_return_type< - ReadHandler, void(error_code)> -#endif -async_read( - AsyncReadStream& stream, - DynamicBuffer& buffer, - message>& msg, - ReadHandler&& handler); - -} // http -} // beast - -#include - -#endif diff --git a/src/beast/include/beast/http/rfc7230.hpp b/src/beast/include/beast/http/rfc7230.hpp deleted file mode 100644 index e2d3f3fb294..00000000000 --- a/src/beast/include/beast/http/rfc7230.hpp +++ /dev/null @@ -1,325 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_RFC7230_HPP -#define BEAST_HTTP_RFC7230_HPP - -#include -#include -#include - -namespace beast { -namespace http { - -/** A list of parameters in an HTTP extension field value. - - This container allows iteration of the parameter list in an HTTP - extension. The parameter list is a series of name/value pairs - with each pair starting with a semicolon. The value is optional. - - If a parsing error is encountered while iterating the string, - the behavior of the container will be as if a string containing - only characters up to but excluding the first invalid character - was used to construct the list. - - @par BNF - @code - param-list = *( OWS ";" OWS param ) - param = token OWS [ "=" OWS ( token / quoted-string ) ] - @endcode - - To use this class, construct with the string to be parsed and - then use @ref begin and @ref end, or range-for to iterate each - item: - - @par Example - @code - for(auto const& param : param_list{";level=9;no_context_takeover;bits=15"}) - { - std::cout << ";" << param.first; - if(! param.second.empty()) - std::cout << "=" << param.second; - std::cout << "\n"; - } - @endcode -*/ -class param_list -{ - string_view s_; - -public: - /** The type of each element in the list. - - The first string in the pair is the name of the parameter, - and the second string in the pair is its value (which may - be empty). - */ - using value_type = - std::pair; - - /// A constant iterator to the list -#if BEAST_DOXYGEN - using const_iterator = implementation_defined; -#else - class const_iterator; -#endif - - /// Default constructor. - param_list() = default; - - /** Construct a list. - - @param s A string containing the list contents. The string - must remain valid for the lifetime of the container. - */ - explicit - param_list(string_view s) - : s_(s) - { - } - - /// Return a const iterator to the beginning of the list - const_iterator begin() const; - - /// Return a const iterator to the end of the list - const_iterator end() const; - - /// Return a const iterator to the beginning of the list - const_iterator cbegin() const; - - /// Return a const iterator to the end of the list - const_iterator cend() const; -}; - -//------------------------------------------------------------------------------ - -/** A list of extensions in a comma separated HTTP field value. - - This container allows iteration of the extensions in an HTTP - field value. The extension list is a comma separated list of - token parameter list pairs. - - If a parsing error is encountered while iterating the string, - the behavior of the container will be as if a string containing - only characters up to but excluding the first invalid character - was used to construct the list. - - @par BNF - @code - ext-list = *( "," OWS ) ext *( OWS "," [ OWS ext ] ) - ext = token param-list - param-list = *( OWS ";" OWS param ) - param = token OWS [ "=" OWS ( token / quoted-string ) ] - @endcode - - To use this class, construct with the string to be parsed and - then use @ref begin and @ref end, or range-for to iterate each - item: - - @par Example - @code - for(auto const& ext : ext_list{"none, 7z;level=9, zip;no_context_takeover;bits=15"}) - { - std::cout << ext.first << "\n"; - for(auto const& param : ext.second) - { - std::cout << ";" << param.first; - if(! param.second.empty()) - std::cout << "=" << param.second; - std::cout << "\n"; - } - } - @endcode -*/ -class ext_list -{ - using iter_type = string_view::const_iterator; - - string_view s_; - -public: - /** The type of each element in the list. - - The first element of the pair is the extension token, and the - second element of the pair is an iterable container holding the - extension's name/value parameters. - */ - using value_type = std::pair; - - /// A constant iterator to the list -#if BEAST_DOXYGEN - using const_iterator = implementation_defined; -#else - class const_iterator; -#endif - - /** Construct a list. - - @param s A string containing the list contents. The string - must remain valid for the lifetime of the container. - */ - explicit - ext_list(string_view s) - : s_(s) - { - } - - /// Return a const iterator to the beginning of the list - const_iterator begin() const; - - /// Return a const iterator to the end of the list - const_iterator end() const; - - /// Return a const iterator to the beginning of the list - const_iterator cbegin() const; - - /// Return a const iterator to the end of the list - const_iterator cend() const; - - /** Find a token in the list. - - @param s The token to find. A case-insensitive comparison is used. - - @return An iterator to the matching token, or `end()` if no - token exists. - */ - template - const_iterator - find(T const& s); - - /** Return `true` if a token is present in the list. - - @param s The token to find. A case-insensitive comparison is used. - */ - template - bool - exists(T const& s); -}; - -//------------------------------------------------------------------------------ - -/** A list of tokens in a comma separated HTTP field value. - - This container allows iteration of a list of items in a - header field value. The input is a comma separated list of - tokens. - - If a parsing error is encountered while iterating the string, - the behavior of the container will be as if a string containing - only characters up to but excluding the first invalid character - was used to construct the list. - - @par BNF - @code - token-list = *( "," OWS ) token *( OWS "," [ OWS token ] ) - @endcode - - To use this class, construct with the string to be parsed and - then use @ref begin and @ref end, or range-for to iterate each - item: - - @par Example - @code - for(auto const& token : token_list{"apple, pear, banana"}) - std::cout << token << "\n"; - @endcode -*/ -class token_list -{ - using iter_type = string_view::const_iterator; - - string_view s_; - -public: - /// The type of each element in the token list. - using value_type = string_view; - - /// A constant iterator to the list -#if BEAST_DOXYGEN - using const_iterator = implementation_defined; -#else - class const_iterator; -#endif - - /** Construct a list. - - @param s A string containing the list contents. The string - must remain valid for the lifetime of the container. - */ - explicit - token_list(string_view s) - : s_(s) - { - } - - /// Return a const iterator to the beginning of the list - const_iterator begin() const; - - /// Return a const iterator to the end of the list - const_iterator end() const; - - /// Return a const iterator to the beginning of the list - const_iterator cbegin() const; - - /// Return a const iterator to the end of the list - const_iterator cend() const; - - /** Return `true` if a token is present in the list. - - @param s The token to find. A case-insensitive comparison is used. - */ - template - bool - exists(T const& s); -}; - -/** A list of tokens in a comma separated HTTP field value. - - This container allows iteration of a list of items in a - header field value. The input is a comma separated list of - tokens. - - If a parsing error is encountered while iterating the string, - the behavior of the container will be as if a string containing - only characters up to but excluding the first invalid character - was used to construct the list. - - @par BNF - @code - token-list = *( "," OWS ) token *( OWS "," [ OWS token ] ) - @endcode - - To use this class, construct with the string to be parsed and - then use `begin` and `end`, or range-for to iterate each item: - - @par Example - @code - for(auto const& token : token_list{"apple, pear, banana"}) - std::cout << token << "\n"; - @endcode -*/ -using opt_token_list = - detail::basic_parsed_list< - detail::opt_token_list_policy>; - -/** Returns `true` if a parsed list is parsed without errors. - - This function iterates a single pass through a parsed list - and returns `true` if there were no parsing errors, else - returns `false`. -*/ -template -bool -validate_list(detail::basic_parsed_list< - Policy> const& list); - -} // http -} // beast - -#include - -#endif diff --git a/src/beast/include/beast/http/serializer.hpp b/src/beast/include/beast/http/serializer.hpp deleted file mode 100644 index 34bf1d83bfb..00000000000 --- a/src/beast/include/beast/http/serializer.hpp +++ /dev/null @@ -1,502 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_SERIALIZER_HPP -#define BEAST_HTTP_SERIALIZER_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifndef BEAST_NO_BIG_VARIANTS -# if defined(BOOST_GCC) && BOOST_GCC < 50000 && BOOST_VERSION < 106400 -# define BEAST_NO_BIG_VARIANTS -# endif -#endif - -namespace beast { -namespace http { - -/** A chunk decorator which does nothing. - - When selected as a chunk decorator, objects of this type - affect the output of messages specifying chunked - transfer encodings as follows: - - @li chunk headers will have empty chunk extensions, and - - @li final chunks will have an empty set of trailers. - - @see @ref serializer -*/ -struct no_chunk_decorator -{ - template - string_view - operator()(ConstBufferSequence const&) const - { - return {}; - } - - string_view - operator()(boost::asio::null_buffers) const - { - return {}; - } -}; - -/** Provides buffer oriented HTTP message serialization functionality. - - An object of this type is used to serialize a complete - HTTP message into a sequence of octets. To use this class, - construct an instance with the message to be serialized. - - The implementation will automatically perform chunk encoding - if the contents of the message indicate that chunk encoding - is required. If the semantics of the message indicate that - the connection should be closed after the message is sent, the - function @ref keep_alive will return `true`. - - Upon construction, an optional chunk decorator may be - specified. This decorator is a function object called with - each buffer sequence of the body when the chunked transfer - encoding is indicate in the message header. The decorator - will be called with an empty buffer sequence (actually - the type `boost::asio::null_buffers`) to indicate the - final chunk. The decorator may return a string which forms - the chunk extension for chunks, and the field trailers - for the final chunk. - - In C++11 the decorator must be declared as a class or - struct with a templated operator() thusly: - - @code - // The implementation guarantees that operator() - // will be called only after the view returned by - // any previous calls to operator() are no longer - // needed. The decorator instance is intended to - // manage the lifetime of the storage for all returned - // views. - // - struct decorator - { - // Returns the chunk-extension for each chunk, - // or an empty string for no chunk extension. The - // buffer must include the leading semicolon (";") - // and follow the format for chunk extensions defined - // in rfc7230. - // - template - string_view - operator()(ConstBufferSequence const&) const; - - // Returns a set of field trailers for the final chunk. - // Each field should be formatted according to rfc7230 - // including the trailing "\r\n" for each field. If - // no trailers are indicated, an empty string is returned. - // - string_view - operator()(boost::asio::null_buffers) const; - }; - @endcode - - @tparam isRequest `true` if the message is a request. - - @tparam Body The body type of the message. - - @tparam Fields The type of fields in the message. - - @tparam ChunkDecorator The type of chunk decorator to use. -*/ -template< - bool isRequest, - class Body, - class Fields = fields, - class ChunkDecorator = no_chunk_decorator> -class serializer -{ -public: - static_assert(is_body::value, - "Body requirements not met"); - - static_assert(is_body_reader::value, - "BodyReader requirements not met"); - - /** The type of message this serializer uses - - This may be const or non-const depending on the - implementation of the corresponding @b BodyReader. - */ -#if BEAST_DOXYGEN - using value_type = implementation_defined; -#else - using value_type = - typename std::conditional< - std::is_constructible&>::value && - ! std::is_constructible const&>::value, - message, - message const>::type; -#endif - -private: - enum - { - do_construct = 0, - - do_init = 10, - do_header_only = 20, - do_header = 30, - do_body = 40, - - do_init_c = 50, - do_header_only_c = 60, - do_header_c = 70, - do_body_c = 80, - do_final_c = 90, - #ifndef BEAST_NO_BIG_VARIANTS - do_body_final_c = 100, - do_all_c = 110, - #endif - - do_complete = 120 - }; - - void frdinit(std::true_type); - void frdinit(std::false_type); - - template - void - do_visit(error_code& ec, Visit& visit); - - using reader = typename Body::reader; - - using cb1_t = consuming_buffers; // header - using pcb1_t = buffer_prefix_view; - - using cb2_t = consuming_buffers>; // body - using pcb2_t = buffer_prefix_view; - - using cb3_t = consuming_buffers< - typename reader::const_buffers_type>; // body - using pcb3_t = buffer_prefix_view; - - using cb4_t = consuming_buffers>; // crlf - using pcb4_t = buffer_prefix_view; - - using cb5_t = consuming_buffers>; // crlf - using pcb5_t = buffer_prefix_view; - -#ifndef BEAST_NO_BIG_VARIANTS - using cb6_t = consuming_buffers>; // crlf - using pcb6_t = buffer_prefix_view; - - using cb7_t = consuming_buffers>; // crlf - using pcb7_t = buffer_prefix_view; -#endif - - using cb8_t = consuming_buffers>; // crlf - using pcb8_t = buffer_prefix_view; - - value_type& m_; - reader rd_; - boost::optional frd_; - boost::variant v_; - boost::variant pv_; - std::size_t limit_ = - (std::numeric_limits::max)(); - int s_ = do_construct; - bool split_ = false; - bool header_done_ = false; - bool chunked_; - bool keep_alive_; - bool more_; - ChunkDecorator d_; - -public: - /** Constructor - - The implementation guarantees that the message passed on - construction will not be accessed until the first call to - @ref next. This allows the message to be lazily created. - For example, if the header is filled in before serialization. - - @param msg A reference to the message to serialize, which must - remain valid for the lifetime of the serializer. Depending on - the type of Body used, this may or may not be a `const` reference. - - @note This function participates in overload resolution only if - Body::reader is constructible from a `const` message reference. - */ - explicit - serializer(value_type& msg); - - /** Constructor - - The implementation guarantees that the message passed on - construction will not be accessed until the first call to - @ref next. This allows the message to be lazily created. - For example, if the header is filled in before serialization. - - @param msg A reference to the message to serialize, which must - remain valid for the lifetime of the serializer. Depending on - the type of Body used, this may or may not be a `const` reference. - - @param decorator The decorator to use. - - @note This function participates in overload resolution only if - Body::reader is constructible from a `const` message reference. - */ - explicit - serializer(value_type& msg, ChunkDecorator const& decorator); - - /// Returns the message being serialized - value_type& - get() - { - return m_; - } - - /** Provides access to the associated @b BodyReader - - This function provides access to the instance of the reader - associated with the body and created by the serializer - upon construction. The behavior of accessing this object - is defined by the specification of the particular reader - and its associated body. - - @return A reference to the reader. - */ - reader& - reader_impl() - { - return rd_; - } - - /// Returns the serialized buffer size limit - std::size_t - limit() - { - return limit_; - } - - /** Set the serialized buffer size limit - - This function adjusts the limit on the maximum size of the - buffers passed to the visitor. The new size limit takes effect - in the following call to @ref next. - - The default is no buffer size limit. - - @param limit The new buffer size limit. If this number - is zero, the size limit is removed. - */ - void - limit(std::size_t limit) - { - limit_ = limit > 0 ? limit : - (std::numeric_limits::max)(); - } - - /** Returns `true` if we will pause after writing the complete header. - */ - bool - split() - { - return split_; - } - - /** Set whether the header and body are written separately. - - When the split feature is enabled, the implementation will - write only the octets corresponding to the serialized header - first. If the header has already been written, this function - will have no effect on output. - */ - void - split(bool v) - { - split_ = v; - } - - /** Return `true` if serialization of the header is complete. - - This function indicates whether or not all buffers containing - serialized header octets have been retrieved. - */ - bool - is_header_done() - { - return header_done_; - } - - /** Return `true` if serialization is complete. - - The operation is complete when all octets corresponding - to the serialized representation of the message have been - successfully retrieved. - */ - bool - is_done() - { - return s_ == do_complete; - } - - /** Return `true` if the serializer will apply chunk-encoding. - - This function may only be called if @ref is_header_done - would return `true`. - */ - bool - chunked() - { - return chunked_; - } - - /** Return `true` if Connection: keep-alive semantic is indicated. - - This function returns `true` if the semantics of the - message indicate that the connection should be kept open - after the serialized message has been transmitted. The - value depends on the HTTP version of the message, - the tokens in the Connection header, and the metadata - describing the payload body. - - Depending on the payload body, the end of the message may - be indicated by connection closuire. In order for the - recipient (if any) to receive a complete message, the - underlying stream or network connection must be closed - when this function returns `false`. - - This function may only be called if @ref is_header_done - would return `true`. - */ - bool - keep_alive() - { - return keep_alive_; - } - - /** Returns the next set of buffers in the serialization. - - This function will attempt to call the `visit` function - object with a @b ConstBufferSequence of unspecified type - representing the next set of buffers in the serialization - of the message represented by this object. - - If there are no more buffers in the serialization, the - visit function will not be called. In this case, no error - will be indicated, and the function @ref is_done will - return `true`. - - @param ec Set to the error, if any occurred. - - @param visit The function to call. The equivalent function - signature of this object must be: - @code - template - void visit(error_code&, ConstBufferSequence const&); - @endcode - The function is not copied, if no error occurs it will be - invoked before the call to @ref next returns. - - */ - template - void - next(error_code& ec, Visit&& visit); - - /** Consume buffer octets in the serialization. - - This function should be called after one or more octets - contained in the buffers provided in the prior call - to @ref next have been used. - - After a call to @ref consume, callers should check the - return value of @ref is_done to determine if the entire - message has been serialized. - - @param n The number of octets to consume. This number must - be greater than zero and no greater than the number of - octets in the buffers provided in the prior call to @ref next. - */ - void - consume(std::size_t n); -}; - -/// A serializer for HTTP/1 requests -template< - class Body, - class Fields = fields, - class ChunkDecorator = no_chunk_decorator> -using request_serializer = serializer; - -/// A serializer for HTTP/1 responses -template< - class Body, - class Fields = fields, - class ChunkDecorator = no_chunk_decorator> -using response_serializer = serializer; - -} // http -} // beast - -#include - -#endif diff --git a/src/beast/include/beast/http/span_body.hpp b/src/beast/include/beast/http/span_body.hpp deleted file mode 100644 index 8e83cde2014..00000000000 --- a/src/beast/include/beast/http/span_body.hpp +++ /dev/null @@ -1,167 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_SPAN_BODY_HPP -#define BEAST_HTTP_SPAN_BODY_HPP - -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -/** A @b Body using @ref span - - This body uses @ref span as a memory-based container for - holding message payloads. The container represents a - non-owning reference to a continguous area of memory. - Messages using this body type may be serialized and - parsed. - - Unlike @ref buffer_body, only one buffer may be provided - during a parse or serialize operation. -*/ -template -struct span_body -{ -private: - static_assert(std::is_pod::value, - "POD requirements not met"); - -public: - /** The type of container used for the body - - This determines the type of @ref message::body - when this body type is used with a message container. - */ - using value_type = span; - - /** Returns the payload size of the body - - When this body is used with @ref message::prepare_payload, - the Content-Length will be set to the payload size, and - any chunked Transfer-Encoding will be removed. - */ - static - std::uint64_t - size(value_type const& body) - { - return body.size(); - } - - /** The algorithm for serializing the body - - Meets the requirements of @b BodyReader. - */ -#if BEAST_DOXYGEN - using reader = implementation_defined; -#else - class reader - { - value_type const& body_; - - public: - using const_buffers_type = - boost::asio::const_buffers_1; - - template - explicit - reader(message const& msg) - : body_(msg.body) - { - } - - void - init(error_code& ec) - { - ec.assign(0, ec.category()); - } - - boost::optional> - get(error_code& ec) - { - ec.assign(0, ec.category()); - return {{ - { body_.data(), - body_.size() * sizeof(typename - value_type::value_type)}, - false}}; - } - }; -#endif - - /** The algorithm for parsing the body - - Meets the requirements of @b BodyReader. - */ -#if BEAST_DOXYGEN - using writer = implementation_defined; -#else - class writer - { - value_type& body_; - - public: - template - explicit - writer(message& m) - : body_(m.body) - { - } - - void - init(boost::optional< - std::uint64_t> const& length, error_code& ec) - { - if(length && *length > body_.size()) - { - ec = error::buffer_overflow; - return; - } - ec.assign(0, ec.category()); - } - - template - std::size_t - put(ConstBufferSequence const& buffers, - error_code& ec) - { - using boost::asio::buffer_size; - using boost::asio::buffer_copy; - auto const n = buffer_size(buffers); - auto const len = body_.size(); - if(n > len) - { - ec = error::buffer_overflow; - return 0; - } - ec.assign(0, ec.category()); - buffer_copy(boost::asio::buffer( - body_.data(), n), buffers); - body_ = value_type{ - body_.data() + n, body_.size() - n}; - return n; - } - - void - finish(error_code& ec) - { - ec.assign(0, ec.category()); - } - }; -#endif -}; - -} // http -} // beast - -#endif diff --git a/src/beast/include/beast/http/status.hpp b/src/beast/include/beast/http/status.hpp deleted file mode 100644 index b202aa7beee..00000000000 --- a/src/beast/include/beast/http/status.hpp +++ /dev/null @@ -1,163 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_STATUS_HPP -#define BEAST_HTTP_STATUS_HPP - -#include -#include -#include - -namespace beast { -namespace http { - -enum class status : unsigned -{ - /** An unknown status-code. - - This value indicates that the value for the status code - is not in the list of commonly recognized status codes. - Callers interested in the exactly value should use the - interface which provides the raw integer. - */ - unknown = 0, - - continue_ = 100, - switching_protocols = 101, - processing = 102, - - ok = 200, - created = 201, - accepted = 202, - non_authoritative_information = 203, - no_content = 204, - reset_content = 205, - partial_content = 206, - multi_status = 207, - already_reported = 208, - im_used = 226, - - multiple_choices = 300, - moved_permanently = 301, - found = 302, - see_other = 303, - not_modified = 304, - use_proxy = 305, - temporary_redirect = 307, - permanent_redirect = 308, - - bad_request = 400, - unauthorized = 401, - payment_required = 402, - forbidden = 403, - not_found = 404, - method_not_allowed = 405, - not_acceptable = 406, - proxy_authentication_required = 407, - request_timeout = 408, - conflict = 409, - gone = 410, - length_required = 411, - precondition_failed = 412, - payload_too_large = 413, - uri_too_long = 414, - unsupported_media_type = 415, - range_not_satisfiable = 416, - expectation_failed = 417, - misdirected_request = 421, - unprocessable_entity = 422, - locked = 423, - failed_dependency = 424, - upgrade_required = 426, - precondition_required = 428, - too_many_requests = 429, - request_header_fields_too_large = 431, - connection_closed_without_response = 444, - unavailable_for_legal_reasons = 451, - client_closed_request = 499, - - internal_server_error = 500, - not_implemented = 501, - bad_gateway = 502, - service_unavailable = 503, - gateway_timeout = 504, - http_version_not_supported = 505, - variant_also_negotiates = 506, - insufficient_storage = 507, - loop_detected = 508, - not_extended = 510, - network_authentication_required = 511, - network_connect_timeout_error = 599 -}; - -/** Represents the class of a status-code. -*/ -enum class status_class : unsigned -{ - /// Unknown status-class - unknown = 0, - - /// The request was received, continuing processing. - informational = 1, - - /// The request was successfully received, understood, and accepted. - successful = 2, - - /// Further action needs to be taken in order to complete the request. - redirection = 3, - - /// The request contains bad syntax or cannot be fulfilled. - client_error = 4, - - /// The server failed to fulfill an apparently valid request. - server_error = 5, -}; - -/** Converts the integer to a known status-code. - - If the integer does not match a known status code, - @ref status::unknown is returned. -*/ -status -int_to_status(unsigned v); - -/** Convert an integer to a status_class. - - @param v The integer representing a status code. - - @return The status class. If the integer does not match - a known status class, @ref status_class::unknown is returned. -*/ -status_class -to_status_class(unsigned v); - -/** Convert a status_code to a status_class. - - @param v The status code to convert. - - @return The status class. -*/ -status_class -to_status_class(status v); - -/** Returns the obsolete reason-phrase text for a status code. - - @param v The status code to use. -*/ -string_view -obsolete_reason(status v); - -/// Outputs the standard reason phrase of a status code to a stream. -std::ostream& -operator<<(std::ostream&, status); - -} // http -} // beast - -#include - -#endif diff --git a/src/beast/include/beast/http/string_body.hpp b/src/beast/include/beast/http/string_body.hpp deleted file mode 100644 index cdeaec7c765..00000000000 --- a/src/beast/include/beast/http/string_body.hpp +++ /dev/null @@ -1,190 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_STRING_BODY_HPP -#define BEAST_HTTP_STRING_BODY_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -/** A @b Body using `std::basic_string` - - This body uses `std::basic_string` as a memory-based container - for holding message payloads. Messages using this body type - may be serialized and parsed. -*/ -template< - class CharT, - class Traits = std::char_traits, - class Allocator = std::allocator> -struct basic_string_body -{ -private: - static_assert( - std::is_integral::value && - sizeof(CharT) == 1, - "CharT requirements not met"); - -public: - /** The type of container used for the body - - This determines the type of @ref message::body - when this body type is used with a message container. - */ - using value_type = - std::basic_string; - - /** Returns the payload size of the body - - When this body is used with @ref message::prepare_payload, - the Content-Length will be set to the payload size, and - any chunked Transfer-Encoding will be removed. - */ - static - std::uint64_t - size(value_type const& body) - { - return body.size(); - } - - /** The algorithm for serializing the body - - Meets the requirements of @b BodyReader. - */ -#if BEAST_DOXYGEN - using reader = implementation_defined; -#else - class reader - { - value_type const& body_; - - public: - using const_buffers_type = - boost::asio::const_buffers_1; - - template - explicit - reader(message const& msg) - : body_(msg.body) - { - } - - void - init(error_code& ec) - { - ec.assign(0, ec.category()); - } - - boost::optional> - get(error_code& ec) - { - ec.assign(0, ec.category()); - return {{const_buffers_type{ - body_.data(), body_.size()}, false}}; - } - }; -#endif - - /** The algorithm for parsing the body - - Meets the requirements of @b BodyReader. - */ -#if BEAST_DOXYGEN - using writer = implementation_defined; -#else - class writer - { - value_type& body_; - - public: - template - explicit - writer(message& m) - : body_(m.body) - { - } - - void - init(boost::optional< - std::uint64_t> const& length, error_code& ec) - { - if(length) - { - if(*length > ( - std::numeric_limits::max)()) - { - ec = error::buffer_overflow; - return; - } - try - { - body_.reserve( - static_cast(*length)); - } - catch(std::exception const&) - { - ec = error::buffer_overflow; - return; - } - } - ec.assign(0, ec.category()); - } - - template - std::size_t - put(ConstBufferSequence const& buffers, - error_code& ec) - { - using boost::asio::buffer_size; - using boost::asio::buffer_copy; - auto const n = buffer_size(buffers); - auto const len = body_.size(); - try - { - body_.resize(len + n); - } - catch(std::exception const&) - { - ec = error::buffer_overflow; - return 0; - } - ec.assign(0, ec.category()); - return buffer_copy(boost::asio::buffer( - &body_[0] + len, n), buffers); - } - - void - finish(error_code& ec) - { - ec.assign(0, ec.category()); - } - }; -#endif -}; - -/// A @b Body using `std::string` -using string_body = basic_string_body; - -} // http -} // beast - -#endif diff --git a/src/beast/include/beast/http/type_traits.hpp b/src/beast/include/beast/http/type_traits.hpp deleted file mode 100644 index 46f5674a96f..00000000000 --- a/src/beast/include/beast/http/type_traits.hpp +++ /dev/null @@ -1,181 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_TYPE_TRAITS_HPP -#define BEAST_HTTP_TYPE_TRAITS_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -template -struct message; - -/** Determine if `T` meets the requirements of @b Body. - - This metafunction is equivalent to `std::true_type` - if `T` has a nested type named `value_type`. - - @tparam T The body type to test. - - @par Example - @code - template - void check_body(message const&) - { - static_assert(is_body::value, - "Body requirements not met"); - } - @endcode -*/ -template -#if BEAST_DOXYGEN -struct is_body : std::integral_constant{}; -#else -using is_body = detail::has_value_type; -#endif - -/** Determine if a @b Body type has a reader. - - This metafunction is equivalent to `std::true_type` if: - - @li `T` has a nested type named `reader` - - @li The nested type meets the requirements of @b BodyReader. - - @tparam T The body type to test. - - @par Example - @code - template - void check_can_serialize(message const&) - { - static_assert(is_body_reader::value, - "Cannot serialize Body, no reader"); - } - @endcode -*/ -#if BEAST_DOXYGEN -template -struct is_body_reader : std::integral_constant {}; -#else -template -struct is_body_reader : std::false_type {}; - -template -struct is_body_reader().init(std::declval()), - std::declval>&>() = - std::declval().get(std::declval()), - (void)0)>> : std::integral_constant::value && - std::is_constructible&>::value && - std::is_constructible&>::value - > {}; -#endif - -/** Determine if a @b Body type has a writer. - - This metafunction is equivalent to `std::true_type` if: - - @li `T` has a nested type named `writer` - - @li The nested type meets the requirements of @b BodyWriter. - - @tparam T The body type to test. - - @par Example - @code - template - void check_can_parse(message&) - { - static_assert(is_body_writer::value, - "Cannot parse Body, no writer"); - } - @endcode -*/ -#if BEAST_DOXYGEN -template -struct is_body_writer : std::integral_constant {}; -#else -template -struct is_body_writer : std::false_type {}; - -template -struct is_body_writer().init( - boost::optional(), - std::declval()), - std::declval() = - std::declval().put( - std::declval(), - std::declval()), - std::declval().finish( - std::declval()), - (void)0)>> : std::integral_constant&>::value && - std::is_constructible&>::value - > -{ -}; -#endif - -/** Determine if `T` meets the requirements of @b Fields - - @tparam T The body type to test. - - @par Example - - Use with `static_assert`: - - @code - template - void f(message const&) - { - static_assert(is_fields::value, - "Fields requirements not met"); - ... - @endcode - - Use with `std::enable_if` (SFINAE): - - @code - template - typename std::enable_if::value>::type - f(message const&); - @endcode -*/ -#if BEAST_DOXYGEN -template -struct is_fields : std::integral_constant {}; -#else -template -using is_fields = typename detail::is_fields_helper::type; -#endif - -} // http -} // beast - -#endif diff --git a/src/beast/include/beast/http/vector_body.hpp b/src/beast/include/beast/http/vector_body.hpp deleted file mode 100644 index 36a19c42553..00000000000 --- a/src/beast/include/beast/http/vector_body.hpp +++ /dev/null @@ -1,182 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_VECTOR_BODY_HPP -#define BEAST_HTTP_VECTOR_BODY_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -/** A @b Body using `std::vector` - - This body uses `std::vector` as a memory-based container - for holding message payloads. Messages using this body type - may be serialized and parsed. -*/ -template> -struct vector_body -{ -private: - static_assert(sizeof(T) == 1 && - std::is_integral::value, - "T requirements not met"); - -public: - /** The type of container used for the body - - This determines the type of @ref message::body - when this body type is used with a message container. - */ - using value_type = std::vector; - - /** Returns the payload size of the body - - When this body is used with @ref message::prepare_payload, - the Content-Length will be set to the payload size, and - any chunked Transfer-Encoding will be removed. - */ - static - std::uint64_t - size(value_type const& body) - { - return body.size(); - } - - /** The algorithm for serializing the body - - Meets the requirements of @b BodyReader. - */ -#if BEAST_DOXYGEN - using reader = implementation_defined; -#else - class reader - { - value_type const& body_; - - public: - using const_buffers_type = - boost::asio::const_buffers_1; - - template - explicit - reader(message const& msg) - : body_(msg.body) - { - } - - void - init(error_code& ec) - { - ec.assign(0, ec.category()); - } - - boost::optional> - get(error_code& ec) - { - ec.assign(0, ec.category()); - return {{const_buffers_type{ - body_.data(), body_.size()}, false}}; - } - }; -#endif - - /** The algorithm for parsing the body - - Meets the requirements of @b BodyReader. - */ -#if BEAST_DOXYGEN - using writer = implementation_defined; -#else - class writer - { - value_type& body_; - - public: - template - explicit - writer(message& m) - : body_(m.body) - { - } - - void - init(boost::optional< - std::uint64_t> const& length, error_code& ec) - { - if(length) - { - if(*length > ( - std::numeric_limits::max)()) - { - ec = error::buffer_overflow; - return; - } - try - { - body_.reserve( - static_cast(*length)); - } - catch(std::exception const&) - { - ec = error::buffer_overflow; - return; - } - } - ec.assign(0, ec.category()); - } - - template - std::size_t - put(ConstBufferSequence const& buffers, - error_code& ec) - { - using boost::asio::buffer_size; - using boost::asio::buffer_copy; - auto const n = buffer_size(buffers); - auto const len = body_.size(); - try - { - body_.resize(len + n); - } - catch(std::exception const&) - { - ec = error::buffer_overflow; - return 0; - } - ec.assign(0, ec.category()); - return buffer_copy(boost::asio::buffer( - &body_[0] + len, n), buffers); - } - - void - finish(error_code& ec) - { - ec.assign(0, ec.category()); - } - }; -#endif -}; - -} // http -} // beast - -#endif diff --git a/src/beast/include/beast/http/verb.hpp b/src/beast/include/beast/http/verb.hpp deleted file mode 100644 index 679af1a65e3..00000000000 --- a/src/beast/include/beast/http/verb.hpp +++ /dev/null @@ -1,153 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_VERB_HPP -#define BEAST_HTTP_VERB_HPP - -#include -#include -#include - -namespace beast { -namespace http { - -/** HTTP request method verbs - - Each verb corresponds to a particular method string - used in HTTP request messages. -*/ -enum class verb -{ - /** An unknown method. - - This value indicates that the request method string is not - one of the recognized verbs. Callers interested in the method - should use an interface which returns the original string. - */ - unknown = 0, - - /// The DELETE method deletes the specified resource - delete_, - - /** The GET method requests a representation of the specified resource. - - Requests using GET should only retrieve data and should have no other effect. - */ - get, - - /** The HEAD method asks for a response identical to that of a GET request, but without the response body. - - This is useful for retrieving meta-information written in response - headers, without having to transport the entire content. - */ - head, - - /** The POST method requests that the server accept the entity enclosed in the request as a new subordinate of the web resource identified by the URI. - - The data POSTed might be, for example, an annotation for existing - resources; a message for a bulletin board, newsgroup, mailing list, - or comment thread; a block of data that is the result of submitting - a web form to a data-handling process; or an item to add to a database - */ - post, - - /** The PUT method requests that the enclosed entity be stored under the supplied URI. - - If the URI refers to an already existing resource, it is modified; - if the URI does not point to an existing resource, then the server - can create the resource with that URI. - */ - put, - - /** The CONNECT method converts the request connection to a transparent TCP/IP tunnel. - - This is usually to facilitate SSL-encrypted communication (HTTPS) - through an unencrypted HTTP proxy. - */ - connect, - - /** The OPTIONS method returns the HTTP methods that the server supports for the specified URL. - - This can be used to check the functionality of a web server by requesting - '*' instead of a specific resource. - */ - options, - - /** The TRACE method echoes the received request so that a client can see what (if any) changes or additions have been made by intermediate servers. - */ - trace, - - // WebDAV - - copy, - lock, - mkcol, - move, - propfind, - proppatch, - search, - unlock, - bind, - rebind, - unbind, - acl, - - // subversion - - report, - mkactivity, - checkout, - merge, - - // upnp - - msearch, - notify, - subscribe, - unsubscribe, - - // RFC-5789 - - patch, - purge, - - // CalDAV - - mkcalendar, - - // RFC-2068, section 19.6.1.2 - - link, - unlink -}; - -/** Converts a string to the request method verb. - - If the string does not match a known request method, - @ref verb::unknown is returned. -*/ -verb -string_to_verb(string_view s); - -/// Returns the text representation of a request method verb. -string_view -to_string(verb v); - -/// Write the text for a request method verb to an output stream. -inline -std::ostream& -operator<<(std::ostream& os, verb v) -{ - return os << to_string(v); -} - -} // http -} // beast - -#include - -#endif diff --git a/src/beast/include/beast/http/write.hpp b/src/beast/include/beast/http/write.hpp deleted file mode 100644 index 36fe0c00fb5..00000000000 --- a/src/beast/include/beast/http/write.hpp +++ /dev/null @@ -1,538 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_WRITE_HPP -#define BEAST_HTTP_WRITE_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -/** Write part of a message to a stream using a serializer. - - This function is used to write part of a message to a stream using - a caller-provided HTTP/1 serializer. The call will block until one - of the following conditions is true: - - @li One or more bytes have been transferred. - - @li The function @ref serializer::is_done returns `true` - - @li An error occurs on the stream. - - This operation is implemented in terms of one or more calls - to the stream's `write_some` function. - - The amount of data actually transferred is controlled by the behavior - of the underlying stream, subject to the buffer size limit of the - serializer obtained or set through a call to @ref serializer::limit. - Setting a limit and performing bounded work helps applications set - reasonable timeouts. It also allows application-level flow control - to function correctly. For example when using a TCP/IP based - stream. - - @param stream The stream to which the data is to be written. - The type must support the @b SyncWriteStream concept. - - @param sr The serializer to use. - - @throws system_error Thrown on failure. - - @see serializer -*/ -template -void -write_some(SyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator>& sr); - -/** Write part of a message to a stream using a serializer. - - This function is used to write part of a message to a stream using - a caller-provided HTTP/1 serializer. The call will block until one - of the following conditions is true: - - @li One or more bytes have been transferred. - - @li The function @ref serializer::is_done returns `true` - - @li An error occurs on the stream. - - This operation is implemented in terms of one or more calls - to the stream's `write_some` function. - - The amount of data actually transferred is controlled by the behavior - of the underlying stream, subject to the buffer size limit of the - serializer obtained or set through a call to @ref serializer::limit. - Setting a limit and performing bounded work helps applications set - reasonable timeouts. It also allows application-level flow control - to function correctly. For example when using a TCP/IP based - stream. - - @param stream The stream to which the data is to be written. - The type must support the @b SyncWriteStream concept. - - @param sr The serializer to use. - - @param ec Set to indicate what error occurred, if any. - - @see @ref async_write_some, @ref serializer -*/ -template -void -write_some(SyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator>& sr, - error_code& ec); - -/** Write part of a message to a stream asynchronously using a serializer. - - This function is used to write part of a message to a stream - asynchronously using a caller-provided HTTP/1 serializer. The function - call always returns immediately. The asynchronous operation will continue - until one of the following conditions is true: - - @li One or more bytes have been transferred. - - @li The function @ref serializer::is_done returns `true` - - @li An error occurs on the stream. - - This operation is implemented in terms of zero or more calls to the stream's - `async_write_some` function, and is known as a composed operation. - The program must ensure that the stream performs no other write operations - until this operation completes. - - The amount of data actually transferred is controlled by the behavior - of the underlying stream, subject to the buffer size limit of the - serializer obtained or set through a call to @ref serializer::limit. - Setting a limit and performing bounded work helps applications set - reasonable timeouts. It also allows application-level flow control - to function correctly. For example when using a TCP/IP based - stream. - - @param stream The stream to which the data is to be written. - The type must support the @b AsyncWriteStream concept. - - @param sr The serializer to use. - The object must remain valid at least until the - handler is called; ownership is not transferred. - - @param handler The handler to be called when the operation - completes. Copies will be made of the handler as required. - The equivalent function signature of the handler must be: - @code void handler( - error_code const& error // result of operation - ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. - - @see @ref serializer -*/ -template -#if BEAST_DOXYGEN - void_or_deduced -#else -async_return_type -#endif -async_write_some(AsyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator>& sr, - WriteHandler&& handler); - -//------------------------------------------------------------------------------ - -/** Write a header to a stream using a serializer. - - This function is used to write a header to a stream using a - caller-provided HTTP/1 serializer. The call will block until one - of the following conditions is true: - - @li The function @ref serializer::is_header_done returns `true` - - @li An error occurs. - - This operation is implemented in terms of one or more calls - to the stream's `write_some` function. - - @param stream The stream to which the data is to be written. - The type must support the @b SyncWriteStream concept. - - @param sr The serializer to use. - - @throws system_error Thrown on failure. - - @note The implementation will call @ref serializer::split with - the value `true` on the serializer passed in. - - @see @ref serializer -*/ -template -void -write_header(SyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator>& sr); - -/** Write a header to a stream using a serializer. - - This function is used to write a header to a stream using a - caller-provided HTTP/1 serializer. The call will block until one - of the following conditions is true: - - @li The function @ref serializer::is_header_done returns `true` - - @li An error occurs. - - This operation is implemented in terms of one or more calls - to the stream's `write_some` function. - - @param stream The stream to which the data is to be written. - The type must support the @b SyncWriteStream concept. - - @param sr The serializer to use. - - @param ec Set to indicate what error occurred, if any. - - @note The implementation will call @ref serializer::split with - the value `true` on the serializer passed in. - - @see @ref serializer -*/ -template -void -write_header(SyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator>& sr, - error_code& ec); - -/** Write a header to a stream asynchronously using a serializer. - - This function is used to write a header to a stream asynchronously - using a caller-provided HTTP/1 serializer. The function call always - returns immediately. The asynchronous operation will continue until - one of the following conditions is true: - - @li The function @ref serializer::is_header_done returns `true` - - @li An error occurs. - - This operation is implemented in terms of zero or more calls to the stream's - `async_write_some` function, and is known as a composed operation. - The program must ensure that the stream performs no other write operations - until this operation completes. - - @param stream The stream to which the data is to be written. - The type must support the @b AsyncWriteStream concept. - - @param sr The serializer to use. - The object must remain valid at least until the - handler is called; ownership is not transferred. - - @param handler The handler to be called when the operation - completes. Copies will be made of the handler as required. - The equivalent function signature of the handler must be: - @code void handler( - error_code const& error // result of operation - ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. - - @note The implementation will call @ref serializer::split with - the value `true` on the serializer passed in. - - @see @ref serializer -*/ -template -#if BEAST_DOXYGEN - void_or_deduced -#else -async_return_type -#endif -async_write_header(AsyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator>& sr, - WriteHandler&& handler); - -//------------------------------------------------------------------------------ - -/** Write a complete message to a stream using a serializer. - - This function is used to write a complete message to a stream using - a caller-provided HTTP/1 serializer. The call will block until one - of the following conditions is true: - - @li The function @ref serializer::is_done returns `true` - - @li An error occurs. - - This operation is implemented in terms of one or more calls - to the stream's `write_some` function. - - @param stream The stream to which the data is to be written. - The type must support the @b SyncWriteStream concept. - - @param sr The serializer to use. - - @throws system_error Thrown on failure. - - @see @ref serializer -*/ -template -void -write(SyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator>& sr); - -/** Write a complete message to a stream using a serializer. - - This function is used to write a complete message to a stream using - a caller-provided HTTP/1 serializer. The call will block until one - of the following conditions is true: - - @li The function @ref serializer::is_done returns `true` - - @li An error occurs. - - This operation is implemented in terms of one or more calls - to the stream's `write_some` function. - - @param stream The stream to which the data is to be written. - The type must support the @b SyncWriteStream concept. - - @param sr The serializer to use. - - @param ec Set to the error, if any occurred. - - @see @ref serializer -*/ -template -void -write(SyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator>& sr, - error_code& ec); - -/** Write a complete message to a stream asynchronously using a serializer. - - This function is used to write a complete message to a stream - asynchronously using a caller-provided HTTP/1 serializer. The - function call always returns immediately. The asynchronous - operation will continue until one of the following conditions is true: - - @li The function @ref serializer::is_done returns `true` - - @li An error occurs. - - This operation is implemented in terms of zero or more calls to the stream's - `async_write_some` function, and is known as a composed operation. - The program must ensure that the stream performs no other write operations - until this operation completes. - - @param stream The stream to which the data is to be written. - The type must support the @b AsyncWriteStream concept. - - @param sr The serializer to use. - The object must remain valid at least until the - handler is called; ownership is not transferred. - - @param handler The handler to be called when the operation - completes. Copies will be made of the handler as required. - The equivalent function signature of the handler must be: - @code void handler( - error_code const& error // result of operation - ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. - - @see @ref serializer -*/ -template -#if BEAST_DOXYGEN - void_or_deduced -#else -async_return_type -#endif -async_write(AsyncWriteStream& stream, serializer< - isRequest, Body, Fields, Decorator>& sr, - WriteHandler&& handler); - -//------------------------------------------------------------------------------ - -/** Write a complete message to a stream. - - This function is used to write a complete message to a stream using - HTTP/1. The call will block until one of the following conditions is true: - - @li The entire message is written. - - @li An error occurs. - - This operation is implemented in terms of one or more calls to the stream's - `write_some` function. The algorithm will use a temporary @ref serializer - with an empty chunk decorator to produce buffers. If the semantics of the - message indicate that the connection should be closed after the message is - sent, the error delivered by this function will be @ref error::end_of_stream - - @param stream The stream to which the data is to be written. - The type must support the @b SyncWriteStream concept. - - @param msg The message to write. - - @throws system_error Thrown on failure. - - @see @ref message -*/ -template -void -write(SyncWriteStream& stream, - message const& msg); - -/** Write a complete message to a stream. - - This function is used to write a complete message to a stream using - HTTP/1. The call will block until one of the following conditions is true: - - @li The entire message is written. - - @li An error occurs. - - This operation is implemented in terms of one or more calls to the stream's - `write_some` function. The algorithm will use a temporary @ref serializer - with an empty chunk decorator to produce buffers. If the semantics of the - message indicate that the connection should be closed after the message is - sent, the error delivered by this function will be @ref error::end_of_stream - - @param stream The stream to which the data is to be written. - The type must support the @b SyncWriteStream concept. - - @param msg The message to write. - - @param ec Set to the error, if any occurred. - - @see @ref message -*/ -template -void -write(SyncWriteStream& stream, - message const& msg, - error_code& ec); - -/** Write a complete message to a stream asynchronously. - - This function is used to write a complete message to a stream asynchronously - using HTTP/1. The function call always returns immediately. The asynchronous - operation will continue until one of the following conditions is true: - - @li The entire message is written. - - @li An error occurs. - - This operation is implemented in terms of zero or more calls to the stream's - `async_write_some` function, and is known as a composed operation. - The program must ensure that the stream performs no other write operations - until this operation completes. The algorithm will use a temporary - @ref serializer with an empty chunk decorator to produce buffers. If - the semantics of the message indicate that the connection should be - closed after the message is sent, the error delivered by this function - will be @ref error::end_of_stream - - @param stream The stream to which the data is to be written. - The type must support the @b AsyncWriteStream concept. - - @param msg The message to write. - The object must remain valid at least until the - handler is called; ownership is not transferred. - - @param handler The handler to be called when the operation - completes. Copies will be made of the handler as required. - The equivalent function signature of the handler must be: - @code void handler( - error_code const& error // result of operation - ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. - - @see @ref message -*/ -template -async_return_type< - WriteHandler, void(error_code)> -async_write(AsyncWriteStream& stream, - message& msg, - WriteHandler&& handler); - -//------------------------------------------------------------------------------ - -/** Serialize an HTTP/1 header to a `std::ostream`. - - The function converts the header to its HTTP/1 serialized - representation and stores the result in the output stream. - - @param os The output stream to write to. - - @param msg The message fields to write. -*/ -template -std::ostream& -operator<<(std::ostream& os, - header const& msg); - -/** Serialize an HTTP/1 message to a `std::ostream`. - - The function converts the message to its HTTP/1 serialized - representation and stores the result in the output stream. - - The implementation will automatically perform chunk encoding if - the contents of the message indicate that chunk encoding is required. - - @param os The output stream to write to. - - @param msg The message to write. -*/ -template -std::ostream& -operator<<(std::ostream& os, - message const& msg); - -} // http -} // beast - -#include - -#endif diff --git a/src/beast/include/beast/version.hpp b/src/beast/include/beast/version.hpp deleted file mode 100644 index d827f89f3bf..00000000000 --- a/src/beast/include/beast/version.hpp +++ /dev/null @@ -1,26 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_VERSION_HPP -#define BEAST_VERSION_HPP - -#include -#include - -/** @def BEAST_API_VERSION - - Identifies the API version of Beast. - - This is a simple integer that is incremented by one every time - a set of code changes is merged to the master or develop branch. -*/ -#define BEAST_VERSION 79 - -#define BEAST_VERSION_STRING "Beast/" BOOST_STRINGIZE(BEAST_VERSION) - -#endif - diff --git a/src/beast/include/beast/websocket.hpp b/src/beast/include/beast/websocket.hpp deleted file mode 100644 index 1cec37cd4aa..00000000000 --- a/src/beast/include/beast/websocket.hpp +++ /dev/null @@ -1,19 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_WEBSOCKET_HPP -#define BEAST_WEBSOCKET_HPP - -#include - -#include -#include -#include -#include -#include - -#endif diff --git a/src/beast/include/beast/websocket/detail/frame.hpp b/src/beast/include/beast/websocket/detail/frame.hpp deleted file mode 100644 index 512f817a791..00000000000 --- a/src/beast/include/beast/websocket/detail/frame.hpp +++ /dev/null @@ -1,300 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_WEBSOCKET_DETAIL_FRAME_HPP -#define BEAST_WEBSOCKET_DETAIL_FRAME_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace websocket { -namespace detail { - -inline -std::uint16_t -big_uint16_to_native(void const* buf) -{ - auto const p = reinterpret_cast< - std::uint8_t const*>(buf); - return (p[0]<<8) + p[1]; -} - -inline -std::uint64_t -big_uint64_to_native(void const* buf) -{ - auto const p = reinterpret_cast< - std::uint8_t const*>(buf); - return - (static_cast(p[0])<<56) + - (static_cast(p[1])<<48) + - (static_cast(p[2])<<40) + - (static_cast(p[3])<<32) + - (static_cast(p[4])<<24) + - (static_cast(p[5])<<16) + - (static_cast(p[6])<< 8) + - p[7]; -} - -inline -std::uint32_t -little_uint32_to_native(void const* buf) -{ - auto const p = reinterpret_cast< - std::uint8_t const*>(buf); - return - p[0] + - (static_cast(p[1])<< 8) + - (static_cast(p[2])<<16) + - (static_cast(p[3])<<24); -} - -inline -void -native_to_little_uint32(std::uint32_t v, void* buf) -{ - auto p = reinterpret_cast(buf); - p[0] = v & 0xff; - p[1] = (v >> 8) & 0xff; - p[2] = (v >> 16) & 0xff; - p[3] = (v >> 24) & 0xff; -} - -/** WebSocket frame header opcodes. */ -enum class opcode : std::uint8_t -{ - cont = 0, - text = 1, - binary = 2, - rsv3 = 3, - rsv4 = 4, - rsv5 = 5, - rsv6 = 6, - rsv7 = 7, - close = 8, - ping = 9, - pong = 10, - crsvb = 11, - crsvc = 12, - crsvd = 13, - crsve = 14, - crsvf = 15 -}; - -// Contents of a WebSocket frame header -struct frame_header -{ - opcode op; - bool fin; - bool mask; - bool rsv1; - bool rsv2; - bool rsv3; - std::uint64_t len; - std::uint32_t key; -}; - -// holds the largest possible frame header -using fh_streambuf = - static_buffer_n<14>; - -// holds the largest possible control frame -using frame_streambuf = - static_buffer_n< 2 + 8 + 4 + 125 >; - -inline -bool constexpr -is_reserved(opcode op) -{ - return - (op >= opcode::rsv3 && op <= opcode::rsv7) || - (op >= opcode::crsvb && op <= opcode::crsvf); -} - -inline -bool constexpr -is_valid(opcode op) -{ - return op <= opcode::crsvf; -} - -inline -bool constexpr -is_control(opcode op) -{ - return op >= opcode::close; -} - -inline -bool -is_valid_close_code(std::uint16_t v) -{ - switch(v) - { - case close_code::normal: // 1000 - case close_code::going_away: // 1001 - case close_code::protocol_error: // 1002 - case close_code::unknown_data: // 1003 - case close_code::bad_payload: // 1007 - case close_code::policy_error: // 1008 - case close_code::too_big: // 1009 - case close_code::needs_extension: // 1010 - case close_code::internal_error: // 1011 - case close_code::service_restart: // 1012 - case close_code::try_again_later: // 1013 - return true; - - // explicitly reserved - case close_code::reserved1: // 1004 - case close_code::no_status: // 1005 - case close_code::abnormal: // 1006 - case close_code::reserved2: // 1014 - case close_code::reserved3: // 1015 - return false; - } - // reserved - if(v >= 1016 && v <= 2999) - return false; - // not used - if(v <= 999) - return false; - return true; -} - -//------------------------------------------------------------------------------ - -// Write frame header to dynamic buffer -// -template -void -write(DynamicBuffer& db, frame_header const& fh) -{ - using boost::asio::buffer; - using boost::asio::buffer_copy; - using namespace boost::endian; - std::size_t n; - std::uint8_t b[14]; - b[0] = (fh.fin ? 0x80 : 0x00) | static_cast(fh.op); - if(fh.rsv1) - b[0] |= 0x40; - if(fh.rsv2) - b[0] |= 0x20; - if(fh.rsv3) - b[0] |= 0x10; - b[1] = fh.mask ? 0x80 : 0x00; - if(fh.len <= 125) - { - b[1] |= fh.len; - n = 2; - } - else if(fh.len <= 65535) - { - b[1] |= 126; - ::new(&b[2]) big_uint16_buf_t{ - (std::uint16_t)fh.len}; - n = 4; - } - else - { - b[1] |= 127; - ::new(&b[2]) big_uint64_buf_t{fh.len}; - n = 10; - } - if(fh.mask) - { - native_to_little_uint32(fh.key, &b[n]); - n += 4; - } - db.commit(buffer_copy( - db.prepare(n), buffer(b))); -} - -// Read data from buffers -// This is for ping and pong payloads -// -template -void -read(ping_data& data, Buffers const& bs) -{ - using boost::asio::buffer_copy; - using boost::asio::buffer_size; - using boost::asio::mutable_buffers_1; - BOOST_ASSERT(buffer_size(bs) <= data.max_size()); - data.resize(buffer_size(bs)); - buffer_copy(mutable_buffers_1{ - data.data(), data.size()}, bs); -} - -// Read close_reason, return true on success -// This is for the close payload -// -template -void -read(close_reason& cr, - Buffers const& bs, close_code& code) -{ - using boost::asio::buffer; - using boost::asio::buffer_copy; - using boost::asio::buffer_size; - using namespace boost::endian; - auto n = buffer_size(bs); - BOOST_ASSERT(n <= 125); - if(n == 0) - { - cr = close_reason{}; - code = close_code::none; - return; - } - if(n == 1) - { - code = close_code::protocol_error; - return; - } - consuming_buffers cb(bs); - { - std::uint8_t b[2]; - buffer_copy(buffer(b), cb); - cr.code = big_uint16_to_native(&b[0]); - cb.consume(2); - n -= 2; - if(! is_valid_close_code(cr.code)) - { - code = close_code::protocol_error; - return; - } - } - if(n > 0) - { - cr.reason.resize(n); - buffer_copy(buffer(&cr.reason[0], n), cb); - if(! detail::check_utf8( - cr.reason.data(), cr.reason.size())) - { - code = close_code::protocol_error; - return; - } - } - else - { - cr.reason = ""; - } - code = close_code::none; -} - -} // detail -} // websocket -} // beast - -#endif diff --git a/src/beast/include/beast/websocket/detail/hybi13.hpp b/src/beast/include/beast/websocket/detail/hybi13.hpp deleted file mode 100644 index ccfd8854f54..00000000000 --- a/src/beast/include/beast/websocket/detail/hybi13.hpp +++ /dev/null @@ -1,71 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_WEBSOCKET_DETAIL_HYBI13_HPP -#define BEAST_WEBSOCKET_DETAIL_HYBI13_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace websocket { -namespace detail { - -using sec_ws_key_type = static_string< - beast::detail::base64::encoded_size(16)>; - -using sec_ws_accept_type = static_string< - beast::detail::base64::encoded_size(20)>; - -template -void -make_sec_ws_key(sec_ws_key_type& key, Gen& g) -{ - char a[16]; - for(int i = 0; i < 16; i += 4) - { - auto const v = g(); - a[i ] = v & 0xff; - a[i+1] = (v >> 8) & 0xff; - a[i+2] = (v >> 16) & 0xff; - a[i+3] = (v >> 24) & 0xff; - } - key.resize(key.max_size()); - key.resize(beast::detail::base64::encode( - key.data(), &a[0], 16)); -} - -template -void -make_sec_ws_accept(sec_ws_accept_type& accept, - string_view key) -{ - BOOST_ASSERT(key.size() <= sec_ws_key_type::max_size_n); - static_string m(key); - m.append("258EAFA5-E914-47DA-95CA-C5AB0DC85B11"); - beast::detail::sha1_context ctx; - beast::detail::init(ctx); - beast::detail::update(ctx, m.data(), m.size()); - char digest[beast::detail::sha1_context::digest_size]; - beast::detail::finish(ctx, &digest[0]); - accept.resize(accept.max_size()); - accept.resize(beast::detail::base64::encode( - accept.data(), &digest[0], sizeof(digest))); -} - -} // detail -} // websocket -} // beast - -#endif diff --git a/src/beast/include/beast/websocket/detail/mask.hpp b/src/beast/include/beast/websocket/detail/mask.hpp deleted file mode 100644 index 27a3a155a27..00000000000 --- a/src/beast/include/beast/websocket/detail/mask.hpp +++ /dev/null @@ -1,265 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_WEBSOCKET_DETAIL_MASK_HPP -#define BEAST_WEBSOCKET_DETAIL_MASK_HPP - -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace websocket { -namespace detail { - -// Pseudo-random source of mask keys -// -template -class maskgen_t -{ - Generator g_; - -public: - using result_type = - typename Generator::result_type; - - maskgen_t(); - - result_type - operator()() noexcept; - - void - rekey(); -}; - -template -maskgen_t::maskgen_t() -{ - rekey(); -} - -template -auto -maskgen_t::operator()() noexcept -> - result_type -{ - for(;;) - if(auto key = g_()) - return key; -} - -template -void -maskgen_t<_>::rekey() -{ - std::random_device rng; -#if 0 - std::array e; - for(auto& i : e) - i = rng(); - // VFALCO This constructor causes - // address sanitizer to fail, no idea why. - std::seed_seq ss(e.begin(), e.end()); - g_.seed(ss); -#else - g_.seed(rng()); -#endif -} - -// VFALCO NOTE This generator has 5KB of state! -//using maskgen = maskgen_t; -using maskgen = maskgen_t; - -//------------------------------------------------------------------------------ - -using prepared_key = - std::conditional::type; - -inline -void -prepare_key(std::uint32_t& prepared, std::uint32_t key) -{ - prepared = key; -} - -inline -void -prepare_key(std::uint64_t& prepared, std::uint32_t key) -{ - prepared = - (static_cast(key) << 32) | key; -} - -template -inline -typename std::enable_if::value, T>::type -ror(T t, unsigned n = 1) -{ - auto constexpr bits = - static_cast( - sizeof(T) * CHAR_BIT); - n &= bits-1; - return static_cast((t << (bits - n)) | ( - static_cast::type>(t) >> n)); -} - -// 32-bit optimized -// -template -void -mask_inplace_fast( - boost::asio::mutable_buffer const& b, - std::uint32_t& key) -{ - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - auto n = buffer_size(b); - auto p = buffer_cast(b); - if(n >= sizeof(key)) - { - // Bring p to 4-byte alignment - auto const i = reinterpret_cast< - std::uintptr_t>(p) & (sizeof(key)-1); - switch(i) - { - case 1: p[2] ^= static_cast(key >> 16); - case 2: p[1] ^= static_cast(key >> 8); - case 3: p[0] ^= static_cast(key); - { - auto const d = static_cast< - unsigned>(sizeof(key) - i); - key = ror(key, 8*d); - n -= d; - p += d; - } - default: - break; - } - } - - // Mask 4 bytes at a time - for(auto i = n / sizeof(key); i; --i) - { - *reinterpret_cast< - std::uint32_t*>(p) ^= key; - p += sizeof(key); - } - - // Leftovers - n &= sizeof(key)-1; - switch(n) - { - case 3: p[2] ^= static_cast(key >> 16); - case 2: p[1] ^= static_cast(key >> 8); - case 1: p[0] ^= static_cast(key); - key = ror(key, static_cast(8*n)); - default: - break; - } -} - -// 64-bit optimized -// -template -void -mask_inplace_fast( - boost::asio::mutable_buffer const& b, - std::uint64_t& key) -{ - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - auto n = buffer_size(b); - auto p = buffer_cast(b); - if(n >= sizeof(key)) - { - // Bring p to 8-byte alignment - auto const i = reinterpret_cast< - std::uintptr_t>(p) & (sizeof(key)-1); - switch(i) - { - case 1: p[6] ^= static_cast(key >> 48); - case 2: p[5] ^= static_cast(key >> 40); - case 3: p[4] ^= static_cast(key >> 32); - case 4: p[3] ^= static_cast(key >> 24); - case 5: p[2] ^= static_cast(key >> 16); - case 6: p[1] ^= static_cast(key >> 8); - case 7: p[0] ^= static_cast(key); - { - auto const d = static_cast< - unsigned>(sizeof(key) - i); - key = ror(key, 8*d); - n -= d; - p += d; - } - default: - break; - } - } - - // Mask 8 bytes at a time - for(auto i = n / sizeof(key); i; --i) - { - *reinterpret_cast< - std::uint64_t*>(p) ^= key; - p += sizeof(key); - } - - // Leftovers - n &= sizeof(key)-1; - switch(n) - { - case 7: p[6] ^= static_cast(key >> 48); - case 6: p[5] ^= static_cast(key >> 40); - case 5: p[4] ^= static_cast(key >> 32); - case 4: p[3] ^= static_cast(key >> 24); - case 3: p[2] ^= static_cast(key >> 16); - case 2: p[1] ^= static_cast(key >> 8); - case 1: p[0] ^= static_cast(key); - key = ror(key, static_cast(8*n)); - default: - break; - } -} - -inline -void -mask_inplace( - boost::asio::mutable_buffer const& b, - std::uint32_t& key) -{ - mask_inplace_fast(b, key); -} - -inline -void -mask_inplace( - boost::asio::mutable_buffer const& b, - std::uint64_t& key) -{ - mask_inplace_fast(b, key); -} - -// Apply mask in place -// -template -void -mask_inplace( - MutableBuffers const& bs, KeyType& key) -{ - for(boost::asio::mutable_buffer b : bs) - mask_inplace(b, key); -} - -} // detail -} // websocket -} // beast - -#endif diff --git a/src/beast/include/beast/websocket/detail/pausation.hpp b/src/beast/include/beast/websocket/detail/pausation.hpp deleted file mode 100644 index 53a99884a3f..00000000000 --- a/src/beast/include/beast/websocket/detail/pausation.hpp +++ /dev/null @@ -1,157 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_WEBSOCKET_DETAIL_PAUSATION_HPP -#define BEAST_WEBSOCKET_DETAIL_PAUSATION_HPP - -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace websocket { -namespace detail { - -// A container that holds a suspended, asynchronous composed -// operation. The contained object may be invoked later to -// resume the operation, or the container may be destroyed. -// -class pausation -{ - struct base - { - base() = default; - base(base &&) = default; - virtual ~base() = default; - virtual base* move(void* p) = 0; - virtual void operator()() = 0; - }; - - template - struct holder : base - { - F f; - - holder(holder&&) = default; - - template - explicit - holder(U&& u) - : f(std::forward(u)) - { - } - - base* - move(void* p) override - { - return ::new(p) holder(std::move(*this)); - } - - void - operator()() override - { - F f_(std::move(f)); - this->~holder(); - // invocation of f_() can - // assign a new object to *this. - f_(); - } - }; - - struct exemplar - { - struct H - { - void operator()(); - }; - - struct T - { - using handler_type = H; - }; - - handler_ptr hp; - - void operator()(); - }; - - using buf_type = char[sizeof(holder)]; - - base* base_ = nullptr; - alignas(holder) buf_type buf_; - -public: - ~pausation() - { - if(base_) - base_->~base(); - } - - pausation() = default; - - pausation(pausation&& other) - { - if(other.base_) - { - base_ = other.base_->move(buf_); - other.base_ = nullptr; - } - } - - pausation& - operator=(pausation&& other) - { - // Engaged pausations must be invoked before - // assignment otherwise the io_service - // completion invariants are broken. - BOOST_ASSERT(! base_); - - if(other.base_) - { - base_ = other.base_->move(buf_); - other.base_ = nullptr; - } - return *this; - } - - template - void - emplace(F&& f); - - bool - maybe_invoke() - { - if(base_) - { - auto const basep = base_; - base_ = nullptr; - (*basep)(); - return true; - } - return false; - } -}; - -template -void -pausation::emplace(F&& f) -{ - using type = holder::type>; - static_assert(sizeof(buf_type) >= sizeof(type), - "buffer too small"); - BOOST_ASSERT(! base_); - base_ = ::new(buf_) type{std::forward(f)}; -} - -} // detail -} // websocket -} // beast - -#endif diff --git a/src/beast/include/beast/websocket/detail/pmd_extension.hpp b/src/beast/include/beast/websocket/detail/pmd_extension.hpp deleted file mode 100644 index ac1a5a91cf2..00000000000 --- a/src/beast/include/beast/websocket/detail/pmd_extension.hpp +++ /dev/null @@ -1,474 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_WEBSOCKET_DETAIL_PMD_EXTENSION_HPP -#define BEAST_WEBSOCKET_DETAIL_PMD_EXTENSION_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace websocket { -namespace detail { - -// permessage-deflate offer parameters -// -// "context takeover" means: -// preserve sliding window across messages -// -struct pmd_offer -{ - bool accept; - - // 0 = absent, or 8..15 - int server_max_window_bits; - - // -1 = present, 0 = absent, or 8..15 - int client_max_window_bits; - - // `true` if server_no_context_takeover offered - bool server_no_context_takeover; - - // `true` if client_no_context_takeover offered - bool client_no_context_takeover; -}; - -template -int -parse_bits(string_view s) -{ - if(s.size() == 0) - return -1; - if(s.size() > 2) - return -1; - if(s[0] < '1' || s[0] > '9') - return -1; - int i = 0; - for(auto c : s) - { - if(c < '0' || c > '9') - return -1; - i = 10 * i + (c - '0'); - } - return i; -} - -// Parse permessage-deflate request fields -// -template -void -pmd_read(pmd_offer& offer, - http::basic_fields const& fields) -{ - offer.accept = false; - offer.server_max_window_bits= 0; - offer.client_max_window_bits = 0; - offer.server_no_context_takeover = false; - offer.client_no_context_takeover = false; - - http::ext_list list{ - fields["Sec-WebSocket-Extensions"]}; - for(auto const& ext : list) - { - if(iequals(ext.first, "permessage-deflate")) - { - for(auto const& param : ext.second) - { - if(iequals(param.first, - "server_max_window_bits")) - { - if(offer.server_max_window_bits != 0) - { - // The negotiation offer contains multiple - // extension parameters with the same name. - // - return; // MUST decline - } - if(param.second.empty()) - { - // The negotiation offer extension - // parameter is missing the value. - // - return; // MUST decline - } - offer.server_max_window_bits = - parse_bits(param.second); - if( offer.server_max_window_bits < 8 || - offer.server_max_window_bits > 15) - { - // The negotiation offer contains an - // extension parameter with an invalid value. - // - return; // MUST decline - } - } - else if(iequals(param.first, - "client_max_window_bits")) - { - if(offer.client_max_window_bits != 0) - { - // The negotiation offer contains multiple - // extension parameters with the same name. - // - return; // MUST decline - } - if(! param.second.empty()) - { - offer.client_max_window_bits = - parse_bits(param.second); - if( offer.client_max_window_bits < 8 || - offer.client_max_window_bits > 15) - { - // The negotiation offer contains an - // extension parameter with an invalid value. - // - return; // MUST decline - } - } - else - { - offer.client_max_window_bits = -1; - } - } - else if(iequals(param.first, - "server_no_context_takeover")) - { - if(offer.server_no_context_takeover) - { - // The negotiation offer contains multiple - // extension parameters with the same name. - // - return; // MUST decline - } - if(! param.second.empty()) - { - // The negotiation offer contains an - // extension parameter with an invalid value. - // - return; // MUST decline - } - offer.server_no_context_takeover = true; - } - else if(iequals(param.first, - "client_no_context_takeover")) - { - if(offer.client_no_context_takeover) - { - // The negotiation offer contains multiple - // extension parameters with the same name. - // - return; // MUST decline - } - if(! param.second.empty()) - { - // The negotiation offer contains an - // extension parameter with an invalid value. - // - return; // MUST decline - } - offer.client_no_context_takeover = true; - } - else - { - // The negotiation offer contains an extension - // parameter not defined for use in an offer. - // - return; // MUST decline - } - } - offer.accept = true; - return; - } - } -} - -// Set permessage-deflate fields for a client offer -// -template -void -pmd_write(http::basic_fields& fields, - pmd_offer const& offer) -{ - static_string<512> s; - s = "permessage-deflate"; - if(offer.server_max_window_bits != 0) - { - if(offer.server_max_window_bits != -1) - { - s += "; server_max_window_bits="; - s += to_static_string( - offer.server_max_window_bits); - } - else - { - s += "; server_max_window_bits"; - } - } - if(offer.client_max_window_bits != 0) - { - if(offer.client_max_window_bits != -1) - { - s += "; client_max_window_bits="; - s += to_static_string( - offer.client_max_window_bits); - } - else - { - s += "; client_max_window_bits"; - } - } - if(offer.server_no_context_takeover) - { - s += "; server_no_context_takeover"; - } - if(offer.client_no_context_takeover) - { - s += "; client_no_context_takeover"; - } - fields.set(http::field::sec_websocket_extensions, s); -} - -// Negotiate a permessage-deflate client offer -// -template -void -pmd_negotiate( - http::basic_fields& fields, - pmd_offer& config, - pmd_offer const& offer, - permessage_deflate const& o) -{ - if(! (offer.accept && o.server_enable)) - { - config.accept = false; - return; - } - config.accept = true; - - static_string<512> s = "permessage-deflate"; - - config.server_no_context_takeover = - offer.server_no_context_takeover || - o.server_no_context_takeover; - if(config.server_no_context_takeover) - s += "; server_no_context_takeover"; - - config.client_no_context_takeover = - o.client_no_context_takeover || - offer.client_no_context_takeover; - if(config.client_no_context_takeover) - s += "; client_no_context_takeover"; - - if(offer.server_max_window_bits != 0) - config.server_max_window_bits = std::min( - offer.server_max_window_bits, - o.server_max_window_bits); - else - config.server_max_window_bits = - o.server_max_window_bits; - if(config.server_max_window_bits < 15) - { - // ZLib's deflateInit silently treats 8 as - // 9 due to a bug, so prevent 8 from being used. - // - if(config.server_max_window_bits < 9) - config.server_max_window_bits = 9; - - s += "; server_max_window_bits="; - s += to_static_string( - config.server_max_window_bits); - } - - switch(offer.client_max_window_bits) - { - case -1: - // extension parameter is present with no value - config.client_max_window_bits = - o.client_max_window_bits; - if(config.client_max_window_bits < 15) - { - s += "; client_max_window_bits="; - s += to_static_string( - config.client_max_window_bits); - } - break; - - case 0: - /* extension parameter is absent. - - If a received extension negotiation offer doesn't have the - "client_max_window_bits" extension parameter, the corresponding - extension negotiation response to the offer MUST NOT include the - "client_max_window_bits" extension parameter. - */ - if(o.client_max_window_bits == 15) - config.client_max_window_bits = 15; - else - config.accept = false; - break; - - default: - // extension parameter has value in [8..15] - config.client_max_window_bits = std::min( - o.client_max_window_bits, - offer.client_max_window_bits); - s += "; client_max_window_bits="; - s += to_static_string( - config.client_max_window_bits); - break; - } - if(config.accept) - fields.set(http::field::sec_websocket_extensions, s); -} - -// Normalize the server's response -// -inline -void -pmd_normalize(pmd_offer& offer) -{ - if(offer.accept) - { - if( offer.server_max_window_bits == 0) - offer.server_max_window_bits = 15; - - if( offer.client_max_window_bits == 0 || - offer.client_max_window_bits == -1) - offer.client_max_window_bits = 15; - } -} - -//-------------------------------------------------------------------- - -// Decompress into a DynamicBuffer -// -template -void -inflate( - InflateStream& zi, - DynamicBuffer& buffer, - boost::asio::const_buffer const& in, - error_code& ec) -{ - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - zlib::z_params zs; - zs.avail_in = buffer_size(in); - zs.next_in = buffer_cast(in); - for(;;) - { - // VFALCO we could be smarter about the size - auto const bs = buffer.prepare( - read_size_or_throw(buffer, 65536)); - auto const out = *bs.begin(); - zs.avail_out = buffer_size(out); - zs.next_out = buffer_cast(out); - zi.write(zs, zlib::Flush::sync, ec); - buffer.commit(zs.total_out); - zs.total_out = 0; - if( ec == zlib::error::need_buffers || - ec == zlib::error::end_of_stream) - { - ec.assign(0, ec.category()); - break; - } - if(ec) - return; - } -} - -// Compress a buffer sequence -// Returns: `true` if more calls are needed -// -template -bool -deflate( - DeflateStream& zo, - boost::asio::mutable_buffer& out, - consuming_buffers& cb, - bool fin, - error_code& ec) -{ - using boost::asio::buffer; - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - BOOST_ASSERT(buffer_size(out) >= 6); - zlib::z_params zs; - zs.avail_in = 0; - zs.next_in = nullptr; - zs.avail_out = buffer_size(out); - zs.next_out = buffer_cast(out); - for(boost::asio::const_buffer in : cb) - { - zs.avail_in = buffer_size(in); - if(zs.avail_in == 0) - continue; - zs.next_in = buffer_cast(in); - zo.write(zs, zlib::Flush::none, ec); - if(ec) - { - if(ec != zlib::error::need_buffers) - return false; - BOOST_ASSERT(zs.avail_out == 0); - BOOST_ASSERT(zs.total_out == buffer_size(out)); - ec.assign(0, ec.category()); - break; - } - if(zs.avail_out == 0) - { - BOOST_ASSERT(zs.total_out == buffer_size(out)); - break; - } - BOOST_ASSERT(zs.avail_in == 0); - } - cb.consume(zs.total_in); - if(zs.avail_out > 0 && fin) - { - auto const remain = buffer_size(cb); - if(remain == 0) - { - // Inspired by Mark Adler - // https://github.com/madler/zlib/issues/149 - // - // VFALCO We could do this flush twice depending - // on how much space is in the output. - zo.write(zs, zlib::Flush::block, ec); - BOOST_ASSERT(! ec || ec == zlib::error::need_buffers); - if(ec == zlib::error::need_buffers) - ec.assign(0, ec.category()); - if(ec) - return false; - if(zs.avail_out >= 6) - { - zo.write(zs, zlib::Flush::full, ec); - BOOST_ASSERT(! ec); - // remove flush marker - zs.total_out -= 4; - out = buffer( - buffer_cast(out), zs.total_out); - return false; - } - } - } - ec.assign(0, ec.category()); - out = buffer( - buffer_cast(out), zs.total_out); - return true; -} - -} // detail -} // websocket -} // beast - -#endif diff --git a/src/beast/include/beast/websocket/detail/type_traits.hpp b/src/beast/include/beast/websocket/detail/type_traits.hpp deleted file mode 100644 index 7f3481f19d5..00000000000 --- a/src/beast/include/beast/websocket/detail/type_traits.hpp +++ /dev/null @@ -1,32 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_WEBSOCKET_DETAIL_TYPE_TRAITS_HPP -#define BEAST_WEBSOCKET_DETAIL_TYPE_TRAITS_HPP - -#include -#include - -namespace beast { -namespace websocket { -namespace detail { - -template -using is_RequestDecorator = - typename beast::detail::is_invocable::type; - -template -using is_ResponseDecorator = - typename beast::detail::is_invocable::type; - -} // detail -} // websocket -} // beast - -#endif diff --git a/src/beast/include/beast/websocket/detail/utf8_checker.hpp b/src/beast/include/beast/websocket/detail/utf8_checker.hpp deleted file mode 100644 index cbd9b70c694..00000000000 --- a/src/beast/include/beast/websocket/detail/utf8_checker.hpp +++ /dev/null @@ -1,348 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_WEBSOCKET_DETAIL_UTF8_CHECKER_HPP -#define BEAST_WEBSOCKET_DETAIL_UTF8_CHECKER_HPP - -#include -#include -#include -#include -#include - -namespace beast { -namespace websocket { -namespace detail { - -/* This is a modified work. - - Original version and license: - https://www.cl.cam.ac.uk/~mgk25/ucs/utf8_check.c - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject - to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR - ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * - - Additional changes: - Optimized for predominantly 7-bit content, 2016 - https://github.com/uWebSockets/uWebSockets/blob/755bd362649c06abff102f18e273c5792c51c1a0/src/WebSocketProtocol.h#L198 - Copyright (c) 2016 Alex Hultman and contributors - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgement in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -/** A UTF8 validator. - - This validator can be used to check if a buffer containing UTF8 text is - valid. The write function may be called incrementally with segmented UTF8 - sequences. The finish function determines if all processed text is valid. -*/ -template -class utf8_checker_t -{ - std::size_t need_ = 0; - std::uint8_t* p_ = have_; - std::uint8_t have_[4]; - -public: - /** Prepare to process text as valid utf8 - */ - void - reset(); - - /** Check that all processed text is valid utf8 - */ - bool - finish(); - - /** Check if text is valid UTF8 - - @return `true` if the text is valid utf8 or false otherwise. - */ - bool - write(std::uint8_t const* in, std::size_t size); - - /** Check if text is valid UTF8 - - @return `true` if the text is valid utf8 or false otherwise. - */ - template - bool - write(ConstBufferSequence const& bs); -}; - -template -void -utf8_checker_t<_>:: -reset() -{ - need_ = 0; - p_ = have_; -} - -template -bool -utf8_checker_t<_>:: -finish() -{ - auto const success = need_ == 0; - reset(); - return success; -} - -template -template -bool -utf8_checker_t<_>:: -write(ConstBufferSequence const& bs) -{ - static_assert(is_const_buffer_sequence::value, - "ConstBufferSequence requirements not met"); - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - for(boost::asio::const_buffer b : bs) - if(! write(buffer_cast(b), - buffer_size(b))) - return false; - return true; -} - -template -bool -utf8_checker_t<_>:: -write(std::uint8_t const* in, std::size_t size) -{ - auto const valid = - [](std::uint8_t const*& p) - { - if (p[0] < 128) - { - ++p; - return true; - } - if ((p[0] & 0x60) == 0x40) - { - if ((p[1] & 0xc0) != 0x80) - return false; - p += 2; - return true; - } - if ((p[0] & 0xf0) == 0xe0) - { - if ((p[1] & 0xc0) != 0x80 || - (p[2] & 0xc0) != 0x80 || - (p[0] == 224 && p[1] < 160) || - (p[0] == 237 && p[1] > 159)) - return false; - p += 3; - return true; - } - if ((p[0] & 0xf8) == 0xf0) - { - if (p[0] > 244 || - (p[1] & 0xc0) != 0x80 || - (p[2] & 0xc0) != 0x80 || - (p[3] & 0xc0) != 0x80 || - (p[0] == 240 && p[1] < 144) || - (p[0] == 244 && p[1] > 143)) - return false; - p += 4; - return true; - } - return false; - }; - auto const valid_have = - [&]() - { - if ((have_[0] & 0x60) == 0x40) - return have_[0] <= 223; - if ((have_[0] & 0xf0) == 0xe0) - { - if (p_ - have_ > 1 && - ((have_[1] & 0xc0) != 0x80 || - (have_[0] == 224 && have_[1] < 160) || - (have_[0] == 237 && have_[1] > 159))) - return false; - return true; - } - if ((have_[0] & 0xf8) == 0xf0) - { - auto const n = p_ - have_; - if (n > 2 && (have_[2] & 0xc0) != 0x80) - return false; - if (n > 1 && - ((have_[1] & 0xc0) != 0x80 || - (have_[0] == 240 && have_[1] < 144) || - (have_[0] == 244 && have_[1] > 143))) - return false; - } - return true; - }; - auto const needed = - [](std::uint8_t const v) - { - if (v < 128) - return 1; - if (v < 194) - return 0; - if (v < 224) - return 2; - if (v < 240) - return 3; - if (v < 245) - return 4; - return 0; - }; - - auto const end = in + size; - if (need_ > 0) - { - auto n = (std::min)(size, need_); - size -= n; - need_ -= n; - while(n--) - *p_++ = *in++; - if(need_ > 0) - { - BOOST_ASSERT(in == end); - return valid_have(); - } - std::uint8_t const* p = &have_[0]; - if (! valid(p)) - return false; - p_ = have_; - } - - if(size <= sizeof(std::size_t)) - goto slow; - - // align in to sizeof(std::size_t) boundary - { - auto const in0 = in; - auto last = reinterpret_cast( - ((reinterpret_cast(in) + sizeof(std::size_t) - 1) / - sizeof(std::size_t)) * sizeof(std::size_t)); - while(in < last) - { - if(*in & 0x80) - { - size = size - (in - in0); - goto slow; - } - ++in; - } - size = size - (in - in0); - } - - // fast loop - { - auto const in0 = in; - auto last = in + size - 7; - auto constexpr mask = static_cast< - std::size_t>(0x8080808080808080 & ~std::size_t{0}); - while(in < last) - { -#if 0 - std::size_t temp; - std::memcpy(&temp, in, sizeof(temp)); - if((temp & mask) != 0) -#else - // Technically UB but works on all known platforms - if((*reinterpret_cast(in) & mask) != 0) -#endif - { - size = size - (in - in0); - goto slow; - } - in += sizeof(std::size_t); - } - last += 4; - while(in < last) - if(! valid(in)) - return false; - goto tail; - } - - // slow loop: one code point at a time -slow: - { - auto last = in + size - 3; - while(in < last) - if(! valid(in)) - return false; - } - -tail: - for(;;) - { - auto n = end - in; - if(! n) - break; - auto const need = needed(*in); - if (need == 0) - return false; - if(need <= n) - { - if(! valid(in)) - return false; - } - else - { - need_ = need - n; - while(n--) - *p_++ = *in++; - return valid_have(); - } - } - return true; -} - -using utf8_checker = utf8_checker_t<>; - -template -bool -check_utf8(char const* p, std::size_t n) -{ - utf8_checker c; - if(! c.write(reinterpret_cast(p), n)) - return false; - return c.finish(); -} - -} // detail -} // websocket -} // beast - -#endif diff --git a/src/beast/include/beast/websocket/error.hpp b/src/beast/include/beast/websocket/error.hpp deleted file mode 100644 index e36a37fa06f..00000000000 --- a/src/beast/include/beast/websocket/error.hpp +++ /dev/null @@ -1,35 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_WEBSOCKET_ERROR_HPP -#define BEAST_WEBSOCKET_ERROR_HPP - -#include -#include - -namespace beast { -namespace websocket { - -/// Error codes returned from @ref beast::websocket::stream operations. -enum class error -{ - /// Both sides performed a WebSocket close - closed = 1, - - /// WebSocket connection failed, protocol violation - failed, - - /// Upgrade handshake failed - handshake_failed -}; - -} // websocket -} // beast - -#include - -#endif diff --git a/src/beast/include/beast/websocket/impl/accept.ipp b/src/beast/include/beast/websocket/impl/accept.ipp deleted file mode 100644 index 892dcffaee5..00000000000 --- a/src/beast/include/beast/websocket/impl/accept.ipp +++ /dev/null @@ -1,810 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_WEBSOCKET_IMPL_ACCEPT_IPP -#define BEAST_WEBSOCKET_IMPL_ACCEPT_IPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace websocket { - -//------------------------------------------------------------------------------ - -// Respond to an upgrade HTTP request -template -template -class stream::response_op -{ - struct data - { - bool cont; - stream& ws; - response_type res; - int state = 0; - - template - data(Handler&, stream& ws_, http::header< - true, http::basic_fields> const& req, - Decorator const& decorator, - bool cont_) - : cont(cont_) - , ws(ws_) - , res(ws_.build_response(req, decorator)) - { - } - - template - data(Handler&, stream& ws_, http::header< - true, http::basic_fields> const& req, - Buffers const& buffers, - Decorator const& decorator, - bool cont_) - : cont(cont_) - , ws(ws_) - , res(ws_.build_response(req, decorator)) - { - using boost::asio::buffer_copy; - using boost::asio::buffer_size; - // VFALCO What about catch(std::length_error const&)? - ws.stream_.buffer().commit(buffer_copy( - ws.stream_.buffer().prepare( - buffer_size(buffers)), buffers)); - } - }; - - handler_ptr d_; - -public: - response_op(response_op&&) = default; - response_op(response_op const&) = default; - - template - response_op(DeducedHandler&& h, - stream& ws, Args&&... args) - : d_(std::forward(h), - ws, std::forward(args)...) - { - (*this)(error_code{}, false); - } - - void operator()( - error_code ec, bool again = true); - - friend - void* asio_handler_allocate( - std::size_t size, response_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->d_.handler())); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, response_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->d_.handler())); - } - - friend - bool asio_handler_is_continuation(response_op* op) - { - return op->d_->cont; - } - - template - friend - void asio_handler_invoke(Function&& f, response_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->d_.handler())); - } -}; - -template -template -void -stream::response_op:: -operator()(error_code ec, bool again) -{ - auto& d = *d_; - d.cont = d.cont || again; - while(! ec && d.state != 99) - { - switch(d.state) - { - case 0: - // send response - d.state = 1; - http::async_write(d.ws.next_layer(), - d.res, std::move(*this)); - return; - - // sent response - case 1: - d.state = 99; - if(d.res.result() != - http::status::switching_protocols) - ec = error::handshake_failed; - if(! ec) - { - pmd_read(d.ws.pmd_config_, d.res); - d.ws.open(role_type::server); - } - break; - } - } - d_.invoke(ec); -} - -//------------------------------------------------------------------------------ - -// read and respond to an upgrade request -// -template -template -class stream::accept_op -{ - struct data - { - stream& ws; - Decorator decorator; - http::request_parser p; - - data(Handler&, stream& ws_, - Decorator const& decorator_) - : ws(ws_) - , decorator(decorator_) - { - } - - template - data(Handler&, stream& ws_, - Buffers const& buffers, - Decorator const& decorator_) - : ws(ws_) - , decorator(decorator_) - { - using boost::asio::buffer_copy; - using boost::asio::buffer_size; - // VFALCO What about catch(std::length_error const&)? - ws.stream_.buffer().commit(buffer_copy( - ws.stream_.buffer().prepare( - buffer_size(buffers)), buffers)); - } - }; - - handler_ptr d_; - -public: - accept_op(accept_op&&) = default; - accept_op(accept_op const&) = default; - - template - accept_op(DeducedHandler&& h, - stream& ws, Args&&... args) - : d_(std::forward(h), - ws, std::forward(args)...) - { - } - - void operator()(); - - void operator()(error_code ec); - - friend - void* asio_handler_allocate( - std::size_t size, accept_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->d_.handler())); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, accept_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->d_.handler())); - } - - friend - bool asio_handler_is_continuation(accept_op* op) - { - using boost::asio::asio_handler_is_continuation; - return asio_handler_is_continuation( - std::addressof(op->d_.handler())); - } - - template - friend - void asio_handler_invoke(Function&& f, accept_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->d_.handler())); - } -}; - -template -template -void -stream::accept_op:: -operator()() -{ - auto& d = *d_; - http::async_read_header(d.ws.next_layer(), - d.ws.stream_.buffer(), d.p, - std::move(*this)); -} - -template -template -void -stream::accept_op:: -operator()(error_code ec) -{ - auto& d = *d_; - if(! ec) - { - BOOST_ASSERT(d.p.is_header_done()); - // Arguments from our state must be - // moved to the stack before releasing - // the handler. - auto& ws = d.ws; - auto const req = d.p.release(); - auto const decorator = d.decorator; - #if 1 - response_op{ - d_.release_handler(), - ws, req, decorator, true}; - #else - // VFALCO This *should* work but breaks - // coroutine invariants in the unit test. - // Also it calls reset() when it shouldn't. - ws.async_accept_ex( - req, decorator, d_.release_handler()); - #endif - return; - } - d_.invoke(ec); -} - -//------------------------------------------------------------------------------ - -template -void -stream:: -accept() -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - error_code ec; - accept(ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); -} - -template -template -void -stream:: -accept_ex(ResponseDecorator const& decorator) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - static_assert(detail::is_ResponseDecorator< - ResponseDecorator>::value, - "ResponseDecorator requirements not met"); - error_code ec; - accept_ex(decorator, ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); -} - -template -void -stream:: -accept(error_code& ec) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - reset(); - do_accept(&default_decorate_res, ec); -} - -template -template -void -stream:: -accept_ex(ResponseDecorator const& decorator, error_code& ec) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - static_assert(detail::is_ResponseDecorator< - ResponseDecorator>::value, - "ResponseDecorator requirements not met"); - reset(); - do_accept(decorator, ec); -} - -template -template -typename std::enable_if::value>::type -stream:: -accept(ConstBufferSequence const& buffers) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - static_assert(is_const_buffer_sequence< - ConstBufferSequence>::value, - "ConstBufferSequence requirements not met"); - error_code ec; - accept(buffers, ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); -} - -template -template< - class ConstBufferSequence, class ResponseDecorator> -typename std::enable_if::value>::type -stream:: -accept_ex(ConstBufferSequence const& buffers, - ResponseDecorator const &decorator) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - static_assert(is_const_buffer_sequence< - ConstBufferSequence>::value, - "ConstBufferSequence requirements not met"); - static_assert(detail::is_ResponseDecorator< - ResponseDecorator>::value, - "ResponseDecorator requirements not met"); - error_code ec; - accept_ex(buffers, decorator, ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); -} - -template -template -typename std::enable_if::value>::type -stream:: -accept(ConstBufferSequence const& buffers, error_code& ec) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - static_assert(is_const_buffer_sequence< - ConstBufferSequence>::value, - "ConstBufferSequence requirements not met"); - reset(); - using boost::asio::buffer_copy; - using boost::asio::buffer_size; - stream_.buffer().commit(buffer_copy( - stream_.buffer().prepare( - buffer_size(buffers)), buffers)); - do_accept(&default_decorate_res, ec); -} - -template -template< - class ConstBufferSequence, class ResponseDecorator> -typename std::enable_if::value>::type -stream:: -accept_ex(ConstBufferSequence const& buffers, - ResponseDecorator const& decorator, error_code& ec) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - static_assert(is_const_buffer_sequence< - ConstBufferSequence>::value, - "ConstBufferSequence requirements not met"); - static_assert(is_const_buffer_sequence< - ConstBufferSequence>::value, - "ConstBufferSequence requirements not met"); - reset(); - using boost::asio::buffer_copy; - using boost::asio::buffer_size; - stream_.buffer().commit(buffer_copy( - stream_.buffer().prepare( - buffer_size(buffers)), buffers)); - do_accept(decorator, ec); -} - -template -template -void -stream:: -accept(http::header> const& req) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - error_code ec; - accept(req, ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); -} - -template -template -void -stream:: -accept_ex(http::header> const& req, - ResponseDecorator const& decorator) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - static_assert(detail::is_ResponseDecorator< - ResponseDecorator>::value, - "ResponseDecorator requirements not met"); - error_code ec; - accept_ex(req, decorator, ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); -} - -template -template -void -stream:: -accept(http::header> const& req, - error_code& ec) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - reset(); - do_accept(req, &default_decorate_res, ec); -} - -template -template -void -stream:: -accept_ex(http::header> const& req, - ResponseDecorator const& decorator, error_code& ec) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - static_assert(detail::is_ResponseDecorator< - ResponseDecorator>::value, - "ResponseDecorator requirements not met"); - reset(); - do_accept(req, decorator, ec); -} - -template -template -void -stream:: -accept(http::header> const& req, - ConstBufferSequence const& buffers) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - static_assert(is_const_buffer_sequence< - ConstBufferSequence>::value, - "ConstBufferSequence requirements not met"); - error_code ec; - accept(req, buffers, ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); -} - -template -template -void -stream:: -accept_ex(http::header> const& req, - ConstBufferSequence const& buffers, - ResponseDecorator const& decorator) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - static_assert(is_const_buffer_sequence< - ConstBufferSequence>::value, - "ConstBufferSequence requirements not met"); - static_assert(detail::is_ResponseDecorator< - ResponseDecorator>::value, - "ResponseDecorator requirements not met"); - error_code ec; - accept_ex(req, buffers, decorator, ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); -} - -template -template -void -stream:: -accept(http::header const& req, - ConstBufferSequence const& buffers, error_code& ec) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - static_assert(is_const_buffer_sequence< - ConstBufferSequence>::value, - "ConstBufferSequence requirements not met"); - reset(); - using boost::asio::buffer_copy; - using boost::asio::buffer_size; - stream_.buffer().commit(buffer_copy( - stream_.buffer().prepare( - buffer_size(buffers)), buffers)); - do_accept(req, &default_decorate_res, ec); -} - -template -template -void -stream:: -accept_ex(http::header> const& req, - ConstBufferSequence const& buffers, - ResponseDecorator const& decorator, - error_code& ec) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - static_assert(is_const_buffer_sequence< - ConstBufferSequence>::value, - "ConstBufferSequence requirements not met"); - static_assert(detail::is_ResponseDecorator< - ResponseDecorator>::value, - "ResponseDecorator requirements not met"); - reset(); - using boost::asio::buffer_copy; - using boost::asio::buffer_size; - stream_.buffer().commit(buffer_copy( - stream_.buffer().prepare( - buffer_size(buffers)), buffers)); - do_accept(req, decorator, ec); -} - -//------------------------------------------------------------------------------ - -template -template -async_return_type< - AcceptHandler, void(error_code)> -stream:: -async_accept(AcceptHandler&& handler) -{ - static_assert(is_async_stream::value, - "AsyncStream requirements requirements not met"); - async_completion init{handler}; - reset(); - accept_op>{ - init.completion_handler, *this, &default_decorate_res}(); - return init.result.get(); -} - -template -template -async_return_type< - AcceptHandler, void(error_code)> -stream:: -async_accept_ex(ResponseDecorator const& decorator, - AcceptHandler&& handler) -{ - static_assert(is_async_stream::value, - "AsyncStream requirements requirements not met"); - static_assert(detail::is_ResponseDecorator< - ResponseDecorator>::value, - "ResponseDecorator requirements not met"); - async_completion init{handler}; - reset(); - accept_op>{ - init.completion_handler, *this, decorator}(); - return init.result.get(); -} - -template -template -typename std::enable_if< - ! http::detail::is_header::value, - async_return_type>::type -stream:: -async_accept(ConstBufferSequence const& buffers, - AcceptHandler&& handler) -{ - static_assert(is_async_stream::value, - "AsyncStream requirements requirements not met"); - static_assert(is_const_buffer_sequence< - ConstBufferSequence>::value, - "ConstBufferSequence requirements not met"); - async_completion init{handler}; - reset(); - accept_op>{ - init.completion_handler, *this, buffers, - &default_decorate_res}(); - return init.result.get(); -} - -template -template -typename std::enable_if< - ! http::detail::is_header::value, - async_return_type>::type -stream:: -async_accept_ex(ConstBufferSequence const& buffers, - ResponseDecorator const& decorator, - AcceptHandler&& handler) -{ - static_assert(is_async_stream::value, - "AsyncStream requirements requirements not met"); - static_assert(is_const_buffer_sequence< - ConstBufferSequence>::value, - "ConstBufferSequence requirements not met"); - static_assert(detail::is_ResponseDecorator< - ResponseDecorator>::value, - "ResponseDecorator requirements not met"); - async_completion init{handler}; - reset(); - accept_op>{ - init.completion_handler, *this, buffers, - decorator}(); - return init.result.get(); -} - -template -template -async_return_type< - AcceptHandler, void(error_code)> -stream:: -async_accept(http::header> const& req, - AcceptHandler&& handler) -{ - static_assert(is_async_stream::value, - "AsyncStream requirements requirements not met"); - async_completion init{handler}; - reset(); - using boost::asio::asio_handler_is_continuation; - response_op>{init.completion_handler, - *this, req, &default_decorate_res, - asio_handler_is_continuation( - std::addressof(init.completion_handler))}; - return init.result.get(); -} - -template -template -async_return_type< - AcceptHandler, void(error_code)> -stream:: -async_accept_ex(http::header> const& req, - ResponseDecorator const& decorator, AcceptHandler&& handler) -{ - static_assert(is_async_stream::value, - "AsyncStream requirements requirements not met"); - static_assert(detail::is_ResponseDecorator< - ResponseDecorator>::value, - "ResponseDecorator requirements not met"); - async_completion init{handler}; - reset(); - using boost::asio::asio_handler_is_continuation; - response_op>{ - init.completion_handler, *this, req, decorator, - asio_handler_is_continuation( - std::addressof(init.completion_handler))}; - return init.result.get(); -} - -template -template -async_return_type< - AcceptHandler, void(error_code)> -stream:: -async_accept(http::header> const& req, - ConstBufferSequence const& buffers, - AcceptHandler&& handler) -{ - static_assert(is_async_stream::value, - "AsyncStream requirements requirements not met"); - static_assert(is_const_buffer_sequence< - ConstBufferSequence>::value, - "ConstBufferSequence requirements not met"); - async_completion init{handler}; - reset(); - using boost::asio::asio_handler_is_continuation; - response_op>{ - init.completion_handler, *this, req, buffers, - &default_decorate_res, asio_handler_is_continuation( - std::addressof(init.completion_handler))}; - return init.result.get(); -} - -template -template -async_return_type< - AcceptHandler, void(error_code)> -stream:: -async_accept_ex(http::header> const& req, - ConstBufferSequence const& buffers, - ResponseDecorator const& decorator, - AcceptHandler&& handler) -{ - static_assert(is_async_stream::value, - "AsyncStream requirements requirements not met"); - static_assert(is_const_buffer_sequence< - ConstBufferSequence>::value, - "ConstBufferSequence requirements not met"); - static_assert(detail::is_ResponseDecorator< - ResponseDecorator>::value, - "ResponseDecorator requirements not met"); - async_completion init{handler}; - reset(); - using boost::asio::asio_handler_is_continuation; - response_op>{init.completion_handler, - *this, req, buffers, decorator, asio_handler_is_continuation( - std::addressof(init.completion_handler))}; - return init.result.get(); -} - -} // websocket -} // beast - -#endif diff --git a/src/beast/include/beast/websocket/impl/close.ipp b/src/beast/include/beast/websocket/impl/close.ipp deleted file mode 100644 index add4bd6b65f..00000000000 --- a/src/beast/include/beast/websocket/impl/close.ipp +++ /dev/null @@ -1,240 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_WEBSOCKET_IMPL_CLOSE_IPP -#define BEAST_WEBSOCKET_IMPL_CLOSE_IPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace websocket { - -//------------------------------------------------------------------------------ - -// send the close message and wait for the response -// -template -template -class stream::close_op -{ - struct data : op - { - stream& ws; - close_reason cr; - detail::frame_streambuf fb; - int state = 0; - - data(Handler&, stream& ws_, - close_reason const& cr_) - : ws(ws_) - , cr(cr_) - { - ws.template write_close< - static_buffer>(fb, cr); - } - }; - - handler_ptr d_; - -public: - close_op(close_op&&) = default; - close_op(close_op const&) = default; - - template - close_op(DeducedHandler&& h, - stream& ws, Args&&... args) - : d_(std::forward(h), - ws, std::forward(args)...) - { - } - - void operator()() - { - (*this)({}); - } - - void - operator()(error_code ec, - std::size_t bytes_transferred = 0); - - friend - void* asio_handler_allocate( - std::size_t size, close_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->d_.handler())); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, close_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->d_.handler())); - } - - friend - bool asio_handler_is_continuation(close_op* op) - { - using boost::asio::asio_handler_is_continuation; - return asio_handler_is_continuation( - std::addressof(op->d_.handler())); - } - - template - friend - void asio_handler_invoke(Function&& f, close_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->d_.handler())); - } -}; - -template -template -void -stream::close_op:: -operator()(error_code ec, std::size_t) -{ - auto& d = *d_; - if(ec) - { - BOOST_ASSERT(d.ws.wr_block_ == &d); - d.ws.failed_ = true; - goto upcall; - } - switch(d.state) - { - case 0: - if(d.ws.wr_block_) - { - // suspend - d.state = 1; - d.ws.close_op_.emplace(std::move(*this)); - return; - } - d.ws.wr_block_ = &d; - if(d.ws.failed_ || d.ws.wr_close_) - { - // call handler - d.ws.get_io_service().post( - bind_handler(std::move(*this), - boost::asio::error::operation_aborted)); - return; - } - - do_write: - // send close frame - BOOST_ASSERT(d.ws.wr_block_ == &d); - d.state = 3; - d.ws.wr_close_ = true; - boost::asio::async_write(d.ws.stream_, - d.fb.data(), std::move(*this)); - return; - - case 1: - BOOST_ASSERT(! d.ws.wr_block_); - d.ws.wr_block_ = &d; - d.state = 2; - // The current context is safe but might not be - // the same as the one for this operation (since - // we are being called from a write operation). - // Call post to make sure we are invoked the same - // way as the final handler for this operation. - d.ws.get_io_service().post( - bind_handler(std::move(*this), ec)); - return; - - case 2: - BOOST_ASSERT(d.ws.wr_block_ == &d); - if(d.ws.failed_ || d.ws.wr_close_) - { - // call handler - ec = boost::asio::error::operation_aborted; - goto upcall; - } - goto do_write; - - case 3: - break; - } -upcall: - BOOST_ASSERT(d.ws.wr_block_ == &d); - d.ws.wr_block_ = nullptr; - d.ws.rd_op_.maybe_invoke() || - d.ws.ping_op_.maybe_invoke() || - d.ws.wr_op_.maybe_invoke(); - d_.invoke(ec); -} - -template -template -async_return_type< - CloseHandler, void(error_code)> -stream:: -async_close(close_reason const& cr, CloseHandler&& handler) -{ - static_assert(is_async_stream::value, - "AsyncStream requirements not met"); - async_completion init{handler}; - close_op>{ - init.completion_handler, *this, cr}({}); - return init.result.get(); -} - -template -void -stream:: -close(close_reason const& cr) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - error_code ec; - close(cr, ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); -} - -template -void -stream:: -close(close_reason const& cr, error_code& ec) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - BOOST_ASSERT(! wr_close_); - if(wr_close_) - { - ec = boost::asio::error::operation_aborted; - return; - } - wr_close_ = true; - detail::frame_streambuf fb; - write_close(fb, cr); - boost::asio::write(stream_, fb.data(), ec); - failed_ = !!ec; -} - -//------------------------------------------------------------------------------ - -} // websocket -} // beast - -#endif diff --git a/src/beast/include/beast/websocket/impl/error.ipp b/src/beast/include/beast/websocket/impl/error.ipp deleted file mode 100644 index 96b03585607..00000000000 --- a/src/beast/include/beast/websocket/impl/error.ipp +++ /dev/null @@ -1,93 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_WEBSOCKET_IMPL_ERROR_IPP -#define BEAST_WEBSOCKET_IMPL_ERROR_IPP - -namespace boost { -namespace system { -template<> -struct is_error_code_enum -{ - static bool const value = true; -}; -} // system -} // boost - -namespace beast { -namespace websocket { -namespace detail { - -class websocket_error_category : public error_category -{ -public: - const char* - name() const noexcept override - { - return "beast.websocket"; - } - - std::string - message(int ev) const override - { - switch(static_cast(ev)) - { - case error::closed: return "WebSocket connection closed normally"; - case error::failed: return "WebSocket connection failed due to a protocol violation"; - case error::handshake_failed: return "WebSocket Upgrade handshake failed"; - - default: - return "beast.websocket error"; - } - } - - error_condition - default_error_condition(int ev) const noexcept override - { - return error_condition(ev, *this); - } - - bool - equivalent(int ev, - error_condition const& condition - ) const noexcept override - { - return condition.value() == ev && - &condition.category() == this; - } - - bool - equivalent(error_code const& error, int ev) const noexcept override - { - return error.value() == ev && - &error.category() == this; - } -}; - -inline -error_category const& -get_error_category() -{ - static detail::websocket_error_category const cat{}; - return cat; -} - -} // detail - -inline -error_code -make_error_code(error e) -{ - return error_code( - static_cast::type>(e), - detail::get_error_category()); -} - -} // websocket -} // beast - -#endif diff --git a/src/beast/include/beast/websocket/impl/handshake.ipp b/src/beast/include/beast/websocket/impl/handshake.ipp deleted file mode 100644 index 1231b4a852d..00000000000 --- a/src/beast/include/beast/websocket/impl/handshake.ipp +++ /dev/null @@ -1,394 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_WEBSOCKET_IMPL_HANDSHAKE_IPP -#define BEAST_WEBSOCKET_IMPL_HANDSHAKE_IPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace websocket { - -//------------------------------------------------------------------------------ - -// send the upgrade request and process the response -// -template -template -class stream::handshake_op -{ - struct data - { - bool cont; - stream& ws; - response_type* res_p; - detail::sec_ws_key_type key; - http::request req; - response_type res; - int state = 0; - - template - data(Handler& handler, stream& ws_, - response_type* res_p_, - string_view host, - string_view target, - Decorator const& decorator) - : ws(ws_) - , res_p(res_p_) - , req(ws.build_request(key, - host, target, decorator)) - { - using boost::asio::asio_handler_is_continuation; - cont = asio_handler_is_continuation(std::addressof(handler)); - ws.reset(); - } - }; - - handler_ptr d_; - -public: - handshake_op(handshake_op&&) = default; - handshake_op(handshake_op const&) = default; - - template - handshake_op(DeducedHandler&& h, - stream& ws, Args&&... args) - : d_(std::forward(h), - ws, std::forward(args)...) - { - (*this)(error_code{}, false); - } - - void - operator()(error_code ec, bool again = true); - - friend - void* asio_handler_allocate( - std::size_t size, handshake_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->d_.handler())); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, handshake_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->d_.handler())); - } - - friend - bool asio_handler_is_continuation(handshake_op* op) - { - return op->d_->cont; - } - - template - friend - void asio_handler_invoke(Function&& f, handshake_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->d_.handler())); - } -}; - -template -template -void -stream::handshake_op:: -operator()(error_code ec, bool again) -{ - auto& d = *d_; - d.cont = d.cont || again; - while(! ec && d.state != 99) - { - switch(d.state) - { - case 0: - { - // send http upgrade - d.state = 1; - // VFALCO Do we need the ability to move - // a message on the async_write? - // - pmd_read(d.ws.pmd_config_, d.req); - http::async_write(d.ws.stream_, - d.req, std::move(*this)); - // TODO We don't need d.req now. Figure - // out a way to make it a parameter instead - // of a state variable to reduce footprint. - return; - } - - // sent upgrade - case 1: - // read http response - d.state = 2; - http::async_read(d.ws.next_layer(), - d.ws.stream_.buffer(), d.res, - std::move(*this)); - return; - - // got response - case 2: - { - d.ws.do_response(d.res, d.key, ec); - // call handler - d.state = 99; - break; - } - } - } - if(d.res_p) - swap(d.res, *d.res_p); - d_.invoke(ec); -} - -template -template -async_return_type< - HandshakeHandler, void(error_code)> -stream:: -async_handshake(string_view host, - string_view target, - HandshakeHandler&& handler) -{ - static_assert(is_async_stream::value, - "AsyncStream requirements not met"); - async_completion init{handler}; - handshake_op>{ - init.completion_handler, *this, nullptr, host, - target, &default_decorate_req}; - return init.result.get(); -} - -template -template -async_return_type< - HandshakeHandler, void(error_code)> -stream:: -async_handshake(response_type& res, - string_view host, - string_view target, - HandshakeHandler&& handler) -{ - static_assert(is_async_stream::value, - "AsyncStream requirements not met"); - async_completion init{handler}; - handshake_op>{ - init.completion_handler, *this, &res, host, - target, &default_decorate_req}; - return init.result.get(); -} - -template -template -async_return_type< - HandshakeHandler, void(error_code)> -stream:: -async_handshake_ex(string_view host, - string_view target, - RequestDecorator const& decorator, - HandshakeHandler&& handler) -{ - static_assert(is_async_stream::value, - "AsyncStream requirements not met"); - static_assert(detail::is_RequestDecorator< - RequestDecorator>::value, - "RequestDecorator requirements not met"); - async_completion init{handler}; - handshake_op>{ - init.completion_handler, *this, nullptr, host, - target, decorator}; - return init.result.get(); -} - -template -template -async_return_type< - HandshakeHandler, void(error_code)> -stream:: -async_handshake_ex(response_type& res, - string_view host, - string_view target, - RequestDecorator const& decorator, - HandshakeHandler&& handler) -{ - static_assert(is_async_stream::value, - "AsyncStream requirements not met"); - static_assert(detail::is_RequestDecorator< - RequestDecorator>::value, - "RequestDecorator requirements not met"); - async_completion init{handler}; - handshake_op>{ - init.completion_handler, *this, &res, host, - target, decorator}; - return init.result.get(); -} - -template -void -stream:: -handshake(string_view host, - string_view target) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - error_code ec; - handshake( - host, target, ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); -} - -template -void -stream:: -handshake(response_type& res, - string_view host, - string_view target) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - error_code ec; - handshake(res, host, target, ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); -} - -template -template -void -stream:: -handshake_ex(string_view host, - string_view target, - RequestDecorator const& decorator) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - static_assert(detail::is_RequestDecorator< - RequestDecorator>::value, - "RequestDecorator requirements not met"); - error_code ec; - handshake_ex(host, target, decorator, ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); -} - -template -template -void -stream:: -handshake_ex(response_type& res, - string_view host, - string_view target, - RequestDecorator const& decorator) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - static_assert(detail::is_RequestDecorator< - RequestDecorator>::value, - "RequestDecorator requirements not met"); - error_code ec; - handshake_ex(res, host, target, decorator, ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); -} - -template -void -stream:: -handshake(string_view host, - string_view target, error_code& ec) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - do_handshake(nullptr, - host, target, &default_decorate_req, ec); -} - -template -void -stream:: -handshake(response_type& res, - string_view host, - string_view target, - error_code& ec) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - do_handshake(&res, - host, target, &default_decorate_req, ec); -} - -template -template -void -stream:: -handshake_ex(string_view host, - string_view target, - RequestDecorator const& decorator, - error_code& ec) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - static_assert(detail::is_RequestDecorator< - RequestDecorator>::value, - "RequestDecorator requirements not met"); - do_handshake(nullptr, - host, target, decorator, ec); -} - -template -template -void -stream:: -handshake_ex(response_type& res, - string_view host, - string_view target, - RequestDecorator const& decorator, - error_code& ec) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - static_assert(detail::is_RequestDecorator< - RequestDecorator>::value, - "RequestDecorator requirements not met"); - do_handshake(&res, - host, target, decorator, ec); -} - -//------------------------------------------------------------------------------ - -} // websocket -} // beast - -#endif diff --git a/src/beast/include/beast/websocket/impl/ping.ipp b/src/beast/include/beast/websocket/impl/ping.ipp deleted file mode 100644 index dc37278e3b7..00000000000 --- a/src/beast/include/beast/websocket/impl/ping.ipp +++ /dev/null @@ -1,269 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_WEBSOCKET_IMPL_PING_IPP -#define BEAST_WEBSOCKET_IMPL_PING_IPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace websocket { - -//------------------------------------------------------------------------------ - -// write a ping frame -// -template -template -class stream::ping_op -{ - struct data : op - { - stream& ws; - detail::frame_streambuf fb; - int state = 0; - - data(Handler&, stream& ws_, - detail::opcode op_, ping_data const& payload) - : ws(ws_) - { - using boost::asio::buffer; - using boost::asio::buffer_copy; - ws.template write_ping< - static_buffer>(fb, op_, payload); - } - }; - - handler_ptr d_; - -public: - ping_op(ping_op&&) = default; - ping_op(ping_op const&) = default; - - template - ping_op(DeducedHandler&& h, - stream& ws, Args&&... args) - : d_(std::forward(h), - ws, std::forward(args)...) - { - } - - void operator()() - { - (*this)({}); - } - - void operator()(error_code ec, - std::size_t bytes_transferred = 0); - - friend - void* asio_handler_allocate( - std::size_t size, ping_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->d_.handler())); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, ping_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->d_.handler())); - } - - friend - bool asio_handler_is_continuation(ping_op* op) - { - using boost::asio::asio_handler_is_continuation; - return asio_handler_is_continuation( - std::addressof(op->d_.handler())); - } - - template - friend - void asio_handler_invoke(Function&& f, ping_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->d_.handler())); - } -}; - -template -template -void -stream:: -ping_op:: -operator()(error_code ec, std::size_t) -{ - auto& d = *d_; - if(ec) - { - BOOST_ASSERT(d.ws.wr_block_ == &d); - d.ws.failed_ = true; - goto upcall; - } - switch(d.state) - { - case 0: - if(d.ws.wr_block_) - { - // suspend - d.state = 1; - d.ws.ping_op_.emplace(std::move(*this)); - return; - } - d.ws.wr_block_ = &d; - if(d.ws.failed_ || d.ws.wr_close_) - { - // call handler - return d.ws.get_io_service().post( - bind_handler(std::move(*this), - boost::asio::error::operation_aborted)); - } - - do_write: - // send ping frame - BOOST_ASSERT(d.ws.wr_block_ == &d); - d.state = 3; - boost::asio::async_write(d.ws.stream_, - d.fb.data(), std::move(*this)); - return; - - case 1: - BOOST_ASSERT(! d.ws.wr_block_); - d.ws.wr_block_ = &d; - d.state = 2; - // The current context is safe but might not be - // the same as the one for this operation (since - // we are being called from a write operation). - // Call post to make sure we are invoked the same - // way as the final handler for this operation. - d.ws.get_io_service().post( - bind_handler(std::move(*this), ec)); - return; - - case 2: - BOOST_ASSERT(d.ws.wr_block_ == &d); - if(d.ws.failed_ || d.ws.wr_close_) - { - // call handler - ec = boost::asio::error::operation_aborted; - goto upcall; - } - goto do_write; - - case 3: - break; - } -upcall: - BOOST_ASSERT(d.ws.wr_block_ == &d); - d.ws.wr_block_ = nullptr; - d.ws.close_op_.maybe_invoke() || - d.ws.rd_op_.maybe_invoke() || - d.ws.wr_op_.maybe_invoke(); - d_.invoke(ec); -} - -template -template -async_return_type< - WriteHandler, void(error_code)> -stream:: -async_ping(ping_data const& payload, WriteHandler&& handler) -{ - static_assert(is_async_stream::value, - "AsyncStream requirements requirements not met"); - async_completion init{handler}; - ping_op>{ - init.completion_handler, *this, - detail::opcode::ping, payload}({}); - return init.result.get(); -} - -template -template -async_return_type< - WriteHandler, void(error_code)> -stream:: -async_pong(ping_data const& payload, WriteHandler&& handler) -{ - static_assert(is_async_stream::value, - "AsyncStream requirements requirements not met"); - async_completion init{handler}; - ping_op>{ - init.completion_handler, *this, - detail::opcode::pong, payload}({}); - return init.result.get(); -} - -template -void -stream:: -ping(ping_data const& payload) -{ - error_code ec; - ping(payload, ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); -} - -template -void -stream:: -ping(ping_data const& payload, error_code& ec) -{ - detail::frame_streambuf db; - write_ping( - db, detail::opcode::ping, payload); - boost::asio::write(stream_, db.data(), ec); -} - -template -void -stream:: -pong(ping_data const& payload) -{ - error_code ec; - pong(payload, ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); -} - -template -void -stream:: -pong(ping_data const& payload, error_code& ec) -{ - detail::frame_streambuf db; - write_ping( - db, detail::opcode::pong, payload); - boost::asio::write(stream_, db.data(), ec); -} - -//------------------------------------------------------------------------------ - -} // websocket -} // beast - -#endif diff --git a/src/beast/include/beast/websocket/impl/read.ipp b/src/beast/include/beast/websocket/impl/read.ipp deleted file mode 100644 index ec27dba4f9c..00000000000 --- a/src/beast/include/beast/websocket/impl/read.ipp +++ /dev/null @@ -1,1155 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_WEBSOCKET_IMPL_READ_IPP -#define BEAST_WEBSOCKET_IMPL_READ_IPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace websocket { - -//------------------------------------------------------------------------------ - -// Reads a single message frame, -// processes any received control frames. -// -template -template -class stream::read_frame_op -{ - using fb_type = - detail::frame_streambuf; - - using fmb_type = - typename fb_type::mutable_buffers_type; - - using dmb_type = - typename DynamicBuffer::mutable_buffers_type; - - struct data : op - { - bool cont; - stream& ws; - DynamicBuffer& db; - fb_type fb; - std::uint64_t remain; - detail::frame_header fh; - detail::prepared_key key; - boost::optional dmb; - boost::optional fmb; - int state = 0; - - data(Handler& handler, stream& ws_, - DynamicBuffer& sb_) - : ws(ws_) - , db(sb_) - { - using boost::asio::asio_handler_is_continuation; - cont = asio_handler_is_continuation(std::addressof(handler)); - } - }; - - handler_ptr d_; - -public: - read_frame_op(read_frame_op&&) = default; - read_frame_op(read_frame_op const&) = default; - - template - read_frame_op(DeducedHandler&& h, - stream& ws, Args&&... args) - : d_(std::forward(h), - ws, std::forward(args)...) - { - } - - void operator()() - { - (*this)(error_code{}, 0, true); - } - - void operator()(error_code const& ec) - { - (*this)(ec, 0, true); - } - - void operator()(error_code ec, - std::size_t bytes_transferred); - - void operator()(error_code ec, - std::size_t bytes_transferred, bool again); - - friend - void* asio_handler_allocate( - std::size_t size, read_frame_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->d_.handler())); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, read_frame_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->d_.handler())); - } - - friend - bool asio_handler_is_continuation(read_frame_op* op) - { - return op->d_->cont; - } - - template - friend - void asio_handler_invoke(Function&& f, read_frame_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->d_.handler())); - } -}; - -template -template -void -stream::read_frame_op:: -operator()(error_code ec, std::size_t bytes_transferred) -{ - auto& d = *d_; - if(ec) - d.ws.failed_ = true; - (*this)(ec, bytes_transferred, true); -} - -template -template -void -stream::read_frame_op:: -operator()(error_code ec, - std::size_t bytes_transferred, bool again) -{ - using beast::detail::clamp; - using boost::asio::buffer; - enum - { - do_start = 0, - do_read_payload = 1, - do_inflate_payload = 30, - do_frame_done = 4, - do_read_fh = 5, - do_control_payload = 8, - do_control = 9, - do_pong_resume = 10, - do_ponged = 12, - do_close_resume = 14, - do_teardown = 17, - do_fail = 19, - - do_call_handler = 99 - }; - - auto& d = *d_; - if(d.state == do_teardown + 1 && ec == boost::asio::error::eof) - { - // Rationale: - // http://stackoverflow.com/questions/25587403/boost-asio-ssl-async-shutdown-always-finishes-with-an-error - ec.assign(0, ec.category()); - } - if(! ec) - { - d.cont = d.cont || again; - close_code code = close_code::none; - do - { - switch(d.state) - { - case do_start: - if(d.ws.failed_) - { - d.state = do_call_handler; - d.ws.get_io_service().post( - bind_handler(std::move(*this), - boost::asio::error::operation_aborted, 0)); - return; - } - d.state = do_read_fh; - break; - - //------------------------------------------------------------------ - - case do_read_payload: - if(d.fh.len == 0) - { - d.state = do_frame_done; - break; - } - // Enforce message size limit - if(d.ws.rd_msg_max_ && d.fh.len > - d.ws.rd_msg_max_ - d.ws.rd_.size) - { - code = close_code::too_big; - d.state = do_fail; - break; - } - d.ws.rd_.size += d.fh.len; - d.remain = d.fh.len; - if(d.fh.mask) - detail::prepare_key(d.key, d.fh.key); - BEAST_FALLTHROUGH; - - case do_read_payload + 1: - d.state = do_read_payload + 2; - d.dmb = d.db.prepare(clamp(d.remain)); - // Read frame payload data - d.ws.stream_.async_read_some( - *d.dmb, std::move(*this)); - return; - - case do_read_payload + 2: - { - d.remain -= bytes_transferred; - auto const pb = buffer_prefix( - bytes_transferred, *d.dmb); - if(d.fh.mask) - detail::mask_inplace(pb, d.key); - if(d.ws.rd_.op == detail::opcode::text) - { - if(! d.ws.rd_.utf8.write(pb) || - (d.remain == 0 && d.fh.fin && - ! d.ws.rd_.utf8.finish())) - { - // invalid utf8 - code = close_code::bad_payload; - d.state = do_fail; - break; - } - } - d.db.commit(bytes_transferred); - if(d.remain > 0) - { - d.state = do_read_payload + 1; - break; - } - d.state = do_frame_done; - break; - } - - //------------------------------------------------------------------ - - case do_inflate_payload: - d.remain = d.fh.len; - if(d.fh.len == 0) - { - // inflate even if fh.len == 0, otherwise we - // never emit the end-of-stream deflate block. - bytes_transferred = 0; - d.state = do_inflate_payload + 2; - break; - } - if(d.fh.mask) - detail::prepare_key(d.key, d.fh.key); - // fall through - - case do_inflate_payload + 1: - { - d.state = do_inflate_payload + 2; - // Read compressed frame payload data - d.ws.stream_.async_read_some( - buffer(d.ws.rd_.buf.get(), clamp( - d.remain, d.ws.rd_.buf_size)), - std::move(*this)); - return; - } - - case do_inflate_payload + 2: - { - d.remain -= bytes_transferred; - auto const in = buffer( - d.ws.rd_.buf.get(), bytes_transferred); - if(d.fh.mask) - detail::mask_inplace(in, d.key); - auto const prev = d.db.size(); - detail::inflate(d.ws.pmd_->zi, d.db, in, ec); - d.ws.failed_ = !!ec; - if(d.ws.failed_) - break; - if(d.remain == 0 && d.fh.fin) - { - static std::uint8_t constexpr - empty_block[4] = { - 0x00, 0x00, 0xff, 0xff }; - detail::inflate(d.ws.pmd_->zi, d.db, - buffer(&empty_block[0], 4), ec); - d.ws.failed_ = !!ec; - if(d.ws.failed_) - break; - } - if(d.ws.rd_.op == detail::opcode::text) - { - consuming_buffers cb{d.db.data()}; - cb.consume(prev); - if(! d.ws.rd_.utf8.write(cb) || - (d.remain == 0 && d.fh.fin && - ! d.ws.rd_.utf8.finish())) - { - // invalid utf8 - code = close_code::bad_payload; - d.state = do_fail; - break; - } - } - if(d.remain > 0) - { - d.state = do_inflate_payload + 1; - break; - } - if(d.fh.fin && ( - (d.ws.role_ == role_type::client && - d.ws.pmd_config_.server_no_context_takeover) || - (d.ws.role_ == role_type::server && - d.ws.pmd_config_.client_no_context_takeover))) - d.ws.pmd_->zi.reset(); - d.state = do_frame_done; - break; - } - - //------------------------------------------------------------------ - - case do_frame_done: - goto upcall; - - //------------------------------------------------------------------ - - case do_read_fh: - d.state = do_read_fh + 1; - boost::asio::async_read(d.ws.stream_, - d.fb.prepare(2), std::move(*this)); - return; - - case do_read_fh + 1: - { - d.fb.commit(bytes_transferred); - code = close_code::none; - auto const n = d.ws.read_fh1( - d.fh, d.fb, code); - if(code != close_code::none) - { - // protocol error - d.state = do_fail; - break; - } - d.state = do_read_fh + 2; - if(n == 0) - { - bytes_transferred = 0; - break; - } - // read variable header - boost::asio::async_read(d.ws.stream_, - d.fb.prepare(n), std::move(*this)); - return; - } - - case do_read_fh + 2: - d.fb.commit(bytes_transferred); - code = close_code::none; - d.ws.read_fh2(d.fh, d.fb, code); - if(code != close_code::none) - { - // protocol error - d.state = do_fail; - break; - } - if(detail::is_control(d.fh.op)) - { - if(d.fh.len > 0) - { - // read control payload - d.state = do_control_payload; - d.fmb = d.fb.prepare(static_cast< - std::size_t>(d.fh.len)); - boost::asio::async_read(d.ws.stream_, - *d.fmb, std::move(*this)); - return; - } - d.state = do_control; - break; - } - if(d.fh.op == detail::opcode::text || - d.fh.op == detail::opcode::binary) - d.ws.rd_begin(); - if(d.fh.len == 0 && ! d.fh.fin) - { - // Empty message frame - d.state = do_frame_done; - break; - } - if(! d.ws.pmd_ || ! d.ws.pmd_->rd_set) - d.state = do_read_payload; - else - d.state = do_inflate_payload; - break; - - //------------------------------------------------------------------ - - case do_control_payload: - if(d.fh.mask) - { - detail::prepare_key(d.key, d.fh.key); - detail::mask_inplace(*d.fmb, d.key); - } - d.fb.commit(bytes_transferred); - d.state = do_control; // VFALCO fall through? - break; - - //------------------------------------------------------------------ - - case do_control: - if(d.fh.op == detail::opcode::ping) - { - ping_data payload; - detail::read(payload, d.fb.data()); - d.fb.consume(d.fb.size()); - if(d.ws.ctrl_cb_) - d.ws.ctrl_cb_( - frame_type::ping, payload); - if(d.ws.wr_close_) - { - // ignore ping when closing - d.state = do_read_fh; - break; - } - d.ws.template write_ping( - d.fb, detail::opcode::pong, payload); - if(d.ws.wr_block_) - { - // suspend - BOOST_ASSERT(d.ws.wr_block_ != &d); - d.state = do_pong_resume; - d.ws.rd_op_.emplace(std::move(*this)); - return; - } - d.ws.wr_block_ = &d; - goto go_pong; - } - if(d.fh.op == detail::opcode::pong) - { - code = close_code::none; - ping_data payload; - detail::read(payload, d.fb.data()); - if(d.ws.ctrl_cb_) - d.ws.ctrl_cb_( - frame_type::pong, payload); - d.fb.consume(d.fb.size()); - d.state = do_read_fh; - break; - } - BOOST_ASSERT(d.fh.op == detail::opcode::close); - { - detail::read(d.ws.cr_, d.fb.data(), code); - if(code != close_code::none) - { - // protocol error - d.state = do_fail; - break; - } - if(d.ws.ctrl_cb_) - d.ws.ctrl_cb_(frame_type::close, - d.ws.cr_.reason); - if(! d.ws.wr_close_) - { - auto cr = d.ws.cr_; - if(cr.code == close_code::none) - cr.code = close_code::normal; - cr.reason = ""; - d.fb.consume(d.fb.size()); - d.ws.template write_close< - static_buffer>(d.fb, cr); - if(d.ws.wr_block_) - { - // suspend - BOOST_ASSERT(d.ws.wr_block_ != &d); - d.state = do_close_resume; - d.ws.rd_op_.emplace(std::move(*this)); - return; - } - d.ws.wr_block_ = &d; - goto go_close; - } - d.state = do_teardown; - break; - } - - //------------------------------------------------------------------ - - case do_pong_resume: - BOOST_ASSERT(! d.ws.wr_block_); - d.ws.wr_block_ = &d; - d.state = do_pong_resume + 1; - // The current context is safe but might not be - // the same as the one for this operation (since - // we are being called from a write operation). - // Call post to make sure we are invoked the same - // way as the final handler for this operation. - d.ws.get_io_service().post(bind_handler( - std::move(*this), ec, 0)); - return; - - case do_pong_resume + 1: - BOOST_ASSERT(d.ws.wr_block_ == &d); - if(d.ws.failed_) - { - // call handler - ec = boost::asio::error::operation_aborted; - goto upcall; - } - if(d.ws.wr_close_) - { - // ignore ping when closing - d.ws.wr_block_ = nullptr; - d.fb.consume(d.fb.size()); - d.state = do_read_fh; - break; - } - - //------------------------------------------------------------------ - - go_pong: - // send pong - BOOST_ASSERT(d.ws.wr_block_ == &d); - d.state = do_ponged; - boost::asio::async_write(d.ws.stream_, - d.fb.data(), std::move(*this)); - return; - - case do_ponged: - d.ws.wr_block_ = nullptr; - d.fb.consume(d.fb.size()); - d.state = do_read_fh; - break; - - //------------------------------------------------------------------ - - case do_close_resume: - BOOST_ASSERT(! d.ws.wr_block_); - d.ws.wr_block_ = &d; - d.state = do_close_resume + 1; - // The current context is safe but might not be - // the same as the one for this operation (since - // we are being called from a write operation). - // Call post to make sure we are invoked the same - // way as the final handler for this operation. - d.ws.get_io_service().post(bind_handler( - std::move(*this), ec, bytes_transferred)); - return; - - case do_close_resume + 1: - BOOST_ASSERT(d.ws.wr_block_ == &d); - if(d.ws.failed_) - { - // call handler - ec = boost::asio::error::operation_aborted; - goto upcall; - } - if(d.ws.wr_close_) - { - // already sent a close frame - ec = error::closed; - goto upcall; - } - - //------------------------------------------------------------------ - - go_close: - BOOST_ASSERT(d.ws.wr_block_ == &d); - d.state = do_teardown; - d.ws.wr_close_ = true; - boost::asio::async_write(d.ws.stream_, - d.fb.data(), std::move(*this)); - return; - - //------------------------------------------------------------------ - - case do_teardown: - d.state = do_teardown + 1; - websocket_helpers::call_async_teardown( - d.ws.next_layer(), std::move(*this)); - return; - - case do_teardown + 1: - // call handler - ec = error::closed; - goto upcall; - - //------------------------------------------------------------------ - - case do_fail: - if(d.ws.wr_close_) - { - d.state = do_fail + 4; - break; - } - d.fb.consume(d.fb.size()); - d.ws.template write_close< - static_buffer>(d.fb, code); - if(d.ws.wr_block_) - { - // suspend - BOOST_ASSERT(d.ws.wr_block_ != &d); - d.state = do_fail + 2; - d.ws.rd_op_.emplace(std::move(*this)); - return; - } - d.ws.wr_block_ = &d; - BEAST_FALLTHROUGH; - - case do_fail + 1: - BOOST_ASSERT(d.ws.wr_block_ == &d); - d.ws.failed_ = true; - // send close frame - d.state = do_fail + 4; - d.ws.wr_close_ = true; - boost::asio::async_write(d.ws.stream_, - d.fb.data(), std::move(*this)); - return; - - case do_fail + 2: - // resume - BOOST_ASSERT(! d.ws.wr_block_); - d.ws.wr_block_ = &d; - d.state = do_fail + 3; - // The current context is safe but might not be - // the same as the one for this operation (since - // we are being called from a write operation). - // Call post to make sure we are invoked the same - // way as the final handler for this operation. - d.ws.get_io_service().post(bind_handler( - std::move(*this), ec, bytes_transferred)); - return; - - case do_fail + 3: - BOOST_ASSERT(d.ws.wr_block_ == &d); - if(d.ws.failed_ || d.ws.wr_close_) - { - // call handler - ec = error::failed; - goto upcall; - } - d.state = do_fail + 1; - break; - - case do_fail + 4: - d.state = do_fail + 5; - websocket_helpers::call_async_teardown( - d.ws.next_layer(), std::move(*this)); - return; - - case do_fail + 5: - // call handler - ec = error::failed; - goto upcall; - - //------------------------------------------------------------------ - - case do_call_handler: - goto upcall; - } - } - while(! ec); - } -upcall: - if(d.ws.wr_block_ == &d) - d.ws.wr_block_ = nullptr; - d.ws.close_op_.maybe_invoke() || - d.ws.ping_op_.maybe_invoke() || - d.ws.wr_op_.maybe_invoke(); - bool const fin = (! ec) ? d.fh.fin : false; - d_.invoke(ec, fin); -} - -template -template -async_return_type< - ReadHandler, void(error_code, bool)> -stream:: -async_read_frame(DynamicBuffer& buffer, ReadHandler&& handler) -{ - static_assert(is_async_stream::value, - "AsyncStream requirements requirements not met"); - static_assert(beast::is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - async_completion init{handler}; - read_frame_op>{ - init.completion_handler,*this, buffer}( - {}, 0, false); - return init.result.get(); -} - -template -template -bool -stream:: -read_frame(DynamicBuffer& buffer) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - static_assert(beast::is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - error_code ec; - auto const fin = read_frame(buffer, ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); - return fin; -} - -template -template -bool -stream:: -read_frame(DynamicBuffer& dynabuf, error_code& ec) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - static_assert(beast::is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - using beast::detail::clamp; - using boost::asio::buffer; - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - close_code code{}; - for(;;) - { - // Read frame header - detail::frame_header fh; - detail::frame_streambuf fb; - { - fb.commit(boost::asio::read( - stream_, fb.prepare(2), ec)); - failed_ = !!ec; - if(failed_) - return false; - { - auto const n = read_fh1(fh, fb, code); - if(code != close_code::none) - goto do_close; - if(n > 0) - { - fb.commit(boost::asio::read( - stream_, fb.prepare(n), ec)); - failed_ = !!ec; - if(failed_) - return false; - } - } - read_fh2(fh, fb, code); - - failed_ = !!ec; - if(failed_) - return false; - if(code != close_code::none) - goto do_close; - } - if(detail::is_control(fh.op)) - { - // Read control frame payload - if(fh.len > 0) - { - auto const mb = fb.prepare( - static_cast(fh.len)); - fb.commit(boost::asio::read(stream_, mb, ec)); - failed_ = !!ec; - if(failed_) - return false; - if(fh.mask) - { - detail::prepared_key key; - detail::prepare_key(key, fh.key); - detail::mask_inplace(mb, key); - } - fb.commit(static_cast(fh.len)); - } - // Process control frame - if(fh.op == detail::opcode::ping) - { - ping_data payload; - detail::read(payload, fb.data()); - fb.consume(fb.size()); - if(ctrl_cb_) - ctrl_cb_(frame_type::ping, payload); - write_ping(fb, - detail::opcode::pong, payload); - boost::asio::write(stream_, fb.data(), ec); - failed_ = !!ec; - if(failed_) - return false; - continue; - } - else if(fh.op == detail::opcode::pong) - { - ping_data payload; - detail::read(payload, fb.data()); - if(ctrl_cb_) - ctrl_cb_(frame_type::pong, payload); - continue; - } - BOOST_ASSERT(fh.op == detail::opcode::close); - { - detail::read(cr_, fb.data(), code); - if(code != close_code::none) - goto do_close; - if(ctrl_cb_) - ctrl_cb_(frame_type::close, cr_.reason); - if(! wr_close_) - { - auto cr = cr_; - if(cr.code == close_code::none) - cr.code = close_code::normal; - cr.reason = ""; - fb.consume(fb.size()); - wr_close_ = true; - write_close(fb, cr); - boost::asio::write(stream_, fb.data(), ec); - failed_ = !!ec; - if(failed_) - return false; - } - goto do_close; - } - } - if(fh.op != detail::opcode::cont) - rd_begin(); - if(fh.len == 0 && ! fh.fin) - { - // empty frame - continue; - } - auto remain = fh.len; - detail::prepared_key key; - if(fh.mask) - detail::prepare_key(key, fh.key); - if(! pmd_ || ! pmd_->rd_set) - { - // Enforce message size limit - if(rd_msg_max_ && fh.len > - rd_msg_max_ - rd_.size) - { - code = close_code::too_big; - goto do_close; - } - rd_.size += fh.len; - // Read message frame payload - while(remain > 0) - { - auto b = - dynabuf.prepare(clamp(remain)); - auto const bytes_transferred = - stream_.read_some(b, ec); - failed_ = !!ec; - if(failed_) - return false; - BOOST_ASSERT(bytes_transferred > 0); - remain -= bytes_transferred; - auto const pb = buffer_prefix( - bytes_transferred, b); - if(fh.mask) - detail::mask_inplace(pb, key); - if(rd_.op == detail::opcode::text) - { - if(! rd_.utf8.write(pb) || - (remain == 0 && fh.fin && - ! rd_.utf8.finish())) - { - code = close_code::bad_payload; - goto do_close; - } - } - dynabuf.commit(bytes_transferred); - } - } - else - { - // Read compressed message frame payload: - // inflate even if fh.len == 0, otherwise we - // never emit the end-of-stream deflate block. - for(;;) - { - auto const bytes_transferred = - stream_.read_some(buffer(rd_.buf.get(), - clamp(remain, rd_.buf_size)), ec); - failed_ = !!ec; - if(failed_) - return false; - remain -= bytes_transferred; - auto const in = buffer( - rd_.buf.get(), bytes_transferred); - if(fh.mask) - detail::mask_inplace(in, key); - auto const prev = dynabuf.size(); - detail::inflate(pmd_->zi, dynabuf, in, ec); - failed_ = !!ec; - if(failed_) - return false; - if(remain == 0 && fh.fin) - { - static std::uint8_t constexpr - empty_block[4] = { - 0x00, 0x00, 0xff, 0xff }; - detail::inflate(pmd_->zi, dynabuf, - buffer(&empty_block[0], 4), ec); - failed_ = !!ec; - if(failed_) - return false; - } - if(rd_.op == detail::opcode::text) - { - consuming_buffers cb{dynabuf.data()}; - cb.consume(prev); - if(! rd_.utf8.write(cb) || ( - remain == 0 && fh.fin && - ! rd_.utf8.finish())) - { - code = close_code::bad_payload; - goto do_close; - } - } - if(remain == 0) - break; - } - if(fh.fin && ( - (role_ == role_type::client && - pmd_config_.server_no_context_takeover) || - (role_ == role_type::server && - pmd_config_.client_no_context_takeover))) - pmd_->zi.reset(); - } - return fh.fin; - } -do_close: - if(code != close_code::none) - { - // Fail the connection (per rfc6455) - if(! wr_close_) - { - wr_close_ = true; - detail::frame_streambuf fb; - write_close(fb, code); - boost::asio::write(stream_, fb.data(), ec); - failed_ = !!ec; - if(failed_) - return false; - } - websocket_helpers::call_teardown(next_layer(), ec); - if(ec == boost::asio::error::eof) - { - // Rationale: - // http://stackoverflow.com/questions/25587403/boost-asio-ssl-async-shutdown-always-finishes-with-an-error - ec.assign(0, ec.category()); - } - failed_ = !!ec; - if(failed_) - return false; - ec = error::failed; - failed_ = true; - return false; - } - if(! ec) - { - websocket_helpers::call_teardown(next_layer(), ec); - if(ec == boost::asio::error::eof) - { - // (See above) - ec.assign(0, ec.category()); - } - } - if(! ec) - ec = error::closed; - failed_ = !!ec; - if(failed_) - return false; - return true; -} - -//------------------------------------------------------------------------------ - -// read an entire message -// -template -template -class stream::read_op -{ - int state_ = 0; - stream& ws_; - DynamicBuffer& b_; - Handler h_; - -public: - read_op(read_op&&) = default; - read_op(read_op const&) = default; - - template - read_op(DeducedHandler&& h, - stream& ws, DynamicBuffer& b) - : ws_(ws) - , b_(b) - , h_(std::forward(h)) - { - } - - void operator()(error_code const& ec, bool fin); - - friend - void* asio_handler_allocate( - std::size_t size, read_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->h_)); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, read_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->h_)); - } - - friend - bool asio_handler_is_continuation(read_op* op) - { - using boost::asio::asio_handler_is_continuation; - return op->state_ >= 2 ? true: - asio_handler_is_continuation(std::addressof(op->h_)); - } - - template - friend - void asio_handler_invoke(Function&& f, read_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke(f, std::addressof(op->h_)); - } -}; - -template -template -void -stream::read_op:: -operator()(error_code const& ec, bool fin) -{ - switch(state_) - { - case 0: - state_ = 1; - goto do_read; - - case 1: - state_ = 2; - BEAST_FALLTHROUGH; - - case 2: - if(ec) - goto upcall; - if(fin) - goto upcall; - do_read: - return ws_.async_read_frame( - b_, std::move(*this)); - } -upcall: - h_(ec); -} - -template -template -async_return_type< - ReadHandler, void(error_code)> -stream:: -async_read(DynamicBuffer& buffer, ReadHandler&& handler) -{ - static_assert(is_async_stream::value, - "AsyncStream requirements requirements not met"); - static_assert(beast::is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - async_completion init{handler}; - read_op>{ - init.completion_handler, *this, buffer}( - {}, false); - return init.result.get(); -} - -template -template -void -stream:: -read(DynamicBuffer& buffer) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - static_assert(beast::is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - error_code ec; - read(buffer, ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); -} - -template -template -void -stream:: -read(DynamicBuffer& buffer, error_code& ec) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - static_assert(beast::is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - for(;;) - { - auto const fin = read_frame(buffer, ec); - if(ec) - break; - if(fin) - break; - } -} - -//------------------------------------------------------------------------------ - -} // websocket -} // beast - -#endif diff --git a/src/beast/include/beast/websocket/impl/rfc6455.ipp b/src/beast/include/beast/websocket/impl/rfc6455.ipp deleted file mode 100644 index e06b152c4b0..00000000000 --- a/src/beast/include/beast/websocket/impl/rfc6455.ipp +++ /dev/null @@ -1,38 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_WEBSOCKET_IMPL_RFC6455_IPP -#define BEAST_WEBSOCKET_IMPL_RFC6455_IPP - -#include -#include - -namespace beast { -namespace websocket { - -template -bool -is_upgrade(http::header> const& req) -{ - if(req.version < 11) - return false; - if(req.method() != http::verb::get) - return false; - if(! http::token_list{req["Connection"]}.exists("upgrade")) - return false; - if(! http::token_list{req["Upgrade"]}.exists("websocket")) - return false; - if(! req.count(http::field::sec_websocket_version)) - return false; - return true; -} - -} // websocket -} // beast - -#endif diff --git a/src/beast/include/beast/websocket/impl/ssl.ipp b/src/beast/include/beast/websocket/impl/ssl.ipp deleted file mode 100644 index 88e8a5e433c..00000000000 --- a/src/beast/include/beast/websocket/impl/ssl.ipp +++ /dev/null @@ -1,52 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_WEBSOCKET_IMPL_SSL_IPP_INCLUDED -#define BEAST_WEBSOCKET_IMPL_SSL_IPP_INCLUDED - -#include - -namespace beast { -namespace websocket { - -/* - -See -http://stackoverflow.com/questions/32046034/what-is-the-proper-way-to-securely-disconnect-an-asio-ssl-socket/32054476#32054476 - -Behavior of ssl::stream regarding close_ - - If the remote host calls async_shutdown then the - local host's async_read will complete with eof. - - If both hosts call async_shutdown then the calls - to async_shutdown will complete with eof. - -*/ - -template -void -teardown(teardown_tag, - boost::asio::ssl::stream& stream, - error_code& ec) -{ - stream.shutdown(ec); -} - -template -void -async_teardown(teardown_tag, - boost::asio::ssl::stream& stream, - TeardownHandler&& handler) -{ - stream.async_shutdown(std::forward(handler)); -} - -} // websocket -} // beast - -#endif diff --git a/src/beast/include/beast/websocket/impl/stream.ipp b/src/beast/include/beast/websocket/impl/stream.ipp deleted file mode 100644 index 62bfe595220..00000000000 --- a/src/beast/include/beast/websocket/impl/stream.ipp +++ /dev/null @@ -1,688 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_WEBSOCKET_IMPL_STREAM_IPP -#define BEAST_WEBSOCKET_IMPL_STREAM_IPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -namespace beast { -namespace websocket { - -template -template -stream:: -stream(Args&&... args) - : stream_(std::forward(args)...) -{ -} - -template -void -stream:: -set_option(permessage_deflate const& o) -{ - if( o.server_max_window_bits > 15 || - o.server_max_window_bits < 9) - BOOST_THROW_EXCEPTION(std::invalid_argument{ - "invalid server_max_window_bits"}); - if( o.client_max_window_bits > 15 || - o.client_max_window_bits < 9) - BOOST_THROW_EXCEPTION(std::invalid_argument{ - "invalid client_max_window_bits"}); - if( o.compLevel < 0 || - o.compLevel > 9) - BOOST_THROW_EXCEPTION(std::invalid_argument{ - "invalid compLevel"}); - if( o.memLevel < 1 || - o.memLevel > 9) - BOOST_THROW_EXCEPTION(std::invalid_argument{ - "invalid memLevel"}); - pmd_opts_ = o; -} - -//------------------------------------------------------------------------------ - -template -void -stream:: -reset() -{ - failed_ = false; - rd_.cont = false; - wr_close_ = false; - wr_.cont = false; - wr_block_ = nullptr; // should be nullptr on close anyway - ping_data_ = nullptr; // should be nullptr on close anyway - - stream_.buffer().consume( - stream_.buffer().size()); -} - -template -template -void -stream:: -do_accept( - Decorator const& decorator, error_code& ec) -{ - http::request_parser p; - http::read_header(next_layer(), - stream_.buffer(), p, ec); - if(ec) - return; - do_accept(p.get(), decorator, ec); -} - -template -template -void -stream:: -do_accept(http::header> const& req, - Decorator const& decorator, error_code& ec) -{ - auto const res = build_response(req, decorator); - http::write(stream_, res, ec); - if(ec) - return; - if(res.result() != http::status::switching_protocols) - { - ec = error::handshake_failed; - // VFALCO TODO Respect keep alive setting, perform - // teardown if Connection: close. - return; - } - pmd_read(pmd_config_, req); - open(role_type::server); -} - -template -template -void -stream:: -do_handshake(response_type* res_p, - string_view host, - string_view target, - RequestDecorator const& decorator, - error_code& ec) -{ - response_type res; - reset(); - detail::sec_ws_key_type key; - { - auto const req = build_request( - key, host, target, decorator); - pmd_read(pmd_config_, req); - http::write(stream_, req, ec); - } - if(ec) - return; - http::read(next_layer(), stream_.buffer(), res, ec); - if(ec) - return; - do_response(res, key, ec); - if(res_p) - *res_p = std::move(res); -} - -template -template -request_type -stream:: -build_request(detail::sec_ws_key_type& key, - string_view host, - string_view target, - Decorator const& decorator) -{ - request_type req; - req.target(target); - req.version = 11; - req.method(http::verb::get); - req.set(http::field::host, host); - req.set(http::field::upgrade, "websocket"); - req.set(http::field::connection, "upgrade"); - detail::make_sec_ws_key(key, maskgen_); - req.set(http::field::sec_websocket_key, key); - req.set(http::field::sec_websocket_version, "13"); - if(pmd_opts_.client_enable) - { - detail::pmd_offer config; - config.accept = true; - config.server_max_window_bits = - pmd_opts_.server_max_window_bits; - config.client_max_window_bits = - pmd_opts_.client_max_window_bits; - config.server_no_context_takeover = - pmd_opts_.server_no_context_takeover; - config.client_no_context_takeover = - pmd_opts_.client_no_context_takeover; - detail::pmd_write(req, config); - } - decorator(req); - if(! req.count(http::field::user_agent)) - req.set(http::field::user_agent, - BEAST_VERSION_STRING); - return req; -} - -template -template -response_type -stream:: -build_response(http::header> const& req, - Decorator const& decorator) -{ - auto const decorate = - [&decorator](response_type& res) - { - decorator(res); - if(! res.count(http::field::server)) - { - BOOST_STATIC_ASSERT(sizeof(BEAST_VERSION_STRING) < 20); - static_string<20> s(BEAST_VERSION_STRING); - res.set(http::field::server, s); - } - }; - auto err = - [&](std::string const& text) - { - response_type res; - res.version = req.version; - res.result(http::status::bad_request); - res.body = text; - res.prepare_payload(); - decorate(res); - return res; - }; - if(req.version < 11) - return err("HTTP version 1.1 required"); - if(req.method() != http::verb::get) - return err("Wrong method"); - if(! is_upgrade(req)) - return err("Expected Upgrade request"); - if(! req.count(http::field::host)) - return err("Missing Host"); - if(! req.count(http::field::sec_websocket_key)) - return err("Missing Sec-WebSocket-Key"); - if(! http::token_list{req[http::field::upgrade]}.exists("websocket")) - return err("Missing websocket Upgrade token"); - auto const key = req[http::field::sec_websocket_key]; - if(key.size() > detail::sec_ws_key_type::max_size_n) - return err("Invalid Sec-WebSocket-Key"); - { - auto const version = - req[http::field::sec_websocket_version]; - if(version.empty()) - return err("Missing Sec-WebSocket-Version"); - if(version != "13") - { - response_type res; - res.result(http::status::upgrade_required); - res.version = req.version; - res.set(http::field::sec_websocket_version, "13"); - res.prepare_payload(); - decorate(res); - return res; - } - } - - response_type res; - { - detail::pmd_offer offer; - detail::pmd_offer unused; - pmd_read(offer, req); - pmd_negotiate(res, unused, offer, pmd_opts_); - } - res.result(http::status::switching_protocols); - res.version = req.version; - res.set(http::field::upgrade, "websocket"); - res.set(http::field::connection, "upgrade"); - { - detail::sec_ws_accept_type acc; - detail::make_sec_ws_accept(acc, key); - res.set(http::field::sec_websocket_accept, acc); - } - decorate(res); - return res; -} - -template -void -stream:: -do_response(http::header const& res, - detail::sec_ws_key_type const& key, error_code& ec) -{ - bool const success = [&]() - { - if(res.version < 11) - return false; - if(res.result() != http::status::switching_protocols) - return false; - if(! http::token_list{res[http::field::connection]}.exists("upgrade")) - return false; - if(! http::token_list{res[http::field::upgrade]}.exists("websocket")) - return false; - if(res.count(http::field::sec_websocket_accept) != 1) - return false; - detail::sec_ws_accept_type acc; - detail::make_sec_ws_accept(acc, key); - if(acc.compare( - res[http::field::sec_websocket_accept]) != 0) - return false; - return true; - }(); - if(! success) - { - ec = error::handshake_failed; - return; - } - ec.assign(0, ec.category()); - detail::pmd_offer offer; - pmd_read(offer, res); - // VFALCO see if offer satisfies pmd_config_, - // return an error if not. - pmd_config_ = offer; // overwrite for now - open(role_type::client); -} - -//------------------------------------------------------------------------------ - -template -void -stream:: -open(role_type role) -{ - // VFALCO TODO analyze and remove dupe code in reset() - role_ = role; - failed_ = false; - rd_.cont = false; - wr_close_ = false; - wr_block_ = nullptr; // should be nullptr on close anyway - ping_data_ = nullptr; // should be nullptr on close anyway - - wr_.cont = false; - wr_.buf_size = 0; - - if(((role_ == role_type::client && pmd_opts_.client_enable) || - (role_ == role_type::server && pmd_opts_.server_enable)) && - pmd_config_.accept) - { - pmd_normalize(pmd_config_); - pmd_.reset(new pmd_t); - if(role_ == role_type::client) - { - pmd_->zi.reset( - pmd_config_.server_max_window_bits); - pmd_->zo.reset( - pmd_opts_.compLevel, - pmd_config_.client_max_window_bits, - pmd_opts_.memLevel, - zlib::Strategy::normal); - } - else - { - pmd_->zi.reset( - pmd_config_.client_max_window_bits); - pmd_->zo.reset( - pmd_opts_.compLevel, - pmd_config_.server_max_window_bits, - pmd_opts_.memLevel, - zlib::Strategy::normal); - } - } -} - -template -void -stream:: -close() -{ - rd_.buf.reset(); - wr_.buf.reset(); - pmd_.reset(); -} - -// Read fixed frame header from buffer -// Requires at least 2 bytes -// -template -template -std::size_t -stream:: -read_fh1(detail::frame_header& fh, - DynamicBuffer& db, close_code& code) -{ - using boost::asio::buffer; - using boost::asio::buffer_copy; - using boost::asio::buffer_size; - auto const err = - [&](close_code cv) - { - code = cv; - return 0; - }; - std::uint8_t b[2]; - BOOST_ASSERT(buffer_size(db.data()) >= sizeof(b)); - db.consume(buffer_copy(buffer(b), db.data())); - std::size_t need; - fh.len = b[1] & 0x7f; - switch(fh.len) - { - case 126: need = 2; break; - case 127: need = 8; break; - default: - need = 0; - } - fh.mask = (b[1] & 0x80) != 0; - if(fh.mask) - need += 4; - fh.op = static_cast< - detail::opcode>(b[0] & 0x0f); - fh.fin = (b[0] & 0x80) != 0; - fh.rsv1 = (b[0] & 0x40) != 0; - fh.rsv2 = (b[0] & 0x20) != 0; - fh.rsv3 = (b[0] & 0x10) != 0; - switch(fh.op) - { - case detail::opcode::binary: - case detail::opcode::text: - if(rd_.cont) - { - // new data frame when continuation expected - return err(close_code::protocol_error); - } - if((fh.rsv1 && ! pmd_) || - fh.rsv2 || fh.rsv3) - { - // reserved bits not cleared - return err(close_code::protocol_error); - } - if(pmd_) - pmd_->rd_set = fh.rsv1; - break; - - case detail::opcode::cont: - if(! rd_.cont) - { - // continuation without an active message - return err(close_code::protocol_error); - } - if(fh.rsv1 || fh.rsv2 || fh.rsv3) - { - // reserved bits not cleared - return err(close_code::protocol_error); - } - break; - - default: - if(is_reserved(fh.op)) - { - // reserved opcode - return err(close_code::protocol_error); - } - if(! fh.fin) - { - // fragmented control message - return err(close_code::protocol_error); - } - if(fh.len > 125) - { - // invalid length for control message - return err(close_code::protocol_error); - } - if(fh.rsv1 || fh.rsv2 || fh.rsv3) - { - // reserved bits not cleared - return err(close_code::protocol_error); - } - break; - } - // unmasked frame from client - if(role_ == role_type::server && ! fh.mask) - { - code = close_code::protocol_error; - return 0; - } - // masked frame from server - if(role_ == role_type::client && fh.mask) - { - code = close_code::protocol_error; - return 0; - } - code = close_code::none; - return need; -} - -// Decode variable frame header from buffer -// -template -template -void -stream:: -read_fh2(detail::frame_header& fh, - DynamicBuffer& db, close_code& code) -{ - using boost::asio::buffer; - using boost::asio::buffer_copy; - using boost::asio::buffer_size; - using namespace boost::endian; - switch(fh.len) - { - case 126: - { - std::uint8_t b[2]; - BOOST_ASSERT(buffer_size(db.data()) >= sizeof(b)); - db.consume(buffer_copy(buffer(b), db.data())); - fh.len = detail::big_uint16_to_native(&b[0]); - // length not canonical - if(fh.len < 126) - { - code = close_code::protocol_error; - return; - } - break; - } - case 127: - { - std::uint8_t b[8]; - BOOST_ASSERT(buffer_size(db.data()) >= sizeof(b)); - db.consume(buffer_copy(buffer(b), db.data())); - fh.len = detail::big_uint64_to_native(&b[0]); - // length not canonical - if(fh.len < 65536) - { - code = close_code::protocol_error; - return; - } - break; - } - } - if(fh.mask) - { - std::uint8_t b[4]; - BOOST_ASSERT(buffer_size(db.data()) >= sizeof(b)); - db.consume(buffer_copy(buffer(b), db.data())); - fh.key = detail::little_uint32_to_native(&b[0]); - } - else - { - // initialize this otherwise operator== breaks - fh.key = 0; - } - if(! is_control(fh.op)) - { - if(fh.op != detail::opcode::cont) - { - rd_.size = 0; - rd_.op = fh.op; - } - else - { - if(rd_.size > (std::numeric_limits< - std::uint64_t>::max)() - fh.len) - { - code = close_code::too_big; - return; - } - } - rd_.cont = ! fh.fin; - } - code = close_code::none; -} - -template -void -stream:: -rd_begin() -{ - // Maintain the read buffer - if(pmd_) - { - if(! rd_.buf || rd_.buf_size != rd_buf_size_) - { - rd_.buf_size = rd_buf_size_; - rd_.buf = boost::make_unique_noinit< - std::uint8_t[]>(rd_.buf_size); - } - } -} - -template -void -stream:: -wr_begin() -{ - wr_.autofrag = wr_autofrag_; - wr_.compress = static_cast(pmd_); - - // Maintain the write buffer - if( wr_.compress || - role_ == role_type::client) - { - if(! wr_.buf || wr_.buf_size != wr_buf_size_) - { - wr_.buf_size = wr_buf_size_; - wr_.buf = boost::make_unique_noinit< - std::uint8_t[]>(wr_.buf_size); - } - } - else - { - wr_.buf_size = wr_buf_size_; - wr_.buf.reset(); - } -} - -template -template -void -stream:: -write_close(DynamicBuffer& db, close_reason const& cr) -{ - using namespace boost::endian; - detail::frame_header fh; - fh.op = detail::opcode::close; - fh.fin = true; - fh.rsv1 = false; - fh.rsv2 = false; - fh.rsv3 = false; - fh.len = cr.code == close_code::none ? - 0 : 2 + cr.reason.size(); - fh.mask = role_ == role_type::client; - if(fh.mask) - fh.key = maskgen_(); - detail::write(db, fh); - if(cr.code != close_code::none) - { - detail::prepared_key key; - if(fh.mask) - detail::prepare_key(key, fh.key); - { - std::uint8_t b[2]; - ::new(&b[0]) big_uint16_buf_t{ - (std::uint16_t)cr.code}; - auto d = db.prepare(2); - boost::asio::buffer_copy(d, - boost::asio::buffer(b)); - if(fh.mask) - detail::mask_inplace(d, key); - db.commit(2); - } - if(! cr.reason.empty()) - { - auto d = db.prepare(cr.reason.size()); - boost::asio::buffer_copy(d, - boost::asio::const_buffer( - cr.reason.data(), cr.reason.size())); - if(fh.mask) - detail::mask_inplace(d, key); - db.commit(cr.reason.size()); - } - } -} - -template -template -void -stream:: -write_ping(DynamicBuffer& db, - detail::opcode code, ping_data const& data) -{ - detail::frame_header fh; - fh.op = code; - fh.fin = true; - fh.rsv1 = false; - fh.rsv2 = false; - fh.rsv3 = false; - fh.len = data.size(); - fh.mask = role_ == role_type::client; - if(fh.mask) - fh.key = maskgen_(); - detail::write(db, fh); - if(data.empty()) - return; - detail::prepared_key key; - if(fh.mask) - detail::prepare_key(key, fh.key); - auto d = db.prepare(data.size()); - boost::asio::buffer_copy(d, - boost::asio::const_buffers_1( - data.data(), data.size())); - if(fh.mask) - detail::mask_inplace(d, key); - db.commit(data.size()); -} - -} // websocket -} // beast - -#endif diff --git a/src/beast/include/beast/websocket/impl/teardown.ipp b/src/beast/include/beast/websocket/impl/teardown.ipp deleted file mode 100644 index f29a517b01a..00000000000 --- a/src/beast/include/beast/websocket/impl/teardown.ipp +++ /dev/null @@ -1,171 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_WEBSOCKET_IMPL_TEARDOWN_IPP -#define BEAST_WEBSOCKET_IMPL_TEARDOWN_IPP - -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace websocket { - -namespace detail { - -template -class teardown_tcp_op -{ - using socket_type = - boost::asio::ip::tcp::socket; - - struct data - { - bool cont; - socket_type& socket; - char buf[2048]; - int state = 0; - - data(Handler& handler, socket_type& socket_) - : socket(socket_) - { - using boost::asio::asio_handler_is_continuation; - cont = asio_handler_is_continuation(std::addressof(handler)); - } - }; - - handler_ptr d_; - -public: - template - teardown_tcp_op( - DeducedHandler&& h, - socket_type& socket) - : d_(std::forward(h), socket) - { - (*this)(error_code{}, 0, false); - } - - void - operator()(error_code ec, std::size_t, bool again = true); - - friend - void* asio_handler_allocate(std::size_t size, - teardown_tcp_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->d_.handler())); - } - - friend - void asio_handler_deallocate(void* p, - std::size_t size, teardown_tcp_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->d_.handler())); - } - - friend - bool asio_handler_is_continuation(teardown_tcp_op* op) - { - return op->d_->cont; - } - - template - friend - void asio_handler_invoke(Function&& f, - teardown_tcp_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->d_.handler())); - } -}; - -template -void -teardown_tcp_op:: -operator()(error_code ec, std::size_t, bool again) -{ - using boost::asio::buffer; - auto& d = *d_; - d.cont = d.cont || again; - while(! ec) - { - switch(d.state) - { - case 0: - d.state = 1; - d.socket.shutdown( - boost::asio::ip::tcp::socket::shutdown_send, ec); - break; - - case 1: - d.socket.async_read_some( - buffer(d.buf), std::move(*this)); - return; - } - } - if(ec == boost::asio::error::eof) - { - d.socket.close(ec); - ec = error_code{}; - } - d_.invoke(ec); -} - -} // detail - -//------------------------------------------------------------------------------ - -inline -void -teardown(teardown_tag, - boost::asio::ip::tcp::socket& socket, - error_code& ec) -{ - using boost::asio::buffer; - socket.shutdown( - boost::asio::ip::tcp::socket::shutdown_send, ec); - while(! ec) - { - char buf[8192]; - auto const n = socket.read_some( - buffer(buf), ec); - if(! n) - break; - } - if(ec == boost::asio::error::eof) - ec = error_code{}; - socket.close(ec); -} - -template -inline -void -async_teardown(teardown_tag, - boost::asio::ip::tcp::socket& socket, - TeardownHandler&& handler) -{ - static_assert(beast::is_completion_handler< - TeardownHandler, void(error_code)>::value, - "TeardownHandler requirements not met"); - detail::teardown_tcp_op::type>{std::forward< - TeardownHandler>(handler), socket}; -} - -} // websocket -} // beast - -#endif diff --git a/src/beast/include/beast/websocket/impl/write.ipp b/src/beast/include/beast/websocket/impl/write.ipp deleted file mode 100644 index 0da91b111dd..00000000000 --- a/src/beast/include/beast/websocket/impl/write.ipp +++ /dev/null @@ -1,921 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_WEBSOCKET_IMPL_WRITE_IPP -#define BEAST_WEBSOCKET_IMPL_WRITE_IPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace websocket { - -template -template -class stream::write_frame_op -{ - struct data : op - { - bool cont; - stream& ws; - consuming_buffers cb; - bool fin; - detail::frame_header fh; - detail::fh_streambuf fh_buf; - detail::prepared_key key; - std::uint64_t remain; - int step = 0; - int entry_state; - - data(Handler& handler, stream& ws_, - bool fin_, Buffers const& bs) - : ws(ws_) - , cb(bs) - , fin(fin_) - { - using boost::asio::asio_handler_is_continuation; - cont = asio_handler_is_continuation(std::addressof(handler)); - } - }; - - handler_ptr d_; - -public: - write_frame_op(write_frame_op&&) = default; - write_frame_op(write_frame_op const&) = default; - - template - write_frame_op(DeducedHandler&& h, - stream& ws, Args&&... args) - : d_(std::forward(h), - ws, std::forward(args)...) - { - } - - void operator()() - { - (*this)({}, 0, true); - } - - void operator()(error_code ec, - std::size_t bytes_transferred, - bool again = true); - - friend - void* asio_handler_allocate( - std::size_t size, write_frame_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->d_.handler())); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, write_frame_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->d_.handler())); - } - - friend - bool asio_handler_is_continuation(write_frame_op* op) - { - return op->d_->cont; - } - - template - friend - void asio_handler_invoke(Function&& f, write_frame_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->d_.handler())); - } -}; - -template -template -void -stream:: -write_frame_op:: -operator()(error_code ec, - std::size_t bytes_transferred, bool again) -{ - using beast::detail::clamp; - using boost::asio::buffer; - using boost::asio::buffer_copy; - using boost::asio::buffer_size; - enum - { - do_init = 0, - do_nomask_nofrag = 20, - do_nomask_frag = 30, - do_mask_nofrag = 40, - do_mask_frag = 50, - do_deflate = 60, - do_maybe_suspend = 80, - do_upcall = 99 - }; - auto& d = *d_; - d.cont = d.cont || again; - if(ec) - { - BOOST_ASSERT(d.ws.wr_block_ == &d); - d.ws.failed_ = true; - goto upcall; - } -loop: - switch(d.step) - { - case do_init: - if(! d.ws.wr_.cont) - { - d.ws.wr_begin(); - d.fh.rsv1 = d.ws.wr_.compress; - } - else - { - d.fh.rsv1 = false; - } - d.fh.rsv2 = false; - d.fh.rsv3 = false; - d.fh.op = d.ws.wr_.cont ? - detail::opcode::cont : d.ws.wr_opcode_; - d.fh.mask = - d.ws.role_ == role_type::client; - - // entry_state determines which algorithm - // we will use to send. If we suspend, we - // will transition to entry_state + 1 on - // the resume. - if(d.ws.wr_.compress) - { - d.entry_state = do_deflate; - } - else if(! d.fh.mask) - { - if(! d.ws.wr_.autofrag) - { - d.entry_state = do_nomask_nofrag; - } - else - { - BOOST_ASSERT(d.ws.wr_.buf_size != 0); - d.remain = buffer_size(d.cb); - if(d.remain > d.ws.wr_.buf_size) - d.entry_state = do_nomask_frag; - else - d.entry_state = do_nomask_nofrag; - } - } - else - { - if(! d.ws.wr_.autofrag) - { - d.entry_state = do_mask_nofrag; - } - else - { - BOOST_ASSERT(d.ws.wr_.buf_size != 0); - d.remain = buffer_size(d.cb); - if(d.remain > d.ws.wr_.buf_size) - d.entry_state = do_mask_frag; - else - d.entry_state = do_mask_nofrag; - } - } - d.step = do_maybe_suspend; - goto loop; - - //---------------------------------------------------------------------- - - case do_nomask_nofrag: - BOOST_ASSERT(d.ws.wr_block_ == &d); - d.fh.fin = d.fin; - d.fh.len = buffer_size(d.cb); - detail::write( - d.fh_buf, d.fh); - d.ws.wr_.cont = ! d.fin; - // Send frame - d.step = do_upcall; - return boost::asio::async_write(d.ws.stream_, - buffer_cat(d.fh_buf.data(), d.cb), - std::move(*this)); - - //---------------------------------------------------------------------- - - go_nomask_frag: - case do_nomask_frag: - { - BOOST_ASSERT(d.ws.wr_block_ == &d); - auto const n = clamp( - d.remain, d.ws.wr_.buf_size); - d.remain -= n; - d.fh.len = n; - d.fh.fin = d.fin ? d.remain == 0 : false; - detail::write( - d.fh_buf, d.fh); - d.ws.wr_.cont = ! d.fin; - // Send frame - d.step = d.remain == 0 ? - do_upcall : do_nomask_frag + 1; - return boost::asio::async_write( - d.ws.stream_, buffer_cat( - d.fh_buf.data(), buffer_prefix( - n, d.cb)), std::move(*this)); - } - - case do_nomask_frag + 1: - BOOST_ASSERT(d.ws.wr_block_ == &d); - d.ws.wr_block_ = nullptr; - d.cb.consume( - bytes_transferred - d.fh_buf.size()); - d.fh_buf.consume(d.fh_buf.size()); - d.fh.op = detail::opcode::cont; - // Allow outgoing control frames to - // be sent in between message frames - if( d.ws.close_op_.maybe_invoke() || - d.ws.rd_op_.maybe_invoke() || - d.ws.ping_op_.maybe_invoke()) - { - d.step = do_maybe_suspend; - return d.ws.get_io_service().post( - std::move(*this)); - } - d.ws.wr_block_ = &d; - goto go_nomask_frag; - - //---------------------------------------------------------------------- - - case do_mask_nofrag: - { - BOOST_ASSERT(d.ws.wr_block_ == &d); - d.remain = buffer_size(d.cb); - d.fh.fin = d.fin; - d.fh.len = d.remain; - d.fh.key = d.ws.maskgen_(); - detail::prepare_key(d.key, d.fh.key); - detail::write( - d.fh_buf, d.fh); - auto const n = - clamp(d.remain, d.ws.wr_.buf_size); - auto const b = - buffer(d.ws.wr_.buf.get(), n); - buffer_copy(b, d.cb); - detail::mask_inplace(b, d.key); - d.remain -= n; - d.ws.wr_.cont = ! d.fin; - // Send frame header and partial payload - d.step = d.remain == 0 ? - do_upcall : do_mask_nofrag + 1; - return boost::asio::async_write( - d.ws.stream_, buffer_cat(d.fh_buf.data(), - b), std::move(*this)); - } - - case do_mask_nofrag + 1: - { - d.cb.consume(d.ws.wr_.buf_size); - auto const n = - clamp(d.remain, d.ws.wr_.buf_size); - auto const b = - buffer(d.ws.wr_.buf.get(), n); - buffer_copy(b, d.cb); - detail::mask_inplace(b, d.key); - d.remain -= n; - // Send partial payload - if(d.remain == 0) - d.step = do_upcall; - return boost::asio::async_write( - d.ws.stream_, b, std::move(*this)); - } - - //---------------------------------------------------------------------- - - go_mask_frag: - case do_mask_frag: - { - BOOST_ASSERT(d.ws.wr_block_ == &d); - auto const n = clamp( - d.remain, d.ws.wr_.buf_size); - d.remain -= n; - d.fh.len = n; - d.fh.key = d.ws.maskgen_(); - d.fh.fin = d.fin ? d.remain == 0 : false; - detail::prepare_key(d.key, d.fh.key); - auto const b = buffer( - d.ws.wr_.buf.get(), n); - buffer_copy(b, d.cb); - detail::mask_inplace(b, d.key); - detail::write( - d.fh_buf, d.fh); - d.ws.wr_.cont = ! d.fin; - // Send frame - d.step = d.remain == 0 ? - do_upcall : do_mask_frag + 1; - return boost::asio::async_write( - d.ws.stream_, buffer_cat( - d.fh_buf.data(), b), - std::move(*this)); - } - - case do_mask_frag + 1: - BOOST_ASSERT(d.ws.wr_block_ == &d); - d.ws.wr_block_ = nullptr; - d.cb.consume( - bytes_transferred - d.fh_buf.size()); - d.fh_buf.consume(d.fh_buf.size()); - d.fh.op = detail::opcode::cont; - // Allow outgoing control frames to - // be sent in between message frames: - if( d.ws.close_op_.maybe_invoke() || - d.ws.rd_op_.maybe_invoke() || - d.ws.ping_op_.maybe_invoke()) - { - d.step = do_maybe_suspend; - d.ws.get_io_service().post( - std::move(*this)); - return; - } - d.ws.wr_block_ = &d; - goto go_mask_frag; - - //---------------------------------------------------------------------- - - go_deflate: - case do_deflate: - { - BOOST_ASSERT(d.ws.wr_block_ == &d); - auto b = buffer(d.ws.wr_.buf.get(), - d.ws.wr_.buf_size); - auto const more = detail::deflate( - d.ws.pmd_->zo, b, d.cb, d.fin, ec); - d.ws.failed_ = !!ec; - if(d.ws.failed_) - goto upcall; - auto const n = buffer_size(b); - if(n == 0) - { - // The input was consumed, but there - // is no output due to compression - // latency. - BOOST_ASSERT(! d.fin); - BOOST_ASSERT(buffer_size(d.cb) == 0); - - // We can skip the dispatch if the - // asynchronous initiation function is - // not on call stack but its hard to - // figure out so be safe and dispatch. - d.step = do_upcall; - d.ws.get_io_service().post(std::move(*this)); - return; - } - if(d.fh.mask) - { - d.fh.key = d.ws.maskgen_(); - detail::prepared_key key; - detail::prepare_key(key, d.fh.key); - detail::mask_inplace(b, key); - } - d.fh.fin = ! more; - d.fh.len = n; - detail::fh_streambuf fh_buf; - detail::write(fh_buf, d.fh); - d.ws.wr_.cont = ! d.fin; - // Send frame - d.step = more ? - do_deflate + 1 : do_deflate + 2; - boost::asio::async_write(d.ws.stream_, - buffer_cat(fh_buf.data(), b), - std::move(*this)); - return; - } - - case do_deflate + 1: - BOOST_ASSERT(d.ws.wr_block_ == &d); - d.ws.wr_block_ = nullptr; - d.fh.op = detail::opcode::cont; - d.fh.rsv1 = false; - // Allow outgoing control frames to - // be sent in between message frames: - if( d.ws.close_op_.maybe_invoke() || - d.ws.rd_op_.maybe_invoke() || - d.ws.ping_op_.maybe_invoke()) - { - d.step = do_maybe_suspend; - d.ws.get_io_service().post( - std::move(*this)); - return; - } - d.ws.wr_block_ = &d; - goto go_deflate; - - case do_deflate + 2: - BOOST_ASSERT(d.ws.wr_block_ == &d); - if(d.fh.fin && ( - (d.ws.role_ == role_type::client && - d.ws.pmd_config_.client_no_context_takeover) || - (d.ws.role_ == role_type::server && - d.ws.pmd_config_.server_no_context_takeover))) - d.ws.pmd_->zo.reset(); - goto upcall; - - //---------------------------------------------------------------------- - - case do_maybe_suspend: - if(d.ws.wr_block_) - { - // suspend - BOOST_ASSERT(d.ws.wr_block_ != &d); - d.step = do_maybe_suspend + 1; - d.ws.wr_op_.emplace(std::move(*this)); - return; - } - d.ws.wr_block_ = &d; - if(d.ws.failed_ || d.ws.wr_close_) - { - // call handler - return d.ws.get_io_service().post( - bind_handler(std::move(*this), - boost::asio::error::operation_aborted, 0)); - } - d.step = d.entry_state; - goto loop; - - case do_maybe_suspend + 1: - BOOST_ASSERT(! d.ws.wr_block_); - d.ws.wr_block_ = &d; - d.step = do_maybe_suspend + 2; - // The current context is safe but might not be - // the same as the one for this operation (since - // we are being called from a write operation). - // Call post to make sure we are invoked the same - // way as the final handler for this operation. - d.ws.get_io_service().post(bind_handler( - std::move(*this), ec, 0)); - return; - - case do_maybe_suspend + 2: - BOOST_ASSERT(d.ws.wr_block_ == &d); - if(d.ws.failed_ || d.ws.wr_close_) - { - // call handler - ec = boost::asio::error::operation_aborted; - goto upcall; - } - d.step = d.entry_state; - goto loop; - - //---------------------------------------------------------------------- - - case do_upcall: - goto upcall; - } -upcall: - if(d.ws.wr_block_ == &d) - d.ws.wr_block_ = nullptr; - d.ws.close_op_.maybe_invoke() || - d.ws.rd_op_.maybe_invoke() || - d.ws.ping_op_.maybe_invoke(); - d_.invoke(ec); -} - -//------------------------------------------------------------------------------ - -template -template -class stream::write_op -{ - struct data : op - { - int step = 0; - stream& ws; - consuming_buffers cb; - std::size_t remain; - - data(Handler&, stream& ws_, - Buffers const& bs) - : ws(ws_) - , cb(bs) - , remain(boost::asio::buffer_size(cb)) - { - } - }; - - handler_ptr d_; - -public: - write_op(write_op&&) = default; - write_op(write_op const&) = default; - - template - explicit - write_op(DeducedHandler&& h, - stream& ws, Args&&... args) - : d_(std::forward(h), - ws, std::forward(args)...) - { - } - - void operator()(error_code ec); - - friend - void* asio_handler_allocate( - std::size_t size, write_op* op) - { - using boost::asio::asio_handler_allocate; - return asio_handler_allocate( - size, std::addressof(op->d_.handler())); - } - - friend - void asio_handler_deallocate( - void* p, std::size_t size, write_op* op) - { - using boost::asio::asio_handler_deallocate; - asio_handler_deallocate( - p, size, std::addressof(op->d_.handler())); - } - - friend - bool asio_handler_is_continuation(write_op* op) - { - using boost::asio::asio_handler_is_continuation; - return op->d_->step > 2 || - asio_handler_is_continuation( - std::addressof(op->d_.handler())); - } - - template - friend - void asio_handler_invoke(Function&& f, write_op* op) - { - using boost::asio::asio_handler_invoke; - asio_handler_invoke( - f, std::addressof(op->d_.handler())); - } -}; - -template -template -void -stream:: -write_op:: -operator()(error_code ec) -{ - auto& d = *d_; - switch(d.step) - { - case 2: - d.step = 3; - BEAST_FALLTHROUGH; - case 3: - case 0: - { - auto const n = d.remain; - d.remain -= n; - auto const fin = d.remain <= 0; - if(fin) - d.step = d.step ? 4 : 1; - else - d.step = d.step ? 3 : 2; - auto const pb = buffer_prefix(n, d.cb); - d.cb.consume(n); - return d.ws.async_write_frame( - fin, pb, std::move(*this)); - } - - case 1: - case 4: - break; - } - d_.invoke(ec); -} - -//------------------------------------------------------------------------------ - -template -template -void -stream:: -write_frame(bool fin, ConstBufferSequence const& buffers) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - static_assert(beast::is_const_buffer_sequence< - ConstBufferSequence>::value, - "ConstBufferSequence requirements not met"); - error_code ec; - write_frame(fin, buffers, ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); -} - -template -template -void -stream:: -write_frame(bool fin, - ConstBufferSequence const& buffers, error_code& ec) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - static_assert(beast::is_const_buffer_sequence< - ConstBufferSequence>::value, - "ConstBufferSequence requirements not met"); - using beast::detail::clamp; - using boost::asio::buffer; - using boost::asio::buffer_copy; - using boost::asio::buffer_size; - detail::frame_header fh; - if(! wr_.cont) - { - wr_begin(); - fh.rsv1 = wr_.compress; - } - else - { - fh.rsv1 = false; - } - fh.rsv2 = false; - fh.rsv3 = false; - fh.op = wr_.cont ? - detail::opcode::cont : wr_opcode_; - fh.mask = role_ == role_type::client; - auto remain = buffer_size(buffers); - if(wr_.compress) - { - consuming_buffers< - ConstBufferSequence> cb{buffers}; - for(;;) - { - auto b = buffer( - wr_.buf.get(), wr_.buf_size); - auto const more = detail::deflate( - pmd_->zo, b, cb, fin, ec); - failed_ = !!ec; - if(failed_) - return; - auto const n = buffer_size(b); - if(n == 0) - { - // The input was consumed, but there - // is no output due to compression - // latency. - BOOST_ASSERT(! fin); - BOOST_ASSERT(buffer_size(cb) == 0); - fh.fin = false; - break; - } - if(fh.mask) - { - fh.key = maskgen_(); - detail::prepared_key key; - detail::prepare_key(key, fh.key); - detail::mask_inplace(b, key); - } - fh.fin = ! more; - fh.len = n; - detail::fh_streambuf fh_buf; - detail::write(fh_buf, fh); - wr_.cont = ! fin; - boost::asio::write(stream_, - buffer_cat(fh_buf.data(), b), ec); - failed_ = !!ec; - if(failed_) - return; - if(! more) - break; - fh.op = detail::opcode::cont; - fh.rsv1 = false; - } - if(fh.fin && ( - (role_ == role_type::client && - pmd_config_.client_no_context_takeover) || - (role_ == role_type::server && - pmd_config_.server_no_context_takeover))) - pmd_->zo.reset(); - return; - } - if(! fh.mask) - { - if(! wr_.autofrag) - { - // no mask, no autofrag - fh.fin = fin; - fh.len = remain; - detail::fh_streambuf fh_buf; - detail::write(fh_buf, fh); - wr_.cont = ! fin; - boost::asio::write(stream_, - buffer_cat(fh_buf.data(), buffers), ec); - failed_ = !!ec; - if(failed_) - return; - } - else - { - // no mask, autofrag - BOOST_ASSERT(wr_.buf_size != 0); - consuming_buffers< - ConstBufferSequence> cb{buffers}; - for(;;) - { - auto const n = clamp(remain, wr_.buf_size); - remain -= n; - fh.len = n; - fh.fin = fin ? remain == 0 : false; - detail::fh_streambuf fh_buf; - detail::write(fh_buf, fh); - wr_.cont = ! fin; - boost::asio::write(stream_, - buffer_cat(fh_buf.data(), - buffer_prefix(n, cb)), ec); - failed_ = !!ec; - if(failed_) - return; - if(remain == 0) - break; - fh.op = detail::opcode::cont; - cb.consume(n); - } - } - return; - } - if(! wr_.autofrag) - { - // mask, no autofrag - fh.fin = fin; - fh.len = remain; - fh.key = maskgen_(); - detail::prepared_key key; - detail::prepare_key(key, fh.key); - detail::fh_streambuf fh_buf; - detail::write(fh_buf, fh); - consuming_buffers< - ConstBufferSequence> cb{buffers}; - { - auto const n = clamp(remain, wr_.buf_size); - auto const b = buffer(wr_.buf.get(), n); - buffer_copy(b, cb); - cb.consume(n); - remain -= n; - detail::mask_inplace(b, key); - wr_.cont = ! fin; - boost::asio::write(stream_, - buffer_cat(fh_buf.data(), b), ec); - failed_ = !!ec; - if(failed_) - return; - } - while(remain > 0) - { - auto const n = clamp(remain, wr_.buf_size); - auto const b = buffer(wr_.buf.get(), n); - buffer_copy(b, cb); - cb.consume(n); - remain -= n; - detail::mask_inplace(b, key); - boost::asio::write(stream_, b, ec); - failed_ = !!ec; - if(failed_) - return; - } - return; - } - { - // mask, autofrag - BOOST_ASSERT(wr_.buf_size != 0); - consuming_buffers< - ConstBufferSequence> cb{buffers}; - for(;;) - { - fh.key = maskgen_(); - detail::prepared_key key; - detail::prepare_key(key, fh.key); - auto const n = clamp(remain, wr_.buf_size); - auto const b = buffer(wr_.buf.get(), n); - buffer_copy(b, cb); - detail::mask_inplace(b, key); - fh.len = n; - remain -= n; - fh.fin = fin ? remain == 0 : false; - wr_.cont = ! fh.fin; - detail::fh_streambuf fh_buf; - detail::write(fh_buf, fh); - boost::asio::write(stream_, - buffer_cat(fh_buf.data(), b), ec); - failed_ = !!ec; - if(failed_) - return; - if(remain == 0) - break; - fh.op = detail::opcode::cont; - cb.consume(n); - } - return; - } -} - -template -template -async_return_type< - WriteHandler, void(error_code)> -stream:: -async_write_frame(bool fin, - ConstBufferSequence const& bs, WriteHandler&& handler) -{ - static_assert(is_async_stream::value, - "AsyncStream requirements not met"); - static_assert(beast::is_const_buffer_sequence< - ConstBufferSequence>::value, - "ConstBufferSequence requirements not met"); - async_completion init{handler}; - write_frame_op>{init.completion_handler, - *this, fin, bs}({}, 0, false); - return init.result.get(); -} - -//------------------------------------------------------------------------------ - -template -template -void -stream:: -write(ConstBufferSequence const& buffers) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - static_assert(beast::is_const_buffer_sequence< - ConstBufferSequence>::value, - "ConstBufferSequence requirements not met"); - error_code ec; - write(buffers, ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); -} - -template -template -void -stream:: -write(ConstBufferSequence const& buffers, error_code& ec) -{ - static_assert(is_sync_stream::value, - "SyncStream requirements not met"); - static_assert(beast::is_const_buffer_sequence< - ConstBufferSequence>::value, - "ConstBufferSequence requirements not met"); - write_frame(true, buffers, ec); -} - -template -template -async_return_type< - WriteHandler, void(error_code)> -stream:: -async_write( - ConstBufferSequence const& bs, WriteHandler&& handler) -{ - static_assert(is_async_stream::value, - "AsyncStream requirements not met"); - static_assert(beast::is_const_buffer_sequence< - ConstBufferSequence>::value, - "ConstBufferSequence requirements not met"); - async_completion init{handler}; - write_op>{ - init.completion_handler, *this, bs}( - error_code{}); - return init.result.get(); -} - -} // websocket -} // beast - -#endif diff --git a/src/beast/include/beast/websocket/option.hpp b/src/beast/include/beast/websocket/option.hpp deleted file mode 100644 index 258f5565bc2..00000000000 --- a/src/beast/include/beast/websocket/option.hpp +++ /dev/null @@ -1,69 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_WEBSOCKET_OPTION_HPP -#define BEAST_WEBSOCKET_OPTION_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace websocket { - -/** permessage-deflate extension options. - - These settings control the permessage-deflate extension, - which allows messages to be compressed. - - @note Objects of this type are used with - @ref beast::websocket::stream::set_option. -*/ -struct permessage_deflate -{ - /// `true` to offer the extension in the server role - bool server_enable = false; - - /// `true` to offer the extension in the client role - bool client_enable = false; - - /** Maximum server window bits to offer - - @note Due to a bug in ZLib, this value must be greater than 8. - */ - int server_max_window_bits = 15; - - /** Maximum client window bits to offer - - @note Due to a bug in ZLib, this value must be greater than 8. - */ - int client_max_window_bits = 15; - - /// `true` if server_no_context_takeover desired - bool server_no_context_takeover = false; - - /// `true` if client_no_context_takeover desired - bool client_no_context_takeover = false; - - /// Deflate compression level 0..9 - int compLevel = 8; - - /// Deflate memory level, 1..9 - int memLevel = 4; -}; - -} // websocket -} // beast - -#endif diff --git a/src/beast/include/beast/websocket/rfc6455.hpp b/src/beast/include/beast/websocket/rfc6455.hpp deleted file mode 100644 index bb819c8749d..00000000000 --- a/src/beast/include/beast/websocket/rfc6455.hpp +++ /dev/null @@ -1,211 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_WEBSOCKET_RFC6455_HPP -#define BEAST_WEBSOCKET_RFC6455_HPP - -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace websocket { - -/** Returns `true` if the specified HTTP request is a WebSocket Upgrade. - - This function returns `true` when the passed HTTP Request - indicates a WebSocket Upgrade. It does not validate the - contents of the fields: it just trivially accepts requests - which could only possibly be a valid or invalid WebSocket - Upgrade message. - - Callers who wish to manually read HTTP requests in their - server implementation can use this function to determine if - the request should be routed to an instance of - @ref websocket::stream. - - @par Example - @code - void handle_connection(boost::asio::ip::tcp::socket& sock) - { - beast::flat_buffer buffer; - beast::http::request req; - beast::http::read(sock, buffer, req); - if(beast::websocket::is_upgrade(req)) - { - beast::websocket::stream ws{std::move(sock)}; - ws.accept(req); - } - } - @endcode - - @param req The HTTP Request object to check. - - @return `true` if the request is a WebSocket Upgrade. -*/ -template -bool -is_upgrade(beast::http::header> const& req); - -/** Close status codes. - - These codes accompany close frames. - - @see RFC 6455 7.4.1 Defined Status Codes -*/ -enum close_code : std::uint16_t -{ - /// Normal closure; the connection successfully completed whatever purpose for which it was created. - normal = 1000, - - /// The endpoint is going away, either because of a server failure or because the browser is navigating away from the page that opened the connection. - going_away = 1001, - - /// The endpoint is terminating the connection due to a protocol error. - protocol_error = 1002, - - /// The connection is being terminated because the endpoint received data of a type it cannot accept (for example, a text-only endpoint received binary data). - unknown_data = 1003, - - /// The endpoint is terminating the connection because a message was received that contained inconsistent data (e.g., non-UTF-8 data within a text message). - bad_payload = 1007, - - /// The endpoint is terminating the connection because it received a message that violates its policy. This is a generic status code, used when codes 1003 and 1009 are not suitable. - policy_error = 1008, - - /// The endpoint is terminating the connection because a data frame was received that is too large. - too_big = 1009, - - /// The client is terminating the connection because it expected the server to negotiate one or more extension, but the server didn't. - needs_extension = 1010, - - /// The server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request. - internal_error = 1011, - - /// The server is terminating the connection because it is restarting. - service_restart = 1012, - - /// The server is terminating the connection due to a temporary condition, e.g. it is overloaded and is casting off some of its clients. - try_again_later = 1013, - - //---- - // - // The following are illegal on the wire - // - - /** Used internally to mean "no error" - - This code is reserved and may not be sent. - */ - none = 0, - - /** Reserved for future use by the WebSocket standard. - - This code is reserved and may not be sent. - */ - reserved1 = 1004, - - /** No status code was provided even though one was expected. - - This code is reserved and may not be sent. - */ - no_status = 1005, - - /** Connection was closed without receiving a close frame - - This code is reserved and may not be sent. - */ - abnormal = 1006, - - /** Reserved for future use by the WebSocket standard. - - This code is reserved and may not be sent. - */ - reserved2 = 1014, - - /** Reserved for future use by the WebSocket standard. - - This code is reserved and may not be sent. - */ - reserved3 = 1015 - - // - //---- - - //last = 5000 // satisfy warnings -}; - -/// The type representing the reason string in a close frame. -using reason_string = static_string<123, char>; - -/// The type representing the payload of ping and pong messages. -using ping_data = static_string<125, char>; - -/** Description of the close reason. - - This object stores the close code (if any) and the optional - utf-8 encoded implementation defined reason string. -*/ -struct close_reason -{ - /// The close code. - std::uint16_t code = close_code::none; - - /// The optional utf8-encoded reason string. - reason_string reason; - - /** Default constructor. - - The code will be none. Default constructed objects - will explicitly convert to bool as `false`. - */ - close_reason() = default; - - /// Construct from a code. - close_reason(std::uint16_t code_) - : code(code_) - { - } - - /// Construct from a reason string. code is @ref close_code::normal. - close_reason(string_view s) - : code(close_code::normal) - , reason(s) - { - } - - /// Construct from a reason string literal. code is @ref close_code::normal. - close_reason(char const* s) - : code(close_code::normal) - , reason(s) - { - } - - /// Construct from a close code and reason string. - close_reason(close_code code_, string_view s) - : code(code_) - , reason(s) - { - } - - /// Returns `true` if a code was specified - operator bool() const - { - return code != close_code::none; - } -}; - -} // websocket -} // beast - -#include - -#endif diff --git a/src/beast/include/beast/websocket/ssl.hpp b/src/beast/include/beast/websocket/ssl.hpp deleted file mode 100644 index ca4f039c9b9..00000000000 --- a/src/beast/include/beast/websocket/ssl.hpp +++ /dev/null @@ -1,74 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_WEBSOCKET_SSL_HPP -#define BEAST_WEBSOCKET_SSL_HPP - -#include -#include -#include -#include - -namespace beast { -namespace websocket { - -/** Tear down a `boost::asio::ssl::stream`. - - This tears down a connection. The implementation will call - the overload of this function based on the `Stream` parameter - used to consruct the socket. When `Stream` is a user defined - type, and not a `boost::asio::ip::tcp::socket` or any - `boost::asio::ssl::stream`, callers are responsible for - providing a suitable overload of this function. - - @param stream The stream to tear down. - - @param ec Set to the error if any occurred. -*/ -template -void -teardown(teardown_tag, - boost::asio::ssl::stream& stream, - error_code& ec); - -/** Start tearing down a `boost::asio::ssl::stream`. - - This begins tearing down a connection asynchronously. - The implementation will call the overload of this function - based on the `Stream` parameter used to consruct the socket. - When `Stream` is a user defined type, and not a - `boost::asio::ip::tcp::socket` or any `boost::asio::ssl::stream`, - callers are responsible for providing a suitable overload - of this function. - - @param stream The stream to tear down. - - @param handler The handler to be called when the request completes. - Copies will be made of the handler as required. The equivalent - function signature of the handler must be: - @code void handler( - error_code const& error // result of operation - ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using boost::asio::io_service::post(). - -*/ -template -inline -void -async_teardown(teardown_tag, - boost::asio::ssl::stream& stream, - TeardownHandler&& handler); - -} // websocket -} // beast - -#include - -#endif diff --git a/src/beast/include/beast/websocket/stream.hpp b/src/beast/include/beast/websocket/stream.hpp deleted file mode 100644 index 4c494890c0c..00000000000 --- a/src/beast/include/beast/websocket/stream.hpp +++ /dev/null @@ -1,3355 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_WEBSOCKET_STREAM_HPP -#define BEAST_WEBSOCKET_STREAM_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace websocket { - -namespace detail { -class frame_test; -} - -/// The type of object holding HTTP Upgrade requests -using request_type = http::request; - -/// The type of object holding HTTP Upgrade responses -using response_type = http::response; - -/** The type of received control frame. - - Values of this type are passed to the control frame - callback set using @ref stream::control_callback. -*/ -enum class frame_type -{ - /// A close frame was received - close, - - /// A ping frame was received - ping, - - /// A pong frame was received - pong -}; - -//-------------------------------------------------------------------- - -/** Provides message-oriented functionality using WebSocket. - - The @ref stream class template provides asynchronous and blocking - message-oriented functionality necessary for clients and servers - to utilize the WebSocket protocol. - - For asynchronous operations, the application must ensure - that they are are all performed within the same implicit - or explicit strand. - - @par Thread Safety - @e Distinct @e objects: Safe.@n - @e Shared @e objects: Unsafe. - - @par Example - - To use the @ref stream template with an `ip::tcp::socket`, - you would write: - - @code - websocket::stream ws{io_service}; - @endcode - Alternatively, you can write: - @code - ip::tcp::socket sock{io_service}; - websocket::stream ws{sock}; - @endcode - - @tparam NextLayer The type representing the next layer, to which - data will be read and written during operations. For synchronous - operations, the type must support the @b SyncStream concept. - For asynchronous operations, the type must support the - @b AsyncStream concept. - - @note A stream object must not be moved or destroyed while there - are pending asynchronous operations associated with it. - - @par Concepts - @b AsyncStream, - @b DynamicBuffer, - @b SyncStream -*/ -template -class stream -{ - friend class detail::frame_test; - friend class stream_test; - - buffered_read_stream stream_; - - /// Identifies the role of a WebSockets stream. - enum class role_type - { - /// Stream is operating as a client. - client, - - /// Stream is operating as a server. - server - }; - - friend class frame_test; - - using control_cb_type = - std::function; - - struct op {}; - - detail::maskgen maskgen_; // source of mask keys - std::size_t rd_msg_max_ = - 16 * 1024 * 1024; // max message size - bool wr_autofrag_ = true; // auto fragment - std::size_t wr_buf_size_ = 4096; // write buffer size - std::size_t rd_buf_size_ = 4096; // read buffer size - detail::opcode wr_opcode_ = - detail::opcode::text; // outgoing message type - control_cb_type ctrl_cb_; // control callback - role_type role_; // server or client - bool failed_; // the connection failed - - bool wr_close_; // sent close frame - op* wr_block_; // op currenly writing - - ping_data* ping_data_; // where to put the payload - detail::pausation rd_op_; // paused read op - detail::pausation wr_op_; // paused write op - detail::pausation ping_op_; // paused ping op - detail::pausation close_op_; // paused close op - close_reason cr_; // set from received close frame - - // State information for the message being received - // - struct rd_t - { - // opcode of current message being read - detail::opcode op; - - // `true` if the next frame is a continuation. - bool cont; - - // Checks that test messages are valid utf8 - detail::utf8_checker utf8; - - // Size of the current message so far. - std::uint64_t size; - - // Size of the read buffer. - // This gets set to the read buffer size option at the - // beginning of sending a message, so that the option can be - // changed mid-send without affecting the current message. - std::size_t buf_size; - - // The read buffer. Used for compression and masking. - std::unique_ptr buf; - }; - - rd_t rd_; - - // State information for the message being sent - // - struct wr_t - { - // `true` if next frame is a continuation, - // `false` if next frame starts a new message - bool cont; - - // `true` if this message should be auto-fragmented - // This gets set to the auto-fragment option at the beginning - // of sending a message, so that the option can be changed - // mid-send without affecting the current message. - bool autofrag; - - // `true` if this message should be compressed. - // This gets set to the compress option at the beginning of - // of sending a message, so that the option can be changed - // mid-send without affecting the current message. - bool compress; - - // Size of the write buffer. - // This gets set to the write buffer size option at the - // beginning of sending a message, so that the option can be - // changed mid-send without affecting the current message. - std::size_t buf_size; - - // The write buffer. Used for compression and masking. - // The buffer is allocated or reallocated at the beginning of - // sending a message. - std::unique_ptr buf; - }; - - wr_t wr_; - - // State information for the permessage-deflate extension - struct pmd_t - { - // `true` if current read message is compressed - bool rd_set; - - zlib::deflate_stream zo; - zlib::inflate_stream zi; - }; - - // If not engaged, then permessage-deflate is not - // enabled for the currently active session. - std::unique_ptr pmd_; - - // Local options for permessage-deflate - permessage_deflate pmd_opts_; - - // Offer for clients, negotiated result for servers - detail::pmd_offer pmd_config_; - - void - open(role_type role); - - void - close(); - - template - std::size_t - read_fh1(detail::frame_header& fh, - DynamicBuffer& db, close_code& code); - - template - void - read_fh2(detail::frame_header& fh, - DynamicBuffer& db, close_code& code); - - // Called before receiving the first frame of each message - void - rd_begin(); - - // Called before sending the first frame of each message - // - void - wr_begin(); - - template - void - write_close(DynamicBuffer& db, close_reason const& rc); - - template - void - write_ping(DynamicBuffer& db, - detail::opcode op, ping_data const& data); - -public: - /// The type of the next layer. - using next_layer_type = - typename std::remove_reference::type; - - /// The type of the lowest layer. - using lowest_layer_type = - typename get_lowest_layer::type; - - /** Move constructor - - If @c NextLayer is move constructible, this function - will move-construct a new stream from the existing stream. - - @note The behavior of move assignment on or from streams - with active or pending operations is undefined. - */ - stream(stream&&) = default; - - /** Move assignment - - If `NextLayer` is move assignable, this function - will move-assign a new stream from the existing stream. - - @note The behavior of move assignment on or from streams - with active or pending operations is undefined. - */ - stream& operator=(stream&&) = default; - - /** Constructor - - This constructor creates a websocket stream and initializes - the next layer object. - - @throws Any exceptions thrown by the NextLayer constructor. - - @param args The arguments to be passed to initialize the - next layer object. The arguments are forwarded to the next - layer's constructor. - */ - template - explicit - stream(Args&&... args); - - /** Destructor - - @note A stream object must not be destroyed while there - are pending asynchronous operations associated with it. - */ - ~stream() = default; - - /** Return the `io_service` associated with the stream - - This function may be used to obtain the `io_service` object - that the stream uses to dispatch handlers for asynchronous - operations. - - @return A reference to the io_service object that the stream - will use to dispatch handlers. - */ - boost::asio::io_service& - get_io_service() - { - return stream_.get_io_service(); - } - - /** Get a reference to the next layer - - This function returns a reference to the next layer - in a stack of stream layers. - - @return A reference to the next layer in the stack of - stream layers. - */ - next_layer_type& - next_layer() - { - return stream_.next_layer(); - } - - /** Get a reference to the next layer - - This function returns a reference to the next layer in a - stack of stream layers. - - @return A reference to the next layer in the stack of - stream layers. - */ - next_layer_type const& - next_layer() const - { - return stream_.next_layer(); - } - - /** Get a reference to the lowest layer - - This function returns a reference to the lowest layer - in a stack of stream layers. - - @return A reference to the lowest layer in the stack of - stream layers. - */ - lowest_layer_type& - lowest_layer() - { - return stream_.lowest_layer(); - } - - /** Get a reference to the lowest layer - - This function returns a reference to the lowest layer - in a stack of stream layers. - - @return A reference to the lowest layer in the stack of - stream layers. Ownership is not transferred to the caller. - */ - lowest_layer_type const& - lowest_layer() const - { - return stream_.lowest_layer(); - } - - /// Set the permessage-deflate extension options - void - set_option(permessage_deflate const& o); - - /// Get the permessage-deflate extension options - void - get_option(permessage_deflate& o) - { - o = pmd_opts_; - } - - /** Set the automatic fragmentation option. - - Determines if outgoing message payloads are broken up into - multiple pieces. - - When the automatic fragmentation size is turned on, outgoing - message payloads are broken up into multiple frames no larger - than the write buffer size. - - The default setting is to fragment messages. - - @param v A `bool` indicating if auto fragmentation should be on. - - @par Example - Setting the automatic fragmentation option: - @code - ws.auto_fragment(true); - @endcode - */ - void - auto_fragment(bool v) - { - wr_autofrag_ = v; - } - - /// Returns `true` if the automatic fragmentation option is set. - bool - auto_fragment() const - { - return wr_autofrag_; - } - - /** Set the binary message option. - - This controls whether or not outgoing message opcodes - are set to binary or text. The setting is only applied - at the start when a caller begins a new message. Changing - the opcode after a message is started will only take effect - after the current message being sent is complete. - - The default setting is to send text messages. - - @param v `true` if outgoing messages should indicate - binary, or `false` if they should indicate text. - - @par Example - Setting the message type to binary. - @code - ws.binary(true); - @endcode - */ - void - binary(bool v) - { - wr_opcode_ = v ? - detail::opcode::binary : - detail::opcode::text; - } - - /// Returns `true` if the binary message option is set. - bool - binary() const - { - return wr_opcode_ == detail::opcode::binary; - } - - /** Set the control frame callback. - - Sets the callback to be invoked whenever a ping, pong, - or close control frame is received during a call to one - of the following functions: - - @li @ref beast::websocket::stream::read - @li @ref beast::websocket::stream::read_frame - @li @ref beast::websocket::stream::async_read - @li @ref beast::websocket::stream::async_read_frame - - Unlike completion handlers, the callback will be invoked - for each control frame during a call to any synchronous - or asynchronous read function. The operation is passive, - with no associated error code, and triggered by reads. - - The signature of the callback must be: - @code - void - callback( - frame_type kind, // The type of frame - string_view payload // The payload in the frame - ); - @endcode - - For close frames, the close reason code may be obtained by - calling the function @ref reason. - - If the read operation which receives the control frame is - an asynchronous operation, the callback will be invoked using - the same method as that used to invoke the final handler. - - @note It is not necessary to send a close frame upon receipt - of a close frame. The implementation does this automatically. - Attempting to send a close frame after a close frame is - received will result in undefined behavior. - - @param cb The callback to set. - */ - void - control_callback( - std::function cb) - { - ctrl_cb_ = std::move(cb); - } - - /** Set the read buffer size option. - - Sets the size of the read buffer used by the implementation to - receive frames. The read buffer is needed when permessage-deflate - is used. - - Lowering the size of the buffer can decrease the memory requirements - for each connection, while increasing the size of the buffer can reduce - the number of calls made to the next layer to read data. - - The default setting is 4096. The minimum value is 8. - - @param n The size of the read buffer. - - @throws std::invalid_argument If the buffer size is less than 8. - - @par Example - Setting the read buffer size. - @code - ws.read_buffer_size(16 * 1024); - @endcode - */ - void - read_buffer_size(std::size_t n) - { - if(n < 8) - BOOST_THROW_EXCEPTION(std::invalid_argument{ - "read buffer size underflow"}); - rd_buf_size_ = n; - } - - /// Returns the read buffer size setting. - std::size_t - read_buffer_size() const - { - return rd_buf_size_; - } - - /** Set the maximum incoming message size option. - - Sets the largest permissible incoming message size. Message - frame fields indicating a size that would bring the total - message size over this limit will cause a protocol failure. - - The default setting is 16 megabytes. A value of zero indicates - a limit of the maximum value of a `std::uint64_t`. - - @par Example - Setting the maximum read message size. - @code - ws.read_message_max(65536); - @endcode - - @param n The limit on the size of incoming messages. - */ - void - read_message_max(std::size_t n) - { - rd_msg_max_ = n; - } - - /// Returns the maximum incoming message size setting. - std::size_t - read_message_max() const - { - return rd_msg_max_; - } - - /** Set the write buffer size option. - - Sets the size of the write buffer used by the implementation to - send frames. The write buffer is needed when masking payload data - in the client role, compressing frames, or auto-fragmenting message - data. - - Lowering the size of the buffer can decrease the memory requirements - for each connection, while increasing the size of the buffer can reduce - the number of calls made to the next layer to write data. - - The default setting is 4096. The minimum value is 8. - - The write buffer size can only be changed when the stream is not - open. Undefined behavior results if the option is modified after a - successful WebSocket handshake. - - @par Example - Setting the write buffer size. - @code - ws.write_buffer_size(8192); - @endcode - - @param n The size of the write buffer in bytes. - */ - void - write_buffer_size(std::size_t n) - { - if(n < 8) - BOOST_THROW_EXCEPTION(std::invalid_argument{ - "write buffer size underflow"}); - wr_buf_size_ = n; - }; - - /// Returns the size of the write buffer. - std::size_t - write_buffer_size() const - { - return wr_buf_size_; - } - - /** Set the text message option. - - This controls whether or not outgoing message opcodes - are set to binary or text. The setting is only applied - at the start when a caller begins a new message. Changing - the opcode after a message is started will only take effect - after the current message being sent is complete. - - The default setting is to send text messages. - - @param v `true` if outgoing messages should indicate - text, or `false` if they should indicate binary. - - @par Example - Setting the message type to text. - @code - ws.text(true); - @endcode - */ - void - text(bool v) - { - wr_opcode_ = v ? - detail::opcode::text : - detail::opcode::binary; - } - - /// Returns `true` if the text message option is set. - bool - text() const - { - return wr_opcode_ == detail::opcode::text; - } - - /** Returns the close reason received from the peer. - - This is only valid after a read completes with error::closed. - */ - close_reason const& - reason() const - { - return cr_; - } - - /** Returns `true` if the latest message data indicates binary. - - This function informs the caller of whether the last - received message frame represents a message with the - binary opcode. - - If there is no last message frame, the return value is - undefined. - */ - bool - got_binary() - { - return rd_.op == detail::opcode::binary; - } - - /** Returns `true` if the latest message data indicates text. - - This function informs the caller of whether the last - received message frame represents a message with the - text opcode. - - If there is no last message frame, the return value is - undefined. - */ - bool - got_text() - { - return ! got_binary(); - } - - /** Read and respond to a WebSocket HTTP Upgrade request. - - This function is used to synchronously read an HTTP WebSocket - Upgrade request and send the HTTP response. The call blocks - until one of the following conditions is true: - - @li The request is received and the response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @throws system_error Thrown on failure. - */ - void - accept(); - - /** Read and respond to a WebSocket HTTP Upgrade request. - - This function is used to synchronously read an HTTP WebSocket - Upgrade request and send the HTTP response. The call blocks - until one of the following conditions is true: - - @li The request is received and the response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @param decorator A function object which will be called to modify - the HTTP response object delivered by the implementation. This - could be used to set the Server field, subprotocols, or other - application or HTTP specific fields. The object will be called - with this equivalent signature: - @code void decorator( - response_type& res - ); @endcode - - @throws system_error Thrown on failure. - */ - template - void - accept_ex(ResponseDecorator const& decorator); - - /** Read and respond to a WebSocket HTTP Upgrade request. - - This function is used to synchronously read an HTTP WebSocket - Upgrade request and send the HTTP response. The call blocks - until one of the following conditions is true: - - @li The request is received and the response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @param ec Set to indicate what error occurred, if any. - */ - void - accept(error_code& ec); - - /** Read and respond to a WebSocket HTTP Upgrade request. - - This function is used to synchronously read an HTTP WebSocket - Upgrade request and send the HTTP response. The call blocks - until one of the following conditions is true: - - @li The request is received and the response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @param decorator A function object which will be called to modify - the HTTP response object delivered by the implementation. This - could be used to set the Server field, subprotocols, or other - application or HTTP specific fields. The object will be called - with this equivalent signature: - @code void decorator( - response_type& res - ); @endcode - - @param ec Set to indicate what error occurred, if any. - */ - template - void - accept_ex(ResponseDecorator const& decorator, - error_code& ec); - - /** Read and respond to a WebSocket HTTP Upgrade request. - - This function is used to synchronously read an HTTP WebSocket - Upgrade request and send the HTTP response. The call blocks - until one of the following conditions is true: - - @li The request is received and the response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @param buffers Caller provided data that has already been - received on the stream. The implementation will copy the - caller provided data before the function returns. - - @throws system_error Thrown on failure. - */ - template -#if BEAST_DOXYGEN - void -#else - typename std::enable_if::value>::type -#endif - accept(ConstBufferSequence const& buffers); - - /** Read and respond to a WebSocket HTTP Upgrade request. - - This function is used to synchronously read an HTTP WebSocket - Upgrade request and send the HTTP response. The call blocks - until one of the following conditions is true: - - @li The request is received and the response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @param buffers Caller provided data that has already been - received on the stream. The implementation will copy the - caller provided data before the function returns. - - @param decorator A function object which will be called to modify - the HTTP response object delivered by the implementation. This - could be used to set the Server field, subprotocols, or other - application or HTTP specific fields. The object will be called - with this equivalent signature: - @code void decorator( - response_type& res - ); @endcode - - @throws system_error Thrown on failure. - */ - template -#if BEAST_DOXYGEN - void -#else - typename std::enable_if::value>::type -#endif - accept_ex(ConstBufferSequence const& buffers, - ResponseDecorator const& decorator); - - /** Read and respond to a WebSocket HTTP Upgrade request. - - This function is used to synchronously read an HTTP WebSocket - Upgrade request and send the HTTP response. The call blocks - until one of the following conditions is true: - - @li The request is received and the response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @param buffers Caller provided data that has already been - received on the stream. The implementation will copy the - caller provided data before the function returns. - - @param ec Set to indicate what error occurred, if any. - */ - template -#if BEAST_DOXYGEN - void -#else - typename std::enable_if::value>::type -#endif - accept(ConstBufferSequence const& buffers, error_code& ec); - - /** Read and respond to a WebSocket HTTP Upgrade request. - - This function is used to synchronously read an HTTP WebSocket - Upgrade request and send the HTTP response. The call blocks - until one of the following conditions is true: - - @li The request is received and the response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @param buffers Caller provided data that has already been - received on the stream. The implementation will copy the - caller provided data before the function returns. - - @param decorator A function object which will be called to modify - the HTTP response object delivered by the implementation. This - could be used to set the Server field, subprotocols, or other - application or HTTP specific fields. The object will be called - with this equivalent signature: - @code void decorator( - response_type& res - ); @endcode - - @param ec Set to indicate what error occurred, if any. - */ - template -#if BEAST_DOXYGEN - void -#else - typename std::enable_if::value>::type -#endif - accept_ex(ConstBufferSequence const& buffers, - ResponseDecorator const& decorator, - error_code& ec); - - /** Respond to a WebSocket HTTP Upgrade request - - This function is used to synchronously send the HTTP response - to an HTTP request possibly containing a WebSocket Upgrade. - The call blocks until one of the following conditions is true: - - @li The response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @param req An object containing the HTTP Upgrade request. - Ownership is not transferred, the implementation will not - access this object from other threads. - - @throws system_error Thrown on failure. - */ - template - void - accept(http::header> const& req); - - /** Respond to a WebSocket HTTP Upgrade request - - This function is used to synchronously send the HTTP response - to an HTTP request possibly containing a WebSocket Upgrade. - The call blocks until one of the following conditions is true: - - @li The response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @param req An object containing the HTTP Upgrade request. - Ownership is not transferred, the implementation will not - access this object from other threads. - - @param decorator A function object which will be called to modify - the HTTP response object delivered by the implementation. This - could be used to set the Server field, subprotocols, or other - application or HTTP specific fields. The object will be called - with this equivalent signature: - @code void decorator( - response_type& res - ); @endcode - - @throws system_error Thrown on failure. - */ - template - void - accept_ex(http::header> const& req, - ResponseDecorator const& decorator); - - /** Respond to a WebSocket HTTP Upgrade request - - This function is used to synchronously send the HTTP response - to an HTTP request possibly containing a WebSocket Upgrade. - The call blocks until one of the following conditions is true: - - @li The response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @param req An object containing the HTTP Upgrade request. - Ownership is not transferred, the implementation will not - access this object from other threads. - - @param ec Set to indicate what error occurred, if any. - */ - template - void - accept(http::header> const& req, - error_code& ec); - - /** Respond to a WebSocket HTTP Upgrade request - - This function is used to synchronously send the HTTP response - to an HTTP request possibly containing a WebSocket Upgrade. - The call blocks until one of the following conditions is true: - - @li The response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @param req An object containing the HTTP Upgrade request. - Ownership is not transferred, the implementation will not - access this object from other threads. - - @param decorator A function object which will be called to modify - the HTTP response object delivered by the implementation. This - could be used to set the Server field, subprotocols, or other - application or HTTP specific fields. The object will be called - with this equivalent signature: - @code void decorator( - response_type& res - ); @endcode - - @param ec Set to indicate what error occurred, if any. - */ - template - void - accept_ex(http::header> const& req, - ResponseDecorator const& decorator, - error_code& ec); - - /** Respond to a WebSocket HTTP Upgrade request - - This function is used to synchronously send the HTTP response - to an HTTP request possibly containing a WebSocket Upgrade. - The call blocks until one of the following conditions is true: - - @li The response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @param req An object containing the HTTP Upgrade request. - Ownership is not transferred, the implementation will not - access this object from other threads. - - @param buffers Caller provided data that has already been - received on the stream. This must not include the octets - corresponding to the HTTP Upgrade request. The implementation - will copy the caller provided data before the function returns. - - @throws system_error Thrown on failure. - */ - template - void - accept(http::header> const& req, - ConstBufferSequence const& buffers); - - /** Respond to a WebSocket HTTP Upgrade request - - This function is used to synchronously send the HTTP response - to an HTTP request possibly containing a WebSocket Upgrade. - The call blocks until one of the following conditions is true: - - @li The response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @param req An object containing the HTTP Upgrade request. - Ownership is not transferred, the implementation will not - access this object from other threads. - - @param buffers Caller provided data that has already been - received on the stream. This must not include the octets - corresponding to the HTTP Upgrade request. The implementation - will copy the caller provided data before the function returns. - - @param decorator A function object which will be called to modify - the HTTP response object delivered by the implementation. This - could be used to set the Server field, subprotocols, or other - application or HTTP specific fields. The object will be called - with this equivalent signature: - @code void decorator( - response_type& res - ); @endcode - - @throws system_error Thrown on failure. - */ - template - void - accept_ex(http::header> const& req, - ConstBufferSequence const& buffers, - ResponseDecorator const& decorator); - - /** Respond to a WebSocket HTTP Upgrade request - - This function is used to synchronously send the HTTP response - to an HTTP request possibly containing a WebSocket Upgrade. - The call blocks until one of the following conditions is true: - - @li The response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @param req An object containing the HTTP Upgrade request. - Ownership is not transferred, the implementation will not - access this object from other threads. - - @param buffers Caller provided data that has already been - received on the stream. This must not include the octets - corresponding to the HTTP Upgrade request. The implementation - will copy the caller provided data before the function returns. - - @param ec Set to indicate what error occurred, if any. - */ - template - void - accept(http::header const& req, - ConstBufferSequence const& buffers, error_code& ec); - - /** Respond to a WebSocket HTTP Upgrade request - - This function is used to synchronously send the HTTP response - to an HTTP request possibly containing a WebSocket Upgrade. - The call blocks until one of the following conditions is true: - - @li The response finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to - the next layer's `read_some` and `write_some` functions. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When this call returns, the stream is then ready to send and - receive WebSocket protocol frames and messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure. - - @param req An object containing the HTTP Upgrade request. - Ownership is not transferred, the implementation will not - access this object from other threads. - - @param buffers Caller provided data that has already been - received on the stream. This must not include the octets - corresponding to the HTTP Upgrade request. The implementation - will copy the caller provided data before the function returns. - - @param decorator A function object which will be called to modify - the HTTP response object delivered by the implementation. This - could be used to set the Server field, subprotocols, or other - application or HTTP specific fields. The object will be called - with this equivalent signature: - @code void decorator( - response_type& res - ); @endcode - - @param ec Set to indicate what error occurred, if any. - */ - template - void - accept_ex(http::header> const& req, - ConstBufferSequence const& buffers, - ResponseDecorator const& decorator, - error_code& ec); - - /** Start reading and responding to a WebSocket HTTP Upgrade request. - - This function is used to asynchronously read an HTTP WebSocket - Upgrade request and send the HTTP response. The function call - always returns immediately. The asynchronous operation will - continue until one of the following conditions is true: - - @li The request is received and the response finishes sending. - - @li An error occurs on the stream. - - This operation is implemented in terms of one or more calls to - the next layer's `async_read_some` and `async_write_some` - functions, and is known as a composed operation. The - program must ensure that the stream performs no other - asynchronous operations until this operation completes. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When the completion handler is invoked, the stream is then - ready to send and receive WebSocket protocol frames and - messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure, and - the completion handler will be invoked with a suitable error - code set. - - @param handler The handler to be called when the request - completes. Copies will be made of the handler as required. The - equivalent function signature of the handler must be: - @code void handler( - error_code const& ec // Result of operation - ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. - */ - template -#if BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - AcceptHandler, void(error_code)> -#endif - async_accept(AcceptHandler&& handler); - - /** Start reading and responding to a WebSocket HTTP Upgrade request. - - This function is used to asynchronously read an HTTP WebSocket - Upgrade request and send the HTTP response. The function call - always returns immediately. The asynchronous operation will - continue until one of the following conditions is true: - - @li The request is received and the response finishes sending. - - @li An error occurs on the stream. - - This operation is implemented in terms of one or more calls to - the next layer's `async_read_some` and `async_write_some` - functions, and is known as a composed operation. The - program must ensure that the stream performs no other - asynchronous operations until this operation completes. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When the completion handler is invoked, the stream is then - ready to send and receive WebSocket protocol frames and - messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure, and - the completion handler will be invoked with a suitable error - code set. - - @param decorator A function object which will be called to modify - the HTTP response object delivered by the implementation. This - could be used to set the Server field, subprotocols, or other - application or HTTP specific fields. The object will be called - with this equivalent signature: - @code void decorator( - response_type& res - ); @endcode - - @param handler The handler to be called when the request - completes. Copies will be made of the handler as required. The - equivalent function signature of the handler must be: - @code void handler( - error_code const& ec // Result of operation - ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. - */ - template -#if BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - AcceptHandler, void(error_code)> -#endif - async_accept_ex(ResponseDecorator const& decorator, - AcceptHandler&& handler); - - /** Start reading and responding to a WebSocket HTTP Upgrade request. - - This function is used to asynchronously read an HTTP WebSocket - Upgrade request and send the HTTP response. The function call - always returns immediately. The asynchronous operation will - continue until one of the following conditions is true: - - @li The request is received and the response finishes sending. - - @li An error occurs on the stream. - - This operation is implemented in terms of one or more calls to - the next layer's `async_read_some` and `async_write_some` - functions, and is known as a composed operation. The - program must ensure that the stream performs no other - asynchronous operations until this operation completes. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When the completion handler is invoked, the stream is then - ready to send and receive WebSocket protocol frames and - messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure, and - the completion handler will be invoked with a suitable error - code set. - - @param buffers Caller provided data that has already been - received on the stream. This may be used for implementations - allowing multiple protocols on the same stream. The - buffered data will first be applied to the handshake, and - then to received WebSocket frames. The implementation will - copy the caller provided data before the function returns. - - @param handler The handler to be called when the request - completes. Copies will be made of the handler as required. The - equivalent function signature of the handler must be: - @code void handler( - error_code const& ec // Result of operation - ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. - */ - template -#if BEAST_DOXYGEN - void_or_deduced -#else - typename std::enable_if< - ! http::detail::is_header::value, - async_return_type>::type -#endif - async_accept(ConstBufferSequence const& buffers, - AcceptHandler&& handler); - - /** Start reading and responding to a WebSocket HTTP Upgrade request. - - This function is used to asynchronously read an HTTP WebSocket - Upgrade request and send the HTTP response. The function call - always returns immediately. The asynchronous operation will - continue until one of the following conditions is true: - - @li The request is received and the response finishes sending. - - @li An error occurs on the stream. - - This operation is implemented in terms of one or more calls to - the next layer's `async_read_some` and `async_write_some` - functions, and is known as a composed operation. The - program must ensure that the stream performs no other - asynchronous operations until this operation completes. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When the completion handler is invoked, the stream is then - ready to send and receive WebSocket protocol frames and - messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure, and - the completion handler will be invoked with a suitable error - code set. - - @param buffers Caller provided data that has already been - received on the stream. This may be used for implementations - allowing multiple protocols on the same stream. The - buffered data will first be applied to the handshake, and - then to received WebSocket frames. The implementation will - copy the caller provided data before the function returns. - - @param decorator A function object which will be called to modify - the HTTP response object delivered by the implementation. This - could be used to set the Server field, subprotocols, or other - application or HTTP specific fields. The object will be called - with this equivalent signature: - @code void decorator( - response_type& res - ); @endcode - - @param handler The handler to be called when the request - completes. Copies will be made of the handler as required. The - equivalent function signature of the handler must be: - @code void handler( - error_code const& ec // Result of operation - ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. - */ - template -#if BEAST_DOXYGEN - void_or_deduced -#else - typename std::enable_if< - ! http::detail::is_header::value, - async_return_type>::type -#endif - async_accept_ex(ConstBufferSequence const& buffers, - ResponseDecorator const& decorator, - AcceptHandler&& handler); - - /** Start responding to a WebSocket HTTP Upgrade request. - - This function is used to asynchronously send the HTTP response - to an HTTP request possibly containing a WebSocket Upgrade - request. The function call always returns immediately. The - asynchronous operation will continue until one of the following - conditions is true: - - @li The response finishes sending. - - @li An error occurs on the stream. - - This operation is implemented in terms of one or more calls to - the next layer's `async_write_some` functions, and is known as - a composed operation. The program must ensure that the - stream performs no other operations until this operation - completes. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When the completion handler is invoked, the stream is then - ready to send and receive WebSocket protocol frames and - messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure, and - the completion handler will be invoked with a suitable error - code set. - - @param req An object containing the HTTP Upgrade request. - Ownership is not transferred, the implementation will not access - this object from other threads. - - @param handler The handler to be called when the request - completes. Copies will be made of the handler as required. The - equivalent function signature of the handler must be: - @code void handler( - error_code const& ec // Result of operation - ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. - */ - template -#if BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - AcceptHandler, void(error_code)> -#endif - async_accept(http::header> const& req, - AcceptHandler&& handler); - - /** Start responding to a WebSocket HTTP Upgrade request. - - This function is used to asynchronously send the HTTP response - to an HTTP request possibly containing a WebSocket Upgrade - request. The function call always returns immediately. The - asynchronous operation will continue until one of the following - conditions is true: - - @li The response finishes sending. - - @li An error occurs on the stream. - - This operation is implemented in terms of one or more calls to - the next layer's `async_write_some` functions, and is known as - a composed operation. The program must ensure that the - stream performs no other operations until this operation - completes. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When the completion handler is invoked, the stream is then - ready to send and receive WebSocket protocol frames and - messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure, and - the completion handler will be invoked with a suitable error - code set. - - @param req An object containing the HTTP Upgrade request. - Ownership is not transferred, the implementation will not access - this object from other threads. - - @param decorator A function object which will be called to modify - the HTTP response object delivered by the implementation. This - could be used to set the Server field, subprotocols, or other - application or HTTP specific fields. The object will be called - with this equivalent signature: - @code void decorator( - response_type& res - ); @endcode - - @param handler The handler to be called when the request - completes. Copies will be made of the handler as required. The - equivalent function signature of the handler must be: - @code void handler( - error_code const& ec // Result of operation - ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. - */ - template -#if BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - AcceptHandler, void(error_code)> -#endif - async_accept_ex(http::header> const& req, - ResponseDecorator const& decorator, - AcceptHandler&& handler); - - /** Start responding to a WebSocket HTTP Upgrade request. - - This function is used to asynchronously send the HTTP response - to an HTTP request possibly containing a WebSocket Upgrade - request. The function call always returns immediately. The - asynchronous operation will continue until one of the following - conditions is true: - - @li The response finishes sending. - - @li An error occurs on the stream. - - This operation is implemented in terms of one or more calls to - the next layer's `async_write_some` functions, and is known as - a composed operation. The program must ensure that the - stream performs no other operations until this operation - completes. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When the completion handler is invoked, the stream is then - ready to send and receive WebSocket protocol frames and - messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure, and - the completion handler will be invoked with a suitable error - code set. - - @param req An object containing the HTTP Upgrade request. - Ownership is not transferred, the implementation will not access - this object from other threads. - - @param buffers Caller provided data that has already been - received on the stream. This may be used for implementations - allowing multiple protocols on the same stream. The - buffered data will first be applied to the handshake, and - then to received WebSocket frames. The implementation will - copy the caller provided data before the function returns. - - @param handler The handler to be called when the request - completes. Copies will be made of the handler as required. The - equivalent function signature of the handler must be: - @code void handler( - error_code const& ec // Result of operation - ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. - */ - template -#if BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - AcceptHandler, void(error_code)> -#endif - async_accept(http::header> const& req, - ConstBufferSequence const& buffers, - AcceptHandler&& handler); - - /** Start responding to a WebSocket HTTP Upgrade request. - - This function is used to asynchronously send the HTTP response - to an HTTP request possibly containing a WebSocket Upgrade - request. The function call always returns immediately. The - asynchronous operation will continue until one of the following - conditions is true: - - @li The response finishes sending. - - @li An error occurs on the stream. - - This operation is implemented in terms of one or more calls to - the next layer's `async_write_some` functions, and is known as - a composed operation. The program must ensure that the - stream performs no other operations until this operation - completes. - - If the stream receives a valid HTTP WebSocket Upgrade request, - an HTTP response is sent back indicating a successful upgrade. - When the completion handler is invoked, the stream is then - ready to send and receive WebSocket protocol frames and - messages. - - If the HTTP Upgrade request is invalid or cannot be satisfied, - an HTTP response is sent indicating the reason and status code - (typically 400, "Bad Request"). This counts as a failure, and - the completion handler will be invoked with a suitable error - code set. - - @param req An object containing the HTTP Upgrade request. - Ownership is not transferred, the implementation will not access - this object from other threads. - - @param buffers Caller provided data that has already been - received on the stream. This may be used for implementations - allowing multiple protocols on the same stream. The - buffered data will first be applied to the handshake, and - then to received WebSocket frames. The implementation will - copy the caller provided data before the function returns. - - @param decorator A function object which will be called to modify - the HTTP response object delivered by the implementation. This - could be used to set the Server field, subprotocols, or other - application or HTTP specific fields. The object will be called - with this equivalent signature: - @code void decorator( - response_type& res - ); @endcode - - @param handler The handler to be called when the request - completes. Copies will be made of the handler as required. The - equivalent function signature of the handler must be: - @code void handler( - error_code const& ec // Result of operation - ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. - */ - template -#if BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - AcceptHandler, void(error_code)> -#endif - async_accept_ex(http::header> const& req, - ConstBufferSequence const& buffers, - ResponseDecorator const& decorator, - AcceptHandler&& handler); - - /** Send an HTTP WebSocket Upgrade request and receive the response. - - This function is used to synchronously send the WebSocket - upgrade HTTP request. The call blocks until one of the - following conditions is true: - - @li The request is sent and the response is received. - - @li An error occurs on the stream - - This function is implemented in terms of one or more calls to the - next layer's `read_some` and `write_some` functions. - - The operation is successful if the received HTTP response indicates - a successful HTTP Upgrade (represented by a Status-Code of 101, - "switching protocols"). - - @param host The name of the remote host, - required by the HTTP protocol. - - @param target The Request Target, which may not be empty, - required by the HTTP protocol. - - @throws system_error Thrown on failure. - - @par Example - @code - websocket::stream ws{io_service}; - ... - try - { - ws.handshake("localhost", "/"); - } - catch(...) - { - // An error occurred. - } - @endcode - */ - void - handshake(string_view host, string_view target); - - /** Send an HTTP WebSocket Upgrade request and receive the response. - - This function is used to synchronously send the WebSocket - upgrade HTTP request. The call blocks until one of the - following conditions is true: - - @li The request is sent and the response is received. - - @li An error occurs on the stream - - This function is implemented in terms of one or more calls to the - next layer's `read_some` and `write_some` functions. - - The operation is successful if the received HTTP response indicates - a successful HTTP Upgrade (represented by a Status-Code of 101, - "switching protocols"). - - @param res The HTTP Upgrade response returned by the remote - endpoint. - - @param host The name of the remote host, - required by the HTTP protocol. - - @param target The Request Target, which may not be empty, - required by the HTTP protocol. - - @throws system_error Thrown on failure. - - @par Example - @code - websocket::stream ws{io_service}; - ... - try - { - response_type res; - ws.handshake(res, "localhost", "/"); - } - catch(...) - { - // An error occurred. - } - @endcode - */ - void - handshake(response_type& res, - string_view host, string_view target); - - /** Send an HTTP WebSocket Upgrade request and receive the response. - - This function is used to synchronously send the WebSocket - upgrade HTTP request. The call blocks until one of the - following conditions is true: - - @li The request is sent and the response is received. - - @li An error occurs on the stream - - This function is implemented in terms of one or more calls to the - next layer's `read_some` and `write_some` functions. - - The operation is successful if the received HTTP response indicates - a successful HTTP Upgrade (represented by a Status-Code of 101, - "switching protocols"). - - @param host The name of the remote host, - required by the HTTP protocol. - - @param target The Request Target, which may not be empty, - required by the HTTP protocol. - - @param decorator A function object which will be called to modify - the HTTP request object generated by the implementation. This - could be used to set the User-Agent field, subprotocols, or other - application or HTTP specific fields. The object will be called - with this equivalent signature: - @code void decorator( - request_type& req - ); @endcode - - @throws system_error Thrown on failure. - - @par Example - @code - websocket::stream ws{io_service}; - ... - try - { - ws.handshake("localhost", "/", - [](request_type& req) - { - req.set(field::user_agent, "Beast"); - }); - } - catch(...) - { - // An error occurred. - } - @endcode - */ - template - void - handshake_ex(string_view host, string_view target, - RequestDecorator const& decorator); - - /** Send an HTTP WebSocket Upgrade request and receive the response. - - This function is used to synchronously send the WebSocket - upgrade HTTP request. The call blocks until one of the - following conditions is true: - - @li The request is sent and the response is received. - - @li An error occurs on the stream - - This function is implemented in terms of one or more calls to the - next layer's `read_some` and `write_some` functions. - - The operation is successful if the received HTTP response indicates - a successful HTTP Upgrade (represented by a Status-Code of 101, - "switching protocols"). - - @param res The HTTP Upgrade response returned by the remote - endpoint. - - @param host The name of the remote host, - required by the HTTP protocol. - - @param target The Request Target, which may not be empty, - required by the HTTP protocol. - - @param decorator A function object which will be called to modify - the HTTP request object generated by the implementation. This - could be used to set the User-Agent field, subprotocols, or other - application or HTTP specific fields. The object will be called - with this equivalent signature: - @code void decorator( - request_type& req - ); @endcode - - @throws system_error Thrown on failure. - - @par Example - @code - websocket::stream ws{io_service}; - ... - try - { - response_type res; - ws.handshake(res, "localhost", "/", - [](request_type& req) - { - req.set(field::user_agent, "Beast"); - }); - } - catch(...) - { - // An error occurred. - } - @endcode - */ - template - void - handshake_ex(response_type& res, - string_view host, string_view target, - RequestDecorator const& decorator); - - /** Send an HTTP WebSocket Upgrade request and receive the response. - - This function is used to synchronously send the WebSocket - upgrade HTTP request. The call blocks until one of the - following conditions is true: - - @li The request is sent and the response is received. - - @li An error occurs on the stream - - This function is implemented in terms of one or more calls to the - next layer's `read_some` and `write_some` functions. - - The operation is successful if the received HTTP response indicates - a successful HTTP Upgrade (represented by a Status-Code of 101, - "switching protocols"). - - @param host The name of the remote host, - required by the HTTP protocol. - - @param target The Request Target, which may not be empty, - required by the HTTP protocol. - - @param ec Set to indicate what error occurred, if any. - - @par Example - @code - websocket::stream ws{io_service}; - ... - error_code ec; - ws.handshake(host, target, ec); - if(ec) - { - // An error occurred. - } - @endcode - */ - void - handshake(string_view host, - string_view target, error_code& ec); - - /** Send an HTTP WebSocket Upgrade request and receive the response. - - This function is used to synchronously send the WebSocket - upgrade HTTP request. The call blocks until one of the - following conditions is true: - - @li The request is sent and the response is received. - - @li An error occurs on the stream - - This function is implemented in terms of one or more calls to the - next layer's `read_some` and `write_some` functions. - - The operation is successful if the received HTTP response indicates - a successful HTTP Upgrade (represented by a Status-Code of 101, - "switching protocols"). - - @param host The name of the remote host, - required by the HTTP protocol. - - @param target The Request Target, which may not be empty, - required by the HTTP protocol. - - @param ec Set to indicate what error occurred, if any. - - @param res The HTTP Upgrade response returned by the remote - endpoint. If `ec is set, the return value is undefined. - - @par Example - @code - websocket::stream ws{io_service}; - ... - error_code ec; - response_type res; - ws.handshake(res, host, target, ec); - if(ec) - { - // An error occurred. - } - @endcode - */ - void - handshake(response_type& res, - string_view host, string_view target, error_code& ec); - - /** Send an HTTP WebSocket Upgrade request and receive the response. - - This function is used to synchronously send the WebSocket - upgrade HTTP request. The call blocks until one of the - following conditions is true: - - @li The request is sent and the response is received. - - @li An error occurs on the stream - - This function is implemented in terms of one or more calls to the - next layer's `read_some` and `write_some` functions. - - The operation is successful if the received HTTP response indicates - a successful HTTP Upgrade (represented by a Status-Code of 101, - "switching protocols"). - - @param host The name of the remote host, - required by the HTTP protocol. - - @param target The Request Target, which may not be empty, - required by the HTTP protocol. - - @param decorator A function object which will be called to modify - the HTTP request object generated by the implementation. This - could be used to set the User-Agent field, subprotocols, or other - application or HTTP specific fields. The object will be called - with this equivalent signature: - @code void decorator( - request_type& req - ); @endcode - - @param ec Set to indicate what error occurred, if any. - - @par Example - @code - websocket::stream ws{io_service}; - ... - error_code ec; - ws.handshake("localhost", "/", - [](request_type& req) - { - req.set(field::user_agent, "Beast"); - }, - ec); - if(ec) - { - // An error occurred. - } - @endcode - */ - template - void - handshake_ex(string_view host, - string_view target, RequestDecorator const& decorator, - error_code& ec); - - /** Send an HTTP WebSocket Upgrade request and receive the response. - - This function is used to synchronously send the WebSocket - upgrade HTTP request. The call blocks until one of the - following conditions is true: - - @li The request is sent and the response is received. - - @li An error occurs on the stream - - This function is implemented in terms of one or more calls to the - next layer's `read_some` and `write_some` functions. - - The operation is successful if the received HTTP response indicates - a successful HTTP Upgrade (represented by a Status-Code of 101, - "switching protocols"). - - @param res The HTTP Upgrade response returned by the remote - endpoint. - - @param host The name of the remote host, - required by the HTTP protocol. - - @param target The Request Target, which may not be empty, - required by the HTTP protocol. - - @param decorator A function object which will be called to modify - the HTTP request object generated by the implementation. This - could be used to set the User-Agent field, subprotocols, or other - application or HTTP specific fields. The object will be called - with this equivalent signature: - @code void decorator( - request_type& req - ); @endcode - - @param ec Set to indicate what error occurred, if any. - - @par Example - @code - websocket::stream ws{io_service}; - ... - error_code ec; - response_type res; - ws.handshake(res, "localhost", "/", - [](request_type& req) - { - req.set(field::user_agent, "Beast"); - }, - ec); - if(ec) - { - // An error occurred. - } - @endcode - */ - template - void - handshake_ex(response_type& res, - string_view host, string_view target, - RequestDecorator const& decorator, error_code& ec); - - /** Start an asynchronous operation to send an upgrade request and receive the response. - - This function is used to asynchronously send the HTTP WebSocket - upgrade request and receive the HTTP WebSocket Upgrade response. - This function call always returns immediately. The asynchronous - operation will continue until one of the following conditions is - true: - - @li The request is sent and the response is received. - - @li An error occurs on the stream - - This operation is implemented in terms of one or more calls to the - next layer's `async_read_some` and `async_write_some` functions, and - is known as a composed operation. The program must ensure - that the stream performs no other operations until this operation - completes. - - The operation is successful if the received HTTP response indicates - a successful HTTP Upgrade (represented by a Status-Code of 101, - "switching protocols"). - - @param host The name of the remote host, required by - the HTTP protocol. Copies may be made as needed. - - @param target The Request Target, which may not be empty, - required by the HTTP protocol. Copies of this parameter may - be made as needed. - - @param handler The handler to be called when the request completes. - Copies will be made of the handler as required. The equivalent - function signature of the handler must be: - @code void handler( - error_code const& ec // Result of operation - ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. - */ - template -#if BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - HandshakeHandler, void(error_code)> -#endif - async_handshake(string_view host, - string_view target, HandshakeHandler&& handler); - - /** Start an asynchronous operation to send an upgrade request and receive the response. - - This function is used to asynchronously send the HTTP WebSocket - upgrade request and receive the HTTP WebSocket Upgrade response. - This function call always returns immediately. The asynchronous - operation will continue until one of the following conditions is - true: - - @li The request is sent and the response is received. - - @li An error occurs on the stream - - This operation is implemented in terms of one or more calls to the - next layer's `async_read_some` and `async_write_some` functions, and - is known as a composed operation. The program must ensure - that the stream performs no other operations until this operation - completes. - - The operation is successful if the received HTTP response indicates - a successful HTTP Upgrade (represented by a Status-Code of 101, - "switching protocols"). - - @param res The HTTP Upgrade response returned by the remote - endpoint. The caller must ensure this object is valid for at - least until the completion handler is invoked. - - @param host The name of the remote host, required by - the HTTP protocol. Copies may be made as needed. - - @param target The Request Target, which may not be empty, - required by the HTTP protocol. Copies of this parameter may - be made as needed. - - @param handler The handler to be called when the request completes. - Copies will be made of the handler as required. The equivalent - function signature of the handler must be: - @code void handler( - error_code const& ec // Result of operation - ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. - */ - template -#if BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - HandshakeHandler, void(error_code)> -#endif - async_handshake(response_type& res, - string_view host, string_view target, - HandshakeHandler&& handler); - - /** Start an asynchronous operation to send an upgrade request and receive the response. - - This function is used to asynchronously send the HTTP WebSocket - upgrade request and receive the HTTP WebSocket Upgrade response. - This function call always returns immediately. The asynchronous - operation will continue until one of the following conditions is - true: - - @li The request is sent and the response is received. - - @li An error occurs on the stream - - This operation is implemented in terms of one or more calls to the - next layer's `async_read_some` and `async_write_some` functions, and - is known as a composed operation. The program must ensure - that the stream performs no other operations until this operation - completes. - - The operation is successful if the received HTTP response indicates - a successful HTTP Upgrade (represented by a Status-Code of 101, - "switching protocols"). - - @param host The name of the remote host, required by - the HTTP protocol. Copies may be made as needed. - - @param target The Request Target, which may not be empty, - required by the HTTP protocol. Copies of this parameter may - be made as needed. - - @param decorator A function object which will be called to modify - the HTTP request object generated by the implementation. This - could be used to set the User-Agent field, subprotocols, or other - application or HTTP specific fields. The object will be called - with this equivalent signature: - @code void decorator( - request_type& req - ); @endcode - - @param handler The handler to be called when the request completes. - Copies will be made of the handler as required. The equivalent - function signature of the handler must be: - @code void handler( - error_code const& ec // Result of operation - ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. - */ - template -#if BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - HandshakeHandler, void(error_code)> -#endif - async_handshake_ex(string_view host, - string_view target, RequestDecorator const& decorator, - HandshakeHandler&& handler); - - /** Start an asynchronous operation to send an upgrade request and receive the response. - - This function is used to asynchronously send the HTTP WebSocket - upgrade request and receive the HTTP WebSocket Upgrade response. - This function call always returns immediately. The asynchronous - operation will continue until one of the following conditions is - true: - - @li The request is sent and the response is received. - - @li An error occurs on the stream - - This operation is implemented in terms of one or more calls to the - next layer's `async_read_some` and `async_write_some` functions, and - is known as a composed operation. The program must ensure - that the stream performs no other operations until this operation - completes. - - The operation is successful if the received HTTP response indicates - a successful HTTP Upgrade (represented by a Status-Code of 101, - "switching protocols"). - - @param res The HTTP Upgrade response returned by the remote - endpoint. The caller must ensure this object is valid for at - least until the completion handler is invoked. - - @param host The name of the remote host, required by - the HTTP protocol. Copies may be made as needed. - - @param target The Request Target, which may not be empty, - required by the HTTP protocol. Copies of this parameter may - be made as needed. - - @param decorator A function object which will be called to modify - the HTTP request object generated by the implementation. This - could be used to set the User-Agent field, subprotocols, or other - application or HTTP specific fields. The object will be called - with this equivalent signature: - @code void decorator( - request_type& req - ); @endcode - - @param handler The handler to be called when the request completes. - Copies will be made of the handler as required. The equivalent - function signature of the handler must be: - @code void handler( - error_code const& ec // Result of operation - ); @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. - */ - template -#if BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - HandshakeHandler, void(error_code)> -#endif - async_handshake_ex(response_type& res, - string_view host, string_view target, - RequestDecorator const& decorator, - HandshakeHandler&& handler); - - /** Send a WebSocket close frame. - - This function is used to synchronously send a close frame on - the stream. The call blocks until one of the following is true: - - @li The close frame finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls - to the next layer's `write_some` functions. - - If the close reason specifies a close code other than - @ref beast::websocket::close_code::none, the close frame is - sent with the close code and optional reason string. Otherwise, - the close frame is sent with no payload. - - Callers should not attempt to write WebSocket data after - initiating the close. Instead, callers should continue - reading until an error occurs. A read returning @ref error::closed - indicates a successful connection closure. - - @param cr The reason for the close. - - @throws system_error Thrown on failure. - */ - void - close(close_reason const& cr); - - /** Send a WebSocket close frame. - - This function is used to synchronously send a close frame on - the stream. The call blocks until one of the following is true: - - @li The close frame finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls - to the next layer's `write_some` functions. - - If the close reason specifies a close code other than - @ref beast::websocket::close_code::none, the close frame is - sent with the close code and optional reason string. Otherwise, - the close frame is sent with no payload. - - Callers should not attempt to write WebSocket data after - initiating the close. Instead, callers should continue - reading until an error occurs. A read returning @ref error::closed - indicates a successful connection closure. - - @param cr The reason for the close. - - @param ec Set to indicate what error occurred, if any. - */ - void - close(close_reason const& cr, error_code& ec); - - /** Start an asynchronous operation to send a WebSocket close frame. - - This function is used to asynchronously send a close frame on - the stream. This function call always returns immediately. The - asynchronous operation will continue until one of the following - conditions is true: - - @li The close frame finishes sending. - - @li An error occurs on the stream. - - This operation is implemented in terms of one or more calls to the - next layer's `async_write_some` functions, and is known as a - composed operation. The program must ensure that the - stream performs no other write operations (such as @ref async_ping, - @ref stream::async_write, @ref stream::async_write_frame, or - @ref stream::async_close) until this operation completes. - - If the close reason specifies a close code other than - @ref beast::websocket::close_code::none, the close frame is - sent with the close code and optional reason string. Otherwise, - the close frame is sent with no payload. - - Callers should not attempt to write WebSocket data after - initiating the close. Instead, callers should continue - reading until an error occurs. A read returning @ref error::closed - indicates a successful connection closure. - - @param cr The reason for the close. - - @param handler The handler to be called when the close operation - completes. Copies will be made of the handler as required. The - function signature of the handler must be: - @code - void handler( - error_code const& ec // Result of operation - ); - @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. - */ - template -#if BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - CloseHandler, void(error_code)> -#endif - async_close(close_reason const& cr, CloseHandler&& handler); - - /** Send a WebSocket ping frame. - - This function is used to synchronously send a ping frame on - the stream. The call blocks until one of the following is true: - - @li The ping frame finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to the - next layer's `write_some` functions. - - @param payload The payload of the ping message, which may be empty. - - @throws system_error Thrown on failure. - */ - void - ping(ping_data const& payload); - - /** Send a WebSocket ping frame. - - This function is used to synchronously send a ping frame on - the stream. The call blocks until one of the following is true: - - @li The ping frame finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to the - next layer's `write_some` functions. - - @param payload The payload of the ping message, which may be empty. - - @param ec Set to indicate what error occurred, if any. - */ - void - ping(ping_data const& payload, error_code& ec); - - /** Start an asynchronous operation to send a WebSocket ping frame. - - This function is used to asynchronously send a ping frame to - the stream. The function call always returns immediately. The - asynchronous operation will continue until one of the following - is true: - - @li The entire ping frame is sent. - - @li An error occurs on the stream. - - This operation is implemented in terms of one or more calls to the - next layer's `async_write_some` functions, and is known as a - composed operation. The program must ensure that the - stream performs no other writes until this operation completes. - - If a close frame is sent or received before the ping frame is - sent, the completion handler will be called with the error - set to `boost::asio::error::operation_aborted`. - - @param payload The payload of the ping message, which may be empty. - - @param handler The handler to be called when the read operation - completes. Copies will be made of the handler as required. The - function signature of the handler must be: - @code - void handler( - error_code const& ec // Result of operation - ); - @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. - */ - template -#if BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - WriteHandler, void(error_code)> -#endif - async_ping(ping_data const& payload, WriteHandler&& handler); - - /** Send a WebSocket pong frame. - - This function is used to synchronously send a pong frame on - the stream. The call blocks until one of the following is true: - - @li The pong frame finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to the - next layer's `write_some` functions. - - The WebSocket protocol allows pong frames to be sent from either - end at any time. It is not necessary to first receive a ping in - order to send a pong. The remote peer may use the receipt of a - pong frame as an indication that the connection is not dead. - - @param payload The payload of the pong message, which may be empty. - - @throws system_error Thrown on failure. - */ - void - pong(ping_data const& payload); - - /** Send a WebSocket pong frame. - - This function is used to synchronously send a pong frame on - the stream. The call blocks until one of the following is true: - - @li The pong frame finishes sending. - - @li An error occurs on the stream. - - This function is implemented in terms of one or more calls to the - next layer's `write_some` functions. - - The WebSocket protocol allows pong frames to be sent from either - end at any time. It is not necessary to first receive a ping in - order to send a pong. The remote peer may use the receipt of a - pong frame as an indication that the connection is not dead. - - @param payload The payload of the pong message, which may be empty. - - @param ec Set to indicate what error occurred, if any. - */ - void - pong(ping_data const& payload, error_code& ec); - - /** Start an asynchronous operation to send a WebSocket pong frame. - - This function is used to asynchronously send a pong frame to - the stream. The function call always returns immediately. The - asynchronous operation will continue until one of the following - is true: - - @li The entire pong frame is sent. - - @li An error occurs on the stream. - - This operation is implemented in terms of one or more calls to the - next layer's `async_write_some` functions, and is known as a - composed operation. The program must ensure that the - stream performs no other writes until this operation completes. - - The WebSocket protocol allows pong frames to be sent from either - end at any time. It is not necessary to first receive a ping in - order to send a pong. The remote peer may use the receipt of a - pong frame as an indication that the connection is not dead. - - If a close frame is sent or received before the pong frame is - sent, the completion handler will be called with the error - set to `boost::asio::error::operation_aborted`. - - @param payload The payload of the pong message, which may be empty. - - @param handler The handler to be called when the read operation - completes. Copies will be made of the handler as required. The - function signature of the handler must be: - @code - void handler( - error_code const& ec // Result of operation - ); - @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. - */ - template -#if BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - WriteHandler, void(error_code)> -#endif - async_pong(ping_data const& payload, WriteHandler&& handler); - - /** Read a message from the stream. - - This function is used to synchronously read a message from - the stream. The call blocks until one of the following is true: - - @li A complete message is received. - - @li An error occurs on the stream. - - This call is implemented in terms of one or more calls to the - stream's `read_some` and `write_some` operations. - - Upon a success, the input area of the stream buffer will - hold the received message payload bytes (which may be zero - in length). The functions @ref got_binary and @ref got_text - may be used to query the stream and determine the type - of the last received message. - - During reads, the implementation handles control frames as - follows: - - @li A pong frame is sent when a ping frame is received. - - @li The @ref control_callback is invoked when a ping frame - or pong frame is received. - - @li The WebSocket close procedure is started if a close frame - is received. In this case, the operation will eventually - complete with the error set to @ref error::closed. - - @param buffer A dynamic buffer to hold the message data after - any masking or decompression has been applied. - - @throws system_error Thrown on failure. - */ - template - void - read(DynamicBuffer& buffer); - - /** Read a message from the stream. - - This function is used to synchronously read a message from - the stream. The call blocks until one of the following is true: - - @li A complete message is received. - - @li An error occurs on the stream. - - This call is implemented in terms of one or more calls to the - stream's `read_some` and `write_some` operations. - - Upon a success, the input area of the stream buffer will - hold the received message payload bytes (which may be zero - in length). The functions @ref got_binary and @ref got_text - may be used to query the stream and determine the type - of the last received message. - - During reads, the implementation handles control frames as - follows: - - @li The @ref control_callback is invoked when a ping frame - or pong frame is received. - - @li A pong frame is sent when a ping frame is received. - - @li The WebSocket close procedure is started if a close frame - is received. In this case, the operation will eventually - complete with the error set to @ref error::closed. - - @param buffer A dynamic buffer to hold the message data after - any masking or decompression has been applied. - - @param ec Set to indicate what error occurred, if any. - */ - template - void - read(DynamicBuffer& buffer, error_code& ec); - - /** Start an asynchronous operation to read a message from the stream. - - This function is used to asynchronously read a message from - the stream. The function call always returns immediately. The - asynchronous operation will continue until one of the following - is true: - - @li A complete message is received. - - @li An error occurs on the stream. - - This operation is implemented in terms of one or more calls to the - next layer's `async_read_some` and `async_write_some` functions, - and is known as a composed operation. The program must - ensure that the stream performs no other reads until this operation - completes. - - Upon a success, the input area of the stream buffer will - hold the received message payload bytes (which may be zero - in length). The functions @ref got_binary and @ref got_text - may be used to query the stream and determine the type - of the last received message. - - During reads, the implementation handles control frames as - follows: - - @li The @ref control_callback is invoked when a ping frame - or pong frame is received. - - @li A pong frame is sent when a ping frame is received. - - @li The WebSocket close procedure is started if a close frame - is received. In this case, the operation will eventually - complete with the error set to @ref error::closed. - - Because of the need to handle control frames, read operations - can cause writes to take place. These writes are managed - transparently; callers can still have one active asynchronous - read and asynchronous write operation pending simultaneously - (a user initiated call to @ref async_close counts as a write). - - @param buffer A dynamic buffer to hold the message data after - any masking or decompression has been applied. This object must - remain valid until the handler is called. - - @param handler The handler to be called when the read operation - completes. Copies will be made of the handler as required. The - function signature of the handler must be: - @code - void handler( - error_code const& ec // Result of operation - ); - @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. - */ - template -#if BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - ReadHandler, void(error_code)> -#endif - async_read(DynamicBuffer& buffer, ReadHandler&& handler); - - /** Read a message frame from the stream. - - This function is used to synchronously read a single message - frame from the stream. The call blocks until one of the following - is true: - - @li A complete frame is received. - - @li An error occurs on the stream. - - This call is implemented in terms of one or more calls to the - stream's `read_some` and `write_some` operations. - - During reads, the implementation handles control frames as - follows: - - @li The @ref control_callback is invoked when a ping frame - or pong frame is received. - - @li A pong frame is sent when a ping frame is received. - - @li The WebSocket close procedure is started if a close frame - is received. In this case, the operation will eventually - complete with the error set to @ref error::closed. - - @param buffer A dynamic buffer to hold the message data after - any masking or decompression has been applied. - - @return `true` if this is the last frame of the message. - - @throws system_error Thrown on failure. - */ - template - bool - read_frame(DynamicBuffer& buffer); - - /** Read a message frame from the stream. - - This function is used to synchronously read a single message - frame from the stream. The call blocks until one of the following - is true: - - @li A complete frame is received. - - @li An error occurs on the stream. - - This call is implemented in terms of one or more calls to the - stream's `read_some` and `write_some` operations. - - During reads, the implementation handles control frames as - follows: - - @li The @ref control_callback is invoked when a ping frame - or pong frame is received. - - @li A pong frame is sent when a ping frame is received. - - @li The WebSocket close procedure is started if a close frame - is received. In this case, the operation will eventually - complete with the error set to @ref error::closed. - - @param buffer A dynamic buffer to hold the message data after - any masking or decompression has been applied. - - @param ec Set to indicate what error occurred, if any. - - @return `true` if this is the last frame of the message. - */ - template - bool - read_frame(DynamicBuffer& buffer, error_code& ec); - - /** Start an asynchronous operation to read a message frame from the stream. - - This function is used to asynchronously read a single message - frame from the websocket. The function call always returns - immediately. The asynchronous operation will continue until - one of the following conditions is true: - - @li A complete frame is received. - - @li An error occurs on the stream. - - This operation is implemented in terms of one or more calls to the - next layer's `async_read_some` and `async_write_some` functions, - and is known as a composed operation. The program must - ensure that the stream performs no other reads until this operation - completes. - - During reads, the implementation handles control frames as - follows: - - @li The @ref control_callback is invoked when a ping frame - or pong frame is received. - - @li A pong frame is sent when a ping frame is received. - - @li The WebSocket close procedure is started if a close frame - is received. In this case, the operation will eventually - complete with the error set to @ref error::closed. - - Because of the need to handle control frames, read operations - can cause writes to take place. These writes are managed - transparently; callers can still have one active asynchronous - read and asynchronous write operation pending simultaneously - (a user initiated call to @ref async_close counts as a write). - - @param buffer A dynamic buffer to hold the message data after - any masking or decompression has been applied. This object must - remain valid until the handler is called. - - @param handler The handler to be called when the read operation - completes. Copies will be made of the handler as required. The - function signature of the handler must be: - @code - void handler( - error_code const& ec, // Result of operation - bool fin // `true` if this is the last frame - ); - @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using boost::asio::io_service::post(). - */ - template -#if BEAST_DOXYGEN - void_or_deduced -#else - async_return_type -#endif - async_read_frame(DynamicBuffer& buffer, ReadHandler&& handler); - - /** Write a message to the stream. - - This function is used to synchronously write a message to - the stream. The call blocks until one of the following conditions - is met: - - @li The entire message is sent. - - @li An error occurs. - - This operation is implemented in terms of one or more calls to the - next layer's `write_some` function. - - The current setting of the @ref binary option controls - whether the message opcode is set to text or binary. If the - @ref auto_fragment option is set, the message will be split - into one or more frames as necessary. The actual payload contents - sent may be transformed as per the WebSocket protocol settings. - - @param buffers The buffers containing the entire message - payload. The implementation will make copies of this object - as needed, but ownership of the underlying memory is not - transferred. The caller is responsible for ensuring that - the memory locations pointed to by buffers remains valid - until the completion handler is called. - - @throws system_error Thrown on failure. - - @note This function always sends an entire message. To - send a message in fragments, use @ref write_frame. - */ - template - void - write(ConstBufferSequence const& buffers); - - /** Write a message to the stream. - - This function is used to synchronously write a message to - the stream. The call blocks until one of the following conditions - is met: - - @li The entire message is sent. - - @li An error occurs. - - This operation is implemented in terms of one or more calls to the - next layer's `write_some` function. - - The current setting of the @ref binary option controls - whether the message opcode is set to text or binary. If the - @ref auto_fragment option is set, the message will be split - into one or more frames as necessary. The actual payload contents - sent may be transformed as per the WebSocket protocol settings. - - @param buffers The buffers containing the entire message - payload. The implementation will make copies of this object - as needed, but ownership of the underlying memory is not - transferred. The caller is responsible for ensuring that - the memory locations pointed to by buffers remains valid - until the completion handler is called. - - @param ec Set to indicate what error occurred, if any. - - @throws system_error Thrown on failure. - - @note This function always sends an entire message. To - send a message in fragments, use @ref write_frame. - */ - template - void - write(ConstBufferSequence const& buffers, error_code& ec); - - /** Start an asynchronous operation to write a message to the stream. - - This function is used to asynchronously write a message to - the stream. The function call always returns immediately. - The asynchronous operation will continue until one of the - following conditions is true: - - @li The entire message is sent. - - @li An error occurs. - - This operation is implemented in terms of one or more calls - to the next layer's `async_write_some` functions, and is known - as a composed operation. The program must ensure that - the stream performs no other write operations (such as - stream::async_write, stream::async_write_frame, or - stream::async_close). - - The current setting of the @ref binary option controls - whether the message opcode is set to text or binary. If the - @ref auto_fragment option is set, the message will be split - into one or more frames as necessary. The actual payload contents - sent may be transformed as per the WebSocket protocol settings. - - @param buffers The buffers containing the entire message - payload. The implementation will make copies of this object - as needed, but ownership of the underlying memory is not - transferred. The caller is responsible for ensuring that - the memory locations pointed to by buffers remains valid - until the completion handler is called. - - @param handler The handler to be called when the write operation - completes. Copies will be made of the handler as required. The - function signature of the handler must be: - @code - void handler( - error_code const& ec // Result of operation - ); - @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using `boost::asio::io_service::post`. - */ - template -#if BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - WriteHandler, void(error_code)> -#endif - async_write(ConstBufferSequence const& buffers, - WriteHandler&& handler); - - /** Write partial message data on the stream. - - This function is used to write some or all of a message's - payload to the stream. The call will block until one of the - following conditions is true: - - @li A frame is sent. - - @li Message data is transferred to the write buffer. - - @li An error occurs. - - This operation is implemented in terms of one or more calls - to the stream's `write_some` function. - - If this is the beginning of a new message, the message opcode - will be set to text or binary as per the current setting of - the @ref binary option. The actual payload sent may be - transformed as per the WebSocket protocol settings. - - @param fin `true` if this is the last frame in the message. - - @param buffers The input buffer sequence holding the data to write. - - @return The number of bytes consumed in the input buffers. - - @throws system_error Thrown on failure. - */ - template - void - write_frame(bool fin, ConstBufferSequence const& buffers); - - /** Write partial message data on the stream. - - This function is used to write some or all of a message's - payload to the stream. The call will block until one of the - following conditions is true: - - @li A frame is sent. - - @li Message data is transferred to the write buffer. - - @li An error occurs. - - This operation is implemented in terms of one or more calls - to the stream's `write_some` function. - - If this is the beginning of a new message, the message opcode - will be set to text or binary as per the current setting of - the @ref binary option. The actual payload sent may be - transformed as per the WebSocket protocol settings. - - @param fin `true` if this is the last frame in the message. - - @param buffers The input buffer sequence holding the data to write. - - @param ec Set to indicate what error occurred, if any. - - @return The number of bytes consumed in the input buffers. - */ - template - void - write_frame(bool fin, - ConstBufferSequence const& buffers, error_code& ec); - - /** Start an asynchronous operation to send a message frame on the stream. - - This function is used to asynchronously write a message frame - on the stream. This function call always returns immediately. - The asynchronous operation will continue until one of the following - conditions is true: - - @li The entire frame is sent. - - @li An error occurs. - - This operation is implemented in terms of one or more calls - to the next layer's `async_write_some` functions, and is known - as a composed operation. The actual payload sent - may be transformed as per the WebSocket protocol settings. The - program must ensure that the stream performs no other write - operations (such as stream::async_write, stream::async_write_frame, - or stream::async_close). - - If this is the beginning of a new message, the message opcode - will be set to text or binary as per the current setting of - the @ref binary option. The actual payload sent may be - transformed as per the WebSocket protocol settings. - - @param fin A bool indicating whether or not the frame is the - last frame in the corresponding WebSockets message. - - @param buffers A object meeting the requirements of - ConstBufferSequence which holds the payload data before any - masking or compression. Although the buffers object may be copied - as necessary, ownership of the underlying buffers is retained by - the caller, which must guarantee that they remain valid until - the handler is called. - - @param handler The handler to be called when the write completes. - Copies will be made of the handler as required. The equivalent - function signature of the handler must be: - @code void handler( - error_code const& ec // Result of operation - ); @endcode - */ - template -#if BEAST_DOXYGEN - void_or_deduced -#else - async_return_type< - WriteHandler, void(error_code)> -#endif - async_write_frame(bool fin, - ConstBufferSequence const& buffers, WriteHandler&& handler); - -private: - template class accept_op; - template class close_op; - template class handshake_op; - template class ping_op; - template class response_op; - template class write_op; - template class write_frame_op; - template class read_op; - template class read_frame_op; - - static - void - default_decorate_req(request_type&) - { - } - - static - void - default_decorate_res(response_type&) - { - } - - void - reset(); - - template - void - do_accept(Decorator const& decorator, - error_code& ec); - - template - void - do_accept(http::header> const& req, - Decorator const& decorator, error_code& ec); - - template - void - do_handshake(response_type* res_p, - string_view host, - string_view target, - RequestDecorator const& decorator, - error_code& ec); - - template - request_type - build_request(detail::sec_ws_key_type& key, - string_view host, - string_view target, - Decorator const& decorator); - - template - response_type - build_response(http::header> const& req, - Decorator const& decorator); - - void - do_response(http::header const& resp, - detail::sec_ws_key_type const& key, error_code& ec); -}; - -} // websocket -} // beast - -#include -#include -#include -#include -#include -#include -#include - -#endif diff --git a/src/beast/include/beast/websocket/teardown.hpp b/src/beast/include/beast/websocket/teardown.hpp deleted file mode 100644 index a42279766ef..00000000000 --- a/src/beast/include/beast/websocket/teardown.hpp +++ /dev/null @@ -1,186 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_WEBSOCKET_TEARDOWN_HPP -#define BEAST_WEBSOCKET_TEARDOWN_HPP - -#include -#include -#include -#include - -namespace beast { -namespace websocket { - -/** Tag type used to find @ref beast::websocket::teardown and @ref beast::websocket::async_teardown overloads - - Overloads of @ref beast::websocket::teardown and - @ref beast::websocket::async_teardown for user defined types - must take a value of type @ref teardown_tag in the first - argument in order to be found by the implementation. -*/ -struct teardown_tag {}; - -/** Tear down a connection. - - This tears down a connection. The implementation will call - the overload of this function based on the `Socket` parameter - used to consruct the socket. When `Socket` is a user defined - type, and not a `boost::asio::ip::tcp::socket` or any - `boost::asio::ssl::stream`, callers are responsible for - providing a suitable overload of this function. - - @param socket The socket to tear down. - - @param ec Set to the error if any occurred. -*/ -template -void -teardown(teardown_tag, Socket& socket, error_code& ec) -{ -/* - If you are trying to use OpenSSL and this goes off, you need to - add an include for . - - If you are creating an instance of beast::websocket::stream with your - own user defined type, you must provide an overload of teardown with - the corresponding signature (including the teardown_tag). -*/ - static_assert(sizeof(Socket)==-1, - "Unknown Socket type in teardown."); -} - -/** Start tearing down a connection. - - This begins tearing down a connection asynchronously. - The implementation will call the overload of this function - based on the `Socket` parameter used to consruct the socket. - When `Stream` is a user defined type, and not a - `boost::asio::ip::tcp::socket` or any `boost::asio::ssl::stream`, - callers are responsible for providing a suitable overload - of this function. - - @param socket The socket to tear down. - - @param handler The handler to be called when the request completes. - Copies will be made of the handler as required. The equivalent - function signature of the handler must be: - @code void handler( - error_code const& error // result of operation - ); - @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using boost::asio::io_service::post(). - -*/ -template -void -async_teardown(teardown_tag, Socket& socket, TeardownHandler&& handler) -{ -/* - If you are trying to use OpenSSL and this goes off, you need to - add an include for . - - If you are creating an instance of beast::websocket::stream with your - own user defined type, you must provide an overload of teardown with - the corresponding signature (including the teardown_tag). -*/ - static_assert(sizeof(Socket)==-1, - "Unknown Socket type in async_teardown."); -} - -} // websocket - -//------------------------------------------------------------------------------ - -namespace websocket_helpers { - -// Calls to teardown and async_teardown must be made from -// a namespace that does not contain any overloads of these -// functions. The websocket_helpers namespace is defined here -// for that purpose. - -template -inline -void -call_teardown(Socket& socket, error_code& ec) -{ - using websocket::teardown; - teardown(websocket::teardown_tag{}, socket, ec); -} - -template -inline -void -call_async_teardown(Socket& socket, TeardownHandler&& handler) -{ - using websocket::async_teardown; - async_teardown(websocket::teardown_tag{}, socket, - std::forward(handler)); -} - -} // websocket_helpers - -//------------------------------------------------------------------------------ - -namespace websocket { - -/** Tear down a `boost::asio::ip::tcp::socket`. - - This tears down a connection. The implementation will call - the overload of this function based on the `Stream` parameter - used to consruct the socket. When `Stream` is a user defined - type, and not a `boost::asio::ip::tcp::socket` or any - `boost::asio::ssl::stream`, callers are responsible for - providing a suitable overload of this function. - - @param socket The socket to tear down. - - @param ec Set to the error if any occurred. -*/ -void -teardown(teardown_tag, - boost::asio::ip::tcp::socket& socket, error_code& ec); - -/** Start tearing down a `boost::asio::ip::tcp::socket`. - - This begins tearing down a connection asynchronously. - The implementation will call the overload of this function - based on the `Stream` parameter used to consruct the socket. - When `Stream` is a user defined type, and not a - `boost::asio::ip::tcp::socket` or any `boost::asio::ssl::stream`, - callers are responsible for providing a suitable overload - of this function. - - @param socket The socket to tear down. - - @param handler The handler to be called when the request completes. - Copies will be made of the handler as required. The equivalent - function signature of the handler must be: - @code void handler( - error_code const& error // result of operation - ); - @endcode - Regardless of whether the asynchronous operation completes - immediately or not, the handler will not be invoked from within - this function. Invocation of the handler will be performed in a - manner equivalent to using boost::asio::io_service::post(). - -*/ -template -void -async_teardown(teardown_tag, - boost::asio::ip::tcp::socket& socket, TeardownHandler&& handler); - -} // websocket -} // beast - -#include - -#endif diff --git a/src/beast/include/beast/zlib.hpp b/src/beast/include/beast/zlib.hpp deleted file mode 100644 index 8fb12d5705f..00000000000 --- a/src/beast/include/beast/zlib.hpp +++ /dev/null @@ -1,18 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_ZLIB_HPP -#define BEAST_ZLIB_HPP - -#include - -#include -#include -#include -#include - -#endif diff --git a/src/beast/include/beast/zlib/deflate_stream.hpp b/src/beast/include/beast/zlib/deflate_stream.hpp deleted file mode 100644 index b94e9e3539a..00000000000 --- a/src/beast/include/beast/zlib/deflate_stream.hpp +++ /dev/null @@ -1,400 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_ZLIB_DEFLATE_STREAM_HPP -#define BEAST_ZLIB_DEFLATE_STREAM_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace zlib { - -// This is a derivative work based on Zlib, copyright below: -/* - Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Jean-loup Gailly Mark Adler - jloup@gzip.org madler@alumni.caltech.edu - - The data format used by the zlib library is described by RFCs (Request for - Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 - (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). -*/ - -/** Raw deflate compressor. - - This is a port of zlib's "deflate" functionality to C++. -*/ -class deflate_stream - : private detail::deflate_stream -{ -public: - /** Construct a default deflate stream. - - Upon construction, the stream settings will be set - to these default values: - - @li `level = 6` - - @li `windowBits = 15` - - @li `memLevel = 8` - - @li `strategy = Strategy::normal` - - Although the stream is ready to be used immediately - after construction, any required internal buffers are - not dynamically allocated until needed. - */ - deflate_stream() - { - reset(6, 15, DEF_MEM_LEVEL, Strategy::normal); - } - - /** Reset the stream and compression settings. - - This function initializes the stream to the specified - compression settings. - - Although the stream is ready to be used immediately - after a reset, any required internal buffers are not - dynamically allocated until needed. - - @note Any unprocessed input or pending output from - previous calls are discarded. - */ - void - reset( - int level, - int windowBits, - int memLevel, - Strategy strategy) - { - doReset(level, windowBits, memLevel, strategy); - } - - /** Reset the stream without deallocating memory. - - This function performs the equivalent of calling `clear` - followed by `reset` with the same compression settings, - without deallocating the internal buffers. - - @note Any unprocessed input or pending output from - previous calls are discarded. - */ - void - reset() - { - doReset(); - } - - /** Clear the stream. - - This function resets the stream and frees all dynamically - allocated internal buffers. The compression settings are - left unchanged. - - @note Any unprocessed input or pending output from - previous calls are discarded. - */ - void - clear() - { - doClear(); - } - - /** Returns the upper limit on the size of a compressed block. - - This function makes a conservative estimate of the maximum number - of bytes needed to store the result of compressing a block of - data based on the current compression level and strategy. - - @param sourceLen The size of the uncompressed data. - - @return The maximum number of resulting compressed bytes. - */ - std::size_t - upper_bound(std::size_t sourceLen) const - { - return doUpperBound(sourceLen); - } - - /** Fine tune internal compression parameters. - - Compression parameters should only be tuned by someone who - understands the algorithm used by zlib's deflate for searching - for the best matching string, and even then only by the most - fanatic optimizer trying to squeeze out the last compressed bit - for their specific input data. Read the deflate.c source code - (ZLib) for the meaning of the max_lazy, good_length, nice_length, - and max_chain parameters. - */ - void - tune( - int good_length, - int max_lazy, - int nice_length, - int max_chain) - { - doTune(good_length, max_lazy, nice_length, max_chain); - } - - /** Compress input and write output. - - This function compresses as much data as possible, and stops when - the input buffer becomes empty or the output buffer becomes full. - It may introduce some output latency (reading input without - producing any output) except when forced to flush. - - In each call, one or both of these actions are performed: - - @li Compress more input starting at `zs.next_in` and update - `zs.next_in` and `zs.avail_in` accordingly. If not all - input can be processed (because there is not enough room in - the output buffer), `zs.next_in` and `zs.avail_in` are updated - and processing will resume at this point for the next call. - - @li Provide more output starting at `zs.next_out` and update - `zs.next_out` and `zs.avail_out` accordingly. This action is - forced if the parameter flush is not `Flush::none`. Forcing - flush frequently degrades the compression ratio, so this parameter - should be set only when necessary (in interactive applications). - Some output may be provided even if flush is not set. - - Before the call, the application must ensure that at least one - of the actions is possible, by providing more input and/or - consuming more output, and updating `zs.avail_in` or `zs.avail_out` - accordingly; `zs.avail_out` should never be zero before the call. - The application can consume the compressed output when it wants, - for example when the output buffer is full (`zs.avail_out == 0`), - or after each call of `write`. If `write` returns no error - with zero `zs.avail_out`, it must be called again after making - room in the output buffer because there might be more output - pending. - - Normally the parameter flush is set to `Flush::none`, which allows - deflate to decide how much data to accumulate before producing - output, in order to maximize compression. - - If the parameter flush is set to `Flush::sync`, all pending output - is flushed to the output buffer and the output is aligned on a - byte boundary, so that the decompressor can get all input data - available so far. In particular `zs.avail_in` is zero after the - call if enough output space has been provided before the call. - Flushing may degrade compression for some compression algorithms - and so it should be used only when necessary. This completes the - current deflate block and follows it with an empty stored block - that is three bits plus filler bits to the next byte, followed - by the four bytes `{ 0x00, 0x00 0xff 0xff }`. - - If flush is set to `Flush::partial`, all pending output is flushed - to the output buffer, but the output is not aligned to a byte - boundary. All of the input data so far will be available to the - decompressor, as for Z_SYNC_FLUSH. This completes the current - deflate block and follows it with an empty fixed codes block that - is 10 bits long. This assures that enough bytes are output in order - for the decompressor to finish the block before the empty fixed - code block. - - If flush is set to `Flush::block`, a deflate block is completed - and emitted, as for `Flush::sync`, but the output is not aligned - on a byte boundary, and up to seven bits of the current block are - held to be written as the next byte after the next deflate block - is completed. In this case, the decompressor may not be provided - enough bits at this point in order to complete decompression of - the data provided so far to the compressor. It may need to wait - for the next block to be emitted. This is for advanced applications - that need to control the emission of deflate blocks. - - If flush is set to `Flush::full`, all output is flushed as with - `Flush::sync`, and the compression state is reset so that - decompression can restart from this point if previous compressed - data has been damaged or if random access is desired. Using - `Flush::full` too often can seriously degrade compression. - - If `write` returns with `zs.avail_out == 0`, this function must - be called again with the same value of the flush parameter and - more output space (updated `zs.avail_out`), until the flush is - complete (`write` returns with non-zero `zs.avail_out`). In the - case of a `Flush::full`or `Flush::sync`, make sure that - `zs.avail_out` is greater than six to avoid repeated flush markers - due to `zs.avail_out == 0` on return. - - If the parameter flush is set to `Flush::finish`, pending input - is processed, pending output is flushed and deflate returns the - error `error::end_of_stream` if there was enough output space; - if deflate returns with no error, this function must be called - again with `Flush::finish` and more output space (updated - `zs.avail_out`) but no more input data, until it returns the - error `error::end_of_stream` or another error. After `write` has - returned the `error::end_of_stream` error, the only possible - operations on the stream are to reset or destroy. - - `Flush::finish` can be used immediately after initialization - if all the compression is to be done in a single step. In this - case, `zs.avail_out` must be at least value returned by - `upper_bound` (see below). Then `write` is guaranteed to return - the `error::end_of_stream` error. If not enough output space - is provided, deflate will not return `error::end_of_stream`, - and it must be called again as described above. - - `write` returns no error if some progress has been made (more - input processed or more output produced), `error::end_of_stream` - if all input has been consumed and all output has been produced - (only when flush is set to `Flush::finish`), `error::stream_error` - if the stream state was inconsistent (for example if `zs.next_in` - or `zs.next_out` was `nullptr`), `error::need_buffers` if no - progress is possible (for example `zs.avail_in` or `zs.avail_out` - was zero). Note that `error::need_buffers` is not fatal, and - `write` can be called again with more input and more output space - to continue compressing. - */ - void - write( - z_params& zs, - Flush flush, - error_code& ec) - { - doWrite(zs, flush, ec); - } - - /** Update the compression level and strategy. - - This function dynamically updates the compression level and - compression strategy. The interpretation of level and strategy - is as in @ref reset. This can be used to switch between compression - and straight copy of the input data, or to switch to a different kind - of input data requiring a different strategy. If the compression level - is changed, the input available so far is compressed with the old level - (and may be flushed); the new level will take effect only at the next - call of @ref write. - - Before the call of `params`, the stream state must be set as for a - call of @ref write, since the currently available input may have to be - compressed and flushed. In particular, `zs.avail_out` must be non-zero. - - @return `Z_OK` if success, `Z_STREAM_ERROR` if the source stream state - was inconsistent or if a parameter was invalid, `error::need_buffers` - if `zs.avail_out` was zero. - */ - void - params( - z_params& zs, - int level, - Strategy strategy, - error_code& ec) - { - doParams(zs, level, strategy, ec); - } - - /** Return bits pending in the output. - - This function returns the number of bytes and bits of output - that have been generated, but not yet provided in the available - output. The bytes not provided would be due to the available - output space having being consumed. The number of bits of output - not provided are between 0 and 7, where they await more bits to - join them in order to fill out a full byte. If pending or bits - are `nullptr`, then those values are not set. - - @return `Z_OK` if success, or `Z_STREAM_ERROR` if the source - stream state was inconsistent. - */ - void - pending(unsigned *value, int *bits) - { - doPending(value, bits); - } - - /** Insert bits into the compressed output stream. - - This function inserts bits in the deflate output stream. The - intent is that this function is used to start off the deflate - output with the bits leftover from a previous deflate stream when - appending to it. As such, this function can only be used for raw - deflate, and must be used before the first `write` call after an - initialization. `bits` must be less than or equal to 16, and that - many of the least significant bits of `value` will be inserted in - the output. - - @return `error::need_buffers` if there was not enough room in - the internal buffer to insert the bits. - */ - void - prime(int bits, int value, error_code& ec) - { - return doPrime(bits, value, ec); - } -}; - -/** Returns the upper limit on the size of a compressed block. - - This function makes a conservative estimate of the maximum number - of bytes needed to store the result of compressing a block of - data. - - @param bytes The size of the uncompressed data. - - @return The maximum number of resulting compressed bytes. -*/ -std::size_t -deflate_upper_bound(std::size_t bytes); - -/* For the default windowBits of 15 and memLevel of 8, this function returns - a close to exact, as well as small, upper bound on the compressed size. - They are coded as constants here for a reason--if the #define's are - changed, then this function needs to be changed as well. The return - value for 15 and 8 only works for those exact settings. - - For any setting other than those defaults for windowBits and memLevel, - the value returned is a conservative worst case for the maximum expansion - resulting from using fixed blocks instead of stored blocks, which deflate - can emit on compressed data for some combinations of the parameters. - - This function could be more sophisticated to provide closer upper bounds for - every combination of windowBits and memLevel. But even the conservative - upper bound of about 14% expansion does not seem onerous for output buffer - allocation. -*/ -inline -std::size_t -deflate_upper_bound(std::size_t bytes) -{ - return bytes + - ((bytes + 7) >> 3) + - ((bytes + 63) >> 6) + 5 + - 6; -} - -} // zlib -} // beast - -#endif diff --git a/src/beast/include/beast/zlib/detail/bitstream.hpp b/src/beast/include/beast/zlib/detail/bitstream.hpp deleted file mode 100644 index c7ae1a945e3..00000000000 --- a/src/beast/include/beast/zlib/detail/bitstream.hpp +++ /dev/null @@ -1,203 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// -// This is a derivative work based on Zlib, copyright below: -/* - Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Jean-loup Gailly Mark Adler - jloup@gzip.org madler@alumni.caltech.edu - - The data format used by the zlib library is described by RFCs (Request for - Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 - (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). -*/ - -#ifndef BEAST_ZLIB_DETAIL_BITSTREAM_HPP -#define BEAST_ZLIB_DETAIL_BITSTREAM_HPP - -#include -#include -#include - -namespace beast { -namespace zlib { -namespace detail { - -class bitstream -{ - using value_type = std::uint32_t; - - value_type v_ = 0; - unsigned n_ = 0; - -public: - // returns the number of bits in the reservoir - unsigned - size() const - { - return n_; - } - - // discard n bits - void - drop(std::size_t n) - { - BOOST_ASSERT(n <= n_); - n_ -= static_cast(n); - v_ >>= n; - } - - // flush everything - void - flush() - { - n_ = 0; - v_ = 0; - } - - // flush to the next byte boundary - void - flush_byte() - { - drop(n_ % 8); - } - - // ensure at least n bits - template - bool - fill(std::size_t n, FwdIt& first, FwdIt const& last); - - // fill 8 bits, unchecked - template - void - fill_8(FwdIt& it); - - // fill 16 bits, unchecked - template - void - fill_16(FwdIt& it); - - // return n bits - template - void - peek(Unsigned& value, std::size_t n); - - // return everything in the reservoir - value_type - peek_fast() const - { - return v_; - } - - // return n bits, and consume - template - void - read(Unsigned& value, std::size_t n); - - // rewind by the number of whole bytes stored (unchecked) - template - void - rewind(BidirIt& it); -}; - -template -inline -bool -bitstream:: -fill(std::size_t n, FwdIt& first, FwdIt const& last) -{ - while(n_ < n) - { - if(first == last) - return false; - v_ += static_cast(*first++) << n_; - n_ += 8; - } - return true; -} - -template -inline -void -bitstream:: -fill_8(FwdIt& it) -{ - v_ += static_cast(*it++) << n_; - n_ += 8; -} - -template -inline -void -bitstream:: -fill_16(FwdIt& it) -{ - v_ += static_cast(*it++) << n_; - n_ += 8; - v_ += static_cast(*it++) << n_; - n_ += 8; -} - -template -inline -void -bitstream:: -peek(Unsigned& value, std::size_t n) -{ - BOOST_ASSERT(n <= sizeof(value)*8); - BOOST_ASSERT(n <= n_); - value = static_cast( - v_ & ((1ULL << n) - 1)); -} - -template -inline -void -bitstream:: -read(Unsigned& value, std::size_t n) -{ - BOOST_ASSERT(n < sizeof(v_)*8); - BOOST_ASSERT(n <= n_); - value = static_cast( - v_ & ((1ULL << n) - 1)); - v_ >>= n; - n_ -= static_cast(n); -} - -template -inline -void -bitstream:: -rewind(BidirIt& it) -{ - auto len = n_ >> 3; - it = std::prev(it, len); - n_ &= 7; - v_ &= (1U << n_) - 1; -} - -} // detail -} // zlib -} // beast - -#endif diff --git a/src/beast/include/beast/zlib/detail/deflate_stream.hpp b/src/beast/include/beast/zlib/detail/deflate_stream.hpp deleted file mode 100644 index b51baff1b0b..00000000000 --- a/src/beast/include/beast/zlib/detail/deflate_stream.hpp +++ /dev/null @@ -1,2999 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// -// This is a derivative work based on Zlib, copyright below: -/* - Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Jean-loup Gailly Mark Adler - jloup@gzip.org madler@alumni.caltech.edu - - The data format used by the zlib library is described by RFCs (Request for - Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 - (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). -*/ - -#ifndef BEAST_ZLIB_DETAIL_DEFLATE_STREAM_HPP -#define BEAST_ZLIB_DETAIL_DEFLATE_STREAM_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace zlib { -namespace detail { - -/* - * ALGORITHM - * - * The "deflation" process depends on being able to identify portions - * of the input text which are identical to earlier input (within a - * sliding window trailing behind the input currently being processed). - * - * Each code tree is stored in a compressed form which is itself - * a Huffman encoding of the lengths of all the code strings (in - * ascending order by source values). The actual code strings are - * reconstructed from the lengths in the inflate process, as described - * in the deflate specification. - * - * The most straightforward technique turns out to be the fastest for - * most input files: try all possible matches and select the longest. - * The key feature of this algorithm is that insertions into the string - * dictionary are very simple and thus fast, and deletions are avoided - * completely. Insertions are performed at each input character, whereas - * string matches are performed only when the previous match ends. So it - * is preferable to spend more time in matches to allow very fast string - * insertions and avoid deletions. The matching algorithm for small - * strings is inspired from that of Rabin & Karp. A brute force approach - * is used to find longer strings when a small match has been found. - * A similar algorithm is used in comic (by Jan-Mark Wams) and freeze - * (by Leonid Broukhis). - * A previous version of this file used a more sophisticated algorithm - * (by Fiala and Greene) which is guaranteed to run in linear amortized - * time, but has a larger average cost, uses more memory and is patented. - * However the F&G algorithm may be faster for some highly redundant - * files if the parameter max_chain_length (described below) is too large. - * - * ACKNOWLEDGEMENTS - * - * The idea of lazy evaluation of matches is due to Jan-Mark Wams, and - * I found it in 'freeze' written by Leonid Broukhis. - * Thanks to many people for bug reports and testing. - * - * REFERENCES - * - * Deutsch, L.P.,"DEFLATE Compressed Data Format Specification". - * Available in http://tools.ietf.org/html/rfc1951 - * - * A description of the Rabin and Karp algorithm is given in the book - * "Algorithms" by R. Sedgewick, Addison-Wesley, p252. - * - * Fiala,E.R., and Greene,D.H. - * Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595 - * - */ - -class deflate_stream -{ -protected: - // Upper limit on code length - static std::uint8_t constexpr maxBits = 15; - - // Number of length codes, not counting the special END_BLOCK code - static std::uint16_t constexpr lengthCodes = 29; - - // Number of literal bytes 0..255 - static std::uint16_t constexpr literals = 256; - - // Number of Literal or Length codes, including the END_BLOCK code - static std::uint16_t constexpr lCodes = literals + 1 + lengthCodes; - - // Number of distance code lengths - static std::uint16_t constexpr dCodes = 30; - - // Number of codes used to transfer the bit lengths - static std::uint16_t constexpr blCodes = 19; - - // Number of distance codes - static std::uint16_t constexpr distCodeLen = 512; - - // Size limit on bit length codes - static std::uint8_t constexpr maxBlBits= 7; - - static std::uint16_t constexpr minMatch = 3; - static std::uint16_t constexpr maxMatch = 258; - - // Can't change minMatch without also changing code, see original zlib - BOOST_STATIC_ASSERT(minMatch == 3); - - // end of block literal code - static std::uint16_t constexpr END_BLOCK = 256; - - // repeat previous bit length 3-6 times (2 bits of repeat count) - static std::uint8_t constexpr REP_3_6 = 16; - - // repeat a zero length 3-10 times (3 bits of repeat count) - static std::uint8_t constexpr REPZ_3_10 = 17; - - // repeat a zero length 11-138 times (7 bits of repeat count) - static std::uint8_t constexpr REPZ_11_138 = 18; - - // The three kinds of block type - static std::uint8_t constexpr STORED_BLOCK = 0; - static std::uint8_t constexpr STATIC_TREES = 1; - static std::uint8_t constexpr DYN_TREES = 2; - - // Maximum value for memLevel in deflateInit2 - static std::uint8_t constexpr MAX_MEM_LEVEL = 9; - - // Default memLevel - static std::uint8_t constexpr DEF_MEM_LEVEL = MAX_MEM_LEVEL; - - /* Note: the deflate() code requires max_lazy >= minMatch and max_chain >= 4 - For deflate_fast() (levels <= 3) good is ignored and lazy has a different - meaning. - */ - - // maximum heap size - static std::uint16_t constexpr HEAP_SIZE = 2 * lCodes + 1; - - // size of bit buffer in bi_buf - static std::uint8_t constexpr Buf_size = 16; - - // Matches of length 3 are discarded if their distance exceeds kTooFar - static std::size_t constexpr kTooFar = 4096; - - /* Minimum amount of lookahead, except at the end of the input file. - See deflate.c for comments about the minMatch+1. - */ - static std::size_t constexpr kMinLookahead = maxMatch + minMatch+1; - - /* Number of bytes after end of data in window to initialize in order - to avoid memory checker errors from longest match routines - */ - static std::size_t constexpr kWinInit = maxMatch; - - // Describes a single value and its code string. - struct ct_data - { - std::uint16_t fc; // frequency count or bit string - std::uint16_t dl; // parent node in tree or length of bit string - - bool - operator==(ct_data const& rhs) const - { - return fc == rhs.fc && dl == rhs.dl; - } - }; - - struct static_desc - { - ct_data const* static_tree;// static tree or NULL - std::uint8_t const* extra_bits; // extra bits for each code or NULL - std::uint16_t extra_base; // base index for extra_bits - std::uint16_t elems; // max number of elements in the tree - std::uint8_t max_length; // max bit length for the codes - }; - - struct lut_type - { - // Number of extra bits for each length code - std::uint8_t const extra_lbits[lengthCodes] = { - 0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0 - }; - - // Number of extra bits for each distance code - std::uint8_t const extra_dbits[dCodes] = { - 0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13 - }; - - // Number of extra bits for each bit length code - std::uint8_t const extra_blbits[blCodes] = { - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7 - }; - - // The lengths of the bit length codes are sent in order - // of decreasing probability, to avoid transmitting the - // lengths for unused bit length codes. - std::uint8_t const bl_order[blCodes] = { - 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 - }; - - ct_data ltree[lCodes + 2]; - - ct_data dtree[dCodes]; - - // Distance codes. The first 256 values correspond to the distances - // 3 .. 258, the last 256 values correspond to the top 8 bits of - // the 15 bit distances. - std::uint8_t dist_code[distCodeLen]; - - std::uint8_t length_code[maxMatch-minMatch+1]; - - std::uint8_t base_length[lengthCodes]; - - std::uint16_t base_dist[dCodes]; - - static_desc l_desc = { - ltree, extra_lbits, literals+1, lCodes, maxBits - }; - - static_desc d_desc = { - dtree, extra_dbits, 0, dCodes, maxBits - }; - - static_desc bl_desc = - { - nullptr, extra_blbits, 0, blCodes, maxBlBits - }; - }; - - struct tree_desc - { - ct_data *dyn_tree; /* the dynamic tree */ - int max_code; /* largest code with non zero frequency */ - static_desc const* stat_desc; /* the corresponding static tree */ - }; - - enum block_state - { - need_more, /* block not completed, need more input or more output */ - block_done, /* block flush performed */ - finish_started, /* finish started, need only more output at next deflate */ - finish_done /* finish done, accept no more input or output */ - }; - - // VFALCO This might not be needed, e.g. for zip/gzip - enum StreamStatus - { - EXTRA_STATE = 69, - NAME_STATE = 73, - COMMENT_STATE = 91, - HCRC_STATE = 103, - BUSY_STATE = 113, - FINISH_STATE = 666 - }; - - /* A std::uint16_t is an index in the character window. We use short instead of int to - * save space in the various tables. IPos is used only for parameter passing. - */ - using IPos = unsigned; - - using self = deflate_stream; - typedef block_state(self::*compress_func)(z_params& zs, Flush flush); - - //-------------------------------------------------------------------------- - - lut_type const& lut_; - - bool inited_ = false; - std::size_t buf_size_; - std::unique_ptr buf_; - - int status_; // as the name implies - Byte* pending_buf_; // output still pending - std::uint32_t - pending_buf_size_; // size of pending_buf - Byte* pending_out_; // next pending byte to output to the stream - uInt pending_; // nb of bytes in the pending buffer - boost::optional - last_flush_; // value of flush param for previous deflate call - - uInt w_size_; // LZ77 window size (32K by default) - uInt w_bits_; // log2(w_size) (8..16) - uInt w_mask_; // w_size - 1 - - /* Sliding window. Input bytes are read into the second half of the window, - and move to the first half later to keep a dictionary of at least wSize - bytes. With this organization, matches are limited to a distance of - wSize-maxMatch bytes, but this ensures that IO is always - performed with a length multiple of the block size. Also, it limits - the window size to 64K. - To do: use the user input buffer as sliding window. - */ - Byte *window_ = nullptr; - - /* Actual size of window: 2*wSize, except when the user input buffer - is directly used as sliding window. - */ - std::uint32_t window_size_; - - /* Link to older string with same hash index. To limit the size of this - array to 64K, this link is maintained only for the last 32K strings. - An index in this array is thus a window index modulo 32K. - */ - std::uint16_t* prev_; - - std::uint16_t* head_; // Heads of the hash chains or 0 - - uInt ins_h_; // hash index of string to be inserted - uInt hash_size_; // number of elements in hash table - uInt hash_bits_; // log2(hash_size) - uInt hash_mask_; // hash_size-1 - - /* Number of bits by which ins_h must be shifted at each input - step. It must be such that after minMatch steps, - the oldest byte no longer takes part in the hash key, that is: - hash_shift * minMatch >= hash_bits - */ - uInt hash_shift_; - - /* Window position at the beginning of the current output block. - Gets negative when the window is moved backwards. - */ - long block_start_; - - uInt match_length_; // length of best match - IPos prev_match_; // previous match - int match_available_; // set if previous match exists - uInt strstart_; // start of string to insert - uInt match_start_; // start of matching string - uInt lookahead_; // number of valid bytes ahead in window - - /* Length of the best match at previous step. Matches not greater - than this are discarded. This is used in the lazy match evaluation. - */ - uInt prev_length_; - - /* To speed up deflation, hash chains are never searched beyond - this length. A higher limit improves compression ratio but - degrades the speed. - */ - uInt max_chain_length_; - - /* Attempt to find a better match only when the current match is strictly - smaller than this value. This mechanism is used only for compression - levels >= 4. - - OR Insert new strings in the hash table only if the match length is not - greater than this length. This saves time but degrades compression. - used only for compression levels <= 3. - */ - uInt max_lazy_match_; - - int level_; // compression level (1..9) - Strategy strategy_; // favor or force Huffman coding - - // Use a faster search when the previous match is longer than this - uInt good_match_; - - int nice_match_; // Stop searching when current match exceeds this - - ct_data dyn_ltree_[ - HEAP_SIZE]; // literal and length tree - ct_data dyn_dtree_[ - 2*dCodes+1]; // distance tree - ct_data bl_tree_[ - 2*blCodes+1]; // Huffman tree for bit lengths - - tree_desc l_desc_; // desc. for literal tree - tree_desc d_desc_; // desc. for distance tree - tree_desc bl_desc_; // desc. for bit length tree - - // number of codes at each bit length for an optimal tree - std::uint16_t bl_count_[maxBits+1]; - - // Index within the heap array of least frequent node in the Huffman tree - static std::size_t constexpr kSmallest = 1; - - /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. - heap[0] is not used. The same heap array is used to build all trees. - */ - - int heap_[2*lCodes+1]; // heap used to build the Huffman trees - int heap_len_; // number of elements in the heap - int heap_max_; // element of largest frequency - - // Depth of each subtree used as tie breaker for trees of equal frequency - std::uint8_t depth_[2*lCodes+1]; - - std::uint8_t *l_buf_; // buffer for literals or lengths - - /* Size of match buffer for literals/lengths. - There are 4 reasons for limiting lit_bufsize to 64K: - - frequencies can be kept in 16 bit counters - - if compression is not successful for the first block, all input - data is still in the window so we can still emit a stored block even - when input comes from standard input. (This can also be done for - all blocks if lit_bufsize is not greater than 32K.) - - if compression is not successful for a file smaller than 64K, we can - even emit a stored file instead of a stored block (saving 5 bytes). - This is applicable only for zip (not gzip or zlib). - - creating new Huffman trees less frequently may not provide fast - adaptation to changes in the input data statistics. (Take for - example a binary file with poorly compressible code followed by - a highly compressible string table.) Smaller buffer sizes give - fast adaptation but have of course the overhead of transmitting - trees more frequently. - - I can't count above 4 - */ - uInt lit_bufsize_; - uInt last_lit_; // running index in l_buf_ - - /* Buffer for distances. To simplify the code, d_buf_ and l_buf_ - have the same number of elements. To use different lengths, an - extra flag array would be necessary. - */ - std::uint16_t* d_buf_; - - std::uint32_t opt_len_; // bit length of current block with optimal trees - std::uint32_t static_len_; // bit length of current block with static trees - uInt matches_; // number of string matches in current block - uInt insert_; // bytes at end of window left to insert - - /* Output buffer. - Bits are inserted starting at the bottom (least significant bits). - */ - std::uint16_t bi_buf_; - - /* Number of valid bits in bi_buf._ All bits above the last valid - bit are always zero. - */ - int bi_valid_; - - /* High water mark offset in window for initialized bytes -- bytes - above this are set to zero in order to avoid memory check warnings - when longest match routines access bytes past the input. This is - then updated to the new high water mark. - */ - std::uint32_t high_water_; - - //-------------------------------------------------------------------------- - - deflate_stream() - : lut_(get_lut()) - { - } - - /* In order to simplify the code, particularly on 16 bit machines, match - distances are limited to MAX_DIST instead of WSIZE. - */ - std::size_t - max_dist() const - { - return w_size_ - kMinLookahead; - } - - void - put_byte(std::uint8_t c) - { - pending_buf_[pending_++] = c; - } - - void - put_short(std::uint16_t w) - { - put_byte(w & 0xff); - put_byte(w >> 8); - } - - /* Send a value on a given number of bits. - IN assertion: length <= 16 and value fits in length bits. - */ - void - send_bits(int value, int length) - { - if(bi_valid_ > (int)Buf_size - length) - { - bi_buf_ |= (std::uint16_t)value << bi_valid_; - put_short(bi_buf_); - bi_buf_ = (std::uint16_t)value >> (Buf_size - bi_valid_); - bi_valid_ += length - Buf_size; - } - else - { - bi_buf_ |= (std::uint16_t)(value) << bi_valid_; - bi_valid_ += length; - } - } - - // Send a code of the given tree - void - send_code(int value, ct_data const* tree) - { - send_bits(tree[value].fc, tree[value].dl); - } - - /* Mapping from a distance to a distance code. dist is the - distance - 1 and must not have side effects. _dist_code[256] - and _dist_code[257] are never used. - */ - std::uint8_t - d_code(unsigned dist) - { - if(dist < 256) - return lut_.dist_code[dist]; - return lut_.dist_code[256+(dist>>7)]; - } - - /* Update a hash value with the given input byte - IN assertion: all calls to to update_hash are made with - consecutive input characters, so that a running hash - key can be computed from the previous key instead of - complete recalculation each time. - */ - void - update_hash(uInt& h, std::uint8_t c) - { - h = ((h << hash_shift_) ^ c) & hash_mask_; - } - - /* Initialize the hash table (avoiding 64K overflow for 16 - bit systems). prev[] will be initialized on the fly. - */ - void - clear_hash() - { - head_[hash_size_-1] = 0; - std::memset((Byte *)head_, 0, - (unsigned)(hash_size_-1)*sizeof(*head_)); - } - - /* Compares two subtrees, using the tree depth as tie breaker - when the subtrees have equal frequency. This minimizes the - worst case length. - */ - bool - smaller(ct_data const* tree, int n, int m) - { - return tree[n].fc < tree[m].fc || - (tree[n].fc == tree[m].fc && - depth_[n] <= depth_[m]); - } - - /* Insert string str in the dictionary and set match_head to the - previous head of the hash chain (the most recent string with - same hash key). Return the previous length of the hash chain. - If this file is compiled with -DFASTEST, the compression level - is forced to 1, and no hash chains are maintained. - IN assertion: all calls to to INSERT_STRING are made with - consecutive input characters and the first minMatch - bytes of str are valid (except for the last minMatch-1 - bytes of the input file). - */ - void - insert_string(IPos& hash_head) - { - update_hash(ins_h_, window_[strstart_ + (minMatch-1)]); - hash_head = prev_[strstart_ & w_mask_] = head_[ins_h_]; - head_[ins_h_] = (std::uint16_t)strstart_; - } - - //-------------------------------------------------------------------------- - - /* Values for max_lazy_match, good_match and max_chain_length, depending on - * the desired pack level (0..9). The values given below have been tuned to - * exclude worst case performance for pathological files. Better values may be - * found for specific files. - */ - struct config - { - std::uint16_t good_length; /* reduce lazy search above this match length */ - std::uint16_t max_lazy; /* do not perform lazy search above this match length */ - std::uint16_t nice_length; /* quit search above this match length */ - std::uint16_t max_chain; - compress_func func; - - config( - std::uint16_t good_length_, - std::uint16_t max_lazy_, - std::uint16_t nice_length_, - std::uint16_t max_chain_, - compress_func func_) - : good_length(good_length_) - , max_lazy(max_lazy_) - , nice_length(nice_length_) - , max_chain(max_chain_) - , func(func_) - { - } - }; - - static - config - get_config(std::size_t level) - { - switch(level) - { - // good lazy nice chain - case 0: return { 0, 0, 0, 0, &self::deflate_stored}; // store only - case 1: return { 4, 4, 8, 4, &self::deflate_fast}; // max speed, no lazy matches - case 2: return { 4, 5, 16, 8, &self::deflate_fast}; - case 3: return { 4, 6, 32, 32, &self::deflate_fast}; - case 4: return { 4, 4, 16, 16, &self::deflate_slow}; // lazy matches - case 5: return { 8, 16, 32, 32, &self::deflate_slow}; - case 6: return { 8, 16, 128, 128, &self::deflate_slow}; - case 7: return { 8, 32, 128, 256, &self::deflate_slow}; - case 8: return { 32, 128, 258, 1024, &self::deflate_slow}; - default: - case 9: return { 32, 258, 258, 4096, &self::deflate_slow}; // max compression - } - } - - void - maybe_init() - { - if(! inited_) - init(); - } - - template - static - Unsigned - bi_reverse(Unsigned code, unsigned len); - - template - static - void - gen_codes(ct_data *tree, int max_code, std::uint16_t *bl_count); - - template - static - lut_type const& - get_lut(); - - template void doReset (int level, int windowBits, int memLevel, Strategy strategy); - template void doReset (); - template void doClear (); - template std::size_t doUpperBound (std::size_t sourceLen) const; - template void doTune (int good_length, int max_lazy, int nice_length, int max_chain); - template void doParams (z_params& zs, int level, Strategy strategy, error_code& ec); - template void doWrite (z_params& zs, boost::optional flush, error_code& ec); - template void doDictionary (Byte const* dict, uInt dictLength, error_code& ec); - template void doPrime (int bits, int value, error_code& ec); - template void doPending (unsigned* value, int* bits); - - template void init (); - template void lm_init (); - template void init_block (); - template void pqdownheap (ct_data const* tree, int k); - template void pqremove (ct_data const* tree, int& top); - template void gen_bitlen (tree_desc *desc); - template void build_tree (tree_desc *desc); - template void scan_tree (ct_data *tree, int max_code); - template void send_tree (ct_data *tree, int max_code); - template int build_bl_tree (); - template void send_all_trees (int lcodes, int dcodes, int blcodes); - template void compress_block (ct_data const* ltree, ct_data const* dtree); - template int detect_data_type (); - template void bi_windup (); - template void bi_flush (); - template void copy_block (char *buf, unsigned len, int header); - - template void tr_init (); - template void tr_align (); - template void tr_flush_bits (); - template void tr_stored_block (char *bu, std::uint32_t stored_len, int last); - template void tr_tally_dist (std::uint16_t dist, std::uint8_t len, bool& flush); - template void tr_tally_lit (std::uint8_t c, bool& flush); - - template void tr_flush_block (z_params& zs, char *buf, std::uint32_t stored_len, int last); - template void fill_window (z_params& zs); - template void flush_pending (z_params& zs); - template void flush_block (z_params& zs, bool last); - template int read_buf (z_params& zs, Byte *buf, unsigned size); - template uInt longest_match (IPos cur_match); - - template block_state f_stored (z_params& zs, Flush flush); - template block_state f_fast (z_params& zs, Flush flush); - template block_state f_slow (z_params& zs, Flush flush); - template block_state f_rle (z_params& zs, Flush flush); - template block_state f_huff (z_params& zs, Flush flush); - - block_state - deflate_stored(z_params& zs, Flush flush) - { - return f_stored(zs, flush); - } - - block_state - deflate_fast(z_params& zs, Flush flush) - { - return f_fast(zs, flush); - } - - block_state - deflate_slow(z_params& zs, Flush flush) - { - return f_slow(zs, flush); - } - - block_state - deflate_rle(z_params& zs, Flush flush) - { - return f_rle(zs, flush); - } - - block_state - deflate_huff(z_params& zs, Flush flush) - { - return f_huff(zs, flush); - } -}; - -//-------------------------------------------------------------------------- - -// Reverse the first len bits of a code -template -inline -Unsigned -deflate_stream:: -bi_reverse(Unsigned code, unsigned len) -{ - BOOST_STATIC_ASSERT(std::is_unsigned::value); - BOOST_ASSERT(len <= 8 * sizeof(unsigned)); - Unsigned res = 0; - do - { - res |= code & 1; - code >>= 1; - res <<= 1; - } - while(--len > 0); - return res >> 1; -} - -/* Generate the codes for a given tree and bit counts (which need not be optimal). - IN assertion: the array bl_count contains the bit length statistics for - the given tree and the field len is set for all tree elements. - OUT assertion: the field code is set for all tree elements of non - zero code length. -*/ -template -void -deflate_stream:: -gen_codes(ct_data *tree, int max_code, std::uint16_t *bl_count) -{ - std::uint16_t next_code[maxBits+1]; /* next code value for each bit length */ - std::uint16_t code = 0; /* running code value */ - int bits; /* bit index */ - int n; /* code index */ - - // The distribution counts are first used to - // generate the code values without bit reversal. - for(bits = 1; bits <= maxBits; bits++) - { - code = (code + bl_count[bits-1]) << 1; - next_code[bits] = code; - } - // Check that the bit counts in bl_count are consistent. - // The last code must be all ones. - BOOST_ASSERT(code + bl_count[maxBits]-1 == (1< -auto -deflate_stream::get_lut() -> - lut_type const& -{ - struct init - { - lut_type tables; - - init() - { - // number of codes at each bit length for an optimal tree - //std::uint16_t bl_count[maxBits+1]; - - // Initialize the mapping length (0..255) -> length code (0..28) - std::uint8_t length = 0; - for(std::uint8_t code = 0; code < lengthCodes-1; ++code) - { - tables.base_length[code] = length; - auto const run = 1U << tables.extra_lbits[code]; - for(unsigned n = 0; n < run; ++n) - tables.length_code[length++] = code; - } - BOOST_ASSERT(length == 0); - // Note that the length 255 (match length 258) can be represented - // in two different ways: code 284 + 5 bits or code 285, so we - // overwrite length_code[255] to use the best encoding: - tables.length_code[255] = lengthCodes-1; - - // Initialize the mapping dist (0..32K) -> dist code (0..29) - { - std::uint8_t code; - std::uint16_t dist = 0; - for(code = 0; code < 16; code++) - { - tables.base_dist[code] = dist; - auto const run = 1U << tables.extra_dbits[code]; - for(unsigned n = 0; n < run; ++n) - tables.dist_code[dist++] = code; - } - BOOST_ASSERT(dist == 256); - // from now on, all distances are divided by 128 - dist >>= 7; - for(; code < dCodes; ++code) - { - tables.base_dist[code] = dist << 7; - auto const run = 1U << (tables.extra_dbits[code]-7); - for(std::size_t n = 0; n < run; ++n) - tables.dist_code[256 + dist++] = code; - } - BOOST_ASSERT(dist == 256); - } - - // Construct the codes of the static literal tree - std::uint16_t bl_count[maxBits+1]; - std::memset(bl_count, 0, sizeof(bl_count)); - unsigned n = 0; - while (n <= 143) - tables.ltree[n++].dl = 8; - bl_count[8] += 144; - while (n <= 255) - tables.ltree[n++].dl = 9; - bl_count[9] += 112; - while (n <= 279) - tables.ltree[n++].dl = 7; - bl_count[7] += 24; - while (n <= 287) - tables.ltree[n++].dl = 8; - bl_count[8] += 8; - // Codes 286 and 287 do not exist, but we must include them in the tree - // construction to get a canonical Huffman tree (longest code all ones) - gen_codes(tables.ltree, lCodes+1, bl_count); - - for(n = 0; n < dCodes; ++n) - { - tables.dtree[n].dl = 5; - tables.dtree[n].fc = - static_cast(bi_reverse(n, 5)); - } - } - }; - static init const data; - return data.tables; -} - -template -void -deflate_stream:: -doReset( - int level, - int windowBits, - int memLevel, - Strategy strategy) -{ - if(level == Z_DEFAULT_COMPRESSION) - level = 6; - - // VFALCO What do we do about this? - // until 256-byte window bug fixed - if(windowBits == 8) - windowBits = 9; - - if(level < 0 || level > 9) - BOOST_THROW_EXCEPTION(std::invalid_argument{ - "invalid level"}); - - if(windowBits < 8 || windowBits > 15) - BOOST_THROW_EXCEPTION(std::invalid_argument{ - "invalid windowBits"}); - - if(memLevel < 1 || memLevel > MAX_MEM_LEVEL) - BOOST_THROW_EXCEPTION(std::invalid_argument{ - "invalid memLevel"}); - - w_bits_ = windowBits; - - hash_bits_ = memLevel + 7; - - // 16K elements by default - lit_bufsize_ = 1 << (memLevel + 6); - - level_ = level; - strategy_ = strategy; - inited_ = false; -} - -template -void -deflate_stream:: -doReset() -{ - inited_ = false; -} - -template -void -deflate_stream:: -doClear() -{ - inited_ = false; - buf_.reset(); -} - -template -std::size_t -deflate_stream:: -doUpperBound(std::size_t sourceLen) const -{ - std::size_t complen; - std::size_t wraplen; - - /* conservative upper bound for compressed data */ - complen = sourceLen + - ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5; - - /* compute wrapper length */ - wraplen = 0; - - /* if not default parameters, return conservative bound */ - if(w_bits_ != 15 || hash_bits_ != 8 + 7) - return complen + wraplen; - - /* default settings: return tight bound for that case */ - return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + - (sourceLen >> 25) + 13 - 6 + wraplen; -} - -template -void -deflate_stream:: -doTune( - int good_length, - int max_lazy, - int nice_length, - int max_chain) -{ - good_match_ = good_length; - nice_match_ = nice_length; - max_lazy_match_ = max_lazy; - max_chain_length_ = max_chain; -} - -template -void -deflate_stream:: -doParams(z_params& zs, int level, Strategy strategy, error_code& ec) -{ - compress_func func; - - if(level == Z_DEFAULT_COMPRESSION) - level = 6; - if(level < 0 || level > 9) - { - ec = error::stream_error; - return; - } - func = get_config(level_).func; - - if((strategy != strategy_ || func != get_config(level).func) && - zs.total_in != 0) - { - // Flush the last buffer: - doWrite(zs, Flush::block, ec); - if(ec == error::need_buffers && pending_ == 0) - ec.assign(0, ec.category()); - } - if(level_ != level) - { - level_ = level; - max_lazy_match_ = get_config(level).max_lazy; - good_match_ = get_config(level).good_length; - nice_match_ = get_config(level).nice_length; - max_chain_length_ = get_config(level).max_chain; - } - strategy_ = strategy; -} - -// VFALCO boost::optional param is a workaround for -// gcc "maybe uninitialized" warning -// https://github.com/vinniefalco/Beast/issues/532 -// -template -void -deflate_stream:: -doWrite(z_params& zs, boost::optional flush, error_code& ec) -{ - maybe_init(); - - if(zs.next_out == 0 || (zs.next_in == 0 && zs.avail_in != 0) || - (status_ == FINISH_STATE && flush != Flush::finish)) - { - ec = error::stream_error; - return; - } - if(zs.avail_out == 0) - { - ec = error::need_buffers; - return; - } - - // value of flush param for previous deflate call - boost::optional old_flush = last_flush_; - last_flush_ = flush; - - // Flush as much pending output as possible - if(pending_ != 0) - { - flush_pending(zs); - if(zs.avail_out == 0) - { - /* Since avail_out is 0, deflate will be called again with - * more output space, but possibly with both pending and - * avail_in equal to zero. There won't be anything to do, - * but this is not an error situation so make sure we - * return OK instead of BUF_ERROR at next call of deflate: - */ - last_flush_ = boost::none; - return; - } - } - else if(zs.avail_in == 0 && ( - old_flush && flush <= *old_flush - ) && flush != Flush::finish) - { - /* Make sure there is something to do and avoid duplicate consecutive - * flushes. For repeated and useless calls with Flush::finish, we keep - * returning Z_STREAM_END instead of Z_BUF_ERROR. - */ - ec = error::need_buffers; - return; - } - - // User must not provide more input after the first FINISH: - if(status_ == FINISH_STATE && zs.avail_in != 0) - { - ec = error::need_buffers; - return; - } - - /* Start a new block or continue the current one. - */ - if(zs.avail_in != 0 || lookahead_ != 0 || - (flush != Flush::none && status_ != FINISH_STATE)) - { - block_state bstate; - - switch(strategy_) - { - case Strategy::huffman: - bstate = deflate_huff(zs, flush.get()); - break; - case Strategy::rle: - bstate = deflate_rle(zs, flush.get()); - break; - default: - { - bstate = (this->*(get_config(level_).func))(zs, flush.get()); - break; - } - } - - if(bstate == finish_started || bstate == finish_done) - { - status_ = FINISH_STATE; - } - if(bstate == need_more || bstate == finish_started) - { - if(zs.avail_out == 0) - { - last_flush_ = boost::none; /* avoid BUF_ERROR next call, see above */ - } - return; - /* If flush != Flush::none && avail_out == 0, the next call - of deflate should use the same flush parameter to make sure - that the flush is complete. So we don't have to output an - empty block here, this will be done at next call. This also - ensures that for a very small output buffer, we emit at most - one empty block. - */ - } - if(bstate == block_done) - { - if(flush == Flush::partial) - { - tr_align(); - } - else if(flush != Flush::block) - { - /* FULL_FLUSH or SYNC_FLUSH */ - tr_stored_block((char*)0, 0L, 0); - /* For a full flush, this empty block will be recognized - * as a special marker by inflate_sync(). - */ - if(flush == Flush::full) - { - clear_hash(); // forget history - if(lookahead_ == 0) - { - strstart_ = 0; - block_start_ = 0L; - insert_ = 0; - } - } - } - flush_pending(zs); - if(zs.avail_out == 0) - { - last_flush_ = boost::none; /* avoid BUF_ERROR at next call, see above */ - return; - } - } - } - - if(flush == Flush::finish) - { - ec = error::end_of_stream; - return; - } -} - -// VFALCO Warning: untested -template -void -deflate_stream:: -doDictionary(Byte const* dict, uInt dictLength, error_code& ec) -{ - if(lookahead_) - { - ec = error::stream_error; - return; - } - - maybe_init(); - - /* if dict would fill window, just replace the history */ - if(dictLength >= w_size_) - { - clear_hash(); - strstart_ = 0; - block_start_ = 0L; - insert_ = 0; - dict += dictLength - w_size_; /* use the tail */ - dictLength = w_size_; - } - - /* insert dict into window and hash */ - z_params zs; - zs.avail_in = dictLength; - zs.next_in = (const Byte *)dict; - zs.avail_out = 0; - zs.next_out = 0; - fill_window(zs); - while(lookahead_ >= minMatch) - { - uInt str = strstart_; - uInt n = lookahead_ - (minMatch-1); - do - { - update_hash(ins_h_, window_[str + minMatch-1]); - prev_[str & w_mask_] = head_[ins_h_]; - head_[ins_h_] = (std::uint16_t)str; - str++; - } - while(--n); - strstart_ = str; - lookahead_ = minMatch-1; - fill_window(zs); - } - strstart_ += lookahead_; - block_start_ = (long)strstart_; - insert_ = lookahead_; - lookahead_ = 0; - match_length_ = prev_length_ = minMatch-1; - match_available_ = 0; -} - -template -void -deflate_stream:: -doPrime(int bits, int value, error_code& ec) -{ - maybe_init(); - - if((Byte *)(d_buf_) < pending_out_ + ((Buf_size + 7) >> 3)) - { - ec = error::need_buffers; - return; - } - - do - { - int put = Buf_size - bi_valid_; - if(put > bits) - put = bits; - bi_buf_ |= (std::uint16_t)((value & ((1 << put) - 1)) << bi_valid_); - bi_valid_ += put; - tr_flush_bits(); - value >>= put; - bits -= put; - } - while(bits); -} - -template -void -deflate_stream:: -doPending(unsigned* value, int* bits) -{ - if(value != 0) - *value = pending_; - if(bits != 0) - *bits = bi_valid_; -} - -//-------------------------------------------------------------------------- - -// Do lazy initialization -template -void -deflate_stream:: -init() -{ - // Caller must set these: - // w_bits_ - // hash_bits_ - // lit_bufsize_ - // level_ - // strategy_ - - w_size_ = 1 << w_bits_; - w_mask_ = w_size_ - 1; - - hash_size_ = 1 << hash_bits_; - hash_mask_ = hash_size_ - 1; - hash_shift_ = ((hash_bits_+minMatch-1)/minMatch); - - auto const nwindow = w_size_ * 2*sizeof(Byte); - auto const nprev = w_size_ * sizeof(std::uint16_t); - auto const nhead = hash_size_ * sizeof(std::uint16_t); - auto const noverlay = lit_bufsize_ * (sizeof(std::uint16_t)+2); - auto const needed = nwindow + nprev + nhead + noverlay; - - if(! buf_ || buf_size_ != needed) - { - buf_ = boost::make_unique_noinit< - std::uint8_t[]>(needed); - buf_size_ = needed; - } - - window_ = reinterpret_cast(buf_.get()); - prev_ = reinterpret_cast(buf_.get() + nwindow); - head_ = reinterpret_cast(buf_.get() + nwindow + nprev); - - /* We overlay pending_buf_ and d_buf_ + l_buf_. This works - since the average output size for(length, distance) - codes is <= 24 bits. - */ - auto overlay = reinterpret_cast( - buf_.get() + nwindow + nprev + nhead); - - // nothing written to window_ yet - high_water_ = 0; - - pending_buf_ = - reinterpret_cast(overlay); - pending_buf_size_ = - static_cast(lit_bufsize_) * - (sizeof(std::uint16_t) + 2L); - - d_buf_ = overlay + lit_bufsize_ / sizeof(std::uint16_t); - l_buf_ = pending_buf_ + (1 + sizeof(std::uint16_t)) * lit_bufsize_; - - pending_ = 0; - pending_out_ = pending_buf_; - - status_ = BUSY_STATE; - last_flush_ = Flush::none; - - tr_init(); - lm_init(); - - inited_ = true; -} - -/* Initialize the "longest match" routines for a new zlib stream -*/ -template -void -deflate_stream:: -lm_init() -{ - window_size_ = (std::uint32_t)2L*w_size_; - - clear_hash(); - - /* Set the default configuration parameters: - */ - // VFALCO TODO just copy the config struct - max_lazy_match_ = get_config(level_).max_lazy; - good_match_ = get_config(level_).good_length; - nice_match_ = get_config(level_).nice_length; - max_chain_length_ = get_config(level_).max_chain; - - strstart_ = 0; - block_start_ = 0L; - lookahead_ = 0; - insert_ = 0; - match_length_ = prev_length_ = minMatch-1; - match_available_ = 0; - ins_h_ = 0; -} - -// Initialize a new block. -// -template -void -deflate_stream:: -init_block() -{ - for(int n = 0; n < lCodes; n++) - dyn_ltree_[n].fc = 0; - for(int n = 0; n < dCodes; n++) - dyn_dtree_[n].fc = 0; - for(int n = 0; n < blCodes; n++) - bl_tree_[n].fc = 0; - dyn_ltree_[END_BLOCK].fc = 1; - opt_len_ = 0L; - static_len_ = 0L; - last_lit_ = 0; - matches_ = 0; -} - -/* Restore the heap property by moving down the tree starting at node k, - exchanging a node with the smallest of its two sons if necessary, - stopping when the heap property is re-established (each father smaller - than its two sons). -*/ -template -void -deflate_stream:: -pqdownheap( - ct_data const* tree, // the tree to restore - int k) // node to move down -{ - int v = heap_[k]; - int j = k << 1; // left son of k - while(j <= heap_len_) - { - // Set j to the smallest of the two sons: - if(j < heap_len_ && - smaller(tree, heap_[j+1], heap_[j])) - j++; - // Exit if v is smaller than both sons - if(smaller(tree, v, heap_[j])) - break; - - // Exchange v with the smallest son - heap_[k] = heap_[j]; - k = j; - - // And continue down the tree, - // setting j to the left son of k - j <<= 1; - } - heap_[k] = v; -} - -/* Remove the smallest element from the heap and recreate the heap - with one less element. Updates heap and heap_len. -*/ -template -inline -void -deflate_stream:: -pqremove(ct_data const* tree, int& top) -{ - top = heap_[kSmallest]; - heap_[kSmallest] = heap_[heap_len_--]; - pqdownheap(tree, kSmallest); -} - -/* Compute the optimal bit lengths for a tree and update the total bit length - for the current block. - IN assertion: the fields freq and dad are set, heap[heap_max] and - above are the tree nodes sorted by increasing frequency. - OUT assertions: the field len is set to the optimal bit length, the - array bl_count contains the frequencies for each bit length. - The length opt_len is updated; static_len is also updated if stree is - not null. -*/ -template -void -deflate_stream:: -gen_bitlen(tree_desc *desc) -{ - ct_data *tree = desc->dyn_tree; - int max_code = desc->max_code; - ct_data const* stree = desc->stat_desc->static_tree; - std::uint8_t const *extra = desc->stat_desc->extra_bits; - int base = desc->stat_desc->extra_base; - int max_length = desc->stat_desc->max_length; - int h; // heap index - int n, m; // iterate over the tree elements - int bits; // bit length - int xbits; // extra bits - std::uint16_t f; // frequency - int overflow = 0; // number of elements with bit length too large - - std::fill(&bl_count_[0], &bl_count_[maxBits+1], std::uint16_t{0}); - - /* In a first pass, compute the optimal bit lengths (which may - * overflow in the case of the bit length tree). - */ - tree[heap_[heap_max_]].dl = 0; // root of the heap - - for(h = heap_max_+1; h < HEAP_SIZE; h++) { - n = heap_[h]; - bits = tree[tree[n].dl].dl + 1; - if(bits > max_length) bits = max_length, overflow++; - // We overwrite tree[n].dl which is no longer needed - tree[n].dl = (std::uint16_t)bits; - - if(n > max_code) - continue; // not a leaf node - - bl_count_[bits]++; - xbits = 0; - if(n >= base) - xbits = extra[n-base]; - f = tree[n].fc; - opt_len_ += (std::uint32_t)f * (bits + xbits); - if(stree) - static_len_ += (std::uint32_t)f * (stree[n].dl + xbits); - } - if(overflow == 0) - return; - - // Find the first bit length which could increase: - do - { - bits = max_length-1; - while(bl_count_[bits] == 0) - bits--; - bl_count_[bits]--; // move one leaf down the tree - bl_count_[bits+1] += 2; // move one overflow item as its brother - bl_count_[max_length]--; - /* The brother of the overflow item also moves one step up, - * but this does not affect bl_count[max_length] - */ - overflow -= 2; - } - while(overflow > 0); - - /* Now recompute all bit lengths, scanning in increasing frequency. - * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all - * lengths instead of fixing only the wrong ones. This idea is taken - * from 'ar' written by Haruhiko Okumura.) - */ - for(bits = max_length; bits != 0; bits--) - { - n = bl_count_[bits]; - while(n != 0) - { - m = heap_[--h]; - if(m > max_code) - continue; - if((unsigned) tree[m].dl != (unsigned) bits) - { - opt_len_ += ((long)bits - (long)tree[m].dl) *(long)tree[m].fc; - tree[m].dl = (std::uint16_t)bits; - } - n--; - } - } -} - -/* Construct one Huffman tree and assigns the code bit strings and lengths. - Update the total bit length for the current block. - IN assertion: the field freq is set for all tree elements. - OUT assertions: the fields len and code are set to the optimal bit length - and corresponding code. The length opt_len is updated; static_len is - also updated if stree is not null. The field max_code is set. -*/ -template -void -deflate_stream:: -build_tree(tree_desc *desc) -{ - ct_data *tree = desc->dyn_tree; - ct_data const* stree = desc->stat_desc->static_tree; - int elems = desc->stat_desc->elems; - int n, m; // iterate over heap elements - int max_code = -1; // largest code with non zero frequency - int node; // new node being created - - /* Construct the initial heap, with least frequent element in - * heap[kSmallest]. The sons of heap[n] are heap[2*n] and heap[2*n+1]. - * heap[0] is not used. - */ - heap_len_ = 0; - heap_max_ = HEAP_SIZE; - - for(n = 0; n < elems; n++) - { - if(tree[n].fc != 0) - { - heap_[++(heap_len_)] = max_code = n; - depth_[n] = 0; - } - else - { - tree[n].dl = 0; - } - } - - /* The pkzip format requires that at least one distance code exists, - * and that at least one bit should be sent even if there is only one - * possible code. So to avoid special checks later on we force at least - * two codes of non zero frequency. - */ - while(heap_len_ < 2) - { - node = heap_[++(heap_len_)] = (max_code < 2 ? ++max_code : 0); - tree[node].fc = 1; - depth_[node] = 0; - opt_len_--; - if(stree) - static_len_ -= stree[node].dl; - // node is 0 or 1 so it does not have extra bits - } - desc->max_code = max_code; - - /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree, - * establish sub-heaps of increasing lengths: - */ - for(n = heap_len_/2; n >= 1; n--) - pqdownheap(tree, n); - - /* Construct the Huffman tree by repeatedly combining the least two - * frequent nodes. - */ - node = elems; /* next internal node of the tree */ - do - { - pqremove(tree, n); /* n = node of least frequency */ - m = heap_[kSmallest]; /* m = node of next least frequency */ - - heap_[--(heap_max_)] = n; /* keep the nodes sorted by frequency */ - heap_[--(heap_max_)] = m; - - /* Create a new node father of n and m */ - tree[node].fc = tree[n].fc + tree[m].fc; - depth_[node] = (std::uint8_t)((depth_[n] >= depth_[m] ? - depth_[n] : depth_[m]) + 1); - tree[n].dl = tree[m].dl = (std::uint16_t)node; - /* and insert the new node in the heap */ - heap_[kSmallest] = node++; - pqdownheap(tree, kSmallest); - - } - while(heap_len_ >= 2); - - heap_[--(heap_max_)] = heap_[kSmallest]; - - /* At this point, the fields freq and dad are set. We can now - * generate the bit lengths. - */ - gen_bitlen((tree_desc *)desc); - - /* The field len is now set, we can generate the bit codes */ - gen_codes(tree, max_code, bl_count_); -} - -/* Scan a literal or distance tree to determine the frequencies - of the codes in the bit length tree. -*/ -template -void -deflate_stream:: -scan_tree( - ct_data *tree, // the tree to be scanned - int max_code) // and its largest code of non zero frequency -{ - int n; // iterates over all tree elements - int prevlen = -1; // last emitted length - int curlen; // length of current code - int nextlen = tree[0].dl; // length of next code - std::uint16_t count = 0; // repeat count of the current code - int max_count = 7; // max repeat count - int min_count = 4; // min repeat count - - if(nextlen == 0) - { - max_count = 138; - min_count = 3; - } - tree[max_code+1].dl = (std::uint16_t)0xffff; // guard - - for(n = 0; n <= max_code; n++) - { - curlen = nextlen; nextlen = tree[n+1].dl; - if(++count < max_count && curlen == nextlen) - { - continue; - } - else if(count < min_count) - { - bl_tree_[curlen].fc += count; - } - else if(curlen != 0) - { - if(curlen != prevlen) bl_tree_[curlen].fc++; - bl_tree_[REP_3_6].fc++; - } - else if(count <= 10) - { - bl_tree_[REPZ_3_10].fc++; - } - else - { - bl_tree_[REPZ_11_138].fc++; - } - count = 0; - prevlen = curlen; - if(nextlen == 0) - { - max_count = 138; - min_count = 3; - } - else if(curlen == nextlen) - { - max_count = 6; - min_count = 3; - } - else - { - max_count = 7; - min_count = 4; - } - } -} - -/* Send a literal or distance tree in compressed form, - using the codes in bl_tree. -*/ -template -void -deflate_stream:: -send_tree( - ct_data *tree, // the tree to be scanned - int max_code) // and its largest code of non zero frequency -{ - int n; // iterates over all tree elements - int prevlen = -1; // last emitted length - int curlen; // length of current code - int nextlen = tree[0].dl; // length of next code - int count = 0; // repeat count of the current code - int max_count = 7; // max repeat count - int min_count = 4; // min repeat count - - // tree[max_code+1].dl = -1; // guard already set - if(nextlen == 0) - { - max_count = 138; - min_count = 3; - } - - for(n = 0; n <= max_code; n++) - { - curlen = nextlen; - nextlen = tree[n+1].dl; - if(++count < max_count && curlen == nextlen) - { - continue; - } - else if(count < min_count) - { - do - { - send_code(curlen, bl_tree_); - } - while (--count != 0); - } - else if(curlen != 0) - { - if(curlen != prevlen) - { - send_code(curlen, bl_tree_); - count--; - } - BOOST_ASSERT(count >= 3 && count <= 6); - send_code(REP_3_6, bl_tree_); - send_bits(count-3, 2); - } - else if(count <= 10) - { - send_code(REPZ_3_10, bl_tree_); - send_bits(count-3, 3); - } - else - { - send_code(REPZ_11_138, bl_tree_); - send_bits(count-11, 7); - } - count = 0; - prevlen = curlen; - if(nextlen == 0) - { - max_count = 138; - min_count = 3; - } - else if(curlen == nextlen) - { - max_count = 6; - min_count = 3; - } - else - { - max_count = 7; - min_count = 4; - } - } -} - -/* Construct the Huffman tree for the bit lengths and return - the index in bl_order of the last bit length code to send. -*/ -template -int -deflate_stream:: -build_bl_tree() -{ - int max_blindex; // index of last bit length code of non zero freq - - // Determine the bit length frequencies for literal and distance trees - scan_tree((ct_data *)dyn_ltree_, l_desc_.max_code); - scan_tree((ct_data *)dyn_dtree_, d_desc_.max_code); - - // Build the bit length tree: - build_tree((tree_desc *)(&(bl_desc_))); - /* opt_len now includes the length of the tree representations, except - * the lengths of the bit lengths codes and the 5+5+4 bits for the counts. - */ - - /* Determine the number of bit length codes to send. The pkzip format - * requires that at least 4 bit length codes be sent. (appnote.txt says - * 3 but the actual value used is 4.) - */ - for(max_blindex = blCodes-1; max_blindex >= 3; max_blindex--) - { - if(bl_tree_[lut_.bl_order[max_blindex]].dl != 0) - break; - } - // Update opt_len to include the bit length tree and counts - opt_len_ += 3*(max_blindex+1) + 5+5+4; - return max_blindex; -} - -/* Send the header for a block using dynamic Huffman trees: the counts, - the lengths of the bit length codes, the literal tree and the distance - tree. - IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. -*/ -template -void -deflate_stream:: -send_all_trees( - int lcodes, - int dcodes, - int blcodes) // number of codes for each tree -{ - int rank; // index in bl_order - - BOOST_ASSERT(lcodes >= 257 && dcodes >= 1 && blcodes >= 4); - BOOST_ASSERT(lcodes <= lCodes && dcodes <= dCodes && blcodes <= blCodes); - send_bits(lcodes-257, 5); // not +255 as stated in appnote.txt - send_bits(dcodes-1, 5); - send_bits(blcodes-4, 4); // not -3 as stated in appnote.txt - for(rank = 0; rank < blcodes; rank++) - send_bits(bl_tree_[lut_.bl_order[rank]].dl, 3); - send_tree((ct_data *)dyn_ltree_, lcodes-1); // literal tree - send_tree((ct_data *)dyn_dtree_, dcodes-1); // distance tree -} - -/* Send the block data compressed using the given Huffman trees -*/ -template -void -deflate_stream:: -compress_block( - ct_data const* ltree, // literal tree - ct_data const* dtree) // distance tree -{ - unsigned dist; /* distance of matched string */ - int lc; /* match length or unmatched char (if dist == 0) */ - unsigned lx = 0; /* running index in l_buf */ - unsigned code; /* the code to send */ - int extra; /* number of extra bits to send */ - - if(last_lit_ != 0) - { - do - { - dist = d_buf_[lx]; - lc = l_buf_[lx++]; - if(dist == 0) - { - send_code(lc, ltree); /* send a literal byte */ - } - else - { - /* Here, lc is the match length - minMatch */ - code = lut_.length_code[lc]; - send_code(code+literals+1, ltree); /* send the length code */ - extra = lut_.extra_lbits[code]; - if(extra != 0) - { - lc -= lut_.base_length[code]; - send_bits(lc, extra); /* send the extra length bits */ - } - dist--; /* dist is now the match distance - 1 */ - code = d_code(dist); - BOOST_ASSERT(code < dCodes); - - send_code(code, dtree); /* send the distance code */ - extra = lut_.extra_dbits[code]; - if(extra != 0) - { - dist -= lut_.base_dist[code]; - send_bits(dist, extra); /* send the extra distance bits */ - } - } /* literal or match pair ? */ - - /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */ - BOOST_ASSERT((uInt)(pending_) < lit_bufsize_ + 2*lx); - } - while(lx < last_lit_); - } - - send_code(END_BLOCK, ltree); -} - -/* Check if the data type is TEXT or BINARY, using the following algorithm: - - TEXT if the two conditions below are satisfied: - a) There are no non-portable control characters belonging to the - "black list" (0..6, 14..25, 28..31). - b) There is at least one printable character belonging to the - "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255). - - BINARY otherwise. - - The following partially-portable control characters form a - "gray list" that is ignored in this detection algorithm: - (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}). - IN assertion: the fields fc of dyn_ltree are set. -*/ -template -int -deflate_stream:: -detect_data_type() -{ - /* black_mask is the bit mask of black-listed bytes - * set bits 0..6, 14..25, and 28..31 - * 0xf3ffc07f = binary 11110011111111111100000001111111 - */ - unsigned long black_mask = 0xf3ffc07fUL; - int n; - - // Check for non-textual ("black-listed") bytes. - for(n = 0; n <= 31; n++, black_mask >>= 1) - if((black_mask & 1) && (dyn_ltree_[n].fc != 0)) - return Z_BINARY; - - // Check for textual ("white-listed") bytes. */ - if(dyn_ltree_[9].fc != 0 || dyn_ltree_[10].fc != 0 - || dyn_ltree_[13].fc != 0) - return Z_TEXT; - for(n = 32; n < literals; n++) - if(dyn_ltree_[n].fc != 0) - return Z_TEXT; - - /* There are no "black-listed" or "white-listed" bytes: - * this stream either is empty or has tolerated ("gray-listed") bytes only. - */ - return Z_BINARY; -} - -/* Flush the bit buffer and align the output on a byte boundary -*/ -template -void -deflate_stream:: -bi_windup() -{ - if(bi_valid_ > 8) - put_short(bi_buf_); - else if(bi_valid_ > 0) - put_byte((Byte)bi_buf_); - bi_buf_ = 0; - bi_valid_ = 0; -} - -/* Flush the bit buffer, keeping at most 7 bits in it. -*/ -template -void -deflate_stream:: -bi_flush() -{ - if(bi_valid_ == 16) - { - put_short(bi_buf_); - bi_buf_ = 0; - bi_valid_ = 0; - } - else if(bi_valid_ >= 8) - { - put_byte((Byte)bi_buf_); - bi_buf_ >>= 8; - bi_valid_ -= 8; - } -} - -/* Copy a stored block, storing first the length and its - one's complement if requested. -*/ -template -void -deflate_stream:: -copy_block( - char *buf, // the input data - unsigned len, // its length - int header) // true if block header must be written -{ - bi_windup(); // align on byte boundary - - if(header) - { - put_short((std::uint16_t)len); - put_short((std::uint16_t)~len); - } - // VFALCO Use memcpy? - while (len--) - put_byte(*buf++); -} - -//------------------------------------------------------------------------------ - -/* Initialize the tree data structures for a new zlib stream. -*/ -template -void -deflate_stream:: -tr_init() -{ - l_desc_.dyn_tree = dyn_ltree_; - l_desc_.stat_desc = &lut_.l_desc; - - d_desc_.dyn_tree = dyn_dtree_; - d_desc_.stat_desc = &lut_.d_desc; - - bl_desc_.dyn_tree = bl_tree_; - bl_desc_.stat_desc = &lut_.bl_desc; - - bi_buf_ = 0; - bi_valid_ = 0; - - // Initialize the first block of the first file: - init_block(); -} - -/* Send one empty static block to give enough lookahead for inflate. - This takes 10 bits, of which 7 may remain in the bit buffer. -*/ -template -void -deflate_stream:: -tr_align() -{ - send_bits(STATIC_TREES<<1, 3); - send_code(END_BLOCK, lut_.ltree); - bi_flush(); -} - -/* Flush the bits in the bit buffer to pending output (leaves at most 7 bits) -*/ -template -void -deflate_stream:: -tr_flush_bits() -{ - bi_flush(); -} - -/* Send a stored block -*/ -template -void -deflate_stream:: -tr_stored_block( - char *buf, // input block - std::uint32_t stored_len, // length of input block - int last) // one if this is the last block for a file -{ - send_bits((STORED_BLOCK<<1)+last, 3); // send block type - copy_block(buf, (unsigned)stored_len, 1); // with header -} - -template -inline -void -deflate_stream:: -tr_tally_dist(std::uint16_t dist, std::uint8_t len, bool& flush) -{ - d_buf_[last_lit_] = dist; - l_buf_[last_lit_++] = len; - dist--; - dyn_ltree_[lut_.length_code[len]+literals+1].fc++; - dyn_dtree_[d_code(dist)].fc++; - flush = (last_lit_ == lit_bufsize_-1); -} - -template -inline -void -deflate_stream:: -tr_tally_lit(std::uint8_t c, bool& flush) -{ - d_buf_[last_lit_] = 0; - l_buf_[last_lit_++] = c; - dyn_ltree_[c].fc++; - flush = (last_lit_ == lit_bufsize_-1); -} - -//------------------------------------------------------------------------------ - -/* Determine the best encoding for the current block: dynamic trees, - static trees or store, and output the encoded block to the zip file. -*/ -template -void -deflate_stream:: -tr_flush_block( - z_params& zs, - char *buf, // input block, or NULL if too old - std::uint32_t stored_len, // length of input block - int last) // one if this is the last block for a file -{ - std::uint32_t opt_lenb; - std::uint32_t static_lenb; // opt_len and static_len in bytes - int max_blindex = 0; // index of last bit length code of non zero freq - - // Build the Huffman trees unless a stored block is forced - if(level_ > 0) - { - // Check if the file is binary or text - if(zs.data_type == Z_UNKNOWN) - zs.data_type = detect_data_type(); - - // Construct the literal and distance trees - build_tree((tree_desc *)(&(l_desc_))); - - build_tree((tree_desc *)(&(d_desc_))); - /* At this point, opt_len and static_len are the total bit lengths of - * the compressed block data, excluding the tree representations. - */ - - /* Build the bit length tree for the above two trees, and get the index - * in bl_order of the last bit length code to send. - */ - max_blindex = build_bl_tree(); - - /* Determine the best encoding. Compute the block lengths in bytes. */ - opt_lenb = (opt_len_+3+7)>>3; - static_lenb = (static_len_+3+7)>>3; - - if(static_lenb <= opt_lenb) - opt_lenb = static_lenb; - } - else - { - // VFALCO This assertion fails even in the original ZLib, - // happens with strategy == Z_HUFFMAN_ONLY, see: - // https://github.com/madler/zlib/issues/172 - - #if 0 - BOOST_ASSERT(buf); - #endif - opt_lenb = static_lenb = stored_len + 5; // force a stored block - } - -#ifdef FORCE_STORED - if(buf != (char*)0) { /* force stored block */ -#else - if(stored_len+4 <= opt_lenb && buf != (char*)0) { - /* 4: two words for the lengths */ -#endif - /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE. - * Otherwise we can't have processed more than WSIZE input bytes since - * the last block flush, because compression would have been - * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to - * transform a block into a stored block. - */ - tr_stored_block(buf, stored_len, last); - -#ifdef FORCE_STATIC - } - else if(static_lenb >= 0) - { - // force static trees -#else - } - else if(strategy_ == Strategy::fixed || static_lenb == opt_lenb) - { -#endif - send_bits((STATIC_TREES<<1)+last, 3); - compress_block(lut_.ltree, lut_.dtree); - } - else - { - send_bits((DYN_TREES<<1)+last, 3); - send_all_trees(l_desc_.max_code+1, d_desc_.max_code+1, - max_blindex+1); - compress_block((const ct_data *)dyn_ltree_, - (const ct_data *)dyn_dtree_); - } - /* The above check is made mod 2^32, for files larger than 512 MB - * and std::size_t implemented on 32 bits. - */ - init_block(); - - if(last) - bi_windup(); -} - -template -void -deflate_stream:: -fill_window(z_params& zs) -{ - unsigned n, m; - unsigned more; // Amount of free space at the end of the window. - std::uint16_t *p; - uInt wsize = w_size_; - - do - { - more = (unsigned)(window_size_ - - (std::uint32_t)lookahead_ -(std::uint32_t)strstart_); - - // VFALCO We don't support systems below 32-bit - #if 0 - // Deal with !@#$% 64K limit: - if(sizeof(int) <= 2) - { - if(more == 0 && strstart_ == 0 && lookahead_ == 0) - { - more = wsize; - } - else if(more == (unsigned)(-1)) - { - /* Very unlikely, but possible on 16 bit machine if - * strstart == 0 && lookahead == 1 (input done a byte at time) - */ - more--; - } - } - #endif - - /* If the window is almost full and there is insufficient lookahead, - move the upper half to the lower one to make room in the upper half. - */ - if(strstart_ >= wsize+max_dist()) - { - std::memcpy(window_, window_+wsize, (unsigned)wsize); - match_start_ -= wsize; - strstart_ -= wsize; // we now have strstart >= max_dist - block_start_ -= (long) wsize; - - /* Slide the hash table (could be avoided with 32 bit values - at the expense of memory usage). We slide even when level == 0 - to keep the hash table consistent if we switch back to level > 0 - later. (Using level 0 permanently is not an optimal usage of - zlib, so we don't care about this pathological case.) - */ - n = hash_size_; - p = &head_[n]; - do - { - m = *--p; - *p = (std::uint16_t)(m >= wsize ? m-wsize : 0); - } - while(--n); - - n = wsize; - p = &prev_[n]; - do - { - m = *--p; - *p = (std::uint16_t)(m >= wsize ? m-wsize : 0); - /* If n is not on any hash chain, prev[n] is garbage but - its value will never be used. - */ - } - while(--n); - more += wsize; - } - if(zs.avail_in == 0) - break; - - /* If there was no sliding: - strstart <= WSIZE+max_dist-1 && lookahead <= kMinLookahead - 1 && - more == window_size - lookahead - strstart - => more >= window_size - (kMinLookahead-1 + WSIZE + max_dist-1) - => more >= window_size - 2*WSIZE + 2 - In the BIG_MEM or MMAP case (not yet supported), - window_size == input_size + kMinLookahead && - strstart + lookahead_ <= input_size => more >= kMinLookahead. - Otherwise, window_size == 2*WSIZE so more >= 2. - If there was sliding, more >= WSIZE. So in all cases, more >= 2. - */ - n = read_buf(zs, window_ + strstart_ + lookahead_, more); - lookahead_ += n; - - // Initialize the hash value now that we have some input: - if(lookahead_ + insert_ >= minMatch) - { - uInt str = strstart_ - insert_; - ins_h_ = window_[str]; - update_hash(ins_h_, window_[str + 1]); - while(insert_) - { - update_hash(ins_h_, window_[str + minMatch-1]); - prev_[str & w_mask_] = head_[ins_h_]; - head_[ins_h_] = (std::uint16_t)str; - str++; - insert_--; - if(lookahead_ + insert_ < minMatch) - break; - } - } - /* If the whole input has less than minMatch bytes, ins_h is garbage, - but this is not important since only literal bytes will be emitted. - */ - } - while(lookahead_ < kMinLookahead && zs.avail_in != 0); - - /* If the kWinInit bytes after the end of the current data have never been - written, then zero those bytes in order to avoid memory check reports of - the use of uninitialized (or uninitialised as Julian writes) bytes by - the longest match routines. Update the high water mark for the next - time through here. kWinInit is set to maxMatch since the longest match - routines allow scanning to strstart + maxMatch, ignoring lookahead. - */ - if(high_water_ < window_size_) - { - std::uint32_t curr = strstart_ + (std::uint32_t)(lookahead_); - std::uint32_t winit; - - if(high_water_ < curr) - { - /* Previous high water mark below current data -- zero kWinInit - bytes or up to end of window, whichever is less. - */ - winit = window_size_ - curr; - if(winit > kWinInit) - winit = kWinInit; - std::memset(window_ + curr, 0, (unsigned)winit); - high_water_ = curr + winit; - } - else if(high_water_ < (std::uint32_t)curr + kWinInit) - { - /* High water mark at or above current data, but below current data - plus kWinInit -- zero out to current data plus kWinInit, or up - to end of window, whichever is less. - */ - winit = (std::uint32_t)curr + kWinInit - high_water_; - if(winit > window_size_ - high_water_) - winit = window_size_ - high_water_; - std::memset(window_ + high_water_, 0, (unsigned)winit); - high_water_ += winit; - } - } -} - -/* Flush as much pending output as possible. All write() output goes - through this function so some applications may wish to modify it - to avoid allocating a large strm->next_out buffer and copying into it. - (See also read_buf()). -*/ -template -void -deflate_stream:: -flush_pending(z_params& zs) -{ - tr_flush_bits(); - auto len = clamp(pending_, zs.avail_out); - if(len == 0) - return; - - std::memcpy(zs.next_out, pending_out_, len); - zs.next_out = - static_cast(zs.next_out) + len; - pending_out_ += len; - zs.total_out += len; - zs.avail_out -= len; - pending_ -= len; - if(pending_ == 0) - pending_out_ = pending_buf_; -} - -/* Flush the current block, with given end-of-file flag. - IN assertion: strstart is set to the end of the current match. -*/ -template -inline -void -deflate_stream:: -flush_block(z_params& zs, bool last) -{ - tr_flush_block(zs, - (block_start_ >= 0L ? - (char *)&window_[(unsigned)block_start_] : - (char *)0), - (std::uint32_t)((long)strstart_ - block_start_), - last); - block_start_ = strstart_; - flush_pending(zs); -} - -/* Read a new buffer from the current input stream, update the adler32 - and total number of bytes read. All write() input goes through - this function so some applications may wish to modify it to avoid - allocating a large strm->next_in buffer and copying from it. - (See also flush_pending()). -*/ -template -int -deflate_stream:: -read_buf(z_params& zs, Byte *buf, unsigned size) -{ - auto len = clamp(zs.avail_in, size); - if(len == 0) - return 0; - - zs.avail_in -= len; - - std::memcpy(buf, zs.next_in, len); - zs.next_in = static_cast< - std::uint8_t const*>(zs.next_in) + len; - zs.total_in += len; - return (int)len; -} - -/* Set match_start to the longest match starting at the given string and - return its length. Matches shorter or equal to prev_length are discarded, - in which case the result is equal to prev_length and match_start is - garbage. - IN assertions: cur_match is the head of the hash chain for the current - string (strstart) and its distance is <= max_dist, and prev_length >= 1 - OUT assertion: the match length is not greater than s->lookahead_. - - For 80x86 and 680x0, an optimized version will be provided in match.asm or - match.S. The code will be functionally equivalent. -*/ -template -uInt -deflate_stream:: -longest_match(IPos cur_match) -{ - unsigned chain_length = max_chain_length_;/* max hash chain length */ - Byte *scan = window_ + strstart_; /* current string */ - Byte *match; /* matched string */ - int len; /* length of current match */ - int best_len = prev_length_; /* best match length so far */ - int nice_match = nice_match_; /* stop if match long enough */ - IPos limit = strstart_ > (IPos)max_dist() ? - strstart_ - (IPos)max_dist() : 0; - /* Stop when cur_match becomes <= limit. To simplify the code, - * we prevent matches with the string of window index 0. - */ - std::uint16_t *prev = prev_; - uInt wmask = w_mask_; - - Byte *strend = window_ + strstart_ + maxMatch; - Byte scan_end1 = scan[best_len-1]; - Byte scan_end = scan[best_len]; - - /* The code is optimized for HASH_BITS >= 8 and maxMatch-2 multiple of 16. - * It is easy to get rid of this optimization if necessary. - */ - BOOST_ASSERT(hash_bits_ >= 8 && maxMatch == 258); - - /* Do not waste too much time if we already have a good match: */ - if(prev_length_ >= good_match_) { - chain_length >>= 2; - } - /* Do not look for matches beyond the end of the input. This is necessary - * to make deflate deterministic. - */ - if((uInt)nice_match > lookahead_) - nice_match = lookahead_; - - BOOST_ASSERT((std::uint32_t)strstart_ <= window_size_-kMinLookahead); - - do { - BOOST_ASSERT(cur_match < strstart_); - match = window_ + cur_match; - - /* Skip to next match if the match length cannot increase - * or if the match length is less than 2. Note that the checks below - * for insufficient lookahead only occur occasionally for performance - * reasons. Therefore uninitialized memory will be accessed, and - * conditional jumps will be made that depend on those values. - * However the length of the match is limited to the lookahead, so - * the output of deflate is not affected by the uninitialized values. - */ - if( match[best_len] != scan_end || - match[best_len-1] != scan_end1 || - *match != *scan || - *++match != scan[1]) - continue; - - /* The check at best_len-1 can be removed because it will be made - * again later. (This heuristic is not always a win.) - * It is not necessary to compare scan[2] and match[2] since they - * are always equal when the other bytes match, given that - * the hash keys are equal and that HASH_BITS >= 8. - */ - scan += 2, match++; - BOOST_ASSERT(*scan == *match); - - /* We check for insufficient lookahead only every 8th comparison; - * the 256th check will be made at strstart+258. - */ - do - { - } - while( *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - scan < strend); - - BOOST_ASSERT(scan <= window_+(unsigned)(window_size_-1)); - - len = maxMatch - (int)(strend - scan); - scan = strend - maxMatch; - - if(len > best_len) { - match_start_ = cur_match; - best_len = len; - if(len >= nice_match) break; - scan_end1 = scan[best_len-1]; - scan_end = scan[best_len]; - } - } - while((cur_match = prev[cur_match & wmask]) > limit - && --chain_length != 0); - - if((uInt)best_len <= lookahead_) - return (uInt)best_len; - return lookahead_; -} - -//------------------------------------------------------------------------------ - -/* Copy without compression as much as possible from the input stream, return - the current block state. - This function does not insert new strings in the dictionary since - uncompressible data is probably not useful. This function is used - only for the level=0 compression option. - NOTE: this function should be optimized to avoid extra copying from - window to pending_buf. -*/ -template -inline -auto -deflate_stream:: -f_stored(z_params& zs, Flush flush) -> - block_state -{ - /* Stored blocks are limited to 0xffff bytes, pending_buf is limited - * to pending_buf_size, and each stored block has a 5 byte header: - */ - std::uint32_t max_block_size = 0xffff; - std::uint32_t max_start; - - if(max_block_size > pending_buf_size_ - 5) { - max_block_size = pending_buf_size_ - 5; - } - - /* Copy as much as possible from input to output: */ - for(;;) { - /* Fill the window as much as possible: */ - if(lookahead_ <= 1) { - - BOOST_ASSERT(strstart_ < w_size_+max_dist() || - block_start_ >= (long)w_size_); - - fill_window(zs); - if(lookahead_ == 0 && flush == Flush::none) - return need_more; - - if(lookahead_ == 0) break; /* flush the current block */ - } - BOOST_ASSERT(block_start_ >= 0L); - - strstart_ += lookahead_; - lookahead_ = 0; - - /* Emit a stored block if pending_buf will be full: */ - max_start = block_start_ + max_block_size; - if(strstart_ == 0 || (std::uint32_t)strstart_ >= max_start) { - /* strstart == 0 is possible when wraparound on 16-bit machine */ - lookahead_ = (uInt)(strstart_ - max_start); - strstart_ = (uInt)max_start; - flush_block(zs, false); - if(zs.avail_out == 0) - return need_more; - } - /* Flush if we may have to slide, otherwise block_start may become - * negative and the data will be gone: - */ - if(strstart_ - (uInt)block_start_ >= max_dist()) { - flush_block(zs, false); - if(zs.avail_out == 0) - return need_more; - } - } - insert_ = 0; - if(flush == Flush::finish) - { - flush_block(zs, true); - if(zs.avail_out == 0) - return finish_started; - return finish_done; - } - if((long)strstart_ > block_start_) - { - flush_block(zs, false); - if(zs.avail_out == 0) - return need_more; - } - return block_done; -} - -/* Compress as much as possible from the input stream, return the current - block state. - This function does not perform lazy evaluation of matches and inserts - new strings in the dictionary only for unmatched strings or for short - matches. It is used only for the fast compression options. -*/ -template -inline -auto -deflate_stream:: -f_fast(z_params& zs, Flush flush) -> - block_state -{ - IPos hash_head; /* head of the hash chain */ - bool bflush; /* set if current block must be flushed */ - - for(;;) - { - /* Make sure that we always have enough lookahead, except - * at the end of the input file. We need maxMatch bytes - * for the next match, plus minMatch bytes to insert the - * string following the next match. - */ - if(lookahead_ < kMinLookahead) - { - fill_window(zs); - if(lookahead_ < kMinLookahead && flush == Flush::none) - return need_more; - if(lookahead_ == 0) - break; /* flush the current block */ - } - - /* Insert the string window[strstart .. strstart+2] in the - * dictionary, and set hash_head to the head of the hash chain: - */ - hash_head = 0; - if(lookahead_ >= minMatch) { - insert_string(hash_head); - } - - /* Find the longest match, discarding those <= prev_length. - * At this point we have always match_length < minMatch - */ - if(hash_head != 0 && strstart_ - hash_head <= max_dist()) { - /* To simplify the code, we prevent matches with the string - * of window index 0 (in particular we have to avoid a match - * of the string with itself at the start of the input file). - */ - match_length_ = longest_match (hash_head); - /* longest_match() sets match_start */ - } - if(match_length_ >= minMatch) - { - tr_tally_dist(static_cast(strstart_ - match_start_), - static_cast(match_length_ - minMatch), bflush); - - lookahead_ -= match_length_; - - /* Insert new strings in the hash table only if the match length - * is not too large. This saves time but degrades compression. - */ - if(match_length_ <= max_lazy_match_ && - lookahead_ >= minMatch) { - match_length_--; /* string at strstart already in table */ - do - { - strstart_++; - insert_string(hash_head); - /* strstart never exceeds WSIZE-maxMatch, so there are - * always minMatch bytes ahead. - */ - } - while(--match_length_ != 0); - strstart_++; - } - else - { - strstart_ += match_length_; - match_length_ = 0; - ins_h_ = window_[strstart_]; - update_hash(ins_h_, window_[strstart_+1]); - /* If lookahead < minMatch, ins_h is garbage, but it does not - * matter since it will be recomputed at next deflate call. - */ - } - } - else - { - /* No match, output a literal byte */ - tr_tally_lit(window_[strstart_], bflush); - lookahead_--; - strstart_++; - } - if(bflush) - { - flush_block(zs, false); - if(zs.avail_out == 0) - return need_more; - } - } - insert_ = strstart_ < minMatch-1 ? strstart_ : minMatch-1; - if(flush == Flush::finish) - { - flush_block(zs, true); - if(zs.avail_out == 0) - return finish_started; - return finish_done; - } - if(last_lit_) - { - flush_block(zs, false); - if(zs.avail_out == 0) - return need_more; - } - return block_done; -} - -/* Same as above, but achieves better compression. We use a lazy - evaluation for matches: a match is finally adopted only if there is - no better match at the next window position. -*/ -template -inline -auto -deflate_stream:: -f_slow(z_params& zs, Flush flush) -> - block_state -{ - IPos hash_head; /* head of hash chain */ - bool bflush; /* set if current block must be flushed */ - - /* Process the input block. */ - for(;;) - { - /* Make sure that we always have enough lookahead, except - * at the end of the input file. We need maxMatch bytes - * for the next match, plus minMatch bytes to insert the - * string following the next match. - */ - if(lookahead_ < kMinLookahead) - { - fill_window(zs); - if(lookahead_ < kMinLookahead && flush == Flush::none) - return need_more; - if(lookahead_ == 0) - break; /* flush the current block */ - } - - /* Insert the string window[strstart .. strstart+2] in the - * dictionary, and set hash_head to the head of the hash chain: - */ - hash_head = 0; - if(lookahead_ >= minMatch) - insert_string(hash_head); - - /* Find the longest match, discarding those <= prev_length. - */ - prev_length_ = match_length_, prev_match_ = match_start_; - match_length_ = minMatch-1; - - if(hash_head != 0 && prev_length_ < max_lazy_match_ && - strstart_ - hash_head <= max_dist()) - { - /* To simplify the code, we prevent matches with the string - * of window index 0 (in particular we have to avoid a match - * of the string with itself at the start of the input file). - */ - match_length_ = longest_match(hash_head); - /* longest_match() sets match_start */ - - if(match_length_ <= 5 && (strategy_ == Strategy::filtered - || (match_length_ == minMatch && - strstart_ - match_start_ > kTooFar) - )) - { - /* If prev_match is also minMatch, match_start is garbage - * but we will ignore the current match anyway. - */ - match_length_ = minMatch-1; - } - } - /* If there was a match at the previous step and the current - * match is not better, output the previous match: - */ - if(prev_length_ >= minMatch && match_length_ <= prev_length_) - { - /* Do not insert strings in hash table beyond this. */ - uInt max_insert = strstart_ + lookahead_ - minMatch; - - tr_tally_dist( - static_cast(strstart_ -1 - prev_match_), - static_cast(prev_length_ - minMatch), bflush); - - /* Insert in hash table all strings up to the end of the match. - * strstart-1 and strstart are already inserted. If there is not - * enough lookahead, the last two strings are not inserted in - * the hash table. - */ - lookahead_ -= prev_length_-1; - prev_length_ -= 2; - do { - if(++strstart_ <= max_insert) - insert_string(hash_head); - } - while(--prev_length_ != 0); - match_available_ = 0; - match_length_ = minMatch-1; - strstart_++; - - if(bflush) - { - flush_block(zs, false); - if(zs.avail_out == 0) - return need_more; - } - - } - else if(match_available_) - { - /* If there was no match at the previous position, output a - * single literal. If there was a match but the current match - * is longer, truncate the previous match to a single literal. - */ - tr_tally_lit(window_[strstart_-1], bflush); - if(bflush) - flush_block(zs, false); - strstart_++; - lookahead_--; - if(zs.avail_out == 0) - return need_more; - } - else - { - /* There is no previous match to compare with, wait for - * the next step to decide. - */ - match_available_ = 1; - strstart_++; - lookahead_--; - } - } - BOOST_ASSERT(flush != Flush::none); - if(match_available_) - { - tr_tally_lit(window_[strstart_-1], bflush); - match_available_ = 0; - } - insert_ = strstart_ < minMatch-1 ? strstart_ : minMatch-1; - if(flush == Flush::finish) - { - flush_block(zs, true); - if(zs.avail_out == 0) - return finish_started; - return finish_done; - } - if(last_lit_) - { - flush_block(zs, false); - if(zs.avail_out == 0) - return need_more; - } - return block_done; -} - -/* For Strategy::rle, simply look for runs of bytes, generate matches only of distance - one. Do not maintain a hash table. (It will be regenerated if this run of - deflate switches away from Strategy::rle.) -*/ -template -inline -auto -deflate_stream:: -f_rle(z_params& zs, Flush flush) -> - block_state -{ - bool bflush; // set if current block must be flushed - uInt prev; // byte at distance one to match - Byte *scan, *strend; // scan goes up to strend for length of run - - for(;;) - { - /* Make sure that we always have enough lookahead, except - * at the end of the input file. We need maxMatch bytes - * for the longest run, plus one for the unrolled loop. - */ - if(lookahead_ <= maxMatch) { - fill_window(zs); - if(lookahead_ <= maxMatch && flush == Flush::none) { - return need_more; - } - if(lookahead_ == 0) break; /* flush the current block */ - } - - /* See how many times the previous byte repeats */ - match_length_ = 0; - if(lookahead_ >= minMatch && strstart_ > 0) { - scan = window_ + strstart_ - 1; - prev = *scan; - if(prev == *++scan && prev == *++scan && prev == *++scan) { - strend = window_ + strstart_ + maxMatch; - do { - } while(prev == *++scan && prev == *++scan && - prev == *++scan && prev == *++scan && - prev == *++scan && prev == *++scan && - prev == *++scan && prev == *++scan && - scan < strend); - match_length_ = maxMatch - (int)(strend - scan); - if(match_length_ > lookahead_) - match_length_ = lookahead_; - } - BOOST_ASSERT(scan <= window_+(uInt)(window_size_-1)); - } - - /* Emit match if have run of minMatch or longer, else emit literal */ - if(match_length_ >= minMatch) { - tr_tally_dist(std::uint16_t{1}, - static_cast(match_length_ - minMatch), - bflush); - - lookahead_ -= match_length_; - strstart_ += match_length_; - match_length_ = 0; - } else { - /* No match, output a literal byte */ - tr_tally_lit(window_[strstart_], bflush); - lookahead_--; - strstart_++; - } - if(bflush) - { - flush_block(zs, false); - if(zs.avail_out == 0) - return need_more; - } - } - insert_ = 0; - if(flush == Flush::finish) - { - flush_block(zs, true); - if(zs.avail_out == 0) - return finish_started; - return finish_done; - } - if(last_lit_) - { - flush_block(zs, false); - if(zs.avail_out == 0) - return need_more; - } - return block_done; -} - -/* =========================================================================== - * For Strategy::huffman, do not look for matches. Do not maintain a hash table. - * (It will be regenerated if this run of deflate switches away from Huffman.) - */ -template -inline -auto -deflate_stream:: -f_huff(z_params& zs, Flush flush) -> - block_state -{ - bool bflush; // set if current block must be flushed - - for(;;) - { - // Make sure that we have a literal to write. - if(lookahead_ == 0) - { - fill_window(zs); - if(lookahead_ == 0) - { - if(flush == Flush::none) - return need_more; - break; // flush the current block - } - } - - // Output a literal byte - match_length_ = 0; - tr_tally_lit(window_[strstart_], bflush); - lookahead_--; - strstart_++; - if(bflush) - { - flush_block(zs, false); - if(zs.avail_out == 0) - return need_more; - } - } - insert_ = 0; - if(flush == Flush::finish) - { - flush_block(zs, true); - if(zs.avail_out == 0) - return finish_started; - return finish_done; - } - if(last_lit_) - { - flush_block(zs, false); - if(zs.avail_out == 0) - return need_more; - } - return block_done; -} - -} // detail -} // zlib -} // beast - -#endif diff --git a/src/beast/include/beast/zlib/detail/inflate_stream.hpp b/src/beast/include/beast/zlib/detail/inflate_stream.hpp deleted file mode 100644 index 33372786798..00000000000 --- a/src/beast/include/beast/zlib/detail/inflate_stream.hpp +++ /dev/null @@ -1,1306 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// -// This is a derivative work based on Zlib, copyright below: -/* - Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Jean-loup Gailly Mark Adler - jloup@gzip.org madler@alumni.caltech.edu - - The data format used by the zlib library is described by RFCs (Request for - Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 - (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). -*/ - -#ifndef BEAST_ZLIB_DETAIL_INFLATE_STREAM_HPP -#define BEAST_ZLIB_DETAIL_INFLATE_STREAM_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace zlib { -namespace detail { - -class inflate_stream -{ -protected: - inflate_stream() - { - w_.reset(15); - } - - template void doClear(); - template void doReset(int windowBits); - template void doWrite(z_params& zs, Flush flush, error_code& ec); - - void - doReset() - { - doReset(w_.bits()); - } - -private: - enum Mode - { - HEAD, // i: waiting for magic header - FLAGS, // i: waiting for method and flags (gzip) - TIME, // i: waiting for modification time (gzip) - OS, // i: waiting for extra flags and operating system (gzip) - EXLEN, // i: waiting for extra length (gzip) - EXTRA, // i: waiting for extra bytes (gzip) - NAME, // i: waiting for end of file name (gzip) - COMMENT, // i: waiting for end of comment (gzip) - HCRC, // i: waiting for header crc (gzip) - TYPE, // i: waiting for type bits, including last-flag bit - TYPEDO, // i: same, but skip check to exit inflate on new block - STORED, // i: waiting for stored size (length and complement) - COPY_, // i/o: same as COPY below, but only first time in - COPY, // i/o: waiting for input or output to copy stored block - TABLE, // i: waiting for dynamic block table lengths - LENLENS, // i: waiting for code length code lengths - CODELENS, // i: waiting for length/lit and distance code lengths - LEN_, // i: same as LEN below, but only first time in - LEN, // i: waiting for length/lit/eob code - LENEXT, // i: waiting for length extra bits - DIST, // i: waiting for distance code - DISTEXT,// i: waiting for distance extra bits - MATCH, // o: waiting for output space to copy string - LIT, // o: waiting for output space to write literal - CHECK, // i: waiting for 32-bit check value - LENGTH, // i: waiting for 32-bit length (gzip) - DONE, // finished check, done -- remain here until reset - BAD, // got a data error -- remain here until reset - SYNC // looking for synchronization bytes to restart inflate() - }; - - /* Structure for decoding tables. Each entry provides either the - information needed to do the operation requested by the code that - indexed that table entry, or it provides a pointer to another - table that indexes more bits of the code. op indicates whether - the entry is a pointer to another table, a literal, a length or - distance, an end-of-block, or an invalid code. For a table - pointer, the low four bits of op is the number of index bits of - that table. For a length or distance, the low four bits of op - is the number of extra bits to get after the code. bits is - the number of bits in this code or part of the code to drop off - of the bit buffer. val is the actual byte to output in the case - of a literal, the base length or distance, or the offset from - the current table to the next table. Each entry is four bytes. - - op values as set by inflate_table(): - - 00000000 - literal - 0000tttt - table link, tttt != 0 is the number of table index bits - 0001eeee - length or distance, eeee is the number of extra bits - 01100000 - end of block - 01000000 - invalid code - */ - struct code - { - std::uint8_t op; // operation, extra bits, table bits - std::uint8_t bits; // bits in this part of the code - std::uint16_t val; // offset in table or code value - }; - - /* Maximum size of the dynamic table. The maximum number of code - structures is 1444, which is the sum of 852 for literal/length codes - and 592 for distance codes. These values were found by exhaustive - searches using the program examples/enough.c found in the zlib - distribtution. The arguments to that program are the number of - symbols, the initial root table size, and the maximum bit length - of a code. "enough 286 9 15" for literal/length codes returns - returns 852, and "enough 30 6 15" for distance codes returns 592. - The initial root table size (9 or 6) is found in the fifth argument - of the inflate_table() calls in inflate.c and infback.c. If the - root table size is changed, then these maximum sizes would be need - to be recalculated and updated. - */ - static std::uint16_t constexpr kEnoughLens = 852; - static std::uint16_t constexpr kEnoughDists = 592; - static std::uint16_t constexpr kEnough = kEnoughLens + kEnoughDists; - - struct codes - { - code const* lencode; - code const* distcode; - unsigned lenbits; // VFALCO use std::uint8_t - unsigned distbits; - }; - - // Type of code to build for inflate_table() - enum class build - { - codes, - lens, - dists - }; - - template - static - void - inflate_table( - build type, - std::uint16_t* lens, - std::size_t codes, - code** table, - unsigned *bits, - std::uint16_t* work, - error_code& ec); - - template - static - codes const& - get_fixed_tables(); - - template - void - fixedTables(); - - template - void - inflate_fast(ranges& r, error_code& ec); - - bitstream bi_; - - Mode mode_ = HEAD; // current inflate mode - int last_ = 0; // true if processing last block - unsigned dmax_ = 32768U; // zlib header max distance (INFLATE_STRICT) - - // sliding window - window w_; - - // for string and stored block copying - unsigned length_; // literal or length of data to copy - unsigned offset_; // distance back to copy string from - - // for table and code decoding - unsigned extra_; // extra bits needed - - // dynamic table building - unsigned ncode_; // number of code length code lengths - unsigned nlen_; // number of length code lengths - unsigned ndist_; // number of distance code lengths - unsigned have_; // number of code lengths in lens[] - unsigned short lens_[320]; // temporary storage for code lengths - unsigned short work_[288]; // work area for code table building - code codes_[kEnough]; // space for code tables - code *next_ = codes_; // next available space in codes[] - int back_ = -1; // bits back of last unprocessed length/lit - unsigned was_; // initial length of match - - // fixed and dynamic code tables - code const* lencode_ = codes_ ; // starting table for length/literal codes - code const* distcode_ = codes_; // starting table for distance codes - unsigned lenbits_; // index bits for lencode - unsigned distbits_; // index bits for distcode -}; - -//------------------------------------------------------------------------------ - -template -void -inflate_stream:: -doReset(int windowBits) -{ - if(windowBits < 8 || windowBits > 15) - BOOST_THROW_EXCEPTION(std::domain_error{ - "windowBits out of range"}); - w_.reset(windowBits); - - bi_.flush(); - mode_ = HEAD; - last_ = 0; - dmax_ = 32768U; - lencode_ = codes_; - distcode_ = codes_; - next_ = codes_; - back_ = -1; -} - -template -void -inflate_stream:: -doClear() -{ -} - -template -void -inflate_stream:: -doWrite(z_params& zs, Flush flush, error_code& ec) -{ - ranges r; - r.in.first = reinterpret_cast< - std::uint8_t const*>(zs.next_in); - r.in.last = r.in.first + zs.avail_in; - r.in.next = r.in.first; - r.out.first = reinterpret_cast< - std::uint8_t*>(zs.next_out); - r.out.last = r.out.first + zs.avail_out; - r.out.next = r.out.first; - - auto const done = - [&] - { - /* - Return from inflate(), updating the total counts and the check value. - If there was no progress during the inflate() call, return a buffer - error. Call updatewindow() to create and/or update the window state. - Note: a memory error from inflate() is non-recoverable. - */ - - - // VFALCO TODO Don't allocate update the window unless necessary - if(/*wsize_ ||*/ (r.out.used() && mode_ < BAD && - (mode_ < CHECK || flush != Flush::finish))) - w_.write(r.out.first, r.out.used()); - - zs.next_in = r.in.next; - zs.avail_in = r.in.avail(); - zs.next_out = r.out.next; - zs.avail_out = r.out.avail(); - zs.total_in += r.in.used(); - zs.total_out += r.out.used(); - zs.data_type = bi_.size() + (last_ ? 64 : 0) + - (mode_ == TYPE ? 128 : 0) + - (mode_ == LEN_ || mode_ == COPY_ ? 256 : 0); - - if(((! r.in.used() && ! r.out.used()) || - flush == Flush::finish) && ! ec) - ec = error::need_buffers; - }; - auto const err = - [&](error e) - { - ec = e; - mode_ = BAD; - }; - - if(mode_ == TYPE) - mode_ = TYPEDO; - - for(;;) - { - switch(mode_) - { - case HEAD: - mode_ = TYPEDO; - break; - - case TYPE: - if(flush == Flush::block || flush == Flush::trees) - return done(); - // fall through - - case TYPEDO: - { - if(last_) - { - bi_.flush_byte(); - mode_ = CHECK; - break; - } - if(! bi_.fill(3, r.in.next, r.in.last)) - return done(); - std::uint8_t v; - bi_.read(v, 1); - last_ = v != 0; - bi_.read(v, 2); - switch(v) - { - case 0: - // uncompressed block - mode_ = STORED; - break; - case 1: - // fixed Huffman table - fixedTables(); - mode_ = LEN_; /* decode codes */ - if(flush == Flush::trees) - return done(); - break; - case 2: - // dynamic Huffman table - mode_ = TABLE; - break; - - default: - return err(error::invalid_block_type); - } - break; - } - - case STORED: - { - bi_.flush_byte(); - std::uint32_t v; - if(! bi_.fill(32, r.in.next, r.in.last)) - return done(); - bi_.peek(v, 32); - length_ = v & 0xffff; - if(length_ != ((v >> 16) ^ 0xffff)) - return err(error::invalid_stored_length); - // flush instead of read, otherwise - // undefined right shift behavior. - bi_.flush(); - mode_ = COPY_; - if(flush == Flush::trees) - return done(); - // fall through - } - - case COPY_: - mode_ = COPY; - // fall through - - case COPY: - { - auto copy = length_; - if(copy == 0) - { - mode_ = TYPE; - break; - } - copy = clamp(copy, r.in.avail()); - copy = clamp(copy, r.out.avail()); - if(copy == 0) - return done(); - std::memcpy(r.out.next, r.in.next, copy); - r.in.next += copy; - r.out.next += copy; - length_ -= copy; - break; - } - - case TABLE: - if(! bi_.fill(5 + 5 + 4, r.in.next, r.in.last)) - return done(); - bi_.read(nlen_, 5); - nlen_ += 257; - bi_.read(ndist_, 5); - ndist_ += 1; - bi_.read(ncode_, 4); - ncode_ += 4; - if(nlen_ > 286 || ndist_ > 30) - return err(error::too_many_symbols); - have_ = 0; - mode_ = LENLENS; - // fall through - - case LENLENS: - { - static std::array constexpr order = {{ - 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}}; - while(have_ < ncode_) - { - if(! bi_.fill(3, r.in.next, r.in.last)) - return done(); - bi_.read(lens_[order[have_]], 3); - ++have_; - } - while(have_ < order.size()) - lens_[order[have_++]] = 0; - - next_ = &codes_[0]; - lencode_ = next_; - lenbits_ = 7; - inflate_table(build::codes, &lens_[0], - order.size(), &next_, &lenbits_, work_, ec); - if(ec) - { - mode_ = BAD; - break; - } - have_ = 0; - mode_ = CODELENS; - // fall through - } - - case CODELENS: - { - while(have_ < nlen_ + ndist_) - { - std::uint16_t v; - if(! bi_.fill(lenbits_, r.in.next, r.in.last)) - return done(); - bi_.peek(v, lenbits_); - auto cp = &lencode_[v]; - if(cp->val < 16) - { - bi_.drop(cp->bits); - lens_[have_++] = cp->val; - } - else - { - std::uint16_t len; - std::uint16_t copy; - if(cp->val == 16) - { - if(! bi_.fill(cp->bits + 2, r.in.next, r.in.last)) - return done(); - bi_.drop(cp->bits); - if(have_ == 0) - return err(error::invalid_bit_length_repeat); - bi_.read(copy, 2); - len = lens_[have_ - 1]; - copy += 3; - - } - else if(cp->val == 17) - { - if(! bi_.fill(cp->bits + 3, r.in.next, r.in.last)) - return done(); - bi_.drop(cp->bits); - bi_.read(copy, 3); - len = 0; - copy += 3; - } - else - { - if(! bi_.fill(cp->bits + 7, r.in.next, r.in.last)) - return done(); - bi_.drop(cp->bits); - bi_.read(copy, 7); - len = 0; - copy += 11; - } - if(have_ + copy > nlen_ + ndist_) - return err(error::invalid_bit_length_repeat); - std::fill(&lens_[have_], &lens_[have_ + copy], len); - have_ += copy; - copy = 0; - } - } - // handle error breaks in while - if(mode_ == BAD) - break; - // check for end-of-block code (better have one) - if(lens_[256] == 0) - return err(error::missing_eob); - /* build code tables -- note: do not change the lenbits or distbits - values here (9 and 6) without reading the comments in inftrees.hpp - concerning the kEnough constants, which depend on those values */ - next_ = &codes_[0]; - lencode_ = next_; - lenbits_ = 9; - inflate_table(build::lens, &lens_[0], - nlen_, &next_, &lenbits_, work_, ec); - if(ec) - { - mode_ = BAD; - return; - } - distcode_ = next_; - distbits_ = 6; - inflate_table(build::dists, lens_ + nlen_, - ndist_, &next_, &distbits_, work_, ec); - if(ec) - { - mode_ = BAD; - return; - } - mode_ = LEN_; - if(flush == Flush::trees) - return done(); - // fall through - } - - case LEN_: - mode_ = LEN; - // fall through - - case LEN: - { - if(r.in.avail() >= 6 && r.out.avail() >= 258) - { - inflate_fast(r, ec); - if(ec) - { - mode_ = BAD; - return; - } - if(mode_ == TYPE) - back_ = -1; - break; - } - if(! bi_.fill(lenbits_, r.in.next, r.in.last)) - return done(); - std::uint16_t v; - back_ = 0; - bi_.peek(v, lenbits_); - auto cp = &lencode_[v]; - if(cp->op && (cp->op & 0xf0) == 0) - { - auto prev = cp; - if(! bi_.fill(prev->bits + prev->op, r.in.next, r.in.last)) - return done(); - bi_.peek(v, prev->bits + prev->op); - cp = &lencode_[prev->val + (v >> prev->bits)]; - bi_.drop(prev->bits + cp->bits); - back_ += prev->bits + cp->bits; - } - else - { - bi_.drop(cp->bits); - back_ += cp->bits; - } - length_ = cp->val; - if(cp->op == 0) - { - mode_ = LIT; - break; - } - if(cp->op & 32) - { - back_ = -1; - mode_ = TYPE; - break; - } - if(cp->op & 64) - return err(error::invalid_literal_length); - extra_ = cp->op & 15; - mode_ = LENEXT; - // fall through - } - - case LENEXT: - if(extra_) - { - if(! bi_.fill(extra_, r.in.next, r.in.last)) - return done(); - std::uint16_t v; - bi_.read(v, extra_); - length_ += v; - back_ += extra_; - } - was_ = length_; - mode_ = DIST; - // fall through - - case DIST: - { - if(! bi_.fill(distbits_, r.in.next, r.in.last)) - return done(); - std::uint16_t v; - bi_.peek(v, distbits_); - auto cp = &distcode_[v]; - if((cp->op & 0xf0) == 0) - { - auto prev = cp; - if(! bi_.fill(prev->bits + prev->op, r.in.next, r.in.last)) - return done(); - bi_.peek(v, prev->bits + prev->op); - cp = &distcode_[prev->val + (v >> prev->bits)]; - bi_.drop(prev->bits + cp->bits); - back_ += prev->bits + cp->bits; - } - else - { - bi_.drop(cp->bits); - back_ += cp->bits; - } - if(cp->op & 64) - return err(error::invalid_distance_code); - offset_ = cp->val; - extra_ = cp->op & 15; - mode_ = DISTEXT; - // fall through - } - - case DISTEXT: - if(extra_) - { - std::uint16_t v; - if(! bi_.fill(extra_, r.in.next, r.in.last)) - return done(); - bi_.read(v, extra_); - offset_ += v; - back_ += extra_; - } -#ifdef INFLATE_STRICT - if(offset_ > dmax_) - return err(error::invalid_distance); -#endif - mode_ = MATCH; - // fall through - - case MATCH: - { - if(! r.out.avail()) - return done(); - if(offset_ > r.out.used()) - { - // copy from window - auto offset = static_cast( - offset_ - r.out.used()); - if(offset > w_.size()) - return err(error::invalid_distance); - auto const n = clamp(clamp( - length_, offset), r.out.avail()); - w_.read(r.out.next, offset, n); - r.out.next += n; - length_ -= n; - } - else - { - // copy from output - auto in = r.out.next - offset_; - auto n = clamp(length_, r.out.avail()); - length_ -= n; - while(n--) - *r.out.next++ = *in++; - } - if(length_ == 0) - mode_ = LEN; - break; - } - - case LIT: - { - if(! r.out.avail()) - return done(); - auto const v = static_cast(length_); - *r.out.next++ = v; - mode_ = LEN; - break; - } - - case CHECK: - mode_ = DONE; - // fall through - - case DONE: - ec = error::end_of_stream; - return done(); - - case BAD: - return done(); - - case SYNC: - default: - BOOST_THROW_EXCEPTION(std::logic_error{ - "stream error"}); - } - } -} - -//------------------------------------------------------------------------------ - -/* Build a set of tables to decode the provided canonical Huffman code. - The code lengths are lens[0..codes-1]. The result starts at *table, - whose indices are 0..2^bits-1. work is a writable array of at least - lens shorts, which is used as a work area. type is the type of code - to be generated, build::codes, build::lens, or build::dists. On - return, zero is success, -1 is an invalid code, and +1 means that - kEnough isn't enough. table on return points to the next available - entry's address. bits is the requested root table index bits, and - on return it is the actual root table index bits. It will differ if - the request is greater than the longest code or if it is less than - the shortest code. -*/ -template -void -inflate_stream:: -inflate_table( - build type, - std::uint16_t* lens, - std::size_t codes, - code** table, - unsigned *bits, - std::uint16_t* work, - error_code& ec) -{ - unsigned len; // a code's length in bits - unsigned sym; // index of code symbols - unsigned min, max; // minimum and maximum code lengths - unsigned root; // number of index bits for root table - unsigned curr; // number of index bits for current table - unsigned drop; // code bits to drop for sub-table - int left; // number of prefix codes available - unsigned used; // code entries in table used - unsigned huff; // Huffman code - unsigned incr; // for incrementing code, index - unsigned fill; // index for replicating entries - unsigned low; // low bits for current root entry - unsigned mask; // mask for low root bits - code here; // table entry for duplication - code *next; // next available space in table - std::uint16_t const* base; // base value table to use - std::uint16_t const* extra; // extra bits table to use - int end; // use base and extra for symbol > end - std::uint16_t count[15+1]; // number of codes of each length - std::uint16_t offs[15+1]; // offsets in table for each length - - // Length codes 257..285 base - static std::uint16_t constexpr lbase[31] = { - 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, - 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; - - // Length codes 257..285 extra - static std::uint16_t constexpr lext[31] = { - 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, - 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78}; - - // Distance codes 0..29 base - static std::uint16_t constexpr dbase[32] = { - 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, - 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, - 8193, 12289, 16385, 24577, 0, 0}; - - // Distance codes 0..29 extra - static std::uint16_t constexpr dext[32] = { - 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, - 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, - 28, 28, 29, 29, 64, 64}; - - /* - Process a set of code lengths to create a canonical Huffman code. The - code lengths are lens[0..codes-1]. Each length corresponds to the - symbols 0..codes-1. The Huffman code is generated by first sorting the - symbols by length from short to long, and retaining the symbol order - for codes with equal lengths. Then the code starts with all zero bits - for the first code of the shortest length, and the codes are integer - increments for the same length, and zeros are appended as the length - increases. For the deflate format, these bits are stored backwards - from their more natural integer increment ordering, and so when the - decoding tables are built in the large loop below, the integer codes - are incremented backwards. - - This routine assumes, but does not check, that all of the entries in - lens[] are in the range 0..15. The caller must assure this. - 1..15 is interpreted as that code length. zero means that that - symbol does not occur in this code. - - The codes are sorted by computing a count of codes for each length, - creating from that a table of starting indices for each length in the - sorted table, and then entering the symbols in order in the sorted - table. The sorted table is work[], with that space being provided by - the caller. - - The length counts are used for other purposes as well, i.e. finding - the minimum and maximum length codes, determining if there are any - codes at all, checking for a valid set of lengths, and looking ahead - at length counts to determine sub-table sizes when building the - decoding tables. - */ - - /* accumulate lengths for codes (assumes lens[] all in 0..15) */ - for (len = 0; len <= 15; len++) - count[len] = 0; - for (sym = 0; sym < codes; sym++) - count[lens[sym]]++; - - /* bound code lengths, force root to be within code lengths */ - root = *bits; - for (max = 15; max >= 1; max--) - if (count[max] != 0) - break; - if (root > max) - root = max; - if (max == 0) - { /* no symbols to code at all */ - here.op = (std::uint8_t)64; /* invalid code marker */ - here.bits = (std::uint8_t)1; - here.val = (std::uint16_t)0; - *(*table)++ = here; /* make a table to force an error */ - *(*table)++ = here; - *bits = 1; - return; /* no symbols, but wait for decoding to report error */ - } - for (min = 1; min < max; min++) - if (count[min] != 0) - break; - if (root < min) - root = min; - - /* check for an over-subscribed or incomplete set of lengths */ - left = 1; - for (len = 1; len <= 15; len++) - { - left <<= 1; - left -= count[len]; - if (left < 0) - { - ec = error::over_subscribed_length; - return; - } - } - if (left > 0 && (type == build::codes || max != 1)) - { - ec = error::incomplete_length_set; - return; - } - - /* generate offsets into symbol table for each length for sorting */ - offs[1] = 0; - for (len = 1; len < 15; len++) - offs[len + 1] = offs[len] + count[len]; - - /* sort symbols by length, by symbol order within each length */ - for (sym = 0; sym < codes; sym++) - if (lens[sym] != 0) - work[offs[lens[sym]]++] = (std::uint16_t)sym; - - /* - Create and fill in decoding tables. In this loop, the table being - filled is at next and has curr index bits. The code being used is huff - with length len. That code is converted to an index by dropping drop - bits off of the bottom. For codes where len is less than drop + curr, - those top drop + curr - len bits are incremented through all values to - fill the table with replicated entries. - - root is the number of index bits for the root table. When len exceeds - root, sub-tables are created pointed to by the root entry with an index - of the low root bits of huff. This is saved in low to check for when a - new sub-table should be started. drop is zero when the root table is - being filled, and drop is root when sub-tables are being filled. - - When a new sub-table is needed, it is necessary to look ahead in the - code lengths to determine what size sub-table is needed. The length - counts are used for this, and so count[] is decremented as codes are - entered in the tables. - - used keeps track of how many table entries have been allocated from the - provided *table space. It is checked for build::lens and DIST tables against - the constants kEnoughLens and kEnoughDists to guard against changes in - the initial root table size constants. See the comments in inftrees.hpp - for more information. - - sym increments through all symbols, and the loop terminates when - all codes of length max, i.e. all codes, have been processed. This - routine permits incomplete codes, so another loop after this one fills - in the rest of the decoding tables with invalid code markers. - */ - - /* set up for code type */ - switch (type) - { - case build::codes: - base = extra = work; /* dummy value--not used */ - end = 19; - break; - case build::lens: - base = lbase; - base -= 257; - extra = lext; - extra -= 257; - end = 256; - break; - default: /* build::dists */ - base = dbase; - extra = dext; - end = -1; - } - - /* initialize state for loop */ - huff = 0; /* starting code */ - sym = 0; /* starting code symbol */ - len = min; /* starting code length */ - next = *table; /* current table to fill in */ - curr = root; /* current table index bits */ - drop = 0; /* current bits to drop from code for index */ - low = (unsigned)(-1); /* trigger new sub-table when len > root */ - used = 1U << root; /* use root table entries */ - mask = used - 1; /* mask for comparing low */ - - auto const not_enough = [] - { - BOOST_THROW_EXCEPTION(std::logic_error{ - "insufficient output size when inflating tables"}); - }; - - // check available table space - if ((type == build::lens && used > kEnoughLens) || - (type == build::dists && used > kEnoughDists)) - return not_enough(); - - /* process all codes and make table entries */ - for (;;) - { - /* create table entry */ - here.bits = (std::uint8_t)(len - drop); - if ((int)(work[sym]) < end) - { - here.op = (std::uint8_t)0; - here.val = work[sym]; - } - else if ((int)(work[sym]) > end) - { - here.op = (std::uint8_t)(extra[work[sym]]); - here.val = base[work[sym]]; - } - else - { - here.op = (std::uint8_t)(32 + 64); /* end of block */ - here.val = 0; - } - - /* replicate for those indices with low len bits equal to huff */ - incr = 1U << (len - drop); - fill = 1U << curr; - min = fill; /* save offset to next table */ - do - { - fill -= incr; - next[(huff >> drop) + fill] = here; - } while (fill != 0); - - /* backwards increment the len-bit code huff */ - incr = 1U << (len - 1); - while (huff & incr) - incr >>= 1; - if (incr != 0) - { - huff &= incr - 1; - huff += incr; - } - else - huff = 0; - - /* go to next symbol, update count, len */ - sym++; - if (--(count[len]) == 0) - { - if (len == max) break; - len = lens[work[sym]]; - } - - /* create new sub-table if needed */ - if (len > root && (huff & mask) != low) - { - /* if first time, transition to sub-tables */ - if (drop == 0) - drop = root; - - /* increment past last table */ - next += min; /* here min is 1 << curr */ - - /* determine length of next table */ - curr = len - drop; - left = (int)(1 << curr); - while (curr + drop < max) - { - left -= count[curr + drop]; - if (left <= 0) break; - curr++; - left <<= 1; - } - - /* check for enough space */ - used += 1U << curr; - if ((type == build::lens && used > kEnoughLens) || - (type == build::dists && used > kEnoughDists)) - return not_enough(); - - /* point entry in root table to sub-table */ - low = huff & mask; - (*table)[low].op = (std::uint8_t)curr; - (*table)[low].bits = (std::uint8_t)root; - (*table)[low].val = (std::uint16_t)(next - *table); - } - } - - /* fill in remaining table entry if code is incomplete (guaranteed to have - at most one remaining entry, since if the code is incomplete, the - maximum code length that was allowed to get this far is one bit) */ - if (huff != 0) - { - here.op = 64; // invalid code marker - here.bits = (std::uint8_t)(len - drop); - here.val = 0; - next[huff] = here; - } - - *table += used; - *bits = root; -} - -template -auto -inflate_stream:: -get_fixed_tables() -> - codes const& -{ - struct fixed_codes : codes - { - code len_[512]; - code dist_[32]; - - fixed_codes() - { - lencode = len_; - lenbits = 9; - distcode = dist_; - distbits = 5; - - std::uint16_t lens[320]; - std::uint16_t work[288]; - - std::fill(&lens[ 0], &lens[144], std::uint16_t{8}); - std::fill(&lens[144], &lens[256], std::uint16_t{9}); - std::fill(&lens[256], &lens[280], std::uint16_t{7}); - std::fill(&lens[280], &lens[288], std::uint16_t{8}); - - { - error_code ec; - auto next = &len_[0]; - inflate_table(build::lens, - lens, 288, &next, &lenbits, work, ec); - if(ec) - BOOST_THROW_EXCEPTION(std::logic_error{ec.message()}); - } - - // VFALCO These fixups are from ZLib - len_[ 99].op = 64; - len_[227].op = 64; - len_[355].op = 64; - len_[483].op = 64; - - { - error_code ec; - auto next = &dist_[0]; - std::fill(&lens[0], &lens[32], std::uint16_t{5}); - inflate_table(build::dists, - lens, 32, &next, &distbits, work, ec); - if(ec) - BOOST_THROW_EXCEPTION(std::logic_error{ec.message()}); - } - } - }; - - static fixed_codes const fc; - return fc; -} - -template -void -inflate_stream:: -fixedTables() -{ - auto const fc = get_fixed_tables(); - lencode_ = fc.lencode; - lenbits_ = fc.lenbits; - distcode_ = fc.distcode; - distbits_ = fc.distbits; -} - -/* - Decode literal, length, and distance codes and write out the resulting - literal and match bytes until either not enough input or output is - available, an end-of-block is encountered, or a data error is encountered. - When large enough input and output buffers are supplied to inflate(), for - example, a 16K input buffer and a 64K output buffer, more than 95% of the - inflate execution time is spent in this routine. - - Entry assumptions: - - state->mode_ == LEN - zs.avail_in >= 6 - zs.avail_out >= 258 - start >= zs.avail_out - state->bits_ < 8 - - On return, state->mode_ is one of: - - LEN -- ran out of enough output space or enough available input - TYPE -- reached end of block code, inflate() to interpret next block - BAD -- error in block data - - Notes: - - - The maximum input bits used by a length/distance pair is 15 bits for the - length code, 5 bits for the length extra, 15 bits for the distance code, - and 13 bits for the distance extra. This totals 48 bits, or six bytes. - Therefore if zs.avail_in >= 6, then there is enough input to avoid - checking for available input while decoding. - - - The maximum bytes that a single length/distance pair can output is 258 - bytes, which is the maximum length that can be coded. inflate_fast() - requires zs.avail_out >= 258 for each loop to avoid checking for - output space. - - inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe): - - Using bit fields for code structure - - Different op definition to avoid & for extra bits (do & for table bits) - - Three separate decoding do-loops for direct, window, and wnext == 0 - - Special case for distance > 1 copies to do overlapped load and store copy - - Explicit branch predictions (based on measured branch probabilities) - - Deferring match copy and interspersed it with decoding subsequent codes - - Swapping literal/length else - - Swapping window/direct else - - Larger unrolled copy loops (three is about right) - - Moving len -= 3 statement into middle of loop - */ -template -void -inflate_stream:: -inflate_fast(ranges& r, error_code& ec) -{ - unsigned char const* last; // have enough input while in < last - unsigned char *end; // while out < end, enough space available - std::size_t op; // code bits, operation, extra bits, or window position, window bytes to copy - unsigned len; // match length, unused bytes - unsigned dist; // match distance - unsigned const lmask = - (1U << lenbits_) - 1; // mask for first level of length codes - unsigned const dmask = - (1U << distbits_) - 1; // mask for first level of distance codes - - last = r.in.next + (r.in.avail() - 5); - end = r.out.next + (r.out.avail() - 257); - - /* decode literals and length/distances until end-of-block or not enough - input data or output space */ - do - { - if(bi_.size() < 15) - bi_.fill_16(r.in.next); - auto cp = &lencode_[bi_.peek_fast() & lmask]; - dolen: - bi_.drop(cp->bits); - op = (unsigned)(cp->op); - if(op == 0) - { - // literal - *r.out.next++ = (unsigned char)(cp->val); - } - else if(op & 16) - { - // length base - len = (unsigned)(cp->val); - op &= 15; // number of extra bits - if(op) - { - if(bi_.size() < op) - bi_.fill_8(r.in.next); - len += (unsigned)bi_.peek_fast() & ((1U << op) - 1); - bi_.drop(op); - } - if(bi_.size() < 15) - bi_.fill_16(r.in.next); - cp = &distcode_[bi_.peek_fast() & dmask]; - dodist: - bi_.drop(cp->bits); - op = (unsigned)(cp->op); - if(op & 16) - { - // distance base - dist = (unsigned)(cp->val); - op &= 15; // number of extra bits - if(bi_.size() < op) - { - bi_.fill_8(r.in.next); - if(bi_.size() < op) - bi_.fill_8(r.in.next); - } - dist += (unsigned)bi_.peek_fast() & ((1U << op) - 1); -#ifdef INFLATE_STRICT - if(dist > dmax_) - { - ec = error::invalid_distance; - mode_ = BAD; - break; - } -#endif - bi_.drop(op); - - op = r.out.used(); - if(dist > op) - { - // copy from window - op = dist - op; // distance back in window - if(op > w_.size()) - { - ec = error::invalid_distance; - mode_ = BAD; - break; - } - auto const n = clamp(len, op); - w_.read(r.out.next, op, n); - r.out.next += n; - len -= n; - } - if(len > 0) - { - // copy from output - auto in = r.out.next - dist; - auto n = clamp(len, r.out.avail()); - len -= n; - while(n--) - *r.out.next++ = *in++; - } - } - else if((op & 64) == 0) - { - // 2nd level distance code - cp = &distcode_[cp->val + (bi_.peek_fast() & ((1U << op) - 1))]; - goto dodist; - } - else - { - ec = error::invalid_distance_code; - mode_ = BAD; - break; - } - } - else if((op & 64) == 0) - { - // 2nd level length code - cp = &lencode_[cp->val + (bi_.peek_fast() & ((1U << op) - 1))]; - goto dolen; - } - else if(op & 32) - { - // end-of-block - mode_ = TYPE; - break; - } - else - { - ec = error::invalid_literal_length; - mode_ = BAD; - break; - } - } - while(r.in.next < last && r.out.next < end); - - // return unused bytes (on entry, bits < 8, so in won't go too far back) - bi_.rewind(r.in.next); -} - -} // detail -} // zlib -} // beast - -#endif diff --git a/src/beast/include/beast/zlib/detail/ranges.hpp b/src/beast/include/beast/zlib/detail/ranges.hpp deleted file mode 100644 index 094bd45638b..00000000000 --- a/src/beast/include/beast/zlib/detail/ranges.hpp +++ /dev/null @@ -1,100 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// -// This is a derivative work based on Zlib, copyright below: -/* - Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Jean-loup Gailly Mark Adler - jloup@gzip.org madler@alumni.caltech.edu - - The data format used by the zlib library is described by RFCs (Request for - Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 - (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). -*/ - -#ifndef BEAST_ZLIB_DETAIL_RANGES_HPP -#define BEAST_ZLIB_DETAIL_RANGES_HPP - -#include -#include - -namespace beast { -namespace zlib { -namespace detail { - -struct ranges -{ - template - struct range - { - using iter_t = - typename std::conditional::type; - - iter_t first; - iter_t last; - iter_t next; - - // total bytes in range - std::size_t - size() const - { - return last - first; - } - - // bytes consumed - std::size_t - used() const - { - return next - first; - } - - // bytes remaining - std::size_t - avail() const - { - return last - next; - } - }; - - range in; - range out; -}; - -// Clamp u to v where u and v are different types -template -inline -U -clamp(U u, V v) -{ - if(u > v) - u = static_cast(v); - return u; -} - -} // detail -} // zlib -} // beast - -#endif diff --git a/src/beast/include/beast/zlib/detail/window.hpp b/src/beast/include/beast/zlib/detail/window.hpp deleted file mode 100644 index a671b2342f3..00000000000 --- a/src/beast/include/beast/zlib/detail/window.hpp +++ /dev/null @@ -1,163 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// -// This is a derivative work based on Zlib, copyright below: -/* - Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Jean-loup Gailly Mark Adler - jloup@gzip.org madler@alumni.caltech.edu - - The data format used by the zlib library is described by RFCs (Request for - Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 - (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). -*/ - -#ifndef BEAST_ZLIB_DETAIL_WINDOW_HPP -#define BEAST_ZLIB_DETAIL_WINDOW_HPP - -#include -#include -#include -#include -#include - -namespace beast { -namespace zlib { -namespace detail { - -class window -{ - std::unique_ptr p_; - std::uint16_t i_ = 0; - std::uint16_t size_ = 0; - std::uint16_t capacity_ = 0; - std::uint8_t bits_ = 0; - -public: - int - bits() const - { - return bits_; - } - - unsigned - capacity() const - { - return capacity_; - } - - unsigned - size() const - { - return size_; - } - - void - reset(int bits); - - void - read(std::uint8_t* out, std::size_t pos, std::size_t n); - - template - void - write(std::uint8_t const* in, std::size_t n); -}; - -inline -void -window:: -reset(int bits) -{ - if(bits_ != bits) - { - p_.reset(); - bits_ = static_cast(bits); - capacity_ = 1U << bits_; - } - i_ = 0; - size_ = 0; -} - -inline -void -window:: -read(std::uint8_t* out, std::size_t pos, std::size_t n) -{ - if(i_ >= size_) - { - // window is contiguous - std::memcpy(out, &p_[i_ - pos], n); - return; - } - auto i = ((i_ - pos) + capacity_) % capacity_; - auto m = capacity_ - i; - if(n <= m) - { - std::memcpy(out, &p_[i], n); - return; - } - std::memcpy(out, &p_[i], m); - out += m; - std::memcpy(out, &p_[0], n - m); -} - -template -void -window:: -write(std::uint8_t const* in, std::size_t n) -{ - if(! p_) - p_ = boost::make_unique< - std::uint8_t[]>(capacity_); - if(n >= capacity_) - { - i_ = 0; - size_ = capacity_; - std::memcpy(&p_[0], in + (n - size_), size_); - return; - } - if(i_ + n <= capacity_) - { - std::memcpy(&p_[i_], in, n); - if(size_ >= capacity_ - n) - size_ = capacity_; - else - size_ = static_cast(size_ + n); - - i_ = static_cast( - (i_ + n) % capacity_); - return; - } - auto m = capacity_ - i_; - std::memcpy(&p_[i_], in, m); - in += m; - i_ = static_cast(n - m); - std::memcpy(&p_[0], in, i_); - size_ = capacity_; -} - -} // detail -} // zlib -} // beast - -#endif diff --git a/src/beast/include/beast/zlib/error.hpp b/src/beast/include/beast/zlib/error.hpp deleted file mode 100644 index 7ab179536d3..00000000000 --- a/src/beast/include/beast/zlib/error.hpp +++ /dev/null @@ -1,135 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_ZLIB_ERROR_HPP -#define BEAST_ZLIB_ERROR_HPP - -#include -#include - -namespace beast { -namespace zlib { - -// This is a derivative work based on Zlib, copyright below: -/* - Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Jean-loup Gailly Mark Adler - jloup@gzip.org madler@alumni.caltech.edu - - The data format used by the zlib library is described by RFCs (Request for - Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 - (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). -*/ - -/** Error codes returned by the codec. -*/ -enum class error -{ - /** Additional buffers are required. - - This error indicates that one or both of the buffers - provided buffers do not have sufficient available bytes - to make forward progress. - - This does not always indicate a failure condition. - - @note This is the same as `Z_BUF_ERROR` returned by ZLib. - */ - need_buffers = 1, - - /** End of stream reached. - - @note This is the same as `Z_STREAM_END` returned by ZLib. - */ - end_of_stream, - - /** Invalid stream or parameters. - - This error is returned when invalid parameters are passed, - or the operation being performed is not consistent with the - state of the stream. For example, attempting to write data - when the end of stream is already reached. - - @note This is the same as `Z_STREAM_ERROR` returned by ZLib. - */ - stream_error, - - // - // Errors generated by basic_deflate_stream - // - - // - // Errors generated by basic_inflate_stream - // - - /// Invalid block type - invalid_block_type, - - /// Invalid stored block length - invalid_stored_length, - - /// Too many length or distance symbols - too_many_symbols, - - /// Invalid code lengths - invalid_code_lenths, - - /// Invalid bit length repeat - invalid_bit_length_repeat, - - /// Missing end of block code - missing_eob, - - /// Invalid literal/length code - invalid_literal_length, - - /// Invalid distance code - invalid_distance_code, - - /// Invalid distance too far back - invalid_distance, - - // - // Errors generated by inflate_table - // - - /// Over-subscribed length code - over_subscribed_length, - - /// Incomplete length set - incomplete_length_set, - - - - /// general error - general -}; - -} // zlib -} // beast - -#include - -#endif - diff --git a/src/beast/include/beast/zlib/impl/error.ipp b/src/beast/include/beast/zlib/impl/error.ipp deleted file mode 100644 index 50b28423d26..00000000000 --- a/src/beast/include/beast/zlib/impl/error.ipp +++ /dev/null @@ -1,137 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// -// This is a derivative work based on Zlib, copyright below: -/* - Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Jean-loup Gailly Mark Adler - jloup@gzip.org madler@alumni.caltech.edu - - The data format used by the zlib library is described by RFCs (Request for - Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 - (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). -*/ - -#ifndef BEAST_ZLIB_IMPL_ERROR_IPP -#define BEAST_ZLIB_IMPL_ERROR_IPP - -#include -#include - -namespace boost { -namespace system { -template<> -struct is_error_code_enum -{ - static bool const value = true; -}; -} // system -} // boost - -namespace beast { -namespace zlib { -namespace detail { - -class zlib_error_category : public error_category -{ -public: - const char* - name() const noexcept override - { - return "beast.zlib"; - } - - std::string - message(int ev) const override - { - switch(static_cast(ev)) - { - case error::need_buffers: return "need buffers"; - case error::end_of_stream: return "end of stream"; - case error::stream_error: return "stream error"; - - case error::invalid_block_type: return "invalid block type"; - case error::invalid_stored_length: return "invalid stored block length"; - case error::too_many_symbols: return "too many symbols"; - case error::invalid_code_lenths: return "invalid code lengths"; - case error::invalid_bit_length_repeat: return "invalid bit length repeat"; - case error::missing_eob: return "missing end of block code"; - case error::invalid_literal_length: return "invalid literal/length code"; - case error::invalid_distance_code: return "invalid distance code"; - case error::invalid_distance: return "invalid distance"; - - case error::over_subscribed_length: return "over-subscribed length"; - case error::incomplete_length_set: return "incomplete length set"; - - case error::general: - default: - return "beast.zlib error"; - } - } - - error_condition - default_error_condition(int ev) const noexcept override - { - return error_condition{ev, *this}; - } - - bool - equivalent(int ev, - error_condition const& condition - ) const noexcept override - { - return condition.value() == ev && - &condition.category() == this; - } - - bool - equivalent(error_code const& error, int ev) const noexcept override - { - return error.value() == ev && - &error.category() == this; - } -}; - -inline -error_category const& -get_error_category() -{ - static zlib_error_category const cat{}; - return cat; -} - -} // detail - -inline -error_code -make_error_code(error ev) -{ - return error_code{ - static_cast::type>(ev), - detail::get_error_category()}; -} - -} // zlib -} // beast - -#endif diff --git a/src/beast/include/beast/zlib/inflate_stream.hpp b/src/beast/include/beast/zlib/inflate_stream.hpp deleted file mode 100644 index dd4df6bb7e7..00000000000 --- a/src/beast/include/beast/zlib/inflate_stream.hpp +++ /dev/null @@ -1,216 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_ZLIB_INFLATE_STREAM_HPP -#define BEAST_ZLIB_INFLATE_STREAM_HPP - -#include -#include - -// This is a derivative work based on Zlib, copyright below: -/* - Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Jean-loup Gailly Mark Adler - jloup@gzip.org madler@alumni.caltech.edu - - The data format used by the zlib library is described by RFCs (Request for - Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 - (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). -*/ - -namespace beast { -namespace zlib { - -/** Raw deflate stream decompressor. - - This implements a raw deflate stream decompressor. The deflate - protocol is a compression protocol described in - "DEFLATE Compressed Data Format Specification version 1.3" - located here: https://tools.ietf.org/html/rfc1951 - - The implementation is a refactored port to C++ of ZLib's "inflate". - A more detailed description of ZLib is at http://zlib.net/. - - Compression can be done in a single step if the buffers are large - enough (for example if an input file is memory mapped), or can be done - by repeated calls of the compression function. In the latter case, the - application must provide more input and/or consume the output (providing - more output space) before each call. -*/ -class inflate_stream - : private detail::inflate_stream -{ -public: - /** Construct a raw deflate decompression stream. - - The window size is set to the default of 15 bits. - */ - inflate_stream() = default; - - /** Reset the stream. - - This puts the stream in a newly constructed state with - the previously specified window size, but without de-allocating - any dynamically created structures. - */ - void - reset() - { - doReset(); - } - - /** Reset the stream. - - This puts the stream in a newly constructed state with the - specified window size, but without de-allocating any dynamically - created structures. - */ - void - reset(int windowBits) - { - doReset(windowBits); - } - - /** Put the stream in a newly constructed state. - - All dynamically allocated memory is de-allocated. - */ - void - clear() - { - doClear(); - } - - /** Decompress input and produce output. - - This function decompresses as much data as possible, and stops when - the input buffer becomes empty or the output buffer becomes full. It - may introduce some output latency (reading input without producing any - output) except when forced to flush. - - One or both of the following actions are performed: - - @li Decompress more input starting at `zs.next_in` and update `zs.next_in` - and `zs.avail_in` accordingly. If not all input can be processed (because - there is not enough room in the output buffer), `zs.next_in` is updated - and processing will resume at this point for the next call. - - @li Provide more output starting at `zs.next_out` and update `zs.next_out` - and `zs.avail_out` accordingly. `write` provides as much output as - possible, until there is no more input data or no more space in the output - buffer (see below about the flush parameter). - - Before the call, the application should ensure that at least one of the - actions is possible, by providing more input and/or consuming more output, - and updating the values in `zs` accordingly. The application can consume - the uncompressed output when it wants, for example when the output buffer - is full (`zs.avail_out == 0`), or after each call. If `write` returns no - error and with zero `zs.avail_out`, it must be called again after making - room in the output buffer because there might be more output pending. - - The flush parameter may be `Flush::none`, `Flush::sync`, `Flush::finish`, - `Flush::block`, or `Flush::trees`. `Flush::sync` requests to flush as much - output as possible to the output buffer. `Flush::block` requests to stop if - and when it gets to the next deflate block boundary. When decoding the - zlib or gzip format, this will cause `write` to return immediately after - the header and before the first block. When doing a raw inflate, `write` will - go ahead and process the first block, and will return when it gets to the - end of that block, or when it runs out of data. - - The `Flush::block` option assists in appending to or combining deflate - streams. Also to assist in this, on return `write` will set `zs.data_type` - to the number of unused bits in the last byte taken from `zs.next_in`, plus - 64 if `write` is currently decoding the last block in the deflate stream, - plus 128 if `write` returned immediately after decoding an end-of-block code - or decoding the complete header up to just before the first byte of the - deflate stream. The end-of-block will not be indicated until all of the - uncompressed data from that block has been written to `zs.next_out`. The - number of unused bits may in general be greater than seven, except when - bit 7 of `zs.data_type` is set, in which case the number of unused bits - will be less than eight. `zs.data_type` is set as noted here every time - `write` returns for all flush options, and so can be used to determine the - amount of currently consumed input in bits. - - The `Flush::trees` option behaves as `Flush::block` does, but it also returns - when the end of each deflate block header is reached, before any actual data - in that block is decoded. This allows the caller to determine the length of - the deflate block header for later use in random access within a deflate block. - 256 is added to the value of `zs.data_type` when `write` returns immediately - after reaching the end of the deflate block header. - - `write` should normally be called until it returns `error::end_of_stream` or - another error. However if all decompression is to be performed in a single - step (a single call of `write`), the parameter flush should be set to - `Flush::finish`. In this case all pending input is processed and all pending - output is flushed; `zs.avail_out` must be large enough to hold all of the - uncompressed data for the operation to complete. (The size of the uncompressed - data may have been saved by the compressor for this purpose.) The use of - `Flush::finish` is not required to perform an inflation in one step. However - it may be used to inform inflate that a faster approach can be used for the - single call. `Flush::finish` also informs inflate to not maintain a sliding - window if the stream completes, which reduces inflate's memory footprint. - If the stream does not complete, either because not all of the stream is - provided or not enough output space is provided, then a sliding window will be - allocated and `write` can be called again to continue the operation as if - `Flush::none` had been used. - - In this implementation, `write` always flushes as much output as possible to - the output buffer, and always uses the faster approach on the first call. So - the effects of the flush parameter in this implementation are on the return value - of `write` as noted below, when `write` returns early when `Flush::block` or - `Flush::trees` is used, and when `write` avoids the allocation of memory for a - sliding window when `Flush::finsih` is used. - - If a preset dictionary is needed after this call, - `write` sets `zs.adler` to the Adler-32 checksum of the dictionary chosen by - the compressor and returns `error::need_dictionary`; otherwise it sets - `zs.adler` to the Adler-32 checksum of all output produced so far (that is, - `zs.total_out bytes`) and returns no error, `error::end_of_stream`, or an - error code as described below. At the end of the stream, `write` checks that - its computed adler32 checksum is equal to that saved by the compressor and - returns `error::end_of_stream` only if the checksum is correct. - - This function returns no error if some progress has been made (more input - processed or more output produced), `error::end_of_stream` if the end of the - compressed data has been reached and all uncompressed output has been produced, - `error::need_dictionary` if a preset dictionary is needed at this point, - `error::invalid_data` if the input data was corrupted (input stream not - conforming to the zlib format or incorrect check value), `error::stream_error` - if the stream structure was inconsistent (for example if `zs.next_in` or - `zs.next_out` was null), `error::need_buffers` if no progress is possible or - if there was not enough room in the output buffer when `Flush::finish` is - used. Note that `error::need_buffers` is not fatal, and `write` can be called - again with more input and more output space to continue decompressing. - */ - void - write(z_params& zs, Flush flush, error_code& ec) - { - doWrite(zs, flush, ec); - } -}; - -} // zlib -} // beast - -#endif diff --git a/src/beast/include/beast/zlib/zlib.hpp b/src/beast/include/beast/zlib/zlib.hpp deleted file mode 100644 index 217bb191ce0..00000000000 --- a/src/beast/include/beast/zlib/zlib.hpp +++ /dev/null @@ -1,180 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_ZLIB_ZLIB_HPP -#define BEAST_ZLIB_ZLIB_HPP - -#include -#include -#include - -// This is a derivative work based on Zlib, copyright below: -/* - Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Jean-loup Gailly Mark Adler - jloup@gzip.org madler@alumni.caltech.edu - - The data format used by the zlib library is described by RFCs (Request for - Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 - (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). -*/ - -namespace beast { -namespace zlib { - -#if !defined(__MACTYPES__) -typedef unsigned char Byte; /* 8 bits */ -#endif -typedef unsigned int uInt; /* 16 bits or more */ - -/* Possible values of the data_type field (though see inflate()) */ -enum z_Type -{ - Z_BINARY = 0, - Z_TEXT = 1, - Z_UNKNOWN = 2 -}; - -/** Deflate codec parameters. - - Objects of this type are filled in by callers and provided to the - deflate codec to define the input and output areas for the next - compress or decompress operation. - - The application must update next_in and avail_in when avail_in has dropped - to zero. It must update next_out and avail_out when avail_out has dropped - to zero. The application must initialize zalloc, zfree and opaque before - calling the init function. All other fields are set by the compression - library and must not be updated by the application. - - The fields total_in and total_out can be used for statistics or progress - reports. After compression, total_in holds the total size of the - uncompressed data and may be saved for use in the decompressor (particularly - if the decompressor wants to decompress everything in a single step). -*/ -struct z_params -{ - /** A pointer to the next input byte. - - If there is no more input, this may be set to `nullptr`. - */ - void const* next_in; - - /** The number of bytes of input available at `next_in`. - - If there is no more input, this should be set to zero. - */ - std::size_t avail_in; - - /** The total number of input bytes read so far. - */ - std::size_t total_in = 0; - - /** A pointer to the next output byte. - */ - void* next_out; - - /** The remaining bytes of space at `next_out`. - */ - std::size_t avail_out; - - /** The total number of bytes output so far. - */ - std::size_t total_out = 0; - - int data_type = Z_UNKNOWN; // best guess about the data type: binary or text -}; - -/** Flush option. -*/ -enum class Flush -{ - // order matters - - none, - block, - partial, - sync, - full, - finish, - trees -}; - -/* compression levels */ -enum z_Compression -{ - Z_NO_COMPRESSION = 0, - Z_BEST_SPEED = 1, - Z_BEST_COMPRESSION = 9, - Z_DEFAULT_COMPRESSION = -1 -}; - -/** Compression strategy. - - These are used when compressing streams. -*/ -enum class Strategy -{ - /** Default strategy. - - This is suitable for general purpose compression, and works - well in the majority of cases. - */ - normal, - - /** Filtered strategy. - - This strategy should be used when the data be compressed - is produced by a filter or predictor. - */ - filtered, - - /** Huffman-only strategy. - - This strategy only performs Huffman encoding, without doing - any string matching. - */ - huffman, - - /** Run Length Encoding strategy. - - This strategy limits match distances to one, making it - equivalent to run length encoding. This can give better - performance for things like PNG image data. - */ - rle, - - /** Fixed table strategy. - - This strategy prevents the use of dynamic Huffman codes, - allowing for a simpler decoder for special applications. - */ - fixed -}; - -} // zlib -} // beast - -#endif - diff --git a/src/beast/index.html b/src/beast/index.html deleted file mode 100644 index 97143c8d8da..00000000000 --- a/src/beast/index.html +++ /dev/null @@ -1,20 +0,0 @@ - - - - - -Automatic redirection failed, please go to -doc/html/index.html -
- -Boost.Beast
-
-Copyright (C) 2013-2016 Vinnie Falco
-
-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)
-
-
- - diff --git a/src/beast/scripts/blacklist.supp b/src/beast/scripts/blacklist.supp deleted file mode 100644 index 09bc1abed2b..00000000000 --- a/src/beast/scripts/blacklist.supp +++ /dev/null @@ -1,29 +0,0 @@ -# Remember that this blacklist file is GLOBAL to all sanitizers -# Be therefore extremely careful when considering to add a sanitizer -# filter here instead of using a runtime suppression -# -# Remember also that filters here quite literally completely -# remove instrumentation altogether, so filtering here means -# that sanitizers such as tsan will false positive on problems -# introduced by code filtered here. -# -# The main use for this file is ubsan, as it's the only sanitizer -# without a runtime suppression facility. -# -# Be ESPECIALLY careful when filtering out entire source files! -# Try if at all possible to filter only functions using fun:regex -# Remember you must use mangled symbol names with fun:regex - -# boost/lexical_cast.hpp:1625:43: runtime error: downcast of address 0x7fbb4fffbce8 which does not point to an object of type 'buffer_t' (aka 'parser_buf >, char>') -# Fixed in Boost 1.63.0 https://svn.boost.org/trac/boost/ticket/12889 -# -fun:*shl_input_streamable* - -## The well known ubsan failure in libstdc++ extant for years :) -# Line 96:24: runtime error: load of value 4294967221, which is not a valid value for type 'std::_Ios_Fmtflags' -# -#fun:*_Ios_Fmtflags* - -# boost/any.hpp:259:16: runtime error: downcast of address 0x000004392e70 which does not point to an object of type 'any::holder' -# -#fun:*any_cast* diff --git a/src/beast/scripts/build-and-test.sh b/src/beast/scripts/build-and-test.sh deleted file mode 100755 index c09f13d0376..00000000000 --- a/src/beast/scripts/build-and-test.sh +++ /dev/null @@ -1,174 +0,0 @@ -#!/usr/bin/env bash -# We use set -e to bail on first non zero exit code of any processes launched -# and -x to exit upon any unbound variable. -x will output command lines used -# (with variable expansion) -set -eux - -# brew install bash (4) to get this working on OSX! -shopt -s globstar - -################################## ENVIRONMENT ################################# - -DO_VALGRIND=${DO_VALGRIND:-false} - -# If not CI, then set some defaults -if [[ "${CI:-}" == "" ]]; then - TRAVIS_BRANCH=${TRAVIS_BRANCH:-feature} - CC=${CC:-gcc} - ADDRESS_MODEL=${ADDRESS_MODEL:-64} - VARIANT=${VARIANT:-debug} - # If running locally we assume we have lcov/valgrind on PATH -else - export PATH=$VALGRIND_ROOT/bin:$LCOV_ROOT/usr/bin:$PATH -fi - -MAIN_BRANCH="0" -# For builds not triggered by a pull request TRAVIS_BRANCH is the name of the -# branch currently being built; whereas for builds triggered by a pull request -# it is the name of the branch targeted by the pull request (in many cases this -# will be master). -if [[ $TRAVIS_BRANCH == "master" || $TRAVIS_BRANCH == "develop" ]]; then - MAIN_BRANCH="1" -fi - -num_jobs="1" -if [[ $(uname) == "Darwin" ]]; then - num_jobs=$(sysctl -n hw.physicalcpu) -elif [[ $(uname -s) == "Linux" ]]; then - # CircleCI returns 32 phys procs, but 2 virt proc - num_proc_units=$(nproc) - # Physical cores - num_jobs=$(lscpu -p | grep -v '^#' | sort -u -t, -k 2,4 | wc -l) - if ((${num_proc_units} < ${num_jobs})); then - num_jobs=$num_proc_units - fi - if [[ "${TRAVIS}" == "true" && ${NUM_PROCESSORS:=2} > ${num_jobs} ]]; then - num_jobs=$NUM_PROCESSORS - fi - #if [[ "$TRAVIS" == "true" ]] && (( "$num_jobs" > 1)); then - # num_jobs=$((num_jobs - 1)) - #fi -fi - -echo "using toolset: $CC" -echo "using variant: $VARIANT" -echo "using address-model: $ADDRESS_MODEL" -echo "using PATH: $PATH" -echo "using MAIN_BRANCH: $MAIN_BRANCH" -echo "using BOOST_ROOT: $BOOST_ROOT" - -#################################### HELPERS ################################### - -function run_tests_with_debugger { - for x in bin/**/$VARIANT/**/*-tests; do - scripts/run-with-debugger.sh "$x" - done -} - -function run_tests { - for x in bin/**/$VARIANT/**/*-tests; do - $x - done -} - -function run_tests_with_valgrind { - for x in bin/**/$VARIANT/**/*-tests; do - if [[ $(basename $x) == "bench-tests" ]]; then - $x - else - # TODO --max-stackframe=8388608 - # see: https://travis-ci.org/vinniefalco/Beast/jobs/132486245 - valgrind --suppressions=./scripts/valgrind.supp --error-exitcode=1 "$x" - fi - done -} - -function build_beast { - $BOOST_ROOT/bjam toolset=$CC \ - variant=$VARIANT \ - address-model=$ADDRESS_MODEL \ - -j${num_jobs} -} - -function build_beast_cmake { - mkdir -p build - pushd build > /dev/null - cmake -DVARIANT=${VARIANT} .. - make -j${num_jobs} - mkdir -p ../bin/$VARIANT - find . -executable -type f -exec cp {} ../bin/$VARIANT/. \; - popd > /dev/null -} - -function run_autobahn_test_suite { - # Run autobahn tests - wsecho=$(find bin -name "websocket-echo" | grep /$VARIANT/) - nohup $wsecho& - - # We need to wait a while so wstest can connect! - sleep 5 - # Show the output (if any) as it is generated - tail -f nohup.out & - cd scripts && wstest -m fuzzingclient - cd .. - rm nohup.out - # Show what jobs are running - jobs - # Wait a while for things to wind down before issuing a kill - sleep 5 - # Kill it gracefully - kill -INT %1 - kill -INT %2 - # Wait for all the jobs to finish - wait - # Parse the test results, with python>=2.5<3 script - python scripts/parseautobahn.py scripts/autoresults/index.json -} - -##################################### BUILD #################################### - -if [[ ${BUILD_SYSTEM:-} == cmake ]]; then - build_beast_cmake -else - build_beast -fi - -##################################### TESTS #################################### - -if [[ $VARIANT == "coverage" ]]; then - find . -name "*.gcda" | xargs rm -f - rm *.info -f - # Create baseline coverage data file - lcov --no-external -c -i -d . -o baseline.info > /dev/null - - # Perform test - if [[ $MAIN_BRANCH == "1" && "$DO_VALGRIND" = true ]]; then - run_tests_with_valgrind - # skip slow autobahn tests - #run_autobahn_test_suite - else - echo "skipping autobahn/valgrind tests for feature branch build" - run_tests - fi - - # Create test coverage data file - lcov --no-external -c -d . -o testrun.info > /dev/null - - # Combine baseline and test coverage data - lcov -a baseline.info -a testrun.info -o lcov-all.info > /dev/null - - # Extract only include/beast, and don\'t report on examples/test - lcov -e "lcov-all.info" "$PWD/include/beast/*" -o lcov.info > /dev/null - - ~/.local/bin/codecov -X gcov - #cat lcov.info | node_modules/.bin/coveralls - - # Clean up these stragglers so BOOST_ROOT cache is clean - find $BOOST_ROOT/bin.v2 -name "*.gcda" | xargs rm -f -else - if [[ $MAIN_BRANCH == "1" && "$DO_VALGRIND" = true ]]; then - run_tests_with_valgrind - else - run_tests_with_debugger - fi -fi diff --git a/src/beast/scripts/field.txt b/src/beast/scripts/field.txt deleted file mode 100644 index 9f15ab16c76..00000000000 --- a/src/beast/scripts/field.txt +++ /dev/null @@ -1,351 +0,0 @@ -Accept -Accept-Additions -Accept-Charset -Accept-Datetime -Accept-Encoding -Accept-Features -Accept-Language -Accept-Patch -Accept-Post -Accept-Ranges -Access-Control -Access-Control-Allow-Credentials -Access-Control-Allow-Headers -Access-Control-Allow-Methods -Access-Control-Allow-Origin -Access-Control-Max-Age -Access-Control-Request-Headers -Access-Control-Request-Method -Age -A-IM -Allow -ALPN -Also-Control -Alternate-Recipient -Alternates -Alt-Svc -Alt-Used -Apparently-To -Apply-To-Redirect-Ref -Approved -Archive -Archived-At -Article-Names -Article-Updates -Authentication-Control -Authentication-Info -Authentication-Results -Authorization -Autoforwarded -Autosubmitted -Auto-Submitted -Base -Bcc -Body -Cache-Control -CalDAV-Timezones -Cancel-Key -Cancel-Lock -Cc -C-Ext -Close -C-Man -Comments -Compliance -Connection -Content-Alternative -Content-Base -Content-Description -Content-Disposition -Content-Duration -Content-Encoding -Content-features -Content-ID -Content-Identifier -Content-Language -Content-Length -Content-Location -Content-MD5 -Content-Range -Content-Return -Content-Script-Type -Content-Style-Type -Content-Transfer-Encoding -Content-Type -Content-Version -Control -Conversion -Conversion-With-Loss -Cookie -Cookie2 -C-Opt -Cost -C-PEP -C-PEP-Info -DASL -Date -Date-Received -DAV -Default-Style -Deferred-Delivery -Delivery-Date -Delta-Base -Depth -Derived-From -Destination -Differential-ID -Digest -Discarded-X400-IPMS-Extensions -Discarded-X400-MTS-Extensions -Disclose-Recipients -Disposition-Notification-Options -Disposition-Notification-To -Distribution -DKIM-Signature -DL-Expansion-History -Downgraded-Bcc -Downgraded-Cc -Downgraded-Disposition-Notification-To -Downgraded-Final-Recipient -Downgraded-From -Downgraded-In-Reply-To -Downgraded-Mail-From -Downgraded-Message-Id -Downgraded-Original-Recipient -Downgraded-Rcpt-To -Downgraded-References -Downgraded-Reply-To -Downgraded-Resent-Bcc -Downgraded-Resent-Cc -Downgraded-Resent-From -Downgraded-Resent-Reply-To -Downgraded-Resent-Sender -Downgraded-Resent-To -Downgraded-Return-Path -Downgraded-Sender -Downgraded-To -EDIINT-Features -Eesst-Version -Encoding -Encrypted -Errors-To -ETag -Expect -Expires -Expiry-Date -Ext -Followup-To -Forwarded -From -Generate-Delivery-Report -GetProfile -Hobareg -Host -HTTP2-Settings -If -If-Match -If-Modified-Since -If-None-Match -If-Range -If-Schedule-Tag-Match -If-Unmodified-Since -IM -Importance -Incomplete-Copy -Injection-Date -Injection-Info -In-Reply-To -Jabber-ID -Keep-Alive -Keywords -Label -Language -Last-Modified -Latest-Delivery-Time -Lines -Link -List-Archive -List-Help -List-ID -List-Owner -List-Post -List-Subscribe -List-Unsubscribe -List-Unsubscribe-Post -Location -Lock-Token -Man -Max-Forwards -Memento-Datetime -Message-Context -Message-ID -Message-Type -Meter -Method-Check -Method-Check-Expires -MIME-Version -MMHS-Acp127-Message-Identifier -MMHS-Authorizing-Users -MMHS-Codress-Message-Indicator -MMHS-Copy-Precedence -MMHS-Exempted-Address -MMHS-Extended-Authorisation-Info -MMHS-Handling-Instructions -MMHS-Message-Instructions -MMHS-Message-Type -MMHS-Originator-PLAD -MMHS-Originator-Reference -MMHS-Other-Recipients-Indicator-CC -MMHS-Other-Recipients-Indicator-To -MMHS-Primary-Precedence -MMHS-Subject-Indicator-Codes -MT-Priority -Negotiate -Newsgroups -NNTP-Posting-Date -NNTP-Posting-Host -Non-Compliance -Obsoletes -Opt -Optional -Optional-WWW-Authenticate -Ordering-Type -Organization -Origin -Original-Encoded-Information-Types -Original-From -Original-Message-ID -Original-Recipient -Original-Sender -Original-Subject -Originator-Return-Address -Overwrite -P3P -Path -PEP -Pep-Info -PICS-Label -Position -Posting-Version -Pragma -Prefer -Preference-Applied -Prevent-NonDelivery-Report -Priority -Privicon -ProfileObject -Protocol -Protocol-Info -Protocol-Query -Protocol-Request -Proxy-Authenticate -Proxy-Authentication-Info -Proxy-Authorization -Proxy-Connection -Proxy-Features -Proxy-Instruction -Public -Public-Key-Pins -Public-Key-Pins-Report-Only -Range -Received -Received-SPF -Redirect-Ref -References -Referer -Referer-Root -Relay-Version -Reply-By -Reply-To -Require-Recipient-Valid-Since -Resent-Bcc -Resent-Cc -Resent-Date -Resent-From -Resent-Message-ID -Resent-Reply-To -Resent-Sender -Resent-To -Resolution-Hint -Resolver-Location -Retry-After -Return-Path -Safe -Schedule-Reply -Schedule-Tag -Security-Scheme -Sec-WebSocket-Accept -Sec-WebSocket-Extensions -Sec-WebSocket-Key -Sec-WebSocket-Protocol -Sec-WebSocket-Version -See-Also -Sender -Sensitivity -Server -Set-Cookie -Set-Cookie2 -SetProfile -SIO-Label -SIO-Label-History -SLUG -SoapAction -Solicitation -Status-URI -Strict-Transport-Security -Subject -SubOK -Subst -Summary -Supersedes -Surrogate-Capability -Surrogate-Control -TCN -TE -Timeout -Title -To -Topic -Trailer -Transfer-Encoding -TTL -UA-Color -UA-Media -UA-Pixels -UA-Resolution -UA-Windowpixels -Upgrade -Urgency -URI -User-Agent -Variant-Vary -Vary -VBR-Info -Version -Via -Want-Digest -Warning -WWW-Authenticate -X400-Content-Identifier -X400-Content-Return -X400-Content-Type -X400-MTS-Identifier -X400-Originator -X400-Received -X400-Recipients -X400-Trace -X-Archived-At -X-Device-Accept -X-Device-Accept-Charset -X-Device-Accept-Encoding -X-Device-Accept-Language -X-Device-User-Agent -X-Frame-Options -X-Mittente -X-PGP-Sig -Xref -X-Ricevuta -X-Riferimento-Message-ID -X-TipoRicevuta -X-Trasporto -X-VerificaSicurezza diff --git a/src/beast/scripts/fuzzingclient.json b/src/beast/scripts/fuzzingclient.json deleted file mode 100644 index 6bece294007..00000000000 --- a/src/beast/scripts/fuzzingclient.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "outdir": "./autoresults", - "servers": [ - { - "url": "ws://127.0.0.1:6000" - }, - { - "url": "ws://127.0.0.1:6001" - } - ], - "cases": ["*"], - "exclude-cases": [], - "exclude-agent-cases": {} -} \ No newline at end of file diff --git a/src/beast/scripts/install-boost.sh b/src/beast/scripts/install-boost.sh deleted file mode 100755 index fcee32d5abd..00000000000 --- a/src/beast/scripts/install-boost.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bash -# Assumptions: -# 1) BOOST_ROOT and BOOST_URL are already defined, -# and contain valid values. -# 2) The last namepart of BOOST_ROOT matches the -# folder name internal to boost's .tar.gz -# When testing you can force a boost build by clearing travis caches: -# https://travis-ci.org/ripple/rippled/caches -set -eu -#if [ ! -d "$BOOST_ROOT" ] -#then - wget $BOOST_URL -O /tmp/boost.tar.gz - cd `dirname $BOOST_ROOT` - rm -fr ${BOOST_ROOT} - tar xzf /tmp/boost.tar.gz - - params="define=_GLIBCXX_USE_CXX11_ABI=0 \ - address-model=$ADDRESS_MODEL --with-program_options \ - --with-system --with-coroutine --with-filesystem" - cd $BOOST_ROOT && \ - ./bootstrap.sh --prefix=$BOOST_ROOT && \ - ./b2 -d1 $params && \ - ./b2 -d0 $params install -#else -# echo "Using cached boost at $BOOST_ROOT" -#fi - diff --git a/src/beast/scripts/install-dependencies.sh b/src/beast/scripts/install-dependencies.sh deleted file mode 100755 index d6b31dd3dc2..00000000000 --- a/src/beast/scripts/install-dependencies.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/env bash -# Exit if anything fails. -set -eux - -HERE=$PWD - -# Override gcc version to $GCC_VER. -# Put an appropriate symlink at the front of the path. -mkdir -v $HOME/bin -for g in gcc g++ gcov gcc-ar gcc-nm gcc-ranlib -do - test -x $( type -p ${g}-$GCC_VER ) - ln -sv $(type -p ${g}-$GCC_VER) $HOME/bin/${g} -done - -if [[ -n ${CLANG_VER:-} ]]; then - # There are cases where the directory exists, but the exe is not available. - # Use this workaround for now. - if [[ ! -x llvm-${LLVM_VERSION}/bin/llvm-config ]] && [[ -d llvm-${LLVM_VERSION} ]]; then - rm -fr llvm-${LLVM_VERSION} - fi - if [[ ! -d llvm-${LLVM_VERSION} ]]; then - mkdir llvm-${LLVM_VERSION} - LLVM_URL="http://llvm.org/releases/${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-x86_64-linux-gnu-ubuntu-14.04.tar.xz" - wget -O - ${LLVM_URL} | tar -Jxvf - --strip 1 -C llvm-${LLVM_VERSION} - fi - llvm-${LLVM_VERSION}/bin/llvm-config --version; - export LLVM_CONFIG="llvm-${LLVM_VERSION}/bin/llvm-config"; -fi - -# There are cases where the directory exists, but the exe is not available. -# Use this workaround for now. -if [[ ! -x cmake/bin/cmake && -d cmake ]]; then - rm -fr cmake -fi -if [[ ! -d cmake && ${BUILD_SYSTEM:-} == cmake ]]; then - CMAKE_URL="http://www.cmake.org/files/v3.8/cmake-3.8.0-Linux-x86_64.tar.gz" - mkdir cmake && wget --no-check-certificate -O - ${CMAKE_URL} | tar --strip-components=1 -xz -C cmake -fi - -# NOTE, changed from PWD -> HOME -export PATH=$HOME/bin:$PATH - -# What versions are we ACTUALLY running? -if [ -x $HOME/bin/g++ ]; then - $HOME/bin/g++ -v -fi -if [ -x $HOME/bin/clang ]; then - $HOME/bin/clang -v -fi -# Avoid `spurious errors` caused by ~/.npm permission issues -# Does it already exist? Who owns? What permissions? -ls -lah ~/.npm || mkdir ~/.npm -# Make sure we own it -chown -Rc $USER ~/.npm -# We use this so we can filter the subtrees from our coverage report -pip install --user requests==2.13.0 -pip install --user https://github.com/codecov/codecov-python/archive/master.zip -pip install --user autobahntestsuite - -bash scripts/install-boost.sh -bash scripts/install-valgrind.sh - -# Install lcov -# Download the archive -wget http://downloads.sourceforge.net/ltp/lcov-1.12.tar.gz -# Extract to ~/lcov-1.12 -tar xfvz lcov-1.12.tar.gz -C $HOME -# Set install path -mkdir -p $LCOV_ROOT -cd $HOME/lcov-1.12 && make install PREFIX=$LCOV_ROOT - -# Install coveralls reporter -#cd $HERE -#mkdir -p node_modules -#npm install coveralls diff --git a/src/beast/scripts/install-valgrind.sh b/src/beast/scripts/install-valgrind.sh deleted file mode 100755 index 943eb86730c..00000000000 --- a/src/beast/scripts/install-valgrind.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash -# Assumptions: -# 1) VALGRIND_ROOT is already defined, and contains a valid values -set -eu -if [ ! -d "$VALGRIND_ROOT/bin" ] -then - # These are specified in the addons/apt section of .travis.yml - # sudo apt-get install subversion automake autotools-dev libc6-dbg - export PATH=$PATH:$VALGRIND_ROOT/bin - svn co svn://svn.valgrind.org/valgrind/trunk valgrind-co - cd valgrind-co - ./autogen.sh - ./configure --prefix=$VALGRIND_ROOT - make - make install - # test it - valgrind ls -l -else - echo "Using cached valgrind at $VALGRIND_ROOT" -fi diff --git a/src/beast/scripts/make_field.sh b/src/beast/scripts/make_field.sh deleted file mode 100644 index 8e54c137207..00000000000 --- a/src/beast/scripts/make_field.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -export LC_COLLATE=C - -echo "// string constants" -echo ' "",' -cat $1 | sort -f | uniq | sed 's/^/ \"/; s/$/\",/' -echo - -echo "enum class field : unsigned short" -echo "{" -echo " unknown = 0," -echo -#cat $1 | uniq | sort -f | sed 's/./\L&/g; s/^/\t/; s/$/,/' -cat $1 | sort -f | uniq | sed 's/\(.*\)/ \L\1,/; s/-/_/g' -echo "};" -echo - -echo "// pairs" -#cat $1 | uniq | sort -f | sed 's/\(.*\)/\tmatch\(field::\L\1, \"\E\1\"\);/; s/-/_/' -cat $1 | sort -f | uniq | perl -nE 'chomp; $a=lc($_); $a=~s/-/_/g; say " match(field::$a, \"$_\");";' | tr -d "\015" - diff --git a/src/beast/scripts/parseautobahn.py b/src/beast/scripts/parseautobahn.py deleted file mode 100644 index 6b91e8c63ca..00000000000 --- a/src/beast/scripts/parseautobahn.py +++ /dev/null @@ -1,43 +0,0 @@ -import os -import json -import sys - -VARIANT = os.environ.get('VARIANT', 'release') -EXPECTED_BEHAVIOR = ('OK', 'UNIMPLEMENTED', 'INFORMATIONAL') -EXPECTED_BEHAVIOR_CLOSE = ('OK', 'INFORMATIONAL') -WARNINGS = ("peer did not respond (in time) in closing handshake", ) - -args = sys.argv[1:] -fn = os.path.abspath(args[0]) -indexPath = os.path.dirname(fn) -relativeToIndex = lambda f: os.path.join(indexPath, f) -print "index", fn - - -failures = [] -warnings = [] - -with open(fn, 'r') as fh: - index = json.load(fh) - for servername, serverResults in index.items(): - for test in serverResults: - result = serverResults[test] - if ((result['behavior'] not in EXPECTED_BEHAVIOR) or - result['behaviorClose'] not in EXPECTED_BEHAVIOR_CLOSE): - with open(relativeToIndex(result['reportfile'])) as rh: - report = json.load(rh) - if (report.get('wasNotCleanReason', '') in WARNINGS and - VARIANT != 'release'): - warnings.append(report) - else: - failures.append(report) - - -if warnings: - print >> sys.stderr, json.dumps(warnings, indent=2) - print >> sys.stderr, 'there was %s warnings' % len(warnings) - -if failures: - print >> sys.stderr, json.dumps(failures, indent=2) - print >> sys.stderr, 'there was %s failures' % len(failures) - sys.exit(1) diff --git a/src/beast/scripts/run-with-debugger.sh b/src/beast/scripts/run-with-debugger.sh deleted file mode 100755 index 6a8b55d85d7..00000000000 --- a/src/beast/scripts/run-with-debugger.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash -set -eu - -if [[ $(uname) == "Darwin" ]]; then - # -o runs after loading the binary - # -k runs after any crash - # We use a ghetto appromixation of --return-child-result, exiting with - # 1 on a crash - lldb --batch \ - -o 'run' \ - -k 'thread backtrace all' \ - -k 'script import os; os._exit(1)' \ - $@ -else - gdb --silent \ - --batch \ - --return-child-result \ - -ex="set print thread-events off" \ - -ex=run \ - -ex="thread apply all bt full" \ - --args $@ -fi diff --git a/src/beast/scripts/run-with-gdb.sh b/src/beast/scripts/run-with-gdb.sh deleted file mode 100755 index f7ff0bc7267..00000000000 --- a/src/beast/scripts/run-with-gdb.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -u -set -e -gdb --silent \ - --batch \ - --return-child-result \ - -ex="set print thread-events off" \ - -ex=run \ - -ex="thread apply all bt full" \ - --args $@ diff --git a/src/beast/scripts/valgrind.supp b/src/beast/scripts/valgrind.supp deleted file mode 100644 index 1d1ddc0b54b..00000000000 --- a/src/beast/scripts/valgrind.supp +++ /dev/null @@ -1,29 +0,0 @@ -{ - zlib_fill_window_no_init - Memcheck:Cond - fun:fill_window -} -{ - beast_fill_window_no_init - Memcheck:Cond - fun:_ZN5beast4zlib6detail14deflate_stream11fill_windowIvEEvRNS0_8z_paramsE -} -{ - Ignore OpenSSL malloc - Memcheck:Leak - fun:malloc - fun:CRYPTO_malloc - obj:*libcrypto* -} -{ - Ignore OpenSSL realloc - Memcheck:Leak - fun:realloc - fun:CRYPTO_realloc - obj:*libcrypto* -} -{ - OpenSSL Non-Purify - Memcheck:Cond - obj:*libcrypto* -} diff --git a/src/beast/test/CMakeLists.txt b/src/beast/test/CMakeLists.txt deleted file mode 100644 index d939ddbd066..00000000000 --- a/src/beast/test/CMakeLists.txt +++ /dev/null @@ -1,38 +0,0 @@ -# Part of Beast - -add_subdirectory (core) -add_subdirectory (http) -add_subdirectory (websocket) -add_subdirectory (zlib) - -if ((NOT "${VARIANT}" STREQUAL "coverage") AND - (NOT "${VARIANT}" STREQUAL "ubasan")) - - add_subdirectory (benchmarks) - add_subdirectory (common) - add_subdirectory (server) - - GroupSources(extras/beast extras) - GroupSources(include/beast beast) - - GroupSources(test "/") - - add_executable (lib-tests - ${BEAST_INCLUDES} - ${EXTRAS_INCLUDES} - ../extras/beast/unit_test/main.cpp - config.cpp - core.cpp - exemplars.cpp - http.cpp - version.cpp - websocket.cpp - zlib.cpp - ) - - target_link_libraries(lib-tests Beast ${Boost_PROGRAM_OPTIONS_LIBRARY}) - - if (MINGW) - set_target_properties(lib-tests PROPERTIES COMPILE_FLAGS "-Wa,-mbig-obj") - endif() -endif() diff --git a/src/beast/test/Jamfile b/src/beast/test/Jamfile deleted file mode 100644 index 01d339cc18e..00000000000 --- a/src/beast/test/Jamfile +++ /dev/null @@ -1,37 +0,0 @@ -# -# Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -# -# 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) -# - -import os ; - -compile config.cpp : coverage:no - ubasan:no : ; - -compile core.cpp : coverage:no - ubasan:no : ; - -compile exemplars.cpp : coverage:no - ubasan:no : ; - -compile http.cpp : coverage:no - ubasan:no : ; - -compile version.cpp : coverage:no - ubasan:no : ; - -compile websocket.cpp : coverage:no - ubasan:no : ; - -compile zlib.cpp : coverage:no - ubasan:no : ; - -build-project benchmarks ; -build-project common ; -build-project core ; -build-project http ; -build-project server ; -build-project websocket ; -build-project zlib ; diff --git a/src/beast/test/benchmarks/CMakeLists.txt b/src/beast/test/benchmarks/CMakeLists.txt deleted file mode 100644 index f6c0afcbc67..00000000000 --- a/src/beast/test/benchmarks/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -# Part of Beast - -GroupSources(extras/beast extras) -GroupSources(include/beast beast) - -GroupSources(test/benchmarks "/") -GroupSources(test/http "/") - -add_executable (benchmarks - ${BEAST_INCLUDES} - ${EXTRAS_INCLUDES} - ../../extras/beast/unit_test/main.cpp - ../http/message_fuzz.hpp - nodejs_parser.hpp - buffers.cpp - nodejs_parser.cpp - parser.cpp - utf8_checker.cpp -) - -target_link_libraries(benchmarks - Beast - ${Boost_PROGRAM_OPTIONS_LIBRARY} - ${Boost_FILESYSTEM_LIBRARY} - ) diff --git a/src/beast/test/benchmarks/Jamfile b/src/beast/test/benchmarks/Jamfile deleted file mode 100644 index a3ff3bd6dab..00000000000 --- a/src/beast/test/benchmarks/Jamfile +++ /dev/null @@ -1,17 +0,0 @@ -# -# Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -# -# 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) -# - -unit-test benchmarks : - ../../extras/beast/unit_test/main.cpp - buffers.cpp - nodejs_parser.cpp - parser.cpp - utf8_checker.cpp - : - coverage:no - ubasan:no - ; diff --git a/src/beast/test/benchmarks/buffers.cpp b/src/beast/test/benchmarks/buffers.cpp deleted file mode 100644 index 5cc99e6507e..00000000000 --- a/src/beast/test/benchmarks/buffers.cpp +++ /dev/null @@ -1,238 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { - -class buffers_test : public beast::unit_test::suite -{ -public: - using size_type = std::uint64_t; - - class timer - { - using clock_type = - std::chrono::system_clock; - - clock_type::time_point when_; - - public: - using duration = - clock_type::duration; - - timer() - : when_(clock_type::now()) - { - } - - duration - elapsed() const - { - return clock_type::now() - when_; - } - }; - - inline - size_type - throughput(std::chrono::duration< - double> const& elapsed, size_type items) - { - using namespace std::chrono; - return static_cast( - 1 / (elapsed/items).count()); - } - - template - static - std::size_t - fill(MutableBufferSequence const& buffers) - { - std::size_t n = 0; - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - for(boost::asio::mutable_buffer buffer : buffers) - { - std::fill( - buffer_cast(buffer), - buffer_cast(buffer) + - buffer_size(buffer), '\0'); - n += buffer_size(buffer); - } - return n; - } - - template - size_type - do_prepares(std::size_t repeat, - std::size_t count, std::size_t size) - { - timer t; - size_type total = 0; - for(auto i = repeat; i--;) - { - DynamicBuffer b; - for(auto j = count; j--;) - { - auto const n = fill(b.prepare(size)); - b.commit(n); - total += n; - } - } - return throughput(t.elapsed(), total); - } - - template - size_type - do_hints(std::size_t repeat, - std::size_t count, std::size_t size) - { - timer t; - size_type total = 0; - for(auto i = repeat; i--;) - { - DynamicBuffer b; - for(auto j = count; j--;) - { - for(auto remain = size; remain;) - { - auto const n = fill(b.prepare( - read_size(b, remain))); - b.commit(n); - remain -= n; - total += n; - } - } - } - return throughput(t.elapsed(), total); - } - - template - size_type - do_random(std::size_t repeat, - std::size_t count, std::size_t size) - { - timer t; - size_type total = 0; - for(auto i = repeat; i--;) - { - DynamicBuffer b; - for(auto j = count; j--;) - { - auto const n = fill(b.prepare( - 1 + (rand()%(2*size)))); - b.commit(n); - total += n; - } - } - return throughput(t.elapsed(), total); - } - - static - inline - void - do_trials_1(bool) - { - } - - template - void - do_trials_1(bool print, F0&& f, FN... fn) - { - timer t; - using namespace std::chrono; - static size_type constexpr den = 1024 * 1024; - if(print) - { - log << std::right << std::setw(10) << - ((f() + (den / 2)) / den) << " MB/s"; - log.flush(); - } - else - { - f(); - } - do_trials_1(print, fn...); - } - - template - void - do_trials(string_view name, - std::size_t trials, F0&& f0, FN... fn) - { - using namespace std::chrono; - // warm-up - do_trials_1(false, f0, fn...); - do_trials_1(false, f0, fn...); - while(trials--) - { - timer t; - log << std::left << std::setw(24) << name << ":"; - log.flush(); - do_trials_1(true, f0, fn...); - log << " " << - duration_cast(t.elapsed()).count() << "ms"; - log << std::endl; - } - } - - void - run() override - { - static std::size_t constexpr trials = 1; - static std::size_t constexpr repeat = 250; - std::vector> params; - params.emplace_back(1024, 1024); - params.emplace_back(512, 4096); - params.emplace_back(256, 32768); - log << std::endl; - for(auto const& param : params) - { - auto const count = param.first; - auto const size = param.second; - auto const s = std::string("count=") + std::to_string(count) + - ", size=" + std::to_string(size); - log << std::left << std::setw(24) << s << " " << - std::right << std::setw(15) << "prepare" << - std::right << std::setw(15) << "with hint" << - std::right << std::setw(15) << "random" << - std::endl; - do_trials("multi_buffer", trials, - [&](){ return do_prepares(repeat, count, size); } - ,[&](){ return do_hints (repeat, count, size); } - ,[&](){ return do_random (repeat, count, size); } - ); - do_trials("flat_buffer", trials, - [&](){ return do_prepares(repeat, count, size); } - ,[&](){ return do_hints (repeat, count, size); } - ,[&](){ return do_random (repeat, count, size); } - ); - do_trials("boost::asio::streambuf", trials, - [&](){ return do_prepares(repeat, count, size); } - ,[&](){ return do_hints (repeat, count, size); } - ,[&](){ return do_random (repeat, count, size); } - ); - log << std::endl; - } - pass(); - } -}; - -BEAST_DEFINE_TESTSUITE(buffers,benchmarks,beast); - -} // beast diff --git a/src/beast/test/benchmarks/nodejs-parser/AUTHORS b/src/beast/test/benchmarks/nodejs-parser/AUTHORS deleted file mode 100644 index 5323b685cae..00000000000 --- a/src/beast/test/benchmarks/nodejs-parser/AUTHORS +++ /dev/null @@ -1,68 +0,0 @@ -# Authors ordered by first contribution. -Ryan Dahl -Jeremy Hinegardner -Sergey Shepelev -Joe Damato -tomika -Phoenix Sol -Cliff Frey -Ewen Cheslack-Postava -Santiago Gala -Tim Becker -Jeff Terrace -Ben Noordhuis -Nathan Rajlich -Mark Nottingham -Aman Gupta -Tim Becker -Sean Cunningham -Peter Griess -Salman Haq -Cliff Frey -Jon Kolb -Fouad Mardini -Paul Querna -Felix Geisendörfer -koichik -Andre Caron -Ivo Raisr -James McLaughlin -David Gwynne -Thomas LE ROUX -Randy Rizun -Andre Louis Caron -Simon Zimmermann -Erik Dubbelboer -Martell Malone -Bertrand Paquet -BogDan Vatra -Peter Faiman -Corey Richardson -Tóth Tamás -Cam Swords -Chris Dickinson -Uli Köhler -Charlie Somerville -Patrik Stutz -Fedor Indutny -runner -Alexis Campailla -David Wragg -Vinnie Falco -Alex Butum -Rex Feng -Alex Kocharin -Mark Koopman -Helge Heß -Alexis La Goutte -George Miroshnykov -Maciej MaÅ‚ecki -Marc O'Morain -Jeff Pinner -Timothy J Fontaine -Akagi201 -Romain Giraud -Jay Satiro -Arne Steen -Kjell Schubert -Olivier Mengué diff --git a/src/beast/test/benchmarks/nodejs-parser/LICENSE-MIT b/src/beast/test/benchmarks/nodejs-parser/LICENSE-MIT deleted file mode 100644 index 58010b38894..00000000000 --- a/src/beast/test/benchmarks/nodejs-parser/LICENSE-MIT +++ /dev/null @@ -1,23 +0,0 @@ -http_parser.c is based on src/http/ngx_http_parse.c from NGINX copyright -Igor Sysoev. - -Additional changes are licensed under the same terms as NGINX and -copyright Joyent, Inc. and other Node contributors. All rights reserved. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to -deal in the Software without restriction, including without limitation the -rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -sell copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -IN THE SOFTWARE. diff --git a/src/beast/test/benchmarks/nodejs-parser/README.md b/src/beast/test/benchmarks/nodejs-parser/README.md deleted file mode 100644 index eedd7f8c9a4..00000000000 --- a/src/beast/test/benchmarks/nodejs-parser/README.md +++ /dev/null @@ -1,246 +0,0 @@ -HTTP Parser -=========== - -[![Build Status](https://api.travis-ci.org/nodejs/http-parser.svg?branch=master)](https://travis-ci.org/nodejs/http-parser) - -This is a parser for HTTP messages written in C. It parses both requests and -responses. The parser is designed to be used in performance HTTP -applications. It does not make any syscalls nor allocations, it does not -buffer data, it can be interrupted at anytime. Depending on your -architecture, it only requires about 40 bytes of data per message -stream (in a web server that is per connection). - -Features: - - * No dependencies - * Handles persistent streams (keep-alive). - * Decodes chunked encoding. - * Upgrade support - * Defends against buffer overflow attacks. - -The parser extracts the following information from HTTP messages: - - * Header fields and values - * Content-Length - * Request method - * Response status code - * Transfer-Encoding - * HTTP version - * Request URL - * Message body - - -Usage ------ - -One `http_parser` object is used per TCP connection. Initialize the struct -using `http_parser_init()` and set the callbacks. That might look something -like this for a request parser: -```c -http_parser_settings settings; -settings.on_url = my_url_callback; -settings.on_header_field = my_header_field_callback; -/* ... */ - -http_parser *parser = malloc(sizeof(http_parser)); -http_parser_init(parser, HTTP_REQUEST); -parser->data = my_socket; -``` - -When data is received on the socket execute the parser and check for errors. - -```c -size_t len = 80*1024, nparsed; -char buf[len]; -ssize_t recved; - -recved = recv(fd, buf, len, 0); - -if (recved < 0) { - /* Handle error. */ -} - -/* Start up / continue the parser. - * Note we pass recved==0 to signal that EOF has been received. - */ -nparsed = http_parser_execute(parser, &settings, buf, recved); - -if (parser->upgrade) { - /* handle new protocol */ -} else if (nparsed != recved) { - /* Handle error. Usually just close the connection. */ -} -``` - -HTTP needs to know where the end of the stream is. For example, sometimes -servers send responses without Content-Length and expect the client to -consume input (for the body) until EOF. To tell http_parser about EOF, give -`0` as the fourth parameter to `http_parser_execute()`. Callbacks and errors -can still be encountered during an EOF, so one must still be prepared -to receive them. - -Scalar valued message information such as `status_code`, `method`, and the -HTTP version are stored in the parser structure. This data is only -temporally stored in `http_parser` and gets reset on each new message. If -this information is needed later, copy it out of the structure during the -`headers_complete` callback. - -The parser decodes the transfer-encoding for both requests and responses -transparently. That is, a chunked encoding is decoded before being sent to -the on_body callback. - - -The Special Problem of Upgrade ------------------------------- - -HTTP supports upgrading the connection to a different protocol. An -increasingly common example of this is the WebSocket protocol which sends -a request like - - GET /demo HTTP/1.1 - Upgrade: WebSocket - Connection: Upgrade - Host: example.com - Origin: http://example.com - WebSocket-Protocol: sample - -followed by non-HTTP data. - -(See [RFC6455](https://tools.ietf.org/html/rfc6455) for more information the -WebSocket protocol.) - -To support this, the parser will treat this as a normal HTTP message without a -body, issuing both on_headers_complete and on_message_complete callbacks. However -http_parser_execute() will stop parsing at the end of the headers and return. - -The user is expected to check if `parser->upgrade` has been set to 1 after -`http_parser_execute()` returns. Non-HTTP data begins at the buffer supplied -offset by the return value of `http_parser_execute()`. - - -Callbacks ---------- - -During the `http_parser_execute()` call, the callbacks set in -`http_parser_settings` will be executed. The parser maintains state and -never looks behind, so buffering the data is not necessary. If you need to -save certain data for later usage, you can do that from the callbacks. - -There are two types of callbacks: - -* notification `typedef int (*http_cb) (http_parser*);` - Callbacks: on_message_begin, on_headers_complete, on_message_complete. -* data `typedef int (*http_data_cb) (http_parser*, const char *at, size_t length);` - Callbacks: (requests only) on_url, - (common) on_header_field, on_header_value, on_body; - -Callbacks must return 0 on success. Returning a non-zero value indicates -error to the parser, making it exit immediately. - -For cases where it is necessary to pass local information to/from a callback, -the `http_parser` object's `data` field can be used. -An example of such a case is when using threads to handle a socket connection, -parse a request, and then give a response over that socket. By instantiation -of a thread-local struct containing relevant data (e.g. accepted socket, -allocated memory for callbacks to write into, etc), a parser's callbacks are -able to communicate data between the scope of the thread and the scope of the -callback in a threadsafe manner. This allows http-parser to be used in -multi-threaded contexts. - -Example: -``` - typedef struct { - socket_t sock; - void* buffer; - int buf_len; - } custom_data_t; - - -int my_url_callback(http_parser* parser, const char *at, size_t length) { - /* access to thread local custom_data_t struct. - Use this access save parsed data for later use into thread local - buffer, or communicate over socket - */ - parser->data; - ... - return 0; -} - -... - -void http_parser_thread(socket_t sock) { - int nparsed = 0; - /* allocate memory for user data */ - custom_data_t *my_data = malloc(sizeof(custom_data_t)); - - /* some information for use by callbacks. - * achieves thread -> callback information flow */ - my_data->sock = sock; - - /* instantiate a thread-local parser */ - http_parser *parser = malloc(sizeof(http_parser)); - http_parser_init(parser, HTTP_REQUEST); /* initialise parser */ - /* this custom data reference is accessible through the reference to the - parser supplied to callback functions */ - parser->data = my_data; - - http_parser_settings settings; / * set up callbacks */ - settings.on_url = my_url_callback; - - /* execute parser */ - nparsed = http_parser_execute(parser, &settings, buf, recved); - - ... - /* parsed information copied from callback. - can now perform action on data copied into thread-local memory from callbacks. - achieves callback -> thread information flow */ - my_data->buffer; - ... -} - -``` - -In case you parse HTTP message in chunks (i.e. `read()` request line -from socket, parse, read half headers, parse, etc) your data callbacks -may be called more than once. Http-parser guarantees that data pointer is only -valid for the lifetime of callback. You can also `read()` into a heap allocated -buffer to avoid copying memory around if this fits your application. - -Reading headers may be a tricky task if you read/parse headers partially. -Basically, you need to remember whether last header callback was field or value -and apply the following logic: - - (on_header_field and on_header_value shortened to on_h_*) - ------------------------ ------------ -------------------------------------------- - | State (prev. callback) | Callback | Description/action | - ------------------------ ------------ -------------------------------------------- - | nothing (first call) | on_h_field | Allocate new buffer and copy callback data | - | | | into it | - ------------------------ ------------ -------------------------------------------- - | value | on_h_field | New header started. | - | | | Copy current name,value buffers to headers | - | | | list and allocate new buffer for new name | - ------------------------ ------------ -------------------------------------------- - | field | on_h_field | Previous name continues. Reallocate name | - | | | buffer and append callback data to it | - ------------------------ ------------ -------------------------------------------- - | field | on_h_value | Value for current header started. Allocate | - | | | new buffer and copy callback data to it | - ------------------------ ------------ -------------------------------------------- - | value | on_h_value | Value continues. Reallocate value buffer | - | | | and append callback data to it | - ------------------------ ------------ -------------------------------------------- - - -Parsing URLs ------------- - -A simplistic zero-copy URL parser is provided as `http_parser_parse_url()`. -Users of this library may wish to use it to parse URLs constructed from -consecutive `on_url` callbacks. - -See examples of reading in headers: - -* [partial example](http://gist.github.com/155877) in C -* [from http-parser tests](http://github.com/joyent/http-parser/blob/37a0ff8/test.c#L403) in C -* [from Node library](http://github.com/joyent/node/blob/842eaf4/src/http.js#L284) in Javascript diff --git a/src/beast/test/benchmarks/nodejs-parser/http_parser.c b/src/beast/test/benchmarks/nodejs-parser/http_parser.c deleted file mode 100644 index 719617549d0..00000000000 --- a/src/beast/test/benchmarks/nodejs-parser/http_parser.c +++ /dev/null @@ -1,2468 +0,0 @@ -/* Based on src/http/ngx_http_parse.c from NGINX copyright Igor Sysoev - * - * Additional changes are licensed under the same terms as NGINX and - * copyright Joyent, Inc. and other Node contributors. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ -#include "http_parser.h" -#include -#include -#include -#include -#include -#include - -#ifndef ULLONG_MAX -# define ULLONG_MAX ((uint64_t) -1) /* 2^64-1 */ -#endif - -#ifndef MIN -# define MIN(a,b) ((a) < (b) ? (a) : (b)) -#endif - -#ifndef ARRAY_SIZE -# define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) -#endif - -#ifndef BIT_AT -# define BIT_AT(a, i) \ - (!!((unsigned int) (a)[(unsigned int) (i) >> 3] & \ - (1 << ((unsigned int) (i) & 7)))) -#endif - -#ifndef ELEM_AT -# define ELEM_AT(a, i, v) ((unsigned int) (i) < ARRAY_SIZE(a) ? (a)[(i)] : (v)) -#endif - -#define SET_ERRNO(e) \ -do { \ - parser->http_errno = (e); \ -} while(0) - -#define CURRENT_STATE() p_state -#define UPDATE_STATE(V) p_state = (enum state) (V); -#define RETURN(V) \ -do { \ - parser->state = CURRENT_STATE(); \ - return (V); \ -} while (0); -#define REEXECUTE() \ - goto reexecute; \ - - -#ifdef __GNUC__ -# define LIKELY(X) __builtin_expect(!!(X), 1) -# define UNLIKELY(X) __builtin_expect(!!(X), 0) -#else -# define LIKELY(X) (X) -# define UNLIKELY(X) (X) -#endif - - -/* Run the notify callback FOR, returning ER if it fails */ -#define CALLBACK_NOTIFY_(FOR, ER) \ -do { \ - assert(HTTP_PARSER_ERRNO(parser) == HPE_OK); \ - \ - if (LIKELY(settings->on_##FOR)) { \ - parser->state = CURRENT_STATE(); \ - if (UNLIKELY(0 != settings->on_##FOR(parser))) { \ - SET_ERRNO(HPE_CB_##FOR); \ - } \ - UPDATE_STATE(parser->state); \ - \ - /* We either errored above or got paused; get out */ \ - if (UNLIKELY(HTTP_PARSER_ERRNO(parser) != HPE_OK)) { \ - return (ER); \ - } \ - } \ -} while (0) - -/* Run the notify callback FOR and consume the current byte */ -#define CALLBACK_NOTIFY(FOR) CALLBACK_NOTIFY_(FOR, p - data + 1) - -/* Run the notify callback FOR and don't consume the current byte */ -#define CALLBACK_NOTIFY_NOADVANCE(FOR) CALLBACK_NOTIFY_(FOR, p - data) - -/* Run data callback FOR with LEN bytes, returning ER if it fails */ -#define CALLBACK_DATA_(FOR, LEN, ER) \ -do { \ - assert(HTTP_PARSER_ERRNO(parser) == HPE_OK); \ - \ - if (FOR##_mark) { \ - if (LIKELY(settings->on_##FOR)) { \ - parser->state = CURRENT_STATE(); \ - if (UNLIKELY(0 != \ - settings->on_##FOR(parser, FOR##_mark, (LEN)))) { \ - SET_ERRNO(HPE_CB_##FOR); \ - } \ - UPDATE_STATE(parser->state); \ - \ - /* We either errored above or got paused; get out */ \ - if (UNLIKELY(HTTP_PARSER_ERRNO(parser) != HPE_OK)) { \ - return (ER); \ - } \ - } \ - FOR##_mark = NULL; \ - } \ -} while (0) - -/* Run the data callback FOR and consume the current byte */ -#define CALLBACK_DATA(FOR) \ - CALLBACK_DATA_(FOR, p - FOR##_mark, p - data + 1) - -/* Run the data callback FOR and don't consume the current byte */ -#define CALLBACK_DATA_NOADVANCE(FOR) \ - CALLBACK_DATA_(FOR, p - FOR##_mark, p - data) - -/* Set the mark FOR; non-destructive if mark is already set */ -#define MARK(FOR) \ -do { \ - if (!FOR##_mark) { \ - FOR##_mark = p; \ - } \ -} while (0) - -/* Don't allow the total size of the HTTP headers (including the status - * line) to exceed HTTP_MAX_HEADER_SIZE. This check is here to protect - * embedders against denial-of-service attacks where the attacker feeds - * us a never-ending header that the embedder keeps buffering. - * - * This check is arguably the responsibility of embedders but we're doing - * it on the embedder's behalf because most won't bother and this way we - * make the web a little safer. HTTP_MAX_HEADER_SIZE is still far bigger - * than any reasonable request or response so this should never affect - * day-to-day operation. - */ -#define COUNT_HEADER_SIZE(V) \ -do { \ - parser->nread += (V); \ - if (UNLIKELY(parser->nread > (HTTP_MAX_HEADER_SIZE))) { \ - SET_ERRNO(HPE_HEADER_OVERFLOW); \ - goto error; \ - } \ -} while (0) - - -#define PROXY_CONNECTION "proxy-connection" -#define CONNECTION "connection" -#define CONTENT_LENGTH "content-length" -#define TRANSFER_ENCODING "transfer-encoding" -#define UPGRADE "upgrade" -#define CHUNKED "chunked" -#define KEEP_ALIVE "keep-alive" -#define CLOSE "close" - - -static const char *method_strings[] = - { -#define XX(num, name, string) #string, - HTTP_METHOD_MAP(XX) -#undef XX - }; - - -/* Tokens as defined by rfc 2616. Also lowercases them. - * token = 1* - * separators = "(" | ")" | "<" | ">" | "@" - * | "," | ";" | ":" | "\" | <"> - * | "/" | "[" | "]" | "?" | "=" - * | "{" | "}" | SP | HT - */ -static const char tokens[256] = { -/* 0 nul 1 soh 2 stx 3 etx 4 eot 5 enq 6 ack 7 bel */ - 0, 0, 0, 0, 0, 0, 0, 0, -/* 8 bs 9 ht 10 nl 11 vt 12 np 13 cr 14 so 15 si */ - 0, 0, 0, 0, 0, 0, 0, 0, -/* 16 dle 17 dc1 18 dc2 19 dc3 20 dc4 21 nak 22 syn 23 etb */ - 0, 0, 0, 0, 0, 0, 0, 0, -/* 24 can 25 em 26 sub 27 esc 28 fs 29 gs 30 rs 31 us */ - 0, 0, 0, 0, 0, 0, 0, 0, -/* 32 sp 33 ! 34 " 35 # 36 $ 37 % 38 & 39 ' */ - 0, '!', 0, '#', '$', '%', '&', '\'', -/* 40 ( 41 ) 42 * 43 + 44 , 45 - 46 . 47 / */ - 0, 0, '*', '+', 0, '-', '.', 0, -/* 48 0 49 1 50 2 51 3 52 4 53 5 54 6 55 7 */ - '0', '1', '2', '3', '4', '5', '6', '7', -/* 56 8 57 9 58 : 59 ; 60 < 61 = 62 > 63 ? */ - '8', '9', 0, 0, 0, 0, 0, 0, -/* 64 @ 65 A 66 B 67 C 68 D 69 E 70 F 71 G */ - 0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', -/* 72 H 73 I 74 J 75 K 76 L 77 M 78 N 79 O */ - 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', -/* 80 P 81 Q 82 R 83 S 84 T 85 U 86 V 87 W */ - 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', -/* 88 X 89 Y 90 Z 91 [ 92 \ 93 ] 94 ^ 95 _ */ - 'x', 'y', 'z', 0, 0, 0, '^', '_', -/* 96 ` 97 a 98 b 99 c 100 d 101 e 102 f 103 g */ - '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', -/* 104 h 105 i 106 j 107 k 108 l 109 m 110 n 111 o */ - 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', -/* 112 p 113 q 114 r 115 s 116 t 117 u 118 v 119 w */ - 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', -/* 120 x 121 y 122 z 123 { 124 | 125 } 126 ~ 127 del */ - 'x', 'y', 'z', 0, '|', 0, '~', 0 }; - - -static const int8_t unhex[256] = - {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 - ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 - ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 - , 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1 - ,-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1 - ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 - ,-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1 - ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 - }; - - -#if HTTP_PARSER_STRICT -# define T(v) 0 -#else -# define T(v) v -#endif - - -static const uint8_t normal_url_char[32] = { -/* 0 nul 1 soh 2 stx 3 etx 4 eot 5 enq 6 ack 7 bel */ - 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0, -/* 8 bs 9 ht 10 nl 11 vt 12 np 13 cr 14 so 15 si */ - 0 | T(2) | 0 | 0 | T(16) | 0 | 0 | 0, -/* 16 dle 17 dc1 18 dc2 19 dc3 20 dc4 21 nak 22 syn 23 etb */ - 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0, -/* 24 can 25 em 26 sub 27 esc 28 fs 29 gs 30 rs 31 us */ - 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0, -/* 32 sp 33 ! 34 " 35 # 36 $ 37 % 38 & 39 ' */ - 0 | 2 | 4 | 0 | 16 | 32 | 64 | 128, -/* 40 ( 41 ) 42 * 43 + 44 , 45 - 46 . 47 / */ - 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128, -/* 48 0 49 1 50 2 51 3 52 4 53 5 54 6 55 7 */ - 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128, -/* 56 8 57 9 58 : 59 ; 60 < 61 = 62 > 63 ? */ - 1 | 2 | 4 | 8 | 16 | 32 | 64 | 0, -/* 64 @ 65 A 66 B 67 C 68 D 69 E 70 F 71 G */ - 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128, -/* 72 H 73 I 74 J 75 K 76 L 77 M 78 N 79 O */ - 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128, -/* 80 P 81 Q 82 R 83 S 84 T 85 U 86 V 87 W */ - 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128, -/* 88 X 89 Y 90 Z 91 [ 92 \ 93 ] 94 ^ 95 _ */ - 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128, -/* 96 ` 97 a 98 b 99 c 100 d 101 e 102 f 103 g */ - 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128, -/* 104 h 105 i 106 j 107 k 108 l 109 m 110 n 111 o */ - 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128, -/* 112 p 113 q 114 r 115 s 116 t 117 u 118 v 119 w */ - 1 | 2 | 4 | 8 | 16 | 32 | 64 | 128, -/* 120 x 121 y 122 z 123 { 124 | 125 } 126 ~ 127 del */ - 1 | 2 | 4 | 8 | 16 | 32 | 64 | 0, }; - -#undef T - -enum state - { s_dead = 1 /* important that this is > 0 */ - - , s_start_req_or_res - , s_res_or_resp_H - , s_start_res - , s_res_H - , s_res_HT - , s_res_HTT - , s_res_HTTP - , s_res_first_http_major - , s_res_http_major - , s_res_first_http_minor - , s_res_http_minor - , s_res_first_status_code - , s_res_status_code - , s_res_status_start - , s_res_status - , s_res_line_almost_done - - , s_start_req - - , s_req_method - , s_req_spaces_before_url - , s_req_schema - , s_req_schema_slash - , s_req_schema_slash_slash - , s_req_server_start - , s_req_server - , s_req_server_with_at - , s_req_path - , s_req_query_string_start - , s_req_query_string - , s_req_fragment_start - , s_req_fragment - , s_req_http_start - , s_req_http_H - , s_req_http_HT - , s_req_http_HTT - , s_req_http_HTTP - , s_req_first_http_major - , s_req_http_major - , s_req_first_http_minor - , s_req_http_minor - , s_req_line_almost_done - - , s_header_field_start - , s_header_field - , s_header_value_discard_ws - , s_header_value_discard_ws_almost_done - , s_header_value_discard_lws - , s_header_value_start - , s_header_value - , s_header_value_lws - - , s_header_almost_done - - , s_chunk_size_start - , s_chunk_size - , s_chunk_parameters - , s_chunk_size_almost_done - - , s_headers_almost_done - , s_headers_done - - /* Important: 's_headers_done' must be the last 'header' state. All - * states beyond this must be 'body' states. It is used for overflow - * checking. See the PARSING_HEADER() macro. - */ - - , s_chunk_data - , s_chunk_data_almost_done - , s_chunk_data_done - - , s_body_identity - , s_body_identity_eof - - , s_message_done - }; - - -#define PARSING_HEADER(state) (state <= s_headers_done) - - -enum header_states - { h_general = 0 - , h_C - , h_CO - , h_CON - - , h_matching_connection - , h_matching_proxy_connection - , h_matching_content_length - , h_matching_transfer_encoding - , h_matching_upgrade - - , h_connection - , h_content_length - , h_transfer_encoding - , h_upgrade - - , h_matching_transfer_encoding_chunked - , h_matching_connection_token_start - , h_matching_connection_keep_alive - , h_matching_connection_close - , h_matching_connection_upgrade - , h_matching_connection_token - - , h_transfer_encoding_chunked - , h_connection_keep_alive - , h_connection_close - , h_connection_upgrade - }; - -enum http_host_state - { - s_http_host_dead = 1 - , s_http_userinfo_start - , s_http_userinfo - , s_http_host_start - , s_http_host_v6_start - , s_http_host - , s_http_host_v6 - , s_http_host_v6_end - , s_http_host_v6_zone_start - , s_http_host_v6_zone - , s_http_host_port_start - , s_http_host_port -}; - -/* Macros for character classes; depends on strict-mode */ -#define CR '\r' -#define LF '\n' -#define LOWER(c) (unsigned char)(c | 0x20) -#define IS_ALPHA(c) (LOWER(c) >= 'a' && LOWER(c) <= 'z') -#define IS_NUM(c) ((c) >= '0' && (c) <= '9') -#define IS_ALPHANUM(c) (IS_ALPHA(c) || IS_NUM(c)) -#define IS_HEX(c) (IS_NUM(c) || (LOWER(c) >= 'a' && LOWER(c) <= 'f')) -#define IS_MARK(c) ((c) == '-' || (c) == '_' || (c) == '.' || \ - (c) == '!' || (c) == '~' || (c) == '*' || (c) == '\'' || (c) == '(' || \ - (c) == ')') -#define IS_USERINFO_CHAR(c) (IS_ALPHANUM(c) || IS_MARK(c) || (c) == '%' || \ - (c) == ';' || (c) == ':' || (c) == '&' || (c) == '=' || (c) == '+' || \ - (c) == '$' || (c) == ',') - -#define STRICT_TOKEN(c) (tokens[(unsigned char)c]) - -#if HTTP_PARSER_STRICT -#define TOKEN(c) (tokens[(unsigned char)c]) -#define IS_URL_CHAR(c) (BIT_AT(normal_url_char, (unsigned char)c)) -#define IS_HOST_CHAR(c) (IS_ALPHANUM(c) || (c) == '.' || (c) == '-') -#else -#define TOKEN(c) ((c == ' ') ? ' ' : tokens[(unsigned char)c]) -#define IS_URL_CHAR(c) \ - (BIT_AT(normal_url_char, (unsigned char)c) || ((c) & 0x80)) -#define IS_HOST_CHAR(c) \ - (IS_ALPHANUM(c) || (c) == '.' || (c) == '-' || (c) == '_') -#endif - -/** - * Verify that a char is a valid visible (printable) US-ASCII - * character or %x80-FF - **/ -#define IS_HEADER_CHAR(ch) \ - (ch == CR || ch == LF || ch == 9 || ((unsigned char)ch > 31 && ch != 127)) - -#define start_state (parser->type == HTTP_REQUEST ? s_start_req : s_start_res) - - -#if HTTP_PARSER_STRICT -# define STRICT_CHECK(cond) \ -do { \ - if (cond) { \ - SET_ERRNO(HPE_STRICT); \ - goto error; \ - } \ -} while (0) -# define NEW_MESSAGE() (http_should_keep_alive(parser) ? start_state : s_dead) -#else -# define STRICT_CHECK(cond) -# define NEW_MESSAGE() start_state -#endif - - -/* Map errno values to strings for human-readable output */ -#define HTTP_STRERROR_GEN(n, s) { "HPE_" #n, s }, -static struct { - const char *name; - const char *description; -} http_strerror_tab[] = { - HTTP_ERRNO_MAP(HTTP_STRERROR_GEN) -}; -#undef HTTP_STRERROR_GEN - -int http_message_needs_eof(const http_parser *parser); - -/* Our URL parser. - * - * This is designed to be shared by http_parser_execute() for URL validation, - * hence it has a state transition + byte-for-byte interface. In addition, it - * is meant to be embedded in http_parser_parse_url(), which does the dirty - * work of turning state transitions URL components for its API. - * - * This function should only be invoked with non-space characters. It is - * assumed that the caller cares about (and can detect) the transition between - * URL and non-URL states by looking for these. - */ -static enum state -parse_url_char(enum state s, const char ch) -{ - if (ch == ' ' || ch == '\r' || ch == '\n') { - return s_dead; - } - -#if HTTP_PARSER_STRICT - if (ch == '\t' || ch == '\f') { - return s_dead; - } -#endif - - switch (s) { - case s_req_spaces_before_url: - /* Proxied requests are followed by scheme of an absolute URI (alpha). - * All methods except CONNECT are followed by '/' or '*'. - */ - - if (ch == '/' || ch == '*') { - return s_req_path; - } - - if (IS_ALPHA(ch)) { - return s_req_schema; - } - - break; - - case s_req_schema: - if (IS_ALPHA(ch)) { - return s; - } - - if (ch == ':') { - return s_req_schema_slash; - } - - break; - - case s_req_schema_slash: - if (ch == '/') { - return s_req_schema_slash_slash; - } - - break; - - case s_req_schema_slash_slash: - if (ch == '/') { - return s_req_server_start; - } - - break; - - case s_req_server_with_at: - if (ch == '@') { - return s_dead; - } - - /* FALLTHROUGH */ - case s_req_server_start: - case s_req_server: - if (ch == '/') { - return s_req_path; - } - - if (ch == '?') { - return s_req_query_string_start; - } - - if (ch == '@') { - return s_req_server_with_at; - } - - if (IS_USERINFO_CHAR(ch) || ch == '[' || ch == ']') { - return s_req_server; - } - - break; - - case s_req_path: - if (IS_URL_CHAR(ch)) { - return s; - } - - switch (ch) { - case '?': - return s_req_query_string_start; - - case '#': - return s_req_fragment_start; - } - - break; - - case s_req_query_string_start: - case s_req_query_string: - if (IS_URL_CHAR(ch)) { - return s_req_query_string; - } - - switch (ch) { - case '?': - /* allow extra '?' in query string */ - return s_req_query_string; - - case '#': - return s_req_fragment_start; - } - - break; - - case s_req_fragment_start: - if (IS_URL_CHAR(ch)) { - return s_req_fragment; - } - - switch (ch) { - case '?': - return s_req_fragment; - - case '#': - return s; - } - - break; - - case s_req_fragment: - if (IS_URL_CHAR(ch)) { - return s; - } - - switch (ch) { - case '?': - case '#': - return s; - } - - break; - - default: - break; - } - - /* We should never fall out of the switch above unless there's an error */ - return s_dead; -} - -size_t http_parser_execute (http_parser *parser, - const http_parser_settings *settings, - const char *data, - size_t len) -{ - char c, ch; - int8_t unhex_val; - const char *p = data; - const char *header_field_mark = 0; - const char *header_value_mark = 0; - const char *url_mark = 0; - const char *body_mark = 0; - const char *status_mark = 0; - enum state p_state = (enum state) parser->state; - const unsigned int lenient = parser->lenient_http_headers; - - /* We're in an error state. Don't bother doing anything. */ - if (HTTP_PARSER_ERRNO(parser) != HPE_OK) { - return 0; - } - - if (len == 0) { - switch (CURRENT_STATE()) { - case s_body_identity_eof: - /* Use of CALLBACK_NOTIFY() here would erroneously return 1 byte read if - * we got paused. - */ - CALLBACK_NOTIFY_NOADVANCE(message_complete); - return 0; - - case s_dead: - case s_start_req_or_res: - case s_start_res: - case s_start_req: - return 0; - - default: - SET_ERRNO(HPE_INVALID_EOF_STATE); - return 1; - } - } - - - if (CURRENT_STATE() == s_header_field) - header_field_mark = data; - if (CURRENT_STATE() == s_header_value) - header_value_mark = data; - switch (CURRENT_STATE()) { - case s_req_path: - case s_req_schema: - case s_req_schema_slash: - case s_req_schema_slash_slash: - case s_req_server_start: - case s_req_server: - case s_req_server_with_at: - case s_req_query_string_start: - case s_req_query_string: - case s_req_fragment_start: - case s_req_fragment: - url_mark = data; - break; - case s_res_status: - status_mark = data; - break; - default: - break; - } - - for (p=data; p != data + len; p++) { - ch = *p; - - if (PARSING_HEADER(CURRENT_STATE())) - COUNT_HEADER_SIZE(1); - -reexecute: - switch (CURRENT_STATE()) { - - case s_dead: - /* this state is used after a 'Connection: close' message - * the parser will error out if it reads another message - */ - if (LIKELY(ch == CR || ch == LF)) - break; - - SET_ERRNO(HPE_CLOSED_CONNECTION); - goto error; - - case s_start_req_or_res: - { - if (ch == CR || ch == LF) - break; - parser->flags = 0; - parser->content_length = ULLONG_MAX; - - if (ch == 'H') { - UPDATE_STATE(s_res_or_resp_H); - - CALLBACK_NOTIFY(message_begin); - } else { - parser->type = HTTP_REQUEST; - UPDATE_STATE(s_start_req); - REEXECUTE(); - } - - break; - } - - case s_res_or_resp_H: - if (ch == 'T') { - parser->type = HTTP_RESPONSE; - UPDATE_STATE(s_res_HT); - } else { - if (UNLIKELY(ch != 'E')) { - SET_ERRNO(HPE_INVALID_CONSTANT); - goto error; - } - - parser->type = HTTP_REQUEST; - parser->method = HTTP_HEAD; - parser->index = 2; - UPDATE_STATE(s_req_method); - } - break; - - case s_start_res: - { - parser->flags = 0; - parser->content_length = ULLONG_MAX; - - switch (ch) { - case 'H': - UPDATE_STATE(s_res_H); - break; - - case CR: - case LF: - break; - - default: - SET_ERRNO(HPE_INVALID_CONSTANT); - goto error; - } - - CALLBACK_NOTIFY(message_begin); - break; - } - - case s_res_H: - STRICT_CHECK(ch != 'T'); - UPDATE_STATE(s_res_HT); - break; - - case s_res_HT: - STRICT_CHECK(ch != 'T'); - UPDATE_STATE(s_res_HTT); - break; - - case s_res_HTT: - STRICT_CHECK(ch != 'P'); - UPDATE_STATE(s_res_HTTP); - break; - - case s_res_HTTP: - STRICT_CHECK(ch != '/'); - UPDATE_STATE(s_res_first_http_major); - break; - - case s_res_first_http_major: - if (UNLIKELY(ch < '0' || ch > '9')) { - SET_ERRNO(HPE_INVALID_VERSION); - goto error; - } - - parser->http_major = ch - '0'; - UPDATE_STATE(s_res_http_major); - break; - - /* major HTTP version or dot */ - case s_res_http_major: - { - if (ch == '.') { - UPDATE_STATE(s_res_first_http_minor); - break; - } - - if (!IS_NUM(ch)) { - SET_ERRNO(HPE_INVALID_VERSION); - goto error; - } - - parser->http_major *= 10; - parser->http_major += ch - '0'; - - if (UNLIKELY(parser->http_major > 999)) { - SET_ERRNO(HPE_INVALID_VERSION); - goto error; - } - - break; - } - - /* first digit of minor HTTP version */ - case s_res_first_http_minor: - if (UNLIKELY(!IS_NUM(ch))) { - SET_ERRNO(HPE_INVALID_VERSION); - goto error; - } - - parser->http_minor = ch - '0'; - UPDATE_STATE(s_res_http_minor); - break; - - /* minor HTTP version or end of request line */ - case s_res_http_minor: - { - if (ch == ' ') { - UPDATE_STATE(s_res_first_status_code); - break; - } - - if (UNLIKELY(!IS_NUM(ch))) { - SET_ERRNO(HPE_INVALID_VERSION); - goto error; - } - - parser->http_minor *= 10; - parser->http_minor += ch - '0'; - - if (UNLIKELY(parser->http_minor > 999)) { - SET_ERRNO(HPE_INVALID_VERSION); - goto error; - } - - break; - } - - case s_res_first_status_code: - { - if (!IS_NUM(ch)) { - if (ch == ' ') { - break; - } - - SET_ERRNO(HPE_INVALID_STATUS); - goto error; - } - parser->status_code = ch - '0'; - UPDATE_STATE(s_res_status_code); - break; - } - - case s_res_status_code: - { - if (!IS_NUM(ch)) { - switch (ch) { - case ' ': - UPDATE_STATE(s_res_status_start); - break; - case CR: - UPDATE_STATE(s_res_line_almost_done); - break; - case LF: - UPDATE_STATE(s_header_field_start); - break; - default: - SET_ERRNO(HPE_INVALID_STATUS); - goto error; - } - break; - } - - parser->status_code *= 10; - parser->status_code += ch - '0'; - - if (UNLIKELY(parser->status_code > 999)) { - SET_ERRNO(HPE_INVALID_STATUS); - goto error; - } - - break; - } - - case s_res_status_start: - { - if (ch == CR) { - UPDATE_STATE(s_res_line_almost_done); - break; - } - - if (ch == LF) { - UPDATE_STATE(s_header_field_start); - break; - } - - MARK(status); - UPDATE_STATE(s_res_status); - parser->index = 0; - break; - } - - case s_res_status: - if (ch == CR) { - UPDATE_STATE(s_res_line_almost_done); - CALLBACK_DATA(status); - break; - } - - if (ch == LF) { - UPDATE_STATE(s_header_field_start); - CALLBACK_DATA(status); - break; - } - - break; - - case s_res_line_almost_done: - STRICT_CHECK(ch != LF); - UPDATE_STATE(s_header_field_start); - break; - - case s_start_req: - { - if (ch == CR || ch == LF) - break; - parser->flags = 0; - parser->content_length = ULLONG_MAX; - - if (UNLIKELY(!IS_ALPHA(ch))) { - SET_ERRNO(HPE_INVALID_METHOD); - goto error; - } - - parser->method = (enum http_method) 0; - parser->index = 1; - switch (ch) { - case 'A': parser->method = HTTP_ACL; break; - case 'B': parser->method = HTTP_BIND; break; - case 'C': parser->method = HTTP_CONNECT; /* or COPY, CHECKOUT */ break; - case 'D': parser->method = HTTP_DELETE; break; - case 'G': parser->method = HTTP_GET; break; - case 'H': parser->method = HTTP_HEAD; break; - case 'L': parser->method = HTTP_LOCK; /* or LINK */ break; - case 'M': parser->method = HTTP_MKCOL; /* or MOVE, MKACTIVITY, MERGE, M-SEARCH, MKCALENDAR */ break; - case 'N': parser->method = HTTP_NOTIFY; break; - case 'O': parser->method = HTTP_OPTIONS; break; - case 'P': parser->method = HTTP_POST; - /* or PROPFIND|PROPPATCH|PUT|PATCH|PURGE */ - break; - case 'R': parser->method = HTTP_REPORT; /* or REBIND */ break; - case 'S': parser->method = HTTP_SUBSCRIBE; /* or SEARCH */ break; - case 'T': parser->method = HTTP_TRACE; break; - case 'U': parser->method = HTTP_UNLOCK; /* or UNSUBSCRIBE, UNBIND, UNLINK */ break; - default: - SET_ERRNO(HPE_INVALID_METHOD); - goto error; - } - UPDATE_STATE(s_req_method); - - CALLBACK_NOTIFY(message_begin); - - break; - } - - case s_req_method: - { - const char *matcher; - if (UNLIKELY(ch == '\0')) { - SET_ERRNO(HPE_INVALID_METHOD); - goto error; - } - - matcher = method_strings[parser->method]; - if (ch == ' ' && matcher[parser->index] == '\0') { - UPDATE_STATE(s_req_spaces_before_url); - } else if (ch == matcher[parser->index]) { - ; /* nada */ - } else if (IS_ALPHA(ch)) { - - switch (parser->method << 16 | parser->index << 8 | ch) { -#define XX(meth, pos, ch, new_meth) \ - case (HTTP_##meth << 16 | pos << 8 | ch): \ - parser->method = HTTP_##new_meth; break; - - XX(POST, 1, 'U', PUT) - XX(POST, 1, 'A', PATCH) - XX(CONNECT, 1, 'H', CHECKOUT) - XX(CONNECT, 2, 'P', COPY) - XX(MKCOL, 1, 'O', MOVE) - XX(MKCOL, 1, 'E', MERGE) - XX(MKCOL, 2, 'A', MKACTIVITY) - XX(MKCOL, 3, 'A', MKCALENDAR) - XX(SUBSCRIBE, 1, 'E', SEARCH) - XX(REPORT, 2, 'B', REBIND) - XX(POST, 1, 'R', PROPFIND) - XX(PROPFIND, 4, 'P', PROPPATCH) - XX(PUT, 2, 'R', PURGE) - XX(LOCK, 1, 'I', LINK) - XX(UNLOCK, 2, 'S', UNSUBSCRIBE) - XX(UNLOCK, 2, 'B', UNBIND) - XX(UNLOCK, 3, 'I', UNLINK) -#undef XX - - default: - SET_ERRNO(HPE_INVALID_METHOD); - goto error; - } - } else if (ch == '-' && - parser->index == 1 && - parser->method == HTTP_MKCOL) { - parser->method = HTTP_MSEARCH; - } else { - SET_ERRNO(HPE_INVALID_METHOD); - goto error; - } - - ++parser->index; - break; - } - - case s_req_spaces_before_url: - { - if (ch == ' ') break; - - MARK(url); - if (parser->method == HTTP_CONNECT) { - UPDATE_STATE(s_req_server_start); - } - - UPDATE_STATE(parse_url_char(CURRENT_STATE(), ch)); - if (UNLIKELY(CURRENT_STATE() == s_dead)) { - SET_ERRNO(HPE_INVALID_URL); - goto error; - } - - break; - } - - case s_req_schema: - case s_req_schema_slash: - case s_req_schema_slash_slash: - case s_req_server_start: - { - switch (ch) { - /* No whitespace allowed here */ - case ' ': - case CR: - case LF: - SET_ERRNO(HPE_INVALID_URL); - goto error; - default: - UPDATE_STATE(parse_url_char(CURRENT_STATE(), ch)); - if (UNLIKELY(CURRENT_STATE() == s_dead)) { - SET_ERRNO(HPE_INVALID_URL); - goto error; - } - } - - break; - } - - case s_req_server: - case s_req_server_with_at: - case s_req_path: - case s_req_query_string_start: - case s_req_query_string: - case s_req_fragment_start: - case s_req_fragment: - { - switch (ch) { - case ' ': - UPDATE_STATE(s_req_http_start); - CALLBACK_DATA(url); - break; - case CR: - case LF: - parser->http_major = 0; - parser->http_minor = 9; - UPDATE_STATE((ch == CR) ? - s_req_line_almost_done : - s_header_field_start); - CALLBACK_DATA(url); - break; - default: - UPDATE_STATE(parse_url_char(CURRENT_STATE(), ch)); - if (UNLIKELY(CURRENT_STATE() == s_dead)) { - SET_ERRNO(HPE_INVALID_URL); - goto error; - } - } - break; - } - - case s_req_http_start: - switch (ch) { - case 'H': - UPDATE_STATE(s_req_http_H); - break; - case ' ': - break; - default: - SET_ERRNO(HPE_INVALID_CONSTANT); - goto error; - } - break; - - case s_req_http_H: - STRICT_CHECK(ch != 'T'); - UPDATE_STATE(s_req_http_HT); - break; - - case s_req_http_HT: - STRICT_CHECK(ch != 'T'); - UPDATE_STATE(s_req_http_HTT); - break; - - case s_req_http_HTT: - STRICT_CHECK(ch != 'P'); - UPDATE_STATE(s_req_http_HTTP); - break; - - case s_req_http_HTTP: - STRICT_CHECK(ch != '/'); - UPDATE_STATE(s_req_first_http_major); - break; - - /* first digit of major HTTP version */ - case s_req_first_http_major: - if (UNLIKELY(ch < '1' || ch > '9')) { - SET_ERRNO(HPE_INVALID_VERSION); - goto error; - } - - parser->http_major = ch - '0'; - UPDATE_STATE(s_req_http_major); - break; - - /* major HTTP version or dot */ - case s_req_http_major: - { - if (ch == '.') { - UPDATE_STATE(s_req_first_http_minor); - break; - } - - if (UNLIKELY(!IS_NUM(ch))) { - SET_ERRNO(HPE_INVALID_VERSION); - goto error; - } - - parser->http_major *= 10; - parser->http_major += ch - '0'; - - if (UNLIKELY(parser->http_major > 999)) { - SET_ERRNO(HPE_INVALID_VERSION); - goto error; - } - - break; - } - - /* first digit of minor HTTP version */ - case s_req_first_http_minor: - if (UNLIKELY(!IS_NUM(ch))) { - SET_ERRNO(HPE_INVALID_VERSION); - goto error; - } - - parser->http_minor = ch - '0'; - UPDATE_STATE(s_req_http_minor); - break; - - /* minor HTTP version or end of request line */ - case s_req_http_minor: - { - if (ch == CR) { - UPDATE_STATE(s_req_line_almost_done); - break; - } - - if (ch == LF) { - UPDATE_STATE(s_header_field_start); - break; - } - - /* XXX allow spaces after digit? */ - - if (UNLIKELY(!IS_NUM(ch))) { - SET_ERRNO(HPE_INVALID_VERSION); - goto error; - } - - parser->http_minor *= 10; - parser->http_minor += ch - '0'; - - if (UNLIKELY(parser->http_minor > 999)) { - SET_ERRNO(HPE_INVALID_VERSION); - goto error; - } - - break; - } - - /* end of request line */ - case s_req_line_almost_done: - { - if (UNLIKELY(ch != LF)) { - SET_ERRNO(HPE_LF_EXPECTED); - goto error; - } - - UPDATE_STATE(s_header_field_start); - break; - } - - case s_header_field_start: - { - if (ch == CR) { - UPDATE_STATE(s_headers_almost_done); - break; - } - - if (ch == LF) { - /* they might be just sending \n instead of \r\n so this would be - * the second \n to denote the end of headers*/ - UPDATE_STATE(s_headers_almost_done); - REEXECUTE(); - } - - c = TOKEN(ch); - - if (UNLIKELY(!c)) { - SET_ERRNO(HPE_INVALID_HEADER_TOKEN); - goto error; - } - - MARK(header_field); - - parser->index = 0; - UPDATE_STATE(s_header_field); - - switch (c) { - case 'c': - parser->header_state = h_C; - break; - - case 'p': - parser->header_state = h_matching_proxy_connection; - break; - - case 't': - parser->header_state = h_matching_transfer_encoding; - break; - - case 'u': - parser->header_state = h_matching_upgrade; - break; - - default: - parser->header_state = h_general; - break; - } - break; - } - - case s_header_field: - { - const char* start = p; - for (; p != data + len; p++) { - ch = *p; - c = TOKEN(ch); - - if (!c) - break; - - switch (parser->header_state) { - case h_general: - break; - - case h_C: - parser->index++; - parser->header_state = (c == 'o' ? h_CO : h_general); - break; - - case h_CO: - parser->index++; - parser->header_state = (c == 'n' ? h_CON : h_general); - break; - - case h_CON: - parser->index++; - switch (c) { - case 'n': - parser->header_state = h_matching_connection; - break; - case 't': - parser->header_state = h_matching_content_length; - break; - default: - parser->header_state = h_general; - break; - } - break; - - /* connection */ - - case h_matching_connection: - parser->index++; - if (parser->index > sizeof(CONNECTION)-1 - || c != CONNECTION[parser->index]) { - parser->header_state = h_general; - } else if (parser->index == sizeof(CONNECTION)-2) { - parser->header_state = h_connection; - } - break; - - /* proxy-connection */ - - case h_matching_proxy_connection: - parser->index++; - if (parser->index > sizeof(PROXY_CONNECTION)-1 - || c != PROXY_CONNECTION[parser->index]) { - parser->header_state = h_general; - } else if (parser->index == sizeof(PROXY_CONNECTION)-2) { - parser->header_state = h_connection; - } - break; - - /* content-length */ - - case h_matching_content_length: - parser->index++; - if (parser->index > sizeof(CONTENT_LENGTH)-1 - || c != CONTENT_LENGTH[parser->index]) { - parser->header_state = h_general; - } else if (parser->index == sizeof(CONTENT_LENGTH)-2) { - if (parser->flags & F_CONTENTLENGTH) { - SET_ERRNO(HPE_UNEXPECTED_CONTENT_LENGTH); - goto error; - } - parser->header_state = h_content_length; - parser->flags |= F_CONTENTLENGTH; - } - break; - - /* transfer-encoding */ - - case h_matching_transfer_encoding: - parser->index++; - if (parser->index > sizeof(TRANSFER_ENCODING)-1 - || c != TRANSFER_ENCODING[parser->index]) { - parser->header_state = h_general; - } else if (parser->index == sizeof(TRANSFER_ENCODING)-2) { - parser->header_state = h_transfer_encoding; - } - break; - - /* upgrade */ - - case h_matching_upgrade: - parser->index++; - if (parser->index > sizeof(UPGRADE)-1 - || c != UPGRADE[parser->index]) { - parser->header_state = h_general; - } else if (parser->index == sizeof(UPGRADE)-2) { - parser->header_state = h_upgrade; - } - break; - - case h_connection: - case h_content_length: - case h_transfer_encoding: - case h_upgrade: - if (ch != ' ') parser->header_state = h_general; - break; - - default: - assert(0 && "Unknown header_state"); - break; - } - } - - COUNT_HEADER_SIZE(p - start); - - if (p == data + len) { - --p; - break; - } - - if (ch == ':') { - UPDATE_STATE(s_header_value_discard_ws); - CALLBACK_DATA(header_field); - break; - } - - SET_ERRNO(HPE_INVALID_HEADER_TOKEN); - goto error; - } - - case s_header_value_discard_ws: - if (ch == ' ' || ch == '\t') break; - - if (ch == CR) { - UPDATE_STATE(s_header_value_discard_ws_almost_done); - break; - } - - if (ch == LF) { - UPDATE_STATE(s_header_value_discard_lws); - break; - } - - /* FALLTHROUGH */ - - case s_header_value_start: - { - MARK(header_value); - - UPDATE_STATE(s_header_value); - parser->index = 0; - - c = LOWER(ch); - - switch (parser->header_state) { - case h_upgrade: - parser->flags |= F_UPGRADE; - parser->header_state = h_general; - break; - - case h_transfer_encoding: - /* looking for 'Transfer-Encoding: chunked' */ - if ('c' == c) { - parser->header_state = h_matching_transfer_encoding_chunked; - } else { - parser->header_state = h_general; - } - break; - - case h_content_length: - if (UNLIKELY(!IS_NUM(ch))) { - SET_ERRNO(HPE_INVALID_CONTENT_LENGTH); - goto error; - } - - parser->content_length = ch - '0'; - break; - - case h_connection: - /* looking for 'Connection: keep-alive' */ - if (c == 'k') { - parser->header_state = h_matching_connection_keep_alive; - /* looking for 'Connection: close' */ - } else if (c == 'c') { - parser->header_state = h_matching_connection_close; - } else if (c == 'u') { - parser->header_state = h_matching_connection_upgrade; - } else { - parser->header_state = h_matching_connection_token; - } - break; - - /* Multi-value `Connection` header */ - case h_matching_connection_token_start: - break; - - default: - parser->header_state = h_general; - break; - } - break; - } - - case s_header_value: - { - const char* start = p; - enum header_states h_state = (enum header_states) parser->header_state; - for (; p != data + len; p++) { - ch = *p; - if (ch == CR) { - UPDATE_STATE(s_header_almost_done); - parser->header_state = h_state; - CALLBACK_DATA(header_value); - break; - } - - if (ch == LF) { - UPDATE_STATE(s_header_almost_done); - COUNT_HEADER_SIZE(p - start); - parser->header_state = h_state; - CALLBACK_DATA_NOADVANCE(header_value); - REEXECUTE(); - } - - if (!lenient && !IS_HEADER_CHAR(ch)) { - SET_ERRNO(HPE_INVALID_HEADER_TOKEN); - goto error; - } - - c = LOWER(ch); - - switch (h_state) { - case h_general: - { - const char* p_cr; - const char* p_lf; - size_t limit = data + len - p; - - limit = MIN(limit, HTTP_MAX_HEADER_SIZE); - - p_cr = (const char*) memchr(p, CR, limit); - p_lf = (const char*) memchr(p, LF, limit); - if (p_cr != NULL) { - if (p_lf != NULL && p_cr >= p_lf) - p = p_lf; - else - p = p_cr; - } else if (UNLIKELY(p_lf != NULL)) { - p = p_lf; - } else { - p = data + len; - } - --p; - - break; - } - - case h_connection: - case h_transfer_encoding: - assert(0 && "Shouldn't get here."); - break; - - case h_content_length: - { - uint64_t t; - - if (ch == ' ') break; - - if (UNLIKELY(!IS_NUM(ch))) { - SET_ERRNO(HPE_INVALID_CONTENT_LENGTH); - parser->header_state = h_state; - goto error; - } - - t = parser->content_length; - t *= 10; - t += ch - '0'; - - /* Overflow? Test against a conservative limit for simplicity. */ - if (UNLIKELY((ULLONG_MAX - 10) / 10 < parser->content_length)) { - SET_ERRNO(HPE_INVALID_CONTENT_LENGTH); - parser->header_state = h_state; - goto error; - } - - parser->content_length = t; - break; - } - - /* Transfer-Encoding: chunked */ - case h_matching_transfer_encoding_chunked: - parser->index++; - if (parser->index > sizeof(CHUNKED)-1 - || c != CHUNKED[parser->index]) { - h_state = h_general; - } else if (parser->index == sizeof(CHUNKED)-2) { - h_state = h_transfer_encoding_chunked; - } - break; - - case h_matching_connection_token_start: - /* looking for 'Connection: keep-alive' */ - if (c == 'k') { - h_state = h_matching_connection_keep_alive; - /* looking for 'Connection: close' */ - } else if (c == 'c') { - h_state = h_matching_connection_close; - } else if (c == 'u') { - h_state = h_matching_connection_upgrade; - } else if (STRICT_TOKEN(c)) { - h_state = h_matching_connection_token; - } else if (c == ' ' || c == '\t') { - /* Skip lws */ - } else { - h_state = h_general; - } - break; - - /* looking for 'Connection: keep-alive' */ - case h_matching_connection_keep_alive: - parser->index++; - if (parser->index > sizeof(KEEP_ALIVE)-1 - || c != KEEP_ALIVE[parser->index]) { - h_state = h_matching_connection_token; - } else if (parser->index == sizeof(KEEP_ALIVE)-2) { - h_state = h_connection_keep_alive; - } - break; - - /* looking for 'Connection: close' */ - case h_matching_connection_close: - parser->index++; - if (parser->index > sizeof(CLOSE)-1 || c != CLOSE[parser->index]) { - h_state = h_matching_connection_token; - } else if (parser->index == sizeof(CLOSE)-2) { - h_state = h_connection_close; - } - break; - - /* looking for 'Connection: upgrade' */ - case h_matching_connection_upgrade: - parser->index++; - if (parser->index > sizeof(UPGRADE) - 1 || - c != UPGRADE[parser->index]) { - h_state = h_matching_connection_token; - } else if (parser->index == sizeof(UPGRADE)-2) { - h_state = h_connection_upgrade; - } - break; - - case h_matching_connection_token: - if (ch == ',') { - h_state = h_matching_connection_token_start; - parser->index = 0; - } - break; - - case h_transfer_encoding_chunked: - if (ch != ' ') h_state = h_general; - break; - - case h_connection_keep_alive: - case h_connection_close: - case h_connection_upgrade: - if (ch == ',') { - if (h_state == h_connection_keep_alive) { - parser->flags |= F_CONNECTION_KEEP_ALIVE; - } else if (h_state == h_connection_close) { - parser->flags |= F_CONNECTION_CLOSE; - } else if (h_state == h_connection_upgrade) { - parser->flags |= F_CONNECTION_UPGRADE; - } - h_state = h_matching_connection_token_start; - parser->index = 0; - } else if (ch != ' ') { - h_state = h_matching_connection_token; - } - break; - - default: - UPDATE_STATE(s_header_value); - h_state = h_general; - break; - } - } - parser->header_state = h_state; - - COUNT_HEADER_SIZE(p - start); - - if (p == data + len) - --p; - break; - } - - case s_header_almost_done: - { - if (UNLIKELY(ch != LF)) { - SET_ERRNO(HPE_LF_EXPECTED); - goto error; - } - - UPDATE_STATE(s_header_value_lws); - break; - } - - case s_header_value_lws: - { - if (ch == ' ' || ch == '\t') { - UPDATE_STATE(s_header_value_start); - REEXECUTE(); - } - - /* finished the header */ - switch (parser->header_state) { - case h_connection_keep_alive: - parser->flags |= F_CONNECTION_KEEP_ALIVE; - break; - case h_connection_close: - parser->flags |= F_CONNECTION_CLOSE; - break; - case h_transfer_encoding_chunked: - parser->flags |= F_CHUNKED; - break; - case h_connection_upgrade: - parser->flags |= F_CONNECTION_UPGRADE; - break; - default: - break; - } - - UPDATE_STATE(s_header_field_start); - REEXECUTE(); - } - - case s_header_value_discard_ws_almost_done: - { - STRICT_CHECK(ch != LF); - UPDATE_STATE(s_header_value_discard_lws); - break; - } - - case s_header_value_discard_lws: - { - if (ch == ' ' || ch == '\t') { - UPDATE_STATE(s_header_value_discard_ws); - break; - } else { - switch (parser->header_state) { - case h_connection_keep_alive: - parser->flags |= F_CONNECTION_KEEP_ALIVE; - break; - case h_connection_close: - parser->flags |= F_CONNECTION_CLOSE; - break; - case h_connection_upgrade: - parser->flags |= F_CONNECTION_UPGRADE; - break; - case h_transfer_encoding_chunked: - parser->flags |= F_CHUNKED; - break; - default: - break; - } - - /* header value was empty */ - MARK(header_value); - UPDATE_STATE(s_header_field_start); - CALLBACK_DATA_NOADVANCE(header_value); - REEXECUTE(); - } - } - - case s_headers_almost_done: - { - STRICT_CHECK(ch != LF); - - if (parser->flags & F_TRAILING) { - /* End of a chunked request */ - UPDATE_STATE(s_message_done); - CALLBACK_NOTIFY_NOADVANCE(chunk_complete); - REEXECUTE(); - } - - /* Cannot use chunked encoding and a content-length header together - per the HTTP specification. */ - if ((parser->flags & F_CHUNKED) && - (parser->flags & F_CONTENTLENGTH)) { - SET_ERRNO(HPE_UNEXPECTED_CONTENT_LENGTH); - goto error; - } - - UPDATE_STATE(s_headers_done); - - /* Set this here so that on_headers_complete() callbacks can see it */ - parser->upgrade = - ((parser->flags & (F_UPGRADE | F_CONNECTION_UPGRADE)) == - (F_UPGRADE | F_CONNECTION_UPGRADE) || - parser->method == HTTP_CONNECT); - - /* Here we call the headers_complete callback. This is somewhat - * different than other callbacks because if the user returns 1, we - * will interpret that as saying that this message has no body. This - * is needed for the annoying case of recieving a response to a HEAD - * request. - * - * We'd like to use CALLBACK_NOTIFY_NOADVANCE() here but we cannot, so - * we have to simulate it by handling a change in errno below. - */ - if (settings->on_headers_complete) { - switch (settings->on_headers_complete(parser)) { - case 0: - break; - - case 2: - parser->upgrade = 1; - - case 1: - parser->flags |= F_SKIPBODY; - break; - - default: - SET_ERRNO(HPE_CB_headers_complete); - RETURN(p - data); /* Error */ - } - } - - if (HTTP_PARSER_ERRNO(parser) != HPE_OK) { - RETURN(p - data); - } - - REEXECUTE(); - } - - case s_headers_done: - { - int hasBody; - STRICT_CHECK(ch != LF); - - parser->nread = 0; - - hasBody = parser->flags & F_CHUNKED || - (parser->content_length > 0 && parser->content_length != ULLONG_MAX); - if (parser->upgrade && (parser->method == HTTP_CONNECT || - (parser->flags & F_SKIPBODY) || !hasBody)) { - /* Exit, the rest of the message is in a different protocol. */ - UPDATE_STATE(NEW_MESSAGE()); - CALLBACK_NOTIFY(message_complete); - RETURN((p - data) + 1); - } - - if (parser->flags & F_SKIPBODY) { - UPDATE_STATE(NEW_MESSAGE()); - CALLBACK_NOTIFY(message_complete); - } else if (parser->flags & F_CHUNKED) { - /* chunked encoding - ignore Content-Length header */ - UPDATE_STATE(s_chunk_size_start); - } else { - if (parser->content_length == 0) { - /* Content-Length header given but zero: Content-Length: 0\r\n */ - UPDATE_STATE(NEW_MESSAGE()); - CALLBACK_NOTIFY(message_complete); - } else if (parser->content_length != ULLONG_MAX) { - /* Content-Length header given and non-zero */ - UPDATE_STATE(s_body_identity); - } else { - if (!http_message_needs_eof(parser)) { - /* Assume content-length 0 - read the next */ - UPDATE_STATE(NEW_MESSAGE()); - CALLBACK_NOTIFY(message_complete); - } else { - /* Read body until EOF */ - UPDATE_STATE(s_body_identity_eof); - } - } - } - - break; - } - - case s_body_identity: - { - uint64_t to_read = MIN(parser->content_length, - (uint64_t) ((data + len) - p)); - - assert(parser->content_length != 0 - && parser->content_length != ULLONG_MAX); - - /* The difference between advancing content_length and p is because - * the latter will automaticaly advance on the next loop iteration. - * Further, if content_length ends up at 0, we want to see the last - * byte again for our message complete callback. - */ - MARK(body); - parser->content_length -= to_read; - p += to_read - 1; - - if (parser->content_length == 0) { - UPDATE_STATE(s_message_done); - - /* Mimic CALLBACK_DATA_NOADVANCE() but with one extra byte. - * - * The alternative to doing this is to wait for the next byte to - * trigger the data callback, just as in every other case. The - * problem with this is that this makes it difficult for the test - * harness to distinguish between complete-on-EOF and - * complete-on-length. It's not clear that this distinction is - * important for applications, but let's keep it for now. - */ - CALLBACK_DATA_(body, p - body_mark + 1, p - data); - REEXECUTE(); - } - - break; - } - - /* read until EOF */ - case s_body_identity_eof: - MARK(body); - p = data + len - 1; - - break; - - case s_message_done: - UPDATE_STATE(NEW_MESSAGE()); - CALLBACK_NOTIFY(message_complete); - if (parser->upgrade) { - /* Exit, the rest of the message is in a different protocol. */ - RETURN((p - data) + 1); - } - break; - - case s_chunk_size_start: - { - assert(parser->nread == 1); - assert(parser->flags & F_CHUNKED); - - unhex_val = unhex[(unsigned char)ch]; - if (UNLIKELY(unhex_val == -1)) { - SET_ERRNO(HPE_INVALID_CHUNK_SIZE); - goto error; - } - - parser->content_length = unhex_val; - UPDATE_STATE(s_chunk_size); - break; - } - - case s_chunk_size: - { - uint64_t t; - - assert(parser->flags & F_CHUNKED); - - if (ch == CR) { - UPDATE_STATE(s_chunk_size_almost_done); - break; - } - - unhex_val = unhex[(unsigned char)ch]; - - if (unhex_val == -1) { - if (ch == ';' || ch == ' ') { - UPDATE_STATE(s_chunk_parameters); - break; - } - - SET_ERRNO(HPE_INVALID_CHUNK_SIZE); - goto error; - } - - t = parser->content_length; - t *= 16; - t += unhex_val; - - /* Overflow? Test against a conservative limit for simplicity. */ - if (UNLIKELY((ULLONG_MAX - 16) / 16 < parser->content_length)) { - SET_ERRNO(HPE_INVALID_CONTENT_LENGTH); - goto error; - } - - parser->content_length = t; - break; - } - - case s_chunk_parameters: - { - assert(parser->flags & F_CHUNKED); - /* just ignore this shit. TODO check for overflow */ - if (ch == CR) { - UPDATE_STATE(s_chunk_size_almost_done); - break; - } - break; - } - - case s_chunk_size_almost_done: - { - assert(parser->flags & F_CHUNKED); - STRICT_CHECK(ch != LF); - - parser->nread = 0; - - if (parser->content_length == 0) { - parser->flags |= F_TRAILING; - UPDATE_STATE(s_header_field_start); - } else { - UPDATE_STATE(s_chunk_data); - } - CALLBACK_NOTIFY(chunk_header); - break; - } - - case s_chunk_data: - { - uint64_t to_read = MIN(parser->content_length, - (uint64_t) ((data + len) - p)); - - assert(parser->flags & F_CHUNKED); - assert(parser->content_length != 0 - && parser->content_length != ULLONG_MAX); - - /* See the explanation in s_body_identity for why the content - * length and data pointers are managed this way. - */ - MARK(body); - parser->content_length -= to_read; - p += to_read - 1; - - if (parser->content_length == 0) { - UPDATE_STATE(s_chunk_data_almost_done); - } - - break; - } - - case s_chunk_data_almost_done: - assert(parser->flags & F_CHUNKED); - assert(parser->content_length == 0); - STRICT_CHECK(ch != CR); - UPDATE_STATE(s_chunk_data_done); - CALLBACK_DATA(body); - break; - - case s_chunk_data_done: - assert(parser->flags & F_CHUNKED); - STRICT_CHECK(ch != LF); - parser->nread = 0; - UPDATE_STATE(s_chunk_size_start); - CALLBACK_NOTIFY(chunk_complete); - break; - - default: - assert(0 && "unhandled state"); - SET_ERRNO(HPE_INVALID_INTERNAL_STATE); - goto error; - } - } - - /* Run callbacks for any marks that we have leftover after we ran our of - * bytes. There should be at most one of these set, so it's OK to invoke - * them in series (unset marks will not result in callbacks). - * - * We use the NOADVANCE() variety of callbacks here because 'p' has already - * overflowed 'data' and this allows us to correct for the off-by-one that - * we'd otherwise have (since CALLBACK_DATA() is meant to be run with a 'p' - * value that's in-bounds). - */ - - assert(((header_field_mark ? 1 : 0) + - (header_value_mark ? 1 : 0) + - (url_mark ? 1 : 0) + - (body_mark ? 1 : 0) + - (status_mark ? 1 : 0)) <= 1); - - CALLBACK_DATA_NOADVANCE(header_field); - CALLBACK_DATA_NOADVANCE(header_value); - CALLBACK_DATA_NOADVANCE(url); - CALLBACK_DATA_NOADVANCE(body); - CALLBACK_DATA_NOADVANCE(status); - - RETURN(len); - -error: - if (HTTP_PARSER_ERRNO(parser) == HPE_OK) { - SET_ERRNO(HPE_UNKNOWN); - } - - RETURN(p - data); -} - - -/* Does the parser need to see an EOF to find the end of the message? */ -int -http_message_needs_eof (const http_parser *parser) -{ - if (parser->type == HTTP_REQUEST) { - return 0; - } - - /* See RFC 2616 section 4.4 */ - if (parser->status_code / 100 == 1 || /* 1xx e.g. Continue */ - parser->status_code == 204 || /* No Content */ - parser->status_code == 304 || /* Not Modified */ - parser->flags & F_SKIPBODY) { /* response to a HEAD request */ - return 0; - } - - if ((parser->flags & F_CHUNKED) || parser->content_length != ULLONG_MAX) { - return 0; - } - - return 1; -} - - -int -http_should_keep_alive (const http_parser *parser) -{ - if (parser->http_major > 0 && parser->http_minor > 0) { - /* HTTP/1.1 */ - if (parser->flags & F_CONNECTION_CLOSE) { - return 0; - } - } else { - /* HTTP/1.0 or earlier */ - if (!(parser->flags & F_CONNECTION_KEEP_ALIVE)) { - return 0; - } - } - - return !http_message_needs_eof(parser); -} - - -const char * -http_method_str (enum http_method m) -{ - return ELEM_AT(method_strings, m, ""); -} - - -void -http_parser_init (http_parser *parser, enum http_parser_type t) -{ - void *data = parser->data; /* preserve application data */ - memset(parser, 0, sizeof(*parser)); - parser->data = data; - parser->type = t; - parser->state = (t == HTTP_REQUEST ? s_start_req : (t == HTTP_RESPONSE ? s_start_res : s_start_req_or_res)); - parser->http_errno = HPE_OK; -} - -void -http_parser_settings_init(http_parser_settings *settings) -{ - memset(settings, 0, sizeof(*settings)); -} - -const char * -http_errno_name(enum http_errno err) { - assert(((size_t) err) < ARRAY_SIZE(http_strerror_tab)); - return http_strerror_tab[err].name; -} - -const char * -http_errno_description(enum http_errno err) { - assert(((size_t) err) < ARRAY_SIZE(http_strerror_tab)); - return http_strerror_tab[err].description; -} - -static enum http_host_state -http_parse_host_char(enum http_host_state s, const char ch) { - switch(s) { - case s_http_userinfo: - case s_http_userinfo_start: - if (ch == '@') { - return s_http_host_start; - } - - if (IS_USERINFO_CHAR(ch)) { - return s_http_userinfo; - } - break; - - case s_http_host_start: - if (ch == '[') { - return s_http_host_v6_start; - } - - if (IS_HOST_CHAR(ch)) { - return s_http_host; - } - - break; - - case s_http_host: - if (IS_HOST_CHAR(ch)) { - return s_http_host; - } - - /* FALLTHROUGH */ - case s_http_host_v6_end: - if (ch == ':') { - return s_http_host_port_start; - } - - break; - - case s_http_host_v6: - if (ch == ']') { - return s_http_host_v6_end; - } - - /* FALLTHROUGH */ - case s_http_host_v6_start: - if (IS_HEX(ch) || ch == ':' || ch == '.') { - return s_http_host_v6; - } - - if (s == s_http_host_v6 && ch == '%') { - return s_http_host_v6_zone_start; - } - break; - - case s_http_host_v6_zone: - if (ch == ']') { - return s_http_host_v6_end; - } - - /* FALLTHROUGH */ - case s_http_host_v6_zone_start: - /* RFC 6874 Zone ID consists of 1*( unreserved / pct-encoded) */ - if (IS_ALPHANUM(ch) || ch == '%' || ch == '.' || ch == '-' || ch == '_' || - ch == '~') { - return s_http_host_v6_zone; - } - break; - - case s_http_host_port: - case s_http_host_port_start: - if (IS_NUM(ch)) { - return s_http_host_port; - } - - break; - - default: - break; - } - return s_http_host_dead; -} - -static int -http_parse_host(const char * buf, struct http_parser_url *u, int found_at) { - assert(u->field_set & (1 << UF_HOST)); - enum http_host_state s; - - const char *p; - size_t buflen = u->field_data[UF_HOST].off + u->field_data[UF_HOST].len; - - u->field_data[UF_HOST].len = 0; - - s = found_at ? s_http_userinfo_start : s_http_host_start; - - for (p = buf + u->field_data[UF_HOST].off; p < buf + buflen; p++) { - enum http_host_state new_s = http_parse_host_char(s, *p); - - if (new_s == s_http_host_dead) { - return 1; - } - - switch(new_s) { - case s_http_host: - if (s != s_http_host) { - u->field_data[UF_HOST].off = p - buf; - } - u->field_data[UF_HOST].len++; - break; - - case s_http_host_v6: - if (s != s_http_host_v6) { - u->field_data[UF_HOST].off = p - buf; - } - u->field_data[UF_HOST].len++; - break; - - case s_http_host_v6_zone_start: - case s_http_host_v6_zone: - u->field_data[UF_HOST].len++; - break; - - case s_http_host_port: - if (s != s_http_host_port) { - u->field_data[UF_PORT].off = p - buf; - u->field_data[UF_PORT].len = 0; - u->field_set |= (1 << UF_PORT); - } - u->field_data[UF_PORT].len++; - break; - - case s_http_userinfo: - if (s != s_http_userinfo) { - u->field_data[UF_USERINFO].off = p - buf ; - u->field_data[UF_USERINFO].len = 0; - u->field_set |= (1 << UF_USERINFO); - } - u->field_data[UF_USERINFO].len++; - break; - - default: - break; - } - s = new_s; - } - - /* Make sure we don't end somewhere unexpected */ - switch (s) { - case s_http_host_start: - case s_http_host_v6_start: - case s_http_host_v6: - case s_http_host_v6_zone_start: - case s_http_host_v6_zone: - case s_http_host_port_start: - case s_http_userinfo: - case s_http_userinfo_start: - return 1; - default: - break; - } - - return 0; -} - -void -http_parser_url_init(struct http_parser_url *u) { - memset(u, 0, sizeof(*u)); -} - -int -http_parser_parse_url(const char *buf, size_t buflen, int is_connect, - struct http_parser_url *u) -{ - enum state s; - const char *p; - enum http_parser_url_fields uf, old_uf; - int found_at = 0; - - u->port = u->field_set = 0; - s = is_connect ? s_req_server_start : s_req_spaces_before_url; - old_uf = UF_MAX; - - for (p = buf; p < buf + buflen; p++) { - s = parse_url_char(s, *p); - - /* Figure out the next field that we're operating on */ - switch (s) { - case s_dead: - return 1; - - /* Skip delimeters */ - case s_req_schema_slash: - case s_req_schema_slash_slash: - case s_req_server_start: - case s_req_query_string_start: - case s_req_fragment_start: - continue; - - case s_req_schema: - uf = UF_SCHEMA; - break; - - case s_req_server_with_at: - found_at = 1; - - /* FALLTROUGH */ - case s_req_server: - uf = UF_HOST; - break; - - case s_req_path: - uf = UF_PATH; - break; - - case s_req_query_string: - uf = UF_QUERY; - break; - - case s_req_fragment: - uf = UF_FRAGMENT; - break; - - default: - assert(!"Unexpected state"); - return 1; - } - - /* Nothing's changed; soldier on */ - if (uf == old_uf) { - u->field_data[uf].len++; - continue; - } - - u->field_data[uf].off = p - buf; - u->field_data[uf].len = 1; - - u->field_set |= (1 << uf); - old_uf = uf; - } - - /* host must be present if there is a schema */ - /* parsing http:///toto will fail */ - if ((u->field_set & (1 << UF_SCHEMA)) && - (u->field_set & (1 << UF_HOST)) == 0) { - return 1; - } - - if (u->field_set & (1 << UF_HOST)) { - if (http_parse_host(buf, u, found_at) != 0) { - return 1; - } - } - - /* CONNECT requests can only contain "hostname:port" */ - if (is_connect && u->field_set != ((1 << UF_HOST)|(1 << UF_PORT))) { - return 1; - } - - if (u->field_set & (1 << UF_PORT)) { - /* Don't bother with endp; we've already validated the string */ - unsigned long v = strtoul(buf + u->field_data[UF_PORT].off, NULL, 10); - - /* Ports have a max value of 2^16 */ - if (v > 0xffff) { - return 1; - } - - u->port = (uint16_t) v; - } - - return 0; -} - -void -http_parser_pause(http_parser *parser, int paused) { - /* Users should only be pausing/unpausing a parser that is not in an error - * state. In non-debug builds, there's not much that we can do about this - * other than ignore it. - */ - if (HTTP_PARSER_ERRNO(parser) == HPE_OK || - HTTP_PARSER_ERRNO(parser) == HPE_PAUSED) { - SET_ERRNO((paused) ? HPE_PAUSED : HPE_OK); - } else { - assert(0 && "Attempting to pause parser in error state"); - } -} - -int -http_body_is_final(const struct http_parser *parser) { - return parser->state == s_message_done; -} - -unsigned long -http_parser_version(void) { - return HTTP_PARSER_VERSION_MAJOR * 0x10000 | - HTTP_PARSER_VERSION_MINOR * 0x00100 | - HTTP_PARSER_VERSION_PATCH * 0x00001; -} diff --git a/src/beast/test/benchmarks/nodejs-parser/http_parser.h b/src/beast/test/benchmarks/nodejs-parser/http_parser.h deleted file mode 100644 index 105ae510a8a..00000000000 --- a/src/beast/test/benchmarks/nodejs-parser/http_parser.h +++ /dev/null @@ -1,362 +0,0 @@ -/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ -#ifndef http_parser_h -#define http_parser_h -#ifdef __cplusplus -extern "C" { -#endif - -/* Also update SONAME in the Makefile whenever you change these. */ -#define HTTP_PARSER_VERSION_MAJOR 2 -#define HTTP_PARSER_VERSION_MINOR 7 -#define HTTP_PARSER_VERSION_PATCH 0 - -#include -#if defined(_WIN32) && !defined(__MINGW32__) && \ - (!defined(_MSC_VER) || _MSC_VER<1600) && !defined(__WINE__) -#include -#include -typedef __int8 int8_t; -typedef unsigned __int8 uint8_t; -typedef __int16 int16_t; -typedef unsigned __int16 uint16_t; -typedef __int32 int32_t; -typedef unsigned __int32 uint32_t; -typedef __int64 int64_t; -typedef unsigned __int64 uint64_t; -#else -#include -#endif - -/* Compile with -DHTTP_PARSER_STRICT=0 to make less checks, but run - * faster - */ -#ifndef HTTP_PARSER_STRICT -# define HTTP_PARSER_STRICT 1 -#endif - -/* Maximium header size allowed. If the macro is not defined - * before including this header then the default is used. To - * change the maximum header size, define the macro in the build - * environment (e.g. -DHTTP_MAX_HEADER_SIZE=). To remove - * the effective limit on the size of the header, define the macro - * to a very large number (e.g. -DHTTP_MAX_HEADER_SIZE=0x7fffffff) - */ -#ifndef HTTP_MAX_HEADER_SIZE -# define HTTP_MAX_HEADER_SIZE (80*1024) -#endif - -typedef struct http_parser http_parser; -typedef struct http_parser_settings http_parser_settings; - - -/* Callbacks should return non-zero to indicate an error. The parser will - * then halt execution. - * - * The one exception is on_headers_complete. In a HTTP_RESPONSE parser - * returning '1' from on_headers_complete will tell the parser that it - * should not expect a body. This is used when receiving a response to a - * HEAD request which may contain 'Content-Length' or 'Transfer-Encoding: - * chunked' headers that indicate the presence of a body. - * - * Returning `2` from on_headers_complete will tell parser that it should not - * expect neither a body nor any futher responses on this connection. This is - * useful for handling responses to a CONNECT request which may not contain - * `Upgrade` or `Connection: upgrade` headers. - * - * http_data_cb does not return data chunks. It will be called arbitrarily - * many times for each string. E.G. you might get 10 callbacks for "on_url" - * each providing just a few characters more data. - */ -typedef int (*http_data_cb) (http_parser*, const char *at, size_t length); -typedef int (*http_cb) (http_parser*); - - -/* Request Methods */ -#define HTTP_METHOD_MAP(XX) \ - XX(0, DELETE, DELETE) \ - XX(1, GET, GET) \ - XX(2, HEAD, HEAD) \ - XX(3, POST, POST) \ - XX(4, PUT, PUT) \ - /* pathological */ \ - XX(5, CONNECT, CONNECT) \ - XX(6, OPTIONS, OPTIONS) \ - XX(7, TRACE, TRACE) \ - /* WebDAV */ \ - XX(8, COPY, COPY) \ - XX(9, LOCK, LOCK) \ - XX(10, MKCOL, MKCOL) \ - XX(11, MOVE, MOVE) \ - XX(12, PROPFIND, PROPFIND) \ - XX(13, PROPPATCH, PROPPATCH) \ - XX(14, SEARCH, SEARCH) \ - XX(15, UNLOCK, UNLOCK) \ - XX(16, BIND, BIND) \ - XX(17, REBIND, REBIND) \ - XX(18, UNBIND, UNBIND) \ - XX(19, ACL, ACL) \ - /* subversion */ \ - XX(20, REPORT, REPORT) \ - XX(21, MKACTIVITY, MKACTIVITY) \ - XX(22, CHECKOUT, CHECKOUT) \ - XX(23, MERGE, MERGE) \ - /* upnp */ \ - XX(24, MSEARCH, M-SEARCH) \ - XX(25, NOTIFY, NOTIFY) \ - XX(26, SUBSCRIBE, SUBSCRIBE) \ - XX(27, UNSUBSCRIBE, UNSUBSCRIBE) \ - /* RFC-5789 */ \ - XX(28, PATCH, PATCH) \ - XX(29, PURGE, PURGE) \ - /* CalDAV */ \ - XX(30, MKCALENDAR, MKCALENDAR) \ - /* RFC-2068, section 19.6.1.2 */ \ - XX(31, LINK, LINK) \ - XX(32, UNLINK, UNLINK) \ - -enum http_method - { -#define XX(num, name, string) HTTP_##name = num, - HTTP_METHOD_MAP(XX) -#undef XX - }; - - -enum http_parser_type { HTTP_REQUEST, HTTP_RESPONSE, HTTP_BOTH }; - - -/* Flag values for http_parser.flags field */ -enum flags - { F_CHUNKED = 1 << 0 - , F_CONNECTION_KEEP_ALIVE = 1 << 1 - , F_CONNECTION_CLOSE = 1 << 2 - , F_CONNECTION_UPGRADE = 1 << 3 - , F_TRAILING = 1 << 4 - , F_UPGRADE = 1 << 5 - , F_SKIPBODY = 1 << 6 - , F_CONTENTLENGTH = 1 << 7 - }; - - -/* Map for errno-related constants - * - * The provided argument should be a macro that takes 2 arguments. - */ -#define HTTP_ERRNO_MAP(XX) \ - /* No error */ \ - XX(OK, "success") \ - \ - /* Callback-related errors */ \ - XX(CB_message_begin, "the on_message_begin callback failed") \ - XX(CB_url, "the on_url callback failed") \ - XX(CB_header_field, "the on_header_field callback failed") \ - XX(CB_header_value, "the on_header_value callback failed") \ - XX(CB_headers_complete, "the on_headers_complete callback failed") \ - XX(CB_body, "the on_body callback failed") \ - XX(CB_message_complete, "the on_message_complete callback failed") \ - XX(CB_status, "the on_status callback failed") \ - XX(CB_chunk_header, "the on_chunk_header callback failed") \ - XX(CB_chunk_complete, "the on_chunk_complete callback failed") \ - \ - /* Parsing-related errors */ \ - XX(INVALID_EOF_STATE, "stream ended at an unexpected time") \ - XX(HEADER_OVERFLOW, \ - "too many header bytes seen; overflow detected") \ - XX(CLOSED_CONNECTION, \ - "data received after completed connection: close message") \ - XX(INVALID_VERSION, "invalid HTTP version") \ - XX(INVALID_STATUS, "invalid HTTP status code") \ - XX(INVALID_METHOD, "invalid HTTP method") \ - XX(INVALID_URL, "invalid URL") \ - XX(INVALID_HOST, "invalid host") \ - XX(INVALID_PORT, "invalid port") \ - XX(INVALID_PATH, "invalid path") \ - XX(INVALID_QUERY_STRING, "invalid query string") \ - XX(INVALID_FRAGMENT, "invalid fragment") \ - XX(LF_EXPECTED, "LF character expected") \ - XX(INVALID_HEADER_TOKEN, "invalid character in header") \ - XX(INVALID_CONTENT_LENGTH, \ - "invalid character in content-length header") \ - XX(UNEXPECTED_CONTENT_LENGTH, \ - "unexpected content-length header") \ - XX(INVALID_CHUNK_SIZE, \ - "invalid character in chunk size header") \ - XX(INVALID_CONSTANT, "invalid constant string") \ - XX(INVALID_INTERNAL_STATE, "encountered unexpected internal state")\ - XX(STRICT, "strict mode assertion failed") \ - XX(PAUSED, "parser is paused") \ - XX(UNKNOWN, "an unknown error occurred") - - -/* Define HPE_* values for each errno value above */ -#define HTTP_ERRNO_GEN(n, s) HPE_##n, -enum http_errno { - HTTP_ERRNO_MAP(HTTP_ERRNO_GEN) -}; -#undef HTTP_ERRNO_GEN - - -/* Get an http_errno value from an http_parser */ -#define HTTP_PARSER_ERRNO(p) ((enum http_errno) (p)->http_errno) - - -struct http_parser { - /** PRIVATE **/ - unsigned int type : 2; /* enum http_parser_type */ - unsigned int flags : 8; /* F_* values from 'flags' enum; semi-public */ - unsigned int state : 7; /* enum state from http_parser.c */ - unsigned int header_state : 7; /* enum header_state from http_parser.c */ - unsigned int index : 7; /* index into current matcher */ - unsigned int lenient_http_headers : 1; - - uint32_t nread; /* # bytes read in various scenarios */ - uint64_t content_length; /* # bytes in body (0 if no Content-Length header) */ - - /** READ-ONLY **/ - unsigned short http_major; - unsigned short http_minor; - unsigned int status_code : 16; /* responses only */ - unsigned int method : 8; /* requests only */ - unsigned int http_errno : 7; - - /* 1 = Upgrade header was present and the parser has exited because of that. - * 0 = No upgrade header present. - * Should be checked when http_parser_execute() returns in addition to - * error checking. - */ - unsigned int upgrade : 1; - - /** PUBLIC **/ - void *data; /* A pointer to get hook to the "connection" or "socket" object */ -}; - - -struct http_parser_settings { - http_cb on_message_begin; - http_data_cb on_url; - http_data_cb on_status; - http_data_cb on_header_field; - http_data_cb on_header_value; - http_cb on_headers_complete; - http_data_cb on_body; - http_cb on_message_complete; - /* When on_chunk_header is called, the current chunk length is stored - * in parser->content_length. - */ - http_cb on_chunk_header; - http_cb on_chunk_complete; -}; - - -enum http_parser_url_fields - { UF_SCHEMA = 0 - , UF_HOST = 1 - , UF_PORT = 2 - , UF_PATH = 3 - , UF_QUERY = 4 - , UF_FRAGMENT = 5 - , UF_USERINFO = 6 - , UF_MAX = 7 - }; - - -/* Result structure for http_parser_parse_url(). - * - * Callers should index into field_data[] with UF_* values iff field_set - * has the relevant (1 << UF_*) bit set. As a courtesy to clients (and - * because we probably have padding left over), we convert any port to - * a uint16_t. - */ -struct http_parser_url { - uint16_t field_set; /* Bitmask of (1 << UF_*) values */ - uint16_t port; /* Converted UF_PORT string */ - - struct { - uint16_t off; /* Offset into buffer in which field starts */ - uint16_t len; /* Length of run in buffer */ - } field_data[UF_MAX]; -}; - - -/* Returns the library version. Bits 16-23 contain the major version number, - * bits 8-15 the minor version number and bits 0-7 the patch level. - * Usage example: - * - * unsigned long version = http_parser_version(); - * unsigned major = (version >> 16) & 255; - * unsigned minor = (version >> 8) & 255; - * unsigned patch = version & 255; - * printf("http_parser v%u.%u.%u\n", major, minor, patch); - */ -unsigned long http_parser_version(void); - -void http_parser_init(http_parser *parser, enum http_parser_type type); - - -/* Initialize http_parser_settings members to 0 - */ -void http_parser_settings_init(http_parser_settings *settings); - - -/* Executes the parser. Returns number of parsed bytes. Sets - * `parser->http_errno` on error. */ -size_t http_parser_execute(http_parser *parser, - const http_parser_settings *settings, - const char *data, - size_t len); - - -/* If http_should_keep_alive() in the on_headers_complete or - * on_message_complete callback returns 0, then this should be - * the last message on the connection. - * If you are the server, respond with the "Connection: close" header. - * If you are the client, close the connection. - */ -int http_should_keep_alive(const http_parser *parser); - -/* Returns a string version of the HTTP method. */ -const char *http_method_str(enum http_method m); - -/* Return a string name of the given error */ -const char *http_errno_name(enum http_errno err); - -/* Return a string description of the given error */ -const char *http_errno_description(enum http_errno err); - -/* Initialize all http_parser_url members to 0 */ -void http_parser_url_init(struct http_parser_url *u); - -/* Parse a URL; return nonzero on failure */ -int http_parser_parse_url(const char *buf, size_t buflen, - int is_connect, - struct http_parser_url *u); - -/* Pause or un-pause the parser; a nonzero value pauses */ -void http_parser_pause(http_parser *parser, int paused); - -/* Checks if this is the final chunk of the body. */ -int http_body_is_final(const http_parser *parser); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/beast/test/benchmarks/nodejs_parser.cpp b/src/beast/test/benchmarks/nodejs_parser.cpp deleted file mode 100644 index 39bef4542ad..00000000000 --- a/src/beast/test/benchmarks/nodejs_parser.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#if defined(__GNUC__) && (__GNUC__ >= 7) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wimplicit-fallthrough" -#endif - -#include - -#ifdef BOOST_MSVC -# pragma warning (push) -# pragma warning (disable: 4127) // conditional expression is constant -# pragma warning (disable: 4244) // integer conversion, possible loss of data -#endif - -#include "nodejs-parser/http_parser.c" - -#ifdef BOOST_MSVC -# pragma warning (pop) -#endif - -#if defined(__GNUC__) && (__GNUC__ >= 7) -#pragma GCC diagnostic pop -#endif diff --git a/src/beast/test/benchmarks/nodejs_parser.hpp b/src/beast/test/benchmarks/nodejs_parser.hpp deleted file mode 100644 index 043c58349ec..00000000000 --- a/src/beast/test/benchmarks/nodejs_parser.hpp +++ /dev/null @@ -1,638 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_NODEJS_PARSER_HPP -#define BEAST_HTTP_NODEJS_PARSER_HPP - -#include "nodejs-parser/http_parser.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -namespace detail { - -class nodejs_message_category - : public boost::system::error_category -{ -public: - const char* - name() const noexcept override - { - return "nodejs-http-error"; - } - - std::string - message(int ev) const override - { - return http_errno_description( - static_cast(ev)); - } - - boost::system::error_condition - default_error_condition(int ev) const noexcept override - { - return boost::system::error_condition{ev, *this}; - } - - bool - equivalent(int ev, - boost::system::error_condition const& condition - ) const noexcept override - { - return condition.value() == ev && - &condition.category() == this; - } - - bool - equivalent(boost::system::error_code const& error, - int ev) const noexcept override - { - return error.value() == ev && - &error.category() == this; - } -}; - -template -boost::system::error_code -make_nodejs_error(int http_errno) -{ - static nodejs_message_category const mc{}; - return boost::system::error_code{http_errno, mc}; -} - -inline -char const* -method_to_string(unsigned method) -{ - using namespace beast; - switch(static_cast(method)) - { - case HTTP_DELETE: return "DELETE"; - case HTTP_GET: return "GET"; - case HTTP_HEAD: return "HEAD"; - case HTTP_POST: return "POST"; - case HTTP_PUT: return "PUT"; - - // pathological - case HTTP_CONNECT: return "CONNECT"; - case HTTP_OPTIONS: return "OPTIONS"; - case HTTP_TRACE: return "TRACE"; - - // webdav - case HTTP_COPY: return "COPY"; - case HTTP_LOCK: return "LOCK"; - case HTTP_MKCOL: return "MKCOL"; - case HTTP_MOVE: return "MOVE"; - case HTTP_PROPFIND: return "PROPFIND"; - case HTTP_PROPPATCH: return "PROPPATCH"; - case HTTP_SEARCH: return "SEARCH"; - case HTTP_UNLOCK: return "UNLOCK"; - case HTTP_BIND: return "BIND"; - case HTTP_REBIND: return "REBIND"; - case HTTP_UNBIND: return "UNBIND"; - case HTTP_ACL: return "ACL"; - - // subversion - case HTTP_REPORT: return "REPORT"; - case HTTP_MKACTIVITY: return "MKACTIVITY"; - case HTTP_CHECKOUT: return "CHECKOUT"; - case HTTP_MERGE: return "MERGE"; - - // upnp - case HTTP_MSEARCH: return "MSEARCH"; - case HTTP_NOTIFY: return "NOTIFY"; - case HTTP_SUBSCRIBE: return "SUBSCRIBE"; - case HTTP_UNSUBSCRIBE: return "UNSUBSCRIBE"; - - // RFC-5789 - case HTTP_PATCH: return "PATCH"; - case HTTP_PURGE: return "PURGE"; - - // CalDav - case HTTP_MKCALENDAR: return "MKCALENDAR"; - - // RFC-2068, section 19.6.1.2 - case HTTP_LINK: return "LINK"; - case HTTP_UNLINK: return "UNLINK"; - }; - - return ""; -} - -} // detail - -template -class nodejs_basic_parser -{ - http_parser state_; - boost::system::error_code* ec_; - bool complete_ = false; - std::string url_; - std::string status_; - std::string field_; - std::string value_; - -public: - using error_code = boost::system::error_code; - - nodejs_basic_parser(nodejs_basic_parser&& other); - - nodejs_basic_parser& - operator=(nodejs_basic_parser&& other); - - nodejs_basic_parser(nodejs_basic_parser const& other); - - nodejs_basic_parser& operator=(nodejs_basic_parser const& other); - - explicit - nodejs_basic_parser(bool request) noexcept; - - bool - complete() const noexcept - { - return complete_; - } - - std::size_t - write(void const* data, std::size_t size) - { - error_code ec; - auto const used = write(data, size, ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); - return used; - } - - std::size_t - write(void const* data, std::size_t size, - error_code& ec); - - template - std::size_t - write(ConstBufferSequence const& buffers) - { - error_code ec; - auto const used = write(buffers, ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); - return used; - } - - template - std::size_t - write(ConstBufferSequence const& buffers, - error_code& ec); - - void - write_eof() - { - error_code ec; - write_eof(ec); - if(ec) - BOOST_THROW_EXCEPTION(system_error{ec}); - } - - void - write_eof(error_code& ec); - - void - check_header(); - -private: - Derived& - impl() - { - return *static_cast(this); - } - - static int cb_message_start(http_parser*); - static int cb_url(http_parser*, char const*, std::size_t); - static int cb_status(http_parser*, char const*, std::size_t); - static int cb_header_field(http_parser*, char const*, std::size_t); - static int cb_header_value(http_parser*, char const*, std::size_t); - static int cb_headers_complete(http_parser*); - static int cb_body(http_parser*, char const*, std::size_t); - static int cb_message_complete(http_parser*); - static int cb_chunk_header(http_parser*); - static int cb_chunk_complete(http_parser*); - - struct hooks_t : http_parser_settings - { - hooks_t() - { - http_parser_settings_init(this); - on_message_begin = &nodejs_basic_parser::cb_message_start; - on_url = &nodejs_basic_parser::cb_url; - on_status = &nodejs_basic_parser::cb_status; - on_header_field = &nodejs_basic_parser::cb_header_field; - on_header_value = &nodejs_basic_parser::cb_header_value; - on_headers_complete = &nodejs_basic_parser::cb_headers_complete; - on_body = &nodejs_basic_parser::cb_body; - on_message_complete = &nodejs_basic_parser::cb_message_complete; - on_chunk_header = &nodejs_basic_parser::cb_chunk_header; - on_chunk_complete = &nodejs_basic_parser::cb_chunk_complete; - } - }; - - static - http_parser_settings const* - hooks(); -}; - -template -template -std::size_t -nodejs_basic_parser::write( - ConstBufferSequence const& buffers, error_code& ec) -{ - static_assert(beast::is_const_buffer_sequence< - ConstBufferSequence>::value, - "ConstBufferSequence requirements not met"); - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - std::size_t bytes_used = 0; - for(boost::asio::const_buffer buffer : buffers) - { - auto const n = write( - buffer_cast(buffer), - buffer_size(buffer), ec); - if(ec) - return 0; - bytes_used += n; - if(complete()) - break; - } - return bytes_used; -} - -template -http_parser_settings const* -nodejs_basic_parser::hooks() -{ - static hooks_t const h; - return &h; -} - -template -nodejs_basic_parser:: -nodejs_basic_parser(nodejs_basic_parser&& other) -{ - state_ = other.state_; - state_.data = this; - complete_ = other.complete_; - url_ = std::move(other.url_); - status_ = std::move(other.status_); - field_ = std::move(other.field_); - value_ = std::move(other.value_); -} - -template -auto -nodejs_basic_parser:: -operator=(nodejs_basic_parser&& other) -> - nodejs_basic_parser& -{ - state_ = other.state_; - state_.data = this; - complete_ = other.complete_; - url_ = std::move(other.url_); - status_ = std::move(other.status_); - field_ = std::move(other.field_); - value_ = std::move(other.value_); - return *this; -} - -template -nodejs_basic_parser:: -nodejs_basic_parser(nodejs_basic_parser const& other) -{ - state_ = other.state_; - state_.data = this; - complete_ = other.complete_; - url_ = other.url_; - status_ = other.status_; - field_ = other.field_; - value_ = other.value_; -} - -template -auto -nodejs_basic_parser:: -operator=(nodejs_basic_parser const& other) -> - nodejs_basic_parser& -{ - state_ = other.state_; - state_.data = this; - complete_ = other.complete_; - url_ = other.url_; - status_ = other.status_; - field_ = other.field_; - value_ = other.value_; - return *this; -} - -template -nodejs_basic_parser:: -nodejs_basic_parser(bool request) noexcept -{ - state_.data = this; - http_parser_init(&state_, request - ? http_parser_type::HTTP_REQUEST - : http_parser_type::HTTP_RESPONSE); -} - -template -std::size_t -nodejs_basic_parser:: -write(void const* data, - std::size_t size, error_code& ec) -{ - ec_ = &ec; - auto const n = http_parser_execute( - &state_, hooks(), - static_cast(data), size); - if(! ec) - ec = detail::make_nodejs_error( - static_cast(state_.http_errno)); - if(ec) - return 0; - return n; -} - -template -void -nodejs_basic_parser:: -write_eof(error_code& ec) -{ - ec_ = &ec; - http_parser_execute(&state_, hooks(), nullptr, 0); - if(! ec) - ec = detail::make_nodejs_error( - static_cast(state_.http_errno)); -} - -template -void -nodejs_basic_parser:: -check_header() -{ - if(! value_.empty()) - { - impl().on_field(field_, value_); - field_.clear(); - value_.clear(); - } -} - -template -int -nodejs_basic_parser:: -cb_message_start(http_parser* p) -{ - auto& t = *reinterpret_cast(p->data); - t.complete_ = false; - t.url_.clear(); - t.status_.clear(); - t.field_.clear(); - t.value_.clear(); - t.impl().on_start(); - return 0; -} - -template -int -nodejs_basic_parser:: -cb_url(http_parser* p, - char const* in, std::size_t bytes) -{ - auto& t = *reinterpret_cast(p->data); - t.url_.append(in, bytes); - return 0; -} - -template -int -nodejs_basic_parser:: -cb_status(http_parser* p, - char const* in, std::size_t bytes) -{ - auto& t = *reinterpret_cast(p->data); - t.status_.append(in, bytes); - return 0; -} - -template -int -nodejs_basic_parser:: -cb_header_field(http_parser* p, - char const* in, std::size_t bytes) -{ - auto& t = *reinterpret_cast(p->data); - t.check_header(); - t.field_.append(in, bytes); - return 0; -} - -template -int -nodejs_basic_parser:: -cb_header_value(http_parser* p, - char const* in, std::size_t bytes) -{ - auto& t = *reinterpret_cast(p->data); - t.value_.append(in, bytes); - return 0; -} - -template -int -nodejs_basic_parser:: -cb_headers_complete(http_parser* p) -{ - auto& t = *reinterpret_cast(p->data); - t.check_header(); - t.impl().on_headers_complete(*t.ec_); - if(*t.ec_) - return 1; - bool const keep_alive = - http_should_keep_alive(p) != 0; - if(p->type == http_parser_type::HTTP_REQUEST) - { - t.impl().on_request(p->method, t.url_, - p->http_major, p->http_minor, keep_alive, - p->upgrade); - return 0; - } - return t.impl().on_response(p->status_code, t.status_, - p->http_major, p->http_minor, keep_alive, - p->upgrade) ? 0 : 1; -} - -template -int -nodejs_basic_parser:: -cb_body(http_parser* p, - char const* in, std::size_t bytes) -{ - auto& t = *reinterpret_cast(p->data); - t.impl().on_body(in, bytes, *t.ec_); - return *t.ec_ ? 1 : 0; -} - -template -int -nodejs_basic_parser:: -cb_message_complete(http_parser* p) -{ - auto& t = *reinterpret_cast(p->data); - t.complete_ = true; - t.impl().on_complete(); - return 0; -} - -template -int -nodejs_basic_parser:: -cb_chunk_header(http_parser*) -{ - return 0; -} - -template -int -nodejs_basic_parser:: -cb_chunk_complete(http_parser*) -{ - return 0; -} - -//------------------------------------------------------------------------------ - -/** A HTTP parser. - - The parser may only be used once. -*/ -template -class nodejs_parser - : public nodejs_basic_parser> -{ - bool started_ = false; - -public: - nodejs_parser(nodejs_parser&&) = default; - - nodejs_parser() - : http::nodejs_basic_parser(isRequest) - { - } - - /// Returns `true` if at least one byte has been processed - bool - started() - { - return started_; - } - -private: - friend class http::nodejs_basic_parser; - - void - on_start() - { - started_ = true; - } - - void - on_field(std::string const&, std::string const&) - { - } - - void - on_headers_complete(error_code& ec) - { - // vFALCO TODO Decode the Content-Length and - // Transfer-Encoding, see if we can reserve the buffer. - // - // r_.reserve(content_length) - ec.assign(0, ec.category()); - } - - bool - on_request(unsigned, std::string const&, - int, int, bool, bool, std::true_type) - { - return true; - } - - bool - on_request(unsigned, std::string const&, - int, int, bool, bool, std::false_type) - { - return true; - } - - bool - on_request(unsigned method, std::string const& url, - int major, int minor, bool keep_alive, bool upgrade) - { - return on_request(method, url, - major, minor, keep_alive, upgrade, - std::integral_constant< - bool, isRequest>{}); - } - - bool - on_response(int, std::string const&, - int, int, bool, bool, std::true_type) - { - return true; - } - - bool - on_response(int, std::string const&, int, int, bool, bool, - std::false_type) - { - return true; - } - - bool - on_response(int status, std::string const& reason, - int major, int minor, bool keep_alive, bool upgrade) - { - return on_response( - status, reason, major, minor, keep_alive, upgrade, - std::integral_constant{}); - } - - void - on_body(void const*, std::size_t, error_code& ec) - { - ec.assign(0, ec.category()); - } - - void - on_complete() - { - } -}; - -} // http -} // beast - -#endif diff --git a/src/beast/test/benchmarks/parser.cpp b/src/beast/test/benchmarks/parser.cpp deleted file mode 100644 index b7c67f42bef..00000000000 --- a/src/beast/test/benchmarks/parser.cpp +++ /dev/null @@ -1,290 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#include "nodejs_parser.hpp" -#include "../http/message_fuzz.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -class parser_test : public beast::unit_test::suite -{ -public: - static std::size_t constexpr N = 2000; - - //using corpus = std::vector; - using corpus = std::vector; - - corpus creq_; - corpus cres_; - std::size_t size_ = 0; - - template - static - std::string - to_string(ConstBufferSequence const& bs) - { - return boost::lexical_cast< - std::string>(buffers(bs)); - } - - corpus - build_corpus(std::size_t n, std::true_type) - { - corpus v; - v.resize(n); - message_fuzz mg; - for(std::size_t i = 0; i < n; ++i) - { - mg.request(v[i]); - size_ += v[i].size(); - BEAST_EXPECT(v[i].size() > 0); - } - return v; - } - - corpus - build_corpus(std::size_t n, std::false_type) - { - corpus v; - v.resize(n); - message_fuzz mg; - for(std::size_t i = 0; i < n; ++i) - { - mg.response(v[i]); - size_ += v[i].size(); - BEAST_EXPECT(v[i].size() > 0); - } - return v; - } - - template - static - std::size_t - feed(ConstBufferSequence const& buffers, - basic_parser& parser, - error_code& ec) - { - using boost::asio::buffer_size; - beast::consuming_buffers< - ConstBufferSequence> cb{buffers}; - std::size_t used = 0; - for(;;) - { - auto const n = - parser.put(cb, ec); - if(ec) - return 0; - if(n == 0) - break; - cb.consume(n); - used += n; - if(parser.is_done()) - break; - if(buffer_size(cb) == 0) - break; - } - return used; - } - - template - void - testParser1(std::size_t repeat, corpus const& v) - { - while(repeat--) - for(auto const& b : v) - { - Parser p; - error_code ec; - p.write(b.data(), ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - log << to_string(b.data()) << std::endl; - } - } - - template - void - testParser2(std::size_t repeat, corpus const& v) - { - while(repeat--) - for(auto const& b : v) - { - Parser p; - p.header_limit((std::numeric_limits::max)()); - error_code ec; - feed(b.data(), p, ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - log << to_string(b.data()) << std::endl; - } - } - - template - void - timedTest(std::size_t repeat, std::string const& name, Function&& f) - { - using namespace std::chrono; - using clock_type = std::chrono::high_resolution_clock; - log << name << std::endl; - for(std::size_t trial = 1; trial <= repeat; ++trial) - { - auto const t0 = clock_type::now(); - f(); - auto const elapsed = clock_type::now() - t0; - log << - "Trial " << trial << ": " << - duration_cast(elapsed).count() << " ms" << std::endl; - } - } - - template - struct null_parser : - basic_parser> - { - }; - - template - struct bench_parser : basic_parser< - isRequest, bench_parser> - { - using mutable_buffers_type = - boost::asio::mutable_buffers_1; - - void - on_request(verb, string_view, - string_view, int, error_code& ec) - { - ec.assign(0, ec.category()); - } - - void - on_response(int, - string_view, - int, error_code& ec) - { - ec.assign(0, ec.category()); - } - - void - on_field(field, - string_view, string_view, error_code& ec) - { - ec.assign(0, ec.category()); - } - - void - on_header(error_code& ec) - { - ec.assign(0, ec.category()); - } - - void - on_body(boost::optional const&, - error_code& ec) - { - ec.assign(0, ec.category()); - } - - std::size_t - on_data(string_view s, error_code& ec) - { - ec.assign(0, ec.category()); - return s.size(); - } - - void - on_chunk(std::uint64_t, - string_view, - error_code& ec) - { - ec.assign(0, ec.category()); - } - - void - on_complete(error_code& ec) - { - ec.assign(0, ec.category()); - } - }; - - void - testSpeed() - { - static std::size_t constexpr Trials = 5; - static std::size_t constexpr Repeat = 500; - - creq_ = build_corpus(N/2, std::true_type{}); - cres_ = build_corpus(N/2, std::false_type{}); - - log << "sizeof(request parser) == " << - sizeof(null_parser) << '\n'; - - log << "sizeof(response parser) == " << - sizeof(null_parser)<< '\n'; - - testcase << "Parser speed test, " << - ((Repeat * size_ + 512) / 1024) << "KB in " << - (Repeat * (creq_.size() + cres_.size())) << " messages"; - -#if 0 - timedTest(Trials, "http::parser", - [&] - { - testParser2>(Repeat, creq_); - testParser2>(Repeat, cres_); - }); -#endif -#if 1 - timedTest(Trials, "http::basic_parser", - [&] - { - testParser2 >( - Repeat, creq_); - testParser2>( - Repeat, cres_); - }); -#if 1 - timedTest(Trials, "nodejs_parser", - [&] - { - testParser1>( - Repeat, creq_); - testParser1>( - Repeat, cres_); - }); -#endif -#endif - pass(); - } - - void run() override - { - pass(); - testSpeed(); - } -}; - -BEAST_DEFINE_TESTSUITE(parser,benchmarks,beast); - -} // http -} // beast - diff --git a/src/beast/test/benchmarks/utf8_checker.cpp b/src/beast/test/benchmarks/utf8_checker.cpp deleted file mode 100644 index bdb8c5da5bc..00000000000 --- a/src/beast/test/benchmarks/utf8_checker.cpp +++ /dev/null @@ -1,140 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#include -#include -#include -#include -#include - -namespace beast { - -class utf8_checker_test : public beast::unit_test::suite -{ - std::mt19937 rng_; - -public: - using size_type = std::uint64_t; - - class timer - { - using clock_type = - std::chrono::system_clock; - - clock_type::time_point when_; - - public: - using duration = - clock_type::duration; - - timer() - : when_(clock_type::now()) - { - } - - duration - elapsed() const - { - return clock_type::now() - when_; - } - }; - - template - UInt - rand(std::size_t n) - { - return static_cast( - std::uniform_int_distribution< - std::size_t>{0, n-1}(rng_)); - } - - static - inline - size_type - throughput(std::chrono::duration< - double> const& elapsed, size_type items) - { - using namespace std::chrono; - return static_cast( - 1 / (elapsed/items).count()); - } - - std::string - corpus(std::size_t n) - { - std::string s; - s.reserve(n); - while(n--) - s.push_back(static_cast( - ' ' + rand(95))); - return s; - } - - void - checkLocale(std::string const& s) - { - using namespace boost::locale; - auto p = s.begin(); - auto const e = s.end(); - while(p != e) - { - auto cp = utf::utf_traits::decode(p, e); - if(cp == utf::illegal) - break; - } - } - - void - checkBeast(std::string const& s) - { - beast::websocket::detail::check_utf8( - s.data(), s.size()); - } - - template - typename timer::clock_type::duration - test(F const& f) - { - timer t; - f(); - return t.elapsed(); - } - - void - run() override - { - auto const s = corpus(32 * 1024 * 1024); - for(int i = 0; i < 5; ++ i) - { - auto const elapsed = test([&]{ - checkBeast(s); - checkBeast(s); - checkBeast(s); - checkBeast(s); - checkBeast(s); - }); - log << "beast: " << throughput(elapsed, s.size()) << " char/s" << std::endl; - } - for(int i = 0; i < 5; ++ i) - { - auto const elapsed = test([&]{ - checkLocale(s); - checkLocale(s); - checkLocale(s); - checkLocale(s); - checkLocale(s); - }); - log << "locale: " << throughput(elapsed, s.size()) << " char/s" << std::endl; - } - pass(); - } -}; - -BEAST_DEFINE_TESTSUITE(utf8_checker,benchmarks,beast); - -} // beast - diff --git a/src/beast/test/common/CMakeLists.txt b/src/beast/test/common/CMakeLists.txt deleted file mode 100644 index 651732cb6b1..00000000000 --- a/src/beast/test/common/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -# Part of Beast - -GroupSources(example/common common) -GroupSources(extras/beast extras) -GroupSources(include/beast beast) -GroupSources(test/common "/") - -add_executable (common-test - ${BEAST_INCLUDES} - ${COMMON_INCLUDES} - detect_ssl.cpp - mime_types.cpp - rfc7231.cpp - ssl_stream.cpp - write_msg.cpp - main.cpp -) - -target_link_libraries(common-test - Beast - ${Boost_PROGRAM_OPTIONS_LIBRARY} - ${Boost_FILESYSTEM_LIBRARY} - ) - -if (OPENSSL_FOUND) - target_link_libraries (common-test ${OPENSSL_LIBRARIES}) -endif() diff --git a/src/beast/test/common/Jamfile b/src/beast/test/common/Jamfile deleted file mode 100644 index 282b842be04..00000000000 --- a/src/beast/test/common/Jamfile +++ /dev/null @@ -1,18 +0,0 @@ -# -# Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -# -# 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) -# - -exe common-test : - detect_ssl.cpp - mime_types.cpp - rfc7231.cpp - ssl_stream.cpp - write_msg.cpp - main.cpp - : - coverage:no - ubasan:no - ; diff --git a/src/beast/test/common/detect_ssl.cpp b/src/beast/test/common/detect_ssl.cpp deleted file mode 100644 index 00fced9f25a..00000000000 --- a/src/beast/test/common/detect_ssl.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include "../../example/common/detect_ssl.hpp" - diff --git a/src/beast/test/common/main.cpp b/src/beast/test/common/main.cpp deleted file mode 100644 index 6335cbf20ab..00000000000 --- a/src/beast/test/common/main.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -int main() -{ -} diff --git a/src/beast/test/common/mime_types.cpp b/src/beast/test/common/mime_types.cpp deleted file mode 100644 index a681a902c87..00000000000 --- a/src/beast/test/common/mime_types.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include "../../example/common/mime_types.hpp" - diff --git a/src/beast/test/common/rfc7231.cpp b/src/beast/test/common/rfc7231.cpp deleted file mode 100644 index 8c5c017ca7e..00000000000 --- a/src/beast/test/common/rfc7231.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include "../../example/common/rfc7231.hpp" - diff --git a/src/beast/test/common/ssl_stream.cpp b/src/beast/test/common/ssl_stream.cpp deleted file mode 100644 index 6a54bdbdb6a..00000000000 --- a/src/beast/test/common/ssl_stream.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#if BEAST_USE_OPENSSL - -// Test that header file is self-contained. -#include "../../example/common/ssl_stream.hpp" - -#endif diff --git a/src/beast/test/common/write_msg.cpp b/src/beast/test/common/write_msg.cpp deleted file mode 100644 index 80d62d68de6..00000000000 --- a/src/beast/test/common/write_msg.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include "../../example/common/write_msg.hpp" - diff --git a/src/beast/test/config.cpp b/src/beast/test/config.cpp deleted file mode 100644 index 7b9efac24c1..00000000000 --- a/src/beast/test/config.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include diff --git a/src/beast/test/core.cpp b/src/beast/test/core.cpp deleted file mode 100644 index ea704e03808..00000000000 --- a/src/beast/test/core.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include diff --git a/src/beast/test/core/CMakeLists.txt b/src/beast/test/core/CMakeLists.txt deleted file mode 100644 index 39749c57e0a..00000000000 --- a/src/beast/test/core/CMakeLists.txt +++ /dev/null @@ -1,56 +0,0 @@ -# Part of Beast - -GroupSources(example example) -GroupSources(extras/beast extras) -GroupSources(include/beast beast) - -GroupSources(test/core "/") - -add_executable (core-tests - ${BEAST_INCLUDES} - ${EXAMPLE_INCLUDES} - ${EXTRAS_INCLUDES} - ../../extras/beast/unit_test/main.cpp - buffer_test.hpp - file_test.hpp - async_result.cpp - bind_handler.cpp - buffer_cat.cpp - buffer_prefix.cpp - buffered_read_stream.cpp - buffers_adapter.cpp - clamp.cpp - consuming_buffers.cpp - doc_examples.cpp - doc_snippets.cpp - drain_buffer.cpp - error.cpp - file.cpp - file_posix.cpp - file_stdio.cpp - file_win32.cpp - flat_buffer.cpp - handler_alloc.cpp - handler_ptr.cpp - multi_buffer.cpp - ostream.cpp - read_size.cpp - span.cpp - static_buffer.cpp - static_string.cpp - string.cpp - string_param.cpp - type_traits.cpp - base64.cpp - empty_base_optimization.cpp - sha1.cpp -) - -target_link_libraries(core-tests - Beast - ${Boost_PROGRAM_OPTIONS_LIBRARY} - ${Boost_FILESYSTEM_LIBRARY} - ${Boost_COROUTINE_LIBRARY} - ${Boost_THREAD_LIBRARY} - ${Boost_CONTEXT_LIBRARY} - ) diff --git a/src/beast/test/core/Jamfile b/src/beast/test/core/Jamfile deleted file mode 100644 index 159b7ae568c..00000000000 --- a/src/beast/test/core/Jamfile +++ /dev/null @@ -1,41 +0,0 @@ -# -# Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -# -# 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) -# - -unit-test core-tests : - ../../extras/beast/unit_test/main.cpp - async_result.cpp - bind_handler.cpp - buffer_cat.cpp - buffer_prefix.cpp - buffered_read_stream.cpp - buffers_adapter.cpp - clamp.cpp - consuming_buffers.cpp - doc_examples.cpp - doc_snippets.cpp - drain_buffer.cpp - error.cpp - file.cpp - file_posix.cpp - file_stdio.cpp - file_win32.cpp - flat_buffer.cpp - handler_alloc.cpp - handler_ptr.cpp - multi_buffer.cpp - ostream.cpp - read_size.cpp - span.cpp - static_buffer.cpp - static_string.cpp - string.cpp - string_param.cpp - type_traits.cpp - base64.cpp - empty_base_optimization.cpp - sha1.cpp - ; diff --git a/src/beast/test/core/async_result.cpp b/src/beast/test/core/async_result.cpp deleted file mode 100644 index 1aca1cbed81..00000000000 --- a/src/beast/test/core/async_result.cpp +++ /dev/null @@ -1,38 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include -#include -#include - -namespace beast { -namespace { - -struct handler -{ - void operator()(beast::error_code, std::size_t) const; -}; - -static_assert(detail::is_invocable< - typename async_result::completion_handler_type, - void(error_code, std::size_t)>::value, ""); - -static_assert(std::is_same::return_type>::value, ""); - -static_assert(std::is_constructible< - async_result, - typename async_result::completion_handler_type&>::value, ""); - -} // (anon-ns) -} // beast diff --git a/src/beast/test/core/base64.cpp b/src/beast/test/core/base64.cpp deleted file mode 100644 index e33f65d67de..00000000000 --- a/src/beast/test/core/base64.cpp +++ /dev/null @@ -1,57 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include - -namespace beast { -namespace detail { - -class base64_test : public beast::unit_test::suite -{ -public: - void - check (std::string const& in, std::string const& out) - { - auto const encoded = base64_encode (in); - BEAST_EXPECT(encoded == out); - BEAST_EXPECT(base64_decode (encoded) == in); - } - - void - run() - { - check ("", ""); - check ("f", "Zg=="); - check ("fo", "Zm8="); - check ("foo", "Zm9v"); - check ("foob", "Zm9vYg=="); - check ("fooba", "Zm9vYmE="); - check ("foobar", "Zm9vYmFy"); - - check( - "Man is distinguished, not only by his reason, but by this singular passion from " - "other animals, which is a lust of the mind, that by a perseverance of delight " - "in the continued and indefatigable generation of knowledge, exceeds the short " - "vehemence of any carnal pleasure." - , - "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz" - "IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg" - "dGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGlu" - "dWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRo" - "ZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=" - ); - } -}; - -BEAST_DEFINE_TESTSUITE(base64,core,beast); - -} // detail -} // beast - diff --git a/src/beast/test/core/bind_handler.cpp b/src/beast/test/core/bind_handler.cpp deleted file mode 100644 index 85486325a1c..00000000000 --- a/src/beast/test/core/bind_handler.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include -#include -#include - -namespace beast { - -class bind_handler_test : public unit_test::suite -{ -public: - struct handler - { - void - operator()() const; - }; - -#if 0 - // This function should fail to compile - void - failStdBind() - { - std::bind(bind_handler(handler{})); - } -#endif - - void - callback(int v) - { - BEAST_EXPECT(v == 42); - } - - void run() - { - auto f = bind_handler(std::bind( - &bind_handler_test::callback, this, - std::placeholders::_1), 42); - f(); - pass(); - } -}; - -BEAST_DEFINE_TESTSUITE(bind_handler,core,beast); - -} // beast diff --git a/src/beast/test/core/buffer_cat.cpp b/src/beast/test/core/buffer_cat.cpp deleted file mode 100644 index 88005dc558c..00000000000 --- a/src/beast/test/core/buffer_cat.cpp +++ /dev/null @@ -1,266 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include -#include -#include -#include -#include -#include -#include - -namespace beast { - -class buffer_cat_test : public unit_test::suite -{ -public: - template - static - std::reverse_iterator - make_reverse_iterator(Iterator i) - { - return std::reverse_iterator(i); - } - - template - static - std::size_t - bsize1(ConstBufferSequence const& bs) - { - using boost::asio::buffer_size; - std::size_t n = 0; - for(auto it = bs.begin(); it != bs.end(); ++it) - n += buffer_size(*it); - return n; - } - - template - static - std::size_t - bsize2(ConstBufferSequence const& bs) - { - using boost::asio::buffer_size; - std::size_t n = 0; - for(auto it = bs.begin(); it != bs.end(); it++) - n += buffer_size(*it); - return n; - } - - template - static - std::size_t - bsize3(ConstBufferSequence const& bs) - { - using boost::asio::buffer_size; - std::size_t n = 0; - for(auto it = bs.end(); it != bs.begin();) - n += buffer_size(*--it); - return n; - } - - template - static - std::size_t - bsize4(ConstBufferSequence const& bs) - { - using boost::asio::buffer_size; - std::size_t n = 0; - for(auto it = bs.end(); it != bs.begin();) - { - it--; - n += buffer_size(*it); - } - return n; - } - - void testBufferCat() - { - using boost::asio::buffer_size; - using boost::asio::const_buffer; - char buf[10]; - std::list b1; - std::vector b2{ - const_buffer{buf+0, 1}, - const_buffer{buf+1, 2}}; - std::list b3; - std::array b4{{ - const_buffer{buf+3, 1}, - const_buffer{buf+4, 2}, - const_buffer{buf+6, 3}}}; - std::list b5{ - const_buffer{buf+9, 1}}; - std::list b6; - auto bs = buffer_cat( - b1, b2, b3, b4, b5, b6); - BEAST_EXPECT(buffer_size(bs) == 10); - BEAST_EXPECT(bsize1(bs) == 10); - BEAST_EXPECT(bsize2(bs) == 10); - BEAST_EXPECT(bsize3(bs) == 10); - BEAST_EXPECT(bsize4(bs) == 10); - std::vector v; - for(auto iter = make_reverse_iterator(bs.end()); - iter != make_reverse_iterator(bs.begin()); ++iter) - v.emplace_back(*iter); - BEAST_EXPECT(buffer_size(bs) == 10); - decltype(bs) bs2(bs); - auto bs3(std::move(bs)); - { - boost::asio::streambuf sb1, sb2; - BEAST_EXPECT(buffer_size(buffer_cat( - sb1.prepare(5), sb2.prepare(7))) == 12); - sb1.commit(5); - sb2.commit(7); - BEAST_EXPECT(buffer_size(buffer_cat( - sb1.data(), sb2.data())) == 12); - } - for(auto it = bs.begin(); it != bs.end(); ++it) - { - decltype(bs)::const_iterator copy; - copy = it; - BEAST_EXPECT(copy == it); - copy = copy; - BEAST_EXPECT(copy == it); - } - } - - void testIterators() - { - using boost::asio::buffer_size; - using boost::asio::const_buffer; - char buf[9]; - std::vector b1{ - const_buffer{buf+0, 1}, - const_buffer{buf+1, 2}}; - std::array b2{{ - const_buffer{buf+3, 1}, - const_buffer{buf+4, 2}, - const_buffer{buf+6, 3}}}; - auto bs = buffer_cat(b1, b2); - for(int n = 0; - n <= std::distance(bs.begin(), bs.end()); ++n) - { - auto it = std::next(bs.begin(), n); - decltype(it) it2(std::move(it)); - it = std::move(it2); - auto pit = ⁢ - it = std::move(*pit); - } - try - { - std::size_t n = 0; - for(auto it = bs.begin(); n < 100; ++it) - ++n; - fail(); - } - catch(std::exception const&) - { - pass(); - } - - // decrement iterator - /* VFALCO - This causes a mysterious "uninitialized variable" - warning related to this function (see comment) - https://code.woboq.org/qt5/include/c++/6.3.1/bits/stl_iterator.h.html#159 - */ -#if 0 - { - auto const rbegin = - make_reverse_iterator(bs.end()); - auto const rend = - make_reverse_iterator(bs.begin()); - std::size_t n = 0; - for(auto it = rbegin; it != rend; ++it) - n += buffer_size(*it); - BEAST_EXPECT(n == 9); - } -#endif - - try - { - std::size_t n = 0; - for(auto it = bs.end(); n < 100; --it) - ++n; - fail(); - } - catch(std::exception const&) - { - pass(); - } - - try - { - buffer_size(*bs.end()); - fail(); - } - catch(std::exception const&) - { - pass(); - } - auto bs2 = bs; - BEAST_EXPECT(bs.begin() != bs2.begin()); - BEAST_EXPECT(bs.end() != bs2.end()); - decltype(bs)::const_iterator it; - decltype(bs2)::const_iterator it2; - BEAST_EXPECT(it == it2); - } - - void run() override - { - using boost::asio::const_buffer; - using boost::asio::const_buffers_1; - using boost::asio::mutable_buffer; - using boost::asio::mutable_buffers_1; - struct user_defined : mutable_buffer - { - }; - - // Check is_all_const_buffer_sequence - BOOST_STATIC_ASSERT( - detail::is_all_const_buffer_sequence::value); - BOOST_STATIC_ASSERT( - detail::is_all_const_buffer_sequence::value); - BOOST_STATIC_ASSERT( - detail::is_all_const_buffer_sequence::value); - BOOST_STATIC_ASSERT( - detail::is_all_const_buffer_sequence::value); - BOOST_STATIC_ASSERT( - detail::is_all_const_buffer_sequence::value); - BOOST_STATIC_ASSERT( - ! detail::is_all_const_buffer_sequence::value); - - // Ensure that concatenating mutable buffer - // sequences results in a mutable buffer sequence - BOOST_STATIC_ASSERT(std::is_same< - mutable_buffer, - decltype(buffer_cat( - std::declval(), - std::declval(), - std::declval() - ))::value_type>::value); - - // Ensure that concatenating mixed buffer - // sequences results in a const buffer sequence. - BOOST_STATIC_ASSERT(std::is_same< - const_buffer, - decltype(buffer_cat( - std::declval(), - std::declval(), - std::declval() - ))::value_type>::value); - - testBufferCat(); - testIterators(); - } -}; - -BEAST_DEFINE_TESTSUITE(buffer_cat,core,beast); - -} // beast diff --git a/src/beast/test/core/buffer_prefix.cpp b/src/beast/test/core/buffer_prefix.cpp deleted file mode 100644 index 4da8687b1b7..00000000000 --- a/src/beast/test/core/buffer_prefix.cpp +++ /dev/null @@ -1,197 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include -#include -#include -#include -#include - -namespace beast { - -BOOST_STATIC_ASSERT( - std::is_same()))>::value); - -BOOST_STATIC_ASSERT( - is_const_buffer_sequence()))>::value); - -BOOST_STATIC_ASSERT( - std::is_same()))>::value); -BOOST_STATIC_ASSERT( - is_mutable_buffer_sequence()))>::value); - -class buffer_prefix_test : public beast::unit_test::suite -{ -public: - template - static - std::size_t - bsize1(ConstBufferSequence const& bs) - { - using boost::asio::buffer_size; - std::size_t n = 0; - for(auto it = bs.begin(); it != bs.end(); ++it) - n += buffer_size(*it); - return n; - } - - template - static - std::size_t - bsize2(ConstBufferSequence const& bs) - { - using boost::asio::buffer_size; - std::size_t n = 0; - for(auto it = bs.begin(); it != bs.end(); it++) - n += buffer_size(*it); - return n; - } - - template - static - std::size_t - bsize3(ConstBufferSequence const& bs) - { - using boost::asio::buffer_size; - std::size_t n = 0; - for(auto it = bs.end(); it != bs.begin();) - n += buffer_size(*--it); - return n; - } - - template - static - std::size_t - bsize4(ConstBufferSequence const& bs) - { - using boost::asio::buffer_size; - std::size_t n = 0; - for(auto it = bs.end(); it != bs.begin();) - { - it--; - n += buffer_size(*it); - } - return n; - } - - template - static - std::string - to_string(ConstBufferSequence const& bs) - { - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - std::string s; - s.reserve(buffer_size(bs)); - for(boost::asio::const_buffer b : bs) - s.append(buffer_cast(b), - buffer_size(b)); - return s; - } - - template - void testMatrix() - { - using boost::asio::buffer_size; - std::string s = "Hello, world"; - BEAST_EXPECT(s.size() == 12); - for(std::size_t x = 1; x < 4; ++x) { - for(std::size_t y = 1; y < 4; ++y) { - std::size_t z = s.size() - (x + y); - { - std::array bs{{ - BufferType{&s[0], x}, - BufferType{&s[x], y}, - BufferType{&s[x+y], z}}}; - for(std::size_t i = 0; i <= s.size() + 1; ++i) - { - auto pb = buffer_prefix(i, bs); - BEAST_EXPECT(to_string(pb) == s.substr(0, i)); - auto pb2 = pb; - BEAST_EXPECT(to_string(pb2) == to_string(pb)); - pb = buffer_prefix(0, bs); - pb2 = pb; - BEAST_EXPECT(buffer_size(pb2) == 0); - pb2 = buffer_prefix(i, bs); - BEAST_EXPECT(to_string(pb2) == s.substr(0, i)); - } - } - }} - } - - void testNullBuffers() - { - using boost::asio::buffer_copy; - using boost::asio::buffer_size; - using boost::asio::null_buffers; - auto pb0 = buffer_prefix(0, null_buffers{}); - BEAST_EXPECT(buffer_size(pb0) == 0); - auto pb1 = buffer_prefix(1, null_buffers{}); - BEAST_EXPECT(buffer_size(pb1) == 0); - BEAST_EXPECT(buffer_copy(pb0, pb1) == 0); - - using pb_type = decltype(pb0); - consuming_buffers cb(pb0); - BEAST_EXPECT(buffer_size(cb) == 0); - BEAST_EXPECT(buffer_copy(cb, pb1) == 0); - cb.consume(1); - BEAST_EXPECT(buffer_size(cb) == 0); - BEAST_EXPECT(buffer_copy(cb, pb1) == 0); - - auto pbc = buffer_prefix(2, cb); - BEAST_EXPECT(buffer_size(pbc) == 0); - BEAST_EXPECT(buffer_copy(pbc, cb) == 0); - } - - void testIterator() - { - using boost::asio::buffer_size; - using boost::asio::const_buffer; - char b[3]; - std::array bs{{ - const_buffer{&b[0], 1}, - const_buffer{&b[1], 1}, - const_buffer{&b[2], 1}}}; - auto pb = buffer_prefix(2, bs); - BEAST_EXPECT(bsize1(pb) == 2); - BEAST_EXPECT(bsize2(pb) == 2); - BEAST_EXPECT(bsize3(pb) == 2); - BEAST_EXPECT(bsize4(pb) == 2); - std::size_t n = 0; - for(auto it = pb.end(); it != pb.begin(); --it) - { - decltype(pb)::const_iterator it2(std::move(it)); - BEAST_EXPECT(buffer_size(*it2) == 1); - it = std::move(it2); - ++n; - } - BEAST_EXPECT(n == 2); - } - - void run() override - { - testMatrix(); - testMatrix(); - testNullBuffers(); - testIterator(); - } -}; - -BEAST_DEFINE_TESTSUITE(buffer_prefix,core,beast); - -} // beast diff --git a/src/beast/test/core/buffer_test.hpp b/src/beast/test/core/buffer_test.hpp deleted file mode 100644 index 3a05b459960..00000000000 --- a/src/beast/test/core/buffer_test.hpp +++ /dev/null @@ -1,118 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_TEST_BUFFER_TEST_HPP -#define BEAST_TEST_BUFFER_TEST_HPP - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace test { - -template -typename std::enable_if< - is_const_buffer_sequence::value, -std::string>::type -to_string(ConstBufferSequence const& bs) -{ - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - std::string s; - s.reserve(buffer_size(bs)); - for(boost::asio::const_buffer b : bs) - s.append(buffer_cast(b), - buffer_size(b)); - return s; -} - -template -void -write_buffer(DynamicBuffer& b, string_view s) -{ - b.commit(boost::asio::buffer_copy( - b.prepare(s.size()), boost::asio::buffer( - s.data(), s.size()))); -} - -template -typename std::enable_if< - is_const_buffer_sequence::value, - std::size_t>::type -buffer_count(ConstBufferSequence const& buffers) -{ - return std::distance(buffers.begin(), buffers.end()); -} - -template -typename std::enable_if< - is_const_buffer_sequence::value, - std::size_t>::type -size_pre(ConstBufferSequence const& buffers) -{ - std::size_t n = 0; - for(auto it = buffers.begin(); it != buffers.end(); ++it) - { - typename ConstBufferSequence::const_iterator it0(std::move(it)); - typename ConstBufferSequence::const_iterator it1(it0); - typename ConstBufferSequence::const_iterator it2; - it2 = it1; - n += boost::asio::buffer_size(*it2); - it = std::move(it2); - } - return n; -} - -template -typename std::enable_if< - is_const_buffer_sequence::value, - std::size_t>::type -size_post(ConstBufferSequence const& buffers) -{ - std::size_t n = 0; - for(auto it = buffers.begin(); it != buffers.end(); it++) - n += boost::asio::buffer_size(*it); - return n; -} - -template -typename std::enable_if< - is_const_buffer_sequence::value, - std::size_t>::type -size_rev_pre(ConstBufferSequence const& buffers) -{ - std::size_t n = 0; - for(auto it = buffers.end(); it != buffers.begin();) - n += boost::asio::buffer_size(*--it); - return n; -} - -template -typename std::enable_if< - is_const_buffer_sequence::value, - std::size_t>::type -size_rev_post(ConstBufferSequence const& buffers) -{ - std::size_t n = 0; - for(auto it = buffers.end(); it != buffers.begin();) - { - it--; - n += boost::asio::buffer_size(*it); - } - return n; -} - -} // test -} // beast - -#endif diff --git a/src/beast/test/core/buffered_read_stream.cpp b/src/beast/test/core/buffered_read_stream.cpp deleted file mode 100644 index 81536e1ea15..00000000000 --- a/src/beast/test/core/buffered_read_stream.cpp +++ /dev/null @@ -1,143 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include -#include -#include -#include -#include -#include - -namespace beast { - -class buffered_read_stream_test - : public unit_test::suite - , public test::enable_yield_to -{ - using self = buffered_read_stream_test; - -public: - void testSpecialMembers() - { - using socket_type = boost::asio::ip::tcp::socket; - boost::asio::io_service ios; - { - buffered_read_stream srs(ios); - buffered_read_stream srs2(std::move(srs)); - srs = std::move(srs2); - BEAST_EXPECT(&srs.get_io_service() == &ios); - BEAST_EXPECT(&srs.get_io_service() == &srs2.get_io_service()); - } - { - socket_type sock(ios); - buffered_read_stream srs(sock); - buffered_read_stream srs2(std::move(srs)); - } - } - - void testRead(yield_context do_yield) - { - using boost::asio::buffer; - using boost::asio::buffer_copy; - static std::size_t constexpr limit = 100; - std::size_t n; - std::string s; - s.resize(13); - - for(n = 0; n < limit; ++n) - { - test::fail_stream< - test::string_istream> fs(n, ios_, ", world!"); - buffered_read_stream< - decltype(fs)&, multi_buffer> srs(fs); - srs.buffer().commit(buffer_copy( - srs.buffer().prepare(5), buffer("Hello", 5))); - error_code ec = test::error::fail_error; - boost::asio::read(srs, buffer(&s[0], s.size()), ec); - if(! ec) - { - BEAST_EXPECT(s == "Hello, world!"); - break; - } - } - BEAST_EXPECT(n < limit); - - for(n = 0; n < limit; ++n) - { - test::fail_stream< - test::string_istream> fs(n, ios_, ", world!"); - buffered_read_stream< - decltype(fs)&, multi_buffer> srs(fs); - srs.capacity(3); - srs.buffer().commit(buffer_copy( - srs.buffer().prepare(5), buffer("Hello", 5))); - error_code ec = test::error::fail_error; - boost::asio::read(srs, buffer(&s[0], s.size()), ec); - if(! ec) - { - BEAST_EXPECT(s == "Hello, world!"); - break; - } - } - BEAST_EXPECT(n < limit); - - for(n = 0; n < limit; ++n) - { - test::fail_stream< - test::string_istream> fs(n, ios_, ", world!"); - buffered_read_stream< - decltype(fs)&, multi_buffer> srs(fs); - srs.buffer().commit(buffer_copy( - srs.buffer().prepare(5), buffer("Hello", 5))); - error_code ec = test::error::fail_error; - boost::asio::async_read( - srs, buffer(&s[0], s.size()), do_yield[ec]); - if(! ec) - { - BEAST_EXPECT(s == "Hello, world!"); - break; - } - } - BEAST_EXPECT(n < limit); - - for(n = 0; n < limit; ++n) - { - test::fail_stream< - test::string_istream> fs(n, ios_, ", world!"); - buffered_read_stream< - decltype(fs)&, multi_buffer> srs(fs); - srs.capacity(3); - srs.buffer().commit(buffer_copy( - srs.buffer().prepare(5), buffer("Hello", 5))); - error_code ec = test::error::fail_error; - boost::asio::async_read( - srs, buffer(&s[0], s.size()), do_yield[ec]); - if(! ec) - { - BEAST_EXPECT(s == "Hello, world!"); - break; - } - } - BEAST_EXPECT(n < limit); - } - - void run() override - { - testSpecialMembers(); - - yield_to([&](yield_context yield){ - testRead(yield);}); - } -}; - -BEAST_DEFINE_TESTSUITE(buffered_read_stream,core,beast); - -} // beast - diff --git a/src/beast/test/core/buffers_adapter.cpp b/src/beast/test/core/buffers_adapter.cpp deleted file mode 100644 index eff1f2238bb..00000000000 --- a/src/beast/test/core/buffers_adapter.cpp +++ /dev/null @@ -1,199 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include "buffer_test.hpp" -#include -#include -#include -#include -#include -#include -#include - -namespace beast { - -class buffers_adapter_test : public unit_test::suite -{ -public: - template - static - std::string - to_string(ConstBufferSequence const& bs) - { - return boost::lexical_cast< - std::string>(buffers(bs)); - } - - void testBuffersAdapter() - { - using boost::asio::buffer; - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - using boost::asio::const_buffer; - using boost::asio::mutable_buffer; - char buf[12]; - std::string const s = "Hello, world"; - BEAST_EXPECT(s.size() == sizeof(buf)); - for(std::size_t i = 1; i < 4; ++i) { - for(std::size_t j = 1; j < 4; ++j) { - for(std::size_t x = 1; x < 4; ++x) { - for(std::size_t y = 1; y < 4; ++y) { - for(std::size_t t = 1; t < 4; ++ t) { - for(std::size_t u = 1; u < 4; ++ u) { - std::size_t k = sizeof(buf) - (i + j); - std::size_t z = sizeof(buf) - (x + y); - std::size_t v = sizeof(buf) - (t + u); - { - std::memset(buf, 0, sizeof(buf)); - std::array bs{{ - mutable_buffer{&buf[0], i}, - mutable_buffer{&buf[i], j}, - mutable_buffer{&buf[i+j], k}}}; - buffers_adapter ba(std::move(bs)); - BEAST_EXPECT(ba.max_size() == sizeof(buf)); - { - auto d = ba.prepare(z); - BEAST_EXPECT(buffer_size(d) == z); - } - { - auto d = ba.prepare(0); - BEAST_EXPECT(buffer_size(d) == 0); - } - { - auto d = ba.prepare(y); - BEAST_EXPECT(buffer_size(d) == y); - } - { - auto d = ba.prepare(x); - BEAST_EXPECT(buffer_size(d) == x); - ba.commit(buffer_copy(d, buffer(s.data(), x))); - } - BEAST_EXPECT(ba.size() == x); - BEAST_EXPECT(ba.max_size() == sizeof(buf) - x); - BEAST_EXPECT(buffer_size(ba.data()) == ba.size()); - { - auto d = ba.prepare(x); - BEAST_EXPECT(buffer_size(d) == x); - } - { - auto d = ba.prepare(0); - BEAST_EXPECT(buffer_size(d) == 0); - } - { - auto d = ba.prepare(z); - BEAST_EXPECT(buffer_size(d) == z); - } - { - auto d = ba.prepare(y); - BEAST_EXPECT(buffer_size(d) == y); - ba.commit(buffer_copy(d, buffer(s.data()+x, y))); - } - ba.commit(1); - BEAST_EXPECT(ba.size() == x + y); - BEAST_EXPECT(ba.max_size() == sizeof(buf) - (x + y)); - BEAST_EXPECT(buffer_size(ba.data()) == ba.size()); - { - auto d = ba.prepare(x); - BEAST_EXPECT(buffer_size(d) == x); - } - { - auto d = ba.prepare(y); - BEAST_EXPECT(buffer_size(d) == y); - } - { - auto d = ba.prepare(0); - BEAST_EXPECT(buffer_size(d) == 0); - } - { - auto d = ba.prepare(z); BEAST_EXPECT(buffer_size(d) == z); - ba.commit(buffer_copy(d, buffer(s.data()+x+y, z))); - } - ba.commit(2); - BEAST_EXPECT(ba.size() == x + y + z); - BEAST_EXPECT(ba.max_size() == 0); - BEAST_EXPECT(buffer_size(ba.data()) == ba.size()); - BEAST_EXPECT(to_string(ba.data()) == s); - ba.consume(t); - { - auto d = ba.prepare(0); - BEAST_EXPECT(buffer_size(d) == 0); - } - BEAST_EXPECT(to_string(ba.data()) == s.substr(t, std::string::npos)); - ba.consume(u); - BEAST_EXPECT(to_string(ba.data()) == s.substr(t + u, std::string::npos)); - ba.consume(v); - BEAST_EXPECT(to_string(ba.data()) == ""); - ba.consume(1); - { - auto d = ba.prepare(0); - BEAST_EXPECT(buffer_size(d) == 0); - } - try - { - ba.prepare(1); - fail(); - } - catch(...) - { - pass(); - } - } - }}}}}} - } - void testCommit() - { - using boost::asio::buffer_size; - { - using sb_type = boost::asio::streambuf; - sb_type b; - buffers_adapter< - sb_type::mutable_buffers_type> ba(b.prepare(3)); - BEAST_EXPECT(buffer_size(ba.prepare(3)) == 3); - ba.commit(2); - BEAST_EXPECT(buffer_size(ba.data()) == 2); - } - { - using sb_type = beast::multi_buffer; - sb_type b; - b.prepare(3); - buffers_adapter< - sb_type::mutable_buffers_type> ba(b.prepare(8)); - BEAST_EXPECT(buffer_size(ba.prepare(8)) == 8); - ba.commit(2); - BEAST_EXPECT(buffer_size(ba.data()) == 2); - ba.consume(1); - ba.commit(6); - ba.consume(2); - BEAST_EXPECT(buffer_size(ba.data()) == 5); - ba.consume(5); - } - } - - void - testIssue386() - { - using type = boost::asio::streambuf; - type buffer; - buffers_adapter< - type::mutable_buffers_type> ba{buffer.prepare(512)}; - read_size(ba, 1024); - } - - void run() override - { - testBuffersAdapter(); - testCommit(); - testIssue386(); - } -}; - -BEAST_DEFINE_TESTSUITE(buffers_adapter,core,beast); - -} // beast diff --git a/src/beast/test/core/clamp.cpp b/src/beast/test/core/clamp.cpp deleted file mode 100644 index 24fd20a6d5b..00000000000 --- a/src/beast/test/core/clamp.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include -#include - -namespace beast { -namespace detail { - -class clamp_test : public beast::unit_test::suite -{ -public: - void testClamp() - { - BEAST_EXPECT(clamp( - (std::numeric_limits::max)()) == - (std::numeric_limits::max)()); - } - - void run() override - { - testClamp(); - } -}; - -BEAST_DEFINE_TESTSUITE(clamp,core,beast); - -} // detail -} // beast - diff --git a/src/beast/test/core/consuming_buffers.cpp b/src/beast/test/core/consuming_buffers.cpp deleted file mode 100644 index 64a96770b42..00000000000 --- a/src/beast/test/core/consuming_buffers.cpp +++ /dev/null @@ -1,181 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include "buffer_test.hpp" - -#include -#include -#include -#include -#include - -namespace beast { - -class consuming_buffers_test : public beast::unit_test::suite -{ -public: - template - static - consuming_buffers - consumed_buffers(BufferSequence const& bs, std::size_t n) - { - consuming_buffers cb(bs); - cb.consume(n); - return cb; - } - - template - static - bool - eq(Buffers1 const& lhs, Buffers2 const& rhs) - { - using namespace test; - return to_string(lhs) == to_string(rhs); - } - - template - void - expect_size(std::size_t n, ConstBufferSequence const& buffers) - { - BEAST_EXPECT(test::size_pre(buffers) == n); - BEAST_EXPECT(test::size_post(buffers) == n); - BEAST_EXPECT(test::size_rev_pre(buffers) == n); - BEAST_EXPECT(test::size_rev_post(buffers) == n); - } - - void - testMembers() - { - char buf[12]; - consuming_buffers< - boost::asio::const_buffers_1> cb1{ - boost::in_place_init, buf, sizeof(buf)}; - consuming_buffers< - boost::asio::const_buffers_1> cb2{ - boost::in_place_init, nullptr, 0}; - cb2 = cb1; - cb1 = std::move(cb2); - } - - void - testMatrix() - { - using namespace test; - using boost::asio::buffer; - using boost::asio::const_buffer; - char buf[12]; - std::string const s = "Hello, world"; - BEAST_EXPECT(s.size() == sizeof(buf)); - buffer_copy(buffer(buf), buffer(s)); - BEAST_EXPECT(to_string(buffer(buf)) == s); - for(std::size_t i = 1; i < 4; ++i) { - for(std::size_t j = 1; j < 4; ++j) { - for(std::size_t x = 1; x < 4; ++x) { - for(std::size_t y = 1; y < 4; ++y) { - std::size_t k = sizeof(buf) - (i + j); - std::size_t z = sizeof(buf) - (x + y); - { - std::array bs{{ - const_buffer{&buf[0], i}, - const_buffer{&buf[i], j}, - const_buffer{&buf[i+j], k}}}; - consuming_buffers cb(bs); - BEAST_EXPECT(to_string(cb) == s); - expect_size(s.size(), cb); - cb.consume(0); - BEAST_EXPECT(eq(cb, consumed_buffers(bs, 0))); - BEAST_EXPECT(to_string(cb) == s); - expect_size(s.size(), cb); - cb.consume(x); - BEAST_EXPECT(to_string(cb) == s.substr(x)); - BEAST_EXPECT(eq(cb, consumed_buffers(bs, x))); - cb.consume(y); - BEAST_EXPECT(to_string(cb) == s.substr(x+y)); - BEAST_EXPECT(eq(cb, consumed_buffers(bs, x+y))); - cb.consume(z); - BEAST_EXPECT(to_string(cb) == ""); - BEAST_EXPECT(eq(cb, consumed_buffers(bs, x+y+z))); - cb.consume(1); - BEAST_EXPECT(to_string(cb) == ""); - BEAST_EXPECT(eq(cb, consumed_buffers(bs, x+y+z))); - } - }}}} - } - - void - testDefaultCtor() - { - using namespace test; - class test_buffer : public boost::asio::const_buffers_1 - { - public: - test_buffer() - : boost::asio::const_buffers_1("\r\n", 2) - { - } - }; - - consuming_buffers cb; - BEAST_EXPECT(to_string(cb) == "\r\n"); - } - - void - testInPlace() - { - using namespace test; - consuming_buffers> cb( - boost::in_place_init, - boost::asio::const_buffers_1("\r", 1), - boost::asio::const_buffers_1("\n", 1)); - BEAST_EXPECT(to_string(cb) == "\r\n"); - } - - void - testNullBuffers() - { - using boost::asio::buffer_copy; - using boost::asio::buffer_size; - using boost::asio::null_buffers; - consuming_buffers cb( - null_buffers{}); - BEAST_EXPECT(buffer_size(cb) == 0); - consuming_buffers cb2( - null_buffers{}); - BEAST_EXPECT(buffer_copy(cb2, cb) == 0); - } - - void - testIterator() - { - using boost::asio::const_buffer; - std::array ba; - consuming_buffers cb(ba); - std::size_t n = 0; - for(auto it = cb.end(); it != cb.begin(); --it) - ++n; - BEAST_EXPECT(n == 3); - } - - void run() override - { - testMembers(); - testMatrix(); - testDefaultCtor(); - testInPlace(); - testNullBuffers(); - testIterator(); - } -}; - -BEAST_DEFINE_TESTSUITE(consuming_buffers,core,beast); - -} // beast diff --git a/src/beast/test/core/doc_examples.cpp b/src/beast/test/core/doc_examples.cpp deleted file mode 100644 index ff4d2e4b572..00000000000 --- a/src/beast/test/core/doc_examples.cpp +++ /dev/null @@ -1,85 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#include "example/common/detect_ssl.hpp" - -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -class doc_core_samples_test - : public beast::unit_test::suite - , public beast::test::enable_yield_to -{ -public: - void - testDetect() - { - char buf[4]; - buf[0] = 0x16; - buf[1] = 0; - buf[2] = 0; - buf[3] = 0; - BEAST_EXPECT(boost::indeterminate(is_ssl_handshake( - boost::asio::buffer(buf, 0)))); - BEAST_EXPECT(boost::indeterminate(is_ssl_handshake( - boost::asio::buffer(buf, 1)))); - BEAST_EXPECT(boost::indeterminate(is_ssl_handshake( - boost::asio::buffer(buf, 2)))); - BEAST_EXPECT(boost::indeterminate(is_ssl_handshake( - boost::asio::buffer(buf, 3)))); - BEAST_EXPECT(is_ssl_handshake( - boost::asio::buffer(buf, 4))); - buf[0] = 0; - BEAST_EXPECT(! is_ssl_handshake( - boost::asio::buffer(buf, 1))); - } - - void - testRead() - { - { - test::pipe p{ios_}; - ostream(p.server.buffer) << - "\x16***"; - error_code ec; - flat_buffer b; - auto const result = detect_ssl(p.server, b, ec); - BEAST_EXPECTS(! ec, ec.message()); - BEAST_EXPECT(result); - } - yield_to( - [&](yield_context yield) - { - test::pipe p{ios_}; - ostream(p.server.buffer) << - "\x16***"; - error_code ec; - flat_buffer b; - auto const result = async_detect_ssl(p.server, b, yield[ec]); - BEAST_EXPECTS(! ec, ec.message()); - BEAST_EXPECT(result); - }); - } - - void - run() - { - testDetect(); - testRead(); - } -}; - -BEAST_DEFINE_TESTSUITE(doc_core_samples,core,beast); - -} // http -} // beast diff --git a/src/beast/test/core/doc_snippets.cpp b/src/beast/test/core/doc_snippets.cpp deleted file mode 100644 index 0fa3e97c28c..00000000000 --- a/src/beast/test/core/doc_snippets.cpp +++ /dev/null @@ -1,65 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -//[snippet_core_1a - -#include -#include -#include -#include - -//] - -using namespace beast; - -namespace doc_core_snippets { - -void fxx() -{ - -//[snippet_core_1b -// -using namespace beast; - -boost::asio::io_service ios; -boost::asio::io_service::work work{ios}; -std::thread t{[&](){ ios.run(); }}; - -error_code ec; -boost::asio::ip::tcp::socket sock{ios}; - -//] - -{ -//[snippet_core_2 - -char const* const host = "www.example.com"; -boost::asio::ip::tcp::resolver r{ios}; -boost::asio::ip::tcp::socket stream{ios}; -boost::asio::connect(stream, r.resolve({host, "http"})); - -// At this point `stream` is a connected to a remote -// host and may be used to perform stream operations. - -//] -} - -} // fxx() - -//[snippet_core_3 - -template -void write_string(SyncWriteStream& stream, string_view s) -{ - static_assert(is_sync_write_stream::value, - "SyncWriteStream requirements not met"); - boost::asio::write(stream, boost::asio::const_buffers_1(s.data(), s.size())); -} - -//] - -} // doc_core_snippets diff --git a/src/beast/test/core/drain_buffer.cpp b/src/beast/test/core/drain_buffer.cpp deleted file mode 100644 index 5e7e35e7102..00000000000 --- a/src/beast/test/core/drain_buffer.cpp +++ /dev/null @@ -1,51 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include -#include - -namespace beast { - -static_assert(is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - -class drain_buffer_test : public beast::unit_test::suite -{ -public: - void - run() override - { - using boost::asio::buffer_size; - drain_buffer b; - BEAST_EXPECT(buffer_size(b.prepare(0)) == 0); - BEAST_EXPECT(buffer_size(b.prepare(100)) == 100); - try - { - b.prepare(b.max_size() + 1); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - b.prepare(10); - BEAST_EXPECT(b.size() == 0); - b.commit(10); - BEAST_EXPECT(b.size() == 0); - b.consume(10); - BEAST_EXPECT(b.size() == 0); - b.consume(1000); - BEAST_EXPECT(b.size() == 0); - } -}; - -BEAST_DEFINE_TESTSUITE(drain_buffer,core,beast); - -} // beast diff --git a/src/beast/test/core/empty_base_optimization.cpp b/src/beast/test/core/empty_base_optimization.cpp deleted file mode 100644 index e6270085472..00000000000 --- a/src/beast/test/core/empty_base_optimization.cpp +++ /dev/null @@ -1,94 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include - -namespace beast { -namespace detail { - -class empty_base_optimization_test - : public beast::unit_test::suite -{ -public: - template - class test1 - : private empty_base_optimization - { - using Base = empty_base_optimization; - void* m_p; - public: - explicit test1 (T const& t) - : Base (t) - {} - - T& member() {return Base::member();} - T const& member() const {return Base::member();} - }; - - template - class test2 - { - void* m_p; - T m_t; - public: - explicit test2 (T const& t) - : m_t (t) - {} - - T& member() {return m_t;} - T const& member() const {return m_t;} - }; - - struct Empty - { - operator bool() {return true;} - }; - - static - bool - test_one() - { - test1 t1(1); - test2 t2(2); - static_assert(sizeof(t1) == sizeof(t2), "don't optimize for int"); - if(t1.member() != 1) - return false; - if(t2.member() != 2) - return false; - return true; - } - - static - bool - test_two() - { - test1 t1((Empty())); - test2 t2((Empty())); - static_assert(sizeof(t1) < sizeof(t2), "do optimize for Empty"); - if(t1.member() != true) - return false; - if(t2.member() != true) - return false; - return true; - } - - void - run() - { - BEAST_EXPECT(test_one()); - BEAST_EXPECT(test_two()); - pass(); - } -}; - -BEAST_DEFINE_TESTSUITE(empty_base_optimization,core,beast); - -} // detail -} // beast diff --git a/src/beast/test/core/error.cpp b/src/beast/test/core/error.cpp deleted file mode 100644 index 266f599076a..00000000000 --- a/src/beast/test/core/error.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include diff --git a/src/beast/test/core/file.cpp b/src/beast/test/core/file.cpp deleted file mode 100644 index f483142bcc9..00000000000 --- a/src/beast/test/core/file.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include diff --git a/src/beast/test/core/file_posix.cpp b/src/beast/test/core/file_posix.cpp deleted file mode 100644 index 2a8bd046c83..00000000000 --- a/src/beast/test/core/file_posix.cpp +++ /dev/null @@ -1,35 +0,0 @@ -// -// Copyright (c) 2013-2016 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#if BEAST_USE_POSIX_FILE - -#include "file_test.hpp" - -#include -#include - -namespace beast { - -class file_posix_test - : public beast::unit_test::suite -{ -public: - void - run() - { - doTestFile(*this); - } -}; - -BEAST_DEFINE_TESTSUITE(file_posix,core,beast); - -} // beast - -#endif diff --git a/src/beast/test/core/file_stdio.cpp b/src/beast/test/core/file_stdio.cpp deleted file mode 100644 index 3bb61e242f0..00000000000 --- a/src/beast/test/core/file_stdio.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// -// Copyright (c) 2013-2016 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include "file_test.hpp" - -#include -#include - -namespace beast { - -class file_stdio_test - : public beast::unit_test::suite -{ -public: - void - run() - { - doTestFile(*this); - } -}; - -BEAST_DEFINE_TESTSUITE(file_stdio,core,beast); - -} // beast diff --git a/src/beast/test/core/file_test.hpp b/src/beast/test/core/file_test.hpp deleted file mode 100644 index 2249a4c0b09..00000000000 --- a/src/beast/test/core/file_test.hpp +++ /dev/null @@ -1,122 +0,0 @@ -// -// Copyright (c) 2013-2016 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_TEST_CORE_FILE_TEST_HPP -#define BEAST_TEST_CORE_FILE_TEST_HPP - -#include -#include -#include -#include -#include - -namespace beast { - -template -void -doTestFile(beast::unit_test::suite& test) -{ - BOOST_STATIC_ASSERT(is_file::value); - - error_code ec; - auto const temp = boost::filesystem::unique_path(); - - { - { - File f1; - test.BEAST_EXPECT(! f1.is_open()); - f1.open(temp.string().c_str(), file_mode::write, ec); - test.BEAST_EXPECT(! ec); - File f2{std::move(f1)}; - test.BEAST_EXPECT(! f1.is_open()); - test.BEAST_EXPECT(f2.is_open()); - File f3; - f3 = std::move(f2); - test.BEAST_EXPECT(! f2.is_open()); - test.BEAST_EXPECT(f3.is_open()); - f1.close(ec); - test.BEAST_EXPECT(! ec); - auto const temp2 = boost::filesystem::unique_path(); - f3.open(temp2.string().c_str(), file_mode::read, ec); - test.BEAST_EXPECT(ec); - ec.assign(0, ec.category()); - } - boost::filesystem::remove(temp, ec); - test.BEAST_EXPECT(! ec); - } - - File f; - - test.BEAST_EXPECT(! f.is_open()); - - f.size(ec); - test.BEAST_EXPECT(ec == errc::invalid_argument); - ec.assign(0, ec.category()); - - f.pos(ec); - test.BEAST_EXPECT(ec == errc::invalid_argument); - ec.assign(0, ec.category()); - - f.seek(0, ec); - test.BEAST_EXPECT(ec == errc::invalid_argument); - ec.assign(0, ec.category()); - - f.read(nullptr, 0, ec); - test.BEAST_EXPECT(ec == errc::invalid_argument); - ec.assign(0, ec.category()); - - f.write(nullptr, 0, ec); - test.BEAST_EXPECT(ec == errc::invalid_argument); - ec.assign(0, ec.category()); - - f.open(temp.string().c_str(), file_mode::write, ec); - test.BEAST_EXPECT(! ec); - - std::string const s = "Hello, world!"; - f.write(s.data(), s.size(), ec); - test.BEAST_EXPECT(! ec); - - auto size = f.size(ec); - test.BEAST_EXPECT(! ec); - test.BEAST_EXPECT(size == s.size()); - - auto pos = f.pos(ec); - test.BEAST_EXPECT(! ec); - test.BEAST_EXPECT(pos == size); - - f.close(ec); - test.BEAST_EXPECT(! ec); - - f.open(temp.string().c_str(), file_mode::read, ec); - test.BEAST_EXPECT(! ec); - - std::string buf; - buf.resize(s.size()); - f.read(&buf[0], buf.size(), ec); - test.BEAST_EXPECT(! ec); - test.BEAST_EXPECT(buf == s); - - f.seek(1, ec); - test.BEAST_EXPECT(! ec); - buf.resize(3); - f.read(&buf[0], buf.size(), ec); - test.BEAST_EXPECT(! ec); - test.BEAST_EXPECT(buf == "ell"); - - pos = f.pos(ec); - test.BEAST_EXPECT(! ec); - test.BEAST_EXPECT(pos == 4); - - f.close(ec); - test.BEAST_EXPECT(! ec); - boost::filesystem::remove(temp, ec); - test.BEAST_EXPECT(! ec); -} - -} // beast - -#endif diff --git a/src/beast/test/core/file_win32.cpp b/src/beast/test/core/file_win32.cpp deleted file mode 100644 index 91530a7084a..00000000000 --- a/src/beast/test/core/file_win32.cpp +++ /dev/null @@ -1,35 +0,0 @@ -// -// Copyright (c) 2013-2016 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#if BEAST_USE_WIN32_FILE - -#include "file_test.hpp" - -#include -#include - -namespace beast { - -class file_win32_test - : public beast::unit_test::suite -{ -public: - void - run() - { - doTestFile(*this); - } -}; - -BEAST_DEFINE_TESTSUITE(file_win32,core,beast); - -} // beast - -#endif diff --git a/src/beast/test/core/flat_buffer.cpp b/src/beast/test/core/flat_buffer.cpp deleted file mode 100644 index fda65623fe0..00000000000 --- a/src/beast/test/core/flat_buffer.cpp +++ /dev/null @@ -1,352 +0,0 @@ -// -// Copyright (c) 2013-2016 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include "buffer_test.hpp" - -#include -#include -#include -#include -#include -#include -#include - -namespace beast { - -static_assert(is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - -class flat_buffer_test : public beast::unit_test::suite -{ -public: - void - testBuffer() - { - using namespace test; - - using a_t = test::test_allocator; - - // Equal == false - using a_neq_t = test::test_allocator; - - // construction - { - { - flat_buffer b; - BEAST_EXPECT(b.capacity() == 0); - } - { - flat_buffer b{500}; - BEAST_EXPECT(b.capacity() == 0); - BEAST_EXPECT(b.max_size() == 500); - } - { - a_neq_t a1; - basic_flat_buffer b{a1}; - BEAST_EXPECT(b.get_allocator() == a1); - a_neq_t a2; - BEAST_EXPECT(b.get_allocator() != a2); - } - { - a_neq_t a; - basic_flat_buffer b{500, a}; - BEAST_EXPECT(b.capacity() == 0); - BEAST_EXPECT(b.max_size() == 500); - } - } - - // move construction - { - { - basic_flat_buffer b1{30}; - BEAST_EXPECT(b1.get_allocator()->nmove == 0); - ostream(b1) << "Hello"; - basic_flat_buffer b2{std::move(b1)}; - BEAST_EXPECT(b2.get_allocator()->nmove == 1); - BEAST_EXPECT(b1.size() == 0); - BEAST_EXPECT(b1.capacity() == 0); - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - BEAST_EXPECT(b1.max_size() == b2.max_size()); - } - { - basic_flat_buffer b1{30}; - ostream(b1) << "Hello"; - a_t a; - basic_flat_buffer b2{std::move(b1), a}; - BEAST_EXPECT(b1.size() == 0); - BEAST_EXPECT(b1.capacity() == 0); - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - BEAST_EXPECT(b1.max_size() == b2.max_size()); - } - { - basic_flat_buffer b1{30}; - ostream(b1) << "Hello"; - a_neq_t a; - basic_flat_buffer b2{std::move(b1), a}; - BEAST_EXPECT(b1.size() == 0); - BEAST_EXPECT(b1.capacity() == 0); - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - BEAST_EXPECT(b1.max_size() == b2.max_size()); - } - } - - // copy construction - { - basic_flat_buffer b1; - ostream(b1) << "Hello"; - basic_flat_buffer b2(b1); - BEAST_EXPECT(b1.get_allocator() == b2.get_allocator()); - BEAST_EXPECT(to_string(b1.data()) == "Hello"); - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - } - { - basic_flat_buffer b1; - ostream(b1) << "Hello"; - a_neq_t a; - basic_flat_buffer b2(b1, a); - BEAST_EXPECT(b1.get_allocator() != b2.get_allocator()); - BEAST_EXPECT(to_string(b1.data()) == "Hello"); - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - } - { - basic_flat_buffer b1; - ostream(b1) << "Hello"; - basic_flat_buffer b2(b1); - BEAST_EXPECT(to_string(b1.data()) == "Hello"); - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - } - { - basic_flat_buffer b1; - ostream(b1) << "Hello"; - a_t a; - basic_flat_buffer b2(b1, a); - BEAST_EXPECT(b2.get_allocator() == a); - BEAST_EXPECT(to_string(b1.data()) == "Hello"); - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - } - - // move assignment - { - { - flat_buffer b1; - ostream(b1) << "Hello"; - flat_buffer b2; - b2 = std::move(b1); - BEAST_EXPECT(b1.size() == 0); - BEAST_EXPECT(b1.capacity() == 0); - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - } - { - using na_t = test::test_allocator; - basic_flat_buffer b1; - ostream(b1) << "Hello"; - basic_flat_buffer b2; - b2 = std::move(b1); - BEAST_EXPECT(b1.get_allocator() == b2.get_allocator()); - BEAST_EXPECT(b1.size() == 0); - BEAST_EXPECT(b1.capacity() == 0); - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - } - { - using na_t = test::test_allocator; - basic_flat_buffer b1; - ostream(b1) << "Hello"; - basic_flat_buffer b2; - b2 = std::move(b1); - BEAST_EXPECT(b1.get_allocator() != b2.get_allocator()); - BEAST_EXPECT(b1.size() == 0); - BEAST_EXPECT(b1.capacity() == 0); - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - } - { - // propagate_on_container_move_assignment : true - using pocma_t = test::test_allocator; - basic_flat_buffer b1; - ostream(b1) << "Hello"; - basic_flat_buffer b2; - b2 = std::move(b1); - BEAST_EXPECT(b1.size() == 0); - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - } - { - // propagate_on_container_move_assignment : false - using pocma_t = test::test_allocator; - basic_flat_buffer b1; - ostream(b1) << "Hello"; - basic_flat_buffer b2; - b2 = std::move(b1); - BEAST_EXPECT(b1.size() == 0); - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - } - } - - // copy assignment - { - { - flat_buffer b1; - ostream(b1) << "Hello"; - flat_buffer b2; - b2 = b1; - BEAST_EXPECT(to_string(b1.data()) == "Hello"); - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - basic_flat_buffer b3; - b3 = b2; - BEAST_EXPECT(to_string(b3.data()) == "Hello"); - } - { - // propagate_on_container_copy_assignment : true - using pocca_t = test::test_allocator; - basic_flat_buffer b1; - ostream(b1) << "Hello"; - basic_flat_buffer b2; - b2 = b1; - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - } - { - // propagate_on_container_copy_assignment : false - using pocca_t = test::test_allocator; - basic_flat_buffer b1; - ostream(b1) << "Hello"; - basic_flat_buffer b2; - b2 = b1; - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - } - } - - // operations - { - string_view const s = "Hello, world!"; - flat_buffer b1{64}; - BEAST_EXPECT(b1.size() == 0); - BEAST_EXPECT(b1.max_size() == 64); - BEAST_EXPECT(b1.capacity() == 0); - ostream(b1) << s; - BEAST_EXPECT(to_string(b1.data()) == s); - { - flat_buffer b2{b1}; - BEAST_EXPECT(to_string(b2.data()) == s); - b2.consume(7); - BEAST_EXPECT(to_string(b2.data()) == s.substr(7)); - } - { - flat_buffer b2{64}; - b2 = b1; - BEAST_EXPECT(to_string(b2.data()) == s); - b2.consume(7); - BEAST_EXPECT(to_string(b2.data()) == s.substr(7)); - } - } - - // cause memmove - { - flat_buffer b{20}; - ostream(b) << "12345"; - b.consume(3); - ostream(b) << "67890123"; - BEAST_EXPECT(to_string(b.data()) == "4567890123"); - } - - // read_size - { - flat_buffer b{10}; - BEAST_EXPECT(read_size(b, 512) == 10); - b.prepare(4); - b.commit(4); - BEAST_EXPECT(read_size(b, 512) == 6); - b.consume(2); - BEAST_EXPECT(read_size(b, 512) == 8); - b.prepare(8); - b.commit(8); - BEAST_EXPECT(read_size(b, 512) == 0); - } - - // swap - { - { - basic_flat_buffer b1; - ostream(b1) << "Hello"; - basic_flat_buffer b2; - BEAST_EXPECT(b1.get_allocator() != b2.get_allocator()); - swap(b1, b2); - BEAST_EXPECT(b1.get_allocator() != b2.get_allocator()); - BEAST_EXPECT(b1.size() == 0); - BEAST_EXPECT(b1.capacity() == 0); - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - } - { - using na_t = test::test_allocator; - na_t a1; - basic_flat_buffer b1{a1}; - na_t a2; - ostream(b1) << "Hello"; - basic_flat_buffer b2{a2}; - BEAST_EXPECT(b1.get_allocator() == a1); - BEAST_EXPECT(b2.get_allocator() == a2); - swap(b1, b2); - BEAST_EXPECT(b1.get_allocator() == b2.get_allocator()); - BEAST_EXPECT(b1.size() == 0); - BEAST_EXPECT(b1.capacity() == 0); - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - } - } - - // prepare - { - flat_buffer b{100}; - b.prepare(10); - b.commit(10); - b.prepare(5); - BEAST_EXPECT(b.capacity() >= 5); - try - { - b.prepare(1000); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - - // shrink to fit - { - flat_buffer b; - BEAST_EXPECT(b.capacity() == 0); - b.prepare(50); - BEAST_EXPECT(b.capacity() == 50); - b.commit(50); - BEAST_EXPECT(b.capacity() == 50); - b.prepare(75); - BEAST_EXPECT(b.capacity() >= 125); - b.shrink_to_fit(); - BEAST_EXPECT(b.capacity() == b.size()); - - } - } - - void - run() override - { - testBuffer(); - } -}; - -BEAST_DEFINE_TESTSUITE(flat_buffer,core,beast); - -} // beast diff --git a/src/beast/test/core/handler_alloc.cpp b/src/beast/test/core/handler_alloc.cpp deleted file mode 100644 index 64acc0749cf..00000000000 --- a/src/beast/test/core/handler_alloc.cpp +++ /dev/null @@ -1,64 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include -#include -#include - -namespace beast { - -class handler_alloc_test : public beast::unit_test::suite -{ -public: - struct handler - { - void - operator()() const - { - } - }; - - // https://github.com/vinniefalco/Beast/issues/432 - void - testRegression432() - { - handler h; - handler_alloc a{h}; - std::list> v{a}; - v.push_back(1); - v.push_back(2); - v.push_back(3); - } - - void - run() override - { - testRegression432(); - - handler h; - handler h2; - handler_alloc a1{h}; - handler_alloc a2{h2}; - BEAST_EXPECT(a2 == a1); - auto a3 = a1; - BEAST_EXPECT(a3 == a1); - { - std::vector> v(a1); - v.reserve(32); - v.resize(10); - } - } -}; - -BEAST_DEFINE_TESTSUITE(handler_alloc,core,beast); - -} // beast - diff --git a/src/beast/test/core/handler_ptr.cpp b/src/beast/test/core/handler_ptr.cpp deleted file mode 100644 index f40bc158a07..00000000000 --- a/src/beast/test/core/handler_ptr.cpp +++ /dev/null @@ -1,80 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include -#include -#include - -namespace beast { - -class handler_ptr_test : public beast::unit_test::suite -{ -public: - struct handler - { - handler() = default; - handler(handler const&) = default; - - void - operator()(bool& b) const - { - b = true; - } - }; - - struct T - { - T(handler&) - { - } - - ~T() - { - } - }; - - struct U - { - U(handler&) - { - throw std::exception{}; - } - }; - - void - run() override - { - handler h; - handler_ptr p1{h}; - handler_ptr p2{p1}; - try - { - handler_ptr p3{h}; - fail(); - } - catch(std::exception const&) - { - pass(); - } - catch(...) - { - fail(); - } - handler_ptr p4{std::move(h)}; - bool b = false; - p4.invoke(std::ref(b)); - BEAST_EXPECT(b); - } -}; - -BEAST_DEFINE_TESTSUITE(handler_ptr,core,beast); - -} // beast - diff --git a/src/beast/test/core/multi_buffer.cpp b/src/beast/test/core/multi_buffer.cpp deleted file mode 100644 index f2e3dbf3b36..00000000000 --- a/src/beast/test/core/multi_buffer.cpp +++ /dev/null @@ -1,592 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include "buffer_test.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { - -BOOST_STATIC_ASSERT(is_dynamic_buffer::value); - -class multi_buffer_test : public beast::unit_test::suite -{ -public: - template - static - bool - eq(basic_multi_buffer const& mb1, - basic_multi_buffer const& mb2) - { - return test::to_string(mb1.data()) == - test::to_string(mb2.data()); - } - - template - void - expect_size(std::size_t n, ConstBufferSequence const& buffers) - { - BEAST_EXPECT(test::size_pre(buffers) == n); - BEAST_EXPECT(test::size_post(buffers) == n); - BEAST_EXPECT(test::size_rev_pre(buffers) == n); - BEAST_EXPECT(test::size_rev_post(buffers) == n); - } - - template - static - void - self_assign(U& u, V&& v) - { - u = std::forward(v); - } - - void - testMatrix1() - { - using namespace test; - using boost::asio::buffer; - std::string const s = "Hello, world"; - BEAST_EXPECT(s.size() == 12); - for(std::size_t i = 1; i < 12; ++i) { - for(std::size_t x = 1; x < 4; ++x) { - for(std::size_t y = 1; y < 4; ++y) { - std::size_t z = s.size() - (x + y); - { - multi_buffer b; - b.commit(buffer_copy(b.prepare(x), buffer(s.data(), x))); - b.commit(buffer_copy(b.prepare(y), buffer(s.data()+x, y))); - b.commit(buffer_copy(b.prepare(z), buffer(s.data()+x+y, z))); - BEAST_EXPECT(to_string(b.data()) == s); - { - multi_buffer mb2{b}; - BEAST_EXPECT(eq(b, mb2)); - } - { - multi_buffer mb2; - mb2 = b; - BEAST_EXPECT(eq(b, mb2)); - } - { - multi_buffer mb2{std::move(b)}; - BEAST_EXPECT(to_string(mb2.data()) == s); - expect_size(0, b.data()); - b = std::move(mb2); - BEAST_EXPECT(to_string(b.data()) == s); - expect_size(0, mb2.data()); - } - self_assign(b, b); - BEAST_EXPECT(to_string(b.data()) == s); - self_assign(b, std::move(b)); - BEAST_EXPECT(to_string(b.data()) == s); - } - }}} - } - - void - testMatrix2() - { - using namespace test; - using boost::asio::buffer; - using boost::asio::buffer_size; - std::string const s = "Hello, world"; - BEAST_EXPECT(s.size() == 12); - for(std::size_t i = 1; i < 12; ++i) { - for(std::size_t x = 1; x < 4; ++x) { - for(std::size_t y = 1; y < 4; ++y) { - for(std::size_t t = 1; t < 4; ++ t) { - for(std::size_t u = 1; u < 4; ++ u) { - std::size_t z = s.size() - (x + y); - std::size_t v = s.size() - (t + u); - { - multi_buffer b; - { - auto d = b.prepare(z); - BEAST_EXPECT(buffer_size(d) == z); - } - { - auto d = b.prepare(0); - BEAST_EXPECT(buffer_size(d) == 0); - } - { - auto d = b.prepare(y); - BEAST_EXPECT(buffer_size(d) == y); - } - { - auto d = b.prepare(x); - BEAST_EXPECT(buffer_size(d) == x); - b.commit(buffer_copy(d, buffer(s.data(), x))); - } - BEAST_EXPECT(b.size() == x); - BEAST_EXPECT(buffer_size(b.data()) == b.size()); - { - auto d = b.prepare(x); - BEAST_EXPECT(buffer_size(d) == x); - } - { - auto d = b.prepare(0); - BEAST_EXPECT(buffer_size(d) == 0); - } - { - auto d = b.prepare(z); - BEAST_EXPECT(buffer_size(d) == z); - } - { - auto d = b.prepare(y); - BEAST_EXPECT(buffer_size(d) == y); - b.commit(buffer_copy(d, buffer(s.data()+x, y))); - } - b.commit(1); - BEAST_EXPECT(b.size() == x + y); - BEAST_EXPECT(buffer_size(b.data()) == b.size()); - { - auto d = b.prepare(x); - BEAST_EXPECT(buffer_size(d) == x); - } - { - auto d = b.prepare(y); - BEAST_EXPECT(buffer_size(d) == y); - } - { - auto d = b.prepare(0); - BEAST_EXPECT(buffer_size(d) == 0); - } - { - auto d = b.prepare(z); - BEAST_EXPECT(buffer_size(d) == z); - b.commit(buffer_copy(d, buffer(s.data()+x+y, z))); - } - b.commit(2); - BEAST_EXPECT(b.size() == x + y + z); - BEAST_EXPECT(buffer_size(b.data()) == b.size()); - BEAST_EXPECT(to_string(b.data()) == s); - b.consume(t); - { - auto d = b.prepare(0); - BEAST_EXPECT(buffer_size(d) == 0); - } - BEAST_EXPECT(to_string(b.data()) == s.substr(t, std::string::npos)); - b.consume(u); - BEAST_EXPECT(to_string(b.data()) == s.substr(t + u, std::string::npos)); - b.consume(v); - BEAST_EXPECT(to_string(b.data()) == ""); - b.consume(1); - { - auto d = b.prepare(0); - BEAST_EXPECT(buffer_size(d) == 0); - } - } - }}}}} - } - - void - testIterators() - { - using boost::asio::buffer_size; - multi_buffer b; - b.prepare(1); - b.commit(1); - b.prepare(2); - b.commit(2); - expect_size(3, b.data()); - b.prepare(1); - expect_size(3, b.prepare(3)); - b.commit(2); - } - - void - testMembers() - { - using namespace test; - - // compare equal - using equal_t = test::test_allocator; - - // compare not equal - using unequal_t = test::test_allocator; - - // construction - { - { - multi_buffer b; - BEAST_EXPECT(b.capacity() == 0); - } - { - multi_buffer b{500}; - BEAST_EXPECT(b.capacity() == 0); - BEAST_EXPECT(b.max_size() == 500); - } - { - unequal_t a1; - basic_multi_buffer b{a1}; - BEAST_EXPECT(b.get_allocator() == a1); - BEAST_EXPECT(b.get_allocator() != unequal_t{}); - } - } - - // move construction - { - { - basic_multi_buffer b1{30}; - BEAST_EXPECT(b1.get_allocator()->nmove == 0); - ostream(b1) << "Hello"; - basic_multi_buffer b2{std::move(b1)}; - BEAST_EXPECT(b2.get_allocator()->nmove == 1); - BEAST_EXPECT(b1.size() == 0); - BEAST_EXPECT(b1.capacity() == 0); - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - BEAST_EXPECT(b1.max_size() == b2.max_size()); - } - // allocators equal - { - basic_multi_buffer b1{30}; - ostream(b1) << "Hello"; - equal_t a; - basic_multi_buffer b2{std::move(b1), a}; - BEAST_EXPECT(b1.size() == 0); - BEAST_EXPECT(b1.capacity() == 0); - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - BEAST_EXPECT(b1.max_size() == b2.max_size()); - } - { - // allocators unequal - basic_multi_buffer b1{30}; - ostream(b1) << "Hello"; - unequal_t a; - basic_multi_buffer b2{std::move(b1), a}; - BEAST_EXPECT(b1.size() == 0); - BEAST_EXPECT(b1.capacity() == 0); - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - BEAST_EXPECT(b1.max_size() == b2.max_size()); - } - } - - // copy construction - { - { - basic_multi_buffer b1; - ostream(b1) << "Hello"; - basic_multi_buffer b2{b1}; - BEAST_EXPECT(b1.get_allocator() == b2.get_allocator()); - BEAST_EXPECT(to_string(b1.data()) == "Hello"); - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - } - { - basic_multi_buffer b1; - ostream(b1) << "Hello"; - unequal_t a; - basic_multi_buffer b2(b1, a); - BEAST_EXPECT(b1.get_allocator() != b2.get_allocator()); - BEAST_EXPECT(to_string(b1.data()) == "Hello"); - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - } - { - basic_multi_buffer b1; - ostream(b1) << "Hello"; - basic_multi_buffer b2(b1); - BEAST_EXPECT(to_string(b1.data()) == "Hello"); - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - } - { - basic_multi_buffer b1; - ostream(b1) << "Hello"; - equal_t a; - basic_multi_buffer b2(b1, a); - BEAST_EXPECT(b2.get_allocator() == a); - BEAST_EXPECT(to_string(b1.data()) == "Hello"); - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - } - } - - // move assignment - { - { - multi_buffer b1; - ostream(b1) << "Hello"; - multi_buffer b2; - b2 = std::move(b1); - BEAST_EXPECT(b1.size() == 0); - BEAST_EXPECT(b1.capacity() == 0); - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - } - { - // propagate_on_container_move_assignment : true - using pocma_t = test::test_allocator; - basic_multi_buffer b1; - ostream(b1) << "Hello"; - basic_multi_buffer b2; - b2 = std::move(b1); - BEAST_EXPECT(b1.size() == 0); - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - } - { - // propagate_on_container_move_assignment : false - using pocma_t = test::test_allocator; - basic_multi_buffer b1; - ostream(b1) << "Hello"; - basic_multi_buffer b2; - b2 = std::move(b1); - BEAST_EXPECT(b1.size() == 0); - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - } - } - - // copy assignment - { - { - multi_buffer b1; - ostream(b1) << "Hello"; - multi_buffer b2; - b2 = b1; - BEAST_EXPECT(to_string(b1.data()) == "Hello"); - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - basic_multi_buffer b3; - b3 = b2; - BEAST_EXPECT(to_string(b3.data()) == "Hello"); - } - { - // propagate_on_container_copy_assignment : true - using pocca_t = test::test_allocator; - basic_multi_buffer b1; - ostream(b1) << "Hello"; - basic_multi_buffer b2; - b2 = b1; - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - } - { - // propagate_on_container_copy_assignment : false - using pocca_t = test::test_allocator; - basic_multi_buffer b1; - ostream(b1) << "Hello"; - basic_multi_buffer b2; - b2 = b1; - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - } - } - - // prepare - { - { - multi_buffer b{100}; - try - { - b.prepare(b.max_size() + 1); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - string_view const s = "Hello, world!"; - multi_buffer b1{64}; - BEAST_EXPECT(b1.size() == 0); - BEAST_EXPECT(b1.max_size() == 64); - BEAST_EXPECT(b1.capacity() == 0); - ostream(b1) << s; - BEAST_EXPECT(to_string(b1.data()) == s); - { - multi_buffer b2{b1}; - BEAST_EXPECT(to_string(b2.data()) == s); - b2.consume(7); - BEAST_EXPECT(to_string(b2.data()) == s.substr(7)); - } - { - multi_buffer b2{64}; - b2 = b1; - BEAST_EXPECT(to_string(b2.data()) == s); - b2.consume(7); - BEAST_EXPECT(to_string(b2.data()) == s.substr(7)); - } - } - { - multi_buffer b; - b.prepare(1000); - BEAST_EXPECT(b.capacity() >= 1000); - b.commit(1); - BEAST_EXPECT(b.size() == 1); - BEAST_EXPECT(b.capacity() >= 1000); - b.prepare(1000); - BEAST_EXPECT(b.size() == 1); - BEAST_EXPECT(b.capacity() >= 1000); - b.prepare(1500); - BEAST_EXPECT(b.capacity() >= 1000); - } - { - multi_buffer b; - b.prepare(1000); - BEAST_EXPECT(b.capacity() >= 1000); - b.commit(1); - BEAST_EXPECT(b.capacity() >= 1000); - b.prepare(1000); - BEAST_EXPECT(b.capacity() >= 1000); - b.prepare(2000); - BEAST_EXPECT(b.capacity() >= 2000); - b.commit(2); - } - { - multi_buffer b; - b.prepare(1000); - BEAST_EXPECT(b.capacity() >= 1000); - b.prepare(2000); - BEAST_EXPECT(b.capacity() >= 2000); - b.prepare(4000); - BEAST_EXPECT(b.capacity() >= 4000); - b.prepare(50); - BEAST_EXPECT(b.capacity() >= 50); - } - } - - // commit - { - multi_buffer b; - b.prepare(1000); - BEAST_EXPECT(b.capacity() >= 1000); - b.commit(1000); - BEAST_EXPECT(b.size() == 1000); - BEAST_EXPECT(b.capacity() >= 1000); - b.consume(1000); - BEAST_EXPECT(b.size() == 0); - BEAST_EXPECT(b.capacity() == 0); - b.prepare(1000); - b.commit(650); - BEAST_EXPECT(b.size() == 650); - BEAST_EXPECT(b.capacity() >= 1000); - b.prepare(1000); - BEAST_EXPECT(b.capacity() >= 1650); - b.commit(100); - BEAST_EXPECT(b.size() == 750); - BEAST_EXPECT(b.capacity() >= 1000); - b.prepare(1000); - BEAST_EXPECT(b.capacity() >= 2000); - b.commit(500); - } - - // consume - { - multi_buffer b; - b.prepare(1000); - BEAST_EXPECT(b.capacity() >= 1000); - b.commit(1000); - BEAST_EXPECT(b.size() == 1000); - BEAST_EXPECT(b.capacity() >= 1000); - b.prepare(1000); - BEAST_EXPECT(b.capacity() >= 2000); - b.commit(750); - BEAST_EXPECT(b.size() == 1750); - b.consume(500); - BEAST_EXPECT(b.size() == 1250); - b.consume(500); - BEAST_EXPECT(b.size() == 750); - b.prepare(250); - b.consume(750); - BEAST_EXPECT(b.size() == 0); - b.prepare(1000); - b.commit(800); - BEAST_EXPECT(b.size() == 800); - b.prepare(1000); - b.commit(600); - BEAST_EXPECT(b.size() == 1400); - b.consume(1400); - BEAST_EXPECT(b.size() == 0); - } - - // swap - { - { - // propagate_on_container_swap : true - using pocs_t = test::test_allocator; - pocs_t a1, a2; - BEAST_EXPECT(a1 != a2); - basic_multi_buffer b1{a1}; - ostream(b1) << "Hello"; - basic_multi_buffer b2{a2}; - BEAST_EXPECT(b1.get_allocator() == a1); - BEAST_EXPECT(b2.get_allocator() == a2); - swap(b1, b2); - BEAST_EXPECT(b1.get_allocator() == a2); - BEAST_EXPECT(b2.get_allocator() == a1); - BEAST_EXPECT(b1.size() == 0); - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - swap(b1, b2); - BEAST_EXPECT(b1.get_allocator() == a1); - BEAST_EXPECT(b2.get_allocator() == a2); - BEAST_EXPECT(to_string(b1.data()) == "Hello"); - BEAST_EXPECT(b2.size() == 0); - } - { - // propagate_on_container_swap : false - using pocs_t = test::test_allocator; - pocs_t a1, a2; - BEAST_EXPECT(a1 == a2); - BEAST_EXPECT(a1.id() != a2.id()); - basic_multi_buffer b1{a1}; - ostream(b1) << "Hello"; - basic_multi_buffer b2{a2}; - BEAST_EXPECT(b1.get_allocator() == a1); - BEAST_EXPECT(b2.get_allocator() == a2); - swap(b1, b2); - BEAST_EXPECT(b1.get_allocator().id() == a1.id()); - BEAST_EXPECT(b2.get_allocator().id() == a2.id()); - BEAST_EXPECT(b1.size() == 0); - BEAST_EXPECT(to_string(b2.data()) == "Hello"); - swap(b1, b2); - BEAST_EXPECT(b1.get_allocator().id() == a1.id()); - BEAST_EXPECT(b2.get_allocator().id() == a2.id()); - BEAST_EXPECT(to_string(b1.data()) == "Hello"); - BEAST_EXPECT(b2.size() == 0); - } - } - - // read_size - { - multi_buffer b{10}; - BEAST_EXPECT(read_size(b, 512) == 10); - b.prepare(4); - b.commit(4); - BEAST_EXPECT(read_size(b, 512) == 6); - b.consume(2); - BEAST_EXPECT(read_size(b, 512) == 8); - b.prepare(8); - b.commit(8); - BEAST_EXPECT(read_size(b, 512) == 0); - } - } - - void - run() override - { - testMatrix1(); - testMatrix2(); - testIterators(); - testMembers(); - } -}; - -BEAST_DEFINE_TESTSUITE(multi_buffer,core,beast); - -} // beast diff --git a/src/beast/test/core/ostream.cpp b/src/beast/test/core/ostream.cpp deleted file mode 100644 index 25b805ec317..00000000000 --- a/src/beast/test/core/ostream.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include -#include -#include -#include - -namespace beast { - -class ostream_test : public beast::unit_test::suite -{ -public: - void - run() override - { - { - multi_buffer b; - auto os = ostream(b); - os << "Hello, world!\n"; - os.flush(); - BEAST_EXPECT(boost::lexical_cast( - buffers(b.data())) == "Hello, world!\n"); - auto os2 = std::move(os); - } - { - auto const s = - "0123456789abcdef" "0123456789abcdef" "0123456789abcdef" "0123456789abcdef" - "0123456789abcdef" "0123456789abcdef" "0123456789abcdef" "0123456789abcdef" - "0123456789abcdef" "0123456789abcdef" "0123456789abcdef" "0123456789abcdef" - "0123456789abcdef" "0123456789abcdef" "0123456789abcdef" "0123456789abcdef" - "0123456789abcdef" "0123456789abcdef" "0123456789abcdef" "0123456789abcdef" - "0123456789abcdef" "0123456789abcdef" "0123456789abcdef" "0123456789abcdef" - "0123456789abcdef" "0123456789abcdef" "0123456789abcdef" "0123456789abcdef" - "0123456789abcdef" "0123456789abcdef" "0123456789abcdef" "0123456789abcdef"; - multi_buffer b; - ostream(b) << s; - BEAST_EXPECT(boost::lexical_cast( - buffers(b.data())) == s); - } - } -}; - -BEAST_DEFINE_TESTSUITE(ostream,core,beast); - -} // beast diff --git a/src/beast/test/core/prepare_buffers.cpp b/src/beast/test/core/prepare_buffers.cpp deleted file mode 100644 index f7db38403bb..00000000000 --- a/src/beast/test/core/prepare_buffers.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - diff --git a/src/beast/test/core/read_size.cpp b/src/beast/test/core/read_size.cpp deleted file mode 100644 index 40a01c0c4ed..00000000000 --- a/src/beast/test/core/read_size.cpp +++ /dev/null @@ -1,44 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include -#include -#include -#include - -#include - -namespace beast { - -class read_size_test : public beast::unit_test::suite -{ -public: - template - void - check() - { - DynamicBuffer buffer; - read_size(buffer, 65536); - pass(); - } - - void - run() override - { - check(); - check(); - check(); - check(); - } -}; - -BEAST_DEFINE_TESTSUITE(read_size,core,beast); - -} // beast diff --git a/src/beast/test/core/sha1.cpp b/src/beast/test/core/sha1.cpp deleted file mode 100644 index d85b2e2cbd3..00000000000 --- a/src/beast/test/core/sha1.cpp +++ /dev/null @@ -1,80 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#include -#include -#include - -namespace beast { -namespace detail { - -class sha1_test : public beast::unit_test::suite -{ -public: - static - inline - std::uint8_t - unhex(char c) - { - if(c >= '0' && c <= '9') - return c - '0'; - if(c >= 'a' && c <= 'f') - return c - 'a' + 10; - if(c >= 'A' && c <= 'F') - return c - 'A' + 10; - throw std::invalid_argument("not a hex digit"); - } - - static - std::string - unhex(std::string const& in) - { - std::string out; - out.reserve(in.size() / 2); - if(in.size() % 2) - throw std::domain_error("invalid hex string"); - for(std::size_t i = 0; i < in.size(); i += 2) - out.push_back( - (unhex(in[i])<<4) + unhex(in[i+1])); - return out; - } - - void - check(std::string const& message, std::string const& answer) - { - std::string digest; - digest = unhex(answer); - sha1_context ctx; - std::string result; - result.resize(sha1_context::digest_size); - init(ctx); - update(ctx, message.data(), message.size()); - finish(ctx, &result[0]); - BEAST_EXPECT(result == digest); - } - - void - run() - { - // http://www.di-mgt.com.au/sha_testvectors.html - // - check("abc", - "a9993e36" "4706816a" "ba3e2571" "7850c26c" "9cd0d89d"); - check("", - "da39a3ee" "5e6b4b0d" "3255bfef" "95601890" "afd80709"); - check("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", - "84983e44" "1c3bd26e" "baae4aa1" "f95129e5" "e54670f1"); - check("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu", - "a49b2446" "a02c645b" "f419f995" "b6709125" "3a04a259"); - } -}; - -BEAST_DEFINE_TESTSUITE(sha1,core,beast); - -} // test -} // beast - diff --git a/src/beast/test/core/span.cpp b/src/beast/test/core/span.cpp deleted file mode 100644 index ec8c7d3e045..00000000000 --- a/src/beast/test/core/span.cpp +++ /dev/null @@ -1,56 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include -#include - -namespace beast { - -class span_test : public beast::unit_test::suite -{ -public: - BOOST_STATIC_ASSERT( - detail::is_contiguous_container< - string_view, char const>::value); - - struct base {}; - struct derived : base {}; - - BOOST_STATIC_ASSERT(detail::is_contiguous_container< - std::vector, char>::value); - - BOOST_STATIC_ASSERT(detail::is_contiguous_container< - std::vector, char const>::value); - - BOOST_STATIC_ASSERT(! detail::is_contiguous_container< - std::vector, base>::value); - - BOOST_STATIC_ASSERT(! detail::is_contiguous_container< - std::vector, base const>::value); - - void - testSpan() - { - span sp{"hello", 5}; - BEAST_EXPECT(sp.size() == 5); - std::string s("world"); - sp = s; - } - - void - run() override - { - testSpan(); - } -}; - -BEAST_DEFINE_TESTSUITE(span,core,beast); - -} // beast diff --git a/src/beast/test/core/static_buffer.cpp b/src/beast/test/core/static_buffer.cpp deleted file mode 100644 index fb0f4f628e5..00000000000 --- a/src/beast/test/core/static_buffer.cpp +++ /dev/null @@ -1,233 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include "buffer_test.hpp" - -#include -#include -#include -#include - -namespace beast { - -static_assert( - is_dynamic_buffer::value, - "DynamicBuffer requirements not met"); - -class static_buffer_test : public beast::unit_test::suite -{ -public: - void - testStaticBuffer() - { - using namespace test; - using boost::asio::buffer; - using boost::asio::buffer_cast; - using boost::asio::buffer_size; - char buf[12]; - std::string const s = "Hello, world"; - BEAST_EXPECT(s.size() == sizeof(buf)); - for(std::size_t i = 1; i < 4; ++i) { - for(std::size_t j = 1; j < 4; ++j) { - for(std::size_t x = 1; x < 4; ++x) { - for(std::size_t y = 1; y < 4; ++y) { - for(std::size_t t = 1; t < 4; ++ t) { - for(std::size_t u = 1; u < 4; ++ u) { - std::size_t z = sizeof(buf) - (x + y); - std::size_t v = sizeof(buf) - (t + u); - { - std::memset(buf, 0, sizeof(buf)); - static_buffer_n ba; - { - auto d = ba.prepare(z); - BEAST_EXPECT(buffer_size(d) == z); - } - { - auto d = ba.prepare(0); - BEAST_EXPECT(buffer_size(d) == 0); - } - { - auto d = ba.prepare(y); - BEAST_EXPECT(buffer_size(d) == y); - } - { - auto d = ba.prepare(x); - BEAST_EXPECT(buffer_size(d) == x); - ba.commit(buffer_copy(d, buffer(s.data(), x))); - } - BEAST_EXPECT(ba.size() == x); - BEAST_EXPECT(buffer_size(ba.data()) == ba.size()); - { - auto d = ba.prepare(x); - BEAST_EXPECT(buffer_size(d) == x); - } - { - auto d = ba.prepare(0); - BEAST_EXPECT(buffer_size(d) == 0); - } - { - auto d = ba.prepare(z); - BEAST_EXPECT(buffer_size(d) == z); - } - { - auto d = ba.prepare(y); - BEAST_EXPECT(buffer_size(d) == y); - ba.commit(buffer_copy(d, buffer(s.data()+x, y))); - } - ba.commit(1); - BEAST_EXPECT(ba.size() == x + y); - BEAST_EXPECT(buffer_size(ba.data()) == ba.size()); - { - auto d = ba.prepare(x); - BEAST_EXPECT(buffer_size(d) == x); - } - { - auto d = ba.prepare(y); - BEAST_EXPECT(buffer_size(d) == y); - } - { - auto d = ba.prepare(0); - BEAST_EXPECT(buffer_size(d) == 0); - } - { - auto d = ba.prepare(z); - BEAST_EXPECT(buffer_size(d) == z); - ba.commit(buffer_copy(d, buffer(s.data()+x+y, z))); - } - ba.commit(2); - BEAST_EXPECT(ba.size() == x + y + z); - BEAST_EXPECT(buffer_size(ba.data()) == ba.size()); - BEAST_EXPECT(to_string(ba.data()) == s); - ba.consume(t); - { - auto d = ba.prepare(0); - BEAST_EXPECT(buffer_size(d) == 0); - } - BEAST_EXPECT(to_string(ba.data()) == s.substr(t, std::string::npos)); - ba.consume(u); - BEAST_EXPECT(to_string(ba.data()) == s.substr(t + u, std::string::npos)); - ba.consume(v); - BEAST_EXPECT(to_string(ba.data()) == ""); - ba.consume(1); - { - auto d = ba.prepare(0); - BEAST_EXPECT(buffer_size(d) == 0); - } - try - { - ba.prepare(ba.capacity() - ba.size() + 1); - fail(); - } - catch(...) - { - pass(); - } - } - }}}}}} - } - - void - testBuffer() - { - using namespace test; - string_view const s = "Hello, world!"; - - // static_buffer - { - char buf[64]; - static_buffer b{buf, sizeof(buf)}; - ostream(b) << s; - BEAST_EXPECT(to_string(b.data()) == s); - b.consume(b.size()); - BEAST_EXPECT(to_string(b.data()) == ""); - } - - // static_buffer_n - { - static_buffer_n<64> b1; - BEAST_EXPECT(b1.size() == 0); - BEAST_EXPECT(b1.max_size() == 64); - BEAST_EXPECT(b1.capacity() == 64); - ostream(b1) << s; - BEAST_EXPECT(to_string(b1.data()) == s); - { - static_buffer_n<64> b2{b1}; - BEAST_EXPECT(to_string(b2.data()) == s); - b2.consume(7); - BEAST_EXPECT(to_string(b2.data()) == s.substr(7)); - } - { - static_buffer_n<64> b2; - b2 = b1; - BEAST_EXPECT(to_string(b2.data()) == s); - b2.consume(7); - BEAST_EXPECT(to_string(b2.data()) == s.substr(7)); - } - } - - // cause memmove - { - static_buffer_n<10> b; - write_buffer(b, "12345"); - b.consume(3); - write_buffer(b, "67890123"); - BEAST_EXPECT(to_string(b.data()) == "4567890123"); - try - { - b.prepare(1); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - - // read_size - { - static_buffer_n<10> b; - BEAST_EXPECT(read_size(b, 512) == 10); - b.prepare(4); - b.commit(4); - BEAST_EXPECT(read_size(b, 512) == 6); - b.consume(2); - BEAST_EXPECT(read_size(b, 512) == 8); - b.prepare(8); - b.commit(8); - BEAST_EXPECT(read_size(b, 512) == 0); - } - - // base - { - static_buffer_n<10> b; - [&](static_buffer& base) - { - BEAST_EXPECT(base.max_size() == b.capacity()); - } - (b.base()); - - [&](static_buffer const& base) - { - BEAST_EXPECT(base.max_size() == b.capacity()); - } - (b.base()); - } - } - - void run() override - { - testBuffer(); - //testStaticBuffer(); - } -}; - -BEAST_DEFINE_TESTSUITE(static_buffer,core,beast); - -} // beastp diff --git a/src/beast/test/core/static_string.cpp b/src/beast/test/core/static_string.cpp deleted file mode 100644 index 227b2e721ff..00000000000 --- a/src/beast/test/core/static_string.cpp +++ /dev/null @@ -1,1476 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include - -namespace beast { - -class static_string_test : public beast::unit_test::suite -{ -public: - void - testConstruct() - { - { - static_string<1> s; - BEAST_EXPECT(s.empty()); - BEAST_EXPECT(s.size() == 0); - BEAST_EXPECT(s == ""); - BEAST_EXPECT(*s.end() == 0); - } - { - static_string<4> s1(3, 'x'); - BEAST_EXPECT(! s1.empty()); - BEAST_EXPECT(s1.size() == 3); - BEAST_EXPECT(s1 == "xxx"); - BEAST_EXPECT(*s1.end() == 0); - try - { - static_string<2> s2(3, 'x'); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - static_string<5> s1("12345"); - BEAST_EXPECT(*s1.end() == 0); - static_string<3> s2(s1, 2); - BEAST_EXPECT(s2 == "345"); - BEAST_EXPECT(*s2.end() == 0); - static_string<0> s3(s1, 5); - BEAST_EXPECT(s3.empty()); - BEAST_EXPECT(s3.front() == 0); - BEAST_EXPECT(*s3.end() == 0); - } - { - static_string<5> s1("12345"); - static_string<2> s2(s1, 1, 2); - BEAST_EXPECT(s2 == "23"); - BEAST_EXPECT(*s2.end() == 0); - static_string<0> s3(s1, 5, 1); - BEAST_EXPECT(s3.empty()); - BEAST_EXPECT(s3.front() == 0); - BEAST_EXPECT(*s3.end() == 0); - try - { - static_string<5> s4(s1, 6); - fail("", __FILE__, __LINE__); - } - catch(std::out_of_range const&) - { - pass(); - } - } - { - static_string<5> s1("UVXYZ", 3); - BEAST_EXPECT(s1 == "UVX"); - BEAST_EXPECT(*s1.end() == 0); - static_string<5> s2("X\0""Y\0""Z", 3); - BEAST_EXPECT(std::memcmp( - s2.data(), "X\0""Y", 3) == 0); - BEAST_EXPECT(*s2.end() == 0); - } - { - static_string<5> s1("12345"); - static_string<3> s2( - s1.begin() + 1, s1.begin() + 3); - BEAST_EXPECT(s2 == "23"); - BEAST_EXPECT(*s2.end() == 0); - } - { - static_string<5> s1("12345"); - static_string<5> s2(s1); - BEAST_EXPECT(s2 == "12345"); - BEAST_EXPECT(*s2.end() == 0); - static_string<6> s3(s1); - BEAST_EXPECT(s3 == "12345"); - BEAST_EXPECT(*s3.end() == 0); - try - { - static_string<4> s4(s1); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - static_string<3> s1({'1', '2', '3'}); - BEAST_EXPECT(s1 == "123"); - BEAST_EXPECT(*s1.end() == 0); - BEAST_EXPECT( - static_string<0>({}) == static_string<0>()); - try - { - static_string<2> s2({'1', '2', '3'}); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - static_string<3> s1( - string_view("123")); - BEAST_EXPECT(s1 == "123"); - BEAST_EXPECT(*s1.end() == 0); - try - { - static_string<2> s2( - string_view("123")); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - static_string<5> s1( - std::string("12345"), 2, 2); - BEAST_EXPECT(s1 == "34"); - BEAST_EXPECT(*s1.end() == 0); - try - { - static_string<2> s2( - std::string("12345"), 1, 3); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - } - - void - testAssign() - { - { - static_string<3> s1("123"); - static_string<3> s2; - s2 = s1; - BEAST_EXPECT(s2 == "123"); - BEAST_EXPECT(*s2.end() == 0); - } - { - static_string<3> s1("123"); - static_string<5> s2; - s2 = s1; - BEAST_EXPECT(s2 == "123"); - BEAST_EXPECT(*s2.end() == 0); - try - { - static_string<1> s3; - s3 = s1; - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - static_string<3> s1; - s1 = "123"; - BEAST_EXPECT(s1 == "123"); - BEAST_EXPECT(*s1.end() == 0); - try - { - static_string<1> s2; - s2 = "123"; - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - static_string<1> s1; - s1 = 'x'; - BEAST_EXPECT(s1 == "x"); - BEAST_EXPECT(*s1.end() == 0); - try - { - static_string<0> s2; - s2 = 'x'; - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - static_string<3> s1; - s1 = {'1', '2', '3'}; - BEAST_EXPECT(s1 == "123"); - BEAST_EXPECT(*s1.end() == 0); - try - { - static_string<1> s2; - s2 = {'1', '2', '3'}; - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - static_string<3> s1; - s1 = string_view("123"); - BEAST_EXPECT(s1 == "123"); - BEAST_EXPECT(*s1.end() == 0); - try - { - static_string<1> s2; - s2 = string_view("123"); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - - { - static_string<4> s1; - s1.assign(3, 'x'); - BEAST_EXPECT(s1 == "xxx"); - BEAST_EXPECT(*s1.end() == 0); - try - { - static_string<2> s2; - s2.assign(3, 'x'); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - static_string<5> s1("12345"); - BEAST_EXPECT(*s1.end() == 0); - static_string<5> s2; - s2.assign(s1); - BEAST_EXPECT(s2 == "12345"); - BEAST_EXPECT(*s2.end() == 0); - } - { - static_string<5> s1("12345"); - BEAST_EXPECT(*s1.end() == 0); - static_string<7> s2; - s2.assign(s1); - BEAST_EXPECT(s2 == "12345"); - BEAST_EXPECT(*s2.end() == 0); - try - { - static_string<3> s3; - s3.assign(s1); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - static_string<5> s1("12345"); - static_string<5> s2; - s2.assign(s1, 1); - BEAST_EXPECT(s2 == "2345"); - BEAST_EXPECT(*s2.end() == 0); - s2.assign(s1, 1, 2); - BEAST_EXPECT(s2 == "23"); - BEAST_EXPECT(*s2.end() == 0); - s2.assign(s1, 1, 100); - BEAST_EXPECT(s2 == "2345"); - BEAST_EXPECT(*s2.end() == 0); - try - { - s2.assign(s1, 6); - fail("", __FILE__, __LINE__); - } - catch(std::out_of_range const&) - { - pass(); - } - try - { - static_string<3> s3; - s3.assign(s1, 1); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - static_string<5> s1; - s1.assign("12"); - BEAST_EXPECT(s1 == "12"); - BEAST_EXPECT(*s1.end() == 0); - s1.assign("12345"); - BEAST_EXPECT(s1 == "12345"); - BEAST_EXPECT(*s1.end() == 0); - } - { - static_string<5> s1; - s1.assign("12345", 3); - BEAST_EXPECT(s1 == "123"); - BEAST_EXPECT(*s1.end() == 0); - } - { - static_string<5> s1("12345"); - static_string<3> s2; - s2.assign(s1.begin(), s1.begin() + 2); - BEAST_EXPECT(s2 == "12"); - BEAST_EXPECT(*s2.end() == 0); - try - { - s2.assign(s1.begin(), s1.end()); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - static_string<5> s1; - s1.assign({'1', '2', '3'}); - BEAST_EXPECT(s1 == "123"); - BEAST_EXPECT(*s1.end() == 0); - try - { - static_string<1> s2; - s2.assign({'1', '2', '3'}); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - static_string<5> s1; - s1.assign(string_view("123")); - BEAST_EXPECT(s1 == "123"); - BEAST_EXPECT(*s1.end() == 0); - s1.assign(string_view("12345")); - BEAST_EXPECT(s1 == "12345"); - BEAST_EXPECT(*s1.end() == 0); - try - { - s1.assign(string_view("1234567")); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - static_string<5> s1; - s1.assign(std::string("12345"), 2, 2); - BEAST_EXPECT(s1 == "34"); - BEAST_EXPECT(*s1.end() == 0); - s1.assign(std::string("12345"), 3); - BEAST_EXPECT(s1 == "45"); - BEAST_EXPECT(*s1.end() == 0); - try - { - static_string<2> s2; - s2.assign( - std::string("12345"), 1, 3); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - } - - void - testAccess() - { - { - static_string<5> s("12345"); - BEAST_EXPECT(s.at(1) == '2'); - BEAST_EXPECT(s.at(4) == '5'); - try - { - BEAST_EXPECT(s.at(5) == 0); - fail("", __FILE__, __LINE__); - } - catch(std::out_of_range const&) - { - pass(); - } - } - { - static_string<5> const s("12345"); - BEAST_EXPECT(s.at(1) == '2'); - BEAST_EXPECT(s.at(4) == '5'); - try - { - BEAST_EXPECT(s.at(5) == 0); - fail("", __FILE__, __LINE__); - } - catch(std::out_of_range const&) - { - pass(); - } - } - { - static_string<5> s("12345"); - BEAST_EXPECT(s[1] == '2'); - BEAST_EXPECT(s[4] == '5'); - s[1] = '_'; - BEAST_EXPECT(s == "1_345"); - } - { - static_string<5> const s("12345"); - BEAST_EXPECT(s[1] == '2'); - BEAST_EXPECT(s[4] == '5'); - BEAST_EXPECT(s[5] == 0); - } - { - static_string<3> s("123"); - BEAST_EXPECT(s.front() == '1'); - BEAST_EXPECT(s.back() == '3'); - s.front() = '_'; - BEAST_EXPECT(s == "_23"); - s.back() = '_'; - BEAST_EXPECT(s == "_2_"); - } - { - static_string<3> const s("123"); - BEAST_EXPECT(s.front() == '1'); - BEAST_EXPECT(s.back() == '3'); - } - { - static_string<3> s("123"); - BEAST_EXPECT(std::memcmp( - s.data(), "123", 3) == 0); - } - { - static_string<3> const s("123"); - BEAST_EXPECT(std::memcmp( - s.data(), "123", 3) == 0); - } - { - static_string<3> s("123"); - BEAST_EXPECT(std::memcmp( - s.c_str(), "123\0", 4) == 0); - } - { - static_string<3> s("123"); - string_view sv = s; - BEAST_EXPECT(static_string<5>(sv) == "123"); - } - } - - void - testIterators() - { - { - static_string<3> s; - BEAST_EXPECT(std::distance( - s.begin(), s.end()) == 0); - BEAST_EXPECT(std::distance( - s.rbegin(), s.rend()) == 0); - s = "123"; - BEAST_EXPECT(std::distance( - s.begin(), s.end()) == 3); - BEAST_EXPECT(std::distance( - s.rbegin(), s.rend()) == 3); - } - { - static_string<3> const s("123"); - BEAST_EXPECT(std::distance( - s.begin(), s.end()) == 3); - BEAST_EXPECT(std::distance( - s.cbegin(), s.cend()) == 3); - BEAST_EXPECT(std::distance( - s.rbegin(), s.rend()) == 3); - BEAST_EXPECT(std::distance( - s.crbegin(), s.crend()) == 3); - } - } - - void - testCapacity() - { - static_string<3> s; - BEAST_EXPECT(s.empty()); - BEAST_EXPECT(s.size() == 0); - BEAST_EXPECT(s.length() == 0); - BEAST_EXPECT(s.max_size() == 3); - BEAST_EXPECT(s.capacity() == 3); - s = "123"; - BEAST_EXPECT(! s.empty()); - BEAST_EXPECT(s.size() == 3); - BEAST_EXPECT(s.length() == 3); - s.reserve(0); - s.reserve(3); - try - { - s.reserve(4); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - s.shrink_to_fit(); - BEAST_EXPECT(! s.empty()); - BEAST_EXPECT(s.size() == 3); - BEAST_EXPECT(s.length() == 3); - BEAST_EXPECT(*s.end() == 0); - } - - void - testOperations() - { - // - // clear - // - - { - static_string<3> s("123"); - s.clear(); - BEAST_EXPECT(s.empty()); - BEAST_EXPECT(*s.end() == 0); - } - - // - // insert - // - - { - static_string<7> s1("12345"); - s1.insert(2, 2, '_'); - BEAST_EXPECT(s1 == "12__345"); - BEAST_EXPECT(*s1.end() == 0); - try - { - static_string<6> s2("12345"); - s2.insert(2, 2, '_'); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - try - { - static_string<6> s2("12345"); - s2.insert(6, 2, '_'); - fail("", __FILE__, __LINE__); - } - catch(std::out_of_range const&) - { - pass(); - } - } - { - static_string<7> s1("12345"); - s1.insert(2, "__"); - BEAST_EXPECT(s1 == "12__345"); - BEAST_EXPECT(*s1.end() == 0); - try - { - static_string<6> s2("12345"); - s2.insert(2, "__"); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - try - { - static_string<6> s2("12345"); - s2.insert(6, "__"); - fail("", __FILE__, __LINE__); - } - catch(std::out_of_range const&) - { - pass(); - } - } - { - static_string<7> s1("12345"); - s1.insert(2, "TUV", 2); - BEAST_EXPECT(s1 == "12TU345"); - BEAST_EXPECT(*s1.end() == 0); - try - { - static_string<6> s2("12345"); - s2.insert(2, "TUV", 2); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - try - { - static_string<6> s2("12345"); - s2.insert(6, "TUV", 2); - fail("", __FILE__, __LINE__); - } - catch(std::out_of_range const&) - { - pass(); - } - } - { - static_string<7> s1("12345"); - s1.insert(2, static_string<3>("TU")); - BEAST_EXPECT(s1 == "12TU345"); - BEAST_EXPECT(*s1.end() == 0); - try - { - static_string<6> s2("12345"); - s2.insert(2, static_string<3>("TUV")); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - try - { - static_string<6> s2("12345"); - s2.insert(6, static_string<3>("TUV")); - fail("", __FILE__, __LINE__); - } - catch(std::out_of_range const&) - { - pass(); - } - } - { - static_string<7> s1("12345"); - s1.insert(2, static_string<3>("TUV"), 1); - BEAST_EXPECT(s1 == "12UV345"); - BEAST_EXPECT(*s1.end() == 0); - s1 = "12345"; - s1.insert(2, static_string<3>("TUV"), 1, 1); - BEAST_EXPECT(s1 == "12U345"); - BEAST_EXPECT(*s1.end() == 0); - try - { - static_string<6> s2("12345"); - s2.insert(2, static_string<3>("TUV"), 1, 2); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - try - { - static_string<6> s2("12345"); - s2.insert(6, static_string<3>("TUV"), 1, 2); - fail("", __FILE__, __LINE__); - } - catch(std::out_of_range const&) - { - pass(); - } - } - { - static_string<4> s1("123"); - s1.insert(s1.begin() + 1, '_'); - BEAST_EXPECT(s1 == "1_23"); - BEAST_EXPECT(*s1.end() == 0); - try - { - static_string<3> s2("123"); - s2.insert(s2.begin() + 1, '_'); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - static_string<4> s1("12"); - s1.insert(s1.begin() + 1, 2, '_'); - BEAST_EXPECT(s1 == "1__2"); - BEAST_EXPECT(*s1.end() == 0); - try - { - static_string<4> s2("123"); - s2.insert(s2.begin() + 1, 2, ' '); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - static_string<3> s1("123"); - static_string<5> s2("UV"); - s2.insert(s2.begin() + 1, s1.begin(), s1.end()); - BEAST_EXPECT(s2 == "U123V"); - BEAST_EXPECT(*s2.end() == 0); - try - { - static_string<4> s3("UV"); - s3.insert(s3.begin() + 1, s1.begin(), s1.end()); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - static_string<5> s1("123"); - s1.insert(1, string_view("UV")); - BEAST_EXPECT(s1 == "1UV23"); - BEAST_EXPECT(*s1.end() == 0); - try - { - static_string<4> s2("123"); - s2.insert(1, string_view("UV")); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - try - { - static_string<5> s2("123"); - s2.insert(5, string_view("UV")); - fail("", __FILE__, __LINE__); - } - catch(std::out_of_range const&) - { - pass(); - } - } - { - static_string<5> s1("123"); - s1.insert(1, std::string("UV")); - BEAST_EXPECT(s1 == "1UV23"); - BEAST_EXPECT(*s1.end() == 0); - try - { - s1.insert(1, std::string("UV")); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - static_string<6> s1("123"); - s1.insert(1, std::string("UVX"), 1); - BEAST_EXPECT(s1 == "1VX23"); - BEAST_EXPECT(*s1.end() == 0); - s1.insert(4, std::string("PQR"), 1, 1); - BEAST_EXPECT(s1 == "1VX2Q3"); - BEAST_EXPECT(*s1.end() == 0); - try - { - s1.insert(4, std::string("PQR"), 1, 1); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - - // - // erase - // - - { - static_string<9> s1("123456789"); - BEAST_EXPECT(s1.erase(1, 1) == "13456789"); - BEAST_EXPECT(s1 == "13456789"); - BEAST_EXPECT(*s1.end() == 0); - BEAST_EXPECT(s1.erase(5) == "13456"); - BEAST_EXPECT(s1 == "13456"); - BEAST_EXPECT(*s1.end() == 0); - try - { - s1.erase(7); - fail("", __FILE__, __LINE__); - } - catch(std::out_of_range const&) - { - pass(); - } - } - { - static_string<9> s1("123456789"); - BEAST_EXPECT(*s1.erase(s1.begin() + 5) == '7'); - BEAST_EXPECT(s1 == "12345789"); - BEAST_EXPECT(*s1.end() == 0); - } - { - static_string<9> s1("123456789"); - BEAST_EXPECT(*s1.erase( - s1.begin() + 5, s1.begin() + 7) == '8'); - BEAST_EXPECT(s1 == "1234589"); - BEAST_EXPECT(*s1.end() == 0); - } - - // - // push_back - // - - { - static_string<3> s1("12"); - s1.push_back('3'); - BEAST_EXPECT(s1 == "123"); - try - { - s1.push_back('4'); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - static_string<0> s2; - try - { - s2.push_back('_'); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - - // - // pop_back - // - - { - static_string<3> s1("123"); - s1.pop_back(); - BEAST_EXPECT(s1 == "12"); - BEAST_EXPECT(*s1.end() == 0); - s1.pop_back(); - BEAST_EXPECT(s1 == "1"); - BEAST_EXPECT(*s1.end() == 0); - s1.pop_back(); - BEAST_EXPECT(s1.empty()); - BEAST_EXPECT(*s1.end() == 0); - } - - // - // append - // - - { - static_string<3> s1("1"); - s1.append(2, '_'); - BEAST_EXPECT(s1 == "1__"); - BEAST_EXPECT(*s1.end() == 0); - try - { - static_string<2> s2("1"); - s2.append(2, '_'); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - static_string<2> s1("__"); - static_string<3> s2("1"); - s2.append(s1); - BEAST_EXPECT(s2 == "1__"); - BEAST_EXPECT(*s2.end() == 0); - try - { - static_string<2> s3("1"); - s3.append(s1); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - static_string<3> s1("XYZ"); - static_string<4> s2("12"); - s2.append(s1, 1); - BEAST_EXPECT(s2 == "12YZ"); - BEAST_EXPECT(*s2.end() == 0); - static_string<3> s3("12"); - s3.append(s1, 1, 1); - BEAST_EXPECT(s3 == "12Y"); - BEAST_EXPECT(*s3.end() == 0); - try - { - static_string<3> s4("12"); - s4.append(s1, 3); - fail("", __FILE__, __LINE__); - } - catch(std::out_of_range const&) - { - pass(); - } - try - { - static_string<3> s4("12"); - s4.append(s1, 1); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - static_string<4> s1("12"); - s1.append("XYZ", 2); - BEAST_EXPECT(s1 == "12XY"); - BEAST_EXPECT(*s1.end() == 0); - try - { - static_string<3> s3("12"); - s3.append("XYZ", 2); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - static_string<5> s1("12"); - s1.append("XYZ"); - BEAST_EXPECT(s1 == "12XYZ"); - BEAST_EXPECT(*s1.end() == 0); - try - { - static_string<4> s2("12"); - s2.append("XYZ"); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - static_string<3> s1("XYZ"); - static_string<5> s2("12"); - s2.append(s1.begin(), s1.end()); - BEAST_EXPECT(s2 == "12XYZ"); - BEAST_EXPECT(*s2.end() == 0); - try - { - static_string<4> s3("12"); - s3.append(s1.begin(), s1.end()); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - static_string<5> s1("123"); - s1.append({'X', 'Y'}); - BEAST_EXPECT(s1 == "123XY"); - BEAST_EXPECT(*s1.end() == 0); - try - { - static_string<4> s2("123"); - s2.append({'X', 'Y'}); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - string_view s1("XYZ"); - static_string<5> s2("12"); - s2.append(s1); - BEAST_EXPECT(s2 == "12XYZ"); - BEAST_EXPECT(*s2.end() == 0); - try - { - static_string<4> s3("12"); - s3.append(s1); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - static_string<6> s1("123"); - s1.append(std::string("UVX"), 1); - BEAST_EXPECT(s1 == "123VX"); - BEAST_EXPECT(*s1.end() == 0); - s1.append(std::string("PQR"), 1, 1); - BEAST_EXPECT(s1 == "123VXQ"); - BEAST_EXPECT(*s1.end() == 0); - try - { - static_string<3> s2("123"); - s2.append(std::string("PQR"), 1, 1); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - - // - // operator+= - // - - { - static_string<2> s1("__"); - static_string<3> s2("1"); - s2 += s1; - BEAST_EXPECT(s2 == "1__"); - BEAST_EXPECT(*s2.end() == 0); - try - { - static_string<2> s3("1"); - s3 += s1; - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - static_string<3> s1("12"); - s1 += '3'; - BEAST_EXPECT(s1 == "123"); - try - { - s1 += '4'; - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - static_string<4> s1("12"); - s1 += "34"; - BEAST_EXPECT(s1 == "1234"); - try - { - s1 += "5"; - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - static_string<4> s1("12"); - s1 += {'3', '4'}; - BEAST_EXPECT(s1 == "1234"); - try - { - s1 += {'5'}; - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - { - string_view s1("34"); - static_string<4> s2("12"); - s2 += s1; - BEAST_EXPECT(s2 == "1234"); - try - { - s2 += s1; - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - } - - void - testCompare() - { - using str1 = static_string<1>; - using str2 = static_string<2>; - { - str1 s1; - str2 s2; - s1 = "1"; - s2 = "22"; - BEAST_EXPECT(s1.compare(s2) < 0); - BEAST_EXPECT(s2.compare(s1) > 0); - BEAST_EXPECT(s1 < "10"); - BEAST_EXPECT(s2 > "1"); - BEAST_EXPECT("10" > s1); - BEAST_EXPECT("1" < s2); - BEAST_EXPECT(s1 < "20"); - BEAST_EXPECT(s2 > "1"); - BEAST_EXPECT(s2 > "2"); - } - { - str2 s1("x"); - str2 s2("x"); - BEAST_EXPECT(s1 == s2); - BEAST_EXPECT(s1 <= s2); - BEAST_EXPECT(s1 >= s2); - BEAST_EXPECT(! (s1 < s2)); - BEAST_EXPECT(! (s1 > s2)); - BEAST_EXPECT(! (s1 != s2)); - } - { - str1 s1("x"); - str2 s2("x"); - BEAST_EXPECT(s1 == s2); - BEAST_EXPECT(s1 <= s2); - BEAST_EXPECT(s1 >= s2); - BEAST_EXPECT(! (s1 < s2)); - BEAST_EXPECT(! (s1 > s2)); - BEAST_EXPECT(! (s1 != s2)); - } - { - str2 s("x"); - BEAST_EXPECT(s == "x"); - BEAST_EXPECT(s <= "x"); - BEAST_EXPECT(s >= "x"); - BEAST_EXPECT(! (s < "x")); - BEAST_EXPECT(! (s > "x")); - BEAST_EXPECT(! (s != "x")); - BEAST_EXPECT("x" == s); - BEAST_EXPECT("x" <= s); - BEAST_EXPECT("x" >= s); - BEAST_EXPECT(! ("x" < s)); - BEAST_EXPECT(! ("x" > s)); - BEAST_EXPECT(! ("x" != s)); - } - { - str2 s("x"); - BEAST_EXPECT(s <= "y"); - BEAST_EXPECT(s < "y"); - BEAST_EXPECT(s != "y"); - BEAST_EXPECT(! (s == "y")); - BEAST_EXPECT(! (s >= "y")); - BEAST_EXPECT(! (s > "x")); - BEAST_EXPECT("y" >= s); - BEAST_EXPECT("y" > s); - BEAST_EXPECT("y" != s); - BEAST_EXPECT(! ("y" == s)); - BEAST_EXPECT(! ("y" <= s)); - BEAST_EXPECT(! ("y" < s)); - } - { - str1 s1("x"); - str2 s2("y"); - BEAST_EXPECT(s1 <= s2); - BEAST_EXPECT(s1 < s2); - BEAST_EXPECT(s1 != s2); - BEAST_EXPECT(! (s1 == s2)); - BEAST_EXPECT(! (s1 >= s2)); - BEAST_EXPECT(! (s1 > s2)); - } - { - str1 s1("x"); - str2 s2("xx"); - BEAST_EXPECT(s1 < s2); - BEAST_EXPECT(s2 > s1); - } - { - str1 s1("x"); - str2 s2("yy"); - BEAST_EXPECT(s1 < s2); - BEAST_EXPECT(s2 > s1); - } - } - - void - testSwap() - { - { - static_string<3> s1("123"); - static_string<3> s2("XYZ"); - swap(s1, s2); - BEAST_EXPECT(s1 == "XYZ"); - BEAST_EXPECT(*s1.end() == 0); - BEAST_EXPECT(s2 == "123"); - BEAST_EXPECT(*s2.end() == 0); - static_string<3> s3("UV"); - swap(s2, s3); - BEAST_EXPECT(s2 == "UV"); - BEAST_EXPECT(*s2.end() == 0); - BEAST_EXPECT(s3 == "123"); - BEAST_EXPECT(*s3.end() == 0); - } - { - static_string<5> s1("123"); - static_string<7> s2("XYZ"); - swap(s1, s2); - BEAST_EXPECT(s1 == "XYZ"); - BEAST_EXPECT(*s1.end() == 0); - BEAST_EXPECT(s2 == "123"); - BEAST_EXPECT(*s2.end() == 0); - static_string<3> s3("UV"); - swap(s2, s3); - BEAST_EXPECT(s2 == "UV"); - BEAST_EXPECT(*s2.end() == 0); - BEAST_EXPECT(s3 == "123"); - BEAST_EXPECT(*s3.end() == 0); - try - { - static_string<5> s4("12345"); - static_string<3> s5("XYZ"); - swap(s4, s5); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - try - { - static_string<3> s4("XYZ"); - static_string<5> s5("12345"); - swap(s4, s5); - fail("", __FILE__, __LINE__); - } - catch(std::length_error const&) - { - pass(); - } - } - } - - void - testGeneral() - { - using str1 = static_string<1>; - using str2 = static_string<2>; - { - str1 s1; - BEAST_EXPECT(s1 == ""); - BEAST_EXPECT(s1.empty()); - BEAST_EXPECT(s1.size() == 0); - BEAST_EXPECT(s1.max_size() == 1); - BEAST_EXPECT(s1.capacity() == 1); - BEAST_EXPECT(s1.begin() == s1.end()); - BEAST_EXPECT(s1.cbegin() == s1.cend()); - BEAST_EXPECT(s1.rbegin() == s1.rend()); - BEAST_EXPECT(s1.crbegin() == s1.crend()); - try - { - BEAST_EXPECT(s1.at(0) == 0); - fail(); - } - catch(std::exception const&) - { - pass(); - } - BEAST_EXPECT(s1.data()[0] == 0); - BEAST_EXPECT(*s1.c_str() == 0); - BEAST_EXPECT(std::distance(s1.begin(), s1.end()) == 0); - BEAST_EXPECT(std::distance(s1.cbegin(), s1.cend()) == 0); - BEAST_EXPECT(std::distance(s1.rbegin(), s1.rend()) == 0); - BEAST_EXPECT(std::distance(s1.crbegin(), s1.crend()) == 0); - BEAST_EXPECT(s1.compare(s1) == 0); - } - { - str1 const s1; - BEAST_EXPECT(s1 == ""); - BEAST_EXPECT(s1.empty()); - BEAST_EXPECT(s1.size() == 0); - BEAST_EXPECT(s1.max_size() == 1); - BEAST_EXPECT(s1.capacity() == 1); - BEAST_EXPECT(s1.begin() == s1.end()); - BEAST_EXPECT(s1.cbegin() == s1.cend()); - BEAST_EXPECT(s1.rbegin() == s1.rend()); - BEAST_EXPECT(s1.crbegin() == s1.crend()); - try - { - BEAST_EXPECT(s1.at(0) == 0); - fail(); - } - catch(std::exception const&) - { - pass(); - } - BEAST_EXPECT(s1.data()[0] == 0); - BEAST_EXPECT(*s1.c_str() == 0); - BEAST_EXPECT(std::distance(s1.begin(), s1.end()) == 0); - BEAST_EXPECT(std::distance(s1.cbegin(), s1.cend()) == 0); - BEAST_EXPECT(std::distance(s1.rbegin(), s1.rend()) == 0); - BEAST_EXPECT(std::distance(s1.crbegin(), s1.crend()) == 0); - BEAST_EXPECT(s1.compare(s1) == 0); - } - { - str1 s1; - str1 s2("x"); - BEAST_EXPECT(s2 == "x"); - BEAST_EXPECT(s2[0] == 'x'); - BEAST_EXPECT(s2.at(0) == 'x'); - BEAST_EXPECT(s2.front() == 'x'); - BEAST_EXPECT(s2.back() == 'x'); - str1 const s3(s2); - BEAST_EXPECT(s3 == "x"); - BEAST_EXPECT(s3[0] == 'x'); - BEAST_EXPECT(s3.at(0) == 'x'); - BEAST_EXPECT(s3.front() == 'x'); - BEAST_EXPECT(s3.back() == 'x'); - s2 = "y"; - BEAST_EXPECT(s2 == "y"); - BEAST_EXPECT(s3 == "x"); - s1 = s2; - BEAST_EXPECT(s1 == "y"); - s1.clear(); - BEAST_EXPECT(s1.empty()); - BEAST_EXPECT(s1.size() == 0); - } - { - str2 s1("x"); - str1 s2(s1); - BEAST_EXPECT(s2 == "x"); - str1 s3; - s3 = s2; - BEAST_EXPECT(s3 == "x"); - s1 = "xy"; - BEAST_EXPECT(s1.size() == 2); - BEAST_EXPECT(s1[0] == 'x'); - BEAST_EXPECT(s1[1] == 'y'); - BEAST_EXPECT(s1.at(0) == 'x'); - BEAST_EXPECT(s1.at(1) == 'y'); - BEAST_EXPECT(s1.front() == 'x'); - BEAST_EXPECT(s1.back() == 'y'); - auto const s4 = s1; - BEAST_EXPECT(s4[0] == 'x'); - BEAST_EXPECT(s4[1] == 'y'); - BEAST_EXPECT(s4.at(0) == 'x'); - BEAST_EXPECT(s4.at(1) == 'y'); - BEAST_EXPECT(s4.front() == 'x'); - BEAST_EXPECT(s4.back() == 'y'); - try - { - s3 = s1; - fail(); - } - catch(std::exception const&) - { - pass(); - } - try - { - str1 s5(s1); - fail(); - } - catch(std::exception const&) - { - pass(); - } - } - { - str1 s1("x"); - str2 s2; - s2 = s1; - try - { - s1.resize(2); - fail(); - } - catch(std::length_error const&) - { - pass(); - } - } - pass(); - } - - void - testToStaticString() - { - BEAST_EXPECT(to_static_string(0) == "0"); - BEAST_EXPECT(to_static_string(1) == "1"); - BEAST_EXPECT(to_static_string(0xffff) == "65535"); - BEAST_EXPECT(to_static_string(0x10000) == "65536"); - BEAST_EXPECT(to_static_string(0xffffffff) == "4294967295"); - - BEAST_EXPECT(to_static_string(-1) == "-1"); - BEAST_EXPECT(to_static_string(-65535) == "-65535"); - BEAST_EXPECT(to_static_string(-65536) == "-65536"); - BEAST_EXPECT(to_static_string(-4294967295ll) == "-4294967295"); - - BEAST_EXPECT(to_static_string(0) == "0"); - BEAST_EXPECT(to_static_string(1) == "1"); - BEAST_EXPECT(to_static_string(0xffff) == "65535"); - BEAST_EXPECT(to_static_string(0x10000) == "65536"); - BEAST_EXPECT(to_static_string(0xffffffff) == "4294967295"); - } - - void - run() override - { - testConstruct(); - testAssign(); - testAccess(); - testIterators(); - testCapacity(); - testOperations(); - testCompare(); - testSwap(); - - testGeneral(); - testToStaticString(); - } -}; - -BEAST_DEFINE_TESTSUITE(static_string,core,beast); - -} // beast diff --git a/src/beast/test/core/string.cpp b/src/beast/test/core/string.cpp deleted file mode 100644 index c8afa23c86e..00000000000 --- a/src/beast/test/core/string.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include diff --git a/src/beast/test/core/string_param.cpp b/src/beast/test/core/string_param.cpp deleted file mode 100644 index 4ccfc9a0376..00000000000 --- a/src/beast/test/core/string_param.cpp +++ /dev/null @@ -1,79 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include -#include - -namespace beast { - -class string_param_test : public unit_test::suite -{ -public: - struct nop {}; - - void - check(string_param const& v, string_view s) - { - BEAST_EXPECT(static_cast(v) == s); - } - - class repeater - { - std::size_t n_; - - public: - explicit - repeater(std::size_t n) - : n_(n) - { - } - - friend - std::ostream& - operator<<(std::ostream& os, repeater const& v) - { - return os << std::string(v.n_, '*'); - } - }; - - void - testConversion() - { - // Make sure things convert correctly - check(std::string("hello"), "hello"); - check("xyz", "xyz"); - check(1, "1"); - check(12, "12"); - check(123, "123"); - check(1234, "1234"); - check(12345, "12345"); - check({"a", "b"}, "ab"); - check({1, 2, 3}, "123"); - } - - void - testStaticOstream() - { - // exercise static_ostream for coverage - std::string s(500, '*'); - check(repeater{500}, s); - } - - void - run() override - { - testConversion(); - testStaticOstream(); - } -}; - -BEAST_DEFINE_TESTSUITE(string_param,core,beast); - -} // beast diff --git a/src/beast/test/core/type_traits.cpp b/src/beast/test/core/type_traits.cpp deleted file mode 100644 index 4706155bd38..00000000000 --- a/src/beast/test/core/type_traits.cpp +++ /dev/null @@ -1,155 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include -#include -#include - -namespace beast { - -namespace detail { - -namespace { - -// -// is_invocable -// - -struct is_invocable_udt1 -{ - void operator()(int) const; -}; - -struct is_invocable_udt2 -{ - int operator()(int) const; -}; - -struct is_invocable_udt3 -{ - int operator()(int); -}; - -#ifndef __INTELLISENSE__ -// VFALCO Fails to compile with Intellisense -BOOST_STATIC_ASSERT(is_invocable::value); -BOOST_STATIC_ASSERT(is_invocable::value); -BOOST_STATIC_ASSERT(is_invocable::value); -BOOST_STATIC_ASSERT(! is_invocable::value); -BOOST_STATIC_ASSERT(! is_invocable::value); -BOOST_STATIC_ASSERT(! is_invocable::value); -BOOST_STATIC_ASSERT(! is_invocable::value); -#endif - -// -// get_lowest_layer -// - -struct F1 {}; -struct F2 {}; - -template -struct F3 -{ - using next_layer_type = - typename std::remove_reference::type; - - using lowest_layer_type = typename - get_lowest_layer::type; -}; - -template -struct F4 -{ - using next_layer_type = - typename std::remove_reference::type; - - using lowest_layer_type = typename - get_lowest_layer::type; -}; - -BOOST_STATIC_ASSERT(std::is_same::type, F1>::value); -BOOST_STATIC_ASSERT(std::is_same::type, F2>::value); -BOOST_STATIC_ASSERT(std::is_same>::type, F1>::value); -BOOST_STATIC_ASSERT(std::is_same>::type, F2>::value); -BOOST_STATIC_ASSERT(std::is_same>::type, F1>::value); -BOOST_STATIC_ASSERT(std::is_same>::type, F2>::value); -BOOST_STATIC_ASSERT(std::is_same>>::type, F1>::value); -BOOST_STATIC_ASSERT(std::is_same>>::type, F2>::value); - -} // (anonymous) - -} // detail - -// -// buffer concepts -// - -namespace { - -struct T {}; - -BOOST_STATIC_ASSERT(is_const_buffer_sequence::value); -BOOST_STATIC_ASSERT(! is_const_buffer_sequence::value); - -BOOST_STATIC_ASSERT(is_mutable_buffer_sequence::value); -BOOST_STATIC_ASSERT(! is_mutable_buffer_sequence::value); - -BOOST_STATIC_ASSERT(is_dynamic_buffer::value); - -} // (anonymous) - -// -// handler concepts -// - -namespace { - -struct H -{ - void operator()(int); -}; - -} // anonymous - -BOOST_STATIC_ASSERT(is_completion_handler::value); -BOOST_STATIC_ASSERT(! is_completion_handler::value); - -// -// stream concepts -// - -namespace { - -using stream_type = boost::asio::ip::tcp::socket; - -struct not_a_stream -{ - void - get_io_service(); -}; - -BOOST_STATIC_ASSERT(has_get_io_service::value); -BOOST_STATIC_ASSERT(is_async_read_stream::value); -BOOST_STATIC_ASSERT(is_async_write_stream::value); -BOOST_STATIC_ASSERT(is_async_stream::value); -BOOST_STATIC_ASSERT(is_sync_read_stream::value); -BOOST_STATIC_ASSERT(is_sync_write_stream::value); -BOOST_STATIC_ASSERT(is_sync_stream::value); - -BOOST_STATIC_ASSERT(! has_get_io_service::value); -BOOST_STATIC_ASSERT(! is_async_read_stream::value); -BOOST_STATIC_ASSERT(! is_async_write_stream::value); -BOOST_STATIC_ASSERT(! is_sync_read_stream::value); -BOOST_STATIC_ASSERT(! is_sync_write_stream::value); - -} // (anonymous) - -} // beast diff --git a/src/beast/test/core/zlib.cpp b/src/beast/test/core/zlib.cpp deleted file mode 100644 index cb963dcec04..00000000000 --- a/src/beast/test/core/zlib.cpp +++ /dev/null @@ -1,232 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include -#include - -#include -#include -#include -#include -#include - -namespace beast { -namespace zlib { - -class zlib_test : public beast::unit_test::suite -{ -public: - class buffer - { - std::size_t size_ = 0; - std::size_t capacity_ = 0; - std::unique_ptr p_; - - public: - buffer() = default; - buffer(buffer&&) = default; - buffer& operator=(buffer&&) = default; - - - explicit - buffer(std::size_t capacity) - { - reserve(capacity); - } - - bool - empty() const - { - return size_ == 0; - } - - std::size_t - size() const - { - return size_; - } - - std::size_t - capacity() const - { - return capacity_; - } - - std::uint8_t const* - data() const - { - return p_.get(); - } - - std::uint8_t* - data() - { - return p_.get(); - } - - void - reserve(std::size_t capacity) - { - if(capacity != capacity_) - { - p_.reset(new std::uint8_t[capacity]); - capacity_ = capacity; - } - } - - void - resize(std::size_t size) - { - assert(size <= capacity_); - size_ = size; - } - }; - - buffer - make_source1(std::size_t size) - { - std::mt19937 rng; - buffer b(size); - auto p = b.data(); - std::size_t n = 0; - static std::string const chars( - "01234567890{}\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" - "{{{{{{{{{{}}}}}}}}}} "); - while(n < size) - { - *p++ = chars[rng()%chars.size()]; - ++n; - } - b.resize(n); - return b; - } - - buffer - make_source2(std::size_t size) - { - std::mt19937 rng; - std::array const i{0, 65535}; - std::array const w{0, 1}; - std::piecewise_linear_distribution d( - i.begin(), i.end(), w.begin()); - buffer b(size); - auto p = b.data(); - std::size_t n = 0; - while(n < size) - { - if(n == 1) - { - *p++ = rng()%256; - ++n; - continue; - } - auto const v = static_cast(d(rng)); - *p++ = v>>8; - *p++ = v&0xff; - n += 2; - - } - b.resize(n); - return b; - } - - void - checkInflate(buffer const& input, buffer const& original) - { - for(std::size_t i = 0; i < input.size(); ++i) - { - buffer output(original.size()); - inflate_stream zs; - zs.avail_in = 0; - zs.next_in = 0; - zs.next_out = output.data(); - zs.avail_out = output.capacity(); - if(i > 0) - { - zs.next_in = (Byte*)input.data(); - zs.avail_in = i; - auto result = zs.write(Z_FULL_FLUSH); - expect(result == Z_OK); - } - zs.next_in = (Byte*)input.data() + i; - zs.avail_in = input.size() - i; - auto result = zs.write(Z_FULL_FLUSH); - output.resize(output.capacity() - zs.avail_out); - expect(result == Z_OK); - expect(output.size() == original.size()); - expect(std::memcmp( - output.data(), original.data(), original.size()) == 0); - } - } - - void testSpecial() - { - { - deflate_stream zs; - } - { - inflate_stream zs; - } - } - - void testCompress() - { - static std::size_t constexpr N = 2048; - for(int source = 0; source <= 1; ++source) - { - buffer original; - switch(source) - { - case 0: - original = make_source1(N); - break; - case 1: - original = make_source2(N); - break; - } - for(int level = 0; level <= 9; ++level) - { - for(int strategy = 0; strategy <= 4; ++strategy) - { - for(int wbits = 15; wbits <= 15; ++wbits) - { - deflate_stream zs; - zs.avail_in = 0; - zs.next_in = 0; - expect(deflate_stream::deflateInit2(&zs, - level, - wbits, - 4, - strategy) == Z_OK); - buffer output(deflate_stream::deflateBound(&zs, original.size())); - zs.next_in = (Byte*)original.data(); - zs.avail_in = original.size(); - zs.next_out = output.data(); - zs.avail_out = output.capacity(); - auto result = zs.deflate(Z_FULL_FLUSH); - expect(result == Z_OK); - output.resize(output.capacity() - zs.avail_out); - checkInflate(output, original); - } - } - } - } - } - - void run() override - { - testSpecial(); - testCompress(); - } -}; - -BEAST_DEFINE_TESTSUITE(zlib,core,beast); - -} // zlib -} // beast - diff --git a/src/beast/test/exemplars.cpp b/src/beast/test/exemplars.cpp deleted file mode 100644 index 9a8256a4705..00000000000 --- a/src/beast/test/exemplars.cpp +++ /dev/null @@ -1,345 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -class BodyReader; -class BodyWriter; - -//[concept_Body - -struct Body -{ - // The type of message::body when used - struct value_type; - - /// The algorithm used for extracting buffers - using reader = BodyReader; - - /// The algorithm used for inserting buffers - using writer = BodyWriter; - - /// Returns the body's payload size - static - std::uint64_t - size(value_type const& v); -}; - -static_assert(is_body::value, ""); - -//] - -struct Body_BodyReader { - struct value_type{}; -//[concept_BodyReader - -struct BodyReader -{ -public: - /// The type of buffer returned by `get`. - using const_buffers_type = boost::asio::const_buffers_1; - - /** Construct the reader. - - @param msg The message whose body is to be retrieved. - - @param ec Set to the error, if any occurred. - */ - template - explicit - BodyReader(message const& msg); - - /** Initialize the reader - - This is called after construction and before the first - call to `get`. The message is valid and complete upon - entry. - - @param ec Set to the error, if any occurred. - */ - void - init(error_code& ec) - { - // The specification requires this to indicate "no error" - ec.assign(0, ec.category()); - } - - /** Returns the next buffer in the body. - - @li If the return value is `boost::none` (unseated optional) and - `ec` does not contain an error, this indicates the end of the - body, no more buffers are present. - - @li If the optional contains a value, the first element of the - pair represents a @b ConstBufferSequence containing one or - more octets of the body data. The second element indicates - whether or not there are additional octets of body data. - A value of `true` means there is more data, and that the - implementation will perform a subsequent call to `get`. - A value of `false` means there is no more body data. - - @li If `ec` contains an error code, the return value is ignored. - - @param ec Set to the error, if any occurred. - */ - boost::optional> - get(error_code& ec) - { - // The specification requires this to indicate "no error" - ec.assign(0, ec.category()); - - return boost::none; // for exposition only - } -}; - -//] - using reader = BodyReader; -}; - -static_assert(is_body_reader::value, ""); - -struct Body_BodyWriter { - struct value_type{}; -//[concept_BodyWriter - -struct BodyWriter -{ - /** Construct the writer. - - @param msg The message whose body is to be stored. - */ - template - explicit - BodyWriter(message& msg); - - /** Initialize the writer - - This is called after construction and before the first - call to `put`. The message is valid and complete upon - entry. - - @param ec Set to the error, if any occurred. - */ - void - init( - boost::optional const& content_length, - error_code& ec) - { - boost::ignore_unused(content_length); - - // The specification requires this to indicate "no error" - ec.assign(0, ec.category()); - } - - /** Store buffers. - - This is called zero or more times with parsed body octets. - - @param buffers The constant buffer sequence to store. - - @param ec Set to the error, if any occurred. - - @return The number of bytes transferred from the input buffers. - */ - template - std::size_t - put(ConstBufferSequence const& buffers, error_code& ec) - { - // The specification requires this to indicate "no error" - ec = {}; - - return boost::asio::buffer_size(buffers); - } - - /** Called when the body is complete. - - @param ec Set to the error, if any occurred. - */ - void - finish(error_code& ec) - { - // The specification requires this to indicate "no error" - ec = {}; - } -}; - -//] - using writer = BodyWriter; -}; - -static_assert(is_body_writer::value, ""); - -//[concept_Fields - -class Fields -{ -public: - struct reader; - -protected: - /** Returns the request-method string. - - @note Only called for requests. - */ - string_view - get_method_impl() const; - - /** Returns the request-target string. - - @note Only called for requests. - */ - string_view - get_target_impl() const; - - /** Returns the response reason-phrase string. - - @note Only called for responses. - */ - string_view - get_reason_impl() const; - - /** Returns the chunked Transfer-Encoding setting - */ - bool - get_chunked_impl() const; - - /** Returns the keep-alive setting - */ - bool - get_keep_alive_impl(unsigned version) const; - - /** Set or clear the method string. - - @note Only called for requests. - */ - void - set_method_impl(string_view s); - - /** Set or clear the target string. - - @note Only called for requests. - */ - void - set_target_impl(string_view s); - - /** Set or clear the reason string. - - @note Only called for responses. - */ - void - set_reason_impl(string_view s); - - /** Sets or clears the chunked Transfer-Encoding value - */ - void - set_chunked_impl(bool value); - - /** Sets or clears the Content-Length field - */ - void - set_content_length_impl(boost::optional); - - /** Adjusts the Connection field - */ - void - set_keep_alive_impl(unsigned version, bool keep_alive); -}; - -static_assert(is_fields::value, - "Fields requirements not met"); - -//] - -struct Fields_FieldsReader { - using F = Fields_FieldsReader; -//[concept_FieldsReader - -struct FieldsReader -{ - // The type of buffers returned by `get` - struct const_buffers_type; - - // Constructor for requests - FieldsReader(F const& f, unsigned version, verb method); - - // Constructor for responses - FieldsReader(F const& f, unsigned version, unsigned status); - - // Returns `true` if keep-alive is indicated - bool - keep_alive(); - - // Returns the serialized header buffers - const_buffers_type - get(); -}; - -//] -}; - -//[concept_File - -struct File -{ - /** Default constructor - - There is no open file initially. - */ - File(); - - /** Destructor - - If the file is open it is first closed. - */ - ~File(); - - /// Returns `true` if the file is open - bool - is_open() const; - - /// Close the file if open - void - close(error_code& ec); - - /// Open a file at the given path with the specified mode - void - open(char const* path, file_mode mode, error_code& ec); - - /// Return the size of the open file - std::uint64_t - size(error_code& ec) const; - - /// Return the current position in the open file - std::uint64_t - pos(error_code& ec) const; - - /// Adjust the current position in the open file - void - seek(std::uint64_t offset, error_code& ec); - - /// Read from the open file - std::size_t - read(void* buffer, std::size_t n, error_code& ec) const; - - /// Write to the open file - std::size_t - write(void const* buffer, std::size_t n, error_code& ec); -}; - -//] - -} // http -} // beast diff --git a/src/beast/test/http.cpp b/src/beast/test/http.cpp deleted file mode 100644 index 66854b43287..00000000000 --- a/src/beast/test/http.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include diff --git a/src/beast/test/http/CMakeLists.txt b/src/beast/test/http/CMakeLists.txt deleted file mode 100644 index a609f6b1566..00000000000 --- a/src/beast/test/http/CMakeLists.txt +++ /dev/null @@ -1,47 +0,0 @@ -# Part of Beast - -GroupSources(example example) -GroupSources(extras/beast extras) -GroupSources(include/beast beast) - -GroupSources(test/http "/") - -add_executable (http-tests - ${BEAST_INCLUDES} - ${EXAMPLE_INCLUDES} - ${EXTRAS_INCLUDES} - message_fuzz.hpp - test_parser.hpp - ../../extras/beast/unit_test/main.cpp - basic_parser.cpp - buffer_body.cpp - doc_examples.cpp - doc_snippets.cpp - dynamic_body.cpp - empty_body.cpp - error.cpp - field.cpp - fields.cpp - file_body.cpp - message.cpp - parser.cpp - read.cpp - rfc7230.cpp - serializer.cpp - span_body.cpp - status.cpp - string_body.cpp - type_traits.cpp - vector_body.cpp - verb.cpp - write.cpp -) - -target_link_libraries(http-tests - Beast - ${Boost_PROGRAM_OPTIONS_LIBRARY} - ${Boost_FILESYSTEM_LIBRARY} - ${Boost_COROUTINE_LIBRARY} - ${Boost_THREAD_LIBRARY} - ${Boost_CONTEXT_LIBRARY} - ) diff --git a/src/beast/test/http/Jamfile b/src/beast/test/http/Jamfile deleted file mode 100644 index aca163002cd..00000000000 --- a/src/beast/test/http/Jamfile +++ /dev/null @@ -1,31 +0,0 @@ -# -# Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -# -# 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) -# - -unit-test http-tests : - ../../extras/beast/unit_test/main.cpp - basic_parser.cpp - buffer_body.cpp - doc_examples.cpp - doc_snippets.cpp - dynamic_body.cpp - error.cpp - field.cpp - fields.cpp - file_body.cpp - message.cpp - parser.cpp - read.cpp - rfc7230.cpp - serializer.cpp - span_body.cpp - status.cpp - string_body.cpp - type_traits.cpp - vector_body.cpp - verb.cpp - write.cpp - ; diff --git a/src/beast/test/http/basic_parser.cpp b/src/beast/test/http/basic_parser.cpp deleted file mode 100644 index 6303fa7f28b..00000000000 --- a/src/beast/test/http/basic_parser.cpp +++ /dev/null @@ -1,1164 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include "test_parser.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -class basic_parser_test : public beast::unit_test::suite -{ -public: - enum parse_flag - { - chunked = 1, - connection_keep_alive = 2, - connection_close = 4, - connection_upgrade = 8, - upgrade = 16, - }; - - class expect_version - { - suite& s_; - int version_; - - public: - expect_version(suite& s, int version) - : s_(s) - , version_(version) - { - } - - template - void - operator()(Parser const& p) const - { - s_.BEAST_EXPECT(p.version == version_); - } - }; - - class expect_status - { - suite& s_; - int status_; - - public: - expect_status(suite& s, int status) - : s_(s) - , status_(status) - { - } - - template - void - operator()(Parser const& p) const - { - s_.BEAST_EXPECT(p.status == status_); - } - }; - - class expect_flags - { - suite& s_; - unsigned flags_; - - public: - expect_flags(suite& s, unsigned flags) - : s_(s) - , flags_(flags) - { - } - - template - void - operator()(Parser const& p) const - { - if(flags_ & parse_flag::chunked) - s_.BEAST_EXPECT(p.is_chunked()); - if(flags_ & parse_flag::connection_keep_alive) - s_.BEAST_EXPECT(p.is_keep_alive()); - if(flags_ & parse_flag::connection_close) - s_.BEAST_EXPECT(! p.is_keep_alive()); - if(flags_ & parse_flag::upgrade) - s_.BEAST_EXPECT(! p.is_upgrade()); - } - }; - - class expect_keepalive - { - suite& s_; - bool v_; - - public: - expect_keepalive(suite& s, bool v) - : s_(s) - , v_(v) - { - } - - template - void - operator()(Parser const& p) const - { - s_.BEAST_EXPECT(p.is_keep_alive() == v_); - } - }; - - class expect_body - { - suite& s_; - std::string const& body_; - - public: - expect_body(expect_body&&) = default; - - expect_body(suite& s, std::string const& v) - : s_(s) - , body_(v) - { - } - - template - void - operator()(Parser const& p) const - { - s_.BEAST_EXPECT(p.body == body_); - } - }; - - //-------------------------------------------------------------------------- - - template - typename std::enable_if< - is_const_buffer_sequence::value>::type - parsegrind(ConstBufferSequence const& buffers, - Test const& test, bool skip = false) - { - auto const size = boost::asio::buffer_size(buffers); - for(std::size_t i = 1; i < size - 1; ++i) - { - Parser p; - p.eager(true); - p.skip(skip); - error_code ec; - consuming_buffers cb{buffers}; - auto n = p.put(buffer_prefix(i, cb), ec); - if(! BEAST_EXPECTS(! ec || - ec == error::need_more, ec.message())) - continue; - if(! BEAST_EXPECT(! p.is_done())) - continue; - cb.consume(n); - n = p.put(cb, ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - continue; - if(! BEAST_EXPECT(n == boost::asio::buffer_size(cb))) - continue; - if(p.need_eof()) - { - p.put_eof(ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - continue; - } - if(! BEAST_EXPECT(p.is_done())) - continue; - test(p); - } - for(std::size_t i = 1; i < size - 1; ++i) - { - Parser p; - p.eager(true); - error_code ec; - consuming_buffers cb{buffers}; - cb.consume(i); - auto n = p.put(buffer_cat( - buffer_prefix(i, buffers), cb), ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - continue; - if(! BEAST_EXPECT(n == size)) - continue; - if(p.need_eof()) - { - p.put_eof(ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - continue; - } - test(p); - } - } - - template - void - parsegrind(string_view msg, Test const& test, bool skip = false) - { - parsegrind(boost::asio::const_buffers_1{ - msg.data(), msg.size()}, test, skip); - } - - template - typename std::enable_if< - is_const_buffer_sequence::value>::type - parsegrind(ConstBufferSequence const& buffers) - { - parsegrind(buffers, [](Parser const&){}); - } - - template - void - parsegrind(string_view msg) - { - parsegrind(msg, [](Parser const&){}); - } - - template - void - failgrind(string_view msg, error_code const& result) - { - for(std::size_t i = 1; i < msg.size() - 1; ++i) - { - Parser p; - p.eager(true); - error_code ec; - consuming_buffers cb{ - boost::in_place_init, msg.data(), msg.size()}; - auto n = p.put(buffer_prefix(i, cb), ec); - if(ec == result) - { - pass(); - continue; - } - if(! BEAST_EXPECTS( - ec == error::need_more, ec.message())) - continue; - if(! BEAST_EXPECT(! p.is_done())) - continue; - cb.consume(n); - n = p.put(cb, ec); - if(! ec) - p.put_eof(ec); - BEAST_EXPECTS(ec == result, ec.message()); - } - for(std::size_t i = 1; i < msg.size() - 1; ++i) - { - Parser p; - p.eager(true); - error_code ec; - p.put(buffer_cat( - boost::asio::const_buffers_1{msg.data(), i}, - boost::asio::const_buffers_1{ - msg.data() + i, msg.size() - i}), ec); - if(! ec) - p.put_eof(ec); - BEAST_EXPECTS(ec == result, ec.message()); - } - } - - //-------------------------------------------------------------------------- - - void - testFlatten() - { - parsegrind>( - "GET / HTTP/1.1\r\n" - "\r\n" - ); - parsegrind>( - "POST / HTTP/1.1\r\n" - "Content-Length: 5\r\n" - "\r\n" - "*****" - ); - parsegrind>( - "HTTP/1.1 403 Not Found\r\n" - "\r\n" - ); - parsegrind>( - "HTTP/1.1 200 OK\r\n" - "Content-Length: 5\r\n" - "\r\n" - "*****" - ); - parsegrind>( - "HTTP/1.1 200 OK\r\n" - "Transfer-Encoding: chunked\r\n" - "\r\n" - "5;x\r\n*****\r\n" - "0\r\nMD5: 0xff30\r\n" - "\r\n" - ); - parsegrind>( - "HTTP/1.1 200 OK\r\n" - "\r\n" - "*****" - ); - } - - void - testObsFold() - { - auto const check = - [&](std::string const& s, string_view value) - { - std::string m = - "GET / HTTP/1.1\r\n" - "f: " + s + "\r\n" - "\r\n"; - parsegrind>(m, - [&](parser const& p) - { - BEAST_EXPECT(p.get()["f"] == value); - }); - }; - check("x", "x"); - check(" x", "x"); - check("\tx", "x"); - check(" \tx", "x"); - check("\t x", "x"); - check("x ", "x"); - check(" x\t", "x"); - check("\tx \t", "x"); - check(" \tx\t ", "x"); - check("\t x \t ", "x"); - check("\r\n x", "x"); - check(" \r\n x", "x"); - check(" \r\n\tx", "x"); - check(" \r\n\t x", "x"); - check(" \r\n \tx", "x"); - check(" \r\n \r\n \r\n x \t", "x"); - check("xy", "xy"); - check("\r\n x", "x"); - check("\r\n x", "x"); - check("\r\n xy", "xy"); - check("\r\n \r\n \r\n x", "x"); - check("\r\n \r\n \r\n xy", "xy"); - check("x\r\n y", "x y"); - check("x\r\n y\r\n z ", "x y z"); - } - - // Check that all callbacks are invoked - void - testCallbacks() - { - parsegrind>( - "GET / HTTP/1.1\r\n" - "User-Agent: test\r\n" - "Content-Length: 1\r\n" - "\r\n" - "*", - [&](test_parser const& p) - { - BEAST_EXPECT(p.got_on_begin == 1); - BEAST_EXPECT(p.got_on_field == 2); - BEAST_EXPECT(p.got_on_header == 1); - BEAST_EXPECT(p.got_on_body == 1); - BEAST_EXPECT(p.got_on_chunk == 0); - BEAST_EXPECT(p.got_on_complete == 1); - }); - parsegrind>( - "HTTP/1.1 200 OK\r\n" - "Server: test\r\n" - "Content-Length: 1\r\n" - "\r\n" - "*", - [&](test_parser const& p) - { - BEAST_EXPECT(p.got_on_begin == 1); - BEAST_EXPECT(p.got_on_field == 2); - BEAST_EXPECT(p.got_on_header == 1); - BEAST_EXPECT(p.got_on_body == 1); - BEAST_EXPECT(p.got_on_chunk == 0); - BEAST_EXPECT(p.got_on_complete == 1); - }); - parsegrind>( - "HTTP/1.1 200 OK\r\n" - "Server: test\r\n" - "Transfer-Encoding: chunked\r\n" - "\r\n" - "1\r\n*\r\n" - "0\r\n\r\n", - [&](test_parser const& p) - { - BEAST_EXPECT(p.got_on_begin == 1); - BEAST_EXPECT(p.got_on_field == 2); - BEAST_EXPECT(p.got_on_header == 1); - BEAST_EXPECT(p.got_on_body == 1); - BEAST_EXPECT(p.got_on_chunk == 1); - BEAST_EXPECT(p.got_on_complete == 1); - }); - parsegrind>( - "HTTP/1.1 200 OK\r\n" - "Server: test\r\n" - "Transfer-Encoding: chunked\r\n" - "\r\n" - "1;x\r\n*\r\n" - "0\r\n\r\n", - [&](test_parser const& p) - { - BEAST_EXPECT(p.got_on_begin == 1); - BEAST_EXPECT(p.got_on_field == 2); - BEAST_EXPECT(p.got_on_header == 1); - BEAST_EXPECT(p.got_on_body == 1); - BEAST_EXPECT(p.got_on_chunk == 1); - BEAST_EXPECT(p.got_on_complete == 1); - }); - } - - void - testRequestLine() - { - using P = test_parser; - - parsegrind

("GET /x HTTP/1.0\r\n\r\n"); - parsegrind

("!#$%&'*+-.^_`|~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz / HTTP/1.0\r\n\r\n"); - parsegrind

("GET / HTTP/1.0\r\n\r\n", expect_version{*this, 10}); - parsegrind

("G / HTTP/1.1\r\n\r\n", expect_version{*this, 11}); - // VFALCO TODO various forms of good request-target (uri) - - failgrind

("\tGET / HTTP/1.0\r\n" "\r\n", error::bad_method); - failgrind

("GET\x01 / HTTP/1.0\r\n" "\r\n", error::bad_method); - failgrind

("GET / HTTP/1.0\r\n" "\r\n", error::bad_target); - failgrind

("GET \x01 HTTP/1.0\r\n" "\r\n", error::bad_target); - failgrind

("GET /\x01 HTTP/1.0\r\n" "\r\n", error::bad_target); - // VFALCO TODO various forms of bad request-target (uri) - failgrind

("GET / HTTP/1.0\r\n" "\r\n", error::bad_version); - failgrind

("GET / _TTP/1.0\r\n" "\r\n", error::bad_version); - failgrind

("GET / H_TP/1.0\r\n" "\r\n", error::bad_version); - failgrind

("GET / HT_P/1.0\r\n" "\r\n", error::bad_version); - failgrind

("GET / HTT_/1.0\r\n" "\r\n", error::bad_version); - failgrind

("GET / HTTP_1.0\r\n" "\r\n", error::bad_version); - failgrind

("GET / HTTP/01.2\r\n" "\r\n", error::bad_version); - failgrind

("GET / HTTP/3.45\r\n" "\r\n", error::bad_version); - failgrind

("GET / HTTP/67.89\r\n" "\r\n", error::bad_version); - failgrind

("GET / HTTP/x.0\r\n" "\r\n", error::bad_version); - failgrind

("GET / HTTP/1.x\r\n" "\r\n", error::bad_version); - failgrind

("GET / HTTP/1.0 \r\n" "\r\n", error::bad_version); - failgrind

("GET / HTTP/1_0\r\n" "\r\n", error::bad_version); - failgrind

("GET / HTTP/1.0\n\r\n" "\r\n", error::bad_version); - failgrind

("GET / HTTP/1.0\n\r\r\n" "\r\n", error::bad_version); - failgrind

("GET / HTTP/1.0\r\r\n" "\r\n", error::bad_version); - } - - void - testStatusLine() - { - using P = test_parser; - - parsegrind

("HTTP/1.0 000 OK\r\n" "\r\n", expect_status{*this, 0}); - parsegrind

("HTTP/1.1 012 OK\r\n" "\r\n", expect_status{*this, 12}); - parsegrind

("HTTP/1.0 345 OK\r\n" "\r\n", expect_status{*this, 345}); - parsegrind

("HTTP/1.0 678 OK\r\n" "\r\n", expect_status{*this, 678}); - parsegrind

("HTTP/1.0 999 OK\r\n" "\r\n", expect_status{*this, 999}); - parsegrind

("HTTP/1.0 200 \tX\r\n" "\r\n", expect_version{*this, 10}); - parsegrind

("HTTP/1.1 200 X\r\n" "\r\n", expect_version{*this, 11}); - parsegrind

("HTTP/1.0 200 \r\n" "\r\n"); - parsegrind

("HTTP/1.1 200 X \r\n" "\r\n"); - parsegrind

("HTTP/1.1 200 X\t\r\n" "\r\n"); - parsegrind

("HTTP/1.1 200 \x80\x81...\xfe\xff\r\n\r\n"); - parsegrind

("HTTP/1.1 200 !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\r\n\r\n"); - - failgrind

("\rHTTP/1.0 200 OK\r\n" "\r\n", error::bad_version); - failgrind

("\nHTTP/1.0 200 OK\r\n" "\r\n", error::bad_version); - failgrind

(" HTTP/1.0 200 OK\r\n" "\r\n", error::bad_version); - failgrind

("_TTP/1.0 200 OK\r\n" "\r\n", error::bad_version); - failgrind

("H_TP/1.0 200 OK\r\n" "\r\n", error::bad_version); - failgrind

("HT_P/1.0 200 OK\r\n" "\r\n", error::bad_version); - failgrind

("HTT_/1.0 200 OK\r\n" "\r\n", error::bad_version); - failgrind

("HTTP_1.0 200 OK\r\n" "\r\n", error::bad_version); - failgrind

("HTTP/01.2 200 OK\r\n" "\r\n", error::bad_version); - failgrind

("HTTP/3.45 200 OK\r\n" "\r\n", error::bad_version); - failgrind

("HTTP/67.89 200 OK\r\n" "\r\n", error::bad_version); - failgrind

("HTTP/x.0 200 OK\r\n" "\r\n", error::bad_version); - failgrind

("HTTP/1.x 200 OK\r\n" "\r\n", error::bad_version); - failgrind

("HTTP/1_0 200 OK\r\n" "\r\n", error::bad_version); - failgrind

("HTTP/1.0 200 OK\r\n" "\r\n", error::bad_status); - failgrind

("HTTP/1.0 0 OK\r\n" "\r\n", error::bad_status); - failgrind

("HTTP/1.0 12 OK\r\n" "\r\n", error::bad_status); - failgrind

("HTTP/1.0 3456 OK\r\n" "\r\n", error::bad_status); - failgrind

("HTTP/1.0 200\r\n" "\r\n", error::bad_status); - failgrind

("HTTP/1.0 200 \n\r\n" "\r\n", error::bad_reason); - failgrind

("HTTP/1.0 200 \x01\r\n" "\r\n", error::bad_reason); - failgrind

("HTTP/1.0 200 \x7f\r\n" "\r\n", error::bad_reason); - failgrind

("HTTP/1.0 200 OK\n\r\n" "\r\n", error::bad_reason); - failgrind

("HTTP/1.0 200 OK\r\r\n" "\r\n", error::bad_line_ending); - } - - void - testFields() - { - auto const m = - [](std::string const& s) - { - return "GET / HTTP/1.1\r\n" + s + "\r\n"; - }; - - using P = test_parser; - - parsegrind

(m("f:\r\n")); - parsegrind

(m("f: \r\n")); - parsegrind

(m("f:\t\r\n")); - parsegrind

(m("f: \t\r\n")); - parsegrind

(m("f: v\r\n")); - parsegrind

(m("f:\tv\r\n")); - parsegrind

(m("f:\tv \r\n")); - parsegrind

(m("f:\tv\t\r\n")); - parsegrind

(m("f:\tv\t \r\n")); - parsegrind

(m("f:\r\n \r\n")); - parsegrind

(m("f:v\r\n")); - parsegrind

(m("f: v\r\n u\r\n")); - parsegrind

(m("!#$%&'*+-.^_`|~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz: v\r\n")); - parsegrind

(m("f: !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x80\x81...\xfe\xff\r\n")); - - failgrind

(m(" f: v\r\n"), error::bad_field); - failgrind

(m("\tf: v\r\n"), error::bad_field); - failgrind

(m("f : v\r\n"), error::bad_field); - failgrind

(m("f\t: v\r\n"), error::bad_field); - failgrind

(m("f: \n\r\n"), error::bad_value); - failgrind

(m("f: v\r \r\n"), error::bad_line_ending); - failgrind

(m("f: \r v\r\n"), error::bad_line_ending); - failgrind

( - "GET / HTTP/1.1\r\n" - "\r \n\r\n" - "\r\n", error::bad_line_ending); - } - - void - testConnectionField() - { - auto const m = [](std::string const& s) - { return "GET / HTTP/1.1\r\n" + s + "\r\n"; }; - auto const cn = [](std::string const& s) - { return "GET / HTTP/1.1\r\nConnection: " + s + "\r\n"; }; - #if 0 - auto const keepalive = [&](bool v) - { //return keepalive_f{*this, v}; return true; }; - #endif - - using P = test_parser; - - parsegrind

(cn("close\r\n"), expect_flags{*this, parse_flag::connection_close}); - parsegrind

(cn(",close\r\n"), expect_flags{*this, parse_flag::connection_close}); - parsegrind

(cn(" close\r\n"), expect_flags{*this, parse_flag::connection_close}); - parsegrind

(cn("\tclose\r\n"), expect_flags{*this, parse_flag::connection_close}); - parsegrind

(cn("close,\r\n"), expect_flags{*this, parse_flag::connection_close}); - parsegrind

(cn("close\t\r\n"), expect_flags{*this, parse_flag::connection_close}); - parsegrind

(cn("close\r\n"), expect_flags{*this, parse_flag::connection_close}); - parsegrind

(cn(" ,\t,,close,, ,\t,,\r\n"), expect_flags{*this, parse_flag::connection_close}); - parsegrind

(cn("\r\n close\r\n"), expect_flags{*this, parse_flag::connection_close}); - parsegrind

(cn("close\r\n \r\n"), expect_flags{*this, parse_flag::connection_close}); - parsegrind

(cn("any,close\r\n"), expect_flags{*this, parse_flag::connection_close}); - parsegrind

(cn("close,any\r\n"), expect_flags{*this, parse_flag::connection_close}); - parsegrind

(cn("any\r\n ,close\r\n"), expect_flags{*this, parse_flag::connection_close}); - parsegrind

(cn("close\r\n ,any\r\n"), expect_flags{*this, parse_flag::connection_close}); - parsegrind

(cn("close,close\r\n"), expect_flags{*this, parse_flag::connection_close}); // weird but allowed - - parsegrind

(cn("keep-alive\r\n"), expect_flags{*this, parse_flag::connection_keep_alive}); - parsegrind

(cn("keep-alive \r\n"), expect_flags{*this, parse_flag::connection_keep_alive}); - parsegrind

(cn("keep-alive\t \r\n"), expect_flags{*this, parse_flag::connection_keep_alive}); - parsegrind

(cn("keep-alive\t ,x\r\n"), expect_flags{*this, parse_flag::connection_keep_alive}); - parsegrind

(cn("\r\n keep-alive \t\r\n"), expect_flags{*this, parse_flag::connection_keep_alive}); - parsegrind

(cn("keep-alive \r\n \t \r\n"), expect_flags{*this, parse_flag::connection_keep_alive}); - parsegrind

(cn("keep-alive\r\n \r\n"), expect_flags{*this, parse_flag::connection_keep_alive}); - - parsegrind

(cn("upgrade\r\n"), expect_flags{*this, parse_flag::connection_upgrade}); - parsegrind

(cn("upgrade \r\n"), expect_flags{*this, parse_flag::connection_upgrade}); - parsegrind

(cn("upgrade\t \r\n"), expect_flags{*this, parse_flag::connection_upgrade}); - parsegrind

(cn("upgrade\t ,x\r\n"), expect_flags{*this, parse_flag::connection_upgrade}); - parsegrind

(cn("\r\n upgrade \t\r\n"), expect_flags{*this, parse_flag::connection_upgrade}); - parsegrind

(cn("upgrade \r\n \t \r\n"), expect_flags{*this, parse_flag::connection_upgrade}); - parsegrind

(cn("upgrade\r\n \r\n"), expect_flags{*this, parse_flag::connection_upgrade}); - - // VFALCO What's up with these? - //parsegrind

(cn("close,keep-alive\r\n"), expect_flags{*this, parse_flag::connection_close | parse_flag::connection_keep_alive}); - parsegrind

(cn("upgrade,keep-alive\r\n"), expect_flags{*this, parse_flag::connection_upgrade | parse_flag::connection_keep_alive}); - parsegrind

(cn("upgrade,\r\n keep-alive\r\n"), expect_flags{*this, parse_flag::connection_upgrade | parse_flag::connection_keep_alive}); - //parsegrind

(cn("close,keep-alive,upgrade\r\n"), expect_flags{*this, parse_flag::connection_close | parse_flag::connection_keep_alive | parse_flag::connection_upgrade}); - - parsegrind

("GET / HTTP/1.1\r\n\r\n", expect_keepalive(*this, true)); - parsegrind

("GET / HTTP/1.0\r\n\r\n", expect_keepalive(*this, false)); - parsegrind

("GET / HTTP/1.0\r\n" - "Connection: keep-alive\r\n\r\n", expect_keepalive(*this, true)); - parsegrind

("GET / HTTP/1.1\r\n" - "Connection: close\r\n\r\n", expect_keepalive(*this, false)); - - parsegrind

(cn("x\r\n"), expect_flags{*this, 0}); - parsegrind

(cn("x,y\r\n"), expect_flags{*this, 0}); - parsegrind

(cn("x ,y\r\n"), expect_flags{*this, 0}); - parsegrind

(cn("x\t,y\r\n"), expect_flags{*this, 0}); - parsegrind

(cn("keep\r\n"), expect_flags{*this, 0}); - parsegrind

(cn(",keep\r\n"), expect_flags{*this, 0}); - parsegrind

(cn(" keep\r\n"), expect_flags{*this, 0}); - parsegrind

(cn("\tnone\r\n"), expect_flags{*this, 0}); - parsegrind

(cn("keep,\r\n"), expect_flags{*this, 0}); - parsegrind

(cn("keep\t\r\n"), expect_flags{*this, 0}); - parsegrind

(cn("keep\r\n"), expect_flags{*this, 0}); - parsegrind

(cn(" ,\t,,keep,, ,\t,,\r\n"), expect_flags{*this, 0}); - parsegrind

(cn("\r\n keep\r\n"), expect_flags{*this, 0}); - parsegrind

(cn("keep\r\n \r\n"), expect_flags{*this, 0}); - parsegrind

(cn("closet\r\n"), expect_flags{*this, 0}); - parsegrind

(cn(",closet\r\n"), expect_flags{*this, 0}); - parsegrind

(cn(" closet\r\n"), expect_flags{*this, 0}); - parsegrind

(cn("\tcloset\r\n"), expect_flags{*this, 0}); - parsegrind

(cn("closet,\r\n"), expect_flags{*this, 0}); - parsegrind

(cn("closet\t\r\n"), expect_flags{*this, 0}); - parsegrind

(cn("closet\r\n"), expect_flags{*this, 0}); - parsegrind

(cn(" ,\t,,closet,, ,\t,,\r\n"), expect_flags{*this, 0}); - parsegrind

(cn("\r\n closet\r\n"), expect_flags{*this, 0}); - parsegrind

(cn("closet\r\n \r\n"), expect_flags{*this, 0}); - parsegrind

(cn("clog\r\n"), expect_flags{*this, 0}); - parsegrind

(cn("key\r\n"), expect_flags{*this, 0}); - parsegrind

(cn("uptown\r\n"), expect_flags{*this, 0}); - parsegrind

(cn("keeper\r\n \r\n"), expect_flags{*this, 0}); - parsegrind

(cn("keep-alively\r\n \r\n"), expect_flags{*this, 0}); - parsegrind

(cn("up\r\n \r\n"), expect_flags{*this, 0}); - parsegrind

(cn("upgrader\r\n \r\n"), expect_flags{*this, 0}); - parsegrind

(cn("none\r\n"), expect_flags{*this, 0}); - parsegrind

(cn("\r\n none\r\n"), expect_flags{*this, 0}); - - parsegrind

(m("ConnectioX: close\r\n"), expect_flags{*this, 0}); - parsegrind

(m("Condor: close\r\n"), expect_flags{*this, 0}); - parsegrind

(m("Connect: close\r\n"), expect_flags{*this, 0}); - parsegrind

(m("Connections: close\r\n"), expect_flags{*this, 0}); - - parsegrind

(m("Proxy-Connection: close\r\n"), expect_flags{*this, parse_flag::connection_close}); - parsegrind

(m("Proxy-Connection: keep-alive\r\n"), expect_flags{*this, parse_flag::connection_keep_alive}); - parsegrind

(m("Proxy-Connection: upgrade\r\n"), expect_flags{*this, parse_flag::connection_upgrade}); - parsegrind

(m("Proxy-ConnectioX: none\r\n"), expect_flags{*this, 0}); - parsegrind

(m("Proxy-Connections: 1\r\n"), expect_flags{*this, 0}); - parsegrind

(m("Proxy-Connotes: see-also\r\n"), expect_flags{*this, 0}); - - failgrind

(cn("[\r\n"), error::bad_value); - failgrind

(cn("close[\r\n"), error::bad_value); - failgrind

(cn("close [\r\n"), error::bad_value); - failgrind

(cn("close, upgrade [\r\n"), error::bad_value); - failgrind

(cn("upgrade[]\r\n"), error::bad_value); - failgrind

(cn("keep\r\n -alive\r\n"), error::bad_value); - failgrind

(cn("keep-alive[\r\n"), error::bad_value); - failgrind

(cn("keep-alive []\r\n"), error::bad_value); - failgrind

(cn("no[ne]\r\n"), error::bad_value); - } - - void - testContentLengthField() - { - using P = test_parser; - auto const c = [](std::string const& s) - { return "GET / HTTP/1.1\r\nContent-Length: " + s + "\r\n"; }; - auto const m = [](std::string const& s) - { return "GET / HTTP/1.1\r\n" + s + "\r\n"; }; - auto const check = - [&](std::string const& s, std::uint64_t v) - { - parsegrind

(c(s), - [&](P const& p) - { - BEAST_EXPECT(p.content_length()); - BEAST_EXPECT(p.content_length() && *p.content_length() == v); - }, true); - }; - - check("0\r\n", 0); - check("00\r\n", 0); - check("1\r\n", 1); - check("01\r\n", 1); - check("9\r\n", 9); - check("42 \r\n", 42); - check("42\t\r\n", 42); - check("42 \t \r\n", 42); - check("42\r\n \t \r\n", 42); - - parsegrind

(m("Content-LengtX: 0\r\n"), expect_flags{*this, 0}); - parsegrind

(m("Content-Lengths: many\r\n"), expect_flags{*this, 0}); - parsegrind

(m("Content: full\r\n"), expect_flags{*this, 0}); - - failgrind

(c("\r\n"), error::bad_content_length); - failgrind

(c("18446744073709551616\r\n"), error::bad_content_length); - failgrind

(c("0 0\r\n"), error::bad_content_length); - failgrind

(c("0 1\r\n"), error::bad_content_length); - failgrind

(c(",\r\n"), error::bad_content_length); - failgrind

(c("0,\r\n"), error::bad_content_length); - failgrind

(m( - "Content-Length: 0\r\nContent-Length: 0\r\n"), error::bad_content_length); - } - - void - testTransferEncodingField() - { - auto const m = [](std::string const& s) - { return "GET / HTTP/1.1\r\n" + s + "\r\n"; }; - auto const ce = [](std::string const& s) - { return "GET / HTTP/1.1\r\nTransfer-Encoding: " + s + "\r\n0\r\n\r\n"; }; - auto const te = [](std::string const& s) - { return "GET / HTTP/1.1\r\nTransfer-Encoding: " + s + "\r\n"; }; - - using P = test_parser; - - parsegrind

(ce("chunked\r\n"), expect_flags{*this, parse_flag::chunked}); - parsegrind

(ce("chunked \r\n"), expect_flags{*this, parse_flag::chunked}); - parsegrind

(ce("chunked\t\r\n"), expect_flags{*this, parse_flag::chunked}); - parsegrind

(ce("chunked \t\r\n"), expect_flags{*this, parse_flag::chunked}); - parsegrind

(ce(" chunked\r\n"), expect_flags{*this, parse_flag::chunked}); - parsegrind

(ce("\tchunked\r\n"), expect_flags{*this, parse_flag::chunked}); - parsegrind

(ce("chunked,\r\n"), expect_flags{*this, parse_flag::chunked}); - parsegrind

(ce("chunked ,\r\n"), expect_flags{*this, parse_flag::chunked}); - parsegrind

(ce("chunked, \r\n"), expect_flags{*this, parse_flag::chunked}); - parsegrind

(ce(",chunked\r\n"), expect_flags{*this, parse_flag::chunked}); - parsegrind

(ce(", chunked\r\n"), expect_flags{*this, parse_flag::chunked}); - parsegrind

(ce(" ,chunked\r\n"), expect_flags{*this, parse_flag::chunked}); - parsegrind

(ce("chunked\r\n \r\n"), expect_flags{*this, parse_flag::chunked}); - parsegrind

(ce("\r\n chunked\r\n"), expect_flags{*this, parse_flag::chunked}); - parsegrind

(ce(",\r\n chunked\r\n"), expect_flags{*this, parse_flag::chunked}); - parsegrind

(ce("\r\n ,chunked\r\n"), expect_flags{*this, parse_flag::chunked}); - parsegrind

(ce(",\r\n chunked\r\n"), expect_flags{*this, parse_flag::chunked}); - parsegrind

(ce("gzip, chunked\r\n"), expect_flags{*this, parse_flag::chunked}); - parsegrind

(ce("gzip, chunked \r\n"), expect_flags{*this, parse_flag::chunked}); - parsegrind

(ce("gzip, \r\n chunked\r\n"), expect_flags{*this, parse_flag::chunked}); - - // Technically invalid but beyond the parser's scope to detect - // VFALCO Look into this - //parsegrind

(ce("custom;key=\",chunked\r\n"), expect_flags{*this, parse_flag::chunked}); - - parsegrind

(te("gzip\r\n"), expect_flags{*this, 0}); - parsegrind

(te("chunked, gzip\r\n"), expect_flags{*this, 0}); - parsegrind

(te("chunked\r\n , gzip\r\n"), expect_flags{*this, 0}); - parsegrind

(te("chunked,\r\n gzip\r\n"), expect_flags{*this, 0}); - parsegrind

(te("chunked,\r\n ,gzip\r\n"), expect_flags{*this, 0}); - parsegrind

(te("bigchunked\r\n"), expect_flags{*this, 0}); - parsegrind

(te("chunk\r\n ked\r\n"), expect_flags{*this, 0}); - parsegrind

(te("bar\r\n ley chunked\r\n"), expect_flags{*this, 0}); - parsegrind

(te("barley\r\n chunked\r\n"), expect_flags{*this, 0}); - - parsegrind

(m("Transfer-EncodinX: none\r\n"), expect_flags{*this, 0}); - parsegrind

(m("Transfer-Encodings: 2\r\n"), expect_flags{*this, 0}); - parsegrind

(m("Transfer-Encoded: false\r\n"), expect_flags{*this, 0}); - - failgrind>( - "HTTP/1.1 200 OK\r\n" - "Content-Length: 1\r\n" - "Transfer-Encoding: chunked\r\n" - "\r\n", error::bad_transfer_encoding); - } - - void - testUpgradeField() - { - auto const m = [](std::string const& s) - { return "GET / HTTP/1.1\r\n" + s + "\r\n"; }; - - using P = test_parser; - - parsegrind

(m("Upgrade:\r\n"), expect_flags{*this, parse_flag::upgrade}); - parsegrind

(m("Upgrade: \r\n"), expect_flags{*this, parse_flag::upgrade}); - parsegrind

(m("Upgrade: yes\r\n"), expect_flags{*this, parse_flag::upgrade}); - - parsegrind

(m("Up: yes\r\n"), expect_flags{*this, 0}); - parsegrind

(m("UpgradX: none\r\n"), expect_flags{*this, 0}); - parsegrind

(m("Upgrades: 2\r\n"), expect_flags{*this, 0}); - parsegrind

(m("Upsample: 4x\r\n"), expect_flags{*this, 0}); - - parsegrind

( - "GET / HTTP/1.1\r\n" - "Connection: upgrade\r\n" - "Upgrade: WebSocket\r\n" - "\r\n", - [&](P const& p) - { - BEAST_EXPECT(p.is_upgrade()); - }); - } - - void - testPartial() - { - // Make sure the slow-loris defense works and that - // we don't get duplicate or missing fields on a split. - parsegrind>( - "GET / HTTP/1.1\r\n" - "a: 0\r\n" - "b: 1\r\n" - "c: 2\r\n" - "d: 3\r\n" - "e: 4\r\n" - "f: 5\r\n" - "g: 6\r\n" - "h: 7\r\n" - "i: 8\r\n" - "j: 9\r\n" - "\r\n", - [&](test_parser const& p) - { - BEAST_EXPECT(p.fields.size() == 10); - BEAST_EXPECT(p.fields.at("a") == "0"); - BEAST_EXPECT(p.fields.at("b") == "1"); - BEAST_EXPECT(p.fields.at("c") == "2"); - BEAST_EXPECT(p.fields.at("d") == "3"); - BEAST_EXPECT(p.fields.at("e") == "4"); - BEAST_EXPECT(p.fields.at("f") == "5"); - BEAST_EXPECT(p.fields.at("g") == "6"); - BEAST_EXPECT(p.fields.at("h") == "7"); - BEAST_EXPECT(p.fields.at("i") == "8"); - BEAST_EXPECT(p.fields.at("j") == "9"); - }); - } - - void - testLimits() - { - { - multi_buffer b; - ostream(b) << - "POST / HTTP/1.1\r\n" - "Content-Length: 2\r\n" - "\r\n" - "**"; - error_code ec; - test_parser p; - p.header_limit(10); - p.eager(true); - p.put(b.data(), ec); - BEAST_EXPECTS(ec == error::header_limit, ec.message()); - } - { - multi_buffer b; - ostream(b) << - "POST / HTTP/1.1\r\n" - "Content-Length: 2\r\n" - "\r\n" - "**"; - error_code ec; - test_parser p; - p.body_limit(1); - p.eager(true); - p.put(b.data(), ec); - BEAST_EXPECTS(ec == error::body_limit, ec.message()); - } - { - multi_buffer b; - ostream(b) << - "HTTP/1.1 200 OK\r\n" - "\r\n" - "**"; - error_code ec; - test_parser p; - p.body_limit(1); - p.eager(true); - p.put(b.data(), ec); - BEAST_EXPECTS(ec == error::body_limit, ec.message()); - } - { - multi_buffer b; - ostream(b) << - "POST / HTTP/1.1\r\n" - "Transfer-Encoding: chunked\r\n" - "\r\n" - "2\r\n" - "**\r\n" - "0\r\n\r\n"; - error_code ec; - test_parser p; - p.body_limit(1); - p.eager(true); - p.put(b.data(), ec); - BEAST_EXPECTS(ec == error::body_limit, ec.message()); - } - } - - //-------------------------------------------------------------------------- - - static - boost::asio::const_buffers_1 - buf(string_view s) - { - return {s.data(), s.size()}; - } - - template - std::size_t - feed(ConstBufferSequence const& buffers, - basic_parser& p, error_code& ec) - { - p.eager(true); - return p.put(buffers, ec); - } - - void - testBody() - { - parsegrind>( - "HTTP/1.1 200 OK\r\n" - "Transfer-Encoding: chunked\r\n" - "Content-Type: application/octet-stream\r\n" - "\r\n" - "4\r\nabcd\r\n" - "0\r\n\r\n" - ,[&](test_parser const& p) - { - BEAST_EXPECT(p.body == "abcd"); - }); - parsegrind>( - "HTTP/1.1 200 OK\r\n" - "Server: test\r\n" - "Expect: Expires, MD5-Fingerprint\r\n" - "Transfer-Encoding: chunked\r\n" - "\r\n" - "5\r\n" - "*****\r\n" - "2;a;b=1;c=\"2\"\r\n" - "--\r\n" - "0;d;e=3;f=\"4\"\r\n" - "Expires: never\r\n" - "MD5-Fingerprint: -\r\n" - "\r\n" - ,[&](test_parser const& p) - { - BEAST_EXPECT(p.body == "*****--"); - }); - - parsegrind>( - "GET / HTTP/1.1\r\n" - "Content-Length: 1\r\n" - "\r\n" - "1", - expect_body(*this, "1")); - - parsegrind>( - "HTTP/1.0 200 OK\r\n" - "\r\n" - "hello", - expect_body(*this, "hello")); - - parsegrind>(buffer_cat( - buf("GET / HTTP/1.1\r\n" - "Content-Length: 10\r\n" - "\r\n"), - buf("12"), - buf("345"), - buf("67890"))); - - // request without Content-Length or - // Transfer-Encoding: chunked has no body. - { - error_code ec; - test_parser p; - feed(buf( - "GET / HTTP/1.0\r\n" - "\r\n" - ), p, ec); - BEAST_EXPECTS(! ec, ec.message()); - BEAST_EXPECT(p.is_done()); - } - { - error_code ec; - test_parser p; - feed(buf( - "GET / HTTP/1.1\r\n" - "\r\n" - ), p, ec); - BEAST_EXPECTS(! ec, ec.message()); - BEAST_EXPECT(p.is_done()); - } - - // response without Content-Length or - // Transfer-Encoding: chunked requires eof. - { - error_code ec; - test_parser p; - feed(buf( - "HTTP/1.0 200 OK\r\n" - "\r\n" - ), p, ec); - BEAST_EXPECTS(! ec, ec.message()); - BEAST_EXPECT(! p.is_done()); - BEAST_EXPECT(p.need_eof()); - } - - // 304 "Not Modified" response does not require eof - { - error_code ec; - test_parser p; - feed(buf( - "HTTP/1.0 304 Not Modified\r\n" - "\r\n" - ), p, ec); - BEAST_EXPECTS(! ec, ec.message()); - BEAST_EXPECT(p.is_done()); - } - - // Chunked response does not require eof - { - error_code ec; - test_parser p; - feed(buf( - "HTTP/1.1 200 OK\r\n" - "Transfer-Encoding: chunked\r\n" - "\r\n" - ), p, ec); - BEAST_EXPECTS(! ec, ec.message()); - BEAST_EXPECT(! p.is_done()); - feed(buf( - "0\r\n\r\n" - ), p, ec); - BEAST_EXPECTS(! ec, ec.message()); - BEAST_EXPECT(p.is_done()); - } - - // restart: 1.0 assumes Connection: close - { - error_code ec; - test_parser p; - feed(buf( - "GET / HTTP/1.0\r\n" - "\r\n" - ), p, ec); - BEAST_EXPECTS(! ec, ec.message()); - BEAST_EXPECT(p.is_done()); - } - - // restart: 1.1 assumes Connection: keep-alive - { - error_code ec; - test_parser p; - feed(buf( - "GET / HTTP/1.1\r\n" - "\r\n" - ), p, ec); - BEAST_EXPECTS(! ec, ec.message()); - BEAST_EXPECT(p.is_done()); - } - - failgrind>( - "GET / HTTP/1.1\r\n" - "Content-Length: 1\r\n" - "\r\n", - error::partial_message); - } - - //-------------------------------------------------------------------------- - - // https://github.com/vinniefalco/Beast/issues/430 - void - testIssue430() - { - parsegrind>( - "HTTP/1.1 200 OK\r\n" - "Transfer-Encoding: chunked\r\n" - "Content-Type: application/octet-stream\r\n" - "\r\n" - "4\r\nabcd\r\n" - "0\r\n\r\n"); - } - - // https://github.com/vinniefalco/Beast/issues/452 - void - testIssue452() - { - error_code ec; - test_parser p; - p.eager(true); - string_view s = - "GET / HTTP/1.1\r\n" - "\r\n" - "die!"; - p.put(boost::asio::buffer( - s.data(), s.size()), ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - BEAST_EXPECT(p.is_done()); - } - - // https://github.com/vinniefalco/Beast/issues/496 - void - testIssue496() - { - // The bug affected hex parsing with leading zeroes - using P = test_parser; - parsegrind

( - "HTTP/1.1 200 OK\r\n" - "Transfer-Encoding: chunked\r\n" - "Content-Type: application/octet-stream\r\n" - "\r\n" - "0004\r\nabcd\r\n" - "0\r\n\r\n" - ,[&](P const& p) - { - BEAST_EXPECT(p.body == "abcd"); - }); - } - - //-------------------------------------------------------------------------- - - void - testFuzz1() - { - // crash_00cda0b02d5166bd1039ddb3b12618cd80da75f3 - unsigned char buf[] ={ - 0x4C,0x4F,0x43,0x4B,0x20,0x2F,0x25,0x65,0x37,0x6C,0x59,0x3B,0x2F,0x3B,0x3B,0x25,0x30,0x62,0x38,0x3D,0x70,0x2F,0x72,0x20, - 0x48,0x54,0x54,0x50,0x2F,0x31,0x2E,0x31,0x0D,0x0A,0x41,0x63,0x63,0x65,0x70,0x74,0x2D,0x45,0x6E,0x63,0x6F,0x64,0x69,0x6E, - 0x67,0x3A,0x0D,0x0A,0x09,0x20,0xEE,0x0D,0x0A,0x4F,0x72,0x69,0x67,0x69,0x6E,0x61,0x6C,0x2D,0x4D,0x65,0x73,0x73,0x61,0x67, - 0x65,0x2D,0x49,0x44,0x3A,0xEB,0x09,0x09,0x09,0x09,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x3A,0x20,0x0D,0x0A,0x09,0x20, - 0xF7,0x44,0x9B,0xA5,0x06,0x9F,0x0D,0x0A,0x52,0x65,0x73,0x65,0x6E,0x74,0x2D,0x44,0x61,0x74,0x65,0x3A,0xF4,0x0D,0x0A,0x41, - 0x6C,0x74,0x2D,0x53,0x76,0x63,0x3A,0x20,0x0D,0x0A,0x54,0x72,0x61,0x69,0x6C,0x65,0x72,0x3A,0x20,0x20,0x09,0x20,0x20,0x20, - 0x0D,0x0A,0x4C,0x69,0x73,0x74,0x2D,0x49,0x44,0x3A,0xA6,0x6B,0x86,0x09,0x09,0x20,0x09,0x0D,0x0A,0x41,0x6C,0x74,0x65,0x72, - 0x6E,0x61,0x74,0x65,0x2D,0x52,0x65,0x63,0x69,0x70,0x69,0x65,0x6E,0x74,0x3A,0xF3,0x13,0xE3,0x22,0x9D,0xEF,0xFB,0x84,0x71, - 0x4A,0xCC,0xBC,0x96,0xF7,0x5B,0x72,0xF1,0xF2,0x0D,0x0A,0x4C,0x6F,0x63,0x61,0x74,0x69,0x6F,0x6E,0x3A,0x20,0x0D,0x0A,0x41, - 0x63,0x63,0x65,0x70,0x74,0x2D,0x41,0x64,0x64,0x69,0x74,0x69,0x6F,0x6E,0x73,0x3A,0x20,0x0D,0x0A,0x4D,0x4D,0x48,0x53,0x2D, - 0x4F,0x72,0x69,0x67,0x69,0x6E,0x61,0x74,0x6F,0x72,0x2D,0x50,0x4C,0x41,0x44,0x3A,0x20,0x0D,0x0A,0x4F,0x72,0x69,0x67,0x69, - 0x6E,0x61,0x6C,0x2D,0x53,0x65,0x6E,0x64,0x65,0x72,0x3A,0x20,0x0D,0x0A,0x4F,0x72,0x69,0x67,0x69,0x6E,0x61,0x6C,0x2D,0x53, - 0x65,0x6E,0x64,0x65,0x72,0x3A,0x0D,0x0A,0x50,0x49,0x43,0x53,0x2D,0x4C,0x61,0x62,0x65,0x6C,0x3A,0x0D,0x0A,0x20,0x09,0x0D, - 0x0A,0x49,0x66,0x3A,0x20,0x40,0xC1,0x50,0x5C,0xD6,0xC3,0x86,0xFC,0x8D,0x5C,0x7C,0x96,0x45,0x0D,0x0A,0x4D,0x4D,0x48,0x53, - 0x2D,0x45,0x78,0x65,0x6D,0x70,0x74,0x65,0x64,0x2D,0x41,0x64,0x64,0x72,0x65,0x73,0x73,0x3A,0x0D,0x0A,0x49,0x6E,0x6A,0x65, - 0x63,0x74,0x69,0x6F,0x6E,0x2D,0x49,0x6E,0x66,0x6F,0x3A,0x20,0x0D,0x0A,0x43,0x6F,0x6E,0x74,0x65,0x74,0x6E,0x2D,0x4C,0x65, - 0x6E,0x67,0x74,0x68,0x3A,0x20,0x30,0x0D,0x0A,0x0D,0x0A - }; - - error_code ec; - test_parser p; - feed(boost::asio::buffer(buf, sizeof(buf)), p, ec); - BEAST_EXPECT(ec); - } - - //-------------------------------------------------------------------------- - - void - run() override - { - testFlatten(); - testObsFold(); - testCallbacks(); - testRequestLine(); - testStatusLine(); - testFields(); - testConnectionField(); - testContentLengthField(); - testTransferEncodingField(); - testUpgradeField(); - testPartial(); - testLimits(); - testBody(); - testIssue430(); - testIssue452(); - testIssue496(); - testFuzz1(); - } -}; - -BEAST_DEFINE_TESTSUITE(basic_parser,http,beast); - -} // http -} // beast diff --git a/src/beast/test/http/buffer_body.cpp b/src/beast/test/http/buffer_body.cpp deleted file mode 100644 index 2526a3c03fe..00000000000 --- a/src/beast/test/http/buffer_body.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include diff --git a/src/beast/test/http/doc_examples.cpp b/src/beast/test/http/doc_examples.cpp deleted file mode 100644 index 7017e176d9d..00000000000 --- a/src/beast/test/http/doc_examples.cpp +++ /dev/null @@ -1,303 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#include "example/doc/http_examples.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -class doc_examples_test - : public beast::unit_test::suite - , public beast::test::enable_yield_to -{ -public: - // two threads, for some examples using a pipe - doc_examples_test() - : enable_yield_to(2) - { - } - - template - bool - equal_body(string_view sv, string_view body) - { - test::string_istream si{ - get_io_service(), sv.to_string()}; - message m; - multi_buffer b; - try - { - read(si, b, m); - return m.body == body; - } - catch(std::exception const& e) - { - log << "equal_body: " << e.what() << std::endl; - return false; - } - } - - void - doExpect100Continue() - { - test::pipe p{ios_}; - yield_to( - [&](yield_context) - { - error_code ec; - flat_buffer buffer; - receive_expect_100_continue( - p.server, buffer, ec); - BEAST_EXPECTS(! ec, ec.message()); - }, - [&](yield_context) - { - flat_buffer buffer; - request req; - req.version = 11; - req.method_string("POST"); - req.target("/"); - req.insert(field::user_agent, "test"); - req.body = "Hello, world!"; - req.prepare_payload(); - - error_code ec; - send_expect_100_continue( - p.client, buffer, req, ec); - BEAST_EXPECTS(! ec, ec.message()); - }); - } - - void - doCgiResponse() - { - std::string const s = "Hello, world!"; - test::pipe child{ios_}; - child.server.read_size(3); - ostream(child.server.buffer) << s; - child.client.close(); - test::pipe p{ios_}; - error_code ec; - send_cgi_response(child.server, p.client, ec); - BEAST_EXPECTS(! ec, ec.message()); - BEAST_EXPECT(equal_body(p.server.str(), s)); - } - - void - doRelay() - { - request req; - req.version = 11; - req.method_string("POST"); - req.target("/"); - req.insert(field::user_agent, "test"); - req.body = "Hello, world!"; - req.prepare_payload(); - - test::pipe downstream{ios_}; - downstream.server.read_size(3); - test::pipe upstream{ios_}; - upstream.client.write_size(3); - - error_code ec; - write(downstream.client, req); - BEAST_EXPECTS(! ec, ec.message()); - downstream.client.close(); - - flat_buffer buffer; - relay(upstream.client, downstream.server, buffer, ec, - [&](header& h, error_code& ev) - { - ev = {}; - h.erase("Content-Length"); - h.set("Transfer-Encoding", "chunked"); - }); - BEAST_EXPECTS(! ec, ec.message()); - BEAST_EXPECT(equal_body( - upstream.server.str(), req.body)); - } - - void - doReadStdStream() - { - std::string const s = - "HTTP/1.0 200 OK\r\n" - "User-Agent: test\r\n" - "\r\n" - "Hello, world!"; - std::istringstream is(s); - error_code ec; - flat_buffer buffer; - response res; - read_istream(is, buffer, res, ec); - BEAST_EXPECTS(! ec, ec.message()); - BEAST_EXPECT(boost::lexical_cast< - std::string>(res) == s); - } - - void - doWriteStdStream() - { - std::ostringstream os; - request req; - req.version = 11; - req.method(verb::get); - req.target("/"); - req.insert(field::user_agent, "test"); - error_code ec; - write_ostream(os, req, ec); - BEAST_EXPECTS(! ec, ec.message()); - BEAST_EXPECT(boost::lexical_cast< - std::string>(req) == os.str()); - } - - void - doCustomParser() - { - { - string_view s{ - "POST / HTTP/1.1\r\n" - "User-Agent: test\r\n" - "Content-Length: 13\r\n" - "\r\n" - "Hello, world!" - }; - error_code ec; - custom_parser p; - p.put(boost::asio::buffer( - s.data(), s.size()), ec); - BEAST_EXPECTS(! ec, ec.message()); - } - { - string_view s{ - "HTTP/1.1 200 OK\r\n" - "Server: test\r\n" - "Transfer-Encoding: chunked\r\n" - "\r\n" - "d\r\n" - "Hello, world!" - "\r\n" - "0\r\n\r\n" - }; - error_code ec; - custom_parser p; - p.put(boost::asio::buffer( - s.data(), s.size()), ec); - BEAST_EXPECTS(! ec, ec.message()); - } - } - - void - doHEAD() - { - test::pipe p{ios_}; - yield_to( - [&](yield_context) - { - error_code ec; - flat_buffer buffer; - do_server_head(p.server, buffer, ec); - BEAST_EXPECTS(! ec, ec.message()); - }, - [&](yield_context) - { - error_code ec; - flat_buffer buffer; - auto res = do_head_request(p.client, buffer, "/", ec); - BEAST_EXPECTS(! ec, ec.message()); - }); - } - - struct handler - { - std::string body; - - template - void - operator()(request&&) - { - } - - void - operator()(request&& req) - { - body = req.body; - } - }; - - void - doDeferredBody() - { - test::pipe p{ios_}; - ostream(p.server.buffer) << - "POST / HTTP/1.1\r\n" - "User-Agent: test\r\n" - "Content-Type: multipart/form-data\r\n" - "Content-Length: 13\r\n" - "\r\n" - "Hello, world!"; - - handler h; - flat_buffer buffer; - do_form_request(p.server, buffer, h); - BEAST_EXPECT(h.body == "Hello, world!"); - } - - //-------------------------------------------------------------------------- - - void - doIncrementalRead() - { - test::pipe c{ios_}; - std::string s(2048, '*'); - ostream(c.server.buffer) << - "HTTP/1.1 200 OK\r\n" - "Content-Length: 2048\r\n" - "Server: test\r\n" - "\r\n" << - s; - error_code ec; - flat_buffer b; - std::stringstream ss; - read_and_print_body(ss, c.server, b, ec); - if(BEAST_EXPECTS(! ec, ec.message())) - BEAST_EXPECT(ss.str() == s); - } - - //-------------------------------------------------------------------------- - - void - run() - { - doExpect100Continue(); - doCgiResponse(); - doRelay(); - doReadStdStream(); - doWriteStdStream(); - doCustomParser(); - doHEAD(); - doDeferredBody(); - doIncrementalRead(); - } -}; - -BEAST_DEFINE_TESTSUITE(doc_examples,http,beast); - -} // http -} // beast diff --git a/src/beast/test/http/doc_snippets.cpp b/src/beast/test/http/doc_snippets.cpp deleted file mode 100644 index 1fdf10de902..00000000000 --- a/src/beast/test/http/doc_snippets.cpp +++ /dev/null @@ -1,328 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#include -#include -#include -#include -#include - -using namespace beast; - -//[http_snippet_1 - -#include -using namespace beast::http; - -//] - -namespace doc_http_snippets { - -void fxx() { - - boost::asio::io_service ios; - boost::asio::io_service::work work{ios}; - std::thread t{[&](){ ios.run(); }}; - boost::asio::ip::tcp::socket sock{ios}; - -{ -//[http_snippet_2 - - request req; - req.version = 11; // HTTP/1.1 - req.method(verb::get); - req.target("/index.htm"); - req.set(field::accept, "text/html"); - req.set(field::user_agent, "Beast"); - -//] -} - -{ -//[http_snippet_3 - - response res; - res.version = 11; // HTTP/1.1 - res.result(status::ok); - res.set(field::server, "Beast"); - res.body = "Hello, world!"; - res.prepare_payload(); - -//] -} - -{ -//[http_snippet_4 - - flat_buffer buffer; // (The parser is optimized for flat buffers) - request req; - read(sock, buffer, req); - -//] -} - -{ -//[http_snippet_5 - - flat_buffer buffer; - response res; - async_read(sock, buffer, res, - [&](error_code ec) - { - std::cerr << ec.message() << std::endl; - }); - -//] -} - -{ -//[http_snippet_6 - - // This buffer's max size is too small for much of anything - flat_buffer buffer{10}; - - // Try to read a request - error_code ec; - request req; - read(sock, buffer, req, ec); - if(ec == error::buffer_overflow) - std::cerr << "Buffer limit exceeded!" << std::endl; - -//] -} - -{ -//[http_snippet_7 - - response res; - res.version = 11; - res.result(status::ok); - res.set(field::server, "Beast"); - res.body = "Hello, world!"; - - error_code ec; - write(sock, res, ec); - if(ec == error::end_of_stream) - sock.close(); -//] - -//[http_snippet_8 - async_write(sock, res, - [&](error_code) - { - if(ec) - std::cerr << ec.message() << std::endl; - }); -//] -} - -{ -//[http_snippet_10 - - response res; - - response_serializer sr{res}; - -//] -} - -} // fxx() - -//[http_snippet_12 - -/** Send a message to a stream synchronously. - - @param stream The stream to write to. This type must support - the @b SyncWriteStream concept. - - @param m The message to send. The Body type must support - the @b BodyReader concept. -*/ -template< - class SyncWriteStream, - bool isRequest, class Body, class Fields> -void -send( - SyncWriteStream& stream, - message const& m) -{ - // Check the template types - static_assert(is_sync_write_stream::value, - "SyncWriteStream requirements not met"); - static_assert(is_body_reader::value, - "BodyReader requirements not met"); - - // Create the instance of serializer for the message - serializer sr{m}; - - // Loop until the serializer is finished - do - { - // This call guarantees it will make some - // forward progress, or otherwise return an error. - write_some(stream, sr); - } - while(! sr.is_done()); -} - -//] - -//[http_snippet_13 - -template -void -print_response(SyncReadStream& stream) -{ - static_assert(is_sync_read_stream::value, - "SyncReadStream requirements not met"); - - // Declare a parser for an HTTP response - response_parser parser; - - // Read the entire message - read(stream, parser); - - // Now print the message - std::cout << parser.get() << std::endl; -} - -//] - -#ifdef BOOST_MSVC -//[http_snippet_14 - -template -void -print_cxx14(message const& m) -{ - error_code ec; - serializer sr{m}; - do - { - sr.next(ec, - [&sr](error_code& ec, auto const& buffer) - { - ec.assign(0, ec.category()); - std::cout << buffers(buffer); - sr.consume(boost::asio::buffer_size(buffer)); - }); - } - while(! ec && ! sr.is_done()); - if(! ec) - std::cout << std::endl; - else - std::cerr << ec.message() << std::endl; -} - -//] -#endif - -//[http_snippet_15 - -template -struct lambda -{ - Serializer& sr; - - lambda(Serializer& sr_) : sr(sr_) {} - - template - void operator()(error_code& ec, ConstBufferSequence const& buffer) const - { - ec.assign(0, ec.category()); - std::cout << buffers(buffer); - sr.consume(boost::asio::buffer_size(buffer)); - } -}; - -template -void -print(message const& m) -{ - error_code ec; - serializer sr{m}; - do - { - sr.next(ec, lambda{sr}); - } - while(! ec && ! sr.is_done()); - if(! ec) - std::cout << std::endl; - else - std::cerr << ec.message() << std::endl; -} - -//] - -#if BOOST_MSVC -//[http_snippet_16 - -template -void -split_print_cxx14(message const& m) -{ - error_code ec; - serializer sr{m}; - sr.split(true); - std::cout << "Header:" << std::endl; - do - { - sr.next(ec, - [&sr](error_code& ec, auto const& buffer) - { - ec.assign(0, ec.category()); - std::cout << buffers(buffer); - sr.consume(boost::asio::buffer_size(buffer)); - }); - } - while(! sr.is_header_done()); - if(! ec && ! sr.is_done()) - { - std::cout << "Body:" << std::endl; - do - { - sr.next(ec, - [&sr](error_code& ec, auto const& buffer) - { - ec.assign(0, ec.category()); - std::cout << buffers(buffer); - sr.consume(boost::asio::buffer_size(buffer)); - }); - } - while(! ec && ! sr.is_done()); - } - if(ec) - std::cerr << ec.message() << std::endl; -} - -//] -#endif - -//[http_snippet_17 - -struct decorator -{ - std::string s; - - template - string_view - operator()(ConstBufferSequence const& buffers) - { - s = ";x=" + std::to_string(boost::asio::buffer_size(buffers)); - return s; - } - - string_view - operator()(boost::asio::null_buffers) - { - return "Result: OK\r\n"; - } -}; - -//] - -} // doc_http_snippets diff --git a/src/beast/test/http/dynamic_body.cpp b/src/beast/test/http/dynamic_body.cpp deleted file mode 100644 index 37e3fb5d92f..00000000000 --- a/src/beast/test/http/dynamic_body.cpp +++ /dev/null @@ -1,51 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -class dynamic_body_test : public beast::unit_test::suite -{ - boost::asio::io_service ios_; - -public: - void - run() override - { - std::string const s = - "HTTP/1.1 200 OK\r\n" - "Server: test\r\n" - "Content-Length: 3\r\n" - "\r\n" - "xyz"; - test::string_istream ss(ios_, s); - response_parser p; - multi_buffer b; - read(ss, b, p); - auto const& m = p.get(); - BEAST_EXPECT(boost::lexical_cast( - buffers(m.body.data())) == "xyz"); - BEAST_EXPECT(boost::lexical_cast(m) == s); - } -}; - -BEAST_DEFINE_TESTSUITE(dynamic_body,http,beast); - -} // http -} // beast diff --git a/src/beast/test/http/empty_body.cpp b/src/beast/test/http/empty_body.cpp deleted file mode 100644 index a1fdfd5ec60..00000000000 --- a/src/beast/test/http/empty_body.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -namespace beast { -namespace http { - -BOOST_STATIC_ASSERT(is_body::value); -BOOST_STATIC_ASSERT(is_body_reader::value); -BOOST_STATIC_ASSERT(is_body_writer::value); - -} // http -} // beast diff --git a/src/beast/test/http/error.cpp b/src/beast/test/http/error.cpp deleted file mode 100644 index 52d986bb90c..00000000000 --- a/src/beast/test/http/error.cpp +++ /dev/null @@ -1,66 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include -#include - -namespace beast { -namespace http { - -class error_test : public unit_test::suite -{ -public: - void - check(char const* name, error ev) - { - auto const ec = make_error_code(ev); - BEAST_EXPECT(std::string(ec.category().name()) == name); - BEAST_EXPECT(! ec.message().empty()); - BEAST_EXPECT(std::addressof(ec.category()) == - std::addressof(detail::get_http_error_category())); - BEAST_EXPECT(detail::get_http_error_category().equivalent( - static_cast::type>(ev), - ec.category().default_error_condition( - static_cast::type>(ev)))); - BEAST_EXPECT(detail::get_http_error_category().equivalent( - ec, static_cast::type>(ev))); - } - - void - run() override - { - check("beast.http", error::end_of_stream); - check("beast.http", error::partial_message); - check("beast.http", error::need_more); - check("beast.http", error::unexpected_body); - check("beast.http", error::need_buffer); - check("beast.http", error::buffer_overflow); - check("beast.http", error::body_limit); - check("beast.http", error::bad_alloc); - - check("beast.http", error::bad_line_ending); - check("beast.http", error::bad_method); - check("beast.http", error::bad_target); - check("beast.http", error::bad_version); - check("beast.http", error::bad_status); - check("beast.http", error::bad_reason); - check("beast.http", error::bad_field); - check("beast.http", error::bad_value); - check("beast.http", error::bad_content_length); - check("beast.http", error::bad_transfer_encoding); - check("beast.http", error::bad_chunk); - check("beast.http", error::bad_obs_fold); - } -}; - -BEAST_DEFINE_TESTSUITE(error,http,beast); - -} // http -} // beast diff --git a/src/beast/test/http/field.cpp b/src/beast/test/http/field.cpp deleted file mode 100644 index c44f48cc89b..00000000000 --- a/src/beast/test/http/field.cpp +++ /dev/null @@ -1,405 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include - -namespace beast { -namespace http { - -class field_test : public beast::unit_test::suite -{ -public: - void - testField() - { - auto const match = - [&](field f, string_view s) - { - BEAST_EXPECT(iequals(to_string(f), s)); - BEAST_EXPECT(string_to_field(s) == f); - }; - - match(field::accept, "accept"); - match(field::accept, "aCcept"); - match(field::accept, "ACCEPT"); - - - match(field::a_im, "A-IM"); - match(field::accept, "Accept"); - match(field::accept_additions, "Accept-Additions"); - match(field::accept_charset, "Accept-Charset"); - match(field::accept_datetime, "Accept-Datetime"); - match(field::accept_encoding, "Accept-Encoding"); - match(field::accept_features, "Accept-Features"); - match(field::accept_language, "Accept-Language"); - match(field::accept_patch, "Accept-Patch"); - match(field::accept_post, "Accept-Post"); - match(field::accept_ranges, "Accept-Ranges"); - match(field::access_control, "Access-Control"); - match(field::access_control_allow_credentials, "Access-Control-Allow-Credentials"); - match(field::access_control_allow_headers, "Access-Control-Allow-Headers"); - match(field::access_control_allow_methods, "Access-Control-Allow-Methods"); - match(field::access_control_allow_origin, "Access-Control-Allow-Origin"); - match(field::access_control_max_age, "Access-Control-Max-Age"); - match(field::access_control_request_headers, "Access-Control-Request-Headers"); - match(field::access_control_request_method, "Access-Control-Request-Method"); - match(field::age, "Age"); - match(field::allow, "Allow"); - match(field::alpn, "ALPN"); - match(field::also_control, "Also-Control"); - match(field::alt_svc, "Alt-Svc"); - match(field::alt_used, "Alt-Used"); - match(field::alternate_recipient, "Alternate-Recipient"); - match(field::alternates, "Alternates"); - match(field::apparently_to, "Apparently-To"); - match(field::apply_to_redirect_ref, "Apply-To-Redirect-Ref"); - match(field::approved, "Approved"); - match(field::archive, "Archive"); - match(field::archived_at, "Archived-At"); - match(field::article_names, "Article-Names"); - match(field::article_updates, "Article-Updates"); - match(field::authentication_control, "Authentication-Control"); - match(field::authentication_info, "Authentication-Info"); - match(field::authentication_results, "Authentication-Results"); - match(field::authorization, "Authorization"); - match(field::auto_submitted, "Auto-Submitted"); - match(field::autoforwarded, "Autoforwarded"); - match(field::autosubmitted, "Autosubmitted"); - match(field::base, "Base"); - match(field::bcc, "Bcc"); - match(field::body, "Body"); - match(field::c_ext, "C-Ext"); - match(field::c_man, "C-Man"); - match(field::c_opt, "C-Opt"); - match(field::c_pep, "C-PEP"); - match(field::c_pep_info, "C-PEP-Info"); - match(field::cache_control, "Cache-Control"); - match(field::caldav_timezones, "CalDAV-Timezones"); - match(field::cancel_key, "Cancel-Key"); - match(field::cancel_lock, "Cancel-Lock"); - match(field::cc, "Cc"); - match(field::close, "Close"); - match(field::comments, "Comments"); - match(field::compliance, "Compliance"); - match(field::connection, "Connection"); - match(field::content_alternative, "Content-Alternative"); - match(field::content_base, "Content-Base"); - match(field::content_description, "Content-Description"); - match(field::content_disposition, "Content-Disposition"); - match(field::content_duration, "Content-Duration"); - match(field::content_encoding, "Content-Encoding"); - match(field::content_features, "Content-features"); - match(field::content_id, "Content-ID"); - match(field::content_identifier, "Content-Identifier"); - match(field::content_language, "Content-Language"); - match(field::content_length, "Content-Length"); - match(field::content_location, "Content-Location"); - match(field::content_md5, "Content-MD5"); - match(field::content_range, "Content-Range"); - match(field::content_return, "Content-Return"); - match(field::content_script_type, "Content-Script-Type"); - match(field::content_style_type, "Content-Style-Type"); - match(field::content_transfer_encoding, "Content-Transfer-Encoding"); - match(field::content_type, "Content-Type"); - match(field::content_version, "Content-Version"); - match(field::control, "Control"); - match(field::conversion, "Conversion"); - match(field::conversion_with_loss, "Conversion-With-Loss"); - match(field::cookie, "Cookie"); - match(field::cookie2, "Cookie2"); - match(field::cost, "Cost"); - match(field::dasl, "DASL"); - match(field::date, "Date"); - match(field::date_received, "Date-Received"); - match(field::dav, "DAV"); - match(field::default_style, "Default-Style"); - match(field::deferred_delivery, "Deferred-Delivery"); - match(field::delivery_date, "Delivery-Date"); - match(field::delta_base, "Delta-Base"); - match(field::depth, "Depth"); - match(field::derived_from, "Derived-From"); - match(field::destination, "Destination"); - match(field::differential_id, "Differential-ID"); - match(field::digest, "Digest"); - match(field::discarded_x400_ipms_extensions, "Discarded-X400-IPMS-Extensions"); - match(field::discarded_x400_mts_extensions, "Discarded-X400-MTS-Extensions"); - match(field::disclose_recipients, "Disclose-Recipients"); - match(field::disposition_notification_options, "Disposition-Notification-Options"); - match(field::disposition_notification_to, "Disposition-Notification-To"); - match(field::distribution, "Distribution"); - match(field::dkim_signature, "DKIM-Signature"); - match(field::dl_expansion_history, "DL-Expansion-History"); - match(field::downgraded_bcc, "Downgraded-Bcc"); - match(field::downgraded_cc, "Downgraded-Cc"); - match(field::downgraded_disposition_notification_to, "Downgraded-Disposition-Notification-To"); - match(field::downgraded_final_recipient, "Downgraded-Final-Recipient"); - match(field::downgraded_from, "Downgraded-From"); - match(field::downgraded_in_reply_to, "Downgraded-In-Reply-To"); - match(field::downgraded_mail_from, "Downgraded-Mail-From"); - match(field::downgraded_message_id, "Downgraded-Message-Id"); - match(field::downgraded_original_recipient, "Downgraded-Original-Recipient"); - match(field::downgraded_rcpt_to, "Downgraded-Rcpt-To"); - match(field::downgraded_references, "Downgraded-References"); - match(field::downgraded_reply_to, "Downgraded-Reply-To"); - match(field::downgraded_resent_bcc, "Downgraded-Resent-Bcc"); - match(field::downgraded_resent_cc, "Downgraded-Resent-Cc"); - match(field::downgraded_resent_from, "Downgraded-Resent-From"); - match(field::downgraded_resent_reply_to, "Downgraded-Resent-Reply-To"); - match(field::downgraded_resent_sender, "Downgraded-Resent-Sender"); - match(field::downgraded_resent_to, "Downgraded-Resent-To"); - match(field::downgraded_return_path, "Downgraded-Return-Path"); - match(field::downgraded_sender, "Downgraded-Sender"); - match(field::downgraded_to, "Downgraded-To"); - match(field::ediint_features, "EDIINT-Features"); - match(field::eesst_version, "Eesst-Version"); - match(field::encoding, "Encoding"); - match(field::encrypted, "Encrypted"); - match(field::errors_to, "Errors-To"); - match(field::etag, "ETag"); - match(field::expect, "Expect"); - match(field::expires, "Expires"); - match(field::expiry_date, "Expiry-Date"); - match(field::ext, "Ext"); - match(field::followup_to, "Followup-To"); - match(field::forwarded, "Forwarded"); - match(field::from, "From"); - match(field::generate_delivery_report, "Generate-Delivery-Report"); - match(field::getprofile, "GetProfile"); - match(field::hobareg, "Hobareg"); - match(field::host, "Host"); - match(field::http2_settings, "HTTP2-Settings"); - match(field::if_, "If"); - match(field::if_match, "If-Match"); - match(field::if_modified_since, "If-Modified-Since"); - match(field::if_none_match, "If-None-Match"); - match(field::if_range, "If-Range"); - match(field::if_schedule_tag_match, "If-Schedule-Tag-Match"); - match(field::if_unmodified_since, "If-Unmodified-Since"); - match(field::im, "IM"); - match(field::importance, "Importance"); - match(field::in_reply_to, "In-Reply-To"); - match(field::incomplete_copy, "Incomplete-Copy"); - match(field::injection_date, "Injection-Date"); - match(field::injection_info, "Injection-Info"); - match(field::jabber_id, "Jabber-ID"); - match(field::keep_alive, "Keep-Alive"); - match(field::keywords, "Keywords"); - match(field::label, "Label"); - match(field::language, "Language"); - match(field::last_modified, "Last-Modified"); - match(field::latest_delivery_time, "Latest-Delivery-Time"); - match(field::lines, "Lines"); - match(field::link, "Link"); - match(field::list_archive, "List-Archive"); - match(field::list_help, "List-Help"); - match(field::list_id, "List-ID"); - match(field::list_owner, "List-Owner"); - match(field::list_post, "List-Post"); - match(field::list_subscribe, "List-Subscribe"); - match(field::list_unsubscribe, "List-Unsubscribe"); - match(field::list_unsubscribe_post, "List-Unsubscribe-Post"); - match(field::location, "Location"); - match(field::lock_token, "Lock-Token"); - match(field::man, "Man"); - match(field::max_forwards, "Max-Forwards"); - match(field::memento_datetime, "Memento-Datetime"); - match(field::message_context, "Message-Context"); - match(field::message_id, "Message-ID"); - match(field::message_type, "Message-Type"); - match(field::meter, "Meter"); - match(field::method_check, "Method-Check"); - match(field::method_check_expires, "Method-Check-Expires"); - match(field::mime_version, "MIME-Version"); - match(field::mmhs_acp127_message_identifier, "MMHS-Acp127-Message-Identifier"); - match(field::mmhs_authorizing_users, "MMHS-Authorizing-Users"); - match(field::mmhs_codress_message_indicator, "MMHS-Codress-Message-Indicator"); - match(field::mmhs_copy_precedence, "MMHS-Copy-Precedence"); - match(field::mmhs_exempted_address, "MMHS-Exempted-Address"); - match(field::mmhs_extended_authorisation_info, "MMHS-Extended-Authorisation-Info"); - match(field::mmhs_handling_instructions, "MMHS-Handling-Instructions"); - match(field::mmhs_message_instructions, "MMHS-Message-Instructions"); - match(field::mmhs_message_type, "MMHS-Message-Type"); - match(field::mmhs_originator_plad, "MMHS-Originator-PLAD"); - match(field::mmhs_originator_reference, "MMHS-Originator-Reference"); - match(field::mmhs_other_recipients_indicator_cc, "MMHS-Other-Recipients-Indicator-CC"); - match(field::mmhs_other_recipients_indicator_to, "MMHS-Other-Recipients-Indicator-To"); - match(field::mmhs_primary_precedence, "MMHS-Primary-Precedence"); - match(field::mmhs_subject_indicator_codes, "MMHS-Subject-Indicator-Codes"); - match(field::mt_priority, "MT-Priority"); - match(field::negotiate, "Negotiate"); - match(field::newsgroups, "Newsgroups"); - match(field::nntp_posting_date, "NNTP-Posting-Date"); - match(field::nntp_posting_host, "NNTP-Posting-Host"); - match(field::non_compliance, "Non-Compliance"); - match(field::obsoletes, "Obsoletes"); - match(field::opt, "Opt"); - match(field::optional, "Optional"); - match(field::optional_www_authenticate, "Optional-WWW-Authenticate"); - match(field::ordering_type, "Ordering-Type"); - match(field::organization, "Organization"); - match(field::origin, "Origin"); - match(field::original_encoded_information_types, "Original-Encoded-Information-Types"); - match(field::original_from, "Original-From"); - match(field::original_message_id, "Original-Message-ID"); - match(field::original_recipient, "Original-Recipient"); - match(field::original_sender, "Original-Sender"); - match(field::original_subject, "Original-Subject"); - match(field::originator_return_address, "Originator-Return-Address"); - match(field::overwrite, "Overwrite"); - match(field::p3p, "P3P"); - match(field::path, "Path"); - match(field::pep, "PEP"); - match(field::pep_info, "Pep-Info"); - match(field::pics_label, "PICS-Label"); - match(field::position, "Position"); - match(field::posting_version, "Posting-Version"); - match(field::pragma, "Pragma"); - match(field::prefer, "Prefer"); - match(field::preference_applied, "Preference-Applied"); - match(field::prevent_nondelivery_report, "Prevent-NonDelivery-Report"); - match(field::priority, "Priority"); - match(field::privicon, "Privicon"); - match(field::profileobject, "ProfileObject"); - match(field::protocol, "Protocol"); - match(field::protocol_info, "Protocol-Info"); - match(field::protocol_query, "Protocol-Query"); - match(field::protocol_request, "Protocol-Request"); - match(field::proxy_authenticate, "Proxy-Authenticate"); - match(field::proxy_authentication_info, "Proxy-Authentication-Info"); - match(field::proxy_authorization, "Proxy-Authorization"); - match(field::proxy_connection, "Proxy-Connection"); - match(field::proxy_features, "Proxy-Features"); - match(field::proxy_instruction, "Proxy-Instruction"); - match(field::public_, "Public"); - match(field::public_key_pins, "Public-Key-Pins"); - match(field::public_key_pins_report_only, "Public-Key-Pins-Report-Only"); - match(field::range, "Range"); - match(field::received, "Received"); - match(field::received_spf, "Received-SPF"); - match(field::redirect_ref, "Redirect-Ref"); - match(field::references, "References"); - match(field::referer, "Referer"); - match(field::referer_root, "Referer-Root"); - match(field::relay_version, "Relay-Version"); - match(field::reply_by, "Reply-By"); - match(field::reply_to, "Reply-To"); - match(field::require_recipient_valid_since, "Require-Recipient-Valid-Since"); - match(field::resent_bcc, "Resent-Bcc"); - match(field::resent_cc, "Resent-Cc"); - match(field::resent_date, "Resent-Date"); - match(field::resent_from, "Resent-From"); - match(field::resent_message_id, "Resent-Message-ID"); - match(field::resent_reply_to, "Resent-Reply-To"); - match(field::resent_sender, "Resent-Sender"); - match(field::resent_to, "Resent-To"); - match(field::resolution_hint, "Resolution-Hint"); - match(field::resolver_location, "Resolver-Location"); - match(field::retry_after, "Retry-After"); - match(field::return_path, "Return-Path"); - match(field::safe, "Safe"); - match(field::schedule_reply, "Schedule-Reply"); - match(field::schedule_tag, "Schedule-Tag"); - match(field::sec_websocket_accept, "Sec-WebSocket-Accept"); - match(field::sec_websocket_extensions, "Sec-WebSocket-Extensions"); - match(field::sec_websocket_key, "Sec-WebSocket-Key"); - match(field::sec_websocket_protocol, "Sec-WebSocket-Protocol"); - match(field::sec_websocket_version, "Sec-WebSocket-Version"); - match(field::security_scheme, "Security-Scheme"); - match(field::see_also, "See-Also"); - match(field::sender, "Sender"); - match(field::sensitivity, "Sensitivity"); - match(field::server, "Server"); - match(field::set_cookie, "Set-Cookie"); - match(field::set_cookie2, "Set-Cookie2"); - match(field::setprofile, "SetProfile"); - match(field::sio_label, "SIO-Label"); - match(field::sio_label_history, "SIO-Label-History"); - match(field::slug, "SLUG"); - match(field::soapaction, "SoapAction"); - match(field::solicitation, "Solicitation"); - match(field::status_uri, "Status-URI"); - match(field::strict_transport_security, "Strict-Transport-Security"); - match(field::subject, "Subject"); - match(field::subok, "SubOK"); - match(field::subst, "Subst"); - match(field::summary, "Summary"); - match(field::supersedes, "Supersedes"); - match(field::surrogate_capability, "Surrogate-Capability"); - match(field::surrogate_control, "Surrogate-Control"); - match(field::tcn, "TCN"); - match(field::te, "TE"); - match(field::timeout, "Timeout"); - match(field::title, "Title"); - match(field::to, "To"); - match(field::topic, "Topic"); - match(field::trailer, "Trailer"); - match(field::transfer_encoding, "Transfer-Encoding"); - match(field::ttl, "TTL"); - match(field::ua_color, "UA-Color"); - match(field::ua_media, "UA-Media"); - match(field::ua_pixels, "UA-Pixels"); - match(field::ua_resolution, "UA-Resolution"); - match(field::ua_windowpixels, "UA-Windowpixels"); - match(field::upgrade, "Upgrade"); - match(field::urgency, "Urgency"); - match(field::uri, "URI"); - match(field::user_agent, "User-Agent"); - match(field::variant_vary, "Variant-Vary"); - match(field::vary, "Vary"); - match(field::vbr_info, "VBR-Info"); - match(field::version, "Version"); - match(field::via, "Via"); - match(field::want_digest, "Want-Digest"); - match(field::warning, "Warning"); - match(field::www_authenticate, "WWW-Authenticate"); - match(field::x_archived_at, "X-Archived-At"); - match(field::x_device_accept, "X-Device-Accept"); - match(field::x_device_accept_charset, "X-Device-Accept-Charset"); - match(field::x_device_accept_encoding, "X-Device-Accept-Encoding"); - match(field::x_device_accept_language, "X-Device-Accept-Language"); - match(field::x_device_user_agent, "X-Device-User-Agent"); - match(field::x_frame_options, "X-Frame-Options"); - match(field::x_mittente, "X-Mittente"); - match(field::x_pgp_sig, "X-PGP-Sig"); - match(field::x_ricevuta, "X-Ricevuta"); - match(field::x_riferimento_message_id, "X-Riferimento-Message-ID"); - match(field::x_tiporicevuta, "X-TipoRicevuta"); - match(field::x_trasporto, "X-Trasporto"); - match(field::x_verificasicurezza, "X-VerificaSicurezza"); - match(field::x400_content_identifier, "X400-Content-Identifier"); - match(field::x400_content_return, "X400-Content-Return"); - match(field::x400_content_type, "X400-Content-Type"); - match(field::x400_mts_identifier, "X400-MTS-Identifier"); - match(field::x400_originator, "X400-Originator"); - match(field::x400_received, "X400-Received"); - match(field::x400_recipients, "X400-Recipients"); - match(field::x400_trace, "X400-Trace"); - match(field::xref, "Xref"); - - auto const unknown = - [&](string_view s) - { - BEAST_EXPECT(string_to_field(s) == field::unknown); - }; - unknown(""); - unknown("x"); - } - - void run() override - { - testField(); - pass(); - } -}; - -BEAST_DEFINE_TESTSUITE(field,http,beast); - -} // http -} // beast diff --git a/src/beast/test/http/fields.cpp b/src/beast/test/http/fields.cpp deleted file mode 100644 index 0958952de92..00000000000 --- a/src/beast/test/http/fields.cpp +++ /dev/null @@ -1,921 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -BOOST_STATIC_ASSERT(is_fields::value); - -class fields_test : public beast::unit_test::suite -{ -public: - template - using fa_t = basic_fields; - - using f_t = fa_t>; - - template - static - void - fill(std::size_t n, basic_fields& f) - { - for(std::size_t i = 1; i<= n; ++i) - f.insert(boost::lexical_cast(i), i); - } - - template - static - void - self_assign(U& u, V&& v) - { - u = std::forward(v); - } - - template - static - bool - empty(basic_fields const& f) - { - return f.begin() == f.end(); - } - - template - static - std::size_t - size(basic_fields const& f) - { - return std::distance(f.begin(), f.end()); - } - - void - testMembers() - { - using namespace test; - - // compare equal - using equal_t = test::test_allocator; - - // compare not equal - using unequal_t = test::test_allocator; - - // construction - { - { - fields f; - BEAST_EXPECT(f.begin() == f.end()); - } - { - unequal_t a1; - basic_fields f{a1}; - BEAST_EXPECT(f.get_allocator() == a1); - BEAST_EXPECT(f.get_allocator() != unequal_t{}); - } - } - - // move construction - { - { - basic_fields f1; - BEAST_EXPECT(f1.get_allocator()->nmove == 0); - f1.insert("1", "1"); - BEAST_EXPECT(f1["1"] == "1"); - basic_fields f2{std::move(f1)}; - BEAST_EXPECT(f2.get_allocator()->nmove == 1); - BEAST_EXPECT(f2["1"] == "1"); - BEAST_EXPECT(f1["1"] == ""); - } - // allocators equal - { - basic_fields f1; - f1.insert("1", "1"); - equal_t a; - basic_fields f2{std::move(f1), a}; - BEAST_EXPECT(f2["1"] == "1"); - BEAST_EXPECT(f1["1"] == ""); - } - { - // allocators unequal - basic_fields f1; - f1.insert("1", "1"); - unequal_t a; - basic_fields f2{std::move(f1), a}; - BEAST_EXPECT(f2["1"] == "1"); - } - } - - // copy construction - { - { - basic_fields f1; - f1.insert("1", "1"); - basic_fields f2{f1}; - BEAST_EXPECT(f1.get_allocator() == f2.get_allocator()); - BEAST_EXPECT(f1["1"] == "1"); - BEAST_EXPECT(f2["1"] == "1"); - } - { - basic_fields f1; - f1.insert("1", "1"); - unequal_t a; - basic_fields f2(f1, a); - BEAST_EXPECT(f1.get_allocator() != f2.get_allocator()); - BEAST_EXPECT(f1["1"] == "1"); - BEAST_EXPECT(f2["1"] == "1"); - } - { - basic_fields f1; - f1.insert("1", "1"); - basic_fields f2(f1); - BEAST_EXPECT(f1["1"] == "1"); - BEAST_EXPECT(f2["1"] == "1"); - } - { - basic_fields f1; - f1.insert("1", "1"); - equal_t a; - basic_fields f2(f1, a); - BEAST_EXPECT(f2.get_allocator() == a); - BEAST_EXPECT(f1["1"] == "1"); - BEAST_EXPECT(f2["1"] == "1"); - } - } - - // move assignment - { - { - fields f1; - f1.insert("1", "1"); - fields f2; - f2 = std::move(f1); - BEAST_EXPECT(f1.begin() == f1.end()); - BEAST_EXPECT(f2["1"] == "1"); - } - { - // propagate_on_container_move_assignment : true - using pocma_t = test::test_allocator; - basic_fields f1; - f1.insert("1", "1"); - basic_fields f2; - f2 = std::move(f1); - BEAST_EXPECT(f1.begin() == f1.end()); - BEAST_EXPECT(f2["1"] == "1"); - } - { - // propagate_on_container_move_assignment : false - using pocma_t = test::test_allocator; - basic_fields f1; - f1.insert("1", "1"); - basic_fields f2; - f2 = std::move(f1); - BEAST_EXPECT(f1.begin() == f1.end()); - BEAST_EXPECT(f2["1"] == "1"); - } - } - - // copy assignment - { - { - fields f1; - f1.insert("1", "1"); - fields f2; - f2 = f1; - BEAST_EXPECT(f1["1"] == "1"); - BEAST_EXPECT(f2["1"] == "1"); - basic_fields f3; - f3 = f2; - BEAST_EXPECT(f3["1"] == "1"); - } - { - // propagate_on_container_copy_assignment : true - using pocca_t = test::test_allocator; - basic_fields f1; - f1.insert("1", "1"); - basic_fields f2; - f2 = f1; - BEAST_EXPECT(f2["1"] == "1"); - } - { - // propagate_on_container_copy_assignment : false - using pocca_t = test::test_allocator; - basic_fields f1; - f1.insert("1", "1"); - basic_fields f2; - f2 = f1; - BEAST_EXPECT(f2["1"] == "1"); - } - } - - // swap - { - { - // propagate_on_container_swap : true - using pocs_t = test::test_allocator; - pocs_t a1, a2; - BEAST_EXPECT(a1 != a2); - basic_fields f1{a1}; - f1.insert("1", "1"); - basic_fields f2{a2}; - BEAST_EXPECT(f1.get_allocator() == a1); - BEAST_EXPECT(f2.get_allocator() == a2); - swap(f1, f2); - BEAST_EXPECT(f1.get_allocator() == a2); - BEAST_EXPECT(f2.get_allocator() == a1); - BEAST_EXPECT(f1.begin() == f1.end()); - BEAST_EXPECT(f2["1"] == "1"); - swap(f1, f2); - BEAST_EXPECT(f1.get_allocator() == a1); - BEAST_EXPECT(f2.get_allocator() == a2); - BEAST_EXPECT(f1["1"] == "1"); - BEAST_EXPECT(f2.begin() == f2.end()); - } - { - // propagate_on_container_swap : false - using pocs_t = test::test_allocator; - pocs_t a1, a2; - BEAST_EXPECT(a1 == a2); - BEAST_EXPECT(a1.id() != a2.id()); - basic_fields f1{a1}; - f1.insert("1", "1"); - basic_fields f2{a2}; - BEAST_EXPECT(f1.get_allocator() == a1); - BEAST_EXPECT(f2.get_allocator() == a2); - swap(f1, f2); - BEAST_EXPECT(f1.get_allocator().id() == a1.id()); - BEAST_EXPECT(f2.get_allocator().id() == a2.id()); - BEAST_EXPECT(f1.begin() == f1.end()); - BEAST_EXPECT(f2["1"] == "1"); - swap(f1, f2); - BEAST_EXPECT(f1.get_allocator().id() == a1.id()); - BEAST_EXPECT(f2.get_allocator().id() == a2.id()); - BEAST_EXPECT(f1["1"] == "1"); - BEAST_EXPECT(f2.begin() == f2.end()); - } - } - - // operations - { - fields f; - f.insert(field::user_agent, "x"); - BEAST_EXPECT(f.count(field::user_agent)); - BEAST_EXPECT(f.count(to_string(field::user_agent))); - BEAST_EXPECT(f.count(field::user_agent) == 1); - BEAST_EXPECT(f.count(to_string(field::user_agent)) == 1); - f.insert(field::user_agent, "y"); - BEAST_EXPECT(f.count(field::user_agent) == 2); - } - } - - void testHeaders() - { - f_t f1; - BEAST_EXPECT(empty(f1)); - fill(1, f1); - BEAST_EXPECT(size(f1) == 1); - f_t f2; - f2 = f1; - BEAST_EXPECT(size(f2) == 1); - f2.insert("2", "2"); - BEAST_EXPECT(std::distance(f2.begin(), f2.end()) == 2); - f1 = std::move(f2); - BEAST_EXPECT(size(f1) == 2); - BEAST_EXPECT(size(f2) == 0); - f_t f3(std::move(f1)); - BEAST_EXPECT(size(f3) == 2); - BEAST_EXPECT(size(f1) == 0); - self_assign(f3, std::move(f3)); - BEAST_EXPECT(size(f3) == 2); - BEAST_EXPECT(f2.erase("Not-Present") == 0); - } - - void testRFC2616() - { - f_t f; - f.insert("a", "w"); - f.insert("a", "x"); - f.insert("aa", "y"); - f.insert("f", "z"); - BEAST_EXPECT(f.count("a") == 2); - } - - void testErase() - { - f_t f; - f.insert("a", "w"); - f.insert("a", "x"); - f.insert("aa", "y"); - f.insert("f", "z"); - BEAST_EXPECT(size(f) == 4); - f.erase("a"); - BEAST_EXPECT(size(f) == 2); - } - - void - testContainer() - { - { - // group fields - fields f; - f.insert(field::age, 1); - f.insert(field::body, 2); - f.insert(field::close, 3); - f.insert(field::body, 4); - BEAST_EXPECT(std::next(f.begin(), 0)->name() == field::age); - BEAST_EXPECT(std::next(f.begin(), 1)->name() == field::body); - BEAST_EXPECT(std::next(f.begin(), 2)->name() == field::body); - BEAST_EXPECT(std::next(f.begin(), 3)->name() == field::close); - BEAST_EXPECT(std::next(f.begin(), 0)->name_string() == "Age"); - BEAST_EXPECT(std::next(f.begin(), 1)->name_string() == "Body"); - BEAST_EXPECT(std::next(f.begin(), 2)->name_string() == "Body"); - BEAST_EXPECT(std::next(f.begin(), 3)->name_string() == "Close"); - BEAST_EXPECT(std::next(f.begin(), 0)->value() == "1"); - BEAST_EXPECT(std::next(f.begin(), 1)->value() == "2"); - BEAST_EXPECT(std::next(f.begin(), 2)->value() == "4"); - BEAST_EXPECT(std::next(f.begin(), 3)->value() == "3"); - BEAST_EXPECT(f.erase(field::body) == 2); - BEAST_EXPECT(std::next(f.begin(), 0)->name_string() == "Age"); - BEAST_EXPECT(std::next(f.begin(), 1)->name_string() == "Close"); - } - { - // group fields, case insensitive - fields f; - f.insert("a", 1); - f.insert("ab", 2); - f.insert("b", 3); - f.insert("AB", 4); - BEAST_EXPECT(std::next(f.begin(), 0)->name() == field::unknown); - BEAST_EXPECT(std::next(f.begin(), 1)->name() == field::unknown); - BEAST_EXPECT(std::next(f.begin(), 2)->name() == field::unknown); - BEAST_EXPECT(std::next(f.begin(), 3)->name() == field::unknown); - BEAST_EXPECT(std::next(f.begin(), 0)->name_string() == "a"); - BEAST_EXPECT(std::next(f.begin(), 1)->name_string() == "ab"); - BEAST_EXPECT(std::next(f.begin(), 2)->name_string() == "AB"); - BEAST_EXPECT(std::next(f.begin(), 3)->name_string() == "b"); - BEAST_EXPECT(std::next(f.begin(), 0)->value() == "1"); - BEAST_EXPECT(std::next(f.begin(), 1)->value() == "2"); - BEAST_EXPECT(std::next(f.begin(), 2)->value() == "4"); - BEAST_EXPECT(std::next(f.begin(), 3)->value() == "3"); - BEAST_EXPECT(f.erase("Ab") == 2); - BEAST_EXPECT(std::next(f.begin(), 0)->name_string() == "a"); - BEAST_EXPECT(std::next(f.begin(), 1)->name_string() == "b"); - } - { - // verify insertion orde - fields f; - f.insert( "a", 1); - f.insert("dd", 2); - f.insert("b", 3); - f.insert("dD", 4); - f.insert("c", 5); - f.insert("Dd", 6); - f.insert("DD", 7); - f.insert( "e", 8); - BEAST_EXPECT(f.count("dd") == 4); - BEAST_EXPECT(std::next(f.begin(), 1)->name_string() == "dd"); - BEAST_EXPECT(std::next(f.begin(), 2)->name_string() == "dD"); - BEAST_EXPECT(std::next(f.begin(), 3)->name_string() == "Dd"); - BEAST_EXPECT(std::next(f.begin(), 4)->name_string() == "DD"); - f.set("dd", "-"); - BEAST_EXPECT(f.count("dd") == 1); - BEAST_EXPECT(f["dd"] == "-"); - } - } - - struct sized_body - { - using value_type = std::uint64_t; - - static - std::uint64_t - size(value_type const& v) - { - return v; - } - }; - - struct unsized_body - { - struct value_type {}; - }; - - void - testPreparePayload() - { - // GET, empty - { - request req; - req.version = 11; - req.method(verb::get); - - req.prepare_payload(); - BEAST_EXPECT(req.count(field::content_length) == 0); - BEAST_EXPECT(req.count(field::transfer_encoding) == 0); - - req.set(field::content_length, "0"); - req.set(field::transfer_encoding, "chunked"); - req.prepare_payload(); - - BEAST_EXPECT(req.count(field::content_length) == 0); - BEAST_EXPECT(req.count(field::transfer_encoding) == 0); - - req.set(field::transfer_encoding, "deflate"); - req.prepare_payload(); - BEAST_EXPECT(req.count(field::content_length) == 0); - BEAST_EXPECT(req[field::transfer_encoding] == "deflate"); - - req.set(field::transfer_encoding, "deflate, chunked"); - req.prepare_payload(); - BEAST_EXPECT(req.count(field::content_length) == 0); - BEAST_EXPECT(req[field::transfer_encoding] == "deflate"); - } - - // GET, sized - { - request req; - req.version = 11; - req.method(verb::get); - req.body = 50; - - req.prepare_payload(); - BEAST_EXPECT(req[field::content_length] == "50"); - BEAST_EXPECT(req[field::transfer_encoding] == ""); - - req.set(field::content_length, "0"); - req.set(field::transfer_encoding, "chunked"); - req.prepare_payload(); - BEAST_EXPECT(req[field::content_length] == "50"); - BEAST_EXPECT(req.count(field::transfer_encoding) == 0); - - req.set(field::transfer_encoding, "deflate, chunked"); - req.prepare_payload(); - BEAST_EXPECT(req[field::content_length] == "50"); - BEAST_EXPECT(req[field::transfer_encoding] == "deflate"); - } - - // PUT, empty - { - request req; - req.version = 11; - req.method(verb::put); - - req.prepare_payload(); - BEAST_EXPECT(req[field::content_length] == "0"); - BEAST_EXPECT(req.count(field::transfer_encoding) == 0); - - req.set(field::content_length, "50"); - req.set(field::transfer_encoding, "deflate, chunked"); - req.prepare_payload(); - BEAST_EXPECT(req[field::content_length] == "0"); - BEAST_EXPECT(req[field::transfer_encoding] == "deflate"); - } - - // PUT, sized - { - request req; - req.version = 11; - req.method(verb::put); - req.body = 50; - - req.prepare_payload(); - BEAST_EXPECT(req[field::content_length] == "50"); - BEAST_EXPECT(req.count(field::transfer_encoding) == 0); - - req.set(field::content_length, "25"); - req.set(field::transfer_encoding, "deflate, chunked"); - req.prepare_payload(); - BEAST_EXPECT(req[field::content_length] == "50"); - BEAST_EXPECT(req[field::transfer_encoding] == "deflate"); - } - - // POST, unsized - { - request req; - req.version = 11; - req.method(verb::post); - - req.prepare_payload(); - BEAST_EXPECT(req.count(field::content_length) == 0); - BEAST_EXPECT(req[field::transfer_encoding] == "chunked"); - - req.set(field::transfer_encoding, "deflate"); - req.prepare_payload(); - BEAST_EXPECT(req.count(field::content_length) == 0); - BEAST_EXPECT(req[field::transfer_encoding] == "deflate, chunked"); - } - - // POST, unsized HTTP/1.0 - { - request req; - req.version = 10; - req.method(verb::post); - - req.prepare_payload(); - BEAST_EXPECT(req.count(field::content_length) == 0); - BEAST_EXPECT(req.count(field::transfer_encoding) == 0); - - req.set(field::transfer_encoding, "deflate"); - req.prepare_payload(); - BEAST_EXPECT(req.count(field::content_length) == 0); - BEAST_EXPECT(req[field::transfer_encoding] == "deflate"); - } - - // OK, empty - { - response res; - res.version = 11; - - res.prepare_payload(); - BEAST_EXPECT(res[field::content_length] == "0"); - BEAST_EXPECT(res.count(field::transfer_encoding) == 0); - - res.erase(field::content_length); - res.set(field::transfer_encoding, "chunked"); - res.prepare_payload(); - BEAST_EXPECT(res[field::content_length] == "0"); - BEAST_EXPECT(res.count(field::transfer_encoding) == 0); - } - - // OK, sized - { - response res; - res.version = 11; - res.body = 50; - - res.prepare_payload(); - BEAST_EXPECT(res[field::content_length] == "50"); - BEAST_EXPECT(res.count(field::transfer_encoding) == 0); - - res.erase(field::content_length); - res.set(field::transfer_encoding, "chunked"); - res.prepare_payload(); - BEAST_EXPECT(res[field::content_length] == "50"); - BEAST_EXPECT(res.count(field::transfer_encoding) == 0); - } - - // OK, unsized - { - response res; - res.version = 11; - - res.prepare_payload(); - BEAST_EXPECT(res.count(field::content_length) == 0); - BEAST_EXPECT(res[field::transfer_encoding] == "chunked"); - } - } - - void - testKeepAlive() - { - response res; - auto const keep_alive = - [&](bool v) - { - res.keep_alive(v); - BEAST_EXPECT( - (res.keep_alive() && v) || - (! res.keep_alive() && ! v)); - }; - - BOOST_STATIC_ASSERT(fields::max_static_buffer == 4096); - std::string const big(4096 + 1, 'a'); - - // HTTP/1.0 - res.version = 10; - res.erase(field::connection); - - keep_alive(false); - BEAST_EXPECT(res.count(field::connection) == 0); - - res.set(field::connection, "close"); - keep_alive(false); - BEAST_EXPECT(res.count(field::connection) == 0); - - res.set(field::connection, "keep-alive"); - keep_alive(false); - BEAST_EXPECT(res.count(field::connection) == 0); - - res.set(field::connection, "keep-alive, close"); - keep_alive(false); - BEAST_EXPECT(res.count(field::connection) == 0); - - res.erase(field::connection); - keep_alive(true); - BEAST_EXPECT(res[field::connection] == "keep-alive"); - - res.set(field::connection, "close"); - keep_alive(true); - BEAST_EXPECT(res[field::connection] == "keep-alive"); - - res.set(field::connection, "keep-alive"); - keep_alive(true); - BEAST_EXPECT(res[field::connection] == "keep-alive"); - - res.set(field::connection, "keep-alive, close"); - keep_alive(true); - BEAST_EXPECT(res[field::connection] == "keep-alive"); - - auto const test10 = - [&](std::string s) - { - res.set(field::connection, s); - keep_alive(false); - BEAST_EXPECT(res[field::connection] == s); - - res.set(field::connection, s + ", close"); - keep_alive(false); - BEAST_EXPECT(res[field::connection] == s); - - res.set(field::connection, "keep-alive, " + s); - keep_alive(false); - BEAST_EXPECT(res[field::connection] == s); - - res.set(field::connection, "keep-alive, " + s + ", close"); - keep_alive(false); - BEAST_EXPECT(res[field::connection] == s); - - res.set(field::connection, s); - keep_alive(true); - BEAST_EXPECT(res[field::connection] == s + ", keep-alive"); - - res.set(field::connection, s + ", close"); - keep_alive(true); - BEAST_EXPECT(res[field::connection] == s + ", keep-alive"); - - res.set(field::connection, "keep-alive, " + s); - keep_alive(true); - BEAST_EXPECT(res[field::connection] == "keep-alive, " + s); - - res.set(field::connection, "keep-alive, " + s+ ", close"); - keep_alive(true); - BEAST_EXPECT(res[field::connection] == "keep-alive, " + s); - }; - - test10("foo"); - test10(big); - - // HTTP/1.1 - res.version = 11; - - res.erase(field::connection); - keep_alive(true); - BEAST_EXPECT(res.count(field::connection) == 0); - - res.set(field::connection, "close"); - keep_alive(true); - BEAST_EXPECT(res.count(field::connection) == 0); - - res.set(field::connection, "keep-alive"); - keep_alive(true); - BEAST_EXPECT(res.count(field::connection) == 0); - - res.set(field::connection, "keep-alive, close"); - keep_alive(true); - BEAST_EXPECT(res.count(field::connection) == 0); - - res.erase(field::connection); - keep_alive(false); - BEAST_EXPECT(res[field::connection] == "close"); - - res.set(field::connection, "close"); - keep_alive(false); - BEAST_EXPECT(res[field::connection] == "close"); - - res.set(field::connection, "keep-alive"); - keep_alive(false); - BEAST_EXPECT(res[field::connection] == "close"); - - res.set(field::connection, "keep-alive, close"); - keep_alive(false); - BEAST_EXPECT(res[field::connection] == "close"); - - auto const test11 = - [&](std::string s) - { - res.set(field::connection, s); - keep_alive(true); - BEAST_EXPECT(res[field::connection] == s); - - res.set(field::connection, s + ", close"); - keep_alive(true); - BEAST_EXPECT(res[field::connection] == s); - - res.set(field::connection, "keep-alive, " + s); - keep_alive(true); - BEAST_EXPECT(res[field::connection] == s); - - res.set(field::connection, "keep-alive, " + s + ", close"); - keep_alive(true); - BEAST_EXPECT(res[field::connection] == s); - - res.set(field::connection, s); - keep_alive(false); - BEAST_EXPECT(res[field::connection] == s + ", close"); - - res.set(field::connection, "close, " + s); - keep_alive(false); - BEAST_EXPECT(res[field::connection] == "close, " + s); - - res.set(field::connection, "keep-alive, " + s); - keep_alive(false); - BEAST_EXPECT(res[field::connection] == s + ", close"); - - res.set(field::connection, "close, " + s + ", keep-alive"); - keep_alive(false); - BEAST_EXPECT(res[field::connection] == "close, " + s); - }; - - test11("foo"); - test11(big); - } - - void - testContentLength() - { - response res{status::ok, 11}; - BEAST_EXPECT(res.count(field::content_length) == 0); - BEAST_EXPECT(res.count(field::transfer_encoding) == 0); - - res.content_length(0); - BEAST_EXPECT(res[field::content_length] == "0"); - - res.content_length(100); - BEAST_EXPECT(res[field::content_length] == "100"); - - res.content_length(boost::none); - BEAST_EXPECT(res.count(field::content_length) == 0); - - res.set(field::transfer_encoding, "chunked"); - res.content_length(0); - BEAST_EXPECT(res[field::content_length] == "0"); - BEAST_EXPECT(res.count(field::transfer_encoding) == 0); - - res.set(field::transfer_encoding, "chunked"); - res.content_length(100); - BEAST_EXPECT(res[field::content_length] == "100"); - BEAST_EXPECT(res.count(field::transfer_encoding) == 0); - - res.set(field::transfer_encoding, "chunked"); - res.content_length(boost::none); - BEAST_EXPECT(res.count(field::content_length) == 0); - BEAST_EXPECT(res.count(field::transfer_encoding) == 0); - - auto const check = [&](std::string s) - { - res.set(field::transfer_encoding, s); - res.content_length(0); - BEAST_EXPECT(res[field::content_length] == "0"); - BEAST_EXPECT(res[field::transfer_encoding] == s); - - res.set(field::transfer_encoding, s); - res.content_length(100); - BEAST_EXPECT(res[field::content_length] == "100"); - BEAST_EXPECT(res[field::transfer_encoding] == s); - - res.set(field::transfer_encoding, s); - res.content_length(boost::none); - BEAST_EXPECT(res.count(field::content_length) == 0); - BEAST_EXPECT(res[field::transfer_encoding] == s); - - res.set(field::transfer_encoding, s + ", chunked"); - res.content_length(0); - BEAST_EXPECT(res[field::content_length] == "0"); - BEAST_EXPECT(res[field::transfer_encoding] == s); - - res.set(field::transfer_encoding, s + ", chunked"); - res.content_length(100); - BEAST_EXPECT(res[field::content_length] == "100"); - BEAST_EXPECT(res[field::transfer_encoding] == s); - - res.set(field::transfer_encoding, s + ", chunked"); - res.content_length(boost::none); - BEAST_EXPECT(res.count(field::content_length) == 0); - BEAST_EXPECT(res[field::transfer_encoding] == s); - - res.set(field::transfer_encoding, "chunked, " + s); - res.content_length(0); - BEAST_EXPECT(res[field::content_length] == "0"); - BEAST_EXPECT(res[field::transfer_encoding] == "chunked, " + s); - - res.set(field::transfer_encoding, "chunked, " + s); - res.content_length(100); - BEAST_EXPECT(res[field::content_length] == "100"); - BEAST_EXPECT(res[field::transfer_encoding] == "chunked, " + s); - - res.set(field::transfer_encoding, "chunked, " + s); - res.content_length(boost::none); - BEAST_EXPECT(res.count(field::content_length) == 0); - BEAST_EXPECT(res[field::transfer_encoding] == "chunked, " + s); - }; - - check("foo"); - - BOOST_STATIC_ASSERT(fields::max_static_buffer == 4096); - std::string const big(4096 + 1, 'a'); - - check(big); - } - - void - testChunked() - { - response res{status::ok, 11}; - BEAST_EXPECT(res.count(field::content_length) == 0); - BEAST_EXPECT(res.count(field::transfer_encoding) == 0); - - auto const chunked = - [&](bool v) - { - res.chunked(v); - BEAST_EXPECT( - (res.chunked() && v) || - (! res.chunked() && ! v)); - BEAST_EXPECT(res.count( - field::content_length) == 0); - }; - - res.erase(field::transfer_encoding); - res.set(field::content_length, 32); - chunked(true); - BEAST_EXPECT(res[field::transfer_encoding] == "chunked"); - - res.set(field::transfer_encoding, "chunked"); - chunked(true); - BEAST_EXPECT(res[field::transfer_encoding] == "chunked"); - - res.erase(field::transfer_encoding); - res.set(field::content_length, 32); - chunked(false); - BEAST_EXPECT(res.count(field::transfer_encoding) == 0); - - res.set(field::transfer_encoding, "chunked"); - chunked(false); - BEAST_EXPECT(res.count(field::transfer_encoding) == 0); - - - - res.set(field::transfer_encoding, "foo"); - chunked(true); - BEAST_EXPECT(res[field::transfer_encoding] == "foo, chunked"); - - res.set(field::transfer_encoding, "chunked, foo"); - chunked(true); - BEAST_EXPECT(res[field::transfer_encoding] == "chunked, foo, chunked"); - - res.set(field::transfer_encoding, "chunked, foo, chunked"); - chunked(true); - BEAST_EXPECT(res[field::transfer_encoding] == "chunked, foo, chunked"); - - res.set(field::transfer_encoding, "foo, chunked"); - chunked(false); - BEAST_EXPECT(res[field::transfer_encoding] == "foo"); - - res.set(field::transfer_encoding, "chunked, foo"); - chunked(false); - BEAST_EXPECT(res[field::transfer_encoding] == "chunked, foo"); - - res.set(field::transfer_encoding, "chunked, foo, chunked"); - chunked(false); - BEAST_EXPECT(res[field::transfer_encoding] == "chunked, foo"); - } - - void - run() override - { - testMembers(); - testHeaders(); - testRFC2616(); - testErase(); - testContainer(); - testPreparePayload(); - - testKeepAlive(); - testContentLength(); - testChunked(); - } -}; - -BEAST_DEFINE_TESTSUITE(fields,http,beast); - -} // http -} // beast diff --git a/src/beast/test/http/file_body.cpp b/src/beast/test/http/file_body.cpp deleted file mode 100644 index 3555be7108f..00000000000 --- a/src/beast/test/http/file_body.cpp +++ /dev/null @@ -1,112 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -class file_body_test : public beast::unit_test::suite -{ -public: - struct lambda - { - flat_buffer buffer; - - template - void - operator()(error_code&, ConstBufferSequence const& buffers) - { - buffer.commit(boost::asio::buffer_copy( - buffer.prepare(boost::asio::buffer_size(buffers)), - buffers)); - } - }; - - template - void - doTestFileBody() - { - error_code ec; - string_view const s = - "HTTP/1.1 200 OK\r\n" - "Server: test\r\n" - "Content-Length: 3\r\n" - "\r\n" - "xyz"; - auto const temp = boost::filesystem::unique_path(); - { - response_parser> p; - p.eager(true); - - p.get().body.open( - temp.string().c_str(), file_mode::write, ec); - BEAST_EXPECTS(! ec, ec.message()); - - p.put(boost::asio::buffer(s.data(), s.size()), ec); - BEAST_EXPECTS(! ec, ec.message()); - } - { - File f; - f.open(temp.string().c_str(), file_mode::read, ec); - auto size = f.size(ec); - BEAST_EXPECTS(! ec, ec.message()); - BEAST_EXPECT(size == 3); - std::string s1; - s1.resize(3); - f.read(&s1[0], s1.size(), ec); - BEAST_EXPECTS(! ec, ec.message()); - BEAST_EXPECTS(s1 == "xyz", s); - } - { - lambda visit; - { - response> res{status::ok, 11}; - res.set(field::server, "test"); - res.body.open(temp.string().c_str(), - file_mode::scan, ec); - BEAST_EXPECTS(! ec, ec.message()); - res.prepare_payload(); - - serializer, fields> sr{res}; - sr.next(ec, visit); - BEAST_EXPECTS(! ec, ec.message()); - auto const cb = *visit.buffer.data().begin(); - string_view const s1{ - boost::asio::buffer_cast(cb), - boost::asio::buffer_size(cb)}; - BEAST_EXPECTS(s1 == s, s1); - } - } - boost::filesystem::remove(temp, ec); - BEAST_EXPECTS(! ec, ec.message()); - } - void - run() override - { - doTestFileBody(); - #if BEAST_USE_WIN32_FILE - doTestFileBody(); - #endif - #if BEAST_USE_POSIX_FILE - doTestFileBody(); - #endif - } -}; - -BEAST_DEFINE_TESTSUITE(file_body,http,beast); - -} // http -} // beast diff --git a/src/beast/test/http/message.cpp b/src/beast/test/http/message.cpp deleted file mode 100644 index 18159fee952..00000000000 --- a/src/beast/test/http/message.cpp +++ /dev/null @@ -1,376 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -class message_test : public beast::unit_test::suite -{ -public: - struct Arg1 - { - bool moved = false; - - Arg1() = default; - - Arg1(Arg1&& other) - { - other.moved = true; - } - }; - - struct Arg2 { }; - struct Arg3 { }; - - // default constructible Body - struct default_body - { - using value_type = std::string; - }; - - // 1-arg constructible Body - struct one_arg_body - { - struct value_type - { - explicit - value_type(Arg1 const&) - { - } - - explicit - value_type(Arg1&& arg) - { - Arg1 arg_(std::move(arg)); - } - }; - }; - - // 2-arg constructible Body - struct two_arg_body - { - struct value_type - { - value_type(Arg1 const&, Arg2 const&) - { - } - }; - }; - - // 0-arg - BOOST_STATIC_ASSERT(std::is_constructible< - request>::value); - - // 1-arg - BOOST_STATIC_ASSERT(! std::is_constructible - >::value); - - //BOOST_STATIC_ASSERT(! std::is_constructible, - // verb, string_view, unsigned>::value); - - BOOST_STATIC_ASSERT(std::is_constructible, - verb, string_view, unsigned, Arg1>::value); - - BOOST_STATIC_ASSERT(std::is_constructible, - verb, string_view, unsigned, Arg1&&>::value); - - BOOST_STATIC_ASSERT(std::is_constructible, - verb, string_view, unsigned, Arg1 const>::value); - - BOOST_STATIC_ASSERT(std::is_constructible, - verb, string_view, unsigned, Arg1 const&>::value); - - // 1-arg + fields - BOOST_STATIC_ASSERT(std::is_constructible, - verb, string_view, unsigned, Arg1, fields::allocator_type>::value); - - BOOST_STATIC_ASSERT(std::is_constructible, std::piecewise_construct_t, - std::tuple>::value); - - BOOST_STATIC_ASSERT(std::is_constructible, std::piecewise_construct_t, - std::tuple>::value); - - BOOST_STATIC_ASSERT(std::is_constructible, std::piecewise_construct_t, - std::tuple, std::tuple>::value); - - // special members - BOOST_STATIC_ASSERT(std::is_copy_constructible>::value); - BOOST_STATIC_ASSERT(std::is_move_constructible>::value); - BOOST_STATIC_ASSERT(std::is_copy_assignable>::value); - BOOST_STATIC_ASSERT(std::is_move_assignable>::value); - BOOST_STATIC_ASSERT(std::is_copy_constructible>::value); - BOOST_STATIC_ASSERT(std::is_move_constructible>::value); - BOOST_STATIC_ASSERT(std::is_copy_assignable>::value); - BOOST_STATIC_ASSERT(std::is_move_assignable>::value); - - void - testMessage() - { - { - Arg1 arg1; - request{verb::get, "/", 11, std::move(arg1)}; - BEAST_EXPECT(arg1.moved); - } - - { - header h; - h.set(field::user_agent, "test"); - BEAST_EXPECT(h[field::user_agent] == "test"); - request m{std::move(h)}; - BEAST_EXPECT(m[field::user_agent] == "test"); - BEAST_EXPECT(h.count(field::user_agent) == 0); - } - { - request h{verb::get, "/", 10}; - h.set(field::user_agent, "test"); - request m{std::move(h.base()), Arg1{}}; - BEAST_EXPECT(m["User-Agent"] == "test"); - BEAST_EXPECT(h.count(http::field::user_agent) == 0); - BEAST_EXPECT(m.method() == verb::get); - BEAST_EXPECT(m.target() == "/"); - BEAST_EXPECT(m.version == 10); - } - - // swap - request m1; - request m2; - m1.target("u"); - m1.body = "1"; - m1.insert("h", "v"); - m2.method_string("G"); - m2.body = "2"; - swap(m1, m2); - BEAST_EXPECT(m1.method_string() == "G"); - BEAST_EXPECT(m2.method_string().empty()); - BEAST_EXPECT(m1.target().empty()); - BEAST_EXPECT(m2.target() == "u"); - BEAST_EXPECT(m1.body == "2"); - BEAST_EXPECT(m2.body == "1"); - BEAST_EXPECT(! m1.count("h")); - BEAST_EXPECT(m2.count("h")); - } - - struct MoveFields : fields - { - bool moved_to = false; - bool moved_from = false; - - MoveFields() = default; - - MoveFields(MoveFields&& other) - : moved_to(true) - { - other.moved_from = true; - } - - MoveFields& operator=(MoveFields&&) - { - return *this; - } - }; - - struct token {}; - - struct test_fields - { - std::string target; - - test_fields() = delete; - test_fields(token) {} - string_view get_method_impl() const { return {}; } - string_view get_target_impl() const { return target; } - string_view get_reason_impl() const { return {}; } - bool get_chunked_impl() const { return false; } - bool get_keep_alive_impl(unsigned) const { return true; } - void set_method_impl(string_view) {} - void set_target_impl(string_view s) { target = s.to_string(); } - void set_reason_impl(string_view) {} - void set_chunked_impl(bool) {} - void set_content_length_impl(boost::optional) {} - void set_keep_alive_impl(unsigned, bool) {} - }; - - void - testMessageCtors() - { - { - request req; - BEAST_EXPECT(req.version == 11); - BEAST_EXPECT(req.method() == verb::unknown); - BEAST_EXPECT(req.target() == ""); - } - { - request req{verb::get, "/", 11}; - BEAST_EXPECT(req.version == 11); - BEAST_EXPECT(req.method() == verb::get); - BEAST_EXPECT(req.target() == "/"); - } - { - request req{verb::get, "/", 11, "Hello"}; - BEAST_EXPECT(req.version == 11); - BEAST_EXPECT(req.method() == verb::get); - BEAST_EXPECT(req.target() == "/"); - BEAST_EXPECT(req.body == "Hello"); - } - { - request req{ - verb::get, "/", 11, "Hello", token{}}; - BEAST_EXPECT(req.version == 11); - BEAST_EXPECT(req.method() == verb::get); - BEAST_EXPECT(req.target() == "/"); - BEAST_EXPECT(req.body == "Hello"); - } - { - response res; - BEAST_EXPECT(res.version == 11); - BEAST_EXPECT(res.result() == status::ok); - BEAST_EXPECT(res.reason() == "OK"); - } - { - response res{status::bad_request, 10}; - BEAST_EXPECT(res.version == 10); - BEAST_EXPECT(res.result() == status::bad_request); - BEAST_EXPECT(res.reason() == "Bad Request"); - } - { - response res{status::bad_request, 10, "Hello"}; - BEAST_EXPECT(res.version == 10); - BEAST_EXPECT(res.result() == status::bad_request); - BEAST_EXPECT(res.reason() == "Bad Request"); - BEAST_EXPECT(res.body == "Hello"); - } - { - response res{ - status::bad_request, 10, "Hello", token{}}; - BEAST_EXPECT(res.version == 10); - BEAST_EXPECT(res.result() == status::bad_request); - BEAST_EXPECT(res.reason() == "Bad Request"); - BEAST_EXPECT(res.body == "Hello"); - } - } - - void - testSwap() - { - response m1; - response m2; - m1.result(status::ok); - m1.version = 10; - m1.body = "1"; - m1.insert("h", "v"); - m2.result(status::not_found); - m2.body = "2"; - m2.version = 11; - swap(m1, m2); - BEAST_EXPECT(m1.result() == status::not_found); - BEAST_EXPECT(m1.result_int() == 404); - BEAST_EXPECT(m2.result() == status::ok); - BEAST_EXPECT(m2.result_int() == 200); - BEAST_EXPECT(m1.reason() == "Not Found"); - BEAST_EXPECT(m2.reason() == "OK"); - BEAST_EXPECT(m1.version == 11); - BEAST_EXPECT(m2.version == 10); - BEAST_EXPECT(m1.body == "2"); - BEAST_EXPECT(m2.body == "1"); - BEAST_EXPECT(! m1.count("h")); - BEAST_EXPECT(m2.count("h")); - } - - void - testSpecialMembers() - { - response r1; - response r2{r1}; - response r3{std::move(r2)}; - r2 = r3; - r1 = std::move(r2); - [r1]() - { - }(); - } - - void - testMethod() - { - header h; - auto const vcheck = - [&](verb v) - { - h.method(v); - BEAST_EXPECT(h.method() == v); - BEAST_EXPECT(h.method_string() == to_string(v)); - }; - auto const scheck = - [&](string_view s) - { - h.method_string(s); - BEAST_EXPECT(h.method() == string_to_verb(s)); - BEAST_EXPECT(h.method_string() == s); - }; - vcheck(verb::get); - vcheck(verb::head); - scheck("GET"); - scheck("HEAD"); - scheck("XYZ"); - } - - void - testStatus() - { - header h; - h.result(200); - BEAST_EXPECT(h.result_int() == 200); - BEAST_EXPECT(h.result() == status::ok); - h.result(status::switching_protocols); - BEAST_EXPECT(h.result_int() == 101); - BEAST_EXPECT(h.result() == status::switching_protocols); - h.result(1); - BEAST_EXPECT(h.result_int() == 1); - BEAST_EXPECT(h.result() == status::unknown); - } - - void - testReason() - { - header h; - h.result(status::ok); - BEAST_EXPECT(h.reason() == "OK"); - h.reason("Pepe"); - BEAST_EXPECT(h.reason() == "Pepe"); - h.result(status::not_found); - BEAST_EXPECT(h.reason() == "Pepe"); - h.reason({}); - BEAST_EXPECT(h.reason() == "Not Found"); - } - - void - run() override - { - testMessage(); - testMessageCtors(); - testSwap(); - testSpecialMembers(); - testMethod(); - testStatus(); - testReason(); - } -}; - -BEAST_DEFINE_TESTSUITE(message,http,beast); - -} // http -} // beast diff --git a/src/beast/test/http/message_fuzz.hpp b/src/beast/test/http/message_fuzz.hpp deleted file mode 100644 index 2c1ff25b0b9..00000000000 --- a/src/beast/test/http/message_fuzz.hpp +++ /dev/null @@ -1,568 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_TEST_MESSAGE_FUZZ_HPP -#define BEAST_HTTP_TEST_MESSAGE_FUZZ_HPP - -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -template -std::string -escaped_string(string_view s) -{ - std::string out; - out.reserve(s.size()); - char const* p = s.data(); - while(p != s.end()) - { - if(*p == '\r') - out.append("\\r"); - else if(*p == '\n') - out.append("\\n"); - else if(*p == '\t') - out.append("\\t"); - else - out.append(p, 1); - ++p; - } - return out; -} - -// Produces random HTTP messages -// -template -class message_fuzz_t -{ - std::mt19937 rng_; - - static - std::string - to_hex(std::size_t v) - { - if(! v) - return "0"; - std::string s; - while(v > 0) - { - s.insert(s.begin(), - "0123456789abcdef"[v&0xf]); - v >>= 4; - } - return s; - } - -public: - template - UInt - rand(std::size_t n) - { - return static_cast( - std::uniform_int_distribution< - std::size_t>{0, n-1}(rng_)); - } - - std::string - method() - { -#if 0 - // All IANA registered methods - static char const* const list[39] = { - "ACL", "BASELINE-CONTROL", "BIND", "CHECKIN", "CHECKOUT", "CONNECT", - "COPY", "DELETE", "GET", "HEAD", "LABEL", "LINK", "LOCK", "MERGE", - "MKACTIVITY", "MKCALENDAR", "MKCOL", "MKREDIRECTREF", "MKWORKSPACE", - "MOVE", "OPTIONS", "ORDERPATCH", "PATCH", "POST", "PRI", "PROPFIND", - "PROPPATCH", "PUT", "REBIND", "REPORT", "SEARCH", "TRACE", "UNBIND", - "UNCHECKOUT", "UNLINK", "UNLOCK", "UPDATE", "UPDATEREDIRECTREF", - "VERSION-CONTROL" - }; - return list[rand(39)]; -#else - // methods parsed by nodejs-http-parser - static char const* const list[33] = { - "ACL", "BIND", "CHECKOUT", "CONNECT", "COPY", "DELETE", "HEAD", "GET", - "LINK", "LOCK", "MERGE", "MKCOL", "MKCALENDAR", "MKACTIVITY", "M-SEARCH", - "MOVE", "NOTIFY", "OPTIONS", "PATCH", "POST", "PROPFIND", "PROPPATCH", - "PURGE", "PUT", "REBIND", "REPORT", "SEARCH", "SUBSCRIBE", "TRACE", - "UNBIND", "UNLINK", "UNLOCK", "UNSUBSCRIBE" - }; - return list[rand(33)]; -#endif - } - - std::string - scheme() - { - static char const* const list[241] = { - "aaa", "aaas", "about", "acap", "acct", "acr", "adiumxtra", "afp", "afs", - "aim", "appdata", "apt", "attachment", "aw", "barion", "beshare", "bitcoin", - "blob", "bolo", "callto", "cap", "chrome", "chrome-extension", "cid", - "coap", "coaps", "com-eventbrite-attendee", "content", "crid", "cvs", - "data", "dav", "dict", "dis", "dlna-playcontainer", "dlna-playsingle", - "dns", "dntp", "dtn", "dvb", "ed2k", "example", "facetime", "fax", "feed", - "feedready", "file", "filesystem", "finger", "fish", "ftp", "geo", "gg", - "git", "gizmoproject", "go", "gopher", "gtalk", "h323", "ham", "hcp", - "http", "https", "iax", "icap", "icon", "im", "imap", "info", "iotdisco", - "ipn", "ipp", "ipps", "irc", "irc6", "ircs", "iris", "iris.beep", - "iris.lwz", "iris.xpc", "iris.xpcs", "isostore", "itms", "jabber", "jar", - "jms", "keyparc", "lastfm", "ldap", "ldaps", "magnet", "mailserver", - "mailto", "maps", "market", "message", "mid", "mms", - "modem", "ms-access", "ms-drive-to", "ms-enrollment", "ms-excel", - "ms-getoffice", "ms-help", "ms-infopath", "ms-media-stream-id", "ms-project", - "ms-powerpoint", "ms-publisher", "ms-search-repair", - "ms-secondary-screen-controller", "ms-secondary-screen-setup", - "ms-settings", "ms-settings-airplanemode", "ms-settings-bluetooth", - "ms-settings-camera", "ms-settings-cellular", "ms-settings-cloudstorage", - "ms-settings-emailandaccounts", "ms-settings-language", "ms-settings-location", - "ms-settings-lock", "ms-settings-nfctransactions", "ms-settings-notifications", - "ms-settings-power", "ms-settings-privacy", "ms-settings-proximity", - "ms-settings-screenrotation", "ms-settings-wifi", "ms-settings-workplace", - "ms-spd", "ms-transit-to", "ms-visio", "ms-walk-to", "ms-word", "msnim", - "msrp", "msrps", "mtqp", "mumble", "mupdate", "mvn", "news", "nfs", "ni", - "nih", "nntp", "notes", "oid", "opaquelocktoken", "pack", "palm", "paparazzi", - "pkcs11", "platform", "pop", "pres", "prospero", "proxy", "psyc", "query", - "redis", "rediss", "reload", "res", "target", "rmi", "rsync", "rtmfp", - "rtmp", "rtsp", "rtsps", "rtspu", "secondlife", "service", "session", "sftp", - "sgn", "shttp", "sieve", "sip", "sips", "skype", "smb", "sms", "smtp", - "snews", "snmp", "soap.beep", "soap.beeps", "soldat", "spotify", "ssh", - "steam", "stun", "stuns", "submit", "svn", "tag", "teamspeak", "tel", - "teliaeid", "telnet", "tftp", "things", "thismessage", "tip", "tn3270", - "tool", "turn", "turns", "tv", "udp", "unreal", "urn", "ut2004", "v-event", - "vemmi", "ventrilo", "videotex", "vnc", "view-source", "wais", "webcal", - "wpid", "ws", "wss", "wtai", "wyciwyg", "xcon", "xcon-userid", "xfire", - "xmlrpc.beep", "xmlrpc.beeps", "xmpp", "xri", "ymsgr", "z39.50", "z39.50r", - "z39.50s:" - }; - return list[rand(241)]; - } - - std::string - pchar() - { - if(rand(4)) - return std::string(1, - "0123456789" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" - ":@&=+$,"[rand(69)]); - std::string s = "%"; - s += "0123456789abcdef"[rand(16)]; - s += "0123456789abcdef"[rand(16)]; - return s; - } - - char - uric() - { - return 'a'; - } - - char - uric_no_slash() - { - return 'a'; - } - - std::string - param() - { - std::string s; - while(rand(2)) - s += pchar(); - return s; - } - - std::string - query() - { - std::string s; - while(rand(2)) - s += uric(); - return s; - } - - std::string - userinfo() - { - std::string s; - while(rand(2)) - s += "a"; - return s; - } - - /* authority = server | reg_name - - reg_name = 1*( unreserved | escaped | "$" | "," | - ";" | ":" | "@" | "&" | "=" | "+" ) - - server = [ [ userinfo "@" ] hostport ] - userinfo = *( unreserved | escaped | - ";" | ":" | "&" | "=" | "+" | "$" | "," ) - - hostport = host [ ":" port ] - host = hostname | IPv4address - hostname = *( domainlabel "." ) toplabel [ "." ] - domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum - toplabel = alpha | alpha *( alphanum | "-" ) alphanum - IPv4address = 1*digit "." 1*digit "." 1*digit "." 1*digit - port = *digit - */ - std::string - server() - { - std::string s; - if(rand(2)) - s += userinfo() + "@"; - return s; - } - - std::string - reg_name() - { - std::string s; - s = "a"; - while(rand(2)) - s += "a"; - return s; - } - - std::string - authority() - { - if(rand(2)) - return server(); - return reg_name(); - } - - std::string - opaque_part() - { - std::string s; - s += uric_no_slash(); - while(rand(2)) - s += uric(); - return s; - } - - /* abs_path = "/" path_segments - path_segments = segment *( "/" segment ) - segment = *pchar *( ";" param ) - param = *pchar - pchar = unreserved | escaped | - ":" | "@" | "&" | "=" | "+" | "$" | "," - */ - std::string - abs_path() - { - std::string s = "/"; - for(;;) - { - while(rand(2)) - s += pchar(); - while(rand(2)) - s += ";" + param(); - if(rand(2)) - break; - s.append("/"); - } - return s; - } - - /* net_path = "//" authority [ abs_path ] - */ - std::string - net_path() - { - std::string s = "//"; - s += authority(); - if(rand(2)) - s += abs_path(); - return s; - } - - /* absoluteURI = scheme ":" ( hier_part | opaque_part ) - scheme = alpha *( alpha | digit | "+" | "-" | "." ) - hier_part = ( net_path | abs_path ) [ "?" query ] - abs_path = "/" path_segments - query = *uric - opaque_part = uric_no_slash *uric - */ - std::string - abs_uri() - { - std::string s; - s = scheme() + ":"; - if(rand(2)) - { - if(rand(2)) - s += net_path(); - else - s += abs_path(); - if(rand(2)) - s += "?" + query(); - } - else - { - s += opaque_part(); - } - return s; - } - - std::string - target() - { - //switch(rand(4)) - switch(1) - { - case 0: return abs_uri(); - case 1: return abs_path(); - case 2: return authority(); - default: - case 3: break; - } - return "*"; - } - - std::string - token() - { - static char constexpr valid[78] = - "!#$%&\'*+-." "0123456789" "ABCDEFGHIJ" "KLMNOPQRST" - "UVWXYZ^_`a" "bcdefghijk" "lmnopqrstu" "vwxyz|~"; - std::string s; - s.append(1, valid[rand(77)]); - while(rand(4)) - s.append(1, valid[rand(77)]); - return s; - } - -#if 0 - std::string - target() - { - static char constexpr alpha[63] = - "0123456789" "ABCDEFGHIJ" "KLMNOPQRST" - "UVWXYZabcd" "efghijklmn" "opqrstuvwx" "yz"; - std::string s; - s = "/"; - while(rand(4)) - s.append(1, alpha[rand(62)]); - return s; - } -#endif - - std::string - field() - { static char const* const list[289] = - { - "A-IM", - "Accept", "Accept-Additions", "Accept-Charset", "Accept-Datetime", "Accept-Encoding", - "Accept-Features", "Accept-Language", "Accept-Patch", "Accept-Ranges", "Age", "Allow", - "ALPN", "Also-Control", "Alt-Svc", "Alt-Used", "Alternate-Recipient", "Alternates", - "Apply-To-Redirect-Ref", "Approved", "Archive", "Archived-At", "Article-Names", - "Article-Updates", "Authentication-Info", "Authentication-Results", "Authorization", - "Auto-Submitted", "Autoforwarded", "Autosubmitted", "Base", "Bcc", "Body", "C-Ext", - "C-Man", "C-Opt", "C-PEP", "C-PEP-Info", "Cache-Control", - "CalDAV-Timezones", "Cc", "Close", "Comments", /*"Connection",*/ "Content-Alternative", - "Content-Base", "Content-Description", "Content-Disposition", "Content-Duration", - "Content-Encoding", "Content-features", "Content-ID", "Content-Identifier", - "Content-Language", /*"Content-Length",*/ "Content-Location", "Content-MD5", - "Content-Range", "Content-Return", "Content-Script-Type", "Content-Style-Type", - "Content-Transfer-Encoding", "Content-Type", "Content-Version", "Control", "Conversion", - "Conversion-With-Loss", "Cookie", "Cookie2", "DASL", "DAV", "DL-Expansion-History", "Date", - "Date-Received", "Default-Style", "Deferred-Delivery", "Delivery-Date", "Delta-Base", - "Depth", "Derived-From", "Destination", "Differential-ID", "Digest", - "Discarded-X400-IPMS-Extensions", "Discarded-X400-MTS-Extensions", "Disclose-Recipients", - "Disposition-Notification-Options", "Disposition-Notification-To", "Distribution", - "DKIM-Signature", "Downgraded-Bcc", "Downgraded-Cc", "Downgraded-Disposition-Notification-To", - "Downgraded-Final-Recipient", "Downgraded-From", "Downgraded-In-Reply-To", - "Downgraded-Mail-From", "Downgraded-Message-Id", "Downgraded-Original-Recipient", - "Downgraded-Rcpt-To", "Downgraded-References", "Downgraded-Reply-To", "Downgraded-Resent-Bcc", - "Downgraded-Resent-Cc", "Downgraded-Resent-From", "Downgraded-Resent-Reply-To", - "Downgraded-Resent-Sender", "Downgraded-Resent-To", "Downgraded-Return-Path", - "Downgraded-Sender", "Downgraded-To", "Encoding", "Encrypted", "ETag", "Expect", - "Expires", "Expiry-Date", "Ext", "Followup-To", "Forwarded", "From", - "Generate-Delivery-Report", "GetProfile", "Hobareg", "Host", "HTTP2-Settings", "IM", "If", - "If-Match", "If-Modified-Since", "If-None-Match", "If-Range", "If-Schedule-Tag-Match", - "If-Unmodified-Since", "Importance", "In-Reply-To", "Incomplete-Copy", "Injection-Date", - "Injection-Info", "Keep-Alive", "Keywords", "Label", "Language", "Last-Modified", - "Latest-Delivery-Time", "Lines", "Link", "List-Archive", "List-Help", "List-ID", - "List-Owner", "List-Post", "List-Subscribe", "List-Unsubscribe", "Location", "Lock-Token", - "Man", "Max-Forwards", "Memento-Datetime", "Message-Context", "Message-ID", "Message-Type", - "Meter", "MIME-Version", "MMHS-Exempted-Address", "MMHS-Extended-Authorisation-Info", - "MMHS-Subject-Indicator-Codes", "MMHS-Handling-Instructions", "MMHS-Message-Instructions", - "MMHS-Codress-Message-Indicator", "MMHS-Originator-Reference", "MMHS-Primary-Precedence", - "MMHS-Copy-Precedence", "MMHS-Message-Type", "MMHS-Other-Recipients-Indicator-To", - "MMHS-Other-Recipients-Indicator-CC", "MMHS-Acp127-Message-Identifier", "MMHS-Originator-PLAD", - "MT-Priority", "Negotiate", "Newsgroups", "NNTP-Posting-Date", "NNTP-Posting-Host", - "Obsoletes", "Opt", "Ordering-Type", "Organization", "Origin", - "Original-Encoded-Information-Types", "Original-From", "Original-Message-ID", - "Original-Recipient", "Original-Sender", "Originator-Return-Address", "Original-Subject", - "Overwrite", "P3P", "Path", "PEP", "PICS-Label", "Pep-Info", "Position", "Posting-Version", - "Pragma", "Prefer", "Preference-Applied", "Prevent-NonDelivery-Report", "Priority", - "ProfileObject", "Protocol", "Protocol-Info", "Protocol-Query", "Protocol-Request", - "Proxy-Authenticate", "Proxy-Authentication-Info", "Proxy-Authorization", "Proxy-Features", - "Proxy-Instruction", "Public", "Public-Key-Pins", "Public-Key-Pins-Report-Only", "Range", - "Received", "Received-SPF", "Redirect-Ref", "References", "Referer", "Relay-Version", - "Reply-By", "Reply-To", "Require-Recipient-Valid-Since", "Resent-Bcc", "Resent-Cc", - "Resent-Date", "Resent-From", "Resent-Message-ID", "Resent-Reply-To", "Resent-Sender", - "Resent-To", "Retry-After", "Return-Path", "Safe", "Schedule-Reply", "Schedule-Tag", - "Sec-WebSocket-Accept", "Sec-WebSocket-Extensions", "Sec-WebSocket-Key", - "Sec-WebSocket-Protocol", "Sec-WebSocket-Version", "Security-Scheme", "See-Also", "Sender", - "Sensitivity", "Server", "Set-Cookie", "Set-Cookie2", - "SetProfile", "SLUG", "SoapAction", "Solicitation", "Status-URI", "Strict-Transport-Security", - "Subject", "Summary", "Supersedes", "Surrogate-Capability", "Surrogate-Control", "TCN", - "TE", "Timeout", "To", "Trailer", /*"Transfer-Encoding",*/ "URI", /*"Upgrade",*/ "User-Agent", - "Variant-Vary", "Vary", "VBR-Info", "Via", "WWW-Authenticate", "Want-Digest", "Warning", - "X400-Content-Identifier", "X400-Content-Return", "X400-Content-Type", "X400-MTS-Identifier", - "X400-Originator", "X400-Received", "X400-Recipients", "X400-Trace", "X-Frame-Options", "Xref" - }; - return list[rand(289)]; - } - - std::string - text() - { - std::string s; - while(rand(3)) - { - for(;;) - { - char c = rand(256); - if(detail::is_text(c)) - { - s.append(1, c); - break; - } - } - } - return s; - } - - std::string - value() - { - std::string s; - while(rand(3)) - { - if(rand(5)) - { - s.append(text()); - } - else - { - // LWS - if(! rand(4)) - s.append("\r\n"); - s.append(1, rand(2) ? ' ' : '\t'); - while(rand(2)) - s.append(1, rand(2) ? ' ' : '\t'); - } - } - return s; - } - - template - void - fields(DynamicBuffer& db) - { - auto os = ostream(db); - while(rand(6)) - os << - field() << - (rand(4) ? ": " : ":") << - value() << - "\r\n"; - } - - template - void - body(DynamicBuffer& db) - { - if(! rand(4)) - { - ostream(db) << - "Content-Length: 0\r\n\r\n"; - return; - } - if(rand(2)) - { - auto const len = rand(500); - ostream(db) << - "Content-Length: " << len << "\r\n\r\n"; - for(boost::asio::mutable_buffer b : db.prepare(len)) - { - auto p = boost::asio::buffer_cast(b); - auto n = boost::asio::buffer_size(b); - while(n--) - *p++ = static_cast(32 + rand(26+26+10+6)); - } - db.commit(len); - } - else - { - auto len = rand(500); - ostream(db) << - "Transfer-Encoding: chunked\r\n\r\n"; - while(len > 0) - { - auto n = (std::min)(1 + rand(300), len); - len -= n; - ostream(db) << - to_hex(n) << "\r\n"; - for(boost::asio::mutable_buffer b : db.prepare(n)) - { - auto p = boost::asio::buffer_cast(b); - auto m = boost::asio::buffer_size(b); - while(m--) - *p++ = static_cast(32 + rand(26+26+10+6)); - } - db.commit(n); - ostream(db) << "\r\n"; - } - ostream(db) << "0\r\n\r\n"; - } - } - - template - void - request(DynamicBuffer& db) - { - ostream(db) << - method() << " " << target() << " HTTP/1.1\r\n"; - fields(db); - body(db); - } - - template - void - response(DynamicBuffer& db) - { - ostream(db) << - "HTTP/1." << - (rand(2) ? "0" : "1") << " " << - (100 + rand(401)) << " " << - token() << - "\r\n"; - fields(db); - body(db); - ostream(db) << "\r\n"; - } -}; - -using message_fuzz = message_fuzz_t<>; - -} // http -} // beast - -#endif diff --git a/src/beast/test/http/parser.cpp b/src/beast/test/http/parser.cpp deleted file mode 100644 index cae9d904578..00000000000 --- a/src/beast/test/http/parser.cpp +++ /dev/null @@ -1,389 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include "test_parser.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -class parser_test - : public beast::unit_test::suite - , public beast::test::enable_yield_to -{ -public: - template - using parser_type = - parser; - - static - boost::asio::const_buffers_1 - buf(string_view s) - { - return {s.data(), s.size()}; - } - - template - static - void - put(ConstBufferSequence const& buffers, - basic_parser& p, - error_code& ec) - { - using boost::asio::buffer_size; - consuming_buffers cb{buffers}; - for(;;) - { - auto const used = p.put(cb, ec); - cb.consume(used); - if(ec) - return; - if(p.need_eof() && - buffer_size(cb) == 0) - { - p.put_eof(ec); - if(ec) - return; - } - if(p.is_done()) - break; - } - } - - template - void - doMatrix(string_view s0, F const& f) - { - using boost::asio::buffer; - // parse a single buffer - { - auto s = s0; - error_code ec; - parser_type p; - put(buffer(s.data(), s.size()), p, ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - f(p); - } - // parse two buffers - for(auto n = s0.size() - 1; n >= 1; --n) - { - auto s = s0; - error_code ec; - parser_type p; - p.eager(true); - auto used = - p.put(buffer(s.data(), n), ec); - s.remove_prefix(used); - if(ec == error::need_more) - ec.assign(0, ec.category()); - if(! BEAST_EXPECTS(! ec, ec.message())) - continue; - BEAST_EXPECT(! p.is_done()); - used = p.put( - buffer(s.data(), s.size()), ec); - s.remove_prefix(used); - if(! BEAST_EXPECTS(! ec, ec.message())) - continue; - BEAST_EXPECT(s.empty()); - if(p.need_eof()) - { - p.put_eof(ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - continue; - } - if(BEAST_EXPECT(p.is_done())) - f(p); - } - } - - void - testParse() - { - doMatrix( - "HTTP/1.0 200 OK\r\n" - "Server: test\r\n" - "\r\n" - "Hello, world!", - [&](parser_type const& p) - { - auto const& m = p.get(); - BEAST_EXPECT(! p.is_chunked()); - BEAST_EXPECT(p.need_eof()); - BEAST_EXPECT(p.content_length() == boost::none); - BEAST_EXPECT(m.version == 10); - BEAST_EXPECT(m.result() == status::ok); - BEAST_EXPECT(m.reason() == "OK"); - BEAST_EXPECT(m["Server"] == "test"); - BEAST_EXPECT(m.body == "Hello, world!"); - } - ); - doMatrix( - "HTTP/1.1 200 OK\r\n" - "Server: test\r\n" - "Expect: Expires, MD5-Fingerprint\r\n" - "Transfer-Encoding: chunked\r\n" - "\r\n" - "5\r\n" - "*****\r\n" - "2;a;b=1;c=\"2\"\r\n" - "--\r\n" - "0;d;e=3;f=\"4\"\r\n" - "Expires: never\r\n" - "MD5-Fingerprint: -\r\n" - "\r\n", - [&](parser_type const& p) - { - auto const& m = p.get(); - BEAST_EXPECT(! p.need_eof()); - BEAST_EXPECT(p.is_chunked()); - BEAST_EXPECT(p.content_length() == boost::none); - BEAST_EXPECT(m.version == 11); - BEAST_EXPECT(m.result() == status::ok); - BEAST_EXPECT(m.reason() == "OK"); - BEAST_EXPECT(m["Server"] == "test"); - BEAST_EXPECT(m["Transfer-Encoding"] == "chunked"); - BEAST_EXPECT(m["Expires"] == "never"); - BEAST_EXPECT(m["MD5-Fingerprint"] == "-"); - BEAST_EXPECT(m.body == "*****--"); - } - ); - doMatrix( - "HTTP/1.0 200 OK\r\n" - "Server: test\r\n" - "Content-Length: 5\r\n" - "\r\n" - "*****", - [&](parser_type const& p) - { - auto const& m = p.get(); - BEAST_EXPECT(m.body == "*****"); - } - ); - doMatrix( - "GET / HTTP/1.1\r\n" - "User-Agent: test\r\n" - "\r\n", - [&](parser_type const& p) - { - auto const& m = p.get(); - BEAST_EXPECT(m.method() == verb::get); - BEAST_EXPECT(m.target() == "/"); - BEAST_EXPECT(m.version == 11); - BEAST_EXPECT(! p.need_eof()); - BEAST_EXPECT(! p.is_chunked()); - BEAST_EXPECT(p.content_length() == boost::none); - } - ); - doMatrix( - "GET / HTTP/1.1\r\n" - "User-Agent: test\r\n" - "X: \t x \t \r\n" - "\r\n", - [&](parser_type const& p) - { - auto const& m = p.get(); - BEAST_EXPECT(m["X"] == "x"); - } - ); - - // test eager(true) - { - error_code ec; - parser_type p; - p.eager(true); - p.put(buf( - "GET / HTTP/1.1\r\n" - "User-Agent: test\r\n" - "Content-Length: 1\r\n" - "\r\n" - "*") - , ec); - auto const& m = p.get(); - BEAST_EXPECT(! ec); - BEAST_EXPECT(p.is_done()); - BEAST_EXPECT(p.is_header_done()); - BEAST_EXPECT(! p.need_eof()); - BEAST_EXPECT(m.method() == verb::get); - BEAST_EXPECT(m.target() == "/"); - BEAST_EXPECT(m.version == 11); - BEAST_EXPECT(m["User-Agent"] == "test"); - BEAST_EXPECT(m.body == "*"); - } - { - // test partial parsing of final chunk - // parse through the chunk body - error_code ec; - flat_buffer b; - parser_type p; - p.eager(true); - ostream(b) << - "PUT / HTTP/1.1\r\n" - "Transfer-Encoding: chunked\r\n" - "\r\n" - "1\r\n" - "*"; - auto used = p.put(b.data(), ec); - b.consume(used); - BEAST_EXPECT(! ec); - BEAST_EXPECT(! p.is_done()); - BEAST_EXPECT(p.get().body == "*"); - ostream(b) << - "\r\n" - "0;d;e=3;f=\"4\"\r\n" - "Expires: never\r\n" - "MD5-Fingerprint: -\r\n"; - // incomplete parse, missing the final crlf - used = p.put(b.data(), ec); - b.consume(used); - BEAST_EXPECT(ec == error::need_more); - ec.assign(0, ec.category()); - BEAST_EXPECT(! p.is_done()); - ostream(b) << - "\r\n"; // final crlf to end message - used = p.put(b.data(), ec); - b.consume(used); - BEAST_EXPECTS(! ec, ec.message()); - BEAST_EXPECT(p.is_done()); - } - // skip body - { - error_code ec; - response_parser p; - p.skip(true); - p.put(buf( - "HTTP/1.1 200 OK\r\n" - "Content-Length: 5\r\n" - "\r\n" - "*****") - , ec); - BEAST_EXPECTS(! ec, ec.message()); - BEAST_EXPECT(p.is_done()); - BEAST_EXPECT(p.is_header_done()); - BEAST_EXPECT(p.content_length() && - *p.content_length() == 5); - } - } - - //-------------------------------------------------------------------------- - - template - void - testNeedMore() - { - error_code ec; - std::size_t used; - { - DynamicBuffer b; - parser_type p; - ostream(b) << - "GET / HTTP/1.1\r\n"; - used = p.put(b.data(), ec); - BEAST_EXPECTS(ec == error::need_more, ec.message()); - b.consume(used); - ec.assign(0, ec.category()); - ostream(b) << - "User-Agent: test\r\n" - "\r\n"; - used = p.put(b.data(), ec); - BEAST_EXPECTS(! ec, ec.message()); - b.consume(used); - BEAST_EXPECT(p.is_done()); - BEAST_EXPECT(p.is_header_done()); - } - } - - void - testGotSome() - { - error_code ec; - parser_type p; - auto used = p.put(buf(""), ec); - BEAST_EXPECT(ec == error::need_more); - BEAST_EXPECT(! p.got_some()); - BEAST_EXPECT(used == 0); - ec.assign(0, ec.category()); - used = p.put(buf("G"), ec); - BEAST_EXPECT(ec == error::need_more); - BEAST_EXPECT(p.got_some()); - BEAST_EXPECT(used == 0); - } - - void - testCallback() - { - { - multi_buffer b; - ostream(b) << - "POST / HTTP/1.1\r\n" - "Content-Length: 2\r\n" - "\r\n" - "**"; - error_code ec; - parser p; - p.eager(true); - p.put(b.data(), ec); - p.on_header( - [this](parser& p, error_code& ec) - { - BEAST_EXPECT(p.is_header_done()); - ec.assign(0, ec.category()); - }); - BEAST_EXPECTS(! ec, ec.message()); - } - { - multi_buffer b; - ostream(b) << - "POST / HTTP/1.1\r\n" - "Content-Length: 2\r\n" - "\r\n" - "**"; - error_code ec; - parser p; - p.eager(true); - p.put(b.data(), ec); - p.on_header( - [this](parser&, error_code& ec) - { - ec.assign(errc::bad_message, - generic_category()); - }); - BEAST_EXPECTS(! ec, ec.message()); - } - } - - void - run() override - { - testParse(); - testNeedMore(); - testNeedMore(); - testGotSome(); - testCallback(); - } -}; - -BEAST_DEFINE_TESTSUITE(parser,http,beast); - -} // http -} // beast - diff --git a/src/beast/test/http/read.cpp b/src/beast/test/http/read.cpp deleted file mode 100644 index 3e28ea50834..00000000000 --- a/src/beast/test/http/read.cpp +++ /dev/null @@ -1,464 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include "test_parser.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -class read_test - : public beast::unit_test::suite - , public test::enable_yield_to -{ -public: - template - void - failMatrix(char const* s, yield_context do_yield) - { - using boost::asio::buffer; - using boost::asio::buffer_copy; - static std::size_t constexpr limit = 100; - std::size_t n; - auto const len = strlen(s); - for(n = 0; n < limit; ++n) - { - multi_buffer b; - b.commit(buffer_copy( - b.prepare(len), buffer(s, len))); - test::fail_counter fc(n); - test::fail_stream< - test::string_istream> fs{fc, ios_, ""}; - test_parser p(fc); - error_code ec = test::error::fail_error; - read(fs, b, p, ec); - if(! ec) - break; - } - BEAST_EXPECT(n < limit); - for(n = 0; n < limit; ++n) - { - static std::size_t constexpr pre = 10; - multi_buffer b; - b.commit(buffer_copy( - b.prepare(pre), buffer(s, pre))); - test::fail_counter fc(n); - test::fail_stream fs{ - fc, ios_, std::string{s + pre, len - pre}}; - test_parser p(fc); - error_code ec = test::error::fail_error; - read(fs, b, p, ec); - if(! ec) - break; - } - BEAST_EXPECT(n < limit); - for(n = 0; n < limit; ++n) - { - multi_buffer b; - b.commit(buffer_copy( - b.prepare(len), buffer(s, len))); - test::fail_counter fc(n); - test::fail_stream< - test::string_istream> fs{fc, ios_, ""}; - test_parser p(fc); - error_code ec = test::error::fail_error; - async_read(fs, b, p, do_yield[ec]); - if(! ec) - break; - } - BEAST_EXPECT(n < limit); - for(n = 0; n < limit; ++n) - { - static std::size_t constexpr pre = 10; - multi_buffer b; - b.commit(buffer_copy( - b.prepare(pre), buffer(s, pre))); - test::fail_counter fc(n); - test::fail_stream fs{ - fc, ios_, std::string{s + pre, len - pre}}; - test_parser p(fc); - error_code ec = test::error::fail_error; - async_read(fs, b, p, do_yield[ec]); - if(! ec) - break; - } - BEAST_EXPECT(n < limit); - } - - void testThrow() - { - try - { - multi_buffer b; - test::string_istream ss(ios_, "GET / X"); - request_parser p; - read(ss, b, p); - fail(); - } - catch(std::exception const&) - { - pass(); - } - } - - void - testBufferOverflow() - { - { - test::pipe p{ios_}; - ostream(p.server.buffer) << - "GET / HTTP/1.1\r\n" - "Host: localhost\r\n" - "User-Agent: test\r\n" - "Transfer-Encoding: chunked\r\n" - "\r\n" - "10\r\n" - "****************\r\n" - "0\r\n\r\n"; - static_buffer_n<1024> b; - request req; - try - { - read(p.server, b, req); - pass(); - } - catch(std::exception const& e) - { - fail(e.what(), __FILE__, __LINE__); - } - } - { - test::pipe p{ios_}; - ostream(p.server.buffer) << - "GET / HTTP/1.1\r\n" - "Host: localhost\r\n" - "User-Agent: test\r\n" - "Transfer-Encoding: chunked\r\n" - "\r\n" - "10\r\n" - "****************\r\n" - "0\r\n\r\n"; - error_code ec = test::error::fail_error; - static_buffer_n<10> b; - request req; - read(p.server, b, req, ec); - BEAST_EXPECTS(ec == error::buffer_overflow, - ec.message()); - } - } - - void testFailures(yield_context do_yield) - { - char const* req[] = { - "GET / HTTP/1.0\r\n" - "Host: localhost\r\n" - "User-Agent: test\r\n" - "Empty:\r\n" - "\r\n" - , - "GET / HTTP/1.1\r\n" - "Host: localhost\r\n" - "User-Agent: test\r\n" - "Content-Length: 2\r\n" - "\r\n" - "**" - , - "GET / HTTP/1.1\r\n" - "Host: localhost\r\n" - "User-Agent: test\r\n" - "Transfer-Encoding: chunked\r\n" - "\r\n" - "10\r\n" - "****************\r\n" - "0\r\n\r\n" - , - nullptr - }; - - char const* res[] = { - "HTTP/1.0 200 OK\r\n" - "Server: test\r\n" - "\r\n" - , - "HTTP/1.0 200 OK\r\n" - "Server: test\r\n" - "\r\n" - "***" - , - "HTTP/1.1 200 OK\r\n" - "Server: test\r\n" - "Content-Length: 3\r\n" - "\r\n" - "***" - , - "HTTP/1.1 200 OK\r\n" - "Server: test\r\n" - "Transfer-Encoding: chunked\r\n" - "\r\n" - "10\r\n" - "****************\r\n" - "0\r\n\r\n" - , - nullptr - }; - - for(std::size_t i = 0; req[i]; ++i) - failMatrix(req[i], do_yield); - - for(std::size_t i = 0; res[i]; ++i) - failMatrix(res[i], do_yield); - } - - void testRead(yield_context do_yield) - { - static std::size_t constexpr limit = 100; - std::size_t n; - - for(n = 0; n < limit; ++n) - { - test::fail_stream fs(n, ios_, - "GET / HTTP/1.1\r\n" - "Host: localhost\r\n" - "User-Agent: test\r\n" - "Content-Length: 0\r\n" - "\r\n" - ); - request m; - try - { - multi_buffer b; - read(fs, b, m); - break; - } - catch(std::exception const&) - { - } - } - BEAST_EXPECT(n < limit); - - for(n = 0; n < limit; ++n) - { - test::fail_stream fs(n, ios_, - "GET / HTTP/1.1\r\n" - "Host: localhost\r\n" - "User-Agent: test\r\n" - "Content-Length: 0\r\n" - "\r\n" - ); - request m; - error_code ec = test::error::fail_error; - multi_buffer b; - read(fs, b, m, ec); - if(! ec) - break; - } - BEAST_EXPECT(n < limit); - - for(n = 0; n < limit; ++n) - { - test::fail_stream fs(n, ios_, - "GET / HTTP/1.1\r\n" - "Host: localhost\r\n" - "User-Agent: test\r\n" - "Content-Length: 0\r\n" - "\r\n" - ); - request m; - error_code ec = test::error::fail_error; - multi_buffer b; - async_read(fs, b, m, do_yield[ec]); - if(! ec) - break; - } - BEAST_EXPECT(n < limit); - } - - void - testEof(yield_context do_yield) - { - { - multi_buffer b; - test::string_istream ss(ios_, ""); - request_parser p; - error_code ec; - read(ss, b, p, ec); - BEAST_EXPECT(ec == http::error::end_of_stream); - } - { - multi_buffer b; - test::string_istream ss(ios_, ""); - request_parser p; - error_code ec; - async_read(ss, b, p, do_yield[ec]); - BEAST_EXPECT(ec == http::error::end_of_stream); - } - } - - // Ensure completion handlers are not leaked - struct handler - { - static std::atomic& - count() { static std::atomic n; return n; } - handler() { ++count(); } - ~handler() { --count(); } - handler(handler const&) { ++count(); } - void operator()(error_code const&) const {} - }; - - void - testIoService() - { - { - // Make sure handlers are not destroyed - // after calling io_service::stop - boost::asio::io_service ios; - test::string_istream is{ios, - "GET / HTTP/1.1\r\n\r\n"}; - BEAST_EXPECT(handler::count() == 0); - multi_buffer b; - request m; - async_read(is, b, m, handler{}); - BEAST_EXPECT(handler::count() > 0); - ios.stop(); - BEAST_EXPECT(handler::count() > 0); - ios.reset(); - BEAST_EXPECT(handler::count() > 0); - ios.run_one(); - BEAST_EXPECT(handler::count() == 0); - } - { - // Make sure uninvoked handlers are - // destroyed when calling ~io_service - { - boost::asio::io_service ios; - test::string_istream is{ios, - "GET / HTTP/1.1\r\n\r\n"}; - BEAST_EXPECT(handler::count() == 0); - multi_buffer b; - request m; - async_read(is, b, m, handler{}); - BEAST_EXPECT(handler::count() > 0); - } - BEAST_EXPECT(handler::count() == 0); - } - } - - // https://github.com/vinniefalco/Beast/issues/430 - void - testRegression430() - { - test::pipe c{ios_}; - c.server.read_size(1); - ostream(c.server.buffer) << - "HTTP/1.1 200 OK\r\n" - "Transfer-Encoding: chunked\r\n" - "Content-Type: application/octet-stream\r\n" - "\r\n" - "4\r\nabcd\r\n" - "0\r\n\r\n"; - error_code ec; - flat_buffer fb; - parser p; - read(c.server, fb, p, ec); - BEAST_EXPECTS(! ec, ec.message()); - } - - //-------------------------------------------------------------------------- - - template - void - readgrind(string_view s, Pred&& pred) - { - using boost::asio::buffer; - for(std::size_t n = 1; n < s.size() - 1; ++n) - { - Parser p; - error_code ec = test::error::fail_error; - flat_buffer b; - test::pipe c{ios_}; - ostream(c.server.buffer) << s; - c.server.read_size(n); - read(c.server, b, p, ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - continue; - pred(p); - } - } - - void - testReadGrind() - { - readgrind>( - "HTTP/1.1 200 OK\r\n" - "Transfer-Encoding: chunked\r\n" - "Content-Type: application/octet-stream\r\n" - "\r\n" - "4\r\nabcd\r\n" - "0\r\n\r\n" - ,[&](test_parser const& p) - { - BEAST_EXPECT(p.body == "abcd"); - }); - readgrind>( - "HTTP/1.1 200 OK\r\n" - "Server: test\r\n" - "Expect: Expires, MD5-Fingerprint\r\n" - "Transfer-Encoding: chunked\r\n" - "\r\n" - "5\r\n" - "*****\r\n" - "2;a;b=1;c=\"2\"\r\n" - "--\r\n" - "0;d;e=3;f=\"4\"\r\n" - "Expires: never\r\n" - "MD5-Fingerprint: -\r\n" - "\r\n" - ,[&](test_parser const& p) - { - BEAST_EXPECT(p.body == "*****--"); - }); - } - - void - run() override - { - testThrow(); - testBufferOverflow(); - - yield_to([&](yield_context yield){ - testFailures(yield); }); - yield_to([&](yield_context yield){ - testRead(yield); }); - yield_to([&](yield_context yield){ - testEof(yield); }); - - testIoService(); - testRegression430(); - testReadGrind(); - } -}; - -BEAST_DEFINE_TESTSUITE(read,http,beast); - -} // http -} // beast diff --git a/src/beast/test/http/rfc7230.cpp b/src/beast/test/http/rfc7230.cpp deleted file mode 100644 index dfa5b068f49..00000000000 --- a/src/beast/test/http/rfc7230.cpp +++ /dev/null @@ -1,357 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include -#include -#include -#include - -#include - -namespace beast { -namespace http { - -class rfc7230_test : public beast::unit_test::suite -{ -public: - static - std::string - fmt(std::string const& s) - { - return '\'' + s + '\''; - } - - static - std::string - str(string_view s) - { - return std::string(s.data(), s.size()); - } - - static - std::string - str(param_list const& c) - { - std::string s; - for(auto const& p : c) - { - s.push_back(';'); - s.append(str(p.first)); - if(! p.second.empty()) - { - s.push_back('='); - s.append(str(p.second)); - } - } - return s; - } - - void - testParamList() - { - auto const ce = - [&](std::string const& s) - { - auto const got = str(param_list{s}); - BEAST_EXPECTS(got == s, fmt(got)); - }; - auto const cs = - [&](std::string const& s, std::string const& answer) - { - ce(answer); - auto const got = str(param_list{s}); - ce(got); - BEAST_EXPECTS(got == answer, fmt(got)); - }; - auto const cq = - [&](std::string const& s, std::string const& answer) - { - auto const got = str(param_list{s}); - BEAST_EXPECTS(got == answer, fmt(got)); - }; - - ce(""); - ce(";x"); - ce(";xy"); - ce(";x;y"); - - ce(""); - cs(" ;\t i =\t 1 \t", ";i=1"); - cq("\t; \t xyz=1 ; ijk=\"q\\\"t\"", ";xyz=1;ijk=q\"t"); - ce(";x;y"); - - // invalid strings - cs(";", ""); - cs(";,", ""); - cq(";x=,", ""); - cq(";xy=\"", ""); - cq(";xy=\"\x7f", ""); - cq(";xy=\"\\", ""); - cq(";xy=\"\\\x01\"", ""); - } - - static - std::string - str(ext_list const& ex) - { - std::string s; - for(auto const& e : ex) - { - if(! s.empty()) - s += ','; - s.append(str(e.first)); - s += str(e.second); - } - return s; - } - - void - testExtList() - { - auto const ce = - [&](std::string const& s) - { - auto const got = str(ext_list{s}); - BEAST_EXPECTS(got == s, fmt(got)); - }; - auto const cs = - [&](std::string const& s, std::string const& good) - { - ce(good); - auto const got = str(ext_list{s}); - ce(got); - BEAST_EXPECTS(got == good, fmt(got)); - }; - auto const cq = - [&](std::string const& s, std::string const& good) - { - auto const got = str(ext_list{s}); - BEAST_EXPECTS(got == good, fmt(got)); - }; - /* - ext-basic_parsed_list = *( "," OWS ) ext *( OWS "," [ OWS ext ] ) - ext = token param-basic_parsed_list - param-basic_parsed_list = *( OWS ";" OWS param ) - param = token OWS "=" OWS ( token / quoted-string ) - */ - cs(",", ""); - cs(", ", ""); - cs(",\t", ""); - cs(", \t", ""); - cs(" ", ""); - cs(" ,", ""); - cs("\t,", ""); - cs("\t , \t", ""); - cs(",,", ""); - cs(" , \t,, \t,", ""); - cs( "permessage-deflate; client_no_context_takeover; client_max_window_bits", - "permessage-deflate;client_no_context_takeover;client_max_window_bits"); - - ce("a"); - ce("ab"); - ce("a,b"); - cs(" a ", "a"); - cs("\t a, b\t , c\t", "a,b,c"); - ce("a;b"); - ce("a;b;c"); - - cs("a; \t i\t=\t \t1\t ", "a;i=1"); - ce("a;i=1;j=2;k=3"); - ce("a;i=1;j=2;k=3,b;i=4;j=5;k=6"); - - cq("ab;x=\" \"", "ab;x= "); - cq("ab;x=\"\\\"\"", "ab;x=\""); - - BEAST_EXPECT(ext_list{"a,b;i=1,c;j=2;k=3"}.exists("A")); - BEAST_EXPECT(ext_list{"a,b;i=1,c;j=2;k=3"}.exists("b")); - BEAST_EXPECT(! ext_list{"a,b;i=1,c;j=2;k=3"}.exists("d")); - - // invalid strings - cs("i j", "i"); - cs(";", ""); - } - - static - std::string - str(token_list const& c) - { - bool first = true; - std::string s; - for(auto const& p : c) - { - if(! first) - s.push_back(','); - s.append(str(p)); - first = false; - } - return s; - } - - void - testTokenList() - { - auto const ce = - [&](std::string const& s) - { - auto const got = str(token_list{s}); - BEAST_EXPECTS(got == s, fmt(got)); - }; - auto const cs = - [&](std::string const& s, std::string const& good) - { - ce(good); - auto const got = str(token_list{s}); - ce(got); - BEAST_EXPECTS(got == good, fmt(got)); - }; - - cs("", ""); - cs(" ", ""); - cs(" ", ""); - cs("\t", ""); - cs(" \t ", ""); - cs(",", ""); - cs(",,", ""); - cs(" ,", ""); - cs(" , ,", ""); - cs(" x", "x"); - cs(" \t x", "x"); - cs("x ", "x"); - cs("x \t", "x"); - cs(" \t x \t ", "x"); - ce("x,y"); - cs("x ,\ty ", "x,y"); - cs("x, y, z", "x,y,z"); - - BEAST_EXPECT(token_list{"a,b,c"}.exists("A")); - BEAST_EXPECT(token_list{"a,b,c"}.exists("b")); - BEAST_EXPECT(! token_list{"a,b,c"}.exists("d")); - - // invalid - cs("x y", "x"); - } - - template - static - std::vector - to_vector(string_view in) - { - std::vector v; - detail::basic_parsed_list list{in}; - for(auto const& s : - detail::basic_parsed_list{in}) - v.emplace_back(s.data(), s.size()); - return v; - } - - template - void - validate(string_view in, - std::vector const& v) - { - BEAST_EXPECT(to_vector(in) == v); - } - - template - void - good(string_view in) - { - BEAST_EXPECT(validate_list( - detail::basic_parsed_list{in})); - } - - template - void - good(string_view in, - std::vector const& v) - { - BEAST_EXPECT(validate_list( - detail::basic_parsed_list{in})); - validate(in, v); - } - - template - void - bad(string_view in) - { - BEAST_EXPECT(! validate_list( - detail::basic_parsed_list{in})); - } - - void - testOptTokenList() - { - /* - #token = [ ( "," / token ) *( OWS "," [ OWS token ] ) ] - */ - using type = detail::opt_token_list_policy; - - good("", {}); - good(" ", {}); - good("\t", {}); - good(" \t", {}); - good(",", {}); - good(",,", {}); - good(", ,", {}); - good(",\t,", {}); - good(", \t,", {}); - good(", \t, ", {}); - good(", \t,\t", {}); - good(", \t, \t", {}); - - good("x", {"x"}); - good(" x", {"x"}); - good("x,,", {"x"}); - good("x, ,", {"x"}); - good("x,, ", {"x"}); - good("x,,,", {"x"}); - - good("x,y", {"x","y"}); - good("x ,y", {"x","y"}); - good("x\t,y", {"x","y"}); - good("x \t,y", {"x","y"}); - good(" x,y", {"x","y"}); - good(" x,y ", {"x","y"}); - good(",x,y", {"x","y"}); - good("x,y,", {"x","y"}); - good(",,x,y", {"x","y"}); - good(",x,,y", {"x","y"}); - good(",x,y,", {"x","y"}); - good("x ,, y", {"x","y"}); - good("x , ,y", {"x","y"}); - - good("x,y,z", {"x","y","z"}); - - bad("("); - bad("x("); - bad("(x"); - bad(",("); - bad("(,"); - bad("x,("); - bad("(,x"); - bad("x y"); - } - - void - run() - { - testOptTokenList(); -#if 0 - testParamList(); - testExtList(); - testTokenList(); -#endif - } -}; - -BEAST_DEFINE_TESTSUITE(rfc7230,http,beast); - -} // http -} // beast diff --git a/src/beast/test/http/serializer.cpp b/src/beast/test/http/serializer.cpp deleted file mode 100644 index d39dbcb50ec..00000000000 --- a/src/beast/test/http/serializer.cpp +++ /dev/null @@ -1,125 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include -#include - -namespace beast { -namespace http { - -class serializer_test : public beast::unit_test::suite -{ -public: - struct const_body - { - struct value_type{}; - - struct reader - { - using const_buffers_type = - boost::asio::const_buffers_1; - - template - reader(message const&); - - void - init(error_code& ec); - - boost::optional> - get(error_code&); - }; - }; - - struct mutable_body - { - struct value_type{}; - - struct reader - { - using const_buffers_type = - boost::asio::const_buffers_1; - - template - reader(message&); - - void - init(error_code& ec); - - boost::optional> - get(error_code&); - }; - }; - - BOOST_STATIC_ASSERT(std::is_const< serializer< - true, const_body>::value_type>::value); - - BOOST_STATIC_ASSERT(! std::is_const::value_type>::value); - - BOOST_STATIC_ASSERT(std::is_constructible< - serializer, - message &>::value); - - BOOST_STATIC_ASSERT(std::is_constructible< - serializer, - message const&>::value); - - BOOST_STATIC_ASSERT(std::is_constructible< - serializer, - message &>::value); - - BOOST_STATIC_ASSERT(! std::is_constructible< - serializer, - message const&>::value); - - struct lambda - { - std::size_t size; - - template - void - operator()(error_code&, - ConstBufferSequence const& buffers) - { - size = boost::asio::buffer_size(buffers); - } - }; - - void - testWriteLimit() - { - auto const limit = 30; - lambda visit; - error_code ec; - response res; - res.body.append(1000, '*'); - serializer sr{res}; - sr.limit(limit); - for(;;) - { - sr.next(ec, visit); - BEAST_EXPECT(visit.size <= limit); - sr.consume(visit.size); - if(sr.is_done()) - break; - } - } - - void - run() override - { - testWriteLimit(); - } -}; - -BEAST_DEFINE_TESTSUITE(serializer,http,beast); - -} // http -} // beast diff --git a/src/beast/test/http/span_body.cpp b/src/beast/test/http/span_body.cpp deleted file mode 100644 index 3e9e3b178f6..00000000000 --- a/src/beast/test/http/span_body.cpp +++ /dev/null @@ -1,76 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include -#include - -namespace beast { -namespace http { - -struct span_body_test - : public beast::unit_test::suite -{ - void - testSpanBody() - { - { - using B = span_body; - request req; - - BEAST_EXPECT(req.body.size() == 0); - BEAST_EXPECT(B::size(req.body) == 0); - - req.body = B::value_type("xyz", 3); - BEAST_EXPECT(req.body.size() == 3); - BEAST_EXPECT(B::size(req.body) == 3); - - B::reader r{req}; - error_code ec; - r.init(ec); - BEAST_EXPECTS(! ec, ec.message()); - auto const buf = r.get(ec); - BEAST_EXPECTS(! ec, ec.message()); - if(! BEAST_EXPECT(buf != boost::none)) - return; - BEAST_EXPECT(boost::asio::buffer_size(buf->first) == 3); - BEAST_EXPECT(! buf->second); - } - { - char buf[5]; - using B = span_body; - request req; - req.body = span{buf, sizeof(buf)}; - B::writer w{req}; - error_code ec; - w.init(boost::none, ec); - BEAST_EXPECTS(! ec, ec.message()); - w.put(boost::asio::const_buffers_1{ - "123", 3}, ec); - BEAST_EXPECTS(! ec, ec.message()); - BEAST_EXPECT(buf[0] == '1'); - BEAST_EXPECT(buf[1] == '2'); - BEAST_EXPECT(buf[2] == '3'); - w.put(boost::asio::const_buffers_1{ - "456", 3}, ec); - BEAST_EXPECTS(ec == error::buffer_overflow, ec.message()); - } - } - - void - run() override - { - testSpanBody(); - } -}; - -BEAST_DEFINE_TESTSUITE(span_body,http,beast); - -} // http -} // beast diff --git a/src/beast/test/http/status.cpp b/src/beast/test/http/status.cpp deleted file mode 100644 index 69cdcbffa68..00000000000 --- a/src/beast/test/http/status.cpp +++ /dev/null @@ -1,176 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include - -namespace beast { -namespace http { - -class status_test - : public beast::unit_test::suite -{ -public: - void - testStatus() - { - auto const check = [&](status s, int i, status_class sc) - { - BEAST_EXPECT(int_to_status(i) == s); - BEAST_EXPECT(to_status_class(i) == sc); - BEAST_EXPECT(to_status_class(int_to_status(i)) == sc); - }; - check(status::continue_ ,100, status_class::informational); - check(status::switching_protocols ,101, status_class::informational); - check(status::processing ,102, status_class::informational); - - check(status::ok ,200, status_class::successful); - check(status::created ,201, status_class::successful); - check(status::accepted ,202, status_class::successful); - check(status::non_authoritative_information ,203, status_class::successful); - check(status::no_content ,204, status_class::successful); - check(status::reset_content ,205, status_class::successful); - check(status::partial_content ,206, status_class::successful); - check(status::multi_status ,207, status_class::successful); - check(status::already_reported ,208, status_class::successful); - check(status::im_used ,226, status_class::successful); - - check(status::multiple_choices ,300, status_class::redirection); - check(status::moved_permanently ,301, status_class::redirection); - check(status::found ,302, status_class::redirection); - check(status::see_other ,303, status_class::redirection); - check(status::not_modified ,304, status_class::redirection); - check(status::use_proxy ,305, status_class::redirection); - check(status::temporary_redirect ,307, status_class::redirection); - check(status::permanent_redirect ,308, status_class::redirection); - - check(status::bad_request ,400, status_class::client_error); - check(status::unauthorized ,401, status_class::client_error); - check(status::payment_required ,402, status_class::client_error); - check(status::forbidden ,403, status_class::client_error); - check(status::not_found ,404, status_class::client_error); - check(status::method_not_allowed ,405, status_class::client_error); - check(status::not_acceptable ,406, status_class::client_error); - check(status::proxy_authentication_required ,407, status_class::client_error); - check(status::request_timeout ,408, status_class::client_error); - check(status::conflict ,409, status_class::client_error); - check(status::gone ,410, status_class::client_error); - check(status::length_required ,411, status_class::client_error); - check(status::precondition_failed ,412, status_class::client_error); - check(status::payload_too_large ,413, status_class::client_error); - check(status::uri_too_long ,414, status_class::client_error); - check(status::unsupported_media_type ,415, status_class::client_error); - check(status::range_not_satisfiable ,416, status_class::client_error); - check(status::expectation_failed ,417, status_class::client_error); - check(status::misdirected_request ,421, status_class::client_error); - check(status::unprocessable_entity ,422, status_class::client_error); - check(status::locked ,423, status_class::client_error); - check(status::failed_dependency ,424, status_class::client_error); - check(status::upgrade_required ,426, status_class::client_error); - check(status::precondition_required ,428, status_class::client_error); - check(status::too_many_requests ,429, status_class::client_error); - check(status::request_header_fields_too_large ,431, status_class::client_error); - check(status::connection_closed_without_response ,444, status_class::client_error); - check(status::unavailable_for_legal_reasons ,451, status_class::client_error); - check(status::client_closed_request ,499, status_class::client_error); - - check(status::internal_server_error ,500, status_class::server_error); - check(status::not_implemented ,501, status_class::server_error); - check(status::bad_gateway ,502, status_class::server_error); - check(status::service_unavailable ,503, status_class::server_error); - check(status::gateway_timeout ,504, status_class::server_error); - check(status::http_version_not_supported ,505, status_class::server_error); - check(status::variant_also_negotiates ,506, status_class::server_error); - check(status::insufficient_storage ,507, status_class::server_error); - check(status::loop_detected ,508, status_class::server_error); - check(status::not_extended ,510, status_class::server_error); - check(status::network_authentication_required ,511, status_class::server_error); - check(status::network_connect_timeout_error ,599, status_class::server_error); - - BEAST_EXPECT(to_status_class(1) == status_class::unknown); - BEAST_EXPECT(to_status_class(status::unknown) == status_class::unknown); - - auto const good = - [&](status v) - { - BEAST_EXPECT(obsolete_reason(v) != "Unknown Status"); - }; - good(status::continue_); - good(status::switching_protocols); - good(status::processing); - good(status::ok); - good(status::created); - good(status::accepted); - good(status::non_authoritative_information); - good(status::no_content); - good(status::reset_content); - good(status::partial_content); - good(status::multi_status); - good(status::already_reported); - good(status::im_used); - good(status::multiple_choices); - good(status::moved_permanently); - good(status::found); - good(status::see_other); - good(status::not_modified); - good(status::use_proxy); - good(status::temporary_redirect); - good(status::permanent_redirect); - good(status::bad_request); - good(status::unauthorized); - good(status::payment_required); - good(status::forbidden); - good(status::not_found); - good(status::method_not_allowed); - good(status::not_acceptable); - good(status::proxy_authentication_required); - good(status::request_timeout); - good(status::conflict); - good(status::gone); - good(status::length_required); - good(status::precondition_failed); - good(status::payload_too_large); - good(status::uri_too_long); - good(status::unsupported_media_type); - good(status::range_not_satisfiable); - good(status::expectation_failed); - good(status::misdirected_request); - good(status::unprocessable_entity); - good(status::locked); - good(status::failed_dependency); - good(status::upgrade_required); - good(status::precondition_required); - good(status::too_many_requests); - good(status::request_header_fields_too_large); - good(status::unavailable_for_legal_reasons); - good(status::internal_server_error); - good(status::not_implemented); - good(status::bad_gateway); - good(status::service_unavailable); - good(status::gateway_timeout); - good(status::http_version_not_supported); - good(status::variant_also_negotiates); - good(status::insufficient_storage); - good(status::loop_detected); - good(status::not_extended); - good(status::network_authentication_required); - } - - void - run() - { - testStatus(); - } -}; - -BEAST_DEFINE_TESTSUITE(status,http,beast); - -} // http -} // beast - diff --git a/src/beast/test/http/string_body.cpp b/src/beast/test/http/string_body.cpp deleted file mode 100644 index 71e9dea274f..00000000000 --- a/src/beast/test/http/string_body.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -namespace beast { -namespace http { - -BOOST_STATIC_ASSERT(is_body::value); -BOOST_STATIC_ASSERT(is_body_reader::value); -BOOST_STATIC_ASSERT(is_body_writer::value); - -} // http -} // beast diff --git a/src/beast/test/http/test_parser.hpp b/src/beast/test/http/test_parser.hpp deleted file mode 100644 index 7a17ee9f862..00000000000 --- a/src/beast/test/http/test_parser.hpp +++ /dev/null @@ -1,158 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_HTTP_TEST_PARSER_HPP -#define BEAST_HTTP_TEST_PARSER_HPP - -#include -#include -#include -#include - -namespace beast { -namespace http { - -template -class test_parser - : public basic_parser> -{ - test::fail_counter* fc_ = nullptr; - -public: - using mutable_buffers_type = - boost::asio::mutable_buffers_1; - - int status = 0; - int version = 0; - std::string method; - std::string path; - std::string reason; - std::string body; - int got_on_begin = 0; - int got_on_field = 0; - int got_on_header = 0; - int got_on_body = 0; - int got_content_length = 0; - int got_on_chunk = 0; - int got_on_complete = 0; - std::unordered_map< - std::string, std::string> fields; - - test_parser() = default; - - explicit - test_parser(test::fail_counter& fc) - : fc_(&fc) - { - } - - void - on_request(verb, string_view method_str_, - string_view path_, int version_, error_code& ec) - { - method = std::string( - method_str_.data(), method_str_.size()); - path = std::string( - path_.data(), path_.size()); - version = version_; - ++got_on_begin; - if(fc_) - fc_->fail(ec); - else - ec.assign(0, ec.category()); - } - - void - on_response(int code, - string_view reason_, - int version_, error_code& ec) - { - status = code; - reason = std::string( - reason_.data(), reason_.size()); - version = version_; - ++got_on_begin; - if(fc_) - fc_->fail(ec); - else - ec.assign(0, ec.category()); - } - - void - on_field(field, string_view name, - string_view value, error_code& ec) - { - ++got_on_field; - if(fc_) - fc_->fail(ec); - else - ec.assign(0, ec.category()); - fields[name.to_string()] = value.to_string(); - } - - void - on_header(error_code& ec) - { - ++got_on_header; - if(fc_) - fc_->fail(ec); - else - ec.assign(0, ec.category()); - } - - void - on_body(boost::optional< - std::uint64_t> const& content_length_, - error_code& ec) - { - ++got_on_body; - got_content_length = - static_cast(content_length_); - if(fc_) - fc_->fail(ec); - else - ec.assign(0, ec.category()); - } - - std::size_t - on_data(string_view s, - error_code& ec) - { - body.append(s.data(), s.size()); - if(fc_) - fc_->fail(ec); - else - ec.assign(0, ec.category()); - return s.size(); - } - - void - on_chunk(std::uint64_t, - string_view, error_code& ec) - { - ++got_on_chunk; - if(fc_) - fc_->fail(ec); - else - ec.assign(0, ec.category()); - } - - void - on_complete(error_code& ec) - { - ++got_on_complete; - if(fc_) - fc_->fail(ec); - else - ec.assign(0, ec.category()); - } -}; - -} // http -} // beast - -#endif diff --git a/src/beast/test/http/type_traits.cpp b/src/beast/test/http/type_traits.cpp deleted file mode 100644 index a461c5b0c22..00000000000 --- a/src/beast/test/http/type_traits.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include -#include - -namespace beast { -namespace http { - -BOOST_STATIC_ASSERT(! is_body_reader::value); - -BOOST_STATIC_ASSERT(is_body_reader::value); - -BOOST_STATIC_ASSERT(! is_body_writer::value); - -namespace { - -struct not_fields {}; - -} // (anonymous) - -BOOST_STATIC_ASSERT(! is_fields::value); - -} // http -} // beast diff --git a/src/beast/test/http/vector_body.cpp b/src/beast/test/http/vector_body.cpp deleted file mode 100644 index 91252137ece..00000000000 --- a/src/beast/test/http/vector_body.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -namespace beast { -namespace http { - -BOOST_STATIC_ASSERT(is_body>::value); -BOOST_STATIC_ASSERT(is_body_reader>::value); -BOOST_STATIC_ASSERT(is_body_writer>::value); - -} // http -} // beast diff --git a/src/beast/test/http/verb.cpp b/src/beast/test/http/verb.cpp deleted file mode 100644 index ec90033d98d..00000000000 --- a/src/beast/test/http/verb.cpp +++ /dev/null @@ -1,128 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include - -namespace beast { -namespace http { - -class verb_test - : public beast::unit_test::suite -{ -public: - void - testVerb() - { - auto const good = - [&](verb v) - { - BEAST_EXPECT(string_to_verb(to_string(v)) == v); - }; - - good(verb::unknown); - - good(verb::delete_); - good(verb::get); - good(verb::head); - good(verb::post); - good(verb::put); - good(verb::connect); - good(verb::options); - good(verb::trace); - good(verb::copy); - good(verb::lock); - good(verb::mkcol); - good(verb::move); - good(verb::propfind); - good(verb::proppatch); - good(verb::search); - good(verb::unlock); - good(verb::bind); - good(verb::rebind); - good(verb::unbind); - good(verb::acl); - good(verb::report); - good(verb::mkactivity); - good(verb::checkout); - good(verb::merge); - good(verb::msearch); - good(verb::notify); - good(verb::subscribe); - good(verb::unsubscribe); - good(verb::patch); - good(verb::purge); - good(verb::mkcalendar); - good(verb::link); - good(verb::unlink); - - auto const bad = - [&](string_view s) - { - auto const v = string_to_verb(s); - BEAST_EXPECTS(v == verb::unknown, to_string(v)); - }; - - bad("AC_"); - bad("BIN_"); - bad("CHECKOU_"); - bad("CONNEC_"); - bad("COP_"); - bad("DELET_"); - bad("GE_"); - bad("HEA_"); - bad("LIN_"); - bad("LOC_"); - bad("M-SEARC_"); - bad("MERG_"); - bad("MKACTIVIT_"); - bad("MKCALENDA_"); - bad("MKCO_"); - bad("MOV_"); - bad("NOTIF_"); - bad("OPTION_"); - bad("PATC_"); - bad("POS_"); - bad("PROPFIN_"); - bad("PROPPATC_"); - bad("PURG_"); - bad("PU_"); - bad("REBIN_"); - bad("REPOR_"); - bad("SEARC_"); - bad("SUBSCRIB_"); - bad("TRAC_"); - bad("UNBIN_"); - bad("UNLIN_"); - bad("UNLOC_"); - bad("UNSUBSCRIB_"); - - try - { - to_string(static_cast(-1)); - fail("", __FILE__, __LINE__); - } - catch(std::exception const&) - { - pass(); - } - } - - void - run() - { - testVerb(); - } -}; - -BEAST_DEFINE_TESTSUITE(verb,http,beast); - -} // http -} // beast - diff --git a/src/beast/test/http/write.cpp b/src/beast/test/http/write.cpp deleted file mode 100644 index bb0a7f638fc..00000000000 --- a/src/beast/test/http/write.cpp +++ /dev/null @@ -1,856 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -class write_test - : public beast::unit_test::suite - , public test::enable_yield_to -{ -public: - struct unsized_body - { - using value_type = std::string; - - class reader - { - value_type const& body_; - - public: - using const_buffers_type = - boost::asio::const_buffers_1; - - template - explicit - reader(message const& msg) - : body_(msg.body) - { - } - - void - init(error_code& ec) - { - ec.assign(0, ec.category()); - } - - boost::optional> - get(error_code& ec) - { - ec.assign(0, ec.category()); - return {{const_buffers_type{ - body_.data(), body_.size()}, false}}; - } - }; - }; - - template< - bool isSplit, - bool isFinalEmpty - > - struct test_body - { - struct value_type - { - std::string s; - bool mutable read = false; - }; - - class reader - { - int step_ = 0; - value_type const& body_; - - public: - using const_buffers_type = - boost::asio::const_buffers_1; - - template - explicit - reader(message const& msg) - : body_(msg.body) - { - } - - void - init(error_code& ec) - { - ec.assign(0, ec.category()); - } - - boost::optional> - get(error_code& ec) - { - ec.assign(0, ec.category()); - body_.read = true; - return get( - std::integral_constant{}, - std::integral_constant{}); - } - - private: - boost::optional> - get( - std::false_type, // isSplit - std::false_type) // isFinalEmpty - { - using boost::asio::buffer; - if(body_.s.empty()) - return boost::none; - return {{buffer(body_.s.data(), body_.s.size()), false}}; - } - - boost::optional> - get( - std::false_type, // isSplit - std::true_type) // isFinalEmpty - { - using boost::asio::buffer; - if(body_.s.empty()) - return boost::none; - switch(step_) - { - case 0: - step_ = 1; - return {{buffer( - body_.s.data(), body_.s.size()), true}}; - default: - return boost::none; - } - } - - boost::optional> - get( - std::true_type, // isSplit - std::false_type) // isFinalEmpty - { - using boost::asio::buffer; - auto const n = (body_.s.size() + 1) / 2; - switch(step_) - { - case 0: - if(n == 0) - return boost::none; - step_ = 1; - return {{buffer(body_.s.data(), n), - body_.s.size() > 1}}; - default: - return {{buffer(body_.s.data() + n, - body_.s.size() - n), false}}; - } - } - - boost::optional> - get( - std::true_type, // isSplit - std::true_type) // isFinalEmpty - { - using boost::asio::buffer; - auto const n = (body_.s.size() + 1) / 2; - switch(step_) - { - case 0: - if(n == 0) - return boost::none; - step_ = body_.s.size() > 1 ? 1 : 2; - return {{buffer(body_.s.data(), n), true}}; - case 1: - BOOST_ASSERT(body_.s.size() > 1); - step_ = 2; - return {{buffer(body_.s.data() + n, - body_.s.size() - n), true}}; - default: - return boost::none; - } - } - }; - }; - - struct fail_body - { - class reader; - - class value_type - { - friend class reader; - - std::string s_; - test::fail_counter& fc_; - - public: - explicit - value_type(test::fail_counter& fc) - : fc_(fc) - { - } - - value_type& - operator=(std::string s) - { - s_ = std::move(s); - return *this; - } - }; - - class reader - { - std::size_t n_ = 0; - value_type const& body_; - - public: - using const_buffers_type = - boost::asio::const_buffers_1; - - template - explicit - reader(message const& msg) - : body_(msg.body) - { - } - - void - init(error_code& ec) - { - body_.fc_.fail(ec); - } - - boost::optional> - get(error_code& ec) - { - if(body_.fc_.fail(ec)) - return boost::none; - if(n_ >= body_.s_.size()) - return boost::none; - return {{const_buffers_type{ - body_.s_.data() + n_++, 1}, true}}; - } - }; - }; - - template - bool - equal_body(string_view sv, string_view body) - { - test::string_istream si{ - get_io_service(), sv.to_string()}; - message m; - multi_buffer b; - try - { - read(si, b, m); - return m.body == body; - } - catch(std::exception const& e) - { - log << "equal_body: " << e.what() << std::endl; - return false; - } - } - - template - std::string - str(message const& m) - { - test::string_ostream ss(ios_); - error_code ec; - write(ss, m, ec); - if(ec && ec != error::end_of_stream) - BOOST_THROW_EXCEPTION(system_error{ec}); - return ss.str; - } - - void - testAsyncWrite(yield_context do_yield) - { - { - response m; - m.version = 10; - m.result(status::ok); - m.set(field::server, "test"); - m.set(field::content_length, "5"); - m.body = "*****"; - error_code ec; - test::string_ostream ss{ios_}; - async_write(ss, m, do_yield[ec]); - if(BEAST_EXPECTS(ec == error::end_of_stream, ec.message())) - BEAST_EXPECT(ss.str == - "HTTP/1.0 200 OK\r\n" - "Server: test\r\n" - "Content-Length: 5\r\n" - "\r\n" - "*****"); - } - { - response m; - m.version = 11; - m.result(status::ok); - m.set(field::server, "test"); - m.set(field::transfer_encoding, "chunked"); - m.body = "*****"; - error_code ec; - test::string_ostream ss(ios_); - async_write(ss, m, do_yield[ec]); - if(BEAST_EXPECTS(! ec, ec.message())) - BEAST_EXPECT(ss.str == - "HTTP/1.1 200 OK\r\n" - "Server: test\r\n" - "Transfer-Encoding: chunked\r\n" - "\r\n" - "5\r\n" - "*****\r\n" - "0\r\n\r\n"); - } - } - - void - testFailures(yield_context do_yield) - { - static std::size_t constexpr limit = 100; - std::size_t n; - - for(n = 0; n < limit; ++n) - { - test::fail_counter fc(n); - test::fail_stream< - test::string_ostream> fs(fc, ios_); - request m(verb::get, "/", 10, fc); - m.set(field::user_agent, "test"); - m.set(field::connection, "keep-alive"); - m.set(field::content_length, "5"); - m.body = "*****"; - try - { - write(fs, m); - BEAST_EXPECT(fs.next_layer().str == - "GET / HTTP/1.0\r\n" - "User-Agent: test\r\n" - "Connection: keep-alive\r\n" - "Content-Length: 5\r\n" - "\r\n" - "*****" - ); - pass(); - break; - } - catch(std::exception const&) - { - } - } - BEAST_EXPECT(n < limit); - - for(n = 0; n < limit; ++n) - { - test::fail_counter fc(n); - test::fail_stream< - test::string_ostream> fs(fc, ios_); - request m{verb::get, "/", 10, fc}; - m.set(field::user_agent, "test"); - m.set(field::transfer_encoding, "chunked"); - m.body = "*****"; - error_code ec = test::error::fail_error; - write(fs, m, ec); - if(ec == error::end_of_stream) - { - BEAST_EXPECT(fs.next_layer().str == - "GET / HTTP/1.0\r\n" - "User-Agent: test\r\n" - "Transfer-Encoding: chunked\r\n" - "\r\n" - "1\r\n*\r\n" - "1\r\n*\r\n" - "1\r\n*\r\n" - "1\r\n*\r\n" - "1\r\n*\r\n" - "0\r\n\r\n" - ); - break; - } - } - BEAST_EXPECT(n < limit); - - for(n = 0; n < limit; ++n) - { - test::fail_counter fc(n); - test::fail_stream< - test::string_ostream> fs(fc, ios_); - request m{verb::get, "/", 10, fc}; - m.set(field::user_agent, "test"); - m.set(field::transfer_encoding, "chunked"); - m.body = "*****"; - error_code ec = test::error::fail_error; - async_write(fs, m, do_yield[ec]); - if(ec == error::end_of_stream) - { - BEAST_EXPECT(fs.next_layer().str == - "GET / HTTP/1.0\r\n" - "User-Agent: test\r\n" - "Transfer-Encoding: chunked\r\n" - "\r\n" - "1\r\n*\r\n" - "1\r\n*\r\n" - "1\r\n*\r\n" - "1\r\n*\r\n" - "1\r\n*\r\n" - "0\r\n\r\n" - ); - break; - } - } - BEAST_EXPECT(n < limit); - - for(n = 0; n < limit; ++n) - { - test::fail_counter fc(n); - test::fail_stream< - test::string_ostream> fs(fc, ios_); - request m{verb::get, "/", 10, fc}; - m.set(field::user_agent, "test"); - m.set(field::connection, "keep-alive"); - m.set(field::content_length, "5"); - m.body = "*****"; - error_code ec = test::error::fail_error; - write(fs, m, ec); - if(! ec) - { - BEAST_EXPECT(fs.next_layer().str == - "GET / HTTP/1.0\r\n" - "User-Agent: test\r\n" - "Connection: keep-alive\r\n" - "Content-Length: 5\r\n" - "\r\n" - "*****" - ); - break; - } - } - BEAST_EXPECT(n < limit); - - for(n = 0; n < limit; ++n) - { - test::fail_counter fc(n); - test::fail_stream< - test::string_ostream> fs(fc, ios_); - request m{verb::get, "/", 10, fc}; - m.set(field::user_agent, "test"); - m.set(field::connection, "keep-alive"); - m.set(field::content_length, "5"); - m.body = "*****"; - error_code ec = test::error::fail_error; - async_write(fs, m, do_yield[ec]); - if(! ec) - { - BEAST_EXPECT(fs.next_layer().str == - "GET / HTTP/1.0\r\n" - "User-Agent: test\r\n" - "Connection: keep-alive\r\n" - "Content-Length: 5\r\n" - "\r\n" - "*****" - ); - break; - } - } - BEAST_EXPECT(n < limit); - } - - void - testOutput() - { - // auto content-length HTTP/1.0 - { - request m; - m.method(verb::get); - m.target("/"); - m.version = 10; - m.set(field::user_agent, "test"); - m.body = "*"; - m.prepare_payload(); - BEAST_EXPECT(str(m) == - "GET / HTTP/1.0\r\n" - "User-Agent: test\r\n" - "Content-Length: 1\r\n" - "\r\n" - "*" - ); - } - // no content-length HTTP/1.0 - { - request m; - m.method(verb::get); - m.target("/"); - m.version = 10; - m.set(field::user_agent, "test"); - m.body = "*"; - m.prepare_payload(); - test::string_ostream ss(ios_); - error_code ec; - write(ss, m, ec); - BEAST_EXPECT(ec == error::end_of_stream); - BEAST_EXPECT(ss.str == - "GET / HTTP/1.0\r\n" - "User-Agent: test\r\n" - "\r\n" - "*" - ); - } - // auto content-length HTTP/1.1 - { - request m; - m.method(verb::get); - m.target("/"); - m.version = 11; - m.set(field::user_agent, "test"); - m.body = "*"; - m.prepare_payload(); - BEAST_EXPECT(str(m) == - "GET / HTTP/1.1\r\n" - "User-Agent: test\r\n" - "Content-Length: 1\r\n" - "\r\n" - "*" - ); - } - // no content-length HTTP/1.1 - { - request m; - m.method(verb::get); - m.target("/"); - m.version = 11; - m.set(field::user_agent, "test"); - m.body = "*"; - m.prepare_payload(); - test::string_ostream ss(ios_); - error_code ec; - write(ss, m, ec); - BEAST_EXPECT(ss.str == - "GET / HTTP/1.1\r\n" - "User-Agent: test\r\n" - "Transfer-Encoding: chunked\r\n" - "\r\n" - "1\r\n" - "*\r\n" - "0\r\n\r\n" - ); - } - } - - void test_std_ostream() - { - // Conversion to std::string via operator<< - request m; - m.method(verb::get); - m.target("/"); - m.version = 11; - m.set(field::user_agent, "test"); - m.body = "*"; - BEAST_EXPECT(boost::lexical_cast(m) == - "GET / HTTP/1.1\r\nUser-Agent: test\r\n\r\n*"); - } - - // Ensure completion handlers are not leaked - struct handler - { - static std::atomic& - count() { static std::atomic n; return n; } - handler() { ++count(); } - ~handler() { --count(); } - handler(handler const&) { ++count(); } - void operator()(error_code const&) const {} - }; - - void - testIoService() - { - { - // Make sure handlers are not destroyed - // after calling io_service::stop - boost::asio::io_service ios; - test::string_ostream os{ios}; - BEAST_EXPECT(handler::count() == 0); - request m; - m.method(verb::get); - m.version = 11; - m.target("/"); - m.set("Content-Length", 5); - m.body = "*****"; - async_write(os, m, handler{}); - BEAST_EXPECT(handler::count() > 0); - ios.stop(); - BEAST_EXPECT(handler::count() > 0); - ios.reset(); - BEAST_EXPECT(handler::count() > 0); - ios.run_one(); - BEAST_EXPECT(handler::count() == 0); - } - { - // Make sure uninvoked handlers are - // destroyed when calling ~io_service - { - boost::asio::io_service ios; - test::string_ostream is{ios}; - BEAST_EXPECT(handler::count() == 0); - request m; - m.method(verb::get); - m.version = 11; - m.target("/"); - m.set("Content-Length", 5); - m.body = "*****"; - async_write(is, m, handler{}); - BEAST_EXPECT(handler::count() > 0); - } - BEAST_EXPECT(handler::count() == 0); - } - } - - template - void - do_write(Stream& stream, message< - isRequest, Body, Fields> const& m, error_code& ec, - Decorator const& decorator = Decorator{}) - { - serializer sr{m, decorator}; - for(;;) - { - stream.nwrite = 0; - write_some(stream, sr, ec); - if(ec) - return; - BEAST_EXPECT(stream.nwrite <= 1); - if(sr.is_done()) - break; - } - } - - template - void - do_async_write(Stream& stream, - message const& m, - error_code& ec, yield_context yield, - Decorator const& decorator = Decorator{}) - { - serializer sr{m, decorator}; - for(;;) - { - stream.nwrite = 0; - async_write_some(stream, sr, yield[ec]); - if(ec) - return; - BEAST_EXPECT(stream.nwrite <= 1); - if(sr.is_done()) - break; - } - } - - struct test_decorator - { - std::string s; - - template - string_view - operator()(ConstBufferSequence const& buffers) - { - s = ";x=" + std::to_string(boost::asio::buffer_size(buffers)); - return s; - } - - string_view - operator()(boost::asio::null_buffers) - { - return "Result: OK\r\n"; - } - }; - - template - void - testWriteStream(boost::asio::yield_context yield) - { - test::pipe p{ios_}; - p.client.write_size(3); - - response m0; - m0.version = 11; - m0.result(status::ok); - m0.reason("OK"); - m0.set(field::server, "test"); - m0.body.s = "Hello, world!\n"; - - { - std::string const result = - "HTTP/1.1 200 OK\r\n" - "Server: test\r\n" - "\r\n" - "Hello, world!\n"; - { - auto m = m0; - error_code ec; - do_write(p.client, m, ec); - BEAST_EXPECT(p.server.str() == result); - BEAST_EXPECT(equal_body( - p.server.str(), m.body.s)); - p.server.clear(); - } - { - auto m = m0; - error_code ec; - do_async_write(p.client, m, ec, yield); - BEAST_EXPECT(p.server.str() == result); - BEAST_EXPECT(equal_body( - p.server.str(), m.body.s)); - p.server.clear(); - } - { - auto m = m0; - error_code ec; - response_serializer sr{m}; - sr.split(true); - for(;;) - { - write_some(p.client, sr); - if(sr.is_header_done()) - break; - } - BEAST_EXPECT(! m.body.read); - p.server.clear(); - } - { - auto m = m0; - error_code ec; - response_serializer sr{m}; - sr.split(true); - for(;;) - { - async_write_some(p.client, sr, yield); - if(sr.is_header_done()) - break; - } - BEAST_EXPECT(! m.body.read); - p.server.clear(); - } - } - { - m0.set("Transfer-Encoding", "chunked"); - { - auto m = m0; - error_code ec; - do_write(p.client, m, ec); - BEAST_EXPECT(equal_body( - p.server.str(), m.body.s)); - p.server.clear(); - } - { - auto m = m0; - error_code ec; - do_write(p.client, m, ec, test_decorator{}); - BEAST_EXPECT(equal_body( - p.server.str(), m.body.s)); - p.server.clear(); - } - { - auto m = m0; - error_code ec; - do_async_write(p.client, m, ec, yield); - BEAST_EXPECT(equal_body( - p.server.str(), m.body.s)); - p.server.clear(); - } - { - auto m = m0; - error_code ec; - do_async_write(p.client, m, ec, yield, test_decorator{}); - BEAST_EXPECT(equal_body( - p.server.str(), m.body.s)); - p.server.clear(); - } - { - auto m = m0; - error_code ec; - test::string_ostream so{get_io_service(), 3}; - response_serializer sr{m}; - sr.split(true); - for(;;) - { - write_some(p.client, sr); - if(sr.is_header_done()) - break; - } - BEAST_EXPECT(! m.body.read); - p.server.clear(); - } - { - auto m = m0; - error_code ec; - response_serializer sr{m}; - sr.split(true); - for(;;) - { - async_write_some(p.client, sr, yield); - if(sr.is_header_done()) - break; - } - BEAST_EXPECT(! m.body.read); - p.server.clear(); - } - } - } - - void run() override - { - yield_to( - [&](yield_context yield) - { - testAsyncWrite(yield); - }); - yield_to( - [&](yield_context yield) - { - testFailures(yield); - }); - testOutput(); - test_std_ostream(); - testIoService(); - yield_to( - [&](yield_context yield) - { - testWriteStream>(yield); - testWriteStream>(yield); - testWriteStream>(yield); - testWriteStream>(yield); - }); - } -}; - -BEAST_DEFINE_TESTSUITE(write,http,beast); - -} // http -} // beast diff --git a/src/beast/test/server/CMakeLists.txt b/src/beast/test/server/CMakeLists.txt deleted file mode 100644 index fe7cbbdeabf..00000000000 --- a/src/beast/test/server/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ -# Part of Beast - -GroupSources(example/server-framework framework) -GroupSources(example/common common) -GroupSources(extras/beast extras) -GroupSources(include/beast beast) - -GroupSources(test/server "/") - -add_executable (server-test - ${BEAST_INCLUDES} - ${COMMON_INCLUDES} - ${SERVER_INCLUDES} - ../../extras/beast/unit_test/main.cpp - file_service.cpp - framework.cpp - http_async_port.cpp - http_base.cpp - http_sync_port.cpp - https_ports.cpp - multi_port.cpp - server.cpp - service_list.cpp - ssl_certificate - tests.cpp - ws_async_port.cpp - ws_sync_port.cpp - ws_upgrade_service.cpp - wss_ports.cpp -) - -target_link_libraries(server-test - Beast - ${Boost_PROGRAM_OPTIONS_LIBRARY} - ${Boost_FILESYSTEM_LIBRARY} - ) - -if (OPENSSL_FOUND) - target_link_libraries (server-test ${OPENSSL_LIBRARIES}) -endif() diff --git a/src/beast/test/server/Jamfile b/src/beast/test/server/Jamfile deleted file mode 100644 index 2011716038c..00000000000 --- a/src/beast/test/server/Jamfile +++ /dev/null @@ -1,28 +0,0 @@ -# -# Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -# -# 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) -# - -unit-test server-test : - ../../extras/beast/unit_test/main.cpp - file_service.cpp - framework.cpp - http_async_port.cpp - http_base.cpp - http_sync_port.cpp - https_ports.cpp - multi_port.cpp - server.cpp - service_list.cpp - ssl_certificate.cpp - tests.cpp - ws_async_port.cpp - ws_sync_port.cpp - ws_upgrade_service.cpp - wss_ports.cpp - : - coverage:no - ubasan:no - ; diff --git a/src/beast/test/server/file_service.cpp b/src/beast/test/server/file_service.cpp deleted file mode 100644 index 334c60b23e2..00000000000 --- a/src/beast/test/server/file_service.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include "../../example/server-framework/file_service.hpp" - diff --git a/src/beast/test/server/framework.cpp b/src/beast/test/server/framework.cpp deleted file mode 100644 index ac995427066..00000000000 --- a/src/beast/test/server/framework.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include "../../example/server-framework/framework.hpp" - diff --git a/src/beast/test/server/http_async_port.cpp b/src/beast/test/server/http_async_port.cpp deleted file mode 100644 index dfed5a0a754..00000000000 --- a/src/beast/test/server/http_async_port.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include "../../example/server-framework/http_async_port.hpp" - diff --git a/src/beast/test/server/http_base.cpp b/src/beast/test/server/http_base.cpp deleted file mode 100644 index b27661d1790..00000000000 --- a/src/beast/test/server/http_base.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include "../../example/server-framework/http_base.hpp" - diff --git a/src/beast/test/server/http_sync_port.cpp b/src/beast/test/server/http_sync_port.cpp deleted file mode 100644 index 4625ad94ede..00000000000 --- a/src/beast/test/server/http_sync_port.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include "../../example/server-framework/http_sync_port.hpp" - diff --git a/src/beast/test/server/https_ports.cpp b/src/beast/test/server/https_ports.cpp deleted file mode 100644 index f8414cfca1a..00000000000 --- a/src/beast/test/server/https_ports.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#if BEAST_USE_OPENSSL - -// Test that header file is self-contained. -#include "../../example/server-framework/https_ports.hpp" - -#endif diff --git a/src/beast/test/server/multi_port.cpp b/src/beast/test/server/multi_port.cpp deleted file mode 100644 index a86ee0f3c36..00000000000 --- a/src/beast/test/server/multi_port.cpp +++ /dev/null @@ -1,14 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#if BEAST_USE_OPENSSL - -// Test that header file is self-contained. -#include "../../example/server-framework/multi_port.hpp" - -#endif - diff --git a/src/beast/test/server/server.cpp b/src/beast/test/server/server.cpp deleted file mode 100644 index 0920a344821..00000000000 --- a/src/beast/test/server/server.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include "../../example/server-framework/server.hpp" - diff --git a/src/beast/test/server/service_list.cpp b/src/beast/test/server/service_list.cpp deleted file mode 100644 index dd1569f8ade..00000000000 --- a/src/beast/test/server/service_list.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include "../../example/server-framework/service_list.hpp" - diff --git a/src/beast/test/server/ssl_certificate.cpp b/src/beast/test/server/ssl_certificate.cpp deleted file mode 100644 index 19b0baeee19..00000000000 --- a/src/beast/test/server/ssl_certificate.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#if BEAST_USE_OPENSSL - -// Test that header file is self-contained. -#include "../../example/server-framework/ssl_certificate.hpp" - -#endif diff --git a/src/beast/test/server/tests.cpp b/src/beast/test/server/tests.cpp deleted file mode 100644 index efd4b456e4f..00000000000 --- a/src/beast/test/server/tests.cpp +++ /dev/null @@ -1,328 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#include "example/server-framework/http_sync_port.hpp" -#include "example/server-framework/http_async_port.hpp" -#include "example/server-framework/ws_sync_port.hpp" -#include "example/server-framework/ws_async_port.hpp" -#include "example/server-framework/ws_upgrade_service.hpp" - -#if BEAST_USE_OPENSSL -# include "example/server-framework/https_ports.hpp" -# include "example/server-framework/multi_port.hpp" -# include "example/server-framework/ssl_certificate.hpp" -# include "example/server-framework/wss_ports.hpp" -#endif - -#include -#include -#include -#include - -namespace beast { -namespace websocket { - -class server_test - : public beast::unit_test::suite - , public test::enable_yield_to -{ -public: - static unsigned short constexpr port_num = 6000; - - class set_ws_options - { - beast::websocket::permessage_deflate pmd_; - - public: - set_ws_options(beast::websocket::permessage_deflate const& pmd) - : pmd_(pmd) - { - } - - template - void - operator()(beast::websocket::stream& ws) const - { - ws.auto_fragment(false); - ws.set_option(pmd_); - ws.read_message_max(64 * 1024 * 1024); - } - }; - - set_ws_options - get_ws_options() - { - beast::websocket::permessage_deflate pmd; - pmd.client_enable = true; - pmd.server_enable = true; - pmd.compLevel = 3; - return set_ws_options{pmd}; - } - - template - void - doOptions(Stream& stream, error_code& ec) - { - beast::http::request req; - req.version = 11; - req.method(beast::http::verb::options); - req.target("*"); - req.set(beast::http::field::user_agent, "test"); - req.set(beast::http::field::connection, "close"); - - beast::http::write(stream, req, ec); - if(! BEAST_EXPECTS( - ec == beast::http::error::end_of_stream, - ec.message())) - return; - - beast::flat_buffer b; - beast::http::response res; - beast::http::read(stream, b, res, ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - } - - template - void - doHello(stream& ws, error_code& ec) - { - ws.handshake("localhost", "/", ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - ws.write(boost::asio::buffer(std::string("Hello, world!")), ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - beast::multi_buffer b; - ws.read(b, ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - ws.close(beast::websocket::close_code::normal, ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - // VFALCO Verify the buffer's contents - drain_buffer drain; - for(;;) - { - ws.read(drain, ec); - if(ec == beast::websocket::error::closed) - break; - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - } - } - - void - httpClient(framework::endpoint_type const& ep) - { - error_code ec; - boost::asio::ip::tcp::socket con{ios_}; - con.connect(ep, ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - doOptions(con, ec); - } - - void - wsClient(framework::endpoint_type const& ep) - { - error_code ec; - stream ws{ios_}; - ws.next_layer().connect(ep, ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - doHello(ws, ec); - } - - void - testPlain() - { - using namespace framework; - - // ws sync - { - error_code ec; - server instance; - auto const ep1 = endpoint_type{ - address_type::from_string("127.0.0.1"), port_num}; - auto const wsp = instance.make_port( - ec, ep1, instance, log, get_ws_options()); - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - auto const ep2 = endpoint_type{ - address_type::from_string("127.0.0.1"), - static_cast(port_num + 1)}; - auto const sp = instance.make_port< - http_sync_port>>( - ec, ep2, instance, log); - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - sp->template init<0>(ec, *wsp); - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - - wsClient(ep1); - wsClient(ep2); - - httpClient(ep2); - } - - // ws async - { - error_code ec; - server instance; - auto const ep1 = endpoint_type{ - address_type::from_string("127.0.0.1"), port_num}; - auto const wsp = instance.make_port( - ec, ep1, instance, log, get_ws_options()); - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - auto const ep2 = endpoint_type{ - address_type::from_string("127.0.0.1"), - static_cast(port_num + 1)}; - auto const sp = instance.make_port< - http_async_port>>( - ec, ep2, instance, log); - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - sp->template init<0>(ec, *wsp); - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - - wsClient(ep1); - wsClient(ep2); - - httpClient(ep2); - } - } - -#if BEAST_USE_OPENSSL - // - // OpenSSL enabled ports - // - - void - httpsClient(framework::endpoint_type const& ep, - boost::asio::ssl::context& ctx) - { - error_code ec; - boost::asio::ssl::stream con{ios_, ctx}; - con.next_layer().connect(ep, ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - con.handshake( - boost::asio::ssl::stream_base::client, ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - doOptions(con, ec); - if(ec) - return; - con.shutdown(ec); - // VFALCO No idea why we get eof in the normal case - if(ec == boost::asio::error::eof) - ec.assign(0, ec.category()); - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - } - - void - wssClient(framework::endpoint_type const& ep, - boost::asio::ssl::context& ctx) - { - error_code ec; - stream> wss{ios_, ctx}; - wss.next_layer().next_layer().connect(ep, ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - wss.next_layer().handshake( - boost::asio::ssl::stream_base::client, ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - doHello(wss, ec); - } - - void - testSSL() - { - using namespace framework; - - ssl_certificate cert; - - // wss sync - { - error_code ec; - server instance; - auto const ep1 = endpoint_type{ - address_type::from_string("127.0.0.1"), port_num}; - auto const wsp = instance.make_port( - ec, ep1, instance, log, cert.get(), get_ws_options()); - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - auto const ep2 = endpoint_type{ - address_type::from_string("127.0.0.1"), - static_cast(port_num + 1)}; - auto const sp = instance.make_port< - https_sync_port>>( - ec, ep2, instance, log, cert.get()); - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - sp->template init<0>(ec, *wsp); - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - - wssClient(ep1, cert.get()); - wssClient(ep2, cert.get()); - - httpsClient(ep2, cert.get()); - } - - // wss async - { - error_code ec; - server instance; - auto const ep1 = endpoint_type{ - address_type::from_string("127.0.0.1"), port_num}; - auto const wsp = instance.make_port( - ec, ep1, instance, log, cert.get(), get_ws_options()); - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - auto const ep2 = endpoint_type{ - address_type::from_string("127.0.0.1"), - static_cast(port_num + 1)}; - auto const sp = instance.make_port< - https_async_port>>( - ec, ep2, instance, log, cert.get()); - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - sp->template init<0>(ec, *wsp); - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - - wssClient(ep1, cert.get()); - wssClient(ep2, cert.get()); - - httpsClient(ep2, cert.get()); - } - } -#endif - - void - run() override - { - testPlain(); - - #if BEAST_USE_OPENSSL - testSSL(); - #endif - } -}; - -BEAST_DEFINE_TESTSUITE(server,websocket,beast); - -} // websocket -} // beast - diff --git a/src/beast/test/server/ws_async_port.cpp b/src/beast/test/server/ws_async_port.cpp deleted file mode 100644 index e826d97c1de..00000000000 --- a/src/beast/test/server/ws_async_port.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include "../../example/server-framework/ws_async_port.hpp" - diff --git a/src/beast/test/server/ws_sync_port.cpp b/src/beast/test/server/ws_sync_port.cpp deleted file mode 100644 index 8bba84d8a31..00000000000 --- a/src/beast/test/server/ws_sync_port.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include "../../example/server-framework/ws_sync_port.hpp" - diff --git a/src/beast/test/server/ws_upgrade_service.cpp b/src/beast/test/server/ws_upgrade_service.cpp deleted file mode 100644 index dcabff756aa..00000000000 --- a/src/beast/test/server/ws_upgrade_service.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include "../../example/server-framework/ws_upgrade_service.hpp" - diff --git a/src/beast/test/server/wss_ports.cpp b/src/beast/test/server/wss_ports.cpp deleted file mode 100644 index 6307f532c62..00000000000 --- a/src/beast/test/server/wss_ports.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#if BEAST_USE_OPENSSL - -// Test that header file is self-contained. -#include "../../example/server-framework/wss_ports.hpp" - -#endif diff --git a/src/beast/test/version.cpp b/src/beast/test/version.cpp deleted file mode 100644 index f4f10f9dbcf..00000000000 --- a/src/beast/test/version.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include diff --git a/src/beast/test/websocket.cpp b/src/beast/test/websocket.cpp deleted file mode 100644 index d1be7b299d9..00000000000 --- a/src/beast/test/websocket.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include diff --git a/src/beast/test/websocket/CMakeLists.txt b/src/beast/test/websocket/CMakeLists.txt deleted file mode 100644 index 2807477d34f..00000000000 --- a/src/beast/test/websocket/CMakeLists.txt +++ /dev/null @@ -1,38 +0,0 @@ -# Part of Beast - -GroupSources(extras/beast extras) -GroupSources(include/beast beast) - -GroupSources(test/websocket "/") - -#include_directories(../../example/) - -add_executable (websocket-tests - ${BEAST_INCLUDES} - ${EXTRAS_INCLUDES} - ../../extras/beast/unit_test/main.cpp - websocket_async_echo_server.hpp - websocket_sync_echo_server.hpp - doc_snippets.cpp - error.cpp - option.cpp - rfc6455.cpp - stream.cpp - teardown.cpp - frame.cpp - mask.cpp - utf8_checker.cpp -) - -target_link_libraries(websocket-tests - Beast - ${Boost_PROGRAM_OPTIONS_LIBRARY} - ${Boost_FILESYSTEM_LIBRARY} - ${Boost_COROUTINE_LIBRARY} - ${Boost_THREAD_LIBRARY} - ${Boost_CONTEXT_LIBRARY} - ) - -if (OPENSSL_FOUND) - target_link_libraries(websocket-tests ${OPENSSL_LIBRARIES}) -endif() diff --git a/src/beast/test/websocket/Jamfile b/src/beast/test/websocket/Jamfile deleted file mode 100644 index 4781f16aca3..00000000000 --- a/src/beast/test/websocket/Jamfile +++ /dev/null @@ -1,19 +0,0 @@ -# -# Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -# -# 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) -# - -unit-test websocket-tests : - ../../extras/beast/unit_test/main.cpp - doc_snippets.cpp - error.cpp - option.cpp - rfc6455.cpp - stream.cpp - teardown.cpp - frame.cpp - mask.cpp - utf8_checker.cpp - ; diff --git a/src/beast/test/websocket/doc_snippets.cpp b/src/beast/test/websocket/doc_snippets.cpp deleted file mode 100644 index 654c2ca3adf..00000000000 --- a/src/beast/test/websocket/doc_snippets.cpp +++ /dev/null @@ -1,282 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#include -#include -#include -#include -#include -#include -#include -#include - -//[ws_snippet_1 -#include -using namespace beast::websocket; -//] - -using namespace beast; - -namespace doc_ws_snippets { - -void fxx() { - -boost::asio::io_service ios; -boost::asio::io_service::work work{ios}; -std::thread t{[&](){ ios.run(); }}; -error_code ec; -boost::asio::ip::tcp::socket sock{ios}; - -{ -//[ws_snippet_2 - stream ws{ios}; -//] -} - -{ -//[ws_snippet_3 - stream ws{std::move(sock)}; -//] -} - -{ -//[ws_snippet_4 - stream ws{sock}; -//] - -//[ws_snippet_5 - ws.next_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_send); -//] -} - -{ -//[ws_snippet_6 - std::string const host = "mywebapp.com"; - boost::asio::ip::tcp::resolver r{ios}; - stream ws{ios}; - boost::asio::connect(ws.next_layer(), r.resolve({host, "ws"})); -//] -} - -{ -//[ws_snippet_7 - boost::asio::ip::tcp::acceptor acceptor{ios}; - stream ws{acceptor.get_io_service()}; - acceptor.accept(ws.next_layer()); -//] -} - -{ - stream ws{ios}; -//[ws_snippet_8 - ws.handshake("localhost", "/"); -//] - -//[ws_snippet_9 - ws.handshake_ex("localhost", "/", - [](request_type& m) - { - m.insert(http::field::sec_websocket_protocol, "xmpp;ws-chat"); - }); -//] - -//[ws_snippet_10 - response_type res; - ws.handshake(res, "localhost", "/"); - if(! res.count(http::field::sec_websocket_protocol)) - throw std::invalid_argument("missing subprotocols"); -//] - -//[ws_snippet_11 - ws.accept(); -//] - -//[ws_snippet_12 - ws.accept_ex( - [](response_type& m) - { - m.insert(http::field::server, "MyServer"); - }); -//] -} - -{ -//[ws_snippet_13] - // Buffer required for reading HTTP messages - flat_buffer buffer; - - // Read the HTTP request ourselves - http::request req; - http::read(sock, buffer, req); - - // See if its a WebSocket upgrade request - if(websocket::is_upgrade(req)) - { - // Construct the stream, transferring ownership of the socket - stream ws{std::move(sock)}; - - // Accept the request from our message. Clients SHOULD NOT - // begin sending WebSocket frames until the server has - // provided a response, but just in case they did, we pass - // any leftovers in the buffer to the accept function. - // - ws.accept(req, buffer.data()); - } - else - { - // Its not a WebSocket upgrade, so - // handle it like a normal HTTP request. - } -//] -} - -{ - stream ws{ios}; -//[ws_snippet_14 - // Read into our buffer until we reach the end of the HTTP request. - // No parsing takes place here, we are just accumulating data. - boost::asio::streambuf buffer; - boost::asio::read_until(sock, buffer, "\r\n\r\n"); - - // Now accept the connection, using the buffered data. - ws.accept(buffer.data()); -//] -} -{ - stream ws{ios}; -//[ws_snippet_15 - multi_buffer buffer; - ws.read(buffer); - - ws.text(ws.got_text()); - ws.write(buffer.data()); - buffer.consume(buffer.size()); -//] -} - -{ - stream ws{ios}; -//[ws_snippet_16 - multi_buffer buffer; - for(;;) - if(ws.read_frame(buffer)) - break; - ws.binary(ws.got_binary()); - consuming_buffers cb{buffer.data()}; - for(;;) - { - using boost::asio::buffer_size; - if(buffer_size(cb) > 512) - { - ws.write_frame(false, buffer_prefix(512, cb)); - cb.consume(512); - } - else - { - ws.write_frame(true, cb); - break; - } - } -//] -} - -{ - stream ws{ios}; -//[ws_snippet_17 - ws.control_callback( - [](frame_type kind, string_view payload) - { - // Do something with the payload - boost::ignore_unused(kind, payload); - }); -//] - -//[ws_snippet_18 - ws.close(close_code::normal); -//] - -//[ws_snippet_19 - ws.auto_fragment(true); - ws.write_buffer_size(16384); -//] - -//[ws_snippet_20 - multi_buffer buffer; - ws.async_read(buffer, - [](error_code) - { - // Do something with the buffer - }); -//] -} - -} // fxx() - -// workaround for https://github.com/chriskohlhoff/asio/issues/112 -#ifdef BOOST_MSVC -//[ws_snippet_21 -void echo(stream& ws, - multi_buffer& buffer, boost::asio::yield_context yield) -{ - ws.async_read(buffer, yield); - std::future fut = - ws.async_write(buffer.data(), boost::asio::use_future); -} -//] -#endif - -} // doc_ws_snippets - -//------------------------------------------------------------------------------ - -#if BEAST_USE_OPENSSL - -//[wss_snippet_1 -#include -#include -//] - -namespace doc_wss_snippets { - -void fxx() { - -boost::asio::io_service ios; -boost::asio::io_service::work work{ios}; -std::thread t{[&](){ ios.run(); }}; -error_code ec; -boost::asio::ip::tcp::socket sock{ios}; - -{ -//[wss_snippet_2 - boost::asio::ssl::context ctx{boost::asio::ssl::context::sslv23}; - stream> wss{ios, ctx}; -//] -} - -{ -//[wss_snippet_3 - boost::asio::ip::tcp::endpoint ep; - boost::asio::ssl::context ctx{boost::asio::ssl::context::sslv23}; - stream> ws{ios, ctx}; - - // connect the underlying TCP/IP socket - ws.next_layer().next_layer().connect(ep); - - // perform SSL handshake - ws.next_layer().handshake(boost::asio::ssl::stream_base::client); - - // perform WebSocket handshake - ws.handshake("localhost", "/"); -//] -} - -} // fxx() - -} // doc_wss_snippets - -#endif - diff --git a/src/beast/test/websocket/error.cpp b/src/beast/test/websocket/error.cpp deleted file mode 100644 index 3032915d5ce..00000000000 --- a/src/beast/test/websocket/error.cpp +++ /dev/null @@ -1,46 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include -#include - -namespace beast { -namespace websocket { - -class error_test : public unit_test::suite -{ -public: - void check(char const* name, error ev) - { - auto const ec = make_error_code(ev); - BEAST_EXPECT(std::string{ec.category().name()} == name); - BEAST_EXPECT(! ec.message().empty()); - BEAST_EXPECT(std::addressof(ec.category()) == - std::addressof(detail::get_error_category())); - BEAST_EXPECT(detail::get_error_category().equivalent( - static_cast::type>(ev), - ec.category().default_error_condition( - static_cast::type>(ev)))); - BEAST_EXPECT(detail::get_error_category().equivalent( - ec, static_cast::type>(ev))); - } - - void run() override - { - check("beast.websocket", error::closed); - check("beast.websocket", error::failed); - check("beast.websocket", error::handshake_failed); - } -}; - -BEAST_DEFINE_TESTSUITE(error,websocket,beast); - -} // websocket -} // beast diff --git a/src/beast/test/websocket/frame.cpp b/src/beast/test/websocket/frame.cpp deleted file mode 100644 index 2dc21c4ecd5..00000000000 --- a/src/beast/test/websocket/frame.cpp +++ /dev/null @@ -1,253 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace websocket { -namespace detail { - -static -bool -operator==(frame_header const& lhs, frame_header const& rhs) -{ - return - lhs.op == rhs.op && - lhs.fin == rhs.fin && - lhs.mask == rhs.mask && - lhs.rsv1 == rhs.rsv1 && - lhs.rsv2 == rhs.rsv2 && - lhs.rsv3 == rhs.rsv3 && - lhs.len == rhs.len && - lhs.key == rhs.key; -} - -class frame_test - : public beast::unit_test::suite - , public test::enable_yield_to -{ -public: - void testCloseCodes() - { - BEAST_EXPECT(! is_valid_close_code(0)); - BEAST_EXPECT(! is_valid_close_code(1)); - BEAST_EXPECT(! is_valid_close_code(999)); - BEAST_EXPECT(! is_valid_close_code(1004)); - BEAST_EXPECT(! is_valid_close_code(1005)); - BEAST_EXPECT(! is_valid_close_code(1006)); - BEAST_EXPECT(! is_valid_close_code(1016)); - BEAST_EXPECT(! is_valid_close_code(2000)); - BEAST_EXPECT(! is_valid_close_code(2999)); - BEAST_EXPECT(is_valid_close_code(1000)); - BEAST_EXPECT(is_valid_close_code(1002)); - BEAST_EXPECT(is_valid_close_code(3000)); - BEAST_EXPECT(is_valid_close_code(4000)); - BEAST_EXPECT(is_valid_close_code(5000)); - } - - struct test_fh : frame_header - { - test_fh() - { - op = detail::opcode::text; - fin = false; - mask = false; - rsv1 = false; - rsv2 = false; - rsv3 = false; - len = 0; - key = 0; - } - }; - - void testFrameHeader() - { - using stream_type = - beast::websocket::stream; - test::pipe p{ios_}; - - // good frame fields - { - stream_type::role_type role = - stream_type::role_type::client; - - auto check = - [&](frame_header const& fh) - { - fh_streambuf b; - write(b, fh); - close_code code; - stream_type stream{p.server}; - stream.open(role); - detail::frame_header fh1; - auto const n = - stream.read_fh1(fh1, b, code); - if(! BEAST_EXPECT(! code)) - return; - if(! BEAST_EXPECT(b.size() == n)) - return; - stream.read_fh2(fh1, b, code); - if(! BEAST_EXPECT(! code)) - return; - if(! BEAST_EXPECT(b.size() == 0)) - return; - BEAST_EXPECT(fh1 == fh); - }; - - test_fh fh; - - check(fh); - - role = stream_type::role_type::server; - fh.mask = true; - fh.key = 1; - check(fh); - - fh.len = 1; - check(fh); - - fh.len = 126; - check(fh); - - fh.len = 65535; - check(fh); - - fh.len = 65536; - check(fh); - - fh.len = 65537; - check(fh); - } - - // bad frame fields - { - stream_type::role_type role = stream_type::role_type::client; - - auto check = - [&](frame_header const& fh) - { - fh_streambuf b; - write(b, fh); - close_code code; - stream_type stream{p.server}; - stream.open(role); - frame_header fh1; - auto const n = - stream.read_fh1(fh1, b, code); - if(code) - { - pass(); - return; - } - if(! BEAST_EXPECT(b.size() == n)) - return; - stream.read_fh2(fh1, b, code); - if(! BEAST_EXPECT(code)) - return; - if(! BEAST_EXPECT(b.size() == 0)) - return; - }; - - test_fh fh; - - fh.op = detail::opcode::close; - fh.fin = true; - fh.len = 126; - check(fh); - fh.len = 0; - - fh.rsv1 = true; - check(fh); - fh.rsv1 = false; - - fh.rsv2 = true; - check(fh); - fh.rsv2 = false; - - fh.rsv3 = true; - check(fh); - fh.rsv3 = false; - - fh.op = detail::opcode::rsv3; - check(fh); - fh.op = detail::opcode::text; - - fh.op = detail::opcode::ping; - fh.fin = false; - check(fh); - fh.fin = true; - - fh.mask = true; - check(fh); - - role = stream_type::role_type::server; - fh.mask = false; - check(fh); - } - } - - void bad(std::initializer_list bs) - { - using stream_type = - beast::websocket::stream; - using boost::asio::buffer; - using boost::asio::buffer_copy; - test::pipe p{ios_}; - static stream_type::role_type constexpr role = stream_type::role_type::client; - std::vector v{bs}; - fh_streambuf b; - b.commit(buffer_copy(b.prepare(v.size()), buffer(v))); - stream_type stream{p.server}; - stream.open(role); - close_code code; - detail::frame_header fh; - auto const n = - stream.read_fh1(fh, b, code); - if(code) - { - pass(); - return; - } - if(! BEAST_EXPECT(b.size() == n)) - return; - stream.read_fh2(fh, b, code); - if(! BEAST_EXPECT(code)) - return; - if(! BEAST_EXPECT(b.size() == 0)) - return; - } - - void testBadFrameHeaders() - { - // bad frame fields - // - // can't be created by the library - // so we produce them manually. - - bad({0, 126, 0, 125}); - bad({0, 127, 0, 0, 0, 0, 0, 0, 255, 255}); - } - - void run() override - { - testCloseCodes(); - testFrameHeader(); - testBadFrameHeaders(); - } -}; - -BEAST_DEFINE_TESTSUITE(frame,websocket,beast); - -} // detail -} // websocket -} // beast diff --git a/src/beast/test/websocket/mask.cpp b/src/beast/test/websocket/mask.cpp deleted file mode 100644 index 83472556b21..00000000000 --- a/src/beast/test/websocket/mask.cpp +++ /dev/null @@ -1,55 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include - -namespace beast { -namespace websocket { -namespace detail { - -class mask_test : public beast::unit_test::suite -{ -public: - struct test_generator - { - using result_type = std::uint32_t; - - result_type n = 0; - - void - seed(std::seed_seq const&) - { - } - - void - seed(result_type const&) - { - } - - std::uint32_t - operator()() - { - return n++; - } - }; - - void run() override - { - maskgen_t mg; - BEAST_EXPECT(mg() != 0); - } -}; - -BEAST_DEFINE_TESTSUITE(mask,websocket,beast); - -} // detail -} // websocket -} // beast - diff --git a/src/beast/test/websocket/option.cpp b/src/beast/test/websocket/option.cpp deleted file mode 100644 index e0cd2ee500d..00000000000 --- a/src/beast/test/websocket/option.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include diff --git a/src/beast/test/websocket/rfc6455.cpp b/src/beast/test/websocket/rfc6455.cpp deleted file mode 100644 index 169ba810004..00000000000 --- a/src/beast/test/websocket/rfc6455.cpp +++ /dev/null @@ -1,49 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include - -namespace beast { -namespace websocket { - -class rfc6455_test - : public beast::unit_test::suite -{ -public: - void - test_is_upgrade() - { - http::header req; - req.version = 10; - BEAST_EXPECT(! is_upgrade(req)); - req.version = 11; - req.method(http::verb::post); - req.target("/"); - BEAST_EXPECT(! is_upgrade(req)); - req.method(http::verb::get); - req.insert("Connection", "upgrade"); - BEAST_EXPECT(! is_upgrade(req)); - req.insert("Upgrade", "websocket"); - BEAST_EXPECT(! is_upgrade(req)); - req.insert("Sec-WebSocket-Version", "13"); - BEAST_EXPECT(is_upgrade(req)); - } - - void - run() override - { - test_is_upgrade(); - } -}; - -BEAST_DEFINE_TESTSUITE(rfc6455,websocket,beast); - -} // websocket -} // beast diff --git a/src/beast/test/websocket/stream.cpp b/src/beast/test/websocket/stream.cpp deleted file mode 100644 index 02bab544a6a..00000000000 --- a/src/beast/test/websocket/stream.cpp +++ /dev/null @@ -1,1939 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include "websocket_async_echo_server.hpp" -#include "websocket_sync_echo_server.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace beast { -namespace websocket { - -class stream_test - : public beast::unit_test::suite - , public test::enable_yield_to -{ -public: - using self = stream_test; - using endpoint_type = boost::asio::ip::tcp::endpoint; - using address_type = boost::asio::ip::address; - using socket_type = boost::asio::ip::tcp::socket; - - template - static - std::string - to_string(ConstBufferSequence const& bs) - { - return boost::lexical_cast< - std::string>(buffers(bs)); - } - - struct con - { - stream ws; - - con(endpoint_type const& ep, boost::asio::io_service& ios) - : ws(ios) - { - ws.next_layer().connect(ep); - ws.handshake("localhost", "/"); - } - }; - - template - class cbuf_helper - { - std::array v_; - boost::asio::const_buffer cb_; - - public: - using value_type = decltype(cb_); - using const_iterator = value_type const*; - - template - explicit - cbuf_helper(Vn... vn) - : v_({{ static_cast(vn)... }}) - , cb_(v_.data(), v_.size()) - { - } - - const_iterator - begin() const - { - return &cb_; - } - - const_iterator - end() const - { - return begin()+1; - } - }; - - template - cbuf_helper - cbuf(Vn... vn) - { - return cbuf_helper(vn...); - } - - template - static - boost::asio::const_buffers_1 - sbuf(const char (&s)[N]) - { - return boost::asio::const_buffers_1(&s[0], N-1); - } - - template - static - bool - run_until(boost::asio::io_service& ios, - std::size_t limit, Pred&& pred) - { - for(std::size_t i = 0; i < limit; ++i) - { - if(pred()) - return true; - ios.run_one(); - } - return false; - } - - struct SyncClient - { - template - void - accept(stream& ws) const - { - ws.accept(); - } - - template - typename std::enable_if< - ! http::detail::is_header::value>::type - accept(stream& ws, - Buffers const& buffers) const - { - ws.accept(buffers); - } - - template - void - accept(stream& ws, - http::header const& req) const - { - ws.accept(req); - } - - template - void - accept(stream& ws, - http::header const& req, - Buffers const& buffers) const - { - ws.accept(req, buffers); - } - - template - void - accept_ex(stream& ws, - Decorator const& d) const - { - ws.accept_ex(d); - } - - template - typename std::enable_if< - ! http::detail::is_header::value>::type - accept_ex(stream& ws, - Buffers const& buffers, - Decorator const& d) const - { - ws.accept_ex(buffers, d); - } - - template - void - accept_ex(stream& ws, - http::header const& req, - Decorator const& d) const - { - ws.accept_ex(req, d); - } - - template - void - accept_ex(stream& ws, - http::header const& req, - Buffers const& buffers, - Decorator const& d) const - { - ws.accept_ex(req, buffers, d); - } - - template - void - handshake(stream& ws, - string_view uri, - string_view path) const - { - ws.handshake(uri, path); - } - - template - void - handshake(stream& ws, - response_type& res, - string_view uri, - string_view path) const - { - ws.handshake(res, uri, path); - } - - template - void - handshake_ex(stream& ws, - string_view uri, - string_view path, - Decorator const& d) const - { - ws.handshake_ex(uri, path, d); - } - - template - void - handshake_ex(stream& ws, - response_type& res, - string_view uri, - string_view path, - Decorator const& d) const - { - ws.handshake_ex(res, uri, path, d); - } - - template - void - ping(stream& ws, - ping_data const& payload) const - { - ws.ping(payload); - } - - template - void - pong(stream& ws, - ping_data const& payload) const - { - ws.pong(payload); - } - - template - void - close(stream& ws, - close_reason const& cr) const - { - ws.close(cr); - } - - template< - class NextLayer, class DynamicBuffer> - void - read(stream& ws, - DynamicBuffer& buffer) const - { - ws.read(buffer); - } - - template< - class NextLayer, class ConstBufferSequence> - void - write(stream& ws, - ConstBufferSequence const& buffers) const - { - ws.write(buffers); - } - - template< - class NextLayer, class ConstBufferSequence> - void - write_frame(stream& ws, bool fin, - ConstBufferSequence const& buffers) const - { - ws.write_frame(fin, buffers); - } - - template< - class NextLayer, class ConstBufferSequence> - void - write_raw(stream& ws, - ConstBufferSequence const& buffers) const - { - boost::asio::write( - ws.next_layer(), buffers); - } - }; - - class AsyncClient - { - yield_context& yield_; - - public: - explicit - AsyncClient(yield_context& yield) - : yield_(yield) - { - } - - template - void - accept(stream& ws) const - { - error_code ec; - ws.async_accept(yield_[ec]); - if(ec) - throw system_error{ec}; - } - - template - typename std::enable_if< - ! http::detail::is_header::value>::type - accept(stream& ws, - Buffers const& buffers) const - { - error_code ec; - ws.async_accept(buffers, yield_[ec]); - if(ec) - throw system_error{ec}; - } - - template - void - accept(stream& ws, - http::header const& req) const - { - error_code ec; - ws.async_accept(req, yield_[ec]); - if(ec) - throw system_error{ec}; - } - - template - void - accept(stream& ws, - http::header const& req, - Buffers const& buffers) const - { - error_code ec; - ws.async_accept(req, buffers, yield_[ec]); - if(ec) - throw system_error{ec}; - } - - template - void - accept_ex(stream& ws, - Decorator const& d) const - { - error_code ec; - ws.async_accept_ex(d, yield_[ec]); - if(ec) - throw system_error{ec}; - } - - template - typename std::enable_if< - ! http::detail::is_header::value>::type - accept_ex(stream& ws, - Buffers const& buffers, - Decorator const& d) const - { - error_code ec; - ws.async_accept_ex(buffers, d, yield_[ec]); - if(ec) - throw system_error{ec}; - } - - template - void - accept_ex(stream& ws, - http::header const& req, - Decorator const& d) const - { - error_code ec; - ws.async_accept_ex(req, d, yield_[ec]); - if(ec) - throw system_error{ec}; - } - - template - void - accept_ex(stream& ws, - http::header const& req, - Buffers const& buffers, - Decorator const& d) const - { - error_code ec; - ws.async_accept_ex( - req, buffers, d, yield_[ec]); - if(ec) - throw system_error{ec}; - } - - template - void - handshake(stream& ws, - string_view uri, - string_view path) const - { - error_code ec; - ws.async_handshake( - uri, path, yield_[ec]); - if(ec) - throw system_error{ec}; - } - - template - void - handshake(stream& ws, - response_type& res, - string_view uri, - string_view path) const - { - error_code ec; - ws.async_handshake( - res, uri, path, yield_[ec]); - if(ec) - throw system_error{ec}; - } - - template - void - handshake_ex(stream& ws, - string_view uri, - string_view path, - Decorator const &d) const - { - error_code ec; - ws.async_handshake_ex( - uri, path, d, yield_[ec]); - if(ec) - throw system_error{ec}; - } - - template - void - handshake_ex(stream& ws, - response_type& res, - string_view uri, - string_view path, - Decorator const &d) const - { - error_code ec; - ws.async_handshake_ex( - res, uri, path, d, yield_[ec]); - if(ec) - throw system_error{ec}; - } - - template - void - ping(stream& ws, - ping_data const& payload) const - { - error_code ec; - ws.async_ping(payload, yield_[ec]); - if(ec) - throw system_error{ec}; - } - - template - void - pong(stream& ws, - ping_data const& payload) const - { - error_code ec; - ws.async_pong(payload, yield_[ec]); - if(ec) - throw system_error{ec}; - } - - template - void - close(stream& ws, - close_reason const& cr) const - { - error_code ec; - ws.async_close(cr, yield_[ec]); - if(ec) - throw system_error{ec}; - } - - template< - class NextLayer, class DynamicBuffer> - void - read(stream& ws, - DynamicBuffer& buffer) const - { - error_code ec; - ws.async_read(buffer, yield_[ec]); - if(ec) - throw system_error{ec}; - } - - template< - class NextLayer, class ConstBufferSequence> - void - write(stream& ws, - ConstBufferSequence const& buffers) const - { - error_code ec; - ws.async_write(buffers, yield_[ec]); - if(ec) - throw system_error{ec}; - } - - template< - class NextLayer, class ConstBufferSequence> - void - write_frame(stream& ws, bool fin, - ConstBufferSequence const& buffers) const - { - error_code ec; - ws.async_write_frame(fin, buffers, yield_[ec]); - if(ec) - throw system_error{ec}; - } - - template< - class NextLayer, class ConstBufferSequence> - void - write_raw(stream& ws, - ConstBufferSequence const& buffers) const - { - error_code ec; - boost::asio::async_write( - ws.next_layer(), buffers, yield_[ec]); - if(ec) - throw system_error{ec}; - } - }; - - void - testOptions() - { - stream ws(ios_); - ws.auto_fragment(true); - ws.write_buffer_size(2048); - ws.binary(false); - ws.read_buffer_size(8192); - ws.read_message_max(1 * 1024 * 1024); - try - { - ws.write_buffer_size(7); - fail(); - } - catch(std::exception const&) - { - pass(); - } - } - - //-------------------------------------------------------------------------- - - class res_decorator - { - bool& b_; - - public: - res_decorator(res_decorator const&) = default; - - explicit - res_decorator(bool& b) - : b_(b) - { - } - - void - operator()(response_type&) const - { - b_ = true; - } - }; - - template - void - testAccept(Client const& c) - { - static std::size_t constexpr limit = 200; - std::size_t n; - for(n = 0; n < limit; ++n) - { - test::fail_counter fc{n}; - try - { - // request in stream - { - stream> ws{fc, ios_, - "GET / HTTP/1.1\r\n" - "Host: localhost\r\n" - "Upgrade: websocket\r\n" - "Connection: upgrade\r\n" - "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" - "Sec-WebSocket-Version: 13\r\n" - "\r\n" - , 20}; - c.accept(ws); - // VFALCO validate contents of ws.next_layer().str? - } - { - stream> ws{fc, ios_, - "GET / HTTP/1.1\r\n" - "Host: localhost\r\n" - "Upgrade: websocket\r\n" - "Connection: upgrade\r\n" - "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" - "Sec-WebSocket-Version: 13\r\n" - "\r\n" - , 20}; - bool called = false; - c.accept_ex(ws, res_decorator{called}); - BEAST_EXPECT(called); - } - // request in buffers - { - stream> ws{fc, ios_}; - c.accept(ws, sbuf( - "GET / HTTP/1.1\r\n" - "Host: localhost\r\n" - "Upgrade: websocket\r\n" - "Connection: upgrade\r\n" - "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" - "Sec-WebSocket-Version: 13\r\n" - "\r\n" - )); - } - { - stream> ws{fc, ios_}; - bool called = false; - c.accept_ex(ws, sbuf( - "GET / HTTP/1.1\r\n" - "Host: localhost\r\n" - "Upgrade: websocket\r\n" - "Connection: upgrade\r\n" - "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" - "Sec-WebSocket-Version: 13\r\n" - "\r\n"), - res_decorator{called}); - BEAST_EXPECT(called); - } - // request in buffers and stream - { - stream> ws{fc, ios_, - "Connection: upgrade\r\n" - "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" - "Sec-WebSocket-Version: 13\r\n" - "\r\n" - , 16}; - c.accept(ws, sbuf( - "GET / HTTP/1.1\r\n" - "Host: localhost\r\n" - "Upgrade: websocket\r\n" - )); - } - { - stream> ws{fc, ios_, - "Connection: upgrade\r\n" - "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" - "Sec-WebSocket-Version: 13\r\n" - "\r\n" - , 16}; - bool called = false; - c.accept_ex(ws, sbuf( - "GET / HTTP/1.1\r\n" - "Host: localhost\r\n" - "Upgrade: websocket\r\n"), - res_decorator{called}); - BEAST_EXPECT(called); - } - // request in message - { - request_type req; - req.method(http::verb::get); - req.target("/"); - req.version = 11; - req.insert("Host", "localhost"); - req.insert("Upgrade", "websocket"); - req.insert("Connection", "upgrade"); - req.insert("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); - req.insert("Sec-WebSocket-Version", "13"); - stream> ws{fc, ios_}; - c.accept(ws, req); - } - { - request_type req; - req.method(http::verb::get); - req.target("/"); - req.version = 11; - req.insert("Host", "localhost"); - req.insert("Upgrade", "websocket"); - req.insert("Connection", "upgrade"); - req.insert("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); - req.insert("Sec-WebSocket-Version", "13"); - stream> ws{fc, ios_}; - bool called = false; - c.accept_ex(ws, req, - res_decorator{called}); - BEAST_EXPECT(called); - } - // request in message, close frame in buffers - { - request_type req; - req.method(http::verb::get); - req.target("/"); - req.version = 11; - req.insert("Host", "localhost"); - req.insert("Upgrade", "websocket"); - req.insert("Connection", "upgrade"); - req.insert("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); - req.insert("Sec-WebSocket-Version", "13"); - stream> ws{fc, ios_}; - c.accept(ws, req, - cbuf(0x88, 0x82, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x17)); - try - { - multi_buffer b; - c.read(ws, b); - fail("success", __FILE__, __LINE__); - } - catch(system_error const& e) - { - if(e.code() != websocket::error::closed) - throw; - } - } - { - request_type req; - req.method(http::verb::get); - req.target("/"); - req.version = 11; - req.insert("Host", "localhost"); - req.insert("Upgrade", "websocket"); - req.insert("Connection", "upgrade"); - req.insert("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); - req.insert("Sec-WebSocket-Version", "13"); - stream> ws{fc, ios_}; - bool called = false; - c.accept_ex(ws, req, - cbuf(0x88, 0x82, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x17), - res_decorator{called}); - BEAST_EXPECT(called); - try - { - multi_buffer b; - c.read(ws, b); - fail("success", __FILE__, __LINE__); - } - catch(system_error const& e) - { - if(e.code() != websocket::error::closed) - throw; - } - } - // request in message, close frame in stream - { - request_type req; - req.method(http::verb::get); - req.target("/"); - req.version = 11; - req.insert("Host", "localhost"); - req.insert("Upgrade", "websocket"); - req.insert("Connection", "upgrade"); - req.insert("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); - req.insert("Sec-WebSocket-Version", "13"); - stream> ws{fc, ios_, - "\x88\x82\xff\xff\xff\xff\xfc\x17"}; - c.accept(ws, req); - try - { - multi_buffer b; - c.read(ws, b); - fail("success", __FILE__, __LINE__); - } - catch(system_error const& e) - { - if(e.code() != websocket::error::closed) - throw; - } - } - // request in message, close frame in stream and buffers - { - request_type req; - req.method(http::verb::get); - req.target("/"); - req.version = 11; - req.insert("Host", "localhost"); - req.insert("Upgrade", "websocket"); - req.insert("Connection", "upgrade"); - req.insert("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); - req.insert("Sec-WebSocket-Version", "13"); - stream> ws{fc, ios_, - "xff\xff\xfc\x17"}; - c.accept(ws, req, - cbuf(0x88, 0x82, 0xff, 0xff)); - try - { - multi_buffer b; - c.read(ws, b); - fail("success", __FILE__, __LINE__); - } - catch(system_error const& e) - { - if(e.code() != websocket::error::closed) - throw; - } - } - // failed handshake (missing Sec-WebSocket-Key) - { - stream> ws{fc, ios_, - "GET / HTTP/1.1\r\n" - "Host: localhost\r\n" - "Upgrade: websocket\r\n" - "Connection: upgrade\r\n" - "Sec-WebSocket-Version: 13\r\n" - "\r\n" - , 20}; - try - { - c.accept(ws); - fail("success", __FILE__, __LINE__); - } - catch(system_error const& e) - { - if( e.code() != - websocket::error::handshake_failed && - e.code() != - boost::asio::error::eof) - throw; - } - } - } - catch(system_error const&) - { - continue; - } - break; - } - BEAST_EXPECT(n < limit); - } - - void - testAccept() - { - testAccept(SyncClient{}); - yield_to( - [&](yield_context yield) - { - testAccept(AsyncClient{yield}); - }); - } - - //-------------------------------------------------------------------------- - - class req_decorator - { - bool& b_; - - public: - req_decorator(req_decorator const&) = default; - - explicit - req_decorator(bool& b) - : b_(b) - { - } - - void - operator()(request_type&) const - { - b_ = true; - } - }; - - template - void - testHandshake(endpoint_type const& ep, Client const& c) - { - static std::size_t constexpr limit = 200; - std::size_t n; - for(n = 199; n < limit; ++n) - { - test::fail_counter fc{n}; - try - { - // handshake - { - stream> ws{fc, ios_}; - ws.next_layer().next_layer().connect(ep); - c.handshake(ws, "localhost", "/"); - } - // handshake, response - { - stream> ws{fc, ios_}; - ws.next_layer().next_layer().connect(ep); - response_type res; - c.handshake(ws, res, "localhost", "/"); - // VFALCO validate res? - } - // handshake_ex - { - stream> ws{fc, ios_}; - ws.next_layer().next_layer().connect(ep); - bool called = false; - c.handshake_ex(ws, "localhost", "/", - req_decorator{called}); - BEAST_EXPECT(called); - } - // handshake_ex, response - { - stream> ws{fc, ios_}; - ws.next_layer().next_layer().connect(ep); - bool called = false; - response_type res; - c.handshake_ex(ws, res, "localhost", "/", - req_decorator{called}); - // VFALCO validate res? - BEAST_EXPECT(called); - } - } - catch(system_error const&) - { - continue; - } - break; - } - BEAST_EXPECT(n < limit); - } - - void - testHandshake() - { - error_code ec = test::error::fail_error; - ::websocket::async_echo_server server{nullptr, 1}; - auto const any = endpoint_type{ - address_type::from_string("127.0.0.1"), 0}; - server.open(any, ec); - BEAST_EXPECTS(! ec, ec.message()); - auto const ep = server.local_endpoint(); - testHandshake(ep, SyncClient{}); - yield_to( - [&](yield_context yield) - { - testHandshake(ep, AsyncClient{yield}); - }); - } - - //-------------------------------------------------------------------------- - - void testBadHandshakes() - { - auto const check = - [&](error_code const& ev, std::string const& s) - { - for(std::size_t i = 0; i < s.size(); ++i) - { - stream ws(ios_, - s.substr(i, s.size() - i)); - try - { - ws.accept(boost::asio::buffer( - s.substr(0, i), i)); - BEAST_EXPECTS(! ev, ev.message()); - } - catch(system_error const& se) - { - BEAST_EXPECTS(se.code() == ev, se.what()); - } - } - }; - // wrong version - check(http::error::end_of_stream, - "GET / HTTP/1.0\r\n" - "Host: localhost:80\r\n" - "Upgrade: WebSocket\r\n" - "Connection: keep-alive,upgrade\r\n" - "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" - "Sec-WebSocket-Version: 13\r\n" - "\r\n" - ); - // wrong method - check(error::handshake_failed, - "POST / HTTP/1.1\r\n" - "Host: localhost:80\r\n" - "Upgrade: WebSocket\r\n" - "Connection: keep-alive,upgrade\r\n" - "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" - "Sec-WebSocket-Version: 13\r\n" - "\r\n" - ); - // missing Host - check(error::handshake_failed, - "GET / HTTP/1.1\r\n" - "Upgrade: WebSocket\r\n" - "Connection: keep-alive,upgrade\r\n" - "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" - "Sec-WebSocket-Version: 13\r\n" - "\r\n" - ); - // missing Sec-WebSocket-Key - check(error::handshake_failed, - "GET / HTTP/1.1\r\n" - "Host: localhost:80\r\n" - "Upgrade: WebSocket\r\n" - "Connection: keep-alive,upgrade\r\n" - "Sec-WebSocket-Version: 13\r\n" - "\r\n" - ); - // missing Sec-WebSocket-Version - check(error::handshake_failed, - "GET / HTTP/1.1\r\n" - "Host: localhost:80\r\n" - "Upgrade: WebSocket\r\n" - "Connection: keep-alive,upgrade\r\n" - "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" - "\r\n" - ); - // wrong Sec-WebSocket-Version - check(error::handshake_failed, - "GET / HTTP/1.1\r\n" - "Host: localhost:80\r\n" - "Upgrade: WebSocket\r\n" - "Connection: keep-alive,upgrade\r\n" - "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" - "Sec-WebSocket-Version: 1\r\n" - "\r\n" - ); - // missing upgrade token - check(error::handshake_failed, - "GET / HTTP/1.1\r\n" - "Host: localhost:80\r\n" - "Upgrade: HTTP/2\r\n" - "Connection: upgrade\r\n" - "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" - "Sec-WebSocket-Version: 13\r\n" - "\r\n" - ); - // missing connection token - check(error::handshake_failed, - "GET / HTTP/1.1\r\n" - "Host: localhost:80\r\n" - "Upgrade: WebSocket\r\n" - "Connection: keep-alive\r\n" - "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" - "Sec-WebSocket-Version: 13\r\n" - "\r\n" - ); - // valid request - check({}, - "GET / HTTP/1.1\r\n" - "Host: localhost:80\r\n" - "Upgrade: WebSocket\r\n" - "Connection: upgrade\r\n" - "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" - "Sec-WebSocket-Version: 13\r\n" - "\r\n" - ); - } - - void testBadResponses() - { - auto const check = - [&](std::string const& s) - { - stream ws(ios_, s); - try - { - ws.handshake("localhost:80", "/"); - fail(); - } - catch(system_error const& se) - { - BEAST_EXPECT(se.code() == error::handshake_failed); - } - }; - // wrong HTTP version - check( - "HTTP/1.0 101 Switching Protocols\r\n" - "Server: beast\r\n" - "Upgrade: WebSocket\r\n" - "Connection: upgrade\r\n" - "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n" - "Sec-WebSocket-Version: 13\r\n" - "\r\n" - ); - // wrong status - check( - "HTTP/1.1 200 OK\r\n" - "Server: beast\r\n" - "Upgrade: WebSocket\r\n" - "Connection: upgrade\r\n" - "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n" - "Sec-WebSocket-Version: 13\r\n" - "\r\n" - ); - // missing upgrade token - check( - "HTTP/1.1 101 Switching Protocols\r\n" - "Server: beast\r\n" - "Upgrade: HTTP/2\r\n" - "Connection: upgrade\r\n" - "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n" - "Sec-WebSocket-Version: 13\r\n" - "\r\n" - ); - // missing connection token - check( - "HTTP/1.1 101 Switching Protocols\r\n" - "Server: beast\r\n" - "Upgrade: WebSocket\r\n" - "Connection: keep-alive\r\n" - "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n" - "Sec-WebSocket-Version: 13\r\n" - "\r\n" - ); - // missing accept key - check( - "HTTP/1.1 101 Switching Protocols\r\n" - "Server: beast\r\n" - "Upgrade: WebSocket\r\n" - "Connection: upgrade\r\n" - "Sec-WebSocket-Version: 13\r\n" - "\r\n" - ); - // wrong accept key - check( - "HTTP/1.1 101 Switching Protocols\r\n" - "Server: beast\r\n" - "Upgrade: WebSocket\r\n" - "Connection: upgrade\r\n" - "Sec-WebSocket-Accept: *\r\n" - "Sec-WebSocket-Version: 13\r\n" - "\r\n" - ); - } - - void - testMask(endpoint_type const& ep, - yield_context do_yield) - { - { - std::vector v; - for(char n = 0; n < 20; ++n) - { - error_code ec = test::error::fail_error; - socket_type sock(ios_); - sock.connect(ep, ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - break; - stream ws(sock); - ws.handshake("localhost", "/", ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - break; - ws.write(boost::asio::buffer(v), ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - break; - multi_buffer db; - ws.read(db, ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - break; - BEAST_EXPECT(to_string(db.data()) == - std::string(v.data(), v.size())); - v.push_back(n+1); - } - } - { - std::vector v; - for(char n = 0; n < 20; ++n) - { - error_code ec = test::error::fail_error; - socket_type sock(ios_); - sock.connect(ep, ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - break; - stream ws(sock); - ws.handshake("localhost", "/", ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - break; - ws.async_write(boost::asio::buffer(v), do_yield[ec]); - if(! BEAST_EXPECTS(! ec, ec.message())) - break; - multi_buffer db; - ws.async_read(db, do_yield[ec]); - if(! BEAST_EXPECTS(! ec, ec.message())) - break; - BEAST_EXPECT(to_string(db.data()) == - std::string(v.data(), v.size())); - v.push_back(n+1); - } - } - } - - void testClose(endpoint_type const& ep, yield_context) - { - { - // payload length 1 - con c(ep, ios_); - boost::asio::write(c.ws.next_layer(), - cbuf(0x88, 0x81, 0xff, 0xff, 0xff, 0xff, 0x00)); - } - { - // invalid close code 1005 - con c(ep, ios_); - boost::asio::write(c.ws.next_layer(), - cbuf(0x88, 0x82, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x12)); - } - { - // invalid utf8 - con c(ep, ios_); - boost::asio::write(c.ws.next_layer(), - cbuf(0x88, 0x86, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x15, - 0x0f, 0xd7, 0x73, 0x43)); - } - { - // good utf8 - con c(ep, ios_); - boost::asio::write(c.ws.next_layer(), - cbuf(0x88, 0x86, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x15, - 'u', 't', 'f', '8')); - } - } - -#if 0 - void testPausation1(endpoint_type const& ep) - { - boost::asio::io_service ios; - stream ws(ios); - ws.next_layer().connect(ep); - ws.handshake("localhost", "/"); - - // Make remote send a ping frame - ws.binary(false); - ws.write(buffer_cat(sbuf("PING"), sbuf("ping"))); - - std::size_t count = 0; - - // Write a text message - ++count; - ws.async_write(sbuf("Hello"), - [&](error_code ec) - { - --count; - }); - - // Read - multi_buffer db; - ++count; - ws.async_read(db, - [&](error_code ec) - { - --count; - }); - // Run until the read_op writes a close frame. - while(! ws.wr_block_) - ios.run_one(); - // Write a text message, leaving - // the write_op suspended as pausation. - ws.async_write(sbuf("Hello"), - [&](error_code ec) - { - ++count; - // Send is canceled because close received. - BEAST_EXPECT(ec == boost::asio:: - error::operation_aborted, - ec.message()); - // Writes after close are aborted. - ws.async_write(sbuf("World"), - [&](error_code ec) - { - ++count; - BEAST_EXPECT(ec == boost::asio:: - error::operation_aborted, - ec.message()); - }); - }); - // Run until all completions are delivered. - static std::size_t constexpr limit = 100; - std::size_t n; - for(n = 0; n < limit; ++n) - { - if(count >= 4) - break; - ios.run_one(); - } - BEAST_EXPECT(n < limit); - ios.run(); - } -#endif - - void testPausation2(endpoint_type const& ep) - { - boost::asio::io_service ios; - stream ws(ios); - ws.next_layer().connect(ep); - ws.handshake("localhost", "/"); - - // Make remote send a text message with bad utf8. - ws.binary(true); - ws.write(buffer_cat(sbuf("TEXT"), - cbuf(0x03, 0xea, 0xf0, 0x28, 0x8c, 0xbc))); - multi_buffer db; - std::size_t count = 0; - // Read text message with bad utf8. - // Causes a close to be sent, blocking writes. - ws.async_read(db, - [&](error_code ec) - { - // Read should fail with protocol error - ++count; - BEAST_EXPECTS( - ec == error::failed, ec.message()); - // Reads after failure are aborted - ws.async_read(db, - [&](error_code ec) - { - ++count; - BEAST_EXPECTS(ec == boost::asio:: - error::operation_aborted, - ec.message()); - }); - }); - // Run until the read_op writes a close frame. - while(! ws.wr_block_) - ios.run_one(); - // Write a text message, leaving - // the write_op suspended as a pausation. - ws.async_write(sbuf("Hello"), - [&](error_code ec) - { - ++count; - // Send is canceled because close received. - BEAST_EXPECTS(ec == boost::asio:: - error::operation_aborted, - ec.message()); - // Writes after close are aborted. - ws.async_write(sbuf("World"), - [&](error_code ec) - { - ++count; - BEAST_EXPECTS(ec == boost::asio:: - error::operation_aborted, - ec.message()); - }); - }); - // Run until all completions are delivered. - static std::size_t constexpr limit = 100; - std::size_t n; - for(n = 0; n < limit; ++n) - { - if(count >= 4) - break; - ios.run_one(); - } - BEAST_EXPECT(n < limit); - ios.run(); - } - - void testPausation3(endpoint_type const& ep) - { - boost::asio::io_service ios; - stream ws(ios); - ws.next_layer().connect(ep); - ws.handshake("localhost", "/"); - - // Cause close to be received - ws.binary(true); - ws.write(sbuf("CLOSE")); - multi_buffer db; - std::size_t count = 0; - // Read a close frame. - // Sends a close frame, blocking writes. - ws.async_read(db, - [&](error_code ec) - { - // Read should complete with error::closed - ++count; - BEAST_EXPECTS(ec == error::closed, - ec.message()); - // Pings after a close are aborted - ws.async_ping("", - [&](error_code ec) - { - ++count; - BEAST_EXPECTS(ec == boost::asio:: - error::operation_aborted, - ec.message()); - }); - }); - if(! BEAST_EXPECT(run_until(ios, 100, - [&]{ return ws.wr_close_; }))) - return; - // Try to ping - ws.async_ping("payload", - [&](error_code ec) - { - // Pings after a close are aborted - ++count; - BEAST_EXPECTS(ec == boost::asio:: - error::operation_aborted, - ec.message()); - // Subsequent calls to close are aborted - ws.async_close({}, - [&](error_code ec) - { - ++count; - BEAST_EXPECTS(ec == boost::asio:: - error::operation_aborted, - ec.message()); - }); - }); - static std::size_t constexpr limit = 100; - std::size_t n; - for(n = 0; n < limit; ++n) - { - if(count >= 4) - break; - ios.run_one(); - } - BEAST_EXPECT(n < limit); - ios.run(); - } - - void testPausation4(endpoint_type const& ep) - { - boost::asio::io_service ios; - stream ws(ios); - ws.next_layer().connect(ep); - ws.handshake("localhost", "/"); - - // Cause close to be received - ws.binary(true); - ws.write(sbuf("CLOSE")); - multi_buffer db; - std::size_t count = 0; - ws.async_read(db, - [&](error_code ec) - { - ++count; - BEAST_EXPECTS(ec == error::closed, - ec.message()); - }); - while(! ws.wr_block_) - ios.run_one(); - // try to close - ws.async_close("payload", - [&](error_code ec) - { - ++count; - BEAST_EXPECTS(ec == boost::asio:: - error::operation_aborted, - ec.message()); - }); - static std::size_t constexpr limit = 100; - std::size_t n; - for(n = 0; n < limit; ++n) - { - if(count >= 2) - break; - ios.run_one(); - } - BEAST_EXPECT(n < limit); - ios.run(); - } - -#if 0 - void testPausation5(endpoint_type const& ep) - { - boost::asio::io_service ios; - stream ws(ios); - ws.next_layer().connect(ep); - ws.handshake("localhost", "/"); - - ws.async_write(sbuf("CLOSE"), - [&](error_code ec) - { - BEAST_EXPECT(! ec); - ws.async_write(sbuf("PING"), - [&](error_code ec) - { - BEAST_EXPECT(! ec); - }); - }); - multi_buffer db; - ws.async_read(db, - [&](error_code ec) - { - BEAST_EXPECTS(ec == error::closed, ec.message()); - }); - if(! BEAST_EXPECT(run_until(ios, 100, - [&]{ return ios.stopped(); }))) - return; - } -#endif - - /* - https://github.com/vinniefalco/Beast/issues/300 - - Write a message as two individual frames - */ - void - testWriteFrames(endpoint_type const& ep) - { - error_code ec; - socket_type sock{ios_}; - sock.connect(ep, ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - stream ws{sock}; - ws.handshake("localhost", "/", ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - ws.write_frame(false, sbuf("u")); - ws.write_frame(true, sbuf("v")); - multi_buffer b; - ws.read(b, ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - } - - void - testAsyncWriteFrame(endpoint_type const& ep) - { - for(;;) - { - boost::asio::io_service ios; - error_code ec; - socket_type sock(ios); - sock.connect(ep, ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - break; - stream ws(sock); - ws.handshake("localhost", "/", ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - break; - ws.async_write_frame(false, - boost::asio::null_buffers{}, - [&](error_code) - { - fail(); - }); - ws.next_layer().cancel(ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - break; - // - // Destruction of the io_service will cause destruction - // of the write_frame_op without invoking the final handler. - // - break; - } - } - - struct abort_test - { - }; - - template - void - testEndpoint(Client const& c, - endpoint_type const& ep, permessage_deflate const& pmd) - { - using boost::asio::buffer; - static std::size_t constexpr limit = 200; - std::size_t n; - for(n = 0; n <= limit; ++n) - { - stream> ws{n, ios_}; - ws.set_option(pmd); - auto const restart = - [&](error_code ev) - { - try - { - multi_buffer db; - c.read(ws, db); - fail(); - throw abort_test{}; - } - catch(system_error const& se) - { - if(se.code() != ev) - throw; - } - error_code ec; - ws.lowest_layer().connect(ep, ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - throw abort_test{}; - c.handshake(ws, "localhost", "/"); - }; - try - { - { - // connect - error_code ec; - ws.lowest_layer().connect(ep, ec); - if(! BEAST_EXPECTS(! ec, ec.message())) - return; - } - c.handshake(ws, "localhost", "/"); - - // send message - ws.auto_fragment(false); - ws.binary(false); - c.write(ws, sbuf("Hello")); - { - // receive echoed message - multi_buffer db; - c.read(ws, db); - BEAST_EXPECT(ws.got_text()); - BEAST_EXPECT(to_string(db.data()) == "Hello"); - } - - // close, no payload - c.close(ws, {}); - restart(error::closed); - - // close with code - c.close(ws, close_code::going_away); - restart(error::closed); - - // close with code and reason string - c.close(ws, {close_code::going_away, "Going away"}); - restart(error::closed); - - bool once; - - // send ping and message - once = false; - ws.control_callback( - [&](frame_type kind, string_view s) - { - BEAST_EXPECT(kind == frame_type::pong); - BEAST_EXPECT(! once); - once = true; - BEAST_EXPECT(s == ""); - }); - c.ping(ws, ""); - ws.binary(true); - c.write(ws, sbuf("Hello")); - { - // receive echoed message - multi_buffer db; - c.read(ws, db); - BEAST_EXPECT(once); - BEAST_EXPECT(ws.got_binary()); - BEAST_EXPECT(to_string(db.data()) == "Hello"); - } - ws.control_callback({}); - - // send ping and fragmented message - once = false; - ws.control_callback( - [&](frame_type kind, string_view s) - { - BEAST_EXPECT(kind == frame_type::pong); - BEAST_EXPECT(! once); - once = true; - BEAST_EXPECT(s == "payload"); - }); - ws.ping("payload"); - c.write_frame(ws, false, sbuf("Hello, ")); - c.write_frame(ws, false, sbuf("")); - c.write_frame(ws, true, sbuf("World!")); - { - // receive echoed message - multi_buffer db; - c.read(ws, db); - BEAST_EXPECT(once); - BEAST_EXPECT(to_string(db.data()) == "Hello, World!"); - } - ws.control_callback({}); - - // send pong - c.pong(ws, ""); - - // send auto fragmented message - ws.auto_fragment(true); - ws.write_buffer_size(8); - c.write(ws, sbuf("Now is the time for all good men")); - { - // receive echoed message - multi_buffer b; - c.read(ws, b); - BEAST_EXPECT(to_string(b.data()) == "Now is the time for all good men"); - } - ws.auto_fragment(false); - ws.write_buffer_size(4096); - - // send message with write buffer limit - { - std::string s(2000, '*'); - ws.write_buffer_size(1200); - c.write(ws, buffer(s.data(), s.size())); - { - // receive echoed message - multi_buffer db; - c.read(ws, db); - BEAST_EXPECT(to_string(db.data()) == s); - } - } - - // cause ping - ws.binary(true); - c.write(ws, sbuf("PING")); - ws.binary(false); - c.write(ws, sbuf("Hello")); - { - // receive echoed message - multi_buffer db; - c.read(ws, db); - BEAST_EXPECT(ws.got_text()); - BEAST_EXPECT(to_string(db.data()) == "Hello"); - } - - // cause close - ws.binary(true); - c.write(ws, sbuf("CLOSE")); - restart(error::closed); - - // send bad utf8 - ws.binary(true); - c.write(ws, buffer_cat(sbuf("TEXT"), - cbuf(0x03, 0xea, 0xf0, 0x28, 0x8c, 0xbc))); - restart(error::failed); - - // cause bad utf8 - ws.binary(true); - c.write(ws, buffer_cat(sbuf("TEXT"), - cbuf(0x03, 0xea, 0xf0, 0x28, 0x8c, 0xbc))); - c.write(ws, sbuf("Hello")); - restart(error::failed); - - // cause bad close - ws.binary(true); - c.write(ws, buffer_cat(sbuf("RAW"), - cbuf(0x88, 0x02, 0x03, 0xed))); - restart(error::failed); - - // unexpected cont - c.write_raw(ws, - cbuf(0x80, 0x80, 0xff, 0xff, 0xff, 0xff)); - restart(error::closed); - - // invalid fixed frame header - c.write_raw(ws, - cbuf(0x8f, 0x80, 0xff, 0xff, 0xff, 0xff)); - restart(error::closed); - - // cause non-canonical extended size - c.write(ws, buffer_cat(sbuf("RAW"), - cbuf(0x82, 0x7e, 0x00, 0x01, 0x00))); - restart(error::failed); - - if(! pmd.client_enable) - { - // expected cont - c.write_frame(ws, false, boost::asio::null_buffers{}); - c.write_raw(ws, - cbuf(0x81, 0x80, 0xff, 0xff, 0xff, 0xff)); - restart(error::closed); - - // message size above 2^64 - c.write_frame(ws, false, cbuf(0x00)); - c.write_raw(ws, - cbuf(0x80, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff)); - restart(error::closed); - - // message size exceeds max - ws.read_message_max(1); - c.write(ws, cbuf(0x00, 0x00)); - restart(error::failed); - ws.read_message_max(16*1024*1024); - } - } - catch(system_error const&) - { - continue; - } - break; - } - BEAST_EXPECT(n < limit); - } - - void - run() override - { - BOOST_STATIC_ASSERT(std::is_constructible< - stream, boost::asio::io_service&>::value); - - BOOST_STATIC_ASSERT(std::is_move_constructible< - stream>::value); - - BOOST_STATIC_ASSERT(std::is_move_assignable< - stream>::value); - - BOOST_STATIC_ASSERT(std::is_constructible< - stream, socket_type&>::value); - - BOOST_STATIC_ASSERT(std::is_move_constructible< - stream>::value); - - BOOST_STATIC_ASSERT(! std::is_move_assignable< - stream>::value); - - log << "sizeof(websocket::stream) == " << - sizeof(websocket::stream) << std::endl; - - auto const any = endpoint_type{ - address_type::from_string("127.0.0.1"), 0}; - - testOptions(); - testAccept(); - testHandshake(); - testBadHandshakes(); - testBadResponses(); - - permessage_deflate pmd; - pmd.client_enable = false; - pmd.server_enable = false; - - { - error_code ec; - ::websocket::sync_echo_server server{nullptr}; - server.set_option(pmd); - server.open(any, ec); - BEAST_EXPECTS(! ec, ec.message()); - auto const ep = server.local_endpoint(); - //testPausation1(ep); - testPausation2(ep); - testPausation3(ep); - testPausation4(ep); - //testPausation5(ep); - testWriteFrames(ep); - testAsyncWriteFrame(ep); - } - - { - error_code ec; - ::websocket::async_echo_server server{nullptr, 4}; - server.open(any, ec); - BEAST_EXPECTS(! ec, ec.message()); - auto const ep = server.local_endpoint(); - testAsyncWriteFrame(ep); - } - - auto const doClientTests = - [this, any](permessage_deflate const& pmd) - { - { - error_code ec; - ::websocket::sync_echo_server server{nullptr}; - server.set_option(pmd); - server.open(any, ec); - BEAST_EXPECTS(! ec, ec.message()); - auto const ep = server.local_endpoint(); - testEndpoint(SyncClient{}, ep, pmd); - yield_to( - [&](yield_context yield) - { - testEndpoint( - AsyncClient{yield}, ep, pmd); - }); - } - { - error_code ec; - ::websocket::async_echo_server server{nullptr, 4}; - server.set_option(pmd); - server.open(any, ec); - BEAST_EXPECTS(! ec, ec.message()); - auto const ep = server.local_endpoint(); - testEndpoint(SyncClient{}, ep, pmd); - yield_to( - [&](yield_context yield) - { - testEndpoint( - AsyncClient{yield}, ep, pmd); - }); - } - }; - - pmd.client_enable = false; - pmd.server_enable = false; - doClientTests(pmd); - - #if ! BEAST_NO_SLOW_TESTS - pmd.client_enable = true; - pmd.server_enable = true; - pmd.client_max_window_bits = 10; - pmd.client_no_context_takeover = false; - doClientTests(pmd); - - pmd.client_enable = true; - pmd.server_enable = true; - pmd.client_max_window_bits = 10; - pmd.client_no_context_takeover = true; - doClientTests(pmd); - #endif - } -}; - -BEAST_DEFINE_TESTSUITE(stream,websocket,beast); - -} // websocket -} // beast diff --git a/src/beast/test/websocket/teardown.cpp b/src/beast/test/websocket/teardown.cpp deleted file mode 100644 index e0985f7bf2f..00000000000 --- a/src/beast/test/websocket/teardown.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include diff --git a/src/beast/test/websocket/utf8_checker.cpp b/src/beast/test/websocket/utf8_checker.cpp deleted file mode 100644 index dc01a332589..00000000000 --- a/src/beast/test/websocket/utf8_checker.cpp +++ /dev/null @@ -1,412 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include -#include -#include -#include - -namespace beast { -namespace websocket { -namespace detail { - -class utf8_checker_test : public beast::unit_test::suite -{ -public: - void - testOneByteSequence() - { - utf8_checker utf8; - std::array buf = - ([]() - { - std::array values; - std::uint8_t i = 0; - for(auto& c : values) - c = i++; - return values; - })(); - - // Valid range 0-127 - BEAST_EXPECT(utf8.write(buf.data(), 128)); - BEAST_EXPECT(utf8.finish()); - - // Invalid range 128-193 - for(auto it = std::next(buf.begin(), 128); - it != std::next(buf.begin(), 194); ++it) - BEAST_EXPECT(! utf8.write(&(*it), 1)); - - // Invalid range 245-255 - for(auto it = std::next(buf.begin(), 245); - it != buf.end(); ++it) - BEAST_EXPECT(! utf8.write(&(*it), 1)); - - // Invalid sequence - std::fill(buf.begin(), buf.end(), '\xff'); - BEAST_EXPECT(! utf8.write(&buf.front(), buf.size())); - } - - void - testTwoByteSequence() - { - utf8_checker utf8; - std::uint8_t buf[2]; - for(auto i = 194; i <= 223; ++i) - { - // First byte valid range 194-223 - buf[0] = static_cast(i); - - for(auto j = 128; j <= 191; ++j) - { - // Second byte valid range 128-191 - buf[1] = static_cast(j); - BEAST_EXPECT(utf8.write(buf, 2)); - BEAST_EXPECT(utf8.finish()); - } - - for(auto j = 0; j <= 127; ++j) - { - // Second byte invalid range 0-127 - buf[1] = static_cast(j); - BEAST_EXPECT(! utf8.write(buf, 2)); - } - - for(auto j = 192; j <= 255; ++j) - { - // Second byte invalid range 192-255 - buf[1] = static_cast(j); - BEAST_EXPECT(! utf8.write(buf, 2)); - } - - // Segmented sequence second byte invalid - BEAST_EXPECT(utf8.write(buf, 1)); - BEAST_EXPECT(! utf8.write(&buf[1], 1)); - utf8.reset(); - } - } - - void - testThreeByteSequence() - { - utf8_checker utf8; - std::uint8_t buf[3]; - for(auto i = 224; i <= 239; ++i) - { - // First byte valid range 224-239 - buf[0] = static_cast(i); - - std::int32_t const b = (i == 224 ? 160 : 128); - std::int32_t const e = (i == 237 ? 159 : 191); - for(auto j = b; j <= e; ++j) - { - // Second byte valid range 128-191 or 160-191 or 128-159 - buf[1] = static_cast(j); - - for(auto k = 128; k <= 191; ++k) - { - // Third byte valid range 128-191 - buf[2] = static_cast(k); - BEAST_EXPECT(utf8.write(buf, 3)); - BEAST_EXPECT(utf8.finish()); - // Segmented sequence - BEAST_EXPECT(utf8.write(buf, 1)); - BEAST_EXPECT(utf8.write(&buf[1], 2)); - utf8.reset(); - // Segmented sequence - BEAST_EXPECT(utf8.write(buf, 2)); - BEAST_EXPECT(utf8.write(&buf[2], 1)); - utf8.reset(); - - if (i == 224) - { - for (auto l = 0; l < b; ++l) - { - // Second byte invalid range 0-127 or 0-159 - buf[1] = static_cast(l); - BEAST_EXPECT(! utf8.write(buf, 3)); - if (l > 127) - { - // Segmented sequence second byte invalid - BEAST_EXPECT(! utf8.write(buf, 2)); - utf8.reset(); - } - } - buf[1] = static_cast(j); - } - else if (i == 237) - { - for (auto l = e + 1; l <= 255; ++l) - { - // Second byte invalid range 160-255 or 192-255 - buf[1] = static_cast(l); - BEAST_EXPECT(!utf8.write(buf, 3)); - if (l > 159) - { - // Segmented sequence second byte invalid - BEAST_EXPECT(! utf8.write(buf, 2)); - utf8.reset(); - } - } - buf[1] = static_cast(j); - } - } - - for(auto k = 0; k <= 127; ++k) - { - // Third byte invalid range 0-127 - buf[2] = static_cast(k); - BEAST_EXPECT(! utf8.write(buf, 3)); - } - - for(auto k = 192; k <= 255; ++k) - { - // Third byte invalid range 192-255 - buf[2] = static_cast(k); - BEAST_EXPECT(! utf8.write(buf, 3)); - } - - // Segmented sequence third byte invalid - BEAST_EXPECT(utf8.write(buf, 2)); - BEAST_EXPECT(! utf8.write(&buf[2], 1)); - utf8.reset(); - } - - for(auto j = 0; j < b; ++j) - { - // Second byte invalid range 0-127 or 0-159 - buf[1] = static_cast(j); - BEAST_EXPECT(! utf8.write(buf, 3)); - } - - for(auto j = e + 1; j <= 255; ++j) - { - // Second byte invalid range 160-255 or 192-255 - buf[1] = static_cast(j); - BEAST_EXPECT(! utf8.write(buf, 3)); - } - - // Segmented sequence second byte invalid - BEAST_EXPECT(utf8.write(buf, 1)); - BEAST_EXPECT(! utf8.write(&buf[1], 1)); - utf8.reset(); - } - } - - void - testFourByteSequence() - { - using boost::asio::const_buffers_1; - utf8_checker utf8; - std::uint8_t buf[4]; - for(auto i = 240; i <= 244; ++i) - { - // First byte valid range 240-244 - buf[0] = static_cast(i); - - std::int32_t const b = (i == 240 ? 144 : 128); - std::int32_t const e = (i == 244 ? 143 : 191); - for(auto j = b; j <= e; ++j) - { - // Second byte valid range 144-191 or 128-191 or 128-143 - buf[1] = static_cast(j); - - for(auto k = 128; k <= 191; ++k) - { - // Third byte valid range 128-191 - buf[2] = static_cast(k); - - for(auto n = 128; n <= 191; ++n) - { - // Fourth byte valid range 128-191 - buf[3] = static_cast(n); - BEAST_EXPECT(utf8.write(const_buffers_1{buf, 4})); - BEAST_EXPECT(utf8.finish()); - // Segmented sequence - BEAST_EXPECT(utf8.write(buf, 1)); - BEAST_EXPECT(utf8.write(&buf[1], 3)); - utf8.reset(); - // Segmented sequence - BEAST_EXPECT(utf8.write(buf, 2)); - BEAST_EXPECT(utf8.write(&buf[2], 2)); - utf8.reset(); - // Segmented sequence - BEAST_EXPECT(utf8.write(buf, 3)); - BEAST_EXPECT(utf8.write(&buf[3], 1)); - utf8.reset(); - - if (i == 240) - { - for (auto l = 0; l < b; ++l) - { - // Second byte invalid range 0-127 or 0-143 - buf[1] = static_cast(l); - BEAST_EXPECT(! utf8.write(buf, 4)); - if (l > 127) - { - // Segmented sequence second byte invalid - BEAST_EXPECT(! utf8.write(buf, 2)); - utf8.reset(); - } - } - buf[1] = static_cast(j); - } - else if (i == 244) - { - for (auto l = e + 1; l <= 255; ++l) - { - // Second byte invalid range 144-255 or 192-255 - buf[1] = static_cast(l); - BEAST_EXPECT(! utf8.write(buf, 4)); - if (l > 143) - { - // Segmented sequence second byte invalid - BEAST_EXPECT(! utf8.write(buf, 2)); - utf8.reset(); - } - } - buf[1] = static_cast(j); - } - } - - for(auto n = 0; n <= 127; ++n) - { - // Fourth byte invalid range 0-127 - buf[3] = static_cast(n); - BEAST_EXPECT(! utf8.write(const_buffers_1{buf, 4})); - } - - for(auto n = 192; n <= 255; ++n) - { - // Fourth byte invalid range 192-255 - buf[3] = static_cast(n); - BEAST_EXPECT(! utf8.write(buf, 4)); - } - - // Segmented sequence fourth byte invalid - BEAST_EXPECT(utf8.write(buf, 3)); - BEAST_EXPECT(! utf8.write(&buf[3], 1)); - utf8.reset(); - } - - for(auto k = 0; k <= 127; ++k) - { - // Third byte invalid range 0-127 - buf[2] = static_cast(k); - BEAST_EXPECT(! utf8.write(buf, 4)); - } - - for(auto k = 192; k <= 255; ++k) - { - // Third byte invalid range 192-255 - buf[2] = static_cast(k); - BEAST_EXPECT(! utf8.write(buf, 4)); - } - - // Segmented sequence third byte invalid - BEAST_EXPECT(utf8.write(buf, 2)); - BEAST_EXPECT(! utf8.write(&buf[2], 1)); - utf8.reset(); - } - - for(auto j = 0; j < b; ++j) - { - // Second byte invalid range 0-127 or 0-143 - buf[1] = static_cast(j); - BEAST_EXPECT(! utf8.write(buf, 4)); - } - - for(auto j = e + 1; j <= 255; ++j) - { - // Second byte invalid range 144-255 or 192-255 - buf[1] = static_cast(j); - BEAST_EXPECT(! utf8.write(buf, 4)); - } - - // Segmented sequence second byte invalid - BEAST_EXPECT(utf8.write(buf, 1)); - BEAST_EXPECT(! utf8.write(&buf[1], 1)); - utf8.reset(); - } - - for (auto i = 245; i <= 255; ++i) - { - // First byte invalid range 245-255 - buf[0] = static_cast(i); - BEAST_EXPECT(! utf8.write(buf, 4)); - } - } - - void - testWithStreamBuffer() - { - using namespace boost::asio; - { - // Valid UTF8 encoded text - std::vector> const data{{ - 0x48,0x65,0x69,0x7A,0xC3,0xB6,0x6C,0x72,0xC3,0xBC,0x63,0x6B, - 0x73,0x74,0x6F,0xC3,0x9F,0x61,0x62,0x64,0xC3,0xA4,0x6D,0x70, - 0x66,0x75,0x6E,0x67 - }, { - 0xCE,0x93,0xCE,0xB1,0xCE,0xB6,0xCE,0xAD,0xCE,0xB5,0xCF,0x82, - 0x20,0xCE,0xBA,0xCE,0xB1,0xE1,0xBD,0xB6,0x20,0xCE,0xBC,0xCF, - 0x85,0xCF,0x81,0xCF,0x84,0xCE,0xB9,0xE1,0xBD,0xB2,0xCF,0x82, - 0x20,0xCE,0xB4,0xE1,0xBD,0xB2,0xCE,0xBD,0x20,0xCE,0xB8,0xE1, - 0xBD,0xB0,0x20,0xCE,0xB2,0xCF,0x81,0xE1,0xBF,0xB6,0x20,0xCF, - 0x80,0xCE,0xB9,0xE1,0xBD,0xB0,0x20,0xCF,0x83,0xCF,0x84,0xE1, - 0xBD,0xB8,0x20,0xCF,0x87,0xCF,0x81,0xCF,0x85,0xCF,0x83,0xCE, - 0xB1,0xCF,0x86,0xE1,0xBD,0xB6,0x20,0xCE,0xBE,0xCE,0xAD,0xCF, - 0x86,0xCF,0x89,0xCF,0x84,0xCE,0xBF - }, { - 0xC3,0x81,0x72,0x76,0xC3,0xAD,0x7A,0x74,0xC5,0xB1,0x72,0xC5, - 0x91,0x20,0x74,0xC3,0xBC,0x6B,0xC3,0xB6,0x72,0x66,0xC3,0xBA, - 0x72,0xC3,0xB3,0x67,0xC3,0xA9,0x70 - }, { - 240, 144, 128, 128 - } - }; - utf8_checker utf8; - for(auto const& s : data) - { - static std::size_t constexpr size = 3; - std::size_t n = s.size(); - consuming_buffers< - boost::asio::const_buffers_1> cb{ - boost::asio::const_buffers_1(s.data(), n)}; - multi_buffer b; - while(n) - { - auto const amount = (std::min)(n, size); - b.commit(buffer_copy(b.prepare(amount), cb)); - cb.consume(amount); - n -= amount; - } - BEAST_EXPECT(utf8.write(b.data())); - BEAST_EXPECT(utf8.finish()); - } - } - } - - void run() override - { - testOneByteSequence(); - testTwoByteSequence(); - testThreeByteSequence(); - testFourByteSequence(); - testWithStreamBuffer(); - } -}; - -#if defined(NDEBUG) && ! BEAST_NO_SLOW_TESTS -BEAST_DEFINE_TESTSUITE(utf8_checker,websocket,beast); -#endif - -} // detail -} // websocket -} // beast diff --git a/src/beast/test/websocket/websocket_async_echo_server.hpp b/src/beast/test/websocket/websocket_async_echo_server.hpp deleted file mode 100644 index 9057e3cc562..00000000000 --- a/src/beast/test/websocket/websocket_async_echo_server.hpp +++ /dev/null @@ -1,409 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_WEBSOCKET_ASYNC_ECHO_SERVER_HPP -#define BEAST_WEBSOCKET_ASYNC_ECHO_SERVER_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace websocket { - -/** Asynchronous WebSocket echo client/server -*/ -class async_echo_server -{ -public: - using error_code = beast::error_code; - using address_type = boost::asio::ip::address; - using socket_type = boost::asio::ip::tcp::socket; - using endpoint_type = boost::asio::ip::tcp::endpoint; - -private: - /** A container of type-erased option setters. - */ - template - class options_set - { - // workaround for std::function bug in msvc - struct callable - { - virtual ~callable() = default; - virtual void operator()( - beast::websocket::stream&) = 0; - }; - - template - class callable_impl : public callable - { - T t_; - - public: - template - callable_impl(U&& u) - : t_(std::forward(u)) - { - } - - void - operator()(beast::websocket::stream& ws) - { - t_(ws); - } - }; - - template - class lambda - { - Opt opt_; - - public: - lambda(lambda&&) = default; - lambda(lambda const&) = default; - - lambda(Opt const& opt) - : opt_(opt) - { - } - - void - operator()(beast::websocket::stream& ws) const - { - ws.set_option(opt_); - } - }; - - std::unordered_map> list_; - - public: - template - void - set_option(Opt const& opt) - { - std::unique_ptr p; - p.reset(new callable_impl>{opt}); - list_[std::type_index{ - typeid(Opt)}] = std::move(p); - } - - void - set_options(beast::websocket::stream& ws) - { - for(auto const& op : list_) - (*op.second)(ws); - } - }; - - std::ostream* log_; - boost::asio::io_service ios_; - socket_type sock_; - endpoint_type ep_; - boost::asio::ip::tcp::acceptor acceptor_; - std::vector thread_; - boost::optional work_; - options_set opts_; - -public: - async_echo_server(async_echo_server const&) = delete; - async_echo_server& operator=(async_echo_server const&) = delete; - - /** Constructor. - - @param log A pointer to a stream to log to, or `nullptr` - to disable logging. - - @param threads The number of threads in the io_service. - */ - async_echo_server(std::ostream* log, - std::size_t threads) - : log_(log) - , sock_(ios_) - , acceptor_(ios_) - , work_(ios_) - { - thread_.reserve(threads); - for(std::size_t i = 0; i < threads; ++i) - thread_.emplace_back( - [&]{ ios_.run(); }); - } - - /** Destructor. - */ - ~async_echo_server() - { - work_ = boost::none; - error_code ec; - ios_.dispatch( - [&]{ acceptor_.close(ec); }); - for(auto& t : thread_) - t.join(); - } - - /** Return the listening endpoint. - */ - endpoint_type - local_endpoint() const - { - return acceptor_.local_endpoint(); - } - - /** Set a websocket option. - - The option will be applied to all new connections. - - @param opt The option to apply. - */ - template - void - set_option(Opt const& opt) - { - opts_.set_option(opt); - } - - /** Open a listening port. - - @param ep The address and port to bind to. - - @param ec Set to the error, if any occurred. - */ - void - open(endpoint_type const& ep, error_code& ec) - { - acceptor_.open(ep.protocol(), ec); - if(ec) - return fail("open", ec); - acceptor_.set_option( - boost::asio::socket_base::reuse_address{true}); - acceptor_.bind(ep, ec); - if(ec) - return fail("bind", ec); - acceptor_.listen( - boost::asio::socket_base::max_connections, ec); - if(ec) - return fail("listen", ec); - acceptor_.async_accept(sock_, ep_, - std::bind(&async_echo_server::on_accept, this, - std::placeholders::_1)); - } - -private: - class peer - { - struct data - { - async_echo_server& server; - endpoint_type ep; - int state = 0; - beast::websocket::stream ws; - boost::asio::io_service::strand strand; - beast::multi_buffer db; - std::size_t id; - - data(async_echo_server& server_, - endpoint_type const& ep_, - socket_type&& sock_) - : server(server_) - , ep(ep_) - , ws(std::move(sock_)) - , strand(ws.get_io_service()) - , id([] - { - static std::atomic n{0}; - return ++n; - }()) - { - } - }; - - // VFALCO This could be unique_ptr in [Net.TS] - std::shared_ptr d_; - - public: - peer(peer&&) = default; - peer(peer const&) = default; - peer& operator=(peer&&) = delete; - peer& operator=(peer const&) = delete; - - template - explicit - peer(async_echo_server& server, - endpoint_type const& ep, socket_type&& sock, - Args&&... args) - : d_(std::make_shared(server, ep, - std::forward(sock), - std::forward(args)...)) - { - auto& d = *d_; - d.server.opts_.set_options(d.ws); - run(); - } - - void run() - { - auto& d = *d_; - d.ws.async_accept_ex( - [](beast::websocket::response_type& res) - { - res.insert( - "Server", "async_echo_server"); - }, - std::move(*this)); - } - - template - static - bool - match(DynamicBuffer& db, char const(&s)[N]) - { - using boost::asio::buffer; - using boost::asio::buffer_copy; - if(db.size() < N-1) - return false; - beast::static_string t; - t.resize(N-1); - buffer_copy(buffer(t.data(), t.size()), - db.data()); - if(t != s) - return false; - db.consume(N-1); - return true; - } - - void operator()(error_code ec, std::size_t) - { - (*this)(ec); - } - - void operator()(error_code ec) - { - using boost::asio::buffer; - using boost::asio::buffer_copy; - auto& d = *d_; - switch(d.state) - { - // did accept - case 0: - if(ec) - return fail("async_accept", ec); - - // start - case 1: - if(ec) - return fail("async_handshake", ec); - d.db.consume(d.db.size()); - // read message - d.state = 2; - d.ws.async_read(d.db, - d.strand.wrap(std::move(*this))); - return; - - // got message - case 2: - if(ec == beast::websocket::error::closed) - return; - if(ec) - return fail("async_read", ec); - if(match(d.db, "RAW")) - { - d.state = 1; - boost::asio::async_write(d.ws.next_layer(), - d.db.data(), d.strand.wrap(std::move(*this))); - return; - } - else if(match(d.db, "TEXT")) - { - d.state = 1; - d.ws.binary(false); - d.ws.async_write( - d.db.data(), d.strand.wrap(std::move(*this))); - return; - } - else if(match(d.db, "PING")) - { - beast::websocket::ping_data payload; - d.db.consume(buffer_copy( - buffer(payload.data(), payload.size()), - d.db.data())); - d.state = 1; - d.ws.async_ping(payload, - d.strand.wrap(std::move(*this))); - return; - } - else if(match(d.db, "CLOSE")) - { - d.state = 1; - d.ws.async_close({}, - d.strand.wrap(std::move(*this))); - return; - } - // write message - d.state = 1; - d.ws.binary(d.ws.got_binary()); - d.ws.async_write(d.db.data(), - d.strand.wrap(std::move(*this))); - return; - } - } - - private: - void - fail(std::string what, error_code ec) - { - auto& d = *d_; - if(d.server.log_) - if(ec != beast::websocket::error::closed) - d.server.fail("[#" + std::to_string(d.id) + - " " + boost::lexical_cast(d.ep) + - "] " + what, ec); - } - }; - - void - fail(std::string what, error_code ec) - { - if(log_) - { - static std::mutex m; - std::lock_guard lock{m}; - (*log_) << what << ": " << - ec.message() << std::endl; - } - } - - void - on_accept(error_code ec) - { - if(! acceptor_.is_open()) - return; - if(ec == boost::asio::error::operation_aborted) - return; - if(ec) - fail("accept", ec); - peer{*this, ep_, std::move(sock_)}; - acceptor_.async_accept(sock_, ep_, - std::bind(&async_echo_server::on_accept, this, - std::placeholders::_1)); - } -}; - -} // websocket - -#endif diff --git a/src/beast/test/websocket/websocket_sync_echo_server.hpp b/src/beast/test/websocket/websocket_sync_echo_server.hpp deleted file mode 100644 index ab4384e9adf..00000000000 --- a/src/beast/test/websocket/websocket_sync_echo_server.hpp +++ /dev/null @@ -1,353 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_WEBSOCKET_SYNC_ECHO_SERVER_HPP -#define BEAST_WEBSOCKET_SYNC_ECHO_SERVER_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace websocket { - -/** Synchronous WebSocket echo client/server -*/ -class sync_echo_server -{ -public: - using error_code = beast::error_code; - using endpoint_type = boost::asio::ip::tcp::endpoint; - using address_type = boost::asio::ip::address; - using socket_type = boost::asio::ip::tcp::socket; - -private: - /** A container of type-erased option setters. - */ - template - class options_set - { - // workaround for std::function bug in msvc - struct callable - { - virtual ~callable() = default; - virtual void operator()( - beast::websocket::stream&) = 0; - }; - - template - class callable_impl : public callable - { - T t_; - - public: - template - callable_impl(U&& u) - : t_(std::forward(u)) - { - } - - void - operator()(beast::websocket::stream& ws) - { - t_(ws); - } - }; - - template - class lambda - { - Opt opt_; - - public: - lambda(lambda&&) = default; - lambda(lambda const&) = default; - - lambda(Opt const& opt) - : opt_(opt) - { - } - - void - operator()(beast::websocket::stream& ws) const - { - ws.set_option(opt_); - } - }; - - std::unordered_map> list_; - - public: - template - void - set_option(Opt const& opt) - { - std::unique_ptr p; - p.reset(new callable_impl>{opt}); - list_[std::type_index{ - typeid(Opt)}] = std::move(p); - } - - void - set_options(beast::websocket::stream& ws) - { - for(auto const& op : list_) - (*op.second)(ws); - } - }; - - std::ostream* log_; - boost::asio::io_service ios_; - socket_type sock_; - endpoint_type ep_; - boost::asio::ip::tcp::acceptor acceptor_; - std::thread thread_; - options_set opts_; - -public: - /** Constructor. - - @param log A pointer to a stream to log to, or `nullptr` - to disable logging. - */ - sync_echo_server(std::ostream* log) - : log_(log) - , sock_(ios_) - , acceptor_(ios_) - { - } - - /** Destructor. - */ - ~sync_echo_server() - { - if(thread_.joinable()) - { - error_code ec; - ios_.dispatch( - [&]{ acceptor_.close(ec); }); - thread_.join(); - } - } - - /** Return the listening endpoint. - */ - endpoint_type - local_endpoint() const - { - return acceptor_.local_endpoint(); - } - - /** Set a websocket option. - - The option will be applied to all new connections. - - @param opt The option to apply. - */ - template - void - set_option(Opt const& opt) - { - opts_.set_option(opt); - } - - /** Open a listening port. - - @param ep The address and port to bind to. - - @param ec Set to the error, if any occurred. - */ - void - open(endpoint_type const& ep, error_code& ec) - { - acceptor_.open(ep.protocol(), ec); - if(ec) - return fail("open", ec); - acceptor_.set_option( - boost::asio::socket_base::reuse_address{true}); - acceptor_.bind(ep, ec); - if(ec) - return fail("bind", ec); - acceptor_.listen( - boost::asio::socket_base::max_connections, ec); - if(ec) - return fail("listen", ec); - acceptor_.async_accept(sock_, ep_, - std::bind(&sync_echo_server::on_accept, this, - std::placeholders::_1)); - thread_ = std::thread{[&]{ ios_.run(); }}; - } - -private: - void - fail(std::string what, error_code ec) - { - if(log_) - { - static std::mutex m; - std::lock_guard lock{m}; - (*log_) << what << ": " << - ec.message() << std::endl; - } - } - - void - fail(std::string what, error_code ec, - std::size_t id, endpoint_type const& ep) - { - if(log_) - if(ec != beast::websocket::error::closed) - fail("[#" + std::to_string(id) + " " + - boost::lexical_cast(ep) + - "] " + what, ec); - } - - void - on_accept(error_code ec) - { - if(ec == boost::asio::error::operation_aborted) - return; - if(ec) - return fail("accept", ec); - struct lambda - { - std::size_t id; - endpoint_type ep; - sync_echo_server& self; - boost::asio::io_service::work work; - // Must be destroyed before work otherwise the - // io_service could be destroyed before the socket. - socket_type sock; - - lambda(sync_echo_server& self_, - endpoint_type const& ep_, - socket_type&& sock_) - : id([] - { - static std::atomic n{0}; - return ++n; - }()) - , ep(ep_) - , self(self_) - , work(sock_.get_io_service()) - , sock(std::move(sock_)) - { - } - - void operator()() - { - self.do_peer(id, ep, std::move(sock)); - } - }; - std::thread{lambda{*this, ep_, std::move(sock_)}}.detach(); - acceptor_.async_accept(sock_, ep_, - std::bind(&sync_echo_server::on_accept, this, - std::placeholders::_1)); - } - - template - static - bool - match(DynamicBuffer& db, char const(&s)[N]) - { - using boost::asio::buffer; - using boost::asio::buffer_copy; - if(db.size() < N-1) - return false; - beast::static_string t; - t.resize(N-1); - buffer_copy(buffer(t.data(), t.size()), - db.data()); - if(t != s) - return false; - db.consume(N-1); - return true; - } - - void - do_peer(std::size_t id, - endpoint_type const& ep, socket_type&& sock) - { - using boost::asio::buffer; - using boost::asio::buffer_copy; - beast::websocket::stream< - socket_type> ws{std::move(sock)}; - opts_.set_options(ws); - error_code ec; - ws.accept_ex( - [](beast::websocket::response_type& res) - { - res.insert( - "Server", "sync_echo_server"); - }, - ec); - if(ec) - { - fail("accept", ec, id, ep); - return; - } - for(;;) - { - beast::multi_buffer b; - ws.read(b, ec); - if(ec) - { - auto const s = ec.message(); - break; - } - ws.binary(ws.got_binary()); - if(match(b, "RAW")) - { - boost::asio::write( - ws.next_layer(), b.data(), ec); - } - else if(match(b, "TEXT")) - { - ws.binary(false); - ws.write(b.data(), ec); - } - else if(match(b, "PING")) - { - beast::websocket::ping_data payload; - b.consume(buffer_copy( - buffer(payload.data(), payload.size()), - b.data())); - ws.ping(payload, ec); - } - else if(match(b, "CLOSE")) - { - ws.close({}, ec); - } - else - { - ws.write(b.data(), ec); - } - if(ec) - break; - } - if(ec && ec != beast::websocket::error::closed) - { - fail("read", ec, id, ep); - } - } -}; - -} // websocket - -#endif diff --git a/src/beast/test/zlib.cpp b/src/beast/test/zlib.cpp deleted file mode 100644 index 10db45cb182..00000000000 --- a/src/beast/test/zlib.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include diff --git a/src/beast/test/zlib/CMakeLists.txt b/src/beast/test/zlib/CMakeLists.txt deleted file mode 100644 index 6d3c6f507e9..00000000000 --- a/src/beast/test/zlib/CMakeLists.txt +++ /dev/null @@ -1,50 +0,0 @@ -# Part of Beast - -GroupSources(extras/beast extras) -GroupSources(include/beast beast) - -GroupSources(test/zlib "/") - -set(ZLIB_SOURCES - ${CMAKE_CURRENT_LIST_DIR}/zlib-1.2.8/crc32.h - ${CMAKE_CURRENT_LIST_DIR}/zlib-1.2.8/deflate.h - ${CMAKE_CURRENT_LIST_DIR}/zlib-1.2.8/inffast.h - ${CMAKE_CURRENT_LIST_DIR}/zlib-1.2.8/inffixed.h - ${CMAKE_CURRENT_LIST_DIR}/zlib-1.2.8/inflate.h - ${CMAKE_CURRENT_LIST_DIR}/zlib-1.2.8/inftrees.h - ${CMAKE_CURRENT_LIST_DIR}/zlib-1.2.8/trees.h - ${CMAKE_CURRENT_LIST_DIR}/zlib-1.2.8/zlib.h - ${CMAKE_CURRENT_LIST_DIR}/zlib-1.2.8/zutil.h - ${CMAKE_CURRENT_LIST_DIR}/zlib-1.2.8/adler32.c - ${CMAKE_CURRENT_LIST_DIR}/zlib-1.2.8/compress.c - ${CMAKE_CURRENT_LIST_DIR}/zlib-1.2.8/crc32.c - ${CMAKE_CURRENT_LIST_DIR}/zlib-1.2.8/deflate.c - ${CMAKE_CURRENT_LIST_DIR}/zlib-1.2.8/infback.c - ${CMAKE_CURRENT_LIST_DIR}/zlib-1.2.8/inffast.c - ${CMAKE_CURRENT_LIST_DIR}/zlib-1.2.8/inflate.c - ${CMAKE_CURRENT_LIST_DIR}/zlib-1.2.8/inftrees.c - ${CMAKE_CURRENT_LIST_DIR}/zlib-1.2.8/trees.c - ${CMAKE_CURRENT_LIST_DIR}/zlib-1.2.8/uncompr.c - ${CMAKE_CURRENT_LIST_DIR}/zlib-1.2.8/zutil.c -) - -if (MSVC) - set_source_files_properties (${ZLIB_SOURCES} PROPERTIES COMPILE_FLAGS "/wd4127 /wd4131 /wd4244") -endif() - -add_executable (zlib-tests - ${BEAST_INCLUDES} - ${EXTRAS_INCLUDES} - ${ZLIB_SOURCES} - ../../extras/beast/unit_test/main.cpp - ztest.hpp - deflate_stream.cpp - error.cpp - inflate_stream.cpp -) - -target_link_libraries(zlib-tests - Beast - ${Boost_PROGRAM_OPTIONS_LIBRARY} - ${Boost_FILESYSTEM_LIBRARY} - ) diff --git a/src/beast/test/zlib/Jamfile b/src/beast/test/zlib/Jamfile deleted file mode 100644 index deea895cc09..00000000000 --- a/src/beast/test/zlib/Jamfile +++ /dev/null @@ -1,24 +0,0 @@ -# -# Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -# -# 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) -# - -unit-test zlib-tests : - ../../extras/beast/unit_test/main.cpp - zlib-1.2.8/adler32.c - zlib-1.2.8/compress.c - zlib-1.2.8/crc32.c - zlib-1.2.8/deflate.c - zlib-1.2.8/infback.c - zlib-1.2.8/inffast.c - zlib-1.2.8/inflate.c - zlib-1.2.8/inftrees.c - zlib-1.2.8/trees.c - zlib-1.2.8/uncompr.c - zlib-1.2.8/zutil.c - deflate_stream.cpp - error.cpp - inflate_stream.cpp - ; diff --git a/src/beast/test/zlib/deflate_stream.cpp b/src/beast/test/zlib/deflate_stream.cpp deleted file mode 100644 index c1b2b38f58a..00000000000 --- a/src/beast/test/zlib/deflate_stream.cpp +++ /dev/null @@ -1,338 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include "ztest.hpp" -#include - -namespace beast { -namespace zlib { - -class deflate_stream_test : public beast::unit_test::suite -{ -public: - using self = deflate_stream_test; - typedef void(self::*pmf_t)( - int level, int windowBits, int strategy, - std::string const&); - - static - Strategy - toStrategy(int strategy) - { - switch(strategy) - { - default: - case 0: return Strategy::normal; - case 1: return Strategy::filtered; - case 2: return Strategy::huffman; - case 3: return Strategy::rle; - case 4: return Strategy::fixed; - } - } - - void - doDeflate1_zlib( - int level, int windowBits, int strategy, - std::string const& check) - { - int result; - std::string out; - ::z_stream zs; - std::memset(&zs, 0, sizeof(zs)); - result = deflateInit2(&zs, - level, - Z_DEFLATED, - -windowBits, - 8, - strategy); - if(! BEAST_EXPECT(result == Z_OK)) - goto err; - out.resize(deflateBound(&zs, - static_cast(check.size()))); - zs.next_in = (Bytef*)check.data(); - zs.avail_in = static_cast(check.size()); - zs.next_out = (Bytef*)out.data(); - zs.avail_out = static_cast(out.size()); - { - bool progress = true; - for(;;) - { - result = deflate(&zs, Z_FULL_FLUSH); - if( result == Z_BUF_ERROR || - result == Z_STREAM_END) // per zlib FAQ - goto fin; - if(! BEAST_EXPECT(progress)) - goto err; - progress = false; - } - } - - fin: - out.resize(zs.total_out); - { - z_inflator zi; - auto const s = zi(out); - BEAST_EXPECT(s == check); - } - - err: - deflateEnd(&zs); - } - - void - doDeflate1_beast( - int level, int windowBits, int strategy, - std::string const& check) - { - std::string out; - z_params zs; - deflate_stream ds; - ds.reset( - level, - windowBits, - 8, - toStrategy(strategy)); - out.resize(ds.upper_bound( - static_cast(check.size()))); - zs.next_in = (Bytef*)check.data(); - zs.avail_in = static_cast(check.size()); - zs.next_out = (Bytef*)out.data(); - zs.avail_out = static_cast(out.size()); - { - bool progress = true; - for(;;) - { - error_code ec; - ds.write(zs, Flush::full, ec); - if( ec == error::need_buffers || - ec == error::end_of_stream) // per zlib FAQ - goto fin; - if(! BEAST_EXPECTS(! ec, ec.message())) - goto err; - if(! BEAST_EXPECT(progress)) - goto err; - progress = false; - } - } - - fin: - out.resize(zs.total_out); - { - z_inflator zi; - auto const s = zi(out); - BEAST_EXPECT(s == check); - } - - err: - ; - } - - //-------------------------------------------------------------------------- - - void - doDeflate2_zlib( - int level, int windowBits, int strategy, - std::string const& check) - { - for(std::size_t i = 1; i < check.size(); ++i) - { - for(std::size_t j = 1;; ++j) - { - int result; - ::z_stream zs; - std::memset(&zs, 0, sizeof(zs)); - result = deflateInit2(&zs, - level, - Z_DEFLATED, - -windowBits, - 8, - strategy); - if(! BEAST_EXPECT(result == Z_OK)) - continue; - std::string out; - out.resize(deflateBound(&zs, - static_cast(check.size()))); - if(j >= out.size()) - { - deflateEnd(&zs); - break; - } - zs.next_in = (Bytef*)check.data(); - zs.avail_in = static_cast(i); - zs.next_out = (Bytef*)out.data(); - zs.avail_out = static_cast(j); - bool bi = false; - bool bo = false; - for(;;) - { - int flush = bi ? Z_FULL_FLUSH : Z_NO_FLUSH; - result = deflate(&zs, flush); - if( result == Z_BUF_ERROR || - result == Z_STREAM_END) // per zlib FAQ - goto fin; - if(! BEAST_EXPECT(result == Z_OK)) - goto err; - if(zs.avail_in == 0 && ! bi) - { - bi = true; - zs.avail_in = - static_cast(check.size() - i); - } - if(zs.avail_out == 0 && ! bo) - { - bo = true; - zs.avail_out = - static_cast(out.size() - j); - } - } - - fin: - out.resize(zs.total_out); - { - z_inflator zi; - auto const s = zi(out); - BEAST_EXPECT(s == check); - } - - err: - deflateEnd(&zs); - } - } - } - - void - doDeflate2_beast( - int level, int windowBits, int strategy, - std::string const& check) - { - for(std::size_t i = 1; i < check.size(); ++i) - { - for(std::size_t j = 1;; ++j) - { - z_params zs; - deflate_stream ds; - ds.reset( - level, - windowBits, - 8, - toStrategy(strategy)); - std::string out; - out.resize(ds.upper_bound( - static_cast(check.size()))); - if(j >= out.size()) - break; - zs.next_in = (Bytef*)check.data(); - zs.avail_in = static_cast(i); - zs.next_out = (Bytef*)out.data(); - zs.avail_out = static_cast(j); - bool bi = false; - bool bo = false; - for(;;) - { - error_code ec; - ds.write(zs, - bi ? Flush::full : Flush::none, ec); - if( ec == error::need_buffers || - ec == error::end_of_stream) // per zlib FAQ - goto fin; - if(! BEAST_EXPECTS(! ec, ec.message())) - goto err; - if(zs.avail_in == 0 && ! bi) - { - bi = true; - zs.avail_in = - static_cast(check.size() - i); - } - if(zs.avail_out == 0 && ! bo) - { - bo = true; - zs.avail_out = - static_cast(out.size() - j); - } - } - - fin: - out.resize(zs.total_out); - { - z_inflator zi; - auto const s = zi(out); - BEAST_EXPECT(s == check); - } - - err: - ; - } - } - } - - //-------------------------------------------------------------------------- - - void - doMatrix(std::string const& label, - std::string const& check, pmf_t pmf) - { - using namespace std::chrono; - using clock_type = steady_clock; - auto const when = clock_type::now(); - for(int level = 0; level <= 9; ++level) - { - for(int windowBits = 8; windowBits <= 9; ++windowBits) - { - for(int strategy = 0; strategy <= 4; ++strategy) - { - (this->*pmf)( - level, windowBits, strategy, check); - } - } - } - auto const elapsed = clock_type::now() - when; - log << - label << ": " << - duration_cast< - milliseconds>(elapsed).count() << "ms\n"; - log.flush(); - } - - void - testDeflate() - { - doMatrix("1.beast ", "Hello, world!", &self::doDeflate1_beast); - doMatrix("1.zlib ", "Hello, world!", &self::doDeflate1_zlib); - #if ! BEAST_NO_SLOW_TESTS - doMatrix("2.beast ", "Hello, world!", &self::doDeflate2_beast); - doMatrix("2.zlib ", "Hello, world!", &self::doDeflate2_zlib); - { - auto const s = corpus1(56); - doMatrix("3.beast ", s, &self::doDeflate2_beast); - doMatrix("3.zlib ", s, &self::doDeflate2_zlib); - } - { - auto const s = corpus1(512 * 1024); - doMatrix("4.beast ", s, &self::doDeflate1_beast); - doMatrix("4.zlib ", s, &self::doDeflate1_zlib); - } - #endif - } - - void - run() override - { - log << - "sizeof(deflate_stream) == " << - sizeof(deflate_stream) << std::endl; - - testDeflate(); - } -}; - -BEAST_DEFINE_TESTSUITE(deflate_stream,core,beast); - -} // zlib -} // beast diff --git a/src/beast/test/zlib/error.cpp b/src/beast/test/zlib/error.cpp deleted file mode 100644 index eb40185dfb5..00000000000 --- a/src/beast/test/zlib/error.cpp +++ /dev/null @@ -1,61 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include -#include - -namespace beast { -namespace zlib { - -class error_test : public unit_test::suite -{ -public: - void check(char const* name, error ev) - { - auto const ec = make_error_code(ev); - BEAST_EXPECT(std::string{ec.category().name()} == name); - BEAST_EXPECT(! ec.message().empty()); - BEAST_EXPECT(std::addressof(ec.category()) == - std::addressof(detail::get_error_category())); - BEAST_EXPECT(detail::get_error_category().equivalent( - static_cast::type>(ev), - ec.category().default_error_condition( - static_cast::type>(ev)))); - BEAST_EXPECT(detail::get_error_category().equivalent( - ec, static_cast::type>(ev))); - } - - void run() override - { - check("beast.zlib", error::need_buffers); - check("beast.zlib", error::end_of_stream); - check("beast.zlib", error::stream_error); - - check("beast.zlib", error::invalid_block_type); - check("beast.zlib", error::invalid_stored_length); - check("beast.zlib", error::too_many_symbols); - check("beast.zlib", error::invalid_code_lenths); - check("beast.zlib", error::invalid_bit_length_repeat); - check("beast.zlib", error::missing_eob); - check("beast.zlib", error::invalid_literal_length); - check("beast.zlib", error::invalid_distance_code); - check("beast.zlib", error::invalid_distance); - - check("beast.zlib", error::over_subscribed_length); - check("beast.zlib", error::incomplete_length_set); - - check("beast.zlib", error::general); - } -}; - -BEAST_DEFINE_TESTSUITE(error,zlib,beast); - -} // zlib -} // beast diff --git a/src/beast/test/zlib/inflate_stream.cpp b/src/beast/test/zlib/inflate_stream.cpp deleted file mode 100644 index 1af12d7f886..00000000000 --- a/src/beast/test/zlib/inflate_stream.cpp +++ /dev/null @@ -1,415 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -// Test that header file is self-contained. -#include - -#include "ztest.hpp" -#include -#include -#include - -namespace beast { -namespace zlib { - -class inflate_stream_test : public beast::unit_test::suite -{ -public: - //-------------------------------------------------------------------------- - - enum Split - { - once, - half, - full - }; - - class Beast - { - Split in_; - Split check_; - Flush flush_; - - public: - Beast(Split in, Split check, Flush flush = Flush::sync) - : in_(in) - , check_(check) - , flush_(flush) - { - } - - void - operator()( - int window, - std::string const& in, - std::string const& check, - unit_test::suite& suite) const - { - auto const f = - [&](std::size_t i, std::size_t j) - { - std::string out(check.size(), 0); - z_params zs; - zs.next_in = in.data(); - zs.next_out = &out[0]; - zs.avail_in = i; - zs.avail_out = j; - inflate_stream is; - is.reset(window); - bool bi = ! (i < in.size()); - bool bo = ! (j < check.size()); - for(;;) - { - error_code ec; - is.write(zs, flush_, ec); - if( ec == error::need_buffers || - ec == error::end_of_stream) - { - out.resize(zs.total_out); - suite.expect(out == check, __FILE__, __LINE__); - break; - } - if(ec) - { - suite.fail(ec.message(), __FILE__, __LINE__); - break; - } - if(zs.avail_in == 0 && ! bi) - { - bi = true; - zs.avail_in = in.size() - i; - } - if(zs.avail_out == 0 && ! bo) - { - bo = true; - zs.avail_out = check.size() - j; - } - } - }; - - std::size_t i0, i1; - std::size_t j0, j1; - - switch(in_) - { - default: - case once: i0 = in.size(); i1 = i0; break; - case half: i0 = in.size() / 2; i1 = i0; break; - case full: i0 = 1; i1 = in.size(); break; - } - - switch(check_) - { - default: - case once: j0 = check.size(); j1 = j0; break; - case half: j0 = check.size() / 2; j1 = j0; break; - case full: j0 = 1; j1 = check.size(); break; - } - - for(std::size_t i = i0; i <= i1; ++i) - for(std::size_t j = j0; j <= j1; ++j) - f(i, j); - } - }; - - class ZLib - { - Split in_; - Split check_; - int flush_; - - public: - ZLib(Split in, Split check, int flush = Z_SYNC_FLUSH) - : in_(in) - , check_(check) - , flush_(flush) - { - } - - void - operator()( - int window, - std::string const& in, - std::string const& check, - unit_test::suite& suite) const - { - auto const f = - [&](std::size_t i, std::size_t j) - { - int result; - std::string out(check.size(), 0); - ::z_stream zs; - memset(&zs, 0, sizeof(zs)); - result = inflateInit2(&zs, -window); - if(result != Z_OK) - { - suite.fail("! Z_OK", __FILE__, __LINE__); - return; - } - zs.next_in = (Bytef*)in.data(); - zs.next_out = (Bytef*)out.data(); - zs.avail_in = static_cast(i); - zs.avail_out = static_cast(j); - bool bi = ! (i < in.size()); - bool bo = ! (j < check.size()); - for(;;) - { - result = inflate(&zs, flush_); - if( result == Z_BUF_ERROR || - result == Z_STREAM_END) // per zlib FAQ - { - out.resize(zs.total_out); - suite.expect(out == check, __FILE__, __LINE__); - break; - } - if(result != Z_OK) - { - suite.fail("! Z_OK", __FILE__, __LINE__); - break; - } - if(zs.avail_in == 0 && ! bi) - { - bi = true; - zs.avail_in = static_cast(in.size() - i); - } - if(zs.avail_out == 0 && ! bo) - { - bo = true; - zs.avail_out = static_cast(check.size() - j); - } - } - inflateEnd(&zs); - }; - - std::size_t i0, i1; - std::size_t j0, j1; - - switch(in_) - { - default: - case once: i0 = in.size(); i1 = i0; break; - case half: i0 = in.size() / 2; i1 = i0; break; - case full: i0 = 1; i1 = in.size(); break; - } - - switch(check_) - { - default: - case once: j0 = check.size(); j1 = j0; break; - case half: j0 = check.size() / 2; j1 = j0; break; - case full: j0 = 1; j1 = check.size(); break; - } - - for(std::size_t i = i0; i <= i1; ++i) - for(std::size_t j = j0; j <= j1; ++j) - f(i, j); - } - }; - - class Matrix - { - unit_test::suite& suite_; - - int level_[2]; - int window_[2]; - int strategy_[2]; - - public: - explicit - Matrix(unit_test::suite& suite) - : suite_(suite) - { - level_[0] = 0; - level_[1] = 9; - window_[0] = 8; - window_[1] = 15; - strategy_[0] = 0; - strategy_[1] = 4; - } - - void - level(int from, int to) - { - level_[0] = from; - level_[1] = to; - } - - void - level(int what) - { - level(what, what); - } - - void - window(int from, int to) - { - window_[0] = from; - window_[1] = to; - } - - void - window(int what) - { - window(what, what); - } - - void - strategy(int from, int to) - { - strategy_[0] = from; - strategy_[1] = to; - } - - void - strategy(int what) - { - strategy(what, what); - } - - template - void - operator()( - std::string label, - F const& f, - std::string const& check) const - { - using namespace std::chrono; - using clock_type = steady_clock; - auto const when = clock_type::now(); - - for(auto level = level_[0]; - level <= level_[1]; ++level) - { - for(auto window = window_[0]; - window <= window_[1]; ++window) - { - for(auto strategy = strategy_[0]; - strategy <= strategy_[1]; ++strategy) - { - z_deflator zd; - zd.level(level); - zd.windowBits(window); - zd.strategy(strategy); - auto const in = zd(check); - f(window, in, check, suite_); - } - } - } - auto const elapsed = clock_type::now() - when; - suite_.log << - label << ": " << - duration_cast< - milliseconds>(elapsed).count() << "ms\n"; - suite_.log.flush(); - } - }; - - void - testInflate() - { - { - Matrix m{*this}; - std::string check = - "{\n \"AutobahnPython/0.6.0\": {\n" - " \"1.1.1\": {\n" - " \"behavior\": \"OK\",\n" - " \"behaviorClose\": \"OK\",\n" - " \"duration\": 2,\n" - " \"remoteCloseCode\": 1000,\n" - " \"reportfile\": \"autobahnpython_0_6_0_case_1_1_1.json\"\n" - ; - m("1. beast", Beast{half, half}, check); - m("1. zlib ", ZLib {half, half}, check); - } - - #if ! BEAST_NO_SLOW_TESTS - { - Matrix m{*this}; - auto const check = corpus1(50000); - m("2. beast", Beast{half, half}, check); - m("2. zlib ", ZLib {half, half}, check); - } - { - Matrix m{*this}; - auto const check = corpus2(50000); - m("3. beast", Beast{half, half}, check); - m("3. zlib ", ZLib {half, half}, check); - } - { - Matrix m{*this}; - auto const check = corpus1(10000); - m.level(6); - m.window(9); - m.strategy(Z_DEFAULT_STRATEGY); - m("4. beast", Beast{once, full}, check); - m("4. zlib ", ZLib {once, full}, check); - } - { - Matrix m{*this}; - auto const check = corpus2(10000); - m.level(6); - m.window(9); - m.strategy(Z_DEFAULT_STRATEGY); - m("5. beast", Beast{once, full}, check); - m("5. zlib ", ZLib {once, full}, check); - } - { - Matrix m{*this}; - m.level(6); - m.window(9); - auto const check = corpus1(200); - m("6. beast", Beast{full, full}, check); - m("6. zlib ", ZLib {full, full}, check); - } - { - Matrix m{*this}; - m.level(6); - m.window(9); - auto const check = corpus2(500); - m("7. beast", Beast{full, full}, check); - m("7. zlib ", ZLib {full, full}, check); - } - { - Matrix m{*this}; - auto const check = corpus2(10000); - m.level(6); - m.window(9); - m.strategy(Z_DEFAULT_STRATEGY); - m("8. beast", Beast{full, once, Flush::block}, check); - m("8. zlib ", ZLib {full, once, Z_BLOCK}, check); - } - #endif - - // VFALCO Fails, but I'm unsure of what the correct - // behavior of Z_TREES/Flush::trees is. -#if 0 - { - Matrix m{*this}; - auto const check = corpus2(10000); - m.level(6); - m.window(9); - m.strategy(Z_DEFAULT_STRATEGY); - m("9. beast", Beast{full, once, Flush::trees}, check); - m("9. zlib ", ZLib {full, once, Z_TREES}, check); - } -#endif - } - - void - run() override - { - log << - "sizeof(inflate_stream) == " << - sizeof(inflate_stream) << std::endl; - testInflate(); - } -}; - -BEAST_DEFINE_TESTSUITE(inflate_stream,core,beast); - -} // zlib -} // beast diff --git a/src/beast/test/zlib/zlib-1.2.8/CMakeLists.txt b/src/beast/test/zlib/zlib-1.2.8/CMakeLists.txt deleted file mode 100644 index 0c0247cc516..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/CMakeLists.txt +++ /dev/null @@ -1,249 +0,0 @@ -cmake_minimum_required(VERSION 2.4.4) -set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON) - -project(zlib C) - -set(VERSION "1.2.8") - -option(ASM686 "Enable building i686 assembly implementation") -option(AMD64 "Enable building amd64 assembly implementation") - -set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables") -set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries") -set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers") -set(INSTALL_MAN_DIR "${CMAKE_INSTALL_PREFIX}/share/man" CACHE PATH "Installation directory for manual pages") -set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_PREFIX}/share/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files") - -include(CheckTypeSize) -include(CheckFunctionExists) -include(CheckIncludeFile) -include(CheckCSourceCompiles) -enable_testing() - -check_include_file(sys/types.h HAVE_SYS_TYPES_H) -check_include_file(stdint.h HAVE_STDINT_H) -check_include_file(stddef.h HAVE_STDDEF_H) - -# -# Check to see if we have large file support -# -set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE=1) -# We add these other definitions here because CheckTypeSize.cmake -# in CMake 2.4.x does not automatically do so and we want -# compatibility with CMake 2.4.x. -if(HAVE_SYS_TYPES_H) - list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H) -endif() -if(HAVE_STDINT_H) - list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H) -endif() -if(HAVE_STDDEF_H) - list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H) -endif() -check_type_size(off64_t OFF64_T) -if(HAVE_OFF64_T) - add_definitions(-D_LARGEFILE64_SOURCE=1) -endif() -set(CMAKE_REQUIRED_DEFINITIONS) # clear variable - -# -# Check for fseeko -# -check_function_exists(fseeko HAVE_FSEEKO) -if(NOT HAVE_FSEEKO) - add_definitions(-DNO_FSEEKO) -endif() - -# -# Check for unistd.h -# -check_include_file(unistd.h Z_HAVE_UNISTD_H) - -if(MSVC) - set(CMAKE_DEBUG_POSTFIX "d") - add_definitions(-D_CRT_SECURE_NO_DEPRECATE) - add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) - include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -endif() - -if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR) - # If we're doing an out of source build and the user has a zconf.h - # in their source tree... - if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h) - message(STATUS "Renaming") - message(STATUS " ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h") - message(STATUS "to 'zconf.h.included' because this file is included with zlib") - message(STATUS "but CMake generates it automatically in the build directory.") - file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.included) - endif() -endif() - -set(ZLIB_PC ${CMAKE_CURRENT_BINARY_DIR}/zlib.pc) -configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zlib.pc.cmakein - ${ZLIB_PC} @ONLY) -configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein - ${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY) -include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}) - - -#============================================================================ -# zlib -#============================================================================ - -set(ZLIB_PUBLIC_HDRS - ${CMAKE_CURRENT_BINARY_DIR}/zconf.h - zlib.h -) -set(ZLIB_PRIVATE_HDRS - crc32.h - deflate.h - gzguts.h - inffast.h - inffixed.h - inflate.h - inftrees.h - trees.h - zutil.h -) -set(ZLIB_SRCS - adler32.c - compress.c - crc32.c - deflate.c - gzclose.c - gzlib.c - gzread.c - gzwrite.c - inflate.c - infback.c - inftrees.c - inffast.c - trees.c - uncompr.c - zutil.c -) - -if(NOT MINGW) - set(ZLIB_DLL_SRCS - win32/zlib1.rc # If present will override custom build rule below. - ) -endif() - -if(CMAKE_COMPILER_IS_GNUCC) - if(ASM686) - set(ZLIB_ASMS contrib/asm686/match.S) - elseif (AMD64) - set(ZLIB_ASMS contrib/amd64/amd64-match.S) - endif () - - if(ZLIB_ASMS) - add_definitions(-DASMV) - set_source_files_properties(${ZLIB_ASMS} PROPERTIES LANGUAGE C COMPILE_FLAGS -DNO_UNDERLINE) - endif() -endif() - -if(MSVC) - if(ASM686) - ENABLE_LANGUAGE(ASM_MASM) - set(ZLIB_ASMS - contrib/masmx86/inffas32.asm - contrib/masmx86/match686.asm - ) - elseif (AMD64) - ENABLE_LANGUAGE(ASM_MASM) - set(ZLIB_ASMS - contrib/masmx64/gvmat64.asm - contrib/masmx64/inffasx64.asm - ) - endif() - - if(ZLIB_ASMS) - add_definitions(-DASMV -DASMINF) - endif() -endif() - -# parse the full version number from zlib.h and include in ZLIB_FULL_VERSION -file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents) -string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([-0-9A-Za-z.]+)\".*" - "\\1" ZLIB_FULL_VERSION ${_zlib_h_contents}) - -if(MINGW) - # This gets us DLL resource information when compiling on MinGW. - if(NOT CMAKE_RC_COMPILER) - set(CMAKE_RC_COMPILER windres.exe) - endif() - - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj - COMMAND ${CMAKE_RC_COMPILER} - -D GCC_WINDRES - -I ${CMAKE_CURRENT_SOURCE_DIR} - -I ${CMAKE_CURRENT_BINARY_DIR} - -o ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj - -i ${CMAKE_CURRENT_SOURCE_DIR}/win32/zlib1.rc) - set(ZLIB_DLL_SRCS ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj) -endif(MINGW) - -add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) -add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) -set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL) -set_target_properties(zlib PROPERTIES SOVERSION 1) - -if(NOT CYGWIN) - # This property causes shared libraries on Linux to have the full version - # encoded into their final filename. We disable this on Cygwin because - # it causes cygz-${ZLIB_FULL_VERSION}.dll to be created when cygz.dll - # seems to be the default. - # - # This has no effect with MSVC, on that platform the version info for - # the DLL comes from the resource file win32/zlib1.rc - set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION}) -endif() - -if(UNIX) - # On unix-like platforms the library is almost always called libz - set_target_properties(zlib zlibstatic PROPERTIES OUTPUT_NAME z) - if(NOT APPLE) - set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"") - endif() -elseif(BUILD_SHARED_LIBS AND WIN32) - # Creates zlib1.dll when building shared library version - set_target_properties(zlib PROPERTIES SUFFIX "1.dll") -endif() - -if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL ) - install(TARGETS zlib zlibstatic - RUNTIME DESTINATION "${INSTALL_BIN_DIR}" - ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" - LIBRARY DESTINATION "${INSTALL_LIB_DIR}" ) -endif() -if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL ) - install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION "${INSTALL_INC_DIR}") -endif() -if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL ) - install(FILES zlib.3 DESTINATION "${INSTALL_MAN_DIR}/man3") -endif() -if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL ) - install(FILES ${ZLIB_PC} DESTINATION "${INSTALL_PKGCONFIG_DIR}") -endif() - -#============================================================================ -# Example binaries -#============================================================================ - -add_executable(example test/example.c) -target_link_libraries(example zlib) -add_test(example example) - -add_executable(minigzip test/minigzip.c) -target_link_libraries(minigzip zlib) - -if(HAVE_OFF64_T) - add_executable(example64 test/example.c) - target_link_libraries(example64 zlib) - set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") - add_test(example64 example64) - - add_executable(minigzip64 test/minigzip.c) - target_link_libraries(minigzip64 zlib) - set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64") -endif() diff --git a/src/beast/test/zlib/zlib-1.2.8/ChangeLog b/src/beast/test/zlib/zlib-1.2.8/ChangeLog deleted file mode 100644 index f22aabaef53..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/ChangeLog +++ /dev/null @@ -1,1472 +0,0 @@ - - ChangeLog file for zlib - -Changes in 1.2.8 (28 Apr 2013) -- Update contrib/minizip/iowin32.c for Windows RT [Vollant] -- Do not force Z_CONST for C++ -- Clean up contrib/vstudio [Ro§] -- Correct spelling error in zlib.h -- Fix mixed line endings in contrib/vstudio - -Changes in 1.2.7.3 (13 Apr 2013) -- Fix version numbers and DLL names in contrib/vstudio/*/zlib.rc - -Changes in 1.2.7.2 (13 Apr 2013) -- Change check for a four-byte type back to hexadecimal -- Fix typo in win32/Makefile.msc -- Add casts in gzwrite.c for pointer differences - -Changes in 1.2.7.1 (24 Mar 2013) -- Replace use of unsafe string functions with snprintf if available -- Avoid including stddef.h on Windows for Z_SOLO compile [Niessink] -- Fix gzgetc undefine when Z_PREFIX set [Turk] -- Eliminate use of mktemp in Makefile (not always available) -- Fix bug in 'F' mode for gzopen() -- Add inflateGetDictionary() function -- Correct comment in deflate.h -- Use _snprintf for snprintf in Microsoft C -- On Darwin, only use /usr/bin/libtool if libtool is not Apple -- Delete "--version" file if created by "ar --version" [Richard G.] -- Fix configure check for veracity of compiler error return codes -- Fix CMake compilation of static lib for MSVC2010 x64 -- Remove unused variable in infback9.c -- Fix argument checks in gzlog_compress() and gzlog_write() -- Clean up the usage of z_const and respect const usage within zlib -- Clean up examples/gzlog.[ch] comparisons of different types -- Avoid shift equal to bits in type (caused endless loop) -- Fix unintialized value bug in gzputc() introduced by const patches -- Fix memory allocation error in examples/zran.c [Nor] -- Fix bug where gzopen(), gzclose() would write an empty file -- Fix bug in gzclose() when gzwrite() runs out of memory -- Check for input buffer malloc failure in examples/gzappend.c -- Add note to contrib/blast to use binary mode in stdio -- Fix comparisons of differently signed integers in contrib/blast -- Check for invalid code length codes in contrib/puff -- Fix serious but very rare decompression bug in inftrees.c -- Update inflateBack() comments, since inflate() can be faster -- Use underscored I/O function names for WINAPI_FAMILY -- Add _tr_flush_bits to the external symbols prefixed by --zprefix -- Add contrib/vstudio/vc10 pre-build step for static only -- Quote --version-script argument in CMakeLists.txt -- Don't specify --version-script on Apple platforms in CMakeLists.txt -- Fix casting error in contrib/testzlib/testzlib.c -- Fix types in contrib/minizip to match result of get_crc_table() -- Simplify contrib/vstudio/vc10 with 'd' suffix -- Add TOP support to win32/Makefile.msc -- Suport i686 and amd64 assembler builds in CMakeLists.txt -- Fix typos in the use of _LARGEFILE64_SOURCE in zconf.h -- Add vc11 and vc12 build files to contrib/vstudio -- Add gzvprintf() as an undocumented function in zlib -- Fix configure for Sun shell -- Remove runtime check in configure for four-byte integer type -- Add casts and consts to ease user conversion to C++ -- Add man pages for minizip and miniunzip -- In Makefile uninstall, don't rm if preceding cd fails -- Do not return Z_BUF_ERROR if deflateParam() has nothing to write - -Changes in 1.2.7 (2 May 2012) -- Replace use of memmove() with a simple copy for portability -- Test for existence of strerror -- Restore gzgetc_ for backward compatibility with 1.2.6 -- Fix build with non-GNU make on Solaris -- Require gcc 4.0 or later on Mac OS X to use the hidden attribute -- Include unistd.h for Watcom C -- Use __WATCOMC__ instead of __WATCOM__ -- Do not use the visibility attribute if NO_VIZ defined -- Improve the detection of no hidden visibility attribute -- Avoid using __int64 for gcc or solo compilation -- Cast to char * in gzprintf to avoid warnings [Zinser] -- Fix make_vms.com for VAX [Zinser] -- Don't use library or built-in byte swaps -- Simplify test and use of gcc hidden attribute -- Fix bug in gzclose_w() when gzwrite() fails to allocate memory -- Add "x" (O_EXCL) and "e" (O_CLOEXEC) modes support to gzopen() -- Fix bug in test/minigzip.c for configure --solo -- Fix contrib/vstudio project link errors [Mohanathas] -- Add ability to choose the builder in make_vms.com [Schweda] -- Add DESTDIR support to mingw32 win32/Makefile.gcc -- Fix comments in win32/Makefile.gcc for proper usage -- Allow overriding the default install locations for cmake -- Generate and install the pkg-config file with cmake -- Build both a static and a shared version of zlib with cmake -- Include version symbols for cmake builds -- If using cmake with MSVC, add the source directory to the includes -- Remove unneeded EXTRA_CFLAGS from win32/Makefile.gcc [Truta] -- Move obsolete emx makefile to old [Truta] -- Allow the use of -Wundef when compiling or using zlib -- Avoid the use of the -u option with mktemp -- Improve inflate() documentation on the use of Z_FINISH -- Recognize clang as gcc -- Add gzopen_w() in Windows for wide character path names -- Rename zconf.h in CMakeLists.txt to move it out of the way -- Add source directory in CMakeLists.txt for building examples -- Look in build directory for zlib.pc in CMakeLists.txt -- Remove gzflags from zlibvc.def in vc9 and vc10 -- Fix contrib/minizip compilation in the MinGW environment -- Update ./configure for Solaris, support --64 [Mooney] -- Remove -R. from Solaris shared build (possible security issue) -- Avoid race condition for parallel make (-j) running example -- Fix type mismatch between get_crc_table() and crc_table -- Fix parsing of version with "-" in CMakeLists.txt [Snider, Ziegler] -- Fix the path to zlib.map in CMakeLists.txt -- Force the native libtool in Mac OS X to avoid GNU libtool [Beebe] -- Add instructions to win32/Makefile.gcc for shared install [Torri] - -Changes in 1.2.6.1 (12 Feb 2012) -- Avoid the use of the Objective-C reserved name "id" -- Include io.h in gzguts.h for Microsoft compilers -- Fix problem with ./configure --prefix and gzgetc macro -- Include gz_header definition when compiling zlib solo -- Put gzflags() functionality back in zutil.c -- Avoid library header include in crc32.c for Z_SOLO -- Use name in GCC_CLASSIC as C compiler for coverage testing, if set -- Minor cleanup in contrib/minizip/zip.c [Vollant] -- Update make_vms.com [Zinser] -- Remove unnecessary gzgetc_ function -- Use optimized byte swap operations for Microsoft and GNU [Snyder] -- Fix minor typo in zlib.h comments [Rzesniowiecki] - -Changes in 1.2.6 (29 Jan 2012) -- Update the Pascal interface in contrib/pascal -- Fix function numbers for gzgetc_ in zlibvc.def files -- Fix configure.ac for contrib/minizip [Schiffer] -- Fix large-entry detection in minizip on 64-bit systems [Schiffer] -- Have ./configure use the compiler return code for error indication -- Fix CMakeLists.txt for cross compilation [McClure] -- Fix contrib/minizip/zip.c for 64-bit architectures [Dalsnes] -- Fix compilation of contrib/minizip on FreeBSD [Marquez] -- Correct suggested usages in win32/Makefile.msc [Shachar, Horvath] -- Include io.h for Turbo C / Borland C on all platforms [Truta] -- Make version explicit in contrib/minizip/configure.ac [Bosmans] -- Avoid warning for no encryption in contrib/minizip/zip.c [Vollant] -- Minor cleanup up contrib/minizip/unzip.c [Vollant] -- Fix bug when compiling minizip with C++ [Vollant] -- Protect for long name and extra fields in contrib/minizip [Vollant] -- Avoid some warnings in contrib/minizip [Vollant] -- Add -I../.. -L../.. to CFLAGS for minizip and miniunzip -- Add missing libs to minizip linker command -- Add support for VPATH builds in contrib/minizip -- Add an --enable-demos option to contrib/minizip/configure -- Add the generation of configure.log by ./configure -- Exit when required parameters not provided to win32/Makefile.gcc -- Have gzputc return the character written instead of the argument -- Use the -m option on ldconfig for BSD systems [Tobias] -- Correct in zlib.map when deflateResetKeep was added - -Changes in 1.2.5.3 (15 Jan 2012) -- Restore gzgetc function for binary compatibility -- Do not use _lseeki64 under Borland C++ [Truta] -- Update win32/Makefile.msc to build test/*.c [Truta] -- Remove old/visualc6 given CMakefile and other alternatives -- Update AS400 build files and documentation [Monnerat] -- Update win32/Makefile.gcc to build test/*.c [Truta] -- Permit stronger flushes after Z_BLOCK flushes -- Avoid extraneous empty blocks when doing empty flushes -- Permit Z_NULL arguments to deflatePending -- Allow deflatePrime() to insert bits in the middle of a stream -- Remove second empty static block for Z_PARTIAL_FLUSH -- Write out all of the available bits when using Z_BLOCK -- Insert the first two strings in the hash table after a flush - -Changes in 1.2.5.2 (17 Dec 2011) -- fix ld error: unable to find version dependency 'ZLIB_1.2.5' -- use relative symlinks for shared libs -- Avoid searching past window for Z_RLE strategy -- Assure that high-water mark initialization is always applied in deflate -- Add assertions to fill_window() in deflate.c to match comments -- Update python link in README -- Correct spelling error in gzread.c -- Fix bug in gzgets() for a concatenated empty gzip stream -- Correct error in comment for gz_make() -- Change gzread() and related to ignore junk after gzip streams -- Allow gzread() and related to continue after gzclearerr() -- Allow gzrewind() and gzseek() after a premature end-of-file -- Simplify gzseek() now that raw after gzip is ignored -- Change gzgetc() to a macro for speed (~40% speedup in testing) -- Fix gzclose() to return the actual error last encountered -- Always add large file support for windows -- Include zconf.h for windows large file support -- Include zconf.h.cmakein for windows large file support -- Update zconf.h.cmakein on make distclean -- Merge vestigial vsnprintf determination from zutil.h to gzguts.h -- Clarify how gzopen() appends in zlib.h comments -- Correct documentation of gzdirect() since junk at end now ignored -- Add a transparent write mode to gzopen() when 'T' is in the mode -- Update python link in zlib man page -- Get inffixed.h and MAKEFIXED result to match -- Add a ./config --solo option to make zlib subset with no libary use -- Add undocumented inflateResetKeep() function for CAB file decoding -- Add --cover option to ./configure for gcc coverage testing -- Add #define ZLIB_CONST option to use const in the z_stream interface -- Add comment to gzdopen() in zlib.h to use dup() when using fileno() -- Note behavior of uncompress() to provide as much data as it can -- Add files in contrib/minizip to aid in building libminizip -- Split off AR options in Makefile.in and configure -- Change ON macro to Z_ARG to avoid application conflicts -- Facilitate compilation with Borland C++ for pragmas and vsnprintf -- Include io.h for Turbo C / Borland C++ -- Move example.c and minigzip.c to test/ -- Simplify incomplete code table filling in inflate_table() -- Remove code from inflate.c and infback.c that is impossible to execute -- Test the inflate code with full coverage -- Allow deflateSetDictionary, inflateSetDictionary at any time (in raw) -- Add deflateResetKeep and fix inflateResetKeep to retain dictionary -- Fix gzwrite.c to accommodate reduced memory zlib compilation -- Have inflate() with Z_FINISH avoid the allocation of a window -- Do not set strm->adler when doing raw inflate -- Fix gzeof() to behave just like feof() when read is not past end of file -- Fix bug in gzread.c when end-of-file is reached -- Avoid use of Z_BUF_ERROR in gz* functions except for premature EOF -- Document gzread() capability to read concurrently written files -- Remove hard-coding of resource compiler in CMakeLists.txt [Blammo] - -Changes in 1.2.5.1 (10 Sep 2011) -- Update FAQ entry on shared builds (#13) -- Avoid symbolic argument to chmod in Makefile.in -- Fix bug and add consts in contrib/puff [Oberhumer] -- Update contrib/puff/zeros.raw test file to have all block types -- Add full coverage test for puff in contrib/puff/Makefile -- Fix static-only-build install in Makefile.in -- Fix bug in unzGetCurrentFileInfo() in contrib/minizip [Kuno] -- Add libz.a dependency to shared in Makefile.in for parallel builds -- Spell out "number" (instead of "nb") in zlib.h for total_in, total_out -- Replace $(...) with `...` in configure for non-bash sh [Bowler] -- Add darwin* to Darwin* and solaris* to SunOS\ 5* in configure [Groffen] -- Add solaris* to Linux* in configure to allow gcc use [Groffen] -- Add *bsd* to Linux* case in configure [Bar-Lev] -- Add inffast.obj to dependencies in win32/Makefile.msc -- Correct spelling error in deflate.h [Kohler] -- Change libzdll.a again to libz.dll.a (!) in win32/Makefile.gcc -- Add test to configure for GNU C looking for gcc in output of $cc -v -- Add zlib.pc generation to win32/Makefile.gcc [Weigelt] -- Fix bug in zlib.h for _FILE_OFFSET_BITS set and _LARGEFILE64_SOURCE not -- Add comment in zlib.h that adler32_combine with len2 < 0 makes no sense -- Make NO_DIVIDE option in adler32.c much faster (thanks to John Reiser) -- Make stronger test in zconf.h to include unistd.h for LFS -- Apply Darwin patches for 64-bit file offsets to contrib/minizip [Slack] -- Fix zlib.h LFS support when Z_PREFIX used -- Add updated as400 support (removed from old) [Monnerat] -- Avoid deflate sensitivity to volatile input data -- Avoid division in adler32_combine for NO_DIVIDE -- Clarify the use of Z_FINISH with deflateBound() amount of space -- Set binary for output file in puff.c -- Use u4 type for crc_table to avoid conversion warnings -- Apply casts in zlib.h to avoid conversion warnings -- Add OF to prototypes for adler32_combine_ and crc32_combine_ [Miller] -- Improve inflateSync() documentation to note indeterminancy -- Add deflatePending() function to return the amount of pending output -- Correct the spelling of "specification" in FAQ [Randers-Pehrson] -- Add a check in configure for stdarg.h, use for gzprintf() -- Check that pointers fit in ints when gzprint() compiled old style -- Add dummy name before $(SHAREDLIBV) in Makefile [Bar-Lev, Bowler] -- Delete line in configure that adds -L. libz.a to LDFLAGS [Weigelt] -- Add debug records in assmebler code [Londer] -- Update RFC references to use http://tools.ietf.org/html/... [Li] -- Add --archs option, use of libtool to configure for Mac OS X [Borstel] - -Changes in 1.2.5 (19 Apr 2010) -- Disable visibility attribute in win32/Makefile.gcc [Bar-Lev] -- Default to libdir as sharedlibdir in configure [Nieder] -- Update copyright dates on modified source files -- Update trees.c to be able to generate modified trees.h -- Exit configure for MinGW, suggesting win32/Makefile.gcc -- Check for NULL path in gz_open [Homurlu] - -Changes in 1.2.4.5 (18 Apr 2010) -- Set sharedlibdir in configure [Torok] -- Set LDFLAGS in Makefile.in [Bar-Lev] -- Avoid mkdir objs race condition in Makefile.in [Bowler] -- Add ZLIB_INTERNAL in front of internal inter-module functions and arrays -- Define ZLIB_INTERNAL to hide internal functions and arrays for GNU C -- Don't use hidden attribute when it is a warning generator (e.g. Solaris) - -Changes in 1.2.4.4 (18 Apr 2010) -- Fix CROSS_PREFIX executable testing, CHOST extract, mingw* [Torok] -- Undefine _LARGEFILE64_SOURCE in zconf.h if it is zero, but not if empty -- Try to use bash or ksh regardless of functionality of /bin/sh -- Fix configure incompatibility with NetBSD sh -- Remove attempt to run under bash or ksh since have better NetBSD fix -- Fix win32/Makefile.gcc for MinGW [Bar-Lev] -- Add diagnostic messages when using CROSS_PREFIX in configure -- Added --sharedlibdir option to configure [Weigelt] -- Use hidden visibility attribute when available [Frysinger] - -Changes in 1.2.4.3 (10 Apr 2010) -- Only use CROSS_PREFIX in configure for ar and ranlib if they exist -- Use CROSS_PREFIX for nm [Bar-Lev] -- Assume _LARGEFILE64_SOURCE defined is equivalent to true -- Avoid use of undefined symbols in #if with && and || -- Make *64 prototypes in gzguts.h consistent with functions -- Add -shared load option for MinGW in configure [Bowler] -- Move z_off64_t to public interface, use instead of off64_t -- Remove ! from shell test in configure (not portable to Solaris) -- Change +0 macro tests to -0 for possibly increased portability - -Changes in 1.2.4.2 (9 Apr 2010) -- Add consistent carriage returns to readme.txt's in masmx86 and masmx64 -- Really provide prototypes for *64 functions when building without LFS -- Only define unlink() in minigzip.c if unistd.h not included -- Update README to point to contrib/vstudio project files -- Move projects/vc6 to old/ and remove projects/ -- Include stdlib.h in minigzip.c for setmode() definition under WinCE -- Clean up assembler builds in win32/Makefile.msc [Rowe] -- Include sys/types.h for Microsoft for off_t definition -- Fix memory leak on error in gz_open() -- Symbolize nm as $NM in configure [Weigelt] -- Use TEST_LDSHARED instead of LDSHARED to link test programs [Weigelt] -- Add +0 to _FILE_OFFSET_BITS and _LFS64_LARGEFILE in case not defined -- Fix bug in gzeof() to take into account unused input data -- Avoid initialization of structures with variables in puff.c -- Updated win32/README-WIN32.txt [Rowe] - -Changes in 1.2.4.1 (28 Mar 2010) -- Remove the use of [a-z] constructs for sed in configure [gentoo 310225] -- Remove $(SHAREDLIB) from LIBS in Makefile.in [Creech] -- Restore "for debugging" comment on sprintf() in gzlib.c -- Remove fdopen for MVS from gzguts.h -- Put new README-WIN32.txt in win32 [Rowe] -- Add check for shell to configure and invoke another shell if needed -- Fix big fat stinking bug in gzseek() on uncompressed files -- Remove vestigial F_OPEN64 define in zutil.h -- Set and check the value of _LARGEFILE_SOURCE and _LARGEFILE64_SOURCE -- Avoid errors on non-LFS systems when applications define LFS macros -- Set EXE to ".exe" in configure for MINGW [Kahle] -- Match crc32() in crc32.c exactly to the prototype in zlib.h [Sherrill] -- Add prefix for cross-compilation in win32/makefile.gcc [Bar-Lev] -- Add DLL install in win32/makefile.gcc [Bar-Lev] -- Allow Linux* or linux* from uname in configure [Bar-Lev] -- Allow ldconfig to be redefined in configure and Makefile.in [Bar-Lev] -- Add cross-compilation prefixes to configure [Bar-Lev] -- Match type exactly in gz_load() invocation in gzread.c -- Match type exactly of zcalloc() in zutil.c to zlib.h alloc_func -- Provide prototypes for *64 functions when building zlib without LFS -- Don't use -lc when linking shared library on MinGW -- Remove errno.h check in configure and vestigial errno code in zutil.h - -Changes in 1.2.4 (14 Mar 2010) -- Fix VER3 extraction in configure for no fourth subversion -- Update zlib.3, add docs to Makefile.in to make .pdf out of it -- Add zlib.3.pdf to distribution -- Don't set error code in gzerror() if passed pointer is NULL -- Apply destination directory fixes to CMakeLists.txt [Lowman] -- Move #cmakedefine's to a new zconf.in.cmakein -- Restore zconf.h for builds that don't use configure or cmake -- Add distclean to dummy Makefile for convenience -- Update and improve INDEX, README, and FAQ -- Update CMakeLists.txt for the return of zconf.h [Lowman] -- Update contrib/vstudio/vc9 and vc10 [Vollant] -- Change libz.dll.a back to libzdll.a in win32/Makefile.gcc -- Apply license and readme changes to contrib/asm686 [Raiter] -- Check file name lengths and add -c option in minigzip.c [Li] -- Update contrib/amd64 and contrib/masmx86/ [Vollant] -- Avoid use of "eof" parameter in trees.c to not shadow library variable -- Update make_vms.com for removal of zlibdefs.h [Zinser] -- Update assembler code and vstudio projects in contrib [Vollant] -- Remove outdated assembler code contrib/masm686 and contrib/asm586 -- Remove old vc7 and vc8 from contrib/vstudio -- Update win32/Makefile.msc, add ZLIB_VER_SUBREVISION [Rowe] -- Fix memory leaks in gzclose_r() and gzclose_w(), file leak in gz_open() -- Add contrib/gcc_gvmat64 for longest_match and inflate_fast [Vollant] -- Remove *64 functions from win32/zlib.def (they're not 64-bit yet) -- Fix bug in void-returning vsprintf() case in gzwrite.c -- Fix name change from inflate.h in contrib/inflate86/inffas86.c -- Check if temporary file exists before removing in make_vms.com [Zinser] -- Fix make install and uninstall for --static option -- Fix usage of _MSC_VER in gzguts.h and zutil.h [Truta] -- Update readme.txt in contrib/masmx64 and masmx86 to assemble - -Changes in 1.2.3.9 (21 Feb 2010) -- Expunge gzio.c -- Move as400 build information to old -- Fix updates in contrib/minizip and contrib/vstudio -- Add const to vsnprintf test in configure to avoid warnings [Weigelt] -- Delete zconf.h (made by configure) [Weigelt] -- Change zconf.in.h to zconf.h.in per convention [Weigelt] -- Check for NULL buf in gzgets() -- Return empty string for gzgets() with len == 1 (like fgets()) -- Fix description of gzgets() in zlib.h for end-of-file, NULL return -- Update minizip to 1.1 [Vollant] -- Avoid MSVC loss of data warnings in gzread.c, gzwrite.c -- Note in zlib.h that gzerror() should be used to distinguish from EOF -- Remove use of snprintf() from gzlib.c -- Fix bug in gzseek() -- Update contrib/vstudio, adding vc9 and vc10 [Kuno, Vollant] -- Fix zconf.h generation in CMakeLists.txt [Lowman] -- Improve comments in zconf.h where modified by configure - -Changes in 1.2.3.8 (13 Feb 2010) -- Clean up text files (tabs, trailing whitespace, etc.) [Oberhumer] -- Use z_off64_t in gz_zero() and gz_skip() to match state->skip -- Avoid comparison problem when sizeof(int) == sizeof(z_off64_t) -- Revert to Makefile.in from 1.2.3.6 (live with the clutter) -- Fix missing error return in gzflush(), add zlib.h note -- Add *64 functions to zlib.map [Levin] -- Fix signed/unsigned comparison in gz_comp() -- Use SFLAGS when testing shared linking in configure -- Add --64 option to ./configure to use -m64 with gcc -- Fix ./configure --help to correctly name options -- Have make fail if a test fails [Levin] -- Avoid buffer overrun in contrib/masmx64/gvmat64.asm [Simpson] -- Remove assembler object files from contrib - -Changes in 1.2.3.7 (24 Jan 2010) -- Always gzopen() with O_LARGEFILE if available -- Fix gzdirect() to work immediately after gzopen() or gzdopen() -- Make gzdirect() more precise when the state changes while reading -- Improve zlib.h documentation in many places -- Catch memory allocation failure in gz_open() -- Complete close operation if seek forward in gzclose_w() fails -- Return Z_ERRNO from gzclose_r() if close() fails -- Return Z_STREAM_ERROR instead of EOF for gzclose() being passed NULL -- Return zero for gzwrite() errors to match zlib.h description -- Return -1 on gzputs() error to match zlib.h description -- Add zconf.in.h to allow recovery from configure modification [Weigelt] -- Fix static library permissions in Makefile.in [Weigelt] -- Avoid warnings in configure tests that hide functionality [Weigelt] -- Add *BSD and DragonFly to Linux case in configure [gentoo 123571] -- Change libzdll.a to libz.dll.a in win32/Makefile.gcc [gentoo 288212] -- Avoid access of uninitialized data for first inflateReset2 call [Gomes] -- Keep object files in subdirectories to reduce the clutter somewhat -- Remove default Makefile and zlibdefs.h, add dummy Makefile -- Add new external functions to Z_PREFIX, remove duplicates, z_z_ -> z_ -- Remove zlibdefs.h completely -- modify zconf.h instead - -Changes in 1.2.3.6 (17 Jan 2010) -- Avoid void * arithmetic in gzread.c and gzwrite.c -- Make compilers happier with const char * for gz_error message -- Avoid unused parameter warning in inflate.c -- Avoid signed-unsigned comparison warning in inflate.c -- Indent #pragma's for traditional C -- Fix usage of strwinerror() in glib.c, change to gz_strwinerror() -- Correct email address in configure for system options -- Update make_vms.com and add make_vms.com to contrib/minizip [Zinser] -- Update zlib.map [Brown] -- Fix Makefile.in for Solaris 10 make of example64 and minizip64 [Torok] -- Apply various fixes to CMakeLists.txt [Lowman] -- Add checks on len in gzread() and gzwrite() -- Add error message for no more room for gzungetc() -- Remove zlib version check in gzwrite() -- Defer compression of gzprintf() result until need to -- Use snprintf() in gzdopen() if available -- Remove USE_MMAP configuration determination (only used by minigzip) -- Remove examples/pigz.c (available separately) -- Update examples/gun.c to 1.6 - -Changes in 1.2.3.5 (8 Jan 2010) -- Add space after #if in zutil.h for some compilers -- Fix relatively harmless bug in deflate_fast() [Exarevsky] -- Fix same problem in deflate_slow() -- Add $(SHAREDLIBV) to LIBS in Makefile.in [Brown] -- Add deflate_rle() for faster Z_RLE strategy run-length encoding -- Add deflate_huff() for faster Z_HUFFMAN_ONLY encoding -- Change name of "write" variable in inffast.c to avoid library collisions -- Fix premature EOF from gzread() in gzio.c [Brown] -- Use zlib header window size if windowBits is 0 in inflateInit2() -- Remove compressBound() call in deflate.c to avoid linking compress.o -- Replace use of errno in gz* with functions, support WinCE [Alves] -- Provide alternative to perror() in minigzip.c for WinCE [Alves] -- Don't use _vsnprintf on later versions of MSVC [Lowman] -- Add CMake build script and input file [Lowman] -- Update contrib/minizip to 1.1 [Svensson, Vollant] -- Moved nintendods directory from contrib to . -- Replace gzio.c with a new set of routines with the same functionality -- Add gzbuffer(), gzoffset(), gzclose_r(), gzclose_w() as part of above -- Update contrib/minizip to 1.1b -- Change gzeof() to return 0 on error instead of -1 to agree with zlib.h - -Changes in 1.2.3.4 (21 Dec 2009) -- Use old school .SUFFIXES in Makefile.in for FreeBSD compatibility -- Update comments in configure and Makefile.in for default --shared -- Fix test -z's in configure [Marquess] -- Build examplesh and minigzipsh when not testing -- Change NULL's to Z_NULL's in deflate.c and in comments in zlib.h -- Import LDFLAGS from the environment in configure -- Fix configure to populate SFLAGS with discovered CFLAGS options -- Adapt make_vms.com to the new Makefile.in [Zinser] -- Add zlib2ansi script for C++ compilation [Marquess] -- Add _FILE_OFFSET_BITS=64 test to make test (when applicable) -- Add AMD64 assembler code for longest match to contrib [Teterin] -- Include options from $SFLAGS when doing $LDSHARED -- Simplify 64-bit file support by introducing z_off64_t type -- Make shared object files in objs directory to work around old Sun cc -- Use only three-part version number for Darwin shared compiles -- Add rc option to ar in Makefile.in for when ./configure not run -- Add -WI,-rpath,. to LDFLAGS for OSF 1 V4* -- Set LD_LIBRARYN32_PATH for SGI IRIX shared compile -- Protect against _FILE_OFFSET_BITS being defined when compiling zlib -- Rename Makefile.in targets allstatic to static and allshared to shared -- Fix static and shared Makefile.in targets to be independent -- Correct error return bug in gz_open() by setting state [Brown] -- Put spaces before ;;'s in configure for better sh compatibility -- Add pigz.c (parallel implementation of gzip) to examples/ -- Correct constant in crc32.c to UL [Leventhal] -- Reject negative lengths in crc32_combine() -- Add inflateReset2() function to work like inflateEnd()/inflateInit2() -- Include sys/types.h for _LARGEFILE64_SOURCE [Brown] -- Correct typo in doc/algorithm.txt [Janik] -- Fix bug in adler32_combine() [Zhu] -- Catch missing-end-of-block-code error in all inflates and in puff - Assures that random input to inflate eventually results in an error -- Added enough.c (calculation of ENOUGH for inftrees.h) to examples/ -- Update ENOUGH and its usage to reflect discovered bounds -- Fix gzerror() error report on empty input file [Brown] -- Add ush casts in trees.c to avoid pedantic runtime errors -- Fix typo in zlib.h uncompress() description [Reiss] -- Correct inflate() comments with regard to automatic header detection -- Remove deprecation comment on Z_PARTIAL_FLUSH (it stays) -- Put new version of gzlog (2.0) in examples with interruption recovery -- Add puff compile option to permit invalid distance-too-far streams -- Add puff TEST command options, ability to read piped input -- Prototype the *64 functions in zlib.h when _FILE_OFFSET_BITS == 64, but - _LARGEFILE64_SOURCE not defined -- Fix Z_FULL_FLUSH to truly erase the past by resetting s->strstart -- Fix deflateSetDictionary() to use all 32K for output consistency -- Remove extraneous #define MIN_LOOKAHEAD in deflate.c (in deflate.h) -- Clear bytes after deflate lookahead to avoid use of uninitialized data -- Change a limit in inftrees.c to be more transparent to Coverity Prevent -- Update win32/zlib.def with exported symbols from zlib.h -- Correct spelling errors in zlib.h [Willem, Sobrado] -- Allow Z_BLOCK for deflate() to force a new block -- Allow negative bits in inflatePrime() to delete existing bit buffer -- Add Z_TREES flush option to inflate() to return at end of trees -- Add inflateMark() to return current state information for random access -- Add Makefile for NintendoDS to contrib [Costa] -- Add -w in configure compile tests to avoid spurious warnings [Beucler] -- Fix typos in zlib.h comments for deflateSetDictionary() -- Fix EOF detection in transparent gzread() [Maier] - -Changes in 1.2.3.3 (2 October 2006) -- Make --shared the default for configure, add a --static option -- Add compile option to permit invalid distance-too-far streams -- Add inflateUndermine() function which is required to enable above -- Remove use of "this" variable name for C++ compatibility [Marquess] -- Add testing of shared library in make test, if shared library built -- Use ftello() and fseeko() if available instead of ftell() and fseek() -- Provide two versions of all functions that use the z_off_t type for - binary compatibility -- a normal version and a 64-bit offset version, - per the Large File Support Extension when _LARGEFILE64_SOURCE is - defined; use the 64-bit versions by default when _FILE_OFFSET_BITS - is defined to be 64 -- Add a --uname= option to configure to perhaps help with cross-compiling - -Changes in 1.2.3.2 (3 September 2006) -- Turn off silly Borland warnings [Hay] -- Use off64_t and define _LARGEFILE64_SOURCE when present -- Fix missing dependency on inffixed.h in Makefile.in -- Rig configure --shared to build both shared and static [Teredesai, Truta] -- Remove zconf.in.h and instead create a new zlibdefs.h file -- Fix contrib/minizip/unzip.c non-encrypted after encrypted [Vollant] -- Add treebuild.xml (see http://treebuild.metux.de/) [Weigelt] - -Changes in 1.2.3.1 (16 August 2006) -- Add watcom directory with OpenWatcom make files [Daniel] -- Remove #undef of FAR in zconf.in.h for MVS [Fedtke] -- Update make_vms.com [Zinser] -- Use -fPIC for shared build in configure [Teredesai, Nicholson] -- Use only major version number for libz.so on IRIX and OSF1 [Reinholdtsen] -- Use fdopen() (not _fdopen()) for Interix in zutil.h [BŠck] -- Add some FAQ entries about the contrib directory -- Update the MVS question in the FAQ -- Avoid extraneous reads after EOF in gzio.c [Brown] -- Correct spelling of "successfully" in gzio.c [Randers-Pehrson] -- Add comments to zlib.h about gzerror() usage [Brown] -- Set extra flags in gzip header in gzopen() like deflate() does -- Make configure options more compatible with double-dash conventions - [Weigelt] -- Clean up compilation under Solaris SunStudio cc [Rowe, Reinholdtsen] -- Fix uninstall target in Makefile.in [Truta] -- Add pkgconfig support [Weigelt] -- Use $(DESTDIR) macro in Makefile.in [Reinholdtsen, Weigelt] -- Replace set_data_type() with a more accurate detect_data_type() in - trees.c, according to the txtvsbin.txt document [Truta] -- Swap the order of #include and #include "zlib.h" in - gzio.c, example.c and minigzip.c [Truta] -- Shut up annoying VS2005 warnings about standard C deprecation [Rowe, - Truta] (where?) -- Fix target "clean" from win32/Makefile.bor [Truta] -- Create .pdb and .manifest files in win32/makefile.msc [Ziegler, Rowe] -- Update zlib www home address in win32/DLL_FAQ.txt [Truta] -- Update contrib/masmx86/inffas32.asm for VS2005 [Vollant, Van Wassenhove] -- Enable browse info in the "Debug" and "ASM Debug" configurations in - the Visual C++ 6 project, and set (non-ASM) "Debug" as default [Truta] -- Add pkgconfig support [Weigelt] -- Add ZLIB_VER_MAJOR, ZLIB_VER_MINOR and ZLIB_VER_REVISION in zlib.h, - for use in win32/zlib1.rc [Polushin, Rowe, Truta] -- Add a document that explains the new text detection scheme to - doc/txtvsbin.txt [Truta] -- Add rfc1950.txt, rfc1951.txt and rfc1952.txt to doc/ [Truta] -- Move algorithm.txt into doc/ [Truta] -- Synchronize FAQ with website -- Fix compressBound(), was low for some pathological cases [Fearnley] -- Take into account wrapper variations in deflateBound() -- Set examples/zpipe.c input and output to binary mode for Windows -- Update examples/zlib_how.html with new zpipe.c (also web site) -- Fix some warnings in examples/gzlog.c and examples/zran.c (it seems - that gcc became pickier in 4.0) -- Add zlib.map for Linux: "All symbols from zlib-1.1.4 remain - un-versioned, the patch adds versioning only for symbols introduced in - zlib-1.2.0 or later. It also declares as local those symbols which are - not designed to be exported." [Levin] -- Update Z_PREFIX list in zconf.in.h, add --zprefix option to configure -- Do not initialize global static by default in trees.c, add a response - NO_INIT_GLOBAL_POINTERS to initialize them if needed [Marquess] -- Don't use strerror() in gzio.c under WinCE [Yakimov] -- Don't use errno.h in zutil.h under WinCE [Yakimov] -- Move arguments for AR to its usage to allow replacing ar [Marot] -- Add HAVE_VISIBILITY_PRAGMA in zconf.in.h for Mozilla [Randers-Pehrson] -- Improve inflateInit() and inflateInit2() documentation -- Fix structure size comment in inflate.h -- Change configure help option from --h* to --help [Santos] - -Changes in 1.2.3 (18 July 2005) -- Apply security vulnerability fixes to contrib/infback9 as well -- Clean up some text files (carriage returns, trailing space) -- Update testzlib, vstudio, masmx64, and masmx86 in contrib [Vollant] - -Changes in 1.2.2.4 (11 July 2005) -- Add inflatePrime() function for starting inflation at bit boundary -- Avoid some Visual C warnings in deflate.c -- Avoid more silly Visual C warnings in inflate.c and inftrees.c for 64-bit - compile -- Fix some spelling errors in comments [Betts] -- Correct inflateInit2() error return documentation in zlib.h -- Add zran.c example of compressed data random access to examples - directory, shows use of inflatePrime() -- Fix cast for assignments to strm->state in inflate.c and infback.c -- Fix zlibCompileFlags() in zutil.c to use 1L for long shifts [Oberhumer] -- Move declarations of gf2 functions to right place in crc32.c [Oberhumer] -- Add cast in trees.c t avoid a warning [Oberhumer] -- Avoid some warnings in fitblk.c, gun.c, gzjoin.c in examples [Oberhumer] -- Update make_vms.com [Zinser] -- Initialize state->write in inflateReset() since copied in inflate_fast() -- Be more strict on incomplete code sets in inflate_table() and increase - ENOUGH and MAXD -- this repairs a possible security vulnerability for - invalid inflate input. Thanks to Tavis Ormandy and Markus Oberhumer for - discovering the vulnerability and providing test cases. -- Add ia64 support to configure for HP-UX [Smith] -- Add error return to gzread() for format or i/o error [Levin] -- Use malloc.h for OS/2 [Necasek] - -Changes in 1.2.2.3 (27 May 2005) -- Replace 1U constants in inflate.c and inftrees.c for 64-bit compile -- Typecast fread() return values in gzio.c [Vollant] -- Remove trailing space in minigzip.c outmode (VC++ can't deal with it) -- Fix crc check bug in gzread() after gzungetc() [Heiner] -- Add the deflateTune() function to adjust internal compression parameters -- Add a fast gzip decompressor, gun.c, to examples (use of inflateBack) -- Remove an incorrect assertion in examples/zpipe.c -- Add C++ wrapper in infback9.h [Donais] -- Fix bug in inflateCopy() when decoding fixed codes -- Note in zlib.h how much deflateSetDictionary() actually uses -- Remove USE_DICT_HEAD in deflate.c (would mess up inflate if used) -- Add _WIN32_WCE to define WIN32 in zconf.in.h [Spencer] -- Don't include stderr.h or errno.h for _WIN32_WCE in zutil.h [Spencer] -- Add gzdirect() function to indicate transparent reads -- Update contrib/minizip [Vollant] -- Fix compilation of deflate.c when both ASMV and FASTEST [Oberhumer] -- Add casts in crc32.c to avoid warnings [Oberhumer] -- Add contrib/masmx64 [Vollant] -- Update contrib/asm586, asm686, masmx86, testzlib, vstudio [Vollant] - -Changes in 1.2.2.2 (30 December 2004) -- Replace structure assignments in deflate.c and inflate.c with zmemcpy to - avoid implicit memcpy calls (portability for no-library compilation) -- Increase sprintf() buffer size in gzdopen() to allow for large numbers -- Add INFLATE_STRICT to check distances against zlib header -- Improve WinCE errno handling and comments [Chang] -- Remove comment about no gzip header processing in FAQ -- Add Z_FIXED strategy option to deflateInit2() to force fixed trees -- Add updated make_vms.com [Coghlan], update README -- Create a new "examples" directory, move gzappend.c there, add zpipe.c, - fitblk.c, gzlog.[ch], gzjoin.c, and zlib_how.html. -- Add FAQ entry and comments in deflate.c on uninitialized memory access -- Add Solaris 9 make options in configure [Gilbert] -- Allow strerror() usage in gzio.c for STDC -- Fix DecompressBuf in contrib/delphi/ZLib.pas [ManChesTer] -- Update contrib/masmx86/inffas32.asm and gvmat32.asm [Vollant] -- Use z_off_t for adler32_combine() and crc32_combine() lengths -- Make adler32() much faster for small len -- Use OS_CODE in deflate() default gzip header - -Changes in 1.2.2.1 (31 October 2004) -- Allow inflateSetDictionary() call for raw inflate -- Fix inflate header crc check bug for file names and comments -- Add deflateSetHeader() and gz_header structure for custom gzip headers -- Add inflateGetheader() to retrieve gzip headers -- Add crc32_combine() and adler32_combine() functions -- Add alloc_func, free_func, in_func, out_func to Z_PREFIX list -- Use zstreamp consistently in zlib.h (inflate_back functions) -- Remove GUNZIP condition from definition of inflate_mode in inflate.h - and in contrib/inflate86/inffast.S [Truta, Anderson] -- Add support for AMD64 in contrib/inflate86/inffas86.c [Anderson] -- Update projects/README.projects and projects/visualc6 [Truta] -- Update win32/DLL_FAQ.txt [Truta] -- Avoid warning under NO_GZCOMPRESS in gzio.c; fix typo [Truta] -- Deprecate Z_ASCII; use Z_TEXT instead [Truta] -- Use a new algorithm for setting strm->data_type in trees.c [Truta] -- Do not define an exit() prototype in zutil.c unless DEBUG defined -- Remove prototype of exit() from zutil.c, example.c, minigzip.c [Truta] -- Add comment in zlib.h for Z_NO_FLUSH parameter to deflate() -- Fix Darwin build version identification [Peterson] - -Changes in 1.2.2 (3 October 2004) -- Update zlib.h comments on gzip in-memory processing -- Set adler to 1 in inflateReset() to support Java test suite [Walles] -- Add contrib/dotzlib [Ravn] -- Update win32/DLL_FAQ.txt [Truta] -- Update contrib/minizip [Vollant] -- Move contrib/visual-basic.txt to old/ [Truta] -- Fix assembler builds in projects/visualc6/ [Truta] - -Changes in 1.2.1.2 (9 September 2004) -- Update INDEX file -- Fix trees.c to update strm->data_type (no one ever noticed!) -- Fix bug in error case in inflate.c, infback.c, and infback9.c [Brown] -- Add "volatile" to crc table flag declaration (for DYNAMIC_CRC_TABLE) -- Add limited multitasking protection to DYNAMIC_CRC_TABLE -- Add NO_vsnprintf for VMS in zutil.h [Mozilla] -- Don't declare strerror() under VMS [Mozilla] -- Add comment to DYNAMIC_CRC_TABLE to use get_crc_table() to initialize -- Update contrib/ada [Anisimkov] -- Update contrib/minizip [Vollant] -- Fix configure to not hardcode directories for Darwin [Peterson] -- Fix gzio.c to not return error on empty files [Brown] -- Fix indentation; update version in contrib/delphi/ZLib.pas and - contrib/pascal/zlibpas.pas [Truta] -- Update mkasm.bat in contrib/masmx86 [Truta] -- Update contrib/untgz [Truta] -- Add projects/README.projects [Truta] -- Add project for MS Visual C++ 6.0 in projects/visualc6 [Cadieux, Truta] -- Update win32/DLL_FAQ.txt [Truta] -- Update list of Z_PREFIX symbols in zconf.h [Randers-Pehrson, Truta] -- Remove an unnecessary assignment to curr in inftrees.c [Truta] -- Add OS/2 to exe builds in configure [Poltorak] -- Remove err dummy parameter in zlib.h [Kientzle] - -Changes in 1.2.1.1 (9 January 2004) -- Update email address in README -- Several FAQ updates -- Fix a big fat bug in inftrees.c that prevented decoding valid - dynamic blocks with only literals and no distance codes -- - Thanks to "Hot Emu" for the bug report and sample file -- Add a note to puff.c on no distance codes case. - -Changes in 1.2.1 (17 November 2003) -- Remove a tab in contrib/gzappend/gzappend.c -- Update some interfaces in contrib for new zlib functions -- Update zlib version number in some contrib entries -- Add Windows CE definition for ptrdiff_t in zutil.h [Mai, Truta] -- Support shared libraries on Hurd and KFreeBSD [Brown] -- Fix error in NO_DIVIDE option of adler32.c - -Changes in 1.2.0.8 (4 November 2003) -- Update version in contrib/delphi/ZLib.pas and contrib/pascal/zlibpas.pas -- Add experimental NO_DIVIDE #define in adler32.c - - Possibly faster on some processors (let me know if it is) -- Correct Z_BLOCK to not return on first inflate call if no wrap -- Fix strm->data_type on inflate() return to correctly indicate EOB -- Add deflatePrime() function for appending in the middle of a byte -- Add contrib/gzappend for an example of appending to a stream -- Update win32/DLL_FAQ.txt [Truta] -- Delete Turbo C comment in README [Truta] -- Improve some indentation in zconf.h [Truta] -- Fix infinite loop on bad input in configure script [Church] -- Fix gzeof() for concatenated gzip files [Johnson] -- Add example to contrib/visual-basic.txt [Michael B.] -- Add -p to mkdir's in Makefile.in [vda] -- Fix configure to properly detect presence or lack of printf functions -- Add AS400 support [Monnerat] -- Add a little Cygwin support [Wilson] - -Changes in 1.2.0.7 (21 September 2003) -- Correct some debug formats in contrib/infback9 -- Cast a type in a debug statement in trees.c -- Change search and replace delimiter in configure from % to # [Beebe] -- Update contrib/untgz to 0.2 with various fixes [Truta] -- Add build support for Amiga [Nikl] -- Remove some directories in old that have been updated to 1.2 -- Add dylib building for Mac OS X in configure and Makefile.in -- Remove old distribution stuff from Makefile -- Update README to point to DLL_FAQ.txt, and add comment on Mac OS X -- Update links in README - -Changes in 1.2.0.6 (13 September 2003) -- Minor FAQ updates -- Update contrib/minizip to 1.00 [Vollant] -- Remove test of gz functions in example.c when GZ_COMPRESS defined [Truta] -- Update POSTINC comment for 68060 [Nikl] -- Add contrib/infback9 with deflate64 decoding (unsupported) -- For MVS define NO_vsnprintf and undefine FAR [van Burik] -- Add pragma for fdopen on MVS [van Burik] - -Changes in 1.2.0.5 (8 September 2003) -- Add OF to inflateBackEnd() declaration in zlib.h -- Remember start when using gzdopen in the middle of a file -- Use internal off_t counters in gz* functions to properly handle seeks -- Perform more rigorous check for distance-too-far in inffast.c -- Add Z_BLOCK flush option to return from inflate at block boundary -- Set strm->data_type on return from inflate - - Indicate bits unused, if at block boundary, and if in last block -- Replace size_t with ptrdiff_t in crc32.c, and check for correct size -- Add condition so old NO_DEFLATE define still works for compatibility -- FAQ update regarding the Windows DLL [Truta] -- INDEX update: add qnx entry, remove aix entry [Truta] -- Install zlib.3 into mandir [Wilson] -- Move contrib/zlib_dll_FAQ.txt to win32/DLL_FAQ.txt; update [Truta] -- Adapt the zlib interface to the new DLL convention guidelines [Truta] -- Introduce ZLIB_WINAPI macro to allow the export of functions using - the WINAPI calling convention, for Visual Basic [Vollant, Truta] -- Update msdos and win32 scripts and makefiles [Truta] -- Export symbols by name, not by ordinal, in win32/zlib.def [Truta] -- Add contrib/ada [Anisimkov] -- Move asm files from contrib/vstudio/vc70_32 to contrib/asm386 [Truta] -- Rename contrib/asm386 to contrib/masmx86 [Truta, Vollant] -- Add contrib/masm686 [Truta] -- Fix offsets in contrib/inflate86 and contrib/masmx86/inffas32.asm - [Truta, Vollant] -- Update contrib/delphi; rename to contrib/pascal; add example [Truta] -- Remove contrib/delphi2; add a new contrib/delphi [Truta] -- Avoid inclusion of the nonstandard in contrib/iostream, - and fix some method prototypes [Truta] -- Fix the ZCR_SEED2 constant to avoid warnings in contrib/minizip - [Truta] -- Avoid the use of backslash (\) in contrib/minizip [Vollant] -- Fix file time handling in contrib/untgz; update makefiles [Truta] -- Update contrib/vstudio/vc70_32 to comply with the new DLL guidelines - [Vollant] -- Remove contrib/vstudio/vc15_16 [Vollant] -- Rename contrib/vstudio/vc70_32 to contrib/vstudio/vc7 [Truta] -- Update README.contrib [Truta] -- Invert the assignment order of match_head and s->prev[...] in - INSERT_STRING [Truta] -- Compare TOO_FAR with 32767 instead of 32768, to avoid 16-bit warnings - [Truta] -- Compare function pointers with 0, not with NULL or Z_NULL [Truta] -- Fix prototype of syncsearch in inflate.c [Truta] -- Introduce ASMINF macro to be enabled when using an ASM implementation - of inflate_fast [Truta] -- Change NO_DEFLATE to NO_GZCOMPRESS [Truta] -- Modify test_gzio in example.c to take a single file name as a - parameter [Truta] -- Exit the example.c program if gzopen fails [Truta] -- Add type casts around strlen in example.c [Truta] -- Remove casting to sizeof in minigzip.c; give a proper type - to the variable compared with SUFFIX_LEN [Truta] -- Update definitions of STDC and STDC99 in zconf.h [Truta] -- Synchronize zconf.h with the new Windows DLL interface [Truta] -- Use SYS16BIT instead of __32BIT__ to distinguish between - 16- and 32-bit platforms [Truta] -- Use far memory allocators in small 16-bit memory models for - Turbo C [Truta] -- Add info about the use of ASMV, ASMINF and ZLIB_WINAPI in - zlibCompileFlags [Truta] -- Cygwin has vsnprintf [Wilson] -- In Windows16, OS_CODE is 0, as in MSDOS [Truta] -- In Cygwin, OS_CODE is 3 (Unix), not 11 (Windows32) [Wilson] - -Changes in 1.2.0.4 (10 August 2003) -- Minor FAQ updates -- Be more strict when checking inflateInit2's windowBits parameter -- Change NO_GUNZIP compile option to NO_GZIP to cover deflate as well -- Add gzip wrapper option to deflateInit2 using windowBits -- Add updated QNX rule in configure and qnx directory [Bonnefoy] -- Make inflate distance-too-far checks more rigorous -- Clean up FAR usage in inflate -- Add casting to sizeof() in gzio.c and minigzip.c - -Changes in 1.2.0.3 (19 July 2003) -- Fix silly error in gzungetc() implementation [Vollant] -- Update contrib/minizip and contrib/vstudio [Vollant] -- Fix printf format in example.c -- Correct cdecl support in zconf.in.h [Anisimkov] -- Minor FAQ updates - -Changes in 1.2.0.2 (13 July 2003) -- Add ZLIB_VERNUM in zlib.h for numerical preprocessor comparisons -- Attempt to avoid warnings in crc32.c for pointer-int conversion -- Add AIX to configure, remove aix directory [Bakker] -- Add some casts to minigzip.c -- Improve checking after insecure sprintf() or vsprintf() calls -- Remove #elif's from crc32.c -- Change leave label to inf_leave in inflate.c and infback.c to avoid - library conflicts -- Remove inflate gzip decoding by default--only enable gzip decoding by - special request for stricter backward compatibility -- Add zlibCompileFlags() function to return compilation information -- More typecasting in deflate.c to avoid warnings -- Remove leading underscore from _Capital #defines [Truta] -- Fix configure to link shared library when testing -- Add some Windows CE target adjustments [Mai] -- Remove #define ZLIB_DLL in zconf.h [Vollant] -- Add zlib.3 [Rodgers] -- Update RFC URL in deflate.c and algorithm.txt [Mai] -- Add zlib_dll_FAQ.txt to contrib [Truta] -- Add UL to some constants [Truta] -- Update minizip and vstudio [Vollant] -- Remove vestigial NEED_DUMMY_RETURN from zconf.in.h -- Expand use of NO_DUMMY_DECL to avoid all dummy structures -- Added iostream3 to contrib [Schwardt] -- Replace rewind() with fseek() for WinCE [Truta] -- Improve setting of zlib format compression level flags - - Report 0 for huffman and rle strategies and for level == 0 or 1 - - Report 2 only for level == 6 -- Only deal with 64K limit when necessary at compile time [Truta] -- Allow TOO_FAR check to be turned off at compile time [Truta] -- Add gzclearerr() function [Souza] -- Add gzungetc() function - -Changes in 1.2.0.1 (17 March 2003) -- Add Z_RLE strategy for run-length encoding [Truta] - - When Z_RLE requested, restrict matches to distance one - - Update zlib.h, minigzip.c, gzopen(), gzdopen() for Z_RLE -- Correct FASTEST compilation to allow level == 0 -- Clean up what gets compiled for FASTEST -- Incorporate changes to zconf.in.h [Vollant] - - Refine detection of Turbo C need for dummy returns - - Refine ZLIB_DLL compilation - - Include additional header file on VMS for off_t typedef -- Try to use _vsnprintf where it supplants vsprintf [Vollant] -- Add some casts in inffast.c -- Enchance comments in zlib.h on what happens if gzprintf() tries to - write more than 4095 bytes before compression -- Remove unused state from inflateBackEnd() -- Remove exit(0) from minigzip.c, example.c -- Get rid of all those darn tabs -- Add "check" target to Makefile.in that does the same thing as "test" -- Add "mostlyclean" and "maintainer-clean" targets to Makefile.in -- Update contrib/inflate86 [Anderson] -- Update contrib/testzlib, contrib/vstudio, contrib/minizip [Vollant] -- Add msdos and win32 directories with makefiles [Truta] -- More additions and improvements to the FAQ - -Changes in 1.2.0 (9 March 2003) -- New and improved inflate code - - About 20% faster - - Does not allocate 32K window unless and until needed - - Automatically detects and decompresses gzip streams - - Raw inflate no longer needs an extra dummy byte at end - - Added inflateBack functions using a callback interface--even faster - than inflate, useful for file utilities (gzip, zip) - - Added inflateCopy() function to record state for random access on - externally generated deflate streams (e.g. in gzip files) - - More readable code (I hope) -- New and improved crc32() - - About 50% faster, thanks to suggestions from Rodney Brown -- Add deflateBound() and compressBound() functions -- Fix memory leak in deflateInit2() -- Permit setting dictionary for raw deflate (for parallel deflate) -- Fix const declaration for gzwrite() -- Check for some malloc() failures in gzio.c -- Fix bug in gzopen() on single-byte file 0x1f -- Fix bug in gzread() on concatenated file with 0x1f at end of buffer - and next buffer doesn't start with 0x8b -- Fix uncompress() to return Z_DATA_ERROR on truncated input -- Free memory at end of example.c -- Remove MAX #define in trees.c (conflicted with some libraries) -- Fix static const's in deflate.c, gzio.c, and zutil.[ch] -- Declare malloc() and free() in gzio.c if STDC not defined -- Use malloc() instead of calloc() in zutil.c if int big enough -- Define STDC for AIX -- Add aix/ with approach for compiling shared library on AIX -- Add HP-UX support for shared libraries in configure -- Add OpenUNIX support for shared libraries in configure -- Use $cc instead of gcc to build shared library -- Make prefix directory if needed when installing -- Correct Macintosh avoidance of typedef Byte in zconf.h -- Correct Turbo C memory allocation when under Linux -- Use libz.a instead of -lz in Makefile (assure use of compiled library) -- Update configure to check for snprintf or vsnprintf functions and their - return value, warn during make if using an insecure function -- Fix configure problem with compile-time knowledge of HAVE_UNISTD_H that - is lost when library is used--resolution is to build new zconf.h -- Documentation improvements (in zlib.h): - - Document raw deflate and inflate - - Update RFCs URL - - Point out that zlib and gzip formats are different - - Note that Z_BUF_ERROR is not fatal - - Document string limit for gzprintf() and possible buffer overflow - - Note requirement on avail_out when flushing - - Note permitted values of flush parameter of inflate() -- Add some FAQs (and even answers) to the FAQ -- Add contrib/inflate86/ for x86 faster inflate -- Add contrib/blast/ for PKWare Data Compression Library decompression -- Add contrib/puff/ simple inflate for deflate format description - -Changes in 1.1.4 (11 March 2002) -- ZFREE was repeated on same allocation on some error conditions. - This creates a security problem described in - http://www.zlib.org/advisory-2002-03-11.txt -- Returned incorrect error (Z_MEM_ERROR) on some invalid data -- Avoid accesses before window for invalid distances with inflate window - less than 32K. -- force windowBits > 8 to avoid a bug in the encoder for a window size - of 256 bytes. (A complete fix will be available in 1.1.5). - -Changes in 1.1.3 (9 July 1998) -- fix "an inflate input buffer bug that shows up on rare but persistent - occasions" (Mark) -- fix gzread and gztell for concatenated .gz files (Didier Le Botlan) -- fix gzseek(..., SEEK_SET) in write mode -- fix crc check after a gzeek (Frank Faubert) -- fix miniunzip when the last entry in a zip file is itself a zip file - (J Lillge) -- add contrib/asm586 and contrib/asm686 (Brian Raiter) - See http://www.muppetlabs.com/~breadbox/software/assembly.html -- add support for Delphi 3 in contrib/delphi (Bob Dellaca) -- add support for C++Builder 3 and Delphi 3 in contrib/delphi2 (Davide Moretti) -- do not exit prematurely in untgz if 0 at start of block (Magnus Holmgren) -- use macro EXTERN instead of extern to support DLL for BeOS (Sander Stoks) -- added a FAQ file - -- Support gzdopen on Mac with Metrowerks (Jason Linhart) -- Do not redefine Byte on Mac (Brad Pettit & Jason Linhart) -- define SEEK_END too if SEEK_SET is not defined (Albert Chin-A-Young) -- avoid some warnings with Borland C (Tom Tanner) -- fix a problem in contrib/minizip/zip.c for 16-bit MSDOS (Gilles Vollant) -- emulate utime() for WIN32 in contrib/untgz (Gilles Vollant) -- allow several arguments to configure (Tim Mooney, Frodo Looijaard) -- use libdir and includedir in Makefile.in (Tim Mooney) -- support shared libraries on OSF1 V4 (Tim Mooney) -- remove so_locations in "make clean" (Tim Mooney) -- fix maketree.c compilation error (Glenn, Mark) -- Python interface to zlib now in Python 1.5 (Jeremy Hylton) -- new Makefile.riscos (Rich Walker) -- initialize static descriptors in trees.c for embedded targets (Nick Smith) -- use "foo-gz" in example.c for RISCOS and VMS (Nick Smith) -- add the OS/2 files in Makefile.in too (Andrew Zabolotny) -- fix fdopen and halloc macros for Microsoft C 6.0 (Tom Lane) -- fix maketree.c to allow clean compilation of inffixed.h (Mark) -- fix parameter check in deflateCopy (Gunther Nikl) -- cleanup trees.c, use compressed_len only in debug mode (Christian Spieler) -- Many portability patches by Christian Spieler: - . zutil.c, zutil.h: added "const" for zmem* - . Make_vms.com: fixed some typos - . Make_vms.com: msdos/Makefile.*: removed zutil.h from some dependency lists - . msdos/Makefile.msc: remove "default rtl link library" info from obj files - . msdos/Makefile.*: use model-dependent name for the built zlib library - . msdos/Makefile.emx, nt/Makefile.emx, nt/Makefile.gcc: - new makefiles, for emx (DOS/OS2), emx&rsxnt and mingw32 (Windows 9x / NT) -- use define instead of typedef for Bytef also for MSC small/medium (Tom Lane) -- replace __far with _far for better portability (Christian Spieler, Tom Lane) -- fix test for errno.h in configure (Tim Newsham) - -Changes in 1.1.2 (19 March 98) -- added contrib/minzip, mini zip and unzip based on zlib (Gilles Vollant) - See http://www.winimage.com/zLibDll/unzip.html -- preinitialize the inflate tables for fixed codes, to make the code - completely thread safe (Mark) -- some simplifications and slight speed-up to the inflate code (Mark) -- fix gzeof on non-compressed files (Allan Schrum) -- add -std1 option in configure for OSF1 to fix gzprintf (Martin Mokrejs) -- use default value of 4K for Z_BUFSIZE for 16-bit MSDOS (Tim Wegner + Glenn) -- added os2/Makefile.def and os2/zlib.def (Andrew Zabolotny) -- add shared lib support for UNIX_SV4.2MP (MATSUURA Takanori) -- do not wrap extern "C" around system includes (Tom Lane) -- mention zlib binding for TCL in README (Andreas Kupries) -- added amiga/Makefile.pup for Amiga powerUP SAS/C PPC (Andreas Kleinert) -- allow "make install prefix=..." even after configure (Glenn Randers-Pehrson) -- allow "configure --prefix $HOME" (Tim Mooney) -- remove warnings in example.c and gzio.c (Glenn Randers-Pehrson) -- move Makefile.sas to amiga/Makefile.sas - -Changes in 1.1.1 (27 Feb 98) -- fix macros _tr_tally_* in deflate.h for debug mode (Glenn Randers-Pehrson) -- remove block truncation heuristic which had very marginal effect for zlib - (smaller lit_bufsize than in gzip 1.2.4) and degraded a little the - compression ratio on some files. This also allows inlining _tr_tally for - matches in deflate_slow. -- added msdos/Makefile.w32 for WIN32 Microsoft Visual C++ (Bob Frazier) - -Changes in 1.1.0 (24 Feb 98) -- do not return STREAM_END prematurely in inflate (John Bowler) -- revert to the zlib 1.0.8 inflate to avoid the gcc 2.8.0 bug (Jeremy Buhler) -- compile with -DFASTEST to get compression code optimized for speed only -- in minigzip, try mmap'ing the input file first (Miguel Albrecht) -- increase size of I/O buffers in minigzip.c and gzio.c (not a big gain - on Sun but significant on HP) - -- add a pointer to experimental unzip library in README (Gilles Vollant) -- initialize variable gcc in configure (Chris Herborth) - -Changes in 1.0.9 (17 Feb 1998) -- added gzputs and gzgets functions -- do not clear eof flag in gzseek (Mark Diekhans) -- fix gzseek for files in transparent mode (Mark Diekhans) -- do not assume that vsprintf returns the number of bytes written (Jens Krinke) -- replace EXPORT with ZEXPORT to avoid conflict with other programs -- added compress2 in zconf.h, zlib.def, zlib.dnt -- new asm code from Gilles Vollant in contrib/asm386 -- simplify the inflate code (Mark): - . Replace ZALLOC's in huft_build() with single ZALLOC in inflate_blocks_new() - . ZALLOC the length list in inflate_trees_fixed() instead of using stack - . ZALLOC the value area for huft_build() instead of using stack - . Simplify Z_FINISH check in inflate() - -- Avoid gcc 2.8.0 comparison bug a little differently than zlib 1.0.8 -- in inftrees.c, avoid cc -O bug on HP (Farshid Elahi) -- in zconf.h move the ZLIB_DLL stuff earlier to avoid problems with - the declaration of FAR (Gilles VOllant) -- install libz.so* with mode 755 (executable) instead of 644 (Marc Lehmann) -- read_buf buf parameter of type Bytef* instead of charf* -- zmemcpy parameters are of type Bytef*, not charf* (Joseph Strout) -- do not redeclare unlink in minigzip.c for WIN32 (John Bowler) -- fix check for presence of directories in "make install" (Ian Willis) - -Changes in 1.0.8 (27 Jan 1998) -- fixed offsets in contrib/asm386/gvmat32.asm (Gilles Vollant) -- fix gzgetc and gzputc for big endian systems (Markus Oberhumer) -- added compress2() to allow setting the compression level -- include sys/types.h to get off_t on some systems (Marc Lehmann & QingLong) -- use constant arrays for the static trees in trees.c instead of computing - them at run time (thanks to Ken Raeburn for this suggestion). To create - trees.h, compile with GEN_TREES_H and run "make test". -- check return code of example in "make test" and display result -- pass minigzip command line options to file_compress -- simplifying code of inflateSync to avoid gcc 2.8 bug - -- support CC="gcc -Wall" in configure -s (QingLong) -- avoid a flush caused by ftell in gzopen for write mode (Ken Raeburn) -- fix test for shared library support to avoid compiler warnings -- zlib.lib -> zlib.dll in msdos/zlib.rc (Gilles Vollant) -- check for TARGET_OS_MAC in addition to MACOS (Brad Pettit) -- do not use fdopen for Metrowerks on Mac (Brad Pettit)) -- add checks for gzputc and gzputc in example.c -- avoid warnings in gzio.c and deflate.c (Andreas Kleinert) -- use const for the CRC table (Ken Raeburn) -- fixed "make uninstall" for shared libraries -- use Tracev instead of Trace in infblock.c -- in example.c use correct compressed length for test_sync -- suppress +vnocompatwarnings in configure for HPUX (not always supported) - -Changes in 1.0.7 (20 Jan 1998) -- fix gzseek which was broken in write mode -- return error for gzseek to negative absolute position -- fix configure for Linux (Chun-Chung Chen) -- increase stack space for MSC (Tim Wegner) -- get_crc_table and inflateSyncPoint are EXPORTed (Gilles Vollant) -- define EXPORTVA for gzprintf (Gilles Vollant) -- added man page zlib.3 (Rick Rodgers) -- for contrib/untgz, fix makedir() and improve Makefile - -- check gzseek in write mode in example.c -- allocate extra buffer for seeks only if gzseek is actually called -- avoid signed/unsigned comparisons (Tim Wegner, Gilles Vollant) -- add inflateSyncPoint in zconf.h -- fix list of exported functions in nt/zlib.dnt and mdsos/zlib.def - -Changes in 1.0.6 (19 Jan 1998) -- add functions gzprintf, gzputc, gzgetc, gztell, gzeof, gzseek, gzrewind and - gzsetparams (thanks to Roland Giersig and Kevin Ruland for some of this code) -- Fix a deflate bug occurring only with compression level 0 (thanks to - Andy Buckler for finding this one). -- In minigzip, pass transparently also the first byte for .Z files. -- return Z_BUF_ERROR instead of Z_OK if output buffer full in uncompress() -- check Z_FINISH in inflate (thanks to Marc Schluper) -- Implement deflateCopy (thanks to Adam Costello) -- make static libraries by default in configure, add --shared option. -- move MSDOS or Windows specific files to directory msdos -- suppress the notion of partial flush to simplify the interface - (but the symbol Z_PARTIAL_FLUSH is kept for compatibility with 1.0.4) -- suppress history buffer provided by application to simplify the interface - (this feature was not implemented anyway in 1.0.4) -- next_in and avail_in must be initialized before calling inflateInit or - inflateInit2 -- add EXPORT in all exported functions (for Windows DLL) -- added Makefile.nt (thanks to Stephen Williams) -- added the unsupported "contrib" directory: - contrib/asm386/ by Gilles Vollant - 386 asm code replacing longest_match(). - contrib/iostream/ by Kevin Ruland - A C++ I/O streams interface to the zlib gz* functions - contrib/iostream2/ by Tyge Løvset - Another C++ I/O streams interface - contrib/untgz/ by "Pedro A. Aranda Guti\irrez" - A very simple tar.gz file extractor using zlib - contrib/visual-basic.txt by Carlos Rios - How to use compress(), uncompress() and the gz* functions from VB. -- pass params -f (filtered data), -h (huffman only), -1 to -9 (compression - level) in minigzip (thanks to Tom Lane) - -- use const for rommable constants in deflate -- added test for gzseek and gztell in example.c -- add undocumented function inflateSyncPoint() (hack for Paul Mackerras) -- add undocumented function zError to convert error code to string - (for Tim Smithers) -- Allow compilation of gzio with -DNO_DEFLATE to avoid the compression code. -- Use default memcpy for Symantec MSDOS compiler. -- Add EXPORT keyword for check_func (needed for Windows DLL) -- add current directory to LD_LIBRARY_PATH for "make test" -- create also a link for libz.so.1 -- added support for FUJITSU UXP/DS (thanks to Toshiaki Nomura) -- use $(SHAREDLIB) instead of libz.so in Makefile.in (for HPUX) -- added -soname for Linux in configure (Chun-Chung Chen, -- assign numbers to the exported functions in zlib.def (for Windows DLL) -- add advice in zlib.h for best usage of deflateSetDictionary -- work around compiler bug on Atari (cast Z_NULL in call of s->checkfn) -- allow compilation with ANSI keywords only enabled for TurboC in large model -- avoid "versionString"[0] (Borland bug) -- add NEED_DUMMY_RETURN for Borland -- use variable z_verbose for tracing in debug mode (L. Peter Deutsch). -- allow compilation with CC -- defined STDC for OS/2 (David Charlap) -- limit external names to 8 chars for MVS (Thomas Lund) -- in minigzip.c, use static buffers only for 16-bit systems -- fix suffix check for "minigzip -d foo.gz" -- do not return an error for the 2nd of two consecutive gzflush() (Felix Lee) -- use _fdopen instead of fdopen for MSC >= 6.0 (Thomas Fanslau) -- added makelcc.bat for lcc-win32 (Tom St Denis) -- in Makefile.dj2, use copy and del instead of install and rm (Frank Donahoe) -- Avoid expanded $Id$. Use "rcs -kb" or "cvs admin -kb" to avoid Id expansion. -- check for unistd.h in configure (for off_t) -- remove useless check parameter in inflate_blocks_free -- avoid useless assignment of s->check to itself in inflate_blocks_new -- do not flush twice in gzclose (thanks to Ken Raeburn) -- rename FOPEN as F_OPEN to avoid clash with /usr/include/sys/file.h -- use NO_ERRNO_H instead of enumeration of operating systems with errno.h -- work around buggy fclose on pipes for HP/UX -- support zlib DLL with BORLAND C++ 5.0 (thanks to Glenn Randers-Pehrson) -- fix configure if CC is already equal to gcc - -Changes in 1.0.5 (3 Jan 98) -- Fix inflate to terminate gracefully when fed corrupted or invalid data -- Use const for rommable constants in inflate -- Eliminate memory leaks on error conditions in inflate -- Removed some vestigial code in inflate -- Update web address in README - -Changes in 1.0.4 (24 Jul 96) -- In very rare conditions, deflate(s, Z_FINISH) could fail to produce an EOF - bit, so the decompressor could decompress all the correct data but went - on to attempt decompressing extra garbage data. This affected minigzip too. -- zlibVersion and gzerror return const char* (needed for DLL) -- port to RISCOS (no fdopen, no multiple dots, no unlink, no fileno) -- use z_error only for DEBUG (avoid problem with DLLs) - -Changes in 1.0.3 (2 Jul 96) -- use z_streamp instead of z_stream *, which is now a far pointer in MSDOS - small and medium models; this makes the library incompatible with previous - versions for these models. (No effect in large model or on other systems.) -- return OK instead of BUF_ERROR if previous deflate call returned with - avail_out as zero but there is nothing to do -- added memcmp for non STDC compilers -- define NO_DUMMY_DECL for more Mac compilers (.h files merged incorrectly) -- define __32BIT__ if __386__ or i386 is defined (pb. with Watcom and SCO) -- better check for 16-bit mode MSC (avoids problem with Symantec) - -Changes in 1.0.2 (23 May 96) -- added Windows DLL support -- added a function zlibVersion (for the DLL support) -- fixed declarations using Bytef in infutil.c (pb with MSDOS medium model) -- Bytef is define's instead of typedef'd only for Borland C -- avoid reading uninitialized memory in example.c -- mention in README that the zlib format is now RFC1950 -- updated Makefile.dj2 -- added algorithm.doc - -Changes in 1.0.1 (20 May 96) [1.0 skipped to avoid confusion] -- fix array overlay in deflate.c which sometimes caused bad compressed data -- fix inflate bug with empty stored block -- fix MSDOS medium model which was broken in 0.99 -- fix deflateParams() which could generated bad compressed data. -- Bytef is define'd instead of typedef'ed (work around Borland bug) -- added an INDEX file -- new makefiles for DJGPP (Makefile.dj2), 32-bit Borland (Makefile.b32), - Watcom (Makefile.wat), Amiga SAS/C (Makefile.sas) -- speed up adler32 for modern machines without auto-increment -- added -ansi for IRIX in configure -- static_init_done in trees.c is an int -- define unlink as delete for VMS -- fix configure for QNX -- add configure branch for SCO and HPUX -- avoid many warnings (unused variables, dead assignments, etc...) -- no fdopen for BeOS -- fix the Watcom fix for 32 bit mode (define FAR as empty) -- removed redefinition of Byte for MKWERKS -- work around an MWKERKS bug (incorrect merge of all .h files) - -Changes in 0.99 (27 Jan 96) -- allow preset dictionary shared between compressor and decompressor -- allow compression level 0 (no compression) -- add deflateParams in zlib.h: allow dynamic change of compression level - and compression strategy. -- test large buffers and deflateParams in example.c -- add optional "configure" to build zlib as a shared library -- suppress Makefile.qnx, use configure instead -- fixed deflate for 64-bit systems (detected on Cray) -- fixed inflate_blocks for 64-bit systems (detected on Alpha) -- declare Z_DEFLATED in zlib.h (possible parameter for deflateInit2) -- always return Z_BUF_ERROR when deflate() has nothing to do -- deflateInit and inflateInit are now macros to allow version checking -- prefix all global functions and types with z_ with -DZ_PREFIX -- make falloc completely reentrant (inftrees.c) -- fixed very unlikely race condition in ct_static_init -- free in reverse order of allocation to help memory manager -- use zlib-1.0/* instead of zlib/* inside the tar.gz -- make zlib warning-free with "gcc -O3 -Wall -Wwrite-strings -Wpointer-arith - -Wconversion -Wstrict-prototypes -Wmissing-prototypes" -- allow gzread on concatenated .gz files -- deflateEnd now returns Z_DATA_ERROR if it was premature -- deflate is finally (?) fully deterministic (no matches beyond end of input) -- Document Z_SYNC_FLUSH -- add uninstall in Makefile -- Check for __cpluplus in zlib.h -- Better test in ct_align for partial flush -- avoid harmless warnings for Borland C++ -- initialize hash_head in deflate.c -- avoid warning on fdopen (gzio.c) for HP cc -Aa -- include stdlib.h for STDC compilers -- include errno.h for Cray -- ignore error if ranlib doesn't exist -- call ranlib twice for NeXTSTEP -- use exec_prefix instead of prefix for libz.a -- renamed ct_* as _tr_* to avoid conflict with applications -- clear z->msg in inflateInit2 before any error return -- initialize opaque in example.c, gzio.c, deflate.c and inflate.c -- fixed typo in zconf.h (_GNUC__ => __GNUC__) -- check for WIN32 in zconf.h and zutil.c (avoid farmalloc in 32-bit mode) -- fix typo in Make_vms.com (f$trnlnm -> f$getsyi) -- in fcalloc, normalize pointer if size > 65520 bytes -- don't use special fcalloc for 32 bit Borland C++ -- use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc... -- use Z_BINARY instead of BINARY -- document that gzclose after gzdopen will close the file -- allow "a" as mode in gzopen. -- fix error checking in gzread -- allow skipping .gz extra-field on pipes -- added reference to Perl interface in README -- put the crc table in FAR data (I dislike more and more the medium model :) -- added get_crc_table -- added a dimension to all arrays (Borland C can't count). -- workaround Borland C bug in declaration of inflate_codes_new & inflate_fast -- guard against multiple inclusion of *.h (for precompiled header on Mac) -- Watcom C pretends to be Microsoft C small model even in 32 bit mode. -- don't use unsized arrays to avoid silly warnings by Visual C++: - warning C4746: 'inflate_mask' : unsized array treated as '__far' - (what's wrong with far data in far model?). -- define enum out of inflate_blocks_state to allow compilation with C++ - -Changes in 0.95 (16 Aug 95) -- fix MSDOS small and medium model (now easier to adapt to any compiler) -- inlined send_bits -- fix the final (:-) bug for deflate with flush (output was correct but - not completely flushed in rare occasions). -- default window size is same for compression and decompression - (it's now sufficient to set MAX_WBITS in zconf.h). -- voidp -> voidpf and voidnp -> voidp (for consistency with other - typedefs and because voidnp was not near in large model). - -Changes in 0.94 (13 Aug 95) -- support MSDOS medium model -- fix deflate with flush (could sometimes generate bad output) -- fix deflateReset (zlib header was incorrectly suppressed) -- added support for VMS -- allow a compression level in gzopen() -- gzflush now calls fflush -- For deflate with flush, flush even if no more input is provided. -- rename libgz.a as libz.a -- avoid complex expression in infcodes.c triggering Turbo C bug -- work around a problem with gcc on Alpha (in INSERT_STRING) -- don't use inline functions (problem with some gcc versions) -- allow renaming of Byte, uInt, etc... with #define. -- avoid warning about (unused) pointer before start of array in deflate.c -- avoid various warnings in gzio.c, example.c, infblock.c, adler32.c, zutil.c -- avoid reserved word 'new' in trees.c - -Changes in 0.93 (25 June 95) -- temporarily disable inline functions -- make deflate deterministic -- give enough lookahead for PARTIAL_FLUSH -- Set binary mode for stdin/stdout in minigzip.c for OS/2 -- don't even use signed char in inflate (not portable enough) -- fix inflate memory leak for segmented architectures - -Changes in 0.92 (3 May 95) -- don't assume that char is signed (problem on SGI) -- Clear bit buffer when starting a stored block -- no memcpy on Pyramid -- suppressed inftest.c -- optimized fill_window, put longest_match inline for gcc -- optimized inflate on stored blocks. -- untabify all sources to simplify patches - -Changes in 0.91 (2 May 95) -- Default MEM_LEVEL is 8 (not 9 for Unix) as documented in zlib.h -- Document the memory requirements in zconf.h -- added "make install" -- fix sync search logic in inflateSync -- deflate(Z_FULL_FLUSH) now works even if output buffer too short -- after inflateSync, don't scare people with just "lo world" -- added support for DJGPP - -Changes in 0.9 (1 May 95) -- don't assume that zalloc clears the allocated memory (the TurboC bug - was Mark's bug after all :) -- let again gzread copy uncompressed data unchanged (was working in 0.71) -- deflate(Z_FULL_FLUSH), inflateReset and inflateSync are now fully implemented -- added a test of inflateSync in example.c -- moved MAX_WBITS to zconf.h because users might want to change that. -- document explicitly that zalloc(64K) on MSDOS must return a normalized - pointer (zero offset) -- added Makefiles for Microsoft C, Turbo C, Borland C++ -- faster crc32() - -Changes in 0.8 (29 April 95) -- added fast inflate (inffast.c) -- deflate(Z_FINISH) now returns Z_STREAM_END when done. Warning: this - is incompatible with previous versions of zlib which returned Z_OK. -- work around a TurboC compiler bug (bad code for b << 0, see infutil.h) - (actually that was not a compiler bug, see 0.81 above) -- gzread no longer reads one extra byte in certain cases -- In gzio destroy(), don't reference a freed structure -- avoid many warnings for MSDOS -- avoid the ERROR symbol which is used by MS Windows - -Changes in 0.71 (14 April 95) -- Fixed more MSDOS compilation problems :( There is still a bug with - TurboC large model. - -Changes in 0.7 (14 April 95) -- Added full inflate support. -- Simplified the crc32() interface. The pre- and post-conditioning - (one's complement) is now done inside crc32(). WARNING: this is - incompatible with previous versions; see zlib.h for the new usage. - -Changes in 0.61 (12 April 95) -- workaround for a bug in TurboC. example and minigzip now work on MSDOS. - -Changes in 0.6 (11 April 95) -- added minigzip.c -- added gzdopen to reopen a file descriptor as gzFile -- added transparent reading of non-gziped files in gzread. -- fixed bug in gzread (don't read crc as data) -- fixed bug in destroy (gzio.c) (don't return Z_STREAM_END for gzclose). -- don't allocate big arrays in the stack (for MSDOS) -- fix some MSDOS compilation problems - -Changes in 0.5: -- do real compression in deflate.c. Z_PARTIAL_FLUSH is supported but - not yet Z_FULL_FLUSH. -- support decompression but only in a single step (forced Z_FINISH) -- added opaque object for zalloc and zfree. -- added deflateReset and inflateReset -- added a variable zlib_version for consistency checking. -- renamed the 'filter' parameter of deflateInit2 as 'strategy'. - Added Z_FILTERED and Z_HUFFMAN_ONLY constants. - -Changes in 0.4: -- avoid "zip" everywhere, use zlib instead of ziplib. -- suppress Z_BLOCK_FLUSH, interpret Z_PARTIAL_FLUSH as block flush - if compression method == 8. -- added adler32 and crc32 -- renamed deflateOptions as deflateInit2, call one or the other but not both -- added the method parameter for deflateInit2. -- added inflateInit2 -- simplied considerably deflateInit and inflateInit by not supporting - user-provided history buffer. This is supported only in deflateInit2 - and inflateInit2. - -Changes in 0.3: -- prefix all macro names with Z_ -- use Z_FINISH instead of deflateEnd to finish compression. -- added Z_HUFFMAN_ONLY -- added gzerror() diff --git a/src/beast/test/zlib/zlib-1.2.8/FAQ b/src/beast/test/zlib/zlib-1.2.8/FAQ deleted file mode 100644 index 99b7cf92e45..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/FAQ +++ /dev/null @@ -1,368 +0,0 @@ - - Frequently Asked Questions about zlib - - -If your question is not there, please check the zlib home page -http://zlib.net/ which may have more recent information. -The lastest zlib FAQ is at http://zlib.net/zlib_faq.html - - - 1. Is zlib Y2K-compliant? - - Yes. zlib doesn't handle dates. - - 2. Where can I get a Windows DLL version? - - The zlib sources can be compiled without change to produce a DLL. See the - file win32/DLL_FAQ.txt in the zlib distribution. Pointers to the - precompiled DLL are found in the zlib web site at http://zlib.net/ . - - 3. Where can I get a Visual Basic interface to zlib? - - See - * http://marknelson.us/1997/01/01/zlib-engine/ - * win32/DLL_FAQ.txt in the zlib distribution - - 4. compress() returns Z_BUF_ERROR. - - Make sure that before the call of compress(), the length of the compressed - buffer is equal to the available size of the compressed buffer and not - zero. For Visual Basic, check that this parameter is passed by reference - ("as any"), not by value ("as long"). - - 5. deflate() or inflate() returns Z_BUF_ERROR. - - Before making the call, make sure that avail_in and avail_out are not zero. - When setting the parameter flush equal to Z_FINISH, also make sure that - avail_out is big enough to allow processing all pending input. Note that a - Z_BUF_ERROR is not fatal--another call to deflate() or inflate() can be - made with more input or output space. A Z_BUF_ERROR may in fact be - unavoidable depending on how the functions are used, since it is not - possible to tell whether or not there is more output pending when - strm.avail_out returns with zero. See http://zlib.net/zlib_how.html for a - heavily annotated example. - - 6. Where's the zlib documentation (man pages, etc.)? - - It's in zlib.h . Examples of zlib usage are in the files test/example.c - and test/minigzip.c, with more in examples/ . - - 7. Why don't you use GNU autoconf or libtool or ...? - - Because we would like to keep zlib as a very small and simple package. - zlib is rather portable and doesn't need much configuration. - - 8. I found a bug in zlib. - - Most of the time, such problems are due to an incorrect usage of zlib. - Please try to reproduce the problem with a small program and send the - corresponding source to us at zlib@gzip.org . Do not send multi-megabyte - data files without prior agreement. - - 9. Why do I get "undefined reference to gzputc"? - - If "make test" produces something like - - example.o(.text+0x154): undefined reference to `gzputc' - - check that you don't have old files libz.* in /usr/lib, /usr/local/lib or - /usr/X11R6/lib. Remove any old versions, then do "make install". - -10. I need a Delphi interface to zlib. - - See the contrib/delphi directory in the zlib distribution. - -11. Can zlib handle .zip archives? - - Not by itself, no. See the directory contrib/minizip in the zlib - distribution. - -12. Can zlib handle .Z files? - - No, sorry. You have to spawn an uncompress or gunzip subprocess, or adapt - the code of uncompress on your own. - -13. How can I make a Unix shared library? - - By default a shared (and a static) library is built for Unix. So: - - make distclean - ./configure - make - -14. How do I install a shared zlib library on Unix? - - After the above, then: - - make install - - However, many flavors of Unix come with a shared zlib already installed. - Before going to the trouble of compiling a shared version of zlib and - trying to install it, you may want to check if it's already there! If you - can #include , it's there. The -lz option will probably link to - it. You can check the version at the top of zlib.h or with the - ZLIB_VERSION symbol defined in zlib.h . - -15. I have a question about OttoPDF. - - We are not the authors of OttoPDF. The real author is on the OttoPDF web - site: Joel Hainley, jhainley@myndkryme.com. - -16. Can zlib decode Flate data in an Adobe PDF file? - - Yes. See http://www.pdflib.com/ . To modify PDF forms, see - http://sourceforge.net/projects/acroformtool/ . - -17. Why am I getting this "register_frame_info not found" error on Solaris? - - After installing zlib 1.1.4 on Solaris 2.6, running applications using zlib - generates an error such as: - - ld.so.1: rpm: fatal: relocation error: file /usr/local/lib/libz.so: - symbol __register_frame_info: referenced symbol not found - - The symbol __register_frame_info is not part of zlib, it is generated by - the C compiler (cc or gcc). You must recompile applications using zlib - which have this problem. This problem is specific to Solaris. See - http://www.sunfreeware.com for Solaris versions of zlib and applications - using zlib. - -18. Why does gzip give an error on a file I make with compress/deflate? - - The compress and deflate functions produce data in the zlib format, which - is different and incompatible with the gzip format. The gz* functions in - zlib on the other hand use the gzip format. Both the zlib and gzip formats - use the same compressed data format internally, but have different headers - and trailers around the compressed data. - -19. Ok, so why are there two different formats? - - The gzip format was designed to retain the directory information about a - single file, such as the name and last modification date. The zlib format - on the other hand was designed for in-memory and communication channel - applications, and has a much more compact header and trailer and uses a - faster integrity check than gzip. - -20. Well that's nice, but how do I make a gzip file in memory? - - You can request that deflate write the gzip format instead of the zlib - format using deflateInit2(). You can also request that inflate decode the - gzip format using inflateInit2(). Read zlib.h for more details. - -21. Is zlib thread-safe? - - Yes. However any library routines that zlib uses and any application- - provided memory allocation routines must also be thread-safe. zlib's gz* - functions use stdio library routines, and most of zlib's functions use the - library memory allocation routines by default. zlib's *Init* functions - allow for the application to provide custom memory allocation routines. - - Of course, you should only operate on any given zlib or gzip stream from a - single thread at a time. - -22. Can I use zlib in my commercial application? - - Yes. Please read the license in zlib.h. - -23. Is zlib under the GNU license? - - No. Please read the license in zlib.h. - -24. The license says that altered source versions must be "plainly marked". So - what exactly do I need to do to meet that requirement? - - You need to change the ZLIB_VERSION and ZLIB_VERNUM #defines in zlib.h. In - particular, the final version number needs to be changed to "f", and an - identification string should be appended to ZLIB_VERSION. Version numbers - x.x.x.f are reserved for modifications to zlib by others than the zlib - maintainers. For example, if the version of the base zlib you are altering - is "1.2.3.4", then in zlib.h you should change ZLIB_VERNUM to 0x123f, and - ZLIB_VERSION to something like "1.2.3.f-zachary-mods-v3". You can also - update the version strings in deflate.c and inftrees.c. - - For altered source distributions, you should also note the origin and - nature of the changes in zlib.h, as well as in ChangeLog and README, along - with the dates of the alterations. The origin should include at least your - name (or your company's name), and an email address to contact for help or - issues with the library. - - Note that distributing a compiled zlib library along with zlib.h and - zconf.h is also a source distribution, and so you should change - ZLIB_VERSION and ZLIB_VERNUM and note the origin and nature of the changes - in zlib.h as you would for a full source distribution. - -25. Will zlib work on a big-endian or little-endian architecture, and can I - exchange compressed data between them? - - Yes and yes. - -26. Will zlib work on a 64-bit machine? - - Yes. It has been tested on 64-bit machines, and has no dependence on any - data types being limited to 32-bits in length. If you have any - difficulties, please provide a complete problem report to zlib@gzip.org - -27. Will zlib decompress data from the PKWare Data Compression Library? - - No. The PKWare DCL uses a completely different compressed data format than - does PKZIP and zlib. However, you can look in zlib's contrib/blast - directory for a possible solution to your problem. - -28. Can I access data randomly in a compressed stream? - - No, not without some preparation. If when compressing you periodically use - Z_FULL_FLUSH, carefully write all the pending data at those points, and - keep an index of those locations, then you can start decompression at those - points. You have to be careful to not use Z_FULL_FLUSH too often, since it - can significantly degrade compression. Alternatively, you can scan a - deflate stream once to generate an index, and then use that index for - random access. See examples/zran.c . - -29. Does zlib work on MVS, OS/390, CICS, etc.? - - It has in the past, but we have not heard of any recent evidence. There - were working ports of zlib 1.1.4 to MVS, but those links no longer work. - If you know of recent, successful applications of zlib on these operating - systems, please let us know. Thanks. - -30. Is there some simpler, easier to read version of inflate I can look at to - understand the deflate format? - - First off, you should read RFC 1951. Second, yes. Look in zlib's - contrib/puff directory. - -31. Does zlib infringe on any patents? - - As far as we know, no. In fact, that was originally the whole point behind - zlib. Look here for some more information: - - http://www.gzip.org/#faq11 - -32. Can zlib work with greater than 4 GB of data? - - Yes. inflate() and deflate() will process any amount of data correctly. - Each call of inflate() or deflate() is limited to input and output chunks - of the maximum value that can be stored in the compiler's "unsigned int" - type, but there is no limit to the number of chunks. Note however that the - strm.total_in and strm_total_out counters may be limited to 4 GB. These - counters are provided as a convenience and are not used internally by - inflate() or deflate(). The application can easily set up its own counters - updated after each call of inflate() or deflate() to count beyond 4 GB. - compress() and uncompress() may be limited to 4 GB, since they operate in a - single call. gzseek() and gztell() may be limited to 4 GB depending on how - zlib is compiled. See the zlibCompileFlags() function in zlib.h. - - The word "may" appears several times above since there is a 4 GB limit only - if the compiler's "long" type is 32 bits. If the compiler's "long" type is - 64 bits, then the limit is 16 exabytes. - -33. Does zlib have any security vulnerabilities? - - The only one that we are aware of is potentially in gzprintf(). If zlib is - compiled to use sprintf() or vsprintf(), then there is no protection - against a buffer overflow of an 8K string space (or other value as set by - gzbuffer()), other than the caller of gzprintf() assuring that the output - will not exceed 8K. On the other hand, if zlib is compiled to use - snprintf() or vsnprintf(), which should normally be the case, then there is - no vulnerability. The ./configure script will display warnings if an - insecure variation of sprintf() will be used by gzprintf(). Also the - zlibCompileFlags() function will return information on what variant of - sprintf() is used by gzprintf(). - - If you don't have snprintf() or vsnprintf() and would like one, you can - find a portable implementation here: - - http://www.ijs.si/software/snprintf/ - - Note that you should be using the most recent version of zlib. Versions - 1.1.3 and before were subject to a double-free vulnerability, and versions - 1.2.1 and 1.2.2 were subject to an access exception when decompressing - invalid compressed data. - -34. Is there a Java version of zlib? - - Probably what you want is to use zlib in Java. zlib is already included - as part of the Java SDK in the java.util.zip package. If you really want - a version of zlib written in the Java language, look on the zlib home - page for links: http://zlib.net/ . - -35. I get this or that compiler or source-code scanner warning when I crank it - up to maximally-pedantic. Can't you guys write proper code? - - Many years ago, we gave up attempting to avoid warnings on every compiler - in the universe. It just got to be a waste of time, and some compilers - were downright silly as well as contradicted each other. So now, we simply - make sure that the code always works. - -36. Valgrind (or some similar memory access checker) says that deflate is - performing a conditional jump that depends on an uninitialized value. - Isn't that a bug? - - No. That is intentional for performance reasons, and the output of deflate - is not affected. This only started showing up recently since zlib 1.2.x - uses malloc() by default for allocations, whereas earlier versions used - calloc(), which zeros out the allocated memory. Even though the code was - correct, versions 1.2.4 and later was changed to not stimulate these - checkers. - -37. Will zlib read the (insert any ancient or arcane format here) compressed - data format? - - Probably not. Look in the comp.compression FAQ for pointers to various - formats and associated software. - -38. How can I encrypt/decrypt zip files with zlib? - - zlib doesn't support encryption. The original PKZIP encryption is very - weak and can be broken with freely available programs. To get strong - encryption, use GnuPG, http://www.gnupg.org/ , which already includes zlib - compression. For PKZIP compatible "encryption", look at - http://www.info-zip.org/ - -39. What's the difference between the "gzip" and "deflate" HTTP 1.1 encodings? - - "gzip" is the gzip format, and "deflate" is the zlib format. They should - probably have called the second one "zlib" instead to avoid confusion with - the raw deflate compressed data format. While the HTTP 1.1 RFC 2616 - correctly points to the zlib specification in RFC 1950 for the "deflate" - transfer encoding, there have been reports of servers and browsers that - incorrectly produce or expect raw deflate data per the deflate - specification in RFC 1951, most notably Microsoft. So even though the - "deflate" transfer encoding using the zlib format would be the more - efficient approach (and in fact exactly what the zlib format was designed - for), using the "gzip" transfer encoding is probably more reliable due to - an unfortunate choice of name on the part of the HTTP 1.1 authors. - - Bottom line: use the gzip format for HTTP 1.1 encoding. - -40. Does zlib support the new "Deflate64" format introduced by PKWare? - - No. PKWare has apparently decided to keep that format proprietary, since - they have not documented it as they have previous compression formats. In - any case, the compression improvements are so modest compared to other more - modern approaches, that it's not worth the effort to implement. - -41. I'm having a problem with the zip functions in zlib, can you help? - - There are no zip functions in zlib. You are probably using minizip by - Giles Vollant, which is found in the contrib directory of zlib. It is not - part of zlib. In fact none of the stuff in contrib is part of zlib. The - files in there are not supported by the zlib authors. You need to contact - the authors of the respective contribution for help. - -42. The match.asm code in contrib is under the GNU General Public License. - Since it's part of zlib, doesn't that mean that all of zlib falls under the - GNU GPL? - - No. The files in contrib are not part of zlib. They were contributed by - other authors and are provided as a convenience to the user within the zlib - distribution. Each item in contrib has its own license. - -43. Is zlib subject to export controls? What is its ECCN? - - zlib is not subject to export controls, and so is classified as EAR99. - -44. Can you please sign these lengthy legal documents and fax them back to us - so that we can use your software in our product? - - No. Go away. Shoo. diff --git a/src/beast/test/zlib/zlib-1.2.8/INDEX b/src/beast/test/zlib/zlib-1.2.8/INDEX deleted file mode 100644 index 2ba06412048..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/INDEX +++ /dev/null @@ -1,68 +0,0 @@ -CMakeLists.txt cmake build file -ChangeLog history of changes -FAQ Frequently Asked Questions about zlib -INDEX this file -Makefile dummy Makefile that tells you to ./configure -Makefile.in template for Unix Makefile -README guess what -configure configure script for Unix -make_vms.com makefile for VMS -test/example.c zlib usages examples for build testing -test/minigzip.c minimal gzip-like functionality for build testing -test/infcover.c inf*.c code coverage for build coverage testing -treebuild.xml XML description of source file dependencies -zconf.h.cmakein zconf.h template for cmake -zconf.h.in zconf.h template for configure -zlib.3 Man page for zlib -zlib.3.pdf Man page in PDF format -zlib.map Linux symbol information -zlib.pc.in Template for pkg-config descriptor -zlib.pc.cmakein zlib.pc template for cmake -zlib2ansi perl script to convert source files for C++ compilation - -amiga/ makefiles for Amiga SAS C -as400/ makefiles for AS/400 -doc/ documentation for formats and algorithms -msdos/ makefiles for MSDOS -nintendods/ makefile for Nintendo DS -old/ makefiles for various architectures and zlib documentation - files that have not yet been updated for zlib 1.2.x -qnx/ makefiles for QNX -watcom/ makefiles for OpenWatcom -win32/ makefiles for Windows - - zlib public header files (required for library use): -zconf.h -zlib.h - - private source files used to build the zlib library: -adler32.c -compress.c -crc32.c -crc32.h -deflate.c -deflate.h -gzclose.c -gzguts.h -gzlib.c -gzread.c -gzwrite.c -infback.c -inffast.c -inffast.h -inffixed.h -inflate.c -inflate.h -inftrees.c -inftrees.h -trees.c -trees.h -uncompr.c -zutil.c -zutil.h - - source files for sample programs -See examples/README.examples - - unsupported contributions by third parties -See contrib/README.contrib diff --git a/src/beast/test/zlib/zlib-1.2.8/Makefile b/src/beast/test/zlib/zlib-1.2.8/Makefile deleted file mode 100644 index 6bba86c73fc..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -all: - -@echo "Please use ./configure first. Thank you." - -distclean: - make -f Makefile.in distclean diff --git a/src/beast/test/zlib/zlib-1.2.8/Makefile.in b/src/beast/test/zlib/zlib-1.2.8/Makefile.in deleted file mode 100644 index c61aa3008d4..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/Makefile.in +++ /dev/null @@ -1,288 +0,0 @@ -# Makefile for zlib -# Copyright (C) 1995-2013 Jean-loup Gailly, Mark Adler -# For conditions of distribution and use, see copyright notice in zlib.h - -# To compile and test, type: -# ./configure; make test -# Normally configure builds both a static and a shared library. -# If you want to build just a static library, use: ./configure --static - -# To use the asm code, type: -# cp contrib/asm?86/match.S ./match.S -# make LOC=-DASMV OBJA=match.o - -# To install /usr/local/lib/libz.* and /usr/local/include/zlib.h, type: -# make install -# To install in $HOME instead of /usr/local, use: -# make install prefix=$HOME - -CC=cc - -CFLAGS=-O -#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7 -#CFLAGS=-g -DDEBUG -#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \ -# -Wstrict-prototypes -Wmissing-prototypes - -SFLAGS=-O -LDFLAGS= -TEST_LDFLAGS=-L. libz.a -LDSHARED=$(CC) -CPP=$(CC) -E - -STATICLIB=libz.a -SHAREDLIB=libz.so -SHAREDLIBV=libz.so.1.2.8 -SHAREDLIBM=libz.so.1 -LIBS=$(STATICLIB) $(SHAREDLIBV) - -AR=ar -ARFLAGS=rc -RANLIB=ranlib -LDCONFIG=ldconfig -LDSHAREDLIBC=-lc -TAR=tar -SHELL=/bin/sh -EXE= - -prefix = /usr/local -exec_prefix = ${prefix} -libdir = ${exec_prefix}/lib -sharedlibdir = ${libdir} -includedir = ${prefix}/include -mandir = ${prefix}/share/man -man3dir = ${mandir}/man3 -pkgconfigdir = ${libdir}/pkgconfig - -OBJZ = adler32.o crc32.o deflate.o infback.o inffast.o inflate.o inftrees.o trees.o zutil.o -OBJG = compress.o uncompr.o gzclose.o gzlib.o gzread.o gzwrite.o -OBJC = $(OBJZ) $(OBJG) - -PIC_OBJZ = adler32.lo crc32.lo deflate.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo zutil.lo -PIC_OBJG = compress.lo uncompr.lo gzclose.lo gzlib.lo gzread.lo gzwrite.lo -PIC_OBJC = $(PIC_OBJZ) $(PIC_OBJG) - -# to use the asm code: make OBJA=match.o, PIC_OBJA=match.lo -OBJA = -PIC_OBJA = - -OBJS = $(OBJC) $(OBJA) - -PIC_OBJS = $(PIC_OBJC) $(PIC_OBJA) - -all: static shared - -static: example$(EXE) minigzip$(EXE) - -shared: examplesh$(EXE) minigzipsh$(EXE) - -all64: example64$(EXE) minigzip64$(EXE) - -check: test - -test: all teststatic testshared - -teststatic: static - @TMPST=tmpst_$$; \ - if echo hello world | ./minigzip | ./minigzip -d && ./example $$TMPST ; then \ - echo ' *** zlib test OK ***'; \ - else \ - echo ' *** zlib test FAILED ***'; false; \ - fi; \ - rm -f $$TMPST - -testshared: shared - @LD_LIBRARY_PATH=`pwd`:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \ - LD_LIBRARYN32_PATH=`pwd`:$(LD_LIBRARYN32_PATH) ; export LD_LIBRARYN32_PATH; \ - DYLD_LIBRARY_PATH=`pwd`:$(DYLD_LIBRARY_PATH) ; export DYLD_LIBRARY_PATH; \ - SHLIB_PATH=`pwd`:$(SHLIB_PATH) ; export SHLIB_PATH; \ - TMPSH=tmpsh_$$; \ - if echo hello world | ./minigzipsh | ./minigzipsh -d && ./examplesh $$TMPSH; then \ - echo ' *** zlib shared test OK ***'; \ - else \ - echo ' *** zlib shared test FAILED ***'; false; \ - fi; \ - rm -f $$TMPSH - -test64: all64 - @TMP64=tmp64_$$; \ - if echo hello world | ./minigzip64 | ./minigzip64 -d && ./example64 $$TMP64; then \ - echo ' *** zlib 64-bit test OK ***'; \ - else \ - echo ' *** zlib 64-bit test FAILED ***'; false; \ - fi; \ - rm -f $$TMP64 - -infcover.o: test/infcover.c zlib.h zconf.h - $(CC) $(CFLAGS) -I. -c -o $@ test/infcover.c - -infcover: infcover.o libz.a - $(CC) $(CFLAGS) -o $@ infcover.o libz.a - -cover: infcover - rm -f *.gcda - ./infcover - gcov inf*.c - -libz.a: $(OBJS) - $(AR) $(ARFLAGS) $@ $(OBJS) - -@ ($(RANLIB) $@ || true) >/dev/null 2>&1 - -match.o: match.S - $(CPP) match.S > _match.s - $(CC) -c _match.s - mv _match.o match.o - rm -f _match.s - -match.lo: match.S - $(CPP) match.S > _match.s - $(CC) -c -fPIC _match.s - mv _match.o match.lo - rm -f _match.s - -example.o: test/example.c zlib.h zconf.h - $(CC) $(CFLAGS) -I. -c -o $@ test/example.c - -minigzip.o: test/minigzip.c zlib.h zconf.h - $(CC) $(CFLAGS) -I. -c -o $@ test/minigzip.c - -example64.o: test/example.c zlib.h zconf.h - $(CC) $(CFLAGS) -I. -D_FILE_OFFSET_BITS=64 -c -o $@ test/example.c - -minigzip64.o: test/minigzip.c zlib.h zconf.h - $(CC) $(CFLAGS) -I. -D_FILE_OFFSET_BITS=64 -c -o $@ test/minigzip.c - -.SUFFIXES: .lo - -.c.lo: - -@mkdir objs 2>/dev/null || test -d objs - $(CC) $(SFLAGS) -DPIC -c -o objs/$*.o $< - -@mv objs/$*.o $@ - -placebo $(SHAREDLIBV): $(PIC_OBJS) libz.a - $(LDSHARED) $(SFLAGS) -o $@ $(PIC_OBJS) $(LDSHAREDLIBC) $(LDFLAGS) - rm -f $(SHAREDLIB) $(SHAREDLIBM) - ln -s $@ $(SHAREDLIB) - ln -s $@ $(SHAREDLIBM) - -@rmdir objs - -example$(EXE): example.o $(STATICLIB) - $(CC) $(CFLAGS) -o $@ example.o $(TEST_LDFLAGS) - -minigzip$(EXE): minigzip.o $(STATICLIB) - $(CC) $(CFLAGS) -o $@ minigzip.o $(TEST_LDFLAGS) - -examplesh$(EXE): example.o $(SHAREDLIBV) - $(CC) $(CFLAGS) -o $@ example.o -L. $(SHAREDLIBV) - -minigzipsh$(EXE): minigzip.o $(SHAREDLIBV) - $(CC) $(CFLAGS) -o $@ minigzip.o -L. $(SHAREDLIBV) - -example64$(EXE): example64.o $(STATICLIB) - $(CC) $(CFLAGS) -o $@ example64.o $(TEST_LDFLAGS) - -minigzip64$(EXE): minigzip64.o $(STATICLIB) - $(CC) $(CFLAGS) -o $@ minigzip64.o $(TEST_LDFLAGS) - -install-libs: $(LIBS) - -@if [ ! -d $(DESTDIR)$(exec_prefix) ]; then mkdir -p $(DESTDIR)$(exec_prefix); fi - -@if [ ! -d $(DESTDIR)$(libdir) ]; then mkdir -p $(DESTDIR)$(libdir); fi - -@if [ ! -d $(DESTDIR)$(sharedlibdir) ]; then mkdir -p $(DESTDIR)$(sharedlibdir); fi - -@if [ ! -d $(DESTDIR)$(man3dir) ]; then mkdir -p $(DESTDIR)$(man3dir); fi - -@if [ ! -d $(DESTDIR)$(pkgconfigdir) ]; then mkdir -p $(DESTDIR)$(pkgconfigdir); fi - cp $(STATICLIB) $(DESTDIR)$(libdir) - chmod 644 $(DESTDIR)$(libdir)/$(STATICLIB) - -@($(RANLIB) $(DESTDIR)$(libdir)/libz.a || true) >/dev/null 2>&1 - -@if test -n "$(SHAREDLIBV)"; then \ - cp $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir); \ - echo "cp $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)"; \ - chmod 755 $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBV); \ - echo "chmod 755 $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBV)"; \ - rm -f $(DESTDIR)$(sharedlibdir)/$(SHAREDLIB) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBM); \ - ln -s $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIB); \ - ln -s $(SHAREDLIBV) $(DESTDIR)$(sharedlibdir)/$(SHAREDLIBM); \ - ($(LDCONFIG) || true) >/dev/null 2>&1; \ - fi - cp zlib.3 $(DESTDIR)$(man3dir) - chmod 644 $(DESTDIR)$(man3dir)/zlib.3 - cp zlib.pc $(DESTDIR)$(pkgconfigdir) - chmod 644 $(DESTDIR)$(pkgconfigdir)/zlib.pc -# The ranlib in install is needed on NeXTSTEP which checks file times -# ldconfig is for Linux - -install: install-libs - -@if [ ! -d $(DESTDIR)$(includedir) ]; then mkdir -p $(DESTDIR)$(includedir); fi - cp zlib.h zconf.h $(DESTDIR)$(includedir) - chmod 644 $(DESTDIR)$(includedir)/zlib.h $(DESTDIR)$(includedir)/zconf.h - -uninstall: - cd $(DESTDIR)$(includedir) && rm -f zlib.h zconf.h - cd $(DESTDIR)$(libdir) && rm -f libz.a; \ - if test -n "$(SHAREDLIBV)" -a -f $(SHAREDLIBV); then \ - rm -f $(SHAREDLIBV) $(SHAREDLIB) $(SHAREDLIBM); \ - fi - cd $(DESTDIR)$(man3dir) && rm -f zlib.3 - cd $(DESTDIR)$(pkgconfigdir) && rm -f zlib.pc - -docs: zlib.3.pdf - -zlib.3.pdf: zlib.3 - groff -mandoc -f H -T ps zlib.3 | ps2pdf - zlib.3.pdf - -zconf.h.cmakein: zconf.h.in - -@ TEMPFILE=zconfh_$$; \ - echo "/#define ZCONF_H/ a\\\\\n#cmakedefine Z_PREFIX\\\\\n#cmakedefine Z_HAVE_UNISTD_H\n" >> $$TEMPFILE &&\ - sed -f $$TEMPFILE zconf.h.in > zconf.h.cmakein &&\ - touch -r zconf.h.in zconf.h.cmakein &&\ - rm $$TEMPFILE - -zconf: zconf.h.in - cp -p zconf.h.in zconf.h - -mostlyclean: clean -clean: - rm -f *.o *.lo *~ \ - example$(EXE) minigzip$(EXE) examplesh$(EXE) minigzipsh$(EXE) \ - example64$(EXE) minigzip64$(EXE) \ - infcover \ - libz.* foo.gz so_locations \ - _match.s maketree contrib/infback9/*.o - rm -rf objs - rm -f *.gcda *.gcno *.gcov - rm -f contrib/infback9/*.gcda contrib/infback9/*.gcno contrib/infback9/*.gcov - -maintainer-clean: distclean -distclean: clean zconf zconf.h.cmakein docs - rm -f Makefile zlib.pc configure.log - -@rm -f .DS_Store - -@printf 'all:\n\t-@echo "Please use ./configure first. Thank you."\n' > Makefile - -@printf '\ndistclean:\n\tmake -f Makefile.in distclean\n' >> Makefile - -@touch -r Makefile.in Makefile - -tags: - etags *.[ch] - -depend: - makedepend -- $(CFLAGS) -- *.[ch] - -# DO NOT DELETE THIS LINE -- make depend depends on it. - -adler32.o zutil.o: zutil.h zlib.h zconf.h -gzclose.o gzlib.o gzread.o gzwrite.o: zlib.h zconf.h gzguts.h -compress.o example.o minigzip.o uncompr.o: zlib.h zconf.h -crc32.o: zutil.h zlib.h zconf.h crc32.h -deflate.o: deflate.h zutil.h zlib.h zconf.h -infback.o inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h inffixed.h -inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h -inftrees.o: zutil.h zlib.h zconf.h inftrees.h -trees.o: deflate.h zutil.h zlib.h zconf.h trees.h - -adler32.lo zutil.lo: zutil.h zlib.h zconf.h -gzclose.lo gzlib.lo gzread.lo gzwrite.lo: zlib.h zconf.h gzguts.h -compress.lo example.lo minigzip.lo uncompr.lo: zlib.h zconf.h -crc32.lo: zutil.h zlib.h zconf.h crc32.h -deflate.lo: deflate.h zutil.h zlib.h zconf.h -infback.lo inflate.lo: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h inffixed.h -inffast.lo: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h -inftrees.lo: zutil.h zlib.h zconf.h inftrees.h -trees.lo: deflate.h zutil.h zlib.h zconf.h trees.h diff --git a/src/beast/test/zlib/zlib-1.2.8/README b/src/beast/test/zlib/zlib-1.2.8/README deleted file mode 100644 index 5ca9d127eda..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/README +++ /dev/null @@ -1,115 +0,0 @@ -ZLIB DATA COMPRESSION LIBRARY - -zlib 1.2.8 is a general purpose data compression library. All the code is -thread safe. The data format used by the zlib library is described by RFCs -(Request for Comments) 1950 to 1952 in the files -http://tools.ietf.org/html/rfc1950 (zlib format), rfc1951 (deflate format) and -rfc1952 (gzip format). - -All functions of the compression library are documented in the file zlib.h -(volunteer to write man pages welcome, contact zlib@gzip.org). A usage example -of the library is given in the file test/example.c which also tests that -the library is working correctly. Another example is given in the file -test/minigzip.c. The compression library itself is composed of all source -files in the root directory. - -To compile all files and run the test program, follow the instructions given at -the top of Makefile.in. In short "./configure; make test", and if that goes -well, "make install" should work for most flavors of Unix. For Windows, use -one of the special makefiles in win32/ or contrib/vstudio/ . For VMS, use -make_vms.com. - -Questions about zlib should be sent to , or to Gilles Vollant - for the Windows DLL version. The zlib home page is -http://zlib.net/ . Before reporting a problem, please check this site to -verify that you have the latest version of zlib; otherwise get the latest -version and check whether the problem still exists or not. - -PLEASE read the zlib FAQ http://zlib.net/zlib_faq.html before asking for help. - -Mark Nelson wrote an article about zlib for the Jan. 1997 -issue of Dr. Dobb's Journal; a copy of the article is available at -http://marknelson.us/1997/01/01/zlib-engine/ . - -The changes made in version 1.2.8 are documented in the file ChangeLog. - -Unsupported third party contributions are provided in directory contrib/ . - -zlib is available in Java using the java.util.zip package, documented at -http://java.sun.com/developer/technicalArticles/Programming/compression/ . - -A Perl interface to zlib written by Paul Marquess is available -at CPAN (Comprehensive Perl Archive Network) sites, including -http://search.cpan.org/~pmqs/IO-Compress-Zlib/ . - -A Python interface to zlib written by A.M. Kuchling is -available in Python 1.5 and later versions, see -http://docs.python.org/library/zlib.html . - -zlib is built into tcl: http://wiki.tcl.tk/4610 . - -An experimental package to read and write files in .zip format, written on top -of zlib by Gilles Vollant , is available in the -contrib/minizip directory of zlib. - - -Notes for some targets: - -- For Windows DLL versions, please see win32/DLL_FAQ.txt - -- For 64-bit Irix, deflate.c must be compiled without any optimization. With - -O, one libpng test fails. The test works in 32 bit mode (with the -n32 - compiler flag). The compiler bug has been reported to SGI. - -- zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 it works - when compiled with cc. - -- On Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1 is - necessary to get gzprintf working correctly. This is done by configure. - -- zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works with - other compilers. Use "make test" to check your compiler. - -- gzdopen is not supported on RISCOS or BEOS. - -- For PalmOs, see http://palmzlib.sourceforge.net/ - - -Acknowledgments: - - The deflate format used by zlib was defined by Phil Katz. The deflate and - zlib specifications were written by L. Peter Deutsch. Thanks to all the - people who reported problems and suggested various improvements in zlib; they - are too numerous to cite here. - -Copyright notice: - - (C) 1995-2013 Jean-loup Gailly and Mark Adler - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Jean-loup Gailly Mark Adler - jloup@gzip.org madler@alumni.caltech.edu - -If you use the zlib library in a product, we would appreciate *not* receiving -lengthy legal documents to sign. The sources are provided for free but without -warranty of any kind. The library has been entirely written by Jean-loup -Gailly and Mark Adler; it does not include third-party code. - -If you redistribute modified sources, we would appreciate that you include in -the file ChangeLog history information documenting your changes. Please read -the FAQ for more information on the distribution of modified source versions. diff --git a/src/beast/test/zlib/zlib-1.2.8/adler32.c b/src/beast/test/zlib/zlib-1.2.8/adler32.c deleted file mode 100644 index a868f073d8a..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/adler32.c +++ /dev/null @@ -1,179 +0,0 @@ -/* adler32.c -- compute the Adler-32 checksum of a data stream - * Copyright (C) 1995-2011 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id$ */ - -#include "zutil.h" - -#define local static - -local uLong adler32_combine_ OF((uLong adler1, uLong adler2, z_off64_t len2)); - -#define BASE 65521 /* largest prime smaller than 65536 */ -#define NMAX 5552 -/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ - -#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;} -#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); -#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); -#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); -#define DO16(buf) DO8(buf,0); DO8(buf,8); - -/* use NO_DIVIDE if your processor does not do division in hardware -- - try it both ways to see which is faster */ -#ifdef NO_DIVIDE -/* note that this assumes BASE is 65521, where 65536 % 65521 == 15 - (thank you to John Reiser for pointing this out) */ -# define CHOP(a) \ - do { \ - unsigned long tmp = a >> 16; \ - a &= 0xffffUL; \ - a += (tmp << 4) - tmp; \ - } while (0) -# define MOD28(a) \ - do { \ - CHOP(a); \ - if (a >= BASE) a -= BASE; \ - } while (0) -# define MOD(a) \ - do { \ - CHOP(a); \ - MOD28(a); \ - } while (0) -# define MOD63(a) \ - do { /* this assumes a is not negative */ \ - z_off64_t tmp = a >> 32; \ - a &= 0xffffffffL; \ - a += (tmp << 8) - (tmp << 5) + tmp; \ - tmp = a >> 16; \ - a &= 0xffffL; \ - a += (tmp << 4) - tmp; \ - tmp = a >> 16; \ - a &= 0xffffL; \ - a += (tmp << 4) - tmp; \ - if (a >= BASE) a -= BASE; \ - } while (0) -#else -# define MOD(a) a %= BASE -# define MOD28(a) a %= BASE -# define MOD63(a) a %= BASE -#endif - -/* ========================================================================= */ -uLong ZEXPORT adler32(adler, buf, len) - uLong adler; - const Bytef *buf; - uInt len; -{ - unsigned long sum2; - unsigned n; - - /* split Adler-32 into component sums */ - sum2 = (adler >> 16) & 0xffff; - adler &= 0xffff; - - /* in case user likes doing a byte at a time, keep it fast */ - if (len == 1) { - adler += buf[0]; - if (adler >= BASE) - adler -= BASE; - sum2 += adler; - if (sum2 >= BASE) - sum2 -= BASE; - return adler | (sum2 << 16); - } - - /* initial Adler-32 value (deferred check for len == 1 speed) */ - if (buf == Z_NULL) - return 1L; - - /* in case short lengths are provided, keep it somewhat fast */ - if (len < 16) { - while (len--) { - adler += *buf++; - sum2 += adler; - } - if (adler >= BASE) - adler -= BASE; - MOD28(sum2); /* only added so many BASE's */ - return adler | (sum2 << 16); - } - - /* do length NMAX blocks -- requires just one modulo operation */ - while (len >= NMAX) { - len -= NMAX; - n = NMAX / 16; /* NMAX is divisible by 16 */ - do { - DO16(buf); /* 16 sums unrolled */ - buf += 16; - } while (--n); - MOD(adler); - MOD(sum2); - } - - /* do remaining bytes (less than NMAX, still just one modulo) */ - if (len) { /* avoid modulos if none remaining */ - while (len >= 16) { - len -= 16; - DO16(buf); - buf += 16; - } - while (len--) { - adler += *buf++; - sum2 += adler; - } - MOD(adler); - MOD(sum2); - } - - /* return recombined sums */ - return adler | (sum2 << 16); -} - -/* ========================================================================= */ -local uLong adler32_combine_(adler1, adler2, len2) - uLong adler1; - uLong adler2; - z_off64_t len2; -{ - unsigned long sum1; - unsigned long sum2; - unsigned rem; - - /* for negative len, return invalid adler32 as a clue for debugging */ - if (len2 < 0) - return 0xffffffffUL; - - /* the derivation of this formula is left as an exercise for the reader */ - MOD63(len2); /* assumes len2 >= 0 */ - rem = (unsigned)len2; - sum1 = adler1 & 0xffff; - sum2 = rem * sum1; - MOD(sum2); - sum1 += (adler2 & 0xffff) + BASE - 1; - sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem; - if (sum1 >= BASE) sum1 -= BASE; - if (sum1 >= BASE) sum1 -= BASE; - if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1); - if (sum2 >= BASE) sum2 -= BASE; - return sum1 | (sum2 << 16); -} - -/* ========================================================================= */ -uLong ZEXPORT adler32_combine(adler1, adler2, len2) - uLong adler1; - uLong adler2; - z_off_t len2; -{ - return adler32_combine_(adler1, adler2, len2); -} - -uLong ZEXPORT adler32_combine64(adler1, adler2, len2) - uLong adler1; - uLong adler2; - z_off64_t len2; -{ - return adler32_combine_(adler1, adler2, len2); -} diff --git a/src/beast/test/zlib/zlib-1.2.8/amiga/Makefile.pup b/src/beast/test/zlib/zlib-1.2.8/amiga/Makefile.pup deleted file mode 100644 index 8940c120fbb..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/amiga/Makefile.pup +++ /dev/null @@ -1,69 +0,0 @@ -# Amiga powerUP (TM) Makefile -# makefile for libpng and SAS C V6.58/7.00 PPC compiler -# Copyright (C) 1998 by Andreas R. Kleinert - -LIBNAME = libzip.a - -CC = scppc -CFLAGS = NOSTKCHK NOSINT OPTIMIZE OPTGO OPTPEEP OPTINLOCAL OPTINL \ - OPTLOOP OPTRDEP=8 OPTDEP=8 OPTCOMP=8 NOVER -AR = ppc-amigaos-ar cr -RANLIB = ppc-amigaos-ranlib -LD = ppc-amigaos-ld -r -LDFLAGS = -o -LDLIBS = LIB:scppc.a LIB:end.o -RM = delete quiet - -OBJS = adler32.o compress.o crc32.o gzclose.o gzlib.o gzread.o gzwrite.o \ - uncompr.o deflate.o trees.o zutil.o inflate.o infback.o inftrees.o inffast.o - -TEST_OBJS = example.o minigzip.o - -all: example minigzip - -check: test -test: all - example - echo hello world | minigzip | minigzip -d - -$(LIBNAME): $(OBJS) - $(AR) $@ $(OBJS) - -$(RANLIB) $@ - -example: example.o $(LIBNAME) - $(LD) $(LDFLAGS) $@ LIB:c_ppc.o $@.o $(LIBNAME) $(LDLIBS) - -minigzip: minigzip.o $(LIBNAME) - $(LD) $(LDFLAGS) $@ LIB:c_ppc.o $@.o $(LIBNAME) $(LDLIBS) - -mostlyclean: clean -clean: - $(RM) *.o example minigzip $(LIBNAME) foo.gz - -zip: - zip -ul9 zlib README ChangeLog Makefile Make????.??? Makefile.?? \ - descrip.mms *.[ch] - -tgz: - cd ..; tar cfz zlib/zlib.tgz zlib/README zlib/ChangeLog zlib/Makefile \ - zlib/Make????.??? zlib/Makefile.?? zlib/descrip.mms zlib/*.[ch] - -# DO NOT DELETE THIS LINE -- make depend depends on it. - -adler32.o: zlib.h zconf.h -compress.o: zlib.h zconf.h -crc32.o: crc32.h zlib.h zconf.h -deflate.o: deflate.h zutil.h zlib.h zconf.h -example.o: zlib.h zconf.h -gzclose.o: zlib.h zconf.h gzguts.h -gzlib.o: zlib.h zconf.h gzguts.h -gzread.o: zlib.h zconf.h gzguts.h -gzwrite.o: zlib.h zconf.h gzguts.h -inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h -inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h -infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h -inftrees.o: zutil.h zlib.h zconf.h inftrees.h -minigzip.o: zlib.h zconf.h -trees.o: deflate.h zutil.h zlib.h zconf.h trees.h -uncompr.o: zlib.h zconf.h -zutil.o: zutil.h zlib.h zconf.h diff --git a/src/beast/test/zlib/zlib-1.2.8/amiga/Makefile.sas b/src/beast/test/zlib/zlib-1.2.8/amiga/Makefile.sas deleted file mode 100644 index 749e2915271..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/amiga/Makefile.sas +++ /dev/null @@ -1,68 +0,0 @@ -# SMakefile for zlib -# Modified from the standard UNIX Makefile Copyright Jean-loup Gailly -# Osma Ahvenlampi -# Amiga, SAS/C 6.56 & Smake - -CC=sc -CFLAGS=OPT -#CFLAGS=OPT CPU=68030 -#CFLAGS=DEBUG=LINE -LDFLAGS=LIB z.lib - -SCOPTIONS=OPTSCHED OPTINLINE OPTALIAS OPTTIME OPTINLOCAL STRMERGE \ - NOICONS PARMS=BOTH NOSTACKCHECK UTILLIB NOVERSION ERRORREXX \ - DEF=POSTINC - -OBJS = adler32.o compress.o crc32.o gzclose.o gzlib.o gzread.o gzwrite.o \ - uncompr.o deflate.o trees.o zutil.o inflate.o infback.o inftrees.o inffast.o - -TEST_OBJS = example.o minigzip.o - -all: SCOPTIONS example minigzip - -check: test -test: all - example - echo hello world | minigzip | minigzip -d - -install: z.lib - copy clone zlib.h zconf.h INCLUDE: - copy clone z.lib LIB: - -z.lib: $(OBJS) - oml z.lib r $(OBJS) - -example: example.o z.lib - $(CC) $(CFLAGS) LINK TO $@ example.o $(LDFLAGS) - -minigzip: minigzip.o z.lib - $(CC) $(CFLAGS) LINK TO $@ minigzip.o $(LDFLAGS) - -mostlyclean: clean -clean: - -delete force quiet example minigzip *.o z.lib foo.gz *.lnk SCOPTIONS - -SCOPTIONS: Makefile.sas - copy to $@ 64K on 16-bit machine: */ - if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; -#endif - stream.next_out = dest; - stream.avail_out = (uInt)*destLen; - if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; - - stream.zalloc = (alloc_func)0; - stream.zfree = (free_func)0; - stream.opaque = (voidpf)0; - - err = deflateInit(&stream, level); - if (err != Z_OK) return err; - - err = deflate(&stream, Z_FINISH); - if (err != Z_STREAM_END) { - deflateEnd(&stream); - return err == Z_OK ? Z_BUF_ERROR : err; - } - *destLen = stream.total_out; - - err = deflateEnd(&stream); - return err; -} - -/* =========================================================================== - */ -int ZEXPORT compress (dest, destLen, source, sourceLen) - Bytef *dest; - uLongf *destLen; - const Bytef *source; - uLong sourceLen; -{ - return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); -} - -/* =========================================================================== - If the default memLevel or windowBits for deflateInit() is changed, then - this function needs to be updated. - */ -uLong ZEXPORT compressBound (sourceLen) - uLong sourceLen; -{ - return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + - (sourceLen >> 25) + 13; -} diff --git a/src/beast/test/zlib/zlib-1.2.8/configure b/src/beast/test/zlib/zlib-1.2.8/configure deleted file mode 100644 index b77a8a8cf95..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/configure +++ /dev/null @@ -1,831 +0,0 @@ -#!/bin/sh -# configure script for zlib. -# -# Normally configure builds both a static and a shared library. -# If you want to build just a static library, use: ./configure --static -# -# To impose specific compiler or flags or install directory, use for example: -# prefix=$HOME CC=cc CFLAGS="-O4" ./configure -# or for csh/tcsh users: -# (setenv prefix $HOME; setenv CC cc; setenv CFLAGS "-O4"; ./configure) - -# Incorrect settings of CC or CFLAGS may prevent creating a shared library. -# If you have problems, try without defining CC and CFLAGS before reporting -# an error. - -# start off configure.log -echo -------------------- >> configure.log -echo $0 $* >> configure.log -date >> configure.log - -# set command prefix for cross-compilation -if [ -n "${CHOST}" ]; then - uname="`echo "${CHOST}" | sed -e 's/^[^-]*-\([^-]*\)$/\1/' -e 's/^[^-]*-[^-]*-\([^-]*\)$/\1/' -e 's/^[^-]*-[^-]*-\([^-]*\)-.*$/\1/'`" - CROSS_PREFIX="${CHOST}-" -fi - -# destination name for static library -STATICLIB=libz.a - -# extract zlib version numbers from zlib.h -VER=`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h` -VER3=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\\.[0-9]*\).*/\1/p' < zlib.h` -VER2=`sed -n -e '/VERSION "/s/.*"\([0-9]*\\.[0-9]*\)\\..*/\1/p' < zlib.h` -VER1=`sed -n -e '/VERSION "/s/.*"\([0-9]*\)\\..*/\1/p' < zlib.h` - -# establish commands for library building -if "${CROSS_PREFIX}ar" --version >/dev/null 2>/dev/null || test $? -lt 126; then - AR=${AR-"${CROSS_PREFIX}ar"} - test -n "${CROSS_PREFIX}" && echo Using ${AR} | tee -a configure.log -else - AR=${AR-"ar"} - test -n "${CROSS_PREFIX}" && echo Using ${AR} | tee -a configure.log -fi -ARFLAGS=${ARFLAGS-"rc"} -if "${CROSS_PREFIX}ranlib" --version >/dev/null 2>/dev/null || test $? -lt 126; then - RANLIB=${RANLIB-"${CROSS_PREFIX}ranlib"} - test -n "${CROSS_PREFIX}" && echo Using ${RANLIB} | tee -a configure.log -else - RANLIB=${RANLIB-"ranlib"} -fi -if "${CROSS_PREFIX}nm" --version >/dev/null 2>/dev/null || test $? -lt 126; then - NM=${NM-"${CROSS_PREFIX}nm"} - test -n "${CROSS_PREFIX}" && echo Using ${NM} | tee -a configure.log -else - NM=${NM-"nm"} -fi - -# set defaults before processing command line options -LDCONFIG=${LDCONFIG-"ldconfig"} -LDSHAREDLIBC="${LDSHAREDLIBC--lc}" -ARCHS= -prefix=${prefix-/usr/local} -exec_prefix=${exec_prefix-'${prefix}'} -libdir=${libdir-'${exec_prefix}/lib'} -sharedlibdir=${sharedlibdir-'${libdir}'} -includedir=${includedir-'${prefix}/include'} -mandir=${mandir-'${prefix}/share/man'} -shared_ext='.so' -shared=1 -solo=0 -cover=0 -zprefix=0 -zconst=0 -build64=0 -gcc=0 -old_cc="$CC" -old_cflags="$CFLAGS" -OBJC='$(OBJZ) $(OBJG)' -PIC_OBJC='$(PIC_OBJZ) $(PIC_OBJG)' - -# leave this script, optionally in a bad way -leave() -{ - if test "$*" != "0"; then - echo "** $0 aborting." | tee -a configure.log - fi - rm -f $test.[co] $test $test$shared_ext $test.gcno ./--version - echo -------------------- >> configure.log - echo >> configure.log - echo >> configure.log - exit $1 -} - -# process command line options -while test $# -ge 1 -do -case "$1" in - -h* | --help) - echo 'usage:' | tee -a configure.log - echo ' configure [--const] [--zprefix] [--prefix=PREFIX] [--eprefix=EXPREFIX]' | tee -a configure.log - echo ' [--static] [--64] [--libdir=LIBDIR] [--sharedlibdir=LIBDIR]' | tee -a configure.log - echo ' [--includedir=INCLUDEDIR] [--archs="-arch i386 -arch x86_64"]' | tee -a configure.log - exit 0 ;; - -p*=* | --prefix=*) prefix=`echo $1 | sed 's/.*=//'`; shift ;; - -e*=* | --eprefix=*) exec_prefix=`echo $1 | sed 's/.*=//'`; shift ;; - -l*=* | --libdir=*) libdir=`echo $1 | sed 's/.*=//'`; shift ;; - --sharedlibdir=*) sharedlibdir=`echo $1 | sed 's/.*=//'`; shift ;; - -i*=* | --includedir=*) includedir=`echo $1 | sed 's/.*=//'`;shift ;; - -u*=* | --uname=*) uname=`echo $1 | sed 's/.*=//'`;shift ;; - -p* | --prefix) prefix="$2"; shift; shift ;; - -e* | --eprefix) exec_prefix="$2"; shift; shift ;; - -l* | --libdir) libdir="$2"; shift; shift ;; - -i* | --includedir) includedir="$2"; shift; shift ;; - -s* | --shared | --enable-shared) shared=1; shift ;; - -t | --static) shared=0; shift ;; - --solo) solo=1; shift ;; - --cover) cover=1; shift ;; - -z* | --zprefix) zprefix=1; shift ;; - -6* | --64) build64=1; shift ;; - -a*=* | --archs=*) ARCHS=`echo $1 | sed 's/.*=//'`; shift ;; - --sysconfdir=*) echo "ignored option: --sysconfdir" | tee -a configure.log; shift ;; - --localstatedir=*) echo "ignored option: --localstatedir" | tee -a configure.log; shift ;; - -c* | --const) zconst=1; shift ;; - *) - echo "unknown option: $1" | tee -a configure.log - echo "$0 --help for help" | tee -a configure.log - leave 1;; - esac -done - -# temporary file name -test=ztest$$ - -# put arguments in log, also put test file in log if used in arguments -show() -{ - case "$*" in - *$test.c*) - echo === $test.c === >> configure.log - cat $test.c >> configure.log - echo === >> configure.log;; - esac - echo $* >> configure.log -} - -# check for gcc vs. cc and set compile and link flags based on the system identified by uname -cat > $test.c <&1` in - *gcc*) gcc=1 ;; -esac - -show $cc -c $test.c -if test "$gcc" -eq 1 && ($cc -c $test.c) >> configure.log 2>&1; then - echo ... using gcc >> configure.log - CC="$cc" - CFLAGS="${CFLAGS--O3} ${ARCHS}" - SFLAGS="${CFLAGS--O3} -fPIC" - LDFLAGS="${LDFLAGS} ${ARCHS}" - if test $build64 -eq 1; then - CFLAGS="${CFLAGS} -m64" - SFLAGS="${SFLAGS} -m64" - fi - if test "${ZLIBGCCWARN}" = "YES"; then - if test "$zconst" -eq 1; then - CFLAGS="${CFLAGS} -Wall -Wextra -Wcast-qual -pedantic -DZLIB_CONST" - else - CFLAGS="${CFLAGS} -Wall -Wextra -pedantic" - fi - fi - if test -z "$uname"; then - uname=`(uname -s || echo unknown) 2>/dev/null` - fi - case "$uname" in - Linux* | linux* | GNU | GNU/* | solaris*) - LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map"} ;; - *BSD | *bsd* | DragonFly) - LDSHARED=${LDSHARED-"$cc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map"} - LDCONFIG="ldconfig -m" ;; - CYGWIN* | Cygwin* | cygwin* | OS/2*) - EXE='.exe' ;; - MINGW* | mingw*) -# temporary bypass - rm -f $test.[co] $test $test$shared_ext - echo "Please use win32/Makefile.gcc instead." | tee -a configure.log - leave 1 - LDSHARED=${LDSHARED-"$cc -shared"} - LDSHAREDLIBC="" - EXE='.exe' ;; - QNX*) # This is for QNX6. I suppose that the QNX rule below is for QNX2,QNX4 - # (alain.bonnefoy@icbt.com) - LDSHARED=${LDSHARED-"$cc -shared -Wl,-hlibz.so.1"} ;; - HP-UX*) - LDSHARED=${LDSHARED-"$cc -shared $SFLAGS"} - case `(uname -m || echo unknown) 2>/dev/null` in - ia64) - shared_ext='.so' - SHAREDLIB='libz.so' ;; - *) - shared_ext='.sl' - SHAREDLIB='libz.sl' ;; - esac ;; - Darwin* | darwin*) - shared_ext='.dylib' - SHAREDLIB=libz$shared_ext - SHAREDLIBV=libz.$VER$shared_ext - SHAREDLIBM=libz.$VER1$shared_ext - LDSHARED=${LDSHARED-"$cc -dynamiclib -install_name $libdir/$SHAREDLIBM -compatibility_version $VER1 -current_version $VER3"} - if libtool -V 2>&1 | grep Apple > /dev/null; then - AR="libtool" - else - AR="/usr/bin/libtool" - fi - ARFLAGS="-o" ;; - *) LDSHARED=${LDSHARED-"$cc -shared"} ;; - esac -else - # find system name and corresponding cc options - CC=${CC-cc} - gcc=0 - echo ... using $CC >> configure.log - if test -z "$uname"; then - uname=`(uname -sr || echo unknown) 2>/dev/null` - fi - case "$uname" in - HP-UX*) SFLAGS=${CFLAGS-"-O +z"} - CFLAGS=${CFLAGS-"-O"} -# LDSHARED=${LDSHARED-"ld -b +vnocompatwarnings"} - LDSHARED=${LDSHARED-"ld -b"} - case `(uname -m || echo unknown) 2>/dev/null` in - ia64) - shared_ext='.so' - SHAREDLIB='libz.so' ;; - *) - shared_ext='.sl' - SHAREDLIB='libz.sl' ;; - esac ;; - IRIX*) SFLAGS=${CFLAGS-"-ansi -O2 -rpath ."} - CFLAGS=${CFLAGS-"-ansi -O2"} - LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;; - OSF1\ V4*) SFLAGS=${CFLAGS-"-O -std1"} - CFLAGS=${CFLAGS-"-O -std1"} - LDFLAGS="${LDFLAGS} -Wl,-rpath,." - LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so -Wl,-msym -Wl,-rpath,$(libdir) -Wl,-set_version,${VER}:1.0"} ;; - OSF1*) SFLAGS=${CFLAGS-"-O -std1"} - CFLAGS=${CFLAGS-"-O -std1"} - LDSHARED=${LDSHARED-"cc -shared -Wl,-soname,libz.so.1"} ;; - QNX*) SFLAGS=${CFLAGS-"-4 -O"} - CFLAGS=${CFLAGS-"-4 -O"} - LDSHARED=${LDSHARED-"cc"} - RANLIB=${RANLIB-"true"} - AR="cc" - ARFLAGS="-A" ;; - SCO_SV\ 3.2*) SFLAGS=${CFLAGS-"-O3 -dy -KPIC "} - CFLAGS=${CFLAGS-"-O3"} - LDSHARED=${LDSHARED-"cc -dy -KPIC -G"} ;; - SunOS\ 5* | solaris*) - LDSHARED=${LDSHARED-"cc -G -h libz$shared_ext.$VER1"} - SFLAGS=${CFLAGS-"-fast -KPIC"} - CFLAGS=${CFLAGS-"-fast"} - if test $build64 -eq 1; then - # old versions of SunPRO/Workshop/Studio don't support -m64, - # but newer ones do. Check for it. - flag64=`$CC -flags | egrep -- '^-m64'` - if test x"$flag64" != x"" ; then - CFLAGS="${CFLAGS} -m64" - SFLAGS="${SFLAGS} -m64" - else - case `(uname -m || echo unknown) 2>/dev/null` in - i86*) - SFLAGS="$SFLAGS -xarch=amd64" - CFLAGS="$CFLAGS -xarch=amd64" ;; - *) - SFLAGS="$SFLAGS -xarch=v9" - CFLAGS="$CFLAGS -xarch=v9" ;; - esac - fi - fi - ;; - SunOS\ 4*) SFLAGS=${CFLAGS-"-O2 -PIC"} - CFLAGS=${CFLAGS-"-O2"} - LDSHARED=${LDSHARED-"ld"} ;; - SunStudio\ 9*) SFLAGS=${CFLAGS-"-fast -xcode=pic32 -xtarget=ultra3 -xarch=v9b"} - CFLAGS=${CFLAGS-"-fast -xtarget=ultra3 -xarch=v9b"} - LDSHARED=${LDSHARED-"cc -xarch=v9b"} ;; - UNIX_System_V\ 4.2.0) - SFLAGS=${CFLAGS-"-KPIC -O"} - CFLAGS=${CFLAGS-"-O"} - LDSHARED=${LDSHARED-"cc -G"} ;; - UNIX_SV\ 4.2MP) - SFLAGS=${CFLAGS-"-Kconform_pic -O"} - CFLAGS=${CFLAGS-"-O"} - LDSHARED=${LDSHARED-"cc -G"} ;; - OpenUNIX\ 5) - SFLAGS=${CFLAGS-"-KPIC -O"} - CFLAGS=${CFLAGS-"-O"} - LDSHARED=${LDSHARED-"cc -G"} ;; - AIX*) # Courtesy of dbakker@arrayasolutions.com - SFLAGS=${CFLAGS-"-O -qmaxmem=8192"} - CFLAGS=${CFLAGS-"-O -qmaxmem=8192"} - LDSHARED=${LDSHARED-"xlc -G"} ;; - # send working options for other systems to zlib@gzip.org - *) SFLAGS=${CFLAGS-"-O"} - CFLAGS=${CFLAGS-"-O"} - LDSHARED=${LDSHARED-"cc -shared"} ;; - esac -fi - -# destination names for shared library if not defined above -SHAREDLIB=${SHAREDLIB-"libz$shared_ext"} -SHAREDLIBV=${SHAREDLIBV-"libz$shared_ext.$VER"} -SHAREDLIBM=${SHAREDLIBM-"libz$shared_ext.$VER1"} - -echo >> configure.log - -# define functions for testing compiler and library characteristics and logging the results - -cat > $test.c </dev/null; then - try() - { - show $* - test "`( $* ) 2>&1 | tee -a configure.log`" = "" - } - echo - using any output from compiler to indicate an error >> configure.log -else -try() -{ - show $* - ( $* ) >> configure.log 2>&1 - ret=$? - if test $ret -ne 0; then - echo "(exit code "$ret")" >> configure.log - fi - return $ret -} -fi - -tryboth() -{ - show $* - got=`( $* ) 2>&1` - ret=$? - printf %s "$got" >> configure.log - if test $ret -ne 0; then - return $ret - fi - test "$got" = "" -} - -cat > $test.c << EOF -int foo() { return 0; } -EOF -echo "Checking for obsessive-compulsive compiler options..." >> configure.log -if try $CC -c $CFLAGS $test.c; then - : -else - echo "Compiler error reporting is too harsh for $0 (perhaps remove -Werror)." | tee -a configure.log - leave 1 -fi - -echo >> configure.log - -# see if shared library build supported -cat > $test.c <> configure.log - show "$NM $test.o | grep _hello" - if test "`$NM $test.o | grep _hello | tee -a configure.log`" = ""; then - CPP="$CPP -DNO_UNDERLINE" - echo Checking for underline in external names... No. | tee -a configure.log - else - echo Checking for underline in external names... Yes. | tee -a configure.log - fi ;; -esac - -echo >> configure.log - -# check for large file support, and if none, check for fseeko() -cat > $test.c < -off64_t dummy = 0; -EOF -if try $CC -c $CFLAGS -D_LARGEFILE64_SOURCE=1 $test.c; then - CFLAGS="${CFLAGS} -D_LARGEFILE64_SOURCE=1" - SFLAGS="${SFLAGS} -D_LARGEFILE64_SOURCE=1" - ALL="${ALL} all64" - TEST="${TEST} test64" - echo "Checking for off64_t... Yes." | tee -a configure.log - echo "Checking for fseeko... Yes." | tee -a configure.log -else - echo "Checking for off64_t... No." | tee -a configure.log - echo >> configure.log - cat > $test.c < -int main(void) { - fseeko(NULL, 0, 0); - return 0; -} -EOF - if try $CC $CFLAGS -o $test $test.c; then - echo "Checking for fseeko... Yes." | tee -a configure.log - else - CFLAGS="${CFLAGS} -DNO_FSEEKO" - SFLAGS="${SFLAGS} -DNO_FSEEKO" - echo "Checking for fseeko... No." | tee -a configure.log - fi -fi - -echo >> configure.log - -# check for strerror() for use by gz* functions -cat > $test.c < -#include -int main() { return strlen(strerror(errno)); } -EOF -if try $CC $CFLAGS -o $test $test.c; then - echo "Checking for strerror... Yes." | tee -a configure.log -else - CFLAGS="${CFLAGS} -DNO_STRERROR" - SFLAGS="${SFLAGS} -DNO_STRERROR" - echo "Checking for strerror... No." | tee -a configure.log -fi - -# copy clean zconf.h for subsequent edits -cp -p zconf.h.in zconf.h - -echo >> configure.log - -# check for unistd.h and save result in zconf.h -cat > $test.c < -int main() { return 0; } -EOF -if try $CC -c $CFLAGS $test.c; then - sed < zconf.h "/^#ifdef HAVE_UNISTD_H.* may be/s/def HAVE_UNISTD_H\(.*\) may be/ 1\1 was/" > zconf.temp.h - mv zconf.temp.h zconf.h - echo "Checking for unistd.h... Yes." | tee -a configure.log -else - echo "Checking for unistd.h... No." | tee -a configure.log -fi - -echo >> configure.log - -# check for stdarg.h and save result in zconf.h -cat > $test.c < -int main() { return 0; } -EOF -if try $CC -c $CFLAGS $test.c; then - sed < zconf.h "/^#ifdef HAVE_STDARG_H.* may be/s/def HAVE_STDARG_H\(.*\) may be/ 1\1 was/" > zconf.temp.h - mv zconf.temp.h zconf.h - echo "Checking for stdarg.h... Yes." | tee -a configure.log -else - echo "Checking for stdarg.h... No." | tee -a configure.log -fi - -# if the z_ prefix was requested, save that in zconf.h -if test $zprefix -eq 1; then - sed < zconf.h "/#ifdef Z_PREFIX.* may be/s/def Z_PREFIX\(.*\) may be/ 1\1 was/" > zconf.temp.h - mv zconf.temp.h zconf.h - echo >> configure.log - echo "Using z_ prefix on all symbols." | tee -a configure.log -fi - -# if --solo compilation was requested, save that in zconf.h and remove gz stuff from object lists -if test $solo -eq 1; then - sed '/#define ZCONF_H/a\ -#define Z_SOLO - -' < zconf.h > zconf.temp.h - mv zconf.temp.h zconf.h -OBJC='$(OBJZ)' -PIC_OBJC='$(PIC_OBJZ)' -fi - -# if code coverage testing was requested, use older gcc if defined, e.g. "gcc-4.2" on Mac OS X -if test $cover -eq 1; then - CFLAGS="${CFLAGS} -fprofile-arcs -ftest-coverage" - if test -n "$GCC_CLASSIC"; then - CC=$GCC_CLASSIC - fi -fi - -echo >> configure.log - -# conduct a series of tests to resolve eight possible cases of using "vs" or "s" printf functions -# (using stdarg or not), with or without "n" (proving size of buffer), and with or without a -# return value. The most secure result is vsnprintf() with a return value. snprintf() with a -# return value is secure as well, but then gzprintf() will be limited to 20 arguments. -cat > $test.c < -#include -#include "zconf.h" -int main() -{ -#ifndef STDC - choke me -#endif - return 0; -} -EOF -if try $CC -c $CFLAGS $test.c; then - echo "Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf()." | tee -a configure.log - - echo >> configure.log - cat > $test.c < -#include -int mytest(const char *fmt, ...) -{ - char buf[20]; - va_list ap; - va_start(ap, fmt); - vsnprintf(buf, sizeof(buf), fmt, ap); - va_end(ap); - return 0; -} -int main() -{ - return (mytest("Hello%d\n", 1)); -} -EOF - if try $CC $CFLAGS -o $test $test.c; then - echo "Checking for vsnprintf() in stdio.h... Yes." | tee -a configure.log - - echo >> configure.log - cat >$test.c < -#include -int mytest(const char *fmt, ...) -{ - int n; - char buf[20]; - va_list ap; - va_start(ap, fmt); - n = vsnprintf(buf, sizeof(buf), fmt, ap); - va_end(ap); - return n; -} -int main() -{ - return (mytest("Hello%d\n", 1)); -} -EOF - - if try $CC -c $CFLAGS $test.c; then - echo "Checking for return value of vsnprintf()... Yes." | tee -a configure.log - else - CFLAGS="$CFLAGS -DHAS_vsnprintf_void" - SFLAGS="$SFLAGS -DHAS_vsnprintf_void" - echo "Checking for return value of vsnprintf()... No." | tee -a configure.log - echo " WARNING: apparently vsnprintf() does not return a value. zlib" | tee -a configure.log - echo " can build but will be open to possible string-format security" | tee -a configure.log - echo " vulnerabilities." | tee -a configure.log - fi - else - CFLAGS="$CFLAGS -DNO_vsnprintf" - SFLAGS="$SFLAGS -DNO_vsnprintf" - echo "Checking for vsnprintf() in stdio.h... No." | tee -a configure.log - echo " WARNING: vsnprintf() not found, falling back to vsprintf(). zlib" | tee -a configure.log - echo " can build but will be open to possible buffer-overflow security" | tee -a configure.log - echo " vulnerabilities." | tee -a configure.log - - echo >> configure.log - cat >$test.c < -#include -int mytest(const char *fmt, ...) -{ - int n; - char buf[20]; - va_list ap; - va_start(ap, fmt); - n = vsprintf(buf, fmt, ap); - va_end(ap); - return n; -} -int main() -{ - return (mytest("Hello%d\n", 1)); -} -EOF - - if try $CC -c $CFLAGS $test.c; then - echo "Checking for return value of vsprintf()... Yes." | tee -a configure.log - else - CFLAGS="$CFLAGS -DHAS_vsprintf_void" - SFLAGS="$SFLAGS -DHAS_vsprintf_void" - echo "Checking for return value of vsprintf()... No." | tee -a configure.log - echo " WARNING: apparently vsprintf() does not return a value. zlib" | tee -a configure.log - echo " can build but will be open to possible string-format security" | tee -a configure.log - echo " vulnerabilities." | tee -a configure.log - fi - fi -else - echo "Checking whether to use vs[n]printf() or s[n]printf()... using s[n]printf()." | tee -a configure.log - - echo >> configure.log - cat >$test.c < -int mytest() -{ - char buf[20]; - snprintf(buf, sizeof(buf), "%s", "foo"); - return 0; -} -int main() -{ - return (mytest()); -} -EOF - - if try $CC $CFLAGS -o $test $test.c; then - echo "Checking for snprintf() in stdio.h... Yes." | tee -a configure.log - - echo >> configure.log - cat >$test.c < -int mytest() -{ - char buf[20]; - return snprintf(buf, sizeof(buf), "%s", "foo"); -} -int main() -{ - return (mytest()); -} -EOF - - if try $CC -c $CFLAGS $test.c; then - echo "Checking for return value of snprintf()... Yes." | tee -a configure.log - else - CFLAGS="$CFLAGS -DHAS_snprintf_void" - SFLAGS="$SFLAGS -DHAS_snprintf_void" - echo "Checking for return value of snprintf()... No." | tee -a configure.log - echo " WARNING: apparently snprintf() does not return a value. zlib" | tee -a configure.log - echo " can build but will be open to possible string-format security" | tee -a configure.log - echo " vulnerabilities." | tee -a configure.log - fi - else - CFLAGS="$CFLAGS -DNO_snprintf" - SFLAGS="$SFLAGS -DNO_snprintf" - echo "Checking for snprintf() in stdio.h... No." | tee -a configure.log - echo " WARNING: snprintf() not found, falling back to sprintf(). zlib" | tee -a configure.log - echo " can build but will be open to possible buffer-overflow security" | tee -a configure.log - echo " vulnerabilities." | tee -a configure.log - - echo >> configure.log - cat >$test.c < -int mytest() -{ - char buf[20]; - return sprintf(buf, "%s", "foo"); -} -int main() -{ - return (mytest()); -} -EOF - - if try $CC -c $CFLAGS $test.c; then - echo "Checking for return value of sprintf()... Yes." | tee -a configure.log - else - CFLAGS="$CFLAGS -DHAS_sprintf_void" - SFLAGS="$SFLAGS -DHAS_sprintf_void" - echo "Checking for return value of sprintf()... No." | tee -a configure.log - echo " WARNING: apparently sprintf() does not return a value. zlib" | tee -a configure.log - echo " can build but will be open to possible string-format security" | tee -a configure.log - echo " vulnerabilities." | tee -a configure.log - fi - fi -fi - -# see if we can hide zlib internal symbols that are linked between separate source files -if test "$gcc" -eq 1; then - echo >> configure.log - cat > $test.c <> configure.log -echo ALL = $ALL >> configure.log -echo AR = $AR >> configure.log -echo ARFLAGS = $ARFLAGS >> configure.log -echo CC = $CC >> configure.log -echo CFLAGS = $CFLAGS >> configure.log -echo CPP = $CPP >> configure.log -echo EXE = $EXE >> configure.log -echo LDCONFIG = $LDCONFIG >> configure.log -echo LDFLAGS = $LDFLAGS >> configure.log -echo LDSHARED = $LDSHARED >> configure.log -echo LDSHAREDLIBC = $LDSHAREDLIBC >> configure.log -echo OBJC = $OBJC >> configure.log -echo PIC_OBJC = $PIC_OBJC >> configure.log -echo RANLIB = $RANLIB >> configure.log -echo SFLAGS = $SFLAGS >> configure.log -echo SHAREDLIB = $SHAREDLIB >> configure.log -echo SHAREDLIBM = $SHAREDLIBM >> configure.log -echo SHAREDLIBV = $SHAREDLIBV >> configure.log -echo STATICLIB = $STATICLIB >> configure.log -echo TEST = $TEST >> configure.log -echo VER = $VER >> configure.log -echo Z_U4 = $Z_U4 >> configure.log -echo exec_prefix = $exec_prefix >> configure.log -echo includedir = $includedir >> configure.log -echo libdir = $libdir >> configure.log -echo mandir = $mandir >> configure.log -echo prefix = $prefix >> configure.log -echo sharedlibdir = $sharedlibdir >> configure.log -echo uname = $uname >> configure.log - -# udpate Makefile with the configure results -sed < Makefile.in " -/^CC *=/s#=.*#=$CC# -/^CFLAGS *=/s#=.*#=$CFLAGS# -/^SFLAGS *=/s#=.*#=$SFLAGS# -/^LDFLAGS *=/s#=.*#=$LDFLAGS# -/^LDSHARED *=/s#=.*#=$LDSHARED# -/^CPP *=/s#=.*#=$CPP# -/^STATICLIB *=/s#=.*#=$STATICLIB# -/^SHAREDLIB *=/s#=.*#=$SHAREDLIB# -/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV# -/^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM# -/^AR *=/s#=.*#=$AR# -/^ARFLAGS *=/s#=.*#=$ARFLAGS# -/^RANLIB *=/s#=.*#=$RANLIB# -/^LDCONFIG *=/s#=.*#=$LDCONFIG# -/^LDSHAREDLIBC *=/s#=.*#=$LDSHAREDLIBC# -/^EXE *=/s#=.*#=$EXE# -/^prefix *=/s#=.*#=$prefix# -/^exec_prefix *=/s#=.*#=$exec_prefix# -/^libdir *=/s#=.*#=$libdir# -/^sharedlibdir *=/s#=.*#=$sharedlibdir# -/^includedir *=/s#=.*#=$includedir# -/^mandir *=/s#=.*#=$mandir# -/^OBJC *=/s#=.*#= $OBJC# -/^PIC_OBJC *=/s#=.*#= $PIC_OBJC# -/^all: */s#:.*#: $ALL# -/^test: */s#:.*#: $TEST# -" > Makefile - -# create zlib.pc with the configure results -sed < zlib.pc.in " -/^CC *=/s#=.*#=$CC# -/^CFLAGS *=/s#=.*#=$CFLAGS# -/^CPP *=/s#=.*#=$CPP# -/^LDSHARED *=/s#=.*#=$LDSHARED# -/^STATICLIB *=/s#=.*#=$STATICLIB# -/^SHAREDLIB *=/s#=.*#=$SHAREDLIB# -/^SHAREDLIBV *=/s#=.*#=$SHAREDLIBV# -/^SHAREDLIBM *=/s#=.*#=$SHAREDLIBM# -/^AR *=/s#=.*#=$AR# -/^ARFLAGS *=/s#=.*#=$ARFLAGS# -/^RANLIB *=/s#=.*#=$RANLIB# -/^EXE *=/s#=.*#=$EXE# -/^prefix *=/s#=.*#=$prefix# -/^exec_prefix *=/s#=.*#=$exec_prefix# -/^libdir *=/s#=.*#=$libdir# -/^sharedlibdir *=/s#=.*#=$sharedlibdir# -/^includedir *=/s#=.*#=$includedir# -/^mandir *=/s#=.*#=$mandir# -/^LDFLAGS *=/s#=.*#=$LDFLAGS# -" | sed -e " -s/\@VERSION\@/$VER/g; -" > zlib.pc - -# done -leave 0 diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/README.contrib b/src/beast/test/zlib/zlib-1.2.8/contrib/README.contrib deleted file mode 100644 index c66349b7c67..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/README.contrib +++ /dev/null @@ -1,78 +0,0 @@ -All files under this contrib directory are UNSUPPORTED. There were -provided by users of zlib and were not tested by the authors of zlib. -Use at your own risk. Please contact the authors of the contributions -for help about these, not the zlib authors. Thanks. - - -ada/ by Dmitriy Anisimkov - Support for Ada - See http://zlib-ada.sourceforge.net/ - -amd64/ by Mikhail Teterin - asm code for AMD64 - See patch at http://www.freebsd.org/cgi/query-pr.cgi?pr=bin/96393 - -asm686/ by Brian Raiter - asm code for Pentium and PPro/PII, using the AT&T (GNU as) syntax - See http://www.muppetlabs.com/~breadbox/software/assembly.html - -blast/ by Mark Adler - Decompressor for output of PKWare Data Compression Library (DCL) - -delphi/ by Cosmin Truta - Support for Delphi and C++ Builder - -dotzlib/ by Henrik Ravn - Support for Microsoft .Net and Visual C++ .Net - -gcc_gvmat64/by Gilles Vollant - GCC Version of x86 64-bit (AMD64 and Intel EM64t) code for x64 - assembler to replace longest_match() and inflate_fast() - -infback9/ by Mark Adler - Unsupported diffs to infback to decode the deflate64 format - -inflate86/ by Chris Anderson - Tuned x86 gcc asm code to replace inflate_fast() - -iostream/ by Kevin Ruland - A C++ I/O streams interface to the zlib gz* functions - -iostream2/ by Tyge Løvset - Another C++ I/O streams interface - -iostream3/ by Ludwig Schwardt - and Kevin Ruland - Yet another C++ I/O streams interface - -masmx64/ by Gilles Vollant - x86 64-bit (AMD64 and Intel EM64t) code for x64 assembler to - replace longest_match() and inflate_fast(), also masm x86 - 64-bits translation of Chris Anderson inflate_fast() - -masmx86/ by Gilles Vollant - x86 asm code to replace longest_match() and inflate_fast(), - for Visual C++ and MASM (32 bits). - Based on Brian Raiter (asm686) and Chris Anderson (inflate86) - -minizip/ by Gilles Vollant - Mini zip and unzip based on zlib - Includes Zip64 support by Mathias Svensson - See http://www.winimage.com/zLibDll/unzip.html - -pascal/ by Bob Dellaca et al. - Support for Pascal - -puff/ by Mark Adler - Small, low memory usage inflate. Also serves to provide an - unambiguous description of the deflate format. - -testzlib/ by Gilles Vollant - Example of the use of zlib - -untgz/ by Pedro A. Aranda Gutierrez - A very simple tar.gz file extractor using zlib - -vstudio/ by Gilles Vollant - Building a minizip-enhanced zlib with Microsoft Visual Studio - Includes vc11 from kreuzerkrieg and vc12 from davispuh diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/ada/buffer_demo.adb b/src/beast/test/zlib/zlib-1.2.8/contrib/ada/buffer_demo.adb deleted file mode 100644 index 46b8638107f..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/ada/buffer_demo.adb +++ /dev/null @@ -1,106 +0,0 @@ ----------------------------------------------------------------- --- ZLib for Ada thick binding. -- --- -- --- Copyright (C) 2002-2004 Dmitriy Anisimkov -- --- -- --- Open source license information is in the zlib.ads file. -- ----------------------------------------------------------------- --- --- $Id: buffer_demo.adb,v 1.3 2004/09/06 06:55:35 vagul Exp $ - --- This demo program provided by Dr Steve Sangwine --- --- Demonstration of a problem with Zlib-Ada (already fixed) when a buffer --- of exactly the correct size is used for decompressed data, and the last --- few bytes passed in to Zlib are checksum bytes. - --- This program compresses a string of text, and then decompresses the --- compressed text into a buffer of the same size as the original text. - -with Ada.Streams; use Ada.Streams; -with Ada.Text_IO; - -with ZLib; use ZLib; - -procedure Buffer_Demo is - EOL : Character renames ASCII.LF; - Text : constant String - := "Four score and seven years ago our fathers brought forth," & EOL & - "upon this continent, a new nation, conceived in liberty," & EOL & - "and dedicated to the proposition that `all men are created equal'."; - - Source : Stream_Element_Array (1 .. Text'Length); - for Source'Address use Text'Address; - -begin - Ada.Text_IO.Put (Text); - Ada.Text_IO.New_Line; - Ada.Text_IO.Put_Line - ("Uncompressed size : " & Positive'Image (Text'Length) & " bytes"); - - declare - Compressed_Data : Stream_Element_Array (1 .. Text'Length); - L : Stream_Element_Offset; - begin - Compress : declare - Compressor : Filter_Type; - I : Stream_Element_Offset; - begin - Deflate_Init (Compressor); - - -- Compress the whole of T at once. - - Translate (Compressor, Source, I, Compressed_Data, L, Finish); - pragma Assert (I = Source'Last); - - Close (Compressor); - - Ada.Text_IO.Put_Line - ("Compressed size : " - & Stream_Element_Offset'Image (L) & " bytes"); - end Compress; - - -- Now we decompress the data, passing short blocks of data to Zlib - -- (because this demonstrates the problem - the last block passed will - -- contain checksum information and there will be no output, only a - -- check inside Zlib that the checksum is correct). - - Decompress : declare - Decompressor : Filter_Type; - - Uncompressed_Data : Stream_Element_Array (1 .. Text'Length); - - Block_Size : constant := 4; - -- This makes sure that the last block contains - -- only Adler checksum data. - - P : Stream_Element_Offset := Compressed_Data'First - 1; - O : Stream_Element_Offset; - begin - Inflate_Init (Decompressor); - - loop - Translate - (Decompressor, - Compressed_Data - (P + 1 .. Stream_Element_Offset'Min (P + Block_Size, L)), - P, - Uncompressed_Data - (Total_Out (Decompressor) + 1 .. Uncompressed_Data'Last), - O, - No_Flush); - - Ada.Text_IO.Put_Line - ("Total in : " & Count'Image (Total_In (Decompressor)) & - ", out : " & Count'Image (Total_Out (Decompressor))); - - exit when P = L; - end loop; - - Ada.Text_IO.New_Line; - Ada.Text_IO.Put_Line - ("Decompressed text matches original text : " - & Boolean'Image (Uncompressed_Data = Source)); - end Decompress; - end; -end Buffer_Demo; diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/ada/mtest.adb b/src/beast/test/zlib/zlib-1.2.8/contrib/ada/mtest.adb deleted file mode 100644 index c4dfd080f0c..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/ada/mtest.adb +++ /dev/null @@ -1,156 +0,0 @@ ----------------------------------------------------------------- --- ZLib for Ada thick binding. -- --- -- --- Copyright (C) 2002-2003 Dmitriy Anisimkov -- --- -- --- Open source license information is in the zlib.ads file. -- ----------------------------------------------------------------- --- Continuous test for ZLib multithreading. If the test would fail --- we should provide thread safe allocation routines for the Z_Stream. --- --- $Id: mtest.adb,v 1.4 2004/07/23 07:49:54 vagul Exp $ - -with ZLib; -with Ada.Streams; -with Ada.Numerics.Discrete_Random; -with Ada.Text_IO; -with Ada.Exceptions; -with Ada.Task_Identification; - -procedure MTest is - use Ada.Streams; - use ZLib; - - Stop : Boolean := False; - - pragma Atomic (Stop); - - subtype Visible_Symbols is Stream_Element range 16#20# .. 16#7E#; - - package Random_Elements is - new Ada.Numerics.Discrete_Random (Visible_Symbols); - - task type Test_Task; - - task body Test_Task is - Buffer : Stream_Element_Array (1 .. 100_000); - Gen : Random_Elements.Generator; - - Buffer_First : Stream_Element_Offset; - Compare_First : Stream_Element_Offset; - - Deflate : Filter_Type; - Inflate : Filter_Type; - - procedure Further (Item : in Stream_Element_Array); - - procedure Read_Buffer - (Item : out Ada.Streams.Stream_Element_Array; - Last : out Ada.Streams.Stream_Element_Offset); - - ------------- - -- Further -- - ------------- - - procedure Further (Item : in Stream_Element_Array) is - - procedure Compare (Item : in Stream_Element_Array); - - ------------- - -- Compare -- - ------------- - - procedure Compare (Item : in Stream_Element_Array) is - Next_First : Stream_Element_Offset := Compare_First + Item'Length; - begin - if Buffer (Compare_First .. Next_First - 1) /= Item then - raise Program_Error; - end if; - - Compare_First := Next_First; - end Compare; - - procedure Compare_Write is new ZLib.Write (Write => Compare); - begin - Compare_Write (Inflate, Item, No_Flush); - end Further; - - ----------------- - -- Read_Buffer -- - ----------------- - - procedure Read_Buffer - (Item : out Ada.Streams.Stream_Element_Array; - Last : out Ada.Streams.Stream_Element_Offset) - is - Buff_Diff : Stream_Element_Offset := Buffer'Last - Buffer_First; - Next_First : Stream_Element_Offset; - begin - if Item'Length <= Buff_Diff then - Last := Item'Last; - - Next_First := Buffer_First + Item'Length; - - Item := Buffer (Buffer_First .. Next_First - 1); - - Buffer_First := Next_First; - else - Last := Item'First + Buff_Diff; - Item (Item'First .. Last) := Buffer (Buffer_First .. Buffer'Last); - Buffer_First := Buffer'Last + 1; - end if; - end Read_Buffer; - - procedure Translate is new Generic_Translate - (Data_In => Read_Buffer, - Data_Out => Further); - - begin - Random_Elements.Reset (Gen); - - Buffer := (others => 20); - - Main : loop - for J in Buffer'Range loop - Buffer (J) := Random_Elements.Random (Gen); - - Deflate_Init (Deflate); - Inflate_Init (Inflate); - - Buffer_First := Buffer'First; - Compare_First := Buffer'First; - - Translate (Deflate); - - if Compare_First /= Buffer'Last + 1 then - raise Program_Error; - end if; - - Ada.Text_IO.Put_Line - (Ada.Task_Identification.Image - (Ada.Task_Identification.Current_Task) - & Stream_Element_Offset'Image (J) - & ZLib.Count'Image (Total_Out (Deflate))); - - Close (Deflate); - Close (Inflate); - - exit Main when Stop; - end loop; - end loop Main; - exception - when E : others => - Ada.Text_IO.Put_Line (Ada.Exceptions.Exception_Information (E)); - Stop := True; - end Test_Task; - - Test : array (1 .. 4) of Test_Task; - - pragma Unreferenced (Test); - - Dummy : Character; - -begin - Ada.Text_IO.Get_Immediate (Dummy); - Stop := True; -end MTest; diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/ada/read.adb b/src/beast/test/zlib/zlib-1.2.8/contrib/ada/read.adb deleted file mode 100644 index 1f2efbfeb80..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/ada/read.adb +++ /dev/null @@ -1,156 +0,0 @@ ----------------------------------------------------------------- --- ZLib for Ada thick binding. -- --- -- --- Copyright (C) 2002-2003 Dmitriy Anisimkov -- --- -- --- Open source license information is in the zlib.ads file. -- ----------------------------------------------------------------- - --- $Id: read.adb,v 1.8 2004/05/31 10:53:40 vagul Exp $ - --- Test/demo program for the generic read interface. - -with Ada.Numerics.Discrete_Random; -with Ada.Streams; -with Ada.Text_IO; - -with ZLib; - -procedure Read is - - use Ada.Streams; - - ------------------------------------ - -- Test configuration parameters -- - ------------------------------------ - - File_Size : Stream_Element_Offset := 100_000; - - Continuous : constant Boolean := False; - -- If this constant is True, the test would be repeated again and again, - -- with increment File_Size for every iteration. - - Header : constant ZLib.Header_Type := ZLib.Default; - -- Do not use Header other than Default in ZLib versions 1.1.4 and older. - - Init_Random : constant := 8; - -- We are using the same random sequence, in case of we catch bug, - -- so we would be able to reproduce it. - - -- End -- - - Pack_Size : Stream_Element_Offset; - Offset : Stream_Element_Offset; - - Filter : ZLib.Filter_Type; - - subtype Visible_Symbols - is Stream_Element range 16#20# .. 16#7E#; - - package Random_Elements is new - Ada.Numerics.Discrete_Random (Visible_Symbols); - - Gen : Random_Elements.Generator; - Period : constant Stream_Element_Offset := 200; - -- Period constant variable for random generator not to be very random. - -- Bigger period, harder random. - - Read_Buffer : Stream_Element_Array (1 .. 2048); - Read_First : Stream_Element_Offset; - Read_Last : Stream_Element_Offset; - - procedure Reset; - - procedure Read - (Item : out Stream_Element_Array; - Last : out Stream_Element_Offset); - -- this procedure is for generic instantiation of - -- ZLib.Read - -- reading data from the File_In. - - procedure Read is new ZLib.Read - (Read, - Read_Buffer, - Rest_First => Read_First, - Rest_Last => Read_Last); - - ---------- - -- Read -- - ---------- - - procedure Read - (Item : out Stream_Element_Array; - Last : out Stream_Element_Offset) is - begin - Last := Stream_Element_Offset'Min - (Item'Last, - Item'First + File_Size - Offset); - - for J in Item'First .. Last loop - if J < Item'First + Period then - Item (J) := Random_Elements.Random (Gen); - else - Item (J) := Item (J - Period); - end if; - - Offset := Offset + 1; - end loop; - end Read; - - ----------- - -- Reset -- - ----------- - - procedure Reset is - begin - Random_Elements.Reset (Gen, Init_Random); - Pack_Size := 0; - Offset := 1; - Read_First := Read_Buffer'Last + 1; - Read_Last := Read_Buffer'Last; - end Reset; - -begin - Ada.Text_IO.Put_Line ("ZLib " & ZLib.Version); - - loop - for Level in ZLib.Compression_Level'Range loop - - Ada.Text_IO.Put ("Level =" - & ZLib.Compression_Level'Image (Level)); - - -- Deflate using generic instantiation. - - ZLib.Deflate_Init - (Filter, - Level, - Header => Header); - - Reset; - - Ada.Text_IO.Put - (Stream_Element_Offset'Image (File_Size) & " ->"); - - loop - declare - Buffer : Stream_Element_Array (1 .. 1024); - Last : Stream_Element_Offset; - begin - Read (Filter, Buffer, Last); - - Pack_Size := Pack_Size + Last - Buffer'First + 1; - - exit when Last < Buffer'Last; - end; - end loop; - - Ada.Text_IO.Put_Line (Stream_Element_Offset'Image (Pack_Size)); - - ZLib.Close (Filter); - end loop; - - exit when not Continuous; - - File_Size := File_Size + 1; - end loop; -end Read; diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/ada/readme.txt b/src/beast/test/zlib/zlib-1.2.8/contrib/ada/readme.txt deleted file mode 100644 index ce4d2cadf0d..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/ada/readme.txt +++ /dev/null @@ -1,65 +0,0 @@ - ZLib for Ada thick binding (ZLib.Ada) - Release 1.3 - -ZLib.Ada is a thick binding interface to the popular ZLib data -compression library, available at http://www.gzip.org/zlib/. -It provides Ada-style access to the ZLib C library. - - - Here are the main changes since ZLib.Ada 1.2: - -- Attension: ZLib.Read generic routine have a initialization requirement - for Read_Last parameter now. It is a bit incompartible with previous version, - but extends functionality, we could use new parameters Allow_Read_Some and - Flush now. - -- Added Is_Open routines to ZLib and ZLib.Streams packages. - -- Add pragma Assert to check Stream_Element is 8 bit. - -- Fix extraction to buffer with exact known decompressed size. Error reported by - Steve Sangwine. - -- Fix definition of ULong (changed to unsigned_long), fix regression on 64 bits - computers. Patch provided by Pascal Obry. - -- Add Status_Error exception definition. - -- Add pragma Assertion that Ada.Streams.Stream_Element size is 8 bit. - - - How to build ZLib.Ada under GNAT - -You should have the ZLib library already build on your computer, before -building ZLib.Ada. Make the directory of ZLib.Ada sources current and -issue the command: - - gnatmake test -largs -L -lz - -Or use the GNAT project file build for GNAT 3.15 or later: - - gnatmake -Pzlib.gpr -L - - - How to build ZLib.Ada under Aonix ObjectAda for Win32 7.2.2 - -1. Make a project with all *.ads and *.adb files from the distribution. -2. Build the libz.a library from the ZLib C sources. -3. Rename libz.a to z.lib. -4. Add the library z.lib to the project. -5. Add the libc.lib library from the ObjectAda distribution to the project. -6. Build the executable using test.adb as a main procedure. - - - How to use ZLib.Ada - -The source files test.adb and read.adb are small demo programs that show -the main functionality of ZLib.Ada. - -The routines from the package specifications are commented. - - -Homepage: http://zlib-ada.sourceforge.net/ -Author: Dmitriy Anisimkov - -Contributors: Pascal Obry , Steve Sangwine diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/ada/test.adb b/src/beast/test/zlib/zlib-1.2.8/contrib/ada/test.adb deleted file mode 100644 index 90773acfa18..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/ada/test.adb +++ /dev/null @@ -1,463 +0,0 @@ ----------------------------------------------------------------- --- ZLib for Ada thick binding. -- --- -- --- Copyright (C) 2002-2003 Dmitriy Anisimkov -- --- -- --- Open source license information is in the zlib.ads file. -- ----------------------------------------------------------------- - --- $Id: test.adb,v 1.17 2003/08/12 12:13:30 vagul Exp $ - --- The program has a few aims. --- 1. Test ZLib.Ada95 thick binding functionality. --- 2. Show the example of use main functionality of the ZLib.Ada95 binding. --- 3. Build this program automatically compile all ZLib.Ada95 packages under --- GNAT Ada95 compiler. - -with ZLib.Streams; -with Ada.Streams.Stream_IO; -with Ada.Numerics.Discrete_Random; - -with Ada.Text_IO; - -with Ada.Calendar; - -procedure Test is - - use Ada.Streams; - use Stream_IO; - - ------------------------------------ - -- Test configuration parameters -- - ------------------------------------ - - File_Size : Count := 100_000; - Continuous : constant Boolean := False; - - Header : constant ZLib.Header_Type := ZLib.Default; - -- ZLib.None; - -- ZLib.Auto; - -- ZLib.GZip; - -- Do not use Header other then Default in ZLib versions 1.1.4 - -- and older. - - Strategy : constant ZLib.Strategy_Type := ZLib.Default_Strategy; - Init_Random : constant := 10; - - -- End -- - - In_File_Name : constant String := "testzlib.in"; - -- Name of the input file - - Z_File_Name : constant String := "testzlib.zlb"; - -- Name of the compressed file. - - Out_File_Name : constant String := "testzlib.out"; - -- Name of the decompressed file. - - File_In : File_Type; - File_Out : File_Type; - File_Back : File_Type; - File_Z : ZLib.Streams.Stream_Type; - - Filter : ZLib.Filter_Type; - - Time_Stamp : Ada.Calendar.Time; - - procedure Generate_File; - -- Generate file of spetsified size with some random data. - -- The random data is repeatable, for the good compression. - - procedure Compare_Streams - (Left, Right : in out Root_Stream_Type'Class); - -- The procedure compearing data in 2 streams. - -- It is for compare data before and after compression/decompression. - - procedure Compare_Files (Left, Right : String); - -- Compare files. Based on the Compare_Streams. - - procedure Copy_Streams - (Source, Target : in out Root_Stream_Type'Class; - Buffer_Size : in Stream_Element_Offset := 1024); - -- Copying data from one stream to another. It is for test stream - -- interface of the library. - - procedure Data_In - (Item : out Stream_Element_Array; - Last : out Stream_Element_Offset); - -- this procedure is for generic instantiation of - -- ZLib.Generic_Translate. - -- reading data from the File_In. - - procedure Data_Out (Item : in Stream_Element_Array); - -- this procedure is for generic instantiation of - -- ZLib.Generic_Translate. - -- writing data to the File_Out. - - procedure Stamp; - -- Store the timestamp to the local variable. - - procedure Print_Statistic (Msg : String; Data_Size : ZLib.Count); - -- Print the time statistic with the message. - - procedure Translate is new ZLib.Generic_Translate - (Data_In => Data_In, - Data_Out => Data_Out); - -- This procedure is moving data from File_In to File_Out - -- with compression or decompression, depend on initialization of - -- Filter parameter. - - ------------------- - -- Compare_Files -- - ------------------- - - procedure Compare_Files (Left, Right : String) is - Left_File, Right_File : File_Type; - begin - Open (Left_File, In_File, Left); - Open (Right_File, In_File, Right); - Compare_Streams (Stream (Left_File).all, Stream (Right_File).all); - Close (Left_File); - Close (Right_File); - end Compare_Files; - - --------------------- - -- Compare_Streams -- - --------------------- - - procedure Compare_Streams - (Left, Right : in out Ada.Streams.Root_Stream_Type'Class) - is - Left_Buffer, Right_Buffer : Stream_Element_Array (0 .. 16#FFF#); - Left_Last, Right_Last : Stream_Element_Offset; - begin - loop - Read (Left, Left_Buffer, Left_Last); - Read (Right, Right_Buffer, Right_Last); - - if Left_Last /= Right_Last then - Ada.Text_IO.Put_Line ("Compare error :" - & Stream_Element_Offset'Image (Left_Last) - & " /= " - & Stream_Element_Offset'Image (Right_Last)); - - raise Constraint_Error; - - elsif Left_Buffer (0 .. Left_Last) - /= Right_Buffer (0 .. Right_Last) - then - Ada.Text_IO.Put_Line ("ERROR: IN and OUT files is not equal."); - raise Constraint_Error; - - end if; - - exit when Left_Last < Left_Buffer'Last; - end loop; - end Compare_Streams; - - ------------------ - -- Copy_Streams -- - ------------------ - - procedure Copy_Streams - (Source, Target : in out Ada.Streams.Root_Stream_Type'Class; - Buffer_Size : in Stream_Element_Offset := 1024) - is - Buffer : Stream_Element_Array (1 .. Buffer_Size); - Last : Stream_Element_Offset; - begin - loop - Read (Source, Buffer, Last); - Write (Target, Buffer (1 .. Last)); - - exit when Last < Buffer'Last; - end loop; - end Copy_Streams; - - ------------- - -- Data_In -- - ------------- - - procedure Data_In - (Item : out Stream_Element_Array; - Last : out Stream_Element_Offset) is - begin - Read (File_In, Item, Last); - end Data_In; - - -------------- - -- Data_Out -- - -------------- - - procedure Data_Out (Item : in Stream_Element_Array) is - begin - Write (File_Out, Item); - end Data_Out; - - ------------------- - -- Generate_File -- - ------------------- - - procedure Generate_File is - subtype Visible_Symbols is Stream_Element range 16#20# .. 16#7E#; - - package Random_Elements is - new Ada.Numerics.Discrete_Random (Visible_Symbols); - - Gen : Random_Elements.Generator; - Buffer : Stream_Element_Array := (1 .. 77 => 16#20#) & 10; - - Buffer_Count : constant Count := File_Size / Buffer'Length; - -- Number of same buffers in the packet. - - Density : constant Count := 30; -- from 0 to Buffer'Length - 2; - - procedure Fill_Buffer (J, D : in Count); - -- Change the part of the buffer. - - ----------------- - -- Fill_Buffer -- - ----------------- - - procedure Fill_Buffer (J, D : in Count) is - begin - for K in 0 .. D loop - Buffer - (Stream_Element_Offset ((J + K) mod (Buffer'Length - 1) + 1)) - := Random_Elements.Random (Gen); - - end loop; - end Fill_Buffer; - - begin - Random_Elements.Reset (Gen, Init_Random); - - Create (File_In, Out_File, In_File_Name); - - Fill_Buffer (1, Buffer'Length - 2); - - for J in 1 .. Buffer_Count loop - Write (File_In, Buffer); - - Fill_Buffer (J, Density); - end loop; - - -- fill remain size. - - Write - (File_In, - Buffer - (1 .. Stream_Element_Offset - (File_Size - Buffer'Length * Buffer_Count))); - - Flush (File_In); - Close (File_In); - end Generate_File; - - --------------------- - -- Print_Statistic -- - --------------------- - - procedure Print_Statistic (Msg : String; Data_Size : ZLib.Count) is - use Ada.Calendar; - use Ada.Text_IO; - - package Count_IO is new Integer_IO (ZLib.Count); - - Curr_Dur : Duration := Clock - Time_Stamp; - begin - Put (Msg); - - Set_Col (20); - Ada.Text_IO.Put ("size ="); - - Count_IO.Put - (Data_Size, - Width => Stream_IO.Count'Image (File_Size)'Length); - - Put_Line (" duration =" & Duration'Image (Curr_Dur)); - end Print_Statistic; - - ----------- - -- Stamp -- - ----------- - - procedure Stamp is - begin - Time_Stamp := Ada.Calendar.Clock; - end Stamp; - -begin - Ada.Text_IO.Put_Line ("ZLib " & ZLib.Version); - - loop - Generate_File; - - for Level in ZLib.Compression_Level'Range loop - - Ada.Text_IO.Put_Line ("Level =" - & ZLib.Compression_Level'Image (Level)); - - -- Test generic interface. - Open (File_In, In_File, In_File_Name); - Create (File_Out, Out_File, Z_File_Name); - - Stamp; - - -- Deflate using generic instantiation. - - ZLib.Deflate_Init - (Filter => Filter, - Level => Level, - Strategy => Strategy, - Header => Header); - - Translate (Filter); - Print_Statistic ("Generic compress", ZLib.Total_Out (Filter)); - ZLib.Close (Filter); - - Close (File_In); - Close (File_Out); - - Open (File_In, In_File, Z_File_Name); - Create (File_Out, Out_File, Out_File_Name); - - Stamp; - - -- Inflate using generic instantiation. - - ZLib.Inflate_Init (Filter, Header => Header); - - Translate (Filter); - Print_Statistic ("Generic decompress", ZLib.Total_Out (Filter)); - - ZLib.Close (Filter); - - Close (File_In); - Close (File_Out); - - Compare_Files (In_File_Name, Out_File_Name); - - -- Test stream interface. - - -- Compress to the back stream. - - Open (File_In, In_File, In_File_Name); - Create (File_Back, Out_File, Z_File_Name); - - Stamp; - - ZLib.Streams.Create - (Stream => File_Z, - Mode => ZLib.Streams.Out_Stream, - Back => ZLib.Streams.Stream_Access - (Stream (File_Back)), - Back_Compressed => True, - Level => Level, - Strategy => Strategy, - Header => Header); - - Copy_Streams - (Source => Stream (File_In).all, - Target => File_Z); - - -- Flushing internal buffers to the back stream. - - ZLib.Streams.Flush (File_Z, ZLib.Finish); - - Print_Statistic ("Write compress", - ZLib.Streams.Write_Total_Out (File_Z)); - - ZLib.Streams.Close (File_Z); - - Close (File_In); - Close (File_Back); - - -- Compare reading from original file and from - -- decompression stream. - - Open (File_In, In_File, In_File_Name); - Open (File_Back, In_File, Z_File_Name); - - ZLib.Streams.Create - (Stream => File_Z, - Mode => ZLib.Streams.In_Stream, - Back => ZLib.Streams.Stream_Access - (Stream (File_Back)), - Back_Compressed => True, - Header => Header); - - Stamp; - Compare_Streams (Stream (File_In).all, File_Z); - - Print_Statistic ("Read decompress", - ZLib.Streams.Read_Total_Out (File_Z)); - - ZLib.Streams.Close (File_Z); - Close (File_In); - Close (File_Back); - - -- Compress by reading from compression stream. - - Open (File_Back, In_File, In_File_Name); - Create (File_Out, Out_File, Z_File_Name); - - ZLib.Streams.Create - (Stream => File_Z, - Mode => ZLib.Streams.In_Stream, - Back => ZLib.Streams.Stream_Access - (Stream (File_Back)), - Back_Compressed => False, - Level => Level, - Strategy => Strategy, - Header => Header); - - Stamp; - Copy_Streams - (Source => File_Z, - Target => Stream (File_Out).all); - - Print_Statistic ("Read compress", - ZLib.Streams.Read_Total_Out (File_Z)); - - ZLib.Streams.Close (File_Z); - - Close (File_Out); - Close (File_Back); - - -- Decompress to decompression stream. - - Open (File_In, In_File, Z_File_Name); - Create (File_Back, Out_File, Out_File_Name); - - ZLib.Streams.Create - (Stream => File_Z, - Mode => ZLib.Streams.Out_Stream, - Back => ZLib.Streams.Stream_Access - (Stream (File_Back)), - Back_Compressed => False, - Header => Header); - - Stamp; - - Copy_Streams - (Source => Stream (File_In).all, - Target => File_Z); - - Print_Statistic ("Write decompress", - ZLib.Streams.Write_Total_Out (File_Z)); - - ZLib.Streams.Close (File_Z); - Close (File_In); - Close (File_Back); - - Compare_Files (In_File_Name, Out_File_Name); - end loop; - - Ada.Text_IO.Put_Line (Count'Image (File_Size) & " Ok."); - - exit when not Continuous; - - File_Size := File_Size + 1; - end loop; -end Test; diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/ada/zlib-streams.adb b/src/beast/test/zlib/zlib-1.2.8/contrib/ada/zlib-streams.adb deleted file mode 100644 index b6497bae286..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/ada/zlib-streams.adb +++ /dev/null @@ -1,225 +0,0 @@ ----------------------------------------------------------------- --- ZLib for Ada thick binding. -- --- -- --- Copyright (C) 2002-2003 Dmitriy Anisimkov -- --- -- --- Open source license information is in the zlib.ads file. -- ----------------------------------------------------------------- - --- $Id: zlib-streams.adb,v 1.10 2004/05/31 10:53:40 vagul Exp $ - -with Ada.Unchecked_Deallocation; - -package body ZLib.Streams is - - ----------- - -- Close -- - ----------- - - procedure Close (Stream : in out Stream_Type) is - procedure Free is new Ada.Unchecked_Deallocation - (Stream_Element_Array, Buffer_Access); - begin - if Stream.Mode = Out_Stream or Stream.Mode = Duplex then - -- We should flush the data written by the writer. - - Flush (Stream, Finish); - - Close (Stream.Writer); - end if; - - if Stream.Mode = In_Stream or Stream.Mode = Duplex then - Close (Stream.Reader); - Free (Stream.Buffer); - end if; - end Close; - - ------------ - -- Create -- - ------------ - - procedure Create - (Stream : out Stream_Type; - Mode : in Stream_Mode; - Back : in Stream_Access; - Back_Compressed : in Boolean; - Level : in Compression_Level := Default_Compression; - Strategy : in Strategy_Type := Default_Strategy; - Header : in Header_Type := Default; - Read_Buffer_Size : in Ada.Streams.Stream_Element_Offset - := Default_Buffer_Size; - Write_Buffer_Size : in Ada.Streams.Stream_Element_Offset - := Default_Buffer_Size) - is - - subtype Buffer_Subtype is Stream_Element_Array (1 .. Read_Buffer_Size); - - procedure Init_Filter - (Filter : in out Filter_Type; - Compress : in Boolean); - - ----------------- - -- Init_Filter -- - ----------------- - - procedure Init_Filter - (Filter : in out Filter_Type; - Compress : in Boolean) is - begin - if Compress then - Deflate_Init - (Filter, Level, Strategy, Header => Header); - else - Inflate_Init (Filter, Header => Header); - end if; - end Init_Filter; - - begin - Stream.Back := Back; - Stream.Mode := Mode; - - if Mode = Out_Stream or Mode = Duplex then - Init_Filter (Stream.Writer, Back_Compressed); - Stream.Buffer_Size := Write_Buffer_Size; - else - Stream.Buffer_Size := 0; - end if; - - if Mode = In_Stream or Mode = Duplex then - Init_Filter (Stream.Reader, not Back_Compressed); - - Stream.Buffer := new Buffer_Subtype; - Stream.Rest_First := Stream.Buffer'Last + 1; - Stream.Rest_Last := Stream.Buffer'Last; - end if; - end Create; - - ----------- - -- Flush -- - ----------- - - procedure Flush - (Stream : in out Stream_Type; - Mode : in Flush_Mode := Sync_Flush) - is - Buffer : Stream_Element_Array (1 .. Stream.Buffer_Size); - Last : Stream_Element_Offset; - begin - loop - Flush (Stream.Writer, Buffer, Last, Mode); - - Ada.Streams.Write (Stream.Back.all, Buffer (1 .. Last)); - - exit when Last < Buffer'Last; - end loop; - end Flush; - - ------------- - -- Is_Open -- - ------------- - - function Is_Open (Stream : Stream_Type) return Boolean is - begin - return Is_Open (Stream.Reader) or else Is_Open (Stream.Writer); - end Is_Open; - - ---------- - -- Read -- - ---------- - - procedure Read - (Stream : in out Stream_Type; - Item : out Stream_Element_Array; - Last : out Stream_Element_Offset) - is - - procedure Read - (Item : out Stream_Element_Array; - Last : out Stream_Element_Offset); - - ---------- - -- Read -- - ---------- - - procedure Read - (Item : out Stream_Element_Array; - Last : out Stream_Element_Offset) is - begin - Ada.Streams.Read (Stream.Back.all, Item, Last); - end Read; - - procedure Read is new ZLib.Read - (Read => Read, - Buffer => Stream.Buffer.all, - Rest_First => Stream.Rest_First, - Rest_Last => Stream.Rest_Last); - - begin - Read (Stream.Reader, Item, Last); - end Read; - - ------------------- - -- Read_Total_In -- - ------------------- - - function Read_Total_In (Stream : in Stream_Type) return Count is - begin - return Total_In (Stream.Reader); - end Read_Total_In; - - -------------------- - -- Read_Total_Out -- - -------------------- - - function Read_Total_Out (Stream : in Stream_Type) return Count is - begin - return Total_Out (Stream.Reader); - end Read_Total_Out; - - ----------- - -- Write -- - ----------- - - procedure Write - (Stream : in out Stream_Type; - Item : in Stream_Element_Array) - is - - procedure Write (Item : in Stream_Element_Array); - - ----------- - -- Write -- - ----------- - - procedure Write (Item : in Stream_Element_Array) is - begin - Ada.Streams.Write (Stream.Back.all, Item); - end Write; - - procedure Write is new ZLib.Write - (Write => Write, - Buffer_Size => Stream.Buffer_Size); - - begin - Write (Stream.Writer, Item, No_Flush); - end Write; - - -------------------- - -- Write_Total_In -- - -------------------- - - function Write_Total_In (Stream : in Stream_Type) return Count is - begin - return Total_In (Stream.Writer); - end Write_Total_In; - - --------------------- - -- Write_Total_Out -- - --------------------- - - function Write_Total_Out (Stream : in Stream_Type) return Count is - begin - return Total_Out (Stream.Writer); - end Write_Total_Out; - -end ZLib.Streams; diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/ada/zlib-streams.ads b/src/beast/test/zlib/zlib-1.2.8/contrib/ada/zlib-streams.ads deleted file mode 100644 index f0193c6baee..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/ada/zlib-streams.ads +++ /dev/null @@ -1,114 +0,0 @@ ----------------------------------------------------------------- --- ZLib for Ada thick binding. -- --- -- --- Copyright (C) 2002-2003 Dmitriy Anisimkov -- --- -- --- Open source license information is in the zlib.ads file. -- ----------------------------------------------------------------- - --- $Id: zlib-streams.ads,v 1.12 2004/05/31 10:53:40 vagul Exp $ - -package ZLib.Streams is - - type Stream_Mode is (In_Stream, Out_Stream, Duplex); - - type Stream_Access is access all Ada.Streams.Root_Stream_Type'Class; - - type Stream_Type is - new Ada.Streams.Root_Stream_Type with private; - - procedure Read - (Stream : in out Stream_Type; - Item : out Ada.Streams.Stream_Element_Array; - Last : out Ada.Streams.Stream_Element_Offset); - - procedure Write - (Stream : in out Stream_Type; - Item : in Ada.Streams.Stream_Element_Array); - - procedure Flush - (Stream : in out Stream_Type; - Mode : in Flush_Mode := Sync_Flush); - -- Flush the written data to the back stream, - -- all data placed to the compressor is flushing to the Back stream. - -- Should not be used untill necessary, becouse it is decreasing - -- compression. - - function Read_Total_In (Stream : in Stream_Type) return Count; - pragma Inline (Read_Total_In); - -- Return total number of bytes read from back stream so far. - - function Read_Total_Out (Stream : in Stream_Type) return Count; - pragma Inline (Read_Total_Out); - -- Return total number of bytes read so far. - - function Write_Total_In (Stream : in Stream_Type) return Count; - pragma Inline (Write_Total_In); - -- Return total number of bytes written so far. - - function Write_Total_Out (Stream : in Stream_Type) return Count; - pragma Inline (Write_Total_Out); - -- Return total number of bytes written to the back stream. - - procedure Create - (Stream : out Stream_Type; - Mode : in Stream_Mode; - Back : in Stream_Access; - Back_Compressed : in Boolean; - Level : in Compression_Level := Default_Compression; - Strategy : in Strategy_Type := Default_Strategy; - Header : in Header_Type := Default; - Read_Buffer_Size : in Ada.Streams.Stream_Element_Offset - := Default_Buffer_Size; - Write_Buffer_Size : in Ada.Streams.Stream_Element_Offset - := Default_Buffer_Size); - -- Create the Comression/Decompression stream. - -- If mode is In_Stream then Write operation is disabled. - -- If mode is Out_Stream then Read operation is disabled. - - -- If Back_Compressed is true then - -- Data written to the Stream is compressing to the Back stream - -- and data read from the Stream is decompressed data from the Back stream. - - -- If Back_Compressed is false then - -- Data written to the Stream is decompressing to the Back stream - -- and data read from the Stream is compressed data from the Back stream. - - -- !!! When the Need_Header is False ZLib-Ada is using undocumented - -- ZLib 1.1.4 functionality to do not create/wait for ZLib headers. - - function Is_Open (Stream : Stream_Type) return Boolean; - - procedure Close (Stream : in out Stream_Type); - -private - - use Ada.Streams; - - type Buffer_Access is access all Stream_Element_Array; - - type Stream_Type - is new Root_Stream_Type with - record - Mode : Stream_Mode; - - Buffer : Buffer_Access; - Rest_First : Stream_Element_Offset; - Rest_Last : Stream_Element_Offset; - -- Buffer for Read operation. - -- We need to have this buffer in the record - -- becouse not all read data from back stream - -- could be processed during the read operation. - - Buffer_Size : Stream_Element_Offset; - -- Buffer size for write operation. - -- We do not need to have this buffer - -- in the record becouse all data could be - -- processed in the write operation. - - Back : Stream_Access; - Reader : Filter_Type; - Writer : Filter_Type; - end record; - -end ZLib.Streams; diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/ada/zlib-thin.adb b/src/beast/test/zlib/zlib-1.2.8/contrib/ada/zlib-thin.adb deleted file mode 100644 index 0ca4a712046..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/ada/zlib-thin.adb +++ /dev/null @@ -1,141 +0,0 @@ ----------------------------------------------------------------- --- ZLib for Ada thick binding. -- --- -- --- Copyright (C) 2002-2003 Dmitriy Anisimkov -- --- -- --- Open source license information is in the zlib.ads file. -- ----------------------------------------------------------------- - --- $Id: zlib-thin.adb,v 1.8 2003/12/14 18:27:31 vagul Exp $ - -package body ZLib.Thin is - - ZLIB_VERSION : constant Chars_Ptr := zlibVersion; - - Z_Stream_Size : constant Int := Z_Stream'Size / System.Storage_Unit; - - -------------- - -- Avail_In -- - -------------- - - function Avail_In (Strm : in Z_Stream) return UInt is - begin - return Strm.Avail_In; - end Avail_In; - - --------------- - -- Avail_Out -- - --------------- - - function Avail_Out (Strm : in Z_Stream) return UInt is - begin - return Strm.Avail_Out; - end Avail_Out; - - ------------------ - -- Deflate_Init -- - ------------------ - - function Deflate_Init - (strm : Z_Streamp; - level : Int; - method : Int; - windowBits : Int; - memLevel : Int; - strategy : Int) - return Int is - begin - return deflateInit2 - (strm, - level, - method, - windowBits, - memLevel, - strategy, - ZLIB_VERSION, - Z_Stream_Size); - end Deflate_Init; - - ------------------ - -- Inflate_Init -- - ------------------ - - function Inflate_Init (strm : Z_Streamp; windowBits : Int) return Int is - begin - return inflateInit2 (strm, windowBits, ZLIB_VERSION, Z_Stream_Size); - end Inflate_Init; - - ------------------------ - -- Last_Error_Message -- - ------------------------ - - function Last_Error_Message (Strm : in Z_Stream) return String is - use Interfaces.C.Strings; - begin - if Strm.msg = Null_Ptr then - return ""; - else - return Value (Strm.msg); - end if; - end Last_Error_Message; - - ------------ - -- Set_In -- - ------------ - - procedure Set_In - (Strm : in out Z_Stream; - Buffer : in Voidp; - Size : in UInt) is - begin - Strm.Next_In := Buffer; - Strm.Avail_In := Size; - end Set_In; - - ------------------ - -- Set_Mem_Func -- - ------------------ - - procedure Set_Mem_Func - (Strm : in out Z_Stream; - Opaque : in Voidp; - Alloc : in alloc_func; - Free : in free_func) is - begin - Strm.opaque := Opaque; - Strm.zalloc := Alloc; - Strm.zfree := Free; - end Set_Mem_Func; - - ------------- - -- Set_Out -- - ------------- - - procedure Set_Out - (Strm : in out Z_Stream; - Buffer : in Voidp; - Size : in UInt) is - begin - Strm.Next_Out := Buffer; - Strm.Avail_Out := Size; - end Set_Out; - - -------------- - -- Total_In -- - -------------- - - function Total_In (Strm : in Z_Stream) return ULong is - begin - return Strm.Total_In; - end Total_In; - - --------------- - -- Total_Out -- - --------------- - - function Total_Out (Strm : in Z_Stream) return ULong is - begin - return Strm.Total_Out; - end Total_Out; - -end ZLib.Thin; diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/ada/zlib-thin.ads b/src/beast/test/zlib/zlib-1.2.8/contrib/ada/zlib-thin.ads deleted file mode 100644 index d4407eb800d..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/ada/zlib-thin.ads +++ /dev/null @@ -1,450 +0,0 @@ ----------------------------------------------------------------- --- ZLib for Ada thick binding. -- --- -- --- Copyright (C) 2002-2003 Dmitriy Anisimkov -- --- -- --- Open source license information is in the zlib.ads file. -- ----------------------------------------------------------------- - --- $Id: zlib-thin.ads,v 1.11 2004/07/23 06:33:11 vagul Exp $ - -with Interfaces.C.Strings; - -with System; - -private package ZLib.Thin is - - -- From zconf.h - - MAX_MEM_LEVEL : constant := 9; -- zconf.h:105 - -- zconf.h:105 - MAX_WBITS : constant := 15; -- zconf.h:115 - -- 32K LZ77 window - -- zconf.h:115 - SEEK_SET : constant := 8#0000#; -- zconf.h:244 - -- Seek from beginning of file. - -- zconf.h:244 - SEEK_CUR : constant := 1; -- zconf.h:245 - -- Seek from current position. - -- zconf.h:245 - SEEK_END : constant := 2; -- zconf.h:246 - -- Set file pointer to EOF plus "offset" - -- zconf.h:246 - - type Byte is new Interfaces.C.unsigned_char; -- 8 bits - -- zconf.h:214 - type UInt is new Interfaces.C.unsigned; -- 16 bits or more - -- zconf.h:216 - type Int is new Interfaces.C.int; - - type ULong is new Interfaces.C.unsigned_long; -- 32 bits or more - -- zconf.h:217 - subtype Chars_Ptr is Interfaces.C.Strings.chars_ptr; - - type ULong_Access is access ULong; - type Int_Access is access Int; - - subtype Voidp is System.Address; -- zconf.h:232 - - subtype Byte_Access is Voidp; - - Nul : constant Voidp := System.Null_Address; - -- end from zconf - - Z_NO_FLUSH : constant := 8#0000#; -- zlib.h:125 - -- zlib.h:125 - Z_PARTIAL_FLUSH : constant := 1; -- zlib.h:126 - -- will be removed, use - -- Z_SYNC_FLUSH instead - -- zlib.h:126 - Z_SYNC_FLUSH : constant := 2; -- zlib.h:127 - -- zlib.h:127 - Z_FULL_FLUSH : constant := 3; -- zlib.h:128 - -- zlib.h:128 - Z_FINISH : constant := 4; -- zlib.h:129 - -- zlib.h:129 - Z_OK : constant := 8#0000#; -- zlib.h:132 - -- zlib.h:132 - Z_STREAM_END : constant := 1; -- zlib.h:133 - -- zlib.h:133 - Z_NEED_DICT : constant := 2; -- zlib.h:134 - -- zlib.h:134 - Z_ERRNO : constant := -1; -- zlib.h:135 - -- zlib.h:135 - Z_STREAM_ERROR : constant := -2; -- zlib.h:136 - -- zlib.h:136 - Z_DATA_ERROR : constant := -3; -- zlib.h:137 - -- zlib.h:137 - Z_MEM_ERROR : constant := -4; -- zlib.h:138 - -- zlib.h:138 - Z_BUF_ERROR : constant := -5; -- zlib.h:139 - -- zlib.h:139 - Z_VERSION_ERROR : constant := -6; -- zlib.h:140 - -- zlib.h:140 - Z_NO_COMPRESSION : constant := 8#0000#; -- zlib.h:145 - -- zlib.h:145 - Z_BEST_SPEED : constant := 1; -- zlib.h:146 - -- zlib.h:146 - Z_BEST_COMPRESSION : constant := 9; -- zlib.h:147 - -- zlib.h:147 - Z_DEFAULT_COMPRESSION : constant := -1; -- zlib.h:148 - -- zlib.h:148 - Z_FILTERED : constant := 1; -- zlib.h:151 - -- zlib.h:151 - Z_HUFFMAN_ONLY : constant := 2; -- zlib.h:152 - -- zlib.h:152 - Z_DEFAULT_STRATEGY : constant := 8#0000#; -- zlib.h:153 - -- zlib.h:153 - Z_BINARY : constant := 8#0000#; -- zlib.h:156 - -- zlib.h:156 - Z_ASCII : constant := 1; -- zlib.h:157 - -- zlib.h:157 - Z_UNKNOWN : constant := 2; -- zlib.h:158 - -- zlib.h:158 - Z_DEFLATED : constant := 8; -- zlib.h:161 - -- zlib.h:161 - Z_NULL : constant := 8#0000#; -- zlib.h:164 - -- for initializing zalloc, zfree, opaque - -- zlib.h:164 - type gzFile is new Voidp; -- zlib.h:646 - - type Z_Stream is private; - - type Z_Streamp is access all Z_Stream; -- zlib.h:89 - - type alloc_func is access function - (Opaque : Voidp; - Items : UInt; - Size : UInt) - return Voidp; -- zlib.h:63 - - type free_func is access procedure (opaque : Voidp; address : Voidp); - - function zlibVersion return Chars_Ptr; - - function Deflate (strm : Z_Streamp; flush : Int) return Int; - - function DeflateEnd (strm : Z_Streamp) return Int; - - function Inflate (strm : Z_Streamp; flush : Int) return Int; - - function InflateEnd (strm : Z_Streamp) return Int; - - function deflateSetDictionary - (strm : Z_Streamp; - dictionary : Byte_Access; - dictLength : UInt) - return Int; - - function deflateCopy (dest : Z_Streamp; source : Z_Streamp) return Int; - -- zlib.h:478 - - function deflateReset (strm : Z_Streamp) return Int; -- zlib.h:495 - - function deflateParams - (strm : Z_Streamp; - level : Int; - strategy : Int) - return Int; -- zlib.h:506 - - function inflateSetDictionary - (strm : Z_Streamp; - dictionary : Byte_Access; - dictLength : UInt) - return Int; -- zlib.h:548 - - function inflateSync (strm : Z_Streamp) return Int; -- zlib.h:565 - - function inflateReset (strm : Z_Streamp) return Int; -- zlib.h:580 - - function compress - (dest : Byte_Access; - destLen : ULong_Access; - source : Byte_Access; - sourceLen : ULong) - return Int; -- zlib.h:601 - - function compress2 - (dest : Byte_Access; - destLen : ULong_Access; - source : Byte_Access; - sourceLen : ULong; - level : Int) - return Int; -- zlib.h:615 - - function uncompress - (dest : Byte_Access; - destLen : ULong_Access; - source : Byte_Access; - sourceLen : ULong) - return Int; - - function gzopen (path : Chars_Ptr; mode : Chars_Ptr) return gzFile; - - function gzdopen (fd : Int; mode : Chars_Ptr) return gzFile; - - function gzsetparams - (file : gzFile; - level : Int; - strategy : Int) - return Int; - - function gzread - (file : gzFile; - buf : Voidp; - len : UInt) - return Int; - - function gzwrite - (file : in gzFile; - buf : in Voidp; - len : in UInt) - return Int; - - function gzprintf (file : in gzFile; format : in Chars_Ptr) return Int; - - function gzputs (file : in gzFile; s : in Chars_Ptr) return Int; - - function gzgets - (file : gzFile; - buf : Chars_Ptr; - len : Int) - return Chars_Ptr; - - function gzputc (file : gzFile; char : Int) return Int; - - function gzgetc (file : gzFile) return Int; - - function gzflush (file : gzFile; flush : Int) return Int; - - function gzseek - (file : gzFile; - offset : Int; - whence : Int) - return Int; - - function gzrewind (file : gzFile) return Int; - - function gztell (file : gzFile) return Int; - - function gzeof (file : gzFile) return Int; - - function gzclose (file : gzFile) return Int; - - function gzerror (file : gzFile; errnum : Int_Access) return Chars_Ptr; - - function adler32 - (adler : ULong; - buf : Byte_Access; - len : UInt) - return ULong; - - function crc32 - (crc : ULong; - buf : Byte_Access; - len : UInt) - return ULong; - - function deflateInit - (strm : Z_Streamp; - level : Int; - version : Chars_Ptr; - stream_size : Int) - return Int; - - function deflateInit2 - (strm : Z_Streamp; - level : Int; - method : Int; - windowBits : Int; - memLevel : Int; - strategy : Int; - version : Chars_Ptr; - stream_size : Int) - return Int; - - function Deflate_Init - (strm : Z_Streamp; - level : Int; - method : Int; - windowBits : Int; - memLevel : Int; - strategy : Int) - return Int; - pragma Inline (Deflate_Init); - - function inflateInit - (strm : Z_Streamp; - version : Chars_Ptr; - stream_size : Int) - return Int; - - function inflateInit2 - (strm : in Z_Streamp; - windowBits : in Int; - version : in Chars_Ptr; - stream_size : in Int) - return Int; - - function inflateBackInit - (strm : in Z_Streamp; - windowBits : in Int; - window : in Byte_Access; - version : in Chars_Ptr; - stream_size : in Int) - return Int; - -- Size of window have to be 2**windowBits. - - function Inflate_Init (strm : Z_Streamp; windowBits : Int) return Int; - pragma Inline (Inflate_Init); - - function zError (err : Int) return Chars_Ptr; - - function inflateSyncPoint (z : Z_Streamp) return Int; - - function get_crc_table return ULong_Access; - - -- Interface to the available fields of the z_stream structure. - -- The application must update next_in and avail_in when avail_in has - -- dropped to zero. It must update next_out and avail_out when avail_out - -- has dropped to zero. The application must initialize zalloc, zfree and - -- opaque before calling the init function. - - procedure Set_In - (Strm : in out Z_Stream; - Buffer : in Voidp; - Size : in UInt); - pragma Inline (Set_In); - - procedure Set_Out - (Strm : in out Z_Stream; - Buffer : in Voidp; - Size : in UInt); - pragma Inline (Set_Out); - - procedure Set_Mem_Func - (Strm : in out Z_Stream; - Opaque : in Voidp; - Alloc : in alloc_func; - Free : in free_func); - pragma Inline (Set_Mem_Func); - - function Last_Error_Message (Strm : in Z_Stream) return String; - pragma Inline (Last_Error_Message); - - function Avail_Out (Strm : in Z_Stream) return UInt; - pragma Inline (Avail_Out); - - function Avail_In (Strm : in Z_Stream) return UInt; - pragma Inline (Avail_In); - - function Total_In (Strm : in Z_Stream) return ULong; - pragma Inline (Total_In); - - function Total_Out (Strm : in Z_Stream) return ULong; - pragma Inline (Total_Out); - - function inflateCopy - (dest : in Z_Streamp; - Source : in Z_Streamp) - return Int; - - function compressBound (Source_Len : in ULong) return ULong; - - function deflateBound - (Strm : in Z_Streamp; - Source_Len : in ULong) - return ULong; - - function gzungetc (C : in Int; File : in gzFile) return Int; - - function zlibCompileFlags return ULong; - -private - - type Z_Stream is record -- zlib.h:68 - Next_In : Voidp := Nul; -- next input byte - Avail_In : UInt := 0; -- number of bytes available at next_in - Total_In : ULong := 0; -- total nb of input bytes read so far - Next_Out : Voidp := Nul; -- next output byte should be put there - Avail_Out : UInt := 0; -- remaining free space at next_out - Total_Out : ULong := 0; -- total nb of bytes output so far - msg : Chars_Ptr; -- last error message, NULL if no error - state : Voidp; -- not visible by applications - zalloc : alloc_func := null; -- used to allocate the internal state - zfree : free_func := null; -- used to free the internal state - opaque : Voidp; -- private data object passed to - -- zalloc and zfree - data_type : Int; -- best guess about the data type: - -- ascii or binary - adler : ULong; -- adler32 value of the uncompressed - -- data - reserved : ULong; -- reserved for future use - end record; - - pragma Convention (C, Z_Stream); - - pragma Import (C, zlibVersion, "zlibVersion"); - pragma Import (C, Deflate, "deflate"); - pragma Import (C, DeflateEnd, "deflateEnd"); - pragma Import (C, Inflate, "inflate"); - pragma Import (C, InflateEnd, "inflateEnd"); - pragma Import (C, deflateSetDictionary, "deflateSetDictionary"); - pragma Import (C, deflateCopy, "deflateCopy"); - pragma Import (C, deflateReset, "deflateReset"); - pragma Import (C, deflateParams, "deflateParams"); - pragma Import (C, inflateSetDictionary, "inflateSetDictionary"); - pragma Import (C, inflateSync, "inflateSync"); - pragma Import (C, inflateReset, "inflateReset"); - pragma Import (C, compress, "compress"); - pragma Import (C, compress2, "compress2"); - pragma Import (C, uncompress, "uncompress"); - pragma Import (C, gzopen, "gzopen"); - pragma Import (C, gzdopen, "gzdopen"); - pragma Import (C, gzsetparams, "gzsetparams"); - pragma Import (C, gzread, "gzread"); - pragma Import (C, gzwrite, "gzwrite"); - pragma Import (C, gzprintf, "gzprintf"); - pragma Import (C, gzputs, "gzputs"); - pragma Import (C, gzgets, "gzgets"); - pragma Import (C, gzputc, "gzputc"); - pragma Import (C, gzgetc, "gzgetc"); - pragma Import (C, gzflush, "gzflush"); - pragma Import (C, gzseek, "gzseek"); - pragma Import (C, gzrewind, "gzrewind"); - pragma Import (C, gztell, "gztell"); - pragma Import (C, gzeof, "gzeof"); - pragma Import (C, gzclose, "gzclose"); - pragma Import (C, gzerror, "gzerror"); - pragma Import (C, adler32, "adler32"); - pragma Import (C, crc32, "crc32"); - pragma Import (C, deflateInit, "deflateInit_"); - pragma Import (C, inflateInit, "inflateInit_"); - pragma Import (C, deflateInit2, "deflateInit2_"); - pragma Import (C, inflateInit2, "inflateInit2_"); - pragma Import (C, zError, "zError"); - pragma Import (C, inflateSyncPoint, "inflateSyncPoint"); - pragma Import (C, get_crc_table, "get_crc_table"); - - -- since zlib 1.2.0: - - pragma Import (C, inflateCopy, "inflateCopy"); - pragma Import (C, compressBound, "compressBound"); - pragma Import (C, deflateBound, "deflateBound"); - pragma Import (C, gzungetc, "gzungetc"); - pragma Import (C, zlibCompileFlags, "zlibCompileFlags"); - - pragma Import (C, inflateBackInit, "inflateBackInit_"); - - -- I stopped binding the inflateBack routines, becouse realize that - -- it does not support zlib and gzip headers for now, and have no - -- symmetric deflateBack routines. - -- ZLib-Ada is symmetric regarding deflate/inflate data transformation - -- and has a similar generic callback interface for the - -- deflate/inflate transformation based on the regular Deflate/Inflate - -- routines. - - -- pragma Import (C, inflateBack, "inflateBack"); - -- pragma Import (C, inflateBackEnd, "inflateBackEnd"); - -end ZLib.Thin; diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/ada/zlib.adb b/src/beast/test/zlib/zlib-1.2.8/contrib/ada/zlib.adb deleted file mode 100644 index 8b6fd686ac7..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/ada/zlib.adb +++ /dev/null @@ -1,701 +0,0 @@ ----------------------------------------------------------------- --- ZLib for Ada thick binding. -- --- -- --- Copyright (C) 2002-2004 Dmitriy Anisimkov -- --- -- --- Open source license information is in the zlib.ads file. -- ----------------------------------------------------------------- - --- $Id: zlib.adb,v 1.31 2004/09/06 06:53:19 vagul Exp $ - -with Ada.Exceptions; -with Ada.Unchecked_Conversion; -with Ada.Unchecked_Deallocation; - -with Interfaces.C.Strings; - -with ZLib.Thin; - -package body ZLib is - - use type Thin.Int; - - type Z_Stream is new Thin.Z_Stream; - - type Return_Code_Enum is - (OK, - STREAM_END, - NEED_DICT, - ERRNO, - STREAM_ERROR, - DATA_ERROR, - MEM_ERROR, - BUF_ERROR, - VERSION_ERROR); - - type Flate_Step_Function is access - function (Strm : in Thin.Z_Streamp; Flush : in Thin.Int) return Thin.Int; - pragma Convention (C, Flate_Step_Function); - - type Flate_End_Function is access - function (Ctrm : in Thin.Z_Streamp) return Thin.Int; - pragma Convention (C, Flate_End_Function); - - type Flate_Type is record - Step : Flate_Step_Function; - Done : Flate_End_Function; - end record; - - subtype Footer_Array is Stream_Element_Array (1 .. 8); - - Simple_GZip_Header : constant Stream_Element_Array (1 .. 10) - := (16#1f#, 16#8b#, -- Magic header - 16#08#, -- Z_DEFLATED - 16#00#, -- Flags - 16#00#, 16#00#, 16#00#, 16#00#, -- Time - 16#00#, -- XFlags - 16#03# -- OS code - ); - -- The simplest gzip header is not for informational, but just for - -- gzip format compatibility. - -- Note that some code below is using assumption - -- Simple_GZip_Header'Last > Footer_Array'Last, so do not make - -- Simple_GZip_Header'Last <= Footer_Array'Last. - - Return_Code : constant array (Thin.Int range <>) of Return_Code_Enum - := (0 => OK, - 1 => STREAM_END, - 2 => NEED_DICT, - -1 => ERRNO, - -2 => STREAM_ERROR, - -3 => DATA_ERROR, - -4 => MEM_ERROR, - -5 => BUF_ERROR, - -6 => VERSION_ERROR); - - Flate : constant array (Boolean) of Flate_Type - := (True => (Step => Thin.Deflate'Access, - Done => Thin.DeflateEnd'Access), - False => (Step => Thin.Inflate'Access, - Done => Thin.InflateEnd'Access)); - - Flush_Finish : constant array (Boolean) of Flush_Mode - := (True => Finish, False => No_Flush); - - procedure Raise_Error (Stream : in Z_Stream); - pragma Inline (Raise_Error); - - procedure Raise_Error (Message : in String); - pragma Inline (Raise_Error); - - procedure Check_Error (Stream : in Z_Stream; Code : in Thin.Int); - - procedure Free is new Ada.Unchecked_Deallocation - (Z_Stream, Z_Stream_Access); - - function To_Thin_Access is new Ada.Unchecked_Conversion - (Z_Stream_Access, Thin.Z_Streamp); - - procedure Translate_GZip - (Filter : in out Filter_Type; - In_Data : in Ada.Streams.Stream_Element_Array; - In_Last : out Ada.Streams.Stream_Element_Offset; - Out_Data : out Ada.Streams.Stream_Element_Array; - Out_Last : out Ada.Streams.Stream_Element_Offset; - Flush : in Flush_Mode); - -- Separate translate routine for make gzip header. - - procedure Translate_Auto - (Filter : in out Filter_Type; - In_Data : in Ada.Streams.Stream_Element_Array; - In_Last : out Ada.Streams.Stream_Element_Offset; - Out_Data : out Ada.Streams.Stream_Element_Array; - Out_Last : out Ada.Streams.Stream_Element_Offset; - Flush : in Flush_Mode); - -- translate routine without additional headers. - - ----------------- - -- Check_Error -- - ----------------- - - procedure Check_Error (Stream : in Z_Stream; Code : in Thin.Int) is - use type Thin.Int; - begin - if Code /= Thin.Z_OK then - Raise_Error - (Return_Code_Enum'Image (Return_Code (Code)) - & ": " & Last_Error_Message (Stream)); - end if; - end Check_Error; - - ----------- - -- Close -- - ----------- - - procedure Close - (Filter : in out Filter_Type; - Ignore_Error : in Boolean := False) - is - Code : Thin.Int; - begin - if not Ignore_Error and then not Is_Open (Filter) then - raise Status_Error; - end if; - - Code := Flate (Filter.Compression).Done (To_Thin_Access (Filter.Strm)); - - if Ignore_Error or else Code = Thin.Z_OK then - Free (Filter.Strm); - else - declare - Error_Message : constant String - := Last_Error_Message (Filter.Strm.all); - begin - Free (Filter.Strm); - Ada.Exceptions.Raise_Exception - (ZLib_Error'Identity, - Return_Code_Enum'Image (Return_Code (Code)) - & ": " & Error_Message); - end; - end if; - end Close; - - ----------- - -- CRC32 -- - ----------- - - function CRC32 - (CRC : in Unsigned_32; - Data : in Ada.Streams.Stream_Element_Array) - return Unsigned_32 - is - use Thin; - begin - return Unsigned_32 (crc32 (ULong (CRC), - Data'Address, - Data'Length)); - end CRC32; - - procedure CRC32 - (CRC : in out Unsigned_32; - Data : in Ada.Streams.Stream_Element_Array) is - begin - CRC := CRC32 (CRC, Data); - end CRC32; - - ------------------ - -- Deflate_Init -- - ------------------ - - procedure Deflate_Init - (Filter : in out Filter_Type; - Level : in Compression_Level := Default_Compression; - Strategy : in Strategy_Type := Default_Strategy; - Method : in Compression_Method := Deflated; - Window_Bits : in Window_Bits_Type := Default_Window_Bits; - Memory_Level : in Memory_Level_Type := Default_Memory_Level; - Header : in Header_Type := Default) - is - use type Thin.Int; - Win_Bits : Thin.Int := Thin.Int (Window_Bits); - begin - if Is_Open (Filter) then - raise Status_Error; - end if; - - -- We allow ZLib to make header only in case of default header type. - -- Otherwise we would either do header by ourselfs, or do not do - -- header at all. - - if Header = None or else Header = GZip then - Win_Bits := -Win_Bits; - end if; - - -- For the GZip CRC calculation and make headers. - - if Header = GZip then - Filter.CRC := 0; - Filter.Offset := Simple_GZip_Header'First; - else - Filter.Offset := Simple_GZip_Header'Last + 1; - end if; - - Filter.Strm := new Z_Stream; - Filter.Compression := True; - Filter.Stream_End := False; - Filter.Header := Header; - - if Thin.Deflate_Init - (To_Thin_Access (Filter.Strm), - Level => Thin.Int (Level), - method => Thin.Int (Method), - windowBits => Win_Bits, - memLevel => Thin.Int (Memory_Level), - strategy => Thin.Int (Strategy)) /= Thin.Z_OK - then - Raise_Error (Filter.Strm.all); - end if; - end Deflate_Init; - - ----------- - -- Flush -- - ----------- - - procedure Flush - (Filter : in out Filter_Type; - Out_Data : out Ada.Streams.Stream_Element_Array; - Out_Last : out Ada.Streams.Stream_Element_Offset; - Flush : in Flush_Mode) - is - No_Data : Stream_Element_Array := (1 .. 0 => 0); - Last : Stream_Element_Offset; - begin - Translate (Filter, No_Data, Last, Out_Data, Out_Last, Flush); - end Flush; - - ----------------------- - -- Generic_Translate -- - ----------------------- - - procedure Generic_Translate - (Filter : in out ZLib.Filter_Type; - In_Buffer_Size : in Integer := Default_Buffer_Size; - Out_Buffer_Size : in Integer := Default_Buffer_Size) - is - In_Buffer : Stream_Element_Array - (1 .. Stream_Element_Offset (In_Buffer_Size)); - Out_Buffer : Stream_Element_Array - (1 .. Stream_Element_Offset (Out_Buffer_Size)); - Last : Stream_Element_Offset; - In_Last : Stream_Element_Offset; - In_First : Stream_Element_Offset; - Out_Last : Stream_Element_Offset; - begin - Main : loop - Data_In (In_Buffer, Last); - - In_First := In_Buffer'First; - - loop - Translate - (Filter => Filter, - In_Data => In_Buffer (In_First .. Last), - In_Last => In_Last, - Out_Data => Out_Buffer, - Out_Last => Out_Last, - Flush => Flush_Finish (Last < In_Buffer'First)); - - if Out_Buffer'First <= Out_Last then - Data_Out (Out_Buffer (Out_Buffer'First .. Out_Last)); - end if; - - exit Main when Stream_End (Filter); - - -- The end of in buffer. - - exit when In_Last = Last; - - In_First := In_Last + 1; - end loop; - end loop Main; - - end Generic_Translate; - - ------------------ - -- Inflate_Init -- - ------------------ - - procedure Inflate_Init - (Filter : in out Filter_Type; - Window_Bits : in Window_Bits_Type := Default_Window_Bits; - Header : in Header_Type := Default) - is - use type Thin.Int; - Win_Bits : Thin.Int := Thin.Int (Window_Bits); - - procedure Check_Version; - -- Check the latest header types compatibility. - - procedure Check_Version is - begin - if Version <= "1.1.4" then - Raise_Error - ("Inflate header type " & Header_Type'Image (Header) - & " incompatible with ZLib version " & Version); - end if; - end Check_Version; - - begin - if Is_Open (Filter) then - raise Status_Error; - end if; - - case Header is - when None => - Check_Version; - - -- Inflate data without headers determined - -- by negative Win_Bits. - - Win_Bits := -Win_Bits; - when GZip => - Check_Version; - - -- Inflate gzip data defined by flag 16. - - Win_Bits := Win_Bits + 16; - when Auto => - Check_Version; - - -- Inflate with automatic detection - -- of gzip or native header defined by flag 32. - - Win_Bits := Win_Bits + 32; - when Default => null; - end case; - - Filter.Strm := new Z_Stream; - Filter.Compression := False; - Filter.Stream_End := False; - Filter.Header := Header; - - if Thin.Inflate_Init - (To_Thin_Access (Filter.Strm), Win_Bits) /= Thin.Z_OK - then - Raise_Error (Filter.Strm.all); - end if; - end Inflate_Init; - - ------------- - -- Is_Open -- - ------------- - - function Is_Open (Filter : in Filter_Type) return Boolean is - begin - return Filter.Strm /= null; - end Is_Open; - - ----------------- - -- Raise_Error -- - ----------------- - - procedure Raise_Error (Message : in String) is - begin - Ada.Exceptions.Raise_Exception (ZLib_Error'Identity, Message); - end Raise_Error; - - procedure Raise_Error (Stream : in Z_Stream) is - begin - Raise_Error (Last_Error_Message (Stream)); - end Raise_Error; - - ---------- - -- Read -- - ---------- - - procedure Read - (Filter : in out Filter_Type; - Item : out Ada.Streams.Stream_Element_Array; - Last : out Ada.Streams.Stream_Element_Offset; - Flush : in Flush_Mode := No_Flush) - is - In_Last : Stream_Element_Offset; - Item_First : Ada.Streams.Stream_Element_Offset := Item'First; - V_Flush : Flush_Mode := Flush; - - begin - pragma Assert (Rest_First in Buffer'First .. Buffer'Last + 1); - pragma Assert (Rest_Last in Buffer'First - 1 .. Buffer'Last); - - loop - if Rest_Last = Buffer'First - 1 then - V_Flush := Finish; - - elsif Rest_First > Rest_Last then - Read (Buffer, Rest_Last); - Rest_First := Buffer'First; - - if Rest_Last < Buffer'First then - V_Flush := Finish; - end if; - end if; - - Translate - (Filter => Filter, - In_Data => Buffer (Rest_First .. Rest_Last), - In_Last => In_Last, - Out_Data => Item (Item_First .. Item'Last), - Out_Last => Last, - Flush => V_Flush); - - Rest_First := In_Last + 1; - - exit when Stream_End (Filter) - or else Last = Item'Last - or else (Last >= Item'First and then Allow_Read_Some); - - Item_First := Last + 1; - end loop; - end Read; - - ---------------- - -- Stream_End -- - ---------------- - - function Stream_End (Filter : in Filter_Type) return Boolean is - begin - if Filter.Header = GZip and Filter.Compression then - return Filter.Stream_End - and then Filter.Offset = Footer_Array'Last + 1; - else - return Filter.Stream_End; - end if; - end Stream_End; - - -------------- - -- Total_In -- - -------------- - - function Total_In (Filter : in Filter_Type) return Count is - begin - return Count (Thin.Total_In (To_Thin_Access (Filter.Strm).all)); - end Total_In; - - --------------- - -- Total_Out -- - --------------- - - function Total_Out (Filter : in Filter_Type) return Count is - begin - return Count (Thin.Total_Out (To_Thin_Access (Filter.Strm).all)); - end Total_Out; - - --------------- - -- Translate -- - --------------- - - procedure Translate - (Filter : in out Filter_Type; - In_Data : in Ada.Streams.Stream_Element_Array; - In_Last : out Ada.Streams.Stream_Element_Offset; - Out_Data : out Ada.Streams.Stream_Element_Array; - Out_Last : out Ada.Streams.Stream_Element_Offset; - Flush : in Flush_Mode) is - begin - if Filter.Header = GZip and then Filter.Compression then - Translate_GZip - (Filter => Filter, - In_Data => In_Data, - In_Last => In_Last, - Out_Data => Out_Data, - Out_Last => Out_Last, - Flush => Flush); - else - Translate_Auto - (Filter => Filter, - In_Data => In_Data, - In_Last => In_Last, - Out_Data => Out_Data, - Out_Last => Out_Last, - Flush => Flush); - end if; - end Translate; - - -------------------- - -- Translate_Auto -- - -------------------- - - procedure Translate_Auto - (Filter : in out Filter_Type; - In_Data : in Ada.Streams.Stream_Element_Array; - In_Last : out Ada.Streams.Stream_Element_Offset; - Out_Data : out Ada.Streams.Stream_Element_Array; - Out_Last : out Ada.Streams.Stream_Element_Offset; - Flush : in Flush_Mode) - is - use type Thin.Int; - Code : Thin.Int; - - begin - if not Is_Open (Filter) then - raise Status_Error; - end if; - - if Out_Data'Length = 0 and then In_Data'Length = 0 then - raise Constraint_Error; - end if; - - Set_Out (Filter.Strm.all, Out_Data'Address, Out_Data'Length); - Set_In (Filter.Strm.all, In_Data'Address, In_Data'Length); - - Code := Flate (Filter.Compression).Step - (To_Thin_Access (Filter.Strm), - Thin.Int (Flush)); - - if Code = Thin.Z_STREAM_END then - Filter.Stream_End := True; - else - Check_Error (Filter.Strm.all, Code); - end if; - - In_Last := In_Data'Last - - Stream_Element_Offset (Avail_In (Filter.Strm.all)); - Out_Last := Out_Data'Last - - Stream_Element_Offset (Avail_Out (Filter.Strm.all)); - end Translate_Auto; - - -------------------- - -- Translate_GZip -- - -------------------- - - procedure Translate_GZip - (Filter : in out Filter_Type; - In_Data : in Ada.Streams.Stream_Element_Array; - In_Last : out Ada.Streams.Stream_Element_Offset; - Out_Data : out Ada.Streams.Stream_Element_Array; - Out_Last : out Ada.Streams.Stream_Element_Offset; - Flush : in Flush_Mode) - is - Out_First : Stream_Element_Offset; - - procedure Add_Data (Data : in Stream_Element_Array); - -- Add data to stream from the Filter.Offset till necessary, - -- used for add gzip headr/footer. - - procedure Put_32 - (Item : in out Stream_Element_Array; - Data : in Unsigned_32); - pragma Inline (Put_32); - - -------------- - -- Add_Data -- - -------------- - - procedure Add_Data (Data : in Stream_Element_Array) is - Data_First : Stream_Element_Offset renames Filter.Offset; - Data_Last : Stream_Element_Offset; - Data_Len : Stream_Element_Offset; -- -1 - Out_Len : Stream_Element_Offset; -- -1 - begin - Out_First := Out_Last + 1; - - if Data_First > Data'Last then - return; - end if; - - Data_Len := Data'Last - Data_First; - Out_Len := Out_Data'Last - Out_First; - - if Data_Len <= Out_Len then - Out_Last := Out_First + Data_Len; - Data_Last := Data'Last; - else - Out_Last := Out_Data'Last; - Data_Last := Data_First + Out_Len; - end if; - - Out_Data (Out_First .. Out_Last) := Data (Data_First .. Data_Last); - - Data_First := Data_Last + 1; - Out_First := Out_Last + 1; - end Add_Data; - - ------------ - -- Put_32 -- - ------------ - - procedure Put_32 - (Item : in out Stream_Element_Array; - Data : in Unsigned_32) - is - D : Unsigned_32 := Data; - begin - for J in Item'First .. Item'First + 3 loop - Item (J) := Stream_Element (D and 16#FF#); - D := Shift_Right (D, 8); - end loop; - end Put_32; - - begin - Out_Last := Out_Data'First - 1; - - if not Filter.Stream_End then - Add_Data (Simple_GZip_Header); - - Translate_Auto - (Filter => Filter, - In_Data => In_Data, - In_Last => In_Last, - Out_Data => Out_Data (Out_First .. Out_Data'Last), - Out_Last => Out_Last, - Flush => Flush); - - CRC32 (Filter.CRC, In_Data (In_Data'First .. In_Last)); - end if; - - if Filter.Stream_End and then Out_Last <= Out_Data'Last then - -- This detection method would work only when - -- Simple_GZip_Header'Last > Footer_Array'Last - - if Filter.Offset = Simple_GZip_Header'Last + 1 then - Filter.Offset := Footer_Array'First; - end if; - - declare - Footer : Footer_Array; - begin - Put_32 (Footer, Filter.CRC); - Put_32 (Footer (Footer'First + 4 .. Footer'Last), - Unsigned_32 (Total_In (Filter))); - Add_Data (Footer); - end; - end if; - end Translate_GZip; - - ------------- - -- Version -- - ------------- - - function Version return String is - begin - return Interfaces.C.Strings.Value (Thin.zlibVersion); - end Version; - - ----------- - -- Write -- - ----------- - - procedure Write - (Filter : in out Filter_Type; - Item : in Ada.Streams.Stream_Element_Array; - Flush : in Flush_Mode := No_Flush) - is - Buffer : Stream_Element_Array (1 .. Buffer_Size); - In_Last : Stream_Element_Offset; - Out_Last : Stream_Element_Offset; - In_First : Stream_Element_Offset := Item'First; - begin - if Item'Length = 0 and Flush = No_Flush then - return; - end if; - - loop - Translate - (Filter => Filter, - In_Data => Item (In_First .. Item'Last), - In_Last => In_Last, - Out_Data => Buffer, - Out_Last => Out_Last, - Flush => Flush); - - if Out_Last >= Buffer'First then - Write (Buffer (1 .. Out_Last)); - end if; - - exit when In_Last = Item'Last or Stream_End (Filter); - - In_First := In_Last + 1; - end loop; - end Write; - -end ZLib; diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/ada/zlib.ads b/src/beast/test/zlib/zlib-1.2.8/contrib/ada/zlib.ads deleted file mode 100644 index 79ffc4095cf..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/ada/zlib.ads +++ /dev/null @@ -1,328 +0,0 @@ ------------------------------------------------------------------------------- --- ZLib for Ada thick binding. -- --- -- --- Copyright (C) 2002-2004 Dmitriy Anisimkov -- --- -- --- This library is free software; you can redistribute it and/or modify -- --- it under the terms of the GNU General Public License as published by -- --- the Free Software Foundation; either version 2 of the License, or (at -- --- your option) any later version. -- --- -- --- This library is distributed in the hope that it will be useful, but -- --- WITHOUT ANY WARRANTY; without even the implied warranty of -- --- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -- --- General Public License for more details. -- --- -- --- You should have received a copy of the GNU General Public License -- --- along with this library; if not, write to the Free Software Foundation, -- --- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -- --- -- --- As a special exception, if other files instantiate generics from this -- --- unit, or you link this unit with other files to produce an executable, -- --- this unit does not by itself cause the resulting executable to be -- --- covered by the GNU General Public License. This exception does not -- --- however invalidate any other reasons why the executable file might be -- --- covered by the GNU Public License. -- ------------------------------------------------------------------------------- - --- $Id: zlib.ads,v 1.26 2004/09/06 06:53:19 vagul Exp $ - -with Ada.Streams; - -with Interfaces; - -package ZLib is - - ZLib_Error : exception; - Status_Error : exception; - - type Compression_Level is new Integer range -1 .. 9; - - type Flush_Mode is private; - - type Compression_Method is private; - - type Window_Bits_Type is new Integer range 8 .. 15; - - type Memory_Level_Type is new Integer range 1 .. 9; - - type Unsigned_32 is new Interfaces.Unsigned_32; - - type Strategy_Type is private; - - type Header_Type is (None, Auto, Default, GZip); - -- Header type usage have a some limitation for inflate. - -- See comment for Inflate_Init. - - subtype Count is Ada.Streams.Stream_Element_Count; - - Default_Memory_Level : constant Memory_Level_Type := 8; - Default_Window_Bits : constant Window_Bits_Type := 15; - - ---------------------------------- - -- Compression method constants -- - ---------------------------------- - - Deflated : constant Compression_Method; - -- Only one method allowed in this ZLib version - - --------------------------------- - -- Compression level constants -- - --------------------------------- - - No_Compression : constant Compression_Level := 0; - Best_Speed : constant Compression_Level := 1; - Best_Compression : constant Compression_Level := 9; - Default_Compression : constant Compression_Level := -1; - - -------------------------- - -- Flush mode constants -- - -------------------------- - - No_Flush : constant Flush_Mode; - -- Regular way for compression, no flush - - Partial_Flush : constant Flush_Mode; - -- Will be removed, use Z_SYNC_FLUSH instead - - Sync_Flush : constant Flush_Mode; - -- All pending output is flushed to the output buffer and the output - -- is aligned on a byte boundary, so that the decompressor can get all - -- input data available so far. (In particular avail_in is zero after the - -- call if enough output space has been provided before the call.) - -- Flushing may degrade compression for some compression algorithms and so - -- it should be used only when necessary. - - Block_Flush : constant Flush_Mode; - -- Z_BLOCK requests that inflate() stop - -- if and when it get to the next deflate block boundary. When decoding the - -- zlib or gzip format, this will cause inflate() to return immediately - -- after the header and before the first block. When doing a raw inflate, - -- inflate() will go ahead and process the first block, and will return - -- when it gets to the end of that block, or when it runs out of data. - - Full_Flush : constant Flush_Mode; - -- All output is flushed as with SYNC_FLUSH, and the compression state - -- is reset so that decompression can restart from this point if previous - -- compressed data has been damaged or if random access is desired. Using - -- Full_Flush too often can seriously degrade the compression. - - Finish : constant Flush_Mode; - -- Just for tell the compressor that input data is complete. - - ------------------------------------ - -- Compression strategy constants -- - ------------------------------------ - - -- RLE stategy could be used only in version 1.2.0 and later. - - Filtered : constant Strategy_Type; - Huffman_Only : constant Strategy_Type; - RLE : constant Strategy_Type; - Default_Strategy : constant Strategy_Type; - - Default_Buffer_Size : constant := 4096; - - type Filter_Type is tagged limited private; - -- The filter is for compression and for decompression. - -- The usage of the type is depend of its initialization. - - function Version return String; - pragma Inline (Version); - -- Return string representation of the ZLib version. - - procedure Deflate_Init - (Filter : in out Filter_Type; - Level : in Compression_Level := Default_Compression; - Strategy : in Strategy_Type := Default_Strategy; - Method : in Compression_Method := Deflated; - Window_Bits : in Window_Bits_Type := Default_Window_Bits; - Memory_Level : in Memory_Level_Type := Default_Memory_Level; - Header : in Header_Type := Default); - -- Compressor initialization. - -- When Header parameter is Auto or Default, then default zlib header - -- would be provided for compressed data. - -- When Header is GZip, then gzip header would be set instead of - -- default header. - -- When Header is None, no header would be set for compressed data. - - procedure Inflate_Init - (Filter : in out Filter_Type; - Window_Bits : in Window_Bits_Type := Default_Window_Bits; - Header : in Header_Type := Default); - -- Decompressor initialization. - -- Default header type mean that ZLib default header is expecting in the - -- input compressed stream. - -- Header type None mean that no header is expecting in the input stream. - -- GZip header type mean that GZip header is expecting in the - -- input compressed stream. - -- Auto header type mean that header type (GZip or Native) would be - -- detected automatically in the input stream. - -- Note that header types parameter values None, GZip and Auto are - -- supported for inflate routine only in ZLib versions 1.2.0.2 and later. - -- Deflate_Init is supporting all header types. - - function Is_Open (Filter : in Filter_Type) return Boolean; - pragma Inline (Is_Open); - -- Is the filter opened for compression or decompression. - - procedure Close - (Filter : in out Filter_Type; - Ignore_Error : in Boolean := False); - -- Closing the compression or decompressor. - -- If stream is closing before the complete and Ignore_Error is False, - -- The exception would be raised. - - generic - with procedure Data_In - (Item : out Ada.Streams.Stream_Element_Array; - Last : out Ada.Streams.Stream_Element_Offset); - with procedure Data_Out - (Item : in Ada.Streams.Stream_Element_Array); - procedure Generic_Translate - (Filter : in out Filter_Type; - In_Buffer_Size : in Integer := Default_Buffer_Size; - Out_Buffer_Size : in Integer := Default_Buffer_Size); - -- Compress/decompress data fetch from Data_In routine and pass the result - -- to the Data_Out routine. User should provide Data_In and Data_Out - -- for compression/decompression data flow. - -- Compression or decompression depend on Filter initialization. - - function Total_In (Filter : in Filter_Type) return Count; - pragma Inline (Total_In); - -- Returns total number of input bytes read so far - - function Total_Out (Filter : in Filter_Type) return Count; - pragma Inline (Total_Out); - -- Returns total number of bytes output so far - - function CRC32 - (CRC : in Unsigned_32; - Data : in Ada.Streams.Stream_Element_Array) - return Unsigned_32; - pragma Inline (CRC32); - -- Compute CRC32, it could be necessary for make gzip format - - procedure CRC32 - (CRC : in out Unsigned_32; - Data : in Ada.Streams.Stream_Element_Array); - pragma Inline (CRC32); - -- Compute CRC32, it could be necessary for make gzip format - - ------------------------------------------------- - -- Below is more complex low level routines. -- - ------------------------------------------------- - - procedure Translate - (Filter : in out Filter_Type; - In_Data : in Ada.Streams.Stream_Element_Array; - In_Last : out Ada.Streams.Stream_Element_Offset; - Out_Data : out Ada.Streams.Stream_Element_Array; - Out_Last : out Ada.Streams.Stream_Element_Offset; - Flush : in Flush_Mode); - -- Compress/decompress the In_Data buffer and place the result into - -- Out_Data. In_Last is the index of last element from In_Data accepted by - -- the Filter. Out_Last is the last element of the received data from - -- Filter. To tell the filter that incoming data are complete put the - -- Flush parameter to Finish. - - function Stream_End (Filter : in Filter_Type) return Boolean; - pragma Inline (Stream_End); - -- Return the true when the stream is complete. - - procedure Flush - (Filter : in out Filter_Type; - Out_Data : out Ada.Streams.Stream_Element_Array; - Out_Last : out Ada.Streams.Stream_Element_Offset; - Flush : in Flush_Mode); - pragma Inline (Flush); - -- Flushing the data from the compressor. - - generic - with procedure Write - (Item : in Ada.Streams.Stream_Element_Array); - -- User should provide this routine for accept - -- compressed/decompressed data. - - Buffer_Size : in Ada.Streams.Stream_Element_Offset - := Default_Buffer_Size; - -- Buffer size for Write user routine. - - procedure Write - (Filter : in out Filter_Type; - Item : in Ada.Streams.Stream_Element_Array; - Flush : in Flush_Mode := No_Flush); - -- Compress/Decompress data from Item to the generic parameter procedure - -- Write. Output buffer size could be set in Buffer_Size generic parameter. - - generic - with procedure Read - (Item : out Ada.Streams.Stream_Element_Array; - Last : out Ada.Streams.Stream_Element_Offset); - -- User should provide data for compression/decompression - -- thru this routine. - - Buffer : in out Ada.Streams.Stream_Element_Array; - -- Buffer for keep remaining data from the previous - -- back read. - - Rest_First, Rest_Last : in out Ada.Streams.Stream_Element_Offset; - -- Rest_First have to be initialized to Buffer'Last + 1 - -- Rest_Last have to be initialized to Buffer'Last - -- before usage. - - Allow_Read_Some : in Boolean := False; - -- Is it allowed to return Last < Item'Last before end of data. - - procedure Read - (Filter : in out Filter_Type; - Item : out Ada.Streams.Stream_Element_Array; - Last : out Ada.Streams.Stream_Element_Offset; - Flush : in Flush_Mode := No_Flush); - -- Compress/Decompress data from generic parameter procedure Read to the - -- Item. User should provide Buffer and initialized Rest_First, Rest_Last - -- indicators. If Allow_Read_Some is True, Read routines could return - -- Last < Item'Last only at end of stream. - -private - - use Ada.Streams; - - pragma Assert (Ada.Streams.Stream_Element'Size = 8); - pragma Assert (Ada.Streams.Stream_Element'Modulus = 2**8); - - type Flush_Mode is new Integer range 0 .. 5; - - type Compression_Method is new Integer range 8 .. 8; - - type Strategy_Type is new Integer range 0 .. 3; - - No_Flush : constant Flush_Mode := 0; - Partial_Flush : constant Flush_Mode := 1; - Sync_Flush : constant Flush_Mode := 2; - Full_Flush : constant Flush_Mode := 3; - Finish : constant Flush_Mode := 4; - Block_Flush : constant Flush_Mode := 5; - - Filtered : constant Strategy_Type := 1; - Huffman_Only : constant Strategy_Type := 2; - RLE : constant Strategy_Type := 3; - Default_Strategy : constant Strategy_Type := 0; - - Deflated : constant Compression_Method := 8; - - type Z_Stream; - - type Z_Stream_Access is access all Z_Stream; - - type Filter_Type is tagged limited record - Strm : Z_Stream_Access; - Compression : Boolean; - Stream_End : Boolean; - Header : Header_Type; - CRC : Unsigned_32; - Offset : Stream_Element_Offset; - -- Offset for gzip header/footer output. - end record; - -end ZLib; diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/ada/zlib.gpr b/src/beast/test/zlib/zlib-1.2.8/contrib/ada/zlib.gpr deleted file mode 100644 index 296b22aa966..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/ada/zlib.gpr +++ /dev/null @@ -1,20 +0,0 @@ -project Zlib is - - for Languages use ("Ada"); - for Source_Dirs use ("."); - for Object_Dir use "."; - for Main use ("test.adb", "mtest.adb", "read.adb", "buffer_demo"); - - package Compiler is - for Default_Switches ("ada") use ("-gnatwcfilopru", "-gnatVcdfimorst", "-gnatyabcefhiklmnoprst"); - end Compiler; - - package Linker is - for Default_Switches ("ada") use ("-lz"); - end Linker; - - package Builder is - for Default_Switches ("ada") use ("-s", "-gnatQ"); - end Builder; - -end Zlib; diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/amd64/amd64-match.S b/src/beast/test/zlib/zlib-1.2.8/contrib/amd64/amd64-match.S deleted file mode 100644 index 81d4a1c9494..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/amd64/amd64-match.S +++ /dev/null @@ -1,452 +0,0 @@ -/* - * match.S -- optimized version of longest_match() - * based on the similar work by Gilles Vollant, and Brian Raiter, written 1998 - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the BSD License. Use by owners of Che Guevarra - * parafernalia is prohibited, where possible, and highly discouraged - * elsewhere. - */ - -#ifndef NO_UNDERLINE -# define match_init _match_init -# define longest_match _longest_match -#endif - -#define scanend ebx -#define scanendw bx -#define chainlenwmask edx /* high word: current chain len low word: s->wmask */ -#define curmatch rsi -#define curmatchd esi -#define windowbestlen r8 -#define scanalign r9 -#define scanalignd r9d -#define window r10 -#define bestlen r11 -#define bestlend r11d -#define scanstart r12d -#define scanstartw r12w -#define scan r13 -#define nicematch r14d -#define limit r15 -#define limitd r15d -#define prev rcx - -/* - * The 258 is a "magic number, not a parameter -- changing it - * breaks the hell loose - */ -#define MAX_MATCH (258) -#define MIN_MATCH (3) -#define MIN_LOOKAHEAD (MAX_MATCH + MIN_MATCH + 1) -#define MAX_MATCH_8 ((MAX_MATCH + 7) & ~7) - -/* stack frame offsets */ -#define LocalVarsSize (112) -#define _chainlenwmask ( 8-LocalVarsSize)(%rsp) -#define _windowbestlen (16-LocalVarsSize)(%rsp) -#define save_r14 (24-LocalVarsSize)(%rsp) -#define save_rsi (32-LocalVarsSize)(%rsp) -#define save_rbx (40-LocalVarsSize)(%rsp) -#define save_r12 (56-LocalVarsSize)(%rsp) -#define save_r13 (64-LocalVarsSize)(%rsp) -#define save_r15 (80-LocalVarsSize)(%rsp) - - -.globl match_init, longest_match - -/* - * On AMD64 the first argument of a function (in our case -- the pointer to - * deflate_state structure) is passed in %rdi, hence our offsets below are - * all off of that. - */ - -/* you can check the structure offset by running - -#include -#include -#include "deflate.h" - -void print_depl() -{ -deflate_state ds; -deflate_state *s=&ds; -printf("size pointer=%u\n",(int)sizeof(void*)); - -printf("#define dsWSize (%3u)(%%rdi)\n",(int)(((char*)&(s->w_size))-((char*)s))); -printf("#define dsWMask (%3u)(%%rdi)\n",(int)(((char*)&(s->w_mask))-((char*)s))); -printf("#define dsWindow (%3u)(%%rdi)\n",(int)(((char*)&(s->window))-((char*)s))); -printf("#define dsPrev (%3u)(%%rdi)\n",(int)(((char*)&(s->prev))-((char*)s))); -printf("#define dsMatchLen (%3u)(%%rdi)\n",(int)(((char*)&(s->match_length))-((char*)s))); -printf("#define dsPrevMatch (%3u)(%%rdi)\n",(int)(((char*)&(s->prev_match))-((char*)s))); -printf("#define dsStrStart (%3u)(%%rdi)\n",(int)(((char*)&(s->strstart))-((char*)s))); -printf("#define dsMatchStart (%3u)(%%rdi)\n",(int)(((char*)&(s->match_start))-((char*)s))); -printf("#define dsLookahead (%3u)(%%rdi)\n",(int)(((char*)&(s->lookahead))-((char*)s))); -printf("#define dsPrevLen (%3u)(%%rdi)\n",(int)(((char*)&(s->prev_length))-((char*)s))); -printf("#define dsMaxChainLen (%3u)(%%rdi)\n",(int)(((char*)&(s->max_chain_length))-((char*)s))); -printf("#define dsGoodMatch (%3u)(%%rdi)\n",(int)(((char*)&(s->good_match))-((char*)s))); -printf("#define dsNiceMatch (%3u)(%%rdi)\n",(int)(((char*)&(s->nice_match))-((char*)s))); -} - -*/ - - -/* - to compile for XCode 3.2 on MacOSX x86_64 - - run "gcc -g -c -DXCODE_MAC_X64_STRUCTURE amd64-match.S" - */ - - -#ifndef CURRENT_LINX_XCODE_MAC_X64_STRUCTURE -#define dsWSize ( 68)(%rdi) -#define dsWMask ( 76)(%rdi) -#define dsWindow ( 80)(%rdi) -#define dsPrev ( 96)(%rdi) -#define dsMatchLen (144)(%rdi) -#define dsPrevMatch (148)(%rdi) -#define dsStrStart (156)(%rdi) -#define dsMatchStart (160)(%rdi) -#define dsLookahead (164)(%rdi) -#define dsPrevLen (168)(%rdi) -#define dsMaxChainLen (172)(%rdi) -#define dsGoodMatch (188)(%rdi) -#define dsNiceMatch (192)(%rdi) - -#else - -#ifndef STRUCT_OFFSET -# define STRUCT_OFFSET (0) -#endif - - -#define dsWSize ( 56 + STRUCT_OFFSET)(%rdi) -#define dsWMask ( 64 + STRUCT_OFFSET)(%rdi) -#define dsWindow ( 72 + STRUCT_OFFSET)(%rdi) -#define dsPrev ( 88 + STRUCT_OFFSET)(%rdi) -#define dsMatchLen (136 + STRUCT_OFFSET)(%rdi) -#define dsPrevMatch (140 + STRUCT_OFFSET)(%rdi) -#define dsStrStart (148 + STRUCT_OFFSET)(%rdi) -#define dsMatchStart (152 + STRUCT_OFFSET)(%rdi) -#define dsLookahead (156 + STRUCT_OFFSET)(%rdi) -#define dsPrevLen (160 + STRUCT_OFFSET)(%rdi) -#define dsMaxChainLen (164 + STRUCT_OFFSET)(%rdi) -#define dsGoodMatch (180 + STRUCT_OFFSET)(%rdi) -#define dsNiceMatch (184 + STRUCT_OFFSET)(%rdi) - -#endif - - - - -.text - -/* uInt longest_match(deflate_state *deflatestate, IPos curmatch) */ - -longest_match: -/* - * Retrieve the function arguments. %curmatch will hold cur_match - * throughout the entire function (passed via rsi on amd64). - * rdi will hold the pointer to the deflate_state (first arg on amd64) - */ - mov %rsi, save_rsi - mov %rbx, save_rbx - mov %r12, save_r12 - mov %r13, save_r13 - mov %r14, save_r14 - mov %r15, save_r15 - -/* uInt wmask = s->w_mask; */ -/* unsigned chain_length = s->max_chain_length; */ -/* if (s->prev_length >= s->good_match) { */ -/* chain_length >>= 2; */ -/* } */ - - movl dsPrevLen, %eax - movl dsGoodMatch, %ebx - cmpl %ebx, %eax - movl dsWMask, %eax - movl dsMaxChainLen, %chainlenwmask - jl LastMatchGood - shrl $2, %chainlenwmask -LastMatchGood: - -/* chainlen is decremented once beforehand so that the function can */ -/* use the sign flag instead of the zero flag for the exit test. */ -/* It is then shifted into the high word, to make room for the wmask */ -/* value, which it will always accompany. */ - - decl %chainlenwmask - shll $16, %chainlenwmask - orl %eax, %chainlenwmask - -/* if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; */ - - movl dsNiceMatch, %eax - movl dsLookahead, %ebx - cmpl %eax, %ebx - jl LookaheadLess - movl %eax, %ebx -LookaheadLess: movl %ebx, %nicematch - -/* register Bytef *scan = s->window + s->strstart; */ - - mov dsWindow, %window - movl dsStrStart, %limitd - lea (%limit, %window), %scan - -/* Determine how many bytes the scan ptr is off from being */ -/* dword-aligned. */ - - mov %scan, %scanalign - negl %scanalignd - andl $3, %scanalignd - -/* IPos limit = s->strstart > (IPos)MAX_DIST(s) ? */ -/* s->strstart - (IPos)MAX_DIST(s) : NIL; */ - - movl dsWSize, %eax - subl $MIN_LOOKAHEAD, %eax - xorl %ecx, %ecx - subl %eax, %limitd - cmovng %ecx, %limitd - -/* int best_len = s->prev_length; */ - - movl dsPrevLen, %bestlend - -/* Store the sum of s->window + best_len in %windowbestlen locally, and in memory. */ - - lea (%window, %bestlen), %windowbestlen - mov %windowbestlen, _windowbestlen - -/* register ush scan_start = *(ushf*)scan; */ -/* register ush scan_end = *(ushf*)(scan+best_len-1); */ -/* Posf *prev = s->prev; */ - - movzwl (%scan), %scanstart - movzwl -1(%scan, %bestlen), %scanend - mov dsPrev, %prev - -/* Jump into the main loop. */ - - movl %chainlenwmask, _chainlenwmask - jmp LoopEntry - -.balign 16 - -/* do { - * match = s->window + cur_match; - * if (*(ushf*)(match+best_len-1) != scan_end || - * *(ushf*)match != scan_start) continue; - * [...] - * } while ((cur_match = prev[cur_match & wmask]) > limit - * && --chain_length != 0); - * - * Here is the inner loop of the function. The function will spend the - * majority of its time in this loop, and majority of that time will - * be spent in the first ten instructions. - */ -LookupLoop: - andl %chainlenwmask, %curmatchd - movzwl (%prev, %curmatch, 2), %curmatchd - cmpl %limitd, %curmatchd - jbe LeaveNow - subl $0x00010000, %chainlenwmask - js LeaveNow -LoopEntry: cmpw -1(%windowbestlen, %curmatch), %scanendw - jne LookupLoop - cmpw %scanstartw, (%window, %curmatch) - jne LookupLoop - -/* Store the current value of chainlen. */ - movl %chainlenwmask, _chainlenwmask - -/* %scan is the string under scrutiny, and %prev to the string we */ -/* are hoping to match it up with. In actuality, %esi and %edi are */ -/* both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and %edx is */ -/* initialized to -(MAX_MATCH_8 - scanalign). */ - - mov $(-MAX_MATCH_8), %rdx - lea (%curmatch, %window), %windowbestlen - lea MAX_MATCH_8(%windowbestlen, %scanalign), %windowbestlen - lea MAX_MATCH_8(%scan, %scanalign), %prev - -/* the prefetching below makes very little difference... */ - prefetcht1 (%windowbestlen, %rdx) - prefetcht1 (%prev, %rdx) - -/* - * Test the strings for equality, 8 bytes at a time. At the end, - * adjust %rdx so that it is offset to the exact byte that mismatched. - * - * It should be confessed that this loop usually does not represent - * much of the total running time. Replacing it with a more - * straightforward "rep cmpsb" would not drastically degrade - * performance -- unrolling it, for example, makes no difference. - */ - -#undef USE_SSE /* works, but is 6-7% slower, than non-SSE... */ - -LoopCmps: -#ifdef USE_SSE - /* Preload the SSE registers */ - movdqu (%windowbestlen, %rdx), %xmm1 - movdqu (%prev, %rdx), %xmm2 - pcmpeqb %xmm2, %xmm1 - movdqu 16(%windowbestlen, %rdx), %xmm3 - movdqu 16(%prev, %rdx), %xmm4 - pcmpeqb %xmm4, %xmm3 - movdqu 32(%windowbestlen, %rdx), %xmm5 - movdqu 32(%prev, %rdx), %xmm6 - pcmpeqb %xmm6, %xmm5 - movdqu 48(%windowbestlen, %rdx), %xmm7 - movdqu 48(%prev, %rdx), %xmm8 - pcmpeqb %xmm8, %xmm7 - - /* Check the comparisions' results */ - pmovmskb %xmm1, %rax - notw %ax - bsfw %ax, %ax - jnz LeaveLoopCmps - - /* this is the only iteration of the loop with a possibility of having - incremented rdx by 0x108 (each loop iteration add 16*4 = 0x40 - and (0x40*4)+8=0x108 */ - add $8, %rdx - jz LenMaximum - add $8, %rdx - - - pmovmskb %xmm3, %rax - notw %ax - bsfw %ax, %ax - jnz LeaveLoopCmps - - - add $16, %rdx - - - pmovmskb %xmm5, %rax - notw %ax - bsfw %ax, %ax - jnz LeaveLoopCmps - - add $16, %rdx - - - pmovmskb %xmm7, %rax - notw %ax - bsfw %ax, %ax - jnz LeaveLoopCmps - - add $16, %rdx - - jmp LoopCmps -LeaveLoopCmps: add %rax, %rdx -#else - mov (%windowbestlen, %rdx), %rax - xor (%prev, %rdx), %rax - jnz LeaveLoopCmps - - mov 8(%windowbestlen, %rdx), %rax - xor 8(%prev, %rdx), %rax - jnz LeaveLoopCmps8 - - mov 16(%windowbestlen, %rdx), %rax - xor 16(%prev, %rdx), %rax - jnz LeaveLoopCmps16 - - add $24, %rdx - jnz LoopCmps - jmp LenMaximum -# if 0 -/* - * This three-liner is tantalizingly simple, but bsf is a slow instruction, - * and the complicated alternative down below is quite a bit faster. Sad... - */ - -LeaveLoopCmps: bsf %rax, %rax /* find the first non-zero bit */ - shrl $3, %eax /* divide by 8 to get the byte */ - add %rax, %rdx -# else -LeaveLoopCmps16: - add $8, %rdx -LeaveLoopCmps8: - add $8, %rdx -LeaveLoopCmps: testl $0xFFFFFFFF, %eax /* Check the first 4 bytes */ - jnz Check16 - add $4, %rdx - shr $32, %rax -Check16: testw $0xFFFF, %ax - jnz LenLower - add $2, %rdx - shrl $16, %eax -LenLower: subb $1, %al - adc $0, %rdx -# endif -#endif - -/* Calculate the length of the match. If it is longer than MAX_MATCH, */ -/* then automatically accept it as the best possible match and leave. */ - - lea (%prev, %rdx), %rax - sub %scan, %rax - cmpl $MAX_MATCH, %eax - jge LenMaximum - -/* If the length of the match is not longer than the best match we */ -/* have so far, then forget it and return to the lookup loop. */ - - cmpl %bestlend, %eax - jg LongerMatch - mov _windowbestlen, %windowbestlen - mov dsPrev, %prev - movl _chainlenwmask, %edx - jmp LookupLoop - -/* s->match_start = cur_match; */ -/* best_len = len; */ -/* if (len >= nice_match) break; */ -/* scan_end = *(ushf*)(scan+best_len-1); */ - -LongerMatch: - movl %eax, %bestlend - movl %curmatchd, dsMatchStart - cmpl %nicematch, %eax - jge LeaveNow - - lea (%window, %bestlen), %windowbestlen - mov %windowbestlen, _windowbestlen - - movzwl -1(%scan, %rax), %scanend - mov dsPrev, %prev - movl _chainlenwmask, %chainlenwmask - jmp LookupLoop - -/* Accept the current string, with the maximum possible length. */ - -LenMaximum: - movl $MAX_MATCH, %bestlend - movl %curmatchd, dsMatchStart - -/* if ((uInt)best_len <= s->lookahead) return (uInt)best_len; */ -/* return s->lookahead; */ - -LeaveNow: - movl dsLookahead, %eax - cmpl %eax, %bestlend - cmovngl %bestlend, %eax -LookaheadRet: - -/* Restore the registers and return from whence we came. */ - - mov save_rsi, %rsi - mov save_rbx, %rbx - mov save_r12, %r12 - mov save_r13, %r13 - mov save_r14, %r14 - mov save_r15, %r15 - - ret - -match_init: ret diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/asm686/README.686 b/src/beast/test/zlib/zlib-1.2.8/contrib/asm686/README.686 deleted file mode 100644 index a0bf3bea4af..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/asm686/README.686 +++ /dev/null @@ -1,51 +0,0 @@ -This is a patched version of zlib, modified to use -Pentium-Pro-optimized assembly code in the deflation algorithm. The -files changed/added by this patch are: - -README.686 -match.S - -The speedup that this patch provides varies, depending on whether the -compiler used to build the original version of zlib falls afoul of the -PPro's speed traps. My own tests show a speedup of around 10-20% at -the default compression level, and 20-30% using -9, against a version -compiled using gcc 2.7.2.3. Your mileage may vary. - -Note that this code has been tailored for the PPro/PII in particular, -and will not perform particuarly well on a Pentium. - -If you are using an assembler other than GNU as, you will have to -translate match.S to use your assembler's syntax. (Have fun.) - -Brian Raiter -breadbox@muppetlabs.com -April, 1998 - - -Added for zlib 1.1.3: - -The patches come from -http://www.muppetlabs.com/~breadbox/software/assembly.html - -To compile zlib with this asm file, copy match.S to the zlib directory -then do: - -CFLAGS="-O3 -DASMV" ./configure -make OBJA=match.o - - -Update: - -I've been ignoring these assembly routines for years, believing that -gcc's generated code had caught up with it sometime around gcc 2.95 -and the major rearchitecting of the Pentium 4. However, I recently -learned that, despite what I believed, this code still has some life -in it. On the Pentium 4 and AMD64 chips, it continues to run about 8% -faster than the code produced by gcc 4.1. - -In acknowledgement of its continuing usefulness, I've altered the -license to match that of the rest of zlib. Share and Enjoy! - -Brian Raiter -breadbox@muppetlabs.com -April, 2007 diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/asm686/match.S b/src/beast/test/zlib/zlib-1.2.8/contrib/asm686/match.S deleted file mode 100644 index fa421092785..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/asm686/match.S +++ /dev/null @@ -1,357 +0,0 @@ -/* match.S -- x86 assembly version of the zlib longest_match() function. - * Optimized for the Intel 686 chips (PPro and later). - * - * Copyright (C) 1998, 2007 Brian Raiter - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the author be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - */ - -#ifndef NO_UNDERLINE -#define match_init _match_init -#define longest_match _longest_match -#endif - -#define MAX_MATCH (258) -#define MIN_MATCH (3) -#define MIN_LOOKAHEAD (MAX_MATCH + MIN_MATCH + 1) -#define MAX_MATCH_8 ((MAX_MATCH + 7) & ~7) - -/* stack frame offsets */ - -#define chainlenwmask 0 /* high word: current chain len */ - /* low word: s->wmask */ -#define window 4 /* local copy of s->window */ -#define windowbestlen 8 /* s->window + bestlen */ -#define scanstart 16 /* first two bytes of string */ -#define scanend 12 /* last two bytes of string */ -#define scanalign 20 /* dword-misalignment of string */ -#define nicematch 24 /* a good enough match size */ -#define bestlen 28 /* size of best match so far */ -#define scan 32 /* ptr to string wanting match */ - -#define LocalVarsSize (36) -/* saved ebx 36 */ -/* saved edi 40 */ -/* saved esi 44 */ -/* saved ebp 48 */ -/* return address 52 */ -#define deflatestate 56 /* the function arguments */ -#define curmatch 60 - -/* All the +zlib1222add offsets are due to the addition of fields - * in zlib in the deflate_state structure since the asm code was first written - * (if you compile with zlib 1.0.4 or older, use "zlib1222add equ (-4)"). - * (if you compile with zlib between 1.0.5 and 1.2.2.1, use "zlib1222add equ 0"). - * if you compile with zlib 1.2.2.2 or later , use "zlib1222add equ 8"). - */ - -#define zlib1222add (8) - -#define dsWSize (36+zlib1222add) -#define dsWMask (44+zlib1222add) -#define dsWindow (48+zlib1222add) -#define dsPrev (56+zlib1222add) -#define dsMatchLen (88+zlib1222add) -#define dsPrevMatch (92+zlib1222add) -#define dsStrStart (100+zlib1222add) -#define dsMatchStart (104+zlib1222add) -#define dsLookahead (108+zlib1222add) -#define dsPrevLen (112+zlib1222add) -#define dsMaxChainLen (116+zlib1222add) -#define dsGoodMatch (132+zlib1222add) -#define dsNiceMatch (136+zlib1222add) - - -.file "match.S" - -.globl match_init, longest_match - -.text - -/* uInt longest_match(deflate_state *deflatestate, IPos curmatch) */ -.cfi_sections .debug_frame - -longest_match: - -.cfi_startproc -/* Save registers that the compiler may be using, and adjust %esp to */ -/* make room for our stack frame. */ - - pushl %ebp - .cfi_def_cfa_offset 8 - .cfi_offset ebp, -8 - pushl %edi - .cfi_def_cfa_offset 12 - pushl %esi - .cfi_def_cfa_offset 16 - pushl %ebx - .cfi_def_cfa_offset 20 - subl $LocalVarsSize, %esp - .cfi_def_cfa_offset LocalVarsSize+20 - -/* Retrieve the function arguments. %ecx will hold cur_match */ -/* throughout the entire function. %edx will hold the pointer to the */ -/* deflate_state structure during the function's setup (before */ -/* entering the main loop). */ - - movl deflatestate(%esp), %edx - movl curmatch(%esp), %ecx - -/* uInt wmask = s->w_mask; */ -/* unsigned chain_length = s->max_chain_length; */ -/* if (s->prev_length >= s->good_match) { */ -/* chain_length >>= 2; */ -/* } */ - - movl dsPrevLen(%edx), %eax - movl dsGoodMatch(%edx), %ebx - cmpl %ebx, %eax - movl dsWMask(%edx), %eax - movl dsMaxChainLen(%edx), %ebx - jl LastMatchGood - shrl $2, %ebx -LastMatchGood: - -/* chainlen is decremented once beforehand so that the function can */ -/* use the sign flag instead of the zero flag for the exit test. */ -/* It is then shifted into the high word, to make room for the wmask */ -/* value, which it will always accompany. */ - - decl %ebx - shll $16, %ebx - orl %eax, %ebx - movl %ebx, chainlenwmask(%esp) - -/* if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; */ - - movl dsNiceMatch(%edx), %eax - movl dsLookahead(%edx), %ebx - cmpl %eax, %ebx - jl LookaheadLess - movl %eax, %ebx -LookaheadLess: movl %ebx, nicematch(%esp) - -/* register Bytef *scan = s->window + s->strstart; */ - - movl dsWindow(%edx), %esi - movl %esi, window(%esp) - movl dsStrStart(%edx), %ebp - lea (%esi,%ebp), %edi - movl %edi, scan(%esp) - -/* Determine how many bytes the scan ptr is off from being */ -/* dword-aligned. */ - - movl %edi, %eax - negl %eax - andl $3, %eax - movl %eax, scanalign(%esp) - -/* IPos limit = s->strstart > (IPos)MAX_DIST(s) ? */ -/* s->strstart - (IPos)MAX_DIST(s) : NIL; */ - - movl dsWSize(%edx), %eax - subl $MIN_LOOKAHEAD, %eax - subl %eax, %ebp - jg LimitPositive - xorl %ebp, %ebp -LimitPositive: - -/* int best_len = s->prev_length; */ - - movl dsPrevLen(%edx), %eax - movl %eax, bestlen(%esp) - -/* Store the sum of s->window + best_len in %esi locally, and in %esi. */ - - addl %eax, %esi - movl %esi, windowbestlen(%esp) - -/* register ush scan_start = *(ushf*)scan; */ -/* register ush scan_end = *(ushf*)(scan+best_len-1); */ -/* Posf *prev = s->prev; */ - - movzwl (%edi), %ebx - movl %ebx, scanstart(%esp) - movzwl -1(%edi,%eax), %ebx - movl %ebx, scanend(%esp) - movl dsPrev(%edx), %edi - -/* Jump into the main loop. */ - - movl chainlenwmask(%esp), %edx - jmp LoopEntry - -.balign 16 - -/* do { - * match = s->window + cur_match; - * if (*(ushf*)(match+best_len-1) != scan_end || - * *(ushf*)match != scan_start) continue; - * [...] - * } while ((cur_match = prev[cur_match & wmask]) > limit - * && --chain_length != 0); - * - * Here is the inner loop of the function. The function will spend the - * majority of its time in this loop, and majority of that time will - * be spent in the first ten instructions. - * - * Within this loop: - * %ebx = scanend - * %ecx = curmatch - * %edx = chainlenwmask - i.e., ((chainlen << 16) | wmask) - * %esi = windowbestlen - i.e., (window + bestlen) - * %edi = prev - * %ebp = limit - */ -LookupLoop: - andl %edx, %ecx - movzwl (%edi,%ecx,2), %ecx - cmpl %ebp, %ecx - jbe LeaveNow - subl $0x00010000, %edx - js LeaveNow -LoopEntry: movzwl -1(%esi,%ecx), %eax - cmpl %ebx, %eax - jnz LookupLoop - movl window(%esp), %eax - movzwl (%eax,%ecx), %eax - cmpl scanstart(%esp), %eax - jnz LookupLoop - -/* Store the current value of chainlen. */ - - movl %edx, chainlenwmask(%esp) - -/* Point %edi to the string under scrutiny, and %esi to the string we */ -/* are hoping to match it up with. In actuality, %esi and %edi are */ -/* both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and %edx is */ -/* initialized to -(MAX_MATCH_8 - scanalign). */ - - movl window(%esp), %esi - movl scan(%esp), %edi - addl %ecx, %esi - movl scanalign(%esp), %eax - movl $(-MAX_MATCH_8), %edx - lea MAX_MATCH_8(%edi,%eax), %edi - lea MAX_MATCH_8(%esi,%eax), %esi - -/* Test the strings for equality, 8 bytes at a time. At the end, - * adjust %edx so that it is offset to the exact byte that mismatched. - * - * We already know at this point that the first three bytes of the - * strings match each other, and they can be safely passed over before - * starting the compare loop. So what this code does is skip over 0-3 - * bytes, as much as necessary in order to dword-align the %edi - * pointer. (%esi will still be misaligned three times out of four.) - * - * It should be confessed that this loop usually does not represent - * much of the total running time. Replacing it with a more - * straightforward "rep cmpsb" would not drastically degrade - * performance. - */ -LoopCmps: - movl (%esi,%edx), %eax - xorl (%edi,%edx), %eax - jnz LeaveLoopCmps - movl 4(%esi,%edx), %eax - xorl 4(%edi,%edx), %eax - jnz LeaveLoopCmps4 - addl $8, %edx - jnz LoopCmps - jmp LenMaximum -LeaveLoopCmps4: addl $4, %edx -LeaveLoopCmps: testl $0x0000FFFF, %eax - jnz LenLower - addl $2, %edx - shrl $16, %eax -LenLower: subb $1, %al - adcl $0, %edx - -/* Calculate the length of the match. If it is longer than MAX_MATCH, */ -/* then automatically accept it as the best possible match and leave. */ - - lea (%edi,%edx), %eax - movl scan(%esp), %edi - subl %edi, %eax - cmpl $MAX_MATCH, %eax - jge LenMaximum - -/* If the length of the match is not longer than the best match we */ -/* have so far, then forget it and return to the lookup loop. */ - - movl deflatestate(%esp), %edx - movl bestlen(%esp), %ebx - cmpl %ebx, %eax - jg LongerMatch - movl windowbestlen(%esp), %esi - movl dsPrev(%edx), %edi - movl scanend(%esp), %ebx - movl chainlenwmask(%esp), %edx - jmp LookupLoop - -/* s->match_start = cur_match; */ -/* best_len = len; */ -/* if (len >= nice_match) break; */ -/* scan_end = *(ushf*)(scan+best_len-1); */ - -LongerMatch: movl nicematch(%esp), %ebx - movl %eax, bestlen(%esp) - movl %ecx, dsMatchStart(%edx) - cmpl %ebx, %eax - jge LeaveNow - movl window(%esp), %esi - addl %eax, %esi - movl %esi, windowbestlen(%esp) - movzwl -1(%edi,%eax), %ebx - movl dsPrev(%edx), %edi - movl %ebx, scanend(%esp) - movl chainlenwmask(%esp), %edx - jmp LookupLoop - -/* Accept the current string, with the maximum possible length. */ - -LenMaximum: movl deflatestate(%esp), %edx - movl $MAX_MATCH, bestlen(%esp) - movl %ecx, dsMatchStart(%edx) - -/* if ((uInt)best_len <= s->lookahead) return (uInt)best_len; */ -/* return s->lookahead; */ - -LeaveNow: - movl deflatestate(%esp), %edx - movl bestlen(%esp), %ebx - movl dsLookahead(%edx), %eax - cmpl %eax, %ebx - jg LookaheadRet - movl %ebx, %eax -LookaheadRet: - -/* Restore the stack and return from whence we came. */ - - addl $LocalVarsSize, %esp - .cfi_def_cfa_offset 20 - popl %ebx - .cfi_def_cfa_offset 16 - popl %esi - .cfi_def_cfa_offset 12 - popl %edi - .cfi_def_cfa_offset 8 - popl %ebp - .cfi_def_cfa_offset 4 -.cfi_endproc -match_init: ret diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/blast/Makefile b/src/beast/test/zlib/zlib-1.2.8/contrib/blast/Makefile deleted file mode 100644 index 9be80bafe05..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/blast/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -blast: blast.c blast.h - cc -DTEST -o blast blast.c - -test: blast - blast < test.pk | cmp - test.txt - -clean: - rm -f blast blast.o diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/blast/README b/src/beast/test/zlib/zlib-1.2.8/contrib/blast/README deleted file mode 100644 index e3a60b3f5cc..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/blast/README +++ /dev/null @@ -1,4 +0,0 @@ -Read blast.h for purpose and usage. - -Mark Adler -madler@alumni.caltech.edu diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/blast/blast.c b/src/beast/test/zlib/zlib-1.2.8/contrib/blast/blast.c deleted file mode 100644 index 69ef0fe00e8..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/blast/blast.c +++ /dev/null @@ -1,446 +0,0 @@ -/* blast.c - * Copyright (C) 2003, 2012 Mark Adler - * For conditions of distribution and use, see copyright notice in blast.h - * version 1.2, 24 Oct 2012 - * - * blast.c decompresses data compressed by the PKWare Compression Library. - * This function provides functionality similar to the explode() function of - * the PKWare library, hence the name "blast". - * - * This decompressor is based on the excellent format description provided by - * Ben Rudiak-Gould in comp.compression on August 13, 2001. Interestingly, the - * example Ben provided in the post is incorrect. The distance 110001 should - * instead be 111000. When corrected, the example byte stream becomes: - * - * 00 04 82 24 25 8f 80 7f - * - * which decompresses to "AIAIAIAIAIAIA" (without the quotes). - */ - -/* - * Change history: - * - * 1.0 12 Feb 2003 - First version - * 1.1 16 Feb 2003 - Fixed distance check for > 4 GB uncompressed data - * 1.2 24 Oct 2012 - Add note about using binary mode in stdio - * - Fix comparisons of differently signed integers - */ - -#include /* for setjmp(), longjmp(), and jmp_buf */ -#include "blast.h" /* prototype for blast() */ - -#define local static /* for local function definitions */ -#define MAXBITS 13 /* maximum code length */ -#define MAXWIN 4096 /* maximum window size */ - -/* input and output state */ -struct state { - /* input state */ - blast_in infun; /* input function provided by user */ - void *inhow; /* opaque information passed to infun() */ - unsigned char *in; /* next input location */ - unsigned left; /* available input at in */ - int bitbuf; /* bit buffer */ - int bitcnt; /* number of bits in bit buffer */ - - /* input limit error return state for bits() and decode() */ - jmp_buf env; - - /* output state */ - blast_out outfun; /* output function provided by user */ - void *outhow; /* opaque information passed to outfun() */ - unsigned next; /* index of next write location in out[] */ - int first; /* true to check distances (for first 4K) */ - unsigned char out[MAXWIN]; /* output buffer and sliding window */ -}; - -/* - * Return need bits from the input stream. This always leaves less than - * eight bits in the buffer. bits() works properly for need == 0. - * - * Format notes: - * - * - Bits are stored in bytes from the least significant bit to the most - * significant bit. Therefore bits are dropped from the bottom of the bit - * buffer, using shift right, and new bytes are appended to the top of the - * bit buffer, using shift left. - */ -local int bits(struct state *s, int need) -{ - int val; /* bit accumulator */ - - /* load at least need bits into val */ - val = s->bitbuf; - while (s->bitcnt < need) { - if (s->left == 0) { - s->left = s->infun(s->inhow, &(s->in)); - if (s->left == 0) longjmp(s->env, 1); /* out of input */ - } - val |= (int)(*(s->in)++) << s->bitcnt; /* load eight bits */ - s->left--; - s->bitcnt += 8; - } - - /* drop need bits and update buffer, always zero to seven bits left */ - s->bitbuf = val >> need; - s->bitcnt -= need; - - /* return need bits, zeroing the bits above that */ - return val & ((1 << need) - 1); -} - -/* - * Huffman code decoding tables. count[1..MAXBITS] is the number of symbols of - * each length, which for a canonical code are stepped through in order. - * symbol[] are the symbol values in canonical order, where the number of - * entries is the sum of the counts in count[]. The decoding process can be - * seen in the function decode() below. - */ -struct huffman { - short *count; /* number of symbols of each length */ - short *symbol; /* canonically ordered symbols */ -}; - -/* - * Decode a code from the stream s using huffman table h. Return the symbol or - * a negative value if there is an error. If all of the lengths are zero, i.e. - * an empty code, or if the code is incomplete and an invalid code is received, - * then -9 is returned after reading MAXBITS bits. - * - * Format notes: - * - * - The codes as stored in the compressed data are bit-reversed relative to - * a simple integer ordering of codes of the same lengths. Hence below the - * bits are pulled from the compressed data one at a time and used to - * build the code value reversed from what is in the stream in order to - * permit simple integer comparisons for decoding. - * - * - The first code for the shortest length is all ones. Subsequent codes of - * the same length are simply integer decrements of the previous code. When - * moving up a length, a one bit is appended to the code. For a complete - * code, the last code of the longest length will be all zeros. To support - * this ordering, the bits pulled during decoding are inverted to apply the - * more "natural" ordering starting with all zeros and incrementing. - */ -local int decode(struct state *s, struct huffman *h) -{ - int len; /* current number of bits in code */ - int code; /* len bits being decoded */ - int first; /* first code of length len */ - int count; /* number of codes of length len */ - int index; /* index of first code of length len in symbol table */ - int bitbuf; /* bits from stream */ - int left; /* bits left in next or left to process */ - short *next; /* next number of codes */ - - bitbuf = s->bitbuf; - left = s->bitcnt; - code = first = index = 0; - len = 1; - next = h->count + 1; - while (1) { - while (left--) { - code |= (bitbuf & 1) ^ 1; /* invert code */ - bitbuf >>= 1; - count = *next++; - if (code < first + count) { /* if length len, return symbol */ - s->bitbuf = bitbuf; - s->bitcnt = (s->bitcnt - len) & 7; - return h->symbol[index + (code - first)]; - } - index += count; /* else update for next length */ - first += count; - first <<= 1; - code <<= 1; - len++; - } - left = (MAXBITS+1) - len; - if (left == 0) break; - if (s->left == 0) { - s->left = s->infun(s->inhow, &(s->in)); - if (s->left == 0) longjmp(s->env, 1); /* out of input */ - } - bitbuf = *(s->in)++; - s->left--; - if (left > 8) left = 8; - } - return -9; /* ran out of codes */ -} - -/* - * Given a list of repeated code lengths rep[0..n-1], where each byte is a - * count (high four bits + 1) and a code length (low four bits), generate the - * list of code lengths. This compaction reduces the size of the object code. - * Then given the list of code lengths length[0..n-1] representing a canonical - * Huffman code for n symbols, construct the tables required to decode those - * codes. Those tables are the number of codes of each length, and the symbols - * sorted by length, retaining their original order within each length. The - * return value is zero for a complete code set, negative for an over- - * subscribed code set, and positive for an incomplete code set. The tables - * can be used if the return value is zero or positive, but they cannot be used - * if the return value is negative. If the return value is zero, it is not - * possible for decode() using that table to return an error--any stream of - * enough bits will resolve to a symbol. If the return value is positive, then - * it is possible for decode() using that table to return an error for received - * codes past the end of the incomplete lengths. - */ -local int construct(struct huffman *h, const unsigned char *rep, int n) -{ - int symbol; /* current symbol when stepping through length[] */ - int len; /* current length when stepping through h->count[] */ - int left; /* number of possible codes left of current length */ - short offs[MAXBITS+1]; /* offsets in symbol table for each length */ - short length[256]; /* code lengths */ - - /* convert compact repeat counts into symbol bit length list */ - symbol = 0; - do { - len = *rep++; - left = (len >> 4) + 1; - len &= 15; - do { - length[symbol++] = len; - } while (--left); - } while (--n); - n = symbol; - - /* count number of codes of each length */ - for (len = 0; len <= MAXBITS; len++) - h->count[len] = 0; - for (symbol = 0; symbol < n; symbol++) - (h->count[length[symbol]])++; /* assumes lengths are within bounds */ - if (h->count[0] == n) /* no codes! */ - return 0; /* complete, but decode() will fail */ - - /* check for an over-subscribed or incomplete set of lengths */ - left = 1; /* one possible code of zero length */ - for (len = 1; len <= MAXBITS; len++) { - left <<= 1; /* one more bit, double codes left */ - left -= h->count[len]; /* deduct count from possible codes */ - if (left < 0) return left; /* over-subscribed--return negative */ - } /* left > 0 means incomplete */ - - /* generate offsets into symbol table for each length for sorting */ - offs[1] = 0; - for (len = 1; len < MAXBITS; len++) - offs[len + 1] = offs[len] + h->count[len]; - - /* - * put symbols in table sorted by length, by symbol order within each - * length - */ - for (symbol = 0; symbol < n; symbol++) - if (length[symbol] != 0) - h->symbol[offs[length[symbol]]++] = symbol; - - /* return zero for complete set, positive for incomplete set */ - return left; -} - -/* - * Decode PKWare Compression Library stream. - * - * Format notes: - * - * - First byte is 0 if literals are uncoded or 1 if they are coded. Second - * byte is 4, 5, or 6 for the number of extra bits in the distance code. - * This is the base-2 logarithm of the dictionary size minus six. - * - * - Compressed data is a combination of literals and length/distance pairs - * terminated by an end code. Literals are either Huffman coded or - * uncoded bytes. A length/distance pair is a coded length followed by a - * coded distance to represent a string that occurs earlier in the - * uncompressed data that occurs again at the current location. - * - * - A bit preceding a literal or length/distance pair indicates which comes - * next, 0 for literals, 1 for length/distance. - * - * - If literals are uncoded, then the next eight bits are the literal, in the - * normal bit order in th stream, i.e. no bit-reversal is needed. Similarly, - * no bit reversal is needed for either the length extra bits or the distance - * extra bits. - * - * - Literal bytes are simply written to the output. A length/distance pair is - * an instruction to copy previously uncompressed bytes to the output. The - * copy is from distance bytes back in the output stream, copying for length - * bytes. - * - * - Distances pointing before the beginning of the output data are not - * permitted. - * - * - Overlapped copies, where the length is greater than the distance, are - * allowed and common. For example, a distance of one and a length of 518 - * simply copies the last byte 518 times. A distance of four and a length of - * twelve copies the last four bytes three times. A simple forward copy - * ignoring whether the length is greater than the distance or not implements - * this correctly. - */ -local int decomp(struct state *s) -{ - int lit; /* true if literals are coded */ - int dict; /* log2(dictionary size) - 6 */ - int symbol; /* decoded symbol, extra bits for distance */ - int len; /* length for copy */ - unsigned dist; /* distance for copy */ - int copy; /* copy counter */ - unsigned char *from, *to; /* copy pointers */ - static int virgin = 1; /* build tables once */ - static short litcnt[MAXBITS+1], litsym[256]; /* litcode memory */ - static short lencnt[MAXBITS+1], lensym[16]; /* lencode memory */ - static short distcnt[MAXBITS+1], distsym[64]; /* distcode memory */ - static struct huffman litcode = {litcnt, litsym}; /* length code */ - static struct huffman lencode = {lencnt, lensym}; /* length code */ - static struct huffman distcode = {distcnt, distsym};/* distance code */ - /* bit lengths of literal codes */ - static const unsigned char litlen[] = { - 11, 124, 8, 7, 28, 7, 188, 13, 76, 4, 10, 8, 12, 10, 12, 10, 8, 23, 8, - 9, 7, 6, 7, 8, 7, 6, 55, 8, 23, 24, 12, 11, 7, 9, 11, 12, 6, 7, 22, 5, - 7, 24, 6, 11, 9, 6, 7, 22, 7, 11, 38, 7, 9, 8, 25, 11, 8, 11, 9, 12, - 8, 12, 5, 38, 5, 38, 5, 11, 7, 5, 6, 21, 6, 10, 53, 8, 7, 24, 10, 27, - 44, 253, 253, 253, 252, 252, 252, 13, 12, 45, 12, 45, 12, 61, 12, 45, - 44, 173}; - /* bit lengths of length codes 0..15 */ - static const unsigned char lenlen[] = {2, 35, 36, 53, 38, 23}; - /* bit lengths of distance codes 0..63 */ - static const unsigned char distlen[] = {2, 20, 53, 230, 247, 151, 248}; - static const short base[16] = { /* base for length codes */ - 3, 2, 4, 5, 6, 7, 8, 9, 10, 12, 16, 24, 40, 72, 136, 264}; - static const char extra[16] = { /* extra bits for length codes */ - 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8}; - - /* set up decoding tables (once--might not be thread-safe) */ - if (virgin) { - construct(&litcode, litlen, sizeof(litlen)); - construct(&lencode, lenlen, sizeof(lenlen)); - construct(&distcode, distlen, sizeof(distlen)); - virgin = 0; - } - - /* read header */ - lit = bits(s, 8); - if (lit > 1) return -1; - dict = bits(s, 8); - if (dict < 4 || dict > 6) return -2; - - /* decode literals and length/distance pairs */ - do { - if (bits(s, 1)) { - /* get length */ - symbol = decode(s, &lencode); - len = base[symbol] + bits(s, extra[symbol]); - if (len == 519) break; /* end code */ - - /* get distance */ - symbol = len == 2 ? 2 : dict; - dist = decode(s, &distcode) << symbol; - dist += bits(s, symbol); - dist++; - if (s->first && dist > s->next) - return -3; /* distance too far back */ - - /* copy length bytes from distance bytes back */ - do { - to = s->out + s->next; - from = to - dist; - copy = MAXWIN; - if (s->next < dist) { - from += copy; - copy = dist; - } - copy -= s->next; - if (copy > len) copy = len; - len -= copy; - s->next += copy; - do { - *to++ = *from++; - } while (--copy); - if (s->next == MAXWIN) { - if (s->outfun(s->outhow, s->out, s->next)) return 1; - s->next = 0; - s->first = 0; - } - } while (len != 0); - } - else { - /* get literal and write it */ - symbol = lit ? decode(s, &litcode) : bits(s, 8); - s->out[s->next++] = symbol; - if (s->next == MAXWIN) { - if (s->outfun(s->outhow, s->out, s->next)) return 1; - s->next = 0; - s->first = 0; - } - } - } while (1); - return 0; -} - -/* See comments in blast.h */ -int blast(blast_in infun, void *inhow, blast_out outfun, void *outhow) -{ - struct state s; /* input/output state */ - int err; /* return value */ - - /* initialize input state */ - s.infun = infun; - s.inhow = inhow; - s.left = 0; - s.bitbuf = 0; - s.bitcnt = 0; - - /* initialize output state */ - s.outfun = outfun; - s.outhow = outhow; - s.next = 0; - s.first = 1; - - /* return if bits() or decode() tries to read past available input */ - if (setjmp(s.env) != 0) /* if came back here via longjmp(), */ - err = 2; /* then skip decomp(), return error */ - else - err = decomp(&s); /* decompress */ - - /* write any leftover output and update the error code if needed */ - if (err != 1 && s.next && s.outfun(s.outhow, s.out, s.next) && err == 0) - err = 1; - return err; -} - -#ifdef TEST -/* Example of how to use blast() */ -#include -#include - -#define CHUNK 16384 - -local unsigned inf(void *how, unsigned char **buf) -{ - static unsigned char hold[CHUNK]; - - *buf = hold; - return fread(hold, 1, CHUNK, (FILE *)how); -} - -local int outf(void *how, unsigned char *buf, unsigned len) -{ - return fwrite(buf, 1, len, (FILE *)how) != len; -} - -/* Decompress a PKWare Compression Library stream from stdin to stdout */ -int main(void) -{ - int ret, n; - - /* decompress to stdout */ - ret = blast(inf, stdin, outf, stdout); - if (ret != 0) fprintf(stderr, "blast error: %d\n", ret); - - /* see if there are any leftover bytes */ - n = 0; - while (getchar() != EOF) n++; - if (n) fprintf(stderr, "blast warning: %d unused bytes of input\n", n); - - /* return blast() error code */ - return ret; -} -#endif diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/blast/blast.h b/src/beast/test/zlib/zlib-1.2.8/contrib/blast/blast.h deleted file mode 100644 index 658cfd32004..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/blast/blast.h +++ /dev/null @@ -1,75 +0,0 @@ -/* blast.h -- interface for blast.c - Copyright (C) 2003, 2012 Mark Adler - version 1.2, 24 Oct 2012 - - This software is provided 'as-is', without any express or implied - warranty. In no event will the author be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Mark Adler madler@alumni.caltech.edu - */ - - -/* - * blast() decompresses the PKWare Data Compression Library (DCL) compressed - * format. It provides the same functionality as the explode() function in - * that library. (Note: PKWare overused the "implode" verb, and the format - * used by their library implode() function is completely different and - * incompatible with the implode compression method supported by PKZIP.) - * - * The binary mode for stdio functions should be used to assure that the - * compressed data is not corrupted when read or written. For example: - * fopen(..., "rb") and fopen(..., "wb"). - */ - - -typedef unsigned (*blast_in)(void *how, unsigned char **buf); -typedef int (*blast_out)(void *how, unsigned char *buf, unsigned len); -/* Definitions for input/output functions passed to blast(). See below for - * what the provided functions need to do. - */ - - -int blast(blast_in infun, void *inhow, blast_out outfun, void *outhow); -/* Decompress input to output using the provided infun() and outfun() calls. - * On success, the return value of blast() is zero. If there is an error in - * the source data, i.e. it is not in the proper format, then a negative value - * is returned. If there is not enough input available or there is not enough - * output space, then a positive error is returned. - * - * The input function is invoked: len = infun(how, &buf), where buf is set by - * infun() to point to the input buffer, and infun() returns the number of - * available bytes there. If infun() returns zero, then blast() returns with - * an input error. (blast() only asks for input if it needs it.) inhow is for - * use by the application to pass an input descriptor to infun(), if desired. - * - * The output function is invoked: err = outfun(how, buf, len), where the bytes - * to be written are buf[0..len-1]. If err is not zero, then blast() returns - * with an output error. outfun() is always called with len <= 4096. outhow - * is for use by the application to pass an output descriptor to outfun(), if - * desired. - * - * The return codes are: - * - * 2: ran out of input before completing decompression - * 1: output error before completing decompression - * 0: successful decompression - * -1: literal flag not zero or one - * -2: dictionary size not in 4..6 - * -3: distance is too far back - * - * At the bottom of blast.c is an example program that uses blast() that can be - * compiled to produce a command-line decompression filter by defining TEST. - */ diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/blast/test.pk b/src/beast/test/zlib/zlib-1.2.8/contrib/blast/test.pk deleted file mode 100644 index be10b2bbb25..00000000000 Binary files a/src/beast/test/zlib/zlib-1.2.8/contrib/blast/test.pk and /dev/null differ diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/blast/test.txt b/src/beast/test/zlib/zlib-1.2.8/contrib/blast/test.txt deleted file mode 100644 index bfdf1c5dca0..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/blast/test.txt +++ /dev/null @@ -1 +0,0 @@ -AIAIAIAIAIAIA \ No newline at end of file diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/delphi/ZLib.pas b/src/beast/test/zlib/zlib-1.2.8/contrib/delphi/ZLib.pas deleted file mode 100644 index a579974f044..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/delphi/ZLib.pas +++ /dev/null @@ -1,557 +0,0 @@ -{*******************************************************} -{ } -{ Borland Delphi Supplemental Components } -{ ZLIB Data Compression Interface Unit } -{ } -{ Copyright (c) 1997,99 Borland Corporation } -{ } -{*******************************************************} - -{ Updated for zlib 1.2.x by Cosmin Truta } - -unit ZLib; - -interface - -uses SysUtils, Classes; - -type - TAlloc = function (AppData: Pointer; Items, Size: Integer): Pointer; cdecl; - TFree = procedure (AppData, Block: Pointer); cdecl; - - // Internal structure. Ignore. - TZStreamRec = packed record - next_in: PChar; // next input byte - avail_in: Integer; // number of bytes available at next_in - total_in: Longint; // total nb of input bytes read so far - - next_out: PChar; // next output byte should be put here - avail_out: Integer; // remaining free space at next_out - total_out: Longint; // total nb of bytes output so far - - msg: PChar; // last error message, NULL if no error - internal: Pointer; // not visible by applications - - zalloc: TAlloc; // used to allocate the internal state - zfree: TFree; // used to free the internal state - AppData: Pointer; // private data object passed to zalloc and zfree - - data_type: Integer; // best guess about the data type: ascii or binary - adler: Longint; // adler32 value of the uncompressed data - reserved: Longint; // reserved for future use - end; - - // Abstract ancestor class - TCustomZlibStream = class(TStream) - private - FStrm: TStream; - FStrmPos: Integer; - FOnProgress: TNotifyEvent; - FZRec: TZStreamRec; - FBuffer: array [Word] of Char; - protected - procedure Progress(Sender: TObject); dynamic; - property OnProgress: TNotifyEvent read FOnProgress write FOnProgress; - constructor Create(Strm: TStream); - end; - -{ TCompressionStream compresses data on the fly as data is written to it, and - stores the compressed data to another stream. - - TCompressionStream is write-only and strictly sequential. Reading from the - stream will raise an exception. Using Seek to move the stream pointer - will raise an exception. - - Output data is cached internally, written to the output stream only when - the internal output buffer is full. All pending output data is flushed - when the stream is destroyed. - - The Position property returns the number of uncompressed bytes of - data that have been written to the stream so far. - - CompressionRate returns the on-the-fly percentage by which the original - data has been compressed: (1 - (CompressedBytes / UncompressedBytes)) * 100 - If raw data size = 100 and compressed data size = 25, the CompressionRate - is 75% - - The OnProgress event is called each time the output buffer is filled and - written to the output stream. This is useful for updating a progress - indicator when you are writing a large chunk of data to the compression - stream in a single call.} - - - TCompressionLevel = (clNone, clFastest, clDefault, clMax); - - TCompressionStream = class(TCustomZlibStream) - private - function GetCompressionRate: Single; - public - constructor Create(CompressionLevel: TCompressionLevel; Dest: TStream); - destructor Destroy; override; - function Read(var Buffer; Count: Longint): Longint; override; - function Write(const Buffer; Count: Longint): Longint; override; - function Seek(Offset: Longint; Origin: Word): Longint; override; - property CompressionRate: Single read GetCompressionRate; - property OnProgress; - end; - -{ TDecompressionStream decompresses data on the fly as data is read from it. - - Compressed data comes from a separate source stream. TDecompressionStream - is read-only and unidirectional; you can seek forward in the stream, but not - backwards. The special case of setting the stream position to zero is - allowed. Seeking forward decompresses data until the requested position in - the uncompressed data has been reached. Seeking backwards, seeking relative - to the end of the stream, requesting the size of the stream, and writing to - the stream will raise an exception. - - The Position property returns the number of bytes of uncompressed data that - have been read from the stream so far. - - The OnProgress event is called each time the internal input buffer of - compressed data is exhausted and the next block is read from the input stream. - This is useful for updating a progress indicator when you are reading a - large chunk of data from the decompression stream in a single call.} - - TDecompressionStream = class(TCustomZlibStream) - public - constructor Create(Source: TStream); - destructor Destroy; override; - function Read(var Buffer; Count: Longint): Longint; override; - function Write(const Buffer; Count: Longint): Longint; override; - function Seek(Offset: Longint; Origin: Word): Longint; override; - property OnProgress; - end; - - - -{ CompressBuf compresses data, buffer to buffer, in one call. - In: InBuf = ptr to compressed data - InBytes = number of bytes in InBuf - Out: OutBuf = ptr to newly allocated buffer containing decompressed data - OutBytes = number of bytes in OutBuf } -procedure CompressBuf(const InBuf: Pointer; InBytes: Integer; - out OutBuf: Pointer; out OutBytes: Integer); - - -{ DecompressBuf decompresses data, buffer to buffer, in one call. - In: InBuf = ptr to compressed data - InBytes = number of bytes in InBuf - OutEstimate = zero, or est. size of the decompressed data - Out: OutBuf = ptr to newly allocated buffer containing decompressed data - OutBytes = number of bytes in OutBuf } -procedure DecompressBuf(const InBuf: Pointer; InBytes: Integer; - OutEstimate: Integer; out OutBuf: Pointer; out OutBytes: Integer); - -{ DecompressToUserBuf decompresses data, buffer to buffer, in one call. - In: InBuf = ptr to compressed data - InBytes = number of bytes in InBuf - Out: OutBuf = ptr to user-allocated buffer to contain decompressed data - BufSize = number of bytes in OutBuf } -procedure DecompressToUserBuf(const InBuf: Pointer; InBytes: Integer; - const OutBuf: Pointer; BufSize: Integer); - -const - zlib_version = '1.2.8'; - -type - EZlibError = class(Exception); - ECompressionError = class(EZlibError); - EDecompressionError = class(EZlibError); - -implementation - -uses ZLibConst; - -const - Z_NO_FLUSH = 0; - Z_PARTIAL_FLUSH = 1; - Z_SYNC_FLUSH = 2; - Z_FULL_FLUSH = 3; - Z_FINISH = 4; - - Z_OK = 0; - Z_STREAM_END = 1; - Z_NEED_DICT = 2; - Z_ERRNO = (-1); - Z_STREAM_ERROR = (-2); - Z_DATA_ERROR = (-3); - Z_MEM_ERROR = (-4); - Z_BUF_ERROR = (-5); - Z_VERSION_ERROR = (-6); - - Z_NO_COMPRESSION = 0; - Z_BEST_SPEED = 1; - Z_BEST_COMPRESSION = 9; - Z_DEFAULT_COMPRESSION = (-1); - - Z_FILTERED = 1; - Z_HUFFMAN_ONLY = 2; - Z_RLE = 3; - Z_DEFAULT_STRATEGY = 0; - - Z_BINARY = 0; - Z_ASCII = 1; - Z_UNKNOWN = 2; - - Z_DEFLATED = 8; - - -{$L adler32.obj} -{$L compress.obj} -{$L crc32.obj} -{$L deflate.obj} -{$L infback.obj} -{$L inffast.obj} -{$L inflate.obj} -{$L inftrees.obj} -{$L trees.obj} -{$L uncompr.obj} -{$L zutil.obj} - -procedure adler32; external; -procedure compressBound; external; -procedure crc32; external; -procedure deflateInit2_; external; -procedure deflateParams; external; - -function _malloc(Size: Integer): Pointer; cdecl; -begin - Result := AllocMem(Size); -end; - -procedure _free(Block: Pointer); cdecl; -begin - FreeMem(Block); -end; - -procedure _memset(P: Pointer; B: Byte; count: Integer); cdecl; -begin - FillChar(P^, count, B); -end; - -procedure _memcpy(dest, source: Pointer; count: Integer); cdecl; -begin - Move(source^, dest^, count); -end; - - - -// deflate compresses data -function deflateInit_(var strm: TZStreamRec; level: Integer; version: PChar; - recsize: Integer): Integer; external; -function deflate(var strm: TZStreamRec; flush: Integer): Integer; external; -function deflateEnd(var strm: TZStreamRec): Integer; external; - -// inflate decompresses data -function inflateInit_(var strm: TZStreamRec; version: PChar; - recsize: Integer): Integer; external; -function inflate(var strm: TZStreamRec; flush: Integer): Integer; external; -function inflateEnd(var strm: TZStreamRec): Integer; external; -function inflateReset(var strm: TZStreamRec): Integer; external; - - -function zlibAllocMem(AppData: Pointer; Items, Size: Integer): Pointer; cdecl; -begin -// GetMem(Result, Items*Size); - Result := AllocMem(Items * Size); -end; - -procedure zlibFreeMem(AppData, Block: Pointer); cdecl; -begin - FreeMem(Block); -end; - -{function zlibCheck(code: Integer): Integer; -begin - Result := code; - if code < 0 then - raise EZlibError.Create('error'); //!! -end;} - -function CCheck(code: Integer): Integer; -begin - Result := code; - if code < 0 then - raise ECompressionError.Create('error'); //!! -end; - -function DCheck(code: Integer): Integer; -begin - Result := code; - if code < 0 then - raise EDecompressionError.Create('error'); //!! -end; - -procedure CompressBuf(const InBuf: Pointer; InBytes: Integer; - out OutBuf: Pointer; out OutBytes: Integer); -var - strm: TZStreamRec; - P: Pointer; -begin - FillChar(strm, sizeof(strm), 0); - strm.zalloc := zlibAllocMem; - strm.zfree := zlibFreeMem; - OutBytes := ((InBytes + (InBytes div 10) + 12) + 255) and not 255; - GetMem(OutBuf, OutBytes); - try - strm.next_in := InBuf; - strm.avail_in := InBytes; - strm.next_out := OutBuf; - strm.avail_out := OutBytes; - CCheck(deflateInit_(strm, Z_BEST_COMPRESSION, zlib_version, sizeof(strm))); - try - while CCheck(deflate(strm, Z_FINISH)) <> Z_STREAM_END do - begin - P := OutBuf; - Inc(OutBytes, 256); - ReallocMem(OutBuf, OutBytes); - strm.next_out := PChar(Integer(OutBuf) + (Integer(strm.next_out) - Integer(P))); - strm.avail_out := 256; - end; - finally - CCheck(deflateEnd(strm)); - end; - ReallocMem(OutBuf, strm.total_out); - OutBytes := strm.total_out; - except - FreeMem(OutBuf); - raise - end; -end; - - -procedure DecompressBuf(const InBuf: Pointer; InBytes: Integer; - OutEstimate: Integer; out OutBuf: Pointer; out OutBytes: Integer); -var - strm: TZStreamRec; - P: Pointer; - BufInc: Integer; -begin - FillChar(strm, sizeof(strm), 0); - strm.zalloc := zlibAllocMem; - strm.zfree := zlibFreeMem; - BufInc := (InBytes + 255) and not 255; - if OutEstimate = 0 then - OutBytes := BufInc - else - OutBytes := OutEstimate; - GetMem(OutBuf, OutBytes); - try - strm.next_in := InBuf; - strm.avail_in := InBytes; - strm.next_out := OutBuf; - strm.avail_out := OutBytes; - DCheck(inflateInit_(strm, zlib_version, sizeof(strm))); - try - while DCheck(inflate(strm, Z_NO_FLUSH)) <> Z_STREAM_END do - begin - P := OutBuf; - Inc(OutBytes, BufInc); - ReallocMem(OutBuf, OutBytes); - strm.next_out := PChar(Integer(OutBuf) + (Integer(strm.next_out) - Integer(P))); - strm.avail_out := BufInc; - end; - finally - DCheck(inflateEnd(strm)); - end; - ReallocMem(OutBuf, strm.total_out); - OutBytes := strm.total_out; - except - FreeMem(OutBuf); - raise - end; -end; - -procedure DecompressToUserBuf(const InBuf: Pointer; InBytes: Integer; - const OutBuf: Pointer; BufSize: Integer); -var - strm: TZStreamRec; -begin - FillChar(strm, sizeof(strm), 0); - strm.zalloc := zlibAllocMem; - strm.zfree := zlibFreeMem; - strm.next_in := InBuf; - strm.avail_in := InBytes; - strm.next_out := OutBuf; - strm.avail_out := BufSize; - DCheck(inflateInit_(strm, zlib_version, sizeof(strm))); - try - if DCheck(inflate(strm, Z_FINISH)) <> Z_STREAM_END then - raise EZlibError.CreateRes(@sTargetBufferTooSmall); - finally - DCheck(inflateEnd(strm)); - end; -end; - -// TCustomZlibStream - -constructor TCustomZLibStream.Create(Strm: TStream); -begin - inherited Create; - FStrm := Strm; - FStrmPos := Strm.Position; - FZRec.zalloc := zlibAllocMem; - FZRec.zfree := zlibFreeMem; -end; - -procedure TCustomZLibStream.Progress(Sender: TObject); -begin - if Assigned(FOnProgress) then FOnProgress(Sender); -end; - - -// TCompressionStream - -constructor TCompressionStream.Create(CompressionLevel: TCompressionLevel; - Dest: TStream); -const - Levels: array [TCompressionLevel] of ShortInt = - (Z_NO_COMPRESSION, Z_BEST_SPEED, Z_DEFAULT_COMPRESSION, Z_BEST_COMPRESSION); -begin - inherited Create(Dest); - FZRec.next_out := FBuffer; - FZRec.avail_out := sizeof(FBuffer); - CCheck(deflateInit_(FZRec, Levels[CompressionLevel], zlib_version, sizeof(FZRec))); -end; - -destructor TCompressionStream.Destroy; -begin - FZRec.next_in := nil; - FZRec.avail_in := 0; - try - if FStrm.Position <> FStrmPos then FStrm.Position := FStrmPos; - while (CCheck(deflate(FZRec, Z_FINISH)) <> Z_STREAM_END) - and (FZRec.avail_out = 0) do - begin - FStrm.WriteBuffer(FBuffer, sizeof(FBuffer)); - FZRec.next_out := FBuffer; - FZRec.avail_out := sizeof(FBuffer); - end; - if FZRec.avail_out < sizeof(FBuffer) then - FStrm.WriteBuffer(FBuffer, sizeof(FBuffer) - FZRec.avail_out); - finally - deflateEnd(FZRec); - end; - inherited Destroy; -end; - -function TCompressionStream.Read(var Buffer; Count: Longint): Longint; -begin - raise ECompressionError.CreateRes(@sInvalidStreamOp); -end; - -function TCompressionStream.Write(const Buffer; Count: Longint): Longint; -begin - FZRec.next_in := @Buffer; - FZRec.avail_in := Count; - if FStrm.Position <> FStrmPos then FStrm.Position := FStrmPos; - while (FZRec.avail_in > 0) do - begin - CCheck(deflate(FZRec, 0)); - if FZRec.avail_out = 0 then - begin - FStrm.WriteBuffer(FBuffer, sizeof(FBuffer)); - FZRec.next_out := FBuffer; - FZRec.avail_out := sizeof(FBuffer); - FStrmPos := FStrm.Position; - Progress(Self); - end; - end; - Result := Count; -end; - -function TCompressionStream.Seek(Offset: Longint; Origin: Word): Longint; -begin - if (Offset = 0) and (Origin = soFromCurrent) then - Result := FZRec.total_in - else - raise ECompressionError.CreateRes(@sInvalidStreamOp); -end; - -function TCompressionStream.GetCompressionRate: Single; -begin - if FZRec.total_in = 0 then - Result := 0 - else - Result := (1.0 - (FZRec.total_out / FZRec.total_in)) * 100.0; -end; - - -// TDecompressionStream - -constructor TDecompressionStream.Create(Source: TStream); -begin - inherited Create(Source); - FZRec.next_in := FBuffer; - FZRec.avail_in := 0; - DCheck(inflateInit_(FZRec, zlib_version, sizeof(FZRec))); -end; - -destructor TDecompressionStream.Destroy; -begin - FStrm.Seek(-FZRec.avail_in, 1); - inflateEnd(FZRec); - inherited Destroy; -end; - -function TDecompressionStream.Read(var Buffer; Count: Longint): Longint; -begin - FZRec.next_out := @Buffer; - FZRec.avail_out := Count; - if FStrm.Position <> FStrmPos then FStrm.Position := FStrmPos; - while (FZRec.avail_out > 0) do - begin - if FZRec.avail_in = 0 then - begin - FZRec.avail_in := FStrm.Read(FBuffer, sizeof(FBuffer)); - if FZRec.avail_in = 0 then - begin - Result := Count - FZRec.avail_out; - Exit; - end; - FZRec.next_in := FBuffer; - FStrmPos := FStrm.Position; - Progress(Self); - end; - CCheck(inflate(FZRec, 0)); - end; - Result := Count; -end; - -function TDecompressionStream.Write(const Buffer; Count: Longint): Longint; -begin - raise EDecompressionError.CreateRes(@sInvalidStreamOp); -end; - -function TDecompressionStream.Seek(Offset: Longint; Origin: Word): Longint; -var - I: Integer; - Buf: array [0..4095] of Char; -begin - if (Offset = 0) and (Origin = soFromBeginning) then - begin - DCheck(inflateReset(FZRec)); - FZRec.next_in := FBuffer; - FZRec.avail_in := 0; - FStrm.Position := 0; - FStrmPos := 0; - end - else if ( (Offset >= 0) and (Origin = soFromCurrent)) or - ( ((Offset - FZRec.total_out) > 0) and (Origin = soFromBeginning)) then - begin - if Origin = soFromBeginning then Dec(Offset, FZRec.total_out); - if Offset > 0 then - begin - for I := 1 to Offset div sizeof(Buf) do - ReadBuffer(Buf, sizeof(Buf)); - ReadBuffer(Buf, Offset mod sizeof(Buf)); - end; - end - else - raise EDecompressionError.CreateRes(@sInvalidStreamOp); - Result := FZRec.total_out; -end; - - -end. diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/delphi/ZLibConst.pas b/src/beast/test/zlib/zlib-1.2.8/contrib/delphi/ZLibConst.pas deleted file mode 100644 index cdfe13671d3..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/delphi/ZLibConst.pas +++ /dev/null @@ -1,11 +0,0 @@ -unit ZLibConst; - -interface - -resourcestring - sTargetBufferTooSmall = 'ZLib error: target buffer may be too small'; - sInvalidStreamOp = 'Invalid stream operation'; - -implementation - -end. diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/delphi/readme.txt b/src/beast/test/zlib/zlib-1.2.8/contrib/delphi/readme.txt deleted file mode 100644 index 2dc9a8bba2f..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/delphi/readme.txt +++ /dev/null @@ -1,76 +0,0 @@ - -Overview -======== - -This directory contains an update to the ZLib interface unit, -distributed by Borland as a Delphi supplemental component. - -The original ZLib unit is Copyright (c) 1997,99 Borland Corp., -and is based on zlib version 1.0.4. There are a series of bugs -and security problems associated with that old zlib version, and -we recommend the users to update their ZLib unit. - - -Summary of modifications -======================== - -- Improved makefile, adapted to zlib version 1.2.1. - -- Some field types from TZStreamRec are changed from Integer to - Longint, for consistency with the zlib.h header, and for 64-bit - readiness. - -- The zlib_version constant is updated. - -- The new Z_RLE strategy has its corresponding symbolic constant. - -- The allocation and deallocation functions and function types - (TAlloc, TFree, zlibAllocMem and zlibFreeMem) are now cdecl, - and _malloc and _free are added as C RTL stubs. As a result, - the original C sources of zlib can be compiled out of the box, - and linked to the ZLib unit. - - -Suggestions for improvements -============================ - -Currently, the ZLib unit provides only a limited wrapper around -the zlib library, and much of the original zlib functionality is -missing. Handling compressed file formats like ZIP/GZIP or PNG -cannot be implemented without having this functionality. -Applications that handle these formats are either using their own, -duplicated code, or not using the ZLib unit at all. - -Here are a few suggestions: - -- Checksum class wrappers around adler32() and crc32(), similar - to the Java classes that implement the java.util.zip.Checksum - interface. - -- The ability to read and write raw deflate streams, without the - zlib stream header and trailer. Raw deflate streams are used - in the ZIP file format. - -- The ability to read and write gzip streams, used in the GZIP - file format, and normally produced by the gzip program. - -- The ability to select a different compression strategy, useful - to PNG and MNG image compression, and to multimedia compression - in general. Besides the compression level - - TCompressionLevel = (clNone, clFastest, clDefault, clMax); - - which, in fact, could have used the 'z' prefix and avoided - TColor-like symbols - - TCompressionLevel = (zcNone, zcFastest, zcDefault, zcMax); - - there could be a compression strategy - - TCompressionStrategy = (zsDefault, zsFiltered, zsHuffmanOnly, zsRle); - -- ZIP and GZIP stream handling via TStreams. - - --- -Cosmin Truta diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/delphi/zlibd32.mak b/src/beast/test/zlib/zlib-1.2.8/contrib/delphi/zlibd32.mak deleted file mode 100644 index 9bb00b7cc42..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/delphi/zlibd32.mak +++ /dev/null @@ -1,99 +0,0 @@ -# Makefile for zlib -# For use with Delphi and C++ Builder under Win32 -# Updated for zlib 1.2.x by Cosmin Truta - -# ------------ Borland C++ ------------ - -# This project uses the Delphi (fastcall/register) calling convention: -LOC = -DZEXPORT=__fastcall -DZEXPORTVA=__cdecl - -CC = bcc32 -LD = bcc32 -AR = tlib -# do not use "-pr" in CFLAGS -CFLAGS = -a -d -k- -O2 $(LOC) -LDFLAGS = - - -# variables -ZLIB_LIB = zlib.lib - -OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzlib.obj gzread.obj -OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj -OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzlib.obj+gzread.obj -OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj - - -# targets -all: $(ZLIB_LIB) example.exe minigzip.exe - -.c.obj: - $(CC) -c $(CFLAGS) $*.c - -adler32.obj: adler32.c zlib.h zconf.h - -compress.obj: compress.c zlib.h zconf.h - -crc32.obj: crc32.c zlib.h zconf.h crc32.h - -deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h - -gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h - -gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h - -gzread.obj: gzread.c zlib.h zconf.h gzguts.h - -gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h - -infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ - inffast.h inffixed.h - -inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ - inffast.h - -inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ - inffast.h inffixed.h - -inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h - -trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h - -uncompr.obj: uncompr.c zlib.h zconf.h - -zutil.obj: zutil.c zutil.h zlib.h zconf.h - -example.obj: test/example.c zlib.h zconf.h - -minigzip.obj: test/minigzip.c zlib.h zconf.h - - -# For the sake of the old Borland make, -# the command line is cut to fit in the MS-DOS 128 byte limit: -$(ZLIB_LIB): $(OBJ1) $(OBJ2) - -del $(ZLIB_LIB) - $(AR) $(ZLIB_LIB) $(OBJP1) - $(AR) $(ZLIB_LIB) $(OBJP2) - - -# testing -test: example.exe minigzip.exe - example - echo hello world | minigzip | minigzip -d - -example.exe: example.obj $(ZLIB_LIB) - $(LD) $(LDFLAGS) example.obj $(ZLIB_LIB) - -minigzip.exe: minigzip.obj $(ZLIB_LIB) - $(LD) $(LDFLAGS) minigzip.obj $(ZLIB_LIB) - - -# cleanup -clean: - -del *.obj - -del *.exe - -del *.lib - -del *.tds - -del zlib.bak - -del foo.gz - diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib.build b/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib.build deleted file mode 100644 index e69630cec2d..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib.build +++ /dev/null @@ -1,33 +0,0 @@ - - - A .Net wrapper library around ZLib1.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib.chm b/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib.chm deleted file mode 100644 index f214a444aeb..00000000000 Binary files a/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib.chm and /dev/null differ diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib.sln b/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib.sln deleted file mode 100644 index 5d533d6bc57..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib.sln +++ /dev/null @@ -1,21 +0,0 @@ -Microsoft Visual Studio Solution File, Format Version 8.00 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotZLib", "DotZLib\DotZLib.csproj", "{BB1EE0B1-1808-46CB-B786-949D91117FC5}" - ProjectSection(ProjectDependencies) = postProject - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfiguration) = preSolution - Debug = Debug - Release = Release - EndGlobalSection - GlobalSection(ProjectConfiguration) = postSolution - {BB1EE0B1-1808-46CB-B786-949D91117FC5}.Debug.ActiveCfg = Debug|.NET - {BB1EE0B1-1808-46CB-B786-949D91117FC5}.Debug.Build.0 = Debug|.NET - {BB1EE0B1-1808-46CB-B786-949D91117FC5}.Release.ActiveCfg = Release|.NET - {BB1EE0B1-1808-46CB-B786-949D91117FC5}.Release.Build.0 = Release|.NET - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - EndGlobalSection - GlobalSection(ExtensibilityAddIns) = postSolution - EndGlobalSection -EndGlobal diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib/AssemblyInfo.cs b/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib/AssemblyInfo.cs deleted file mode 100644 index 724c5347f35..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib/AssemblyInfo.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; - -// -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -// -[assembly: AssemblyTitle("DotZLib")] -[assembly: AssemblyDescription(".Net bindings for ZLib compression dll 1.2.x")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Henrik Ravn")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("(c) 2004 by Henrik Ravn")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Revision and Build Numbers -// by using the '*' as shown below: - -[assembly: AssemblyVersion("1.0.*")] - -// -// In order to sign your assembly you must specify a key to use. Refer to the -// Microsoft .NET Framework documentation for more information on assembly signing. -// -// Use the attributes below to control which key is used for signing. -// -// Notes: -// (*) If no key is specified, the assembly is not signed. -// (*) KeyName refers to a key that has been installed in the Crypto Service -// Provider (CSP) on your machine. KeyFile refers to a file which contains -// a key. -// (*) If the KeyFile and the KeyName values are both specified, the -// following processing occurs: -// (1) If the KeyName can be found in the CSP, that key is used. -// (2) If the KeyName does not exist and the KeyFile does exist, the key -// in the KeyFile is installed into the CSP and used. -// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. -// When specifying the KeyFile, the location of the KeyFile should be -// relative to the project output directory which is -// %Project Directory%\obj\. For example, if your KeyFile is -// located in the project directory, you would specify the AssemblyKeyFile -// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] -// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework -// documentation for more information on this. -// -[assembly: AssemblyDelaySign(false)] -[assembly: AssemblyKeyFile("")] -[assembly: AssemblyKeyName("")] diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib/ChecksumImpl.cs b/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib/ChecksumImpl.cs deleted file mode 100644 index b110dae6a19..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib/ChecksumImpl.cs +++ /dev/null @@ -1,202 +0,0 @@ -// -// © Copyright Henrik Ravn 2004 -// -// Use, modification and distribution are subject to 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) -// - -using System; -using System.Runtime.InteropServices; -using System.Text; - - -namespace DotZLib -{ - #region ChecksumGeneratorBase - ///

- /// Implements the common functionality needed for all s - /// - /// - public abstract class ChecksumGeneratorBase : ChecksumGenerator - { - /// - /// The value of the current checksum - /// - protected uint _current; - - /// - /// Initializes a new instance of the checksum generator base - the current checksum is - /// set to zero - /// - public ChecksumGeneratorBase() - { - _current = 0; - } - - /// - /// Initializes a new instance of the checksum generator basewith a specified value - /// - /// The value to set the current checksum to - public ChecksumGeneratorBase(uint initialValue) - { - _current = initialValue; - } - - /// - /// Resets the current checksum to zero - /// - public void Reset() { _current = 0; } - - /// - /// Gets the current checksum value - /// - public uint Value { get { return _current; } } - - /// - /// Updates the current checksum with part of an array of bytes - /// - /// The data to update the checksum with - /// Where in data to start updating - /// The number of bytes from data to use - /// The sum of offset and count is larger than the length of data - /// data is a null reference - /// Offset or count is negative. - /// All the other Update methods are implmeneted in terms of this one. - /// This is therefore the only method a derived class has to implement - public abstract void Update(byte[] data, int offset, int count); - - /// - /// Updates the current checksum with an array of bytes. - /// - /// The data to update the checksum with - public void Update(byte[] data) - { - Update(data, 0, data.Length); - } - - /// - /// Updates the current checksum with the data from a string - /// - /// The string to update the checksum with - /// The characters in the string are converted by the UTF-8 encoding - public void Update(string data) - { - Update(Encoding.UTF8.GetBytes(data)); - } - - /// - /// Updates the current checksum with the data from a string, using a specific encoding - /// - /// The string to update the checksum with - /// The encoding to use - public void Update(string data, Encoding encoding) - { - Update(encoding.GetBytes(data)); - } - - } - #endregion - - #region CRC32 - /// - /// Implements a CRC32 checksum generator - /// - public sealed class CRC32Checksum : ChecksumGeneratorBase - { - #region DLL imports - - [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] - private static extern uint crc32(uint crc, int data, uint length); - - #endregion - - /// - /// Initializes a new instance of the CRC32 checksum generator - /// - public CRC32Checksum() : base() {} - - /// - /// Initializes a new instance of the CRC32 checksum generator with a specified value - /// - /// The value to set the current checksum to - public CRC32Checksum(uint initialValue) : base(initialValue) {} - - /// - /// Updates the current checksum with part of an array of bytes - /// - /// The data to update the checksum with - /// Where in data to start updating - /// The number of bytes from data to use - /// The sum of offset and count is larger than the length of data - /// data is a null reference - /// Offset or count is negative. - public override void Update(byte[] data, int offset, int count) - { - if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException(); - if ((offset+count) > data.Length) throw new ArgumentException(); - GCHandle hData = GCHandle.Alloc(data, GCHandleType.Pinned); - try - { - _current = crc32(_current, hData.AddrOfPinnedObject().ToInt32()+offset, (uint)count); - } - finally - { - hData.Free(); - } - } - - } - #endregion - - #region Adler - /// - /// Implements a checksum generator that computes the Adler checksum on data - /// - public sealed class AdlerChecksum : ChecksumGeneratorBase - { - #region DLL imports - - [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] - private static extern uint adler32(uint adler, int data, uint length); - - #endregion - - /// - /// Initializes a new instance of the Adler checksum generator - /// - public AdlerChecksum() : base() {} - - /// - /// Initializes a new instance of the Adler checksum generator with a specified value - /// - /// The value to set the current checksum to - public AdlerChecksum(uint initialValue) : base(initialValue) {} - - /// - /// Updates the current checksum with part of an array of bytes - /// - /// The data to update the checksum with - /// Where in data to start updating - /// The number of bytes from data to use - /// The sum of offset and count is larger than the length of data - /// data is a null reference - /// Offset or count is negative. - public override void Update(byte[] data, int offset, int count) - { - if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException(); - if ((offset+count) > data.Length) throw new ArgumentException(); - GCHandle hData = GCHandle.Alloc(data, GCHandleType.Pinned); - try - { - _current = adler32(_current, hData.AddrOfPinnedObject().ToInt32()+offset, (uint)count); - } - finally - { - hData.Free(); - } - } - - } - #endregion - -} \ No newline at end of file diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib/CircularBuffer.cs b/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib/CircularBuffer.cs deleted file mode 100644 index 9c8d601954f..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib/CircularBuffer.cs +++ /dev/null @@ -1,83 +0,0 @@ -// -// © Copyright Henrik Ravn 2004 -// -// Use, modification and distribution are subject to 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) -// - -using System; -using System.Diagnostics; - -namespace DotZLib -{ - - /// - /// This class implements a circular buffer - /// - internal class CircularBuffer - { - #region Private data - private int _capacity; - private int _head; - private int _tail; - private int _size; - private byte[] _buffer; - #endregion - - public CircularBuffer(int capacity) - { - Debug.Assert( capacity > 0 ); - _buffer = new byte[capacity]; - _capacity = capacity; - _head = 0; - _tail = 0; - _size = 0; - } - - public int Size { get { return _size; } } - - public int Put(byte[] source, int offset, int count) - { - Debug.Assert( count > 0 ); - int trueCount = Math.Min(count, _capacity - Size); - for (int i = 0; i < trueCount; ++i) - _buffer[(_tail+i) % _capacity] = source[offset+i]; - _tail += trueCount; - _tail %= _capacity; - _size += trueCount; - return trueCount; - } - - public bool Put(byte b) - { - if (Size == _capacity) // no room - return false; - _buffer[_tail++] = b; - _tail %= _capacity; - ++_size; - return true; - } - - public int Get(byte[] destination, int offset, int count) - { - int trueCount = Math.Min(count,Size); - for (int i = 0; i < trueCount; ++i) - destination[offset + i] = _buffer[(_head+i) % _capacity]; - _head += trueCount; - _head %= _capacity; - _size -= trueCount; - return trueCount; - } - - public int Get() - { - if (Size == 0) - return -1; - - int result = (int)_buffer[_head++ % _capacity]; - --_size; - return result; - } - - } -} diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib/CodecBase.cs b/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib/CodecBase.cs deleted file mode 100644 index b0eb78a0221..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib/CodecBase.cs +++ /dev/null @@ -1,198 +0,0 @@ -// -// © Copyright Henrik Ravn 2004 -// -// Use, modification and distribution are subject to 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) -// - -using System; -using System.Runtime.InteropServices; - -namespace DotZLib -{ - /// - /// Implements the common functionality needed for all s - /// - public abstract class CodecBase : Codec, IDisposable - { - - #region Data members - - /// - /// Instance of the internal zlib buffer structure that is - /// passed to all functions in the zlib dll - /// - internal ZStream _ztream = new ZStream(); - - /// - /// True if the object instance has been disposed, false otherwise - /// - protected bool _isDisposed = false; - - /// - /// The size of the internal buffers - /// - protected const int kBufferSize = 16384; - - private byte[] _outBuffer = new byte[kBufferSize]; - private byte[] _inBuffer = new byte[kBufferSize]; - - private GCHandle _hInput; - private GCHandle _hOutput; - - private uint _checksum = 0; - - #endregion - - /// - /// Initializes a new instance of the CodeBase class. - /// - public CodecBase() - { - try - { - _hInput = GCHandle.Alloc(_inBuffer, GCHandleType.Pinned); - _hOutput = GCHandle.Alloc(_outBuffer, GCHandleType.Pinned); - } - catch (Exception) - { - CleanUp(false); - throw; - } - } - - - #region Codec Members - - /// - /// Occurs when more processed data are available. - /// - public event DataAvailableHandler DataAvailable; - - /// - /// Fires the event - /// - protected void OnDataAvailable() - { - if (_ztream.total_out > 0) - { - if (DataAvailable != null) - DataAvailable( _outBuffer, 0, (int)_ztream.total_out); - resetOutput(); - } - } - - /// - /// Adds more data to the codec to be processed. - /// - /// Byte array containing the data to be added to the codec - /// Adding data may, or may not, raise the DataAvailable event - public void Add(byte[] data) - { - Add(data,0,data.Length); - } - - /// - /// Adds more data to the codec to be processed. - /// - /// Byte array containing the data to be added to the codec - /// The index of the first byte to add from data - /// The number of bytes to add - /// Adding data may, or may not, raise the DataAvailable event - /// This must be implemented by a derived class - public abstract void Add(byte[] data, int offset, int count); - - /// - /// Finishes up any pending data that needs to be processed and handled. - /// - /// This must be implemented by a derived class - public abstract void Finish(); - - /// - /// Gets the checksum of the data that has been added so far - /// - public uint Checksum { get { return _checksum; } } - - #endregion - - #region Destructor & IDisposable stuff - - /// - /// Destroys this instance - /// - ~CodecBase() - { - CleanUp(false); - } - - /// - /// Releases any unmanaged resources and calls the method of the derived class - /// - public void Dispose() - { - CleanUp(true); - } - - /// - /// Performs any codec specific cleanup - /// - /// This must be implemented by a derived class - protected abstract void CleanUp(); - - // performs the release of the handles and calls the dereived CleanUp() - private void CleanUp(bool isDisposing) - { - if (!_isDisposed) - { - CleanUp(); - if (_hInput.IsAllocated) - _hInput.Free(); - if (_hOutput.IsAllocated) - _hOutput.Free(); - - _isDisposed = true; - } - } - - - #endregion - - #region Helper methods - - /// - /// Copies a number of bytes to the internal codec buffer - ready for proccesing - /// - /// The byte array that contains the data to copy - /// The index of the first byte to copy - /// The number of bytes to copy from data - protected void copyInput(byte[] data, int startIndex, int count) - { - Array.Copy(data, startIndex, _inBuffer,0, count); - _ztream.next_in = _hInput.AddrOfPinnedObject(); - _ztream.total_in = 0; - _ztream.avail_in = (uint)count; - - } - - /// - /// Resets the internal output buffers to a known state - ready for processing - /// - protected void resetOutput() - { - _ztream.total_out = 0; - _ztream.avail_out = kBufferSize; - _ztream.next_out = _hOutput.AddrOfPinnedObject(); - } - - /// - /// Updates the running checksum property - /// - /// The new checksum value - protected void setChecksum(uint newSum) - { - _checksum = newSum; - } - #endregion - - } -} diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib/Deflater.cs b/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib/Deflater.cs deleted file mode 100644 index 9039f41f663..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib/Deflater.cs +++ /dev/null @@ -1,106 +0,0 @@ -// -// © Copyright Henrik Ravn 2004 -// -// Use, modification and distribution are subject to 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) -// - -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; - -namespace DotZLib -{ - - /// - /// Implements a data compressor, using the deflate algorithm in the ZLib dll - /// - public sealed class Deflater : CodecBase - { - #region Dll imports - [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl, CharSet=CharSet.Ansi)] - private static extern int deflateInit_(ref ZStream sz, int level, string vs, int size); - - [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] - private static extern int deflate(ref ZStream sz, int flush); - - [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] - private static extern int deflateReset(ref ZStream sz); - - [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] - private static extern int deflateEnd(ref ZStream sz); - #endregion - - /// - /// Constructs an new instance of the Deflater - /// - /// The compression level to use for this Deflater - public Deflater(CompressLevel level) : base() - { - int retval = deflateInit_(ref _ztream, (int)level, Info.Version, Marshal.SizeOf(_ztream)); - if (retval != 0) - throw new ZLibException(retval, "Could not initialize deflater"); - - resetOutput(); - } - - /// - /// Adds more data to the codec to be processed. - /// - /// Byte array containing the data to be added to the codec - /// The index of the first byte to add from data - /// The number of bytes to add - /// Adding data may, or may not, raise the DataAvailable event - public override void Add(byte[] data, int offset, int count) - { - if (data == null) throw new ArgumentNullException(); - if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException(); - if ((offset+count) > data.Length) throw new ArgumentException(); - - int total = count; - int inputIndex = offset; - int err = 0; - - while (err >= 0 && inputIndex < total) - { - copyInput(data, inputIndex, Math.Min(total - inputIndex, kBufferSize)); - while (err >= 0 && _ztream.avail_in > 0) - { - err = deflate(ref _ztream, (int)FlushTypes.None); - if (err == 0) - while (_ztream.avail_out == 0) - { - OnDataAvailable(); - err = deflate(ref _ztream, (int)FlushTypes.None); - } - inputIndex += (int)_ztream.total_in; - } - } - setChecksum( _ztream.adler ); - } - - - /// - /// Finishes up any pending data that needs to be processed and handled. - /// - public override void Finish() - { - int err; - do - { - err = deflate(ref _ztream, (int)FlushTypes.Finish); - OnDataAvailable(); - } - while (err == 0); - setChecksum( _ztream.adler ); - deflateReset(ref _ztream); - resetOutput(); - } - - /// - /// Closes the internal zlib deflate stream - /// - protected override void CleanUp() { deflateEnd(ref _ztream); } - - } -} diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib/DotZLib.cs b/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib/DotZLib.cs deleted file mode 100644 index 90c7c3b3807..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib/DotZLib.cs +++ /dev/null @@ -1,288 +0,0 @@ -// -// © Copyright Henrik Ravn 2004 -// -// Use, modification and distribution are subject to 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) -// - -using System; -using System.IO; -using System.Runtime.InteropServices; -using System.Text; - - -namespace DotZLib -{ - - #region Internal types - - /// - /// Defines constants for the various flush types used with zlib - /// - internal enum FlushTypes - { - None, Partial, Sync, Full, Finish, Block - } - - #region ZStream structure - // internal mapping of the zlib zstream structure for marshalling - [StructLayoutAttribute(LayoutKind.Sequential, Pack=4, Size=0, CharSet=CharSet.Ansi)] - internal struct ZStream - { - public IntPtr next_in; - public uint avail_in; - public uint total_in; - - public IntPtr next_out; - public uint avail_out; - public uint total_out; - - [MarshalAs(UnmanagedType.LPStr)] - string msg; - uint state; - - uint zalloc; - uint zfree; - uint opaque; - - int data_type; - public uint adler; - uint reserved; - } - - #endregion - - #endregion - - #region Public enums - /// - /// Defines constants for the available compression levels in zlib - /// - public enum CompressLevel : int - { - /// - /// The default compression level with a reasonable compromise between compression and speed - /// - Default = -1, - /// - /// No compression at all. The data are passed straight through. - /// - None = 0, - /// - /// The maximum compression rate available. - /// - Best = 9, - /// - /// The fastest available compression level. - /// - Fastest = 1 - } - #endregion - - #region Exception classes - /// - /// The exception that is thrown when an error occurs on the zlib dll - /// - public class ZLibException : ApplicationException - { - /// - /// Initializes a new instance of the class with a specified - /// error message and error code - /// - /// The zlib error code that caused the exception - /// A message that (hopefully) describes the error - public ZLibException(int errorCode, string msg) : base(String.Format("ZLib error {0} {1}", errorCode, msg)) - { - } - - /// - /// Initializes a new instance of the class with a specified - /// error code - /// - /// The zlib error code that caused the exception - public ZLibException(int errorCode) : base(String.Format("ZLib error {0}", errorCode)) - { - } - } - #endregion - - #region Interfaces - - /// - /// Declares methods and properties that enables a running checksum to be calculated - /// - public interface ChecksumGenerator - { - /// - /// Gets the current value of the checksum - /// - uint Value { get; } - - /// - /// Clears the current checksum to 0 - /// - void Reset(); - - /// - /// Updates the current checksum with an array of bytes - /// - /// The data to update the checksum with - void Update(byte[] data); - - /// - /// Updates the current checksum with part of an array of bytes - /// - /// The data to update the checksum with - /// Where in data to start updating - /// The number of bytes from data to use - /// The sum of offset and count is larger than the length of data - /// data is a null reference - /// Offset or count is negative. - void Update(byte[] data, int offset, int count); - - /// - /// Updates the current checksum with the data from a string - /// - /// The string to update the checksum with - /// The characters in the string are converted by the UTF-8 encoding - void Update(string data); - - /// - /// Updates the current checksum with the data from a string, using a specific encoding - /// - /// The string to update the checksum with - /// The encoding to use - void Update(string data, Encoding encoding); - } - - - /// - /// Represents the method that will be called from a codec when new data - /// are available. - /// - /// The byte array containing the processed data - /// The index of the first processed byte in data - /// The number of processed bytes available - /// On return from this method, the data may be overwritten, so grab it while you can. - /// You cannot assume that startIndex will be zero. - /// - public delegate void DataAvailableHandler(byte[] data, int startIndex, int count); - - /// - /// Declares methods and events for implementing compressors/decompressors - /// - public interface Codec - { - /// - /// Occurs when more processed data are available. - /// - event DataAvailableHandler DataAvailable; - - /// - /// Adds more data to the codec to be processed. - /// - /// Byte array containing the data to be added to the codec - /// Adding data may, or may not, raise the DataAvailable event - void Add(byte[] data); - - /// - /// Adds more data to the codec to be processed. - /// - /// Byte array containing the data to be added to the codec - /// The index of the first byte to add from data - /// The number of bytes to add - /// Adding data may, or may not, raise the DataAvailable event - void Add(byte[] data, int offset, int count); - - /// - /// Finishes up any pending data that needs to be processed and handled. - /// - void Finish(); - - /// - /// Gets the checksum of the data that has been added so far - /// - uint Checksum { get; } - - - } - - #endregion - - #region Classes - /// - /// Encapsulates general information about the ZLib library - /// - public class Info - { - #region DLL imports - [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] - private static extern uint zlibCompileFlags(); - - [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] - private static extern string zlibVersion(); - #endregion - - #region Private stuff - private uint _flags; - - // helper function that unpacks a bitsize mask - private static int bitSize(uint bits) - { - switch (bits) - { - case 0: return 16; - case 1: return 32; - case 2: return 64; - } - return -1; - } - #endregion - - /// - /// Constructs an instance of the Info class. - /// - public Info() - { - _flags = zlibCompileFlags(); - } - - /// - /// True if the library is compiled with debug info - /// - public bool HasDebugInfo { get { return 0 != (_flags & 0x100); } } - - /// - /// True if the library is compiled with assembly optimizations - /// - public bool UsesAssemblyCode { get { return 0 != (_flags & 0x200); } } - - /// - /// Gets the size of the unsigned int that was compiled into Zlib - /// - public int SizeOfUInt { get { return bitSize(_flags & 3); } } - - /// - /// Gets the size of the unsigned long that was compiled into Zlib - /// - public int SizeOfULong { get { return bitSize((_flags >> 2) & 3); } } - - /// - /// Gets the size of the pointers that were compiled into Zlib - /// - public int SizeOfPointer { get { return bitSize((_flags >> 4) & 3); } } - - /// - /// Gets the size of the z_off_t type that was compiled into Zlib - /// - public int SizeOfOffset { get { return bitSize((_flags >> 6) & 3); } } - - /// - /// Gets the version of ZLib as a string, e.g. "1.2.1" - /// - public static string Version { get { return zlibVersion(); } } - } - - #endregion - -} diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib/DotZLib.csproj b/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib/DotZLib.csproj deleted file mode 100644 index dea7fb16a94..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib/DotZLib.csproj +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib/GZipStream.cs b/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib/GZipStream.cs deleted file mode 100644 index f0eada1d24b..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib/GZipStream.cs +++ /dev/null @@ -1,301 +0,0 @@ -// -// © Copyright Henrik Ravn 2004 -// -// Use, modification and distribution are subject to 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) -// - -using System; -using System.IO; -using System.Runtime.InteropServices; - -namespace DotZLib -{ - /// - /// Implements a compressed , in GZip (.gz) format. - /// - public class GZipStream : Stream, IDisposable - { - #region Dll Imports - [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl, CharSet=CharSet.Ansi)] - private static extern IntPtr gzopen(string name, string mode); - - [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] - private static extern int gzclose(IntPtr gzFile); - - [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] - private static extern int gzwrite(IntPtr gzFile, int data, int length); - - [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] - private static extern int gzread(IntPtr gzFile, int data, int length); - - [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] - private static extern int gzgetc(IntPtr gzFile); - - [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] - private static extern int gzputc(IntPtr gzFile, int c); - - #endregion - - #region Private data - private IntPtr _gzFile; - private bool _isDisposed = false; - private bool _isWriting; - #endregion - - #region Constructors - /// - /// Creates a new file as a writeable GZipStream - /// - /// The name of the compressed file to create - /// The compression level to use when adding data - /// If an error occurred in the internal zlib function - public GZipStream(string fileName, CompressLevel level) - { - _isWriting = true; - _gzFile = gzopen(fileName, String.Format("wb{0}", (int)level)); - if (_gzFile == IntPtr.Zero) - throw new ZLibException(-1, "Could not open " + fileName); - } - - /// - /// Opens an existing file as a readable GZipStream - /// - /// The name of the file to open - /// If an error occurred in the internal zlib function - public GZipStream(string fileName) - { - _isWriting = false; - _gzFile = gzopen(fileName, "rb"); - if (_gzFile == IntPtr.Zero) - throw new ZLibException(-1, "Could not open " + fileName); - - } - #endregion - - #region Access properties - /// - /// Returns true of this stream can be read from, false otherwise - /// - public override bool CanRead - { - get - { - return !_isWriting; - } - } - - - /// - /// Returns false. - /// - public override bool CanSeek - { - get - { - return false; - } - } - - /// - /// Returns true if this tsream is writeable, false otherwise - /// - public override bool CanWrite - { - get - { - return _isWriting; - } - } - #endregion - - #region Destructor & IDispose stuff - - /// - /// Destroys this instance - /// - ~GZipStream() - { - cleanUp(false); - } - - /// - /// Closes the external file handle - /// - public void Dispose() - { - cleanUp(true); - } - - // Does the actual closing of the file handle. - private void cleanUp(bool isDisposing) - { - if (!_isDisposed) - { - gzclose(_gzFile); - _isDisposed = true; - } - } - #endregion - - #region Basic reading and writing - /// - /// Attempts to read a number of bytes from the stream. - /// - /// The destination data buffer - /// The index of the first destination byte in buffer - /// The number of bytes requested - /// The number of bytes read - /// If buffer is null - /// If count or offset are negative - /// If offset + count is > buffer.Length - /// If this stream is not readable. - /// If this stream has been disposed. - public override int Read(byte[] buffer, int offset, int count) - { - if (!CanRead) throw new NotSupportedException(); - if (buffer == null) throw new ArgumentNullException(); - if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException(); - if ((offset+count) > buffer.Length) throw new ArgumentException(); - if (_isDisposed) throw new ObjectDisposedException("GZipStream"); - - GCHandle h = GCHandle.Alloc(buffer, GCHandleType.Pinned); - int result; - try - { - result = gzread(_gzFile, h.AddrOfPinnedObject().ToInt32() + offset, count); - if (result < 0) - throw new IOException(); - } - finally - { - h.Free(); - } - return result; - } - - /// - /// Attempts to read a single byte from the stream. - /// - /// The byte that was read, or -1 in case of error or End-Of-File - public override int ReadByte() - { - if (!CanRead) throw new NotSupportedException(); - if (_isDisposed) throw new ObjectDisposedException("GZipStream"); - return gzgetc(_gzFile); - } - - /// - /// Writes a number of bytes to the stream - /// - /// - /// - /// - /// If buffer is null - /// If count or offset are negative - /// If offset + count is > buffer.Length - /// If this stream is not writeable. - /// If this stream has been disposed. - public override void Write(byte[] buffer, int offset, int count) - { - if (!CanWrite) throw new NotSupportedException(); - if (buffer == null) throw new ArgumentNullException(); - if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException(); - if ((offset+count) > buffer.Length) throw new ArgumentException(); - if (_isDisposed) throw new ObjectDisposedException("GZipStream"); - - GCHandle h = GCHandle.Alloc(buffer, GCHandleType.Pinned); - try - { - int result = gzwrite(_gzFile, h.AddrOfPinnedObject().ToInt32() + offset, count); - if (result < 0) - throw new IOException(); - } - finally - { - h.Free(); - } - } - - /// - /// Writes a single byte to the stream - /// - /// The byte to add to the stream. - /// If this stream is not writeable. - /// If this stream has been disposed. - public override void WriteByte(byte value) - { - if (!CanWrite) throw new NotSupportedException(); - if (_isDisposed) throw new ObjectDisposedException("GZipStream"); - - int result = gzputc(_gzFile, (int)value); - if (result < 0) - throw new IOException(); - } - #endregion - - #region Position & length stuff - /// - /// Not supported. - /// - /// - /// Always thrown - public override void SetLength(long value) - { - throw new NotSupportedException(); - } - - /// - /// Not suppported. - /// - /// - /// - /// - /// Always thrown - public override long Seek(long offset, SeekOrigin origin) - { - throw new NotSupportedException(); - } - - /// - /// Flushes the GZipStream. - /// - /// In this implementation, this method does nothing. This is because excessive - /// flushing may degrade the achievable compression rates. - public override void Flush() - { - // left empty on purpose - } - - /// - /// Gets/sets the current position in the GZipStream. Not suppported. - /// - /// In this implementation this property is not supported - /// Always thrown - public override long Position - { - get - { - throw new NotSupportedException(); - } - set - { - throw new NotSupportedException(); - } - } - - /// - /// Gets the size of the stream. Not suppported. - /// - /// In this implementation this property is not supported - /// Always thrown - public override long Length - { - get - { - throw new NotSupportedException(); - } - } - #endregion - } -} diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib/Inflater.cs b/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib/Inflater.cs deleted file mode 100644 index d295f268048..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib/Inflater.cs +++ /dev/null @@ -1,105 +0,0 @@ -// -// © Copyright Henrik Ravn 2004 -// -// Use, modification and distribution are subject to 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) -// - -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; - -namespace DotZLib -{ - - /// - /// Implements a data decompressor, using the inflate algorithm in the ZLib dll - /// - public class Inflater : CodecBase - { - #region Dll imports - [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl, CharSet=CharSet.Ansi)] - private static extern int inflateInit_(ref ZStream sz, string vs, int size); - - [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] - private static extern int inflate(ref ZStream sz, int flush); - - [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] - private static extern int inflateReset(ref ZStream sz); - - [DllImport("ZLIB1.dll", CallingConvention=CallingConvention.Cdecl)] - private static extern int inflateEnd(ref ZStream sz); - #endregion - - /// - /// Constructs an new instance of the Inflater - /// - public Inflater() : base() - { - int retval = inflateInit_(ref _ztream, Info.Version, Marshal.SizeOf(_ztream)); - if (retval != 0) - throw new ZLibException(retval, "Could not initialize inflater"); - - resetOutput(); - } - - - /// - /// Adds more data to the codec to be processed. - /// - /// Byte array containing the data to be added to the codec - /// The index of the first byte to add from data - /// The number of bytes to add - /// Adding data may, or may not, raise the DataAvailable event - public override void Add(byte[] data, int offset, int count) - { - if (data == null) throw new ArgumentNullException(); - if (offset < 0 || count < 0) throw new ArgumentOutOfRangeException(); - if ((offset+count) > data.Length) throw new ArgumentException(); - - int total = count; - int inputIndex = offset; - int err = 0; - - while (err >= 0 && inputIndex < total) - { - copyInput(data, inputIndex, Math.Min(total - inputIndex, kBufferSize)); - err = inflate(ref _ztream, (int)FlushTypes.None); - if (err == 0) - while (_ztream.avail_out == 0) - { - OnDataAvailable(); - err = inflate(ref _ztream, (int)FlushTypes.None); - } - - inputIndex += (int)_ztream.total_in; - } - setChecksum( _ztream.adler ); - } - - - /// - /// Finishes up any pending data that needs to be processed and handled. - /// - public override void Finish() - { - int err; - do - { - err = inflate(ref _ztream, (int)FlushTypes.Finish); - OnDataAvailable(); - } - while (err == 0); - setChecksum( _ztream.adler ); - inflateReset(ref _ztream); - resetOutput(); - } - - /// - /// Closes the internal zlib inflate stream - /// - protected override void CleanUp() { inflateEnd(ref _ztream); } - - - } -} diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib/UnitTests.cs b/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib/UnitTests.cs deleted file mode 100644 index 15394614054..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/DotZLib/UnitTests.cs +++ /dev/null @@ -1,274 +0,0 @@ -// -// © Copyright Henrik Ravn 2004 -// -// Use, modification and distribution are subject to 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) -// - -using System; -using System.Collections; -using System.IO; - -// uncomment the define below to include unit tests -//#define nunit -#if nunit -using NUnit.Framework; - -// Unit tests for the DotZLib class library -// ---------------------------------------- -// -// Use this with NUnit 2 from http://www.nunit.org -// - -namespace DotZLibTests -{ - using DotZLib; - - // helper methods - internal class Utils - { - public static bool byteArrEqual( byte[] lhs, byte[] rhs ) - { - if (lhs.Length != rhs.Length) - return false; - for (int i = lhs.Length-1; i >= 0; --i) - if (lhs[i] != rhs[i]) - return false; - return true; - } - - } - - - [TestFixture] - public class CircBufferTests - { - #region Circular buffer tests - [Test] - public void SinglePutGet() - { - CircularBuffer buf = new CircularBuffer(10); - Assert.AreEqual( 0, buf.Size ); - Assert.AreEqual( -1, buf.Get() ); - - Assert.IsTrue(buf.Put( 1 )); - Assert.AreEqual( 1, buf.Size ); - Assert.AreEqual( 1, buf.Get() ); - Assert.AreEqual( 0, buf.Size ); - Assert.AreEqual( -1, buf.Get() ); - } - - [Test] - public void BlockPutGet() - { - CircularBuffer buf = new CircularBuffer(10); - byte[] arr = {1,2,3,4,5,6,7,8,9,10}; - Assert.AreEqual( 10, buf.Put(arr,0,10) ); - Assert.AreEqual( 10, buf.Size ); - Assert.IsFalse( buf.Put(11) ); - Assert.AreEqual( 1, buf.Get() ); - Assert.IsTrue( buf.Put(11) ); - - byte[] arr2 = (byte[])arr.Clone(); - Assert.AreEqual( 9, buf.Get(arr2,1,9) ); - Assert.IsTrue( Utils.byteArrEqual(arr,arr2) ); - } - - #endregion - } - - [TestFixture] - public class ChecksumTests - { - #region CRC32 Tests - [Test] - public void CRC32_Null() - { - CRC32Checksum crc32 = new CRC32Checksum(); - Assert.AreEqual( 0, crc32.Value ); - - crc32 = new CRC32Checksum(1); - Assert.AreEqual( 1, crc32.Value ); - - crc32 = new CRC32Checksum(556); - Assert.AreEqual( 556, crc32.Value ); - } - - [Test] - public void CRC32_Data() - { - CRC32Checksum crc32 = new CRC32Checksum(); - byte[] data = { 1,2,3,4,5,6,7 }; - crc32.Update(data); - Assert.AreEqual( 0x70e46888, crc32.Value ); - - crc32 = new CRC32Checksum(); - crc32.Update("penguin"); - Assert.AreEqual( 0x0e5c1a120, crc32.Value ); - - crc32 = new CRC32Checksum(1); - crc32.Update("penguin"); - Assert.AreEqual(0x43b6aa94, crc32.Value); - - } - #endregion - - #region Adler tests - - [Test] - public void Adler_Null() - { - AdlerChecksum adler = new AdlerChecksum(); - Assert.AreEqual(0, adler.Value); - - adler = new AdlerChecksum(1); - Assert.AreEqual( 1, adler.Value ); - - adler = new AdlerChecksum(556); - Assert.AreEqual( 556, adler.Value ); - } - - [Test] - public void Adler_Data() - { - AdlerChecksum adler = new AdlerChecksum(1); - byte[] data = { 1,2,3,4,5,6,7 }; - adler.Update(data); - Assert.AreEqual( 0x5b001d, adler.Value ); - - adler = new AdlerChecksum(); - adler.Update("penguin"); - Assert.AreEqual(0x0bcf02f6, adler.Value ); - - adler = new AdlerChecksum(1); - adler.Update("penguin"); - Assert.AreEqual(0x0bd602f7, adler.Value); - - } - #endregion - } - - [TestFixture] - public class InfoTests - { - #region Info tests - [Test] - public void Info_Version() - { - Info info = new Info(); - Assert.AreEqual("1.2.8", Info.Version); - Assert.AreEqual(32, info.SizeOfUInt); - Assert.AreEqual(32, info.SizeOfULong); - Assert.AreEqual(32, info.SizeOfPointer); - Assert.AreEqual(32, info.SizeOfOffset); - } - #endregion - } - - [TestFixture] - public class DeflateInflateTests - { - #region Deflate tests - [Test] - public void Deflate_Init() - { - using (Deflater def = new Deflater(CompressLevel.Default)) - { - } - } - - private ArrayList compressedData = new ArrayList(); - private uint adler1; - - private ArrayList uncompressedData = new ArrayList(); - private uint adler2; - - public void CDataAvail(byte[] data, int startIndex, int count) - { - for (int i = 0; i < count; ++i) - compressedData.Add(data[i+startIndex]); - } - - [Test] - public void Deflate_Compress() - { - compressedData.Clear(); - - byte[] testData = new byte[35000]; - for (int i = 0; i < testData.Length; ++i) - testData[i] = 5; - - using (Deflater def = new Deflater((CompressLevel)5)) - { - def.DataAvailable += new DataAvailableHandler(CDataAvail); - def.Add(testData); - def.Finish(); - adler1 = def.Checksum; - } - } - #endregion - - #region Inflate tests - [Test] - public void Inflate_Init() - { - using (Inflater inf = new Inflater()) - { - } - } - - private void DDataAvail(byte[] data, int startIndex, int count) - { - for (int i = 0; i < count; ++i) - uncompressedData.Add(data[i+startIndex]); - } - - [Test] - public void Inflate_Expand() - { - uncompressedData.Clear(); - - using (Inflater inf = new Inflater()) - { - inf.DataAvailable += new DataAvailableHandler(DDataAvail); - inf.Add((byte[])compressedData.ToArray(typeof(byte))); - inf.Finish(); - adler2 = inf.Checksum; - } - Assert.AreEqual( adler1, adler2 ); - } - #endregion - } - - [TestFixture] - public class GZipStreamTests - { - #region GZipStream test - [Test] - public void GZipStream_WriteRead() - { - using (GZipStream gzOut = new GZipStream("gzstream.gz", CompressLevel.Best)) - { - BinaryWriter writer = new BinaryWriter(gzOut); - writer.Write("hi there"); - writer.Write(Math.PI); - writer.Write(42); - } - - using (GZipStream gzIn = new GZipStream("gzstream.gz")) - { - BinaryReader reader = new BinaryReader(gzIn); - string s = reader.ReadString(); - Assert.AreEqual("hi there",s); - double d = reader.ReadDouble(); - Assert.AreEqual(Math.PI, d); - int i = reader.ReadInt32(); - Assert.AreEqual(42,i); - } - - } - #endregion - } -} - -#endif diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/LICENSE_1_0.txt b/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/LICENSE_1_0.txt deleted file mode 100644 index 127a5bc39ba..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/LICENSE_1_0.txt +++ /dev/null @@ -1,23 +0,0 @@ -Boost Software License - Version 1.0 - August 17th, 2003 - -Permission is hereby granted, free of charge, to any person or organization -obtaining a copy of the software and accompanying documentation covered by -this license (the "Software") to use, reproduce, display, distribute, -execute, and transmit the Software, and to prepare derivative works of the -Software, and to permit third-parties to whom the Software is furnished to -do so, all subject to the following: - -The copyright notices in the Software and this entire statement, including -the above license grant, this restriction and the following disclaimer, -must be included in all copies of the Software, in whole or in part, and -all derivative works of the Software, unless such copies or derivative -works are solely in the form of machine-executable object code generated by -a source language processor. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/readme.txt b/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/readme.txt deleted file mode 100644 index 4d8c2dd9324..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/dotzlib/readme.txt +++ /dev/null @@ -1,58 +0,0 @@ -This directory contains a .Net wrapper class library for the ZLib1.dll - -The wrapper includes support for inflating/deflating memory buffers, -.Net streaming wrappers for the gz streams part of zlib, and wrappers -for the checksum parts of zlib. See DotZLib/UnitTests.cs for examples. - -Directory structure: --------------------- - -LICENSE_1_0.txt - License file. -readme.txt - This file. -DotZLib.chm - Class library documentation -DotZLib.build - NAnt build file -DotZLib.sln - Microsoft Visual Studio 2003 solution file - -DotZLib\*.cs - Source files for the class library - -Unit tests: ------------ -The file DotZLib/UnitTests.cs contains unit tests for use with NUnit 2.1 or higher. -To include unit tests in the build, define nunit before building. - - -Build instructions: -------------------- - -1. Using Visual Studio.Net 2003: - Open DotZLib.sln in VS.Net and build from there. Output file (DotZLib.dll) - will be found ./DotZLib/bin/release or ./DotZLib/bin/debug, depending on - you are building the release or debug version of the library. Check - DotZLib/UnitTests.cs for instructions on how to include unit tests in the - build. - -2. Using NAnt: - Open a command prompt with access to the build environment and run nant - in the same directory as the DotZLib.build file. - You can define 2 properties on the nant command-line to control the build: - debug={true|false} to toggle between release/debug builds (default=true). - nunit={true|false} to include or esclude unit tests (default=true). - Also the target clean will remove binaries. - Output file (DotZLib.dll) will be found in either ./DotZLib/bin/release - or ./DotZLib/bin/debug, depending on whether you are building the release - or debug version of the library. - - Examples: - nant -D:debug=false -D:nunit=false - will build a release mode version of the library without unit tests. - nant - will build a debug version of the library with unit tests - nant clean - will remove all previously built files. - - ---------------------------------- -Copyright (c) Henrik Ravn 2004 - -Use, modification and distribution are subject to 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) diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/gcc_gvmat64/gvmat64.S b/src/beast/test/zlib/zlib-1.2.8/contrib/gcc_gvmat64/gvmat64.S deleted file mode 100644 index 23309fa286e..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/gcc_gvmat64/gvmat64.S +++ /dev/null @@ -1,574 +0,0 @@ -/* -;uInt longest_match_x64( -; deflate_state *s, -; IPos cur_match); // current match - -; gvmat64.S -- Asm portion of the optimized longest_match for 32 bits x86_64 -; (AMD64 on Athlon 64, Opteron, Phenom -; and Intel EM64T on Pentium 4 with EM64T, Pentium D, Core 2 Duo, Core I5/I7) -; this file is translation from gvmat64.asm to GCC 4.x (for Linux, Mac XCode) -; Copyright (C) 1995-2010 Jean-loup Gailly, Brian Raiter and Gilles Vollant. -; -; File written by Gilles Vollant, by converting to assembly the longest_match -; from Jean-loup Gailly in deflate.c of zLib and infoZip zip. -; and by taking inspiration on asm686 with masm, optimised assembly code -; from Brian Raiter, written 1998 -; -; This software is provided 'as-is', without any express or implied -; warranty. In no event will the authors be held liable for any damages -; arising from the use of this software. -; -; Permission is granted to anyone to use this software for any purpose, -; including commercial applications, and to alter it and redistribute it -; freely, subject to the following restrictions: -; -; 1. The origin of this software must not be misrepresented; you must not -; claim that you wrote the original software. If you use this software -; in a product, an acknowledgment in the product documentation would be -; appreciated but is not required. -; 2. Altered source versions must be plainly marked as such, and must not be -; misrepresented as being the original software -; 3. This notice may not be removed or altered from any source distribution. -; -; http://www.zlib.net -; http://www.winimage.com/zLibDll -; http://www.muppetlabs.com/~breadbox/software/assembly.html -; -; to compile this file for zLib, I use option: -; gcc -c -arch x86_64 gvmat64.S - - -;uInt longest_match(s, cur_match) -; deflate_state *s; -; IPos cur_match; // current match / -; -; with XCode for Mac, I had strange error with some jump on intel syntax -; this is why BEFORE_JMP and AFTER_JMP are used - */ - - -#define BEFORE_JMP .att_syntax -#define AFTER_JMP .intel_syntax noprefix - -#ifndef NO_UNDERLINE -# define match_init _match_init -# define longest_match _longest_match -#endif - -.intel_syntax noprefix - -.globl match_init, longest_match -.text -longest_match: - - - -#define LocalVarsSize 96 -/* -; register used : rax,rbx,rcx,rdx,rsi,rdi,r8,r9,r10,r11,r12 -; free register : r14,r15 -; register can be saved : rsp -*/ - -#define chainlenwmask (rsp + 8 - LocalVarsSize) -#define nicematch (rsp + 16 - LocalVarsSize) - -#define save_rdi (rsp + 24 - LocalVarsSize) -#define save_rsi (rsp + 32 - LocalVarsSize) -#define save_rbx (rsp + 40 - LocalVarsSize) -#define save_rbp (rsp + 48 - LocalVarsSize) -#define save_r12 (rsp + 56 - LocalVarsSize) -#define save_r13 (rsp + 64 - LocalVarsSize) -#define save_r14 (rsp + 72 - LocalVarsSize) -#define save_r15 (rsp + 80 - LocalVarsSize) - - -/* -; all the +4 offsets are due to the addition of pending_buf_size (in zlib -; in the deflate_state structure since the asm code was first written -; (if you compile with zlib 1.0.4 or older, remove the +4). -; Note : these value are good with a 8 bytes boundary pack structure -*/ - -#define MAX_MATCH 258 -#define MIN_MATCH 3 -#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) - -/* -;;; Offsets for fields in the deflate_state structure. These numbers -;;; are calculated from the definition of deflate_state, with the -;;; assumption that the compiler will dword-align the fields. (Thus, -;;; changing the definition of deflate_state could easily cause this -;;; program to crash horribly, without so much as a warning at -;;; compile time. Sigh.) - -; all the +zlib1222add offsets are due to the addition of fields -; in zlib in the deflate_state structure since the asm code was first written -; (if you compile with zlib 1.0.4 or older, use "zlib1222add equ (-4)"). -; (if you compile with zlib between 1.0.5 and 1.2.2.1, use "zlib1222add equ 0"). -; if you compile with zlib 1.2.2.2 or later , use "zlib1222add equ 8"). -*/ - - - -/* you can check the structure offset by running - -#include -#include -#include "deflate.h" - -void print_depl() -{ -deflate_state ds; -deflate_state *s=&ds; -printf("size pointer=%u\n",(int)sizeof(void*)); - -printf("#define dsWSize %u\n",(int)(((char*)&(s->w_size))-((char*)s))); -printf("#define dsWMask %u\n",(int)(((char*)&(s->w_mask))-((char*)s))); -printf("#define dsWindow %u\n",(int)(((char*)&(s->window))-((char*)s))); -printf("#define dsPrev %u\n",(int)(((char*)&(s->prev))-((char*)s))); -printf("#define dsMatchLen %u\n",(int)(((char*)&(s->match_length))-((char*)s))); -printf("#define dsPrevMatch %u\n",(int)(((char*)&(s->prev_match))-((char*)s))); -printf("#define dsStrStart %u\n",(int)(((char*)&(s->strstart))-((char*)s))); -printf("#define dsMatchStart %u\n",(int)(((char*)&(s->match_start))-((char*)s))); -printf("#define dsLookahead %u\n",(int)(((char*)&(s->lookahead))-((char*)s))); -printf("#define dsPrevLen %u\n",(int)(((char*)&(s->prev_length))-((char*)s))); -printf("#define dsMaxChainLen %u\n",(int)(((char*)&(s->max_chain_length))-((char*)s))); -printf("#define dsGoodMatch %u\n",(int)(((char*)&(s->good_match))-((char*)s))); -printf("#define dsNiceMatch %u\n",(int)(((char*)&(s->nice_match))-((char*)s))); -} -*/ - -#define dsWSize 68 -#define dsWMask 76 -#define dsWindow 80 -#define dsPrev 96 -#define dsMatchLen 144 -#define dsPrevMatch 148 -#define dsStrStart 156 -#define dsMatchStart 160 -#define dsLookahead 164 -#define dsPrevLen 168 -#define dsMaxChainLen 172 -#define dsGoodMatch 188 -#define dsNiceMatch 192 - -#define window_size [ rcx + dsWSize] -#define WMask [ rcx + dsWMask] -#define window_ad [ rcx + dsWindow] -#define prev_ad [ rcx + dsPrev] -#define strstart [ rcx + dsStrStart] -#define match_start [ rcx + dsMatchStart] -#define Lookahead [ rcx + dsLookahead] //; 0ffffffffh on infozip -#define prev_length [ rcx + dsPrevLen] -#define max_chain_length [ rcx + dsMaxChainLen] -#define good_match [ rcx + dsGoodMatch] -#define nice_match [ rcx + dsNiceMatch] - -/* -; windows: -; parameter 1 in rcx(deflate state s), param 2 in rdx (cur match) - -; see http://weblogs.asp.net/oldnewthing/archive/2004/01/14/58579.aspx and -; http://msdn.microsoft.com/library/en-us/kmarch/hh/kmarch/64bitAMD_8e951dd2-ee77-4728-8702-55ce4b5dd24a.xml.asp -; -; All registers must be preserved across the call, except for -; rax, rcx, rdx, r8, r9, r10, and r11, which are scratch. - -; -; gcc on macosx-linux: -; see http://www.x86-64.org/documentation/abi-0.99.pdf -; param 1 in rdi, param 2 in rsi -; rbx, rsp, rbp, r12 to r15 must be preserved - -;;; Save registers that the compiler may be using, and adjust esp to -;;; make room for our stack frame. - - -;;; Retrieve the function arguments. r8d will hold cur_match -;;; throughout the entire function. edx will hold the pointer to the -;;; deflate_state structure during the function's setup (before -;;; entering the main loop. - -; ms: parameter 1 in rcx (deflate_state* s), param 2 in edx -> r8 (cur match) -; mac: param 1 in rdi, param 2 rsi -; this clear high 32 bits of r8, which can be garbage in both r8 and rdx -*/ - mov [save_rbx],rbx - mov [save_rbp],rbp - - - mov rcx,rdi - - mov r8d,esi - - - mov [save_r12],r12 - mov [save_r13],r13 - mov [save_r14],r14 - mov [save_r15],r15 - - -//;;; uInt wmask = s->w_mask; -//;;; unsigned chain_length = s->max_chain_length; -//;;; if (s->prev_length >= s->good_match) { -//;;; chain_length >>= 2; -//;;; } - - - mov edi, prev_length - mov esi, good_match - mov eax, WMask - mov ebx, max_chain_length - cmp edi, esi - jl LastMatchGood - shr ebx, 2 -LastMatchGood: - -//;;; chainlen is decremented once beforehand so that the function can -//;;; use the sign flag instead of the zero flag for the exit test. -//;;; It is then shifted into the high word, to make room for the wmask -//;;; value, which it will always accompany. - - dec ebx - shl ebx, 16 - or ebx, eax - -//;;; on zlib only -//;;; if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; - - - - mov eax, nice_match - mov [chainlenwmask], ebx - mov r10d, Lookahead - cmp r10d, eax - cmovnl r10d, eax - mov [nicematch],r10d - - - -//;;; register Bytef *scan = s->window + s->strstart; - mov r10, window_ad - mov ebp, strstart - lea r13, [r10 + rbp] - -//;;; Determine how many bytes the scan ptr is off from being -//;;; dword-aligned. - - mov r9,r13 - neg r13 - and r13,3 - -//;;; IPos limit = s->strstart > (IPos)MAX_DIST(s) ? -//;;; s->strstart - (IPos)MAX_DIST(s) : NIL; - - - mov eax, window_size - sub eax, MIN_LOOKAHEAD - - - xor edi,edi - sub ebp, eax - - mov r11d, prev_length - - cmovng ebp,edi - -//;;; int best_len = s->prev_length; - - -//;;; Store the sum of s->window + best_len in esi locally, and in esi. - - lea rsi,[r10+r11] - -//;;; register ush scan_start = *(ushf*)scan; -//;;; register ush scan_end = *(ushf*)(scan+best_len-1); -//;;; Posf *prev = s->prev; - - movzx r12d,word ptr [r9] - movzx ebx, word ptr [r9 + r11 - 1] - - mov rdi, prev_ad - -//;;; Jump into the main loop. - - mov edx, [chainlenwmask] - - cmp bx,word ptr [rsi + r8 - 1] - jz LookupLoopIsZero - - - -LookupLoop1: - and r8d, edx - - movzx r8d, word ptr [rdi + r8*2] - cmp r8d, ebp - jbe LeaveNow - - - - sub edx, 0x00010000 - BEFORE_JMP - js LeaveNow - AFTER_JMP - -LoopEntry1: - cmp bx,word ptr [rsi + r8 - 1] - BEFORE_JMP - jz LookupLoopIsZero - AFTER_JMP - -LookupLoop2: - and r8d, edx - - movzx r8d, word ptr [rdi + r8*2] - cmp r8d, ebp - BEFORE_JMP - jbe LeaveNow - AFTER_JMP - sub edx, 0x00010000 - BEFORE_JMP - js LeaveNow - AFTER_JMP - -LoopEntry2: - cmp bx,word ptr [rsi + r8 - 1] - BEFORE_JMP - jz LookupLoopIsZero - AFTER_JMP - -LookupLoop4: - and r8d, edx - - movzx r8d, word ptr [rdi + r8*2] - cmp r8d, ebp - BEFORE_JMP - jbe LeaveNow - AFTER_JMP - sub edx, 0x00010000 - BEFORE_JMP - js LeaveNow - AFTER_JMP - -LoopEntry4: - - cmp bx,word ptr [rsi + r8 - 1] - BEFORE_JMP - jnz LookupLoop1 - jmp LookupLoopIsZero - AFTER_JMP -/* -;;; do { -;;; match = s->window + cur_match; -;;; if (*(ushf*)(match+best_len-1) != scan_end || -;;; *(ushf*)match != scan_start) continue; -;;; [...] -;;; } while ((cur_match = prev[cur_match & wmask]) > limit -;;; && --chain_length != 0); -;;; -;;; Here is the inner loop of the function. The function will spend the -;;; majority of its time in this loop, and majority of that time will -;;; be spent in the first ten instructions. -;;; -;;; Within this loop: -;;; ebx = scanend -;;; r8d = curmatch -;;; edx = chainlenwmask - i.e., ((chainlen << 16) | wmask) -;;; esi = windowbestlen - i.e., (window + bestlen) -;;; edi = prev -;;; ebp = limit -*/ -.balign 16 -LookupLoop: - and r8d, edx - - movzx r8d, word ptr [rdi + r8*2] - cmp r8d, ebp - BEFORE_JMP - jbe LeaveNow - AFTER_JMP - sub edx, 0x00010000 - BEFORE_JMP - js LeaveNow - AFTER_JMP - -LoopEntry: - - cmp bx,word ptr [rsi + r8 - 1] - BEFORE_JMP - jnz LookupLoop1 - AFTER_JMP -LookupLoopIsZero: - cmp r12w, word ptr [r10 + r8] - BEFORE_JMP - jnz LookupLoop1 - AFTER_JMP - - -//;;; Store the current value of chainlen. - mov [chainlenwmask], edx -/* -;;; Point edi to the string under scrutiny, and esi to the string we -;;; are hoping to match it up with. In actuality, esi and edi are -;;; both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and edx is -;;; initialized to -(MAX_MATCH_8 - scanalign). -*/ - lea rsi,[r8+r10] - mov rdx, 0xfffffffffffffef8 //; -(MAX_MATCH_8) - lea rsi, [rsi + r13 + 0x0108] //;MAX_MATCH_8] - lea rdi, [r9 + r13 + 0x0108] //;MAX_MATCH_8] - - prefetcht1 [rsi+rdx] - prefetcht1 [rdi+rdx] - -/* -;;; Test the strings for equality, 8 bytes at a time. At the end, -;;; adjust rdx so that it is offset to the exact byte that mismatched. -;;; -;;; We already know at this point that the first three bytes of the -;;; strings match each other, and they can be safely passed over before -;;; starting the compare loop. So what this code does is skip over 0-3 -;;; bytes, as much as necessary in order to dword-align the edi -;;; pointer. (rsi will still be misaligned three times out of four.) -;;; -;;; It should be confessed that this loop usually does not represent -;;; much of the total running time. Replacing it with a more -;;; straightforward "rep cmpsb" would not drastically degrade -;;; performance. -*/ - -LoopCmps: - mov rax, [rsi + rdx] - xor rax, [rdi + rdx] - jnz LeaveLoopCmps - - mov rax, [rsi + rdx + 8] - xor rax, [rdi + rdx + 8] - jnz LeaveLoopCmps8 - - - mov rax, [rsi + rdx + 8+8] - xor rax, [rdi + rdx + 8+8] - jnz LeaveLoopCmps16 - - add rdx,8+8+8 - - BEFORE_JMP - jnz LoopCmps - jmp LenMaximum - AFTER_JMP - -LeaveLoopCmps16: add rdx,8 -LeaveLoopCmps8: add rdx,8 -LeaveLoopCmps: - - test eax, 0x0000FFFF - jnz LenLower - - test eax,0xffffffff - - jnz LenLower32 - - add rdx,4 - shr rax,32 - or ax,ax - BEFORE_JMP - jnz LenLower - AFTER_JMP - -LenLower32: - shr eax,16 - add rdx,2 - -LenLower: - sub al, 1 - adc rdx, 0 -//;;; Calculate the length of the match. If it is longer than MAX_MATCH, -//;;; then automatically accept it as the best possible match and leave. - - lea rax, [rdi + rdx] - sub rax, r9 - cmp eax, MAX_MATCH - BEFORE_JMP - jge LenMaximum - AFTER_JMP -/* -;;; If the length of the match is not longer than the best match we -;;; have so far, then forget it and return to the lookup loop. -;/////////////////////////////////// -*/ - cmp eax, r11d - jg LongerMatch - - lea rsi,[r10+r11] - - mov rdi, prev_ad - mov edx, [chainlenwmask] - BEFORE_JMP - jmp LookupLoop - AFTER_JMP -/* -;;; s->match_start = cur_match; -;;; best_len = len; -;;; if (len >= nice_match) break; -;;; scan_end = *(ushf*)(scan+best_len-1); -*/ -LongerMatch: - mov r11d, eax - mov match_start, r8d - cmp eax, [nicematch] - BEFORE_JMP - jge LeaveNow - AFTER_JMP - - lea rsi,[r10+rax] - - movzx ebx, word ptr [r9 + rax - 1] - mov rdi, prev_ad - mov edx, [chainlenwmask] - BEFORE_JMP - jmp LookupLoop - AFTER_JMP - -//;;; Accept the current string, with the maximum possible length. - -LenMaximum: - mov r11d,MAX_MATCH - mov match_start, r8d - -//;;; if ((uInt)best_len <= s->lookahead) return (uInt)best_len; -//;;; return s->lookahead; - -LeaveNow: - mov eax, Lookahead - cmp r11d, eax - cmovng eax, r11d - - - -//;;; Restore the stack and return from whence we came. - - -// mov rsi,[save_rsi] -// mov rdi,[save_rdi] - mov rbx,[save_rbx] - mov rbp,[save_rbp] - mov r12,[save_r12] - mov r13,[save_r13] - mov r14,[save_r14] - mov r15,[save_r15] - - - ret 0 -//; please don't remove this string ! -//; Your can freely use gvmat64 in any free or commercial app -//; but it is far better don't remove the string in the binary! - // db 0dh,0ah,"asm686 with masm, optimised assembly code from Brian Raiter, written 1998, converted to amd 64 by Gilles Vollant 2005",0dh,0ah,0 - - -match_init: - ret 0 - - diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/infback9/README b/src/beast/test/zlib/zlib-1.2.8/contrib/infback9/README deleted file mode 100644 index e75ed132948..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/infback9/README +++ /dev/null @@ -1 +0,0 @@ -See infback9.h for what this is and how to use it. diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/infback9/infback9.c b/src/beast/test/zlib/zlib-1.2.8/contrib/infback9/infback9.c deleted file mode 100644 index 05fb3e33807..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/infback9/infback9.c +++ /dev/null @@ -1,615 +0,0 @@ -/* infback9.c -- inflate deflate64 data using a call-back interface - * Copyright (C) 1995-2008 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#include "zutil.h" -#include "infback9.h" -#include "inftree9.h" -#include "inflate9.h" - -#define WSIZE 65536UL - -/* - strm provides memory allocation functions in zalloc and zfree, or - Z_NULL to use the library memory allocation functions. - - window is a user-supplied window and output buffer that is 64K bytes. - */ -int ZEXPORT inflateBack9Init_(strm, window, version, stream_size) -z_stream FAR *strm; -unsigned char FAR *window; -const char *version; -int stream_size; -{ - struct inflate_state FAR *state; - - if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || - stream_size != (int)(sizeof(z_stream))) - return Z_VERSION_ERROR; - if (strm == Z_NULL || window == Z_NULL) - return Z_STREAM_ERROR; - strm->msg = Z_NULL; /* in case we return an error */ - if (strm->zalloc == (alloc_func)0) { - strm->zalloc = zcalloc; - strm->opaque = (voidpf)0; - } - if (strm->zfree == (free_func)0) strm->zfree = zcfree; - state = (struct inflate_state FAR *)ZALLOC(strm, 1, - sizeof(struct inflate_state)); - if (state == Z_NULL) return Z_MEM_ERROR; - Tracev((stderr, "inflate: allocated\n")); - strm->state = (voidpf)state; - state->window = window; - return Z_OK; -} - -/* - Build and output length and distance decoding tables for fixed code - decoding. - */ -#ifdef MAKEFIXED -#include - -void makefixed9(void) -{ - unsigned sym, bits, low, size; - code *next, *lenfix, *distfix; - struct inflate_state state; - code fixed[544]; - - /* literal/length table */ - sym = 0; - while (sym < 144) state.lens[sym++] = 8; - while (sym < 256) state.lens[sym++] = 9; - while (sym < 280) state.lens[sym++] = 7; - while (sym < 288) state.lens[sym++] = 8; - next = fixed; - lenfix = next; - bits = 9; - inflate_table9(LENS, state.lens, 288, &(next), &(bits), state.work); - - /* distance table */ - sym = 0; - while (sym < 32) state.lens[sym++] = 5; - distfix = next; - bits = 5; - inflate_table9(DISTS, state.lens, 32, &(next), &(bits), state.work); - - /* write tables */ - puts(" /* inffix9.h -- table for decoding deflate64 fixed codes"); - puts(" * Generated automatically by makefixed9()."); - puts(" */"); - puts(""); - puts(" /* WARNING: this file should *not* be used by applications."); - puts(" It is part of the implementation of this library and is"); - puts(" subject to change. Applications should only use zlib.h."); - puts(" */"); - puts(""); - size = 1U << 9; - printf(" static const code lenfix[%u] = {", size); - low = 0; - for (;;) { - if ((low % 6) == 0) printf("\n "); - printf("{%u,%u,%d}", lenfix[low].op, lenfix[low].bits, - lenfix[low].val); - if (++low == size) break; - putchar(','); - } - puts("\n };"); - size = 1U << 5; - printf("\n static const code distfix[%u] = {", size); - low = 0; - for (;;) { - if ((low % 5) == 0) printf("\n "); - printf("{%u,%u,%d}", distfix[low].op, distfix[low].bits, - distfix[low].val); - if (++low == size) break; - putchar(','); - } - puts("\n };"); -} -#endif /* MAKEFIXED */ - -/* Macros for inflateBack(): */ - -/* Clear the input bit accumulator */ -#define INITBITS() \ - do { \ - hold = 0; \ - bits = 0; \ - } while (0) - -/* Assure that some input is available. If input is requested, but denied, - then return a Z_BUF_ERROR from inflateBack(). */ -#define PULL() \ - do { \ - if (have == 0) { \ - have = in(in_desc, &next); \ - if (have == 0) { \ - next = Z_NULL; \ - ret = Z_BUF_ERROR; \ - goto inf_leave; \ - } \ - } \ - } while (0) - -/* Get a byte of input into the bit accumulator, or return from inflateBack() - with an error if there is no input available. */ -#define PULLBYTE() \ - do { \ - PULL(); \ - have--; \ - hold += (unsigned long)(*next++) << bits; \ - bits += 8; \ - } while (0) - -/* Assure that there are at least n bits in the bit accumulator. If there is - not enough available input to do that, then return from inflateBack() with - an error. */ -#define NEEDBITS(n) \ - do { \ - while (bits < (unsigned)(n)) \ - PULLBYTE(); \ - } while (0) - -/* Return the low n bits of the bit accumulator (n <= 16) */ -#define BITS(n) \ - ((unsigned)hold & ((1U << (n)) - 1)) - -/* Remove n bits from the bit accumulator */ -#define DROPBITS(n) \ - do { \ - hold >>= (n); \ - bits -= (unsigned)(n); \ - } while (0) - -/* Remove zero to seven bits as needed to go to a byte boundary */ -#define BYTEBITS() \ - do { \ - hold >>= bits & 7; \ - bits -= bits & 7; \ - } while (0) - -/* Assure that some output space is available, by writing out the window - if it's full. If the write fails, return from inflateBack() with a - Z_BUF_ERROR. */ -#define ROOM() \ - do { \ - if (left == 0) { \ - put = window; \ - left = WSIZE; \ - wrap = 1; \ - if (out(out_desc, put, (unsigned)left)) { \ - ret = Z_BUF_ERROR; \ - goto inf_leave; \ - } \ - } \ - } while (0) - -/* - strm provides the memory allocation functions and window buffer on input, - and provides information on the unused input on return. For Z_DATA_ERROR - returns, strm will also provide an error message. - - in() and out() are the call-back input and output functions. When - inflateBack() needs more input, it calls in(). When inflateBack() has - filled the window with output, or when it completes with data in the - window, it calls out() to write out the data. The application must not - change the provided input until in() is called again or inflateBack() - returns. The application must not change the window/output buffer until - inflateBack() returns. - - in() and out() are called with a descriptor parameter provided in the - inflateBack() call. This parameter can be a structure that provides the - information required to do the read or write, as well as accumulated - information on the input and output such as totals and check values. - - in() should return zero on failure. out() should return non-zero on - failure. If either in() or out() fails, than inflateBack() returns a - Z_BUF_ERROR. strm->next_in can be checked for Z_NULL to see whether it - was in() or out() that caused in the error. Otherwise, inflateBack() - returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format - error, or Z_MEM_ERROR if it could not allocate memory for the state. - inflateBack() can also return Z_STREAM_ERROR if the input parameters - are not correct, i.e. strm is Z_NULL or the state was not initialized. - */ -int ZEXPORT inflateBack9(strm, in, in_desc, out, out_desc) -z_stream FAR *strm; -in_func in; -void FAR *in_desc; -out_func out; -void FAR *out_desc; -{ - struct inflate_state FAR *state; - z_const unsigned char FAR *next; /* next input */ - unsigned char FAR *put; /* next output */ - unsigned have; /* available input */ - unsigned long left; /* available output */ - inflate_mode mode; /* current inflate mode */ - int lastblock; /* true if processing last block */ - int wrap; /* true if the window has wrapped */ - unsigned char FAR *window; /* allocated sliding window, if needed */ - unsigned long hold; /* bit buffer */ - unsigned bits; /* bits in bit buffer */ - unsigned extra; /* extra bits needed */ - unsigned long length; /* literal or length of data to copy */ - unsigned long offset; /* distance back to copy string from */ - unsigned long copy; /* number of stored or match bytes to copy */ - unsigned char FAR *from; /* where to copy match bytes from */ - code const FAR *lencode; /* starting table for length/literal codes */ - code const FAR *distcode; /* starting table for distance codes */ - unsigned lenbits; /* index bits for lencode */ - unsigned distbits; /* index bits for distcode */ - code here; /* current decoding table entry */ - code last; /* parent table entry */ - unsigned len; /* length to copy for repeats, bits to drop */ - int ret; /* return code */ - static const unsigned short order[19] = /* permutation of code lengths */ - {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; -#include "inffix9.h" - - /* Check that the strm exists and that the state was initialized */ - if (strm == Z_NULL || strm->state == Z_NULL) - return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - - /* Reset the state */ - strm->msg = Z_NULL; - mode = TYPE; - lastblock = 0; - wrap = 0; - window = state->window; - next = strm->next_in; - have = next != Z_NULL ? strm->avail_in : 0; - hold = 0; - bits = 0; - put = window; - left = WSIZE; - lencode = Z_NULL; - distcode = Z_NULL; - - /* Inflate until end of block marked as last */ - for (;;) - switch (mode) { - case TYPE: - /* determine and dispatch block type */ - if (lastblock) { - BYTEBITS(); - mode = DONE; - break; - } - NEEDBITS(3); - lastblock = BITS(1); - DROPBITS(1); - switch (BITS(2)) { - case 0: /* stored block */ - Tracev((stderr, "inflate: stored block%s\n", - lastblock ? " (last)" : "")); - mode = STORED; - break; - case 1: /* fixed block */ - lencode = lenfix; - lenbits = 9; - distcode = distfix; - distbits = 5; - Tracev((stderr, "inflate: fixed codes block%s\n", - lastblock ? " (last)" : "")); - mode = LEN; /* decode codes */ - break; - case 2: /* dynamic block */ - Tracev((stderr, "inflate: dynamic codes block%s\n", - lastblock ? " (last)" : "")); - mode = TABLE; - break; - case 3: - strm->msg = (char *)"invalid block type"; - mode = BAD; - } - DROPBITS(2); - break; - - case STORED: - /* get and verify stored block length */ - BYTEBITS(); /* go to byte boundary */ - NEEDBITS(32); - if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) { - strm->msg = (char *)"invalid stored block lengths"; - mode = BAD; - break; - } - length = (unsigned)hold & 0xffff; - Tracev((stderr, "inflate: stored length %lu\n", - length)); - INITBITS(); - - /* copy stored block from input to output */ - while (length != 0) { - copy = length; - PULL(); - ROOM(); - if (copy > have) copy = have; - if (copy > left) copy = left; - zmemcpy(put, next, copy); - have -= copy; - next += copy; - left -= copy; - put += copy; - length -= copy; - } - Tracev((stderr, "inflate: stored end\n")); - mode = TYPE; - break; - - case TABLE: - /* get dynamic table entries descriptor */ - NEEDBITS(14); - state->nlen = BITS(5) + 257; - DROPBITS(5); - state->ndist = BITS(5) + 1; - DROPBITS(5); - state->ncode = BITS(4) + 4; - DROPBITS(4); - if (state->nlen > 286) { - strm->msg = (char *)"too many length symbols"; - mode = BAD; - break; - } - Tracev((stderr, "inflate: table sizes ok\n")); - - /* get code length code lengths (not a typo) */ - state->have = 0; - while (state->have < state->ncode) { - NEEDBITS(3); - state->lens[order[state->have++]] = (unsigned short)BITS(3); - DROPBITS(3); - } - while (state->have < 19) - state->lens[order[state->have++]] = 0; - state->next = state->codes; - lencode = (code const FAR *)(state->next); - lenbits = 7; - ret = inflate_table9(CODES, state->lens, 19, &(state->next), - &(lenbits), state->work); - if (ret) { - strm->msg = (char *)"invalid code lengths set"; - mode = BAD; - break; - } - Tracev((stderr, "inflate: code lengths ok\n")); - - /* get length and distance code code lengths */ - state->have = 0; - while (state->have < state->nlen + state->ndist) { - for (;;) { - here = lencode[BITS(lenbits)]; - if ((unsigned)(here.bits) <= bits) break; - PULLBYTE(); - } - if (here.val < 16) { - NEEDBITS(here.bits); - DROPBITS(here.bits); - state->lens[state->have++] = here.val; - } - else { - if (here.val == 16) { - NEEDBITS(here.bits + 2); - DROPBITS(here.bits); - if (state->have == 0) { - strm->msg = (char *)"invalid bit length repeat"; - mode = BAD; - break; - } - len = (unsigned)(state->lens[state->have - 1]); - copy = 3 + BITS(2); - DROPBITS(2); - } - else if (here.val == 17) { - NEEDBITS(here.bits + 3); - DROPBITS(here.bits); - len = 0; - copy = 3 + BITS(3); - DROPBITS(3); - } - else { - NEEDBITS(here.bits + 7); - DROPBITS(here.bits); - len = 0; - copy = 11 + BITS(7); - DROPBITS(7); - } - if (state->have + copy > state->nlen + state->ndist) { - strm->msg = (char *)"invalid bit length repeat"; - mode = BAD; - break; - } - while (copy--) - state->lens[state->have++] = (unsigned short)len; - } - } - - /* handle error breaks in while */ - if (mode == BAD) break; - - /* check for end-of-block code (better have one) */ - if (state->lens[256] == 0) { - strm->msg = (char *)"invalid code -- missing end-of-block"; - mode = BAD; - break; - } - - /* build code tables -- note: do not change the lenbits or distbits - values here (9 and 6) without reading the comments in inftree9.h - concerning the ENOUGH constants, which depend on those values */ - state->next = state->codes; - lencode = (code const FAR *)(state->next); - lenbits = 9; - ret = inflate_table9(LENS, state->lens, state->nlen, - &(state->next), &(lenbits), state->work); - if (ret) { - strm->msg = (char *)"invalid literal/lengths set"; - mode = BAD; - break; - } - distcode = (code const FAR *)(state->next); - distbits = 6; - ret = inflate_table9(DISTS, state->lens + state->nlen, - state->ndist, &(state->next), &(distbits), - state->work); - if (ret) { - strm->msg = (char *)"invalid distances set"; - mode = BAD; - break; - } - Tracev((stderr, "inflate: codes ok\n")); - mode = LEN; - - case LEN: - /* get a literal, length, or end-of-block code */ - for (;;) { - here = lencode[BITS(lenbits)]; - if ((unsigned)(here.bits) <= bits) break; - PULLBYTE(); - } - if (here.op && (here.op & 0xf0) == 0) { - last = here; - for (;;) { - here = lencode[last.val + - (BITS(last.bits + last.op) >> last.bits)]; - if ((unsigned)(last.bits + here.bits) <= bits) break; - PULLBYTE(); - } - DROPBITS(last.bits); - } - DROPBITS(here.bits); - length = (unsigned)here.val; - - /* process literal */ - if (here.op == 0) { - Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? - "inflate: literal '%c'\n" : - "inflate: literal 0x%02x\n", here.val)); - ROOM(); - *put++ = (unsigned char)(length); - left--; - mode = LEN; - break; - } - - /* process end of block */ - if (here.op & 32) { - Tracevv((stderr, "inflate: end of block\n")); - mode = TYPE; - break; - } - - /* invalid code */ - if (here.op & 64) { - strm->msg = (char *)"invalid literal/length code"; - mode = BAD; - break; - } - - /* length code -- get extra bits, if any */ - extra = (unsigned)(here.op) & 31; - if (extra != 0) { - NEEDBITS(extra); - length += BITS(extra); - DROPBITS(extra); - } - Tracevv((stderr, "inflate: length %lu\n", length)); - - /* get distance code */ - for (;;) { - here = distcode[BITS(distbits)]; - if ((unsigned)(here.bits) <= bits) break; - PULLBYTE(); - } - if ((here.op & 0xf0) == 0) { - last = here; - for (;;) { - here = distcode[last.val + - (BITS(last.bits + last.op) >> last.bits)]; - if ((unsigned)(last.bits + here.bits) <= bits) break; - PULLBYTE(); - } - DROPBITS(last.bits); - } - DROPBITS(here.bits); - if (here.op & 64) { - strm->msg = (char *)"invalid distance code"; - mode = BAD; - break; - } - offset = (unsigned)here.val; - - /* get distance extra bits, if any */ - extra = (unsigned)(here.op) & 15; - if (extra != 0) { - NEEDBITS(extra); - offset += BITS(extra); - DROPBITS(extra); - } - if (offset > WSIZE - (wrap ? 0: left)) { - strm->msg = (char *)"invalid distance too far back"; - mode = BAD; - break; - } - Tracevv((stderr, "inflate: distance %lu\n", offset)); - - /* copy match from window to output */ - do { - ROOM(); - copy = WSIZE - offset; - if (copy < left) { - from = put + copy; - copy = left - copy; - } - else { - from = put - offset; - copy = left; - } - if (copy > length) copy = length; - length -= copy; - left -= copy; - do { - *put++ = *from++; - } while (--copy); - } while (length != 0); - break; - - case DONE: - /* inflate stream terminated properly -- write leftover output */ - ret = Z_STREAM_END; - if (left < WSIZE) { - if (out(out_desc, window, (unsigned)(WSIZE - left))) - ret = Z_BUF_ERROR; - } - goto inf_leave; - - case BAD: - ret = Z_DATA_ERROR; - goto inf_leave; - - default: /* can't happen, but makes compilers happy */ - ret = Z_STREAM_ERROR; - goto inf_leave; - } - - /* Return unused input */ - inf_leave: - strm->next_in = next; - strm->avail_in = have; - return ret; -} - -int ZEXPORT inflateBack9End(strm) -z_stream FAR *strm; -{ - if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) - return Z_STREAM_ERROR; - ZFREE(strm, strm->state); - strm->state = Z_NULL; - Tracev((stderr, "inflate: end\n")); - return Z_OK; -} diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/infback9/infback9.h b/src/beast/test/zlib/zlib-1.2.8/contrib/infback9/infback9.h deleted file mode 100644 index 1073c0a38e6..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/infback9/infback9.h +++ /dev/null @@ -1,37 +0,0 @@ -/* infback9.h -- header for using inflateBack9 functions - * Copyright (C) 2003 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* - * This header file and associated patches provide a decoder for PKWare's - * undocumented deflate64 compression method (method 9). Use with infback9.c, - * inftree9.h, inftree9.c, and inffix9.h. These patches are not supported. - * This should be compiled with zlib, since it uses zutil.h and zutil.o. - * This code has not yet been tested on 16-bit architectures. See the - * comments in zlib.h for inflateBack() usage. These functions are used - * identically, except that there is no windowBits parameter, and a 64K - * window must be provided. Also if int's are 16 bits, then a zero for - * the third parameter of the "out" function actually means 65536UL. - * zlib.h must be included before this header file. - */ - -#ifdef __cplusplus -extern "C" { -#endif - -ZEXTERN int ZEXPORT inflateBack9 OF((z_stream FAR *strm, - in_func in, void FAR *in_desc, - out_func out, void FAR *out_desc)); -ZEXTERN int ZEXPORT inflateBack9End OF((z_stream FAR *strm)); -ZEXTERN int ZEXPORT inflateBack9Init_ OF((z_stream FAR *strm, - unsigned char FAR *window, - const char *version, - int stream_size)); -#define inflateBack9Init(strm, window) \ - inflateBack9Init_((strm), (window), \ - ZLIB_VERSION, sizeof(z_stream)) - -#ifdef __cplusplus -} -#endif diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/infback9/inffix9.h b/src/beast/test/zlib/zlib-1.2.8/contrib/infback9/inffix9.h deleted file mode 100644 index ee5671d2df6..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/infback9/inffix9.h +++ /dev/null @@ -1,107 +0,0 @@ - /* inffix9.h -- table for decoding deflate64 fixed codes - * Generated automatically by makefixed9(). - */ - - /* WARNING: this file should *not* be used by applications. - It is part of the implementation of this library and is - subject to change. Applications should only use zlib.h. - */ - - static const code lenfix[512] = { - {96,7,0},{0,8,80},{0,8,16},{132,8,115},{130,7,31},{0,8,112}, - {0,8,48},{0,9,192},{128,7,10},{0,8,96},{0,8,32},{0,9,160}, - {0,8,0},{0,8,128},{0,8,64},{0,9,224},{128,7,6},{0,8,88}, - {0,8,24},{0,9,144},{131,7,59},{0,8,120},{0,8,56},{0,9,208}, - {129,7,17},{0,8,104},{0,8,40},{0,9,176},{0,8,8},{0,8,136}, - {0,8,72},{0,9,240},{128,7,4},{0,8,84},{0,8,20},{133,8,227}, - {131,7,43},{0,8,116},{0,8,52},{0,9,200},{129,7,13},{0,8,100}, - {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232}, - {128,7,8},{0,8,92},{0,8,28},{0,9,152},{132,7,83},{0,8,124}, - {0,8,60},{0,9,216},{130,7,23},{0,8,108},{0,8,44},{0,9,184}, - {0,8,12},{0,8,140},{0,8,76},{0,9,248},{128,7,3},{0,8,82}, - {0,8,18},{133,8,163},{131,7,35},{0,8,114},{0,8,50},{0,9,196}, - {129,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},{0,8,130}, - {0,8,66},{0,9,228},{128,7,7},{0,8,90},{0,8,26},{0,9,148}, - {132,7,67},{0,8,122},{0,8,58},{0,9,212},{130,7,19},{0,8,106}, - {0,8,42},{0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244}, - {128,7,5},{0,8,86},{0,8,22},{65,8,0},{131,7,51},{0,8,118}, - {0,8,54},{0,9,204},{129,7,15},{0,8,102},{0,8,38},{0,9,172}, - {0,8,6},{0,8,134},{0,8,70},{0,9,236},{128,7,9},{0,8,94}, - {0,8,30},{0,9,156},{132,7,99},{0,8,126},{0,8,62},{0,9,220}, - {130,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, - {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{133,8,131}, - {130,7,31},{0,8,113},{0,8,49},{0,9,194},{128,7,10},{0,8,97}, - {0,8,33},{0,9,162},{0,8,1},{0,8,129},{0,8,65},{0,9,226}, - {128,7,6},{0,8,89},{0,8,25},{0,9,146},{131,7,59},{0,8,121}, - {0,8,57},{0,9,210},{129,7,17},{0,8,105},{0,8,41},{0,9,178}, - {0,8,9},{0,8,137},{0,8,73},{0,9,242},{128,7,4},{0,8,85}, - {0,8,21},{144,8,3},{131,7,43},{0,8,117},{0,8,53},{0,9,202}, - {129,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133}, - {0,8,69},{0,9,234},{128,7,8},{0,8,93},{0,8,29},{0,9,154}, - {132,7,83},{0,8,125},{0,8,61},{0,9,218},{130,7,23},{0,8,109}, - {0,8,45},{0,9,186},{0,8,13},{0,8,141},{0,8,77},{0,9,250}, - {128,7,3},{0,8,83},{0,8,19},{133,8,195},{131,7,35},{0,8,115}, - {0,8,51},{0,9,198},{129,7,11},{0,8,99},{0,8,35},{0,9,166}, - {0,8,3},{0,8,131},{0,8,67},{0,9,230},{128,7,7},{0,8,91}, - {0,8,27},{0,9,150},{132,7,67},{0,8,123},{0,8,59},{0,9,214}, - {130,7,19},{0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139}, - {0,8,75},{0,9,246},{128,7,5},{0,8,87},{0,8,23},{77,8,0}, - {131,7,51},{0,8,119},{0,8,55},{0,9,206},{129,7,15},{0,8,103}, - {0,8,39},{0,9,174},{0,8,7},{0,8,135},{0,8,71},{0,9,238}, - {128,7,9},{0,8,95},{0,8,31},{0,9,158},{132,7,99},{0,8,127}, - {0,8,63},{0,9,222},{130,7,27},{0,8,111},{0,8,47},{0,9,190}, - {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80}, - {0,8,16},{132,8,115},{130,7,31},{0,8,112},{0,8,48},{0,9,193}, - {128,7,10},{0,8,96},{0,8,32},{0,9,161},{0,8,0},{0,8,128}, - {0,8,64},{0,9,225},{128,7,6},{0,8,88},{0,8,24},{0,9,145}, - {131,7,59},{0,8,120},{0,8,56},{0,9,209},{129,7,17},{0,8,104}, - {0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},{0,9,241}, - {128,7,4},{0,8,84},{0,8,20},{133,8,227},{131,7,43},{0,8,116}, - {0,8,52},{0,9,201},{129,7,13},{0,8,100},{0,8,36},{0,9,169}, - {0,8,4},{0,8,132},{0,8,68},{0,9,233},{128,7,8},{0,8,92}, - {0,8,28},{0,9,153},{132,7,83},{0,8,124},{0,8,60},{0,9,217}, - {130,7,23},{0,8,108},{0,8,44},{0,9,185},{0,8,12},{0,8,140}, - {0,8,76},{0,9,249},{128,7,3},{0,8,82},{0,8,18},{133,8,163}, - {131,7,35},{0,8,114},{0,8,50},{0,9,197},{129,7,11},{0,8,98}, - {0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, - {128,7,7},{0,8,90},{0,8,26},{0,9,149},{132,7,67},{0,8,122}, - {0,8,58},{0,9,213},{130,7,19},{0,8,106},{0,8,42},{0,9,181}, - {0,8,10},{0,8,138},{0,8,74},{0,9,245},{128,7,5},{0,8,86}, - {0,8,22},{65,8,0},{131,7,51},{0,8,118},{0,8,54},{0,9,205}, - {129,7,15},{0,8,102},{0,8,38},{0,9,173},{0,8,6},{0,8,134}, - {0,8,70},{0,9,237},{128,7,9},{0,8,94},{0,8,30},{0,9,157}, - {132,7,99},{0,8,126},{0,8,62},{0,9,221},{130,7,27},{0,8,110}, - {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253}, - {96,7,0},{0,8,81},{0,8,17},{133,8,131},{130,7,31},{0,8,113}, - {0,8,49},{0,9,195},{128,7,10},{0,8,97},{0,8,33},{0,9,163}, - {0,8,1},{0,8,129},{0,8,65},{0,9,227},{128,7,6},{0,8,89}, - {0,8,25},{0,9,147},{131,7,59},{0,8,121},{0,8,57},{0,9,211}, - {129,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},{0,8,137}, - {0,8,73},{0,9,243},{128,7,4},{0,8,85},{0,8,21},{144,8,3}, - {131,7,43},{0,8,117},{0,8,53},{0,9,203},{129,7,13},{0,8,101}, - {0,8,37},{0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235}, - {128,7,8},{0,8,93},{0,8,29},{0,9,155},{132,7,83},{0,8,125}, - {0,8,61},{0,9,219},{130,7,23},{0,8,109},{0,8,45},{0,9,187}, - {0,8,13},{0,8,141},{0,8,77},{0,9,251},{128,7,3},{0,8,83}, - {0,8,19},{133,8,195},{131,7,35},{0,8,115},{0,8,51},{0,9,199}, - {129,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, - {0,8,67},{0,9,231},{128,7,7},{0,8,91},{0,8,27},{0,9,151}, - {132,7,67},{0,8,123},{0,8,59},{0,9,215},{130,7,19},{0,8,107}, - {0,8,43},{0,9,183},{0,8,11},{0,8,139},{0,8,75},{0,9,247}, - {128,7,5},{0,8,87},{0,8,23},{77,8,0},{131,7,51},{0,8,119}, - {0,8,55},{0,9,207},{129,7,15},{0,8,103},{0,8,39},{0,9,175}, - {0,8,7},{0,8,135},{0,8,71},{0,9,239},{128,7,9},{0,8,95}, - {0,8,31},{0,9,159},{132,7,99},{0,8,127},{0,8,63},{0,9,223}, - {130,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143}, - {0,8,79},{0,9,255} - }; - - static const code distfix[32] = { - {128,5,1},{135,5,257},{131,5,17},{139,5,4097},{129,5,5}, - {137,5,1025},{133,5,65},{141,5,16385},{128,5,3},{136,5,513}, - {132,5,33},{140,5,8193},{130,5,9},{138,5,2049},{134,5,129}, - {142,5,32769},{128,5,2},{135,5,385},{131,5,25},{139,5,6145}, - {129,5,7},{137,5,1537},{133,5,97},{141,5,24577},{128,5,4}, - {136,5,769},{132,5,49},{140,5,12289},{130,5,13},{138,5,3073}, - {134,5,193},{142,5,49153} - }; diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/infback9/inflate9.h b/src/beast/test/zlib/zlib-1.2.8/contrib/infback9/inflate9.h deleted file mode 100644 index ee9a79394b6..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/infback9/inflate9.h +++ /dev/null @@ -1,47 +0,0 @@ -/* inflate9.h -- internal inflate state definition - * Copyright (C) 1995-2003 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -/* Possible inflate modes between inflate() calls */ -typedef enum { - TYPE, /* i: waiting for type bits, including last-flag bit */ - STORED, /* i: waiting for stored size (length and complement) */ - TABLE, /* i: waiting for dynamic block table lengths */ - LEN, /* i: waiting for length/lit code */ - DONE, /* finished check, done -- remain here until reset */ - BAD /* got a data error -- remain here until reset */ -} inflate_mode; - -/* - State transitions between above modes - - - (most modes can go to the BAD mode -- not shown for clarity) - - Read deflate blocks: - TYPE -> STORED or TABLE or LEN or DONE - STORED -> TYPE - TABLE -> LENLENS -> CODELENS -> LEN - Read deflate codes: - LEN -> LEN or TYPE - */ - -/* state maintained between inflate() calls. Approximately 7K bytes. */ -struct inflate_state { - /* sliding window */ - unsigned char FAR *window; /* allocated sliding window, if needed */ - /* dynamic table building */ - unsigned ncode; /* number of code length code lengths */ - unsigned nlen; /* number of length code lengths */ - unsigned ndist; /* number of distance code lengths */ - unsigned have; /* number of code lengths in lens[] */ - code FAR *next; /* next available space in codes[] */ - unsigned short lens[320]; /* temporary storage for code lengths */ - unsigned short work[288]; /* work area for code table building */ - code codes[ENOUGH]; /* space for code tables */ -}; diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/infback9/inftree9.c b/src/beast/test/zlib/zlib-1.2.8/contrib/infback9/inftree9.c deleted file mode 100644 index 4a73ad215f5..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/infback9/inftree9.c +++ /dev/null @@ -1,324 +0,0 @@ -/* inftree9.c -- generate Huffman trees for efficient decoding - * Copyright (C) 1995-2013 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#include "zutil.h" -#include "inftree9.h" - -#define MAXBITS 15 - -const char inflate9_copyright[] = - " inflate9 1.2.8 Copyright 1995-2013 Mark Adler "; -/* - If you use the zlib library in a product, an acknowledgment is welcome - in the documentation of your product. If for some reason you cannot - include such an acknowledgment, I would appreciate that you keep this - copyright string in the executable of your product. - */ - -/* - Build a set of tables to decode the provided canonical Huffman code. - The code lengths are lens[0..codes-1]. The result starts at *table, - whose indices are 0..2^bits-1. work is a writable array of at least - lens shorts, which is used as a work area. type is the type of code - to be generated, CODES, LENS, or DISTS. On return, zero is success, - -1 is an invalid code, and +1 means that ENOUGH isn't enough. table - on return points to the next available entry's address. bits is the - requested root table index bits, and on return it is the actual root - table index bits. It will differ if the request is greater than the - longest code or if it is less than the shortest code. - */ -int inflate_table9(type, lens, codes, table, bits, work) -codetype type; -unsigned short FAR *lens; -unsigned codes; -code FAR * FAR *table; -unsigned FAR *bits; -unsigned short FAR *work; -{ - unsigned len; /* a code's length in bits */ - unsigned sym; /* index of code symbols */ - unsigned min, max; /* minimum and maximum code lengths */ - unsigned root; /* number of index bits for root table */ - unsigned curr; /* number of index bits for current table */ - unsigned drop; /* code bits to drop for sub-table */ - int left; /* number of prefix codes available */ - unsigned used; /* code entries in table used */ - unsigned huff; /* Huffman code */ - unsigned incr; /* for incrementing code, index */ - unsigned fill; /* index for replicating entries */ - unsigned low; /* low bits for current root entry */ - unsigned mask; /* mask for low root bits */ - code this; /* table entry for duplication */ - code FAR *next; /* next available space in table */ - const unsigned short FAR *base; /* base value table to use */ - const unsigned short FAR *extra; /* extra bits table to use */ - int end; /* use base and extra for symbol > end */ - unsigned short count[MAXBITS+1]; /* number of codes of each length */ - unsigned short offs[MAXBITS+1]; /* offsets in table for each length */ - static const unsigned short lbase[31] = { /* Length codes 257..285 base */ - 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, - 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, - 131, 163, 195, 227, 3, 0, 0}; - static const unsigned short lext[31] = { /* Length codes 257..285 extra */ - 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, - 130, 130, 130, 130, 131, 131, 131, 131, 132, 132, 132, 132, - 133, 133, 133, 133, 144, 72, 78}; - static const unsigned short dbase[32] = { /* Distance codes 0..31 base */ - 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, - 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, - 4097, 6145, 8193, 12289, 16385, 24577, 32769, 49153}; - static const unsigned short dext[32] = { /* Distance codes 0..31 extra */ - 128, 128, 128, 128, 129, 129, 130, 130, 131, 131, 132, 132, - 133, 133, 134, 134, 135, 135, 136, 136, 137, 137, 138, 138, - 139, 139, 140, 140, 141, 141, 142, 142}; - - /* - Process a set of code lengths to create a canonical Huffman code. The - code lengths are lens[0..codes-1]. Each length corresponds to the - symbols 0..codes-1. The Huffman code is generated by first sorting the - symbols by length from short to long, and retaining the symbol order - for codes with equal lengths. Then the code starts with all zero bits - for the first code of the shortest length, and the codes are integer - increments for the same length, and zeros are appended as the length - increases. For the deflate format, these bits are stored backwards - from their more natural integer increment ordering, and so when the - decoding tables are built in the large loop below, the integer codes - are incremented backwards. - - This routine assumes, but does not check, that all of the entries in - lens[] are in the range 0..MAXBITS. The caller must assure this. - 1..MAXBITS is interpreted as that code length. zero means that that - symbol does not occur in this code. - - The codes are sorted by computing a count of codes for each length, - creating from that a table of starting indices for each length in the - sorted table, and then entering the symbols in order in the sorted - table. The sorted table is work[], with that space being provided by - the caller. - - The length counts are used for other purposes as well, i.e. finding - the minimum and maximum length codes, determining if there are any - codes at all, checking for a valid set of lengths, and looking ahead - at length counts to determine sub-table sizes when building the - decoding tables. - */ - - /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */ - for (len = 0; len <= MAXBITS; len++) - count[len] = 0; - for (sym = 0; sym < codes; sym++) - count[lens[sym]]++; - - /* bound code lengths, force root to be within code lengths */ - root = *bits; - for (max = MAXBITS; max >= 1; max--) - if (count[max] != 0) break; - if (root > max) root = max; - if (max == 0) return -1; /* no codes! */ - for (min = 1; min <= MAXBITS; min++) - if (count[min] != 0) break; - if (root < min) root = min; - - /* check for an over-subscribed or incomplete set of lengths */ - left = 1; - for (len = 1; len <= MAXBITS; len++) { - left <<= 1; - left -= count[len]; - if (left < 0) return -1; /* over-subscribed */ - } - if (left > 0 && (type == CODES || max != 1)) - return -1; /* incomplete set */ - - /* generate offsets into symbol table for each length for sorting */ - offs[1] = 0; - for (len = 1; len < MAXBITS; len++) - offs[len + 1] = offs[len] + count[len]; - - /* sort symbols by length, by symbol order within each length */ - for (sym = 0; sym < codes; sym++) - if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym; - - /* - Create and fill in decoding tables. In this loop, the table being - filled is at next and has curr index bits. The code being used is huff - with length len. That code is converted to an index by dropping drop - bits off of the bottom. For codes where len is less than drop + curr, - those top drop + curr - len bits are incremented through all values to - fill the table with replicated entries. - - root is the number of index bits for the root table. When len exceeds - root, sub-tables are created pointed to by the root entry with an index - of the low root bits of huff. This is saved in low to check for when a - new sub-table should be started. drop is zero when the root table is - being filled, and drop is root when sub-tables are being filled. - - When a new sub-table is needed, it is necessary to look ahead in the - code lengths to determine what size sub-table is needed. The length - counts are used for this, and so count[] is decremented as codes are - entered in the tables. - - used keeps track of how many table entries have been allocated from the - provided *table space. It is checked for LENS and DIST tables against - the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in - the initial root table size constants. See the comments in inftree9.h - for more information. - - sym increments through all symbols, and the loop terminates when - all codes of length max, i.e. all codes, have been processed. This - routine permits incomplete codes, so another loop after this one fills - in the rest of the decoding tables with invalid code markers. - */ - - /* set up for code type */ - switch (type) { - case CODES: - base = extra = work; /* dummy value--not used */ - end = 19; - break; - case LENS: - base = lbase; - base -= 257; - extra = lext; - extra -= 257; - end = 256; - break; - default: /* DISTS */ - base = dbase; - extra = dext; - end = -1; - } - - /* initialize state for loop */ - huff = 0; /* starting code */ - sym = 0; /* starting code symbol */ - len = min; /* starting code length */ - next = *table; /* current table to fill in */ - curr = root; /* current table index bits */ - drop = 0; /* current bits to drop from code for index */ - low = (unsigned)(-1); /* trigger new sub-table when len > root */ - used = 1U << root; /* use root table entries */ - mask = used - 1; /* mask for comparing low */ - - /* check available table space */ - if ((type == LENS && used >= ENOUGH_LENS) || - (type == DISTS && used >= ENOUGH_DISTS)) - return 1; - - /* process all codes and make table entries */ - for (;;) { - /* create table entry */ - this.bits = (unsigned char)(len - drop); - if ((int)(work[sym]) < end) { - this.op = (unsigned char)0; - this.val = work[sym]; - } - else if ((int)(work[sym]) > end) { - this.op = (unsigned char)(extra[work[sym]]); - this.val = base[work[sym]]; - } - else { - this.op = (unsigned char)(32 + 64); /* end of block */ - this.val = 0; - } - - /* replicate for those indices with low len bits equal to huff */ - incr = 1U << (len - drop); - fill = 1U << curr; - do { - fill -= incr; - next[(huff >> drop) + fill] = this; - } while (fill != 0); - - /* backwards increment the len-bit code huff */ - incr = 1U << (len - 1); - while (huff & incr) - incr >>= 1; - if (incr != 0) { - huff &= incr - 1; - huff += incr; - } - else - huff = 0; - - /* go to next symbol, update count, len */ - sym++; - if (--(count[len]) == 0) { - if (len == max) break; - len = lens[work[sym]]; - } - - /* create new sub-table if needed */ - if (len > root && (huff & mask) != low) { - /* if first time, transition to sub-tables */ - if (drop == 0) - drop = root; - - /* increment past last table */ - next += 1U << curr; - - /* determine length of next table */ - curr = len - drop; - left = (int)(1 << curr); - while (curr + drop < max) { - left -= count[curr + drop]; - if (left <= 0) break; - curr++; - left <<= 1; - } - - /* check for enough space */ - used += 1U << curr; - if ((type == LENS && used >= ENOUGH_LENS) || - (type == DISTS && used >= ENOUGH_DISTS)) - return 1; - - /* point entry in root table to sub-table */ - low = huff & mask; - (*table)[low].op = (unsigned char)curr; - (*table)[low].bits = (unsigned char)root; - (*table)[low].val = (unsigned short)(next - *table); - } - } - - /* - Fill in rest of table for incomplete codes. This loop is similar to the - loop above in incrementing huff for table indices. It is assumed that - len is equal to curr + drop, so there is no loop needed to increment - through high index bits. When the current sub-table is filled, the loop - drops back to the root table to fill in any remaining entries there. - */ - this.op = (unsigned char)64; /* invalid code marker */ - this.bits = (unsigned char)(len - drop); - this.val = (unsigned short)0; - while (huff != 0) { - /* when done with sub-table, drop back to root table */ - if (drop != 0 && (huff & mask) != low) { - drop = 0; - len = root; - next = *table; - curr = root; - this.bits = (unsigned char)len; - } - - /* put invalid code marker in table */ - next[huff >> drop] = this; - - /* backwards increment the len-bit code huff */ - incr = 1U << (len - 1); - while (huff & incr) - incr >>= 1; - if (incr != 0) { - huff &= incr - 1; - huff += incr; - } - else - huff = 0; - } - - /* set return parameters */ - *table += used; - *bits = root; - return 0; -} diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/infback9/inftree9.h b/src/beast/test/zlib/zlib-1.2.8/contrib/infback9/inftree9.h deleted file mode 100644 index 5ab21f0c6d1..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/infback9/inftree9.h +++ /dev/null @@ -1,61 +0,0 @@ -/* inftree9.h -- header to use inftree9.c - * Copyright (C) 1995-2008 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -/* Structure for decoding tables. Each entry provides either the - information needed to do the operation requested by the code that - indexed that table entry, or it provides a pointer to another - table that indexes more bits of the code. op indicates whether - the entry is a pointer to another table, a literal, a length or - distance, an end-of-block, or an invalid code. For a table - pointer, the low four bits of op is the number of index bits of - that table. For a length or distance, the low four bits of op - is the number of extra bits to get after the code. bits is - the number of bits in this code or part of the code to drop off - of the bit buffer. val is the actual byte to output in the case - of a literal, the base length or distance, or the offset from - the current table to the next table. Each entry is four bytes. */ -typedef struct { - unsigned char op; /* operation, extra bits, table bits */ - unsigned char bits; /* bits in this part of the code */ - unsigned short val; /* offset in table or code value */ -} code; - -/* op values as set by inflate_table(): - 00000000 - literal - 0000tttt - table link, tttt != 0 is the number of table index bits - 100eeeee - length or distance, eeee is the number of extra bits - 01100000 - end of block - 01000000 - invalid code - */ - -/* Maximum size of the dynamic table. The maximum number of code structures is - 1446, which is the sum of 852 for literal/length codes and 594 for distance - codes. These values were found by exhaustive searches using the program - examples/enough.c found in the zlib distribtution. The arguments to that - program are the number of symbols, the initial root table size, and the - maximum bit length of a code. "enough 286 9 15" for literal/length codes - returns returns 852, and "enough 32 6 15" for distance codes returns 594. - The initial root table size (9 or 6) is found in the fifth argument of the - inflate_table() calls in infback9.c. If the root table size is changed, - then these maximum sizes would be need to be recalculated and updated. */ -#define ENOUGH_LENS 852 -#define ENOUGH_DISTS 594 -#define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS) - -/* Type of code to build for inflate_table9() */ -typedef enum { - CODES, - LENS, - DISTS -} codetype; - -extern int inflate_table9 OF((codetype type, unsigned short FAR *lens, - unsigned codes, code FAR * FAR *table, - unsigned FAR *bits, unsigned short FAR *work)); diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/inflate86/inffas86.c b/src/beast/test/zlib/zlib-1.2.8/contrib/inflate86/inffas86.c deleted file mode 100644 index 7292f67b753..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/inflate86/inffas86.c +++ /dev/null @@ -1,1157 +0,0 @@ -/* inffas86.c is a hand tuned assembler version of - * - * inffast.c -- fast decoding - * Copyright (C) 1995-2003 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - * - * Copyright (C) 2003 Chris Anderson - * Please use the copyright conditions above. - * - * Dec-29-2003 -- I added AMD64 inflate asm support. This version is also - * slightly quicker on x86 systems because, instead of using rep movsb to copy - * data, it uses rep movsw, which moves data in 2-byte chunks instead of single - * bytes. I've tested the AMD64 code on a Fedora Core 1 + the x86_64 updates - * from http://fedora.linux.duke.edu/fc1_x86_64 - * which is running on an Athlon 64 3000+ / Gigabyte GA-K8VT800M system with - * 1GB ram. The 64-bit version is about 4% faster than the 32-bit version, - * when decompressing mozilla-source-1.3.tar.gz. - * - * Mar-13-2003 -- Most of this is derived from inffast.S which is derived from - * the gcc -S output of zlib-1.2.0/inffast.c. Zlib-1.2.0 is in beta release at - * the moment. I have successfully compiled and tested this code with gcc2.96, - * gcc3.2, icc5.0, msvc6.0. It is very close to the speed of inffast.S - * compiled with gcc -DNO_MMX, but inffast.S is still faster on the P3 with MMX - * enabled. I will attempt to merge the MMX code into this version. Newer - * versions of this and inffast.S can be found at - * http://www.eetbeetee.com/zlib/ and http://www.charm.net/~christop/zlib/ - */ - -#include "zutil.h" -#include "inftrees.h" -#include "inflate.h" -#include "inffast.h" - -/* Mark Adler's comments from inffast.c: */ - -/* - Decode literal, length, and distance codes and write out the resulting - literal and match bytes until either not enough input or output is - available, an end-of-block is encountered, or a data error is encountered. - When large enough input and output buffers are supplied to inflate(), for - example, a 16K input buffer and a 64K output buffer, more than 95% of the - inflate execution time is spent in this routine. - - Entry assumptions: - - state->mode == LEN - strm->avail_in >= 6 - strm->avail_out >= 258 - start >= strm->avail_out - state->bits < 8 - - On return, state->mode is one of: - - LEN -- ran out of enough output space or enough available input - TYPE -- reached end of block code, inflate() to interpret next block - BAD -- error in block data - - Notes: - - - The maximum input bits used by a length/distance pair is 15 bits for the - length code, 5 bits for the length extra, 15 bits for the distance code, - and 13 bits for the distance extra. This totals 48 bits, or six bytes. - Therefore if strm->avail_in >= 6, then there is enough input to avoid - checking for available input while decoding. - - - The maximum bytes that a single length/distance pair can output is 258 - bytes, which is the maximum length that can be coded. inflate_fast() - requires strm->avail_out >= 258 for each loop to avoid checking for - output space. - */ -void inflate_fast(strm, start) -z_streamp strm; -unsigned start; /* inflate()'s starting value for strm->avail_out */ -{ - struct inflate_state FAR *state; - struct inffast_ar { -/* 64 32 x86 x86_64 */ -/* ar offset register */ -/* 0 0 */ void *esp; /* esp save */ -/* 8 4 */ void *ebp; /* ebp save */ -/* 16 8 */ unsigned char FAR *in; /* esi rsi local strm->next_in */ -/* 24 12 */ unsigned char FAR *last; /* r9 while in < last */ -/* 32 16 */ unsigned char FAR *out; /* edi rdi local strm->next_out */ -/* 40 20 */ unsigned char FAR *beg; /* inflate()'s init next_out */ -/* 48 24 */ unsigned char FAR *end; /* r10 while out < end */ -/* 56 28 */ unsigned char FAR *window;/* size of window, wsize!=0 */ -/* 64 32 */ code const FAR *lcode; /* ebp rbp local strm->lencode */ -/* 72 36 */ code const FAR *dcode; /* r11 local strm->distcode */ -/* 80 40 */ unsigned long hold; /* edx rdx local strm->hold */ -/* 88 44 */ unsigned bits; /* ebx rbx local strm->bits */ -/* 92 48 */ unsigned wsize; /* window size */ -/* 96 52 */ unsigned write; /* window write index */ -/*100 56 */ unsigned lmask; /* r12 mask for lcode */ -/*104 60 */ unsigned dmask; /* r13 mask for dcode */ -/*108 64 */ unsigned len; /* r14 match length */ -/*112 68 */ unsigned dist; /* r15 match distance */ -/*116 72 */ unsigned status; /* set when state chng*/ - } ar; - -#if defined( __GNUC__ ) && defined( __amd64__ ) && ! defined( __i386 ) -#define PAD_AVAIL_IN 6 -#define PAD_AVAIL_OUT 258 -#else -#define PAD_AVAIL_IN 5 -#define PAD_AVAIL_OUT 257 -#endif - - /* copy state to local variables */ - state = (struct inflate_state FAR *)strm->state; - ar.in = strm->next_in; - ar.last = ar.in + (strm->avail_in - PAD_AVAIL_IN); - ar.out = strm->next_out; - ar.beg = ar.out - (start - strm->avail_out); - ar.end = ar.out + (strm->avail_out - PAD_AVAIL_OUT); - ar.wsize = state->wsize; - ar.write = state->wnext; - ar.window = state->window; - ar.hold = state->hold; - ar.bits = state->bits; - ar.lcode = state->lencode; - ar.dcode = state->distcode; - ar.lmask = (1U << state->lenbits) - 1; - ar.dmask = (1U << state->distbits) - 1; - - /* decode literals and length/distances until end-of-block or not enough - input data or output space */ - - /* align in on 1/2 hold size boundary */ - while (((unsigned long)(void *)ar.in & (sizeof(ar.hold) / 2 - 1)) != 0) { - ar.hold += (unsigned long)*ar.in++ << ar.bits; - ar.bits += 8; - } - -#if defined( __GNUC__ ) && defined( __amd64__ ) && ! defined( __i386 ) - __asm__ __volatile__ ( -" leaq %0, %%rax\n" -" movq %%rbp, 8(%%rax)\n" /* save regs rbp and rsp */ -" movq %%rsp, (%%rax)\n" -" movq %%rax, %%rsp\n" /* make rsp point to &ar */ -" movq 16(%%rsp), %%rsi\n" /* rsi = in */ -" movq 32(%%rsp), %%rdi\n" /* rdi = out */ -" movq 24(%%rsp), %%r9\n" /* r9 = last */ -" movq 48(%%rsp), %%r10\n" /* r10 = end */ -" movq 64(%%rsp), %%rbp\n" /* rbp = lcode */ -" movq 72(%%rsp), %%r11\n" /* r11 = dcode */ -" movq 80(%%rsp), %%rdx\n" /* rdx = hold */ -" movl 88(%%rsp), %%ebx\n" /* ebx = bits */ -" movl 100(%%rsp), %%r12d\n" /* r12d = lmask */ -" movl 104(%%rsp), %%r13d\n" /* r13d = dmask */ - /* r14d = len */ - /* r15d = dist */ -" cld\n" -" cmpq %%rdi, %%r10\n" -" je .L_one_time\n" /* if only one decode left */ -" cmpq %%rsi, %%r9\n" -" je .L_one_time\n" -" jmp .L_do_loop\n" - -".L_one_time:\n" -" movq %%r12, %%r8\n" /* r8 = lmask */ -" cmpb $32, %%bl\n" -" ja .L_get_length_code_one_time\n" - -" lodsl\n" /* eax = *(uint *)in++ */ -" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */ -" addb $32, %%bl\n" /* bits += 32 */ -" shlq %%cl, %%rax\n" -" orq %%rax, %%rdx\n" /* hold |= *((uint *)in)++ << bits */ -" jmp .L_get_length_code_one_time\n" - -".align 32,0x90\n" -".L_while_test:\n" -" cmpq %%rdi, %%r10\n" -" jbe .L_break_loop\n" -" cmpq %%rsi, %%r9\n" -" jbe .L_break_loop\n" - -".L_do_loop:\n" -" movq %%r12, %%r8\n" /* r8 = lmask */ -" cmpb $32, %%bl\n" -" ja .L_get_length_code\n" /* if (32 < bits) */ - -" lodsl\n" /* eax = *(uint *)in++ */ -" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */ -" addb $32, %%bl\n" /* bits += 32 */ -" shlq %%cl, %%rax\n" -" orq %%rax, %%rdx\n" /* hold |= *((uint *)in)++ << bits */ - -".L_get_length_code:\n" -" andq %%rdx, %%r8\n" /* r8 &= hold */ -" movl (%%rbp,%%r8,4), %%eax\n" /* eax = lcode[hold & lmask] */ - -" movb %%ah, %%cl\n" /* cl = this.bits */ -" subb %%ah, %%bl\n" /* bits -= this.bits */ -" shrq %%cl, %%rdx\n" /* hold >>= this.bits */ - -" testb %%al, %%al\n" -" jnz .L_test_for_length_base\n" /* if (op != 0) 45.7% */ - -" movq %%r12, %%r8\n" /* r8 = lmask */ -" shrl $16, %%eax\n" /* output this.val char */ -" stosb\n" - -".L_get_length_code_one_time:\n" -" andq %%rdx, %%r8\n" /* r8 &= hold */ -" movl (%%rbp,%%r8,4), %%eax\n" /* eax = lcode[hold & lmask] */ - -".L_dolen:\n" -" movb %%ah, %%cl\n" /* cl = this.bits */ -" subb %%ah, %%bl\n" /* bits -= this.bits */ -" shrq %%cl, %%rdx\n" /* hold >>= this.bits */ - -" testb %%al, %%al\n" -" jnz .L_test_for_length_base\n" /* if (op != 0) 45.7% */ - -" shrl $16, %%eax\n" /* output this.val char */ -" stosb\n" -" jmp .L_while_test\n" - -".align 32,0x90\n" -".L_test_for_length_base:\n" -" movl %%eax, %%r14d\n" /* len = this */ -" shrl $16, %%r14d\n" /* len = this.val */ -" movb %%al, %%cl\n" - -" testb $16, %%al\n" -" jz .L_test_for_second_level_length\n" /* if ((op & 16) == 0) 8% */ -" andb $15, %%cl\n" /* op &= 15 */ -" jz .L_decode_distance\n" /* if (!op) */ - -".L_add_bits_to_len:\n" -" subb %%cl, %%bl\n" -" xorl %%eax, %%eax\n" -" incl %%eax\n" -" shll %%cl, %%eax\n" -" decl %%eax\n" -" andl %%edx, %%eax\n" /* eax &= hold */ -" shrq %%cl, %%rdx\n" -" addl %%eax, %%r14d\n" /* len += hold & mask[op] */ - -".L_decode_distance:\n" -" movq %%r13, %%r8\n" /* r8 = dmask */ -" cmpb $32, %%bl\n" -" ja .L_get_distance_code\n" /* if (32 < bits) */ - -" lodsl\n" /* eax = *(uint *)in++ */ -" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */ -" addb $32, %%bl\n" /* bits += 32 */ -" shlq %%cl, %%rax\n" -" orq %%rax, %%rdx\n" /* hold |= *((uint *)in)++ << bits */ - -".L_get_distance_code:\n" -" andq %%rdx, %%r8\n" /* r8 &= hold */ -" movl (%%r11,%%r8,4), %%eax\n" /* eax = dcode[hold & dmask] */ - -".L_dodist:\n" -" movl %%eax, %%r15d\n" /* dist = this */ -" shrl $16, %%r15d\n" /* dist = this.val */ -" movb %%ah, %%cl\n" -" subb %%ah, %%bl\n" /* bits -= this.bits */ -" shrq %%cl, %%rdx\n" /* hold >>= this.bits */ -" movb %%al, %%cl\n" /* cl = this.op */ - -" testb $16, %%al\n" /* if ((op & 16) == 0) */ -" jz .L_test_for_second_level_dist\n" -" andb $15, %%cl\n" /* op &= 15 */ -" jz .L_check_dist_one\n" - -".L_add_bits_to_dist:\n" -" subb %%cl, %%bl\n" -" xorl %%eax, %%eax\n" -" incl %%eax\n" -" shll %%cl, %%eax\n" -" decl %%eax\n" /* (1 << op) - 1 */ -" andl %%edx, %%eax\n" /* eax &= hold */ -" shrq %%cl, %%rdx\n" -" addl %%eax, %%r15d\n" /* dist += hold & ((1 << op) - 1) */ - -".L_check_window:\n" -" movq %%rsi, %%r8\n" /* save in so from can use it's reg */ -" movq %%rdi, %%rax\n" -" subq 40(%%rsp), %%rax\n" /* nbytes = out - beg */ - -" cmpl %%r15d, %%eax\n" -" jb .L_clip_window\n" /* if (dist > nbytes) 4.2% */ - -" movl %%r14d, %%ecx\n" /* ecx = len */ -" movq %%rdi, %%rsi\n" -" subq %%r15, %%rsi\n" /* from = out - dist */ - -" sarl %%ecx\n" -" jnc .L_copy_two\n" /* if len % 2 == 0 */ - -" rep movsw\n" -" movb (%%rsi), %%al\n" -" movb %%al, (%%rdi)\n" -" incq %%rdi\n" - -" movq %%r8, %%rsi\n" /* move in back to %rsi, toss from */ -" jmp .L_while_test\n" - -".L_copy_two:\n" -" rep movsw\n" -" movq %%r8, %%rsi\n" /* move in back to %rsi, toss from */ -" jmp .L_while_test\n" - -".align 32,0x90\n" -".L_check_dist_one:\n" -" cmpl $1, %%r15d\n" /* if dist 1, is a memset */ -" jne .L_check_window\n" -" cmpq %%rdi, 40(%%rsp)\n" /* if out == beg, outside window */ -" je .L_check_window\n" - -" movl %%r14d, %%ecx\n" /* ecx = len */ -" movb -1(%%rdi), %%al\n" -" movb %%al, %%ah\n" - -" sarl %%ecx\n" -" jnc .L_set_two\n" -" movb %%al, (%%rdi)\n" -" incq %%rdi\n" - -".L_set_two:\n" -" rep stosw\n" -" jmp .L_while_test\n" - -".align 32,0x90\n" -".L_test_for_second_level_length:\n" -" testb $64, %%al\n" -" jnz .L_test_for_end_of_block\n" /* if ((op & 64) != 0) */ - -" xorl %%eax, %%eax\n" -" incl %%eax\n" -" shll %%cl, %%eax\n" -" decl %%eax\n" -" andl %%edx, %%eax\n" /* eax &= hold */ -" addl %%r14d, %%eax\n" /* eax += len */ -" movl (%%rbp,%%rax,4), %%eax\n" /* eax = lcode[val+(hold&mask[op])]*/ -" jmp .L_dolen\n" - -".align 32,0x90\n" -".L_test_for_second_level_dist:\n" -" testb $64, %%al\n" -" jnz .L_invalid_distance_code\n" /* if ((op & 64) != 0) */ - -" xorl %%eax, %%eax\n" -" incl %%eax\n" -" shll %%cl, %%eax\n" -" decl %%eax\n" -" andl %%edx, %%eax\n" /* eax &= hold */ -" addl %%r15d, %%eax\n" /* eax += dist */ -" movl (%%r11,%%rax,4), %%eax\n" /* eax = dcode[val+(hold&mask[op])]*/ -" jmp .L_dodist\n" - -".align 32,0x90\n" -".L_clip_window:\n" -" movl %%eax, %%ecx\n" /* ecx = nbytes */ -" movl 92(%%rsp), %%eax\n" /* eax = wsize, prepare for dist cmp */ -" negl %%ecx\n" /* nbytes = -nbytes */ - -" cmpl %%r15d, %%eax\n" -" jb .L_invalid_distance_too_far\n" /* if (dist > wsize) */ - -" addl %%r15d, %%ecx\n" /* nbytes = dist - nbytes */ -" cmpl $0, 96(%%rsp)\n" -" jne .L_wrap_around_window\n" /* if (write != 0) */ - -" movq 56(%%rsp), %%rsi\n" /* from = window */ -" subl %%ecx, %%eax\n" /* eax -= nbytes */ -" addq %%rax, %%rsi\n" /* from += wsize - nbytes */ - -" movl %%r14d, %%eax\n" /* eax = len */ -" cmpl %%ecx, %%r14d\n" -" jbe .L_do_copy\n" /* if (nbytes >= len) */ - -" subl %%ecx, %%eax\n" /* eax -= nbytes */ -" rep movsb\n" -" movq %%rdi, %%rsi\n" -" subq %%r15, %%rsi\n" /* from = &out[ -dist ] */ -" jmp .L_do_copy\n" - -".align 32,0x90\n" -".L_wrap_around_window:\n" -" movl 96(%%rsp), %%eax\n" /* eax = write */ -" cmpl %%eax, %%ecx\n" -" jbe .L_contiguous_in_window\n" /* if (write >= nbytes) */ - -" movl 92(%%rsp), %%esi\n" /* from = wsize */ -" addq 56(%%rsp), %%rsi\n" /* from += window */ -" addq %%rax, %%rsi\n" /* from += write */ -" subq %%rcx, %%rsi\n" /* from -= nbytes */ -" subl %%eax, %%ecx\n" /* nbytes -= write */ - -" movl %%r14d, %%eax\n" /* eax = len */ -" cmpl %%ecx, %%eax\n" -" jbe .L_do_copy\n" /* if (nbytes >= len) */ - -" subl %%ecx, %%eax\n" /* len -= nbytes */ -" rep movsb\n" -" movq 56(%%rsp), %%rsi\n" /* from = window */ -" movl 96(%%rsp), %%ecx\n" /* nbytes = write */ -" cmpl %%ecx, %%eax\n" -" jbe .L_do_copy\n" /* if (nbytes >= len) */ - -" subl %%ecx, %%eax\n" /* len -= nbytes */ -" rep movsb\n" -" movq %%rdi, %%rsi\n" -" subq %%r15, %%rsi\n" /* from = out - dist */ -" jmp .L_do_copy\n" - -".align 32,0x90\n" -".L_contiguous_in_window:\n" -" movq 56(%%rsp), %%rsi\n" /* rsi = window */ -" addq %%rax, %%rsi\n" -" subq %%rcx, %%rsi\n" /* from += write - nbytes */ - -" movl %%r14d, %%eax\n" /* eax = len */ -" cmpl %%ecx, %%eax\n" -" jbe .L_do_copy\n" /* if (nbytes >= len) */ - -" subl %%ecx, %%eax\n" /* len -= nbytes */ -" rep movsb\n" -" movq %%rdi, %%rsi\n" -" subq %%r15, %%rsi\n" /* from = out - dist */ -" jmp .L_do_copy\n" /* if (nbytes >= len) */ - -".align 32,0x90\n" -".L_do_copy:\n" -" movl %%eax, %%ecx\n" /* ecx = len */ -" rep movsb\n" - -" movq %%r8, %%rsi\n" /* move in back to %esi, toss from */ -" jmp .L_while_test\n" - -".L_test_for_end_of_block:\n" -" testb $32, %%al\n" -" jz .L_invalid_literal_length_code\n" -" movl $1, 116(%%rsp)\n" -" jmp .L_break_loop_with_status\n" - -".L_invalid_literal_length_code:\n" -" movl $2, 116(%%rsp)\n" -" jmp .L_break_loop_with_status\n" - -".L_invalid_distance_code:\n" -" movl $3, 116(%%rsp)\n" -" jmp .L_break_loop_with_status\n" - -".L_invalid_distance_too_far:\n" -" movl $4, 116(%%rsp)\n" -" jmp .L_break_loop_with_status\n" - -".L_break_loop:\n" -" movl $0, 116(%%rsp)\n" - -".L_break_loop_with_status:\n" -/* put in, out, bits, and hold back into ar and pop esp */ -" movq %%rsi, 16(%%rsp)\n" /* in */ -" movq %%rdi, 32(%%rsp)\n" /* out */ -" movl %%ebx, 88(%%rsp)\n" /* bits */ -" movq %%rdx, 80(%%rsp)\n" /* hold */ -" movq (%%rsp), %%rax\n" /* restore rbp and rsp */ -" movq 8(%%rsp), %%rbp\n" -" movq %%rax, %%rsp\n" - : - : "m" (ar) - : "memory", "%rax", "%rbx", "%rcx", "%rdx", "%rsi", "%rdi", - "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15" - ); -#elif ( defined( __GNUC__ ) || defined( __ICC ) ) && defined( __i386 ) - __asm__ __volatile__ ( -" leal %0, %%eax\n" -" movl %%esp, (%%eax)\n" /* save esp, ebp */ -" movl %%ebp, 4(%%eax)\n" -" movl %%eax, %%esp\n" -" movl 8(%%esp), %%esi\n" /* esi = in */ -" movl 16(%%esp), %%edi\n" /* edi = out */ -" movl 40(%%esp), %%edx\n" /* edx = hold */ -" movl 44(%%esp), %%ebx\n" /* ebx = bits */ -" movl 32(%%esp), %%ebp\n" /* ebp = lcode */ - -" cld\n" -" jmp .L_do_loop\n" - -".align 32,0x90\n" -".L_while_test:\n" -" cmpl %%edi, 24(%%esp)\n" /* out < end */ -" jbe .L_break_loop\n" -" cmpl %%esi, 12(%%esp)\n" /* in < last */ -" jbe .L_break_loop\n" - -".L_do_loop:\n" -" cmpb $15, %%bl\n" -" ja .L_get_length_code\n" /* if (15 < bits) */ - -" xorl %%eax, %%eax\n" -" lodsw\n" /* al = *(ushort *)in++ */ -" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */ -" addb $16, %%bl\n" /* bits += 16 */ -" shll %%cl, %%eax\n" -" orl %%eax, %%edx\n" /* hold |= *((ushort *)in)++ << bits */ - -".L_get_length_code:\n" -" movl 56(%%esp), %%eax\n" /* eax = lmask */ -" andl %%edx, %%eax\n" /* eax &= hold */ -" movl (%%ebp,%%eax,4), %%eax\n" /* eax = lcode[hold & lmask] */ - -".L_dolen:\n" -" movb %%ah, %%cl\n" /* cl = this.bits */ -" subb %%ah, %%bl\n" /* bits -= this.bits */ -" shrl %%cl, %%edx\n" /* hold >>= this.bits */ - -" testb %%al, %%al\n" -" jnz .L_test_for_length_base\n" /* if (op != 0) 45.7% */ - -" shrl $16, %%eax\n" /* output this.val char */ -" stosb\n" -" jmp .L_while_test\n" - -".align 32,0x90\n" -".L_test_for_length_base:\n" -" movl %%eax, %%ecx\n" /* len = this */ -" shrl $16, %%ecx\n" /* len = this.val */ -" movl %%ecx, 64(%%esp)\n" /* save len */ -" movb %%al, %%cl\n" - -" testb $16, %%al\n" -" jz .L_test_for_second_level_length\n" /* if ((op & 16) == 0) 8% */ -" andb $15, %%cl\n" /* op &= 15 */ -" jz .L_decode_distance\n" /* if (!op) */ -" cmpb %%cl, %%bl\n" -" jae .L_add_bits_to_len\n" /* if (op <= bits) */ - -" movb %%cl, %%ch\n" /* stash op in ch, freeing cl */ -" xorl %%eax, %%eax\n" -" lodsw\n" /* al = *(ushort *)in++ */ -" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */ -" addb $16, %%bl\n" /* bits += 16 */ -" shll %%cl, %%eax\n" -" orl %%eax, %%edx\n" /* hold |= *((ushort *)in)++ << bits */ -" movb %%ch, %%cl\n" /* move op back to ecx */ - -".L_add_bits_to_len:\n" -" subb %%cl, %%bl\n" -" xorl %%eax, %%eax\n" -" incl %%eax\n" -" shll %%cl, %%eax\n" -" decl %%eax\n" -" andl %%edx, %%eax\n" /* eax &= hold */ -" shrl %%cl, %%edx\n" -" addl %%eax, 64(%%esp)\n" /* len += hold & mask[op] */ - -".L_decode_distance:\n" -" cmpb $15, %%bl\n" -" ja .L_get_distance_code\n" /* if (15 < bits) */ - -" xorl %%eax, %%eax\n" -" lodsw\n" /* al = *(ushort *)in++ */ -" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */ -" addb $16, %%bl\n" /* bits += 16 */ -" shll %%cl, %%eax\n" -" orl %%eax, %%edx\n" /* hold |= *((ushort *)in)++ << bits */ - -".L_get_distance_code:\n" -" movl 60(%%esp), %%eax\n" /* eax = dmask */ -" movl 36(%%esp), %%ecx\n" /* ecx = dcode */ -" andl %%edx, %%eax\n" /* eax &= hold */ -" movl (%%ecx,%%eax,4), %%eax\n"/* eax = dcode[hold & dmask] */ - -".L_dodist:\n" -" movl %%eax, %%ebp\n" /* dist = this */ -" shrl $16, %%ebp\n" /* dist = this.val */ -" movb %%ah, %%cl\n" -" subb %%ah, %%bl\n" /* bits -= this.bits */ -" shrl %%cl, %%edx\n" /* hold >>= this.bits */ -" movb %%al, %%cl\n" /* cl = this.op */ - -" testb $16, %%al\n" /* if ((op & 16) == 0) */ -" jz .L_test_for_second_level_dist\n" -" andb $15, %%cl\n" /* op &= 15 */ -" jz .L_check_dist_one\n" -" cmpb %%cl, %%bl\n" -" jae .L_add_bits_to_dist\n" /* if (op <= bits) 97.6% */ - -" movb %%cl, %%ch\n" /* stash op in ch, freeing cl */ -" xorl %%eax, %%eax\n" -" lodsw\n" /* al = *(ushort *)in++ */ -" movb %%bl, %%cl\n" /* cl = bits, needs it for shifting */ -" addb $16, %%bl\n" /* bits += 16 */ -" shll %%cl, %%eax\n" -" orl %%eax, %%edx\n" /* hold |= *((ushort *)in)++ << bits */ -" movb %%ch, %%cl\n" /* move op back to ecx */ - -".L_add_bits_to_dist:\n" -" subb %%cl, %%bl\n" -" xorl %%eax, %%eax\n" -" incl %%eax\n" -" shll %%cl, %%eax\n" -" decl %%eax\n" /* (1 << op) - 1 */ -" andl %%edx, %%eax\n" /* eax &= hold */ -" shrl %%cl, %%edx\n" -" addl %%eax, %%ebp\n" /* dist += hold & ((1 << op) - 1) */ - -".L_check_window:\n" -" movl %%esi, 8(%%esp)\n" /* save in so from can use it's reg */ -" movl %%edi, %%eax\n" -" subl 20(%%esp), %%eax\n" /* nbytes = out - beg */ - -" cmpl %%ebp, %%eax\n" -" jb .L_clip_window\n" /* if (dist > nbytes) 4.2% */ - -" movl 64(%%esp), %%ecx\n" /* ecx = len */ -" movl %%edi, %%esi\n" -" subl %%ebp, %%esi\n" /* from = out - dist */ - -" sarl %%ecx\n" -" jnc .L_copy_two\n" /* if len % 2 == 0 */ - -" rep movsw\n" -" movb (%%esi), %%al\n" -" movb %%al, (%%edi)\n" -" incl %%edi\n" - -" movl 8(%%esp), %%esi\n" /* move in back to %esi, toss from */ -" movl 32(%%esp), %%ebp\n" /* ebp = lcode */ -" jmp .L_while_test\n" - -".L_copy_two:\n" -" rep movsw\n" -" movl 8(%%esp), %%esi\n" /* move in back to %esi, toss from */ -" movl 32(%%esp), %%ebp\n" /* ebp = lcode */ -" jmp .L_while_test\n" - -".align 32,0x90\n" -".L_check_dist_one:\n" -" cmpl $1, %%ebp\n" /* if dist 1, is a memset */ -" jne .L_check_window\n" -" cmpl %%edi, 20(%%esp)\n" -" je .L_check_window\n" /* out == beg, if outside window */ - -" movl 64(%%esp), %%ecx\n" /* ecx = len */ -" movb -1(%%edi), %%al\n" -" movb %%al, %%ah\n" - -" sarl %%ecx\n" -" jnc .L_set_two\n" -" movb %%al, (%%edi)\n" -" incl %%edi\n" - -".L_set_two:\n" -" rep stosw\n" -" movl 32(%%esp), %%ebp\n" /* ebp = lcode */ -" jmp .L_while_test\n" - -".align 32,0x90\n" -".L_test_for_second_level_length:\n" -" testb $64, %%al\n" -" jnz .L_test_for_end_of_block\n" /* if ((op & 64) != 0) */ - -" xorl %%eax, %%eax\n" -" incl %%eax\n" -" shll %%cl, %%eax\n" -" decl %%eax\n" -" andl %%edx, %%eax\n" /* eax &= hold */ -" addl 64(%%esp), %%eax\n" /* eax += len */ -" movl (%%ebp,%%eax,4), %%eax\n" /* eax = lcode[val+(hold&mask[op])]*/ -" jmp .L_dolen\n" - -".align 32,0x90\n" -".L_test_for_second_level_dist:\n" -" testb $64, %%al\n" -" jnz .L_invalid_distance_code\n" /* if ((op & 64) != 0) */ - -" xorl %%eax, %%eax\n" -" incl %%eax\n" -" shll %%cl, %%eax\n" -" decl %%eax\n" -" andl %%edx, %%eax\n" /* eax &= hold */ -" addl %%ebp, %%eax\n" /* eax += dist */ -" movl 36(%%esp), %%ecx\n" /* ecx = dcode */ -" movl (%%ecx,%%eax,4), %%eax\n" /* eax = dcode[val+(hold&mask[op])]*/ -" jmp .L_dodist\n" - -".align 32,0x90\n" -".L_clip_window:\n" -" movl %%eax, %%ecx\n" -" movl 48(%%esp), %%eax\n" /* eax = wsize */ -" negl %%ecx\n" /* nbytes = -nbytes */ -" movl 28(%%esp), %%esi\n" /* from = window */ - -" cmpl %%ebp, %%eax\n" -" jb .L_invalid_distance_too_far\n" /* if (dist > wsize) */ - -" addl %%ebp, %%ecx\n" /* nbytes = dist - nbytes */ -" cmpl $0, 52(%%esp)\n" -" jne .L_wrap_around_window\n" /* if (write != 0) */ - -" subl %%ecx, %%eax\n" -" addl %%eax, %%esi\n" /* from += wsize - nbytes */ - -" movl 64(%%esp), %%eax\n" /* eax = len */ -" cmpl %%ecx, %%eax\n" -" jbe .L_do_copy\n" /* if (nbytes >= len) */ - -" subl %%ecx, %%eax\n" /* len -= nbytes */ -" rep movsb\n" -" movl %%edi, %%esi\n" -" subl %%ebp, %%esi\n" /* from = out - dist */ -" jmp .L_do_copy\n" - -".align 32,0x90\n" -".L_wrap_around_window:\n" -" movl 52(%%esp), %%eax\n" /* eax = write */ -" cmpl %%eax, %%ecx\n" -" jbe .L_contiguous_in_window\n" /* if (write >= nbytes) */ - -" addl 48(%%esp), %%esi\n" /* from += wsize */ -" addl %%eax, %%esi\n" /* from += write */ -" subl %%ecx, %%esi\n" /* from -= nbytes */ -" subl %%eax, %%ecx\n" /* nbytes -= write */ - -" movl 64(%%esp), %%eax\n" /* eax = len */ -" cmpl %%ecx, %%eax\n" -" jbe .L_do_copy\n" /* if (nbytes >= len) */ - -" subl %%ecx, %%eax\n" /* len -= nbytes */ -" rep movsb\n" -" movl 28(%%esp), %%esi\n" /* from = window */ -" movl 52(%%esp), %%ecx\n" /* nbytes = write */ -" cmpl %%ecx, %%eax\n" -" jbe .L_do_copy\n" /* if (nbytes >= len) */ - -" subl %%ecx, %%eax\n" /* len -= nbytes */ -" rep movsb\n" -" movl %%edi, %%esi\n" -" subl %%ebp, %%esi\n" /* from = out - dist */ -" jmp .L_do_copy\n" - -".align 32,0x90\n" -".L_contiguous_in_window:\n" -" addl %%eax, %%esi\n" -" subl %%ecx, %%esi\n" /* from += write - nbytes */ - -" movl 64(%%esp), %%eax\n" /* eax = len */ -" cmpl %%ecx, %%eax\n" -" jbe .L_do_copy\n" /* if (nbytes >= len) */ - -" subl %%ecx, %%eax\n" /* len -= nbytes */ -" rep movsb\n" -" movl %%edi, %%esi\n" -" subl %%ebp, %%esi\n" /* from = out - dist */ -" jmp .L_do_copy\n" /* if (nbytes >= len) */ - -".align 32,0x90\n" -".L_do_copy:\n" -" movl %%eax, %%ecx\n" -" rep movsb\n" - -" movl 8(%%esp), %%esi\n" /* move in back to %esi, toss from */ -" movl 32(%%esp), %%ebp\n" /* ebp = lcode */ -" jmp .L_while_test\n" - -".L_test_for_end_of_block:\n" -" testb $32, %%al\n" -" jz .L_invalid_literal_length_code\n" -" movl $1, 72(%%esp)\n" -" jmp .L_break_loop_with_status\n" - -".L_invalid_literal_length_code:\n" -" movl $2, 72(%%esp)\n" -" jmp .L_break_loop_with_status\n" - -".L_invalid_distance_code:\n" -" movl $3, 72(%%esp)\n" -" jmp .L_break_loop_with_status\n" - -".L_invalid_distance_too_far:\n" -" movl 8(%%esp), %%esi\n" -" movl $4, 72(%%esp)\n" -" jmp .L_break_loop_with_status\n" - -".L_break_loop:\n" -" movl $0, 72(%%esp)\n" - -".L_break_loop_with_status:\n" -/* put in, out, bits, and hold back into ar and pop esp */ -" movl %%esi, 8(%%esp)\n" /* save in */ -" movl %%edi, 16(%%esp)\n" /* save out */ -" movl %%ebx, 44(%%esp)\n" /* save bits */ -" movl %%edx, 40(%%esp)\n" /* save hold */ -" movl 4(%%esp), %%ebp\n" /* restore esp, ebp */ -" movl (%%esp), %%esp\n" - : - : "m" (ar) - : "memory", "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi" - ); -#elif defined( _MSC_VER ) && ! defined( _M_AMD64 ) - __asm { - lea eax, ar - mov [eax], esp /* save esp, ebp */ - mov [eax+4], ebp - mov esp, eax - mov esi, [esp+8] /* esi = in */ - mov edi, [esp+16] /* edi = out */ - mov edx, [esp+40] /* edx = hold */ - mov ebx, [esp+44] /* ebx = bits */ - mov ebp, [esp+32] /* ebp = lcode */ - - cld - jmp L_do_loop - -ALIGN 4 -L_while_test: - cmp [esp+24], edi - jbe L_break_loop - cmp [esp+12], esi - jbe L_break_loop - -L_do_loop: - cmp bl, 15 - ja L_get_length_code /* if (15 < bits) */ - - xor eax, eax - lodsw /* al = *(ushort *)in++ */ - mov cl, bl /* cl = bits, needs it for shifting */ - add bl, 16 /* bits += 16 */ - shl eax, cl - or edx, eax /* hold |= *((ushort *)in)++ << bits */ - -L_get_length_code: - mov eax, [esp+56] /* eax = lmask */ - and eax, edx /* eax &= hold */ - mov eax, [ebp+eax*4] /* eax = lcode[hold & lmask] */ - -L_dolen: - mov cl, ah /* cl = this.bits */ - sub bl, ah /* bits -= this.bits */ - shr edx, cl /* hold >>= this.bits */ - - test al, al - jnz L_test_for_length_base /* if (op != 0) 45.7% */ - - shr eax, 16 /* output this.val char */ - stosb - jmp L_while_test - -ALIGN 4 -L_test_for_length_base: - mov ecx, eax /* len = this */ - shr ecx, 16 /* len = this.val */ - mov [esp+64], ecx /* save len */ - mov cl, al - - test al, 16 - jz L_test_for_second_level_length /* if ((op & 16) == 0) 8% */ - and cl, 15 /* op &= 15 */ - jz L_decode_distance /* if (!op) */ - cmp bl, cl - jae L_add_bits_to_len /* if (op <= bits) */ - - mov ch, cl /* stash op in ch, freeing cl */ - xor eax, eax - lodsw /* al = *(ushort *)in++ */ - mov cl, bl /* cl = bits, needs it for shifting */ - add bl, 16 /* bits += 16 */ - shl eax, cl - or edx, eax /* hold |= *((ushort *)in)++ << bits */ - mov cl, ch /* move op back to ecx */ - -L_add_bits_to_len: - sub bl, cl - xor eax, eax - inc eax - shl eax, cl - dec eax - and eax, edx /* eax &= hold */ - shr edx, cl - add [esp+64], eax /* len += hold & mask[op] */ - -L_decode_distance: - cmp bl, 15 - ja L_get_distance_code /* if (15 < bits) */ - - xor eax, eax - lodsw /* al = *(ushort *)in++ */ - mov cl, bl /* cl = bits, needs it for shifting */ - add bl, 16 /* bits += 16 */ - shl eax, cl - or edx, eax /* hold |= *((ushort *)in)++ << bits */ - -L_get_distance_code: - mov eax, [esp+60] /* eax = dmask */ - mov ecx, [esp+36] /* ecx = dcode */ - and eax, edx /* eax &= hold */ - mov eax, [ecx+eax*4]/* eax = dcode[hold & dmask] */ - -L_dodist: - mov ebp, eax /* dist = this */ - shr ebp, 16 /* dist = this.val */ - mov cl, ah - sub bl, ah /* bits -= this.bits */ - shr edx, cl /* hold >>= this.bits */ - mov cl, al /* cl = this.op */ - - test al, 16 /* if ((op & 16) == 0) */ - jz L_test_for_second_level_dist - and cl, 15 /* op &= 15 */ - jz L_check_dist_one - cmp bl, cl - jae L_add_bits_to_dist /* if (op <= bits) 97.6% */ - - mov ch, cl /* stash op in ch, freeing cl */ - xor eax, eax - lodsw /* al = *(ushort *)in++ */ - mov cl, bl /* cl = bits, needs it for shifting */ - add bl, 16 /* bits += 16 */ - shl eax, cl - or edx, eax /* hold |= *((ushort *)in)++ << bits */ - mov cl, ch /* move op back to ecx */ - -L_add_bits_to_dist: - sub bl, cl - xor eax, eax - inc eax - shl eax, cl - dec eax /* (1 << op) - 1 */ - and eax, edx /* eax &= hold */ - shr edx, cl - add ebp, eax /* dist += hold & ((1 << op) - 1) */ - -L_check_window: - mov [esp+8], esi /* save in so from can use it's reg */ - mov eax, edi - sub eax, [esp+20] /* nbytes = out - beg */ - - cmp eax, ebp - jb L_clip_window /* if (dist > nbytes) 4.2% */ - - mov ecx, [esp+64] /* ecx = len */ - mov esi, edi - sub esi, ebp /* from = out - dist */ - - sar ecx, 1 - jnc L_copy_two - - rep movsw - mov al, [esi] - mov [edi], al - inc edi - - mov esi, [esp+8] /* move in back to %esi, toss from */ - mov ebp, [esp+32] /* ebp = lcode */ - jmp L_while_test - -L_copy_two: - rep movsw - mov esi, [esp+8] /* move in back to %esi, toss from */ - mov ebp, [esp+32] /* ebp = lcode */ - jmp L_while_test - -ALIGN 4 -L_check_dist_one: - cmp ebp, 1 /* if dist 1, is a memset */ - jne L_check_window - cmp [esp+20], edi - je L_check_window /* out == beg, if outside window */ - - mov ecx, [esp+64] /* ecx = len */ - mov al, [edi-1] - mov ah, al - - sar ecx, 1 - jnc L_set_two - mov [edi], al /* memset out with from[-1] */ - inc edi - -L_set_two: - rep stosw - mov ebp, [esp+32] /* ebp = lcode */ - jmp L_while_test - -ALIGN 4 -L_test_for_second_level_length: - test al, 64 - jnz L_test_for_end_of_block /* if ((op & 64) != 0) */ - - xor eax, eax - inc eax - shl eax, cl - dec eax - and eax, edx /* eax &= hold */ - add eax, [esp+64] /* eax += len */ - mov eax, [ebp+eax*4] /* eax = lcode[val+(hold&mask[op])]*/ - jmp L_dolen - -ALIGN 4 -L_test_for_second_level_dist: - test al, 64 - jnz L_invalid_distance_code /* if ((op & 64) != 0) */ - - xor eax, eax - inc eax - shl eax, cl - dec eax - and eax, edx /* eax &= hold */ - add eax, ebp /* eax += dist */ - mov ecx, [esp+36] /* ecx = dcode */ - mov eax, [ecx+eax*4] /* eax = dcode[val+(hold&mask[op])]*/ - jmp L_dodist - -ALIGN 4 -L_clip_window: - mov ecx, eax - mov eax, [esp+48] /* eax = wsize */ - neg ecx /* nbytes = -nbytes */ - mov esi, [esp+28] /* from = window */ - - cmp eax, ebp - jb L_invalid_distance_too_far /* if (dist > wsize) */ - - add ecx, ebp /* nbytes = dist - nbytes */ - cmp dword ptr [esp+52], 0 - jne L_wrap_around_window /* if (write != 0) */ - - sub eax, ecx - add esi, eax /* from += wsize - nbytes */ - - mov eax, [esp+64] /* eax = len */ - cmp eax, ecx - jbe L_do_copy /* if (nbytes >= len) */ - - sub eax, ecx /* len -= nbytes */ - rep movsb - mov esi, edi - sub esi, ebp /* from = out - dist */ - jmp L_do_copy - -ALIGN 4 -L_wrap_around_window: - mov eax, [esp+52] /* eax = write */ - cmp ecx, eax - jbe L_contiguous_in_window /* if (write >= nbytes) */ - - add esi, [esp+48] /* from += wsize */ - add esi, eax /* from += write */ - sub esi, ecx /* from -= nbytes */ - sub ecx, eax /* nbytes -= write */ - - mov eax, [esp+64] /* eax = len */ - cmp eax, ecx - jbe L_do_copy /* if (nbytes >= len) */ - - sub eax, ecx /* len -= nbytes */ - rep movsb - mov esi, [esp+28] /* from = window */ - mov ecx, [esp+52] /* nbytes = write */ - cmp eax, ecx - jbe L_do_copy /* if (nbytes >= len) */ - - sub eax, ecx /* len -= nbytes */ - rep movsb - mov esi, edi - sub esi, ebp /* from = out - dist */ - jmp L_do_copy - -ALIGN 4 -L_contiguous_in_window: - add esi, eax - sub esi, ecx /* from += write - nbytes */ - - mov eax, [esp+64] /* eax = len */ - cmp eax, ecx - jbe L_do_copy /* if (nbytes >= len) */ - - sub eax, ecx /* len -= nbytes */ - rep movsb - mov esi, edi - sub esi, ebp /* from = out - dist */ - jmp L_do_copy - -ALIGN 4 -L_do_copy: - mov ecx, eax - rep movsb - - mov esi, [esp+8] /* move in back to %esi, toss from */ - mov ebp, [esp+32] /* ebp = lcode */ - jmp L_while_test - -L_test_for_end_of_block: - test al, 32 - jz L_invalid_literal_length_code - mov dword ptr [esp+72], 1 - jmp L_break_loop_with_status - -L_invalid_literal_length_code: - mov dword ptr [esp+72], 2 - jmp L_break_loop_with_status - -L_invalid_distance_code: - mov dword ptr [esp+72], 3 - jmp L_break_loop_with_status - -L_invalid_distance_too_far: - mov esi, [esp+4] - mov dword ptr [esp+72], 4 - jmp L_break_loop_with_status - -L_break_loop: - mov dword ptr [esp+72], 0 - -L_break_loop_with_status: -/* put in, out, bits, and hold back into ar and pop esp */ - mov [esp+8], esi /* save in */ - mov [esp+16], edi /* save out */ - mov [esp+44], ebx /* save bits */ - mov [esp+40], edx /* save hold */ - mov ebp, [esp+4] /* restore esp, ebp */ - mov esp, [esp] - } -#else -#error "x86 architecture not defined" -#endif - - if (ar.status > 1) { - if (ar.status == 2) - strm->msg = "invalid literal/length code"; - else if (ar.status == 3) - strm->msg = "invalid distance code"; - else - strm->msg = "invalid distance too far back"; - state->mode = BAD; - } - else if ( ar.status == 1 ) { - state->mode = TYPE; - } - - /* return unused bytes (on entry, bits < 8, so in won't go too far back) */ - ar.len = ar.bits >> 3; - ar.in -= ar.len; - ar.bits -= ar.len << 3; - ar.hold &= (1U << ar.bits) - 1; - - /* update state and return */ - strm->next_in = ar.in; - strm->next_out = ar.out; - strm->avail_in = (unsigned)(ar.in < ar.last ? - PAD_AVAIL_IN + (ar.last - ar.in) : - PAD_AVAIL_IN - (ar.in - ar.last)); - strm->avail_out = (unsigned)(ar.out < ar.end ? - PAD_AVAIL_OUT + (ar.end - ar.out) : - PAD_AVAIL_OUT - (ar.out - ar.end)); - state->hold = ar.hold; - state->bits = ar.bits; - return; -} - diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/inflate86/inffast.S b/src/beast/test/zlib/zlib-1.2.8/contrib/inflate86/inffast.S deleted file mode 100644 index 2245a2905bd..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/inflate86/inffast.S +++ /dev/null @@ -1,1368 +0,0 @@ -/* - * inffast.S is a hand tuned assembler version of: - * - * inffast.c -- fast decoding - * Copyright (C) 1995-2003 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - * - * Copyright (C) 2003 Chris Anderson - * Please use the copyright conditions above. - * - * This version (Jan-23-2003) of inflate_fast was coded and tested under - * GNU/Linux on a pentium 3, using the gcc-3.2 compiler distribution. On that - * machine, I found that gzip style archives decompressed about 20% faster than - * the gcc-3.2 -O3 -fomit-frame-pointer compiled version. Your results will - * depend on how large of a buffer is used for z_stream.next_in & next_out - * (8K-32K worked best for my 256K cpu cache) and how much overhead there is in - * stream processing I/O and crc32/addler32. In my case, this routine used - * 70% of the cpu time and crc32 used 20%. - * - * I am confident that this version will work in the general case, but I have - * not tested a wide variety of datasets or a wide variety of platforms. - * - * Jan-24-2003 -- Added -DUSE_MMX define for slightly faster inflating. - * It should be a runtime flag instead of compile time flag... - * - * Jan-26-2003 -- Added runtime check for MMX support with cpuid instruction. - * With -DUSE_MMX, only MMX code is compiled. With -DNO_MMX, only non-MMX code - * is compiled. Without either option, runtime detection is enabled. Runtime - * detection should work on all modern cpus and the recomended algorithm (flip - * ID bit on eflags and then use the cpuid instruction) is used in many - * multimedia applications. Tested under win2k with gcc-2.95 and gas-2.12 - * distributed with cygwin3. Compiling with gcc-2.95 -c inffast.S -o - * inffast.obj generates a COFF object which can then be linked with MSVC++ - * compiled code. Tested under FreeBSD 4.7 with gcc-2.95. - * - * Jan-28-2003 -- Tested Athlon XP... MMX mode is slower than no MMX (and - * slower than compiler generated code). Adjusted cpuid check to use the MMX - * code only for Pentiums < P4 until I have more data on the P4. Speed - * improvment is only about 15% on the Athlon when compared with code generated - * with MSVC++. Not sure yet, but I think the P4 will also be slower using the - * MMX mode because many of it's x86 ALU instructions execute in .5 cycles and - * have less latency than MMX ops. Added code to buffer the last 11 bytes of - * the input stream since the MMX code grabs bits in chunks of 32, which - * differs from the inffast.c algorithm. I don't think there would have been - * read overruns where a page boundary was crossed (a segfault), but there - * could have been overruns when next_in ends on unaligned memory (unintialized - * memory read). - * - * Mar-13-2003 -- P4 MMX is slightly slower than P4 NO_MMX. I created a C - * version of the non-MMX code so that it doesn't depend on zstrm and zstate - * structure offsets which are hard coded in this file. This was last tested - * with zlib-1.2.0 which is currently in beta testing, newer versions of this - * and inffas86.c can be found at http://www.eetbeetee.com/zlib/ and - * http://www.charm.net/~christop/zlib/ - */ - - -/* - * if you have underscore linking problems (_inflate_fast undefined), try - * using -DGAS_COFF - */ -#if ! defined( GAS_COFF ) && ! defined( GAS_ELF ) - -#if defined( WIN32 ) || defined( __CYGWIN__ ) -#define GAS_COFF /* windows object format */ -#else -#define GAS_ELF -#endif - -#endif /* ! GAS_COFF && ! GAS_ELF */ - - -#if defined( GAS_COFF ) - -/* coff externals have underscores */ -#define inflate_fast _inflate_fast -#define inflate_fast_use_mmx _inflate_fast_use_mmx - -#endif /* GAS_COFF */ - - -.file "inffast.S" - -.globl inflate_fast - -.text -.align 4,0 -.L_invalid_literal_length_code_msg: -.string "invalid literal/length code" - -.align 4,0 -.L_invalid_distance_code_msg: -.string "invalid distance code" - -.align 4,0 -.L_invalid_distance_too_far_msg: -.string "invalid distance too far back" - -#if ! defined( NO_MMX ) -.align 4,0 -.L_mask: /* mask[N] = ( 1 << N ) - 1 */ -.long 0 -.long 1 -.long 3 -.long 7 -.long 15 -.long 31 -.long 63 -.long 127 -.long 255 -.long 511 -.long 1023 -.long 2047 -.long 4095 -.long 8191 -.long 16383 -.long 32767 -.long 65535 -.long 131071 -.long 262143 -.long 524287 -.long 1048575 -.long 2097151 -.long 4194303 -.long 8388607 -.long 16777215 -.long 33554431 -.long 67108863 -.long 134217727 -.long 268435455 -.long 536870911 -.long 1073741823 -.long 2147483647 -.long 4294967295 -#endif /* NO_MMX */ - -.text - -/* - * struct z_stream offsets, in zlib.h - */ -#define next_in_strm 0 /* strm->next_in */ -#define avail_in_strm 4 /* strm->avail_in */ -#define next_out_strm 12 /* strm->next_out */ -#define avail_out_strm 16 /* strm->avail_out */ -#define msg_strm 24 /* strm->msg */ -#define state_strm 28 /* strm->state */ - -/* - * struct inflate_state offsets, in inflate.h - */ -#define mode_state 0 /* state->mode */ -#define wsize_state 32 /* state->wsize */ -#define write_state 40 /* state->write */ -#define window_state 44 /* state->window */ -#define hold_state 48 /* state->hold */ -#define bits_state 52 /* state->bits */ -#define lencode_state 68 /* state->lencode */ -#define distcode_state 72 /* state->distcode */ -#define lenbits_state 76 /* state->lenbits */ -#define distbits_state 80 /* state->distbits */ - -/* - * inflate_fast's activation record - */ -#define local_var_size 64 /* how much local space for vars */ -#define strm_sp 88 /* first arg: z_stream * (local_var_size + 24) */ -#define start_sp 92 /* second arg: unsigned int (local_var_size + 28) */ - -/* - * offsets for local vars on stack - */ -#define out 60 /* unsigned char* */ -#define window 56 /* unsigned char* */ -#define wsize 52 /* unsigned int */ -#define write 48 /* unsigned int */ -#define in 44 /* unsigned char* */ -#define beg 40 /* unsigned char* */ -#define buf 28 /* char[ 12 ] */ -#define len 24 /* unsigned int */ -#define last 20 /* unsigned char* */ -#define end 16 /* unsigned char* */ -#define dcode 12 /* code* */ -#define lcode 8 /* code* */ -#define dmask 4 /* unsigned int */ -#define lmask 0 /* unsigned int */ - -/* - * typedef enum inflate_mode consts, in inflate.h - */ -#define INFLATE_MODE_TYPE 11 /* state->mode flags enum-ed in inflate.h */ -#define INFLATE_MODE_BAD 26 - - -#if ! defined( USE_MMX ) && ! defined( NO_MMX ) - -#define RUN_TIME_MMX - -#define CHECK_MMX 1 -#define DO_USE_MMX 2 -#define DONT_USE_MMX 3 - -.globl inflate_fast_use_mmx - -.data - -.align 4,0 -inflate_fast_use_mmx: /* integer flag for run time control 1=check,2=mmx,3=no */ -.long CHECK_MMX - -#if defined( GAS_ELF ) -/* elf info */ -.type inflate_fast_use_mmx,@object -.size inflate_fast_use_mmx,4 -#endif - -#endif /* RUN_TIME_MMX */ - -#if defined( GAS_COFF ) -/* coff info: scl 2 = extern, type 32 = function */ -.def inflate_fast; .scl 2; .type 32; .endef -#endif - -.text - -.align 32,0x90 -inflate_fast: - pushl %edi - pushl %esi - pushl %ebp - pushl %ebx - pushf /* save eflags (strm_sp, state_sp assumes this is 32 bits) */ - subl $local_var_size, %esp - cld - -#define strm_r %esi -#define state_r %edi - - movl strm_sp(%esp), strm_r - movl state_strm(strm_r), state_r - - /* in = strm->next_in; - * out = strm->next_out; - * last = in + strm->avail_in - 11; - * beg = out - (start - strm->avail_out); - * end = out + (strm->avail_out - 257); - */ - movl avail_in_strm(strm_r), %edx - movl next_in_strm(strm_r), %eax - - addl %eax, %edx /* avail_in += next_in */ - subl $11, %edx /* avail_in -= 11 */ - - movl %eax, in(%esp) - movl %edx, last(%esp) - - movl start_sp(%esp), %ebp - movl avail_out_strm(strm_r), %ecx - movl next_out_strm(strm_r), %ebx - - subl %ecx, %ebp /* start -= avail_out */ - negl %ebp /* start = -start */ - addl %ebx, %ebp /* start += next_out */ - - subl $257, %ecx /* avail_out -= 257 */ - addl %ebx, %ecx /* avail_out += out */ - - movl %ebx, out(%esp) - movl %ebp, beg(%esp) - movl %ecx, end(%esp) - - /* wsize = state->wsize; - * write = state->write; - * window = state->window; - * hold = state->hold; - * bits = state->bits; - * lcode = state->lencode; - * dcode = state->distcode; - * lmask = ( 1 << state->lenbits ) - 1; - * dmask = ( 1 << state->distbits ) - 1; - */ - - movl lencode_state(state_r), %eax - movl distcode_state(state_r), %ecx - - movl %eax, lcode(%esp) - movl %ecx, dcode(%esp) - - movl $1, %eax - movl lenbits_state(state_r), %ecx - shll %cl, %eax - decl %eax - movl %eax, lmask(%esp) - - movl $1, %eax - movl distbits_state(state_r), %ecx - shll %cl, %eax - decl %eax - movl %eax, dmask(%esp) - - movl wsize_state(state_r), %eax - movl write_state(state_r), %ecx - movl window_state(state_r), %edx - - movl %eax, wsize(%esp) - movl %ecx, write(%esp) - movl %edx, window(%esp) - - movl hold_state(state_r), %ebp - movl bits_state(state_r), %ebx - -#undef strm_r -#undef state_r - -#define in_r %esi -#define from_r %esi -#define out_r %edi - - movl in(%esp), in_r - movl last(%esp), %ecx - cmpl in_r, %ecx - ja .L_align_long /* if in < last */ - - addl $11, %ecx /* ecx = &in[ avail_in ] */ - subl in_r, %ecx /* ecx = avail_in */ - movl $12, %eax - subl %ecx, %eax /* eax = 12 - avail_in */ - leal buf(%esp), %edi - rep movsb /* memcpy( buf, in, avail_in ) */ - movl %eax, %ecx - xorl %eax, %eax - rep stosb /* memset( &buf[ avail_in ], 0, 12 - avail_in ) */ - leal buf(%esp), in_r /* in = buf */ - movl in_r, last(%esp) /* last = in, do just one iteration */ - jmp .L_is_aligned - - /* align in_r on long boundary */ -.L_align_long: - testl $3, in_r - jz .L_is_aligned - xorl %eax, %eax - movb (in_r), %al - incl in_r - movl %ebx, %ecx - addl $8, %ebx - shll %cl, %eax - orl %eax, %ebp - jmp .L_align_long - -.L_is_aligned: - movl out(%esp), out_r - -#if defined( NO_MMX ) - jmp .L_do_loop -#endif - -#if defined( USE_MMX ) - jmp .L_init_mmx -#endif - -/*** Runtime MMX check ***/ - -#if defined( RUN_TIME_MMX ) -.L_check_mmx: - cmpl $DO_USE_MMX, inflate_fast_use_mmx - je .L_init_mmx - ja .L_do_loop /* > 2 */ - - pushl %eax - pushl %ebx - pushl %ecx - pushl %edx - pushf - movl (%esp), %eax /* copy eflags to eax */ - xorl $0x200000, (%esp) /* try toggling ID bit of eflags (bit 21) - * to see if cpu supports cpuid... - * ID bit method not supported by NexGen but - * bios may load a cpuid instruction and - * cpuid may be disabled on Cyrix 5-6x86 */ - popf - pushf - popl %edx /* copy new eflags to edx */ - xorl %eax, %edx /* test if ID bit is flipped */ - jz .L_dont_use_mmx /* not flipped if zero */ - xorl %eax, %eax - cpuid - cmpl $0x756e6547, %ebx /* check for GenuineIntel in ebx,ecx,edx */ - jne .L_dont_use_mmx - cmpl $0x6c65746e, %ecx - jne .L_dont_use_mmx - cmpl $0x49656e69, %edx - jne .L_dont_use_mmx - movl $1, %eax - cpuid /* get cpu features */ - shrl $8, %eax - andl $15, %eax - cmpl $6, %eax /* check for Pentium family, is 0xf for P4 */ - jne .L_dont_use_mmx - testl $0x800000, %edx /* test if MMX feature is set (bit 23) */ - jnz .L_use_mmx - jmp .L_dont_use_mmx -.L_use_mmx: - movl $DO_USE_MMX, inflate_fast_use_mmx - jmp .L_check_mmx_pop -.L_dont_use_mmx: - movl $DONT_USE_MMX, inflate_fast_use_mmx -.L_check_mmx_pop: - popl %edx - popl %ecx - popl %ebx - popl %eax - jmp .L_check_mmx -#endif - - -/*** Non-MMX code ***/ - -#if defined ( NO_MMX ) || defined( RUN_TIME_MMX ) - -#define hold_r %ebp -#define bits_r %bl -#define bitslong_r %ebx - -.align 32,0x90 -.L_while_test: - /* while (in < last && out < end) - */ - cmpl out_r, end(%esp) - jbe .L_break_loop /* if (out >= end) */ - - cmpl in_r, last(%esp) - jbe .L_break_loop - -.L_do_loop: - /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out - * - * do { - * if (bits < 15) { - * hold |= *((unsigned short *)in)++ << bits; - * bits += 16 - * } - * this = lcode[hold & lmask] - */ - cmpb $15, bits_r - ja .L_get_length_code /* if (15 < bits) */ - - xorl %eax, %eax - lodsw /* al = *(ushort *)in++ */ - movb bits_r, %cl /* cl = bits, needs it for shifting */ - addb $16, bits_r /* bits += 16 */ - shll %cl, %eax - orl %eax, hold_r /* hold |= *((ushort *)in)++ << bits */ - -.L_get_length_code: - movl lmask(%esp), %edx /* edx = lmask */ - movl lcode(%esp), %ecx /* ecx = lcode */ - andl hold_r, %edx /* edx &= hold */ - movl (%ecx,%edx,4), %eax /* eax = lcode[hold & lmask] */ - -.L_dolen: - /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out - * - * dolen: - * bits -= this.bits; - * hold >>= this.bits - */ - movb %ah, %cl /* cl = this.bits */ - subb %ah, bits_r /* bits -= this.bits */ - shrl %cl, hold_r /* hold >>= this.bits */ - - /* check if op is a literal - * if (op == 0) { - * PUP(out) = this.val; - * } - */ - testb %al, %al - jnz .L_test_for_length_base /* if (op != 0) 45.7% */ - - shrl $16, %eax /* output this.val char */ - stosb - jmp .L_while_test - -.L_test_for_length_base: - /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out, %edx = len - * - * else if (op & 16) { - * len = this.val - * op &= 15 - * if (op) { - * if (op > bits) { - * hold |= *((unsigned short *)in)++ << bits; - * bits += 16 - * } - * len += hold & mask[op]; - * bits -= op; - * hold >>= op; - * } - */ -#define len_r %edx - movl %eax, len_r /* len = this */ - shrl $16, len_r /* len = this.val */ - movb %al, %cl - - testb $16, %al - jz .L_test_for_second_level_length /* if ((op & 16) == 0) 8% */ - andb $15, %cl /* op &= 15 */ - jz .L_save_len /* if (!op) */ - cmpb %cl, bits_r - jae .L_add_bits_to_len /* if (op <= bits) */ - - movb %cl, %ch /* stash op in ch, freeing cl */ - xorl %eax, %eax - lodsw /* al = *(ushort *)in++ */ - movb bits_r, %cl /* cl = bits, needs it for shifting */ - addb $16, bits_r /* bits += 16 */ - shll %cl, %eax - orl %eax, hold_r /* hold |= *((ushort *)in)++ << bits */ - movb %ch, %cl /* move op back to ecx */ - -.L_add_bits_to_len: - movl $1, %eax - shll %cl, %eax - decl %eax - subb %cl, bits_r - andl hold_r, %eax /* eax &= hold */ - shrl %cl, hold_r - addl %eax, len_r /* len += hold & mask[op] */ - -.L_save_len: - movl len_r, len(%esp) /* save len */ -#undef len_r - -.L_decode_distance: - /* regs: %esi = in, %ebp = hold, %bl = bits, %edi = out, %edx = dist - * - * if (bits < 15) { - * hold |= *((unsigned short *)in)++ << bits; - * bits += 16 - * } - * this = dcode[hold & dmask]; - * dodist: - * bits -= this.bits; - * hold >>= this.bits; - * op = this.op; - */ - - cmpb $15, bits_r - ja .L_get_distance_code /* if (15 < bits) */ - - xorl %eax, %eax - lodsw /* al = *(ushort *)in++ */ - movb bits_r, %cl /* cl = bits, needs it for shifting */ - addb $16, bits_r /* bits += 16 */ - shll %cl, %eax - orl %eax, hold_r /* hold |= *((ushort *)in)++ << bits */ - -.L_get_distance_code: - movl dmask(%esp), %edx /* edx = dmask */ - movl dcode(%esp), %ecx /* ecx = dcode */ - andl hold_r, %edx /* edx &= hold */ - movl (%ecx,%edx,4), %eax /* eax = dcode[hold & dmask] */ - -#define dist_r %edx -.L_dodist: - movl %eax, dist_r /* dist = this */ - shrl $16, dist_r /* dist = this.val */ - movb %ah, %cl - subb %ah, bits_r /* bits -= this.bits */ - shrl %cl, hold_r /* hold >>= this.bits */ - - /* if (op & 16) { - * dist = this.val - * op &= 15 - * if (op > bits) { - * hold |= *((unsigned short *)in)++ << bits; - * bits += 16 - * } - * dist += hold & mask[op]; - * bits -= op; - * hold >>= op; - */ - movb %al, %cl /* cl = this.op */ - - testb $16, %al /* if ((op & 16) == 0) */ - jz .L_test_for_second_level_dist - andb $15, %cl /* op &= 15 */ - jz .L_check_dist_one - cmpb %cl, bits_r - jae .L_add_bits_to_dist /* if (op <= bits) 97.6% */ - - movb %cl, %ch /* stash op in ch, freeing cl */ - xorl %eax, %eax - lodsw /* al = *(ushort *)in++ */ - movb bits_r, %cl /* cl = bits, needs it for shifting */ - addb $16, bits_r /* bits += 16 */ - shll %cl, %eax - orl %eax, hold_r /* hold |= *((ushort *)in)++ << bits */ - movb %ch, %cl /* move op back to ecx */ - -.L_add_bits_to_dist: - movl $1, %eax - shll %cl, %eax - decl %eax /* (1 << op) - 1 */ - subb %cl, bits_r - andl hold_r, %eax /* eax &= hold */ - shrl %cl, hold_r - addl %eax, dist_r /* dist += hold & ((1 << op) - 1) */ - jmp .L_check_window - -.L_check_window: - /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist - * %ecx = nbytes - * - * nbytes = out - beg; - * if (dist <= nbytes) { - * from = out - dist; - * do { - * PUP(out) = PUP(from); - * } while (--len > 0) { - * } - */ - - movl in_r, in(%esp) /* save in so from can use it's reg */ - movl out_r, %eax - subl beg(%esp), %eax /* nbytes = out - beg */ - - cmpl dist_r, %eax - jb .L_clip_window /* if (dist > nbytes) 4.2% */ - - movl len(%esp), %ecx - movl out_r, from_r - subl dist_r, from_r /* from = out - dist */ - - subl $3, %ecx - movb (from_r), %al - movb %al, (out_r) - movb 1(from_r), %al - movb 2(from_r), %dl - addl $3, from_r - movb %al, 1(out_r) - movb %dl, 2(out_r) - addl $3, out_r - rep movsb - - movl in(%esp), in_r /* move in back to %esi, toss from */ - jmp .L_while_test - -.align 16,0x90 -.L_check_dist_one: - cmpl $1, dist_r - jne .L_check_window - cmpl out_r, beg(%esp) - je .L_check_window - - decl out_r - movl len(%esp), %ecx - movb (out_r), %al - subl $3, %ecx - - movb %al, 1(out_r) - movb %al, 2(out_r) - movb %al, 3(out_r) - addl $4, out_r - rep stosb - - jmp .L_while_test - -.align 16,0x90 -.L_test_for_second_level_length: - /* else if ((op & 64) == 0) { - * this = lcode[this.val + (hold & mask[op])]; - * } - */ - testb $64, %al - jnz .L_test_for_end_of_block /* if ((op & 64) != 0) */ - - movl $1, %eax - shll %cl, %eax - decl %eax - andl hold_r, %eax /* eax &= hold */ - addl %edx, %eax /* eax += this.val */ - movl lcode(%esp), %edx /* edx = lcode */ - movl (%edx,%eax,4), %eax /* eax = lcode[val + (hold&mask[op])] */ - jmp .L_dolen - -.align 16,0x90 -.L_test_for_second_level_dist: - /* else if ((op & 64) == 0) { - * this = dcode[this.val + (hold & mask[op])]; - * } - */ - testb $64, %al - jnz .L_invalid_distance_code /* if ((op & 64) != 0) */ - - movl $1, %eax - shll %cl, %eax - decl %eax - andl hold_r, %eax /* eax &= hold */ - addl %edx, %eax /* eax += this.val */ - movl dcode(%esp), %edx /* edx = dcode */ - movl (%edx,%eax,4), %eax /* eax = dcode[val + (hold&mask[op])] */ - jmp .L_dodist - -.align 16,0x90 -.L_clip_window: - /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist - * %ecx = nbytes - * - * else { - * if (dist > wsize) { - * invalid distance - * } - * from = window; - * nbytes = dist - nbytes; - * if (write == 0) { - * from += wsize - nbytes; - */ -#define nbytes_r %ecx - movl %eax, nbytes_r - movl wsize(%esp), %eax /* prepare for dist compare */ - negl nbytes_r /* nbytes = -nbytes */ - movl window(%esp), from_r /* from = window */ - - cmpl dist_r, %eax - jb .L_invalid_distance_too_far /* if (dist > wsize) */ - - addl dist_r, nbytes_r /* nbytes = dist - nbytes */ - cmpl $0, write(%esp) - jne .L_wrap_around_window /* if (write != 0) */ - - subl nbytes_r, %eax - addl %eax, from_r /* from += wsize - nbytes */ - - /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist - * %ecx = nbytes, %eax = len - * - * if (nbytes < len) { - * len -= nbytes; - * do { - * PUP(out) = PUP(from); - * } while (--nbytes); - * from = out - dist; - * } - * } - */ -#define len_r %eax - movl len(%esp), len_r - cmpl nbytes_r, len_r - jbe .L_do_copy1 /* if (nbytes >= len) */ - - subl nbytes_r, len_r /* len -= nbytes */ - rep movsb - movl out_r, from_r - subl dist_r, from_r /* from = out - dist */ - jmp .L_do_copy1 - - cmpl nbytes_r, len_r - jbe .L_do_copy1 /* if (nbytes >= len) */ - - subl nbytes_r, len_r /* len -= nbytes */ - rep movsb - movl out_r, from_r - subl dist_r, from_r /* from = out - dist */ - jmp .L_do_copy1 - -.L_wrap_around_window: - /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist - * %ecx = nbytes, %eax = write, %eax = len - * - * else if (write < nbytes) { - * from += wsize + write - nbytes; - * nbytes -= write; - * if (nbytes < len) { - * len -= nbytes; - * do { - * PUP(out) = PUP(from); - * } while (--nbytes); - * from = window; - * nbytes = write; - * if (nbytes < len) { - * len -= nbytes; - * do { - * PUP(out) = PUP(from); - * } while(--nbytes); - * from = out - dist; - * } - * } - * } - */ -#define write_r %eax - movl write(%esp), write_r - cmpl write_r, nbytes_r - jbe .L_contiguous_in_window /* if (write >= nbytes) */ - - addl wsize(%esp), from_r - addl write_r, from_r - subl nbytes_r, from_r /* from += wsize + write - nbytes */ - subl write_r, nbytes_r /* nbytes -= write */ -#undef write_r - - movl len(%esp), len_r - cmpl nbytes_r, len_r - jbe .L_do_copy1 /* if (nbytes >= len) */ - - subl nbytes_r, len_r /* len -= nbytes */ - rep movsb - movl window(%esp), from_r /* from = window */ - movl write(%esp), nbytes_r /* nbytes = write */ - cmpl nbytes_r, len_r - jbe .L_do_copy1 /* if (nbytes >= len) */ - - subl nbytes_r, len_r /* len -= nbytes */ - rep movsb - movl out_r, from_r - subl dist_r, from_r /* from = out - dist */ - jmp .L_do_copy1 - -.L_contiguous_in_window: - /* regs: %esi = from, %ebp = hold, %bl = bits, %edi = out, %edx = dist - * %ecx = nbytes, %eax = write, %eax = len - * - * else { - * from += write - nbytes; - * if (nbytes < len) { - * len -= nbytes; - * do { - * PUP(out) = PUP(from); - * } while (--nbytes); - * from = out - dist; - * } - * } - */ -#define write_r %eax - addl write_r, from_r - subl nbytes_r, from_r /* from += write - nbytes */ -#undef write_r - - movl len(%esp), len_r - cmpl nbytes_r, len_r - jbe .L_do_copy1 /* if (nbytes >= len) */ - - subl nbytes_r, len_r /* len -= nbytes */ - rep movsb - movl out_r, from_r - subl dist_r, from_r /* from = out - dist */ - -.L_do_copy1: - /* regs: %esi = from, %esi = in, %ebp = hold, %bl = bits, %edi = out - * %eax = len - * - * while (len > 0) { - * PUP(out) = PUP(from); - * len--; - * } - * } - * } while (in < last && out < end); - */ -#undef nbytes_r -#define in_r %esi - movl len_r, %ecx - rep movsb - - movl in(%esp), in_r /* move in back to %esi, toss from */ - jmp .L_while_test - -#undef len_r -#undef dist_r - -#endif /* NO_MMX || RUN_TIME_MMX */ - - -/*** MMX code ***/ - -#if defined( USE_MMX ) || defined( RUN_TIME_MMX ) - -.align 32,0x90 -.L_init_mmx: - emms - -#undef bits_r -#undef bitslong_r -#define bitslong_r %ebp -#define hold_mm %mm0 - movd %ebp, hold_mm - movl %ebx, bitslong_r - -#define used_mm %mm1 -#define dmask2_mm %mm2 -#define lmask2_mm %mm3 -#define lmask_mm %mm4 -#define dmask_mm %mm5 -#define tmp_mm %mm6 - - movd lmask(%esp), lmask_mm - movq lmask_mm, lmask2_mm - movd dmask(%esp), dmask_mm - movq dmask_mm, dmask2_mm - pxor used_mm, used_mm - movl lcode(%esp), %ebx /* ebx = lcode */ - jmp .L_do_loop_mmx - -.align 32,0x90 -.L_while_test_mmx: - /* while (in < last && out < end) - */ - cmpl out_r, end(%esp) - jbe .L_break_loop /* if (out >= end) */ - - cmpl in_r, last(%esp) - jbe .L_break_loop - -.L_do_loop_mmx: - psrlq used_mm, hold_mm /* hold_mm >>= last bit length */ - - cmpl $32, bitslong_r - ja .L_get_length_code_mmx /* if (32 < bits) */ - - movd bitslong_r, tmp_mm - movd (in_r), %mm7 - addl $4, in_r - psllq tmp_mm, %mm7 - addl $32, bitslong_r - por %mm7, hold_mm /* hold_mm |= *((uint *)in)++ << bits */ - -.L_get_length_code_mmx: - pand hold_mm, lmask_mm - movd lmask_mm, %eax - movq lmask2_mm, lmask_mm - movl (%ebx,%eax,4), %eax /* eax = lcode[hold & lmask] */ - -.L_dolen_mmx: - movzbl %ah, %ecx /* ecx = this.bits */ - movd %ecx, used_mm - subl %ecx, bitslong_r /* bits -= this.bits */ - - testb %al, %al - jnz .L_test_for_length_base_mmx /* if (op != 0) 45.7% */ - - shrl $16, %eax /* output this.val char */ - stosb - jmp .L_while_test_mmx - -.L_test_for_length_base_mmx: -#define len_r %edx - movl %eax, len_r /* len = this */ - shrl $16, len_r /* len = this.val */ - - testb $16, %al - jz .L_test_for_second_level_length_mmx /* if ((op & 16) == 0) 8% */ - andl $15, %eax /* op &= 15 */ - jz .L_decode_distance_mmx /* if (!op) */ - - psrlq used_mm, hold_mm /* hold_mm >>= last bit length */ - movd %eax, used_mm - movd hold_mm, %ecx - subl %eax, bitslong_r - andl .L_mask(,%eax,4), %ecx - addl %ecx, len_r /* len += hold & mask[op] */ - -.L_decode_distance_mmx: - psrlq used_mm, hold_mm /* hold_mm >>= last bit length */ - - cmpl $32, bitslong_r - ja .L_get_dist_code_mmx /* if (32 < bits) */ - - movd bitslong_r, tmp_mm - movd (in_r), %mm7 - addl $4, in_r - psllq tmp_mm, %mm7 - addl $32, bitslong_r - por %mm7, hold_mm /* hold_mm |= *((uint *)in)++ << bits */ - -.L_get_dist_code_mmx: - movl dcode(%esp), %ebx /* ebx = dcode */ - pand hold_mm, dmask_mm - movd dmask_mm, %eax - movq dmask2_mm, dmask_mm - movl (%ebx,%eax,4), %eax /* eax = dcode[hold & lmask] */ - -.L_dodist_mmx: -#define dist_r %ebx - movzbl %ah, %ecx /* ecx = this.bits */ - movl %eax, dist_r - shrl $16, dist_r /* dist = this.val */ - subl %ecx, bitslong_r /* bits -= this.bits */ - movd %ecx, used_mm - - testb $16, %al /* if ((op & 16) == 0) */ - jz .L_test_for_second_level_dist_mmx - andl $15, %eax /* op &= 15 */ - jz .L_check_dist_one_mmx - -.L_add_bits_to_dist_mmx: - psrlq used_mm, hold_mm /* hold_mm >>= last bit length */ - movd %eax, used_mm /* save bit length of current op */ - movd hold_mm, %ecx /* get the next bits on input stream */ - subl %eax, bitslong_r /* bits -= op bits */ - andl .L_mask(,%eax,4), %ecx /* ecx = hold & mask[op] */ - addl %ecx, dist_r /* dist += hold & mask[op] */ - -.L_check_window_mmx: - movl in_r, in(%esp) /* save in so from can use it's reg */ - movl out_r, %eax - subl beg(%esp), %eax /* nbytes = out - beg */ - - cmpl dist_r, %eax - jb .L_clip_window_mmx /* if (dist > nbytes) 4.2% */ - - movl len_r, %ecx - movl out_r, from_r - subl dist_r, from_r /* from = out - dist */ - - subl $3, %ecx - movb (from_r), %al - movb %al, (out_r) - movb 1(from_r), %al - movb 2(from_r), %dl - addl $3, from_r - movb %al, 1(out_r) - movb %dl, 2(out_r) - addl $3, out_r - rep movsb - - movl in(%esp), in_r /* move in back to %esi, toss from */ - movl lcode(%esp), %ebx /* move lcode back to %ebx, toss dist */ - jmp .L_while_test_mmx - -.align 16,0x90 -.L_check_dist_one_mmx: - cmpl $1, dist_r - jne .L_check_window_mmx - cmpl out_r, beg(%esp) - je .L_check_window_mmx - - decl out_r - movl len_r, %ecx - movb (out_r), %al - subl $3, %ecx - - movb %al, 1(out_r) - movb %al, 2(out_r) - movb %al, 3(out_r) - addl $4, out_r - rep stosb - - movl lcode(%esp), %ebx /* move lcode back to %ebx, toss dist */ - jmp .L_while_test_mmx - -.align 16,0x90 -.L_test_for_second_level_length_mmx: - testb $64, %al - jnz .L_test_for_end_of_block /* if ((op & 64) != 0) */ - - andl $15, %eax - psrlq used_mm, hold_mm /* hold_mm >>= last bit length */ - movd hold_mm, %ecx - andl .L_mask(,%eax,4), %ecx - addl len_r, %ecx - movl (%ebx,%ecx,4), %eax /* eax = lcode[hold & lmask] */ - jmp .L_dolen_mmx - -.align 16,0x90 -.L_test_for_second_level_dist_mmx: - testb $64, %al - jnz .L_invalid_distance_code /* if ((op & 64) != 0) */ - - andl $15, %eax - psrlq used_mm, hold_mm /* hold_mm >>= last bit length */ - movd hold_mm, %ecx - andl .L_mask(,%eax,4), %ecx - movl dcode(%esp), %eax /* ecx = dcode */ - addl dist_r, %ecx - movl (%eax,%ecx,4), %eax /* eax = lcode[hold & lmask] */ - jmp .L_dodist_mmx - -.align 16,0x90 -.L_clip_window_mmx: -#define nbytes_r %ecx - movl %eax, nbytes_r - movl wsize(%esp), %eax /* prepare for dist compare */ - negl nbytes_r /* nbytes = -nbytes */ - movl window(%esp), from_r /* from = window */ - - cmpl dist_r, %eax - jb .L_invalid_distance_too_far /* if (dist > wsize) */ - - addl dist_r, nbytes_r /* nbytes = dist - nbytes */ - cmpl $0, write(%esp) - jne .L_wrap_around_window_mmx /* if (write != 0) */ - - subl nbytes_r, %eax - addl %eax, from_r /* from += wsize - nbytes */ - - cmpl nbytes_r, len_r - jbe .L_do_copy1_mmx /* if (nbytes >= len) */ - - subl nbytes_r, len_r /* len -= nbytes */ - rep movsb - movl out_r, from_r - subl dist_r, from_r /* from = out - dist */ - jmp .L_do_copy1_mmx - - cmpl nbytes_r, len_r - jbe .L_do_copy1_mmx /* if (nbytes >= len) */ - - subl nbytes_r, len_r /* len -= nbytes */ - rep movsb - movl out_r, from_r - subl dist_r, from_r /* from = out - dist */ - jmp .L_do_copy1_mmx - -.L_wrap_around_window_mmx: -#define write_r %eax - movl write(%esp), write_r - cmpl write_r, nbytes_r - jbe .L_contiguous_in_window_mmx /* if (write >= nbytes) */ - - addl wsize(%esp), from_r - addl write_r, from_r - subl nbytes_r, from_r /* from += wsize + write - nbytes */ - subl write_r, nbytes_r /* nbytes -= write */ -#undef write_r - - cmpl nbytes_r, len_r - jbe .L_do_copy1_mmx /* if (nbytes >= len) */ - - subl nbytes_r, len_r /* len -= nbytes */ - rep movsb - movl window(%esp), from_r /* from = window */ - movl write(%esp), nbytes_r /* nbytes = write */ - cmpl nbytes_r, len_r - jbe .L_do_copy1_mmx /* if (nbytes >= len) */ - - subl nbytes_r, len_r /* len -= nbytes */ - rep movsb - movl out_r, from_r - subl dist_r, from_r /* from = out - dist */ - jmp .L_do_copy1_mmx - -.L_contiguous_in_window_mmx: -#define write_r %eax - addl write_r, from_r - subl nbytes_r, from_r /* from += write - nbytes */ -#undef write_r - - cmpl nbytes_r, len_r - jbe .L_do_copy1_mmx /* if (nbytes >= len) */ - - subl nbytes_r, len_r /* len -= nbytes */ - rep movsb - movl out_r, from_r - subl dist_r, from_r /* from = out - dist */ - -.L_do_copy1_mmx: -#undef nbytes_r -#define in_r %esi - movl len_r, %ecx - rep movsb - - movl in(%esp), in_r /* move in back to %esi, toss from */ - movl lcode(%esp), %ebx /* move lcode back to %ebx, toss dist */ - jmp .L_while_test_mmx - -#undef hold_r -#undef bitslong_r - -#endif /* USE_MMX || RUN_TIME_MMX */ - - -/*** USE_MMX, NO_MMX, and RUNTIME_MMX from here on ***/ - -.L_invalid_distance_code: - /* else { - * strm->msg = "invalid distance code"; - * state->mode = BAD; - * } - */ - movl $.L_invalid_distance_code_msg, %ecx - movl $INFLATE_MODE_BAD, %edx - jmp .L_update_stream_state - -.L_test_for_end_of_block: - /* else if (op & 32) { - * state->mode = TYPE; - * break; - * } - */ - testb $32, %al - jz .L_invalid_literal_length_code /* if ((op & 32) == 0) */ - - movl $0, %ecx - movl $INFLATE_MODE_TYPE, %edx - jmp .L_update_stream_state - -.L_invalid_literal_length_code: - /* else { - * strm->msg = "invalid literal/length code"; - * state->mode = BAD; - * } - */ - movl $.L_invalid_literal_length_code_msg, %ecx - movl $INFLATE_MODE_BAD, %edx - jmp .L_update_stream_state - -.L_invalid_distance_too_far: - /* strm->msg = "invalid distance too far back"; - * state->mode = BAD; - */ - movl in(%esp), in_r /* from_r has in's reg, put in back */ - movl $.L_invalid_distance_too_far_msg, %ecx - movl $INFLATE_MODE_BAD, %edx - jmp .L_update_stream_state - -.L_update_stream_state: - /* set strm->msg = %ecx, strm->state->mode = %edx */ - movl strm_sp(%esp), %eax - testl %ecx, %ecx /* if (msg != NULL) */ - jz .L_skip_msg - movl %ecx, msg_strm(%eax) /* strm->msg = msg */ -.L_skip_msg: - movl state_strm(%eax), %eax /* state = strm->state */ - movl %edx, mode_state(%eax) /* state->mode = edx (BAD | TYPE) */ - jmp .L_break_loop - -.align 32,0x90 -.L_break_loop: - -/* - * Regs: - * - * bits = %ebp when mmx, and in %ebx when non-mmx - * hold = %hold_mm when mmx, and in %ebp when non-mmx - * in = %esi - * out = %edi - */ - -#if defined( USE_MMX ) || defined( RUN_TIME_MMX ) - -#if defined( RUN_TIME_MMX ) - - cmpl $DO_USE_MMX, inflate_fast_use_mmx - jne .L_update_next_in - -#endif /* RUN_TIME_MMX */ - - movl %ebp, %ebx - -.L_update_next_in: - -#endif - -#define strm_r %eax -#define state_r %edx - - /* len = bits >> 3; - * in -= len; - * bits -= len << 3; - * hold &= (1U << bits) - 1; - * state->hold = hold; - * state->bits = bits; - * strm->next_in = in; - * strm->next_out = out; - */ - movl strm_sp(%esp), strm_r - movl %ebx, %ecx - movl state_strm(strm_r), state_r - shrl $3, %ecx - subl %ecx, in_r - shll $3, %ecx - subl %ecx, %ebx - movl out_r, next_out_strm(strm_r) - movl %ebx, bits_state(state_r) - movl %ebx, %ecx - - leal buf(%esp), %ebx - cmpl %ebx, last(%esp) - jne .L_buf_not_used /* if buf != last */ - - subl %ebx, in_r /* in -= buf */ - movl next_in_strm(strm_r), %ebx - movl %ebx, last(%esp) /* last = strm->next_in */ - addl %ebx, in_r /* in += strm->next_in */ - movl avail_in_strm(strm_r), %ebx - subl $11, %ebx - addl %ebx, last(%esp) /* last = &strm->next_in[ avail_in - 11 ] */ - -.L_buf_not_used: - movl in_r, next_in_strm(strm_r) - - movl $1, %ebx - shll %cl, %ebx - decl %ebx - -#if defined( USE_MMX ) || defined( RUN_TIME_MMX ) - -#if defined( RUN_TIME_MMX ) - - cmpl $DO_USE_MMX, inflate_fast_use_mmx - jne .L_update_hold - -#endif /* RUN_TIME_MMX */ - - psrlq used_mm, hold_mm /* hold_mm >>= last bit length */ - movd hold_mm, %ebp - - emms - -.L_update_hold: - -#endif /* USE_MMX || RUN_TIME_MMX */ - - andl %ebx, %ebp - movl %ebp, hold_state(state_r) - -#define last_r %ebx - - /* strm->avail_in = in < last ? 11 + (last - in) : 11 - (in - last) */ - movl last(%esp), last_r - cmpl in_r, last_r - jbe .L_last_is_smaller /* if (in >= last) */ - - subl in_r, last_r /* last -= in */ - addl $11, last_r /* last += 11 */ - movl last_r, avail_in_strm(strm_r) - jmp .L_fixup_out -.L_last_is_smaller: - subl last_r, in_r /* in -= last */ - negl in_r /* in = -in */ - addl $11, in_r /* in += 11 */ - movl in_r, avail_in_strm(strm_r) - -#undef last_r -#define end_r %ebx - -.L_fixup_out: - /* strm->avail_out = out < end ? 257 + (end - out) : 257 - (out - end)*/ - movl end(%esp), end_r - cmpl out_r, end_r - jbe .L_end_is_smaller /* if (out >= end) */ - - subl out_r, end_r /* end -= out */ - addl $257, end_r /* end += 257 */ - movl end_r, avail_out_strm(strm_r) - jmp .L_done -.L_end_is_smaller: - subl end_r, out_r /* out -= end */ - negl out_r /* out = -out */ - addl $257, out_r /* out += 257 */ - movl out_r, avail_out_strm(strm_r) - -#undef end_r -#undef strm_r -#undef state_r - -.L_done: - addl $local_var_size, %esp - popf - popl %ebx - popl %ebp - popl %esi - popl %edi - ret - -#if defined( GAS_ELF ) -/* elf info */ -.type inflate_fast,@function -.size inflate_fast,.-inflate_fast -#endif diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/iostream/test.cpp b/src/beast/test/zlib/zlib-1.2.8/contrib/iostream/test.cpp deleted file mode 100644 index 7d265b3b5c0..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/iostream/test.cpp +++ /dev/null @@ -1,24 +0,0 @@ - -#include "zfstream.h" - -int main() { - - // Construct a stream object with this filebuffer. Anything sent - // to this stream will go to standard out. - gzofstream os( 1, ios::out ); - - // This text is getting compressed and sent to stdout. - // To prove this, run 'test | zcat'. - os << "Hello, Mommy" << endl; - - os << setcompressionlevel( Z_NO_COMPRESSION ); - os << "hello, hello, hi, ho!" << endl; - - setcompressionlevel( os, Z_DEFAULT_COMPRESSION ) - << "I'm compressing again" << endl; - - os.close(); - - return 0; - -} diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/iostream/zfstream.cpp b/src/beast/test/zlib/zlib-1.2.8/contrib/iostream/zfstream.cpp deleted file mode 100644 index d0cd85faaf5..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/iostream/zfstream.cpp +++ /dev/null @@ -1,329 +0,0 @@ - -#include "zfstream.h" - -gzfilebuf::gzfilebuf() : - file(NULL), - mode(0), - own_file_descriptor(0) -{ } - -gzfilebuf::~gzfilebuf() { - - sync(); - if ( own_file_descriptor ) - close(); - -} - -gzfilebuf *gzfilebuf::open( const char *name, - int io_mode ) { - - if ( is_open() ) - return NULL; - - char char_mode[10]; - char *p = char_mode; - - if ( io_mode & ios::in ) { - mode = ios::in; - *p++ = 'r'; - } else if ( io_mode & ios::app ) { - mode = ios::app; - *p++ = 'a'; - } else { - mode = ios::out; - *p++ = 'w'; - } - - if ( io_mode & ios::binary ) { - mode |= ios::binary; - *p++ = 'b'; - } - - // Hard code the compression level - if ( io_mode & (ios::out|ios::app )) { - *p++ = '9'; - } - - // Put the end-of-string indicator - *p = '\0'; - - if ( (file = gzopen(name, char_mode)) == NULL ) - return NULL; - - own_file_descriptor = 1; - - return this; - -} - -gzfilebuf *gzfilebuf::attach( int file_descriptor, - int io_mode ) { - - if ( is_open() ) - return NULL; - - char char_mode[10]; - char *p = char_mode; - - if ( io_mode & ios::in ) { - mode = ios::in; - *p++ = 'r'; - } else if ( io_mode & ios::app ) { - mode = ios::app; - *p++ = 'a'; - } else { - mode = ios::out; - *p++ = 'w'; - } - - if ( io_mode & ios::binary ) { - mode |= ios::binary; - *p++ = 'b'; - } - - // Hard code the compression level - if ( io_mode & (ios::out|ios::app )) { - *p++ = '9'; - } - - // Put the end-of-string indicator - *p = '\0'; - - if ( (file = gzdopen(file_descriptor, char_mode)) == NULL ) - return NULL; - - own_file_descriptor = 0; - - return this; - -} - -gzfilebuf *gzfilebuf::close() { - - if ( is_open() ) { - - sync(); - gzclose( file ); - file = NULL; - - } - - return this; - -} - -int gzfilebuf::setcompressionlevel( int comp_level ) { - - return gzsetparams(file, comp_level, -2); - -} - -int gzfilebuf::setcompressionstrategy( int comp_strategy ) { - - return gzsetparams(file, -2, comp_strategy); - -} - - -streampos gzfilebuf::seekoff( streamoff off, ios::seek_dir dir, int which ) { - - return streampos(EOF); - -} - -int gzfilebuf::underflow() { - - // If the file hasn't been opened for reading, error. - if ( !is_open() || !(mode & ios::in) ) - return EOF; - - // if a buffer doesn't exists, allocate one. - if ( !base() ) { - - if ( (allocate()) == EOF ) - return EOF; - setp(0,0); - - } else { - - if ( in_avail() ) - return (unsigned char) *gptr(); - - if ( out_waiting() ) { - if ( flushbuf() == EOF ) - return EOF; - } - - } - - // Attempt to fill the buffer. - - int result = fillbuf(); - if ( result == EOF ) { - // disable get area - setg(0,0,0); - return EOF; - } - - return (unsigned char) *gptr(); - -} - -int gzfilebuf::overflow( int c ) { - - if ( !is_open() || !(mode & ios::out) ) - return EOF; - - if ( !base() ) { - if ( allocate() == EOF ) - return EOF; - setg(0,0,0); - } else { - if (in_avail()) { - return EOF; - } - if (out_waiting()) { - if (flushbuf() == EOF) - return EOF; - } - } - - int bl = blen(); - setp( base(), base() + bl); - - if ( c != EOF ) { - - *pptr() = c; - pbump(1); - - } - - return 0; - -} - -int gzfilebuf::sync() { - - if ( !is_open() ) - return EOF; - - if ( out_waiting() ) - return flushbuf(); - - return 0; - -} - -int gzfilebuf::flushbuf() { - - int n; - char *q; - - q = pbase(); - n = pptr() - q; - - if ( gzwrite( file, q, n) < n ) - return EOF; - - setp(0,0); - - return 0; - -} - -int gzfilebuf::fillbuf() { - - int required; - char *p; - - p = base(); - - required = blen(); - - int t = gzread( file, p, required ); - - if ( t <= 0) return EOF; - - setg( base(), base(), base()+t); - - return t; - -} - -gzfilestream_common::gzfilestream_common() : - ios( gzfilestream_common::rdbuf() ) -{ } - -gzfilestream_common::~gzfilestream_common() -{ } - -void gzfilestream_common::attach( int fd, int io_mode ) { - - if ( !buffer.attach( fd, io_mode) ) - clear( ios::failbit | ios::badbit ); - else - clear(); - -} - -void gzfilestream_common::open( const char *name, int io_mode ) { - - if ( !buffer.open( name, io_mode ) ) - clear( ios::failbit | ios::badbit ); - else - clear(); - -} - -void gzfilestream_common::close() { - - if ( !buffer.close() ) - clear( ios::failbit | ios::badbit ); - -} - -gzfilebuf *gzfilestream_common::rdbuf() -{ - return &buffer; -} - -gzifstream::gzifstream() : - ios( gzfilestream_common::rdbuf() ) -{ - clear( ios::badbit ); -} - -gzifstream::gzifstream( const char *name, int io_mode ) : - ios( gzfilestream_common::rdbuf() ) -{ - gzfilestream_common::open( name, io_mode ); -} - -gzifstream::gzifstream( int fd, int io_mode ) : - ios( gzfilestream_common::rdbuf() ) -{ - gzfilestream_common::attach( fd, io_mode ); -} - -gzifstream::~gzifstream() { } - -gzofstream::gzofstream() : - ios( gzfilestream_common::rdbuf() ) -{ - clear( ios::badbit ); -} - -gzofstream::gzofstream( const char *name, int io_mode ) : - ios( gzfilestream_common::rdbuf() ) -{ - gzfilestream_common::open( name, io_mode ); -} - -gzofstream::gzofstream( int fd, int io_mode ) : - ios( gzfilestream_common::rdbuf() ) -{ - gzfilestream_common::attach( fd, io_mode ); -} - -gzofstream::~gzofstream() { } diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/iostream/zfstream.h b/src/beast/test/zlib/zlib-1.2.8/contrib/iostream/zfstream.h deleted file mode 100644 index ed79098a3ad..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/iostream/zfstream.h +++ /dev/null @@ -1,128 +0,0 @@ - -#ifndef zfstream_h -#define zfstream_h - -#include -#include "zlib.h" - -class gzfilebuf : public streambuf { - -public: - - gzfilebuf( ); - virtual ~gzfilebuf(); - - gzfilebuf *open( const char *name, int io_mode ); - gzfilebuf *attach( int file_descriptor, int io_mode ); - gzfilebuf *close(); - - int setcompressionlevel( int comp_level ); - int setcompressionstrategy( int comp_strategy ); - - inline int is_open() const { return (file !=NULL); } - - virtual streampos seekoff( streamoff, ios::seek_dir, int ); - - virtual int sync(); - -protected: - - virtual int underflow(); - virtual int overflow( int = EOF ); - -private: - - gzFile file; - short mode; - short own_file_descriptor; - - int flushbuf(); - int fillbuf(); - -}; - -class gzfilestream_common : virtual public ios { - - friend class gzifstream; - friend class gzofstream; - friend gzofstream &setcompressionlevel( gzofstream &, int ); - friend gzofstream &setcompressionstrategy( gzofstream &, int ); - -public: - virtual ~gzfilestream_common(); - - void attach( int fd, int io_mode ); - void open( const char *name, int io_mode ); - void close(); - -protected: - gzfilestream_common(); - -private: - gzfilebuf *rdbuf(); - - gzfilebuf buffer; - -}; - -class gzifstream : public gzfilestream_common, public istream { - -public: - - gzifstream(); - gzifstream( const char *name, int io_mode = ios::in ); - gzifstream( int fd, int io_mode = ios::in ); - - virtual ~gzifstream(); - -}; - -class gzofstream : public gzfilestream_common, public ostream { - -public: - - gzofstream(); - gzofstream( const char *name, int io_mode = ios::out ); - gzofstream( int fd, int io_mode = ios::out ); - - virtual ~gzofstream(); - -}; - -template class gzomanip { - friend gzofstream &operator<<(gzofstream &, const gzomanip &); -public: - gzomanip(gzofstream &(*f)(gzofstream &, T), T v) : func(f), val(v) { } -private: - gzofstream &(*func)(gzofstream &, T); - T val; -}; - -template gzofstream &operator<<(gzofstream &s, const gzomanip &m) -{ - return (*m.func)(s, m.val); -} - -inline gzofstream &setcompressionlevel( gzofstream &s, int l ) -{ - (s.rdbuf())->setcompressionlevel(l); - return s; -} - -inline gzofstream &setcompressionstrategy( gzofstream &s, int l ) -{ - (s.rdbuf())->setcompressionstrategy(l); - return s; -} - -inline gzomanip setcompressionlevel(int l) -{ - return gzomanip(&setcompressionlevel,l); -} - -inline gzomanip setcompressionstrategy(int l) -{ - return gzomanip(&setcompressionstrategy,l); -} - -#endif diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/iostream2/zstream.h b/src/beast/test/zlib/zlib-1.2.8/contrib/iostream2/zstream.h deleted file mode 100644 index 43d2332b79b..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/iostream2/zstream.h +++ /dev/null @@ -1,307 +0,0 @@ -/* - * - * Copyright (c) 1997 - * Christian Michelsen Research AS - * Advanced Computing - * Fantoftvegen 38, 5036 BERGEN, Norway - * http://www.cmr.no - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Christian Michelsen Research AS makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -#ifndef ZSTREAM__H -#define ZSTREAM__H - -/* - * zstream.h - C++ interface to the 'zlib' general purpose compression library - * $Id: zstream.h 1.1 1997-06-25 12:00:56+02 tyge Exp tyge $ - */ - -#include -#include -#include -#include "zlib.h" - -#if defined(_WIN32) -# include -# include -# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) -#else -# define SET_BINARY_MODE(file) -#endif - -class zstringlen { -public: - zstringlen(class izstream&); - zstringlen(class ozstream&, const char*); - size_t value() const { return val.word; } -private: - struct Val { unsigned char byte; size_t word; } val; -}; - -// ----------------------------- izstream ----------------------------- - -class izstream -{ - public: - izstream() : m_fp(0) {} - izstream(FILE* fp) : m_fp(0) { open(fp); } - izstream(const char* name) : m_fp(0) { open(name); } - ~izstream() { close(); } - - /* Opens a gzip (.gz) file for reading. - * open() can be used to read a file which is not in gzip format; - * in this case read() will directly read from the file without - * decompression. errno can be checked to distinguish two error - * cases (if errno is zero, the zlib error is Z_MEM_ERROR). - */ - void open(const char* name) { - if (m_fp) close(); - m_fp = ::gzopen(name, "rb"); - } - - void open(FILE* fp) { - SET_BINARY_MODE(fp); - if (m_fp) close(); - m_fp = ::gzdopen(fileno(fp), "rb"); - } - - /* Flushes all pending input if necessary, closes the compressed file - * and deallocates all the (de)compression state. The return value is - * the zlib error number (see function error() below). - */ - int close() { - int r = ::gzclose(m_fp); - m_fp = 0; return r; - } - - /* Binary read the given number of bytes from the compressed file. - */ - int read(void* buf, size_t len) { - return ::gzread(m_fp, buf, len); - } - - /* Returns the error message for the last error which occurred on the - * given compressed file. errnum is set to zlib error number. If an - * error occurred in the file system and not in the compression library, - * errnum is set to Z_ERRNO and the application may consult errno - * to get the exact error code. - */ - const char* error(int* errnum) { - return ::gzerror(m_fp, errnum); - } - - gzFile fp() { return m_fp; } - - private: - gzFile m_fp; -}; - -/* - * Binary read the given (array of) object(s) from the compressed file. - * If the input file was not in gzip format, read() copies the objects number - * of bytes into the buffer. - * returns the number of uncompressed bytes actually read - * (0 for end of file, -1 for error). - */ -template -inline int read(izstream& zs, T* x, Items items) { - return ::gzread(zs.fp(), x, items*sizeof(T)); -} - -/* - * Binary input with the '>' operator. - */ -template -inline izstream& operator>(izstream& zs, T& x) { - ::gzread(zs.fp(), &x, sizeof(T)); - return zs; -} - - -inline zstringlen::zstringlen(izstream& zs) { - zs > val.byte; - if (val.byte == 255) zs > val.word; - else val.word = val.byte; -} - -/* - * Read length of string + the string with the '>' operator. - */ -inline izstream& operator>(izstream& zs, char* x) { - zstringlen len(zs); - ::gzread(zs.fp(), x, len.value()); - x[len.value()] = '\0'; - return zs; -} - -inline char* read_string(izstream& zs) { - zstringlen len(zs); - char* x = new char[len.value()+1]; - ::gzread(zs.fp(), x, len.value()); - x[len.value()] = '\0'; - return x; -} - -// ----------------------------- ozstream ----------------------------- - -class ozstream -{ - public: - ozstream() : m_fp(0), m_os(0) { - } - ozstream(FILE* fp, int level = Z_DEFAULT_COMPRESSION) - : m_fp(0), m_os(0) { - open(fp, level); - } - ozstream(const char* name, int level = Z_DEFAULT_COMPRESSION) - : m_fp(0), m_os(0) { - open(name, level); - } - ~ozstream() { - close(); - } - - /* Opens a gzip (.gz) file for writing. - * The compression level parameter should be in 0..9 - * errno can be checked to distinguish two error cases - * (if errno is zero, the zlib error is Z_MEM_ERROR). - */ - void open(const char* name, int level = Z_DEFAULT_COMPRESSION) { - char mode[4] = "wb\0"; - if (level != Z_DEFAULT_COMPRESSION) mode[2] = '0'+level; - if (m_fp) close(); - m_fp = ::gzopen(name, mode); - } - - /* open from a FILE pointer. - */ - void open(FILE* fp, int level = Z_DEFAULT_COMPRESSION) { - SET_BINARY_MODE(fp); - char mode[4] = "wb\0"; - if (level != Z_DEFAULT_COMPRESSION) mode[2] = '0'+level; - if (m_fp) close(); - m_fp = ::gzdopen(fileno(fp), mode); - } - - /* Flushes all pending output if necessary, closes the compressed file - * and deallocates all the (de)compression state. The return value is - * the zlib error number (see function error() below). - */ - int close() { - if (m_os) { - ::gzwrite(m_fp, m_os->str(), m_os->pcount()); - delete[] m_os->str(); delete m_os; m_os = 0; - } - int r = ::gzclose(m_fp); m_fp = 0; return r; - } - - /* Binary write the given number of bytes into the compressed file. - */ - int write(const void* buf, size_t len) { - return ::gzwrite(m_fp, (voidp) buf, len); - } - - /* Flushes all pending output into the compressed file. The parameter - * _flush is as in the deflate() function. The return value is the zlib - * error number (see function gzerror below). flush() returns Z_OK if - * the flush_ parameter is Z_FINISH and all output could be flushed. - * flush() should be called only when strictly necessary because it can - * degrade compression. - */ - int flush(int _flush) { - os_flush(); - return ::gzflush(m_fp, _flush); - } - - /* Returns the error message for the last error which occurred on the - * given compressed file. errnum is set to zlib error number. If an - * error occurred in the file system and not in the compression library, - * errnum is set to Z_ERRNO and the application may consult errno - * to get the exact error code. - */ - const char* error(int* errnum) { - return ::gzerror(m_fp, errnum); - } - - gzFile fp() { return m_fp; } - - ostream& os() { - if (m_os == 0) m_os = new ostrstream; - return *m_os; - } - - void os_flush() { - if (m_os && m_os->pcount()>0) { - ostrstream* oss = new ostrstream; - oss->fill(m_os->fill()); - oss->flags(m_os->flags()); - oss->precision(m_os->precision()); - oss->width(m_os->width()); - ::gzwrite(m_fp, m_os->str(), m_os->pcount()); - delete[] m_os->str(); delete m_os; m_os = oss; - } - } - - private: - gzFile m_fp; - ostrstream* m_os; -}; - -/* - * Binary write the given (array of) object(s) into the compressed file. - * returns the number of uncompressed bytes actually written - * (0 in case of error). - */ -template -inline int write(ozstream& zs, const T* x, Items items) { - return ::gzwrite(zs.fp(), (voidp) x, items*sizeof(T)); -} - -/* - * Binary output with the '<' operator. - */ -template -inline ozstream& operator<(ozstream& zs, const T& x) { - ::gzwrite(zs.fp(), (voidp) &x, sizeof(T)); - return zs; -} - -inline zstringlen::zstringlen(ozstream& zs, const char* x) { - val.byte = 255; val.word = ::strlen(x); - if (val.word < 255) zs < (val.byte = val.word); - else zs < val; -} - -/* - * Write length of string + the string with the '<' operator. - */ -inline ozstream& operator<(ozstream& zs, const char* x) { - zstringlen len(zs, x); - ::gzwrite(zs.fp(), (voidp) x, len.value()); - return zs; -} - -#ifdef _MSC_VER -inline ozstream& operator<(ozstream& zs, char* const& x) { - return zs < (const char*) x; -} -#endif - -/* - * Ascii write with the << operator; - */ -template -inline ostream& operator<<(ozstream& zs, const T& x) { - zs.os_flush(); - return zs.os() << x; -} - -#endif diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/iostream2/zstream_test.cpp b/src/beast/test/zlib/zlib-1.2.8/contrib/iostream2/zstream_test.cpp deleted file mode 100644 index 6273f62d62a..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/iostream2/zstream_test.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "zstream.h" -#include -#include -#include - -void main() { - char h[256] = "Hello"; - char* g = "Goodbye"; - ozstream out("temp.gz"); - out < "This works well" < h < g; - out.close(); - - izstream in("temp.gz"); // read it back - char *x = read_string(in), *y = new char[256], z[256]; - in > y > z; - in.close(); - cout << x << endl << y << endl << z << endl; - - out.open("temp.gz"); // try ascii output; zcat temp.gz to see the results - out << setw(50) << setfill('#') << setprecision(20) << x << endl << y << endl << z << endl; - out << z << endl << y << endl << x << endl; - out << 1.1234567890123456789 << endl; - - delete[] x; delete[] y; -} diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/iostream3/README b/src/beast/test/zlib/zlib-1.2.8/contrib/iostream3/README deleted file mode 100644 index f7b319ab91a..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/iostream3/README +++ /dev/null @@ -1,35 +0,0 @@ -These classes provide a C++ stream interface to the zlib library. It allows you -to do things like: - - gzofstream outf("blah.gz"); - outf << "These go into the gzip file " << 123 << endl; - -It does this by deriving a specialized stream buffer for gzipped files, which is -the way Stroustrup would have done it. :-> - -The gzifstream and gzofstream classes were originally written by Kevin Ruland -and made available in the zlib contrib/iostream directory. The older version still -compiles under gcc 2.xx, but not under gcc 3.xx, which sparked the development of -this version. - -The new classes are as standard-compliant as possible, closely following the -approach of the standard library's fstream classes. It compiles under gcc versions -3.2 and 3.3, but not under gcc 2.xx. This is mainly due to changes in the standard -library naming scheme. The new version of gzifstream/gzofstream/gzfilebuf differs -from the previous one in the following respects: -- added showmanyc -- added setbuf, with support for unbuffered output via setbuf(0,0) -- a few bug fixes of stream behavior -- gzipped output file opened with default compression level instead of maximum level -- setcompressionlevel()/strategy() members replaced by single setcompression() - -The code is provided "as is", with the permission to use, copy, modify, distribute -and sell it for any purpose without fee. - -Ludwig Schwardt - - -DSP Lab -Electrical & Electronic Engineering Department -University of Stellenbosch -South Africa diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/iostream3/TODO b/src/beast/test/zlib/zlib-1.2.8/contrib/iostream3/TODO deleted file mode 100644 index 7032f97be04..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/iostream3/TODO +++ /dev/null @@ -1,17 +0,0 @@ -Possible upgrades to gzfilebuf: - -- The ability to do putback (e.g. putbackfail) - -- The ability to seek (zlib supports this, but could be slow/tricky) - -- Simultaneous read/write access (does it make sense?) - -- Support for ios_base::ate open mode - -- Locale support? - -- Check public interface to see which calls give problems - (due to dependence on library internals) - -- Override operator<<(ostream&, gzfilebuf*) to allow direct copying - of stream buffer to stream ( i.e. os << is.rdbuf(); ) diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/iostream3/test.cc b/src/beast/test/zlib/zlib-1.2.8/contrib/iostream3/test.cc deleted file mode 100644 index 94235334f25..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/iostream3/test.cc +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Test program for gzifstream and gzofstream - * - * by Ludwig Schwardt - * original version by Kevin Ruland - */ - -#include "zfstream.h" -#include // for cout - -int main() { - - gzofstream outf; - gzifstream inf; - char buf[80]; - - outf.open("test1.txt.gz"); - outf << "The quick brown fox sidestepped the lazy canine\n" - << 1.3 << "\nPlan " << 9 << std::endl; - outf.close(); - std::cout << "Wrote the following message to 'test1.txt.gz' (check with zcat or zless):\n" - << "The quick brown fox sidestepped the lazy canine\n" - << 1.3 << "\nPlan " << 9 << std::endl; - - std::cout << "\nReading 'test1.txt.gz' (buffered) produces:\n"; - inf.open("test1.txt.gz"); - while (inf.getline(buf,80,'\n')) { - std::cout << buf << "\t(" << inf.rdbuf()->in_avail() << " chars left in buffer)\n"; - } - inf.close(); - - outf.rdbuf()->pubsetbuf(0,0); - outf.open("test2.txt.gz"); - outf << setcompression(Z_NO_COMPRESSION) - << "The quick brown fox sidestepped the lazy canine\n" - << 1.3 << "\nPlan " << 9 << std::endl; - outf.close(); - std::cout << "\nWrote the same message to 'test2.txt.gz' in uncompressed form"; - - std::cout << "\nReading 'test2.txt.gz' (unbuffered) produces:\n"; - inf.rdbuf()->pubsetbuf(0,0); - inf.open("test2.txt.gz"); - while (inf.getline(buf,80,'\n')) { - std::cout << buf << "\t(" << inf.rdbuf()->in_avail() << " chars left in buffer)\n"; - } - inf.close(); - - return 0; - -} diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/iostream3/zfstream.cc b/src/beast/test/zlib/zlib-1.2.8/contrib/iostream3/zfstream.cc deleted file mode 100644 index 94eb933444a..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/iostream3/zfstream.cc +++ /dev/null @@ -1,479 +0,0 @@ -/* - * A C++ I/O streams interface to the zlib gz* functions - * - * by Ludwig Schwardt - * original version by Kevin Ruland - * - * This version is standard-compliant and compatible with gcc 3.x. - */ - -#include "zfstream.h" -#include // for strcpy, strcat, strlen (mode strings) -#include // for BUFSIZ - -// Internal buffer sizes (default and "unbuffered" versions) -#define BIGBUFSIZE BUFSIZ -#define SMALLBUFSIZE 1 - -/*****************************************************************************/ - -// Default constructor -gzfilebuf::gzfilebuf() -: file(NULL), io_mode(std::ios_base::openmode(0)), own_fd(false), - buffer(NULL), buffer_size(BIGBUFSIZE), own_buffer(true) -{ - // No buffers to start with - this->disable_buffer(); -} - -// Destructor -gzfilebuf::~gzfilebuf() -{ - // Sync output buffer and close only if responsible for file - // (i.e. attached streams should be left open at this stage) - this->sync(); - if (own_fd) - this->close(); - // Make sure internal buffer is deallocated - this->disable_buffer(); -} - -// Set compression level and strategy -int -gzfilebuf::setcompression(int comp_level, - int comp_strategy) -{ - return gzsetparams(file, comp_level, comp_strategy); -} - -// Open gzipped file -gzfilebuf* -gzfilebuf::open(const char *name, - std::ios_base::openmode mode) -{ - // Fail if file already open - if (this->is_open()) - return NULL; - // Don't support simultaneous read/write access (yet) - if ((mode & std::ios_base::in) && (mode & std::ios_base::out)) - return NULL; - - // Build mode string for gzopen and check it [27.8.1.3.2] - char char_mode[6] = "\0\0\0\0\0"; - if (!this->open_mode(mode, char_mode)) - return NULL; - - // Attempt to open file - if ((file = gzopen(name, char_mode)) == NULL) - return NULL; - - // On success, allocate internal buffer and set flags - this->enable_buffer(); - io_mode = mode; - own_fd = true; - return this; -} - -// Attach to gzipped file -gzfilebuf* -gzfilebuf::attach(int fd, - std::ios_base::openmode mode) -{ - // Fail if file already open - if (this->is_open()) - return NULL; - // Don't support simultaneous read/write access (yet) - if ((mode & std::ios_base::in) && (mode & std::ios_base::out)) - return NULL; - - // Build mode string for gzdopen and check it [27.8.1.3.2] - char char_mode[6] = "\0\0\0\0\0"; - if (!this->open_mode(mode, char_mode)) - return NULL; - - // Attempt to attach to file - if ((file = gzdopen(fd, char_mode)) == NULL) - return NULL; - - // On success, allocate internal buffer and set flags - this->enable_buffer(); - io_mode = mode; - own_fd = false; - return this; -} - -// Close gzipped file -gzfilebuf* -gzfilebuf::close() -{ - // Fail immediately if no file is open - if (!this->is_open()) - return NULL; - // Assume success - gzfilebuf* retval = this; - // Attempt to sync and close gzipped file - if (this->sync() == -1) - retval = NULL; - if (gzclose(file) < 0) - retval = NULL; - // File is now gone anyway (postcondition [27.8.1.3.8]) - file = NULL; - own_fd = false; - // Destroy internal buffer if it exists - this->disable_buffer(); - return retval; -} - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -// Convert int open mode to mode string -bool -gzfilebuf::open_mode(std::ios_base::openmode mode, - char* c_mode) const -{ - bool testb = mode & std::ios_base::binary; - bool testi = mode & std::ios_base::in; - bool testo = mode & std::ios_base::out; - bool testt = mode & std::ios_base::trunc; - bool testa = mode & std::ios_base::app; - - // Check for valid flag combinations - see [27.8.1.3.2] (Table 92) - // Original zfstream hardcoded the compression level to maximum here... - // Double the time for less than 1% size improvement seems - // excessive though - keeping it at the default level - // To change back, just append "9" to the next three mode strings - if (!testi && testo && !testt && !testa) - strcpy(c_mode, "w"); - if (!testi && testo && !testt && testa) - strcpy(c_mode, "a"); - if (!testi && testo && testt && !testa) - strcpy(c_mode, "w"); - if (testi && !testo && !testt && !testa) - strcpy(c_mode, "r"); - // No read/write mode yet -// if (testi && testo && !testt && !testa) -// strcpy(c_mode, "r+"); -// if (testi && testo && testt && !testa) -// strcpy(c_mode, "w+"); - - // Mode string should be empty for invalid combination of flags - if (strlen(c_mode) == 0) - return false; - if (testb) - strcat(c_mode, "b"); - return true; -} - -// Determine number of characters in internal get buffer -std::streamsize -gzfilebuf::showmanyc() -{ - // Calls to underflow will fail if file not opened for reading - if (!this->is_open() || !(io_mode & std::ios_base::in)) - return -1; - // Make sure get area is in use - if (this->gptr() && (this->gptr() < this->egptr())) - return std::streamsize(this->egptr() - this->gptr()); - else - return 0; -} - -// Fill get area from gzipped file -gzfilebuf::int_type -gzfilebuf::underflow() -{ - // If something is left in the get area by chance, return it - // (this shouldn't normally happen, as underflow is only supposed - // to be called when gptr >= egptr, but it serves as error check) - if (this->gptr() && (this->gptr() < this->egptr())) - return traits_type::to_int_type(*(this->gptr())); - - // If the file hasn't been opened for reading, produce error - if (!this->is_open() || !(io_mode & std::ios_base::in)) - return traits_type::eof(); - - // Attempt to fill internal buffer from gzipped file - // (buffer must be guaranteed to exist...) - int bytes_read = gzread(file, buffer, buffer_size); - // Indicates error or EOF - if (bytes_read <= 0) - { - // Reset get area - this->setg(buffer, buffer, buffer); - return traits_type::eof(); - } - // Make all bytes read from file available as get area - this->setg(buffer, buffer, buffer + bytes_read); - - // Return next character in get area - return traits_type::to_int_type(*(this->gptr())); -} - -// Write put area to gzipped file -gzfilebuf::int_type -gzfilebuf::overflow(int_type c) -{ - // Determine whether put area is in use - if (this->pbase()) - { - // Double-check pointer range - if (this->pptr() > this->epptr() || this->pptr() < this->pbase()) - return traits_type::eof(); - // Add extra character to buffer if not EOF - if (!traits_type::eq_int_type(c, traits_type::eof())) - { - *(this->pptr()) = traits_type::to_char_type(c); - this->pbump(1); - } - // Number of characters to write to file - int bytes_to_write = this->pptr() - this->pbase(); - // Overflow doesn't fail if nothing is to be written - if (bytes_to_write > 0) - { - // If the file hasn't been opened for writing, produce error - if (!this->is_open() || !(io_mode & std::ios_base::out)) - return traits_type::eof(); - // If gzipped file won't accept all bytes written to it, fail - if (gzwrite(file, this->pbase(), bytes_to_write) != bytes_to_write) - return traits_type::eof(); - // Reset next pointer to point to pbase on success - this->pbump(-bytes_to_write); - } - } - // Write extra character to file if not EOF - else if (!traits_type::eq_int_type(c, traits_type::eof())) - { - // If the file hasn't been opened for writing, produce error - if (!this->is_open() || !(io_mode & std::ios_base::out)) - return traits_type::eof(); - // Impromptu char buffer (allows "unbuffered" output) - char_type last_char = traits_type::to_char_type(c); - // If gzipped file won't accept this character, fail - if (gzwrite(file, &last_char, 1) != 1) - return traits_type::eof(); - } - - // If you got here, you have succeeded (even if c was EOF) - // The return value should therefore be non-EOF - if (traits_type::eq_int_type(c, traits_type::eof())) - return traits_type::not_eof(c); - else - return c; -} - -// Assign new buffer -std::streambuf* -gzfilebuf::setbuf(char_type* p, - std::streamsize n) -{ - // First make sure stuff is sync'ed, for safety - if (this->sync() == -1) - return NULL; - // If buffering is turned off on purpose via setbuf(0,0), still allocate one... - // "Unbuffered" only really refers to put [27.8.1.4.10], while get needs at - // least a buffer of size 1 (very inefficient though, therefore make it bigger?) - // This follows from [27.5.2.4.3]/12 (gptr needs to point at something, it seems) - if (!p || !n) - { - // Replace existing buffer (if any) with small internal buffer - this->disable_buffer(); - buffer = NULL; - buffer_size = 0; - own_buffer = true; - this->enable_buffer(); - } - else - { - // Replace existing buffer (if any) with external buffer - this->disable_buffer(); - buffer = p; - buffer_size = n; - own_buffer = false; - this->enable_buffer(); - } - return this; -} - -// Write put area to gzipped file (i.e. ensures that put area is empty) -int -gzfilebuf::sync() -{ - return traits_type::eq_int_type(this->overflow(), traits_type::eof()) ? -1 : 0; -} - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -// Allocate internal buffer -void -gzfilebuf::enable_buffer() -{ - // If internal buffer required, allocate one - if (own_buffer && !buffer) - { - // Check for buffered vs. "unbuffered" - if (buffer_size > 0) - { - // Allocate internal buffer - buffer = new char_type[buffer_size]; - // Get area starts empty and will be expanded by underflow as need arises - this->setg(buffer, buffer, buffer); - // Setup entire internal buffer as put area. - // The one-past-end pointer actually points to the last element of the buffer, - // so that overflow(c) can safely add the extra character c to the sequence. - // These pointers remain in place for the duration of the buffer - this->setp(buffer, buffer + buffer_size - 1); - } - else - { - // Even in "unbuffered" case, (small?) get buffer is still required - buffer_size = SMALLBUFSIZE; - buffer = new char_type[buffer_size]; - this->setg(buffer, buffer, buffer); - // "Unbuffered" means no put buffer - this->setp(0, 0); - } - } - else - { - // If buffer already allocated, reset buffer pointers just to make sure no - // stale chars are lying around - this->setg(buffer, buffer, buffer); - this->setp(buffer, buffer + buffer_size - 1); - } -} - -// Destroy internal buffer -void -gzfilebuf::disable_buffer() -{ - // If internal buffer exists, deallocate it - if (own_buffer && buffer) - { - // Preserve unbuffered status by zeroing size - if (!this->pbase()) - buffer_size = 0; - delete[] buffer; - buffer = NULL; - this->setg(0, 0, 0); - this->setp(0, 0); - } - else - { - // Reset buffer pointers to initial state if external buffer exists - this->setg(buffer, buffer, buffer); - if (buffer) - this->setp(buffer, buffer + buffer_size - 1); - else - this->setp(0, 0); - } -} - -/*****************************************************************************/ - -// Default constructor initializes stream buffer -gzifstream::gzifstream() -: std::istream(NULL), sb() -{ this->init(&sb); } - -// Initialize stream buffer and open file -gzifstream::gzifstream(const char* name, - std::ios_base::openmode mode) -: std::istream(NULL), sb() -{ - this->init(&sb); - this->open(name, mode); -} - -// Initialize stream buffer and attach to file -gzifstream::gzifstream(int fd, - std::ios_base::openmode mode) -: std::istream(NULL), sb() -{ - this->init(&sb); - this->attach(fd, mode); -} - -// Open file and go into fail() state if unsuccessful -void -gzifstream::open(const char* name, - std::ios_base::openmode mode) -{ - if (!sb.open(name, mode | std::ios_base::in)) - this->setstate(std::ios_base::failbit); - else - this->clear(); -} - -// Attach to file and go into fail() state if unsuccessful -void -gzifstream::attach(int fd, - std::ios_base::openmode mode) -{ - if (!sb.attach(fd, mode | std::ios_base::in)) - this->setstate(std::ios_base::failbit); - else - this->clear(); -} - -// Close file -void -gzifstream::close() -{ - if (!sb.close()) - this->setstate(std::ios_base::failbit); -} - -/*****************************************************************************/ - -// Default constructor initializes stream buffer -gzofstream::gzofstream() -: std::ostream(NULL), sb() -{ this->init(&sb); } - -// Initialize stream buffer and open file -gzofstream::gzofstream(const char* name, - std::ios_base::openmode mode) -: std::ostream(NULL), sb() -{ - this->init(&sb); - this->open(name, mode); -} - -// Initialize stream buffer and attach to file -gzofstream::gzofstream(int fd, - std::ios_base::openmode mode) -: std::ostream(NULL), sb() -{ - this->init(&sb); - this->attach(fd, mode); -} - -// Open file and go into fail() state if unsuccessful -void -gzofstream::open(const char* name, - std::ios_base::openmode mode) -{ - if (!sb.open(name, mode | std::ios_base::out)) - this->setstate(std::ios_base::failbit); - else - this->clear(); -} - -// Attach to file and go into fail() state if unsuccessful -void -gzofstream::attach(int fd, - std::ios_base::openmode mode) -{ - if (!sb.attach(fd, mode | std::ios_base::out)) - this->setstate(std::ios_base::failbit); - else - this->clear(); -} - -// Close file -void -gzofstream::close() -{ - if (!sb.close()) - this->setstate(std::ios_base::failbit); -} diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/iostream3/zfstream.h b/src/beast/test/zlib/zlib-1.2.8/contrib/iostream3/zfstream.h deleted file mode 100644 index 8574479ae1e..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/iostream3/zfstream.h +++ /dev/null @@ -1,466 +0,0 @@ -/* - * A C++ I/O streams interface to the zlib gz* functions - * - * by Ludwig Schwardt - * original version by Kevin Ruland - * - * This version is standard-compliant and compatible with gcc 3.x. - */ - -#ifndef ZFSTREAM_H -#define ZFSTREAM_H - -#include // not iostream, since we don't need cin/cout -#include -#include "zlib.h" - -/*****************************************************************************/ - -/** - * @brief Gzipped file stream buffer class. - * - * This class implements basic_filebuf for gzipped files. It doesn't yet support - * seeking (allowed by zlib but slow/limited), putback and read/write access - * (tricky). Otherwise, it attempts to be a drop-in replacement for the standard - * file streambuf. -*/ -class gzfilebuf : public std::streambuf -{ -public: - // Default constructor. - gzfilebuf(); - - // Destructor. - virtual - ~gzfilebuf(); - - /** - * @brief Set compression level and strategy on the fly. - * @param comp_level Compression level (see zlib.h for allowed values) - * @param comp_strategy Compression strategy (see zlib.h for allowed values) - * @return Z_OK on success, Z_STREAM_ERROR otherwise. - * - * Unfortunately, these parameters cannot be modified separately, as the - * previous zfstream version assumed. Since the strategy is seldom changed, - * it can default and setcompression(level) then becomes like the old - * setcompressionlevel(level). - */ - int - setcompression(int comp_level, - int comp_strategy = Z_DEFAULT_STRATEGY); - - /** - * @brief Check if file is open. - * @return True if file is open. - */ - bool - is_open() const { return (file != NULL); } - - /** - * @brief Open gzipped file. - * @param name File name. - * @param mode Open mode flags. - * @return @c this on success, NULL on failure. - */ - gzfilebuf* - open(const char* name, - std::ios_base::openmode mode); - - /** - * @brief Attach to already open gzipped file. - * @param fd File descriptor. - * @param mode Open mode flags. - * @return @c this on success, NULL on failure. - */ - gzfilebuf* - attach(int fd, - std::ios_base::openmode mode); - - /** - * @brief Close gzipped file. - * @return @c this on success, NULL on failure. - */ - gzfilebuf* - close(); - -protected: - /** - * @brief Convert ios open mode int to mode string used by zlib. - * @return True if valid mode flag combination. - */ - bool - open_mode(std::ios_base::openmode mode, - char* c_mode) const; - - /** - * @brief Number of characters available in stream buffer. - * @return Number of characters. - * - * This indicates number of characters in get area of stream buffer. - * These characters can be read without accessing the gzipped file. - */ - virtual std::streamsize - showmanyc(); - - /** - * @brief Fill get area from gzipped file. - * @return First character in get area on success, EOF on error. - * - * This actually reads characters from gzipped file to stream - * buffer. Always buffered. - */ - virtual int_type - underflow(); - - /** - * @brief Write put area to gzipped file. - * @param c Extra character to add to buffer contents. - * @return Non-EOF on success, EOF on error. - * - * This actually writes characters in stream buffer to - * gzipped file. With unbuffered output this is done one - * character at a time. - */ - virtual int_type - overflow(int_type c = traits_type::eof()); - - /** - * @brief Installs external stream buffer. - * @param p Pointer to char buffer. - * @param n Size of external buffer. - * @return @c this on success, NULL on failure. - * - * Call setbuf(0,0) to enable unbuffered output. - */ - virtual std::streambuf* - setbuf(char_type* p, - std::streamsize n); - - /** - * @brief Flush stream buffer to file. - * @return 0 on success, -1 on error. - * - * This calls underflow(EOF) to do the job. - */ - virtual int - sync(); - -// -// Some future enhancements -// -// virtual int_type uflow(); -// virtual int_type pbackfail(int_type c = traits_type::eof()); -// virtual pos_type -// seekoff(off_type off, -// std::ios_base::seekdir way, -// std::ios_base::openmode mode = std::ios_base::in|std::ios_base::out); -// virtual pos_type -// seekpos(pos_type sp, -// std::ios_base::openmode mode = std::ios_base::in|std::ios_base::out); - -private: - /** - * @brief Allocate internal buffer. - * - * This function is safe to call multiple times. It will ensure - * that a proper internal buffer exists if it is required. If the - * buffer already exists or is external, the buffer pointers will be - * reset to their original state. - */ - void - enable_buffer(); - - /** - * @brief Destroy internal buffer. - * - * This function is safe to call multiple times. It will ensure - * that the internal buffer is deallocated if it exists. In any - * case, it will also reset the buffer pointers. - */ - void - disable_buffer(); - - /** - * Underlying file pointer. - */ - gzFile file; - - /** - * Mode in which file was opened. - */ - std::ios_base::openmode io_mode; - - /** - * @brief True if this object owns file descriptor. - * - * This makes the class responsible for closing the file - * upon destruction. - */ - bool own_fd; - - /** - * @brief Stream buffer. - * - * For simplicity this remains allocated on the free store for the - * entire life span of the gzfilebuf object, unless replaced by setbuf. - */ - char_type* buffer; - - /** - * @brief Stream buffer size. - * - * Defaults to system default buffer size (typically 8192 bytes). - * Modified by setbuf. - */ - std::streamsize buffer_size; - - /** - * @brief True if this object owns stream buffer. - * - * This makes the class responsible for deleting the buffer - * upon destruction. - */ - bool own_buffer; -}; - -/*****************************************************************************/ - -/** - * @brief Gzipped file input stream class. - * - * This class implements ifstream for gzipped files. Seeking and putback - * is not supported yet. -*/ -class gzifstream : public std::istream -{ -public: - // Default constructor - gzifstream(); - - /** - * @brief Construct stream on gzipped file to be opened. - * @param name File name. - * @param mode Open mode flags (forced to contain ios::in). - */ - explicit - gzifstream(const char* name, - std::ios_base::openmode mode = std::ios_base::in); - - /** - * @brief Construct stream on already open gzipped file. - * @param fd File descriptor. - * @param mode Open mode flags (forced to contain ios::in). - */ - explicit - gzifstream(int fd, - std::ios_base::openmode mode = std::ios_base::in); - - /** - * Obtain underlying stream buffer. - */ - gzfilebuf* - rdbuf() const - { return const_cast(&sb); } - - /** - * @brief Check if file is open. - * @return True if file is open. - */ - bool - is_open() { return sb.is_open(); } - - /** - * @brief Open gzipped file. - * @param name File name. - * @param mode Open mode flags (forced to contain ios::in). - * - * Stream will be in state good() if file opens successfully; - * otherwise in state fail(). This differs from the behavior of - * ifstream, which never sets the state to good() and therefore - * won't allow you to reuse the stream for a second file unless - * you manually clear() the state. The choice is a matter of - * convenience. - */ - void - open(const char* name, - std::ios_base::openmode mode = std::ios_base::in); - - /** - * @brief Attach to already open gzipped file. - * @param fd File descriptor. - * @param mode Open mode flags (forced to contain ios::in). - * - * Stream will be in state good() if attach succeeded; otherwise - * in state fail(). - */ - void - attach(int fd, - std::ios_base::openmode mode = std::ios_base::in); - - /** - * @brief Close gzipped file. - * - * Stream will be in state fail() if close failed. - */ - void - close(); - -private: - /** - * Underlying stream buffer. - */ - gzfilebuf sb; -}; - -/*****************************************************************************/ - -/** - * @brief Gzipped file output stream class. - * - * This class implements ofstream for gzipped files. Seeking and putback - * is not supported yet. -*/ -class gzofstream : public std::ostream -{ -public: - // Default constructor - gzofstream(); - - /** - * @brief Construct stream on gzipped file to be opened. - * @param name File name. - * @param mode Open mode flags (forced to contain ios::out). - */ - explicit - gzofstream(const char* name, - std::ios_base::openmode mode = std::ios_base::out); - - /** - * @brief Construct stream on already open gzipped file. - * @param fd File descriptor. - * @param mode Open mode flags (forced to contain ios::out). - */ - explicit - gzofstream(int fd, - std::ios_base::openmode mode = std::ios_base::out); - - /** - * Obtain underlying stream buffer. - */ - gzfilebuf* - rdbuf() const - { return const_cast(&sb); } - - /** - * @brief Check if file is open. - * @return True if file is open. - */ - bool - is_open() { return sb.is_open(); } - - /** - * @brief Open gzipped file. - * @param name File name. - * @param mode Open mode flags (forced to contain ios::out). - * - * Stream will be in state good() if file opens successfully; - * otherwise in state fail(). This differs from the behavior of - * ofstream, which never sets the state to good() and therefore - * won't allow you to reuse the stream for a second file unless - * you manually clear() the state. The choice is a matter of - * convenience. - */ - void - open(const char* name, - std::ios_base::openmode mode = std::ios_base::out); - - /** - * @brief Attach to already open gzipped file. - * @param fd File descriptor. - * @param mode Open mode flags (forced to contain ios::out). - * - * Stream will be in state good() if attach succeeded; otherwise - * in state fail(). - */ - void - attach(int fd, - std::ios_base::openmode mode = std::ios_base::out); - - /** - * @brief Close gzipped file. - * - * Stream will be in state fail() if close failed. - */ - void - close(); - -private: - /** - * Underlying stream buffer. - */ - gzfilebuf sb; -}; - -/*****************************************************************************/ - -/** - * @brief Gzipped file output stream manipulator class. - * - * This class defines a two-argument manipulator for gzofstream. It is used - * as base for the setcompression(int,int) manipulator. -*/ -template - class gzomanip2 - { - public: - // Allows insertor to peek at internals - template - friend gzofstream& - operator<<(gzofstream&, - const gzomanip2&); - - // Constructor - gzomanip2(gzofstream& (*f)(gzofstream&, T1, T2), - T1 v1, - T2 v2); - private: - // Underlying manipulator function - gzofstream& - (*func)(gzofstream&, T1, T2); - - // Arguments for manipulator function - T1 val1; - T2 val2; - }; - -/*****************************************************************************/ - -// Manipulator function thunks through to stream buffer -inline gzofstream& -setcompression(gzofstream &gzs, int l, int s = Z_DEFAULT_STRATEGY) -{ - (gzs.rdbuf())->setcompression(l, s); - return gzs; -} - -// Manipulator constructor stores arguments -template - inline - gzomanip2::gzomanip2(gzofstream &(*f)(gzofstream &, T1, T2), - T1 v1, - T2 v2) - : func(f), val1(v1), val2(v2) - { } - -// Insertor applies underlying manipulator function to stream -template - inline gzofstream& - operator<<(gzofstream& s, const gzomanip2& m) - { return (*m.func)(s, m.val1, m.val2); } - -// Insert this onto stream to simplify setting of compression level -inline gzomanip2 -setcompression(int l, int s = Z_DEFAULT_STRATEGY) -{ return gzomanip2(&setcompression, l, s); } - -#endif // ZFSTREAM_H diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/masmx64/bld_ml64.bat b/src/beast/test/zlib/zlib-1.2.8/contrib/masmx64/bld_ml64.bat deleted file mode 100644 index f74bcef5b48..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/masmx64/bld_ml64.bat +++ /dev/null @@ -1,2 +0,0 @@ -ml64.exe /Flinffasx64 /c /Zi inffasx64.asm -ml64.exe /Flgvmat64 /c /Zi gvmat64.asm diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/masmx64/gvmat64.asm b/src/beast/test/zlib/zlib-1.2.8/contrib/masmx64/gvmat64.asm deleted file mode 100644 index c1817f1be96..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/masmx64/gvmat64.asm +++ /dev/null @@ -1,553 +0,0 @@ -;uInt longest_match_x64( -; deflate_state *s, -; IPos cur_match); /* current match */ - -; gvmat64.asm -- Asm portion of the optimized longest_match for 32 bits x86_64 -; (AMD64 on Athlon 64, Opteron, Phenom -; and Intel EM64T on Pentium 4 with EM64T, Pentium D, Core 2 Duo, Core I5/I7) -; Copyright (C) 1995-2010 Jean-loup Gailly, Brian Raiter and Gilles Vollant. -; -; File written by Gilles Vollant, by converting to assembly the longest_match -; from Jean-loup Gailly in deflate.c of zLib and infoZip zip. -; -; and by taking inspiration on asm686 with masm, optimised assembly code -; from Brian Raiter, written 1998 -; -; This software is provided 'as-is', without any express or implied -; warranty. In no event will the authors be held liable for any damages -; arising from the use of this software. -; -; Permission is granted to anyone to use this software for any purpose, -; including commercial applications, and to alter it and redistribute it -; freely, subject to the following restrictions: -; -; 1. The origin of this software must not be misrepresented; you must not -; claim that you wrote the original software. If you use this software -; in a product, an acknowledgment in the product documentation would be -; appreciated but is not required. -; 2. Altered source versions must be plainly marked as such, and must not be -; misrepresented as being the original software -; 3. This notice may not be removed or altered from any source distribution. -; -; -; -; http://www.zlib.net -; http://www.winimage.com/zLibDll -; http://www.muppetlabs.com/~breadbox/software/assembly.html -; -; to compile this file for infozip Zip, I use option: -; ml64.exe /Flgvmat64 /c /Zi /DINFOZIP gvmat64.asm -; -; to compile this file for zLib, I use option: -; ml64.exe /Flgvmat64 /c /Zi gvmat64.asm -; Be carrefull to adapt zlib1222add below to your version of zLib -; (if you use a version of zLib before 1.0.4 or after 1.2.2.2, change -; value of zlib1222add later) -; -; This file compile with Microsoft Macro Assembler (x64) for AMD64 -; -; ml64.exe is given with Visual Studio 2005/2008/2010 and Windows WDK -; -; (you can get Windows WDK with ml64 for AMD64 from -; http://www.microsoft.com/whdc/Devtools/wdk/default.mspx for low price) -; - - -;uInt longest_match(s, cur_match) -; deflate_state *s; -; IPos cur_match; /* current match */ -.code -longest_match PROC - - -;LocalVarsSize equ 88 - LocalVarsSize equ 72 - -; register used : rax,rbx,rcx,rdx,rsi,rdi,r8,r9,r10,r11,r12 -; free register : r14,r15 -; register can be saved : rsp - - chainlenwmask equ rsp + 8 - LocalVarsSize ; high word: current chain len - ; low word: s->wmask -;window equ rsp + xx - LocalVarsSize ; local copy of s->window ; stored in r10 -;windowbestlen equ rsp + xx - LocalVarsSize ; s->window + bestlen , use r10+r11 -;scanstart equ rsp + xx - LocalVarsSize ; first two bytes of string ; stored in r12w -;scanend equ rsp + xx - LocalVarsSize ; last two bytes of string use ebx -;scanalign equ rsp + xx - LocalVarsSize ; dword-misalignment of string r13 -;bestlen equ rsp + xx - LocalVarsSize ; size of best match so far -> r11d -;scan equ rsp + xx - LocalVarsSize ; ptr to string wanting match -> r9 -IFDEF INFOZIP -ELSE - nicematch equ (rsp + 16 - LocalVarsSize) ; a good enough match size -ENDIF - -save_rdi equ rsp + 24 - LocalVarsSize -save_rsi equ rsp + 32 - LocalVarsSize -save_rbx equ rsp + 40 - LocalVarsSize -save_rbp equ rsp + 48 - LocalVarsSize -save_r12 equ rsp + 56 - LocalVarsSize -save_r13 equ rsp + 64 - LocalVarsSize -;save_r14 equ rsp + 72 - LocalVarsSize -;save_r15 equ rsp + 80 - LocalVarsSize - - -; summary of register usage -; scanend ebx -; scanendw bx -; chainlenwmask edx -; curmatch rsi -; curmatchd esi -; windowbestlen r8 -; scanalign r9 -; scanalignd r9d -; window r10 -; bestlen r11 -; bestlend r11d -; scanstart r12d -; scanstartw r12w -; scan r13 -; nicematch r14d -; limit r15 -; limitd r15d -; prev rcx - -; all the +4 offsets are due to the addition of pending_buf_size (in zlib -; in the deflate_state structure since the asm code was first written -; (if you compile with zlib 1.0.4 or older, remove the +4). -; Note : these value are good with a 8 bytes boundary pack structure - - - MAX_MATCH equ 258 - MIN_MATCH equ 3 - MIN_LOOKAHEAD equ (MAX_MATCH+MIN_MATCH+1) - - -;;; Offsets for fields in the deflate_state structure. These numbers -;;; are calculated from the definition of deflate_state, with the -;;; assumption that the compiler will dword-align the fields. (Thus, -;;; changing the definition of deflate_state could easily cause this -;;; program to crash horribly, without so much as a warning at -;;; compile time. Sigh.) - -; all the +zlib1222add offsets are due to the addition of fields -; in zlib in the deflate_state structure since the asm code was first written -; (if you compile with zlib 1.0.4 or older, use "zlib1222add equ (-4)"). -; (if you compile with zlib between 1.0.5 and 1.2.2.1, use "zlib1222add equ 0"). -; if you compile with zlib 1.2.2.2 or later , use "zlib1222add equ 8"). - - -IFDEF INFOZIP - -_DATA SEGMENT -COMM window_size:DWORD -; WMask ; 7fff -COMM window:BYTE:010040H -COMM prev:WORD:08000H -; MatchLen : unused -; PrevMatch : unused -COMM strstart:DWORD -COMM match_start:DWORD -; Lookahead : ignore -COMM prev_length:DWORD ; PrevLen -COMM max_chain_length:DWORD -COMM good_match:DWORD -COMM nice_match:DWORD -prev_ad equ OFFSET prev -window_ad equ OFFSET window -nicematch equ nice_match -_DATA ENDS -WMask equ 07fffh - -ELSE - - IFNDEF zlib1222add - zlib1222add equ 8 - ENDIF -dsWSize equ 56+zlib1222add+(zlib1222add/2) -dsWMask equ 64+zlib1222add+(zlib1222add/2) -dsWindow equ 72+zlib1222add -dsPrev equ 88+zlib1222add -dsMatchLen equ 128+zlib1222add -dsPrevMatch equ 132+zlib1222add -dsStrStart equ 140+zlib1222add -dsMatchStart equ 144+zlib1222add -dsLookahead equ 148+zlib1222add -dsPrevLen equ 152+zlib1222add -dsMaxChainLen equ 156+zlib1222add -dsGoodMatch equ 172+zlib1222add -dsNiceMatch equ 176+zlib1222add - -window_size equ [ rcx + dsWSize] -WMask equ [ rcx + dsWMask] -window_ad equ [ rcx + dsWindow] -prev_ad equ [ rcx + dsPrev] -strstart equ [ rcx + dsStrStart] -match_start equ [ rcx + dsMatchStart] -Lookahead equ [ rcx + dsLookahead] ; 0ffffffffh on infozip -prev_length equ [ rcx + dsPrevLen] -max_chain_length equ [ rcx + dsMaxChainLen] -good_match equ [ rcx + dsGoodMatch] -nice_match equ [ rcx + dsNiceMatch] -ENDIF - -; parameter 1 in r8(deflate state s), param 2 in rdx (cur match) - -; see http://weblogs.asp.net/oldnewthing/archive/2004/01/14/58579.aspx and -; http://msdn.microsoft.com/library/en-us/kmarch/hh/kmarch/64bitAMD_8e951dd2-ee77-4728-8702-55ce4b5dd24a.xml.asp -; -; All registers must be preserved across the call, except for -; rax, rcx, rdx, r8, r9, r10, and r11, which are scratch. - - - -;;; Save registers that the compiler may be using, and adjust esp to -;;; make room for our stack frame. - - -;;; Retrieve the function arguments. r8d will hold cur_match -;;; throughout the entire function. edx will hold the pointer to the -;;; deflate_state structure during the function's setup (before -;;; entering the main loop. - -; parameter 1 in rcx (deflate_state* s), param 2 in edx -> r8 (cur match) - -; this clear high 32 bits of r8, which can be garbage in both r8 and rdx - - mov [save_rdi],rdi - mov [save_rsi],rsi - mov [save_rbx],rbx - mov [save_rbp],rbp -IFDEF INFOZIP - mov r8d,ecx -ELSE - mov r8d,edx -ENDIF - mov [save_r12],r12 - mov [save_r13],r13 -; mov [save_r14],r14 -; mov [save_r15],r15 - - -;;; uInt wmask = s->w_mask; -;;; unsigned chain_length = s->max_chain_length; -;;; if (s->prev_length >= s->good_match) { -;;; chain_length >>= 2; -;;; } - - mov edi, prev_length - mov esi, good_match - mov eax, WMask - mov ebx, max_chain_length - cmp edi, esi - jl LastMatchGood - shr ebx, 2 -LastMatchGood: - -;;; chainlen is decremented once beforehand so that the function can -;;; use the sign flag instead of the zero flag for the exit test. -;;; It is then shifted into the high word, to make room for the wmask -;;; value, which it will always accompany. - - dec ebx - shl ebx, 16 - or ebx, eax - -;;; on zlib only -;;; if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; - -IFDEF INFOZIP - mov [chainlenwmask], ebx -; on infozip nice_match = [nice_match] -ELSE - mov eax, nice_match - mov [chainlenwmask], ebx - mov r10d, Lookahead - cmp r10d, eax - cmovnl r10d, eax - mov [nicematch],r10d -ENDIF - -;;; register Bytef *scan = s->window + s->strstart; - mov r10, window_ad - mov ebp, strstart - lea r13, [r10 + rbp] - -;;; Determine how many bytes the scan ptr is off from being -;;; dword-aligned. - - mov r9,r13 - neg r13 - and r13,3 - -;;; IPos limit = s->strstart > (IPos)MAX_DIST(s) ? -;;; s->strstart - (IPos)MAX_DIST(s) : NIL; -IFDEF INFOZIP - mov eax,07efah ; MAX_DIST = (WSIZE-MIN_LOOKAHEAD) (0x8000-(3+8+1)) -ELSE - mov eax, window_size - sub eax, MIN_LOOKAHEAD -ENDIF - xor edi,edi - sub ebp, eax - - mov r11d, prev_length - - cmovng ebp,edi - -;;; int best_len = s->prev_length; - - -;;; Store the sum of s->window + best_len in esi locally, and in esi. - - lea rsi,[r10+r11] - -;;; register ush scan_start = *(ushf*)scan; -;;; register ush scan_end = *(ushf*)(scan+best_len-1); -;;; Posf *prev = s->prev; - - movzx r12d,word ptr [r9] - movzx ebx, word ptr [r9 + r11 - 1] - - mov rdi, prev_ad - -;;; Jump into the main loop. - - mov edx, [chainlenwmask] - - cmp bx,word ptr [rsi + r8 - 1] - jz LookupLoopIsZero - -LookupLoop1: - and r8d, edx - - movzx r8d, word ptr [rdi + r8*2] - cmp r8d, ebp - jbe LeaveNow - sub edx, 00010000h - js LeaveNow - -LoopEntry1: - cmp bx,word ptr [rsi + r8 - 1] - jz LookupLoopIsZero - -LookupLoop2: - and r8d, edx - - movzx r8d, word ptr [rdi + r8*2] - cmp r8d, ebp - jbe LeaveNow - sub edx, 00010000h - js LeaveNow - -LoopEntry2: - cmp bx,word ptr [rsi + r8 - 1] - jz LookupLoopIsZero - -LookupLoop4: - and r8d, edx - - movzx r8d, word ptr [rdi + r8*2] - cmp r8d, ebp - jbe LeaveNow - sub edx, 00010000h - js LeaveNow - -LoopEntry4: - - cmp bx,word ptr [rsi + r8 - 1] - jnz LookupLoop1 - jmp LookupLoopIsZero - - -;;; do { -;;; match = s->window + cur_match; -;;; if (*(ushf*)(match+best_len-1) != scan_end || -;;; *(ushf*)match != scan_start) continue; -;;; [...] -;;; } while ((cur_match = prev[cur_match & wmask]) > limit -;;; && --chain_length != 0); -;;; -;;; Here is the inner loop of the function. The function will spend the -;;; majority of its time in this loop, and majority of that time will -;;; be spent in the first ten instructions. -;;; -;;; Within this loop: -;;; ebx = scanend -;;; r8d = curmatch -;;; edx = chainlenwmask - i.e., ((chainlen << 16) | wmask) -;;; esi = windowbestlen - i.e., (window + bestlen) -;;; edi = prev -;;; ebp = limit - -LookupLoop: - and r8d, edx - - movzx r8d, word ptr [rdi + r8*2] - cmp r8d, ebp - jbe LeaveNow - sub edx, 00010000h - js LeaveNow - -LoopEntry: - - cmp bx,word ptr [rsi + r8 - 1] - jnz LookupLoop1 -LookupLoopIsZero: - cmp r12w, word ptr [r10 + r8] - jnz LookupLoop1 - - -;;; Store the current value of chainlen. - mov [chainlenwmask], edx - -;;; Point edi to the string under scrutiny, and esi to the string we -;;; are hoping to match it up with. In actuality, esi and edi are -;;; both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and edx is -;;; initialized to -(MAX_MATCH_8 - scanalign). - - lea rsi,[r8+r10] - mov rdx, 0fffffffffffffef8h; -(MAX_MATCH_8) - lea rsi, [rsi + r13 + 0108h] ;MAX_MATCH_8] - lea rdi, [r9 + r13 + 0108h] ;MAX_MATCH_8] - - prefetcht1 [rsi+rdx] - prefetcht1 [rdi+rdx] - - -;;; Test the strings for equality, 8 bytes at a time. At the end, -;;; adjust rdx so that it is offset to the exact byte that mismatched. -;;; -;;; We already know at this point that the first three bytes of the -;;; strings match each other, and they can be safely passed over before -;;; starting the compare loop. So what this code does is skip over 0-3 -;;; bytes, as much as necessary in order to dword-align the edi -;;; pointer. (rsi will still be misaligned three times out of four.) -;;; -;;; It should be confessed that this loop usually does not represent -;;; much of the total running time. Replacing it with a more -;;; straightforward "rep cmpsb" would not drastically degrade -;;; performance. - - -LoopCmps: - mov rax, [rsi + rdx] - xor rax, [rdi + rdx] - jnz LeaveLoopCmps - - mov rax, [rsi + rdx + 8] - xor rax, [rdi + rdx + 8] - jnz LeaveLoopCmps8 - - - mov rax, [rsi + rdx + 8+8] - xor rax, [rdi + rdx + 8+8] - jnz LeaveLoopCmps16 - - add rdx,8+8+8 - - jnz short LoopCmps - jmp short LenMaximum -LeaveLoopCmps16: add rdx,8 -LeaveLoopCmps8: add rdx,8 -LeaveLoopCmps: - - test eax, 0000FFFFh - jnz LenLower - - test eax,0ffffffffh - - jnz LenLower32 - - add rdx,4 - shr rax,32 - or ax,ax - jnz LenLower - -LenLower32: - shr eax,16 - add rdx,2 -LenLower: sub al, 1 - adc rdx, 0 -;;; Calculate the length of the match. If it is longer than MAX_MATCH, -;;; then automatically accept it as the best possible match and leave. - - lea rax, [rdi + rdx] - sub rax, r9 - cmp eax, MAX_MATCH - jge LenMaximum - -;;; If the length of the match is not longer than the best match we -;;; have so far, then forget it and return to the lookup loop. -;/////////////////////////////////// - - cmp eax, r11d - jg LongerMatch - - lea rsi,[r10+r11] - - mov rdi, prev_ad - mov edx, [chainlenwmask] - jmp LookupLoop - -;;; s->match_start = cur_match; -;;; best_len = len; -;;; if (len >= nice_match) break; -;;; scan_end = *(ushf*)(scan+best_len-1); - -LongerMatch: - mov r11d, eax - mov match_start, r8d - cmp eax, [nicematch] - jge LeaveNow - - lea rsi,[r10+rax] - - movzx ebx, word ptr [r9 + rax - 1] - mov rdi, prev_ad - mov edx, [chainlenwmask] - jmp LookupLoop - -;;; Accept the current string, with the maximum possible length. - -LenMaximum: - mov r11d,MAX_MATCH - mov match_start, r8d - -;;; if ((uInt)best_len <= s->lookahead) return (uInt)best_len; -;;; return s->lookahead; - -LeaveNow: -IFDEF INFOZIP - mov eax,r11d -ELSE - mov eax, Lookahead - cmp r11d, eax - cmovng eax, r11d -ENDIF - -;;; Restore the stack and return from whence we came. - - - mov rsi,[save_rsi] - mov rdi,[save_rdi] - mov rbx,[save_rbx] - mov rbp,[save_rbp] - mov r12,[save_r12] - mov r13,[save_r13] -; mov r14,[save_r14] -; mov r15,[save_r15] - - - ret 0 -; please don't remove this string ! -; Your can freely use gvmat64 in any free or commercial app -; but it is far better don't remove the string in the binary! - db 0dh,0ah,"asm686 with masm, optimised assembly code from Brian Raiter, written 1998, converted to amd 64 by Gilles Vollant 2005",0dh,0ah,0 -longest_match ENDP - -match_init PROC - ret 0 -match_init ENDP - - -END diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/masmx64/inffas8664.c b/src/beast/test/zlib/zlib-1.2.8/contrib/masmx64/inffas8664.c deleted file mode 100644 index aa861a33392..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/masmx64/inffas8664.c +++ /dev/null @@ -1,186 +0,0 @@ -/* inffas8664.c is a hand tuned assembler version of inffast.c - fast decoding - * version for AMD64 on Windows using Microsoft C compiler - * - * Copyright (C) 1995-2003 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - * - * Copyright (C) 2003 Chris Anderson - * Please use the copyright conditions above. - * - * 2005 - Adaptation to Microsoft C Compiler for AMD64 by Gilles Vollant - * - * inffas8664.c call function inffas8664fnc in inffasx64.asm - * inffasx64.asm is automatically convert from AMD64 portion of inffas86.c - * - * Dec-29-2003 -- I added AMD64 inflate asm support. This version is also - * slightly quicker on x86 systems because, instead of using rep movsb to copy - * data, it uses rep movsw, which moves data in 2-byte chunks instead of single - * bytes. I've tested the AMD64 code on a Fedora Core 1 + the x86_64 updates - * from http://fedora.linux.duke.edu/fc1_x86_64 - * which is running on an Athlon 64 3000+ / Gigabyte GA-K8VT800M system with - * 1GB ram. The 64-bit version is about 4% faster than the 32-bit version, - * when decompressing mozilla-source-1.3.tar.gz. - * - * Mar-13-2003 -- Most of this is derived from inffast.S which is derived from - * the gcc -S output of zlib-1.2.0/inffast.c. Zlib-1.2.0 is in beta release at - * the moment. I have successfully compiled and tested this code with gcc2.96, - * gcc3.2, icc5.0, msvc6.0. It is very close to the speed of inffast.S - * compiled with gcc -DNO_MMX, but inffast.S is still faster on the P3 with MMX - * enabled. I will attempt to merge the MMX code into this version. Newer - * versions of this and inffast.S can be found at - * http://www.eetbeetee.com/zlib/ and http://www.charm.net/~christop/zlib/ - * - */ - -#include -#include "zutil.h" -#include "inftrees.h" -#include "inflate.h" -#include "inffast.h" - -/* Mark Adler's comments from inffast.c: */ - -/* - Decode literal, length, and distance codes and write out the resulting - literal and match bytes until either not enough input or output is - available, an end-of-block is encountered, or a data error is encountered. - When large enough input and output buffers are supplied to inflate(), for - example, a 16K input buffer and a 64K output buffer, more than 95% of the - inflate execution time is spent in this routine. - - Entry assumptions: - - state->mode == LEN - strm->avail_in >= 6 - strm->avail_out >= 258 - start >= strm->avail_out - state->bits < 8 - - On return, state->mode is one of: - - LEN -- ran out of enough output space or enough available input - TYPE -- reached end of block code, inflate() to interpret next block - BAD -- error in block data - - Notes: - - - The maximum input bits used by a length/distance pair is 15 bits for the - length code, 5 bits for the length extra, 15 bits for the distance code, - and 13 bits for the distance extra. This totals 48 bits, or six bytes. - Therefore if strm->avail_in >= 6, then there is enough input to avoid - checking for available input while decoding. - - - The maximum bytes that a single length/distance pair can output is 258 - bytes, which is the maximum length that can be coded. inflate_fast() - requires strm->avail_out >= 258 for each loop to avoid checking for - output space. - */ - - - - typedef struct inffast_ar { -/* 64 32 x86 x86_64 */ -/* ar offset register */ -/* 0 0 */ void *esp; /* esp save */ -/* 8 4 */ void *ebp; /* ebp save */ -/* 16 8 */ unsigned char FAR *in; /* esi rsi local strm->next_in */ -/* 24 12 */ unsigned char FAR *last; /* r9 while in < last */ -/* 32 16 */ unsigned char FAR *out; /* edi rdi local strm->next_out */ -/* 40 20 */ unsigned char FAR *beg; /* inflate()'s init next_out */ -/* 48 24 */ unsigned char FAR *end; /* r10 while out < end */ -/* 56 28 */ unsigned char FAR *window;/* size of window, wsize!=0 */ -/* 64 32 */ code const FAR *lcode; /* ebp rbp local strm->lencode */ -/* 72 36 */ code const FAR *dcode; /* r11 local strm->distcode */ -/* 80 40 */ size_t /*unsigned long */hold; /* edx rdx local strm->hold */ -/* 88 44 */ unsigned bits; /* ebx rbx local strm->bits */ -/* 92 48 */ unsigned wsize; /* window size */ -/* 96 52 */ unsigned write; /* window write index */ -/*100 56 */ unsigned lmask; /* r12 mask for lcode */ -/*104 60 */ unsigned dmask; /* r13 mask for dcode */ -/*108 64 */ unsigned len; /* r14 match length */ -/*112 68 */ unsigned dist; /* r15 match distance */ -/*116 72 */ unsigned status; /* set when state chng*/ - } type_ar; -#ifdef ASMINF - -void inflate_fast(strm, start) -z_streamp strm; -unsigned start; /* inflate()'s starting value for strm->avail_out */ -{ - struct inflate_state FAR *state; - type_ar ar; - void inffas8664fnc(struct inffast_ar * par); - - - -#if (defined( __GNUC__ ) && defined( __amd64__ ) && ! defined( __i386 )) || (defined(_MSC_VER) && defined(_M_AMD64)) -#define PAD_AVAIL_IN 6 -#define PAD_AVAIL_OUT 258 -#else -#define PAD_AVAIL_IN 5 -#define PAD_AVAIL_OUT 257 -#endif - - /* copy state to local variables */ - state = (struct inflate_state FAR *)strm->state; - - ar.in = strm->next_in; - ar.last = ar.in + (strm->avail_in - PAD_AVAIL_IN); - ar.out = strm->next_out; - ar.beg = ar.out - (start - strm->avail_out); - ar.end = ar.out + (strm->avail_out - PAD_AVAIL_OUT); - ar.wsize = state->wsize; - ar.write = state->wnext; - ar.window = state->window; - ar.hold = state->hold; - ar.bits = state->bits; - ar.lcode = state->lencode; - ar.dcode = state->distcode; - ar.lmask = (1U << state->lenbits) - 1; - ar.dmask = (1U << state->distbits) - 1; - - /* decode literals and length/distances until end-of-block or not enough - input data or output space */ - - /* align in on 1/2 hold size boundary */ - while (((size_t)(void *)ar.in & (sizeof(ar.hold) / 2 - 1)) != 0) { - ar.hold += (unsigned long)*ar.in++ << ar.bits; - ar.bits += 8; - } - - inffas8664fnc(&ar); - - if (ar.status > 1) { - if (ar.status == 2) - strm->msg = "invalid literal/length code"; - else if (ar.status == 3) - strm->msg = "invalid distance code"; - else - strm->msg = "invalid distance too far back"; - state->mode = BAD; - } - else if ( ar.status == 1 ) { - state->mode = TYPE; - } - - /* return unused bytes (on entry, bits < 8, so in won't go too far back) */ - ar.len = ar.bits >> 3; - ar.in -= ar.len; - ar.bits -= ar.len << 3; - ar.hold &= (1U << ar.bits) - 1; - - /* update state and return */ - strm->next_in = ar.in; - strm->next_out = ar.out; - strm->avail_in = (unsigned)(ar.in < ar.last ? - PAD_AVAIL_IN + (ar.last - ar.in) : - PAD_AVAIL_IN - (ar.in - ar.last)); - strm->avail_out = (unsigned)(ar.out < ar.end ? - PAD_AVAIL_OUT + (ar.end - ar.out) : - PAD_AVAIL_OUT - (ar.out - ar.end)); - state->hold = (unsigned long)ar.hold; - state->bits = ar.bits; - return; -} - -#endif diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/masmx64/inffasx64.asm b/src/beast/test/zlib/zlib-1.2.8/contrib/masmx64/inffasx64.asm deleted file mode 100644 index 41ec82392ed..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/masmx64/inffasx64.asm +++ /dev/null @@ -1,396 +0,0 @@ -; inffasx64.asm is a hand tuned assembler version of inffast.c - fast decoding -; version for AMD64 on Windows using Microsoft C compiler -; -; inffasx64.asm is automatically convert from AMD64 portion of inffas86.c -; inffasx64.asm is called by inffas8664.c, which contain more info. - - -; to compile this file, I use option -; ml64.exe /Flinffasx64 /c /Zi inffasx64.asm -; with Microsoft Macro Assembler (x64) for AMD64 -; - -; This file compile with Microsoft Macro Assembler (x64) for AMD64 -; -; ml64.exe is given with Visual Studio 2005/2008/2010 and Windows WDK -; -; (you can get Windows WDK with ml64 for AMD64 from -; http://www.microsoft.com/whdc/Devtools/wdk/default.mspx for low price) -; - - -.code -inffas8664fnc PROC - -; see http://weblogs.asp.net/oldnewthing/archive/2004/01/14/58579.aspx and -; http://msdn.microsoft.com/library/en-us/kmarch/hh/kmarch/64bitAMD_8e951dd2-ee77-4728-8702-55ce4b5dd24a.xml.asp -; -; All registers must be preserved across the call, except for -; rax, rcx, rdx, r8, r-9, r10, and r11, which are scratch. - - - mov [rsp-8],rsi - mov [rsp-16],rdi - mov [rsp-24],r12 - mov [rsp-32],r13 - mov [rsp-40],r14 - mov [rsp-48],r15 - mov [rsp-56],rbx - - mov rax,rcx - - mov [rax+8], rbp ; /* save regs rbp and rsp */ - mov [rax], rsp - - mov rsp, rax ; /* make rsp point to &ar */ - - mov rsi, [rsp+16] ; /* rsi = in */ - mov rdi, [rsp+32] ; /* rdi = out */ - mov r9, [rsp+24] ; /* r9 = last */ - mov r10, [rsp+48] ; /* r10 = end */ - mov rbp, [rsp+64] ; /* rbp = lcode */ - mov r11, [rsp+72] ; /* r11 = dcode */ - mov rdx, [rsp+80] ; /* rdx = hold */ - mov ebx, [rsp+88] ; /* ebx = bits */ - mov r12d, [rsp+100] ; /* r12d = lmask */ - mov r13d, [rsp+104] ; /* r13d = dmask */ - ; /* r14d = len */ - ; /* r15d = dist */ - - - cld - cmp r10, rdi - je L_one_time ; /* if only one decode left */ - cmp r9, rsi - - jne L_do_loop - - -L_one_time: - mov r8, r12 ; /* r8 = lmask */ - cmp bl, 32 - ja L_get_length_code_one_time - - lodsd ; /* eax = *(uint *)in++ */ - mov cl, bl ; /* cl = bits, needs it for shifting */ - add bl, 32 ; /* bits += 32 */ - shl rax, cl - or rdx, rax ; /* hold |= *((uint *)in)++ << bits */ - jmp L_get_length_code_one_time - -ALIGN 4 -L_while_test: - cmp r10, rdi - jbe L_break_loop - cmp r9, rsi - jbe L_break_loop - -L_do_loop: - mov r8, r12 ; /* r8 = lmask */ - cmp bl, 32 - ja L_get_length_code ; /* if (32 < bits) */ - - lodsd ; /* eax = *(uint *)in++ */ - mov cl, bl ; /* cl = bits, needs it for shifting */ - add bl, 32 ; /* bits += 32 */ - shl rax, cl - or rdx, rax ; /* hold |= *((uint *)in)++ << bits */ - -L_get_length_code: - and r8, rdx ; /* r8 &= hold */ - mov eax, [rbp+r8*4] ; /* eax = lcode[hold & lmask] */ - - mov cl, ah ; /* cl = this.bits */ - sub bl, ah ; /* bits -= this.bits */ - shr rdx, cl ; /* hold >>= this.bits */ - - test al, al - jnz L_test_for_length_base ; /* if (op != 0) 45.7% */ - - mov r8, r12 ; /* r8 = lmask */ - shr eax, 16 ; /* output this.val char */ - stosb - -L_get_length_code_one_time: - and r8, rdx ; /* r8 &= hold */ - mov eax, [rbp+r8*4] ; /* eax = lcode[hold & lmask] */ - -L_dolen: - mov cl, ah ; /* cl = this.bits */ - sub bl, ah ; /* bits -= this.bits */ - shr rdx, cl ; /* hold >>= this.bits */ - - test al, al - jnz L_test_for_length_base ; /* if (op != 0) 45.7% */ - - shr eax, 16 ; /* output this.val char */ - stosb - jmp L_while_test - -ALIGN 4 -L_test_for_length_base: - mov r14d, eax ; /* len = this */ - shr r14d, 16 ; /* len = this.val */ - mov cl, al - - test al, 16 - jz L_test_for_second_level_length ; /* if ((op & 16) == 0) 8% */ - and cl, 15 ; /* op &= 15 */ - jz L_decode_distance ; /* if (!op) */ - -L_add_bits_to_len: - sub bl, cl - xor eax, eax - inc eax - shl eax, cl - dec eax - and eax, edx ; /* eax &= hold */ - shr rdx, cl - add r14d, eax ; /* len += hold & mask[op] */ - -L_decode_distance: - mov r8, r13 ; /* r8 = dmask */ - cmp bl, 32 - ja L_get_distance_code ; /* if (32 < bits) */ - - lodsd ; /* eax = *(uint *)in++ */ - mov cl, bl ; /* cl = bits, needs it for shifting */ - add bl, 32 ; /* bits += 32 */ - shl rax, cl - or rdx, rax ; /* hold |= *((uint *)in)++ << bits */ - -L_get_distance_code: - and r8, rdx ; /* r8 &= hold */ - mov eax, [r11+r8*4] ; /* eax = dcode[hold & dmask] */ - -L_dodist: - mov r15d, eax ; /* dist = this */ - shr r15d, 16 ; /* dist = this.val */ - mov cl, ah - sub bl, ah ; /* bits -= this.bits */ - shr rdx, cl ; /* hold >>= this.bits */ - mov cl, al ; /* cl = this.op */ - - test al, 16 ; /* if ((op & 16) == 0) */ - jz L_test_for_second_level_dist - and cl, 15 ; /* op &= 15 */ - jz L_check_dist_one - -L_add_bits_to_dist: - sub bl, cl - xor eax, eax - inc eax - shl eax, cl - dec eax ; /* (1 << op) - 1 */ - and eax, edx ; /* eax &= hold */ - shr rdx, cl - add r15d, eax ; /* dist += hold & ((1 << op) - 1) */ - -L_check_window: - mov r8, rsi ; /* save in so from can use it's reg */ - mov rax, rdi - sub rax, [rsp+40] ; /* nbytes = out - beg */ - - cmp eax, r15d - jb L_clip_window ; /* if (dist > nbytes) 4.2% */ - - mov ecx, r14d ; /* ecx = len */ - mov rsi, rdi - sub rsi, r15 ; /* from = out - dist */ - - sar ecx, 1 - jnc L_copy_two ; /* if len % 2 == 0 */ - - rep movsw - mov al, [rsi] - mov [rdi], al - inc rdi - - mov rsi, r8 ; /* move in back to %rsi, toss from */ - jmp L_while_test - -L_copy_two: - rep movsw - mov rsi, r8 ; /* move in back to %rsi, toss from */ - jmp L_while_test - -ALIGN 4 -L_check_dist_one: - cmp r15d, 1 ; /* if dist 1, is a memset */ - jne L_check_window - cmp [rsp+40], rdi ; /* if out == beg, outside window */ - je L_check_window - - mov ecx, r14d ; /* ecx = len */ - mov al, [rdi-1] - mov ah, al - - sar ecx, 1 - jnc L_set_two - mov [rdi], al - inc rdi - -L_set_two: - rep stosw - jmp L_while_test - -ALIGN 4 -L_test_for_second_level_length: - test al, 64 - jnz L_test_for_end_of_block ; /* if ((op & 64) != 0) */ - - xor eax, eax - inc eax - shl eax, cl - dec eax - and eax, edx ; /* eax &= hold */ - add eax, r14d ; /* eax += len */ - mov eax, [rbp+rax*4] ; /* eax = lcode[val+(hold&mask[op])]*/ - jmp L_dolen - -ALIGN 4 -L_test_for_second_level_dist: - test al, 64 - jnz L_invalid_distance_code ; /* if ((op & 64) != 0) */ - - xor eax, eax - inc eax - shl eax, cl - dec eax - and eax, edx ; /* eax &= hold */ - add eax, r15d ; /* eax += dist */ - mov eax, [r11+rax*4] ; /* eax = dcode[val+(hold&mask[op])]*/ - jmp L_dodist - -ALIGN 4 -L_clip_window: - mov ecx, eax ; /* ecx = nbytes */ - mov eax, [rsp+92] ; /* eax = wsize, prepare for dist cmp */ - neg ecx ; /* nbytes = -nbytes */ - - cmp eax, r15d - jb L_invalid_distance_too_far ; /* if (dist > wsize) */ - - add ecx, r15d ; /* nbytes = dist - nbytes */ - cmp dword ptr [rsp+96], 0 - jne L_wrap_around_window ; /* if (write != 0) */ - - mov rsi, [rsp+56] ; /* from = window */ - sub eax, ecx ; /* eax -= nbytes */ - add rsi, rax ; /* from += wsize - nbytes */ - - mov eax, r14d ; /* eax = len */ - cmp r14d, ecx - jbe L_do_copy ; /* if (nbytes >= len) */ - - sub eax, ecx ; /* eax -= nbytes */ - rep movsb - mov rsi, rdi - sub rsi, r15 ; /* from = &out[ -dist ] */ - jmp L_do_copy - -ALIGN 4 -L_wrap_around_window: - mov eax, [rsp+96] ; /* eax = write */ - cmp ecx, eax - jbe L_contiguous_in_window ; /* if (write >= nbytes) */ - - mov esi, [rsp+92] ; /* from = wsize */ - add rsi, [rsp+56] ; /* from += window */ - add rsi, rax ; /* from += write */ - sub rsi, rcx ; /* from -= nbytes */ - sub ecx, eax ; /* nbytes -= write */ - - mov eax, r14d ; /* eax = len */ - cmp eax, ecx - jbe L_do_copy ; /* if (nbytes >= len) */ - - sub eax, ecx ; /* len -= nbytes */ - rep movsb - mov rsi, [rsp+56] ; /* from = window */ - mov ecx, [rsp+96] ; /* nbytes = write */ - cmp eax, ecx - jbe L_do_copy ; /* if (nbytes >= len) */ - - sub eax, ecx ; /* len -= nbytes */ - rep movsb - mov rsi, rdi - sub rsi, r15 ; /* from = out - dist */ - jmp L_do_copy - -ALIGN 4 -L_contiguous_in_window: - mov rsi, [rsp+56] ; /* rsi = window */ - add rsi, rax - sub rsi, rcx ; /* from += write - nbytes */ - - mov eax, r14d ; /* eax = len */ - cmp eax, ecx - jbe L_do_copy ; /* if (nbytes >= len) */ - - sub eax, ecx ; /* len -= nbytes */ - rep movsb - mov rsi, rdi - sub rsi, r15 ; /* from = out - dist */ - jmp L_do_copy ; /* if (nbytes >= len) */ - -ALIGN 4 -L_do_copy: - mov ecx, eax ; /* ecx = len */ - rep movsb - - mov rsi, r8 ; /* move in back to %esi, toss from */ - jmp L_while_test - -L_test_for_end_of_block: - test al, 32 - jz L_invalid_literal_length_code - mov dword ptr [rsp+116], 1 - jmp L_break_loop_with_status - -L_invalid_literal_length_code: - mov dword ptr [rsp+116], 2 - jmp L_break_loop_with_status - -L_invalid_distance_code: - mov dword ptr [rsp+116], 3 - jmp L_break_loop_with_status - -L_invalid_distance_too_far: - mov dword ptr [rsp+116], 4 - jmp L_break_loop_with_status - -L_break_loop: - mov dword ptr [rsp+116], 0 - -L_break_loop_with_status: -; /* put in, out, bits, and hold back into ar and pop esp */ - mov [rsp+16], rsi ; /* in */ - mov [rsp+32], rdi ; /* out */ - mov [rsp+88], ebx ; /* bits */ - mov [rsp+80], rdx ; /* hold */ - - mov rax, [rsp] ; /* restore rbp and rsp */ - mov rbp, [rsp+8] - mov rsp, rax - - - - mov rsi,[rsp-8] - mov rdi,[rsp-16] - mov r12,[rsp-24] - mov r13,[rsp-32] - mov r14,[rsp-40] - mov r15,[rsp-48] - mov rbx,[rsp-56] - - ret 0 -; : -; : "m" (ar) -; : "memory", "%rax", "%rbx", "%rcx", "%rdx", "%rsi", "%rdi", -; "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15" -; ); - -inffas8664fnc ENDP -;_TEXT ENDS -END diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/masmx64/readme.txt b/src/beast/test/zlib/zlib-1.2.8/contrib/masmx64/readme.txt deleted file mode 100644 index 652571c7a52..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/masmx64/readme.txt +++ /dev/null @@ -1,31 +0,0 @@ -Summary -------- -This directory contains ASM implementations of the functions -longest_match() and inflate_fast(), for 64 bits x86 (both AMD64 and Intel EM64t), -for use with Microsoft Macro Assembler (x64) for AMD64 and Microsoft C++ 64 bits. - -gvmat64.asm is written by Gilles Vollant (2005), by using Brian Raiter 686/32 bits - assembly optimized version from Jean-loup Gailly original longest_match function - -inffasx64.asm and inffas8664.c were written by Chris Anderson, by optimizing - original function from Mark Adler - -Use instructions ----------------- -Assemble the .asm files using MASM and put the object files into the zlib source -directory. You can also get object files here: - - http://www.winimage.com/zLibDll/zlib124_masm_obj.zip - -define ASMV and ASMINF in your project. Include inffas8664.c in your source tree, -and inffasx64.obj and gvmat64.obj as object to link. - - -Build instructions ------------------- -run bld_64.bat with Microsoft Macro Assembler (x64) for AMD64 (ml64.exe) - -ml64.exe is given with Visual Studio 2005, Windows 2003 server DDK - -You can get Windows 2003 server DDK with ml64 and cl for AMD64 from - http://www.microsoft.com/whdc/devtools/ddk/default.mspx for low price) diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/masmx86/bld_ml32.bat b/src/beast/test/zlib/zlib-1.2.8/contrib/masmx86/bld_ml32.bat deleted file mode 100644 index fcf5755e46a..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/masmx86/bld_ml32.bat +++ /dev/null @@ -1,2 +0,0 @@ -ml /coff /Zi /c /Flmatch686.lst match686.asm -ml /coff /Zi /c /Flinffas32.lst inffas32.asm diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/masmx86/inffas32.asm b/src/beast/test/zlib/zlib-1.2.8/contrib/masmx86/inffas32.asm deleted file mode 100644 index cb37a81e4ee..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/masmx86/inffas32.asm +++ /dev/null @@ -1,1080 +0,0 @@ -;/* inffas32.asm is a hand tuned assembler version of inffast.c -- fast decoding -; * -; * inffas32.asm is derivated from inffas86.c, with translation of assembly code -; * -; * Copyright (C) 1995-2003 Mark Adler -; * For conditions of distribution and use, see copyright notice in zlib.h -; * -; * Copyright (C) 2003 Chris Anderson -; * Please use the copyright conditions above. -; * -; * Mar-13-2003 -- Most of this is derived from inffast.S which is derived from -; * the gcc -S output of zlib-1.2.0/inffast.c. Zlib-1.2.0 is in beta release at -; * the moment. I have successfully compiled and tested this code with gcc2.96, -; * gcc3.2, icc5.0, msvc6.0. It is very close to the speed of inffast.S -; * compiled with gcc -DNO_MMX, but inffast.S is still faster on the P3 with MMX -; * enabled. I will attempt to merge the MMX code into this version. Newer -; * versions of this and inffast.S can be found at -; * http://www.eetbeetee.com/zlib/ and http://www.charm.net/~christop/zlib/ -; * -; * 2005 : modification by Gilles Vollant -; */ -; For Visual C++ 4.x and higher and ML 6.x and higher -; ml.exe is in directory \MASM611C of Win95 DDK -; ml.exe is also distributed in http://www.masm32.com/masmdl.htm -; and in VC++2003 toolkit at http://msdn.microsoft.com/visualc/vctoolkit2003/ -; -; -; compile with command line option -; ml /coff /Zi /c /Flinffas32.lst inffas32.asm - -; if you define NO_GZIP (see inflate.h), compile with -; ml /coff /Zi /c /Flinffas32.lst /DNO_GUNZIP inffas32.asm - - -; zlib122sup is 0 fort zlib 1.2.2.1 and lower -; zlib122sup is 8 fort zlib 1.2.2.2 and more (with addition of dmax and head -; in inflate_state in inflate.h) -zlib1222sup equ 8 - - -IFDEF GUNZIP - INFLATE_MODE_TYPE equ 11 - INFLATE_MODE_BAD equ 26 -ELSE - IFNDEF NO_GUNZIP - INFLATE_MODE_TYPE equ 11 - INFLATE_MODE_BAD equ 26 - ELSE - INFLATE_MODE_TYPE equ 3 - INFLATE_MODE_BAD equ 17 - ENDIF -ENDIF - - -; 75 "inffast.S" -;FILE "inffast.S" - -;;;GLOBAL _inflate_fast - -;;;SECTION .text - - - - .586p - .mmx - - name inflate_fast_x86 - .MODEL FLAT - -_DATA segment -inflate_fast_use_mmx: - dd 1 - - -_TEXT segment - - - -ALIGN 4 - db 'Fast decoding Code from Chris Anderson' - db 0 - -ALIGN 4 -invalid_literal_length_code_msg: - db 'invalid literal/length code' - db 0 - -ALIGN 4 -invalid_distance_code_msg: - db 'invalid distance code' - db 0 - -ALIGN 4 -invalid_distance_too_far_msg: - db 'invalid distance too far back' - db 0 - - -ALIGN 4 -inflate_fast_mask: -dd 0 -dd 1 -dd 3 -dd 7 -dd 15 -dd 31 -dd 63 -dd 127 -dd 255 -dd 511 -dd 1023 -dd 2047 -dd 4095 -dd 8191 -dd 16383 -dd 32767 -dd 65535 -dd 131071 -dd 262143 -dd 524287 -dd 1048575 -dd 2097151 -dd 4194303 -dd 8388607 -dd 16777215 -dd 33554431 -dd 67108863 -dd 134217727 -dd 268435455 -dd 536870911 -dd 1073741823 -dd 2147483647 -dd 4294967295 - - -mode_state equ 0 ;/* state->mode */ -wsize_state equ (32+zlib1222sup) ;/* state->wsize */ -write_state equ (36+4+zlib1222sup) ;/* state->write */ -window_state equ (40+4+zlib1222sup) ;/* state->window */ -hold_state equ (44+4+zlib1222sup) ;/* state->hold */ -bits_state equ (48+4+zlib1222sup) ;/* state->bits */ -lencode_state equ (64+4+zlib1222sup) ;/* state->lencode */ -distcode_state equ (68+4+zlib1222sup) ;/* state->distcode */ -lenbits_state equ (72+4+zlib1222sup) ;/* state->lenbits */ -distbits_state equ (76+4+zlib1222sup) ;/* state->distbits */ - - -;;SECTION .text -; 205 "inffast.S" -;GLOBAL inflate_fast_use_mmx - -;SECTION .data - - -; GLOBAL inflate_fast_use_mmx:object -;.size inflate_fast_use_mmx, 4 -; 226 "inffast.S" -;SECTION .text - -ALIGN 4 -_inflate_fast proc near -.FPO (16, 4, 0, 0, 1, 0) - push edi - push esi - push ebp - push ebx - pushfd - sub esp,64 - cld - - - - - mov esi, [esp+88] - mov edi, [esi+28] - - - - - - - - mov edx, [esi+4] - mov eax, [esi+0] - - add edx,eax - sub edx,11 - - mov [esp+44],eax - mov [esp+20],edx - - mov ebp, [esp+92] - mov ecx, [esi+16] - mov ebx, [esi+12] - - sub ebp,ecx - neg ebp - add ebp,ebx - - sub ecx,257 - add ecx,ebx - - mov [esp+60],ebx - mov [esp+40],ebp - mov [esp+16],ecx -; 285 "inffast.S" - mov eax, [edi+lencode_state] - mov ecx, [edi+distcode_state] - - mov [esp+8],eax - mov [esp+12],ecx - - mov eax,1 - mov ecx, [edi+lenbits_state] - shl eax,cl - dec eax - mov [esp+0],eax - - mov eax,1 - mov ecx, [edi+distbits_state] - shl eax,cl - dec eax - mov [esp+4],eax - - mov eax, [edi+wsize_state] - mov ecx, [edi+write_state] - mov edx, [edi+window_state] - - mov [esp+52],eax - mov [esp+48],ecx - mov [esp+56],edx - - mov ebp, [edi+hold_state] - mov ebx, [edi+bits_state] -; 321 "inffast.S" - mov esi, [esp+44] - mov ecx, [esp+20] - cmp ecx,esi - ja L_align_long - - add ecx,11 - sub ecx,esi - mov eax,12 - sub eax,ecx - lea edi, [esp+28] - rep movsb - mov ecx,eax - xor eax,eax - rep stosb - lea esi, [esp+28] - mov [esp+20],esi - jmp L_is_aligned - - -L_align_long: - test esi,3 - jz L_is_aligned - xor eax,eax - mov al, [esi] - inc esi - mov ecx,ebx - add ebx,8 - shl eax,cl - or ebp,eax - jmp L_align_long - -L_is_aligned: - mov edi, [esp+60] -; 366 "inffast.S" -L_check_mmx: - cmp dword ptr [inflate_fast_use_mmx],2 - je L_init_mmx - ja L_do_loop - - push eax - push ebx - push ecx - push edx - pushfd - mov eax, [esp] - xor dword ptr [esp],0200000h - - - - - popfd - pushfd - pop edx - xor edx,eax - jz L_dont_use_mmx - xor eax,eax - cpuid - cmp ebx,0756e6547h - jne L_dont_use_mmx - cmp ecx,06c65746eh - jne L_dont_use_mmx - cmp edx,049656e69h - jne L_dont_use_mmx - mov eax,1 - cpuid - shr eax,8 - and eax,15 - cmp eax,6 - jne L_dont_use_mmx - test edx,0800000h - jnz L_use_mmx - jmp L_dont_use_mmx -L_use_mmx: - mov dword ptr [inflate_fast_use_mmx],2 - jmp L_check_mmx_pop -L_dont_use_mmx: - mov dword ptr [inflate_fast_use_mmx],3 -L_check_mmx_pop: - pop edx - pop ecx - pop ebx - pop eax - jmp L_check_mmx -; 426 "inffast.S" -ALIGN 4 -L_do_loop: -; 437 "inffast.S" - cmp bl,15 - ja L_get_length_code - - xor eax,eax - lodsw - mov cl,bl - add bl,16 - shl eax,cl - or ebp,eax - -L_get_length_code: - mov edx, [esp+0] - mov ecx, [esp+8] - and edx,ebp - mov eax, [ecx+edx*4] - -L_dolen: - - - - - - - mov cl,ah - sub bl,ah - shr ebp,cl - - - - - - - test al,al - jnz L_test_for_length_base - - shr eax,16 - stosb - -L_while_test: - - - cmp [esp+16],edi - jbe L_break_loop - - cmp [esp+20],esi - ja L_do_loop - jmp L_break_loop - -L_test_for_length_base: -; 502 "inffast.S" - mov edx,eax - shr edx,16 - mov cl,al - - test al,16 - jz L_test_for_second_level_length - and cl,15 - jz L_save_len - cmp bl,cl - jae L_add_bits_to_len - - mov ch,cl - xor eax,eax - lodsw - mov cl,bl - add bl,16 - shl eax,cl - or ebp,eax - mov cl,ch - -L_add_bits_to_len: - mov eax,1 - shl eax,cl - dec eax - sub bl,cl - and eax,ebp - shr ebp,cl - add edx,eax - -L_save_len: - mov [esp+24],edx - - -L_decode_distance: -; 549 "inffast.S" - cmp bl,15 - ja L_get_distance_code - - xor eax,eax - lodsw - mov cl,bl - add bl,16 - shl eax,cl - or ebp,eax - -L_get_distance_code: - mov edx, [esp+4] - mov ecx, [esp+12] - and edx,ebp - mov eax, [ecx+edx*4] - - -L_dodist: - mov edx,eax - shr edx,16 - mov cl,ah - sub bl,ah - shr ebp,cl -; 584 "inffast.S" - mov cl,al - - test al,16 - jz L_test_for_second_level_dist - and cl,15 - jz L_check_dist_one - cmp bl,cl - jae L_add_bits_to_dist - - mov ch,cl - xor eax,eax - lodsw - mov cl,bl - add bl,16 - shl eax,cl - or ebp,eax - mov cl,ch - -L_add_bits_to_dist: - mov eax,1 - shl eax,cl - dec eax - sub bl,cl - and eax,ebp - shr ebp,cl - add edx,eax - jmp L_check_window - -L_check_window: -; 625 "inffast.S" - mov [esp+44],esi - mov eax,edi - sub eax, [esp+40] - - cmp eax,edx - jb L_clip_window - - mov ecx, [esp+24] - mov esi,edi - sub esi,edx - - sub ecx,3 - mov al, [esi] - mov [edi],al - mov al, [esi+1] - mov dl, [esi+2] - add esi,3 - mov [edi+1],al - mov [edi+2],dl - add edi,3 - rep movsb - - mov esi, [esp+44] - jmp L_while_test - -ALIGN 4 -L_check_dist_one: - cmp edx,1 - jne L_check_window - cmp [esp+40],edi - je L_check_window - - dec edi - mov ecx, [esp+24] - mov al, [edi] - sub ecx,3 - - mov [edi+1],al - mov [edi+2],al - mov [edi+3],al - add edi,4 - rep stosb - - jmp L_while_test - -ALIGN 4 -L_test_for_second_level_length: - - - - - test al,64 - jnz L_test_for_end_of_block - - mov eax,1 - shl eax,cl - dec eax - and eax,ebp - add eax,edx - mov edx, [esp+8] - mov eax, [edx+eax*4] - jmp L_dolen - -ALIGN 4 -L_test_for_second_level_dist: - - - - - test al,64 - jnz L_invalid_distance_code - - mov eax,1 - shl eax,cl - dec eax - and eax,ebp - add eax,edx - mov edx, [esp+12] - mov eax, [edx+eax*4] - jmp L_dodist - -ALIGN 4 -L_clip_window: -; 721 "inffast.S" - mov ecx,eax - mov eax, [esp+52] - neg ecx - mov esi, [esp+56] - - cmp eax,edx - jb L_invalid_distance_too_far - - add ecx,edx - cmp dword ptr [esp+48],0 - jne L_wrap_around_window - - sub eax,ecx - add esi,eax -; 749 "inffast.S" - mov eax, [esp+24] - cmp eax,ecx - jbe L_do_copy1 - - sub eax,ecx - rep movsb - mov esi,edi - sub esi,edx - jmp L_do_copy1 - - cmp eax,ecx - jbe L_do_copy1 - - sub eax,ecx - rep movsb - mov esi,edi - sub esi,edx - jmp L_do_copy1 - -L_wrap_around_window: -; 793 "inffast.S" - mov eax, [esp+48] - cmp ecx,eax - jbe L_contiguous_in_window - - add esi, [esp+52] - add esi,eax - sub esi,ecx - sub ecx,eax - - - mov eax, [esp+24] - cmp eax,ecx - jbe L_do_copy1 - - sub eax,ecx - rep movsb - mov esi, [esp+56] - mov ecx, [esp+48] - cmp eax,ecx - jbe L_do_copy1 - - sub eax,ecx - rep movsb - mov esi,edi - sub esi,edx - jmp L_do_copy1 - -L_contiguous_in_window: -; 836 "inffast.S" - add esi,eax - sub esi,ecx - - - mov eax, [esp+24] - cmp eax,ecx - jbe L_do_copy1 - - sub eax,ecx - rep movsb - mov esi,edi - sub esi,edx - -L_do_copy1: -; 862 "inffast.S" - mov ecx,eax - rep movsb - - mov esi, [esp+44] - jmp L_while_test -; 878 "inffast.S" -ALIGN 4 -L_init_mmx: - emms - - - - - - movd mm0,ebp - mov ebp,ebx -; 896 "inffast.S" - movd mm4,dword ptr [esp+0] - movq mm3,mm4 - movd mm5,dword ptr [esp+4] - movq mm2,mm5 - pxor mm1,mm1 - mov ebx, [esp+8] - jmp L_do_loop_mmx - -ALIGN 4 -L_do_loop_mmx: - psrlq mm0,mm1 - - cmp ebp,32 - ja L_get_length_code_mmx - - movd mm6,ebp - movd mm7,dword ptr [esi] - add esi,4 - psllq mm7,mm6 - add ebp,32 - por mm0,mm7 - -L_get_length_code_mmx: - pand mm4,mm0 - movd eax,mm4 - movq mm4,mm3 - mov eax, [ebx+eax*4] - -L_dolen_mmx: - movzx ecx,ah - movd mm1,ecx - sub ebp,ecx - - test al,al - jnz L_test_for_length_base_mmx - - shr eax,16 - stosb - -L_while_test_mmx: - - - cmp [esp+16],edi - jbe L_break_loop - - cmp [esp+20],esi - ja L_do_loop_mmx - jmp L_break_loop - -L_test_for_length_base_mmx: - - mov edx,eax - shr edx,16 - - test al,16 - jz L_test_for_second_level_length_mmx - and eax,15 - jz L_decode_distance_mmx - - psrlq mm0,mm1 - movd mm1,eax - movd ecx,mm0 - sub ebp,eax - and ecx, [inflate_fast_mask+eax*4] - add edx,ecx - -L_decode_distance_mmx: - psrlq mm0,mm1 - - cmp ebp,32 - ja L_get_dist_code_mmx - - movd mm6,ebp - movd mm7,dword ptr [esi] - add esi,4 - psllq mm7,mm6 - add ebp,32 - por mm0,mm7 - -L_get_dist_code_mmx: - mov ebx, [esp+12] - pand mm5,mm0 - movd eax,mm5 - movq mm5,mm2 - mov eax, [ebx+eax*4] - -L_dodist_mmx: - - movzx ecx,ah - mov ebx,eax - shr ebx,16 - sub ebp,ecx - movd mm1,ecx - - test al,16 - jz L_test_for_second_level_dist_mmx - and eax,15 - jz L_check_dist_one_mmx - -L_add_bits_to_dist_mmx: - psrlq mm0,mm1 - movd mm1,eax - movd ecx,mm0 - sub ebp,eax - and ecx, [inflate_fast_mask+eax*4] - add ebx,ecx - -L_check_window_mmx: - mov [esp+44],esi - mov eax,edi - sub eax, [esp+40] - - cmp eax,ebx - jb L_clip_window_mmx - - mov ecx,edx - mov esi,edi - sub esi,ebx - - sub ecx,3 - mov al, [esi] - mov [edi],al - mov al, [esi+1] - mov dl, [esi+2] - add esi,3 - mov [edi+1],al - mov [edi+2],dl - add edi,3 - rep movsb - - mov esi, [esp+44] - mov ebx, [esp+8] - jmp L_while_test_mmx - -ALIGN 4 -L_check_dist_one_mmx: - cmp ebx,1 - jne L_check_window_mmx - cmp [esp+40],edi - je L_check_window_mmx - - dec edi - mov ecx,edx - mov al, [edi] - sub ecx,3 - - mov [edi+1],al - mov [edi+2],al - mov [edi+3],al - add edi,4 - rep stosb - - mov ebx, [esp+8] - jmp L_while_test_mmx - -ALIGN 4 -L_test_for_second_level_length_mmx: - test al,64 - jnz L_test_for_end_of_block - - and eax,15 - psrlq mm0,mm1 - movd ecx,mm0 - and ecx, [inflate_fast_mask+eax*4] - add ecx,edx - mov eax, [ebx+ecx*4] - jmp L_dolen_mmx - -ALIGN 4 -L_test_for_second_level_dist_mmx: - test al,64 - jnz L_invalid_distance_code - - and eax,15 - psrlq mm0,mm1 - movd ecx,mm0 - and ecx, [inflate_fast_mask+eax*4] - mov eax, [esp+12] - add ecx,ebx - mov eax, [eax+ecx*4] - jmp L_dodist_mmx - -ALIGN 4 -L_clip_window_mmx: - - mov ecx,eax - mov eax, [esp+52] - neg ecx - mov esi, [esp+56] - - cmp eax,ebx - jb L_invalid_distance_too_far - - add ecx,ebx - cmp dword ptr [esp+48],0 - jne L_wrap_around_window_mmx - - sub eax,ecx - add esi,eax - - cmp edx,ecx - jbe L_do_copy1_mmx - - sub edx,ecx - rep movsb - mov esi,edi - sub esi,ebx - jmp L_do_copy1_mmx - - cmp edx,ecx - jbe L_do_copy1_mmx - - sub edx,ecx - rep movsb - mov esi,edi - sub esi,ebx - jmp L_do_copy1_mmx - -L_wrap_around_window_mmx: - - mov eax, [esp+48] - cmp ecx,eax - jbe L_contiguous_in_window_mmx - - add esi, [esp+52] - add esi,eax - sub esi,ecx - sub ecx,eax - - - cmp edx,ecx - jbe L_do_copy1_mmx - - sub edx,ecx - rep movsb - mov esi, [esp+56] - mov ecx, [esp+48] - cmp edx,ecx - jbe L_do_copy1_mmx - - sub edx,ecx - rep movsb - mov esi,edi - sub esi,ebx - jmp L_do_copy1_mmx - -L_contiguous_in_window_mmx: - - add esi,eax - sub esi,ecx - - - cmp edx,ecx - jbe L_do_copy1_mmx - - sub edx,ecx - rep movsb - mov esi,edi - sub esi,ebx - -L_do_copy1_mmx: - - - mov ecx,edx - rep movsb - - mov esi, [esp+44] - mov ebx, [esp+8] - jmp L_while_test_mmx -; 1174 "inffast.S" -L_invalid_distance_code: - - - - - - mov ecx, invalid_distance_code_msg - mov edx,INFLATE_MODE_BAD - jmp L_update_stream_state - -L_test_for_end_of_block: - - - - - - test al,32 - jz L_invalid_literal_length_code - - mov ecx,0 - mov edx,INFLATE_MODE_TYPE - jmp L_update_stream_state - -L_invalid_literal_length_code: - - - - - - mov ecx, invalid_literal_length_code_msg - mov edx,INFLATE_MODE_BAD - jmp L_update_stream_state - -L_invalid_distance_too_far: - - - - mov esi, [esp+44] - mov ecx, invalid_distance_too_far_msg - mov edx,INFLATE_MODE_BAD - jmp L_update_stream_state - -L_update_stream_state: - - mov eax, [esp+88] - test ecx,ecx - jz L_skip_msg - mov [eax+24],ecx -L_skip_msg: - mov eax, [eax+28] - mov [eax+mode_state],edx - jmp L_break_loop - -ALIGN 4 -L_break_loop: -; 1243 "inffast.S" - cmp dword ptr [inflate_fast_use_mmx],2 - jne L_update_next_in - - - - mov ebx,ebp - -L_update_next_in: -; 1266 "inffast.S" - mov eax, [esp+88] - mov ecx,ebx - mov edx, [eax+28] - shr ecx,3 - sub esi,ecx - shl ecx,3 - sub ebx,ecx - mov [eax+12],edi - mov [edx+bits_state],ebx - mov ecx,ebx - - lea ebx, [esp+28] - cmp [esp+20],ebx - jne L_buf_not_used - - sub esi,ebx - mov ebx, [eax+0] - mov [esp+20],ebx - add esi,ebx - mov ebx, [eax+4] - sub ebx,11 - add [esp+20],ebx - -L_buf_not_used: - mov [eax+0],esi - - mov ebx,1 - shl ebx,cl - dec ebx - - - - - - cmp dword ptr [inflate_fast_use_mmx],2 - jne L_update_hold - - - - psrlq mm0,mm1 - movd ebp,mm0 - - emms - -L_update_hold: - - - - and ebp,ebx - mov [edx+hold_state],ebp - - - - - mov ebx, [esp+20] - cmp ebx,esi - jbe L_last_is_smaller - - sub ebx,esi - add ebx,11 - mov [eax+4],ebx - jmp L_fixup_out -L_last_is_smaller: - sub esi,ebx - neg esi - add esi,11 - mov [eax+4],esi - - - - -L_fixup_out: - - mov ebx, [esp+16] - cmp ebx,edi - jbe L_end_is_smaller - - sub ebx,edi - add ebx,257 - mov [eax+16],ebx - jmp L_done -L_end_is_smaller: - sub edi,ebx - neg edi - add edi,257 - mov [eax+16],edi - - - - - -L_done: - add esp,64 - popfd - pop ebx - pop ebp - pop esi - pop edi - ret -_inflate_fast endp - -_TEXT ends -end diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/masmx86/match686.asm b/src/beast/test/zlib/zlib-1.2.8/contrib/masmx86/match686.asm deleted file mode 100644 index 69e0eed01de..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/masmx86/match686.asm +++ /dev/null @@ -1,479 +0,0 @@ -; match686.asm -- Asm portion of the optimized longest_match for 32 bits x86 -; Copyright (C) 1995-1996 Jean-loup Gailly, Brian Raiter and Gilles Vollant. -; File written by Gilles Vollant, by converting match686.S from Brian Raiter -; for MASM. This is as assembly version of longest_match -; from Jean-loup Gailly in deflate.c -; -; http://www.zlib.net -; http://www.winimage.com/zLibDll -; http://www.muppetlabs.com/~breadbox/software/assembly.html -; -; For Visual C++ 4.x and higher and ML 6.x and higher -; ml.exe is distributed in -; http://www.microsoft.com/downloads/details.aspx?FamilyID=7a1c9da0-0510-44a2-b042-7ef370530c64 -; -; this file contain two implementation of longest_match -; -; this longest_match was written by Brian raiter (1998), optimized for Pentium Pro -; (and the faster known version of match_init on modern Core 2 Duo and AMD Phenom) -; -; for using an assembly version of longest_match, you need define ASMV in project -; -; compile the asm file running -; ml /coff /Zi /c /Flmatch686.lst match686.asm -; and do not include match686.obj in your project -; -; note: contrib of zLib 1.2.3 and earlier contained both a deprecated version for -; Pentium (prior Pentium Pro) and this version for Pentium Pro and modern processor -; with autoselect (with cpu detection code) -; if you want support the old pentium optimization, you can still use these version -; -; this file is not optimized for old pentium, but it compatible with all x86 32 bits -; processor (starting 80386) -; -; -; see below : zlib1222add must be adjuster if you use a zlib version < 1.2.2.2 - -;uInt longest_match(s, cur_match) -; deflate_state *s; -; IPos cur_match; /* current match */ - - NbStack equ 76 - cur_match equ dword ptr[esp+NbStack-0] - str_s equ dword ptr[esp+NbStack-4] -; 5 dword on top (ret,ebp,esi,edi,ebx) - adrret equ dword ptr[esp+NbStack-8] - pushebp equ dword ptr[esp+NbStack-12] - pushedi equ dword ptr[esp+NbStack-16] - pushesi equ dword ptr[esp+NbStack-20] - pushebx equ dword ptr[esp+NbStack-24] - - chain_length equ dword ptr [esp+NbStack-28] - limit equ dword ptr [esp+NbStack-32] - best_len equ dword ptr [esp+NbStack-36] - window equ dword ptr [esp+NbStack-40] - prev equ dword ptr [esp+NbStack-44] - scan_start equ word ptr [esp+NbStack-48] - wmask equ dword ptr [esp+NbStack-52] - match_start_ptr equ dword ptr [esp+NbStack-56] - nice_match equ dword ptr [esp+NbStack-60] - scan equ dword ptr [esp+NbStack-64] - - windowlen equ dword ptr [esp+NbStack-68] - match_start equ dword ptr [esp+NbStack-72] - strend equ dword ptr [esp+NbStack-76] - NbStackAdd equ (NbStack-24) - - .386p - - name gvmatch - .MODEL FLAT - - - -; all the +zlib1222add offsets are due to the addition of fields -; in zlib in the deflate_state structure since the asm code was first written -; (if you compile with zlib 1.0.4 or older, use "zlib1222add equ (-4)"). -; (if you compile with zlib between 1.0.5 and 1.2.2.1, use "zlib1222add equ 0"). -; if you compile with zlib 1.2.2.2 or later , use "zlib1222add equ 8"). - - zlib1222add equ 8 - -; Note : these value are good with a 8 bytes boundary pack structure - dep_chain_length equ 74h+zlib1222add - dep_window equ 30h+zlib1222add - dep_strstart equ 64h+zlib1222add - dep_prev_length equ 70h+zlib1222add - dep_nice_match equ 88h+zlib1222add - dep_w_size equ 24h+zlib1222add - dep_prev equ 38h+zlib1222add - dep_w_mask equ 2ch+zlib1222add - dep_good_match equ 84h+zlib1222add - dep_match_start equ 68h+zlib1222add - dep_lookahead equ 6ch+zlib1222add - - -_TEXT segment - -IFDEF NOUNDERLINE - public longest_match - public match_init -ELSE - public _longest_match - public _match_init -ENDIF - - MAX_MATCH equ 258 - MIN_MATCH equ 3 - MIN_LOOKAHEAD equ (MAX_MATCH+MIN_MATCH+1) - - - -MAX_MATCH equ 258 -MIN_MATCH equ 3 -MIN_LOOKAHEAD equ (MAX_MATCH + MIN_MATCH + 1) -MAX_MATCH_8_ equ ((MAX_MATCH + 7) AND 0FFF0h) - - -;;; stack frame offsets - -chainlenwmask equ esp + 0 ; high word: current chain len - ; low word: s->wmask -window equ esp + 4 ; local copy of s->window -windowbestlen equ esp + 8 ; s->window + bestlen -scanstart equ esp + 16 ; first two bytes of string -scanend equ esp + 12 ; last two bytes of string -scanalign equ esp + 20 ; dword-misalignment of string -nicematch equ esp + 24 ; a good enough match size -bestlen equ esp + 28 ; size of best match so far -scan equ esp + 32 ; ptr to string wanting match - -LocalVarsSize equ 36 -; saved ebx byte esp + 36 -; saved edi byte esp + 40 -; saved esi byte esp + 44 -; saved ebp byte esp + 48 -; return address byte esp + 52 -deflatestate equ esp + 56 ; the function arguments -curmatch equ esp + 60 - -;;; Offsets for fields in the deflate_state structure. These numbers -;;; are calculated from the definition of deflate_state, with the -;;; assumption that the compiler will dword-align the fields. (Thus, -;;; changing the definition of deflate_state could easily cause this -;;; program to crash horribly, without so much as a warning at -;;; compile time. Sigh.) - -dsWSize equ 36+zlib1222add -dsWMask equ 44+zlib1222add -dsWindow equ 48+zlib1222add -dsPrev equ 56+zlib1222add -dsMatchLen equ 88+zlib1222add -dsPrevMatch equ 92+zlib1222add -dsStrStart equ 100+zlib1222add -dsMatchStart equ 104+zlib1222add -dsLookahead equ 108+zlib1222add -dsPrevLen equ 112+zlib1222add -dsMaxChainLen equ 116+zlib1222add -dsGoodMatch equ 132+zlib1222add -dsNiceMatch equ 136+zlib1222add - - -;;; match686.asm -- Pentium-Pro-optimized version of longest_match() -;;; Written for zlib 1.1.2 -;;; Copyright (C) 1998 Brian Raiter -;;; You can look at http://www.muppetlabs.com/~breadbox/software/assembly.html -;;; -;; -;; This software is provided 'as-is', without any express or implied -;; warranty. In no event will the authors be held liable for any damages -;; arising from the use of this software. -;; -;; Permission is granted to anyone to use this software for any purpose, -;; including commercial applications, and to alter it and redistribute it -;; freely, subject to the following restrictions: -;; -;; 1. The origin of this software must not be misrepresented; you must not -;; claim that you wrote the original software. If you use this software -;; in a product, an acknowledgment in the product documentation would be -;; appreciated but is not required. -;; 2. Altered source versions must be plainly marked as such, and must not be -;; misrepresented as being the original software -;; 3. This notice may not be removed or altered from any source distribution. -;; - -;GLOBAL _longest_match, _match_init - - -;SECTION .text - -;;; uInt longest_match(deflate_state *deflatestate, IPos curmatch) - -;_longest_match: - IFDEF NOUNDERLINE - longest_match proc near - ELSE - _longest_match proc near - ENDIF -.FPO (9, 4, 0, 0, 1, 0) - -;;; Save registers that the compiler may be using, and adjust esp to -;;; make room for our stack frame. - - push ebp - push edi - push esi - push ebx - sub esp, LocalVarsSize - -;;; Retrieve the function arguments. ecx will hold cur_match -;;; throughout the entire function. edx will hold the pointer to the -;;; deflate_state structure during the function's setup (before -;;; entering the main loop. - - mov edx, [deflatestate] - mov ecx, [curmatch] - -;;; uInt wmask = s->w_mask; -;;; unsigned chain_length = s->max_chain_length; -;;; if (s->prev_length >= s->good_match) { -;;; chain_length >>= 2; -;;; } - - mov eax, [edx + dsPrevLen] - mov ebx, [edx + dsGoodMatch] - cmp eax, ebx - mov eax, [edx + dsWMask] - mov ebx, [edx + dsMaxChainLen] - jl LastMatchGood - shr ebx, 2 -LastMatchGood: - -;;; chainlen is decremented once beforehand so that the function can -;;; use the sign flag instead of the zero flag for the exit test. -;;; It is then shifted into the high word, to make room for the wmask -;;; value, which it will always accompany. - - dec ebx - shl ebx, 16 - or ebx, eax - mov [chainlenwmask], ebx - -;;; if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; - - mov eax, [edx + dsNiceMatch] - mov ebx, [edx + dsLookahead] - cmp ebx, eax - jl LookaheadLess - mov ebx, eax -LookaheadLess: mov [nicematch], ebx - -;;; register Bytef *scan = s->window + s->strstart; - - mov esi, [edx + dsWindow] - mov [window], esi - mov ebp, [edx + dsStrStart] - lea edi, [esi + ebp] - mov [scan], edi - -;;; Determine how many bytes the scan ptr is off from being -;;; dword-aligned. - - mov eax, edi - neg eax - and eax, 3 - mov [scanalign], eax - -;;; IPos limit = s->strstart > (IPos)MAX_DIST(s) ? -;;; s->strstart - (IPos)MAX_DIST(s) : NIL; - - mov eax, [edx + dsWSize] - sub eax, MIN_LOOKAHEAD - sub ebp, eax - jg LimitPositive - xor ebp, ebp -LimitPositive: - -;;; int best_len = s->prev_length; - - mov eax, [edx + dsPrevLen] - mov [bestlen], eax - -;;; Store the sum of s->window + best_len in esi locally, and in esi. - - add esi, eax - mov [windowbestlen], esi - -;;; register ush scan_start = *(ushf*)scan; -;;; register ush scan_end = *(ushf*)(scan+best_len-1); -;;; Posf *prev = s->prev; - - movzx ebx, word ptr [edi] - mov [scanstart], ebx - movzx ebx, word ptr [edi + eax - 1] - mov [scanend], ebx - mov edi, [edx + dsPrev] - -;;; Jump into the main loop. - - mov edx, [chainlenwmask] - jmp short LoopEntry - -align 4 - -;;; do { -;;; match = s->window + cur_match; -;;; if (*(ushf*)(match+best_len-1) != scan_end || -;;; *(ushf*)match != scan_start) continue; -;;; [...] -;;; } while ((cur_match = prev[cur_match & wmask]) > limit -;;; && --chain_length != 0); -;;; -;;; Here is the inner loop of the function. The function will spend the -;;; majority of its time in this loop, and majority of that time will -;;; be spent in the first ten instructions. -;;; -;;; Within this loop: -;;; ebx = scanend -;;; ecx = curmatch -;;; edx = chainlenwmask - i.e., ((chainlen << 16) | wmask) -;;; esi = windowbestlen - i.e., (window + bestlen) -;;; edi = prev -;;; ebp = limit - -LookupLoop: - and ecx, edx - movzx ecx, word ptr [edi + ecx*2] - cmp ecx, ebp - jbe LeaveNow - sub edx, 00010000h - js LeaveNow -LoopEntry: movzx eax, word ptr [esi + ecx - 1] - cmp eax, ebx - jnz LookupLoop - mov eax, [window] - movzx eax, word ptr [eax + ecx] - cmp eax, [scanstart] - jnz LookupLoop - -;;; Store the current value of chainlen. - - mov [chainlenwmask], edx - -;;; Point edi to the string under scrutiny, and esi to the string we -;;; are hoping to match it up with. In actuality, esi and edi are -;;; both pointed (MAX_MATCH_8 - scanalign) bytes ahead, and edx is -;;; initialized to -(MAX_MATCH_8 - scanalign). - - mov esi, [window] - mov edi, [scan] - add esi, ecx - mov eax, [scanalign] - mov edx, 0fffffef8h; -(MAX_MATCH_8) - lea edi, [edi + eax + 0108h] ;MAX_MATCH_8] - lea esi, [esi + eax + 0108h] ;MAX_MATCH_8] - -;;; Test the strings for equality, 8 bytes at a time. At the end, -;;; adjust edx so that it is offset to the exact byte that mismatched. -;;; -;;; We already know at this point that the first three bytes of the -;;; strings match each other, and they can be safely passed over before -;;; starting the compare loop. So what this code does is skip over 0-3 -;;; bytes, as much as necessary in order to dword-align the edi -;;; pointer. (esi will still be misaligned three times out of four.) -;;; -;;; It should be confessed that this loop usually does not represent -;;; much of the total running time. Replacing it with a more -;;; straightforward "rep cmpsb" would not drastically degrade -;;; performance. - -LoopCmps: - mov eax, [esi + edx] - xor eax, [edi + edx] - jnz LeaveLoopCmps - mov eax, [esi + edx + 4] - xor eax, [edi + edx + 4] - jnz LeaveLoopCmps4 - add edx, 8 - jnz LoopCmps - jmp short LenMaximum -LeaveLoopCmps4: add edx, 4 -LeaveLoopCmps: test eax, 0000FFFFh - jnz LenLower - add edx, 2 - shr eax, 16 -LenLower: sub al, 1 - adc edx, 0 - -;;; Calculate the length of the match. If it is longer than MAX_MATCH, -;;; then automatically accept it as the best possible match and leave. - - lea eax, [edi + edx] - mov edi, [scan] - sub eax, edi - cmp eax, MAX_MATCH - jge LenMaximum - -;;; If the length of the match is not longer than the best match we -;;; have so far, then forget it and return to the lookup loop. - - mov edx, [deflatestate] - mov ebx, [bestlen] - cmp eax, ebx - jg LongerMatch - mov esi, [windowbestlen] - mov edi, [edx + dsPrev] - mov ebx, [scanend] - mov edx, [chainlenwmask] - jmp LookupLoop - -;;; s->match_start = cur_match; -;;; best_len = len; -;;; if (len >= nice_match) break; -;;; scan_end = *(ushf*)(scan+best_len-1); - -LongerMatch: mov ebx, [nicematch] - mov [bestlen], eax - mov [edx + dsMatchStart], ecx - cmp eax, ebx - jge LeaveNow - mov esi, [window] - add esi, eax - mov [windowbestlen], esi - movzx ebx, word ptr [edi + eax - 1] - mov edi, [edx + dsPrev] - mov [scanend], ebx - mov edx, [chainlenwmask] - jmp LookupLoop - -;;; Accept the current string, with the maximum possible length. - -LenMaximum: mov edx, [deflatestate] - mov dword ptr [bestlen], MAX_MATCH - mov [edx + dsMatchStart], ecx - -;;; if ((uInt)best_len <= s->lookahead) return (uInt)best_len; -;;; return s->lookahead; - -LeaveNow: - mov edx, [deflatestate] - mov ebx, [bestlen] - mov eax, [edx + dsLookahead] - cmp ebx, eax - jg LookaheadRet - mov eax, ebx -LookaheadRet: - -;;; Restore the stack and return from whence we came. - - add esp, LocalVarsSize - pop ebx - pop esi - pop edi - pop ebp - - ret -; please don't remove this string ! -; Your can freely use match686 in any free or commercial app if you don't remove the string in the binary! - db 0dh,0ah,"asm686 with masm, optimised assembly code from Brian Raiter, written 1998",0dh,0ah - - - IFDEF NOUNDERLINE - longest_match endp - ELSE - _longest_match endp - ENDIF - - IFDEF NOUNDERLINE - match_init proc near - ret - match_init endp - ELSE - _match_init proc near - ret - _match_init endp - ENDIF - - -_TEXT ends -end diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/masmx86/readme.txt b/src/beast/test/zlib/zlib-1.2.8/contrib/masmx86/readme.txt deleted file mode 100644 index 3f8888679fc..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/masmx86/readme.txt +++ /dev/null @@ -1,27 +0,0 @@ - -Summary -------- -This directory contains ASM implementations of the functions -longest_match() and inflate_fast(). - - -Use instructions ----------------- -Assemble using MASM, and copy the object files into the zlib source -directory, then run the appropriate makefile, as suggested below. You can -donwload MASM from here: - - http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=7a1c9da0-0510-44a2-b042-7ef370530c64 - -You can also get objects files here: - - http://www.winimage.com/zLibDll/zlib124_masm_obj.zip - -Build instructions ------------------- -* With Microsoft C and MASM: -nmake -f win32/Makefile.msc LOC="-DASMV -DASMINF" OBJA="match686.obj inffas32.obj" - -* With Borland C and TASM: -make -f win32/Makefile.bor LOCAL_ZLIB="-DASMV -DASMINF" OBJA="match686.obj inffas32.obj" OBJPA="+match686c.obj+match686.obj+inffas32.obj" - diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/Makefile b/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/Makefile deleted file mode 100644 index 84eaad20d4f..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -CC=cc -CFLAGS=-O -I../.. - -UNZ_OBJS = miniunz.o unzip.o ioapi.o ../../libz.a -ZIP_OBJS = minizip.o zip.o ioapi.o ../../libz.a - -.c.o: - $(CC) -c $(CFLAGS) $*.c - -all: miniunz minizip - -miniunz: $(UNZ_OBJS) - $(CC) $(CFLAGS) -o $@ $(UNZ_OBJS) - -minizip: $(ZIP_OBJS) - $(CC) $(CFLAGS) -o $@ $(ZIP_OBJS) - -test: miniunz minizip - ./minizip test readme.txt - ./miniunz -l test.zip - mv readme.txt readme.old - ./miniunz test.zip - -clean: - /bin/rm -f *.o *~ minizip miniunz diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/Makefile.am b/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/Makefile.am deleted file mode 100644 index d343011ebc3..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/Makefile.am +++ /dev/null @@ -1,45 +0,0 @@ -lib_LTLIBRARIES = libminizip.la - -if COND_DEMOS -bin_PROGRAMS = miniunzip minizip -endif - -zlib_top_srcdir = $(top_srcdir)/../.. -zlib_top_builddir = $(top_builddir)/../.. - -AM_CPPFLAGS = -I$(zlib_top_srcdir) -AM_LDFLAGS = -L$(zlib_top_builddir) - -if WIN32 -iowin32_src = iowin32.c -iowin32_h = iowin32.h -endif - -libminizip_la_SOURCES = \ - ioapi.c \ - mztools.c \ - unzip.c \ - zip.c \ - ${iowin32_src} - -libminizip_la_LDFLAGS = $(AM_LDFLAGS) -version-info 1:0:0 -lz - -minizip_includedir = $(includedir)/minizip -minizip_include_HEADERS = \ - crypt.h \ - ioapi.h \ - mztools.h \ - unzip.h \ - zip.h \ - ${iowin32_h} - -pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = minizip.pc - -EXTRA_PROGRAMS = miniunzip minizip - -miniunzip_SOURCES = miniunz.c -miniunzip_LDADD = libminizip.la - -minizip_SOURCES = minizip.c -minizip_LDADD = libminizip.la -lz diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/MiniZip64_Changes.txt b/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/MiniZip64_Changes.txt deleted file mode 100644 index 13a1bd91a9b..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/MiniZip64_Changes.txt +++ /dev/null @@ -1,6 +0,0 @@ - -MiniZip 1.1 was derrived from MiniZip at version 1.01f - -Change in 1.0 (Okt 2009) - - **TODO - Add history** - diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/MiniZip64_info.txt b/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/MiniZip64_info.txt deleted file mode 100644 index 57d71524208..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/MiniZip64_info.txt +++ /dev/null @@ -1,74 +0,0 @@ -MiniZip - Copyright (c) 1998-2010 - by Gilles Vollant - version 1.1 64 bits from Mathias Svensson - -Introduction ---------------------- -MiniZip 1.1 is built from MiniZip 1.0 by Gilles Vollant ( http://www.winimage.com/zLibDll/minizip.html ) - -When adding ZIP64 support into minizip it would result into risk of breaking compatibility with minizip 1.0. -All possible work was done for compatibility. - - -Background ---------------------- -When adding ZIP64 support Mathias Svensson found that Even Rouault have added ZIP64 -support for unzip.c into minizip for a open source project called gdal ( http://www.gdal.org/ ) - -That was used as a starting point. And after that ZIP64 support was added to zip.c -some refactoring and code cleanup was also done. - - -Changed from MiniZip 1.0 to MiniZip 1.1 ---------------------------------------- -* Added ZIP64 support for unzip ( by Even Rouault ) -* Added ZIP64 support for zip ( by Mathias Svensson ) -* Reverted some changed that Even Rouault did. -* Bunch of patches received from Gulles Vollant that he received for MiniZip from various users. -* Added unzip patch for BZIP Compression method (patch create by Daniel Borca) -* Added BZIP Compress method for zip -* Did some refactoring and code cleanup - - -Credits - - Gilles Vollant - Original MiniZip author - Even Rouault - ZIP64 unzip Support - Daniel Borca - BZip Compression method support in unzip - Mathias Svensson - ZIP64 zip support - Mathias Svensson - BZip Compression method support in zip - - Resources - - ZipLayout http://result42.com/projects/ZipFileLayout - Command line tool for Windows that shows the layout and information of the headers in a zip archive. - Used when debugging and validating the creation of zip files using MiniZip64 - - - ZIP App Note http://www.pkware.com/documents/casestudies/APPNOTE.TXT - Zip File specification - - -Notes. - * To be able to use BZip compression method in zip64.c or unzip64.c the BZIP2 lib is needed and HAVE_BZIP2 need to be defined. - -License ----------------------------------------------------------- - Condition of use and distribution are the same than zlib : - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - ----------------------------------------------------------- - diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/configure.ac b/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/configure.ac deleted file mode 100644 index 827a4e05770..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/configure.ac +++ /dev/null @@ -1,32 +0,0 @@ -# -*- Autoconf -*- -# Process this file with autoconf to produce a configure script. - -AC_INIT([minizip], [1.2.8], [bugzilla.redhat.com]) -AC_CONFIG_SRCDIR([minizip.c]) -AM_INIT_AUTOMAKE([foreign]) -LT_INIT - -AC_MSG_CHECKING([whether to build example programs]) -AC_ARG_ENABLE([demos], AC_HELP_STRING([--enable-demos], [build example programs])) -AM_CONDITIONAL([COND_DEMOS], [test "$enable_demos" = yes]) -if test "$enable_demos" = yes -then - AC_MSG_RESULT([yes]) -else - AC_MSG_RESULT([no]) -fi - -case "${host}" in - *-mingw* | mingw*) - WIN32="yes" - ;; - *) - ;; -esac -AM_CONDITIONAL([WIN32], [test "${WIN32}" = "yes"]) - - -AC_SUBST([HAVE_UNISTD_H], [0]) -AC_CHECK_HEADER([unistd.h], [HAVE_UNISTD_H=1], []) -AC_CONFIG_FILES([Makefile minizip.pc]) -AC_OUTPUT diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/crypt.h b/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/crypt.h deleted file mode 100644 index 1e9e8200b20..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/crypt.h +++ /dev/null @@ -1,131 +0,0 @@ -/* crypt.h -- base code for crypt/uncrypt ZIPfile - - - Version 1.01e, February 12th, 2005 - - Copyright (C) 1998-2005 Gilles Vollant - - This code is a modified version of crypting code in Infozip distribution - - The encryption/decryption parts of this source code (as opposed to the - non-echoing password parts) were originally written in Europe. The - whole source package can be freely distributed, including from the USA. - (Prior to January 2000, re-export from the US was a violation of US law.) - - This encryption code is a direct transcription of the algorithm from - Roger Schlafly, described by Phil Katz in the file appnote.txt. This - file (appnote.txt) is distributed with the PKZIP program (even in the - version without encryption capabilities). - - If you don't need crypting in your application, just define symbols - NOCRYPT and NOUNCRYPT. - - This code support the "Traditional PKWARE Encryption". - - The new AES encryption added on Zip format by Winzip (see the page - http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong - Encryption is not supported. -*/ - -#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) - -/*********************************************************************** - * Return the next byte in the pseudo-random sequence - */ -static int decrypt_byte(unsigned long* pkeys, const z_crc_t* pcrc_32_tab) -{ - unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an - * unpredictable manner on 16-bit systems; not a problem - * with any known compiler so far, though */ - - temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2; - return (int)(((temp * (temp ^ 1)) >> 8) & 0xff); -} - -/*********************************************************************** - * Update the encryption keys with the next byte of plain text - */ -static int update_keys(unsigned long* pkeys,const z_crc_t* pcrc_32_tab,int c) -{ - (*(pkeys+0)) = CRC32((*(pkeys+0)), c); - (*(pkeys+1)) += (*(pkeys+0)) & 0xff; - (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1; - { - register int keyshift = (int)((*(pkeys+1)) >> 24); - (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift); - } - return c; -} - - -/*********************************************************************** - * Initialize the encryption keys and the random header according to - * the given password. - */ -static void init_keys(const char* passwd,unsigned long* pkeys,const z_crc_t* pcrc_32_tab) -{ - *(pkeys+0) = 305419896L; - *(pkeys+1) = 591751049L; - *(pkeys+2) = 878082192L; - while (*passwd != '\0') { - update_keys(pkeys,pcrc_32_tab,(int)*passwd); - passwd++; - } -} - -#define zdecode(pkeys,pcrc_32_tab,c) \ - (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab))) - -#define zencode(pkeys,pcrc_32_tab,c,t) \ - (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c)) - -#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED - -#define RAND_HEAD_LEN 12 - /* "last resort" source for second part of crypt seed pattern */ -# ifndef ZCR_SEED2 -# define ZCR_SEED2 3141592654UL /* use PI as default pattern */ -# endif - -static int crypthead(const char* passwd, /* password string */ - unsigned char* buf, /* where to write header */ - int bufSize, - unsigned long* pkeys, - const z_crc_t* pcrc_32_tab, - unsigned long crcForCrypting) -{ - int n; /* index in random header */ - int t; /* temporary */ - int c; /* random byte */ - unsigned char header[RAND_HEAD_LEN-2]; /* random header */ - static unsigned calls = 0; /* ensure different random header each time */ - - if (bufSize> 7) & 0xff; - header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t); - } - /* Encrypt random header (last two bytes is high word of crc) */ - init_keys(passwd, pkeys, pcrc_32_tab); - for (n = 0; n < RAND_HEAD_LEN-2; n++) - { - buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t); - } - buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t); - buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t); - return n; -} - -#endif diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/ioapi.c b/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/ioapi.c deleted file mode 100644 index 7f5c191b2af..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/ioapi.c +++ /dev/null @@ -1,247 +0,0 @@ -/* ioapi.h -- IO base function header for compress/uncompress .zip - part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) - - Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) - - Modifications for Zip64 support - Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) - - For more info read MiniZip_info.txt - -*/ - -#if defined(_WIN32) && (!(defined(_CRT_SECURE_NO_WARNINGS))) - #define _CRT_SECURE_NO_WARNINGS -#endif - -#if defined(__APPLE__) || defined(IOAPI_NO_64) -// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions -#define FOPEN_FUNC(filename, mode) fopen(filename, mode) -#define FTELLO_FUNC(stream) ftello(stream) -#define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin) -#else -#define FOPEN_FUNC(filename, mode) fopen64(filename, mode) -#define FTELLO_FUNC(stream) ftello64(stream) -#define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin) -#endif - - -#include "ioapi.h" - -voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode) -{ - if (pfilefunc->zfile_func64.zopen64_file != NULL) - return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode); - else - { - return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode); - } -} - -long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin) -{ - if (pfilefunc->zfile_func64.zseek64_file != NULL) - return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin); - else - { - uLong offsetTruncated = (uLong)offset; - if (offsetTruncated != offset) - return -1; - else - return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin); - } -} - -ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream) -{ - if (pfilefunc->zfile_func64.zseek64_file != NULL) - return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream); - else - { - uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream); - if ((tell_uLong) == MAXU32) - return (ZPOS64_T)-1; - else - return tell_uLong; - } -} - -void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32) -{ - p_filefunc64_32->zfile_func64.zopen64_file = NULL; - p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file; - p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; - p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file; - p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file; - p_filefunc64_32->zfile_func64.ztell64_file = NULL; - p_filefunc64_32->zfile_func64.zseek64_file = NULL; - p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file; - p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; - p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque; - p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file; - p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file; -} - - - -static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode)); -static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size)); -static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size)); -static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream)); -static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); -static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream)); -static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream)); - -static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode) -{ - FILE* file = NULL; - const char* mode_fopen = NULL; - if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) - mode_fopen = "rb"; - else - if (mode & ZLIB_FILEFUNC_MODE_EXISTING) - mode_fopen = "r+b"; - else - if (mode & ZLIB_FILEFUNC_MODE_CREATE) - mode_fopen = "wb"; - - if ((filename!=NULL) && (mode_fopen != NULL)) - file = fopen(filename, mode_fopen); - return file; -} - -static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode) -{ - FILE* file = NULL; - const char* mode_fopen = NULL; - if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) - mode_fopen = "rb"; - else - if (mode & ZLIB_FILEFUNC_MODE_EXISTING) - mode_fopen = "r+b"; - else - if (mode & ZLIB_FILEFUNC_MODE_CREATE) - mode_fopen = "wb"; - - if ((filename!=NULL) && (mode_fopen != NULL)) - file = FOPEN_FUNC((const char*)filename, mode_fopen); - return file; -} - - -static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size) -{ - uLong ret; - ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); - return ret; -} - -static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size) -{ - uLong ret; - ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); - return ret; -} - -static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream) -{ - long ret; - ret = ftell((FILE *)stream); - return ret; -} - - -static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream) -{ - ZPOS64_T ret; - ret = FTELLO_FUNC((FILE *)stream); - return ret; -} - -static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin) -{ - int fseek_origin=0; - long ret; - switch (origin) - { - case ZLIB_FILEFUNC_SEEK_CUR : - fseek_origin = SEEK_CUR; - break; - case ZLIB_FILEFUNC_SEEK_END : - fseek_origin = SEEK_END; - break; - case ZLIB_FILEFUNC_SEEK_SET : - fseek_origin = SEEK_SET; - break; - default: return -1; - } - ret = 0; - if (fseek((FILE *)stream, offset, fseek_origin) != 0) - ret = -1; - return ret; -} - -static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin) -{ - int fseek_origin=0; - long ret; - switch (origin) - { - case ZLIB_FILEFUNC_SEEK_CUR : - fseek_origin = SEEK_CUR; - break; - case ZLIB_FILEFUNC_SEEK_END : - fseek_origin = SEEK_END; - break; - case ZLIB_FILEFUNC_SEEK_SET : - fseek_origin = SEEK_SET; - break; - default: return -1; - } - ret = 0; - - if(FSEEKO_FUNC((FILE *)stream, offset, fseek_origin) != 0) - ret = -1; - - return ret; -} - - -static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream) -{ - int ret; - ret = fclose((FILE *)stream); - return ret; -} - -static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream) -{ - int ret; - ret = ferror((FILE *)stream); - return ret; -} - -void fill_fopen_filefunc (pzlib_filefunc_def) - zlib_filefunc_def* pzlib_filefunc_def; -{ - pzlib_filefunc_def->zopen_file = fopen_file_func; - pzlib_filefunc_def->zread_file = fread_file_func; - pzlib_filefunc_def->zwrite_file = fwrite_file_func; - pzlib_filefunc_def->ztell_file = ftell_file_func; - pzlib_filefunc_def->zseek_file = fseek_file_func; - pzlib_filefunc_def->zclose_file = fclose_file_func; - pzlib_filefunc_def->zerror_file = ferror_file_func; - pzlib_filefunc_def->opaque = NULL; -} - -void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def) -{ - pzlib_filefunc_def->zopen64_file = fopen64_file_func; - pzlib_filefunc_def->zread_file = fread_file_func; - pzlib_filefunc_def->zwrite_file = fwrite_file_func; - pzlib_filefunc_def->ztell64_file = ftell64_file_func; - pzlib_filefunc_def->zseek64_file = fseek64_file_func; - pzlib_filefunc_def->zclose_file = fclose_file_func; - pzlib_filefunc_def->zerror_file = ferror_file_func; - pzlib_filefunc_def->opaque = NULL; -} diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/ioapi.h b/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/ioapi.h deleted file mode 100644 index 8dcbdb06e35..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/ioapi.h +++ /dev/null @@ -1,208 +0,0 @@ -/* ioapi.h -- IO base function header for compress/uncompress .zip - part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) - - Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) - - Modifications for Zip64 support - Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) - - For more info read MiniZip_info.txt - - Changes - - Oct-2009 - Defined ZPOS64_T to fpos_t on windows and u_int64_t on linux. (might need to find a better why for this) - Oct-2009 - Change to fseeko64, ftello64 and fopen64 so large files would work on linux. - More if/def section may be needed to support other platforms - Oct-2009 - Defined fxxxx64 calls to normal fopen/ftell/fseek so they would compile on windows. - (but you should use iowin32.c for windows instead) - -*/ - -#ifndef _ZLIBIOAPI64_H -#define _ZLIBIOAPI64_H - -#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__)) - - // Linux needs this to support file operation on files larger then 4+GB - // But might need better if/def to select just the platforms that needs them. - - #ifndef __USE_FILE_OFFSET64 - #define __USE_FILE_OFFSET64 - #endif - #ifndef __USE_LARGEFILE64 - #define __USE_LARGEFILE64 - #endif - #ifndef _LARGEFILE64_SOURCE - #define _LARGEFILE64_SOURCE - #endif - #ifndef _FILE_OFFSET_BIT - #define _FILE_OFFSET_BIT 64 - #endif - -#endif - -#include -#include -#include "zlib.h" - -#if defined(USE_FILE32API) -#define fopen64 fopen -#define ftello64 ftell -#define fseeko64 fseek -#else -#ifdef __FreeBSD__ -#define fopen64 fopen -#define ftello64 ftello -#define fseeko64 fseeko -#endif -#ifdef _MSC_VER - #define fopen64 fopen - #if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC))) - #define ftello64 _ftelli64 - #define fseeko64 _fseeki64 - #else // old MSC - #define ftello64 ftell - #define fseeko64 fseek - #endif -#endif -#endif - -/* -#ifndef ZPOS64_T - #ifdef _WIN32 - #define ZPOS64_T fpos_t - #else - #include - #define ZPOS64_T uint64_t - #endif -#endif -*/ - -#ifdef HAVE_MINIZIP64_CONF_H -#include "mz64conf.h" -#endif - -/* a type choosen by DEFINE */ -#ifdef HAVE_64BIT_INT_CUSTOM -typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T; -#else -#ifdef HAS_STDINT_H -#include "stdint.h" -typedef uint64_t ZPOS64_T; -#else - -/* Maximum unsigned 32-bit value used as placeholder for zip64 */ -#define MAXU32 0xffffffff - -#if defined(_MSC_VER) || defined(__BORLANDC__) -typedef unsigned __int64 ZPOS64_T; -#else -typedef unsigned long long int ZPOS64_T; -#endif -#endif -#endif - - - -#ifdef __cplusplus -extern "C" { -#endif - - -#define ZLIB_FILEFUNC_SEEK_CUR (1) -#define ZLIB_FILEFUNC_SEEK_END (2) -#define ZLIB_FILEFUNC_SEEK_SET (0) - -#define ZLIB_FILEFUNC_MODE_READ (1) -#define ZLIB_FILEFUNC_MODE_WRITE (2) -#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) - -#define ZLIB_FILEFUNC_MODE_EXISTING (4) -#define ZLIB_FILEFUNC_MODE_CREATE (8) - - -#ifndef ZCALLBACK - #if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) - #define ZCALLBACK CALLBACK - #else - #define ZCALLBACK - #endif -#endif - - - - -typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); -typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); -typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); -typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); -typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); - -typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); -typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); - - -/* here is the "old" 32 bits structure structure */ -typedef struct zlib_filefunc_def_s -{ - open_file_func zopen_file; - read_file_func zread_file; - write_file_func zwrite_file; - tell_file_func ztell_file; - seek_file_func zseek_file; - close_file_func zclose_file; - testerror_file_func zerror_file; - voidpf opaque; -} zlib_filefunc_def; - -typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream)); -typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); -typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode)); - -typedef struct zlib_filefunc64_def_s -{ - open64_file_func zopen64_file; - read_file_func zread_file; - write_file_func zwrite_file; - tell64_file_func ztell64_file; - seek64_file_func zseek64_file; - close_file_func zclose_file; - testerror_file_func zerror_file; - voidpf opaque; -} zlib_filefunc64_def; - -void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def)); -void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); - -/* now internal definition, only for zip.c and unzip.h */ -typedef struct zlib_filefunc64_32_def_s -{ - zlib_filefunc64_def zfile_func64; - open_file_func zopen32_file; - tell_file_func ztell32_file; - seek_file_func zseek32_file; -} zlib_filefunc64_32_def; - - -#define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) -#define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) -//#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream)) -//#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode)) -#define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream)) -#define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream)) - -voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)); -long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)); -ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)); - -void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32); - -#define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode))) -#define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream))) -#define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode))) - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/iowin32.c b/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/iowin32.c deleted file mode 100644 index a46d96c7fdd..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/iowin32.c +++ /dev/null @@ -1,461 +0,0 @@ -/* iowin32.c -- IO base function header for compress/uncompress .zip - Version 1.1, February 14h, 2010 - part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) - - Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) - - Modifications for Zip64 support - Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) - - For more info read MiniZip_info.txt - -*/ - -#include - -#include "zlib.h" -#include "ioapi.h" -#include "iowin32.h" - -#ifndef INVALID_HANDLE_VALUE -#define INVALID_HANDLE_VALUE (0xFFFFFFFF) -#endif - -#ifndef INVALID_SET_FILE_POINTER -#define INVALID_SET_FILE_POINTER ((DWORD)-1) -#endif - - -#if defined(WINAPI_FAMILY_PARTITION) && (!(defined(IOWIN32_USING_WINRT_API))) -#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) -#define IOWIN32_USING_WINRT_API 1 -#endif -#endif - -voidpf ZCALLBACK win32_open_file_func OF((voidpf opaque, const char* filename, int mode)); -uLong ZCALLBACK win32_read_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size)); -uLong ZCALLBACK win32_write_file_func OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); -ZPOS64_T ZCALLBACK win32_tell64_file_func OF((voidpf opaque, voidpf stream)); -long ZCALLBACK win32_seek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); -int ZCALLBACK win32_close_file_func OF((voidpf opaque, voidpf stream)); -int ZCALLBACK win32_error_file_func OF((voidpf opaque, voidpf stream)); - -typedef struct -{ - HANDLE hf; - int error; -} WIN32FILE_IOWIN; - - -static void win32_translate_open_mode(int mode, - DWORD* lpdwDesiredAccess, - DWORD* lpdwCreationDisposition, - DWORD* lpdwShareMode, - DWORD* lpdwFlagsAndAttributes) -{ - *lpdwDesiredAccess = *lpdwShareMode = *lpdwFlagsAndAttributes = *lpdwCreationDisposition = 0; - - if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) - { - *lpdwDesiredAccess = GENERIC_READ; - *lpdwCreationDisposition = OPEN_EXISTING; - *lpdwShareMode = FILE_SHARE_READ; - } - else if (mode & ZLIB_FILEFUNC_MODE_EXISTING) - { - *lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ; - *lpdwCreationDisposition = OPEN_EXISTING; - } - else if (mode & ZLIB_FILEFUNC_MODE_CREATE) - { - *lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ; - *lpdwCreationDisposition = CREATE_ALWAYS; - } -} - -static voidpf win32_build_iowin(HANDLE hFile) -{ - voidpf ret=NULL; - - if ((hFile != NULL) && (hFile != INVALID_HANDLE_VALUE)) - { - WIN32FILE_IOWIN w32fiow; - w32fiow.hf = hFile; - w32fiow.error = 0; - ret = malloc(sizeof(WIN32FILE_IOWIN)); - - if (ret==NULL) - CloseHandle(hFile); - else - *((WIN32FILE_IOWIN*)ret) = w32fiow; - } - return ret; -} - -voidpf ZCALLBACK win32_open64_file_func (voidpf opaque,const void* filename,int mode) -{ - const char* mode_fopen = NULL; - DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; - HANDLE hFile = NULL; - - win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes); - -#ifdef IOWIN32_USING_WINRT_API -#ifdef UNICODE - if ((filename!=NULL) && (dwDesiredAccess != 0)) - hFile = CreateFile2((LPCTSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL); -#else - if ((filename!=NULL) && (dwDesiredAccess != 0)) - { - WCHAR filenameW[FILENAME_MAX + 0x200 + 1]; - MultiByteToWideChar(CP_ACP,0,(const char*)filename,-1,filenameW,FILENAME_MAX + 0x200); - hFile = CreateFile2(filenameW, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL); - } -#endif -#else - if ((filename!=NULL) && (dwDesiredAccess != 0)) - hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL); -#endif - - return win32_build_iowin(hFile); -} - - -voidpf ZCALLBACK win32_open64_file_funcA (voidpf opaque,const void* filename,int mode) -{ - const char* mode_fopen = NULL; - DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; - HANDLE hFile = NULL; - - win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes); - -#ifdef IOWIN32_USING_WINRT_API - if ((filename!=NULL) && (dwDesiredAccess != 0)) - { - WCHAR filenameW[FILENAME_MAX + 0x200 + 1]; - MultiByteToWideChar(CP_ACP,0,(const char*)filename,-1,filenameW,FILENAME_MAX + 0x200); - hFile = CreateFile2(filenameW, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL); - } -#else - if ((filename!=NULL) && (dwDesiredAccess != 0)) - hFile = CreateFileA((LPCSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL); -#endif - - return win32_build_iowin(hFile); -} - - -voidpf ZCALLBACK win32_open64_file_funcW (voidpf opaque,const void* filename,int mode) -{ - const char* mode_fopen = NULL; - DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; - HANDLE hFile = NULL; - - win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes); - -#ifdef IOWIN32_USING_WINRT_API - if ((filename!=NULL) && (dwDesiredAccess != 0)) - hFile = CreateFile2((LPCWSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition,NULL); -#else - if ((filename!=NULL) && (dwDesiredAccess != 0)) - hFile = CreateFileW((LPCWSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL); -#endif - - return win32_build_iowin(hFile); -} - - -voidpf ZCALLBACK win32_open_file_func (voidpf opaque,const char* filename,int mode) -{ - const char* mode_fopen = NULL; - DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; - HANDLE hFile = NULL; - - win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes); - -#ifdef IOWIN32_USING_WINRT_API -#ifdef UNICODE - if ((filename!=NULL) && (dwDesiredAccess != 0)) - hFile = CreateFile2((LPCTSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL); -#else - if ((filename!=NULL) && (dwDesiredAccess != 0)) - { - WCHAR filenameW[FILENAME_MAX + 0x200 + 1]; - MultiByteToWideChar(CP_ACP,0,(const char*)filename,-1,filenameW,FILENAME_MAX + 0x200); - hFile = CreateFile2(filenameW, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL); - } -#endif -#else - if ((filename!=NULL) && (dwDesiredAccess != 0)) - hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL); -#endif - - return win32_build_iowin(hFile); -} - - -uLong ZCALLBACK win32_read_file_func (voidpf opaque, voidpf stream, void* buf,uLong size) -{ - uLong ret=0; - HANDLE hFile = NULL; - if (stream!=NULL) - hFile = ((WIN32FILE_IOWIN*)stream) -> hf; - - if (hFile != NULL) - { - if (!ReadFile(hFile, buf, size, &ret, NULL)) - { - DWORD dwErr = GetLastError(); - if (dwErr == ERROR_HANDLE_EOF) - dwErr = 0; - ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; - } - } - - return ret; -} - - -uLong ZCALLBACK win32_write_file_func (voidpf opaque,voidpf stream,const void* buf,uLong size) -{ - uLong ret=0; - HANDLE hFile = NULL; - if (stream!=NULL) - hFile = ((WIN32FILE_IOWIN*)stream) -> hf; - - if (hFile != NULL) - { - if (!WriteFile(hFile, buf, size, &ret, NULL)) - { - DWORD dwErr = GetLastError(); - if (dwErr == ERROR_HANDLE_EOF) - dwErr = 0; - ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; - } - } - - return ret; -} - -static BOOL MySetFilePointerEx(HANDLE hFile, LARGE_INTEGER pos, LARGE_INTEGER *newPos, DWORD dwMoveMethod) -{ -#ifdef IOWIN32_USING_WINRT_API - return SetFilePointerEx(hFile, pos, newPos, dwMoveMethod); -#else - LONG lHigh = pos.HighPart; - DWORD dwNewPos = SetFilePointer(hFile, pos.LowPart, &lHigh, FILE_CURRENT); - BOOL fOk = TRUE; - if (dwNewPos == 0xFFFFFFFF) - if (GetLastError() != NO_ERROR) - fOk = FALSE; - if ((newPos != NULL) && (fOk)) - { - newPos->LowPart = dwNewPos; - newPos->HighPart = lHigh; - } - return fOk; -#endif -} - -long ZCALLBACK win32_tell_file_func (voidpf opaque,voidpf stream) -{ - long ret=-1; - HANDLE hFile = NULL; - if (stream!=NULL) - hFile = ((WIN32FILE_IOWIN*)stream) -> hf; - if (hFile != NULL) - { - LARGE_INTEGER pos; - pos.QuadPart = 0; - - if (!MySetFilePointerEx(hFile, pos, &pos, FILE_CURRENT)) - { - DWORD dwErr = GetLastError(); - ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; - ret = -1; - } - else - ret=(long)pos.LowPart; - } - return ret; -} - -ZPOS64_T ZCALLBACK win32_tell64_file_func (voidpf opaque, voidpf stream) -{ - ZPOS64_T ret= (ZPOS64_T)-1; - HANDLE hFile = NULL; - if (stream!=NULL) - hFile = ((WIN32FILE_IOWIN*)stream)->hf; - - if (hFile) - { - LARGE_INTEGER pos; - pos.QuadPart = 0; - - if (!MySetFilePointerEx(hFile, pos, &pos, FILE_CURRENT)) - { - DWORD dwErr = GetLastError(); - ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; - ret = (ZPOS64_T)-1; - } - else - ret=pos.QuadPart; - } - return ret; -} - - -long ZCALLBACK win32_seek_file_func (voidpf opaque,voidpf stream,uLong offset,int origin) -{ - DWORD dwMoveMethod=0xFFFFFFFF; - HANDLE hFile = NULL; - - long ret=-1; - if (stream!=NULL) - hFile = ((WIN32FILE_IOWIN*)stream) -> hf; - switch (origin) - { - case ZLIB_FILEFUNC_SEEK_CUR : - dwMoveMethod = FILE_CURRENT; - break; - case ZLIB_FILEFUNC_SEEK_END : - dwMoveMethod = FILE_END; - break; - case ZLIB_FILEFUNC_SEEK_SET : - dwMoveMethod = FILE_BEGIN; - break; - default: return -1; - } - - if (hFile != NULL) - { - LARGE_INTEGER pos; - pos.QuadPart = offset; - if (!MySetFilePointerEx(hFile, pos, NULL, dwMoveMethod)) - { - DWORD dwErr = GetLastError(); - ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; - ret = -1; - } - else - ret=0; - } - return ret; -} - -long ZCALLBACK win32_seek64_file_func (voidpf opaque, voidpf stream,ZPOS64_T offset,int origin) -{ - DWORD dwMoveMethod=0xFFFFFFFF; - HANDLE hFile = NULL; - long ret=-1; - - if (stream!=NULL) - hFile = ((WIN32FILE_IOWIN*)stream)->hf; - - switch (origin) - { - case ZLIB_FILEFUNC_SEEK_CUR : - dwMoveMethod = FILE_CURRENT; - break; - case ZLIB_FILEFUNC_SEEK_END : - dwMoveMethod = FILE_END; - break; - case ZLIB_FILEFUNC_SEEK_SET : - dwMoveMethod = FILE_BEGIN; - break; - default: return -1; - } - - if (hFile) - { - LARGE_INTEGER pos; - pos.QuadPart = offset; - if (!MySetFilePointerEx(hFile, pos, NULL, FILE_CURRENT)) - { - DWORD dwErr = GetLastError(); - ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; - ret = -1; - } - else - ret=0; - } - return ret; -} - -int ZCALLBACK win32_close_file_func (voidpf opaque, voidpf stream) -{ - int ret=-1; - - if (stream!=NULL) - { - HANDLE hFile; - hFile = ((WIN32FILE_IOWIN*)stream) -> hf; - if (hFile != NULL) - { - CloseHandle(hFile); - ret=0; - } - free(stream); - } - return ret; -} - -int ZCALLBACK win32_error_file_func (voidpf opaque,voidpf stream) -{ - int ret=-1; - if (stream!=NULL) - { - ret = ((WIN32FILE_IOWIN*)stream) -> error; - } - return ret; -} - -void fill_win32_filefunc (zlib_filefunc_def* pzlib_filefunc_def) -{ - pzlib_filefunc_def->zopen_file = win32_open_file_func; - pzlib_filefunc_def->zread_file = win32_read_file_func; - pzlib_filefunc_def->zwrite_file = win32_write_file_func; - pzlib_filefunc_def->ztell_file = win32_tell_file_func; - pzlib_filefunc_def->zseek_file = win32_seek_file_func; - pzlib_filefunc_def->zclose_file = win32_close_file_func; - pzlib_filefunc_def->zerror_file = win32_error_file_func; - pzlib_filefunc_def->opaque = NULL; -} - -void fill_win32_filefunc64(zlib_filefunc64_def* pzlib_filefunc_def) -{ - pzlib_filefunc_def->zopen64_file = win32_open64_file_func; - pzlib_filefunc_def->zread_file = win32_read_file_func; - pzlib_filefunc_def->zwrite_file = win32_write_file_func; - pzlib_filefunc_def->ztell64_file = win32_tell64_file_func; - pzlib_filefunc_def->zseek64_file = win32_seek64_file_func; - pzlib_filefunc_def->zclose_file = win32_close_file_func; - pzlib_filefunc_def->zerror_file = win32_error_file_func; - pzlib_filefunc_def->opaque = NULL; -} - - -void fill_win32_filefunc64A(zlib_filefunc64_def* pzlib_filefunc_def) -{ - pzlib_filefunc_def->zopen64_file = win32_open64_file_funcA; - pzlib_filefunc_def->zread_file = win32_read_file_func; - pzlib_filefunc_def->zwrite_file = win32_write_file_func; - pzlib_filefunc_def->ztell64_file = win32_tell64_file_func; - pzlib_filefunc_def->zseek64_file = win32_seek64_file_func; - pzlib_filefunc_def->zclose_file = win32_close_file_func; - pzlib_filefunc_def->zerror_file = win32_error_file_func; - pzlib_filefunc_def->opaque = NULL; -} - - -void fill_win32_filefunc64W(zlib_filefunc64_def* pzlib_filefunc_def) -{ - pzlib_filefunc_def->zopen64_file = win32_open64_file_funcW; - pzlib_filefunc_def->zread_file = win32_read_file_func; - pzlib_filefunc_def->zwrite_file = win32_write_file_func; - pzlib_filefunc_def->ztell64_file = win32_tell64_file_func; - pzlib_filefunc_def->zseek64_file = win32_seek64_file_func; - pzlib_filefunc_def->zclose_file = win32_close_file_func; - pzlib_filefunc_def->zerror_file = win32_error_file_func; - pzlib_filefunc_def->opaque = NULL; -} diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/iowin32.h b/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/iowin32.h deleted file mode 100644 index 0ca0969a7d0..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/iowin32.h +++ /dev/null @@ -1,28 +0,0 @@ -/* iowin32.h -- IO base function header for compress/uncompress .zip - Version 1.1, February 14h, 2010 - part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) - - Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) - - Modifications for Zip64 support - Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) - - For more info read MiniZip_info.txt - -*/ - -#include - - -#ifdef __cplusplus -extern "C" { -#endif - -void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); -void fill_win32_filefunc64 OF((zlib_filefunc64_def* pzlib_filefunc_def)); -void fill_win32_filefunc64A OF((zlib_filefunc64_def* pzlib_filefunc_def)); -void fill_win32_filefunc64W OF((zlib_filefunc64_def* pzlib_filefunc_def)); - -#ifdef __cplusplus -} -#endif diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/make_vms.com b/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/make_vms.com deleted file mode 100644 index 9ac13a98fa5..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/make_vms.com +++ /dev/null @@ -1,25 +0,0 @@ -$ if f$search("ioapi.h_orig") .eqs. "" then copy ioapi.h ioapi.h_orig -$ open/write zdef vmsdefs.h -$ copy sys$input: zdef -$ deck -#define unix -#define fill_zlib_filefunc64_32_def_from_filefunc32 fillzffunc64from -#define Write_Zip64EndOfCentralDirectoryLocator Write_Zip64EoDLocator -#define Write_Zip64EndOfCentralDirectoryRecord Write_Zip64EoDRecord -#define Write_EndOfCentralDirectoryRecord Write_EoDRecord -$ eod -$ close zdef -$ copy vmsdefs.h,ioapi.h_orig ioapi.h -$ cc/include=[--]/prefix=all ioapi.c -$ cc/include=[--]/prefix=all miniunz.c -$ cc/include=[--]/prefix=all unzip.c -$ cc/include=[--]/prefix=all minizip.c -$ cc/include=[--]/prefix=all zip.c -$ link miniunz,unzip,ioapi,[--]libz.olb/lib -$ link minizip,zip,ioapi,[--]libz.olb/lib -$ mcr []minizip test minizip_info.txt -$ mcr []miniunz -l test.zip -$ rename minizip_info.txt; minizip_info.txt_old -$ mcr []miniunz test.zip -$ delete test.zip;* -$exit diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/miniunz.c b/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/miniunz.c deleted file mode 100644 index 3d65401be5c..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/miniunz.c +++ /dev/null @@ -1,660 +0,0 @@ -/* - miniunz.c - Version 1.1, February 14h, 2010 - sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) - - Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) - - Modifications of Unzip for Zip64 - Copyright (C) 2007-2008 Even Rouault - - Modifications for Zip64 support on both zip and unzip - Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) -*/ - -#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__)) - #ifndef __USE_FILE_OFFSET64 - #define __USE_FILE_OFFSET64 - #endif - #ifndef __USE_LARGEFILE64 - #define __USE_LARGEFILE64 - #endif - #ifndef _LARGEFILE64_SOURCE - #define _LARGEFILE64_SOURCE - #endif - #ifndef _FILE_OFFSET_BIT - #define _FILE_OFFSET_BIT 64 - #endif -#endif - -#ifdef __APPLE__ -// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions -#define FOPEN_FUNC(filename, mode) fopen(filename, mode) -#define FTELLO_FUNC(stream) ftello(stream) -#define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin) -#else -#define FOPEN_FUNC(filename, mode) fopen64(filename, mode) -#define FTELLO_FUNC(stream) ftello64(stream) -#define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin) -#endif - - -#include -#include -#include -#include -#include -#include - -#ifdef _WIN32 -# include -# include -#else -# include -# include -#endif - - -#include "unzip.h" - -#define CASESENSITIVITY (0) -#define WRITEBUFFERSIZE (8192) -#define MAXFILENAME (256) - -#ifdef _WIN32 -#define USEWIN32IOAPI -#include "iowin32.h" -#endif -/* - mini unzip, demo of unzip package - - usage : - Usage : miniunz [-exvlo] file.zip [file_to_extract] [-d extractdir] - - list the file in the zipfile, and print the content of FILE_ID.ZIP or README.TXT - if it exists -*/ - - -/* change_file_date : change the date/time of a file - filename : the filename of the file where date/time must be modified - dosdate : the new date at the MSDos format (4 bytes) - tmu_date : the SAME new date at the tm_unz format */ -void change_file_date(filename,dosdate,tmu_date) - const char *filename; - uLong dosdate; - tm_unz tmu_date; -{ -#ifdef _WIN32 - HANDLE hFile; - FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite; - - hFile = CreateFileA(filename,GENERIC_READ | GENERIC_WRITE, - 0,NULL,OPEN_EXISTING,0,NULL); - GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite); - DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal); - LocalFileTimeToFileTime(&ftLocal,&ftm); - SetFileTime(hFile,&ftm,&ftLastAcc,&ftm); - CloseHandle(hFile); -#else -#ifdef unix || __APPLE__ - struct utimbuf ut; - struct tm newdate; - newdate.tm_sec = tmu_date.tm_sec; - newdate.tm_min=tmu_date.tm_min; - newdate.tm_hour=tmu_date.tm_hour; - newdate.tm_mday=tmu_date.tm_mday; - newdate.tm_mon=tmu_date.tm_mon; - if (tmu_date.tm_year > 1900) - newdate.tm_year=tmu_date.tm_year - 1900; - else - newdate.tm_year=tmu_date.tm_year ; - newdate.tm_isdst=-1; - - ut.actime=ut.modtime=mktime(&newdate); - utime(filename,&ut); -#endif -#endif -} - - -/* mymkdir and change_file_date are not 100 % portable - As I don't know well Unix, I wait feedback for the unix portion */ - -int mymkdir(dirname) - const char* dirname; -{ - int ret=0; -#ifdef _WIN32 - ret = _mkdir(dirname); -#elif unix - ret = mkdir (dirname,0775); -#elif __APPLE__ - ret = mkdir (dirname,0775); -#endif - return ret; -} - -int makedir (newdir) - char *newdir; -{ - char *buffer ; - char *p; - int len = (int)strlen(newdir); - - if (len <= 0) - return 0; - - buffer = (char*)malloc(len+1); - if (buffer==NULL) - { - printf("Error allocating memory\n"); - return UNZ_INTERNALERROR; - } - strcpy(buffer,newdir); - - if (buffer[len-1] == '/') { - buffer[len-1] = '\0'; - } - if (mymkdir(buffer) == 0) - { - free(buffer); - return 1; - } - - p = buffer+1; - while (1) - { - char hold; - - while(*p && *p != '\\' && *p != '/') - p++; - hold = *p; - *p = 0; - if ((mymkdir(buffer) == -1) && (errno == ENOENT)) - { - printf("couldn't create directory %s\n",buffer); - free(buffer); - return 0; - } - if (hold == 0) - break; - *p++ = hold; - } - free(buffer); - return 1; -} - -void do_banner() -{ - printf("MiniUnz 1.01b, demo of zLib + Unz package written by Gilles Vollant\n"); - printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n"); -} - -void do_help() -{ - printf("Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [file_to_extr.] [-d extractdir]\n\n" \ - " -e Extract without pathname (junk paths)\n" \ - " -x Extract with pathname\n" \ - " -v list files\n" \ - " -l list files\n" \ - " -d directory to extract into\n" \ - " -o overwrite files without prompting\n" \ - " -p extract crypted file using password\n\n"); -} - -void Display64BitsSize(ZPOS64_T n, int size_char) -{ - /* to avoid compatibility problem , we do here the conversion */ - char number[21]; - int offset=19; - int pos_string = 19; - number[20]=0; - for (;;) { - number[offset]=(char)((n%10)+'0'); - if (number[offset] != '0') - pos_string=offset; - n/=10; - if (offset==0) - break; - offset--; - } - { - int size_display_string = 19-pos_string; - while (size_char > size_display_string) - { - size_char--; - printf(" "); - } - } - - printf("%s",&number[pos_string]); -} - -int do_list(uf) - unzFile uf; -{ - uLong i; - unz_global_info64 gi; - int err; - - err = unzGetGlobalInfo64(uf,&gi); - if (err!=UNZ_OK) - printf("error %d with zipfile in unzGetGlobalInfo \n",err); - printf(" Length Method Size Ratio Date Time CRC-32 Name\n"); - printf(" ------ ------ ---- ----- ---- ---- ------ ----\n"); - for (i=0;i0) - ratio = (uLong)((file_info.compressed_size*100)/file_info.uncompressed_size); - - /* display a '*' if the file is crypted */ - if ((file_info.flag & 1) != 0) - charCrypt='*'; - - if (file_info.compression_method==0) - string_method="Stored"; - else - if (file_info.compression_method==Z_DEFLATED) - { - uInt iLevel=(uInt)((file_info.flag & 0x6)/2); - if (iLevel==0) - string_method="Defl:N"; - else if (iLevel==1) - string_method="Defl:X"; - else if ((iLevel==2) || (iLevel==3)) - string_method="Defl:F"; /* 2:fast , 3 : extra fast*/ - } - else - if (file_info.compression_method==Z_BZIP2ED) - { - string_method="BZip2 "; - } - else - string_method="Unkn. "; - - Display64BitsSize(file_info.uncompressed_size,7); - printf(" %6s%c",string_method,charCrypt); - Display64BitsSize(file_info.compressed_size,7); - printf(" %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n", - ratio, - (uLong)file_info.tmu_date.tm_mon + 1, - (uLong)file_info.tmu_date.tm_mday, - (uLong)file_info.tmu_date.tm_year % 100, - (uLong)file_info.tmu_date.tm_hour,(uLong)file_info.tmu_date.tm_min, - (uLong)file_info.crc,filename_inzip); - if ((i+1)='a') && (rep<='z')) - rep -= 0x20; - } - while ((rep!='Y') && (rep!='N') && (rep!='A')); - } - - if (rep == 'N') - skip = 1; - - if (rep == 'A') - *popt_overwrite=1; - } - - if ((skip==0) && (err==UNZ_OK)) - { - fout=FOPEN_FUNC(write_filename,"wb"); - /* some zipfile don't contain directory alone before file */ - if ((fout==NULL) && ((*popt_extract_without_path)==0) && - (filename_withoutpath!=(char*)filename_inzip)) - { - char c=*(filename_withoutpath-1); - *(filename_withoutpath-1)='\0'; - makedir(write_filename); - *(filename_withoutpath-1)=c; - fout=FOPEN_FUNC(write_filename,"wb"); - } - - if (fout==NULL) - { - printf("error opening %s\n",write_filename); - } - } - - if (fout!=NULL) - { - printf(" extracting: %s\n",write_filename); - - do - { - err = unzReadCurrentFile(uf,buf,size_buf); - if (err<0) - { - printf("error %d with zipfile in unzReadCurrentFile\n",err); - break; - } - if (err>0) - if (fwrite(buf,err,1,fout)!=1) - { - printf("error in writing extracted file\n"); - err=UNZ_ERRNO; - break; - } - } - while (err>0); - if (fout) - fclose(fout); - - if (err==0) - change_file_date(write_filename,file_info.dosDate, - file_info.tmu_date); - } - - if (err==UNZ_OK) - { - err = unzCloseCurrentFile (uf); - if (err!=UNZ_OK) - { - printf("error %d with zipfile in unzCloseCurrentFile\n",err); - } - } - else - unzCloseCurrentFile(uf); /* don't lose the error */ - } - - free(buf); - return err; -} - - -int do_extract(uf,opt_extract_without_path,opt_overwrite,password) - unzFile uf; - int opt_extract_without_path; - int opt_overwrite; - const char* password; -{ - uLong i; - unz_global_info64 gi; - int err; - FILE* fout=NULL; - - err = unzGetGlobalInfo64(uf,&gi); - if (err!=UNZ_OK) - printf("error %d with zipfile in unzGetGlobalInfo \n",err); - - for (i=0;i insert n+1 empty lines -.\" for manpage-specific macros, see man(7) -.SH NAME -miniunzip - uncompress and examine ZIP archives -.SH SYNOPSIS -.B miniunzip -.RI [ -exvlo ] -zipfile [ files_to_extract ] [-d tempdir] -.SH DESCRIPTION -.B minizip -is a simple tool which allows the extraction of compressed file -archives in the ZIP format used by the MS-DOS utility PKZIP. It was -written as a demonstration of the -.IR zlib (3) -library and therefore lack many of the features of the -.IR unzip (1) -program. -.SH OPTIONS -A number of options are supported. With the exception of -.BI \-d\ tempdir -these must be supplied before any -other arguments and are: -.TP -.BI \-l\ ,\ \-\-v -List the files in the archive without extracting them. -.TP -.B \-o -Overwrite files without prompting for confirmation. -.TP -.B \-x -Extract files (default). -.PP -The -.I zipfile -argument is the name of the archive to process. The next argument can be used -to specify a single file to extract from the archive. - -Lastly, the following option can be specified at the end of the command-line: -.TP -.BI \-d\ tempdir -Extract the archive in the directory -.I tempdir -rather than the current directory. -.SH SEE ALSO -.BR minizip (1), -.BR zlib (3), -.BR unzip (1). -.SH AUTHOR -This program was written by Gilles Vollant. This manual page was -written by Mark Brown . The -d tempdir option -was added by Dirk Eddelbuettel . diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/minizip.1 b/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/minizip.1 deleted file mode 100644 index 1154484c1cc..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/minizip.1 +++ /dev/null @@ -1,46 +0,0 @@ -.\" Hey, EMACS: -*- nroff -*- -.TH minizip 1 "May 2, 2001" -.\" Please adjust this date whenever revising the manpage. -.\" -.\" Some roff macros, for reference: -.\" .nh disable hyphenation -.\" .hy enable hyphenation -.\" .ad l left justify -.\" .ad b justify to both left and right margins -.\" .nf disable filling -.\" .fi enable filling -.\" .br insert line break -.\" .sp insert n+1 empty lines -.\" for manpage-specific macros, see man(7) -.SH NAME -minizip - create ZIP archives -.SH SYNOPSIS -.B minizip -.RI [ -o ] -zipfile [ " files" ... ] -.SH DESCRIPTION -.B minizip -is a simple tool which allows the creation of compressed file archives -in the ZIP format used by the MS-DOS utility PKZIP. It was written as -a demonstration of the -.IR zlib (3) -library and therefore lack many of the features of the -.IR zip (1) -program. -.SH OPTIONS -The first argument supplied is the name of the ZIP archive to create or -.RI -o -in which case it is ignored and the second argument treated as the -name of the ZIP file. If the ZIP file already exists it will be -overwritten. -.PP -Subsequent arguments specify a list of files to place in the ZIP -archive. If none are specified then an empty archive will be created. -.SH SEE ALSO -.BR miniunzip (1), -.BR zlib (3), -.BR zip (1). -.SH AUTHOR -This program was written by Gilles Vollant. This manual page was -written by Mark Brown . - diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/minizip.c b/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/minizip.c deleted file mode 100644 index 4288962ecef..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/minizip.c +++ /dev/null @@ -1,520 +0,0 @@ -/* - minizip.c - Version 1.1, February 14h, 2010 - sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) - - Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) - - Modifications of Unzip for Zip64 - Copyright (C) 2007-2008 Even Rouault - - Modifications for Zip64 support on both zip and unzip - Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) -*/ - - -#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__)) - #ifndef __USE_FILE_OFFSET64 - #define __USE_FILE_OFFSET64 - #endif - #ifndef __USE_LARGEFILE64 - #define __USE_LARGEFILE64 - #endif - #ifndef _LARGEFILE64_SOURCE - #define _LARGEFILE64_SOURCE - #endif - #ifndef _FILE_OFFSET_BIT - #define _FILE_OFFSET_BIT 64 - #endif -#endif - -#ifdef __APPLE__ -// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions -#define FOPEN_FUNC(filename, mode) fopen(filename, mode) -#define FTELLO_FUNC(stream) ftello(stream) -#define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin) -#else -#define FOPEN_FUNC(filename, mode) fopen64(filename, mode) -#define FTELLO_FUNC(stream) ftello64(stream) -#define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin) -#endif - - - -#include -#include -#include -#include -#include -#include - -#ifdef _WIN32 -# include -# include -#else -# include -# include -# include -# include -#endif - -#include "zip.h" - -#ifdef _WIN32 - #define USEWIN32IOAPI - #include "iowin32.h" -#endif - - - -#define WRITEBUFFERSIZE (16384) -#define MAXFILENAME (256) - -#ifdef _WIN32 -uLong filetime(f, tmzip, dt) - char *f; /* name of file to get info on */ - tm_zip *tmzip; /* return value: access, modific. and creation times */ - uLong *dt; /* dostime */ -{ - int ret = 0; - { - FILETIME ftLocal; - HANDLE hFind; - WIN32_FIND_DATAA ff32; - - hFind = FindFirstFileA(f,&ff32); - if (hFind != INVALID_HANDLE_VALUE) - { - FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal); - FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0); - FindClose(hFind); - ret = 1; - } - } - return ret; -} -#else -#ifdef unix || __APPLE__ -uLong filetime(f, tmzip, dt) - char *f; /* name of file to get info on */ - tm_zip *tmzip; /* return value: access, modific. and creation times */ - uLong *dt; /* dostime */ -{ - int ret=0; - struct stat s; /* results of stat() */ - struct tm* filedate; - time_t tm_t=0; - - if (strcmp(f,"-")!=0) - { - char name[MAXFILENAME+1]; - int len = strlen(f); - if (len > MAXFILENAME) - len = MAXFILENAME; - - strncpy(name, f,MAXFILENAME-1); - /* strncpy doesnt append the trailing NULL, of the string is too long. */ - name[ MAXFILENAME ] = '\0'; - - if (name[len - 1] == '/') - name[len - 1] = '\0'; - /* not all systems allow stat'ing a file with / appended */ - if (stat(name,&s)==0) - { - tm_t = s.st_mtime; - ret = 1; - } - } - filedate = localtime(&tm_t); - - tmzip->tm_sec = filedate->tm_sec; - tmzip->tm_min = filedate->tm_min; - tmzip->tm_hour = filedate->tm_hour; - tmzip->tm_mday = filedate->tm_mday; - tmzip->tm_mon = filedate->tm_mon ; - tmzip->tm_year = filedate->tm_year; - - return ret; -} -#else -uLong filetime(f, tmzip, dt) - char *f; /* name of file to get info on */ - tm_zip *tmzip; /* return value: access, modific. and creation times */ - uLong *dt; /* dostime */ -{ - return 0; -} -#endif -#endif - - - - -int check_exist_file(filename) - const char* filename; -{ - FILE* ftestexist; - int ret = 1; - ftestexist = FOPEN_FUNC(filename,"rb"); - if (ftestexist==NULL) - ret = 0; - else - fclose(ftestexist); - return ret; -} - -void do_banner() -{ - printf("MiniZip 1.1, demo of zLib + MiniZip64 package, written by Gilles Vollant\n"); - printf("more info on MiniZip at http://www.winimage.com/zLibDll/minizip.html\n\n"); -} - -void do_help() -{ - printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] [-j] file.zip [files_to_add]\n\n" \ - " -o Overwrite existing file.zip\n" \ - " -a Append to existing file.zip\n" \ - " -0 Store only\n" \ - " -1 Compress faster\n" \ - " -9 Compress better\n\n" \ - " -j exclude path. store only the file name.\n\n"); -} - -/* calculate the CRC32 of a file, - because to encrypt a file, we need known the CRC32 of the file before */ -int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigned long* result_crc) -{ - unsigned long calculate_crc=0; - int err=ZIP_OK; - FILE * fin = FOPEN_FUNC(filenameinzip,"rb"); - - unsigned long size_read = 0; - unsigned long total_read = 0; - if (fin==NULL) - { - err = ZIP_ERRNO; - } - - if (err == ZIP_OK) - do - { - err = ZIP_OK; - size_read = (int)fread(buf,1,size_buf,fin); - if (size_read < size_buf) - if (feof(fin)==0) - { - printf("error in reading %s\n",filenameinzip); - err = ZIP_ERRNO; - } - - if (size_read>0) - calculate_crc = crc32(calculate_crc,buf,size_read); - total_read += size_read; - - } while ((err == ZIP_OK) && (size_read>0)); - - if (fin) - fclose(fin); - - *result_crc=calculate_crc; - printf("file %s crc %lx\n", filenameinzip, calculate_crc); - return err; -} - -int isLargeFile(const char* filename) -{ - int largeFile = 0; - ZPOS64_T pos = 0; - FILE* pFile = FOPEN_FUNC(filename, "rb"); - - if(pFile != NULL) - { - int n = FSEEKO_FUNC(pFile, 0, SEEK_END); - pos = FTELLO_FUNC(pFile); - - printf("File : %s is %lld bytes\n", filename, pos); - - if(pos >= 0xffffffff) - largeFile = 1; - - fclose(pFile); - } - - return largeFile; -} - -int main(argc,argv) - int argc; - char *argv[]; -{ - int i; - int opt_overwrite=0; - int opt_compress_level=Z_DEFAULT_COMPRESSION; - int opt_exclude_path=0; - int zipfilenamearg = 0; - char filename_try[MAXFILENAME+16]; - int zipok; - int err=0; - int size_buf=0; - void* buf=NULL; - const char* password=NULL; - - - do_banner(); - if (argc==1) - { - do_help(); - return 0; - } - else - { - for (i=1;i='0') && (c<='9')) - opt_compress_level = c-'0'; - if ((c=='j') || (c=='J')) - opt_exclude_path = 1; - - if (((c=='p') || (c=='P')) && (i+1='a') && (rep<='z')) - rep -= 0x20; - } - while ((rep!='Y') && (rep!='N') && (rep!='A')); - if (rep=='N') - zipok = 0; - if (rep=='A') - opt_overwrite = 2; - } - } - - if (zipok==1) - { - zipFile zf; - int errclose; -# ifdef USEWIN32IOAPI - zlib_filefunc64_def ffunc; - fill_win32_filefunc64A(&ffunc); - zf = zipOpen2_64(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc); -# else - zf = zipOpen64(filename_try,(opt_overwrite==2) ? 2 : 0); -# endif - - if (zf == NULL) - { - printf("error opening %s\n",filename_try); - err= ZIP_ERRNO; - } - else - printf("creating %s\n",filename_try); - - for (i=zipfilenamearg+1;(i='0') || (argv[i][1]<='9'))) && - (strlen(argv[i]) == 2))) - { - FILE * fin; - int size_read; - const char* filenameinzip = argv[i]; - const char *savefilenameinzip; - zip_fileinfo zi; - unsigned long crcFile=0; - int zip64 = 0; - - zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour = - zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0; - zi.dosDate = 0; - zi.internal_fa = 0; - zi.external_fa = 0; - filetime(filenameinzip,&zi.tmz_date,&zi.dosDate); - -/* - err = zipOpenNewFileInZip(zf,filenameinzip,&zi, - NULL,0,NULL,0,NULL / * comment * /, - (opt_compress_level != 0) ? Z_DEFLATED : 0, - opt_compress_level); -*/ - if ((password != NULL) && (err==ZIP_OK)) - err = getFileCrc(filenameinzip,buf,size_buf,&crcFile); - - zip64 = isLargeFile(filenameinzip); - - /* The path name saved, should not include a leading slash. */ - /*if it did, windows/xp and dynazip couldn't read the zip file. */ - savefilenameinzip = filenameinzip; - while( savefilenameinzip[0] == '\\' || savefilenameinzip[0] == '/' ) - { - savefilenameinzip++; - } - - /*should the zip file contain any path at all?*/ - if( opt_exclude_path ) - { - const char *tmpptr; - const char *lastslash = 0; - for( tmpptr = savefilenameinzip; *tmpptr; tmpptr++) - { - if( *tmpptr == '\\' || *tmpptr == '/') - { - lastslash = tmpptr; - } - } - if( lastslash != NULL ) - { - savefilenameinzip = lastslash+1; // base filename follows last slash. - } - } - - /**/ - err = zipOpenNewFileInZip3_64(zf,savefilenameinzip,&zi, - NULL,0,NULL,0,NULL /* comment*/, - (opt_compress_level != 0) ? Z_DEFLATED : 0, - opt_compress_level,0, - /* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */ - -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, - password,crcFile, zip64); - - if (err != ZIP_OK) - printf("error in opening %s in zipfile\n",filenameinzip); - else - { - fin = FOPEN_FUNC(filenameinzip,"rb"); - if (fin==NULL) - { - err=ZIP_ERRNO; - printf("error in opening %s for reading\n",filenameinzip); - } - } - - if (err == ZIP_OK) - do - { - err = ZIP_OK; - size_read = (int)fread(buf,1,size_buf,fin); - if (size_read < size_buf) - if (feof(fin)==0) - { - printf("error in reading %s\n",filenameinzip); - err = ZIP_ERRNO; - } - - if (size_read>0) - { - err = zipWriteInFileInZip (zf,buf,size_read); - if (err<0) - { - printf("error in writing %s in the zipfile\n", - filenameinzip); - } - - } - } while ((err == ZIP_OK) && (size_read>0)); - - if (fin) - fclose(fin); - - if (err<0) - err=ZIP_ERRNO; - else - { - err = zipCloseFileInZip(zf); - if (err!=ZIP_OK) - printf("error in closing %s in the zipfile\n", - filenameinzip); - } - } - } - errclose = zipClose(zf,NULL); - if (errclose != ZIP_OK) - printf("error in closing %s\n",filename_try); - } - else - { - do_help(); - } - - free(buf); - return 0; -} diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/minizip.pc.in b/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/minizip.pc.in deleted file mode 100644 index 69b5b7fdcb3..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/minizip.pc.in +++ /dev/null @@ -1,12 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@/minizip - -Name: minizip -Description: Minizip zip file manipulation library -Requires: -Version: @PACKAGE_VERSION@ -Libs: -L${libdir} -lminizip -Libs.private: -lz -Cflags: -I${includedir} diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/mztools.c b/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/mztools.c deleted file mode 100644 index 96891c2e0b7..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/mztools.c +++ /dev/null @@ -1,291 +0,0 @@ -/* - Additional tools for Minizip - Code: Xavier Roche '2004 - License: Same as ZLIB (www.gzip.org) -*/ - -/* Code */ -#include -#include -#include -#include "zlib.h" -#include "unzip.h" - -#define READ_8(adr) ((unsigned char)*(adr)) -#define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) ) -#define READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) ) - -#define WRITE_8(buff, n) do { \ - *((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \ -} while(0) -#define WRITE_16(buff, n) do { \ - WRITE_8((unsigned char*)(buff), n); \ - WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \ -} while(0) -#define WRITE_32(buff, n) do { \ - WRITE_16((unsigned char*)(buff), (n) & 0xffff); \ - WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \ -} while(0) - -extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered) -const char* file; -const char* fileOut; -const char* fileOutTmp; -uLong* nRecovered; -uLong* bytesRecovered; -{ - int err = Z_OK; - FILE* fpZip = fopen(file, "rb"); - FILE* fpOut = fopen(fileOut, "wb"); - FILE* fpOutCD = fopen(fileOutTmp, "wb"); - if (fpZip != NULL && fpOut != NULL) { - int entries = 0; - uLong totalBytes = 0; - char header[30]; - char filename[1024]; - char extra[1024]; - int offset = 0; - int offsetCD = 0; - while ( fread(header, 1, 30, fpZip) == 30 ) { - int currentOffset = offset; - - /* File entry */ - if (READ_32(header) == 0x04034b50) { - unsigned int version = READ_16(header + 4); - unsigned int gpflag = READ_16(header + 6); - unsigned int method = READ_16(header + 8); - unsigned int filetime = READ_16(header + 10); - unsigned int filedate = READ_16(header + 12); - unsigned int crc = READ_32(header + 14); /* crc */ - unsigned int cpsize = READ_32(header + 18); /* compressed size */ - unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */ - unsigned int fnsize = READ_16(header + 26); /* file name length */ - unsigned int extsize = READ_16(header + 28); /* extra field length */ - filename[0] = extra[0] = '\0'; - - /* Header */ - if (fwrite(header, 1, 30, fpOut) == 30) { - offset += 30; - } else { - err = Z_ERRNO; - break; - } - - /* Filename */ - if (fnsize > 0) { - if (fnsize < sizeof(filename)) { - if (fread(filename, 1, fnsize, fpZip) == fnsize) { - if (fwrite(filename, 1, fnsize, fpOut) == fnsize) { - offset += fnsize; - } else { - err = Z_ERRNO; - break; - } - } else { - err = Z_ERRNO; - break; - } - } else { - err = Z_ERRNO; - break; - } - } else { - err = Z_STREAM_ERROR; - break; - } - - /* Extra field */ - if (extsize > 0) { - if (extsize < sizeof(extra)) { - if (fread(extra, 1, extsize, fpZip) == extsize) { - if (fwrite(extra, 1, extsize, fpOut) == extsize) { - offset += extsize; - } else { - err = Z_ERRNO; - break; - } - } else { - err = Z_ERRNO; - break; - } - } else { - err = Z_ERRNO; - break; - } - } - - /* Data */ - { - int dataSize = cpsize; - if (dataSize == 0) { - dataSize = uncpsize; - } - if (dataSize > 0) { - char* data = malloc(dataSize); - if (data != NULL) { - if ((int)fread(data, 1, dataSize, fpZip) == dataSize) { - if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) { - offset += dataSize; - totalBytes += dataSize; - } else { - err = Z_ERRNO; - } - } else { - err = Z_ERRNO; - } - free(data); - if (err != Z_OK) { - break; - } - } else { - err = Z_MEM_ERROR; - break; - } - } - } - - /* Central directory entry */ - { - char header[46]; - char* comment = ""; - int comsize = (int) strlen(comment); - WRITE_32(header, 0x02014b50); - WRITE_16(header + 4, version); - WRITE_16(header + 6, version); - WRITE_16(header + 8, gpflag); - WRITE_16(header + 10, method); - WRITE_16(header + 12, filetime); - WRITE_16(header + 14, filedate); - WRITE_32(header + 16, crc); - WRITE_32(header + 20, cpsize); - WRITE_32(header + 24, uncpsize); - WRITE_16(header + 28, fnsize); - WRITE_16(header + 30, extsize); - WRITE_16(header + 32, comsize); - WRITE_16(header + 34, 0); /* disk # */ - WRITE_16(header + 36, 0); /* int attrb */ - WRITE_32(header + 38, 0); /* ext attrb */ - WRITE_32(header + 42, currentOffset); - /* Header */ - if (fwrite(header, 1, 46, fpOutCD) == 46) { - offsetCD += 46; - - /* Filename */ - if (fnsize > 0) { - if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) { - offsetCD += fnsize; - } else { - err = Z_ERRNO; - break; - } - } else { - err = Z_STREAM_ERROR; - break; - } - - /* Extra field */ - if (extsize > 0) { - if (fwrite(extra, 1, extsize, fpOutCD) == extsize) { - offsetCD += extsize; - } else { - err = Z_ERRNO; - break; - } - } - - /* Comment field */ - if (comsize > 0) { - if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) { - offsetCD += comsize; - } else { - err = Z_ERRNO; - break; - } - } - - - } else { - err = Z_ERRNO; - break; - } - } - - /* Success */ - entries++; - - } else { - break; - } - } - - /* Final central directory */ - { - int entriesZip = entries; - char header[22]; - char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools"; - int comsize = (int) strlen(comment); - if (entriesZip > 0xffff) { - entriesZip = 0xffff; - } - WRITE_32(header, 0x06054b50); - WRITE_16(header + 4, 0); /* disk # */ - WRITE_16(header + 6, 0); /* disk # */ - WRITE_16(header + 8, entriesZip); /* hack */ - WRITE_16(header + 10, entriesZip); /* hack */ - WRITE_32(header + 12, offsetCD); /* size of CD */ - WRITE_32(header + 16, offset); /* offset to CD */ - WRITE_16(header + 20, comsize); /* comment */ - - /* Header */ - if (fwrite(header, 1, 22, fpOutCD) == 22) { - - /* Comment field */ - if (comsize > 0) { - if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) { - err = Z_ERRNO; - } - } - - } else { - err = Z_ERRNO; - } - } - - /* Final merge (file + central directory) */ - fclose(fpOutCD); - if (err == Z_OK) { - fpOutCD = fopen(fileOutTmp, "rb"); - if (fpOutCD != NULL) { - int nRead; - char buffer[8192]; - while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) { - if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) { - err = Z_ERRNO; - break; - } - } - fclose(fpOutCD); - } - } - - /* Close */ - fclose(fpZip); - fclose(fpOut); - - /* Wipe temporary file */ - (void)remove(fileOutTmp); - - /* Number of recovered entries */ - if (err == Z_OK) { - if (nRecovered != NULL) { - *nRecovered = entries; - } - if (bytesRecovered != NULL) { - *bytesRecovered = totalBytes; - } - } - } else { - err = Z_STREAM_ERROR; - } - return err; -} diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/mztools.h b/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/mztools.h deleted file mode 100644 index a49a426ec2f..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/mztools.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - Additional tools for Minizip - Code: Xavier Roche '2004 - License: Same as ZLIB (www.gzip.org) -*/ - -#ifndef _zip_tools_H -#define _zip_tools_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _ZLIB_H -#include "zlib.h" -#endif - -#include "unzip.h" - -/* Repair a ZIP file (missing central directory) - file: file to recover - fileOut: output file after recovery - fileOutTmp: temporary file name used for recovery -*/ -extern int ZEXPORT unzRepair(const char* file, - const char* fileOut, - const char* fileOutTmp, - uLong* nRecovered, - uLong* bytesRecovered); - - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/unzip.c b/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/unzip.c deleted file mode 100644 index 909350435a5..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/unzip.c +++ /dev/null @@ -1,2125 +0,0 @@ -/* unzip.c -- IO for uncompress .zip files using zlib - Version 1.1, February 14h, 2010 - part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) - - Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) - - Modifications of Unzip for Zip64 - Copyright (C) 2007-2008 Even Rouault - - Modifications for Zip64 support on both zip and unzip - Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) - - For more info read MiniZip_info.txt - - - ------------------------------------------------------------------------------------ - Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of - compatibility with older software. The following is from the original crypt.c. - Code woven in by Terry Thorsen 1/2003. - - Copyright (c) 1990-2000 Info-ZIP. All rights reserved. - - See the accompanying file LICENSE, version 2000-Apr-09 or later - (the contents of which are also included in zip.h) for terms of use. - If, for some reason, all these files are missing, the Info-ZIP license - also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html - - crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h] - - The encryption/decryption parts of this source code (as opposed to the - non-echoing password parts) were originally written in Europe. The - whole source package can be freely distributed, including from the USA. - (Prior to January 2000, re-export from the US was a violation of US law.) - - This encryption code is a direct transcription of the algorithm from - Roger Schlafly, described by Phil Katz in the file appnote.txt. This - file (appnote.txt) is distributed with the PKZIP program (even in the - version without encryption capabilities). - - ------------------------------------------------------------------------------------ - - Changes in unzip.c - - 2007-2008 - Even Rouault - Addition of cpl_unzGetCurrentFileZStreamPos - 2007-2008 - Even Rouault - Decoration of symbol names unz* -> cpl_unz* - 2007-2008 - Even Rouault - Remove old C style function prototypes - 2007-2008 - Even Rouault - Add unzip support for ZIP64 - - Copyright (C) 2007-2008 Even Rouault - - - Oct-2009 - Mathias Svensson - Removed cpl_* from symbol names (Even Rouault added them but since this is now moved to a new project (minizip64) I renamed them again). - Oct-2009 - Mathias Svensson - Fixed problem if uncompressed size was > 4G and compressed size was <4G - should only read the compressed/uncompressed size from the Zip64 format if - the size from normal header was 0xFFFFFFFF - Oct-2009 - Mathias Svensson - Applied some bug fixes from paches recived from Gilles Vollant - Oct-2009 - Mathias Svensson - Applied support to unzip files with compression mathod BZIP2 (bzip2 lib is required) - Patch created by Daniel Borca - - Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer - - Copyright (C) 1998 - 2010 Gilles Vollant, Even Rouault, Mathias Svensson - -*/ - - -#include -#include -#include - -#ifndef NOUNCRYPT - #define NOUNCRYPT -#endif - -#include "zlib.h" -#include "unzip.h" - -#ifdef STDC -# include -# include -# include -#endif -#ifdef NO_ERRNO_H - extern int errno; -#else -# include -#endif - - -#ifndef local -# define local static -#endif -/* compile with -Dlocal if your debugger can't find static symbols */ - - -#ifndef CASESENSITIVITYDEFAULT_NO -# if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) -# define CASESENSITIVITYDEFAULT_NO -# endif -#endif - - -#ifndef UNZ_BUFSIZE -#define UNZ_BUFSIZE (16384) -#endif - -#ifndef UNZ_MAXFILENAMEINZIP -#define UNZ_MAXFILENAMEINZIP (256) -#endif - -#ifndef ALLOC -# define ALLOC(size) (malloc(size)) -#endif -#ifndef TRYFREE -# define TRYFREE(p) {if (p) free(p);} -#endif - -#define SIZECENTRALDIRITEM (0x2e) -#define SIZEZIPLOCALHEADER (0x1e) - - -const char unz_copyright[] = - " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; - -/* unz_file_info_interntal contain internal info about a file in zipfile*/ -typedef struct unz_file_info64_internal_s -{ - ZPOS64_T offset_curfile;/* relative offset of local header 8 bytes */ -} unz_file_info64_internal; - - -/* file_in_zip_read_info_s contain internal information about a file in zipfile, - when reading and decompress it */ -typedef struct -{ - char *read_buffer; /* internal buffer for compressed data */ - z_stream stream; /* zLib stream structure for inflate */ - -#ifdef HAVE_BZIP2 - bz_stream bstream; /* bzLib stream structure for bziped */ -#endif - - ZPOS64_T pos_in_zipfile; /* position in byte on the zipfile, for fseek*/ - uLong stream_initialised; /* flag set if stream structure is initialised*/ - - ZPOS64_T offset_local_extrafield;/* offset of the local extra field */ - uInt size_local_extrafield;/* size of the local extra field */ - ZPOS64_T pos_local_extrafield; /* position in the local extra field in read*/ - ZPOS64_T total_out_64; - - uLong crc32; /* crc32 of all data uncompressed */ - uLong crc32_wait; /* crc32 we must obtain after decompress all */ - ZPOS64_T rest_read_compressed; /* number of byte to be decompressed */ - ZPOS64_T rest_read_uncompressed;/*number of byte to be obtained after decomp*/ - zlib_filefunc64_32_def z_filefunc; - voidpf filestream; /* io structore of the zipfile */ - uLong compression_method; /* compression method (0==store) */ - ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ - int raw; -} file_in_zip64_read_info_s; - - -/* unz64_s contain internal information about the zipfile -*/ -typedef struct -{ - zlib_filefunc64_32_def z_filefunc; - int is64bitOpenFunction; - voidpf filestream; /* io structore of the zipfile */ - unz_global_info64 gi; /* public global information */ - ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ - ZPOS64_T num_file; /* number of the current file in the zipfile*/ - ZPOS64_T pos_in_central_dir; /* pos of the current file in the central dir*/ - ZPOS64_T current_file_ok; /* flag about the usability of the current file*/ - ZPOS64_T central_pos; /* position of the beginning of the central dir*/ - - ZPOS64_T size_central_dir; /* size of the central directory */ - ZPOS64_T offset_central_dir; /* offset of start of central directory with - respect to the starting disk number */ - - unz_file_info64 cur_file_info; /* public info about the current file in zip*/ - unz_file_info64_internal cur_file_info_internal; /* private info about it*/ - file_in_zip64_read_info_s* pfile_in_zip_read; /* structure about the current - file if we are decompressing it */ - int encrypted; - - int isZip64; - -# ifndef NOUNCRYPT - unsigned long keys[3]; /* keys defining the pseudo-random sequence */ - const z_crc_t* pcrc_32_tab; -# endif -} unz64_s; - - -#ifndef NOUNCRYPT -#include "crypt.h" -#endif - -/* =========================================================================== - Read a byte from a gz_stream; update next_in and avail_in. Return EOF - for end of file. - IN assertion: the stream s has been sucessfully opened for reading. -*/ - - -local int unz64local_getByte OF(( - const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - int *pi)); - -local int unz64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi) -{ - unsigned char c; - int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1); - if (err==1) - { - *pi = (int)c; - return UNZ_OK; - } - else - { - if (ZERROR64(*pzlib_filefunc_def,filestream)) - return UNZ_ERRNO; - else - return UNZ_EOF; - } -} - - -/* =========================================================================== - Reads a long in LSB order from the given gz_stream. Sets -*/ -local int unz64local_getShort OF(( - const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - uLong *pX)); - -local int unz64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - uLong *pX) -{ - uLong x ; - int i = 0; - int err; - - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x = (uLong)i; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((uLong)i)<<8; - - if (err==UNZ_OK) - *pX = x; - else - *pX = 0; - return err; -} - -local int unz64local_getLong OF(( - const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - uLong *pX)); - -local int unz64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - uLong *pX) -{ - uLong x ; - int i = 0; - int err; - - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x = (uLong)i; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((uLong)i)<<8; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((uLong)i)<<16; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x += ((uLong)i)<<24; - - if (err==UNZ_OK) - *pX = x; - else - *pX = 0; - return err; -} - -local int unz64local_getLong64 OF(( - const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - ZPOS64_T *pX)); - - -local int unz64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream, - ZPOS64_T *pX) -{ - ZPOS64_T x ; - int i = 0; - int err; - - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x = (ZPOS64_T)i; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<8; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<16; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<24; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<32; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<40; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<48; - - if (err==UNZ_OK) - err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); - x |= ((ZPOS64_T)i)<<56; - - if (err==UNZ_OK) - *pX = x; - else - *pX = 0; - return err; -} - -/* My own strcmpi / strcasecmp */ -local int strcmpcasenosensitive_internal (const char* fileName1, const char* fileName2) -{ - for (;;) - { - char c1=*(fileName1++); - char c2=*(fileName2++); - if ((c1>='a') && (c1<='z')) - c1 -= 0x20; - if ((c2>='a') && (c2<='z')) - c2 -= 0x20; - if (c1=='\0') - return ((c2=='\0') ? 0 : -1); - if (c2=='\0') - return 1; - if (c1c2) - return 1; - } -} - - -#ifdef CASESENSITIVITYDEFAULT_NO -#define CASESENSITIVITYDEFAULTVALUE 2 -#else -#define CASESENSITIVITYDEFAULTVALUE 1 -#endif - -#ifndef STRCMPCASENOSENTIVEFUNCTION -#define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal -#endif - -/* - Compare two filename (fileName1,fileName2). - If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) - If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi - or strcasecmp) - If iCaseSenisivity = 0, case sensitivity is defaut of your operating system - (like 1 on Unix, 2 on Windows) - -*/ -extern int ZEXPORT unzStringFileNameCompare (const char* fileName1, - const char* fileName2, - int iCaseSensitivity) - -{ - if (iCaseSensitivity==0) - iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; - - if (iCaseSensitivity==1) - return strcmp(fileName1,fileName2); - - return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2); -} - -#ifndef BUFREADCOMMENT -#define BUFREADCOMMENT (0x400) -#endif - -/* - Locate the Central directory of a zipfile (at the end, just before - the global comment) -*/ -local ZPOS64_T unz64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)); -local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) -{ - unsigned char* buf; - ZPOS64_T uSizeFile; - ZPOS64_T uBackRead; - ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ - ZPOS64_T uPosFound=0; - - if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) - return 0; - - - uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); - - if (uMaxBack>uSizeFile) - uMaxBack = uSizeFile; - - buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); - if (buf==NULL) - return 0; - - uBackRead = 4; - while (uBackReaduMaxBack) - uBackRead = uMaxBack; - else - uBackRead+=BUFREADCOMMENT; - uReadPos = uSizeFile-uBackRead ; - - uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? - (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); - if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) - break; - - if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) - break; - - for (i=(int)uReadSize-3; (i--)>0;) - if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && - ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) - { - uPosFound = uReadPos+i; - break; - } - - if (uPosFound!=0) - break; - } - TRYFREE(buf); - return uPosFound; -} - - -/* - Locate the Central directory 64 of a zipfile (at the end, just before - the global comment) -*/ -local ZPOS64_T unz64local_SearchCentralDir64 OF(( - const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream)); - -local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, - voidpf filestream) -{ - unsigned char* buf; - ZPOS64_T uSizeFile; - ZPOS64_T uBackRead; - ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ - ZPOS64_T uPosFound=0; - uLong uL; - ZPOS64_T relativeOffset; - - if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) - return 0; - - - uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); - - if (uMaxBack>uSizeFile) - uMaxBack = uSizeFile; - - buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); - if (buf==NULL) - return 0; - - uBackRead = 4; - while (uBackReaduMaxBack) - uBackRead = uMaxBack; - else - uBackRead+=BUFREADCOMMENT; - uReadPos = uSizeFile-uBackRead ; - - uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? - (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); - if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) - break; - - if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) - break; - - for (i=(int)uReadSize-3; (i--)>0;) - if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && - ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07)) - { - uPosFound = uReadPos+i; - break; - } - - if (uPosFound!=0) - break; - } - TRYFREE(buf); - if (uPosFound == 0) - return 0; - - /* Zip64 end of central directory locator */ - if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0) - return 0; - - /* the signature, already checked */ - if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) - return 0; - - /* number of the disk with the start of the zip64 end of central directory */ - if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) - return 0; - if (uL != 0) - return 0; - - /* relative offset of the zip64 end of central directory record */ - if (unz64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=UNZ_OK) - return 0; - - /* total number of disks */ - if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) - return 0; - if (uL != 1) - return 0; - - /* Goto end of central directory record */ - if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0) - return 0; - - /* the signature */ - if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) - return 0; - - if (uL != 0x06064b50) - return 0; - - return relativeOffset; -} - -/* - Open a Zip file. path contain the full pathname (by example, - on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer - "zlib/zlib114.zip". - If the zipfile cannot be opened (file doesn't exist or in not valid), the - return value is NULL. - Else, the return value is a unzFile Handle, usable with other function - of this unzip package. -*/ -local unzFile unzOpenInternal (const void *path, - zlib_filefunc64_32_def* pzlib_filefunc64_32_def, - int is64bitOpenFunction) -{ - unz64_s us; - unz64_s *s; - ZPOS64_T central_pos; - uLong uL; - - uLong number_disk; /* number of the current dist, used for - spaning ZIP, unsupported, always 0*/ - uLong number_disk_with_CD; /* number the the disk with central dir, used - for spaning ZIP, unsupported, always 0*/ - ZPOS64_T number_entry_CD; /* total number of entries in - the central dir - (same than number_entry on nospan) */ - - int err=UNZ_OK; - - if (unz_copyright[0]!=' ') - return NULL; - - us.z_filefunc.zseek32_file = NULL; - us.z_filefunc.ztell32_file = NULL; - if (pzlib_filefunc64_32_def==NULL) - fill_fopen64_filefunc(&us.z_filefunc.zfile_func64); - else - us.z_filefunc = *pzlib_filefunc64_32_def; - us.is64bitOpenFunction = is64bitOpenFunction; - - - - us.filestream = ZOPEN64(us.z_filefunc, - path, - ZLIB_FILEFUNC_MODE_READ | - ZLIB_FILEFUNC_MODE_EXISTING); - if (us.filestream==NULL) - return NULL; - - central_pos = unz64local_SearchCentralDir64(&us.z_filefunc,us.filestream); - if (central_pos) - { - uLong uS; - ZPOS64_T uL64; - - us.isZip64 = 1; - - if (ZSEEK64(us.z_filefunc, us.filestream, - central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) - err=UNZ_ERRNO; - - /* the signature, already checked */ - if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) - err=UNZ_ERRNO; - - /* size of zip64 end of central directory record */ - if (unz64local_getLong64(&us.z_filefunc, us.filestream,&uL64)!=UNZ_OK) - err=UNZ_ERRNO; - - /* version made by */ - if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK) - err=UNZ_ERRNO; - - /* version needed to extract */ - if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK) - err=UNZ_ERRNO; - - /* number of this disk */ - if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) - err=UNZ_ERRNO; - - /* number of the disk with the start of the central directory */ - if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) - err=UNZ_ERRNO; - - /* total number of entries in the central directory on this disk */ - if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK) - err=UNZ_ERRNO; - - /* total number of entries in the central directory */ - if (unz64local_getLong64(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK) - err=UNZ_ERRNO; - - if ((number_entry_CD!=us.gi.number_entry) || - (number_disk_with_CD!=0) || - (number_disk!=0)) - err=UNZ_BADZIPFILE; - - /* size of the central directory */ - if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK) - err=UNZ_ERRNO; - - /* offset of start of central directory with respect to the - starting disk number */ - if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK) - err=UNZ_ERRNO; - - us.gi.size_comment = 0; - } - else - { - central_pos = unz64local_SearchCentralDir(&us.z_filefunc,us.filestream); - if (central_pos==0) - err=UNZ_ERRNO; - - us.isZip64 = 0; - - if (ZSEEK64(us.z_filefunc, us.filestream, - central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) - err=UNZ_ERRNO; - - /* the signature, already checked */ - if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) - err=UNZ_ERRNO; - - /* number of this disk */ - if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) - err=UNZ_ERRNO; - - /* number of the disk with the start of the central directory */ - if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) - err=UNZ_ERRNO; - - /* total number of entries in the central dir on this disk */ - if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) - err=UNZ_ERRNO; - us.gi.number_entry = uL; - - /* total number of entries in the central dir */ - if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) - err=UNZ_ERRNO; - number_entry_CD = uL; - - if ((number_entry_CD!=us.gi.number_entry) || - (number_disk_with_CD!=0) || - (number_disk!=0)) - err=UNZ_BADZIPFILE; - - /* size of the central directory */ - if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) - err=UNZ_ERRNO; - us.size_central_dir = uL; - - /* offset of start of central directory with respect to the - starting disk number */ - if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) - err=UNZ_ERRNO; - us.offset_central_dir = uL; - - /* zipfile comment length */ - if (unz64local_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK) - err=UNZ_ERRNO; - } - - if ((central_pospfile_in_zip_read!=NULL) - unzCloseCurrentFile(file); - - ZCLOSE64(s->z_filefunc, s->filestream); - TRYFREE(s); - return UNZ_OK; -} - - -/* - Write info about the ZipFile in the *pglobal_info structure. - No preparation of the structure is needed - return UNZ_OK if there is no problem. */ -extern int ZEXPORT unzGetGlobalInfo64 (unzFile file, unz_global_info64* pglobal_info) -{ - unz64_s* s; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - *pglobal_info=s->gi; - return UNZ_OK; -} - -extern int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info* pglobal_info32) -{ - unz64_s* s; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - /* to do : check if number_entry is not truncated */ - pglobal_info32->number_entry = (uLong)s->gi.number_entry; - pglobal_info32->size_comment = s->gi.size_comment; - return UNZ_OK; -} -/* - Translate date/time from Dos format to tm_unz (readable more easilty) -*/ -local void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz* ptm) -{ - ZPOS64_T uDate; - uDate = (ZPOS64_T)(ulDosDate>>16); - ptm->tm_mday = (uInt)(uDate&0x1f) ; - ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ; - ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ; - - ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800); - ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ; - ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ; -} - -/* - Get Info about the current file in the zipfile, with internal only info -*/ -local int unz64local_GetCurrentFileInfoInternal OF((unzFile file, - unz_file_info64 *pfile_info, - unz_file_info64_internal - *pfile_info_internal, - char *szFileName, - uLong fileNameBufferSize, - void *extraField, - uLong extraFieldBufferSize, - char *szComment, - uLong commentBufferSize)); - -local int unz64local_GetCurrentFileInfoInternal (unzFile file, - unz_file_info64 *pfile_info, - unz_file_info64_internal - *pfile_info_internal, - char *szFileName, - uLong fileNameBufferSize, - void *extraField, - uLong extraFieldBufferSize, - char *szComment, - uLong commentBufferSize) -{ - unz64_s* s; - unz_file_info64 file_info; - unz_file_info64_internal file_info_internal; - int err=UNZ_OK; - uLong uMagic; - long lSeek=0; - uLong uL; - - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - if (ZSEEK64(s->z_filefunc, s->filestream, - s->pos_in_central_dir+s->byte_before_the_zipfile, - ZLIB_FILEFUNC_SEEK_SET)!=0) - err=UNZ_ERRNO; - - - /* we check the magic */ - if (err==UNZ_OK) - { - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) - err=UNZ_ERRNO; - else if (uMagic!=0x02014b50) - err=UNZ_BADZIPFILE; - } - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK) - err=UNZ_ERRNO; - - unz64local_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date); - - if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) - err=UNZ_ERRNO; - file_info.compressed_size = uL; - - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) - err=UNZ_ERRNO; - file_info.uncompressed_size = uL; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK) - err=UNZ_ERRNO; - - // relative offset of local header - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) - err=UNZ_ERRNO; - file_info_internal.offset_curfile = uL; - - lSeek+=file_info.size_filename; - if ((err==UNZ_OK) && (szFileName!=NULL)) - { - uLong uSizeRead ; - if (file_info.size_filename0) && (fileNameBufferSize>0)) - if (ZREAD64(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead) - err=UNZ_ERRNO; - lSeek -= uSizeRead; - } - - // Read extrafield - if ((err==UNZ_OK) && (extraField!=NULL)) - { - ZPOS64_T uSizeRead ; - if (file_info.size_file_extraz_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) - lSeek=0; - else - err=UNZ_ERRNO; - } - - if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) - if (ZREAD64(s->z_filefunc, s->filestream,extraField,(uLong)uSizeRead)!=uSizeRead) - err=UNZ_ERRNO; - - lSeek += file_info.size_file_extra - (uLong)uSizeRead; - } - else - lSeek += file_info.size_file_extra; - - - if ((err==UNZ_OK) && (file_info.size_file_extra != 0)) - { - uLong acc = 0; - - // since lSeek now points to after the extra field we need to move back - lSeek -= file_info.size_file_extra; - - if (lSeek!=0) - { - if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) - lSeek=0; - else - err=UNZ_ERRNO; - } - - while(acc < file_info.size_file_extra) - { - uLong headerId; - uLong dataSize; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&headerId) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&dataSize) != UNZ_OK) - err=UNZ_ERRNO; - - /* ZIP64 extra fields */ - if (headerId == 0x0001) - { - uLong uL; - - if(file_info.uncompressed_size == MAXU32) - { - if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK) - err=UNZ_ERRNO; - } - - if(file_info.compressed_size == MAXU32) - { - if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK) - err=UNZ_ERRNO; - } - - if(file_info_internal.offset_curfile == MAXU32) - { - /* Relative Header offset */ - if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK) - err=UNZ_ERRNO; - } - - if(file_info.disk_num_start == MAXU32) - { - /* Disk Start Number */ - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) - err=UNZ_ERRNO; - } - - } - else - { - if (ZSEEK64(s->z_filefunc, s->filestream,dataSize,ZLIB_FILEFUNC_SEEK_CUR)!=0) - err=UNZ_ERRNO; - } - - acc += 2 + 2 + dataSize; - } - } - - if ((err==UNZ_OK) && (szComment!=NULL)) - { - uLong uSizeRead ; - if (file_info.size_file_commentz_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) - lSeek=0; - else - err=UNZ_ERRNO; - } - - if ((file_info.size_file_comment>0) && (commentBufferSize>0)) - if (ZREAD64(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead) - err=UNZ_ERRNO; - lSeek+=file_info.size_file_comment - uSizeRead; - } - else - lSeek+=file_info.size_file_comment; - - - if ((err==UNZ_OK) && (pfile_info!=NULL)) - *pfile_info=file_info; - - if ((err==UNZ_OK) && (pfile_info_internal!=NULL)) - *pfile_info_internal=file_info_internal; - - return err; -} - - - -/* - Write info about the ZipFile in the *pglobal_info structure. - No preparation of the structure is needed - return UNZ_OK if there is no problem. -*/ -extern int ZEXPORT unzGetCurrentFileInfo64 (unzFile file, - unz_file_info64 * pfile_info, - char * szFileName, uLong fileNameBufferSize, - void *extraField, uLong extraFieldBufferSize, - char* szComment, uLong commentBufferSize) -{ - return unz64local_GetCurrentFileInfoInternal(file,pfile_info,NULL, - szFileName,fileNameBufferSize, - extraField,extraFieldBufferSize, - szComment,commentBufferSize); -} - -extern int ZEXPORT unzGetCurrentFileInfo (unzFile file, - unz_file_info * pfile_info, - char * szFileName, uLong fileNameBufferSize, - void *extraField, uLong extraFieldBufferSize, - char* szComment, uLong commentBufferSize) -{ - int err; - unz_file_info64 file_info64; - err = unz64local_GetCurrentFileInfoInternal(file,&file_info64,NULL, - szFileName,fileNameBufferSize, - extraField,extraFieldBufferSize, - szComment,commentBufferSize); - if ((err==UNZ_OK) && (pfile_info != NULL)) - { - pfile_info->version = file_info64.version; - pfile_info->version_needed = file_info64.version_needed; - pfile_info->flag = file_info64.flag; - pfile_info->compression_method = file_info64.compression_method; - pfile_info->dosDate = file_info64.dosDate; - pfile_info->crc = file_info64.crc; - - pfile_info->size_filename = file_info64.size_filename; - pfile_info->size_file_extra = file_info64.size_file_extra; - pfile_info->size_file_comment = file_info64.size_file_comment; - - pfile_info->disk_num_start = file_info64.disk_num_start; - pfile_info->internal_fa = file_info64.internal_fa; - pfile_info->external_fa = file_info64.external_fa; - - pfile_info->tmu_date = file_info64.tmu_date, - - - pfile_info->compressed_size = (uLong)file_info64.compressed_size; - pfile_info->uncompressed_size = (uLong)file_info64.uncompressed_size; - - } - return err; -} -/* - Set the current file of the zipfile to the first file. - return UNZ_OK if there is no problem -*/ -extern int ZEXPORT unzGoToFirstFile (unzFile file) -{ - int err=UNZ_OK; - unz64_s* s; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - s->pos_in_central_dir=s->offset_central_dir; - s->num_file=0; - err=unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, - &s->cur_file_info_internal, - NULL,0,NULL,0,NULL,0); - s->current_file_ok = (err == UNZ_OK); - return err; -} - -/* - Set the current file of the zipfile to the next file. - return UNZ_OK if there is no problem - return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. -*/ -extern int ZEXPORT unzGoToNextFile (unzFile file) -{ - unz64_s* s; - int err; - - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - if (!s->current_file_ok) - return UNZ_END_OF_LIST_OF_FILE; - if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */ - if (s->num_file+1==s->gi.number_entry) - return UNZ_END_OF_LIST_OF_FILE; - - s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename + - s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ; - s->num_file++; - err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, - &s->cur_file_info_internal, - NULL,0,NULL,0,NULL,0); - s->current_file_ok = (err == UNZ_OK); - return err; -} - - -/* - Try locate the file szFileName in the zipfile. - For the iCaseSensitivity signification, see unzStringFileNameCompare - - return value : - UNZ_OK if the file is found. It becomes the current file. - UNZ_END_OF_LIST_OF_FILE if the file is not found -*/ -extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity) -{ - unz64_s* s; - int err; - - /* We remember the 'current' position in the file so that we can jump - * back there if we fail. - */ - unz_file_info64 cur_file_infoSaved; - unz_file_info64_internal cur_file_info_internalSaved; - ZPOS64_T num_fileSaved; - ZPOS64_T pos_in_central_dirSaved; - - - if (file==NULL) - return UNZ_PARAMERROR; - - if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) - return UNZ_PARAMERROR; - - s=(unz64_s*)file; - if (!s->current_file_ok) - return UNZ_END_OF_LIST_OF_FILE; - - /* Save the current state */ - num_fileSaved = s->num_file; - pos_in_central_dirSaved = s->pos_in_central_dir; - cur_file_infoSaved = s->cur_file_info; - cur_file_info_internalSaved = s->cur_file_info_internal; - - err = unzGoToFirstFile(file); - - while (err == UNZ_OK) - { - char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; - err = unzGetCurrentFileInfo64(file,NULL, - szCurrentFileName,sizeof(szCurrentFileName)-1, - NULL,0,NULL,0); - if (err == UNZ_OK) - { - if (unzStringFileNameCompare(szCurrentFileName, - szFileName,iCaseSensitivity)==0) - return UNZ_OK; - err = unzGoToNextFile(file); - } - } - - /* We failed, so restore the state of the 'current file' to where we - * were. - */ - s->num_file = num_fileSaved ; - s->pos_in_central_dir = pos_in_central_dirSaved ; - s->cur_file_info = cur_file_infoSaved; - s->cur_file_info_internal = cur_file_info_internalSaved; - return err; -} - - -/* -/////////////////////////////////////////// -// Contributed by Ryan Haksi (mailto://cryogen@infoserve.net) -// I need random access -// -// Further optimization could be realized by adding an ability -// to cache the directory in memory. The goal being a single -// comprehensive file read to put the file I need in a memory. -*/ - -/* -typedef struct unz_file_pos_s -{ - ZPOS64_T pos_in_zip_directory; // offset in file - ZPOS64_T num_of_file; // # of file -} unz_file_pos; -*/ - -extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos* file_pos) -{ - unz64_s* s; - - if (file==NULL || file_pos==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - if (!s->current_file_ok) - return UNZ_END_OF_LIST_OF_FILE; - - file_pos->pos_in_zip_directory = s->pos_in_central_dir; - file_pos->num_of_file = s->num_file; - - return UNZ_OK; -} - -extern int ZEXPORT unzGetFilePos( - unzFile file, - unz_file_pos* file_pos) -{ - unz64_file_pos file_pos64; - int err = unzGetFilePos64(file,&file_pos64); - if (err==UNZ_OK) - { - file_pos->pos_in_zip_directory = (uLong)file_pos64.pos_in_zip_directory; - file_pos->num_of_file = (uLong)file_pos64.num_of_file; - } - return err; -} - -extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos) -{ - unz64_s* s; - int err; - - if (file==NULL || file_pos==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - - /* jump to the right spot */ - s->pos_in_central_dir = file_pos->pos_in_zip_directory; - s->num_file = file_pos->num_of_file; - - /* set the current file */ - err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, - &s->cur_file_info_internal, - NULL,0,NULL,0,NULL,0); - /* return results */ - s->current_file_ok = (err == UNZ_OK); - return err; -} - -extern int ZEXPORT unzGoToFilePos( - unzFile file, - unz_file_pos* file_pos) -{ - unz64_file_pos file_pos64; - if (file_pos == NULL) - return UNZ_PARAMERROR; - - file_pos64.pos_in_zip_directory = file_pos->pos_in_zip_directory; - file_pos64.num_of_file = file_pos->num_of_file; - return unzGoToFilePos64(file,&file_pos64); -} - -/* -// Unzip Helper Functions - should be here? -/////////////////////////////////////////// -*/ - -/* - Read the local header of the current zipfile - Check the coherency of the local header and info in the end of central - directory about this file - store in *piSizeVar the size of extra info in local header - (filename and size of extra field data) -*/ -local int unz64local_CheckCurrentFileCoherencyHeader (unz64_s* s, uInt* piSizeVar, - ZPOS64_T * poffset_local_extrafield, - uInt * psize_local_extrafield) -{ - uLong uMagic,uData,uFlags; - uLong size_filename; - uLong size_extra_field; - int err=UNZ_OK; - - *piSizeVar = 0; - *poffset_local_extrafield = 0; - *psize_local_extrafield = 0; - - if (ZSEEK64(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile + - s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0) - return UNZ_ERRNO; - - - if (err==UNZ_OK) - { - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) - err=UNZ_ERRNO; - else if (uMagic!=0x04034b50) - err=UNZ_BADZIPFILE; - } - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) - err=UNZ_ERRNO; -/* - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion)) - err=UNZ_BADZIPFILE; -*/ - if (unz64local_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK) - err=UNZ_ERRNO; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) - err=UNZ_ERRNO; - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method)) - err=UNZ_BADZIPFILE; - - if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) && -/* #ifdef HAVE_BZIP2 */ - (s->cur_file_info.compression_method!=Z_BZIP2ED) && -/* #endif */ - (s->cur_file_info.compression_method!=Z_DEFLATED)) - err=UNZ_BADZIPFILE; - - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */ - err=UNZ_ERRNO; - - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */ - err=UNZ_ERRNO; - else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && ((uFlags & 8)==0)) - err=UNZ_BADZIPFILE; - - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */ - err=UNZ_ERRNO; - else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && ((uFlags & 8)==0)) - err=UNZ_BADZIPFILE; - - if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */ - err=UNZ_ERRNO; - else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && ((uFlags & 8)==0)) - err=UNZ_BADZIPFILE; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK) - err=UNZ_ERRNO; - else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename)) - err=UNZ_BADZIPFILE; - - *piSizeVar += (uInt)size_filename; - - if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK) - err=UNZ_ERRNO; - *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile + - SIZEZIPLOCALHEADER + size_filename; - *psize_local_extrafield = (uInt)size_extra_field; - - *piSizeVar += (uInt)size_extra_field; - - return err; -} - -/* - Open for reading data the current file in the zipfile. - If there is no error and the file is opened, the return value is UNZ_OK. -*/ -extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method, - int* level, int raw, const char* password) -{ - int err=UNZ_OK; - uInt iSizeVar; - unz64_s* s; - file_in_zip64_read_info_s* pfile_in_zip_read_info; - ZPOS64_T offset_local_extrafield; /* offset of the local extra field */ - uInt size_local_extrafield; /* size of the local extra field */ -# ifndef NOUNCRYPT - char source[12]; -# else - if (password != NULL) - return UNZ_PARAMERROR; -# endif - - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - if (!s->current_file_ok) - return UNZ_PARAMERROR; - - if (s->pfile_in_zip_read != NULL) - unzCloseCurrentFile(file); - - if (unz64local_CheckCurrentFileCoherencyHeader(s,&iSizeVar, &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK) - return UNZ_BADZIPFILE; - - pfile_in_zip_read_info = (file_in_zip64_read_info_s*)ALLOC(sizeof(file_in_zip64_read_info_s)); - if (pfile_in_zip_read_info==NULL) - return UNZ_INTERNALERROR; - - pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE); - pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield; - pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield; - pfile_in_zip_read_info->pos_local_extrafield=0; - pfile_in_zip_read_info->raw=raw; - - if (pfile_in_zip_read_info->read_buffer==NULL) - { - TRYFREE(pfile_in_zip_read_info); - return UNZ_INTERNALERROR; - } - - pfile_in_zip_read_info->stream_initialised=0; - - if (method!=NULL) - *method = (int)s->cur_file_info.compression_method; - - if (level!=NULL) - { - *level = 6; - switch (s->cur_file_info.flag & 0x06) - { - case 6 : *level = 1; break; - case 4 : *level = 2; break; - case 2 : *level = 9; break; - } - } - - if ((s->cur_file_info.compression_method!=0) && -/* #ifdef HAVE_BZIP2 */ - (s->cur_file_info.compression_method!=Z_BZIP2ED) && -/* #endif */ - (s->cur_file_info.compression_method!=Z_DEFLATED)) - - err=UNZ_BADZIPFILE; - - pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc; - pfile_in_zip_read_info->crc32=0; - pfile_in_zip_read_info->total_out_64=0; - pfile_in_zip_read_info->compression_method = s->cur_file_info.compression_method; - pfile_in_zip_read_info->filestream=s->filestream; - pfile_in_zip_read_info->z_filefunc=s->z_filefunc; - pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile; - - pfile_in_zip_read_info->stream.total_out = 0; - - if ((s->cur_file_info.compression_method==Z_BZIP2ED) && (!raw)) - { -#ifdef HAVE_BZIP2 - pfile_in_zip_read_info->bstream.bzalloc = (void *(*) (void *, int, int))0; - pfile_in_zip_read_info->bstream.bzfree = (free_func)0; - pfile_in_zip_read_info->bstream.opaque = (voidpf)0; - pfile_in_zip_read_info->bstream.state = (voidpf)0; - - pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; - pfile_in_zip_read_info->stream.zfree = (free_func)0; - pfile_in_zip_read_info->stream.opaque = (voidpf)0; - pfile_in_zip_read_info->stream.next_in = (voidpf)0; - pfile_in_zip_read_info->stream.avail_in = 0; - - err=BZ2_bzDecompressInit(&pfile_in_zip_read_info->bstream, 0, 0); - if (err == Z_OK) - pfile_in_zip_read_info->stream_initialised=Z_BZIP2ED; - else - { - TRYFREE(pfile_in_zip_read_info); - return err; - } -#else - pfile_in_zip_read_info->raw=1; -#endif - } - else if ((s->cur_file_info.compression_method==Z_DEFLATED) && (!raw)) - { - pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; - pfile_in_zip_read_info->stream.zfree = (free_func)0; - pfile_in_zip_read_info->stream.opaque = (voidpf)0; - pfile_in_zip_read_info->stream.next_in = 0; - pfile_in_zip_read_info->stream.avail_in = 0; - - err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS); - if (err == Z_OK) - pfile_in_zip_read_info->stream_initialised=Z_DEFLATED; - else - { - TRYFREE(pfile_in_zip_read_info); - return err; - } - /* windowBits is passed < 0 to tell that there is no zlib header. - * Note that in this case inflate *requires* an extra "dummy" byte - * after the compressed stream in order to complete decompression and - * return Z_STREAM_END. - * In unzip, i don't wait absolutely Z_STREAM_END because I known the - * size of both compressed and uncompressed data - */ - } - pfile_in_zip_read_info->rest_read_compressed = - s->cur_file_info.compressed_size ; - pfile_in_zip_read_info->rest_read_uncompressed = - s->cur_file_info.uncompressed_size ; - - - pfile_in_zip_read_info->pos_in_zipfile = - s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + - iSizeVar; - - pfile_in_zip_read_info->stream.avail_in = (uInt)0; - - s->pfile_in_zip_read = pfile_in_zip_read_info; - s->encrypted = 0; - -# ifndef NOUNCRYPT - if (password != NULL) - { - int i; - s->pcrc_32_tab = get_crc_table(); - init_keys(password,s->keys,s->pcrc_32_tab); - if (ZSEEK64(s->z_filefunc, s->filestream, - s->pfile_in_zip_read->pos_in_zipfile + - s->pfile_in_zip_read->byte_before_the_zipfile, - SEEK_SET)!=0) - return UNZ_INTERNALERROR; - if(ZREAD64(s->z_filefunc, s->filestream,source, 12)<12) - return UNZ_INTERNALERROR; - - for (i = 0; i<12; i++) - zdecode(s->keys,s->pcrc_32_tab,source[i]); - - s->pfile_in_zip_read->pos_in_zipfile+=12; - s->encrypted=1; - } -# endif - - - return UNZ_OK; -} - -extern int ZEXPORT unzOpenCurrentFile (unzFile file) -{ - return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL); -} - -extern int ZEXPORT unzOpenCurrentFilePassword (unzFile file, const char* password) -{ - return unzOpenCurrentFile3(file, NULL, NULL, 0, password); -} - -extern int ZEXPORT unzOpenCurrentFile2 (unzFile file, int* method, int* level, int raw) -{ - return unzOpenCurrentFile3(file, method, level, raw, NULL); -} - -/** Addition for GDAL : START */ - -extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64( unzFile file) -{ - unz64_s* s; - file_in_zip64_read_info_s* pfile_in_zip_read_info; - s=(unz64_s*)file; - if (file==NULL) - return 0; //UNZ_PARAMERROR; - pfile_in_zip_read_info=s->pfile_in_zip_read; - if (pfile_in_zip_read_info==NULL) - return 0; //UNZ_PARAMERROR; - return pfile_in_zip_read_info->pos_in_zipfile + - pfile_in_zip_read_info->byte_before_the_zipfile; -} - -/** Addition for GDAL : END */ - -/* - Read bytes from the current file. - buf contain buffer where data must be copied - len the size of buf. - - return the number of byte copied if somes bytes are copied - return 0 if the end of file was reached - return <0 with error code if there is an error - (UNZ_ERRNO for IO error, or zLib error for uncompress error) -*/ -extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len) -{ - int err=UNZ_OK; - uInt iRead = 0; - unz64_s* s; - file_in_zip64_read_info_s* pfile_in_zip_read_info; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return UNZ_PARAMERROR; - - - if (pfile_in_zip_read_info->read_buffer == NULL) - return UNZ_END_OF_LIST_OF_FILE; - if (len==0) - return 0; - - pfile_in_zip_read_info->stream.next_out = (Bytef*)buf; - - pfile_in_zip_read_info->stream.avail_out = (uInt)len; - - if ((len>pfile_in_zip_read_info->rest_read_uncompressed) && - (!(pfile_in_zip_read_info->raw))) - pfile_in_zip_read_info->stream.avail_out = - (uInt)pfile_in_zip_read_info->rest_read_uncompressed; - - if ((len>pfile_in_zip_read_info->rest_read_compressed+ - pfile_in_zip_read_info->stream.avail_in) && - (pfile_in_zip_read_info->raw)) - pfile_in_zip_read_info->stream.avail_out = - (uInt)pfile_in_zip_read_info->rest_read_compressed+ - pfile_in_zip_read_info->stream.avail_in; - - while (pfile_in_zip_read_info->stream.avail_out>0) - { - if ((pfile_in_zip_read_info->stream.avail_in==0) && - (pfile_in_zip_read_info->rest_read_compressed>0)) - { - uInt uReadThis = UNZ_BUFSIZE; - if (pfile_in_zip_read_info->rest_read_compressedrest_read_compressed; - if (uReadThis == 0) - return UNZ_EOF; - if (ZSEEK64(pfile_in_zip_read_info->z_filefunc, - pfile_in_zip_read_info->filestream, - pfile_in_zip_read_info->pos_in_zipfile + - pfile_in_zip_read_info->byte_before_the_zipfile, - ZLIB_FILEFUNC_SEEK_SET)!=0) - return UNZ_ERRNO; - if (ZREAD64(pfile_in_zip_read_info->z_filefunc, - pfile_in_zip_read_info->filestream, - pfile_in_zip_read_info->read_buffer, - uReadThis)!=uReadThis) - return UNZ_ERRNO; - - -# ifndef NOUNCRYPT - if(s->encrypted) - { - uInt i; - for(i=0;iread_buffer[i] = - zdecode(s->keys,s->pcrc_32_tab, - pfile_in_zip_read_info->read_buffer[i]); - } -# endif - - - pfile_in_zip_read_info->pos_in_zipfile += uReadThis; - - pfile_in_zip_read_info->rest_read_compressed-=uReadThis; - - pfile_in_zip_read_info->stream.next_in = - (Bytef*)pfile_in_zip_read_info->read_buffer; - pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis; - } - - if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw)) - { - uInt uDoCopy,i ; - - if ((pfile_in_zip_read_info->stream.avail_in == 0) && - (pfile_in_zip_read_info->rest_read_compressed == 0)) - return (iRead==0) ? UNZ_EOF : iRead; - - if (pfile_in_zip_read_info->stream.avail_out < - pfile_in_zip_read_info->stream.avail_in) - uDoCopy = pfile_in_zip_read_info->stream.avail_out ; - else - uDoCopy = pfile_in_zip_read_info->stream.avail_in ; - - for (i=0;istream.next_out+i) = - *(pfile_in_zip_read_info->stream.next_in+i); - - pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uDoCopy; - - pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32, - pfile_in_zip_read_info->stream.next_out, - uDoCopy); - pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy; - pfile_in_zip_read_info->stream.avail_in -= uDoCopy; - pfile_in_zip_read_info->stream.avail_out -= uDoCopy; - pfile_in_zip_read_info->stream.next_out += uDoCopy; - pfile_in_zip_read_info->stream.next_in += uDoCopy; - pfile_in_zip_read_info->stream.total_out += uDoCopy; - iRead += uDoCopy; - } - else if (pfile_in_zip_read_info->compression_method==Z_BZIP2ED) - { -#ifdef HAVE_BZIP2 - uLong uTotalOutBefore,uTotalOutAfter; - const Bytef *bufBefore; - uLong uOutThis; - - pfile_in_zip_read_info->bstream.next_in = (char*)pfile_in_zip_read_info->stream.next_in; - pfile_in_zip_read_info->bstream.avail_in = pfile_in_zip_read_info->stream.avail_in; - pfile_in_zip_read_info->bstream.total_in_lo32 = pfile_in_zip_read_info->stream.total_in; - pfile_in_zip_read_info->bstream.total_in_hi32 = 0; - pfile_in_zip_read_info->bstream.next_out = (char*)pfile_in_zip_read_info->stream.next_out; - pfile_in_zip_read_info->bstream.avail_out = pfile_in_zip_read_info->stream.avail_out; - pfile_in_zip_read_info->bstream.total_out_lo32 = pfile_in_zip_read_info->stream.total_out; - pfile_in_zip_read_info->bstream.total_out_hi32 = 0; - - uTotalOutBefore = pfile_in_zip_read_info->bstream.total_out_lo32; - bufBefore = (const Bytef *)pfile_in_zip_read_info->bstream.next_out; - - err=BZ2_bzDecompress(&pfile_in_zip_read_info->bstream); - - uTotalOutAfter = pfile_in_zip_read_info->bstream.total_out_lo32; - uOutThis = uTotalOutAfter-uTotalOutBefore; - - pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis; - - pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,bufBefore, (uInt)(uOutThis)); - pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis; - iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); - - pfile_in_zip_read_info->stream.next_in = (Bytef*)pfile_in_zip_read_info->bstream.next_in; - pfile_in_zip_read_info->stream.avail_in = pfile_in_zip_read_info->bstream.avail_in; - pfile_in_zip_read_info->stream.total_in = pfile_in_zip_read_info->bstream.total_in_lo32; - pfile_in_zip_read_info->stream.next_out = (Bytef*)pfile_in_zip_read_info->bstream.next_out; - pfile_in_zip_read_info->stream.avail_out = pfile_in_zip_read_info->bstream.avail_out; - pfile_in_zip_read_info->stream.total_out = pfile_in_zip_read_info->bstream.total_out_lo32; - - if (err==BZ_STREAM_END) - return (iRead==0) ? UNZ_EOF : iRead; - if (err!=BZ_OK) - break; -#endif - } // end Z_BZIP2ED - else - { - ZPOS64_T uTotalOutBefore,uTotalOutAfter; - const Bytef *bufBefore; - ZPOS64_T uOutThis; - int flush=Z_SYNC_FLUSH; - - uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; - bufBefore = pfile_in_zip_read_info->stream.next_out; - - /* - if ((pfile_in_zip_read_info->rest_read_uncompressed == - pfile_in_zip_read_info->stream.avail_out) && - (pfile_in_zip_read_info->rest_read_compressed == 0)) - flush = Z_FINISH; - */ - err=inflate(&pfile_in_zip_read_info->stream,flush); - - if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL)) - err = Z_DATA_ERROR; - - uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; - uOutThis = uTotalOutAfter-uTotalOutBefore; - - pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis; - - pfile_in_zip_read_info->crc32 = - crc32(pfile_in_zip_read_info->crc32,bufBefore, - (uInt)(uOutThis)); - - pfile_in_zip_read_info->rest_read_uncompressed -= - uOutThis; - - iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); - - if (err==Z_STREAM_END) - return (iRead==0) ? UNZ_EOF : iRead; - if (err!=Z_OK) - break; - } - } - - if (err==Z_OK) - return iRead; - return err; -} - - -/* - Give the current position in uncompressed data -*/ -extern z_off_t ZEXPORT unztell (unzFile file) -{ - unz64_s* s; - file_in_zip64_read_info_s* pfile_in_zip_read_info; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return UNZ_PARAMERROR; - - return (z_off_t)pfile_in_zip_read_info->stream.total_out; -} - -extern ZPOS64_T ZEXPORT unztell64 (unzFile file) -{ - - unz64_s* s; - file_in_zip64_read_info_s* pfile_in_zip_read_info; - if (file==NULL) - return (ZPOS64_T)-1; - s=(unz64_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return (ZPOS64_T)-1; - - return pfile_in_zip_read_info->total_out_64; -} - - -/* - return 1 if the end of file was reached, 0 elsewhere -*/ -extern int ZEXPORT unzeof (unzFile file) -{ - unz64_s* s; - file_in_zip64_read_info_s* pfile_in_zip_read_info; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return UNZ_PARAMERROR; - - if (pfile_in_zip_read_info->rest_read_uncompressed == 0) - return 1; - else - return 0; -} - - - -/* -Read extra field from the current file (opened by unzOpenCurrentFile) -This is the local-header version of the extra field (sometimes, there is -more info in the local-header version than in the central-header) - - if buf==NULL, it return the size of the local extra field that can be read - - if buf!=NULL, len is the size of the buffer, the extra header is copied in - buf. - the return value is the number of bytes copied in buf, or (if <0) - the error code -*/ -extern int ZEXPORT unzGetLocalExtrafield (unzFile file, voidp buf, unsigned len) -{ - unz64_s* s; - file_in_zip64_read_info_s* pfile_in_zip_read_info; - uInt read_now; - ZPOS64_T size_to_read; - - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return UNZ_PARAMERROR; - - size_to_read = (pfile_in_zip_read_info->size_local_extrafield - - pfile_in_zip_read_info->pos_local_extrafield); - - if (buf==NULL) - return (int)size_to_read; - - if (len>size_to_read) - read_now = (uInt)size_to_read; - else - read_now = (uInt)len ; - - if (read_now==0) - return 0; - - if (ZSEEK64(pfile_in_zip_read_info->z_filefunc, - pfile_in_zip_read_info->filestream, - pfile_in_zip_read_info->offset_local_extrafield + - pfile_in_zip_read_info->pos_local_extrafield, - ZLIB_FILEFUNC_SEEK_SET)!=0) - return UNZ_ERRNO; - - if (ZREAD64(pfile_in_zip_read_info->z_filefunc, - pfile_in_zip_read_info->filestream, - buf,read_now)!=read_now) - return UNZ_ERRNO; - - return (int)read_now; -} - -/* - Close the file in zip opened with unzOpenCurrentFile - Return UNZ_CRCERROR if all the file was read but the CRC is not good -*/ -extern int ZEXPORT unzCloseCurrentFile (unzFile file) -{ - int err=UNZ_OK; - - unz64_s* s; - file_in_zip64_read_info_s* pfile_in_zip_read_info; - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - pfile_in_zip_read_info=s->pfile_in_zip_read; - - if (pfile_in_zip_read_info==NULL) - return UNZ_PARAMERROR; - - - if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) && - (!pfile_in_zip_read_info->raw)) - { - if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait) - err=UNZ_CRCERROR; - } - - - TRYFREE(pfile_in_zip_read_info->read_buffer); - pfile_in_zip_read_info->read_buffer = NULL; - if (pfile_in_zip_read_info->stream_initialised == Z_DEFLATED) - inflateEnd(&pfile_in_zip_read_info->stream); -#ifdef HAVE_BZIP2 - else if (pfile_in_zip_read_info->stream_initialised == Z_BZIP2ED) - BZ2_bzDecompressEnd(&pfile_in_zip_read_info->bstream); -#endif - - - pfile_in_zip_read_info->stream_initialised = 0; - TRYFREE(pfile_in_zip_read_info); - - s->pfile_in_zip_read=NULL; - - return err; -} - - -/* - Get the global comment string of the ZipFile, in the szComment buffer. - uSizeBuf is the size of the szComment buffer. - return the number of byte copied or an error code <0 -*/ -extern int ZEXPORT unzGetGlobalComment (unzFile file, char * szComment, uLong uSizeBuf) -{ - unz64_s* s; - uLong uReadThis ; - if (file==NULL) - return (int)UNZ_PARAMERROR; - s=(unz64_s*)file; - - uReadThis = uSizeBuf; - if (uReadThis>s->gi.size_comment) - uReadThis = s->gi.size_comment; - - if (ZSEEK64(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0) - return UNZ_ERRNO; - - if (uReadThis>0) - { - *szComment='\0'; - if (ZREAD64(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis) - return UNZ_ERRNO; - } - - if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment)) - *(szComment+s->gi.size_comment)='\0'; - return (int)uReadThis; -} - -/* Additions by RX '2004 */ -extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file) -{ - unz64_s* s; - - if (file==NULL) - return 0; //UNZ_PARAMERROR; - s=(unz64_s*)file; - if (!s->current_file_ok) - return 0; - if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff) - if (s->num_file==s->gi.number_entry) - return 0; - return s->pos_in_central_dir; -} - -extern uLong ZEXPORT unzGetOffset (unzFile file) -{ - ZPOS64_T offset64; - - if (file==NULL) - return 0; //UNZ_PARAMERROR; - offset64 = unzGetOffset64(file); - return (uLong)offset64; -} - -extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos) -{ - unz64_s* s; - int err; - - if (file==NULL) - return UNZ_PARAMERROR; - s=(unz64_s*)file; - - s->pos_in_central_dir = pos; - s->num_file = s->gi.number_entry; /* hack */ - err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, - &s->cur_file_info_internal, - NULL,0,NULL,0,NULL,0); - s->current_file_ok = (err == UNZ_OK); - return err; -} - -extern int ZEXPORT unzSetOffset (unzFile file, uLong pos) -{ - return unzSetOffset64(file,pos); -} diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/unzip.h b/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/unzip.h deleted file mode 100644 index 2104e391507..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/unzip.h +++ /dev/null @@ -1,437 +0,0 @@ -/* unzip.h -- IO for uncompress .zip files using zlib - Version 1.1, February 14h, 2010 - part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) - - Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) - - Modifications of Unzip for Zip64 - Copyright (C) 2007-2008 Even Rouault - - Modifications for Zip64 support on both zip and unzip - Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) - - For more info read MiniZip_info.txt - - --------------------------------------------------------------------------------- - - Condition of use and distribution are the same than zlib : - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - --------------------------------------------------------------------------------- - - Changes - - See header of unzip64.c - -*/ - -#ifndef _unz64_H -#define _unz64_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _ZLIB_H -#include "zlib.h" -#endif - -#ifndef _ZLIBIOAPI_H -#include "ioapi.h" -#endif - -#ifdef HAVE_BZIP2 -#include "bzlib.h" -#endif - -#define Z_BZIP2ED 12 - -#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) -/* like the STRICT of WIN32, we define a pointer that cannot be converted - from (void*) without cast */ -typedef struct TagunzFile__ { int unused; } unzFile__; -typedef unzFile__ *unzFile; -#else -typedef voidp unzFile; -#endif - - -#define UNZ_OK (0) -#define UNZ_END_OF_LIST_OF_FILE (-100) -#define UNZ_ERRNO (Z_ERRNO) -#define UNZ_EOF (0) -#define UNZ_PARAMERROR (-102) -#define UNZ_BADZIPFILE (-103) -#define UNZ_INTERNALERROR (-104) -#define UNZ_CRCERROR (-105) - -/* tm_unz contain date/time info */ -typedef struct tm_unz_s -{ - uInt tm_sec; /* seconds after the minute - [0,59] */ - uInt tm_min; /* minutes after the hour - [0,59] */ - uInt tm_hour; /* hours since midnight - [0,23] */ - uInt tm_mday; /* day of the month - [1,31] */ - uInt tm_mon; /* months since January - [0,11] */ - uInt tm_year; /* years - [1980..2044] */ -} tm_unz; - -/* unz_global_info structure contain global data about the ZIPfile - These data comes from the end of central dir */ -typedef struct unz_global_info64_s -{ - ZPOS64_T number_entry; /* total number of entries in - the central dir on this disk */ - uLong size_comment; /* size of the global comment of the zipfile */ -} unz_global_info64; - -typedef struct unz_global_info_s -{ - uLong number_entry; /* total number of entries in - the central dir on this disk */ - uLong size_comment; /* size of the global comment of the zipfile */ -} unz_global_info; - -/* unz_file_info contain information about a file in the zipfile */ -typedef struct unz_file_info64_s -{ - uLong version; /* version made by 2 bytes */ - uLong version_needed; /* version needed to extract 2 bytes */ - uLong flag; /* general purpose bit flag 2 bytes */ - uLong compression_method; /* compression method 2 bytes */ - uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ - uLong crc; /* crc-32 4 bytes */ - ZPOS64_T compressed_size; /* compressed size 8 bytes */ - ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */ - uLong size_filename; /* filename length 2 bytes */ - uLong size_file_extra; /* extra field length 2 bytes */ - uLong size_file_comment; /* file comment length 2 bytes */ - - uLong disk_num_start; /* disk number start 2 bytes */ - uLong internal_fa; /* internal file attributes 2 bytes */ - uLong external_fa; /* external file attributes 4 bytes */ - - tm_unz tmu_date; -} unz_file_info64; - -typedef struct unz_file_info_s -{ - uLong version; /* version made by 2 bytes */ - uLong version_needed; /* version needed to extract 2 bytes */ - uLong flag; /* general purpose bit flag 2 bytes */ - uLong compression_method; /* compression method 2 bytes */ - uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ - uLong crc; /* crc-32 4 bytes */ - uLong compressed_size; /* compressed size 4 bytes */ - uLong uncompressed_size; /* uncompressed size 4 bytes */ - uLong size_filename; /* filename length 2 bytes */ - uLong size_file_extra; /* extra field length 2 bytes */ - uLong size_file_comment; /* file comment length 2 bytes */ - - uLong disk_num_start; /* disk number start 2 bytes */ - uLong internal_fa; /* internal file attributes 2 bytes */ - uLong external_fa; /* external file attributes 4 bytes */ - - tm_unz tmu_date; -} unz_file_info; - -extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, - const char* fileName2, - int iCaseSensitivity)); -/* - Compare two filename (fileName1,fileName2). - If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) - If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi - or strcasecmp) - If iCaseSenisivity = 0, case sensitivity is defaut of your operating system - (like 1 on Unix, 2 on Windows) -*/ - - -extern unzFile ZEXPORT unzOpen OF((const char *path)); -extern unzFile ZEXPORT unzOpen64 OF((const void *path)); -/* - Open a Zip file. path contain the full pathname (by example, - on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer - "zlib/zlib113.zip". - If the zipfile cannot be opened (file don't exist or in not valid), the - return value is NULL. - Else, the return value is a unzFile Handle, usable with other function - of this unzip package. - the "64" function take a const void* pointer, because the path is just the - value passed to the open64_file_func callback. - Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path - is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char* - does not describe the reality -*/ - - -extern unzFile ZEXPORT unzOpen2 OF((const char *path, - zlib_filefunc_def* pzlib_filefunc_def)); -/* - Open a Zip file, like unzOpen, but provide a set of file low level API - for read/write the zip file (see ioapi.h) -*/ - -extern unzFile ZEXPORT unzOpen2_64 OF((const void *path, - zlib_filefunc64_def* pzlib_filefunc_def)); -/* - Open a Zip file, like unz64Open, but provide a set of file low level API - for read/write the zip file (see ioapi.h) -*/ - -extern int ZEXPORT unzClose OF((unzFile file)); -/* - Close a ZipFile opened with unzOpen. - If there is files inside the .Zip opened with unzOpenCurrentFile (see later), - these files MUST be closed with unzCloseCurrentFile before call unzClose. - return UNZ_OK if there is no problem. */ - -extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, - unz_global_info *pglobal_info)); - -extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file, - unz_global_info64 *pglobal_info)); -/* - Write info about the ZipFile in the *pglobal_info structure. - No preparation of the structure is needed - return UNZ_OK if there is no problem. */ - - -extern int ZEXPORT unzGetGlobalComment OF((unzFile file, - char *szComment, - uLong uSizeBuf)); -/* - Get the global comment string of the ZipFile, in the szComment buffer. - uSizeBuf is the size of the szComment buffer. - return the number of byte copied or an error code <0 -*/ - - -/***************************************************************************/ -/* Unzip package allow you browse the directory of the zipfile */ - -extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); -/* - Set the current file of the zipfile to the first file. - return UNZ_OK if there is no problem -*/ - -extern int ZEXPORT unzGoToNextFile OF((unzFile file)); -/* - Set the current file of the zipfile to the next file. - return UNZ_OK if there is no problem - return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. -*/ - -extern int ZEXPORT unzLocateFile OF((unzFile file, - const char *szFileName, - int iCaseSensitivity)); -/* - Try locate the file szFileName in the zipfile. - For the iCaseSensitivity signification, see unzStringFileNameCompare - - return value : - UNZ_OK if the file is found. It becomes the current file. - UNZ_END_OF_LIST_OF_FILE if the file is not found -*/ - - -/* ****************************************** */ -/* Ryan supplied functions */ -/* unz_file_info contain information about a file in the zipfile */ -typedef struct unz_file_pos_s -{ - uLong pos_in_zip_directory; /* offset in zip file directory */ - uLong num_of_file; /* # of file */ -} unz_file_pos; - -extern int ZEXPORT unzGetFilePos( - unzFile file, - unz_file_pos* file_pos); - -extern int ZEXPORT unzGoToFilePos( - unzFile file, - unz_file_pos* file_pos); - -typedef struct unz64_file_pos_s -{ - ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */ - ZPOS64_T num_of_file; /* # of file */ -} unz64_file_pos; - -extern int ZEXPORT unzGetFilePos64( - unzFile file, - unz64_file_pos* file_pos); - -extern int ZEXPORT unzGoToFilePos64( - unzFile file, - const unz64_file_pos* file_pos); - -/* ****************************************** */ - -extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file, - unz_file_info64 *pfile_info, - char *szFileName, - uLong fileNameBufferSize, - void *extraField, - uLong extraFieldBufferSize, - char *szComment, - uLong commentBufferSize)); - -extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, - unz_file_info *pfile_info, - char *szFileName, - uLong fileNameBufferSize, - void *extraField, - uLong extraFieldBufferSize, - char *szComment, - uLong commentBufferSize)); -/* - Get Info about the current file - if pfile_info!=NULL, the *pfile_info structure will contain somes info about - the current file - if szFileName!=NULL, the filemane string will be copied in szFileName - (fileNameBufferSize is the size of the buffer) - if extraField!=NULL, the extra field information will be copied in extraField - (extraFieldBufferSize is the size of the buffer). - This is the Central-header version of the extra field - if szComment!=NULL, the comment string of the file will be copied in szComment - (commentBufferSize is the size of the buffer) -*/ - - -/** Addition for GDAL : START */ - -extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file)); - -/** Addition for GDAL : END */ - - -/***************************************************************************/ -/* for reading the content of the current zipfile, you can open it, read data - from it, and close it (you can close it before reading all the file) - */ - -extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); -/* - Open for reading data the current file in the zipfile. - If there is no error, the return value is UNZ_OK. -*/ - -extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file, - const char* password)); -/* - Open for reading data the current file in the zipfile. - password is a crypting password - If there is no error, the return value is UNZ_OK. -*/ - -extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file, - int* method, - int* level, - int raw)); -/* - Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) - if raw==1 - *method will receive method of compression, *level will receive level of - compression - note : you can set level parameter as NULL (if you did not want known level, - but you CANNOT set method parameter as NULL -*/ - -extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file, - int* method, - int* level, - int raw, - const char* password)); -/* - Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) - if raw==1 - *method will receive method of compression, *level will receive level of - compression - note : you can set level parameter as NULL (if you did not want known level, - but you CANNOT set method parameter as NULL -*/ - - -extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); -/* - Close the file in zip opened with unzOpenCurrentFile - Return UNZ_CRCERROR if all the file was read but the CRC is not good -*/ - -extern int ZEXPORT unzReadCurrentFile OF((unzFile file, - voidp buf, - unsigned len)); -/* - Read bytes from the current file (opened by unzOpenCurrentFile) - buf contain buffer where data must be copied - len the size of buf. - - return the number of byte copied if somes bytes are copied - return 0 if the end of file was reached - return <0 with error code if there is an error - (UNZ_ERRNO for IO error, or zLib error for uncompress error) -*/ - -extern z_off_t ZEXPORT unztell OF((unzFile file)); - -extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file)); -/* - Give the current position in uncompressed data -*/ - -extern int ZEXPORT unzeof OF((unzFile file)); -/* - return 1 if the end of file was reached, 0 elsewhere -*/ - -extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, - voidp buf, - unsigned len)); -/* - Read extra field from the current file (opened by unzOpenCurrentFile) - This is the local-header version of the extra field (sometimes, there is - more info in the local-header version than in the central-header) - - if buf==NULL, it return the size of the local extra field - - if buf!=NULL, len is the size of the buffer, the extra header is copied in - buf. - the return value is the number of bytes copied in buf, or (if <0) - the error code -*/ - -/***************************************************************************/ - -/* Get the current file offset */ -extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file); -extern uLong ZEXPORT unzGetOffset (unzFile file); - -/* Set the current file offset */ -extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos); -extern int ZEXPORT unzSetOffset (unzFile file, uLong pos); - - - -#ifdef __cplusplus -} -#endif - -#endif /* _unz64_H */ diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/zip.c b/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/zip.c deleted file mode 100644 index ea54853e858..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/zip.c +++ /dev/null @@ -1,2007 +0,0 @@ -/* zip.c -- IO on .zip files using zlib - Version 1.1, February 14h, 2010 - part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) - - Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) - - Modifications for Zip64 support - Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) - - For more info read MiniZip_info.txt - - Changes - Oct-2009 - Mathias Svensson - Remove old C style function prototypes - Oct-2009 - Mathias Svensson - Added Zip64 Support when creating new file archives - Oct-2009 - Mathias Svensson - Did some code cleanup and refactoring to get better overview of some functions. - Oct-2009 - Mathias Svensson - Added zipRemoveExtraInfoBlock to strip extra field data from its ZIP64 data - It is used when recreting zip archive with RAW when deleting items from a zip. - ZIP64 data is automaticly added to items that needs it, and existing ZIP64 data need to be removed. - Oct-2009 - Mathias Svensson - Added support for BZIP2 as compression mode (bzip2 lib is required) - Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer - -*/ - - -#include -#include -#include -#include -#include "zlib.h" -#include "zip.h" - -#ifdef STDC -# include -# include -# include -#endif -#ifdef NO_ERRNO_H - extern int errno; -#else -# include -#endif - - -#ifndef local -# define local static -#endif -/* compile with -Dlocal if your debugger can't find static symbols */ - -#ifndef VERSIONMADEBY -# define VERSIONMADEBY (0x0) /* platform depedent */ -#endif - -#ifndef Z_BUFSIZE -#define Z_BUFSIZE (64*1024) //(16384) -#endif - -#ifndef Z_MAXFILENAMEINZIP -#define Z_MAXFILENAMEINZIP (256) -#endif - -#ifndef ALLOC -# define ALLOC(size) (malloc(size)) -#endif -#ifndef TRYFREE -# define TRYFREE(p) {if (p) free(p);} -#endif - -/* -#define SIZECENTRALDIRITEM (0x2e) -#define SIZEZIPLOCALHEADER (0x1e) -*/ - -/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */ - - -// NOT sure that this work on ALL platform -#define MAKEULONG64(a, b) ((ZPOS64_T)(((unsigned long)(a)) | ((ZPOS64_T)((unsigned long)(b))) << 32)) - -#ifndef SEEK_CUR -#define SEEK_CUR 1 -#endif - -#ifndef SEEK_END -#define SEEK_END 2 -#endif - -#ifndef SEEK_SET -#define SEEK_SET 0 -#endif - -#ifndef DEF_MEM_LEVEL -#if MAX_MEM_LEVEL >= 8 -# define DEF_MEM_LEVEL 8 -#else -# define DEF_MEM_LEVEL MAX_MEM_LEVEL -#endif -#endif -const char zip_copyright[] =" zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; - - -#define SIZEDATA_INDATABLOCK (4096-(4*4)) - -#define LOCALHEADERMAGIC (0x04034b50) -#define CENTRALHEADERMAGIC (0x02014b50) -#define ENDHEADERMAGIC (0x06054b50) -#define ZIP64ENDHEADERMAGIC (0x6064b50) -#define ZIP64ENDLOCHEADERMAGIC (0x7064b50) - -#define FLAG_LOCALHEADER_OFFSET (0x06) -#define CRC_LOCALHEADER_OFFSET (0x0e) - -#define SIZECENTRALHEADER (0x2e) /* 46 */ - -typedef struct linkedlist_datablock_internal_s -{ - struct linkedlist_datablock_internal_s* next_datablock; - uLong avail_in_this_block; - uLong filled_in_this_block; - uLong unused; /* for future use and alignement */ - unsigned char data[SIZEDATA_INDATABLOCK]; -} linkedlist_datablock_internal; - -typedef struct linkedlist_data_s -{ - linkedlist_datablock_internal* first_block; - linkedlist_datablock_internal* last_block; -} linkedlist_data; - - -typedef struct -{ - z_stream stream; /* zLib stream structure for inflate */ -#ifdef HAVE_BZIP2 - bz_stream bstream; /* bzLib stream structure for bziped */ -#endif - - int stream_initialised; /* 1 is stream is initialised */ - uInt pos_in_buffered_data; /* last written byte in buffered_data */ - - ZPOS64_T pos_local_header; /* offset of the local header of the file - currenty writing */ - char* central_header; /* central header data for the current file */ - uLong size_centralExtra; - uLong size_centralheader; /* size of the central header for cur file */ - uLong size_centralExtraFree; /* Extra bytes allocated to the centralheader but that are not used */ - uLong flag; /* flag of the file currently writing */ - - int method; /* compression method of file currenty wr.*/ - int raw; /* 1 for directly writing raw data */ - Byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/ - uLong dosDate; - uLong crc32; - int encrypt; - int zip64; /* Add ZIP64 extened information in the extra field */ - ZPOS64_T pos_zip64extrainfo; - ZPOS64_T totalCompressedData; - ZPOS64_T totalUncompressedData; -#ifndef NOCRYPT - unsigned long keys[3]; /* keys defining the pseudo-random sequence */ - const z_crc_t* pcrc_32_tab; - int crypt_header_size; -#endif -} curfile64_info; - -typedef struct -{ - zlib_filefunc64_32_def z_filefunc; - voidpf filestream; /* io structore of the zipfile */ - linkedlist_data central_dir;/* datablock with central dir in construction*/ - int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/ - curfile64_info ci; /* info on the file curretly writing */ - - ZPOS64_T begin_pos; /* position of the beginning of the zipfile */ - ZPOS64_T add_position_when_writting_offset; - ZPOS64_T number_entry; - -#ifndef NO_ADDFILEINEXISTINGZIP - char *globalcomment; -#endif - -} zip64_internal; - - -#ifndef NOCRYPT -#define INCLUDECRYPTINGCODE_IFCRYPTALLOWED -#include "crypt.h" -#endif - -local linkedlist_datablock_internal* allocate_new_datablock() -{ - linkedlist_datablock_internal* ldi; - ldi = (linkedlist_datablock_internal*) - ALLOC(sizeof(linkedlist_datablock_internal)); - if (ldi!=NULL) - { - ldi->next_datablock = NULL ; - ldi->filled_in_this_block = 0 ; - ldi->avail_in_this_block = SIZEDATA_INDATABLOCK ; - } - return ldi; -} - -local void free_datablock(linkedlist_datablock_internal* ldi) -{ - while (ldi!=NULL) - { - linkedlist_datablock_internal* ldinext = ldi->next_datablock; - TRYFREE(ldi); - ldi = ldinext; - } -} - -local void init_linkedlist(linkedlist_data* ll) -{ - ll->first_block = ll->last_block = NULL; -} - -local void free_linkedlist(linkedlist_data* ll) -{ - free_datablock(ll->first_block); - ll->first_block = ll->last_block = NULL; -} - - -local int add_data_in_datablock(linkedlist_data* ll, const void* buf, uLong len) -{ - linkedlist_datablock_internal* ldi; - const unsigned char* from_copy; - - if (ll==NULL) - return ZIP_INTERNALERROR; - - if (ll->last_block == NULL) - { - ll->first_block = ll->last_block = allocate_new_datablock(); - if (ll->first_block == NULL) - return ZIP_INTERNALERROR; - } - - ldi = ll->last_block; - from_copy = (unsigned char*)buf; - - while (len>0) - { - uInt copy_this; - uInt i; - unsigned char* to_copy; - - if (ldi->avail_in_this_block==0) - { - ldi->next_datablock = allocate_new_datablock(); - if (ldi->next_datablock == NULL) - return ZIP_INTERNALERROR; - ldi = ldi->next_datablock ; - ll->last_block = ldi; - } - - if (ldi->avail_in_this_block < len) - copy_this = (uInt)ldi->avail_in_this_block; - else - copy_this = (uInt)len; - - to_copy = &(ldi->data[ldi->filled_in_this_block]); - - for (i=0;ifilled_in_this_block += copy_this; - ldi->avail_in_this_block -= copy_this; - from_copy += copy_this ; - len -= copy_this; - } - return ZIP_OK; -} - - - -/****************************************************************************/ - -#ifndef NO_ADDFILEINEXISTINGZIP -/* =========================================================================== - Inputs a long in LSB order to the given file - nbByte == 1, 2 ,4 or 8 (byte, short or long, ZPOS64_T) -*/ - -local int zip64local_putValue OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte)); -local int zip64local_putValue (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte) -{ - unsigned char buf[8]; - int n; - for (n = 0; n < nbByte; n++) - { - buf[n] = (unsigned char)(x & 0xff); - x >>= 8; - } - if (x != 0) - { /* data overflow - hack for ZIP64 (X Roche) */ - for (n = 0; n < nbByte; n++) - { - buf[n] = 0xff; - } - } - - if (ZWRITE64(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte) - return ZIP_ERRNO; - else - return ZIP_OK; -} - -local void zip64local_putValue_inmemory OF((void* dest, ZPOS64_T x, int nbByte)); -local void zip64local_putValue_inmemory (void* dest, ZPOS64_T x, int nbByte) -{ - unsigned char* buf=(unsigned char*)dest; - int n; - for (n = 0; n < nbByte; n++) { - buf[n] = (unsigned char)(x & 0xff); - x >>= 8; - } - - if (x != 0) - { /* data overflow - hack for ZIP64 */ - for (n = 0; n < nbByte; n++) - { - buf[n] = 0xff; - } - } -} - -/****************************************************************************/ - - -local uLong zip64local_TmzDateToDosDate(const tm_zip* ptm) -{ - uLong year = (uLong)ptm->tm_year; - if (year>=1980) - year-=1980; - else if (year>=80) - year-=80; - return - (uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) | - ((ptm->tm_sec/2) + (32* ptm->tm_min) + (2048 * (uLong)ptm->tm_hour)); -} - - -/****************************************************************************/ - -local int zip64local_getByte OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi)); - -local int zip64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def,voidpf filestream,int* pi) -{ - unsigned char c; - int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1); - if (err==1) - { - *pi = (int)c; - return ZIP_OK; - } - else - { - if (ZERROR64(*pzlib_filefunc_def,filestream)) - return ZIP_ERRNO; - else - return ZIP_EOF; - } -} - - -/* =========================================================================== - Reads a long in LSB order from the given gz_stream. Sets -*/ -local int zip64local_getShort OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX)); - -local int zip64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX) -{ - uLong x ; - int i = 0; - int err; - - err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); - x = (uLong)i; - - if (err==ZIP_OK) - err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); - x += ((uLong)i)<<8; - - if (err==ZIP_OK) - *pX = x; - else - *pX = 0; - return err; -} - -local int zip64local_getLong OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX)); - -local int zip64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX) -{ - uLong x ; - int i = 0; - int err; - - err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); - x = (uLong)i; - - if (err==ZIP_OK) - err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); - x += ((uLong)i)<<8; - - if (err==ZIP_OK) - err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); - x += ((uLong)i)<<16; - - if (err==ZIP_OK) - err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); - x += ((uLong)i)<<24; - - if (err==ZIP_OK) - *pX = x; - else - *pX = 0; - return err; -} - -local int zip64local_getLong64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)); - - -local int zip64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX) -{ - ZPOS64_T x; - int i = 0; - int err; - - err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); - x = (ZPOS64_T)i; - - if (err==ZIP_OK) - err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); - x += ((ZPOS64_T)i)<<8; - - if (err==ZIP_OK) - err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); - x += ((ZPOS64_T)i)<<16; - - if (err==ZIP_OK) - err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); - x += ((ZPOS64_T)i)<<24; - - if (err==ZIP_OK) - err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); - x += ((ZPOS64_T)i)<<32; - - if (err==ZIP_OK) - err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); - x += ((ZPOS64_T)i)<<40; - - if (err==ZIP_OK) - err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); - x += ((ZPOS64_T)i)<<48; - - if (err==ZIP_OK) - err = zip64local_getByte(pzlib_filefunc_def,filestream,&i); - x += ((ZPOS64_T)i)<<56; - - if (err==ZIP_OK) - *pX = x; - else - *pX = 0; - - return err; -} - -#ifndef BUFREADCOMMENT -#define BUFREADCOMMENT (0x400) -#endif -/* - Locate the Central directory of a zipfile (at the end, just before - the global comment) -*/ -local ZPOS64_T zip64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)); - -local ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) -{ - unsigned char* buf; - ZPOS64_T uSizeFile; - ZPOS64_T uBackRead; - ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ - ZPOS64_T uPosFound=0; - - if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) - return 0; - - - uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); - - if (uMaxBack>uSizeFile) - uMaxBack = uSizeFile; - - buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); - if (buf==NULL) - return 0; - - uBackRead = 4; - while (uBackReaduMaxBack) - uBackRead = uMaxBack; - else - uBackRead+=BUFREADCOMMENT; - uReadPos = uSizeFile-uBackRead ; - - uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? - (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); - if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) - break; - - if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) - break; - - for (i=(int)uReadSize-3; (i--)>0;) - if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && - ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) - { - uPosFound = uReadPos+i; - break; - } - - if (uPosFound!=0) - break; - } - TRYFREE(buf); - return uPosFound; -} - -/* -Locate the End of Zip64 Central directory locator and from there find the CD of a zipfile (at the end, just before -the global comment) -*/ -local ZPOS64_T zip64local_SearchCentralDir64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)); - -local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) -{ - unsigned char* buf; - ZPOS64_T uSizeFile; - ZPOS64_T uBackRead; - ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ - ZPOS64_T uPosFound=0; - uLong uL; - ZPOS64_T relativeOffset; - - if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) - return 0; - - uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); - - if (uMaxBack>uSizeFile) - uMaxBack = uSizeFile; - - buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); - if (buf==NULL) - return 0; - - uBackRead = 4; - while (uBackReaduMaxBack) - uBackRead = uMaxBack; - else - uBackRead+=BUFREADCOMMENT; - uReadPos = uSizeFile-uBackRead ; - - uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? - (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); - if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) - break; - - if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) - break; - - for (i=(int)uReadSize-3; (i--)>0;) - { - // Signature "0x07064b50" Zip64 end of central directory locater - if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07)) - { - uPosFound = uReadPos+i; - break; - } - } - - if (uPosFound!=0) - break; - } - - TRYFREE(buf); - if (uPosFound == 0) - return 0; - - /* Zip64 end of central directory locator */ - if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0) - return 0; - - /* the signature, already checked */ - if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK) - return 0; - - /* number of the disk with the start of the zip64 end of central directory */ - if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK) - return 0; - if (uL != 0) - return 0; - - /* relative offset of the zip64 end of central directory record */ - if (zip64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=ZIP_OK) - return 0; - - /* total number of disks */ - if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK) - return 0; - if (uL != 1) - return 0; - - /* Goto Zip64 end of central directory record */ - if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0) - return 0; - - /* the signature */ - if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK) - return 0; - - if (uL != 0x06064b50) // signature of 'Zip64 end of central directory' - return 0; - - return relativeOffset; -} - -int LoadCentralDirectoryRecord(zip64_internal* pziinit) -{ - int err=ZIP_OK; - ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ - - ZPOS64_T size_central_dir; /* size of the central directory */ - ZPOS64_T offset_central_dir; /* offset of start of central directory */ - ZPOS64_T central_pos; - uLong uL; - - uLong number_disk; /* number of the current dist, used for - spaning ZIP, unsupported, always 0*/ - uLong number_disk_with_CD; /* number the the disk with central dir, used - for spaning ZIP, unsupported, always 0*/ - ZPOS64_T number_entry; - ZPOS64_T number_entry_CD; /* total number of entries in - the central dir - (same than number_entry on nospan) */ - uLong VersionMadeBy; - uLong VersionNeeded; - uLong size_comment; - - int hasZIP64Record = 0; - - // check first if we find a ZIP64 record - central_pos = zip64local_SearchCentralDir64(&pziinit->z_filefunc,pziinit->filestream); - if(central_pos > 0) - { - hasZIP64Record = 1; - } - else if(central_pos == 0) - { - central_pos = zip64local_SearchCentralDir(&pziinit->z_filefunc,pziinit->filestream); - } - -/* disable to allow appending to empty ZIP archive - if (central_pos==0) - err=ZIP_ERRNO; -*/ - - if(hasZIP64Record) - { - ZPOS64_T sizeEndOfCentralDirectory; - if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos, ZLIB_FILEFUNC_SEEK_SET) != 0) - err=ZIP_ERRNO; - - /* the signature, already checked */ - if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK) - err=ZIP_ERRNO; - - /* size of zip64 end of central directory record */ - if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &sizeEndOfCentralDirectory)!=ZIP_OK) - err=ZIP_ERRNO; - - /* version made by */ - if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionMadeBy)!=ZIP_OK) - err=ZIP_ERRNO; - - /* version needed to extract */ - if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionNeeded)!=ZIP_OK) - err=ZIP_ERRNO; - - /* number of this disk */ - if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK) - err=ZIP_ERRNO; - - /* number of the disk with the start of the central directory */ - if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK) - err=ZIP_ERRNO; - - /* total number of entries in the central directory on this disk */ - if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &number_entry)!=ZIP_OK) - err=ZIP_ERRNO; - - /* total number of entries in the central directory */ - if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&number_entry_CD)!=ZIP_OK) - err=ZIP_ERRNO; - - if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0)) - err=ZIP_BADZIPFILE; - - /* size of the central directory */ - if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&size_central_dir)!=ZIP_OK) - err=ZIP_ERRNO; - - /* offset of start of central directory with respect to the - starting disk number */ - if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&offset_central_dir)!=ZIP_OK) - err=ZIP_ERRNO; - - // TODO.. - // read the comment from the standard central header. - size_comment = 0; - } - else - { - // Read End of central Directory info - if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) - err=ZIP_ERRNO; - - /* the signature, already checked */ - if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK) - err=ZIP_ERRNO; - - /* number of this disk */ - if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK) - err=ZIP_ERRNO; - - /* number of the disk with the start of the central directory */ - if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK) - err=ZIP_ERRNO; - - /* total number of entries in the central dir on this disk */ - number_entry = 0; - if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK) - err=ZIP_ERRNO; - else - number_entry = uL; - - /* total number of entries in the central dir */ - number_entry_CD = 0; - if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK) - err=ZIP_ERRNO; - else - number_entry_CD = uL; - - if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0)) - err=ZIP_BADZIPFILE; - - /* size of the central directory */ - size_central_dir = 0; - if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK) - err=ZIP_ERRNO; - else - size_central_dir = uL; - - /* offset of start of central directory with respect to the starting disk number */ - offset_central_dir = 0; - if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK) - err=ZIP_ERRNO; - else - offset_central_dir = uL; - - - /* zipfile global comment length */ - if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &size_comment)!=ZIP_OK) - err=ZIP_ERRNO; - } - - if ((central_posz_filefunc, pziinit->filestream); - return ZIP_ERRNO; - } - - if (size_comment>0) - { - pziinit->globalcomment = (char*)ALLOC(size_comment+1); - if (pziinit->globalcomment) - { - size_comment = ZREAD64(pziinit->z_filefunc, pziinit->filestream, pziinit->globalcomment,size_comment); - pziinit->globalcomment[size_comment]=0; - } - } - - byte_before_the_zipfile = central_pos - (offset_central_dir+size_central_dir); - pziinit->add_position_when_writting_offset = byte_before_the_zipfile; - - { - ZPOS64_T size_central_dir_to_read = size_central_dir; - size_t buf_size = SIZEDATA_INDATABLOCK; - void* buf_read = (void*)ALLOC(buf_size); - if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir + byte_before_the_zipfile, ZLIB_FILEFUNC_SEEK_SET) != 0) - err=ZIP_ERRNO; - - while ((size_central_dir_to_read>0) && (err==ZIP_OK)) - { - ZPOS64_T read_this = SIZEDATA_INDATABLOCK; - if (read_this > size_central_dir_to_read) - read_this = size_central_dir_to_read; - - if (ZREAD64(pziinit->z_filefunc, pziinit->filestream,buf_read,(uLong)read_this) != read_this) - err=ZIP_ERRNO; - - if (err==ZIP_OK) - err = add_data_in_datablock(&pziinit->central_dir,buf_read, (uLong)read_this); - - size_central_dir_to_read-=read_this; - } - TRYFREE(buf_read); - } - pziinit->begin_pos = byte_before_the_zipfile; - pziinit->number_entry = number_entry_CD; - - if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET) != 0) - err=ZIP_ERRNO; - - return err; -} - - -#endif /* !NO_ADDFILEINEXISTINGZIP*/ - - -/************************************************************/ -extern zipFile ZEXPORT zipOpen3 (const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_32_def* pzlib_filefunc64_32_def) -{ - zip64_internal ziinit; - zip64_internal* zi; - int err=ZIP_OK; - - ziinit.z_filefunc.zseek32_file = NULL; - ziinit.z_filefunc.ztell32_file = NULL; - if (pzlib_filefunc64_32_def==NULL) - fill_fopen64_filefunc(&ziinit.z_filefunc.zfile_func64); - else - ziinit.z_filefunc = *pzlib_filefunc64_32_def; - - ziinit.filestream = ZOPEN64(ziinit.z_filefunc, - pathname, - (append == APPEND_STATUS_CREATE) ? - (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE) : - (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING)); - - if (ziinit.filestream == NULL) - return NULL; - - if (append == APPEND_STATUS_CREATEAFTER) - ZSEEK64(ziinit.z_filefunc,ziinit.filestream,0,SEEK_END); - - ziinit.begin_pos = ZTELL64(ziinit.z_filefunc,ziinit.filestream); - ziinit.in_opened_file_inzip = 0; - ziinit.ci.stream_initialised = 0; - ziinit.number_entry = 0; - ziinit.add_position_when_writting_offset = 0; - init_linkedlist(&(ziinit.central_dir)); - - - - zi = (zip64_internal*)ALLOC(sizeof(zip64_internal)); - if (zi==NULL) - { - ZCLOSE64(ziinit.z_filefunc,ziinit.filestream); - return NULL; - } - - /* now we add file in a zipfile */ -# ifndef NO_ADDFILEINEXISTINGZIP - ziinit.globalcomment = NULL; - if (append == APPEND_STATUS_ADDINZIP) - { - // Read and Cache Central Directory Records - err = LoadCentralDirectoryRecord(&ziinit); - } - - if (globalcomment) - { - *globalcomment = ziinit.globalcomment; - } -# endif /* !NO_ADDFILEINEXISTINGZIP*/ - - if (err != ZIP_OK) - { -# ifndef NO_ADDFILEINEXISTINGZIP - TRYFREE(ziinit.globalcomment); -# endif /* !NO_ADDFILEINEXISTINGZIP*/ - TRYFREE(zi); - return NULL; - } - else - { - *zi = ziinit; - return (zipFile)zi; - } -} - -extern zipFile ZEXPORT zipOpen2 (const char *pathname, int append, zipcharpc* globalcomment, zlib_filefunc_def* pzlib_filefunc32_def) -{ - if (pzlib_filefunc32_def != NULL) - { - zlib_filefunc64_32_def zlib_filefunc64_32_def_fill; - fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def); - return zipOpen3(pathname, append, globalcomment, &zlib_filefunc64_32_def_fill); - } - else - return zipOpen3(pathname, append, globalcomment, NULL); -} - -extern zipFile ZEXPORT zipOpen2_64 (const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_def* pzlib_filefunc_def) -{ - if (pzlib_filefunc_def != NULL) - { - zlib_filefunc64_32_def zlib_filefunc64_32_def_fill; - zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def; - zlib_filefunc64_32_def_fill.ztell32_file = NULL; - zlib_filefunc64_32_def_fill.zseek32_file = NULL; - return zipOpen3(pathname, append, globalcomment, &zlib_filefunc64_32_def_fill); - } - else - return zipOpen3(pathname, append, globalcomment, NULL); -} - - - -extern zipFile ZEXPORT zipOpen (const char* pathname, int append) -{ - return zipOpen3((const void*)pathname,append,NULL,NULL); -} - -extern zipFile ZEXPORT zipOpen64 (const void* pathname, int append) -{ - return zipOpen3(pathname,append,NULL,NULL); -} - -int Write_LocalFileHeader(zip64_internal* zi, const char* filename, uInt size_extrafield_local, const void* extrafield_local) -{ - /* write the local header */ - int err; - uInt size_filename = (uInt)strlen(filename); - uInt size_extrafield = size_extrafield_local; - - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)LOCALHEADERMAGIC, 4); - - if (err==ZIP_OK) - { - if(zi->ci.zip64) - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);/* version needed to extract */ - else - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)20,2);/* version needed to extract */ - } - - if (err==ZIP_OK) - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.flag,2); - - if (err==ZIP_OK) - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.method,2); - - if (err==ZIP_OK) - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4); - - // CRC / Compressed size / Uncompressed size will be filled in later and rewritten later - if (err==ZIP_OK) - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */ - if (err==ZIP_OK) - { - if(zi->ci.zip64) - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xFFFFFFFF,4); /* compressed size, unknown */ - else - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* compressed size, unknown */ - } - if (err==ZIP_OK) - { - if(zi->ci.zip64) - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xFFFFFFFF,4); /* uncompressed size, unknown */ - else - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* uncompressed size, unknown */ - } - - if (err==ZIP_OK) - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_filename,2); - - if(zi->ci.zip64) - { - size_extrafield += 20; - } - - if (err==ZIP_OK) - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_extrafield,2); - - if ((err==ZIP_OK) && (size_filename > 0)) - { - if (ZWRITE64(zi->z_filefunc,zi->filestream,filename,size_filename)!=size_filename) - err = ZIP_ERRNO; - } - - if ((err==ZIP_OK) && (size_extrafield_local > 0)) - { - if (ZWRITE64(zi->z_filefunc, zi->filestream, extrafield_local, size_extrafield_local) != size_extrafield_local) - err = ZIP_ERRNO; - } - - - if ((err==ZIP_OK) && (zi->ci.zip64)) - { - // write the Zip64 extended info - short HeaderID = 1; - short DataSize = 16; - ZPOS64_T CompressedSize = 0; - ZPOS64_T UncompressedSize = 0; - - // Remember position of Zip64 extended info for the local file header. (needed when we update size after done with file) - zi->ci.pos_zip64extrainfo = ZTELL64(zi->z_filefunc,zi->filestream); - - err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (short)HeaderID,2); - err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (short)DataSize,2); - - err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)UncompressedSize,8); - err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)CompressedSize,8); - } - - return err; -} - -/* - NOTE. - When writing RAW the ZIP64 extended information in extrafield_local and extrafield_global needs to be stripped - before calling this function it can be done with zipRemoveExtraInfoBlock - - It is not done here because then we need to realloc a new buffer since parameters are 'const' and I want to minimize - unnecessary allocations. - */ -extern int ZEXPORT zipOpenNewFileInZip4_64 (zipFile file, const char* filename, const zip_fileinfo* zipfi, - const void* extrafield_local, uInt size_extrafield_local, - const void* extrafield_global, uInt size_extrafield_global, - const char* comment, int method, int level, int raw, - int windowBits,int memLevel, int strategy, - const char* password, uLong crcForCrypting, - uLong versionMadeBy, uLong flagBase, int zip64) -{ - zip64_internal* zi; - uInt size_filename; - uInt size_comment; - uInt i; - int err = ZIP_OK; - -# ifdef NOCRYPT - (crcForCrypting); - if (password != NULL) - return ZIP_PARAMERROR; -# endif - - if (file == NULL) - return ZIP_PARAMERROR; - -#ifdef HAVE_BZIP2 - if ((method!=0) && (method!=Z_DEFLATED) && (method!=Z_BZIP2ED)) - return ZIP_PARAMERROR; -#else - if ((method!=0) && (method!=Z_DEFLATED)) - return ZIP_PARAMERROR; -#endif - - zi = (zip64_internal*)file; - - if (zi->in_opened_file_inzip == 1) - { - err = zipCloseFileInZip (file); - if (err != ZIP_OK) - return err; - } - - if (filename==NULL) - filename="-"; - - if (comment==NULL) - size_comment = 0; - else - size_comment = (uInt)strlen(comment); - - size_filename = (uInt)strlen(filename); - - if (zipfi == NULL) - zi->ci.dosDate = 0; - else - { - if (zipfi->dosDate != 0) - zi->ci.dosDate = zipfi->dosDate; - else - zi->ci.dosDate = zip64local_TmzDateToDosDate(&zipfi->tmz_date); - } - - zi->ci.flag = flagBase; - if ((level==8) || (level==9)) - zi->ci.flag |= 2; - if (level==2) - zi->ci.flag |= 4; - if (level==1) - zi->ci.flag |= 6; - if (password != NULL) - zi->ci.flag |= 1; - - zi->ci.crc32 = 0; - zi->ci.method = method; - zi->ci.encrypt = 0; - zi->ci.stream_initialised = 0; - zi->ci.pos_in_buffered_data = 0; - zi->ci.raw = raw; - zi->ci.pos_local_header = ZTELL64(zi->z_filefunc,zi->filestream); - - zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + size_extrafield_global + size_comment; - zi->ci.size_centralExtraFree = 32; // Extra space we have reserved in case we need to add ZIP64 extra info data - - zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader + zi->ci.size_centralExtraFree); - - zi->ci.size_centralExtra = size_extrafield_global; - zip64local_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4); - /* version info */ - zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)versionMadeBy,2); - zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)20,2); - zip64local_putValue_inmemory(zi->ci.central_header+8,(uLong)zi->ci.flag,2); - zip64local_putValue_inmemory(zi->ci.central_header+10,(uLong)zi->ci.method,2); - zip64local_putValue_inmemory(zi->ci.central_header+12,(uLong)zi->ci.dosDate,4); - zip64local_putValue_inmemory(zi->ci.central_header+16,(uLong)0,4); /*crc*/ - zip64local_putValue_inmemory(zi->ci.central_header+20,(uLong)0,4); /*compr size*/ - zip64local_putValue_inmemory(zi->ci.central_header+24,(uLong)0,4); /*uncompr size*/ - zip64local_putValue_inmemory(zi->ci.central_header+28,(uLong)size_filename,2); - zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)size_extrafield_global,2); - zip64local_putValue_inmemory(zi->ci.central_header+32,(uLong)size_comment,2); - zip64local_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/ - - if (zipfi==NULL) - zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2); - else - zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2); - - if (zipfi==NULL) - zip64local_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4); - else - zip64local_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4); - - if(zi->ci.pos_local_header >= 0xffffffff) - zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)0xffffffff,4); - else - zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header - zi->add_position_when_writting_offset,4); - - for (i=0;ici.central_header+SIZECENTRALHEADER+i) = *(filename+i); - - for (i=0;ici.central_header+SIZECENTRALHEADER+size_filename+i) = - *(((const char*)extrafield_global)+i); - - for (i=0;ici.central_header+SIZECENTRALHEADER+size_filename+ - size_extrafield_global+i) = *(comment+i); - if (zi->ci.central_header == NULL) - return ZIP_INTERNALERROR; - - zi->ci.zip64 = zip64; - zi->ci.totalCompressedData = 0; - zi->ci.totalUncompressedData = 0; - zi->ci.pos_zip64extrainfo = 0; - - err = Write_LocalFileHeader(zi, filename, size_extrafield_local, extrafield_local); - -#ifdef HAVE_BZIP2 - zi->ci.bstream.avail_in = (uInt)0; - zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE; - zi->ci.bstream.next_out = (char*)zi->ci.buffered_data; - zi->ci.bstream.total_in_hi32 = 0; - zi->ci.bstream.total_in_lo32 = 0; - zi->ci.bstream.total_out_hi32 = 0; - zi->ci.bstream.total_out_lo32 = 0; -#endif - - zi->ci.stream.avail_in = (uInt)0; - zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; - zi->ci.stream.next_out = zi->ci.buffered_data; - zi->ci.stream.total_in = 0; - zi->ci.stream.total_out = 0; - zi->ci.stream.data_type = Z_BINARY; - -#ifdef HAVE_BZIP2 - if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED || zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw)) -#else - if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) -#endif - { - if(zi->ci.method == Z_DEFLATED) - { - zi->ci.stream.zalloc = (alloc_func)0; - zi->ci.stream.zfree = (free_func)0; - zi->ci.stream.opaque = (voidpf)0; - - if (windowBits>0) - windowBits = -windowBits; - - err = deflateInit2(&zi->ci.stream, level, Z_DEFLATED, windowBits, memLevel, strategy); - - if (err==Z_OK) - zi->ci.stream_initialised = Z_DEFLATED; - } - else if(zi->ci.method == Z_BZIP2ED) - { -#ifdef HAVE_BZIP2 - // Init BZip stuff here - zi->ci.bstream.bzalloc = 0; - zi->ci.bstream.bzfree = 0; - zi->ci.bstream.opaque = (voidpf)0; - - err = BZ2_bzCompressInit(&zi->ci.bstream, level, 0,35); - if(err == BZ_OK) - zi->ci.stream_initialised = Z_BZIP2ED; -#endif - } - - } - -# ifndef NOCRYPT - zi->ci.crypt_header_size = 0; - if ((err==Z_OK) && (password != NULL)) - { - unsigned char bufHead[RAND_HEAD_LEN]; - unsigned int sizeHead; - zi->ci.encrypt = 1; - zi->ci.pcrc_32_tab = get_crc_table(); - /*init_keys(password,zi->ci.keys,zi->ci.pcrc_32_tab);*/ - - sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,crcForCrypting); - zi->ci.crypt_header_size = sizeHead; - - if (ZWRITE64(zi->z_filefunc,zi->filestream,bufHead,sizeHead) != sizeHead) - err = ZIP_ERRNO; - } -# endif - - if (err==Z_OK) - zi->in_opened_file_inzip = 1; - return err; -} - -extern int ZEXPORT zipOpenNewFileInZip4 (zipFile file, const char* filename, const zip_fileinfo* zipfi, - const void* extrafield_local, uInt size_extrafield_local, - const void* extrafield_global, uInt size_extrafield_global, - const char* comment, int method, int level, int raw, - int windowBits,int memLevel, int strategy, - const char* password, uLong crcForCrypting, - uLong versionMadeBy, uLong flagBase) -{ - return zipOpenNewFileInZip4_64 (file, filename, zipfi, - extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, - comment, method, level, raw, - windowBits, memLevel, strategy, - password, crcForCrypting, versionMadeBy, flagBase, 0); -} - -extern int ZEXPORT zipOpenNewFileInZip3 (zipFile file, const char* filename, const zip_fileinfo* zipfi, - const void* extrafield_local, uInt size_extrafield_local, - const void* extrafield_global, uInt size_extrafield_global, - const char* comment, int method, int level, int raw, - int windowBits,int memLevel, int strategy, - const char* password, uLong crcForCrypting) -{ - return zipOpenNewFileInZip4_64 (file, filename, zipfi, - extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, - comment, method, level, raw, - windowBits, memLevel, strategy, - password, crcForCrypting, VERSIONMADEBY, 0, 0); -} - -extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char* filename, const zip_fileinfo* zipfi, - const void* extrafield_local, uInt size_extrafield_local, - const void* extrafield_global, uInt size_extrafield_global, - const char* comment, int method, int level, int raw, - int windowBits,int memLevel, int strategy, - const char* password, uLong crcForCrypting, int zip64) -{ - return zipOpenNewFileInZip4_64 (file, filename, zipfi, - extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, - comment, method, level, raw, - windowBits, memLevel, strategy, - password, crcForCrypting, VERSIONMADEBY, 0, zip64); -} - -extern int ZEXPORT zipOpenNewFileInZip2(zipFile file, const char* filename, const zip_fileinfo* zipfi, - const void* extrafield_local, uInt size_extrafield_local, - const void* extrafield_global, uInt size_extrafield_global, - const char* comment, int method, int level, int raw) -{ - return zipOpenNewFileInZip4_64 (file, filename, zipfi, - extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, - comment, method, level, raw, - -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, - NULL, 0, VERSIONMADEBY, 0, 0); -} - -extern int ZEXPORT zipOpenNewFileInZip2_64(zipFile file, const char* filename, const zip_fileinfo* zipfi, - const void* extrafield_local, uInt size_extrafield_local, - const void* extrafield_global, uInt size_extrafield_global, - const char* comment, int method, int level, int raw, int zip64) -{ - return zipOpenNewFileInZip4_64 (file, filename, zipfi, - extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, - comment, method, level, raw, - -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, - NULL, 0, VERSIONMADEBY, 0, zip64); -} - -extern int ZEXPORT zipOpenNewFileInZip64 (zipFile file, const char* filename, const zip_fileinfo* zipfi, - const void* extrafield_local, uInt size_extrafield_local, - const void*extrafield_global, uInt size_extrafield_global, - const char* comment, int method, int level, int zip64) -{ - return zipOpenNewFileInZip4_64 (file, filename, zipfi, - extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, - comment, method, level, 0, - -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, - NULL, 0, VERSIONMADEBY, 0, zip64); -} - -extern int ZEXPORT zipOpenNewFileInZip (zipFile file, const char* filename, const zip_fileinfo* zipfi, - const void* extrafield_local, uInt size_extrafield_local, - const void*extrafield_global, uInt size_extrafield_global, - const char* comment, int method, int level) -{ - return zipOpenNewFileInZip4_64 (file, filename, zipfi, - extrafield_local, size_extrafield_local, - extrafield_global, size_extrafield_global, - comment, method, level, 0, - -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, - NULL, 0, VERSIONMADEBY, 0, 0); -} - -local int zip64FlushWriteBuffer(zip64_internal* zi) -{ - int err=ZIP_OK; - - if (zi->ci.encrypt != 0) - { -#ifndef NOCRYPT - uInt i; - int t; - for (i=0;ici.pos_in_buffered_data;i++) - zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab, zi->ci.buffered_data[i],t); -#endif - } - - if (ZWRITE64(zi->z_filefunc,zi->filestream,zi->ci.buffered_data,zi->ci.pos_in_buffered_data) != zi->ci.pos_in_buffered_data) - err = ZIP_ERRNO; - - zi->ci.totalCompressedData += zi->ci.pos_in_buffered_data; - -#ifdef HAVE_BZIP2 - if(zi->ci.method == Z_BZIP2ED) - { - zi->ci.totalUncompressedData += zi->ci.bstream.total_in_lo32; - zi->ci.bstream.total_in_lo32 = 0; - zi->ci.bstream.total_in_hi32 = 0; - } - else -#endif - { - zi->ci.totalUncompressedData += zi->ci.stream.total_in; - zi->ci.stream.total_in = 0; - } - - - zi->ci.pos_in_buffered_data = 0; - - return err; -} - -extern int ZEXPORT zipWriteInFileInZip (zipFile file,const void* buf,unsigned int len) -{ - zip64_internal* zi; - int err=ZIP_OK; - - if (file == NULL) - return ZIP_PARAMERROR; - zi = (zip64_internal*)file; - - if (zi->in_opened_file_inzip == 0) - return ZIP_PARAMERROR; - - zi->ci.crc32 = crc32(zi->ci.crc32,buf,(uInt)len); - -#ifdef HAVE_BZIP2 - if(zi->ci.method == Z_BZIP2ED && (!zi->ci.raw)) - { - zi->ci.bstream.next_in = (void*)buf; - zi->ci.bstream.avail_in = len; - err = BZ_RUN_OK; - - while ((err==BZ_RUN_OK) && (zi->ci.bstream.avail_in>0)) - { - if (zi->ci.bstream.avail_out == 0) - { - if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO) - err = ZIP_ERRNO; - zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE; - zi->ci.bstream.next_out = (char*)zi->ci.buffered_data; - } - - - if(err != BZ_RUN_OK) - break; - - if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw)) - { - uLong uTotalOutBefore_lo = zi->ci.bstream.total_out_lo32; -// uLong uTotalOutBefore_hi = zi->ci.bstream.total_out_hi32; - err=BZ2_bzCompress(&zi->ci.bstream, BZ_RUN); - - zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore_lo) ; - } - } - - if(err == BZ_RUN_OK) - err = ZIP_OK; - } - else -#endif - { - zi->ci.stream.next_in = (Bytef*)buf; - zi->ci.stream.avail_in = len; - - while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0)) - { - if (zi->ci.stream.avail_out == 0) - { - if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO) - err = ZIP_ERRNO; - zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; - zi->ci.stream.next_out = zi->ci.buffered_data; - } - - - if(err != ZIP_OK) - break; - - if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) - { - uLong uTotalOutBefore = zi->ci.stream.total_out; - err=deflate(&zi->ci.stream, Z_NO_FLUSH); - if(uTotalOutBefore > zi->ci.stream.total_out) - { - int bBreak = 0; - bBreak++; - } - - zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ; - } - else - { - uInt copy_this,i; - if (zi->ci.stream.avail_in < zi->ci.stream.avail_out) - copy_this = zi->ci.stream.avail_in; - else - copy_this = zi->ci.stream.avail_out; - - for (i = 0; i < copy_this; i++) - *(((char*)zi->ci.stream.next_out)+i) = - *(((const char*)zi->ci.stream.next_in)+i); - { - zi->ci.stream.avail_in -= copy_this; - zi->ci.stream.avail_out-= copy_this; - zi->ci.stream.next_in+= copy_this; - zi->ci.stream.next_out+= copy_this; - zi->ci.stream.total_in+= copy_this; - zi->ci.stream.total_out+= copy_this; - zi->ci.pos_in_buffered_data += copy_this; - } - } - }// while(...) - } - - return err; -} - -extern int ZEXPORT zipCloseFileInZipRaw (zipFile file, uLong uncompressed_size, uLong crc32) -{ - return zipCloseFileInZipRaw64 (file, uncompressed_size, crc32); -} - -extern int ZEXPORT zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_size, uLong crc32) -{ - zip64_internal* zi; - ZPOS64_T compressed_size; - uLong invalidValue = 0xffffffff; - short datasize = 0; - int err=ZIP_OK; - - if (file == NULL) - return ZIP_PARAMERROR; - zi = (zip64_internal*)file; - - if (zi->in_opened_file_inzip == 0) - return ZIP_PARAMERROR; - zi->ci.stream.avail_in = 0; - - if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) - { - while (err==ZIP_OK) - { - uLong uTotalOutBefore; - if (zi->ci.stream.avail_out == 0) - { - if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO) - err = ZIP_ERRNO; - zi->ci.stream.avail_out = (uInt)Z_BUFSIZE; - zi->ci.stream.next_out = zi->ci.buffered_data; - } - uTotalOutBefore = zi->ci.stream.total_out; - err=deflate(&zi->ci.stream, Z_FINISH); - zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ; - } - } - else if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw)) - { -#ifdef HAVE_BZIP2 - err = BZ_FINISH_OK; - while (err==BZ_FINISH_OK) - { - uLong uTotalOutBefore; - if (zi->ci.bstream.avail_out == 0) - { - if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO) - err = ZIP_ERRNO; - zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE; - zi->ci.bstream.next_out = (char*)zi->ci.buffered_data; - } - uTotalOutBefore = zi->ci.bstream.total_out_lo32; - err=BZ2_bzCompress(&zi->ci.bstream, BZ_FINISH); - if(err == BZ_STREAM_END) - err = Z_STREAM_END; - - zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore); - } - - if(err == BZ_FINISH_OK) - err = ZIP_OK; -#endif - } - - if (err==Z_STREAM_END) - err=ZIP_OK; /* this is normal */ - - if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK)) - { - if (zip64FlushWriteBuffer(zi)==ZIP_ERRNO) - err = ZIP_ERRNO; - } - - if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw)) - { - int tmp_err = deflateEnd(&zi->ci.stream); - if (err == ZIP_OK) - err = tmp_err; - zi->ci.stream_initialised = 0; - } -#ifdef HAVE_BZIP2 - else if((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw)) - { - int tmperr = BZ2_bzCompressEnd(&zi->ci.bstream); - if (err==ZIP_OK) - err = tmperr; - zi->ci.stream_initialised = 0; - } -#endif - - if (!zi->ci.raw) - { - crc32 = (uLong)zi->ci.crc32; - uncompressed_size = zi->ci.totalUncompressedData; - } - compressed_size = zi->ci.totalCompressedData; - -# ifndef NOCRYPT - compressed_size += zi->ci.crypt_header_size; -# endif - - // update Current Item crc and sizes, - if(compressed_size >= 0xffffffff || uncompressed_size >= 0xffffffff || zi->ci.pos_local_header >= 0xffffffff) - { - /*version Made by*/ - zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)45,2); - /*version needed*/ - zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)45,2); - - } - - zip64local_putValue_inmemory(zi->ci.central_header+16,crc32,4); /*crc*/ - - - if(compressed_size >= 0xffffffff) - zip64local_putValue_inmemory(zi->ci.central_header+20, invalidValue,4); /*compr size*/ - else - zip64local_putValue_inmemory(zi->ci.central_header+20, compressed_size,4); /*compr size*/ - - /// set internal file attributes field - if (zi->ci.stream.data_type == Z_ASCII) - zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2); - - if(uncompressed_size >= 0xffffffff) - zip64local_putValue_inmemory(zi->ci.central_header+24, invalidValue,4); /*uncompr size*/ - else - zip64local_putValue_inmemory(zi->ci.central_header+24, uncompressed_size,4); /*uncompr size*/ - - // Add ZIP64 extra info field for uncompressed size - if(uncompressed_size >= 0xffffffff) - datasize += 8; - - // Add ZIP64 extra info field for compressed size - if(compressed_size >= 0xffffffff) - datasize += 8; - - // Add ZIP64 extra info field for relative offset to local file header of current file - if(zi->ci.pos_local_header >= 0xffffffff) - datasize += 8; - - if(datasize > 0) - { - char* p = NULL; - - if((uLong)(datasize + 4) > zi->ci.size_centralExtraFree) - { - // we can not write more data to the buffer that we have room for. - return ZIP_BADZIPFILE; - } - - p = zi->ci.central_header + zi->ci.size_centralheader; - - // Add Extra Information Header for 'ZIP64 information' - zip64local_putValue_inmemory(p, 0x0001, 2); // HeaderID - p += 2; - zip64local_putValue_inmemory(p, datasize, 2); // DataSize - p += 2; - - if(uncompressed_size >= 0xffffffff) - { - zip64local_putValue_inmemory(p, uncompressed_size, 8); - p += 8; - } - - if(compressed_size >= 0xffffffff) - { - zip64local_putValue_inmemory(p, compressed_size, 8); - p += 8; - } - - if(zi->ci.pos_local_header >= 0xffffffff) - { - zip64local_putValue_inmemory(p, zi->ci.pos_local_header, 8); - p += 8; - } - - // Update how much extra free space we got in the memory buffer - // and increase the centralheader size so the new ZIP64 fields are included - // ( 4 below is the size of HeaderID and DataSize field ) - zi->ci.size_centralExtraFree -= datasize + 4; - zi->ci.size_centralheader += datasize + 4; - - // Update the extra info size field - zi->ci.size_centralExtra += datasize + 4; - zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)zi->ci.size_centralExtra,2); - } - - if (err==ZIP_OK) - err = add_data_in_datablock(&zi->central_dir, zi->ci.central_header, (uLong)zi->ci.size_centralheader); - - free(zi->ci.central_header); - - if (err==ZIP_OK) - { - // Update the LocalFileHeader with the new values. - - ZPOS64_T cur_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream); - - if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_local_header + 14,ZLIB_FILEFUNC_SEEK_SET)!=0) - err = ZIP_ERRNO; - - if (err==ZIP_OK) - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */ - - if(uncompressed_size >= 0xffffffff || compressed_size >= 0xffffffff ) - { - if(zi->ci.pos_zip64extrainfo > 0) - { - // Update the size in the ZIP64 extended field. - if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_zip64extrainfo + 4,ZLIB_FILEFUNC_SEEK_SET)!=0) - err = ZIP_ERRNO; - - if (err==ZIP_OK) /* compressed size, unknown */ - err = zip64local_putValue(&zi->z_filefunc, zi->filestream, uncompressed_size, 8); - - if (err==ZIP_OK) /* uncompressed size, unknown */ - err = zip64local_putValue(&zi->z_filefunc, zi->filestream, compressed_size, 8); - } - else - err = ZIP_BADZIPFILE; // Caller passed zip64 = 0, so no room for zip64 info -> fatal - } - else - { - if (err==ZIP_OK) /* compressed size, unknown */ - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4); - - if (err==ZIP_OK) /* uncompressed size, unknown */ - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4); - } - - if (ZSEEK64(zi->z_filefunc,zi->filestream, cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0) - err = ZIP_ERRNO; - } - - zi->number_entry ++; - zi->in_opened_file_inzip = 0; - - return err; -} - -extern int ZEXPORT zipCloseFileInZip (zipFile file) -{ - return zipCloseFileInZipRaw (file,0,0); -} - -int Write_Zip64EndOfCentralDirectoryLocator(zip64_internal* zi, ZPOS64_T zip64eocd_pos_inzip) -{ - int err = ZIP_OK; - ZPOS64_T pos = zip64eocd_pos_inzip - zi->add_position_when_writting_offset; - - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDLOCHEADERMAGIC,4); - - /*num disks*/ - if (err==ZIP_OK) /* number of the disk with the start of the central directory */ - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); - - /*relative offset*/ - if (err==ZIP_OK) /* Relative offset to the Zip64EndOfCentralDirectory */ - err = zip64local_putValue(&zi->z_filefunc,zi->filestream, pos,8); - - /*total disks*/ /* Do not support spawning of disk so always say 1 here*/ - if (err==ZIP_OK) /* number of the disk with the start of the central directory */ - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)1,4); - - return err; -} - -int Write_Zip64EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip) -{ - int err = ZIP_OK; - - uLong Zip64DataSize = 44; - - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDHEADERMAGIC,4); - - if (err==ZIP_OK) /* size of this 'zip64 end of central directory' */ - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)Zip64DataSize,8); // why ZPOS64_T of this ? - - if (err==ZIP_OK) /* version made by */ - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2); - - if (err==ZIP_OK) /* version needed */ - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2); - - if (err==ZIP_OK) /* number of this disk */ - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); - - if (err==ZIP_OK) /* number of the disk with the start of the central directory */ - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); - - if (err==ZIP_OK) /* total number of entries in the central dir on this disk */ - err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8); - - if (err==ZIP_OK) /* total number of entries in the central dir */ - err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8); - - if (err==ZIP_OK) /* size of the central directory */ - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)size_centraldir,8); - - if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */ - { - ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset; - err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (ZPOS64_T)pos,8); - } - return err; -} -int Write_EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip) -{ - int err = ZIP_OK; - - /*signature*/ - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4); - - if (err==ZIP_OK) /* number of this disk */ - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2); - - if (err==ZIP_OK) /* number of the disk with the start of the central directory */ - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2); - - if (err==ZIP_OK) /* total number of entries in the central dir on this disk */ - { - { - if(zi->number_entry >= 0xFFFF) - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); // use value in ZIP64 record - else - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2); - } - } - - if (err==ZIP_OK) /* total number of entries in the central dir */ - { - if(zi->number_entry >= 0xFFFF) - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); // use value in ZIP64 record - else - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2); - } - - if (err==ZIP_OK) /* size of the central directory */ - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4); - - if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */ - { - ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset; - if(pos >= 0xffffffff) - { - err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)0xffffffff,4); - } - else - err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)(centraldir_pos_inzip - zi->add_position_when_writting_offset),4); - } - - return err; -} - -int Write_GlobalComment(zip64_internal* zi, const char* global_comment) -{ - int err = ZIP_OK; - uInt size_global_comment = 0; - - if(global_comment != NULL) - size_global_comment = (uInt)strlen(global_comment); - - err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_global_comment,2); - - if (err == ZIP_OK && size_global_comment > 0) - { - if (ZWRITE64(zi->z_filefunc,zi->filestream, global_comment, size_global_comment) != size_global_comment) - err = ZIP_ERRNO; - } - return err; -} - -extern int ZEXPORT zipClose (zipFile file, const char* global_comment) -{ - zip64_internal* zi; - int err = 0; - uLong size_centraldir = 0; - ZPOS64_T centraldir_pos_inzip; - ZPOS64_T pos; - - if (file == NULL) - return ZIP_PARAMERROR; - - zi = (zip64_internal*)file; - - if (zi->in_opened_file_inzip == 1) - { - err = zipCloseFileInZip (file); - } - -#ifndef NO_ADDFILEINEXISTINGZIP - if (global_comment==NULL) - global_comment = zi->globalcomment; -#endif - - centraldir_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream); - - if (err==ZIP_OK) - { - linkedlist_datablock_internal* ldi = zi->central_dir.first_block; - while (ldi!=NULL) - { - if ((err==ZIP_OK) && (ldi->filled_in_this_block>0)) - { - if (ZWRITE64(zi->z_filefunc,zi->filestream, ldi->data, ldi->filled_in_this_block) != ldi->filled_in_this_block) - err = ZIP_ERRNO; - } - - size_centraldir += ldi->filled_in_this_block; - ldi = ldi->next_datablock; - } - } - free_linkedlist(&(zi->central_dir)); - - pos = centraldir_pos_inzip - zi->add_position_when_writting_offset; - if(pos >= 0xffffffff || zi->number_entry > 0xFFFF) - { - ZPOS64_T Zip64EOCDpos = ZTELL64(zi->z_filefunc,zi->filestream); - Write_Zip64EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip); - - Write_Zip64EndOfCentralDirectoryLocator(zi, Zip64EOCDpos); - } - - if (err==ZIP_OK) - err = Write_EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip); - - if(err == ZIP_OK) - err = Write_GlobalComment(zi, global_comment); - - if (ZCLOSE64(zi->z_filefunc,zi->filestream) != 0) - if (err == ZIP_OK) - err = ZIP_ERRNO; - -#ifndef NO_ADDFILEINEXISTINGZIP - TRYFREE(zi->globalcomment); -#endif - TRYFREE(zi); - - return err; -} - -extern int ZEXPORT zipRemoveExtraInfoBlock (char* pData, int* dataLen, short sHeader) -{ - char* p = pData; - int size = 0; - char* pNewHeader; - char* pTmp; - short header; - short dataSize; - - int retVal = ZIP_OK; - - if(pData == NULL || *dataLen < 4) - return ZIP_PARAMERROR; - - pNewHeader = (char*)ALLOC(*dataLen); - pTmp = pNewHeader; - - while(p < (pData + *dataLen)) - { - header = *(short*)p; - dataSize = *(((short*)p)+1); - - if( header == sHeader ) // Header found. - { - p += dataSize + 4; // skip it. do not copy to temp buffer - } - else - { - // Extra Info block should not be removed, So copy it to the temp buffer. - memcpy(pTmp, p, dataSize + 4); - p += dataSize + 4; - size += dataSize + 4; - } - - } - - if(size < *dataLen) - { - // clean old extra info block. - memset(pData,0, *dataLen); - - // copy the new extra info block over the old - if(size > 0) - memcpy(pData, pNewHeader, size); - - // set the new extra info size - *dataLen = size; - - retVal = ZIP_OK; - } - else - retVal = ZIP_ERRNO; - - TRYFREE(pNewHeader); - - return retVal; -} diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/zip.h b/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/zip.h deleted file mode 100644 index 8aaebb62343..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/minizip/zip.h +++ /dev/null @@ -1,362 +0,0 @@ -/* zip.h -- IO on .zip files using zlib - Version 1.1, February 14h, 2010 - part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) - - Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) - - Modifications for Zip64 support - Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) - - For more info read MiniZip_info.txt - - --------------------------------------------------------------------------- - - Condition of use and distribution are the same than zlib : - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - --------------------------------------------------------------------------- - - Changes - - See header of zip.h - -*/ - -#ifndef _zip12_H -#define _zip12_H - -#ifdef __cplusplus -extern "C" { -#endif - -//#define HAVE_BZIP2 - -#ifndef _ZLIB_H -#include "zlib.h" -#endif - -#ifndef _ZLIBIOAPI_H -#include "ioapi.h" -#endif - -#ifdef HAVE_BZIP2 -#include "bzlib.h" -#endif - -#define Z_BZIP2ED 12 - -#if defined(STRICTZIP) || defined(STRICTZIPUNZIP) -/* like the STRICT of WIN32, we define a pointer that cannot be converted - from (void*) without cast */ -typedef struct TagzipFile__ { int unused; } zipFile__; -typedef zipFile__ *zipFile; -#else -typedef voidp zipFile; -#endif - -#define ZIP_OK (0) -#define ZIP_EOF (0) -#define ZIP_ERRNO (Z_ERRNO) -#define ZIP_PARAMERROR (-102) -#define ZIP_BADZIPFILE (-103) -#define ZIP_INTERNALERROR (-104) - -#ifndef DEF_MEM_LEVEL -# if MAX_MEM_LEVEL >= 8 -# define DEF_MEM_LEVEL 8 -# else -# define DEF_MEM_LEVEL MAX_MEM_LEVEL -# endif -#endif -/* default memLevel */ - -/* tm_zip contain date/time info */ -typedef struct tm_zip_s -{ - uInt tm_sec; /* seconds after the minute - [0,59] */ - uInt tm_min; /* minutes after the hour - [0,59] */ - uInt tm_hour; /* hours since midnight - [0,23] */ - uInt tm_mday; /* day of the month - [1,31] */ - uInt tm_mon; /* months since January - [0,11] */ - uInt tm_year; /* years - [1980..2044] */ -} tm_zip; - -typedef struct -{ - tm_zip tmz_date; /* date in understandable format */ - uLong dosDate; /* if dos_date == 0, tmu_date is used */ -/* uLong flag; */ /* general purpose bit flag 2 bytes */ - - uLong internal_fa; /* internal file attributes 2 bytes */ - uLong external_fa; /* external file attributes 4 bytes */ -} zip_fileinfo; - -typedef const char* zipcharpc; - - -#define APPEND_STATUS_CREATE (0) -#define APPEND_STATUS_CREATEAFTER (1) -#define APPEND_STATUS_ADDINZIP (2) - -extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append)); -extern zipFile ZEXPORT zipOpen64 OF((const void *pathname, int append)); -/* - Create a zipfile. - pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on - an Unix computer "zlib/zlib113.zip". - if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip - will be created at the end of the file. - (useful if the file contain a self extractor code) - if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will - add files in existing zip (be sure you don't add file that doesn't exist) - If the zipfile cannot be opened, the return value is NULL. - Else, the return value is a zipFile Handle, usable with other function - of this zip package. -*/ - -/* Note : there is no delete function into a zipfile. - If you want delete file into a zipfile, you must open a zipfile, and create another - Of couse, you can use RAW reading and writing to copy the file you did not want delte -*/ - -extern zipFile ZEXPORT zipOpen2 OF((const char *pathname, - int append, - zipcharpc* globalcomment, - zlib_filefunc_def* pzlib_filefunc_def)); - -extern zipFile ZEXPORT zipOpen2_64 OF((const void *pathname, - int append, - zipcharpc* globalcomment, - zlib_filefunc64_def* pzlib_filefunc_def)); - -extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file, - const char* filename, - const zip_fileinfo* zipfi, - const void* extrafield_local, - uInt size_extrafield_local, - const void* extrafield_global, - uInt size_extrafield_global, - const char* comment, - int method, - int level)); - -extern int ZEXPORT zipOpenNewFileInZip64 OF((zipFile file, - const char* filename, - const zip_fileinfo* zipfi, - const void* extrafield_local, - uInt size_extrafield_local, - const void* extrafield_global, - uInt size_extrafield_global, - const char* comment, - int method, - int level, - int zip64)); - -/* - Open a file in the ZIP for writing. - filename : the filename in zip (if NULL, '-' without quote will be used - *zipfi contain supplemental information - if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local - contains the extrafield data the the local header - if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global - contains the extrafield data the the local header - if comment != NULL, comment contain the comment string - method contain the compression method (0 for store, Z_DEFLATED for deflate) - level contain the level of compression (can be Z_DEFAULT_COMPRESSION) - zip64 is set to 1 if a zip64 extended information block should be added to the local file header. - this MUST be '1' if the uncompressed size is >= 0xffffffff. - -*/ - - -extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file, - const char* filename, - const zip_fileinfo* zipfi, - const void* extrafield_local, - uInt size_extrafield_local, - const void* extrafield_global, - uInt size_extrafield_global, - const char* comment, - int method, - int level, - int raw)); - - -extern int ZEXPORT zipOpenNewFileInZip2_64 OF((zipFile file, - const char* filename, - const zip_fileinfo* zipfi, - const void* extrafield_local, - uInt size_extrafield_local, - const void* extrafield_global, - uInt size_extrafield_global, - const char* comment, - int method, - int level, - int raw, - int zip64)); -/* - Same than zipOpenNewFileInZip, except if raw=1, we write raw file - */ - -extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file, - const char* filename, - const zip_fileinfo* zipfi, - const void* extrafield_local, - uInt size_extrafield_local, - const void* extrafield_global, - uInt size_extrafield_global, - const char* comment, - int method, - int level, - int raw, - int windowBits, - int memLevel, - int strategy, - const char* password, - uLong crcForCrypting)); - -extern int ZEXPORT zipOpenNewFileInZip3_64 OF((zipFile file, - const char* filename, - const zip_fileinfo* zipfi, - const void* extrafield_local, - uInt size_extrafield_local, - const void* extrafield_global, - uInt size_extrafield_global, - const char* comment, - int method, - int level, - int raw, - int windowBits, - int memLevel, - int strategy, - const char* password, - uLong crcForCrypting, - int zip64 - )); - -/* - Same than zipOpenNewFileInZip2, except - windowBits,memLevel,,strategy : see parameter strategy in deflateInit2 - password : crypting password (NULL for no crypting) - crcForCrypting : crc of file to compress (needed for crypting) - */ - -extern int ZEXPORT zipOpenNewFileInZip4 OF((zipFile file, - const char* filename, - const zip_fileinfo* zipfi, - const void* extrafield_local, - uInt size_extrafield_local, - const void* extrafield_global, - uInt size_extrafield_global, - const char* comment, - int method, - int level, - int raw, - int windowBits, - int memLevel, - int strategy, - const char* password, - uLong crcForCrypting, - uLong versionMadeBy, - uLong flagBase - )); - - -extern int ZEXPORT zipOpenNewFileInZip4_64 OF((zipFile file, - const char* filename, - const zip_fileinfo* zipfi, - const void* extrafield_local, - uInt size_extrafield_local, - const void* extrafield_global, - uInt size_extrafield_global, - const char* comment, - int method, - int level, - int raw, - int windowBits, - int memLevel, - int strategy, - const char* password, - uLong crcForCrypting, - uLong versionMadeBy, - uLong flagBase, - int zip64 - )); -/* - Same than zipOpenNewFileInZip4, except - versionMadeBy : value for Version made by field - flag : value for flag field (compression level info will be added) - */ - - -extern int ZEXPORT zipWriteInFileInZip OF((zipFile file, - const void* buf, - unsigned len)); -/* - Write data in the zipfile -*/ - -extern int ZEXPORT zipCloseFileInZip OF((zipFile file)); -/* - Close the current file in the zipfile -*/ - -extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file, - uLong uncompressed_size, - uLong crc32)); - -extern int ZEXPORT zipCloseFileInZipRaw64 OF((zipFile file, - ZPOS64_T uncompressed_size, - uLong crc32)); - -/* - Close the current file in the zipfile, for file opened with - parameter raw=1 in zipOpenNewFileInZip2 - uncompressed_size and crc32 are value for the uncompressed size -*/ - -extern int ZEXPORT zipClose OF((zipFile file, - const char* global_comment)); -/* - Close the zipfile -*/ - - -extern int ZEXPORT zipRemoveExtraInfoBlock OF((char* pData, int* dataLen, short sHeader)); -/* - zipRemoveExtraInfoBlock - Added by Mathias Svensson - - Remove extra information block from a extra information data for the local file header or central directory header - - It is needed to remove ZIP64 extra information blocks when before data is written if using RAW mode. - - 0x0001 is the signature header for the ZIP64 extra information blocks - - usage. - Remove ZIP64 Extra information from a central director extra field data - zipRemoveExtraInfoBlock(pCenDirExtraFieldData, &nCenDirExtraFieldDataLen, 0x0001); - - Remove ZIP64 Extra information from a Local File Header extra field data - zipRemoveExtraInfoBlock(pLocalHeaderExtraFieldData, &nLocalHeaderExtraFieldDataLen, 0x0001); -*/ - -#ifdef __cplusplus -} -#endif - -#endif /* _zip64_H */ diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/pascal/example.pas b/src/beast/test/zlib/zlib-1.2.8/contrib/pascal/example.pas deleted file mode 100644 index 5518b36a730..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/pascal/example.pas +++ /dev/null @@ -1,599 +0,0 @@ -(* example.c -- usage example of the zlib compression library - * Copyright (C) 1995-2003 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - * - * Pascal translation - * Copyright (C) 1998 by Jacques Nomssi Nzali. - * For conditions of distribution and use, see copyright notice in readme.txt - * - * Adaptation to the zlibpas interface - * Copyright (C) 2003 by Cosmin Truta. - * For conditions of distribution and use, see copyright notice in readme.txt - *) - -program example; - -{$DEFINE TEST_COMPRESS} -{DO NOT $DEFINE TEST_GZIO} -{$DEFINE TEST_DEFLATE} -{$DEFINE TEST_INFLATE} -{$DEFINE TEST_FLUSH} -{$DEFINE TEST_SYNC} -{$DEFINE TEST_DICT} - -uses SysUtils, zlibpas; - -const TESTFILE = 'foo.gz'; - -(* "hello world" would be more standard, but the repeated "hello" - * stresses the compression code better, sorry... - *) -const hello: PChar = 'hello, hello!'; - -const dictionary: PChar = 'hello'; - -var dictId: LongInt; (* Adler32 value of the dictionary *) - -procedure CHECK_ERR(err: Integer; msg: String); -begin - if err <> Z_OK then - begin - WriteLn(msg, ' error: ', err); - Halt(1); - end; -end; - -procedure EXIT_ERR(const msg: String); -begin - WriteLn('Error: ', msg); - Halt(1); -end; - -(* =========================================================================== - * Test compress and uncompress - *) -{$IFDEF TEST_COMPRESS} -procedure test_compress(compr: Pointer; comprLen: LongInt; - uncompr: Pointer; uncomprLen: LongInt); -var err: Integer; - len: LongInt; -begin - len := StrLen(hello)+1; - - err := compress(compr, comprLen, hello, len); - CHECK_ERR(err, 'compress'); - - StrCopy(PChar(uncompr), 'garbage'); - - err := uncompress(uncompr, uncomprLen, compr, comprLen); - CHECK_ERR(err, 'uncompress'); - - if StrComp(PChar(uncompr), hello) <> 0 then - EXIT_ERR('bad uncompress') - else - WriteLn('uncompress(): ', PChar(uncompr)); -end; -{$ENDIF} - -(* =========================================================================== - * Test read/write of .gz files - *) -{$IFDEF TEST_GZIO} -procedure test_gzio(const fname: PChar; (* compressed file name *) - uncompr: Pointer; - uncomprLen: LongInt); -var err: Integer; - len: Integer; - zfile: gzFile; - pos: LongInt; -begin - len := StrLen(hello)+1; - - zfile := gzopen(fname, 'wb'); - if zfile = NIL then - begin - WriteLn('gzopen error'); - Halt(1); - end; - gzputc(zfile, 'h'); - if gzputs(zfile, 'ello') <> 4 then - begin - WriteLn('gzputs err: ', gzerror(zfile, err)); - Halt(1); - end; - {$IFDEF GZ_FORMAT_STRING} - if gzprintf(zfile, ', %s!', 'hello') <> 8 then - begin - WriteLn('gzprintf err: ', gzerror(zfile, err)); - Halt(1); - end; - {$ELSE} - if gzputs(zfile, ', hello!') <> 8 then - begin - WriteLn('gzputs err: ', gzerror(zfile, err)); - Halt(1); - end; - {$ENDIF} - gzseek(zfile, 1, SEEK_CUR); (* add one zero byte *) - gzclose(zfile); - - zfile := gzopen(fname, 'rb'); - if zfile = NIL then - begin - WriteLn('gzopen error'); - Halt(1); - end; - - StrCopy(PChar(uncompr), 'garbage'); - - if gzread(zfile, uncompr, uncomprLen) <> len then - begin - WriteLn('gzread err: ', gzerror(zfile, err)); - Halt(1); - end; - if StrComp(PChar(uncompr), hello) <> 0 then - begin - WriteLn('bad gzread: ', PChar(uncompr)); - Halt(1); - end - else - WriteLn('gzread(): ', PChar(uncompr)); - - pos := gzseek(zfile, -8, SEEK_CUR); - if (pos <> 6) or (gztell(zfile) <> pos) then - begin - WriteLn('gzseek error, pos=', pos, ', gztell=', gztell(zfile)); - Halt(1); - end; - - if gzgetc(zfile) <> ' ' then - begin - WriteLn('gzgetc error'); - Halt(1); - end; - - if gzungetc(' ', zfile) <> ' ' then - begin - WriteLn('gzungetc error'); - Halt(1); - end; - - gzgets(zfile, PChar(uncompr), uncomprLen); - uncomprLen := StrLen(PChar(uncompr)); - if uncomprLen <> 7 then (* " hello!" *) - begin - WriteLn('gzgets err after gzseek: ', gzerror(zfile, err)); - Halt(1); - end; - if StrComp(PChar(uncompr), hello + 6) <> 0 then - begin - WriteLn('bad gzgets after gzseek'); - Halt(1); - end - else - WriteLn('gzgets() after gzseek: ', PChar(uncompr)); - - gzclose(zfile); -end; -{$ENDIF} - -(* =========================================================================== - * Test deflate with small buffers - *) -{$IFDEF TEST_DEFLATE} -procedure test_deflate(compr: Pointer; comprLen: LongInt); -var c_stream: z_stream; (* compression stream *) - err: Integer; - len: LongInt; -begin - len := StrLen(hello)+1; - - c_stream.zalloc := NIL; - c_stream.zfree := NIL; - c_stream.opaque := NIL; - - err := deflateInit(c_stream, Z_DEFAULT_COMPRESSION); - CHECK_ERR(err, 'deflateInit'); - - c_stream.next_in := hello; - c_stream.next_out := compr; - - while (c_stream.total_in <> len) and - (c_stream.total_out < comprLen) do - begin - c_stream.avail_out := 1; { force small buffers } - c_stream.avail_in := 1; - err := deflate(c_stream, Z_NO_FLUSH); - CHECK_ERR(err, 'deflate'); - end; - - (* Finish the stream, still forcing small buffers: *) - while TRUE do - begin - c_stream.avail_out := 1; - err := deflate(c_stream, Z_FINISH); - if err = Z_STREAM_END then - break; - CHECK_ERR(err, 'deflate'); - end; - - err := deflateEnd(c_stream); - CHECK_ERR(err, 'deflateEnd'); -end; -{$ENDIF} - -(* =========================================================================== - * Test inflate with small buffers - *) -{$IFDEF TEST_INFLATE} -procedure test_inflate(compr: Pointer; comprLen : LongInt; - uncompr: Pointer; uncomprLen : LongInt); -var err: Integer; - d_stream: z_stream; (* decompression stream *) -begin - StrCopy(PChar(uncompr), 'garbage'); - - d_stream.zalloc := NIL; - d_stream.zfree := NIL; - d_stream.opaque := NIL; - - d_stream.next_in := compr; - d_stream.avail_in := 0; - d_stream.next_out := uncompr; - - err := inflateInit(d_stream); - CHECK_ERR(err, 'inflateInit'); - - while (d_stream.total_out < uncomprLen) and - (d_stream.total_in < comprLen) do - begin - d_stream.avail_out := 1; (* force small buffers *) - d_stream.avail_in := 1; - err := inflate(d_stream, Z_NO_FLUSH); - if err = Z_STREAM_END then - break; - CHECK_ERR(err, 'inflate'); - end; - - err := inflateEnd(d_stream); - CHECK_ERR(err, 'inflateEnd'); - - if StrComp(PChar(uncompr), hello) <> 0 then - EXIT_ERR('bad inflate') - else - WriteLn('inflate(): ', PChar(uncompr)); -end; -{$ENDIF} - -(* =========================================================================== - * Test deflate with large buffers and dynamic change of compression level - *) -{$IFDEF TEST_DEFLATE} -procedure test_large_deflate(compr: Pointer; comprLen: LongInt; - uncompr: Pointer; uncomprLen: LongInt); -var c_stream: z_stream; (* compression stream *) - err: Integer; -begin - c_stream.zalloc := NIL; - c_stream.zfree := NIL; - c_stream.opaque := NIL; - - err := deflateInit(c_stream, Z_BEST_SPEED); - CHECK_ERR(err, 'deflateInit'); - - c_stream.next_out := compr; - c_stream.avail_out := Integer(comprLen); - - (* At this point, uncompr is still mostly zeroes, so it should compress - * very well: - *) - c_stream.next_in := uncompr; - c_stream.avail_in := Integer(uncomprLen); - err := deflate(c_stream, Z_NO_FLUSH); - CHECK_ERR(err, 'deflate'); - if c_stream.avail_in <> 0 then - EXIT_ERR('deflate not greedy'); - - (* Feed in already compressed data and switch to no compression: *) - deflateParams(c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY); - c_stream.next_in := compr; - c_stream.avail_in := Integer(comprLen div 2); - err := deflate(c_stream, Z_NO_FLUSH); - CHECK_ERR(err, 'deflate'); - - (* Switch back to compressing mode: *) - deflateParams(c_stream, Z_BEST_COMPRESSION, Z_FILTERED); - c_stream.next_in := uncompr; - c_stream.avail_in := Integer(uncomprLen); - err := deflate(c_stream, Z_NO_FLUSH); - CHECK_ERR(err, 'deflate'); - - err := deflate(c_stream, Z_FINISH); - if err <> Z_STREAM_END then - EXIT_ERR('deflate should report Z_STREAM_END'); - - err := deflateEnd(c_stream); - CHECK_ERR(err, 'deflateEnd'); -end; -{$ENDIF} - -(* =========================================================================== - * Test inflate with large buffers - *) -{$IFDEF TEST_INFLATE} -procedure test_large_inflate(compr: Pointer; comprLen: LongInt; - uncompr: Pointer; uncomprLen: LongInt); -var err: Integer; - d_stream: z_stream; (* decompression stream *) -begin - StrCopy(PChar(uncompr), 'garbage'); - - d_stream.zalloc := NIL; - d_stream.zfree := NIL; - d_stream.opaque := NIL; - - d_stream.next_in := compr; - d_stream.avail_in := Integer(comprLen); - - err := inflateInit(d_stream); - CHECK_ERR(err, 'inflateInit'); - - while TRUE do - begin - d_stream.next_out := uncompr; (* discard the output *) - d_stream.avail_out := Integer(uncomprLen); - err := inflate(d_stream, Z_NO_FLUSH); - if err = Z_STREAM_END then - break; - CHECK_ERR(err, 'large inflate'); - end; - - err := inflateEnd(d_stream); - CHECK_ERR(err, 'inflateEnd'); - - if d_stream.total_out <> 2 * uncomprLen + comprLen div 2 then - begin - WriteLn('bad large inflate: ', d_stream.total_out); - Halt(1); - end - else - WriteLn('large_inflate(): OK'); -end; -{$ENDIF} - -(* =========================================================================== - * Test deflate with full flush - *) -{$IFDEF TEST_FLUSH} -procedure test_flush(compr: Pointer; var comprLen : LongInt); -var c_stream: z_stream; (* compression stream *) - err: Integer; - len: Integer; -begin - len := StrLen(hello)+1; - - c_stream.zalloc := NIL; - c_stream.zfree := NIL; - c_stream.opaque := NIL; - - err := deflateInit(c_stream, Z_DEFAULT_COMPRESSION); - CHECK_ERR(err, 'deflateInit'); - - c_stream.next_in := hello; - c_stream.next_out := compr; - c_stream.avail_in := 3; - c_stream.avail_out := Integer(comprLen); - err := deflate(c_stream, Z_FULL_FLUSH); - CHECK_ERR(err, 'deflate'); - - Inc(PByteArray(compr)^[3]); (* force an error in first compressed block *) - c_stream.avail_in := len - 3; - - err := deflate(c_stream, Z_FINISH); - if err <> Z_STREAM_END then - CHECK_ERR(err, 'deflate'); - - err := deflateEnd(c_stream); - CHECK_ERR(err, 'deflateEnd'); - - comprLen := c_stream.total_out; -end; -{$ENDIF} - -(* =========================================================================== - * Test inflateSync() - *) -{$IFDEF TEST_SYNC} -procedure test_sync(compr: Pointer; comprLen: LongInt; - uncompr: Pointer; uncomprLen : LongInt); -var err: Integer; - d_stream: z_stream; (* decompression stream *) -begin - StrCopy(PChar(uncompr), 'garbage'); - - d_stream.zalloc := NIL; - d_stream.zfree := NIL; - d_stream.opaque := NIL; - - d_stream.next_in := compr; - d_stream.avail_in := 2; (* just read the zlib header *) - - err := inflateInit(d_stream); - CHECK_ERR(err, 'inflateInit'); - - d_stream.next_out := uncompr; - d_stream.avail_out := Integer(uncomprLen); - - inflate(d_stream, Z_NO_FLUSH); - CHECK_ERR(err, 'inflate'); - - d_stream.avail_in := Integer(comprLen-2); (* read all compressed data *) - err := inflateSync(d_stream); (* but skip the damaged part *) - CHECK_ERR(err, 'inflateSync'); - - err := inflate(d_stream, Z_FINISH); - if err <> Z_DATA_ERROR then - EXIT_ERR('inflate should report DATA_ERROR'); - (* Because of incorrect adler32 *) - - err := inflateEnd(d_stream); - CHECK_ERR(err, 'inflateEnd'); - - WriteLn('after inflateSync(): hel', PChar(uncompr)); -end; -{$ENDIF} - -(* =========================================================================== - * Test deflate with preset dictionary - *) -{$IFDEF TEST_DICT} -procedure test_dict_deflate(compr: Pointer; comprLen: LongInt); -var c_stream: z_stream; (* compression stream *) - err: Integer; -begin - c_stream.zalloc := NIL; - c_stream.zfree := NIL; - c_stream.opaque := NIL; - - err := deflateInit(c_stream, Z_BEST_COMPRESSION); - CHECK_ERR(err, 'deflateInit'); - - err := deflateSetDictionary(c_stream, dictionary, StrLen(dictionary)); - CHECK_ERR(err, 'deflateSetDictionary'); - - dictId := c_stream.adler; - c_stream.next_out := compr; - c_stream.avail_out := Integer(comprLen); - - c_stream.next_in := hello; - c_stream.avail_in := StrLen(hello)+1; - - err := deflate(c_stream, Z_FINISH); - if err <> Z_STREAM_END then - EXIT_ERR('deflate should report Z_STREAM_END'); - - err := deflateEnd(c_stream); - CHECK_ERR(err, 'deflateEnd'); -end; -{$ENDIF} - -(* =========================================================================== - * Test inflate with a preset dictionary - *) -{$IFDEF TEST_DICT} -procedure test_dict_inflate(compr: Pointer; comprLen: LongInt; - uncompr: Pointer; uncomprLen: LongInt); -var err: Integer; - d_stream: z_stream; (* decompression stream *) -begin - StrCopy(PChar(uncompr), 'garbage'); - - d_stream.zalloc := NIL; - d_stream.zfree := NIL; - d_stream.opaque := NIL; - - d_stream.next_in := compr; - d_stream.avail_in := Integer(comprLen); - - err := inflateInit(d_stream); - CHECK_ERR(err, 'inflateInit'); - - d_stream.next_out := uncompr; - d_stream.avail_out := Integer(uncomprLen); - - while TRUE do - begin - err := inflate(d_stream, Z_NO_FLUSH); - if err = Z_STREAM_END then - break; - if err = Z_NEED_DICT then - begin - if d_stream.adler <> dictId then - EXIT_ERR('unexpected dictionary'); - err := inflateSetDictionary(d_stream, dictionary, StrLen(dictionary)); - end; - CHECK_ERR(err, 'inflate with dict'); - end; - - err := inflateEnd(d_stream); - CHECK_ERR(err, 'inflateEnd'); - - if StrComp(PChar(uncompr), hello) <> 0 then - EXIT_ERR('bad inflate with dict') - else - WriteLn('inflate with dictionary: ', PChar(uncompr)); -end; -{$ENDIF} - -var compr, uncompr: Pointer; - comprLen, uncomprLen: LongInt; - -begin - if zlibVersion^ <> ZLIB_VERSION[1] then - EXIT_ERR('Incompatible zlib version'); - - WriteLn('zlib version: ', zlibVersion); - WriteLn('zlib compile flags: ', Format('0x%x', [zlibCompileFlags])); - - comprLen := 10000 * SizeOf(Integer); (* don't overflow on MSDOS *) - uncomprLen := comprLen; - GetMem(compr, comprLen); - GetMem(uncompr, uncomprLen); - if (compr = NIL) or (uncompr = NIL) then - EXIT_ERR('Out of memory'); - (* compr and uncompr are cleared to avoid reading uninitialized - * data and to ensure that uncompr compresses well. - *) - FillChar(compr^, comprLen, 0); - FillChar(uncompr^, uncomprLen, 0); - - {$IFDEF TEST_COMPRESS} - WriteLn('** Testing compress'); - test_compress(compr, comprLen, uncompr, uncomprLen); - {$ENDIF} - - {$IFDEF TEST_GZIO} - WriteLn('** Testing gzio'); - if ParamCount >= 1 then - test_gzio(ParamStr(1), uncompr, uncomprLen) - else - test_gzio(TESTFILE, uncompr, uncomprLen); - {$ENDIF} - - {$IFDEF TEST_DEFLATE} - WriteLn('** Testing deflate with small buffers'); - test_deflate(compr, comprLen); - {$ENDIF} - {$IFDEF TEST_INFLATE} - WriteLn('** Testing inflate with small buffers'); - test_inflate(compr, comprLen, uncompr, uncomprLen); - {$ENDIF} - - {$IFDEF TEST_DEFLATE} - WriteLn('** Testing deflate with large buffers'); - test_large_deflate(compr, comprLen, uncompr, uncomprLen); - {$ENDIF} - {$IFDEF TEST_INFLATE} - WriteLn('** Testing inflate with large buffers'); - test_large_inflate(compr, comprLen, uncompr, uncomprLen); - {$ENDIF} - - {$IFDEF TEST_FLUSH} - WriteLn('** Testing deflate with full flush'); - test_flush(compr, comprLen); - {$ENDIF} - {$IFDEF TEST_SYNC} - WriteLn('** Testing inflateSync'); - test_sync(compr, comprLen, uncompr, uncomprLen); - {$ENDIF} - comprLen := uncomprLen; - - {$IFDEF TEST_DICT} - WriteLn('** Testing deflate and inflate with preset dictionary'); - test_dict_deflate(compr, comprLen); - test_dict_inflate(compr, comprLen, uncompr, uncomprLen); - {$ENDIF} - - FreeMem(compr, comprLen); - FreeMem(uncompr, uncomprLen); -end. diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/pascal/readme.txt b/src/beast/test/zlib/zlib-1.2.8/contrib/pascal/readme.txt deleted file mode 100644 index 60e87c8a331..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/pascal/readme.txt +++ /dev/null @@ -1,76 +0,0 @@ - -This directory contains a Pascal (Delphi, Kylix) interface to the -zlib data compression library. - - -Directory listing -================= - -zlibd32.mak makefile for Borland C++ -example.pas usage example of zlib -zlibpas.pas the Pascal interface to zlib -readme.txt this file - - -Compatibility notes -=================== - -- Although the name "zlib" would have been more normal for the - zlibpas unit, this name is already taken by Borland's ZLib unit. - This is somehow unfortunate, because that unit is not a genuine - interface to the full-fledged zlib functionality, but a suite of - class wrappers around zlib streams. Other essential features, - such as checksums, are missing. - It would have been more appropriate for that unit to have a name - like "ZStreams", or something similar. - -- The C and zlib-supplied types int, uInt, long, uLong, etc. are - translated directly into Pascal types of similar sizes (Integer, - LongInt, etc.), to avoid namespace pollution. In particular, - there is no conversion of unsigned int into a Pascal unsigned - integer. The Word type is non-portable and has the same size - (16 bits) both in a 16-bit and in a 32-bit environment, unlike - Integer. Even if there is a 32-bit Cardinal type, there is no - real need for unsigned int in zlib under a 32-bit environment. - -- Except for the callbacks, the zlib function interfaces are - assuming the calling convention normally used in Pascal - (__pascal for DOS and Windows16, __fastcall for Windows32). - Since the cdecl keyword is used, the old Turbo Pascal does - not work with this interface. - -- The gz* function interfaces are not translated, to avoid - interfacing problems with the C runtime library. Besides, - gzprintf(gzFile file, const char *format, ...) - cannot be translated into Pascal. - - -Legal issues -============ - -The zlibpas interface is: - Copyright (C) 1995-2003 Jean-loup Gailly and Mark Adler. - Copyright (C) 1998 by Bob Dellaca. - Copyright (C) 2003 by Cosmin Truta. - -The example program is: - Copyright (C) 1995-2003 by Jean-loup Gailly. - Copyright (C) 1998,1999,2000 by Jacques Nomssi Nzali. - Copyright (C) 2003 by Cosmin Truta. - - This software is provided 'as-is', without any express or implied - warranty. In no event will the author be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/pascal/zlibd32.mak b/src/beast/test/zlib/zlib-1.2.8/contrib/pascal/zlibd32.mak deleted file mode 100644 index 9bb00b7cc42..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/pascal/zlibd32.mak +++ /dev/null @@ -1,99 +0,0 @@ -# Makefile for zlib -# For use with Delphi and C++ Builder under Win32 -# Updated for zlib 1.2.x by Cosmin Truta - -# ------------ Borland C++ ------------ - -# This project uses the Delphi (fastcall/register) calling convention: -LOC = -DZEXPORT=__fastcall -DZEXPORTVA=__cdecl - -CC = bcc32 -LD = bcc32 -AR = tlib -# do not use "-pr" in CFLAGS -CFLAGS = -a -d -k- -O2 $(LOC) -LDFLAGS = - - -# variables -ZLIB_LIB = zlib.lib - -OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzlib.obj gzread.obj -OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj -OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzlib.obj+gzread.obj -OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj - - -# targets -all: $(ZLIB_LIB) example.exe minigzip.exe - -.c.obj: - $(CC) -c $(CFLAGS) $*.c - -adler32.obj: adler32.c zlib.h zconf.h - -compress.obj: compress.c zlib.h zconf.h - -crc32.obj: crc32.c zlib.h zconf.h crc32.h - -deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h - -gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h - -gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h - -gzread.obj: gzread.c zlib.h zconf.h gzguts.h - -gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h - -infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ - inffast.h inffixed.h - -inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ - inffast.h - -inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ - inffast.h inffixed.h - -inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h - -trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h - -uncompr.obj: uncompr.c zlib.h zconf.h - -zutil.obj: zutil.c zutil.h zlib.h zconf.h - -example.obj: test/example.c zlib.h zconf.h - -minigzip.obj: test/minigzip.c zlib.h zconf.h - - -# For the sake of the old Borland make, -# the command line is cut to fit in the MS-DOS 128 byte limit: -$(ZLIB_LIB): $(OBJ1) $(OBJ2) - -del $(ZLIB_LIB) - $(AR) $(ZLIB_LIB) $(OBJP1) - $(AR) $(ZLIB_LIB) $(OBJP2) - - -# testing -test: example.exe minigzip.exe - example - echo hello world | minigzip | minigzip -d - -example.exe: example.obj $(ZLIB_LIB) - $(LD) $(LDFLAGS) example.obj $(ZLIB_LIB) - -minigzip.exe: minigzip.obj $(ZLIB_LIB) - $(LD) $(LDFLAGS) minigzip.obj $(ZLIB_LIB) - - -# cleanup -clean: - -del *.obj - -del *.exe - -del *.lib - -del *.tds - -del zlib.bak - -del foo.gz - diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/pascal/zlibpas.pas b/src/beast/test/zlib/zlib-1.2.8/contrib/pascal/zlibpas.pas deleted file mode 100644 index e6a0782b48c..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/pascal/zlibpas.pas +++ /dev/null @@ -1,276 +0,0 @@ -(* zlibpas -- Pascal interface to the zlib data compression library - * - * Copyright (C) 2003 Cosmin Truta. - * Derived from original sources by Bob Dellaca. - * For conditions of distribution and use, see copyright notice in readme.txt - *) - -unit zlibpas; - -interface - -const - ZLIB_VERSION = '1.2.8'; - ZLIB_VERNUM = $1280; - -type - alloc_func = function(opaque: Pointer; items, size: Integer): Pointer; - cdecl; - free_func = procedure(opaque, address: Pointer); - cdecl; - - in_func = function(opaque: Pointer; var buf: PByte): Integer; - cdecl; - out_func = function(opaque: Pointer; buf: PByte; size: Integer): Integer; - cdecl; - - z_streamp = ^z_stream; - z_stream = packed record - next_in: PChar; (* next input byte *) - avail_in: Integer; (* number of bytes available at next_in *) - total_in: LongInt; (* total nb of input bytes read so far *) - - next_out: PChar; (* next output byte should be put there *) - avail_out: Integer; (* remaining free space at next_out *) - total_out: LongInt; (* total nb of bytes output so far *) - - msg: PChar; (* last error message, NULL if no error *) - state: Pointer; (* not visible by applications *) - - zalloc: alloc_func; (* used to allocate the internal state *) - zfree: free_func; (* used to free the internal state *) - opaque: Pointer; (* private data object passed to zalloc and zfree *) - - data_type: Integer; (* best guess about the data type: ascii or binary *) - adler: LongInt; (* adler32 value of the uncompressed data *) - reserved: LongInt; (* reserved for future use *) - end; - - gz_headerp = ^gz_header; - gz_header = packed record - text: Integer; (* true if compressed data believed to be text *) - time: LongInt; (* modification time *) - xflags: Integer; (* extra flags (not used when writing a gzip file) *) - os: Integer; (* operating system *) - extra: PChar; (* pointer to extra field or Z_NULL if none *) - extra_len: Integer; (* extra field length (valid if extra != Z_NULL) *) - extra_max: Integer; (* space at extra (only when reading header) *) - name: PChar; (* pointer to zero-terminated file name or Z_NULL *) - name_max: Integer; (* space at name (only when reading header) *) - comment: PChar; (* pointer to zero-terminated comment or Z_NULL *) - comm_max: Integer; (* space at comment (only when reading header) *) - hcrc: Integer; (* true if there was or will be a header crc *) - done: Integer; (* true when done reading gzip header *) - end; - -(* constants *) -const - Z_NO_FLUSH = 0; - Z_PARTIAL_FLUSH = 1; - Z_SYNC_FLUSH = 2; - Z_FULL_FLUSH = 3; - Z_FINISH = 4; - Z_BLOCK = 5; - Z_TREES = 6; - - Z_OK = 0; - Z_STREAM_END = 1; - Z_NEED_DICT = 2; - Z_ERRNO = -1; - Z_STREAM_ERROR = -2; - Z_DATA_ERROR = -3; - Z_MEM_ERROR = -4; - Z_BUF_ERROR = -5; - Z_VERSION_ERROR = -6; - - Z_NO_COMPRESSION = 0; - Z_BEST_SPEED = 1; - Z_BEST_COMPRESSION = 9; - Z_DEFAULT_COMPRESSION = -1; - - Z_FILTERED = 1; - Z_HUFFMAN_ONLY = 2; - Z_RLE = 3; - Z_FIXED = 4; - Z_DEFAULT_STRATEGY = 0; - - Z_BINARY = 0; - Z_TEXT = 1; - Z_ASCII = 1; - Z_UNKNOWN = 2; - - Z_DEFLATED = 8; - -(* basic functions *) -function zlibVersion: PChar; -function deflateInit(var strm: z_stream; level: Integer): Integer; -function deflate(var strm: z_stream; flush: Integer): Integer; -function deflateEnd(var strm: z_stream): Integer; -function inflateInit(var strm: z_stream): Integer; -function inflate(var strm: z_stream; flush: Integer): Integer; -function inflateEnd(var strm: z_stream): Integer; - -(* advanced functions *) -function deflateInit2(var strm: z_stream; level, method, windowBits, - memLevel, strategy: Integer): Integer; -function deflateSetDictionary(var strm: z_stream; const dictionary: PChar; - dictLength: Integer): Integer; -function deflateCopy(var dest, source: z_stream): Integer; -function deflateReset(var strm: z_stream): Integer; -function deflateParams(var strm: z_stream; level, strategy: Integer): Integer; -function deflateTune(var strm: z_stream; good_length, max_lazy, nice_length, max_chain: Integer): Integer; -function deflateBound(var strm: z_stream; sourceLen: LongInt): LongInt; -function deflatePending(var strm: z_stream; var pending: Integer; var bits: Integer): Integer; -function deflatePrime(var strm: z_stream; bits, value: Integer): Integer; -function deflateSetHeader(var strm: z_stream; head: gz_header): Integer; -function inflateInit2(var strm: z_stream; windowBits: Integer): Integer; -function inflateSetDictionary(var strm: z_stream; const dictionary: PChar; - dictLength: Integer): Integer; -function inflateSync(var strm: z_stream): Integer; -function inflateCopy(var dest, source: z_stream): Integer; -function inflateReset(var strm: z_stream): Integer; -function inflateReset2(var strm: z_stream; windowBits: Integer): Integer; -function inflatePrime(var strm: z_stream; bits, value: Integer): Integer; -function inflateMark(var strm: z_stream): LongInt; -function inflateGetHeader(var strm: z_stream; var head: gz_header): Integer; -function inflateBackInit(var strm: z_stream; - windowBits: Integer; window: PChar): Integer; -function inflateBack(var strm: z_stream; in_fn: in_func; in_desc: Pointer; - out_fn: out_func; out_desc: Pointer): Integer; -function inflateBackEnd(var strm: z_stream): Integer; -function zlibCompileFlags: LongInt; - -(* utility functions *) -function compress(dest: PChar; var destLen: LongInt; - const source: PChar; sourceLen: LongInt): Integer; -function compress2(dest: PChar; var destLen: LongInt; - const source: PChar; sourceLen: LongInt; - level: Integer): Integer; -function compressBound(sourceLen: LongInt): LongInt; -function uncompress(dest: PChar; var destLen: LongInt; - const source: PChar; sourceLen: LongInt): Integer; - -(* checksum functions *) -function adler32(adler: LongInt; const buf: PChar; len: Integer): LongInt; -function adler32_combine(adler1, adler2, len2: LongInt): LongInt; -function crc32(crc: LongInt; const buf: PChar; len: Integer): LongInt; -function crc32_combine(crc1, crc2, len2: LongInt): LongInt; - -(* various hacks, don't look :) *) -function deflateInit_(var strm: z_stream; level: Integer; - const version: PChar; stream_size: Integer): Integer; -function inflateInit_(var strm: z_stream; const version: PChar; - stream_size: Integer): Integer; -function deflateInit2_(var strm: z_stream; - level, method, windowBits, memLevel, strategy: Integer; - const version: PChar; stream_size: Integer): Integer; -function inflateInit2_(var strm: z_stream; windowBits: Integer; - const version: PChar; stream_size: Integer): Integer; -function inflateBackInit_(var strm: z_stream; - windowBits: Integer; window: PChar; - const version: PChar; stream_size: Integer): Integer; - - -implementation - -{$L adler32.obj} -{$L compress.obj} -{$L crc32.obj} -{$L deflate.obj} -{$L infback.obj} -{$L inffast.obj} -{$L inflate.obj} -{$L inftrees.obj} -{$L trees.obj} -{$L uncompr.obj} -{$L zutil.obj} - -function adler32; external; -function adler32_combine; external; -function compress; external; -function compress2; external; -function compressBound; external; -function crc32; external; -function crc32_combine; external; -function deflate; external; -function deflateBound; external; -function deflateCopy; external; -function deflateEnd; external; -function deflateInit_; external; -function deflateInit2_; external; -function deflateParams; external; -function deflatePending; external; -function deflatePrime; external; -function deflateReset; external; -function deflateSetDictionary; external; -function deflateSetHeader; external; -function deflateTune; external; -function inflate; external; -function inflateBack; external; -function inflateBackEnd; external; -function inflateBackInit_; external; -function inflateCopy; external; -function inflateEnd; external; -function inflateGetHeader; external; -function inflateInit_; external; -function inflateInit2_; external; -function inflateMark; external; -function inflatePrime; external; -function inflateReset; external; -function inflateReset2; external; -function inflateSetDictionary; external; -function inflateSync; external; -function uncompress; external; -function zlibCompileFlags; external; -function zlibVersion; external; - -function deflateInit(var strm: z_stream; level: Integer): Integer; -begin - Result := deflateInit_(strm, level, ZLIB_VERSION, sizeof(z_stream)); -end; - -function deflateInit2(var strm: z_stream; level, method, windowBits, memLevel, - strategy: Integer): Integer; -begin - Result := deflateInit2_(strm, level, method, windowBits, memLevel, strategy, - ZLIB_VERSION, sizeof(z_stream)); -end; - -function inflateInit(var strm: z_stream): Integer; -begin - Result := inflateInit_(strm, ZLIB_VERSION, sizeof(z_stream)); -end; - -function inflateInit2(var strm: z_stream; windowBits: Integer): Integer; -begin - Result := inflateInit2_(strm, windowBits, ZLIB_VERSION, sizeof(z_stream)); -end; - -function inflateBackInit(var strm: z_stream; - windowBits: Integer; window: PChar): Integer; -begin - Result := inflateBackInit_(strm, windowBits, window, - ZLIB_VERSION, sizeof(z_stream)); -end; - -function _malloc(Size: Integer): Pointer; cdecl; -begin - GetMem(Result, Size); -end; - -procedure _free(Block: Pointer); cdecl; -begin - FreeMem(Block); -end; - -procedure _memset(P: Pointer; B: Byte; count: Integer); cdecl; -begin - FillChar(P^, count, B); -end; - -procedure _memcpy(dest, source: Pointer; count: Integer); cdecl; -begin - Move(source^, dest^, count); -end; - -end. diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/puff/Makefile b/src/beast/test/zlib/zlib-1.2.8/contrib/puff/Makefile deleted file mode 100644 index 0e2594c8088..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/puff/Makefile +++ /dev/null @@ -1,42 +0,0 @@ -CFLAGS=-O - -puff: puff.o pufftest.o - -puff.o: puff.h - -pufftest.o: puff.h - -test: puff - puff zeros.raw - -puft: puff.c puff.h pufftest.o - cc -fprofile-arcs -ftest-coverage -o puft puff.c pufftest.o - -# puff full coverage test (should say 100%) -cov: puft - @rm -f *.gcov *.gcda - @puft -w zeros.raw 2>&1 | cat > /dev/null - @echo '04' | xxd -r -p | puft 2> /dev/null || test $$? -eq 2 - @echo '00' | xxd -r -p | puft 2> /dev/null || test $$? -eq 2 - @echo '00 00 00 00 00' | xxd -r -p | puft 2> /dev/null || test $$? -eq 254 - @echo '00 01 00 fe ff' | xxd -r -p | puft 2> /dev/null || test $$? -eq 2 - @echo '01 01 00 fe ff 0a' | xxd -r -p | puft -f 2>&1 | cat > /dev/null - @echo '02 7e ff ff' | xxd -r -p | puft 2> /dev/null || test $$? -eq 246 - @echo '02' | xxd -r -p | puft 2> /dev/null || test $$? -eq 2 - @echo '04 80 49 92 24 49 92 24 0f b4 ff ff c3 04' | xxd -r -p | puft 2> /dev/null || test $$? -eq 2 - @echo '04 80 49 92 24 49 92 24 71 ff ff 93 11 00' | xxd -r -p | puft 2> /dev/null || test $$? -eq 249 - @echo '04 c0 81 08 00 00 00 00 20 7f eb 0b 00 00' | xxd -r -p | puft 2> /dev/null || test $$? -eq 246 - @echo '0b 00 00' | xxd -r -p | puft -f 2>&1 | cat > /dev/null - @echo '1a 07' | xxd -r -p | puft 2> /dev/null || test $$? -eq 246 - @echo '0c c0 81 00 00 00 00 00 90 ff 6b 04' | xxd -r -p | puft 2> /dev/null || test $$? -eq 245 - @puft -f zeros.raw 2>&1 | cat > /dev/null - @echo 'fc 00 00' | xxd -r -p | puft 2> /dev/null || test $$? -eq 253 - @echo '04 00 fe ff' | xxd -r -p | puft 2> /dev/null || test $$? -eq 252 - @echo '04 00 24 49' | xxd -r -p | puft 2> /dev/null || test $$? -eq 251 - @echo '04 80 49 92 24 49 92 24 0f b4 ff ff c3 84' | xxd -r -p | puft 2> /dev/null || test $$? -eq 248 - @echo '04 00 24 e9 ff ff' | xxd -r -p | puft 2> /dev/null || test $$? -eq 250 - @echo '04 00 24 e9 ff 6d' | xxd -r -p | puft 2> /dev/null || test $$? -eq 247 - @gcov -n puff.c - -clean: - rm -f puff puft *.o *.gc* diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/puff/README b/src/beast/test/zlib/zlib-1.2.8/contrib/puff/README deleted file mode 100644 index bbc4cb595ec..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/puff/README +++ /dev/null @@ -1,63 +0,0 @@ -Puff -- A Simple Inflate -3 Mar 2003 -Mark Adler -madler@alumni.caltech.edu - -What this is -- - -puff.c provides the routine puff() to decompress the deflate data format. It -does so more slowly than zlib, but the code is about one-fifth the size of the -inflate code in zlib, and written to be very easy to read. - -Why I wrote this -- - -puff.c was written to document the deflate format unambiguously, by virtue of -being working C code. It is meant to supplement RFC 1951, which formally -describes the deflate format. I have received many questions on details of the -deflate format, and I hope that reading this code will answer those questions. -puff.c is heavily commented with details of the deflate format, especially -those little nooks and cranies of the format that might not be obvious from a -specification. - -puff.c may also be useful in applications where code size or memory usage is a -very limited resource, and speed is not as important. - -How to use it -- - -Well, most likely you should just be reading puff.c and using zlib for actual -applications, but if you must ... - -Include puff.h in your code, which provides this prototype: - -int puff(unsigned char *dest, /* pointer to destination pointer */ - unsigned long *destlen, /* amount of output space */ - unsigned char *source, /* pointer to source data pointer */ - unsigned long *sourcelen); /* amount of input available */ - -Then you can call puff() to decompress a deflate stream that is in memory in -its entirety at source, to a sufficiently sized block of memory for the -decompressed data at dest. puff() is the only external symbol in puff.c The -only C library functions that puff.c needs are setjmp() and longjmp(), which -are used to simplify error checking in the code to improve readabilty. puff.c -does no memory allocation, and uses less than 2K bytes off of the stack. - -If destlen is not enough space for the uncompressed data, then inflate will -return an error without writing more than destlen bytes. Note that this means -that in order to decompress the deflate data successfully, you need to know -the size of the uncompressed data ahead of time. - -If needed, puff() can determine the size of the uncompressed data with no -output space. This is done by passing dest equal to (unsigned char *)0. Then -the initial value of *destlen is ignored and *destlen is set to the length of -the uncompressed data. So if the size of the uncompressed data is not known, -then two passes of puff() can be used--first to determine the size, and second -to do the actual inflation after allocating the appropriate memory. Not -pretty, but it works. (This is one of the reasons you should be using zlib.) - -The deflate format is self-terminating. If the deflate stream does not end -in *sourcelen bytes, puff() will return an error without reading at or past -endsource. - -On return, *sourcelen is updated to the amount of input data consumed, and -*destlen is updated to the size of the uncompressed data. See the comments -in puff.c for the possible return codes for puff(). diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/puff/puff.c b/src/beast/test/zlib/zlib-1.2.8/contrib/puff/puff.c deleted file mode 100644 index ba58483d570..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/puff/puff.c +++ /dev/null @@ -1,840 +0,0 @@ -/* - * puff.c - * Copyright (C) 2002-2013 Mark Adler - * For conditions of distribution and use, see copyright notice in puff.h - * version 2.3, 21 Jan 2013 - * - * puff.c is a simple inflate written to be an unambiguous way to specify the - * deflate format. It is not written for speed but rather simplicity. As a - * side benefit, this code might actually be useful when small code is more - * important than speed, such as bootstrap applications. For typical deflate - * data, zlib's inflate() is about four times as fast as puff(). zlib's - * inflate compiles to around 20K on my machine, whereas puff.c compiles to - * around 4K on my machine (a PowerPC using GNU cc). If the faster decode() - * function here is used, then puff() is only twice as slow as zlib's - * inflate(). - * - * All dynamically allocated memory comes from the stack. The stack required - * is less than 2K bytes. This code is compatible with 16-bit int's and - * assumes that long's are at least 32 bits. puff.c uses the short data type, - * assumed to be 16 bits, for arrays in order to to conserve memory. The code - * works whether integers are stored big endian or little endian. - * - * In the comments below are "Format notes" that describe the inflate process - * and document some of the less obvious aspects of the format. This source - * code is meant to supplement RFC 1951, which formally describes the deflate - * format: - * - * http://www.zlib.org/rfc-deflate.html - */ - -/* - * Change history: - * - * 1.0 10 Feb 2002 - First version - * 1.1 17 Feb 2002 - Clarifications of some comments and notes - * - Update puff() dest and source pointers on negative - * errors to facilitate debugging deflators - * - Remove longest from struct huffman -- not needed - * - Simplify offs[] index in construct() - * - Add input size and checking, using longjmp() to - * maintain easy readability - * - Use short data type for large arrays - * - Use pointers instead of long to specify source and - * destination sizes to avoid arbitrary 4 GB limits - * 1.2 17 Mar 2002 - Add faster version of decode(), doubles speed (!), - * but leave simple version for readabilty - * - Make sure invalid distances detected if pointers - * are 16 bits - * - Fix fixed codes table error - * - Provide a scanning mode for determining size of - * uncompressed data - * 1.3 20 Mar 2002 - Go back to lengths for puff() parameters [Gailly] - * - Add a puff.h file for the interface - * - Add braces in puff() for else do [Gailly] - * - Use indexes instead of pointers for readability - * 1.4 31 Mar 2002 - Simplify construct() code set check - * - Fix some comments - * - Add FIXLCODES #define - * 1.5 6 Apr 2002 - Minor comment fixes - * 1.6 7 Aug 2002 - Minor format changes - * 1.7 3 Mar 2003 - Added test code for distribution - * - Added zlib-like license - * 1.8 9 Jan 2004 - Added some comments on no distance codes case - * 1.9 21 Feb 2008 - Fix bug on 16-bit integer architectures [Pohland] - * - Catch missing end-of-block symbol error - * 2.0 25 Jul 2008 - Add #define to permit distance too far back - * - Add option in TEST code for puff to write the data - * - Add option in TEST code to skip input bytes - * - Allow TEST code to read from piped stdin - * 2.1 4 Apr 2010 - Avoid variable initialization for happier compilers - * - Avoid unsigned comparisons for even happier compilers - * 2.2 25 Apr 2010 - Fix bug in variable initializations [Oberhumer] - * - Add const where appropriate [Oberhumer] - * - Split if's and ?'s for coverage testing - * - Break out test code to separate file - * - Move NIL to puff.h - * - Allow incomplete code only if single code length is 1 - * - Add full code coverage test to Makefile - * 2.3 21 Jan 2013 - Check for invalid code length codes in dynamic blocks - */ - -#include /* for setjmp(), longjmp(), and jmp_buf */ -#include "puff.h" /* prototype for puff() */ - -#define local static /* for local function definitions */ - -/* - * Maximums for allocations and loops. It is not useful to change these -- - * they are fixed by the deflate format. - */ -#define MAXBITS 15 /* maximum bits in a code */ -#define MAXLCODES 286 /* maximum number of literal/length codes */ -#define MAXDCODES 30 /* maximum number of distance codes */ -#define MAXCODES (MAXLCODES+MAXDCODES) /* maximum codes lengths to read */ -#define FIXLCODES 288 /* number of fixed literal/length codes */ - -/* input and output state */ -struct state { - /* output state */ - unsigned char *out; /* output buffer */ - unsigned long outlen; /* available space at out */ - unsigned long outcnt; /* bytes written to out so far */ - - /* input state */ - const unsigned char *in; /* input buffer */ - unsigned long inlen; /* available input at in */ - unsigned long incnt; /* bytes read so far */ - int bitbuf; /* bit buffer */ - int bitcnt; /* number of bits in bit buffer */ - - /* input limit error return state for bits() and decode() */ - jmp_buf env; -}; - -/* - * Return need bits from the input stream. This always leaves less than - * eight bits in the buffer. bits() works properly for need == 0. - * - * Format notes: - * - * - Bits are stored in bytes from the least significant bit to the most - * significant bit. Therefore bits are dropped from the bottom of the bit - * buffer, using shift right, and new bytes are appended to the top of the - * bit buffer, using shift left. - */ -local int bits(struct state *s, int need) -{ - long val; /* bit accumulator (can use up to 20 bits) */ - - /* load at least need bits into val */ - val = s->bitbuf; - while (s->bitcnt < need) { - if (s->incnt == s->inlen) - longjmp(s->env, 1); /* out of input */ - val |= (long)(s->in[s->incnt++]) << s->bitcnt; /* load eight bits */ - s->bitcnt += 8; - } - - /* drop need bits and update buffer, always zero to seven bits left */ - s->bitbuf = (int)(val >> need); - s->bitcnt -= need; - - /* return need bits, zeroing the bits above that */ - return (int)(val & ((1L << need) - 1)); -} - -/* - * Process a stored block. - * - * Format notes: - * - * - After the two-bit stored block type (00), the stored block length and - * stored bytes are byte-aligned for fast copying. Therefore any leftover - * bits in the byte that has the last bit of the type, as many as seven, are - * discarded. The value of the discarded bits are not defined and should not - * be checked against any expectation. - * - * - The second inverted copy of the stored block length does not have to be - * checked, but it's probably a good idea to do so anyway. - * - * - A stored block can have zero length. This is sometimes used to byte-align - * subsets of the compressed data for random access or partial recovery. - */ -local int stored(struct state *s) -{ - unsigned len; /* length of stored block */ - - /* discard leftover bits from current byte (assumes s->bitcnt < 8) */ - s->bitbuf = 0; - s->bitcnt = 0; - - /* get length and check against its one's complement */ - if (s->incnt + 4 > s->inlen) - return 2; /* not enough input */ - len = s->in[s->incnt++]; - len |= s->in[s->incnt++] << 8; - if (s->in[s->incnt++] != (~len & 0xff) || - s->in[s->incnt++] != ((~len >> 8) & 0xff)) - return -2; /* didn't match complement! */ - - /* copy len bytes from in to out */ - if (s->incnt + len > s->inlen) - return 2; /* not enough input */ - if (s->out != NIL) { - if (s->outcnt + len > s->outlen) - return 1; /* not enough output space */ - while (len--) - s->out[s->outcnt++] = s->in[s->incnt++]; - } - else { /* just scanning */ - s->outcnt += len; - s->incnt += len; - } - - /* done with a valid stored block */ - return 0; -} - -/* - * Huffman code decoding tables. count[1..MAXBITS] is the number of symbols of - * each length, which for a canonical code are stepped through in order. - * symbol[] are the symbol values in canonical order, where the number of - * entries is the sum of the counts in count[]. The decoding process can be - * seen in the function decode() below. - */ -struct huffman { - short *count; /* number of symbols of each length */ - short *symbol; /* canonically ordered symbols */ -}; - -/* - * Decode a code from the stream s using huffman table h. Return the symbol or - * a negative value if there is an error. If all of the lengths are zero, i.e. - * an empty code, or if the code is incomplete and an invalid code is received, - * then -10 is returned after reading MAXBITS bits. - * - * Format notes: - * - * - The codes as stored in the compressed data are bit-reversed relative to - * a simple integer ordering of codes of the same lengths. Hence below the - * bits are pulled from the compressed data one at a time and used to - * build the code value reversed from what is in the stream in order to - * permit simple integer comparisons for decoding. A table-based decoding - * scheme (as used in zlib) does not need to do this reversal. - * - * - The first code for the shortest length is all zeros. Subsequent codes of - * the same length are simply integer increments of the previous code. When - * moving up a length, a zero bit is appended to the code. For a complete - * code, the last code of the longest length will be all ones. - * - * - Incomplete codes are handled by this decoder, since they are permitted - * in the deflate format. See the format notes for fixed() and dynamic(). - */ -#ifdef SLOW -local int decode(struct state *s, const struct huffman *h) -{ - int len; /* current number of bits in code */ - int code; /* len bits being decoded */ - int first; /* first code of length len */ - int count; /* number of codes of length len */ - int index; /* index of first code of length len in symbol table */ - - code = first = index = 0; - for (len = 1; len <= MAXBITS; len++) { - code |= bits(s, 1); /* get next bit */ - count = h->count[len]; - if (code - count < first) /* if length len, return symbol */ - return h->symbol[index + (code - first)]; - index += count; /* else update for next length */ - first += count; - first <<= 1; - code <<= 1; - } - return -10; /* ran out of codes */ -} - -/* - * A faster version of decode() for real applications of this code. It's not - * as readable, but it makes puff() twice as fast. And it only makes the code - * a few percent larger. - */ -#else /* !SLOW */ -local int decode(struct state *s, const struct huffman *h) -{ - int len; /* current number of bits in code */ - int code; /* len bits being decoded */ - int first; /* first code of length len */ - int count; /* number of codes of length len */ - int index; /* index of first code of length len in symbol table */ - int bitbuf; /* bits from stream */ - int left; /* bits left in next or left to process */ - short *next; /* next number of codes */ - - bitbuf = s->bitbuf; - left = s->bitcnt; - code = first = index = 0; - len = 1; - next = h->count + 1; - while (1) { - while (left--) { - code |= bitbuf & 1; - bitbuf >>= 1; - count = *next++; - if (code - count < first) { /* if length len, return symbol */ - s->bitbuf = bitbuf; - s->bitcnt = (s->bitcnt - len) & 7; - return h->symbol[index + (code - first)]; - } - index += count; /* else update for next length */ - first += count; - first <<= 1; - code <<= 1; - len++; - } - left = (MAXBITS+1) - len; - if (left == 0) - break; - if (s->incnt == s->inlen) - longjmp(s->env, 1); /* out of input */ - bitbuf = s->in[s->incnt++]; - if (left > 8) - left = 8; - } - return -10; /* ran out of codes */ -} -#endif /* SLOW */ - -/* - * Given the list of code lengths length[0..n-1] representing a canonical - * Huffman code for n symbols, construct the tables required to decode those - * codes. Those tables are the number of codes of each length, and the symbols - * sorted by length, retaining their original order within each length. The - * return value is zero for a complete code set, negative for an over- - * subscribed code set, and positive for an incomplete code set. The tables - * can be used if the return value is zero or positive, but they cannot be used - * if the return value is negative. If the return value is zero, it is not - * possible for decode() using that table to return an error--any stream of - * enough bits will resolve to a symbol. If the return value is positive, then - * it is possible for decode() using that table to return an error for received - * codes past the end of the incomplete lengths. - * - * Not used by decode(), but used for error checking, h->count[0] is the number - * of the n symbols not in the code. So n - h->count[0] is the number of - * codes. This is useful for checking for incomplete codes that have more than - * one symbol, which is an error in a dynamic block. - * - * Assumption: for all i in 0..n-1, 0 <= length[i] <= MAXBITS - * This is assured by the construction of the length arrays in dynamic() and - * fixed() and is not verified by construct(). - * - * Format notes: - * - * - Permitted and expected examples of incomplete codes are one of the fixed - * codes and any code with a single symbol which in deflate is coded as one - * bit instead of zero bits. See the format notes for fixed() and dynamic(). - * - * - Within a given code length, the symbols are kept in ascending order for - * the code bits definition. - */ -local int construct(struct huffman *h, const short *length, int n) -{ - int symbol; /* current symbol when stepping through length[] */ - int len; /* current length when stepping through h->count[] */ - int left; /* number of possible codes left of current length */ - short offs[MAXBITS+1]; /* offsets in symbol table for each length */ - - /* count number of codes of each length */ - for (len = 0; len <= MAXBITS; len++) - h->count[len] = 0; - for (symbol = 0; symbol < n; symbol++) - (h->count[length[symbol]])++; /* assumes lengths are within bounds */ - if (h->count[0] == n) /* no codes! */ - return 0; /* complete, but decode() will fail */ - - /* check for an over-subscribed or incomplete set of lengths */ - left = 1; /* one possible code of zero length */ - for (len = 1; len <= MAXBITS; len++) { - left <<= 1; /* one more bit, double codes left */ - left -= h->count[len]; /* deduct count from possible codes */ - if (left < 0) - return left; /* over-subscribed--return negative */ - } /* left > 0 means incomplete */ - - /* generate offsets into symbol table for each length for sorting */ - offs[1] = 0; - for (len = 1; len < MAXBITS; len++) - offs[len + 1] = offs[len] + h->count[len]; - - /* - * put symbols in table sorted by length, by symbol order within each - * length - */ - for (symbol = 0; symbol < n; symbol++) - if (length[symbol] != 0) - h->symbol[offs[length[symbol]]++] = symbol; - - /* return zero for complete set, positive for incomplete set */ - return left; -} - -/* - * Decode literal/length and distance codes until an end-of-block code. - * - * Format notes: - * - * - Compressed data that is after the block type if fixed or after the code - * description if dynamic is a combination of literals and length/distance - * pairs terminated by and end-of-block code. Literals are simply Huffman - * coded bytes. A length/distance pair is a coded length followed by a - * coded distance to represent a string that occurs earlier in the - * uncompressed data that occurs again at the current location. - * - * - Literals, lengths, and the end-of-block code are combined into a single - * code of up to 286 symbols. They are 256 literals (0..255), 29 length - * symbols (257..285), and the end-of-block symbol (256). - * - * - There are 256 possible lengths (3..258), and so 29 symbols are not enough - * to represent all of those. Lengths 3..10 and 258 are in fact represented - * by just a length symbol. Lengths 11..257 are represented as a symbol and - * some number of extra bits that are added as an integer to the base length - * of the length symbol. The number of extra bits is determined by the base - * length symbol. These are in the static arrays below, lens[] for the base - * lengths and lext[] for the corresponding number of extra bits. - * - * - The reason that 258 gets its own symbol is that the longest length is used - * often in highly redundant files. Note that 258 can also be coded as the - * base value 227 plus the maximum extra value of 31. While a good deflate - * should never do this, it is not an error, and should be decoded properly. - * - * - If a length is decoded, including its extra bits if any, then it is - * followed a distance code. There are up to 30 distance symbols. Again - * there are many more possible distances (1..32768), so extra bits are added - * to a base value represented by the symbol. The distances 1..4 get their - * own symbol, but the rest require extra bits. The base distances and - * corresponding number of extra bits are below in the static arrays dist[] - * and dext[]. - * - * - Literal bytes are simply written to the output. A length/distance pair is - * an instruction to copy previously uncompressed bytes to the output. The - * copy is from distance bytes back in the output stream, copying for length - * bytes. - * - * - Distances pointing before the beginning of the output data are not - * permitted. - * - * - Overlapped copies, where the length is greater than the distance, are - * allowed and common. For example, a distance of one and a length of 258 - * simply copies the last byte 258 times. A distance of four and a length of - * twelve copies the last four bytes three times. A simple forward copy - * ignoring whether the length is greater than the distance or not implements - * this correctly. You should not use memcpy() since its behavior is not - * defined for overlapped arrays. You should not use memmove() or bcopy() - * since though their behavior -is- defined for overlapping arrays, it is - * defined to do the wrong thing in this case. - */ -local int codes(struct state *s, - const struct huffman *lencode, - const struct huffman *distcode) -{ - int symbol; /* decoded symbol */ - int len; /* length for copy */ - unsigned dist; /* distance for copy */ - static const short lens[29] = { /* Size base for length codes 257..285 */ - 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, - 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258}; - static const short lext[29] = { /* Extra bits for length codes 257..285 */ - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, - 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0}; - static const short dists[30] = { /* Offset base for distance codes 0..29 */ - 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, - 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, - 8193, 12289, 16385, 24577}; - static const short dext[30] = { /* Extra bits for distance codes 0..29 */ - 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, - 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, - 12, 12, 13, 13}; - - /* decode literals and length/distance pairs */ - do { - symbol = decode(s, lencode); - if (symbol < 0) - return symbol; /* invalid symbol */ - if (symbol < 256) { /* literal: symbol is the byte */ - /* write out the literal */ - if (s->out != NIL) { - if (s->outcnt == s->outlen) - return 1; - s->out[s->outcnt] = symbol; - } - s->outcnt++; - } - else if (symbol > 256) { /* length */ - /* get and compute length */ - symbol -= 257; - if (symbol >= 29) - return -10; /* invalid fixed code */ - len = lens[symbol] + bits(s, lext[symbol]); - - /* get and check distance */ - symbol = decode(s, distcode); - if (symbol < 0) - return symbol; /* invalid symbol */ - dist = dists[symbol] + bits(s, dext[symbol]); -#ifndef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR - if (dist > s->outcnt) - return -11; /* distance too far back */ -#endif - - /* copy length bytes from distance bytes back */ - if (s->out != NIL) { - if (s->outcnt + len > s->outlen) - return 1; - while (len--) { - s->out[s->outcnt] = -#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR - dist > s->outcnt ? - 0 : -#endif - s->out[s->outcnt - dist]; - s->outcnt++; - } - } - else - s->outcnt += len; - } - } while (symbol != 256); /* end of block symbol */ - - /* done with a valid fixed or dynamic block */ - return 0; -} - -/* - * Process a fixed codes block. - * - * Format notes: - * - * - This block type can be useful for compressing small amounts of data for - * which the size of the code descriptions in a dynamic block exceeds the - * benefit of custom codes for that block. For fixed codes, no bits are - * spent on code descriptions. Instead the code lengths for literal/length - * codes and distance codes are fixed. The specific lengths for each symbol - * can be seen in the "for" loops below. - * - * - The literal/length code is complete, but has two symbols that are invalid - * and should result in an error if received. This cannot be implemented - * simply as an incomplete code since those two symbols are in the "middle" - * of the code. They are eight bits long and the longest literal/length\ - * code is nine bits. Therefore the code must be constructed with those - * symbols, and the invalid symbols must be detected after decoding. - * - * - The fixed distance codes also have two invalid symbols that should result - * in an error if received. Since all of the distance codes are the same - * length, this can be implemented as an incomplete code. Then the invalid - * codes are detected while decoding. - */ -local int fixed(struct state *s) -{ - static int virgin = 1; - static short lencnt[MAXBITS+1], lensym[FIXLCODES]; - static short distcnt[MAXBITS+1], distsym[MAXDCODES]; - static struct huffman lencode, distcode; - - /* build fixed huffman tables if first call (may not be thread safe) */ - if (virgin) { - int symbol; - short lengths[FIXLCODES]; - - /* construct lencode and distcode */ - lencode.count = lencnt; - lencode.symbol = lensym; - distcode.count = distcnt; - distcode.symbol = distsym; - - /* literal/length table */ - for (symbol = 0; symbol < 144; symbol++) - lengths[symbol] = 8; - for (; symbol < 256; symbol++) - lengths[symbol] = 9; - for (; symbol < 280; symbol++) - lengths[symbol] = 7; - for (; symbol < FIXLCODES; symbol++) - lengths[symbol] = 8; - construct(&lencode, lengths, FIXLCODES); - - /* distance table */ - for (symbol = 0; symbol < MAXDCODES; symbol++) - lengths[symbol] = 5; - construct(&distcode, lengths, MAXDCODES); - - /* do this just once */ - virgin = 0; - } - - /* decode data until end-of-block code */ - return codes(s, &lencode, &distcode); -} - -/* - * Process a dynamic codes block. - * - * Format notes: - * - * - A dynamic block starts with a description of the literal/length and - * distance codes for that block. New dynamic blocks allow the compressor to - * rapidly adapt to changing data with new codes optimized for that data. - * - * - The codes used by the deflate format are "canonical", which means that - * the actual bits of the codes are generated in an unambiguous way simply - * from the number of bits in each code. Therefore the code descriptions - * are simply a list of code lengths for each symbol. - * - * - The code lengths are stored in order for the symbols, so lengths are - * provided for each of the literal/length symbols, and for each of the - * distance symbols. - * - * - If a symbol is not used in the block, this is represented by a zero as - * as the code length. This does not mean a zero-length code, but rather - * that no code should be created for this symbol. There is no way in the - * deflate format to represent a zero-length code. - * - * - The maximum number of bits in a code is 15, so the possible lengths for - * any code are 1..15. - * - * - The fact that a length of zero is not permitted for a code has an - * interesting consequence. Normally if only one symbol is used for a given - * code, then in fact that code could be represented with zero bits. However - * in deflate, that code has to be at least one bit. So for example, if - * only a single distance base symbol appears in a block, then it will be - * represented by a single code of length one, in particular one 0 bit. This - * is an incomplete code, since if a 1 bit is received, it has no meaning, - * and should result in an error. So incomplete distance codes of one symbol - * should be permitted, and the receipt of invalid codes should be handled. - * - * - It is also possible to have a single literal/length code, but that code - * must be the end-of-block code, since every dynamic block has one. This - * is not the most efficient way to create an empty block (an empty fixed - * block is fewer bits), but it is allowed by the format. So incomplete - * literal/length codes of one symbol should also be permitted. - * - * - If there are only literal codes and no lengths, then there are no distance - * codes. This is represented by one distance code with zero bits. - * - * - The list of up to 286 length/literal lengths and up to 30 distance lengths - * are themselves compressed using Huffman codes and run-length encoding. In - * the list of code lengths, a 0 symbol means no code, a 1..15 symbol means - * that length, and the symbols 16, 17, and 18 are run-length instructions. - * Each of 16, 17, and 18 are follwed by extra bits to define the length of - * the run. 16 copies the last length 3 to 6 times. 17 represents 3 to 10 - * zero lengths, and 18 represents 11 to 138 zero lengths. Unused symbols - * are common, hence the special coding for zero lengths. - * - * - The symbols for 0..18 are Huffman coded, and so that code must be - * described first. This is simply a sequence of up to 19 three-bit values - * representing no code (0) or the code length for that symbol (1..7). - * - * - A dynamic block starts with three fixed-size counts from which is computed - * the number of literal/length code lengths, the number of distance code - * lengths, and the number of code length code lengths (ok, you come up with - * a better name!) in the code descriptions. For the literal/length and - * distance codes, lengths after those provided are considered zero, i.e. no - * code. The code length code lengths are received in a permuted order (see - * the order[] array below) to make a short code length code length list more - * likely. As it turns out, very short and very long codes are less likely - * to be seen in a dynamic code description, hence what may appear initially - * to be a peculiar ordering. - * - * - Given the number of literal/length code lengths (nlen) and distance code - * lengths (ndist), then they are treated as one long list of nlen + ndist - * code lengths. Therefore run-length coding can and often does cross the - * boundary between the two sets of lengths. - * - * - So to summarize, the code description at the start of a dynamic block is - * three counts for the number of code lengths for the literal/length codes, - * the distance codes, and the code length codes. This is followed by the - * code length code lengths, three bits each. This is used to construct the - * code length code which is used to read the remainder of the lengths. Then - * the literal/length code lengths and distance lengths are read as a single - * set of lengths using the code length codes. Codes are constructed from - * the resulting two sets of lengths, and then finally you can start - * decoding actual compressed data in the block. - * - * - For reference, a "typical" size for the code description in a dynamic - * block is around 80 bytes. - */ -local int dynamic(struct state *s) -{ - int nlen, ndist, ncode; /* number of lengths in descriptor */ - int index; /* index of lengths[] */ - int err; /* construct() return value */ - short lengths[MAXCODES]; /* descriptor code lengths */ - short lencnt[MAXBITS+1], lensym[MAXLCODES]; /* lencode memory */ - short distcnt[MAXBITS+1], distsym[MAXDCODES]; /* distcode memory */ - struct huffman lencode, distcode; /* length and distance codes */ - static const short order[19] = /* permutation of code length codes */ - {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; - - /* construct lencode and distcode */ - lencode.count = lencnt; - lencode.symbol = lensym; - distcode.count = distcnt; - distcode.symbol = distsym; - - /* get number of lengths in each table, check lengths */ - nlen = bits(s, 5) + 257; - ndist = bits(s, 5) + 1; - ncode = bits(s, 4) + 4; - if (nlen > MAXLCODES || ndist > MAXDCODES) - return -3; /* bad counts */ - - /* read code length code lengths (really), missing lengths are zero */ - for (index = 0; index < ncode; index++) - lengths[order[index]] = bits(s, 3); - for (; index < 19; index++) - lengths[order[index]] = 0; - - /* build huffman table for code lengths codes (use lencode temporarily) */ - err = construct(&lencode, lengths, 19); - if (err != 0) /* require complete code set here */ - return -4; - - /* read length/literal and distance code length tables */ - index = 0; - while (index < nlen + ndist) { - int symbol; /* decoded value */ - int len; /* last length to repeat */ - - symbol = decode(s, &lencode); - if (symbol < 0) - return symbol; /* invalid symbol */ - if (symbol < 16) /* length in 0..15 */ - lengths[index++] = symbol; - else { /* repeat instruction */ - len = 0; /* assume repeating zeros */ - if (symbol == 16) { /* repeat last length 3..6 times */ - if (index == 0) - return -5; /* no last length! */ - len = lengths[index - 1]; /* last length */ - symbol = 3 + bits(s, 2); - } - else if (symbol == 17) /* repeat zero 3..10 times */ - symbol = 3 + bits(s, 3); - else /* == 18, repeat zero 11..138 times */ - symbol = 11 + bits(s, 7); - if (index + symbol > nlen + ndist) - return -6; /* too many lengths! */ - while (symbol--) /* repeat last or zero symbol times */ - lengths[index++] = len; - } - } - - /* check for end-of-block code -- there better be one! */ - if (lengths[256] == 0) - return -9; - - /* build huffman table for literal/length codes */ - err = construct(&lencode, lengths, nlen); - if (err && (err < 0 || nlen != lencode.count[0] + lencode.count[1])) - return -7; /* incomplete code ok only for single length 1 code */ - - /* build huffman table for distance codes */ - err = construct(&distcode, lengths + nlen, ndist); - if (err && (err < 0 || ndist != distcode.count[0] + distcode.count[1])) - return -8; /* incomplete code ok only for single length 1 code */ - - /* decode data until end-of-block code */ - return codes(s, &lencode, &distcode); -} - -/* - * Inflate source to dest. On return, destlen and sourcelen are updated to the - * size of the uncompressed data and the size of the deflate data respectively. - * On success, the return value of puff() is zero. If there is an error in the - * source data, i.e. it is not in the deflate format, then a negative value is - * returned. If there is not enough input available or there is not enough - * output space, then a positive error is returned. In that case, destlen and - * sourcelen are not updated to facilitate retrying from the beginning with the - * provision of more input data or more output space. In the case of invalid - * inflate data (a negative error), the dest and source pointers are updated to - * facilitate the debugging of deflators. - * - * puff() also has a mode to determine the size of the uncompressed output with - * no output written. For this dest must be (unsigned char *)0. In this case, - * the input value of *destlen is ignored, and on return *destlen is set to the - * size of the uncompressed output. - * - * The return codes are: - * - * 2: available inflate data did not terminate - * 1: output space exhausted before completing inflate - * 0: successful inflate - * -1: invalid block type (type == 3) - * -2: stored block length did not match one's complement - * -3: dynamic block code description: too many length or distance codes - * -4: dynamic block code description: code lengths codes incomplete - * -5: dynamic block code description: repeat lengths with no first length - * -6: dynamic block code description: repeat more than specified lengths - * -7: dynamic block code description: invalid literal/length code lengths - * -8: dynamic block code description: invalid distance code lengths - * -9: dynamic block code description: missing end-of-block code - * -10: invalid literal/length or distance code in fixed or dynamic block - * -11: distance is too far back in fixed or dynamic block - * - * Format notes: - * - * - Three bits are read for each block to determine the kind of block and - * whether or not it is the last block. Then the block is decoded and the - * process repeated if it was not the last block. - * - * - The leftover bits in the last byte of the deflate data after the last - * block (if it was a fixed or dynamic block) are undefined and have no - * expected values to check. - */ -int puff(unsigned char *dest, /* pointer to destination pointer */ - unsigned long *destlen, /* amount of output space */ - const unsigned char *source, /* pointer to source data pointer */ - unsigned long *sourcelen) /* amount of input available */ -{ - struct state s; /* input/output state */ - int last, type; /* block information */ - int err; /* return value */ - - /* initialize output state */ - s.out = dest; - s.outlen = *destlen; /* ignored if dest is NIL */ - s.outcnt = 0; - - /* initialize input state */ - s.in = source; - s.inlen = *sourcelen; - s.incnt = 0; - s.bitbuf = 0; - s.bitcnt = 0; - - /* return if bits() or decode() tries to read past available input */ - if (setjmp(s.env) != 0) /* if came back here via longjmp() */ - err = 2; /* then skip do-loop, return error */ - else { - /* process blocks until last block or error */ - do { - last = bits(&s, 1); /* one if last block */ - type = bits(&s, 2); /* block type 0..3 */ - err = type == 0 ? - stored(&s) : - (type == 1 ? - fixed(&s) : - (type == 2 ? - dynamic(&s) : - -1)); /* type == 3, invalid */ - if (err != 0) - break; /* return with error */ - } while (!last); - } - - /* update the lengths and return */ - if (err <= 0) { - *destlen = s.outcnt; - *sourcelen = s.incnt; - } - return err; -} diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/puff/puff.h b/src/beast/test/zlib/zlib-1.2.8/contrib/puff/puff.h deleted file mode 100644 index e23a2454316..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/puff/puff.h +++ /dev/null @@ -1,35 +0,0 @@ -/* puff.h - Copyright (C) 2002-2013 Mark Adler, all rights reserved - version 2.3, 21 Jan 2013 - - This software is provided 'as-is', without any express or implied - warranty. In no event will the author be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Mark Adler madler@alumni.caltech.edu - */ - - -/* - * See puff.c for purpose and usage. - */ -#ifndef NIL -# define NIL ((unsigned char *)0) /* for no output option */ -#endif - -int puff(unsigned char *dest, /* pointer to destination pointer */ - unsigned long *destlen, /* amount of output space */ - const unsigned char *source, /* pointer to source data pointer */ - unsigned long *sourcelen); /* amount of input available */ diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/puff/pufftest.c b/src/beast/test/zlib/zlib-1.2.8/contrib/puff/pufftest.c deleted file mode 100644 index 776481488c9..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/puff/pufftest.c +++ /dev/null @@ -1,165 +0,0 @@ -/* - * pufftest.c - * Copyright (C) 2002-2013 Mark Adler - * For conditions of distribution and use, see copyright notice in puff.h - * version 2.3, 21 Jan 2013 - */ - -/* Example of how to use puff(). - - Usage: puff [-w] [-f] [-nnn] file - ... | puff [-w] [-f] [-nnn] - - where file is the input file with deflate data, nnn is the number of bytes - of input to skip before inflating (e.g. to skip a zlib or gzip header), and - -w is used to write the decompressed data to stdout. -f is for coverage - testing, and causes pufftest to fail with not enough output space (-f does - a write like -w, so -w is not required). */ - -#include -#include -#include "puff.h" - -#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) -# include -# include -# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) -#else -# define SET_BINARY_MODE(file) -#endif - -#define local static - -/* Return size times approximately the cube root of 2, keeping the result as 1, - 3, or 5 times a power of 2 -- the result is always > size, until the result - is the maximum value of an unsigned long, where it remains. This is useful - to keep reallocations less than ~33% over the actual data. */ -local size_t bythirds(size_t size) -{ - int n; - size_t m; - - m = size; - for (n = 0; m; n++) - m >>= 1; - if (n < 3) - return size + 1; - n -= 3; - m = size >> n; - m += m == 6 ? 2 : 1; - m <<= n; - return m > size ? m : (size_t)(-1); -} - -/* Read the input file *name, or stdin if name is NULL, into allocated memory. - Reallocate to larger buffers until the entire file is read in. Return a - pointer to the allocated data, or NULL if there was a memory allocation - failure. *len is the number of bytes of data read from the input file (even - if load() returns NULL). If the input file was empty or could not be opened - or read, *len is zero. */ -local void *load(const char *name, size_t *len) -{ - size_t size; - void *buf, *swap; - FILE *in; - - *len = 0; - buf = malloc(size = 4096); - if (buf == NULL) - return NULL; - in = name == NULL ? stdin : fopen(name, "rb"); - if (in != NULL) { - for (;;) { - *len += fread((char *)buf + *len, 1, size - *len, in); - if (*len < size) break; - size = bythirds(size); - if (size == *len || (swap = realloc(buf, size)) == NULL) { - free(buf); - buf = NULL; - break; - } - buf = swap; - } - fclose(in); - } - return buf; -} - -int main(int argc, char **argv) -{ - int ret, put = 0, fail = 0; - unsigned skip = 0; - char *arg, *name = NULL; - unsigned char *source = NULL, *dest; - size_t len = 0; - unsigned long sourcelen, destlen; - - /* process arguments */ - while (arg = *++argv, --argc) - if (arg[0] == '-') { - if (arg[1] == 'w' && arg[2] == 0) - put = 1; - else if (arg[1] == 'f' && arg[2] == 0) - fail = 1, put = 1; - else if (arg[1] >= '0' && arg[1] <= '9') - skip = (unsigned)atoi(arg + 1); - else { - fprintf(stderr, "invalid option %s\n", arg); - return 3; - } - } - else if (name != NULL) { - fprintf(stderr, "only one file name allowed\n"); - return 3; - } - else - name = arg; - source = load(name, &len); - if (source == NULL) { - fprintf(stderr, "memory allocation failure\n"); - return 4; - } - if (len == 0) { - fprintf(stderr, "could not read %s, or it was empty\n", - name == NULL ? "" : name); - free(source); - return 3; - } - if (skip >= len) { - fprintf(stderr, "skip request of %d leaves no input\n", skip); - free(source); - return 3; - } - - /* test inflate data with offset skip */ - len -= skip; - sourcelen = (unsigned long)len; - ret = puff(NIL, &destlen, source + skip, &sourcelen); - if (ret) - fprintf(stderr, "puff() failed with return code %d\n", ret); - else { - fprintf(stderr, "puff() succeeded uncompressing %lu bytes\n", destlen); - if (sourcelen < len) fprintf(stderr, "%lu compressed bytes unused\n", - len - sourcelen); - } - - /* if requested, inflate again and write decompressd data to stdout */ - if (put && ret == 0) { - if (fail) - destlen >>= 1; - dest = malloc(destlen); - if (dest == NULL) { - fprintf(stderr, "memory allocation failure\n"); - free(source); - return 4; - } - puff(dest, &destlen, source + skip, &sourcelen); - SET_BINARY_MODE(stdout); - fwrite(dest, 1, destlen, stdout); - free(dest); - } - - /* clean up */ - free(source); - return ret; -} diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/puff/zeros.raw b/src/beast/test/zlib/zlib-1.2.8/contrib/puff/zeros.raw deleted file mode 100644 index 0a90e76b300..00000000000 Binary files a/src/beast/test/zlib/zlib-1.2.8/contrib/puff/zeros.raw and /dev/null differ diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/testzlib/testzlib.c b/src/beast/test/zlib/zlib-1.2.8/contrib/testzlib/testzlib.c deleted file mode 100644 index 8626c92ad17..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/testzlib/testzlib.c +++ /dev/null @@ -1,275 +0,0 @@ -#include -#include -#include - -#include "zlib.h" - - -void MyDoMinus64(LARGE_INTEGER *R,LARGE_INTEGER A,LARGE_INTEGER B) -{ - R->HighPart = A.HighPart - B.HighPart; - if (A.LowPart >= B.LowPart) - R->LowPart = A.LowPart - B.LowPart; - else - { - R->LowPart = A.LowPart - B.LowPart; - R->HighPart --; - } -} - -#ifdef _M_X64 -// see http://msdn2.microsoft.com/library/twchhe95(en-us,vs.80).aspx for __rdtsc -unsigned __int64 __rdtsc(void); -void BeginCountRdtsc(LARGE_INTEGER * pbeginTime64) -{ - // printf("rdtsc = %I64x\n",__rdtsc()); - pbeginTime64->QuadPart=__rdtsc(); -} - -LARGE_INTEGER GetResRdtsc(LARGE_INTEGER beginTime64,BOOL fComputeTimeQueryPerf) -{ - LARGE_INTEGER LIres; - unsigned _int64 res=__rdtsc()-((unsigned _int64)(beginTime64.QuadPart)); - LIres.QuadPart=res; - // printf("rdtsc = %I64x\n",__rdtsc()); - return LIres; -} -#else -#ifdef _M_IX86 -void myGetRDTSC32(LARGE_INTEGER * pbeginTime64) -{ - DWORD dwEdx,dwEax; - _asm - { - rdtsc - mov dwEax,eax - mov dwEdx,edx - } - pbeginTime64->LowPart=dwEax; - pbeginTime64->HighPart=dwEdx; -} - -void BeginCountRdtsc(LARGE_INTEGER * pbeginTime64) -{ - myGetRDTSC32(pbeginTime64); -} - -LARGE_INTEGER GetResRdtsc(LARGE_INTEGER beginTime64,BOOL fComputeTimeQueryPerf) -{ - LARGE_INTEGER LIres,endTime64; - myGetRDTSC32(&endTime64); - - LIres.LowPart=LIres.HighPart=0; - MyDoMinus64(&LIres,endTime64,beginTime64); - return LIres; -} -#else -void myGetRDTSC32(LARGE_INTEGER * pbeginTime64) -{ -} - -void BeginCountRdtsc(LARGE_INTEGER * pbeginTime64) -{ -} - -LARGE_INTEGER GetResRdtsc(LARGE_INTEGER beginTime64,BOOL fComputeTimeQueryPerf) -{ - LARGE_INTEGER lr; - lr.QuadPart=0; - return lr; -} -#endif -#endif - -void BeginCountPerfCounter(LARGE_INTEGER * pbeginTime64,BOOL fComputeTimeQueryPerf) -{ - if ((!fComputeTimeQueryPerf) || (!QueryPerformanceCounter(pbeginTime64))) - { - pbeginTime64->LowPart = GetTickCount(); - pbeginTime64->HighPart = 0; - } -} - -DWORD GetMsecSincePerfCounter(LARGE_INTEGER beginTime64,BOOL fComputeTimeQueryPerf) -{ - LARGE_INTEGER endTime64,ticksPerSecond,ticks; - DWORDLONG ticksShifted,tickSecShifted; - DWORD dwLog=16+0; - DWORD dwRet; - if ((!fComputeTimeQueryPerf) || (!QueryPerformanceCounter(&endTime64))) - dwRet = (GetTickCount() - beginTime64.LowPart)*1; - else - { - MyDoMinus64(&ticks,endTime64,beginTime64); - QueryPerformanceFrequency(&ticksPerSecond); - - - { - ticksShifted = Int64ShrlMod32(*(DWORDLONG*)&ticks,dwLog); - tickSecShifted = Int64ShrlMod32(*(DWORDLONG*)&ticksPerSecond,dwLog); - - } - - dwRet = (DWORD)((((DWORD)ticksShifted)*1000)/(DWORD)(tickSecShifted)); - dwRet *=1; - } - return dwRet; -} - -int ReadFileMemory(const char* filename,long* plFileSize,unsigned char** pFilePtr) -{ - FILE* stream; - unsigned char* ptr; - int retVal=1; - stream=fopen(filename, "rb"); - if (stream==NULL) - return 0; - - fseek(stream,0,SEEK_END); - - *plFileSize=ftell(stream); - fseek(stream,0,SEEK_SET); - ptr=malloc((*plFileSize)+1); - if (ptr==NULL) - retVal=0; - else - { - if (fread(ptr, 1, *plFileSize,stream) != (*plFileSize)) - retVal=0; - } - fclose(stream); - *pFilePtr=ptr; - return retVal; -} - -int main(int argc, char *argv[]) -{ - int BlockSizeCompress=0x8000; - int BlockSizeUncompress=0x8000; - int cprLevel=Z_DEFAULT_COMPRESSION ; - long lFileSize; - unsigned char* FilePtr; - long lBufferSizeCpr; - long lBufferSizeUncpr; - long lCompressedSize=0; - unsigned char* CprPtr; - unsigned char* UncprPtr; - long lSizeCpr,lSizeUncpr; - DWORD dwGetTick,dwMsecQP; - LARGE_INTEGER li_qp,li_rdtsc,dwResRdtsc; - - if (argc<=1) - { - printf("run TestZlib [BlockSizeCompress] [BlockSizeUncompress] [compres. level]\n"); - return 0; - } - - if (ReadFileMemory(argv[1],&lFileSize,&FilePtr)==0) - { - printf("error reading %s\n",argv[1]); - return 1; - } - else printf("file %s read, %u bytes\n",argv[1],lFileSize); - - if (argc>=3) - BlockSizeCompress=atol(argv[2]); - - if (argc>=4) - BlockSizeUncompress=atol(argv[3]); - - if (argc>=5) - cprLevel=(int)atol(argv[4]); - - lBufferSizeCpr = lFileSize + (lFileSize/0x10) + 0x200; - lBufferSizeUncpr = lBufferSizeCpr; - - CprPtr=(unsigned char*)malloc(lBufferSizeCpr + BlockSizeCompress); - - BeginCountPerfCounter(&li_qp,TRUE); - dwGetTick=GetTickCount(); - BeginCountRdtsc(&li_rdtsc); - { - z_stream zcpr; - int ret=Z_OK; - long lOrigToDo = lFileSize; - long lOrigDone = 0; - int step=0; - memset(&zcpr,0,sizeof(z_stream)); - deflateInit(&zcpr,cprLevel); - - zcpr.next_in = FilePtr; - zcpr.next_out = CprPtr; - - - do - { - long all_read_before = zcpr.total_in; - zcpr.avail_in = min(lOrigToDo,BlockSizeCompress); - zcpr.avail_out = BlockSizeCompress; - ret=deflate(&zcpr,(zcpr.avail_in==lOrigToDo) ? Z_FINISH : Z_SYNC_FLUSH); - lOrigDone += (zcpr.total_in-all_read_before); - lOrigToDo -= (zcpr.total_in-all_read_before); - step++; - } while (ret==Z_OK); - - lSizeCpr=zcpr.total_out; - deflateEnd(&zcpr); - dwGetTick=GetTickCount()-dwGetTick; - dwMsecQP=GetMsecSincePerfCounter(li_qp,TRUE); - dwResRdtsc=GetResRdtsc(li_rdtsc,TRUE); - printf("total compress size = %u, in %u step\n",lSizeCpr,step); - printf("time = %u msec = %f sec\n",dwGetTick,dwGetTick/(double)1000.); - printf("defcpr time QP = %u msec = %f sec\n",dwMsecQP,dwMsecQP/(double)1000.); - printf("defcpr result rdtsc = %I64x\n\n",dwResRdtsc.QuadPart); - } - - CprPtr=(unsigned char*)realloc(CprPtr,lSizeCpr); - UncprPtr=(unsigned char*)malloc(lBufferSizeUncpr + BlockSizeUncompress); - - BeginCountPerfCounter(&li_qp,TRUE); - dwGetTick=GetTickCount(); - BeginCountRdtsc(&li_rdtsc); - { - z_stream zcpr; - int ret=Z_OK; - long lOrigToDo = lSizeCpr; - long lOrigDone = 0; - int step=0; - memset(&zcpr,0,sizeof(z_stream)); - inflateInit(&zcpr); - - zcpr.next_in = CprPtr; - zcpr.next_out = UncprPtr; - - - do - { - long all_read_before = zcpr.total_in; - zcpr.avail_in = min(lOrigToDo,BlockSizeUncompress); - zcpr.avail_out = BlockSizeUncompress; - ret=inflate(&zcpr,Z_SYNC_FLUSH); - lOrigDone += (zcpr.total_in-all_read_before); - lOrigToDo -= (zcpr.total_in-all_read_before); - step++; - } while (ret==Z_OK); - - lSizeUncpr=zcpr.total_out; - inflateEnd(&zcpr); - dwGetTick=GetTickCount()-dwGetTick; - dwMsecQP=GetMsecSincePerfCounter(li_qp,TRUE); - dwResRdtsc=GetResRdtsc(li_rdtsc,TRUE); - printf("total uncompress size = %u, in %u step\n",lSizeUncpr,step); - printf("time = %u msec = %f sec\n",dwGetTick,dwGetTick/(double)1000.); - printf("uncpr time QP = %u msec = %f sec\n",dwMsecQP,dwMsecQP/(double)1000.); - printf("uncpr result rdtsc = %I64x\n\n",dwResRdtsc.QuadPart); - } - - if (lSizeUncpr==lFileSize) - { - if (memcmp(FilePtr,UncprPtr,lFileSize)==0) - printf("compare ok\n"); - - } - - return 0; -} diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/testzlib/testzlib.txt b/src/beast/test/zlib/zlib-1.2.8/contrib/testzlib/testzlib.txt deleted file mode 100644 index e508bb22ff4..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/testzlib/testzlib.txt +++ /dev/null @@ -1,10 +0,0 @@ -To build testzLib with Visual Studio 2005: - -copy to a directory file from : -- root of zLib tree -- contrib/testzlib -- contrib/masmx86 -- contrib/masmx64 -- contrib/vstudio/vc7 - -and open testzlib8.sln \ No newline at end of file diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/untgz/Makefile b/src/beast/test/zlib/zlib-1.2.8/contrib/untgz/Makefile deleted file mode 100644 index b54266fba20..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/untgz/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -CC=cc -CFLAGS=-g - -untgz: untgz.o ../../libz.a - $(CC) $(CFLAGS) -o untgz untgz.o -L../.. -lz - -untgz.o: untgz.c ../../zlib.h - $(CC) $(CFLAGS) -c -I../.. untgz.c - -../../libz.a: - cd ../..; ./configure; make - -clean: - rm -f untgz untgz.o *~ diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/untgz/Makefile.msc b/src/beast/test/zlib/zlib-1.2.8/contrib/untgz/Makefile.msc deleted file mode 100644 index 77b86022137..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/untgz/Makefile.msc +++ /dev/null @@ -1,17 +0,0 @@ -CC=cl -CFLAGS=-MD - -untgz.exe: untgz.obj ..\..\zlib.lib - $(CC) $(CFLAGS) untgz.obj ..\..\zlib.lib - -untgz.obj: untgz.c ..\..\zlib.h - $(CC) $(CFLAGS) -c -I..\.. untgz.c - -..\..\zlib.lib: - cd ..\.. - $(MAKE) -f win32\makefile.msc - cd contrib\untgz - -clean: - -del untgz.obj - -del untgz.exe diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/untgz/untgz.c b/src/beast/test/zlib/zlib-1.2.8/contrib/untgz/untgz.c deleted file mode 100644 index 2c391e59867..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/untgz/untgz.c +++ /dev/null @@ -1,674 +0,0 @@ -/* - * untgz.c -- Display contents and extract files from a gzip'd TAR file - * - * written by Pedro A. Aranda Gutierrez - * adaptation to Unix by Jean-loup Gailly - * various fixes by Cosmin Truta - */ - -#include -#include -#include -#include -#include - -#include "zlib.h" - -#ifdef unix -# include -#else -# include -# include -#endif - -#ifdef WIN32 -#include -# ifndef F_OK -# define F_OK 0 -# endif -# define mkdir(dirname,mode) _mkdir(dirname) -# ifdef _MSC_VER -# define access(path,mode) _access(path,mode) -# define chmod(path,mode) _chmod(path,mode) -# define strdup(str) _strdup(str) -# endif -#else -# include -#endif - - -/* values used in typeflag field */ - -#define REGTYPE '0' /* regular file */ -#define AREGTYPE '\0' /* regular file */ -#define LNKTYPE '1' /* link */ -#define SYMTYPE '2' /* reserved */ -#define CHRTYPE '3' /* character special */ -#define BLKTYPE '4' /* block special */ -#define DIRTYPE '5' /* directory */ -#define FIFOTYPE '6' /* FIFO special */ -#define CONTTYPE '7' /* reserved */ - -/* GNU tar extensions */ - -#define GNUTYPE_DUMPDIR 'D' /* file names from dumped directory */ -#define GNUTYPE_LONGLINK 'K' /* long link name */ -#define GNUTYPE_LONGNAME 'L' /* long file name */ -#define GNUTYPE_MULTIVOL 'M' /* continuation of file from another volume */ -#define GNUTYPE_NAMES 'N' /* file name that does not fit into main hdr */ -#define GNUTYPE_SPARSE 'S' /* sparse file */ -#define GNUTYPE_VOLHDR 'V' /* tape/volume header */ - - -/* tar header */ - -#define BLOCKSIZE 512 -#define SHORTNAMESIZE 100 - -struct tar_header -{ /* byte offset */ - char name[100]; /* 0 */ - char mode[8]; /* 100 */ - char uid[8]; /* 108 */ - char gid[8]; /* 116 */ - char size[12]; /* 124 */ - char mtime[12]; /* 136 */ - char chksum[8]; /* 148 */ - char typeflag; /* 156 */ - char linkname[100]; /* 157 */ - char magic[6]; /* 257 */ - char version[2]; /* 263 */ - char uname[32]; /* 265 */ - char gname[32]; /* 297 */ - char devmajor[8]; /* 329 */ - char devminor[8]; /* 337 */ - char prefix[155]; /* 345 */ - /* 500 */ -}; - -union tar_buffer -{ - char buffer[BLOCKSIZE]; - struct tar_header header; -}; - -struct attr_item -{ - struct attr_item *next; - char *fname; - int mode; - time_t time; -}; - -enum { TGZ_EXTRACT, TGZ_LIST, TGZ_INVALID }; - -char *TGZfname OF((const char *)); -void TGZnotfound OF((const char *)); - -int getoct OF((char *, int)); -char *strtime OF((time_t *)); -int setfiletime OF((char *, time_t)); -void push_attr OF((struct attr_item **, char *, int, time_t)); -void restore_attr OF((struct attr_item **)); - -int ExprMatch OF((char *, char *)); - -int makedir OF((char *)); -int matchname OF((int, int, char **, char *)); - -void error OF((const char *)); -int tar OF((gzFile, int, int, int, char **)); - -void help OF((int)); -int main OF((int, char **)); - -char *prog; - -const char *TGZsuffix[] = { "\0", ".tar", ".tar.gz", ".taz", ".tgz", NULL }; - -/* return the file name of the TGZ archive */ -/* or NULL if it does not exist */ - -char *TGZfname (const char *arcname) -{ - static char buffer[1024]; - int origlen,i; - - strcpy(buffer,arcname); - origlen = strlen(buffer); - - for (i=0; TGZsuffix[i]; i++) - { - strcpy(buffer+origlen,TGZsuffix[i]); - if (access(buffer,F_OK) == 0) - return buffer; - } - return NULL; -} - - -/* error message for the filename */ - -void TGZnotfound (const char *arcname) -{ - int i; - - fprintf(stderr,"%s: Couldn't find ",prog); - for (i=0;TGZsuffix[i];i++) - fprintf(stderr,(TGZsuffix[i+1]) ? "%s%s, " : "or %s%s\n", - arcname, - TGZsuffix[i]); - exit(1); -} - - -/* convert octal digits to int */ -/* on error return -1 */ - -int getoct (char *p,int width) -{ - int result = 0; - char c; - - while (width--) - { - c = *p++; - if (c == 0) - break; - if (c == ' ') - continue; - if (c < '0' || c > '7') - return -1; - result = result * 8 + (c - '0'); - } - return result; -} - - -/* convert time_t to string */ -/* use the "YYYY/MM/DD hh:mm:ss" format */ - -char *strtime (time_t *t) -{ - struct tm *local; - static char result[32]; - - local = localtime(t); - sprintf(result,"%4d/%02d/%02d %02d:%02d:%02d", - local->tm_year+1900, local->tm_mon+1, local->tm_mday, - local->tm_hour, local->tm_min, local->tm_sec); - return result; -} - - -/* set file time */ - -int setfiletime (char *fname,time_t ftime) -{ -#ifdef WIN32 - static int isWinNT = -1; - SYSTEMTIME st; - FILETIME locft, modft; - struct tm *loctm; - HANDLE hFile; - int result; - - loctm = localtime(&ftime); - if (loctm == NULL) - return -1; - - st.wYear = (WORD)loctm->tm_year + 1900; - st.wMonth = (WORD)loctm->tm_mon + 1; - st.wDayOfWeek = (WORD)loctm->tm_wday; - st.wDay = (WORD)loctm->tm_mday; - st.wHour = (WORD)loctm->tm_hour; - st.wMinute = (WORD)loctm->tm_min; - st.wSecond = (WORD)loctm->tm_sec; - st.wMilliseconds = 0; - if (!SystemTimeToFileTime(&st, &locft) || - !LocalFileTimeToFileTime(&locft, &modft)) - return -1; - - if (isWinNT < 0) - isWinNT = (GetVersion() < 0x80000000) ? 1 : 0; - hFile = CreateFile(fname, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, - (isWinNT ? FILE_FLAG_BACKUP_SEMANTICS : 0), - NULL); - if (hFile == INVALID_HANDLE_VALUE) - return -1; - result = SetFileTime(hFile, NULL, NULL, &modft) ? 0 : -1; - CloseHandle(hFile); - return result; -#else - struct utimbuf settime; - - settime.actime = settime.modtime = ftime; - return utime(fname,&settime); -#endif -} - - -/* push file attributes */ - -void push_attr(struct attr_item **list,char *fname,int mode,time_t time) -{ - struct attr_item *item; - - item = (struct attr_item *)malloc(sizeof(struct attr_item)); - if (item == NULL) - error("Out of memory"); - item->fname = strdup(fname); - item->mode = mode; - item->time = time; - item->next = *list; - *list = item; -} - - -/* restore file attributes */ - -void restore_attr(struct attr_item **list) -{ - struct attr_item *item, *prev; - - for (item = *list; item != NULL; ) - { - setfiletime(item->fname,item->time); - chmod(item->fname,item->mode); - prev = item; - item = item->next; - free(prev); - } - *list = NULL; -} - - -/* match regular expression */ - -#define ISSPECIAL(c) (((c) == '*') || ((c) == '/')) - -int ExprMatch (char *string,char *expr) -{ - while (1) - { - if (ISSPECIAL(*expr)) - { - if (*expr == '/') - { - if (*string != '\\' && *string != '/') - return 0; - string ++; expr++; - } - else if (*expr == '*') - { - if (*expr ++ == 0) - return 1; - while (*++string != *expr) - if (*string == 0) - return 0; - } - } - else - { - if (*string != *expr) - return 0; - if (*expr++ == 0) - return 1; - string++; - } - } -} - - -/* recursive mkdir */ -/* abort on ENOENT; ignore other errors like "directory already exists" */ -/* return 1 if OK */ -/* 0 on error */ - -int makedir (char *newdir) -{ - char *buffer = strdup(newdir); - char *p; - int len = strlen(buffer); - - if (len <= 0) { - free(buffer); - return 0; - } - if (buffer[len-1] == '/') { - buffer[len-1] = '\0'; - } - if (mkdir(buffer, 0755) == 0) - { - free(buffer); - return 1; - } - - p = buffer+1; - while (1) - { - char hold; - - while(*p && *p != '\\' && *p != '/') - p++; - hold = *p; - *p = 0; - if ((mkdir(buffer, 0755) == -1) && (errno == ENOENT)) - { - fprintf(stderr,"%s: Couldn't create directory %s\n",prog,buffer); - free(buffer); - return 0; - } - if (hold == 0) - break; - *p++ = hold; - } - free(buffer); - return 1; -} - - -int matchname (int arg,int argc,char **argv,char *fname) -{ - if (arg == argc) /* no arguments given (untgz tgzarchive) */ - return 1; - - while (arg < argc) - if (ExprMatch(fname,argv[arg++])) - return 1; - - return 0; /* ignore this for the moment being */ -} - - -/* tar file list or extract */ - -int tar (gzFile in,int action,int arg,int argc,char **argv) -{ - union tar_buffer buffer; - int len; - int err; - int getheader = 1; - int remaining = 0; - FILE *outfile = NULL; - char fname[BLOCKSIZE]; - int tarmode; - time_t tartime; - struct attr_item *attributes = NULL; - - if (action == TGZ_LIST) - printf(" date time size file\n" - " ---------- -------- --------- -------------------------------------\n"); - while (1) - { - len = gzread(in, &buffer, BLOCKSIZE); - if (len < 0) - error(gzerror(in, &err)); - /* - * Always expect complete blocks to process - * the tar information. - */ - if (len != BLOCKSIZE) - { - action = TGZ_INVALID; /* force error exit */ - remaining = 0; /* force I/O cleanup */ - } - - /* - * If we have to get a tar header - */ - if (getheader >= 1) - { - /* - * if we met the end of the tar - * or the end-of-tar block, - * we are done - */ - if (len == 0 || buffer.header.name[0] == 0) - break; - - tarmode = getoct(buffer.header.mode,8); - tartime = (time_t)getoct(buffer.header.mtime,12); - if (tarmode == -1 || tartime == (time_t)-1) - { - buffer.header.name[0] = 0; - action = TGZ_INVALID; - } - - if (getheader == 1) - { - strncpy(fname,buffer.header.name,SHORTNAMESIZE); - if (fname[SHORTNAMESIZE-1] != 0) - fname[SHORTNAMESIZE] = 0; - } - else - { - /* - * The file name is longer than SHORTNAMESIZE - */ - if (strncmp(fname,buffer.header.name,SHORTNAMESIZE-1) != 0) - error("bad long name"); - getheader = 1; - } - - /* - * Act according to the type flag - */ - switch (buffer.header.typeflag) - { - case DIRTYPE: - if (action == TGZ_LIST) - printf(" %s %s\n",strtime(&tartime),fname); - if (action == TGZ_EXTRACT) - { - makedir(fname); - push_attr(&attributes,fname,tarmode,tartime); - } - break; - case REGTYPE: - case AREGTYPE: - remaining = getoct(buffer.header.size,12); - if (remaining == -1) - { - action = TGZ_INVALID; - break; - } - if (action == TGZ_LIST) - printf(" %s %9d %s\n",strtime(&tartime),remaining,fname); - else if (action == TGZ_EXTRACT) - { - if (matchname(arg,argc,argv,fname)) - { - outfile = fopen(fname,"wb"); - if (outfile == NULL) { - /* try creating directory */ - char *p = strrchr(fname, '/'); - if (p != NULL) { - *p = '\0'; - makedir(fname); - *p = '/'; - outfile = fopen(fname,"wb"); - } - } - if (outfile != NULL) - printf("Extracting %s\n",fname); - else - fprintf(stderr, "%s: Couldn't create %s",prog,fname); - } - else - outfile = NULL; - } - getheader = 0; - break; - case GNUTYPE_LONGLINK: - case GNUTYPE_LONGNAME: - remaining = getoct(buffer.header.size,12); - if (remaining < 0 || remaining >= BLOCKSIZE) - { - action = TGZ_INVALID; - break; - } - len = gzread(in, fname, BLOCKSIZE); - if (len < 0) - error(gzerror(in, &err)); - if (fname[BLOCKSIZE-1] != 0 || (int)strlen(fname) > remaining) - { - action = TGZ_INVALID; - break; - } - getheader = 2; - break; - default: - if (action == TGZ_LIST) - printf(" %s <---> %s\n",strtime(&tartime),fname); - break; - } - } - else - { - unsigned int bytes = (remaining > BLOCKSIZE) ? BLOCKSIZE : remaining; - - if (outfile != NULL) - { - if (fwrite(&buffer,sizeof(char),bytes,outfile) != bytes) - { - fprintf(stderr, - "%s: Error writing %s -- skipping\n",prog,fname); - fclose(outfile); - outfile = NULL; - remove(fname); - } - } - remaining -= bytes; - } - - if (remaining == 0) - { - getheader = 1; - if (outfile != NULL) - { - fclose(outfile); - outfile = NULL; - if (action != TGZ_INVALID) - push_attr(&attributes,fname,tarmode,tartime); - } - } - - /* - * Abandon if errors are found - */ - if (action == TGZ_INVALID) - { - error("broken archive"); - break; - } - } - - /* - * Restore file modes and time stamps - */ - restore_attr(&attributes); - - if (gzclose(in) != Z_OK) - error("failed gzclose"); - - return 0; -} - - -/* ============================================================ */ - -void help(int exitval) -{ - printf("untgz version 0.2.1\n" - " using zlib version %s\n\n", - zlibVersion()); - printf("Usage: untgz file.tgz extract all files\n" - " untgz file.tgz fname ... extract selected files\n" - " untgz -l file.tgz list archive contents\n" - " untgz -h display this help\n"); - exit(exitval); -} - -void error(const char *msg) -{ - fprintf(stderr, "%s: %s\n", prog, msg); - exit(1); -} - - -/* ============================================================ */ - -#if defined(WIN32) && defined(__GNUC__) -int _CRT_glob = 0; /* disable argument globbing in MinGW */ -#endif - -int main(int argc,char **argv) -{ - int action = TGZ_EXTRACT; - int arg = 1; - char *TGZfile; - gzFile *f; - - prog = strrchr(argv[0],'\\'); - if (prog == NULL) - { - prog = strrchr(argv[0],'/'); - if (prog == NULL) - { - prog = strrchr(argv[0],':'); - if (prog == NULL) - prog = argv[0]; - else - prog++; - } - else - prog++; - } - else - prog++; - - if (argc == 1) - help(0); - - if (strcmp(argv[arg],"-l") == 0) - { - action = TGZ_LIST; - if (argc == ++arg) - help(0); - } - else if (strcmp(argv[arg],"-h") == 0) - { - help(0); - } - - if ((TGZfile = TGZfname(argv[arg])) == NULL) - TGZnotfound(argv[arg]); - - ++arg; - if ((action == TGZ_LIST) && (arg != argc)) - help(1); - -/* - * Process the TGZ file - */ - switch(action) - { - case TGZ_LIST: - case TGZ_EXTRACT: - f = gzopen(TGZfile,"rb"); - if (f == NULL) - { - fprintf(stderr,"%s: Couldn't gzopen %s\n",prog,TGZfile); - return 1; - } - exit(tar(f, action, arg, argc, argv)); - break; - - default: - error("Unknown option"); - exit(1); - } - - return 0; -} diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/readme.txt b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/readme.txt deleted file mode 100644 index 04b8baac8ce..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/readme.txt +++ /dev/null @@ -1,65 +0,0 @@ -Building instructions for the DLL versions of Zlib 1.2.8 -======================================================== - -This directory contains projects that build zlib and minizip using -Microsoft Visual C++ 9.0/10.0. - -You don't need to build these projects yourself. You can download the -binaries from: - http://www.winimage.com/zLibDll - -More information can be found at this site. - - - - - -Build instructions for Visual Studio 2008 (32 bits or 64 bits) --------------------------------------------------------------- -- Uncompress current zlib, including all contrib/* files -- Compile assembly code (with Visual Studio Command Prompt) by running: - bld_ml64.bat (in contrib\masmx64) - bld_ml32.bat (in contrib\masmx86) -- Open contrib\vstudio\vc9\zlibvc.sln with Microsoft Visual C++ 2008 -- Or run: vcbuild /rebuild contrib\vstudio\vc9\zlibvc.sln "Release|Win32" - -Build instructions for Visual Studio 2010 (32 bits or 64 bits) --------------------------------------------------------------- -- Uncompress current zlib, including all contrib/* files -- Open contrib\vstudio\vc10\zlibvc.sln with Microsoft Visual C++ 2010 - -Build instructions for Visual Studio 2012 (32 bits or 64 bits) --------------------------------------------------------------- -- Uncompress current zlib, including all contrib/* files -- Open contrib\vstudio\vc11\zlibvc.sln with Microsoft Visual C++ 2012 - - -Important ---------- -- To use zlibwapi.dll in your application, you must define the - macro ZLIB_WINAPI when compiling your application's source files. - - -Additional notes ----------------- -- This DLL, named zlibwapi.dll, is compatible to the old zlib.dll built - by Gilles Vollant from the zlib 1.1.x sources, and distributed at - http://www.winimage.com/zLibDll - It uses the WINAPI calling convention for the exported functions, and - includes the minizip functionality. If your application needs that - particular build of zlib.dll, you can rename zlibwapi.dll to zlib.dll. - -- The new DLL was renamed because there exist several incompatible - versions of zlib.dll on the Internet. - -- There is also an official DLL build of zlib, named zlib1.dll. This one - is exporting the functions using the CDECL convention. See the file - win32\DLL_FAQ.txt found in this zlib distribution. - -- There used to be a ZLIB_DLL macro in zlib 1.1.x, but now this symbol - has a slightly different effect. To avoid compatibility problems, do - not define it here. - - -Gilles Vollant -info@winimage.com diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/miniunz.vcxproj b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/miniunz.vcxproj deleted file mode 100644 index 1b3624215a2..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/miniunz.vcxproj +++ /dev/null @@ -1,310 +0,0 @@ - - - - - Debug - Itanium - - - Debug - Win32 - - - Debug - x64 - - - Release - Itanium - - - Release - Win32 - - - Release - x64 - - - - {C52F9E7B-498A-42BE-8DB4-85A15694382A} - Win32Proj - - - - Application - MultiByte - - - Application - MultiByte - - - Application - MultiByte - - - Application - MultiByte - - - Application - MultiByte - - - Application - MultiByte - - - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30128.1 - x86\MiniUnzip$(Configuration)\ - x86\MiniUnzip$(Configuration)\Tmp\ - true - false - x86\MiniUnzip$(Configuration)\ - x86\MiniUnzip$(Configuration)\Tmp\ - false - false - x64\MiniUnzip$(Configuration)\ - x64\MiniUnzip$(Configuration)\Tmp\ - true - false - ia64\MiniUnzip$(Configuration)\ - ia64\MiniUnzip$(Configuration)\Tmp\ - true - false - x64\MiniUnzip$(Configuration)\ - x64\MiniUnzip$(Configuration)\Tmp\ - false - false - ia64\MiniUnzip$(Configuration)\ - ia64\MiniUnzip$(Configuration)\Tmp\ - false - false - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - - - - Disabled - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - Default - MultiThreadedDebug - false - - - $(IntDir) - Level3 - EditAndContinue - - - x86\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)miniunz.exe - true - $(OutDir)miniunz.pdb - Console - false - - - MachineX86 - - - - - MaxSpeed - OnlyExplicitInline - true - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - Default - MultiThreaded - false - true - - - $(IntDir) - Level3 - ProgramDatabase - - - x86\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)miniunz.exe - true - Console - true - true - false - - - MachineX86 - - - - - X64 - - - Disabled - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) - true - Default - MultiThreadedDebugDLL - false - - - $(IntDir) - Level3 - ProgramDatabase - - - x64\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)miniunz.exe - true - $(OutDir)miniunz.pdb - Console - MachineX64 - - - - - Itanium - - - Disabled - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) - true - Default - MultiThreadedDebugDLL - false - - - $(IntDir) - Level3 - ProgramDatabase - - - ia64\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)miniunz.exe - true - $(OutDir)miniunz.pdb - Console - MachineIA64 - - - - - X64 - - - MaxSpeed - OnlyExplicitInline - true - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) - true - Default - MultiThreadedDLL - false - true - - - $(IntDir) - Level3 - ProgramDatabase - - - x64\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)miniunz.exe - true - Console - true - true - MachineX64 - - - - - Itanium - - - MaxSpeed - OnlyExplicitInline - true - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) - true - Default - MultiThreadedDLL - false - true - - - $(IntDir) - Level3 - ProgramDatabase - - - ia64\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)miniunz.exe - true - Console - true - true - MachineIA64 - - - - - - - - {8fd826f8-3739-44e6-8cc8-997122e53b8d} - - - - - - \ No newline at end of file diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/miniunz.vcxproj.filters b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/miniunz.vcxproj.filters deleted file mode 100644 index 0bd12210cac..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/miniunz.vcxproj.filters +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {048af943-022b-4db6-beeb-a54c34774ee2} - cpp;c;cxx;def;odl;idl;hpj;bat;asm - - - {c1d600d2-888f-4aea-b73e-8b0dd9befa0c} - h;hpp;hxx;hm;inl;inc - - - {0844199a-966b-4f19-81db-1e0125e141b9} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe - - - - - Source Files - - - \ No newline at end of file diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/minizip.vcxproj b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/minizip.vcxproj deleted file mode 100644 index ccd3651df6e..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/minizip.vcxproj +++ /dev/null @@ -1,307 +0,0 @@ - - - - - Debug - Itanium - - - Debug - Win32 - - - Debug - x64 - - - Release - Itanium - - - Release - Win32 - - - Release - x64 - - - - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B} - Win32Proj - - - - Application - MultiByte - - - Application - MultiByte - - - Application - MultiByte - - - Application - MultiByte - - - Application - MultiByte - - - Application - MultiByte - - - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30128.1 - x86\MiniZip$(Configuration)\ - x86\MiniZip$(Configuration)\Tmp\ - true - false - x86\MiniZip$(Configuration)\ - x86\MiniZip$(Configuration)\Tmp\ - false - x64\$(Configuration)\ - x64\$(Configuration)\ - true - false - ia64\$(Configuration)\ - ia64\$(Configuration)\ - true - false - x64\$(Configuration)\ - x64\$(Configuration)\ - false - ia64\$(Configuration)\ - ia64\$(Configuration)\ - false - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - - - - Disabled - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - Default - MultiThreadedDebug - false - - - $(IntDir) - Level3 - EditAndContinue - - - x86\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)minizip.exe - true - $(OutDir)minizip.pdb - Console - false - - - MachineX86 - - - - - MaxSpeed - OnlyExplicitInline - true - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - Default - MultiThreaded - false - true - - - $(IntDir) - Level3 - ProgramDatabase - - - x86\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)minizip.exe - true - Console - true - true - false - - - MachineX86 - - - - - X64 - - - Disabled - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) - true - Default - MultiThreadedDebugDLL - false - - - $(IntDir) - Level3 - ProgramDatabase - - - x64\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)minizip.exe - true - $(OutDir)minizip.pdb - Console - MachineX64 - - - - - Itanium - - - Disabled - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) - true - Default - MultiThreadedDebugDLL - false - - - $(IntDir) - Level3 - ProgramDatabase - - - ia64\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)minizip.exe - true - $(OutDir)minizip.pdb - Console - MachineIA64 - - - - - X64 - - - MaxSpeed - OnlyExplicitInline - true - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) - true - Default - MultiThreadedDLL - false - true - - - $(IntDir) - Level3 - ProgramDatabase - - - x64\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)minizip.exe - true - Console - true - true - MachineX64 - - - - - Itanium - - - MaxSpeed - OnlyExplicitInline - true - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) - true - Default - MultiThreadedDLL - false - true - - - $(IntDir) - Level3 - ProgramDatabase - - - ia64\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)minizip.exe - true - Console - true - true - MachineIA64 - - - - - - - - {8fd826f8-3739-44e6-8cc8-997122e53b8d} - - - - - - \ No newline at end of file diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/minizip.vcxproj.filters b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/minizip.vcxproj.filters deleted file mode 100644 index 7076d76ff63..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/minizip.vcxproj.filters +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {c0419b40-bf50-40da-b153-ff74215b79de} - cpp;c;cxx;def;odl;idl;hpj;bat;asm - - - {bb87b070-735b-478e-92ce-7383abb2f36c} - h;hpp;hxx;hm;inl;inc - - - {f46ab6a6-548f-43cb-ae96-681abb5bd5db} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe - - - - - Source Files - - - \ No newline at end of file diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/testzlib.vcxproj b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/testzlib.vcxproj deleted file mode 100644 index 476b8ea453e..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/testzlib.vcxproj +++ /dev/null @@ -1,420 +0,0 @@ - - - - - Debug - Itanium - - - Debug - Win32 - - - Debug - x64 - - - ReleaseWithoutAsm - Itanium - - - ReleaseWithoutAsm - Win32 - - - ReleaseWithoutAsm - x64 - - - Release - Itanium - - - Release - Win32 - - - Release - x64 - - - - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B} - testzlib - Win32Proj - - - - Application - MultiByte - true - - - Application - MultiByte - true - - - Application - MultiByte - - - Application - MultiByte - true - - - Application - MultiByte - true - - - Application - MultiByte - - - Application - true - - - Application - true - - - Application - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30128.1 - x86\TestZlib$(Configuration)\ - x86\TestZlib$(Configuration)\Tmp\ - true - false - x86\TestZlib$(Configuration)\ - x86\TestZlib$(Configuration)\Tmp\ - false - false - x86\TestZlib$(Configuration)\ - x86\TestZlib$(Configuration)\Tmp\ - false - false - x64\TestZlib$(Configuration)\ - x64\TestZlib$(Configuration)\Tmp\ - false - ia64\TestZlib$(Configuration)\ - ia64\TestZlib$(Configuration)\Tmp\ - true - false - x64\TestZlib$(Configuration)\ - x64\TestZlib$(Configuration)\Tmp\ - false - ia64\TestZlib$(Configuration)\ - ia64\TestZlib$(Configuration)\Tmp\ - false - false - x64\TestZlib$(Configuration)\ - x64\TestZlib$(Configuration)\Tmp\ - false - ia64\TestZlib$(Configuration)\ - ia64\TestZlib$(Configuration)\Tmp\ - false - false - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - - - - Disabled - ..\..\..;%(AdditionalIncludeDirectories) - ASMV;ASMINF;WIN32;ZLIB_WINAPI;_DEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) - true - Default - MultiThreadedDebug - false - - - AssemblyAndSourceCode - $(IntDir) - Level3 - EditAndContinue - - - ..\..\masmx86\match686.obj;..\..\masmx86\inffas32.obj;%(AdditionalDependencies) - $(OutDir)testzlib.exe - true - $(OutDir)testzlib.pdb - Console - false - - - MachineX86 - - - - - MaxSpeed - OnlyExplicitInline - true - ..\..\..;%(AdditionalIncludeDirectories) - WIN32;ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) - true - Default - MultiThreaded - false - true - - - $(IntDir) - Level3 - ProgramDatabase - - - $(OutDir)testzlib.exe - true - Console - true - true - false - - - MachineX86 - - - - - MaxSpeed - OnlyExplicitInline - true - ..\..\..;%(AdditionalIncludeDirectories) - ASMV;ASMINF;WIN32;ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) - true - Default - MultiThreaded - false - true - - - $(IntDir) - Level3 - ProgramDatabase - - - ..\..\masmx86\match686.obj;..\..\masmx86\inffas32.obj;%(AdditionalDependencies) - $(OutDir)testzlib.exe - true - Console - true - true - false - - - MachineX86 - - - - - ..\..\..;%(AdditionalIncludeDirectories) - ASMV;ASMINF;WIN32;ZLIB_WINAPI;_DEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) - Default - MultiThreadedDebugDLL - false - $(IntDir) - - - ..\..\masmx64\gvmat64.obj;..\..\masmx64\inffasx64.obj;%(AdditionalDependencies) - - - - - Itanium - - - Disabled - ..\..\..;%(AdditionalIncludeDirectories) - ZLIB_WINAPI;_DEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions) - true - Default - MultiThreadedDebugDLL - false - - - AssemblyAndSourceCode - $(IntDir) - Level3 - ProgramDatabase - - - $(OutDir)testzlib.exe - true - $(OutDir)testzlib.pdb - Console - MachineIA64 - - - - - ..\..\..;%(AdditionalIncludeDirectories) - WIN32;ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) - Default - MultiThreadedDLL - false - $(IntDir) - - - %(AdditionalDependencies) - - - - - Itanium - - - MaxSpeed - OnlyExplicitInline - true - ..\..\..;%(AdditionalIncludeDirectories) - ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions) - true - Default - MultiThreadedDLL - false - true - - - $(IntDir) - Level3 - ProgramDatabase - - - $(OutDir)testzlib.exe - true - Console - true - true - MachineIA64 - - - - - ..\..\..;%(AdditionalIncludeDirectories) - ASMV;ASMINF;WIN32;ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) - Default - MultiThreadedDLL - false - $(IntDir) - - - ..\..\masmx64\gvmat64.obj;..\..\masmx64\inffasx64.obj;%(AdditionalDependencies) - - - - - Itanium - - - MaxSpeed - OnlyExplicitInline - true - ..\..\..;%(AdditionalIncludeDirectories) - ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions) - true - Default - MultiThreadedDLL - false - true - - - $(IntDir) - Level3 - ProgramDatabase - - - $(OutDir)testzlib.exe - true - Console - true - true - MachineIA64 - - - - - - - - - - true - true - true - true - true - true - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/testzlib.vcxproj.filters b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/testzlib.vcxproj.filters deleted file mode 100644 index 32764910392..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/testzlib.vcxproj.filters +++ /dev/null @@ -1,58 +0,0 @@ - - - - - {c1f6a2e3-5da5-4955-8653-310d3efe05a9} - cpp;c;cxx;def;odl;idl;hpj;bat;asm - - - {c2aaffdc-2c95-4d6f-8466-4bec5890af2c} - h;hpp;hxx;hm;inl;inc - - - {c274fe07-05f2-461c-964b-f6341e4e7eb5} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - \ No newline at end of file diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/testzlibdll.vcxproj b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/testzlibdll.vcxproj deleted file mode 100644 index 8e38876fa38..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/testzlibdll.vcxproj +++ /dev/null @@ -1,310 +0,0 @@ - - - - - Debug - Itanium - - - Debug - Win32 - - - Debug - x64 - - - Release - Itanium - - - Release - Win32 - - - Release - x64 - - - - {C52F9E7B-498A-42BE-8DB4-85A15694366A} - Win32Proj - - - - Application - MultiByte - - - Application - MultiByte - - - Application - MultiByte - - - Application - MultiByte - - - Application - MultiByte - - - Application - MultiByte - - - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30128.1 - x86\TestZlibDll$(Configuration)\ - x86\TestZlibDll$(Configuration)\Tmp\ - true - false - x86\TestZlibDll$(Configuration)\ - x86\TestZlibDll$(Configuration)\Tmp\ - false - false - x64\TestZlibDll$(Configuration)\ - x64\TestZlibDll$(Configuration)\Tmp\ - true - false - ia64\TestZlibDll$(Configuration)\ - ia64\TestZlibDll$(Configuration)\Tmp\ - true - false - x64\TestZlibDll$(Configuration)\ - x64\TestZlibDll$(Configuration)\Tmp\ - false - false - ia64\TestZlibDll$(Configuration)\ - ia64\TestZlibDll$(Configuration)\Tmp\ - false - false - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - - - - Disabled - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - Default - MultiThreadedDebug - false - - - $(IntDir) - Level3 - EditAndContinue - - - x86\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)testzlibdll.exe - true - $(OutDir)testzlib.pdb - Console - false - - - MachineX86 - - - - - MaxSpeed - OnlyExplicitInline - true - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - Default - MultiThreaded - false - true - - - $(IntDir) - Level3 - ProgramDatabase - - - x86\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)testzlibdll.exe - true - Console - true - true - false - - - MachineX86 - - - - - X64 - - - Disabled - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) - true - Default - MultiThreadedDebugDLL - false - - - $(IntDir) - Level3 - ProgramDatabase - - - x64\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)testzlibdll.exe - true - $(OutDir)testzlib.pdb - Console - MachineX64 - - - - - Itanium - - - Disabled - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) - true - Default - MultiThreadedDebugDLL - false - - - $(IntDir) - Level3 - ProgramDatabase - - - ia64\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)testzlibdll.exe - true - $(OutDir)testzlib.pdb - Console - MachineIA64 - - - - - X64 - - - MaxSpeed - OnlyExplicitInline - true - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) - true - Default - MultiThreadedDLL - false - true - - - $(IntDir) - Level3 - ProgramDatabase - - - x64\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)testzlibdll.exe - true - Console - true - true - MachineX64 - - - - - Itanium - - - MaxSpeed - OnlyExplicitInline - true - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) - true - Default - MultiThreadedDLL - false - true - - - $(IntDir) - Level3 - ProgramDatabase - - - ia64\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)testzlibdll.exe - true - Console - true - true - MachineIA64 - - - - - - - - {8fd826f8-3739-44e6-8cc8-997122e53b8d} - - - - - - \ No newline at end of file diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/testzlibdll.vcxproj.filters b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/testzlibdll.vcxproj.filters deleted file mode 100644 index ab87f09f47a..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/testzlibdll.vcxproj.filters +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {fa61a89f-93fc-4c89-b29e-36224b7592f4} - cpp;c;cxx;def;odl;idl;hpj;bat;asm - - - {d4b85da0-2ba2-4934-b57f-e2584e3848ee} - h;hpp;hxx;hm;inl;inc - - - {e573e075-00bd-4a7d-bd67-a8cc9bfc5aca} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe - - - - - Source Files - - - \ No newline at end of file diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/zlib.rc b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/zlib.rc deleted file mode 100644 index d42f191d37d..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/zlib.rc +++ /dev/null @@ -1,32 +0,0 @@ -#include - -#define IDR_VERSION1 1 -IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE - FILEVERSION 1,2,8,0 - PRODUCTVERSION 1,2,8,0 - FILEFLAGSMASK VS_FFI_FILEFLAGSMASK - FILEFLAGS 0 - FILEOS VOS_DOS_WINDOWS32 - FILETYPE VFT_DLL - FILESUBTYPE 0 // not used -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904E4" - //language ID = U.S. English, char set = Windows, Multilingual - - BEGIN - VALUE "FileDescription", "zlib data compression and ZIP file I/O library\0" - VALUE "FileVersion", "1.2.8\0" - VALUE "InternalName", "zlib\0" - VALUE "OriginalFilename", "zlibwapi.dll\0" - VALUE "ProductName", "ZLib.DLL\0" - VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0" - VALUE "LegalCopyright", "(C) 1995-2013 Jean-loup Gailly & Mark Adler\0" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x0409, 1252 - END -END diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/zlibstat.vcxproj b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/zlibstat.vcxproj deleted file mode 100644 index 45389a35215..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/zlibstat.vcxproj +++ /dev/null @@ -1,473 +0,0 @@ - - - - - Debug - Itanium - - - Debug - Win32 - - - Debug - x64 - - - ReleaseWithoutAsm - Itanium - - - ReleaseWithoutAsm - Win32 - - - ReleaseWithoutAsm - x64 - - - Release - Itanium - - - Release - Win32 - - - Release - x64 - - - - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8} - - - - StaticLibrary - false - - - StaticLibrary - false - - - StaticLibrary - false - - - StaticLibrary - false - - - StaticLibrary - false - - - StaticLibrary - false - - - StaticLibrary - false - - - StaticLibrary - false - - - StaticLibrary - false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30128.1 - x86\ZlibStat$(Configuration)\ - x86\ZlibStat$(Configuration)\Tmp\ - x86\ZlibStat$(Configuration)\ - x86\ZlibStat$(Configuration)\Tmp\ - x86\ZlibStat$(Configuration)\ - x86\ZlibStat$(Configuration)\Tmp\ - x64\ZlibStat$(Configuration)\ - x64\ZlibStat$(Configuration)\Tmp\ - ia64\ZlibStat$(Configuration)\ - ia64\ZlibStat$(Configuration)\Tmp\ - x64\ZlibStat$(Configuration)\ - x64\ZlibStat$(Configuration)\Tmp\ - ia64\ZlibStat$(Configuration)\ - ia64\ZlibStat$(Configuration)\Tmp\ - x64\ZlibStat$(Configuration)\ - x64\ZlibStat$(Configuration)\Tmp\ - ia64\ZlibStat$(Configuration)\ - ia64\ZlibStat$(Configuration)\Tmp\ - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - - - - Disabled - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - WIN32;ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) - - - MultiThreadedDebug - false - $(IntDir)zlibstat.pch - $(IntDir) - $(IntDir) - $(OutDir) - Level3 - true - OldStyle - - - 0x040c - - - /MACHINE:X86 /NODEFAULTLIB %(AdditionalOptions) - $(OutDir)zlibstat.lib - true - - - cd ..\..\masmx86 -bld_ml32.bat - - - - - OnlyExplicitInline - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - WIN32;ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ASMV;ASMINF;%(PreprocessorDefinitions) - true - - - MultiThreaded - false - true - $(IntDir)zlibstat.pch - $(IntDir) - $(IntDir) - $(OutDir) - Level3 - true - - - 0x040c - - - /MACHINE:X86 /NODEFAULTLIB %(AdditionalOptions) - ..\..\masmx86\match686.obj;..\..\masmx86\inffas32.obj;%(AdditionalDependencies) - $(OutDir)zlibstat.lib - true - - - cd ..\..\masmx86 -bld_ml32.bat - - - - - OnlyExplicitInline - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - WIN32;ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) - true - - - MultiThreaded - false - true - $(IntDir)zlibstat.pch - $(IntDir) - $(IntDir) - $(OutDir) - Level3 - true - - - 0x040c - - - /MACHINE:X86 /NODEFAULTLIB %(AdditionalOptions) - $(OutDir)zlibstat.lib - true - - - - - X64 - - - Disabled - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions) - - - MultiThreadedDebugDLL - false - $(IntDir)zlibstat.pch - $(IntDir) - $(IntDir) - $(OutDir) - Level3 - true - OldStyle - - - 0x040c - - - /MACHINE:AMD64 /NODEFAULTLIB %(AdditionalOptions) - $(OutDir)zlibstat.lib - true - - - cd ..\..\masmx64 -bld_ml64.bat - - - - - Itanium - - - Disabled - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions) - - - MultiThreadedDebugDLL - false - $(IntDir)zlibstat.pch - $(IntDir) - $(IntDir) - $(OutDir) - Level3 - true - OldStyle - - - 0x040c - - - /MACHINE:IA64 /NODEFAULTLIB %(AdditionalOptions) - $(OutDir)zlibstat.lib - true - - - - - X64 - - - OnlyExplicitInline - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ASMV;ASMINF;WIN64;%(PreprocessorDefinitions) - true - - - MultiThreadedDLL - false - true - $(IntDir)zlibstat.pch - $(IntDir) - $(IntDir) - $(OutDir) - Level3 - true - - - 0x040c - - - /MACHINE:AMD64 /NODEFAULTLIB %(AdditionalOptions) - ..\..\masmx64\gvmat64.obj;..\..\masmx64\inffasx64.obj;%(AdditionalDependencies) - $(OutDir)zlibstat.lib - true - - - cd ..\..\masmx64 -bld_ml64.bat - - - - - Itanium - - - OnlyExplicitInline - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions) - true - - - MultiThreadedDLL - false - true - $(IntDir)zlibstat.pch - $(IntDir) - $(IntDir) - $(OutDir) - Level3 - true - - - 0x040c - - - /MACHINE:IA64 /NODEFAULTLIB %(AdditionalOptions) - $(OutDir)zlibstat.lib - true - - - - - X64 - - - OnlyExplicitInline - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions) - true - - - MultiThreadedDLL - false - true - $(IntDir)zlibstat.pch - $(IntDir) - $(IntDir) - $(OutDir) - Level3 - true - - - 0x040c - - - /MACHINE:AMD64 /NODEFAULTLIB %(AdditionalOptions) - $(OutDir)zlibstat.lib - true - - - - - Itanium - - - OnlyExplicitInline - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions) - true - - - MultiThreadedDLL - false - true - $(IntDir)zlibstat.pch - $(IntDir) - $(IntDir) - $(OutDir) - Level3 - true - - - 0x040c - - - /MACHINE:IA64 /NODEFAULTLIB %(AdditionalOptions) - $(OutDir)zlibstat.lib - true - - - - - - - - - - - - - - true - true - true - true - true - true - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/zlibstat.vcxproj.filters b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/zlibstat.vcxproj.filters deleted file mode 100644 index 0c8b2501cc8..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/zlibstat.vcxproj.filters +++ /dev/null @@ -1,77 +0,0 @@ - - - - - {174213f6-7f66-4ae8-a3a8-a1e0a1e6ffdd} - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - - - Source Files - - - - - Source Files - - - \ No newline at end of file diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/zlibvc.def b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/zlibvc.def deleted file mode 100644 index 980fed3a48f..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/zlibvc.def +++ /dev/null @@ -1,143 +0,0 @@ -LIBRARY -; zlib data compression and ZIP file I/O library - -VERSION 1.2.8 - -EXPORTS - adler32 @1 - compress @2 - crc32 @3 - deflate @4 - deflateCopy @5 - deflateEnd @6 - deflateInit2_ @7 - deflateInit_ @8 - deflateParams @9 - deflateReset @10 - deflateSetDictionary @11 - gzclose @12 - gzdopen @13 - gzerror @14 - gzflush @15 - gzopen @16 - gzread @17 - gzwrite @18 - inflate @19 - inflateEnd @20 - inflateInit2_ @21 - inflateInit_ @22 - inflateReset @23 - inflateSetDictionary @24 - inflateSync @25 - uncompress @26 - zlibVersion @27 - gzprintf @28 - gzputc @29 - gzgetc @30 - gzseek @31 - gzrewind @32 - gztell @33 - gzeof @34 - gzsetparams @35 - zError @36 - inflateSyncPoint @37 - get_crc_table @38 - compress2 @39 - gzputs @40 - gzgets @41 - inflateCopy @42 - inflateBackInit_ @43 - inflateBack @44 - inflateBackEnd @45 - compressBound @46 - deflateBound @47 - gzclearerr @48 - gzungetc @49 - zlibCompileFlags @50 - deflatePrime @51 - deflatePending @52 - - unzOpen @61 - unzClose @62 - unzGetGlobalInfo @63 - unzGetCurrentFileInfo @64 - unzGoToFirstFile @65 - unzGoToNextFile @66 - unzOpenCurrentFile @67 - unzReadCurrentFile @68 - unzOpenCurrentFile3 @69 - unztell @70 - unzeof @71 - unzCloseCurrentFile @72 - unzGetGlobalComment @73 - unzStringFileNameCompare @74 - unzLocateFile @75 - unzGetLocalExtrafield @76 - unzOpen2 @77 - unzOpenCurrentFile2 @78 - unzOpenCurrentFilePassword @79 - - zipOpen @80 - zipOpenNewFileInZip @81 - zipWriteInFileInZip @82 - zipCloseFileInZip @83 - zipClose @84 - zipOpenNewFileInZip2 @86 - zipCloseFileInZipRaw @87 - zipOpen2 @88 - zipOpenNewFileInZip3 @89 - - unzGetFilePos @100 - unzGoToFilePos @101 - - fill_win32_filefunc @110 - -; zlibwapi v1.2.4 added: - fill_win32_filefunc64 @111 - fill_win32_filefunc64A @112 - fill_win32_filefunc64W @113 - - unzOpen64 @120 - unzOpen2_64 @121 - unzGetGlobalInfo64 @122 - unzGetCurrentFileInfo64 @124 - unzGetCurrentFileZStreamPos64 @125 - unztell64 @126 - unzGetFilePos64 @127 - unzGoToFilePos64 @128 - - zipOpen64 @130 - zipOpen2_64 @131 - zipOpenNewFileInZip64 @132 - zipOpenNewFileInZip2_64 @133 - zipOpenNewFileInZip3_64 @134 - zipOpenNewFileInZip4_64 @135 - zipCloseFileInZipRaw64 @136 - -; zlib1 v1.2.4 added: - adler32_combine @140 - crc32_combine @142 - deflateSetHeader @144 - deflateTune @145 - gzbuffer @146 - gzclose_r @147 - gzclose_w @148 - gzdirect @149 - gzoffset @150 - inflateGetHeader @156 - inflateMark @157 - inflatePrime @158 - inflateReset2 @159 - inflateUndermine @160 - -; zlib1 v1.2.6 added: - gzgetc_ @161 - inflateResetKeep @163 - deflateResetKeep @164 - -; zlib1 v1.2.7 added: - gzopen_w @165 - -; zlib1 v1.2.8 added: - inflateGetDictionary @166 - gzvprintf @167 diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/zlibvc.sln b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/zlibvc.sln deleted file mode 100644 index 649f40c7ea0..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/zlibvc.sln +++ /dev/null @@ -1,135 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlibvc", "zlibvc.vcxproj", "{8FD826F8-3739-44E6-8CC8-997122E53B8D}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlibstat", "zlibstat.vcxproj", "{745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testzlib", "testzlib.vcxproj", "{AA6666AA-E09F-4135-9C0C-4FE50C3C654B}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testzlibdll", "testzlibdll.vcxproj", "{C52F9E7B-498A-42BE-8DB4-85A15694366A}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "minizip", "minizip.vcxproj", "{48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "miniunz", "miniunz.vcxproj", "{C52F9E7B-498A-42BE-8DB4-85A15694382A}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Itanium = Debug|Itanium - Debug|Win32 = Debug|Win32 - Debug|x64 = Debug|x64 - Release|Itanium = Release|Itanium - Release|Win32 = Release|Win32 - Release|x64 = Release|x64 - ReleaseWithoutAsm|Itanium = ReleaseWithoutAsm|Itanium - ReleaseWithoutAsm|Win32 = ReleaseWithoutAsm|Win32 - ReleaseWithoutAsm|x64 = ReleaseWithoutAsm|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Itanium.ActiveCfg = Debug|Itanium - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Itanium.Build.0 = Debug|Itanium - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Win32.ActiveCfg = Debug|Win32 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Win32.Build.0 = Debug|Win32 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|x64.ActiveCfg = Debug|x64 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|x64.Build.0 = Debug|x64 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Itanium.ActiveCfg = Release|Itanium - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Itanium.Build.0 = Release|Itanium - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Win32.ActiveCfg = Release|Win32 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Win32.Build.0 = Release|Win32 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|x64.ActiveCfg = Release|x64 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|x64.Build.0 = Release|x64 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Itanium.ActiveCfg = ReleaseWithoutAsm|Itanium - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Itanium.Build.0 = ReleaseWithoutAsm|Itanium - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Win32.ActiveCfg = ReleaseWithoutAsm|Win32 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Win32.Build.0 = ReleaseWithoutAsm|Win32 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|x64.ActiveCfg = ReleaseWithoutAsm|x64 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|x64.Build.0 = ReleaseWithoutAsm|x64 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Itanium.ActiveCfg = Debug|Itanium - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Itanium.Build.0 = Debug|Itanium - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Win32.ActiveCfg = Debug|Win32 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Win32.Build.0 = Debug|Win32 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|x64.ActiveCfg = Debug|x64 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|x64.Build.0 = Debug|x64 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Itanium.ActiveCfg = Release|Itanium - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Itanium.Build.0 = Release|Itanium - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Win32.ActiveCfg = Release|Win32 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Win32.Build.0 = Release|Win32 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|x64.ActiveCfg = Release|x64 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|x64.Build.0 = Release|x64 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Itanium.ActiveCfg = ReleaseWithoutAsm|Itanium - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Itanium.Build.0 = ReleaseWithoutAsm|Itanium - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Win32.ActiveCfg = ReleaseWithoutAsm|Win32 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Win32.Build.0 = ReleaseWithoutAsm|Win32 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|x64.ActiveCfg = ReleaseWithoutAsm|x64 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|x64.Build.0 = ReleaseWithoutAsm|x64 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.ActiveCfg = Debug|Itanium - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.Build.0 = Debug|Itanium - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.ActiveCfg = Debug|Win32 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.Build.0 = Debug|Win32 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.ActiveCfg = Debug|x64 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.Build.0 = Debug|x64 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.ActiveCfg = Release|Itanium - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.Build.0 = Release|Itanium - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.ActiveCfg = Release|Win32 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.Build.0 = Release|Win32 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.ActiveCfg = Release|x64 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.Build.0 = Release|x64 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.ActiveCfg = ReleaseWithoutAsm|Itanium - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.Build.0 = ReleaseWithoutAsm|Itanium - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Win32.ActiveCfg = ReleaseWithoutAsm|Win32 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Win32.Build.0 = ReleaseWithoutAsm|Win32 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|x64.ActiveCfg = ReleaseWithoutAsm|x64 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|x64.Build.0 = ReleaseWithoutAsm|x64 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Itanium.ActiveCfg = Debug|Itanium - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Itanium.Build.0 = Debug|Itanium - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Win32.ActiveCfg = Debug|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Win32.Build.0 = Debug|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|x64.ActiveCfg = Debug|x64 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|x64.Build.0 = Debug|x64 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Itanium.ActiveCfg = Release|Itanium - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Itanium.Build.0 = Release|Itanium - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Win32.ActiveCfg = Release|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Win32.Build.0 = Release|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|x64.ActiveCfg = Release|x64 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|x64.Build.0 = Release|x64 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|Itanium.ActiveCfg = Release|Itanium - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|Itanium.Build.0 = Release|Itanium - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|Win32.ActiveCfg = Release|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|x64.ActiveCfg = Release|x64 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.ActiveCfg = Debug|Itanium - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.Build.0 = Debug|Itanium - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.ActiveCfg = Debug|Win32 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.Build.0 = Debug|Win32 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.ActiveCfg = Debug|x64 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.Build.0 = Debug|x64 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.ActiveCfg = Release|Itanium - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.Build.0 = Release|Itanium - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.ActiveCfg = Release|Win32 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.Build.0 = Release|Win32 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.ActiveCfg = Release|x64 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.Build.0 = Release|x64 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.ActiveCfg = Release|Itanium - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.Build.0 = Release|Itanium - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Win32.ActiveCfg = Release|Win32 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|x64.ActiveCfg = Release|x64 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Itanium.ActiveCfg = Debug|Itanium - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Itanium.Build.0 = Debug|Itanium - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Win32.ActiveCfg = Debug|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Win32.Build.0 = Debug|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|x64.ActiveCfg = Debug|x64 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|x64.Build.0 = Debug|x64 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Itanium.ActiveCfg = Release|Itanium - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Itanium.Build.0 = Release|Itanium - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Win32.ActiveCfg = Release|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Win32.Build.0 = Release|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|x64.ActiveCfg = Release|x64 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|x64.Build.0 = Release|x64 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|Itanium.ActiveCfg = Release|Itanium - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|Itanium.Build.0 = Release|Itanium - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|Win32.ActiveCfg = Release|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|x64.ActiveCfg = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/zlibvc.vcxproj b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/zlibvc.vcxproj deleted file mode 100644 index 7d7c49a6dd9..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/zlibvc.vcxproj +++ /dev/null @@ -1,657 +0,0 @@ - - - - - Debug - Itanium - - - Debug - Win32 - - - Debug - x64 - - - ReleaseWithoutAsm - Itanium - - - ReleaseWithoutAsm - Win32 - - - ReleaseWithoutAsm - x64 - - - Release - Itanium - - - Release - Win32 - - - Release - x64 - - - - {8FD826F8-3739-44E6-8CC8-997122E53B8D} - - - - DynamicLibrary - false - true - - - DynamicLibrary - false - true - - - DynamicLibrary - false - - - DynamicLibrary - false - true - - - DynamicLibrary - false - true - - - DynamicLibrary - false - - - DynamicLibrary - false - true - - - DynamicLibrary - false - true - - - DynamicLibrary - false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30128.1 - x86\ZlibDll$(Configuration)\ - x86\ZlibDll$(Configuration)\Tmp\ - true - false - x86\ZlibDll$(Configuration)\ - x86\ZlibDll$(Configuration)\Tmp\ - false - false - x86\ZlibDll$(Configuration)\ - x86\ZlibDll$(Configuration)\Tmp\ - false - false - x64\ZlibDll$(Configuration)\ - x64\ZlibDll$(Configuration)\Tmp\ - true - false - ia64\ZlibDll$(Configuration)\ - ia64\ZlibDll$(Configuration)\Tmp\ - true - false - x64\ZlibDll$(Configuration)\ - x64\ZlibDll$(Configuration)\Tmp\ - false - false - ia64\ZlibDll$(Configuration)\ - ia64\ZlibDll$(Configuration)\Tmp\ - false - false - x64\ZlibDll$(Configuration)\ - x64\ZlibDll$(Configuration)\Tmp\ - false - false - ia64\ZlibDll$(Configuration)\ - ia64\ZlibDll$(Configuration)\Tmp\ - false - false - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - zlibwapid - zlibwapi - zlibwapi - zlibwapid - zlibwapi - zlibwapi - - - - _DEBUG;%(PreprocessorDefinitions) - true - true - Win32 - $(OutDir)zlibvc.tlb - - - Disabled - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;ASMV;ASMINF;%(PreprocessorDefinitions) - - - MultiThreadedDebug - false - $(IntDir)zlibvc.pch - $(IntDir) - $(IntDir) - $(OutDir) - - - Level3 - true - EditAndContinue - - - _DEBUG;%(PreprocessorDefinitions) - 0x040c - - - /MACHINE:I386 %(AdditionalOptions) - ..\..\masmx86\match686.obj;..\..\masmx86\inffas32.obj;%(AdditionalDependencies) - true - .\zlibvc.def - true - true - Windows - false - - - - - cd ..\..\masmx86 -bld_ml32.bat - - - - - NDEBUG;%(PreprocessorDefinitions) - true - true - Win32 - $(OutDir)zlibvc.tlb - - - OnlyExplicitInline - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;%(PreprocessorDefinitions) - true - - - MultiThreadedDLL - false - true - $(IntDir)zlibvc.pch - All - $(IntDir) - $(IntDir) - $(OutDir) - - - Level3 - true - - - NDEBUG;%(PreprocessorDefinitions) - 0x040c - - - /MACHINE:I386 %(AdditionalOptions) - true - false - .\zlibvc.def - true - Windows - false - - - - - - - NDEBUG;%(PreprocessorDefinitions) - true - true - Win32 - $(OutDir)zlibvc.tlb - - - OnlyExplicitInline - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;ASMV;ASMINF;%(PreprocessorDefinitions) - true - - - MultiThreaded - false - true - $(IntDir)zlibvc.pch - All - $(IntDir) - $(IntDir) - $(OutDir) - - - Level3 - true - - - NDEBUG;%(PreprocessorDefinitions) - 0x040c - - - /MACHINE:I386 %(AdditionalOptions) - ..\..\masmx86\match686.obj;..\..\masmx86\inffas32.obj;%(AdditionalDependencies) - true - false - .\zlibvc.def - true - Windows - false - - - - - cd ..\..\masmx86 -bld_ml32.bat - - - - - _DEBUG;%(PreprocessorDefinitions) - true - true - X64 - $(OutDir)zlibvc.tlb - - - Disabled - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;ASMV;ASMINF;WIN64;%(PreprocessorDefinitions) - - - MultiThreadedDebugDLL - false - $(IntDir)zlibvc.pch - $(IntDir) - $(IntDir) - $(OutDir) - - - Level3 - true - ProgramDatabase - - - _DEBUG;%(PreprocessorDefinitions) - 0x040c - - - ..\..\masmx64\gvmat64.obj;..\..\masmx64\inffasx64.obj;%(AdditionalDependencies) - true - .\zlibvc.def - true - true - Windows - MachineX64 - - - cd ..\..\masmx64 -bld_ml64.bat - - - - - _DEBUG;%(PreprocessorDefinitions) - true - true - Itanium - $(OutDir)zlibvc.tlb - - - Disabled - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;WIN64;%(PreprocessorDefinitions) - - - MultiThreadedDebugDLL - false - $(IntDir)zlibvc.pch - $(IntDir) - $(IntDir) - $(OutDir) - - - Level3 - true - ProgramDatabase - - - _DEBUG;%(PreprocessorDefinitions) - 0x040c - - - $(OutDir)zlibwapi.dll - true - .\zlibvc.def - true - $(OutDir)zlibwapi.pdb - true - $(OutDir)zlibwapi.map - Windows - $(OutDir)zlibwapi.lib - MachineIA64 - - - - - NDEBUG;%(PreprocessorDefinitions) - true - true - X64 - $(OutDir)zlibvc.tlb - - - OnlyExplicitInline - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;WIN64;%(PreprocessorDefinitions) - true - - - MultiThreadedDLL - false - true - $(IntDir)zlibvc.pch - All - $(IntDir) - $(IntDir) - $(OutDir) - - - Level3 - true - - - NDEBUG;%(PreprocessorDefinitions) - 0x040c - - - true - false - .\zlibvc.def - true - Windows - MachineX64 - - - - - NDEBUG;%(PreprocessorDefinitions) - true - true - Itanium - $(OutDir)zlibvc.tlb - - - OnlyExplicitInline - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;WIN64;%(PreprocessorDefinitions) - true - - - MultiThreadedDLL - false - true - $(IntDir)zlibvc.pch - All - $(IntDir) - $(IntDir) - $(OutDir) - - - Level3 - true - - - NDEBUG;%(PreprocessorDefinitions) - 0x040c - - - $(OutDir)zlibwapi.dll - true - false - .\zlibvc.def - $(OutDir)zlibwapi.pdb - true - $(OutDir)zlibwapi.map - Windows - $(OutDir)zlibwapi.lib - MachineIA64 - - - - - NDEBUG;%(PreprocessorDefinitions) - true - true - X64 - $(OutDir)zlibvc.tlb - - - OnlyExplicitInline - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;ASMV;ASMINF;WIN64;%(PreprocessorDefinitions) - true - - - MultiThreadedDLL - false - true - $(IntDir)zlibvc.pch - All - $(IntDir) - $(IntDir) - $(OutDir) - - - Level3 - true - - - NDEBUG;%(PreprocessorDefinitions) - 0x040c - - - ..\..\masmx64\gvmat64.obj;..\..\masmx64\inffasx64.obj;%(AdditionalDependencies) - true - false - .\zlibvc.def - true - Windows - MachineX64 - - - cd ..\..\masmx64 -bld_ml64.bat - - - - - NDEBUG;%(PreprocessorDefinitions) - true - true - Itanium - $(OutDir)zlibvc.tlb - - - OnlyExplicitInline - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;WIN64;%(PreprocessorDefinitions) - true - - - MultiThreadedDLL - false - true - $(IntDir)zlibvc.pch - All - $(IntDir) - $(IntDir) - $(OutDir) - - - Level3 - true - - - NDEBUG;%(PreprocessorDefinitions) - 0x040c - - - $(OutDir)zlibwapi.dll - true - false - .\zlibvc.def - $(OutDir)zlibwapi.pdb - true - $(OutDir)zlibwapi.map - Windows - $(OutDir)zlibwapi.lib - MachineIA64 - - - - - - - - - - - - - - true - true - true - true - true - true - - - - - - - - - - %(AdditionalIncludeDirectories) - ZLIB_INTERNAL;%(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - ZLIB_INTERNAL;%(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - ZLIB_INTERNAL;%(PreprocessorDefinitions) - - - %(AdditionalIncludeDirectories) - ZLIB_INTERNAL;%(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - ZLIB_INTERNAL;%(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - ZLIB_INTERNAL;%(PreprocessorDefinitions) - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/zlibvc.vcxproj.filters b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/zlibvc.vcxproj.filters deleted file mode 100644 index 22786824fca..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc10/zlibvc.vcxproj.filters +++ /dev/null @@ -1,118 +0,0 @@ - - - - - {07934a85-8b61-443d-a0ee-b2eedb74f3cd} - cpp;c;cxx;rc;def;r;odl;hpj;bat;for;f90 - - - {1d99675b-433d-4a21-9e50-ed4ab8b19762} - h;hpp;hxx;hm;inl;fi;fd - - - {431c0958-fa71-44d0-9084-2d19d100c0cc} - ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - - - Source Files - - - - - Source Files - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - \ No newline at end of file diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc11/miniunz.vcxproj b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc11/miniunz.vcxproj deleted file mode 100644 index 99be63d69c2..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc11/miniunz.vcxproj +++ /dev/null @@ -1,314 +0,0 @@ - - - - - Debug - Itanium - - - Debug - Win32 - - - Debug - x64 - - - Release - Itanium - - - Release - Win32 - - - Release - x64 - - - - {C52F9E7B-498A-42BE-8DB4-85A15694382A} - Win32Proj - - - - Application - MultiByte - v110 - - - Application - Unicode - v110 - - - Application - MultiByte - - - Application - MultiByte - - - Application - MultiByte - v110 - - - Application - MultiByte - v110 - - - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30128.1 - x86\MiniUnzip$(Configuration)\ - x86\MiniUnzip$(Configuration)\Tmp\ - true - false - x86\MiniUnzip$(Configuration)\ - x86\MiniUnzip$(Configuration)\Tmp\ - false - false - x64\MiniUnzip$(Configuration)\ - x64\MiniUnzip$(Configuration)\Tmp\ - true - false - ia64\MiniUnzip$(Configuration)\ - ia64\MiniUnzip$(Configuration)\Tmp\ - true - false - x64\MiniUnzip$(Configuration)\ - x64\MiniUnzip$(Configuration)\Tmp\ - false - false - ia64\MiniUnzip$(Configuration)\ - ia64\MiniUnzip$(Configuration)\Tmp\ - false - false - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - - - - Disabled - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - Default - MultiThreadedDebugDLL - false - - - $(IntDir) - Level3 - ProgramDatabase - - - x86\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)miniunz.exe - true - $(OutDir)miniunz.pdb - Console - false - - - MachineX86 - - - - - MaxSpeed - OnlyExplicitInline - true - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - Default - MultiThreaded - false - true - - - $(IntDir) - Level3 - ProgramDatabase - - - x86\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)miniunz.exe - true - Console - true - true - false - - - MachineX86 - - - - - X64 - - - Disabled - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) - true - Default - MultiThreadedDebugDLL - false - - - $(IntDir) - Level3 - ProgramDatabase - - - x64\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)miniunz.exe - true - $(OutDir)miniunz.pdb - Console - MachineX64 - - - - - Itanium - - - Disabled - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) - true - Default - MultiThreadedDebugDLL - false - - - $(IntDir) - Level3 - ProgramDatabase - - - ia64\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)miniunz.exe - true - $(OutDir)miniunz.pdb - Console - MachineIA64 - - - - - X64 - - - MaxSpeed - OnlyExplicitInline - true - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) - true - Default - MultiThreadedDLL - false - true - - - $(IntDir) - Level3 - ProgramDatabase - - - x64\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)miniunz.exe - true - Console - true - true - MachineX64 - - - - - Itanium - - - MaxSpeed - OnlyExplicitInline - true - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) - true - Default - MultiThreadedDLL - false - true - - - $(IntDir) - Level3 - ProgramDatabase - - - ia64\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)miniunz.exe - true - Console - true - true - MachineIA64 - - - - - - - - {8fd826f8-3739-44e6-8cc8-997122e53b8d} - - - - - - \ No newline at end of file diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc11/minizip.vcxproj b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc11/minizip.vcxproj deleted file mode 100644 index d6e98f4d57f..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc11/minizip.vcxproj +++ /dev/null @@ -1,311 +0,0 @@ - - - - - Debug - Itanium - - - Debug - Win32 - - - Debug - x64 - - - Release - Itanium - - - Release - Win32 - - - Release - x64 - - - - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B} - Win32Proj - - - - Application - MultiByte - v110 - - - Application - Unicode - v110 - - - Application - MultiByte - - - Application - MultiByte - - - Application - MultiByte - v110 - - - Application - MultiByte - v110 - - - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30128.1 - x86\MiniZip$(Configuration)\ - x86\MiniZip$(Configuration)\Tmp\ - true - false - x86\MiniZip$(Configuration)\ - x86\MiniZip$(Configuration)\Tmp\ - false - x64\$(Configuration)\ - x64\$(Configuration)\ - true - false - ia64\$(Configuration)\ - ia64\$(Configuration)\ - true - false - x64\$(Configuration)\ - x64\$(Configuration)\ - false - ia64\$(Configuration)\ - ia64\$(Configuration)\ - false - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - - - - Disabled - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - Default - MultiThreadedDebugDLL - false - - - $(IntDir) - Level3 - ProgramDatabase - - - x86\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)minizip.exe - true - $(OutDir)minizip.pdb - Console - false - - - MachineX86 - - - - - MaxSpeed - OnlyExplicitInline - true - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - Default - MultiThreaded - false - true - - - $(IntDir) - Level3 - ProgramDatabase - - - x86\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)minizip.exe - true - Console - true - true - false - - - MachineX86 - - - - - X64 - - - Disabled - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) - true - Default - MultiThreadedDebugDLL - false - - - $(IntDir) - Level3 - ProgramDatabase - - - x64\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)minizip.exe - true - $(OutDir)minizip.pdb - Console - MachineX64 - - - - - Itanium - - - Disabled - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) - true - Default - MultiThreadedDebugDLL - false - - - $(IntDir) - Level3 - ProgramDatabase - - - ia64\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)minizip.exe - true - $(OutDir)minizip.pdb - Console - MachineIA64 - - - - - X64 - - - MaxSpeed - OnlyExplicitInline - true - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) - true - Default - MultiThreadedDLL - false - true - - - $(IntDir) - Level3 - ProgramDatabase - - - x64\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)minizip.exe - true - Console - true - true - MachineX64 - - - - - Itanium - - - MaxSpeed - OnlyExplicitInline - true - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) - true - Default - MultiThreadedDLL - false - true - - - $(IntDir) - Level3 - ProgramDatabase - - - ia64\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)minizip.exe - true - Console - true - true - MachineIA64 - - - - - - - - {8fd826f8-3739-44e6-8cc8-997122e53b8d} - - - - - - \ No newline at end of file diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc11/testzlib.vcxproj b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc11/testzlib.vcxproj deleted file mode 100644 index 0115dd17b96..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc11/testzlib.vcxproj +++ /dev/null @@ -1,426 +0,0 @@ - - - - - Debug - Itanium - - - Debug - Win32 - - - Debug - x64 - - - ReleaseWithoutAsm - Itanium - - - ReleaseWithoutAsm - Win32 - - - ReleaseWithoutAsm - x64 - - - Release - Itanium - - - Release - Win32 - - - Release - x64 - - - - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B} - testzlib - Win32Proj - - - - Application - MultiByte - true - v110 - - - Application - MultiByte - true - v110 - - - Application - Unicode - v110 - - - Application - MultiByte - true - - - Application - MultiByte - true - - - Application - MultiByte - - - Application - true - v110 - - - Application - true - v110 - - - Application - v110 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30128.1 - x86\TestZlib$(Configuration)\ - x86\TestZlib$(Configuration)\Tmp\ - true - false - x86\TestZlib$(Configuration)\ - x86\TestZlib$(Configuration)\Tmp\ - false - false - x86\TestZlib$(Configuration)\ - x86\TestZlib$(Configuration)\Tmp\ - false - false - x64\TestZlib$(Configuration)\ - x64\TestZlib$(Configuration)\Tmp\ - false - ia64\TestZlib$(Configuration)\ - ia64\TestZlib$(Configuration)\Tmp\ - true - false - x64\TestZlib$(Configuration)\ - x64\TestZlib$(Configuration)\Tmp\ - false - ia64\TestZlib$(Configuration)\ - ia64\TestZlib$(Configuration)\Tmp\ - false - false - x64\TestZlib$(Configuration)\ - x64\TestZlib$(Configuration)\Tmp\ - false - ia64\TestZlib$(Configuration)\ - ia64\TestZlib$(Configuration)\Tmp\ - false - false - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - - - - Disabled - ..\..\..;%(AdditionalIncludeDirectories) - ASMV;ASMINF;WIN32;ZLIB_WINAPI;_DEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) - true - Default - MultiThreadedDebugDLL - false - - - AssemblyAndSourceCode - $(IntDir) - Level3 - ProgramDatabase - - - ..\..\masmx86\match686.obj;..\..\masmx86\inffas32.obj;%(AdditionalDependencies) - $(OutDir)testzlib.exe - true - $(OutDir)testzlib.pdb - Console - false - - - MachineX86 - - - - - MaxSpeed - OnlyExplicitInline - true - ..\..\..;%(AdditionalIncludeDirectories) - WIN32;ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) - true - Default - MultiThreaded - false - true - - - $(IntDir) - Level3 - ProgramDatabase - - - $(OutDir)testzlib.exe - true - Console - true - true - false - - - MachineX86 - - - - - MaxSpeed - OnlyExplicitInline - true - ..\..\..;%(AdditionalIncludeDirectories) - ASMV;ASMINF;WIN32;ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) - true - Default - MultiThreaded - false - true - - - $(IntDir) - Level3 - ProgramDatabase - - - ..\..\masmx86\match686.obj;..\..\masmx86\inffas32.obj;%(AdditionalDependencies) - $(OutDir)testzlib.exe - true - Console - true - true - false - - - MachineX86 - - - - - ..\..\..;%(AdditionalIncludeDirectories) - ASMV;ASMINF;WIN32;ZLIB_WINAPI;_DEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) - Default - MultiThreadedDebugDLL - false - $(IntDir) - - - ..\..\masmx64\gvmat64.obj;..\..\masmx64\inffasx64.obj;%(AdditionalDependencies) - - - - - Itanium - - - Disabled - ..\..\..;%(AdditionalIncludeDirectories) - ZLIB_WINAPI;_DEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions) - true - Default - MultiThreadedDebugDLL - false - - - AssemblyAndSourceCode - $(IntDir) - Level3 - ProgramDatabase - - - $(OutDir)testzlib.exe - true - $(OutDir)testzlib.pdb - Console - MachineIA64 - - - - - ..\..\..;%(AdditionalIncludeDirectories) - WIN32;ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) - Default - MultiThreadedDLL - false - $(IntDir) - - - %(AdditionalDependencies) - - - - - Itanium - - - MaxSpeed - OnlyExplicitInline - true - ..\..\..;%(AdditionalIncludeDirectories) - ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions) - true - Default - MultiThreadedDLL - false - true - - - $(IntDir) - Level3 - ProgramDatabase - - - $(OutDir)testzlib.exe - true - Console - true - true - MachineIA64 - - - - - ..\..\..;%(AdditionalIncludeDirectories) - ASMV;ASMINF;WIN32;ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) - Default - MultiThreadedDLL - false - $(IntDir) - - - ..\..\masmx64\gvmat64.obj;..\..\masmx64\inffasx64.obj;%(AdditionalDependencies) - - - - - Itanium - - - MaxSpeed - OnlyExplicitInline - true - ..\..\..;%(AdditionalIncludeDirectories) - ZLIB_WINAPI;NDEBUG;_CONSOLE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions) - true - Default - MultiThreadedDLL - false - true - - - $(IntDir) - Level3 - ProgramDatabase - - - $(OutDir)testzlib.exe - true - Console - true - true - MachineIA64 - - - - - - - - - - true - true - true - true - true - true - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc11/testzlibdll.vcxproj b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc11/testzlibdll.vcxproj deleted file mode 100644 index 9d36336eb8f..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc11/testzlibdll.vcxproj +++ /dev/null @@ -1,314 +0,0 @@ - - - - - Debug - Itanium - - - Debug - Win32 - - - Debug - x64 - - - Release - Itanium - - - Release - Win32 - - - Release - x64 - - - - {C52F9E7B-498A-42BE-8DB4-85A15694366A} - Win32Proj - - - - Application - MultiByte - v110 - - - Application - Unicode - v110 - - - Application - MultiByte - - - Application - MultiByte - - - Application - MultiByte - v110 - - - Application - MultiByte - v110 - - - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30128.1 - x86\TestZlibDll$(Configuration)\ - x86\TestZlibDll$(Configuration)\Tmp\ - true - false - x86\TestZlibDll$(Configuration)\ - x86\TestZlibDll$(Configuration)\Tmp\ - false - false - x64\TestZlibDll$(Configuration)\ - x64\TestZlibDll$(Configuration)\Tmp\ - true - false - ia64\TestZlibDll$(Configuration)\ - ia64\TestZlibDll$(Configuration)\Tmp\ - true - false - x64\TestZlibDll$(Configuration)\ - x64\TestZlibDll$(Configuration)\Tmp\ - false - false - ia64\TestZlibDll$(Configuration)\ - ia64\TestZlibDll$(Configuration)\Tmp\ - false - false - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - - - - Disabled - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - Default - MultiThreadedDebugDLL - false - - - $(IntDir) - Level3 - ProgramDatabase - - - x86\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)testzlibdll.exe - true - $(OutDir)testzlib.pdb - Console - false - - - MachineX86 - - - - - MaxSpeed - OnlyExplicitInline - true - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - Default - MultiThreaded - false - true - - - $(IntDir) - Level3 - ProgramDatabase - - - x86\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)testzlibdll.exe - true - Console - true - true - false - - - MachineX86 - - - - - X64 - - - Disabled - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) - true - Default - MultiThreadedDebugDLL - false - - - $(IntDir) - Level3 - ProgramDatabase - - - x64\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)testzlibdll.exe - true - $(OutDir)testzlib.pdb - Console - MachineX64 - - - - - Itanium - - - Disabled - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) - true - Default - MultiThreadedDebugDLL - false - - - $(IntDir) - Level3 - ProgramDatabase - - - ia64\ZlibDllDebug\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)testzlibdll.exe - true - $(OutDir)testzlib.pdb - Console - MachineIA64 - - - - - X64 - - - MaxSpeed - OnlyExplicitInline - true - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) - true - Default - MultiThreadedDLL - false - true - - - $(IntDir) - Level3 - ProgramDatabase - - - x64\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)testzlibdll.exe - true - Console - true - true - MachineX64 - - - - - Itanium - - - MaxSpeed - OnlyExplicitInline - true - ..\..\..;..\..\minizip;%(AdditionalIncludeDirectories) - _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;ZLIB_WINAPI;NDEBUG;_CONSOLE;WIN64;%(PreprocessorDefinitions) - true - Default - MultiThreadedDLL - false - true - - - $(IntDir) - Level3 - ProgramDatabase - - - ia64\ZlibDllRelease\zlibwapi.lib;%(AdditionalDependencies) - $(OutDir)testzlibdll.exe - true - Console - true - true - MachineIA64 - - - - - - - - {8fd826f8-3739-44e6-8cc8-997122e53b8d} - - - - - - \ No newline at end of file diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc11/zlib.rc b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc11/zlib.rc deleted file mode 100644 index d42f191d37d..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc11/zlib.rc +++ /dev/null @@ -1,32 +0,0 @@ -#include - -#define IDR_VERSION1 1 -IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE - FILEVERSION 1,2,8,0 - PRODUCTVERSION 1,2,8,0 - FILEFLAGSMASK VS_FFI_FILEFLAGSMASK - FILEFLAGS 0 - FILEOS VOS_DOS_WINDOWS32 - FILETYPE VFT_DLL - FILESUBTYPE 0 // not used -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904E4" - //language ID = U.S. English, char set = Windows, Multilingual - - BEGIN - VALUE "FileDescription", "zlib data compression and ZIP file I/O library\0" - VALUE "FileVersion", "1.2.8\0" - VALUE "InternalName", "zlib\0" - VALUE "OriginalFilename", "zlibwapi.dll\0" - VALUE "ProductName", "ZLib.DLL\0" - VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0" - VALUE "LegalCopyright", "(C) 1995-2013 Jean-loup Gailly & Mark Adler\0" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x0409, 1252 - END -END diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc11/zlibstat.vcxproj b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc11/zlibstat.vcxproj deleted file mode 100644 index 64b4d869dce..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc11/zlibstat.vcxproj +++ /dev/null @@ -1,464 +0,0 @@ - - - - - Debug - Itanium - - - Debug - Win32 - - - Debug - x64 - - - ReleaseWithoutAsm - Itanium - - - ReleaseWithoutAsm - Win32 - - - ReleaseWithoutAsm - x64 - - - Release - Itanium - - - Release - Win32 - - - Release - x64 - - - - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8} - - - - StaticLibrary - false - v110 - - - StaticLibrary - false - v110 - - - StaticLibrary - false - v110 - Unicode - - - StaticLibrary - false - - - StaticLibrary - false - - - StaticLibrary - false - - - StaticLibrary - false - v110 - - - StaticLibrary - false - v110 - - - StaticLibrary - false - v110 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30128.1 - x86\ZlibStat$(Configuration)\ - x86\ZlibStat$(Configuration)\Tmp\ - x86\ZlibStat$(Configuration)\ - x86\ZlibStat$(Configuration)\Tmp\ - x86\ZlibStat$(Configuration)\ - x86\ZlibStat$(Configuration)\Tmp\ - x64\ZlibStat$(Configuration)\ - x64\ZlibStat$(Configuration)\Tmp\ - ia64\ZlibStat$(Configuration)\ - ia64\ZlibStat$(Configuration)\Tmp\ - x64\ZlibStat$(Configuration)\ - x64\ZlibStat$(Configuration)\Tmp\ - ia64\ZlibStat$(Configuration)\ - ia64\ZlibStat$(Configuration)\Tmp\ - x64\ZlibStat$(Configuration)\ - x64\ZlibStat$(Configuration)\Tmp\ - ia64\ZlibStat$(Configuration)\ - ia64\ZlibStat$(Configuration)\Tmp\ - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - - - - Disabled - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - WIN32;ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) - - - MultiThreadedDebugDLL - false - $(IntDir)zlibstat.pch - $(IntDir) - $(IntDir) - $(OutDir) - Level3 - true - OldStyle - - - 0x040c - - - /MACHINE:X86 /NODEFAULTLIB %(AdditionalOptions) - $(OutDir)zlibstat.lib - true - - - - - OnlyExplicitInline - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - WIN32;ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ASMV;ASMINF;%(PreprocessorDefinitions) - true - - - MultiThreaded - false - true - $(IntDir)zlibstat.pch - $(IntDir) - $(IntDir) - $(OutDir) - Level3 - true - - - 0x040c - - - /MACHINE:X86 /NODEFAULTLIB %(AdditionalOptions) - ..\..\masmx86\match686.obj;..\..\masmx86\inffas32.obj;%(AdditionalDependencies) - $(OutDir)zlibstat.lib - true - - - - - OnlyExplicitInline - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - WIN32;ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;%(PreprocessorDefinitions) - true - - - MultiThreaded - false - true - $(IntDir)zlibstat.pch - $(IntDir) - $(IntDir) - $(OutDir) - Level3 - true - - - 0x040c - - - /MACHINE:X86 /NODEFAULTLIB %(AdditionalOptions) - $(OutDir)zlibstat.lib - true - - - - - X64 - - - Disabled - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions) - - - MultiThreadedDebugDLL - false - $(IntDir)zlibstat.pch - $(IntDir) - $(IntDir) - $(OutDir) - Level3 - true - OldStyle - - - 0x040c - - - /MACHINE:AMD64 /NODEFAULTLIB %(AdditionalOptions) - $(OutDir)zlibstat.lib - true - - - - - Itanium - - - Disabled - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions) - - - MultiThreadedDebugDLL - false - $(IntDir)zlibstat.pch - $(IntDir) - $(IntDir) - $(OutDir) - Level3 - true - OldStyle - - - 0x040c - - - /MACHINE:IA64 /NODEFAULTLIB %(AdditionalOptions) - $(OutDir)zlibstat.lib - true - - - - - X64 - - - OnlyExplicitInline - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ASMV;ASMINF;WIN64;%(PreprocessorDefinitions) - true - - - MultiThreadedDLL - false - true - $(IntDir)zlibstat.pch - $(IntDir) - $(IntDir) - $(OutDir) - Level3 - true - - - 0x040c - - - /MACHINE:AMD64 /NODEFAULTLIB %(AdditionalOptions) - ..\..\masmx64\gvmat64.obj;..\..\masmx64\inffasx64.obj;%(AdditionalDependencies) - $(OutDir)zlibstat.lib - true - - - - - Itanium - - - OnlyExplicitInline - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions) - true - - - MultiThreadedDLL - false - true - $(IntDir)zlibstat.pch - $(IntDir) - $(IntDir) - $(OutDir) - Level3 - true - - - 0x040c - - - /MACHINE:IA64 /NODEFAULTLIB %(AdditionalOptions) - $(OutDir)zlibstat.lib - true - - - - - X64 - - - OnlyExplicitInline - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions) - true - - - MultiThreadedDLL - false - true - $(IntDir)zlibstat.pch - $(IntDir) - $(IntDir) - $(OutDir) - Level3 - true - - - 0x040c - - - /MACHINE:AMD64 /NODEFAULTLIB %(AdditionalOptions) - $(OutDir)zlibstat.lib - true - - - - - Itanium - - - OnlyExplicitInline - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - ZLIB_WINAPI;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;WIN64;%(PreprocessorDefinitions) - true - - - MultiThreadedDLL - false - true - $(IntDir)zlibstat.pch - $(IntDir) - $(IntDir) - $(OutDir) - Level3 - true - - - 0x040c - - - /MACHINE:IA64 /NODEFAULTLIB %(AdditionalOptions) - $(OutDir)zlibstat.lib - true - - - - - - - - - - - - - - true - true - true - true - true - true - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc11/zlibvc.def b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc11/zlibvc.def deleted file mode 100644 index 980fed3a48f..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc11/zlibvc.def +++ /dev/null @@ -1,143 +0,0 @@ -LIBRARY -; zlib data compression and ZIP file I/O library - -VERSION 1.2.8 - -EXPORTS - adler32 @1 - compress @2 - crc32 @3 - deflate @4 - deflateCopy @5 - deflateEnd @6 - deflateInit2_ @7 - deflateInit_ @8 - deflateParams @9 - deflateReset @10 - deflateSetDictionary @11 - gzclose @12 - gzdopen @13 - gzerror @14 - gzflush @15 - gzopen @16 - gzread @17 - gzwrite @18 - inflate @19 - inflateEnd @20 - inflateInit2_ @21 - inflateInit_ @22 - inflateReset @23 - inflateSetDictionary @24 - inflateSync @25 - uncompress @26 - zlibVersion @27 - gzprintf @28 - gzputc @29 - gzgetc @30 - gzseek @31 - gzrewind @32 - gztell @33 - gzeof @34 - gzsetparams @35 - zError @36 - inflateSyncPoint @37 - get_crc_table @38 - compress2 @39 - gzputs @40 - gzgets @41 - inflateCopy @42 - inflateBackInit_ @43 - inflateBack @44 - inflateBackEnd @45 - compressBound @46 - deflateBound @47 - gzclearerr @48 - gzungetc @49 - zlibCompileFlags @50 - deflatePrime @51 - deflatePending @52 - - unzOpen @61 - unzClose @62 - unzGetGlobalInfo @63 - unzGetCurrentFileInfo @64 - unzGoToFirstFile @65 - unzGoToNextFile @66 - unzOpenCurrentFile @67 - unzReadCurrentFile @68 - unzOpenCurrentFile3 @69 - unztell @70 - unzeof @71 - unzCloseCurrentFile @72 - unzGetGlobalComment @73 - unzStringFileNameCompare @74 - unzLocateFile @75 - unzGetLocalExtrafield @76 - unzOpen2 @77 - unzOpenCurrentFile2 @78 - unzOpenCurrentFilePassword @79 - - zipOpen @80 - zipOpenNewFileInZip @81 - zipWriteInFileInZip @82 - zipCloseFileInZip @83 - zipClose @84 - zipOpenNewFileInZip2 @86 - zipCloseFileInZipRaw @87 - zipOpen2 @88 - zipOpenNewFileInZip3 @89 - - unzGetFilePos @100 - unzGoToFilePos @101 - - fill_win32_filefunc @110 - -; zlibwapi v1.2.4 added: - fill_win32_filefunc64 @111 - fill_win32_filefunc64A @112 - fill_win32_filefunc64W @113 - - unzOpen64 @120 - unzOpen2_64 @121 - unzGetGlobalInfo64 @122 - unzGetCurrentFileInfo64 @124 - unzGetCurrentFileZStreamPos64 @125 - unztell64 @126 - unzGetFilePos64 @127 - unzGoToFilePos64 @128 - - zipOpen64 @130 - zipOpen2_64 @131 - zipOpenNewFileInZip64 @132 - zipOpenNewFileInZip2_64 @133 - zipOpenNewFileInZip3_64 @134 - zipOpenNewFileInZip4_64 @135 - zipCloseFileInZipRaw64 @136 - -; zlib1 v1.2.4 added: - adler32_combine @140 - crc32_combine @142 - deflateSetHeader @144 - deflateTune @145 - gzbuffer @146 - gzclose_r @147 - gzclose_w @148 - gzdirect @149 - gzoffset @150 - inflateGetHeader @156 - inflateMark @157 - inflatePrime @158 - inflateReset2 @159 - inflateUndermine @160 - -; zlib1 v1.2.6 added: - gzgetc_ @161 - inflateResetKeep @163 - deflateResetKeep @164 - -; zlib1 v1.2.7 added: - gzopen_w @165 - -; zlib1 v1.2.8 added: - inflateGetDictionary @166 - gzvprintf @167 diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc11/zlibvc.sln b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc11/zlibvc.sln deleted file mode 100644 index b7e3812661e..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc11/zlibvc.sln +++ /dev/null @@ -1,117 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlibvc", "zlibvc.vcxproj", "{8FD826F8-3739-44E6-8CC8-997122E53B8D}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlibstat", "zlibstat.vcxproj", "{745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testzlib", "testzlib.vcxproj", "{AA6666AA-E09F-4135-9C0C-4FE50C3C654B}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testzlibdll", "testzlibdll.vcxproj", "{C52F9E7B-498A-42BE-8DB4-85A15694366A}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "minizip", "minizip.vcxproj", "{48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "miniunz", "miniunz.vcxproj", "{C52F9E7B-498A-42BE-8DB4-85A15694382A}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Itanium = Debug|Itanium - Debug|Win32 = Debug|Win32 - Debug|x64 = Debug|x64 - Release|Itanium = Release|Itanium - Release|Win32 = Release|Win32 - Release|x64 = Release|x64 - ReleaseWithoutAsm|Itanium = ReleaseWithoutAsm|Itanium - ReleaseWithoutAsm|Win32 = ReleaseWithoutAsm|Win32 - ReleaseWithoutAsm|x64 = ReleaseWithoutAsm|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Itanium.ActiveCfg = Debug|Win32 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Win32.ActiveCfg = Debug|Win32 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Win32.Build.0 = Debug|Win32 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|x64.ActiveCfg = Debug|x64 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|x64.Build.0 = Debug|x64 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Itanium.ActiveCfg = Release|Win32 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Win32.ActiveCfg = Release|Win32 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Win32.Build.0 = Release|Win32 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|x64.ActiveCfg = Release|x64 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|x64.Build.0 = Release|x64 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Itanium.ActiveCfg = ReleaseWithoutAsm|Win32 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Win32.ActiveCfg = ReleaseWithoutAsm|Win32 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Win32.Build.0 = ReleaseWithoutAsm|Win32 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|x64.ActiveCfg = ReleaseWithoutAsm|x64 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|x64.Build.0 = ReleaseWithoutAsm|x64 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Itanium.ActiveCfg = Debug|Win32 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Win32.ActiveCfg = Debug|Win32 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Win32.Build.0 = Debug|Win32 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|x64.ActiveCfg = Debug|x64 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|x64.Build.0 = Debug|x64 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Itanium.ActiveCfg = Release|Win32 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Win32.ActiveCfg = Release|Win32 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Win32.Build.0 = Release|Win32 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|x64.ActiveCfg = Release|x64 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|x64.Build.0 = Release|x64 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Itanium.ActiveCfg = ReleaseWithoutAsm|Win32 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Win32.ActiveCfg = ReleaseWithoutAsm|Win32 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Win32.Build.0 = ReleaseWithoutAsm|Win32 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|x64.ActiveCfg = ReleaseWithoutAsm|x64 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|x64.Build.0 = ReleaseWithoutAsm|x64 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.ActiveCfg = Debug|Win32 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.ActiveCfg = Debug|Win32 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.Build.0 = Debug|Win32 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.ActiveCfg = Debug|x64 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.Build.0 = Debug|x64 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.ActiveCfg = Release|Win32 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.ActiveCfg = Release|Win32 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.Build.0 = Release|Win32 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.ActiveCfg = Release|x64 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.Build.0 = Release|x64 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.ActiveCfg = ReleaseWithoutAsm|Win32 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Win32.ActiveCfg = ReleaseWithoutAsm|Win32 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Win32.Build.0 = ReleaseWithoutAsm|Win32 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|x64.ActiveCfg = ReleaseWithoutAsm|x64 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|x64.Build.0 = ReleaseWithoutAsm|x64 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Itanium.ActiveCfg = Debug|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Win32.ActiveCfg = Debug|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Win32.Build.0 = Debug|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|x64.ActiveCfg = Debug|x64 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|x64.Build.0 = Debug|x64 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Itanium.ActiveCfg = Release|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Win32.ActiveCfg = Release|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Win32.Build.0 = Release|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|x64.ActiveCfg = Release|x64 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|x64.Build.0 = Release|x64 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|Itanium.ActiveCfg = Release|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|Win32.ActiveCfg = Release|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|x64.ActiveCfg = Release|x64 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.ActiveCfg = Debug|Win32 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.ActiveCfg = Debug|Win32 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.Build.0 = Debug|Win32 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.ActiveCfg = Debug|x64 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.Build.0 = Debug|x64 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.ActiveCfg = Release|Win32 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.ActiveCfg = Release|Win32 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.Build.0 = Release|Win32 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.ActiveCfg = Release|x64 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.Build.0 = Release|x64 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.ActiveCfg = Release|Win32 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Win32.ActiveCfg = Release|Win32 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|x64.ActiveCfg = Release|x64 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Itanium.ActiveCfg = Debug|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Win32.ActiveCfg = Debug|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Win32.Build.0 = Debug|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|x64.ActiveCfg = Debug|x64 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|x64.Build.0 = Debug|x64 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Itanium.ActiveCfg = Release|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Win32.ActiveCfg = Release|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Win32.Build.0 = Release|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|x64.ActiveCfg = Release|x64 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|x64.Build.0 = Release|x64 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|Itanium.ActiveCfg = Release|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|Win32.ActiveCfg = Release|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|x64.ActiveCfg = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc11/zlibvc.vcxproj b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc11/zlibvc.vcxproj deleted file mode 100644 index c4cffccf1db..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc11/zlibvc.vcxproj +++ /dev/null @@ -1,688 +0,0 @@ - - - - - Debug - Itanium - - - Debug - Win32 - - - Debug - x64 - - - ReleaseWithoutAsm - Itanium - - - ReleaseWithoutAsm - Win32 - - - ReleaseWithoutAsm - x64 - - - Release - Itanium - - - Release - Win32 - - - Release - x64 - - - - {8FD826F8-3739-44E6-8CC8-997122E53B8D} - - - - DynamicLibrary - false - true - v110 - - - DynamicLibrary - false - true - v110 - - - DynamicLibrary - false - v110 - Unicode - - - DynamicLibrary - false - true - - - DynamicLibrary - false - true - - - DynamicLibrary - false - - - DynamicLibrary - false - true - v110 - - - DynamicLibrary - false - true - v110 - - - DynamicLibrary - false - v110 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30128.1 - x86\ZlibDll$(Configuration)\ - x86\ZlibDll$(Configuration)\Tmp\ - true - false - x86\ZlibDll$(Configuration)\ - x86\ZlibDll$(Configuration)\Tmp\ - false - false - x86\ZlibDll$(Configuration)\ - x86\ZlibDll$(Configuration)\Tmp\ - false - false - x64\ZlibDll$(Configuration)\ - x64\ZlibDll$(Configuration)\Tmp\ - true - false - ia64\ZlibDll$(Configuration)\ - ia64\ZlibDll$(Configuration)\Tmp\ - true - false - x64\ZlibDll$(Configuration)\ - x64\ZlibDll$(Configuration)\Tmp\ - false - false - ia64\ZlibDll$(Configuration)\ - ia64\ZlibDll$(Configuration)\Tmp\ - false - false - x64\ZlibDll$(Configuration)\ - x64\ZlibDll$(Configuration)\Tmp\ - false - false - ia64\ZlibDll$(Configuration)\ - ia64\ZlibDll$(Configuration)\Tmp\ - false - false - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - AllRules.ruleset - - - zlibwapi - zlibwapi - zlibwapi - zlibwapi - zlibwapi - zlibwapi - - - - _DEBUG;%(PreprocessorDefinitions) - true - true - Win32 - $(OutDir)zlibvc.tlb - - - Disabled - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;ASMV;ASMINF;%(PreprocessorDefinitions) - - - MultiThreadedDebugDLL - false - $(IntDir)zlibvc.pch - $(IntDir) - $(IntDir) - $(OutDir) - - - Level3 - true - ProgramDatabase - - - _DEBUG;%(PreprocessorDefinitions) - 0x040c - - - /MACHINE:I386 %(AdditionalOptions) - ..\..\masmx86\match686.obj;..\..\masmx86\inffas32.obj;%(AdditionalDependencies) - $(OutDir)zlibwapi.dll - true - .\zlibvc.def - true - $(OutDir)zlibwapi.pdb - true - $(OutDir)zlibwapi.map - Windows - false - - - $(OutDir)zlibwapi.lib - - - cd ..\..\masmx86 -bld_ml32.bat - - - - - NDEBUG;%(PreprocessorDefinitions) - true - true - Win32 - $(OutDir)zlibvc.tlb - - - OnlyExplicitInline - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;%(PreprocessorDefinitions) - true - - - MultiThreadedDLL - false - true - $(IntDir)zlibvc.pch - All - $(IntDir) - $(IntDir) - $(OutDir) - - - Level3 - true - - - NDEBUG;%(PreprocessorDefinitions) - 0x040c - - - /MACHINE:I386 %(AdditionalOptions) - $(OutDir)zlibwapi.dll - true - false - .\zlibvc.def - $(OutDir)zlibwapi.pdb - true - $(OutDir)zlibwapi.map - Windows - false - - - $(OutDir)zlibwapi.lib - - - - - NDEBUG;%(PreprocessorDefinitions) - true - true - Win32 - $(OutDir)zlibvc.tlb - - - OnlyExplicitInline - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;ASMV;ASMINF;%(PreprocessorDefinitions) - true - - - MultiThreaded - false - true - $(IntDir)zlibvc.pch - All - $(IntDir) - $(IntDir) - $(OutDir) - - - Level3 - true - - - NDEBUG;%(PreprocessorDefinitions) - 0x040c - - - /MACHINE:I386 %(AdditionalOptions) - ..\..\masmx86\match686.obj;..\..\masmx86\inffas32.obj;%(AdditionalDependencies) - $(OutDir)zlibwapi.dll - true - false - .\zlibvc.def - $(OutDir)zlibwapi.pdb - true - $(OutDir)zlibwapi.map - Windows - false - - - $(OutDir)zlibwapi.lib - - - cd ..\..\masmx86 -bld_ml32.bat - - - - - _DEBUG;%(PreprocessorDefinitions) - true - true - X64 - $(OutDir)zlibvc.tlb - - - Disabled - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;ASMV;ASMINF;WIN64;%(PreprocessorDefinitions) - - - MultiThreadedDebugDLL - false - $(IntDir)zlibvc.pch - $(IntDir) - $(IntDir) - $(OutDir) - - - Level3 - true - ProgramDatabase - - - _DEBUG;%(PreprocessorDefinitions) - 0x040c - - - ..\..\masmx64\gvmat64.obj;..\..\masmx64\inffasx64.obj;%(AdditionalDependencies) - $(OutDir)zlibwapi.dll - true - .\zlibvc.def - true - $(OutDir)zlibwapi.pdb - true - $(OutDir)zlibwapi.map - Windows - $(OutDir)zlibwapi.lib - MachineX64 - - - cd ..\..\contrib\masmx64 -bld_ml64.bat - - - - - _DEBUG;%(PreprocessorDefinitions) - true - true - Itanium - $(OutDir)zlibvc.tlb - - - Disabled - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;WIN64;%(PreprocessorDefinitions) - - - MultiThreadedDebugDLL - false - $(IntDir)zlibvc.pch - $(IntDir) - $(IntDir) - $(OutDir) - - - Level3 - true - ProgramDatabase - - - _DEBUG;%(PreprocessorDefinitions) - 0x040c - - - $(OutDir)zlibwapi.dll - true - .\zlibvc.def - true - $(OutDir)zlibwapi.pdb - true - $(OutDir)zlibwapi.map - Windows - $(OutDir)zlibwapi.lib - MachineIA64 - - - - - NDEBUG;%(PreprocessorDefinitions) - true - true - X64 - $(OutDir)zlibvc.tlb - - - OnlyExplicitInline - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;WIN64;%(PreprocessorDefinitions) - true - - - MultiThreadedDLL - false - true - $(IntDir)zlibvc.pch - All - $(IntDir) - $(IntDir) - $(OutDir) - - - Level3 - true - - - NDEBUG;%(PreprocessorDefinitions) - 0x040c - - - $(OutDir)zlibwapi.dll - true - false - .\zlibvc.def - $(OutDir)zlibwapi.pdb - true - $(OutDir)zlibwapi.map - Windows - $(OutDir)zlibwapi.lib - MachineX64 - - - - - NDEBUG;%(PreprocessorDefinitions) - true - true - Itanium - $(OutDir)zlibvc.tlb - - - OnlyExplicitInline - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - WIN32;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;WIN64;%(PreprocessorDefinitions) - true - - - MultiThreadedDLL - false - true - $(IntDir)zlibvc.pch - All - $(IntDir) - $(IntDir) - $(OutDir) - - - Level3 - true - - - NDEBUG;%(PreprocessorDefinitions) - 0x040c - - - $(OutDir)zlibwapi.dll - true - false - .\zlibvc.def - $(OutDir)zlibwapi.pdb - true - $(OutDir)zlibwapi.map - Windows - $(OutDir)zlibwapi.lib - MachineIA64 - - - - - NDEBUG;%(PreprocessorDefinitions) - true - true - X64 - $(OutDir)zlibvc.tlb - - - OnlyExplicitInline - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;ASMV;ASMINF;WIN64;%(PreprocessorDefinitions) - true - - - MultiThreadedDLL - false - true - $(IntDir)zlibvc.pch - All - $(IntDir) - $(IntDir) - $(OutDir) - - - Level3 - true - - - NDEBUG;%(PreprocessorDefinitions) - 0x040c - - - ..\..\masmx64\gvmat64.obj;..\..\masmx64\inffasx64.obj;%(AdditionalDependencies) - $(OutDir)zlibwapi.dll - true - false - .\zlibvc.def - $(OutDir)zlibwapi.pdb - true - $(OutDir)zlibwapi.map - Windows - $(OutDir)zlibwapi.lib - MachineX64 - - - cd ..\..\masmx64 -bld_ml64.bat - - - - - NDEBUG;%(PreprocessorDefinitions) - true - true - Itanium - $(OutDir)zlibvc.tlb - - - OnlyExplicitInline - ..\..\..;..\..\masmx86;%(AdditionalIncludeDirectories) - _CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS;ZLIB_WINAPI;WIN64;%(PreprocessorDefinitions) - true - - - MultiThreadedDLL - false - true - $(IntDir)zlibvc.pch - All - $(IntDir) - $(IntDir) - $(OutDir) - - - Level3 - true - - - NDEBUG;%(PreprocessorDefinitions) - 0x040c - - - $(OutDir)zlibwapi.dll - true - false - .\zlibvc.def - $(OutDir)zlibwapi.pdb - true - $(OutDir)zlibwapi.map - Windows - $(OutDir)zlibwapi.lib - MachineIA64 - - - - - - - - - - - - - - true - true - true - true - true - true - - - - - - - - - - %(AdditionalIncludeDirectories) - ZLIB_INTERNAL;%(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - ZLIB_INTERNAL;%(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - ZLIB_INTERNAL;%(PreprocessorDefinitions) - - - %(AdditionalIncludeDirectories) - ZLIB_INTERNAL;%(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - ZLIB_INTERNAL;%(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - ZLIB_INTERNAL;%(PreprocessorDefinitions) - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc9/miniunz.vcproj b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc9/miniunz.vcproj deleted file mode 100644 index 038a9e5faf1..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc9/miniunz.vcproj +++ /dev/null @@ -1,565 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc9/minizip.vcproj b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc9/minizip.vcproj deleted file mode 100644 index ad402399144..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc9/minizip.vcproj +++ /dev/null @@ -1,562 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc9/testzlib.vcproj b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc9/testzlib.vcproj deleted file mode 100644 index c9f19d24ef9..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc9/testzlib.vcproj +++ /dev/null @@ -1,852 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc9/testzlibdll.vcproj b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc9/testzlibdll.vcproj deleted file mode 100644 index d7530fd7dcb..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc9/testzlibdll.vcproj +++ /dev/null @@ -1,565 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc9/zlib.rc b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc9/zlib.rc deleted file mode 100644 index d42f191d37d..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc9/zlib.rc +++ /dev/null @@ -1,32 +0,0 @@ -#include - -#define IDR_VERSION1 1 -IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE - FILEVERSION 1,2,8,0 - PRODUCTVERSION 1,2,8,0 - FILEFLAGSMASK VS_FFI_FILEFLAGSMASK - FILEFLAGS 0 - FILEOS VOS_DOS_WINDOWS32 - FILETYPE VFT_DLL - FILESUBTYPE 0 // not used -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904E4" - //language ID = U.S. English, char set = Windows, Multilingual - - BEGIN - VALUE "FileDescription", "zlib data compression and ZIP file I/O library\0" - VALUE "FileVersion", "1.2.8\0" - VALUE "InternalName", "zlib\0" - VALUE "OriginalFilename", "zlibwapi.dll\0" - VALUE "ProductName", "ZLib.DLL\0" - VALUE "Comments","DLL support by Alessandro Iacopetti & Gilles Vollant\0" - VALUE "LegalCopyright", "(C) 1995-2013 Jean-loup Gailly & Mark Adler\0" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x0409, 1252 - END -END diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc9/zlibstat.vcproj b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc9/zlibstat.vcproj deleted file mode 100644 index d4ffb46b245..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc9/zlibstat.vcproj +++ /dev/null @@ -1,835 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc9/zlibvc.def b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc9/zlibvc.def deleted file mode 100644 index 980fed3a48f..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc9/zlibvc.def +++ /dev/null @@ -1,143 +0,0 @@ -LIBRARY -; zlib data compression and ZIP file I/O library - -VERSION 1.2.8 - -EXPORTS - adler32 @1 - compress @2 - crc32 @3 - deflate @4 - deflateCopy @5 - deflateEnd @6 - deflateInit2_ @7 - deflateInit_ @8 - deflateParams @9 - deflateReset @10 - deflateSetDictionary @11 - gzclose @12 - gzdopen @13 - gzerror @14 - gzflush @15 - gzopen @16 - gzread @17 - gzwrite @18 - inflate @19 - inflateEnd @20 - inflateInit2_ @21 - inflateInit_ @22 - inflateReset @23 - inflateSetDictionary @24 - inflateSync @25 - uncompress @26 - zlibVersion @27 - gzprintf @28 - gzputc @29 - gzgetc @30 - gzseek @31 - gzrewind @32 - gztell @33 - gzeof @34 - gzsetparams @35 - zError @36 - inflateSyncPoint @37 - get_crc_table @38 - compress2 @39 - gzputs @40 - gzgets @41 - inflateCopy @42 - inflateBackInit_ @43 - inflateBack @44 - inflateBackEnd @45 - compressBound @46 - deflateBound @47 - gzclearerr @48 - gzungetc @49 - zlibCompileFlags @50 - deflatePrime @51 - deflatePending @52 - - unzOpen @61 - unzClose @62 - unzGetGlobalInfo @63 - unzGetCurrentFileInfo @64 - unzGoToFirstFile @65 - unzGoToNextFile @66 - unzOpenCurrentFile @67 - unzReadCurrentFile @68 - unzOpenCurrentFile3 @69 - unztell @70 - unzeof @71 - unzCloseCurrentFile @72 - unzGetGlobalComment @73 - unzStringFileNameCompare @74 - unzLocateFile @75 - unzGetLocalExtrafield @76 - unzOpen2 @77 - unzOpenCurrentFile2 @78 - unzOpenCurrentFilePassword @79 - - zipOpen @80 - zipOpenNewFileInZip @81 - zipWriteInFileInZip @82 - zipCloseFileInZip @83 - zipClose @84 - zipOpenNewFileInZip2 @86 - zipCloseFileInZipRaw @87 - zipOpen2 @88 - zipOpenNewFileInZip3 @89 - - unzGetFilePos @100 - unzGoToFilePos @101 - - fill_win32_filefunc @110 - -; zlibwapi v1.2.4 added: - fill_win32_filefunc64 @111 - fill_win32_filefunc64A @112 - fill_win32_filefunc64W @113 - - unzOpen64 @120 - unzOpen2_64 @121 - unzGetGlobalInfo64 @122 - unzGetCurrentFileInfo64 @124 - unzGetCurrentFileZStreamPos64 @125 - unztell64 @126 - unzGetFilePos64 @127 - unzGoToFilePos64 @128 - - zipOpen64 @130 - zipOpen2_64 @131 - zipOpenNewFileInZip64 @132 - zipOpenNewFileInZip2_64 @133 - zipOpenNewFileInZip3_64 @134 - zipOpenNewFileInZip4_64 @135 - zipCloseFileInZipRaw64 @136 - -; zlib1 v1.2.4 added: - adler32_combine @140 - crc32_combine @142 - deflateSetHeader @144 - deflateTune @145 - gzbuffer @146 - gzclose_r @147 - gzclose_w @148 - gzdirect @149 - gzoffset @150 - inflateGetHeader @156 - inflateMark @157 - inflatePrime @158 - inflateReset2 @159 - inflateUndermine @160 - -; zlib1 v1.2.6 added: - gzgetc_ @161 - inflateResetKeep @163 - deflateResetKeep @164 - -; zlib1 v1.2.7 added: - gzopen_w @165 - -; zlib1 v1.2.8 added: - inflateGetDictionary @166 - gzvprintf @167 diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc9/zlibvc.sln b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc9/zlibvc.sln deleted file mode 100644 index 75c64c3f4ad..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc9/zlibvc.sln +++ /dev/null @@ -1,144 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual Studio 2008 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlibvc", "zlibvc.vcproj", "{8FD826F8-3739-44E6-8CC8-997122E53B8D}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlibstat", "zlibstat.vcproj", "{745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testzlib", "testzlib.vcproj", "{AA6666AA-E09F-4135-9C0C-4FE50C3C654B}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestZlibDll", "testzlibdll.vcproj", "{C52F9E7B-498A-42BE-8DB4-85A15694366A}" - ProjectSection(ProjectDependencies) = postProject - {8FD826F8-3739-44E6-8CC8-997122E53B8D} = {8FD826F8-3739-44E6-8CC8-997122E53B8D} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "minizip", "minizip.vcproj", "{48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}" - ProjectSection(ProjectDependencies) = postProject - {8FD826F8-3739-44E6-8CC8-997122E53B8D} = {8FD826F8-3739-44E6-8CC8-997122E53B8D} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "miniunz", "miniunz.vcproj", "{C52F9E7B-498A-42BE-8DB4-85A15694382A}" - ProjectSection(ProjectDependencies) = postProject - {8FD826F8-3739-44E6-8CC8-997122E53B8D} = {8FD826F8-3739-44E6-8CC8-997122E53B8D} - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Itanium = Debug|Itanium - Debug|Win32 = Debug|Win32 - Debug|x64 = Debug|x64 - Release|Itanium = Release|Itanium - Release|Win32 = Release|Win32 - Release|x64 = Release|x64 - ReleaseWithoutAsm|Itanium = ReleaseWithoutAsm|Itanium - ReleaseWithoutAsm|Win32 = ReleaseWithoutAsm|Win32 - ReleaseWithoutAsm|x64 = ReleaseWithoutAsm|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Itanium.ActiveCfg = Debug|Itanium - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Itanium.Build.0 = Debug|Itanium - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Win32.ActiveCfg = Debug|Win32 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|Win32.Build.0 = Debug|Win32 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|x64.ActiveCfg = Debug|x64 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Debug|x64.Build.0 = Debug|x64 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Itanium.ActiveCfg = Release|Itanium - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Itanium.Build.0 = Release|Itanium - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Win32.ActiveCfg = Release|Win32 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|Win32.Build.0 = Release|Win32 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|x64.ActiveCfg = Release|x64 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.Release|x64.Build.0 = Release|x64 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Itanium.ActiveCfg = ReleaseWithoutAsm|Itanium - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Itanium.Build.0 = ReleaseWithoutAsm|Itanium - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Win32.ActiveCfg = ReleaseWithoutAsm|Win32 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|Win32.Build.0 = ReleaseWithoutAsm|Win32 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|x64.ActiveCfg = ReleaseWithoutAsm|x64 - {8FD826F8-3739-44E6-8CC8-997122E53B8D}.ReleaseWithoutAsm|x64.Build.0 = ReleaseWithoutAsm|x64 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Itanium.ActiveCfg = Debug|Itanium - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Itanium.Build.0 = Debug|Itanium - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Win32.ActiveCfg = Debug|Win32 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|Win32.Build.0 = Debug|Win32 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|x64.ActiveCfg = Debug|x64 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Debug|x64.Build.0 = Debug|x64 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Itanium.ActiveCfg = Release|Itanium - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Itanium.Build.0 = Release|Itanium - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Win32.ActiveCfg = Release|Win32 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|Win32.Build.0 = Release|Win32 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|x64.ActiveCfg = Release|x64 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.Release|x64.Build.0 = Release|x64 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Itanium.ActiveCfg = ReleaseWithoutAsm|Itanium - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Itanium.Build.0 = ReleaseWithoutAsm|Itanium - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Win32.ActiveCfg = ReleaseWithoutAsm|Win32 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|Win32.Build.0 = ReleaseWithoutAsm|Win32 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|x64.ActiveCfg = ReleaseWithoutAsm|x64 - {745DEC58-EBB3-47A9-A9B8-4C6627C01BF8}.ReleaseWithoutAsm|x64.Build.0 = ReleaseWithoutAsm|x64 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.ActiveCfg = Debug|Itanium - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.Build.0 = Debug|Itanium - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.ActiveCfg = Debug|Win32 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.Build.0 = Debug|Win32 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.ActiveCfg = Debug|x64 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.Build.0 = Debug|x64 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.ActiveCfg = Release|Itanium - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.Build.0 = Release|Itanium - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.ActiveCfg = Release|Win32 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.Build.0 = Release|Win32 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.ActiveCfg = Release|x64 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.Build.0 = Release|x64 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.ActiveCfg = ReleaseWithoutAsm|Itanium - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.Build.0 = ReleaseWithoutAsm|Itanium - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Win32.ActiveCfg = ReleaseWithoutAsm|Win32 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Win32.Build.0 = ReleaseWithoutAsm|Win32 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|x64.ActiveCfg = ReleaseWithoutAsm|x64 - {AA6666AA-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|x64.Build.0 = ReleaseWithoutAsm|x64 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Itanium.ActiveCfg = Debug|Itanium - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Itanium.Build.0 = Debug|Itanium - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Win32.ActiveCfg = Debug|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|Win32.Build.0 = Debug|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|x64.ActiveCfg = Debug|x64 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Debug|x64.Build.0 = Debug|x64 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Itanium.ActiveCfg = Release|Itanium - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Itanium.Build.0 = Release|Itanium - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Win32.ActiveCfg = Release|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|Win32.Build.0 = Release|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|x64.ActiveCfg = Release|x64 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.Release|x64.Build.0 = Release|x64 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|Itanium.ActiveCfg = Release|Itanium - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|Itanium.Build.0 = Release|Itanium - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|Win32.ActiveCfg = Release|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694366A}.ReleaseWithoutAsm|x64.ActiveCfg = Release|x64 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.ActiveCfg = Debug|Itanium - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Itanium.Build.0 = Debug|Itanium - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.ActiveCfg = Debug|Win32 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|Win32.Build.0 = Debug|Win32 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.ActiveCfg = Debug|x64 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Debug|x64.Build.0 = Debug|x64 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.ActiveCfg = Release|Itanium - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Itanium.Build.0 = Release|Itanium - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.ActiveCfg = Release|Win32 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|Win32.Build.0 = Release|Win32 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.ActiveCfg = Release|x64 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.Release|x64.Build.0 = Release|x64 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.ActiveCfg = Release|Itanium - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Itanium.Build.0 = Release|Itanium - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|Win32.ActiveCfg = Release|Win32 - {48CDD9DC-E09F-4135-9C0C-4FE50C3C654B}.ReleaseWithoutAsm|x64.ActiveCfg = Release|x64 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Itanium.ActiveCfg = Debug|Itanium - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Itanium.Build.0 = Debug|Itanium - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Win32.ActiveCfg = Debug|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|Win32.Build.0 = Debug|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|x64.ActiveCfg = Debug|x64 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Debug|x64.Build.0 = Debug|x64 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Itanium.ActiveCfg = Release|Itanium - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Itanium.Build.0 = Release|Itanium - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Win32.ActiveCfg = Release|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|Win32.Build.0 = Release|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|x64.ActiveCfg = Release|x64 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.Release|x64.Build.0 = Release|x64 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|Itanium.ActiveCfg = Release|Itanium - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|Itanium.Build.0 = Release|Itanium - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|Win32.ActiveCfg = Release|Win32 - {C52F9E7B-498A-42BE-8DB4-85A15694382A}.ReleaseWithoutAsm|x64.ActiveCfg = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc9/zlibvc.vcproj b/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc9/zlibvc.vcproj deleted file mode 100644 index 95bb241f304..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/contrib/vstudio/vc9/zlibvc.vcproj +++ /dev/null @@ -1,1156 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/beast/test/zlib/zlib-1.2.8/crc32.c b/src/beast/test/zlib/zlib-1.2.8/crc32.c deleted file mode 100644 index 979a7190a3c..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/crc32.c +++ /dev/null @@ -1,425 +0,0 @@ -/* crc32.c -- compute the CRC-32 of a data stream - * Copyright (C) 1995-2006, 2010, 2011, 2012 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - * - * Thanks to Rodney Brown for his contribution of faster - * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing - * tables for updating the shift register in one step with three exclusive-ors - * instead of four steps with four exclusive-ors. This results in about a - * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3. - */ - -/* @(#) $Id$ */ - -/* - Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore - protection on the static variables used to control the first-use generation - of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should - first call get_crc_table() to initialize the tables before allowing more than - one thread to use crc32(). - - DYNAMIC_CRC_TABLE and MAKECRCH can be #defined to write out crc32.h. - */ - -#ifdef MAKECRCH -# include -# ifndef DYNAMIC_CRC_TABLE -# define DYNAMIC_CRC_TABLE -# endif /* !DYNAMIC_CRC_TABLE */ -#endif /* MAKECRCH */ - -#include "zutil.h" /* for STDC and FAR definitions */ - -#define local static - -/* Definitions for doing the crc four data bytes at a time. */ -#if !defined(NOBYFOUR) && defined(Z_U4) -# define BYFOUR -#endif -#ifdef BYFOUR - local unsigned long crc32_little OF((unsigned long, - const unsigned char FAR *, unsigned)); - local unsigned long crc32_big OF((unsigned long, - const unsigned char FAR *, unsigned)); -# define TBLS 8 -#else -# define TBLS 1 -#endif /* BYFOUR */ - -/* Local functions for crc concatenation */ -local unsigned long gf2_matrix_times OF((unsigned long *mat, - unsigned long vec)); -local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat)); -local uLong crc32_combine_ OF((uLong crc1, uLong crc2, z_off64_t len2)); - - -#ifdef DYNAMIC_CRC_TABLE - -local volatile int crc_table_empty = 1; -local z_crc_t FAR crc_table[TBLS][256]; -local void make_crc_table OF((void)); -#ifdef MAKECRCH - local void write_table OF((FILE *, const z_crc_t FAR *)); -#endif /* MAKECRCH */ -/* - Generate tables for a byte-wise 32-bit CRC calculation on the polynomial: - x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1. - - Polynomials over GF(2) are represented in binary, one bit per coefficient, - with the lowest powers in the most significant bit. Then adding polynomials - is just exclusive-or, and multiplying a polynomial by x is a right shift by - one. If we call the above polynomial p, and represent a byte as the - polynomial q, also with the lowest power in the most significant bit (so the - byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p, - where a mod b means the remainder after dividing a by b. - - This calculation is done using the shift-register method of multiplying and - taking the remainder. The register is initialized to zero, and for each - incoming bit, x^32 is added mod p to the register if the bit is a one (where - x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by - x (which is shifting right by one and adding x^32 mod p if the bit shifted - out is a one). We start with the highest power (least significant bit) of - q and repeat for all eight bits of q. - - The first table is simply the CRC of all possible eight bit values. This is - all the information needed to generate CRCs on data a byte at a time for all - combinations of CRC register values and incoming bytes. The remaining tables - allow for word-at-a-time CRC calculation for both big-endian and little- - endian machines, where a word is four bytes. -*/ -local void make_crc_table() -{ - z_crc_t c; - int n, k; - z_crc_t poly; /* polynomial exclusive-or pattern */ - /* terms of polynomial defining this crc (except x^32): */ - static volatile int first = 1; /* flag to limit concurrent making */ - static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; - - /* See if another task is already doing this (not thread-safe, but better - than nothing -- significantly reduces duration of vulnerability in - case the advice about DYNAMIC_CRC_TABLE is ignored) */ - if (first) { - first = 0; - - /* make exclusive-or pattern from polynomial (0xedb88320UL) */ - poly = 0; - for (n = 0; n < (int)(sizeof(p)/sizeof(unsigned char)); n++) - poly |= (z_crc_t)1 << (31 - p[n]); - - /* generate a crc for every 8-bit value */ - for (n = 0; n < 256; n++) { - c = (z_crc_t)n; - for (k = 0; k < 8; k++) - c = c & 1 ? poly ^ (c >> 1) : c >> 1; - crc_table[0][n] = c; - } - -#ifdef BYFOUR - /* generate crc for each value followed by one, two, and three zeros, - and then the byte reversal of those as well as the first table */ - for (n = 0; n < 256; n++) { - c = crc_table[0][n]; - crc_table[4][n] = ZSWAP32(c); - for (k = 1; k < 4; k++) { - c = crc_table[0][c & 0xff] ^ (c >> 8); - crc_table[k][n] = c; - crc_table[k + 4][n] = ZSWAP32(c); - } - } -#endif /* BYFOUR */ - - crc_table_empty = 0; - } - else { /* not first */ - /* wait for the other guy to finish (not efficient, but rare) */ - while (crc_table_empty) - ; - } - -#ifdef MAKECRCH - /* write out CRC tables to crc32.h */ - { - FILE *out; - - out = fopen("crc32.h", "w"); - if (out == NULL) return; - fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n"); - fprintf(out, " * Generated automatically by crc32.c\n */\n\n"); - fprintf(out, "local const z_crc_t FAR "); - fprintf(out, "crc_table[TBLS][256] =\n{\n {\n"); - write_table(out, crc_table[0]); -# ifdef BYFOUR - fprintf(out, "#ifdef BYFOUR\n"); - for (k = 1; k < 8; k++) { - fprintf(out, " },\n {\n"); - write_table(out, crc_table[k]); - } - fprintf(out, "#endif\n"); -# endif /* BYFOUR */ - fprintf(out, " }\n};\n"); - fclose(out); - } -#endif /* MAKECRCH */ -} - -#ifdef MAKECRCH -local void write_table(out, table) - FILE *out; - const z_crc_t FAR *table; -{ - int n; - - for (n = 0; n < 256; n++) - fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", - (unsigned long)(table[n]), - n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", ")); -} -#endif /* MAKECRCH */ - -#else /* !DYNAMIC_CRC_TABLE */ -/* ======================================================================== - * Tables of CRC-32s of all single-byte values, made by make_crc_table(). - */ -#include "crc32.h" -#endif /* DYNAMIC_CRC_TABLE */ - -/* ========================================================================= - * This function can be used by asm versions of crc32() - */ -const z_crc_t FAR * ZEXPORT get_crc_table() -{ -#ifdef DYNAMIC_CRC_TABLE - if (crc_table_empty) - make_crc_table(); -#endif /* DYNAMIC_CRC_TABLE */ - return (const z_crc_t FAR *)crc_table; -} - -/* ========================================================================= */ -#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8) -#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1 - -/* ========================================================================= */ -unsigned long ZEXPORT crc32(crc, buf, len) - unsigned long crc; - const unsigned char FAR *buf; - uInt len; -{ - if (buf == Z_NULL) return 0UL; - -#ifdef DYNAMIC_CRC_TABLE - if (crc_table_empty) - make_crc_table(); -#endif /* DYNAMIC_CRC_TABLE */ - -#ifdef BYFOUR - if (sizeof(void *) == sizeof(ptrdiff_t)) { - z_crc_t endian; - - endian = 1; - if (*((unsigned char *)(&endian))) - return crc32_little(crc, buf, len); - else - return crc32_big(crc, buf, len); - } -#endif /* BYFOUR */ - crc = crc ^ 0xffffffffUL; - while (len >= 8) { - DO8; - len -= 8; - } - if (len) do { - DO1; - } while (--len); - return crc ^ 0xffffffffUL; -} - -#ifdef BYFOUR - -/* ========================================================================= */ -#define DOLIT4 c ^= *buf4++; \ - c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \ - crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24] -#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4 - -/* ========================================================================= */ -local unsigned long crc32_little(crc, buf, len) - unsigned long crc; - const unsigned char FAR *buf; - unsigned len; -{ - register z_crc_t c; - register const z_crc_t FAR *buf4; - - c = (z_crc_t)crc; - c = ~c; - while (len && ((ptrdiff_t)buf & 3)) { - c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); - len--; - } - - buf4 = (const z_crc_t FAR *)(const void FAR *)buf; - while (len >= 32) { - DOLIT32; - len -= 32; - } - while (len >= 4) { - DOLIT4; - len -= 4; - } - buf = (const unsigned char FAR *)buf4; - - if (len) do { - c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); - } while (--len); - c = ~c; - return (unsigned long)c; -} - -/* ========================================================================= */ -#define DOBIG4 c ^= *++buf4; \ - c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \ - crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24] -#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4 - -/* ========================================================================= */ -local unsigned long crc32_big(crc, buf, len) - unsigned long crc; - const unsigned char FAR *buf; - unsigned len; -{ - register z_crc_t c; - register const z_crc_t FAR *buf4; - - c = ZSWAP32((z_crc_t)crc); - c = ~c; - while (len && ((ptrdiff_t)buf & 3)) { - c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); - len--; - } - - buf4 = (const z_crc_t FAR *)(const void FAR *)buf; - buf4--; - while (len >= 32) { - DOBIG32; - len -= 32; - } - while (len >= 4) { - DOBIG4; - len -= 4; - } - buf4++; - buf = (const unsigned char FAR *)buf4; - - if (len) do { - c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); - } while (--len); - c = ~c; - return (unsigned long)(ZSWAP32(c)); -} - -#endif /* BYFOUR */ - -#define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */ - -/* ========================================================================= */ -local unsigned long gf2_matrix_times(mat, vec) - unsigned long *mat; - unsigned long vec; -{ - unsigned long sum; - - sum = 0; - while (vec) { - if (vec & 1) - sum ^= *mat; - vec >>= 1; - mat++; - } - return sum; -} - -/* ========================================================================= */ -local void gf2_matrix_square(square, mat) - unsigned long *square; - unsigned long *mat; -{ - int n; - - for (n = 0; n < GF2_DIM; n++) - square[n] = gf2_matrix_times(mat, mat[n]); -} - -/* ========================================================================= */ -local uLong crc32_combine_(crc1, crc2, len2) - uLong crc1; - uLong crc2; - z_off64_t len2; -{ - int n; - unsigned long row; - unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */ - unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */ - - /* degenerate case (also disallow negative lengths) */ - if (len2 <= 0) - return crc1; - - /* put operator for one zero bit in odd */ - odd[0] = 0xedb88320UL; /* CRC-32 polynomial */ - row = 1; - for (n = 1; n < GF2_DIM; n++) { - odd[n] = row; - row <<= 1; - } - - /* put operator for two zero bits in even */ - gf2_matrix_square(even, odd); - - /* put operator for four zero bits in odd */ - gf2_matrix_square(odd, even); - - /* apply len2 zeros to crc1 (first square will put the operator for one - zero byte, eight zero bits, in even) */ - do { - /* apply zeros operator for this bit of len2 */ - gf2_matrix_square(even, odd); - if (len2 & 1) - crc1 = gf2_matrix_times(even, crc1); - len2 >>= 1; - - /* if no more bits set, then done */ - if (len2 == 0) - break; - - /* another iteration of the loop with odd and even swapped */ - gf2_matrix_square(odd, even); - if (len2 & 1) - crc1 = gf2_matrix_times(odd, crc1); - len2 >>= 1; - - /* if no more bits set, then done */ - } while (len2 != 0); - - /* return combined crc */ - crc1 ^= crc2; - return crc1; -} - -/* ========================================================================= */ -uLong ZEXPORT crc32_combine(crc1, crc2, len2) - uLong crc1; - uLong crc2; - z_off_t len2; -{ - return crc32_combine_(crc1, crc2, len2); -} - -uLong ZEXPORT crc32_combine64(crc1, crc2, len2) - uLong crc1; - uLong crc2; - z_off64_t len2; -{ - return crc32_combine_(crc1, crc2, len2); -} diff --git a/src/beast/test/zlib/zlib-1.2.8/crc32.h b/src/beast/test/zlib/zlib-1.2.8/crc32.h deleted file mode 100644 index 9e0c7781025..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/crc32.h +++ /dev/null @@ -1,441 +0,0 @@ -/* crc32.h -- tables for rapid CRC calculation - * Generated automatically by crc32.c - */ - -local const z_crc_t FAR crc_table[TBLS][256] = -{ - { - 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL, - 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL, - 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL, - 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL, - 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL, - 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL, - 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL, - 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL, - 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL, - 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL, - 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL, - 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL, - 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL, - 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL, - 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL, - 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL, - 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL, - 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL, - 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL, - 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL, - 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL, - 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL, - 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL, - 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL, - 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL, - 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL, - 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL, - 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL, - 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL, - 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL, - 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL, - 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL, - 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL, - 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL, - 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL, - 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL, - 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL, - 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL, - 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL, - 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL, - 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL, - 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL, - 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL, - 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL, - 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL, - 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL, - 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL, - 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL, - 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL, - 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL, - 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL, - 0x2d02ef8dUL -#ifdef BYFOUR - }, - { - 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL, - 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL, - 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL, - 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL, - 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL, - 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL, - 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL, - 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL, - 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL, - 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL, - 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL, - 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL, - 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL, - 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL, - 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL, - 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL, - 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL, - 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL, - 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL, - 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL, - 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL, - 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL, - 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL, - 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL, - 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL, - 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL, - 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL, - 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL, - 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL, - 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL, - 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL, - 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL, - 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL, - 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL, - 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL, - 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL, - 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL, - 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL, - 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL, - 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL, - 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL, - 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL, - 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL, - 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL, - 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL, - 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL, - 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL, - 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL, - 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL, - 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL, - 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL, - 0x9324fd72UL - }, - { - 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL, - 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL, - 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL, - 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL, - 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL, - 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL, - 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL, - 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL, - 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL, - 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL, - 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL, - 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL, - 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL, - 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL, - 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL, - 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL, - 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL, - 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL, - 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL, - 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL, - 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL, - 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL, - 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL, - 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL, - 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL, - 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL, - 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL, - 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL, - 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL, - 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL, - 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL, - 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL, - 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL, - 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL, - 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL, - 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL, - 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL, - 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL, - 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL, - 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL, - 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL, - 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL, - 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL, - 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL, - 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL, - 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL, - 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL, - 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL, - 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL, - 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL, - 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL, - 0xbe9834edUL - }, - { - 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL, - 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL, - 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL, - 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL, - 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL, - 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL, - 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL, - 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL, - 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL, - 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL, - 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL, - 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL, - 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL, - 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL, - 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL, - 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL, - 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL, - 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL, - 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL, - 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL, - 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL, - 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL, - 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL, - 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL, - 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL, - 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL, - 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL, - 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL, - 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL, - 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL, - 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL, - 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL, - 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL, - 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL, - 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL, - 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL, - 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL, - 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL, - 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL, - 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL, - 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL, - 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL, - 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL, - 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL, - 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL, - 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL, - 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL, - 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL, - 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL, - 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL, - 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL, - 0xde0506f1UL - }, - { - 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL, - 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL, - 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL, - 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL, - 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL, - 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL, - 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL, - 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL, - 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL, - 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL, - 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL, - 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL, - 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL, - 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL, - 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL, - 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL, - 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL, - 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL, - 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL, - 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL, - 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL, - 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL, - 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL, - 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL, - 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL, - 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL, - 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL, - 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL, - 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL, - 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL, - 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL, - 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL, - 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL, - 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL, - 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL, - 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL, - 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL, - 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL, - 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL, - 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL, - 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL, - 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL, - 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL, - 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL, - 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL, - 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL, - 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL, - 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL, - 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL, - 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL, - 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL, - 0x8def022dUL - }, - { - 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL, - 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL, - 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL, - 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL, - 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL, - 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL, - 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL, - 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL, - 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL, - 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL, - 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL, - 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL, - 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL, - 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL, - 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL, - 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL, - 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL, - 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL, - 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL, - 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL, - 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL, - 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL, - 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL, - 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL, - 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL, - 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL, - 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL, - 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL, - 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL, - 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL, - 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL, - 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL, - 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL, - 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL, - 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL, - 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL, - 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL, - 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL, - 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL, - 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL, - 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL, - 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL, - 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL, - 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL, - 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL, - 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL, - 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL, - 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL, - 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL, - 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL, - 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL, - 0x72fd2493UL - }, - { - 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL, - 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL, - 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL, - 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL, - 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL, - 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL, - 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL, - 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL, - 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL, - 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL, - 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL, - 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL, - 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL, - 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL, - 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL, - 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL, - 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL, - 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL, - 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL, - 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL, - 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL, - 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL, - 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL, - 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL, - 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL, - 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL, - 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL, - 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL, - 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL, - 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL, - 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL, - 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL, - 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL, - 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL, - 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL, - 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL, - 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL, - 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL, - 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL, - 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL, - 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL, - 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL, - 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL, - 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL, - 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL, - 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL, - 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL, - 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL, - 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL, - 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL, - 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL, - 0xed3498beUL - }, - { - 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL, - 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL, - 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL, - 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL, - 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL, - 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL, - 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL, - 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL, - 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL, - 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL, - 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL, - 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL, - 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL, - 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL, - 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL, - 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL, - 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL, - 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL, - 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL, - 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL, - 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL, - 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL, - 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL, - 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL, - 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL, - 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL, - 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL, - 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL, - 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL, - 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL, - 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL, - 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL, - 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL, - 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL, - 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL, - 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL, - 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL, - 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL, - 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL, - 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL, - 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL, - 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL, - 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL, - 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL, - 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL, - 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL, - 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL, - 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL, - 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL, - 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL, - 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL, - 0xf10605deUL -#endif - } -}; diff --git a/src/beast/test/zlib/zlib-1.2.8/deflate.c b/src/beast/test/zlib/zlib-1.2.8/deflate.c deleted file mode 100644 index 696957705b7..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/deflate.c +++ /dev/null @@ -1,1967 +0,0 @@ -/* deflate.c -- compress data using the deflation algorithm - * Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* - * ALGORITHM - * - * The "deflation" process depends on being able to identify portions - * of the input text which are identical to earlier input (within a - * sliding window trailing behind the input currently being processed). - * - * The most straightforward technique turns out to be the fastest for - * most input files: try all possible matches and select the longest. - * The key feature of this algorithm is that insertions into the string - * dictionary are very simple and thus fast, and deletions are avoided - * completely. Insertions are performed at each input character, whereas - * string matches are performed only when the previous match ends. So it - * is preferable to spend more time in matches to allow very fast string - * insertions and avoid deletions. The matching algorithm for small - * strings is inspired from that of Rabin & Karp. A brute force approach - * is used to find longer strings when a small match has been found. - * A similar algorithm is used in comic (by Jan-Mark Wams) and freeze - * (by Leonid Broukhis). - * A previous version of this file used a more sophisticated algorithm - * (by Fiala and Greene) which is guaranteed to run in linear amortized - * time, but has a larger average cost, uses more memory and is patented. - * However the F&G algorithm may be faster for some highly redundant - * files if the parameter max_chain_length (described below) is too large. - * - * ACKNOWLEDGEMENTS - * - * The idea of lazy evaluation of matches is due to Jan-Mark Wams, and - * I found it in 'freeze' written by Leonid Broukhis. - * Thanks to many people for bug reports and testing. - * - * REFERENCES - * - * Deutsch, L.P.,"DEFLATE Compressed Data Format Specification". - * Available in http://tools.ietf.org/html/rfc1951 - * - * A description of the Rabin and Karp algorithm is given in the book - * "Algorithms" by R. Sedgewick, Addison-Wesley, p252. - * - * Fiala,E.R., and Greene,D.H. - * Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595 - * - */ - -/* @(#) $Id$ */ - -#include "deflate.h" - -const char deflate_copyright[] = - " deflate 1.2.8 Copyright 1995-2013 Jean-loup Gailly and Mark Adler "; -/* - If you use the zlib library in a product, an acknowledgment is welcome - in the documentation of your product. If for some reason you cannot - include such an acknowledgment, I would appreciate that you keep this - copyright string in the executable of your product. - */ - -/* =========================================================================== - * Function prototypes. - */ -typedef enum { - need_more, /* block not completed, need more input or more output */ - block_done, /* block flush performed */ - finish_started, /* finish started, need only more output at next deflate */ - finish_done /* finish done, accept no more input or output */ -} block_state; - -typedef block_state (*compress_func) OF((deflate_state *s, int flush)); -/* Compression function. Returns the block state after the call. */ - -local void fill_window OF((deflate_state *s)); -local block_state deflate_stored OF((deflate_state *s, int flush)); -local block_state deflate_fast OF((deflate_state *s, int flush)); -#ifndef FASTEST -local block_state deflate_slow OF((deflate_state *s, int flush)); -#endif -local block_state deflate_rle OF((deflate_state *s, int flush)); -local block_state deflate_huff OF((deflate_state *s, int flush)); -local void lm_init OF((deflate_state *s)); -local void putShortMSB OF((deflate_state *s, uInt b)); -local void flush_pending OF((z_streamp strm)); -local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); -#ifdef ASMV - void match_init OF((void)); /* asm code initialization */ - uInt longest_match OF((deflate_state *s, IPos cur_match)); -#else -local uInt longest_match OF((deflate_state *s, IPos cur_match)); -#endif - -#ifdef DEBUG -local void check_match OF((deflate_state *s, IPos start, IPos match, - int length)); -#endif - -/* =========================================================================== - * Local data - */ - -#define NIL 0 -/* Tail of hash chains */ - -#ifndef TOO_FAR -# define TOO_FAR 4096 -#endif -/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */ - -/* Values for max_lazy_match, good_match and max_chain_length, depending on - * the desired pack level (0..9). The values given below have been tuned to - * exclude worst case performance for pathological files. Better values may be - * found for specific files. - */ -typedef struct config_s { - ush good_length; /* reduce lazy search above this match length */ - ush max_lazy; /* do not perform lazy search above this match length */ - ush nice_length; /* quit search above this match length */ - ush max_chain; - compress_func func; -} config; - -#ifdef FASTEST -local const config configuration_table[2] = { -/* good lazy nice chain */ -/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ -/* 1 */ {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */ -#else -local const config configuration_table[10] = { -/* good lazy nice chain */ -/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ -/* 1 */ {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */ -/* 2 */ {4, 5, 16, 8, deflate_fast}, -/* 3 */ {4, 6, 32, 32, deflate_fast}, - -/* 4 */ {4, 4, 16, 16, deflate_slow}, /* lazy matches */ -/* 5 */ {8, 16, 32, 32, deflate_slow}, -/* 6 */ {8, 16, 128, 128, deflate_slow}, -/* 7 */ {8, 32, 128, 256, deflate_slow}, -/* 8 */ {32, 128, 258, 1024, deflate_slow}, -/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* max compression */ -#endif - -/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4 - * For deflate_fast() (levels <= 3) good is ignored and lazy has a different - * meaning. - */ - -#define EQUAL 0 -/* result of memcmp for equal strings */ - -#ifndef NO_DUMMY_DECL -struct static_tree_desc_s {int dummy;}; /* for buggy compilers */ -#endif - -/* rank Z_BLOCK between Z_NO_FLUSH and Z_PARTIAL_FLUSH */ -#define RANK(f) (((f) << 1) - ((f) > 4 ? 9 : 0)) - -/* =========================================================================== - * Update a hash value with the given input byte - * IN assertion: all calls to to UPDATE_HASH are made with consecutive - * input characters, so that a running hash key can be computed from the - * previous key instead of complete recalculation each time. - */ -#define UPDATE_HASH(s,h,c) (h = (((h)<hash_shift) ^ (c)) & s->hash_mask) - - -/* =========================================================================== - * Insert string str in the dictionary and set match_head to the previous head - * of the hash chain (the most recent string with same hash key). Return - * the previous length of the hash chain. - * If this file is compiled with -DFASTEST, the compression level is forced - * to 1, and no hash chains are maintained. - * IN assertion: all calls to to INSERT_STRING are made with consecutive - * input characters and the first MIN_MATCH bytes of str are valid - * (except for the last MIN_MATCH-1 bytes of the input file). - */ -#ifdef FASTEST -#define INSERT_STRING(s, str, match_head) \ - (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ - match_head = s->head[s->ins_h], \ - s->head[s->ins_h] = (Pos)(str)) -#else -#define INSERT_STRING(s, str, match_head) \ - (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ - match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \ - s->head[s->ins_h] = (Pos)(str)) -#endif - -/* =========================================================================== - * Initialize the hash table (avoiding 64K overflow for 16 bit systems). - * prev[] will be initialized on the fly. - */ -#define CLEAR_HASH(s) \ - s->head[s->hash_size-1] = NIL; \ - zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head)); - -/* ========================================================================= */ -int ZEXPORT deflateInit_(strm, level, version, stream_size) - z_streamp strm; - int level; - const char *version; - int stream_size; -{ - return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, - Z_DEFAULT_STRATEGY, version, stream_size); - /* To do: ignore strm->next_in if we use it as window */ -} - -/* ========================================================================= */ -int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, - version, stream_size) - z_streamp strm; - int level; - int method; - int windowBits; - int memLevel; - int strategy; - const char *version; - int stream_size; -{ - deflate_state *s; - int wrap = 1; - static const char my_version[] = ZLIB_VERSION; - - ushf *overlay; - /* We overlay pending_buf and d_buf+l_buf. This works since the average - * output size for (length,distance) codes is <= 24 bits. - */ - - if (version == Z_NULL || version[0] != my_version[0] || - stream_size != sizeof(z_stream)) { - return Z_VERSION_ERROR; - } - if (strm == Z_NULL) return Z_STREAM_ERROR; - - strm->msg = Z_NULL; - if (strm->zalloc == (alloc_func)0) { -#ifdef Z_SOLO - return Z_STREAM_ERROR; -#else - strm->zalloc = zcalloc; - strm->opaque = (voidpf)0; -#endif - } - if (strm->zfree == (free_func)0) -#ifdef Z_SOLO - return Z_STREAM_ERROR; -#else - strm->zfree = zcfree; -#endif - -#ifdef FASTEST - if (level != 0) level = 1; -#else - if (level == Z_DEFAULT_COMPRESSION) level = 6; -#endif - - if (windowBits < 0) { /* suppress zlib wrapper */ - wrap = 0; - windowBits = -windowBits; - } -#ifdef GZIP - else if (windowBits > 15) { - wrap = 2; /* write gzip wrapper instead */ - windowBits -= 16; - } -#endif - if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || - windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || - strategy < 0 || strategy > Z_FIXED) { - return Z_STREAM_ERROR; - } - if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */ - s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state)); - if (s == Z_NULL) return Z_MEM_ERROR; - strm->state = (struct internal_state FAR *)s; - s->strm = strm; - - s->wrap = wrap; - s->gzhead = Z_NULL; - s->w_bits = windowBits; - s->w_size = 1 << s->w_bits; - s->w_mask = s->w_size - 1; - - s->hash_bits = memLevel + 7; - s->hash_size = 1 << s->hash_bits; - s->hash_mask = s->hash_size - 1; - s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH); - - s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); - s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos)); - s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos)); - - s->high_water = 0; /* nothing written to s->window yet */ - - s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ - - overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2); - s->pending_buf = (uchf *) overlay; - s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L); - - if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || - s->pending_buf == Z_NULL) { - s->status = FINISH_STATE; - strm->msg = ERR_MSG(Z_MEM_ERROR); - deflateEnd (strm); - return Z_MEM_ERROR; - } - s->d_buf = overlay + s->lit_bufsize/sizeof(ush); - s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize; - - s->level = level; - s->strategy = strategy; - s->method = (Byte)method; - - return deflateReset(strm); -} - -/* ========================================================================= */ -int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) - z_streamp strm; - const Bytef *dictionary; - uInt dictLength; -{ - deflate_state *s; - uInt str, n; - int wrap; - unsigned avail; - z_const unsigned char *next; - - if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL) - return Z_STREAM_ERROR; - s = strm->state; - wrap = s->wrap; - if (wrap == 2 || (wrap == 1 && s->status != INIT_STATE) || s->lookahead) - return Z_STREAM_ERROR; - - /* when using zlib wrappers, compute Adler-32 for provided dictionary */ - if (wrap == 1) - strm->adler = adler32(strm->adler, dictionary, dictLength); - s->wrap = 0; /* avoid computing Adler-32 in read_buf */ - - /* if dictionary would fill window, just replace the history */ - if (dictLength >= s->w_size) { - if (wrap == 0) { /* already empty otherwise */ - CLEAR_HASH(s); - s->strstart = 0; - s->block_start = 0L; - s->insert = 0; - } - dictionary += dictLength - s->w_size; /* use the tail */ - dictLength = s->w_size; - } - - /* insert dictionary into window and hash */ - avail = strm->avail_in; - next = strm->next_in; - strm->avail_in = dictLength; - strm->next_in = (z_const Bytef *)dictionary; - fill_window(s); - while (s->lookahead >= MIN_MATCH) { - str = s->strstart; - n = s->lookahead - (MIN_MATCH-1); - do { - UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); -#ifndef FASTEST - s->prev[str & s->w_mask] = s->head[s->ins_h]; -#endif - s->head[s->ins_h] = (Pos)str; - str++; - } while (--n); - s->strstart = str; - s->lookahead = MIN_MATCH-1; - fill_window(s); - } - s->strstart += s->lookahead; - s->block_start = (long)s->strstart; - s->insert = s->lookahead; - s->lookahead = 0; - s->match_length = s->prev_length = MIN_MATCH-1; - s->match_available = 0; - strm->next_in = next; - strm->avail_in = avail; - s->wrap = wrap; - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflateResetKeep (strm) - z_streamp strm; -{ - deflate_state *s; - - if (strm == Z_NULL || strm->state == Z_NULL || - strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) { - return Z_STREAM_ERROR; - } - - strm->total_in = strm->total_out = 0; - strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */ - strm->data_type = Z_UNKNOWN; - - s = (deflate_state *)strm->state; - s->pending = 0; - s->pending_out = s->pending_buf; - - if (s->wrap < 0) { - s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */ - } - s->status = s->wrap ? INIT_STATE : BUSY_STATE; - strm->adler = -#ifdef GZIP - s->wrap == 2 ? crc32(0L, Z_NULL, 0) : -#endif - adler32(0L, Z_NULL, 0); - s->last_flush = Z_NO_FLUSH; - - _tr_init(s); - - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflateReset (strm) - z_streamp strm; -{ - int ret; - - ret = deflateResetKeep(strm); - if (ret == Z_OK) - lm_init(strm->state); - return ret; -} - -/* ========================================================================= */ -int ZEXPORT deflateSetHeader (strm, head) - z_streamp strm; - gz_headerp head; -{ - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - if (strm->state->wrap != 2) return Z_STREAM_ERROR; - strm->state->gzhead = head; - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflatePending (strm, pending, bits) - unsigned *pending; - int *bits; - z_streamp strm; -{ - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - if (pending != Z_NULL) - *pending = strm->state->pending; - if (bits != Z_NULL) - *bits = strm->state->bi_valid; - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflatePrime (strm, bits, value) - z_streamp strm; - int bits; - int value; -{ - deflate_state *s; - int put; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - s = strm->state; - if ((Bytef *)(s->d_buf) < s->pending_out + ((Buf_size + 7) >> 3)) - return Z_BUF_ERROR; - do { - put = Buf_size - s->bi_valid; - if (put > bits) - put = bits; - s->bi_buf |= (ush)((value & ((1 << put) - 1)) << s->bi_valid); - s->bi_valid += put; - _tr_flush_bits(s); - value >>= put; - bits -= put; - } while (bits); - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflateParams(strm, level, strategy) - z_streamp strm; - int level; - int strategy; -{ - deflate_state *s; - compress_func func; - int err = Z_OK; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - s = strm->state; - -#ifdef FASTEST - if (level != 0) level = 1; -#else - if (level == Z_DEFAULT_COMPRESSION) level = 6; -#endif - if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) { - return Z_STREAM_ERROR; - } - func = configuration_table[s->level].func; - - if ((strategy != s->strategy || func != configuration_table[level].func) && - strm->total_in != 0) { - /* Flush the last buffer: */ - err = deflate(strm, Z_BLOCK); - if (err == Z_BUF_ERROR && s->pending == 0) - err = Z_OK; - } - if (s->level != level) { - s->level = level; - s->max_lazy_match = configuration_table[level].max_lazy; - s->good_match = configuration_table[level].good_length; - s->nice_match = configuration_table[level].nice_length; - s->max_chain_length = configuration_table[level].max_chain; - } - s->strategy = strategy; - return err; -} - -/* ========================================================================= */ -int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain) - z_streamp strm; - int good_length; - int max_lazy; - int nice_length; - int max_chain; -{ - deflate_state *s; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - s = strm->state; - s->good_match = good_length; - s->max_lazy_match = max_lazy; - s->nice_match = nice_length; - s->max_chain_length = max_chain; - return Z_OK; -} - -/* ========================================================================= - * For the default windowBits of 15 and memLevel of 8, this function returns - * a close to exact, as well as small, upper bound on the compressed size. - * They are coded as constants here for a reason--if the #define's are - * changed, then this function needs to be changed as well. The return - * value for 15 and 8 only works for those exact settings. - * - * For any setting other than those defaults for windowBits and memLevel, - * the value returned is a conservative worst case for the maximum expansion - * resulting from using fixed blocks instead of stored blocks, which deflate - * can emit on compressed data for some combinations of the parameters. - * - * This function could be more sophisticated to provide closer upper bounds for - * every combination of windowBits and memLevel. But even the conservative - * upper bound of about 14% expansion does not seem onerous for output buffer - * allocation. - */ -uLong ZEXPORT deflateBound(strm, sourceLen) - z_streamp strm; - uLong sourceLen; -{ - deflate_state *s; - uLong complen, wraplen; - Bytef *str; - - /* conservative upper bound for compressed data */ - complen = sourceLen + - ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5; - - /* if can't get parameters, return conservative bound plus zlib wrapper */ - if (strm == Z_NULL || strm->state == Z_NULL) - return complen + 6; - - /* compute wrapper length */ - s = strm->state; - switch (s->wrap) { - case 0: /* raw deflate */ - wraplen = 0; - break; - case 1: /* zlib wrapper */ - wraplen = 6 + (s->strstart ? 4 : 0); - break; - case 2: /* gzip wrapper */ - wraplen = 18; - if (s->gzhead != Z_NULL) { /* user-supplied gzip header */ - if (s->gzhead->extra != Z_NULL) - wraplen += 2 + s->gzhead->extra_len; - str = s->gzhead->name; - if (str != Z_NULL) - do { - wraplen++; - } while (*str++); - str = s->gzhead->comment; - if (str != Z_NULL) - do { - wraplen++; - } while (*str++); - if (s->gzhead->hcrc) - wraplen += 2; - } - break; - default: /* for compiler happiness */ - wraplen = 6; - } - - /* if not default parameters, return conservative bound */ - if (s->w_bits != 15 || s->hash_bits != 8 + 7) - return complen + wraplen; - - /* default settings: return tight bound for that case */ - return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + - (sourceLen >> 25) + 13 - 6 + wraplen; -} - -/* ========================================================================= - * Put a short in the pending buffer. The 16-bit value is put in MSB order. - * IN assertion: the stream state is correct and there is enough room in - * pending_buf. - */ -local void putShortMSB (s, b) - deflate_state *s; - uInt b; -{ - put_byte(s, (Byte)(b >> 8)); - put_byte(s, (Byte)(b & 0xff)); -} - -/* ========================================================================= - * Flush as much pending output as possible. All deflate() output goes - * through this function so some applications may wish to modify it - * to avoid allocating a large strm->next_out buffer and copying into it. - * (See also read_buf()). - */ -local void flush_pending(strm) - z_streamp strm; -{ - unsigned len; - deflate_state *s = strm->state; - - _tr_flush_bits(s); - len = s->pending; - if (len > strm->avail_out) len = strm->avail_out; - if (len == 0) return; - - zmemcpy(strm->next_out, s->pending_out, len); - strm->next_out += len; - s->pending_out += len; - strm->total_out += len; - strm->avail_out -= len; - s->pending -= len; - if (s->pending == 0) { - s->pending_out = s->pending_buf; - } -} - -/* ========================================================================= */ -int ZEXPORT deflate (strm, flush) - z_streamp strm; - int flush; -{ - int old_flush; /* value of flush param for previous deflate call */ - deflate_state *s; - - if (strm == Z_NULL || strm->state == Z_NULL || - flush > Z_BLOCK || flush < 0) { - return Z_STREAM_ERROR; - } - s = strm->state; - - if (strm->next_out == Z_NULL || - (strm->next_in == Z_NULL && strm->avail_in != 0) || - (s->status == FINISH_STATE && flush != Z_FINISH)) { - ERR_RETURN(strm, Z_STREAM_ERROR); - } - if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR); - - s->strm = strm; /* just in case */ - old_flush = s->last_flush; - s->last_flush = flush; - - /* Write the header */ - if (s->status == INIT_STATE) { -#ifdef GZIP - if (s->wrap == 2) { - strm->adler = crc32(0L, Z_NULL, 0); - put_byte(s, 31); - put_byte(s, 139); - put_byte(s, 8); - if (s->gzhead == Z_NULL) { - put_byte(s, 0); - put_byte(s, 0); - put_byte(s, 0); - put_byte(s, 0); - put_byte(s, 0); - put_byte(s, s->level == 9 ? 2 : - (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? - 4 : 0)); - put_byte(s, OS_CODE); - s->status = BUSY_STATE; - } - else { - put_byte(s, (s->gzhead->text ? 1 : 0) + - (s->gzhead->hcrc ? 2 : 0) + - (s->gzhead->extra == Z_NULL ? 0 : 4) + - (s->gzhead->name == Z_NULL ? 0 : 8) + - (s->gzhead->comment == Z_NULL ? 0 : 16) - ); - put_byte(s, (Byte)(s->gzhead->time & 0xff)); - put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff)); - put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff)); - put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff)); - put_byte(s, s->level == 9 ? 2 : - (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? - 4 : 0)); - put_byte(s, s->gzhead->os & 0xff); - if (s->gzhead->extra != Z_NULL) { - put_byte(s, s->gzhead->extra_len & 0xff); - put_byte(s, (s->gzhead->extra_len >> 8) & 0xff); - } - if (s->gzhead->hcrc) - strm->adler = crc32(strm->adler, s->pending_buf, - s->pending); - s->gzindex = 0; - s->status = EXTRA_STATE; - } - } - else -#endif - { - uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8; - uInt level_flags; - - if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2) - level_flags = 0; - else if (s->level < 6) - level_flags = 1; - else if (s->level == 6) - level_flags = 2; - else - level_flags = 3; - header |= (level_flags << 6); - if (s->strstart != 0) header |= PRESET_DICT; - header += 31 - (header % 31); - - s->status = BUSY_STATE; - putShortMSB(s, header); - - /* Save the adler32 of the preset dictionary: */ - if (s->strstart != 0) { - putShortMSB(s, (uInt)(strm->adler >> 16)); - putShortMSB(s, (uInt)(strm->adler & 0xffff)); - } - strm->adler = adler32(0L, Z_NULL, 0); - } - } -#ifdef GZIP - if (s->status == EXTRA_STATE) { - if (s->gzhead->extra != Z_NULL) { - uInt beg = s->pending; /* start of bytes to update crc */ - - while (s->gzindex < (s->gzhead->extra_len & 0xffff)) { - if (s->pending == s->pending_buf_size) { - if (s->gzhead->hcrc && s->pending > beg) - strm->adler = crc32(strm->adler, s->pending_buf + beg, - s->pending - beg); - flush_pending(strm); - beg = s->pending; - if (s->pending == s->pending_buf_size) - break; - } - put_byte(s, s->gzhead->extra[s->gzindex]); - s->gzindex++; - } - if (s->gzhead->hcrc && s->pending > beg) - strm->adler = crc32(strm->adler, s->pending_buf + beg, - s->pending - beg); - if (s->gzindex == s->gzhead->extra_len) { - s->gzindex = 0; - s->status = NAME_STATE; - } - } - else - s->status = NAME_STATE; - } - if (s->status == NAME_STATE) { - if (s->gzhead->name != Z_NULL) { - uInt beg = s->pending; /* start of bytes to update crc */ - int val; - - do { - if (s->pending == s->pending_buf_size) { - if (s->gzhead->hcrc && s->pending > beg) - strm->adler = crc32(strm->adler, s->pending_buf + beg, - s->pending - beg); - flush_pending(strm); - beg = s->pending; - if (s->pending == s->pending_buf_size) { - val = 1; - break; - } - } - val = s->gzhead->name[s->gzindex++]; - put_byte(s, val); - } while (val != 0); - if (s->gzhead->hcrc && s->pending > beg) - strm->adler = crc32(strm->adler, s->pending_buf + beg, - s->pending - beg); - if (val == 0) { - s->gzindex = 0; - s->status = COMMENT_STATE; - } - } - else - s->status = COMMENT_STATE; - } - if (s->status == COMMENT_STATE) { - if (s->gzhead->comment != Z_NULL) { - uInt beg = s->pending; /* start of bytes to update crc */ - int val; - - do { - if (s->pending == s->pending_buf_size) { - if (s->gzhead->hcrc && s->pending > beg) - strm->adler = crc32(strm->adler, s->pending_buf + beg, - s->pending - beg); - flush_pending(strm); - beg = s->pending; - if (s->pending == s->pending_buf_size) { - val = 1; - break; - } - } - val = s->gzhead->comment[s->gzindex++]; - put_byte(s, val); - } while (val != 0); - if (s->gzhead->hcrc && s->pending > beg) - strm->adler = crc32(strm->adler, s->pending_buf + beg, - s->pending - beg); - if (val == 0) - s->status = HCRC_STATE; - } - else - s->status = HCRC_STATE; - } - if (s->status == HCRC_STATE) { - if (s->gzhead->hcrc) { - if (s->pending + 2 > s->pending_buf_size) - flush_pending(strm); - if (s->pending + 2 <= s->pending_buf_size) { - put_byte(s, (Byte)(strm->adler & 0xff)); - put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); - strm->adler = crc32(0L, Z_NULL, 0); - s->status = BUSY_STATE; - } - } - else - s->status = BUSY_STATE; - } -#endif - - /* Flush as much pending output as possible */ - if (s->pending != 0) { - flush_pending(strm); - if (strm->avail_out == 0) { - /* Since avail_out is 0, deflate will be called again with - * more output space, but possibly with both pending and - * avail_in equal to zero. There won't be anything to do, - * but this is not an error situation so make sure we - * return OK instead of BUF_ERROR at next call of deflate: - */ - s->last_flush = -1; - return Z_OK; - } - - /* Make sure there is something to do and avoid duplicate consecutive - * flushes. For repeated and useless calls with Z_FINISH, we keep - * returning Z_STREAM_END instead of Z_BUF_ERROR. - */ - } else if (strm->avail_in == 0 && RANK(flush) <= RANK(old_flush) && - flush != Z_FINISH) { - ERR_RETURN(strm, Z_BUF_ERROR); - } - - /* User must not provide more input after the first FINISH: */ - if (s->status == FINISH_STATE && strm->avail_in != 0) { - ERR_RETURN(strm, Z_BUF_ERROR); - } - - /* Start a new block or continue the current one. - */ - if (strm->avail_in != 0 || s->lookahead != 0 || - (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) { - block_state bstate; - - bstate = s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) : - (s->strategy == Z_RLE ? deflate_rle(s, flush) : - (*(configuration_table[s->level].func))(s, flush)); - - if (bstate == finish_started || bstate == finish_done) { - s->status = FINISH_STATE; - } - if (bstate == need_more || bstate == finish_started) { - if (strm->avail_out == 0) { - s->last_flush = -1; /* avoid BUF_ERROR next call, see above */ - } - return Z_OK; - /* If flush != Z_NO_FLUSH && avail_out == 0, the next call - * of deflate should use the same flush parameter to make sure - * that the flush is complete. So we don't have to output an - * empty block here, this will be done at next call. This also - * ensures that for a very small output buffer, we emit at most - * one empty block. - */ - } - if (bstate == block_done) { - if (flush == Z_PARTIAL_FLUSH) { - _tr_align(s); - } else if (flush != Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */ - _tr_stored_block(s, (char*)0, 0L, 0); - /* For a full flush, this empty block will be recognized - * as a special marker by inflate_sync(). - */ - if (flush == Z_FULL_FLUSH) { - CLEAR_HASH(s); /* forget history */ - if (s->lookahead == 0) { - s->strstart = 0; - s->block_start = 0L; - s->insert = 0; - } - } - } - flush_pending(strm); - if (strm->avail_out == 0) { - s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */ - return Z_OK; - } - } - } - Assert(strm->avail_out > 0, "bug2"); - - if (flush != Z_FINISH) return Z_OK; - if (s->wrap <= 0) return Z_STREAM_END; - - /* Write the trailer */ -#ifdef GZIP - if (s->wrap == 2) { - put_byte(s, (Byte)(strm->adler & 0xff)); - put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); - put_byte(s, (Byte)((strm->adler >> 16) & 0xff)); - put_byte(s, (Byte)((strm->adler >> 24) & 0xff)); - put_byte(s, (Byte)(strm->total_in & 0xff)); - put_byte(s, (Byte)((strm->total_in >> 8) & 0xff)); - put_byte(s, (Byte)((strm->total_in >> 16) & 0xff)); - put_byte(s, (Byte)((strm->total_in >> 24) & 0xff)); - } - else -#endif - { - putShortMSB(s, (uInt)(strm->adler >> 16)); - putShortMSB(s, (uInt)(strm->adler & 0xffff)); - } - flush_pending(strm); - /* If avail_out is zero, the application will call deflate again - * to flush the rest. - */ - if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */ - return s->pending != 0 ? Z_OK : Z_STREAM_END; -} - -/* ========================================================================= */ -int ZEXPORT deflateEnd (strm) - z_streamp strm; -{ - int status; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - - status = strm->state->status; - if (status != INIT_STATE && - status != EXTRA_STATE && - status != NAME_STATE && - status != COMMENT_STATE && - status != HCRC_STATE && - status != BUSY_STATE && - status != FINISH_STATE) { - return Z_STREAM_ERROR; - } - - /* Deallocate in reverse order of allocations: */ - TRY_FREE(strm, strm->state->pending_buf); - TRY_FREE(strm, strm->state->head); - TRY_FREE(strm, strm->state->prev); - TRY_FREE(strm, strm->state->window); - - ZFREE(strm, strm->state); - strm->state = Z_NULL; - - return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK; -} - -/* ========================================================================= - * Copy the source state to the destination state. - * To simplify the source, this is not supported for 16-bit MSDOS (which - * doesn't have enough memory anyway to duplicate compression states). - */ -int ZEXPORT deflateCopy (dest, source) - z_streamp dest; - z_streamp source; -{ -#ifdef MAXSEG_64K - return Z_STREAM_ERROR; -#else - deflate_state *ds; - deflate_state *ss; - ushf *overlay; - - - if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) { - return Z_STREAM_ERROR; - } - - ss = source->state; - - zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream)); - - ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state)); - if (ds == Z_NULL) return Z_MEM_ERROR; - dest->state = (struct internal_state FAR *) ds; - zmemcpy((voidpf)ds, (voidpf)ss, sizeof(deflate_state)); - ds->strm = dest; - - ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); - ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos)); - ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos)); - overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2); - ds->pending_buf = (uchf *) overlay; - - if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL || - ds->pending_buf == Z_NULL) { - deflateEnd (dest); - return Z_MEM_ERROR; - } - /* following zmemcpy do not work for 16-bit MSDOS */ - zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte)); - zmemcpy((voidpf)ds->prev, (voidpf)ss->prev, ds->w_size * sizeof(Pos)); - zmemcpy((voidpf)ds->head, (voidpf)ss->head, ds->hash_size * sizeof(Pos)); - zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); - - ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); - ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush); - ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize; - - ds->l_desc.dyn_tree = ds->dyn_ltree; - ds->d_desc.dyn_tree = ds->dyn_dtree; - ds->bl_desc.dyn_tree = ds->bl_tree; - - return Z_OK; -#endif /* MAXSEG_64K */ -} - -/* =========================================================================== - * Read a new buffer from the current input stream, update the adler32 - * and total number of bytes read. All deflate() input goes through - * this function so some applications may wish to modify it to avoid - * allocating a large strm->next_in buffer and copying from it. - * (See also flush_pending()). - */ -local int read_buf(strm, buf, size) - z_streamp strm; - Bytef *buf; - unsigned size; -{ - unsigned len = strm->avail_in; - - if (len > size) len = size; - if (len == 0) return 0; - - strm->avail_in -= len; - - zmemcpy(buf, strm->next_in, len); - if (strm->state->wrap == 1) { - strm->adler = adler32(strm->adler, buf, len); - } -#ifdef GZIP - else if (strm->state->wrap == 2) { - strm->adler = crc32(strm->adler, buf, len); - } -#endif - strm->next_in += len; - strm->total_in += len; - - return (int)len; -} - -/* =========================================================================== - * Initialize the "longest match" routines for a new zlib stream - */ -local void lm_init (s) - deflate_state *s; -{ - s->window_size = (ulg)2L*s->w_size; - - CLEAR_HASH(s); - - /* Set the default configuration parameters: - */ - s->max_lazy_match = configuration_table[s->level].max_lazy; - s->good_match = configuration_table[s->level].good_length; - s->nice_match = configuration_table[s->level].nice_length; - s->max_chain_length = configuration_table[s->level].max_chain; - - s->strstart = 0; - s->block_start = 0L; - s->lookahead = 0; - s->insert = 0; - s->match_length = s->prev_length = MIN_MATCH-1; - s->match_available = 0; - s->ins_h = 0; -#ifndef FASTEST -#ifdef ASMV - match_init(); /* initialize the asm code */ -#endif -#endif -} - -#ifndef FASTEST -/* =========================================================================== - * Set match_start to the longest match starting at the given string and - * return its length. Matches shorter or equal to prev_length are discarded, - * in which case the result is equal to prev_length and match_start is - * garbage. - * IN assertions: cur_match is the head of the hash chain for the current - * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 - * OUT assertion: the match length is not greater than s->lookahead. - */ -#ifndef ASMV -/* For 80x86 and 680x0, an optimized version will be provided in match.asm or - * match.S. The code will be functionally equivalent. - */ -local uInt longest_match(s, cur_match) - deflate_state *s; - IPos cur_match; /* current match */ -{ - unsigned chain_length = s->max_chain_length;/* max hash chain length */ - register Bytef *scan = s->window + s->strstart; /* current string */ - register Bytef *match; /* matched string */ - register int len; /* length of current match */ - int best_len = s->prev_length; /* best match length so far */ - int nice_match = s->nice_match; /* stop if match long enough */ - IPos limit = s->strstart > (IPos)MAX_DIST(s) ? - s->strstart - (IPos)MAX_DIST(s) : NIL; - /* Stop when cur_match becomes <= limit. To simplify the code, - * we prevent matches with the string of window index 0. - */ - Posf *prev = s->prev; - uInt wmask = s->w_mask; - -#ifdef UNALIGNED_OK - /* Compare two bytes at a time. Note: this is not always beneficial. - * Try with and without -DUNALIGNED_OK to check. - */ - register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1; - register ush scan_start = *(ushf*)scan; - register ush scan_end = *(ushf*)(scan+best_len-1); -#else - register Bytef *strend = s->window + s->strstart + MAX_MATCH; - register Byte scan_end1 = scan[best_len-1]; - register Byte scan_end = scan[best_len]; -#endif - - /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. - * It is easy to get rid of this optimization if necessary. - */ - Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); - - /* Do not waste too much time if we already have a good match: */ - if (s->prev_length >= s->good_match) { - chain_length >>= 2; - } - /* Do not look for matches beyond the end of the input. This is necessary - * to make deflate deterministic. - */ - if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; - - Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); - - do { - Assert(cur_match < s->strstart, "no future"); - match = s->window + cur_match; - - /* Skip to next match if the match length cannot increase - * or if the match length is less than 2. Note that the checks below - * for insufficient lookahead only occur occasionally for performance - * reasons. Therefore uninitialized memory will be accessed, and - * conditional jumps will be made that depend on those values. - * However the length of the match is limited to the lookahead, so - * the output of deflate is not affected by the uninitialized values. - */ -#if (defined(UNALIGNED_OK) && MAX_MATCH == 258) - /* This code assumes sizeof(unsigned short) == 2. Do not use - * UNALIGNED_OK if your compiler uses a different size. - */ - if (*(ushf*)(match+best_len-1) != scan_end || - *(ushf*)match != scan_start) continue; - - /* It is not necessary to compare scan[2] and match[2] since they are - * always equal when the other bytes match, given that the hash keys - * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at - * strstart+3, +5, ... up to strstart+257. We check for insufficient - * lookahead only every 4th comparison; the 128th check will be made - * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is - * necessary to put more guard bytes at the end of the window, or - * to check more often for insufficient lookahead. - */ - Assert(scan[2] == match[2], "scan[2]?"); - scan++, match++; - do { - } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) && - *(ushf*)(scan+=2) == *(ushf*)(match+=2) && - *(ushf*)(scan+=2) == *(ushf*)(match+=2) && - *(ushf*)(scan+=2) == *(ushf*)(match+=2) && - scan < strend); - /* The funny "do {}" generates better code on most compilers */ - - /* Here, scan <= window+strstart+257 */ - Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); - if (*scan == *match) scan++; - - len = (MAX_MATCH - 1) - (int)(strend-scan); - scan = strend - (MAX_MATCH-1); - -#else /* UNALIGNED_OK */ - - if (match[best_len] != scan_end || - match[best_len-1] != scan_end1 || - *match != *scan || - *++match != scan[1]) continue; - - /* The check at best_len-1 can be removed because it will be made - * again later. (This heuristic is not always a win.) - * It is not necessary to compare scan[2] and match[2] since they - * are always equal when the other bytes match, given that - * the hash keys are equal and that HASH_BITS >= 8. - */ - scan += 2, match++; - Assert(*scan == *match, "match[2]?"); - - /* We check for insufficient lookahead only every 8th comparison; - * the 256th check will be made at strstart+258. - */ - do { - } while (*++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - scan < strend); - - Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); - - len = MAX_MATCH - (int)(strend - scan); - scan = strend - MAX_MATCH; - -#endif /* UNALIGNED_OK */ - - if (len > best_len) { - s->match_start = cur_match; - best_len = len; - if (len >= nice_match) break; -#ifdef UNALIGNED_OK - scan_end = *(ushf*)(scan+best_len-1); -#else - scan_end1 = scan[best_len-1]; - scan_end = scan[best_len]; -#endif - } - } while ((cur_match = prev[cur_match & wmask]) > limit - && --chain_length != 0); - - if ((uInt)best_len <= s->lookahead) return (uInt)best_len; - return s->lookahead; -} -#endif /* ASMV */ - -#else /* FASTEST */ - -/* --------------------------------------------------------------------------- - * Optimized version for FASTEST only - */ -local uInt longest_match(s, cur_match) - deflate_state *s; - IPos cur_match; /* current match */ -{ - register Bytef *scan = s->window + s->strstart; /* current string */ - register Bytef *match; /* matched string */ - register int len; /* length of current match */ - register Bytef *strend = s->window + s->strstart + MAX_MATCH; - - /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. - * It is easy to get rid of this optimization if necessary. - */ - Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); - - Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); - - Assert(cur_match < s->strstart, "no future"); - - match = s->window + cur_match; - - /* Return failure if the match length is less than 2: - */ - if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1; - - /* The check at best_len-1 can be removed because it will be made - * again later. (This heuristic is not always a win.) - * It is not necessary to compare scan[2] and match[2] since they - * are always equal when the other bytes match, given that - * the hash keys are equal and that HASH_BITS >= 8. - */ - scan += 2, match += 2; - Assert(*scan == *match, "match[2]?"); - - /* We check for insufficient lookahead only every 8th comparison; - * the 256th check will be made at strstart+258. - */ - do { - } while (*++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - scan < strend); - - Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); - - len = MAX_MATCH - (int)(strend - scan); - - if (len < MIN_MATCH) return MIN_MATCH - 1; - - s->match_start = cur_match; - return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead; -} - -#endif /* FASTEST */ - -#ifdef DEBUG -/* =========================================================================== - * Check that the match at match_start is indeed a match. - */ -local void check_match(s, start, match, length) - deflate_state *s; - IPos start, match; - int length; -{ - /* check that the match is indeed a match */ - if (zmemcmp(s->window + match, - s->window + start, length) != EQUAL) { - fprintf(stderr, " start %u, match %u, length %d\n", - start, match, length); - do { - fprintf(stderr, "%c%c", s->window[match++], s->window[start++]); - } while (--length != 0); - z_error("invalid match"); - } - if (z_verbose > 1) { - fprintf(stderr,"\\[%d,%d]", start-match, length); - do { putc(s->window[start++], stderr); } while (--length != 0); - } -} -#else -# define check_match(s, start, match, length) -#endif /* DEBUG */ - -/* =========================================================================== - * Fill the window when the lookahead becomes insufficient. - * Updates strstart and lookahead. - * - * IN assertion: lookahead < MIN_LOOKAHEAD - * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD - * At least one byte has been read, or avail_in == 0; reads are - * performed for at least two bytes (required for the zip translate_eol - * option -- not supported here). - */ -local void fill_window(s) - deflate_state *s; -{ - register unsigned n, m; - register Posf *p; - unsigned more; /* Amount of free space at the end of the window. */ - uInt wsize = s->w_size; - - Assert(s->lookahead < MIN_LOOKAHEAD, "already enough lookahead"); - - do { - more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); - - /* Deal with !@#$% 64K limit: */ - if (sizeof(int) <= 2) { - if (more == 0 && s->strstart == 0 && s->lookahead == 0) { - more = wsize; - - } else if (more == (unsigned)(-1)) { - /* Very unlikely, but possible on 16 bit machine if - * strstart == 0 && lookahead == 1 (input done a byte at time) - */ - more--; - } - } - - /* If the window is almost full and there is insufficient lookahead, - * move the upper half to the lower one to make room in the upper half. - */ - if (s->strstart >= wsize+MAX_DIST(s)) { - - zmemcpy(s->window, s->window+wsize, (unsigned)wsize); - s->match_start -= wsize; - s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ - s->block_start -= (long) wsize; - - /* Slide the hash table (could be avoided with 32 bit values - at the expense of memory usage). We slide even when level == 0 - to keep the hash table consistent if we switch back to level > 0 - later. (Using level 0 permanently is not an optimal usage of - zlib, so we don't care about this pathological case.) - */ - n = s->hash_size; - p = &s->head[n]; - do { - m = *--p; - *p = (Pos)(m >= wsize ? m-wsize : NIL); - } while (--n); - - n = wsize; -#ifndef FASTEST - p = &s->prev[n]; - do { - m = *--p; - *p = (Pos)(m >= wsize ? m-wsize : NIL); - /* If n is not on any hash chain, prev[n] is garbage but - * its value will never be used. - */ - } while (--n); -#endif - more += wsize; - } - if (s->strm->avail_in == 0) break; - - /* If there was no sliding: - * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && - * more == window_size - lookahead - strstart - * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) - * => more >= window_size - 2*WSIZE + 2 - * In the BIG_MEM or MMAP case (not yet supported), - * window_size == input_size + MIN_LOOKAHEAD && - * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. - * Otherwise, window_size == 2*WSIZE so more >= 2. - * If there was sliding, more >= WSIZE. So in all cases, more >= 2. - */ - Assert(more >= 2, "more < 2"); - - n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); - s->lookahead += n; - - /* Initialize the hash value now that we have some input: */ - if (s->lookahead + s->insert >= MIN_MATCH) { - uInt str = s->strstart - s->insert; - s->ins_h = s->window[str]; - UPDATE_HASH(s, s->ins_h, s->window[str + 1]); -#if MIN_MATCH != 3 - Call UPDATE_HASH() MIN_MATCH-3 more times -#endif - while (s->insert) { - UPDATE_HASH(s, s->ins_h, s->window[str + MIN_MATCH-1]); -#ifndef FASTEST - s->prev[str & s->w_mask] = s->head[s->ins_h]; -#endif - s->head[s->ins_h] = (Pos)str; - str++; - s->insert--; - if (s->lookahead + s->insert < MIN_MATCH) - break; - } - } - /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage, - * but this is not important since only literal bytes will be emitted. - */ - - } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0); - - /* If the WIN_INIT bytes after the end of the current data have never been - * written, then zero those bytes in order to avoid memory check reports of - * the use of uninitialized (or uninitialised as Julian writes) bytes by - * the longest match routines. Update the high water mark for the next - * time through here. WIN_INIT is set to MAX_MATCH since the longest match - * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead. - */ - if (s->high_water < s->window_size) { - ulg curr = s->strstart + (ulg)(s->lookahead); - ulg init; - - if (s->high_water < curr) { - /* Previous high water mark below current data -- zero WIN_INIT - * bytes or up to end of window, whichever is less. - */ - init = s->window_size - curr; - if (init > WIN_INIT) - init = WIN_INIT; - zmemzero(s->window + curr, (unsigned)init); - s->high_water = curr + init; - } - else if (s->high_water < (ulg)curr + WIN_INIT) { - /* High water mark at or above current data, but below current data - * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up - * to end of window, whichever is less. - */ - init = (ulg)curr + WIN_INIT - s->high_water; - if (init > s->window_size - s->high_water) - init = s->window_size - s->high_water; - zmemzero(s->window + s->high_water, (unsigned)init); - s->high_water += init; - } - } - - Assert((ulg)s->strstart <= s->window_size - MIN_LOOKAHEAD, - "not enough room for search"); -} - -/* =========================================================================== - * Flush the current block, with given end-of-file flag. - * IN assertion: strstart is set to the end of the current match. - */ -#define FLUSH_BLOCK_ONLY(s, last) { \ - _tr_flush_block(s, (s->block_start >= 0L ? \ - (charf *)&s->window[(unsigned)s->block_start] : \ - (charf *)Z_NULL), \ - (ulg)((long)s->strstart - s->block_start), \ - (last)); \ - s->block_start = s->strstart; \ - flush_pending(s->strm); \ - Tracev((stderr,"[FLUSH]")); \ -} - -/* Same but force premature exit if necessary. */ -#define FLUSH_BLOCK(s, last) { \ - FLUSH_BLOCK_ONLY(s, last); \ - if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \ -} - -/* =========================================================================== - * Copy without compression as much as possible from the input stream, return - * the current block state. - * This function does not insert new strings in the dictionary since - * uncompressible data is probably not useful. This function is used - * only for the level=0 compression option. - * NOTE: this function should be optimized to avoid extra copying from - * window to pending_buf. - */ -local block_state deflate_stored(s, flush) - deflate_state *s; - int flush; -{ - /* Stored blocks are limited to 0xffff bytes, pending_buf is limited - * to pending_buf_size, and each stored block has a 5 byte header: - */ - ulg max_block_size = 0xffff; - ulg max_start; - - if (max_block_size > s->pending_buf_size - 5) { - max_block_size = s->pending_buf_size - 5; - } - - /* Copy as much as possible from input to output: */ - for (;;) { - /* Fill the window as much as possible: */ - if (s->lookahead <= 1) { - - Assert(s->strstart < s->w_size+MAX_DIST(s) || - s->block_start >= (long)s->w_size, "slide too late"); - - fill_window(s); - if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more; - - if (s->lookahead == 0) break; /* flush the current block */ - } - Assert(s->block_start >= 0L, "block gone"); - - s->strstart += s->lookahead; - s->lookahead = 0; - - /* Emit a stored block if pending_buf will be full: */ - max_start = s->block_start + max_block_size; - if (s->strstart == 0 || (ulg)s->strstart >= max_start) { - /* strstart == 0 is possible when wraparound on 16-bit machine */ - s->lookahead = (uInt)(s->strstart - max_start); - s->strstart = (uInt)max_start; - FLUSH_BLOCK(s, 0); - } - /* Flush if we may have to slide, otherwise block_start may become - * negative and the data will be gone: - */ - if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) { - FLUSH_BLOCK(s, 0); - } - } - s->insert = 0; - if (flush == Z_FINISH) { - FLUSH_BLOCK(s, 1); - return finish_done; - } - if ((long)s->strstart > s->block_start) - FLUSH_BLOCK(s, 0); - return block_done; -} - -/* =========================================================================== - * Compress as much as possible from the input stream, return the current - * block state. - * This function does not perform lazy evaluation of matches and inserts - * new strings in the dictionary only for unmatched strings or for short - * matches. It is used only for the fast compression options. - */ -local block_state deflate_fast(s, flush) - deflate_state *s; - int flush; -{ - IPos hash_head; /* head of the hash chain */ - int bflush; /* set if current block must be flushed */ - - for (;;) { - /* Make sure that we always have enough lookahead, except - * at the end of the input file. We need MAX_MATCH bytes - * for the next match, plus MIN_MATCH bytes to insert the - * string following the next match. - */ - if (s->lookahead < MIN_LOOKAHEAD) { - fill_window(s); - if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { - return need_more; - } - if (s->lookahead == 0) break; /* flush the current block */ - } - - /* Insert the string window[strstart .. strstart+2] in the - * dictionary, and set hash_head to the head of the hash chain: - */ - hash_head = NIL; - if (s->lookahead >= MIN_MATCH) { - INSERT_STRING(s, s->strstart, hash_head); - } - - /* Find the longest match, discarding those <= prev_length. - * At this point we have always match_length < MIN_MATCH - */ - if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) { - /* To simplify the code, we prevent matches with the string - * of window index 0 (in particular we have to avoid a match - * of the string with itself at the start of the input file). - */ - s->match_length = longest_match (s, hash_head); - /* longest_match() sets match_start */ - } - if (s->match_length >= MIN_MATCH) { - check_match(s, s->strstart, s->match_start, s->match_length); - - _tr_tally_dist(s, s->strstart - s->match_start, - s->match_length - MIN_MATCH, bflush); - - s->lookahead -= s->match_length; - - /* Insert new strings in the hash table only if the match length - * is not too large. This saves time but degrades compression. - */ -#ifndef FASTEST - if (s->match_length <= s->max_insert_length && - s->lookahead >= MIN_MATCH) { - s->match_length--; /* string at strstart already in table */ - do { - s->strstart++; - INSERT_STRING(s, s->strstart, hash_head); - /* strstart never exceeds WSIZE-MAX_MATCH, so there are - * always MIN_MATCH bytes ahead. - */ - } while (--s->match_length != 0); - s->strstart++; - } else -#endif - { - s->strstart += s->match_length; - s->match_length = 0; - s->ins_h = s->window[s->strstart]; - UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]); -#if MIN_MATCH != 3 - Call UPDATE_HASH() MIN_MATCH-3 more times -#endif - /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not - * matter since it will be recomputed at next deflate call. - */ - } - } else { - /* No match, output a literal byte */ - Tracevv((stderr,"%c", s->window[s->strstart])); - _tr_tally_lit (s, s->window[s->strstart], bflush); - s->lookahead--; - s->strstart++; - } - if (bflush) FLUSH_BLOCK(s, 0); - } - s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1; - if (flush == Z_FINISH) { - FLUSH_BLOCK(s, 1); - return finish_done; - } - if (s->last_lit) - FLUSH_BLOCK(s, 0); - return block_done; -} - -#ifndef FASTEST -/* =========================================================================== - * Same as above, but achieves better compression. We use a lazy - * evaluation for matches: a match is finally adopted only if there is - * no better match at the next window position. - */ -local block_state deflate_slow(s, flush) - deflate_state *s; - int flush; -{ - IPos hash_head; /* head of hash chain */ - int bflush; /* set if current block must be flushed */ - - /* Process the input block. */ - for (;;) { - /* Make sure that we always have enough lookahead, except - * at the end of the input file. We need MAX_MATCH bytes - * for the next match, plus MIN_MATCH bytes to insert the - * string following the next match. - */ - if (s->lookahead < MIN_LOOKAHEAD) { - fill_window(s); - if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { - return need_more; - } - if (s->lookahead == 0) break; /* flush the current block */ - } - - /* Insert the string window[strstart .. strstart+2] in the - * dictionary, and set hash_head to the head of the hash chain: - */ - hash_head = NIL; - if (s->lookahead >= MIN_MATCH) { - INSERT_STRING(s, s->strstart, hash_head); - } - - /* Find the longest match, discarding those <= prev_length. - */ - s->prev_length = s->match_length, s->prev_match = s->match_start; - s->match_length = MIN_MATCH-1; - - if (hash_head != NIL && s->prev_length < s->max_lazy_match && - s->strstart - hash_head <= MAX_DIST(s)) { - /* To simplify the code, we prevent matches with the string - * of window index 0 (in particular we have to avoid a match - * of the string with itself at the start of the input file). - */ - s->match_length = longest_match (s, hash_head); - /* longest_match() sets match_start */ - - if (s->match_length <= 5 && (s->strategy == Z_FILTERED -#if TOO_FAR <= 32767 - || (s->match_length == MIN_MATCH && - s->strstart - s->match_start > TOO_FAR) -#endif - )) { - - /* If prev_match is also MIN_MATCH, match_start is garbage - * but we will ignore the current match anyway. - */ - s->match_length = MIN_MATCH-1; - } - } - /* If there was a match at the previous step and the current - * match is not better, output the previous match: - */ - if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) { - uInt max_insert = s->strstart + s->lookahead - MIN_MATCH; - /* Do not insert strings in hash table beyond this. */ - - check_match(s, s->strstart-1, s->prev_match, s->prev_length); - - _tr_tally_dist(s, s->strstart -1 - s->prev_match, - s->prev_length - MIN_MATCH, bflush); - - /* Insert in hash table all strings up to the end of the match. - * strstart-1 and strstart are already inserted. If there is not - * enough lookahead, the last two strings are not inserted in - * the hash table. - */ - s->lookahead -= s->prev_length-1; - s->prev_length -= 2; - do { - if (++s->strstart <= max_insert) { - INSERT_STRING(s, s->strstart, hash_head); - } - } while (--s->prev_length != 0); - s->match_available = 0; - s->match_length = MIN_MATCH-1; - s->strstart++; - - if (bflush) FLUSH_BLOCK(s, 0); - - } else if (s->match_available) { - /* If there was no match at the previous position, output a - * single literal. If there was a match but the current match - * is longer, truncate the previous match to a single literal. - */ - Tracevv((stderr,"%c", s->window[s->strstart-1])); - _tr_tally_lit(s, s->window[s->strstart-1], bflush); - if (bflush) { - FLUSH_BLOCK_ONLY(s, 0); - } - s->strstart++; - s->lookahead--; - if (s->strm->avail_out == 0) return need_more; - } else { - /* There is no previous match to compare with, wait for - * the next step to decide. - */ - s->match_available = 1; - s->strstart++; - s->lookahead--; - } - } - Assert (flush != Z_NO_FLUSH, "no flush?"); - if (s->match_available) { - Tracevv((stderr,"%c", s->window[s->strstart-1])); - _tr_tally_lit(s, s->window[s->strstart-1], bflush); - s->match_available = 0; - } - s->insert = s->strstart < MIN_MATCH-1 ? s->strstart : MIN_MATCH-1; - if (flush == Z_FINISH) { - FLUSH_BLOCK(s, 1); - return finish_done; - } - if (s->last_lit) - FLUSH_BLOCK(s, 0); - return block_done; -} -#endif /* FASTEST */ - -/* =========================================================================== - * For Z_RLE, simply look for runs of bytes, generate matches only of distance - * one. Do not maintain a hash table. (It will be regenerated if this run of - * deflate switches away from Z_RLE.) - */ -local block_state deflate_rle(s, flush) - deflate_state *s; - int flush; -{ - int bflush; /* set if current block must be flushed */ - uInt prev; /* byte at distance one to match */ - Bytef *scan, *strend; /* scan goes up to strend for length of run */ - - for (;;) { - /* Make sure that we always have enough lookahead, except - * at the end of the input file. We need MAX_MATCH bytes - * for the longest run, plus one for the unrolled loop. - */ - if (s->lookahead <= MAX_MATCH) { - fill_window(s); - if (s->lookahead <= MAX_MATCH && flush == Z_NO_FLUSH) { - return need_more; - } - if (s->lookahead == 0) break; /* flush the current block */ - } - - /* See how many times the previous byte repeats */ - s->match_length = 0; - if (s->lookahead >= MIN_MATCH && s->strstart > 0) { - scan = s->window + s->strstart - 1; - prev = *scan; - if (prev == *++scan && prev == *++scan && prev == *++scan) { - strend = s->window + s->strstart + MAX_MATCH; - do { - } while (prev == *++scan && prev == *++scan && - prev == *++scan && prev == *++scan && - prev == *++scan && prev == *++scan && - prev == *++scan && prev == *++scan && - scan < strend); - s->match_length = MAX_MATCH - (int)(strend - scan); - if (s->match_length > s->lookahead) - s->match_length = s->lookahead; - } - Assert(scan <= s->window+(uInt)(s->window_size-1), "wild scan"); - } - - /* Emit match if have run of MIN_MATCH or longer, else emit literal */ - if (s->match_length >= MIN_MATCH) { - check_match(s, s->strstart, s->strstart - 1, s->match_length); - - _tr_tally_dist(s, 1, s->match_length - MIN_MATCH, bflush); - - s->lookahead -= s->match_length; - s->strstart += s->match_length; - s->match_length = 0; - } else { - /* No match, output a literal byte */ - Tracevv((stderr,"%c", s->window[s->strstart])); - _tr_tally_lit (s, s->window[s->strstart], bflush); - s->lookahead--; - s->strstart++; - } - if (bflush) FLUSH_BLOCK(s, 0); - } - s->insert = 0; - if (flush == Z_FINISH) { - FLUSH_BLOCK(s, 1); - return finish_done; - } - if (s->last_lit) - FLUSH_BLOCK(s, 0); - return block_done; -} - -/* =========================================================================== - * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table. - * (It will be regenerated if this run of deflate switches away from Huffman.) - */ -local block_state deflate_huff(s, flush) - deflate_state *s; - int flush; -{ - int bflush; /* set if current block must be flushed */ - - for (;;) { - /* Make sure that we have a literal to write. */ - if (s->lookahead == 0) { - fill_window(s); - if (s->lookahead == 0) { - if (flush == Z_NO_FLUSH) - return need_more; - break; /* flush the current block */ - } - } - - /* Output a literal byte */ - s->match_length = 0; - Tracevv((stderr,"%c", s->window[s->strstart])); - _tr_tally_lit (s, s->window[s->strstart], bflush); - s->lookahead--; - s->strstart++; - if (bflush) FLUSH_BLOCK(s, 0); - } - s->insert = 0; - if (flush == Z_FINISH) { - FLUSH_BLOCK(s, 1); - return finish_done; - } - if (s->last_lit) - FLUSH_BLOCK(s, 0); - return block_done; -} diff --git a/src/beast/test/zlib/zlib-1.2.8/deflate.h b/src/beast/test/zlib/zlib-1.2.8/deflate.h deleted file mode 100644 index ce0299edd19..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/deflate.h +++ /dev/null @@ -1,346 +0,0 @@ -/* deflate.h -- internal compression state - * Copyright (C) 1995-2012 Jean-loup Gailly - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -/* @(#) $Id$ */ - -#ifndef DEFLATE_H -#define DEFLATE_H - -#include "zutil.h" - -/* define NO_GZIP when compiling if you want to disable gzip header and - trailer creation by deflate(). NO_GZIP would be used to avoid linking in - the crc code when it is not needed. For shared libraries, gzip encoding - should be left enabled. */ -#ifndef NO_GZIP -# define GZIP -#endif - -/* =========================================================================== - * Internal compression state. - */ - -#define LENGTH_CODES 29 -/* number of length codes, not counting the special END_BLOCK code */ - -#define LITERALS 256 -/* number of literal bytes 0..255 */ - -#define L_CODES (LITERALS+1+LENGTH_CODES) -/* number of Literal or Length codes, including the END_BLOCK code */ - -#define D_CODES 30 -/* number of distance codes */ - -#define BL_CODES 19 -/* number of codes used to transfer the bit lengths */ - -#define HEAP_SIZE (2*L_CODES+1) -/* maximum heap size */ - -#define MAX_BITS 15 -/* All codes must not exceed MAX_BITS bits */ - -#define Buf_size 16 -/* size of bit buffer in bi_buf */ - -#define INIT_STATE 42 -#define EXTRA_STATE 69 -#define NAME_STATE 73 -#define COMMENT_STATE 91 -#define HCRC_STATE 103 -#define BUSY_STATE 113 -#define FINISH_STATE 666 -/* Stream status */ - - -/* Data structure describing a single value and its code string. */ -typedef struct ct_data_s { - union { - ush freq; /* frequency count */ - ush code; /* bit string */ - } fc; - union { - ush dad; /* father node in Huffman tree */ - ush len; /* length of bit string */ - } dl; -} FAR ct_data; - -#define Freq fc.freq -#define Code fc.code -#define Dad dl.dad -#define Len dl.len - -typedef struct static_tree_desc_s static_tree_desc; - -typedef struct tree_desc_s { - ct_data *dyn_tree; /* the dynamic tree */ - int max_code; /* largest code with non zero frequency */ - static_tree_desc *stat_desc; /* the corresponding static tree */ -} FAR tree_desc; - -typedef ush Pos; -typedef Pos FAR Posf; -typedef unsigned IPos; - -/* A Pos is an index in the character window. We use short instead of int to - * save space in the various tables. IPos is used only for parameter passing. - */ - -typedef struct internal_state { - z_streamp strm; /* pointer back to this zlib stream */ - int status; /* as the name implies */ - Bytef *pending_buf; /* output still pending */ - ulg pending_buf_size; /* size of pending_buf */ - Bytef *pending_out; /* next pending byte to output to the stream */ - uInt pending; /* nb of bytes in the pending buffer */ - int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ - gz_headerp gzhead; /* gzip header information to write */ - uInt gzindex; /* where in extra, name, or comment */ - Byte method; /* can only be DEFLATED */ - int last_flush; /* value of flush param for previous deflate call */ - - /* used by deflate.c: */ - - uInt w_size; /* LZ77 window size (32K by default) */ - uInt w_bits; /* log2(w_size) (8..16) */ - uInt w_mask; /* w_size - 1 */ - - Bytef *window; - /* Sliding window. Input bytes are read into the second half of the window, - * and move to the first half later to keep a dictionary of at least wSize - * bytes. With this organization, matches are limited to a distance of - * wSize-MAX_MATCH bytes, but this ensures that IO is always - * performed with a length multiple of the block size. Also, it limits - * the window size to 64K, which is quite useful on MSDOS. - * To do: use the user input buffer as sliding window. - */ - - ulg window_size; - /* Actual size of window: 2*wSize, except when the user input buffer - * is directly used as sliding window. - */ - - Posf *prev; - /* Link to older string with same hash index. To limit the size of this - * array to 64K, this link is maintained only for the last 32K strings. - * An index in this array is thus a window index modulo 32K. - */ - - Posf *head; /* Heads of the hash chains or NIL. */ - - uInt ins_h; /* hash index of string to be inserted */ - uInt hash_size; /* number of elements in hash table */ - uInt hash_bits; /* log2(hash_size) */ - uInt hash_mask; /* hash_size-1 */ - - uInt hash_shift; - /* Number of bits by which ins_h must be shifted at each input - * step. It must be such that after MIN_MATCH steps, the oldest - * byte no longer takes part in the hash key, that is: - * hash_shift * MIN_MATCH >= hash_bits - */ - - long block_start; - /* Window position at the beginning of the current output block. Gets - * negative when the window is moved backwards. - */ - - uInt match_length; /* length of best match */ - IPos prev_match; /* previous match */ - int match_available; /* set if previous match exists */ - uInt strstart; /* start of string to insert */ - uInt match_start; /* start of matching string */ - uInt lookahead; /* number of valid bytes ahead in window */ - - uInt prev_length; - /* Length of the best match at previous step. Matches not greater than this - * are discarded. This is used in the lazy match evaluation. - */ - - uInt max_chain_length; - /* To speed up deflation, hash chains are never searched beyond this - * length. A higher limit improves compression ratio but degrades the - * speed. - */ - - uInt max_lazy_match; - /* Attempt to find a better match only when the current match is strictly - * smaller than this value. This mechanism is used only for compression - * levels >= 4. - */ -# define max_insert_length max_lazy_match - /* Insert new strings in the hash table only if the match length is not - * greater than this length. This saves time but degrades compression. - * max_insert_length is used only for compression levels <= 3. - */ - - int level; /* compression level (1..9) */ - int strategy; /* favor or force Huffman coding*/ - - uInt good_match; - /* Use a faster search when the previous match is longer than this */ - - int nice_match; /* Stop searching when current match exceeds this */ - - /* used by trees.c: */ - /* Didn't use ct_data typedef below to suppress compiler warning */ - struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */ - struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */ - struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */ - - struct tree_desc_s l_desc; /* desc. for literal tree */ - struct tree_desc_s d_desc; /* desc. for distance tree */ - struct tree_desc_s bl_desc; /* desc. for bit length tree */ - - ush bl_count[MAX_BITS+1]; - /* number of codes at each bit length for an optimal tree */ - - int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */ - int heap_len; /* number of elements in the heap */ - int heap_max; /* element of largest frequency */ - /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used. - * The same heap array is used to build all trees. - */ - - uch depth[2*L_CODES+1]; - /* Depth of each subtree used as tie breaker for trees of equal frequency - */ - - uchf *l_buf; /* buffer for literals or lengths */ - - uInt lit_bufsize; - /* Size of match buffer for literals/lengths. There are 4 reasons for - * limiting lit_bufsize to 64K: - * - frequencies can be kept in 16 bit counters - * - if compression is not successful for the first block, all input - * data is still in the window so we can still emit a stored block even - * when input comes from standard input. (This can also be done for - * all blocks if lit_bufsize is not greater than 32K.) - * - if compression is not successful for a file smaller than 64K, we can - * even emit a stored file instead of a stored block (saving 5 bytes). - * This is applicable only for zip (not gzip or zlib). - * - creating new Huffman trees less frequently may not provide fast - * adaptation to changes in the input data statistics. (Take for - * example a binary file with poorly compressible code followed by - * a highly compressible string table.) Smaller buffer sizes give - * fast adaptation but have of course the overhead of transmitting - * trees more frequently. - * - I can't count above 4 - */ - - uInt last_lit; /* running index in l_buf */ - - ushf *d_buf; - /* Buffer for distances. To simplify the code, d_buf and l_buf have - * the same number of elements. To use different lengths, an extra flag - * array would be necessary. - */ - - ulg opt_len; /* bit length of current block with optimal trees */ - ulg static_len; /* bit length of current block with static trees */ - uInt matches; /* number of string matches in current block */ - uInt insert; /* bytes at end of window left to insert */ - -#ifdef DEBUG - ulg compressed_len; /* total bit length of compressed file mod 2^32 */ - ulg bits_sent; /* bit length of compressed data sent mod 2^32 */ -#endif - - ush bi_buf; - /* Output buffer. bits are inserted starting at the bottom (least - * significant bits). - */ - int bi_valid; - /* Number of valid bits in bi_buf. All bits above the last valid bit - * are always zero. - */ - - ulg high_water; - /* High water mark offset in window for initialized bytes -- bytes above - * this are set to zero in order to avoid memory check warnings when - * longest match routines access bytes past the input. This is then - * updated to the new high water mark. - */ - -} FAR deflate_state; - -/* Output a byte on the stream. - * IN assertion: there is enough room in pending_buf. - */ -#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);} - - -#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) -/* Minimum amount of lookahead, except at the end of the input file. - * See deflate.c for comments about the MIN_MATCH+1. - */ - -#define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD) -/* In order to simplify the code, particularly on 16 bit machines, match - * distances are limited to MAX_DIST instead of WSIZE. - */ - -#define WIN_INIT MAX_MATCH -/* Number of bytes after end of data in window to initialize in order to avoid - memory checker errors from longest match routines */ - - /* in trees.c */ -void ZLIB_INTERNAL _tr_init OF((deflate_state *s)); -int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); -void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf, - ulg stored_len, int last)); -void ZLIB_INTERNAL _tr_flush_bits OF((deflate_state *s)); -void ZLIB_INTERNAL _tr_align OF((deflate_state *s)); -void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, - ulg stored_len, int last)); - -#define d_code(dist) \ - ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) -/* Mapping from a distance to a distance code. dist is the distance - 1 and - * must not have side effects. _dist_code[256] and _dist_code[257] are never - * used. - */ - -#ifndef DEBUG -/* Inline versions of _tr_tally for speed: */ - -#if defined(GEN_TREES_H) || !defined(STDC) - extern uch ZLIB_INTERNAL _length_code[]; - extern uch ZLIB_INTERNAL _dist_code[]; -#else - extern const uch ZLIB_INTERNAL _length_code[]; - extern const uch ZLIB_INTERNAL _dist_code[]; -#endif - -# define _tr_tally_lit(s, c, flush) \ - { uch cc = (c); \ - s->d_buf[s->last_lit] = 0; \ - s->l_buf[s->last_lit++] = cc; \ - s->dyn_ltree[cc].Freq++; \ - flush = (s->last_lit == s->lit_bufsize-1); \ - } -# define _tr_tally_dist(s, distance, length, flush) \ - { uch len = (length); \ - ush dist = (distance); \ - s->d_buf[s->last_lit] = dist; \ - s->l_buf[s->last_lit++] = len; \ - dist--; \ - s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ - s->dyn_dtree[d_code(dist)].Freq++; \ - flush = (s->last_lit == s->lit_bufsize-1); \ - } -#else -# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) -# define _tr_tally_dist(s, distance, length, flush) \ - flush = _tr_tally(s, distance, length) -#endif - -#endif /* DEFLATE_H */ diff --git a/src/beast/test/zlib/zlib-1.2.8/doc/algorithm.txt b/src/beast/test/zlib/zlib-1.2.8/doc/algorithm.txt deleted file mode 100644 index c97f495020b..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/doc/algorithm.txt +++ /dev/null @@ -1,209 +0,0 @@ -1. Compression algorithm (deflate) - -The deflation algorithm used by gzip (also zip and zlib) is a variation of -LZ77 (Lempel-Ziv 1977, see reference below). It finds duplicated strings in -the input data. The second occurrence of a string is replaced by a -pointer to the previous string, in the form of a pair (distance, -length). Distances are limited to 32K bytes, and lengths are limited -to 258 bytes. When a string does not occur anywhere in the previous -32K bytes, it is emitted as a sequence of literal bytes. (In this -description, `string' must be taken as an arbitrary sequence of bytes, -and is not restricted to printable characters.) - -Literals or match lengths are compressed with one Huffman tree, and -match distances are compressed with another tree. The trees are stored -in a compact form at the start of each block. The blocks can have any -size (except that the compressed data for one block must fit in -available memory). A block is terminated when deflate() determines that -it would be useful to start another block with fresh trees. (This is -somewhat similar to the behavior of LZW-based _compress_.) - -Duplicated strings are found using a hash table. All input strings of -length 3 are inserted in the hash table. A hash index is computed for -the next 3 bytes. If the hash chain for this index is not empty, all -strings in the chain are compared with the current input string, and -the longest match is selected. - -The hash chains are searched starting with the most recent strings, to -favor small distances and thus take advantage of the Huffman encoding. -The hash chains are singly linked. There are no deletions from the -hash chains, the algorithm simply discards matches that are too old. - -To avoid a worst-case situation, very long hash chains are arbitrarily -truncated at a certain length, determined by a runtime option (level -parameter of deflateInit). So deflate() does not always find the longest -possible match but generally finds a match which is long enough. - -deflate() also defers the selection of matches with a lazy evaluation -mechanism. After a match of length N has been found, deflate() searches for -a longer match at the next input byte. If a longer match is found, the -previous match is truncated to a length of one (thus producing a single -literal byte) and the process of lazy evaluation begins again. Otherwise, -the original match is kept, and the next match search is attempted only N -steps later. - -The lazy match evaluation is also subject to a runtime parameter. If -the current match is long enough, deflate() reduces the search for a longer -match, thus speeding up the whole process. If compression ratio is more -important than speed, deflate() attempts a complete second search even if -the first match is already long enough. - -The lazy match evaluation is not performed for the fastest compression -modes (level parameter 1 to 3). For these fast modes, new strings -are inserted in the hash table only when no match was found, or -when the match is not too long. This degrades the compression ratio -but saves time since there are both fewer insertions and fewer searches. - - -2. Decompression algorithm (inflate) - -2.1 Introduction - -The key question is how to represent a Huffman code (or any prefix code) so -that you can decode fast. The most important characteristic is that shorter -codes are much more common than longer codes, so pay attention to decoding the -short codes fast, and let the long codes take longer to decode. - -inflate() sets up a first level table that covers some number of bits of -input less than the length of longest code. It gets that many bits from the -stream, and looks it up in the table. The table will tell if the next -code is that many bits or less and how many, and if it is, it will tell -the value, else it will point to the next level table for which inflate() -grabs more bits and tries to decode a longer code. - -How many bits to make the first lookup is a tradeoff between the time it -takes to decode and the time it takes to build the table. If building the -table took no time (and if you had infinite memory), then there would only -be a first level table to cover all the way to the longest code. However, -building the table ends up taking a lot longer for more bits since short -codes are replicated many times in such a table. What inflate() does is -simply to make the number of bits in the first table a variable, and then -to set that variable for the maximum speed. - -For inflate, which has 286 possible codes for the literal/length tree, the size -of the first table is nine bits. Also the distance trees have 30 possible -values, and the size of the first table is six bits. Note that for each of -those cases, the table ended up one bit longer than the ``average'' code -length, i.e. the code length of an approximately flat code which would be a -little more than eight bits for 286 symbols and a little less than five bits -for 30 symbols. - - -2.2 More details on the inflate table lookup - -Ok, you want to know what this cleverly obfuscated inflate tree actually -looks like. You are correct that it's not a Huffman tree. It is simply a -lookup table for the first, let's say, nine bits of a Huffman symbol. The -symbol could be as short as one bit or as long as 15 bits. If a particular -symbol is shorter than nine bits, then that symbol's translation is duplicated -in all those entries that start with that symbol's bits. For example, if the -symbol is four bits, then it's duplicated 32 times in a nine-bit table. If a -symbol is nine bits long, it appears in the table once. - -If the symbol is longer than nine bits, then that entry in the table points -to another similar table for the remaining bits. Again, there are duplicated -entries as needed. The idea is that most of the time the symbol will be short -and there will only be one table look up. (That's whole idea behind data -compression in the first place.) For the less frequent long symbols, there -will be two lookups. If you had a compression method with really long -symbols, you could have as many levels of lookups as is efficient. For -inflate, two is enough. - -So a table entry either points to another table (in which case nine bits in -the above example are gobbled), or it contains the translation for the symbol -and the number of bits to gobble. Then you start again with the next -ungobbled bit. - -You may wonder: why not just have one lookup table for how ever many bits the -longest symbol is? The reason is that if you do that, you end up spending -more time filling in duplicate symbol entries than you do actually decoding. -At least for deflate's output that generates new trees every several 10's of -kbytes. You can imagine that filling in a 2^15 entry table for a 15-bit code -would take too long if you're only decoding several thousand symbols. At the -other extreme, you could make a new table for every bit in the code. In fact, -that's essentially a Huffman tree. But then you spend too much time -traversing the tree while decoding, even for short symbols. - -So the number of bits for the first lookup table is a trade of the time to -fill out the table vs. the time spent looking at the second level and above of -the table. - -Here is an example, scaled down: - -The code being decoded, with 10 symbols, from 1 to 6 bits long: - -A: 0 -B: 10 -C: 1100 -D: 11010 -E: 11011 -F: 11100 -G: 11101 -H: 11110 -I: 111110 -J: 111111 - -Let's make the first table three bits long (eight entries): - -000: A,1 -001: A,1 -010: A,1 -011: A,1 -100: B,2 -101: B,2 -110: -> table X (gobble 3 bits) -111: -> table Y (gobble 3 bits) - -Each entry is what the bits decode as and how many bits that is, i.e. how -many bits to gobble. Or the entry points to another table, with the number of -bits to gobble implicit in the size of the table. - -Table X is two bits long since the longest code starting with 110 is five bits -long: - -00: C,1 -01: C,1 -10: D,2 -11: E,2 - -Table Y is three bits long since the longest code starting with 111 is six -bits long: - -000: F,2 -001: F,2 -010: G,2 -011: G,2 -100: H,2 -101: H,2 -110: I,3 -111: J,3 - -So what we have here are three tables with a total of 20 entries that had to -be constructed. That's compared to 64 entries for a single table. Or -compared to 16 entries for a Huffman tree (six two entry tables and one four -entry table). Assuming that the code ideally represents the probability of -the symbols, it takes on the average 1.25 lookups per symbol. That's compared -to one lookup for the single table, or 1.66 lookups per symbol for the -Huffman tree. - -There, I think that gives you a picture of what's going on. For inflate, the -meaning of a particular symbol is often more than just a letter. It can be a -byte (a "literal"), or it can be either a length or a distance which -indicates a base value and a number of bits to fetch after the code that is -added to the base value. Or it might be the special end-of-block code. The -data structures created in inftrees.c try to encode all that information -compactly in the tables. - - -Jean-loup Gailly Mark Adler -jloup@gzip.org madler@alumni.caltech.edu - - -References: - -[LZ77] Ziv J., Lempel A., ``A Universal Algorithm for Sequential Data -Compression,'' IEEE Transactions on Information Theory, Vol. 23, No. 3, -pp. 337-343. - -``DEFLATE Compressed Data Format Specification'' available in -http://tools.ietf.org/html/rfc1951 diff --git a/src/beast/test/zlib/zlib-1.2.8/doc/rfc1950.txt b/src/beast/test/zlib/zlib-1.2.8/doc/rfc1950.txt deleted file mode 100644 index ce6428a0f2e..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/doc/rfc1950.txt +++ /dev/null @@ -1,619 +0,0 @@ - - - - - - -Network Working Group P. Deutsch -Request for Comments: 1950 Aladdin Enterprises -Category: Informational J-L. Gailly - Info-ZIP - May 1996 - - - ZLIB Compressed Data Format Specification version 3.3 - -Status of This Memo - - This memo provides information for the Internet community. This memo - does not specify an Internet standard of any kind. Distribution of - this memo is unlimited. - -IESG Note: - - The IESG takes no position on the validity of any Intellectual - Property Rights statements contained in this document. - -Notices - - Copyright (c) 1996 L. Peter Deutsch and Jean-Loup Gailly - - Permission is granted to copy and distribute this document for any - purpose and without charge, including translations into other - languages and incorporation into compilations, provided that the - copyright notice and this notice are preserved, and that any - substantive changes or deletions from the original are clearly - marked. - - A pointer to the latest version of this and related documentation in - HTML format can be found at the URL - . - -Abstract - - This specification defines a lossless compressed data format. The - data can be produced or consumed, even for an arbitrarily long - sequentially presented input data stream, using only an a priori - bounded amount of intermediate storage. The format presently uses - the DEFLATE compression method but can be easily extended to use - other compression methods. It can be implemented readily in a manner - not covered by patents. This specification also defines the ADLER-32 - checksum (an extension and improvement of the Fletcher checksum), - used for detection of data corruption, and provides an algorithm for - computing it. - - - - -Deutsch & Gailly Informational [Page 1] - -RFC 1950 ZLIB Compressed Data Format Specification May 1996 - - -Table of Contents - - 1. Introduction ................................................... 2 - 1.1. Purpose ................................................... 2 - 1.2. Intended audience ......................................... 3 - 1.3. Scope ..................................................... 3 - 1.4. Compliance ................................................ 3 - 1.5. Definitions of terms and conventions used ................ 3 - 1.6. Changes from previous versions ............................ 3 - 2. Detailed specification ......................................... 3 - 2.1. Overall conventions ....................................... 3 - 2.2. Data format ............................................... 4 - 2.3. Compliance ................................................ 7 - 3. References ..................................................... 7 - 4. Source code .................................................... 8 - 5. Security Considerations ........................................ 8 - 6. Acknowledgements ............................................... 8 - 7. Authors' Addresses ............................................. 8 - 8. Appendix: Rationale ............................................ 9 - 9. Appendix: Sample code ..........................................10 - -1. Introduction - - 1.1. Purpose - - The purpose of this specification is to define a lossless - compressed data format that: - - * Is independent of CPU type, operating system, file system, - and character set, and hence can be used for interchange; - - * Can be produced or consumed, even for an arbitrarily long - sequentially presented input data stream, using only an a - priori bounded amount of intermediate storage, and hence can - be used in data communications or similar structures such as - Unix filters; - - * Can use a number of different compression methods; - - * Can be implemented readily in a manner not covered by - patents, and hence can be practiced freely. - - The data format defined by this specification does not attempt to - allow random access to compressed data. - - - - - - - -Deutsch & Gailly Informational [Page 2] - -RFC 1950 ZLIB Compressed Data Format Specification May 1996 - - - 1.2. Intended audience - - This specification is intended for use by implementors of software - to compress data into zlib format and/or decompress data from zlib - format. - - The text of the specification assumes a basic background in - programming at the level of bits and other primitive data - representations. - - 1.3. Scope - - The specification specifies a compressed data format that can be - used for in-memory compression of a sequence of arbitrary bytes. - - 1.4. Compliance - - Unless otherwise indicated below, a compliant decompressor must be - able to accept and decompress any data set that conforms to all - the specifications presented here; a compliant compressor must - produce data sets that conform to all the specifications presented - here. - - 1.5. Definitions of terms and conventions used - - byte: 8 bits stored or transmitted as a unit (same as an octet). - (For this specification, a byte is exactly 8 bits, even on - machines which store a character on a number of bits different - from 8.) See below, for the numbering of bits within a byte. - - 1.6. Changes from previous versions - - Version 3.1 was the first public release of this specification. - In version 3.2, some terminology was changed and the Adler-32 - sample code was rewritten for clarity. In version 3.3, the - support for a preset dictionary was introduced, and the - specification was converted to RFC style. - -2. Detailed specification - - 2.1. Overall conventions - - In the diagrams below, a box like this: - - +---+ - | | <-- the vertical bars might be missing - +---+ - - - - -Deutsch & Gailly Informational [Page 3] - -RFC 1950 ZLIB Compressed Data Format Specification May 1996 - - - represents one byte; a box like this: - - +==============+ - | | - +==============+ - - represents a variable number of bytes. - - Bytes stored within a computer do not have a "bit order", since - they are always treated as a unit. However, a byte considered as - an integer between 0 and 255 does have a most- and least- - significant bit, and since we write numbers with the most- - significant digit on the left, we also write bytes with the most- - significant bit on the left. In the diagrams below, we number the - bits of a byte so that bit 0 is the least-significant bit, i.e., - the bits are numbered: - - +--------+ - |76543210| - +--------+ - - Within a computer, a number may occupy multiple bytes. All - multi-byte numbers in the format described here are stored with - the MOST-significant byte first (at the lower memory address). - For example, the decimal number 520 is stored as: - - 0 1 - +--------+--------+ - |00000010|00001000| - +--------+--------+ - ^ ^ - | | - | + less significant byte = 8 - + more significant byte = 2 x 256 - - 2.2. Data format - - A zlib stream has the following structure: - - 0 1 - +---+---+ - |CMF|FLG| (more-->) - +---+---+ - - - - - - - - -Deutsch & Gailly Informational [Page 4] - -RFC 1950 ZLIB Compressed Data Format Specification May 1996 - - - (if FLG.FDICT set) - - 0 1 2 3 - +---+---+---+---+ - | DICTID | (more-->) - +---+---+---+---+ - - +=====================+---+---+---+---+ - |...compressed data...| ADLER32 | - +=====================+---+---+---+---+ - - Any data which may appear after ADLER32 are not part of the zlib - stream. - - CMF (Compression Method and flags) - This byte is divided into a 4-bit compression method and a 4- - bit information field depending on the compression method. - - bits 0 to 3 CM Compression method - bits 4 to 7 CINFO Compression info - - CM (Compression method) - This identifies the compression method used in the file. CM = 8 - denotes the "deflate" compression method with a window size up - to 32K. This is the method used by gzip and PNG (see - references [1] and [2] in Chapter 3, below, for the reference - documents). CM = 15 is reserved. It might be used in a future - version of this specification to indicate the presence of an - extra field before the compressed data. - - CINFO (Compression info) - For CM = 8, CINFO is the base-2 logarithm of the LZ77 window - size, minus eight (CINFO=7 indicates a 32K window size). Values - of CINFO above 7 are not allowed in this version of the - specification. CINFO is not defined in this specification for - CM not equal to 8. - - FLG (FLaGs) - This flag byte is divided as follows: - - bits 0 to 4 FCHECK (check bits for CMF and FLG) - bit 5 FDICT (preset dictionary) - bits 6 to 7 FLEVEL (compression level) - - The FCHECK value must be such that CMF and FLG, when viewed as - a 16-bit unsigned integer stored in MSB order (CMF*256 + FLG), - is a multiple of 31. - - - - -Deutsch & Gailly Informational [Page 5] - -RFC 1950 ZLIB Compressed Data Format Specification May 1996 - - - FDICT (Preset dictionary) - If FDICT is set, a DICT dictionary identifier is present - immediately after the FLG byte. The dictionary is a sequence of - bytes which are initially fed to the compressor without - producing any compressed output. DICT is the Adler-32 checksum - of this sequence of bytes (see the definition of ADLER32 - below). The decompressor can use this identifier to determine - which dictionary has been used by the compressor. - - FLEVEL (Compression level) - These flags are available for use by specific compression - methods. The "deflate" method (CM = 8) sets these flags as - follows: - - 0 - compressor used fastest algorithm - 1 - compressor used fast algorithm - 2 - compressor used default algorithm - 3 - compressor used maximum compression, slowest algorithm - - The information in FLEVEL is not needed for decompression; it - is there to indicate if recompression might be worthwhile. - - compressed data - For compression method 8, the compressed data is stored in the - deflate compressed data format as described in the document - "DEFLATE Compressed Data Format Specification" by L. Peter - Deutsch. (See reference [3] in Chapter 3, below) - - Other compressed data formats are not specified in this version - of the zlib specification. - - ADLER32 (Adler-32 checksum) - This contains a checksum value of the uncompressed data - (excluding any dictionary data) computed according to Adler-32 - algorithm. This algorithm is a 32-bit extension and improvement - of the Fletcher algorithm, used in the ITU-T X.224 / ISO 8073 - standard. See references [4] and [5] in Chapter 3, below) - - Adler-32 is composed of two sums accumulated per byte: s1 is - the sum of all bytes, s2 is the sum of all s1 values. Both sums - are done modulo 65521. s1 is initialized to 1, s2 to zero. The - Adler-32 checksum is stored as s2*65536 + s1 in most- - significant-byte first (network) order. - - - - - - - - -Deutsch & Gailly Informational [Page 6] - -RFC 1950 ZLIB Compressed Data Format Specification May 1996 - - - 2.3. Compliance - - A compliant compressor must produce streams with correct CMF, FLG - and ADLER32, but need not support preset dictionaries. When the - zlib data format is used as part of another standard data format, - the compressor may use only preset dictionaries that are specified - by this other data format. If this other format does not use the - preset dictionary feature, the compressor must not set the FDICT - flag. - - A compliant decompressor must check CMF, FLG, and ADLER32, and - provide an error indication if any of these have incorrect values. - A compliant decompressor must give an error indication if CM is - not one of the values defined in this specification (only the - value 8 is permitted in this version), since another value could - indicate the presence of new features that would cause subsequent - data to be interpreted incorrectly. A compliant decompressor must - give an error indication if FDICT is set and DICTID is not the - identifier of a known preset dictionary. A decompressor may - ignore FLEVEL and still be compliant. When the zlib data format - is being used as a part of another standard format, a compliant - decompressor must support all the preset dictionaries specified by - the other format. When the other format does not use the preset - dictionary feature, a compliant decompressor must reject any - stream in which the FDICT flag is set. - -3. References - - [1] Deutsch, L.P.,"GZIP Compressed Data Format Specification", - available in ftp://ftp.uu.net/pub/archiving/zip/doc/ - - [2] Thomas Boutell, "PNG (Portable Network Graphics) specification", - available in ftp://ftp.uu.net/graphics/png/documents/ - - [3] Deutsch, L.P.,"DEFLATE Compressed Data Format Specification", - available in ftp://ftp.uu.net/pub/archiving/zip/doc/ - - [4] Fletcher, J. G., "An Arithmetic Checksum for Serial - Transmissions," IEEE Transactions on Communications, Vol. COM-30, - No. 1, January 1982, pp. 247-252. - - [5] ITU-T Recommendation X.224, Annex D, "Checksum Algorithms," - November, 1993, pp. 144, 145. (Available from - gopher://info.itu.ch). ITU-T X.244 is also the same as ISO 8073. - - - - - - - -Deutsch & Gailly Informational [Page 7] - -RFC 1950 ZLIB Compressed Data Format Specification May 1996 - - -4. Source code - - Source code for a C language implementation of a "zlib" compliant - library is available at ftp://ftp.uu.net/pub/archiving/zip/zlib/. - -5. Security Considerations - - A decoder that fails to check the ADLER32 checksum value may be - subject to undetected data corruption. - -6. Acknowledgements - - Trademarks cited in this document are the property of their - respective owners. - - Jean-Loup Gailly and Mark Adler designed the zlib format and wrote - the related software described in this specification. Glenn - Randers-Pehrson converted this document to RFC and HTML format. - -7. Authors' Addresses - - L. Peter Deutsch - Aladdin Enterprises - 203 Santa Margarita Ave. - Menlo Park, CA 94025 - - Phone: (415) 322-0103 (AM only) - FAX: (415) 322-1734 - EMail: - - - Jean-Loup Gailly - - EMail: - - Questions about the technical content of this specification can be - sent by email to - - Jean-Loup Gailly and - Mark Adler - - Editorial comments on this specification can be sent by email to - - L. Peter Deutsch and - Glenn Randers-Pehrson - - - - - - -Deutsch & Gailly Informational [Page 8] - -RFC 1950 ZLIB Compressed Data Format Specification May 1996 - - -8. Appendix: Rationale - - 8.1. Preset dictionaries - - A preset dictionary is specially useful to compress short input - sequences. The compressor can take advantage of the dictionary - context to encode the input in a more compact manner. The - decompressor can be initialized with the appropriate context by - virtually decompressing a compressed version of the dictionary - without producing any output. However for certain compression - algorithms such as the deflate algorithm this operation can be - achieved without actually performing any decompression. - - The compressor and the decompressor must use exactly the same - dictionary. The dictionary may be fixed or may be chosen among a - certain number of predefined dictionaries, according to the kind - of input data. The decompressor can determine which dictionary has - been chosen by the compressor by checking the dictionary - identifier. This document does not specify the contents of - predefined dictionaries, since the optimal dictionaries are - application specific. Standard data formats using this feature of - the zlib specification must precisely define the allowed - dictionaries. - - 8.2. The Adler-32 algorithm - - The Adler-32 algorithm is much faster than the CRC32 algorithm yet - still provides an extremely low probability of undetected errors. - - The modulo on unsigned long accumulators can be delayed for 5552 - bytes, so the modulo operation time is negligible. If the bytes - are a, b, c, the second sum is 3a + 2b + c + 3, and so is position - and order sensitive, unlike the first sum, which is just a - checksum. That 65521 is prime is important to avoid a possible - large class of two-byte errors that leave the check unchanged. - (The Fletcher checksum uses 255, which is not prime and which also - makes the Fletcher check insensitive to single byte changes 0 <-> - 255.) - - The sum s1 is initialized to 1 instead of zero to make the length - of the sequence part of s2, so that the length does not have to be - checked separately. (Any sequence of zeroes has a Fletcher - checksum of zero.) - - - - - - - - -Deutsch & Gailly Informational [Page 9] - -RFC 1950 ZLIB Compressed Data Format Specification May 1996 - - -9. Appendix: Sample code - - The following C code computes the Adler-32 checksum of a data buffer. - It is written for clarity, not for speed. The sample code is in the - ANSI C programming language. Non C users may find it easier to read - with these hints: - - & Bitwise AND operator. - >> Bitwise right shift operator. When applied to an - unsigned quantity, as here, right shift inserts zero bit(s) - at the left. - << Bitwise left shift operator. Left shift inserts zero - bit(s) at the right. - ++ "n++" increments the variable n. - % modulo operator: a % b is the remainder of a divided by b. - - #define BASE 65521 /* largest prime smaller than 65536 */ - - /* - Update a running Adler-32 checksum with the bytes buf[0..len-1] - and return the updated checksum. The Adler-32 checksum should be - initialized to 1. - - Usage example: - - unsigned long adler = 1L; - - while (read_buffer(buffer, length) != EOF) { - adler = update_adler32(adler, buffer, length); - } - if (adler != original_adler) error(); - */ - unsigned long update_adler32(unsigned long adler, - unsigned char *buf, int len) - { - unsigned long s1 = adler & 0xffff; - unsigned long s2 = (adler >> 16) & 0xffff; - int n; - - for (n = 0; n < len; n++) { - s1 = (s1 + buf[n]) % BASE; - s2 = (s2 + s1) % BASE; - } - return (s2 << 16) + s1; - } - - /* Return the adler32 of the bytes buf[0..len-1] */ - - - - -Deutsch & Gailly Informational [Page 10] - -RFC 1950 ZLIB Compressed Data Format Specification May 1996 - - - unsigned long adler32(unsigned char *buf, int len) - { - return update_adler32(1L, buf, len); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Deutsch & Gailly Informational [Page 11] - diff --git a/src/beast/test/zlib/zlib-1.2.8/doc/rfc1951.txt b/src/beast/test/zlib/zlib-1.2.8/doc/rfc1951.txt deleted file mode 100644 index 403c8c722ff..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/doc/rfc1951.txt +++ /dev/null @@ -1,955 +0,0 @@ - - - - - - -Network Working Group P. Deutsch -Request for Comments: 1951 Aladdin Enterprises -Category: Informational May 1996 - - - DEFLATE Compressed Data Format Specification version 1.3 - -Status of This Memo - - This memo provides information for the Internet community. This memo - does not specify an Internet standard of any kind. Distribution of - this memo is unlimited. - -IESG Note: - - The IESG takes no position on the validity of any Intellectual - Property Rights statements contained in this document. - -Notices - - Copyright (c) 1996 L. Peter Deutsch - - Permission is granted to copy and distribute this document for any - purpose and without charge, including translations into other - languages and incorporation into compilations, provided that the - copyright notice and this notice are preserved, and that any - substantive changes or deletions from the original are clearly - marked. - - A pointer to the latest version of this and related documentation in - HTML format can be found at the URL - . - -Abstract - - This specification defines a lossless compressed data format that - compresses data using a combination of the LZ77 algorithm and Huffman - coding, with efficiency comparable to the best currently available - general-purpose compression methods. The data can be produced or - consumed, even for an arbitrarily long sequentially presented input - data stream, using only an a priori bounded amount of intermediate - storage. The format can be implemented readily in a manner not - covered by patents. - - - - - - - - -Deutsch Informational [Page 1] - -RFC 1951 DEFLATE Compressed Data Format Specification May 1996 - - -Table of Contents - - 1. Introduction ................................................... 2 - 1.1. Purpose ................................................... 2 - 1.2. Intended audience ......................................... 3 - 1.3. Scope ..................................................... 3 - 1.4. Compliance ................................................ 3 - 1.5. Definitions of terms and conventions used ................ 3 - 1.6. Changes from previous versions ............................ 4 - 2. Compressed representation overview ............................. 4 - 3. Detailed specification ......................................... 5 - 3.1. Overall conventions ....................................... 5 - 3.1.1. Packing into bytes .................................. 5 - 3.2. Compressed block format ................................... 6 - 3.2.1. Synopsis of prefix and Huffman coding ............... 6 - 3.2.2. Use of Huffman coding in the "deflate" format ....... 7 - 3.2.3. Details of block format ............................. 9 - 3.2.4. Non-compressed blocks (BTYPE=00) ................... 11 - 3.2.5. Compressed blocks (length and distance codes) ...... 11 - 3.2.6. Compression with fixed Huffman codes (BTYPE=01) .... 12 - 3.2.7. Compression with dynamic Huffman codes (BTYPE=10) .. 13 - 3.3. Compliance ............................................... 14 - 4. Compression algorithm details ................................. 14 - 5. References .................................................... 16 - 6. Security Considerations ....................................... 16 - 7. Source code ................................................... 16 - 8. Acknowledgements .............................................. 16 - 9. Author's Address .............................................. 17 - -1. Introduction - - 1.1. Purpose - - The purpose of this specification is to define a lossless - compressed data format that: - * Is independent of CPU type, operating system, file system, - and character set, and hence can be used for interchange; - * Can be produced or consumed, even for an arbitrarily long - sequentially presented input data stream, using only an a - priori bounded amount of intermediate storage, and hence - can be used in data communications or similar structures - such as Unix filters; - * Compresses data with efficiency comparable to the best - currently available general-purpose compression methods, - and in particular considerably better than the "compress" - program; - * Can be implemented readily in a manner not covered by - patents, and hence can be practiced freely; - - - -Deutsch Informational [Page 2] - -RFC 1951 DEFLATE Compressed Data Format Specification May 1996 - - - * Is compatible with the file format produced by the current - widely used gzip utility, in that conforming decompressors - will be able to read data produced by the existing gzip - compressor. - - The data format defined by this specification does not attempt to: - - * Allow random access to compressed data; - * Compress specialized data (e.g., raster graphics) as well - as the best currently available specialized algorithms. - - A simple counting argument shows that no lossless compression - algorithm can compress every possible input data set. For the - format defined here, the worst case expansion is 5 bytes per 32K- - byte block, i.e., a size increase of 0.015% for large data sets. - English text usually compresses by a factor of 2.5 to 3; - executable files usually compress somewhat less; graphical data - such as raster images may compress much more. - - 1.2. Intended audience - - This specification is intended for use by implementors of software - to compress data into "deflate" format and/or decompress data from - "deflate" format. - - The text of the specification assumes a basic background in - programming at the level of bits and other primitive data - representations. Familiarity with the technique of Huffman coding - is helpful but not required. - - 1.3. Scope - - The specification specifies a method for representing a sequence - of bytes as a (usually shorter) sequence of bits, and a method for - packing the latter bit sequence into bytes. - - 1.4. Compliance - - Unless otherwise indicated below, a compliant decompressor must be - able to accept and decompress any data set that conforms to all - the specifications presented here; a compliant compressor must - produce data sets that conform to all the specifications presented - here. - - 1.5. Definitions of terms and conventions used - - Byte: 8 bits stored or transmitted as a unit (same as an octet). - For this specification, a byte is exactly 8 bits, even on machines - - - -Deutsch Informational [Page 3] - -RFC 1951 DEFLATE Compressed Data Format Specification May 1996 - - - which store a character on a number of bits different from eight. - See below, for the numbering of bits within a byte. - - String: a sequence of arbitrary bytes. - - 1.6. Changes from previous versions - - There have been no technical changes to the deflate format since - version 1.1 of this specification. In version 1.2, some - terminology was changed. Version 1.3 is a conversion of the - specification to RFC style. - -2. Compressed representation overview - - A compressed data set consists of a series of blocks, corresponding - to successive blocks of input data. The block sizes are arbitrary, - except that non-compressible blocks are limited to 65,535 bytes. - - Each block is compressed using a combination of the LZ77 algorithm - and Huffman coding. The Huffman trees for each block are independent - of those for previous or subsequent blocks; the LZ77 algorithm may - use a reference to a duplicated string occurring in a previous block, - up to 32K input bytes before. - - Each block consists of two parts: a pair of Huffman code trees that - describe the representation of the compressed data part, and a - compressed data part. (The Huffman trees themselves are compressed - using Huffman encoding.) The compressed data consists of a series of - elements of two types: literal bytes (of strings that have not been - detected as duplicated within the previous 32K input bytes), and - pointers to duplicated strings, where a pointer is represented as a - pair . The representation used in the - "deflate" format limits distances to 32K bytes and lengths to 258 - bytes, but does not limit the size of a block, except for - uncompressible blocks, which are limited as noted above. - - Each type of value (literals, distances, and lengths) in the - compressed data is represented using a Huffman code, using one code - tree for literals and lengths and a separate code tree for distances. - The code trees for each block appear in a compact form just before - the compressed data for that block. - - - - - - - - - - -Deutsch Informational [Page 4] - -RFC 1951 DEFLATE Compressed Data Format Specification May 1996 - - -3. Detailed specification - - 3.1. Overall conventions In the diagrams below, a box like this: - - +---+ - | | <-- the vertical bars might be missing - +---+ - - represents one byte; a box like this: - - +==============+ - | | - +==============+ - - represents a variable number of bytes. - - Bytes stored within a computer do not have a "bit order", since - they are always treated as a unit. However, a byte considered as - an integer between 0 and 255 does have a most- and least- - significant bit, and since we write numbers with the most- - significant digit on the left, we also write bytes with the most- - significant bit on the left. In the diagrams below, we number the - bits of a byte so that bit 0 is the least-significant bit, i.e., - the bits are numbered: - - +--------+ - |76543210| - +--------+ - - Within a computer, a number may occupy multiple bytes. All - multi-byte numbers in the format described here are stored with - the least-significant byte first (at the lower memory address). - For example, the decimal number 520 is stored as: - - 0 1 - +--------+--------+ - |00001000|00000010| - +--------+--------+ - ^ ^ - | | - | + more significant byte = 2 x 256 - + less significant byte = 8 - - 3.1.1. Packing into bytes - - This document does not address the issue of the order in which - bits of a byte are transmitted on a bit-sequential medium, - since the final data format described here is byte- rather than - - - -Deutsch Informational [Page 5] - -RFC 1951 DEFLATE Compressed Data Format Specification May 1996 - - - bit-oriented. However, we describe the compressed block format - in below, as a sequence of data elements of various bit - lengths, not a sequence of bytes. We must therefore specify - how to pack these data elements into bytes to form the final - compressed byte sequence: - - * Data elements are packed into bytes in order of - increasing bit number within the byte, i.e., starting - with the least-significant bit of the byte. - * Data elements other than Huffman codes are packed - starting with the least-significant bit of the data - element. - * Huffman codes are packed starting with the most- - significant bit of the code. - - In other words, if one were to print out the compressed data as - a sequence of bytes, starting with the first byte at the - *right* margin and proceeding to the *left*, with the most- - significant bit of each byte on the left as usual, one would be - able to parse the result from right to left, with fixed-width - elements in the correct MSB-to-LSB order and Huffman codes in - bit-reversed order (i.e., with the first bit of the code in the - relative LSB position). - - 3.2. Compressed block format - - 3.2.1. Synopsis of prefix and Huffman coding - - Prefix coding represents symbols from an a priori known - alphabet by bit sequences (codes), one code for each symbol, in - a manner such that different symbols may be represented by bit - sequences of different lengths, but a parser can always parse - an encoded string unambiguously symbol-by-symbol. - - We define a prefix code in terms of a binary tree in which the - two edges descending from each non-leaf node are labeled 0 and - 1 and in which the leaf nodes correspond one-for-one with (are - labeled with) the symbols of the alphabet; then the code for a - symbol is the sequence of 0's and 1's on the edges leading from - the root to the leaf labeled with that symbol. For example: - - - - - - - - - - - -Deutsch Informational [Page 6] - -RFC 1951 DEFLATE Compressed Data Format Specification May 1996 - - - /\ Symbol Code - 0 1 ------ ---- - / \ A 00 - /\ B B 1 - 0 1 C 011 - / \ D 010 - A /\ - 0 1 - / \ - D C - - A parser can decode the next symbol from an encoded input - stream by walking down the tree from the root, at each step - choosing the edge corresponding to the next input bit. - - Given an alphabet with known symbol frequencies, the Huffman - algorithm allows the construction of an optimal prefix code - (one which represents strings with those symbol frequencies - using the fewest bits of any possible prefix codes for that - alphabet). Such a code is called a Huffman code. (See - reference [1] in Chapter 5, references for additional - information on Huffman codes.) - - Note that in the "deflate" format, the Huffman codes for the - various alphabets must not exceed certain maximum code lengths. - This constraint complicates the algorithm for computing code - lengths from symbol frequencies. Again, see Chapter 5, - references for details. - - 3.2.2. Use of Huffman coding in the "deflate" format - - The Huffman codes used for each alphabet in the "deflate" - format have two additional rules: - - * All codes of a given bit length have lexicographically - consecutive values, in the same order as the symbols - they represent; - - * Shorter codes lexicographically precede longer codes. - - - - - - - - - - - - -Deutsch Informational [Page 7] - -RFC 1951 DEFLATE Compressed Data Format Specification May 1996 - - - We could recode the example above to follow this rule as - follows, assuming that the order of the alphabet is ABCD: - - Symbol Code - ------ ---- - A 10 - B 0 - C 110 - D 111 - - I.e., 0 precedes 10 which precedes 11x, and 110 and 111 are - lexicographically consecutive. - - Given this rule, we can define the Huffman code for an alphabet - just by giving the bit lengths of the codes for each symbol of - the alphabet in order; this is sufficient to determine the - actual codes. In our example, the code is completely defined - by the sequence of bit lengths (2, 1, 3, 3). The following - algorithm generates the codes as integers, intended to be read - from most- to least-significant bit. The code lengths are - initially in tree[I].Len; the codes are produced in - tree[I].Code. - - 1) Count the number of codes for each code length. Let - bl_count[N] be the number of codes of length N, N >= 1. - - 2) Find the numerical value of the smallest code for each - code length: - - code = 0; - bl_count[0] = 0; - for (bits = 1; bits <= MAX_BITS; bits++) { - code = (code + bl_count[bits-1]) << 1; - next_code[bits] = code; - } - - 3) Assign numerical values to all codes, using consecutive - values for all codes of the same length with the base - values determined at step 2. Codes that are never used - (which have a bit length of zero) must not be assigned a - value. - - for (n = 0; n <= max_code; n++) { - len = tree[n].Len; - if (len != 0) { - tree[n].Code = next_code[len]; - next_code[len]++; - } - - - -Deutsch Informational [Page 8] - -RFC 1951 DEFLATE Compressed Data Format Specification May 1996 - - - } - - Example: - - Consider the alphabet ABCDEFGH, with bit lengths (3, 3, 3, 3, - 3, 2, 4, 4). After step 1, we have: - - N bl_count[N] - - ----------- - 2 1 - 3 5 - 4 2 - - Step 2 computes the following next_code values: - - N next_code[N] - - ------------ - 1 0 - 2 0 - 3 2 - 4 14 - - Step 3 produces the following code values: - - Symbol Length Code - ------ ------ ---- - A 3 010 - B 3 011 - C 3 100 - D 3 101 - E 3 110 - F 2 00 - G 4 1110 - H 4 1111 - - 3.2.3. Details of block format - - Each block of compressed data begins with 3 header bits - containing the following data: - - first bit BFINAL - next 2 bits BTYPE - - Note that the header bits do not necessarily begin on a byte - boundary, since a block does not necessarily occupy an integral - number of bytes. - - - - - -Deutsch Informational [Page 9] - -RFC 1951 DEFLATE Compressed Data Format Specification May 1996 - - - BFINAL is set if and only if this is the last block of the data - set. - - BTYPE specifies how the data are compressed, as follows: - - 00 - no compression - 01 - compressed with fixed Huffman codes - 10 - compressed with dynamic Huffman codes - 11 - reserved (error) - - The only difference between the two compressed cases is how the - Huffman codes for the literal/length and distance alphabets are - defined. - - In all cases, the decoding algorithm for the actual data is as - follows: - - do - read block header from input stream. - if stored with no compression - skip any remaining bits in current partially - processed byte - read LEN and NLEN (see next section) - copy LEN bytes of data to output - otherwise - if compressed with dynamic Huffman codes - read representation of code trees (see - subsection below) - loop (until end of block code recognized) - decode literal/length value from input stream - if value < 256 - copy value (literal byte) to output stream - otherwise - if value = end of block (256) - break from loop - otherwise (value = 257..285) - decode distance from input stream - - move backwards distance bytes in the output - stream, and copy length bytes from this - position to the output stream. - end loop - while not last block - - Note that a duplicated string reference may refer to a string - in a previous block; i.e., the backward distance may cross one - or more block boundaries. However a distance cannot refer past - the beginning of the output stream. (An application using a - - - -Deutsch Informational [Page 10] - -RFC 1951 DEFLATE Compressed Data Format Specification May 1996 - - - preset dictionary might discard part of the output stream; a - distance can refer to that part of the output stream anyway) - Note also that the referenced string may overlap the current - position; for example, if the last 2 bytes decoded have values - X and Y, a string reference with - adds X,Y,X,Y,X to the output stream. - - We now specify each compression method in turn. - - 3.2.4. Non-compressed blocks (BTYPE=00) - - Any bits of input up to the next byte boundary are ignored. - The rest of the block consists of the following information: - - 0 1 2 3 4... - +---+---+---+---+================================+ - | LEN | NLEN |... LEN bytes of literal data...| - +---+---+---+---+================================+ - - LEN is the number of data bytes in the block. NLEN is the - one's complement of LEN. - - 3.2.5. Compressed blocks (length and distance codes) - - As noted above, encoded data blocks in the "deflate" format - consist of sequences of symbols drawn from three conceptually - distinct alphabets: either literal bytes, from the alphabet of - byte values (0..255), or pairs, - where the length is drawn from (3..258) and the distance is - drawn from (1..32,768). In fact, the literal and length - alphabets are merged into a single alphabet (0..285), where - values 0..255 represent literal bytes, the value 256 indicates - end-of-block, and values 257..285 represent length codes - (possibly in conjunction with extra bits following the symbol - code) as follows: - - - - - - - - - - - - - - - - -Deutsch Informational [Page 11] - -RFC 1951 DEFLATE Compressed Data Format Specification May 1996 - - - Extra Extra Extra - Code Bits Length(s) Code Bits Lengths Code Bits Length(s) - ---- ---- ------ ---- ---- ------- ---- ---- ------- - 257 0 3 267 1 15,16 277 4 67-82 - 258 0 4 268 1 17,18 278 4 83-98 - 259 0 5 269 2 19-22 279 4 99-114 - 260 0 6 270 2 23-26 280 4 115-130 - 261 0 7 271 2 27-30 281 5 131-162 - 262 0 8 272 2 31-34 282 5 163-194 - 263 0 9 273 3 35-42 283 5 195-226 - 264 0 10 274 3 43-50 284 5 227-257 - 265 1 11,12 275 3 51-58 285 0 258 - 266 1 13,14 276 3 59-66 - - The extra bits should be interpreted as a machine integer - stored with the most-significant bit first, e.g., bits 1110 - represent the value 14. - - Extra Extra Extra - Code Bits Dist Code Bits Dist Code Bits Distance - ---- ---- ---- ---- ---- ------ ---- ---- -------- - 0 0 1 10 4 33-48 20 9 1025-1536 - 1 0 2 11 4 49-64 21 9 1537-2048 - 2 0 3 12 5 65-96 22 10 2049-3072 - 3 0 4 13 5 97-128 23 10 3073-4096 - 4 1 5,6 14 6 129-192 24 11 4097-6144 - 5 1 7,8 15 6 193-256 25 11 6145-8192 - 6 2 9-12 16 7 257-384 26 12 8193-12288 - 7 2 13-16 17 7 385-512 27 12 12289-16384 - 8 3 17-24 18 8 513-768 28 13 16385-24576 - 9 3 25-32 19 8 769-1024 29 13 24577-32768 - - 3.2.6. Compression with fixed Huffman codes (BTYPE=01) - - The Huffman codes for the two alphabets are fixed, and are not - represented explicitly in the data. The Huffman code lengths - for the literal/length alphabet are: - - Lit Value Bits Codes - --------- ---- ----- - 0 - 143 8 00110000 through - 10111111 - 144 - 255 9 110010000 through - 111111111 - 256 - 279 7 0000000 through - 0010111 - 280 - 287 8 11000000 through - 11000111 - - - -Deutsch Informational [Page 12] - -RFC 1951 DEFLATE Compressed Data Format Specification May 1996 - - - The code lengths are sufficient to generate the actual codes, - as described above; we show the codes in the table for added - clarity. Literal/length values 286-287 will never actually - occur in the compressed data, but participate in the code - construction. - - Distance codes 0-31 are represented by (fixed-length) 5-bit - codes, with possible additional bits as shown in the table - shown in Paragraph 3.2.5, above. Note that distance codes 30- - 31 will never actually occur in the compressed data. - - 3.2.7. Compression with dynamic Huffman codes (BTYPE=10) - - The Huffman codes for the two alphabets appear in the block - immediately after the header bits and before the actual - compressed data, first the literal/length code and then the - distance code. Each code is defined by a sequence of code - lengths, as discussed in Paragraph 3.2.2, above. For even - greater compactness, the code length sequences themselves are - compressed using a Huffman code. The alphabet for code lengths - is as follows: - - 0 - 15: Represent code lengths of 0 - 15 - 16: Copy the previous code length 3 - 6 times. - The next 2 bits indicate repeat length - (0 = 3, ... , 3 = 6) - Example: Codes 8, 16 (+2 bits 11), - 16 (+2 bits 10) will expand to - 12 code lengths of 8 (1 + 6 + 5) - 17: Repeat a code length of 0 for 3 - 10 times. - (3 bits of length) - 18: Repeat a code length of 0 for 11 - 138 times - (7 bits of length) - - A code length of 0 indicates that the corresponding symbol in - the literal/length or distance alphabet will not occur in the - block, and should not participate in the Huffman code - construction algorithm given earlier. If only one distance - code is used, it is encoded using one bit, not zero bits; in - this case there is a single code length of one, with one unused - code. One distance code of zero bits means that there are no - distance codes used at all (the data is all literals). - - We can now define the format of the block: - - 5 Bits: HLIT, # of Literal/Length codes - 257 (257 - 286) - 5 Bits: HDIST, # of Distance codes - 1 (1 - 32) - 4 Bits: HCLEN, # of Code Length codes - 4 (4 - 19) - - - -Deutsch Informational [Page 13] - -RFC 1951 DEFLATE Compressed Data Format Specification May 1996 - - - (HCLEN + 4) x 3 bits: code lengths for the code length - alphabet given just above, in the order: 16, 17, 18, - 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 - - These code lengths are interpreted as 3-bit integers - (0-7); as above, a code length of 0 means the - corresponding symbol (literal/length or distance code - length) is not used. - - HLIT + 257 code lengths for the literal/length alphabet, - encoded using the code length Huffman code - - HDIST + 1 code lengths for the distance alphabet, - encoded using the code length Huffman code - - The actual compressed data of the block, - encoded using the literal/length and distance Huffman - codes - - The literal/length symbol 256 (end of data), - encoded using the literal/length Huffman code - - The code length repeat codes can cross from HLIT + 257 to the - HDIST + 1 code lengths. In other words, all code lengths form - a single sequence of HLIT + HDIST + 258 values. - - 3.3. Compliance - - A compressor may limit further the ranges of values specified in - the previous section and still be compliant; for example, it may - limit the range of backward pointers to some value smaller than - 32K. Similarly, a compressor may limit the size of blocks so that - a compressible block fits in memory. - - A compliant decompressor must accept the full range of possible - values defined in the previous section, and must accept blocks of - arbitrary size. - -4. Compression algorithm details - - While it is the intent of this document to define the "deflate" - compressed data format without reference to any particular - compression algorithm, the format is related to the compressed - formats produced by LZ77 (Lempel-Ziv 1977, see reference [2] below); - since many variations of LZ77 are patented, it is strongly - recommended that the implementor of a compressor follow the general - algorithm presented here, which is known not to be patented per se. - The material in this section is not part of the definition of the - - - -Deutsch Informational [Page 14] - -RFC 1951 DEFLATE Compressed Data Format Specification May 1996 - - - specification per se, and a compressor need not follow it in order to - be compliant. - - The compressor terminates a block when it determines that starting a - new block with fresh trees would be useful, or when the block size - fills up the compressor's block buffer. - - The compressor uses a chained hash table to find duplicated strings, - using a hash function that operates on 3-byte sequences. At any - given point during compression, let XYZ be the next 3 input bytes to - be examined (not necessarily all different, of course). First, the - compressor examines the hash chain for XYZ. If the chain is empty, - the compressor simply writes out X as a literal byte and advances one - byte in the input. If the hash chain is not empty, indicating that - the sequence XYZ (or, if we are unlucky, some other 3 bytes with the - same hash function value) has occurred recently, the compressor - compares all strings on the XYZ hash chain with the actual input data - sequence starting at the current point, and selects the longest - match. - - The compressor searches the hash chains starting with the most recent - strings, to favor small distances and thus take advantage of the - Huffman encoding. The hash chains are singly linked. There are no - deletions from the hash chains; the algorithm simply discards matches - that are too old. To avoid a worst-case situation, very long hash - chains are arbitrarily truncated at a certain length, determined by a - run-time parameter. - - To improve overall compression, the compressor optionally defers the - selection of matches ("lazy matching"): after a match of length N has - been found, the compressor searches for a longer match starting at - the next input byte. If it finds a longer match, it truncates the - previous match to a length of one (thus producing a single literal - byte) and then emits the longer match. Otherwise, it emits the - original match, and, as described above, advances N bytes before - continuing. - - Run-time parameters also control this "lazy match" procedure. If - compression ratio is most important, the compressor attempts a - complete second search regardless of the length of the first match. - In the normal case, if the current match is "long enough", the - compressor reduces the search for a longer match, thus speeding up - the process. If speed is most important, the compressor inserts new - strings in the hash table only when no match was found, or when the - match is not "too long". This degrades the compression ratio but - saves time since there are both fewer insertions and fewer searches. - - - - - -Deutsch Informational [Page 15] - -RFC 1951 DEFLATE Compressed Data Format Specification May 1996 - - -5. References - - [1] Huffman, D. A., "A Method for the Construction of Minimum - Redundancy Codes", Proceedings of the Institute of Radio - Engineers, September 1952, Volume 40, Number 9, pp. 1098-1101. - - [2] Ziv J., Lempel A., "A Universal Algorithm for Sequential Data - Compression", IEEE Transactions on Information Theory, Vol. 23, - No. 3, pp. 337-343. - - [3] Gailly, J.-L., and Adler, M., ZLIB documentation and sources, - available in ftp://ftp.uu.net/pub/archiving/zip/doc/ - - [4] Gailly, J.-L., and Adler, M., GZIP documentation and sources, - available as gzip-*.tar in ftp://prep.ai.mit.edu/pub/gnu/ - - [5] Schwartz, E. S., and Kallick, B. "Generating a canonical prefix - encoding." Comm. ACM, 7,3 (Mar. 1964), pp. 166-169. - - [6] Hirschberg and Lelewer, "Efficient decoding of prefix codes," - Comm. ACM, 33,4, April 1990, pp. 449-459. - -6. Security Considerations - - Any data compression method involves the reduction of redundancy in - the data. Consequently, any corruption of the data is likely to have - severe effects and be difficult to correct. Uncompressed text, on - the other hand, will probably still be readable despite the presence - of some corrupted bytes. - - It is recommended that systems using this data format provide some - means of validating the integrity of the compressed data. See - reference [3], for example. - -7. Source code - - Source code for a C language implementation of a "deflate" compliant - compressor and decompressor is available within the zlib package at - ftp://ftp.uu.net/pub/archiving/zip/zlib/. - -8. Acknowledgements - - Trademarks cited in this document are the property of their - respective owners. - - Phil Katz designed the deflate format. Jean-Loup Gailly and Mark - Adler wrote the related software described in this specification. - Glenn Randers-Pehrson converted this document to RFC and HTML format. - - - -Deutsch Informational [Page 16] - -RFC 1951 DEFLATE Compressed Data Format Specification May 1996 - - -9. Author's Address - - L. Peter Deutsch - Aladdin Enterprises - 203 Santa Margarita Ave. - Menlo Park, CA 94025 - - Phone: (415) 322-0103 (AM only) - FAX: (415) 322-1734 - EMail: - - Questions about the technical content of this specification can be - sent by email to: - - Jean-Loup Gailly and - Mark Adler - - Editorial comments on this specification can be sent by email to: - - L. Peter Deutsch and - Glenn Randers-Pehrson - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Deutsch Informational [Page 17] - diff --git a/src/beast/test/zlib/zlib-1.2.8/doc/rfc1952.txt b/src/beast/test/zlib/zlib-1.2.8/doc/rfc1952.txt deleted file mode 100644 index a8e51b4567f..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/doc/rfc1952.txt +++ /dev/null @@ -1,675 +0,0 @@ - - - - - - -Network Working Group P. Deutsch -Request for Comments: 1952 Aladdin Enterprises -Category: Informational May 1996 - - - GZIP file format specification version 4.3 - -Status of This Memo - - This memo provides information for the Internet community. This memo - does not specify an Internet standard of any kind. Distribution of - this memo is unlimited. - -IESG Note: - - The IESG takes no position on the validity of any Intellectual - Property Rights statements contained in this document. - -Notices - - Copyright (c) 1996 L. Peter Deutsch - - Permission is granted to copy and distribute this document for any - purpose and without charge, including translations into other - languages and incorporation into compilations, provided that the - copyright notice and this notice are preserved, and that any - substantive changes or deletions from the original are clearly - marked. - - A pointer to the latest version of this and related documentation in - HTML format can be found at the URL - . - -Abstract - - This specification defines a lossless compressed data format that is - compatible with the widely used GZIP utility. The format includes a - cyclic redundancy check value for detecting data corruption. The - format presently uses the DEFLATE method of compression but can be - easily extended to use other compression methods. The format can be - implemented readily in a manner not covered by patents. - - - - - - - - - - -Deutsch Informational [Page 1] - -RFC 1952 GZIP File Format Specification May 1996 - - -Table of Contents - - 1. Introduction ................................................... 2 - 1.1. Purpose ................................................... 2 - 1.2. Intended audience ......................................... 3 - 1.3. Scope ..................................................... 3 - 1.4. Compliance ................................................ 3 - 1.5. Definitions of terms and conventions used ................. 3 - 1.6. Changes from previous versions ............................ 3 - 2. Detailed specification ......................................... 4 - 2.1. Overall conventions ....................................... 4 - 2.2. File format ............................................... 5 - 2.3. Member format ............................................. 5 - 2.3.1. Member header and trailer ........................... 6 - 2.3.1.1. Extra field ................................... 8 - 2.3.1.2. Compliance .................................... 9 - 3. References .................................................. 9 - 4. Security Considerations .................................... 10 - 5. Acknowledgements ........................................... 10 - 6. Author's Address ........................................... 10 - 7. Appendix: Jean-Loup Gailly's gzip utility .................. 11 - 8. Appendix: Sample CRC Code .................................. 11 - -1. Introduction - - 1.1. Purpose - - The purpose of this specification is to define a lossless - compressed data format that: - - * Is independent of CPU type, operating system, file system, - and character set, and hence can be used for interchange; - * Can compress or decompress a data stream (as opposed to a - randomly accessible file) to produce another data stream, - using only an a priori bounded amount of intermediate - storage, and hence can be used in data communications or - similar structures such as Unix filters; - * Compresses data with efficiency comparable to the best - currently available general-purpose compression methods, - and in particular considerably better than the "compress" - program; - * Can be implemented readily in a manner not covered by - patents, and hence can be practiced freely; - * Is compatible with the file format produced by the current - widely used gzip utility, in that conforming decompressors - will be able to read data produced by the existing gzip - compressor. - - - - -Deutsch Informational [Page 2] - -RFC 1952 GZIP File Format Specification May 1996 - - - The data format defined by this specification does not attempt to: - - * Provide random access to compressed data; - * Compress specialized data (e.g., raster graphics) as well as - the best currently available specialized algorithms. - - 1.2. Intended audience - - This specification is intended for use by implementors of software - to compress data into gzip format and/or decompress data from gzip - format. - - The text of the specification assumes a basic background in - programming at the level of bits and other primitive data - representations. - - 1.3. Scope - - The specification specifies a compression method and a file format - (the latter assuming only that a file can store a sequence of - arbitrary bytes). It does not specify any particular interface to - a file system or anything about character sets or encodings - (except for file names and comments, which are optional). - - 1.4. Compliance - - Unless otherwise indicated below, a compliant decompressor must be - able to accept and decompress any file that conforms to all the - specifications presented here; a compliant compressor must produce - files that conform to all the specifications presented here. The - material in the appendices is not part of the specification per se - and is not relevant to compliance. - - 1.5. Definitions of terms and conventions used - - byte: 8 bits stored or transmitted as a unit (same as an octet). - (For this specification, a byte is exactly 8 bits, even on - machines which store a character on a number of bits different - from 8.) See below for the numbering of bits within a byte. - - 1.6. Changes from previous versions - - There have been no technical changes to the gzip format since - version 4.1 of this specification. In version 4.2, some - terminology was changed, and the sample CRC code was rewritten for - clarity and to eliminate the requirement for the caller to do pre- - and post-conditioning. Version 4.3 is a conversion of the - specification to RFC style. - - - -Deutsch Informational [Page 3] - -RFC 1952 GZIP File Format Specification May 1996 - - -2. Detailed specification - - 2.1. Overall conventions - - In the diagrams below, a box like this: - - +---+ - | | <-- the vertical bars might be missing - +---+ - - represents one byte; a box like this: - - +==============+ - | | - +==============+ - - represents a variable number of bytes. - - Bytes stored within a computer do not have a "bit order", since - they are always treated as a unit. However, a byte considered as - an integer between 0 and 255 does have a most- and least- - significant bit, and since we write numbers with the most- - significant digit on the left, we also write bytes with the most- - significant bit on the left. In the diagrams below, we number the - bits of a byte so that bit 0 is the least-significant bit, i.e., - the bits are numbered: - - +--------+ - |76543210| - +--------+ - - This document does not address the issue of the order in which - bits of a byte are transmitted on a bit-sequential medium, since - the data format described here is byte- rather than bit-oriented. - - Within a computer, a number may occupy multiple bytes. All - multi-byte numbers in the format described here are stored with - the least-significant byte first (at the lower memory address). - For example, the decimal number 520 is stored as: - - 0 1 - +--------+--------+ - |00001000|00000010| - +--------+--------+ - ^ ^ - | | - | + more significant byte = 2 x 256 - + less significant byte = 8 - - - -Deutsch Informational [Page 4] - -RFC 1952 GZIP File Format Specification May 1996 - - - 2.2. File format - - A gzip file consists of a series of "members" (compressed data - sets). The format of each member is specified in the following - section. The members simply appear one after another in the file, - with no additional information before, between, or after them. - - 2.3. Member format - - Each member has the following structure: - - +---+---+---+---+---+---+---+---+---+---+ - |ID1|ID2|CM |FLG| MTIME |XFL|OS | (more-->) - +---+---+---+---+---+---+---+---+---+---+ - - (if FLG.FEXTRA set) - - +---+---+=================================+ - | XLEN |...XLEN bytes of "extra field"...| (more-->) - +---+---+=================================+ - - (if FLG.FNAME set) - - +=========================================+ - |...original file name, zero-terminated...| (more-->) - +=========================================+ - - (if FLG.FCOMMENT set) - - +===================================+ - |...file comment, zero-terminated...| (more-->) - +===================================+ - - (if FLG.FHCRC set) - - +---+---+ - | CRC16 | - +---+---+ - - +=======================+ - |...compressed blocks...| (more-->) - +=======================+ - - 0 1 2 3 4 5 6 7 - +---+---+---+---+---+---+---+---+ - | CRC32 | ISIZE | - +---+---+---+---+---+---+---+---+ - - - - -Deutsch Informational [Page 5] - -RFC 1952 GZIP File Format Specification May 1996 - - - 2.3.1. Member header and trailer - - ID1 (IDentification 1) - ID2 (IDentification 2) - These have the fixed values ID1 = 31 (0x1f, \037), ID2 = 139 - (0x8b, \213), to identify the file as being in gzip format. - - CM (Compression Method) - This identifies the compression method used in the file. CM - = 0-7 are reserved. CM = 8 denotes the "deflate" - compression method, which is the one customarily used by - gzip and which is documented elsewhere. - - FLG (FLaGs) - This flag byte is divided into individual bits as follows: - - bit 0 FTEXT - bit 1 FHCRC - bit 2 FEXTRA - bit 3 FNAME - bit 4 FCOMMENT - bit 5 reserved - bit 6 reserved - bit 7 reserved - - If FTEXT is set, the file is probably ASCII text. This is - an optional indication, which the compressor may set by - checking a small amount of the input data to see whether any - non-ASCII characters are present. In case of doubt, FTEXT - is cleared, indicating binary data. For systems which have - different file formats for ascii text and binary data, the - decompressor can use FTEXT to choose the appropriate format. - We deliberately do not specify the algorithm used to set - this bit, since a compressor always has the option of - leaving it cleared and a decompressor always has the option - of ignoring it and letting some other program handle issues - of data conversion. - - If FHCRC is set, a CRC16 for the gzip header is present, - immediately before the compressed data. The CRC16 consists - of the two least significant bytes of the CRC32 for all - bytes of the gzip header up to and not including the CRC16. - [The FHCRC bit was never set by versions of gzip up to - 1.2.4, even though it was documented with a different - meaning in gzip 1.2.4.] - - If FEXTRA is set, optional extra fields are present, as - described in a following section. - - - -Deutsch Informational [Page 6] - -RFC 1952 GZIP File Format Specification May 1996 - - - If FNAME is set, an original file name is present, - terminated by a zero byte. The name must consist of ISO - 8859-1 (LATIN-1) characters; on operating systems using - EBCDIC or any other character set for file names, the name - must be translated to the ISO LATIN-1 character set. This - is the original name of the file being compressed, with any - directory components removed, and, if the file being - compressed is on a file system with case insensitive names, - forced to lower case. There is no original file name if the - data was compressed from a source other than a named file; - for example, if the source was stdin on a Unix system, there - is no file name. - - If FCOMMENT is set, a zero-terminated file comment is - present. This comment is not interpreted; it is only - intended for human consumption. The comment must consist of - ISO 8859-1 (LATIN-1) characters. Line breaks should be - denoted by a single line feed character (10 decimal). - - Reserved FLG bits must be zero. - - MTIME (Modification TIME) - This gives the most recent modification time of the original - file being compressed. The time is in Unix format, i.e., - seconds since 00:00:00 GMT, Jan. 1, 1970. (Note that this - may cause problems for MS-DOS and other systems that use - local rather than Universal time.) If the compressed data - did not come from a file, MTIME is set to the time at which - compression started. MTIME = 0 means no time stamp is - available. - - XFL (eXtra FLags) - These flags are available for use by specific compression - methods. The "deflate" method (CM = 8) sets these flags as - follows: - - XFL = 2 - compressor used maximum compression, - slowest algorithm - XFL = 4 - compressor used fastest algorithm - - OS (Operating System) - This identifies the type of file system on which compression - took place. This may be useful in determining end-of-line - convention for text files. The currently defined values are - as follows: - - - - - - -Deutsch Informational [Page 7] - -RFC 1952 GZIP File Format Specification May 1996 - - - 0 - FAT filesystem (MS-DOS, OS/2, NT/Win32) - 1 - Amiga - 2 - VMS (or OpenVMS) - 3 - Unix - 4 - VM/CMS - 5 - Atari TOS - 6 - HPFS filesystem (OS/2, NT) - 7 - Macintosh - 8 - Z-System - 9 - CP/M - 10 - TOPS-20 - 11 - NTFS filesystem (NT) - 12 - QDOS - 13 - Acorn RISCOS - 255 - unknown - - XLEN (eXtra LENgth) - If FLG.FEXTRA is set, this gives the length of the optional - extra field. See below for details. - - CRC32 (CRC-32) - This contains a Cyclic Redundancy Check value of the - uncompressed data computed according to CRC-32 algorithm - used in the ISO 3309 standard and in section 8.1.1.6.2 of - ITU-T recommendation V.42. (See http://www.iso.ch for - ordering ISO documents. See gopher://info.itu.ch for an - online version of ITU-T V.42.) - - ISIZE (Input SIZE) - This contains the size of the original (uncompressed) input - data modulo 2^32. - - 2.3.1.1. Extra field - - If the FLG.FEXTRA bit is set, an "extra field" is present in - the header, with total length XLEN bytes. It consists of a - series of subfields, each of the form: - - +---+---+---+---+==================================+ - |SI1|SI2| LEN |... LEN bytes of subfield data ...| - +---+---+---+---+==================================+ - - SI1 and SI2 provide a subfield ID, typically two ASCII letters - with some mnemonic value. Jean-Loup Gailly - is maintaining a registry of subfield - IDs; please send him any subfield ID you wish to use. Subfield - IDs with SI2 = 0 are reserved for future use. The following - IDs are currently defined: - - - -Deutsch Informational [Page 8] - -RFC 1952 GZIP File Format Specification May 1996 - - - SI1 SI2 Data - ---------- ---------- ---- - 0x41 ('A') 0x70 ('P') Apollo file type information - - LEN gives the length of the subfield data, excluding the 4 - initial bytes. - - 2.3.1.2. Compliance - - A compliant compressor must produce files with correct ID1, - ID2, CM, CRC32, and ISIZE, but may set all the other fields in - the fixed-length part of the header to default values (255 for - OS, 0 for all others). The compressor must set all reserved - bits to zero. - - A compliant decompressor must check ID1, ID2, and CM, and - provide an error indication if any of these have incorrect - values. It must examine FEXTRA/XLEN, FNAME, FCOMMENT and FHCRC - at least so it can skip over the optional fields if they are - present. It need not examine any other part of the header or - trailer; in particular, a decompressor may ignore FTEXT and OS - and always produce binary output, and still be compliant. A - compliant decompressor must give an error indication if any - reserved bit is non-zero, since such a bit could indicate the - presence of a new field that would cause subsequent data to be - interpreted incorrectly. - -3. References - - [1] "Information Processing - 8-bit single-byte coded graphic - character sets - Part 1: Latin alphabet No.1" (ISO 8859-1:1987). - The ISO 8859-1 (Latin-1) character set is a superset of 7-bit - ASCII. Files defining this character set are available as - iso_8859-1.* in ftp://ftp.uu.net/graphics/png/documents/ - - [2] ISO 3309 - - [3] ITU-T recommendation V.42 - - [4] Deutsch, L.P.,"DEFLATE Compressed Data Format Specification", - available in ftp://ftp.uu.net/pub/archiving/zip/doc/ - - [5] Gailly, J.-L., GZIP documentation, available as gzip-*.tar in - ftp://prep.ai.mit.edu/pub/gnu/ - - [6] Sarwate, D.V., "Computation of Cyclic Redundancy Checks via Table - Look-Up", Communications of the ACM, 31(8), pp.1008-1013. - - - - -Deutsch Informational [Page 9] - -RFC 1952 GZIP File Format Specification May 1996 - - - [7] Schwaderer, W.D., "CRC Calculation", April 85 PC Tech Journal, - pp.118-133. - - [8] ftp://ftp.adelaide.edu.au/pub/rocksoft/papers/crc_v3.txt, - describing the CRC concept. - -4. Security Considerations - - Any data compression method involves the reduction of redundancy in - the data. Consequently, any corruption of the data is likely to have - severe effects and be difficult to correct. Uncompressed text, on - the other hand, will probably still be readable despite the presence - of some corrupted bytes. - - It is recommended that systems using this data format provide some - means of validating the integrity of the compressed data, such as by - setting and checking the CRC-32 check value. - -5. Acknowledgements - - Trademarks cited in this document are the property of their - respective owners. - - Jean-Loup Gailly designed the gzip format and wrote, with Mark Adler, - the related software described in this specification. Glenn - Randers-Pehrson converted this document to RFC and HTML format. - -6. Author's Address - - L. Peter Deutsch - Aladdin Enterprises - 203 Santa Margarita Ave. - Menlo Park, CA 94025 - - Phone: (415) 322-0103 (AM only) - FAX: (415) 322-1734 - EMail: - - Questions about the technical content of this specification can be - sent by email to: - - Jean-Loup Gailly and - Mark Adler - - Editorial comments on this specification can be sent by email to: - - L. Peter Deutsch and - Glenn Randers-Pehrson - - - -Deutsch Informational [Page 10] - -RFC 1952 GZIP File Format Specification May 1996 - - -7. Appendix: Jean-Loup Gailly's gzip utility - - The most widely used implementation of gzip compression, and the - original documentation on which this specification is based, were - created by Jean-Loup Gailly . Since this - implementation is a de facto standard, we mention some more of its - features here. Again, the material in this section is not part of - the specification per se, and implementations need not follow it to - be compliant. - - When compressing or decompressing a file, gzip preserves the - protection, ownership, and modification time attributes on the local - file system, since there is no provision for representing protection - attributes in the gzip file format itself. Since the file format - includes a modification time, the gzip decompressor provides a - command line switch that assigns the modification time from the file, - rather than the local modification time of the compressed input, to - the decompressed output. - -8. Appendix: Sample CRC Code - - The following sample code represents a practical implementation of - the CRC (Cyclic Redundancy Check). (See also ISO 3309 and ITU-T V.42 - for a formal specification.) - - The sample code is in the ANSI C programming language. Non C users - may find it easier to read with these hints: - - & Bitwise AND operator. - ^ Bitwise exclusive-OR operator. - >> Bitwise right shift operator. When applied to an - unsigned quantity, as here, right shift inserts zero - bit(s) at the left. - ! Logical NOT operator. - ++ "n++" increments the variable n. - 0xNNN 0x introduces a hexadecimal (base 16) constant. - Suffix L indicates a long value (at least 32 bits). - - /* Table of CRCs of all 8-bit messages. */ - unsigned long crc_table[256]; - - /* Flag: has the table been computed? Initially false. */ - int crc_table_computed = 0; - - /* Make the table for a fast CRC. */ - void make_crc_table(void) - { - unsigned long c; - - - -Deutsch Informational [Page 11] - -RFC 1952 GZIP File Format Specification May 1996 - - - int n, k; - for (n = 0; n < 256; n++) { - c = (unsigned long) n; - for (k = 0; k < 8; k++) { - if (c & 1) { - c = 0xedb88320L ^ (c >> 1); - } else { - c = c >> 1; - } - } - crc_table[n] = c; - } - crc_table_computed = 1; - } - - /* - Update a running crc with the bytes buf[0..len-1] and return - the updated crc. The crc should be initialized to zero. Pre- and - post-conditioning (one's complement) is performed within this - function so it shouldn't be done by the caller. Usage example: - - unsigned long crc = 0L; - - while (read_buffer(buffer, length) != EOF) { - crc = update_crc(crc, buffer, length); - } - if (crc != original_crc) error(); - */ - unsigned long update_crc(unsigned long crc, - unsigned char *buf, int len) - { - unsigned long c = crc ^ 0xffffffffL; - int n; - - if (!crc_table_computed) - make_crc_table(); - for (n = 0; n < len; n++) { - c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8); - } - return c ^ 0xffffffffL; - } - - /* Return the CRC of the bytes buf[0..len-1]. */ - unsigned long crc(unsigned char *buf, int len) - { - return update_crc(0L, buf, len); - } - - - - -Deutsch Informational [Page 12] - diff --git a/src/beast/test/zlib/zlib-1.2.8/doc/txtvsbin.txt b/src/beast/test/zlib/zlib-1.2.8/doc/txtvsbin.txt deleted file mode 100644 index 3d0f0634f72..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/doc/txtvsbin.txt +++ /dev/null @@ -1,107 +0,0 @@ -A Fast Method for Identifying Plain Text Files -============================================== - - -Introduction ------------- - -Given a file coming from an unknown source, it is sometimes desirable -to find out whether the format of that file is plain text. Although -this may appear like a simple task, a fully accurate detection of the -file type requires heavy-duty semantic analysis on the file contents. -It is, however, possible to obtain satisfactory results by employing -various heuristics. - -Previous versions of PKZip and other zip-compatible compression tools -were using a crude detection scheme: if more than 80% (4/5) of the bytes -found in a certain buffer are within the range [7..127], the file is -labeled as plain text, otherwise it is labeled as binary. A prominent -limitation of this scheme is the restriction to Latin-based alphabets. -Other alphabets, like Greek, Cyrillic or Asian, make extensive use of -the bytes within the range [128..255], and texts using these alphabets -are most often misidentified by this scheme; in other words, the rate -of false negatives is sometimes too high, which means that the recall -is low. Another weakness of this scheme is a reduced precision, due to -the false positives that may occur when binary files containing large -amounts of textual characters are misidentified as plain text. - -In this article we propose a new, simple detection scheme that features -a much increased precision and a near-100% recall. This scheme is -designed to work on ASCII, Unicode and other ASCII-derived alphabets, -and it handles single-byte encodings (ISO-8859, MacRoman, KOI8, etc.) -and variable-sized encodings (ISO-2022, UTF-8, etc.). Wider encodings -(UCS-2/UTF-16 and UCS-4/UTF-32) are not handled, however. - - -The Algorithm -------------- - -The algorithm works by dividing the set of bytecodes [0..255] into three -categories: -- The white list of textual bytecodes: - 9 (TAB), 10 (LF), 13 (CR), 32 (SPACE) to 255. -- The gray list of tolerated bytecodes: - 7 (BEL), 8 (BS), 11 (VT), 12 (FF), 26 (SUB), 27 (ESC). -- The black list of undesired, non-textual bytecodes: - 0 (NUL) to 6, 14 to 31. - -If a file contains at least one byte that belongs to the white list and -no byte that belongs to the black list, then the file is categorized as -plain text; otherwise, it is categorized as binary. (The boundary case, -when the file is empty, automatically falls into the latter category.) - - -Rationale ---------- - -The idea behind this algorithm relies on two observations. - -The first observation is that, although the full range of 7-bit codes -[0..127] is properly specified by the ASCII standard, most control -characters in the range [0..31] are not used in practice. The only -widely-used, almost universally-portable control codes are 9 (TAB), -10 (LF) and 13 (CR). There are a few more control codes that are -recognized on a reduced range of platforms and text viewers/editors: -7 (BEL), 8 (BS), 11 (VT), 12 (FF), 26 (SUB) and 27 (ESC); but these -codes are rarely (if ever) used alone, without being accompanied by -some printable text. Even the newer, portable text formats such as -XML avoid using control characters outside the list mentioned here. - -The second observation is that most of the binary files tend to contain -control characters, especially 0 (NUL). Even though the older text -detection schemes observe the presence of non-ASCII codes from the range -[128..255], the precision rarely has to suffer if this upper range is -labeled as textual, because the files that are genuinely binary tend to -contain both control characters and codes from the upper range. On the -other hand, the upper range needs to be labeled as textual, because it -is used by virtually all ASCII extensions. In particular, this range is -used for encoding non-Latin scripts. - -Since there is no counting involved, other than simply observing the -presence or the absence of some byte values, the algorithm produces -consistent results, regardless what alphabet encoding is being used. -(If counting were involved, it could be possible to obtain different -results on a text encoded, say, using ISO-8859-16 versus UTF-8.) - -There is an extra category of plain text files that are "polluted" with -one or more black-listed codes, either by mistake or by peculiar design -considerations. In such cases, a scheme that tolerates a small fraction -of black-listed codes would provide an increased recall (i.e. more true -positives). This, however, incurs a reduced precision overall, since -false positives are more likely to appear in binary files that contain -large chunks of textual data. Furthermore, "polluted" plain text should -be regarded as binary by general-purpose text detection schemes, because -general-purpose text processing algorithms might not be applicable. -Under this premise, it is safe to say that our detection method provides -a near-100% recall. - -Experiments have been run on many files coming from various platforms -and applications. We tried plain text files, system logs, source code, -formatted office documents, compiled object code, etc. The results -confirm the optimistic assumptions about the capabilities of this -algorithm. - - --- -Cosmin Truta -Last updated: 2006-May-28 diff --git a/src/beast/test/zlib/zlib-1.2.8/examples/README.examples b/src/beast/test/zlib/zlib-1.2.8/examples/README.examples deleted file mode 100644 index 56a31714e56..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/examples/README.examples +++ /dev/null @@ -1,49 +0,0 @@ -This directory contains examples of the use of zlib and other relevant -programs and documentation. - -enough.c - calculation and justification of ENOUGH parameter in inftrees.h - - calculates the maximum table space used in inflate tree - construction over all possible Huffman codes - -fitblk.c - compress just enough input to nearly fill a requested output size - - zlib isn't designed to do this, but fitblk does it anyway - -gun.c - uncompress a gzip file - - illustrates the use of inflateBack() for high speed file-to-file - decompression using call-back functions - - is approximately twice as fast as gzip -d - - also provides Unix uncompress functionality, again twice as fast - -gzappend.c - append to a gzip file - - illustrates the use of the Z_BLOCK flush parameter for inflate() - - illustrates the use of deflatePrime() to start at any bit - -gzjoin.c - join gzip files without recalculating the crc or recompressing - - illustrates the use of the Z_BLOCK flush parameter for inflate() - - illustrates the use of crc32_combine() - -gzlog.c -gzlog.h - efficiently and robustly maintain a message log file in gzip format - - illustrates use of raw deflate, Z_PARTIAL_FLUSH, deflatePrime(), - and deflateSetDictionary() - - illustrates use of a gzip header extra field - -zlib_how.html - painfully comprehensive description of zpipe.c (see below) - - describes in excruciating detail the use of deflate() and inflate() - -zpipe.c - reads and writes zlib streams from stdin to stdout - - illustrates the proper use of deflate() and inflate() - - deeply commented in zlib_how.html (see above) - -zran.c - index a zlib or gzip stream and randomly access it - - illustrates the use of Z_BLOCK, inflatePrime(), and - inflateSetDictionary() to provide random access diff --git a/src/beast/test/zlib/zlib-1.2.8/examples/enough.c b/src/beast/test/zlib/zlib-1.2.8/examples/enough.c deleted file mode 100644 index b9911443052..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/examples/enough.c +++ /dev/null @@ -1,572 +0,0 @@ -/* enough.c -- determine the maximum size of inflate's Huffman code tables over - * all possible valid and complete Huffman codes, subject to a length limit. - * Copyright (C) 2007, 2008, 2012 Mark Adler - * Version 1.4 18 August 2012 Mark Adler - */ - -/* Version history: - 1.0 3 Jan 2007 First version (derived from codecount.c version 1.4) - 1.1 4 Jan 2007 Use faster incremental table usage computation - Prune examine() search on previously visited states - 1.2 5 Jan 2007 Comments clean up - As inflate does, decrease root for short codes - Refuse cases where inflate would increase root - 1.3 17 Feb 2008 Add argument for initial root table size - Fix bug for initial root table size == max - 1 - Use a macro to compute the history index - 1.4 18 Aug 2012 Avoid shifts more than bits in type (caused endless loop!) - Clean up comparisons of different types - Clean up code indentation - */ - -/* - Examine all possible Huffman codes for a given number of symbols and a - maximum code length in bits to determine the maximum table size for zilb's - inflate. Only complete Huffman codes are counted. - - Two codes are considered distinct if the vectors of the number of codes per - length are not identical. So permutations of the symbol assignments result - in the same code for the counting, as do permutations of the assignments of - the bit values to the codes (i.e. only canonical codes are counted). - - We build a code from shorter to longer lengths, determining how many symbols - are coded at each length. At each step, we have how many symbols remain to - be coded, what the last code length used was, and how many bit patterns of - that length remain unused. Then we add one to the code length and double the - number of unused patterns to graduate to the next code length. We then - assign all portions of the remaining symbols to that code length that - preserve the properties of a correct and eventually complete code. Those - properties are: we cannot use more bit patterns than are available; and when - all the symbols are used, there are exactly zero possible bit patterns - remaining. - - The inflate Huffman decoding algorithm uses two-level lookup tables for - speed. There is a single first-level table to decode codes up to root bits - in length (root == 9 in the current inflate implementation). The table - has 1 << root entries and is indexed by the next root bits of input. Codes - shorter than root bits have replicated table entries, so that the correct - entry is pointed to regardless of the bits that follow the short code. If - the code is longer than root bits, then the table entry points to a second- - level table. The size of that table is determined by the longest code with - that root-bit prefix. If that longest code has length len, then the table - has size 1 << (len - root), to index the remaining bits in that set of - codes. Each subsequent root-bit prefix then has its own sub-table. The - total number of table entries required by the code is calculated - incrementally as the number of codes at each bit length is populated. When - all of the codes are shorter than root bits, then root is reduced to the - longest code length, resulting in a single, smaller, one-level table. - - The inflate algorithm also provides for small values of root (relative to - the log2 of the number of symbols), where the shortest code has more bits - than root. In that case, root is increased to the length of the shortest - code. This program, by design, does not handle that case, so it is verified - that the number of symbols is less than 2^(root + 1). - - In order to speed up the examination (by about ten orders of magnitude for - the default arguments), the intermediate states in the build-up of a code - are remembered and previously visited branches are pruned. The memory - required for this will increase rapidly with the total number of symbols and - the maximum code length in bits. However this is a very small price to pay - for the vast speedup. - - First, all of the possible Huffman codes are counted, and reachable - intermediate states are noted by a non-zero count in a saved-results array. - Second, the intermediate states that lead to (root + 1) bit or longer codes - are used to look at all sub-codes from those junctures for their inflate - memory usage. (The amount of memory used is not affected by the number of - codes of root bits or less in length.) Third, the visited states in the - construction of those sub-codes and the associated calculation of the table - size is recalled in order to avoid recalculating from the same juncture. - Beginning the code examination at (root + 1) bit codes, which is enabled by - identifying the reachable nodes, accounts for about six of the orders of - magnitude of improvement for the default arguments. About another four - orders of magnitude come from not revisiting previous states. Out of - approximately 2x10^16 possible Huffman codes, only about 2x10^6 sub-codes - need to be examined to cover all of the possible table memory usage cases - for the default arguments of 286 symbols limited to 15-bit codes. - - Note that an unsigned long long type is used for counting. It is quite easy - to exceed the capacity of an eight-byte integer with a large number of - symbols and a large maximum code length, so multiple-precision arithmetic - would need to replace the unsigned long long arithmetic in that case. This - program will abort if an overflow occurs. The big_t type identifies where - the counting takes place. - - An unsigned long long type is also used for calculating the number of - possible codes remaining at the maximum length. This limits the maximum - code length to the number of bits in a long long minus the number of bits - needed to represent the symbols in a flat code. The code_t type identifies - where the bit pattern counting takes place. - */ - -#include -#include -#include -#include - -#define local static - -/* special data types */ -typedef unsigned long long big_t; /* type for code counting */ -typedef unsigned long long code_t; /* type for bit pattern counting */ -struct tab { /* type for been here check */ - size_t len; /* length of bit vector in char's */ - char *vec; /* allocated bit vector */ -}; - -/* The array for saving results, num[], is indexed with this triplet: - - syms: number of symbols remaining to code - left: number of available bit patterns at length len - len: number of bits in the codes currently being assigned - - Those indices are constrained thusly when saving results: - - syms: 3..totsym (totsym == total symbols to code) - left: 2..syms - 1, but only the evens (so syms == 8 -> 2, 4, 6) - len: 1..max - 1 (max == maximum code length in bits) - - syms == 2 is not saved since that immediately leads to a single code. left - must be even, since it represents the number of available bit patterns at - the current length, which is double the number at the previous length. - left ends at syms-1 since left == syms immediately results in a single code. - (left > sym is not allowed since that would result in an incomplete code.) - len is less than max, since the code completes immediately when len == max. - - The offset into the array is calculated for the three indices with the - first one (syms) being outermost, and the last one (len) being innermost. - We build the array with length max-1 lists for the len index, with syms-3 - of those for each symbol. There are totsym-2 of those, with each one - varying in length as a function of sym. See the calculation of index in - count() for the index, and the calculation of size in main() for the size - of the array. - - For the deflate example of 286 symbols limited to 15-bit codes, the array - has 284,284 entries, taking up 2.17 MB for an 8-byte big_t. More than - half of the space allocated for saved results is actually used -- not all - possible triplets are reached in the generation of valid Huffman codes. - */ - -/* The array for tracking visited states, done[], is itself indexed identically - to the num[] array as described above for the (syms, left, len) triplet. - Each element in the array is further indexed by the (mem, rem) doublet, - where mem is the amount of inflate table space used so far, and rem is the - remaining unused entries in the current inflate sub-table. Each indexed - element is simply one bit indicating whether the state has been visited or - not. Since the ranges for mem and rem are not known a priori, each bit - vector is of a variable size, and grows as needed to accommodate the visited - states. mem and rem are used to calculate a single index in a triangular - array. Since the range of mem is expected in the default case to be about - ten times larger than the range of rem, the array is skewed to reduce the - memory usage, with eight times the range for mem than for rem. See the - calculations for offset and bit in beenhere() for the details. - - For the deflate example of 286 symbols limited to 15-bit codes, the bit - vectors grow to total approximately 21 MB, in addition to the 4.3 MB done[] - array itself. - */ - -/* Globals to avoid propagating constants or constant pointers recursively */ -local int max; /* maximum allowed bit length for the codes */ -local int root; /* size of base code table in bits */ -local int large; /* largest code table so far */ -local size_t size; /* number of elements in num and done */ -local int *code; /* number of symbols assigned to each bit length */ -local big_t *num; /* saved results array for code counting */ -local struct tab *done; /* states already evaluated array */ - -/* Index function for num[] and done[] */ -#define INDEX(i,j,k) (((size_t)((i-1)>>1)*((i-2)>>1)+(j>>1)-1)*(max-1)+k-1) - -/* Free allocated space. Uses globals code, num, and done. */ -local void cleanup(void) -{ - size_t n; - - if (done != NULL) { - for (n = 0; n < size; n++) - if (done[n].len) - free(done[n].vec); - free(done); - } - if (num != NULL) - free(num); - if (code != NULL) - free(code); -} - -/* Return the number of possible Huffman codes using bit patterns of lengths - len through max inclusive, coding syms symbols, with left bit patterns of - length len unused -- return -1 if there is an overflow in the counting. - Keep a record of previous results in num to prevent repeating the same - calculation. Uses the globals max and num. */ -local big_t count(int syms, int len, int left) -{ - big_t sum; /* number of possible codes from this juncture */ - big_t got; /* value returned from count() */ - int least; /* least number of syms to use at this juncture */ - int most; /* most number of syms to use at this juncture */ - int use; /* number of bit patterns to use in next call */ - size_t index; /* index of this case in *num */ - - /* see if only one possible code */ - if (syms == left) - return 1; - - /* note and verify the expected state */ - assert(syms > left && left > 0 && len < max); - - /* see if we've done this one already */ - index = INDEX(syms, left, len); - got = num[index]; - if (got) - return got; /* we have -- return the saved result */ - - /* we need to use at least this many bit patterns so that the code won't be - incomplete at the next length (more bit patterns than symbols) */ - least = (left << 1) - syms; - if (least < 0) - least = 0; - - /* we can use at most this many bit patterns, lest there not be enough - available for the remaining symbols at the maximum length (if there were - no limit to the code length, this would become: most = left - 1) */ - most = (((code_t)left << (max - len)) - syms) / - (((code_t)1 << (max - len)) - 1); - - /* count all possible codes from this juncture and add them up */ - sum = 0; - for (use = least; use <= most; use++) { - got = count(syms - use, len + 1, (left - use) << 1); - sum += got; - if (got == (big_t)0 - 1 || sum < got) /* overflow */ - return (big_t)0 - 1; - } - - /* verify that all recursive calls are productive */ - assert(sum != 0); - - /* save the result and return it */ - num[index] = sum; - return sum; -} - -/* Return true if we've been here before, set to true if not. Set a bit in a - bit vector to indicate visiting this state. Each (syms,len,left) state - has a variable size bit vector indexed by (mem,rem). The bit vector is - lengthened if needed to allow setting the (mem,rem) bit. */ -local int beenhere(int syms, int len, int left, int mem, int rem) -{ - size_t index; /* index for this state's bit vector */ - size_t offset; /* offset in this state's bit vector */ - int bit; /* mask for this state's bit */ - size_t length; /* length of the bit vector in bytes */ - char *vector; /* new or enlarged bit vector */ - - /* point to vector for (syms,left,len), bit in vector for (mem,rem) */ - index = INDEX(syms, left, len); - mem -= 1 << root; - offset = (mem >> 3) + rem; - offset = ((offset * (offset + 1)) >> 1) + rem; - bit = 1 << (mem & 7); - - /* see if we've been here */ - length = done[index].len; - if (offset < length && (done[index].vec[offset] & bit) != 0) - return 1; /* done this! */ - - /* we haven't been here before -- set the bit to show we have now */ - - /* see if we need to lengthen the vector in order to set the bit */ - if (length <= offset) { - /* if we have one already, enlarge it, zero out the appended space */ - if (length) { - do { - length <<= 1; - } while (length <= offset); - vector = realloc(done[index].vec, length); - if (vector != NULL) - memset(vector + done[index].len, 0, length - done[index].len); - } - - /* otherwise we need to make a new vector and zero it out */ - else { - length = 1 << (len - root); - while (length <= offset) - length <<= 1; - vector = calloc(length, sizeof(char)); - } - - /* in either case, bail if we can't get the memory */ - if (vector == NULL) { - fputs("abort: unable to allocate enough memory\n", stderr); - cleanup(); - exit(1); - } - - /* install the new vector */ - done[index].len = length; - done[index].vec = vector; - } - - /* set the bit */ - done[index].vec[offset] |= bit; - return 0; -} - -/* Examine all possible codes from the given node (syms, len, left). Compute - the amount of memory required to build inflate's decoding tables, where the - number of code structures used so far is mem, and the number remaining in - the current sub-table is rem. Uses the globals max, code, root, large, and - done. */ -local void examine(int syms, int len, int left, int mem, int rem) -{ - int least; /* least number of syms to use at this juncture */ - int most; /* most number of syms to use at this juncture */ - int use; /* number of bit patterns to use in next call */ - - /* see if we have a complete code */ - if (syms == left) { - /* set the last code entry */ - code[len] = left; - - /* complete computation of memory used by this code */ - while (rem < left) { - left -= rem; - rem = 1 << (len - root); - mem += rem; - } - assert(rem == left); - - /* if this is a new maximum, show the entries used and the sub-code */ - if (mem > large) { - large = mem; - printf("max %d: ", mem); - for (use = root + 1; use <= max; use++) - if (code[use]) - printf("%d[%d] ", code[use], use); - putchar('\n'); - fflush(stdout); - } - - /* remove entries as we drop back down in the recursion */ - code[len] = 0; - return; - } - - /* prune the tree if we can */ - if (beenhere(syms, len, left, mem, rem)) - return; - - /* we need to use at least this many bit patterns so that the code won't be - incomplete at the next length (more bit patterns than symbols) */ - least = (left << 1) - syms; - if (least < 0) - least = 0; - - /* we can use at most this many bit patterns, lest there not be enough - available for the remaining symbols at the maximum length (if there were - no limit to the code length, this would become: most = left - 1) */ - most = (((code_t)left << (max - len)) - syms) / - (((code_t)1 << (max - len)) - 1); - - /* occupy least table spaces, creating new sub-tables as needed */ - use = least; - while (rem < use) { - use -= rem; - rem = 1 << (len - root); - mem += rem; - } - rem -= use; - - /* examine codes from here, updating table space as we go */ - for (use = least; use <= most; use++) { - code[len] = use; - examine(syms - use, len + 1, (left - use) << 1, - mem + (rem ? 1 << (len - root) : 0), rem << 1); - if (rem == 0) { - rem = 1 << (len - root); - mem += rem; - } - rem--; - } - - /* remove entries as we drop back down in the recursion */ - code[len] = 0; -} - -/* Look at all sub-codes starting with root + 1 bits. Look at only the valid - intermediate code states (syms, left, len). For each completed code, - calculate the amount of memory required by inflate to build the decoding - tables. Find the maximum amount of memory required and show the code that - requires that maximum. Uses the globals max, root, and num. */ -local void enough(int syms) -{ - int n; /* number of remaing symbols for this node */ - int left; /* number of unused bit patterns at this length */ - size_t index; /* index of this case in *num */ - - /* clear code */ - for (n = 0; n <= max; n++) - code[n] = 0; - - /* look at all (root + 1) bit and longer codes */ - large = 1 << root; /* base table */ - if (root < max) /* otherwise, there's only a base table */ - for (n = 3; n <= syms; n++) - for (left = 2; left < n; left += 2) - { - /* look at all reachable (root + 1) bit nodes, and the - resulting codes (complete at root + 2 or more) */ - index = INDEX(n, left, root + 1); - if (root + 1 < max && num[index]) /* reachable node */ - examine(n, root + 1, left, 1 << root, 0); - - /* also look at root bit codes with completions at root + 1 - bits (not saved in num, since complete), just in case */ - if (num[index - 1] && n <= left << 1) - examine((n - left) << 1, root + 1, (n - left) << 1, - 1 << root, 0); - } - - /* done */ - printf("done: maximum of %d table entries\n", large); -} - -/* - Examine and show the total number of possible Huffman codes for a given - maximum number of symbols, initial root table size, and maximum code length - in bits -- those are the command arguments in that order. The default - values are 286, 9, and 15 respectively, for the deflate literal/length code. - The possible codes are counted for each number of coded symbols from two to - the maximum. The counts for each of those and the total number of codes are - shown. The maximum number of inflate table entires is then calculated - across all possible codes. Each new maximum number of table entries and the - associated sub-code (starting at root + 1 == 10 bits) is shown. - - To count and examine Huffman codes that are not length-limited, provide a - maximum length equal to the number of symbols minus one. - - For the deflate literal/length code, use "enough". For the deflate distance - code, use "enough 30 6". - - This uses the %llu printf format to print big_t numbers, which assumes that - big_t is an unsigned long long. If the big_t type is changed (for example - to a multiple precision type), the method of printing will also need to be - updated. - */ -int main(int argc, char **argv) -{ - int syms; /* total number of symbols to code */ - int n; /* number of symbols to code for this run */ - big_t got; /* return value of count() */ - big_t sum; /* accumulated number of codes over n */ - code_t word; /* for counting bits in code_t */ - - /* set up globals for cleanup() */ - code = NULL; - num = NULL; - done = NULL; - - /* get arguments -- default to the deflate literal/length code */ - syms = 286; - root = 9; - max = 15; - if (argc > 1) { - syms = atoi(argv[1]); - if (argc > 2) { - root = atoi(argv[2]); - if (argc > 3) - max = atoi(argv[3]); - } - } - if (argc > 4 || syms < 2 || root < 1 || max < 1) { - fputs("invalid arguments, need: [sym >= 2 [root >= 1 [max >= 1]]]\n", - stderr); - return 1; - } - - /* if not restricting the code length, the longest is syms - 1 */ - if (max > syms - 1) - max = syms - 1; - - /* determine the number of bits in a code_t */ - for (n = 0, word = 1; word; n++, word <<= 1) - ; - - /* make sure that the calculation of most will not overflow */ - if (max > n || (code_t)(syms - 2) >= (((code_t)0 - 1) >> (max - 1))) { - fputs("abort: code length too long for internal types\n", stderr); - return 1; - } - - /* reject impossible code requests */ - if ((code_t)(syms - 1) > ((code_t)1 << max) - 1) { - fprintf(stderr, "%d symbols cannot be coded in %d bits\n", - syms, max); - return 1; - } - - /* allocate code vector */ - code = calloc(max + 1, sizeof(int)); - if (code == NULL) { - fputs("abort: unable to allocate enough memory\n", stderr); - return 1; - } - - /* determine size of saved results array, checking for overflows, - allocate and clear the array (set all to zero with calloc()) */ - if (syms == 2) /* iff max == 1 */ - num = NULL; /* won't be saving any results */ - else { - size = syms >> 1; - if (size > ((size_t)0 - 1) / (n = (syms - 1) >> 1) || - (size *= n, size > ((size_t)0 - 1) / (n = max - 1)) || - (size *= n, size > ((size_t)0 - 1) / sizeof(big_t)) || - (num = calloc(size, sizeof(big_t))) == NULL) { - fputs("abort: unable to allocate enough memory\n", stderr); - cleanup(); - return 1; - } - } - - /* count possible codes for all numbers of symbols, add up counts */ - sum = 0; - for (n = 2; n <= syms; n++) { - got = count(n, 1, 2); - sum += got; - if (got == (big_t)0 - 1 || sum < got) { /* overflow */ - fputs("abort: can't count that high!\n", stderr); - cleanup(); - return 1; - } - printf("%llu %d-codes\n", got, n); - } - printf("%llu total codes for 2 to %d symbols", sum, syms); - if (max < syms - 1) - printf(" (%d-bit length limit)\n", max); - else - puts(" (no length limit)"); - - /* allocate and clear done array for beenhere() */ - if (syms == 2) - done = NULL; - else if (size > ((size_t)0 - 1) / sizeof(struct tab) || - (done = calloc(size, sizeof(struct tab))) == NULL) { - fputs("abort: unable to allocate enough memory\n", stderr); - cleanup(); - return 1; - } - - /* find and show maximum inflate table usage */ - if (root > max) /* reduce root to max length */ - root = max; - if ((code_t)syms < ((code_t)1 << (root + 1))) - enough(syms); - else - puts("cannot handle minimum code lengths > root"); - - /* done */ - cleanup(); - return 0; -} diff --git a/src/beast/test/zlib/zlib-1.2.8/examples/fitblk.c b/src/beast/test/zlib/zlib-1.2.8/examples/fitblk.c deleted file mode 100644 index c61de5c9967..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/examples/fitblk.c +++ /dev/null @@ -1,233 +0,0 @@ -/* fitblk.c: example of fitting compressed output to a specified size - Not copyrighted -- provided to the public domain - Version 1.1 25 November 2004 Mark Adler */ - -/* Version history: - 1.0 24 Nov 2004 First version - 1.1 25 Nov 2004 Change deflateInit2() to deflateInit() - Use fixed-size, stack-allocated raw buffers - Simplify code moving compression to subroutines - Use assert() for internal errors - Add detailed description of approach - */ - -/* Approach to just fitting a requested compressed size: - - fitblk performs three compression passes on a portion of the input - data in order to determine how much of that input will compress to - nearly the requested output block size. The first pass generates - enough deflate blocks to produce output to fill the requested - output size plus a specfied excess amount (see the EXCESS define - below). The last deflate block may go quite a bit past that, but - is discarded. The second pass decompresses and recompresses just - the compressed data that fit in the requested plus excess sized - buffer. The deflate process is terminated after that amount of - input, which is less than the amount consumed on the first pass. - The last deflate block of the result will be of a comparable size - to the final product, so that the header for that deflate block and - the compression ratio for that block will be about the same as in - the final product. The third compression pass decompresses the - result of the second step, but only the compressed data up to the - requested size minus an amount to allow the compressed stream to - complete (see the MARGIN define below). That will result in a - final compressed stream whose length is less than or equal to the - requested size. Assuming sufficient input and a requested size - greater than a few hundred bytes, the shortfall will typically be - less than ten bytes. - - If the input is short enough that the first compression completes - before filling the requested output size, then that compressed - stream is return with no recompression. - - EXCESS is chosen to be just greater than the shortfall seen in a - two pass approach similar to the above. That shortfall is due to - the last deflate block compressing more efficiently with a smaller - header on the second pass. EXCESS is set to be large enough so - that there is enough uncompressed data for the second pass to fill - out the requested size, and small enough so that the final deflate - block of the second pass will be close in size to the final deflate - block of the third and final pass. MARGIN is chosen to be just - large enough to assure that the final compression has enough room - to complete in all cases. - */ - -#include -#include -#include -#include "zlib.h" - -#define local static - -/* print nastygram and leave */ -local void quit(char *why) -{ - fprintf(stderr, "fitblk abort: %s\n", why); - exit(1); -} - -#define RAWLEN 4096 /* intermediate uncompressed buffer size */ - -/* compress from file to def until provided buffer is full or end of - input reached; return last deflate() return value, or Z_ERRNO if - there was read error on the file */ -local int partcompress(FILE *in, z_streamp def) -{ - int ret, flush; - unsigned char raw[RAWLEN]; - - flush = Z_NO_FLUSH; - do { - def->avail_in = fread(raw, 1, RAWLEN, in); - if (ferror(in)) - return Z_ERRNO; - def->next_in = raw; - if (feof(in)) - flush = Z_FINISH; - ret = deflate(def, flush); - assert(ret != Z_STREAM_ERROR); - } while (def->avail_out != 0 && flush == Z_NO_FLUSH); - return ret; -} - -/* recompress from inf's input to def's output; the input for inf and - the output for def are set in those structures before calling; - return last deflate() return value, or Z_MEM_ERROR if inflate() - was not able to allocate enough memory when it needed to */ -local int recompress(z_streamp inf, z_streamp def) -{ - int ret, flush; - unsigned char raw[RAWLEN]; - - flush = Z_NO_FLUSH; - do { - /* decompress */ - inf->avail_out = RAWLEN; - inf->next_out = raw; - ret = inflate(inf, Z_NO_FLUSH); - assert(ret != Z_STREAM_ERROR && ret != Z_DATA_ERROR && - ret != Z_NEED_DICT); - if (ret == Z_MEM_ERROR) - return ret; - - /* compress what was decompresed until done or no room */ - def->avail_in = RAWLEN - inf->avail_out; - def->next_in = raw; - if (inf->avail_out != 0) - flush = Z_FINISH; - ret = deflate(def, flush); - assert(ret != Z_STREAM_ERROR); - } while (ret != Z_STREAM_END && def->avail_out != 0); - return ret; -} - -#define EXCESS 256 /* empirically determined stream overage */ -#define MARGIN 8 /* amount to back off for completion */ - -/* compress from stdin to fixed-size block on stdout */ -int main(int argc, char **argv) -{ - int ret; /* return code */ - unsigned size; /* requested fixed output block size */ - unsigned have; /* bytes written by deflate() call */ - unsigned char *blk; /* intermediate and final stream */ - unsigned char *tmp; /* close to desired size stream */ - z_stream def, inf; /* zlib deflate and inflate states */ - - /* get requested output size */ - if (argc != 2) - quit("need one argument: size of output block"); - ret = strtol(argv[1], argv + 1, 10); - if (argv[1][0] != 0) - quit("argument must be a number"); - if (ret < 8) /* 8 is minimum zlib stream size */ - quit("need positive size of 8 or greater"); - size = (unsigned)ret; - - /* allocate memory for buffers and compression engine */ - blk = malloc(size + EXCESS); - def.zalloc = Z_NULL; - def.zfree = Z_NULL; - def.opaque = Z_NULL; - ret = deflateInit(&def, Z_DEFAULT_COMPRESSION); - if (ret != Z_OK || blk == NULL) - quit("out of memory"); - - /* compress from stdin until output full, or no more input */ - def.avail_out = size + EXCESS; - def.next_out = blk; - ret = partcompress(stdin, &def); - if (ret == Z_ERRNO) - quit("error reading input"); - - /* if it all fit, then size was undersubscribed -- done! */ - if (ret == Z_STREAM_END && def.avail_out >= EXCESS) { - /* write block to stdout */ - have = size + EXCESS - def.avail_out; - if (fwrite(blk, 1, have, stdout) != have || ferror(stdout)) - quit("error writing output"); - - /* clean up and print results to stderr */ - ret = deflateEnd(&def); - assert(ret != Z_STREAM_ERROR); - free(blk); - fprintf(stderr, - "%u bytes unused out of %u requested (all input)\n", - size - have, size); - return 0; - } - - /* it didn't all fit -- set up for recompression */ - inf.zalloc = Z_NULL; - inf.zfree = Z_NULL; - inf.opaque = Z_NULL; - inf.avail_in = 0; - inf.next_in = Z_NULL; - ret = inflateInit(&inf); - tmp = malloc(size + EXCESS); - if (ret != Z_OK || tmp == NULL) - quit("out of memory"); - ret = deflateReset(&def); - assert(ret != Z_STREAM_ERROR); - - /* do first recompression close to the right amount */ - inf.avail_in = size + EXCESS; - inf.next_in = blk; - def.avail_out = size + EXCESS; - def.next_out = tmp; - ret = recompress(&inf, &def); - if (ret == Z_MEM_ERROR) - quit("out of memory"); - - /* set up for next reocmpression */ - ret = inflateReset(&inf); - assert(ret != Z_STREAM_ERROR); - ret = deflateReset(&def); - assert(ret != Z_STREAM_ERROR); - - /* do second and final recompression (third compression) */ - inf.avail_in = size - MARGIN; /* assure stream will complete */ - inf.next_in = tmp; - def.avail_out = size; - def.next_out = blk; - ret = recompress(&inf, &def); - if (ret == Z_MEM_ERROR) - quit("out of memory"); - assert(ret == Z_STREAM_END); /* otherwise MARGIN too small */ - - /* done -- write block to stdout */ - have = size - def.avail_out; - if (fwrite(blk, 1, have, stdout) != have || ferror(stdout)) - quit("error writing output"); - - /* clean up and print results to stderr */ - free(tmp); - ret = inflateEnd(&inf); - assert(ret != Z_STREAM_ERROR); - ret = deflateEnd(&def); - assert(ret != Z_STREAM_ERROR); - free(blk); - fprintf(stderr, - "%u bytes unused out of %u requested (%lu input)\n", - size - have, size, def.total_in); - return 0; -} diff --git a/src/beast/test/zlib/zlib-1.2.8/examples/gun.c b/src/beast/test/zlib/zlib-1.2.8/examples/gun.c deleted file mode 100644 index 89e484fee60..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/examples/gun.c +++ /dev/null @@ -1,702 +0,0 @@ -/* gun.c -- simple gunzip to give an example of the use of inflateBack() - * Copyright (C) 2003, 2005, 2008, 2010, 2012 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - Version 1.7 12 August 2012 Mark Adler */ - -/* Version history: - 1.0 16 Feb 2003 First version for testing of inflateBack() - 1.1 21 Feb 2005 Decompress concatenated gzip streams - Remove use of "this" variable (C++ keyword) - Fix return value for in() - Improve allocation failure checking - Add typecasting for void * structures - Add -h option for command version and usage - Add a bunch of comments - 1.2 20 Mar 2005 Add Unix compress (LZW) decompression - Copy file attributes from input file to output file - 1.3 12 Jun 2005 Add casts for error messages [Oberhumer] - 1.4 8 Dec 2006 LZW decompression speed improvements - 1.5 9 Feb 2008 Avoid warning in latest version of gcc - 1.6 17 Jan 2010 Avoid signed/unsigned comparison warnings - 1.7 12 Aug 2012 Update for z_const usage in zlib 1.2.8 - */ - -/* - gun [ -t ] [ name ... ] - - decompresses the data in the named gzip files. If no arguments are given, - gun will decompress from stdin to stdout. The names must end in .gz, -gz, - .z, -z, _z, or .Z. The uncompressed data will be written to a file name - with the suffix stripped. On success, the original file is deleted. On - failure, the output file is deleted. For most failures, the command will - continue to process the remaining names on the command line. A memory - allocation failure will abort the command. If -t is specified, then the - listed files or stdin will be tested as gzip files for integrity (without - checking for a proper suffix), no output will be written, and no files - will be deleted. - - Like gzip, gun allows concatenated gzip streams and will decompress them, - writing all of the uncompressed data to the output. Unlike gzip, gun allows - an empty file on input, and will produce no error writing an empty output - file. - - gun will also decompress files made by Unix compress, which uses LZW - compression. These files are automatically detected by virtue of their - magic header bytes. Since the end of Unix compress stream is marked by the - end-of-file, they cannot be concantenated. If a Unix compress stream is - encountered in an input file, it is the last stream in that file. - - Like gunzip and uncompress, the file attributes of the orignal compressed - file are maintained in the final uncompressed file, to the extent that the - user permissions allow it. - - On my Mac OS X PowerPC G4, gun is almost twice as fast as gunzip (version - 1.2.4) is on the same file, when gun is linked with zlib 1.2.2. Also the - LZW decompression provided by gun is about twice as fast as the standard - Unix uncompress command. - */ - -/* external functions and related types and constants */ -#include /* fprintf() */ -#include /* malloc(), free() */ -#include /* strerror(), strcmp(), strlen(), memcpy() */ -#include /* errno */ -#include /* open() */ -#include /* read(), write(), close(), chown(), unlink() */ -#include -#include /* stat(), chmod() */ -#include /* utime() */ -#include "zlib.h" /* inflateBackInit(), inflateBack(), */ - /* inflateBackEnd(), crc32() */ - -/* function declaration */ -#define local static - -/* buffer constants */ -#define SIZE 32768U /* input and output buffer sizes */ -#define PIECE 16384 /* limits i/o chunks for 16-bit int case */ - -/* structure for infback() to pass to input function in() -- it maintains the - input file and a buffer of size SIZE */ -struct ind { - int infile; - unsigned char *inbuf; -}; - -/* Load input buffer, assumed to be empty, and return bytes loaded and a - pointer to them. read() is called until the buffer is full, or until it - returns end-of-file or error. Return 0 on error. */ -local unsigned in(void *in_desc, z_const unsigned char **buf) -{ - int ret; - unsigned len; - unsigned char *next; - struct ind *me = (struct ind *)in_desc; - - next = me->inbuf; - *buf = next; - len = 0; - do { - ret = PIECE; - if ((unsigned)ret > SIZE - len) - ret = (int)(SIZE - len); - ret = (int)read(me->infile, next, ret); - if (ret == -1) { - len = 0; - break; - } - next += ret; - len += ret; - } while (ret != 0 && len < SIZE); - return len; -} - -/* structure for infback() to pass to output function out() -- it maintains the - output file, a running CRC-32 check on the output and the total number of - bytes output, both for checking against the gzip trailer. (The length in - the gzip trailer is stored modulo 2^32, so it's ok if a long is 32 bits and - the output is greater than 4 GB.) */ -struct outd { - int outfile; - int check; /* true if checking crc and total */ - unsigned long crc; - unsigned long total; -}; - -/* Write output buffer and update the CRC-32 and total bytes written. write() - is called until all of the output is written or an error is encountered. - On success out() returns 0. For a write failure, out() returns 1. If the - output file descriptor is -1, then nothing is written. - */ -local int out(void *out_desc, unsigned char *buf, unsigned len) -{ - int ret; - struct outd *me = (struct outd *)out_desc; - - if (me->check) { - me->crc = crc32(me->crc, buf, len); - me->total += len; - } - if (me->outfile != -1) - do { - ret = PIECE; - if ((unsigned)ret > len) - ret = (int)len; - ret = (int)write(me->outfile, buf, ret); - if (ret == -1) - return 1; - buf += ret; - len -= ret; - } while (len != 0); - return 0; -} - -/* next input byte macro for use inside lunpipe() and gunpipe() */ -#define NEXT() (have ? 0 : (have = in(indp, &next)), \ - last = have ? (have--, (int)(*next++)) : -1) - -/* memory for gunpipe() and lunpipe() -- - the first 256 entries of prefix[] and suffix[] are never used, could - have offset the index, but it's faster to waste the memory */ -unsigned char inbuf[SIZE]; /* input buffer */ -unsigned char outbuf[SIZE]; /* output buffer */ -unsigned short prefix[65536]; /* index to LZW prefix string */ -unsigned char suffix[65536]; /* one-character LZW suffix */ -unsigned char match[65280 + 2]; /* buffer for reversed match or gzip - 32K sliding window */ - -/* throw out what's left in the current bits byte buffer (this is a vestigial - aspect of the compressed data format derived from an implementation that - made use of a special VAX machine instruction!) */ -#define FLUSHCODE() \ - do { \ - left = 0; \ - rem = 0; \ - if (chunk > have) { \ - chunk -= have; \ - have = 0; \ - if (NEXT() == -1) \ - break; \ - chunk--; \ - if (chunk > have) { \ - chunk = have = 0; \ - break; \ - } \ - } \ - have -= chunk; \ - next += chunk; \ - chunk = 0; \ - } while (0) - -/* Decompress a compress (LZW) file from indp to outfile. The compress magic - header (two bytes) has already been read and verified. There are have bytes - of buffered input at next. strm is used for passing error information back - to gunpipe(). - - lunpipe() will return Z_OK on success, Z_BUF_ERROR for an unexpected end of - file, read error, or write error (a write error indicated by strm->next_in - not equal to Z_NULL), or Z_DATA_ERROR for invalid input. - */ -local int lunpipe(unsigned have, z_const unsigned char *next, struct ind *indp, - int outfile, z_stream *strm) -{ - int last; /* last byte read by NEXT(), or -1 if EOF */ - unsigned chunk; /* bytes left in current chunk */ - int left; /* bits left in rem */ - unsigned rem; /* unused bits from input */ - int bits; /* current bits per code */ - unsigned code; /* code, table traversal index */ - unsigned mask; /* mask for current bits codes */ - int max; /* maximum bits per code for this stream */ - unsigned flags; /* compress flags, then block compress flag */ - unsigned end; /* last valid entry in prefix/suffix tables */ - unsigned temp; /* current code */ - unsigned prev; /* previous code */ - unsigned final; /* last character written for previous code */ - unsigned stack; /* next position for reversed string */ - unsigned outcnt; /* bytes in output buffer */ - struct outd outd; /* output structure */ - unsigned char *p; - - /* set up output */ - outd.outfile = outfile; - outd.check = 0; - - /* process remainder of compress header -- a flags byte */ - flags = NEXT(); - if (last == -1) - return Z_BUF_ERROR; - if (flags & 0x60) { - strm->msg = (char *)"unknown lzw flags set"; - return Z_DATA_ERROR; - } - max = flags & 0x1f; - if (max < 9 || max > 16) { - strm->msg = (char *)"lzw bits out of range"; - return Z_DATA_ERROR; - } - if (max == 9) /* 9 doesn't really mean 9 */ - max = 10; - flags &= 0x80; /* true if block compress */ - - /* clear table */ - bits = 9; - mask = 0x1ff; - end = flags ? 256 : 255; - - /* set up: get first 9-bit code, which is the first decompressed byte, but - don't create a table entry until the next code */ - if (NEXT() == -1) /* no compressed data is ok */ - return Z_OK; - final = prev = (unsigned)last; /* low 8 bits of code */ - if (NEXT() == -1) /* missing a bit */ - return Z_BUF_ERROR; - if (last & 1) { /* code must be < 256 */ - strm->msg = (char *)"invalid lzw code"; - return Z_DATA_ERROR; - } - rem = (unsigned)last >> 1; /* remaining 7 bits */ - left = 7; - chunk = bits - 2; /* 7 bytes left in this chunk */ - outbuf[0] = (unsigned char)final; /* write first decompressed byte */ - outcnt = 1; - - /* decode codes */ - stack = 0; - for (;;) { - /* if the table will be full after this, increment the code size */ - if (end >= mask && bits < max) { - FLUSHCODE(); - bits++; - mask <<= 1; - mask++; - } - - /* get a code of length bits */ - if (chunk == 0) /* decrement chunk modulo bits */ - chunk = bits; - code = rem; /* low bits of code */ - if (NEXT() == -1) { /* EOF is end of compressed data */ - /* write remaining buffered output */ - if (outcnt && out(&outd, outbuf, outcnt)) { - strm->next_in = outbuf; /* signal write error */ - return Z_BUF_ERROR; - } - return Z_OK; - } - code += (unsigned)last << left; /* middle (or high) bits of code */ - left += 8; - chunk--; - if (bits > left) { /* need more bits */ - if (NEXT() == -1) /* can't end in middle of code */ - return Z_BUF_ERROR; - code += (unsigned)last << left; /* high bits of code */ - left += 8; - chunk--; - } - code &= mask; /* mask to current code length */ - left -= bits; /* number of unused bits */ - rem = (unsigned)last >> (8 - left); /* unused bits from last byte */ - - /* process clear code (256) */ - if (code == 256 && flags) { - FLUSHCODE(); - bits = 9; /* initialize bits and mask */ - mask = 0x1ff; - end = 255; /* empty table */ - continue; /* get next code */ - } - - /* special code to reuse last match */ - temp = code; /* save the current code */ - if (code > end) { - /* Be picky on the allowed code here, and make sure that the code - we drop through (prev) will be a valid index so that random - input does not cause an exception. The code != end + 1 check is - empirically derived, and not checked in the original uncompress - code. If this ever causes a problem, that check could be safely - removed. Leaving this check in greatly improves gun's ability - to detect random or corrupted input after a compress header. - In any case, the prev > end check must be retained. */ - if (code != end + 1 || prev > end) { - strm->msg = (char *)"invalid lzw code"; - return Z_DATA_ERROR; - } - match[stack++] = (unsigned char)final; - code = prev; - } - - /* walk through linked list to generate output in reverse order */ - p = match + stack; - while (code >= 256) { - *p++ = suffix[code]; - code = prefix[code]; - } - stack = p - match; - match[stack++] = (unsigned char)code; - final = code; - - /* link new table entry */ - if (end < mask) { - end++; - prefix[end] = (unsigned short)prev; - suffix[end] = (unsigned char)final; - } - - /* set previous code for next iteration */ - prev = temp; - - /* write output in forward order */ - while (stack > SIZE - outcnt) { - while (outcnt < SIZE) - outbuf[outcnt++] = match[--stack]; - if (out(&outd, outbuf, outcnt)) { - strm->next_in = outbuf; /* signal write error */ - return Z_BUF_ERROR; - } - outcnt = 0; - } - p = match + stack; - do { - outbuf[outcnt++] = *--p; - } while (p > match); - stack = 0; - - /* loop for next code with final and prev as the last match, rem and - left provide the first 0..7 bits of the next code, end is the last - valid table entry */ - } -} - -/* Decompress a gzip file from infile to outfile. strm is assumed to have been - successfully initialized with inflateBackInit(). The input file may consist - of a series of gzip streams, in which case all of them will be decompressed - to the output file. If outfile is -1, then the gzip stream(s) integrity is - checked and nothing is written. - - The return value is a zlib error code: Z_MEM_ERROR if out of memory, - Z_DATA_ERROR if the header or the compressed data is invalid, or if the - trailer CRC-32 check or length doesn't match, Z_BUF_ERROR if the input ends - prematurely or a write error occurs, or Z_ERRNO if junk (not a another gzip - stream) follows a valid gzip stream. - */ -local int gunpipe(z_stream *strm, int infile, int outfile) -{ - int ret, first, last; - unsigned have, flags, len; - z_const unsigned char *next = NULL; - struct ind ind, *indp; - struct outd outd; - - /* setup input buffer */ - ind.infile = infile; - ind.inbuf = inbuf; - indp = &ind; - - /* decompress concatenated gzip streams */ - have = 0; /* no input data read in yet */ - first = 1; /* looking for first gzip header */ - strm->next_in = Z_NULL; /* so Z_BUF_ERROR means EOF */ - for (;;) { - /* look for the two magic header bytes for a gzip stream */ - if (NEXT() == -1) { - ret = Z_OK; - break; /* empty gzip stream is ok */ - } - if (last != 31 || (NEXT() != 139 && last != 157)) { - strm->msg = (char *)"incorrect header check"; - ret = first ? Z_DATA_ERROR : Z_ERRNO; - break; /* not a gzip or compress header */ - } - first = 0; /* next non-header is junk */ - - /* process a compress (LZW) file -- can't be concatenated after this */ - if (last == 157) { - ret = lunpipe(have, next, indp, outfile, strm); - break; - } - - /* process remainder of gzip header */ - ret = Z_BUF_ERROR; - if (NEXT() != 8) { /* only deflate method allowed */ - if (last == -1) break; - strm->msg = (char *)"unknown compression method"; - ret = Z_DATA_ERROR; - break; - } - flags = NEXT(); /* header flags */ - NEXT(); /* discard mod time, xflgs, os */ - NEXT(); - NEXT(); - NEXT(); - NEXT(); - NEXT(); - if (last == -1) break; - if (flags & 0xe0) { - strm->msg = (char *)"unknown header flags set"; - ret = Z_DATA_ERROR; - break; - } - if (flags & 4) { /* extra field */ - len = NEXT(); - len += (unsigned)(NEXT()) << 8; - if (last == -1) break; - while (len > have) { - len -= have; - have = 0; - if (NEXT() == -1) break; - len--; - } - if (last == -1) break; - have -= len; - next += len; - } - if (flags & 8) /* file name */ - while (NEXT() != 0 && last != -1) - ; - if (flags & 16) /* comment */ - while (NEXT() != 0 && last != -1) - ; - if (flags & 2) { /* header crc */ - NEXT(); - NEXT(); - } - if (last == -1) break; - - /* set up output */ - outd.outfile = outfile; - outd.check = 1; - outd.crc = crc32(0L, Z_NULL, 0); - outd.total = 0; - - /* decompress data to output */ - strm->next_in = next; - strm->avail_in = have; - ret = inflateBack(strm, in, indp, out, &outd); - if (ret != Z_STREAM_END) break; - next = strm->next_in; - have = strm->avail_in; - strm->next_in = Z_NULL; /* so Z_BUF_ERROR means EOF */ - - /* check trailer */ - ret = Z_BUF_ERROR; - if (NEXT() != (int)(outd.crc & 0xff) || - NEXT() != (int)((outd.crc >> 8) & 0xff) || - NEXT() != (int)((outd.crc >> 16) & 0xff) || - NEXT() != (int)((outd.crc >> 24) & 0xff)) { - /* crc error */ - if (last != -1) { - strm->msg = (char *)"incorrect data check"; - ret = Z_DATA_ERROR; - } - break; - } - if (NEXT() != (int)(outd.total & 0xff) || - NEXT() != (int)((outd.total >> 8) & 0xff) || - NEXT() != (int)((outd.total >> 16) & 0xff) || - NEXT() != (int)((outd.total >> 24) & 0xff)) { - /* length error */ - if (last != -1) { - strm->msg = (char *)"incorrect length check"; - ret = Z_DATA_ERROR; - } - break; - } - - /* go back and look for another gzip stream */ - } - - /* clean up and return */ - return ret; -} - -/* Copy file attributes, from -> to, as best we can. This is best effort, so - no errors are reported. The mode bits, including suid, sgid, and the sticky - bit are copied (if allowed), the owner's user id and group id are copied - (again if allowed), and the access and modify times are copied. */ -local void copymeta(char *from, char *to) -{ - struct stat was; - struct utimbuf when; - - /* get all of from's Unix meta data, return if not a regular file */ - if (stat(from, &was) != 0 || (was.st_mode & S_IFMT) != S_IFREG) - return; - - /* set to's mode bits, ignore errors */ - (void)chmod(to, was.st_mode & 07777); - - /* copy owner's user and group, ignore errors */ - (void)chown(to, was.st_uid, was.st_gid); - - /* copy access and modify times, ignore errors */ - when.actime = was.st_atime; - when.modtime = was.st_mtime; - (void)utime(to, &when); -} - -/* Decompress the file inname to the file outnname, of if test is true, just - decompress without writing and check the gzip trailer for integrity. If - inname is NULL or an empty string, read from stdin. If outname is NULL or - an empty string, write to stdout. strm is a pre-initialized inflateBack - structure. When appropriate, copy the file attributes from inname to - outname. - - gunzip() returns 1 if there is an out-of-memory error or an unexpected - return code from gunpipe(). Otherwise it returns 0. - */ -local int gunzip(z_stream *strm, char *inname, char *outname, int test) -{ - int ret; - int infile, outfile; - - /* open files */ - if (inname == NULL || *inname == 0) { - inname = "-"; - infile = 0; /* stdin */ - } - else { - infile = open(inname, O_RDONLY, 0); - if (infile == -1) { - fprintf(stderr, "gun cannot open %s\n", inname); - return 0; - } - } - if (test) - outfile = -1; - else if (outname == NULL || *outname == 0) { - outname = "-"; - outfile = 1; /* stdout */ - } - else { - outfile = open(outname, O_CREAT | O_TRUNC | O_WRONLY, 0666); - if (outfile == -1) { - close(infile); - fprintf(stderr, "gun cannot create %s\n", outname); - return 0; - } - } - errno = 0; - - /* decompress */ - ret = gunpipe(strm, infile, outfile); - if (outfile > 2) close(outfile); - if (infile > 2) close(infile); - - /* interpret result */ - switch (ret) { - case Z_OK: - case Z_ERRNO: - if (infile > 2 && outfile > 2) { - copymeta(inname, outname); /* copy attributes */ - unlink(inname); - } - if (ret == Z_ERRNO) - fprintf(stderr, "gun warning: trailing garbage ignored in %s\n", - inname); - break; - case Z_DATA_ERROR: - if (outfile > 2) unlink(outname); - fprintf(stderr, "gun data error on %s: %s\n", inname, strm->msg); - break; - case Z_MEM_ERROR: - if (outfile > 2) unlink(outname); - fprintf(stderr, "gun out of memory error--aborting\n"); - return 1; - case Z_BUF_ERROR: - if (outfile > 2) unlink(outname); - if (strm->next_in != Z_NULL) { - fprintf(stderr, "gun write error on %s: %s\n", - outname, strerror(errno)); - } - else if (errno) { - fprintf(stderr, "gun read error on %s: %s\n", - inname, strerror(errno)); - } - else { - fprintf(stderr, "gun unexpected end of file on %s\n", - inname); - } - break; - default: - if (outfile > 2) unlink(outname); - fprintf(stderr, "gun internal error--aborting\n"); - return 1; - } - return 0; -} - -/* Process the gun command line arguments. See the command syntax near the - beginning of this source file. */ -int main(int argc, char **argv) -{ - int ret, len, test; - char *outname; - unsigned char *window; - z_stream strm; - - /* initialize inflateBack state for repeated use */ - window = match; /* reuse LZW match buffer */ - strm.zalloc = Z_NULL; - strm.zfree = Z_NULL; - strm.opaque = Z_NULL; - ret = inflateBackInit(&strm, 15, window); - if (ret != Z_OK) { - fprintf(stderr, "gun out of memory error--aborting\n"); - return 1; - } - - /* decompress each file to the same name with the suffix removed */ - argc--; - argv++; - test = 0; - if (argc && strcmp(*argv, "-h") == 0) { - fprintf(stderr, "gun 1.6 (17 Jan 2010)\n"); - fprintf(stderr, "Copyright (C) 2003-2010 Mark Adler\n"); - fprintf(stderr, "usage: gun [-t] [file1.gz [file2.Z ...]]\n"); - return 0; - } - if (argc && strcmp(*argv, "-t") == 0) { - test = 1; - argc--; - argv++; - } - if (argc) - do { - if (test) - outname = NULL; - else { - len = (int)strlen(*argv); - if (strcmp(*argv + len - 3, ".gz") == 0 || - strcmp(*argv + len - 3, "-gz") == 0) - len -= 3; - else if (strcmp(*argv + len - 2, ".z") == 0 || - strcmp(*argv + len - 2, "-z") == 0 || - strcmp(*argv + len - 2, "_z") == 0 || - strcmp(*argv + len - 2, ".Z") == 0) - len -= 2; - else { - fprintf(stderr, "gun error: no gz type on %s--skipping\n", - *argv); - continue; - } - outname = malloc(len + 1); - if (outname == NULL) { - fprintf(stderr, "gun out of memory error--aborting\n"); - ret = 1; - break; - } - memcpy(outname, *argv, len); - outname[len] = 0; - } - ret = gunzip(&strm, *argv, outname, test); - if (outname != NULL) free(outname); - if (ret) break; - } while (argv++, --argc); - else - ret = gunzip(&strm, NULL, NULL, test); - - /* clean up */ - inflateBackEnd(&strm); - return ret; -} diff --git a/src/beast/test/zlib/zlib-1.2.8/examples/gzappend.c b/src/beast/test/zlib/zlib-1.2.8/examples/gzappend.c deleted file mode 100644 index 662dec3794b..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/examples/gzappend.c +++ /dev/null @@ -1,504 +0,0 @@ -/* gzappend -- command to append to a gzip file - - Copyright (C) 2003, 2012 Mark Adler, all rights reserved - version 1.2, 11 Oct 2012 - - This software is provided 'as-is', without any express or implied - warranty. In no event will the author be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Mark Adler madler@alumni.caltech.edu - */ - -/* - * Change history: - * - * 1.0 19 Oct 2003 - First version - * 1.1 4 Nov 2003 - Expand and clarify some comments and notes - * - Add version and copyright to help - * - Send help to stdout instead of stderr - * - Add some preemptive typecasts - * - Add L to constants in lseek() calls - * - Remove some debugging information in error messages - * - Use new data_type definition for zlib 1.2.1 - * - Simplfy and unify file operations - * - Finish off gzip file in gztack() - * - Use deflatePrime() instead of adding empty blocks - * - Keep gzip file clean on appended file read errors - * - Use in-place rotate instead of auxiliary buffer - * (Why you ask? Because it was fun to write!) - * 1.2 11 Oct 2012 - Fix for proper z_const usage - * - Check for input buffer malloc failure - */ - -/* - gzappend takes a gzip file and appends to it, compressing files from the - command line or data from stdin. The gzip file is written to directly, to - avoid copying that file, in case it's large. Note that this results in the - unfriendly behavior that if gzappend fails, the gzip file is corrupted. - - This program was written to illustrate the use of the new Z_BLOCK option of - zlib 1.2.x's inflate() function. This option returns from inflate() at each - block boundary to facilitate locating and modifying the last block bit at - the start of the final deflate block. Also whether using Z_BLOCK or not, - another required feature of zlib 1.2.x is that inflate() now provides the - number of unusued bits in the last input byte used. gzappend will not work - with versions of zlib earlier than 1.2.1. - - gzappend first decompresses the gzip file internally, discarding all but - the last 32K of uncompressed data, and noting the location of the last block - bit and the number of unused bits in the last byte of the compressed data. - The gzip trailer containing the CRC-32 and length of the uncompressed data - is verified. This trailer will be later overwritten. - - Then the last block bit is cleared by seeking back in the file and rewriting - the byte that contains it. Seeking forward, the last byte of the compressed - data is saved along with the number of unused bits to initialize deflate. - - A deflate process is initialized, using the last 32K of the uncompressed - data from the gzip file to initialize the dictionary. If the total - uncompressed data was less than 32K, then all of it is used to initialize - the dictionary. The deflate output bit buffer is also initialized with the - last bits from the original deflate stream. From here on, the data to - append is simply compressed using deflate, and written to the gzip file. - When that is complete, the new CRC-32 and uncompressed length are written - as the trailer of the gzip file. - */ - -#include -#include -#include -#include -#include -#include "zlib.h" - -#define local static -#define LGCHUNK 14 -#define CHUNK (1U << LGCHUNK) -#define DSIZE 32768U - -/* print an error message and terminate with extreme prejudice */ -local void bye(char *msg1, char *msg2) -{ - fprintf(stderr, "gzappend error: %s%s\n", msg1, msg2); - exit(1); -} - -/* return the greatest common divisor of a and b using Euclid's algorithm, - modified to be fast when one argument much greater than the other, and - coded to avoid unnecessary swapping */ -local unsigned gcd(unsigned a, unsigned b) -{ - unsigned c; - - while (a && b) - if (a > b) { - c = b; - while (a - c >= c) - c <<= 1; - a -= c; - } - else { - c = a; - while (b - c >= c) - c <<= 1; - b -= c; - } - return a + b; -} - -/* rotate list[0..len-1] left by rot positions, in place */ -local void rotate(unsigned char *list, unsigned len, unsigned rot) -{ - unsigned char tmp; - unsigned cycles; - unsigned char *start, *last, *to, *from; - - /* normalize rot and handle degenerate cases */ - if (len < 2) return; - if (rot >= len) rot %= len; - if (rot == 0) return; - - /* pointer to last entry in list */ - last = list + (len - 1); - - /* do simple left shift by one */ - if (rot == 1) { - tmp = *list; - memcpy(list, list + 1, len - 1); - *last = tmp; - return; - } - - /* do simple right shift by one */ - if (rot == len - 1) { - tmp = *last; - memmove(list + 1, list, len - 1); - *list = tmp; - return; - } - - /* otherwise do rotate as a set of cycles in place */ - cycles = gcd(len, rot); /* number of cycles */ - do { - start = from = list + cycles; /* start index is arbitrary */ - tmp = *from; /* save entry to be overwritten */ - for (;;) { - to = from; /* next step in cycle */ - from += rot; /* go right rot positions */ - if (from > last) from -= len; /* (pointer better not wrap) */ - if (from == start) break; /* all but one shifted */ - *to = *from; /* shift left */ - } - *to = tmp; /* complete the circle */ - } while (--cycles); -} - -/* structure for gzip file read operations */ -typedef struct { - int fd; /* file descriptor */ - int size; /* 1 << size is bytes in buf */ - unsigned left; /* bytes available at next */ - unsigned char *buf; /* buffer */ - z_const unsigned char *next; /* next byte in buffer */ - char *name; /* file name for error messages */ -} file; - -/* reload buffer */ -local int readin(file *in) -{ - int len; - - len = read(in->fd, in->buf, 1 << in->size); - if (len == -1) bye("error reading ", in->name); - in->left = (unsigned)len; - in->next = in->buf; - return len; -} - -/* read from file in, exit if end-of-file */ -local int readmore(file *in) -{ - if (readin(in) == 0) bye("unexpected end of ", in->name); - return 0; -} - -#define read1(in) (in->left == 0 ? readmore(in) : 0, \ - in->left--, *(in->next)++) - -/* skip over n bytes of in */ -local void skip(file *in, unsigned n) -{ - unsigned bypass; - - if (n > in->left) { - n -= in->left; - bypass = n & ~((1U << in->size) - 1); - if (bypass) { - if (lseek(in->fd, (off_t)bypass, SEEK_CUR) == -1) - bye("seeking ", in->name); - n -= bypass; - } - readmore(in); - if (n > in->left) - bye("unexpected end of ", in->name); - } - in->left -= n; - in->next += n; -} - -/* read a four-byte unsigned integer, little-endian, from in */ -unsigned long read4(file *in) -{ - unsigned long val; - - val = read1(in); - val += (unsigned)read1(in) << 8; - val += (unsigned long)read1(in) << 16; - val += (unsigned long)read1(in) << 24; - return val; -} - -/* skip over gzip header */ -local void gzheader(file *in) -{ - int flags; - unsigned n; - - if (read1(in) != 31 || read1(in) != 139) bye(in->name, " not a gzip file"); - if (read1(in) != 8) bye("unknown compression method in", in->name); - flags = read1(in); - if (flags & 0xe0) bye("unknown header flags set in", in->name); - skip(in, 6); - if (flags & 4) { - n = read1(in); - n += (unsigned)(read1(in)) << 8; - skip(in, n); - } - if (flags & 8) while (read1(in) != 0) ; - if (flags & 16) while (read1(in) != 0) ; - if (flags & 2) skip(in, 2); -} - -/* decompress gzip file "name", return strm with a deflate stream ready to - continue compression of the data in the gzip file, and return a file - descriptor pointing to where to write the compressed data -- the deflate - stream is initialized to compress using level "level" */ -local int gzscan(char *name, z_stream *strm, int level) -{ - int ret, lastbit, left, full; - unsigned have; - unsigned long crc, tot; - unsigned char *window; - off_t lastoff, end; - file gz; - - /* open gzip file */ - gz.name = name; - gz.fd = open(name, O_RDWR, 0); - if (gz.fd == -1) bye("cannot open ", name); - gz.buf = malloc(CHUNK); - if (gz.buf == NULL) bye("out of memory", ""); - gz.size = LGCHUNK; - gz.left = 0; - - /* skip gzip header */ - gzheader(&gz); - - /* prepare to decompress */ - window = malloc(DSIZE); - if (window == NULL) bye("out of memory", ""); - strm->zalloc = Z_NULL; - strm->zfree = Z_NULL; - strm->opaque = Z_NULL; - ret = inflateInit2(strm, -15); - if (ret != Z_OK) bye("out of memory", " or library mismatch"); - - /* decompress the deflate stream, saving append information */ - lastbit = 0; - lastoff = lseek(gz.fd, 0L, SEEK_CUR) - gz.left; - left = 0; - strm->avail_in = gz.left; - strm->next_in = gz.next; - crc = crc32(0L, Z_NULL, 0); - have = full = 0; - do { - /* if needed, get more input */ - if (strm->avail_in == 0) { - readmore(&gz); - strm->avail_in = gz.left; - strm->next_in = gz.next; - } - - /* set up output to next available section of sliding window */ - strm->avail_out = DSIZE - have; - strm->next_out = window + have; - - /* inflate and check for errors */ - ret = inflate(strm, Z_BLOCK); - if (ret == Z_STREAM_ERROR) bye("internal stream error!", ""); - if (ret == Z_MEM_ERROR) bye("out of memory", ""); - if (ret == Z_DATA_ERROR) - bye("invalid compressed data--format violated in", name); - - /* update crc and sliding window pointer */ - crc = crc32(crc, window + have, DSIZE - have - strm->avail_out); - if (strm->avail_out) - have = DSIZE - strm->avail_out; - else { - have = 0; - full = 1; - } - - /* process end of block */ - if (strm->data_type & 128) { - if (strm->data_type & 64) - left = strm->data_type & 0x1f; - else { - lastbit = strm->data_type & 0x1f; - lastoff = lseek(gz.fd, 0L, SEEK_CUR) - strm->avail_in; - } - } - } while (ret != Z_STREAM_END); - inflateEnd(strm); - gz.left = strm->avail_in; - gz.next = strm->next_in; - - /* save the location of the end of the compressed data */ - end = lseek(gz.fd, 0L, SEEK_CUR) - gz.left; - - /* check gzip trailer and save total for deflate */ - if (crc != read4(&gz)) - bye("invalid compressed data--crc mismatch in ", name); - tot = strm->total_out; - if ((tot & 0xffffffffUL) != read4(&gz)) - bye("invalid compressed data--length mismatch in", name); - - /* if not at end of file, warn */ - if (gz.left || readin(&gz)) - fprintf(stderr, - "gzappend warning: junk at end of gzip file overwritten\n"); - - /* clear last block bit */ - lseek(gz.fd, lastoff - (lastbit != 0), SEEK_SET); - if (read(gz.fd, gz.buf, 1) != 1) bye("reading after seek on ", name); - *gz.buf = (unsigned char)(*gz.buf ^ (1 << ((8 - lastbit) & 7))); - lseek(gz.fd, -1L, SEEK_CUR); - if (write(gz.fd, gz.buf, 1) != 1) bye("writing after seek to ", name); - - /* if window wrapped, build dictionary from window by rotating */ - if (full) { - rotate(window, DSIZE, have); - have = DSIZE; - } - - /* set up deflate stream with window, crc, total_in, and leftover bits */ - ret = deflateInit2(strm, level, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY); - if (ret != Z_OK) bye("out of memory", ""); - deflateSetDictionary(strm, window, have); - strm->adler = crc; - strm->total_in = tot; - if (left) { - lseek(gz.fd, --end, SEEK_SET); - if (read(gz.fd, gz.buf, 1) != 1) bye("reading after seek on ", name); - deflatePrime(strm, 8 - left, *gz.buf); - } - lseek(gz.fd, end, SEEK_SET); - - /* clean up and return */ - free(window); - free(gz.buf); - return gz.fd; -} - -/* append file "name" to gzip file gd using deflate stream strm -- if last - is true, then finish off the deflate stream at the end */ -local void gztack(char *name, int gd, z_stream *strm, int last) -{ - int fd, len, ret; - unsigned left; - unsigned char *in, *out; - - /* open file to compress and append */ - fd = 0; - if (name != NULL) { - fd = open(name, O_RDONLY, 0); - if (fd == -1) - fprintf(stderr, "gzappend warning: %s not found, skipping ...\n", - name); - } - - /* allocate buffers */ - in = malloc(CHUNK); - out = malloc(CHUNK); - if (in == NULL || out == NULL) bye("out of memory", ""); - - /* compress input file and append to gzip file */ - do { - /* get more input */ - len = read(fd, in, CHUNK); - if (len == -1) { - fprintf(stderr, - "gzappend warning: error reading %s, skipping rest ...\n", - name); - len = 0; - } - strm->avail_in = (unsigned)len; - strm->next_in = in; - if (len) strm->adler = crc32(strm->adler, in, (unsigned)len); - - /* compress and write all available output */ - do { - strm->avail_out = CHUNK; - strm->next_out = out; - ret = deflate(strm, last && len == 0 ? Z_FINISH : Z_NO_FLUSH); - left = CHUNK - strm->avail_out; - while (left) { - len = write(gd, out + CHUNK - strm->avail_out - left, left); - if (len == -1) bye("writing gzip file", ""); - left -= (unsigned)len; - } - } while (strm->avail_out == 0 && ret != Z_STREAM_END); - } while (len != 0); - - /* write trailer after last entry */ - if (last) { - deflateEnd(strm); - out[0] = (unsigned char)(strm->adler); - out[1] = (unsigned char)(strm->adler >> 8); - out[2] = (unsigned char)(strm->adler >> 16); - out[3] = (unsigned char)(strm->adler >> 24); - out[4] = (unsigned char)(strm->total_in); - out[5] = (unsigned char)(strm->total_in >> 8); - out[6] = (unsigned char)(strm->total_in >> 16); - out[7] = (unsigned char)(strm->total_in >> 24); - len = 8; - do { - ret = write(gd, out + 8 - len, len); - if (ret == -1) bye("writing gzip file", ""); - len -= ret; - } while (len); - close(gd); - } - - /* clean up and return */ - free(out); - free(in); - if (fd > 0) close(fd); -} - -/* process the compression level option if present, scan the gzip file, and - append the specified files, or append the data from stdin if no other file - names are provided on the command line -- the gzip file must be writable - and seekable */ -int main(int argc, char **argv) -{ - int gd, level; - z_stream strm; - - /* ignore command name */ - argc--; argv++; - - /* provide usage if no arguments */ - if (*argv == NULL) { - printf( - "gzappend 1.2 (11 Oct 2012) Copyright (C) 2003, 2012 Mark Adler\n" - ); - printf( - "usage: gzappend [-level] file.gz [ addthis [ andthis ... ]]\n"); - return 0; - } - - /* set compression level */ - level = Z_DEFAULT_COMPRESSION; - if (argv[0][0] == '-') { - if (argv[0][1] < '0' || argv[0][1] > '9' || argv[0][2] != 0) - bye("invalid compression level", ""); - level = argv[0][1] - '0'; - if (*++argv == NULL) bye("no gzip file name after options", ""); - } - - /* prepare to append to gzip file */ - gd = gzscan(*argv++, &strm, level); - - /* append files on command line, or from stdin if none */ - if (*argv == NULL) - gztack(NULL, gd, &strm, 1); - else - do { - gztack(*argv, gd, &strm, argv[1] == NULL); - } while (*++argv != NULL); - return 0; -} diff --git a/src/beast/test/zlib/zlib-1.2.8/examples/gzjoin.c b/src/beast/test/zlib/zlib-1.2.8/examples/gzjoin.c deleted file mode 100644 index 89e8098441b..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/examples/gzjoin.c +++ /dev/null @@ -1,449 +0,0 @@ -/* gzjoin -- command to join gzip files into one gzip file - - Copyright (C) 2004, 2005, 2012 Mark Adler, all rights reserved - version 1.2, 14 Aug 2012 - - This software is provided 'as-is', without any express or implied - warranty. In no event will the author be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Mark Adler madler@alumni.caltech.edu - */ - -/* - * Change history: - * - * 1.0 11 Dec 2004 - First version - * 1.1 12 Jun 2005 - Changed ssize_t to long for portability - * 1.2 14 Aug 2012 - Clean up for z_const usage - */ - -/* - gzjoin takes one or more gzip files on the command line and writes out a - single gzip file that will uncompress to the concatenation of the - uncompressed data from the individual gzip files. gzjoin does this without - having to recompress any of the data and without having to calculate a new - crc32 for the concatenated uncompressed data. gzjoin does however have to - decompress all of the input data in order to find the bits in the compressed - data that need to be modified to concatenate the streams. - - gzjoin does not do an integrity check on the input gzip files other than - checking the gzip header and decompressing the compressed data. They are - otherwise assumed to be complete and correct. - - Each joint between gzip files removes at least 18 bytes of previous trailer - and subsequent header, and inserts an average of about three bytes to the - compressed data in order to connect the streams. The output gzip file - has a minimal ten-byte gzip header with no file name or modification time. - - This program was written to illustrate the use of the Z_BLOCK option of - inflate() and the crc32_combine() function. gzjoin will not compile with - versions of zlib earlier than 1.2.3. - */ - -#include /* fputs(), fprintf(), fwrite(), putc() */ -#include /* exit(), malloc(), free() */ -#include /* open() */ -#include /* close(), read(), lseek() */ -#include "zlib.h" - /* crc32(), crc32_combine(), inflateInit2(), inflate(), inflateEnd() */ - -#define local static - -/* exit with an error (return a value to allow use in an expression) */ -local int bail(char *why1, char *why2) -{ - fprintf(stderr, "gzjoin error: %s%s, output incomplete\n", why1, why2); - exit(1); - return 0; -} - -/* -- simple buffered file input with access to the buffer -- */ - -#define CHUNK 32768 /* must be a power of two and fit in unsigned */ - -/* bin buffered input file type */ -typedef struct { - char *name; /* name of file for error messages */ - int fd; /* file descriptor */ - unsigned left; /* bytes remaining at next */ - unsigned char *next; /* next byte to read */ - unsigned char *buf; /* allocated buffer of length CHUNK */ -} bin; - -/* close a buffered file and free allocated memory */ -local void bclose(bin *in) -{ - if (in != NULL) { - if (in->fd != -1) - close(in->fd); - if (in->buf != NULL) - free(in->buf); - free(in); - } -} - -/* open a buffered file for input, return a pointer to type bin, or NULL on - failure */ -local bin *bopen(char *name) -{ - bin *in; - - in = malloc(sizeof(bin)); - if (in == NULL) - return NULL; - in->buf = malloc(CHUNK); - in->fd = open(name, O_RDONLY, 0); - if (in->buf == NULL || in->fd == -1) { - bclose(in); - return NULL; - } - in->left = 0; - in->next = in->buf; - in->name = name; - return in; -} - -/* load buffer from file, return -1 on read error, 0 or 1 on success, with - 1 indicating that end-of-file was reached */ -local int bload(bin *in) -{ - long len; - - if (in == NULL) - return -1; - if (in->left != 0) - return 0; - in->next = in->buf; - do { - len = (long)read(in->fd, in->buf + in->left, CHUNK - in->left); - if (len < 0) - return -1; - in->left += (unsigned)len; - } while (len != 0 && in->left < CHUNK); - return len == 0 ? 1 : 0; -} - -/* get a byte from the file, bail if end of file */ -#define bget(in) (in->left ? 0 : bload(in), \ - in->left ? (in->left--, *(in->next)++) : \ - bail("unexpected end of file on ", in->name)) - -/* get a four-byte little-endian unsigned integer from file */ -local unsigned long bget4(bin *in) -{ - unsigned long val; - - val = bget(in); - val += (unsigned long)(bget(in)) << 8; - val += (unsigned long)(bget(in)) << 16; - val += (unsigned long)(bget(in)) << 24; - return val; -} - -/* skip bytes in file */ -local void bskip(bin *in, unsigned skip) -{ - /* check pointer */ - if (in == NULL) - return; - - /* easy case -- skip bytes in buffer */ - if (skip <= in->left) { - in->left -= skip; - in->next += skip; - return; - } - - /* skip what's in buffer, discard buffer contents */ - skip -= in->left; - in->left = 0; - - /* seek past multiples of CHUNK bytes */ - if (skip > CHUNK) { - unsigned left; - - left = skip & (CHUNK - 1); - if (left == 0) { - /* exact number of chunks: seek all the way minus one byte to check - for end-of-file with a read */ - lseek(in->fd, skip - 1, SEEK_CUR); - if (read(in->fd, in->buf, 1) != 1) - bail("unexpected end of file on ", in->name); - return; - } - - /* skip the integral chunks, update skip with remainder */ - lseek(in->fd, skip - left, SEEK_CUR); - skip = left; - } - - /* read more input and skip remainder */ - bload(in); - if (skip > in->left) - bail("unexpected end of file on ", in->name); - in->left -= skip; - in->next += skip; -} - -/* -- end of buffered input functions -- */ - -/* skip the gzip header from file in */ -local void gzhead(bin *in) -{ - int flags; - - /* verify gzip magic header and compression method */ - if (bget(in) != 0x1f || bget(in) != 0x8b || bget(in) != 8) - bail(in->name, " is not a valid gzip file"); - - /* get and verify flags */ - flags = bget(in); - if ((flags & 0xe0) != 0) - bail("unknown reserved bits set in ", in->name); - - /* skip modification time, extra flags, and os */ - bskip(in, 6); - - /* skip extra field if present */ - if (flags & 4) { - unsigned len; - - len = bget(in); - len += (unsigned)(bget(in)) << 8; - bskip(in, len); - } - - /* skip file name if present */ - if (flags & 8) - while (bget(in) != 0) - ; - - /* skip comment if present */ - if (flags & 16) - while (bget(in) != 0) - ; - - /* skip header crc if present */ - if (flags & 2) - bskip(in, 2); -} - -/* write a four-byte little-endian unsigned integer to out */ -local void put4(unsigned long val, FILE *out) -{ - putc(val & 0xff, out); - putc((val >> 8) & 0xff, out); - putc((val >> 16) & 0xff, out); - putc((val >> 24) & 0xff, out); -} - -/* Load up zlib stream from buffered input, bail if end of file */ -local void zpull(z_streamp strm, bin *in) -{ - if (in->left == 0) - bload(in); - if (in->left == 0) - bail("unexpected end of file on ", in->name); - strm->avail_in = in->left; - strm->next_in = in->next; -} - -/* Write header for gzip file to out and initialize trailer. */ -local void gzinit(unsigned long *crc, unsigned long *tot, FILE *out) -{ - fwrite("\x1f\x8b\x08\0\0\0\0\0\0\xff", 1, 10, out); - *crc = crc32(0L, Z_NULL, 0); - *tot = 0; -} - -/* Copy the compressed data from name, zeroing the last block bit of the last - block if clr is true, and adding empty blocks as needed to get to a byte - boundary. If clr is false, then the last block becomes the last block of - the output, and the gzip trailer is written. crc and tot maintains the - crc and length (modulo 2^32) of the output for the trailer. The resulting - gzip file is written to out. gzinit() must be called before the first call - of gzcopy() to write the gzip header and to initialize crc and tot. */ -local void gzcopy(char *name, int clr, unsigned long *crc, unsigned long *tot, - FILE *out) -{ - int ret; /* return value from zlib functions */ - int pos; /* where the "last block" bit is in byte */ - int last; /* true if processing the last block */ - bin *in; /* buffered input file */ - unsigned char *start; /* start of compressed data in buffer */ - unsigned char *junk; /* buffer for uncompressed data -- discarded */ - z_off_t len; /* length of uncompressed data (support > 4 GB) */ - z_stream strm; /* zlib inflate stream */ - - /* open gzip file and skip header */ - in = bopen(name); - if (in == NULL) - bail("could not open ", name); - gzhead(in); - - /* allocate buffer for uncompressed data and initialize raw inflate - stream */ - junk = malloc(CHUNK); - strm.zalloc = Z_NULL; - strm.zfree = Z_NULL; - strm.opaque = Z_NULL; - strm.avail_in = 0; - strm.next_in = Z_NULL; - ret = inflateInit2(&strm, -15); - if (junk == NULL || ret != Z_OK) - bail("out of memory", ""); - - /* inflate and copy compressed data, clear last-block bit if requested */ - len = 0; - zpull(&strm, in); - start = in->next; - last = start[0] & 1; - if (last && clr) - start[0] &= ~1; - strm.avail_out = 0; - for (;;) { - /* if input used and output done, write used input and get more */ - if (strm.avail_in == 0 && strm.avail_out != 0) { - fwrite(start, 1, strm.next_in - start, out); - start = in->buf; - in->left = 0; - zpull(&strm, in); - } - - /* decompress -- return early when end-of-block reached */ - strm.avail_out = CHUNK; - strm.next_out = junk; - ret = inflate(&strm, Z_BLOCK); - switch (ret) { - case Z_MEM_ERROR: - bail("out of memory", ""); - case Z_DATA_ERROR: - bail("invalid compressed data in ", in->name); - } - - /* update length of uncompressed data */ - len += CHUNK - strm.avail_out; - - /* check for block boundary (only get this when block copied out) */ - if (strm.data_type & 128) { - /* if that was the last block, then done */ - if (last) - break; - - /* number of unused bits in last byte */ - pos = strm.data_type & 7; - - /* find the next last-block bit */ - if (pos != 0) { - /* next last-block bit is in last used byte */ - pos = 0x100 >> pos; - last = strm.next_in[-1] & pos; - if (last && clr) - in->buf[strm.next_in - in->buf - 1] &= ~pos; - } - else { - /* next last-block bit is in next unused byte */ - if (strm.avail_in == 0) { - /* don't have that byte yet -- get it */ - fwrite(start, 1, strm.next_in - start, out); - start = in->buf; - in->left = 0; - zpull(&strm, in); - } - last = strm.next_in[0] & 1; - if (last && clr) - in->buf[strm.next_in - in->buf] &= ~1; - } - } - } - - /* update buffer with unused input */ - in->left = strm.avail_in; - in->next = in->buf + (strm.next_in - in->buf); - - /* copy used input, write empty blocks to get to byte boundary */ - pos = strm.data_type & 7; - fwrite(start, 1, in->next - start - 1, out); - last = in->next[-1]; - if (pos == 0 || !clr) - /* already at byte boundary, or last file: write last byte */ - putc(last, out); - else { - /* append empty blocks to last byte */ - last &= ((0x100 >> pos) - 1); /* assure unused bits are zero */ - if (pos & 1) { - /* odd -- append an empty stored block */ - putc(last, out); - if (pos == 1) - putc(0, out); /* two more bits in block header */ - fwrite("\0\0\xff\xff", 1, 4, out); - } - else { - /* even -- append 1, 2, or 3 empty fixed blocks */ - switch (pos) { - case 6: - putc(last | 8, out); - last = 0; - case 4: - putc(last | 0x20, out); - last = 0; - case 2: - putc(last | 0x80, out); - putc(0, out); - } - } - } - - /* update crc and tot */ - *crc = crc32_combine(*crc, bget4(in), len); - *tot += (unsigned long)len; - - /* clean up */ - inflateEnd(&strm); - free(junk); - bclose(in); - - /* write trailer if this is the last gzip file */ - if (!clr) { - put4(*crc, out); - put4(*tot, out); - } -} - -/* join the gzip files on the command line, write result to stdout */ -int main(int argc, char **argv) -{ - unsigned long crc, tot; /* running crc and total uncompressed length */ - - /* skip command name */ - argc--; - argv++; - - /* show usage if no arguments */ - if (argc == 0) { - fputs("gzjoin usage: gzjoin f1.gz [f2.gz [f3.gz ...]] > fjoin.gz\n", - stderr); - return 0; - } - - /* join gzip files on command line and write to stdout */ - gzinit(&crc, &tot, stdout); - while (argc--) - gzcopy(*argv++, argc, &crc, &tot, stdout); - - /* done */ - return 0; -} diff --git a/src/beast/test/zlib/zlib-1.2.8/examples/gzlog.c b/src/beast/test/zlib/zlib-1.2.8/examples/gzlog.c deleted file mode 100644 index 922f878dde3..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/examples/gzlog.c +++ /dev/null @@ -1,1059 +0,0 @@ -/* - * gzlog.c - * Copyright (C) 2004, 2008, 2012 Mark Adler, all rights reserved - * For conditions of distribution and use, see copyright notice in gzlog.h - * version 2.2, 14 Aug 2012 - */ - -/* - gzlog provides a mechanism for frequently appending short strings to a gzip - file that is efficient both in execution time and compression ratio. The - strategy is to write the short strings in an uncompressed form to the end of - the gzip file, only compressing when the amount of uncompressed data has - reached a given threshold. - - gzlog also provides protection against interruptions in the process due to - system crashes. The status of the operation is recorded in an extra field - in the gzip file, and is only updated once the gzip file is brought to a - valid state. The last data to be appended or compressed is saved in an - auxiliary file, so that if the operation is interrupted, it can be completed - the next time an append operation is attempted. - - gzlog maintains another auxiliary file with the last 32K of data from the - compressed portion, which is preloaded for the compression of the subsequent - data. This minimizes the impact to the compression ratio of appending. - */ - -/* - Operations Concept: - - Files (log name "foo"): - foo.gz -- gzip file with the complete log - foo.add -- last message to append or last data to compress - foo.dict -- dictionary of the last 32K of data for next compression - foo.temp -- temporary dictionary file for compression after this one - foo.lock -- lock file for reading and writing the other files - foo.repairs -- log file for log file recovery operations (not compressed) - - gzip file structure: - - fixed-length (no file name) header with extra field (see below) - - compressed data ending initially with empty stored block - - uncompressed data filling out originally empty stored block and - subsequent stored blocks as needed (16K max each) - - gzip trailer - - no junk at end (no other gzip streams) - - When appending data, the information in the first three items above plus the - foo.add file are sufficient to recover an interrupted append operation. The - extra field has the necessary information to restore the start of the last - stored block and determine where to append the data in the foo.add file, as - well as the crc and length of the gzip data before the append operation. - - The foo.add file is created before the gzip file is marked for append, and - deleted after the gzip file is marked as complete. So if the append - operation is interrupted, the data to add will still be there. If due to - some external force, the foo.add file gets deleted between when the append - operation was interrupted and when recovery is attempted, the gzip file will - still be restored, but without the appended data. - - When compressing data, the information in the first two items above plus the - foo.add file are sufficient to recover an interrupted compress operation. - The extra field has the necessary information to find the end of the - compressed data, and contains both the crc and length of just the compressed - data and of the complete set of data including the contents of the foo.add - file. - - Again, the foo.add file is maintained during the compress operation in case - of an interruption. If in the unlikely event the foo.add file with the data - to be compressed is missing due to some external force, a gzip file with - just the previous compressed data will be reconstructed. In this case, all - of the data that was to be compressed is lost (approximately one megabyte). - This will not occur if all that happened was an interruption of the compress - operation. - - The third state that is marked is the replacement of the old dictionary with - the new dictionary after a compress operation. Once compression is - complete, the gzip file is marked as being in the replace state. This - completes the gzip file, so an interrupt after being so marked does not - result in recompression. Then the dictionary file is replaced, and the gzip - file is marked as completed. This state prevents the possibility of - restarting compression with the wrong dictionary file. - - All three operations are wrapped by a lock/unlock procedure. In order to - gain exclusive access to the log files, first a foo.lock file must be - exclusively created. When all operations are complete, the lock is - released by deleting the foo.lock file. If when attempting to create the - lock file, it already exists and the modify time of the lock file is more - than five minutes old (set by the PATIENCE define below), then the old - lock file is considered stale and deleted, and the exclusive creation of - the lock file is retried. To assure that there are no false assessments - of the staleness of the lock file, the operations periodically touch the - lock file to update the modified date. - - Following is the definition of the extra field with all of the information - required to enable the above append and compress operations and their - recovery if interrupted. Multi-byte values are stored little endian - (consistent with the gzip format). File pointers are eight bytes long. - The crc's and lengths for the gzip trailer are four bytes long. (Note that - the length at the end of a gzip file is used for error checking only, and - for large files is actually the length modulo 2^32.) The stored block - length is two bytes long. The gzip extra field two-byte identification is - "ap" for append. It is assumed that writing the extra field to the file is - an "atomic" operation. That is, either all of the extra field is written - to the file, or none of it is, if the operation is interrupted right at the - point of updating the extra field. This is a reasonable assumption, since - the extra field is within the first 52 bytes of the file, which is smaller - than any expected block size for a mass storage device (usually 512 bytes or - larger). - - Extra field (35 bytes): - - Pointer to first stored block length -- this points to the two-byte length - of the first stored block, which is followed by the two-byte, one's - complement of that length. The stored block length is preceded by the - three-bit header of the stored block, which is the actual start of the - stored block in the deflate format. See the bit offset field below. - - Pointer to the last stored block length. This is the same as above, but - for the last stored block of the uncompressed data in the gzip file. - Initially this is the same as the first stored block length pointer. - When the stored block gets to 16K (see the MAX_STORE define), then a new - stored block as added, at which point the last stored block length pointer - is different from the first stored block length pointer. When they are - different, the first bit of the last stored block header is eight bits, or - one byte back from the block length. - - Compressed data crc and length. This is the crc and length of the data - that is in the compressed portion of the deflate stream. These are used - only in the event that the foo.add file containing the data to compress is - lost after a compress operation is interrupted. - - Total data crc and length. This is the crc and length of all of the data - stored in the gzip file, compressed and uncompressed. It is used to - reconstruct the gzip trailer when compressing, as well as when recovering - interrupted operations. - - Final stored block length. This is used to quickly find where to append, - and allows the restoration of the original final stored block state when - an append operation is interrupted. - - First stored block start as the number of bits back from the final stored - block first length byte. This value is in the range of 3..10, and is - stored as the low three bits of the final byte of the extra field after - subtracting three (0..7). This allows the last-block bit of the stored - block header to be updated when a new stored block is added, for the case - when the first stored block and the last stored block are the same. (When - they are different, the numbers of bits back is known to be eight.) This - also allows for new compressed data to be appended to the old compressed - data in the compress operation, overwriting the previous first stored - block, or for the compressed data to be terminated and a valid gzip file - reconstructed on the off chance that a compression operation was - interrupted and the data to compress in the foo.add file was deleted. - - The operation in process. This is the next two bits in the last byte (the - bits under the mask 0x18). The are interpreted as 0: nothing in process, - 1: append in process, 2: compress in process, 3: replace in process. - - The top three bits of the last byte in the extra field are reserved and - are currently set to zero. - - Main procedure: - - Exclusively create the foo.lock file using the O_CREAT and O_EXCL modes of - the system open() call. If the modify time of an existing lock file is - more than PATIENCE seconds old, then the lock file is deleted and the - exclusive create is retried. - - Load the extra field from the foo.gz file, and see if an operation was in - progress but not completed. If so, apply the recovery procedure below. - - Perform the append procedure with the provided data. - - If the uncompressed data in the foo.gz file is 1MB or more, apply the - compress procedure. - - Delete the foo.lock file. - - Append procedure: - - Put what to append in the foo.add file so that the operation can be - restarted if this procedure is interrupted. - - Mark the foo.gz extra field with the append operation in progress. - + Restore the original last-block bit and stored block length of the last - stored block from the information in the extra field, in case a previous - append operation was interrupted. - - Append the provided data to the last stored block, creating new stored - blocks as needed and updating the stored blocks last-block bits and - lengths. - - Update the crc and length with the new data, and write the gzip trailer. - - Write over the extra field (with a single write operation) with the new - pointers, lengths, and crc's, and mark the gzip file as not in process. - Though there is still a foo.add file, it will be ignored since nothing - is in process. If a foo.add file is leftover from a previously - completed operation, it is truncated when writing new data to it. - - Delete the foo.add file. - - Compress and replace procedures: - - Read all of the uncompressed data in the stored blocks in foo.gz and write - it to foo.add. Also write foo.temp with the last 32K of that data to - provide a dictionary for the next invocation of this procedure. - - Rewrite the extra field marking foo.gz with a compression in process. - * If there is no data provided to compress (due to a missing foo.add file - when recovering), reconstruct and truncate the foo.gz file to contain - only the previous compressed data and proceed to the step after the next - one. Otherwise ... - - Compress the data with the dictionary in foo.dict, and write to the - foo.gz file starting at the bit immediately following the last previously - compressed block. If there is no foo.dict, proceed anyway with the - compression at slightly reduced efficiency. (For the foo.dict file to be - missing requires some external failure beyond simply the interruption of - a compress operation.) During this process, the foo.lock file is - periodically touched to assure that that file is not considered stale by - another process before we're done. The deflation is terminated with a - non-last empty static block (10 bits long), that is then located and - written over by a last-bit-set empty stored block. - - Append the crc and length of the data in the gzip file (previously - calculated during the append operations). - - Write over the extra field with the updated stored block offsets, bits - back, crc's, and lengths, and mark foo.gz as in process for a replacement - of the dictionary. - @ Delete the foo.add file. - - Replace foo.dict with foo.temp. - - Write over the extra field, marking foo.gz as complete. - - Recovery procedure: - - If not a replace recovery, read in the foo.add file, and provide that data - to the appropriate recovery below. If there is no foo.add file, provide - a zero data length to the recovery. In that case, the append recovery - restores the foo.gz to the previous compressed + uncompressed data state. - For the the compress recovery, a missing foo.add file results in foo.gz - being restored to the previous compressed-only data state. - - Append recovery: - - Pick up append at + step above - - Compress recovery: - - Pick up compress at * step above - - Replace recovery: - - Pick up compress at @ step above - - Log the repair with a date stamp in foo.repairs - */ - -#include -#include /* rename, fopen, fprintf, fclose */ -#include /* malloc, free */ -#include /* strlen, strrchr, strcpy, strncpy, strcmp */ -#include /* open */ -#include /* lseek, read, write, close, unlink, sleep, */ - /* ftruncate, fsync */ -#include /* errno */ -#include /* time, ctime */ -#include /* stat */ -#include /* utimes */ -#include "zlib.h" /* crc32 */ - -#include "gzlog.h" /* header for external access */ - -#define local static -typedef unsigned int uint; -typedef unsigned long ulong; - -/* Macro for debugging to deterministically force recovery operations */ -#ifdef DEBUG - #include /* longjmp */ - jmp_buf gzlog_jump; /* where to go back to */ - int gzlog_bail = 0; /* which point to bail at (1..8) */ - int gzlog_count = -1; /* number of times through to wait */ -# define BAIL(n) do { if (n == gzlog_bail && gzlog_count-- == 0) \ - longjmp(gzlog_jump, gzlog_bail); } while (0) -#else -# define BAIL(n) -#endif - -/* how old the lock file can be in seconds before considering it stale */ -#define PATIENCE 300 - -/* maximum stored block size in Kbytes -- must be in 1..63 */ -#define MAX_STORE 16 - -/* number of stored Kbytes to trigger compression (must be >= 32 to allow - dictionary construction, and <= 204 * MAX_STORE, in order for >> 10 to - discard the stored block headers contribution of five bytes each) */ -#define TRIGGER 1024 - -/* size of a deflate dictionary (this cannot be changed) */ -#define DICT 32768U - -/* values for the operation (2 bits) */ -#define NO_OP 0 -#define APPEND_OP 1 -#define COMPRESS_OP 2 -#define REPLACE_OP 3 - -/* macros to extract little-endian integers from an unsigned byte buffer */ -#define PULL2(p) ((p)[0]+((uint)((p)[1])<<8)) -#define PULL4(p) (PULL2(p)+((ulong)PULL2(p+2)<<16)) -#define PULL8(p) (PULL4(p)+((off_t)PULL4(p+4)<<32)) - -/* macros to store integers into a byte buffer in little-endian order */ -#define PUT2(p,a) do {(p)[0]=a;(p)[1]=(a)>>8;} while(0) -#define PUT4(p,a) do {PUT2(p,a);PUT2(p+2,a>>16);} while(0) -#define PUT8(p,a) do {PUT4(p,a);PUT4(p+4,a>>32);} while(0) - -/* internal structure for log information */ -#define LOGID "\106\035\172" /* should be three non-zero characters */ -struct log { - char id[4]; /* contains LOGID to detect inadvertent overwrites */ - int fd; /* file descriptor for .gz file, opened read/write */ - char *path; /* allocated path, e.g. "/var/log/foo" or "foo" */ - char *end; /* end of path, for appending suffices such as ".gz" */ - off_t first; /* offset of first stored block first length byte */ - int back; /* location of first block id in bits back from first */ - uint stored; /* bytes currently in last stored block */ - off_t last; /* offset of last stored block first length byte */ - ulong ccrc; /* crc of compressed data */ - ulong clen; /* length (modulo 2^32) of compressed data */ - ulong tcrc; /* crc of total data */ - ulong tlen; /* length (modulo 2^32) of total data */ - time_t lock; /* last modify time of our lock file */ -}; - -/* gzip header for gzlog */ -local unsigned char log_gzhead[] = { - 0x1f, 0x8b, /* magic gzip id */ - 8, /* compression method is deflate */ - 4, /* there is an extra field (no file name) */ - 0, 0, 0, 0, /* no modification time provided */ - 0, 0xff, /* no extra flags, no OS specified */ - 39, 0, 'a', 'p', 35, 0 /* extra field with "ap" subfield */ - /* 35 is EXTRA, 39 is EXTRA + 4 */ -}; - -#define HEAD sizeof(log_gzhead) /* should be 16 */ - -/* initial gzip extra field content (52 == HEAD + EXTRA + 1) */ -local unsigned char log_gzext[] = { - 52, 0, 0, 0, 0, 0, 0, 0, /* offset of first stored block length */ - 52, 0, 0, 0, 0, 0, 0, 0, /* offset of last stored block length */ - 0, 0, 0, 0, 0, 0, 0, 0, /* compressed data crc and length */ - 0, 0, 0, 0, 0, 0, 0, 0, /* total data crc and length */ - 0, 0, /* final stored block data length */ - 5 /* op is NO_OP, last bit 8 bits back */ -}; - -#define EXTRA sizeof(log_gzext) /* should be 35 */ - -/* initial gzip data and trailer */ -local unsigned char log_gzbody[] = { - 1, 0, 0, 0xff, 0xff, /* empty stored block (last) */ - 0, 0, 0, 0, /* crc */ - 0, 0, 0, 0 /* uncompressed length */ -}; - -#define BODY sizeof(log_gzbody) - -/* Exclusively create foo.lock in order to negotiate exclusive access to the - foo.* files. If the modify time of an existing lock file is greater than - PATIENCE seconds in the past, then consider the lock file to have been - abandoned, delete it, and try the exclusive create again. Save the lock - file modify time for verification of ownership. Return 0 on success, or -1 - on failure, usually due to an access restriction or invalid path. Note that - if stat() or unlink() fails, it may be due to another process noticing the - abandoned lock file a smidge sooner and deleting it, so those are not - flagged as an error. */ -local int log_lock(struct log *log) -{ - int fd; - struct stat st; - - strcpy(log->end, ".lock"); - while ((fd = open(log->path, O_CREAT | O_EXCL, 0644)) < 0) { - if (errno != EEXIST) - return -1; - if (stat(log->path, &st) == 0 && time(NULL) - st.st_mtime > PATIENCE) { - unlink(log->path); - continue; - } - sleep(2); /* relinquish the CPU for two seconds while waiting */ - } - close(fd); - if (stat(log->path, &st) == 0) - log->lock = st.st_mtime; - return 0; -} - -/* Update the modify time of the lock file to now, in order to prevent another - task from thinking that the lock is stale. Save the lock file modify time - for verification of ownership. */ -local void log_touch(struct log *log) -{ - struct stat st; - - strcpy(log->end, ".lock"); - utimes(log->path, NULL); - if (stat(log->path, &st) == 0) - log->lock = st.st_mtime; -} - -/* Check the log file modify time against what is expected. Return true if - this is not our lock. If it is our lock, touch it to keep it. */ -local int log_check(struct log *log) -{ - struct stat st; - - strcpy(log->end, ".lock"); - if (stat(log->path, &st) || st.st_mtime != log->lock) - return 1; - log_touch(log); - return 0; -} - -/* Unlock a previously acquired lock, but only if it's ours. */ -local void log_unlock(struct log *log) -{ - if (log_check(log)) - return; - strcpy(log->end, ".lock"); - unlink(log->path); - log->lock = 0; -} - -/* Check the gzip header and read in the extra field, filling in the values in - the log structure. Return op on success or -1 if the gzip header was not as - expected. op is the current operation in progress last written to the extra - field. This assumes that the gzip file has already been opened, with the - file descriptor log->fd. */ -local int log_head(struct log *log) -{ - int op; - unsigned char buf[HEAD + EXTRA]; - - if (lseek(log->fd, 0, SEEK_SET) < 0 || - read(log->fd, buf, HEAD + EXTRA) != HEAD + EXTRA || - memcmp(buf, log_gzhead, HEAD)) { - return -1; - } - log->first = PULL8(buf + HEAD); - log->last = PULL8(buf + HEAD + 8); - log->ccrc = PULL4(buf + HEAD + 16); - log->clen = PULL4(buf + HEAD + 20); - log->tcrc = PULL4(buf + HEAD + 24); - log->tlen = PULL4(buf + HEAD + 28); - log->stored = PULL2(buf + HEAD + 32); - log->back = 3 + (buf[HEAD + 34] & 7); - op = (buf[HEAD + 34] >> 3) & 3; - return op; -} - -/* Write over the extra field contents, marking the operation as op. Use fsync - to assure that the device is written to, and in the requested order. This - operation, and only this operation, is assumed to be atomic in order to - assure that the log is recoverable in the event of an interruption at any - point in the process. Return -1 if the write to foo.gz failed. */ -local int log_mark(struct log *log, int op) -{ - int ret; - unsigned char ext[EXTRA]; - - PUT8(ext, log->first); - PUT8(ext + 8, log->last); - PUT4(ext + 16, log->ccrc); - PUT4(ext + 20, log->clen); - PUT4(ext + 24, log->tcrc); - PUT4(ext + 28, log->tlen); - PUT2(ext + 32, log->stored); - ext[34] = log->back - 3 + (op << 3); - fsync(log->fd); - ret = lseek(log->fd, HEAD, SEEK_SET) < 0 || - write(log->fd, ext, EXTRA) != EXTRA ? -1 : 0; - fsync(log->fd); - return ret; -} - -/* Rewrite the last block header bits and subsequent zero bits to get to a byte - boundary, setting the last block bit if last is true, and then write the - remainder of the stored block header (length and one's complement). Leave - the file pointer after the end of the last stored block data. Return -1 if - there is a read or write failure on the foo.gz file */ -local int log_last(struct log *log, int last) -{ - int back, len, mask; - unsigned char buf[6]; - - /* determine the locations of the bytes and bits to modify */ - back = log->last == log->first ? log->back : 8; - len = back > 8 ? 2 : 1; /* bytes back from log->last */ - mask = 0x80 >> ((back - 1) & 7); /* mask for block last-bit */ - - /* get the byte to modify (one or two back) into buf[0] -- don't need to - read the byte if the last-bit is eight bits back, since in that case - the entire byte will be modified */ - buf[0] = 0; - if (back != 8 && (lseek(log->fd, log->last - len, SEEK_SET) < 0 || - read(log->fd, buf, 1) != 1)) - return -1; - - /* change the last-bit of the last stored block as requested -- note - that all bits above the last-bit are set to zero, per the type bits - of a stored block being 00 and per the convention that the bits to - bring the stream to a byte boundary are also zeros */ - buf[1] = 0; - buf[2 - len] = (*buf & (mask - 1)) + (last ? mask : 0); - - /* write the modified stored block header and lengths, move the file - pointer to after the last stored block data */ - PUT2(buf + 2, log->stored); - PUT2(buf + 4, log->stored ^ 0xffff); - return lseek(log->fd, log->last - len, SEEK_SET) < 0 || - write(log->fd, buf + 2 - len, len + 4) != len + 4 || - lseek(log->fd, log->stored, SEEK_CUR) < 0 ? -1 : 0; -} - -/* Append len bytes from data to the locked and open log file. len may be zero - if recovering and no .add file was found. In that case, the previous state - of the foo.gz file is restored. The data is appended uncompressed in - deflate stored blocks. Return -1 if there was an error reading or writing - the foo.gz file. */ -local int log_append(struct log *log, unsigned char *data, size_t len) -{ - uint put; - off_t end; - unsigned char buf[8]; - - /* set the last block last-bit and length, in case recovering an - interrupted append, then position the file pointer to append to the - block */ - if (log_last(log, 1)) - return -1; - - /* append, adding stored blocks and updating the offset of the last stored - block as needed, and update the total crc and length */ - while (len) { - /* append as much as we can to the last block */ - put = (MAX_STORE << 10) - log->stored; - if (put > len) - put = (uint)len; - if (put) { - if (write(log->fd, data, put) != put) - return -1; - BAIL(1); - log->tcrc = crc32(log->tcrc, data, put); - log->tlen += put; - log->stored += put; - data += put; - len -= put; - } - - /* if we need to, add a new empty stored block */ - if (len) { - /* mark current block as not last */ - if (log_last(log, 0)) - return -1; - - /* point to new, empty stored block */ - log->last += 4 + log->stored + 1; - log->stored = 0; - } - - /* mark last block as last, update its length */ - if (log_last(log, 1)) - return -1; - BAIL(2); - } - - /* write the new crc and length trailer, and truncate just in case (could - be recovering from partial append with a missing foo.add file) */ - PUT4(buf, log->tcrc); - PUT4(buf + 4, log->tlen); - if (write(log->fd, buf, 8) != 8 || - (end = lseek(log->fd, 0, SEEK_CUR)) < 0 || ftruncate(log->fd, end)) - return -1; - - /* write the extra field, marking the log file as done, delete .add file */ - if (log_mark(log, NO_OP)) - return -1; - strcpy(log->end, ".add"); - unlink(log->path); /* ignore error, since may not exist */ - return 0; -} - -/* Replace the foo.dict file with the foo.temp file. Also delete the foo.add - file, since the compress operation may have been interrupted before that was - done. Returns 1 if memory could not be allocated, or -1 if reading or - writing foo.gz fails, or if the rename fails for some reason other than - foo.temp not existing. foo.temp not existing is a permitted error, since - the replace operation may have been interrupted after the rename is done, - but before foo.gz is marked as complete. */ -local int log_replace(struct log *log) -{ - int ret; - char *dest; - - /* delete foo.add file */ - strcpy(log->end, ".add"); - unlink(log->path); /* ignore error, since may not exist */ - BAIL(3); - - /* rename foo.name to foo.dict, replacing foo.dict if it exists */ - strcpy(log->end, ".dict"); - dest = malloc(strlen(log->path) + 1); - if (dest == NULL) - return -2; - strcpy(dest, log->path); - strcpy(log->end, ".temp"); - ret = rename(log->path, dest); - free(dest); - if (ret && errno != ENOENT) - return -1; - BAIL(4); - - /* mark the foo.gz file as done */ - return log_mark(log, NO_OP); -} - -/* Compress the len bytes at data and append the compressed data to the - foo.gz deflate data immediately after the previous compressed data. This - overwrites the previous uncompressed data, which was stored in foo.add - and is the data provided in data[0..len-1]. If this operation is - interrupted, it picks up at the start of this routine, with the foo.add - file read in again. If there is no data to compress (len == 0), then we - simply terminate the foo.gz file after the previously compressed data, - appending a final empty stored block and the gzip trailer. Return -1 if - reading or writing the log.gz file failed, or -2 if there was a memory - allocation failure. */ -local int log_compress(struct log *log, unsigned char *data, size_t len) -{ - int fd; - uint got, max; - ssize_t dict; - off_t end; - z_stream strm; - unsigned char buf[DICT]; - - /* compress and append compressed data */ - if (len) { - /* set up for deflate, allocating memory */ - strm.zalloc = Z_NULL; - strm.zfree = Z_NULL; - strm.opaque = Z_NULL; - if (deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -15, 8, - Z_DEFAULT_STRATEGY) != Z_OK) - return -2; - - /* read in dictionary (last 32K of data that was compressed) */ - strcpy(log->end, ".dict"); - fd = open(log->path, O_RDONLY, 0); - if (fd >= 0) { - dict = read(fd, buf, DICT); - close(fd); - if (dict < 0) { - deflateEnd(&strm); - return -1; - } - if (dict) - deflateSetDictionary(&strm, buf, (uint)dict); - } - log_touch(log); - - /* prime deflate with last bits of previous block, position write - pointer to write those bits and overwrite what follows */ - if (lseek(log->fd, log->first - (log->back > 8 ? 2 : 1), - SEEK_SET) < 0 || - read(log->fd, buf, 1) != 1 || lseek(log->fd, -1, SEEK_CUR) < 0) { - deflateEnd(&strm); - return -1; - } - deflatePrime(&strm, (8 - log->back) & 7, *buf); - - /* compress, finishing with a partial non-last empty static block */ - strm.next_in = data; - max = (((uint)0 - 1) >> 1) + 1; /* in case int smaller than size_t */ - do { - strm.avail_in = len > max ? max : (uint)len; - len -= strm.avail_in; - do { - strm.avail_out = DICT; - strm.next_out = buf; - deflate(&strm, len ? Z_NO_FLUSH : Z_PARTIAL_FLUSH); - got = DICT - strm.avail_out; - if (got && write(log->fd, buf, got) != got) { - deflateEnd(&strm); - return -1; - } - log_touch(log); - } while (strm.avail_out == 0); - } while (len); - deflateEnd(&strm); - BAIL(5); - - /* find start of empty static block -- scanning backwards the first one - bit is the second bit of the block, if the last byte is zero, then - we know the byte before that has a one in the top bit, since an - empty static block is ten bits long */ - if ((log->first = lseek(log->fd, -1, SEEK_CUR)) < 0 || - read(log->fd, buf, 1) != 1) - return -1; - log->first++; - if (*buf) { - log->back = 1; - while ((*buf & ((uint)1 << (8 - log->back++))) == 0) - ; /* guaranteed to terminate, since *buf != 0 */ - } - else - log->back = 10; - - /* update compressed crc and length */ - log->ccrc = log->tcrc; - log->clen = log->tlen; - } - else { - /* no data to compress -- fix up existing gzip stream */ - log->tcrc = log->ccrc; - log->tlen = log->clen; - } - - /* complete and truncate gzip stream */ - log->last = log->first; - log->stored = 0; - PUT4(buf, log->tcrc); - PUT4(buf + 4, log->tlen); - if (log_last(log, 1) || write(log->fd, buf, 8) != 8 || - (end = lseek(log->fd, 0, SEEK_CUR)) < 0 || ftruncate(log->fd, end)) - return -1; - BAIL(6); - - /* mark as being in the replace operation */ - if (log_mark(log, REPLACE_OP)) - return -1; - - /* execute the replace operation and mark the file as done */ - return log_replace(log); -} - -/* log a repair record to the .repairs file */ -local void log_log(struct log *log, int op, char *record) -{ - time_t now; - FILE *rec; - - now = time(NULL); - strcpy(log->end, ".repairs"); - rec = fopen(log->path, "a"); - if (rec == NULL) - return; - fprintf(rec, "%.24s %s recovery: %s\n", ctime(&now), op == APPEND_OP ? - "append" : (op == COMPRESS_OP ? "compress" : "replace"), record); - fclose(rec); - return; -} - -/* Recover the interrupted operation op. First read foo.add for recovering an - append or compress operation. Return -1 if there was an error reading or - writing foo.gz or reading an existing foo.add, or -2 if there was a memory - allocation failure. */ -local int log_recover(struct log *log, int op) -{ - int fd, ret = 0; - unsigned char *data = NULL; - size_t len = 0; - struct stat st; - - /* log recovery */ - log_log(log, op, "start"); - - /* load foo.add file if expected and present */ - if (op == APPEND_OP || op == COMPRESS_OP) { - strcpy(log->end, ".add"); - if (stat(log->path, &st) == 0 && st.st_size) { - len = (size_t)(st.st_size); - if ((off_t)len != st.st_size || - (data = malloc(st.st_size)) == NULL) { - log_log(log, op, "allocation failure"); - return -2; - } - if ((fd = open(log->path, O_RDONLY, 0)) < 0) { - log_log(log, op, ".add file read failure"); - return -1; - } - ret = (size_t)read(fd, data, len) != len; - close(fd); - if (ret) { - log_log(log, op, ".add file read failure"); - return -1; - } - log_log(log, op, "loaded .add file"); - } - else - log_log(log, op, "missing .add file!"); - } - - /* recover the interrupted operation */ - switch (op) { - case APPEND_OP: - ret = log_append(log, data, len); - break; - case COMPRESS_OP: - ret = log_compress(log, data, len); - break; - case REPLACE_OP: - ret = log_replace(log); - } - - /* log status */ - log_log(log, op, ret ? "failure" : "complete"); - - /* clean up */ - if (data != NULL) - free(data); - return ret; -} - -/* Close the foo.gz file (if open) and release the lock. */ -local void log_close(struct log *log) -{ - if (log->fd >= 0) - close(log->fd); - log->fd = -1; - log_unlock(log); -} - -/* Open foo.gz, verify the header, and load the extra field contents, after - first creating the foo.lock file to gain exclusive access to the foo.* - files. If foo.gz does not exist or is empty, then write the initial header, - extra, and body content of an empty foo.gz log file. If there is an error - creating the lock file due to access restrictions, or an error reading or - writing the foo.gz file, or if the foo.gz file is not a proper log file for - this object (e.g. not a gzip file or does not contain the expected extra - field), then return true. If there is an error, the lock is released. - Otherwise, the lock is left in place. */ -local int log_open(struct log *log) -{ - int op; - - /* release open file resource if left over -- can occur if lock lost - between gzlog_open() and gzlog_write() */ - if (log->fd >= 0) - close(log->fd); - log->fd = -1; - - /* negotiate exclusive access */ - if (log_lock(log) < 0) - return -1; - - /* open the log file, foo.gz */ - strcpy(log->end, ".gz"); - log->fd = open(log->path, O_RDWR | O_CREAT, 0644); - if (log->fd < 0) { - log_close(log); - return -1; - } - - /* if new, initialize foo.gz with an empty log, delete old dictionary */ - if (lseek(log->fd, 0, SEEK_END) == 0) { - if (write(log->fd, log_gzhead, HEAD) != HEAD || - write(log->fd, log_gzext, EXTRA) != EXTRA || - write(log->fd, log_gzbody, BODY) != BODY) { - log_close(log); - return -1; - } - strcpy(log->end, ".dict"); - unlink(log->path); - } - - /* verify log file and load extra field information */ - if ((op = log_head(log)) < 0) { - log_close(log); - return -1; - } - - /* check for interrupted process and if so, recover */ - if (op != NO_OP && log_recover(log, op)) { - log_close(log); - return -1; - } - - /* touch the lock file to prevent another process from grabbing it */ - log_touch(log); - return 0; -} - -/* See gzlog.h for the description of the external methods below */ -gzlog *gzlog_open(char *path) -{ - size_t n; - struct log *log; - - /* check arguments */ - if (path == NULL || *path == 0) - return NULL; - - /* allocate and initialize log structure */ - log = malloc(sizeof(struct log)); - if (log == NULL) - return NULL; - strcpy(log->id, LOGID); - log->fd = -1; - - /* save path and end of path for name construction */ - n = strlen(path); - log->path = malloc(n + 9); /* allow for ".repairs" */ - if (log->path == NULL) { - free(log); - return NULL; - } - strcpy(log->path, path); - log->end = log->path + n; - - /* gain exclusive access and verify log file -- may perform a - recovery operation if needed */ - if (log_open(log)) { - free(log->path); - free(log); - return NULL; - } - - /* return pointer to log structure */ - return log; -} - -/* gzlog_compress() return values: - 0: all good - -1: file i/o error (usually access issue) - -2: memory allocation failure - -3: invalid log pointer argument */ -int gzlog_compress(gzlog *logd) -{ - int fd, ret; - uint block; - size_t len, next; - unsigned char *data, buf[5]; - struct log *log = logd; - - /* check arguments */ - if (log == NULL || strcmp(log->id, LOGID)) - return -3; - - /* see if we lost the lock -- if so get it again and reload the extra - field information (it probably changed), recover last operation if - necessary */ - if (log_check(log) && log_open(log)) - return -1; - - /* create space for uncompressed data */ - len = ((size_t)(log->last - log->first) & ~(((size_t)1 << 10) - 1)) + - log->stored; - if ((data = malloc(len)) == NULL) - return -2; - - /* do statement here is just a cheap trick for error handling */ - do { - /* read in the uncompressed data */ - if (lseek(log->fd, log->first - 1, SEEK_SET) < 0) - break; - next = 0; - while (next < len) { - if (read(log->fd, buf, 5) != 5) - break; - block = PULL2(buf + 1); - if (next + block > len || - read(log->fd, (char *)data + next, block) != block) - break; - next += block; - } - if (lseek(log->fd, 0, SEEK_CUR) != log->last + 4 + log->stored) - break; - log_touch(log); - - /* write the uncompressed data to the .add file */ - strcpy(log->end, ".add"); - fd = open(log->path, O_WRONLY | O_CREAT | O_TRUNC, 0644); - if (fd < 0) - break; - ret = (size_t)write(fd, data, len) != len; - if (ret | close(fd)) - break; - log_touch(log); - - /* write the dictionary for the next compress to the .temp file */ - strcpy(log->end, ".temp"); - fd = open(log->path, O_WRONLY | O_CREAT | O_TRUNC, 0644); - if (fd < 0) - break; - next = DICT > len ? len : DICT; - ret = (size_t)write(fd, (char *)data + len - next, next) != next; - if (ret | close(fd)) - break; - log_touch(log); - - /* roll back to compressed data, mark the compress in progress */ - log->last = log->first; - log->stored = 0; - if (log_mark(log, COMPRESS_OP)) - break; - BAIL(7); - - /* compress and append the data (clears mark) */ - ret = log_compress(log, data, len); - free(data); - return ret; - } while (0); - - /* broke out of do above on i/o error */ - free(data); - return -1; -} - -/* gzlog_write() return values: - 0: all good - -1: file i/o error (usually access issue) - -2: memory allocation failure - -3: invalid log pointer argument */ -int gzlog_write(gzlog *logd, void *data, size_t len) -{ - int fd, ret; - struct log *log = logd; - - /* check arguments */ - if (log == NULL || strcmp(log->id, LOGID)) - return -3; - if (data == NULL || len <= 0) - return 0; - - /* see if we lost the lock -- if so get it again and reload the extra - field information (it probably changed), recover last operation if - necessary */ - if (log_check(log) && log_open(log)) - return -1; - - /* create and write .add file */ - strcpy(log->end, ".add"); - fd = open(log->path, O_WRONLY | O_CREAT | O_TRUNC, 0644); - if (fd < 0) - return -1; - ret = (size_t)write(fd, data, len) != len; - if (ret | close(fd)) - return -1; - log_touch(log); - - /* mark log file with append in progress */ - if (log_mark(log, APPEND_OP)) - return -1; - BAIL(8); - - /* append data (clears mark) */ - if (log_append(log, data, len)) - return -1; - - /* check to see if it's time to compress -- if not, then done */ - if (((log->last - log->first) >> 10) + (log->stored >> 10) < TRIGGER) - return 0; - - /* time to compress */ - return gzlog_compress(log); -} - -/* gzlog_close() return values: - 0: ok - -3: invalid log pointer argument */ -int gzlog_close(gzlog *logd) -{ - struct log *log = logd; - - /* check arguments */ - if (log == NULL || strcmp(log->id, LOGID)) - return -3; - - /* close the log file and release the lock */ - log_close(log); - - /* free structure and return */ - if (log->path != NULL) - free(log->path); - strcpy(log->id, "bad"); - free(log); - return 0; -} diff --git a/src/beast/test/zlib/zlib-1.2.8/examples/gzlog.h b/src/beast/test/zlib/zlib-1.2.8/examples/gzlog.h deleted file mode 100644 index 86f0cecba5b..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/examples/gzlog.h +++ /dev/null @@ -1,91 +0,0 @@ -/* gzlog.h - Copyright (C) 2004, 2008, 2012 Mark Adler, all rights reserved - version 2.2, 14 Aug 2012 - - This software is provided 'as-is', without any express or implied - warranty. In no event will the author be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Mark Adler madler@alumni.caltech.edu - */ - -/* Version History: - 1.0 26 Nov 2004 First version - 2.0 25 Apr 2008 Complete redesign for recovery of interrupted operations - Interface changed slightly in that now path is a prefix - Compression now occurs as needed during gzlog_write() - gzlog_write() now always leaves the log file as valid gzip - 2.1 8 Jul 2012 Fix argument checks in gzlog_compress() and gzlog_write() - 2.2 14 Aug 2012 Clean up signed comparisons - */ - -/* - The gzlog object allows writing short messages to a gzipped log file, - opening the log file locked for small bursts, and then closing it. The log - object works by appending stored (uncompressed) data to the gzip file until - 1 MB has been accumulated. At that time, the stored data is compressed, and - replaces the uncompressed data in the file. The log file is truncated to - its new size at that time. After each write operation, the log file is a - valid gzip file that can decompressed to recover what was written. - - The gzlog operations can be interupted at any point due to an application or - system crash, and the log file will be recovered the next time the log is - opened with gzlog_open(). - */ - -#ifndef GZLOG_H -#define GZLOG_H - -/* gzlog object type */ -typedef void gzlog; - -/* Open a gzlog object, creating the log file if it does not exist. Return - NULL on error. Note that gzlog_open() could take a while to complete if it - has to wait to verify that a lock is stale (possibly for five minutes), or - if there is significant contention with other instantiations of this object - when locking the resource. path is the prefix of the file names created by - this object. If path is "foo", then the log file will be "foo.gz", and - other auxiliary files will be created and destroyed during the process: - "foo.dict" for a compression dictionary, "foo.temp" for a temporary (next) - dictionary, "foo.add" for data being added or compressed, "foo.lock" for the - lock file, and "foo.repairs" to log recovery operations performed due to - interrupted gzlog operations. A gzlog_open() followed by a gzlog_close() - will recover a previously interrupted operation, if any. */ -gzlog *gzlog_open(char *path); - -/* Write to a gzlog object. Return zero on success, -1 if there is a file i/o - error on any of the gzlog files (this should not happen if gzlog_open() - succeeded, unless the device has run out of space or leftover auxiliary - files have permissions or ownership that prevent their use), -2 if there is - a memory allocation failure, or -3 if the log argument is invalid (e.g. if - it was not created by gzlog_open()). This function will write data to the - file uncompressed, until 1 MB has been accumulated, at which time that data - will be compressed. The log file will be a valid gzip file upon successful - return. */ -int gzlog_write(gzlog *log, void *data, size_t len); - -/* Force compression of any uncompressed data in the log. This should be used - sparingly, if at all. The main application would be when a log file will - not be appended to again. If this is used to compress frequently while - appending, it will both significantly increase the execution time and - reduce the compression ratio. The return codes are the same as for - gzlog_write(). */ -int gzlog_compress(gzlog *log); - -/* Close a gzlog object. Return zero on success, -3 if the log argument is - invalid. The log object is freed, and so cannot be referenced again. */ -int gzlog_close(gzlog *log); - -#endif diff --git a/src/beast/test/zlib/zlib-1.2.8/examples/zlib_how.html b/src/beast/test/zlib/zlib-1.2.8/examples/zlib_how.html deleted file mode 100644 index 444ff1c9a32..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/examples/zlib_how.html +++ /dev/null @@ -1,545 +0,0 @@ - - - - -zlib Usage Example - - - -

zlib Usage Example

-We often get questions about how the deflate() and inflate() functions should be used. -Users wonder when they should provide more input, when they should use more output, -what to do with a Z_BUF_ERROR, how to make sure the process terminates properly, and -so on. So for those who have read zlib.h (a few times), and -would like further edification, below is an annotated example in C of simple routines to compress and decompress -from an input file to an output file using deflate() and inflate() respectively. The -annotations are interspersed between lines of the code. So please read between the lines. -We hope this helps explain some of the intricacies of zlib. -

-Without further adieu, here is the program zpipe.c: -


-/* zpipe.c: example of proper use of zlib's inflate() and deflate()
-   Not copyrighted -- provided to the public domain
-   Version 1.4  11 December 2005  Mark Adler */
-
-/* Version history:
-   1.0  30 Oct 2004  First version
-   1.1   8 Nov 2004  Add void casting for unused return values
-                     Use switch statement for inflate() return values
-   1.2   9 Nov 2004  Add assertions to document zlib guarantees
-   1.3   6 Apr 2005  Remove incorrect assertion in inf()
-   1.4  11 Dec 2005  Add hack to avoid MSDOS end-of-line conversions
-                     Avoid some compiler warnings for input and output buffers
- */
-
-We now include the header files for the required definitions. From -stdio.h we use fopen(), fread(), fwrite(), -feof(), ferror(), and fclose() for file i/o, and -fputs() for error messages. From string.h we use -strcmp() for command line argument processing. -From assert.h we use the assert() macro. -From zlib.h -we use the basic compression functions deflateInit(), -deflate(), and deflateEnd(), and the basic decompression -functions inflateInit(), inflate(), and -inflateEnd(). -

-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-#include "zlib.h"
-
-This is an ugly hack required to avoid corruption of the input and output data on -Windows/MS-DOS systems. Without this, those systems would assume that the input and output -files are text, and try to convert the end-of-line characters from one standard to -another. That would corrupt binary data, and in particular would render the compressed data unusable. -This sets the input and output to binary which suppresses the end-of-line conversions. -SET_BINARY_MODE() will be used later on stdin and stdout, at the beginning of main(). -

-#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
-#  include <fcntl.h>
-#  include <io.h>
-#  define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
-#else
-#  define SET_BINARY_MODE(file)
-#endif
-
-CHUNK is simply the buffer size for feeding data to and pulling data -from the zlib routines. Larger buffer sizes would be more efficient, -especially for inflate(). If the memory is available, buffers sizes -on the order of 128K or 256K bytes should be used. -

-#define CHUNK 16384
-
-The def() routine compresses data from an input file to an output file. The output data -will be in the zlib format, which is different from the gzip or zip -formats. The zlib format has a very small header of only two bytes to identify it as -a zlib stream and to provide decoding information, and a four-byte trailer with a fast -check value to verify the integrity of the uncompressed data after decoding. -

-/* Compress from file source to file dest until EOF on source.
-   def() returns Z_OK on success, Z_MEM_ERROR if memory could not be
-   allocated for processing, Z_STREAM_ERROR if an invalid compression
-   level is supplied, Z_VERSION_ERROR if the version of zlib.h and the
-   version of the library linked do not match, or Z_ERRNO if there is
-   an error reading or writing the files. */
-int def(FILE *source, FILE *dest, int level)
-{
-
-Here are the local variables for def(). ret will be used for zlib -return codes. flush will keep track of the current flushing state for deflate(), -which is either no flushing, or flush to completion after the end of the input file is reached. -have is the amount of data returned from deflate(). The strm structure -is used to pass information to and from the zlib routines, and to maintain the -deflate() state. in and out are the input and output buffers for -deflate(). -

-    int ret, flush;
-    unsigned have;
-    z_stream strm;
-    unsigned char in[CHUNK];
-    unsigned char out[CHUNK];
-
-The first thing we do is to initialize the zlib state for compression using -deflateInit(). This must be done before the first use of deflate(). -The zalloc, zfree, and opaque fields in the strm -structure must be initialized before calling deflateInit(). Here they are -set to the zlib constant Z_NULL to request that zlib use -the default memory allocation routines. An application may also choose to provide -custom memory allocation routines here. deflateInit() will allocate on the -order of 256K bytes for the internal state. -(See zlib Technical Details.) -

-deflateInit() is called with a pointer to the structure to be initialized and -the compression level, which is an integer in the range of -1 to 9. Lower compression -levels result in faster execution, but less compression. Higher levels result in -greater compression, but slower execution. The zlib constant Z_DEFAULT_COMPRESSION, -equal to -1, -provides a good compromise between compression and speed and is equivalent to level 6. -Level 0 actually does no compression at all, and in fact expands the data slightly to produce -the zlib format (it is not a byte-for-byte copy of the input). -More advanced applications of zlib -may use deflateInit2() here instead. Such an application may want to reduce how -much memory will be used, at some price in compression. Or it may need to request a -gzip header and trailer instead of a zlib header and trailer, or raw -encoding with no header or trailer at all. -

-We must check the return value of deflateInit() against the zlib constant -Z_OK to make sure that it was able to -allocate memory for the internal state, and that the provided arguments were valid. -deflateInit() will also check that the version of zlib that the zlib.h -file came from matches the version of zlib actually linked with the program. This -is especially important for environments in which zlib is a shared library. -

-Note that an application can initialize multiple, independent zlib streams, which can -operate in parallel. The state information maintained in the structure allows the zlib -routines to be reentrant. -


-    /* allocate deflate state */
-    strm.zalloc = Z_NULL;
-    strm.zfree = Z_NULL;
-    strm.opaque = Z_NULL;
-    ret = deflateInit(&strm, level);
-    if (ret != Z_OK)
-        return ret;
-
-With the pleasantries out of the way, now we can get down to business. The outer do-loop -reads all of the input file and exits at the bottom of the loop once end-of-file is reached. -This loop contains the only call of deflate(). So we must make sure that all of the -input data has been processed and that all of the output data has been generated and consumed -before we fall out of the loop at the bottom. -

-    /* compress until end of file */
-    do {
-
-We start off by reading data from the input file. The number of bytes read is put directly -into avail_in, and a pointer to those bytes is put into next_in. We also -check to see if end-of-file on the input has been reached. If we are at the end of file, then flush is set to the -zlib constant Z_FINISH, which is later passed to deflate() to -indicate that this is the last chunk of input data to compress. We need to use feof() -to check for end-of-file as opposed to seeing if fewer than CHUNK bytes have been read. The -reason is that if the input file length is an exact multiple of CHUNK, we will miss -the fact that we got to the end-of-file, and not know to tell deflate() to finish -up the compressed stream. If we are not yet at the end of the input, then the zlib -constant Z_NO_FLUSH will be passed to deflate to indicate that we are still -in the middle of the uncompressed data. -

-If there is an error in reading from the input file, the process is aborted with -deflateEnd() being called to free the allocated zlib state before returning -the error. We wouldn't want a memory leak, now would we? deflateEnd() can be called -at any time after the state has been initialized. Once that's done, deflateInit() (or -deflateInit2()) would have to be called to start a new compression process. There is -no point here in checking the deflateEnd() return code. The deallocation can't fail. -


-        strm.avail_in = fread(in, 1, CHUNK, source);
-        if (ferror(source)) {
-            (void)deflateEnd(&strm);
-            return Z_ERRNO;
-        }
-        flush = feof(source) ? Z_FINISH : Z_NO_FLUSH;
-        strm.next_in = in;
-
-The inner do-loop passes our chunk of input data to deflate(), and then -keeps calling deflate() until it is done producing output. Once there is no more -new output, deflate() is guaranteed to have consumed all of the input, i.e., -avail_in will be zero. -

-        /* run deflate() on input until output buffer not full, finish
-           compression if all of source has been read in */
-        do {
-
-Output space is provided to deflate() by setting avail_out to the number -of available output bytes and next_out to a pointer to that space. -

-            strm.avail_out = CHUNK;
-            strm.next_out = out;
-
-Now we call the compression engine itself, deflate(). It takes as many of the -avail_in bytes at next_in as it can process, and writes as many as -avail_out bytes to next_out. Those counters and pointers are then -updated past the input data consumed and the output data written. It is the amount of -output space available that may limit how much input is consumed. -Hence the inner loop to make sure that -all of the input is consumed by providing more output space each time. Since avail_in -and next_in are updated by deflate(), we don't have to mess with those -between deflate() calls until it's all used up. -

-The parameters to deflate() are a pointer to the strm structure containing -the input and output information and the internal compression engine state, and a parameter -indicating whether and how to flush data to the output. Normally deflate will consume -several K bytes of input data before producing any output (except for the header), in order -to accumulate statistics on the data for optimum compression. It will then put out a burst of -compressed data, and proceed to consume more input before the next burst. Eventually, -deflate() -must be told to terminate the stream, complete the compression with provided input data, and -write out the trailer check value. deflate() will continue to compress normally as long -as the flush parameter is Z_NO_FLUSH. Once the Z_FINISH parameter is provided, -deflate() will begin to complete the compressed output stream. However depending on how -much output space is provided, deflate() may have to be called several times until it -has provided the complete compressed stream, even after it has consumed all of the input. The flush -parameter must continue to be Z_FINISH for those subsequent calls. -

-There are other values of the flush parameter that are used in more advanced applications. You can -force deflate() to produce a burst of output that encodes all of the input data provided -so far, even if it wouldn't have otherwise, for example to control data latency on a link with -compressed data. You can also ask that deflate() do that as well as erase any history up to -that point so that what follows can be decompressed independently, for example for random access -applications. Both requests will degrade compression by an amount depending on how often such -requests are made. -

-deflate() has a return value that can indicate errors, yet we do not check it here. Why -not? Well, it turns out that deflate() can do no wrong here. Let's go through -deflate()'s return values and dispense with them one by one. The possible values are -Z_OK, Z_STREAM_END, Z_STREAM_ERROR, or Z_BUF_ERROR. Z_OK -is, well, ok. Z_STREAM_END is also ok and will be returned for the last call of -deflate(). This is already guaranteed by calling deflate() with Z_FINISH -until it has no more output. Z_STREAM_ERROR is only possible if the stream is not -initialized properly, but we did initialize it properly. There is no harm in checking for -Z_STREAM_ERROR here, for example to check for the possibility that some -other part of the application inadvertently clobbered the memory containing the zlib state. -Z_BUF_ERROR will be explained further below, but -suffice it to say that this is simply an indication that deflate() could not consume -more input or produce more output. deflate() can be called again with more output space -or more available input, which it will be in this code. -


-            ret = deflate(&strm, flush);    /* no bad return value */
-            assert(ret != Z_STREAM_ERROR);  /* state not clobbered */
-
-Now we compute how much output deflate() provided on the last call, which is the -difference between how much space was provided before the call, and how much output space -is still available after the call. Then that data, if any, is written to the output file. -We can then reuse the output buffer for the next call of deflate(). Again if there -is a file i/o error, we call deflateEnd() before returning to avoid a memory leak. -

-            have = CHUNK - strm.avail_out;
-            if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
-                (void)deflateEnd(&strm);
-                return Z_ERRNO;
-            }
-
-The inner do-loop is repeated until the last deflate() call fails to fill the -provided output buffer. Then we know that deflate() has done as much as it can with -the provided input, and that all of that input has been consumed. We can then fall out of this -loop and reuse the input buffer. -

-The way we tell that deflate() has no more output is by seeing that it did not fill -the output buffer, leaving avail_out greater than zero. However suppose that -deflate() has no more output, but just so happened to exactly fill the output buffer! -avail_out is zero, and we can't tell that deflate() has done all it can. -As far as we know, deflate() -has more output for us. So we call it again. But now deflate() produces no output -at all, and avail_out remains unchanged as CHUNK. That deflate() call -wasn't able to do anything, either consume input or produce output, and so it returns -Z_BUF_ERROR. (See, I told you I'd cover this later.) However this is not a problem at -all. Now we finally have the desired indication that deflate() is really done, -and so we drop out of the inner loop to provide more input to deflate(). -

-With flush set to Z_FINISH, this final set of deflate() calls will -complete the output stream. Once that is done, subsequent calls of deflate() would return -Z_STREAM_ERROR if the flush parameter is not Z_FINISH, and do no more processing -until the state is reinitialized. -

-Some applications of zlib have two loops that call deflate() -instead of the single inner loop we have here. The first loop would call -without flushing and feed all of the data to deflate(). The second loop would call -deflate() with no more -data and the Z_FINISH parameter to complete the process. As you can see from this -example, that can be avoided by simply keeping track of the current flush state. -


-        } while (strm.avail_out == 0);
-        assert(strm.avail_in == 0);     /* all input will be used */
-
-Now we check to see if we have already processed all of the input file. That information was -saved in the flush variable, so we see if that was set to Z_FINISH. If so, -then we're done and we fall out of the outer loop. We're guaranteed to get Z_STREAM_END -from the last deflate() call, since we ran it until the last chunk of input was -consumed and all of the output was generated. -

-        /* done when last data in file processed */
-    } while (flush != Z_FINISH);
-    assert(ret == Z_STREAM_END);        /* stream will be complete */
-
-The process is complete, but we still need to deallocate the state to avoid a memory leak -(or rather more like a memory hemorrhage if you didn't do this). Then -finally we can return with a happy return value. -

-    /* clean up and return */
-    (void)deflateEnd(&strm);
-    return Z_OK;
-}
-
-Now we do the same thing for decompression in the inf() routine. inf() -decompresses what is hopefully a valid zlib stream from the input file and writes the -uncompressed data to the output file. Much of the discussion above for def() -applies to inf() as well, so the discussion here will focus on the differences between -the two. -

-/* Decompress from file source to file dest until stream ends or EOF.
-   inf() returns Z_OK on success, Z_MEM_ERROR if memory could not be
-   allocated for processing, Z_DATA_ERROR if the deflate data is
-   invalid or incomplete, Z_VERSION_ERROR if the version of zlib.h and
-   the version of the library linked do not match, or Z_ERRNO if there
-   is an error reading or writing the files. */
-int inf(FILE *source, FILE *dest)
-{
-
-The local variables have the same functionality as they do for def(). The -only difference is that there is no flush variable, since inflate() -can tell from the zlib stream itself when the stream is complete. -

-    int ret;
-    unsigned have;
-    z_stream strm;
-    unsigned char in[CHUNK];
-    unsigned char out[CHUNK];
-
-The initialization of the state is the same, except that there is no compression level, -of course, and two more elements of the structure are initialized. avail_in -and next_in must be initialized before calling inflateInit(). This -is because the application has the option to provide the start of the zlib stream in -order for inflateInit() to have access to information about the compression -method to aid in memory allocation. In the current implementation of zlib -(up through versions 1.2.x), the method-dependent memory allocations are deferred to the first call of -inflate() anyway. However those fields must be initialized since later versions -of zlib that provide more compression methods may take advantage of this interface. -In any case, no decompression is performed by inflateInit(), so the -avail_out and next_out fields do not need to be initialized before calling. -

-Here avail_in is set to zero and next_in is set to Z_NULL to -indicate that no input data is being provided. -


-    /* allocate inflate state */
-    strm.zalloc = Z_NULL;
-    strm.zfree = Z_NULL;
-    strm.opaque = Z_NULL;
-    strm.avail_in = 0;
-    strm.next_in = Z_NULL;
-    ret = inflateInit(&strm);
-    if (ret != Z_OK)
-        return ret;
-
-The outer do-loop decompresses input until inflate() indicates -that it has reached the end of the compressed data and has produced all of the uncompressed -output. This is in contrast to def() which processes all of the input file. -If end-of-file is reached before the compressed data self-terminates, then the compressed -data is incomplete and an error is returned. -

-    /* decompress until deflate stream ends or end of file */
-    do {
-
-We read input data and set the strm structure accordingly. If we've reached the -end of the input file, then we leave the outer loop and report an error, since the -compressed data is incomplete. Note that we may read more data than is eventually consumed -by inflate(), if the input file continues past the zlib stream. -For applications where zlib streams are embedded in other data, this routine would -need to be modified to return the unused data, or at least indicate how much of the input -data was not used, so the application would know where to pick up after the zlib stream. -

-        strm.avail_in = fread(in, 1, CHUNK, source);
-        if (ferror(source)) {
-            (void)inflateEnd(&strm);
-            return Z_ERRNO;
-        }
-        if (strm.avail_in == 0)
-            break;
-        strm.next_in = in;
-
-The inner do-loop has the same function it did in def(), which is to -keep calling inflate() until has generated all of the output it can with the -provided input. -

-        /* run inflate() on input until output buffer not full */
-        do {
-
-Just like in def(), the same output space is provided for each call of inflate(). -

-            strm.avail_out = CHUNK;
-            strm.next_out = out;
-
-Now we run the decompression engine itself. There is no need to adjust the flush parameter, since -the zlib format is self-terminating. The main difference here is that there are -return values that we need to pay attention to. Z_DATA_ERROR -indicates that inflate() detected an error in the zlib compressed data format, -which means that either the data is not a zlib stream to begin with, or that the data was -corrupted somewhere along the way since it was compressed. The other error to be processed is -Z_MEM_ERROR, which can occur since memory allocation is deferred until inflate() -needs it, unlike deflate(), whose memory is allocated at the start by deflateInit(). -

-Advanced applications may use -deflateSetDictionary() to prime deflate() with a set of likely data to improve the -first 32K or so of compression. This is noted in the zlib header, so inflate() -requests that that dictionary be provided before it can start to decompress. Without the dictionary, -correct decompression is not possible. For this routine, we have no idea what the dictionary is, -so the Z_NEED_DICT indication is converted to a Z_DATA_ERROR. -

-inflate() can also return Z_STREAM_ERROR, which should not be possible here, -but could be checked for as noted above for def(). Z_BUF_ERROR does not need to be -checked for here, for the same reasons noted for def(). Z_STREAM_END will be -checked for later. -


-            ret = inflate(&strm, Z_NO_FLUSH);
-            assert(ret != Z_STREAM_ERROR);  /* state not clobbered */
-            switch (ret) {
-            case Z_NEED_DICT:
-                ret = Z_DATA_ERROR;     /* and fall through */
-            case Z_DATA_ERROR:
-            case Z_MEM_ERROR:
-                (void)inflateEnd(&strm);
-                return ret;
-            }
-
-The output of inflate() is handled identically to that of deflate(). -

-            have = CHUNK - strm.avail_out;
-            if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
-                (void)inflateEnd(&strm);
-                return Z_ERRNO;
-            }
-
-The inner do-loop ends when inflate() has no more output as indicated -by not filling the output buffer, just as for deflate(). In this case, we cannot -assert that strm.avail_in will be zero, since the deflate stream may end before the file -does. -

-        } while (strm.avail_out == 0);
-
-The outer do-loop ends when inflate() reports that it has reached the -end of the input zlib stream, has completed the decompression and integrity -check, and has provided all of the output. This is indicated by the inflate() -return value Z_STREAM_END. The inner loop is guaranteed to leave ret -equal to Z_STREAM_END if the last chunk of the input file read contained the end -of the zlib stream. So if the return value is not Z_STREAM_END, the -loop continues to read more input. -

-        /* done when inflate() says it's done */
-    } while (ret != Z_STREAM_END);
-
-At this point, decompression successfully completed, or we broke out of the loop due to no -more data being available from the input file. If the last inflate() return value -is not Z_STREAM_END, then the zlib stream was incomplete and a data error -is returned. Otherwise, we return with a happy return value. Of course, inflateEnd() -is called first to avoid a memory leak. -

-    /* clean up and return */
-    (void)inflateEnd(&strm);
-    return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
-}
-
-That ends the routines that directly use zlib. The following routines make this -a command-line program by running data through the above routines from stdin to -stdout, and handling any errors reported by def() or inf(). -

-zerr() is used to interpret the possible error codes from def() -and inf(), as detailed in their comments above, and print out an error message. -Note that these are only a subset of the possible return values from deflate() -and inflate(). -


-/* report a zlib or i/o error */
-void zerr(int ret)
-{
-    fputs("zpipe: ", stderr);
-    switch (ret) {
-    case Z_ERRNO:
-        if (ferror(stdin))
-            fputs("error reading stdin\n", stderr);
-        if (ferror(stdout))
-            fputs("error writing stdout\n", stderr);
-        break;
-    case Z_STREAM_ERROR:
-        fputs("invalid compression level\n", stderr);
-        break;
-    case Z_DATA_ERROR:
-        fputs("invalid or incomplete deflate data\n", stderr);
-        break;
-    case Z_MEM_ERROR:
-        fputs("out of memory\n", stderr);
-        break;
-    case Z_VERSION_ERROR:
-        fputs("zlib version mismatch!\n", stderr);
-    }
-}
-
-Here is the main() routine used to test def() and inf(). The -zpipe command is simply a compression pipe from stdin to stdout, if -no arguments are given, or it is a decompression pipe if zpipe -d is used. If any other -arguments are provided, no compression or decompression is performed. Instead a usage -message is displayed. Examples are zpipe < foo.txt > foo.txt.z to compress, and -zpipe -d < foo.txt.z > foo.txt to decompress. -

-/* compress or decompress from stdin to stdout */
-int main(int argc, char **argv)
-{
-    int ret;
-
-    /* avoid end-of-line conversions */
-    SET_BINARY_MODE(stdin);
-    SET_BINARY_MODE(stdout);
-
-    /* do compression if no arguments */
-    if (argc == 1) {
-        ret = def(stdin, stdout, Z_DEFAULT_COMPRESSION);
-        if (ret != Z_OK)
-            zerr(ret);
-        return ret;
-    }
-
-    /* do decompression if -d specified */
-    else if (argc == 2 && strcmp(argv[1], "-d") == 0) {
-        ret = inf(stdin, stdout);
-        if (ret != Z_OK)
-            zerr(ret);
-        return ret;
-    }
-
-    /* otherwise, report usage */
-    else {
-        fputs("zpipe usage: zpipe [-d] < source > dest\n", stderr);
-        return 1;
-    }
-}
-
-
-Copyright (c) 2004, 2005 by Mark Adler
Last modified 11 December 2005
- - diff --git a/src/beast/test/zlib/zlib-1.2.8/examples/zpipe.c b/src/beast/test/zlib/zlib-1.2.8/examples/zpipe.c deleted file mode 100644 index 83535d16935..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/examples/zpipe.c +++ /dev/null @@ -1,205 +0,0 @@ -/* zpipe.c: example of proper use of zlib's inflate() and deflate() - Not copyrighted -- provided to the public domain - Version 1.4 11 December 2005 Mark Adler */ - -/* Version history: - 1.0 30 Oct 2004 First version - 1.1 8 Nov 2004 Add void casting for unused return values - Use switch statement for inflate() return values - 1.2 9 Nov 2004 Add assertions to document zlib guarantees - 1.3 6 Apr 2005 Remove incorrect assertion in inf() - 1.4 11 Dec 2005 Add hack to avoid MSDOS end-of-line conversions - Avoid some compiler warnings for input and output buffers - */ - -#include -#include -#include -#include "zlib.h" - -#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) -# include -# include -# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) -#else -# define SET_BINARY_MODE(file) -#endif - -#define CHUNK 16384 - -/* Compress from file source to file dest until EOF on source. - def() returns Z_OK on success, Z_MEM_ERROR if memory could not be - allocated for processing, Z_STREAM_ERROR if an invalid compression - level is supplied, Z_VERSION_ERROR if the version of zlib.h and the - version of the library linked do not match, or Z_ERRNO if there is - an error reading or writing the files. */ -int def(FILE *source, FILE *dest, int level) -{ - int ret, flush; - unsigned have; - z_stream strm; - unsigned char in[CHUNK]; - unsigned char out[CHUNK]; - - /* allocate deflate state */ - strm.zalloc = Z_NULL; - strm.zfree = Z_NULL; - strm.opaque = Z_NULL; - ret = deflateInit(&strm, level); - if (ret != Z_OK) - return ret; - - /* compress until end of file */ - do { - strm.avail_in = fread(in, 1, CHUNK, source); - if (ferror(source)) { - (void)deflateEnd(&strm); - return Z_ERRNO; - } - flush = feof(source) ? Z_FINISH : Z_NO_FLUSH; - strm.next_in = in; - - /* run deflate() on input until output buffer not full, finish - compression if all of source has been read in */ - do { - strm.avail_out = CHUNK; - strm.next_out = out; - ret = deflate(&strm, flush); /* no bad return value */ - assert(ret != Z_STREAM_ERROR); /* state not clobbered */ - have = CHUNK - strm.avail_out; - if (fwrite(out, 1, have, dest) != have || ferror(dest)) { - (void)deflateEnd(&strm); - return Z_ERRNO; - } - } while (strm.avail_out == 0); - assert(strm.avail_in == 0); /* all input will be used */ - - /* done when last data in file processed */ - } while (flush != Z_FINISH); - assert(ret == Z_STREAM_END); /* stream will be complete */ - - /* clean up and return */ - (void)deflateEnd(&strm); - return Z_OK; -} - -/* Decompress from file source to file dest until stream ends or EOF. - inf() returns Z_OK on success, Z_MEM_ERROR if memory could not be - allocated for processing, Z_DATA_ERROR if the deflate data is - invalid or incomplete, Z_VERSION_ERROR if the version of zlib.h and - the version of the library linked do not match, or Z_ERRNO if there - is an error reading or writing the files. */ -int inf(FILE *source, FILE *dest) -{ - int ret; - unsigned have; - z_stream strm; - unsigned char in[CHUNK]; - unsigned char out[CHUNK]; - - /* allocate inflate state */ - strm.zalloc = Z_NULL; - strm.zfree = Z_NULL; - strm.opaque = Z_NULL; - strm.avail_in = 0; - strm.next_in = Z_NULL; - ret = inflateInit(&strm); - if (ret != Z_OK) - return ret; - - /* decompress until deflate stream ends or end of file */ - do { - strm.avail_in = fread(in, 1, CHUNK, source); - if (ferror(source)) { - (void)inflateEnd(&strm); - return Z_ERRNO; - } - if (strm.avail_in == 0) - break; - strm.next_in = in; - - /* run inflate() on input until output buffer not full */ - do { - strm.avail_out = CHUNK; - strm.next_out = out; - ret = inflate(&strm, Z_NO_FLUSH); - assert(ret != Z_STREAM_ERROR); /* state not clobbered */ - switch (ret) { - case Z_NEED_DICT: - ret = Z_DATA_ERROR; /* and fall through */ - case Z_DATA_ERROR: - case Z_MEM_ERROR: - (void)inflateEnd(&strm); - return ret; - } - have = CHUNK - strm.avail_out; - if (fwrite(out, 1, have, dest) != have || ferror(dest)) { - (void)inflateEnd(&strm); - return Z_ERRNO; - } - } while (strm.avail_out == 0); - - /* done when inflate() says it's done */ - } while (ret != Z_STREAM_END); - - /* clean up and return */ - (void)inflateEnd(&strm); - return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR; -} - -/* report a zlib or i/o error */ -void zerr(int ret) -{ - fputs("zpipe: ", stderr); - switch (ret) { - case Z_ERRNO: - if (ferror(stdin)) - fputs("error reading stdin\n", stderr); - if (ferror(stdout)) - fputs("error writing stdout\n", stderr); - break; - case Z_STREAM_ERROR: - fputs("invalid compression level\n", stderr); - break; - case Z_DATA_ERROR: - fputs("invalid or incomplete deflate data\n", stderr); - break; - case Z_MEM_ERROR: - fputs("out of memory\n", stderr); - break; - case Z_VERSION_ERROR: - fputs("zlib version mismatch!\n", stderr); - } -} - -/* compress or decompress from stdin to stdout */ -int main(int argc, char **argv) -{ - int ret; - - /* avoid end-of-line conversions */ - SET_BINARY_MODE(stdin); - SET_BINARY_MODE(stdout); - - /* do compression if no arguments */ - if (argc == 1) { - ret = def(stdin, stdout, Z_DEFAULT_COMPRESSION); - if (ret != Z_OK) - zerr(ret); - return ret; - } - - /* do decompression if -d specified */ - else if (argc == 2 && strcmp(argv[1], "-d") == 0) { - ret = inf(stdin, stdout); - if (ret != Z_OK) - zerr(ret); - return ret; - } - - /* otherwise, report usage */ - else { - fputs("zpipe usage: zpipe [-d] < source > dest\n", stderr); - return 1; - } -} diff --git a/src/beast/test/zlib/zlib-1.2.8/examples/zran.c b/src/beast/test/zlib/zlib-1.2.8/examples/zran.c deleted file mode 100644 index 278f9ad07d2..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/examples/zran.c +++ /dev/null @@ -1,409 +0,0 @@ -/* zran.c -- example of zlib/gzip stream indexing and random access - * Copyright (C) 2005, 2012 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - Version 1.1 29 Sep 2012 Mark Adler */ - -/* Version History: - 1.0 29 May 2005 First version - 1.1 29 Sep 2012 Fix memory reallocation error - */ - -/* Illustrate the use of Z_BLOCK, inflatePrime(), and inflateSetDictionary() - for random access of a compressed file. A file containing a zlib or gzip - stream is provided on the command line. The compressed stream is decoded in - its entirety, and an index built with access points about every SPAN bytes - in the uncompressed output. The compressed file is left open, and can then - be read randomly, having to decompress on the average SPAN/2 uncompressed - bytes before getting to the desired block of data. - - An access point can be created at the start of any deflate block, by saving - the starting file offset and bit of that block, and the 32K bytes of - uncompressed data that precede that block. Also the uncompressed offset of - that block is saved to provide a referece for locating a desired starting - point in the uncompressed stream. build_index() works by decompressing the - input zlib or gzip stream a block at a time, and at the end of each block - deciding if enough uncompressed data has gone by to justify the creation of - a new access point. If so, that point is saved in a data structure that - grows as needed to accommodate the points. - - To use the index, an offset in the uncompressed data is provided, for which - the latest accees point at or preceding that offset is located in the index. - The input file is positioned to the specified location in the index, and if - necessary the first few bits of the compressed data is read from the file. - inflate is initialized with those bits and the 32K of uncompressed data, and - the decompression then proceeds until the desired offset in the file is - reached. Then the decompression continues to read the desired uncompressed - data from the file. - - Another approach would be to generate the index on demand. In that case, - requests for random access reads from the compressed data would try to use - the index, but if a read far enough past the end of the index is required, - then further index entries would be generated and added. - - There is some fair bit of overhead to starting inflation for the random - access, mainly copying the 32K byte dictionary. So if small pieces of the - file are being accessed, it would make sense to implement a cache to hold - some lookahead and avoid many calls to extract() for small lengths. - - Another way to build an index would be to use inflateCopy(). That would - not be constrained to have access points at block boundaries, but requires - more memory per access point, and also cannot be saved to file due to the - use of pointers in the state. The approach here allows for storage of the - index in a file. - */ - -#include -#include -#include -#include "zlib.h" - -#define local static - -#define SPAN 1048576L /* desired distance between access points */ -#define WINSIZE 32768U /* sliding window size */ -#define CHUNK 16384 /* file input buffer size */ - -/* access point entry */ -struct point { - off_t out; /* corresponding offset in uncompressed data */ - off_t in; /* offset in input file of first full byte */ - int bits; /* number of bits (1-7) from byte at in - 1, or 0 */ - unsigned char window[WINSIZE]; /* preceding 32K of uncompressed data */ -}; - -/* access point list */ -struct access { - int have; /* number of list entries filled in */ - int size; /* number of list entries allocated */ - struct point *list; /* allocated list */ -}; - -/* Deallocate an index built by build_index() */ -local void free_index(struct access *index) -{ - if (index != NULL) { - free(index->list); - free(index); - } -} - -/* Add an entry to the access point list. If out of memory, deallocate the - existing list and return NULL. */ -local struct access *addpoint(struct access *index, int bits, - off_t in, off_t out, unsigned left, unsigned char *window) -{ - struct point *next; - - /* if list is empty, create it (start with eight points) */ - if (index == NULL) { - index = malloc(sizeof(struct access)); - if (index == NULL) return NULL; - index->list = malloc(sizeof(struct point) << 3); - if (index->list == NULL) { - free(index); - return NULL; - } - index->size = 8; - index->have = 0; - } - - /* if list is full, make it bigger */ - else if (index->have == index->size) { - index->size <<= 1; - next = realloc(index->list, sizeof(struct point) * index->size); - if (next == NULL) { - free_index(index); - return NULL; - } - index->list = next; - } - - /* fill in entry and increment how many we have */ - next = index->list + index->have; - next->bits = bits; - next->in = in; - next->out = out; - if (left) - memcpy(next->window, window + WINSIZE - left, left); - if (left < WINSIZE) - memcpy(next->window + left, window, WINSIZE - left); - index->have++; - - /* return list, possibly reallocated */ - return index; -} - -/* Make one entire pass through the compressed stream and build an index, with - access points about every span bytes of uncompressed output -- span is - chosen to balance the speed of random access against the memory requirements - of the list, about 32K bytes per access point. Note that data after the end - of the first zlib or gzip stream in the file is ignored. build_index() - returns the number of access points on success (>= 1), Z_MEM_ERROR for out - of memory, Z_DATA_ERROR for an error in the input file, or Z_ERRNO for a - file read error. On success, *built points to the resulting index. */ -local int build_index(FILE *in, off_t span, struct access **built) -{ - int ret; - off_t totin, totout; /* our own total counters to avoid 4GB limit */ - off_t last; /* totout value of last access point */ - struct access *index; /* access points being generated */ - z_stream strm; - unsigned char input[CHUNK]; - unsigned char window[WINSIZE]; - - /* initialize inflate */ - strm.zalloc = Z_NULL; - strm.zfree = Z_NULL; - strm.opaque = Z_NULL; - strm.avail_in = 0; - strm.next_in = Z_NULL; - ret = inflateInit2(&strm, 47); /* automatic zlib or gzip decoding */ - if (ret != Z_OK) - return ret; - - /* inflate the input, maintain a sliding window, and build an index -- this - also validates the integrity of the compressed data using the check - information at the end of the gzip or zlib stream */ - totin = totout = last = 0; - index = NULL; /* will be allocated by first addpoint() */ - strm.avail_out = 0; - do { - /* get some compressed data from input file */ - strm.avail_in = fread(input, 1, CHUNK, in); - if (ferror(in)) { - ret = Z_ERRNO; - goto build_index_error; - } - if (strm.avail_in == 0) { - ret = Z_DATA_ERROR; - goto build_index_error; - } - strm.next_in = input; - - /* process all of that, or until end of stream */ - do { - /* reset sliding window if necessary */ - if (strm.avail_out == 0) { - strm.avail_out = WINSIZE; - strm.next_out = window; - } - - /* inflate until out of input, output, or at end of block -- - update the total input and output counters */ - totin += strm.avail_in; - totout += strm.avail_out; - ret = inflate(&strm, Z_BLOCK); /* return at end of block */ - totin -= strm.avail_in; - totout -= strm.avail_out; - if (ret == Z_NEED_DICT) - ret = Z_DATA_ERROR; - if (ret == Z_MEM_ERROR || ret == Z_DATA_ERROR) - goto build_index_error; - if (ret == Z_STREAM_END) - break; - - /* if at end of block, consider adding an index entry (note that if - data_type indicates an end-of-block, then all of the - uncompressed data from that block has been delivered, and none - of the compressed data after that block has been consumed, - except for up to seven bits) -- the totout == 0 provides an - entry point after the zlib or gzip header, and assures that the - index always has at least one access point; we avoid creating an - access point after the last block by checking bit 6 of data_type - */ - if ((strm.data_type & 128) && !(strm.data_type & 64) && - (totout == 0 || totout - last > span)) { - index = addpoint(index, strm.data_type & 7, totin, - totout, strm.avail_out, window); - if (index == NULL) { - ret = Z_MEM_ERROR; - goto build_index_error; - } - last = totout; - } - } while (strm.avail_in != 0); - } while (ret != Z_STREAM_END); - - /* clean up and return index (release unused entries in list) */ - (void)inflateEnd(&strm); - index->list = realloc(index->list, sizeof(struct point) * index->have); - index->size = index->have; - *built = index; - return index->size; - - /* return error */ - build_index_error: - (void)inflateEnd(&strm); - if (index != NULL) - free_index(index); - return ret; -} - -/* Use the index to read len bytes from offset into buf, return bytes read or - negative for error (Z_DATA_ERROR or Z_MEM_ERROR). If data is requested past - the end of the uncompressed data, then extract() will return a value less - than len, indicating how much as actually read into buf. This function - should not return a data error unless the file was modified since the index - was generated. extract() may also return Z_ERRNO if there is an error on - reading or seeking the input file. */ -local int extract(FILE *in, struct access *index, off_t offset, - unsigned char *buf, int len) -{ - int ret, skip; - z_stream strm; - struct point *here; - unsigned char input[CHUNK]; - unsigned char discard[WINSIZE]; - - /* proceed only if something reasonable to do */ - if (len < 0) - return 0; - - /* find where in stream to start */ - here = index->list; - ret = index->have; - while (--ret && here[1].out <= offset) - here++; - - /* initialize file and inflate state to start there */ - strm.zalloc = Z_NULL; - strm.zfree = Z_NULL; - strm.opaque = Z_NULL; - strm.avail_in = 0; - strm.next_in = Z_NULL; - ret = inflateInit2(&strm, -15); /* raw inflate */ - if (ret != Z_OK) - return ret; - ret = fseeko(in, here->in - (here->bits ? 1 : 0), SEEK_SET); - if (ret == -1) - goto extract_ret; - if (here->bits) { - ret = getc(in); - if (ret == -1) { - ret = ferror(in) ? Z_ERRNO : Z_DATA_ERROR; - goto extract_ret; - } - (void)inflatePrime(&strm, here->bits, ret >> (8 - here->bits)); - } - (void)inflateSetDictionary(&strm, here->window, WINSIZE); - - /* skip uncompressed bytes until offset reached, then satisfy request */ - offset -= here->out; - strm.avail_in = 0; - skip = 1; /* while skipping to offset */ - do { - /* define where to put uncompressed data, and how much */ - if (offset == 0 && skip) { /* at offset now */ - strm.avail_out = len; - strm.next_out = buf; - skip = 0; /* only do this once */ - } - if (offset > WINSIZE) { /* skip WINSIZE bytes */ - strm.avail_out = WINSIZE; - strm.next_out = discard; - offset -= WINSIZE; - } - else if (offset != 0) { /* last skip */ - strm.avail_out = (unsigned)offset; - strm.next_out = discard; - offset = 0; - } - - /* uncompress until avail_out filled, or end of stream */ - do { - if (strm.avail_in == 0) { - strm.avail_in = fread(input, 1, CHUNK, in); - if (ferror(in)) { - ret = Z_ERRNO; - goto extract_ret; - } - if (strm.avail_in == 0) { - ret = Z_DATA_ERROR; - goto extract_ret; - } - strm.next_in = input; - } - ret = inflate(&strm, Z_NO_FLUSH); /* normal inflate */ - if (ret == Z_NEED_DICT) - ret = Z_DATA_ERROR; - if (ret == Z_MEM_ERROR || ret == Z_DATA_ERROR) - goto extract_ret; - if (ret == Z_STREAM_END) - break; - } while (strm.avail_out != 0); - - /* if reach end of stream, then don't keep trying to get more */ - if (ret == Z_STREAM_END) - break; - - /* do until offset reached and requested data read, or stream ends */ - } while (skip); - - /* compute number of uncompressed bytes read after offset */ - ret = skip ? 0 : len - strm.avail_out; - - /* clean up and return bytes read or error */ - extract_ret: - (void)inflateEnd(&strm); - return ret; -} - -/* Demonstrate the use of build_index() and extract() by processing the file - provided on the command line, and the extracting 16K from about 2/3rds of - the way through the uncompressed output, and writing that to stdout. */ -int main(int argc, char **argv) -{ - int len; - off_t offset; - FILE *in; - struct access *index = NULL; - unsigned char buf[CHUNK]; - - /* open input file */ - if (argc != 2) { - fprintf(stderr, "usage: zran file.gz\n"); - return 1; - } - in = fopen(argv[1], "rb"); - if (in == NULL) { - fprintf(stderr, "zran: could not open %s for reading\n", argv[1]); - return 1; - } - - /* build index */ - len = build_index(in, SPAN, &index); - if (len < 0) { - fclose(in); - switch (len) { - case Z_MEM_ERROR: - fprintf(stderr, "zran: out of memory\n"); - break; - case Z_DATA_ERROR: - fprintf(stderr, "zran: compressed data error in %s\n", argv[1]); - break; - case Z_ERRNO: - fprintf(stderr, "zran: read error on %s\n", argv[1]); - break; - default: - fprintf(stderr, "zran: error %d while building index\n", len); - } - return 1; - } - fprintf(stderr, "zran: built index with %d access points\n", len); - - /* use index by reading some bytes from an arbitrary offset */ - offset = (index->list[index->have - 1].out << 1) / 3; - len = extract(in, index, offset, buf, CHUNK); - if (len < 0) - fprintf(stderr, "zran: extraction failed: %s error\n", - len == Z_MEM_ERROR ? "out of memory" : "input corrupted"); - else { - fwrite(buf, 1, len, stdout); - fprintf(stderr, "zran: extracted %d bytes at %llu\n", len, offset); - } - - /* clean up and exit */ - free_index(index); - fclose(in); - return 0; -} diff --git a/src/beast/test/zlib/zlib-1.2.8/gzclose.c b/src/beast/test/zlib/zlib-1.2.8/gzclose.c deleted file mode 100644 index caeb99a3177..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/gzclose.c +++ /dev/null @@ -1,25 +0,0 @@ -/* gzclose.c -- zlib gzclose() function - * Copyright (C) 2004, 2010 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#include "gzguts.h" - -/* gzclose() is in a separate file so that it is linked in only if it is used. - That way the other gzclose functions can be used instead to avoid linking in - unneeded compression or decompression routines. */ -int ZEXPORT gzclose(file) - gzFile file; -{ -#ifndef NO_GZCOMPRESS - gz_statep state; - - if (file == NULL) - return Z_STREAM_ERROR; - state = (gz_statep)file; - - return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file); -#else - return gzclose_r(file); -#endif -} diff --git a/src/beast/test/zlib/zlib-1.2.8/gzguts.h b/src/beast/test/zlib/zlib-1.2.8/gzguts.h deleted file mode 100644 index d87659d0319..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/gzguts.h +++ /dev/null @@ -1,209 +0,0 @@ -/* gzguts.h -- zlib internal header definitions for gz* operations - * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#ifdef _LARGEFILE64_SOURCE -# ifndef _LARGEFILE_SOURCE -# define _LARGEFILE_SOURCE 1 -# endif -# ifdef _FILE_OFFSET_BITS -# undef _FILE_OFFSET_BITS -# endif -#endif - -#ifdef HAVE_HIDDEN -# define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) -#else -# define ZLIB_INTERNAL -#endif - -#include -#include "zlib.h" -#ifdef STDC -# include -# include -# include -#endif -#include - -#ifdef _WIN32 -# include -#endif - -#if defined(__TURBOC__) || defined(_MSC_VER) || defined(_WIN32) -# include -#endif - -#ifdef WINAPI_FAMILY -# define open _open -# define read _read -# define write _write -# define close _close -#endif - -#ifdef NO_DEFLATE /* for compatibility with old definition */ -# define NO_GZCOMPRESS -#endif - -#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550) -# ifndef HAVE_VSNPRINTF -# define HAVE_VSNPRINTF -# endif -#endif - -#if defined(__CYGWIN__) -# ifndef HAVE_VSNPRINTF -# define HAVE_VSNPRINTF -# endif -#endif - -#if defined(MSDOS) && defined(__BORLANDC__) && (BORLANDC > 0x410) -# ifndef HAVE_VSNPRINTF -# define HAVE_VSNPRINTF -# endif -#endif - -#ifndef HAVE_VSNPRINTF -# ifdef MSDOS -/* vsnprintf may exist on some MS-DOS compilers (DJGPP?), - but for now we just assume it doesn't. */ -# define NO_vsnprintf -# endif -# ifdef __TURBOC__ -# define NO_vsnprintf -# endif -# ifdef WIN32 -/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ -# if !defined(vsnprintf) && !defined(NO_vsnprintf) -# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 ) -# define vsnprintf _vsnprintf -# endif -# endif -# endif -# ifdef __SASC -# define NO_vsnprintf -# endif -# ifdef VMS -# define NO_vsnprintf -# endif -# ifdef __OS400__ -# define NO_vsnprintf -# endif -# ifdef __MVS__ -# define NO_vsnprintf -# endif -#endif - -/* unlike snprintf (which is required in C99, yet still not supported by - Microsoft more than a decade later!), _snprintf does not guarantee null - termination of the result -- however this is only used in gzlib.c where - the result is assured to fit in the space provided */ -#ifdef _MSC_VER -# define snprintf _snprintf -#endif - -#ifndef local -# define local static -#endif -/* compile with -Dlocal if your debugger can't find static symbols */ - -/* gz* functions always use library allocation functions */ -#ifndef STDC - extern voidp malloc OF((uInt size)); - extern void free OF((voidpf ptr)); -#endif - -/* get errno and strerror definition */ -#if defined UNDER_CE -# include -# define zstrerror() gz_strwinerror((DWORD)GetLastError()) -#else -# ifndef NO_STRERROR -# include -# define zstrerror() strerror(errno) -# else -# define zstrerror() "stdio error (consult errno)" -# endif -#endif - -/* provide prototypes for these when building zlib without LFS */ -#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0 - ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); - ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); - ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); - ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); -#endif - -/* default memLevel */ -#if MAX_MEM_LEVEL >= 8 -# define DEF_MEM_LEVEL 8 -#else -# define DEF_MEM_LEVEL MAX_MEM_LEVEL -#endif - -/* default i/o buffer size -- double this for output when reading (this and - twice this must be able to fit in an unsigned type) */ -#define GZBUFSIZE 8192 - -/* gzip modes, also provide a little integrity check on the passed structure */ -#define GZ_NONE 0 -#define GZ_READ 7247 -#define GZ_WRITE 31153 -#define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */ - -/* values for gz_state how */ -#define LOOK 0 /* look for a gzip header */ -#define COPY 1 /* copy input directly */ -#define GZIP 2 /* decompress a gzip stream */ - -/* internal gzip file state data structure */ -typedef struct { - /* exposed contents for gzgetc() macro */ - struct gzFile_s x; /* "x" for exposed */ - /* x.have: number of bytes available at x.next */ - /* x.next: next output data to deliver or write */ - /* x.pos: current position in uncompressed data */ - /* used for both reading and writing */ - int mode; /* see gzip modes above */ - int fd; /* file descriptor */ - char *path; /* path or fd for error messages */ - unsigned size; /* buffer size, zero if not allocated yet */ - unsigned want; /* requested buffer size, default is GZBUFSIZE */ - unsigned char *in; /* input buffer */ - unsigned char *out; /* output buffer (double-sized when reading) */ - int direct; /* 0 if processing gzip, 1 if transparent */ - /* just for reading */ - int how; /* 0: get header, 1: copy, 2: decompress */ - z_off64_t start; /* where the gzip data started, for rewinding */ - int eof; /* true if end of input file reached */ - int past; /* true if read requested past end */ - /* just for writing */ - int level; /* compression level */ - int strategy; /* compression strategy */ - /* seek request */ - z_off64_t skip; /* amount to skip (already rewound if backwards) */ - int seek; /* true if seek request pending */ - /* error information */ - int err; /* error code */ - char *msg; /* error message */ - /* zlib inflate or deflate stream */ - z_stream strm; /* stream structure in-place (not a pointer) */ -} gz_state; -typedef gz_state FAR *gz_statep; - -/* shared functions */ -void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *)); -#if defined UNDER_CE -char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error)); -#endif - -/* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t - value -- needed when comparing unsigned to z_off64_t, which is signed - (possible z_off64_t types off_t, off64_t, and long are all signed) */ -#ifdef INT_MAX -# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX) -#else -unsigned ZLIB_INTERNAL gz_intmax OF((void)); -# define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax()) -#endif diff --git a/src/beast/test/zlib/zlib-1.2.8/gzlib.c b/src/beast/test/zlib/zlib-1.2.8/gzlib.c deleted file mode 100644 index fae202ef890..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/gzlib.c +++ /dev/null @@ -1,634 +0,0 @@ -/* gzlib.c -- zlib functions common to reading and writing gzip files - * Copyright (C) 2004, 2010, 2011, 2012, 2013 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#include "gzguts.h" - -#if defined(_WIN32) && !defined(__BORLANDC__) -# define LSEEK _lseeki64 -#else -#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0 -# define LSEEK lseek64 -#else -# define LSEEK lseek -#endif -#endif - -/* Local functions */ -local void gz_reset OF((gz_statep)); -local gzFile gz_open OF((const void *, int, const char *)); - -#if defined UNDER_CE - -/* Map the Windows error number in ERROR to a locale-dependent error message - string and return a pointer to it. Typically, the values for ERROR come - from GetLastError. - - The string pointed to shall not be modified by the application, but may be - overwritten by a subsequent call to gz_strwinerror - - The gz_strwinerror function does not change the current setting of - GetLastError. */ -char ZLIB_INTERNAL *gz_strwinerror (error) - DWORD error; -{ - static char buf[1024]; - - wchar_t *msgbuf; - DWORD lasterr = GetLastError(); - DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM - | FORMAT_MESSAGE_ALLOCATE_BUFFER, - NULL, - error, - 0, /* Default language */ - (LPVOID)&msgbuf, - 0, - NULL); - if (chars != 0) { - /* If there is an \r\n appended, zap it. */ - if (chars >= 2 - && msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') { - chars -= 2; - msgbuf[chars] = 0; - } - - if (chars > sizeof (buf) - 1) { - chars = sizeof (buf) - 1; - msgbuf[chars] = 0; - } - - wcstombs(buf, msgbuf, chars + 1); - LocalFree(msgbuf); - } - else { - sprintf(buf, "unknown win32 error (%ld)", error); - } - - SetLastError(lasterr); - return buf; -} - -#endif /* UNDER_CE */ - -/* Reset gzip file state */ -local void gz_reset(state) - gz_statep state; -{ - state->x.have = 0; /* no output data available */ - if (state->mode == GZ_READ) { /* for reading ... */ - state->eof = 0; /* not at end of file */ - state->past = 0; /* have not read past end yet */ - state->how = LOOK; /* look for gzip header */ - } - state->seek = 0; /* no seek request pending */ - gz_error(state, Z_OK, NULL); /* clear error */ - state->x.pos = 0; /* no uncompressed data yet */ - state->strm.avail_in = 0; /* no input data yet */ -} - -/* Open a gzip file either by name or file descriptor. */ -local gzFile gz_open(path, fd, mode) - const void *path; - int fd; - const char *mode; -{ - gz_statep state; - size_t len; - int oflag; -#ifdef O_CLOEXEC - int cloexec = 0; -#endif -#ifdef O_EXCL - int exclusive = 0; -#endif - - /* check input */ - if (path == NULL) - return NULL; - - /* allocate gzFile structure to return */ - state = (gz_statep)malloc(sizeof(gz_state)); - if (state == NULL) - return NULL; - state->size = 0; /* no buffers allocated yet */ - state->want = GZBUFSIZE; /* requested buffer size */ - state->msg = NULL; /* no error message yet */ - - /* interpret mode */ - state->mode = GZ_NONE; - state->level = Z_DEFAULT_COMPRESSION; - state->strategy = Z_DEFAULT_STRATEGY; - state->direct = 0; - while (*mode) { - if (*mode >= '0' && *mode <= '9') - state->level = *mode - '0'; - else - switch (*mode) { - case 'r': - state->mode = GZ_READ; - break; -#ifndef NO_GZCOMPRESS - case 'w': - state->mode = GZ_WRITE; - break; - case 'a': - state->mode = GZ_APPEND; - break; -#endif - case '+': /* can't read and write at the same time */ - free(state); - return NULL; - case 'b': /* ignore -- will request binary anyway */ - break; -#ifdef O_CLOEXEC - case 'e': - cloexec = 1; - break; -#endif -#ifdef O_EXCL - case 'x': - exclusive = 1; - break; -#endif - case 'f': - state->strategy = Z_FILTERED; - break; - case 'h': - state->strategy = Z_HUFFMAN_ONLY; - break; - case 'R': - state->strategy = Z_RLE; - break; - case 'F': - state->strategy = Z_FIXED; - break; - case 'T': - state->direct = 1; - break; - default: /* could consider as an error, but just ignore */ - ; - } - mode++; - } - - /* must provide an "r", "w", or "a" */ - if (state->mode == GZ_NONE) { - free(state); - return NULL; - } - - /* can't force transparent read */ - if (state->mode == GZ_READ) { - if (state->direct) { - free(state); - return NULL; - } - state->direct = 1; /* for empty file */ - } - - /* save the path name for error messages */ -#ifdef _WIN32 - if (fd == -2) { - len = wcstombs(NULL, path, 0); - if (len == (size_t)-1) - len = 0; - } - else -#endif - len = strlen((const char *)path); - state->path = (char *)malloc(len + 1); - if (state->path == NULL) { - free(state); - return NULL; - } -#ifdef _WIN32 - if (fd == -2) - if (len) - wcstombs(state->path, path, len + 1); - else - *(state->path) = 0; - else -#endif -#if !defined(NO_snprintf) && !defined(NO_vsnprintf) - snprintf(state->path, len + 1, "%s", (const char *)path); -#else - strcpy(state->path, path); -#endif - - /* compute the flags for open() */ - oflag = -#ifdef O_LARGEFILE - O_LARGEFILE | -#endif -#ifdef O_BINARY - O_BINARY | -#endif -#ifdef O_CLOEXEC - (cloexec ? O_CLOEXEC : 0) | -#endif - (state->mode == GZ_READ ? - O_RDONLY : - (O_WRONLY | O_CREAT | -#ifdef O_EXCL - (exclusive ? O_EXCL : 0) | -#endif - (state->mode == GZ_WRITE ? - O_TRUNC : - O_APPEND))); - - /* open the file with the appropriate flags (or just use fd) */ - state->fd = fd > -1 ? fd : ( -#ifdef _WIN32 - fd == -2 ? _wopen(path, oflag, 0666) : -#endif - open((const char *)path, oflag, 0666)); - if (state->fd == -1) { - free(state->path); - free(state); - return NULL; - } - if (state->mode == GZ_APPEND) - state->mode = GZ_WRITE; /* simplify later checks */ - - /* save the current position for rewinding (only if reading) */ - if (state->mode == GZ_READ) { - state->start = LSEEK(state->fd, 0, SEEK_CUR); - if (state->start == -1) state->start = 0; - } - - /* initialize stream */ - gz_reset(state); - - /* return stream */ - return (gzFile)state; -} - -/* -- see zlib.h -- */ -gzFile ZEXPORT gzopen(path, mode) - const char *path; - const char *mode; -{ - return gz_open(path, -1, mode); -} - -/* -- see zlib.h -- */ -gzFile ZEXPORT gzopen64(path, mode) - const char *path; - const char *mode; -{ - return gz_open(path, -1, mode); -} - -/* -- see zlib.h -- */ -gzFile ZEXPORT gzdopen(fd, mode) - int fd; - const char *mode; -{ - char *path; /* identifier for error messages */ - gzFile gz; - - if (fd == -1 || (path = (char *)malloc(7 + 3 * sizeof(int))) == NULL) - return NULL; -#if !defined(NO_snprintf) && !defined(NO_vsnprintf) - snprintf(path, 7 + 3 * sizeof(int), "", fd); /* for debugging */ -#else - sprintf(path, "", fd); /* for debugging */ -#endif - gz = gz_open(path, fd, mode); - free(path); - return gz; -} - -/* -- see zlib.h -- */ -#ifdef _WIN32 -gzFile ZEXPORT gzopen_w(path, mode) - const wchar_t *path; - const char *mode; -{ - return gz_open(path, -2, mode); -} -#endif - -/* -- see zlib.h -- */ -int ZEXPORT gzbuffer(file, size) - gzFile file; - unsigned size; -{ - gz_statep state; - - /* get internal structure and check integrity */ - if (file == NULL) - return -1; - state = (gz_statep)file; - if (state->mode != GZ_READ && state->mode != GZ_WRITE) - return -1; - - /* make sure we haven't already allocated memory */ - if (state->size != 0) - return -1; - - /* check and set requested size */ - if (size < 2) - size = 2; /* need two bytes to check magic header */ - state->want = size; - return 0; -} - -/* -- see zlib.h -- */ -int ZEXPORT gzrewind(file) - gzFile file; -{ - gz_statep state; - - /* get internal structure */ - if (file == NULL) - return -1; - state = (gz_statep)file; - - /* check that we're reading and that there's no error */ - if (state->mode != GZ_READ || - (state->err != Z_OK && state->err != Z_BUF_ERROR)) - return -1; - - /* back up and start over */ - if (LSEEK(state->fd, state->start, SEEK_SET) == -1) - return -1; - gz_reset(state); - return 0; -} - -/* -- see zlib.h -- */ -z_off64_t ZEXPORT gzseek64(file, offset, whence) - gzFile file; - z_off64_t offset; - int whence; -{ - unsigned n; - z_off64_t ret; - gz_statep state; - - /* get internal structure and check integrity */ - if (file == NULL) - return -1; - state = (gz_statep)file; - if (state->mode != GZ_READ && state->mode != GZ_WRITE) - return -1; - - /* check that there's no error */ - if (state->err != Z_OK && state->err != Z_BUF_ERROR) - return -1; - - /* can only seek from start or relative to current position */ - if (whence != SEEK_SET && whence != SEEK_CUR) - return -1; - - /* normalize offset to a SEEK_CUR specification */ - if (whence == SEEK_SET) - offset -= state->x.pos; - else if (state->seek) - offset += state->skip; - state->seek = 0; - - /* if within raw area while reading, just go there */ - if (state->mode == GZ_READ && state->how == COPY && - state->x.pos + offset >= 0) { - ret = LSEEK(state->fd, offset - state->x.have, SEEK_CUR); - if (ret == -1) - return -1; - state->x.have = 0; - state->eof = 0; - state->past = 0; - state->seek = 0; - gz_error(state, Z_OK, NULL); - state->strm.avail_in = 0; - state->x.pos += offset; - return state->x.pos; - } - - /* calculate skip amount, rewinding if needed for back seek when reading */ - if (offset < 0) { - if (state->mode != GZ_READ) /* writing -- can't go backwards */ - return -1; - offset += state->x.pos; - if (offset < 0) /* before start of file! */ - return -1; - if (gzrewind(file) == -1) /* rewind, then skip to offset */ - return -1; - } - - /* if reading, skip what's in output buffer (one less gzgetc() check) */ - if (state->mode == GZ_READ) { - n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > offset ? - (unsigned)offset : state->x.have; - state->x.have -= n; - state->x.next += n; - state->x.pos += n; - offset -= n; - } - - /* request skip (if not zero) */ - if (offset) { - state->seek = 1; - state->skip = offset; - } - return state->x.pos + offset; -} - -/* -- see zlib.h -- */ -z_off_t ZEXPORT gzseek(file, offset, whence) - gzFile file; - z_off_t offset; - int whence; -{ - z_off64_t ret; - - ret = gzseek64(file, (z_off64_t)offset, whence); - return ret == (z_off_t)ret ? (z_off_t)ret : -1; -} - -/* -- see zlib.h -- */ -z_off64_t ZEXPORT gztell64(file) - gzFile file; -{ - gz_statep state; - - /* get internal structure and check integrity */ - if (file == NULL) - return -1; - state = (gz_statep)file; - if (state->mode != GZ_READ && state->mode != GZ_WRITE) - return -1; - - /* return position */ - return state->x.pos + (state->seek ? state->skip : 0); -} - -/* -- see zlib.h -- */ -z_off_t ZEXPORT gztell(file) - gzFile file; -{ - z_off64_t ret; - - ret = gztell64(file); - return ret == (z_off_t)ret ? (z_off_t)ret : -1; -} - -/* -- see zlib.h -- */ -z_off64_t ZEXPORT gzoffset64(file) - gzFile file; -{ - z_off64_t offset; - gz_statep state; - - /* get internal structure and check integrity */ - if (file == NULL) - return -1; - state = (gz_statep)file; - if (state->mode != GZ_READ && state->mode != GZ_WRITE) - return -1; - - /* compute and return effective offset in file */ - offset = LSEEK(state->fd, 0, SEEK_CUR); - if (offset == -1) - return -1; - if (state->mode == GZ_READ) /* reading */ - offset -= state->strm.avail_in; /* don't count buffered input */ - return offset; -} - -/* -- see zlib.h -- */ -z_off_t ZEXPORT gzoffset(file) - gzFile file; -{ - z_off64_t ret; - - ret = gzoffset64(file); - return ret == (z_off_t)ret ? (z_off_t)ret : -1; -} - -/* -- see zlib.h -- */ -int ZEXPORT gzeof(file) - gzFile file; -{ - gz_statep state; - - /* get internal structure and check integrity */ - if (file == NULL) - return 0; - state = (gz_statep)file; - if (state->mode != GZ_READ && state->mode != GZ_WRITE) - return 0; - - /* return end-of-file state */ - return state->mode == GZ_READ ? state->past : 0; -} - -/* -- see zlib.h -- */ -const char * ZEXPORT gzerror(file, errnum) - gzFile file; - int *errnum; -{ - gz_statep state; - - /* get internal structure and check integrity */ - if (file == NULL) - return NULL; - state = (gz_statep)file; - if (state->mode != GZ_READ && state->mode != GZ_WRITE) - return NULL; - - /* return error information */ - if (errnum != NULL) - *errnum = state->err; - return state->err == Z_MEM_ERROR ? "out of memory" : - (state->msg == NULL ? "" : state->msg); -} - -/* -- see zlib.h -- */ -void ZEXPORT gzclearerr(file) - gzFile file; -{ - gz_statep state; - - /* get internal structure and check integrity */ - if (file == NULL) - return; - state = (gz_statep)file; - if (state->mode != GZ_READ && state->mode != GZ_WRITE) - return; - - /* clear error and end-of-file */ - if (state->mode == GZ_READ) { - state->eof = 0; - state->past = 0; - } - gz_error(state, Z_OK, NULL); -} - -/* Create an error message in allocated memory and set state->err and - state->msg accordingly. Free any previous error message already there. Do - not try to free or allocate space if the error is Z_MEM_ERROR (out of - memory). Simply save the error message as a static string. If there is an - allocation failure constructing the error message, then convert the error to - out of memory. */ -void ZLIB_INTERNAL gz_error(state, err, msg) - gz_statep state; - int err; - const char *msg; -{ - /* free previously allocated message and clear */ - if (state->msg != NULL) { - if (state->err != Z_MEM_ERROR) - free(state->msg); - state->msg = NULL; - } - - /* if fatal, set state->x.have to 0 so that the gzgetc() macro fails */ - if (err != Z_OK && err != Z_BUF_ERROR) - state->x.have = 0; - - /* set error code, and if no message, then done */ - state->err = err; - if (msg == NULL) - return; - - /* for an out of memory error, return literal string when requested */ - if (err == Z_MEM_ERROR) - return; - - /* construct error message with path */ - if ((state->msg = (char *)malloc(strlen(state->path) + strlen(msg) + 3)) == - NULL) { - state->err = Z_MEM_ERROR; - return; - } -#if !defined(NO_snprintf) && !defined(NO_vsnprintf) - snprintf(state->msg, strlen(state->path) + strlen(msg) + 3, - "%s%s%s", state->path, ": ", msg); -#else - strcpy(state->msg, state->path); - strcat(state->msg, ": "); - strcat(state->msg, msg); -#endif - return; -} - -#ifndef INT_MAX -/* portably return maximum value for an int (when limits.h presumed not - available) -- we need to do this to cover cases where 2's complement not - used, since C standard permits 1's complement and sign-bit representations, - otherwise we could just use ((unsigned)-1) >> 1 */ -unsigned ZLIB_INTERNAL gz_intmax() -{ - unsigned p, q; - - p = 1; - do { - q = p; - p <<= 1; - p++; - } while (p > q); - return q >> 1; -} -#endif diff --git a/src/beast/test/zlib/zlib-1.2.8/gzread.c b/src/beast/test/zlib/zlib-1.2.8/gzread.c deleted file mode 100644 index bf4538eb274..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/gzread.c +++ /dev/null @@ -1,594 +0,0 @@ -/* gzread.c -- zlib functions for reading gzip files - * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#include "gzguts.h" - -/* Local functions */ -local int gz_load OF((gz_statep, unsigned char *, unsigned, unsigned *)); -local int gz_avail OF((gz_statep)); -local int gz_look OF((gz_statep)); -local int gz_decomp OF((gz_statep)); -local int gz_fetch OF((gz_statep)); -local int gz_skip OF((gz_statep, z_off64_t)); - -/* Use read() to load a buffer -- return -1 on error, otherwise 0. Read from - state->fd, and update state->eof, state->err, and state->msg as appropriate. - This function needs to loop on read(), since read() is not guaranteed to - read the number of bytes requested, depending on the type of descriptor. */ -local int gz_load(state, buf, len, have) - gz_statep state; - unsigned char *buf; - unsigned len; - unsigned *have; -{ - int ret; - - *have = 0; - do { - ret = read(state->fd, buf + *have, len - *have); - if (ret <= 0) - break; - *have += ret; - } while (*have < len); - if (ret < 0) { - gz_error(state, Z_ERRNO, zstrerror()); - return -1; - } - if (ret == 0) - state->eof = 1; - return 0; -} - -/* Load up input buffer and set eof flag if last data loaded -- return -1 on - error, 0 otherwise. Note that the eof flag is set when the end of the input - file is reached, even though there may be unused data in the buffer. Once - that data has been used, no more attempts will be made to read the file. - If strm->avail_in != 0, then the current data is moved to the beginning of - the input buffer, and then the remainder of the buffer is loaded with the - available data from the input file. */ -local int gz_avail(state) - gz_statep state; -{ - unsigned got; - z_streamp strm = &(state->strm); - - if (state->err != Z_OK && state->err != Z_BUF_ERROR) - return -1; - if (state->eof == 0) { - if (strm->avail_in) { /* copy what's there to the start */ - unsigned char *p = state->in; - unsigned const char *q = strm->next_in; - unsigned n = strm->avail_in; - do { - *p++ = *q++; - } while (--n); - } - if (gz_load(state, state->in + strm->avail_in, - state->size - strm->avail_in, &got) == -1) - return -1; - strm->avail_in += got; - strm->next_in = state->in; - } - return 0; -} - -/* Look for gzip header, set up for inflate or copy. state->x.have must be 0. - If this is the first time in, allocate required memory. state->how will be - left unchanged if there is no more input data available, will be set to COPY - if there is no gzip header and direct copying will be performed, or it will - be set to GZIP for decompression. If direct copying, then leftover input - data from the input buffer will be copied to the output buffer. In that - case, all further file reads will be directly to either the output buffer or - a user buffer. If decompressing, the inflate state will be initialized. - gz_look() will return 0 on success or -1 on failure. */ -local int gz_look(state) - gz_statep state; -{ - z_streamp strm = &(state->strm); - - /* allocate read buffers and inflate memory */ - if (state->size == 0) { - /* allocate buffers */ - state->in = (unsigned char *)malloc(state->want); - state->out = (unsigned char *)malloc(state->want << 1); - if (state->in == NULL || state->out == NULL) { - if (state->out != NULL) - free(state->out); - if (state->in != NULL) - free(state->in); - gz_error(state, Z_MEM_ERROR, "out of memory"); - return -1; - } - state->size = state->want; - - /* allocate inflate memory */ - state->strm.zalloc = Z_NULL; - state->strm.zfree = Z_NULL; - state->strm.opaque = Z_NULL; - state->strm.avail_in = 0; - state->strm.next_in = Z_NULL; - if (inflateInit2(&(state->strm), 15 + 16) != Z_OK) { /* gunzip */ - free(state->out); - free(state->in); - state->size = 0; - gz_error(state, Z_MEM_ERROR, "out of memory"); - return -1; - } - } - - /* get at least the magic bytes in the input buffer */ - if (strm->avail_in < 2) { - if (gz_avail(state) == -1) - return -1; - if (strm->avail_in == 0) - return 0; - } - - /* look for gzip magic bytes -- if there, do gzip decoding (note: there is - a logical dilemma here when considering the case of a partially written - gzip file, to wit, if a single 31 byte is written, then we cannot tell - whether this is a single-byte file, or just a partially written gzip - file -- for here we assume that if a gzip file is being written, then - the header will be written in a single operation, so that reading a - single byte is sufficient indication that it is not a gzip file) */ - if (strm->avail_in > 1 && - strm->next_in[0] == 31 && strm->next_in[1] == 139) { - inflateReset(strm); - state->how = GZIP; - state->direct = 0; - return 0; - } - - /* no gzip header -- if we were decoding gzip before, then this is trailing - garbage. Ignore the trailing garbage and finish. */ - if (state->direct == 0) { - strm->avail_in = 0; - state->eof = 1; - state->x.have = 0; - return 0; - } - - /* doing raw i/o, copy any leftover input to output -- this assumes that - the output buffer is larger than the input buffer, which also assures - space for gzungetc() */ - state->x.next = state->out; - if (strm->avail_in) { - memcpy(state->x.next, strm->next_in, strm->avail_in); - state->x.have = strm->avail_in; - strm->avail_in = 0; - } - state->how = COPY; - state->direct = 1; - return 0; -} - -/* Decompress from input to the provided next_out and avail_out in the state. - On return, state->x.have and state->x.next point to the just decompressed - data. If the gzip stream completes, state->how is reset to LOOK to look for - the next gzip stream or raw data, once state->x.have is depleted. Returns 0 - on success, -1 on failure. */ -local int gz_decomp(state) - gz_statep state; -{ - int ret = Z_OK; - unsigned had; - z_streamp strm = &(state->strm); - - /* fill output buffer up to end of deflate stream */ - had = strm->avail_out; - do { - /* get more input for inflate() */ - if (strm->avail_in == 0 && gz_avail(state) == -1) - return -1; - if (strm->avail_in == 0) { - gz_error(state, Z_BUF_ERROR, "unexpected end of file"); - break; - } - - /* decompress and handle errors */ - ret = inflate(strm, Z_NO_FLUSH); - if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT) { - gz_error(state, Z_STREAM_ERROR, - "internal error: inflate stream corrupt"); - return -1; - } - if (ret == Z_MEM_ERROR) { - gz_error(state, Z_MEM_ERROR, "out of memory"); - return -1; - } - if (ret == Z_DATA_ERROR) { /* deflate stream invalid */ - gz_error(state, Z_DATA_ERROR, - strm->msg == NULL ? "compressed data error" : strm->msg); - return -1; - } - } while (strm->avail_out && ret != Z_STREAM_END); - - /* update available output */ - state->x.have = had - strm->avail_out; - state->x.next = strm->next_out - state->x.have; - - /* if the gzip stream completed successfully, look for another */ - if (ret == Z_STREAM_END) - state->how = LOOK; - - /* good decompression */ - return 0; -} - -/* Fetch data and put it in the output buffer. Assumes state->x.have is 0. - Data is either copied from the input file or decompressed from the input - file depending on state->how. If state->how is LOOK, then a gzip header is - looked for to determine whether to copy or decompress. Returns -1 on error, - otherwise 0. gz_fetch() will leave state->how as COPY or GZIP unless the - end of the input file has been reached and all data has been processed. */ -local int gz_fetch(state) - gz_statep state; -{ - z_streamp strm = &(state->strm); - - do { - switch(state->how) { - case LOOK: /* -> LOOK, COPY (only if never GZIP), or GZIP */ - if (gz_look(state) == -1) - return -1; - if (state->how == LOOK) - return 0; - break; - case COPY: /* -> COPY */ - if (gz_load(state, state->out, state->size << 1, &(state->x.have)) - == -1) - return -1; - state->x.next = state->out; - return 0; - case GZIP: /* -> GZIP or LOOK (if end of gzip stream) */ - strm->avail_out = state->size << 1; - strm->next_out = state->out; - if (gz_decomp(state) == -1) - return -1; - } - } while (state->x.have == 0 && (!state->eof || strm->avail_in)); - return 0; -} - -/* Skip len uncompressed bytes of output. Return -1 on error, 0 on success. */ -local int gz_skip(state, len) - gz_statep state; - z_off64_t len; -{ - unsigned n; - - /* skip over len bytes or reach end-of-file, whichever comes first */ - while (len) - /* skip over whatever is in output buffer */ - if (state->x.have) { - n = GT_OFF(state->x.have) || (z_off64_t)state->x.have > len ? - (unsigned)len : state->x.have; - state->x.have -= n; - state->x.next += n; - state->x.pos += n; - len -= n; - } - - /* output buffer empty -- return if we're at the end of the input */ - else if (state->eof && state->strm.avail_in == 0) - break; - - /* need more data to skip -- load up output buffer */ - else { - /* get more output, looking for header if required */ - if (gz_fetch(state) == -1) - return -1; - } - return 0; -} - -/* -- see zlib.h -- */ -int ZEXPORT gzread(file, buf, len) - gzFile file; - voidp buf; - unsigned len; -{ - unsigned got, n; - gz_statep state; - z_streamp strm; - - /* get internal structure */ - if (file == NULL) - return -1; - state = (gz_statep)file; - strm = &(state->strm); - - /* check that we're reading and that there's no (serious) error */ - if (state->mode != GZ_READ || - (state->err != Z_OK && state->err != Z_BUF_ERROR)) - return -1; - - /* since an int is returned, make sure len fits in one, otherwise return - with an error (this avoids the flaw in the interface) */ - if ((int)len < 0) { - gz_error(state, Z_DATA_ERROR, "requested length does not fit in int"); - return -1; - } - - /* if len is zero, avoid unnecessary operations */ - if (len == 0) - return 0; - - /* process a skip request */ - if (state->seek) { - state->seek = 0; - if (gz_skip(state, state->skip) == -1) - return -1; - } - - /* get len bytes to buf, or less than len if at the end */ - got = 0; - do { - /* first just try copying data from the output buffer */ - if (state->x.have) { - n = state->x.have > len ? len : state->x.have; - memcpy(buf, state->x.next, n); - state->x.next += n; - state->x.have -= n; - } - - /* output buffer empty -- return if we're at the end of the input */ - else if (state->eof && strm->avail_in == 0) { - state->past = 1; /* tried to read past end */ - break; - } - - /* need output data -- for small len or new stream load up our output - buffer */ - else if (state->how == LOOK || len < (state->size << 1)) { - /* get more output, looking for header if required */ - if (gz_fetch(state) == -1) - return -1; - continue; /* no progress yet -- go back to copy above */ - /* the copy above assures that we will leave with space in the - output buffer, allowing at least one gzungetc() to succeed */ - } - - /* large len -- read directly into user buffer */ - else if (state->how == COPY) { /* read directly */ - if (gz_load(state, (unsigned char *)buf, len, &n) == -1) - return -1; - } - - /* large len -- decompress directly into user buffer */ - else { /* state->how == GZIP */ - strm->avail_out = len; - strm->next_out = (unsigned char *)buf; - if (gz_decomp(state) == -1) - return -1; - n = state->x.have; - state->x.have = 0; - } - - /* update progress */ - len -= n; - buf = (char *)buf + n; - got += n; - state->x.pos += n; - } while (len); - - /* return number of bytes read into user buffer (will fit in int) */ - return (int)got; -} - -/* -- see zlib.h -- */ -#ifdef Z_PREFIX_SET -# undef z_gzgetc -#else -# undef gzgetc -#endif -int ZEXPORT gzgetc(file) - gzFile file; -{ - int ret; - unsigned char buf[1]; - gz_statep state; - - /* get internal structure */ - if (file == NULL) - return -1; - state = (gz_statep)file; - - /* check that we're reading and that there's no (serious) error */ - if (state->mode != GZ_READ || - (state->err != Z_OK && state->err != Z_BUF_ERROR)) - return -1; - - /* try output buffer (no need to check for skip request) */ - if (state->x.have) { - state->x.have--; - state->x.pos++; - return *(state->x.next)++; - } - - /* nothing there -- try gzread() */ - ret = gzread(file, buf, 1); - return ret < 1 ? -1 : buf[0]; -} - -int ZEXPORT gzgetc_(file) -gzFile file; -{ - return gzgetc(file); -} - -/* -- see zlib.h -- */ -int ZEXPORT gzungetc(c, file) - int c; - gzFile file; -{ - gz_statep state; - - /* get internal structure */ - if (file == NULL) - return -1; - state = (gz_statep)file; - - /* check that we're reading and that there's no (serious) error */ - if (state->mode != GZ_READ || - (state->err != Z_OK && state->err != Z_BUF_ERROR)) - return -1; - - /* process a skip request */ - if (state->seek) { - state->seek = 0; - if (gz_skip(state, state->skip) == -1) - return -1; - } - - /* can't push EOF */ - if (c < 0) - return -1; - - /* if output buffer empty, put byte at end (allows more pushing) */ - if (state->x.have == 0) { - state->x.have = 1; - state->x.next = state->out + (state->size << 1) - 1; - state->x.next[0] = c; - state->x.pos--; - state->past = 0; - return c; - } - - /* if no room, give up (must have already done a gzungetc()) */ - if (state->x.have == (state->size << 1)) { - gz_error(state, Z_DATA_ERROR, "out of room to push characters"); - return -1; - } - - /* slide output data if needed and insert byte before existing data */ - if (state->x.next == state->out) { - unsigned char *src = state->out + state->x.have; - unsigned char *dest = state->out + (state->size << 1); - while (src > state->out) - *--dest = *--src; - state->x.next = dest; - } - state->x.have++; - state->x.next--; - state->x.next[0] = c; - state->x.pos--; - state->past = 0; - return c; -} - -/* -- see zlib.h -- */ -char * ZEXPORT gzgets(file, buf, len) - gzFile file; - char *buf; - int len; -{ - unsigned left, n; - char *str; - unsigned char *eol; - gz_statep state; - - /* check parameters and get internal structure */ - if (file == NULL || buf == NULL || len < 1) - return NULL; - state = (gz_statep)file; - - /* check that we're reading and that there's no (serious) error */ - if (state->mode != GZ_READ || - (state->err != Z_OK && state->err != Z_BUF_ERROR)) - return NULL; - - /* process a skip request */ - if (state->seek) { - state->seek = 0; - if (gz_skip(state, state->skip) == -1) - return NULL; - } - - /* copy output bytes up to new line or len - 1, whichever comes first -- - append a terminating zero to the string (we don't check for a zero in - the contents, let the user worry about that) */ - str = buf; - left = (unsigned)len - 1; - if (left) do { - /* assure that something is in the output buffer */ - if (state->x.have == 0 && gz_fetch(state) == -1) - return NULL; /* error */ - if (state->x.have == 0) { /* end of file */ - state->past = 1; /* read past end */ - break; /* return what we have */ - } - - /* look for end-of-line in current output buffer */ - n = state->x.have > left ? left : state->x.have; - eol = (unsigned char *)memchr(state->x.next, '\n', n); - if (eol != NULL) - n = (unsigned)(eol - state->x.next) + 1; - - /* copy through end-of-line, or remainder if not found */ - memcpy(buf, state->x.next, n); - state->x.have -= n; - state->x.next += n; - state->x.pos += n; - left -= n; - buf += n; - } while (left && eol == NULL); - - /* return terminated string, or if nothing, end of file */ - if (buf == str) - return NULL; - buf[0] = 0; - return str; -} - -/* -- see zlib.h -- */ -int ZEXPORT gzdirect(file) - gzFile file; -{ - gz_statep state; - - /* get internal structure */ - if (file == NULL) - return 0; - state = (gz_statep)file; - - /* if the state is not known, but we can find out, then do so (this is - mainly for right after a gzopen() or gzdopen()) */ - if (state->mode == GZ_READ && state->how == LOOK && state->x.have == 0) - (void)gz_look(state); - - /* return 1 if transparent, 0 if processing a gzip stream */ - return state->direct; -} - -/* -- see zlib.h -- */ -int ZEXPORT gzclose_r(file) - gzFile file; -{ - int ret, err; - gz_statep state; - - /* get internal structure */ - if (file == NULL) - return Z_STREAM_ERROR; - state = (gz_statep)file; - - /* check that we're reading */ - if (state->mode != GZ_READ) - return Z_STREAM_ERROR; - - /* free memory and close file */ - if (state->size) { - inflateEnd(&(state->strm)); - free(state->out); - free(state->in); - } - err = state->err == Z_BUF_ERROR ? Z_BUF_ERROR : Z_OK; - gz_error(state, Z_OK, NULL); - free(state->path); - ret = close(state->fd); - free(state); - return ret ? Z_ERRNO : err; -} diff --git a/src/beast/test/zlib/zlib-1.2.8/gzwrite.c b/src/beast/test/zlib/zlib-1.2.8/gzwrite.c deleted file mode 100644 index aa767fbf63e..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/gzwrite.c +++ /dev/null @@ -1,577 +0,0 @@ -/* gzwrite.c -- zlib functions for writing gzip files - * Copyright (C) 2004, 2005, 2010, 2011, 2012, 2013 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#include "gzguts.h" - -/* Local functions */ -local int gz_init OF((gz_statep)); -local int gz_comp OF((gz_statep, int)); -local int gz_zero OF((gz_statep, z_off64_t)); - -/* Initialize state for writing a gzip file. Mark initialization by setting - state->size to non-zero. Return -1 on failure or 0 on success. */ -local int gz_init(state) - gz_statep state; -{ - int ret; - z_streamp strm = &(state->strm); - - /* allocate input buffer */ - state->in = (unsigned char *)malloc(state->want); - if (state->in == NULL) { - gz_error(state, Z_MEM_ERROR, "out of memory"); - return -1; - } - - /* only need output buffer and deflate state if compressing */ - if (!state->direct) { - /* allocate output buffer */ - state->out = (unsigned char *)malloc(state->want); - if (state->out == NULL) { - free(state->in); - gz_error(state, Z_MEM_ERROR, "out of memory"); - return -1; - } - - /* allocate deflate memory, set up for gzip compression */ - strm->zalloc = Z_NULL; - strm->zfree = Z_NULL; - strm->opaque = Z_NULL; - ret = deflateInit2(strm, state->level, Z_DEFLATED, - MAX_WBITS + 16, DEF_MEM_LEVEL, state->strategy); - if (ret != Z_OK) { - free(state->out); - free(state->in); - gz_error(state, Z_MEM_ERROR, "out of memory"); - return -1; - } - } - - /* mark state as initialized */ - state->size = state->want; - - /* initialize write buffer if compressing */ - if (!state->direct) { - strm->avail_out = state->size; - strm->next_out = state->out; - state->x.next = strm->next_out; - } - return 0; -} - -/* Compress whatever is at avail_in and next_in and write to the output file. - Return -1 if there is an error writing to the output file, otherwise 0. - flush is assumed to be a valid deflate() flush value. If flush is Z_FINISH, - then the deflate() state is reset to start a new gzip stream. If gz->direct - is true, then simply write to the output file without compressing, and - ignore flush. */ -local int gz_comp(state, flush) - gz_statep state; - int flush; -{ - int ret, got; - unsigned have; - z_streamp strm = &(state->strm); - - /* allocate memory if this is the first time through */ - if (state->size == 0 && gz_init(state) == -1) - return -1; - - /* write directly if requested */ - if (state->direct) { - got = write(state->fd, strm->next_in, strm->avail_in); - if (got < 0 || (unsigned)got != strm->avail_in) { - gz_error(state, Z_ERRNO, zstrerror()); - return -1; - } - strm->avail_in = 0; - return 0; - } - - /* run deflate() on provided input until it produces no more output */ - ret = Z_OK; - do { - /* write out current buffer contents if full, or if flushing, but if - doing Z_FINISH then don't write until we get to Z_STREAM_END */ - if (strm->avail_out == 0 || (flush != Z_NO_FLUSH && - (flush != Z_FINISH || ret == Z_STREAM_END))) { - have = (unsigned)(strm->next_out - state->x.next); - if (have && ((got = write(state->fd, state->x.next, have)) < 0 || - (unsigned)got != have)) { - gz_error(state, Z_ERRNO, zstrerror()); - return -1; - } - if (strm->avail_out == 0) { - strm->avail_out = state->size; - strm->next_out = state->out; - } - state->x.next = strm->next_out; - } - - /* compress */ - have = strm->avail_out; - ret = deflate(strm, flush); - if (ret == Z_STREAM_ERROR) { - gz_error(state, Z_STREAM_ERROR, - "internal error: deflate stream corrupt"); - return -1; - } - have -= strm->avail_out; - } while (have); - - /* if that completed a deflate stream, allow another to start */ - if (flush == Z_FINISH) - deflateReset(strm); - - /* all done, no errors */ - return 0; -} - -/* Compress len zeros to output. Return -1 on error, 0 on success. */ -local int gz_zero(state, len) - gz_statep state; - z_off64_t len; -{ - int first; - unsigned n; - z_streamp strm = &(state->strm); - - /* consume whatever's left in the input buffer */ - if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) - return -1; - - /* compress len zeros (len guaranteed > 0) */ - first = 1; - while (len) { - n = GT_OFF(state->size) || (z_off64_t)state->size > len ? - (unsigned)len : state->size; - if (first) { - memset(state->in, 0, n); - first = 0; - } - strm->avail_in = n; - strm->next_in = state->in; - state->x.pos += n; - if (gz_comp(state, Z_NO_FLUSH) == -1) - return -1; - len -= n; - } - return 0; -} - -/* -- see zlib.h -- */ -int ZEXPORT gzwrite(file, buf, len) - gzFile file; - voidpc buf; - unsigned len; -{ - unsigned put = len; - gz_statep state; - z_streamp strm; - - /* get internal structure */ - if (file == NULL) - return 0; - state = (gz_statep)file; - strm = &(state->strm); - - /* check that we're writing and that there's no error */ - if (state->mode != GZ_WRITE || state->err != Z_OK) - return 0; - - /* since an int is returned, make sure len fits in one, otherwise return - with an error (this avoids the flaw in the interface) */ - if ((int)len < 0) { - gz_error(state, Z_DATA_ERROR, "requested length does not fit in int"); - return 0; - } - - /* if len is zero, avoid unnecessary operations */ - if (len == 0) - return 0; - - /* allocate memory if this is the first time through */ - if (state->size == 0 && gz_init(state) == -1) - return 0; - - /* check for seek request */ - if (state->seek) { - state->seek = 0; - if (gz_zero(state, state->skip) == -1) - return 0; - } - - /* for small len, copy to input buffer, otherwise compress directly */ - if (len < state->size) { - /* copy to input buffer, compress when full */ - do { - unsigned have, copy; - - if (strm->avail_in == 0) - strm->next_in = state->in; - have = (unsigned)((strm->next_in + strm->avail_in) - state->in); - copy = state->size - have; - if (copy > len) - copy = len; - memcpy(state->in + have, buf, copy); - strm->avail_in += copy; - state->x.pos += copy; - buf = (const char *)buf + copy; - len -= copy; - if (len && gz_comp(state, Z_NO_FLUSH) == -1) - return 0; - } while (len); - } - else { - /* consume whatever's left in the input buffer */ - if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) - return 0; - - /* directly compress user buffer to file */ - strm->avail_in = len; - strm->next_in = (z_const Bytef *)buf; - state->x.pos += len; - if (gz_comp(state, Z_NO_FLUSH) == -1) - return 0; - } - - /* input was all buffered or compressed (put will fit in int) */ - return (int)put; -} - -/* -- see zlib.h -- */ -int ZEXPORT gzputc(file, c) - gzFile file; - int c; -{ - unsigned have; - unsigned char buf[1]; - gz_statep state; - z_streamp strm; - - /* get internal structure */ - if (file == NULL) - return -1; - state = (gz_statep)file; - strm = &(state->strm); - - /* check that we're writing and that there's no error */ - if (state->mode != GZ_WRITE || state->err != Z_OK) - return -1; - - /* check for seek request */ - if (state->seek) { - state->seek = 0; - if (gz_zero(state, state->skip) == -1) - return -1; - } - - /* try writing to input buffer for speed (state->size == 0 if buffer not - initialized) */ - if (state->size) { - if (strm->avail_in == 0) - strm->next_in = state->in; - have = (unsigned)((strm->next_in + strm->avail_in) - state->in); - if (have < state->size) { - state->in[have] = c; - strm->avail_in++; - state->x.pos++; - return c & 0xff; - } - } - - /* no room in buffer or not initialized, use gz_write() */ - buf[0] = c; - if (gzwrite(file, buf, 1) != 1) - return -1; - return c & 0xff; -} - -/* -- see zlib.h -- */ -int ZEXPORT gzputs(file, str) - gzFile file; - const char *str; -{ - int ret; - unsigned len; - - /* write string */ - len = (unsigned)strlen(str); - ret = gzwrite(file, str, len); - return ret == 0 && len != 0 ? -1 : ret; -} - -#if defined(STDC) || defined(Z_HAVE_STDARG_H) -#include - -/* -- see zlib.h -- */ -int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va) -{ - int size, len; - gz_statep state; - z_streamp strm; - - /* get internal structure */ - if (file == NULL) - return -1; - state = (gz_statep)file; - strm = &(state->strm); - - /* check that we're writing and that there's no error */ - if (state->mode != GZ_WRITE || state->err != Z_OK) - return 0; - - /* make sure we have some buffer space */ - if (state->size == 0 && gz_init(state) == -1) - return 0; - - /* check for seek request */ - if (state->seek) { - state->seek = 0; - if (gz_zero(state, state->skip) == -1) - return 0; - } - - /* consume whatever's left in the input buffer */ - if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) - return 0; - - /* do the printf() into the input buffer, put length in len */ - size = (int)(state->size); - state->in[size - 1] = 0; -#ifdef NO_vsnprintf -# ifdef HAS_vsprintf_void - (void)vsprintf((char *)(state->in), format, va); - for (len = 0; len < size; len++) - if (state->in[len] == 0) break; -# else - len = vsprintf((char *)(state->in), format, va); -# endif -#else -# ifdef HAS_vsnprintf_void - (void)vsnprintf((char *)(state->in), size, format, va); - len = strlen((char *)(state->in)); -# else - len = vsnprintf((char *)(state->in), size, format, va); -# endif -#endif - - /* check that printf() results fit in buffer */ - if (len <= 0 || len >= (int)size || state->in[size - 1] != 0) - return 0; - - /* update buffer and position, defer compression until needed */ - strm->avail_in = (unsigned)len; - strm->next_in = state->in; - state->x.pos += len; - return len; -} - -int ZEXPORTVA gzprintf(gzFile file, const char *format, ...) -{ - va_list va; - int ret; - - va_start(va, format); - ret = gzvprintf(file, format, va); - va_end(va); - return ret; -} - -#else /* !STDC && !Z_HAVE_STDARG_H */ - -/* -- see zlib.h -- */ -int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, - a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) - gzFile file; - const char *format; - int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, - a11, a12, a13, a14, a15, a16, a17, a18, a19, a20; -{ - int size, len; - gz_statep state; - z_streamp strm; - - /* get internal structure */ - if (file == NULL) - return -1; - state = (gz_statep)file; - strm = &(state->strm); - - /* check that can really pass pointer in ints */ - if (sizeof(int) != sizeof(void *)) - return 0; - - /* check that we're writing and that there's no error */ - if (state->mode != GZ_WRITE || state->err != Z_OK) - return 0; - - /* make sure we have some buffer space */ - if (state->size == 0 && gz_init(state) == -1) - return 0; - - /* check for seek request */ - if (state->seek) { - state->seek = 0; - if (gz_zero(state, state->skip) == -1) - return 0; - } - - /* consume whatever's left in the input buffer */ - if (strm->avail_in && gz_comp(state, Z_NO_FLUSH) == -1) - return 0; - - /* do the printf() into the input buffer, put length in len */ - size = (int)(state->size); - state->in[size - 1] = 0; -#ifdef NO_snprintf -# ifdef HAS_sprintf_void - sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8, - a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); - for (len = 0; len < size; len++) - if (state->in[len] == 0) break; -# else - len = sprintf((char *)(state->in), format, a1, a2, a3, a4, a5, a6, a7, a8, - a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); -# endif -#else -# ifdef HAS_snprintf_void - snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6, a7, a8, - a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); - len = strlen((char *)(state->in)); -# else - len = snprintf((char *)(state->in), size, format, a1, a2, a3, a4, a5, a6, - a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, - a19, a20); -# endif -#endif - - /* check that printf() results fit in buffer */ - if (len <= 0 || len >= (int)size || state->in[size - 1] != 0) - return 0; - - /* update buffer and position, defer compression until needed */ - strm->avail_in = (unsigned)len; - strm->next_in = state->in; - state->x.pos += len; - return len; -} - -#endif - -/* -- see zlib.h -- */ -int ZEXPORT gzflush(file, flush) - gzFile file; - int flush; -{ - gz_statep state; - - /* get internal structure */ - if (file == NULL) - return -1; - state = (gz_statep)file; - - /* check that we're writing and that there's no error */ - if (state->mode != GZ_WRITE || state->err != Z_OK) - return Z_STREAM_ERROR; - - /* check flush parameter */ - if (flush < 0 || flush > Z_FINISH) - return Z_STREAM_ERROR; - - /* check for seek request */ - if (state->seek) { - state->seek = 0; - if (gz_zero(state, state->skip) == -1) - return -1; - } - - /* compress remaining data with requested flush */ - gz_comp(state, flush); - return state->err; -} - -/* -- see zlib.h -- */ -int ZEXPORT gzsetparams(file, level, strategy) - gzFile file; - int level; - int strategy; -{ - gz_statep state; - z_streamp strm; - - /* get internal structure */ - if (file == NULL) - return Z_STREAM_ERROR; - state = (gz_statep)file; - strm = &(state->strm); - - /* check that we're writing and that there's no error */ - if (state->mode != GZ_WRITE || state->err != Z_OK) - return Z_STREAM_ERROR; - - /* if no change is requested, then do nothing */ - if (level == state->level && strategy == state->strategy) - return Z_OK; - - /* check for seek request */ - if (state->seek) { - state->seek = 0; - if (gz_zero(state, state->skip) == -1) - return -1; - } - - /* change compression parameters for subsequent input */ - if (state->size) { - /* flush previous input with previous parameters before changing */ - if (strm->avail_in && gz_comp(state, Z_PARTIAL_FLUSH) == -1) - return state->err; - deflateParams(strm, level, strategy); - } - state->level = level; - state->strategy = strategy; - return Z_OK; -} - -/* -- see zlib.h -- */ -int ZEXPORT gzclose_w(file) - gzFile file; -{ - int ret = Z_OK; - gz_statep state; - - /* get internal structure */ - if (file == NULL) - return Z_STREAM_ERROR; - state = (gz_statep)file; - - /* check that we're writing */ - if (state->mode != GZ_WRITE) - return Z_STREAM_ERROR; - - /* check for seek request */ - if (state->seek) { - state->seek = 0; - if (gz_zero(state, state->skip) == -1) - ret = state->err; - } - - /* flush, free memory, and close file */ - if (gz_comp(state, Z_FINISH) == -1) - ret = state->err; - if (state->size) { - if (!state->direct) { - (void)deflateEnd(&(state->strm)); - free(state->out); - } - free(state->in); - } - gz_error(state, Z_OK, NULL); - free(state->path); - if (close(state->fd) == -1) - ret = Z_ERRNO; - free(state); - return ret; -} diff --git a/src/beast/test/zlib/zlib-1.2.8/infback.c b/src/beast/test/zlib/zlib-1.2.8/infback.c deleted file mode 100644 index f3833c2e434..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/infback.c +++ /dev/null @@ -1,640 +0,0 @@ -/* infback.c -- inflate using a call-back interface - * Copyright (C) 1995-2011 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* - This code is largely copied from inflate.c. Normally either infback.o or - inflate.o would be linked into an application--not both. The interface - with inffast.c is retained so that optimized assembler-coded versions of - inflate_fast() can be used with either inflate.c or infback.c. - */ - -#include "zutil.h" -#include "inftrees.h" -#include "inflate.h" -#include "inffast.h" - -/* function prototypes */ -local void fixedtables OF((struct inflate_state FAR *state)); - -/* - strm provides memory allocation functions in zalloc and zfree, or - Z_NULL to use the library memory allocation functions. - - windowBits is in the range 8..15, and window is a user-supplied - window and output buffer that is 2**windowBits bytes. - */ -int ZEXPORT inflateBackInit_(strm, windowBits, window, version, stream_size) -z_streamp strm; -int windowBits; -unsigned char FAR *window; -const char *version; -int stream_size; -{ - struct inflate_state FAR *state; - - if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || - stream_size != (int)(sizeof(z_stream))) - return Z_VERSION_ERROR; - if (strm == Z_NULL || window == Z_NULL || - windowBits < 8 || windowBits > 15) - return Z_STREAM_ERROR; - strm->msg = Z_NULL; /* in case we return an error */ - if (strm->zalloc == (alloc_func)0) { -#ifdef Z_SOLO - return Z_STREAM_ERROR; -#else - strm->zalloc = zcalloc; - strm->opaque = (voidpf)0; -#endif - } - if (strm->zfree == (free_func)0) -#ifdef Z_SOLO - return Z_STREAM_ERROR; -#else - strm->zfree = zcfree; -#endif - state = (struct inflate_state FAR *)ZALLOC(strm, 1, - sizeof(struct inflate_state)); - if (state == Z_NULL) return Z_MEM_ERROR; - Tracev((stderr, "inflate: allocated\n")); - strm->state = (struct internal_state FAR *)state; - state->dmax = 32768U; - state->wbits = windowBits; - state->wsize = 1U << windowBits; - state->window = window; - state->wnext = 0; - state->whave = 0; - return Z_OK; -} - -/* - Return state with length and distance decoding tables and index sizes set to - fixed code decoding. Normally this returns fixed tables from inffixed.h. - If BUILDFIXED is defined, then instead this routine builds the tables the - first time it's called, and returns those tables the first time and - thereafter. This reduces the size of the code by about 2K bytes, in - exchange for a little execution time. However, BUILDFIXED should not be - used for threaded applications, since the rewriting of the tables and virgin - may not be thread-safe. - */ -local void fixedtables(state) -struct inflate_state FAR *state; -{ -#ifdef BUILDFIXED - static int virgin = 1; - static code *lenfix, *distfix; - static code fixed[544]; - - /* build fixed huffman tables if first call (may not be thread safe) */ - if (virgin) { - unsigned sym, bits; - static code *next; - - /* literal/length table */ - sym = 0; - while (sym < 144) state->lens[sym++] = 8; - while (sym < 256) state->lens[sym++] = 9; - while (sym < 280) state->lens[sym++] = 7; - while (sym < 288) state->lens[sym++] = 8; - next = fixed; - lenfix = next; - bits = 9; - inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work); - - /* distance table */ - sym = 0; - while (sym < 32) state->lens[sym++] = 5; - distfix = next; - bits = 5; - inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work); - - /* do this just once */ - virgin = 0; - } -#else /* !BUILDFIXED */ -# include "inffixed.h" -#endif /* BUILDFIXED */ - state->lencode = lenfix; - state->lenbits = 9; - state->distcode = distfix; - state->distbits = 5; -} - -/* Macros for inflateBack(): */ - -/* Load returned state from inflate_fast() */ -#define LOAD() \ - do { \ - put = strm->next_out; \ - left = strm->avail_out; \ - next = strm->next_in; \ - have = strm->avail_in; \ - hold = state->hold; \ - bits = state->bits; \ - } while (0) - -/* Set state from registers for inflate_fast() */ -#define RESTORE() \ - do { \ - strm->next_out = put; \ - strm->avail_out = left; \ - strm->next_in = next; \ - strm->avail_in = have; \ - state->hold = hold; \ - state->bits = bits; \ - } while (0) - -/* Clear the input bit accumulator */ -#define INITBITS() \ - do { \ - hold = 0; \ - bits = 0; \ - } while (0) - -/* Assure that some input is available. If input is requested, but denied, - then return a Z_BUF_ERROR from inflateBack(). */ -#define PULL() \ - do { \ - if (have == 0) { \ - have = in(in_desc, &next); \ - if (have == 0) { \ - next = Z_NULL; \ - ret = Z_BUF_ERROR; \ - goto inf_leave; \ - } \ - } \ - } while (0) - -/* Get a byte of input into the bit accumulator, or return from inflateBack() - with an error if there is no input available. */ -#define PULLBYTE() \ - do { \ - PULL(); \ - have--; \ - hold += (unsigned long)(*next++) << bits; \ - bits += 8; \ - } while (0) - -/* Assure that there are at least n bits in the bit accumulator. If there is - not enough available input to do that, then return from inflateBack() with - an error. */ -#define NEEDBITS(n) \ - do { \ - while (bits < (unsigned)(n)) \ - PULLBYTE(); \ - } while (0) - -/* Return the low n bits of the bit accumulator (n < 16) */ -#define BITS(n) \ - ((unsigned)hold & ((1U << (n)) - 1)) - -/* Remove n bits from the bit accumulator */ -#define DROPBITS(n) \ - do { \ - hold >>= (n); \ - bits -= (unsigned)(n); \ - } while (0) - -/* Remove zero to seven bits as needed to go to a byte boundary */ -#define BYTEBITS() \ - do { \ - hold >>= bits & 7; \ - bits -= bits & 7; \ - } while (0) - -/* Assure that some output space is available, by writing out the window - if it's full. If the write fails, return from inflateBack() with a - Z_BUF_ERROR. */ -#define ROOM() \ - do { \ - if (left == 0) { \ - put = state->window; \ - left = state->wsize; \ - state->whave = left; \ - if (out(out_desc, put, left)) { \ - ret = Z_BUF_ERROR; \ - goto inf_leave; \ - } \ - } \ - } while (0) - -/* - strm provides the memory allocation functions and window buffer on input, - and provides information on the unused input on return. For Z_DATA_ERROR - returns, strm will also provide an error message. - - in() and out() are the call-back input and output functions. When - inflateBack() needs more input, it calls in(). When inflateBack() has - filled the window with output, or when it completes with data in the - window, it calls out() to write out the data. The application must not - change the provided input until in() is called again or inflateBack() - returns. The application must not change the window/output buffer until - inflateBack() returns. - - in() and out() are called with a descriptor parameter provided in the - inflateBack() call. This parameter can be a structure that provides the - information required to do the read or write, as well as accumulated - information on the input and output such as totals and check values. - - in() should return zero on failure. out() should return non-zero on - failure. If either in() or out() fails, than inflateBack() returns a - Z_BUF_ERROR. strm->next_in can be checked for Z_NULL to see whether it - was in() or out() that caused in the error. Otherwise, inflateBack() - returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format - error, or Z_MEM_ERROR if it could not allocate memory for the state. - inflateBack() can also return Z_STREAM_ERROR if the input parameters - are not correct, i.e. strm is Z_NULL or the state was not initialized. - */ -int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc) -z_streamp strm; -in_func in; -void FAR *in_desc; -out_func out; -void FAR *out_desc; -{ - struct inflate_state FAR *state; - z_const unsigned char FAR *next; /* next input */ - unsigned char FAR *put; /* next output */ - unsigned have, left; /* available input and output */ - unsigned long hold; /* bit buffer */ - unsigned bits; /* bits in bit buffer */ - unsigned copy; /* number of stored or match bytes to copy */ - unsigned char FAR *from; /* where to copy match bytes from */ - code here; /* current decoding table entry */ - code last; /* parent table entry */ - unsigned len; /* length to copy for repeats, bits to drop */ - int ret; /* return code */ - static const unsigned short order[19] = /* permutation of code lengths */ - {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; - - /* Check that the strm exists and that the state was initialized */ - if (strm == Z_NULL || strm->state == Z_NULL) - return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - - /* Reset the state */ - strm->msg = Z_NULL; - state->mode = TYPE; - state->last = 0; - state->whave = 0; - next = strm->next_in; - have = next != Z_NULL ? strm->avail_in : 0; - hold = 0; - bits = 0; - put = state->window; - left = state->wsize; - - /* Inflate until end of block marked as last */ - for (;;) - switch (state->mode) { - case TYPE: - /* determine and dispatch block type */ - if (state->last) { - BYTEBITS(); - state->mode = DONE; - break; - } - NEEDBITS(3); - state->last = BITS(1); - DROPBITS(1); - switch (BITS(2)) { - case 0: /* stored block */ - Tracev((stderr, "inflate: stored block%s\n", - state->last ? " (last)" : "")); - state->mode = STORED; - break; - case 1: /* fixed block */ - fixedtables(state); - Tracev((stderr, "inflate: fixed codes block%s\n", - state->last ? " (last)" : "")); - state->mode = LEN; /* decode codes */ - break; - case 2: /* dynamic block */ - Tracev((stderr, "inflate: dynamic codes block%s\n", - state->last ? " (last)" : "")); - state->mode = TABLE; - break; - case 3: - strm->msg = (char *)"invalid block type"; - state->mode = BAD; - } - DROPBITS(2); - break; - - case STORED: - /* get and verify stored block length */ - BYTEBITS(); /* go to byte boundary */ - NEEDBITS(32); - if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) { - strm->msg = (char *)"invalid stored block lengths"; - state->mode = BAD; - break; - } - state->length = (unsigned)hold & 0xffff; - Tracev((stderr, "inflate: stored length %u\n", - state->length)); - INITBITS(); - - /* copy stored block from input to output */ - while (state->length != 0) { - copy = state->length; - PULL(); - ROOM(); - if (copy > have) copy = have; - if (copy > left) copy = left; - zmemcpy(put, next, copy); - have -= copy; - next += copy; - left -= copy; - put += copy; - state->length -= copy; - } - Tracev((stderr, "inflate: stored end\n")); - state->mode = TYPE; - break; - - case TABLE: - /* get dynamic table entries descriptor */ - NEEDBITS(14); - state->nlen = BITS(5) + 257; - DROPBITS(5); - state->ndist = BITS(5) + 1; - DROPBITS(5); - state->ncode = BITS(4) + 4; - DROPBITS(4); -#ifndef PKZIP_BUG_WORKAROUND - if (state->nlen > 286 || state->ndist > 30) { - strm->msg = (char *)"too many length or distance symbols"; - state->mode = BAD; - break; - } -#endif - Tracev((stderr, "inflate: table sizes ok\n")); - - /* get code length code lengths (not a typo) */ - state->have = 0; - while (state->have < state->ncode) { - NEEDBITS(3); - state->lens[order[state->have++]] = (unsigned short)BITS(3); - DROPBITS(3); - } - while (state->have < 19) - state->lens[order[state->have++]] = 0; - state->next = state->codes; - state->lencode = (code const FAR *)(state->next); - state->lenbits = 7; - ret = inflate_table(CODES, state->lens, 19, &(state->next), - &(state->lenbits), state->work); - if (ret) { - strm->msg = (char *)"invalid code lengths set"; - state->mode = BAD; - break; - } - Tracev((stderr, "inflate: code lengths ok\n")); - - /* get length and distance code code lengths */ - state->have = 0; - while (state->have < state->nlen + state->ndist) { - for (;;) { - here = state->lencode[BITS(state->lenbits)]; - if ((unsigned)(here.bits) <= bits) break; - PULLBYTE(); - } - if (here.val < 16) { - DROPBITS(here.bits); - state->lens[state->have++] = here.val; - } - else { - if (here.val == 16) { - NEEDBITS(here.bits + 2); - DROPBITS(here.bits); - if (state->have == 0) { - strm->msg = (char *)"invalid bit length repeat"; - state->mode = BAD; - break; - } - len = (unsigned)(state->lens[state->have - 1]); - copy = 3 + BITS(2); - DROPBITS(2); - } - else if (here.val == 17) { - NEEDBITS(here.bits + 3); - DROPBITS(here.bits); - len = 0; - copy = 3 + BITS(3); - DROPBITS(3); - } - else { - NEEDBITS(here.bits + 7); - DROPBITS(here.bits); - len = 0; - copy = 11 + BITS(7); - DROPBITS(7); - } - if (state->have + copy > state->nlen + state->ndist) { - strm->msg = (char *)"invalid bit length repeat"; - state->mode = BAD; - break; - } - while (copy--) - state->lens[state->have++] = (unsigned short)len; - } - } - - /* handle error breaks in while */ - if (state->mode == BAD) break; - - /* check for end-of-block code (better have one) */ - if (state->lens[256] == 0) { - strm->msg = (char *)"invalid code -- missing end-of-block"; - state->mode = BAD; - break; - } - - /* build code tables -- note: do not change the lenbits or distbits - values here (9 and 6) without reading the comments in inftrees.h - concerning the ENOUGH constants, which depend on those values */ - state->next = state->codes; - state->lencode = (code const FAR *)(state->next); - state->lenbits = 9; - ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), - &(state->lenbits), state->work); - if (ret) { - strm->msg = (char *)"invalid literal/lengths set"; - state->mode = BAD; - break; - } - state->distcode = (code const FAR *)(state->next); - state->distbits = 6; - ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist, - &(state->next), &(state->distbits), state->work); - if (ret) { - strm->msg = (char *)"invalid distances set"; - state->mode = BAD; - break; - } - Tracev((stderr, "inflate: codes ok\n")); - state->mode = LEN; - - case LEN: - /* use inflate_fast() if we have enough input and output */ - if (have >= 6 && left >= 258) { - RESTORE(); - if (state->whave < state->wsize) - state->whave = state->wsize - left; - inflate_fast(strm, state->wsize); - LOAD(); - break; - } - - /* get a literal, length, or end-of-block code */ - for (;;) { - here = state->lencode[BITS(state->lenbits)]; - if ((unsigned)(here.bits) <= bits) break; - PULLBYTE(); - } - if (here.op && (here.op & 0xf0) == 0) { - last = here; - for (;;) { - here = state->lencode[last.val + - (BITS(last.bits + last.op) >> last.bits)]; - if ((unsigned)(last.bits + here.bits) <= bits) break; - PULLBYTE(); - } - DROPBITS(last.bits); - } - DROPBITS(here.bits); - state->length = (unsigned)here.val; - - /* process literal */ - if (here.op == 0) { - Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? - "inflate: literal '%c'\n" : - "inflate: literal 0x%02x\n", here.val)); - ROOM(); - *put++ = (unsigned char)(state->length); - left--; - state->mode = LEN; - break; - } - - /* process end of block */ - if (here.op & 32) { - Tracevv((stderr, "inflate: end of block\n")); - state->mode = TYPE; - break; - } - - /* invalid code */ - if (here.op & 64) { - strm->msg = (char *)"invalid literal/length code"; - state->mode = BAD; - break; - } - - /* length code -- get extra bits, if any */ - state->extra = (unsigned)(here.op) & 15; - if (state->extra != 0) { - NEEDBITS(state->extra); - state->length += BITS(state->extra); - DROPBITS(state->extra); - } - Tracevv((stderr, "inflate: length %u\n", state->length)); - - /* get distance code */ - for (;;) { - here = state->distcode[BITS(state->distbits)]; - if ((unsigned)(here.bits) <= bits) break; - PULLBYTE(); - } - if ((here.op & 0xf0) == 0) { - last = here; - for (;;) { - here = state->distcode[last.val + - (BITS(last.bits + last.op) >> last.bits)]; - if ((unsigned)(last.bits + here.bits) <= bits) break; - PULLBYTE(); - } - DROPBITS(last.bits); - } - DROPBITS(here.bits); - if (here.op & 64) { - strm->msg = (char *)"invalid distance code"; - state->mode = BAD; - break; - } - state->offset = (unsigned)here.val; - - /* get distance extra bits, if any */ - state->extra = (unsigned)(here.op) & 15; - if (state->extra != 0) { - NEEDBITS(state->extra); - state->offset += BITS(state->extra); - DROPBITS(state->extra); - } - if (state->offset > state->wsize - (state->whave < state->wsize ? - left : 0)) { - strm->msg = (char *)"invalid distance too far back"; - state->mode = BAD; - break; - } - Tracevv((stderr, "inflate: distance %u\n", state->offset)); - - /* copy match from window to output */ - do { - ROOM(); - copy = state->wsize - state->offset; - if (copy < left) { - from = put + copy; - copy = left - copy; - } - else { - from = put - state->offset; - copy = left; - } - if (copy > state->length) copy = state->length; - state->length -= copy; - left -= copy; - do { - *put++ = *from++; - } while (--copy); - } while (state->length != 0); - break; - - case DONE: - /* inflate stream terminated properly -- write leftover output */ - ret = Z_STREAM_END; - if (left < state->wsize) { - if (out(out_desc, state->window, state->wsize - left)) - ret = Z_BUF_ERROR; - } - goto inf_leave; - - case BAD: - ret = Z_DATA_ERROR; - goto inf_leave; - - default: /* can't happen, but makes compilers happy */ - ret = Z_STREAM_ERROR; - goto inf_leave; - } - - /* Return unused input */ - inf_leave: - strm->next_in = next; - strm->avail_in = have; - return ret; -} - -int ZEXPORT inflateBackEnd(strm) -z_streamp strm; -{ - if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) - return Z_STREAM_ERROR; - ZFREE(strm, strm->state); - strm->state = Z_NULL; - Tracev((stderr, "inflate: end\n")); - return Z_OK; -} diff --git a/src/beast/test/zlib/zlib-1.2.8/inffast.c b/src/beast/test/zlib/zlib-1.2.8/inffast.c deleted file mode 100644 index bda59ceb6a1..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/inffast.c +++ /dev/null @@ -1,340 +0,0 @@ -/* inffast.c -- fast decoding - * Copyright (C) 1995-2008, 2010, 2013 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#include "zutil.h" -#include "inftrees.h" -#include "inflate.h" -#include "inffast.h" - -#ifndef ASMINF - -/* Allow machine dependent optimization for post-increment or pre-increment. - Based on testing to date, - Pre-increment preferred for: - - PowerPC G3 (Adler) - - MIPS R5000 (Randers-Pehrson) - Post-increment preferred for: - - none - No measurable difference: - - Pentium III (Anderson) - - M68060 (Nikl) - */ -#ifdef POSTINC -# define OFF 0 -# define PUP(a) *(a)++ -#else -# define OFF 1 -# define PUP(a) *++(a) -#endif - -/* - Decode literal, length, and distance codes and write out the resulting - literal and match bytes until either not enough input or output is - available, an end-of-block is encountered, or a data error is encountered. - When large enough input and output buffers are supplied to inflate(), for - example, a 16K input buffer and a 64K output buffer, more than 95% of the - inflate execution time is spent in this routine. - - Entry assumptions: - - state->mode == LEN - strm->avail_in >= 6 - strm->avail_out >= 258 - start >= strm->avail_out - state->bits < 8 - - On return, state->mode is one of: - - LEN -- ran out of enough output space or enough available input - TYPE -- reached end of block code, inflate() to interpret next block - BAD -- error in block data - - Notes: - - - The maximum input bits used by a length/distance pair is 15 bits for the - length code, 5 bits for the length extra, 15 bits for the distance code, - and 13 bits for the distance extra. This totals 48 bits, or six bytes. - Therefore if strm->avail_in >= 6, then there is enough input to avoid - checking for available input while decoding. - - - The maximum bytes that a single length/distance pair can output is 258 - bytes, which is the maximum length that can be coded. inflate_fast() - requires strm->avail_out >= 258 for each loop to avoid checking for - output space. - */ -void ZLIB_INTERNAL inflate_fast(strm, start) -z_streamp strm; -unsigned start; /* inflate()'s starting value for strm->avail_out */ -{ - struct inflate_state FAR *state; - z_const unsigned char FAR *in; /* local strm->next_in */ - z_const unsigned char FAR *last; /* have enough input while in < last */ - unsigned char FAR *out; /* local strm->next_out */ - unsigned char FAR *beg; /* inflate()'s initial strm->next_out */ - unsigned char FAR *end; /* while out < end, enough space available */ -#ifdef INFLATE_STRICT - unsigned dmax; /* maximum distance from zlib header */ -#endif - unsigned wsize; /* window size or zero if not using window */ - unsigned whave; /* valid bytes in the window */ - unsigned wnext; /* window write index */ - unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */ - unsigned long hold; /* local strm->hold */ - unsigned bits; /* local strm->bits */ - code const FAR *lcode; /* local strm->lencode */ - code const FAR *dcode; /* local strm->distcode */ - unsigned lmask; /* mask for first level of length codes */ - unsigned dmask; /* mask for first level of distance codes */ - code here; /* retrieved table entry */ - unsigned op; /* code bits, operation, extra bits, or */ - /* window position, window bytes to copy */ - unsigned len; /* match length, unused bytes */ - unsigned dist; /* match distance */ - unsigned char FAR *from; /* where to copy match from */ - - /* copy state to local variables */ - state = (struct inflate_state FAR *)strm->state; - in = strm->next_in - OFF; - last = in + (strm->avail_in - 5); - out = strm->next_out - OFF; - beg = out - (start - strm->avail_out); - end = out + (strm->avail_out - 257); -#ifdef INFLATE_STRICT - dmax = state->dmax; -#endif - wsize = state->wsize; - whave = state->whave; - wnext = state->wnext; - window = state->window; - hold = state->hold; - bits = state->bits; - lcode = state->lencode; - dcode = state->distcode; - lmask = (1U << state->lenbits) - 1; - dmask = (1U << state->distbits) - 1; - - /* decode literals and length/distances until end-of-block or not enough - input data or output space */ - do { - if (bits < 15) { - hold += (unsigned long)(PUP(in)) << bits; - bits += 8; - hold += (unsigned long)(PUP(in)) << bits; - bits += 8; - } - here = lcode[hold & lmask]; - dolen: - op = (unsigned)(here.bits); - hold >>= op; - bits -= op; - op = (unsigned)(here.op); - if (op == 0) { /* literal */ - Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? - "inflate: literal '%c'\n" : - "inflate: literal 0x%02x\n", here.val)); - PUP(out) = (unsigned char)(here.val); - } - else if (op & 16) { /* length base */ - len = (unsigned)(here.val); - op &= 15; /* number of extra bits */ - if (op) { - if (bits < op) { - hold += (unsigned long)(PUP(in)) << bits; - bits += 8; - } - len += (unsigned)hold & ((1U << op) - 1); - hold >>= op; - bits -= op; - } - Tracevv((stderr, "inflate: length %u\n", len)); - if (bits < 15) { - hold += (unsigned long)(PUP(in)) << bits; - bits += 8; - hold += (unsigned long)(PUP(in)) << bits; - bits += 8; - } - here = dcode[hold & dmask]; - dodist: - op = (unsigned)(here.bits); - hold >>= op; - bits -= op; - op = (unsigned)(here.op); - if (op & 16) { /* distance base */ - dist = (unsigned)(here.val); - op &= 15; /* number of extra bits */ - if (bits < op) { - hold += (unsigned long)(PUP(in)) << bits; - bits += 8; - if (bits < op) { - hold += (unsigned long)(PUP(in)) << bits; - bits += 8; - } - } - dist += (unsigned)hold & ((1U << op) - 1); -#ifdef INFLATE_STRICT - if (dist > dmax) { - strm->msg = (char *)"invalid distance too far back"; - state->mode = BAD; - break; - } -#endif - hold >>= op; - bits -= op; - Tracevv((stderr, "inflate: distance %u\n", dist)); - op = (unsigned)(out - beg); /* max distance in output */ - if (dist > op) { /* see if copy from window */ - op = dist - op; /* distance back in window */ - if (op > whave) { - if (state->sane) { - strm->msg = - (char *)"invalid distance too far back"; - state->mode = BAD; - break; - } -#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR - if (len <= op - whave) { - do { - PUP(out) = 0; - } while (--len); - continue; - } - len -= op - whave; - do { - PUP(out) = 0; - } while (--op > whave); - if (op == 0) { - from = out - dist; - do { - PUP(out) = PUP(from); - } while (--len); - continue; - } -#endif - } - from = window - OFF; - if (wnext == 0) { /* very common case */ - from += wsize - op; - if (op < len) { /* some from window */ - len -= op; - do { - PUP(out) = PUP(from); - } while (--op); - from = out - dist; /* rest from output */ - } - } - else if (wnext < op) { /* wrap around window */ - from += wsize + wnext - op; - op -= wnext; - if (op < len) { /* some from end of window */ - len -= op; - do { - PUP(out) = PUP(from); - } while (--op); - from = window - OFF; - if (wnext < len) { /* some from start of window */ - op = wnext; - len -= op; - do { - PUP(out) = PUP(from); - } while (--op); - from = out - dist; /* rest from output */ - } - } - } - else { /* contiguous in window */ - from += wnext - op; - if (op < len) { /* some from window */ - len -= op; - do { - PUP(out) = PUP(from); - } while (--op); - from = out - dist; /* rest from output */ - } - } - while (len > 2) { - PUP(out) = PUP(from); - PUP(out) = PUP(from); - PUP(out) = PUP(from); - len -= 3; - } - if (len) { - PUP(out) = PUP(from); - if (len > 1) - PUP(out) = PUP(from); - } - } - else { - from = out - dist; /* copy direct from output */ - do { /* minimum length is three */ - PUP(out) = PUP(from); - PUP(out) = PUP(from); - PUP(out) = PUP(from); - len -= 3; - } while (len > 2); - if (len) { - PUP(out) = PUP(from); - if (len > 1) - PUP(out) = PUP(from); - } - } - } - else if ((op & 64) == 0) { /* 2nd level distance code */ - here = dcode[here.val + (hold & ((1U << op) - 1))]; - goto dodist; - } - else { - strm->msg = (char *)"invalid distance code"; - state->mode = BAD; - break; - } - } - else if ((op & 64) == 0) { /* 2nd level length code */ - here = lcode[here.val + (hold & ((1U << op) - 1))]; - goto dolen; - } - else if (op & 32) { /* end-of-block */ - Tracevv((stderr, "inflate: end of block\n")); - state->mode = TYPE; - break; - } - else { - strm->msg = (char *)"invalid literal/length code"; - state->mode = BAD; - break; - } - } while (in < last && out < end); - - /* return unused bytes (on entry, bits < 8, so in won't go too far back) */ - len = bits >> 3; - in -= len; - bits -= len << 3; - hold &= (1U << bits) - 1; - - /* update state and return */ - strm->next_in = in + OFF; - strm->next_out = out + OFF; - strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last)); - strm->avail_out = (unsigned)(out < end ? - 257 + (end - out) : 257 - (out - end)); - state->hold = hold; - state->bits = bits; - return; -} - -/* - inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe): - - Using bit fields for code structure - - Different op definition to avoid & for extra bits (do & for table bits) - - Three separate decoding do-loops for direct, window, and wnext == 0 - - Special case for distance > 1 copies to do overlapped load and store copy - - Explicit branch predictions (based on measured branch probabilities) - - Deferring match copy and interspersed it with decoding subsequent codes - - Swapping literal/length else - - Swapping window/direct else - - Larger unrolled copy loops (three is about right) - - Moving len -= 3 statement into middle of loop - */ - -#endif /* !ASMINF */ diff --git a/src/beast/test/zlib/zlib-1.2.8/inffast.h b/src/beast/test/zlib/zlib-1.2.8/inffast.h deleted file mode 100644 index e5c1aa4ca8c..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/inffast.h +++ /dev/null @@ -1,11 +0,0 @@ -/* inffast.h -- header to use inffast.c - * Copyright (C) 1995-2003, 2010 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start)); diff --git a/src/beast/test/zlib/zlib-1.2.8/inffixed.h b/src/beast/test/zlib/zlib-1.2.8/inffixed.h deleted file mode 100644 index d6283277694..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/inffixed.h +++ /dev/null @@ -1,94 +0,0 @@ - /* inffixed.h -- table for decoding fixed codes - * Generated automatically by makefixed(). - */ - - /* WARNING: this file should *not* be used by applications. - It is part of the implementation of this library and is - subject to change. Applications should only use zlib.h. - */ - - static const code lenfix[512] = { - {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, - {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, - {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, - {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176}, - {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20}, - {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100}, - {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8}, - {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216}, - {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76}, - {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114}, - {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2}, - {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148}, - {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42}, - {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86}, - {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15}, - {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236}, - {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62}, - {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, - {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31}, - {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162}, - {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25}, - {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105}, - {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4}, - {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202}, - {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69}, - {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125}, - {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13}, - {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195}, - {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35}, - {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91}, - {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19}, - {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246}, - {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55}, - {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135}, - {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99}, - {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190}, - {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16}, - {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96}, - {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6}, - {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209}, - {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72}, - {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116}, - {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4}, - {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153}, - {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44}, - {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82}, - {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11}, - {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, - {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58}, - {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138}, - {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51}, - {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173}, - {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30}, - {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110}, - {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0}, - {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195}, - {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65}, - {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121}, - {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9}, - {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258}, - {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37}, - {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93}, - {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23}, - {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251}, - {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51}, - {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, - {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67}, - {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183}, - {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23}, - {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103}, - {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9}, - {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223}, - {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79}, - {0,9,255} - }; - - static const code distfix[32] = { - {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, - {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, - {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, - {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577}, - {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073}, - {22,5,193},{64,5,0} - }; diff --git a/src/beast/test/zlib/zlib-1.2.8/inflate.c b/src/beast/test/zlib/zlib-1.2.8/inflate.c deleted file mode 100644 index 870f89bb4d3..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/inflate.c +++ /dev/null @@ -1,1512 +0,0 @@ -/* inflate.c -- zlib decompression - * Copyright (C) 1995-2012 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* - * Change history: - * - * 1.2.beta0 24 Nov 2002 - * - First version -- complete rewrite of inflate to simplify code, avoid - * creation of window when not needed, minimize use of window when it is - * needed, make inffast.c even faster, implement gzip decoding, and to - * improve code readability and style over the previous zlib inflate code - * - * 1.2.beta1 25 Nov 2002 - * - Use pointers for available input and output checking in inffast.c - * - Remove input and output counters in inffast.c - * - Change inffast.c entry and loop from avail_in >= 7 to >= 6 - * - Remove unnecessary second byte pull from length extra in inffast.c - * - Unroll direct copy to three copies per loop in inffast.c - * - * 1.2.beta2 4 Dec 2002 - * - Change external routine names to reduce potential conflicts - * - Correct filename to inffixed.h for fixed tables in inflate.c - * - Make hbuf[] unsigned char to match parameter type in inflate.c - * - Change strm->next_out[-state->offset] to *(strm->next_out - state->offset) - * to avoid negation problem on Alphas (64 bit) in inflate.c - * - * 1.2.beta3 22 Dec 2002 - * - Add comments on state->bits assertion in inffast.c - * - Add comments on op field in inftrees.h - * - Fix bug in reuse of allocated window after inflateReset() - * - Remove bit fields--back to byte structure for speed - * - Remove distance extra == 0 check in inflate_fast()--only helps for lengths - * - Change post-increments to pre-increments in inflate_fast(), PPC biased? - * - Add compile time option, POSTINC, to use post-increments instead (Intel?) - * - Make MATCH copy in inflate() much faster for when inflate_fast() not used - * - Use local copies of stream next and avail values, as well as local bit - * buffer and bit count in inflate()--for speed when inflate_fast() not used - * - * 1.2.beta4 1 Jan 2003 - * - Split ptr - 257 statements in inflate_table() to avoid compiler warnings - * - Move a comment on output buffer sizes from inffast.c to inflate.c - * - Add comments in inffast.c to introduce the inflate_fast() routine - * - Rearrange window copies in inflate_fast() for speed and simplification - * - Unroll last copy for window match in inflate_fast() - * - Use local copies of window variables in inflate_fast() for speed - * - Pull out common wnext == 0 case for speed in inflate_fast() - * - Make op and len in inflate_fast() unsigned for consistency - * - Add FAR to lcode and dcode declarations in inflate_fast() - * - Simplified bad distance check in inflate_fast() - * - Added inflateBackInit(), inflateBack(), and inflateBackEnd() in new - * source file infback.c to provide a call-back interface to inflate for - * programs like gzip and unzip -- uses window as output buffer to avoid - * window copying - * - * 1.2.beta5 1 Jan 2003 - * - Improved inflateBack() interface to allow the caller to provide initial - * input in strm. - * - Fixed stored blocks bug in inflateBack() - * - * 1.2.beta6 4 Jan 2003 - * - Added comments in inffast.c on effectiveness of POSTINC - * - Typecasting all around to reduce compiler warnings - * - Changed loops from while (1) or do {} while (1) to for (;;), again to - * make compilers happy - * - Changed type of window in inflateBackInit() to unsigned char * - * - * 1.2.beta7 27 Jan 2003 - * - Changed many types to unsigned or unsigned short to avoid warnings - * - Added inflateCopy() function - * - * 1.2.0 9 Mar 2003 - * - Changed inflateBack() interface to provide separate opaque descriptors - * for the in() and out() functions - * - Changed inflateBack() argument and in_func typedef to swap the length - * and buffer address return values for the input function - * - Check next_in and next_out for Z_NULL on entry to inflate() - * - * The history for versions after 1.2.0 are in ChangeLog in zlib distribution. - */ - -#include "zutil.h" -#include "inftrees.h" -#include "inflate.h" -#include "inffast.h" - -#ifdef MAKEFIXED -# ifndef BUILDFIXED -# define BUILDFIXED -# endif -#endif - -/* function prototypes */ -local void fixedtables OF((struct inflate_state FAR *state)); -local int updatewindow OF((z_streamp strm, const unsigned char FAR *end, - unsigned copy)); -#ifdef BUILDFIXED - void makefixed OF((void)); -#endif -local unsigned syncsearch OF((unsigned FAR *have, const unsigned char FAR *buf, - unsigned len)); - -int ZEXPORT inflateResetKeep(strm) -z_streamp strm; -{ - struct inflate_state FAR *state; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - strm->total_in = strm->total_out = state->total = 0; - strm->msg = Z_NULL; - if (state->wrap) /* to support ill-conceived Java test suite */ - strm->adler = state->wrap & 1; - state->mode = HEAD; - state->last = 0; - state->havedict = 0; - state->dmax = 32768U; - state->head = Z_NULL; - state->hold = 0; - state->bits = 0; - state->lencode = state->distcode = state->next = state->codes; - state->sane = 1; - state->back = -1; - Tracev((stderr, "inflate: reset\n")); - return Z_OK; -} - -int ZEXPORT inflateReset(strm) -z_streamp strm; -{ - struct inflate_state FAR *state; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - state->wsize = 0; - state->whave = 0; - state->wnext = 0; - return inflateResetKeep(strm); -} - -int ZEXPORT inflateReset2(strm, windowBits) -z_streamp strm; -int windowBits; -{ - int wrap; - struct inflate_state FAR *state; - - /* get the state */ - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - - /* extract wrap request from windowBits parameter */ - if (windowBits < 0) { - wrap = 0; - windowBits = -windowBits; - } - else { - wrap = (windowBits >> 4) + 1; -#ifdef GUNZIP - if (windowBits < 48) - windowBits &= 15; -#endif - } - - /* set number of window bits, free window if different */ - if (windowBits && (windowBits < 8 || windowBits > 15)) - return Z_STREAM_ERROR; - if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) { - ZFREE(strm, state->window); - state->window = Z_NULL; - } - - /* update state and reset the rest of it */ - state->wrap = wrap; - state->wbits = (unsigned)windowBits; - return inflateReset(strm); -} - -int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size) -z_streamp strm; -int windowBits; -const char *version; -int stream_size; -{ - int ret; - struct inflate_state FAR *state; - - if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || - stream_size != (int)(sizeof(z_stream))) - return Z_VERSION_ERROR; - if (strm == Z_NULL) return Z_STREAM_ERROR; - strm->msg = Z_NULL; /* in case we return an error */ - if (strm->zalloc == (alloc_func)0) { -#ifdef Z_SOLO - return Z_STREAM_ERROR; -#else - strm->zalloc = zcalloc; - strm->opaque = (voidpf)0; -#endif - } - if (strm->zfree == (free_func)0) -#ifdef Z_SOLO - return Z_STREAM_ERROR; -#else - strm->zfree = zcfree; -#endif - state = (struct inflate_state FAR *) - ZALLOC(strm, 1, sizeof(struct inflate_state)); - if (state == Z_NULL) return Z_MEM_ERROR; - Tracev((stderr, "inflate: allocated\n")); - strm->state = (struct internal_state FAR *)state; - state->window = Z_NULL; - ret = inflateReset2(strm, windowBits); - if (ret != Z_OK) { - ZFREE(strm, state); - strm->state = Z_NULL; - } - return ret; -} - -int ZEXPORT inflateInit_(strm, version, stream_size) -z_streamp strm; -const char *version; -int stream_size; -{ - return inflateInit2_(strm, DEF_WBITS, version, stream_size); -} - -int ZEXPORT inflatePrime(strm, bits, value) -z_streamp strm; -int bits; -int value; -{ - struct inflate_state FAR *state; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - if (bits < 0) { - state->hold = 0; - state->bits = 0; - return Z_OK; - } - if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR; - value &= (1L << bits) - 1; - state->hold += value << state->bits; - state->bits += bits; - return Z_OK; -} - -/* - Return state with length and distance decoding tables and index sizes set to - fixed code decoding. Normally this returns fixed tables from inffixed.h. - If BUILDFIXED is defined, then instead this routine builds the tables the - first time it's called, and returns those tables the first time and - thereafter. This reduces the size of the code by about 2K bytes, in - exchange for a little execution time. However, BUILDFIXED should not be - used for threaded applications, since the rewriting of the tables and virgin - may not be thread-safe. - */ -local void fixedtables(state) -struct inflate_state FAR *state; -{ -#ifdef BUILDFIXED - static int virgin = 1; - static code *lenfix, *distfix; - static code fixed[544]; - - /* build fixed huffman tables if first call (may not be thread safe) */ - if (virgin) { - unsigned sym, bits; - static code *next; - - /* literal/length table */ - sym = 0; - while (sym < 144) state->lens[sym++] = 8; - while (sym < 256) state->lens[sym++] = 9; - while (sym < 280) state->lens[sym++] = 7; - while (sym < 288) state->lens[sym++] = 8; - next = fixed; - lenfix = next; - bits = 9; - inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work); - - /* distance table */ - sym = 0; - while (sym < 32) state->lens[sym++] = 5; - distfix = next; - bits = 5; - inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work); - - /* do this just once */ - virgin = 0; - } -#else /* !BUILDFIXED */ -# include "inffixed.h" -#endif /* BUILDFIXED */ - state->lencode = lenfix; - state->lenbits = 9; - state->distcode = distfix; - state->distbits = 5; -} - -#ifdef MAKEFIXED -#include - -/* - Write out the inffixed.h that is #include'd above. Defining MAKEFIXED also - defines BUILDFIXED, so the tables are built on the fly. makefixed() writes - those tables to stdout, which would be piped to inffixed.h. A small program - can simply call makefixed to do this: - - void makefixed(void); - - int main(void) - { - makefixed(); - return 0; - } - - Then that can be linked with zlib built with MAKEFIXED defined and run: - - a.out > inffixed.h - */ -void makefixed() -{ - unsigned low, size; - struct inflate_state state; - - fixedtables(&state); - puts(" /* inffixed.h -- table for decoding fixed codes"); - puts(" * Generated automatically by makefixed()."); - puts(" */"); - puts(""); - puts(" /* WARNING: this file should *not* be used by applications."); - puts(" It is part of the implementation of this library and is"); - puts(" subject to change. Applications should only use zlib.h."); - puts(" */"); - puts(""); - size = 1U << 9; - printf(" static const code lenfix[%u] = {", size); - low = 0; - for (;;) { - if ((low % 7) == 0) printf("\n "); - printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op, - state.lencode[low].bits, state.lencode[low].val); - if (++low == size) break; - putchar(','); - } - puts("\n };"); - size = 1U << 5; - printf("\n static const code distfix[%u] = {", size); - low = 0; - for (;;) { - if ((low % 6) == 0) printf("\n "); - printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits, - state.distcode[low].val); - if (++low == size) break; - putchar(','); - } - puts("\n };"); -} -#endif /* MAKEFIXED */ - -/* - Update the window with the last wsize (normally 32K) bytes written before - returning. If window does not exist yet, create it. This is only called - when a window is already in use, or when output has been written during this - inflate call, but the end of the deflate stream has not been reached yet. - It is also called to create a window for dictionary data when a dictionary - is loaded. - - Providing output buffers larger than 32K to inflate() should provide a speed - advantage, since only the last 32K of output is copied to the sliding window - upon return from inflate(), and since all distances after the first 32K of - output will fall in the output data, making match copies simpler and faster. - The advantage may be dependent on the size of the processor's data caches. - */ -local int updatewindow(strm, end, copy) -z_streamp strm; -const Bytef *end; -unsigned copy; -{ - struct inflate_state FAR *state; - unsigned dist; - - state = (struct inflate_state FAR *)strm->state; - - /* if it hasn't been done already, allocate space for the window */ - if (state->window == Z_NULL) { - state->window = (unsigned char FAR *) - ZALLOC(strm, 1U << state->wbits, - sizeof(unsigned char)); - if (state->window == Z_NULL) return 1; - } - - /* if window not in use yet, initialize */ - if (state->wsize == 0) { - state->wsize = 1U << state->wbits; - state->wnext = 0; - state->whave = 0; - } - - /* copy state->wsize or less output bytes into the circular window */ - if (copy >= state->wsize) { - zmemcpy(state->window, end - state->wsize, state->wsize); - state->wnext = 0; - state->whave = state->wsize; - } - else { - dist = state->wsize - state->wnext; - if (dist > copy) dist = copy; - zmemcpy(state->window + state->wnext, end - copy, dist); - copy -= dist; - if (copy) { - zmemcpy(state->window, end - copy, copy); - state->wnext = copy; - state->whave = state->wsize; - } - else { - state->wnext += dist; - if (state->wnext == state->wsize) state->wnext = 0; - if (state->whave < state->wsize) state->whave += dist; - } - } - return 0; -} - -/* Macros for inflate(): */ - -/* check function to use adler32() for zlib or crc32() for gzip */ -#ifdef GUNZIP -# define UPDATE(check, buf, len) \ - (state->flags ? crc32(check, buf, len) : adler32(check, buf, len)) -#else -# define UPDATE(check, buf, len) adler32(check, buf, len) -#endif - -/* check macros for header crc */ -#ifdef GUNZIP -# define CRC2(check, word) \ - do { \ - hbuf[0] = (unsigned char)(word); \ - hbuf[1] = (unsigned char)((word) >> 8); \ - check = crc32(check, hbuf, 2); \ - } while (0) - -# define CRC4(check, word) \ - do { \ - hbuf[0] = (unsigned char)(word); \ - hbuf[1] = (unsigned char)((word) >> 8); \ - hbuf[2] = (unsigned char)((word) >> 16); \ - hbuf[3] = (unsigned char)((word) >> 24); \ - check = crc32(check, hbuf, 4); \ - } while (0) -#endif - -/* Load registers with state in inflate() for speed */ -#define LOAD() \ - do { \ - put = strm->next_out; \ - left = strm->avail_out; \ - next = strm->next_in; \ - have = strm->avail_in; \ - hold = state->hold; \ - bits = state->bits; \ - } while (0) - -/* Restore state from registers in inflate() */ -#define RESTORE() \ - do { \ - strm->next_out = put; \ - strm->avail_out = left; \ - strm->next_in = next; \ - strm->avail_in = have; \ - state->hold = hold; \ - state->bits = bits; \ - } while (0) - -/* Clear the input bit accumulator */ -#define INITBITS() \ - do { \ - hold = 0; \ - bits = 0; \ - } while (0) - -/* Get a byte of input into the bit accumulator, or return from inflate() - if there is no input available. */ -#define PULLBYTE() \ - do { \ - if (have == 0) goto inf_leave; \ - have--; \ - hold += (unsigned long)(*next++) << bits; \ - bits += 8; \ - } while (0) - -/* Assure that there are at least n bits in the bit accumulator. If there is - not enough available input to do that, then return from inflate(). */ -#define NEEDBITS(n) \ - do { \ - while (bits < (unsigned)(n)) \ - PULLBYTE(); \ - } while (0) - -/* Return the low n bits of the bit accumulator (n < 16) */ -#define BITS(n) \ - ((unsigned)hold & ((1U << (n)) - 1)) - -/* Remove n bits from the bit accumulator */ -#define DROPBITS(n) \ - do { \ - hold >>= (n); \ - bits -= (unsigned)(n); \ - } while (0) - -/* Remove zero to seven bits as needed to go to a byte boundary */ -#define BYTEBITS() \ - do { \ - hold >>= bits & 7; \ - bits -= bits & 7; \ - } while (0) - -/* - inflate() uses a state machine to process as much input data and generate as - much output data as possible before returning. The state machine is - structured roughly as follows: - - for (;;) switch (state) { - ... - case STATEn: - if (not enough input data or output space to make progress) - return; - ... make progress ... - state = STATEm; - break; - ... - } - - so when inflate() is called again, the same case is attempted again, and - if the appropriate resources are provided, the machine proceeds to the - next state. The NEEDBITS() macro is usually the way the state evaluates - whether it can proceed or should return. NEEDBITS() does the return if - the requested bits are not available. The typical use of the BITS macros - is: - - NEEDBITS(n); - ... do something with BITS(n) ... - DROPBITS(n); - - where NEEDBITS(n) either returns from inflate() if there isn't enough - input left to load n bits into the accumulator, or it continues. BITS(n) - gives the low n bits in the accumulator. When done, DROPBITS(n) drops - the low n bits off the accumulator. INITBITS() clears the accumulator - and sets the number of available bits to zero. BYTEBITS() discards just - enough bits to put the accumulator on a byte boundary. After BYTEBITS() - and a NEEDBITS(8), then BITS(8) would return the next byte in the stream. - - NEEDBITS(n) uses PULLBYTE() to get an available byte of input, or to return - if there is no input available. The decoding of variable length codes uses - PULLBYTE() directly in order to pull just enough bytes to decode the next - code, and no more. - - Some states loop until they get enough input, making sure that enough - state information is maintained to continue the loop where it left off - if NEEDBITS() returns in the loop. For example, want, need, and keep - would all have to actually be part of the saved state in case NEEDBITS() - returns: - - case STATEw: - while (want < need) { - NEEDBITS(n); - keep[want++] = BITS(n); - DROPBITS(n); - } - state = STATEx; - case STATEx: - - As shown above, if the next state is also the next case, then the break - is omitted. - - A state may also return if there is not enough output space available to - complete that state. Those states are copying stored data, writing a - literal byte, and copying a matching string. - - When returning, a "goto inf_leave" is used to update the total counters, - update the check value, and determine whether any progress has been made - during that inflate() call in order to return the proper return code. - Progress is defined as a change in either strm->avail_in or strm->avail_out. - When there is a window, goto inf_leave will update the window with the last - output written. If a goto inf_leave occurs in the middle of decompression - and there is no window currently, goto inf_leave will create one and copy - output to the window for the next call of inflate(). - - In this implementation, the flush parameter of inflate() only affects the - return code (per zlib.h). inflate() always writes as much as possible to - strm->next_out, given the space available and the provided input--the effect - documented in zlib.h of Z_SYNC_FLUSH. Furthermore, inflate() always defers - the allocation of and copying into a sliding window until necessary, which - provides the effect documented in zlib.h for Z_FINISH when the entire input - stream available. So the only thing the flush parameter actually does is: - when flush is set to Z_FINISH, inflate() cannot return Z_OK. Instead it - will return Z_BUF_ERROR if it has not reached the end of the stream. - */ - -int ZEXPORT inflate(strm, flush) -z_streamp strm; -int flush; -{ - struct inflate_state FAR *state; - z_const unsigned char FAR *next; /* next input */ - unsigned char FAR *put; /* next output */ - unsigned have, left; /* available input and output */ - unsigned long hold; /* bit buffer */ - unsigned bits; /* bits in bit buffer */ - unsigned in, out; /* save starting available input and output */ - unsigned copy; /* number of stored or match bytes to copy */ - unsigned char FAR *from; /* where to copy match bytes from */ - code here; /* current decoding table entry */ - code last; /* parent table entry */ - unsigned len; /* length to copy for repeats, bits to drop */ - int ret; /* return code */ -#ifdef GUNZIP - unsigned char hbuf[4]; /* buffer for gzip header crc calculation */ -#endif - static const unsigned short order[19] = /* permutation of code lengths */ - {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; - - if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL || - (strm->next_in == Z_NULL && strm->avail_in != 0)) - return Z_STREAM_ERROR; - - state = (struct inflate_state FAR *)strm->state; - if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */ - LOAD(); - in = have; - out = left; - ret = Z_OK; - for (;;) - switch (state->mode) { - case HEAD: - if (state->wrap == 0) { - state->mode = TYPEDO; - break; - } - NEEDBITS(16); -#ifdef GUNZIP - if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */ - state->check = crc32(0L, Z_NULL, 0); - CRC2(state->check, hold); - INITBITS(); - state->mode = FLAGS; - break; - } - state->flags = 0; /* expect zlib header */ - if (state->head != Z_NULL) - state->head->done = -1; - if (!(state->wrap & 1) || /* check if zlib header allowed */ -#else - if ( -#endif - ((BITS(8) << 8) + (hold >> 8)) % 31) { - strm->msg = (char *)"incorrect header check"; - state->mode = BAD; - break; - } - if (BITS(4) != Z_DEFLATED) { - strm->msg = (char *)"unknown compression method"; - state->mode = BAD; - break; - } - DROPBITS(4); - len = BITS(4) + 8; - if (state->wbits == 0) - state->wbits = len; - else if (len > state->wbits) { - strm->msg = (char *)"invalid window size"; - state->mode = BAD; - break; - } - state->dmax = 1U << len; - Tracev((stderr, "inflate: zlib header ok\n")); - strm->adler = state->check = adler32(0L, Z_NULL, 0); - state->mode = hold & 0x200 ? DICTID : TYPE; - INITBITS(); - break; -#ifdef GUNZIP - case FLAGS: - NEEDBITS(16); - state->flags = (int)(hold); - if ((state->flags & 0xff) != Z_DEFLATED) { - strm->msg = (char *)"unknown compression method"; - state->mode = BAD; - break; - } - if (state->flags & 0xe000) { - strm->msg = (char *)"unknown header flags set"; - state->mode = BAD; - break; - } - if (state->head != Z_NULL) - state->head->text = (int)((hold >> 8) & 1); - if (state->flags & 0x0200) CRC2(state->check, hold); - INITBITS(); - state->mode = TIME; - case TIME: - NEEDBITS(32); - if (state->head != Z_NULL) - state->head->time = hold; - if (state->flags & 0x0200) CRC4(state->check, hold); - INITBITS(); - state->mode = OS; - case OS: - NEEDBITS(16); - if (state->head != Z_NULL) { - state->head->xflags = (int)(hold & 0xff); - state->head->os = (int)(hold >> 8); - } - if (state->flags & 0x0200) CRC2(state->check, hold); - INITBITS(); - state->mode = EXLEN; - case EXLEN: - if (state->flags & 0x0400) { - NEEDBITS(16); - state->length = (unsigned)(hold); - if (state->head != Z_NULL) - state->head->extra_len = (unsigned)hold; - if (state->flags & 0x0200) CRC2(state->check, hold); - INITBITS(); - } - else if (state->head != Z_NULL) - state->head->extra = Z_NULL; - state->mode = EXTRA; - case EXTRA: - if (state->flags & 0x0400) { - copy = state->length; - if (copy > have) copy = have; - if (copy) { - if (state->head != Z_NULL && - state->head->extra != Z_NULL) { - len = state->head->extra_len - state->length; - zmemcpy(state->head->extra + len, next, - len + copy > state->head->extra_max ? - state->head->extra_max - len : copy); - } - if (state->flags & 0x0200) - state->check = crc32(state->check, next, copy); - have -= copy; - next += copy; - state->length -= copy; - } - if (state->length) goto inf_leave; - } - state->length = 0; - state->mode = NAME; - case NAME: - if (state->flags & 0x0800) { - if (have == 0) goto inf_leave; - copy = 0; - do { - len = (unsigned)(next[copy++]); - if (state->head != Z_NULL && - state->head->name != Z_NULL && - state->length < state->head->name_max) - state->head->name[state->length++] = len; - } while (len && copy < have); - if (state->flags & 0x0200) - state->check = crc32(state->check, next, copy); - have -= copy; - next += copy; - if (len) goto inf_leave; - } - else if (state->head != Z_NULL) - state->head->name = Z_NULL; - state->length = 0; - state->mode = COMMENT; - case COMMENT: - if (state->flags & 0x1000) { - if (have == 0) goto inf_leave; - copy = 0; - do { - len = (unsigned)(next[copy++]); - if (state->head != Z_NULL && - state->head->comment != Z_NULL && - state->length < state->head->comm_max) - state->head->comment[state->length++] = len; - } while (len && copy < have); - if (state->flags & 0x0200) - state->check = crc32(state->check, next, copy); - have -= copy; - next += copy; - if (len) goto inf_leave; - } - else if (state->head != Z_NULL) - state->head->comment = Z_NULL; - state->mode = HCRC; - case HCRC: - if (state->flags & 0x0200) { - NEEDBITS(16); - if (hold != (state->check & 0xffff)) { - strm->msg = (char *)"header crc mismatch"; - state->mode = BAD; - break; - } - INITBITS(); - } - if (state->head != Z_NULL) { - state->head->hcrc = (int)((state->flags >> 9) & 1); - state->head->done = 1; - } - strm->adler = state->check = crc32(0L, Z_NULL, 0); - state->mode = TYPE; - break; -#endif - case DICTID: - NEEDBITS(32); - strm->adler = state->check = ZSWAP32(hold); - INITBITS(); - state->mode = DICT; - case DICT: - if (state->havedict == 0) { - RESTORE(); - return Z_NEED_DICT; - } - strm->adler = state->check = adler32(0L, Z_NULL, 0); - state->mode = TYPE; - case TYPE: - if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave; - case TYPEDO: - if (state->last) { - BYTEBITS(); - state->mode = CHECK; - break; - } - NEEDBITS(3); - state->last = BITS(1); - DROPBITS(1); - switch (BITS(2)) { - case 0: /* stored block */ - Tracev((stderr, "inflate: stored block%s\n", - state->last ? " (last)" : "")); - state->mode = STORED; - break; - case 1: /* fixed block */ - fixedtables(state); - Tracev((stderr, "inflate: fixed codes block%s\n", - state->last ? " (last)" : "")); - state->mode = LEN_; /* decode codes */ - if (flush == Z_TREES) { - DROPBITS(2); - goto inf_leave; - } - break; - case 2: /* dynamic block */ - Tracev((stderr, "inflate: dynamic codes block%s\n", - state->last ? " (last)" : "")); - state->mode = TABLE; - break; - case 3: - strm->msg = (char *)"invalid block type"; - state->mode = BAD; - } - DROPBITS(2); - break; - case STORED: - BYTEBITS(); /* go to byte boundary */ - NEEDBITS(32); - if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) { - strm->msg = (char *)"invalid stored block lengths"; - state->mode = BAD; - break; - } - state->length = (unsigned)hold & 0xffff; - Tracev((stderr, "inflate: stored length %u\n", - state->length)); - INITBITS(); - state->mode = COPY_; - if (flush == Z_TREES) goto inf_leave; - case COPY_: - state->mode = COPY; - case COPY: - copy = state->length; - if (copy) { - if (copy > have) copy = have; - if (copy > left) copy = left; - if (copy == 0) goto inf_leave; - zmemcpy(put, next, copy); - have -= copy; - next += copy; - left -= copy; - put += copy; - state->length -= copy; - break; - } - Tracev((stderr, "inflate: stored end\n")); - state->mode = TYPE; - break; - case TABLE: - NEEDBITS(14); - state->nlen = BITS(5) + 257; - DROPBITS(5); - state->ndist = BITS(5) + 1; - DROPBITS(5); - state->ncode = BITS(4) + 4; - DROPBITS(4); -#ifndef PKZIP_BUG_WORKAROUND - if (state->nlen > 286 || state->ndist > 30) { - strm->msg = (char *)"too many length or distance symbols"; - state->mode = BAD; - break; - } -#endif - Tracev((stderr, "inflate: table sizes ok\n")); - state->have = 0; - state->mode = LENLENS; - case LENLENS: - while (state->have < state->ncode) { - NEEDBITS(3); - state->lens[order[state->have++]] = (unsigned short)BITS(3); - DROPBITS(3); - } - while (state->have < 19) - state->lens[order[state->have++]] = 0; - state->next = state->codes; - state->lencode = (const code FAR *)(state->next); - state->lenbits = 7; - ret = inflate_table(CODES, state->lens, 19, &(state->next), - &(state->lenbits), state->work); - if (ret) { - strm->msg = (char *)"invalid code lengths set"; - state->mode = BAD; - break; - } - Tracev((stderr, "inflate: code lengths ok\n")); - state->have = 0; - state->mode = CODELENS; - case CODELENS: - while (state->have < state->nlen + state->ndist) { - for (;;) { - here = state->lencode[BITS(state->lenbits)]; - if ((unsigned)(here.bits) <= bits) break; - PULLBYTE(); - } - if (here.val < 16) { - DROPBITS(here.bits); - state->lens[state->have++] = here.val; - } - else { - if (here.val == 16) { - NEEDBITS(here.bits + 2); - DROPBITS(here.bits); - if (state->have == 0) { - strm->msg = (char *)"invalid bit length repeat"; - state->mode = BAD; - break; - } - len = state->lens[state->have - 1]; - copy = 3 + BITS(2); - DROPBITS(2); - } - else if (here.val == 17) { - NEEDBITS(here.bits + 3); - DROPBITS(here.bits); - len = 0; - copy = 3 + BITS(3); - DROPBITS(3); - } - else { - NEEDBITS(here.bits + 7); - DROPBITS(here.bits); - len = 0; - copy = 11 + BITS(7); - DROPBITS(7); - } - if (state->have + copy > state->nlen + state->ndist) { - strm->msg = (char *)"invalid bit length repeat"; - state->mode = BAD; - break; - } - while (copy--) - state->lens[state->have++] = (unsigned short)len; - } - } - - /* handle error breaks in while */ - if (state->mode == BAD) break; - - /* check for end-of-block code (better have one) */ - if (state->lens[256] == 0) { - strm->msg = (char *)"invalid code -- missing end-of-block"; - state->mode = BAD; - break; - } - - /* build code tables -- note: do not change the lenbits or distbits - values here (9 and 6) without reading the comments in inftrees.h - concerning the ENOUGH constants, which depend on those values */ - state->next = state->codes; - state->lencode = (const code FAR *)(state->next); - state->lenbits = 9; - ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), - &(state->lenbits), state->work); - if (ret) { - strm->msg = (char *)"invalid literal/lengths set"; - state->mode = BAD; - break; - } - state->distcode = (const code FAR *)(state->next); - state->distbits = 6; - ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist, - &(state->next), &(state->distbits), state->work); - if (ret) { - strm->msg = (char *)"invalid distances set"; - state->mode = BAD; - break; - } - Tracev((stderr, "inflate: codes ok\n")); - state->mode = LEN_; - if (flush == Z_TREES) goto inf_leave; - case LEN_: - state->mode = LEN; - case LEN: - if (have >= 6 && left >= 258) { - RESTORE(); - inflate_fast(strm, out); - LOAD(); - if (state->mode == TYPE) - state->back = -1; - break; - } - state->back = 0; - for (;;) { - here = state->lencode[BITS(state->lenbits)]; - if ((unsigned)(here.bits) <= bits) break; - PULLBYTE(); - } - if (here.op && (here.op & 0xf0) == 0) { - last = here; - for (;;) { - here = state->lencode[last.val + - (BITS(last.bits + last.op) >> last.bits)]; - if ((unsigned)(last.bits + here.bits) <= bits) break; - PULLBYTE(); - } - DROPBITS(last.bits); - state->back += last.bits; - } - DROPBITS(here.bits); - state->back += here.bits; - state->length = (unsigned)here.val; - if ((int)(here.op) == 0) { - Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? - "inflate: literal '%c'\n" : - "inflate: literal 0x%02x\n", here.val)); - state->mode = LIT; - break; - } - if (here.op & 32) { - Tracevv((stderr, "inflate: end of block\n")); - state->back = -1; - state->mode = TYPE; - break; - } - if (here.op & 64) { - strm->msg = (char *)"invalid literal/length code"; - state->mode = BAD; - break; - } - state->extra = (unsigned)(here.op) & 15; - state->mode = LENEXT; - case LENEXT: - if (state->extra) { - NEEDBITS(state->extra); - state->length += BITS(state->extra); - DROPBITS(state->extra); - state->back += state->extra; - } - Tracevv((stderr, "inflate: length %u\n", state->length)); - state->was = state->length; - state->mode = DIST; - case DIST: - for (;;) { - here = state->distcode[BITS(state->distbits)]; - if ((unsigned)(here.bits) <= bits) break; - PULLBYTE(); - } - if ((here.op & 0xf0) == 0) { - last = here; - for (;;) { - here = state->distcode[last.val + - (BITS(last.bits + last.op) >> last.bits)]; - if ((unsigned)(last.bits + here.bits) <= bits) break; - PULLBYTE(); - } - DROPBITS(last.bits); - state->back += last.bits; - } - DROPBITS(here.bits); - state->back += here.bits; - if (here.op & 64) { - strm->msg = (char *)"invalid distance code"; - state->mode = BAD; - break; - } - state->offset = (unsigned)here.val; - state->extra = (unsigned)(here.op) & 15; - state->mode = DISTEXT; - case DISTEXT: - if (state->extra) { - NEEDBITS(state->extra); - state->offset += BITS(state->extra); - DROPBITS(state->extra); - state->back += state->extra; - } -#ifdef INFLATE_STRICT - if (state->offset > state->dmax) { - strm->msg = (char *)"invalid distance too far back"; - state->mode = BAD; - break; - } -#endif - Tracevv((stderr, "inflate: distance %u\n", state->offset)); - state->mode = MATCH; - case MATCH: - if (left == 0) goto inf_leave; - copy = out - left; - if (state->offset > copy) { /* copy from window */ - copy = state->offset - copy; - if (copy > state->whave) { - if (state->sane) { - strm->msg = (char *)"invalid distance too far back"; - state->mode = BAD; - break; - } -#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR - Trace((stderr, "inflate.c too far\n")); - copy -= state->whave; - if (copy > state->length) copy = state->length; - if (copy > left) copy = left; - left -= copy; - state->length -= copy; - do { - *put++ = 0; - } while (--copy); - if (state->length == 0) state->mode = LEN; - break; -#endif - } - if (copy > state->wnext) { - copy -= state->wnext; - from = state->window + (state->wsize - copy); - } - else - from = state->window + (state->wnext - copy); - if (copy > state->length) copy = state->length; - } - else { /* copy from output */ - from = put - state->offset; - copy = state->length; - } - if (copy > left) copy = left; - left -= copy; - state->length -= copy; - do { - *put++ = *from++; - } while (--copy); - if (state->length == 0) state->mode = LEN; - break; - case LIT: - if (left == 0) goto inf_leave; - *put++ = (unsigned char)(state->length); - left--; - state->mode = LEN; - break; - case CHECK: - if (state->wrap) { - NEEDBITS(32); - out -= left; - strm->total_out += out; - state->total += out; - if (out) - strm->adler = state->check = - UPDATE(state->check, put - out, out); - out = left; - if (( -#ifdef GUNZIP - state->flags ? hold : -#endif - ZSWAP32(hold)) != state->check) { - strm->msg = (char *)"incorrect data check"; - state->mode = BAD; - break; - } - INITBITS(); - Tracev((stderr, "inflate: check matches trailer\n")); - } -#ifdef GUNZIP - state->mode = LENGTH; - case LENGTH: - if (state->wrap && state->flags) { - NEEDBITS(32); - if (hold != (state->total & 0xffffffffUL)) { - strm->msg = (char *)"incorrect length check"; - state->mode = BAD; - break; - } - INITBITS(); - Tracev((stderr, "inflate: length matches trailer\n")); - } -#endif - state->mode = DONE; - case DONE: - ret = Z_STREAM_END; - goto inf_leave; - case BAD: - ret = Z_DATA_ERROR; - goto inf_leave; - case MEM: - return Z_MEM_ERROR; - case SYNC: - default: - return Z_STREAM_ERROR; - } - - /* - Return from inflate(), updating the total counts and the check value. - If there was no progress during the inflate() call, return a buffer - error. Call updatewindow() to create and/or update the window state. - Note: a memory error from inflate() is non-recoverable. - */ - inf_leave: - RESTORE(); - if (state->wsize || (out != strm->avail_out && state->mode < BAD && - (state->mode < CHECK || flush != Z_FINISH))) - if (updatewindow(strm, strm->next_out, out - strm->avail_out)) { - state->mode = MEM; - return Z_MEM_ERROR; - } - in -= strm->avail_in; - out -= strm->avail_out; - strm->total_in += in; - strm->total_out += out; - state->total += out; - if (state->wrap && out) - strm->adler = state->check = - UPDATE(state->check, strm->next_out - out, out); - strm->data_type = state->bits + (state->last ? 64 : 0) + - (state->mode == TYPE ? 128 : 0) + - (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0); - if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK) - ret = Z_BUF_ERROR; - return ret; -} - -int ZEXPORT inflateEnd(strm) -z_streamp strm; -{ - struct inflate_state FAR *state; - if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) - return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - if (state->window != Z_NULL) ZFREE(strm, state->window); - ZFREE(strm, strm->state); - strm->state = Z_NULL; - Tracev((stderr, "inflate: end\n")); - return Z_OK; -} - -int ZEXPORT inflateGetDictionary(strm, dictionary, dictLength) -z_streamp strm; -Bytef *dictionary; -uInt *dictLength; -{ - struct inflate_state FAR *state; - - /* check state */ - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - - /* copy dictionary */ - if (state->whave && dictionary != Z_NULL) { - zmemcpy(dictionary, state->window + state->wnext, - state->whave - state->wnext); - zmemcpy(dictionary + state->whave - state->wnext, - state->window, state->wnext); - } - if (dictLength != Z_NULL) - *dictLength = state->whave; - return Z_OK; -} - -int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength) -z_streamp strm; -const Bytef *dictionary; -uInt dictLength; -{ - struct inflate_state FAR *state; - unsigned long dictid; - int ret; - - /* check state */ - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - if (state->wrap != 0 && state->mode != DICT) - return Z_STREAM_ERROR; - - /* check for correct dictionary identifier */ - if (state->mode == DICT) { - dictid = adler32(0L, Z_NULL, 0); - dictid = adler32(dictid, dictionary, dictLength); - if (dictid != state->check) - return Z_DATA_ERROR; - } - - /* copy dictionary to window using updatewindow(), which will amend the - existing dictionary if appropriate */ - ret = updatewindow(strm, dictionary + dictLength, dictLength); - if (ret) { - state->mode = MEM; - return Z_MEM_ERROR; - } - state->havedict = 1; - Tracev((stderr, "inflate: dictionary set\n")); - return Z_OK; -} - -int ZEXPORT inflateGetHeader(strm, head) -z_streamp strm; -gz_headerp head; -{ - struct inflate_state FAR *state; - - /* check state */ - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - if ((state->wrap & 2) == 0) return Z_STREAM_ERROR; - - /* save header structure */ - state->head = head; - head->done = 0; - return Z_OK; -} - -/* - Search buf[0..len-1] for the pattern: 0, 0, 0xff, 0xff. Return when found - or when out of input. When called, *have is the number of pattern bytes - found in order so far, in 0..3. On return *have is updated to the new - state. If on return *have equals four, then the pattern was found and the - return value is how many bytes were read including the last byte of the - pattern. If *have is less than four, then the pattern has not been found - yet and the return value is len. In the latter case, syncsearch() can be - called again with more data and the *have state. *have is initialized to - zero for the first call. - */ -local unsigned syncsearch(have, buf, len) -unsigned FAR *have; -const unsigned char FAR *buf; -unsigned len; -{ - unsigned got; - unsigned next; - - got = *have; - next = 0; - while (next < len && got < 4) { - if ((int)(buf[next]) == (got < 2 ? 0 : 0xff)) - got++; - else if (buf[next]) - got = 0; - else - got = 4 - got; - next++; - } - *have = got; - return next; -} - -int ZEXPORT inflateSync(strm) -z_streamp strm; -{ - unsigned len; /* number of bytes to look at or looked at */ - unsigned long in, out; /* temporary to save total_in and total_out */ - unsigned char buf[4]; /* to restore bit buffer to byte string */ - struct inflate_state FAR *state; - - /* check parameters */ - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR; - - /* if first time, start search in bit buffer */ - if (state->mode != SYNC) { - state->mode = SYNC; - state->hold <<= state->bits & 7; - state->bits -= state->bits & 7; - len = 0; - while (state->bits >= 8) { - buf[len++] = (unsigned char)(state->hold); - state->hold >>= 8; - state->bits -= 8; - } - state->have = 0; - syncsearch(&(state->have), buf, len); - } - - /* search available input */ - len = syncsearch(&(state->have), strm->next_in, strm->avail_in); - strm->avail_in -= len; - strm->next_in += len; - strm->total_in += len; - - /* return no joy or set up to restart inflate() on a new block */ - if (state->have != 4) return Z_DATA_ERROR; - in = strm->total_in; out = strm->total_out; - inflateReset(strm); - strm->total_in = in; strm->total_out = out; - state->mode = TYPE; - return Z_OK; -} - -/* - Returns true if inflate is currently at the end of a block generated by - Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP - implementation to provide an additional safety check. PPP uses - Z_SYNC_FLUSH but removes the length bytes of the resulting empty stored - block. When decompressing, PPP checks that at the end of input packet, - inflate is waiting for these length bytes. - */ -int ZEXPORT inflateSyncPoint(strm) -z_streamp strm; -{ - struct inflate_state FAR *state; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - return state->mode == STORED && state->bits == 0; -} - -int ZEXPORT inflateCopy(dest, source) -z_streamp dest; -z_streamp source; -{ - struct inflate_state FAR *state; - struct inflate_state FAR *copy; - unsigned char FAR *window; - unsigned wsize; - - /* check input */ - if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL || - source->zalloc == (alloc_func)0 || source->zfree == (free_func)0) - return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)source->state; - - /* allocate space */ - copy = (struct inflate_state FAR *) - ZALLOC(source, 1, sizeof(struct inflate_state)); - if (copy == Z_NULL) return Z_MEM_ERROR; - window = Z_NULL; - if (state->window != Z_NULL) { - window = (unsigned char FAR *) - ZALLOC(source, 1U << state->wbits, sizeof(unsigned char)); - if (window == Z_NULL) { - ZFREE(source, copy); - return Z_MEM_ERROR; - } - } - - /* copy state */ - zmemcpy((voidpf)dest, (voidpf)source, sizeof(z_stream)); - zmemcpy((voidpf)copy, (voidpf)state, sizeof(struct inflate_state)); - if (state->lencode >= state->codes && - state->lencode <= state->codes + ENOUGH - 1) { - copy->lencode = copy->codes + (state->lencode - state->codes); - copy->distcode = copy->codes + (state->distcode - state->codes); - } - copy->next = copy->codes + (state->next - state->codes); - if (window != Z_NULL) { - wsize = 1U << state->wbits; - zmemcpy(window, state->window, wsize); - } - copy->window = window; - dest->state = (struct internal_state FAR *)copy; - return Z_OK; -} - -int ZEXPORT inflateUndermine(strm, subvert) -z_streamp strm; -int subvert; -{ - struct inflate_state FAR *state; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - state->sane = !subvert; -#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR - return Z_OK; -#else - state->sane = 1; - return Z_DATA_ERROR; -#endif -} - -long ZEXPORT inflateMark(strm) -z_streamp strm; -{ - struct inflate_state FAR *state; - - if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16; - state = (struct inflate_state FAR *)strm->state; - return ((long)(state->back) << 16) + - (state->mode == COPY ? state->length : - (state->mode == MATCH ? state->was - state->length : 0)); -} diff --git a/src/beast/test/zlib/zlib-1.2.8/inflate.h b/src/beast/test/zlib/zlib-1.2.8/inflate.h deleted file mode 100644 index 95f4986d400..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/inflate.h +++ /dev/null @@ -1,122 +0,0 @@ -/* inflate.h -- internal inflate state definition - * Copyright (C) 1995-2009 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -/* define NO_GZIP when compiling if you want to disable gzip header and - trailer decoding by inflate(). NO_GZIP would be used to avoid linking in - the crc code when it is not needed. For shared libraries, gzip decoding - should be left enabled. */ -#ifndef NO_GZIP -# define GUNZIP -#endif - -/* Possible inflate modes between inflate() calls */ -typedef enum { - HEAD, /* i: waiting for magic header */ - FLAGS, /* i: waiting for method and flags (gzip) */ - TIME, /* i: waiting for modification time (gzip) */ - OS, /* i: waiting for extra flags and operating system (gzip) */ - EXLEN, /* i: waiting for extra length (gzip) */ - EXTRA, /* i: waiting for extra bytes (gzip) */ - NAME, /* i: waiting for end of file name (gzip) */ - COMMENT, /* i: waiting for end of comment (gzip) */ - HCRC, /* i: waiting for header crc (gzip) */ - DICTID, /* i: waiting for dictionary check value */ - DICT, /* waiting for inflateSetDictionary() call */ - TYPE, /* i: waiting for type bits, including last-flag bit */ - TYPEDO, /* i: same, but skip check to exit inflate on new block */ - STORED, /* i: waiting for stored size (length and complement) */ - COPY_, /* i/o: same as COPY below, but only first time in */ - COPY, /* i/o: waiting for input or output to copy stored block */ - TABLE, /* i: waiting for dynamic block table lengths */ - LENLENS, /* i: waiting for code length code lengths */ - CODELENS, /* i: waiting for length/lit and distance code lengths */ - LEN_, /* i: same as LEN below, but only first time in */ - LEN, /* i: waiting for length/lit/eob code */ - LENEXT, /* i: waiting for length extra bits */ - DIST, /* i: waiting for distance code */ - DISTEXT, /* i: waiting for distance extra bits */ - MATCH, /* o: waiting for output space to copy string */ - LIT, /* o: waiting for output space to write literal */ - CHECK, /* i: waiting for 32-bit check value */ - LENGTH, /* i: waiting for 32-bit length (gzip) */ - DONE, /* finished check, done -- remain here until reset */ - BAD, /* got a data error -- remain here until reset */ - MEM, /* got an inflate() memory error -- remain here until reset */ - SYNC /* looking for synchronization bytes to restart inflate() */ -} inflate_mode; - -/* - State transitions between above modes - - - (most modes can go to BAD or MEM on error -- not shown for clarity) - - Process header: - HEAD -> (gzip) or (zlib) or (raw) - (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT -> - HCRC -> TYPE - (zlib) -> DICTID or TYPE - DICTID -> DICT -> TYPE - (raw) -> TYPEDO - Read deflate blocks: - TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK - STORED -> COPY_ -> COPY -> TYPE - TABLE -> LENLENS -> CODELENS -> LEN_ - LEN_ -> LEN - Read deflate codes in fixed or dynamic block: - LEN -> LENEXT or LIT or TYPE - LENEXT -> DIST -> DISTEXT -> MATCH -> LEN - LIT -> LEN - Process trailer: - CHECK -> LENGTH -> DONE - */ - -/* state maintained between inflate() calls. Approximately 10K bytes. */ -struct inflate_state { - inflate_mode mode; /* current inflate mode */ - int last; /* true if processing last block */ - int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ - int havedict; /* true if dictionary provided */ - int flags; /* gzip header method and flags (0 if zlib) */ - unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ - unsigned long check; /* protected copy of check value */ - unsigned long total; /* protected copy of output count */ - gz_headerp head; /* where to save gzip header information */ - /* sliding window */ - unsigned wbits; /* log base 2 of requested window size */ - unsigned wsize; /* window size or zero if not using window */ - unsigned whave; /* valid bytes in the window */ - unsigned wnext; /* window write index */ - unsigned char FAR *window; /* allocated sliding window, if needed */ - /* bit accumulator */ - unsigned long hold; /* input bit accumulator */ - unsigned bits; /* number of bits in "in" */ - /* for string and stored block copying */ - unsigned length; /* literal or length of data to copy */ - unsigned offset; /* distance back to copy string from */ - /* for table and code decoding */ - unsigned extra; /* extra bits needed */ - /* fixed and dynamic code tables */ - code const FAR *lencode; /* starting table for length/literal codes */ - code const FAR *distcode; /* starting table for distance codes */ - unsigned lenbits; /* index bits for lencode */ - unsigned distbits; /* index bits for distcode */ - /* dynamic table building */ - unsigned ncode; /* number of code length code lengths */ - unsigned nlen; /* number of length code lengths */ - unsigned ndist; /* number of distance code lengths */ - unsigned have; /* number of code lengths in lens[] */ - code FAR *next; /* next available space in codes[] */ - unsigned short lens[320]; /* temporary storage for code lengths */ - unsigned short work[288]; /* work area for code table building */ - code codes[ENOUGH]; /* space for code tables */ - int sane; /* if false, allow invalid distance too far */ - int back; /* bits back of last unprocessed length/lit */ - unsigned was; /* initial length of match */ -}; diff --git a/src/beast/test/zlib/zlib-1.2.8/inftrees.c b/src/beast/test/zlib/zlib-1.2.8/inftrees.c deleted file mode 100644 index 44d89cf24e1..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/inftrees.c +++ /dev/null @@ -1,306 +0,0 @@ -/* inftrees.c -- generate Huffman trees for efficient decoding - * Copyright (C) 1995-2013 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#include "zutil.h" -#include "inftrees.h" - -#define MAXBITS 15 - -const char inflate_copyright[] = - " inflate 1.2.8 Copyright 1995-2013 Mark Adler "; -/* - If you use the zlib library in a product, an acknowledgment is welcome - in the documentation of your product. If for some reason you cannot - include such an acknowledgment, I would appreciate that you keep this - copyright string in the executable of your product. - */ - -/* - Build a set of tables to decode the provided canonical Huffman code. - The code lengths are lens[0..codes-1]. The result starts at *table, - whose indices are 0..2^bits-1. work is a writable array of at least - lens shorts, which is used as a work area. type is the type of code - to be generated, CODES, LENS, or DISTS. On return, zero is success, - -1 is an invalid code, and +1 means that ENOUGH isn't enough. table - on return points to the next available entry's address. bits is the - requested root table index bits, and on return it is the actual root - table index bits. It will differ if the request is greater than the - longest code or if it is less than the shortest code. - */ -int ZLIB_INTERNAL inflate_table(type, lens, codes, table, bits, work) -codetype type; -unsigned short FAR *lens; -unsigned codes; -code FAR * FAR *table; -unsigned FAR *bits; -unsigned short FAR *work; -{ - unsigned len; /* a code's length in bits */ - unsigned sym; /* index of code symbols */ - unsigned min, max; /* minimum and maximum code lengths */ - unsigned root; /* number of index bits for root table */ - unsigned curr; /* number of index bits for current table */ - unsigned drop; /* code bits to drop for sub-table */ - int left; /* number of prefix codes available */ - unsigned used; /* code entries in table used */ - unsigned huff; /* Huffman code */ - unsigned incr; /* for incrementing code, index */ - unsigned fill; /* index for replicating entries */ - unsigned low; /* low bits for current root entry */ - unsigned mask; /* mask for low root bits */ - code here; /* table entry for duplication */ - code FAR *next; /* next available space in table */ - const unsigned short FAR *base; /* base value table to use */ - const unsigned short FAR *extra; /* extra bits table to use */ - int end; /* use base and extra for symbol > end */ - unsigned short count[MAXBITS+1]; /* number of codes of each length */ - unsigned short offs[MAXBITS+1]; /* offsets in table for each length */ - static const unsigned short lbase[31] = { /* Length codes 257..285 base */ - 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, - 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; - static const unsigned short lext[31] = { /* Length codes 257..285 extra */ - 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, - 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78}; - static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ - 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, - 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, - 8193, 12289, 16385, 24577, 0, 0}; - static const unsigned short dext[32] = { /* Distance codes 0..29 extra */ - 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, - 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, - 28, 28, 29, 29, 64, 64}; - - /* - Process a set of code lengths to create a canonical Huffman code. The - code lengths are lens[0..codes-1]. Each length corresponds to the - symbols 0..codes-1. The Huffman code is generated by first sorting the - symbols by length from short to long, and retaining the symbol order - for codes with equal lengths. Then the code starts with all zero bits - for the first code of the shortest length, and the codes are integer - increments for the same length, and zeros are appended as the length - increases. For the deflate format, these bits are stored backwards - from their more natural integer increment ordering, and so when the - decoding tables are built in the large loop below, the integer codes - are incremented backwards. - - This routine assumes, but does not check, that all of the entries in - lens[] are in the range 0..MAXBITS. The caller must assure this. - 1..MAXBITS is interpreted as that code length. zero means that that - symbol does not occur in this code. - - The codes are sorted by computing a count of codes for each length, - creating from that a table of starting indices for each length in the - sorted table, and then entering the symbols in order in the sorted - table. The sorted table is work[], with that space being provided by - the caller. - - The length counts are used for other purposes as well, i.e. finding - the minimum and maximum length codes, determining if there are any - codes at all, checking for a valid set of lengths, and looking ahead - at length counts to determine sub-table sizes when building the - decoding tables. - */ - - /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */ - for (len = 0; len <= MAXBITS; len++) - count[len] = 0; - for (sym = 0; sym < codes; sym++) - count[lens[sym]]++; - - /* bound code lengths, force root to be within code lengths */ - root = *bits; - for (max = MAXBITS; max >= 1; max--) - if (count[max] != 0) break; - if (root > max) root = max; - if (max == 0) { /* no symbols to code at all */ - here.op = (unsigned char)64; /* invalid code marker */ - here.bits = (unsigned char)1; - here.val = (unsigned short)0; - *(*table)++ = here; /* make a table to force an error */ - *(*table)++ = here; - *bits = 1; - return 0; /* no symbols, but wait for decoding to report error */ - } - for (min = 1; min < max; min++) - if (count[min] != 0) break; - if (root < min) root = min; - - /* check for an over-subscribed or incomplete set of lengths */ - left = 1; - for (len = 1; len <= MAXBITS; len++) { - left <<= 1; - left -= count[len]; - if (left < 0) return -1; /* over-subscribed */ - } - if (left > 0 && (type == CODES || max != 1)) - return -1; /* incomplete set */ - - /* generate offsets into symbol table for each length for sorting */ - offs[1] = 0; - for (len = 1; len < MAXBITS; len++) - offs[len + 1] = offs[len] + count[len]; - - /* sort symbols by length, by symbol order within each length */ - for (sym = 0; sym < codes; sym++) - if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym; - - /* - Create and fill in decoding tables. In this loop, the table being - filled is at next and has curr index bits. The code being used is huff - with length len. That code is converted to an index by dropping drop - bits off of the bottom. For codes where len is less than drop + curr, - those top drop + curr - len bits are incremented through all values to - fill the table with replicated entries. - - root is the number of index bits for the root table. When len exceeds - root, sub-tables are created pointed to by the root entry with an index - of the low root bits of huff. This is saved in low to check for when a - new sub-table should be started. drop is zero when the root table is - being filled, and drop is root when sub-tables are being filled. - - When a new sub-table is needed, it is necessary to look ahead in the - code lengths to determine what size sub-table is needed. The length - counts are used for this, and so count[] is decremented as codes are - entered in the tables. - - used keeps track of how many table entries have been allocated from the - provided *table space. It is checked for LENS and DIST tables against - the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in - the initial root table size constants. See the comments in inftrees.h - for more information. - - sym increments through all symbols, and the loop terminates when - all codes of length max, i.e. all codes, have been processed. This - routine permits incomplete codes, so another loop after this one fills - in the rest of the decoding tables with invalid code markers. - */ - - /* set up for code type */ - switch (type) { - case CODES: - base = extra = work; /* dummy value--not used */ - end = 19; - break; - case LENS: - base = lbase; - base -= 257; - extra = lext; - extra -= 257; - end = 256; - break; - default: /* DISTS */ - base = dbase; - extra = dext; - end = -1; - } - - /* initialize state for loop */ - huff = 0; /* starting code */ - sym = 0; /* starting code symbol */ - len = min; /* starting code length */ - next = *table; /* current table to fill in */ - curr = root; /* current table index bits */ - drop = 0; /* current bits to drop from code for index */ - low = (unsigned)(-1); /* trigger new sub-table when len > root */ - used = 1U << root; /* use root table entries */ - mask = used - 1; /* mask for comparing low */ - - /* check available table space */ - if ((type == LENS && used > ENOUGH_LENS) || - (type == DISTS && used > ENOUGH_DISTS)) - return 1; - - /* process all codes and make table entries */ - for (;;) { - /* create table entry */ - here.bits = (unsigned char)(len - drop); - if ((int)(work[sym]) < end) { - here.op = (unsigned char)0; - here.val = work[sym]; - } - else if ((int)(work[sym]) > end) { - here.op = (unsigned char)(extra[work[sym]]); - here.val = base[work[sym]]; - } - else { - here.op = (unsigned char)(32 + 64); /* end of block */ - here.val = 0; - } - - /* replicate for those indices with low len bits equal to huff */ - incr = 1U << (len - drop); - fill = 1U << curr; - min = fill; /* save offset to next table */ - do { - fill -= incr; - next[(huff >> drop) + fill] = here; - } while (fill != 0); - - /* backwards increment the len-bit code huff */ - incr = 1U << (len - 1); - while (huff & incr) - incr >>= 1; - if (incr != 0) { - huff &= incr - 1; - huff += incr; - } - else - huff = 0; - - /* go to next symbol, update count, len */ - sym++; - if (--(count[len]) == 0) { - if (len == max) break; - len = lens[work[sym]]; - } - - /* create new sub-table if needed */ - if (len > root && (huff & mask) != low) { - /* if first time, transition to sub-tables */ - if (drop == 0) - drop = root; - - /* increment past last table */ - next += min; /* here min is 1 << curr */ - - /* determine length of next table */ - curr = len - drop; - left = (int)(1 << curr); - while (curr + drop < max) { - left -= count[curr + drop]; - if (left <= 0) break; - curr++; - left <<= 1; - } - - /* check for enough space */ - used += 1U << curr; - if ((type == LENS && used > ENOUGH_LENS) || - (type == DISTS && used > ENOUGH_DISTS)) - return 1; - - /* point entry in root table to sub-table */ - low = huff & mask; - (*table)[low].op = (unsigned char)curr; - (*table)[low].bits = (unsigned char)root; - (*table)[low].val = (unsigned short)(next - *table); - } - } - - /* fill in remaining table entry if code is incomplete (guaranteed to have - at most one remaining entry, since if the code is incomplete, the - maximum code length that was allowed to get this far is one bit) */ - if (huff != 0) { - here.op = (unsigned char)64; /* invalid code marker */ - here.bits = (unsigned char)(len - drop); - here.val = (unsigned short)0; - next[huff] = here; - } - - /* set return parameters */ - *table += used; - *bits = root; - return 0; -} diff --git a/src/beast/test/zlib/zlib-1.2.8/inftrees.h b/src/beast/test/zlib/zlib-1.2.8/inftrees.h deleted file mode 100644 index baa53a0b1a1..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/inftrees.h +++ /dev/null @@ -1,62 +0,0 @@ -/* inftrees.h -- header to use inftrees.c - * Copyright (C) 1995-2005, 2010 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -/* Structure for decoding tables. Each entry provides either the - information needed to do the operation requested by the code that - indexed that table entry, or it provides a pointer to another - table that indexes more bits of the code. op indicates whether - the entry is a pointer to another table, a literal, a length or - distance, an end-of-block, or an invalid code. For a table - pointer, the low four bits of op is the number of index bits of - that table. For a length or distance, the low four bits of op - is the number of extra bits to get after the code. bits is - the number of bits in this code or part of the code to drop off - of the bit buffer. val is the actual byte to output in the case - of a literal, the base length or distance, or the offset from - the current table to the next table. Each entry is four bytes. */ -typedef struct { - unsigned char op; /* operation, extra bits, table bits */ - unsigned char bits; /* bits in this part of the code */ - unsigned short val; /* offset in table or code value */ -} code; - -/* op values as set by inflate_table(): - 00000000 - literal - 0000tttt - table link, tttt != 0 is the number of table index bits - 0001eeee - length or distance, eeee is the number of extra bits - 01100000 - end of block - 01000000 - invalid code - */ - -/* Maximum size of the dynamic table. The maximum number of code structures is - 1444, which is the sum of 852 for literal/length codes and 592 for distance - codes. These values were found by exhaustive searches using the program - examples/enough.c found in the zlib distribtution. The arguments to that - program are the number of symbols, the initial root table size, and the - maximum bit length of a code. "enough 286 9 15" for literal/length codes - returns returns 852, and "enough 30 6 15" for distance codes returns 592. - The initial root table size (9 or 6) is found in the fifth argument of the - inflate_table() calls in inflate.c and infback.c. If the root table size is - changed, then these maximum sizes would be need to be recalculated and - updated. */ -#define ENOUGH_LENS 852 -#define ENOUGH_DISTS 592 -#define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS) - -/* Type of code to build for inflate_table() */ -typedef enum { - CODES, - LENS, - DISTS -} codetype; - -int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens, - unsigned codes, code FAR * FAR *table, - unsigned FAR *bits, unsigned short FAR *work)); diff --git a/src/beast/test/zlib/zlib-1.2.8/make_vms.com b/src/beast/test/zlib/zlib-1.2.8/make_vms.com deleted file mode 100644 index 65e9d0cbc8e..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/make_vms.com +++ /dev/null @@ -1,867 +0,0 @@ -$! make libz under VMS written by -$! Martin P.J. Zinser -$! -$! In case of problems with the install you might contact me at -$! zinser@zinser.no-ip.info(preferred) or -$! martin.zinser@eurexchange.com (work) -$! -$! Make procedure history for Zlib -$! -$!------------------------------------------------------------------------------ -$! Version history -$! 0.01 20060120 First version to receive a number -$! 0.02 20061008 Adapt to new Makefile.in -$! 0.03 20091224 Add support for large file check -$! 0.04 20100110 Add new gzclose, gzlib, gzread, gzwrite -$! 0.05 20100221 Exchange zlibdefs.h by zconf.h.in -$! 0.06 20120111 Fix missing amiss_err, update zconf_h.in, fix new exmples -$! subdir path, update module search in makefile.in -$! 0.07 20120115 Triggered by work done by Alexey Chupahin completly redesigned -$! shared image creation -$! 0.08 20120219 Make it work on VAX again, pre-load missing symbols to shared -$! image -$! 0.09 20120305 SMS. P1 sets builder ("MMK", "MMS", " " (built-in)). -$! "" -> automatic, preference: MMK, MMS, built-in. -$! -$ on error then goto err_exit -$! -$ true = 1 -$ false = 0 -$ tmpnam = "temp_" + f$getjpi("","pid") -$ tt = tmpnam + ".txt" -$ tc = tmpnam + ".c" -$ th = tmpnam + ".h" -$ define/nolog tconfig 'th' -$ its_decc = false -$ its_vaxc = false -$ its_gnuc = false -$ s_case = False -$! -$! Setup variables holding "config" information -$! -$ Make = "''p1'" -$ name = "Zlib" -$ version = "?.?.?" -$ v_string = "ZLIB_VERSION" -$ v_file = "zlib.h" -$ ccopt = "/include = []" -$ lopts = "" -$ dnsrl = "" -$ aconf_in_file = "zconf.h.in#zconf.h_in#zconf_h.in" -$ conf_check_string = "" -$ linkonly = false -$ optfile = name + ".opt" -$ mapfile = name + ".map" -$ libdefs = "" -$ vax = f$getsyi("HW_MODEL").lt.1024 -$ axp = f$getsyi("HW_MODEL").ge.1024 .and. f$getsyi("HW_MODEL").lt.4096 -$ ia64 = f$getsyi("HW_MODEL").ge.4096 -$! -$! 2012-03-05 SMS. -$! Why is this needed? And if it is needed, why not simply ".not. vax"? -$! -$!!! if axp .or. ia64 then set proc/parse=extended -$! -$ whoami = f$parse(f$environment("Procedure"),,,,"NO_CONCEAL") -$ mydef = F$parse(whoami,,,"DEVICE") -$ mydir = f$parse(whoami,,,"DIRECTORY") - "][" -$ myproc = f$parse(whoami,,,"Name") + f$parse(whoami,,,"type") -$! -$! Check for MMK/MMS -$! -$ if (Make .eqs. "") -$ then -$ If F$Search ("Sys$System:MMS.EXE") .nes. "" Then Make = "MMS" -$ If F$Type (MMK) .eqs. "STRING" Then Make = "MMK" -$ else -$ Make = f$edit( Make, "trim") -$ endif -$! -$ gosub find_version -$! -$ open/write topt tmp.opt -$ open/write optf 'optfile' -$! -$ gosub check_opts -$! -$! Look for the compiler used -$! -$ gosub check_compiler -$ close topt -$ close optf -$! -$ if its_decc -$ then -$ ccopt = "/prefix=all" + ccopt -$ if f$trnlnm("SYS") .eqs. "" -$ then -$ if axp -$ then -$ define sys sys$library: -$ else -$ ccopt = "/decc" + ccopt -$ define sys decc$library_include: -$ endif -$ endif -$! -$! 2012-03-05 SMS. -$! Why /NAMES = AS_IS? Why not simply ".not. vax"? And why not on VAX? -$! -$ if axp .or. ia64 -$ then -$ ccopt = ccopt + "/name=as_is/opt=(inline=speed)" -$ s_case = true -$ endif -$ endif -$ if its_vaxc .or. its_gnuc -$ then -$ if f$trnlnm("SYS").eqs."" then define sys sys$library: -$ endif -$! -$! Build a fake configure input header -$! -$ open/write conf_hin config.hin -$ write conf_hin "#undef _LARGEFILE64_SOURCE" -$ close conf_hin -$! -$! -$ i = 0 -$FIND_ACONF: -$ fname = f$element(i,"#",aconf_in_file) -$ if fname .eqs. "#" then goto AMISS_ERR -$ if f$search(fname) .eqs. "" -$ then -$ i = i + 1 -$ goto find_aconf -$ endif -$ open/read/err=aconf_err aconf_in 'fname' -$ open/write aconf zconf.h -$ACONF_LOOP: -$ read/end_of_file=aconf_exit aconf_in line -$ work = f$edit(line, "compress,trim") -$ if f$extract(0,6,work) .nes. "#undef" -$ then -$ if f$extract(0,12,work) .nes. "#cmakedefine" -$ then -$ write aconf line -$ endif -$ else -$ cdef = f$element(1," ",work) -$ gosub check_config -$ endif -$ goto aconf_loop -$ACONF_EXIT: -$ write aconf "" -$ write aconf "/* VMS specifics added by make_vms.com: */" -$ write aconf "#define VMS 1" -$ write aconf "#include " -$ write aconf "#include " -$ write aconf "#ifdef _LARGEFILE" -$ write aconf "# define off64_t __off64_t" -$ write aconf "# define fopen64 fopen" -$ write aconf "# define fseeko64 fseeko" -$ write aconf "# define lseek64 lseek" -$ write aconf "# define ftello64 ftell" -$ write aconf "#endif" -$ write aconf "#if !defined( __VAX) && (__CRTL_VER >= 70312000)" -$ write aconf "# define HAVE_VSNPRINTF" -$ write aconf "#endif" -$ close aconf_in -$ close aconf -$ if f$search("''th'") .nes. "" then delete 'th';* -$! Build the thing plain or with mms -$! -$ write sys$output "Compiling Zlib sources ..." -$ if make.eqs."" -$ then -$ if (f$search( "example.obj;*") .nes. "") then delete example.obj;* -$ if (f$search( "minigzip.obj;*") .nes. "") then delete minigzip.obj;* -$ CALL MAKE adler32.OBJ "CC ''CCOPT' adler32" - - adler32.c zlib.h zconf.h -$ CALL MAKE compress.OBJ "CC ''CCOPT' compress" - - compress.c zlib.h zconf.h -$ CALL MAKE crc32.OBJ "CC ''CCOPT' crc32" - - crc32.c zlib.h zconf.h -$ CALL MAKE deflate.OBJ "CC ''CCOPT' deflate" - - deflate.c deflate.h zutil.h zlib.h zconf.h -$ CALL MAKE gzclose.OBJ "CC ''CCOPT' gzclose" - - gzclose.c zutil.h zlib.h zconf.h -$ CALL MAKE gzlib.OBJ "CC ''CCOPT' gzlib" - - gzlib.c zutil.h zlib.h zconf.h -$ CALL MAKE gzread.OBJ "CC ''CCOPT' gzread" - - gzread.c zutil.h zlib.h zconf.h -$ CALL MAKE gzwrite.OBJ "CC ''CCOPT' gzwrite" - - gzwrite.c zutil.h zlib.h zconf.h -$ CALL MAKE infback.OBJ "CC ''CCOPT' infback" - - infback.c zutil.h inftrees.h inflate.h inffast.h inffixed.h -$ CALL MAKE inffast.OBJ "CC ''CCOPT' inffast" - - inffast.c zutil.h zlib.h zconf.h inffast.h -$ CALL MAKE inflate.OBJ "CC ''CCOPT' inflate" - - inflate.c zutil.h zlib.h zconf.h infblock.h -$ CALL MAKE inftrees.OBJ "CC ''CCOPT' inftrees" - - inftrees.c zutil.h zlib.h zconf.h inftrees.h -$ CALL MAKE trees.OBJ "CC ''CCOPT' trees" - - trees.c deflate.h zutil.h zlib.h zconf.h -$ CALL MAKE uncompr.OBJ "CC ''CCOPT' uncompr" - - uncompr.c zlib.h zconf.h -$ CALL MAKE zutil.OBJ "CC ''CCOPT' zutil" - - zutil.c zutil.h zlib.h zconf.h -$ write sys$output "Building Zlib ..." -$ CALL MAKE libz.OLB "lib/crea libz.olb *.obj" *.OBJ -$ write sys$output "Building example..." -$ CALL MAKE example.OBJ "CC ''CCOPT' [.test]example" - - [.test]example.c zlib.h zconf.h -$ call make example.exe "LINK example,libz.olb/lib" example.obj libz.olb -$ write sys$output "Building minigzip..." -$ CALL MAKE minigzip.OBJ "CC ''CCOPT' [.test]minigzip" - - [.test]minigzip.c zlib.h zconf.h -$ call make minigzip.exe - - "LINK minigzip,libz.olb/lib" - - minigzip.obj libz.olb -$ else -$ gosub crea_mms -$ write sys$output "Make ''name' ''version' with ''Make' " -$ 'make' -$ endif -$! -$! Create shareable image -$! -$ gosub crea_olist -$ write sys$output "Creating libzshr.exe" -$ call map_2_shopt 'mapfile' 'optfile' -$ LINK_'lopts'/SHARE=libzshr.exe modules.opt/opt,'optfile'/opt -$ write sys$output "Zlib build completed" -$ delete/nolog tmp.opt;* -$ exit -$AMISS_ERR: -$ write sys$output "No source for config.hin found." -$ write sys$output "Tried any of ''aconf_in_file'" -$ goto err_exit -$CC_ERR: -$ write sys$output "C compiler required to build ''name'" -$ goto err_exit -$ERR_EXIT: -$ set message/facil/ident/sever/text -$ close/nolog optf -$ close/nolog topt -$ close/nolog aconf_in -$ close/nolog aconf -$ close/nolog out -$ close/nolog min -$ close/nolog mod -$ close/nolog h_in -$ write sys$output "Exiting..." -$ exit 2 -$! -$! -$MAKE: SUBROUTINE !SUBROUTINE TO CHECK DEPENDENCIES -$ V = 'F$Verify(0) -$! P1 = What we are trying to make -$! P2 = Command to make it -$! P3 - P8 What it depends on -$ -$ If F$Search(P1) .Eqs. "" Then Goto Makeit -$ Time = F$CvTime(F$File(P1,"RDT")) -$arg=3 -$Loop: -$ Argument = P'arg -$ If Argument .Eqs. "" Then Goto Exit -$ El=0 -$Loop2: -$ File = F$Element(El," ",Argument) -$ If File .Eqs. " " Then Goto Endl -$ AFile = "" -$Loop3: -$ OFile = AFile -$ AFile = F$Search(File) -$ If AFile .Eqs. "" .Or. AFile .Eqs. OFile Then Goto NextEl -$ If F$CvTime(F$File(AFile,"RDT")) .Ges. Time Then Goto Makeit -$ Goto Loop3 -$NextEL: -$ El = El + 1 -$ Goto Loop2 -$EndL: -$ arg=arg+1 -$ If arg .Le. 8 Then Goto Loop -$ Goto Exit -$ -$Makeit: -$ VV=F$VERIFY(0) -$ write sys$output P2 -$ 'P2 -$ VV='F$Verify(VV) -$Exit: -$ If V Then Set Verify -$ENDSUBROUTINE -$!------------------------------------------------------------------------------ -$! -$! Check command line options and set symbols accordingly -$! -$!------------------------------------------------------------------------------ -$! Version history -$! 0.01 20041206 First version to receive a number -$! 0.02 20060126 Add new "HELP" target -$ CHECK_OPTS: -$ i = 1 -$ OPT_LOOP: -$ if i .lt. 9 -$ then -$ cparm = f$edit(p'i',"upcase") -$! -$! Check if parameter actually contains something -$! -$ if f$edit(cparm,"trim") .nes. "" -$ then -$ if cparm .eqs. "DEBUG" -$ then -$ ccopt = ccopt + "/noopt/deb" -$ lopts = lopts + "/deb" -$ endif -$ if f$locate("CCOPT=",cparm) .lt. f$length(cparm) -$ then -$ start = f$locate("=",cparm) + 1 -$ len = f$length(cparm) - start -$ ccopt = ccopt + f$extract(start,len,cparm) -$ if f$locate("AS_IS",f$edit(ccopt,"UPCASE")) .lt. f$length(ccopt) - - then s_case = true -$ endif -$ if cparm .eqs. "LINK" then linkonly = true -$ if f$locate("LOPTS=",cparm) .lt. f$length(cparm) -$ then -$ start = f$locate("=",cparm) + 1 -$ len = f$length(cparm) - start -$ lopts = lopts + f$extract(start,len,cparm) -$ endif -$ if f$locate("CC=",cparm) .lt. f$length(cparm) -$ then -$ start = f$locate("=",cparm) + 1 -$ len = f$length(cparm) - start -$ cc_com = f$extract(start,len,cparm) - if (cc_com .nes. "DECC") .and. - - (cc_com .nes. "VAXC") .and. - - (cc_com .nes. "GNUC") -$ then -$ write sys$output "Unsupported compiler choice ''cc_com' ignored" -$ write sys$output "Use DECC, VAXC, or GNUC instead" -$ else -$ if cc_com .eqs. "DECC" then its_decc = true -$ if cc_com .eqs. "VAXC" then its_vaxc = true -$ if cc_com .eqs. "GNUC" then its_gnuc = true -$ endif -$ endif -$ if f$locate("MAKE=",cparm) .lt. f$length(cparm) -$ then -$ start = f$locate("=",cparm) + 1 -$ len = f$length(cparm) - start -$ mmks = f$extract(start,len,cparm) -$ if (mmks .eqs. "MMK") .or. (mmks .eqs. "MMS") -$ then -$ make = mmks -$ else -$ write sys$output "Unsupported make choice ''mmks' ignored" -$ write sys$output "Use MMK or MMS instead" -$ endif -$ endif -$ if cparm .eqs. "HELP" then gosub bhelp -$ endif -$ i = i + 1 -$ goto opt_loop -$ endif -$ return -$!------------------------------------------------------------------------------ -$! -$! Look for the compiler used -$! -$! Version history -$! 0.01 20040223 First version to receive a number -$! 0.02 20040229 Save/set value of decc$no_rooted_search_lists -$! 0.03 20060202 Extend handling of GNU C -$! 0.04 20090402 Compaq -> hp -$CHECK_COMPILER: -$ if (.not. (its_decc .or. its_vaxc .or. its_gnuc)) -$ then -$ its_decc = (f$search("SYS$SYSTEM:DECC$COMPILER.EXE") .nes. "") -$ its_vaxc = .not. its_decc .and. (F$Search("SYS$System:VAXC.Exe") .nes. "") -$ its_gnuc = .not. (its_decc .or. its_vaxc) .and. (f$trnlnm("gnu_cc") .nes. "") -$ endif -$! -$! Exit if no compiler available -$! -$ if (.not. (its_decc .or. its_vaxc .or. its_gnuc)) -$ then goto CC_ERR -$ else -$ if its_decc -$ then -$ write sys$output "CC compiler check ... hp C" -$ if f$trnlnm("decc$no_rooted_search_lists") .nes. "" -$ then -$ dnrsl = f$trnlnm("decc$no_rooted_search_lists") -$ endif -$ define/nolog decc$no_rooted_search_lists 1 -$ else -$ if its_vaxc then write sys$output "CC compiler check ... VAX C" -$ if its_gnuc -$ then -$ write sys$output "CC compiler check ... GNU C" -$ if f$trnlnm(topt) then write topt "gnu_cc:[000000]gcclib.olb/lib" -$ if f$trnlnm(optf) then write optf "gnu_cc:[000000]gcclib.olb/lib" -$ cc = "gcc" -$ endif -$ if f$trnlnm(topt) then write topt "sys$share:vaxcrtl.exe/share" -$ if f$trnlnm(optf) then write optf "sys$share:vaxcrtl.exe/share" -$ endif -$ endif -$ return -$!------------------------------------------------------------------------------ -$! -$! If MMS/MMK are available dump out the descrip.mms if required -$! -$CREA_MMS: -$ write sys$output "Creating descrip.mms..." -$ create descrip.mms -$ open/append out descrip.mms -$ copy sys$input: out -$ deck -# descrip.mms: MMS description file for building zlib on VMS -# written by Martin P.J. Zinser -# - -OBJS = adler32.obj, compress.obj, crc32.obj, gzclose.obj, gzlib.obj\ - gzread.obj, gzwrite.obj, uncompr.obj, infback.obj\ - deflate.obj, trees.obj, zutil.obj, inflate.obj, \ - inftrees.obj, inffast.obj - -$ eod -$ write out "CFLAGS=", ccopt -$ write out "LOPTS=", lopts -$ write out "all : example.exe minigzip.exe libz.olb" -$ copy sys$input: out -$ deck - @ write sys$output " Example applications available" - -libz.olb : libz.olb($(OBJS)) - @ write sys$output " libz available" - -example.exe : example.obj libz.olb - link $(LOPTS) example,libz.olb/lib - -minigzip.exe : minigzip.obj libz.olb - link $(LOPTS) minigzip,libz.olb/lib - -clean : - delete *.obj;*,libz.olb;*,*.opt;*,*.exe;* - - -# Other dependencies. -adler32.obj : adler32.c zutil.h zlib.h zconf.h -compress.obj : compress.c zlib.h zconf.h -crc32.obj : crc32.c zutil.h zlib.h zconf.h -deflate.obj : deflate.c deflate.h zutil.h zlib.h zconf.h -example.obj : [.test]example.c zlib.h zconf.h -gzclose.obj : gzclose.c zutil.h zlib.h zconf.h -gzlib.obj : gzlib.c zutil.h zlib.h zconf.h -gzread.obj : gzread.c zutil.h zlib.h zconf.h -gzwrite.obj : gzwrite.c zutil.h zlib.h zconf.h -inffast.obj : inffast.c zutil.h zlib.h zconf.h inftrees.h inffast.h -inflate.obj : inflate.c zutil.h zlib.h zconf.h -inftrees.obj : inftrees.c zutil.h zlib.h zconf.h inftrees.h -minigzip.obj : [.test]minigzip.c zlib.h zconf.h -trees.obj : trees.c deflate.h zutil.h zlib.h zconf.h -uncompr.obj : uncompr.c zlib.h zconf.h -zutil.obj : zutil.c zutil.h zlib.h zconf.h -infback.obj : infback.c zutil.h inftrees.h inflate.h inffast.h inffixed.h -$ eod -$ close out -$ return -$!------------------------------------------------------------------------------ -$! -$! Read list of core library sources from makefile.in and create options -$! needed to build shareable image -$! -$CREA_OLIST: -$ open/read min makefile.in -$ open/write mod modules.opt -$ src_check_list = "OBJZ =#OBJG =" -$MRLOOP: -$ read/end=mrdone min rec -$ i = 0 -$SRC_CHECK_LOOP: -$ src_check = f$element(i, "#", src_check_list) -$ i = i+1 -$ if src_check .eqs. "#" then goto mrloop -$ if (f$extract(0,6,rec) .nes. src_check) then goto src_check_loop -$ rec = rec - src_check -$ gosub extra_filnam -$ if (f$element(1,"\",rec) .eqs. "\") then goto mrloop -$MRSLOOP: -$ read/end=mrdone min rec -$ gosub extra_filnam -$ if (f$element(1,"\",rec) .nes. "\") then goto mrsloop -$MRDONE: -$ close min -$ close mod -$ return -$!------------------------------------------------------------------------------ -$! -$! Take record extracted in crea_olist and split it into single filenames -$! -$EXTRA_FILNAM: -$ myrec = f$edit(rec - "\", "trim,compress") -$ i = 0 -$FELOOP: -$ srcfil = f$element(i," ", myrec) -$ if (srcfil .nes. " ") -$ then -$ write mod f$parse(srcfil,,,"NAME"), ".obj" -$ i = i + 1 -$ goto feloop -$ endif -$ return -$!------------------------------------------------------------------------------ -$! -$! Find current Zlib version number -$! -$FIND_VERSION: -$ open/read h_in 'v_file' -$hloop: -$ read/end=hdone h_in rec -$ rec = f$edit(rec,"TRIM") -$ if (f$extract(0,1,rec) .nes. "#") then goto hloop -$ rec = f$edit(rec - "#", "TRIM") -$ if f$element(0," ",rec) .nes. "define" then goto hloop -$ if f$element(1," ",rec) .eqs. v_string -$ then -$ version = 'f$element(2," ",rec)' -$ goto hdone -$ endif -$ goto hloop -$hdone: -$ close h_in -$ return -$!------------------------------------------------------------------------------ -$! -$CHECK_CONFIG: -$! -$ in_ldef = f$locate(cdef,libdefs) -$ if (in_ldef .lt. f$length(libdefs)) -$ then -$ write aconf "#define ''cdef' 1" -$ libdefs = f$extract(0,in_ldef,libdefs) + - - f$extract(in_ldef + f$length(cdef) + 1, - - f$length(libdefs) - in_ldef - f$length(cdef) - 1, - - libdefs) -$ else -$ if (f$type('cdef') .eqs. "INTEGER") -$ then -$ write aconf "#define ''cdef' ", 'cdef' -$ else -$ if (f$type('cdef') .eqs. "STRING") -$ then -$ write aconf "#define ''cdef' ", """", '''cdef'', """" -$ else -$ gosub check_cc_def -$ endif -$ endif -$ endif -$ return -$!------------------------------------------------------------------------------ -$! -$! Check if this is a define relating to the properties of the C/C++ -$! compiler -$! -$ CHECK_CC_DEF: -$ if (cdef .eqs. "_LARGEFILE64_SOURCE") -$ then -$ copy sys$input: 'tc' -$ deck -#include "tconfig" -#define _LARGEFILE -#include - -int main(){ -FILE *fp; - fp = fopen("temp.txt","r"); - fseeko(fp,1,SEEK_SET); - fclose(fp); -} - -$ eod -$ test_inv = false -$ comm_h = false -$ gosub cc_prop_check -$ return -$ endif -$ write aconf "/* ", line, " */" -$ return -$!------------------------------------------------------------------------------ -$! -$! Check for properties of C/C++ compiler -$! -$! Version history -$! 0.01 20031020 First version to receive a number -$! 0.02 20031022 Added logic for defines with value -$! 0.03 20040309 Make sure local config file gets not deleted -$! 0.04 20041230 Also write include for configure run -$! 0.05 20050103 Add processing of "comment defines" -$CC_PROP_CHECK: -$ cc_prop = true -$ is_need = false -$ is_need = (f$extract(0,4,cdef) .eqs. "NEED") .or. (test_inv .eq. true) -$ if f$search(th) .eqs. "" then create 'th' -$ set message/nofac/noident/nosever/notext -$ on error then continue -$ cc 'tmpnam' -$ if .not. ($status) then cc_prop = false -$ on error then continue -$! The headers might lie about the capabilities of the RTL -$ link 'tmpnam',tmp.opt/opt -$ if .not. ($status) then cc_prop = false -$ set message/fac/ident/sever/text -$ on error then goto err_exit -$ delete/nolog 'tmpnam'.*;*/exclude='th' -$ if (cc_prop .and. .not. is_need) .or. - - (.not. cc_prop .and. is_need) -$ then -$ write sys$output "Checking for ''cdef'... yes" -$ if f$type('cdef_val'_yes) .nes. "" -$ then -$ if f$type('cdef_val'_yes) .eqs. "INTEGER" - - then call write_config f$fao("#define !AS !UL",cdef,'cdef_val'_yes) -$ if f$type('cdef_val'_yes) .eqs. "STRING" - - then call write_config f$fao("#define !AS !AS",cdef,'cdef_val'_yes) -$ else -$ call write_config f$fao("#define !AS 1",cdef) -$ endif -$ if (cdef .eqs. "HAVE_FSEEKO") .or. (cdef .eqs. "_LARGE_FILES") .or. - - (cdef .eqs. "_LARGEFILE64_SOURCE") then - - call write_config f$string("#define _LARGEFILE 1") -$ else -$ write sys$output "Checking for ''cdef'... no" -$ if (comm_h) -$ then - call write_config f$fao("/* !AS */",line) -$ else -$ if f$type('cdef_val'_no) .nes. "" -$ then -$ if f$type('cdef_val'_no) .eqs. "INTEGER" - - then call write_config f$fao("#define !AS !UL",cdef,'cdef_val'_no) -$ if f$type('cdef_val'_no) .eqs. "STRING" - - then call write_config f$fao("#define !AS !AS",cdef,'cdef_val'_no) -$ else -$ call write_config f$fao("#undef !AS",cdef) -$ endif -$ endif -$ endif -$ return -$!------------------------------------------------------------------------------ -$! -$! Check for properties of C/C++ compiler with multiple result values -$! -$! Version history -$! 0.01 20040127 First version -$! 0.02 20050103 Reconcile changes from cc_prop up to version 0.05 -$CC_MPROP_CHECK: -$ cc_prop = true -$ i = 1 -$ idel = 1 -$ MT_LOOP: -$ if f$type(result_'i') .eqs. "STRING" -$ then -$ set message/nofac/noident/nosever/notext -$ on error then continue -$ cc 'tmpnam'_'i' -$ if .not. ($status) then cc_prop = false -$ on error then continue -$! The headers might lie about the capabilities of the RTL -$ link 'tmpnam'_'i',tmp.opt/opt -$ if .not. ($status) then cc_prop = false -$ set message/fac/ident/sever/text -$ on error then goto err_exit -$ delete/nolog 'tmpnam'_'i'.*;* -$ if (cc_prop) -$ then -$ write sys$output "Checking for ''cdef'... ", mdef_'i' -$ if f$type(mdef_'i') .eqs. "INTEGER" - - then call write_config f$fao("#define !AS !UL",cdef,mdef_'i') -$ if f$type('cdef_val'_yes) .eqs. "STRING" - - then call write_config f$fao("#define !AS !AS",cdef,mdef_'i') -$ goto msym_clean -$ else -$ i = i + 1 -$ goto mt_loop -$ endif -$ endif -$ write sys$output "Checking for ''cdef'... no" -$ call write_config f$fao("#undef !AS",cdef) -$ MSYM_CLEAN: -$ if (idel .le. msym_max) -$ then -$ delete/sym mdef_'idel' -$ idel = idel + 1 -$ goto msym_clean -$ endif -$ return -$!------------------------------------------------------------------------------ -$! -$! Write configuration to both permanent and temporary config file -$! -$! Version history -$! 0.01 20031029 First version to receive a number -$! -$WRITE_CONFIG: SUBROUTINE -$ write aconf 'p1' -$ open/append confh 'th' -$ write confh 'p1' -$ close confh -$ENDSUBROUTINE -$!------------------------------------------------------------------------------ -$! -$! Analyze the project map file and create the symbol vector for a shareable -$! image from it -$! -$! Version history -$! 0.01 20120128 First version -$! 0.02 20120226 Add pre-load logic -$! -$ MAP_2_SHOPT: Subroutine -$! -$ SAY := "WRITE_ SYS$OUTPUT" -$! -$ IF F$SEARCH("''P1'") .EQS. "" -$ THEN -$ SAY "MAP_2_SHOPT-E-NOSUCHFILE: Error, inputfile ''p1' not available" -$ goto exit_m2s -$ ENDIF -$ IF "''P2'" .EQS. "" -$ THEN -$ SAY "MAP_2_SHOPT: Error, no output file provided" -$ goto exit_m2s -$ ENDIF -$! -$ module1 = "deflate#deflateEnd#deflateInit_#deflateParams#deflateSetDictionary" -$ module2 = "gzclose#gzerror#gzgetc#gzgets#gzopen#gzprintf#gzputc#gzputs#gzread" -$ module3 = "gzseek#gztell#inflate#inflateEnd#inflateInit_#inflateSetDictionary" -$ module4 = "inflateSync#uncompress#zlibVersion#compress" -$ open/read map 'p1 -$ if axp .or. ia64 -$ then -$ open/write aopt a.opt -$ open/write bopt b.opt -$ write aopt " CASE_SENSITIVE=YES" -$ write bopt "SYMBOL_VECTOR= (-" -$ mod_sym_num = 1 -$ MOD_SYM_LOOP: -$ if f$type(module'mod_sym_num') .nes. "" -$ then -$ mod_in = 0 -$ MOD_SYM_IN: -$ shared_proc = f$element(mod_in, "#", module'mod_sym_num') -$ if shared_proc .nes. "#" -$ then -$ write aopt f$fao(" symbol_vector=(!AS/!AS=PROCEDURE)",- - f$edit(shared_proc,"upcase"),shared_proc) -$ write bopt f$fao("!AS=PROCEDURE,-",shared_proc) -$ mod_in = mod_in + 1 -$ goto mod_sym_in -$ endif -$ mod_sym_num = mod_sym_num + 1 -$ goto mod_sym_loop -$ endif -$MAP_LOOP: -$ read/end=map_end map line -$ if (f$locate("{",line).lt. f$length(line)) .or. - - (f$locate("global:", line) .lt. f$length(line)) -$ then -$ proc = true -$ goto map_loop -$ endif -$ if f$locate("}",line).lt. f$length(line) then proc = false -$ if f$locate("local:", line) .lt. f$length(line) then proc = false -$ if proc -$ then -$ shared_proc = f$edit(line,"collapse") -$ chop_semi = f$locate(";", shared_proc) -$ if chop_semi .lt. f$length(shared_proc) then - - shared_proc = f$extract(0, chop_semi, shared_proc) -$ write aopt f$fao(" symbol_vector=(!AS/!AS=PROCEDURE)",- - f$edit(shared_proc,"upcase"),shared_proc) -$ write bopt f$fao("!AS=PROCEDURE,-",shared_proc) -$ endif -$ goto map_loop -$MAP_END: -$ close/nolog aopt -$ close/nolog bopt -$ open/append libopt 'p2' -$ open/read aopt a.opt -$ open/read bopt b.opt -$ALOOP: -$ read/end=aloop_end aopt line -$ write libopt line -$ goto aloop -$ALOOP_END: -$ close/nolog aopt -$ sv = "" -$BLOOP: -$ read/end=bloop_end bopt svn -$ if (svn.nes."") -$ then -$ if (sv.nes."") then write libopt sv -$ sv = svn -$ endif -$ goto bloop -$BLOOP_END: -$ write libopt f$extract(0,f$length(sv)-2,sv), "-" -$ write libopt ")" -$ close/nolog bopt -$ delete/nolog/noconf a.opt;*,b.opt;* -$ else -$ if vax -$ then -$ open/append libopt 'p2' -$ mod_sym_num = 1 -$ VMOD_SYM_LOOP: -$ if f$type(module'mod_sym_num') .nes. "" -$ then -$ mod_in = 0 -$ VMOD_SYM_IN: -$ shared_proc = f$element(mod_in, "#", module'mod_sym_num') -$ if shared_proc .nes. "#" -$ then -$ write libopt f$fao("UNIVERSAL=!AS",- - f$edit(shared_proc,"upcase")) -$ mod_in = mod_in + 1 -$ goto vmod_sym_in -$ endif -$ mod_sym_num = mod_sym_num + 1 -$ goto vmod_sym_loop -$ endif -$VMAP_LOOP: -$ read/end=vmap_end map line -$ if (f$locate("{",line).lt. f$length(line)) .or. - - (f$locate("global:", line) .lt. f$length(line)) -$ then -$ proc = true -$ goto vmap_loop -$ endif -$ if f$locate("}",line).lt. f$length(line) then proc = false -$ if f$locate("local:", line) .lt. f$length(line) then proc = false -$ if proc -$ then -$ shared_proc = f$edit(line,"collapse") -$ chop_semi = f$locate(";", shared_proc) -$ if chop_semi .lt. f$length(shared_proc) then - - shared_proc = f$extract(0, chop_semi, shared_proc) -$ write libopt f$fao("UNIVERSAL=!AS",- - f$edit(shared_proc,"upcase")) -$ endif -$ goto vmap_loop -$VMAP_END: -$ else -$ write sys$output "Unknown Architecture (Not VAX, AXP, or IA64)" -$ write sys$output "No options file created" -$ endif -$ endif -$ EXIT_M2S: -$ close/nolog map -$ close/nolog libopt -$ endsubroutine diff --git a/src/beast/test/zlib/zlib-1.2.8/msdos/Makefile.bor b/src/beast/test/zlib/zlib-1.2.8/msdos/Makefile.bor deleted file mode 100644 index 3d12a2c2527..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/msdos/Makefile.bor +++ /dev/null @@ -1,115 +0,0 @@ -# Makefile for zlib -# Borland C++ -# Last updated: 15-Mar-2003 - -# To use, do "make -fmakefile.bor" -# To compile in small model, set below: MODEL=s - -# WARNING: the small model is supported but only for small values of -# MAX_WBITS and MAX_MEM_LEVEL. For example: -# -DMAX_WBITS=11 -DDEF_WBITS=11 -DMAX_MEM_LEVEL=3 -# If you wish to reduce the memory requirements (default 256K for big -# objects plus a few K), you can add to the LOC macro below: -# -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14 -# See zconf.h for details about the memory requirements. - -# ------------ Turbo C++, Borland C++ ------------ - -# Optional nonstandard preprocessor flags (e.g. -DMAX_MEM_LEVEL=7) -# should be added to the environment via "set LOCAL_ZLIB=-DFOO" or added -# to the declaration of LOC here: -LOC = $(LOCAL_ZLIB) - -# type for CPU required: 0: 8086, 1: 80186, 2: 80286, 3: 80386, etc. -CPU_TYP = 0 - -# memory model: one of s, m, c, l (small, medium, compact, large) -MODEL=l - -# replace bcc with tcc for Turbo C++ 1.0, with bcc32 for the 32 bit version -CC=bcc -LD=bcc -AR=tlib - -# compiler flags -# replace "-O2" by "-O -G -a -d" for Turbo C++ 1.0 -CFLAGS=-O2 -Z -m$(MODEL) $(LOC) - -LDFLAGS=-m$(MODEL) -f- - - -# variables -ZLIB_LIB = zlib_$(MODEL).lib - -OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzlib.obj gzread.obj -OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj -OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzlib.obj+gzread.obj -OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj - - -# targets -all: $(ZLIB_LIB) example.exe minigzip.exe - -.c.obj: - $(CC) -c $(CFLAGS) $*.c - -adler32.obj: adler32.c zlib.h zconf.h - -compress.obj: compress.c zlib.h zconf.h - -crc32.obj: crc32.c zlib.h zconf.h crc32.h - -deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h - -gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h - -gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h - -gzread.obj: gzread.c zlib.h zconf.h gzguts.h - -gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h - -infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ - inffast.h inffixed.h - -inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ - inffast.h - -inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ - inffast.h inffixed.h - -inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h - -trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h - -uncompr.obj: uncompr.c zlib.h zconf.h - -zutil.obj: zutil.c zutil.h zlib.h zconf.h - -example.obj: test/example.c zlib.h zconf.h - -minigzip.obj: test/minigzip.c zlib.h zconf.h - - -# the command line is cut to fit in the MS-DOS 128 byte limit: -$(ZLIB_LIB): $(OBJ1) $(OBJ2) - -del $(ZLIB_LIB) - $(AR) $(ZLIB_LIB) $(OBJP1) - $(AR) $(ZLIB_LIB) $(OBJP2) - -example.exe: example.obj $(ZLIB_LIB) - $(LD) $(LDFLAGS) example.obj $(ZLIB_LIB) - -minigzip.exe: minigzip.obj $(ZLIB_LIB) - $(LD) $(LDFLAGS) minigzip.obj $(ZLIB_LIB) - -test: example.exe minigzip.exe - example - echo hello world | minigzip | minigzip -d - -clean: - -del *.obj - -del *.lib - -del *.exe - -del zlib_*.bak - -del foo.gz diff --git a/src/beast/test/zlib/zlib-1.2.8/msdos/Makefile.dj2 b/src/beast/test/zlib/zlib-1.2.8/msdos/Makefile.dj2 deleted file mode 100644 index 29b03954d7b..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/msdos/Makefile.dj2 +++ /dev/null @@ -1,104 +0,0 @@ -# Makefile for zlib. Modified for djgpp v2.0 by F. J. Donahoe, 3/15/96. -# Copyright (C) 1995-1998 Jean-loup Gailly. -# For conditions of distribution and use, see copyright notice in zlib.h - -# To compile, or to compile and test, type: -# -# make -fmakefile.dj2; make test -fmakefile.dj2 -# -# To install libz.a, zconf.h and zlib.h in the djgpp directories, type: -# -# make install -fmakefile.dj2 -# -# after first defining LIBRARY_PATH and INCLUDE_PATH in djgpp.env as -# in the sample below if the pattern of the DJGPP distribution is to -# be followed. Remember that, while 'es around <=> are ignored in -# makefiles, they are *not* in batch files or in djgpp.env. -# - - - - - -# [make] -# INCLUDE_PATH=%\>;INCLUDE_PATH%%\DJDIR%\include -# LIBRARY_PATH=%\>;LIBRARY_PATH%%\DJDIR%\lib -# BUTT=-m486 -# - - - - - -# Alternately, these variables may be defined below, overriding the values -# in djgpp.env, as -# INCLUDE_PATH=c:\usr\include -# LIBRARY_PATH=c:\usr\lib - -CC=gcc - -#CFLAGS=-MMD -O -#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7 -#CFLAGS=-MMD -g -DDEBUG -CFLAGS=-MMD -O3 $(BUTT) -Wall -Wwrite-strings -Wpointer-arith -Wconversion \ - -Wstrict-prototypes -Wmissing-prototypes - -# If cp.exe is available, replace "copy /Y" with "cp -fp" . -CP=copy /Y -# If gnu install.exe is available, replace $(CP) with ginstall. -INSTALL=$(CP) -# The default value of RM is "rm -f." If "rm.exe" is found, comment out: -RM=del -LDLIBS=-L. -lz -LD=$(CC) -s -o -LDSHARED=$(CC) - -INCL=zlib.h zconf.h -LIBS=libz.a - -AR=ar rcs - -prefix=/usr/local -exec_prefix = $(prefix) - -OBJS = adler32.o compress.o crc32.o gzclose.o gzlib.o gzread.o gzwrite.o \ - uncompr.o deflate.o trees.o zutil.o inflate.o infback.o inftrees.o inffast.o - -OBJA = -# to use the asm code: make OBJA=match.o - -TEST_OBJS = example.o minigzip.o - -all: example.exe minigzip.exe - -check: test -test: all - ./example - echo hello world | .\minigzip | .\minigzip -d - -%.o : %.c - $(CC) $(CFLAGS) -c $< -o $@ - -libz.a: $(OBJS) $(OBJA) - $(AR) $@ $(OBJS) $(OBJA) - -%.exe : %.o $(LIBS) - $(LD) $@ $< $(LDLIBS) - -# INCLUDE_PATH and LIBRARY_PATH were set for [make] in djgpp.env . - -.PHONY : uninstall clean - -install: $(INCL) $(LIBS) - -@if not exist $(INCLUDE_PATH)\nul mkdir $(INCLUDE_PATH) - -@if not exist $(LIBRARY_PATH)\nul mkdir $(LIBRARY_PATH) - $(INSTALL) zlib.h $(INCLUDE_PATH) - $(INSTALL) zconf.h $(INCLUDE_PATH) - $(INSTALL) libz.a $(LIBRARY_PATH) - -uninstall: - $(RM) $(INCLUDE_PATH)\zlib.h - $(RM) $(INCLUDE_PATH)\zconf.h - $(RM) $(LIBRARY_PATH)\libz.a - -clean: - $(RM) *.d - $(RM) *.o - $(RM) *.exe - $(RM) libz.a - $(RM) foo.gz - -DEPS := $(wildcard *.d) -ifneq ($(DEPS),) -include $(DEPS) -endif diff --git a/src/beast/test/zlib/zlib-1.2.8/msdos/Makefile.emx b/src/beast/test/zlib/zlib-1.2.8/msdos/Makefile.emx deleted file mode 100644 index 9c1b57a5857..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/msdos/Makefile.emx +++ /dev/null @@ -1,69 +0,0 @@ -# Makefile for zlib. Modified for emx 0.9c by Chr. Spieler, 6/17/98. -# Copyright (C) 1995-1998 Jean-loup Gailly. -# For conditions of distribution and use, see copyright notice in zlib.h - -# To compile, or to compile and test, type: -# -# make -fmakefile.emx; make test -fmakefile.emx -# - -CC=gcc - -#CFLAGS=-MMD -O -#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7 -#CFLAGS=-MMD -g -DDEBUG -CFLAGS=-MMD -O3 $(BUTT) -Wall -Wwrite-strings -Wpointer-arith -Wconversion \ - -Wstrict-prototypes -Wmissing-prototypes - -# If cp.exe is available, replace "copy /Y" with "cp -fp" . -CP=copy /Y -# If gnu install.exe is available, replace $(CP) with ginstall. -INSTALL=$(CP) -# The default value of RM is "rm -f." If "rm.exe" is found, comment out: -RM=del -LDLIBS=-L. -lzlib -LD=$(CC) -s -o -LDSHARED=$(CC) - -INCL=zlib.h zconf.h -LIBS=zlib.a - -AR=ar rcs - -prefix=/usr/local -exec_prefix = $(prefix) - -OBJS = adler32.o compress.o crc32.o gzclose.o gzlib.o gzread.o gzwrite.o \ - uncompr.o deflate.o trees.o zutil.o inflate.o infback.o inftrees.o inffast.o - -TEST_OBJS = example.o minigzip.o - -all: example.exe minigzip.exe - -test: all - ./example - echo hello world | .\minigzip | .\minigzip -d - -%.o : %.c - $(CC) $(CFLAGS) -c $< -o $@ - -zlib.a: $(OBJS) - $(AR) $@ $(OBJS) - -%.exe : %.o $(LIBS) - $(LD) $@ $< $(LDLIBS) - - -.PHONY : clean - -clean: - $(RM) *.d - $(RM) *.o - $(RM) *.exe - $(RM) zlib.a - $(RM) foo.gz - -DEPS := $(wildcard *.d) -ifneq ($(DEPS),) -include $(DEPS) -endif diff --git a/src/beast/test/zlib/zlib-1.2.8/msdos/Makefile.msc b/src/beast/test/zlib/zlib-1.2.8/msdos/Makefile.msc deleted file mode 100644 index ae8378615ec..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/msdos/Makefile.msc +++ /dev/null @@ -1,112 +0,0 @@ -# Makefile for zlib -# Microsoft C 5.1 or later -# Last updated: 19-Mar-2003 - -# To use, do "make makefile.msc" -# To compile in small model, set below: MODEL=S - -# If you wish to reduce the memory requirements (default 256K for big -# objects plus a few K), you can add to the LOC macro below: -# -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14 -# See zconf.h for details about the memory requirements. - -# ------------- Microsoft C 5.1 and later ------------- - -# Optional nonstandard preprocessor flags (e.g. -DMAX_MEM_LEVEL=7) -# should be added to the environment via "set LOCAL_ZLIB=-DFOO" or added -# to the declaration of LOC here: -LOC = $(LOCAL_ZLIB) - -# Type for CPU required: 0: 8086, 1: 80186, 2: 80286, 3: 80386, etc. -CPU_TYP = 0 - -# Memory model: one of S, M, C, L (small, medium, compact, large) -MODEL=L - -CC=cl -CFLAGS=-nologo -A$(MODEL) -G$(CPU_TYP) -W3 -Oait -Gs $(LOC) -#-Ox generates bad code with MSC 5.1 -LIB_CFLAGS=-Zl $(CFLAGS) - -LD=link -LDFLAGS=/noi/e/st:0x1500/noe/farcall/packcode -# "/farcall/packcode" are only useful for `large code' memory models -# but should be a "no-op" for small code models. - - -# variables -ZLIB_LIB = zlib_$(MODEL).lib - -OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzlib.obj gzread.obj -OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj - - -# targets -all: $(ZLIB_LIB) example.exe minigzip.exe - -.c.obj: - $(CC) -c $(LIB_CFLAGS) $*.c - -adler32.obj: adler32.c zlib.h zconf.h - -compress.obj: compress.c zlib.h zconf.h - -crc32.obj: crc32.c zlib.h zconf.h crc32.h - -deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h - -gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h - -gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h - -gzread.obj: gzread.c zlib.h zconf.h gzguts.h - -gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h - -infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ - inffast.h inffixed.h - -inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ - inffast.h - -inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ - inffast.h inffixed.h - -inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h - -trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h - -uncompr.obj: uncompr.c zlib.h zconf.h - -zutil.obj: zutil.c zutil.h zlib.h zconf.h - -example.obj: test/example.c zlib.h zconf.h - $(CC) -c $(CFLAGS) $*.c - -minigzip.obj: test/minigzip.c zlib.h zconf.h - $(CC) -c $(CFLAGS) $*.c - - -# the command line is cut to fit in the MS-DOS 128 byte limit: -$(ZLIB_LIB): $(OBJ1) $(OBJ2) - if exist $(ZLIB_LIB) del $(ZLIB_LIB) - lib $(ZLIB_LIB) $(OBJ1); - lib $(ZLIB_LIB) $(OBJ2); - -example.exe: example.obj $(ZLIB_LIB) - $(LD) $(LDFLAGS) example.obj,,,$(ZLIB_LIB); - -minigzip.exe: minigzip.obj $(ZLIB_LIB) - $(LD) $(LDFLAGS) minigzip.obj,,,$(ZLIB_LIB); - -test: example.exe minigzip.exe - example - echo hello world | minigzip | minigzip -d - -clean: - -del *.obj - -del *.lib - -del *.exe - -del *.map - -del zlib_*.bak - -del foo.gz diff --git a/src/beast/test/zlib/zlib-1.2.8/msdos/Makefile.tc b/src/beast/test/zlib/zlib-1.2.8/msdos/Makefile.tc deleted file mode 100644 index 5aec82a9d58..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/msdos/Makefile.tc +++ /dev/null @@ -1,100 +0,0 @@ -# Makefile for zlib -# Turbo C 2.01, Turbo C++ 1.01 -# Last updated: 15-Mar-2003 - -# To use, do "make -fmakefile.tc" -# To compile in small model, set below: MODEL=s - -# WARNING: the small model is supported but only for small values of -# MAX_WBITS and MAX_MEM_LEVEL. For example: -# -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3 -# If you wish to reduce the memory requirements (default 256K for big -# objects plus a few K), you can add to CFLAGS below: -# -DMAX_MEM_LEVEL=7 -DMAX_WBITS=14 -# See zconf.h for details about the memory requirements. - -# ------------ Turbo C 2.01, Turbo C++ 1.01 ------------ -MODEL=l -CC=tcc -LD=tcc -AR=tlib -# CFLAGS=-O2 -G -Z -m$(MODEL) -DMAX_WBITS=11 -DMAX_MEM_LEVEL=3 -CFLAGS=-O2 -G -Z -m$(MODEL) -LDFLAGS=-m$(MODEL) -f- - - -# variables -ZLIB_LIB = zlib_$(MODEL).lib - -OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzlib.obj gzread.obj -OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj -OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzlib.obj+gzread.obj -OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj - - -# targets -all: $(ZLIB_LIB) example.exe minigzip.exe - -.c.obj: - $(CC) -c $(CFLAGS) $*.c - -adler32.obj: adler32.c zlib.h zconf.h - -compress.obj: compress.c zlib.h zconf.h - -crc32.obj: crc32.c zlib.h zconf.h crc32.h - -deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h - -gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h - -gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h - -gzread.obj: gzread.c zlib.h zconf.h gzguts.h - -gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h - -infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ - inffast.h inffixed.h - -inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ - inffast.h - -inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ - inffast.h inffixed.h - -inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h - -trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h - -uncompr.obj: uncompr.c zlib.h zconf.h - -zutil.obj: zutil.c zutil.h zlib.h zconf.h - -example.obj: test/example.c zlib.h zconf.h - -minigzip.obj: test/minigzip.c zlib.h zconf.h - - -# the command line is cut to fit in the MS-DOS 128 byte limit: -$(ZLIB_LIB): $(OBJ1) $(OBJ2) - -del $(ZLIB_LIB) - $(AR) $(ZLIB_LIB) $(OBJP1) - $(AR) $(ZLIB_LIB) $(OBJP2) - -example.exe: example.obj $(ZLIB_LIB) - $(LD) $(LDFLAGS) example.obj $(ZLIB_LIB) - -minigzip.exe: minigzip.obj $(ZLIB_LIB) - $(LD) $(LDFLAGS) minigzip.obj $(ZLIB_LIB) - -test: example.exe minigzip.exe - example - echo hello world | minigzip | minigzip -d - -clean: - -del *.obj - -del *.lib - -del *.exe - -del zlib_*.bak - -del foo.gz diff --git a/src/beast/test/zlib/zlib-1.2.8/nintendods/Makefile b/src/beast/test/zlib/zlib-1.2.8/nintendods/Makefile deleted file mode 100644 index 21337d01ab2..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/nintendods/Makefile +++ /dev/null @@ -1,126 +0,0 @@ -#--------------------------------------------------------------------------------- -.SUFFIXES: -#--------------------------------------------------------------------------------- - -ifeq ($(strip $(DEVKITARM)),) -$(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") -endif - -include $(DEVKITARM)/ds_rules - -#--------------------------------------------------------------------------------- -# TARGET is the name of the output -# BUILD is the directory where object files & intermediate files will be placed -# SOURCES is a list of directories containing source code -# DATA is a list of directories containing data files -# INCLUDES is a list of directories containing header files -#--------------------------------------------------------------------------------- -TARGET := $(shell basename $(CURDIR)) -BUILD := build -SOURCES := ../../ -DATA := data -INCLUDES := include - -#--------------------------------------------------------------------------------- -# options for code generation -#--------------------------------------------------------------------------------- -ARCH := -mthumb -mthumb-interwork - -CFLAGS := -Wall -O2\ - -march=armv5te -mtune=arm946e-s \ - -fomit-frame-pointer -ffast-math \ - $(ARCH) - -CFLAGS += $(INCLUDE) -DARM9 -CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions - -ASFLAGS := $(ARCH) -march=armv5te -mtune=arm946e-s -LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) - -#--------------------------------------------------------------------------------- -# list of directories containing libraries, this must be the top level containing -# include and lib -#--------------------------------------------------------------------------------- -LIBDIRS := $(LIBNDS) - -#--------------------------------------------------------------------------------- -# no real need to edit anything past this point unless you need to add additional -# rules for different file extensions -#--------------------------------------------------------------------------------- -ifneq ($(BUILD),$(notdir $(CURDIR))) -#--------------------------------------------------------------------------------- - -export OUTPUT := $(CURDIR)/lib/libz.a - -export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ - $(foreach dir,$(DATA),$(CURDIR)/$(dir)) - -export DEPSDIR := $(CURDIR)/$(BUILD) - -CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) -CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) -SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) -BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) - -#--------------------------------------------------------------------------------- -# use CXX for linking C++ projects, CC for standard C -#--------------------------------------------------------------------------------- -ifeq ($(strip $(CPPFILES)),) -#--------------------------------------------------------------------------------- - export LD := $(CC) -#--------------------------------------------------------------------------------- -else -#--------------------------------------------------------------------------------- - export LD := $(CXX) -#--------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------- - -export OFILES := $(addsuffix .o,$(BINFILES)) \ - $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) - -export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ - $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ - -I$(CURDIR)/$(BUILD) - -.PHONY: $(BUILD) clean all - -#--------------------------------------------------------------------------------- -all: $(BUILD) - @[ -d $@ ] || mkdir -p include - @cp ../../*.h include - -lib: - @[ -d $@ ] || mkdir -p $@ - -$(BUILD): lib - @[ -d $@ ] || mkdir -p $@ - @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile - -#--------------------------------------------------------------------------------- -clean: - @echo clean ... - @rm -fr $(BUILD) lib - -#--------------------------------------------------------------------------------- -else - -DEPENDS := $(OFILES:.o=.d) - -#--------------------------------------------------------------------------------- -# main targets -#--------------------------------------------------------------------------------- -$(OUTPUT) : $(OFILES) - -#--------------------------------------------------------------------------------- -%.bin.o : %.bin -#--------------------------------------------------------------------------------- - @echo $(notdir $<) - @$(bin2o) - - --include $(DEPENDS) - -#--------------------------------------------------------------------------------------- -endif -#--------------------------------------------------------------------------------------- diff --git a/src/beast/test/zlib/zlib-1.2.8/nintendods/README b/src/beast/test/zlib/zlib-1.2.8/nintendods/README deleted file mode 100644 index ba7a37dbe8e..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/nintendods/README +++ /dev/null @@ -1,5 +0,0 @@ -This Makefile requires devkitARM (http://www.devkitpro.org/category/devkitarm/) and works inside "contrib/nds". It is based on a devkitARM template. - -Eduardo Costa -January 3, 2009 - diff --git a/src/beast/test/zlib/zlib-1.2.8/old/Makefile.emx b/src/beast/test/zlib/zlib-1.2.8/old/Makefile.emx deleted file mode 100644 index 4d6ab0efa66..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/old/Makefile.emx +++ /dev/null @@ -1,69 +0,0 @@ -# Makefile for zlib. Modified for emx/rsxnt by Chr. Spieler, 6/16/98. -# Copyright (C) 1995-1998 Jean-loup Gailly. -# For conditions of distribution and use, see copyright notice in zlib.h - -# To compile, or to compile and test, type: -# -# make -fmakefile.emx; make test -fmakefile.emx -# - -CC=gcc -Zwin32 - -#CFLAGS=-MMD -O -#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7 -#CFLAGS=-MMD -g -DDEBUG -CFLAGS=-MMD -O3 $(BUTT) -Wall -Wwrite-strings -Wpointer-arith -Wconversion \ - -Wstrict-prototypes -Wmissing-prototypes - -# If cp.exe is available, replace "copy /Y" with "cp -fp" . -CP=copy /Y -# If gnu install.exe is available, replace $(CP) with ginstall. -INSTALL=$(CP) -# The default value of RM is "rm -f." If "rm.exe" is found, comment out: -RM=del -LDLIBS=-L. -lzlib -LD=$(CC) -s -o -LDSHARED=$(CC) - -INCL=zlib.h zconf.h -LIBS=zlib.a - -AR=ar rcs - -prefix=/usr/local -exec_prefix = $(prefix) - -OBJS = adler32.o compress.o crc32.o deflate.o gzclose.o gzlib.o gzread.o \ - gzwrite.o infback.o inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o - -TEST_OBJS = example.o minigzip.o - -all: example.exe minigzip.exe - -test: all - ./example - echo hello world | .\minigzip | .\minigzip -d - -%.o : %.c - $(CC) $(CFLAGS) -c $< -o $@ - -zlib.a: $(OBJS) - $(AR) $@ $(OBJS) - -%.exe : %.o $(LIBS) - $(LD) $@ $< $(LDLIBS) - - -.PHONY : clean - -clean: - $(RM) *.d - $(RM) *.o - $(RM) *.exe - $(RM) zlib.a - $(RM) foo.gz - -DEPS := $(wildcard *.d) -ifneq ($(DEPS),) -include $(DEPS) -endif diff --git a/src/beast/test/zlib/zlib-1.2.8/old/Makefile.riscos b/src/beast/test/zlib/zlib-1.2.8/old/Makefile.riscos deleted file mode 100644 index 57e29d3fba9..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/old/Makefile.riscos +++ /dev/null @@ -1,151 +0,0 @@ -# Project: zlib_1_03 -# Patched for zlib 1.1.2 rw@shadow.org.uk 19980430 -# test works out-of-the-box, installs `somewhere' on demand - -# Toolflags: -CCflags = -c -depend !Depend -IC: -g -throwback -DRISCOS -fah -C++flags = -c -depend !Depend -IC: -throwback -Linkflags = -aif -c++ -o $@ -ObjAsmflags = -throwback -NoCache -depend !Depend -CMHGflags = -LibFileflags = -c -l -o $@ -Squeezeflags = -o $@ - -# change the line below to where _you_ want the library installed. -libdest = lib:zlib - -# Final targets: -@.lib: @.o.adler32 @.o.compress @.o.crc32 @.o.deflate @.o.gzio \ - @.o.infblock @.o.infcodes @.o.inffast @.o.inflate @.o.inftrees @.o.infutil @.o.trees \ - @.o.uncompr @.o.zutil - LibFile $(LibFileflags) @.o.adler32 @.o.compress @.o.crc32 @.o.deflate \ - @.o.gzio @.o.infblock @.o.infcodes @.o.inffast @.o.inflate @.o.inftrees @.o.infutil \ - @.o.trees @.o.uncompr @.o.zutil -test: @.minigzip @.example @.lib - @copy @.lib @.libc A~C~DF~L~N~P~Q~RS~TV - @echo running tests: hang on. - @/@.minigzip -f -9 libc - @/@.minigzip -d libc-gz - @/@.minigzip -f -1 libc - @/@.minigzip -d libc-gz - @/@.minigzip -h -9 libc - @/@.minigzip -d libc-gz - @/@.minigzip -h -1 libc - @/@.minigzip -d libc-gz - @/@.minigzip -9 libc - @/@.minigzip -d libc-gz - @/@.minigzip -1 libc - @/@.minigzip -d libc-gz - @diff @.lib @.libc - @echo that should have reported '@.lib and @.libc identical' if you have diff. - @/@.example @.fred @.fred - @echo that will have given lots of hello!'s. - -@.minigzip: @.o.minigzip @.lib C:o.Stubs - Link $(Linkflags) @.o.minigzip @.lib C:o.Stubs -@.example: @.o.example @.lib C:o.Stubs - Link $(Linkflags) @.o.example @.lib C:o.Stubs - -install: @.lib - cdir $(libdest) - cdir $(libdest).h - @copy @.h.zlib $(libdest).h.zlib A~C~DF~L~N~P~Q~RS~TV - @copy @.h.zconf $(libdest).h.zconf A~C~DF~L~N~P~Q~RS~TV - @copy @.lib $(libdest).lib A~C~DF~L~N~P~Q~RS~TV - @echo okay, installed zlib in $(libdest) - -clean:; remove @.minigzip - remove @.example - remove @.libc - -wipe @.o.* F~r~cV - remove @.fred - -# User-editable dependencies: -.c.o: - cc $(ccflags) -o $@ $< - -# Static dependencies: - -# Dynamic dependencies: -o.example: c.example -o.example: h.zlib -o.example: h.zconf -o.minigzip: c.minigzip -o.minigzip: h.zlib -o.minigzip: h.zconf -o.adler32: c.adler32 -o.adler32: h.zlib -o.adler32: h.zconf -o.compress: c.compress -o.compress: h.zlib -o.compress: h.zconf -o.crc32: c.crc32 -o.crc32: h.zlib -o.crc32: h.zconf -o.deflate: c.deflate -o.deflate: h.deflate -o.deflate: h.zutil -o.deflate: h.zlib -o.deflate: h.zconf -o.gzio: c.gzio -o.gzio: h.zutil -o.gzio: h.zlib -o.gzio: h.zconf -o.infblock: c.infblock -o.infblock: h.zutil -o.infblock: h.zlib -o.infblock: h.zconf -o.infblock: h.infblock -o.infblock: h.inftrees -o.infblock: h.infcodes -o.infblock: h.infutil -o.infcodes: c.infcodes -o.infcodes: h.zutil -o.infcodes: h.zlib -o.infcodes: h.zconf -o.infcodes: h.inftrees -o.infcodes: h.infblock -o.infcodes: h.infcodes -o.infcodes: h.infutil -o.infcodes: h.inffast -o.inffast: c.inffast -o.inffast: h.zutil -o.inffast: h.zlib -o.inffast: h.zconf -o.inffast: h.inftrees -o.inffast: h.infblock -o.inffast: h.infcodes -o.inffast: h.infutil -o.inffast: h.inffast -o.inflate: c.inflate -o.inflate: h.zutil -o.inflate: h.zlib -o.inflate: h.zconf -o.inflate: h.infblock -o.inftrees: c.inftrees -o.inftrees: h.zutil -o.inftrees: h.zlib -o.inftrees: h.zconf -o.inftrees: h.inftrees -o.inftrees: h.inffixed -o.infutil: c.infutil -o.infutil: h.zutil -o.infutil: h.zlib -o.infutil: h.zconf -o.infutil: h.infblock -o.infutil: h.inftrees -o.infutil: h.infcodes -o.infutil: h.infutil -o.trees: c.trees -o.trees: h.deflate -o.trees: h.zutil -o.trees: h.zlib -o.trees: h.zconf -o.trees: h.trees -o.uncompr: c.uncompr -o.uncompr: h.zlib -o.uncompr: h.zconf -o.zutil: c.zutil -o.zutil: h.zutil -o.zutil: h.zlib -o.zutil: h.zconf diff --git a/src/beast/test/zlib/zlib-1.2.8/old/README b/src/beast/test/zlib/zlib-1.2.8/old/README deleted file mode 100644 index 800bf079827..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/old/README +++ /dev/null @@ -1,3 +0,0 @@ -This directory contains files that have not been updated for zlib 1.2.x - -(Volunteers are encouraged to help clean this up. Thanks.) diff --git a/src/beast/test/zlib/zlib-1.2.8/old/descrip.mms b/src/beast/test/zlib/zlib-1.2.8/old/descrip.mms deleted file mode 100644 index 7066da5b557..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/old/descrip.mms +++ /dev/null @@ -1,48 +0,0 @@ -# descrip.mms: MMS description file for building zlib on VMS -# written by Martin P.J. Zinser - -cc_defs = -c_deb = - -.ifdef __DECC__ -pref = /prefix=all -.endif - -OBJS = adler32.obj, compress.obj, crc32.obj, gzio.obj, uncompr.obj,\ - deflate.obj, trees.obj, zutil.obj, inflate.obj, infblock.obj,\ - inftrees.obj, infcodes.obj, infutil.obj, inffast.obj - -CFLAGS= $(C_DEB) $(CC_DEFS) $(PREF) - -all : example.exe minigzip.exe - @ write sys$output " Example applications available" -libz.olb : libz.olb($(OBJS)) - @ write sys$output " libz available" - -example.exe : example.obj libz.olb - link example,libz.olb/lib - -minigzip.exe : minigzip.obj libz.olb - link minigzip,libz.olb/lib,x11vms:xvmsutils.olb/lib - -clean : - delete *.obj;*,libz.olb;* - - -# Other dependencies. -adler32.obj : zutil.h zlib.h zconf.h -compress.obj : zlib.h zconf.h -crc32.obj : zutil.h zlib.h zconf.h -deflate.obj : deflate.h zutil.h zlib.h zconf.h -example.obj : zlib.h zconf.h -gzio.obj : zutil.h zlib.h zconf.h -infblock.obj : zutil.h zlib.h zconf.h infblock.h inftrees.h infcodes.h infutil.h -infcodes.obj : zutil.h zlib.h zconf.h inftrees.h infutil.h infcodes.h inffast.h -inffast.obj : zutil.h zlib.h zconf.h inftrees.h infutil.h inffast.h -inflate.obj : zutil.h zlib.h zconf.h infblock.h -inftrees.obj : zutil.h zlib.h zconf.h inftrees.h -infutil.obj : zutil.h zlib.h zconf.h inftrees.h infutil.h -minigzip.obj : zlib.h zconf.h -trees.obj : deflate.h zutil.h zlib.h zconf.h -uncompr.obj : zlib.h zconf.h -zutil.obj : zutil.h zlib.h zconf.h diff --git a/src/beast/test/zlib/zlib-1.2.8/old/os2/Makefile.os2 b/src/beast/test/zlib/zlib-1.2.8/old/os2/Makefile.os2 deleted file mode 100644 index a105aaa5bbd..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/old/os2/Makefile.os2 +++ /dev/null @@ -1,136 +0,0 @@ -# Makefile for zlib under OS/2 using GCC (PGCC) -# For conditions of distribution and use, see copyright notice in zlib.h - -# To compile and test, type: -# cp Makefile.os2 .. -# cd .. -# make -f Makefile.os2 test - -# This makefile will build a static library z.lib, a shared library -# z.dll and a import library zdll.lib. You can use either z.lib or -# zdll.lib by specifying either -lz or -lzdll on gcc's command line - -CC=gcc -Zomf -s - -CFLAGS=-O6 -Wall -#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7 -#CFLAGS=-g -DDEBUG -#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \ -# -Wstrict-prototypes -Wmissing-prototypes - -#################### BUG WARNING: ##################### -## infcodes.c hits a bug in pgcc-1.0, so you have to use either -## -O# where # <= 4 or one of (-fno-ommit-frame-pointer or -fno-force-mem) -## This bug is reportedly fixed in pgcc >1.0, but this was not tested -CFLAGS+=-fno-force-mem - -LDFLAGS=-s -L. -lzdll -Zcrtdll -LDSHARED=$(CC) -s -Zomf -Zdll -Zcrtdll - -VER=1.1.0 -ZLIB=z.lib -SHAREDLIB=z.dll -SHAREDLIBIMP=zdll.lib -LIBS=$(ZLIB) $(SHAREDLIB) $(SHAREDLIBIMP) - -AR=emxomfar cr -IMPLIB=emximp -RANLIB=echo -TAR=tar -SHELL=bash - -prefix=/usr/local -exec_prefix = $(prefix) - -OBJS = adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o \ - zutil.o inflate.o infblock.o inftrees.o infcodes.o infutil.o inffast.o - -TEST_OBJS = example.o minigzip.o - -DISTFILES = README INDEX ChangeLog configure Make*[a-z0-9] *.[ch] descrip.mms \ - algorithm.txt zlib.3 msdos/Make*[a-z0-9] msdos/zlib.def msdos/zlib.rc \ - nt/Makefile.nt nt/zlib.dnt contrib/README.contrib contrib/*.txt \ - contrib/asm386/*.asm contrib/asm386/*.c \ - contrib/asm386/*.bat contrib/asm386/zlibvc.d?? contrib/iostream/*.cpp \ - contrib/iostream/*.h contrib/iostream2/*.h contrib/iostream2/*.cpp \ - contrib/untgz/Makefile contrib/untgz/*.c contrib/untgz/*.w32 - -all: example.exe minigzip.exe - -test: all - @LD_LIBRARY_PATH=.:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \ - echo hello world | ./minigzip | ./minigzip -d || \ - echo ' *** minigzip test FAILED ***' ; \ - if ./example; then \ - echo ' *** zlib test OK ***'; \ - else \ - echo ' *** zlib test FAILED ***'; \ - fi - -$(ZLIB): $(OBJS) - $(AR) $@ $(OBJS) - -@ ($(RANLIB) $@ || true) >/dev/null 2>&1 - -$(SHAREDLIB): $(OBJS) os2/z.def - $(LDSHARED) -o $@ $^ - -$(SHAREDLIBIMP): os2/z.def - $(IMPLIB) -o $@ $^ - -example.exe: example.o $(LIBS) - $(CC) $(CFLAGS) -o $@ example.o $(LDFLAGS) - -minigzip.exe: minigzip.o $(LIBS) - $(CC) $(CFLAGS) -o $@ minigzip.o $(LDFLAGS) - -clean: - rm -f *.o *~ example minigzip libz.a libz.so* foo.gz - -distclean: clean - -zip: - mv Makefile Makefile~; cp -p Makefile.in Makefile - rm -f test.c ztest*.c - v=`sed -n -e 's/\.//g' -e '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`;\ - zip -ul9 zlib$$v $(DISTFILES) - mv Makefile~ Makefile - -dist: - mv Makefile Makefile~; cp -p Makefile.in Makefile - rm -f test.c ztest*.c - d=zlib-`sed -n '/VERSION "/s/.*"\(.*\)".*/\1/p' < zlib.h`;\ - rm -f $$d.tar.gz; \ - if test ! -d ../$$d; then rm -f ../$$d; ln -s `pwd` ../$$d; fi; \ - files=""; \ - for f in $(DISTFILES); do files="$$files $$d/$$f"; done; \ - cd ..; \ - GZIP=-9 $(TAR) chofz $$d/$$d.tar.gz $$files; \ - if test ! -d $$d; then rm -f $$d; fi - mv Makefile~ Makefile - -tags: - etags *.[ch] - -depend: - makedepend -- $(CFLAGS) -- *.[ch] - -# DO NOT DELETE THIS LINE -- make depend depends on it. - -adler32.o: zlib.h zconf.h -compress.o: zlib.h zconf.h -crc32.o: zlib.h zconf.h -deflate.o: deflate.h zutil.h zlib.h zconf.h -example.o: zlib.h zconf.h -gzio.o: zutil.h zlib.h zconf.h -infblock.o: infblock.h inftrees.h infcodes.h infutil.h zutil.h zlib.h zconf.h -infcodes.o: zutil.h zlib.h zconf.h -infcodes.o: inftrees.h infblock.h infcodes.h infutil.h inffast.h -inffast.o: zutil.h zlib.h zconf.h inftrees.h -inffast.o: infblock.h infcodes.h infutil.h inffast.h -inflate.o: zutil.h zlib.h zconf.h infblock.h -inftrees.o: zutil.h zlib.h zconf.h inftrees.h -infutil.o: zutil.h zlib.h zconf.h infblock.h inftrees.h infcodes.h infutil.h -minigzip.o: zlib.h zconf.h -trees.o: deflate.h zutil.h zlib.h zconf.h trees.h -uncompr.o: zlib.h zconf.h -zutil.o: zutil.h zlib.h zconf.h diff --git a/src/beast/test/zlib/zlib-1.2.8/old/os2/zlib.def b/src/beast/test/zlib/zlib-1.2.8/old/os2/zlib.def deleted file mode 100644 index 4c753f1a3b9..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/old/os2/zlib.def +++ /dev/null @@ -1,51 +0,0 @@ -; -; Slightly modified version of ../nt/zlib.dnt :-) -; - -LIBRARY Z -DESCRIPTION "Zlib compression library for OS/2" -CODE PRELOAD MOVEABLE DISCARDABLE -DATA PRELOAD MOVEABLE MULTIPLE - -EXPORTS - adler32 - compress - crc32 - deflate - deflateCopy - deflateEnd - deflateInit2_ - deflateInit_ - deflateParams - deflateReset - deflateSetDictionary - gzclose - gzdopen - gzerror - gzflush - gzopen - gzread - gzwrite - inflate - inflateEnd - inflateInit2_ - inflateInit_ - inflateReset - inflateSetDictionary - inflateSync - uncompress - zlibVersion - gzprintf - gzputc - gzgetc - gzseek - gzrewind - gztell - gzeof - gzsetparams - zError - inflateSyncPoint - get_crc_table - compress2 - gzputs - gzgets diff --git a/src/beast/test/zlib/zlib-1.2.8/old/visual-basic.txt b/src/beast/test/zlib/zlib-1.2.8/old/visual-basic.txt deleted file mode 100644 index 57efe58124e..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/old/visual-basic.txt +++ /dev/null @@ -1,160 +0,0 @@ -See below some functions declarations for Visual Basic. - -Frequently Asked Question: - -Q: Each time I use the compress function I get the -5 error (not enough - room in the output buffer). - -A: Make sure that the length of the compressed buffer is passed by - reference ("as any"), not by value ("as long"). Also check that - before the call of compress this length is equal to the total size of - the compressed buffer and not zero. - - -From: "Jon Caruana" -Subject: Re: How to port zlib declares to vb? -Date: Mon, 28 Oct 1996 18:33:03 -0600 - -Got the answer! (I haven't had time to check this but it's what I got, and -looks correct): - -He has the following routines working: - compress - uncompress - gzopen - gzwrite - gzread - gzclose - -Declares follow: (Quoted from Carlos Rios , in Vb4 form) - -#If Win16 Then 'Use Win16 calls. -Declare Function compress Lib "ZLIB.DLL" (ByVal compr As - String, comprLen As Any, ByVal buf As String, ByVal buflen - As Long) As Integer -Declare Function uncompress Lib "ZLIB.DLL" (ByVal uncompr - As String, uncomprLen As Any, ByVal compr As String, ByVal - lcompr As Long) As Integer -Declare Function gzopen Lib "ZLIB.DLL" (ByVal filePath As - String, ByVal mode As String) As Long -Declare Function gzread Lib "ZLIB.DLL" (ByVal file As - Long, ByVal uncompr As String, ByVal uncomprLen As Integer) - As Integer -Declare Function gzwrite Lib "ZLIB.DLL" (ByVal file As - Long, ByVal uncompr As String, ByVal uncomprLen As Integer) - As Integer -Declare Function gzclose Lib "ZLIB.DLL" (ByVal file As - Long) As Integer -#Else -Declare Function compress Lib "ZLIB32.DLL" - (ByVal compr As String, comprLen As Any, ByVal buf As - String, ByVal buflen As Long) As Integer -Declare Function uncompress Lib "ZLIB32.DLL" - (ByVal uncompr As String, uncomprLen As Any, ByVal compr As - String, ByVal lcompr As Long) As Long -Declare Function gzopen Lib "ZLIB32.DLL" - (ByVal file As String, ByVal mode As String) As Long -Declare Function gzread Lib "ZLIB32.DLL" - (ByVal file As Long, ByVal uncompr As String, ByVal - uncomprLen As Long) As Long -Declare Function gzwrite Lib "ZLIB32.DLL" - (ByVal file As Long, ByVal uncompr As String, ByVal - uncomprLen As Long) As Long -Declare Function gzclose Lib "ZLIB32.DLL" - (ByVal file As Long) As Long -#End If - --Jon Caruana -jon-net@usa.net -Microsoft Sitebuilder Network Level 1 Member - HTML Writer's Guild Member - - -Here is another example from Michael that he -says conforms to the VB guidelines, and that solves the problem of not -knowing the uncompressed size by storing it at the end of the file: - -'Calling the functions: -'bracket meaning: [optional] {Range of possible values} -'Call subCompressFile( [, , [level of compression {1..9}]]) -'Call subUncompressFile() - -Option Explicit -Private lngpvtPcnSml As Long 'Stores value for 'lngPercentSmaller' -Private Const SUCCESS As Long = 0 -Private Const strFilExt As String = ".cpr" -Private Declare Function lngfncCpr Lib "zlib.dll" Alias "compress2" (ByRef -dest As Any, ByRef destLen As Any, ByRef src As Any, ByVal srcLen As Long, -ByVal level As Integer) As Long -Private Declare Function lngfncUcp Lib "zlib.dll" Alias "uncompress" (ByRef -dest As Any, ByRef destLen As Any, ByRef src As Any, ByVal srcLen As Long) -As Long - -Public Sub subCompressFile(ByVal strargOriFilPth As String, Optional ByVal -strargCprFilPth As String, Optional ByVal intLvl As Integer = 9) - Dim strCprPth As String - Dim lngOriSiz As Long - Dim lngCprSiz As Long - Dim bytaryOri() As Byte - Dim bytaryCpr() As Byte - lngOriSiz = FileLen(strargOriFilPth) - ReDim bytaryOri(lngOriSiz - 1) - Open strargOriFilPth For Binary Access Read As #1 - Get #1, , bytaryOri() - Close #1 - strCprPth = IIf(strargCprFilPth = "", strargOriFilPth, strargCprFilPth) -'Select file path and name - strCprPth = strCprPth & IIf(Right(strCprPth, Len(strFilExt)) = -strFilExt, "", strFilExt) 'Add file extension if not exists - lngCprSiz = (lngOriSiz * 1.01) + 12 'Compression needs temporary a bit -more space then original file size - ReDim bytaryCpr(lngCprSiz - 1) - If lngfncCpr(bytaryCpr(0), lngCprSiz, bytaryOri(0), lngOriSiz, intLvl) = -SUCCESS Then - lngpvtPcnSml = (1# - (lngCprSiz / lngOriSiz)) * 100 - ReDim Preserve bytaryCpr(lngCprSiz - 1) - Open strCprPth For Binary Access Write As #1 - Put #1, , bytaryCpr() - Put #1, , lngOriSiz 'Add the the original size value to the end -(last 4 bytes) - Close #1 - Else - MsgBox "Compression error" - End If - Erase bytaryCpr - Erase bytaryOri -End Sub - -Public Sub subUncompressFile(ByVal strargFilPth As String) - Dim bytaryCpr() As Byte - Dim bytaryOri() As Byte - Dim lngOriSiz As Long - Dim lngCprSiz As Long - Dim strOriPth As String - lngCprSiz = FileLen(strargFilPth) - ReDim bytaryCpr(lngCprSiz - 1) - Open strargFilPth For Binary Access Read As #1 - Get #1, , bytaryCpr() - Close #1 - 'Read the original file size value: - lngOriSiz = bytaryCpr(lngCprSiz - 1) * (2 ^ 24) _ - + bytaryCpr(lngCprSiz - 2) * (2 ^ 16) _ - + bytaryCpr(lngCprSiz - 3) * (2 ^ 8) _ - + bytaryCpr(lngCprSiz - 4) - ReDim Preserve bytaryCpr(lngCprSiz - 5) 'Cut of the original size value - ReDim bytaryOri(lngOriSiz - 1) - If lngfncUcp(bytaryOri(0), lngOriSiz, bytaryCpr(0), lngCprSiz) = SUCCESS -Then - strOriPth = Left(strargFilPth, Len(strargFilPth) - Len(strFilExt)) - Open strOriPth For Binary Access Write As #1 - Put #1, , bytaryOri() - Close #1 - Else - MsgBox "Uncompression error" - End If - Erase bytaryCpr - Erase bytaryOri -End Sub -Public Property Get lngPercentSmaller() As Long - lngPercentSmaller = lngpvtPcnSml -End Property diff --git a/src/beast/test/zlib/zlib-1.2.8/qnx/package.qpg b/src/beast/test/zlib/zlib-1.2.8/qnx/package.qpg deleted file mode 100644 index aebf6e3ac12..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/qnx/package.qpg +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Library - - Medium - - 2.0 - - - - zlib - zlib - alain.bonnefoy@icbt.com - Public - public - www.gzip.org/zlib - - - Jean-Loup Gailly,Mark Adler - www.gzip.org/zlib - - zlib@gzip.org - - - A massively spiffy yet delicately unobtrusive compression library. - zlib is designed to be a free, general-purpose, legally unencumbered, lossless data compression library for use on virtually any computer hardware and operating system. - http://www.gzip.org/zlib - - - - - 1.2.8 - Medium - Stable - - - - - - - No License - - - - Software Development/Libraries and Extensions/C Libraries - zlib,compression - qnx6 - qnx6 - None - Developer - - - - - - - - - - - - - - Install - Post - No - Ignore - - No - Optional - - - - - - - - - - - - - InstallOver - zlib - - - - - - - - - - - - - InstallOver - zlib-dev - - - - - - - - - diff --git a/src/beast/test/zlib/zlib-1.2.8/test/example.c b/src/beast/test/zlib/zlib-1.2.8/test/example.c deleted file mode 100644 index 138a699bd53..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/test/example.c +++ /dev/null @@ -1,601 +0,0 @@ -/* example.c -- usage example of the zlib compression library - * Copyright (C) 1995-2006, 2011 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id$ */ - -#include "zlib.h" -#include - -#ifdef STDC -# include -# include -#endif - -#if defined(VMS) || defined(RISCOS) -# define TESTFILE "foo-gz" -#else -# define TESTFILE "foo.gz" -#endif - -#define CHECK_ERR(err, msg) { \ - if (err != Z_OK) { \ - fprintf(stderr, "%s error: %d\n", msg, err); \ - exit(1); \ - } \ -} - -z_const char hello[] = "hello, hello!"; -/* "hello world" would be more standard, but the repeated "hello" - * stresses the compression code better, sorry... - */ - -const char dictionary[] = "hello"; -uLong dictId; /* Adler32 value of the dictionary */ - -void test_deflate OF((Byte *compr, uLong comprLen)); -void test_inflate OF((Byte *compr, uLong comprLen, - Byte *uncompr, uLong uncomprLen)); -void test_large_deflate OF((Byte *compr, uLong comprLen, - Byte *uncompr, uLong uncomprLen)); -void test_large_inflate OF((Byte *compr, uLong comprLen, - Byte *uncompr, uLong uncomprLen)); -void test_flush OF((Byte *compr, uLong *comprLen)); -void test_sync OF((Byte *compr, uLong comprLen, - Byte *uncompr, uLong uncomprLen)); -void test_dict_deflate OF((Byte *compr, uLong comprLen)); -void test_dict_inflate OF((Byte *compr, uLong comprLen, - Byte *uncompr, uLong uncomprLen)); -int main OF((int argc, char *argv[])); - - -#ifdef Z_SOLO - -void *myalloc OF((void *, unsigned, unsigned)); -void myfree OF((void *, void *)); - -void *myalloc(q, n, m) - void *q; - unsigned n, m; -{ - q = Z_NULL; - return calloc(n, m); -} - -void myfree(void *q, void *p) -{ - q = Z_NULL; - free(p); -} - -static alloc_func zalloc = myalloc; -static free_func zfree = myfree; - -#else /* !Z_SOLO */ - -static alloc_func zalloc = (alloc_func)0; -static free_func zfree = (free_func)0; - -void test_compress OF((Byte *compr, uLong comprLen, - Byte *uncompr, uLong uncomprLen)); -void test_gzio OF((const char *fname, - Byte *uncompr, uLong uncomprLen)); - -/* =========================================================================== - * Test compress() and uncompress() - */ -void test_compress(compr, comprLen, uncompr, uncomprLen) - Byte *compr, *uncompr; - uLong comprLen, uncomprLen; -{ - int err; - uLong len = (uLong)strlen(hello)+1; - - err = compress(compr, &comprLen, (const Bytef*)hello, len); - CHECK_ERR(err, "compress"); - - strcpy((char*)uncompr, "garbage"); - - err = uncompress(uncompr, &uncomprLen, compr, comprLen); - CHECK_ERR(err, "uncompress"); - - if (strcmp((char*)uncompr, hello)) { - fprintf(stderr, "bad uncompress\n"); - exit(1); - } else { - printf("uncompress(): %s\n", (char *)uncompr); - } -} - -/* =========================================================================== - * Test read/write of .gz files - */ -void test_gzio(fname, uncompr, uncomprLen) - const char *fname; /* compressed file name */ - Byte *uncompr; - uLong uncomprLen; -{ -#ifdef NO_GZCOMPRESS - fprintf(stderr, "NO_GZCOMPRESS -- gz* functions cannot compress\n"); -#else - int err; - int len = (int)strlen(hello)+1; - gzFile file; - z_off_t pos; - - file = gzopen(fname, "wb"); - if (file == NULL) { - fprintf(stderr, "gzopen error\n"); - exit(1); - } - gzputc(file, 'h'); - if (gzputs(file, "ello") != 4) { - fprintf(stderr, "gzputs err: %s\n", gzerror(file, &err)); - exit(1); - } - if (gzprintf(file, ", %s!", "hello") != 8) { - fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err)); - exit(1); - } - gzseek(file, 1L, SEEK_CUR); /* add one zero byte */ - gzclose(file); - - file = gzopen(fname, "rb"); - if (file == NULL) { - fprintf(stderr, "gzopen error\n"); - exit(1); - } - strcpy((char*)uncompr, "garbage"); - - if (gzread(file, uncompr, (unsigned)uncomprLen) != len) { - fprintf(stderr, "gzread err: %s\n", gzerror(file, &err)); - exit(1); - } - if (strcmp((char*)uncompr, hello)) { - fprintf(stderr, "bad gzread: %s\n", (char*)uncompr); - exit(1); - } else { - printf("gzread(): %s\n", (char*)uncompr); - } - - pos = gzseek(file, -8L, SEEK_CUR); - if (pos != 6 || gztell(file) != pos) { - fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n", - (long)pos, (long)gztell(file)); - exit(1); - } - - if (gzgetc(file) != ' ') { - fprintf(stderr, "gzgetc error\n"); - exit(1); - } - - if (gzungetc(' ', file) != ' ') { - fprintf(stderr, "gzungetc error\n"); - exit(1); - } - - gzgets(file, (char*)uncompr, (int)uncomprLen); - if (strlen((char*)uncompr) != 7) { /* " hello!" */ - fprintf(stderr, "gzgets err after gzseek: %s\n", gzerror(file, &err)); - exit(1); - } - if (strcmp((char*)uncompr, hello + 6)) { - fprintf(stderr, "bad gzgets after gzseek\n"); - exit(1); - } else { - printf("gzgets() after gzseek: %s\n", (char*)uncompr); - } - - gzclose(file); -#endif -} - -#endif /* Z_SOLO */ - -/* =========================================================================== - * Test deflate() with small buffers - */ -void test_deflate(compr, comprLen) - Byte *compr; - uLong comprLen; -{ - z_stream c_stream; /* compression stream */ - int err; - uLong len = (uLong)strlen(hello)+1; - - c_stream.zalloc = zalloc; - c_stream.zfree = zfree; - c_stream.opaque = (voidpf)0; - - err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION); - CHECK_ERR(err, "deflateInit"); - - c_stream.next_in = (z_const unsigned char *)hello; - c_stream.next_out = compr; - - while (c_stream.total_in != len && c_stream.total_out < comprLen) { - c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */ - err = deflate(&c_stream, Z_NO_FLUSH); - CHECK_ERR(err, "deflate"); - } - /* Finish the stream, still forcing small buffers: */ - for (;;) { - c_stream.avail_out = 1; - err = deflate(&c_stream, Z_FINISH); - if (err == Z_STREAM_END) break; - CHECK_ERR(err, "deflate"); - } - - err = deflateEnd(&c_stream); - CHECK_ERR(err, "deflateEnd"); -} - -/* =========================================================================== - * Test inflate() with small buffers - */ -void test_inflate(compr, comprLen, uncompr, uncomprLen) - Byte *compr, *uncompr; - uLong comprLen, uncomprLen; -{ - int err; - z_stream d_stream; /* decompression stream */ - - strcpy((char*)uncompr, "garbage"); - - d_stream.zalloc = zalloc; - d_stream.zfree = zfree; - d_stream.opaque = (voidpf)0; - - d_stream.next_in = compr; - d_stream.avail_in = 0; - d_stream.next_out = uncompr; - - err = inflateInit(&d_stream); - CHECK_ERR(err, "inflateInit"); - - while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen) { - d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */ - err = inflate(&d_stream, Z_NO_FLUSH); - if (err == Z_STREAM_END) break; - CHECK_ERR(err, "inflate"); - } - - err = inflateEnd(&d_stream); - CHECK_ERR(err, "inflateEnd"); - - if (strcmp((char*)uncompr, hello)) { - fprintf(stderr, "bad inflate\n"); - exit(1); - } else { - printf("inflate(): %s\n", (char *)uncompr); - } -} - -/* =========================================================================== - * Test deflate() with large buffers and dynamic change of compression level - */ -void test_large_deflate(compr, comprLen, uncompr, uncomprLen) - Byte *compr, *uncompr; - uLong comprLen, uncomprLen; -{ - z_stream c_stream; /* compression stream */ - int err; - - c_stream.zalloc = zalloc; - c_stream.zfree = zfree; - c_stream.opaque = (voidpf)0; - - err = deflateInit(&c_stream, Z_BEST_SPEED); - CHECK_ERR(err, "deflateInit"); - - c_stream.next_out = compr; - c_stream.avail_out = (uInt)comprLen; - - /* At this point, uncompr is still mostly zeroes, so it should compress - * very well: - */ - c_stream.next_in = uncompr; - c_stream.avail_in = (uInt)uncomprLen; - err = deflate(&c_stream, Z_NO_FLUSH); - CHECK_ERR(err, "deflate"); - if (c_stream.avail_in != 0) { - fprintf(stderr, "deflate not greedy\n"); - exit(1); - } - - /* Feed in already compressed data and switch to no compression: */ - deflateParams(&c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY); - c_stream.next_in = compr; - c_stream.avail_in = (uInt)comprLen/2; - err = deflate(&c_stream, Z_NO_FLUSH); - CHECK_ERR(err, "deflate"); - - /* Switch back to compressing mode: */ - deflateParams(&c_stream, Z_BEST_COMPRESSION, Z_FILTERED); - c_stream.next_in = uncompr; - c_stream.avail_in = (uInt)uncomprLen; - err = deflate(&c_stream, Z_NO_FLUSH); - CHECK_ERR(err, "deflate"); - - err = deflate(&c_stream, Z_FINISH); - if (err != Z_STREAM_END) { - fprintf(stderr, "deflate should report Z_STREAM_END\n"); - exit(1); - } - err = deflateEnd(&c_stream); - CHECK_ERR(err, "deflateEnd"); -} - -/* =========================================================================== - * Test inflate() with large buffers - */ -void test_large_inflate(compr, comprLen, uncompr, uncomprLen) - Byte *compr, *uncompr; - uLong comprLen, uncomprLen; -{ - int err; - z_stream d_stream; /* decompression stream */ - - strcpy((char*)uncompr, "garbage"); - - d_stream.zalloc = zalloc; - d_stream.zfree = zfree; - d_stream.opaque = (voidpf)0; - - d_stream.next_in = compr; - d_stream.avail_in = (uInt)comprLen; - - err = inflateInit(&d_stream); - CHECK_ERR(err, "inflateInit"); - - for (;;) { - d_stream.next_out = uncompr; /* discard the output */ - d_stream.avail_out = (uInt)uncomprLen; - err = inflate(&d_stream, Z_NO_FLUSH); - if (err == Z_STREAM_END) break; - CHECK_ERR(err, "large inflate"); - } - - err = inflateEnd(&d_stream); - CHECK_ERR(err, "inflateEnd"); - - if (d_stream.total_out != 2*uncomprLen + comprLen/2) { - fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out); - exit(1); - } else { - printf("large_inflate(): OK\n"); - } -} - -/* =========================================================================== - * Test deflate() with full flush - */ -void test_flush(compr, comprLen) - Byte *compr; - uLong *comprLen; -{ - z_stream c_stream; /* compression stream */ - int err; - uInt len = (uInt)strlen(hello)+1; - - c_stream.zalloc = zalloc; - c_stream.zfree = zfree; - c_stream.opaque = (voidpf)0; - - err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION); - CHECK_ERR(err, "deflateInit"); - - c_stream.next_in = (z_const unsigned char *)hello; - c_stream.next_out = compr; - c_stream.avail_in = 3; - c_stream.avail_out = (uInt)*comprLen; - err = deflate(&c_stream, Z_FULL_FLUSH); - CHECK_ERR(err, "deflate"); - - compr[3]++; /* force an error in first compressed block */ - c_stream.avail_in = len - 3; - - err = deflate(&c_stream, Z_FINISH); - if (err != Z_STREAM_END) { - CHECK_ERR(err, "deflate"); - } - err = deflateEnd(&c_stream); - CHECK_ERR(err, "deflateEnd"); - - *comprLen = c_stream.total_out; -} - -/* =========================================================================== - * Test inflateSync() - */ -void test_sync(compr, comprLen, uncompr, uncomprLen) - Byte *compr, *uncompr; - uLong comprLen, uncomprLen; -{ - int err; - z_stream d_stream; /* decompression stream */ - - strcpy((char*)uncompr, "garbage"); - - d_stream.zalloc = zalloc; - d_stream.zfree = zfree; - d_stream.opaque = (voidpf)0; - - d_stream.next_in = compr; - d_stream.avail_in = 2; /* just read the zlib header */ - - err = inflateInit(&d_stream); - CHECK_ERR(err, "inflateInit"); - - d_stream.next_out = uncompr; - d_stream.avail_out = (uInt)uncomprLen; - - inflate(&d_stream, Z_NO_FLUSH); - CHECK_ERR(err, "inflate"); - - d_stream.avail_in = (uInt)comprLen-2; /* read all compressed data */ - err = inflateSync(&d_stream); /* but skip the damaged part */ - CHECK_ERR(err, "inflateSync"); - - err = inflate(&d_stream, Z_FINISH); - if (err != Z_DATA_ERROR) { - fprintf(stderr, "inflate should report DATA_ERROR\n"); - /* Because of incorrect adler32 */ - exit(1); - } - err = inflateEnd(&d_stream); - CHECK_ERR(err, "inflateEnd"); - - printf("after inflateSync(): hel%s\n", (char *)uncompr); -} - -/* =========================================================================== - * Test deflate() with preset dictionary - */ -void test_dict_deflate(compr, comprLen) - Byte *compr; - uLong comprLen; -{ - z_stream c_stream; /* compression stream */ - int err; - - c_stream.zalloc = zalloc; - c_stream.zfree = zfree; - c_stream.opaque = (voidpf)0; - - err = deflateInit(&c_stream, Z_BEST_COMPRESSION); - CHECK_ERR(err, "deflateInit"); - - err = deflateSetDictionary(&c_stream, - (const Bytef*)dictionary, (int)sizeof(dictionary)); - CHECK_ERR(err, "deflateSetDictionary"); - - dictId = c_stream.adler; - c_stream.next_out = compr; - c_stream.avail_out = (uInt)comprLen; - - c_stream.next_in = (z_const unsigned char *)hello; - c_stream.avail_in = (uInt)strlen(hello)+1; - - err = deflate(&c_stream, Z_FINISH); - if (err != Z_STREAM_END) { - fprintf(stderr, "deflate should report Z_STREAM_END\n"); - exit(1); - } - err = deflateEnd(&c_stream); - CHECK_ERR(err, "deflateEnd"); -} - -/* =========================================================================== - * Test inflate() with a preset dictionary - */ -void test_dict_inflate(compr, comprLen, uncompr, uncomprLen) - Byte *compr, *uncompr; - uLong comprLen, uncomprLen; -{ - int err; - z_stream d_stream; /* decompression stream */ - - strcpy((char*)uncompr, "garbage"); - - d_stream.zalloc = zalloc; - d_stream.zfree = zfree; - d_stream.opaque = (voidpf)0; - - d_stream.next_in = compr; - d_stream.avail_in = (uInt)comprLen; - - err = inflateInit(&d_stream); - CHECK_ERR(err, "inflateInit"); - - d_stream.next_out = uncompr; - d_stream.avail_out = (uInt)uncomprLen; - - for (;;) { - err = inflate(&d_stream, Z_NO_FLUSH); - if (err == Z_STREAM_END) break; - if (err == Z_NEED_DICT) { - if (d_stream.adler != dictId) { - fprintf(stderr, "unexpected dictionary"); - exit(1); - } - err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary, - (int)sizeof(dictionary)); - } - CHECK_ERR(err, "inflate with dict"); - } - - err = inflateEnd(&d_stream); - CHECK_ERR(err, "inflateEnd"); - - if (strcmp((char*)uncompr, hello)) { - fprintf(stderr, "bad inflate with dict\n"); - exit(1); - } else { - printf("inflate with dictionary: %s\n", (char *)uncompr); - } -} - -/* =========================================================================== - * Usage: example [output.gz [input.gz]] - */ - -int main(argc, argv) - int argc; - char *argv[]; -{ - Byte *compr, *uncompr; - uLong comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */ - uLong uncomprLen = comprLen; - static const char* myVersion = ZLIB_VERSION; - - if (zlibVersion()[0] != myVersion[0]) { - fprintf(stderr, "incompatible zlib version\n"); - exit(1); - - } else if (strcmp(zlibVersion(), ZLIB_VERSION) != 0) { - fprintf(stderr, "warning: different zlib version\n"); - } - - printf("zlib version %s = 0x%04x, compile flags = 0x%lx\n", - ZLIB_VERSION, ZLIB_VERNUM, zlibCompileFlags()); - - compr = (Byte*)calloc((uInt)comprLen, 1); - uncompr = (Byte*)calloc((uInt)uncomprLen, 1); - /* compr and uncompr are cleared to avoid reading uninitialized - * data and to ensure that uncompr compresses well. - */ - if (compr == Z_NULL || uncompr == Z_NULL) { - printf("out of memory\n"); - exit(1); - } - -#ifdef Z_SOLO - argc = strlen(argv[0]); -#else - test_compress(compr, comprLen, uncompr, uncomprLen); - - test_gzio((argc > 1 ? argv[1] : TESTFILE), - uncompr, uncomprLen); -#endif - - test_deflate(compr, comprLen); - test_inflate(compr, comprLen, uncompr, uncomprLen); - - test_large_deflate(compr, comprLen, uncompr, uncomprLen); - test_large_inflate(compr, comprLen, uncompr, uncomprLen); - - test_flush(compr, &comprLen); - test_sync(compr, comprLen, uncompr, uncomprLen); - comprLen = uncomprLen; - - test_dict_deflate(compr, comprLen); - test_dict_inflate(compr, comprLen, uncompr, uncomprLen); - - free(compr); - free(uncompr); - - return 0; -} diff --git a/src/beast/test/zlib/zlib-1.2.8/test/infcover.c b/src/beast/test/zlib/zlib-1.2.8/test/infcover.c deleted file mode 100644 index fe3d9203a02..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/test/infcover.c +++ /dev/null @@ -1,671 +0,0 @@ -/* infcover.c -- test zlib's inflate routines with full code coverage - * Copyright (C) 2011 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* to use, do: ./configure --cover && make cover */ - -#include -#include -#include -#include -#include "zlib.h" - -/* get definition of internal structure so we can mess with it (see pull()), - and so we can call inflate_trees() (see cover5()) */ -#define ZLIB_INTERNAL -#include "inftrees.h" -#include "inflate.h" - -#define local static - -/* -- memory tracking routines -- */ - -/* - These memory tracking routines are provided to zlib and track all of zlib's - allocations and deallocations, check for LIFO operations, keep a current - and high water mark of total bytes requested, optionally set a limit on the - total memory that can be allocated, and when done check for memory leaks. - - They are used as follows: - - z_stream strm; - mem_setup(&strm) initializes the memory tracking and sets the - zalloc, zfree, and opaque members of strm to use - memory tracking for all zlib operations on strm - mem_limit(&strm, limit) sets a limit on the total bytes requested -- a - request that exceeds this limit will result in an - allocation failure (returns NULL) -- setting the - limit to zero means no limit, which is the default - after mem_setup() - mem_used(&strm, "msg") prints to stderr "msg" and the total bytes used - mem_high(&strm, "msg") prints to stderr "msg" and the high water mark - mem_done(&strm, "msg") ends memory tracking, releases all allocations - for the tracking as well as leaked zlib blocks, if - any. If there was anything unusual, such as leaked - blocks, non-FIFO frees, or frees of addresses not - allocated, then "msg" and information about the - problem is printed to stderr. If everything is - normal, nothing is printed. mem_done resets the - strm members to Z_NULL to use the default memory - allocation routines on the next zlib initialization - using strm. - */ - -/* these items are strung together in a linked list, one for each allocation */ -struct mem_item { - void *ptr; /* pointer to allocated memory */ - size_t size; /* requested size of allocation */ - struct mem_item *next; /* pointer to next item in list, or NULL */ -}; - -/* this structure is at the root of the linked list, and tracks statistics */ -struct mem_zone { - struct mem_item *first; /* pointer to first item in list, or NULL */ - size_t total, highwater; /* total allocations, and largest total */ - size_t limit; /* memory allocation limit, or 0 if no limit */ - int notlifo, rogue; /* counts of non-LIFO frees and rogue frees */ -}; - -/* memory allocation routine to pass to zlib */ -local void *mem_alloc(void *mem, unsigned count, unsigned size) -{ - void *ptr; - struct mem_item *item; - struct mem_zone *zone = mem; - size_t len = count * (size_t)size; - - /* induced allocation failure */ - if (zone == NULL || (zone->limit && zone->total + len > zone->limit)) - return NULL; - - /* perform allocation using the standard library, fill memory with a - non-zero value to make sure that the code isn't depending on zeros */ - ptr = malloc(len); - if (ptr == NULL) - return NULL; - memset(ptr, 0xa5, len); - - /* create a new item for the list */ - item = malloc(sizeof(struct mem_item)); - if (item == NULL) { - free(ptr); - return NULL; - } - item->ptr = ptr; - item->size = len; - - /* insert item at the beginning of the list */ - item->next = zone->first; - zone->first = item; - - /* update the statistics */ - zone->total += item->size; - if (zone->total > zone->highwater) - zone->highwater = zone->total; - - /* return the allocated memory */ - return ptr; -} - -/* memory free routine to pass to zlib */ -local void mem_free(void *mem, void *ptr) -{ - struct mem_item *item, *next; - struct mem_zone *zone = mem; - - /* if no zone, just do a free */ - if (zone == NULL) { - free(ptr); - return; - } - - /* point next to the item that matches ptr, or NULL if not found -- remove - the item from the linked list if found */ - next = zone->first; - if (next) { - if (next->ptr == ptr) - zone->first = next->next; /* first one is it, remove from list */ - else { - do { /* search the linked list */ - item = next; - next = item->next; - } while (next != NULL && next->ptr != ptr); - if (next) { /* if found, remove from linked list */ - item->next = next->next; - zone->notlifo++; /* not a LIFO free */ - } - - } - } - - /* if found, update the statistics and free the item */ - if (next) { - zone->total -= next->size; - free(next); - } - - /* if not found, update the rogue count */ - else - zone->rogue++; - - /* in any case, do the requested free with the standard library function */ - free(ptr); -} - -/* set up a controlled memory allocation space for monitoring, set the stream - parameters to the controlled routines, with opaque pointing to the space */ -local void mem_setup(z_stream *strm) -{ - struct mem_zone *zone; - - zone = malloc(sizeof(struct mem_zone)); - assert(zone != NULL); - zone->first = NULL; - zone->total = 0; - zone->highwater = 0; - zone->limit = 0; - zone->notlifo = 0; - zone->rogue = 0; - strm->opaque = zone; - strm->zalloc = mem_alloc; - strm->zfree = mem_free; -} - -/* set a limit on the total memory allocation, or 0 to remove the limit */ -local void mem_limit(z_stream *strm, size_t limit) -{ - struct mem_zone *zone = strm->opaque; - - zone->limit = limit; -} - -/* show the current total requested allocations in bytes */ -local void mem_used(z_stream *strm, char *prefix) -{ - struct mem_zone *zone = strm->opaque; - - fprintf(stderr, "%s: %lu allocated\n", prefix, zone->total); -} - -/* show the high water allocation in bytes */ -local void mem_high(z_stream *strm, char *prefix) -{ - struct mem_zone *zone = strm->opaque; - - fprintf(stderr, "%s: %lu high water mark\n", prefix, zone->highwater); -} - -/* release the memory allocation zone -- if there are any surprises, notify */ -local void mem_done(z_stream *strm, char *prefix) -{ - int count = 0; - struct mem_item *item, *next; - struct mem_zone *zone = strm->opaque; - - /* show high water mark */ - mem_high(strm, prefix); - - /* free leftover allocations and item structures, if any */ - item = zone->first; - while (item != NULL) { - free(item->ptr); - next = item->next; - free(item); - item = next; - count++; - } - - /* issue alerts about anything unexpected */ - if (count || zone->total) - fprintf(stderr, "** %s: %lu bytes in %d blocks not freed\n", - prefix, zone->total, count); - if (zone->notlifo) - fprintf(stderr, "** %s: %d frees not LIFO\n", prefix, zone->notlifo); - if (zone->rogue) - fprintf(stderr, "** %s: %d frees not recognized\n", - prefix, zone->rogue); - - /* free the zone and delete from the stream */ - free(zone); - strm->opaque = Z_NULL; - strm->zalloc = Z_NULL; - strm->zfree = Z_NULL; -} - -/* -- inflate test routines -- */ - -/* Decode a hexadecimal string, set *len to length, in[] to the bytes. This - decodes liberally, in that hex digits can be adjacent, in which case two in - a row writes a byte. Or they can delimited by any non-hex character, where - the delimiters are ignored except when a single hex digit is followed by a - delimiter in which case that single digit writes a byte. The returned - data is allocated and must eventually be freed. NULL is returned if out of - memory. If the length is not needed, then len can be NULL. */ -local unsigned char *h2b(const char *hex, unsigned *len) -{ - unsigned char *in; - unsigned next, val; - - in = malloc((strlen(hex) + 1) >> 1); - if (in == NULL) - return NULL; - next = 0; - val = 1; - do { - if (*hex >= '0' && *hex <= '9') - val = (val << 4) + *hex - '0'; - else if (*hex >= 'A' && *hex <= 'F') - val = (val << 4) + *hex - 'A' + 10; - else if (*hex >= 'a' && *hex <= 'f') - val = (val << 4) + *hex - 'a' + 10; - else if (val != 1 && val < 32) /* one digit followed by delimiter */ - val += 240; /* make it look like two digits */ - if (val > 255) { /* have two digits */ - in[next++] = val & 0xff; /* save the decoded byte */ - val = 1; /* start over */ - } - } while (*hex++); /* go through the loop with the terminating null */ - if (len != NULL) - *len = next; - in = reallocf(in, next); - return in; -} - -/* generic inflate() run, where hex is the hexadecimal input data, what is the - text to include in an error message, step is how much input data to feed - inflate() on each call, or zero to feed it all, win is the window bits - parameter to inflateInit2(), len is the size of the output buffer, and err - is the error code expected from the first inflate() call (the second - inflate() call is expected to return Z_STREAM_END). If win is 47, then - header information is collected with inflateGetHeader(). If a zlib stream - is looking for a dictionary, then an empty dictionary is provided. - inflate() is run until all of the input data is consumed. */ -local void inf(char *hex, char *what, unsigned step, int win, unsigned len, - int err) -{ - int ret; - unsigned have; - unsigned char *in, *out; - z_stream strm, copy; - gz_header head; - - mem_setup(&strm); - strm.avail_in = 0; - strm.next_in = Z_NULL; - ret = inflateInit2(&strm, win); - if (ret != Z_OK) { - mem_done(&strm, what); - return; - } - out = malloc(len); assert(out != NULL); - if (win == 47) { - head.extra = out; - head.extra_max = len; - head.name = out; - head.name_max = len; - head.comment = out; - head.comm_max = len; - ret = inflateGetHeader(&strm, &head); assert(ret == Z_OK); - } - in = h2b(hex, &have); assert(in != NULL); - if (step == 0 || step > have) - step = have; - strm.avail_in = step; - have -= step; - strm.next_in = in; - do { - strm.avail_out = len; - strm.next_out = out; - ret = inflate(&strm, Z_NO_FLUSH); assert(err == 9 || ret == err); - if (ret != Z_OK && ret != Z_BUF_ERROR && ret != Z_NEED_DICT) - break; - if (ret == Z_NEED_DICT) { - ret = inflateSetDictionary(&strm, in, 1); - assert(ret == Z_DATA_ERROR); - mem_limit(&strm, 1); - ret = inflateSetDictionary(&strm, out, 0); - assert(ret == Z_MEM_ERROR); - mem_limit(&strm, 0); - ((struct inflate_state *)strm.state)->mode = DICT; - ret = inflateSetDictionary(&strm, out, 0); - assert(ret == Z_OK); - ret = inflate(&strm, Z_NO_FLUSH); assert(ret == Z_BUF_ERROR); - } - ret = inflateCopy(©, &strm); assert(ret == Z_OK); - ret = inflateEnd(©); assert(ret == Z_OK); - err = 9; /* don't care next time around */ - have += strm.avail_in; - strm.avail_in = step > have ? have : step; - have -= strm.avail_in; - } while (strm.avail_in); - free(in); - free(out); - ret = inflateReset2(&strm, -8); assert(ret == Z_OK); - ret = inflateEnd(&strm); assert(ret == Z_OK); - mem_done(&strm, what); -} - -/* cover all of the lines in inflate.c up to inflate() */ -local void cover_support(void) -{ - int ret; - z_stream strm; - - mem_setup(&strm); - strm.avail_in = 0; - strm.next_in = Z_NULL; - ret = inflateInit(&strm); assert(ret == Z_OK); - mem_used(&strm, "inflate init"); - ret = inflatePrime(&strm, 5, 31); assert(ret == Z_OK); - ret = inflatePrime(&strm, -1, 0); assert(ret == Z_OK); - ret = inflateSetDictionary(&strm, Z_NULL, 0); - assert(ret == Z_STREAM_ERROR); - ret = inflateEnd(&strm); assert(ret == Z_OK); - mem_done(&strm, "prime"); - - inf("63 0", "force window allocation", 0, -15, 1, Z_OK); - inf("63 18 5", "force window replacement", 0, -8, 259, Z_OK); - inf("63 18 68 30 d0 0 0", "force split window update", 4, -8, 259, Z_OK); - inf("3 0", "use fixed blocks", 0, -15, 1, Z_STREAM_END); - inf("", "bad window size", 0, 1, 0, Z_STREAM_ERROR); - - mem_setup(&strm); - strm.avail_in = 0; - strm.next_in = Z_NULL; - ret = inflateInit_(&strm, ZLIB_VERSION - 1, (int)sizeof(z_stream)); - assert(ret == Z_VERSION_ERROR); - mem_done(&strm, "wrong version"); - - strm.avail_in = 0; - strm.next_in = Z_NULL; - ret = inflateInit(&strm); assert(ret == Z_OK); - ret = inflateEnd(&strm); assert(ret == Z_OK); - fputs("inflate built-in memory routines\n", stderr); -} - -/* cover all inflate() header and trailer cases and code after inflate() */ -local void cover_wrap(void) -{ - int ret; - z_stream strm, copy; - unsigned char dict[257]; - - ret = inflate(Z_NULL, 0); assert(ret == Z_STREAM_ERROR); - ret = inflateEnd(Z_NULL); assert(ret == Z_STREAM_ERROR); - ret = inflateCopy(Z_NULL, Z_NULL); assert(ret == Z_STREAM_ERROR); - fputs("inflate bad parameters\n", stderr); - - inf("1f 8b 0 0", "bad gzip method", 0, 31, 0, Z_DATA_ERROR); - inf("1f 8b 8 80", "bad gzip flags", 0, 31, 0, Z_DATA_ERROR); - inf("77 85", "bad zlib method", 0, 15, 0, Z_DATA_ERROR); - inf("8 99", "set window size from header", 0, 0, 0, Z_OK); - inf("78 9c", "bad zlib window size", 0, 8, 0, Z_DATA_ERROR); - inf("78 9c 63 0 0 0 1 0 1", "check adler32", 0, 15, 1, Z_STREAM_END); - inf("1f 8b 8 1e 0 0 0 0 0 0 1 0 0 0 0 0 0", "bad header crc", 0, 47, 1, - Z_DATA_ERROR); - inf("1f 8b 8 2 0 0 0 0 0 0 1d 26 3 0 0 0 0 0 0 0 0 0", "check gzip length", - 0, 47, 0, Z_STREAM_END); - inf("78 90", "bad zlib header check", 0, 47, 0, Z_DATA_ERROR); - inf("8 b8 0 0 0 1", "need dictionary", 0, 8, 0, Z_NEED_DICT); - inf("78 9c 63 0", "compute adler32", 0, 15, 1, Z_OK); - - mem_setup(&strm); - strm.avail_in = 0; - strm.next_in = Z_NULL; - ret = inflateInit2(&strm, -8); - strm.avail_in = 2; - strm.next_in = (void *)"\x63"; - strm.avail_out = 1; - strm.next_out = (void *)&ret; - mem_limit(&strm, 1); - ret = inflate(&strm, Z_NO_FLUSH); assert(ret == Z_MEM_ERROR); - ret = inflate(&strm, Z_NO_FLUSH); assert(ret == Z_MEM_ERROR); - mem_limit(&strm, 0); - memset(dict, 0, 257); - ret = inflateSetDictionary(&strm, dict, 257); - assert(ret == Z_OK); - mem_limit(&strm, (sizeof(struct inflate_state) << 1) + 256); - ret = inflatePrime(&strm, 16, 0); assert(ret == Z_OK); - strm.avail_in = 2; - strm.next_in = (void *)"\x80"; - ret = inflateSync(&strm); assert(ret == Z_DATA_ERROR); - ret = inflate(&strm, Z_NO_FLUSH); assert(ret == Z_STREAM_ERROR); - strm.avail_in = 4; - strm.next_in = (void *)"\0\0\xff\xff"; - ret = inflateSync(&strm); assert(ret == Z_OK); - (void)inflateSyncPoint(&strm); - ret = inflateCopy(©, &strm); assert(ret == Z_MEM_ERROR); - mem_limit(&strm, 0); - ret = inflateUndermine(&strm, 1); assert(ret == Z_DATA_ERROR); - (void)inflateMark(&strm); - ret = inflateEnd(&strm); assert(ret == Z_OK); - mem_done(&strm, "miscellaneous, force memory errors"); -} - -/* input and output functions for inflateBack() */ -local unsigned pull(void *desc, unsigned char **buf) -{ - static unsigned int next = 0; - static unsigned char dat[] = {0x63, 0, 2, 0}; - struct inflate_state *state; - - if (desc == Z_NULL) { - next = 0; - return 0; /* no input (already provided at next_in) */ - } - state = (void *)((z_stream *)desc)->state; - if (state != Z_NULL) - state->mode = SYNC; /* force an otherwise impossible situation */ - return next < sizeof(dat) ? (*buf = dat + next++, 1) : 0; -} - -local int push(void *desc, unsigned char *buf, unsigned len) -{ - buf += len; - return desc != Z_NULL; /* force error if desc not null */ -} - -/* cover inflateBack() up to common deflate data cases and after those */ -local void cover_back(void) -{ - int ret; - z_stream strm; - unsigned char win[32768]; - - ret = inflateBackInit_(Z_NULL, 0, win, 0, 0); - assert(ret == Z_VERSION_ERROR); - ret = inflateBackInit(Z_NULL, 0, win); assert(ret == Z_STREAM_ERROR); - ret = inflateBack(Z_NULL, Z_NULL, Z_NULL, Z_NULL, Z_NULL); - assert(ret == Z_STREAM_ERROR); - ret = inflateBackEnd(Z_NULL); assert(ret == Z_STREAM_ERROR); - fputs("inflateBack bad parameters\n", stderr); - - mem_setup(&strm); - ret = inflateBackInit(&strm, 15, win); assert(ret == Z_OK); - strm.avail_in = 2; - strm.next_in = (void *)"\x03"; - ret = inflateBack(&strm, pull, Z_NULL, push, Z_NULL); - assert(ret == Z_STREAM_END); - /* force output error */ - strm.avail_in = 3; - strm.next_in = (void *)"\x63\x00"; - ret = inflateBack(&strm, pull, Z_NULL, push, &strm); - assert(ret == Z_BUF_ERROR); - /* force mode error by mucking with state */ - ret = inflateBack(&strm, pull, &strm, push, Z_NULL); - assert(ret == Z_STREAM_ERROR); - ret = inflateBackEnd(&strm); assert(ret == Z_OK); - mem_done(&strm, "inflateBack bad state"); - - ret = inflateBackInit(&strm, 15, win); assert(ret == Z_OK); - ret = inflateBackEnd(&strm); assert(ret == Z_OK); - fputs("inflateBack built-in memory routines\n", stderr); -} - -/* do a raw inflate of data in hexadecimal with both inflate and inflateBack */ -local int try(char *hex, char *id, int err) -{ - int ret; - unsigned len, size; - unsigned char *in, *out, *win; - char *prefix; - z_stream strm; - - /* convert to hex */ - in = h2b(hex, &len); - assert(in != NULL); - - /* allocate work areas */ - size = len << 3; - out = malloc(size); - assert(out != NULL); - win = malloc(32768); - assert(win != NULL); - prefix = malloc(strlen(id) + 6); - assert(prefix != NULL); - - /* first with inflate */ - strcpy(prefix, id); - strcat(prefix, "-late"); - mem_setup(&strm); - strm.avail_in = 0; - strm.next_in = Z_NULL; - ret = inflateInit2(&strm, err < 0 ? 47 : -15); - assert(ret == Z_OK); - strm.avail_in = len; - strm.next_in = in; - do { - strm.avail_out = size; - strm.next_out = out; - ret = inflate(&strm, Z_TREES); - assert(ret != Z_STREAM_ERROR && ret != Z_MEM_ERROR); - if (ret == Z_DATA_ERROR || ret == Z_NEED_DICT) - break; - } while (strm.avail_in || strm.avail_out == 0); - if (err) { - assert(ret == Z_DATA_ERROR); - assert(strcmp(id, strm.msg) == 0); - } - inflateEnd(&strm); - mem_done(&strm, prefix); - - /* then with inflateBack */ - if (err >= 0) { - strcpy(prefix, id); - strcat(prefix, "-back"); - mem_setup(&strm); - ret = inflateBackInit(&strm, 15, win); - assert(ret == Z_OK); - strm.avail_in = len; - strm.next_in = in; - ret = inflateBack(&strm, pull, Z_NULL, push, Z_NULL); - assert(ret != Z_STREAM_ERROR); - if (err) { - assert(ret == Z_DATA_ERROR); - assert(strcmp(id, strm.msg) == 0); - } - inflateBackEnd(&strm); - mem_done(&strm, prefix); - } - - /* clean up */ - free(prefix); - free(win); - free(out); - free(in); - return ret; -} - -/* cover deflate data cases in both inflate() and inflateBack() */ -local void cover_inflate(void) -{ - try("0 0 0 0 0", "invalid stored block lengths", 1); - try("3 0", "fixed", 0); - try("6", "invalid block type", 1); - try("1 1 0 fe ff 0", "stored", 0); - try("fc 0 0", "too many length or distance symbols", 1); - try("4 0 fe ff", "invalid code lengths set", 1); - try("4 0 24 49 0", "invalid bit length repeat", 1); - try("4 0 24 e9 ff ff", "invalid bit length repeat", 1); - try("4 0 24 e9 ff 6d", "invalid code -- missing end-of-block", 1); - try("4 80 49 92 24 49 92 24 71 ff ff 93 11 0", - "invalid literal/lengths set", 1); - try("4 80 49 92 24 49 92 24 f b4 ff ff c3 84", "invalid distances set", 1); - try("4 c0 81 8 0 0 0 0 20 7f eb b 0 0", "invalid literal/length code", 1); - try("2 7e ff ff", "invalid distance code", 1); - try("c c0 81 0 0 0 0 0 90 ff 6b 4 0", "invalid distance too far back", 1); - - /* also trailer mismatch just in inflate() */ - try("1f 8b 8 0 0 0 0 0 0 0 3 0 0 0 0 1", "incorrect data check", -1); - try("1f 8b 8 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 1", - "incorrect length check", -1); - try("5 c0 21 d 0 0 0 80 b0 fe 6d 2f 91 6c", "pull 17", 0); - try("5 e0 81 91 24 cb b2 2c 49 e2 f 2e 8b 9a 47 56 9f fb fe ec d2 ff 1f", - "long code", 0); - try("ed c0 1 1 0 0 0 40 20 ff 57 1b 42 2c 4f", "length extra", 0); - try("ed cf c1 b1 2c 47 10 c4 30 fa 6f 35 1d 1 82 59 3d fb be 2e 2a fc f c", - "long distance and extra", 0); - try("ed c0 81 0 0 0 0 80 a0 fd a9 17 a9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " - "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6", "window end", 0); - inf("2 8 20 80 0 3 0", "inflate_fast TYPE return", 0, -15, 258, - Z_STREAM_END); - inf("63 18 5 40 c 0", "window wrap", 3, -8, 300, Z_OK); -} - -/* cover remaining lines in inftrees.c */ -local void cover_trees(void) -{ - int ret; - unsigned bits; - unsigned short lens[16], work[16]; - code *next, table[ENOUGH_DISTS]; - - /* we need to call inflate_table() directly in order to manifest not- - enough errors, since zlib insures that enough is always enough */ - for (bits = 0; bits < 15; bits++) - lens[bits] = (unsigned short)(bits + 1); - lens[15] = 15; - next = table; - bits = 15; - ret = inflate_table(DISTS, lens, 16, &next, &bits, work); - assert(ret == 1); - next = table; - bits = 1; - ret = inflate_table(DISTS, lens, 16, &next, &bits, work); - assert(ret == 1); - fputs("inflate_table not enough errors\n", stderr); -} - -/* cover remaining inffast.c decoding and window copying */ -local void cover_fast(void) -{ - inf("e5 e0 81 ad 6d cb b2 2c c9 01 1e 59 63 ae 7d ee fb 4d fd b5 35 41 68" - " ff 7f 0f 0 0 0", "fast length extra bits", 0, -8, 258, Z_DATA_ERROR); - inf("25 fd 81 b5 6d 59 b6 6a 49 ea af 35 6 34 eb 8c b9 f6 b9 1e ef 67 49" - " 50 fe ff ff 3f 0 0", "fast distance extra bits", 0, -8, 258, - Z_DATA_ERROR); - inf("3 7e 0 0 0 0 0", "fast invalid distance code", 0, -8, 258, - Z_DATA_ERROR); - inf("1b 7 0 0 0 0 0", "fast invalid literal/length code", 0, -8, 258, - Z_DATA_ERROR); - inf("d c7 1 ae eb 38 c 4 41 a0 87 72 de df fb 1f b8 36 b1 38 5d ff ff 0", - "fast 2nd level codes and too far back", 0, -8, 258, Z_DATA_ERROR); - inf("63 18 5 8c 10 8 0 0 0 0", "very common case", 0, -8, 259, Z_OK); - inf("63 60 60 18 c9 0 8 18 18 18 26 c0 28 0 29 0 0 0", - "contiguous and wrap around window", 6, -8, 259, Z_OK); - inf("63 0 3 0 0 0 0 0", "copy direct from output", 0, -8, 259, - Z_STREAM_END); -} - -int main(void) -{ - fprintf(stderr, "%s\n", zlibVersion()); - cover_support(); - cover_wrap(); - cover_back(); - cover_inflate(); - cover_trees(); - cover_fast(); - return 0; -} diff --git a/src/beast/test/zlib/zlib-1.2.8/test/minigzip.c b/src/beast/test/zlib/zlib-1.2.8/test/minigzip.c deleted file mode 100644 index b3025a489a9..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/test/minigzip.c +++ /dev/null @@ -1,651 +0,0 @@ -/* minigzip.c -- simulate gzip using the zlib compression library - * Copyright (C) 1995-2006, 2010, 2011 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* - * minigzip is a minimal implementation of the gzip utility. This is - * only an example of using zlib and isn't meant to replace the - * full-featured gzip. No attempt is made to deal with file systems - * limiting names to 14 or 8+3 characters, etc... Error checking is - * very limited. So use minigzip only for testing; use gzip for the - * real thing. On MSDOS, use only on file names without extension - * or in pipe mode. - */ - -/* @(#) $Id$ */ - -#include "zlib.h" -#include - -#ifdef STDC -# include -# include -#endif - -#ifdef USE_MMAP -# include -# include -# include -#endif - -#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) -# include -# include -# ifdef UNDER_CE -# include -# endif -# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) -#else -# define SET_BINARY_MODE(file) -#endif - -#ifdef _MSC_VER -# define snprintf _snprintf -#endif - -#ifdef VMS -# define unlink delete -# define GZ_SUFFIX "-gz" -#endif -#ifdef RISCOS -# define unlink remove -# define GZ_SUFFIX "-gz" -# define fileno(file) file->__file -#endif -#if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os -# include /* for fileno */ -#endif - -#if !defined(Z_HAVE_UNISTD_H) && !defined(_LARGEFILE64_SOURCE) -#ifndef WIN32 /* unlink already in stdio.h for WIN32 */ - extern int unlink OF((const char *)); -#endif -#endif - -#if defined(UNDER_CE) -# include -# define perror(s) pwinerror(s) - -/* Map the Windows error number in ERROR to a locale-dependent error - message string and return a pointer to it. Typically, the values - for ERROR come from GetLastError. - - The string pointed to shall not be modified by the application, - but may be overwritten by a subsequent call to strwinerror - - The strwinerror function does not change the current setting - of GetLastError. */ - -static char *strwinerror (error) - DWORD error; -{ - static char buf[1024]; - - wchar_t *msgbuf; - DWORD lasterr = GetLastError(); - DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM - | FORMAT_MESSAGE_ALLOCATE_BUFFER, - NULL, - error, - 0, /* Default language */ - (LPVOID)&msgbuf, - 0, - NULL); - if (chars != 0) { - /* If there is an \r\n appended, zap it. */ - if (chars >= 2 - && msgbuf[chars - 2] == '\r' && msgbuf[chars - 1] == '\n') { - chars -= 2; - msgbuf[chars] = 0; - } - - if (chars > sizeof (buf) - 1) { - chars = sizeof (buf) - 1; - msgbuf[chars] = 0; - } - - wcstombs(buf, msgbuf, chars + 1); - LocalFree(msgbuf); - } - else { - sprintf(buf, "unknown win32 error (%ld)", error); - } - - SetLastError(lasterr); - return buf; -} - -static void pwinerror (s) - const char *s; -{ - if (s && *s) - fprintf(stderr, "%s: %s\n", s, strwinerror(GetLastError ())); - else - fprintf(stderr, "%s\n", strwinerror(GetLastError ())); -} - -#endif /* UNDER_CE */ - -#ifndef GZ_SUFFIX -# define GZ_SUFFIX ".gz" -#endif -#define SUFFIX_LEN (sizeof(GZ_SUFFIX)-1) - -#define BUFLEN 16384 -#define MAX_NAME_LEN 1024 - -#ifdef MAXSEG_64K -# define local static - /* Needed for systems with limitation on stack size. */ -#else -# define local -#endif - -#ifdef Z_SOLO -/* for Z_SOLO, create simplified gz* functions using deflate and inflate */ - -#if defined(Z_HAVE_UNISTD_H) || defined(Z_LARGE) -# include /* for unlink() */ -#endif - -void *myalloc OF((void *, unsigned, unsigned)); -void myfree OF((void *, void *)); - -void *myalloc(q, n, m) - void *q; - unsigned n, m; -{ - q = Z_NULL; - return calloc(n, m); -} - -void myfree(q, p) - void *q, *p; -{ - q = Z_NULL; - free(p); -} - -typedef struct gzFile_s { - FILE *file; - int write; - int err; - char *msg; - z_stream strm; -} *gzFile; - -gzFile gzopen OF((const char *, const char *)); -gzFile gzdopen OF((int, const char *)); -gzFile gz_open OF((const char *, int, const char *)); - -gzFile gzopen(path, mode) -const char *path; -const char *mode; -{ - return gz_open(path, -1, mode); -} - -gzFile gzdopen(fd, mode) -int fd; -const char *mode; -{ - return gz_open(NULL, fd, mode); -} - -gzFile gz_open(path, fd, mode) - const char *path; - int fd; - const char *mode; -{ - gzFile gz; - int ret; - - gz = malloc(sizeof(struct gzFile_s)); - if (gz == NULL) - return NULL; - gz->write = strchr(mode, 'w') != NULL; - gz->strm.zalloc = myalloc; - gz->strm.zfree = myfree; - gz->strm.opaque = Z_NULL; - if (gz->write) - ret = deflateInit2(&(gz->strm), -1, 8, 15 + 16, 8, 0); - else { - gz->strm.next_in = 0; - gz->strm.avail_in = Z_NULL; - ret = inflateInit2(&(gz->strm), 15 + 16); - } - if (ret != Z_OK) { - free(gz); - return NULL; - } - gz->file = path == NULL ? fdopen(fd, gz->write ? "wb" : "rb") : - fopen(path, gz->write ? "wb" : "rb"); - if (gz->file == NULL) { - gz->write ? deflateEnd(&(gz->strm)) : inflateEnd(&(gz->strm)); - free(gz); - return NULL; - } - gz->err = 0; - gz->msg = ""; - return gz; -} - -int gzwrite OF((gzFile, const void *, unsigned)); - -int gzwrite(gz, buf, len) - gzFile gz; - const void *buf; - unsigned len; -{ - z_stream *strm; - unsigned char out[BUFLEN]; - - if (gz == NULL || !gz->write) - return 0; - strm = &(gz->strm); - strm->next_in = (void *)buf; - strm->avail_in = len; - do { - strm->next_out = out; - strm->avail_out = BUFLEN; - (void)deflate(strm, Z_NO_FLUSH); - fwrite(out, 1, BUFLEN - strm->avail_out, gz->file); - } while (strm->avail_out == 0); - return len; -} - -int gzread OF((gzFile, void *, unsigned)); - -int gzread(gz, buf, len) - gzFile gz; - void *buf; - unsigned len; -{ - int ret; - unsigned got; - unsigned char in[1]; - z_stream *strm; - - if (gz == NULL || gz->write) - return 0; - if (gz->err) - return 0; - strm = &(gz->strm); - strm->next_out = (void *)buf; - strm->avail_out = len; - do { - got = fread(in, 1, 1, gz->file); - if (got == 0) - break; - strm->next_in = in; - strm->avail_in = 1; - ret = inflate(strm, Z_NO_FLUSH); - if (ret == Z_DATA_ERROR) { - gz->err = Z_DATA_ERROR; - gz->msg = strm->msg; - return 0; - } - if (ret == Z_STREAM_END) - inflateReset(strm); - } while (strm->avail_out); - return len - strm->avail_out; -} - -int gzclose OF((gzFile)); - -int gzclose(gz) - gzFile gz; -{ - z_stream *strm; - unsigned char out[BUFLEN]; - - if (gz == NULL) - return Z_STREAM_ERROR; - strm = &(gz->strm); - if (gz->write) { - strm->next_in = Z_NULL; - strm->avail_in = 0; - do { - strm->next_out = out; - strm->avail_out = BUFLEN; - (void)deflate(strm, Z_FINISH); - fwrite(out, 1, BUFLEN - strm->avail_out, gz->file); - } while (strm->avail_out == 0); - deflateEnd(strm); - } - else - inflateEnd(strm); - fclose(gz->file); - free(gz); - return Z_OK; -} - -const char *gzerror OF((gzFile, int *)); - -const char *gzerror(gz, err) - gzFile gz; - int *err; -{ - *err = gz->err; - return gz->msg; -} - -#endif - -char *prog; - -void error OF((const char *msg)); -void gz_compress OF((FILE *in, gzFile out)); -#ifdef USE_MMAP -int gz_compress_mmap OF((FILE *in, gzFile out)); -#endif -void gz_uncompress OF((gzFile in, FILE *out)); -void file_compress OF((char *file, char *mode)); -void file_uncompress OF((char *file)); -int main OF((int argc, char *argv[])); - -/* =========================================================================== - * Display error message and exit - */ -void error(msg) - const char *msg; -{ - fprintf(stderr, "%s: %s\n", prog, msg); - exit(1); -} - -/* =========================================================================== - * Compress input to output then close both files. - */ - -void gz_compress(in, out) - FILE *in; - gzFile out; -{ - local char buf[BUFLEN]; - int len; - int err; - -#ifdef USE_MMAP - /* Try first compressing with mmap. If mmap fails (minigzip used in a - * pipe), use the normal fread loop. - */ - if (gz_compress_mmap(in, out) == Z_OK) return; -#endif - for (;;) { - len = (int)fread(buf, 1, sizeof(buf), in); - if (ferror(in)) { - perror("fread"); - exit(1); - } - if (len == 0) break; - - if (gzwrite(out, buf, (unsigned)len) != len) error(gzerror(out, &err)); - } - fclose(in); - if (gzclose(out) != Z_OK) error("failed gzclose"); -} - -#ifdef USE_MMAP /* MMAP version, Miguel Albrecht */ - -/* Try compressing the input file at once using mmap. Return Z_OK if - * if success, Z_ERRNO otherwise. - */ -int gz_compress_mmap(in, out) - FILE *in; - gzFile out; -{ - int len; - int err; - int ifd = fileno(in); - caddr_t buf; /* mmap'ed buffer for the entire input file */ - off_t buf_len; /* length of the input file */ - struct stat sb; - - /* Determine the size of the file, needed for mmap: */ - if (fstat(ifd, &sb) < 0) return Z_ERRNO; - buf_len = sb.st_size; - if (buf_len <= 0) return Z_ERRNO; - - /* Now do the actual mmap: */ - buf = mmap((caddr_t) 0, buf_len, PROT_READ, MAP_SHARED, ifd, (off_t)0); - if (buf == (caddr_t)(-1)) return Z_ERRNO; - - /* Compress the whole file at once: */ - len = gzwrite(out, (char *)buf, (unsigned)buf_len); - - if (len != (int)buf_len) error(gzerror(out, &err)); - - munmap(buf, buf_len); - fclose(in); - if (gzclose(out) != Z_OK) error("failed gzclose"); - return Z_OK; -} -#endif /* USE_MMAP */ - -/* =========================================================================== - * Uncompress input to output then close both files. - */ -void gz_uncompress(in, out) - gzFile in; - FILE *out; -{ - local char buf[BUFLEN]; - int len; - int err; - - for (;;) { - len = gzread(in, buf, sizeof(buf)); - if (len < 0) error (gzerror(in, &err)); - if (len == 0) break; - - if ((int)fwrite(buf, 1, (unsigned)len, out) != len) { - error("failed fwrite"); - } - } - if (fclose(out)) error("failed fclose"); - - if (gzclose(in) != Z_OK) error("failed gzclose"); -} - - -/* =========================================================================== - * Compress the given file: create a corresponding .gz file and remove the - * original. - */ -void file_compress(file, mode) - char *file; - char *mode; -{ - local char outfile[MAX_NAME_LEN]; - FILE *in; - gzFile out; - - if (strlen(file) + strlen(GZ_SUFFIX) >= sizeof(outfile)) { - fprintf(stderr, "%s: filename too long\n", prog); - exit(1); - } - -#if !defined(NO_snprintf) && !defined(NO_vsnprintf) - snprintf(outfile, sizeof(outfile), "%s%s", file, GZ_SUFFIX); -#else - strcpy(outfile, file); - strcat(outfile, GZ_SUFFIX); -#endif - - in = fopen(file, "rb"); - if (in == NULL) { - perror(file); - exit(1); - } - out = gzopen(outfile, mode); - if (out == NULL) { - fprintf(stderr, "%s: can't gzopen %s\n", prog, outfile); - exit(1); - } - gz_compress(in, out); - - unlink(file); -} - - -/* =========================================================================== - * Uncompress the given file and remove the original. - */ -void file_uncompress(file) - char *file; -{ - local char buf[MAX_NAME_LEN]; - char *infile, *outfile; - FILE *out; - gzFile in; - size_t len = strlen(file); - - if (len + strlen(GZ_SUFFIX) >= sizeof(buf)) { - fprintf(stderr, "%s: filename too long\n", prog); - exit(1); - } - -#if !defined(NO_snprintf) && !defined(NO_vsnprintf) - snprintf(buf, sizeof(buf), "%s", file); -#else - strcpy(buf, file); -#endif - - if (len > SUFFIX_LEN && strcmp(file+len-SUFFIX_LEN, GZ_SUFFIX) == 0) { - infile = file; - outfile = buf; - outfile[len-3] = '\0'; - } else { - outfile = file; - infile = buf; -#if !defined(NO_snprintf) && !defined(NO_vsnprintf) - snprintf(buf + len, sizeof(buf) - len, "%s", GZ_SUFFIX); -#else - strcat(infile, GZ_SUFFIX); -#endif - } - in = gzopen(infile, "rb"); - if (in == NULL) { - fprintf(stderr, "%s: can't gzopen %s\n", prog, infile); - exit(1); - } - out = fopen(outfile, "wb"); - if (out == NULL) { - perror(file); - exit(1); - } - - gz_uncompress(in, out); - - unlink(infile); -} - - -/* =========================================================================== - * Usage: minigzip [-c] [-d] [-f] [-h] [-r] [-1 to -9] [files...] - * -c : write to standard output - * -d : decompress - * -f : compress with Z_FILTERED - * -h : compress with Z_HUFFMAN_ONLY - * -r : compress with Z_RLE - * -1 to -9 : compression level - */ - -int main(argc, argv) - int argc; - char *argv[]; -{ - int copyout = 0; - int uncompr = 0; - gzFile file; - char *bname, outmode[20]; - -#if !defined(NO_snprintf) && !defined(NO_vsnprintf) - snprintf(outmode, sizeof(outmode), "%s", "wb6 "); -#else - strcpy(outmode, "wb6 "); -#endif - - prog = argv[0]; - bname = strrchr(argv[0], '/'); - if (bname) - bname++; - else - bname = argv[0]; - argc--, argv++; - - if (!strcmp(bname, "gunzip")) - uncompr = 1; - else if (!strcmp(bname, "zcat")) - copyout = uncompr = 1; - - while (argc > 0) { - if (strcmp(*argv, "-c") == 0) - copyout = 1; - else if (strcmp(*argv, "-d") == 0) - uncompr = 1; - else if (strcmp(*argv, "-f") == 0) - outmode[3] = 'f'; - else if (strcmp(*argv, "-h") == 0) - outmode[3] = 'h'; - else if (strcmp(*argv, "-r") == 0) - outmode[3] = 'R'; - else if ((*argv)[0] == '-' && (*argv)[1] >= '1' && (*argv)[1] <= '9' && - (*argv)[2] == 0) - outmode[2] = (*argv)[1]; - else - break; - argc--, argv++; - } - if (outmode[3] == ' ') - outmode[3] = 0; - if (argc == 0) { - SET_BINARY_MODE(stdin); - SET_BINARY_MODE(stdout); - if (uncompr) { - file = gzdopen(fileno(stdin), "rb"); - if (file == NULL) error("can't gzdopen stdin"); - gz_uncompress(file, stdout); - } else { - file = gzdopen(fileno(stdout), outmode); - if (file == NULL) error("can't gzdopen stdout"); - gz_compress(stdin, file); - } - } else { - if (copyout) { - SET_BINARY_MODE(stdout); - } - do { - if (uncompr) { - if (copyout) { - file = gzopen(*argv, "rb"); - if (file == NULL) - fprintf(stderr, "%s: can't gzopen %s\n", prog, *argv); - else - gz_uncompress(file, stdout); - } else { - file_uncompress(*argv); - } - } else { - if (copyout) { - FILE * in = fopen(*argv, "rb"); - - if (in == NULL) { - perror(*argv); - } else { - file = gzdopen(fileno(stdout), outmode); - if (file == NULL) error("can't gzdopen stdout"); - - gz_compress(in, file); - } - - } else { - file_compress(*argv, outmode); - } - } - } while (argv++, --argc); - } - return 0; -} diff --git a/src/beast/test/zlib/zlib-1.2.8/treebuild.xml b/src/beast/test/zlib/zlib-1.2.8/treebuild.xml deleted file mode 100644 index 38d29d75efc..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/treebuild.xml +++ /dev/null @@ -1,116 +0,0 @@ - - - - zip compression library - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/beast/test/zlib/zlib-1.2.8/trees.c b/src/beast/test/zlib/zlib-1.2.8/trees.c deleted file mode 100644 index 1fd7759ef00..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/trees.c +++ /dev/null @@ -1,1226 +0,0 @@ -/* trees.c -- output deflated data using Huffman coding - * Copyright (C) 1995-2012 Jean-loup Gailly - * detect_data_type() function provided freely by Cosmin Truta, 2006 - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* - * ALGORITHM - * - * The "deflation" process uses several Huffman trees. The more - * common source values are represented by shorter bit sequences. - * - * Each code tree is stored in a compressed form which is itself - * a Huffman encoding of the lengths of all the code strings (in - * ascending order by source values). The actual code strings are - * reconstructed from the lengths in the inflate process, as described - * in the deflate specification. - * - * REFERENCES - * - * Deutsch, L.P.,"'Deflate' Compressed Data Format Specification". - * Available in ftp.uu.net:/pub/archiving/zip/doc/deflate-1.1.doc - * - * Storer, James A. - * Data Compression: Methods and Theory, pp. 49-50. - * Computer Science Press, 1988. ISBN 0-7167-8156-5. - * - * Sedgewick, R. - * Algorithms, p290. - * Addison-Wesley, 1983. ISBN 0-201-06672-6. - */ - -/* @(#) $Id$ */ - -/* #define GEN_TREES_H */ - -#include "deflate.h" - -#ifdef DEBUG -# include -#endif - -/* =========================================================================== - * Constants - */ - -#define MAX_BL_BITS 7 -/* Bit length codes must not exceed MAX_BL_BITS bits */ - -#define END_BLOCK 256 -/* end of block literal code */ - -#define REP_3_6 16 -/* repeat previous bit length 3-6 times (2 bits of repeat count) */ - -#define REPZ_3_10 17 -/* repeat a zero length 3-10 times (3 bits of repeat count) */ - -#define REPZ_11_138 18 -/* repeat a zero length 11-138 times (7 bits of repeat count) */ - -local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */ - = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0}; - -local const int extra_dbits[D_CODES] /* extra bits for each distance code */ - = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13}; - -local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */ - = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7}; - -local const uch bl_order[BL_CODES] - = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15}; -/* The lengths of the bit length codes are sent in order of decreasing - * probability, to avoid transmitting the lengths for unused bit length codes. - */ - -/* =========================================================================== - * Local data. These are initialized only once. - */ - -#define DIST_CODE_LEN 512 /* see definition of array dist_code below */ - -#if defined(GEN_TREES_H) || !defined(STDC) -/* non ANSI compilers may not accept trees.h */ - -local ct_data static_ltree[L_CODES+2]; -/* The static literal tree. Since the bit lengths are imposed, there is no - * need for the L_CODES extra codes used during heap construction. However - * The codes 286 and 287 are needed to build a canonical tree (see _tr_init - * below). - */ - -local ct_data static_dtree[D_CODES]; -/* The static distance tree. (Actually a trivial tree since all codes use - * 5 bits.) - */ - -uch _dist_code[DIST_CODE_LEN]; -/* Distance codes. The first 256 values correspond to the distances - * 3 .. 258, the last 256 values correspond to the top 8 bits of - * the 15 bit distances. - */ - -uch _length_code[MAX_MATCH-MIN_MATCH+1]; -/* length code for each normalized match length (0 == MIN_MATCH) */ - -local int base_length[LENGTH_CODES]; -/* First normalized length for each code (0 = MIN_MATCH) */ - -local int base_dist[D_CODES]; -/* First normalized distance for each code (0 = distance of 1) */ - -#else -# include "trees.h" -#endif /* GEN_TREES_H */ - -struct static_tree_desc_s { - const ct_data *static_tree; /* static tree or NULL */ - const intf *extra_bits; /* extra bits for each code or NULL */ - int extra_base; /* base index for extra_bits */ - int elems; /* max number of elements in the tree */ - int max_length; /* max bit length for the codes */ -}; - -local static_tree_desc static_l_desc = -{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS}; - -local static_tree_desc static_d_desc = -{static_dtree, extra_dbits, 0, D_CODES, MAX_BITS}; - -local static_tree_desc static_bl_desc = -{(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS}; - -/* =========================================================================== - * Local (static) routines in this file. - */ - -local void tr_static_init OF((void)); -local void init_block OF((deflate_state *s)); -local void pqdownheap OF((deflate_state *s, ct_data *tree, int k)); -local void gen_bitlen OF((deflate_state *s, tree_desc *desc)); -local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count)); -local void build_tree OF((deflate_state *s, tree_desc *desc)); -local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code)); -local void send_tree OF((deflate_state *s, ct_data *tree, int max_code)); -local int build_bl_tree OF((deflate_state *s)); -local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes, - int blcodes)); -local void compress_block OF((deflate_state *s, const ct_data *ltree, - const ct_data *dtree)); -local int detect_data_type OF((deflate_state *s)); -local unsigned bi_reverse OF((unsigned value, int length)); -local void bi_windup OF((deflate_state *s)); -local void bi_flush OF((deflate_state *s)); -local void copy_block OF((deflate_state *s, charf *buf, unsigned len, - int header)); - -#ifdef GEN_TREES_H -local void gen_trees_header OF((void)); -#endif - -#ifndef DEBUG -# define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len) - /* Send a code of the given tree. c and tree must not have side effects */ - -#else /* DEBUG */ -# define send_code(s, c, tree) \ - { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \ - send_bits(s, tree[c].Code, tree[c].Len); } -#endif - -/* =========================================================================== - * Output a short LSB first on the stream. - * IN assertion: there is enough room in pendingBuf. - */ -#define put_short(s, w) { \ - put_byte(s, (uch)((w) & 0xff)); \ - put_byte(s, (uch)((ush)(w) >> 8)); \ -} - -/* =========================================================================== - * Send a value on a given number of bits. - * IN assertion: length <= 16 and value fits in length bits. - */ -#ifdef DEBUG -local void send_bits OF((deflate_state *s, int value, int length)); - -local void send_bits(s, value, length) - deflate_state *s; - int value; /* value to send */ - int length; /* number of bits */ -{ - Tracevv((stderr," l %2d v %4x ", length, value)); - Assert(length > 0 && length <= 15, "invalid length"); - s->bits_sent += (ulg)length; - - /* If not enough room in bi_buf, use (valid) bits from bi_buf and - * (16 - bi_valid) bits from value, leaving (width - (16-bi_valid)) - * unused bits in value. - */ - if (s->bi_valid > (int)Buf_size - length) { - s->bi_buf |= (ush)value << s->bi_valid; - put_short(s, s->bi_buf); - s->bi_buf = (ush)value >> (Buf_size - s->bi_valid); - s->bi_valid += length - Buf_size; - } else { - s->bi_buf |= (ush)value << s->bi_valid; - s->bi_valid += length; - } -} -#else /* !DEBUG */ - -#define send_bits(s, value, length) \ -{ int len = length;\ - if (s->bi_valid > (int)Buf_size - len) {\ - int val = value;\ - s->bi_buf |= (ush)val << s->bi_valid;\ - put_short(s, s->bi_buf);\ - s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\ - s->bi_valid += len - Buf_size;\ - } else {\ - s->bi_buf |= (ush)(value) << s->bi_valid;\ - s->bi_valid += len;\ - }\ -} -#endif /* DEBUG */ - - -/* the arguments must not have side effects */ - -/* =========================================================================== - * Initialize the various 'constant' tables. - */ -local void tr_static_init() -{ -#if defined(GEN_TREES_H) || !defined(STDC) - static int static_init_done = 0; - int n; /* iterates over tree elements */ - int bits; /* bit counter */ - int length; /* length value */ - int code; /* code value */ - int dist; /* distance index */ - ush bl_count[MAX_BITS+1]; - /* number of codes at each bit length for an optimal tree */ - - if (static_init_done) return; - - /* For some embedded targets, global variables are not initialized: */ -#ifdef NO_INIT_GLOBAL_POINTERS - static_l_desc.static_tree = static_ltree; - static_l_desc.extra_bits = extra_lbits; - static_d_desc.static_tree = static_dtree; - static_d_desc.extra_bits = extra_dbits; - static_bl_desc.extra_bits = extra_blbits; -#endif - - /* Initialize the mapping length (0..255) -> length code (0..28) */ - length = 0; - for (code = 0; code < LENGTH_CODES-1; code++) { - base_length[code] = length; - for (n = 0; n < (1< dist code (0..29) */ - dist = 0; - for (code = 0 ; code < 16; code++) { - base_dist[code] = dist; - for (n = 0; n < (1<>= 7; /* from now on, all distances are divided by 128 */ - for ( ; code < D_CODES; code++) { - base_dist[code] = dist << 7; - for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) { - _dist_code[256 + dist++] = (uch)code; - } - } - Assert (dist == 256, "tr_static_init: 256+dist != 512"); - - /* Construct the codes of the static literal tree */ - for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0; - n = 0; - while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++; - while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++; - while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++; - while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++; - /* Codes 286 and 287 do not exist, but we must include them in the - * tree construction to get a canonical Huffman tree (longest code - * all ones) - */ - gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count); - - /* The static distance tree is trivial: */ - for (n = 0; n < D_CODES; n++) { - static_dtree[n].Len = 5; - static_dtree[n].Code = bi_reverse((unsigned)n, 5); - } - static_init_done = 1; - -# ifdef GEN_TREES_H - gen_trees_header(); -# endif -#endif /* defined(GEN_TREES_H) || !defined(STDC) */ -} - -/* =========================================================================== - * Genererate the file trees.h describing the static trees. - */ -#ifdef GEN_TREES_H -# ifndef DEBUG -# include -# endif - -# define SEPARATOR(i, last, width) \ - ((i) == (last)? "\n};\n\n" : \ - ((i) % (width) == (width)-1 ? ",\n" : ", ")) - -void gen_trees_header() -{ - FILE *header = fopen("trees.h", "w"); - int i; - - Assert (header != NULL, "Can't open trees.h"); - fprintf(header, - "/* header created automatically with -DGEN_TREES_H */\n\n"); - - fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n"); - for (i = 0; i < L_CODES+2; i++) { - fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code, - static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5)); - } - - fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n"); - for (i = 0; i < D_CODES; i++) { - fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code, - static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5)); - } - - fprintf(header, "const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {\n"); - for (i = 0; i < DIST_CODE_LEN; i++) { - fprintf(header, "%2u%s", _dist_code[i], - SEPARATOR(i, DIST_CODE_LEN-1, 20)); - } - - fprintf(header, - "const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {\n"); - for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) { - fprintf(header, "%2u%s", _length_code[i], - SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20)); - } - - fprintf(header, "local const int base_length[LENGTH_CODES] = {\n"); - for (i = 0; i < LENGTH_CODES; i++) { - fprintf(header, "%1u%s", base_length[i], - SEPARATOR(i, LENGTH_CODES-1, 20)); - } - - fprintf(header, "local const int base_dist[D_CODES] = {\n"); - for (i = 0; i < D_CODES; i++) { - fprintf(header, "%5u%s", base_dist[i], - SEPARATOR(i, D_CODES-1, 10)); - } - - fclose(header); -} -#endif /* GEN_TREES_H */ - -/* =========================================================================== - * Initialize the tree data structures for a new zlib stream. - */ -void ZLIB_INTERNAL _tr_init(s) - deflate_state *s; -{ - tr_static_init(); - - s->l_desc.dyn_tree = s->dyn_ltree; - s->l_desc.stat_desc = &static_l_desc; - - s->d_desc.dyn_tree = s->dyn_dtree; - s->d_desc.stat_desc = &static_d_desc; - - s->bl_desc.dyn_tree = s->bl_tree; - s->bl_desc.stat_desc = &static_bl_desc; - - s->bi_buf = 0; - s->bi_valid = 0; -#ifdef DEBUG - s->compressed_len = 0L; - s->bits_sent = 0L; -#endif - - /* Initialize the first block of the first file: */ - init_block(s); -} - -/* =========================================================================== - * Initialize a new block. - */ -local void init_block(s) - deflate_state *s; -{ - int n; /* iterates over tree elements */ - - /* Initialize the trees. */ - for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0; - for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0; - for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0; - - s->dyn_ltree[END_BLOCK].Freq = 1; - s->opt_len = s->static_len = 0L; - s->last_lit = s->matches = 0; -} - -#define SMALLEST 1 -/* Index within the heap array of least frequent node in the Huffman tree */ - - -/* =========================================================================== - * Remove the smallest element from the heap and recreate the heap with - * one less element. Updates heap and heap_len. - */ -#define pqremove(s, tree, top) \ -{\ - top = s->heap[SMALLEST]; \ - s->heap[SMALLEST] = s->heap[s->heap_len--]; \ - pqdownheap(s, tree, SMALLEST); \ -} - -/* =========================================================================== - * Compares to subtrees, using the tree depth as tie breaker when - * the subtrees have equal frequency. This minimizes the worst case length. - */ -#define smaller(tree, n, m, depth) \ - (tree[n].Freq < tree[m].Freq || \ - (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m])) - -/* =========================================================================== - * Restore the heap property by moving down the tree starting at node k, - * exchanging a node with the smallest of its two sons if necessary, stopping - * when the heap property is re-established (each father smaller than its - * two sons). - */ -local void pqdownheap(s, tree, k) - deflate_state *s; - ct_data *tree; /* the tree to restore */ - int k; /* node to move down */ -{ - int v = s->heap[k]; - int j = k << 1; /* left son of k */ - while (j <= s->heap_len) { - /* Set j to the smallest of the two sons: */ - if (j < s->heap_len && - smaller(tree, s->heap[j+1], s->heap[j], s->depth)) { - j++; - } - /* Exit if v is smaller than both sons */ - if (smaller(tree, v, s->heap[j], s->depth)) break; - - /* Exchange v with the smallest son */ - s->heap[k] = s->heap[j]; k = j; - - /* And continue down the tree, setting j to the left son of k */ - j <<= 1; - } - s->heap[k] = v; -} - -/* =========================================================================== - * Compute the optimal bit lengths for a tree and update the total bit length - * for the current block. - * IN assertion: the fields freq and dad are set, heap[heap_max] and - * above are the tree nodes sorted by increasing frequency. - * OUT assertions: the field len is set to the optimal bit length, the - * array bl_count contains the frequencies for each bit length. - * The length opt_len is updated; static_len is also updated if stree is - * not null. - */ -local void gen_bitlen(s, desc) - deflate_state *s; - tree_desc *desc; /* the tree descriptor */ -{ - ct_data *tree = desc->dyn_tree; - int max_code = desc->max_code; - const ct_data *stree = desc->stat_desc->static_tree; - const intf *extra = desc->stat_desc->extra_bits; - int base = desc->stat_desc->extra_base; - int max_length = desc->stat_desc->max_length; - int h; /* heap index */ - int n, m; /* iterate over the tree elements */ - int bits; /* bit length */ - int xbits; /* extra bits */ - ush f; /* frequency */ - int overflow = 0; /* number of elements with bit length too large */ - - for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0; - - /* In a first pass, compute the optimal bit lengths (which may - * overflow in the case of the bit length tree). - */ - tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */ - - for (h = s->heap_max+1; h < HEAP_SIZE; h++) { - n = s->heap[h]; - bits = tree[tree[n].Dad].Len + 1; - if (bits > max_length) bits = max_length, overflow++; - tree[n].Len = (ush)bits; - /* We overwrite tree[n].Dad which is no longer needed */ - - if (n > max_code) continue; /* not a leaf node */ - - s->bl_count[bits]++; - xbits = 0; - if (n >= base) xbits = extra[n-base]; - f = tree[n].Freq; - s->opt_len += (ulg)f * (bits + xbits); - if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits); - } - if (overflow == 0) return; - - Trace((stderr,"\nbit length overflow\n")); - /* This happens for example on obj2 and pic of the Calgary corpus */ - - /* Find the first bit length which could increase: */ - do { - bits = max_length-1; - while (s->bl_count[bits] == 0) bits--; - s->bl_count[bits]--; /* move one leaf down the tree */ - s->bl_count[bits+1] += 2; /* move one overflow item as its brother */ - s->bl_count[max_length]--; - /* The brother of the overflow item also moves one step up, - * but this does not affect bl_count[max_length] - */ - overflow -= 2; - } while (overflow > 0); - - /* Now recompute all bit lengths, scanning in increasing frequency. - * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all - * lengths instead of fixing only the wrong ones. This idea is taken - * from 'ar' written by Haruhiko Okumura.) - */ - for (bits = max_length; bits != 0; bits--) { - n = s->bl_count[bits]; - while (n != 0) { - m = s->heap[--h]; - if (m > max_code) continue; - if ((unsigned) tree[m].Len != (unsigned) bits) { - Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); - s->opt_len += ((long)bits - (long)tree[m].Len) - *(long)tree[m].Freq; - tree[m].Len = (ush)bits; - } - n--; - } - } -} - -/* =========================================================================== - * Generate the codes for a given tree and bit counts (which need not be - * optimal). - * IN assertion: the array bl_count contains the bit length statistics for - * the given tree and the field len is set for all tree elements. - * OUT assertion: the field code is set for all tree elements of non - * zero code length. - */ -local void gen_codes (tree, max_code, bl_count) - ct_data *tree; /* the tree to decorate */ - int max_code; /* largest code with non zero frequency */ - ushf *bl_count; /* number of codes at each bit length */ -{ - ush next_code[MAX_BITS+1]; /* next code value for each bit length */ - ush code = 0; /* running code value */ - int bits; /* bit index */ - int n; /* code index */ - - /* The distribution counts are first used to generate the code values - * without bit reversal. - */ - for (bits = 1; bits <= MAX_BITS; bits++) { - next_code[bits] = code = (code + bl_count[bits-1]) << 1; - } - /* Check that the bit counts in bl_count are consistent. The last code - * must be all ones. - */ - Assert (code + bl_count[MAX_BITS]-1 == (1<dyn_tree; - const ct_data *stree = desc->stat_desc->static_tree; - int elems = desc->stat_desc->elems; - int n, m; /* iterate over heap elements */ - int max_code = -1; /* largest code with non zero frequency */ - int node; /* new node being created */ - - /* Construct the initial heap, with least frequent element in - * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1]. - * heap[0] is not used. - */ - s->heap_len = 0, s->heap_max = HEAP_SIZE; - - for (n = 0; n < elems; n++) { - if (tree[n].Freq != 0) { - s->heap[++(s->heap_len)] = max_code = n; - s->depth[n] = 0; - } else { - tree[n].Len = 0; - } - } - - /* The pkzip format requires that at least one distance code exists, - * and that at least one bit should be sent even if there is only one - * possible code. So to avoid special checks later on we force at least - * two codes of non zero frequency. - */ - while (s->heap_len < 2) { - node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0); - tree[node].Freq = 1; - s->depth[node] = 0; - s->opt_len--; if (stree) s->static_len -= stree[node].Len; - /* node is 0 or 1 so it does not have extra bits */ - } - desc->max_code = max_code; - - /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree, - * establish sub-heaps of increasing lengths: - */ - for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n); - - /* Construct the Huffman tree by repeatedly combining the least two - * frequent nodes. - */ - node = elems; /* next internal node of the tree */ - do { - pqremove(s, tree, n); /* n = node of least frequency */ - m = s->heap[SMALLEST]; /* m = node of next least frequency */ - - s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */ - s->heap[--(s->heap_max)] = m; - - /* Create a new node father of n and m */ - tree[node].Freq = tree[n].Freq + tree[m].Freq; - s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ? - s->depth[n] : s->depth[m]) + 1); - tree[n].Dad = tree[m].Dad = (ush)node; -#ifdef DUMP_BL_TREE - if (tree == s->bl_tree) { - fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)", - node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq); - } -#endif - /* and insert the new node in the heap */ - s->heap[SMALLEST] = node++; - pqdownheap(s, tree, SMALLEST); - - } while (s->heap_len >= 2); - - s->heap[--(s->heap_max)] = s->heap[SMALLEST]; - - /* At this point, the fields freq and dad are set. We can now - * generate the bit lengths. - */ - gen_bitlen(s, (tree_desc *)desc); - - /* The field len is now set, we can generate the bit codes */ - gen_codes ((ct_data *)tree, max_code, s->bl_count); -} - -/* =========================================================================== - * Scan a literal or distance tree to determine the frequencies of the codes - * in the bit length tree. - */ -local void scan_tree (s, tree, max_code) - deflate_state *s; - ct_data *tree; /* the tree to be scanned */ - int max_code; /* and its largest code of non zero frequency */ -{ - int n; /* iterates over all tree elements */ - int prevlen = -1; /* last emitted length */ - int curlen; /* length of current code */ - int nextlen = tree[0].Len; /* length of next code */ - int count = 0; /* repeat count of the current code */ - int max_count = 7; /* max repeat count */ - int min_count = 4; /* min repeat count */ - - if (nextlen == 0) max_count = 138, min_count = 3; - tree[max_code+1].Len = (ush)0xffff; /* guard */ - - for (n = 0; n <= max_code; n++) { - curlen = nextlen; nextlen = tree[n+1].Len; - if (++count < max_count && curlen == nextlen) { - continue; - } else if (count < min_count) { - s->bl_tree[curlen].Freq += count; - } else if (curlen != 0) { - if (curlen != prevlen) s->bl_tree[curlen].Freq++; - s->bl_tree[REP_3_6].Freq++; - } else if (count <= 10) { - s->bl_tree[REPZ_3_10].Freq++; - } else { - s->bl_tree[REPZ_11_138].Freq++; - } - count = 0; prevlen = curlen; - if (nextlen == 0) { - max_count = 138, min_count = 3; - } else if (curlen == nextlen) { - max_count = 6, min_count = 3; - } else { - max_count = 7, min_count = 4; - } - } -} - -/* =========================================================================== - * Send a literal or distance tree in compressed form, using the codes in - * bl_tree. - */ -local void send_tree (s, tree, max_code) - deflate_state *s; - ct_data *tree; /* the tree to be scanned */ - int max_code; /* and its largest code of non zero frequency */ -{ - int n; /* iterates over all tree elements */ - int prevlen = -1; /* last emitted length */ - int curlen; /* length of current code */ - int nextlen = tree[0].Len; /* length of next code */ - int count = 0; /* repeat count of the current code */ - int max_count = 7; /* max repeat count */ - int min_count = 4; /* min repeat count */ - - /* tree[max_code+1].Len = -1; */ /* guard already set */ - if (nextlen == 0) max_count = 138, min_count = 3; - - for (n = 0; n <= max_code; n++) { - curlen = nextlen; nextlen = tree[n+1].Len; - if (++count < max_count && curlen == nextlen) { - continue; - } else if (count < min_count) { - do { send_code(s, curlen, s->bl_tree); } while (--count != 0); - - } else if (curlen != 0) { - if (curlen != prevlen) { - send_code(s, curlen, s->bl_tree); count--; - } - Assert(count >= 3 && count <= 6, " 3_6?"); - send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2); - - } else if (count <= 10) { - send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3); - - } else { - send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7); - } - count = 0; prevlen = curlen; - if (nextlen == 0) { - max_count = 138, min_count = 3; - } else if (curlen == nextlen) { - max_count = 6, min_count = 3; - } else { - max_count = 7, min_count = 4; - } - } -} - -/* =========================================================================== - * Construct the Huffman tree for the bit lengths and return the index in - * bl_order of the last bit length code to send. - */ -local int build_bl_tree(s) - deflate_state *s; -{ - int max_blindex; /* index of last bit length code of non zero freq */ - - /* Determine the bit length frequencies for literal and distance trees */ - scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code); - scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code); - - /* Build the bit length tree: */ - build_tree(s, (tree_desc *)(&(s->bl_desc))); - /* opt_len now includes the length of the tree representations, except - * the lengths of the bit lengths codes and the 5+5+4 bits for the counts. - */ - - /* Determine the number of bit length codes to send. The pkzip format - * requires that at least 4 bit length codes be sent. (appnote.txt says - * 3 but the actual value used is 4.) - */ - for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) { - if (s->bl_tree[bl_order[max_blindex]].Len != 0) break; - } - /* Update opt_len to include the bit length tree and counts */ - s->opt_len += 3*(max_blindex+1) + 5+5+4; - Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", - s->opt_len, s->static_len)); - - return max_blindex; -} - -/* =========================================================================== - * Send the header for a block using dynamic Huffman trees: the counts, the - * lengths of the bit length codes, the literal tree and the distance tree. - * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. - */ -local void send_all_trees(s, lcodes, dcodes, blcodes) - deflate_state *s; - int lcodes, dcodes, blcodes; /* number of codes for each tree */ -{ - int rank; /* index in bl_order */ - - Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); - Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES, - "too many codes"); - Tracev((stderr, "\nbl counts: ")); - send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */ - send_bits(s, dcodes-1, 5); - send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */ - for (rank = 0; rank < blcodes; rank++) { - Tracev((stderr, "\nbl code %2d ", bl_order[rank])); - send_bits(s, s->bl_tree[bl_order[rank]].Len, 3); - } - Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent)); - - send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */ - Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent)); - - send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */ - Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent)); -} - -/* =========================================================================== - * Send a stored block - */ -void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last) - deflate_state *s; - charf *buf; /* input block */ - ulg stored_len; /* length of input block */ - int last; /* one if this is the last block for a file */ -{ - send_bits(s, (STORED_BLOCK<<1)+last, 3); /* send block type */ -#ifdef DEBUG - s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L; - s->compressed_len += (stored_len + 4) << 3; -#endif - copy_block(s, buf, (unsigned)stored_len, 1); /* with header */ -} - -/* =========================================================================== - * Flush the bits in the bit buffer to pending output (leaves at most 7 bits) - */ -void ZLIB_INTERNAL _tr_flush_bits(s) - deflate_state *s; -{ - bi_flush(s); -} - -/* =========================================================================== - * Send one empty static block to give enough lookahead for inflate. - * This takes 10 bits, of which 7 may remain in the bit buffer. - */ -void ZLIB_INTERNAL _tr_align(s) - deflate_state *s; -{ - send_bits(s, STATIC_TREES<<1, 3); - send_code(s, END_BLOCK, static_ltree); -#ifdef DEBUG - s->compressed_len += 10L; /* 3 for block type, 7 for EOB */ -#endif - bi_flush(s); -} - -/* =========================================================================== - * Determine the best encoding for the current block: dynamic trees, static - * trees or store, and output the encoded block to the zip file. - */ -void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) - deflate_state *s; - charf *buf; /* input block, or NULL if too old */ - ulg stored_len; /* length of input block */ - int last; /* one if this is the last block for a file */ -{ - ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ - int max_blindex = 0; /* index of last bit length code of non zero freq */ - - /* Build the Huffman trees unless a stored block is forced */ - if (s->level > 0) { - - /* Check if the file is binary or text */ - if (s->strm->data_type == Z_UNKNOWN) - s->strm->data_type = detect_data_type(s); - - /* Construct the literal and distance trees */ - build_tree(s, (tree_desc *)(&(s->l_desc))); - Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len, - s->static_len)); - - build_tree(s, (tree_desc *)(&(s->d_desc))); - Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len, - s->static_len)); - /* At this point, opt_len and static_len are the total bit lengths of - * the compressed block data, excluding the tree representations. - */ - - /* Build the bit length tree for the above two trees, and get the index - * in bl_order of the last bit length code to send. - */ - max_blindex = build_bl_tree(s); - - /* Determine the best encoding. Compute the block lengths in bytes. */ - opt_lenb = (s->opt_len+3+7)>>3; - static_lenb = (s->static_len+3+7)>>3; - - Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ", - opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, - s->last_lit)); - - if (static_lenb <= opt_lenb) opt_lenb = static_lenb; - - } else { - Assert(buf != (char*)0, "lost buf"); - opt_lenb = static_lenb = stored_len + 5; /* force a stored block */ - } - -#ifdef FORCE_STORED - if (buf != (char*)0) { /* force stored block */ -#else - if (stored_len+4 <= opt_lenb && buf != (char*)0) { - /* 4: two words for the lengths */ -#endif - /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE. - * Otherwise we can't have processed more than WSIZE input bytes since - * the last block flush, because compression would have been - * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to - * transform a block into a stored block. - */ - _tr_stored_block(s, buf, stored_len, last); - -#ifdef FORCE_STATIC - } else if (static_lenb >= 0) { /* force static trees */ -#else - } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) { -#endif - send_bits(s, (STATIC_TREES<<1)+last, 3); - compress_block(s, (const ct_data *)static_ltree, - (const ct_data *)static_dtree); -#ifdef DEBUG - s->compressed_len += 3 + s->static_len; -#endif - } else { - send_bits(s, (DYN_TREES<<1)+last, 3); - send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1, - max_blindex+1); - compress_block(s, (const ct_data *)s->dyn_ltree, - (const ct_data *)s->dyn_dtree); -#ifdef DEBUG - s->compressed_len += 3 + s->opt_len; -#endif - } - Assert (s->compressed_len == s->bits_sent, "bad compressed size"); - /* The above check is made mod 2^32, for files larger than 512 MB - * and uLong implemented on 32 bits. - */ - init_block(s); - - if (last) { - bi_windup(s); -#ifdef DEBUG - s->compressed_len += 7; /* align on byte boundary */ -#endif - } - Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3, - s->compressed_len-7*last)); -} - -/* =========================================================================== - * Save the match info and tally the frequency counts. Return true if - * the current block must be flushed. - */ -int ZLIB_INTERNAL _tr_tally (s, dist, lc) - deflate_state *s; - unsigned dist; /* distance of matched string */ - unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */ -{ - s->d_buf[s->last_lit] = (ush)dist; - s->l_buf[s->last_lit++] = (uch)lc; - if (dist == 0) { - /* lc is the unmatched char */ - s->dyn_ltree[lc].Freq++; - } else { - s->matches++; - /* Here, lc is the match length - MIN_MATCH */ - dist--; /* dist = match distance - 1 */ - Assert((ush)dist < (ush)MAX_DIST(s) && - (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && - (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match"); - - s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++; - s->dyn_dtree[d_code(dist)].Freq++; - } - -#ifdef TRUNCATE_BLOCK - /* Try to guess if it is profitable to stop the current block here */ - if ((s->last_lit & 0x1fff) == 0 && s->level > 2) { - /* Compute an upper bound for the compressed length */ - ulg out_length = (ulg)s->last_lit*8L; - ulg in_length = (ulg)((long)s->strstart - s->block_start); - int dcode; - for (dcode = 0; dcode < D_CODES; dcode++) { - out_length += (ulg)s->dyn_dtree[dcode].Freq * - (5L+extra_dbits[dcode]); - } - out_length >>= 3; - Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ", - s->last_lit, in_length, out_length, - 100L - out_length*100L/in_length)); - if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1; - } -#endif - return (s->last_lit == s->lit_bufsize-1); - /* We avoid equality with lit_bufsize because of wraparound at 64K - * on 16 bit machines and because stored blocks are restricted to - * 64K-1 bytes. - */ -} - -/* =========================================================================== - * Send the block data compressed using the given Huffman trees - */ -local void compress_block(s, ltree, dtree) - deflate_state *s; - const ct_data *ltree; /* literal tree */ - const ct_data *dtree; /* distance tree */ -{ - unsigned dist; /* distance of matched string */ - int lc; /* match length or unmatched char (if dist == 0) */ - unsigned lx = 0; /* running index in l_buf */ - unsigned code; /* the code to send */ - int extra; /* number of extra bits to send */ - - if (s->last_lit != 0) do { - dist = s->d_buf[lx]; - lc = s->l_buf[lx++]; - if (dist == 0) { - send_code(s, lc, ltree); /* send a literal byte */ - Tracecv(isgraph(lc), (stderr," '%c' ", lc)); - } else { - /* Here, lc is the match length - MIN_MATCH */ - code = _length_code[lc]; - send_code(s, code+LITERALS+1, ltree); /* send the length code */ - extra = extra_lbits[code]; - if (extra != 0) { - lc -= base_length[code]; - send_bits(s, lc, extra); /* send the extra length bits */ - } - dist--; /* dist is now the match distance - 1 */ - code = d_code(dist); - Assert (code < D_CODES, "bad d_code"); - - send_code(s, code, dtree); /* send the distance code */ - extra = extra_dbits[code]; - if (extra != 0) { - dist -= base_dist[code]; - send_bits(s, dist, extra); /* send the extra distance bits */ - } - } /* literal or match pair ? */ - - /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */ - Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx, - "pendingBuf overflow"); - - } while (lx < s->last_lit); - - send_code(s, END_BLOCK, ltree); -} - -/* =========================================================================== - * Check if the data type is TEXT or BINARY, using the following algorithm: - * - TEXT if the two conditions below are satisfied: - * a) There are no non-portable control characters belonging to the - * "black list" (0..6, 14..25, 28..31). - * b) There is at least one printable character belonging to the - * "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255). - * - BINARY otherwise. - * - The following partially-portable control characters form a - * "gray list" that is ignored in this detection algorithm: - * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}). - * IN assertion: the fields Freq of dyn_ltree are set. - */ -local int detect_data_type(s) - deflate_state *s; -{ - /* black_mask is the bit mask of black-listed bytes - * set bits 0..6, 14..25, and 28..31 - * 0xf3ffc07f = binary 11110011111111111100000001111111 - */ - unsigned long black_mask = 0xf3ffc07fUL; - int n; - - /* Check for non-textual ("black-listed") bytes. */ - for (n = 0; n <= 31; n++, black_mask >>= 1) - if ((black_mask & 1) && (s->dyn_ltree[n].Freq != 0)) - return Z_BINARY; - - /* Check for textual ("white-listed") bytes. */ - if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0 - || s->dyn_ltree[13].Freq != 0) - return Z_TEXT; - for (n = 32; n < LITERALS; n++) - if (s->dyn_ltree[n].Freq != 0) - return Z_TEXT; - - /* There are no "black-listed" or "white-listed" bytes: - * this stream either is empty or has tolerated ("gray-listed") bytes only. - */ - return Z_BINARY; -} - -/* =========================================================================== - * Reverse the first len bits of a code, using straightforward code (a faster - * method would use a table) - * IN assertion: 1 <= len <= 15 - */ -local unsigned bi_reverse(code, len) - unsigned code; /* the value to invert */ - int len; /* its bit length */ -{ - register unsigned res = 0; - do { - res |= code & 1; - code >>= 1, res <<= 1; - } while (--len > 0); - return res >> 1; -} - -/* =========================================================================== - * Flush the bit buffer, keeping at most 7 bits in it. - */ -local void bi_flush(s) - deflate_state *s; -{ - if (s->bi_valid == 16) { - put_short(s, s->bi_buf); - s->bi_buf = 0; - s->bi_valid = 0; - } else if (s->bi_valid >= 8) { - put_byte(s, (Byte)s->bi_buf); - s->bi_buf >>= 8; - s->bi_valid -= 8; - } -} - -/* =========================================================================== - * Flush the bit buffer and align the output on a byte boundary - */ -local void bi_windup(s) - deflate_state *s; -{ - if (s->bi_valid > 8) { - put_short(s, s->bi_buf); - } else if (s->bi_valid > 0) { - put_byte(s, (Byte)s->bi_buf); - } - s->bi_buf = 0; - s->bi_valid = 0; -#ifdef DEBUG - s->bits_sent = (s->bits_sent+7) & ~7; -#endif -} - -/* =========================================================================== - * Copy a stored block, storing first the length and its - * one's complement if requested. - */ -local void copy_block(s, buf, len, header) - deflate_state *s; - charf *buf; /* the input data */ - unsigned len; /* its length */ - int header; /* true if block header must be written */ -{ - bi_windup(s); /* align on byte boundary */ - - if (header) { - put_short(s, (ush)len); - put_short(s, (ush)~len); -#ifdef DEBUG - s->bits_sent += 2*16; -#endif - } -#ifdef DEBUG - s->bits_sent += (ulg)len<<3; -#endif - while (len--) { - put_byte(s, *buf++); - } -} diff --git a/src/beast/test/zlib/zlib-1.2.8/trees.h b/src/beast/test/zlib/zlib-1.2.8/trees.h deleted file mode 100644 index d35639d82a2..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/trees.h +++ /dev/null @@ -1,128 +0,0 @@ -/* header created automatically with -DGEN_TREES_H */ - -local const ct_data static_ltree[L_CODES+2] = { -{{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}}, -{{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}}, -{{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}}, -{{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}}, -{{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}}, -{{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}}, -{{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}}, -{{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}}, -{{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}}, -{{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}}, -{{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}}, -{{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}}, -{{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}}, -{{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}}, -{{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}}, -{{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}}, -{{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}}, -{{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}}, -{{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}}, -{{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}}, -{{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}}, -{{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}}, -{{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}}, -{{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}}, -{{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}}, -{{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}}, -{{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}}, -{{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}}, -{{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}}, -{{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}}, -{{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}}, -{{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}}, -{{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}}, -{{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}}, -{{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}}, -{{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}}, -{{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}}, -{{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}}, -{{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}}, -{{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}}, -{{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}}, -{{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}}, -{{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}}, -{{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}}, -{{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}}, -{{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}}, -{{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}}, -{{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}}, -{{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}}, -{{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}}, -{{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}}, -{{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}}, -{{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}}, -{{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}}, -{{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}}, -{{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}}, -{{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}}, -{{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}} -}; - -local const ct_data static_dtree[D_CODES] = { -{{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}}, -{{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}}, -{{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}}, -{{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}}, -{{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}}, -{{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}} -}; - -const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = { - 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, - 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, -10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, -11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, -12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, -13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, -13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, -14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, -14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, -14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, -15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, -15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, -15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17, -18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, -23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, -24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, -26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, -26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, -27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, -27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, -28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, -28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, -28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, -29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, -29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, -29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29 -}; - -const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, -13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, -17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, -19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, -21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, -22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, -23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, -24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, -25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, -25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, -26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, -26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, -27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28 -}; - -local const int base_length[LENGTH_CODES] = { -0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, -64, 80, 96, 112, 128, 160, 192, 224, 0 -}; - -local const int base_dist[D_CODES] = { - 0, 1, 2, 3, 4, 6, 8, 12, 16, 24, - 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, - 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576 -}; - diff --git a/src/beast/test/zlib/zlib-1.2.8/uncompr.c b/src/beast/test/zlib/zlib-1.2.8/uncompr.c deleted file mode 100644 index 242e9493dff..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/uncompr.c +++ /dev/null @@ -1,59 +0,0 @@ -/* uncompr.c -- decompress a memory buffer - * Copyright (C) 1995-2003, 2010 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id$ */ - -#define ZLIB_INTERNAL -#include "zlib.h" - -/* =========================================================================== - Decompresses the source buffer into the destination buffer. sourceLen is - the byte length of the source buffer. Upon entry, destLen is the total - size of the destination buffer, which must be large enough to hold the - entire uncompressed data. (The size of the uncompressed data must have - been saved previously by the compressor and transmitted to the decompressor - by some mechanism outside the scope of this compression library.) - Upon exit, destLen is the actual size of the compressed buffer. - - uncompress returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_BUF_ERROR if there was not enough room in the output - buffer, or Z_DATA_ERROR if the input data was corrupted. -*/ -int ZEXPORT uncompress (dest, destLen, source, sourceLen) - Bytef *dest; - uLongf *destLen; - const Bytef *source; - uLong sourceLen; -{ - z_stream stream; - int err; - - stream.next_in = (z_const Bytef *)source; - stream.avail_in = (uInt)sourceLen; - /* Check for source > 64K on 16-bit machine: */ - if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; - - stream.next_out = dest; - stream.avail_out = (uInt)*destLen; - if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; - - stream.zalloc = (alloc_func)0; - stream.zfree = (free_func)0; - - err = inflateInit(&stream); - if (err != Z_OK) return err; - - err = inflate(&stream, Z_FINISH); - if (err != Z_STREAM_END) { - inflateEnd(&stream); - if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) - return Z_DATA_ERROR; - return err; - } - *destLen = stream.total_out; - - err = inflateEnd(&stream); - return err; -} diff --git a/src/beast/test/zlib/zlib-1.2.8/watcom/watcom_f.mak b/src/beast/test/zlib/zlib-1.2.8/watcom/watcom_f.mak deleted file mode 100644 index 37f4d74c19c..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/watcom/watcom_f.mak +++ /dev/null @@ -1,43 +0,0 @@ -# Makefile for zlib -# OpenWatcom flat model -# Last updated: 28-Dec-2005 - -# To use, do "wmake -f watcom_f.mak" - -C_SOURCE = adler32.c compress.c crc32.c deflate.c & - gzclose.c gzlib.c gzread.c gzwrite.c & - infback.c inffast.c inflate.c inftrees.c & - trees.c uncompr.c zutil.c - -OBJS = adler32.obj compress.obj crc32.obj deflate.obj & - gzclose.obj gzlib.obj gzread.obj gzwrite.obj & - infback.obj inffast.obj inflate.obj inftrees.obj & - trees.obj uncompr.obj zutil.obj - -CC = wcc386 -LINKER = wcl386 -CFLAGS = -zq -mf -3r -fp3 -s -bt=dos -oilrtfm -fr=nul -wx -ZLIB_LIB = zlib_f.lib - -.C.OBJ: - $(CC) $(CFLAGS) $[@ - -all: $(ZLIB_LIB) example.exe minigzip.exe - -$(ZLIB_LIB): $(OBJS) - wlib -b -c $(ZLIB_LIB) -+adler32.obj -+compress.obj -+crc32.obj - wlib -b -c $(ZLIB_LIB) -+gzclose.obj -+gzlib.obj -+gzread.obj -+gzwrite.obj - wlib -b -c $(ZLIB_LIB) -+deflate.obj -+infback.obj - wlib -b -c $(ZLIB_LIB) -+inffast.obj -+inflate.obj -+inftrees.obj - wlib -b -c $(ZLIB_LIB) -+trees.obj -+uncompr.obj -+zutil.obj - -example.exe: $(ZLIB_LIB) example.obj - $(LINKER) -ldos32a -fe=example.exe example.obj $(ZLIB_LIB) - -minigzip.exe: $(ZLIB_LIB) minigzip.obj - $(LINKER) -ldos32a -fe=minigzip.exe minigzip.obj $(ZLIB_LIB) - -clean: .SYMBOLIC - del *.obj - del $(ZLIB_LIB) - @echo Cleaning done diff --git a/src/beast/test/zlib/zlib-1.2.8/watcom/watcom_l.mak b/src/beast/test/zlib/zlib-1.2.8/watcom/watcom_l.mak deleted file mode 100644 index 193eed7b318..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/watcom/watcom_l.mak +++ /dev/null @@ -1,43 +0,0 @@ -# Makefile for zlib -# OpenWatcom large model -# Last updated: 28-Dec-2005 - -# To use, do "wmake -f watcom_l.mak" - -C_SOURCE = adler32.c compress.c crc32.c deflate.c & - gzclose.c gzlib.c gzread.c gzwrite.c & - infback.c inffast.c inflate.c inftrees.c & - trees.c uncompr.c zutil.c - -OBJS = adler32.obj compress.obj crc32.obj deflate.obj & - gzclose.obj gzlib.obj gzread.obj gzwrite.obj & - infback.obj inffast.obj inflate.obj inftrees.obj & - trees.obj uncompr.obj zutil.obj - -CC = wcc -LINKER = wcl -CFLAGS = -zq -ml -s -bt=dos -oilrtfm -fr=nul -wx -ZLIB_LIB = zlib_l.lib - -.C.OBJ: - $(CC) $(CFLAGS) $[@ - -all: $(ZLIB_LIB) example.exe minigzip.exe - -$(ZLIB_LIB): $(OBJS) - wlib -b -c $(ZLIB_LIB) -+adler32.obj -+compress.obj -+crc32.obj - wlib -b -c $(ZLIB_LIB) -+gzclose.obj -+gzlib.obj -+gzread.obj -+gzwrite.obj - wlib -b -c $(ZLIB_LIB) -+deflate.obj -+infback.obj - wlib -b -c $(ZLIB_LIB) -+inffast.obj -+inflate.obj -+inftrees.obj - wlib -b -c $(ZLIB_LIB) -+trees.obj -+uncompr.obj -+zutil.obj - -example.exe: $(ZLIB_LIB) example.obj - $(LINKER) -fe=example.exe example.obj $(ZLIB_LIB) - -minigzip.exe: $(ZLIB_LIB) minigzip.obj - $(LINKER) -fe=minigzip.exe minigzip.obj $(ZLIB_LIB) - -clean: .SYMBOLIC - del *.obj - del $(ZLIB_LIB) - @echo Cleaning done diff --git a/src/beast/test/zlib/zlib-1.2.8/win32/DLL_FAQ.txt b/src/beast/test/zlib/zlib-1.2.8/win32/DLL_FAQ.txt deleted file mode 100644 index 12c009018c3..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/win32/DLL_FAQ.txt +++ /dev/null @@ -1,397 +0,0 @@ - - Frequently Asked Questions about ZLIB1.DLL - - -This document describes the design, the rationale, and the usage -of the official DLL build of zlib, named ZLIB1.DLL. If you have -general questions about zlib, you should see the file "FAQ" found -in the zlib distribution, or at the following location: - http://www.gzip.org/zlib/zlib_faq.html - - - 1. What is ZLIB1.DLL, and how can I get it? - - - ZLIB1.DLL is the official build of zlib as a DLL. - (Please remark the character '1' in the name.) - - Pointers to a precompiled ZLIB1.DLL can be found in the zlib - web site at: - http://www.zlib.net/ - - Applications that link to ZLIB1.DLL can rely on the following - specification: - - * The exported symbols are exclusively defined in the source - files "zlib.h" and "zlib.def", found in an official zlib - source distribution. - * The symbols are exported by name, not by ordinal. - * The exported names are undecorated. - * The calling convention of functions is "C" (CDECL). - * The ZLIB1.DLL binary is linked to MSVCRT.DLL. - - The archive in which ZLIB1.DLL is bundled contains compiled - test programs that must run with a valid build of ZLIB1.DLL. - It is recommended to download the prebuilt DLL from the zlib - web site, instead of building it yourself, to avoid potential - incompatibilities that could be introduced by your compiler - and build settings. If you do build the DLL yourself, please - make sure that it complies with all the above requirements, - and it runs with the precompiled test programs, bundled with - the original ZLIB1.DLL distribution. - - If, for any reason, you need to build an incompatible DLL, - please use a different file name. - - - 2. Why did you change the name of the DLL to ZLIB1.DLL? - What happened to the old ZLIB.DLL? - - - The old ZLIB.DLL, built from zlib-1.1.4 or earlier, required - compilation settings that were incompatible to those used by - a static build. The DLL settings were supposed to be enabled - by defining the macro ZLIB_DLL, before including "zlib.h". - Incorrect handling of this macro was silently accepted at - build time, resulting in two major problems: - - * ZLIB_DLL was missing from the old makefile. When building - the DLL, not all people added it to the build options. In - consequence, incompatible incarnations of ZLIB.DLL started - to circulate around the net. - - * When switching from using the static library to using the - DLL, applications had to define the ZLIB_DLL macro and - to recompile all the sources that contained calls to zlib - functions. Failure to do so resulted in creating binaries - that were unable to run with the official ZLIB.DLL build. - - The only possible solution that we could foresee was to make - a binary-incompatible change in the DLL interface, in order to - remove the dependency on the ZLIB_DLL macro, and to release - the new DLL under a different name. - - We chose the name ZLIB1.DLL, where '1' indicates the major - zlib version number. We hope that we will not have to break - the binary compatibility again, at least not as long as the - zlib-1.x series will last. - - There is still a ZLIB_DLL macro, that can trigger a more - efficient build and use of the DLL, but compatibility no - longer dependents on it. - - - 3. Can I build ZLIB.DLL from the new zlib sources, and replace - an old ZLIB.DLL, that was built from zlib-1.1.4 or earlier? - - - In principle, you can do it by assigning calling convention - keywords to the macros ZEXPORT and ZEXPORTVA. In practice, - it depends on what you mean by "an old ZLIB.DLL", because the - old DLL exists in several mutually-incompatible versions. - You have to find out first what kind of calling convention is - being used in your particular ZLIB.DLL build, and to use the - same one in the new build. If you don't know what this is all - about, you might be better off if you would just leave the old - DLL intact. - - - 4. Can I compile my application using the new zlib interface, and - link it to an old ZLIB.DLL, that was built from zlib-1.1.4 or - earlier? - - - The official answer is "no"; the real answer depends again on - what kind of ZLIB.DLL you have. Even if you are lucky, this - course of action is unreliable. - - If you rebuild your application and you intend to use a newer - version of zlib (post- 1.1.4), it is strongly recommended to - link it to the new ZLIB1.DLL. - - - 5. Why are the zlib symbols exported by name, and not by ordinal? - - - Although exporting symbols by ordinal is a little faster, it - is risky. Any single glitch in the maintenance or use of the - DEF file that contains the ordinals can result in incompatible - builds and frustrating crashes. Simply put, the benefits of - exporting symbols by ordinal do not justify the risks. - - Technically, it should be possible to maintain ordinals in - the DEF file, and still export the symbols by name. Ordinals - exist in every DLL, and even if the dynamic linking performed - at the DLL startup is searching for names, ordinals serve as - hints, for a faster name lookup. However, if the DEF file - contains ordinals, the Microsoft linker automatically builds - an implib that will cause the executables linked to it to use - those ordinals, and not the names. It is interesting to - notice that the GNU linker for Win32 does not suffer from this - problem. - - It is possible to avoid the DEF file if the exported symbols - are accompanied by a "__declspec(dllexport)" attribute in the - source files. You can do this in zlib by predefining the - ZLIB_DLL macro. - - - 6. I see that the ZLIB1.DLL functions use the "C" (CDECL) calling - convention. Why not use the STDCALL convention? - STDCALL is the standard convention in Win32, and I need it in - my Visual Basic project! - - (For readability, we use CDECL to refer to the convention - triggered by the "__cdecl" keyword, STDCALL to refer to - the convention triggered by "__stdcall", and FASTCALL to - refer to the convention triggered by "__fastcall".) - - - Most of the native Windows API functions (without varargs) use - indeed the WINAPI convention (which translates to STDCALL in - Win32), but the standard C functions use CDECL. If a user - application is intrinsically tied to the Windows API (e.g. - it calls native Windows API functions such as CreateFile()), - sometimes it makes sense to decorate its own functions with - WINAPI. But if ANSI C or POSIX portability is a goal (e.g. - it calls standard C functions such as fopen()), it is not a - sound decision to request the inclusion of , or to - use non-ANSI constructs, for the sole purpose to make the user - functions STDCALL-able. - - The functionality offered by zlib is not in the category of - "Windows functionality", but is more like "C functionality". - - Technically, STDCALL is not bad; in fact, it is slightly - faster than CDECL, and it works with variable-argument - functions, just like CDECL. It is unfortunate that, in spite - of using STDCALL in the Windows API, it is not the default - convention used by the C compilers that run under Windows. - The roots of the problem reside deep inside the unsafety of - the K&R-style function prototypes, where the argument types - are not specified; but that is another story for another day. - - The remaining fact is that CDECL is the default convention. - Even if an explicit convention is hard-coded into the function - prototypes inside C headers, problems may appear. The - necessity to expose the convention in users' callbacks is one - of these problems. - - The calling convention issues are also important when using - zlib in other programming languages. Some of them, like Ada - (GNAT) and Fortran (GNU G77), have C bindings implemented - initially on Unix, and relying on the C calling convention. - On the other hand, the pre- .NET versions of Microsoft Visual - Basic require STDCALL, while Borland Delphi prefers, although - it does not require, FASTCALL. - - In fairness to all possible uses of zlib outside the C - programming language, we choose the default "C" convention. - Anyone interested in different bindings or conventions is - encouraged to maintain specialized projects. The "contrib/" - directory from the zlib distribution already holds a couple - of foreign bindings, such as Ada, C++, and Delphi. - - - 7. I need a DLL for my Visual Basic project. What can I do? - - - Define the ZLIB_WINAPI macro before including "zlib.h", when - building both the DLL and the user application (except that - you don't need to define anything when using the DLL in Visual - Basic). The ZLIB_WINAPI macro will switch on the WINAPI - (STDCALL) convention. The name of this DLL must be different - than the official ZLIB1.DLL. - - Gilles Vollant has contributed a build named ZLIBWAPI.DLL, - with the ZLIB_WINAPI macro turned on, and with the minizip - functionality built in. For more information, please read - the notes inside "contrib/vstudio/readme.txt", found in the - zlib distribution. - - - 8. I need to use zlib in my Microsoft .NET project. What can I - do? - - - Henrik Ravn has contributed a .NET wrapper around zlib. Look - into contrib/dotzlib/, inside the zlib distribution. - - - 9. If my application uses ZLIB1.DLL, should I link it to - MSVCRT.DLL? Why? - - - It is not required, but it is recommended to link your - application to MSVCRT.DLL, if it uses ZLIB1.DLL. - - The executables (.EXE, .DLL, etc.) that are involved in the - same process and are using the C run-time library (i.e. they - are calling standard C functions), must link to the same - library. There are several libraries in the Win32 system: - CRTDLL.DLL, MSVCRT.DLL, the static C libraries, etc. - Since ZLIB1.DLL is linked to MSVCRT.DLL, the executables that - depend on it should also be linked to MSVCRT.DLL. - - -10. Why are you saying that ZLIB1.DLL and my application should - be linked to the same C run-time (CRT) library? I linked my - application and my DLLs to different C libraries (e.g. my - application to a static library, and my DLLs to MSVCRT.DLL), - and everything works fine. - - - If a user library invokes only pure Win32 API (accessible via - and the related headers), its DLL build will work - in any context. But if this library invokes standard C API, - things get more complicated. - - There is a single Win32 library in a Win32 system. Every - function in this library resides in a single DLL module, that - is safe to call from anywhere. On the other hand, there are - multiple versions of the C library, and each of them has its - own separate internal state. Standalone executables and user - DLLs that call standard C functions must link to a C run-time - (CRT) library, be it static or shared (DLL). Intermixing - occurs when an executable (not necessarily standalone) and a - DLL are linked to different CRTs, and both are running in the - same process. - - Intermixing multiple CRTs is possible, as long as their - internal states are kept intact. The Microsoft Knowledge Base - articles KB94248 "HOWTO: Use the C Run-Time" and KB140584 - "HOWTO: Link with the Correct C Run-Time (CRT) Library" - mention the potential problems raised by intermixing. - - If intermixing works for you, it's because your application - and DLLs are avoiding the corruption of each of the CRTs' - internal states, maybe by careful design, or maybe by fortune. - - Also note that linking ZLIB1.DLL to non-Microsoft CRTs, such - as those provided by Borland, raises similar problems. - - -11. Why are you linking ZLIB1.DLL to MSVCRT.DLL? - - - MSVCRT.DLL exists on every Windows 95 with a new service pack - installed, or with Microsoft Internet Explorer 4 or later, and - on all other Windows 4.x or later (Windows 98, Windows NT 4, - or later). It is freely distributable; if not present in the - system, it can be downloaded from Microsoft or from other - software provider for free. - - The fact that MSVCRT.DLL does not exist on a virgin Windows 95 - is not so problematic. Windows 95 is scarcely found nowadays, - Microsoft ended its support a long time ago, and many recent - applications from various vendors, including Microsoft, do not - even run on it. Furthermore, no serious user should run - Windows 95 without a proper update installed. - - -12. Why are you not linking ZLIB1.DLL to - <> ? - - - We considered and abandoned the following alternatives: - - * Linking ZLIB1.DLL to a static C library (LIBC.LIB, or - LIBCMT.LIB) is not a good option. People are using the DLL - mainly to save disk space. If you are linking your program - to a static C library, you may as well consider linking zlib - in statically, too. - - * Linking ZLIB1.DLL to CRTDLL.DLL looks appealing, because - CRTDLL.DLL is present on every Win32 installation. - Unfortunately, it has a series of problems: it does not - work properly with Microsoft's C++ libraries, it does not - provide support for 64-bit file offsets, (and so on...), - and Microsoft discontinued its support a long time ago. - - * Linking ZLIB1.DLL to MSVCR70.DLL or MSVCR71.DLL, supplied - with the Microsoft .NET platform, and Visual C++ 7.0/7.1, - raises problems related to the status of ZLIB1.DLL as a - system component. According to the Microsoft Knowledge Base - article KB326922 "INFO: Redistribution of the Shared C - Runtime Component in Visual C++ .NET", MSVCR70.DLL and - MSVCR71.DLL are not supposed to function as system DLLs, - because they may clash with MSVCRT.DLL. Instead, the - application's installer is supposed to put these DLLs - (if needed) in the application's private directory. - If ZLIB1.DLL depends on a non-system runtime, it cannot - function as a redistributable system component. - - * Linking ZLIB1.DLL to non-Microsoft runtimes, such as - Borland's, or Cygwin's, raises problems related to the - reliable presence of these runtimes on Win32 systems. - It's easier to let the DLL build of zlib up to the people - who distribute these runtimes, and who may proceed as - explained in the answer to Question 14. - - -13. If ZLIB1.DLL cannot be linked to MSVCR70.DLL or MSVCR71.DLL, - how can I build/use ZLIB1.DLL in Microsoft Visual C++ 7.0 - (Visual Studio .NET) or newer? - - - Due to the problems explained in the Microsoft Knowledge Base - article KB326922 (see the previous answer), the C runtime that - comes with the VC7 environment is no longer considered a - system component. That is, it should not be assumed that this - runtime exists, or may be installed in a system directory. - Since ZLIB1.DLL is supposed to be a system component, it may - not depend on a non-system component. - - In order to link ZLIB1.DLL and your application to MSVCRT.DLL - in VC7, you need the library of Visual C++ 6.0 or older. If - you don't have this library at hand, it's probably best not to - use ZLIB1.DLL. - - We are hoping that, in the future, Microsoft will provide a - way to build applications linked to a proper system runtime, - from the Visual C++ environment. Until then, you have a - couple of alternatives, such as linking zlib in statically. - If your application requires dynamic linking, you may proceed - as explained in the answer to Question 14. - - -14. I need to link my own DLL build to a CRT different than - MSVCRT.DLL. What can I do? - - - Feel free to rebuild the DLL from the zlib sources, and link - it the way you want. You should, however, clearly state that - your build is unofficial. You should give it a different file - name, and/or install it in a private directory that can be - accessed by your application only, and is not visible to the - others (i.e. it's neither in the PATH, nor in the SYSTEM or - SYSTEM32 directories). Otherwise, your build may clash with - applications that link to the official build. - - For example, in Cygwin, zlib is linked to the Cygwin runtime - CYGWIN1.DLL, and it is distributed under the name CYGZ.DLL. - - -15. May I include additional pieces of code that I find useful, - link them in ZLIB1.DLL, and export them? - - - No. A legitimate build of ZLIB1.DLL must not include code - that does not originate from the official zlib source code. - But you can make your own private DLL build, under a different - file name, as suggested in the previous answer. - - For example, zlib is a part of the VCL library, distributed - with Borland Delphi and C++ Builder. The DLL build of VCL - is a redistributable file, named VCLxx.DLL. - - -16. May I remove some functionality out of ZLIB1.DLL, by enabling - macros like NO_GZCOMPRESS or NO_GZIP at compile time? - - - No. A legitimate build of ZLIB1.DLL must provide the complete - zlib functionality, as implemented in the official zlib source - code. But you can make your own private DLL build, under a - different file name, as suggested in the previous answer. - - -17. I made my own ZLIB1.DLL build. Can I test it for compliance? - - - We prefer that you download the official DLL from the zlib - web site. If you need something peculiar from this DLL, you - can send your suggestion to the zlib mailing list. - - However, in case you do rebuild the DLL yourself, you can run - it with the test programs found in the DLL distribution. - Running these test programs is not a guarantee of compliance, - but a failure can imply a detected problem. - -** - -This document is written and maintained by -Cosmin Truta diff --git a/src/beast/test/zlib/zlib-1.2.8/win32/Makefile.bor b/src/beast/test/zlib/zlib-1.2.8/win32/Makefile.bor deleted file mode 100644 index d152bbb7ffd..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/win32/Makefile.bor +++ /dev/null @@ -1,110 +0,0 @@ -# Makefile for zlib -# Borland C++ for Win32 -# -# Usage: -# make -f win32/Makefile.bor -# make -f win32/Makefile.bor LOCAL_ZLIB=-DASMV OBJA=match.obj OBJPA=+match.obj - -# ------------ Borland C++ ------------ - -# Optional nonstandard preprocessor flags (e.g. -DMAX_MEM_LEVEL=7) -# should be added to the environment via "set LOCAL_ZLIB=-DFOO" or -# added to the declaration of LOC here: -LOC = $(LOCAL_ZLIB) - -CC = bcc32 -AS = bcc32 -LD = bcc32 -AR = tlib -CFLAGS = -a -d -k- -O2 $(LOC) -ASFLAGS = $(LOC) -LDFLAGS = $(LOC) - - -# variables -ZLIB_LIB = zlib.lib - -OBJ1 = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzlib.obj gzread.obj -OBJ2 = gzwrite.obj infback.obj inffast.obj inflate.obj inftrees.obj trees.obj uncompr.obj zutil.obj -#OBJA = -OBJP1 = +adler32.obj+compress.obj+crc32.obj+deflate.obj+gzclose.obj+gzlib.obj+gzread.obj -OBJP2 = +gzwrite.obj+infback.obj+inffast.obj+inflate.obj+inftrees.obj+trees.obj+uncompr.obj+zutil.obj -#OBJPA= - - -# targets -all: $(ZLIB_LIB) example.exe minigzip.exe - -.c.obj: - $(CC) -c $(CFLAGS) $< - -.asm.obj: - $(AS) -c $(ASFLAGS) $< - -adler32.obj: adler32.c zlib.h zconf.h - -compress.obj: compress.c zlib.h zconf.h - -crc32.obj: crc32.c zlib.h zconf.h crc32.h - -deflate.obj: deflate.c deflate.h zutil.h zlib.h zconf.h - -gzclose.obj: gzclose.c zlib.h zconf.h gzguts.h - -gzlib.obj: gzlib.c zlib.h zconf.h gzguts.h - -gzread.obj: gzread.c zlib.h zconf.h gzguts.h - -gzwrite.obj: gzwrite.c zlib.h zconf.h gzguts.h - -infback.obj: infback.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ - inffast.h inffixed.h - -inffast.obj: inffast.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ - inffast.h - -inflate.obj: inflate.c zutil.h zlib.h zconf.h inftrees.h inflate.h \ - inffast.h inffixed.h - -inftrees.obj: inftrees.c zutil.h zlib.h zconf.h inftrees.h - -trees.obj: trees.c zutil.h zlib.h zconf.h deflate.h trees.h - -uncompr.obj: uncompr.c zlib.h zconf.h - -zutil.obj: zutil.c zutil.h zlib.h zconf.h - -example.obj: test/example.c zlib.h zconf.h - -minigzip.obj: test/minigzip.c zlib.h zconf.h - - -# For the sake of the old Borland make, -# the command line is cut to fit in the MS-DOS 128 byte limit: -$(ZLIB_LIB): $(OBJ1) $(OBJ2) $(OBJA) - -del $(ZLIB_LIB) - $(AR) $(ZLIB_LIB) $(OBJP1) - $(AR) $(ZLIB_LIB) $(OBJP2) - $(AR) $(ZLIB_LIB) $(OBJPA) - - -# testing -test: example.exe minigzip.exe - example - echo hello world | minigzip | minigzip -d - -example.exe: example.obj $(ZLIB_LIB) - $(LD) $(LDFLAGS) example.obj $(ZLIB_LIB) - -minigzip.exe: minigzip.obj $(ZLIB_LIB) - $(LD) $(LDFLAGS) minigzip.obj $(ZLIB_LIB) - - -# cleanup -clean: - -del $(ZLIB_LIB) - -del *.obj - -del *.exe - -del *.tds - -del zlib.bak - -del foo.gz diff --git a/src/beast/test/zlib/zlib-1.2.8/win32/Makefile.gcc b/src/beast/test/zlib/zlib-1.2.8/win32/Makefile.gcc deleted file mode 100644 index 6d1ded622bf..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/win32/Makefile.gcc +++ /dev/null @@ -1,182 +0,0 @@ -# Makefile for zlib, derived from Makefile.dj2. -# Modified for mingw32 by C. Spieler, 6/16/98. -# Updated for zlib 1.2.x by Christian Spieler and Cosmin Truta, Mar-2003. -# Last updated: Mar 2012. -# Tested under Cygwin and MinGW. - -# Copyright (C) 1995-2003 Jean-loup Gailly. -# For conditions of distribution and use, see copyright notice in zlib.h - -# To compile, or to compile and test, type from the top level zlib directory: -# -# make -fwin32/Makefile.gcc; make test testdll -fwin32/Makefile.gcc -# -# To use the asm code, type: -# cp contrib/asm?86/match.S ./match.S -# make LOC=-DASMV OBJA=match.o -fwin32/Makefile.gcc -# -# To install libz.a, zconf.h and zlib.h in the system directories, type: -# -# make install -fwin32/Makefile.gcc -# -# BINARY_PATH, INCLUDE_PATH and LIBRARY_PATH must be set. -# -# To install the shared lib, append SHARED_MODE=1 to the make command : -# -# make install -fwin32/Makefile.gcc SHARED_MODE=1 - -# Note: -# If the platform is *not* MinGW (e.g. it is Cygwin or UWIN), -# the DLL name should be changed from "zlib1.dll". - -STATICLIB = libz.a -SHAREDLIB = zlib1.dll -IMPLIB = libz.dll.a - -# -# Set to 1 if shared object needs to be installed -# -SHARED_MODE=0 - -#LOC = -DASMV -#LOC = -DDEBUG -g - -PREFIX = -CC = $(PREFIX)gcc -CFLAGS = $(LOC) -O3 -Wall - -AS = $(CC) -ASFLAGS = $(LOC) -Wall - -LD = $(CC) -LDFLAGS = $(LOC) - -AR = $(PREFIX)ar -ARFLAGS = rcs - -RC = $(PREFIX)windres -RCFLAGS = --define GCC_WINDRES - -STRIP = $(PREFIX)strip - -CP = cp -fp -# If GNU install is available, replace $(CP) with install. -INSTALL = $(CP) -RM = rm -f - -prefix ?= /usr/local -exec_prefix = $(prefix) - -OBJS = adler32.o compress.o crc32.o deflate.o gzclose.o gzlib.o gzread.o \ - gzwrite.o infback.o inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o -OBJA = - -all: $(STATICLIB) $(SHAREDLIB) $(IMPLIB) example.exe minigzip.exe example_d.exe minigzip_d.exe - -test: example.exe minigzip.exe - ./example - echo hello world | ./minigzip | ./minigzip -d - -testdll: example_d.exe minigzip_d.exe - ./example_d - echo hello world | ./minigzip_d | ./minigzip_d -d - -.c.o: - $(CC) $(CFLAGS) -c -o $@ $< - -.S.o: - $(AS) $(ASFLAGS) -c -o $@ $< - -$(STATICLIB): $(OBJS) $(OBJA) - $(AR) $(ARFLAGS) $@ $(OBJS) $(OBJA) - -$(IMPLIB): $(SHAREDLIB) - -$(SHAREDLIB): win32/zlib.def $(OBJS) $(OBJA) zlibrc.o - $(CC) -shared -Wl,--out-implib,$(IMPLIB) $(LDFLAGS) \ - -o $@ win32/zlib.def $(OBJS) $(OBJA) zlibrc.o - $(STRIP) $@ - -example.exe: example.o $(STATICLIB) - $(LD) $(LDFLAGS) -o $@ example.o $(STATICLIB) - $(STRIP) $@ - -minigzip.exe: minigzip.o $(STATICLIB) - $(LD) $(LDFLAGS) -o $@ minigzip.o $(STATICLIB) - $(STRIP) $@ - -example_d.exe: example.o $(IMPLIB) - $(LD) $(LDFLAGS) -o $@ example.o $(IMPLIB) - $(STRIP) $@ - -minigzip_d.exe: minigzip.o $(IMPLIB) - $(LD) $(LDFLAGS) -o $@ minigzip.o $(IMPLIB) - $(STRIP) $@ - -example.o: test/example.c zlib.h zconf.h - $(CC) $(CFLAGS) -I. -c -o $@ test/example.c - -minigzip.o: test/minigzip.c zlib.h zconf.h - $(CC) $(CFLAGS) -I. -c -o $@ test/minigzip.c - -zlibrc.o: win32/zlib1.rc - $(RC) $(RCFLAGS) -o $@ win32/zlib1.rc - -.PHONY: install uninstall clean - -install: zlib.h zconf.h $(STATICLIB) $(IMPLIB) - @if test -z "$(DESTDIR)$(INCLUDE_PATH)" -o -z "$(DESTDIR)$(LIBRARY_PATH)" -o -z "$(DESTDIR)$(BINARY_PATH)"; then \ - echo INCLUDE_PATH, LIBRARY_PATH, and BINARY_PATH must be specified; \ - exit 1; \ - fi - -@mkdir -p '$(DESTDIR)$(INCLUDE_PATH)' - -@mkdir -p '$(DESTDIR)$(LIBRARY_PATH)' '$(DESTDIR)$(LIBRARY_PATH)'/pkgconfig - -if [ "$(SHARED_MODE)" = "1" ]; then \ - mkdir -p '$(DESTDIR)$(BINARY_PATH)'; \ - $(INSTALL) $(SHAREDLIB) '$(DESTDIR)$(BINARY_PATH)'; \ - $(INSTALL) $(IMPLIB) '$(DESTDIR)$(LIBRARY_PATH)'; \ - fi - -$(INSTALL) zlib.h '$(DESTDIR)$(INCLUDE_PATH)' - -$(INSTALL) zconf.h '$(DESTDIR)$(INCLUDE_PATH)' - -$(INSTALL) $(STATICLIB) '$(DESTDIR)$(LIBRARY_PATH)' - sed \ - -e 's|@prefix@|${prefix}|g' \ - -e 's|@exec_prefix@|${exec_prefix}|g' \ - -e 's|@libdir@|$(LIBRARY_PATH)|g' \ - -e 's|@sharedlibdir@|$(LIBRARY_PATH)|g' \ - -e 's|@includedir@|$(INCLUDE_PATH)|g' \ - -e 's|@VERSION@|'`sed -n -e '/VERSION "/s/.*"\(.*\)".*/\1/p' zlib.h`'|g' \ - zlib.pc.in > '$(DESTDIR)$(LIBRARY_PATH)'/pkgconfig/zlib.pc - -uninstall: - -if [ "$(SHARED_MODE)" = "1" ]; then \ - $(RM) '$(DESTDIR)$(BINARY_PATH)'/$(SHAREDLIB); \ - $(RM) '$(DESTDIR)$(LIBRARY_PATH)'/$(IMPLIB); \ - fi - -$(RM) '$(DESTDIR)$(INCLUDE_PATH)'/zlib.h - -$(RM) '$(DESTDIR)$(INCLUDE_PATH)'/zconf.h - -$(RM) '$(DESTDIR)$(LIBRARY_PATH)'/$(STATICLIB) - -clean: - -$(RM) $(STATICLIB) - -$(RM) $(SHAREDLIB) - -$(RM) $(IMPLIB) - -$(RM) *.o - -$(RM) *.exe - -$(RM) foo.gz - -adler32.o: zlib.h zconf.h -compress.o: zlib.h zconf.h -crc32.o: crc32.h zlib.h zconf.h -deflate.o: deflate.h zutil.h zlib.h zconf.h -gzclose.o: zlib.h zconf.h gzguts.h -gzlib.o: zlib.h zconf.h gzguts.h -gzread.o: zlib.h zconf.h gzguts.h -gzwrite.o: zlib.h zconf.h gzguts.h -inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h -inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h -infback.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h -inftrees.o: zutil.h zlib.h zconf.h inftrees.h -trees.o: deflate.h zutil.h zlib.h zconf.h trees.h -uncompr.o: zlib.h zconf.h -zutil.o: zutil.h zlib.h zconf.h diff --git a/src/beast/test/zlib/zlib-1.2.8/win32/Makefile.msc b/src/beast/test/zlib/zlib-1.2.8/win32/Makefile.msc deleted file mode 100644 index 67b773171da..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/win32/Makefile.msc +++ /dev/null @@ -1,163 +0,0 @@ -# Makefile for zlib using Microsoft (Visual) C -# zlib is copyright (C) 1995-2006 Jean-loup Gailly and Mark Adler -# -# Usage: -# nmake -f win32/Makefile.msc (standard build) -# nmake -f win32/Makefile.msc LOC=-DFOO (nonstandard build) -# nmake -f win32/Makefile.msc LOC="-DASMV -DASMINF" \ -# OBJA="inffas32.obj match686.obj" (use ASM code, x86) -# nmake -f win32/Makefile.msc AS=ml64 LOC="-DASMV -DASMINF -I." \ -# OBJA="inffasx64.obj gvmat64.obj inffas8664.obj" (use ASM code, x64) - -# The toplevel directory of the source tree. -# -TOP = . - -# optional build flags -LOC = - -# variables -STATICLIB = zlib.lib -SHAREDLIB = zlib1.dll -IMPLIB = zdll.lib - -CC = cl -AS = ml -LD = link -AR = lib -RC = rc -CFLAGS = -nologo -MD -W3 -O2 -Oy- -Zi -Fd"zlib" $(LOC) -WFLAGS = -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -ASFLAGS = -coff -Zi $(LOC) -LDFLAGS = -nologo -debug -incremental:no -opt:ref -ARFLAGS = -nologo -RCFLAGS = /dWIN32 /r - -OBJS = adler32.obj compress.obj crc32.obj deflate.obj gzclose.obj gzlib.obj gzread.obj \ - gzwrite.obj infback.obj inflate.obj inftrees.obj inffast.obj trees.obj uncompr.obj zutil.obj -OBJA = - - -# targets -all: $(STATICLIB) $(SHAREDLIB) $(IMPLIB) \ - example.exe minigzip.exe example_d.exe minigzip_d.exe - -$(STATICLIB): $(OBJS) $(OBJA) - $(AR) $(ARFLAGS) -out:$@ $(OBJS) $(OBJA) - -$(IMPLIB): $(SHAREDLIB) - -$(SHAREDLIB): $(TOP)/win32/zlib.def $(OBJS) $(OBJA) zlib1.res - $(LD) $(LDFLAGS) -def:$(TOP)/win32/zlib.def -dll -implib:$(IMPLIB) \ - -out:$@ -base:0x5A4C0000 $(OBJS) $(OBJA) zlib1.res - if exist $@.manifest \ - mt -nologo -manifest $@.manifest -outputresource:$@;2 - -example.exe: example.obj $(STATICLIB) - $(LD) $(LDFLAGS) example.obj $(STATICLIB) - if exist $@.manifest \ - mt -nologo -manifest $@.manifest -outputresource:$@;1 - -minigzip.exe: minigzip.obj $(STATICLIB) - $(LD) $(LDFLAGS) minigzip.obj $(STATICLIB) - if exist $@.manifest \ - mt -nologo -manifest $@.manifest -outputresource:$@;1 - -example_d.exe: example.obj $(IMPLIB) - $(LD) $(LDFLAGS) -out:$@ example.obj $(IMPLIB) - if exist $@.manifest \ - mt -nologo -manifest $@.manifest -outputresource:$@;1 - -minigzip_d.exe: minigzip.obj $(IMPLIB) - $(LD) $(LDFLAGS) -out:$@ minigzip.obj $(IMPLIB) - if exist $@.manifest \ - mt -nologo -manifest $@.manifest -outputresource:$@;1 - -{$(TOP)}.c.obj: - $(CC) -c $(WFLAGS) $(CFLAGS) $< - -{$(TOP)/test}.c.obj: - $(CC) -c -I$(TOP) $(WFLAGS) $(CFLAGS) $< - -{$(TOP)/contrib/masmx64}.c.obj: - $(CC) -c $(WFLAGS) $(CFLAGS) $< - -{$(TOP)/contrib/masmx64}.asm.obj: - $(AS) -c $(ASFLAGS) $< - -{$(TOP)/contrib/masmx86}.asm.obj: - $(AS) -c $(ASFLAGS) $< - -adler32.obj: $(TOP)/adler32.c $(TOP)/zlib.h $(TOP)/zconf.h - -compress.obj: $(TOP)/compress.c $(TOP)/zlib.h $(TOP)/zconf.h - -crc32.obj: $(TOP)/crc32.c $(TOP)/zlib.h $(TOP)/zconf.h $(TOP)/crc32.h - -deflate.obj: $(TOP)/deflate.c $(TOP)/deflate.h $(TOP)/zutil.h $(TOP)/zlib.h $(TOP)/zconf.h - -gzclose.obj: $(TOP)/gzclose.c $(TOP)/zlib.h $(TOP)/zconf.h $(TOP)/gzguts.h - -gzlib.obj: $(TOP)/gzlib.c $(TOP)/zlib.h $(TOP)/zconf.h $(TOP)/gzguts.h - -gzread.obj: $(TOP)/gzread.c $(TOP)/zlib.h $(TOP)/zconf.h $(TOP)/gzguts.h - -gzwrite.obj: $(TOP)/gzwrite.c $(TOP)/zlib.h $(TOP)/zconf.h $(TOP)/gzguts.h - -infback.obj: $(TOP)/infback.c $(TOP)/zutil.h $(TOP)/zlib.h $(TOP)/zconf.h $(TOP)/inftrees.h $(TOP)/inflate.h \ - $(TOP)/inffast.h $(TOP)/inffixed.h - -inffast.obj: $(TOP)/inffast.c $(TOP)/zutil.h $(TOP)/zlib.h $(TOP)/zconf.h $(TOP)/inftrees.h $(TOP)/inflate.h \ - $(TOP)/inffast.h - -inflate.obj: $(TOP)/inflate.c $(TOP)/zutil.h $(TOP)/zlib.h $(TOP)/zconf.h $(TOP)/inftrees.h $(TOP)/inflate.h \ - $(TOP)/inffast.h $(TOP)/inffixed.h - -inftrees.obj: $(TOP)/inftrees.c $(TOP)/zutil.h $(TOP)/zlib.h $(TOP)/zconf.h $(TOP)/inftrees.h - -trees.obj: $(TOP)/trees.c $(TOP)/zutil.h $(TOP)/zlib.h $(TOP)/zconf.h $(TOP)/deflate.h $(TOP)/trees.h - -uncompr.obj: $(TOP)/uncompr.c $(TOP)/zlib.h $(TOP)/zconf.h - -zutil.obj: $(TOP)/zutil.c $(TOP)/zutil.h $(TOP)/zlib.h $(TOP)/zconf.h - -gvmat64.obj: $(TOP)/contrib\masmx64\gvmat64.asm - -inffasx64.obj: $(TOP)/contrib\masmx64\inffasx64.asm - -inffas8664.obj: $(TOP)/contrib\masmx64\inffas8664.c $(TOP)/zutil.h $(TOP)/zlib.h $(TOP)/zconf.h \ - $(TOP)/inftrees.h $(TOP)/inflate.h $(TOP)/inffast.h - -inffas32.obj: $(TOP)/contrib\masmx86\inffas32.asm - -match686.obj: $(TOP)/contrib\masmx86\match686.asm - -example.obj: $(TOP)/test/example.c $(TOP)/zlib.h $(TOP)/zconf.h - -minigzip.obj: $(TOP)/test/minigzip.c $(TOP)/zlib.h $(TOP)/zconf.h - -zlib1.res: $(TOP)/win32/zlib1.rc - $(RC) $(RCFLAGS) /fo$@ $(TOP)/win32/zlib1.rc - -# testing -test: example.exe minigzip.exe - example - echo hello world | minigzip | minigzip -d - -testdll: example_d.exe minigzip_d.exe - example_d - echo hello world | minigzip_d | minigzip_d -d - - -# cleanup -clean: - -del $(STATICLIB) - -del $(SHAREDLIB) - -del $(IMPLIB) - -del *.obj - -del *.res - -del *.exp - -del *.exe - -del *.pdb - -del *.manifest - -del foo.gz diff --git a/src/beast/test/zlib/zlib-1.2.8/win32/README-WIN32.txt b/src/beast/test/zlib/zlib-1.2.8/win32/README-WIN32.txt deleted file mode 100644 index 3d77d521e83..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/win32/README-WIN32.txt +++ /dev/null @@ -1,103 +0,0 @@ -ZLIB DATA COMPRESSION LIBRARY - -zlib 1.2.8 is a general purpose data compression library. All the code is -thread safe. The data format used by the zlib library is described by RFCs -(Request for Comments) 1950 to 1952 in the files -http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format) -and rfc1952.txt (gzip format). - -All functions of the compression library are documented in the file zlib.h -(volunteer to write man pages welcome, contact zlib@gzip.org). Two compiled -examples are distributed in this package, example and minigzip. The example_d -and minigzip_d flavors validate that the zlib1.dll file is working correctly. - -Questions about zlib should be sent to . The zlib home page -is http://zlib.net/ . Before reporting a problem, please check this site to -verify that you have the latest version of zlib; otherwise get the latest -version and check whether the problem still exists or not. - -PLEASE read DLL_FAQ.txt, and the the zlib FAQ http://zlib.net/zlib_faq.html -before asking for help. - - -Manifest: - -The package zlib-1.2.8-win32-x86.zip will contain the following files: - - README-WIN32.txt This document - ChangeLog Changes since previous zlib packages - DLL_FAQ.txt Frequently asked questions about zlib1.dll - zlib.3.pdf Documentation of this library in Adobe Acrobat format - - example.exe A statically-bound example (using zlib.lib, not the dll) - example.pdb Symbolic information for debugging example.exe - - example_d.exe A zlib1.dll bound example (using zdll.lib) - example_d.pdb Symbolic information for debugging example_d.exe - - minigzip.exe A statically-bound test program (using zlib.lib, not the dll) - minigzip.pdb Symbolic information for debugging minigzip.exe - - minigzip_d.exe A zlib1.dll bound test program (using zdll.lib) - minigzip_d.pdb Symbolic information for debugging minigzip_d.exe - - zlib.h Install these files into the compilers' INCLUDE path to - zconf.h compile programs which use zlib.lib or zdll.lib - - zdll.lib Install these files into the compilers' LIB path if linking - zdll.exp a compiled program to the zlib1.dll binary - - zlib.lib Install these files into the compilers' LIB path to link zlib - zlib.pdb into compiled programs, without zlib1.dll runtime dependency - (zlib.pdb provides debugging info to the compile time linker) - - zlib1.dll Install this binary shared library into the system PATH, or - the program's runtime directory (where the .exe resides) - zlib1.pdb Install in the same directory as zlib1.dll, in order to debug - an application crash using WinDbg or similar tools. - -All .pdb files above are entirely optional, but are very useful to a developer -attempting to diagnose program misbehavior or a crash. Many additional -important files for developers can be found in the zlib127.zip source package -available from http://zlib.net/ - review that package's README file for details. - - -Acknowledgments: - -The deflate format used by zlib was defined by Phil Katz. The deflate and -zlib specifications were written by L. Peter Deutsch. Thanks to all the -people who reported problems and suggested various improvements in zlib; they -are too numerous to cite here. - - -Copyright notice: - - (C) 1995-2012 Jean-loup Gailly and Mark Adler - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Jean-loup Gailly Mark Adler - jloup@gzip.org madler@alumni.caltech.edu - -If you use the zlib library in a product, we would appreciate *not* receiving -lengthy legal documents to sign. The sources are provided for free but without -warranty of any kind. The library has been entirely written by Jean-loup -Gailly and Mark Adler; it does not include third-party code. - -If you redistribute modified sources, we would appreciate that you include in -the file ChangeLog history information documenting your changes. Please read -the FAQ for more information on the distribution of modified source versions. diff --git a/src/beast/test/zlib/zlib-1.2.8/win32/VisualC.txt b/src/beast/test/zlib/zlib-1.2.8/win32/VisualC.txt deleted file mode 100644 index 579a5fc9e0f..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/win32/VisualC.txt +++ /dev/null @@ -1,3 +0,0 @@ - -To build zlib using the Microsoft Visual C++ environment, -use the appropriate project from the projects/ directory. diff --git a/src/beast/test/zlib/zlib-1.2.8/win32/zlib.def b/src/beast/test/zlib/zlib-1.2.8/win32/zlib.def deleted file mode 100644 index face655183a..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/win32/zlib.def +++ /dev/null @@ -1,86 +0,0 @@ -; zlib data compression library -EXPORTS -; basic functions - zlibVersion - deflate - deflateEnd - inflate - inflateEnd -; advanced functions - deflateSetDictionary - deflateCopy - deflateReset - deflateParams - deflateTune - deflateBound - deflatePending - deflatePrime - deflateSetHeader - inflateSetDictionary - inflateGetDictionary - inflateSync - inflateCopy - inflateReset - inflateReset2 - inflatePrime - inflateMark - inflateGetHeader - inflateBack - inflateBackEnd - zlibCompileFlags -; utility functions - compress - compress2 - compressBound - uncompress - gzopen - gzdopen - gzbuffer - gzsetparams - gzread - gzwrite - gzprintf - gzvprintf - gzputs - gzgets - gzputc - gzgetc - gzungetc - gzflush - gzseek - gzrewind - gztell - gzoffset - gzeof - gzdirect - gzclose - gzclose_r - gzclose_w - gzerror - gzclearerr -; large file functions - gzopen64 - gzseek64 - gztell64 - gzoffset64 - adler32_combine64 - crc32_combine64 -; checksum functions - adler32 - crc32 - adler32_combine - crc32_combine -; various hacks, don't look :) - deflateInit_ - deflateInit2_ - inflateInit_ - inflateInit2_ - inflateBackInit_ - gzgetc_ - zError - inflateSyncPoint - get_crc_table - inflateUndermine - inflateResetKeep - deflateResetKeep - gzopen_w diff --git a/src/beast/test/zlib/zlib-1.2.8/win32/zlib1.rc b/src/beast/test/zlib/zlib-1.2.8/win32/zlib1.rc deleted file mode 100644 index 5c0feed1b44..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/win32/zlib1.rc +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include "../zlib.h" - -#ifdef GCC_WINDRES -VS_VERSION_INFO VERSIONINFO -#else -VS_VERSION_INFO VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE -#endif - FILEVERSION ZLIB_VER_MAJOR,ZLIB_VER_MINOR,ZLIB_VER_REVISION,0 - PRODUCTVERSION ZLIB_VER_MAJOR,ZLIB_VER_MINOR,ZLIB_VER_REVISION,0 - FILEFLAGSMASK VS_FFI_FILEFLAGSMASK -#ifdef _DEBUG - FILEFLAGS 1 -#else - FILEFLAGS 0 -#endif - FILEOS VOS__WINDOWS32 - FILETYPE VFT_DLL - FILESUBTYPE 0 // not used -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904E4" - //language ID = U.S. English, char set = Windows, Multilingual - BEGIN - VALUE "FileDescription", "zlib data compression library\0" - VALUE "FileVersion", ZLIB_VERSION "\0" - VALUE "InternalName", "zlib1.dll\0" - VALUE "LegalCopyright", "(C) 1995-2013 Jean-loup Gailly & Mark Adler\0" - VALUE "OriginalFilename", "zlib1.dll\0" - VALUE "ProductName", "zlib\0" - VALUE "ProductVersion", ZLIB_VERSION "\0" - VALUE "Comments", "For more information visit http://www.zlib.net/\0" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x0409, 1252 - END -END diff --git a/src/beast/test/zlib/zlib-1.2.8/zconf.h b/src/beast/test/zlib/zlib-1.2.8/zconf.h deleted file mode 100644 index 9987a775530..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/zconf.h +++ /dev/null @@ -1,511 +0,0 @@ -/* zconf.h -- configuration of the zlib compression library - * Copyright (C) 1995-2013 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id$ */ - -#ifndef ZCONF_H -#define ZCONF_H - -/* - * If you *really* need a unique prefix for all types and library functions, - * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. - * Even better than compiling with -DZ_PREFIX would be to use configure to set - * this permanently in zconf.h using "./configure --zprefix". - */ -#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ -# define Z_PREFIX_SET - -/* all linked symbols */ -# define _dist_code z__dist_code -# define _length_code z__length_code -# define _tr_align z__tr_align -# define _tr_flush_bits z__tr_flush_bits -# define _tr_flush_block z__tr_flush_block -# define _tr_init z__tr_init -# define _tr_stored_block z__tr_stored_block -# define _tr_tally z__tr_tally -# define adler32 z_adler32 -# define adler32_combine z_adler32_combine -# define adler32_combine64 z_adler32_combine64 -# ifndef Z_SOLO -# define compress z_compress -# define compress2 z_compress2 -# define compressBound z_compressBound -# endif -# define crc32 z_crc32 -# define crc32_combine z_crc32_combine -# define crc32_combine64 z_crc32_combine64 -# define deflate z_deflate -# define deflateBound z_deflateBound -# define deflateCopy z_deflateCopy -# define deflateEnd z_deflateEnd -# define deflateInit2_ z_deflateInit2_ -# define deflateInit_ z_deflateInit_ -# define deflateParams z_deflateParams -# define deflatePending z_deflatePending -# define deflatePrime z_deflatePrime -# define deflateReset z_deflateReset -# define deflateResetKeep z_deflateResetKeep -# define deflateSetDictionary z_deflateSetDictionary -# define deflateSetHeader z_deflateSetHeader -# define deflateTune z_deflateTune -# define deflate_copyright z_deflate_copyright -# define get_crc_table z_get_crc_table -# ifndef Z_SOLO -# define gz_error z_gz_error -# define gz_intmax z_gz_intmax -# define gz_strwinerror z_gz_strwinerror -# define gzbuffer z_gzbuffer -# define gzclearerr z_gzclearerr -# define gzclose z_gzclose -# define gzclose_r z_gzclose_r -# define gzclose_w z_gzclose_w -# define gzdirect z_gzdirect -# define gzdopen z_gzdopen -# define gzeof z_gzeof -# define gzerror z_gzerror -# define gzflush z_gzflush -# define gzgetc z_gzgetc -# define gzgetc_ z_gzgetc_ -# define gzgets z_gzgets -# define gzoffset z_gzoffset -# define gzoffset64 z_gzoffset64 -# define gzopen z_gzopen -# define gzopen64 z_gzopen64 -# ifdef _WIN32 -# define gzopen_w z_gzopen_w -# endif -# define gzprintf z_gzprintf -# define gzvprintf z_gzvprintf -# define gzputc z_gzputc -# define gzputs z_gzputs -# define gzread z_gzread -# define gzrewind z_gzrewind -# define gzseek z_gzseek -# define gzseek64 z_gzseek64 -# define gzsetparams z_gzsetparams -# define gztell z_gztell -# define gztell64 z_gztell64 -# define gzungetc z_gzungetc -# define gzwrite z_gzwrite -# endif -# define inflate z_inflate -# define inflateBack z_inflateBack -# define inflateBackEnd z_inflateBackEnd -# define inflateBackInit_ z_inflateBackInit_ -# define inflateCopy z_inflateCopy -# define inflateEnd z_inflateEnd -# define inflateGetHeader z_inflateGetHeader -# define inflateInit2_ z_inflateInit2_ -# define inflateInit_ z_inflateInit_ -# define inflateMark z_inflateMark -# define inflatePrime z_inflatePrime -# define inflateReset z_inflateReset -# define inflateReset2 z_inflateReset2 -# define inflateSetDictionary z_inflateSetDictionary -# define inflateGetDictionary z_inflateGetDictionary -# define inflateSync z_inflateSync -# define inflateSyncPoint z_inflateSyncPoint -# define inflateUndermine z_inflateUndermine -# define inflateResetKeep z_inflateResetKeep -# define inflate_copyright z_inflate_copyright -# define inflate_fast z_inflate_fast -# define inflate_table z_inflate_table -# ifndef Z_SOLO -# define uncompress z_uncompress -# endif -# define zError z_zError -# ifndef Z_SOLO -# define zcalloc z_zcalloc -# define zcfree z_zcfree -# endif -# define zlibCompileFlags z_zlibCompileFlags -# define zlibVersion z_zlibVersion - -/* all zlib typedefs in zlib.h and zconf.h */ -# define Byte z_Byte -# define Bytef z_Bytef -# define alloc_func z_alloc_func -# define charf z_charf -# define free_func z_free_func -# ifndef Z_SOLO -# define gzFile z_gzFile -# endif -# define gz_header z_gz_header -# define gz_headerp z_gz_headerp -# define in_func z_in_func -# define intf z_intf -# define out_func z_out_func -# define uInt z_uInt -# define uIntf z_uIntf -# define uLong z_uLong -# define uLongf z_uLongf -# define voidp z_voidp -# define voidpc z_voidpc -# define voidpf z_voidpf - -/* all zlib structs in zlib.h and zconf.h */ -# define gz_header_s z_gz_header_s -# define internal_state z_internal_state - -#endif - -#if defined(__MSDOS__) && !defined(MSDOS) -# define MSDOS -#endif -#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) -# define OS2 -#endif -#if defined(_WINDOWS) && !defined(WINDOWS) -# define WINDOWS -#endif -#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) -# ifndef WIN32 -# define WIN32 -# endif -#endif -#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) -# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) -# ifndef SYS16BIT -# define SYS16BIT -# endif -# endif -#endif - -/* - * Compile with -DMAXSEG_64K if the alloc function cannot allocate more - * than 64k bytes at a time (needed on systems with 16-bit int). - */ -#ifdef SYS16BIT -# define MAXSEG_64K -#endif -#ifdef MSDOS -# define UNALIGNED_OK -#endif - -#ifdef __STDC_VERSION__ -# ifndef STDC -# define STDC -# endif -# if __STDC_VERSION__ >= 199901L -# ifndef STDC99 -# define STDC99 -# endif -# endif -#endif -#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) -# define STDC -#endif -#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) -# define STDC -#endif -#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) -# define STDC -#endif -#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) -# define STDC -#endif - -#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ -# define STDC -#endif - -#ifndef STDC -# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ -# define const /* note: need a more gentle solution here */ -# endif -#endif - -#if defined(ZLIB_CONST) && !defined(z_const) -# define z_const const -#else -# define z_const -#endif - -/* Some Mac compilers merge all .h files incorrectly: */ -#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) -# define NO_DUMMY_DECL -#endif - -/* Maximum value for memLevel in deflateInit2 */ -#ifndef MAX_MEM_LEVEL -# ifdef MAXSEG_64K -# define MAX_MEM_LEVEL 8 -# else -# define MAX_MEM_LEVEL 9 -# endif -#endif - -/* Maximum value for windowBits in deflateInit2 and inflateInit2. - * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files - * created by gzip. (Files created by minigzip can still be extracted by - * gzip.) - */ -#ifndef MAX_WBITS -# define MAX_WBITS 15 /* 32K LZ77 window */ -#endif - -/* The memory requirements for deflate are (in bytes): - (1 << (windowBits+2)) + (1 << (memLevel+9)) - that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) - plus a few kilobytes for small objects. For example, if you want to reduce - the default memory requirements from 256K to 128K, compile with - make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" - Of course this will generally degrade compression (there's no free lunch). - - The memory requirements for inflate are (in bytes) 1 << windowBits - that is, 32K for windowBits=15 (default value) plus a few kilobytes - for small objects. -*/ - - /* Type declarations */ - -#ifndef OF /* function prototypes */ -# ifdef STDC -# define OF(args) args -# else -# define OF(args) () -# endif -#endif - -#ifndef Z_ARG /* function prototypes for stdarg */ -# if defined(STDC) || defined(Z_HAVE_STDARG_H) -# define Z_ARG(args) args -# else -# define Z_ARG(args) () -# endif -#endif - -/* The following definitions for FAR are needed only for MSDOS mixed - * model programming (small or medium model with some far allocations). - * This was tested only with MSC; for other MSDOS compilers you may have - * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, - * just define FAR to be empty. - */ -#ifdef SYS16BIT -# if defined(M_I86SM) || defined(M_I86MM) - /* MSC small or medium model */ -# define SMALL_MEDIUM -# ifdef _MSC_VER -# define FAR _far -# else -# define FAR far -# endif -# endif -# if (defined(__SMALL__) || defined(__MEDIUM__)) - /* Turbo C small or medium model */ -# define SMALL_MEDIUM -# ifdef __BORLANDC__ -# define FAR _far -# else -# define FAR far -# endif -# endif -#endif - -#if defined(WINDOWS) || defined(WIN32) - /* If building or using zlib as a DLL, define ZLIB_DLL. - * This is not mandatory, but it offers a little performance increase. - */ -# ifdef ZLIB_DLL -# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) -# ifdef ZLIB_INTERNAL -# define ZEXTERN extern __declspec(dllexport) -# else -# define ZEXTERN extern __declspec(dllimport) -# endif -# endif -# endif /* ZLIB_DLL */ - /* If building or using zlib with the WINAPI/WINAPIV calling convention, - * define ZLIB_WINAPI. - * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. - */ -# ifdef ZLIB_WINAPI -# ifdef FAR -# undef FAR -# endif -# include - /* No need for _export, use ZLIB.DEF instead. */ - /* For complete Windows compatibility, use WINAPI, not __stdcall. */ -# define ZEXPORT WINAPI -# ifdef WIN32 -# define ZEXPORTVA WINAPIV -# else -# define ZEXPORTVA FAR CDECL -# endif -# endif -#endif - -#if defined (__BEOS__) -# ifdef ZLIB_DLL -# ifdef ZLIB_INTERNAL -# define ZEXPORT __declspec(dllexport) -# define ZEXPORTVA __declspec(dllexport) -# else -# define ZEXPORT __declspec(dllimport) -# define ZEXPORTVA __declspec(dllimport) -# endif -# endif -#endif - -#ifndef ZEXTERN -# define ZEXTERN extern -#endif -#ifndef ZEXPORT -# define ZEXPORT -#endif -#ifndef ZEXPORTVA -# define ZEXPORTVA -#endif - -#ifndef FAR -# define FAR -#endif - -#if !defined(__MACTYPES__) -typedef unsigned char Byte; /* 8 bits */ -#endif -typedef unsigned int uInt; /* 16 bits or more */ -typedef unsigned long uLong; /* 32 bits or more */ - -#ifdef SMALL_MEDIUM - /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ -# define Bytef Byte FAR -#else - typedef Byte FAR Bytef; -#endif -typedef char FAR charf; -typedef int FAR intf; -typedef uInt FAR uIntf; -typedef uLong FAR uLongf; - -#ifdef STDC - typedef void const *voidpc; - typedef void FAR *voidpf; - typedef void *voidp; -#else - typedef Byte const *voidpc; - typedef Byte FAR *voidpf; - typedef Byte *voidp; -#endif - -#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC) -# include -# if (UINT_MAX == 0xffffffffUL) -# define Z_U4 unsigned -# elif (ULONG_MAX == 0xffffffffUL) -# define Z_U4 unsigned long -# elif (USHRT_MAX == 0xffffffffUL) -# define Z_U4 unsigned short -# endif -#endif - -#ifdef Z_U4 - typedef Z_U4 z_crc_t; -#else - typedef unsigned long z_crc_t; -#endif - -#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ -# define Z_HAVE_UNISTD_H -#endif - -#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ -# define Z_HAVE_STDARG_H -#endif - -#ifdef STDC -# ifndef Z_SOLO -# include /* for off_t */ -# endif -#endif - -#if defined(STDC) || defined(Z_HAVE_STDARG_H) -# ifndef Z_SOLO -# include /* for va_list */ -# endif -#endif - -#ifdef _WIN32 -# ifndef Z_SOLO -# include /* for wchar_t */ -# endif -#endif - -/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and - * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even - * though the former does not conform to the LFS document), but considering - * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as - * equivalently requesting no 64-bit operations - */ -#if defined(_LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1 -# undef _LARGEFILE64_SOURCE -#endif - -#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H) -# define Z_HAVE_UNISTD_H -#endif -#ifndef Z_SOLO -# if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE) -# include /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ -# ifdef VMS -# include /* for off_t */ -# endif -# ifndef z_off_t -# define z_off_t off_t -# endif -# endif -#endif - -#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0 -# define Z_LFS64 -#endif - -#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64) -# define Z_LARGE64 -#endif - -#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64) -# define Z_WANT64 -#endif - -#if !defined(SEEK_SET) && !defined(Z_SOLO) -# define SEEK_SET 0 /* Seek from beginning of file. */ -# define SEEK_CUR 1 /* Seek from current position. */ -# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ -#endif - -#ifndef z_off_t -# define z_off_t long -#endif - -#if !defined(_WIN32) && defined(Z_LARGE64) -# define z_off64_t off64_t -#else -# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) -# define z_off64_t __int64 -# else -# define z_off64_t z_off_t -# endif -#endif - -/* MVS linker does not support external names larger than 8 bytes */ -#if defined(__MVS__) - #pragma map(deflateInit_,"DEIN") - #pragma map(deflateInit2_,"DEIN2") - #pragma map(deflateEnd,"DEEND") - #pragma map(deflateBound,"DEBND") - #pragma map(inflateInit_,"ININ") - #pragma map(inflateInit2_,"ININ2") - #pragma map(inflateEnd,"INEND") - #pragma map(inflateSync,"INSY") - #pragma map(inflateSetDictionary,"INSEDI") - #pragma map(compressBound,"CMBND") - #pragma map(inflate_table,"INTABL") - #pragma map(inflate_fast,"INFA") - #pragma map(inflate_copyright,"INCOPY") -#endif - -#endif /* ZCONF_H */ diff --git a/src/beast/test/zlib/zlib-1.2.8/zconf.h.cmakein b/src/beast/test/zlib/zlib-1.2.8/zconf.h.cmakein deleted file mode 100644 index 043019cda1d..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/zconf.h.cmakein +++ /dev/null @@ -1,513 +0,0 @@ -/* zconf.h -- configuration of the zlib compression library - * Copyright (C) 1995-2013 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id$ */ - -#ifndef ZCONF_H -#define ZCONF_H -#cmakedefine Z_PREFIX -#cmakedefine Z_HAVE_UNISTD_H - -/* - * If you *really* need a unique prefix for all types and library functions, - * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. - * Even better than compiling with -DZ_PREFIX would be to use configure to set - * this permanently in zconf.h using "./configure --zprefix". - */ -#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ -# define Z_PREFIX_SET - -/* all linked symbols */ -# define _dist_code z__dist_code -# define _length_code z__length_code -# define _tr_align z__tr_align -# define _tr_flush_bits z__tr_flush_bits -# define _tr_flush_block z__tr_flush_block -# define _tr_init z__tr_init -# define _tr_stored_block z__tr_stored_block -# define _tr_tally z__tr_tally -# define adler32 z_adler32 -# define adler32_combine z_adler32_combine -# define adler32_combine64 z_adler32_combine64 -# ifndef Z_SOLO -# define compress z_compress -# define compress2 z_compress2 -# define compressBound z_compressBound -# endif -# define crc32 z_crc32 -# define crc32_combine z_crc32_combine -# define crc32_combine64 z_crc32_combine64 -# define deflate z_deflate -# define deflateBound z_deflateBound -# define deflateCopy z_deflateCopy -# define deflateEnd z_deflateEnd -# define deflateInit2_ z_deflateInit2_ -# define deflateInit_ z_deflateInit_ -# define deflateParams z_deflateParams -# define deflatePending z_deflatePending -# define deflatePrime z_deflatePrime -# define deflateReset z_deflateReset -# define deflateResetKeep z_deflateResetKeep -# define deflateSetDictionary z_deflateSetDictionary -# define deflateSetHeader z_deflateSetHeader -# define deflateTune z_deflateTune -# define deflate_copyright z_deflate_copyright -# define get_crc_table z_get_crc_table -# ifndef Z_SOLO -# define gz_error z_gz_error -# define gz_intmax z_gz_intmax -# define gz_strwinerror z_gz_strwinerror -# define gzbuffer z_gzbuffer -# define gzclearerr z_gzclearerr -# define gzclose z_gzclose -# define gzclose_r z_gzclose_r -# define gzclose_w z_gzclose_w -# define gzdirect z_gzdirect -# define gzdopen z_gzdopen -# define gzeof z_gzeof -# define gzerror z_gzerror -# define gzflush z_gzflush -# define gzgetc z_gzgetc -# define gzgetc_ z_gzgetc_ -# define gzgets z_gzgets -# define gzoffset z_gzoffset -# define gzoffset64 z_gzoffset64 -# define gzopen z_gzopen -# define gzopen64 z_gzopen64 -# ifdef _WIN32 -# define gzopen_w z_gzopen_w -# endif -# define gzprintf z_gzprintf -# define gzvprintf z_gzvprintf -# define gzputc z_gzputc -# define gzputs z_gzputs -# define gzread z_gzread -# define gzrewind z_gzrewind -# define gzseek z_gzseek -# define gzseek64 z_gzseek64 -# define gzsetparams z_gzsetparams -# define gztell z_gztell -# define gztell64 z_gztell64 -# define gzungetc z_gzungetc -# define gzwrite z_gzwrite -# endif -# define inflate z_inflate -# define inflateBack z_inflateBack -# define inflateBackEnd z_inflateBackEnd -# define inflateBackInit_ z_inflateBackInit_ -# define inflateCopy z_inflateCopy -# define inflateEnd z_inflateEnd -# define inflateGetHeader z_inflateGetHeader -# define inflateInit2_ z_inflateInit2_ -# define inflateInit_ z_inflateInit_ -# define inflateMark z_inflateMark -# define inflatePrime z_inflatePrime -# define inflateReset z_inflateReset -# define inflateReset2 z_inflateReset2 -# define inflateSetDictionary z_inflateSetDictionary -# define inflateGetDictionary z_inflateGetDictionary -# define inflateSync z_inflateSync -# define inflateSyncPoint z_inflateSyncPoint -# define inflateUndermine z_inflateUndermine -# define inflateResetKeep z_inflateResetKeep -# define inflate_copyright z_inflate_copyright -# define inflate_fast z_inflate_fast -# define inflate_table z_inflate_table -# ifndef Z_SOLO -# define uncompress z_uncompress -# endif -# define zError z_zError -# ifndef Z_SOLO -# define zcalloc z_zcalloc -# define zcfree z_zcfree -# endif -# define zlibCompileFlags z_zlibCompileFlags -# define zlibVersion z_zlibVersion - -/* all zlib typedefs in zlib.h and zconf.h */ -# define Byte z_Byte -# define Bytef z_Bytef -# define alloc_func z_alloc_func -# define charf z_charf -# define free_func z_free_func -# ifndef Z_SOLO -# define gzFile z_gzFile -# endif -# define gz_header z_gz_header -# define gz_headerp z_gz_headerp -# define in_func z_in_func -# define intf z_intf -# define out_func z_out_func -# define uInt z_uInt -# define uIntf z_uIntf -# define uLong z_uLong -# define uLongf z_uLongf -# define voidp z_voidp -# define voidpc z_voidpc -# define voidpf z_voidpf - -/* all zlib structs in zlib.h and zconf.h */ -# define gz_header_s z_gz_header_s -# define internal_state z_internal_state - -#endif - -#if defined(__MSDOS__) && !defined(MSDOS) -# define MSDOS -#endif -#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) -# define OS2 -#endif -#if defined(_WINDOWS) && !defined(WINDOWS) -# define WINDOWS -#endif -#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) -# ifndef WIN32 -# define WIN32 -# endif -#endif -#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) -# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) -# ifndef SYS16BIT -# define SYS16BIT -# endif -# endif -#endif - -/* - * Compile with -DMAXSEG_64K if the alloc function cannot allocate more - * than 64k bytes at a time (needed on systems with 16-bit int). - */ -#ifdef SYS16BIT -# define MAXSEG_64K -#endif -#ifdef MSDOS -# define UNALIGNED_OK -#endif - -#ifdef __STDC_VERSION__ -# ifndef STDC -# define STDC -# endif -# if __STDC_VERSION__ >= 199901L -# ifndef STDC99 -# define STDC99 -# endif -# endif -#endif -#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) -# define STDC -#endif -#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) -# define STDC -#endif -#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) -# define STDC -#endif -#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) -# define STDC -#endif - -#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ -# define STDC -#endif - -#ifndef STDC -# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ -# define const /* note: need a more gentle solution here */ -# endif -#endif - -#if defined(ZLIB_CONST) && !defined(z_const) -# define z_const const -#else -# define z_const -#endif - -/* Some Mac compilers merge all .h files incorrectly: */ -#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) -# define NO_DUMMY_DECL -#endif - -/* Maximum value for memLevel in deflateInit2 */ -#ifndef MAX_MEM_LEVEL -# ifdef MAXSEG_64K -# define MAX_MEM_LEVEL 8 -# else -# define MAX_MEM_LEVEL 9 -# endif -#endif - -/* Maximum value for windowBits in deflateInit2 and inflateInit2. - * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files - * created by gzip. (Files created by minigzip can still be extracted by - * gzip.) - */ -#ifndef MAX_WBITS -# define MAX_WBITS 15 /* 32K LZ77 window */ -#endif - -/* The memory requirements for deflate are (in bytes): - (1 << (windowBits+2)) + (1 << (memLevel+9)) - that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) - plus a few kilobytes for small objects. For example, if you want to reduce - the default memory requirements from 256K to 128K, compile with - make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" - Of course this will generally degrade compression (there's no free lunch). - - The memory requirements for inflate are (in bytes) 1 << windowBits - that is, 32K for windowBits=15 (default value) plus a few kilobytes - for small objects. -*/ - - /* Type declarations */ - -#ifndef OF /* function prototypes */ -# ifdef STDC -# define OF(args) args -# else -# define OF(args) () -# endif -#endif - -#ifndef Z_ARG /* function prototypes for stdarg */ -# if defined(STDC) || defined(Z_HAVE_STDARG_H) -# define Z_ARG(args) args -# else -# define Z_ARG(args) () -# endif -#endif - -/* The following definitions for FAR are needed only for MSDOS mixed - * model programming (small or medium model with some far allocations). - * This was tested only with MSC; for other MSDOS compilers you may have - * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, - * just define FAR to be empty. - */ -#ifdef SYS16BIT -# if defined(M_I86SM) || defined(M_I86MM) - /* MSC small or medium model */ -# define SMALL_MEDIUM -# ifdef _MSC_VER -# define FAR _far -# else -# define FAR far -# endif -# endif -# if (defined(__SMALL__) || defined(__MEDIUM__)) - /* Turbo C small or medium model */ -# define SMALL_MEDIUM -# ifdef __BORLANDC__ -# define FAR _far -# else -# define FAR far -# endif -# endif -#endif - -#if defined(WINDOWS) || defined(WIN32) - /* If building or using zlib as a DLL, define ZLIB_DLL. - * This is not mandatory, but it offers a little performance increase. - */ -# ifdef ZLIB_DLL -# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) -# ifdef ZLIB_INTERNAL -# define ZEXTERN extern __declspec(dllexport) -# else -# define ZEXTERN extern __declspec(dllimport) -# endif -# endif -# endif /* ZLIB_DLL */ - /* If building or using zlib with the WINAPI/WINAPIV calling convention, - * define ZLIB_WINAPI. - * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. - */ -# ifdef ZLIB_WINAPI -# ifdef FAR -# undef FAR -# endif -# include - /* No need for _export, use ZLIB.DEF instead. */ - /* For complete Windows compatibility, use WINAPI, not __stdcall. */ -# define ZEXPORT WINAPI -# ifdef WIN32 -# define ZEXPORTVA WINAPIV -# else -# define ZEXPORTVA FAR CDECL -# endif -# endif -#endif - -#if defined (__BEOS__) -# ifdef ZLIB_DLL -# ifdef ZLIB_INTERNAL -# define ZEXPORT __declspec(dllexport) -# define ZEXPORTVA __declspec(dllexport) -# else -# define ZEXPORT __declspec(dllimport) -# define ZEXPORTVA __declspec(dllimport) -# endif -# endif -#endif - -#ifndef ZEXTERN -# define ZEXTERN extern -#endif -#ifndef ZEXPORT -# define ZEXPORT -#endif -#ifndef ZEXPORTVA -# define ZEXPORTVA -#endif - -#ifndef FAR -# define FAR -#endif - -#if !defined(__MACTYPES__) -typedef unsigned char Byte; /* 8 bits */ -#endif -typedef unsigned int uInt; /* 16 bits or more */ -typedef unsigned long uLong; /* 32 bits or more */ - -#ifdef SMALL_MEDIUM - /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ -# define Bytef Byte FAR -#else - typedef Byte FAR Bytef; -#endif -typedef char FAR charf; -typedef int FAR intf; -typedef uInt FAR uIntf; -typedef uLong FAR uLongf; - -#ifdef STDC - typedef void const *voidpc; - typedef void FAR *voidpf; - typedef void *voidp; -#else - typedef Byte const *voidpc; - typedef Byte FAR *voidpf; - typedef Byte *voidp; -#endif - -#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC) -# include -# if (UINT_MAX == 0xffffffffUL) -# define Z_U4 unsigned -# elif (ULONG_MAX == 0xffffffffUL) -# define Z_U4 unsigned long -# elif (USHRT_MAX == 0xffffffffUL) -# define Z_U4 unsigned short -# endif -#endif - -#ifdef Z_U4 - typedef Z_U4 z_crc_t; -#else - typedef unsigned long z_crc_t; -#endif - -#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ -# define Z_HAVE_UNISTD_H -#endif - -#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ -# define Z_HAVE_STDARG_H -#endif - -#ifdef STDC -# ifndef Z_SOLO -# include /* for off_t */ -# endif -#endif - -#if defined(STDC) || defined(Z_HAVE_STDARG_H) -# ifndef Z_SOLO -# include /* for va_list */ -# endif -#endif - -#ifdef _WIN32 -# ifndef Z_SOLO -# include /* for wchar_t */ -# endif -#endif - -/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and - * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even - * though the former does not conform to the LFS document), but considering - * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as - * equivalently requesting no 64-bit operations - */ -#if defined(_LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1 -# undef _LARGEFILE64_SOURCE -#endif - -#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H) -# define Z_HAVE_UNISTD_H -#endif -#ifndef Z_SOLO -# if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE) -# include /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ -# ifdef VMS -# include /* for off_t */ -# endif -# ifndef z_off_t -# define z_off_t off_t -# endif -# endif -#endif - -#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0 -# define Z_LFS64 -#endif - -#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64) -# define Z_LARGE64 -#endif - -#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64) -# define Z_WANT64 -#endif - -#if !defined(SEEK_SET) && !defined(Z_SOLO) -# define SEEK_SET 0 /* Seek from beginning of file. */ -# define SEEK_CUR 1 /* Seek from current position. */ -# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ -#endif - -#ifndef z_off_t -# define z_off_t long -#endif - -#if !defined(_WIN32) && defined(Z_LARGE64) -# define z_off64_t off64_t -#else -# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) -# define z_off64_t __int64 -# else -# define z_off64_t z_off_t -# endif -#endif - -/* MVS linker does not support external names larger than 8 bytes */ -#if defined(__MVS__) - #pragma map(deflateInit_,"DEIN") - #pragma map(deflateInit2_,"DEIN2") - #pragma map(deflateEnd,"DEEND") - #pragma map(deflateBound,"DEBND") - #pragma map(inflateInit_,"ININ") - #pragma map(inflateInit2_,"ININ2") - #pragma map(inflateEnd,"INEND") - #pragma map(inflateSync,"INSY") - #pragma map(inflateSetDictionary,"INSEDI") - #pragma map(compressBound,"CMBND") - #pragma map(inflate_table,"INTABL") - #pragma map(inflate_fast,"INFA") - #pragma map(inflate_copyright,"INCOPY") -#endif - -#endif /* ZCONF_H */ diff --git a/src/beast/test/zlib/zlib-1.2.8/zconf.h.in b/src/beast/test/zlib/zlib-1.2.8/zconf.h.in deleted file mode 100644 index 9987a775530..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/zconf.h.in +++ /dev/null @@ -1,511 +0,0 @@ -/* zconf.h -- configuration of the zlib compression library - * Copyright (C) 1995-2013 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id$ */ - -#ifndef ZCONF_H -#define ZCONF_H - -/* - * If you *really* need a unique prefix for all types and library functions, - * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. - * Even better than compiling with -DZ_PREFIX would be to use configure to set - * this permanently in zconf.h using "./configure --zprefix". - */ -#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ -# define Z_PREFIX_SET - -/* all linked symbols */ -# define _dist_code z__dist_code -# define _length_code z__length_code -# define _tr_align z__tr_align -# define _tr_flush_bits z__tr_flush_bits -# define _tr_flush_block z__tr_flush_block -# define _tr_init z__tr_init -# define _tr_stored_block z__tr_stored_block -# define _tr_tally z__tr_tally -# define adler32 z_adler32 -# define adler32_combine z_adler32_combine -# define adler32_combine64 z_adler32_combine64 -# ifndef Z_SOLO -# define compress z_compress -# define compress2 z_compress2 -# define compressBound z_compressBound -# endif -# define crc32 z_crc32 -# define crc32_combine z_crc32_combine -# define crc32_combine64 z_crc32_combine64 -# define deflate z_deflate -# define deflateBound z_deflateBound -# define deflateCopy z_deflateCopy -# define deflateEnd z_deflateEnd -# define deflateInit2_ z_deflateInit2_ -# define deflateInit_ z_deflateInit_ -# define deflateParams z_deflateParams -# define deflatePending z_deflatePending -# define deflatePrime z_deflatePrime -# define deflateReset z_deflateReset -# define deflateResetKeep z_deflateResetKeep -# define deflateSetDictionary z_deflateSetDictionary -# define deflateSetHeader z_deflateSetHeader -# define deflateTune z_deflateTune -# define deflate_copyright z_deflate_copyright -# define get_crc_table z_get_crc_table -# ifndef Z_SOLO -# define gz_error z_gz_error -# define gz_intmax z_gz_intmax -# define gz_strwinerror z_gz_strwinerror -# define gzbuffer z_gzbuffer -# define gzclearerr z_gzclearerr -# define gzclose z_gzclose -# define gzclose_r z_gzclose_r -# define gzclose_w z_gzclose_w -# define gzdirect z_gzdirect -# define gzdopen z_gzdopen -# define gzeof z_gzeof -# define gzerror z_gzerror -# define gzflush z_gzflush -# define gzgetc z_gzgetc -# define gzgetc_ z_gzgetc_ -# define gzgets z_gzgets -# define gzoffset z_gzoffset -# define gzoffset64 z_gzoffset64 -# define gzopen z_gzopen -# define gzopen64 z_gzopen64 -# ifdef _WIN32 -# define gzopen_w z_gzopen_w -# endif -# define gzprintf z_gzprintf -# define gzvprintf z_gzvprintf -# define gzputc z_gzputc -# define gzputs z_gzputs -# define gzread z_gzread -# define gzrewind z_gzrewind -# define gzseek z_gzseek -# define gzseek64 z_gzseek64 -# define gzsetparams z_gzsetparams -# define gztell z_gztell -# define gztell64 z_gztell64 -# define gzungetc z_gzungetc -# define gzwrite z_gzwrite -# endif -# define inflate z_inflate -# define inflateBack z_inflateBack -# define inflateBackEnd z_inflateBackEnd -# define inflateBackInit_ z_inflateBackInit_ -# define inflateCopy z_inflateCopy -# define inflateEnd z_inflateEnd -# define inflateGetHeader z_inflateGetHeader -# define inflateInit2_ z_inflateInit2_ -# define inflateInit_ z_inflateInit_ -# define inflateMark z_inflateMark -# define inflatePrime z_inflatePrime -# define inflateReset z_inflateReset -# define inflateReset2 z_inflateReset2 -# define inflateSetDictionary z_inflateSetDictionary -# define inflateGetDictionary z_inflateGetDictionary -# define inflateSync z_inflateSync -# define inflateSyncPoint z_inflateSyncPoint -# define inflateUndermine z_inflateUndermine -# define inflateResetKeep z_inflateResetKeep -# define inflate_copyright z_inflate_copyright -# define inflate_fast z_inflate_fast -# define inflate_table z_inflate_table -# ifndef Z_SOLO -# define uncompress z_uncompress -# endif -# define zError z_zError -# ifndef Z_SOLO -# define zcalloc z_zcalloc -# define zcfree z_zcfree -# endif -# define zlibCompileFlags z_zlibCompileFlags -# define zlibVersion z_zlibVersion - -/* all zlib typedefs in zlib.h and zconf.h */ -# define Byte z_Byte -# define Bytef z_Bytef -# define alloc_func z_alloc_func -# define charf z_charf -# define free_func z_free_func -# ifndef Z_SOLO -# define gzFile z_gzFile -# endif -# define gz_header z_gz_header -# define gz_headerp z_gz_headerp -# define in_func z_in_func -# define intf z_intf -# define out_func z_out_func -# define uInt z_uInt -# define uIntf z_uIntf -# define uLong z_uLong -# define uLongf z_uLongf -# define voidp z_voidp -# define voidpc z_voidpc -# define voidpf z_voidpf - -/* all zlib structs in zlib.h and zconf.h */ -# define gz_header_s z_gz_header_s -# define internal_state z_internal_state - -#endif - -#if defined(__MSDOS__) && !defined(MSDOS) -# define MSDOS -#endif -#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) -# define OS2 -#endif -#if defined(_WINDOWS) && !defined(WINDOWS) -# define WINDOWS -#endif -#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) -# ifndef WIN32 -# define WIN32 -# endif -#endif -#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) -# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) -# ifndef SYS16BIT -# define SYS16BIT -# endif -# endif -#endif - -/* - * Compile with -DMAXSEG_64K if the alloc function cannot allocate more - * than 64k bytes at a time (needed on systems with 16-bit int). - */ -#ifdef SYS16BIT -# define MAXSEG_64K -#endif -#ifdef MSDOS -# define UNALIGNED_OK -#endif - -#ifdef __STDC_VERSION__ -# ifndef STDC -# define STDC -# endif -# if __STDC_VERSION__ >= 199901L -# ifndef STDC99 -# define STDC99 -# endif -# endif -#endif -#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) -# define STDC -#endif -#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) -# define STDC -#endif -#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) -# define STDC -#endif -#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) -# define STDC -#endif - -#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ -# define STDC -#endif - -#ifndef STDC -# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ -# define const /* note: need a more gentle solution here */ -# endif -#endif - -#if defined(ZLIB_CONST) && !defined(z_const) -# define z_const const -#else -# define z_const -#endif - -/* Some Mac compilers merge all .h files incorrectly: */ -#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__) -# define NO_DUMMY_DECL -#endif - -/* Maximum value for memLevel in deflateInit2 */ -#ifndef MAX_MEM_LEVEL -# ifdef MAXSEG_64K -# define MAX_MEM_LEVEL 8 -# else -# define MAX_MEM_LEVEL 9 -# endif -#endif - -/* Maximum value for windowBits in deflateInit2 and inflateInit2. - * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files - * created by gzip. (Files created by minigzip can still be extracted by - * gzip.) - */ -#ifndef MAX_WBITS -# define MAX_WBITS 15 /* 32K LZ77 window */ -#endif - -/* The memory requirements for deflate are (in bytes): - (1 << (windowBits+2)) + (1 << (memLevel+9)) - that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) - plus a few kilobytes for small objects. For example, if you want to reduce - the default memory requirements from 256K to 128K, compile with - make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" - Of course this will generally degrade compression (there's no free lunch). - - The memory requirements for inflate are (in bytes) 1 << windowBits - that is, 32K for windowBits=15 (default value) plus a few kilobytes - for small objects. -*/ - - /* Type declarations */ - -#ifndef OF /* function prototypes */ -# ifdef STDC -# define OF(args) args -# else -# define OF(args) () -# endif -#endif - -#ifndef Z_ARG /* function prototypes for stdarg */ -# if defined(STDC) || defined(Z_HAVE_STDARG_H) -# define Z_ARG(args) args -# else -# define Z_ARG(args) () -# endif -#endif - -/* The following definitions for FAR are needed only for MSDOS mixed - * model programming (small or medium model with some far allocations). - * This was tested only with MSC; for other MSDOS compilers you may have - * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, - * just define FAR to be empty. - */ -#ifdef SYS16BIT -# if defined(M_I86SM) || defined(M_I86MM) - /* MSC small or medium model */ -# define SMALL_MEDIUM -# ifdef _MSC_VER -# define FAR _far -# else -# define FAR far -# endif -# endif -# if (defined(__SMALL__) || defined(__MEDIUM__)) - /* Turbo C small or medium model */ -# define SMALL_MEDIUM -# ifdef __BORLANDC__ -# define FAR _far -# else -# define FAR far -# endif -# endif -#endif - -#if defined(WINDOWS) || defined(WIN32) - /* If building or using zlib as a DLL, define ZLIB_DLL. - * This is not mandatory, but it offers a little performance increase. - */ -# ifdef ZLIB_DLL -# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) -# ifdef ZLIB_INTERNAL -# define ZEXTERN extern __declspec(dllexport) -# else -# define ZEXTERN extern __declspec(dllimport) -# endif -# endif -# endif /* ZLIB_DLL */ - /* If building or using zlib with the WINAPI/WINAPIV calling convention, - * define ZLIB_WINAPI. - * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. - */ -# ifdef ZLIB_WINAPI -# ifdef FAR -# undef FAR -# endif -# include - /* No need for _export, use ZLIB.DEF instead. */ - /* For complete Windows compatibility, use WINAPI, not __stdcall. */ -# define ZEXPORT WINAPI -# ifdef WIN32 -# define ZEXPORTVA WINAPIV -# else -# define ZEXPORTVA FAR CDECL -# endif -# endif -#endif - -#if defined (__BEOS__) -# ifdef ZLIB_DLL -# ifdef ZLIB_INTERNAL -# define ZEXPORT __declspec(dllexport) -# define ZEXPORTVA __declspec(dllexport) -# else -# define ZEXPORT __declspec(dllimport) -# define ZEXPORTVA __declspec(dllimport) -# endif -# endif -#endif - -#ifndef ZEXTERN -# define ZEXTERN extern -#endif -#ifndef ZEXPORT -# define ZEXPORT -#endif -#ifndef ZEXPORTVA -# define ZEXPORTVA -#endif - -#ifndef FAR -# define FAR -#endif - -#if !defined(__MACTYPES__) -typedef unsigned char Byte; /* 8 bits */ -#endif -typedef unsigned int uInt; /* 16 bits or more */ -typedef unsigned long uLong; /* 32 bits or more */ - -#ifdef SMALL_MEDIUM - /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ -# define Bytef Byte FAR -#else - typedef Byte FAR Bytef; -#endif -typedef char FAR charf; -typedef int FAR intf; -typedef uInt FAR uIntf; -typedef uLong FAR uLongf; - -#ifdef STDC - typedef void const *voidpc; - typedef void FAR *voidpf; - typedef void *voidp; -#else - typedef Byte const *voidpc; - typedef Byte FAR *voidpf; - typedef Byte *voidp; -#endif - -#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC) -# include -# if (UINT_MAX == 0xffffffffUL) -# define Z_U4 unsigned -# elif (ULONG_MAX == 0xffffffffUL) -# define Z_U4 unsigned long -# elif (USHRT_MAX == 0xffffffffUL) -# define Z_U4 unsigned short -# endif -#endif - -#ifdef Z_U4 - typedef Z_U4 z_crc_t; -#else - typedef unsigned long z_crc_t; -#endif - -#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ -# define Z_HAVE_UNISTD_H -#endif - -#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ -# define Z_HAVE_STDARG_H -#endif - -#ifdef STDC -# ifndef Z_SOLO -# include /* for off_t */ -# endif -#endif - -#if defined(STDC) || defined(Z_HAVE_STDARG_H) -# ifndef Z_SOLO -# include /* for va_list */ -# endif -#endif - -#ifdef _WIN32 -# ifndef Z_SOLO -# include /* for wchar_t */ -# endif -#endif - -/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and - * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even - * though the former does not conform to the LFS document), but considering - * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as - * equivalently requesting no 64-bit operations - */ -#if defined(_LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1 -# undef _LARGEFILE64_SOURCE -#endif - -#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H) -# define Z_HAVE_UNISTD_H -#endif -#ifndef Z_SOLO -# if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE) -# include /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ -# ifdef VMS -# include /* for off_t */ -# endif -# ifndef z_off_t -# define z_off_t off_t -# endif -# endif -#endif - -#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0 -# define Z_LFS64 -#endif - -#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64) -# define Z_LARGE64 -#endif - -#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64) -# define Z_WANT64 -#endif - -#if !defined(SEEK_SET) && !defined(Z_SOLO) -# define SEEK_SET 0 /* Seek from beginning of file. */ -# define SEEK_CUR 1 /* Seek from current position. */ -# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ -#endif - -#ifndef z_off_t -# define z_off_t long -#endif - -#if !defined(_WIN32) && defined(Z_LARGE64) -# define z_off64_t off64_t -#else -# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) -# define z_off64_t __int64 -# else -# define z_off64_t z_off_t -# endif -#endif - -/* MVS linker does not support external names larger than 8 bytes */ -#if defined(__MVS__) - #pragma map(deflateInit_,"DEIN") - #pragma map(deflateInit2_,"DEIN2") - #pragma map(deflateEnd,"DEEND") - #pragma map(deflateBound,"DEBND") - #pragma map(inflateInit_,"ININ") - #pragma map(inflateInit2_,"ININ2") - #pragma map(inflateEnd,"INEND") - #pragma map(inflateSync,"INSY") - #pragma map(inflateSetDictionary,"INSEDI") - #pragma map(compressBound,"CMBND") - #pragma map(inflate_table,"INTABL") - #pragma map(inflate_fast,"INFA") - #pragma map(inflate_copyright,"INCOPY") -#endif - -#endif /* ZCONF_H */ diff --git a/src/beast/test/zlib/zlib-1.2.8/zlib.3 b/src/beast/test/zlib/zlib-1.2.8/zlib.3 deleted file mode 100644 index 0160e62b69f..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/zlib.3 +++ /dev/null @@ -1,151 +0,0 @@ -.TH ZLIB 3 "28 Apr 2013" -.SH NAME -zlib \- compression/decompression library -.SH SYNOPSIS -[see -.I zlib.h -for full description] -.SH DESCRIPTION -The -.I zlib -library is a general purpose data compression library. -The code is thread safe, assuming that the standard library functions -used are thread safe, such as memory allocation routines. -It provides in-memory compression and decompression functions, -including integrity checks of the uncompressed data. -This version of the library supports only one compression method (deflation) -but other algorithms may be added later -with the same stream interface. -.LP -Compression can be done in a single step if the buffers are large enough -or can be done by repeated calls of the compression function. -In the latter case, -the application must provide more input and/or consume the output -(providing more output space) before each call. -.LP -The library also supports reading and writing files in -.IR gzip (1) -(.gz) format -with an interface similar to that of stdio. -.LP -The library does not install any signal handler. -The decoder checks the consistency of the compressed data, -so the library should never crash even in the case of corrupted input. -.LP -All functions of the compression library are documented in the file -.IR zlib.h . -The distribution source includes examples of use of the library -in the files -.I test/example.c -and -.IR test/minigzip.c, -as well as other examples in the -.IR examples/ -directory. -.LP -Changes to this version are documented in the file -.I ChangeLog -that accompanies the source. -.LP -.I zlib -is available in Java using the java.util.zip package: -.IP -http://java.sun.com/developer/technicalArticles/Programming/compression/ -.LP -A Perl interface to -.IR zlib , -written by Paul Marquess (pmqs@cpan.org), -is available at CPAN (Comprehensive Perl Archive Network) sites, -including: -.IP -http://search.cpan.org/~pmqs/IO-Compress-Zlib/ -.LP -A Python interface to -.IR zlib , -written by A.M. Kuchling (amk@magnet.com), -is available in Python 1.5 and later versions: -.IP -http://docs.python.org/library/zlib.html -.LP -.I zlib -is built into -.IR tcl: -.IP -http://wiki.tcl.tk/4610 -.LP -An experimental package to read and write files in .zip format, -written on top of -.I zlib -by Gilles Vollant (info@winimage.com), -is available at: -.IP -http://www.winimage.com/zLibDll/minizip.html -and also in the -.I contrib/minizip -directory of the main -.I zlib -source distribution. -.SH "SEE ALSO" -The -.I zlib -web site can be found at: -.IP -http://zlib.net/ -.LP -The data format used by the zlib library is described by RFC -(Request for Comments) 1950 to 1952 in the files: -.IP -http://tools.ietf.org/html/rfc1950 (for the zlib header and trailer format) -.br -http://tools.ietf.org/html/rfc1951 (for the deflate compressed data format) -.br -http://tools.ietf.org/html/rfc1952 (for the gzip header and trailer format) -.LP -Mark Nelson wrote an article about -.I zlib -for the Jan. 1997 issue of Dr. Dobb's Journal; -a copy of the article is available at: -.IP -http://marknelson.us/1997/01/01/zlib-engine/ -.SH "REPORTING PROBLEMS" -Before reporting a problem, -please check the -.I zlib -web site to verify that you have the latest version of -.IR zlib ; -otherwise, -obtain the latest version and see if the problem still exists. -Please read the -.I zlib -FAQ at: -.IP -http://zlib.net/zlib_faq.html -.LP -before asking for help. -Send questions and/or comments to zlib@gzip.org, -or (for the Windows DLL version) to Gilles Vollant (info@winimage.com). -.SH AUTHORS -Version 1.2.8 -Copyright (C) 1995-2013 Jean-loup Gailly (jloup@gzip.org) -and Mark Adler (madler@alumni.caltech.edu). -.LP -This software is provided "as-is," -without any express or implied warranty. -In no event will the authors be held liable for any damages -arising from the use of this software. -See the distribution directory with respect to requirements -governing redistribution. -The deflate format used by -.I zlib -was defined by Phil Katz. -The deflate and -.I zlib -specifications were written by L. Peter Deutsch. -Thanks to all the people who reported problems and suggested various -improvements in -.IR zlib ; -who are too numerous to cite here. -.LP -UNIX manual page by R. P. C. Rodgers, -U.S. National Library of Medicine (rodgers@nlm.nih.gov). -.\" end of man page diff --git a/src/beast/test/zlib/zlib-1.2.8/zlib.3.pdf b/src/beast/test/zlib/zlib-1.2.8/zlib.3.pdf deleted file mode 100644 index a346b5d7e24..00000000000 Binary files a/src/beast/test/zlib/zlib-1.2.8/zlib.3.pdf and /dev/null differ diff --git a/src/beast/test/zlib/zlib-1.2.8/zlib.h b/src/beast/test/zlib/zlib-1.2.8/zlib.h deleted file mode 100644 index 3e0c7672ac5..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/zlib.h +++ /dev/null @@ -1,1768 +0,0 @@ -/* zlib.h -- interface of the 'zlib' general purpose compression library - version 1.2.8, April 28th, 2013 - - Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Jean-loup Gailly Mark Adler - jloup@gzip.org madler@alumni.caltech.edu - - - The data format used by the zlib library is described by RFCs (Request for - Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 - (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). -*/ - -#ifndef ZLIB_H -#define ZLIB_H - -#include "zconf.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define ZLIB_VERSION "1.2.8" -#define ZLIB_VERNUM 0x1280 -#define ZLIB_VER_MAJOR 1 -#define ZLIB_VER_MINOR 2 -#define ZLIB_VER_REVISION 8 -#define ZLIB_VER_SUBREVISION 0 - -/* - The 'zlib' compression library provides in-memory compression and - decompression functions, including integrity checks of the uncompressed data. - This version of the library supports only one compression method (deflation) - but other algorithms will be added later and will have the same stream - interface. - - Compression can be done in a single step if the buffers are large enough, - or can be done by repeated calls of the compression function. In the latter - case, the application must provide more input and/or consume the output - (providing more output space) before each call. - - The compressed data format used by default by the in-memory functions is - the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped - around a deflate stream, which is itself documented in RFC 1951. - - The library also supports reading and writing files in gzip (.gz) format - with an interface similar to that of stdio using the functions that start - with "gz". The gzip format is different from the zlib format. gzip is a - gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. - - This library can optionally read and write gzip streams in memory as well. - - The zlib format was designed to be compact and fast for use in memory - and on communications channels. The gzip format was designed for single- - file compression on file systems, has a larger header than zlib to maintain - directory information, and uses a different, slower check method than zlib. - - The library does not install any signal handler. The decoder checks - the consistency of the compressed data, so the library should never crash - even in case of corrupted input. -*/ - -typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); -typedef void (*free_func) OF((voidpf opaque, voidpf address)); - -struct internal_state; - -typedef struct z_stream_s { - z_const Bytef *next_in; /* next input byte */ - uInt avail_in; /* number of bytes available at next_in */ - uLong total_in; /* total number of input bytes read so far */ - - Bytef *next_out; /* next output byte should be put there */ - uInt avail_out; /* remaining free space at next_out */ - uLong total_out; /* total number of bytes output so far */ - - z_const char *msg; /* last error message, NULL if no error */ - struct internal_state FAR *state; /* not visible by applications */ - - alloc_func zalloc; /* used to allocate the internal state */ - free_func zfree; /* used to free the internal state */ - voidpf opaque; /* private data object passed to zalloc and zfree */ - - int data_type; /* best guess about the data type: binary or text */ - uLong adler; /* adler32 value of the uncompressed data */ - uLong reserved; /* reserved for future use */ -} z_stream; - -typedef z_stream FAR *z_streamp; - -/* - gzip header information passed to and from zlib routines. See RFC 1952 - for more details on the meanings of these fields. -*/ -typedef struct gz_header_s { - int text; /* true if compressed data believed to be text */ - uLong time; /* modification time */ - int xflags; /* extra flags (not used when writing a gzip file) */ - int os; /* operating system */ - Bytef *extra; /* pointer to extra field or Z_NULL if none */ - uInt extra_len; /* extra field length (valid if extra != Z_NULL) */ - uInt extra_max; /* space at extra (only when reading header) */ - Bytef *name; /* pointer to zero-terminated file name or Z_NULL */ - uInt name_max; /* space at name (only when reading header) */ - Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */ - uInt comm_max; /* space at comment (only when reading header) */ - int hcrc; /* true if there was or will be a header crc */ - int done; /* true when done reading gzip header (not used - when writing a gzip file) */ -} gz_header; - -typedef gz_header FAR *gz_headerp; - -/* - The application must update next_in and avail_in when avail_in has dropped - to zero. It must update next_out and avail_out when avail_out has dropped - to zero. The application must initialize zalloc, zfree and opaque before - calling the init function. All other fields are set by the compression - library and must not be updated by the application. - - The opaque value provided by the application will be passed as the first - parameter for calls of zalloc and zfree. This can be useful for custom - memory management. The compression library attaches no meaning to the - opaque value. - - zalloc must return Z_NULL if there is not enough memory for the object. - If zlib is used in a multi-threaded application, zalloc and zfree must be - thread safe. - - On 16-bit systems, the functions zalloc and zfree must be able to allocate - exactly 65536 bytes, but will not be required to allocate more than this if - the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers - returned by zalloc for objects of exactly 65536 bytes *must* have their - offset normalized to zero. The default allocation function provided by this - library ensures this (see zutil.c). To reduce memory requirements and avoid - any allocation of 64K objects, at the expense of compression ratio, compile - the library with -DMAX_WBITS=14 (see zconf.h). - - The fields total_in and total_out can be used for statistics or progress - reports. After compression, total_in holds the total size of the - uncompressed data and may be saved for use in the decompressor (particularly - if the decompressor wants to decompress everything in a single step). -*/ - - /* constants */ - -#define Z_NO_FLUSH 0 -#define Z_PARTIAL_FLUSH 1 -#define Z_SYNC_FLUSH 2 -#define Z_FULL_FLUSH 3 -#define Z_FINISH 4 -#define Z_BLOCK 5 -#define Z_TREES 6 -/* Allowed flush values; see deflate() and inflate() below for details */ - -#define Z_OK 0 -#define Z_STREAM_END 1 -#define Z_NEED_DICT 2 -#define Z_ERRNO (-1) -#define Z_STREAM_ERROR (-2) -#define Z_DATA_ERROR (-3) -#define Z_MEM_ERROR (-4) -#define Z_BUF_ERROR (-5) -#define Z_VERSION_ERROR (-6) -/* Return codes for the compression/decompression functions. Negative values - * are errors, positive values are used for special but normal events. - */ - -#define Z_NO_COMPRESSION 0 -#define Z_BEST_SPEED 1 -#define Z_BEST_COMPRESSION 9 -#define Z_DEFAULT_COMPRESSION (-1) -/* compression levels */ - -#define Z_FILTERED 1 -#define Z_HUFFMAN_ONLY 2 -#define Z_RLE 3 -#define Z_FIXED 4 -#define Z_DEFAULT_STRATEGY 0 -/* compression strategy; see deflateInit2() below for details */ - -#define Z_BINARY 0 -#define Z_TEXT 1 -#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ -#define Z_UNKNOWN 2 -/* Possible values of the data_type field (though see inflate()) */ - -#define Z_DEFLATED 8 -/* The deflate compression method (the only one supported in this version) */ - -#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ - -#define zlib_version zlibVersion() -/* for compatibility with versions < 1.0.2 */ - - - /* basic functions */ - -ZEXTERN const char * ZEXPORT zlibVersion OF((void)); -/* The application can compare zlibVersion and ZLIB_VERSION for consistency. - If the first character differs, the library code actually used is not - compatible with the zlib.h header file used by the application. This check - is automatically made by deflateInit and inflateInit. - */ - -/* -ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); - - Initializes the internal stream state for compression. The fields - zalloc, zfree and opaque must be initialized before by the caller. If - zalloc and zfree are set to Z_NULL, deflateInit updates them to use default - allocation functions. - - The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: - 1 gives best speed, 9 gives best compression, 0 gives no compression at all - (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION - requests a default compromise between speed and compression (currently - equivalent to level 6). - - deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_STREAM_ERROR if level is not a valid compression level, or - Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible - with the version assumed by the caller (ZLIB_VERSION). msg is set to null - if there is no error message. deflateInit does not perform any compression: - this will be done by deflate(). -*/ - - -ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); -/* - deflate compresses as much data as possible, and stops when the input - buffer becomes empty or the output buffer becomes full. It may introduce - some output latency (reading input without producing any output) except when - forced to flush. - - The detailed semantics are as follows. deflate performs one or both of the - following actions: - - - Compress more input starting at next_in and update next_in and avail_in - accordingly. If not all input can be processed (because there is not - enough room in the output buffer), next_in and avail_in are updated and - processing will resume at this point for the next call of deflate(). - - - Provide more output starting at next_out and update next_out and avail_out - accordingly. This action is forced if the parameter flush is non zero. - Forcing flush frequently degrades the compression ratio, so this parameter - should be set only when necessary (in interactive applications). Some - output may be provided even if flush is not set. - - Before the call of deflate(), the application should ensure that at least - one of the actions is possible, by providing more input and/or consuming more - output, and updating avail_in or avail_out accordingly; avail_out should - never be zero before the call. The application can consume the compressed - output when it wants, for example when the output buffer is full (avail_out - == 0), or after each call of deflate(). If deflate returns Z_OK and with - zero avail_out, it must be called again after making room in the output - buffer because there might be more output pending. - - Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to - decide how much data to accumulate before producing output, in order to - maximize compression. - - If the parameter flush is set to Z_SYNC_FLUSH, all pending output is - flushed to the output buffer and the output is aligned on a byte boundary, so - that the decompressor can get all input data available so far. (In - particular avail_in is zero after the call if enough output space has been - provided before the call.) Flushing may degrade compression for some - compression algorithms and so it should be used only when necessary. This - completes the current deflate block and follows it with an empty stored block - that is three bits plus filler bits to the next byte, followed by four bytes - (00 00 ff ff). - - If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the - output buffer, but the output is not aligned to a byte boundary. All of the - input data so far will be available to the decompressor, as for Z_SYNC_FLUSH. - This completes the current deflate block and follows it with an empty fixed - codes block that is 10 bits long. This assures that enough bytes are output - in order for the decompressor to finish the block before the empty fixed code - block. - - If flush is set to Z_BLOCK, a deflate block is completed and emitted, as - for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to - seven bits of the current block are held to be written as the next byte after - the next deflate block is completed. In this case, the decompressor may not - be provided enough bits at this point in order to complete decompression of - the data provided so far to the compressor. It may need to wait for the next - block to be emitted. This is for advanced applications that need to control - the emission of deflate blocks. - - If flush is set to Z_FULL_FLUSH, all output is flushed as with - Z_SYNC_FLUSH, and the compression state is reset so that decompression can - restart from this point if previous compressed data has been damaged or if - random access is desired. Using Z_FULL_FLUSH too often can seriously degrade - compression. - - If deflate returns with avail_out == 0, this function must be called again - with the same value of the flush parameter and more output space (updated - avail_out), until the flush is complete (deflate returns with non-zero - avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that - avail_out is greater than six to avoid repeated flush markers due to - avail_out == 0 on return. - - If the parameter flush is set to Z_FINISH, pending input is processed, - pending output is flushed and deflate returns with Z_STREAM_END if there was - enough output space; if deflate returns with Z_OK, this function must be - called again with Z_FINISH and more output space (updated avail_out) but no - more input data, until it returns with Z_STREAM_END or an error. After - deflate has returned Z_STREAM_END, the only possible operations on the stream - are deflateReset or deflateEnd. - - Z_FINISH can be used immediately after deflateInit if all the compression - is to be done in a single step. In this case, avail_out must be at least the - value returned by deflateBound (see below). Then deflate is guaranteed to - return Z_STREAM_END. If not enough output space is provided, deflate will - not return Z_STREAM_END, and it must be called again as described above. - - deflate() sets strm->adler to the adler32 checksum of all input read - so far (that is, total_in bytes). - - deflate() may update strm->data_type if it can make a good guess about - the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered - binary. This field is only for information purposes and does not affect the - compression algorithm in any manner. - - deflate() returns Z_OK if some progress has been made (more input - processed or more output produced), Z_STREAM_END if all input has been - consumed and all output has been produced (only when flush is set to - Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example - if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible - (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not - fatal, and deflate() can be called again with more input and more output - space to continue compressing. -*/ - - -ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); -/* - All dynamically allocated data structures for this stream are freed. - This function discards any unprocessed input and does not flush any pending - output. - - deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the - stream state was inconsistent, Z_DATA_ERROR if the stream was freed - prematurely (some input or output was discarded). In the error case, msg - may be set but then points to a static string (which must not be - deallocated). -*/ - - -/* -ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); - - Initializes the internal stream state for decompression. The fields - next_in, avail_in, zalloc, zfree and opaque must be initialized before by - the caller. If next_in is not Z_NULL and avail_in is large enough (the - exact value depends on the compression method), inflateInit determines the - compression method from the zlib header and allocates all data structures - accordingly; otherwise the allocation will be deferred to the first call of - inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to - use default allocation functions. - - inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_VERSION_ERROR if the zlib library version is incompatible with the - version assumed by the caller, or Z_STREAM_ERROR if the parameters are - invalid, such as a null pointer to the structure. msg is set to null if - there is no error message. inflateInit does not perform any decompression - apart from possibly reading the zlib header if present: actual decompression - will be done by inflate(). (So next_in and avail_in may be modified, but - next_out and avail_out are unused and unchanged.) The current implementation - of inflateInit() does not process any header information -- that is deferred - until inflate() is called. -*/ - - -ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); -/* - inflate decompresses as much data as possible, and stops when the input - buffer becomes empty or the output buffer becomes full. It may introduce - some output latency (reading input without producing any output) except when - forced to flush. - - The detailed semantics are as follows. inflate performs one or both of the - following actions: - - - Decompress more input starting at next_in and update next_in and avail_in - accordingly. If not all input can be processed (because there is not - enough room in the output buffer), next_in is updated and processing will - resume at this point for the next call of inflate(). - - - Provide more output starting at next_out and update next_out and avail_out - accordingly. inflate() provides as much output as possible, until there is - no more input data or no more space in the output buffer (see below about - the flush parameter). - - Before the call of inflate(), the application should ensure that at least - one of the actions is possible, by providing more input and/or consuming more - output, and updating the next_* and avail_* values accordingly. The - application can consume the uncompressed output when it wants, for example - when the output buffer is full (avail_out == 0), or after each call of - inflate(). If inflate returns Z_OK and with zero avail_out, it must be - called again after making room in the output buffer because there might be - more output pending. - - The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH, - Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much - output as possible to the output buffer. Z_BLOCK requests that inflate() - stop if and when it gets to the next deflate block boundary. When decoding - the zlib or gzip format, this will cause inflate() to return immediately - after the header and before the first block. When doing a raw inflate, - inflate() will go ahead and process the first block, and will return when it - gets to the end of that block, or when it runs out of data. - - The Z_BLOCK option assists in appending to or combining deflate streams. - Also to assist in this, on return inflate() will set strm->data_type to the - number of unused bits in the last byte taken from strm->next_in, plus 64 if - inflate() is currently decoding the last block in the deflate stream, plus - 128 if inflate() returned immediately after decoding an end-of-block code or - decoding the complete header up to just before the first byte of the deflate - stream. The end-of-block will not be indicated until all of the uncompressed - data from that block has been written to strm->next_out. The number of - unused bits may in general be greater than seven, except when bit 7 of - data_type is set, in which case the number of unused bits will be less than - eight. data_type is set as noted here every time inflate() returns for all - flush options, and so can be used to determine the amount of currently - consumed input in bits. - - The Z_TREES option behaves as Z_BLOCK does, but it also returns when the - end of each deflate block header is reached, before any actual data in that - block is decoded. This allows the caller to determine the length of the - deflate block header for later use in random access within a deflate block. - 256 is added to the value of strm->data_type when inflate() returns - immediately after reaching the end of the deflate block header. - - inflate() should normally be called until it returns Z_STREAM_END or an - error. However if all decompression is to be performed in a single step (a - single call of inflate), the parameter flush should be set to Z_FINISH. In - this case all pending input is processed and all pending output is flushed; - avail_out must be large enough to hold all of the uncompressed data for the - operation to complete. (The size of the uncompressed data may have been - saved by the compressor for this purpose.) The use of Z_FINISH is not - required to perform an inflation in one step. However it may be used to - inform inflate that a faster approach can be used for the single inflate() - call. Z_FINISH also informs inflate to not maintain a sliding window if the - stream completes, which reduces inflate's memory footprint. If the stream - does not complete, either because not all of the stream is provided or not - enough output space is provided, then a sliding window will be allocated and - inflate() can be called again to continue the operation as if Z_NO_FLUSH had - been used. - - In this implementation, inflate() always flushes as much output as - possible to the output buffer, and always uses the faster approach on the - first call. So the effects of the flush parameter in this implementation are - on the return value of inflate() as noted below, when inflate() returns early - when Z_BLOCK or Z_TREES is used, and when inflate() avoids the allocation of - memory for a sliding window when Z_FINISH is used. - - If a preset dictionary is needed after this call (see inflateSetDictionary - below), inflate sets strm->adler to the Adler-32 checksum of the dictionary - chosen by the compressor and returns Z_NEED_DICT; otherwise it sets - strm->adler to the Adler-32 checksum of all output produced so far (that is, - total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described - below. At the end of the stream, inflate() checks that its computed adler32 - checksum is equal to that saved by the compressor and returns Z_STREAM_END - only if the checksum is correct. - - inflate() can decompress and check either zlib-wrapped or gzip-wrapped - deflate data. The header type is detected automatically, if requested when - initializing with inflateInit2(). Any information contained in the gzip - header is not retained, so applications that need that information should - instead use raw inflate, see inflateInit2() below, or inflateBack() and - perform their own processing of the gzip header and trailer. When processing - gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output - producted so far. The CRC-32 is checked against the gzip trailer. - - inflate() returns Z_OK if some progress has been made (more input processed - or more output produced), Z_STREAM_END if the end of the compressed data has - been reached and all uncompressed output has been produced, Z_NEED_DICT if a - preset dictionary is needed at this point, Z_DATA_ERROR if the input data was - corrupted (input stream not conforming to the zlib format or incorrect check - value), Z_STREAM_ERROR if the stream structure was inconsistent (for example - next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory, - Z_BUF_ERROR if no progress is possible or if there was not enough room in the - output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and - inflate() can be called again with more input and more output space to - continue decompressing. If Z_DATA_ERROR is returned, the application may - then call inflateSync() to look for a good compression block if a partial - recovery of the data is desired. -*/ - - -ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); -/* - All dynamically allocated data structures for this stream are freed. - This function discards any unprocessed input and does not flush any pending - output. - - inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state - was inconsistent. In the error case, msg may be set but then points to a - static string (which must not be deallocated). -*/ - - - /* Advanced functions */ - -/* - The following functions are needed only in some special applications. -*/ - -/* -ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, - int level, - int method, - int windowBits, - int memLevel, - int strategy)); - - This is another version of deflateInit with more compression options. The - fields next_in, zalloc, zfree and opaque must be initialized before by the - caller. - - The method parameter is the compression method. It must be Z_DEFLATED in - this version of the library. - - The windowBits parameter is the base two logarithm of the window size - (the size of the history buffer). It should be in the range 8..15 for this - version of the library. Larger values of this parameter result in better - compression at the expense of memory usage. The default value is 15 if - deflateInit is used instead. - - windowBits can also be -8..-15 for raw deflate. In this case, -windowBits - determines the window size. deflate() will then generate raw deflate data - with no zlib header or trailer, and will not compute an adler32 check value. - - windowBits can also be greater than 15 for optional gzip encoding. Add - 16 to windowBits to write a simple gzip header and trailer around the - compressed data instead of a zlib wrapper. The gzip header will have no - file name, no extra data, no comment, no modification time (set to zero), no - header crc, and the operating system will be set to 255 (unknown). If a - gzip stream is being written, strm->adler is a crc32 instead of an adler32. - - The memLevel parameter specifies how much memory should be allocated - for the internal compression state. memLevel=1 uses minimum memory but is - slow and reduces compression ratio; memLevel=9 uses maximum memory for - optimal speed. The default value is 8. See zconf.h for total memory usage - as a function of windowBits and memLevel. - - The strategy parameter is used to tune the compression algorithm. Use the - value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a - filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no - string match), or Z_RLE to limit match distances to one (run-length - encoding). Filtered data consists mostly of small values with a somewhat - random distribution. In this case, the compression algorithm is tuned to - compress them better. The effect of Z_FILTERED is to force more Huffman - coding and less string matching; it is somewhat intermediate between - Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as - fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The - strategy parameter only affects the compression ratio but not the - correctness of the compressed output even if it is not set appropriately. - Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler - decoder for special applications. - - deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid - method), or Z_VERSION_ERROR if the zlib library version (zlib_version) is - incompatible with the version assumed by the caller (ZLIB_VERSION). msg is - set to null if there is no error message. deflateInit2 does not perform any - compression: this will be done by deflate(). -*/ - -ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, - const Bytef *dictionary, - uInt dictLength)); -/* - Initializes the compression dictionary from the given byte sequence - without producing any compressed output. When using the zlib format, this - function must be called immediately after deflateInit, deflateInit2 or - deflateReset, and before any call of deflate. When doing raw deflate, this - function must be called either before any call of deflate, or immediately - after the completion of a deflate block, i.e. after all input has been - consumed and all output has been delivered when using any of the flush - options Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH. The - compressor and decompressor must use exactly the same dictionary (see - inflateSetDictionary). - - The dictionary should consist of strings (byte sequences) that are likely - to be encountered later in the data to be compressed, with the most commonly - used strings preferably put towards the end of the dictionary. Using a - dictionary is most useful when the data to be compressed is short and can be - predicted with good accuracy; the data can then be compressed better than - with the default empty dictionary. - - Depending on the size of the compression data structures selected by - deflateInit or deflateInit2, a part of the dictionary may in effect be - discarded, for example if the dictionary is larger than the window size - provided in deflateInit or deflateInit2. Thus the strings most likely to be - useful should be put at the end of the dictionary, not at the front. In - addition, the current implementation of deflate will use at most the window - size minus 262 bytes of the provided dictionary. - - Upon return of this function, strm->adler is set to the adler32 value - of the dictionary; the decompressor may later use this value to determine - which dictionary has been used by the compressor. (The adler32 value - applies to the whole dictionary even if only a subset of the dictionary is - actually used by the compressor.) If a raw deflate was requested, then the - adler32 value is not computed and strm->adler is not set. - - deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a - parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is - inconsistent (for example if deflate has already been called for this stream - or if not at a block boundary for raw deflate). deflateSetDictionary does - not perform any compression: this will be done by deflate(). -*/ - -ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, - z_streamp source)); -/* - Sets the destination stream as a complete copy of the source stream. - - This function can be useful when several compression strategies will be - tried, for example when there are several ways of pre-processing the input - data with a filter. The streams that will be discarded should then be freed - by calling deflateEnd. Note that deflateCopy duplicates the internal - compression state which can be quite large, so this strategy is slow and can - consume lots of memory. - - deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_STREAM_ERROR if the source stream state was inconsistent - (such as zalloc being Z_NULL). msg is left unchanged in both source and - destination. -*/ - -ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); -/* - This function is equivalent to deflateEnd followed by deflateInit, - but does not free and reallocate all the internal compression state. The - stream will keep the same compression level and any other attributes that - may have been set by deflateInit2. - - deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent (such as zalloc or state being Z_NULL). -*/ - -ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, - int level, - int strategy)); -/* - Dynamically update the compression level and compression strategy. The - interpretation of level and strategy is as in deflateInit2. This can be - used to switch between compression and straight copy of the input data, or - to switch to a different kind of input data requiring a different strategy. - If the compression level is changed, the input available so far is - compressed with the old level (and may be flushed); the new level will take - effect only at the next call of deflate(). - - Before the call of deflateParams, the stream state must be set as for - a call of deflate(), since the currently available input may have to be - compressed and flushed. In particular, strm->avail_out must be non-zero. - - deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source - stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR if - strm->avail_out was zero. -*/ - -ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, - int good_length, - int max_lazy, - int nice_length, - int max_chain)); -/* - Fine tune deflate's internal compression parameters. This should only be - used by someone who understands the algorithm used by zlib's deflate for - searching for the best matching string, and even then only by the most - fanatic optimizer trying to squeeze out the last compressed bit for their - specific input data. Read the deflate.c source code for the meaning of the - max_lazy, good_length, nice_length, and max_chain parameters. - - deflateTune() can be called after deflateInit() or deflateInit2(), and - returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. - */ - -ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, - uLong sourceLen)); -/* - deflateBound() returns an upper bound on the compressed size after - deflation of sourceLen bytes. It must be called after deflateInit() or - deflateInit2(), and after deflateSetHeader(), if used. This would be used - to allocate an output buffer for deflation in a single pass, and so would be - called before deflate(). If that first deflate() call is provided the - sourceLen input bytes, an output buffer allocated to the size returned by - deflateBound(), and the flush value Z_FINISH, then deflate() is guaranteed - to return Z_STREAM_END. Note that it is possible for the compressed size to - be larger than the value returned by deflateBound() if flush options other - than Z_FINISH or Z_NO_FLUSH are used. -*/ - -ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm, - unsigned *pending, - int *bits)); -/* - deflatePending() returns the number of bytes and bits of output that have - been generated, but not yet provided in the available output. The bytes not - provided would be due to the available output space having being consumed. - The number of bits of output not provided are between 0 and 7, where they - await more bits to join them in order to fill out a full byte. If pending - or bits are Z_NULL, then those values are not set. - - deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent. - */ - -ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, - int bits, - int value)); -/* - deflatePrime() inserts bits in the deflate output stream. The intent - is that this function is used to start off the deflate output with the bits - leftover from a previous deflate stream when appending to it. As such, this - function can only be used for raw deflate, and must be used before the first - deflate() call after a deflateInit2() or deflateReset(). bits must be less - than or equal to 16, and that many of the least significant bits of value - will be inserted in the output. - - deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough - room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the - source stream state was inconsistent. -*/ - -ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, - gz_headerp head)); -/* - deflateSetHeader() provides gzip header information for when a gzip - stream is requested by deflateInit2(). deflateSetHeader() may be called - after deflateInit2() or deflateReset() and before the first call of - deflate(). The text, time, os, extra field, name, and comment information - in the provided gz_header structure are written to the gzip header (xflag is - ignored -- the extra flags are set according to the compression level). The - caller must assure that, if not Z_NULL, name and comment are terminated with - a zero byte, and that if extra is not Z_NULL, that extra_len bytes are - available there. If hcrc is true, a gzip header crc is included. Note that - the current versions of the command-line version of gzip (up through version - 1.3.x) do not support header crc's, and will report that it is a "multi-part - gzip file" and give up. - - If deflateSetHeader is not used, the default gzip header has text false, - the time set to zero, and os set to 255, with no extra, name, or comment - fields. The gzip header is returned to the default state by deflateReset(). - - deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent. -*/ - -/* -ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, - int windowBits)); - - This is another version of inflateInit with an extra parameter. The - fields next_in, avail_in, zalloc, zfree and opaque must be initialized - before by the caller. - - The windowBits parameter is the base two logarithm of the maximum window - size (the size of the history buffer). It should be in the range 8..15 for - this version of the library. The default value is 15 if inflateInit is used - instead. windowBits must be greater than or equal to the windowBits value - provided to deflateInit2() while compressing, or it must be equal to 15 if - deflateInit2() was not used. If a compressed stream with a larger window - size is given as input, inflate() will return with the error code - Z_DATA_ERROR instead of trying to allocate a larger window. - - windowBits can also be zero to request that inflate use the window size in - the zlib header of the compressed stream. - - windowBits can also be -8..-15 for raw inflate. In this case, -windowBits - determines the window size. inflate() will then process raw deflate data, - not looking for a zlib or gzip header, not generating a check value, and not - looking for any check values for comparison at the end of the stream. This - is for use with other formats that use the deflate compressed data format - such as zip. Those formats provide their own check values. If a custom - format is developed using the raw deflate format for compressed data, it is - recommended that a check value such as an adler32 or a crc32 be applied to - the uncompressed data as is done in the zlib, gzip, and zip formats. For - most applications, the zlib format should be used as is. Note that comments - above on the use in deflateInit2() applies to the magnitude of windowBits. - - windowBits can also be greater than 15 for optional gzip decoding. Add - 32 to windowBits to enable zlib and gzip decoding with automatic header - detection, or add 16 to decode only the gzip format (the zlib format will - return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a - crc32 instead of an adler32. - - inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_VERSION_ERROR if the zlib library version is incompatible with the - version assumed by the caller, or Z_STREAM_ERROR if the parameters are - invalid, such as a null pointer to the structure. msg is set to null if - there is no error message. inflateInit2 does not perform any decompression - apart from possibly reading the zlib header if present: actual decompression - will be done by inflate(). (So next_in and avail_in may be modified, but - next_out and avail_out are unused and unchanged.) The current implementation - of inflateInit2() does not process any header information -- that is - deferred until inflate() is called. -*/ - -ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, - const Bytef *dictionary, - uInt dictLength)); -/* - Initializes the decompression dictionary from the given uncompressed byte - sequence. This function must be called immediately after a call of inflate, - if that call returned Z_NEED_DICT. The dictionary chosen by the compressor - can be determined from the adler32 value returned by that call of inflate. - The compressor and decompressor must use exactly the same dictionary (see - deflateSetDictionary). For raw inflate, this function can be called at any - time to set the dictionary. If the provided dictionary is smaller than the - window and there is already data in the window, then the provided dictionary - will amend what's there. The application must insure that the dictionary - that was used for compression is provided. - - inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a - parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is - inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the - expected one (incorrect adler32 value). inflateSetDictionary does not - perform any decompression: this will be done by subsequent calls of - inflate(). -*/ - -ZEXTERN int ZEXPORT inflateGetDictionary OF((z_streamp strm, - Bytef *dictionary, - uInt *dictLength)); -/* - Returns the sliding dictionary being maintained by inflate. dictLength is - set to the number of bytes in the dictionary, and that many bytes are copied - to dictionary. dictionary must have enough space, where 32768 bytes is - always enough. If inflateGetDictionary() is called with dictionary equal to - Z_NULL, then only the dictionary length is returned, and nothing is copied. - Similary, if dictLength is Z_NULL, then it is not set. - - inflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the - stream state is inconsistent. -*/ - -ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); -/* - Skips invalid compressed data until a possible full flush point (see above - for the description of deflate with Z_FULL_FLUSH) can be found, or until all - available input is skipped. No output is provided. - - inflateSync searches for a 00 00 FF FF pattern in the compressed data. - All full flush points have this pattern, but not all occurrences of this - pattern are full flush points. - - inflateSync returns Z_OK if a possible full flush point has been found, - Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point - has been found, or Z_STREAM_ERROR if the stream structure was inconsistent. - In the success case, the application may save the current current value of - total_in which indicates where valid compressed data was found. In the - error case, the application may repeatedly call inflateSync, providing more - input each time, until success or end of the input data. -*/ - -ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, - z_streamp source)); -/* - Sets the destination stream as a complete copy of the source stream. - - This function can be useful when randomly accessing a large stream. The - first pass through the stream can periodically record the inflate state, - allowing restarting inflate at those points when randomly accessing the - stream. - - inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_STREAM_ERROR if the source stream state was inconsistent - (such as zalloc being Z_NULL). msg is left unchanged in both source and - destination. -*/ - -ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); -/* - This function is equivalent to inflateEnd followed by inflateInit, - but does not free and reallocate all the internal decompression state. The - stream will keep attributes that may have been set by inflateInit2. - - inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent (such as zalloc or state being Z_NULL). -*/ - -ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm, - int windowBits)); -/* - This function is the same as inflateReset, but it also permits changing - the wrap and window size requests. The windowBits parameter is interpreted - the same as it is for inflateInit2. - - inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent (such as zalloc or state being Z_NULL), or if - the windowBits parameter is invalid. -*/ - -ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, - int bits, - int value)); -/* - This function inserts bits in the inflate input stream. The intent is - that this function is used to start inflating at a bit position in the - middle of a byte. The provided bits will be used before any bytes are used - from next_in. This function should only be used with raw inflate, and - should be used before the first inflate() call after inflateInit2() or - inflateReset(). bits must be less than or equal to 16, and that many of the - least significant bits of value will be inserted in the input. - - If bits is negative, then the input stream bit buffer is emptied. Then - inflatePrime() can be called again to put bits in the buffer. This is used - to clear out bits leftover after feeding inflate a block description prior - to feeding inflate codes. - - inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent. -*/ - -ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm)); -/* - This function returns two values, one in the lower 16 bits of the return - value, and the other in the remaining upper bits, obtained by shifting the - return value down 16 bits. If the upper value is -1 and the lower value is - zero, then inflate() is currently decoding information outside of a block. - If the upper value is -1 and the lower value is non-zero, then inflate is in - the middle of a stored block, with the lower value equaling the number of - bytes from the input remaining to copy. If the upper value is not -1, then - it is the number of bits back from the current bit position in the input of - the code (literal or length/distance pair) currently being processed. In - that case the lower value is the number of bytes already emitted for that - code. - - A code is being processed if inflate is waiting for more input to complete - decoding of the code, or if it has completed decoding but is waiting for - more output space to write the literal or match data. - - inflateMark() is used to mark locations in the input data for random - access, which may be at bit positions, and to note those cases where the - output of a code may span boundaries of random access blocks. The current - location in the input stream can be determined from avail_in and data_type - as noted in the description for the Z_BLOCK flush parameter for inflate. - - inflateMark returns the value noted above or -1 << 16 if the provided - source stream state was inconsistent. -*/ - -ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, - gz_headerp head)); -/* - inflateGetHeader() requests that gzip header information be stored in the - provided gz_header structure. inflateGetHeader() may be called after - inflateInit2() or inflateReset(), and before the first call of inflate(). - As inflate() processes the gzip stream, head->done is zero until the header - is completed, at which time head->done is set to one. If a zlib stream is - being decoded, then head->done is set to -1 to indicate that there will be - no gzip header information forthcoming. Note that Z_BLOCK or Z_TREES can be - used to force inflate() to return immediately after header processing is - complete and before any actual data is decompressed. - - The text, time, xflags, and os fields are filled in with the gzip header - contents. hcrc is set to true if there is a header CRC. (The header CRC - was valid if done is set to one.) If extra is not Z_NULL, then extra_max - contains the maximum number of bytes to write to extra. Once done is true, - extra_len contains the actual extra field length, and extra contains the - extra field, or that field truncated if extra_max is less than extra_len. - If name is not Z_NULL, then up to name_max characters are written there, - terminated with a zero unless the length is greater than name_max. If - comment is not Z_NULL, then up to comm_max characters are written there, - terminated with a zero unless the length is greater than comm_max. When any - of extra, name, or comment are not Z_NULL and the respective field is not - present in the header, then that field is set to Z_NULL to signal its - absence. This allows the use of deflateSetHeader() with the returned - structure to duplicate the header. However if those fields are set to - allocated memory, then the application will need to save those pointers - elsewhere so that they can be eventually freed. - - If inflateGetHeader is not used, then the header information is simply - discarded. The header is always checked for validity, including the header - CRC if present. inflateReset() will reset the process to discard the header - information. The application would need to call inflateGetHeader() again to - retrieve the header from the next gzip stream. - - inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent. -*/ - -/* -ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, - unsigned char FAR *window)); - - Initialize the internal stream state for decompression using inflateBack() - calls. The fields zalloc, zfree and opaque in strm must be initialized - before the call. If zalloc and zfree are Z_NULL, then the default library- - derived memory allocation routines are used. windowBits is the base two - logarithm of the window size, in the range 8..15. window is a caller - supplied buffer of that size. Except for special applications where it is - assured that deflate was used with small window sizes, windowBits must be 15 - and a 32K byte window must be supplied to be able to decompress general - deflate streams. - - See inflateBack() for the usage of these routines. - - inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of - the parameters are invalid, Z_MEM_ERROR if the internal state could not be - allocated, or Z_VERSION_ERROR if the version of the library does not match - the version of the header file. -*/ - -typedef unsigned (*in_func) OF((void FAR *, - z_const unsigned char FAR * FAR *)); -typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); - -ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, - in_func in, void FAR *in_desc, - out_func out, void FAR *out_desc)); -/* - inflateBack() does a raw inflate with a single call using a call-back - interface for input and output. This is potentially more efficient than - inflate() for file i/o applications, in that it avoids copying between the - output and the sliding window by simply making the window itself the output - buffer. inflate() can be faster on modern CPUs when used with large - buffers. inflateBack() trusts the application to not change the output - buffer passed by the output function, at least until inflateBack() returns. - - inflateBackInit() must be called first to allocate the internal state - and to initialize the state with the user-provided window buffer. - inflateBack() may then be used multiple times to inflate a complete, raw - deflate stream with each call. inflateBackEnd() is then called to free the - allocated state. - - A raw deflate stream is one with no zlib or gzip header or trailer. - This routine would normally be used in a utility that reads zip or gzip - files and writes out uncompressed files. The utility would decode the - header and process the trailer on its own, hence this routine expects only - the raw deflate stream to decompress. This is different from the normal - behavior of inflate(), which expects either a zlib or gzip header and - trailer around the deflate stream. - - inflateBack() uses two subroutines supplied by the caller that are then - called by inflateBack() for input and output. inflateBack() calls those - routines until it reads a complete deflate stream and writes out all of the - uncompressed data, or until it encounters an error. The function's - parameters and return types are defined above in the in_func and out_func - typedefs. inflateBack() will call in(in_desc, &buf) which should return the - number of bytes of provided input, and a pointer to that input in buf. If - there is no input available, in() must return zero--buf is ignored in that - case--and inflateBack() will return a buffer error. inflateBack() will call - out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out() - should return zero on success, or non-zero on failure. If out() returns - non-zero, inflateBack() will return with an error. Neither in() nor out() - are permitted to change the contents of the window provided to - inflateBackInit(), which is also the buffer that out() uses to write from. - The length written by out() will be at most the window size. Any non-zero - amount of input may be provided by in(). - - For convenience, inflateBack() can be provided input on the first call by - setting strm->next_in and strm->avail_in. If that input is exhausted, then - in() will be called. Therefore strm->next_in must be initialized before - calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called - immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in - must also be initialized, and then if strm->avail_in is not zero, input will - initially be taken from strm->next_in[0 .. strm->avail_in - 1]. - - The in_desc and out_desc parameters of inflateBack() is passed as the - first parameter of in() and out() respectively when they are called. These - descriptors can be optionally used to pass any information that the caller- - supplied in() and out() functions need to do their job. - - On return, inflateBack() will set strm->next_in and strm->avail_in to - pass back any unused input that was provided by the last in() call. The - return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR - if in() or out() returned an error, Z_DATA_ERROR if there was a format error - in the deflate stream (in which case strm->msg is set to indicate the nature - of the error), or Z_STREAM_ERROR if the stream was not properly initialized. - In the case of Z_BUF_ERROR, an input or output error can be distinguished - using strm->next_in which will be Z_NULL only if in() returned an error. If - strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning - non-zero. (in() will always be called before out(), so strm->next_in is - assured to be defined if out() returns non-zero.) Note that inflateBack() - cannot return Z_OK. -*/ - -ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); -/* - All memory allocated by inflateBackInit() is freed. - - inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream - state was inconsistent. -*/ - -ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); -/* Return flags indicating compile-time options. - - Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: - 1.0: size of uInt - 3.2: size of uLong - 5.4: size of voidpf (pointer) - 7.6: size of z_off_t - - Compiler, assembler, and debug options: - 8: DEBUG - 9: ASMV or ASMINF -- use ASM code - 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention - 11: 0 (reserved) - - One-time table building (smaller code, but not thread-safe if true): - 12: BUILDFIXED -- build static block decoding tables when needed - 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed - 14,15: 0 (reserved) - - Library content (indicates missing functionality): - 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking - deflate code when not needed) - 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect - and decode gzip streams (to avoid linking crc code) - 18-19: 0 (reserved) - - Operation variations (changes in library functionality): - 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate - 21: FASTEST -- deflate algorithm with only one, lowest compression level - 22,23: 0 (reserved) - - The sprintf variant used by gzprintf (zero is best): - 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format - 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure! - 26: 0 = returns value, 1 = void -- 1 means inferred string length returned - - Remainder: - 27-31: 0 (reserved) - */ - -#ifndef Z_SOLO - - /* utility functions */ - -/* - The following utility functions are implemented on top of the basic - stream-oriented functions. To simplify the interface, some default options - are assumed (compression level and memory usage, standard memory allocation - functions). The source code of these utility functions can be modified if - you need special options. -*/ - -ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen)); -/* - Compresses the source buffer into the destination buffer. sourceLen is - the byte length of the source buffer. Upon entry, destLen is the total size - of the destination buffer, which must be at least the value returned by - compressBound(sourceLen). Upon exit, destLen is the actual size of the - compressed buffer. - - compress returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_BUF_ERROR if there was not enough room in the output - buffer. -*/ - -ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen, - int level)); -/* - Compresses the source buffer into the destination buffer. The level - parameter has the same meaning as in deflateInit. sourceLen is the byte - length of the source buffer. Upon entry, destLen is the total size of the - destination buffer, which must be at least the value returned by - compressBound(sourceLen). Upon exit, destLen is the actual size of the - compressed buffer. - - compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_BUF_ERROR if there was not enough room in the output buffer, - Z_STREAM_ERROR if the level parameter is invalid. -*/ - -ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); -/* - compressBound() returns an upper bound on the compressed size after - compress() or compress2() on sourceLen bytes. It would be used before a - compress() or compress2() call to allocate the destination buffer. -*/ - -ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen)); -/* - Decompresses the source buffer into the destination buffer. sourceLen is - the byte length of the source buffer. Upon entry, destLen is the total size - of the destination buffer, which must be large enough to hold the entire - uncompressed data. (The size of the uncompressed data must have been saved - previously by the compressor and transmitted to the decompressor by some - mechanism outside the scope of this compression library.) Upon exit, destLen - is the actual size of the uncompressed buffer. - - uncompress returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_BUF_ERROR if there was not enough room in the output - buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In - the case where there is not enough room, uncompress() will fill the output - buffer with the uncompressed data up to that point. -*/ - - /* gzip file access functions */ - -/* - This library supports reading and writing files in gzip (.gz) format with - an interface similar to that of stdio, using the functions that start with - "gz". The gzip format is different from the zlib format. gzip is a gzip - wrapper, documented in RFC 1952, wrapped around a deflate stream. -*/ - -typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */ - -/* -ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); - - Opens a gzip (.gz) file for reading or writing. The mode parameter is as - in fopen ("rb" or "wb") but can also include a compression level ("wb9") or - a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only - compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F' - for fixed code compression as in "wb9F". (See the description of - deflateInit2 for more information about the strategy parameter.) 'T' will - request transparent writing or appending with no compression and not using - the gzip format. - - "a" can be used instead of "w" to request that the gzip stream that will - be written be appended to the file. "+" will result in an error, since - reading and writing to the same gzip file is not supported. The addition of - "x" when writing will create the file exclusively, which fails if the file - already exists. On systems that support it, the addition of "e" when - reading or writing will set the flag to close the file on an execve() call. - - These functions, as well as gzip, will read and decode a sequence of gzip - streams in a file. The append function of gzopen() can be used to create - such a file. (Also see gzflush() for another way to do this.) When - appending, gzopen does not test whether the file begins with a gzip stream, - nor does it look for the end of the gzip streams to begin appending. gzopen - will simply append a gzip stream to the existing file. - - gzopen can be used to read a file which is not in gzip format; in this - case gzread will directly read from the file without decompression. When - reading, this will be detected automatically by looking for the magic two- - byte gzip header. - - gzopen returns NULL if the file could not be opened, if there was - insufficient memory to allocate the gzFile state, or if an invalid mode was - specified (an 'r', 'w', or 'a' was not provided, or '+' was provided). - errno can be checked to determine if the reason gzopen failed was that the - file could not be opened. -*/ - -ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); -/* - gzdopen associates a gzFile with the file descriptor fd. File descriptors - are obtained from calls like open, dup, creat, pipe or fileno (if the file - has been previously opened with fopen). The mode parameter is as in gzopen. - - The next call of gzclose on the returned gzFile will also close the file - descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor - fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd, - mode);. The duplicated descriptor should be saved to avoid a leak, since - gzdopen does not close fd if it fails. If you are using fileno() to get the - file descriptor from a FILE *, then you will have to use dup() to avoid - double-close()ing the file descriptor. Both gzclose() and fclose() will - close the associated file descriptor, so they need to have different file - descriptors. - - gzdopen returns NULL if there was insufficient memory to allocate the - gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not - provided, or '+' was provided), or if fd is -1. The file descriptor is not - used until the next gz* read, write, seek, or close operation, so gzdopen - will not detect if fd is invalid (unless fd is -1). -*/ - -ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); -/* - Set the internal buffer size used by this library's functions. The - default buffer size is 8192 bytes. This function must be called after - gzopen() or gzdopen(), and before any other calls that read or write the - file. The buffer memory allocation is always deferred to the first read or - write. Two buffers are allocated, either both of the specified size when - writing, or one of the specified size and the other twice that size when - reading. A larger buffer size of, for example, 64K or 128K bytes will - noticeably increase the speed of decompression (reading). - - The new buffer size also affects the maximum length for gzprintf(). - - gzbuffer() returns 0 on success, or -1 on failure, such as being called - too late. -*/ - -ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); -/* - Dynamically update the compression level or strategy. See the description - of deflateInit2 for the meaning of these parameters. - - gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not - opened for writing. -*/ - -ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); -/* - Reads the given number of uncompressed bytes from the compressed file. If - the input file is not in gzip format, gzread copies the given number of - bytes into the buffer directly from the file. - - After reaching the end of a gzip stream in the input, gzread will continue - to read, looking for another gzip stream. Any number of gzip streams may be - concatenated in the input file, and will all be decompressed by gzread(). - If something other than a gzip stream is encountered after a gzip stream, - that remaining trailing garbage is ignored (and no error is returned). - - gzread can be used to read a gzip file that is being concurrently written. - Upon reaching the end of the input, gzread will return with the available - data. If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then - gzclearerr can be used to clear the end of file indicator in order to permit - gzread to be tried again. Z_OK indicates that a gzip stream was completed - on the last gzread. Z_BUF_ERROR indicates that the input file ended in the - middle of a gzip stream. Note that gzread does not return -1 in the event - of an incomplete gzip stream. This error is deferred until gzclose(), which - will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip - stream. Alternatively, gzerror can be used before gzclose to detect this - case. - - gzread returns the number of uncompressed bytes actually read, less than - len for end of file, or -1 for error. -*/ - -ZEXTERN int ZEXPORT gzwrite OF((gzFile file, - voidpc buf, unsigned len)); -/* - Writes the given number of uncompressed bytes into the compressed file. - gzwrite returns the number of uncompressed bytes written or 0 in case of - error. -*/ - -ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...)); -/* - Converts, formats, and writes the arguments to the compressed file under - control of the format string, as in fprintf. gzprintf returns the number of - uncompressed bytes actually written, or 0 in case of error. The number of - uncompressed bytes written is limited to 8191, or one less than the buffer - size given to gzbuffer(). The caller should assure that this limit is not - exceeded. If it is exceeded, then gzprintf() will return an error (0) with - nothing written. In this case, there may also be a buffer overflow with - unpredictable consequences, which is possible only if zlib was compiled with - the insecure functions sprintf() or vsprintf() because the secure snprintf() - or vsnprintf() functions were not available. This can be determined using - zlibCompileFlags(). -*/ - -ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); -/* - Writes the given null-terminated string to the compressed file, excluding - the terminating null character. - - gzputs returns the number of characters written, or -1 in case of error. -*/ - -ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); -/* - Reads bytes from the compressed file until len-1 characters are read, or a - newline character is read and transferred to buf, or an end-of-file - condition is encountered. If any characters are read or if len == 1, the - string is terminated with a null character. If no characters are read due - to an end-of-file or len < 1, then the buffer is left untouched. - - gzgets returns buf which is a null-terminated string, or it returns NULL - for end-of-file or in case of error. If there was an error, the contents at - buf are indeterminate. -*/ - -ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); -/* - Writes c, converted to an unsigned char, into the compressed file. gzputc - returns the value that was written, or -1 in case of error. -*/ - -ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); -/* - Reads one byte from the compressed file. gzgetc returns this byte or -1 - in case of end of file or error. This is implemented as a macro for speed. - As such, it does not do all of the checking the other functions do. I.e. - it does not check to see if file is NULL, nor whether the structure file - points to has been clobbered or not. -*/ - -ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); -/* - Push one character back onto the stream to be read as the first character - on the next read. At least one character of push-back is allowed. - gzungetc() returns the character pushed, or -1 on failure. gzungetc() will - fail if c is -1, and may fail if a character has been pushed but not read - yet. If gzungetc is used immediately after gzopen or gzdopen, at least the - output buffer size of pushed characters is allowed. (See gzbuffer above.) - The pushed character will be discarded if the stream is repositioned with - gzseek() or gzrewind(). -*/ - -ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); -/* - Flushes all pending output into the compressed file. The parameter flush - is as in the deflate() function. The return value is the zlib error number - (see function gzerror below). gzflush is only permitted when writing. - - If the flush parameter is Z_FINISH, the remaining data is written and the - gzip stream is completed in the output. If gzwrite() is called again, a new - gzip stream will be started in the output. gzread() is able to read such - concatented gzip streams. - - gzflush should be called only when strictly necessary because it will - degrade compression if called too often. -*/ - -/* -ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, - z_off_t offset, int whence)); - - Sets the starting position for the next gzread or gzwrite on the given - compressed file. The offset represents a number of bytes in the - uncompressed data stream. The whence parameter is defined as in lseek(2); - the value SEEK_END is not supported. - - If the file is opened for reading, this function is emulated but can be - extremely slow. If the file is opened for writing, only forward seeks are - supported; gzseek then compresses a sequence of zeroes up to the new - starting position. - - gzseek returns the resulting offset location as measured in bytes from - the beginning of the uncompressed stream, or -1 in case of error, in - particular if the file is opened for writing and the new starting position - would be before the current position. -*/ - -ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); -/* - Rewinds the given file. This function is supported only for reading. - - gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) -*/ - -/* -ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); - - Returns the starting position for the next gzread or gzwrite on the given - compressed file. This position represents a number of bytes in the - uncompressed data stream, and is zero when starting, even if appending or - reading a gzip stream from the middle of a file using gzdopen(). - - gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) -*/ - -/* -ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); - - Returns the current offset in the file being read or written. This offset - includes the count of bytes that precede the gzip stream, for example when - appending or when using gzdopen() for reading. When reading, the offset - does not include as yet unused buffered input. This information can be used - for a progress indicator. On error, gzoffset() returns -1. -*/ - -ZEXTERN int ZEXPORT gzeof OF((gzFile file)); -/* - Returns true (1) if the end-of-file indicator has been set while reading, - false (0) otherwise. Note that the end-of-file indicator is set only if the - read tried to go past the end of the input, but came up short. Therefore, - just like feof(), gzeof() may return false even if there is no more data to - read, in the event that the last read request was for the exact number of - bytes remaining in the input file. This will happen if the input file size - is an exact multiple of the buffer size. - - If gzeof() returns true, then the read functions will return no more data, - unless the end-of-file indicator is reset by gzclearerr() and the input file - has grown since the previous end of file was detected. -*/ - -ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); -/* - Returns true (1) if file is being copied directly while reading, or false - (0) if file is a gzip stream being decompressed. - - If the input file is empty, gzdirect() will return true, since the input - does not contain a gzip stream. - - If gzdirect() is used immediately after gzopen() or gzdopen() it will - cause buffers to be allocated to allow reading the file to determine if it - is a gzip file. Therefore if gzbuffer() is used, it should be called before - gzdirect(). - - When writing, gzdirect() returns true (1) if transparent writing was - requested ("wT" for the gzopen() mode), or false (0) otherwise. (Note: - gzdirect() is not needed when writing. Transparent writing must be - explicitly requested, so the application already knows the answer. When - linking statically, using gzdirect() will include all of the zlib code for - gzip file reading and decompression, which may not be desired.) -*/ - -ZEXTERN int ZEXPORT gzclose OF((gzFile file)); -/* - Flushes all pending output if necessary, closes the compressed file and - deallocates the (de)compression state. Note that once file is closed, you - cannot call gzerror with file, since its structures have been deallocated. - gzclose must not be called more than once on the same file, just as free - must not be called more than once on the same allocation. - - gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a - file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the - last read ended in the middle of a gzip stream, or Z_OK on success. -*/ - -ZEXTERN int ZEXPORT gzclose_r OF((gzFile file)); -ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); -/* - Same as gzclose(), but gzclose_r() is only for use when reading, and - gzclose_w() is only for use when writing or appending. The advantage to - using these instead of gzclose() is that they avoid linking in zlib - compression or decompression code that is not used when only reading or only - writing respectively. If gzclose() is used, then both compression and - decompression code will be included the application when linking to a static - zlib library. -*/ - -ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); -/* - Returns the error message for the last error which occurred on the given - compressed file. errnum is set to zlib error number. If an error occurred - in the file system and not in the compression library, errnum is set to - Z_ERRNO and the application may consult errno to get the exact error code. - - The application must not modify the returned string. Future calls to - this function may invalidate the previously returned string. If file is - closed, then the string previously returned by gzerror will no longer be - available. - - gzerror() should be used to distinguish errors from end-of-file for those - functions above that do not distinguish those cases in their return values. -*/ - -ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); -/* - Clears the error and end-of-file flags for file. This is analogous to the - clearerr() function in stdio. This is useful for continuing to read a gzip - file that is being written concurrently. -*/ - -#endif /* !Z_SOLO */ - - /* checksum functions */ - -/* - These functions are not related to compression but are exported - anyway because they might be useful in applications using the compression - library. -*/ - -ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); -/* - Update a running Adler-32 checksum with the bytes buf[0..len-1] and - return the updated checksum. If buf is Z_NULL, this function returns the - required initial value for the checksum. - - An Adler-32 checksum is almost as reliable as a CRC32 but can be computed - much faster. - - Usage example: - - uLong adler = adler32(0L, Z_NULL, 0); - - while (read_buffer(buffer, length) != EOF) { - adler = adler32(adler, buffer, length); - } - if (adler != original_adler) error(); -*/ - -/* -ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, - z_off_t len2)); - - Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 - and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for - each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of - seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. Note - that the z_off_t type (like off_t) is a signed integer. If len2 is - negative, the result has no meaning or utility. -*/ - -ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); -/* - Update a running CRC-32 with the bytes buf[0..len-1] and return the - updated CRC-32. If buf is Z_NULL, this function returns the required - initial value for the crc. Pre- and post-conditioning (one's complement) is - performed within this function so it shouldn't be done by the application. - - Usage example: - - uLong crc = crc32(0L, Z_NULL, 0); - - while (read_buffer(buffer, length) != EOF) { - crc = crc32(crc, buffer, length); - } - if (crc != original_crc) error(); -*/ - -/* -ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); - - Combine two CRC-32 check values into one. For two sequences of bytes, - seq1 and seq2 with lengths len1 and len2, CRC-32 check values were - calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 - check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and - len2. -*/ - - - /* various hacks, don't look :) */ - -/* deflateInit and inflateInit are macros to allow checking the zlib version - * and the compiler's view of z_stream: - */ -ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, - int windowBits, int memLevel, - int strategy, const char *version, - int stream_size)); -ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, - unsigned char FAR *window, - const char *version, - int stream_size)); -#define deflateInit(strm, level) \ - deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) -#define inflateInit(strm) \ - inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream)) -#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ - deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ - (strategy), ZLIB_VERSION, (int)sizeof(z_stream)) -#define inflateInit2(strm, windowBits) \ - inflateInit2_((strm), (windowBits), ZLIB_VERSION, \ - (int)sizeof(z_stream)) -#define inflateBackInit(strm, windowBits, window) \ - inflateBackInit_((strm), (windowBits), (window), \ - ZLIB_VERSION, (int)sizeof(z_stream)) - -#ifndef Z_SOLO - -/* gzgetc() macro and its supporting function and exposed data structure. Note - * that the real internal state is much larger than the exposed structure. - * This abbreviated structure exposes just enough for the gzgetc() macro. The - * user should not mess with these exposed elements, since their names or - * behavior could change in the future, perhaps even capriciously. They can - * only be used by the gzgetc() macro. You have been warned. - */ -struct gzFile_s { - unsigned have; - unsigned char *next; - z_off64_t pos; -}; -ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ -#ifdef Z_PREFIX_SET -# undef z_gzgetc -# define z_gzgetc(g) \ - ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g)) -#else -# define gzgetc(g) \ - ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g)) -#endif - -/* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or - * change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if - * both are true, the application gets the *64 functions, and the regular - * functions are changed to 64 bits) -- in case these are set on systems - * without large file support, _LFS64_LARGEFILE must also be true - */ -#ifdef Z_LARGE64 - ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); - ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); - ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); - ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); - ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t)); - ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t)); -#endif - -#if !defined(ZLIB_INTERNAL) && defined(Z_WANT64) -# ifdef Z_PREFIX_SET -# define z_gzopen z_gzopen64 -# define z_gzseek z_gzseek64 -# define z_gztell z_gztell64 -# define z_gzoffset z_gzoffset64 -# define z_adler32_combine z_adler32_combine64 -# define z_crc32_combine z_crc32_combine64 -# else -# define gzopen gzopen64 -# define gzseek gzseek64 -# define gztell gztell64 -# define gzoffset gzoffset64 -# define adler32_combine adler32_combine64 -# define crc32_combine crc32_combine64 -# endif -# ifndef Z_LARGE64 - ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); - ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int)); - ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile)); - ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile)); - ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); -# endif -#else - ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); - ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int)); - ZEXTERN z_off_t ZEXPORT gztell OF((gzFile)); - ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile)); - ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); -#endif - -#else /* Z_SOLO */ - - ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); - -#endif /* !Z_SOLO */ - -/* hack for buggy compilers */ -#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL) - struct internal_state {int dummy;}; -#endif - -/* undocumented functions */ -ZEXTERN const char * ZEXPORT zError OF((int)); -ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp)); -ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void)); -ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int)); -ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp)); -ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp)); -#if defined(_WIN32) && !defined(Z_SOLO) -ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path, - const char *mode)); -#endif -#if defined(STDC) || defined(Z_HAVE_STDARG_H) -# ifndef Z_SOLO -ZEXTERN int ZEXPORTVA gzvprintf Z_ARG((gzFile file, - const char *format, - va_list va)); -# endif -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* ZLIB_H */ diff --git a/src/beast/test/zlib/zlib-1.2.8/zlib.map b/src/beast/test/zlib/zlib-1.2.8/zlib.map deleted file mode 100644 index 55c6647eb46..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/zlib.map +++ /dev/null @@ -1,83 +0,0 @@ -ZLIB_1.2.0 { - global: - compressBound; - deflateBound; - inflateBack; - inflateBackEnd; - inflateBackInit_; - inflateCopy; - local: - deflate_copyright; - inflate_copyright; - inflate_fast; - inflate_table; - zcalloc; - zcfree; - z_errmsg; - gz_error; - gz_intmax; - _*; -}; - -ZLIB_1.2.0.2 { - gzclearerr; - gzungetc; - zlibCompileFlags; -} ZLIB_1.2.0; - -ZLIB_1.2.0.8 { - deflatePrime; -} ZLIB_1.2.0.2; - -ZLIB_1.2.2 { - adler32_combine; - crc32_combine; - deflateSetHeader; - inflateGetHeader; -} ZLIB_1.2.0.8; - -ZLIB_1.2.2.3 { - deflateTune; - gzdirect; -} ZLIB_1.2.2; - -ZLIB_1.2.2.4 { - inflatePrime; -} ZLIB_1.2.2.3; - -ZLIB_1.2.3.3 { - adler32_combine64; - crc32_combine64; - gzopen64; - gzseek64; - gztell64; - inflateUndermine; -} ZLIB_1.2.2.4; - -ZLIB_1.2.3.4 { - inflateReset2; - inflateMark; -} ZLIB_1.2.3.3; - -ZLIB_1.2.3.5 { - gzbuffer; - gzoffset; - gzoffset64; - gzclose_r; - gzclose_w; -} ZLIB_1.2.3.4; - -ZLIB_1.2.5.1 { - deflatePending; -} ZLIB_1.2.3.5; - -ZLIB_1.2.5.2 { - deflateResetKeep; - gzgetc_; - inflateResetKeep; -} ZLIB_1.2.5.1; - -ZLIB_1.2.7.1 { - inflateGetDictionary; - gzvprintf; -} ZLIB_1.2.5.2; diff --git a/src/beast/test/zlib/zlib-1.2.8/zlib.pc.cmakein b/src/beast/test/zlib/zlib-1.2.8/zlib.pc.cmakein deleted file mode 100644 index a5e642938c6..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/zlib.pc.cmakein +++ /dev/null @@ -1,13 +0,0 @@ -prefix=@CMAKE_INSTALL_PREFIX@ -exec_prefix=@CMAKE_INSTALL_PREFIX@ -libdir=@INSTALL_LIB_DIR@ -sharedlibdir=@INSTALL_LIB_DIR@ -includedir=@INSTALL_INC_DIR@ - -Name: zlib -Description: zlib compression library -Version: @VERSION@ - -Requires: -Libs: -L${libdir} -L${sharedlibdir} -lz -Cflags: -I${includedir} diff --git a/src/beast/test/zlib/zlib-1.2.8/zlib.pc.in b/src/beast/test/zlib/zlib-1.2.8/zlib.pc.in deleted file mode 100644 index 7e5acf9c77e..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/zlib.pc.in +++ /dev/null @@ -1,13 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -sharedlibdir=@sharedlibdir@ -includedir=@includedir@ - -Name: zlib -Description: zlib compression library -Version: @VERSION@ - -Requires: -Libs: -L${libdir} -L${sharedlibdir} -lz -Cflags: -I${includedir} diff --git a/src/beast/test/zlib/zlib-1.2.8/zlib2ansi b/src/beast/test/zlib/zlib-1.2.8/zlib2ansi deleted file mode 100644 index 15e3e165f37..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/zlib2ansi +++ /dev/null @@ -1,152 +0,0 @@ -#!/usr/bin/perl - -# Transform K&R C function definitions into ANSI equivalent. -# -# Author: Paul Marquess -# Version: 1.0 -# Date: 3 October 2006 - -# TODO -# -# Asumes no function pointer parameters. unless they are typedefed. -# Assumes no literal strings that look like function definitions -# Assumes functions start at the beginning of a line - -use strict; -use warnings; - -local $/; -$_ = <>; - -my $sp = qr{ \s* (?: /\* .*? \*/ )? \s* }x; # assume no nested comments - -my $d1 = qr{ $sp (?: [\w\*\s]+ $sp)* $sp \w+ $sp [\[\]\s]* $sp }x ; -my $decl = qr{ $sp (?: \w+ $sp )+ $d1 }xo ; -my $dList = qr{ $sp $decl (?: $sp , $d1 )* $sp ; $sp }xo ; - - -while (s/^ - ( # Start $1 - ( # Start $2 - .*? # Minimal eat content - ( ^ \w [\w\s\*]+ ) # $3 -- function name - \s* # optional whitespace - ) # $2 - Matched up to before parameter list - - \( \s* # Literal "(" + optional whitespace - ( [^\)]+ ) # $4 - one or more anythings except ")" - \s* \) # optional whitespace surrounding a Literal ")" - - ( (?: $dList )+ ) # $5 - - $sp ^ { # literal "{" at start of line - ) # Remember to $1 - //xsom - ) -{ - my $all = $1 ; - my $prefix = $2; - my $param_list = $4 ; - my $params = $5; - - StripComments($params); - StripComments($param_list); - $param_list =~ s/^\s+//; - $param_list =~ s/\s+$//; - - my $i = 0 ; - my %pList = map { $_ => $i++ } - split /\s*,\s*/, $param_list; - my $pMatch = '(\b' . join('|', keys %pList) . '\b)\W*$' ; - - my @params = split /\s*;\s*/, $params; - my @outParams = (); - foreach my $p (@params) - { - if ($p =~ /,/) - { - my @bits = split /\s*,\s*/, $p; - my $first = shift @bits; - $first =~ s/^\s*//; - push @outParams, $first; - $first =~ /^(\w+\s*)/; - my $type = $1 ; - push @outParams, map { $type . $_ } @bits; - } - else - { - $p =~ s/^\s+//; - push @outParams, $p; - } - } - - - my %tmp = map { /$pMatch/; $_ => $pList{$1} } - @outParams ; - - @outParams = map { " $_" } - sort { $tmp{$a} <=> $tmp{$b} } - @outParams ; - - print $prefix ; - print "(\n" . join(",\n", @outParams) . ")\n"; - print "{" ; - -} - -# Output any trailing code. -print ; -exit 0; - - -sub StripComments -{ - - no warnings; - - # Strip C & C++ coments - # From the perlfaq - $_[0] =~ - - s{ - /\* ## Start of /* ... */ comment - [^*]*\*+ ## Non-* followed by 1-or-more *'s - ( - [^/*][^*]*\*+ - )* ## 0-or-more things which don't start with / - ## but do end with '*' - / ## End of /* ... */ comment - - | ## OR C++ Comment - // ## Start of C++ comment // - [^\n]* ## followed by 0-or-more non end of line characters - - | ## OR various things which aren't comments: - - ( - " ## Start of " ... " string - ( - \\. ## Escaped char - | ## OR - [^"\\] ## Non "\ - )* - " ## End of " ... " string - - | ## OR - - ' ## Start of ' ... ' string - ( - \\. ## Escaped char - | ## OR - [^'\\] ## Non '\ - )* - ' ## End of ' ... ' string - - | ## OR - - . ## Anything other char - [^/"'\\]* ## Chars which doesn't start a comment, string or escape - ) - }{$2}gxs; - -} diff --git a/src/beast/test/zlib/zlib-1.2.8/zutil.c b/src/beast/test/zlib/zlib-1.2.8/zutil.c deleted file mode 100644 index 23d2ebef008..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/zutil.c +++ /dev/null @@ -1,324 +0,0 @@ -/* zutil.c -- target dependent utility functions for the compression library - * Copyright (C) 1995-2005, 2010, 2011, 2012 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id$ */ - -#include "zutil.h" -#ifndef Z_SOLO -# include "gzguts.h" -#endif - -#ifndef NO_DUMMY_DECL -struct internal_state {int dummy;}; /* for buggy compilers */ -#endif - -z_const char * const z_errmsg[10] = { -"need dictionary", /* Z_NEED_DICT 2 */ -"stream end", /* Z_STREAM_END 1 */ -"", /* Z_OK 0 */ -"file error", /* Z_ERRNO (-1) */ -"stream error", /* Z_STREAM_ERROR (-2) */ -"data error", /* Z_DATA_ERROR (-3) */ -"insufficient memory", /* Z_MEM_ERROR (-4) */ -"buffer error", /* Z_BUF_ERROR (-5) */ -"incompatible version",/* Z_VERSION_ERROR (-6) */ -""}; - - -const char * ZEXPORT zlibVersion() -{ - return ZLIB_VERSION; -} - -uLong ZEXPORT zlibCompileFlags() -{ - uLong flags; - - flags = 0; - switch ((int)(sizeof(uInt))) { - case 2: break; - case 4: flags += 1; break; - case 8: flags += 2; break; - default: flags += 3; - } - switch ((int)(sizeof(uLong))) { - case 2: break; - case 4: flags += 1 << 2; break; - case 8: flags += 2 << 2; break; - default: flags += 3 << 2; - } - switch ((int)(sizeof(voidpf))) { - case 2: break; - case 4: flags += 1 << 4; break; - case 8: flags += 2 << 4; break; - default: flags += 3 << 4; - } - switch ((int)(sizeof(z_off_t))) { - case 2: break; - case 4: flags += 1 << 6; break; - case 8: flags += 2 << 6; break; - default: flags += 3 << 6; - } -#ifdef DEBUG - flags += 1 << 8; -#endif -#if defined(ASMV) || defined(ASMINF) - flags += 1 << 9; -#endif -#ifdef ZLIB_WINAPI - flags += 1 << 10; -#endif -#ifdef BUILDFIXED - flags += 1 << 12; -#endif -#ifdef DYNAMIC_CRC_TABLE - flags += 1 << 13; -#endif -#ifdef NO_GZCOMPRESS - flags += 1L << 16; -#endif -#ifdef NO_GZIP - flags += 1L << 17; -#endif -#ifdef PKZIP_BUG_WORKAROUND - flags += 1L << 20; -#endif -#ifdef FASTEST - flags += 1L << 21; -#endif -#if defined(STDC) || defined(Z_HAVE_STDARG_H) -# ifdef NO_vsnprintf - flags += 1L << 25; -# ifdef HAS_vsprintf_void - flags += 1L << 26; -# endif -# else -# ifdef HAS_vsnprintf_void - flags += 1L << 26; -# endif -# endif -#else - flags += 1L << 24; -# ifdef NO_snprintf - flags += 1L << 25; -# ifdef HAS_sprintf_void - flags += 1L << 26; -# endif -# else -# ifdef HAS_snprintf_void - flags += 1L << 26; -# endif -# endif -#endif - return flags; -} - -#ifdef DEBUG - -# ifndef verbose -# define verbose 0 -# endif -int ZLIB_INTERNAL z_verbose = verbose; - -void ZLIB_INTERNAL z_error (m) - char *m; -{ - fprintf(stderr, "%s\n", m); - exit(1); -} -#endif - -/* exported to allow conversion of error code to string for compress() and - * uncompress() - */ -const char * ZEXPORT zError(err) - int err; -{ - return ERR_MSG(err); -} - -#if defined(_WIN32_WCE) - /* The Microsoft C Run-Time Library for Windows CE doesn't have - * errno. We define it as a global variable to simplify porting. - * Its value is always 0 and should not be used. - */ - int errno = 0; -#endif - -#ifndef HAVE_MEMCPY - -void ZLIB_INTERNAL zmemcpy(dest, source, len) - Bytef* dest; - const Bytef* source; - uInt len; -{ - if (len == 0) return; - do { - *dest++ = *source++; /* ??? to be unrolled */ - } while (--len != 0); -} - -int ZLIB_INTERNAL zmemcmp(s1, s2, len) - const Bytef* s1; - const Bytef* s2; - uInt len; -{ - uInt j; - - for (j = 0; j < len; j++) { - if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; - } - return 0; -} - -void ZLIB_INTERNAL zmemzero(dest, len) - Bytef* dest; - uInt len; -{ - if (len == 0) return; - do { - *dest++ = 0; /* ??? to be unrolled */ - } while (--len != 0); -} -#endif - -#ifndef Z_SOLO - -#ifdef SYS16BIT - -#ifdef __TURBOC__ -/* Turbo C in 16-bit mode */ - -# define MY_ZCALLOC - -/* Turbo C malloc() does not allow dynamic allocation of 64K bytes - * and farmalloc(64K) returns a pointer with an offset of 8, so we - * must fix the pointer. Warning: the pointer must be put back to its - * original form in order to free it, use zcfree(). - */ - -#define MAX_PTR 10 -/* 10*64K = 640K */ - -local int next_ptr = 0; - -typedef struct ptr_table_s { - voidpf org_ptr; - voidpf new_ptr; -} ptr_table; - -local ptr_table table[MAX_PTR]; -/* This table is used to remember the original form of pointers - * to large buffers (64K). Such pointers are normalized with a zero offset. - * Since MSDOS is not a preemptive multitasking OS, this table is not - * protected from concurrent access. This hack doesn't work anyway on - * a protected system like OS/2. Use Microsoft C instead. - */ - -voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size) -{ - voidpf buf = opaque; /* just to make some compilers happy */ - ulg bsize = (ulg)items*size; - - /* If we allocate less than 65520 bytes, we assume that farmalloc - * will return a usable pointer which doesn't have to be normalized. - */ - if (bsize < 65520L) { - buf = farmalloc(bsize); - if (*(ush*)&buf != 0) return buf; - } else { - buf = farmalloc(bsize + 16L); - } - if (buf == NULL || next_ptr >= MAX_PTR) return NULL; - table[next_ptr].org_ptr = buf; - - /* Normalize the pointer to seg:0 */ - *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; - *(ush*)&buf = 0; - table[next_ptr++].new_ptr = buf; - return buf; -} - -void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) -{ - int n; - if (*(ush*)&ptr != 0) { /* object < 64K */ - farfree(ptr); - return; - } - /* Find the original pointer */ - for (n = 0; n < next_ptr; n++) { - if (ptr != table[n].new_ptr) continue; - - farfree(table[n].org_ptr); - while (++n < next_ptr) { - table[n-1] = table[n]; - } - next_ptr--; - return; - } - ptr = opaque; /* just to make some compilers happy */ - Assert(0, "zcfree: ptr not found"); -} - -#endif /* __TURBOC__ */ - - -#ifdef M_I86 -/* Microsoft C in 16-bit mode */ - -# define MY_ZCALLOC - -#if (!defined(_MSC_VER) || (_MSC_VER <= 600)) -# define _halloc halloc -# define _hfree hfree -#endif - -voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size) -{ - if (opaque) opaque = 0; /* to make compiler happy */ - return _halloc((long)items, size); -} - -void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) -{ - if (opaque) opaque = 0; /* to make compiler happy */ - _hfree(ptr); -} - -#endif /* M_I86 */ - -#endif /* SYS16BIT */ - - -#ifndef MY_ZCALLOC /* Any system without a special alloc function */ - -#ifndef STDC -extern voidp malloc OF((uInt size)); -extern voidp calloc OF((uInt items, uInt size)); -extern void free OF((voidpf ptr)); -#endif - -voidpf ZLIB_INTERNAL zcalloc (opaque, items, size) - voidpf opaque; - unsigned items; - unsigned size; -{ - if (opaque) items += size - size; /* make compiler happy */ - return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : - (voidpf)calloc(items, size); -} - -void ZLIB_INTERNAL zcfree (opaque, ptr) - voidpf opaque; - voidpf ptr; -{ - free(ptr); - if (opaque) return; /* make compiler happy */ -} - -#endif /* MY_ZCALLOC */ - -#endif /* !Z_SOLO */ diff --git a/src/beast/test/zlib/zlib-1.2.8/zutil.h b/src/beast/test/zlib/zlib-1.2.8/zutil.h deleted file mode 100644 index 24ab06b1cf6..00000000000 --- a/src/beast/test/zlib/zlib-1.2.8/zutil.h +++ /dev/null @@ -1,253 +0,0 @@ -/* zutil.h -- internal interface and configuration of the compression library - * Copyright (C) 1995-2013 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -/* @(#) $Id$ */ - -#ifndef ZUTIL_H -#define ZUTIL_H - -#ifdef HAVE_HIDDEN -# define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) -#else -# define ZLIB_INTERNAL -#endif - -#include "zlib.h" - -#if defined(STDC) && !defined(Z_SOLO) -# if !(defined(_WIN32_WCE) && defined(_MSC_VER)) -# include -# endif -# include -# include -#endif - -#ifdef Z_SOLO - typedef long ptrdiff_t; /* guess -- will be caught if guess is wrong */ -#endif - -#ifndef local -# define local static -#endif -/* compile with -Dlocal if your debugger can't find static symbols */ - -typedef unsigned char uch; -typedef uch FAR uchf; -typedef unsigned short ush; -typedef ush FAR ushf; -typedef unsigned long ulg; - -extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ -/* (size given to avoid silly warnings with Visual C++) */ - -#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] - -#define ERR_RETURN(strm,err) \ - return (strm->msg = ERR_MSG(err), (err)) -/* To be used only when the state is known to be valid */ - - /* common constants */ - -#ifndef DEF_WBITS -# define DEF_WBITS MAX_WBITS -#endif -/* default windowBits for decompression. MAX_WBITS is for compression only */ - -#if MAX_MEM_LEVEL >= 8 -# define DEF_MEM_LEVEL 8 -#else -# define DEF_MEM_LEVEL MAX_MEM_LEVEL -#endif -/* default memLevel */ - -#define STORED_BLOCK 0 -#define STATIC_TREES 1 -#define DYN_TREES 2 -/* The three kinds of block type */ - -#define MIN_MATCH 3 -#define MAX_MATCH 258 -/* The minimum and maximum match lengths */ - -#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ - - /* target dependencies */ - -#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) -# define OS_CODE 0x00 -# ifndef Z_SOLO -# if defined(__TURBOC__) || defined(__BORLANDC__) -# if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) - /* Allow compilation with ANSI keywords only enabled */ - void _Cdecl farfree( void *block ); - void *_Cdecl farmalloc( unsigned long nbytes ); -# else -# include -# endif -# else /* MSC or DJGPP */ -# include -# endif -# endif -#endif - -#ifdef AMIGA -# define OS_CODE 0x01 -#endif - -#if defined(VAXC) || defined(VMS) -# define OS_CODE 0x02 -# define F_OPEN(name, mode) \ - fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") -#endif - -#if defined(ATARI) || defined(atarist) -# define OS_CODE 0x05 -#endif - -#ifdef OS2 -# define OS_CODE 0x06 -# if defined(M_I86) && !defined(Z_SOLO) -# include -# endif -#endif - -#if defined(MACOS) || defined(TARGET_OS_MAC) -# define OS_CODE 0x07 -# ifndef Z_SOLO -# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os -# include /* for fdopen */ -# else -# ifndef fdopen -# define fdopen(fd,mode) NULL /* No fdopen() */ -# endif -# endif -# endif -#endif - -#ifdef TOPS20 -# define OS_CODE 0x0a -#endif - -#ifdef WIN32 -# ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ -# define OS_CODE 0x0b -# endif -#endif - -#ifdef __50SERIES /* Prime/PRIMOS */ -# define OS_CODE 0x0f -#endif - -#if defined(_BEOS_) || defined(RISCOS) -# define fdopen(fd,mode) NULL /* No fdopen() */ -#endif - -#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX -# if defined(_WIN32_WCE) -# define fdopen(fd,mode) NULL /* No fdopen() */ -# ifndef _PTRDIFF_T_DEFINED - typedef int ptrdiff_t; -# define _PTRDIFF_T_DEFINED -# endif -# else -# define fdopen(fd,type) _fdopen(fd,type) -# endif -#endif - -#if defined(__BORLANDC__) && !defined(MSDOS) - #pragma warn -8004 - #pragma warn -8008 - #pragma warn -8066 -#endif - -/* provide prototypes for these when building zlib without LFS */ -#if !defined(_WIN32) && \ - (!defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0) - ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); -#endif - - /* common defaults */ - -#ifndef OS_CODE -# define OS_CODE 0x03 /* assume Unix */ -#endif - -#ifndef F_OPEN -# define F_OPEN(name, mode) fopen((name), (mode)) -#endif - - /* functions */ - -#if defined(pyr) || defined(Z_SOLO) -# define NO_MEMCPY -#endif -#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) - /* Use our own functions for small and medium model with MSC <= 5.0. - * You may have to use the same strategy for Borland C (untested). - * The __SC__ check is for Symantec. - */ -# define NO_MEMCPY -#endif -#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) -# define HAVE_MEMCPY -#endif -#ifdef HAVE_MEMCPY -# ifdef SMALL_MEDIUM /* MSDOS small or medium model */ -# define zmemcpy _fmemcpy -# define zmemcmp _fmemcmp -# define zmemzero(dest, len) _fmemset(dest, 0, len) -# else -# define zmemcpy memcpy -# define zmemcmp memcmp -# define zmemzero(dest, len) memset(dest, 0, len) -# endif -#else - void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); - int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); - void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len)); -#endif - -/* Diagnostic functions */ -#ifdef DEBUG -# include - extern int ZLIB_INTERNAL z_verbose; - extern void ZLIB_INTERNAL z_error OF((char *m)); -# define Assert(cond,msg) {if(!(cond)) z_error(msg);} -# define Trace(x) {if (z_verbose>=0) fprintf x ;} -# define Tracev(x) {if (z_verbose>0) fprintf x ;} -# define Tracevv(x) {if (z_verbose>1) fprintf x ;} -# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} -# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} -#else -# define Assert(cond,msg) -# define Trace(x) -# define Tracev(x) -# define Tracevv(x) -# define Tracec(c,x) -# define Tracecv(c,x) -#endif - -#ifndef Z_SOLO - voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items, - unsigned size)); - void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr)); -#endif - -#define ZALLOC(strm, items, size) \ - (*((strm)->zalloc))((strm)->opaque, (items), (size)) -#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) -#define TRY_FREE(s, p) {if (p) ZFREE(s, p);} - -/* Reverse the bytes in a 32-bit value */ -#define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \ - (((q) & 0xff00) << 8) + (((q) & 0xff) << 24)) - -#endif /* ZUTIL_H */ diff --git a/src/beast/test/zlib/ztest.hpp b/src/beast/test/zlib/ztest.hpp deleted file mode 100644 index e07347eeae9..00000000000 --- a/src/beast/test/zlib/ztest.hpp +++ /dev/null @@ -1,167 +0,0 @@ -// -// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// 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) -// - -#ifndef BEAST_ZTEST_HPP -#define BEAST_ZTEST_HPP - -#include "zlib-1.2.8/zlib.h" -#include -#include -#include - -class z_deflator -{ - int level_ = Z_DEFAULT_COMPRESSION; - int windowBits_ = 15; - int memLevel_ = 4; - int strategy_ = Z_DEFAULT_STRATEGY; - -public: - // -1 = default - // 0 = none - // 1..9 = faster<-->better - void - level(int n) - { - level_ = n; - } - - void - windowBits(int n) - { - windowBits_ = n; - } - - void - memLevel(int n) - { - memLevel_ = n; - } - - void - strategy(int n) - { - strategy_ = n; - } - - std::string - operator()(std::string const& in) - { - int result; - z_stream zs; - memset(&zs, 0, sizeof(zs)); - result = deflateInit2( - &zs, - level_, - Z_DEFLATED, - -windowBits_, - memLevel_, - strategy_ - ); - if(result != Z_OK) - throw std::logic_error("deflateInit2 failed"); - std::string out; - out.resize(deflateBound(&zs, - static_cast(in.size()))); - zs.next_in = (Bytef*)in.data(); - zs.avail_in = static_cast(in.size()); - zs.next_out = (Bytef*)&out[0]; - zs.avail_out = static_cast(out.size()); - result = deflate(&zs, Z_FULL_FLUSH); - if(result != Z_OK) - throw std::logic_error("deflate failed"); - out.resize(zs.total_out); - deflateEnd(&zs); - return out; - } -}; - -class z_inflator -{ -public: - std::string - operator()(std::string const& in) - { - int result; - std::string out; - z_stream zs; - memset(&zs, 0, sizeof(zs)); - result = inflateInit2(&zs, -15); - try - { - zs.next_in = (Bytef*)in.data(); - zs.avail_in = static_cast(in.size()); - for(;;) - { - out.resize(zs.total_out + 1024); - zs.next_out = (Bytef*)&out[zs.total_out]; - zs.avail_out = static_cast( - out.size() - zs.total_out); - result = inflate(&zs, Z_SYNC_FLUSH); - if( result == Z_NEED_DICT || - result == Z_DATA_ERROR || - result == Z_MEM_ERROR) - { - throw std::logic_error("inflate failed"); - } - if(zs.avail_out > 0) - break; - if(result == Z_STREAM_END) - break; - } - out.resize(zs.total_out); - inflateEnd(&zs); - } - catch(...) - { - inflateEnd(&zs); - throw; - } - return out; - } -}; - -// Lots of repeats, limited char range -inline -std::string -corpus1(std::size_t n) -{ - static std::string const alphabet{ - "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" - }; - std::string s; - s.reserve(n + 5); - std::mt19937 g; - std::uniform_int_distribution d0{ - 0, alphabet.size() - 1}; - std::uniform_int_distribution d1{ - 1, 5}; - while(s.size() < n) - { - auto const rep = d1(g); - auto const ch = alphabet[d0(g)]; - s.insert(s.end(), rep, ch); - } - s.resize(n); - return s; -} - -// Random data -inline -std::string -corpus2(std::size_t n) -{ - std::string s; - s.reserve(n); - std::mt19937 g; - std::uniform_int_distribution d0{0, 255}; - while(n--) - s.push_back(static_cast(d0(g))); - return s; -} - -#endif diff --git a/src/ripple/app/main/Application.cpp b/src/ripple/app/main/Application.cpp index 152498debbe..998edcbac93 100644 --- a/src/ripple/app/main/Application.cpp +++ b/src/ripple/app/main/Application.cpp @@ -1686,7 +1686,7 @@ bool ApplicationImp::loadOldLedger ( } } } - else if (ledgerID.empty () || beast::detail::iequals(ledgerID, "latest")) + else if (ledgerID.empty () || boost::beast::detail::iequals(ledgerID, "latest")) { loadLedger = getLastFullLedger (); } diff --git a/src/ripple/app/main/Application.h b/src/ripple/app/main/Application.h index af7c0032d6e..032ae781b3b 100644 --- a/src/ripple/app/main/Application.h +++ b/src/ripple/app/main/Application.h @@ -26,11 +26,10 @@ #include #include #include +#include #include #include -namespace boost { namespace asio { class io_service; } } - namespace ripple { namespace unl { class Manager; } diff --git a/src/ripple/app/misc/NetworkOPs.cpp b/src/ripple/app/misc/NetworkOPs.cpp index 16223bcb2a3..fba0c3b5f68 100644 --- a/src/ripple/app/misc/NetworkOPs.cpp +++ b/src/ripple/app/misc/NetworkOPs.cpp @@ -56,7 +56,7 @@ #include #include #include -#include +#include #include namespace ripple { diff --git a/src/ripple/app/misc/NetworkOPs.h b/src/ripple/app/misc/NetworkOPs.h index dd86629937c..e08ccbe768a 100644 --- a/src/ripple/app/misc/NetworkOPs.h +++ b/src/ripple/app/misc/NetworkOPs.h @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include diff --git a/src/ripple/app/misc/detail/Work.h b/src/ripple/app/misc/detail/Work.h index b3be25c18db..f4f4b556b9c 100644 --- a/src/ripple/app/misc/detail/Work.h +++ b/src/ripple/app/misc/detail/Work.h @@ -20,15 +20,15 @@ #ifndef RIPPLE_APP_MISC_DETAIL_WORK_H_INCLUDED #define RIPPLE_APP_MISC_DETAIL_WORK_H_INCLUDED -#include -#include +#include +#include namespace ripple { namespace detail { using response_type = - beast::http::response; + boost::beast::http::response; class Work { diff --git a/src/ripple/app/misc/detail/WorkBase.h b/src/ripple/app/misc/detail/WorkBase.h index 1c59ab664e0..4ab2f49bfa1 100644 --- a/src/ripple/app/misc/detail/WorkBase.h +++ b/src/ripple/app/misc/detail/WorkBase.h @@ -22,10 +22,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include namespace ripple { @@ -48,7 +48,7 @@ class WorkBase using resolver_type = boost::asio::ip::tcp::resolver; using query_type = resolver_type::query; using request_type = - beast::http::request; + boost::beast::http::request; std::string host_; std::string path_; @@ -60,7 +60,7 @@ class WorkBase socket_type socket_; request_type req_; response_type res_; - beast::multi_buffer read_buf_; + boost::beast::multi_buffer read_buf_; public: WorkBase( @@ -177,14 +177,14 @@ template void WorkBase::onStart() { - req_.method(beast::http::verb::get); + req_.method(boost::beast::http::verb::get); req_.target(path_.empty() ? "/" : path_); - req_.version = 11; + req_.version(11); req_.set ( "Host", host_ + ":" + port_); req_.set ("User-Agent", BuildInfo::getFullVersionString()); req_.prepare_payload(); - beast::http::async_write(impl().stream(), req_, + boost::beast::http::async_write(impl().stream(), req_, strand_.wrap (std::bind (&WorkBase::onRequest, impl().shared_from_this(), std::placeholders::_1))); } @@ -196,7 +196,7 @@ WorkBase::onRequest(error_code const& ec) if (ec) return fail(ec); - beast::http::async_read (impl().stream(), read_buf_, res_, + boost::beast::http::async_read (impl().stream(), read_buf_, res_, strand_.wrap (std::bind (&WorkBase::onResponse, impl().shared_from_this(), std::placeholders::_1))); } diff --git a/src/ripple/app/misc/impl/Manifest.cpp b/src/ripple/app/misc/impl/Manifest.cpp index 4ef6109ee40..532df5b0424 100644 --- a/src/ripple/app/misc/impl/Manifest.cpp +++ b/src/ripple/app/misc/impl/Manifest.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include @@ -184,7 +184,7 @@ ValidatorToken::make_ValidatorToken(std::vector const& tokenBlob) for (auto const& line : tokenBlob) tokenStr += beast::rfc2616::trim(line); - tokenStr = beast::detail::base64_decode(tokenStr); + tokenStr = boost::beast::detail::base64_decode(tokenStr); Json::Reader r; Json::Value token; @@ -386,7 +386,7 @@ ManifestCache::load ( if (! configManifest.empty()) { auto mo = Manifest::make_Manifest ( - beast::detail::base64_decode(configManifest)); + boost::beast::detail::base64_decode(configManifest)); if (! mo) { JLOG (j_.error()) << "Malformed validator_token in config"; @@ -421,7 +421,7 @@ ManifestCache::load ( revocationStr += beast::rfc2616::trim(line); auto mo = Manifest::make_Manifest ( - beast::detail::base64_decode(revocationStr)); + boost::beast::detail::base64_decode(revocationStr)); if (! mo || ! mo->revoked() || applyManifest (std::move(*mo)) == ManifestDisposition::invalid) diff --git a/src/ripple/app/misc/impl/ValidatorKeys.cpp b/src/ripple/app/misc/impl/ValidatorKeys.cpp index 599d83c567b..cc5d636e4c2 100644 --- a/src/ripple/app/misc/impl/ValidatorKeys.cpp +++ b/src/ripple/app/misc/impl/ValidatorKeys.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include namespace ripple { ValidatorKeys::ValidatorKeys(Config const& config, beast::Journal j) @@ -46,7 +46,7 @@ ValidatorKeys::ValidatorKeys(Config const& config, beast::Journal j) auto const pk = derivePublicKey( KeyType::secp256k1, token->validationSecret); auto const m = Manifest::make_Manifest( - beast::detail::base64_decode(token->manifest)); + boost::beast::detail::base64_decode(token->manifest)); if (! m || pk != m->signingKey) { diff --git a/src/ripple/app/misc/impl/ValidatorList.cpp b/src/ripple/app/misc/impl/ValidatorList.cpp index 12bbab8ebe4..066dcf148bb 100644 --- a/src/ripple/app/misc/impl/ValidatorList.cpp +++ b/src/ripple/app/misc/impl/ValidatorList.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include namespace ripple { @@ -291,7 +291,7 @@ ValidatorList::applyList ( for (auto const& valManifest : manifests) { auto m = Manifest::make_Manifest ( - beast::detail::base64_decode(valManifest)); + boost::beast::detail::base64_decode(valManifest)); if (! m || ! keyListings_.count (m->masterKey)) { @@ -321,7 +321,7 @@ ValidatorList::verify ( std::string const& blob, std::string const& signature) { - auto m = Manifest::make_Manifest (beast::detail::base64_decode(manifest)); + auto m = Manifest::make_Manifest (boost::beast::detail::base64_decode(manifest)); if (! m || ! publisherLists_.count (m->masterKey)) return ListDisposition::untrusted; @@ -342,7 +342,7 @@ ValidatorList::verify ( return ListDisposition::untrusted; auto const sig = strUnHex(signature); - auto const data = beast::detail::base64_decode (blob); + auto const data = boost::beast::detail::base64_decode (blob); if (! sig.second || ! ripple::verify ( publisherManifests_.getSigningKey(pubKey), diff --git a/src/ripple/app/misc/impl/ValidatorSite.cpp b/src/ripple/app/misc/impl/ValidatorSite.cpp index 58052ef8408..01a6695bc8f 100644 --- a/src/ripple/app/misc/impl/ValidatorSite.cpp +++ b/src/ripple/app/misc/impl/ValidatorSite.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include namespace ripple { @@ -207,7 +207,7 @@ ValidatorSite::onSiteFetch( detail::response_type&& res, std::size_t siteIdx) { - if (! ec && res.result() != beast::http::status::ok) + if (! ec && res.result() != boost::beast::http::status::ok) { std::lock_guard lock{sites_mutex_}; JLOG (j_.warn()) << @@ -222,7 +222,7 @@ ValidatorSite::onSiteFetch( std::lock_guard lock{sites_mutex_}; Json::Reader r; Json::Value body; - if (r.parse(res.body.data(), body) && + if (r.parse(res.body().data(), body) && body.isObject () && body.isMember("blob") && body["blob"].isString () && body.isMember("manifest") && body["manifest"].isString () && diff --git a/src/ripple/basics/BasicConfig.h b/src/ripple/basics/BasicConfig.h index 75c987b991d..008611d2411 100644 --- a/src/ripple/basics/BasicConfig.h +++ b/src/ripple/basics/BasicConfig.h @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include #include @@ -41,7 +41,7 @@ using IniFileSections = std::map>; */ class Section : public beast::unit_test::detail::const_container < - std::map > + std::map > { private: std::string name_; @@ -173,7 +173,7 @@ class Section class BasicConfig { private: - std::map map_; + std::map map_; public: /** Returns `true` if a section with the given name exists. */ diff --git a/src/ripple/basics/Log.h b/src/ripple/basics/Log.h index 10debfa5de1..0ca8a618099 100644 --- a/src/ripple/basics/Log.h +++ b/src/ripple/basics/Log.h @@ -21,7 +21,7 @@ #define RIPPLE_BASICS_LOG_H_INCLUDED #include -#include +#include #include #include #include @@ -148,7 +148,7 @@ class Logs std::mutex mutable mutex_; std::map , - beast::iless> sinks_; + boost::beast::iless> sinks_; beast::severities::Severity thresh_; File file_; bool silent_ = false; diff --git a/src/ripple/basics/random.h b/src/ripple/basics/random.h index b4388fd588a..dfb379e6c81 100644 --- a/src/ripple/basics/random.h +++ b/src/ripple/basics/random.h @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include #include @@ -52,7 +52,7 @@ namespace detail { // Determines if a type can be called like an Engine template using is_engine = - beast::detail::is_invocable; + boost::beast::detail::is_invocable; } /** Return the default random engine. diff --git a/src/ripple/beast/container/detail/aged_ordered_container.h b/src/ripple/beast/container/detail/aged_ordered_container.h index 08149e61e99..730c86137d2 100644 --- a/src/ripple/beast/container/detail/aged_ordered_container.h +++ b/src/ripple/beast/container/detail/aged_ordered_container.h @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include @@ -163,7 +163,7 @@ class aged_ordered_container // VFALCO TODO This should only be enabled for maps. class pair_value_compare - : private empty_base_optimization + : public boost::beast::detail::empty_base_optimization , public std::binary_function { public: @@ -177,7 +177,7 @@ class aged_ordered_container } pair_value_compare (pair_value_compare const& other) - : empty_base_optimization (other) + : boost::beast::detail::empty_base_optimization (other) { } @@ -185,7 +185,7 @@ class aged_ordered_container friend aged_ordered_container; pair_value_compare (Compare const& compare) - : empty_base_optimization (compare) + : boost::beast::detail::empty_base_optimization (compare) { } }; @@ -193,14 +193,14 @@ class aged_ordered_container // Compares value_type against element, used in insert_check // VFALCO TODO hoist to remove template argument dependencies class KeyValueCompare - : private empty_base_optimization + : public boost::beast::detail::empty_base_optimization , public std::binary_function { public: KeyValueCompare () = default; KeyValueCompare (Compare const& compare) - : empty_base_optimization (compare) + : boost::beast::detail::empty_base_optimization (compare) { } @@ -237,12 +237,12 @@ class aged_ordered_container Compare& compare() { - return empty_base_optimization ::member(); + return boost::beast::detail::empty_base_optimization ::member(); } Compare const& compare() const { - return empty_base_optimization ::member(); + return boost::beast::detail::empty_base_optimization ::member(); } }; @@ -268,7 +268,7 @@ class aged_ordered_container class config_t : private KeyValueCompare - , private empty_base_optimization + , public boost::beast::detail::empty_base_optimization { public: explicit config_t ( @@ -288,7 +288,7 @@ class aged_ordered_container config_t ( clock_type& clock_, Allocator const& alloc_) - : empty_base_optimization (alloc_) + : boost::beast::detail::empty_base_optimization (alloc_) , clock (clock_) { } @@ -298,14 +298,14 @@ class aged_ordered_container Compare const& comp, Allocator const& alloc_) : KeyValueCompare (comp) - , empty_base_optimization (alloc_) + , boost::beast::detail::empty_base_optimization (alloc_) , clock (clock_) { } config_t (config_t const& other) : KeyValueCompare (other.key_compare()) - , empty_base_optimization ( + , boost::beast::detail::empty_base_optimization ( ElementAllocatorTraits:: select_on_container_copy_construction ( other.alloc())) @@ -315,14 +315,14 @@ class aged_ordered_container config_t (config_t const& other, Allocator const& alloc) : KeyValueCompare (other.key_compare()) - , empty_base_optimization (alloc) + , boost::beast::detail::empty_base_optimization (alloc) , clock (other.clock) { } config_t (config_t&& other) : KeyValueCompare (std::move (other.key_compare())) - , empty_base_optimization ( + , boost::beast::detail::empty_base_optimization ( std::move (other)) , clock (other.clock) { @@ -330,7 +330,7 @@ class aged_ordered_container config_t (config_t&& other, Allocator const& alloc) : KeyValueCompare (std::move (other.key_compare())) - , empty_base_optimization (alloc) + , boost::beast::detail::empty_base_optimization (alloc) , clock (other.clock) { } @@ -376,13 +376,13 @@ class aged_ordered_container ElementAllocator& alloc() { - return empty_base_optimization < + return boost::beast::detail::empty_base_optimization < ElementAllocator>::member(); } ElementAllocator const& alloc() const { - return empty_base_optimization < + return boost::beast::detail::empty_base_optimization < ElementAllocator>::member(); } diff --git a/src/ripple/beast/container/detail/aged_unordered_container.h b/src/ripple/beast/container/detail/aged_unordered_container.h index 91d40461704..33547ce4b91 100644 --- a/src/ripple/beast/container/detail/aged_unordered_container.h +++ b/src/ripple/beast/container/detail/aged_unordered_container.h @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include @@ -161,7 +161,7 @@ class aged_unordered_container // VFALCO TODO hoist to remove template argument dependencies class ValueHash - : private empty_base_optimization + : private boost::beast::detail::empty_base_optimization , public std::unary_function { public: @@ -170,7 +170,7 @@ class aged_unordered_container } ValueHash (Hash const& hash) - : empty_base_optimization (hash) + : boost::beast::detail::empty_base_optimization (hash) { } @@ -193,7 +193,7 @@ class aged_unordered_container // Compares value_type against element, used in find/insert_check // VFALCO TODO hoist to remove template argument dependencies class KeyValueEqual - : private empty_base_optimization + : private boost::beast::detail::empty_base_optimization , public std::binary_function { public: @@ -202,7 +202,7 @@ class aged_unordered_container } KeyValueEqual (KeyEqual const& keyEqual) - : empty_base_optimization (keyEqual) + : boost::beast::detail::empty_base_optimization (keyEqual) { } @@ -283,7 +283,7 @@ class aged_unordered_container class config_t : private ValueHash , private KeyValueEqual - , private empty_base_optimization + , private boost::beast::detail::empty_base_optimization { public: explicit config_t ( @@ -311,7 +311,7 @@ class aged_unordered_container config_t ( clock_type& clock_, Allocator const& alloc_) - : empty_base_optimization (alloc_) + : boost::beast::detail::empty_base_optimization (alloc_) , clock (clock_) { } @@ -331,7 +331,7 @@ class aged_unordered_container Hash const& hash, Allocator const& alloc_) : ValueHash (hash) - , empty_base_optimization (alloc_) + , boost::beast::detail::empty_base_optimization (alloc_) , clock (clock_) { } @@ -341,7 +341,7 @@ class aged_unordered_container KeyEqual const& keyEqual, Allocator const& alloc_) : KeyValueEqual (keyEqual) - , empty_base_optimization (alloc_) + , boost::beast::detail::empty_base_optimization (alloc_) , clock (clock_) { } @@ -353,7 +353,7 @@ class aged_unordered_container Allocator const& alloc_) : ValueHash (hash) , KeyValueEqual (keyEqual) - , empty_base_optimization (alloc_) + , boost::beast::detail::empty_base_optimization (alloc_) , clock (clock_) { } @@ -361,7 +361,7 @@ class aged_unordered_container config_t (config_t const& other) : ValueHash (other.hash_function()) , KeyValueEqual (other.key_eq()) - , empty_base_optimization ( + , boost::beast::detail::empty_base_optimization ( ElementAllocatorTraits:: select_on_container_copy_construction ( other.alloc())) @@ -372,7 +372,7 @@ class aged_unordered_container config_t (config_t const& other, Allocator const& alloc) : ValueHash (other.hash_function()) , KeyValueEqual (other.key_eq()) - , empty_base_optimization (alloc) + , boost::beast::detail::empty_base_optimization (alloc) , clock (other.clock) { } @@ -380,7 +380,7 @@ class aged_unordered_container config_t (config_t&& other) : ValueHash (std::move (other.hash_function())) , KeyValueEqual (std::move (other.key_eq())) - , empty_base_optimization ( + , boost::beast::detail::empty_base_optimization ( std::move (other.alloc())) , clock (other.clock) { @@ -389,7 +389,7 @@ class aged_unordered_container config_t (config_t&& other, Allocator const& alloc) : ValueHash (std::move (other.hash_function())) , KeyValueEqual (std::move (other.key_eq())) - , empty_base_optimization (alloc) + , boost::beast::detail::empty_base_optimization (alloc) , clock (other.clock) { } @@ -454,13 +454,13 @@ class aged_unordered_container ElementAllocator& alloc() { - return empty_base_optimization < + return boost::beast::detail::empty_base_optimization < ElementAllocator>::member(); } ElementAllocator const& alloc() const { - return empty_base_optimization < + return boost::beast::detail::empty_base_optimization < ElementAllocator>::member(); } diff --git a/src/ripple/beast/net/IPAddress.h b/src/ripple/beast/net/IPAddress.h index a2de956f4b4..34f5dfe8784 100644 --- a/src/ripple/beast/net/IPAddress.h +++ b/src/ripple/beast/net/IPAddress.h @@ -345,12 +345,12 @@ struct hash namespace boost { template <> -struct hash +struct hash <::beast::IP::Address> { std::size_t - operator() (beast::IP::Address const& addr) const + operator() (::beast::IP::Address const& addr) const { - return beast::uhash<>{} (addr); + return ::beast::uhash<>{} (addr); } }; } diff --git a/src/ripple/beast/net/IPEndpoint.h b/src/ripple/beast/net/IPEndpoint.h index 5557a90289e..5d4918e58c7 100644 --- a/src/ripple/beast/net/IPEndpoint.h +++ b/src/ripple/beast/net/IPEndpoint.h @@ -97,7 +97,7 @@ class Endpoint void hash_append (Hasher& h, Endpoint const& endpoint) { - using beast::hash_append; + using ::beast::hash_append; hash_append(h, endpoint.m_addr, endpoint.m_port); } @@ -155,20 +155,20 @@ std::istream& operator>> (std::istream& is, Endpoint& endpoint); namespace std { /** std::hash support. */ template <> -struct hash +struct hash <::beast::IP::Endpoint> { - std::size_t operator() (beast::IP::Endpoint const& endpoint) const - { return beast::uhash<>{} (endpoint); } + std::size_t operator() (::beast::IP::Endpoint const& endpoint) const + { return ::beast::uhash<>{} (endpoint); } }; } namespace boost { /** boost::hash support. */ template <> -struct hash +struct hash <::beast::IP::Endpoint> { - std::size_t operator() (beast::IP::Endpoint const& endpoint) const - { return beast::uhash<>{} (endpoint); } + std::size_t operator() (::beast::IP::Endpoint const& endpoint) const + { return ::beast::uhash<>{} (endpoint); } }; } diff --git a/src/ripple/beast/rfc2616.h b/src/ripple/beast/rfc2616.h index b2c22d40316..e59da374619 100644 --- a/src/ripple/beast/rfc2616.h +++ b/src/ripple/beast/rfc2616.h @@ -20,8 +20,8 @@ #ifndef BEAST_RFC2616_HPP #define BEAST_RFC2616_HPP -#include -#include +#include +#include #include #include #include @@ -279,7 +279,7 @@ split_commas(FwdIt first, FwdIt last) template > Result -split_commas(beast::string_view const& s) +split_commas(boost::beast::string_view const& s) { return split_commas(s.begin(), s.end()); } @@ -468,13 +468,13 @@ token_in_list(boost::string_ref const& value, template bool -is_keep_alive(beast::http::message const& m) +is_keep_alive(boost::beast::http::message const& m) { - if(m.version <= 10) - return beast::http::token_list{ - m[beast::http::field::connection]}.exists("keep-alive"); - return ! beast::http::token_list{ - m[beast::http::field::connection]}.exists("close"); + if(m.version() <= 10) + return boost::beast::http::token_list{ + m[boost::beast::http::field::connection]}.exists("keep-alive"); + return ! boost::beast::http::token_list{ + m[boost::beast::http::field::connection]}.exists("close"); } } // rfc2616 diff --git a/src/ripple/beast/utility/weak_fn.h b/src/ripple/beast/utility/weak_fn.h index d52bf92f1e0..619eb8a17e0 100644 --- a/src/ripple/beast/utility/weak_fn.h +++ b/src/ripple/beast/utility/weak_fn.h @@ -20,7 +20,7 @@ #ifndef BEAST_WEAK_FN_H_INCLUDED #define BEAST_WEAK_FN_H_INCLUDED -#include +#include #include // Original version: @@ -87,7 +87,7 @@ namespace detail { template class weak_binder - : private beast::detail::empty_base_optimization + : private boost::beast::detail::empty_base_optimization { private: using member_type = R (T::*)(Args...); @@ -101,7 +101,7 @@ class weak_binder weak_binder (member_type member, Policy policy, pointer_type object) - : beast::detail::empty_base_optimization(std::move(policy)) + : boost::beast::detail::empty_base_optimization(std::move(policy)) , member_(member) , object_(object) { } diff --git a/src/ripple/core/Config.h b/src/ripple/core/Config.h index f7000554299..66b581bdf15 100644 --- a/src/ripple/core/Config.h +++ b/src/ripple/core/Config.h @@ -24,7 +24,7 @@ #include #include // VFALCO Breaks levelization #include -#include +#include #include #include // VFALCO FIX: This include should not be here #include // VFALCO FIX: This include should not be here diff --git a/src/ripple/core/impl/Config.cpp b/src/ripple/core/impl/Config.cpp index 6c1dff52760..473420a1dea 100644 --- a/src/ripple/core/impl/Config.cpp +++ b/src/ripple/core/impl/Config.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include @@ -325,15 +325,15 @@ void Config::loadFromString (std::string const& fileContents) if (getSingleSection (secConfig, SECTION_NODE_SIZE, strTemp, j_)) { - if (beast::detail::iequals(strTemp, "tiny")) + if (boost::beast::detail::iequals(strTemp, "tiny")) NODE_SIZE = 0; - else if (beast::detail::iequals(strTemp, "small")) + else if (boost::beast::detail::iequals(strTemp, "small")) NODE_SIZE = 1; - else if (beast::detail::iequals(strTemp, "medium")) + else if (boost::beast::detail::iequals(strTemp, "medium")) NODE_SIZE = 2; - else if (beast::detail::iequals(strTemp, "large")) + else if (boost::beast::detail::iequals(strTemp, "large")) NODE_SIZE = 3; - else if (beast::detail::iequals(strTemp, "huge")) + else if (boost::beast::detail::iequals(strTemp, "huge")) NODE_SIZE = 4; else { @@ -380,9 +380,9 @@ void Config::loadFromString (std::string const& fileContents) if (getSingleSection (secConfig, SECTION_LEDGER_HISTORY, strTemp, j_)) { - if (beast::detail::iequals(strTemp, "full")) + if (boost::beast::detail::iequals(strTemp, "full")) LEDGER_HISTORY = 1000000000u; - else if (beast::detail::iequals(strTemp, "none")) + else if (boost::beast::detail::iequals(strTemp, "none")) LEDGER_HISTORY = 0; else LEDGER_HISTORY = beast::lexicalCastThrow (strTemp); @@ -390,9 +390,9 @@ void Config::loadFromString (std::string const& fileContents) if (getSingleSection (secConfig, SECTION_FETCH_DEPTH, strTemp, j_)) { - if (beast::detail::iequals(strTemp, "none")) + if (boost::beast::detail::iequals(strTemp, "none")) FETCH_DEPTH = 0; - else if (beast::detail::iequals(strTemp, "full")) + else if (boost::beast::detail::iequals(strTemp, "full")) FETCH_DEPTH = 1000000000u; else FETCH_DEPTH = beast::lexicalCastThrow (strTemp); diff --git a/src/ripple/json/Output.h b/src/ripple/json/Output.h index 5122357449d..cc685d03bea 100644 --- a/src/ripple/json/Output.h +++ b/src/ripple/json/Output.h @@ -20,19 +20,19 @@ #ifndef RIPPLE_JSON_OUTPUT_H_INCLUDED #define RIPPLE_JSON_OUTPUT_H_INCLUDED -#include +#include #include namespace Json { class Value; -using Output = std::function ; +using Output = std::function ; inline Output stringOutput (std::string& s) { - return [&](beast::string_view const& b) { s.append (b.data(), b.size()); }; + return [&](boost::beast::string_view const& b) { s.append (b.data(), b.size()); }; } /** Writes a minimal representation of a Json value to an Output in O(n) time. diff --git a/src/ripple/json/impl/Writer.cpp b/src/ripple/json/impl/Writer.cpp index d6064ed2931..0f76e043d4c 100644 --- a/src/ripple/json/impl/Writer.cpp +++ b/src/ripple/json/impl/Writer.cpp @@ -93,13 +93,13 @@ class Writer::Impl stack_.top().type = ct; } - void output (beast::string_view const& bytes) + void output (boost::beast::string_view const& bytes) { markStarted (); output_ (bytes); } - void stringOutput (beast::string_view const& bytes) + void stringOutput (boost::beast::string_view const& bytes) { markStarted (); std::size_t position = 0, writtenUntil = 0; diff --git a/src/ripple/net/AutoSocket.h b/src/ripple/net/AutoSocket.h index 1dbe4b1d6b7..f2d27e384fb 100644 --- a/src/ripple/net/AutoSocket.h +++ b/src/ripple/net/AutoSocket.h @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include #include @@ -177,7 +177,7 @@ class AutoSocket // must be plain mSecure = false; mSocket->get_io_service ().post ( - beast::bind_handler (cbFunc, error_code())); + boost::beast::bind_handler (cbFunc, error_code())); } else { @@ -210,7 +210,7 @@ class AutoSocket ec = e.code(); } mSocket->get_io_service ().post ( - beast::bind_handler (handler, ec)); + boost::beast::bind_handler (handler, ec)); } } diff --git a/src/ripple/net/impl/RPCCall.cpp b/src/ripple/net/impl/RPCCall.cpp index 4e5c6fb9b6d..c392fb46af5 100644 --- a/src/ripple/net/impl/RPCCall.cpp +++ b/src/ripple/net/impl/RPCCall.cpp @@ -36,7 +36,7 @@ #include #include #include -#include +#include #include #include #include @@ -452,9 +452,9 @@ class RPCParser // This may look reversed, but it's intentional: jss::vetoed // determines whether an amendment is vetoed - so "reject" means // that jss::vetoed is true. - if (beast::detail::iequals(action, "reject")) + if (boost::beast::detail::iequals(action, "reject")) jvRequest[jss::vetoed] = Json::Value (true); - else if (beast::detail::iequals(action, "accept")) + else if (boost::beast::detail::iequals(action, "accept")) jvRequest[jss::vetoed] = Json::Value (false); else return rpcError (rpcINVALID_PARAMS); @@ -1488,7 +1488,7 @@ void fromNetwork ( } // HTTP basic authentication - auto const auth = beast::detail::base64_encode(strUsername + ":" + strPassword); + auto const auth = boost::beast::detail::base64_encode(strUsername + ":" + strPassword); std::map mapRequestHeaders; diff --git a/src/ripple/nodestore/backend/MemoryFactory.cpp b/src/ripple/nodestore/backend/MemoryFactory.cpp index 36d576fb6ce..14fb273199f 100644 --- a/src/ripple/nodestore/backend/MemoryFactory.cpp +++ b/src/ripple/nodestore/backend/MemoryFactory.cpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include @@ -40,7 +40,7 @@ class MemoryFactory : public Factory { private: std::mutex mutex_; - std::map map_; + std::map map_; public: MemoryFactory(); diff --git a/src/ripple/nodestore/impl/ManagerImp.cpp b/src/ripple/nodestore/impl/ManagerImp.cpp index a139f2136e1..b8d8a2ccf16 100644 --- a/src/ripple/nodestore/impl/ManagerImp.cpp +++ b/src/ripple/nodestore/impl/ManagerImp.cpp @@ -111,7 +111,7 @@ ManagerImp::find (std::string const& name) auto const iter = std::find_if(list_.begin(), list_.end(), [&name](Factory* other) { - return beast::detail::iequals(name, other->getName()); + return boost::beast::detail::iequals(name, other->getName()); } ); if (iter == list_.end()) return nullptr; diff --git a/src/ripple/overlay/Overlay.h b/src/ripple/overlay/Overlay.h index 75cfdf9718b..02044530a95 100644 --- a/src/ripple/overlay/Overlay.h +++ b/src/ripple/overlay/Overlay.h @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/ripple/overlay/impl/ConnectAttempt.cpp b/src/ripple/overlay/impl/ConnectAttempt.cpp index bdb05e15c1c..b4206fcc6dc 100644 --- a/src/ripple/overlay/impl/ConnectAttempt.cpp +++ b/src/ripple/overlay/impl/ConnectAttempt.cpp @@ -220,7 +220,7 @@ ConnectAttempt::onHandshake (error_code ec) appendHello (req_, hello); setTimer(); - beast::http::async_write(stream_, req_, + boost::beast::http::async_write(stream_, req_, strand_.wrap (std::bind (&ConnectAttempt::onWrite, shared_from_this(), std::placeholders::_1))); } @@ -235,7 +235,7 @@ ConnectAttempt::onWrite (error_code ec) return; if(ec) return fail("onWrite", ec); - beast::http::async_read(stream_, read_buf_, response_, + boost::beast::http::async_read(stream_, read_buf_, response_, strand_.wrap(std::bind(&ConnectAttempt::onRead, shared_from_this(), std::placeholders::_1))); } @@ -286,9 +286,9 @@ ConnectAttempt::makeRequest (bool crawl, request_type { request_type m; - m.method(beast::http::verb::get); + m.method(boost::beast::http::verb::get); m.target("/"); - m.version = 11; + m.version(11); m.insert ("User-Agent", BuildInfo::getFullVersionString()); m.insert ("Upgrade", "RTXP/1.2"); //std::string("RTXP/") + to_string (BuildInfo::getCurrentProtocol())); @@ -301,13 +301,13 @@ ConnectAttempt::makeRequest (bool crawl, void ConnectAttempt::processResponse() { - if (response_.result() == beast::http::status::service_unavailable) + if (response_.result() == boost::beast::http::status::service_unavailable) { Json::Value json; Json::Reader r; std::string s; - s.reserve(boost::asio::buffer_size(response_.body.data())); - for(auto const& buffer : response_.body.data()) + s.reserve(boost::asio::buffer_size(response_.body().data())); + for(auto const& buffer : response_.body().data()) s.append( boost::asio::buffer_cast(buffer), boost::asio::buffer_size(buffer)); diff --git a/src/ripple/overlay/impl/ConnectAttempt.h b/src/ripple/overlay/impl/ConnectAttempt.h index d22463e0fd4..80b5c941b76 100644 --- a/src/ripple/overlay/impl/ConnectAttempt.h +++ b/src/ripple/overlay/impl/ConnectAttempt.h @@ -37,10 +37,10 @@ class ConnectAttempt using endpoint_type = boost::asio::ip::tcp::endpoint; using request_type = - beast::http::request; + boost::beast::http::request; using response_type = - beast::http::response; + boost::beast::http::response; Application& app_; std::uint32_t const id_; @@ -53,7 +53,7 @@ class ConnectAttempt std::unique_ptr ssl_bundle_; beast::asio::ssl_bundle::socket_type& socket_; beast::asio::ssl_bundle::stream_type& stream_; - beast::multi_buffer read_buf_; + boost::beast::multi_buffer read_buf_; response_type response_; PeerFinder::Slot::ptr slot_; request_type req_; diff --git a/src/ripple/overlay/impl/OverlayImpl.cpp b/src/ripple/overlay/impl/OverlayImpl.cpp index ca549eada66..75a39fc61aa 100644 --- a/src/ripple/overlay/impl/OverlayImpl.cpp +++ b/src/ripple/overlay/impl/OverlayImpl.cpp @@ -214,7 +214,7 @@ OverlayImpl::onHandoff (std::unique_ptr && ssl_bundle, if (std::find_if(types.begin(), types.end(), [](std::string const& s) { - return beast::detail::iequals(s, "peer"); + return boost::beast::detail::iequals(s, "peer"); }) == types.end()) { handoff.moved = false; @@ -328,17 +328,17 @@ std::shared_ptr OverlayImpl::makeRedirectResponse (PeerFinder::Slot::ptr const& slot, http_request_type const& request, address_type remote_address) { - beast::http::response msg; - msg.version = request.version; - msg.result(beast::http::status::service_unavailable); + boost::beast::http::response msg; + msg.version(request.version()); + msg.result(boost::beast::http::status::service_unavailable); msg.insert("Server", BuildInfo::getFullVersionString()); msg.insert("Remote-Address", remote_address); msg.insert("Content-Type", "application/json"); - msg.insert(beast::http::field::connection, "close"); - msg.body = Json::objectValue; + msg.insert(boost::beast::http::field::connection, "close"); + msg.body() = Json::objectValue; { auto const result = m_peerFinder->redirect(slot); - Json::Value& ips = (msg.body["peer-ips"] = Json::arrayValue); + Json::Value& ips = (msg.body()["peer-ips"] = Json::arrayValue); for (auto const& _ : m_peerFinder->redirect(slot)) ips.append(_.address.to_string()); } @@ -352,13 +352,13 @@ OverlayImpl::makeErrorResponse (PeerFinder::Slot::ptr const& slot, address_type remote_address, std::string text) { - beast::http::response msg; - msg.version = request.version; - msg.result(beast::http::status::bad_request); + boost::beast::http::response msg; + msg.version(request.version()); + msg.result(boost::beast::http::status::bad_request); msg.insert("Server", BuildInfo::getFullVersionString()); msg.insert("Remote-Address", remote_address.to_string()); - msg.insert(beast::http::field::connection, "close"); - msg.body = text; + msg.insert(boost::beast::http::field::connection, "close"); + msg.body() = text; msg.prepare_payload(); return std::make_shared(msg); } @@ -763,7 +763,7 @@ OverlayImpl::crawl() for_each ([&](std::shared_ptr&& sp) { auto& pv = av.append(Json::Value(Json::objectValue)); - pv[jss::public_key] = beast::detail::base64_encode( + pv[jss::public_key] = boost::beast::detail::base64_encode( sp->getNodePublic().data(), sp->getNodePublic().size()); pv[jss::type] = sp->slot()->inbound() ? @@ -818,13 +818,13 @@ OverlayImpl::processRequest (http_request_type const& req, if (req.target() != "/crawl") return false; - beast::http::response msg; - msg.version = req.version; - msg.result(beast::http::status::ok); + boost::beast::http::response msg; + msg.version(req.version()); + msg.result(boost::beast::http::status::ok); msg.insert("Server", BuildInfo::getFullVersionString()); msg.insert("Content-Type", "application/json"); msg.insert("Connection", "close"); - msg.body["overlay"] = crawl(); + msg.body()["overlay"] = crawl(); msg.prepare_payload(); handoff.response = std::make_shared(msg); return true; diff --git a/src/ripple/overlay/impl/OverlayImpl.h b/src/ripple/overlay/impl/OverlayImpl.h index 81b518fcc40..ae874eccb9a 100644 --- a/src/ripple/overlay/impl/OverlayImpl.h +++ b/src/ripple/overlay/impl/OverlayImpl.h @@ -255,11 +255,11 @@ class OverlayImpl : public Overlay template static bool - isPeerUpgrade (beast::http::response const& response) + isPeerUpgrade (boost::beast::http::response const& response) { if (! is_upgrade(response)) return false; - if(response.result() != beast::http::status::switching_protocols) + if(response.result() != boost::beast::http::status::switching_protocols) return false; auto const versions = parse_ProtocolVersions( response["Upgrade"]); @@ -271,13 +271,13 @@ class OverlayImpl : public Overlay template static bool - is_upgrade(beast::http::header const& req) + is_upgrade(boost::beast::http::header const& req) { - if(req.version < 11) + if(req.version() < 11) return false; - if(req.method() != beast::http::verb::get) + if(req.method() != boost::beast::http::verb::get) return false; - if(! beast::http::token_list{req["Connection"]}.exists("upgrade")) + if(! boost::beast::http::token_list{req["Connection"]}.exists("upgrade")) return false; return true; } @@ -285,11 +285,11 @@ class OverlayImpl : public Overlay template static bool - is_upgrade(beast::http::header const& req) + is_upgrade(boost::beast::http::header const& req) { - if(req.version < 11) + if(req.version() < 11) return false; - if(! beast::http::token_list{req["Connection"]}.exists("upgrade")) + if(! boost::beast::http::token_list{req["Connection"]}.exists("upgrade")) return false; return true; } diff --git a/src/ripple/overlay/impl/PeerImp.cpp b/src/ripple/overlay/impl/PeerImp.cpp index e8be9399532..638919b2e5c 100644 --- a/src/ripple/overlay/impl/PeerImp.cpp +++ b/src/ripple/overlay/impl/PeerImp.cpp @@ -238,7 +238,7 @@ PeerImp::crawl() const auto const iter = headers_.find("Crawl"); if (iter == headers_.end()) return false; - return beast::detail::iequals(iter->value(), "public"); + return boost::beast::detail::iequals(iter->value(), "public"); } std::string @@ -621,7 +621,7 @@ void PeerImp::doAccept() // TODO Apply headers to connection state. - beast::ostream(write_buffer_) << makeResponse( + boost::beast::ostream(write_buffer_) << makeResponse( ! overlay_.peerFinder().config().peerPrivate, request_, remote_address_, *sharedValue); @@ -669,8 +669,8 @@ PeerImp::makeResponse (bool crawl, uint256 const& sharedValue) { http_response_type resp; - resp.result(beast::http::status::switching_protocols); - resp.version = req.version; + resp.result(boost::beast::http::status::switching_protocols); + resp.version(req.version()); resp.insert("Connection", "Upgrade"); resp.insert("Upgrade", "RTXP/1.2"); resp.insert("Connect-As", "Peer"); diff --git a/src/ripple/overlay/impl/PeerImp.h b/src/ripple/overlay/impl/PeerImp.h index e07c5d10067..67e118a444e 100644 --- a/src/ripple/overlay/impl/PeerImp.h +++ b/src/ripple/overlay/impl/PeerImp.h @@ -143,11 +143,11 @@ class PeerImp Resource::Consumer usage_; Resource::Charge fee_; PeerFinder::Slot::ptr slot_; - beast::multi_buffer read_buffer_; + boost::beast::multi_buffer read_buffer_; http_request_type request_; http_response_type response_; - beast::http::fields const& headers_; - beast::multi_buffer write_buffer_; + boost::beast::http::fields const& headers_; + boost::beast::multi_buffer write_buffer_; std::queue send_queue_; bool gracefulClose_ = false; int large_sendq_ = 0; diff --git a/src/ripple/overlay/impl/TMHello.cpp b/src/ripple/overlay/impl/TMHello.cpp index 0ea6a5c31c6..9cb40b52642 100644 --- a/src/ripple/overlay/impl/TMHello.cpp +++ b/src/ripple/overlay/impl/TMHello.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include @@ -151,14 +151,14 @@ buildHello ( } void -appendHello (beast::http::fields& h, +appendHello (boost::beast::http::fields& h, protocol::TMHello const& hello) { //h.append ("Protocol-Versions",... h.insert ("Public-Key", hello.nodepublic()); - h.insert ("Session-Signature", beast::detail::base64_encode ( + h.insert ("Session-Signature", boost::beast::detail::base64_encode ( hello.nodeproof())); if (hello.has_nettime()) @@ -168,11 +168,11 @@ appendHello (beast::http::fields& h, h.insert ("Ledger", std::to_string (hello.ledgerindex())); if (hello.has_ledgerclosed()) - h.insert ("Closed-Ledger", beast::detail::base64_encode ( + h.insert ("Closed-Ledger", boost::beast::detail::base64_encode ( hello.ledgerclosed())); if (hello.has_ledgerprevious()) - h.insert ("Previous-Ledger", beast::detail::base64_encode ( + h.insert ("Previous-Ledger", boost::beast::detail::base64_encode ( hello.ledgerprevious())); if (hello.has_local_ip()) @@ -185,7 +185,7 @@ appendHello (beast::http::fields& h, } std::vector -parse_ProtocolVersions(beast::string_view const& value) +parse_ProtocolVersions(boost::beast::string_view const& value) { static boost::regex re ( "^" // start of line @@ -219,7 +219,7 @@ parse_ProtocolVersions(beast::string_view const& value) } boost::optional -parseHello (bool request, beast::http::fields const& h, beast::Journal journal) +parseHello (bool request, boost::beast::http::fields const& h, beast::Journal journal) { // protocol version in TMHello is obsolete, // it is supplanted by the values in the headers. @@ -259,7 +259,7 @@ parseHello (bool request, beast::http::fields const& h, beast::Journal journal) if (iter == h.end()) return boost::none; // TODO Security Review - hello.set_nodeproof (beast::detail::base64_decode (iter->value().to_string())); + hello.set_nodeproof (boost::beast::detail::base64_decode (iter->value().to_string())); } { @@ -294,13 +294,13 @@ parseHello (bool request, beast::http::fields const& h, beast::Journal journal) { auto const iter = h.find ("Closed-Ledger"); if (iter != h.end()) - hello.set_ledgerclosed (beast::detail::base64_decode (iter->value().to_string())); + hello.set_ledgerclosed (boost::beast::detail::base64_decode (iter->value().to_string())); } { auto const iter = h.find ("Previous-Ledger"); if (iter != h.end()) - hello.set_ledgerprevious (beast::detail::base64_decode (iter->value().to_string())); + hello.set_ledgerprevious (boost::beast::detail::base64_decode (iter->value().to_string())); } { diff --git a/src/ripple/overlay/impl/TMHello.h b/src/ripple/overlay/impl/TMHello.h index ed03f1543eb..9deba3474dd 100644 --- a/src/ripple/overlay/impl/TMHello.h +++ b/src/ripple/overlay/impl/TMHello.h @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include #include @@ -56,14 +56,14 @@ buildHello (uint256 const& sharedValue, /** Insert HTTP headers based on the TMHello protocol message. */ void -appendHello (beast::http::fields& h, protocol::TMHello const& hello); +appendHello (boost::beast::http::fields& h, protocol::TMHello const& hello); /** Parse HTTP headers into TMHello protocol message. @return A protocol message on success; an empty optional if the parsing failed. */ boost::optional -parseHello (bool request, beast::http::fields const& h, beast::Journal journal); +parseHello (bool request, boost::beast::http::fields const& h, beast::Journal journal); /** Validate and store the public key in the TMHello. This includes signature verification on the shared value. @@ -82,7 +82,7 @@ verifyHello (protocol::TMHello const& h, uint256 const& sharedValue, excluded from the result set. */ std::vector -parse_ProtocolVersions(beast::string_view const& s); +parse_ProtocolVersions(boost::beast::string_view const& s); } diff --git a/src/ripple/rpc/impl/ServerHandlerImp.cpp b/src/ripple/rpc/impl/ServerHandlerImp.cpp index ed1330d24d6..796b0a8a6af 100644 --- a/src/ripple/rpc/impl/ServerHandlerImp.cpp +++ b/src/ripple/rpc/impl/ServerHandlerImp.cpp @@ -40,9 +40,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include #include #include @@ -58,10 +58,10 @@ isStatusRequest( http_request_type const& request) { return - request.version >= 11 && + request.version() >= 11 && request.target() == "/" && - request.body.size() == 0 && - request.method() == beast::http::verb::get; + request.body().size() == 0 && + request.method() == boost::beast::http::verb::get; } static @@ -69,21 +69,21 @@ Handoff unauthorizedResponse( http_request_type const& request) { - using namespace beast::http; + using namespace boost::beast::http; Handoff handoff; response msg; - msg.version = request.version; - msg.result(beast::http::status::unauthorized); + msg.version(request.version()); + msg.result(boost::beast::http::status::unauthorized); msg.insert("Server", BuildInfo::getFullVersionString()); msg.insert("Content-Type", "text/html"); msg.insert("Connection", "close"); - msg.body = "Invalid protocol."; + msg.body() = "Invalid protocol."; msg.prepare_payload(); handoff.response = std::make_shared(msg); return handoff; } -// VFALCO TODO Rewrite to use beast::http::fields +// VFALCO TODO Rewrite to use boost::beast::http::fields static bool authorized ( @@ -98,7 +98,7 @@ authorized ( return false; std::string strUserPass64 = it->second.substr (6); boost::trim (strUserPass64); - std::string strUserPass = beast::detail::base64_decode (strUserPass64); + std::string strUserPass = boost::beast::detail::base64_decode (strUserPass64); std::string::size_type nColon = strUserPass.find (":"); if (nColon == std::string::npos) return false; @@ -179,7 +179,7 @@ ServerHandlerImp::onHandoff (Session& session, (session.port().protocol.count("wss") > 0) || (session.port().protocol.count("wss2") > 0); - if(beast::websocket::is_upgrade(request)) + if(boost::beast::websocket::is_upgrade(request)) { if(is_ws) { @@ -219,7 +219,7 @@ ServerHandlerImp::onHandoff (Session& session, boost::asio::ip::tcp::endpoint remote_address) -> Handoff { - if(beast::websocket::is_upgrade(request)) + if(boost::beast::websocket::is_upgrade(request)) { if (session.port().protocol.count("ws2") > 0 || session.port().protocol.count("ws") > 0) @@ -251,7 +251,7 @@ ServerHandlerImp::onHandoff (Session& session, static inline Json::Output makeOutput (Session& session) { - return [&](beast::string_view const& b) + return [&](boost::beast::string_view const& b) { session.write (b.data(), b.size()); }; @@ -260,7 +260,7 @@ Json::Output makeOutput (Session& session) // HACK! static std::map -build_map(beast::http::fields const& h) +build_map(boost::beast::http::fields const& h) { std::map c; for (auto const& e : h) @@ -341,7 +341,7 @@ ServerHandlerImp::onWSMessage( jvResult[jss::type] = jss::error; jvResult[jss::error] = "jsonInvalid"; jvResult[jss::value] = buffers_to_string(buffers); - beast::multi_buffer sb; + boost::beast::multi_buffer sb; Json::stream(jvResult, [&sb](auto const p, auto const n) { @@ -367,7 +367,7 @@ ServerHandlerImp::onWSMessage( this->processSession(session, coro, jv); auto const s = to_string(jr); auto const n = s.length(); - beast::multi_buffer sb(n); + boost::beast::multi_buffer sb(n); sb.commit(boost::asio::buffer_copy( sb.prepare(n), boost::asio::buffer(s.c_str(), n))); session->send(std::make_shared< @@ -509,7 +509,7 @@ ServerHandlerImp::processSession (std::shared_ptr const& session, { processRequest ( session->port(), buffers_to_string( - session->request().body.data()), + session->request().body().data()), session->remoteAddress().at_port (0), makeOutput (*session), coro, [&] @@ -831,25 +831,25 @@ Handoff ServerHandlerImp::statusResponse( http_request_type const& request) const { - using namespace beast::http; + using namespace boost::beast::http; Handoff handoff; response msg; std::string reason; if (app_.serverOkay(reason)) { - msg.result(beast::http::status::ok); - msg.body = "" + systemName() + + msg.result(boost::beast::http::status::ok); + msg.body() = "<!DOCTYPE html><html><head><title>" + systemName() + " Test page for rippled

" + systemName() + " Test

This page shows rippled http(s) " "connectivity is working.

"; } else { - msg.result(beast::http::status::internal_server_error); - msg.body = "Server cannot accept clients: " + + msg.result(boost::beast::http::status::internal_server_error); + msg.body() = "Server cannot accept clients: " + reason + ""; } - msg.version = request.version; + msg.version(request.version()); msg.insert("Server", BuildInfo::getFullVersionString()); msg.insert("Content-Type", "text/html"); msg.insert("Connection", "close"); diff --git a/src/ripple/rpc/impl/WSInfoSub.h b/src/ripple/rpc/impl/WSInfoSub.h index 0eaffd3baac..183084910f2 100644 --- a/src/ripple/rpc/impl/WSInfoSub.h +++ b/src/ripple/rpc/impl/WSInfoSub.h @@ -73,7 +73,7 @@ class WSInfoSub : public InfoSub auto sp = ws_.lock(); if(! sp) return; - beast::multi_buffer sb; + boost::beast::multi_buffer sb; Json::stream(jv, [&](void const* data, std::size_t n) { diff --git a/src/ripple/rpc/json_body.h b/src/ripple/rpc/json_body.h index 6dc1e878693..900c7a161a5 100644 --- a/src/ripple/rpc/json_body.h +++ b/src/ripple/rpc/json_body.h @@ -21,8 +21,10 @@ #define RIPPLE_RPC_JSON_BODY_H #include -#include -#include +#include + +#include +#include namespace ripple { @@ -33,7 +35,7 @@ struct json_body class reader { - using dynamic_buffer_type = beast::multi_buffer; + using dynamic_buffer_type = boost::beast::multi_buffer; dynamic_buffer_type buffer_; @@ -45,7 +47,7 @@ struct json_body template explicit - reader(beast::http::message< + reader(boost::beast::http::message< isRequest, json_body, Fields> const& m) { stream(m.body, @@ -57,19 +59,50 @@ struct json_body } void - init(beast::error_code&) noexcept + init(boost::beast::error_code&) noexcept { } boost::optional> - get(beast::error_code& ec) + get(boost::beast::error_code& ec) { return {{buffer_.data(), false}}; } void - finish(beast::error_code&) + finish(boost::beast::error_code&) + { + } + }; + + class writer + { + std::string body_string_; + + public: + using const_buffers_type = + boost::asio::const_buffer; + + template + explicit + writer(boost::beast::http::message const& msg) + : body_string_(to_string(msg.body())) + { + } + + void + init(boost::beast::error_code& ec) + { + ec.assign(0, ec.category()); + } + + boost::optional> + get(boost::beast::error_code& ec) { + ec.assign(0, ec.category()); + return {{const_buffers_type{ + body_string_.data(), body_string_.size()}, false}}; } }; }; diff --git a/src/ripple/server/Handoff.h b/src/ripple/server/Handoff.h index 48220545ff2..60077f0dd7b 100644 --- a/src/ripple/server/Handoff.h +++ b/src/ripple/server/Handoff.h @@ -21,17 +21,17 @@ #define RIPPLE_SERVER_HANDOFF_H_INCLUDED #include -#include -#include +#include +#include #include namespace ripple { using http_request_type = - beast::http::request; + boost::beast::http::request; using http_response_type = - beast::http::response; + boost::beast::http::response; /** Used to indicate the result of a server connection handoff. */ struct Handoff diff --git a/src/ripple/server/Port.h b/src/ripple/server/Port.h index e911ebc7ace..35b948be901 100644 --- a/src/ripple/server/Port.h +++ b/src/ripple/server/Port.h @@ -22,8 +22,8 @@ #include #include -#include -#include +#include +#include #include #include #include @@ -40,7 +40,7 @@ struct Port std::string name; boost::asio::ip::address ip; std::uint16_t port = 0; - std::set protocol; + std::set protocol; std::vector admin_ip; std::vector secure_gateway_ip; std::string user; @@ -51,7 +51,7 @@ struct Port std::string ssl_cert; std::string ssl_chain; std::string ssl_ciphers; - beast::websocket::permessage_deflate pmd_options; + boost::beast::websocket::permessage_deflate pmd_options; std::shared_ptr context; // How many incoming connections are allowed on this @@ -79,7 +79,7 @@ operator<< (std::ostream& os, Port const& p); struct ParsedPort { std::string name; - std::set protocol; + std::set protocol; std::string user; std::string password; std::string admin_user; @@ -88,7 +88,7 @@ struct ParsedPort std::string ssl_cert; std::string ssl_chain; std::string ssl_ciphers; - beast::websocket::permessage_deflate pmd_options; + boost::beast::websocket::permessage_deflate pmd_options; int limit = 0; std::uint16_t ws_queue_limit; diff --git a/src/ripple/server/Session.h b/src/ripple/server/Session.h index db0d3595672..82f19e01f99 100644 --- a/src/ripple/server/Session.h +++ b/src/ripple/server/Session.h @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/ripple/server/SimpleWriter.h b/src/ripple/server/SimpleWriter.h index 9d17dbd1cd9..0badea441b8 100644 --- a/src/ripple/server/SimpleWriter.h +++ b/src/ripple/server/SimpleWriter.h @@ -21,10 +21,10 @@ #define RIPPLE_SERVER_SIMPLEWRITER_H_INCLUDED #include -#include -#include -#include -#include +#include +#include +#include +#include #include namespace ripple { @@ -32,15 +32,14 @@ namespace ripple { /// Deprecated: Writer that serializes a HTTP/1 message class SimpleWriter : public Writer { - beast::multi_buffer sb_; + boost::beast::multi_buffer sb_; public: - template + template explicit - SimpleWriter(beast::http::message< - isRequest, Body, Headers> const& msg) + SimpleWriter(boost::beast::http::message const& msg) { - beast::ostream(sb_) << msg; + boost::beast::ostream(sb_) << msg; } bool diff --git a/src/ripple/server/WSSession.h b/src/ripple/server/WSSession.h index b89e5d3cc4e..71da1e27bdf 100644 --- a/src/ripple/server/WSSession.h +++ b/src/ripple/server/WSSession.h @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include @@ -98,7 +98,7 @@ class StreambufWSMsg : public WSMsg n_ = sb_.size(); done = true; } - auto const pb = beast::buffer_prefix(n_, sb_.data()); + auto const pb = boost::beast::buffers_prefix(n_, sb_.data()); std::vector vb ( std::distance(pb.begin(), pb.end())); std::copy(pb.begin(), pb.end(), std::back_inserter(vb)); diff --git a/src/ripple/server/impl/BaseHTTPPeer.h b/src/ripple/server/impl/BaseHTTPPeer.h index 90ad13a0064..f4d6118cc66 100644 --- a/src/ripple/server/impl/BaseHTTPPeer.h +++ b/src/ripple/server/impl/BaseHTTPPeer.h @@ -25,10 +25,10 @@ #include #include #include // for is_short_read? -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include @@ -324,10 +324,10 @@ do_read(yield_context do_yield) complete_ = false; error_code ec; start_timer(); - beast::http::async_read(impl().stream_, + boost::beast::http::async_read(impl().stream_, read_buf_, message_, do_yield[ec]); cancel_timer(); - if(ec == beast::http::error::end_of_stream) + if(ec == boost::beast::http::error::end_of_stream) return do_close(); if(ec) return fail(ec, "http::read"); diff --git a/src/ripple/server/impl/BaseWSPeer.h b/src/ripple/server/impl/BaseWSPeer.h index a4a2d3861a8..ca1656e7b18 100644 --- a/src/ripple/server/impl/BaseWSPeer.h +++ b/src/ripple/server/impl/BaseWSPeer.h @@ -24,10 +24,11 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include +#include namespace ripple { @@ -48,24 +49,24 @@ class BaseWSPeer friend class BasePeer; http_request_type request_; - beast::multi_buffer rb_; - beast::multi_buffer wb_; + boost::beast::multi_buffer rb_; + boost::beast::multi_buffer wb_; std::list> wq_; bool do_close_ = false; - beast::websocket::close_reason cr_; + boost::beast::websocket::close_reason cr_; waitable_timer timer_; bool close_on_timer_ = false; bool ping_active_ = false; - beast::websocket::ping_data payload_; + boost::beast::websocket::ping_data payload_; error_code ec_; - + std::function control_callback_; public: template BaseWSPeer( Port const& port, Handler& handler, endpoint_type remote_address, - beast::http::request&& request, + boost::beast::http::request&& request, boost::asio::io_service& io_service, beast::Journal journal); @@ -141,8 +142,8 @@ class BaseWSPeer on_ping(error_code const& ec); void - on_ping_pong(beast::websocket::frame_type kind, - beast::string_view payload); + on_ping_pong(boost::beast::websocket::frame_type kind, + boost::beast::string_view payload); void on_timer(error_code ec); @@ -161,7 +162,7 @@ BaseWSPeer( Port const& port, Handler& handler, endpoint_type remote_address, - beast::http::request&& request, + boost::beast::http::request&& request, boost::asio::io_service& io_service, beast::Journal journal) : BasePeer(port, handler, remote_address, @@ -180,15 +181,17 @@ run() return strand_.post(std::bind( &BaseWSPeer::run, impl().shared_from_this())); impl().ws_.set_option(port().pmd_options); - impl().ws_.control_callback( - std::bind(&BaseWSPeer::on_ping_pong, this, - std::placeholders::_1, std::placeholders::_2)); + // Must manage the control callback memory outside of the `control_callback` function + control_callback_ = std::bind( + &BaseWSPeer::on_ping_pong, + this, std::placeholders::_1, std::placeholders::_2); + impl().ws_.control_callback(control_callback_); start_timer(); close_on_timer_ = true; impl().ws_.async_accept_ex(request_, [](auto & res) { - res.set(beast::http::field::server, + res.set(boost::beast::http::field::server, BuildInfo::getFullVersionString()); }, strand_.wrap(std::bind(&BaseWSPeer::on_ws_handshake, @@ -210,7 +213,7 @@ send(std::shared_ptr w) { JLOG(this->j_.info()) << "closing slow client"; - cr_.code = static_cast(4000); + cr_.code = static_cast(4000); cr_.reason = "Client is too slow."; wq_.erase(std::next(wq_.begin()), wq_.end()); close(); @@ -284,12 +287,12 @@ on_write(error_code const& ec) return; start_timer(); if(! result.first) - impl().ws_.async_write_frame( + impl().ws_.async_write_some( result.first, result.second, strand_.wrap(std::bind( &BaseWSPeer::on_write, impl().shared_from_this(), std::placeholders::_1))); else - impl().ws_.async_write_frame( + impl().ws_.async_write_some( result.first, result.second, strand_.wrap(std::bind( &BaseWSPeer::on_write_fin, impl().shared_from_this(), std::placeholders::_1))); @@ -329,7 +332,7 @@ void BaseWSPeer:: on_read(error_code const& ec) { - if(ec == beast::websocket::error::closed) + if(ec == boost::beast::websocket::error::closed) return on_close({}); if(ec) return fail(ec, "read"); @@ -395,12 +398,12 @@ on_ping(error_code const& ec) template void BaseWSPeer:: -on_ping_pong(beast::websocket::frame_type kind, - beast::string_view payload) +on_ping_pong(boost::beast::websocket::frame_type kind, + boost::beast::string_view payload) { - if(kind == beast::websocket::frame_type::pong) + if(kind == boost::beast::websocket::frame_type::pong) { - beast::string_view p(payload_.begin()); + boost::beast::string_view p(payload_.begin()); if(payload == p) { close_on_timer_ = false; diff --git a/src/ripple/server/impl/Door.h b/src/ripple/server/impl/Door.h index db78aec8c44..bb4a069db5e 100644 --- a/src/ripple/server/impl/Door.h +++ b/src/ripple/server/impl/Door.h @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include @@ -229,7 +229,7 @@ do_detect(boost::asio::yield_context do_yield) { bool ssl; error_code ec; - beast::multi_buffer buf(16); + boost::beast::multi_buffer buf(16); timer_.expires_from_now(std::chrono::seconds(15)); std::tie(ec, ssl) = detect_ssl(socket_, buf, do_yield); error_code unused; diff --git a/src/ripple/server/impl/PlainWSPeer.h b/src/ripple/server/impl/PlainWSPeer.h index 18f8ae4cad5..d06f612ec2b 100644 --- a/src/ripple/server/impl/PlainWSPeer.h +++ b/src/ripple/server/impl/PlainWSPeer.h @@ -39,7 +39,7 @@ class PlainWSPeer using waitable_timer = boost::asio::basic_waitable_timer ; using socket_type = boost::asio::ip::tcp::socket; - beast::websocket::stream ws_; + boost::beast::websocket::stream ws_; public: template @@ -47,7 +47,7 @@ class PlainWSPeer Port const& port, Handler& handler, endpoint_type remote_address, - beast::http::request&& request, + boost::beast::http::request&& request, socket_type&& socket, beast::Journal journal); }; @@ -61,7 +61,7 @@ PlainWSPeer( Port const& port, Handler& handler, endpoint_type remote_address, - beast::http::request&& request, + boost::beast::http::request&& request, socket_type&& socket, beast::Journal journal) : BaseWSPeer(port, handler, remote_address, diff --git a/src/ripple/server/impl/Port.cpp b/src/ripple/server/impl/Port.cpp index c8b18511f82..2f9c26bfcf1 100644 --- a/src/ripple/server/impl/Port.cpp +++ b/src/ripple/server/impl/Port.cpp @@ -188,7 +188,7 @@ parse_Port (ParsedPort& port, Section const& section, std::ostream& log) { auto const lim = get (section, "limit", "unlimited"); - if (!beast::detail::iequals (lim, "unlimited")) + if (!boost::beast::detail::iequals (lim, "unlimited")) { try { diff --git a/src/ripple/server/impl/SSLWSPeer.h b/src/ripple/server/impl/SSLWSPeer.h index 1bf9afe49f4..3b662ff471f 100644 --- a/src/ripple/server/impl/SSLWSPeer.h +++ b/src/ripple/server/impl/SSLWSPeer.h @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include namespace ripple { @@ -43,7 +43,7 @@ class SSLWSPeer boost::asio::basic_waitable_timer ; std::unique_ptr ssl_bundle_; - beast::websocket::stream< + boost::beast::websocket::stream< beast::asio::ssl_bundle::stream_type&> ws_; public: @@ -52,7 +52,7 @@ class SSLWSPeer Port const& port, Handler& handler, endpoint_type remote_endpoint, - beast::http::request&& request, + boost::beast::http::request&& request, std::unique_ptr< beast::asio::ssl_bundle>&& ssl_bundle, beast::Journal journal); @@ -67,7 +67,7 @@ SSLWSPeer( Port const& port, Handler& handler, endpoint_type remote_endpoint, - beast::http::request&& request, + boost::beast::http::request&& request, std::unique_ptr< beast::asio::ssl_bundle>&& ssl_bundle, beast::Journal journal) diff --git a/src/test/app/Manifest_test.cpp b/src/test/app/Manifest_test.cpp index ffa6a6b2e09..425bd80178e 100644 --- a/src/test/app/Manifest_test.cpp +++ b/src/test/app/Manifest_test.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include @@ -123,7 +123,7 @@ class Manifest_test : public beast::unit_test::suite Serializer s; st.add(s); - return beast::detail::base64_encode (std::string( + return boost::beast::detail::base64_encode (std::string( static_cast (s.data()), s.size())); } @@ -176,7 +176,7 @@ class Manifest_test : public beast::unit_test::suite Serializer s; st.add(s); - return beast::detail::base64_encode (std::string( + return boost::beast::detail::base64_encode (std::string( static_cast (s.data()), s.size())); } diff --git a/src/test/app/TxQ_test.cpp b/src/test/app/TxQ_test.cpp index 115a9e9b2f0..1d8035f5575 100644 --- a/src/test/app/TxQ_test.cpp +++ b/src/test/app/TxQ_test.cpp @@ -1092,8 +1092,6 @@ class TxQ_test : public beast::unit_test::suite auto alice = Account("alice"); - auto queued = ter(terQUEUED); - BEAST_EXPECT(env.current()->fees().base == 10); checkMetrics(env, 0, boost::none, 0, 1, 256); @@ -1133,7 +1131,6 @@ class TxQ_test : public beast::unit_test::suite {"maximum_txn_in_ledger", "5"} })); auto alice = Account("alice"); - auto queued = ter(terQUEUED); checkMetrics(env, 0, boost::none, 0, 2, 256); diff --git a/src/test/app/ValidatorList_test.cpp b/src/test/app/ValidatorList_test.cpp index b351370d135..fbd4a61b7ff 100644 --- a/src/test/app/ValidatorList_test.cpp +++ b/src/test/app/ValidatorList_test.cpp @@ -17,7 +17,7 @@ */ //============================================================================== -#include +#include #include #include #include @@ -89,7 +89,7 @@ class ValidatorList_test : public beast::unit_test::suite derivePublicKey(KeyType::ed25519, secret); auto const signingKeys = randomKeyPair(KeyType::secp256k1); return { masterPublic, signingKeys.first, - beast::detail::base64_encode(makeManifestString ( + boost::beast::detail::base64_encode(makeManifestString ( masterPublic, secret, signingKeys.first, signingKeys.second, 1)) }; } @@ -112,7 +112,7 @@ class ValidatorList_test : public beast::unit_test::suite data.pop_back(); data += "]}"; - return beast::detail::base64_encode(data); + return boost::beast::detail::base64_encode(data); } std::string @@ -120,7 +120,7 @@ class ValidatorList_test : public beast::unit_test::suite std::string const& blob, std::pair const& keys) { - auto const data = beast::detail::base64_decode (blob); + auto const data = boost::beast::detail::base64_decode (blob); return strHex(sign( keys.first, keys.second, makeSlice(data))); } @@ -364,7 +364,7 @@ class ValidatorList_test : public beast::unit_test::suite auto const publisherPublic = derivePublicKey(KeyType::ed25519, publisherSecret); auto const pubSigningKeys1 = randomKeyPair(KeyType::secp256k1); - auto const manifest1 = beast::detail::base64_encode(makeManifestString ( + auto const manifest1 = boost::beast::detail::base64_encode(makeManifestString ( publisherPublic, publisherSecret, pubSigningKeys1.first, pubSigningKeys1.second, 1)); @@ -415,7 +415,7 @@ class ValidatorList_test : public beast::unit_test::suite } // do not use list from untrusted publisher - auto const untrustedManifest = beast::detail::base64_encode( + auto const untrustedManifest = boost::beast::detail::base64_encode( makeManifestString ( randomMasterKey(), publisherSecret, pubSigningKeys1.first, pubSigningKeys1.second, 1)); @@ -462,7 +462,7 @@ class ValidatorList_test : public beast::unit_test::suite // apply list with new publisher key updated by manifest auto const pubSigningKeys2 = randomKeyPair(KeyType::secp256k1); - auto manifest2 = beast::detail::base64_encode(makeManifestString ( + auto manifest2 = boost::beast::detail::base64_encode(makeManifestString ( publisherPublic, publisherSecret, pubSigningKeys2.first, pubSigningKeys2.second, 2)); @@ -486,7 +486,7 @@ class ValidatorList_test : public beast::unit_test::suite // do not apply list with revoked publisher key // applied list is removed due to revoked publisher key auto const signingKeysMax = randomKeyPair(KeyType::secp256k1); - auto maxManifest = beast::detail::base64_encode(makeManifestString ( + auto maxManifest = boost::beast::detail::base64_encode(makeManifestString ( publisherPublic, publisherSecret, pubSigningKeys2.first, pubSigningKeys2.second, std::numeric_limits::max ())); @@ -746,7 +746,7 @@ class ValidatorList_test : public beast::unit_test::suite std::vector emptyCfgKeys; auto const publisherKeys = randomKeyPair(KeyType::secp256k1); auto const pubSigningKeys = randomKeyPair(KeyType::secp256k1); - auto const manifest = beast::detail::base64_encode ( + auto const manifest = boost::beast::detail::base64_encode ( makeManifestString ( publisherKeys.first, publisherKeys.second, pubSigningKeys.first, pubSigningKeys.second, 1)); @@ -895,7 +895,7 @@ class ValidatorList_test : public beast::unit_test::suite auto const publisherPublic = derivePublicKey(KeyType::ed25519, publisherSecret); auto const pubSigningKeys = randomKeyPair(KeyType::secp256k1); - auto const manifest = beast::detail::base64_encode(makeManifestString ( + auto const manifest = boost::beast::detail::base64_encode(makeManifestString ( publisherPublic, publisherSecret, pubSigningKeys.first, pubSigningKeys.second, 1)); @@ -998,7 +998,7 @@ class ValidatorList_test : public beast::unit_test::suite auto const publisherPublic = derivePublicKey(KeyType::ed25519, publisherSecret); auto const pubSigningKeys = randomKeyPair(KeyType::secp256k1); - auto const manifest = beast::detail::base64_encode(makeManifestString ( + auto const manifest = boost::beast::detail::base64_encode(makeManifestString ( publisherPublic, publisherSecret, pubSigningKeys.first, pubSigningKeys.second, 1)); diff --git a/src/test/app/ValidatorSite_test.cpp b/src/test/app/ValidatorSite_test.cpp index 132552647e5..b46ee196d66 100644 --- a/src/test/app/ValidatorSite_test.cpp +++ b/src/test/app/ValidatorSite_test.cpp @@ -17,7 +17,6 @@ */ //============================================================================== -#include #include #include #include @@ -29,6 +28,7 @@ #include #include #include +#include namespace ripple { namespace test { @@ -67,7 +67,7 @@ class ValidatorSite_test : public beast::unit_test::suite Serializer s; st.add(s); - return beast::detail::base64_encode (std::string( + return boost::beast::detail::base64_encode (std::string( static_cast (s.data()), s.size())); } diff --git a/src/test/consensus/LedgerTiming_test.cpp b/src/test/consensus/LedgerTiming_test.cpp index 8c036ab9d90..a43c3858546 100644 --- a/src/test/consensus/LedgerTiming_test.cpp +++ b/src/test/consensus/LedgerTiming_test.cpp @@ -127,4 +127,4 @@ class LedgerTiming_test : public beast::unit_test::suite BEAST_DEFINE_TESTSUITE(LedgerTiming, consensus, ripple); } // test -} // ripple \ No newline at end of file +} // ripple diff --git a/src/test/jtx/Env.h b/src/test/jtx/Env.h index fd7c883a7d8..66ba9e9b7a2 100644 --- a/src/test/jtx/Env.h +++ b/src/test/jtx/Env.h @@ -44,7 +44,7 @@ #include #include #include -#include +#include #include #include #include @@ -711,7 +711,7 @@ class Env FN const&... fN) { maybe_invoke(stx, f, - beast::detail::is_invocable()); invoke(stx, fN...); } @@ -745,7 +745,7 @@ class Env FN const&... fN) { maybe_invoke(jt, f, - beast::detail::is_invocable()); invoke(jt, fN...); } diff --git a/src/test/jtx/TrustedPublisherServer.h b/src/test/jtx/TrustedPublisherServer.h index 4cf67a72192..3288127f75f 100644 --- a/src/test/jtx/TrustedPublisherServer.h +++ b/src/test/jtx/TrustedPublisherServer.h @@ -19,14 +19,13 @@ #ifndef RIPPLE_TEST_TRUSTED_PUBLISHER_SERVER_H_INCLUDED #define RIPPLE_TEST_TRUSTED_PUBLISHER_SERVER_H_INCLUDED -#include #include #include #include #include #include -#include -#include +#include +#include namespace ripple { namespace test { @@ -37,8 +36,8 @@ class TrustedPublisherServer using address_type = boost::asio::ip::address; using socket_type = boost::asio::ip::tcp::socket; - using req_type = beast::http::request; - using resp_type = beast::http::response; + using req_type = boost::beast::http::request; + using resp_type = boost::beast::http::response; using error_code = boost::system::error_code; socket_type sock_; @@ -78,7 +77,7 @@ class TrustedPublisherServer } data.pop_back(); data += "]}"; - std::string blob = beast::detail::base64_encode(data); + std::string blob = boost::beast::detail::base64_encode(data); list_ = "{\"blob\":\"" + blob + "\""; @@ -155,35 +154,35 @@ class TrustedPublisherServer do_peer(int id, socket_type&& sock0) { socket_type sock(std::move(sock0)); - beast::multi_buffer sb; + boost::beast::multi_buffer sb; error_code ec; for (;;) { req_type req; - beast::http::read(sock, sb, req, ec); + boost::beast::http::read(sock, sb, req, ec); if (ec) break; auto path = req.target().to_string(); if (path != "/validators") { resp_type res; - res.result(beast::http::status::not_found); - res.version = req.version; + res.result(boost::beast::http::status::not_found); + res.version(req.version()); res.insert("Server", "TrustedPublisherServer"); res.insert("Content-Type", "text/html"); - res.body = "The file '" + path + "' was not found"; + res.body() = "The file '" + path + "' was not found"; res.prepare_payload(); write(sock, res, ec); if (ec) break; } resp_type res; - res.result(beast::http::status::ok); - res.version = req.version; + res.result(boost::beast::http::status::ok); + res.version(req.version()); res.insert("Server", "TrustedPublisherServer"); res.insert("Content-Type", "application/json"); - res.body = list_; + res.body() = list_; try { res.prepare_payload(); @@ -191,11 +190,11 @@ class TrustedPublisherServer catch (std::exception const& e) { res = {}; - res.result(beast::http::status::internal_server_error); - res.version = req.version; + res.result(boost::beast::http::status::internal_server_error); + res.version(req.version()); res.insert("Server", "TrustedPublisherServer"); res.insert("Content-Type", "text/html"); - res.body = std::string{"An internal error occurred"} + e.what(); + res.body() = std::string{"An internal error occurred"} + e.what(); res.prepare_payload(); } write(sock, res, ec); diff --git a/src/test/jtx/WSClient_test.cpp b/src/test/jtx/WSClient_test.cpp index 910166968c9..049d6e284e9 100644 --- a/src/test/jtx/WSClient_test.cpp +++ b/src/test/jtx/WSClient_test.cpp @@ -21,7 +21,6 @@ #include #include #include -#include namespace ripple { namespace test { diff --git a/src/test/jtx/impl/JSONRPCClient.cpp b/src/test/jtx/impl/JSONRPCClient.cpp index a09fa7af427..b39f80d6fd7 100644 --- a/src/test/jtx/impl/JSONRPCClient.cpp +++ b/src/test/jtx/impl/JSONRPCClient.cpp @@ -22,11 +22,11 @@ #include #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include @@ -74,8 +74,8 @@ class JSONRPCClient : public AbstractClient boost::asio::ip::tcp::endpoint ep_; boost::asio::io_service ios_; boost::asio::ip::tcp::socket stream_; - beast::multi_buffer bin_; - beast::multi_buffer bout_; + boost::beast::multi_buffer bin_; + boost::beast::multi_buffer bout_; unsigned rpc_version_; public: @@ -104,14 +104,14 @@ class JSONRPCClient : public AbstractClient invoke(std::string const& cmd, Json::Value const& params) override { - using namespace beast::http; + using namespace boost::beast::http; using namespace boost::asio; using namespace std::string_literals; request req; - req.method(beast::http::verb::post); + req.method(boost::beast::http::verb::post); req.target("/"); - req.version = 11; + req.version(11); req.insert("Content-Type", "application/json; charset=UTF-8"); req.insert("Host", ep_); { @@ -128,7 +128,7 @@ class JSONRPCClient : public AbstractClient Json::Value& ja = jr[jss::params] = Json::arrayValue; ja.append(params); } - req.body = to_string(jr); + req.body() = to_string(jr); } req.prepare_payload(); write(stream_, req); @@ -138,7 +138,7 @@ class JSONRPCClient : public AbstractClient Json::Reader jr; Json::Value jv; - jr.parse(buffer_string(res.body.data()), jv); + jr.parse(buffer_string(res.body().data()), jv); if(jv["result"].isMember("error")) jv["error"] = jv["result"]["error"]; if(jv["result"].isMember("status")) diff --git a/src/test/jtx/impl/WSClient.cpp b/src/test/jtx/impl/WSClient.cpp index 9f5de744b6c..05468b363ee 100644 --- a/src/test/jtx/impl/WSClient.cpp +++ b/src/test/jtx/impl/WSClient.cpp @@ -24,8 +24,8 @@ #include #include #include -#include -#include +#include +#include #include @@ -93,8 +93,8 @@ class WSClientImpl : public WSClient boost::asio::io_service::strand strand_; std::thread thread_; boost::asio::ip::tcp::socket stream_; - beast::websocket::stream ws_; - beast::multi_buffer rb_; + boost::beast::websocket::stream ws_; + boost::beast::multi_buffer rb_; bool peerClosed_ = false; @@ -110,13 +110,17 @@ class WSClientImpl : public WSClient unsigned rpc_version_; - void cleanup() + void + cleanup() { ios_.post(strand_.wrap([this] { error_code ec; if (!peerClosed_) - ws_.close({}, ec); - stream_.close(ec); + { + ws_.async_close({}, strand_.wrap([&](error_code ec) { + stream_.cancel(ec); + })); + } })); work_ = boost::none; thread_.join(); @@ -174,7 +178,7 @@ class WSClientImpl : public WSClient else jp[jss::command] = cmd; auto const s = to_string(jp); - ws_.write_frame(true, buffer(s)); + ws_.write_some(true, buffer(s)); } auto jv = findMsg(5s, @@ -260,7 +264,7 @@ class WSClientImpl : public WSClient { if(ec) { - if(ec == beast::websocket::error::closed) + if(ec == boost::beast::websocket::error::closed) peerClosed_ = true; return; } diff --git a/src/test/nodestore/import_test.cpp b/src/test/nodestore/import_test.cpp index ad1930f43cb..107d372ed07 100644 --- a/src/test/nodestore/import_test.cpp +++ b/src/test/nodestore/import_test.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include @@ -258,7 +258,7 @@ class progress } }; -std::map +std::map parse_args(std::string const& s) { // '=' @@ -274,7 +274,7 @@ parse_args(std::string const& s) , boost::regex_constants::optimize ); std::map map; + std::string, boost::beast::iless> map; auto const v = beast::rfc2616::split( s.begin(), s.end(), ','); for (auto const& kv : v) diff --git a/src/test/rpc/ValidatorRPC_test.cpp b/src/test/rpc/ValidatorRPC_test.cpp index abffdb3b6b3..008267ff3f1 100644 --- a/src/test/rpc/ValidatorRPC_test.cpp +++ b/src/test/rpc/ValidatorRPC_test.cpp @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include @@ -76,7 +76,7 @@ class ValidatorRPC_test : public beast::unit_test::suite Serializer s; st.add(s); - return beast::detail::base64_encode( + return boost::beast::detail::base64_encode( std::string(static_cast(s.data()), s.size())); } diff --git a/src/test/server/ServerStatus_test.cpp b/src/test/server/ServerStatus_test.cpp index 5904bd06659..6a48d796cdf 100644 --- a/src/test/server/ServerStatus_test.cpp +++ b/src/test/server/ServerStatus_test.cpp @@ -27,10 +27,10 @@ #include #include #include -#include +#include #include -#include -#include +#include +#include #include #include #include @@ -42,7 +42,7 @@ namespace test { class ServerStatus_test : public beast::unit_test::suite, public beast::test::enable_yield_to { - class myFields : public beast::http::fields {}; + class myFields : public boost::beast::http::fields {}; auto makeConfig( std::string const& proto, @@ -88,21 +88,21 @@ class ServerStatus_test : uint16_t port) { using namespace boost::asio; - using namespace beast::http; + using namespace boost::beast::http; request req; req.target("/"); - req.version = 11; + req.version(11); req.insert("Host", host + ":" + std::to_string(port)); req.insert("User-Agent", "test"); - req.method(beast::http::verb::get); + req.method(boost::beast::http::verb::get); req.insert("Upgrade", "websocket"); - beast::websocket::detail::maskgen maskgen; - beast::websocket::detail::sec_ws_key_type key; - beast::websocket::detail::make_sec_ws_key(key, maskgen); + boost::beast::websocket::detail::maskgen maskgen; + boost::beast::websocket::detail::sec_ws_key_type key; + boost::beast::websocket::detail::make_sec_ws_key(key, maskgen); req.insert("Sec-WebSocket-Key", key); req.insert("Sec-WebSocket-Version", "13"); - req.insert(beast::http::field::connection, "upgrade"); + req.insert(boost::beast::http::field::connection, "upgrade"); return req; } @@ -113,24 +113,24 @@ class ServerStatus_test : myFields const& fields) { using namespace boost::asio; - using namespace beast::http; + using namespace boost::beast::http; request req; req.target("/"); - req.version = 11; + req.version(11); for(auto const& f : fields) req.insert(f.name(), f.value()); req.insert("Host", host + ":" + std::to_string(port)); req.insert("User-Agent", "test"); if(body.empty()) { - req.method(beast::http::verb::get); + req.method(boost::beast::http::verb::get); } else { - req.method(beast::http::verb::post); + req.method(boost::beast::http::verb::post); req.insert("Content-Type", "application/json; charset=UTF-8"); - req.body = body; + req.body() = body; } req.prepare_payload(); @@ -140,18 +140,18 @@ class ServerStatus_test : void doRequest( boost::asio::yield_context& yield, - beast::http::request&& req, + boost::beast::http::request&& req, std::string const& host, uint16_t port, bool secure, - beast::http::response& resp, + boost::beast::http::response& resp, boost::system::error_code& ec) { using namespace boost::asio; - using namespace beast::http; + using namespace boost::beast::http; io_service& ios = get_io_service(); ip::tcp::resolver r{ios}; - beast::multi_buffer sb; + boost::beast::multi_buffer sb; auto it = r.async_resolve( @@ -170,7 +170,7 @@ class ServerStatus_test : ss.async_handshake(ssl::stream_base::client, yield[ec]); if(ec) return; - beast::http::async_write(ss, req, yield[ec]); + boost::beast::http::async_write(ss, req, yield[ec]); if(ec) return; async_read(ss, sb, resp, yield[ec]); @@ -183,7 +183,7 @@ class ServerStatus_test : async_connect(sock, it, yield[ec]); if(ec) return; - beast::http::async_write(sock, req, yield[ec]); + boost::beast::http::async_write(sock, req, yield[ec]); if(ec) return; async_read(sock, sb, resp, yield[ec]); @@ -199,7 +199,7 @@ class ServerStatus_test : test::jtx::Env& env, boost::asio::yield_context& yield, bool secure, - beast::http::response& resp, + boost::beast::http::response& resp, boost::system::error_code& ec) { auto const port = env.app().config()["port_ws"]. @@ -222,7 +222,7 @@ class ServerStatus_test : test::jtx::Env& env, boost::asio::yield_context& yield, bool secure, - beast::http::response& resp, + boost::beast::http::response& resp, boost::system::error_code& ec, std::string const& body = "", myFields const& fields = {}) @@ -384,21 +384,21 @@ class ServerStatus_test : //non-secure request { boost::system::error_code ec; - beast::http::response resp; + boost::beast::http::response resp; doWSRequest(env, yield, false, resp, ec); if(! BEAST_EXPECTS(! ec, ec.message())) return; - BEAST_EXPECT(resp.result() == beast::http::status::unauthorized); + BEAST_EXPECT(resp.result() == boost::beast::http::status::unauthorized); } //secure request { boost::system::error_code ec; - beast::http::response resp; + boost::beast::http::response resp; doWSRequest(env, yield, true, resp, ec); if(! BEAST_EXPECTS(! ec, ec.message())) return; - BEAST_EXPECT(resp.result() == beast::http::status::unauthorized); + BEAST_EXPECT(resp.result() == boost::beast::http::status::unauthorized); } } @@ -417,21 +417,21 @@ class ServerStatus_test : //non-secure request { boost::system::error_code ec; - beast::http::response resp; + boost::beast::http::response resp; doHTTPRequest(env, yield, false, resp, ec); if(! BEAST_EXPECTS(! ec, ec.message())) return; - BEAST_EXPECT(resp.result() == beast::http::status::ok); + BEAST_EXPECT(resp.result() == boost::beast::http::status::ok); } //secure request { boost::system::error_code ec; - beast::http::response resp; + boost::beast::http::response resp; doHTTPRequest(env, yield, true, resp, ec); if(! BEAST_EXPECTS(! ec, ec.message())) return; - BEAST_EXPECT(resp.result() == beast::http::status::ok); + BEAST_EXPECT(resp.result() == boost::beast::http::status::ok); } }; @@ -441,7 +441,7 @@ class ServerStatus_test : testcase("Partial WS upgrade request"); using namespace jtx; using namespace boost::asio; - using namespace beast::http; + using namespace boost::beast::http; Env env {*this, envconfig([](std::unique_ptr cfg) { cfg->section("port_ws").set("protocol", "ws2"); @@ -463,7 +463,7 @@ class ServerStatus_test : io_service& ios = get_io_service(); ip::tcp::resolver r{ios}; - beast::multi_buffer sb; + boost::beast::multi_buffer sb; auto it = r.async_resolve( @@ -498,7 +498,7 @@ class ServerStatus_test : using namespace jtx; Env env {*this, makeConfig(server_protocol)}; - beast::http::response resp; + boost::beast::http::response resp; boost::system::error_code ec; if(boost::starts_with(client_protocol, "h")) { @@ -540,23 +540,23 @@ class ServerStatus_test : Json::Value jr; jr[jss::method] = "server_info"; - beast::http::response resp; + boost::beast::http::response resp; boost::system::error_code ec; doHTTPRequest(env, yield, secure, resp, ec, to_string(jr)); - BEAST_EXPECT(resp.result() == beast::http::status::forbidden); + BEAST_EXPECT(resp.result() == boost::beast::http::status::forbidden); myFields auth; auth.insert("Authorization", ""); doHTTPRequest(env, yield, secure, resp, ec, to_string(jr), auth); - BEAST_EXPECT(resp.result() == beast::http::status::forbidden); + BEAST_EXPECT(resp.result() == boost::beast::http::status::forbidden); auth.set("Authorization", "Basic NOT-VALID"); doHTTPRequest(env, yield, secure, resp, ec, to_string(jr), auth); - BEAST_EXPECT(resp.result() == beast::http::status::forbidden); + BEAST_EXPECT(resp.result() == boost::beast::http::status::forbidden); - auth.set("Authorization", "Basic " + beast::detail::base64_encode("me:badpass")); + auth.set("Authorization", "Basic " + boost::beast::detail::base64_encode("me:badpass")); doHTTPRequest(env, yield, secure, resp, ec, to_string(jr), auth); - BEAST_EXPECT(resp.result() == beast::http::status::forbidden); + BEAST_EXPECT(resp.result() == boost::beast::http::status::forbidden); auto const user = env.app().config().section("port_rpc"). get("user").value(); @@ -566,14 +566,14 @@ class ServerStatus_test : // try with the correct user/pass, but not encoded auth.set("Authorization", "Basic " + user + ":" + pass); doHTTPRequest(env, yield, secure, resp, ec, to_string(jr), auth); - BEAST_EXPECT(resp.result() == beast::http::status::forbidden); + BEAST_EXPECT(resp.result() == boost::beast::http::status::forbidden); // finally if we use the correct user/pass encoded, we should get a 200 auth.set("Authorization", "Basic " + - beast::detail::base64_encode(user + ":" + pass)); + boost::beast::detail::base64_encode(user + ":" + pass)); doHTTPRequest(env, yield, secure, resp, ec, to_string(jr), auth); - BEAST_EXPECT(resp.result() == beast::http::status::ok); - BEAST_EXPECT(! resp.body.empty()); + BEAST_EXPECT(resp.result() == boost::beast::http::status::ok); + BEAST_EXPECT(! resp.body().empty()); } void @@ -583,7 +583,7 @@ class ServerStatus_test : using namespace test::jtx; using namespace boost::asio; - using namespace beast::http; + using namespace boost::beast::http; Env env {*this, envconfig([&](std::unique_ptr cfg) { (*cfg)["port_rpc"].set("limit", to_string(limit)); return cfg; @@ -607,7 +607,7 @@ class ServerStatus_test : ip::tcp::resolver::query{ip, to_string(port)}, yield[ec]); BEAST_EXPECT(! ec); - std::vector> clients; + std::vector> clients; int connectionCount {1}; //starts at 1 because the Env already has one //for JSONRPCCLient @@ -620,7 +620,7 @@ class ServerStatus_test : while (connectionCount < testTo) { clients.emplace_back( - std::make_pair(ip::tcp::socket {ios}, beast::multi_buffer{})); + std::make_pair(ip::tcp::socket {ios}, boost::beast::multi_buffer{})); async_connect(clients.back().first, it, yield[ec]); BEAST_EXPECT(! ec); auto req = makeHTTPRequest(ip, port, to_string(jr), {}); @@ -635,7 +635,7 @@ class ServerStatus_test : int readCount = 0; for (auto& c : clients) { - beast::http::response resp; + boost::beast::http::response resp; async_read(c.first, c.second, resp, yield[ec]); ++readCount; // expect the reads to fail for the clients that connected at or @@ -659,11 +659,11 @@ class ServerStatus_test : get("port").value(); auto const ip = env.app().config()["port_ws"]. get("ip").value(); - beast::http::response resp; + boost::beast::http::response resp; boost::system::error_code ec; doRequest( yield, makeWSUpgrade(ip, port), ip, port, true, resp, ec); - BEAST_EXPECT(resp.result() == beast::http::status::switching_protocols); + BEAST_EXPECT(resp.result() == boost::beast::http::status::switching_protocols); BEAST_EXPECT(resp.find("Upgrade") != resp.end() && resp["Upgrade"] == "websocket"); BEAST_EXPECT(resp.find("Connection") != resp.end() && @@ -682,14 +682,14 @@ class ServerStatus_test : get("port").value(); auto const ip = env.app().config()["port_ws"]. get("ip").value(); - beast::http::response resp; + boost::beast::http::response resp; boost::system::error_code ec; // body content is required here to avoid being // detected as a status request doRequest(yield, makeHTTPRequest(ip, port, "foo", {}), ip, port, false, resp, ec); - BEAST_EXPECT(resp.result() == beast::http::status::forbidden); - BEAST_EXPECT(resp.body == "Forbidden\r\n"); + BEAST_EXPECT(resp.result() == boost::beast::http::status::forbidden); + BEAST_EXPECT(resp.body() == "Forbidden\r\n"); } void @@ -699,7 +699,7 @@ class ServerStatus_test : using namespace test::jtx; using namespace boost::asio; - using namespace beast::http; + using namespace boost::beast::http; Env env {*this}; auto const port = env.app().config()["port_ws"]. @@ -722,17 +722,17 @@ class ServerStatus_test : if(! BEAST_EXPECT(! ec)) return; - beast::websocket::stream ws{sock}; + boost::beast::websocket::stream ws{sock}; ws.handshake(ip + ":" + to_string(port), "/"); // helper lambda, used below auto sendAndParse = [&](std::string const& req) -> Json::Value { - ws.async_write_frame(true, buffer(req), yield[ec]); + ws.async_write_some(true, buffer(req), yield[ec]); if(! BEAST_EXPECT(! ec)) return Json::objectValue; - beast::multi_buffer sb; + boost::beast::multi_buffer sb; ws.async_read(sb, yield[ec]); if(! BEAST_EXPECT(! ec)) return Json::objectValue; @@ -741,7 +741,7 @@ class ServerStatus_test : Json::Reader jr; if(! BEAST_EXPECT(jr.parse( boost::lexical_cast( - beast::buffers(sb.data())), resp))) + boost::beast::buffers(sb.data())), resp))) return Json::objectValue; sb.consume(sb.size()); return resp; @@ -783,7 +783,7 @@ class ServerStatus_test : testcase("Status request over WS and RPC with/without Amendment Block"); using namespace jtx; using namespace boost::asio; - using namespace beast::http; + using namespace boost::beast::http; Env env {*this, validator( envconfig([](std::unique_ptr cfg) { cfg->section("port_rpc").set("protocol", "http"); @@ -824,9 +824,9 @@ class ServerStatus_test : if(! BEAST_EXPECTS(! ec, ec.message())) return; - BEAST_EXPECT(resp.result() == beast::http::status::ok); + BEAST_EXPECT(resp.result() == boost::beast::http::status::ok); BEAST_EXPECT( - resp.body.find("connectivity is working.") != std::string::npos); + resp.body().find("connectivity is working.") != std::string::npos); // mark the Network as Amendment Blocked, but still won't fail until // ELB is enabled (next step) @@ -856,9 +856,9 @@ class ServerStatus_test : if(! BEAST_EXPECTS(! ec, ec.message())) return; - BEAST_EXPECT(resp.result() == beast::http::status::ok); + BEAST_EXPECT(resp.result() == boost::beast::http::status::ok); BEAST_EXPECT( - resp.body.find("connectivity is working.") != std::string::npos); + resp.body().find("connectivity is working.") != std::string::npos); env.app().config().ELB_SUPPORT = true; @@ -873,11 +873,11 @@ class ServerStatus_test : if(! BEAST_EXPECTS(! ec, ec.message())) return; - BEAST_EXPECT(resp.result() == beast::http::status::internal_server_error); + BEAST_EXPECT(resp.result() == boost::beast::http::status::internal_server_error); BEAST_EXPECT( - resp.body.find("cannot accept clients:") != std::string::npos); + resp.body().find("cannot accept clients:") != std::string::npos); BEAST_EXPECT( - resp.body.find("Server version too old") != std::string::npos); + resp.body().find("Server version too old") != std::string::npos); } void @@ -890,53 +890,53 @@ class ServerStatus_test : boost::system::error_code ec; { - beast::http::response resp; + boost::beast::http::response resp; doHTTPRequest(env, yield, false, resp, ec, "{}"); - BEAST_EXPECT(resp.result() == beast::http::status::bad_request); - BEAST_EXPECT(resp.body == "Unable to parse request\r\n"); + BEAST_EXPECT(resp.result() == boost::beast::http::status::bad_request); + BEAST_EXPECT(resp.body() == "Unable to parse request\r\n"); } Json::Value jv; { - beast::http::response resp; + boost::beast::http::response resp; jv[jss::method] = Json::nullValue; doHTTPRequest(env, yield, false, resp, ec, to_string(jv)); - BEAST_EXPECT(resp.result() == beast::http::status::bad_request); - BEAST_EXPECT(resp.body == "Null method\r\n"); + BEAST_EXPECT(resp.result() == boost::beast::http::status::bad_request); + BEAST_EXPECT(resp.body() == "Null method\r\n"); } { - beast::http::response resp; + boost::beast::http::response resp; jv[jss::method] = 1; doHTTPRequest(env, yield, false, resp, ec, to_string(jv)); - BEAST_EXPECT(resp.result() == beast::http::status::bad_request); - BEAST_EXPECT(resp.body == "method is not string\r\n"); + BEAST_EXPECT(resp.result() == boost::beast::http::status::bad_request); + BEAST_EXPECT(resp.body() == "method is not string\r\n"); } { - beast::http::response resp; + boost::beast::http::response resp; jv[jss::method] = ""; doHTTPRequest(env, yield, false, resp, ec, to_string(jv)); - BEAST_EXPECT(resp.result() == beast::http::status::bad_request); - BEAST_EXPECT(resp.body == "method is empty\r\n"); + BEAST_EXPECT(resp.result() == boost::beast::http::status::bad_request); + BEAST_EXPECT(resp.body() == "method is empty\r\n"); } { - beast::http::response resp; + boost::beast::http::response resp; jv[jss::method] = "some_method"; jv[jss::params] = "params"; doHTTPRequest(env, yield, false, resp, ec, to_string(jv)); - BEAST_EXPECT(resp.result() == beast::http::status::bad_request); - BEAST_EXPECT(resp.body == "params unparseable\r\n"); + BEAST_EXPECT(resp.result() == boost::beast::http::status::bad_request); + BEAST_EXPECT(resp.body() == "params unparseable\r\n"); } { - beast::http::response resp; + boost::beast::http::response resp; jv[jss::params] = Json::arrayValue; jv[jss::params][0u] = "not an object"; doHTTPRequest(env, yield, false, resp, ec, to_string(jv)); - BEAST_EXPECT(resp.result() == beast::http::status::bad_request); - BEAST_EXPECT(resp.body == "params unparseable\r\n"); + BEAST_EXPECT(resp.result() == boost::beast::http::status::bad_request); + BEAST_EXPECT(resp.body() == "params unparseable\r\n"); } } @@ -954,12 +954,12 @@ class ServerStatus_test : //raise the fee so that the server is considered overloaded env.app().getFeeTrack().raiseLocalFee(); - beast::http::response resp; + boost::beast::http::response resp; boost::system::error_code ec; doHTTPRequest(env, yield, false, resp, ec); - BEAST_EXPECT(resp.result() == beast::http::status::internal_server_error); + BEAST_EXPECT(resp.result() == boost::beast::http::status::internal_server_error); std::regex body {"Server cannot accept clients"}; - BEAST_EXPECT(std::regex_search(resp.body, body)); + BEAST_EXPECT(std::regex_search(resp.body(), body)); } public: diff --git a/src/test/unit_test/multi_runner.h b/src/test/unit_test/multi_runner.h index dc21e0e1baa..8e4f1a2082d 100644 --- a/src/test/unit_test/multi_runner.h +++ b/src/test/unit_test/multi_runner.h @@ -20,7 +20,7 @@ #ifndef TEST_UNIT_TEST_MULTI_RUNNER_H #define TEST_UNIT_TEST_MULTI_RUNNER_H -#include +#include #include #include @@ -78,7 +78,7 @@ struct suite_results struct results { - using static_string = beast::static_string<256>; + using static_string = boost::beast::static_string<256>; // results may be stored in shared memory. Use `static_string` to ensure // pointers from different memory spaces do not co-mingle using run_time = std::pair;