diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 08:52:01 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 08:52:01 +0000 |
commit | 42f47327da6a208ac3cd1f9bca07fc506ed51a63 (patch) | |
tree | e06c5e993e0d0b618f616280b372506b1f0f8419 | |
parent | Adding debian version 1.59.0-1. (diff) | |
download | nghttp2-42f47327da6a208ac3cd1f9bca07fc506ed51a63.tar.xz nghttp2-42f47327da6a208ac3cd1f9bca07fc506ed51a63.zip |
Merging upstream version 1.60.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
169 files changed, 11333 insertions, 8675 deletions
diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 8c139c7..9cb65ba 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -4,3 +4,7 @@ updates: directory: "/" schedule: interval: "weekly" +- package-ecosystem: "gomod" + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 51dcdfe..7cfb224 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,11 +7,11 @@ permissions: read-all env: LIBBPF_VERSION: v1.3.0 OPENSSL1_VERSION: 1_1_1w+quic - OPENSSL3_VERSION: 3.1.4+quic - BORINGSSL_VERSION: f42be90d665b6a376177648ccbb76fbbd6497c13 - AWSLC_VERSION: v1.20.0 - NGHTTP3_VERSION: v1.1.0 - NGTCP2_VERSION: v1.2.0 + OPENSSL3_VERSION: 3.1.5+quic + BORINGSSL_VERSION: 8e6a26d128484b886e6dcbfa558b993d38950bb5 + AWSLC_VERSION: v1.21.0 + NGHTTP3_VERSION: v1.2.0 + NGTCP2_VERSION: v1.3.0 jobs: build-cache: @@ -25,26 +25,26 @@ jobs: - uses: actions/checkout@v4 - name: Restore libbpf cache id: cache-libbpf - uses: actions/cache@v3 + uses: actions/cache@v4 if: runner.os == 'Linux' with: path: libbpf/build key: ${{ runner.os }}-libbpf-${{ env.LIBBPF_VERSION }} - name: Restore OpenSSL v1.1.1 cache id: cache-openssl1 - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: openssl1/build key: ${{ runner.os }}-openssl-${{ env.OPENSSL1_VERSION }} - name: Restore OpenSSL v3.x cache id: cache-openssl3 - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: openssl3/build key: ${{ runner.os }}-openssl-${{ env.OPENSSL3_VERSION }} - name: Restore BoringSSL cache id: cache-boringssl - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | boringssl/build/crypto/libcrypto.a @@ -53,7 +53,7 @@ jobs: key: ${{ runner.os }}-boringssl-${{ env.BORINGSSL_VERSION }} - name: Restore aws-lc cache id: cache-awslc - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | aws-lc/build/crypto/libcrypto.a @@ -62,19 +62,19 @@ jobs: key: ${{ runner.os }}-awslc-${{ env.AWSLC_VERSION }} - name: Restore nghttp3 cache id: cache-nghttp3 - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: nghttp3/build key: ${{ runner.os }}-nghttp3-${{ env.NGHTTP3_VERSION }} - name: Restore ngtcp2 + quictls/openssl v1.1.1 cache id: cache-ngtcp2-openssl1 - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ngtcp2-openssl1/build key: ${{ runner.os }}-ngtcp2-${{ env.NGTCP2_VERSION }}-openssl-${{ env.OPENSSL1_VERSION }} - name: Restore ngtcp2 + quictls/openssl v3.x cache id: cache-ngtcp2-openssl3 - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ngtcp2-openssl3/build key: ${{ runner.os }}-ngtcp2-${{ env.NGTCP2_VERSION }}-openssl-${{ env.OPENSSL3_VERSION }} @@ -93,6 +93,7 @@ jobs: - name: Linux setup if: runner.os == 'Linux' && steps.settings.outputs.needs-build == 'true' run: | + sudo apt-get update sudo apt-get install \ g++-12 \ clang-15 \ @@ -137,8 +138,11 @@ jobs: - name: Build BoringSSL if: steps.cache-boringssl.outputs.cache-hit != 'true' run: | - git clone https://boringssl.googlesource.com/boringssl + mkdir boringssl cd boringssl + git init + git remote add origin https://boringssl.googlesource.com/boringssl + git fetch origin --depth 1 ${{ env.BORINGSSL_VERSION }} git checkout ${{ env.BORINGSSL_VERSION }} mkdir build cd build @@ -156,6 +160,7 @@ jobs: run: | git clone --depth 1 -b ${{ env.NGHTTP3_VERSION}} https://github.com/ngtcp2/nghttp3 cd nghttp3 + git submodule update --init --depth 1 autoreconf -i ./configure --prefix=$PWD/build --enable-lib-only make -j"$(nproc 2> /dev/null || sysctl -n hw.ncpu)" check @@ -165,6 +170,7 @@ jobs: run: | git clone --depth 1 -b ${{ env.NGTCP2_VERSION }} https://github.com/ngtcp2/ngtcp2 ngtcp2-openssl1 cd ngtcp2-openssl1 + git submodule update --init --depth 1 autoreconf -i ./configure --prefix=$PWD/build --enable-lib-only \ PKG_CONFIG_PATH="../openssl1/build/lib/pkgconfig" \ @@ -178,6 +184,7 @@ jobs: run: | git clone --depth 1 -b ${{ env.NGTCP2_VERSION }} https://github.com/ngtcp2/ngtcp2 ngtcp2-openssl3 cd ngtcp2-openssl3 + git submodule update --init --depth 1 autoreconf -i ./configure --prefix=$PWD/build --enable-lib-only \ PKG_CONFIG_PATH="../openssl3/build/lib/pkgconfig" \ @@ -228,6 +235,7 @@ jobs: - name: Linux setup if: runner.os == 'Linux' run: | + sudo apt-get update sudo apt-get install \ g++-12 \ clang-15 \ @@ -237,7 +245,6 @@ jobs: libtool \ pkg-config \ zlib1g-dev \ - libcunit1-dev \ libssl-dev \ libxml2-dev \ libev-dev \ @@ -246,6 +253,7 @@ jobs: libjemalloc-dev \ libc-ares-dev \ libelf-dev \ + libbrotli-dev \ cmake \ cmake-data echo 'CPPFLAGS=-fsanitize=address,undefined -fno-sanitize-recover=undefined -g' >> $GITHUB_ENV @@ -257,8 +265,8 @@ jobs: libev \ libevent \ c-ares \ - cunit \ libressl \ + brotli \ autoconf \ automake \ pkg-config \ @@ -285,7 +293,7 @@ jobs: echo 'CC=gcc' >> $GITHUB_ENV echo 'CXX=g++' >> $GITHUB_ENV - name: Restore libbpf cache - uses: actions/cache/restore@v3 + uses: actions/cache/restore@v4 if: matrix.http3 == 'http3' && matrix.compiler == 'clang' && runner.os == 'Linux' with: path: libbpf/build @@ -302,21 +310,21 @@ jobs: echo 'EXTRA_AUTOTOOLS_OPTS='"$EXTRA_AUTOTOOLS_OPTS" >> $GITHUB_ENV echo 'EXTRA_CMAKE_OPTS='"$EXTRA_CMAKE_OPTS" >> $GITHUB_ENV - name: Restore quictls/openssl v1.1.1 cache - uses: actions/cache/restore@v3 + uses: actions/cache/restore@v4 if: matrix.http3 == 'http3' && matrix.openssl == 'openssl1' with: path: openssl1/build key: ${{ runner.os }}-openssl-${{ env.OPENSSL1_VERSION }} fail-on-cache-miss: true - name: Restore quictls/openssl v3.x cache - uses: actions/cache/restore@v3 + uses: actions/cache/restore@v4 if: matrix.http3 == 'http3' && matrix.openssl == 'openssl3' with: path: openssl3/build key: ${{ runner.os }}-openssl-${{ env.OPENSSL3_VERSION }} fail-on-cache-miss: true - name: Restore BoringSSL cache - uses: actions/cache/restore@v3 + uses: actions/cache/restore@v4 if: matrix.openssl == 'boringssl' with: path: | @@ -326,7 +334,7 @@ jobs: key: ${{ runner.os }}-boringssl-${{ env.BORINGSSL_VERSION }} fail-on-cache-miss: true - name: Restore aws-lc cache - uses: actions/cache/restore@v3 + uses: actions/cache/restore@v4 if: matrix.openssl == 'awslc' with: path: | @@ -364,21 +372,21 @@ jobs: echo 'BORINGSSL_LIBS='"$OPENSSL_LIBS" >> $GITHUB_ENV echo 'EXTRA_AUTOTOOLS_OPTS='"$EXTRA_AUTOTOOLS_OPTS" >> $GITHUB_ENV - name: Restore nghttp3 cache - uses: actions/cache/restore@v3 + uses: actions/cache/restore@v4 if: matrix.http3 == 'http3' with: path: nghttp3/build key: ${{ runner.os }}-nghttp3-${{ env.NGHTTP3_VERSION }} fail-on-cache-miss: true - name: Restore ngtcp2 + quictls/openssl v1.1.1 cache + BoringSSL - uses: actions/cache/restore@v3 + uses: actions/cache/restore@v4 if: matrix.http3 == 'http3' && (matrix.openssl == 'openssl1' || matrix.openssl == 'boringssl') with: path: ngtcp2-openssl1/build key: ${{ runner.os }}-ngtcp2-${{ env.NGTCP2_VERSION }}-openssl-${{ env.OPENSSL1_VERSION }} fail-on-cache-miss: true - name: Restore ngtcp2 + quictls/openssl v3.x cache + aws-lc - uses: actions/cache/restore@v3 + uses: actions/cache/restore@v4 if: matrix.http3 == 'http3' && (matrix.openssl == 'openssl3' || matrix.openssl == 'awslc') with: path: ngtcp2-openssl3/build @@ -398,7 +406,7 @@ jobs: echo 'EXTRA_CMAKE_OPTS='"$EXTRA_CMAKE_OPTS" >> $GITHUB_ENV - name: Setup git submodules run: | - git submodule update --init + git submodule update --init --depth 1 - name: Configure autotools run: | autoreconf -i @@ -430,12 +438,12 @@ jobs: if: matrix.buildtool == 'autotools' && runner.os == 'Linux' run: | make -j"$(nproc)" distcheck \ - DISTCHECK_CONFIGURE_FLAGS="--with-mruby --with-neverbleed --with-libev --enable-werror $EXTRA_AUTOTOOLS_OPTS CPPFLAGS=\"$CPPFLAGS\" LDFLAGS=\"$LDFLAGS\"" + DISTCHECK_CONFIGURE_FLAGS="--with-mruby --with-neverbleed --with-libev --with-libbrotlienc --with-libbrotlidec --enable-werror $EXTRA_AUTOTOOLS_OPTS CPPFLAGS=\"$CPPFLAGS\" LDFLAGS=\"$LDFLAGS\"" - name: Build nghttp2 with autotools (MacOS) if: matrix.buildtool == 'autotools' && runner.os == 'macOS' run: | make -j"$(sysctl -n hw.ncpu)" distcheck \ - DISTCHECK_CONFIGURE_FLAGS="--with-mruby --with-libev --enable-werror $EXTRA_AUTOTOOLS_OPTS CPPFLAGS=\"$CPPFLAGS\" LDFLAGS=\"$LDFLAGS\"" + DISTCHECK_CONFIGURE_FLAGS="--with-mruby --with-libev --with-libbrotlienc --with-libbrotlidec --enable-werror $EXTRA_AUTOTOOLS_OPTS CPPFLAGS=\"$CPPFLAGS\" LDFLAGS=\"$LDFLAGS\"" - name: Build nghttp2 with cmake if: matrix.buildtool == 'cmake' run: | @@ -478,20 +486,12 @@ jobs: libtool \ pkg-config \ wine - - name: Build CUnit - run: | - curl -LO https://jaist.dl.sourceforge.net/project/cunit/CUnit/2.1-3/CUnit-2.1-3.tar.bz2 - tar xf CUnit-2.1-3.tar.bz2 - cd CUnit-2.1-3 - ./bootstrap - ./configure --disable-shared --host="$HOST" --prefix="$PWD/build" - make -j$(nproc) install - name: Configure autotools run: | + git submodule update --init --depth 1 autoreconf -i && \ - ./configure --enable-werror --enable-lib-only --with-cunit \ - --host="$HOST" PKG_CONFIG_PATH="$PWD/CUnit-2.1-3/build/lib/pkgconfig" \ - CFLAGS="-g -O2 -D_WIN32_WINNT=0x0600" + ./configure --enable-werror --enable-lib-only --host="$HOST" \ + CFLAGS="-g -O2 -D_WIN32_WINNT=0x0600" LIBS="-pthread" - name: Build nghttp2 run: | make -j$(nproc) @@ -499,6 +499,7 @@ jobs: - name: Run tests if: matrix.host == 'x86_64-w64-mingw32' run: | + export WINEPATH=/usr/x86_64-w64-mingw32/lib cd tests wine main.exe @@ -516,11 +517,10 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: microsoft/setup-msbuild@v1 - - run: | - vcpkg --triplet=${{ matrix.arch }}-windows install cunit + - uses: microsoft/setup-msbuild@v2 - name: Configure cmake run: | + git submodule update --init --depth 1 mkdir build cd build cmake -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_GENERATOR_PLATFORM=${{ matrix.platform }} -DVCPKG_TARGET_TRIPLET=${{ matrix.arch}}-windows .. diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml new file mode 100644 index 0000000..7945573 --- /dev/null +++ b/.github/workflows/docker.yaml @@ -0,0 +1,24 @@ +name: docker-build + +on: + push: + paths: + - docker/Dockerfile + branches: + - '**' + +permissions: read-all + +jobs: + build: + runs-on: ubuntu-22.04 + + steps: + - uses: actions/checkout@v4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Build + uses: docker/build-push-action@v5 + with: + context: docker + build-args: NGHTTP2_BRANCH=${{ github.ref_name }} @@ -42,6 +42,7 @@ rules.ninja lib*.so lib*.so.* lib*.a + # generated by "make test" with cmake Testing/ @@ -54,3 +55,10 @@ _VC_ROOT/ .depend.MSVC *.pyd *.egg-info/ + +# Build Directories +build/ + +# IDEs +cmake-* +.idea/ diff --git a/.gitmodules b/.gitmodules index 393c808..fe2dd42 100644 --- a/.gitmodules +++ b/.gitmodules @@ -5,3 +5,6 @@ path = third-party/neverbleed url = https://github.com/tatsuhiro-t/neverbleed.git branch = nghttp2 +[submodule "tests/munit"] + path = tests/munit + url = https://github.com/ngtcp2/munit @@ -112,6 +112,7 @@ Rudi Heitbaum Ryo Ota Scott Mitchell Sebastiaan Deckers +Sergey Fedorov Shelley Vohr Simon Frankenberger Simone Basso diff --git a/CMakeLists.txt b/CMakeLists.txt index 161a7ee..58ae48c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,15 +22,15 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.14) # XXX using 1.8.90 instead of 1.9.0-DEV -project(nghttp2 VERSION 1.59.0) +project(nghttp2 VERSION 1.60.0) # See versioning rule: # https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html -set(LT_CURRENT 40) +set(LT_CURRENT 41) set(LT_REVISION 0) -set(LT_AGE 26) +set(LT_AGE 27) set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) include(Version) @@ -60,6 +60,8 @@ if(NOT ENABLE_LIB_ONLY) find_package(Libev 4.11) find_package(Libcares 1.7.5) find_package(ZLIB 1.2.3) + find_package(Libbrotlienc 1.0.9) + find_package(Libbrotlidec 1.0.9) endif() find_package(OpenSSL 1.1.1) @@ -165,12 +167,8 @@ endif() # XXX shouldn't ${CMAKE_DL_LIBS} be appended to OPENSSL_LIBRARIES instead of # APP_LIBRARIES if it is really specific to OpenSSL? -find_package(CUnit 2.1) enable_testing() -set(HAVE_CUNIT ${CUNIT_FOUND}) -if(HAVE_CUNIT) - add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}) -endif() +add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}) # openssl (for src) include(CheckSymbolExists) @@ -222,6 +220,13 @@ endif() # jemalloc set(HAVE_JEMALLOC ${JEMALLOC_FOUND}) +# libbrotli (for src) +set(HAVE_LIBBROTLIENC ${LIBBROTLIENC_FOUND}) +set(HAVE_LIBBROTLIDEC ${LIBBROTLIDEC_FOUND}) +if(LIBBROTLIENC_FOUND AND LIBBROTLIDEC_FOUND) + set(HAVE_LIBBROTLI 1) +endif() + # libbpf (for bpf) set(HAVE_LIBBPF ${LIBBPF_FOUND}) if(LIBBPF_FOUND) @@ -458,7 +463,6 @@ message(STATUS "summary of build options: Python: ${Python3_EXECUTABLE} Python3_VERSION: ${Python3_VERSION} Test: - CUnit: ${HAVE_CUNIT} (LIBS='${CUNIT_LIBRARIES}') Failmalloc: ${ENABLE_FAILMALLOC} Libs: OpenSSL: ${HAVE_OPENSSL} (LIBS='${OPENSSL_LIBRARIES}') @@ -474,6 +478,8 @@ message(STATUS "summary of build options: Jemalloc: ${HAVE_JEMALLOC} (LIBS='${JEMALLOC_LIBRARIES}') Zlib: ${HAVE_ZLIB} (LIBS='${ZLIB_LIBRARIES}') Systemd: ${HAVE_SYSTEMD} (LIBS='${SYSTEMD_LIBRARIES}') + Libbrotlienc: ${HAVE_LIBBROTLIENC} (LIBS='${LIBBROTLIENC_LIBRARIES}') + Libbrotlidec: ${HAVE_LIBBROTLIDEC} (LIBS='${LIBBROTLIDEC_LIBRARIES}') Third-party: http-parser: ${ENABLE_THIRD_PARTY} MRuby: ${HAVE_MRUBY} diff --git a/CMakeOptions.txt b/CMakeOptions.txt index 238d5b1..663d8e7 100644 --- a/CMakeOptions.txt +++ b/CMakeOptions.txt @@ -11,8 +11,8 @@ option(ENABLE_EXAMPLES "Build examples" ${ENABLE_EXAMPLES_DEFAULT}) option(ENABLE_FAILMALLOC "Build failmalloc test program" ON) option(ENABLE_LIB_ONLY "Build libnghttp2 only. This is a short hand for -DENABLE_APP=0 -DENABLE_EXAMPLES=0 -DENABLE_HPACK_TOOLS=0") -option(ENABLE_STATIC_LIB "Build libnghttp2 in static mode also") -option(ENABLE_SHARED_LIB "Build libnghttp2 as a shared library" ON) +option(BUILD_SHARED_LIBS "Build libnghttp2 as a shared library" ON) +option(BUILD_STATIC_LIBS "Build libnghttp2 in static mode also" OFF) option(ENABLE_STATIC_CRT "Build libnghttp2 against the MS LIBCMT[d]") option(ENABLE_HTTP3 "Enable HTTP/3 support" OFF) option(ENABLE_DOC "Build documentation" ON) diff --git a/Makefile.am b/Makefile.am index 683b989..684ac17 100644 --- a/Makefile.am +++ b/Makefile.am @@ -35,7 +35,6 @@ EXTRA_DIST = nghttpx.conf.sample proxy.pac.sample android-config android-env \ cmake/ExtractValidFlags.cmake \ cmake/FindJemalloc.cmake \ cmake/FindLibev.cmake \ - cmake/FindCUnit.cmake \ cmake/Version.cmake \ cmake/FindLibevent.cmake \ cmake/FindJansson.cmake \ @@ -45,6 +44,8 @@ EXTRA_DIST = nghttpx.conf.sample proxy.pac.sample android-config android-env \ cmake/FindLibnghttp3.cmake \ cmake/FindLibngtcp2.cmake \ cmake/FindLibngtcp2_crypto_quictls.cmake \ + cmake/FindLibbrotlienc.cmake \ + cmake/FindLibbrotlidec.cmake \ cmake/PickyWarningsC.cmake \ cmake/PickyWarningsCXX.cmake @@ -48,11 +48,6 @@ The following package is required to build the libnghttp2 library: * pkg-config >= 0.20 -To build and run the unit test programs, the following package is -required: - -* cunit >= 2.1 - To build the documentation, you need to install: * sphinx (http://sphinx-doc.org/) @@ -100,6 +95,11 @@ To mitigate heap fragmentation in long running server programs Alpine Linux currently does not support malloc replacement due to musl limitations. See details in issue `#762 <https://github.com/nghttp2/nghttp2/issues/762>`_. +For BoringSSL or aws-lc build, to enable :rfc:`8879` TLS Certificate +Compression in applications, the following library is required: + +* libbrotli-dev >= 1.0.9 + To enable mruby support for nghttpx, `mruby <https://github.com/mruby/mruby>`_ is required. We need to build mruby with C++ ABI explicitly turned on, and probably need other @@ -127,7 +127,7 @@ following libraries are required: <https://github.com/quictls/openssl/tree/OpenSSL_1_1_1w+quic>`_; or LibreSSL (does not support 0RTT); or aws-lc; or `BoringSSL <https://boringssl.googlesource.com/boringssl/>`_ (commit - f42be90d665b6a376177648ccbb76fbbd6497c13) + 8e6a26d128484b886e6dcbfa558b993d38950bb5) * `ngtcp2 <https://github.com/ngtcp2/ngtcp2>`_ >= 1.0.0 * `nghttp3 <https://github.com/ngtcp2/nghttp3>`_ >= 1.1.0 @@ -205,7 +205,7 @@ required packages: sudo apt-get install g++ clang make binutils autoconf automake \ autotools-dev libtool pkg-config \ - zlib1g-dev libcunit1-dev libssl-dev libxml2-dev libev-dev \ + zlib1g-dev libssl-dev libxml2-dev libev-dev \ libevent-dev libjansson-dev \ libc-ares-dev libjemalloc-dev libsystemd-dev \ ruby-dev bison libelf-dev @@ -337,23 +337,24 @@ connections alive during reload. The detailed steps to build HTTP/3 enabled h2load and nghttpx follow. -Build custom OpenSSL: +Build aws-lc: .. code-block:: text - $ git clone --depth 1 -b OpenSSL_1_1_1w+quic https://github.com/quictls/openssl - $ cd openssl - $ ./config --prefix=$PWD/build --openssldir=/etc/ssl - $ make -j$(nproc) - $ make install_sw + $ git clone --depth 1 -b v1.21.0 https://github.com/aws/aws-lc + $ cd aws-lc + $ cmake -B build -DDISABLE_GO=ON --install-prefix=$PWD/opt + $ make -j$(nproc) -C build + $ cmake --install build $ cd .. Build nghttp3: .. code-block:: text - $ git clone --depth 1 -b v1.1.0 https://github.com/ngtcp2/nghttp3 + $ git clone --depth 1 -b v1.2.0 https://github.com/ngtcp2/nghttp3 $ cd nghttp3 + $ git submodule update --init --depth 1 $ autoreconf -i $ ./configure --prefix=$PWD/build --enable-lib-only $ make -j$(nproc) @@ -364,11 +365,13 @@ Build ngtcp2: .. code-block:: text - $ git clone --depth 1 -b v1.2.0 https://github.com/ngtcp2/ngtcp2 + $ git clone --depth 1 -b v1.3.0 https://github.com/ngtcp2/ngtcp2 $ cd ngtcp2 + $ git submodule update --init --depth 1 $ autoreconf -i - $ ./configure --prefix=$PWD/build --enable-lib-only \ - PKG_CONFIG_PATH="$PWD/../openssl/build/lib/pkgconfig" + $ ./configure --prefix=$PWD/build --enable-lib-only --with-boringssl \ + BORINGSSL_CFLAGS="-I$PWD/../aws-lc/opt/include" \ + BORINGSSL_LIBS="-L$PWD/../aws-lc/opt/lib -lssl -lcrypto" $ make -j$(nproc) $ make install $ cd .. @@ -391,10 +394,10 @@ Build nghttp2: $ cd nghttp2 $ git submodule update --init $ autoreconf -i - $ ./configure --with-mruby --with-neverbleed --enable-http3 --with-libbpf \ - CC=clang-14 CXX=clang++-14 \ - PKG_CONFIG_PATH="$PWD/../openssl/build/lib/pkgconfig:$PWD/../nghttp3/build/lib/pkgconfig:$PWD/../ngtcp2/build/lib/pkgconfig:$PWD/../libbpf/build/lib64/pkgconfig" \ - LDFLAGS="$LDFLAGS -Wl,-rpath,$PWD/../openssl/build/lib -Wl,-rpath,$PWD/../libbpf/build/lib64" + $ ./configure --with-mruby --enable-http3 --with-libbpf \ + CC=clang-15 CXX=clang++-15 \ + PKG_CONFIG_PATH="$PWD/../aws-lc/opt/lib/pkgconfig:$PWD/../nghttp3/build/lib/pkgconfig:$PWD/../ngtcp2/build/lib/pkgconfig:$PWD/../libbpf/build/lib64/pkgconfig" \ + LDFLAGS="$LDFLAGS -Wl,-rpath,$PWD/../aws-lc/opt/lib -Wl,-rpath,$PWD/../libbpf/build/lib64" $ make -j$(nproc) The eBPF program ``reuseport_kern.o`` should be found under bpf @@ -479,7 +482,7 @@ Previously nghttp2 library did not send client magic, which is first 24 bytes byte string of client connection preface, and client applications have to send it by themselves. Since v1.0.0, client magic is sent by library via first call of ``nghttp2_session_send()`` -or ``nghttp2_session_mem_send()``. +or ``nghttp2_session_mem_send2()``. The client applications which send client magic must remove the relevant code. @@ -1446,17 +1449,6 @@ See `Contribution Guidelines <https://nghttp2.org/documentation/contribute.html>`_ for more details. -Reporting vulnerability ------------------------ - -If you find a vulnerability in our software, please send the email to -"tatsuhiro.t at gmail dot com" about its details instead of submitting -issues on github issue page. It is a standard practice not to -disclose vulnerability information publicly until a fixed version is -released, or mitigation is worked out. - -In the future, we may setup a dedicated mail address for this purpose. - Versioning ---------- diff --git a/doc/sources/security.rst b/SECURITY.md index 5a8fcd0..b8328a5 100644 --- a/doc/sources/security.rst +++ b/SECURITY.md @@ -1,16 +1,15 @@ -Security Process -================ +# Security Process -If you find a vulnerability in our software, please send the email to -"tatsuhiro.t at gmail dot com" about its details instead of submitting +If you find a vulnerability in our software, please report it via +GitHub "Private vulnerability reporting" feature at +https://github.com/nghttp2/nghttp2/security instead of submitting issues on github issue page. It is a standard practice not to disclose vulnerability information publicly until a fixed version is -released, or mitigation is worked out. In the future, we may setup a -dedicated mail address for this purpose. +released, or mitigation is worked out. If we identify that the reported issue is really a vulnerability, we -open a new security advisory draft using `GitHub security feature -<https://github.com/nghttp2/nghttp2/security>`_ and discuss the +open a new security advisory draft using [GitHub security +feature](https://github.com/nghttp2/nghttp2/security) and discuss the mitigation and bug fixes there. The fixes are committed to the private repository. @@ -21,12 +20,11 @@ We make a new release with the fix at the same time when the vulnerability is disclosed to public. At least 7 days before the public disclosure date, we open a new issue -on `nghttp2 issue tracker -<https://github.com/nghttp2/nghttp2/issues>`_ which notifies that the -upcoming release will have a security fix. The ``SECURITY`` label is -attached to this kind of issue. The issue is not opened if a -vulnerability is already disclosed, and it is publicly known that -nghttp2 is affected by that. +on [nghttp2 issue tracker](https://github.com/nghttp2/nghttp2/issues) +which notifies that the upcoming release will have a security fix. +The `SECURITY` label is attached to this kind of issue. The issue is +not opened if a vulnerability is already disclosed, and it is publicly +known that nghttp2 is affected by that. Before few hours of new release, we merge the fixes to the master branch (and/or a release branch if necessary) and make a new release. diff --git a/bpf/reuseport_kern.c b/bpf/reuseport_kern.c index 74c08c5..a8e65eb 100644 --- a/bpf/reuseport_kern.c +++ b/bpf/reuseport_kern.c @@ -42,11 +42,6 @@ License is Public Domain. Commit hash: 12e7744b4919e9d55de75b7ab566326a1c8e7a67 */ -#define AES_BLOCKLEN \ - 16 /* Block length in bytes - AES is 128b block \ - only */ - -#define AES_KEYLEN 16 /* Key length in bytes */ #define AES_keyExpSize 176 struct AES_ctx { @@ -57,7 +52,6 @@ struct AES_ctx { in AES. Value=4 */ #define Nb 4 -#define Nk 4 /* The number of 32 bit words in a key. */ #define Nr 10 /* The number of rounds in AES Cipher. */ /* state - array holding the intermediate results during @@ -68,31 +62,6 @@ typedef __u8 state_t[4][4]; read-only storage instead of RAM The numbers below can be computed dynamically trading ROM for RAM - This can be useful in (embedded) bootloader applications, where ROM is often limited. */ -static const __u8 sbox[256] = { - /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ - 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, - 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, - 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26, - 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, - 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, - 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, - 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed, - 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, - 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, - 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, - 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec, - 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, - 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, - 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, - 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d, - 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, - 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, - 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, - 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11, - 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, - 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, - 0xb0, 0x54, 0xbb, 0x16}; - static const __u8 rsbox[256] = { 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, @@ -117,78 +86,6 @@ static const __u8 rsbox[256] = { 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d}; -/* The round constant word array, Rcon[i], contains the values given - by x to the power (i-1) being powers of x (x is denoted as {02}) in - the field GF(2^8) */ -static const __u8 Rcon[11] = {0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, - 0x20, 0x40, 0x80, 0x1b, 0x36}; - -#define getSBoxValue(num) (sbox[(num)]) - -/* This function produces Nb(Nr+1) round keys. The round keys are used - in each round to decrypt the states. */ -static void KeyExpansion(__u8 *RoundKey, const __u8 *Key) { - unsigned i, j, k; - __u8 tempa[4]; /* Used for the column/row operations */ - - /* The first round key is the key itself. */ - for (i = 0; i < Nk; ++i) { - RoundKey[(i * 4) + 0] = Key[(i * 4) + 0]; - RoundKey[(i * 4) + 1] = Key[(i * 4) + 1]; - RoundKey[(i * 4) + 2] = Key[(i * 4) + 2]; - RoundKey[(i * 4) + 3] = Key[(i * 4) + 3]; - } - - /* All other round keys are found from the previous round keys. */ - for (i = Nk; i < Nb * (Nr + 1); ++i) { - { - k = (i - 1) * 4; - tempa[0] = RoundKey[k + 0]; - tempa[1] = RoundKey[k + 1]; - tempa[2] = RoundKey[k + 2]; - tempa[3] = RoundKey[k + 3]; - } - - if (i % Nk == 0) { - /* This function shifts the 4 bytes in a word to the left once. - [a0,a1,a2,a3] becomes [a1,a2,a3,a0] */ - - /* Function RotWord() */ - { - const __u8 u8tmp = tempa[0]; - tempa[0] = tempa[1]; - tempa[1] = tempa[2]; - tempa[2] = tempa[3]; - tempa[3] = u8tmp; - } - - /* SubWord() is a function that takes a four-byte input word and - applies the S-box to each of the four bytes to produce an - output word. */ - - /* Function Subword() */ - { - tempa[0] = getSBoxValue(tempa[0]); - tempa[1] = getSBoxValue(tempa[1]); - tempa[2] = getSBoxValue(tempa[2]); - tempa[3] = getSBoxValue(tempa[3]); - } - - tempa[0] = tempa[0] ^ Rcon[i / Nk]; - } - j = i * 4; - k = (i - Nk) * 4; - RoundKey[j + 0] = RoundKey[k + 0] ^ tempa[0]; - RoundKey[j + 1] = RoundKey[k + 1] ^ tempa[1]; - RoundKey[j + 2] = RoundKey[k + 2] ^ tempa[2]; - RoundKey[j + 3] = RoundKey[k + 3] ^ tempa[3]; - } -} - -static void AES_init_ctx(struct AES_ctx *ctx, const __u8 *key) { - KeyExpansion(ctx->RoundKey, key); -} - /* This function adds the round key to state. The round key is added to the state by an XOR function. */ static void AddRoundKey(__u8 round, state_t *state, const __u8 *RoundKey) { @@ -439,11 +336,18 @@ struct { struct { __uint(type, BPF_MAP_TYPE_ARRAY); - __uint(max_entries, 3); + __uint(max_entries, 1); __type(key, __u32); __type(value, __u64); } sk_info SEC(".maps"); +struct { + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 1); + __type(key, __u32); + __type(value, struct AES_ctx); +} aes_key SEC(".maps"); + typedef struct quic_hd { __u8 *dcid; __u32 dcidlen; @@ -573,13 +477,12 @@ static __u32 sk_index_from_dcid(const quic_hd *qhd, SEC("sk_reuseport") int select_reuseport(struct sk_reuseport_md *reuse_md) { __u32 sk_index, *psk_index; - __u64 *pnum_socks, *pkey; - __u32 zero = 0, key_high_idx = 1, key_low_idx = 2; + __u64 *pnum_socks; + __u32 zero = 0; int rv; quic_hd qhd; __u8 qpktbuf[6 + MAX_DCIDLEN]; - struct AES_ctx aes_ctx; - __u8 key[AES_KEYLEN]; + struct AES_ctx *aes_ctx; __u8 *cid_prefix; if (bpf_skb_load_bytes(reuse_md, sizeof(struct udphdr), qpktbuf, @@ -592,33 +495,22 @@ int select_reuseport(struct sk_reuseport_md *reuse_md) { return SK_DROP; } - pkey = bpf_map_lookup_elem(&sk_info, &key_high_idx); - if (pkey == NULL) { + aes_ctx = bpf_map_lookup_elem(&aes_key, &zero); + if (aes_ctx == NULL) { return SK_DROP; } - __builtin_memcpy(key, pkey, sizeof(*pkey)); - - pkey = bpf_map_lookup_elem(&sk_info, &key_low_idx); - if (pkey == NULL) { - return SK_DROP; - } - - __builtin_memcpy(key + sizeof(*pkey), pkey, sizeof(*pkey)); - rv = parse_quic(&qhd, qpktbuf, qpktbuf + sizeof(qpktbuf)); if (rv != 0) { return SK_DROP; } - AES_init_ctx(&aes_ctx, key); - switch (qhd.type) { case NGTCP2_PKT_INITIAL: case NGTCP2_PKT_0RTT: if (qhd.dcidlen == SV_DCIDLEN) { cid_prefix = qhd.dcid + CID_PREFIX_OFFSET; - AES_ECB_decrypt(&aes_ctx, cid_prefix); + AES_ECB_decrypt(aes_ctx, cid_prefix); psk_index = bpf_map_lookup_elem(&cid_prefix_map, cid_prefix); if (psk_index != NULL) { @@ -638,7 +530,7 @@ int select_reuseport(struct sk_reuseport_md *reuse_md) { } cid_prefix = qhd.dcid + CID_PREFIX_OFFSET; - AES_ECB_decrypt(&aes_ctx, cid_prefix); + AES_ECB_decrypt(aes_ctx, cid_prefix); psk_index = bpf_map_lookup_elem(&cid_prefix_map, cid_prefix); if (psk_index == NULL) { diff --git a/cmake/FindCUnit.cmake b/cmake/FindCUnit.cmake deleted file mode 100644 index ada87c1..0000000 --- a/cmake/FindCUnit.cmake +++ /dev/null @@ -1,40 +0,0 @@ -# - Try to find cunit -# Once done this will define -# CUNIT_FOUND - System has cunit -# CUNIT_INCLUDE_DIRS - The cunit include directories -# CUNIT_LIBRARIES - The libraries needed to use cunit - -find_package(PkgConfig QUIET) -pkg_check_modules(PC_CUNIT QUIET cunit) - -find_path(CUNIT_INCLUDE_DIR - NAMES CUnit/CUnit.h - HINTS ${PC_CUNIT_INCLUDE_DIRS} -) -find_library(CUNIT_LIBRARY - NAMES cunit - HINTS ${PC_CUNIT_LIBRARY_DIRS} -) - -if(CUNIT_INCLUDE_DIR) - set(_version_regex "^#define[ \t]+CU_VERSION[ \t]+\"([^\"]+)\".*") - file(STRINGS "${CUNIT_INCLUDE_DIR}/CUnit/CUnit.h" - CUNIT_VERSION REGEX "${_version_regex}") - string(REGEX REPLACE "${_version_regex}" "\\1" - CUNIT_VERSION "${CUNIT_VERSION}") - unset(_version_regex) -endif() - -include(FindPackageHandleStandardArgs) -# handle the QUIETLY and REQUIRED arguments and set CUNIT_FOUND to TRUE -# if all listed variables are TRUE and the requested version matches. -find_package_handle_standard_args(CUnit REQUIRED_VARS - CUNIT_LIBRARY CUNIT_INCLUDE_DIR - VERSION_VAR CUNIT_VERSION) - -if(CUNIT_FOUND) - set(CUNIT_LIBRARIES ${CUNIT_LIBRARY}) - set(CUNIT_INCLUDE_DIRS ${CUNIT_INCLUDE_DIR}) -endif() - -mark_as_advanced(CUNIT_INCLUDE_DIR CUNIT_LIBRARY) diff --git a/cmake/FindLibbrotlidec.cmake b/cmake/FindLibbrotlidec.cmake new file mode 100644 index 0000000..59066c6 --- /dev/null +++ b/cmake/FindLibbrotlidec.cmake @@ -0,0 +1,36 @@ +# - Try to find libbrotlidec +# Once done this will define +# LIBBROTLIDEC_FOUND - System has libbrotlidec +# LIBBROTLIDEC_INCLUDE_DIRS - The libbrotlidec include directories +# LIBBROTLIDEC_LIBRARIES - The libraries needed to use libbrotlidec + +find_package(PkgConfig QUIET) +pkg_check_modules(PC_LIBBROTLIDEC QUIET libbrotlidec) + +find_path(LIBBROTLIDEC_INCLUDE_DIR + NAMES brotli/decode.h + HINTS ${PC_LIBBROTLIDEC_INCLUDE_DIRS} +) +find_library(LIBBROTLIDEC_LIBRARY + NAMES brotlidec + HINTS ${PC_LIBBROTLIDEC_LIBRARY_DIRS} +) + +if(PC_LIBBROTLIDEC_FOUND) + set(LIBBROTLIDEC_VERSION ${PC_LIBBROTLIDEC_VERSION}) +endif() + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set LIBBROTLIDEC_FOUND +# to TRUE if all listed variables are TRUE and the requested version +# matches. +find_package_handle_standard_args(Libbrotlidec REQUIRED_VARS + LIBBROTLIDEC_LIBRARY LIBBROTLIDEC_INCLUDE_DIR + VERSION_VAR LIBBROTLIDEC_VERSION) + +if(LIBBROTLIDEC_FOUND) + set(LIBBROTLIDEC_LIBRARIES ${LIBBROTLIDEC_LIBRARY}) + set(LIBBROTLIDEC_INCLUDE_DIRS ${LIBBROTLIDEC_INCLUDE_DIR}) +endif() + +mark_as_advanced(LIBBROTLIDEC_INCLUDE_DIR LIBBROTLIDEC_LIBRARY) diff --git a/cmake/FindLibbrotlienc.cmake b/cmake/FindLibbrotlienc.cmake new file mode 100644 index 0000000..acf6334 --- /dev/null +++ b/cmake/FindLibbrotlienc.cmake @@ -0,0 +1,36 @@ +# - Try to find libbrotlienc +# Once done this will define +# LIBBROTLIENC_FOUND - System has libbrotlienc +# LIBBROTLIENC_INCLUDE_DIRS - The libbrotlienc include directories +# LIBBROTLIENC_LIBRARIES - The libraries needed to use libbrotlienc + +find_package(PkgConfig QUIET) +pkg_check_modules(PC_LIBBROTLIENC QUIET libbrotlienc) + +find_path(LIBBROTLIENC_INCLUDE_DIR + NAMES brotli/encode.h + HINTS ${PC_LIBBROTLIENC_INCLUDE_DIRS} +) +find_library(LIBBROTLIENC_LIBRARY + NAMES brotlienc + HINTS ${PC_LIBBROTLIENC_LIBRARY_DIRS} +) + +if(PC_LIBBROTLIENC_FOUND) + set(LIBBROTLIENC_VERSION ${PC_LIBBROTLIENC_VERSION}) +endif() + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set LIBBROTLIENC_FOUND +# to TRUE if all listed variables are TRUE and the requested version +# matches. +find_package_handle_standard_args(Libbrotlienc REQUIRED_VARS + LIBBROTLIENC_LIBRARY LIBBROTLIENC_INCLUDE_DIR + VERSION_VAR LIBBROTLIENC_VERSION) + +if(LIBBROTLIENC_FOUND) + set(LIBBROTLIENC_LIBRARIES ${LIBBROTLIENC_LIBRARY}) + set(LIBBROTLIENC_INCLUDE_DIRS ${LIBBROTLIENC_INCLUDE_DIR}) +endif() + +mark_as_advanced(LIBBROTLIENC_INCLUDE_DIR LIBBROTLIENC_LIBRARY) diff --git a/cmake/PickyWarningsC.cmake b/cmake/PickyWarningsC.cmake index 50eb789..6a5ee27 100644 --- a/cmake/PickyWarningsC.cmake +++ b/cmake/PickyWarningsC.cmake @@ -85,7 +85,6 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_C_COMPILER_ID MA -Wstrict-prototypes # clang 1.0 gcc 3.3 # -Wswitch-enum # clang 3.0 gcc 4.1 # Not used because this basically disallows default case -Wunreachable-code # clang 3.0 gcc 4.1 - -Wunused-macros # clang 3.0 gcc 4.1 -Wunused-parameter # clang 3.0 gcc 4.1 -Wvla # clang 2.8 gcc 4.3 ) diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in index a011d00..20916ca 100644 --- a/cmakeconfig.h.in +++ b/cmakeconfig.h.in @@ -99,3 +99,6 @@ /* Define to 1 if you have `libev` library. */ #cmakedefine HAVE_LIBEV 1 + +/* Define to 1 if you have `libbrotlienc` and `libbrotlidec` libraries. */ +#cmakedefine HAVE_LIBBROTLI 1 diff --git a/configure.ac b/configure.ac index defc113..0fb1ae4 100644 --- a/configure.ac +++ b/configure.ac @@ -25,7 +25,7 @@ dnl Do not change user variables! dnl https://www.gnu.org/software/automake/manual/html_node/Flag-Variables-Ordering.html AC_PREREQ(2.61) -AC_INIT([nghttp2], [1.59.0], [t-tujikawa@users.sourceforge.net]) +AC_INIT([nghttp2], [1.60.0], [t-tujikawa@users.sourceforge.net]) AC_CONFIG_AUX_DIR([.]) AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_HEADERS([config.h]) @@ -44,9 +44,9 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) dnl See versioning rule: dnl https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html -AC_SUBST(LT_CURRENT, 40) +AC_SUBST(LT_CURRENT, 41) AC_SUBST(LT_REVISION, 0) -AC_SUBST(LT_AGE, 26) +AC_SUBST(LT_AGE, 27) major=`echo $PACKAGE_VERSION |cut -d. -f1 | sed -e "s/[^0-9]//g"` minor=`echo $PACKAGE_VERSION |cut -d. -f2 | sed -e "s/[^0-9]//g"` @@ -137,11 +137,6 @@ AC_ARG_WITH([libev], [Use libev [default=check]])], [request_libev=$withval], [request_libev=check]) -AC_ARG_WITH([cunit], - [AS_HELP_STRING([--with-cunit], - [Use cunit [default=check]])], - [request_cunit=$withval], [request_cunit=check]) - AC_ARG_WITH([jemalloc], [AS_HELP_STRING([--with-jemalloc], [Use jemalloc [default=check]])], @@ -177,6 +172,16 @@ AC_ARG_WITH([libbpf], [Use libbpf [default=no]])], [request_libbpf=$withval], [request_libbpf=no]) +AC_ARG_WITH([libbrotlienc], + [AS_HELP_STRING([--with-libbrotlienc], + [Use libbrotlienc [default=no]])], + [request_libbrotlienc=$withval], [request_libbrotlienc=no]) + +AC_ARG_WITH([libbrotlidec], + [AS_HELP_STRING([--with-libbrotlidec], + [Use libbrotlidec [default=no]])], + [request_libbrotlidec=$withval], [request_libbrotlidec=no]) + dnl Define variables AC_ARG_VAR([LIBEV_CFLAGS], [C compiler flags for libev, skipping any checks]) AC_ARG_VAR([LIBEV_LIBS], [linker flags for libev, skipping any checks]) @@ -377,43 +382,6 @@ case "${host_os}" in ;; esac -# cunit -have_cunit=no -if test "x${request_cunit}" != "xno"; then - PKG_CHECK_MODULES([CUNIT], [cunit >= 2.1], [have_cunit=yes], [have_cunit=no]) - # If pkg-config does not find cunit, check it using AC_CHECK_LIB. We - # do this because Debian (Ubuntu) lacks pkg-config file for cunit. - if test "x${have_cunit}" = "xno"; then - AC_MSG_WARN([${CUNIT_PKG_ERRORS}]) - AC_CHECK_LIB([cunit], [CU_initialize_registry], - [have_cunit=yes], [have_cunit=no]) - if test "x${have_cunit}" = "xyes"; then - CUNIT_LIBS="-lcunit" - CUNIT_CFLAGS="" - AC_SUBST([CUNIT_LIBS]) - AC_SUBST([CUNIT_CFLAGS]) - fi - fi - if test "x${have_cunit}" = "xyes"; then - # cunit in Mac OS X requires ncurses. Note that in Mac OS X, test - # program can be built without -lncurses, but it emits runtime - # error. - case "${build}" in - *-apple-darwin*) - CUNIT_LIBS="$CUNIT_LIBS -lncurses" - AC_SUBST([CUNIT_LIBS]) - ;; - esac - fi -fi - -if test "x${request_cunit}" = "xyes" && - test "x${have_cunit}" != "xyes"; then - AC_MSG_ERROR([cunit was requested (--with-cunit) but not found]) -fi - -AM_CONDITIONAL([HAVE_CUNIT], [ test "x${have_cunit}" = "xyes" ]) - # libev (for src) have_libev=no if test "x${request_libev}" != "xno"; then @@ -626,6 +594,47 @@ fi AM_CONDITIONAL([HAVE_LIBBPF], [ test "x${have_libbpf}" = "xyes" ]) +# libbrotlienc (for src) +have_libbrotlienc=no +if test "x${request_libbrotlienc}" != "xno"; then + PKG_CHECK_MODULES([LIBBROTLIENC], [libbrotlienc >= 1.0.9], + [have_libbrotlienc=yes], + [have_libbrotlienc=no]) + if test "x${have_libbrotlienc}" = "xno"; then + AC_MSG_NOTICE($LIBBROTLIENC_PKG_ERRORS) + fi +fi + +if test "x${request_libbrotlienc}" = "xyes" && + test "x${have_libbrotlienc}" != "xyes"; then + AC_MSG_ERROR([libbrotlienc was requested (--with-libbrotlienc) but not found]) +fi + +# libbrotlidec (for src) +have_libbrotlidec=no +if test "x${request_libbrotlidec}" != "xno"; then + PKG_CHECK_MODULES([LIBBROTLIDEC], [libbrotlidec >= 1.0.9], + [have_libbrotlidec=yes], + [have_libbrotlidec=no]) + if test "x${have_libbrotlidec}" = "xno"; then + AC_MSG_NOTICE($LIBBROTLIDEC_PKG_ERRORS) + fi +fi + +if test "x${request_libbrotlidec}" = "xyes" && + test "x${have_libbrotlidec}" != "xyes"; then + AC_MSG_ERROR([libbrotlidec was requested (--with-libbrotlidec) but not found]) +fi + +have_libbrotli=no +if test "x${have_libbrotlienc}" = "xyes" && + test "x${have_libbrotlidec}" = "xyes"; then + have_libbrotli=yes + + AC_DEFINE([HAVE_LIBBROTLI], [1], + [Define to 1 if you have `libbrotlienc` and `libbrotlidec` libraries.]) +fi + # libevent_openssl (for examples) # 2.0.8 is required because we use evconnlistener_set_error_cb() have_libevent_openssl=no @@ -1155,7 +1164,6 @@ AC_MSG_NOTICE([summary of build options: Python: ${PYTHON} PYTHON_VERSION: ${PYTHON_VERSION} Test: - CUnit: ${have_cunit} (CFLAGS='${CUNIT_CFLAGS}' LIBS='${CUNIT_LIBS}') Failmalloc: ${enable_failmalloc} Libs: OpenSSL: ${have_openssl} (CFLAGS='${OPENSSL_CFLAGS}' LIBS='${OPENSSL_LIBS}') @@ -1172,6 +1180,8 @@ AC_MSG_NOTICE([summary of build options: Jemalloc: ${have_jemalloc} (CFLAGS='${JEMALLOC_CFLAGS}' LIBS='${JEMALLOC_LIBS}') Zlib: ${have_zlib} (CFLAGS='${ZLIB_CFLAGS}' LIBS='${ZLIB_LIBS}') Systemd: ${have_libsystemd} (CFLAGS='${SYSTEMD_CFLAGS}' LIBS='${SYSTEMD_LIBS}') + Libbrotlienc: ${have_libbrotlienc} (CFLAGS="${LIBBROTLIENC_CFLAGS}' LIBS='${LIBBROTLIENC_LIBS}') + Libbrotlidec: ${have_libbrotlidec} (CFLAGS="${LIBBROTLIDEC_CFLAGS}' LIBS='${LIBBROTLIDEC_LIBS}') Third-party: http-parser: ${enable_third_party} MRuby: ${have_mruby} (CFLAGS='${LIBMRUBY_CFLAGS}' LIBS='${LIBMRUBY_LIBS}') diff --git a/doc/Makefile.am b/doc/Makefile.am index 7d7f31c..51945e4 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -42,7 +42,9 @@ APIDOCS= \ nghttp2_hd_deflate_get_num_table_entries.rst \ nghttp2_hd_deflate_get_table_entry.rst \ nghttp2_hd_deflate_hd.rst \ + nghttp2_hd_deflate_hd2.rst \ nghttp2_hd_deflate_hd_vec.rst \ + nghttp2_hd_deflate_hd_vec2.rst \ nghttp2_hd_deflate_new.rst \ nghttp2_hd_deflate_new2.rst \ nghttp2_hd_inflate_change_table_size.rst \ @@ -54,6 +56,7 @@ APIDOCS= \ nghttp2_hd_inflate_get_table_entry.rst \ nghttp2_hd_inflate_hd.rst \ nghttp2_hd_inflate_hd2.rst \ + nghttp2_hd_inflate_hd3.rst \ nghttp2_hd_inflate_new.rst \ nghttp2_hd_inflate_new2.rst \ nghttp2_http2_strerror.rst \ @@ -78,6 +81,7 @@ APIDOCS= \ nghttp2_option_set_max_settings.rst \ nghttp2_option_set_stream_reset_rate_limit.rst \ nghttp2_pack_settings_payload.rst \ + nghttp2_pack_settings_payload2.rst \ nghttp2_priority_spec_check_default.rst \ nghttp2_priority_spec_default_init.rst \ nghttp2_priority_spec_init.rst \ @@ -91,6 +95,7 @@ APIDOCS= \ nghttp2_session_callbacks_new.rst \ nghttp2_session_callbacks_set_before_frame_send_callback.rst \ nghttp2_session_callbacks_set_data_source_read_length_callback.rst \ + nghttp2_session_callbacks_set_data_source_read_length_callback2.rst \ nghttp2_session_callbacks_set_error_callback.rst \ nghttp2_session_callbacks_set_error_callback2.rst \ nghttp2_session_callbacks_set_on_begin_frame_callback.rst \ @@ -107,9 +112,13 @@ APIDOCS= \ nghttp2_session_callbacks_set_on_invalid_header_callback2.rst \ nghttp2_session_callbacks_set_on_stream_close_callback.rst \ nghttp2_session_callbacks_set_pack_extension_callback.rst \ + nghttp2_session_callbacks_set_pack_extension_callback2.rst \ nghttp2_session_callbacks_set_recv_callback.rst \ + nghttp2_session_callbacks_set_recv_callback2.rst \ nghttp2_session_callbacks_set_select_padding_callback.rst \ + nghttp2_session_callbacks_set_select_padding_callback2.rst \ nghttp2_session_callbacks_set_send_callback.rst \ + nghttp2_session_callbacks_set_send_callback2.rst \ nghttp2_session_callbacks_set_send_data_callback.rst \ nghttp2_session_callbacks_set_unpack_extension_callback.rst \ nghttp2_session_change_extpri_stream_priority.rst \ @@ -146,7 +155,9 @@ APIDOCS= \ nghttp2_session_get_stream_remote_window_size.rst \ nghttp2_session_get_stream_user_data.rst \ nghttp2_session_mem_recv.rst \ + nghttp2_session_mem_recv2.rst \ nghttp2_session_mem_send.rst \ + nghttp2_session_mem_send2.rst \ nghttp2_session_recv.rst \ nghttp2_session_resume_data.rst \ nghttp2_session_send.rst \ @@ -174,6 +185,7 @@ APIDOCS= \ nghttp2_strerror.rst \ nghttp2_submit_altsvc.rst \ nghttp2_submit_data.rst \ + nghttp2_submit_data2.rst \ nghttp2_submit_extension.rst \ nghttp2_submit_goaway.rst \ nghttp2_submit_headers.rst \ @@ -183,7 +195,9 @@ APIDOCS= \ nghttp2_submit_priority_update.rst \ nghttp2_submit_push_promise.rst \ nghttp2_submit_request.rst \ + nghttp2_submit_request2.rst \ nghttp2_submit_response.rst \ + nghttp2_submit_response2.rst \ nghttp2_submit_rst_stream.rst \ nghttp2_submit_settings.rst \ nghttp2_submit_shutdown_notice.rst \ @@ -212,7 +226,6 @@ EXTRA_DIST = \ sources/h2load-howto.rst \ sources/building-android-binary.rst \ sources/contribute.rst \ - sources/security.rst \ _exts/rubydomain/LICENSE.rubydomain \ _exts/rubydomain/__init__.py \ _exts/rubydomain/rubydomain.py \ diff --git a/doc/README.rst b/doc/README.rst index 549e550..7d4809c 100644 --- a/doc/README.rst +++ b/doc/README.rst @@ -68,7 +68,7 @@ The example follows:: * Callback function invoked when |session| wants to send data to * remote peer. */ - typedef ssize_t (*nghttp2_send_callback) + typedef nghttp2_ssize (*nghttp2_send_callback2) (nghttp2_session *session, const uint8_t *data, size_t length, int flags, void *user_data); diff --git a/doc/bash_completion/h2load b/doc/bash_completion/h2load index 2b2d4ab..e07d753 100644 --- a/doc/bash_completion/h2load +++ b/doc/bash_completion/h2load @@ -8,7 +8,7 @@ _h2load() _get_comp_words_by_ref cur prev case $cur in -*) - COMPREPLY=( $( compgen -W '--requests --clients --threads --input-file --max-concurrent-streams --max-frame-size --window-bits --connection-window-bits --header --ciphers --tls13-ciphers --no-tls-proto --data --rate --rate-period --duration --warm-up-time --connection-active-timeout --connection-inactivity-timeout --timing-script-file --base-uri --alpn-list --h1 --header-table-size --encoder-header-table-size --log-file --qlog-file-base --connect-to --rps --groups --no-udp-gso --max-udp-payload-size --ktls --verbose --version --help ' -- "$cur" ) ) + COMPREPLY=( $( compgen -W '--requests --clients --threads --input-file --max-concurrent-streams --max-frame-size --window-bits --connection-window-bits --header --ciphers --tls13-ciphers --no-tls-proto --data --rate --rate-period --duration --warm-up-time --connection-active-timeout --connection-inactivity-timeout --timing-script-file --base-uri --alpn-list --h1 --header-table-size --encoder-header-table-size --log-file --qlog-file-base --connect-to --rps --groups --no-udp-gso --max-udp-payload-size --ktls --sni --verbose --version --help ' -- "$cur" ) ) ;; *) _filedir diff --git a/doc/h2load.1 b/doc/h2load.1 index df052ab..09cdcf3 100644 --- a/doc/h2load.1 +++ b/doc/h2load.1 @@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. -.TH "H2LOAD" "1" "Jan 21, 2024" "1.59.0" "nghttp2" +.TH "H2LOAD" "1" "Mar 01, 2024" "1.60.0" "nghttp2" .SH NAME h2load \- HTTP/2 benchmarking tool .SH SYNOPSIS @@ -344,6 +344,12 @@ Enable ktls. .UNINDENT .INDENT 0.0 .TP +.B \-\-sni=<DNSNAME> +Send <DNSNAME> in TLS SNI, overriding the host name +specified in URI. +.UNINDENT +.INDENT 0.0 +.TP .B \-v, \-\-verbose Output debug information. .UNINDENT diff --git a/doc/h2load.1.rst b/doc/h2load.1.rst index 85ed651..d63a839 100644 --- a/doc/h2load.1.rst +++ b/doc/h2load.1.rst @@ -290,6 +290,11 @@ OPTIONS Enable ktls. +.. option:: --sni=<DNSNAME> + + Send <DNSNAME> in TLS SNI, overriding the host name + specified in URI. + .. option:: -v, --verbose Output debug information. diff --git a/doc/nghttp.1 b/doc/nghttp.1 index 332d9c6..231e5a4 100644 --- a/doc/nghttp.1 +++ b/doc/nghttp.1 @@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. -.TH "NGHTTP" "1" "Jan 21, 2024" "1.59.0" "nghttp2" +.TH "NGHTTP" "1" "Mar 01, 2024" "1.60.0" "nghttp2" .SH NAME nghttp \- HTTP/2 client .SH SYNOPSIS diff --git a/doc/nghttpd.1 b/doc/nghttpd.1 index 219a365..93a990d 100644 --- a/doc/nghttpd.1 +++ b/doc/nghttpd.1 @@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. -.TH "NGHTTPD" "1" "Jan 21, 2024" "1.59.0" "nghttp2" +.TH "NGHTTPD" "1" "Mar 01, 2024" "1.60.0" "nghttp2" .SH NAME nghttpd \- HTTP/2 server .SH SYNOPSIS diff --git a/doc/nghttpx.1 b/doc/nghttpx.1 index e9742a5..ba40059 100644 --- a/doc/nghttpx.1 +++ b/doc/nghttpx.1 @@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. -.TH "NGHTTPX" "1" "Jan 21, 2024" "1.59.0" "nghttp2" +.TH "NGHTTPX" "1" "Mar 01, 2024" "1.60.0" "nghttp2" .SH NAME nghttpx \- HTTP/2 proxy .SH SYNOPSIS diff --git a/doc/programmers-guide.rst b/doc/programmers-guide.rst index 820cd20..4bf5e28 100644 --- a/doc/programmers-guide.rst +++ b/doc/programmers-guide.rst @@ -40,28 +40,28 @@ most event-based architecture applications use is single thread per core, and handling one connection I/O is done by single thread. To feed input to :type:`nghttp2_session` object, one can use -`nghttp2_session_recv()` or `nghttp2_session_mem_recv()` functions. +`nghttp2_session_recv()` or `nghttp2_session_mem_recv2()` functions. They behave similarly, and the difference is that `nghttp2_session_recv()` will use :type:`nghttp2_read_callback` to get -input. On the other hand, `nghttp2_session_mem_recv()` will take -input as its parameter. If in doubt, use `nghttp2_session_mem_recv()` -since it is simpler, and could be faster since it avoids calling -callback function. +input. On the other hand, `nghttp2_session_mem_recv2()` will take +input as its parameter. If in doubt, use +`nghttp2_session_mem_recv2()` since it is simpler, and could be faster +since it avoids calling callback function. To get output from :type:`nghttp2_session` object, one can use -`nghttp2_session_send()` or `nghttp2_session_mem_send()`. The +`nghttp2_session_send()` or `nghttp2_session_mem_send2()`. The difference between them is that the former uses :type:`nghttp2_send_callback` to pass output to an application. On the other hand, the latter returns the output to the caller. If in -doubt, use `nghttp2_session_mem_send()` since it is simpler. But +doubt, use `nghttp2_session_mem_send2()` since it is simpler. But `nghttp2_session_send()` might be easier to use if the output buffer an application has is fixed sized. -In general, an application should call `nghttp2_session_mem_send()` +In general, an application should call `nghttp2_session_mem_send2()` when it gets input from underlying connection. Since there is great chance to get something pushed into transmission queue while the call -of `nghttp2_session_mem_send()`, it is recommended to call -`nghttp2_session_mem_recv()` after `nghttp2_session_mem_send()`. +of `nghttp2_session_mem_send2()`, it is recommended to call +`nghttp2_session_mem_recv2()` after `nghttp2_session_mem_send2()`. There is a question when we are safe to close HTTP/2 session without waiting for the closure of underlying connection. We offer 2 API @@ -70,7 +70,7 @@ calls for this: `nghttp2_session_want_read()` and can destroy :type:`nghttp2_session`, and then close the underlying connection. But make sure that the buffered output has been transmitted to the peer before closing the connection when -`nghttp2_session_mem_send()` is used, since +`nghttp2_session_mem_send2()` is used, since `nghttp2_session_want_write()` does not take into account the transmission of the buffered data outside of :type:`nghttp2_session`. @@ -87,18 +87,18 @@ The header files are also available online: :doc:`nghttp2.h` and Remarks ------- -Do not call `nghttp2_session_send()`, `nghttp2_session_mem_send()`, -`nghttp2_session_recv()` or `nghttp2_session_mem_recv()` from the +Do not call `nghttp2_session_send()`, `nghttp2_session_mem_send2()`, +`nghttp2_session_recv()` or `nghttp2_session_mem_recv2()` from the nghttp2 callback functions directly or indirectly. It will lead to the crash. You can submit requests or frames in the callbacks then call these functions outside the callbacks. -`nghttp2_session_send()` and `nghttp2_session_mem_send()` send first +`nghttp2_session_send()` and `nghttp2_session_mem_send2()` send first 24 bytes of client magic string (MAGIC) (:macro:`NGHTTP2_CLIENT_MAGIC`) on client configuration. The applications are responsible to send SETTINGS frame as part of connection preface using `nghttp2_submit_settings()`. Similarly, -`nghttp2_session_recv()` and `nghttp2_session_mem_recv()` consume +`nghttp2_session_recv()` and `nghttp2_session_mem_recv2()` consume MAGIC on server configuration unless `nghttp2_option_set_no_recv_client_magic()` is used with nonzero option value. @@ -222,7 +222,7 @@ above, the following code does not work: .. code-block:: c - nghttp2_submit_response(...) + nghttp2_submit_response2(...) nghttp2_submit_rst_stream(...) RST_STREAM cancels HEADERS (and DATA), and just RST_STREAM is sent. @@ -258,9 +258,9 @@ For example, we will illustrate how to send `ALTSVC const char *field; } alt_svc; - ssize_t pack_extension_callback(nghttp2_session *session, uint8_t *buf, - size_t len, const nghttp2_frame *frame, - void *user_data) { + nghttp2_ssize pack_extension_callback(nghttp2_session *session, uint8_t *buf, + size_t len, const nghttp2_frame *frame, + void *user_data) { const alt_svc *altsvc = (const alt_svc *)frame->ext.payload; size_t originlen = strlen(altsvc->origin); size_t fieldlen = strlen(altsvc->field); @@ -497,8 +497,8 @@ order to receive and process PRIORITY_UPDATE frame, server has to call NGHTTP2_PRIORITY_UPDATE)`` (see the above section), and pass the option to `nghttp2_session_server_new2()` or `nghttp2_session_server_new3()` to create a server session. Client -can send Priority header field via `nghttp2_submit_request()`. It can -also send PRIORITY_UPDATE frame via +can send Priority header field via `nghttp2_submit_request2()`. It +can also send PRIORITY_UPDATE frame via `nghttp2_submit_priority_update()`. Server processes Priority header field in a request header field and updates the stream priority unless HTTP messaging rule enforcement is disabled (see diff --git a/doc/security.rst b/doc/security.rst deleted file mode 100644 index 00b0c9c..0000000 --- a/doc/security.rst +++ /dev/null @@ -1 +0,0 @@ -.. include:: ../doc/sources/security.rst diff --git a/doc/sources/index.rst b/doc/sources/index.rst index b03c348..e181645 100644 --- a/doc/sources/index.rst +++ b/doc/sources/index.rst @@ -18,7 +18,6 @@ Contents: package_README contribute - security building-android-binary tutorial-client tutorial-server diff --git a/doc/sources/tutorial-client.rst b/doc/sources/tutorial-client.rst index 95a6230..be6eb55 100644 --- a/doc/sources/tutorial-client.rst +++ b/doc/sources/tutorial-client.rst @@ -171,7 +171,7 @@ session object and several callbacks:: nghttp2_session_callbacks_new(&callbacks); - nghttp2_session_callbacks_set_send_callback(callbacks, send_callback); + nghttp2_session_callbacks_set_send_callback2(callbacks, send_callback); nghttp2_session_callbacks_set_on_frame_recv_callback(callbacks, on_frame_recv_callback); @@ -246,8 +246,8 @@ HTTP request in the ``submit_request()`` function:: MAKE_NV(":path", stream_data->path, stream_data->pathlen)}; fprintf(stderr, "Request headers:\n"); print_headers(stderr, hdrs, ARRLEN(hdrs)); - stream_id = nghttp2_submit_request(session_data->session, NULL, hdrs, - ARRLEN(hdrs), NULL, stream_data); + stream_id = nghttp2_submit_request2(session_data->session, NULL, hdrs, + ARRLEN(hdrs), NULL, stream_data); if (stream_id < 0) { errx(1, "Could not submit HTTP request: %s", nghttp2_strerror(stream_id)); } @@ -258,11 +258,11 @@ HTTP request in the ``submit_request()`` function:: We build the HTTP request header fields in ``hdrs``, which is an array of :type:`nghttp2_nv`. There are four header fields to be sent: ``:method``, ``:scheme``, ``:authority``, and ``:path``. To queue the -HTTP request, we call `nghttp2_submit_request()`. The ``stream_data`` +HTTP request, we call `nghttp2_submit_request2()`. The ``stream_data`` is passed via the *stream_user_data* parameter, which is helpfully later passed back to callback functions. -`nghttp2_submit_request()` returns the newly assigned stream ID for +`nghttp2_submit_request2()` returns the newly assigned stream ID for the request. The next bufferevent callback is ``readcb()``, which is invoked when @@ -270,12 +270,12 @@ data is available to read from the bufferevent input buffer:: static void readcb(struct bufferevent *bev, void *ptr) { http2_session_data *session_data = (http2_session_data *)ptr; - ssize_t readlen; + nghttp2_ssize readlen; struct evbuffer *input = bufferevent_get_input(bev); size_t datalen = evbuffer_get_length(input); unsigned char *data = evbuffer_pullup(input, -1); - readlen = nghttp2_session_mem_recv(session_data->session, data, datalen); + readlen = nghttp2_session_mem_recv2(session_data->session, data, datalen); if (readlen < 0) { warnx("Fatal error: %s", nghttp2_strerror((int)readlen)); delete_http2_session_data(session_data); @@ -293,8 +293,8 @@ data is available to read from the bufferevent input buffer:: } In this function we feed all unprocessed, received data to the nghttp2 -session object using the `nghttp2_session_mem_recv()` function. -`nghttp2_session_mem_recv()` processes the received data and may +session object using the `nghttp2_session_mem_recv2()` function. +`nghttp2_session_mem_recv2()` processes the received data and may invoke nghttp2 callbacks and queue frames for transmission. Since there may be pending frames for transmission, we call immediately ``session_send()`` to send them. ``session_send()`` is defined as @@ -313,15 +313,16 @@ follows:: The `nghttp2_session_send()` function serializes pending frames into wire format and calls the ``send_callback()`` function to send them. -``send_callback()`` has type :type:`nghttp2_send_callback` and is +``send_callback()`` has type :type:`nghttp2_send_callback2` and is defined as:: - static ssize_t send_callback(nghttp2_session *session _U_, const uint8_t *data, - size_t length, int flags _U_, void *user_data) { + static nghttp2_ssize send_callback(nghttp2_session *session _U_, + const uint8_t *data, size_t length, + int flags _U_, void *user_data) { http2_session_data *session_data = (http2_session_data *)user_data; struct bufferevent *bev = session_data->bev; bufferevent_write(bev, data, length); - return (ssize_t)length; + return (nghttp2_ssize)length; } Since we use bufferevent to abstract network I/O, we just write the diff --git a/doc/sources/tutorial-hpack.rst b/doc/sources/tutorial-hpack.rst index 36e82d9..82acd94 100644 --- a/doc/sources/tutorial-hpack.rst +++ b/doc/sources/tutorial-hpack.rst @@ -24,11 +24,11 @@ deflater object for the dynamic header table. If in doubt, just specify 4096 here, which is the default upper bound of dynamic header table buffer size. -To encode header fields, use the `nghttp2_hd_deflate_hd()` function:: +To encode header fields, use the `nghttp2_hd_deflate_hd2()` function:: - ssize_t nghttp2_hd_deflate_hd(nghttp2_hd_deflater *deflater, - uint8_t *buf, size_t buflen, - const nghttp2_nv *nva, size_t nvlen); + nghttp2_ssize nghttp2_hd_deflate_hd2(nghttp2_hd_deflater *deflater, + uint8_t *buf, size_t buflen, + const nghttp2_nv *nva, size_t nvlen); The *deflater* is the deflater object initialized by `nghttp2_hd_deflate_new()` described above. The encoded byte string is @@ -44,7 +44,7 @@ cookies), set the :macro:`NGHTTP2_NV_FLAG_NO_INDEX` flag in sensitive header fields by compression based attacks: This is achieved by not inserting the header field into the dynamic header table. -`nghttp2_hd_deflate_hd()` processes all headers given in *nva*. The +`nghttp2_hd_deflate_hd2()` processes all headers given in *nva*. The *nva* must include all request or response header fields to be sent in one HEADERS (or optionally following (multiple) CONTINUATION frame(s)). The *buf* must have enough space to store the encoded @@ -55,13 +55,13 @@ of the encoded result length, use `nghttp2_hd_deflate_bound()`:: const nghttp2_nv *nva, size_t nvlen); Pass this function the same parameters (*deflater*, *nva*, and -*nvlen*) which will be passed to `nghttp2_hd_deflate_hd()`. +*nvlen*) which will be passed to `nghttp2_hd_deflate_hd2()`. -Subsequent calls to `nghttp2_hd_deflate_hd()` will use the current +Subsequent calls to `nghttp2_hd_deflate_hd2()` will use the current encoder state and perform differential encoding, which yields HPAC's fundamental compression gain. -If `nghttp2_hd_deflate_hd()` fails, the failure is fatal and any +If `nghttp2_hd_deflate_hd2()` fails, the failure is fatal and any further calls with the same deflater object will fail. Thus it's very important to use `nghttp2_hd_deflate_bound()` to determine the required size of the output buffer. @@ -78,14 +78,14 @@ header data. To initialize the object, use int nghttp2_hd_inflate_new(nghttp2_hd_inflater **inflater_ptr); -To inflate header data, use `nghttp2_hd_inflate_hd2()`:: +To inflate header data, use `nghttp2_hd_inflate_hd3()`:: - ssize_t nghttp2_hd_inflate_hd2(nghttp2_hd_inflater *inflater, - nghttp2_nv *nv_out, int *inflate_flags, - const uint8_t *in, size_t inlen, - int in_final); + nghttp2_ssize nghttp2_hd_inflate_hd3(nghttp2_hd_inflater *inflater, + nghttp2_nv *nv_out, int *inflate_flags, + const uint8_t *in, size_t inlen, + int in_final); -`nghttp2_hd_inflate_hd2()` reads a stream of bytes and outputs a +`nghttp2_hd_inflate_hd3()` reads a stream of bytes and outputs a single header field at a time. Multiple calls are normally required to read a full stream of bytes and output all of the header fields. @@ -119,7 +119,7 @@ If *in_final* is zero and the :macro:`NGHTTP2_HD_INFLATE_EMIT` flag is not set, it indicates that all given data was processed. The caller is required to pass additional data. -Example usage of `nghttp2_hd_inflate_hd2()` is shown in the +Example usage of `nghttp2_hd_inflate_hd3()` is shown in the `inflate_header_block()` function in `deflate.c`_. Finally, to delete a :type:`nghttp2_hd_inflater` object, use diff --git a/doc/sources/tutorial-server.rst b/doc/sources/tutorial-server.rst index 41680bd..bf71296 100644 --- a/doc/sources/tutorial-server.rst +++ b/doc/sources/tutorial-server.rst @@ -220,7 +220,7 @@ session object and several callbacks:: nghttp2_session_callbacks_new(&callbacks); - nghttp2_session_callbacks_set_send_callback(callbacks, send_callback); + nghttp2_session_callbacks_set_send_callback2(callbacks, send_callback); nghttp2_session_callbacks_set_on_frame_recv_callback(callbacks, on_frame_recv_callback); @@ -275,12 +275,12 @@ this pending data. To process the received data, we call the ``session_recv()`` function:: static int session_recv(http2_session_data *session_data) { - ssize_t readlen; + nghttp2_ssize readlen; struct evbuffer *input = bufferevent_get_input(session_data->bev); size_t datalen = evbuffer_get_length(input); unsigned char *data = evbuffer_pullup(input, -1); - readlen = nghttp2_session_mem_recv(session_data->session, data, datalen); + readlen = nghttp2_session_mem_recv2(session_data->session, data, datalen); if (readlen < 0) { warnx("Fatal error: %s", nghttp2_strerror((int)readlen)); return -1; @@ -296,9 +296,9 @@ this pending data. To process the received data, we call the } In this function, we feed all unprocessed but already received data to -the nghttp2 session object using the `nghttp2_session_mem_recv()` -function. The `nghttp2_session_mem_recv()` function processes the data -and may both invoke the previously setup callbacks and also queue +the nghttp2 session object using the `nghttp2_session_mem_recv2()` +function. The `nghttp2_session_mem_recv2()` function processes the +data and may both invoke the previously setup callbacks and also queue outgoing frames. To send any pending outgoing frames, we immediately call ``session_send()``. @@ -316,11 +316,12 @@ The ``session_send()`` function is defined as follows:: The `nghttp2_session_send()` function serializes the frame into wire format and calls the ``send_callback()``, which is of type -:type:`nghttp2_send_callback`. The ``send_callback()`` is defined as +:type:`nghttp2_send_callback2`. The ``send_callback()`` is defined as follows:: - static ssize_t send_callback(nghttp2_session *session _U_, const uint8_t *data, - size_t length, int flags _U_, void *user_data) { + static nghttp2_ssize send_callback(nghttp2_session *session _U_, + const uint8_t *data, size_t length, + int flags _U_, void *user_data) { http2_session_data *session_data = (http2_session_data *)user_data; struct bufferevent *bev = session_data->bev; /* Avoid excessive buffering in server side. */ @@ -329,7 +330,7 @@ follows:: return NGHTTP2_ERR_WOULDBLOCK; } bufferevent_write(bev, data, length); - return (ssize_t)length; + return (nghttp2_ssize)length; } Since we use bufferevent to abstract network I/O, we just write the @@ -509,11 +510,11 @@ Sending the file content is performed by the ``send_response()`` function:: static int send_response(nghttp2_session *session, int32_t stream_id, nghttp2_nv *nva, size_t nvlen, int fd) { int rv; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; data_prd.source.fd = fd; data_prd.read_callback = file_read_callback; - rv = nghttp2_submit_response(session, stream_id, nva, nvlen, &data_prd); + rv = nghttp2_submit_response2(session, stream_id, nva, nvlen, &data_prd); if (rv != 0) { warnx("Fatal error: %s", nghttp2_strerror(rv)); return -1; @@ -521,7 +522,7 @@ Sending the file content is performed by the ``send_response()`` function:: return 0; } -nghttp2 uses the :type:`nghttp2_data_provider` structure to send the +nghttp2 uses the :type:`nghttp2_data_provider2` structure to send the entity body to the remote peer. The ``source`` member of this structure is a union, which can be either a void pointer or an int (which is intended to be used as file descriptor). In this example @@ -529,11 +530,11 @@ server, we use it as a file descriptor. We also set the ``file_read_callback()`` callback function to read the contents of the file:: - static ssize_t file_read_callback(nghttp2_session *session _U_, - int32_t stream_id _U_, uint8_t *buf, - size_t length, uint32_t *data_flags, - nghttp2_data_source *source, - void *user_data _U_) { + static nghttp2_ssize file_read_callback(nghttp2_session *session _U_, + int32_t stream_id _U_, uint8_t *buf, + size_t length, uint32_t *data_flags, + nghttp2_data_source *source, + void *user_data _U_) { int fd = source->fd; ssize_t r; while ((r = read(fd, buf, length)) == -1 && errno == EINTR) @@ -544,7 +545,7 @@ file:: if (r == 0) { *data_flags |= NGHTTP2_DATA_FLAG_EOF; } - return r; + return (nghttp2_ssize)r; } If an error occurs while reading the file, we return @@ -553,8 +554,8 @@ library to send RST_STREAM to the stream. When all data has been read, the :macro:`NGHTTP2_DATA_FLAG_EOF` flag is set to signal nghttp2 that we have finished reading the file. -The `nghttp2_submit_response()` function is used to send the response to the -remote peer. +The `nghttp2_submit_response2()` function is used to send the response +to the remote peer. The ``on_stream_close_callback()`` function is invoked when the stream is about to close:: diff --git a/docker/Dockerfile b/docker/Dockerfile index 25a7261..8426024 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,22 +1,25 @@ FROM debian:12 as build +ARG NGHTTP2_BRANCH=master + RUN apt-get update && \ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ git clang make binutils autoconf automake autotools-dev libtool \ - pkg-config \ + pkg-config cmake cmake-data \ zlib1g-dev libev-dev libjemalloc-dev ruby-dev libc-ares-dev bison \ - libelf-dev + libelf-dev libbrotli-dev -RUN git clone --depth 1 -b OpenSSL_1_1_1w+quic https://github.com/quictls/openssl && \ - cd openssl && \ - ./config --openssldir=/etc/ssl && \ - make -j$(nproc) && \ - make install_sw && \ +RUN git clone --depth 1 -b v1.21.0 https://github.com/aws/aws-lc && \ + cd aws-lc && \ + cmake -B build -DDISABLE_GO=ON && \ + make -j$(nproc) -C build && \ + cmake --install build && \ cd .. && \ - rm -rf openssl + rm -rf aws-lc -RUN git clone --depth 1 -b v1.1.0 https://github.com/ngtcp2/nghttp3 && \ +RUN git clone --depth 1 -b v1.2.0 https://github.com/ngtcp2/nghttp3 && \ cd nghttp3 && \ + git submodule update --init --depth 1 && \ autoreconf -i && \ ./configure --enable-lib-only && \ make -j$(nproc) && \ @@ -24,12 +27,13 @@ RUN git clone --depth 1 -b v1.1.0 https://github.com/ngtcp2/nghttp3 && \ cd .. && \ rm -rf nghttp3 -RUN git clone --depth 1 -b v1.2.0 https://github.com/ngtcp2/ngtcp2 && \ +RUN git clone --depth 1 -b v1.3.0 https://github.com/ngtcp2/ngtcp2 && \ cd ngtcp2 && \ + git submodule update --init --depth 1 && \ autoreconf -i && \ - ./configure --enable-lib-only \ + ./configure --enable-lib-only --with-boringssl \ LIBTOOL_LDFLAGS="-static-libtool-libs" \ - OPENSSL_LIBS="-l:libssl.a -l:libcrypto.a -ldl -lpthread" \ + BORINGSSL_LIBS="-l:libssl.a -l:libcrypto.a" \ PKG_CONFIG_PATH="/usr/local/lib64/pkgconfig" && \ make -j$(nproc) && \ make install-strip && \ @@ -42,21 +46,24 @@ RUN git clone --depth 1 -b v1.3.0 https://github.com/libbpf/libbpf && \ cd .. && \ rm -rf libbpf -RUN git clone --depth 1 https://github.com/nghttp2/nghttp2.git && \ +RUN git clone --depth 1 -b $NGHTTP2_BRANCH https://github.com/nghttp2/nghttp2 && \ cd nghttp2 && \ - git submodule update --init && \ + git submodule update --init --depth 1 && \ autoreconf -i && \ ./configure --disable-examples --disable-hpack-tools \ - --with-mruby --with-neverbleed \ + --with-mruby \ --enable-http3 --with-libbpf \ + --with-libbrotlienc --with-libbrotlidec \ CC=clang CXX=clang++ \ LIBTOOL_LDFLAGS="-static-libtool-libs" \ - OPENSSL_LIBS="-l:libssl.a -l:libcrypto.a -ldl -pthread" \ + OPENSSL_LIBS="-l:libssl.a -l:libcrypto.a" \ LIBEV_LIBS="-l:libev.a" \ JEMALLOC_LIBS="-l:libjemalloc.a" \ LIBCARES_LIBS="-l:libcares.a" \ ZLIB_LIBS="-l:libz.a" \ LIBBPF_LIBS="-L/usr/local/lib64 -l:libbpf.a -l:libelf.a" \ + LIBBROTLIENC_LIBS="-l:libbrotlienc.a -l:libbrotlicommon.a" \ + LIBBROTLIDEC_LIBS="-l:libbrotlidec.a -l:libbrotlicommon.a" \ LDFLAGS="-static-libgcc -static-libstdc++" \ PKG_CONFIG_PATH="/usr/local/lib64/pkgconfig" && \ make -j$(nproc) install-strip && \ diff --git a/examples/client.c b/examples/client.c index ce8d1d0..7d25610 100644 --- a/examples/client.c +++ b/examples/client.c @@ -56,6 +56,7 @@ #include <string.h> #include <errno.h> +#define NGHTTP2_NO_SSIZE_T #include <nghttp2/nghttp2.h> #include <openssl/ssl.h> @@ -154,13 +155,14 @@ static void diec(const char *func, int error_code) { } /* - * The implementation of nghttp2_send_callback type. Here we write + * The implementation of nghttp2_send_callback2 type. Here we write * |data| with size |length| to the network and return the number of * bytes actually written. See the documentation of * nghttp2_send_callback for the details. */ -static ssize_t send_callback(nghttp2_session *session, const uint8_t *data, - size_t length, int flags, void *user_data) { +static nghttp2_ssize send_callback(nghttp2_session *session, + const uint8_t *data, size_t length, + int flags, void *user_data) { struct Connection *connection; int rv; (void)session; @@ -184,13 +186,14 @@ static ssize_t send_callback(nghttp2_session *session, const uint8_t *data, } /* - * The implementation of nghttp2_recv_callback type. Here we read data - * from the network and write them in |buf|. The capacity of |buf| is - * |length| bytes. Returns the number of bytes stored in |buf|. See - * the documentation of nghttp2_recv_callback for the details. + * The implementation of nghttp2_recv_callback2 type. Here we read + * data from the network and write them in |buf|. The capacity of + * |buf| is |length| bytes. Returns the number of bytes stored in + * |buf|. See the documentation of nghttp2_recv_callback for the + * details. */ -static ssize_t recv_callback(nghttp2_session *session, uint8_t *buf, - size_t length, int flags, void *user_data) { +static nghttp2_ssize recv_callback(nghttp2_session *session, uint8_t *buf, + size_t length, int flags, void *user_data) { struct Connection *connection; int rv; (void)session; @@ -328,9 +331,9 @@ static int on_data_chunk_recv_callback(nghttp2_session *session, uint8_t flags, * recv_callback is also required. */ static void setup_nghttp2_callbacks(nghttp2_session_callbacks *callbacks) { - nghttp2_session_callbacks_set_send_callback(callbacks, send_callback); + nghttp2_session_callbacks_set_send_callback2(callbacks, send_callback); - nghttp2_session_callbacks_set_recv_callback(callbacks, recv_callback); + nghttp2_session_callbacks_set_recv_callback2(callbacks, recv_callback); nghttp2_session_callbacks_set_on_frame_send_callback(callbacks, on_frame_send_callback); @@ -458,8 +461,8 @@ static void submit_request(struct Connection *connection, struct Request *req) { MAKE_NV("accept", "*/*"), MAKE_NV("user-agent", "nghttp2/" NGHTTP2_VERSION)}; - stream_id = nghttp2_submit_request(connection->session, NULL, nva, - sizeof(nva) / sizeof(nva[0]), NULL, req); + stream_id = nghttp2_submit_request2(connection->session, NULL, nva, + sizeof(nva) / sizeof(nva[0]), NULL, req); if (stream_id < 0) { diec("nghttp2_submit_request", stream_id); diff --git a/examples/deflate.c b/examples/deflate.c index df1cb92..8343b16 100644 --- a/examples/deflate.c +++ b/examples/deflate.c @@ -29,6 +29,7 @@ #include <stdio.h> #include <string.h> +#define NGHTTP2_NO_SSIZE_T #include <nghttp2/nghttp2.h> #define MAKE_NV(K, V) \ @@ -93,7 +94,7 @@ int main(void) { static void deflate(nghttp2_hd_deflater *deflater, nghttp2_hd_inflater *inflater, const nghttp2_nv *const nva, size_t nvlen) { - ssize_t rv; + nghttp2_ssize rv; uint8_t *buf; size_t buflen; size_t outlen; @@ -118,10 +119,10 @@ static void deflate(nghttp2_hd_deflater *deflater, buflen = nghttp2_hd_deflate_bound(deflater, nva, nvlen); buf = malloc(buflen); - rv = nghttp2_hd_deflate_hd(deflater, buf, buflen, nva, nvlen); + rv = nghttp2_hd_deflate_hd2(deflater, buf, buflen, nva, nvlen); if (rv < 0) { - fprintf(stderr, "nghttp2_hd_deflate_hd() failed with error: %s\n", + fprintf(stderr, "nghttp2_hd_deflate_hd2() failed with error: %s\n", nghttp2_strerror((int)rv)); free(buf); @@ -166,17 +167,18 @@ static void deflate(nghttp2_hd_deflater *deflater, int inflate_header_block(nghttp2_hd_inflater *inflater, uint8_t *in, size_t inlen, int final) { - ssize_t rv; + nghttp2_ssize rv; for (;;) { nghttp2_nv nv; int inflate_flags = 0; size_t proclen; - rv = nghttp2_hd_inflate_hd(inflater, &nv, &inflate_flags, in, inlen, final); + rv = + nghttp2_hd_inflate_hd3(inflater, &nv, &inflate_flags, in, inlen, final); if (rv < 0) { - fprintf(stderr, "inflate failed with error code %zd", rv); + fprintf(stderr, "inflate failed with error code %td", rv); return -1; } diff --git a/examples/libevent-client.c b/examples/libevent-client.c index 0e1c14a..7f98368 100644 --- a/examples/libevent-client.c +++ b/examples/libevent-client.c @@ -63,6 +63,7 @@ char *strndup(const char *s, size_t size); #include <event2/bufferevent_ssl.h> #include <event2/dns.h> +#define NGHTTP2_NO_SSIZE_T #include <nghttp2/nghttp2.h> #include "url-parser/url_parser.h" @@ -196,18 +197,19 @@ static void print_headers(FILE *f, nghttp2_nv *nva, size_t nvlen) { fprintf(f, "\n"); } -/* nghttp2_send_callback. Here we transmit the |data|, |length| bytes, - to the network. Because we are using libevent bufferevent, we just - write those bytes into bufferevent buffer. */ -static ssize_t send_callback(nghttp2_session *session, const uint8_t *data, - size_t length, int flags, void *user_data) { +/* nghttp2_send_callback2. Here we transmit the |data|, |length| + bytes, to the network. Because we are using libevent bufferevent, + we just write those bytes into bufferevent buffer. */ +static nghttp2_ssize send_callback(nghttp2_session *session, + const uint8_t *data, size_t length, + int flags, void *user_data) { http2_session_data *session_data = (http2_session_data *)user_data; struct bufferevent *bev = session_data->bev; (void)session; (void)flags; bufferevent_write(bev, data, length); - return (ssize_t)length; + return (nghttp2_ssize)length; } /* nghttp2_on_header_callback: Called when nghttp2 library emits @@ -342,7 +344,7 @@ static void initialize_nghttp2_session(http2_session_data *session_data) { nghttp2_session_callbacks_new(&callbacks); - nghttp2_session_callbacks_set_send_callback(callbacks, send_callback); + nghttp2_session_callbacks_set_send_callback2(callbacks, send_callback); nghttp2_session_callbacks_set_on_frame_recv_callback(callbacks, on_frame_recv_callback); @@ -403,8 +405,8 @@ static void submit_request(http2_session_data *session_data) { MAKE_NV(":path", stream_data->path, stream_data->pathlen)}; fprintf(stderr, "Request headers:\n"); print_headers(stderr, hdrs, ARRLEN(hdrs)); - stream_id = nghttp2_submit_request(session_data->session, NULL, hdrs, - ARRLEN(hdrs), NULL, stream_data); + stream_id = nghttp2_submit_request2(session_data->session, NULL, hdrs, + ARRLEN(hdrs), NULL, stream_data); if (stream_id < 0) { errx(1, "Could not submit HTTP request: %s", nghttp2_strerror(stream_id)); } @@ -431,12 +433,12 @@ static int session_send(http2_session_data *session_data) { context. To send them, we call session_send() in the end. */ static void readcb(struct bufferevent *bev, void *ptr) { http2_session_data *session_data = (http2_session_data *)ptr; - ssize_t readlen; + nghttp2_ssize readlen; struct evbuffer *input = bufferevent_get_input(bev); size_t datalen = evbuffer_get_length(input); unsigned char *data = evbuffer_pullup(input, -1); - readlen = nghttp2_session_mem_recv(session_data->session, data, datalen); + readlen = nghttp2_session_mem_recv2(session_data->session, data, datalen); if (readlen < 0) { warnx("Fatal error: %s", nghttp2_strerror((int)readlen)); delete_http2_session_data(session_data); diff --git a/examples/libevent-server.c b/examples/libevent-server.c index fa45d37..cc6c510 100644 --- a/examples/libevent-server.c +++ b/examples/libevent-server.c @@ -71,6 +71,7 @@ #include <event2/bufferevent_ssl.h> #include <event2/listener.h> +#define NGHTTP2_NO_SSIZE_T #include <nghttp2/nghttp2.h> #define OUTPUT_WOULDBLOCK_THRESHOLD (1 << 16) @@ -277,16 +278,16 @@ static int session_send(http2_session_data *session_data) { } /* Read the data in the bufferevent and feed them into nghttp2 library - function. Invocation of nghttp2_session_mem_recv() may make + function. Invocation of nghttp2_session_mem_recv2() may make additional pending frames, so call session_send() at the end of the function. */ static int session_recv(http2_session_data *session_data) { - ssize_t readlen; + nghttp2_ssize readlen; struct evbuffer *input = bufferevent_get_input(session_data->bev); size_t datalen = evbuffer_get_length(input); unsigned char *data = evbuffer_pullup(input, -1); - readlen = nghttp2_session_mem_recv(session_data->session, data, datalen); + readlen = nghttp2_session_mem_recv2(session_data->session, data, datalen); if (readlen < 0) { warnx("Fatal error: %s", nghttp2_strerror((int)readlen)); return -1; @@ -301,8 +302,9 @@ static int session_recv(http2_session_data *session_data) { return 0; } -static ssize_t send_callback(nghttp2_session *session, const uint8_t *data, - size_t length, int flags, void *user_data) { +static nghttp2_ssize send_callback(nghttp2_session *session, + const uint8_t *data, size_t length, + int flags, void *user_data) { http2_session_data *session_data = (http2_session_data *)user_data; struct bufferevent *bev = session_data->bev; (void)session; @@ -314,7 +316,7 @@ static ssize_t send_callback(nghttp2_session *session, const uint8_t *data, return NGHTTP2_ERR_WOULDBLOCK; } bufferevent_write(bev, data, length); - return (ssize_t)length; + return (nghttp2_ssize)length; } /* Returns nonzero if the string |s| ends with the substring |sub| */ @@ -370,11 +372,11 @@ static char *percent_decode(const uint8_t *value, size_t valuelen) { return res; } -static ssize_t file_read_callback(nghttp2_session *session, int32_t stream_id, - uint8_t *buf, size_t length, - uint32_t *data_flags, - nghttp2_data_source *source, - void *user_data) { +static nghttp2_ssize file_read_callback(nghttp2_session *session, + int32_t stream_id, uint8_t *buf, + size_t length, uint32_t *data_flags, + nghttp2_data_source *source, + void *user_data) { int fd = source->fd; ssize_t r; (void)session; @@ -389,17 +391,17 @@ static ssize_t file_read_callback(nghttp2_session *session, int32_t stream_id, if (r == 0) { *data_flags |= NGHTTP2_DATA_FLAG_EOF; } - return r; + return (nghttp2_ssize)r; } static int send_response(nghttp2_session *session, int32_t stream_id, nghttp2_nv *nva, size_t nvlen, int fd) { int rv; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; data_prd.source.fd = fd; data_prd.read_callback = file_read_callback; - rv = nghttp2_submit_response(session, stream_id, nva, nvlen, &data_prd); + rv = nghttp2_submit_response2(session, stream_id, nva, nvlen, &data_prd); if (rv != 0) { warnx("Fatal error: %s", nghttp2_strerror(rv)); return -1; @@ -590,7 +592,7 @@ static void initialize_nghttp2_session(http2_session_data *session_data) { nghttp2_session_callbacks_new(&callbacks); - nghttp2_session_callbacks_set_send_callback(callbacks, send_callback); + nghttp2_session_callbacks_set_send_callback2(callbacks, send_callback); nghttp2_session_callbacks_set_on_frame_recv_callback(callbacks, on_frame_recv_callback); diff --git a/fuzz/fuzz_target.cc b/fuzz/fuzz_target.cc index 4adc5ed..1932802 100644 --- a/fuzz/fuzz_target.cc +++ b/fuzz/fuzz_target.cc @@ -40,7 +40,7 @@ namespace { void send_pending(nghttp2_session *session) { for (;;) { const uint8_t *data; - auto n = nghttp2_session_mem_send(session, &data); + auto n = nghttp2_session_mem_send2(session, &data); if (n == 0) { return; } @@ -70,7 +70,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { nghttp2_settings_entry iv{NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, 100}; nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, &iv, 1); send_pending(session); - nghttp2_session_mem_recv(session, data, size); + nghttp2_session_mem_recv2(session, data, size); send_pending(session); nghttp2_session_del(session); diff --git a/fuzz/fuzz_target_fdp.cc b/fuzz/fuzz_target_fdp.cc index f94b964..668c83f 100644 --- a/fuzz/fuzz_target_fdp.cc +++ b/fuzz/fuzz_target_fdp.cc @@ -44,7 +44,7 @@ namespace { void send_pending(nghttp2_session *session) { for (;;) { const uint8_t *data; - auto n = nghttp2_session_mem_send(session, &data); + auto n = nghttp2_session_mem_send2(session, &data); if (n == 0) { return; } @@ -87,7 +87,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { send_pending(session); std::vector<uint8_t> d = data_provider.ConsumeRemainingBytes<uint8_t>(); - nghttp2_session_mem_recv(session, d.data(), d.size()); + nghttp2_session_mem_recv2(session, d.data(), d.size()); send_pending(session); @@ -6,7 +6,7 @@ require ( github.com/bradfitz/gomemcache v0.0.0-20230905024940-24af94b03874 github.com/quic-go/quic-go v0.41.0 github.com/tatsuhiro-t/go-nghttp2 v0.0.0-20240121064059-46ccb0a462a8 - golang.org/x/net v0.20.0 + golang.org/x/net v0.21.0 ) require ( @@ -15,10 +15,10 @@ require ( github.com/onsi/ginkgo/v2 v2.9.5 // indirect github.com/quic-go/qpack v0.4.0 // indirect go.uber.org/mock v0.3.0 // indirect - golang.org/x/crypto v0.18.0 // indirect + golang.org/x/crypto v0.19.0 // indirect golang.org/x/exp v0.0.0-20221205204356-47842c84f3db // indirect golang.org/x/mod v0.11.0 // indirect - golang.org/x/sys v0.16.0 // indirect + golang.org/x/sys v0.17.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/tools v0.9.1 // indirect ) @@ -34,17 +34,17 @@ github.com/tatsuhiro-t/go-nghttp2 v0.0.0-20240121064059-46ccb0a462a8 h1:zKJxuRe+ github.com/tatsuhiro-t/go-nghttp2 v0.0.0-20240121064059-46ccb0a462a8/go.mod h1:gTqc3Q4boc+cKRlSFywTYdX9t6VGRcsThlNIWwaL3Dc= go.uber.org/mock v0.3.0 h1:3mUxI1No2/60yUYax92Pt8eNOEecx2D3lcXZh2NEZJo= go.uber.org/mock v0.3.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= -golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= -golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= +golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo= +golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= golang.org/x/exp v0.0.0-20221205204356-47842c84f3db h1:D/cFflL63o2KSLJIwjlcIt8PR064j/xsmdEJL/YvY/o= golang.org/x/exp v0.0.0-20221205204356-47842c84f3db/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU= golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= -golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= +golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.9.1 h1:8WMNJAz3zrtPmnYC7ISf5dEn3MT0gY7jBJfw27yrrLo= diff --git a/integration-tests/nghttpx_http1_test.go b/integration-tests/nghttpx_http1_test.go index 740396d..805525e 100644 --- a/integration-tests/nghttpx_http1_test.go +++ b/integration-tests/nghttpx_http1_test.go @@ -58,7 +58,7 @@ func TestH1H1PlainGETClose(t *testing.T) { // 501 status code func TestH1H1InvalidMethod(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward this request") }, } @@ -82,7 +82,7 @@ func TestH1H1InvalidMethod(t *testing.T) { // contains multiple Content-Length header fields. func TestH1H1MultipleRequestCL(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward bad request") }, } @@ -255,7 +255,7 @@ func TestH1H1HostRewrite(t *testing.T) { // characters in host header field. func TestH1H1BadHost(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward this request") }, } @@ -281,7 +281,7 @@ func TestH1H1BadHost(t *testing.T) { // bad characters in authority component of requset URI. func TestH1H1BadAuthority(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward this request") }, } @@ -307,7 +307,7 @@ func TestH1H1BadAuthority(t *testing.T) { // bad characters in scheme component of requset URI. func TestH1H1BadScheme(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward this request") }, } @@ -394,7 +394,7 @@ func TestH1H1HTTP10NoHostRewrite(t *testing.T) { // backend. func TestH1H1RequestTrailer(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { buf := make([]byte, 4096) for { _, err := r.Body.Read(buf) @@ -436,7 +436,7 @@ func TestH1H1HeaderFieldBufferPath(t *testing.T) { // limit. opts := options{ args: []string{"--request-header-field-buffer=100"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatal("execution path should not be here") }, } @@ -460,7 +460,7 @@ func TestH1H1HeaderFieldBufferPath(t *testing.T) { func TestH1H1HeaderFieldBuffer(t *testing.T) { opts := options{ args: []string{"--request-header-field-buffer=10"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatal("execution path should not be here") }, } @@ -483,7 +483,7 @@ func TestH1H1HeaderFieldBuffer(t *testing.T) { func TestH1H1HeaderFields(t *testing.T) { opts := options{ args: []string{"--max-request-header-fields=1"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatal("execution path should not be here") }, } @@ -533,7 +533,7 @@ func TestH1H1Websocket(t *testing.T) { func TestH1H1ReqPhaseSetHeader(t *testing.T) { opts := options{ args: []string{"--mruby-file=" + testDir + "/req-set-header.rb"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("User-Agent"), "mruby"; got != want { t.Errorf("User-Agent = %v; want %v", got, want) } @@ -559,7 +559,7 @@ func TestH1H1ReqPhaseSetHeader(t *testing.T) { func TestH1H1ReqPhaseReturn(t *testing.T) { opts := options{ args: []string{"--mruby-file=" + testDir + "/req-return.rb"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, } @@ -599,7 +599,7 @@ func TestH1H1ReqPhaseReturn(t *testing.T) { func TestH1H1ReqPhaseReturnCONNECTMethod(t *testing.T) { opts := options{ args: []string{"--mruby-file=" + testDir + "/req-return.rb"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, } @@ -884,7 +884,7 @@ func TestH1H1CONNECTMethodFailure(t *testing.T) { func TestH1H2NoHost(t *testing.T) { opts := options{ args: []string{"--http2-bridge"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward bad request") }, } @@ -978,7 +978,7 @@ func TestH1H2HTTP10NoHostRewrite(t *testing.T) { func TestH1H2CrumbleCookie(t *testing.T) { opts := options{ args: []string{"--http2-bridge"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("Cookie"), "alpha; bravo; charlie"; got != want { t.Errorf("Cookie: %v; want %v", got, want) } @@ -1006,7 +1006,7 @@ func TestH1H2CrumbleCookie(t *testing.T) { func TestH1H2GenerateVia(t *testing.T) { opts := options{ args: []string{"--http2-bridge"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("Via"), "1.1 nghttpx"; got != want { t.Errorf("Via: %v; want %v", got, want) } @@ -1092,7 +1092,7 @@ func TestH1H2ReqPhaseReturn(t *testing.T) { "--http2-bridge", "--mruby-file=" + testDir + "/req-return.rb", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, } @@ -1172,7 +1172,7 @@ func TestH1H2RespPhaseReturn(t *testing.T) { func TestH1H2TE(t *testing.T) { opts := options{ args: []string{"--http2-bridge"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("te"), "trailers"; got != want { t.Errorf("te: %v; want %v", got, want) } @@ -1200,7 +1200,7 @@ func TestH1H2TE(t *testing.T) { func TestH1APIBackendconfig(t *testing.T) { opts := options{ args: []string{"-f127.0.0.1,3010;api;no-tls"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, connectPort: 3010, @@ -1242,7 +1242,7 @@ backend=127.0.0.1,3011 func TestH1APIBackendconfigQuery(t *testing.T) { opts := options{ args: []string{"-f127.0.0.1,3010;api;no-tls"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, connectPort: 3010, @@ -1284,7 +1284,7 @@ backend=127.0.0.1,3011 func TestH1APIBackendconfigBadMethod(t *testing.T) { opts := options{ args: []string{"-f127.0.0.1,3010;api;no-tls"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, connectPort: 3010, @@ -1325,7 +1325,7 @@ backend=127.0.0.1,3011 func TestH1APIConfigrevision(t *testing.T) { opts := options{ args: []string{"-f127.0.0.1,3010;api;no-tls"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, connectPort: 3010, @@ -1368,7 +1368,7 @@ func TestH1APIConfigrevision(t *testing.T) { func TestH1APINotFound(t *testing.T) { opts := options{ args: []string{"-f127.0.0.1,3010;api;no-tls"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, connectPort: 3010, @@ -1409,7 +1409,7 @@ backend=127.0.0.1,3011 func TestH1Healthmon(t *testing.T) { opts := options{ args: []string{"-f127.0.0.1,3011;healthmon;no-tls"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, connectPort: 3011, @@ -1434,7 +1434,7 @@ func TestH1Healthmon(t *testing.T) { func TestH1ResponseBeforeRequestEnd(t *testing.T) { opts := options{ args: []string{"--mruby-file=" + testDir + "/req-return.rb"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatal("request should not be forwarded") }, } @@ -1462,7 +1462,7 @@ func TestH1ResponseBeforeRequestEnd(t *testing.T) { // if the backend chunked encoded response ends prematurely. func TestH1H1ChunkedEndsPrematurely(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { hj, ok := w.(http.Hijacker) if !ok { http.Error(w, "Could not hijack the connection", http.StatusInternalServerError) @@ -1495,7 +1495,7 @@ func TestH1H1ChunkedEndsPrematurely(t *testing.T) { // request which contains malformed transfer-encoding. func TestH1H1RequestMalformedTransferEncoding(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward bad request") }, } @@ -1523,7 +1523,7 @@ func TestH1H1RequestMalformedTransferEncoding(t *testing.T) { // its response contains malformed transfer-encoding. func TestH1H1ResponseMalformedTransferEncoding(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { hj, ok := w.(http.Hijacker) if !ok { http.Error(w, "Could not hijack the connection", http.StatusInternalServerError) @@ -1559,7 +1559,7 @@ func TestH1H1ResponseMalformedTransferEncoding(t *testing.T) { // its response contains unknown transfer-encoding. func TestH1H1ResponseUnknownTransferEncoding(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { hj, ok := w.(http.Hijacker) if !ok { http.Error(w, "Could not hijack the connection", http.StatusInternalServerError) @@ -1607,7 +1607,7 @@ func TestH1H1ResponseUnknownTransferEncoding(t *testing.T) { // HTTP/1.0 request which contains transfer-encoding. func TestH1H1RequestHTTP10TransferEncoding(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward bad request") }, } diff --git a/integration-tests/nghttpx_http2_test.go b/integration-tests/nghttpx_http2_test.go index 5324a18..8cda1bc 100644 --- a/integration-tests/nghttpx_http2_test.go +++ b/integration-tests/nghttpx_http2_test.go @@ -40,7 +40,7 @@ func TestH2H1PlainGET(t *testing.T) { func TestH2H1AddXfp(t *testing.T) { opts := options{ args: []string{"--no-strip-incoming-x-forwarded-proto"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { xfp := r.Header.Get("X-Forwarded-Proto") if got, want := xfp, "foo, http"; got != want { t.Errorf("X-Forwarded-Proto = %q; want %q", got, want) @@ -72,7 +72,7 @@ func TestH2H1NoAddXfp(t *testing.T) { "--no-add-x-forwarded-proto", "--no-strip-incoming-x-forwarded-proto", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { xfp := r.Header.Get("X-Forwarded-Proto") if got, want := xfp, "foo"; got != want { t.Errorf("X-Forwarded-Proto = %q; want %q", got, want) @@ -100,7 +100,7 @@ func TestH2H1NoAddXfp(t *testing.T) { // x-forwarded-proto header field. func TestH2H1StripXfp(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { xfp := r.Header.Get("X-Forwarded-Proto") if got, want := xfp, "http"; got != want { t.Errorf("X-Forwarded-Proto = %q; want %q", got, want) @@ -129,7 +129,7 @@ func TestH2H1StripXfp(t *testing.T) { func TestH2H1StripNoAddXfp(t *testing.T) { opts := options{ args: []string{"--no-add-x-forwarded-proto"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, found := r.Header["X-Forwarded-Proto"]; found { t.Errorf("X-Forwarded-Proto = %q; want nothing", got) } @@ -157,7 +157,7 @@ func TestH2H1StripNoAddXfp(t *testing.T) { func TestH2H1AddXff(t *testing.T) { opts := options{ args: []string{"--add-x-forwarded-for"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { xff := r.Header.Get("X-Forwarded-For") want := "127.0.0.1" if xff != want { @@ -184,7 +184,7 @@ func TestH2H1AddXff(t *testing.T) { func TestH2H1AddXff2(t *testing.T) { opts := options{ args: []string{"--add-x-forwarded-for"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { xff := r.Header.Get("X-Forwarded-For") want := "host, 127.0.0.1" if xff != want { @@ -214,7 +214,7 @@ func TestH2H1AddXff2(t *testing.T) { func TestH2H1StripXff(t *testing.T) { opts := options{ args: []string{"--strip-incoming-x-forwarded-for"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if xff, found := r.Header["X-Forwarded-For"]; found { t.Errorf("X-Forwarded-For = %v; want nothing", xff) } @@ -245,7 +245,7 @@ func TestH2H1StripAddXff(t *testing.T) { "--strip-incoming-x-forwarded-for", "--add-x-forwarded-for", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { xff := r.Header.Get("X-Forwarded-For") want := "127.0.0.1" if xff != want { @@ -275,7 +275,7 @@ func TestH2H1StripAddXff(t *testing.T) { func TestH2H1AddForwardedObfuscated(t *testing.T) { opts := options{ args: []string{"--add-forwarded=by,for,host,proto"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { pattern := fmt.Sprintf(`by=_[^;]+;for=_[^;]+;host="127\.0\.0\.1:%v";proto=http`, serverPort) validFwd := regexp.MustCompile(pattern) got := r.Header.Get("Forwarded") @@ -304,7 +304,7 @@ func TestH2H1AddForwardedObfuscated(t *testing.T) { func TestH2H1AddForwardedByIP(t *testing.T) { opts := options{ args: []string{"--add-forwarded=by,for", "--forwarded-by=ip"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { pattern := fmt.Sprintf(`by="127\.0\.0\.1:%v";for=_[^;]+`, serverPort) validFwd := regexp.MustCompile(pattern) if got := r.Header.Get("Forwarded"); !validFwd.MatchString(got) { @@ -335,7 +335,7 @@ func TestH2H1AddForwardedForIP(t *testing.T) { "--forwarded-by=_alpha", "--forwarded-for=ip", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { want := fmt.Sprintf(`by=_alpha;for=127.0.0.1;host="127.0.0.1:%v";proto=http`, serverPort) if got := r.Header.Get("Forwarded"); got != want { t.Errorf("Forwarded = %v; want %v", got, want) @@ -362,7 +362,7 @@ func TestH2H1AddForwardedForIP(t *testing.T) { func TestH2H1AddForwardedMerge(t *testing.T) { opts := options{ args: []string{"--add-forwarded=proto"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("Forwarded"), `host=foo, proto=http`; got != want { t.Errorf("Forwarded = %v; want %v", got, want) } @@ -394,7 +394,7 @@ func TestH2H1AddForwardedStrip(t *testing.T) { "--strip-incoming-forwarded", "--add-forwarded=proto", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("Forwarded"), `proto=http`; got != want { t.Errorf("Forwarded = %v; want %v", got, want) } @@ -422,7 +422,7 @@ func TestH2H1AddForwardedStrip(t *testing.T) { func TestH2H1StripForwarded(t *testing.T) { opts := options{ args: []string{"--strip-incoming-forwarded"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, found := r.Header["Forwarded"]; found { t.Errorf("Forwarded = %v; want nothing", got) } @@ -454,7 +454,7 @@ func TestH2H1AddForwardedStatic(t *testing.T) { "--add-forwarded=by,for", "--forwarded-by=_alpha", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { pattern := `by=_alpha;for=_[^;]+` validFwd := regexp.MustCompile(pattern) if got := r.Header.Get("Forwarded"); !validFwd.MatchString(got) { @@ -480,7 +480,7 @@ func TestH2H1AddForwardedStatic(t *testing.T) { // from backend server. func TestH2H1GenerateVia(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("Via"), "2 nghttpx"; got != want { t.Errorf("Via: %v; want %v", got, want) } @@ -639,7 +639,7 @@ func TestH2H1BadRequestCL(t *testing.T) { // response body size. func TestH2H1BadResponseCL(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { // we set content-length: 1024, but only send 3 bytes. w.Header().Add("Content-Length", "1024") if _, err := w.Write([]byte("foo")); err != nil { @@ -667,7 +667,7 @@ func TestH2H1BadResponseCL(t *testing.T) { // works. func TestH2H1LocationRewrite(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { // TODO we cannot get st.ts's port number // here.. 8443 is just a place holder. We // ignore it on rewrite. @@ -693,7 +693,7 @@ func TestH2H1LocationRewrite(t *testing.T) { // TestH2H1ChunkedRequestBody tests that chunked request body works. func TestH2H1ChunkedRequestBody(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { want := "[chunked]" if got := fmt.Sprint(r.TransferEncoding); got != want { t.Errorf("Transfer-Encoding: %v; want %v", got, want) @@ -728,7 +728,7 @@ func TestH2H1ChunkedRequestBody(t *testing.T) { // multiple Content-Length request header fields. func TestH2H1MultipleRequestCL(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward bad request") }, } @@ -754,7 +754,7 @@ func TestH2H1MultipleRequestCL(t *testing.T) { // Content-Length which cannot be parsed as a number. func TestH2H1InvalidRequestCL(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward bad request") }, } @@ -800,7 +800,7 @@ func TestH2H1InvalidRequestCL(t *testing.T) { // 501. func TestH2H1InvalidMethod(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward this request") }, } @@ -823,7 +823,7 @@ func TestH2H1InvalidMethod(t *testing.T) { // bad characters in :authority header field. func TestH2H1BadAuthority(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward this request") }, } @@ -846,7 +846,7 @@ func TestH2H1BadAuthority(t *testing.T) { // bad characters in :scheme header field. func TestH2H1BadScheme(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward this request") }, } @@ -869,7 +869,7 @@ func TestH2H1BadScheme(t *testing.T) { // request is assembled into 1 when forwarding to HTTP/1 backend link. func TestH2H1AssembleCookies(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("Cookie"), "alpha; bravo; charlie"; got != want { t.Errorf("Cookie: %v; want %v", got, want) } @@ -918,7 +918,7 @@ func TestH2H1TETrailers(t *testing.T) { // field contains gzip. func TestH2H1TEGzip(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Error("server should not forward bad request") }, } @@ -967,7 +967,7 @@ func TestH2H1SNI(t *testing.T) { // connection is encrypted. func TestH2H1TLSXfp(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("x-forwarded-proto"), "http"; got != want { t.Errorf("x-forwarded-proto: want %v; got %v", want, got) } @@ -1028,7 +1028,7 @@ func TestH2H1ServerPush(t *testing.T) { // backend. func TestH2H1RequestTrailer(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { buf := make([]byte, 4096) for { _, err := r.Body.Read(buf) @@ -1067,7 +1067,7 @@ func TestH2H1RequestTrailer(t *testing.T) { func TestH2H1HeaderFieldBuffer(t *testing.T) { opts := options{ args: []string{"--request-header-field-buffer=10"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatal("execution path should not be here") }, } @@ -1090,7 +1090,7 @@ func TestH2H1HeaderFieldBuffer(t *testing.T) { func TestH2H1HeaderFields(t *testing.T) { opts := options{ args: []string{"--max-request-header-fields=1"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatal("execution path should not be here") }, } @@ -1115,7 +1115,7 @@ func TestH2H1HeaderFields(t *testing.T) { func TestH2H1ReqPhaseSetHeader(t *testing.T) { opts := options{ args: []string{"--mruby-file=" + testDir + "/req-set-header.rb"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("User-Agent"), "mruby"; got != want { t.Errorf("User-Agent = %v; want %v", got, want) } @@ -1141,7 +1141,7 @@ func TestH2H1ReqPhaseSetHeader(t *testing.T) { func TestH2H1ReqPhaseReturn(t *testing.T) { opts := options{ args: []string{"--mruby-file=" + testDir + "/req-return.rb"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, } @@ -1284,7 +1284,7 @@ func TestH2H1ProxyProtocolV1ForwardedForObfuscated(t *testing.T) { "--add-forwarded=for", "--forwarded-for=obfuscated", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got := r.Header.Get("Forwarded"); !validFwd.MatchString(got) { t.Errorf("Forwarded: %v; want pattern %v", got, pattern) } @@ -1321,7 +1321,7 @@ func TestH2H1ProxyProtocolV1TCP4(t *testing.T) { "--add-forwarded=for", "--forwarded-for=ip", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("X-Forwarded-For"), "192.168.0.2"; got != want { t.Errorf("X-Forwarded-For: %v; want %v", got, want) } @@ -1361,7 +1361,7 @@ func TestH2H1ProxyProtocolV1TCP6(t *testing.T) { "--add-forwarded=for", "--forwarded-for=ip", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("X-Forwarded-For"), "2001:0db8:85a3:0000:0000:8a2e:0370:7334"; got != want { t.Errorf("X-Forwarded-For: %v; want %v", got, want) } @@ -1401,7 +1401,7 @@ func TestH2H1ProxyProtocolV1TCP4TLS(t *testing.T) { "--add-forwarded=for", "--forwarded-for=ip", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("X-Forwarded-For"), "192.168.0.2"; got != want { t.Errorf("X-Forwarded-For: %v; want %v", got, want) } @@ -1439,7 +1439,7 @@ func TestH2H1ProxyProtocolV1TCP6TLS(t *testing.T) { "--add-forwarded=for", "--forwarded-for=ip", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("X-Forwarded-For"), "2001:0db8:85a3:0000:0000:8a2e:0370:7334"; got != want { t.Errorf("X-Forwarded-For: %v; want %v", got, want) } @@ -1476,7 +1476,7 @@ func TestH2H1ProxyProtocolV1Unknown(t *testing.T) { "--add-forwarded=for", "--forwarded-for=ip", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, notWant := r.Header.Get("X-Forwarded-For"), "192.168.0.2"; got == notWant { t.Errorf("X-Forwarded-For: %v; want something else", got) } @@ -1881,7 +1881,7 @@ func TestH2H1ProxyProtocolV2TCP4(t *testing.T) { "--add-forwarded=for", "--forwarded-for=ip", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("X-Forwarded-For"), "192.168.0.2"; got != want { t.Errorf("X-Forwarded-For: %v; want %v", got, want) } @@ -1937,7 +1937,7 @@ func TestH2H1ProxyProtocolV2TCP6(t *testing.T) { "--add-forwarded=for", "--forwarded-for=ip", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("X-Forwarded-For"), "2001:db8:85a3::8a2e:370:7334"; got != want { t.Errorf("X-Forwarded-For: %v; want %v", got, want) } @@ -2009,7 +2009,7 @@ func TestH2H1ProxyProtocolV2TCP4TLS(t *testing.T) { "--add-forwarded=for", "--forwarded-for=ip", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("X-Forwarded-For"), "192.168.0.2"; got != want { t.Errorf("X-Forwarded-For: %v; want %v", got, want) } @@ -2063,7 +2063,7 @@ func TestH2H1ProxyProtocolV2TCP6TLS(t *testing.T) { "--add-forwarded=for", "--forwarded-for=ip", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("X-Forwarded-For"), "2001:db8:85a3::8a2e:370:7334"; got != want { t.Errorf("X-Forwarded-For: %v; want %v", got, want) } @@ -2100,7 +2100,7 @@ func TestH2H1ProxyProtocolV2Local(t *testing.T) { "--add-forwarded=for", "--forwarded-for=ip", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("X-Forwarded-For"), "127.0.0.1"; got != want { t.Errorf("X-Forwarded-For: %v; want %v", got, want) } @@ -2193,7 +2193,7 @@ func TestH2H1ProxyProtocolV2Unix(t *testing.T) { "--add-forwarded=for", "--forwarded-for=ip", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("X-Forwarded-For"), "127.0.0.1"; got != want { t.Errorf("X-Forwarded-For: %v; want %v", got, want) } @@ -2248,7 +2248,7 @@ func TestH2H1ProxyProtocolV2Unspec(t *testing.T) { "--add-forwarded=for", "--forwarded-for=ip", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("X-Forwarded-For"), "127.0.0.1"; got != want { t.Errorf("X-Forwarded-For: %v; want %v", got, want) } @@ -2383,7 +2383,7 @@ func TestH2H1HTTPSRedirectPort(t *testing.T) { // transfer-encoding is valid. func TestH2H1Code204(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNoContent) }, } @@ -2406,7 +2406,7 @@ func TestH2H1Code204(t *testing.T) { // is allowed. func TestH2H1Code204CL0(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { hj, ok := w.(http.Hijacker) if !ok { http.Error(w, "Could not hijack the connection", http.StatusInternalServerError) @@ -2447,7 +2447,7 @@ func TestH2H1Code204CL0(t *testing.T) { // content-length is not allowed. func TestH2H1Code204CLNonzero(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { hj, ok := w.(http.Hijacker) if !ok { http.Error(w, "Could not hijack the connection", http.StatusInternalServerError) @@ -2484,7 +2484,7 @@ func TestH2H1Code204CLNonzero(t *testing.T) { // not allowed. func TestH2H1Code204TE(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { hj, ok := w.(http.Hijacker) if !ok { http.Error(w, "Could not hijack the connection", http.StatusInternalServerError) @@ -2659,7 +2659,7 @@ func TestH2H1GracefulShutdown(t *testing.T) { func TestH2H2MultipleResponseCL(t *testing.T) { opts := options{ args: []string{"--http2-bridge"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { w.Header().Add("content-length", "1") w.Header().Add("content-length", "1") }, @@ -2684,7 +2684,7 @@ func TestH2H2MultipleResponseCL(t *testing.T) { func TestH2H2InvalidResponseCL(t *testing.T) { opts := options{ args: []string{"--http2-bridge"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { w.Header().Add("content-length", "") }, } @@ -2783,7 +2783,7 @@ func TestH2H2NoHostRewrite(t *testing.T) { func TestH2H2TLSXfp(t *testing.T) { opts := options{ args: []string{"--http2-bridge"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("x-forwarded-proto"), "http"; got != want { t.Errorf("x-forwarded-proto: want %v; got %v", want, got) } @@ -2812,7 +2812,7 @@ func TestH2H2AddXfp(t *testing.T) { "--http2-bridge", "--no-strip-incoming-x-forwarded-proto", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { xfp := r.Header.Get("X-Forwarded-Proto") if got, want := xfp, "foo, http"; got != want { t.Errorf("X-Forwarded-Proto = %q; want %q", got, want) @@ -2846,7 +2846,7 @@ func TestH2H2NoAddXfp(t *testing.T) { "--no-add-x-forwarded-proto", "--no-strip-incoming-x-forwarded-proto", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { xfp := r.Header.Get("X-Forwarded-Proto") if got, want := xfp, "foo"; got != want { t.Errorf("X-Forwarded-Proto = %q; want %q", got, want) @@ -2876,7 +2876,7 @@ func TestH2H2NoAddXfp(t *testing.T) { func TestH2H2StripXfp(t *testing.T) { opts := options{ args: []string{"--http2-bridge"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { xfp := r.Header.Get("X-Forwarded-Proto") if got, want := xfp, "http"; got != want { t.Errorf("X-Forwarded-Proto = %q; want %q", got, want) @@ -2906,7 +2906,7 @@ func TestH2H2StripXfp(t *testing.T) { func TestH2H2StripNoAddXfp(t *testing.T) { opts := options{ args: []string{"--http2-bridge", "--no-add-x-forwarded-proto"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, found := r.Header["X-Forwarded-Proto"]; found { t.Errorf("X-Forwarded-Proto = %q; want nothing", got) } @@ -2935,7 +2935,7 @@ func TestH2H2StripNoAddXfp(t *testing.T) { func TestH2H2AddXff(t *testing.T) { opts := options{ args: []string{"--http2-bridge", "--add-x-forwarded-for"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { xff := r.Header.Get("X-Forwarded-For") want := "127.0.0.1" if xff != want { @@ -2963,7 +2963,7 @@ func TestH2H2AddXff(t *testing.T) { func TestH2H2AddXff2(t *testing.T) { opts := options{ args: []string{"--http2-bridge", "--add-x-forwarded-for"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { xff := r.Header.Get("X-Forwarded-For") want := "host, 127.0.0.1" if xff != want { @@ -2997,7 +2997,7 @@ func TestH2H2StripXff(t *testing.T) { "--http2-bridge", "--strip-incoming-x-forwarded-for", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if xff, found := r.Header["X-Forwarded-For"]; found { t.Errorf("X-Forwarded-For = %v; want nothing", xff) } @@ -3030,7 +3030,7 @@ func TestH2H2StripAddXff(t *testing.T) { "--strip-incoming-x-forwarded-for", "--add-x-forwarded-for", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { xff := r.Header.Get("X-Forwarded-For") want := "127.0.0.1" if xff != want { @@ -3065,7 +3065,7 @@ func TestH2H2AddForwarded(t *testing.T) { "--add-forwarded=by,for,host,proto", "--forwarded-by=_alpha", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { pattern := fmt.Sprintf(`by=_alpha;for=_[^;]+;host="127\.0\.0\.1:%v";proto=https`, serverPort) validFwd := regexp.MustCompile(pattern) if got := r.Header.Get("Forwarded"); !validFwd.MatchString(got) { @@ -3099,7 +3099,7 @@ func TestH2H2AddForwardedMerge(t *testing.T) { "--add-forwarded=by,host,proto", "--forwarded-by=_alpha", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { want := fmt.Sprintf(`host=foo, by=_alpha;host="127.0.0.1:%v";proto=https`, serverPort) if got := r.Header.Get("Forwarded"); got != want { t.Errorf("Forwarded = %v; want %v", got, want) @@ -3136,7 +3136,7 @@ func TestH2H2AddForwardedStrip(t *testing.T) { "--add-forwarded=by,host,proto", "--forwarded-by=_alpha", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { want := fmt.Sprintf(`by=_alpha;host="127.0.0.1:%v";proto=https`, serverPort) if got := r.Header.Get("Forwarded"); got != want { t.Errorf("Forwarded = %v; want %v", got, want) @@ -3167,7 +3167,7 @@ func TestH2H2AddForwardedStrip(t *testing.T) { func TestH2H2StripForwarded(t *testing.T) { opts := options{ args: []string{"--http2-bridge", "--strip-incoming-forwarded"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, found := r.Header["Forwarded"]; found { t.Errorf("Forwarded = %v; want nothing", got) } @@ -3200,7 +3200,7 @@ func TestH2H2ReqPhaseReturn(t *testing.T) { "--http2-bridge", "--mruby-file=" + testDir + "/req-return.rb", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, } @@ -3322,7 +3322,7 @@ func TestH2H2DNS(t *testing.T) { func TestH2H2Code204(t *testing.T) { opts := options{ args: []string{"--http2-bridge"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNoContent) }, } @@ -3346,7 +3346,7 @@ func TestH2H2Code204(t *testing.T) { func TestH2APIBackendconfig(t *testing.T) { opts := options{ args: []string{"-f127.0.0.1,3010;api;no-tls"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, connectPort: 3010, @@ -3388,7 +3388,7 @@ backend=127.0.0.1,3011 func TestH2APIBackendconfigQuery(t *testing.T) { opts := options{ args: []string{"-f127.0.0.1,3010;api;no-tls"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, connectPort: 3010, @@ -3430,7 +3430,7 @@ backend=127.0.0.1,3011 func TestH2APIBackendconfigBadMethod(t *testing.T) { opts := options{ args: []string{"-f127.0.0.1,3010;api;no-tls"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, connectPort: 3010, @@ -3471,7 +3471,7 @@ backend=127.0.0.1,3011 func TestH2APIConfigrevision(t *testing.T) { opts := options{ args: []string{"-f127.0.0.1,3010;api;no-tls"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, connectPort: 3010, @@ -3514,7 +3514,7 @@ func TestH2APIConfigrevision(t *testing.T) { func TestH2APINotFound(t *testing.T) { opts := options{ args: []string{"-f127.0.0.1,3010;api;no-tls"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, connectPort: 3010, @@ -3555,7 +3555,7 @@ backend=127.0.0.1,3011 func TestH2Healthmon(t *testing.T) { opts := options{ args: []string{"-f127.0.0.1,3011;healthmon;no-tls"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, connectPort: 3011, @@ -3580,7 +3580,7 @@ func TestH2Healthmon(t *testing.T) { func TestH2ResponseBeforeRequestEnd(t *testing.T) { opts := options{ args: []string{"--mruby-file=" + testDir + "/req-return.rb"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatal("request should not be forwarded") }, } @@ -3603,7 +3603,7 @@ func TestH2ResponseBeforeRequestEnd(t *testing.T) { // backend chunked encoded response ends prematurely. func TestH2H1ChunkedEndsPrematurely(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { hj, ok := w.(http.Hijacker) if !ok { http.Error(w, "Could not hijack the connection", http.StatusInternalServerError) @@ -3641,7 +3641,7 @@ func TestH2H1ChunkedEndsPrematurely(t *testing.T) { func TestH2H1RequireHTTPSchemeHTTPSWithoutEncryption(t *testing.T) { opts := options{ args: []string{"--require-http-scheme"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward this request") }, } @@ -3666,7 +3666,7 @@ func TestH2H1RequireHTTPSchemeHTTPSWithoutEncryption(t *testing.T) { func TestH2H1RequireHTTPSchemeHTTPWithEncryption(t *testing.T) { opts := options{ args: []string{"--require-http-scheme"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward this request") }, tls: true, @@ -3693,7 +3693,7 @@ func TestH2H1RequireHTTPSchemeHTTPWithEncryption(t *testing.T) { func TestH2H1RequireHTTPSchemeUnknownSchemeWithoutEncryption(t *testing.T) { opts := options{ args: []string{"--require-http-scheme"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward this request") }, } @@ -3718,7 +3718,7 @@ func TestH2H1RequireHTTPSchemeUnknownSchemeWithoutEncryption(t *testing.T) { func TestH2H1RequireHTTPSchemeUnknownSchemeWithEncryption(t *testing.T) { opts := options{ args: []string{"--require-http-scheme"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Errorf("server should not forward this request") }, tls: true, diff --git a/integration-tests/nghttpx_http3_test.go b/integration-tests/nghttpx_http3_test.go index 9ea85d7..757c96f 100644 --- a/integration-tests/nghttpx_http3_test.go +++ b/integration-tests/nghttpx_http3_test.go @@ -41,7 +41,7 @@ func TestH3H1RequestBody(t *testing.T) { } opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { buf := make([]byte, 4096) buflen := 0 p := buf @@ -92,7 +92,7 @@ func TestH3H1RequestBody(t *testing.T) { // and from backend server. func TestH3H1GenerateVia(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(_ http.ResponseWriter, r *http.Request) { if got, want := r.Header.Get("Via"), "3 nghttpx"; got != want { t.Errorf("Via: %v; want %v", got, want) } @@ -177,7 +177,7 @@ func TestH3H1NoVia(t *testing.T) { // response body size. func TestH3H1BadResponseCL(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { // we set content-length: 1024, but only send 3 bytes. w.Header().Add("Content-Length", "1024") if _, err := w.Write([]byte("foo")); err != nil { @@ -256,7 +256,7 @@ func TestH3H2ReqPhaseReturn(t *testing.T) { "--http2-bridge", "--mruby-file=" + testDir + "/req-return.rb", }, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatalf("request should not be forwarded") }, quic: true, @@ -338,7 +338,7 @@ func TestH3H2RespPhaseReturn(t *testing.T) { func TestH3ResponseBeforeRequestEnd(t *testing.T) { opts := options{ args: []string{"--mruby-file=" + testDir + "/req-return.rb"}, - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(http.ResponseWriter, *http.Request) { t.Fatal("request should not be forwarded") }, quic: true, @@ -362,7 +362,7 @@ func TestH3ResponseBeforeRequestEnd(t *testing.T) { // backend chunked encoded response ends prematurely. func TestH3H1ChunkedEndsPrematurely(t *testing.T) { opts := options{ - handler: func(w http.ResponseWriter, r *http.Request) { + handler: func(w http.ResponseWriter, _ *http.Request) { hj, ok := w.(http.Hijacker) if !ok { http.Error(w, "Could not hijack the connection", http.StatusInternalServerError) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 4180748..211c8e4 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -31,6 +31,8 @@ set(NGHTTP2_SOURCES ) set(NGHTTP2_RES "") +set(STATIC_LIB "nghttp2_static") +set(SHARED_LIB "nghttp2") if(WIN32) configure_file( @@ -41,40 +43,61 @@ if(WIN32) set(NGHTTP2_RES ${CMAKE_CURRENT_BINARY_DIR}/version.rc) endif() +set(EXPORT_SET "${PROJECT_NAME}-targets") + # Public shared library -if(ENABLE_SHARED_LIB) - add_library(nghttp2 SHARED ${NGHTTP2_SOURCES} ${NGHTTP2_RES}) - set_target_properties(nghttp2 PROPERTIES +if(BUILD_SHARED_LIBS) + add_library(${SHARED_LIB} SHARED ${NGHTTP2_SOURCES} ${NGHTTP2_RES}) + + set_target_properties(${SHARED_LIB} PROPERTIES COMPILE_FLAGS "${WARNCFLAGS}" VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION} C_VISIBILITY_PRESET hidden ) - target_include_directories(nghttp2 INTERFACE - "${CMAKE_CURRENT_BINARY_DIR}/includes" - "${CMAKE_CURRENT_SOURCE_DIR}/includes" + + target_include_directories(${SHARED_LIB} INTERFACE + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/includes> + $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/includes> + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> ) - install(TARGETS nghttp2 - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + install(TARGETS ${SHARED_LIB} EXPORT ${EXPORT_SET}) + list(APPEND nghttp2_exports ${SHARED_LIB}) endif() -if(HAVE_CUNIT OR ENABLE_STATIC_LIB) - # Static library (for unittests because of symbol visibility) - add_library(nghttp2_static STATIC ${NGHTTP2_SOURCES}) - set_target_properties(nghttp2_static PROPERTIES - COMPILE_FLAGS "${WARNCFLAGS}" - VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION} - ARCHIVE_OUTPUT_NAME nghttp2${STATIC_LIB_SUFFIX} - ) - target_compile_definitions(nghttp2_static PUBLIC "-DNGHTTP2_STATICLIB") - if(ENABLE_STATIC_LIB) - install(TARGETS nghttp2_static - DESTINATION "${CMAKE_INSTALL_LIBDIR}") - endif() +# Static library (for unittests because of symbol visibility) +add_library(${STATIC_LIB} STATIC ${NGHTTP2_SOURCES}) + +set_target_properties(${STATIC_LIB} PROPERTIES + COMPILE_FLAGS "${WARNCFLAGS}" + VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION} + ARCHIVE_OUTPUT_NAME nghttp2${STATIC_LIB_SUFFIX} +) + +target_include_directories(${STATIC_LIB} INTERFACE + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/includes> + $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/includes> + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> +) + +target_compile_definitions(${STATIC_LIB} PUBLIC "-DNGHTTP2_STATICLIB") + +if(BUILD_STATIC_LIBS) + install(TARGETS ${STATIC_LIB} EXPORT ${EXPORT_SET}) + list(APPEND nghttp2_exports ${STATIC_LIB}) endif() +if(BUILD_SHARED_LIBS) + set(LIB_SELECTED ${SHARED_LIB}) +else() + set(LIB_SELECTED ${STATIC_LIB}) +endif() + +add_library(${PROJECT_NAME}::nghttp2 ALIAS ${LIB_SELECTED}) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libnghttp2.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + +install(EXPORT ${EXPORT_SET} + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} + NAMESPACE ${PROJECT_NAME}::) diff --git a/lib/includes/nghttp2/nghttp2.h b/lib/includes/nghttp2/nghttp2.h index 7910db2..8891760 100644 --- a/lib/includes/nghttp2/nghttp2.h +++ b/lib/includes/nghttp2/nghttp2.h @@ -51,6 +51,7 @@ extern "C" { #endif /* !defined(_MSC_VER) || (_MSC_VER >= 1800) */ #include <sys/types.h> #include <stdarg.h> +#include <stddef.h> #include <nghttp2/nghttp2ver.h> @@ -72,6 +73,13 @@ extern "C" { #endif /* !defined(WIN32) */ /** + * @typedef + * + * :type:`nghttp2_ssize` is a signed counterpart of size_t. + */ +typedef ptrdiff_t nghttp2_ssize; + +/** * @macro * * The protocol version identification string of this library @@ -168,6 +176,12 @@ typedef struct { /** * @macro * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. + * * The default weight of stream dependency. */ #define NGHTTP2_DEFAULT_WEIGHT 16 @@ -175,6 +189,12 @@ typedef struct { /** * @macro * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. + * * The maximum weight of stream dependency. */ #define NGHTTP2_MAX_WEIGHT 256 @@ -182,6 +202,12 @@ typedef struct { /** * @macro * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. + * * The minimum weight of stream dependency. */ #define NGHTTP2_MIN_WEIGHT 1 @@ -255,7 +281,7 @@ typedef enum { */ NGHTTP2_ERR_UNSUPPORTED_VERSION = -503, /** - * Used as a return value from :type:`nghttp2_send_callback`, + * Used as a return value from :type:`nghttp2_send_callback2`, * :type:`nghttp2_recv_callback` and * :type:`nghttp2_send_data_callback` to indicate that the operation * would block. @@ -275,9 +301,9 @@ typedef enum { NGHTTP2_ERR_EOF = -507, /** * Used as a return value from - * :func:`nghttp2_data_source_read_callback` to indicate that data + * :func:`nghttp2_data_source_read_callback2` to indicate that data * transfer is postponed. See - * :func:`nghttp2_data_source_read_callback` for details. + * :func:`nghttp2_data_source_read_callback2` for details. */ NGHTTP2_ERR_DEFERRED = -508, /** @@ -830,7 +856,7 @@ typedef struct { * @union * * This union represents the some kind of data source passed to - * :type:`nghttp2_data_source_read_callback`. + * :type:`nghttp2_data_source_read_callback2`. */ typedef union { /** @@ -847,7 +873,7 @@ typedef union { * @enum * * The flags used to set in |data_flags| output parameter in - * :type:`nghttp2_data_source_read_callback`. + * :type:`nghttp2_data_source_read_callback2`. */ typedef enum { /** @@ -861,8 +887,8 @@ typedef enum { /** * Indicates that END_STREAM flag must not be set even if * NGHTTP2_DATA_FLAG_EOF is set. Usually this flag is used to send - * trailer fields with `nghttp2_submit_request()` or - * `nghttp2_submit_response()`. + * trailer fields with `nghttp2_submit_request2()` or + * `nghttp2_submit_response2()`. */ NGHTTP2_DATA_FLAG_NO_END_STREAM = 0x02, /** @@ -872,9 +898,15 @@ typedef enum { NGHTTP2_DATA_FLAG_NO_COPY = 0x04 } nghttp2_data_flag; +#ifndef NGHTTP2_NO_SSIZE_T /** * @functypedef * + * .. warning:: + * + * Deprecated. Use :type:`nghttp2_data_source_read_callback2` + * instead. + * * Callback function invoked when the library wants to read data from * the |source|. The read data is sent in the stream |stream_id|. * The implementation of this function must read at most |length| @@ -939,9 +971,83 @@ typedef ssize_t (*nghttp2_data_source_read_callback)( nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t length, uint32_t *data_flags, nghttp2_data_source *source, void *user_data); +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @functypedef + * + * Callback function invoked when the library wants to read data from + * the |source|. The read data is sent in the stream |stream_id|. + * The implementation of this function must read at most |length| + * bytes of data from |source| (or possibly other places) and store + * them in |buf| and return number of data stored in |buf|. If EOF is + * reached, set :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF` flag + * in |*data_flags|. + * + * Sometime it is desirable to avoid copying data into |buf| and let + * application to send data directly. To achieve this, set + * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_COPY` to + * |*data_flags| (and possibly other flags, just like when we do + * copy), and return the number of bytes to send without copying data + * into |buf|. The library, seeing + * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_COPY`, will invoke + * :type:`nghttp2_send_data_callback`. The application must send + * complete DATA frame in that callback. + * + * If this callback is set by `nghttp2_submit_request2()`, + * `nghttp2_submit_response2()` or `nghttp2_submit_headers()` and + * `nghttp2_submit_data2()` with flag parameter + * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM` set, and + * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF` flag is set to + * |*data_flags|, DATA frame will have END_STREAM flag set. Usually, + * this is expected behaviour and all are fine. One exception is send + * trailer fields. You cannot send trailer fields after sending frame + * with END_STREAM set. To avoid this problem, one can set + * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_END_STREAM` along + * with :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF` to signal the + * library not to set END_STREAM in DATA frame. Then application can + * use `nghttp2_submit_trailer()` to send trailer fields. + * `nghttp2_submit_trailer()` can be called inside this callback. + * + * If the application wants to postpone DATA frames (e.g., + * asynchronous I/O, or reading data blocks for long time), it is + * achieved by returning :enum:`nghttp2_error.NGHTTP2_ERR_DEFERRED` + * without reading any data in this invocation. The library removes + * DATA frame from the outgoing queue temporarily. To move back + * deferred DATA frame to outgoing queue, call + * `nghttp2_session_resume_data()`. + * + * By default, |length| is limited to 16KiB at maximum. If peer + * allows larger frames, application can enlarge transmission buffer + * size. See :type:`nghttp2_data_source_read_length_callback` for + * more details. + * + * If the application just wants to return from + * `nghttp2_session_send()` or `nghttp2_session_mem_send2()` without + * sending anything, return :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE`. + * + * In case of error, there are 2 choices. Returning + * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE` will + * close the stream by issuing RST_STREAM with + * :enum:`nghttp2_error_code.NGHTTP2_INTERNAL_ERROR`. If a different + * error code is desirable, use `nghttp2_submit_rst_stream()` with a + * desired error code and then return + * :enum:`nghttp2_error.NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE`. + * Returning :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` will + * signal the entire session failure. + */ +typedef nghttp2_ssize (*nghttp2_data_source_read_callback2)( + nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t length, + uint32_t *data_flags, nghttp2_data_source *source, void *user_data); + +#ifndef NGHTTP2_NO_SSIZE_T /** * @struct * + * .. warning:: + * + * Deprecated. Use :type:`nghttp2_data_provider2` instead. + * * This struct represents the data source and the way to read a chunk * of data from it. */ @@ -956,6 +1062,25 @@ typedef struct { nghttp2_data_source_read_callback read_callback; } nghttp2_data_provider; +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @struct + * + * This struct represents the data source and the way to read a chunk + * of data from it. + */ +typedef struct { + /** + * The data source. + */ + nghttp2_data_source source; + /** + * The callback function to read a chunk of data from the |source|. + */ + nghttp2_data_source_read_callback2 read_callback; +} nghttp2_data_provider2; + /** * @struct * @@ -1008,6 +1133,12 @@ typedef enum { /** * @struct * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. + * * The structure to specify stream dependency. */ typedef struct { @@ -1042,6 +1173,12 @@ typedef struct { */ size_t padlen; /** + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. + * * The priority specification */ nghttp2_priority_spec pri_spec; @@ -1062,6 +1199,12 @@ typedef struct { /** * @struct * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. + * * The PRIORITY frame. It has the following members: */ typedef struct { @@ -1305,9 +1448,14 @@ typedef union { nghttp2_extension ext; } nghttp2_frame; +#ifndef NGHTTP2_NO_SSIZE_T /** * @functypedef * + * .. warning:: + * + * Deprecated. Use :type:`nghttp2_send_callback2` instead. + * * Callback function invoked when |session| wants to send data to the * remote peer. The implementation of this function must send at most * |length| bytes of data stored in |data|. The |flags| is currently @@ -1340,6 +1488,44 @@ typedef ssize_t (*nghttp2_send_callback)(nghttp2_session *session, const uint8_t *data, size_t length, int flags, void *user_data); +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @functypedef + * + * Callback function invoked when |session| wants to send data to the + * remote peer. The implementation of this function must send at most + * |length| bytes of data stored in |data|. The |flags| is currently + * not used and always 0. It must return the number of bytes sent if + * it succeeds. If it cannot send any single byte without blocking, + * it must return :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`. For + * other errors, it must return + * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. The + * |user_data| pointer is the third argument passed in to the call to + * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`. + * + * This callback is required if the application uses + * `nghttp2_session_send()` to send data to the remote endpoint. If + * the application uses solely `nghttp2_session_mem_send2()` instead, + * this callback function is unnecessary. + * + * To set this callback to :type:`nghttp2_session_callbacks`, use + * `nghttp2_session_callbacks_set_send_callback2()`. + * + * .. note:: + * + * The |length| may be very small. If that is the case, and + * application disables Nagle algorithm (``TCP_NODELAY``), then just + * writing |data| to the network stack leads to very small packet, + * and it is very inefficient. An application should be responsible + * to buffer up small chunks of data as necessary to avoid this + * situation. + */ +typedef nghttp2_ssize (*nghttp2_send_callback2)(nghttp2_session *session, + const uint8_t *data, + size_t length, int flags, + void *user_data); + /** * @functypedef * @@ -1370,7 +1556,7 @@ typedef ssize_t (*nghttp2_send_callback)(nghttp2_session *session, * error; if partial frame data has already sent, it is impossible to * send another data in that state, and all we can do is tear down * connection). When data is fully processed, but application wants - * to make `nghttp2_session_mem_send()` or `nghttp2_session_send()` + * to make `nghttp2_session_mem_send2()` or `nghttp2_session_send()` * return immediately without processing next frames, return * :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE`. If application decided to * reset this stream, return @@ -1387,9 +1573,14 @@ typedef int (*nghttp2_send_data_callback)(nghttp2_session *session, nghttp2_data_source *source, void *user_data); +#ifndef NGHTTP2_NO_SSIZE_T /** * @functypedef * + * .. warning:: + * + * Deprecated. Use :type:`nghttp2_recv_callback2` instead. + * * Callback function invoked when |session| wants to receive data from * the remote peer. The implementation of this function must read at * most |length| bytes of data and store it in |buf|. The |flags| is @@ -1417,11 +1608,43 @@ typedef ssize_t (*nghttp2_recv_callback)(nghttp2_session *session, uint8_t *buf, size_t length, int flags, void *user_data); +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @functypedef + * + * Callback function invoked when |session| wants to receive data from + * the remote peer. The implementation of this function must read at + * most |length| bytes of data and store it in |buf|. The |flags| is + * currently not used and always 0. It must return the number of + * bytes written in |buf| if it succeeds. If it cannot read any + * single byte without blocking, it must return + * :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`. If it gets EOF + * before it reads any single byte, it must return + * :enum:`nghttp2_error.NGHTTP2_ERR_EOF`. For other errors, it must + * return :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. + * Returning 0 is treated as + * :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`. The |user_data| + * pointer is the third argument passed in to the call to + * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`. + * + * This callback is required if the application uses + * `nghttp2_session_recv()` to receive data from the remote endpoint. + * If the application uses solely `nghttp2_session_mem_recv2()` + * instead, this callback function is unnecessary. + * + * To set this callback to :type:`nghttp2_session_callbacks`, use + * `nghttp2_session_callbacks_set_recv_callback2()`. + */ +typedef nghttp2_ssize (*nghttp2_recv_callback2)(nghttp2_session *session, + uint8_t *buf, size_t length, + int flags, void *user_data); + /** * @functypedef * * Callback function invoked by `nghttp2_session_recv()` and - * `nghttp2_session_mem_recv()` when a frame is received. The + * `nghttp2_session_mem_recv2()` when a frame is received. The * |user_data| pointer is the third argument passed in to the call to * `nghttp2_session_client_new()` or `nghttp2_session_server_new()`. * @@ -1439,8 +1662,8 @@ typedef ssize_t (*nghttp2_recv_callback)(nghttp2_session *session, uint8_t *buf, * * The implementation of this function must return 0 if it succeeds. * If nonzero value is returned, it is treated as fatal error and - * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions - * immediately return + * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()` + * functions immediately return * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. * * To set this callback to :type:`nghttp2_session_callbacks`, use @@ -1454,7 +1677,7 @@ typedef int (*nghttp2_on_frame_recv_callback)(nghttp2_session *session, * @functypedef * * Callback function invoked by `nghttp2_session_recv()` and - * `nghttp2_session_mem_recv()` when an invalid non-DATA frame is + * `nghttp2_session_mem_recv2()` when an invalid non-DATA frame is * received. The error is indicated by the |lib_error_code|, which is * one of the values defined in :type:`nghttp2_error`. When this * callback function is invoked, the library automatically submits @@ -1468,8 +1691,8 @@ typedef int (*nghttp2_on_frame_recv_callback)(nghttp2_session *session, * * The implementation of this function must return 0 if it succeeds. * If nonzero is returned, it is treated as fatal error and - * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions - * immediately return + * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()` + * functions immediately return * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. * * To set this callback to :type:`nghttp2_session_callbacks`, use @@ -1492,19 +1715,19 @@ typedef int (*nghttp2_on_invalid_frame_recv_callback)( * argument passed in to the call to `nghttp2_session_client_new()` or * `nghttp2_session_server_new()`. * - * If the application uses `nghttp2_session_mem_recv()`, it can return - * :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` to make - * `nghttp2_session_mem_recv()` return without processing further + * If the application uses `nghttp2_session_mem_recv2()`, it can + * return :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` to make + * `nghttp2_session_mem_recv2()` return without processing further * input bytes. The memory by pointed by the |data| is retained until - * `nghttp2_session_mem_recv()` or `nghttp2_session_recv()` is called. - * The application must retain the input bytes which was used to - * produce the |data| parameter, because it may refer to the memory + * `nghttp2_session_mem_recv2()` or `nghttp2_session_recv()` is + * called. The application must retain the input bytes which was used + * to produce the |data| parameter, because it may refer to the memory * region included in the input bytes. * * The implementation of this function must return 0 if it succeeds. * If nonzero is returned, it is treated as fatal error, and - * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions - * immediately return + * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()` + * functions immediately return * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. * * To set this callback to :type:`nghttp2_session_callbacks`, use @@ -1531,8 +1754,8 @@ typedef int (*nghttp2_on_data_chunk_recv_callback)(nghttp2_session *session, * If there is a fatal error while executing this callback, the * implementation should return * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`, which makes - * `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions - * immediately return + * `nghttp2_session_send()` and `nghttp2_session_mem_send2()` + * functions immediately return * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. * * If the other value is returned, it is treated as if @@ -1556,8 +1779,8 @@ typedef int (*nghttp2_before_frame_send_callback)(nghttp2_session *session, * * The implementation of this function must return 0 if it succeeds. * If nonzero is returned, it is treated as fatal error and - * `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions - * immediately return + * `nghttp2_session_send()` and `nghttp2_session_mem_send2()` + * functions immediately return * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. * * To set this callback to :type:`nghttp2_session_callbacks`, use @@ -1579,8 +1802,8 @@ typedef int (*nghttp2_on_frame_send_callback)(nghttp2_session *session, * * The implementation of this function must return 0 if it succeeds. * If nonzero is returned, it is treated as fatal error and - * `nghttp2_session_send()` and `nghttp2_session_mem_send()` functions - * immediately return + * `nghttp2_session_send()` and `nghttp2_session_mem_send2()` + * functions immediately return * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. * * `nghttp2_session_get_stream_user_data()` can be used to get @@ -1601,7 +1824,7 @@ typedef int (*nghttp2_on_frame_not_send_callback)(nghttp2_session *session, * The reason of closure is indicated by the |error_code|. The * |error_code| is usually one of :enum:`nghttp2_error_code`, but that * is not guaranteed. The stream_user_data, which was specified in - * `nghttp2_submit_request()` or `nghttp2_submit_headers()`, is still + * `nghttp2_submit_request2()` or `nghttp2_submit_headers()`, is still * available in this function. The |user_data| pointer is the third * argument passed in to the call to `nghttp2_session_client_new()` or * `nghttp2_session_server_new()`. @@ -1610,8 +1833,8 @@ typedef int (*nghttp2_on_frame_not_send_callback)(nghttp2_session *session, * * The implementation of this function must return 0 if it succeeds. * If nonzero is returned, it is treated as fatal error and - * `nghttp2_session_recv()`, `nghttp2_session_mem_recv()`, - * `nghttp2_session_send()`, and `nghttp2_session_mem_send()` + * `nghttp2_session_recv()`, `nghttp2_session_mem_recv2()`, + * `nghttp2_session_send()`, and `nghttp2_session_mem_send2()` * functions immediately return * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. * @@ -1681,7 +1904,7 @@ typedef int (*nghttp2_on_stream_close_callback)(nghttp2_session *session, * value is returned, it is treated as if * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` is returned. If * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` is returned, - * `nghttp2_session_mem_recv()` function will immediately return + * `nghttp2_session_mem_recv2()` function will immediately return * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. * * To set this callback to :type:`nghttp2_session_callbacks`, use @@ -1726,11 +1949,11 @@ typedef int (*nghttp2_on_begin_headers_callback)(nghttp2_session *session, * performs validation based on HTTP Messaging rule, which is briefly * explained in :ref:`http-messaging` section. * - * If the application uses `nghttp2_session_mem_recv()`, it can return - * :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` to make - * `nghttp2_session_mem_recv()` return without processing further + * If the application uses `nghttp2_session_mem_recv2()`, it can + * return :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` to make + * `nghttp2_session_mem_recv2()` return without processing further * input bytes. The memory pointed by |frame|, |name| and |value| - * parameters are retained until `nghttp2_session_mem_recv()` or + * parameters are retained until `nghttp2_session_mem_recv2()` or * `nghttp2_session_recv()` is called. The application must retain * the input bytes which was used to produce these parameters, because * it may refer to the memory region included in the input bytes. @@ -1757,8 +1980,8 @@ typedef int (*nghttp2_on_begin_headers_callback)(nghttp2_session *session, * nonzero value is returned, it is treated as * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` is returned, - * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions - * immediately return + * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()` + * functions immediately return * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. * * To set this callback to :type:`nghttp2_session_callbacks`, use @@ -1873,9 +2096,15 @@ typedef int (*nghttp2_on_invalid_header_callback2)( nghttp2_session *session, const nghttp2_frame *frame, nghttp2_rcbuf *name, nghttp2_rcbuf *value, uint8_t flags, void *user_data); +#ifndef NGHTTP2_NO_SSIZE_T /** * @functypedef * + * .. warning:: + * + * Deprecated. Use :type:`nghttp2_select_padding_callback2` + * instead. + * * Callback function invoked when the library asks application how * many padding bytes are required for the transmission of the * |frame|. The application must choose the total length of payload @@ -1896,9 +2125,39 @@ typedef ssize_t (*nghttp2_select_padding_callback)(nghttp2_session *session, size_t max_payloadlen, void *user_data); +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @functypedef + * + * Callback function invoked when the library asks application how + * many padding bytes are required for the transmission of the + * |frame|. The application must choose the total length of payload + * including padded bytes in range [frame->hd.length, max_payloadlen], + * inclusive. Choosing number not in this range will be treated as + * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. Returning + * ``frame->hd.length`` means no padding is added. Returning + * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` will make + * `nghttp2_session_send()` and `nghttp2_session_mem_send2()` + * functions immediately return + * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. + * + * To set this callback to :type:`nghttp2_session_callbacks`, use + * `nghttp2_session_callbacks_set_select_padding_callback2()`. + */ +typedef nghttp2_ssize (*nghttp2_select_padding_callback2)( + nghttp2_session *session, const nghttp2_frame *frame, size_t max_payloadlen, + void *user_data); + +#ifndef NGHTTP2_NO_SSIZE_T /** * @functypedef * + * .. warning:: + * + * Deprecated. Use + * :type:`nghttp2_data_source_read_length_callback2` instead. + * * Callback function invoked when library wants to get max length of * data to send data to the remote peer. The implementation of this * function should return a value in the following range. [1, @@ -1926,6 +2185,38 @@ typedef ssize_t (*nghttp2_data_source_read_length_callback)( int32_t session_remote_window_size, int32_t stream_remote_window_size, uint32_t remote_max_frame_size, void *user_data); +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @functypedef + * + * Callback function invoked when library wants to get max length of + * data to send data to the remote peer. The implementation of this + * function should return a value in the following range. [1, + * min(|session_remote_window_size|, |stream_remote_window_size|, + * |remote_max_frame_size|)]. If a value greater than this range is + * returned than the max allow value will be used. Returning a value + * smaller than this range is treated as + * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. The + * |frame_type| is provided for future extensibility and identifies + * the type of frame (see :type:`nghttp2_frame_type`) for which to get + * the length for. Currently supported frame types are: + * :enum:`nghttp2_frame_type.NGHTTP2_DATA`. + * + * This callback can be used to control the length in bytes for which + * :type:`nghttp2_data_source_read_callback` is allowed to send to the + * remote endpoint. This callback is optional. Returning + * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` will signal the + * entire session failure. + * + * To set this callback to :type:`nghttp2_session_callbacks`, use + * `nghttp2_session_callbacks_set_data_source_read_length_callback2()`. + */ +typedef nghttp2_ssize (*nghttp2_data_source_read_length_callback2)( + nghttp2_session *session, uint8_t frame_type, int32_t stream_id, + int32_t session_remote_window_size, int32_t stream_remote_window_size, + uint32_t remote_max_frame_size, void *user_data); + /** * @functypedef * @@ -1942,8 +2233,8 @@ typedef ssize_t (*nghttp2_data_source_read_length_callback)( * * The implementation of this function must return 0 if it succeeds. * If nonzero value is returned, it is treated as fatal error and - * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions - * immediately return + * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()` + * functions immediately return * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. * * To set this callback to :type:`nghttp2_session_callbacks`, use @@ -1967,8 +2258,8 @@ typedef int (*nghttp2_on_begin_frame_callback)(nghttp2_session *session, * * If fatal error occurred, application should return * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. In this case, - * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions - * immediately return + * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()` + * functions immediately return * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If the other * values are returned, currently they are treated as * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. @@ -2005,8 +2296,8 @@ typedef int (*nghttp2_on_extension_chunk_recv_callback)( * * If fatal error occurred, application should return * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. In this case, - * `nghttp2_session_recv()` and `nghttp2_session_mem_recv()` functions - * immediately return + * `nghttp2_session_recv()` and `nghttp2_session_mem_recv2()` + * functions immediately return * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If the other * values are returned, currently they are treated as * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. @@ -2016,9 +2307,15 @@ typedef int (*nghttp2_unpack_extension_callback)(nghttp2_session *session, const nghttp2_frame_hd *hd, void *user_data); +#ifndef NGHTTP2_NO_SSIZE_T /** * @functypedef * + * .. warning:: + * + * Deprecated. Use :type:`nghttp2_pack_extension_callback2` + * instead. + * * Callback function invoked when library asks the application to pack * extension payload in its wire format. The frame header will be * packed by library. Application must pack payload only. @@ -2049,18 +2346,53 @@ typedef ssize_t (*nghttp2_pack_extension_callback)(nghttp2_session *session, const nghttp2_frame *frame, void *user_data); +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @functypedef + * + * Callback function invoked when library asks the application to pack + * extension payload in its wire format. The frame header will be + * packed by library. Application must pack payload only. + * ``frame->ext.payload`` is the object passed to + * `nghttp2_submit_extension()` as payload parameter. Application + * must pack extension payload to the |buf| of its capacity |len| + * bytes. The |len| is at least 16KiB. + * + * The implementation of this function should return the number of + * bytes written into |buf| when it succeeds. + * + * To abort processing this extension frame, return + * :enum:`nghttp2_error.NGHTTP2_ERR_CANCEL`, and + * :type:`nghttp2_on_frame_not_send_callback` will be invoked. + * + * If fatal error occurred, application should return + * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. In this case, + * `nghttp2_session_send()` and `nghttp2_session_mem_send2()` + * functions immediately return + * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If the other + * values are returned, currently they are treated as + * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. If the return + * value is strictly larger than |len|, it is treated as + * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE`. + */ +typedef nghttp2_ssize (*nghttp2_pack_extension_callback2)( + nghttp2_session *session, uint8_t *buf, size_t len, + const nghttp2_frame *frame, void *user_data); + /** * @functypedef * + * .. warning:: + * + * Deprecated. Use :type:`nghttp2_error_callback2` instead. + * * Callback function invoked when library provides the error message * intended for human consumption. This callback is solely for * debugging purpose. The |msg| is typically NULL-terminated string * of length |len|. |len| does not include the sentinel NULL * character. * - * This function is deprecated. The new application should use - * :type:`nghttp2_error_callback2`. - * * The format of error message may change between nghttp2 library * versions. The application should not depend on the particular * format. @@ -2143,9 +2475,15 @@ nghttp2_session_callbacks_new(nghttp2_session_callbacks **callbacks_ptr); NGHTTP2_EXTERN void nghttp2_session_callbacks_del(nghttp2_session_callbacks *callbacks); +#ifndef NGHTTP2_NO_SSIZE_T /** * @function * + * .. warning:: + * + * Deprecated. Use `nghttp2_session_callbacks_set_send_callback2()` + * with :type:`nghttp2_send_callback2` instead. + * * Sets callback function invoked when a session wants to send data to * the remote peer. This callback is not necessary if the application * uses solely `nghttp2_session_mem_send()` to serialize data to @@ -2154,9 +2492,28 @@ nghttp2_session_callbacks_del(nghttp2_session_callbacks *callbacks); NGHTTP2_EXTERN void nghttp2_session_callbacks_set_send_callback( nghttp2_session_callbacks *cbs, nghttp2_send_callback send_callback); +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @function + * + * Sets callback function invoked when a session wants to send data to + * the remote peer. This callback is not necessary if the application + * uses solely `nghttp2_session_mem_send2()` to serialize data to + * transmit. + */ +NGHTTP2_EXTERN void nghttp2_session_callbacks_set_send_callback2( + nghttp2_session_callbacks *cbs, nghttp2_send_callback2 send_callback); + +#ifndef NGHTTP2_NO_SSIZE_T /** * @function * + * .. warning:: + * + * Deprecated. Use `nghttp2_session_callbacks_set_recv_callback2()` + * with :type:`nghttp2_recv_callback2` instead. + * * Sets callback function invoked when the a session wants to receive * data from the remote peer. This callback is not necessary if the * application uses solely `nghttp2_session_mem_recv()` to process @@ -2165,11 +2522,24 @@ NGHTTP2_EXTERN void nghttp2_session_callbacks_set_send_callback( NGHTTP2_EXTERN void nghttp2_session_callbacks_set_recv_callback( nghttp2_session_callbacks *cbs, nghttp2_recv_callback recv_callback); +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @function + * + * Sets callback function invoked when the a session wants to receive + * data from the remote peer. This callback is not necessary if the + * application uses solely `nghttp2_session_mem_recv2()` to process + * received data. + */ +NGHTTP2_EXTERN void nghttp2_session_callbacks_set_recv_callback2( + nghttp2_session_callbacks *cbs, nghttp2_recv_callback2 recv_callback); + /** * @function * * Sets callback function invoked by `nghttp2_session_recv()` and - * `nghttp2_session_mem_recv()` when a frame is received. + * `nghttp2_session_mem_recv2()` when a frame is received. */ NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_frame_recv_callback( nghttp2_session_callbacks *cbs, @@ -2179,7 +2549,7 @@ NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_frame_recv_callback( * @function * * Sets callback function invoked by `nghttp2_session_recv()` and - * `nghttp2_session_mem_recv()` when an invalid non-DATA frame is + * `nghttp2_session_mem_recv2()` when an invalid non-DATA frame is * received. */ NGHTTP2_EXTERN void @@ -2290,9 +2660,16 @@ NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_invalid_header_callback2( nghttp2_session_callbacks *cbs, nghttp2_on_invalid_header_callback2 on_invalid_header_callback2); +#ifndef NGHTTP2_NO_SSIZE_T /** * @function * + * .. warning:: + * + * Deprecated. Use + * `nghttp2_session_callbacks_set_select_padding_callback2()` with + * :type:`nghttp2_select_padding_callback2` instead. + * * Sets callback function invoked when the library asks application * how many padding bytes are required for the transmission of the * given frame. @@ -2301,9 +2678,29 @@ NGHTTP2_EXTERN void nghttp2_session_callbacks_set_select_padding_callback( nghttp2_session_callbacks *cbs, nghttp2_select_padding_callback select_padding_callback); +#endif /* NGHTTP2_NO_SSIZE_T */ + /** * @function * + * Sets callback function invoked when the library asks application + * how many padding bytes are required for the transmission of the + * given frame. + */ +NGHTTP2_EXTERN void nghttp2_session_callbacks_set_select_padding_callback2( + nghttp2_session_callbacks *cbs, + nghttp2_select_padding_callback2 select_padding_callback); + +#ifndef NGHTTP2_NO_SSIZE_T +/** + * @function + * + * .. warning:: + * + * Deprecated. Use + * `nghttp2_session_callbacks_set_data_source_read_length_callback2()` + * with :type:`nghttp2_data_source_read_length_callback2` instead. + * * Sets callback function determine the length allowed in * :type:`nghttp2_data_source_read_callback`. */ @@ -2312,6 +2709,19 @@ nghttp2_session_callbacks_set_data_source_read_length_callback( nghttp2_session_callbacks *cbs, nghttp2_data_source_read_length_callback data_source_read_length_callback); +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @function + * + * Sets callback function determine the length allowed in + * :type:`nghttp2_data_source_read_callback2`. + */ +NGHTTP2_EXTERN void +nghttp2_session_callbacks_set_data_source_read_length_callback2( + nghttp2_session_callbacks *cbs, + nghttp2_data_source_read_length_callback2 data_source_read_length_callback); + /** * @function * @@ -2326,15 +2736,22 @@ NGHTTP2_EXTERN void nghttp2_session_callbacks_set_on_begin_frame_callback( * * Sets callback function invoked when * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_COPY` is used in - * :type:`nghttp2_data_source_read_callback` to avoid data copy. + * :type:`nghttp2_data_source_read_callback2` to avoid data copy. */ NGHTTP2_EXTERN void nghttp2_session_callbacks_set_send_data_callback( nghttp2_session_callbacks *cbs, nghttp2_send_data_callback send_data_callback); +#ifndef NGHTTP2_NO_SSIZE_T /** * @function * + * .. warning:: + * + * Deprecated. Use + * `nghttp2_session_callbacks_set_pack_extension_callback2()` with + * :type:`nghttp2_pack_extension_callback2` instead. + * * Sets callback function invoked when the library asks the * application to pack extension frame payload in wire format. */ @@ -2342,6 +2759,18 @@ NGHTTP2_EXTERN void nghttp2_session_callbacks_set_pack_extension_callback( nghttp2_session_callbacks *cbs, nghttp2_pack_extension_callback pack_extension_callback); +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @function + * + * Sets callback function invoked when the library asks the + * application to pack extension frame payload in wire format. + */ +NGHTTP2_EXTERN void nghttp2_session_callbacks_set_pack_extension_callback2( + nghttp2_session_callbacks *cbs, + nghttp2_pack_extension_callback2 pack_extension_callback); + /** * @function * @@ -2366,12 +2795,15 @@ nghttp2_session_callbacks_set_on_extension_chunk_recv_callback( /** * @function * + * .. warning:: + * + * Deprecated. Use + * `nghttp2_session_callbacks_set_error_callback2()` with + * :type:`nghttp2_error_callback2` instead. + * * Sets callback function invoked when library tells error message to * the application. * - * This function is deprecated. The new application should use - * `nghttp2_session_callbacks_set_error_callback2()`. - * * If both :type:`nghttp2_error_callback` and * :type:`nghttp2_error_callback2` are set, the latter takes * precedence. @@ -2568,7 +3000,7 @@ nghttp2_option_set_peer_max_concurrent_streams(nghttp2_option *option, * * If this option is not used or used with zero value, if MAGIC does * not match :macro:`NGHTTP2_CLIENT_MAGIC`, `nghttp2_session_recv()` - * and `nghttp2_session_mem_recv()` will return error + * and `nghttp2_session_mem_recv2()` will return error * :enum:`nghttp2_error.NGHTTP2_ERR_BAD_CLIENT_MAGIC`, which is fatal * error. */ @@ -2781,7 +3213,7 @@ nghttp2_option_set_stream_reset_rate_limit(nghttp2_option *option, * does not store |callbacks|. The |user_data| is an arbitrary user * supplied data, which will be passed to the callback functions. * - * The :type:`nghttp2_send_callback` must be specified. If the + * The :type:`nghttp2_send_callback2` must be specified. If the * application code uses `nghttp2_session_recv()`, the * :type:`nghttp2_recv_callback` must be specified. The other members * of |callbacks| can be ``NULL``. @@ -2807,7 +3239,7 @@ nghttp2_session_client_new(nghttp2_session **session_ptr, * does not store |callbacks|. The |user_data| is an arbitrary user * supplied data, which will be passed to the callback functions. * - * The :type:`nghttp2_send_callback` must be specified. If the + * The :type:`nghttp2_send_callback2` must be specified. If the * application code uses `nghttp2_session_recv()`, the * :type:`nghttp2_recv_callback` must be specified. The other members * of |callbacks| can be ``NULL``. @@ -2943,7 +3375,7 @@ NGHTTP2_EXTERN void nghttp2_session_del(nghttp2_session *session); * This function retrieves the highest prioritized frame from the * outbound queue and sends it to the remote peer. It does this as * many times as possible until the user callback - * :type:`nghttp2_send_callback` returns + * :type:`nghttp2_send_callback2` returns * :enum:`nghttp2_error.NGHTTP2_ERR_WOULDBLOCK`, the outbound queue * becomes empty or flow control is triggered (remote window size * becomes depleted or maximum number of concurrent streams is @@ -2973,7 +3405,7 @@ NGHTTP2_EXTERN void nghttp2_session_del(nghttp2_session *session); * :type:`nghttp2_on_frame_not_send_callback` is invoked. Abort * the following steps. * - * 8. :type:`nghttp2_send_callback` is invoked one or more times to + * 8. :type:`nghttp2_send_callback2` is invoked one or more times to * send the frame. * * 9. :type:`nghttp2_on_frame_send_callback` is invoked. @@ -2992,9 +3424,14 @@ NGHTTP2_EXTERN void nghttp2_session_del(nghttp2_session *session); */ NGHTTP2_EXTERN int nghttp2_session_send(nghttp2_session *session); +#ifndef NGHTTP2_NO_SSIZE_T /** * @function * + * .. warning:: + * + * Deprecated. Use `nghttp2_session_mem_send2()` instead. + * * Returns the serialized data to send. * * This function behaves like `nghttp2_session_send()` except that it @@ -3034,6 +3471,50 @@ NGHTTP2_EXTERN int nghttp2_session_send(nghttp2_session *session); NGHTTP2_EXTERN ssize_t nghttp2_session_mem_send(nghttp2_session *session, const uint8_t **data_ptr); +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @function + * + * Returns the serialized data to send. + * + * This function behaves like `nghttp2_session_send()` except that it + * does not use :type:`nghttp2_send_callback2` to transmit data. + * Instead, it assigns the pointer to the serialized data to the + * |*data_ptr| and returns its length. The other callbacks are called + * in the same way as they are in `nghttp2_session_send()`. + * + * If no data is available to send, this function returns 0. + * + * This function may not return all serialized data in one invocation. + * To get all data, call this function repeatedly until it returns 0 + * or one of negative error codes. + * + * The assigned |*data_ptr| is valid until the next call of + * `nghttp2_session_mem_send2()` or `nghttp2_session_send()`. + * + * The caller must send all data before sending the next chunk of + * data. + * + * This function returns the length of the data pointed by the + * |*data_ptr| if it succeeds, or one of the following negative error + * codes: + * + * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` + * Out of memory. + * + * .. note:: + * + * This function may produce very small byte string. If that is the + * case, and application disables Nagle algorithm (``TCP_NODELAY``), + * then writing this small chunk leads to very small packet, and it + * is very inefficient. An application should be responsible to + * buffer up small chunks of data as necessary to avoid this + * situation. + */ +NGHTTP2_EXTERN nghttp2_ssize +nghttp2_session_mem_send2(nghttp2_session *session, const uint8_t **data_ptr); + /** * @function * @@ -3104,9 +3585,14 @@ NGHTTP2_EXTERN ssize_t nghttp2_session_mem_send(nghttp2_session *session, */ NGHTTP2_EXTERN int nghttp2_session_recv(nghttp2_session *session); +#ifndef NGHTTP2_NO_SSIZE_T /** * @function * + * .. warning:: + * + * Deprecated. Use `nghttp2_session_mem_recv2()` instead. + * * Processes data |in| as an input from the remote endpoint. The * |inlen| indicates the number of bytes to receive in the |in|. * @@ -3145,6 +3631,49 @@ NGHTTP2_EXTERN ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, size_t inlen); +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @function + * + * Processes data |in| as an input from the remote endpoint. The + * |inlen| indicates the number of bytes to receive in the |in|. + * + * This function behaves like `nghttp2_session_recv()` except that it + * does not use :type:`nghttp2_recv_callback` to receive data; the + * |in| is the only data for the invocation of this function. If all + * bytes are processed, this function returns. The other callbacks + * are called in the same way as they are in `nghttp2_session_recv()`. + * + * In the current implementation, this function always tries to + * processes |inlen| bytes of input data unless either an error occurs or + * :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` is returned from + * :type:`nghttp2_on_header_callback` or + * :type:`nghttp2_on_data_chunk_recv_callback`. If + * :enum:`nghttp2_error.NGHTTP2_ERR_PAUSE` is used, the return value + * includes the number of bytes which was used to produce the data or + * frame for the callback. + * + * This function returns the number of processed bytes, or one of the + * following negative error codes: + * + * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` + * Out of memory. + * :enum:`nghttp2_error.NGHTTP2_ERR_CALLBACK_FAILURE` + * The callback function failed. + * :enum:`nghttp2_error.NGHTTP2_ERR_BAD_CLIENT_MAGIC` + * Invalid client magic was detected. This error only returns + * when |session| was configured as server and + * `nghttp2_option_set_no_recv_client_magic()` is not used with + * nonzero value. + * :enum:`nghttp2_error.NGHTTP2_ERR_FLOODED` + * Flooding was detected in this HTTP/2 session, and it must be + * closed. This is most likely caused by misbehaviour of peer. + */ +NGHTTP2_EXTERN nghttp2_ssize nghttp2_session_mem_recv2(nghttp2_session *session, + const uint8_t *in, + size_t inlen); + /** * @function * @@ -3190,7 +3719,7 @@ NGHTTP2_EXTERN int nghttp2_session_want_write(nghttp2_session *session); * @function * * Returns stream_user_data for the stream |stream_id|. The - * stream_user_data is provided by `nghttp2_submit_request()`, + * stream_user_data is provided by `nghttp2_submit_request2()`, * `nghttp2_submit_headers()` or * `nghttp2_session_set_stream_user_data()`. Unless it is set using * `nghttp2_session_set_stream_user_data()`, if the stream is @@ -3626,6 +4155,13 @@ NGHTTP2_EXTERN int nghttp2_session_consume_stream(nghttp2_session *session, /** * @function * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. In the future release after the end of + * 2024, this function will always return 0 without doing anything. + * * Changes priority of existing stream denoted by |stream_id|. The * new priority specification is |pri_spec|. * @@ -3665,6 +4201,13 @@ nghttp2_session_change_stream_priority(nghttp2_session *session, /** * @function * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. In the future release after the end of + * 2024, this function will always return 0 without doing anything. + * * Creates idle stream with the given |stream_id|, and priority * |pri_spec|. * @@ -3715,10 +4258,6 @@ nghttp2_session_create_idle_stream(nghttp2_session *session, int32_t stream_id, /** * @function * - * Performs post-process of HTTP Upgrade request. This function can - * be called from both client and server, but the behavior is very - * different in each other. - * * .. warning:: * * This function is deprecated in favor of @@ -3730,6 +4269,10 @@ nghttp2_session_create_idle_stream(nghttp2_session *session, int32_t stream_id, * HEAD is used in request, the length of response body must be 0 * regardless of value included in content-length header field. * + * Performs post-process of HTTP Upgrade request. This function can + * be called from both client and server, but the behavior is very + * different in each other. + * * If called from client side, the |settings_payload| must be the * value sent in ``HTTP2-Settings`` header field and must be decoded * by base64url decoder. The |settings_payloadlen| is the length of @@ -3809,9 +4352,14 @@ NGHTTP2_EXTERN int nghttp2_session_upgrade2(nghttp2_session *session, int head_request, void *stream_user_data); +#ifndef NGHTTP2_NO_SSIZE_T /** * @function * + * .. warning:: + * + * Deprecated. Use `nghttp2_pack_settings_payload2()` instead. + * * Serializes the SETTINGS values |iv| in the |buf|. The size of the * |buf| is specified by |buflen|. The number of entries in the |iv| * array is given by |niv|. The required space in |buf| for the |niv| @@ -3833,6 +4381,32 @@ NGHTTP2_EXTERN int nghttp2_session_upgrade2(nghttp2_session *session, NGHTTP2_EXTERN ssize_t nghttp2_pack_settings_payload( uint8_t *buf, size_t buflen, const nghttp2_settings_entry *iv, size_t niv); +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @function + * + * Serializes the SETTINGS values |iv| in the |buf|. The size of the + * |buf| is specified by |buflen|. The number of entries in the |iv| + * array is given by |niv|. The required space in |buf| for the |niv| + * entries is ``6*niv`` bytes and if the given buffer is too small, an + * error is returned. This function is used mainly for creating a + * SETTINGS payload to be sent with the ``HTTP2-Settings`` header + * field in an HTTP Upgrade request. The data written in |buf| is NOT + * base64url encoded and the application is responsible for encoding. + * + * This function returns the number of bytes written in |buf|, or one + * of the following negative error codes: + * + * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` + * The |iv| contains duplicate settings ID or invalid value. + * + * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE` + * The provided |buflen| size is too small to hold the output. + */ +NGHTTP2_EXTERN nghttp2_ssize nghttp2_pack_settings_payload2( + uint8_t *buf, size_t buflen, const nghttp2_settings_entry *iv, size_t niv); + /** * @function * @@ -3854,6 +4428,12 @@ NGHTTP2_EXTERN const char *nghttp2_http2_strerror(uint32_t error_code); /** * @function * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. + * * Initializes |pri_spec| with the |stream_id| of the stream to depend * on with |weight| and its exclusive flag. If |exclusive| is * nonzero, exclusive flag is set. @@ -3868,6 +4448,12 @@ NGHTTP2_EXTERN void nghttp2_priority_spec_init(nghttp2_priority_spec *pri_spec, /** * @function * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. + * * Initializes |pri_spec| with the default values. The default values * are: stream_id = 0, weight = :macro:`NGHTTP2_DEFAULT_WEIGHT` and * exclusive = 0. @@ -3878,18 +4464,29 @@ nghttp2_priority_spec_default_init(nghttp2_priority_spec *pri_spec); /** * @function * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. + * * Returns nonzero if the |pri_spec| is filled with default values. */ NGHTTP2_EXTERN int nghttp2_priority_spec_check_default(const nghttp2_priority_spec *pri_spec); +#ifndef NGHTTP2_NO_SSIZE_T /** * @function * + * .. warning:: + * + * Deprecated. Use `nghttp2_submit_request2()` instead. + * * Submits HEADERS frame and optionally one or more DATA frames. * - * The |pri_spec| is priority specification of this request. ``NULL`` - * means the default priority (see + * The |pri_spec| is a deprecated priority specification of this + * request. ``NULL`` means the default priority (see * `nghttp2_priority_spec_default_init()`). To specify the priority, * use `nghttp2_priority_spec_init()`. If |pri_spec| is not ``NULL``, * this function will copy its data members. @@ -3970,9 +4567,105 @@ NGHTTP2_EXTERN int32_t nghttp2_submit_request( const nghttp2_nv *nva, size_t nvlen, const nghttp2_data_provider *data_prd, void *stream_user_data); +#endif /* NGHTTP2_NO_SSIZE_T */ + /** * @function * + * Submits HEADERS frame and optionally one or more DATA frames. + * + * The |pri_spec| is a deprecated priority specification of this + * request. ``NULL`` means the default priority (see + * `nghttp2_priority_spec_default_init()`). To specify the priority, + * use `nghttp2_priority_spec_init()`. If |pri_spec| is not ``NULL``, + * this function will copy its data members. In the future release + * after the end of 2024, this function will ignore |pri_spec| and + * behave as if ``NULL`` is given. + * + * The ``pri_spec->weight`` must be in [:macro:`NGHTTP2_MIN_WEIGHT`, + * :macro:`NGHTTP2_MAX_WEIGHT`], inclusive. If ``pri_spec->weight`` + * is strictly less than :macro:`NGHTTP2_MIN_WEIGHT`, it becomes + * :macro:`NGHTTP2_MIN_WEIGHT`. If it is strictly greater than + * :macro:`NGHTTP2_MAX_WEIGHT`, it becomes + * :macro:`NGHTTP2_MAX_WEIGHT`. + * + * If + * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES` + * of value of 1 is received by a remote endpoint, |pri_spec| is + * ignored, and treated as if ``NULL`` is specified. + * + * The |nva| is an array of name/value pair :type:`nghttp2_nv` with + * |nvlen| elements. The application is responsible to include + * required pseudo-header fields (header field whose name starts with + * ":") in |nva| and must place pseudo-headers before regular header + * fields. + * + * This function creates copies of all name/value pairs in |nva|. It + * also lower-cases all names in |nva|. The order of elements in + * |nva| is preserved. For header fields with + * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and + * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, + * header field name and value are not copied respectively. With + * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application + * is responsible to pass header field name in lowercase. The + * application should maintain the references to them until + * :type:`nghttp2_on_frame_send_callback` or + * :type:`nghttp2_on_frame_not_send_callback` is called. + * + * HTTP/2 specification has requirement about header fields in the + * request HEADERS. See the specification for more details. + * + * If |data_prd| is not ``NULL``, it provides data which will be sent + * in subsequent DATA frames. In this case, a method that allows + * request message bodies + * (https://tools.ietf.org/html/rfc7231#section-4) must be specified + * with ``:method`` key in |nva| (e.g. ``POST``). This function does + * not take ownership of the |data_prd|. The function copies the + * members of the |data_prd|. If |data_prd| is ``NULL``, HEADERS have + * END_STREAM set. The |stream_user_data| is data associated to the + * stream opened by this request and can be an arbitrary pointer, + * which can be retrieved later by + * `nghttp2_session_get_stream_user_data()`. + * + * This function returns assigned stream ID if it succeeds, or one of + * the following negative error codes: + * + * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` + * Out of memory. + * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE` + * No stream ID is available because maximum stream ID was + * reached. + * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` + * Trying to depend on itself (new stream ID equals + * ``pri_spec->stream_id``). + * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO` + * The |session| is server session. + * + * .. warning:: + * + * This function returns assigned stream ID if it succeeds. But + * that stream is not created yet. The application must not submit + * frame to that stream ID before + * :type:`nghttp2_before_frame_send_callback` is called for this + * frame. This means `nghttp2_session_get_stream_user_data()` does + * not work before the callback. But + * `nghttp2_session_set_stream_user_data()` handles this situation + * specially, and it can set data to a stream during this period. + * + */ +NGHTTP2_EXTERN int32_t nghttp2_submit_request2( + nghttp2_session *session, const nghttp2_priority_spec *pri_spec, + const nghttp2_nv *nva, size_t nvlen, const nghttp2_data_provider2 *data_prd, + void *stream_user_data); + +#ifndef NGHTTP2_NO_SSIZE_T +/** + * @function + * + * .. warning:: + * + * Deprecated. Use `nghttp2_submit_response2()` instead. + * * Submits response HEADERS frame and optionally one or more DATA * frames against the stream |stream_id|. * @@ -4039,6 +4732,77 @@ nghttp2_submit_response(nghttp2_session *session, int32_t stream_id, const nghttp2_nv *nva, size_t nvlen, const nghttp2_data_provider *data_prd); +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @function + * + * Submits response HEADERS frame and optionally one or more DATA + * frames against the stream |stream_id|. + * + * The |nva| is an array of name/value pair :type:`nghttp2_nv` with + * |nvlen| elements. The application is responsible to include + * required pseudo-header fields (header field whose name starts with + * ":") in |nva| and must place pseudo-headers before regular header + * fields. + * + * This function creates copies of all name/value pairs in |nva|. It + * also lower-cases all names in |nva|. The order of elements in + * |nva| is preserved. For header fields with + * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME` and + * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_VALUE` are set, + * header field name and value are not copied respectively. With + * :enum:`nghttp2_nv_flag.NGHTTP2_NV_FLAG_NO_COPY_NAME`, application + * is responsible to pass header field name in lowercase. The + * application should maintain the references to them until + * :type:`nghttp2_on_frame_send_callback` or + * :type:`nghttp2_on_frame_not_send_callback` is called. + * + * HTTP/2 specification has requirement about header fields in the + * response HEADERS. See the specification for more details. + * + * If |data_prd| is not ``NULL``, it provides data which will be sent + * in subsequent DATA frames. This function does not take ownership + * of the |data_prd|. The function copies the members of the + * |data_prd|. If |data_prd| is ``NULL``, HEADERS will have + * END_STREAM flag set. + * + * This method can be used as normal HTTP response and push response. + * When pushing a resource using this function, the |session| must be + * configured using `nghttp2_session_server_new()` or its variants and + * the target stream denoted by the |stream_id| must be reserved using + * `nghttp2_submit_push_promise()`. + * + * To send non-final response headers (e.g., HTTP status 101), don't + * use this function because this function half-closes the outbound + * stream. Instead, use `nghttp2_submit_headers()` for this purpose. + * + * This function returns 0 if it succeeds, or one of the following + * negative error codes: + * + * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` + * Out of memory. + * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` + * The |stream_id| is 0. + * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST` + * DATA or HEADERS has been already submitted and not fully + * processed yet. Normally, this does not happen, but when + * application wrongly calls `nghttp2_submit_response2()` twice, + * this may happen. + * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO` + * The |session| is client session. + * + * .. warning:: + * + * Calling this function twice for the same stream ID may lead to + * program crash. It is generally considered to a programming error + * to commit response twice. + */ +NGHTTP2_EXTERN int +nghttp2_submit_response2(nghttp2_session *session, int32_t stream_id, + const nghttp2_nv *nva, size_t nvlen, + const nghttp2_data_provider2 *data_prd); + /** * @function * @@ -4064,22 +4828,23 @@ nghttp2_submit_response(nghttp2_session *session, int32_t stream_id, * DATA without END_STREAM flat set. The library does not enforce * this requirement, and applications should do this for themselves. * If `nghttp2_submit_trailer()` is called before any response HEADERS - * submission (usually by `nghttp2_submit_response()`), the content of - * |nva| will be sent as response headers, which will result in error. + * submission (usually by `nghttp2_submit_response2()`), the content + * of |nva| will be sent as response headers, which will result in + * error. * * This function has the same effect with `nghttp2_submit_headers()`, * with flags = :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM` and both * pri_spec and stream_user_data to NULL. * - * To submit trailer fields after `nghttp2_submit_response()` is + * To submit trailer fields after `nghttp2_submit_response2()` is * called, the application has to specify - * :type:`nghttp2_data_provider` to `nghttp2_submit_response()`. - * Inside of :type:`nghttp2_data_source_read_callback`, when setting + * :type:`nghttp2_data_provider2` to `nghttp2_submit_response2()`. + * Inside of :type:`nghttp2_data_source_read_callback2`, when setting * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_EOF`, also set * :enum:`nghttp2_data_flag.NGHTTP2_DATA_FLAG_NO_END_STREAM`. After * that, the application can send trailer fields using * `nghttp2_submit_trailer()`. `nghttp2_submit_trailer()` can be used - * inside :type:`nghttp2_data_source_read_callback`. + * inside :type:`nghttp2_data_source_read_callback2`. * * This function returns 0 if it succeeds and |stream_id| is -1. * Otherwise, this function returns 0 if it succeeds, or one of the @@ -4114,11 +4879,13 @@ NGHTTP2_EXTERN int nghttp2_submit_trailer(nghttp2_session *session, * assigned stream ID will be returned. Otherwise, specify stream ID * in |stream_id|. * - * The |pri_spec| is priority specification of this request. ``NULL`` - * means the default priority (see + * The |pri_spec| is a deprecated priority specification of this + * request. ``NULL`` means the default priority (see * `nghttp2_priority_spec_default_init()`). To specify the priority, * use `nghttp2_priority_spec_init()`. If |pri_spec| is not ``NULL``, - * this function will copy its data members. + * this function will copy its data members. In the future release + * after the end of 2024, this function will ignore |pri_spec| and + * behave as if ``NULL`` is given. * * The ``pri_spec->weight`` must be in [:macro:`NGHTTP2_MIN_WEIGHT`, * :macro:`NGHTTP2_MAX_WEIGHT`], inclusive. If ``pri_spec->weight`` @@ -4156,8 +4923,8 @@ NGHTTP2_EXTERN int nghttp2_submit_trailer(nghttp2_session *session, * * This function is low-level in a sense that the application code can * specify flags directly. For usual HTTP request, - * `nghttp2_submit_request()` is useful. Likewise, for HTTP response, - * prefer `nghttp2_submit_response()`. + * `nghttp2_submit_request2()` is useful. Likewise, for HTTP + * response, prefer `nghttp2_submit_response2()`. * * This function returns newly assigned stream ID if it succeeds and * |stream_id| is -1. Otherwise, this function returns 0 if it @@ -4192,9 +4959,14 @@ NGHTTP2_EXTERN int32_t nghttp2_submit_headers( const nghttp2_priority_spec *pri_spec, const nghttp2_nv *nva, size_t nvlen, void *stream_user_data); +#ifndef NGHTTP2_NO_SSIZE_T /** * @function * + * .. warning:: + * + * Deprecated. Use `nghttp2_submit_data2()` instead. + * * Submits one or more DATA frames to the stream |stream_id|. The * data to be sent are provided by |data_prd|. If |flags| contains * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM`, the last DATA frame @@ -4237,19 +5009,73 @@ NGHTTP2_EXTERN int nghttp2_submit_data(nghttp2_session *session, uint8_t flags, int32_t stream_id, const nghttp2_data_provider *data_prd); +#endif /* NGHTTP2_NO_SSIZE_T */ + /** * @function * + * Submits one or more DATA frames to the stream |stream_id|. The + * data to be sent are provided by |data_prd|. If |flags| contains + * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM`, the last DATA frame + * has END_STREAM flag set. + * + * This function does not take ownership of the |data_prd|. The + * function copies the members of the |data_prd|. + * + * This function returns 0 if it succeeds, or one of the following + * negative error codes: + * + * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` + * Out of memory. + * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST` + * DATA or HEADERS has been already submitted and not fully + * processed yet. + * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` + * The |stream_id| is 0. + * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_CLOSED` + * The stream was already closed; or the |stream_id| is invalid. + * + * .. note:: + * + * Currently, only one DATA or HEADERS is allowed for a stream at a + * time. Submitting these frames more than once before first DATA + * or HEADERS is finished results in + * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST` error code. The + * earliest callback which tells that previous frame is done is + * :type:`nghttp2_on_frame_send_callback`. In side that callback, + * new data can be submitted using `nghttp2_submit_data2()`. Of + * course, all data except for last one must not have + * :enum:`nghttp2_flag.NGHTTP2_FLAG_END_STREAM` flag set in |flags|. + * This sounds a bit complicated, and we recommend to use + * `nghttp2_submit_request2()` and `nghttp2_submit_response2()` to + * avoid this cascading issue. The experience shows that for HTTP + * use, these two functions are enough to implement both client and + * server. + */ +NGHTTP2_EXTERN int nghttp2_submit_data2(nghttp2_session *session, uint8_t flags, + int32_t stream_id, + const nghttp2_data_provider2 *data_prd); + +/** + * @function + * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. In the future release after the end of + * 2024, this function will always return 0 without doing anything. + * * Submits PRIORITY frame to change the priority of stream |stream_id| * to the priority specification |pri_spec|. * * The |flags| is currently ignored and should be * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`. * - * The |pri_spec| is priority specification of this request. ``NULL`` - * is not allowed for this function. To specify the priority, use - * `nghttp2_priority_spec_init()`. This function will copy its data - * members. + * The |pri_spec| is a deprecated priority specification of this + * request. ``NULL`` is not allowed for this function. To specify the + * priority, use `nghttp2_priority_spec_init()`. This function will + * copy its data members. * * The ``pri_spec->weight`` must be in [:macro:`NGHTTP2_MIN_WEIGHT`, * :macro:`NGHTTP2_MAX_WEIGHT`], inclusive. If ``pri_spec->weight`` @@ -4429,7 +5255,7 @@ NGHTTP2_EXTERN int nghttp2_submit_settings(nghttp2_session *session, * The client side is not allowed to use this function. * * To submit response headers and data, use - * `nghttp2_submit_response()`. + * `nghttp2_submit_response2()`. * * This function returns assigned promised stream ID if it succeeds, * or one of the following negative error codes: @@ -4568,10 +5394,11 @@ nghttp2_session_get_last_proc_stream_id(nghttp2_session *session); * reasons are: session is server; stream ID has been spent; GOAWAY * has been sent or received. * - * The application can call `nghttp2_submit_request()` without - * consulting this function. In that case, `nghttp2_submit_request()` - * may return error. Or, request is failed to sent, and - * :type:`nghttp2_on_stream_close_callback` is called. + * The application can call `nghttp2_submit_request2()` without + * consulting this function. In that case, + * `nghttp2_submit_request2()` may return error. Or, request is + * failed to sent, and :type:`nghttp2_on_stream_close_callback` is + * called. */ NGHTTP2_EXTERN int nghttp2_session_check_request_allowed(nghttp2_session *session); @@ -4673,11 +5500,11 @@ nghttp2_session_set_local_window_size(nghttp2_session *session, uint8_t flags, * Application can pass arbitrary frame flags and stream ID in |flags| * and |stream_id| respectively. The |payload| is opaque pointer, and * it can be accessible though ``frame->ext.payload`` in - * :type:`nghttp2_pack_extension_callback`. The library will not own + * :type:`nghttp2_pack_extension_callback2`. The library will not own * passed |payload| pointer. * - * The application must set :type:`nghttp2_pack_extension_callback` - * using `nghttp2_session_callbacks_set_pack_extension_callback()`. + * The application must set :type:`nghttp2_pack_extension_callback2` + * using `nghttp2_session_callbacks_set_pack_extension_callback2()`. * * The application should retain the memory pointed by |payload| until * the transmission of extension frame is done (which is indicated by @@ -4685,7 +5512,7 @@ nghttp2_session_set_local_window_size(nghttp2_session *session, uint8_t flags, * (which is indicated by :type:`nghttp2_on_frame_not_send_callback`). * If application does not touch this memory region after packing it * into a wire format, application can free it inside - * :type:`nghttp2_pack_extension_callback`. + * :type:`nghttp2_pack_extension_callback2`. * * The standard HTTP/2 frame cannot be sent with this function, so * |type| must be strictly grater than 0x9. Otherwise, this function @@ -4696,7 +5523,7 @@ nghttp2_session_set_local_window_size(nghttp2_session *session, uint8_t flags, * negative error codes: * * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_STATE` - * If :type:`nghttp2_pack_extension_callback` is not set. + * If :type:`nghttp2_pack_extension_callback2` is not set. * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` * If |type| specifies standard HTTP/2 frame type. The frame * types in the rage [0x0, 0x9], both inclusive, are standard @@ -5317,9 +6144,14 @@ NGHTTP2_EXTERN int nghttp2_hd_deflate_change_table_size(nghttp2_hd_deflater *deflater, size_t settings_max_dynamic_table_size); +#ifndef NGHTTP2_NO_SSIZE_T /** * @function * + * .. warning:: + * + * Deprecated. Use `nghttp2_hd_deflate_hd2()` instead. + * * Deflates the |nva|, which has the |nvlen| name/value pairs, into * the |buf| of length |buflen|. * @@ -5349,9 +6181,47 @@ NGHTTP2_EXTERN ssize_t nghttp2_hd_deflate_hd(nghttp2_hd_deflater *deflater, const nghttp2_nv *nva, size_t nvlen); +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @function + * + * Deflates the |nva|, which has the |nvlen| name/value pairs, into + * the |buf| of length |buflen|. + * + * If |buf| is not large enough to store the deflated header block, + * this function fails with + * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`. The caller + * should use `nghttp2_hd_deflate_bound()` to know the upper bound of + * buffer size required to deflate given header name/value pairs. + * + * Once this function fails, subsequent call of this function always + * returns :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`. + * + * After this function returns, it is safe to delete the |nva|. + * + * This function returns the number of bytes written to |buf| if it + * succeeds, or one of the following negative error codes: + * + * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` + * Out of memory. + * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP` + * Deflation process has failed. + * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE` + * The provided |buflen| size is too small to hold the output. + */ +NGHTTP2_EXTERN nghttp2_ssize +nghttp2_hd_deflate_hd2(nghttp2_hd_deflater *deflater, uint8_t *buf, + size_t buflen, const nghttp2_nv *nva, size_t nvlen); + +#ifndef NGHTTP2_NO_SSIZE_T /** * @function * + * .. warning:: + * + * Deprecated. Use `nghttp2_hd_deflate_hd_vec2()` instead. + * * Deflates the |nva|, which has the |nvlen| name/value pairs, into * the |veclen| size of buf vector |vec|. The each size of buffer * must be set in len field of :type:`nghttp2_vec`. If and only if @@ -5383,6 +6253,40 @@ NGHTTP2_EXTERN ssize_t nghttp2_hd_deflate_hd_vec(nghttp2_hd_deflater *deflater, const nghttp2_nv *nva, size_t nvlen); +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @function + * + * Deflates the |nva|, which has the |nvlen| name/value pairs, into + * the |veclen| size of buf vector |vec|. The each size of buffer + * must be set in len field of :type:`nghttp2_vec`. If and only if + * one chunk is filled up completely, next chunk will be used. If + * |vec| is not large enough to store the deflated header block, this + * function fails with + * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE`. The caller + * should use `nghttp2_hd_deflate_bound()` to know the upper bound of + * buffer size required to deflate given header name/value pairs. + * + * Once this function fails, subsequent call of this function always + * returns :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP`. + * + * After this function returns, it is safe to delete the |nva|. + * + * This function returns the number of bytes written to |vec| if it + * succeeds, or one of the following negative error codes: + * + * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` + * Out of memory. + * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP` + * Deflation process has failed. + * :enum:`nghttp2_error.NGHTTP2_ERR_INSUFF_BUFSIZE` + * The provided |buflen| size is too small to hold the output. + */ +NGHTTP2_EXTERN nghttp2_ssize nghttp2_hd_deflate_hd_vec2( + nghttp2_hd_deflater *deflater, const nghttp2_vec *vec, size_t veclen, + const nghttp2_nv *nva, size_t nvlen); + /** * @function * @@ -5496,7 +6400,7 @@ NGHTTP2_EXTERN void nghttp2_hd_inflate_del(nghttp2_hd_inflater *inflater); * This function must not be called while header block is being * inflated. In other words, this function must be called after * initialization of |inflater|, but before calling - * `nghttp2_hd_inflate_hd2()`, or after + * `nghttp2_hd_inflate_hd3()`, or after * `nghttp2_hd_inflate_end_headers()`. Otherwise, * `NGHTTP2_ERR_INVALID_STATE` was returned. * @@ -5534,6 +6438,7 @@ typedef enum { NGHTTP2_HD_INFLATE_EMIT = 0x02 } nghttp2_hd_inflate_flag; +#ifndef NGHTTP2_NO_SSIZE_T /** * @function * @@ -5621,9 +6526,16 @@ NGHTTP2_EXTERN ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_inflater *inflater, int *inflate_flags, uint8_t *in, size_t inlen, int in_final); +#endif /* NGHTTP2_NO_SSIZE_T */ + +#ifndef NGHTTP2_NO_SSIZE_T /** * @function * + * .. warning:: + * + * Deprecated. Use `nghttp2_hd_inflate_hd3()` instead. + * * Inflates name/value block stored in |in| with length |inlen|. This * function performs decompression. For each successful emission of * header name/value pair, @@ -5710,6 +6622,95 @@ NGHTTP2_EXTERN ssize_t nghttp2_hd_inflate_hd2(nghttp2_hd_inflater *inflater, const uint8_t *in, size_t inlen, int in_final); +#endif /* NGHTTP2_NO_SSIZE_T */ + +/** + * @function + * + * Inflates name/value block stored in |in| with length |inlen|. This + * function performs decompression. For each successful emission of + * header name/value pair, + * :enum:`nghttp2_hd_inflate_flag.NGHTTP2_HD_INFLATE_EMIT` is set in + * |*inflate_flags| and name/value pair is assigned to the |nv_out| + * and the function returns. The caller must not free the members of + * |nv_out|. + * + * The |nv_out| may include pointers to the memory region in the |in|. + * The caller must retain the |in| while the |nv_out| is used. + * + * The application should call this function repeatedly until the + * ``(*inflate_flags) & NGHTTP2_HD_INFLATE_FINAL`` is nonzero and + * return value is non-negative. If that happens, all given input + * data (|inlen| bytes) are processed successfully. Then the + * application must call `nghttp2_hd_inflate_end_headers()` to prepare + * for the next header block input. + * + * In other words, if |in_final| is nonzero, and this function returns + * |inlen|, you can assert that + * :enum:`nghttp2_hd_inflate_final.NGHTTP2_HD_INFLATE_FINAL` is set in + * |*inflate_flags|. + * + * The caller can feed complete compressed header block. It also can + * feed it in several chunks. The caller must set |in_final| to + * nonzero if the given input is the last block of the compressed + * header. + * + * This function returns the number of bytes processed if it succeeds, + * or one of the following negative error codes: + * + * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` + * Out of memory. + * :enum:`nghttp2_error.NGHTTP2_ERR_HEADER_COMP` + * Inflation process has failed. + * :enum:`nghttp2_error.NGHTTP2_ERR_BUFFER_ERROR` + * The header field name or value is too large. + * + * Example follows:: + * + * int inflate_header_block(nghttp2_hd_inflater *hd_inflater, + * uint8_t *in, size_t inlen, int final) + * { + * nghttp2_ssize rv; + * + * for(;;) { + * nghttp2_nv nv; + * int inflate_flags = 0; + * + * rv = nghttp2_hd_inflate_hd3(hd_inflater, &nv, &inflate_flags, + * in, inlen, final); + * + * if(rv < 0) { + * fprintf(stderr, "inflate failed with error code %td", rv); + * return -1; + * } + * + * in += rv; + * inlen -= rv; + * + * if(inflate_flags & NGHTTP2_HD_INFLATE_EMIT) { + * fwrite(nv.name, nv.namelen, 1, stderr); + * fprintf(stderr, ": "); + * fwrite(nv.value, nv.valuelen, 1, stderr); + * fprintf(stderr, "\n"); + * } + * if(inflate_flags & NGHTTP2_HD_INFLATE_FINAL) { + * nghttp2_hd_inflate_end_headers(hd_inflater); + * break; + * } + * if((inflate_flags & NGHTTP2_HD_INFLATE_EMIT) == 0 && + * inlen == 0) { + * break; + * } + * } + * + * return 0; + * } + * + */ +NGHTTP2_EXTERN nghttp2_ssize nghttp2_hd_inflate_hd3( + nghttp2_hd_inflater *inflater, nghttp2_nv *nv_out, int *inflate_flags, + const uint8_t *in, size_t inlen, int in_final); + /** * @function * @@ -5783,8 +6784,8 @@ typedef struct nghttp2_stream nghttp2_stream; * `nghttp2_session_get_root_stream()`) if 0 is given in |stream_id|. * * Unless |stream_id| == 0, the returned pointer is valid until next - * call of `nghttp2_session_send()`, `nghttp2_session_mem_send()`, - * `nghttp2_session_recv()`, and `nghttp2_session_mem_recv()`. + * call of `nghttp2_session_send()`, `nghttp2_session_mem_send2()`, + * `nghttp2_session_recv()`, and `nghttp2_session_mem_recv2()`. */ NGHTTP2_EXTERN nghttp2_stream * nghttp2_session_find_stream(nghttp2_session *session, int32_t stream_id); @@ -5838,6 +6839,12 @@ nghttp2_stream_get_state(nghttp2_stream *stream); /** * @function * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. + * * Returns root of dependency tree, which is imaginary stream with * stream ID 0. The returned pointer is valid until |session| is * freed by `nghttp2_session_del()`. @@ -5848,6 +6855,13 @@ nghttp2_session_get_root_stream(nghttp2_session *session); /** * @function * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. In the future release after the end of + * 2024, this function will always return NULL. + * * Returns the parent stream of |stream| in dependency tree. Returns * NULL if there is no such stream. */ @@ -5859,6 +6873,13 @@ NGHTTP2_EXTERN int32_t nghttp2_stream_get_stream_id(nghttp2_stream *stream); /** * @function * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. In the future release after the end of + * 2024, this function will always return NULL. + * * Returns the next sibling stream of |stream| in dependency tree. * Returns NULL if there is no such stream. */ @@ -5868,6 +6889,13 @@ nghttp2_stream_get_next_sibling(nghttp2_stream *stream); /** * @function * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. In the future release after the end of + * 2024, this function will always return NULL. + * * Returns the previous sibling stream of |stream| in dependency tree. * Returns NULL if there is no such stream. */ @@ -5877,6 +6905,13 @@ nghttp2_stream_get_previous_sibling(nghttp2_stream *stream); /** * @function * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. In the future release after the end of + * 2024, this function will always return NULL. + * * Returns the first child stream of |stream| in dependency tree. * Returns NULL if there is no such stream. */ @@ -5886,6 +6921,14 @@ nghttp2_stream_get_first_child(nghttp2_stream *stream); /** * @function * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. In the future release after the end of + * 2024, this function will always return + * :macro:`NGHTTP2_DEFAULT_WEIGHT`. + * * Returns dependency weight to the parent stream of |stream|. */ NGHTTP2_EXTERN int32_t nghttp2_stream_get_weight(nghttp2_stream *stream); @@ -5893,6 +6936,13 @@ NGHTTP2_EXTERN int32_t nghttp2_stream_get_weight(nghttp2_stream *stream); /** * @function * + * .. warning:: + * + * Deprecated. :rfc:`7540` priorities are deprecated by + * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible + * prioritization scheme. In the future release after the end of + * 2024, this function will always return 0. + * * Returns the sum of the weight for |stream|'s children. */ NGHTTP2_EXTERN int32_t diff --git a/lib/nghttp2_buf.c b/lib/nghttp2_buf.c index a328447..101035f 100644 --- a/lib/nghttp2_buf.c +++ b/lib/nghttp2_buf.c @@ -430,7 +430,7 @@ int nghttp2_bufs_orb_hold(nghttp2_bufs *bufs, uint8_t b) { return 0; } -ssize_t nghttp2_bufs_remove(nghttp2_bufs *bufs, uint8_t **out) { +nghttp2_ssize nghttp2_bufs_remove(nghttp2_bufs *bufs, uint8_t **out) { size_t len; nghttp2_buf_chain *chain; nghttp2_buf *buf; @@ -462,7 +462,7 @@ ssize_t nghttp2_bufs_remove(nghttp2_bufs *bufs, uint8_t **out) { *out = res; - return (ssize_t)len; + return (nghttp2_ssize)len; } size_t nghttp2_bufs_remove_copy(nghttp2_bufs *bufs, uint8_t *out) { diff --git a/lib/nghttp2_buf.h b/lib/nghttp2_buf.h index 45f62f1..95ff370 100644 --- a/lib/nghttp2_buf.h +++ b/lib/nghttp2_buf.h @@ -349,7 +349,7 @@ int nghttp2_bufs_orb_hold(nghttp2_bufs *bufs, uint8_t b); * NGHTTP2_ERR_NOMEM * Out of memory */ -ssize_t nghttp2_bufs_remove(nghttp2_bufs *bufs, uint8_t **out); +nghttp2_ssize nghttp2_bufs_remove(nghttp2_bufs *bufs, uint8_t **out); /* * Copies all data stored in |bufs| to |out|. This function assumes diff --git a/lib/nghttp2_callbacks.c b/lib/nghttp2_callbacks.c index 3c38214..1776f7d 100644 --- a/lib/nghttp2_callbacks.c +++ b/lib/nghttp2_callbacks.c @@ -45,11 +45,21 @@ void nghttp2_session_callbacks_set_send_callback( cbs->send_callback = send_callback; } +void nghttp2_session_callbacks_set_send_callback2( + nghttp2_session_callbacks *cbs, nghttp2_send_callback2 send_callback) { + cbs->send_callback2 = send_callback; +} + void nghttp2_session_callbacks_set_recv_callback( nghttp2_session_callbacks *cbs, nghttp2_recv_callback recv_callback) { cbs->recv_callback = recv_callback; } +void nghttp2_session_callbacks_set_recv_callback2( + nghttp2_session_callbacks *cbs, nghttp2_recv_callback2 recv_callback) { + cbs->recv_callback2 = recv_callback; +} + void nghttp2_session_callbacks_set_on_frame_recv_callback( nghttp2_session_callbacks *cbs, nghttp2_on_frame_recv_callback on_frame_recv_callback) { @@ -128,12 +138,24 @@ void nghttp2_session_callbacks_set_select_padding_callback( cbs->select_padding_callback = select_padding_callback; } +void nghttp2_session_callbacks_set_select_padding_callback2( + nghttp2_session_callbacks *cbs, + nghttp2_select_padding_callback2 select_padding_callback) { + cbs->select_padding_callback2 = select_padding_callback; +} + void nghttp2_session_callbacks_set_data_source_read_length_callback( nghttp2_session_callbacks *cbs, nghttp2_data_source_read_length_callback data_source_read_length_callback) { cbs->read_length_callback = data_source_read_length_callback; } +void nghttp2_session_callbacks_set_data_source_read_length_callback2( + nghttp2_session_callbacks *cbs, nghttp2_data_source_read_length_callback2 + data_source_read_length_callback) { + cbs->read_length_callback2 = data_source_read_length_callback; +} + void nghttp2_session_callbacks_set_on_begin_frame_callback( nghttp2_session_callbacks *cbs, nghttp2_on_begin_frame_callback on_begin_frame_callback) { @@ -152,6 +174,12 @@ void nghttp2_session_callbacks_set_pack_extension_callback( cbs->pack_extension_callback = pack_extension_callback; } +void nghttp2_session_callbacks_set_pack_extension_callback2( + nghttp2_session_callbacks *cbs, + nghttp2_pack_extension_callback2 pack_extension_callback) { + cbs->pack_extension_callback2 = pack_extension_callback; +} + void nghttp2_session_callbacks_set_unpack_extension_callback( nghttp2_session_callbacks *cbs, nghttp2_unpack_extension_callback unpack_extension_callback) { diff --git a/lib/nghttp2_callbacks.h b/lib/nghttp2_callbacks.h index 61e51fa..a611f48 100644 --- a/lib/nghttp2_callbacks.h +++ b/lib/nghttp2_callbacks.h @@ -36,19 +36,33 @@ */ struct nghttp2_session_callbacks { /** + * Deprecated. Use send_callback2 instead. Callback function + * invoked when the session wants to send data to the remote peer. + * This callback is not necessary if the application uses solely + * `nghttp2_session_mem_send()` to serialize data to transmit. + */ + nghttp2_send_callback send_callback; + /** * Callback function invoked when the session wants to send data to * the remote peer. This callback is not necessary if the - * application uses solely `nghttp2_session_mem_send()` to serialize - * data to transmit. + * application uses solely `nghttp2_session_mem_send2()` to + * serialize data to transmit. */ - nghttp2_send_callback send_callback; + nghttp2_send_callback2 send_callback2; + /** + * Deprecated. Use recv_callback2 instead. Callback function + * invoked when the session wants to receive data from the remote + * peer. This callback is not necessary if the application uses + * solely `nghttp2_session_mem_recv()` to process received data. + */ + nghttp2_recv_callback recv_callback; /** * Callback function invoked when the session wants to receive data * from the remote peer. This callback is not necessary if the - * application uses solely `nghttp2_session_mem_recv()` to process + * application uses solely `nghttp2_session_mem_recv2()` to process * received data. */ - nghttp2_recv_callback recv_callback; + nghttp2_recv_callback2 recv_callback2; /** * Callback function invoked by `nghttp2_session_recv()` when a * frame is received. @@ -100,22 +114,39 @@ struct nghttp2_session_callbacks { nghttp2_on_invalid_header_callback on_invalid_header_callback; nghttp2_on_invalid_header_callback2 on_invalid_header_callback2; /** + * Deprecated. Use select_padding_callback2 instead. Callback + * function invoked when the library asks application how many + * padding bytes are required for the transmission of the given + * frame. + */ + nghttp2_select_padding_callback select_padding_callback; + /** * Callback function invoked when the library asks application how * many padding bytes are required for the transmission of the given * frame. */ - nghttp2_select_padding_callback select_padding_callback; + nghttp2_select_padding_callback2 select_padding_callback2; /** - * The callback function used to determine the length allowed in + * Deprecated. Use read_length_callback2 instead. The callback + * function used to determine the length allowed in * `nghttp2_data_source_read_callback()` */ nghttp2_data_source_read_length_callback read_length_callback; /** + * The callback function used to determine the length allowed in + * `nghttp2_data_source_read_callback2()` + */ + nghttp2_data_source_read_length_callback2 read_length_callback2; + /** * Sets callback function invoked when a frame header is received. */ nghttp2_on_begin_frame_callback on_begin_frame_callback; nghttp2_send_data_callback send_data_callback; + /** + * Deprecated. Use pack_extension_callback2 instead. + */ nghttp2_pack_extension_callback pack_extension_callback; + nghttp2_pack_extension_callback2 pack_extension_callback2; nghttp2_unpack_extension_callback unpack_extension_callback; nghttp2_on_extension_chunk_recv_callback on_extension_chunk_recv_callback; nghttp2_error_callback error_callback; diff --git a/lib/nghttp2_hd.c b/lib/nghttp2_hd.c index 8a2bda6..1b0c713 100644 --- a/lib/nghttp2_hd.c +++ b/lib/nghttp2_hd.c @@ -850,9 +850,10 @@ static size_t encode_length(uint8_t *buf, size_t n, size_t prefix) { * in the next call will be stored in |*shift_ptr|) and returns number * of bytes processed, or returns -1, indicating decoding error. */ -static ssize_t decode_length(uint32_t *res, size_t *shift_ptr, int *fin, - uint32_t initial, size_t shift, const uint8_t *in, - const uint8_t *last, size_t prefix) { +static nghttp2_ssize decode_length(uint32_t *res, size_t *shift_ptr, int *fin, + uint32_t initial, size_t shift, + const uint8_t *in, const uint8_t *last, + size_t prefix) { uint32_t k = (uint8_t)((1 << prefix) - 1); uint32_t n = initial; const uint8_t *start = in; @@ -871,7 +872,7 @@ static ssize_t decode_length(uint32_t *res, size_t *shift_ptr, int *fin, if (++in == last) { *res = n; - return (ssize_t)(in - start); + return (nghttp2_ssize)(in - start); } } @@ -906,12 +907,12 @@ static ssize_t decode_length(uint32_t *res, size_t *shift_ptr, int *fin, if (in == last) { *res = n; - return (ssize_t)(in - start); + return (nghttp2_ssize)(in - start); } *res = n; *fin = 1; - return (ssize_t)(in + 1 - start); + return (nghttp2_ssize)(in + 1 - start); } static int emit_table_size(nghttp2_bufs *bufs, size_t table_size) { @@ -1164,7 +1165,7 @@ static int add_hd_table_incremental(nghttp2_hd_context *context, } typedef struct { - ssize_t index; + nghttp2_ssize index; /* Nonzero if both name and value are matched. */ int name_value_match; } search_result; @@ -1213,8 +1214,8 @@ static search_result search_hd_table(nghttp2_hd_context *context, return res; } - res.index = - (ssize_t)(context->next_seq - 1 - ent->seq + NGHTTP2_STATIC_TABLE_LENGTH); + res.index = (nghttp2_ssize)(context->next_seq - 1 - ent->seq + + NGHTTP2_STATIC_TABLE_LENGTH); res.name_value_match = exact_match; return res; @@ -1343,7 +1344,7 @@ static int deflate_nv(nghttp2_hd_deflater *deflater, nghttp2_bufs *bufs, const nghttp2_nv *nv) { int rv; search_result res; - ssize_t idx; + nghttp2_ssize idx; int indexing_mode; int32_t token; nghttp2_mem *mem; @@ -1379,7 +1380,7 @@ static int deflate_nv(nghttp2_hd_deflater *deflater, nghttp2_bufs *bufs, if (res.name_value_match) { - DEBUGF("deflatehd: name/value match index=%zd\n", idx); + DEBUGF("deflatehd: name/value match index=%td\n", idx); rv = emit_indexed_block(bufs, (size_t)idx); if (rv != 0) { @@ -1390,7 +1391,7 @@ static int deflate_nv(nghttp2_hd_deflater *deflater, nghttp2_bufs *bufs, } if (res.index != -1) { - DEBUGF("deflatehd: name match index=%zd\n", res.index); + DEBUGF("deflatehd: name match index=%td\n", res.index); } if (indexing_mode == NGHTTP2_HD_WITH_INDEXING) { @@ -1491,6 +1492,12 @@ fail: ssize_t nghttp2_hd_deflate_hd(nghttp2_hd_deflater *deflater, uint8_t *buf, size_t buflen, const nghttp2_nv *nv, size_t nvlen) { + return (ssize_t)nghttp2_hd_deflate_hd2(deflater, buf, buflen, nv, nvlen); +} + +nghttp2_ssize nghttp2_hd_deflate_hd2(nghttp2_hd_deflater *deflater, + uint8_t *buf, size_t buflen, + const nghttp2_nv *nv, size_t nvlen) { nghttp2_bufs bufs; int rv; nghttp2_mem *mem; @@ -1517,12 +1524,18 @@ ssize_t nghttp2_hd_deflate_hd(nghttp2_hd_deflater *deflater, uint8_t *buf, return rv; } - return (ssize_t)buflen; + return (nghttp2_ssize)buflen; } ssize_t nghttp2_hd_deflate_hd_vec(nghttp2_hd_deflater *deflater, const nghttp2_vec *vec, size_t veclen, const nghttp2_nv *nv, size_t nvlen) { + return (ssize_t)nghttp2_hd_deflate_hd_vec2(deflater, vec, veclen, nv, nvlen); +} + +nghttp2_ssize nghttp2_hd_deflate_hd_vec2(nghttp2_hd_deflater *deflater, + const nghttp2_vec *vec, size_t veclen, + const nghttp2_nv *nv, size_t nvlen) { nghttp2_bufs bufs; int rv; nghttp2_mem *mem; @@ -1550,7 +1563,7 @@ ssize_t nghttp2_hd_deflate_hd_vec(nghttp2_hd_deflater *deflater, return rv; } - return (ssize_t)buflen; + return (nghttp2_ssize)buflen; } size_t nghttp2_hd_deflate_bound(nghttp2_hd_deflater *deflater, @@ -1643,10 +1656,11 @@ static void hd_inflate_set_huffman_encoded(nghttp2_hd_inflater *inflater, * NGHTTP2_ERR_HEADER_COMP * Integer decoding failed */ -static ssize_t hd_inflate_read_len(nghttp2_hd_inflater *inflater, int *rfin, - const uint8_t *in, const uint8_t *last, - size_t prefix, size_t maxlen) { - ssize_t rv; +static nghttp2_ssize hd_inflate_read_len(nghttp2_hd_inflater *inflater, + int *rfin, const uint8_t *in, + const uint8_t *last, size_t prefix, + size_t maxlen) { + nghttp2_ssize rv; uint32_t out; *rfin = 0; @@ -1684,10 +1698,10 @@ static ssize_t hd_inflate_read_len(nghttp2_hd_inflater *inflater, int *rfin, * NGHTTP2_ERR_HEADER_COMP * Huffman decoding failed */ -static ssize_t hd_inflate_read_huff(nghttp2_hd_inflater *inflater, - nghttp2_buf *buf, const uint8_t *in, - const uint8_t *last) { - ssize_t readlen; +static nghttp2_ssize hd_inflate_read_huff(nghttp2_hd_inflater *inflater, + nghttp2_buf *buf, const uint8_t *in, + const uint8_t *last) { + nghttp2_ssize readlen; int fin = 0; if ((size_t)(last - in) >= inflater->left) { last = in + inflater->left; @@ -1721,14 +1735,15 @@ static ssize_t hd_inflate_read_huff(nghttp2_hd_inflater *inflater, * NGHTTP2_ERR_HEADER_COMP * Header decompression failed */ -static ssize_t hd_inflate_read(nghttp2_hd_inflater *inflater, nghttp2_buf *buf, - const uint8_t *in, const uint8_t *last) { +static nghttp2_ssize hd_inflate_read(nghttp2_hd_inflater *inflater, + nghttp2_buf *buf, const uint8_t *in, + const uint8_t *last) { size_t len = nghttp2_min((size_t)(last - in), inflater->left); buf->last = nghttp2_cpymem(buf->last, in, len); inflater->left -= len; - return (ssize_t)len; + return (nghttp2_ssize)len; } /* @@ -1843,7 +1858,15 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_inflater *inflater, nghttp2_nv *nv_out, ssize_t nghttp2_hd_inflate_hd2(nghttp2_hd_inflater *inflater, nghttp2_nv *nv_out, int *inflate_flags, const uint8_t *in, size_t inlen, int in_final) { - ssize_t rv; + return (nghttp2_ssize)nghttp2_hd_inflate_hd3(inflater, nv_out, inflate_flags, + in, inlen, in_final); +} + +nghttp2_ssize nghttp2_hd_inflate_hd3(nghttp2_hd_inflater *inflater, + nghttp2_nv *nv_out, int *inflate_flags, + const uint8_t *in, size_t inlen, + int in_final) { + nghttp2_ssize rv; nghttp2_hd_nv hd_nv; rv = nghttp2_hd_inflate_hd_nv(inflater, &hd_nv, inflate_flags, in, inlen, @@ -1866,11 +1889,11 @@ ssize_t nghttp2_hd_inflate_hd2(nghttp2_hd_inflater *inflater, return rv; } -ssize_t nghttp2_hd_inflate_hd_nv(nghttp2_hd_inflater *inflater, - nghttp2_hd_nv *nv_out, int *inflate_flags, - const uint8_t *in, size_t inlen, - int in_final) { - ssize_t rv = 0; +nghttp2_ssize nghttp2_hd_inflate_hd_nv(nghttp2_hd_inflater *inflater, + nghttp2_hd_nv *nv_out, + int *inflate_flags, const uint8_t *in, + size_t inlen, int in_final) { + nghttp2_ssize rv = 0; const uint8_t *first = in; const uint8_t *last = in + inlen; int rfin = 0; @@ -1992,7 +2015,7 @@ ssize_t nghttp2_hd_inflate_hd_nv(nghttp2_hd_inflater *inflater, inflater->state = NGHTTP2_HD_STATE_OPCODE; *inflate_flags |= NGHTTP2_HD_INFLATE_EMIT; - return (ssize_t)(in - first); + return (nghttp2_ssize)(in - first); } else { inflater->index = inflater->left; --inflater->index; @@ -2050,7 +2073,7 @@ ssize_t nghttp2_hd_inflate_hd_nv(nghttp2_hd_inflater *inflater, in += rv; - DEBUGF("inflatehd: %zd bytes read\n", rv); + DEBUGF("inflatehd: %td bytes read\n", rv); if (inflater->left) { DEBUGF("inflatehd: still %zu bytes to go\n", inflater->left); @@ -2072,7 +2095,7 @@ ssize_t nghttp2_hd_inflate_hd_nv(nghttp2_hd_inflater *inflater, in += rv; - DEBUGF("inflatehd: %zd bytes read\n", rv); + DEBUGF("inflatehd: %td bytes read\n", rv); if (inflater->left) { DEBUGF("inflatehd: still %zu bytes to go\n", inflater->left); @@ -2138,7 +2161,7 @@ ssize_t nghttp2_hd_inflate_hd_nv(nghttp2_hd_inflater *inflater, in += rv; - DEBUGF("inflatehd: %zd bytes read\n", rv); + DEBUGF("inflatehd: %td bytes read\n", rv); if (inflater->left) { DEBUGF("inflatehd: still %zu bytes to go\n", inflater->left); @@ -2162,18 +2185,18 @@ ssize_t nghttp2_hd_inflate_hd_nv(nghttp2_hd_inflater *inflater, inflater->state = NGHTTP2_HD_STATE_OPCODE; *inflate_flags |= NGHTTP2_HD_INFLATE_EMIT; - return (ssize_t)(in - first); + return (nghttp2_ssize)(in - first); case NGHTTP2_HD_STATE_READ_VALUE: rv = hd_inflate_read(inflater, &inflater->valuebuf, in, last); if (rv < 0) { - DEBUGF("inflatehd: value read failure %zd: %s\n", rv, + DEBUGF("inflatehd: value read failure %td: %s\n", rv, nghttp2_strerror((int)rv)); goto fail; } in += rv; - DEBUGF("inflatehd: %zd bytes read\n", rv); + DEBUGF("inflatehd: %td bytes read\n", rv); if (inflater->left) { DEBUGF("inflatehd: still %zu bytes to go\n", inflater->left); @@ -2196,7 +2219,7 @@ ssize_t nghttp2_hd_inflate_hd_nv(nghttp2_hd_inflater *inflater, inflater->state = NGHTTP2_HD_STATE_OPCODE; *inflate_flags |= NGHTTP2_HD_INFLATE_EMIT; - return (ssize_t)(in - first); + return (nghttp2_ssize)(in - first); } } @@ -2216,7 +2239,7 @@ ssize_t nghttp2_hd_inflate_hd_nv(nghttp2_hd_inflater *inflater, } *inflate_flags |= NGHTTP2_HD_INFLATE_FINAL; } - return (ssize_t)(in - first); + return (nghttp2_ssize)(in - first); almost_ok: if (in_final) { @@ -2226,10 +2249,10 @@ almost_ok: goto fail; } - return (ssize_t)(in - first); + return (nghttp2_ssize)(in - first); fail: - DEBUGF("inflatehd: error return %zd\n", rv); + DEBUGF("inflatehd: error return %td\n", rv); inflater->ctx.bad = 1; return rv; @@ -2297,9 +2320,10 @@ int nghttp2_hd_emit_table_size(nghttp2_bufs *bufs, size_t table_size) { return emit_table_size(bufs, table_size); } -ssize_t nghttp2_hd_decode_length(uint32_t *res, size_t *shift_ptr, int *fin, - uint32_t initial, size_t shift, uint8_t *in, - uint8_t *last, size_t prefix) { +nghttp2_ssize nghttp2_hd_decode_length(uint32_t *res, size_t *shift_ptr, + int *fin, uint32_t initial, size_t shift, + uint8_t *in, uint8_t *last, + size_t prefix) { return decode_length(res, shift_ptr, fin, initial, shift, in, last, prefix); } diff --git a/lib/nghttp2_hd.h b/lib/nghttp2_hd.h index 6de0052..38a31a8 100644 --- a/lib/nghttp2_hd.h +++ b/lib/nghttp2_hd.h @@ -357,9 +357,10 @@ void nghttp2_hd_inflate_free(nghttp2_hd_inflater *inflater); * that return values and semantics are the same as * nghttp2_hd_inflate_hd(). */ -ssize_t nghttp2_hd_inflate_hd_nv(nghttp2_hd_inflater *inflater, - nghttp2_hd_nv *nv_out, int *inflate_flags, - const uint8_t *in, size_t inlen, int in_final); +nghttp2_ssize nghttp2_hd_inflate_hd_nv(nghttp2_hd_inflater *inflater, + nghttp2_hd_nv *nv_out, + int *inflate_flags, const uint8_t *in, + size_t inlen, int in_final); /* For unittesting purpose */ int nghttp2_hd_emit_indname_block(nghttp2_bufs *bufs, size_t index, @@ -376,9 +377,10 @@ int nghttp2_hd_emit_table_size(nghttp2_bufs *bufs, size_t table_size); nghttp2_hd_nv nghttp2_hd_table_get(nghttp2_hd_context *context, size_t index); /* For unittesting purpose */ -ssize_t nghttp2_hd_decode_length(uint32_t *res, size_t *shift_ptr, int *fin, - uint32_t initial, size_t shift, uint8_t *in, - uint8_t *last, size_t prefix); +nghttp2_ssize nghttp2_hd_decode_length(uint32_t *res, size_t *shift_ptr, + int *fin, uint32_t initial, size_t shift, + uint8_t *in, uint8_t *last, + size_t prefix); /* Huffman encoding/decoding functions */ @@ -427,9 +429,9 @@ void nghttp2_hd_huff_decode_context_init(nghttp2_hd_huff_decode_context *ctx); * NGHTTP2_ERR_HEADER_COMP * Decoding process has failed. */ -ssize_t nghttp2_hd_huff_decode(nghttp2_hd_huff_decode_context *ctx, - nghttp2_buf *buf, const uint8_t *src, - size_t srclen, int fin); +nghttp2_ssize nghttp2_hd_huff_decode(nghttp2_hd_huff_decode_context *ctx, + nghttp2_buf *buf, const uint8_t *src, + size_t srclen, int fin); /* * nghttp2_hd_huff_decode_failure_state returns nonzero if |ctx| diff --git a/lib/nghttp2_hd_huffman.c b/lib/nghttp2_hd_huffman.c index ac90f49..959053f 100644 --- a/lib/nghttp2_hd_huffman.c +++ b/lib/nghttp2_hd_huffman.c @@ -107,9 +107,9 @@ void nghttp2_hd_huff_decode_context_init(nghttp2_hd_huff_decode_context *ctx) { ctx->fstate = NGHTTP2_HUFF_ACCEPTED; } -ssize_t nghttp2_hd_huff_decode(nghttp2_hd_huff_decode_context *ctx, - nghttp2_buf *buf, const uint8_t *src, - size_t srclen, int final) { +nghttp2_ssize nghttp2_hd_huff_decode(nghttp2_hd_huff_decode_context *ctx, + nghttp2_buf *buf, const uint8_t *src, + size_t srclen, int final) { const uint8_t *end = src + srclen; nghttp2_huff_decode node = {ctx->fstate, 0}; const nghttp2_huff_decode *t = &node; @@ -136,7 +136,7 @@ ssize_t nghttp2_hd_huff_decode(nghttp2_hd_huff_decode_context *ctx, return NGHTTP2_ERR_HEADER_COMP; } - return (ssize_t)srclen; + return (nghttp2_ssize)srclen; } int nghttp2_hd_huff_decode_failure_state(nghttp2_hd_huff_decode_context *ctx) { diff --git a/lib/nghttp2_outbound_item.c b/lib/nghttp2_outbound_item.c index 2a3041d..a9e9f76 100644 --- a/lib/nghttp2_outbound_item.c +++ b/lib/nghttp2_outbound_item.c @@ -27,6 +27,32 @@ #include <assert.h> #include <string.h> +nghttp2_data_provider_wrap * +nghttp2_data_provider_wrap_v1(nghttp2_data_provider_wrap *dpw, + const nghttp2_data_provider *data_prd) { + if (!data_prd) { + return NULL; + } + + dpw->version = NGHTTP2_DATA_PROVIDER_V1; + dpw->data_prd.v1 = *data_prd; + + return dpw; +} + +nghttp2_data_provider_wrap * +nghttp2_data_provider_wrap_v2(nghttp2_data_provider_wrap *dpw, + const nghttp2_data_provider2 *data_prd) { + if (!data_prd) { + return NULL; + } + + dpw->version = NGHTTP2_DATA_PROVIDER_V2; + dpw->data_prd.v2 = *data_prd; + + return dpw; +} + void nghttp2_outbound_item_init(nghttp2_outbound_item *item) { item->cycle = 0; item->qnext = NULL; diff --git a/lib/nghttp2_outbound_item.h b/lib/nghttp2_outbound_item.h index bd4611b..4e91750 100644 --- a/lib/nghttp2_outbound_item.h +++ b/lib/nghttp2_outbound_item.h @@ -33,9 +33,32 @@ #include "nghttp2_frame.h" #include "nghttp2_mem.h" +#define NGHTTP2_DATA_PROVIDER_V1 1 +#define NGHTTP2_DATA_PROVIDER_V2 2 + +typedef struct nghttp2_data_provider_wrap { + int version; + union { + struct { + nghttp2_data_source source; + void *read_callback; + }; + nghttp2_data_provider v1; + nghttp2_data_provider2 v2; + } data_prd; +} nghttp2_data_provider_wrap; + +nghttp2_data_provider_wrap * +nghttp2_data_provider_wrap_v1(nghttp2_data_provider_wrap *dpw, + const nghttp2_data_provider *data_prd); + +nghttp2_data_provider_wrap * +nghttp2_data_provider_wrap_v2(nghttp2_data_provider_wrap *dpw, + const nghttp2_data_provider2 *data_prd); + /* struct used for HEADERS and PUSH_PROMISE frame */ typedef struct { - nghttp2_data_provider data_prd; + nghttp2_data_provider_wrap dpw; void *stream_user_data; /* error code when request HEADERS is canceled by RST_STREAM while it is in queue. */ @@ -50,7 +73,7 @@ typedef struct { /** * The data to be sent for this DATA frame. */ - nghttp2_data_provider data_prd; + nghttp2_data_provider_wrap dpw; /** * The flags of DATA frame. We use separate flags here and * nghttp2_data frame. The latter contains flags actually sent to diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c index ce21caf..226cdd5 100644 --- a/lib/nghttp2_session.c +++ b/lib/nghttp2_session.c @@ -39,6 +39,7 @@ #include "nghttp2_extpri.h" #include "nghttp2_time.h" #include "nghttp2_debug.h" +#include "nghttp2_submit.h" /* * Returns non-zero if the number of outgoing opened streams is larger @@ -2103,10 +2104,9 @@ static int session_predicate_priority_update_send(nghttp2_session *session, /* Take into account settings max frame size and both connection-level flow control here */ -static ssize_t -nghttp2_session_enforce_flow_control_limits(nghttp2_session *session, - nghttp2_stream *stream, - ssize_t requested_window_size) { +static nghttp2_ssize nghttp2_session_enforce_flow_control_limits( + nghttp2_session *session, nghttp2_stream *stream, + nghttp2_ssize requested_window_size) { DEBUGF("send: remote windowsize connection=%d, remote maxframsize=%u, " "stream(id %d)=%d\n", session->remote_window_size, session->remote_settings.max_frame_size, @@ -2126,12 +2126,12 @@ nghttp2_session_enforce_flow_control_limits(nghttp2_session *session, */ static size_t nghttp2_session_next_data_read(nghttp2_session *session, nghttp2_stream *stream) { - ssize_t window_size; + nghttp2_ssize window_size; window_size = nghttp2_session_enforce_flow_control_limits( session, stream, NGHTTP2_DATA_PAYLOADLEN); - DEBUGF("send: available window=%zd\n", window_size); + DEBUGF("send: available window=%td\n", window_size); return window_size > 0 ? (size_t)window_size : 0; } @@ -2186,29 +2186,33 @@ static int nghttp2_session_predicate_data_send(nghttp2_session *session, return NGHTTP2_ERR_INVALID_STREAM_STATE; } -static ssize_t session_call_select_padding(nghttp2_session *session, - const nghttp2_frame *frame, - size_t max_payloadlen) { - ssize_t rv; +static nghttp2_ssize session_call_select_padding(nghttp2_session *session, + const nghttp2_frame *frame, + size_t max_payloadlen) { + nghttp2_ssize rv; + size_t max_paddedlen; - if (frame->hd.length >= max_payloadlen) { - return (ssize_t)frame->hd.length; + if (frame->hd.length >= max_payloadlen || + (!session->callbacks.select_padding_callback2 && + !session->callbacks.select_padding_callback)) { + return (nghttp2_ssize)frame->hd.length; } - if (session->callbacks.select_padding_callback) { - size_t max_paddedlen; - - max_paddedlen = - nghttp2_min(frame->hd.length + NGHTTP2_MAX_PADLEN, max_payloadlen); + max_paddedlen = + nghttp2_min(frame->hd.length + NGHTTP2_MAX_PADLEN, max_payloadlen); - rv = session->callbacks.select_padding_callback( + if (session->callbacks.select_padding_callback2) { + rv = session->callbacks.select_padding_callback2( session, frame, max_paddedlen, session->user_data); - if (rv < (ssize_t)frame->hd.length || rv > (ssize_t)max_paddedlen) { - return NGHTTP2_ERR_CALLBACK_FAILURE; - } - return rv; + } else { + rv = (nghttp2_ssize)session->callbacks.select_padding_callback( + session, frame, max_paddedlen, session->user_data); + } + if (rv < (nghttp2_ssize)frame->hd.length || + rv > (nghttp2_ssize)max_paddedlen) { + return NGHTTP2_ERR_CALLBACK_FAILURE; } - return (ssize_t)frame->hd.length; + return rv; } /* Add padding to HEADERS or PUSH_PROMISE. We use @@ -2216,7 +2220,7 @@ static ssize_t session_call_select_padding(nghttp2_session *session, frame->push_promise has also padlen in the same position. */ static int session_headers_add_pad(nghttp2_session *session, nghttp2_frame *frame) { - ssize_t padded_payloadlen; + nghttp2_ssize padded_payloadlen; nghttp2_active_outbound_item *aob; nghttp2_bufs *framebufs; size_t padlen; @@ -2237,7 +2241,7 @@ static int session_headers_add_pad(nghttp2_session *session, padlen = (size_t)padded_payloadlen - frame->hd.length; - DEBUGF("send: padding selected: payloadlen=%zd, padlen=%zu\n", + DEBUGF("send: padding selected: payloadlen=%td, padlen=%zu\n", padded_payloadlen, padlen); nghttp2_frame_add_pad(framebufs, &frame->hd, padlen, 0); @@ -2257,18 +2261,24 @@ static size_t session_estimate_headers_payload(nghttp2_session *session, static int session_pack_extension(nghttp2_session *session, nghttp2_bufs *bufs, nghttp2_frame *frame) { - ssize_t rv; + nghttp2_ssize rv; nghttp2_buf *buf; size_t buflen; size_t framelen; - assert(session->callbacks.pack_extension_callback); + assert(session->callbacks.pack_extension_callback2 || + session->callbacks.pack_extension_callback); buf = &bufs->head->buf; buflen = nghttp2_min(nghttp2_buf_avail(buf), NGHTTP2_MAX_PAYLOADLEN); - rv = session->callbacks.pack_extension_callback(session, buf->last, buflen, - frame, session->user_data); + if (session->callbacks.pack_extension_callback2) { + rv = session->callbacks.pack_extension_callback2(session, buf->last, buflen, + frame, session->user_data); + } else { + rv = (nghttp2_ssize)session->callbacks.pack_extension_callback( + session, buf->last, buflen, frame, session->user_data); + } if (rv == NGHTTP2_ERR_CANCEL) { return (int)rv; } @@ -2451,7 +2461,7 @@ static int session_prep_frame(nghttp2_session *session, return rv; } - DEBUGF("send: before padding, HEADERS serialized in %zd bytes\n", + DEBUGF("send: before padding, HEADERS serialized in %zu bytes\n", nghttp2_bufs_len(&session->aob.framebufs)); rv = session_headers_add_pad(session, frame); @@ -2460,7 +2470,7 @@ static int session_prep_frame(nghttp2_session *session, return rv; } - DEBUGF("send: HEADERS finally serialized in %zd bytes\n", + DEBUGF("send: HEADERS finally serialized in %zu bytes\n", nghttp2_bufs_len(&session->aob.framebufs)); if (frame->headers.cat == NGHTTP2_HCAT_REQUEST) { @@ -2877,7 +2887,7 @@ static int session_after_frame_sent1(nghttp2_session *session) { /* Call on_frame_send_callback after nghttp2_stream_detach_item(), so that application can issue - nghttp2_submit_data() in the callback. */ + nghttp2_submit_data2() in the callback. */ if (session->callbacks.on_frame_send_callback) { rv = session_call_on_frame_send(session, frame); if (nghttp2_is_fatal(rv)) { @@ -2949,15 +2959,17 @@ static int session_after_frame_sent1(nghttp2_session *session) { } /* We assume aux_data is a pointer to nghttp2_headers_aux_data */ aux_data = &item->aux_data.headers; - if (aux_data->data_prd.read_callback) { - /* nghttp2_submit_data() makes a copy of aux_data->data_prd */ - rv = nghttp2_submit_data(session, NGHTTP2_FLAG_END_STREAM, - frame->hd.stream_id, &aux_data->data_prd); + if (aux_data->dpw.data_prd.read_callback) { + /* nghttp2_submit_data_shared() makes a copy of + aux_data->dpw */ + rv = nghttp2_submit_data_shared(session, NGHTTP2_FLAG_END_STREAM, + frame->hd.stream_id, &aux_data->dpw); if (nghttp2_is_fatal(rv)) { return rv; } - /* TODO nghttp2_submit_data() may fail if stream has already - DATA frame item. We might have to handle it here. */ + /* TODO nghttp2_submit_data_shared() may fail if stream has + already DATA frame item. We might have to handle it + here. */ } return 0; } @@ -2978,14 +2990,15 @@ static int session_after_frame_sent1(nghttp2_session *session) { } /* We assume aux_data is a pointer to nghttp2_headers_aux_data */ aux_data = &item->aux_data.headers; - if (aux_data->data_prd.read_callback) { - rv = nghttp2_submit_data(session, NGHTTP2_FLAG_END_STREAM, - frame->hd.stream_id, &aux_data->data_prd); + if (aux_data->dpw.data_prd.read_callback) { + rv = nghttp2_submit_data_shared(session, NGHTTP2_FLAG_END_STREAM, + frame->hd.stream_id, &aux_data->dpw); if (nghttp2_is_fatal(rv)) { return rv; } - /* TODO nghttp2_submit_data() may fail if stream has already - DATA frame item. We might have to handle it here. */ + /* TODO nghttp2_submit_data_shared() may fail if stream has + already DATA frame item. We might have to handle it + here. */ } return 0; default: @@ -3144,7 +3157,7 @@ static void session_after_frame_sent2(nghttp2_session *session) { aux_data = &item->aux_data.data; /* On EOF, we have already detached data. Please note that - application may issue nghttp2_submit_data() in + application may issue nghttp2_submit_data2() in on_frame_send_callback (call from session_after_frame_sent1), which attach data to stream. We don't want to detach it. */ if (aux_data->eof) { @@ -3191,7 +3204,7 @@ static int session_call_send_data(nghttp2_session *session, aux_data = &item->aux_data.data; rv = session->callbacks.send_data_callback(session, frame, buf->pos, length, - &aux_data->data_prd.source, + &aux_data->dpw.data_prd.source, session->user_data); switch (rv) { @@ -3205,9 +3218,9 @@ static int session_call_send_data(nghttp2_session *session, } } -static ssize_t nghttp2_session_mem_send_internal(nghttp2_session *session, - const uint8_t **data_ptr, - int fast_cb) { +static nghttp2_ssize nghttp2_session_mem_send_internal(nghttp2_session *session, + const uint8_t **data_ptr, + int fast_cb) { int rv; nghttp2_active_outbound_item *aob; nghttp2_bufs *framebufs; @@ -3385,7 +3398,7 @@ static ssize_t nghttp2_session_mem_send_internal(nghttp2_session *session, } } - DEBUGF("send: start transmitting frame type=%u, length=%zd\n", + DEBUGF("send: start transmitting frame type=%u, length=%td\n", framebufs->cur->buf.pos[3], framebufs->cur->buf.last - framebufs->cur->buf.pos); @@ -3425,7 +3438,7 @@ static ssize_t nghttp2_session_mem_send_internal(nghttp2_session *session, everything, we will adjust it. */ buf->pos += datalen; - return (ssize_t)datalen; + return (nghttp2_ssize)datalen; } case NGHTTP2_OB_SEND_NO_COPY: { nghttp2_stream *stream; @@ -3502,7 +3515,7 @@ static ssize_t nghttp2_session_mem_send_internal(nghttp2_session *session, buf->pos += datalen; - return (ssize_t)datalen; + return (nghttp2_ssize)datalen; } } } @@ -3510,8 +3523,13 @@ static ssize_t nghttp2_session_mem_send_internal(nghttp2_session *session, ssize_t nghttp2_session_mem_send(nghttp2_session *session, const uint8_t **data_ptr) { + return (ssize_t)nghttp2_session_mem_send2(session, data_ptr); +} + +nghttp2_ssize nghttp2_session_mem_send2(nghttp2_session *session, + const uint8_t **data_ptr) { int rv; - ssize_t len; + nghttp2_ssize len; *data_ptr = NULL; @@ -3528,7 +3546,7 @@ ssize_t nghttp2_session_mem_send(nghttp2_session *session, rv = session_after_frame_sent1(session); if (rv < 0) { assert(nghttp2_is_fatal(rv)); - return (ssize_t)rv; + return (nghttp2_ssize)rv; } } @@ -3537,8 +3555,8 @@ ssize_t nghttp2_session_mem_send(nghttp2_session *session, int nghttp2_session_send(nghttp2_session *session) { const uint8_t *data = NULL; - ssize_t datalen; - ssize_t sentlen; + nghttp2_ssize datalen; + nghttp2_ssize sentlen; nghttp2_bufs *framebufs; framebufs = &session->aob.framebufs; @@ -3548,8 +3566,13 @@ int nghttp2_session_send(nghttp2_session *session) { if (datalen <= 0) { return (int)datalen; } - sentlen = session->callbacks.send_callback(session, data, (size_t)datalen, - 0, session->user_data); + if (session->callbacks.send_callback2) { + sentlen = session->callbacks.send_callback2( + session, data, (size_t)datalen, 0, session->user_data); + } else { + sentlen = (nghttp2_ssize)session->callbacks.send_callback( + session, data, (size_t)datalen, 0, session->user_data); + } if (sentlen < 0) { if (sentlen == NGHTTP2_ERR_WOULDBLOCK) { /* Transmission canceled. Rewind the offset */ @@ -3564,11 +3587,17 @@ int nghttp2_session_send(nghttp2_session *session) { } } -static ssize_t session_recv(nghttp2_session *session, uint8_t *buf, - size_t len) { - ssize_t rv; - rv = session->callbacks.recv_callback(session, buf, len, 0, - session->user_data); +static nghttp2_ssize session_recv(nghttp2_session *session, uint8_t *buf, + size_t len) { + nghttp2_ssize rv; + + if (session->callbacks.recv_callback2) { + rv = session->callbacks.recv_callback2(session, buf, len, 0, + session->user_data); + } else { + rv = (nghttp2_ssize)session->callbacks.recv_callback(session, buf, len, 0, + session->user_data); + } if (rv > 0) { if ((size_t)rv > len) { return NGHTTP2_ERR_CALLBACK_FAILURE; @@ -3870,7 +3899,7 @@ static int session_inflate_handle_invalid_connection(nghttp2_session *session, static int inflate_header_block(nghttp2_session *session, nghttp2_frame *frame, size_t *readlen_ptr, uint8_t *in, size_t inlen, int final, int call_header_cb) { - ssize_t proclen; + nghttp2_ssize proclen; int rv; int inflate_flags; nghttp2_hd_nv nv; @@ -3923,7 +3952,7 @@ static int inflate_header_block(nghttp2_session *session, nghttp2_frame *frame, inlen -= (size_t)proclen; *readlen_ptr += (size_t)proclen; - DEBUGF("recv: proclen=%zd\n", proclen); + DEBUGF("recv: proclen=%td\n", proclen); if (call_header_cb && (inflate_flags & NGHTTP2_HD_INFLATE_EMIT)) { rv = 0; @@ -5763,7 +5792,7 @@ static int inbound_frame_handle_pad(nghttp2_inbound_frame *iframe, * Computes number of padding based on flags. This function returns * the calculated length if it succeeds, or -1. */ -static ssize_t inbound_frame_compute_pad(nghttp2_inbound_frame *iframe) { +static nghttp2_ssize inbound_frame_compute_pad(nghttp2_inbound_frame *iframe) { size_t padlen; /* 1 for Pad Length field */ @@ -5778,7 +5807,7 @@ static ssize_t inbound_frame_compute_pad(nghttp2_inbound_frame *iframe) { iframe->padlen = padlen; - return (ssize_t)padlen; + return (nghttp2_ssize)padlen; } /* @@ -5787,9 +5816,9 @@ static ssize_t inbound_frame_compute_pad(nghttp2_inbound_frame *iframe) { * |payloadleft| does not include |readlen|. If padding was started * strictly before this data chunk, this function returns -1. */ -static ssize_t inbound_frame_effective_readlen(nghttp2_inbound_frame *iframe, - size_t payloadleft, - size_t readlen) { +static nghttp2_ssize +inbound_frame_effective_readlen(nghttp2_inbound_frame *iframe, + size_t payloadleft, size_t readlen) { size_t trail_padlen = nghttp2_frame_trail_padlen(&iframe->frame, iframe->padlen); @@ -5799,19 +5828,24 @@ static ssize_t inbound_frame_effective_readlen(nghttp2_inbound_frame *iframe, if (readlen < padlen) { return -1; } - return (ssize_t)(readlen - padlen); + return (nghttp2_ssize)(readlen - padlen); } - return (ssize_t)(readlen); + return (nghttp2_ssize)(readlen); } static const uint8_t static_in[] = {0}; ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, size_t inlen) { + return (ssize_t)nghttp2_session_mem_recv2(session, in, inlen); +} + +nghttp2_ssize nghttp2_session_mem_recv2(nghttp2_session *session, + const uint8_t *in, size_t inlen) { const uint8_t *first, *last; nghttp2_inbound_frame *iframe = &session->iframe; size_t readlen; - ssize_t padlen; + nghttp2_ssize padlen; int rv; int busy = 0; nghttp2_frame_hd cont_hd; @@ -5841,7 +5875,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (!nghttp2_session_want_read(session)) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } for (;;) { @@ -5871,7 +5905,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, in += readlen; if (nghttp2_buf_mark_avail(&iframe->sbuf)) { - return (ssize_t)(in - first); + return (nghttp2_ssize)(in - first); } if (iframe->sbuf.pos[3] != NGHTTP2_SETTINGS || @@ -5893,7 +5927,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, return rv; } - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } iframe->state = NGHTTP2_IB_READ_HEAD; @@ -5908,7 +5942,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, in += readlen; if (nghttp2_buf_mark_avail(&iframe->sbuf)) { - return (ssize_t)(in - first); + return (nghttp2_ssize)(in - first); } nghttp2_frame_unpack_frame_hd(&iframe->frame.hd, iframe->sbuf.pos); @@ -5929,7 +5963,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, return rv; } - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } switch (iframe->frame.hd.type) { @@ -5944,7 +5978,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, rv = session_on_data_received_fail_fast(session); if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } if (rv == NGHTTP2_ERR_IGN_PAYLOAD) { DEBUGF("recv: DATA not allowed stream_id=%d\n", @@ -5966,7 +6000,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, if (nghttp2_is_fatal(rv)) { return rv; } - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } if (rv == 1) { @@ -5993,7 +6027,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, if (nghttp2_is_fatal(rv)) { return rv; } - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } if (rv == 1) { @@ -6036,7 +6070,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, busy = 1; if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } if (rv == NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE) { @@ -6137,7 +6171,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, if (nghttp2_is_fatal(rv)) { return rv; } - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } iframe->iv = nghttp2_mem_malloc(mem, sizeof(nghttp2_settings_entry) * @@ -6175,7 +6209,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, if (nghttp2_is_fatal(rv)) { return rv; } - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } if (rv == 1) { @@ -6235,7 +6269,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, return rv; } - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; default: DEBUGF("recv: extension frame\n"); @@ -6346,7 +6380,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, if (nghttp2_is_fatal(rv)) { return rv; } - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } if (iframe->payloadleft < 4) { @@ -6404,11 +6438,11 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, in += readlen; iframe->payloadleft -= readlen; - DEBUGF("recv: readlen=%zu, payloadleft=%zu, left=%zd\n", readlen, + DEBUGF("recv: readlen=%zu, payloadleft=%zu, left=%zu\n", readlen, iframe->payloadleft, nghttp2_buf_mark_avail(&iframe->sbuf)); if (nghttp2_buf_mark_avail(&iframe->sbuf)) { - return (ssize_t)(in - first); + return (nghttp2_ssize)(in - first); } switch (iframe->frame.hd.type) { @@ -6424,7 +6458,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, if (nghttp2_is_fatal(rv)) { return rv; } - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } iframe->frame.headers.padlen = (size_t)padlen; @@ -6451,7 +6485,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, busy = 1; if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } if (rv == NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE) { @@ -6481,7 +6515,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } } @@ -6495,7 +6529,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } session_inbound_frame_reset(session); @@ -6513,7 +6547,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, if (nghttp2_is_fatal(rv)) { return rv; } - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } iframe->frame.push_promise.padlen = (size_t)padlen; @@ -6539,7 +6573,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, busy = 1; if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } if (rv == NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE) { @@ -6568,7 +6602,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } session_inbound_frame_reset(session); @@ -6603,7 +6637,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } session_inbound_frame_reset(session); @@ -6661,7 +6695,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, break; case NGHTTP2_IB_READ_HEADER_BLOCK: case NGHTTP2_IB_IGN_HEADER_BLOCK: { - ssize_t data_readlen; + nghttp2_ssize data_readlen; size_t trail_padlen; int final; #ifdef DEBUGBUILD @@ -6705,14 +6739,14 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } if (rv == NGHTTP2_ERR_PAUSE) { in += hd_proclen; iframe->payloadleft -= hd_proclen; - return (ssize_t)(in - first); + return (nghttp2_ssize)(in - first); } if (rv == NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE) { @@ -6819,7 +6853,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, assert(iframe->state == NGHTTP2_IB_IGN_ALL); - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; case NGHTTP2_IB_READ_SETTINGS: DEBUGF("recv: [IB_READ_SETTINGS]\n"); @@ -6849,7 +6883,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } session_inbound_frame_reset(session); @@ -6883,7 +6917,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } session_inbound_frame_reset(session); @@ -6903,7 +6937,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, in += readlen; if (nghttp2_buf_mark_avail(&iframe->sbuf)) { - return (ssize_t)(in - first); + return (nghttp2_ssize)(in - first); } nghttp2_frame_unpack_frame_hd(&cont_hd, iframe->sbuf.pos); @@ -6925,7 +6959,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, return rv; } - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } /* CONTINUATION won't bear NGHTTP2_PADDED flag */ @@ -6961,7 +6995,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, iframe->payloadleft, nghttp2_buf_mark_avail(&iframe->sbuf)); if (nghttp2_buf_mark_avail(&iframe->sbuf)) { - return (ssize_t)(in - first); + return (nghttp2_ssize)(in - first); } /* Pad Length field is subject to flow control */ @@ -6971,7 +7005,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } /* Pad Length field is consumed immediately */ @@ -6983,7 +7017,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } stream = nghttp2_session_get_stream(session, iframe->frame.hd.stream_id); @@ -7006,7 +7040,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, if (nghttp2_is_fatal(rv)) { return rv; } - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } iframe->frame.data.padlen = (size_t)padlen; @@ -7033,7 +7067,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, iframe->payloadleft); if (readlen > 0) { - ssize_t data_readlen; + nghttp2_ssize data_readlen; rv = nghttp2_session_update_recv_connection_window_size(session, readlen); @@ -7042,7 +7076,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } rv = nghttp2_session_update_recv_stream_window_size( @@ -7061,7 +7095,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, data_readlen = 0; } - padlen = (ssize_t)readlen - data_readlen; + padlen = (nghttp2_ssize)readlen - data_readlen; if (padlen > 0) { /* Padding is considered as "consumed" immediately */ @@ -7073,11 +7107,11 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } } - DEBUGF("recv: data_readlen=%zd\n", data_readlen); + DEBUGF("recv: data_readlen=%td\n", data_readlen); if (data_readlen > 0) { if (session_enforce_http_messaging(session)) { @@ -7092,7 +7126,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (iframe->state == NGHTTP2_IB_IGN_DATA) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } } @@ -7111,7 +7145,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, session, iframe->frame.hd.flags, iframe->frame.hd.stream_id, in - readlen, (size_t)data_readlen, session->user_data); if (rv == NGHTTP2_ERR_PAUSE) { - return (ssize_t)(in - first); + return (nghttp2_ssize)(in - first); } if (nghttp2_is_fatal(rv)) { @@ -7153,7 +7187,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } if (session->opt_flags & NGHTTP2_OPTMASK_NO_AUTO_WINDOW_UPDATE) { @@ -7166,7 +7200,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } } } @@ -7179,7 +7213,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, break; case NGHTTP2_IB_IGN_ALL: - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; case NGHTTP2_IB_READ_EXTENSION_PAYLOAD: DEBUGF("recv: [IB_READ_EXTENSION_PAYLOAD]\n"); @@ -7274,7 +7308,7 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, } if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (ssize_t)inlen; + return (nghttp2_ssize)inlen; } session_inbound_frame_reset(session); @@ -7291,16 +7325,17 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, assert(in == last); - return (ssize_t)(in - first); + return (nghttp2_ssize)(in - first); } int nghttp2_session_recv(nghttp2_session *session) { uint8_t buf[NGHTTP2_INBOUND_BUFFER_LENGTH]; while (1) { - ssize_t readlen; + nghttp2_ssize readlen; readlen = session_recv(session, buf, sizeof(buf)); if (readlen > 0) { - ssize_t proclen = nghttp2_session_mem_recv(session, buf, (size_t)readlen); + nghttp2_ssize proclen = + nghttp2_session_mem_recv2(session, buf, (size_t)readlen); if (proclen < 0) { return (int)proclen; } @@ -7642,8 +7677,8 @@ int nghttp2_session_pack_data(nghttp2_session *session, nghttp2_bufs *bufs, nghttp2_stream *stream) { int rv; uint32_t data_flags; - ssize_t payloadlen; - ssize_t padded_payloadlen; + nghttp2_ssize payloadlen; + nghttp2_ssize padded_payloadlen; nghttp2_buf *buf; size_t max_payloadlen; @@ -7651,19 +7686,26 @@ int nghttp2_session_pack_data(nghttp2_session *session, nghttp2_bufs *bufs, buf = &bufs->cur->buf; - if (session->callbacks.read_length_callback) { - - payloadlen = session->callbacks.read_length_callback( - session, frame->hd.type, stream->stream_id, session->remote_window_size, - stream->remote_window_size, session->remote_settings.max_frame_size, - session->user_data); + if (session->callbacks.read_length_callback2 || + session->callbacks.read_length_callback) { + if (session->callbacks.read_length_callback2) { + payloadlen = session->callbacks.read_length_callback2( + session, frame->hd.type, stream->stream_id, + session->remote_window_size, stream->remote_window_size, + session->remote_settings.max_frame_size, session->user_data); + } else { + payloadlen = (nghttp2_ssize)session->callbacks.read_length_callback( + session, frame->hd.type, stream->stream_id, + session->remote_window_size, stream->remote_window_size, + session->remote_settings.max_frame_size, session->user_data); + } - DEBUGF("send: read_length_callback=%zd\n", payloadlen); + DEBUGF("send: read_length_callback=%td\n", payloadlen); payloadlen = nghttp2_session_enforce_flow_control_limits(session, stream, payloadlen); - DEBUGF("send: read_length_callback after flow control=%zd\n", payloadlen); + DEBUGF("send: read_length_callback after flow control=%td\n", payloadlen); if (payloadlen <= 0) { return NGHTTP2_ERR_CALLBACK_FAILURE; @@ -7679,9 +7721,9 @@ int nghttp2_session_pack_data(nghttp2_session *session, nghttp2_bufs *bufs, DEBUGF("send: realloc buffer failed rv=%d", rv); /* If reallocation failed, old buffers are still in tact. So use safe limit. */ - payloadlen = (ssize_t)datamax; + payloadlen = (nghttp2_ssize)datamax; - DEBUGF("send: use safe limit payloadlen=%zd", payloadlen); + DEBUGF("send: use safe limit payloadlen=%td", payloadlen); } else { assert(&session->aob.framebufs == bufs); @@ -7695,9 +7737,23 @@ int nghttp2_session_pack_data(nghttp2_session *session, nghttp2_bufs *bufs, assert(nghttp2_buf_avail(buf) >= datamax); data_flags = NGHTTP2_DATA_FLAG_NONE; - payloadlen = aux_data->data_prd.read_callback( - session, frame->hd.stream_id, buf->pos, datamax, &data_flags, - &aux_data->data_prd.source, session->user_data); + switch (aux_data->dpw.version) { + case NGHTTP2_DATA_PROVIDER_V1: + payloadlen = (nghttp2_ssize)aux_data->dpw.data_prd.v1.read_callback( + session, frame->hd.stream_id, buf->pos, datamax, &data_flags, + &aux_data->dpw.data_prd.source, session->user_data); + + break; + case NGHTTP2_DATA_PROVIDER_V2: + payloadlen = aux_data->dpw.data_prd.v2.read_callback( + session, frame->hd.stream_id, buf->pos, datamax, &data_flags, + &aux_data->dpw.data_prd.source, session->user_data); + + break; + default: + assert(0); + abort(); + } if (payloadlen == NGHTTP2_ERR_DEFERRED || payloadlen == NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE || @@ -8275,7 +8331,7 @@ int nghttp2_session_change_stream_priority( /* We don't intentionally call nghttp2_session_adjust_idle_stream() so that idle stream created by this function, and existing ones are kept for application. We will adjust number of idle stream - in nghttp2_session_mem_send or nghttp2_session_mem_recv is + in nghttp2_session_mem_send2 or nghttp2_session_mem_recv2 is called. */ return 0; } @@ -8313,7 +8369,7 @@ int nghttp2_session_create_idle_stream(nghttp2_session *session, /* We don't intentionally call nghttp2_session_adjust_idle_stream() so that idle stream created by this function, and existing ones are kept for application. We will adjust number of idle stream - in nghttp2_session_mem_send or nghttp2_session_mem_recv is + in nghttp2_session_mem_send2 or nghttp2_session_mem_recv2 is called. */ return 0; } diff --git a/lib/nghttp2_submit.c b/lib/nghttp2_submit.c index f5554eb..f947969 100644 --- a/lib/nghttp2_submit.c +++ b/lib/nghttp2_submit.c @@ -68,7 +68,7 @@ static int32_t submit_headers_shared(nghttp2_session *session, uint8_t flags, int32_t stream_id, const nghttp2_priority_spec *pri_spec, nghttp2_nv *nva_copy, size_t nvlen, - const nghttp2_data_provider *data_prd, + const nghttp2_data_provider_wrap *dpw, void *stream_user_data) { int rv; uint8_t flags_copy; @@ -87,8 +87,8 @@ static int32_t submit_headers_shared(nghttp2_session *session, uint8_t flags, nghttp2_outbound_item_init(item); - if (data_prd != NULL && data_prd->read_callback != NULL) { - item->aux_data.headers.data_prd = *data_prd; + if (dpw != NULL && dpw->data_prd.read_callback != NULL) { + item->aux_data.headers.dpw = *dpw; } item->aux_data.headers.stream_user_data = stream_user_data; @@ -143,7 +143,7 @@ static int32_t submit_headers_shared_nva(nghttp2_session *session, uint8_t flags, int32_t stream_id, const nghttp2_priority_spec *pri_spec, const nghttp2_nv *nva, size_t nvlen, - const nghttp2_data_provider *data_prd, + const nghttp2_data_provider_wrap *dpw, void *stream_user_data) { int rv; nghttp2_nv *nva_copy; @@ -165,7 +165,7 @@ static int32_t submit_headers_shared_nva(nghttp2_session *session, } return submit_headers_shared(session, flags, stream_id, ©_pri_spec, - nva_copy, nvlen, data_prd, stream_user_data); + nva_copy, nvlen, dpw, stream_user_data); } int nghttp2_submit_trailer(nghttp2_session *session, int32_t stream_id, @@ -740,9 +740,9 @@ fail_item_malloc: } static uint8_t set_request_flags(const nghttp2_priority_spec *pri_spec, - const nghttp2_data_provider *data_prd) { + const nghttp2_data_provider_wrap *dpw) { uint8_t flags = NGHTTP2_FLAG_NONE; - if (data_prd == NULL || data_prd->read_callback == NULL) { + if (dpw == NULL || dpw->data_prd.read_callback == NULL) { flags |= NGHTTP2_FLAG_END_STREAM; } @@ -753,11 +753,11 @@ static uint8_t set_request_flags(const nghttp2_priority_spec *pri_spec, return flags; } -int32_t nghttp2_submit_request(nghttp2_session *session, - const nghttp2_priority_spec *pri_spec, - const nghttp2_nv *nva, size_t nvlen, - const nghttp2_data_provider *data_prd, - void *stream_user_data) { +static int32_t submit_request_shared(nghttp2_session *session, + const nghttp2_priority_spec *pri_spec, + const nghttp2_nv *nva, size_t nvlen, + const nghttp2_data_provider_wrap *dpw, + void *stream_user_data) { uint8_t flags; int rv; @@ -775,23 +775,47 @@ int32_t nghttp2_submit_request(nghttp2_session *session, pri_spec = NULL; } - flags = set_request_flags(pri_spec, data_prd); + flags = set_request_flags(pri_spec, dpw); return submit_headers_shared_nva(session, flags, -1, pri_spec, nva, nvlen, - data_prd, stream_user_data); + dpw, stream_user_data); +} + +int32_t nghttp2_submit_request(nghttp2_session *session, + const nghttp2_priority_spec *pri_spec, + const nghttp2_nv *nva, size_t nvlen, + const nghttp2_data_provider *data_prd, + void *stream_user_data) { + nghttp2_data_provider_wrap dpw; + + return submit_request_shared(session, pri_spec, nva, nvlen, + nghttp2_data_provider_wrap_v1(&dpw, data_prd), + stream_user_data); +} + +int32_t nghttp2_submit_request2(nghttp2_session *session, + const nghttp2_priority_spec *pri_spec, + const nghttp2_nv *nva, size_t nvlen, + const nghttp2_data_provider2 *data_prd, + void *stream_user_data) { + nghttp2_data_provider_wrap dpw; + + return submit_request_shared(session, pri_spec, nva, nvlen, + nghttp2_data_provider_wrap_v2(&dpw, data_prd), + stream_user_data); } -static uint8_t set_response_flags(const nghttp2_data_provider *data_prd) { +static uint8_t set_response_flags(const nghttp2_data_provider_wrap *dpw) { uint8_t flags = NGHTTP2_FLAG_NONE; - if (data_prd == NULL || data_prd->read_callback == NULL) { + if (dpw == NULL || dpw->data_prd.read_callback == NULL) { flags |= NGHTTP2_FLAG_END_STREAM; } return flags; } -int nghttp2_submit_response(nghttp2_session *session, int32_t stream_id, - const nghttp2_nv *nva, size_t nvlen, - const nghttp2_data_provider *data_prd) { +static int submit_response_shared(nghttp2_session *session, int32_t stream_id, + const nghttp2_nv *nva, size_t nvlen, + const nghttp2_data_provider_wrap *dpw) { uint8_t flags; if (stream_id <= 0) { @@ -802,14 +826,32 @@ int nghttp2_submit_response(nghttp2_session *session, int32_t stream_id, return NGHTTP2_ERR_PROTO; } - flags = set_response_flags(data_prd); + flags = set_response_flags(dpw); return submit_headers_shared_nva(session, flags, stream_id, NULL, nva, nvlen, - data_prd, NULL); + dpw, NULL); } -int nghttp2_submit_data(nghttp2_session *session, uint8_t flags, - int32_t stream_id, - const nghttp2_data_provider *data_prd) { +int nghttp2_submit_response(nghttp2_session *session, int32_t stream_id, + const nghttp2_nv *nva, size_t nvlen, + const nghttp2_data_provider *data_prd) { + nghttp2_data_provider_wrap dpw; + + return submit_response_shared(session, stream_id, nva, nvlen, + nghttp2_data_provider_wrap_v1(&dpw, data_prd)); +} + +int nghttp2_submit_response2(nghttp2_session *session, int32_t stream_id, + const nghttp2_nv *nva, size_t nvlen, + const nghttp2_data_provider2 *data_prd) { + nghttp2_data_provider_wrap dpw; + + return submit_response_shared(session, stream_id, nva, nvlen, + nghttp2_data_provider_wrap_v2(&dpw, data_prd)); +} + +int nghttp2_submit_data_shared(nghttp2_session *session, uint8_t flags, + int32_t stream_id, + const nghttp2_data_provider_wrap *dpw) { int rv; nghttp2_outbound_item *item; nghttp2_frame *frame; @@ -832,7 +874,7 @@ int nghttp2_submit_data(nghttp2_session *session, uint8_t flags, frame = &item->frame; aux_data = &item->aux_data.data; - aux_data->data_prd = *data_prd; + aux_data->dpw = *dpw; aux_data->eof = 0; aux_data->flags = nflags; @@ -848,9 +890,37 @@ int nghttp2_submit_data(nghttp2_session *session, uint8_t flags, return 0; } +int nghttp2_submit_data(nghttp2_session *session, uint8_t flags, + int32_t stream_id, + const nghttp2_data_provider *data_prd) { + nghttp2_data_provider_wrap dpw; + + assert(data_prd); + + return nghttp2_submit_data_shared( + session, flags, stream_id, nghttp2_data_provider_wrap_v1(&dpw, data_prd)); +} + +int nghttp2_submit_data2(nghttp2_session *session, uint8_t flags, + int32_t stream_id, + const nghttp2_data_provider2 *data_prd) { + nghttp2_data_provider_wrap dpw; + + assert(data_prd); + + return nghttp2_submit_data_shared( + session, flags, stream_id, nghttp2_data_provider_wrap_v2(&dpw, data_prd)); +} + ssize_t nghttp2_pack_settings_payload(uint8_t *buf, size_t buflen, const nghttp2_settings_entry *iv, size_t niv) { + return (ssize_t)nghttp2_pack_settings_payload2(buf, buflen, iv, niv); +} + +nghttp2_ssize nghttp2_pack_settings_payload2(uint8_t *buf, size_t buflen, + const nghttp2_settings_entry *iv, + size_t niv) { if (!nghttp2_iv_check(iv, niv)) { return NGHTTP2_ERR_INVALID_ARGUMENT; } @@ -859,7 +929,7 @@ ssize_t nghttp2_pack_settings_payload(uint8_t *buf, size_t buflen, return NGHTTP2_ERR_INSUFF_BUFSIZE; } - return (ssize_t)nghttp2_frame_pack_settings_payload(buf, iv, niv); + return (nghttp2_ssize)nghttp2_frame_pack_settings_payload(buf, iv, niv); } int nghttp2_submit_extension(nghttp2_session *session, uint8_t type, @@ -875,7 +945,8 @@ int nghttp2_submit_extension(nghttp2_session *session, uint8_t type, return NGHTTP2_ERR_INVALID_ARGUMENT; } - if (!session->callbacks.pack_extension_callback) { + if (!session->callbacks.pack_extension_callback2 && + !session->callbacks.pack_extension_callback) { return NGHTTP2_ERR_INVALID_STATE; } diff --git a/lib/nghttp2_submit.h b/lib/nghttp2_submit.h index 74d702f..96781d2 100644 --- a/lib/nghttp2_submit.h +++ b/lib/nghttp2_submit.h @@ -31,4 +31,10 @@ #include <nghttp2/nghttp2.h> +typedef struct nghttp2_data_provider_wrap nghttp2_data_provider_wrap; + +int nghttp2_submit_data_shared(nghttp2_session *session, uint8_t flags, + int32_t stream_id, + const nghttp2_data_provider_wrap *dpw); + #endif /* NGHTTP2_SUBMIT_H */ diff --git a/makerelease.sh b/makerelease.sh index b65e08f..34963dc 100755 --- a/makerelease.sh +++ b/makerelease.sh @@ -6,7 +6,7 @@ PREV_TAG=$2 git checkout refs/tags/$TAG git log --pretty=fuller --date=short refs/tags/$PREV_TAG..HEAD > ChangeLog -git submodule update --init +git submodule update --init --depth 1 autoreconf -i ./configure --with-mruby && \ diff --git a/script/fetch-ocsp-response b/script/fetch-ocsp-response index 7c4785b..f9c2100 100755 --- a/script/fetch-ocsp-response +++ b/script/fetch-ocsp-response @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # nghttp2 - HTTP/2 C Library diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 201c5a2..6583324 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,6 +21,8 @@ include_directories( ${JANSSON_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS} ${LIBBPF_INCLUDE_DIRS} + ${LIBBROTLIENC_INCLUDE_DIRS} + ${LIBBROTLIDEC_INCLUDE_DIRS} ) # XXX per-target? @@ -38,6 +40,8 @@ link_libraries( ${ZLIB_LIBRARIES} ${APP_LIBRARIES} ${LIBBPF_LIBRARIES} + ${LIBBROTLIENC_LIBRARIES} + ${LIBBROTLIDEC_LIBRARIES} ) if(ENABLE_APP) @@ -163,45 +167,45 @@ if(ENABLE_APP) target_link_libraries(nghttpx_static neverbleed) endif() - - if(HAVE_CUNIT) - set(NGHTTPX_UNITTEST_SOURCES - shrpx-unittest.cc - shrpx_tls_test.cc - shrpx_downstream_test.cc - shrpx_config_test.cc - shrpx_worker_test.cc - shrpx_http_test.cc - shrpx_router_test.cc - http2_test.cc - util_test.cc - nghttp2_gzip_test.c - nghttp2_gzip.c - buffer_test.cc - memchunk_test.cc - template_test.cc - base64_test.cc - ) - add_executable(nghttpx-unittest EXCLUDE_FROM_ALL - ${NGHTTPX_UNITTEST_SOURCES} - $<TARGET_OBJECTS:llhttp> - $<TARGET_OBJECTS:url-parser> - ) - target_include_directories(nghttpx-unittest PRIVATE ${CUNIT_INCLUDE_DIRS}) - target_compile_definitions(nghttpx-unittest - PRIVATE "-DNGHTTP2_SRC_DIR=\"${CMAKE_SOURCE_DIR}/src\"" + set(NGHTTPX_UNITTEST_SOURCES + shrpx-unittest.cc + shrpx_tls_test.cc + shrpx_downstream_test.cc + shrpx_config_test.cc + shrpx_worker_test.cc + shrpx_http_test.cc + shrpx_router_test.cc + http2_test.cc + util_test.cc + nghttp2_gzip_test.c + nghttp2_gzip.c + buffer_test.cc + memchunk_test.cc + template_test.cc + base64_test.cc + ${CMAKE_SOURCE_DIR}/tests/munit/munit.c + ) + add_executable(nghttpx-unittest EXCLUDE_FROM_ALL + ${NGHTTPX_UNITTEST_SOURCES} + $<TARGET_OBJECTS:llhttp> + $<TARGET_OBJECTS:url-parser> ) - target_link_libraries(nghttpx-unittest nghttpx_static ${CUNIT_LIBRARIES}) - if(HAVE_MRUBY) - target_link_libraries(nghttpx-unittest mruby-lib) - endif() - if(HAVE_NEVERBLEED) - target_link_libraries(nghttpx-unittest neverbleed) - endif() - - add_test(nghttpx-unittest nghttpx-unittest) - add_dependencies(check nghttpx-unittest) + target_include_directories(nghttpx-unittest PRIVATE + ${CMAKE_SOURCE_DIR}/tests/munit + ) + target_compile_definitions(nghttpx-unittest + PRIVATE "-DNGHTTP2_SRC_DIR=\"${CMAKE_SOURCE_DIR}/src\"" + ) + target_link_libraries(nghttpx-unittest nghttpx_static) + if(HAVE_MRUBY) + target_link_libraries(nghttpx-unittest mruby-lib) endif() + if(HAVE_NEVERBLEED) + target_link_libraries(nghttpx-unittest neverbleed) + endif() + + add_test(nghttpx-unittest nghttpx-unittest) + add_dependencies(check nghttpx-unittest) add_executable(nghttp ${NGHTTP_SOURCES} $<TARGET_OBJECTS:llhttp> $<TARGET_OBJECTS:url-parser> @@ -221,8 +225,7 @@ if(ENABLE_APP) $<TARGET_OBJECTS:url-parser> ) - install(TARGETS nghttp nghttpd nghttpx h2load - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + install(TARGETS nghttp nghttpd nghttpx h2load) endif() if(ENABLE_HPACK_TOOLS) @@ -238,6 +241,5 @@ if(ENABLE_HPACK_TOOLS) ) add_executable(inflatehd ${inflatehd_SOURCES}) add_executable(deflatehd ${deflatehd_SOURCES}) - install(TARGETS inflatehd deflatehd - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + install(TARGETS inflatehd deflatehd) endif() diff --git a/src/HttpServer.cc b/src/HttpServer.cc index 0385cd0..b59cecd 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -607,10 +607,10 @@ int Http2Handler::fill_wb() { for (;;) { const uint8_t *data; - auto datalen = nghttp2_session_mem_send(session_, &data); + auto datalen = nghttp2_session_mem_send2(session_, &data); if (datalen < 0) { - std::cerr << "nghttp2_session_mem_send() returned error: " + std::cerr << "nghttp2_session_mem_send2() returned error: " << nghttp2_strerror(datalen) << std::endl; return -1; } @@ -648,10 +648,10 @@ int Http2Handler::read_clear() { util::hexdump(stdout, buf.data(), nread); } - rv = nghttp2_session_mem_recv(session_, buf.data(), nread); + rv = nghttp2_session_mem_recv2(session_, buf.data(), nread); if (rv < 0) { if (rv != NGHTTP2_ERR_BAD_CLIENT_MAGIC) { - std::cerr << "nghttp2_session_mem_recv() returned error: " + std::cerr << "nghttp2_session_mem_recv2() returned error: " << nghttp2_strerror(rv) << std::endl; } return -1; @@ -771,10 +771,10 @@ int Http2Handler::read_tls() { util::hexdump(stdout, buf.data(), nread); } - rv = nghttp2_session_mem_recv(session_, buf.data(), nread); + rv = nghttp2_session_mem_recv2(session_, buf.data(), nread); if (rv < 0) { if (rv != NGHTTP2_ERR_BAD_CLIENT_MAGIC) { - std::cerr << "nghttp2_session_mem_recv() returned error: " + std::cerr << "nghttp2_session_mem_recv2() returned error: " << nghttp2_strerror(rv) << std::endl; } return -1; @@ -917,7 +917,7 @@ int Http2Handler::verify_alpn_result() { int Http2Handler::submit_file_response(const StringRef &status, Stream *stream, time_t last_modified, off_t file_length, const std::string *content_type, - nghttp2_data_provider *data_prd) { + nghttp2_data_provider2 *data_prd) { std::string last_modified_str; auto nva = make_array(http2::make_nv_ls_nocopy(":status", status), http2::make_nv_ls_nocopy("server", NGHTTPD_SERVER), @@ -942,13 +942,13 @@ int Http2Handler::submit_file_response(const StringRef &status, Stream *stream, if (!trailer_names.empty()) { nva[nvlen++] = http2::make_nv_ls_nocopy("trailer", trailer_names); } - return nghttp2_submit_response(session_, stream->stream_id, nva.data(), nvlen, - data_prd); + return nghttp2_submit_response2(session_, stream->stream_id, nva.data(), + nvlen, data_prd); } int Http2Handler::submit_response(const StringRef &status, int32_t stream_id, const HeaderRefs &headers, - nghttp2_data_provider *data_prd) { + nghttp2_data_provider2 *data_prd) { auto nva = std::vector<nghttp2_nv>(); nva.reserve(4 + headers.size()); nva.push_back(http2::make_nv_ls_nocopy(":status", status)); @@ -965,13 +965,13 @@ int Http2Handler::submit_response(const StringRef &status, int32_t stream_id, for (auto &nv : headers) { nva.push_back(http2::make_nv_nocopy(nv.name, nv.value, nv.no_index)); } - int r = nghttp2_submit_response(session_, stream_id, nva.data(), nva.size(), - data_prd); + int r = nghttp2_submit_response2(session_, stream_id, nva.data(), nva.size(), + data_prd); return r; } int Http2Handler::submit_response(const StringRef &status, int32_t stream_id, - nghttp2_data_provider *data_prd) { + nghttp2_data_provider2 *data_prd) { auto nva = make_array(http2::make_nv_ls_nocopy(":status", status), http2::make_nv_ls_nocopy("server", NGHTTPD_SERVER), http2::make_nv_ls("date", sessions_->get_cached_date()), @@ -985,8 +985,8 @@ int Http2Handler::submit_response(const StringRef &status, int32_t stream_id, } } - return nghttp2_submit_response(session_, stream_id, nva.data(), nvlen, - data_prd); + return nghttp2_submit_response2(session_, stream_id, nva.data(), nvlen, + data_prd); } int Http2Handler::submit_non_final_response(const std::string &status, @@ -1076,9 +1076,10 @@ void Http2Handler::terminate_session(uint32_t error_code) { nghttp2_session_terminate_session(session_, error_code); } -ssize_t file_read_callback(nghttp2_session *session, int32_t stream_id, - uint8_t *buf, size_t length, uint32_t *data_flags, - nghttp2_data_source *source, void *user_data) { +nghttp2_ssize file_read_callback(nghttp2_session *session, int32_t stream_id, + uint8_t *buf, size_t length, + uint32_t *data_flags, + nghttp2_data_source *source, void *user_data) { int rv; auto hd = static_cast<Http2Handler *>(user_data); auto stream = hd->get_stream(stream_id); @@ -1127,7 +1128,7 @@ void prepare_status_response(Stream *stream, Http2Handler *hd, int status) { // we don't set stream->file_ent since we don't want to expire it. stream->body_length = file_ent->length; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; data_prd.source.fd = file_ent->fd; data_prd.read_callback = file_read_callback; @@ -1155,7 +1156,7 @@ void prepare_echo_response(Stream *stream, Http2Handler *hd) { hd->submit_rst_stream(stream, NGHTTP2_INTERNAL_ERROR); return; } - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; data_prd.source.fd = stream->file_ent->fd; data_prd.read_callback = file_read_callback; @@ -1378,7 +1379,7 @@ void prepare_response(Stream *stream, Http2Handler *hd, stream->body_length = file_ent->length; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; data_prd.source.fd = file_ent->fd; data_prd.read_callback = file_read_callback; @@ -1676,9 +1677,9 @@ int send_data_callback(nghttp2_session *session, nghttp2_frame *frame, } // namespace namespace { -ssize_t select_padding_callback(nghttp2_session *session, - const nghttp2_frame *frame, size_t max_payload, - void *user_data) { +nghttp2_ssize select_padding_callback(nghttp2_session *session, + const nghttp2_frame *frame, + size_t max_payload, void *user_data) { auto hd = static_cast<Http2Handler *>(user_data); return std::min(max_payload, frame->hd.length + hd->get_config()->padding); } @@ -1765,7 +1766,7 @@ void fill_callback(nghttp2_session_callbacks *callbacks, const Config *config) { send_data_callback); if (config->padding) { - nghttp2_session_callbacks_set_select_padding_callback( + nghttp2_session_callbacks_set_select_padding_callback2( callbacks, select_padding_callback); } } @@ -2205,6 +2206,15 @@ int HttpServer::run() { // ALPN selection callback SSL_CTX_set_alpn_select_cb(ssl_ctx, alpn_select_proto_cb, this); + +#if defined(NGHTTP2_OPENSSL_IS_BORINGSSL) && defined(HAVE_LIBBROTLI) + if (!SSL_CTX_add_cert_compression_alg( + ssl_ctx, nghttp2::tls::CERTIFICATE_COMPRESSION_ALGO_BROTLI, + nghttp2::tls::cert_compress, nghttp2::tls::cert_decompress)) { + std::cerr << "SSL_CTX_add_cert_compression_alg failed." << std::endl; + return -1; + } +#endif // NGHTTP2_OPENSSL_IS_BORINGSSL && HAVE_LIBBROTLI } auto loop = EV_DEFAULT; diff --git a/src/HttpServer.h b/src/HttpServer.h index 949bd1f..00fd6bf 100644 --- a/src/HttpServer.h +++ b/src/HttpServer.h @@ -41,6 +41,7 @@ #include <ev.h> +#define NGHTTP2_NO_SSIZE_T #include <nghttp2/nghttp2.h> #include "http2.h" @@ -172,14 +173,14 @@ public: int submit_file_response(const StringRef &status, Stream *stream, time_t last_modified, off_t file_length, const std::string *content_type, - nghttp2_data_provider *data_prd); + nghttp2_data_provider2 *data_prd); int submit_response(const StringRef &status, int32_t stream_id, - nghttp2_data_provider *data_prd); + nghttp2_data_provider2 *data_prd); int submit_response(const StringRef &status, int32_t stream_id, const HeaderRefs &headers, - nghttp2_data_provider *data_prd); + nghttp2_data_provider2 *data_prd); int submit_non_final_response(const std::string &status, int32_t stream_id); diff --git a/src/Makefile.am b/src/Makefile.am index f112ac2..5e90018 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -53,6 +53,8 @@ AM_CPPFLAGS = \ @JANSSON_CFLAGS@ \ @LIBBPF_CFLAGS@ \ @ZLIB_CFLAGS@ \ + @LIBBROTLIENC_CFLAGS@ \ + @LIBBROTLIDEC_CFLAGS@ \ @EXTRA_DEFS@ \ @DEFS@ AM_LDFLAGS = @LIBTOOL_LDFLAGS@ @@ -73,6 +75,8 @@ LDADD = $(top_builddir)/lib/libnghttp2.la \ @JANSSON_LIBS@ \ @LIBBPF_LIBS@ \ @ZLIB_LIBS@ \ + @LIBBROTLIENC_LIBS@ \ + @LIBBROTLIDEC_LIBS@ \ @APPLDFLAGS@ if ENABLE_APP @@ -203,7 +207,6 @@ libnghttpx_a_CPPFLAGS += -I${top_srcdir}/third-party/neverbleed nghttpx_LDADD += ${top_builddir}/third-party/libneverbleed.la endif # HAVE_NEVERBLEED -if HAVE_CUNIT check_PROGRAMS += nghttpx-unittest nghttpx_unittest_SOURCES = shrpx-unittest.cc \ shrpx_tls_test.cc shrpx_tls_test.h \ @@ -219,10 +222,13 @@ nghttpx_unittest_SOURCES = shrpx-unittest.cc \ buffer_test.cc buffer_test.h \ memchunk_test.cc memchunk_test.h \ template_test.cc template_test.h \ - base64_test.cc base64_test.h + base64_test.cc base64_test.h \ + $(top_srcdir)/tests/munit/munit.c $(top_srcdir)/tests/munit/munit.h \ + $(top_srcdir)/tests/munit/munitxx.h nghttpx_unittest_CPPFLAGS = ${AM_CPPFLAGS} \ + -I$(top_srcdir)/tests/munit \ -DNGHTTP2_SRC_DIR=\"$(top_srcdir)/src\" -nghttpx_unittest_LDADD = libnghttpx.a ${LDADD} @CUNIT_LIBS@ @TESTLDADD@ +nghttpx_unittest_LDADD = libnghttpx.a ${LDADD} @TESTLDADD@ if HAVE_MRUBY nghttpx_unittest_CPPFLAGS += \ @@ -237,7 +243,6 @@ nghttpx_unittest_LDADD += ${top_builddir}/third-party/libneverbleed.la endif # HAVE_NEVERBLEED TESTS += nghttpx-unittest -endif # HAVE_CUNIT endif # ENABLE_APP diff --git a/src/allocator.h b/src/allocator.h index 97b9a41..363ee91 100644 --- a/src/allocator.h +++ b/src/allocator.h @@ -119,7 +119,7 @@ struct BlockAllocator { } if (!head || - head->end - head->last < static_cast<ssize_t>(size + sizeof(size_t))) { + static_cast<size_t>(head->end - head->last) < size + sizeof(size_t)) { head = alloc_mem_block(block_size); } diff --git a/src/app_helper.cc b/src/app_helper.cc index ef92762..666d16c 100644 --- a/src/app_helper.cc +++ b/src/app_helper.cc @@ -53,8 +53,6 @@ #include <iomanip> #include <fstream> -#include <zlib.h> - #include "app_helper.h" #include "util.h" #include "http2.h" @@ -477,42 +475,4 @@ std::chrono::steady_clock::time_point get_time() { return std::chrono::steady_clock::now(); } -ssize_t deflate_data(uint8_t *out, size_t outlen, const uint8_t *in, - size_t inlen) { - int rv; - z_stream zst{}; - uint8_t temp_out[8_k]; - auto temp_outlen = sizeof(temp_out); - - rv = deflateInit2(&zst, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 31, 9, - Z_DEFAULT_STRATEGY); - - if (rv != Z_OK) { - return -1; - } - - zst.avail_in = inlen; - zst.next_in = (uint8_t *)in; - zst.avail_out = temp_outlen; - zst.next_out = temp_out; - - rv = deflate(&zst, Z_FINISH); - - deflateEnd(&zst); - - if (rv != Z_STREAM_END) { - return -1; - } - - temp_outlen -= zst.avail_out; - - if (temp_outlen > outlen) { - return -1; - } - - memcpy(out, temp_out, temp_outlen); - - return temp_outlen; -} - } // namespace nghttp2 diff --git a/src/app_helper.h b/src/app_helper.h index 5424054..a7ef7cc 100644 --- a/src/app_helper.h +++ b/src/app_helper.h @@ -90,9 +90,6 @@ void set_color_output(bool f); // used. void set_output(FILE *file); -ssize_t deflate_data(uint8_t *out, size_t outlen, const uint8_t *in, - size_t inlen); - } // namespace nghttp2 #endif // APP_HELPER_H diff --git a/src/base64_test.cc b/src/base64_test.cc index 4324bd7..9ab770f 100644 --- a/src/base64_test.cc +++ b/src/base64_test.cc @@ -27,7 +27,7 @@ #include <cstring> #include <iostream> -#include <CUnit/CUnit.h> +#include "munitxx.h" #include <nghttp2/nghttp2.h> @@ -35,26 +35,38 @@ namespace nghttp2 { +namespace { +const MunitTest tests[]{ + munit_void_test(test_base64_encode), + munit_void_test(test_base64_decode), + munit_test_end(), +}; +} // namespace + +const MunitSuite base64_suite{ + "/base64", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_base64_encode(void) { { std::string in = "\xff"; auto out = base64::encode(std::begin(in), std::end(in)); - CU_ASSERT("/w==" == out); + assert_stdstring_equal("/w==", out); } { std::string in = "\xff\xfe"; auto out = base64::encode(std::begin(in), std::end(in)); - CU_ASSERT("//4=" == out); + assert_stdstring_equal("//4=", out); } { std::string in = "\xff\xfe\xfd"; auto out = base64::encode(std::begin(in), std::end(in)); - CU_ASSERT("//79" == out); + assert_stdstring_equal("//79", out); } { std::string in = "\xff\xfe\xfd\xfc"; auto out = base64::encode(std::begin(in), std::end(in)); - CU_ASSERT("//79/A==" == out); + assert_stdstring_equal("//79/A==", out); } } @@ -63,58 +75,65 @@ void test_base64_decode(void) { { std::string in = "/w=="; auto out = base64::decode(std::begin(in), std::end(in)); - CU_ASSERT("\xff" == out); - CU_ASSERT("\xff" == base64::decode(balloc, std::begin(in), std::end(in))); + assert_stdstring_equal("\xff", out); + assert_stdstring_equal( + "\xff", base64::decode(balloc, std::begin(in), std::end(in)).str()); } { std::string in = "//4="; auto out = base64::decode(std::begin(in), std::end(in)); - CU_ASSERT("\xff\xfe" == out); - CU_ASSERT("\xff\xfe" == - base64::decode(balloc, std::begin(in), std::end(in))); + assert_stdstring_equal("\xff\xfe", out); + assert_stdstring_equal( + "\xff\xfe", base64::decode(balloc, std::begin(in), std::end(in)).str()); } { std::string in = "//79"; auto out = base64::decode(std::begin(in), std::end(in)); - CU_ASSERT("\xff\xfe\xfd" == out); - CU_ASSERT("\xff\xfe\xfd" == - base64::decode(balloc, std::begin(in), std::end(in))); + assert_stdstring_equal("\xff\xfe\xfd", out); + assert_stdstring_equal( + "\xff\xfe\xfd", + base64::decode(balloc, std::begin(in), std::end(in)).str()); } { std::string in = "//79/A=="; auto out = base64::decode(std::begin(in), std::end(in)); - CU_ASSERT("\xff\xfe\xfd\xfc" == out); - CU_ASSERT("\xff\xfe\xfd\xfc" == - base64::decode(balloc, std::begin(in), std::end(in))); + assert_stdstring_equal("\xff\xfe\xfd\xfc", out); + assert_stdstring_equal( + "\xff\xfe\xfd\xfc", + base64::decode(balloc, std::begin(in), std::end(in)).str()); } { // we check the number of valid input must be multiples of 4 std::string in = "//79="; auto out = base64::decode(std::begin(in), std::end(in)); - CU_ASSERT("" == out); - CU_ASSERT("" == base64::decode(balloc, std::begin(in), std::end(in))); + assert_stdstring_equal("", out); + assert_stdstring_equal( + "", base64::decode(balloc, std::begin(in), std::end(in)).str()); } { // ending invalid character at the boundary of multiples of 4 is // bad std::string in = "bmdodHRw\n"; auto out = base64::decode(std::begin(in), std::end(in)); - CU_ASSERT("" == out); - CU_ASSERT("" == base64::decode(balloc, std::begin(in), std::end(in))); + assert_stdstring_equal("", out); + assert_stdstring_equal( + "", base64::decode(balloc, std::begin(in), std::end(in)).str()); } { // after seeing '=', subsequent input must be also '='. std::string in = "//79/A=A"; auto out = base64::decode(std::begin(in), std::end(in)); - CU_ASSERT("" == out); - CU_ASSERT("" == base64::decode(balloc, std::begin(in), std::end(in))); + assert_stdstring_equal("", out); + assert_stdstring_equal( + "", base64::decode(balloc, std::begin(in), std::end(in)).str()); } { // additional '=' at the end is bad std::string in = "//79/A======"; auto out = base64::decode(std::begin(in), std::end(in)); - CU_ASSERT("" == out); - CU_ASSERT("" == base64::decode(balloc, std::begin(in), std::end(in))); + assert_stdstring_equal("", out); + assert_stdstring_equal( + "", base64::decode(balloc, std::begin(in), std::end(in)).str()); } } diff --git a/src/base64_test.h b/src/base64_test.h index 8bdb84f..fd74f27 100644 --- a/src/base64_test.h +++ b/src/base64_test.h @@ -29,10 +29,16 @@ # include <config.h> #endif // HAVE_CONFIG_H +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + namespace nghttp2 { -void test_base64_encode(void); -void test_base64_decode(void); +extern const MunitSuite base64_suite; + +munit_void_test_decl(test_base64_encode); +munit_void_test_decl(test_base64_decode); } // namespace nghttp2 diff --git a/src/buffer_test.cc b/src/buffer_test.cc index 38688ed..2079086 100644 --- a/src/buffer_test.cc +++ b/src/buffer_test.cc @@ -28,7 +28,7 @@ #include <iostream> #include <tuple> -#include <CUnit/CUnit.h> +#include "munitxx.h" #include <nghttp2/nghttp2.h> @@ -36,43 +36,54 @@ namespace nghttp2 { +namespace { +const MunitTest tests[]{ + munit_void_test(test_buffer_write), + munit_test_end(), +}; +} // namespace + +const MunitSuite buffer_suite{ + "/buffer", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_buffer_write(void) { Buffer<16> b; - CU_ASSERT(0 == b.rleft()); - CU_ASSERT(16 == b.wleft()); + assert_size(0, ==, b.rleft()); + assert_size(16, ==, b.wleft()); b.write("012", 3); - CU_ASSERT(3 == b.rleft()); - CU_ASSERT(13 == b.wleft()); - CU_ASSERT(b.pos == std::begin(b.buf)); + assert_size(3, ==, b.rleft()); + assert_size(13, ==, b.wleft()); + assert_ptr_equal(b.pos, std::begin(b.buf)); b.drain(3); - CU_ASSERT(0 == b.rleft()); - CU_ASSERT(13 == b.wleft()); - CU_ASSERT(3 == b.pos - std::begin(b.buf)); + assert_size(0, ==, b.rleft()); + assert_size(13, ==, b.wleft()); + assert_ptrdiff(3, ==, b.pos - std::begin(b.buf)); auto n = b.write("0123456789ABCDEF", 16); - CU_ASSERT(n == 13); + assert_ssize(13, ==, n); - CU_ASSERT(13 == b.rleft()); - CU_ASSERT(0 == b.wleft()); - CU_ASSERT(3 == b.pos - std::begin(b.buf)); - CU_ASSERT(0 == memcmp(b.pos, "0123456789ABC", 13)); + assert_size(13, ==, b.rleft()); + assert_size(0, ==, b.wleft()); + assert_ptrdiff(3, ==, b.pos - std::begin(b.buf)); + assert_memory_equal(13, b.pos, "0123456789ABC"); b.reset(); - CU_ASSERT(0 == b.rleft()); - CU_ASSERT(16 == b.wleft()); - CU_ASSERT(b.pos == std::begin(b.buf)); + assert_size(0, ==, b.rleft()); + assert_size(16, ==, b.wleft()); + assert_ptr_equal(b.pos, std::begin(b.buf)); b.write(5); - CU_ASSERT(5 == b.rleft()); - CU_ASSERT(11 == b.wleft()); - CU_ASSERT(b.pos == std::begin(b.buf)); + assert_size(5, ==, b.rleft()); + assert_size(11, ==, b.wleft()); + assert_ptr_equal(b.pos, std::begin(b.buf)); } } // namespace nghttp2 diff --git a/src/buffer_test.h b/src/buffer_test.h index 6789aa3..4fb004f 100644 --- a/src/buffer_test.h +++ b/src/buffer_test.h @@ -29,9 +29,15 @@ # include <config.h> #endif // HAVE_CONFIG_H +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + namespace nghttp2 { -void test_buffer_write(void); +extern const MunitSuite buffer_suite; + +munit_void_test_decl(test_buffer_write); } // namespace nghttp2 diff --git a/src/deflatehd.cc b/src/deflatehd.cc index 7dcfccf..ad472de 100644 --- a/src/deflatehd.cc +++ b/src/deflatehd.cc @@ -41,6 +41,7 @@ #include <jansson.h> +#define NGHTTP2_NO_SSIZE_T #include <nghttp2/nghttp2.h> #include "template.h" @@ -113,11 +114,10 @@ static void output_to_json(nghttp2_hd_deflater *deflater, const uint8_t *buf, static void deflate_hd(nghttp2_hd_deflater *deflater, const std::vector<nghttp2_nv> &nva, size_t inputlen, int seq) { - ssize_t rv; std::array<uint8_t, 64_k> buf; - rv = nghttp2_hd_deflate_hd(deflater, buf.data(), buf.size(), - (nghttp2_nv *)nva.data(), nva.size()); + auto rv = nghttp2_hd_deflate_hd2(deflater, buf.data(), buf.size(), + (nghttp2_nv *)nva.data(), nva.size()); if (rv < 0) { fprintf(stderr, "deflate failed with error code %zd at %d\n", rv, seq); exit(EXIT_FAILURE); diff --git a/src/h2load.cc b/src/h2load.cc index 0f07610..8136a9f 100644 --- a/src/h2load.cc +++ b/src/h2load.cc @@ -410,7 +410,7 @@ namespace { void client_request_timeout_cb(struct ev_loop *loop, ev_timer *w, int revents) { auto client = static_cast<Client *>(w->data); - if (client->streams.size() >= (size_t)config.max_concurrent_streams) { + if (client->streams.size() >= config.max_concurrent_streams) { ev_timer_stop(client->worker->loop, w); return; } @@ -582,8 +582,12 @@ int Client::make_socket(addrinfo *addr) { } } - if (ssl && !util::numeric_host(config.host.c_str())) { - SSL_set_tlsext_host_name(ssl, config.host.c_str()); + if (ssl) { + if (!config.sni.empty()) { + SSL_set_tlsext_host_name(ssl, config.sni.c_str()); + } else if (!util::numeric_host(config.host.c_str())) { + SSL_set_tlsext_host_name(ssl, config.host.c_str()); + } } if (config.is_quic()) { @@ -2301,6 +2305,9 @@ Options: --max-udp-payload-size=<SIZE> Specify the maximum outgoing UDP datagram payload size. --ktls Enable ktls. + --sni=<DNSNAME> + Send <DNSNAME> in TLS SNI, overriding the host name + specified in URI. -v, --verbose Output debug information. --version Display version information and exit. @@ -2363,6 +2370,7 @@ int main(int argc, char **argv) { {"max-udp-payload-size", required_argument, &flag, 17}, {"ktls", no_argument, &flag, 18}, {"alpn-list", required_argument, &flag, 19}, + {"sni", required_argument, &flag, 20}, {nullptr, 0, nullptr, 0}}; int option_index = 0; auto c = getopt_long(argc, argv, @@ -2699,6 +2707,10 @@ int main(int argc, char **argv) { // alpn-list option config.alpn_list = util::parse_config_str_list(StringRef{optarg}); break; + case 20: + // --sni + config.sni = optarg; + break; } break; default: @@ -2973,6 +2985,15 @@ int main(int argc, char **argv) { } } +#if defined(NGHTTP2_OPENSSL_IS_BORINGSSL) && defined(HAVE_LIBBROTLI) + if (!SSL_CTX_add_cert_compression_alg( + ssl_ctx, nghttp2::tls::CERTIFICATE_COMPRESSION_ALGO_BROTLI, + nghttp2::tls::cert_compress, nghttp2::tls::cert_decompress)) { + std::cerr << "SSL_CTX_add_cert_compression_alg failed" << std::endl; + exit(EXIT_FAILURE); + } +#endif // NGHTTP2_OPENSSL_IS_BORINGSSL && HAVE_LIBBROTLI + std::string user_agent = "h2load nghttp2/" NGHTTP2_VERSION; Headers shared_nva; shared_nva.emplace_back(":scheme", config.scheme); @@ -3079,18 +3100,18 @@ int main(int argc, char **argv) { #ifndef NOTHREADS size_t nreqs_per_thread = 0; - ssize_t nreqs_rem = 0; + size_t nreqs_rem = 0; if (!config.timing_script) { nreqs_per_thread = config.nreqs / config.nthreads; nreqs_rem = config.nreqs % config.nthreads; } - size_t nclients_per_thread = config.nclients / config.nthreads; - ssize_t nclients_rem = config.nclients % config.nthreads; + auto nclients_per_thread = config.nclients / config.nthreads; + auto nclients_rem = config.nclients % config.nthreads; - size_t rate_per_thread = config.rate / config.nthreads; - ssize_t rate_per_thread_rem = config.rate % config.nthreads; + auto rate_per_thread = config.rate / config.nthreads; + auto rate_per_thread_rem = config.rate % config.nthreads; size_t max_samples_per_thread = std::max(static_cast<size_t>(256), MAX_SAMPLES / config.nthreads); diff --git a/src/h2load.h b/src/h2load.h index 11bb54c..860bf77 100644 --- a/src/h2load.h +++ b/src/h2load.h @@ -43,6 +43,7 @@ #include <chrono> #include <array> +#define NGHTTP2_NO_SSIZE_T #include <nghttp2/nghttp2.h> #ifdef ENABLE_HTTP3 @@ -92,7 +93,7 @@ struct Config { size_t nclients; size_t nthreads; // The maximum number of concurrent streams per session. - ssize_t max_concurrent_streams; + size_t max_concurrent_streams; size_t window_bits; size_t connection_window_bits; size_t max_frame_size; @@ -138,6 +139,9 @@ struct Config { size_t max_udp_payload_size; // Enable ktls. bool ktls; + // sni is the value sent in TLS SNI, overriding DNS name of the + // remote host. + std::string sni; Config(); ~Config(); diff --git a/src/h2load_http2_session.cc b/src/h2load_http2_session.cc index b058a33..6e810ab 100644 --- a/src/h2load_http2_session.cc +++ b/src/h2load_http2_session.cc @@ -124,9 +124,10 @@ int before_frame_send_callback(nghttp2_session *session, } // namespace namespace { -ssize_t file_read_callback(nghttp2_session *session, int32_t stream_id, - uint8_t *buf, size_t length, uint32_t *data_flags, - nghttp2_data_source *source, void *user_data) { +nghttp2_ssize file_read_callback(nghttp2_session *session, int32_t stream_id, + uint8_t *buf, size_t length, + uint32_t *data_flags, + nghttp2_data_source *source, void *user_data) { auto client = static_cast<Client *>(user_data); auto config = client->worker->config; auto req_stat = client->get_req_stat(stream_id); @@ -158,8 +159,8 @@ ssize_t file_read_callback(nghttp2_session *session, int32_t stream_id, } // namespace namespace { -ssize_t send_callback(nghttp2_session *session, const uint8_t *data, - size_t length, int flags, void *user_data) { +nghttp2_ssize send_callback(nghttp2_session *session, const uint8_t *data, + size_t length, int flags, void *user_data) { auto client = static_cast<Client *>(user_data); auto &wb = client->wb; @@ -198,7 +199,7 @@ void Http2Session::on_connect() { nghttp2_session_callbacks_set_before_frame_send_callback( callbacks, before_frame_send_callback); - nghttp2_session_callbacks_set_send_callback(callbacks, send_callback); + nghttp2_session_callbacks_set_send_callback2(callbacks, send_callback); nghttp2_option *opt; @@ -257,11 +258,11 @@ int Http2Session::submit_request() { client_->reqidx = 0; } - nghttp2_data_provider prd{{0}, file_read_callback}; + nghttp2_data_provider2 prd{{0}, file_read_callback}; auto stream_id = - nghttp2_submit_request(session_, nullptr, nva.data(), nva.size(), - config->data_fd == -1 ? nullptr : &prd, nullptr); + nghttp2_submit_request2(session_, nullptr, nva.data(), nva.size(), + config->data_fd == -1 ? nullptr : &prd, nullptr); if (stream_id < 0) { return -1; } @@ -272,7 +273,7 @@ int Http2Session::submit_request() { } int Http2Session::on_read(const uint8_t *data, size_t len) { - auto rv = nghttp2_session_mem_recv(session_, data, len); + auto rv = nghttp2_session_mem_recv2(session_, data, len); if (rv < 0) { return -1; } @@ -308,7 +309,7 @@ void Http2Session::terminate() { } size_t Http2Session::max_concurrent_streams() { - return (size_t)client_->worker->config->max_concurrent_streams; + return client_->worker->config->max_concurrent_streams; } } // namespace h2load diff --git a/src/h2load_http3_session.cc b/src/h2load_http3_session.cc index d491cba..03a2233 100644 --- a/src/h2load_http3_session.cc +++ b/src/h2load_http3_session.cc @@ -124,7 +124,7 @@ int Http3Session::on_write() { return -1; } void Http3Session::terminate() {} size_t Http3Session::max_concurrent_streams() { - return (size_t)client_->worker->config->max_concurrent_streams; + return client_->worker->config->max_concurrent_streams; } namespace { diff --git a/src/h2load_quic.cc b/src/h2load_quic.cc index e492a3e..8b3c552 100644 --- a/src/h2load_quic.cc +++ b/src/h2load_quic.cc @@ -654,7 +654,8 @@ int Client::write_quic() { ngtcp2_conn_get_path_max_tx_udp_payload_size(quic.conn); #endif // UDP_SEGMENT auto max_pktcnt = - ngtcp2_conn_get_send_quantum(quic.conn) / max_udp_payload_size; + std::max(ngtcp2_conn_get_send_quantum(quic.conn) / max_udp_payload_size, + static_cast<size_t>(1)); uint8_t *bufpos = quic.tx.data.get(); ngtcp2_path_storage ps; size_t gso_size = 0; diff --git a/src/http2_test.cc b/src/http2_test.cc index f8be9f4..3cb0b71 100644 --- a/src/http2_test.cc +++ b/src/http2_test.cc @@ -28,7 +28,7 @@ #include <cstring> #include <iostream> -#include <CUnit/CUnit.h> +#include "munitxx.h" #include "url-parser/url_parser.h" @@ -46,11 +46,38 @@ using namespace nghttp2; namespace shrpx { namespace { +const MunitTest tests[]{ + munit_void_test(test_http2_add_header), + munit_void_test(test_http2_get_header), + munit_void_test(test_http2_copy_headers_to_nva), + munit_void_test(test_http2_build_http1_headers_from_headers), + munit_void_test(test_http2_lws), + munit_void_test(test_http2_rewrite_location_uri), + munit_void_test(test_http2_parse_http_status_code), + munit_void_test(test_http2_index_header), + munit_void_test(test_http2_lookup_token), + munit_void_test(test_http2_parse_link_header), + munit_void_test(test_http2_path_join), + munit_void_test(test_http2_normalize_path), + munit_void_test(test_http2_rewrite_clean_path), + munit_void_test(test_http2_get_pure_path_component), + munit_void_test(test_http2_construct_push_component), + munit_void_test(test_http2_contains_trailers), + munit_void_test(test_http2_check_transfer_encoding), + munit_test_end(), +}; +} // namespace + +const MunitSuite http2_suite{ + "/http2", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + +namespace { void check_nv(const HeaderRef &a, const nghttp2_nv *b) { - CU_ASSERT(a.name.size() == b->namelen); - CU_ASSERT(a.value.size() == b->valuelen); - CU_ASSERT(memcmp(a.name.c_str(), b->name, b->namelen) == 0); - CU_ASSERT(memcmp(a.value.c_str(), b->value, b->valuelen) == 0); + assert_size(a.name.size(), ==, b->namelen); + assert_size(a.value.size(), ==, b->valuelen); + assert_memory_equal(b->namelen, a.name.c_str(), b->name); + assert_memory_equal(b->valuelen, a.value.c_str(), b->value); } } // namespace @@ -59,51 +86,51 @@ void test_http2_add_header(void) { http2::add_header(nva, (const uint8_t *)"alpha", 5, (const uint8_t *)"123", 3, false, -1); - CU_ASSERT(Headers::value_type("alpha", "123") == nva[0]); - CU_ASSERT(!nva[0].no_index); + assert_true(Headers::value_type("alpha", "123") == nva[0]); + assert_false(nva[0].no_index); nva.clear(); http2::add_header(nva, (const uint8_t *)"alpha", 5, (const uint8_t *)"", 0, true, -1); - CU_ASSERT(Headers::value_type("alpha", "") == nva[0]); - CU_ASSERT(nva[0].no_index); + assert_true(Headers::value_type("alpha", "") == nva[0]); + assert_true(nva[0].no_index); nva.clear(); http2::add_header(nva, (const uint8_t *)"a", 1, (const uint8_t *)" b", 2, false, -1); - CU_ASSERT(Headers::value_type("a", "b") == nva[0]); + assert_true(Headers::value_type("a", "b") == nva[0]); nva.clear(); http2::add_header(nva, (const uint8_t *)"a", 1, (const uint8_t *)"b ", 2, false, -1); - CU_ASSERT(Headers::value_type("a", "b") == nva[0]); + assert_true(Headers::value_type("a", "b") == nva[0]); nva.clear(); http2::add_header(nva, (const uint8_t *)"a", 1, (const uint8_t *)" b ", 5, false, -1); - CU_ASSERT(Headers::value_type("a", "b") == nva[0]); + assert_true(Headers::value_type("a", "b") == nva[0]); nva.clear(); http2::add_header(nva, (const uint8_t *)"a", 1, (const uint8_t *)" bravo ", 9, false, -1); - CU_ASSERT(Headers::value_type("a", "bravo") == nva[0]); + assert_true(Headers::value_type("a", "bravo") == nva[0]); nva.clear(); http2::add_header(nva, (const uint8_t *)"a", 1, (const uint8_t *)" ", 4, false, -1); - CU_ASSERT(Headers::value_type("a", "") == nva[0]); + assert_true(Headers::value_type("a", "") == nva[0]); nva.clear(); http2::add_header(nva, (const uint8_t *)"te", 2, (const uint8_t *)"trailers", 8, false, http2::HD_TE); - CU_ASSERT(http2::HD_TE == nva[0].token); + assert_int32(http2::HD_TE, ==, nva[0].token); } void test_http2_get_header(void) { @@ -112,21 +139,21 @@ void test_http2_get_header(void) { {"content-length", "7"}}; const Headers::value_type *rv; rv = http2::get_header(nva, "delta"); - CU_ASSERT(rv != nullptr); - CU_ASSERT("delta" == rv->name); + assert_not_null(rv); + assert_stdstring_equal("delta", rv->name); rv = http2::get_header(nva, "bravo"); - CU_ASSERT(rv != nullptr); - CU_ASSERT("bravo" == rv->name); + assert_not_null(rv); + assert_stdstring_equal("bravo", rv->name); rv = http2::get_header(nva, "foxtrot"); - CU_ASSERT(rv == nullptr); + assert_null(rv); http2::HeaderIndex hdidx; http2::init_hdidx(hdidx); hdidx[http2::HD_CONTENT_LENGTH] = 6; rv = http2::get_header(hdidx, http2::HD_CONTENT_LENGTH, nva); - CU_ASSERT("content-length" == rv->name); + assert_stdstring_equal("content-length", rv->name); } namespace { @@ -177,29 +204,31 @@ void test_http2_copy_headers_to_nva(void) { http2::copy_headers_to_nva_nocopy(nva, headers, http2::HDOP_STRIP_X_FORWARDED_FOR); - CU_ASSERT(7 == nva.size()); + assert_size(7, ==, nva.size()); for (size_t i = 0; i < ans.size(); ++i) { check_nv(headers[ans[i]], &nva[i]); if (ans[i] == 0) { - CU_ASSERT((NGHTTP2_NV_FLAG_NO_COPY_NAME | NGHTTP2_NV_FLAG_NO_COPY_VALUE | - NGHTTP2_NV_FLAG_NO_INDEX) == nva[i].flags); + assert_uint8((NGHTTP2_NV_FLAG_NO_COPY_NAME | + NGHTTP2_NV_FLAG_NO_COPY_VALUE | NGHTTP2_NV_FLAG_NO_INDEX), + ==, nva[i].flags); } else { - CU_ASSERT((NGHTTP2_NV_FLAG_NO_COPY_NAME | - NGHTTP2_NV_FLAG_NO_COPY_VALUE) == nva[i].flags); + assert_uint8( + (NGHTTP2_NV_FLAG_NO_COPY_NAME | NGHTTP2_NV_FLAG_NO_COPY_VALUE), ==, + nva[i].flags); } } nva.clear(); http2::copy_headers_to_nva(nva, headers, http2::HDOP_STRIP_X_FORWARDED_FOR); - CU_ASSERT(7 == nva.size()); + assert_size(7, ==, nva.size()); for (size_t i = 0; i < ans.size(); ++i) { check_nv(headers[ans[i]], &nva[i]); if (ans[i] == 0) { - CU_ASSERT(nva[i].flags & NGHTTP2_NV_FLAG_NO_INDEX); + assert_true(nva[i].flags & NGHTTP2_NV_FLAG_NO_INDEX); } else { - CU_ASSERT(NGHTTP2_NV_FLAG_NONE == nva[i].flags); + assert_false(nva[i].flags); } } @@ -207,7 +236,7 @@ void test_http2_copy_headers_to_nva(void) { auto ans2 = std::vector<int>{0, 2, 4, 6}; http2::copy_headers_to_nva(nva, headers2, http2::HDOP_NONE); - CU_ASSERT(ans2.size() == nva.size()); + assert_size(ans2.size(), ==, nva.size()); for (size_t i = 0; i < ans2.size(); ++i) { check_nv(headers2[ans2[i]], &nva[i]); } @@ -215,7 +244,7 @@ void test_http2_copy_headers_to_nva(void) { nva.clear(); http2::copy_headers_to_nva(nva, headers2, http2::HDOP_STRIP_ALL); - CU_ASSERT(nva.empty()); + assert_true(nva.empty()); } void test_http2_build_http1_headers_from_headers(void) { @@ -224,36 +253,38 @@ void test_http2_build_http1_headers_from_headers(void) { http2::build_http1_headers_from_headers(&buf, headers, http2::HDOP_STRIP_X_FORWARDED_FOR); auto hdrs = std::string(buf.head->pos, buf.head->last); - CU_ASSERT("Alpha: 0\r\n" - "Bravo: 1\r\n" - "Delta: 4\r\n" - "Expect: 5\r\n" - "Foxtrot: 6\r\n" - "Tango: 7\r\n" - "Te: 8\r\n" - "Te: 9\r\n" - "Zulu: 12\r\n" == hdrs); + assert_stdstring_equal("Alpha: 0\r\n" + "Bravo: 1\r\n" + "Delta: 4\r\n" + "Expect: 5\r\n" + "Foxtrot: 6\r\n" + "Tango: 7\r\n" + "Te: 8\r\n" + "Te: 9\r\n" + "Zulu: 12\r\n", + hdrs); buf.reset(); http2::build_http1_headers_from_headers(&buf, headers2, http2::HDOP_NONE); hdrs = std::string(buf.head->pos, buf.head->last); - CU_ASSERT("X-Forwarded-For: xff1\r\n" - "X-Forwarded-Proto: xfp1\r\n" - "Forwarded: fwd1\r\n" - "Via: via1\r\n" == hdrs); + assert_stdstring_equal("X-Forwarded-For: xff1\r\n" + "X-Forwarded-Proto: xfp1\r\n" + "Forwarded: fwd1\r\n" + "Via: via1\r\n", + hdrs); buf.reset(); http2::build_http1_headers_from_headers(&buf, headers2, http2::HDOP_STRIP_ALL); - CU_ASSERT(0 == buf.rleft()); + assert_size(0, ==, buf.rleft()); } void test_http2_lws(void) { - CU_ASSERT(!http2::lws("alpha")); - CU_ASSERT(http2::lws(" ")); - CU_ASSERT(http2::lws("")); + assert_false(http2::lws("alpha")); + assert_true(http2::lws(" ")); + assert_true(http2::lws("")); } namespace { @@ -263,11 +294,11 @@ void check_rewrite_location_uri(const std::string &want, const std::string &uri, const std::string &upstream_scheme) { BlockAllocator balloc(4096, 4096); http_parser_url u{}; - CU_ASSERT(0 == http_parser_parse_url(uri.c_str(), uri.size(), 0, &u)); + assert_int(0, ==, http_parser_parse_url(uri.c_str(), uri.size(), 0, &u)); auto got = http2::rewrite_location_uri( balloc, StringRef{uri}, u, StringRef{match_host}, StringRef{req_authority}, StringRef{upstream_scheme}); - CU_ASSERT(want == got); + assert_stdstring_equal(want, got.str()); } } // namespace @@ -299,13 +330,15 @@ void test_http2_rewrite_location_uri(void) { } void test_http2_parse_http_status_code(void) { - CU_ASSERT(200 == http2::parse_http_status_code(StringRef::from_lit("200"))); - CU_ASSERT(102 == http2::parse_http_status_code(StringRef::from_lit("102"))); - CU_ASSERT(-1 == http2::parse_http_status_code(StringRef::from_lit("099"))); - CU_ASSERT(-1 == http2::parse_http_status_code(StringRef::from_lit("99"))); - CU_ASSERT(-1 == http2::parse_http_status_code(StringRef::from_lit("-1"))); - CU_ASSERT(-1 == http2::parse_http_status_code(StringRef::from_lit("20a"))); - CU_ASSERT(-1 == http2::parse_http_status_code(StringRef{})); + assert_int(200, ==, + http2::parse_http_status_code(StringRef::from_lit("200"))); + assert_int(102, ==, + http2::parse_http_status_code(StringRef::from_lit("102"))); + assert_int(-1, ==, http2::parse_http_status_code(StringRef::from_lit("099"))); + assert_int(-1, ==, http2::parse_http_status_code(StringRef::from_lit("99"))); + assert_int(-1, ==, http2::parse_http_status_code(StringRef::from_lit("-1"))); + assert_int(-1, ==, http2::parse_http_status_code(StringRef::from_lit("20a"))); + assert_int(-1, ==, http2::parse_http_status_code(StringRef{})); } void test_http2_index_header(void) { @@ -315,402 +348,402 @@ void test_http2_index_header(void) { http2::index_header(hdidx, http2::HD__AUTHORITY, 0); http2::index_header(hdidx, -1, 1); - CU_ASSERT(0 == hdidx[http2::HD__AUTHORITY]); + assert_uint16(0, ==, hdidx[http2::HD__AUTHORITY]); } void test_http2_lookup_token(void) { - CU_ASSERT(http2::HD__AUTHORITY == - http2::lookup_token(StringRef::from_lit(":authority"))); - CU_ASSERT(-1 == http2::lookup_token(StringRef::from_lit(":authorit"))); - CU_ASSERT(-1 == http2::lookup_token(StringRef::from_lit(":Authority"))); - CU_ASSERT(http2::HD_EXPECT == - http2::lookup_token(StringRef::from_lit("expect"))); + assert_int(http2::HD__AUTHORITY, ==, + http2::lookup_token(StringRef::from_lit(":authority"))); + assert_int(-1, ==, http2::lookup_token(StringRef::from_lit(":authorit"))); + assert_int(-1, ==, http2::lookup_token(StringRef::from_lit(":Authority"))); + assert_int(http2::HD_EXPECT, ==, + http2::lookup_token(StringRef::from_lit("expect"))); } void test_http2_parse_link_header(void) { { // only URI appears; we don't extract URI unless it bears rel=preload auto res = http2::parse_link_header(StringRef::from_lit("<url>")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // URI url should be extracted auto res = http2::parse_link_header(StringRef::from_lit("<url>; rel=preload")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // With extra link-param. URI url should be extracted auto res = http2::parse_link_header( StringRef::from_lit("<url>; rel=preload; as=file")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // With extra link-param. URI url should be extracted auto res = http2::parse_link_header( StringRef::from_lit("<url>; as=file; rel=preload")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // With extra link-param and quote-string. URI url should be // extracted auto res = http2::parse_link_header( StringRef::from_lit(R"(<url>; rel=preload; title="foo,bar")")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // With extra link-param and quote-string. URI url should be // extracted auto res = http2::parse_link_header( StringRef::from_lit(R"(<url>; title="foo,bar"; rel=preload)")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // ',' after quote-string auto res = http2::parse_link_header( StringRef::from_lit(R"(<url>; title="foo,bar", <url2>; rel=preload)")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url2" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url2", res[0].uri.str()); } { // Only first URI should be extracted. auto res = http2::parse_link_header( StringRef::from_lit("<url>; rel=preload, <url2>")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // Both have rel=preload, so both urls should be extracted auto res = http2::parse_link_header( StringRef::from_lit("<url>; rel=preload, <url2>; rel=preload")); - CU_ASSERT(2 == res.size()); - CU_ASSERT("url" == res[0].uri); - CU_ASSERT("url2" == res[1].uri); + assert_size(2, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); + assert_stdstring_equal("url2", res[1].uri.str()); } { // Second URI uri should be extracted. auto res = http2::parse_link_header( StringRef::from_lit("<url>, <url2>;rel=preload")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url2" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url2", res[0].uri.str()); } { // Error if input ends with ';' auto res = http2::parse_link_header(StringRef::from_lit("<url>;rel=preload;")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // Error if link header ends with ';' auto res = http2::parse_link_header( StringRef::from_lit("<url>;rel=preload;, <url>")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // OK if input ends with ',' auto res = http2::parse_link_header(StringRef::from_lit("<url>;rel=preload,")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // Multiple repeated ','s between fields is OK auto res = http2::parse_link_header( StringRef::from_lit("<url>,,,<url2>;rel=preload")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url2" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url2", res[0].uri.str()); } { // Error if url is not enclosed by <> auto res = http2::parse_link_header(StringRef::from_lit("url>;rel=preload")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // Error if url is not enclosed by <> auto res = http2::parse_link_header(StringRef::from_lit("<url;rel=preload")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // Empty parameter value is not allowed auto res = http2::parse_link_header(StringRef::from_lit("<url>;rel=preload; as=")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // Empty parameter value is not allowed auto res = http2::parse_link_header(StringRef::from_lit("<url>;as=;rel=preload")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // Empty parameter value is not allowed auto res = http2::parse_link_header( StringRef::from_lit("<url>;as=, <url>;rel=preload")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // Empty parameter name is not allowed auto res = http2::parse_link_header( StringRef::from_lit("<url>; =file; rel=preload")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // Without whitespaces auto res = http2::parse_link_header( StringRef::from_lit("<url>;as=file;rel=preload,<url2>;rel=preload")); - CU_ASSERT(2 == res.size()); - CU_ASSERT("url" == res[0].uri); - CU_ASSERT("url2" == res[1].uri); + assert_size(2, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); + assert_stdstring_equal("url2", res[1].uri.str()); } { // link-extension may have no value auto res = http2::parse_link_header(StringRef::from_lit("<url>; as; rel=preload")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // ext-name-star auto res = http2::parse_link_header( StringRef::from_lit("<url>; foo*=bar; rel=preload")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // '*' is not allowed expect for trailing one auto res = http2::parse_link_header( StringRef::from_lit("<url>; *=bar; rel=preload")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // '*' is not allowed expect for trailing one auto res = http2::parse_link_header( StringRef::from_lit("<url>; foo*bar=buzz; rel=preload")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // ext-name-star must be followed by '=' auto res = http2::parse_link_header( StringRef::from_lit("<url>; foo*; rel=preload")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // '>' is not followed by ';' auto res = http2::parse_link_header(StringRef::from_lit("<url> rel=preload")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // Starting with whitespace is no problem. auto res = http2::parse_link_header(StringRef::from_lit(" <url>; rel=preload")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // preload is a prefix of bogus rel parameter value auto res = http2::parse_link_header(StringRef::from_lit("<url>; rel=preloadx")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // preload in relation-types list auto res = http2::parse_link_header( StringRef::from_lit(R"(<url>; rel="preload")")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // preload in relation-types list followed by another parameter auto res = http2::parse_link_header( StringRef::from_lit(R"(<url>; rel="preload foo")")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // preload in relation-types list following another parameter auto res = http2::parse_link_header( StringRef::from_lit(R"(<url>; rel="foo preload")")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // preload in relation-types list between other parameters auto res = http2::parse_link_header( StringRef::from_lit(R"(<url>; rel="foo preload bar")")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // preload in relation-types list between other parameters auto res = http2::parse_link_header( StringRef::from_lit(R"(<url>; rel="foo preload bar")")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // no preload in relation-types list auto res = http2::parse_link_header(StringRef::from_lit(R"(<url>; rel="foo")")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // no preload in relation-types list, multiple unrelated elements. auto res = http2::parse_link_header( StringRef::from_lit(R"(<url>; rel="foo bar")")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // preload in relation-types list, followed by another link-value. auto res = http2::parse_link_header( StringRef::from_lit(R"(<url>; rel="preload", <url2>)")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // preload in relation-types list, following another link-value. auto res = http2::parse_link_header( StringRef::from_lit(R"(<url>, <url2>; rel="preload")")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url2" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url2", res[0].uri.str()); } { // preload in relation-types list, followed by another link-param. auto res = http2::parse_link_header( StringRef::from_lit(R"(<url>; rel="preload"; as="font")")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // preload in relation-types list, followed by character other // than ';' or ',' auto res = http2::parse_link_header( StringRef::from_lit(R"(<url>; rel="preload".)")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // preload in relation-types list, followed by ';' but it // terminates input auto res = http2::parse_link_header( StringRef::from_lit(R"(<url>; rel="preload";)")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // preload in relation-types list, followed by ',' but it // terminates input auto res = http2::parse_link_header( StringRef::from_lit(R"(<url>; rel="preload",)")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // preload in relation-types list but there is preceding white // space. auto res = http2::parse_link_header( StringRef::from_lit(R"(<url>; rel=" preload")")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // preload in relation-types list but there is trailing white // space. auto res = http2::parse_link_header( StringRef::from_lit(R"(<url>; rel="preload ")")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // backslash escaped characters in quoted-string auto res = http2::parse_link_header( StringRef::from_lit(R"(<url>; rel=preload; title="foo\"baz\"bar")")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // anchor="" is acceptable auto res = http2::parse_link_header( StringRef::from_lit(R"(<url>; rel=preload; anchor="")")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // With anchor="#foo", url should be ignored auto res = http2::parse_link_header( StringRef::from_lit(R"(<url>; rel=preload; anchor="#foo")")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // With anchor=f, url should be ignored auto res = http2::parse_link_header( StringRef::from_lit("<url>; rel=preload; anchor=f")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // First url is ignored With anchor="#foo", but url should be // accepted. auto res = http2::parse_link_header(StringRef::from_lit( R"(<url>; rel=preload; anchor="#foo", <url2>; rel=preload)")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url2" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url2", res[0].uri.str()); } { // With loadpolicy="next", url should be ignored auto res = http2::parse_link_header( StringRef::from_lit(R"(<url>; rel=preload; loadpolicy="next")")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // url should be picked up if empty loadpolicy is specified auto res = http2::parse_link_header( StringRef::from_lit(R"(<url>; rel=preload; loadpolicy="")")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // case-insensitive match auto res = http2::parse_link_header( StringRef::from_lit(R"(<url>; rel=preload; ANCHOR="#foo", <url2>; )" R"(REL=PRELOAD, <url3>; REL="foo PRELOAD bar")")); - CU_ASSERT(2 == res.size()); - CU_ASSERT("url2" == res[0].uri); - CU_ASSERT("url3" == res[1].uri); + assert_size(2, ==, res.size()); + assert_stdstring_equal("url2", res[0].uri.str()); + assert_stdstring_equal("url3", res[1].uri.str()); } { // nopush at the end of input auto res = http2::parse_link_header( StringRef::from_lit("<url>; rel=preload; nopush")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // nopush followed by ';' auto res = http2::parse_link_header( StringRef::from_lit("<url>; rel=preload; nopush; foo")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // nopush followed by ',' auto res = http2::parse_link_header( StringRef::from_lit("<url>; nopush; rel=preload")); - CU_ASSERT(0 == res.size()); + assert_size(0, ==, res.size()); } { // string whose prefix is nopush auto res = http2::parse_link_header( StringRef::from_lit("<url>; nopushyes; rel=preload")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } { // rel=preload twice auto res = http2::parse_link_header( StringRef::from_lit("<url>; rel=preload; rel=preload")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("url" == res[0].uri); + assert_size(1, ==, res.size()); + assert_stdstring_equal("url", res[0].uri.str()); } } @@ -718,124 +751,132 @@ void test_http2_path_join(void) { { auto base = StringRef::from_lit("/"); auto rel = StringRef::from_lit("/"); - CU_ASSERT("/" == http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/", http2::path_join(base, StringRef{}, rel, StringRef{})); } { auto base = StringRef::from_lit("/"); auto rel = StringRef::from_lit("/alpha"); - CU_ASSERT("/alpha" == - http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/alpha", http2::path_join(base, StringRef{}, rel, StringRef{})); } { // rel ends with trailing '/' auto base = StringRef::from_lit("/"); auto rel = StringRef::from_lit("/alpha/"); - CU_ASSERT("/alpha/" == - http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/alpha/", http2::path_join(base, StringRef{}, rel, StringRef{})); } { // rel contains multiple components auto base = StringRef::from_lit("/"); auto rel = StringRef::from_lit("/alpha/bravo"); - CU_ASSERT("/alpha/bravo" == - http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/alpha/bravo", http2::path_join(base, StringRef{}, rel, StringRef{})); } { // rel is relative auto base = StringRef::from_lit("/"); auto rel = StringRef::from_lit("alpha/bravo"); - CU_ASSERT("/alpha/bravo" == - http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/alpha/bravo", http2::path_join(base, StringRef{}, rel, StringRef{})); } { // rel is relative and base ends without /, which means it refers // to file. auto base = StringRef::from_lit("/alpha"); auto rel = StringRef::from_lit("bravo/charlie"); - CU_ASSERT("/bravo/charlie" == - http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/bravo/charlie", + http2::path_join(base, StringRef{}, rel, StringRef{})); } { // rel contains repeated '/'s auto base = StringRef::from_lit("/"); auto rel = StringRef::from_lit("/alpha/////bravo/////"); - CU_ASSERT("/alpha/bravo/" == - http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/alpha/bravo/", http2::path_join(base, StringRef{}, rel, StringRef{})); } { // base ends with '/', so '..' eats 'bravo' auto base = StringRef::from_lit("/alpha/bravo/"); auto rel = StringRef::from_lit("../charlie/delta"); - CU_ASSERT("/alpha/charlie/delta" == - http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/alpha/charlie/delta", + http2::path_join(base, StringRef{}, rel, StringRef{})); } { // base does not end with '/', so '..' eats 'alpha/bravo' auto base = StringRef::from_lit("/alpha/bravo"); auto rel = StringRef::from_lit("../charlie"); - CU_ASSERT("/charlie" == - http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/charlie", http2::path_join(base, StringRef{}, rel, StringRef{})); } { // 'charlie' is eaten by following '..' auto base = StringRef::from_lit("/alpha/bravo/"); auto rel = StringRef::from_lit("../charlie/../delta"); - CU_ASSERT("/alpha/delta" == - http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/alpha/delta", http2::path_join(base, StringRef{}, rel, StringRef{})); } { // excessive '..' results in '/' auto base = StringRef::from_lit("/alpha/bravo/"); auto rel = StringRef::from_lit("../../../"); - CU_ASSERT("/" == http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/", http2::path_join(base, StringRef{}, rel, StringRef{})); } { // excessive '..' and path component auto base = StringRef::from_lit("/alpha/bravo/"); auto rel = StringRef::from_lit("../../../charlie"); - CU_ASSERT("/charlie" == - http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/charlie", http2::path_join(base, StringRef{}, rel, StringRef{})); } { // rel ends with '..' auto base = StringRef::from_lit("/alpha/bravo/"); auto rel = StringRef::from_lit("charlie/.."); - CU_ASSERT("/alpha/bravo/" == - http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/alpha/bravo/", http2::path_join(base, StringRef{}, rel, StringRef{})); } { // base empty and rel contains '..' auto base = StringRef{}; auto rel = StringRef::from_lit("charlie/.."); - CU_ASSERT("/" == http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/", http2::path_join(base, StringRef{}, rel, StringRef{})); } { // '.' is ignored auto base = StringRef::from_lit("/"); auto rel = StringRef::from_lit("charlie/././././delta"); - CU_ASSERT("/charlie/delta" == - http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/charlie/delta", + http2::path_join(base, StringRef{}, rel, StringRef{})); } { // trailing '.' is ignored auto base = StringRef::from_lit("/"); auto rel = StringRef::from_lit("charlie/."); - CU_ASSERT("/charlie/" == - http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/charlie/", http2::path_join(base, StringRef{}, rel, StringRef{})); } { // query auto base = StringRef::from_lit("/"); auto rel = StringRef::from_lit("/"); auto relq = StringRef::from_lit("q"); - CU_ASSERT("/?q" == http2::path_join(base, StringRef{}, rel, relq)); + assert_stdstring_equal("/?q", + http2::path_join(base, StringRef{}, rel, relq)); } { // empty rel and query auto base = StringRef::from_lit("/alpha"); auto rel = StringRef{}; auto relq = StringRef::from_lit("q"); - CU_ASSERT("/alpha?q" == http2::path_join(base, StringRef{}, rel, relq)); + assert_stdstring_equal("/alpha?q", + http2::path_join(base, StringRef{}, rel, relq)); } { // both rel and query are empty @@ -843,26 +884,28 @@ void test_http2_path_join(void) { auto baseq = StringRef::from_lit("r"); auto rel = StringRef{}; auto relq = StringRef{}; - CU_ASSERT("/alpha?r" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/alpha?r", + http2::path_join(base, baseq, rel, relq)); } { // empty base auto base = StringRef{}; auto rel = StringRef::from_lit("/alpha"); - CU_ASSERT("/alpha" == - http2::path_join(base, StringRef{}, rel, StringRef{})); + assert_stdstring_equal( + "/alpha", http2::path_join(base, StringRef{}, rel, StringRef{})); } { // everything is empty - CU_ASSERT("/" == http2::path_join(StringRef{}, StringRef{}, StringRef{}, - StringRef{})); + assert_stdstring_equal("/", http2::path_join(StringRef{}, StringRef{}, + StringRef{}, StringRef{})); } { // only baseq is not empty auto base = StringRef{}; auto baseq = StringRef::from_lit("r"); auto rel = StringRef{}; - CU_ASSERT("/?r" == http2::path_join(base, baseq, rel, StringRef{})); + assert_stdstring_equal("/?r", + http2::path_join(base, baseq, rel, StringRef{})); } { // path starts with multiple '/'s. @@ -870,8 +913,8 @@ void test_http2_path_join(void) { auto baseq = StringRef{}; auto rel = StringRef::from_lit("//alpha//bravo"); auto relq = StringRef::from_lit("charlie"); - CU_ASSERT("/alpha/bravo?charlie" == - http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/alpha/bravo?charlie", + http2::path_join(base, baseq, rel, relq)); } // Test cases from RFC 3986, section 5.4. constexpr auto base = StringRef::from_lit("/b/c/d;p"); @@ -879,239 +922,266 @@ void test_http2_path_join(void) { { auto rel = StringRef::from_lit("g"); auto relq = StringRef{}; - CU_ASSERT("/b/c/g" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/g", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("./g"); auto relq = StringRef{}; - CU_ASSERT("/b/c/g" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/g", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("g/"); auto relq = StringRef{}; - CU_ASSERT("/b/c/g/" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/g/", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("/g"); auto relq = StringRef{}; - CU_ASSERT("/g" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/g", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef{}; auto relq = StringRef::from_lit("y"); - CU_ASSERT("/b/c/d;p?y" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/d;p?y", + http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("g"); auto relq = StringRef::from_lit("y"); - CU_ASSERT("/b/c/g?y" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/g?y", + http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit(";x"); auto relq = StringRef{}; - CU_ASSERT("/b/c/;x" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/;x", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("g;x"); auto relq = StringRef{}; - CU_ASSERT("/b/c/g;x" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/g;x", + http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("g;x"); auto relq = StringRef::from_lit("y"); - CU_ASSERT("/b/c/g;x?y" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/g;x?y", + http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef{}; auto relq = StringRef{}; - CU_ASSERT("/b/c/d;p?q" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/d;p?q", + http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("."); auto relq = StringRef{}; - CU_ASSERT("/b/c/" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("./"); auto relq = StringRef{}; - CU_ASSERT("/b/c/" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit(".."); auto relq = StringRef{}; - CU_ASSERT("/b/" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("../"); auto relq = StringRef{}; - CU_ASSERT("/b/" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("../g"); auto relq = StringRef{}; - CU_ASSERT("/b/g" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/g", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("../.."); auto relq = StringRef{}; - CU_ASSERT("/" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("../../"); auto relq = StringRef{}; - CU_ASSERT("/" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("../../g"); auto relq = StringRef{}; - CU_ASSERT("/g" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/g", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("../../../g"); auto relq = StringRef{}; - CU_ASSERT("/g" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/g", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("../../../../g"); auto relq = StringRef{}; - CU_ASSERT("/g" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/g", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("/./g"); auto relq = StringRef{}; - CU_ASSERT("/g" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/g", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("/../g"); auto relq = StringRef{}; - CU_ASSERT("/g" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/g", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("g."); auto relq = StringRef{}; - CU_ASSERT("/b/c/g." == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/g.", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit(".g"); auto relq = StringRef{}; - CU_ASSERT("/b/c/.g" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/.g", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("g.."); auto relq = StringRef{}; - CU_ASSERT("/b/c/g.." == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/g..", + http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("..g"); auto relq = StringRef{}; - CU_ASSERT("/b/c/..g" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/..g", + http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("./../g"); auto relq = StringRef{}; - CU_ASSERT("/b/g" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/g", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("./g/."); auto relq = StringRef{}; - CU_ASSERT("/b/c/g/" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/g/", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("g/./h"); auto relq = StringRef{}; - CU_ASSERT("/b/c/g/h" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/g/h", + http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("g/../h"); auto relq = StringRef{}; - CU_ASSERT("/b/c/h" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/h", http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("g;x=1/./y"); auto relq = StringRef{}; - CU_ASSERT("/b/c/g;x=1/y" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/g;x=1/y", + http2::path_join(base, baseq, rel, relq)); } { auto rel = StringRef::from_lit("g;x=1/../y"); auto relq = StringRef{}; - CU_ASSERT("/b/c/y" == http2::path_join(base, baseq, rel, relq)); + assert_stdstring_equal("/b/c/y", http2::path_join(base, baseq, rel, relq)); } } void test_http2_normalize_path(void) { - CU_ASSERT("/alpha/charlie" == - http2::normalize_path( - StringRef::from_lit("/alpha/bravo/../charlie"), StringRef{})); + assert_stdstring_equal( + "/alpha/charlie", + http2::normalize_path(StringRef::from_lit("/alpha/bravo/../charlie"), + StringRef{})); - CU_ASSERT("/alpha" == - http2::normalize_path(StringRef::from_lit("/a%6c%70%68%61"), - StringRef{})); + assert_stdstring_equal( + "/alpha", http2::normalize_path(StringRef::from_lit("/a%6c%70%68%61"), + StringRef{})); - CU_ASSERT( - "/alpha%2F%3A" == + assert_stdstring_equal( + "/alpha%2F%3A", http2::normalize_path(StringRef::from_lit("/alpha%2f%3a"), StringRef{})); - CU_ASSERT("/%2F" == - http2::normalize_path(StringRef::from_lit("%2f"), StringRef{})); + assert_stdstring_equal( + "/%2F", http2::normalize_path(StringRef::from_lit("%2f"), StringRef{})); - CU_ASSERT("/%f" == - http2::normalize_path(StringRef::from_lit("%f"), StringRef{})); + assert_stdstring_equal( + "/%f", http2::normalize_path(StringRef::from_lit("%f"), StringRef{})); - CU_ASSERT("/%" == - http2::normalize_path(StringRef::from_lit("%"), StringRef{})); + assert_stdstring_equal( + "/%", http2::normalize_path(StringRef::from_lit("%"), StringRef{})); - CU_ASSERT("/" == http2::normalize_path(StringRef{}, StringRef{})); + assert_stdstring_equal("/", http2::normalize_path(StringRef{}, StringRef{})); - CU_ASSERT("/alpha?bravo" == - http2::normalize_path(StringRef::from_lit("/alpha"), - StringRef::from_lit("bravo"))); + assert_stdstring_equal("/alpha?bravo", + http2::normalize_path(StringRef::from_lit("/alpha"), + StringRef::from_lit("bravo"))); } void test_http2_rewrite_clean_path(void) { BlockAllocator balloc(4096, 4096); // unreserved characters - CU_ASSERT("/alpha/bravo/" == - http2::rewrite_clean_path(balloc, - StringRef::from_lit("/alpha/%62ravo/"))); + assert_stdstring_equal( + "/alpha/bravo/", + http2::rewrite_clean_path(balloc, StringRef::from_lit("/alpha/%62ravo/")) + .str()); // percent-encoding is converted to upper case. - CU_ASSERT("/delta%3A" == http2::rewrite_clean_path( - balloc, StringRef::from_lit("/delta%3a"))); + assert_stdstring_equal( + "/delta%3A", + http2::rewrite_clean_path(balloc, StringRef::from_lit("/delta%3a")) + .str()); // path component is normalized before matching - CU_ASSERT( - "/alpha/bravo/" == + assert_stdstring_equal( + "/alpha/bravo/", http2::rewrite_clean_path( - balloc, StringRef::from_lit("/alpha/charlie/%2e././bravo/delta/.."))); + balloc, StringRef::from_lit("/alpha/charlie/%2e././bravo/delta/..")) + .str()); - CU_ASSERT("alpha%3a" == - http2::rewrite_clean_path(balloc, StringRef::from_lit("alpha%3a"))); + assert_stdstring_equal( + "alpha%3a", + http2::rewrite_clean_path(balloc, StringRef::from_lit("alpha%3a")).str()); - CU_ASSERT("" == http2::rewrite_clean_path(balloc, StringRef{})); + assert_stdstring_equal("", + http2::rewrite_clean_path(balloc, StringRef{}).str()); - CU_ASSERT( - "/alpha?bravo" == - http2::rewrite_clean_path(balloc, StringRef::from_lit("//alpha?bravo"))); + assert_stdstring_equal( + "/alpha?bravo", + http2::rewrite_clean_path(balloc, StringRef::from_lit("//alpha?bravo")) + .str()); } void test_http2_get_pure_path_component(void) { - CU_ASSERT("/" == http2::get_pure_path_component(StringRef::from_lit("/"))); - - CU_ASSERT("/foo" == - http2::get_pure_path_component(StringRef::from_lit("/foo"))); - - CU_ASSERT("/bar" == http2::get_pure_path_component( - StringRef::from_lit("https://example.org/bar"))); - - CU_ASSERT("/alpha" == http2::get_pure_path_component(StringRef::from_lit( - "https://example.org/alpha?q=a"))); - - CU_ASSERT("/bravo" == http2::get_pure_path_component(StringRef::from_lit( - "https://example.org/bravo?q=a#fragment"))); - - CU_ASSERT("" == - http2::get_pure_path_component(StringRef::from_lit("\x01\x02"))); + assert_stdstring_equal( + "/", http2::get_pure_path_component(StringRef::from_lit("/")).str()); + + assert_stdstring_equal( + "/foo", + http2::get_pure_path_component(StringRef::from_lit("/foo")).str()); + + assert_stdstring_equal("/bar", + http2::get_pure_path_component( + StringRef::from_lit("https://example.org/bar")) + .str()); + + assert_stdstring_equal( + "/alpha", http2::get_pure_path_component( + StringRef::from_lit("https://example.org/alpha?q=a")) + .str()); + + assert_stdstring_equal( + "/bravo", + http2::get_pure_path_component( + StringRef::from_lit("https://example.org/bravo?q=a#fragment")) + .str()); + + assert_stdstring_equal( + "", + http2::get_pure_path_component(StringRef::from_lit("\x01\x02")).str()); } void test_http2_construct_push_component(void) { @@ -1122,11 +1192,12 @@ void test_http2_construct_push_component(void) { base = StringRef::from_lit("/b/"); uri = StringRef::from_lit("https://example.org/foo"); - CU_ASSERT(0 == http2::construct_push_component(balloc, scheme, authority, - path, base, uri)); - CU_ASSERT("https" == scheme); - CU_ASSERT("example.org" == authority); - CU_ASSERT("/foo" == path); + assert_int(0, ==, + http2::construct_push_component(balloc, scheme, authority, path, + base, uri)); + assert_stdstring_equal("https", scheme.str()); + assert_stdstring_equal("example.org", authority.str()); + assert_stdstring_equal("/foo", path.str()); scheme = StringRef{}; authority = StringRef{}; @@ -1134,11 +1205,12 @@ void test_http2_construct_push_component(void) { uri = StringRef::from_lit("/foo/bar?q=a"); - CU_ASSERT(0 == http2::construct_push_component(balloc, scheme, authority, - path, base, uri)); - CU_ASSERT("" == scheme); - CU_ASSERT("" == authority); - CU_ASSERT("/foo/bar?q=a" == path); + assert_int(0, ==, + http2::construct_push_component(balloc, scheme, authority, path, + base, uri)); + assert_stdstring_equal("", scheme.str()); + assert_stdstring_equal("", authority.str()); + assert_stdstring_equal("/foo/bar?q=a", path.str()); scheme = StringRef{}; authority = StringRef{}; @@ -1146,11 +1218,12 @@ void test_http2_construct_push_component(void) { uri = StringRef::from_lit("foo/../bar?q=a"); - CU_ASSERT(0 == http2::construct_push_component(balloc, scheme, authority, - path, base, uri)); - CU_ASSERT("" == scheme); - CU_ASSERT("" == authority); - CU_ASSERT("/b/bar?q=a" == path); + assert_int(0, ==, + http2::construct_push_component(balloc, scheme, authority, path, + base, uri)); + assert_stdstring_equal("", scheme.str()); + assert_stdstring_equal("", authority.str()); + assert_stdstring_equal("/b/bar?q=a", path.str()); scheme = StringRef{}; authority = StringRef{}; @@ -1158,91 +1231,97 @@ void test_http2_construct_push_component(void) { uri = StringRef{}; - CU_ASSERT(-1 == http2::construct_push_component(balloc, scheme, authority, - path, base, uri)); + assert_int(-1, ==, + http2::construct_push_component(balloc, scheme, authority, path, + base, uri)); scheme = StringRef{}; authority = StringRef{}; path = StringRef{}; uri = StringRef::from_lit("?q=a"); - CU_ASSERT(0 == http2::construct_push_component(balloc, scheme, authority, - path, base, uri)); - CU_ASSERT("" == scheme); - CU_ASSERT("" == authority); - CU_ASSERT("/b/?q=a" == path); + assert_int(0, ==, + http2::construct_push_component(balloc, scheme, authority, path, + base, uri)); + assert_stdstring_equal("", scheme.str()); + assert_stdstring_equal("", authority.str()); + assert_stdstring_equal("/b/?q=a", path.str()); } void test_http2_contains_trailers(void) { - CU_ASSERT(!http2::contains_trailers(StringRef::from_lit(""))); - CU_ASSERT(http2::contains_trailers(StringRef::from_lit("trailers"))); + assert_false(http2::contains_trailers(StringRef::from_lit(""))); + assert_true(http2::contains_trailers(StringRef::from_lit("trailers"))); // Match must be case-insensitive. - CU_ASSERT(http2::contains_trailers(StringRef::from_lit("TRAILERS"))); - CU_ASSERT(!http2::contains_trailers(StringRef::from_lit("trailer"))); - CU_ASSERT(!http2::contains_trailers(StringRef::from_lit("trailers 3"))); - CU_ASSERT(http2::contains_trailers(StringRef::from_lit("trailers,"))); - CU_ASSERT(http2::contains_trailers(StringRef::from_lit("trailers,foo"))); - CU_ASSERT(http2::contains_trailers(StringRef::from_lit("foo,trailers"))); - CU_ASSERT(http2::contains_trailers(StringRef::from_lit("foo,trailers,bar"))); - CU_ASSERT( + assert_true(http2::contains_trailers(StringRef::from_lit("TRAILERS"))); + assert_false(http2::contains_trailers(StringRef::from_lit("trailer"))); + assert_false(http2::contains_trailers(StringRef::from_lit("trailers 3"))); + assert_true(http2::contains_trailers(StringRef::from_lit("trailers,"))); + assert_true(http2::contains_trailers(StringRef::from_lit("trailers,foo"))); + assert_true(http2::contains_trailers(StringRef::from_lit("foo,trailers"))); + assert_true( + http2::contains_trailers(StringRef::from_lit("foo,trailers,bar"))); + assert_true( http2::contains_trailers(StringRef::from_lit("foo, trailers ,bar"))); - CU_ASSERT(http2::contains_trailers(StringRef::from_lit(",trailers"))); + assert_true(http2::contains_trailers(StringRef::from_lit(",trailers"))); } void test_http2_check_transfer_encoding(void) { - CU_ASSERT(http2::check_transfer_encoding(StringRef::from_lit("chunked"))); - CU_ASSERT(http2::check_transfer_encoding(StringRef::from_lit("foo,chunked"))); - CU_ASSERT( + assert_true(http2::check_transfer_encoding(StringRef::from_lit("chunked"))); + assert_true( + http2::check_transfer_encoding(StringRef::from_lit("foo,chunked"))); + assert_true( http2::check_transfer_encoding(StringRef::from_lit("foo, chunked"))); - CU_ASSERT( + assert_true( http2::check_transfer_encoding(StringRef::from_lit("foo , chunked"))); - CU_ASSERT( + assert_true( http2::check_transfer_encoding(StringRef::from_lit("chunked;foo=bar"))); - CU_ASSERT( + assert_true( http2::check_transfer_encoding(StringRef::from_lit("chunked ; foo=bar"))); - CU_ASSERT(http2::check_transfer_encoding( + assert_true(http2::check_transfer_encoding( StringRef::from_lit(R"(chunked;foo="bar")"))); - CU_ASSERT(http2::check_transfer_encoding( + assert_true(http2::check_transfer_encoding( StringRef::from_lit(R"(chunked;foo="\bar\"";FOO=BAR)"))); - CU_ASSERT( + assert_true( http2::check_transfer_encoding(StringRef::from_lit(R"(chunked;foo="")"))); - CU_ASSERT(http2::check_transfer_encoding( + assert_true(http2::check_transfer_encoding( StringRef::from_lit(R"(chunked;foo="bar" , gzip)"))); - CU_ASSERT(!http2::check_transfer_encoding(StringRef{})); - CU_ASSERT(!http2::check_transfer_encoding(StringRef::from_lit(",chunked"))); - CU_ASSERT(!http2::check_transfer_encoding(StringRef::from_lit("chunked,"))); - CU_ASSERT(!http2::check_transfer_encoding(StringRef::from_lit("chunked, "))); - CU_ASSERT( - !http2::check_transfer_encoding(StringRef::from_lit("foo,,chunked"))); - CU_ASSERT( - !http2::check_transfer_encoding(StringRef::from_lit("chunked;foo"))); - CU_ASSERT(!http2::check_transfer_encoding(StringRef::from_lit("chunked;"))); - CU_ASSERT( - !http2::check_transfer_encoding(StringRef::from_lit("chunked;foo=bar;"))); - CU_ASSERT( - !http2::check_transfer_encoding(StringRef::from_lit("chunked;?=bar"))); - CU_ASSERT( - !http2::check_transfer_encoding(StringRef::from_lit("chunked;=bar"))); - CU_ASSERT(!http2::check_transfer_encoding(StringRef::from_lit("chunked;;"))); - CU_ASSERT(!http2::check_transfer_encoding(StringRef::from_lit("chunked?"))); - CU_ASSERT(!http2::check_transfer_encoding(StringRef::from_lit(","))); - CU_ASSERT(!http2::check_transfer_encoding(StringRef::from_lit(" "))); - CU_ASSERT(!http2::check_transfer_encoding(StringRef::from_lit(";"))); - CU_ASSERT(!http2::check_transfer_encoding(StringRef::from_lit("\""))); - CU_ASSERT(!http2::check_transfer_encoding( + assert_false(http2::check_transfer_encoding(StringRef{})); + assert_false(http2::check_transfer_encoding(StringRef::from_lit(",chunked"))); + assert_false(http2::check_transfer_encoding(StringRef::from_lit("chunked,"))); + assert_false( + http2::check_transfer_encoding(StringRef::from_lit("chunked, "))); + assert_false( + http2::check_transfer_encoding(StringRef::from_lit("foo,,chunked"))); + assert_false( + http2::check_transfer_encoding(StringRef::from_lit("chunked;foo"))); + assert_false(http2::check_transfer_encoding(StringRef::from_lit("chunked;"))); + assert_false( + http2::check_transfer_encoding(StringRef::from_lit("chunked;foo=bar;"))); + assert_false( + http2::check_transfer_encoding(StringRef::from_lit("chunked;?=bar"))); + assert_false( + http2::check_transfer_encoding(StringRef::from_lit("chunked;=bar"))); + assert_false( + http2::check_transfer_encoding(StringRef::from_lit("chunked;;"))); + assert_false(http2::check_transfer_encoding(StringRef::from_lit("chunked?"))); + assert_false(http2::check_transfer_encoding(StringRef::from_lit(","))); + assert_false(http2::check_transfer_encoding(StringRef::from_lit(" "))); + assert_false(http2::check_transfer_encoding(StringRef::from_lit(";"))); + assert_false(http2::check_transfer_encoding(StringRef::from_lit("\""))); + assert_false(http2::check_transfer_encoding( StringRef::from_lit(R"(chunked;foo="bar)"))); - CU_ASSERT(!http2::check_transfer_encoding( + assert_false(http2::check_transfer_encoding( StringRef::from_lit(R"(chunked;foo="bar\)"))); - CU_ASSERT( - !http2::check_transfer_encoding(StringRef::from_lit(R"(chunked;foo="bar\)" - "\x0a" - R"(")"))); - CU_ASSERT( - !http2::check_transfer_encoding(StringRef::from_lit(R"(chunked;foo=")" - "\x0a" - R"(")"))); - CU_ASSERT(!http2::check_transfer_encoding( + assert_false( + http2::check_transfer_encoding(StringRef::from_lit(R"(chunked;foo="bar\)" + "\x0a" + R"(")"))); + assert_false( + http2::check_transfer_encoding(StringRef::from_lit(R"(chunked;foo=")" + "\x0a" + R"(")"))); + assert_false(http2::check_transfer_encoding( StringRef::from_lit(R"(chunked;foo="bar",,gzip)"))); } diff --git a/src/http2_test.h b/src/http2_test.h index 382470d..75fd707 100644 --- a/src/http2_test.h +++ b/src/http2_test.h @@ -29,25 +29,31 @@ # include <config.h> #endif // HAVE_CONFIG_H +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + namespace shrpx { -void test_http2_add_header(void); -void test_http2_get_header(void); -void test_http2_copy_headers_to_nva(void); -void test_http2_build_http1_headers_from_headers(void); -void test_http2_lws(void); -void test_http2_rewrite_location_uri(void); -void test_http2_parse_http_status_code(void); -void test_http2_index_header(void); -void test_http2_lookup_token(void); -void test_http2_parse_link_header(void); -void test_http2_path_join(void); -void test_http2_normalize_path(void); -void test_http2_rewrite_clean_path(void); -void test_http2_get_pure_path_component(void); -void test_http2_construct_push_component(void); -void test_http2_contains_trailers(void); -void test_http2_check_transfer_encoding(void); +extern const MunitSuite http2_suite; + +munit_void_test_decl(test_http2_add_header); +munit_void_test_decl(test_http2_get_header); +munit_void_test_decl(test_http2_copy_headers_to_nva); +munit_void_test_decl(test_http2_build_http1_headers_from_headers); +munit_void_test_decl(test_http2_lws); +munit_void_test_decl(test_http2_rewrite_location_uri); +munit_void_test_decl(test_http2_parse_http_status_code); +munit_void_test_decl(test_http2_index_header); +munit_void_test_decl(test_http2_lookup_token); +munit_void_test_decl(test_http2_parse_link_header); +munit_void_test_decl(test_http2_path_join); +munit_void_test_decl(test_http2_normalize_path); +munit_void_test_decl(test_http2_rewrite_clean_path); +munit_void_test_decl(test_http2_get_pure_path_component); +munit_void_test_decl(test_http2_construct_push_component); +munit_void_test_decl(test_http2_contains_trailers); +munit_void_test_decl(test_http2_check_transfer_encoding); } // namespace shrpx diff --git a/src/inflatehd.cc b/src/inflatehd.cc index f484042..537b4fa 100644 --- a/src/inflatehd.cc +++ b/src/inflatehd.cc @@ -41,6 +41,7 @@ #include <jansson.h> +#define NGHTTP2_NO_SSIZE_T #include <nghttp2/nghttp2.h> #include "template.h" @@ -93,7 +94,6 @@ static void to_json(nghttp2_hd_inflater *inflater, json_t *headers, } static int inflate_hd(json_t *obj, nghttp2_hd_inflater *inflater, int seq) { - ssize_t rv; nghttp2_nv nv; int inflate_flags; size_t old_settings_table_size = @@ -120,8 +120,8 @@ static int inflate_hd(json_t *obj, nghttp2_hd_inflater *inflater, int seq) { seq); return -1; } - rv = nghttp2_hd_inflate_change_table_size(inflater, - json_integer_value(table_size)); + auto rv = nghttp2_hd_inflate_change_table_size( + inflater, json_integer_value(table_size)); if (rv != 0) { fprintf(stderr, "nghttp2_hd_change_table_size() failed with error %s at %d\n", @@ -147,7 +147,8 @@ static int inflate_hd(json_t *obj, nghttp2_hd_inflater *inflater, int seq) { auto p = buf.data(); for (;;) { inflate_flags = 0; - rv = nghttp2_hd_inflate_hd(inflater, &nv, &inflate_flags, p, buflen, 1); + auto rv = + nghttp2_hd_inflate_hd3(inflater, &nv, &inflate_flags, p, buflen, 1); if (rv < 0) { fprintf(stderr, "inflate failed with error code %zd at %d\n", rv, seq); exit(EXIT_FAILURE); diff --git a/src/libevent_util.cc b/src/libevent_util.cc deleted file mode 100644 index 3b60b6d..0000000 --- a/src/libevent_util.cc +++ /dev/null @@ -1,162 +0,0 @@ -/* - * nghttp2 - HTTP/2 C Library - * - * Copyright (c) 2014 Tatsuhiro Tsujikawa - * - * 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 "libevent_util.h" - -#include <cstring> -#include <algorithm> - -namespace nghttp2 { - -namespace util { - -EvbufferBuffer::EvbufferBuffer() - : evbuffer_(nullptr), - bucket_(nullptr), - buf_(nullptr), - bufmax_(0), - buflen_(0), - limit_(0), - writelen_(0) {} - -EvbufferBuffer::EvbufferBuffer(evbuffer *evbuffer, uint8_t *buf, size_t bufmax, - ssize_t limit) - : evbuffer_(evbuffer), - bucket_(limit == -1 ? nullptr : evbuffer_new()), - buf_(buf), - bufmax_(bufmax), - buflen_(0), - limit_(limit), - writelen_(0) {} - -void EvbufferBuffer::reset(evbuffer *evbuffer, uint8_t *buf, size_t bufmax, - ssize_t limit) { - evbuffer_ = evbuffer; - buf_ = buf; - if (limit != -1 && !bucket_) { - bucket_ = evbuffer_new(); - } - bufmax_ = bufmax; - buflen_ = 0; - limit_ = limit; - writelen_ = 0; -} - -EvbufferBuffer::~EvbufferBuffer() { - if (bucket_) { - evbuffer_free(bucket_); - } -} - -int EvbufferBuffer::write_buffer() { - for (auto pos = buf_, end = buf_ + buflen_; pos < end;) { - // To avoid merging chunks in evbuffer, we first add to temporal - // buffer bucket_ and then move its chain to evbuffer_. - auto nwrite = std::min(end - pos, limit_); - auto rv = evbuffer_add(bucket_, pos, nwrite); - if (rv == -1) { - return -1; - } - rv = evbuffer_add_buffer(evbuffer_, bucket_); - if (rv == -1) { - return -1; - } - pos += nwrite; - } - return 0; -} - -int EvbufferBuffer::flush() { - int rv; - if (buflen_ > 0) { - if (limit_ == -1) { - rv = evbuffer_add(evbuffer_, buf_, buflen_); - } else { - rv = write_buffer(); - } - if (rv == -1) { - return -1; - } - writelen_ += buflen_; - buflen_ = 0; - } - return 0; -} - -int EvbufferBuffer::add(const uint8_t *data, size_t datalen) { - int rv; - if (buflen_ + datalen > bufmax_) { - if (buflen_ > 0) { - if (limit_ == -1) { - rv = evbuffer_add(evbuffer_, buf_, buflen_); - } else { - rv = write_buffer(); - } - if (rv == -1) { - return -1; - } - writelen_ += buflen_; - buflen_ = 0; - } - if (datalen > bufmax_) { - if (limit_ == -1) { - rv = evbuffer_add(evbuffer_, data, datalen); - } else { - rv = write_buffer(); - } - if (rv == -1) { - return -1; - } - writelen_ += buflen_; - return 0; - } - } - memcpy(buf_ + buflen_, data, datalen); - buflen_ += datalen; - return 0; -} - -size_t EvbufferBuffer::get_buflen() const { return buflen_; } - -size_t EvbufferBuffer::get_writelen() const { return writelen_; } - -void bev_enable_unless(bufferevent *bev, int events) { - if ((bufferevent_get_enabled(bev) & events) == events) { - return; - } - - bufferevent_enable(bev, events); -} - -void bev_disable_unless(bufferevent *bev, int events) { - if ((bufferevent_get_enabled(bev) & events) == 0) { - return; - } - - bufferevent_disable(bev, events); -} - -} // namespace util - -} // namespace nghttp2 diff --git a/src/libevent_util.h b/src/libevent_util.h deleted file mode 100644 index 1d1ee91..0000000 --- a/src/libevent_util.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * nghttp2 - HTTP/2 C Library - * - * Copyright (c) 2014 Tatsuhiro Tsujikawa - * - * 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 LIBEVENT_UTIL_H -#define LIBEVENT_UTIL_H - -#include "nghttp2_config.h" - -#include <event2/buffer.h> -#include <event2/bufferevent.h> - -namespace nghttp2 { - -namespace util { - -class EvbufferBuffer { -public: - EvbufferBuffer(); - // If |limit| is not -1, at most min(limit, bufmax) size bytes are - // added to evbuffer_. - EvbufferBuffer(evbuffer *evbuffer, uint8_t *buf, size_t bufmax, - ssize_t limit = -1); - ~EvbufferBuffer(); - void reset(evbuffer *evbuffer, uint8_t *buf, size_t bufmax, - ssize_t limit = -1); - int flush(); - int add(const uint8_t *data, size_t datalen); - size_t get_buflen() const; - int write_buffer(); - // Returns the number of written bytes to evbuffer_ so far. reset() - // resets this value to 0. - size_t get_writelen() const; - -private: - evbuffer *evbuffer_; - evbuffer *bucket_; - uint8_t *buf_; - size_t bufmax_; - size_t buflen_; - ssize_t limit_; - size_t writelen_; -}; - -// These functions are provided to reduce epoll_ctl syscall. Avoid -// calling bufferevent_enable/disable() unless it is required by -// sniffing current enabled events. -void bev_enable_unless(bufferevent *bev, int events); -void bev_disable_unless(bufferevent *bev, int events); - -} // namespace util - -} // namespace nghttp2 - -#endif // LIBEVENT_UTIL_H diff --git a/src/memchunk_test.cc b/src/memchunk_test.cc index 236d9ea..1c57c02 100644 --- a/src/memchunk_test.cc +++ b/src/memchunk_test.cc @@ -24,7 +24,7 @@ */ #include "memchunk_test.h" -#include <CUnit/CUnit.h> +#include "munitxx.h" #include <nghttp2/nghttp2.h> @@ -33,52 +33,72 @@ namespace nghttp2 { +namespace { +const MunitTest tests[]{ + munit_void_test(test_pool_recycle), + munit_void_test(test_memchunks_append), + munit_void_test(test_memchunks_drain), + munit_void_test(test_memchunks_riovec), + munit_void_test(test_memchunks_recycle), + munit_void_test(test_memchunks_reset), + munit_void_test(test_peek_memchunks_append), + munit_void_test(test_peek_memchunks_disable_peek_drain), + munit_void_test(test_peek_memchunks_disable_peek_no_drain), + munit_void_test(test_peek_memchunks_reset), + munit_test_end(), +}; +} // namespace + +const MunitSuite memchunk_suite{ + "/memchunk", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_pool_recycle(void) { MemchunkPool pool; - CU_ASSERT(!pool.pool); - CU_ASSERT(0 == pool.poolsize); - CU_ASSERT(nullptr == pool.freelist); + assert_null(pool.pool); + assert_size(0, ==, pool.poolsize); + assert_null(pool.freelist); auto m1 = pool.get(); - CU_ASSERT(m1 == pool.pool); - CU_ASSERT(MemchunkPool::value_type::size == pool.poolsize); - CU_ASSERT(nullptr == pool.freelist); + assert_ptr_equal(m1, pool.pool); + assert_size(MemchunkPool::value_type::size, ==, pool.poolsize); + assert_null(pool.freelist); auto m2 = pool.get(); - CU_ASSERT(m2 == pool.pool); - CU_ASSERT(2 * MemchunkPool::value_type::size == pool.poolsize); - CU_ASSERT(nullptr == pool.freelist); - CU_ASSERT(m1 == m2->knext); - CU_ASSERT(nullptr == m1->knext); + assert_ptr_equal(m2, pool.pool); + assert_size(2 * MemchunkPool::value_type::size, ==, pool.poolsize); + assert_null(pool.freelist); + assert_ptr_equal(m1, m2->knext); + assert_null(m1->knext); auto m3 = pool.get(); - CU_ASSERT(m3 == pool.pool); - CU_ASSERT(3 * MemchunkPool::value_type::size == pool.poolsize); - CU_ASSERT(nullptr == pool.freelist); + assert_ptr_equal(m3, pool.pool); + assert_size(3 * MemchunkPool::value_type::size, ==, pool.poolsize); + assert_null(pool.freelist); pool.recycle(m3); - CU_ASSERT(m3 == pool.pool); - CU_ASSERT(3 * MemchunkPool::value_type::size == pool.poolsize); - CU_ASSERT(m3 == pool.freelist); + assert_ptr_equal(m3, pool.pool); + assert_size(3 * MemchunkPool::value_type::size, ==, pool.poolsize); + assert_ptr_equal(m3, pool.freelist); auto m4 = pool.get(); - CU_ASSERT(m3 == m4); - CU_ASSERT(m4 == pool.pool); - CU_ASSERT(3 * MemchunkPool::value_type::size == pool.poolsize); - CU_ASSERT(nullptr == pool.freelist); + assert_ptr_equal(m3, m4); + assert_ptr_equal(m4, pool.pool); + assert_size(3 * MemchunkPool::value_type::size, ==, pool.poolsize); + assert_null(pool.freelist); pool.recycle(m2); pool.recycle(m1); - CU_ASSERT(m1 == pool.freelist); - CU_ASSERT(m2 == m1->next); - CU_ASSERT(nullptr == m2->next); + assert_ptr_equal(m1, pool.freelist); + assert_ptr_equal(m2, m1->next); + assert_null(m2->next); } using Memchunk16 = Memchunk<16>; @@ -94,37 +114,37 @@ void test_memchunks_append(void) { auto m = chunks.tail; - CU_ASSERT(3 == m->len()); - CU_ASSERT(13 == m->left()); + assert_size(3, ==, m->len()); + assert_size(13, ==, m->left()); chunks.append("3456789abcdef@"); - CU_ASSERT(16 == m->len()); - CU_ASSERT(0 == m->left()); + assert_size(16, ==, m->len()); + assert_size(0, ==, m->left()); m = chunks.tail; - CU_ASSERT(1 == m->len()); - CU_ASSERT(15 == m->left()); - CU_ASSERT(17 == chunks.rleft()); + assert_size(1, ==, m->len()); + assert_size(15, ==, m->left()); + assert_size(17, ==, chunks.rleft()); char buf[16]; size_t nread; nread = chunks.remove(buf, 8); - CU_ASSERT(8 == nread); - CU_ASSERT(0 == memcmp("01234567", buf, nread)); - CU_ASSERT(9 == chunks.rleft()); + assert_size(8, ==, nread); + assert_memory_equal(nread, "01234567", buf); + assert_size(9, ==, chunks.rleft()); nread = chunks.remove(buf, sizeof(buf)); - CU_ASSERT(9 == nread); - CU_ASSERT(0 == memcmp("89abcdef@", buf, nread)); - CU_ASSERT(0 == chunks.rleft()); - CU_ASSERT(nullptr == chunks.head); - CU_ASSERT(nullptr == chunks.tail); - CU_ASSERT(32 == pool.poolsize); + assert_size(9, ==, nread); + assert_memory_equal(nread, "89abcdef@", buf); + assert_size(0, ==, chunks.rleft()); + assert_null(chunks.head); + assert_null(chunks.tail); + assert_size(32, ==, pool.poolsize); } void test_memchunks_drain(void) { @@ -137,14 +157,14 @@ void test_memchunks_drain(void) { nread = chunks.drain(3); - CU_ASSERT(3 == nread); + assert_size(3, ==, nread); char buf[16]; nread = chunks.remove(buf, sizeof(buf)); - CU_ASSERT(7 == nread); - CU_ASSERT(0 == memcmp("3456789", buf, nread)); + assert_size(7, ==, nread); + assert_memory_equal(nread, "3456789", buf); } void test_memchunks_riovec(void) { @@ -160,24 +180,24 @@ void test_memchunks_riovec(void) { auto m = chunks.head; - CU_ASSERT(2 == iovcnt); - CU_ASSERT(m->buf.data() == iov[0].iov_base); - CU_ASSERT(m->len() == iov[0].iov_len); + assert_int(2, ==, iovcnt); + assert_ptr_equal(m->buf.data(), iov[0].iov_base); + assert_size(m->len(), ==, iov[0].iov_len); m = m->next; - CU_ASSERT(m->buf.data() == iov[1].iov_base); - CU_ASSERT(m->len() == iov[1].iov_len); + assert_ptr_equal(m->buf.data(), iov[1].iov_base); + assert_size(m->len(), ==, iov[1].iov_len); chunks.drain(2 * 16); iovcnt = chunks.riovec(iov.data(), iov.size()); - CU_ASSERT(1 == iovcnt); + assert_int(1, ==, iovcnt); m = chunks.head; - CU_ASSERT(m->buf.data() == iov[0].iov_base); - CU_ASSERT(m->len() == iov[0].iov_len); + assert_ptr_equal(m->buf.data(), iov[0].iov_base); + assert_size(m->len(), ==, iov[0].iov_len); } void test_memchunks_recycle(void) { @@ -187,14 +207,14 @@ void test_memchunks_recycle(void) { std::array<char, 32> buf{}; chunks.append(buf.data(), buf.size()); } - CU_ASSERT(32 == pool.poolsize); - CU_ASSERT(nullptr != pool.freelist); + assert_size(32, ==, pool.poolsize); + assert_not_null(pool.freelist); auto m = pool.freelist; m = m->next; - CU_ASSERT(nullptr != m); - CU_ASSERT(nullptr == m->next); + assert_not_null(m); + assert_null(m->next); } void test_memchunks_reset(void) { @@ -205,19 +225,19 @@ void test_memchunks_reset(void) { chunks.append(b.data(), b.size()); - CU_ASSERT(32 == chunks.rleft()); + assert_size(32, ==, chunks.rleft()); chunks.reset(); - CU_ASSERT(0 == chunks.rleft()); - CU_ASSERT(nullptr == chunks.head); - CU_ASSERT(nullptr == chunks.tail); + assert_size(0, ==, chunks.rleft()); + assert_null(chunks.head); + assert_null(chunks.tail); auto m = pool.freelist; - CU_ASSERT(nullptr != m); - CU_ASSERT(nullptr != m->next); - CU_ASSERT(nullptr == m->next->next); + assert_not_null(m); + assert_not_null(m->next); + assert_null(m->next->next); } void test_peek_memchunks_append(void) { @@ -232,27 +252,27 @@ void test_peek_memchunks_append(void) { pchunks.append(b.data(), b.size()); - CU_ASSERT(32 == pchunks.rleft()); - CU_ASSERT(32 == pchunks.rleft_buffered()); + assert_size(32, ==, pchunks.rleft()); + assert_size(32, ==, pchunks.rleft_buffered()); - CU_ASSERT(0 == pchunks.remove(nullptr, 0)); + assert_size(0, ==, pchunks.remove(nullptr, 0)); - CU_ASSERT(32 == pchunks.rleft()); - CU_ASSERT(32 == pchunks.rleft_buffered()); + assert_size(32, ==, pchunks.rleft()); + assert_size(32, ==, pchunks.rleft_buffered()); - CU_ASSERT(12 == pchunks.remove(d.data(), 12)); + assert_size(12, ==, pchunks.remove(d.data(), 12)); - CU_ASSERT(std::equal(std::begin(b), std::begin(b) + 12, std::begin(d))); + assert_true(std::equal(std::begin(b), std::begin(b) + 12, std::begin(d))); - CU_ASSERT(20 == pchunks.rleft()); - CU_ASSERT(32 == pchunks.rleft_buffered()); + assert_size(20, ==, pchunks.rleft()); + assert_size(32, ==, pchunks.rleft_buffered()); - CU_ASSERT(20 == pchunks.remove(d.data(), d.size())); + assert_size(20, ==, pchunks.remove(d.data(), d.size())); - CU_ASSERT(std::equal(std::begin(b) + 12, std::end(b), std::begin(d))); + assert_true(std::equal(std::begin(b) + 12, std::end(b), std::begin(d))); - CU_ASSERT(0 == pchunks.rleft()); - CU_ASSERT(32 == pchunks.rleft_buffered()); + assert_size(0, ==, pchunks.rleft()); + assert_size(32, ==, pchunks.rleft_buffered()); } void test_peek_memchunks_disable_peek_drain(void) { @@ -267,20 +287,20 @@ void test_peek_memchunks_disable_peek_drain(void) { pchunks.append(b.data(), b.size()); - CU_ASSERT(12 == pchunks.remove(d.data(), 12)); + assert_size(12, ==, pchunks.remove(d.data(), 12)); pchunks.disable_peek(true); - CU_ASSERT(!pchunks.peeking); - CU_ASSERT(20 == pchunks.rleft()); - CU_ASSERT(20 == pchunks.rleft_buffered()); + assert_false(pchunks.peeking); + assert_size(20, ==, pchunks.rleft()); + assert_size(20, ==, pchunks.rleft_buffered()); - CU_ASSERT(20 == pchunks.remove(d.data(), d.size())); + assert_size(20, ==, pchunks.remove(d.data(), d.size())); - CU_ASSERT(std::equal(std::begin(b) + 12, std::end(b), std::begin(d))); + assert_true(std::equal(std::begin(b) + 12, std::end(b), std::begin(d))); - CU_ASSERT(0 == pchunks.rleft()); - CU_ASSERT(0 == pchunks.rleft_buffered()); + assert_size(0, ==, pchunks.rleft()); + assert_size(0, ==, pchunks.rleft_buffered()); } void test_peek_memchunks_disable_peek_no_drain(void) { @@ -295,20 +315,20 @@ void test_peek_memchunks_disable_peek_no_drain(void) { pchunks.append(b.data(), b.size()); - CU_ASSERT(12 == pchunks.remove(d.data(), 12)); + assert_size(12, ==, pchunks.remove(d.data(), 12)); pchunks.disable_peek(false); - CU_ASSERT(!pchunks.peeking); - CU_ASSERT(32 == pchunks.rleft()); - CU_ASSERT(32 == pchunks.rleft_buffered()); + assert_false(pchunks.peeking); + assert_size(32, ==, pchunks.rleft()); + assert_size(32, ==, pchunks.rleft_buffered()); - CU_ASSERT(32 == pchunks.remove(d.data(), d.size())); + assert_size(32, ==, pchunks.remove(d.data(), d.size())); - CU_ASSERT(std::equal(std::begin(b), std::end(b), std::begin(d))); + assert_true(std::equal(std::begin(b), std::end(b), std::begin(d))); - CU_ASSERT(0 == pchunks.rleft()); - CU_ASSERT(0 == pchunks.rleft_buffered()); + assert_size(0, ==, pchunks.rleft()); + assert_size(0, ==, pchunks.rleft_buffered()); } void test_peek_memchunks_reset(void) { @@ -323,18 +343,18 @@ void test_peek_memchunks_reset(void) { pchunks.append(b.data(), b.size()); - CU_ASSERT(12 == pchunks.remove(d.data(), 12)); + assert_size(12, ==, pchunks.remove(d.data(), 12)); pchunks.disable_peek(true); pchunks.reset(); - CU_ASSERT(0 == pchunks.rleft()); - CU_ASSERT(0 == pchunks.rleft_buffered()); + assert_size(0, ==, pchunks.rleft()); + assert_size(0, ==, pchunks.rleft_buffered()); - CU_ASSERT(nullptr == pchunks.cur); - CU_ASSERT(nullptr == pchunks.cur_pos); - CU_ASSERT(nullptr == pchunks.cur_last); - CU_ASSERT(pchunks.peeking); + assert_null(pchunks.cur); + assert_null(pchunks.cur_pos); + assert_null(pchunks.cur_last); + assert_true(pchunks.peeking); } } // namespace nghttp2 diff --git a/src/memchunk_test.h b/src/memchunk_test.h index 7d677e7..a3fe028 100644 --- a/src/memchunk_test.h +++ b/src/memchunk_test.h @@ -29,18 +29,24 @@ # include <config.h> #endif // HAVE_CONFIG_H +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + namespace nghttp2 { -void test_pool_recycle(void); -void test_memchunks_append(void); -void test_memchunks_drain(void); -void test_memchunks_riovec(void); -void test_memchunks_recycle(void); -void test_memchunks_reset(void); -void test_peek_memchunks_append(void); -void test_peek_memchunks_disable_peek_drain(void); -void test_peek_memchunks_disable_peek_no_drain(void); -void test_peek_memchunks_reset(void); +extern const MunitSuite memchunk_suite; + +munit_void_test_decl(test_pool_recycle); +munit_void_test_decl(test_memchunks_append); +munit_void_test_decl(test_memchunks_drain); +munit_void_test_decl(test_memchunks_riovec); +munit_void_test_decl(test_memchunks_recycle); +munit_void_test_decl(test_memchunks_reset); +munit_void_test_decl(test_peek_memchunks_append); +munit_void_test_decl(test_peek_memchunks_disable_peek_drain); +munit_void_test_decl(test_peek_memchunks_disable_peek_no_drain); +munit_void_test_decl(test_peek_memchunks_reset); } // namespace nghttp2 diff --git a/src/nghttp.cc b/src/nghttp.cc index 41a88c6..f670320 100644 --- a/src/nghttp.cc +++ b/src/nghttp.cc @@ -157,7 +157,7 @@ std::string strip_fragment(const char *raw_uri) { } // namespace Request::Request(const std::string &uri, const http_parser_url &u, - const nghttp2_data_provider *data_prd, int64_t data_length, + const nghttp2_data_provider2 *data_prd, int64_t data_length, const nghttp2_priority_spec &pri_spec, int level) : uri(uri), u(u), @@ -370,11 +370,11 @@ void continue_timeout_cb(struct ev_loop *loop, ev_timer *w, int revents) { auto req = static_cast<Request *>(w->data); int error; - error = nghttp2_submit_data(client->session, NGHTTP2_FLAG_END_STREAM, - req->stream_id, req->data_prd); + error = nghttp2_submit_data2(client->session, NGHTTP2_FLAG_END_STREAM, + req->stream_id, req->data_prd); if (error) { - std::cerr << "[ERROR] nghttp2_submit_data() returned error: " + std::cerr << "[ERROR] nghttp2_submit_data2() returned error: " << nghttp2_strerror(error) << std::endl; nghttp2_submit_rst_stream(client->session, NGHTTP2_FLAG_NONE, req->stream_id, NGHTTP2_INTERNAL_ERROR); @@ -525,13 +525,13 @@ int submit_request(HttpClient *client, const Headers &headers, Request *req) { nva.data(), nva.size(), req); } else { stream_id = - nghttp2_submit_request(client->session, &req->pri_spec, nva.data(), - nva.size(), req->data_prd, req); + nghttp2_submit_request2(client->session, &req->pri_spec, nva.data(), + nva.size(), req->data_prd, req); } if (stream_id < 0) { std::cerr << "[ERROR] nghttp2_submit_" - << (expect_continue ? "headers" : "request") + << (expect_continue ? "headers" : "request2") << "() returned error: " << nghttp2_strerror(stream_id) << std::endl; return -1; @@ -953,14 +953,14 @@ size_t populate_settings(nghttp2_settings_entry *iv) { } // namespace int HttpClient::on_upgrade_connect() { - ssize_t rv; + nghttp2_ssize rv; record_connect_end_time(); assert(!reqvec.empty()); std::array<nghttp2_settings_entry, 16> iv; size_t niv = populate_settings(iv.data()); assert(settings_payload.size() >= 8 * niv); - rv = nghttp2_pack_settings_payload(settings_payload.data(), - settings_payload.size(), iv.data(), niv); + rv = nghttp2_pack_settings_payload2(settings_payload.data(), + settings_payload.size(), iv.data(), niv); if (rv < 0) { return -1; } @@ -1250,9 +1250,9 @@ int HttpClient::on_read(const uint8_t *data, size_t len) { util::hexdump(stdout, data, len); } - auto rv = nghttp2_session_mem_recv(session, data, len); + auto rv = nghttp2_session_mem_recv2(session, data, len); if (rv < 0) { - std::cerr << "[ERROR] nghttp2_session_mem_recv() returned error: " + std::cerr << "[ERROR] nghttp2_session_mem_recv2() returned error: " << nghttp2_strerror(rv) << std::endl; return -1; } @@ -1276,9 +1276,9 @@ int HttpClient::on_write() { } const uint8_t *data; - auto len = nghttp2_session_mem_send(session, &data); + auto len = nghttp2_session_mem_send2(session, &data); if (len < 0) { - std::cerr << "[ERROR] nghttp2_session_send() returned error: " + std::cerr << "[ERROR] nghttp2_session_send2() returned error: " << nghttp2_strerror(len) << std::endl; return -1; } @@ -1449,7 +1449,7 @@ void HttpClient::update_hostport() { } bool HttpClient::add_request(const std::string &uri, - const nghttp2_data_provider *data_prd, + const nghttp2_data_provider2 *data_prd, int64_t data_length, const nghttp2_priority_spec &pri_spec, int level) { http_parser_url u{}; @@ -1768,9 +1768,9 @@ int on_data_chunk_recv_callback(nghttp2_session *session, uint8_t flags, } // namespace namespace { -ssize_t select_padding_callback(nghttp2_session *session, - const nghttp2_frame *frame, size_t max_payload, - void *user_data) { +nghttp2_ssize select_padding_callback(nghttp2_session *session, + const nghttp2_frame *frame, + size_t max_payload, void *user_data) { return std::min(max_payload, frame->hd.length + config.padding); } } // namespace @@ -2241,7 +2241,7 @@ namespace { int communicate( const std::string &scheme, const std::string &host, uint16_t port, std::vector< - std::tuple<std::string, nghttp2_data_provider *, int64_t, int32_t>> + std::tuple<std::string, nghttp2_data_provider2 *, int64_t, int32_t>> requests, const nghttp2_session_callbacks *callbacks) { int result = 0; @@ -2311,6 +2311,17 @@ int communicate( auto proto_list = util::get_default_alpn(); SSL_CTX_set_alpn_protos(ssl_ctx, proto_list.data(), proto_list.size()); + +#if defined(NGHTTP2_OPENSSL_IS_BORINGSSL) && defined(HAVE_LIBBROTLI) + if (!SSL_CTX_add_cert_compression_alg( + ssl_ctx, nghttp2::tls::CERTIFICATE_COMPRESSION_ALGO_BROTLI, + nghttp2::tls::cert_compress, nghttp2::tls::cert_decompress)) { + std::cerr << "[ERROR] SSL_CTX_add_cert_compression_alg failed." + << std::endl; + result = -1; + goto fin; + } +#endif // NGHTTP2_OPENSSL_IS_BORINGSSL && HAVE_LIBBROTLI } { HttpClient client{callbacks, loop, ssl_ctx}; @@ -2391,9 +2402,10 @@ fin: } // namespace namespace { -ssize_t file_read_callback(nghttp2_session *session, int32_t stream_id, - uint8_t *buf, size_t length, uint32_t *data_flags, - nghttp2_data_source *source, void *user_data) { +nghttp2_ssize file_read_callback(nghttp2_session *session, int32_t stream_id, + uint8_t *buf, size_t length, + uint32_t *data_flags, + nghttp2_data_source *source, void *user_data) { int rv; auto req = static_cast<Request *>( nghttp2_session_get_stream_user_data(session, stream_id)); @@ -2429,14 +2441,14 @@ ssize_t file_read_callback(nghttp2_session *session, int32_t stream_id, } } - return nread; + return static_cast<nghttp2_ssize>(nread); } if (req->data_offset > req->data_length || nread == 0) { return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; } - return nread; + return static_cast<nghttp2_ssize>(nread); } } // namespace @@ -2480,7 +2492,7 @@ int run(char **uris, int n) { callbacks, on_frame_not_send_callback); if (config.padding) { - nghttp2_session_callbacks_set_select_padding_callback( + nghttp2_session_callbacks_set_select_padding_callback2( callbacks, select_padding_callback); } @@ -2489,7 +2501,7 @@ int run(char **uris, int n) { uint16_t prev_port = 0; int failures = 0; int data_fd = -1; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; struct stat data_stat; if (!config.datafile.empty()) { @@ -2557,7 +2569,7 @@ int run(char **uris, int n) { data_prd.read_callback = file_read_callback; } std::vector< - std::tuple<std::string, nghttp2_data_provider *, int64_t, int32_t>> + std::tuple<std::string, nghttp2_data_provider2 *, int64_t, int32_t>> requests; size_t next_weight_idx = 0; diff --git a/src/nghttp.h b/src/nghttp.h index a880414..5b339e8 100644 --- a/src/nghttp.h +++ b/src/nghttp.h @@ -45,6 +45,7 @@ #include <ev.h> +#define NGHTTP2_NO_SSIZE_T #include <nghttp2/nghttp2.h> #include "llhttp.h" @@ -77,7 +78,7 @@ struct Config { int64_t encoder_header_table_size; size_t padding; size_t max_concurrent_streams; - ssize_t peer_max_concurrent_streams; + size_t peer_max_concurrent_streams; int multiply; // milliseconds ev_tstamp timeout; @@ -137,7 +138,7 @@ struct ContinueTimer { struct Request { // For pushed request, |uri| is empty and |u| is zero-cleared. Request(const std::string &uri, const http_parser_url &u, - const nghttp2_data_provider *data_prd, int64_t data_length, + const nghttp2_data_provider2 *data_prd, int64_t data_length, const nghttp2_priority_spec &pri_spec, int level = 0); ~Request(); @@ -180,7 +181,7 @@ struct Request { int64_t response_len; nghttp2_gzip *inflater; std::unique_ptr<HtmlParser> html_parser; - const nghttp2_data_provider *data_prd; + const nghttp2_data_provider2 *data_prd; size_t header_buffer_size; int32_t stream_id; int status; @@ -246,7 +247,7 @@ struct HttpClient { bool all_requests_processed() const; void update_hostport(); bool add_request(const std::string &uri, - const nghttp2_data_provider *data_prd, int64_t data_length, + const nghttp2_data_provider2 *data_prd, int64_t data_length, const nghttp2_priority_spec &pri_spec, int level = 0); void record_start_time(); diff --git a/src/nghttp2_gzip_test.c b/src/nghttp2_gzip_test.c index de19d5d..9a36db0 100644 --- a/src/nghttp2_gzip_test.c +++ b/src/nghttp2_gzip_test.c @@ -27,26 +27,35 @@ #include <stdio.h> #include <assert.h> -#include <CUnit/CUnit.h> +#include "munit.h" #include <zlib.h> #include "nghttp2_gzip.h" +static const MunitTest tests[] = { + munit_void_test(test_nghttp2_gzip_inflate), + munit_test_end(), +}; + +const MunitSuite gzip_suite = { + "/gzip", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + static size_t deflate_data(uint8_t *out, size_t outlen, const uint8_t *in, size_t inlen) { int rv; z_stream zst = {0}; rv = deflateInit(&zst, Z_DEFAULT_COMPRESSION); - CU_ASSERT(rv == Z_OK); + assert_int(Z_OK, ==, rv); zst.avail_in = (unsigned int)inlen; zst.next_in = (uint8_t *)in; zst.avail_out = (unsigned int)outlen; zst.next_out = out; rv = deflate(&zst, Z_SYNC_FLUSH); - CU_ASSERT(rv == Z_OK); + assert_int(Z_OK, ==, rv); deflateEnd(&zst); @@ -71,41 +80,44 @@ void test_nghttp2_gzip_inflate(void) { inlen = deflate_data(in, inlen, (const uint8_t *)input, sizeof(input) - 1); - CU_ASSERT(0 == nghttp2_gzip_inflate_new(&inflater)); + assert_int(0, ==, nghttp2_gzip_inflate_new(&inflater)); /* First 16 bytes */ inptr = in; inproclen = inlen; outproclen = 16; - CU_ASSERT( - 0 == nghttp2_gzip_inflate(inflater, out, &outproclen, inptr, &inproclen)); - CU_ASSERT(16 == outproclen); - CU_ASSERT(inproclen > 0); - CU_ASSERT(0 == memcmp(inputptr, out, outproclen)); + assert_int( + 0, ==, + nghttp2_gzip_inflate(inflater, out, &outproclen, inptr, &inproclen)); + assert_size(16, ==, outproclen); + assert_size(0, <, inproclen); + assert_memory_equal(outproclen, inputptr, out); /* Next 32 bytes */ inptr += inproclen; inlen -= inproclen; inproclen = inlen; inputptr += outproclen; outproclen = 32; - CU_ASSERT( - 0 == nghttp2_gzip_inflate(inflater, out, &outproclen, inptr, &inproclen)); - CU_ASSERT(32 == outproclen); - CU_ASSERT(inproclen > 0); - CU_ASSERT(0 == memcmp(inputptr, out, outproclen)); + assert_int( + 0, ==, + nghttp2_gzip_inflate(inflater, out, &outproclen, inptr, &inproclen)); + assert_size(32, ==, outproclen); + assert_size(0, <, inproclen); + assert_memory_equal(outproclen, inputptr, out); /* Rest */ inptr += inproclen; inlen -= inproclen; inproclen = inlen; inputptr += outproclen; outproclen = sizeof(out); - CU_ASSERT( - 0 == nghttp2_gzip_inflate(inflater, out, &outproclen, inptr, &inproclen)); - CU_ASSERT(sizeof(input) - 49 == outproclen); - CU_ASSERT(inproclen > 0); - CU_ASSERT(0 == memcmp(inputptr, out, outproclen)); + assert_int( + 0, ==, + nghttp2_gzip_inflate(inflater, out, &outproclen, inptr, &inproclen)); + assert_size(sizeof(input) - 49, ==, outproclen); + assert_size(0, <, inproclen); + assert_memory_equal(outproclen, inputptr, out); inlen -= inproclen; - CU_ASSERT(0 == inlen); + assert_size(0, ==, inlen); nghttp2_gzip_inflate_del(inflater); } diff --git a/src/nghttp2_gzip_test.h b/src/nghttp2_gzip_test.h index 8d554f7..fa6938b 100644 --- a/src/nghttp2_gzip_test.h +++ b/src/nghttp2_gzip_test.h @@ -33,7 +33,13 @@ extern "C" { #endif -void test_nghttp2_gzip_inflate(void); +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + +extern const MunitSuite gzip_suite; + +munit_void_test_decl(test_nghttp2_gzip_inflate); #ifdef __cplusplus } diff --git a/src/shrpx-unittest.cc b/src/shrpx-unittest.cc index f089adf..ec707e5 100644 --- a/src/shrpx-unittest.cc +++ b/src/shrpx-unittest.cc @@ -26,9 +26,8 @@ # include <config.h> #endif // HAVE_CONFIG_H -#include <stdio.h> -#include <string.h> -#include <CUnit/Basic.h> +#include "munit.h" + // include test cases' include files here #include "shrpx_tls_test.h" #include "shrpx_downstream_test.h" @@ -47,200 +46,21 @@ #include "shrpx_router_test.h" #include "shrpx_log.h" -static int init_suite1(void) { return 0; } - -static int clean_suite1(void) { return 0; } - int main(int argc, char *argv[]) { - CU_pSuite pSuite = nullptr; - unsigned int num_tests_failed; - shrpx::create_config(); - // initialize the CUnit test registry - if (CUE_SUCCESS != CU_initialize_registry()) - return CU_get_error(); - - // add a suite to the registry - pSuite = CU_add_suite("shrpx_TestSuite", init_suite1, clean_suite1); - if (nullptr == pSuite) { - CU_cleanup_registry(); - return CU_get_error(); - } - - // add the tests to the suite - if (!CU_add_test(pSuite, "tls_create_lookup_tree", - shrpx::test_shrpx_tls_create_lookup_tree) || - !CU_add_test(pSuite, "tls_cert_lookup_tree_add_ssl_ctx", - shrpx::test_shrpx_tls_cert_lookup_tree_add_ssl_ctx) || - !CU_add_test(pSuite, "tls_tls_hostname_match", - shrpx::test_shrpx_tls_tls_hostname_match) || - !CU_add_test(pSuite, "tls_tls_verify_numeric_hostname", - shrpx::test_shrpx_tls_verify_numeric_hostname) || - !CU_add_test(pSuite, "tls_tls_verify_dns_hostname", - shrpx::test_shrpx_tls_verify_dns_hostname) || - !CU_add_test(pSuite, "http2_add_header", shrpx::test_http2_add_header) || - !CU_add_test(pSuite, "http2_get_header", shrpx::test_http2_get_header) || - !CU_add_test(pSuite, "http2_copy_headers_to_nva", - shrpx::test_http2_copy_headers_to_nva) || - !CU_add_test(pSuite, "http2_build_http1_headers_from_headers", - shrpx::test_http2_build_http1_headers_from_headers) || - !CU_add_test(pSuite, "http2_lws", shrpx::test_http2_lws) || - !CU_add_test(pSuite, "http2_rewrite_location_uri", - shrpx::test_http2_rewrite_location_uri) || - !CU_add_test(pSuite, "http2_parse_http_status_code", - shrpx::test_http2_parse_http_status_code) || - !CU_add_test(pSuite, "http2_index_header", - shrpx::test_http2_index_header) || - !CU_add_test(pSuite, "http2_lookup_token", - shrpx::test_http2_lookup_token) || - !CU_add_test(pSuite, "http2_parse_link_header", - shrpx::test_http2_parse_link_header) || - !CU_add_test(pSuite, "http2_path_join", shrpx::test_http2_path_join) || - !CU_add_test(pSuite, "http2_normalize_path", - shrpx::test_http2_normalize_path) || - !CU_add_test(pSuite, "http2_rewrite_clean_path", - shrpx::test_http2_rewrite_clean_path) || - !CU_add_test(pSuite, "http2_get_pure_path_component", - shrpx::test_http2_get_pure_path_component) || - !CU_add_test(pSuite, "http2_construct_push_component", - shrpx::test_http2_construct_push_component) || - !CU_add_test(pSuite, "http2_contains_trailers", - shrpx::test_http2_contains_trailers) || - !CU_add_test(pSuite, "http2_check_transfer_encoding", - shrpx::test_http2_check_transfer_encoding) || - !CU_add_test(pSuite, "downstream_field_store_append_last_header", - shrpx::test_downstream_field_store_append_last_header) || - !CU_add_test(pSuite, "downstream_field_store_header", - shrpx::test_downstream_field_store_header) || - !CU_add_test(pSuite, "downstream_crumble_request_cookie", - shrpx::test_downstream_crumble_request_cookie) || - !CU_add_test(pSuite, "downstream_assemble_request_cookie", - shrpx::test_downstream_assemble_request_cookie) || - !CU_add_test(pSuite, "downstream_rewrite_location_response_header", - shrpx::test_downstream_rewrite_location_response_header) || - !CU_add_test(pSuite, "downstream_supports_non_final_response", - shrpx::test_downstream_supports_non_final_response) || - !CU_add_test(pSuite, "downstream_find_affinity_cookie", - shrpx::test_downstream_find_affinity_cookie) || - !CU_add_test(pSuite, "config_parse_header", - shrpx::test_shrpx_config_parse_header) || - !CU_add_test(pSuite, "config_parse_log_format", - shrpx::test_shrpx_config_parse_log_format) || - !CU_add_test(pSuite, "config_read_tls_ticket_key_file", - shrpx::test_shrpx_config_read_tls_ticket_key_file) || - !CU_add_test(pSuite, "config_read_tls_ticket_key_file_aes_256", - shrpx::test_shrpx_config_read_tls_ticket_key_file_aes_256) || - !CU_add_test(pSuite, "worker_match_downstream_addr_group", - shrpx::test_shrpx_worker_match_downstream_addr_group) || - !CU_add_test(pSuite, "http_create_forwarded", - shrpx::test_shrpx_http_create_forwarded) || - !CU_add_test(pSuite, "http_create_via_header_value", - shrpx::test_shrpx_http_create_via_header_value) || - !CU_add_test(pSuite, "http_create_affinity_cookie", - shrpx::test_shrpx_http_create_affinity_cookie) || - !CU_add_test(pSuite, "http_create_atlsvc_header_field_value", - shrpx::test_shrpx_http_create_altsvc_header_value) || - !CU_add_test(pSuite, "http_check_http_scheme", - shrpx::test_shrpx_http_check_http_scheme) || - !CU_add_test(pSuite, "router_match", shrpx::test_shrpx_router_match) || - !CU_add_test(pSuite, "router_match_wildcard", - shrpx::test_shrpx_router_match_wildcard) || - !CU_add_test(pSuite, "router_match_prefix", - shrpx::test_shrpx_router_match_prefix) || - !CU_add_test(pSuite, "util_streq", shrpx::test_util_streq) || - !CU_add_test(pSuite, "util_strieq", shrpx::test_util_strieq) || - !CU_add_test(pSuite, "util_inp_strlower", - shrpx::test_util_inp_strlower) || - !CU_add_test(pSuite, "util_to_base64", shrpx::test_util_to_base64) || - !CU_add_test(pSuite, "util_to_token68", shrpx::test_util_to_token68) || - !CU_add_test(pSuite, "util_percent_encode_token", - shrpx::test_util_percent_encode_token) || - !CU_add_test(pSuite, "util_percent_decode", - shrpx::test_util_percent_decode) || - !CU_add_test(pSuite, "util_quote_string", - shrpx::test_util_quote_string) || - !CU_add_test(pSuite, "util_utox", shrpx::test_util_utox) || - !CU_add_test(pSuite, "util_http_date", shrpx::test_util_http_date) || - !CU_add_test(pSuite, "util_select_h2", shrpx::test_util_select_h2) || - !CU_add_test(pSuite, "util_ipv6_numeric_addr", - shrpx::test_util_ipv6_numeric_addr) || - !CU_add_test(pSuite, "util_utos", shrpx::test_util_utos) || - !CU_add_test(pSuite, "util_make_string_ref_uint", - shrpx::test_util_make_string_ref_uint) || - !CU_add_test(pSuite, "util_utos_unit", shrpx::test_util_utos_unit) || - !CU_add_test(pSuite, "util_utos_funit", shrpx::test_util_utos_funit) || - !CU_add_test(pSuite, "util_parse_uint_with_unit", - shrpx::test_util_parse_uint_with_unit) || - !CU_add_test(pSuite, "util_parse_uint", shrpx::test_util_parse_uint) || - !CU_add_test(pSuite, "util_parse_duration_with_unit", - shrpx::test_util_parse_duration_with_unit) || - !CU_add_test(pSuite, "util_duration_str", - shrpx::test_util_duration_str) || - !CU_add_test(pSuite, "util_format_duration", - shrpx::test_util_format_duration) || - !CU_add_test(pSuite, "util_starts_with", shrpx::test_util_starts_with) || - !CU_add_test(pSuite, "util_ends_with", shrpx::test_util_ends_with) || - !CU_add_test(pSuite, "util_parse_http_date", - shrpx::test_util_parse_http_date) || - !CU_add_test(pSuite, "util_localtime_date", - shrpx::test_util_localtime_date) || - !CU_add_test(pSuite, "util_get_uint64", shrpx::test_util_get_uint64) || - !CU_add_test(pSuite, "util_parse_config_str_list", - shrpx::test_util_parse_config_str_list) || - !CU_add_test(pSuite, "util_make_http_hostport", - shrpx::test_util_make_http_hostport) || - !CU_add_test(pSuite, "util_make_hostport", - shrpx::test_util_make_hostport) || - !CU_add_test(pSuite, "util_strifind", shrpx::test_util_strifind) || - !CU_add_test(pSuite, "util_random_alpha_digit", - shrpx::test_util_random_alpha_digit) || - !CU_add_test(pSuite, "util_format_hex", shrpx::test_util_format_hex) || - !CU_add_test(pSuite, "util_is_hex_string", - shrpx::test_util_is_hex_string) || - !CU_add_test(pSuite, "util_decode_hex", shrpx::test_util_decode_hex) || - !CU_add_test(pSuite, "util_extract_host", - shrpx::test_util_extract_host) || - !CU_add_test(pSuite, "util_split_hostport", - shrpx::test_util_split_hostport) || - !CU_add_test(pSuite, "util_split_str", shrpx::test_util_split_str) || - !CU_add_test(pSuite, "util_rstrip", shrpx::test_util_rstrip) || - !CU_add_test(pSuite, "gzip_inflate", test_nghttp2_gzip_inflate) || - !CU_add_test(pSuite, "buffer_write", nghttp2::test_buffer_write) || - !CU_add_test(pSuite, "pool_recycle", nghttp2::test_pool_recycle) || - !CU_add_test(pSuite, "memchunk_append", nghttp2::test_memchunks_append) || - !CU_add_test(pSuite, "memchunk_drain", nghttp2::test_memchunks_drain) || - !CU_add_test(pSuite, "memchunk_riovec", nghttp2::test_memchunks_riovec) || - !CU_add_test(pSuite, "memchunk_recycle", - nghttp2::test_memchunks_recycle) || - !CU_add_test(pSuite, "memchunk_reset", nghttp2::test_memchunks_reset) || - !CU_add_test(pSuite, "peek_memchunk_append", - nghttp2::test_peek_memchunks_append) || - !CU_add_test(pSuite, "peek_memchunk_disable_peek_drain", - nghttp2::test_peek_memchunks_disable_peek_drain) || - !CU_add_test(pSuite, "peek_memchunk_disable_peek_no_drain", - nghttp2::test_peek_memchunks_disable_peek_no_drain) || - !CU_add_test(pSuite, "peek_memchunk_reset", - nghttp2::test_peek_memchunks_reset) || - !CU_add_test(pSuite, "template_immutable_string", - nghttp2::test_template_immutable_string) || - !CU_add_test(pSuite, "template_string_ref", - nghttp2::test_template_string_ref) || - !CU_add_test(pSuite, "base64_encode", nghttp2::test_base64_encode) || - !CU_add_test(pSuite, "base64_decode", nghttp2::test_base64_decode)) { - CU_cleanup_registry(); - return CU_get_error(); - } + const MunitSuite suites[] = { + shrpx::tls_suite, shrpx::downstream_suite, + shrpx::config_suite, shrpx::worker_suite, + shrpx::http_suite, shrpx::router_suite, + shrpx::http2_suite, shrpx::util_suite, + gzip_suite, buffer_suite, + memchunk_suite, template_suite, + base64_suite, {NULL, NULL, NULL, 0, MUNIT_SUITE_OPTION_NONE}, + }; + const MunitSuite suite = { + "", NULL, suites, 1, MUNIT_SUITE_OPTION_NONE, + }; - // Run all tests using the CUnit Basic interface - CU_basic_set_mode(CU_BRM_VERBOSE); - CU_basic_run_tests(); - num_tests_failed = CU_get_number_of_tests_failed(); - CU_cleanup_registry(); - if (CU_get_error() == CUE_SUCCESS) { - return num_tests_failed; - } else { - printf("CUnit Error: %s\n", CU_get_error_msg()); - return CU_get_error(); - } + return munit_suite_main(&suite, NULL, argc, argv); } diff --git a/src/shrpx.h b/src/shrpx.h index d881ef5..e6379bd 100644 --- a/src/shrpx.h +++ b/src/shrpx.h @@ -36,6 +36,8 @@ #include <cassert> +#define NGHTTP2_NO_SSIZE_T + #ifndef HAVE__EXIT # define nghttp2_Exit(status) _exit(status) #else // HAVE__EXIT diff --git a/src/shrpx_config.cc b/src/shrpx_config.cc index d6d0d07..89b3672 100644 --- a/src/shrpx_config.cc +++ b/src/shrpx_config.cc @@ -49,6 +49,8 @@ #include <fstream> #include <unordered_map> +#include <openssl/evp.h> + #include <nghttp2/nghttp2.h> #include "url-parser/url_parser.h" @@ -64,6 +66,10 @@ #include "ssl_compat.h" #include "xsi_strerror.h" +#ifndef AI_NUMERICSERV +# define AI_NUMERICSERV 0 +#endif + namespace shrpx { namespace { @@ -4691,4 +4697,32 @@ int resolve_hostname(Address *addr, const char *hostname, uint16_t port, return 0; } +#ifdef ENABLE_HTTP3 +QUICKeyingMaterial::QUICKeyingMaterial(QUICKeyingMaterial &&other) noexcept + : cid_encryption_ctx{std::exchange(other.cid_encryption_ctx, nullptr)}, + reserved{other.reserved}, + secret{other.secret}, + salt{other.salt}, + cid_encryption_key{other.cid_encryption_key}, + id{other.id} {} + +QUICKeyingMaterial::~QUICKeyingMaterial() noexcept { + if (cid_encryption_ctx) { + EVP_CIPHER_CTX_free(cid_encryption_ctx); + } +} + +QUICKeyingMaterial & +QUICKeyingMaterial::operator=(QUICKeyingMaterial &&other) noexcept { + cid_encryption_ctx = std::exchange(other.cid_encryption_ctx, nullptr); + reserved = other.reserved; + secret = other.secret; + salt = other.salt; + cid_encryption_key = other.cid_encryption_key; + id = other.id; + + return *this; +} +#endif // ENABLE_HTTP3 + } // namespace shrpx diff --git a/src/shrpx_config.h b/src/shrpx_config.h index 7f316eb..335b0f9 100644 --- a/src/shrpx_config.h +++ b/src/shrpx_config.h @@ -636,6 +636,11 @@ struct TLSCertificate { #ifdef ENABLE_HTTP3 struct QUICKeyingMaterial { + QUICKeyingMaterial() noexcept = default; + QUICKeyingMaterial(QUICKeyingMaterial &&other) noexcept; + ~QUICKeyingMaterial() noexcept; + QUICKeyingMaterial &operator=(QUICKeyingMaterial &&other) noexcept; + EVP_CIPHER_CTX *cid_encryption_ctx; std::array<uint8_t, SHRPX_QUIC_SECRET_RESERVEDLEN> reserved; std::array<uint8_t, SHRPX_QUIC_SECRETLEN> secret; std::array<uint8_t, SHRPX_QUIC_SALTLEN> salt; diff --git a/src/shrpx_config_test.cc b/src/shrpx_config_test.cc index a8f0962..068f185 100644 --- a/src/shrpx_config_test.cc +++ b/src/shrpx_config_test.cc @@ -30,43 +30,57 @@ #include <cstdlib> -#include <CUnit/CUnit.h> +#include "munitxx.h" #include "shrpx_config.h" #include "shrpx_log.h" namespace shrpx { +namespace { +const MunitTest tests[]{ + munit_void_test(test_shrpx_config_parse_header), + munit_void_test(test_shrpx_config_parse_log_format), + munit_void_test(test_shrpx_config_read_tls_ticket_key_file), + munit_void_test(test_shrpx_config_read_tls_ticket_key_file_aes_256), + munit_test_end(), +}; +} // namespace + +const MunitSuite config_suite{ + "/config_suite", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_shrpx_config_parse_header(void) { BlockAllocator balloc(4096, 4096); auto p = parse_header(balloc, StringRef::from_lit("a: b")); - CU_ASSERT("a" == p.name); - CU_ASSERT("b" == p.value); + assert_stdstring_equal("a", p.name.str()); + assert_stdstring_equal("b", p.value.str()); p = parse_header(balloc, StringRef::from_lit("a: b")); - CU_ASSERT("a" == p.name); - CU_ASSERT("b" == p.value); + assert_stdstring_equal("a", p.name.str()); + assert_stdstring_equal("b", p.value.str()); p = parse_header(balloc, StringRef::from_lit(":a: b")); - CU_ASSERT(p.name.empty()); + assert_true(p.name.empty()); p = parse_header(balloc, StringRef::from_lit("a: :b")); - CU_ASSERT("a" == p.name); - CU_ASSERT(":b" == p.value); + assert_stdstring_equal("a", p.name.str()); + assert_stdstring_equal(":b", p.value.str()); p = parse_header(balloc, StringRef::from_lit(": b")); - CU_ASSERT(p.name.empty()); + assert_true(p.name.empty()); p = parse_header(balloc, StringRef::from_lit("alpha: bravo charlie")); - CU_ASSERT("alpha" == p.name); - CU_ASSERT("bravo charlie" == p.value); + assert_stdstring_equal("alpha", p.name.str()); + assert_stdstring_equal("bravo charlie", p.value.str()); p = parse_header(balloc, StringRef::from_lit("a,: b")); - CU_ASSERT(p.name.empty()); + assert_true(p.name.empty()); p = parse_header(balloc, StringRef::from_lit("a: b\x0a")); - CU_ASSERT(p.name.empty()); + assert_true(p.name.empty()); } void test_shrpx_config_parse_log_format(void) { @@ -77,100 +91,102 @@ void test_shrpx_config_parse_log_format(void) { R"($remote_addr - $remote_user [$time_local] )" R"("$request" $status $body_bytes_sent )" R"("${http_referer}" $http_host "$http_user_agent")")); - CU_ASSERT(16 == res.size()); + assert_size(16, ==, res.size()); - CU_ASSERT(LogFragmentType::REMOTE_ADDR == res[0].type); + assert_enum_class(LogFragmentType::REMOTE_ADDR, ==, res[0].type); - CU_ASSERT(LogFragmentType::LITERAL == res[1].type); - CU_ASSERT(" - $remote_user [" == res[1].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[1].type); + assert_stdstring_equal(" - $remote_user [", res[1].value.str()); - CU_ASSERT(LogFragmentType::TIME_LOCAL == res[2].type); + assert_enum_class(LogFragmentType::TIME_LOCAL, ==, res[2].type); - CU_ASSERT(LogFragmentType::LITERAL == res[3].type); - CU_ASSERT("] \"" == res[3].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[3].type); + assert_stdstring_equal("] \"", res[3].value.str()); - CU_ASSERT(LogFragmentType::REQUEST == res[4].type); + assert_enum_class(LogFragmentType::REQUEST, ==, res[4].type); - CU_ASSERT(LogFragmentType::LITERAL == res[5].type); - CU_ASSERT("\" " == res[5].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[5].type); + assert_stdstring_equal("\" ", res[5].value.str()); - CU_ASSERT(LogFragmentType::STATUS == res[6].type); + assert_enum_class(LogFragmentType::STATUS, ==, res[6].type); - CU_ASSERT(LogFragmentType::LITERAL == res[7].type); - CU_ASSERT(" " == res[7].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[7].type); + assert_stdstring_equal(" ", res[7].value.str()); - CU_ASSERT(LogFragmentType::BODY_BYTES_SENT == res[8].type); + assert_enum_class(LogFragmentType::BODY_BYTES_SENT, ==, res[8].type); - CU_ASSERT(LogFragmentType::LITERAL == res[9].type); - CU_ASSERT(" \"" == res[9].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[9].type); + assert_stdstring_equal(" \"", res[9].value.str()); - CU_ASSERT(LogFragmentType::HTTP == res[10].type); - CU_ASSERT("referer" == res[10].value); + assert_enum_class(LogFragmentType::HTTP, ==, res[10].type); + assert_stdstring_equal("referer", res[10].value.str()); - CU_ASSERT(LogFragmentType::LITERAL == res[11].type); - CU_ASSERT("\" " == res[11].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[11].type); + assert_stdstring_equal("\" ", res[11].value.str()); - CU_ASSERT(LogFragmentType::AUTHORITY == res[12].type); + assert_enum_class(LogFragmentType::AUTHORITY, ==, res[12].type); - CU_ASSERT(LogFragmentType::LITERAL == res[13].type); - CU_ASSERT(" \"" == res[13].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[13].type); + assert_stdstring_equal(" \"", res[13].value.str()); - CU_ASSERT(LogFragmentType::HTTP == res[14].type); - CU_ASSERT("user-agent" == res[14].value); + assert_enum_class(LogFragmentType::HTTP, ==, res[14].type); + assert_stdstring_equal("user-agent", res[14].value.str()); - CU_ASSERT(LogFragmentType::LITERAL == res[15].type); - CU_ASSERT("\"" == res[15].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[15].type); + assert_stdstring_equal("\"", res[15].value.str()); res = parse_log_format(balloc, StringRef::from_lit("$")); - CU_ASSERT(1 == res.size()); + assert_size(1, ==, res.size()); - CU_ASSERT(LogFragmentType::LITERAL == res[0].type); - CU_ASSERT("$" == res[0].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[0].type); + assert_stdstring_equal("$", res[0].value.str()); res = parse_log_format(balloc, StringRef::from_lit("${")); - CU_ASSERT(1 == res.size()); + assert_size(1, ==, res.size()); - CU_ASSERT(LogFragmentType::LITERAL == res[0].type); - CU_ASSERT("${" == res[0].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[0].type); + assert_stdstring_equal("${", res[0].value.str()); res = parse_log_format(balloc, StringRef::from_lit("${a")); - CU_ASSERT(1 == res.size()); + assert_size(1, ==, res.size()); - CU_ASSERT(LogFragmentType::LITERAL == res[0].type); - CU_ASSERT("${a" == res[0].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[0].type); + assert_stdstring_equal("${a", res[0].value.str()); res = parse_log_format(balloc, StringRef::from_lit("${a ")); - CU_ASSERT(1 == res.size()); + assert_size(1, ==, res.size()); - CU_ASSERT(LogFragmentType::LITERAL == res[0].type); - CU_ASSERT("${a " == res[0].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[0].type); + assert_stdstring_equal("${a ", res[0].value.str()); res = parse_log_format(balloc, StringRef::from_lit("$$remote_addr")); - CU_ASSERT(2 == res.size()); + assert_size(2, ==, res.size()); - CU_ASSERT(LogFragmentType::LITERAL == res[0].type); - CU_ASSERT("$" == res[0].value); + assert_enum_class(LogFragmentType::LITERAL, ==, res[0].type); + assert_stdstring_equal("$", res[0].value.str()); - CU_ASSERT(LogFragmentType::REMOTE_ADDR == res[1].type); - CU_ASSERT("" == res[1].value); + assert_enum_class(LogFragmentType::REMOTE_ADDR, ==, res[1].type); + assert_stdstring_equal("", res[1].value.str()); } void test_shrpx_config_read_tls_ticket_key_file(void) { char file1[] = "/tmp/nghttpx-unittest.XXXXXX"; auto fd1 = mkstemp(file1); - CU_ASSERT(fd1 != -1); - CU_ASSERT(48 == - write(fd1, "0..............12..............34..............5", 48)); + assert_int(-1, !=, fd1); + assert_ssize( + 48, ==, + write(fd1, "0..............12..............34..............5", 48)); char file2[] = "/tmp/nghttpx-unittest.XXXXXX"; auto fd2 = mkstemp(file2); - CU_ASSERT(fd2 != -1); - CU_ASSERT(48 == - write(fd2, "6..............78..............9a..............b", 48)); + assert_int(-1, !=, fd2); + assert_ssize( + 48, ==, + write(fd2, "6..............78..............9a..............b", 48)); close(fd1); close(fd2); @@ -178,44 +194,48 @@ void test_shrpx_config_read_tls_ticket_key_file(void) { {StringRef{file1}, StringRef{file2}}, EVP_aes_128_cbc(), EVP_sha256()); unlink(file1); unlink(file2); - CU_ASSERT(ticket_keys.get() != nullptr); - CU_ASSERT(2 == ticket_keys->keys.size()); + assert_not_null(ticket_keys.get()); + assert_size(2, ==, ticket_keys->keys.size()); auto key = &ticket_keys->keys[0]; - CU_ASSERT(std::equal(std::begin(key->data.name), std::end(key->data.name), - "0..............1")); - CU_ASSERT(std::equal(std::begin(key->data.enc_key), - std::begin(key->data.enc_key) + 16, "2..............3")); - CU_ASSERT(std::equal(std::begin(key->data.hmac_key), - std::begin(key->data.hmac_key) + 16, - "4..............5")); - CU_ASSERT(16 == key->hmac_keylen); + assert_true(std::equal(std::begin(key->data.name), std::end(key->data.name), + "0..............1")); + assert_true(std::equal(std::begin(key->data.enc_key), + std::begin(key->data.enc_key) + 16, + "2..............3")); + assert_true(std::equal(std::begin(key->data.hmac_key), + std::begin(key->data.hmac_key) + 16, + "4..............5")); + assert_size(16, ==, key->hmac_keylen); key = &ticket_keys->keys[1]; - CU_ASSERT(std::equal(std::begin(key->data.name), std::end(key->data.name), - "6..............7")); - CU_ASSERT(std::equal(std::begin(key->data.enc_key), - std::begin(key->data.enc_key) + 16, "8..............9")); - CU_ASSERT(std::equal(std::begin(key->data.hmac_key), - std::begin(key->data.hmac_key) + 16, - "a..............b")); - CU_ASSERT(16 == key->hmac_keylen); + assert_true(std::equal(std::begin(key->data.name), std::end(key->data.name), + "6..............7")); + assert_true(std::equal(std::begin(key->data.enc_key), + std::begin(key->data.enc_key) + 16, + "8..............9")); + assert_true(std::equal(std::begin(key->data.hmac_key), + std::begin(key->data.hmac_key) + 16, + "a..............b")); + assert_size(16, ==, key->hmac_keylen); } void test_shrpx_config_read_tls_ticket_key_file_aes_256(void) { char file1[] = "/tmp/nghttpx-unittest.XXXXXX"; auto fd1 = mkstemp(file1); - CU_ASSERT(fd1 != -1); - CU_ASSERT(80 == write(fd1, - "0..............12..............................34..." - "...........................5", - 80)); + assert_int(-1, !=, fd1); + assert_ssize(80, ==, + write(fd1, + "0..............12..............................34..." + "...........................5", + 80)); char file2[] = "/tmp/nghttpx-unittest.XXXXXX"; auto fd2 = mkstemp(file2); - CU_ASSERT(fd2 != -1); - CU_ASSERT(80 == write(fd2, - "6..............78..............................9a..." - "...........................b", - 80)); + assert_int(-1, !=, fd2); + assert_ssize(80, ==, + write(fd2, + "6..............78..............................9a..." + "...........................b", + 80)); close(fd1); close(fd2); @@ -223,27 +243,27 @@ void test_shrpx_config_read_tls_ticket_key_file_aes_256(void) { {StringRef{file1}, StringRef{file2}}, EVP_aes_256_cbc(), EVP_sha256()); unlink(file1); unlink(file2); - CU_ASSERT(ticket_keys.get() != nullptr); - CU_ASSERT(2 == ticket_keys->keys.size()); + assert_not_null(ticket_keys.get()); + assert_size(2, ==, ticket_keys->keys.size()); auto key = &ticket_keys->keys[0]; - CU_ASSERT(std::equal(std::begin(key->data.name), std::end(key->data.name), - "0..............1")); - CU_ASSERT(std::equal(std::begin(key->data.enc_key), - std::end(key->data.enc_key), - "2..............................3")); - CU_ASSERT(std::equal(std::begin(key->data.hmac_key), - std::end(key->data.hmac_key), - "4..............................5")); + assert_true(std::equal(std::begin(key->data.name), std::end(key->data.name), + "0..............1")); + assert_true(std::equal(std::begin(key->data.enc_key), + std::end(key->data.enc_key), + "2..............................3")); + assert_true(std::equal(std::begin(key->data.hmac_key), + std::end(key->data.hmac_key), + "4..............................5")); key = &ticket_keys->keys[1]; - CU_ASSERT(std::equal(std::begin(key->data.name), std::end(key->data.name), - "6..............7")); - CU_ASSERT(std::equal(std::begin(key->data.enc_key), - std::end(key->data.enc_key), - "8..............................9")); - CU_ASSERT(std::equal(std::begin(key->data.hmac_key), - std::end(key->data.hmac_key), - "a..............................b")); + assert_true(std::equal(std::begin(key->data.name), std::end(key->data.name), + "6..............7")); + assert_true(std::equal(std::begin(key->data.enc_key), + std::end(key->data.enc_key), + "8..............................9")); + assert_true(std::equal(std::begin(key->data.hmac_key), + std::end(key->data.hmac_key), + "a..............................b")); } } // namespace shrpx diff --git a/src/shrpx_config_test.h b/src/shrpx_config_test.h index a30de41..9863101 100644 --- a/src/shrpx_config_test.h +++ b/src/shrpx_config_test.h @@ -29,13 +29,18 @@ # include <config.h> #endif // HAVE_CONFIG_H +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + namespace shrpx { -void test_shrpx_config_parse_header(void); -void test_shrpx_config_parse_log_format(void); -void test_shrpx_config_read_tls_ticket_key_file(void); -void test_shrpx_config_read_tls_ticket_key_file_aes_256(void); -void test_shrpx_config_match_downstream_addr_group(void); +extern const MunitSuite config_suite; + +munit_void_test_decl(test_shrpx_config_parse_header); +munit_void_test_decl(test_shrpx_config_parse_log_format); +munit_void_test_decl(test_shrpx_config_read_tls_ticket_key_file); +munit_void_test_decl(test_shrpx_config_read_tls_ticket_key_file_aes_256); } // namespace shrpx diff --git a/src/shrpx_connection.cc b/src/shrpx_connection.cc index a5ab390..d863284 100644 --- a/src/shrpx_connection.cc +++ b/src/shrpx_connection.cc @@ -863,7 +863,7 @@ void Connection::start_tls_write_idle() { } } -ssize_t Connection::write_tls(const void *data, size_t len) { +nghttp2_ssize Connection::write_tls(const void *data, size_t len) { // SSL_write requires the same arguments (buf pointer and its // length) on SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE. // get_write_limit() may return smaller length than previously @@ -950,7 +950,7 @@ ssize_t Connection::write_tls(const void *data, size_t len) { return rv; } -ssize_t Connection::read_tls(void *data, size_t len) { +nghttp2_ssize Connection::read_tls(void *data, size_t len) { ERR_clear_error(); #if defined(NGHTTP2_GENUINE_OPENSSL) || defined(NGHTTP2_OPENSSL_IS_BORINGSSL) @@ -1061,7 +1061,7 @@ ssize_t Connection::read_tls(void *data, size_t len) { return rv; } -ssize_t Connection::write_clear(const void *data, size_t len) { +nghttp2_ssize Connection::write_clear(const void *data, size_t len) { len = std::min(len, wlimit.avail()); if (len == 0) { return 0; @@ -1088,7 +1088,7 @@ ssize_t Connection::write_clear(const void *data, size_t len) { return nwrite; } -ssize_t Connection::writev_clear(struct iovec *iov, int iovcnt) { +nghttp2_ssize Connection::writev_clear(struct iovec *iov, int iovcnt) { iovcnt = limit_iovec(iov, iovcnt, wlimit.avail()); if (iovcnt == 0) { return 0; @@ -1115,7 +1115,7 @@ ssize_t Connection::writev_clear(struct iovec *iov, int iovcnt) { return nwrite; } -ssize_t Connection::read_clear(void *data, size_t len) { +nghttp2_ssize Connection::read_clear(void *data, size_t len) { len = std::min(len, rlimit.avail()); if (len == 0) { return 0; @@ -1140,7 +1140,7 @@ ssize_t Connection::read_clear(void *data, size_t len) { return nread; } -ssize_t Connection::read_nolim_clear(void *data, size_t len) { +nghttp2_ssize Connection::read_nolim_clear(void *data, size_t len) { ssize_t nread; while ((nread = read(fd, data, len)) == -1 && errno == EINTR) ; @@ -1158,7 +1158,7 @@ ssize_t Connection::read_nolim_clear(void *data, size_t len) { return nread; } -ssize_t Connection::peek_clear(void *data, size_t len) { +nghttp2_ssize Connection::peek_clear(void *data, size_t len) { ssize_t nread; while ((nread = recv(fd, data, len, MSG_PEEK)) == -1 && errno == EINTR) ; diff --git a/src/shrpx_connection.h b/src/shrpx_connection.h index 10526f7..2db2588 100644 --- a/src/shrpx_connection.h +++ b/src/shrpx_connection.h @@ -33,6 +33,8 @@ #include <openssl/ssl.h> +#include <nghttp2/nghttp2.h> + #ifdef ENABLE_HTTP3 # include <ngtcp2/ngtcp2_crypto.h> #endif // ENABLE_HTTP3 @@ -128,8 +130,8 @@ struct Connection { // underlying connection blocks), return 0. SHRPX_ERR_EOF is // returned in case of EOF and no data was read. Otherwise // SHRPX_ERR_NETWORK is return in case of error. - ssize_t write_tls(const void *data, size_t len); - ssize_t read_tls(void *data, size_t len); + nghttp2_ssize write_tls(const void *data, size_t len); + nghttp2_ssize read_tls(void *data, size_t len); size_t get_tls_write_limit(); // Updates the number of bytes written in warm up period. @@ -138,13 +140,13 @@ struct Connection { // determine fallback to short record size mode. void start_tls_write_idle(); - ssize_t write_clear(const void *data, size_t len); - ssize_t writev_clear(struct iovec *iov, int iovcnt); - ssize_t read_clear(void *data, size_t len); + nghttp2_ssize write_clear(const void *data, size_t len); + nghttp2_ssize writev_clear(struct iovec *iov, int iovcnt); + nghttp2_ssize read_clear(void *data, size_t len); // Read at most |len| bytes of data from socket without rate limit. - ssize_t read_nolim_clear(void *data, size_t len); + nghttp2_ssize read_nolim_clear(void *data, size_t len); // Peek at most |len| bytes of data from socket without rate limit. - ssize_t peek_clear(void *data, size_t len); + nghttp2_ssize peek_clear(void *data, size_t len); void handle_tls_pending_read(); diff --git a/src/shrpx_connection_handler.cc b/src/shrpx_connection_handler.cc index 330e832..af4b8fc 100644 --- a/src/shrpx_connection_handler.cc +++ b/src/shrpx_connection_handler.cc @@ -739,40 +739,31 @@ void ConnectionHandler::handle_ocsp_complete() { // that case we get nullptr. auto quic_ssl_ctx = quic_all_ssl_ctx_[ocsp_.next]; if (quic_ssl_ctx) { -# ifndef NGHTTP2_OPENSSL_IS_BORINGSSL auto quic_tls_ctx_data = static_cast<tls::TLSContextData *>( SSL_CTX_get_app_data(quic_ssl_ctx)); -# ifdef HAVE_ATOMIC_STD_SHARED_PTR +# ifdef HAVE_ATOMIC_STD_SHARED_PTR std::atomic_store_explicit( &quic_tls_ctx_data->ocsp_data, std::make_shared<std::vector<uint8_t>>(ocsp_.resp), std::memory_order_release); -# else // !HAVE_ATOMIC_STD_SHARED_PTR +# else // !HAVE_ATOMIC_STD_SHARED_PTR std::lock_guard<std::mutex> g(quic_tls_ctx_data->mu); quic_tls_ctx_data->ocsp_data = std::make_shared<std::vector<uint8_t>>(ocsp_.resp); -# endif // !HAVE_ATOMIC_STD_SHARED_PTR -# else // NGHTTP2_OPENSSL_IS_BORINGSSL - SSL_CTX_set_ocsp_response(quic_ssl_ctx, ocsp_.resp.data(), - ocsp_.resp.size()); -# endif // NGHTTP2_OPENSSL_IS_BORINGSSL +# endif // !HAVE_ATOMIC_STD_SHARED_PTR } #endif // ENABLE_HTTP3 -#ifndef NGHTTP2_OPENSSL_IS_BORINGSSL -# ifdef HAVE_ATOMIC_STD_SHARED_PTR +#ifdef HAVE_ATOMIC_STD_SHARED_PTR std::atomic_store_explicit( &tls_ctx_data->ocsp_data, std::make_shared<std::vector<uint8_t>>(std::move(ocsp_.resp)), std::memory_order_release); -# else // !HAVE_ATOMIC_STD_SHARED_PTR +#else // !HAVE_ATOMIC_STD_SHARED_PTR std::lock_guard<std::mutex> g(tls_ctx_data->mu); tls_ctx_data->ocsp_data = std::make_shared<std::vector<uint8_t>>(std::move(ocsp_.resp)); -# endif // !HAVE_ATOMIC_STD_SHARED_PTR -#else // NGHTTP2_OPENSSL_IS_BORINGSSL - SSL_CTX_set_ocsp_response(ssl_ctx, ocsp_.resp.data(), ocsp_.resp.size()); -#endif // NGHTTP2_OPENSSL_IS_BORINGSSL +#endif // !HAVE_ATOMIC_STD_SHARED_PTR } ++ocsp_.next; @@ -1288,7 +1279,7 @@ int ConnectionHandler::quic_ipc_read() { if (decrypt_quic_connection_id(decrypted_dcid.data(), vc.dcid + SHRPX_QUIC_CID_PREFIX_OFFSET, - qkm.cid_encryption_key.data()) != 0) { + qkm.cid_encryption_ctx) != 0) { return -1; } diff --git a/src/shrpx_downstream_test.cc b/src/shrpx_downstream_test.cc index 6100b18..46db9b7 100644 --- a/src/shrpx_downstream_test.cc +++ b/src/shrpx_downstream_test.cc @@ -26,12 +26,29 @@ #include <iostream> -#include <CUnit/CUnit.h> +#include "munitxx.h" #include "shrpx_downstream.h" namespace shrpx { +namespace { +const MunitTest tests[]{ + munit_void_test(test_downstream_field_store_append_last_header), + munit_void_test(test_downstream_field_store_header), + munit_void_test(test_downstream_crumble_request_cookie), + munit_void_test(test_downstream_assemble_request_cookie), + munit_void_test(test_downstream_rewrite_location_response_header), + munit_void_test(test_downstream_supports_non_final_response), + munit_void_test(test_downstream_find_affinity_cookie), + munit_test_end(), +}; +} // namespace + +const MunitSuite downstream_suite{ + "/downstream", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_downstream_field_store_append_last_header(void) { BlockAllocator balloc(16, 16); FieldStore fs(balloc, 0); @@ -57,7 +74,7 @@ void test_downstream_field_store_append_last_header(void) { HeaderRefs{{StringRef::from_lit("alphabravogolf0123456789"), StringRef::from_lit("CharliedeltAecho0123456789")}, {StringRef::from_lit("echo"), StringRef::from_lit("foxtrot")}}; - CU_ASSERT(ans == fs.headers()); + assert_true(ans == fs.headers()); } void test_downstream_field_store_header(void) { @@ -72,14 +89,14 @@ void test_downstream_field_store_header(void) { http2::HD_CONTENT_LENGTH); // By token - CU_ASSERT(HeaderRef(StringRef{":authority"}, StringRef{"1"}) == - *fs.header(http2::HD__AUTHORITY)); - CU_ASSERT(nullptr == fs.header(http2::HD__METHOD)); + assert_true(HeaderRef(StringRef{":authority"}, StringRef{"1"}) == + *fs.header(http2::HD__AUTHORITY)); + assert_null(fs.header(http2::HD__METHOD)); // By name - CU_ASSERT(HeaderRef(StringRef{"alpha"}, StringRef{"0"}) == - *fs.header(StringRef::from_lit("alpha"))); - CU_ASSERT(nullptr == fs.header(StringRef::from_lit("bravo"))); + assert_true(HeaderRef(StringRef{"alpha"}, StringRef{"0"}) == + *fs.header(StringRef::from_lit("alpha"))); + assert_null(fs.header(StringRef::from_lit("bravo"))); } void test_downstream_crumble_request_cookie(void) { @@ -103,8 +120,8 @@ void test_downstream_crumble_request_cookie(void) { auto num_cookies = d.count_crumble_request_cookie(); - CU_ASSERT(5 == nva.size()); - CU_ASSERT(5 == num_cookies); + assert_size(5, ==, nva.size()); + assert_size(5, ==, num_cookies); HeaderRefs cookies; std::transform(std::begin(nva), std::end(nva), std::back_inserter(cookies), @@ -121,10 +138,10 @@ void test_downstream_crumble_request_cookie(void) { {StringRef::from_lit("cookie"), StringRef::from_lit("delta")}, {StringRef::from_lit("cookie"), StringRef::from_lit("echo")}}; - CU_ASSERT(ans == cookies); - CU_ASSERT(cookies[0].no_index); - CU_ASSERT(cookies[1].no_index); - CU_ASSERT(cookies[2].no_index); + assert_true(ans == cookies); + assert_true(cookies[0].no_index); + assert_true(cookies[1].no_index); + assert_true(cookies[2].no_index); } void test_downstream_assemble_request_cookie(void) { @@ -147,7 +164,8 @@ void test_downstream_assemble_request_cookie(void) { req.fs.add_header_token(StringRef::from_lit("cookie"), StringRef::from_lit("delta;;"), false, http2::HD_COOKIE); - CU_ASSERT("alpha; bravo; charlie; delta" == d.assemble_request_cookie()); + assert_stdstring_equal("alpha; bravo; charlie; delta", + d.assemble_request_cookie().str()); } void test_downstream_rewrite_location_response_header(void) { @@ -161,7 +179,7 @@ void test_downstream_rewrite_location_response_header(void) { false, http2::HD_LOCATION); d.rewrite_location_response_header(StringRef::from_lit("https")); auto location = resp.fs.header(http2::HD_LOCATION); - CU_ASSERT("https://localhost:8443/" == (*location).value); + assert_stdstring_equal("https://localhost:8443/", (*location).value.str()); } void test_downstream_supports_non_final_response(void) { @@ -171,27 +189,27 @@ void test_downstream_supports_non_final_response(void) { req.http_major = 3; req.http_minor = 0; - CU_ASSERT(d.supports_non_final_response()); + assert_true(d.supports_non_final_response()); req.http_major = 2; req.http_minor = 0; - CU_ASSERT(d.supports_non_final_response()); + assert_true(d.supports_non_final_response()); req.http_major = 1; req.http_minor = 1; - CU_ASSERT(d.supports_non_final_response()); + assert_true(d.supports_non_final_response()); req.http_major = 1; req.http_minor = 0; - CU_ASSERT(!d.supports_non_final_response()); + assert_false(d.supports_non_final_response()); req.http_major = 0; req.http_minor = 9; - CU_ASSERT(!d.supports_non_final_response()); + assert_false(d.supports_non_final_response()); } void test_downstream_find_affinity_cookie(void) { @@ -217,15 +235,15 @@ void test_downstream_find_affinity_cookie(void) { aff = d.find_affinity_cookie(StringRef::from_lit("lb")); - CU_ASSERT(0xdeadbeef == aff); + assert_uint32(0xdeadbeef, ==, aff); aff = d.find_affinity_cookie(StringRef::from_lit("LB")); - CU_ASSERT(0xf1f2f3f4 == aff); + assert_uint32(0xf1f2f3f4, ==, aff); aff = d.find_affinity_cookie(StringRef::from_lit("short")); - CU_ASSERT(0 == aff); + assert_uint32(0, ==, aff); } } // namespace shrpx diff --git a/src/shrpx_downstream_test.h b/src/shrpx_downstream_test.h index ef06ea3..07adbca 100644 --- a/src/shrpx_downstream_test.h +++ b/src/shrpx_downstream_test.h @@ -29,15 +29,21 @@ # include <config.h> #endif // HAVE_CONFIG_H +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + namespace shrpx { -void test_downstream_field_store_append_last_header(void); -void test_downstream_field_store_header(void); -void test_downstream_crumble_request_cookie(void); -void test_downstream_assemble_request_cookie(void); -void test_downstream_rewrite_location_response_header(void); -void test_downstream_supports_non_final_response(void); -void test_downstream_find_affinity_cookie(void); +extern const MunitSuite downstream_suite; + +munit_void_test_decl(test_downstream_field_store_append_last_header); +munit_void_test_decl(test_downstream_field_store_header); +munit_void_test_decl(test_downstream_crumble_request_cookie); +munit_void_test_decl(test_downstream_assemble_request_cookie); +munit_void_test_decl(test_downstream_rewrite_location_response_header); +munit_void_test_decl(test_downstream_supports_non_final_response); +munit_void_test_decl(test_downstream_find_affinity_cookie); } // namespace shrpx diff --git a/src/shrpx_http.cc b/src/shrpx_http.cc index ad32dc9..4750500 100644 --- a/src/shrpx_http.cc +++ b/src/shrpx_http.cc @@ -167,9 +167,9 @@ std::string colorizeHeaders(const char *hdrs) { return nhdrs; } -ssize_t select_padding_callback(nghttp2_session *session, - const nghttp2_frame *frame, size_t max_payload, - void *user_data) { +nghttp2_ssize select_padding_callback(nghttp2_session *session, + const nghttp2_frame *frame, + size_t max_payload, void *user_data) { return std::min(max_payload, frame->hd.length + get_config()->padding); } diff --git a/src/shrpx_http.h b/src/shrpx_http.h index 18935d8..774686c 100644 --- a/src/shrpx_http.h +++ b/src/shrpx_http.h @@ -63,9 +63,9 @@ StringRef create_forwarded(BlockAllocator &balloc, int params, // Adds ANSI color codes to HTTP headers |hdrs|. std::string colorizeHeaders(const char *hdrs); -ssize_t select_padding_callback(nghttp2_session *session, - const nghttp2_frame *frame, size_t max_payload, - void *user_data); +nghttp2_ssize select_padding_callback(nghttp2_session *session, + const nghttp2_frame *frame, + size_t max_payload, void *user_data); // Creates set-cookie-string for cookie based affinity. If |path| is // not empty, "; <path>" is added. If |secure| is true, "; Secure" is diff --git a/src/shrpx_http2_downstream_connection.cc b/src/shrpx_http2_downstream_connection.cc index ee48799..a6c9d53 100644 --- a/src/shrpx_http2_downstream_connection.cc +++ b/src/shrpx_http2_downstream_connection.cc @@ -162,10 +162,11 @@ int Http2DownstreamConnection::submit_rst_stream(Downstream *downstream, } namespace { -ssize_t http2_data_read_callback(nghttp2_session *session, int32_t stream_id, - uint8_t *buf, size_t length, - uint32_t *data_flags, - nghttp2_data_source *source, void *user_data) { +nghttp2_ssize http2_data_read_callback(nghttp2_session *session, + int32_t stream_id, uint8_t *buf, + size_t length, uint32_t *data_flags, + nghttp2_data_source *source, + void *user_data) { int rv; auto sd = static_cast<StreamData *>( nghttp2_session_get_stream_user_data(session, stream_id)); @@ -476,8 +477,8 @@ int Http2DownstreamConnection::push_request_headers() { auto transfer_encoding = req.fs.header(http2::HD_TRANSFER_ENCODING); - nghttp2_data_provider *data_prdptr = nullptr; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 *data_prdptr = nullptr; + nghttp2_data_provider2 data_prd; // Add body as long as transfer-encoding is given even if // req.fs.content_length == 0 to forward trailer fields. diff --git a/src/shrpx_http2_session.cc b/src/shrpx_http2_session.cc index f58ed2f..dccdae4 100644 --- a/src/shrpx_http2_session.cc +++ b/src/shrpx_http2_session.cc @@ -755,15 +755,15 @@ void Http2Session::remove_stream_data(StreamData *sd) { int Http2Session::submit_request(Http2DownstreamConnection *dconn, const nghttp2_nv *nva, size_t nvlen, - const nghttp2_data_provider *data_prd) { + const nghttp2_data_provider2 *data_prd) { assert(state_ == Http2SessionState::CONNECTED); auto sd = std::make_unique<StreamData>(); sd->dlnext = sd->dlprev = nullptr; // TODO Specify nullptr to pri_spec for now - auto stream_id = - nghttp2_submit_request(session_, nullptr, nva, nvlen, data_prd, sd.get()); + auto stream_id = nghttp2_submit_request2(session_, nullptr, nva, nvlen, + data_prd, sd.get()); if (stream_id < 0) { - SSLOG(FATAL, this) << "nghttp2_submit_request() failed: " + SSLOG(FATAL, this) << "nghttp2_submit_request2() failed: " << nghttp2_strerror(stream_id); return -1; } @@ -1653,7 +1653,7 @@ nghttp2_session_callbacks *create_http2_downstream_callbacks() { send_data_callback); if (get_config()->padding) { - nghttp2_session_callbacks_set_select_padding_callback( + nghttp2_session_callbacks_set_select_padding_callback2( callbacks, http::select_padding_callback); } @@ -1754,11 +1754,9 @@ int Http2Session::on_read(const uint8_t *data, size_t datalen) { int Http2Session::on_write() { return on_write_(*this); } int Http2Session::downstream_read(const uint8_t *data, size_t datalen) { - ssize_t rv; - - rv = nghttp2_session_mem_recv(session_, data, datalen); + auto rv = nghttp2_session_mem_recv2(session_, data, datalen); if (rv < 0) { - SSLOG(ERROR, this) << "nghttp2_session_mem_recv() returned error: " + SSLOG(ERROR, this) << "nghttp2_session_mem_recv2() returned error: " << nghttp2_strerror(rv); return -1; } @@ -1778,9 +1776,9 @@ int Http2Session::downstream_read(const uint8_t *data, size_t datalen) { int Http2Session::downstream_write() { for (;;) { const uint8_t *data; - auto datalen = nghttp2_session_mem_send(session_, &data); + auto datalen = nghttp2_session_mem_send2(session_, &data); if (datalen < 0) { - SSLOG(ERROR, this) << "nghttp2_session_mem_send() returned error: " + SSLOG(ERROR, this) << "nghttp2_session_mem_send2() returned error: " << nghttp2_strerror(datalen); return -1; } diff --git a/src/shrpx_http2_session.h b/src/shrpx_http2_session.h index 31b2545..1a67a5f 100644 --- a/src/shrpx_http2_session.h +++ b/src/shrpx_http2_session.h @@ -116,7 +116,7 @@ public: void remove_stream_data(StreamData *sd); int submit_request(Http2DownstreamConnection *dconn, const nghttp2_nv *nva, - size_t nvlen, const nghttp2_data_provider *data_prd); + size_t nvlen, const nghttp2_data_provider2 *data_prd); int submit_rst_stream(int32_t stream_id, uint32_t error_code); diff --git a/src/shrpx_http2_upstream.cc b/src/shrpx_http2_upstream.cc index c9f8a8c..2cb5436 100644 --- a/src/shrpx_http2_upstream.cc +++ b/src/shrpx_http2_upstream.cc @@ -717,7 +717,7 @@ int on_frame_send_callback(nghttp2_session *session, const nghttp2_frame *frame, upstream, handler->get_mcpool(), promised_stream_id); auto &req = promised_downstream->request(); - // As long as we use nghttp2_session_mem_send(), setting stream + // As long as we use nghttp2_session_mem_send2(), setting stream // user data here should not fail. This is because this callback // is called just after frame was serialized. So no worries about // hanging Downstream. @@ -995,7 +995,7 @@ nghttp2_session_callbacks *create_http2_upstream_callbacks() { auto config = get_config(); if (config->padding) { - nghttp2_session_callbacks_set_select_padding_callback( + nghttp2_session_callbacks_set_select_padding_callback2( callbacks, http::select_padding_callback); } @@ -1145,21 +1145,20 @@ Http2Upstream::~Http2Upstream() { } int Http2Upstream::on_read() { - ssize_t rv = 0; auto rb = handler_->get_rb(); auto rlimit = handler_->get_rlimit(); if (rb->rleft()) { - rv = nghttp2_session_mem_recv(session_, rb->pos(), rb->rleft()); + auto rv = nghttp2_session_mem_recv2(session_, rb->pos(), rb->rleft()); if (rv < 0) { if (rv != NGHTTP2_ERR_BAD_CLIENT_MAGIC) { - ULOG(ERROR, this) << "nghttp2_session_mem_recv() returned error: " + ULOG(ERROR, this) << "nghttp2_session_mem_recv2() returned error: " << nghttp2_strerror(rv); } return -1; } - // nghttp2_session_mem_recv should consume all input bytes on + // nghttp2_session_mem_recv2 should consume all input bytes on // success. assert(static_cast<size_t>(rv) == rb->rleft()); rb->reset(); @@ -1221,10 +1220,10 @@ int Http2Upstream::on_write() { } const uint8_t *data; - auto datalen = nghttp2_session_mem_send(session_, &data); + auto datalen = nghttp2_session_mem_send2(session_, &data); if (datalen < 0) { - ULOG(ERROR, this) << "nghttp2_session_mem_send() returned error: " + ULOG(ERROR, this) << "nghttp2_session_mem_send2() returned error: " << nghttp2_strerror(datalen); return -1; } @@ -1436,11 +1435,11 @@ int Http2Upstream::terminate_session(uint32_t error_code) { } namespace { -ssize_t downstream_data_read_callback(nghttp2_session *session, - int32_t stream_id, uint8_t *buf, - size_t length, uint32_t *data_flags, - nghttp2_data_source *source, - void *user_data) { +nghttp2_ssize downstream_data_read_callback(nghttp2_session *session, + int32_t stream_id, uint8_t *buf, + size_t length, uint32_t *data_flags, + nghttp2_data_source *source, + void *user_data) { int rv; auto downstream = static_cast<Downstream *>(source->ptr); auto body = downstream->get_response_buf(); @@ -1508,7 +1507,7 @@ int Http2Upstream::send_reply(Downstream *downstream, const uint8_t *body, size_t bodylen) { int rv; - nghttp2_data_provider data_prd, *data_prd_ptr = nullptr; + nghttp2_data_provider2 data_prd, *data_prd_ptr = nullptr; if (bodylen) { data_prd.source.ptr = downstream; @@ -1555,10 +1554,10 @@ int Http2Upstream::send_reply(Downstream *downstream, const uint8_t *body, nva.push_back(http2::make_nv_nocopy(p.name, p.value)); } - rv = nghttp2_submit_response(session_, downstream->get_stream_id(), - nva.data(), nva.size(), data_prd_ptr); + rv = nghttp2_submit_response2(session_, downstream->get_stream_id(), + nva.data(), nva.size(), data_prd_ptr); if (nghttp2_is_fatal(rv)) { - ULOG(FATAL, this) << "nghttp2_submit_response() failed: " + ULOG(FATAL, this) << "nghttp2_submit_response2() failed: " << nghttp2_strerror(rv); return -1; } @@ -1589,7 +1588,7 @@ int Http2Upstream::error_reply(Downstream *downstream, body->append(html); downstream->set_response_state(DownstreamState::MSG_COMPLETE); - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; data_prd.source.ptr = downstream; data_prd.read_callback = downstream_data_read_callback; @@ -1607,10 +1606,10 @@ int Http2Upstream::error_reply(Downstream *downstream, http2::make_nv_ls_nocopy("content-length", content_length), http2::make_nv_ls_nocopy("date", date)}}; - rv = nghttp2_submit_response(session_, downstream->get_stream_id(), - nva.data(), nva.size(), &data_prd); + rv = nghttp2_submit_response2(session_, downstream->get_stream_id(), + nva.data(), nva.size(), &data_prd); if (rv < NGHTTP2_ERR_FATAL) { - ULOG(FATAL, this) << "nghttp2_submit_response() failed: " + ULOG(FATAL, this) << "nghttp2_submit_response2() failed: " << nghttp2_strerror(rv); return -1; } @@ -1876,11 +1875,11 @@ int Http2Upstream::on_downstream_header_complete(Downstream *downstream) { } } - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; data_prd.source.ptr = downstream; data_prd.read_callback = downstream_data_read_callback; - nghttp2_data_provider *data_prdptr; + nghttp2_data_provider2 *data_prdptr; if (downstream->expect_response_body() || downstream->expect_response_trailer()) { @@ -1889,10 +1888,10 @@ int Http2Upstream::on_downstream_header_complete(Downstream *downstream) { data_prdptr = nullptr; } - rv = nghttp2_submit_response(session_, downstream->get_stream_id(), - nva.data(), nva.size(), data_prdptr); + rv = nghttp2_submit_response2(session_, downstream->get_stream_id(), + nva.data(), nva.size(), data_prdptr); if (rv != 0) { - ULOG(FATAL, this) << "nghttp2_submit_response() failed"; + ULOG(FATAL, this) << "nghttp2_submit_response2() failed"; return -1; } diff --git a/src/shrpx_http3_upstream.cc b/src/shrpx_http3_upstream.cc index f8ae1ce..b8667a3 100644 --- a/src/shrpx_http3_upstream.cc +++ b/src/shrpx_http3_upstream.cc @@ -213,7 +213,7 @@ int get_new_connection_id(ngtcp2_conn *conn, ngtcp2_cid *cid, uint8_t *token, auto &qkm = qkms->keying_materials.front(); if (generate_quic_connection_id(*cid, cidlen, worker->get_cid_prefix(), - qkm.id, qkm.cid_encryption_key.data()) != 0) { + qkm.id, qkm.cid_encryption_ctx) != 0) { return NGTCP2_ERR_CALLBACK_FAILURE; } @@ -611,7 +611,7 @@ int Http3Upstream::init(const UpstreamAddr *faddr, const Address &remote_addr, if (generate_quic_connection_id(scid, SHRPX_QUIC_SCIDLEN, worker->get_cid_prefix(), qkm.id, - qkm.cid_encryption_key.data()) != 0) { + qkm.cid_encryption_ctx) != 0) { return -1; } @@ -635,7 +635,6 @@ int Http3Upstream::init(const UpstreamAddr *faddr, const Address &remote_addr, settings.cc_algo = quicconf.upstream.congestion_controller; settings.max_window = http3conf.upstream.max_connection_window_size; settings.max_stream_window = http3conf.upstream.max_window_size; - settings.max_tx_udp_payload_size = SHRPX_QUIC_MAX_UDP_PAYLOAD_SIZE; settings.rand_ctx.native_handle = &worker->get_randgen(); settings.token = token; settings.tokenlen = tokenlen; @@ -783,7 +782,9 @@ int Http3Upstream::write_streams() { auto path_max_udp_payload_size = ngtcp2_conn_get_path_max_tx_udp_payload_size(conn_); #endif // UDP_SEGMENT - auto max_pktcnt = ngtcp2_conn_get_send_quantum(conn_) / max_udp_payload_size; + auto max_pktcnt = + std::max(ngtcp2_conn_get_send_quantum(conn_) / max_udp_payload_size, + static_cast<size_t>(1)); ngtcp2_pkt_info pi, prev_pi; uint8_t *bufpos = tx_.data.get(); ngtcp2_path_storage ps, prev_ps; diff --git a/src/shrpx_http_test.cc b/src/shrpx_http_test.cc index 3ace870..f753ec8 100644 --- a/src/shrpx_http_test.cc +++ b/src/shrpx_http_test.cc @@ -30,7 +30,7 @@ #include <cstdlib> -#include <CUnit/CUnit.h> +#include "munitxx.h" #include "shrpx_http.h" #include "shrpx_config.h" @@ -38,43 +38,65 @@ namespace shrpx { +namespace { +const MunitTest tests[]{ + munit_void_test(test_shrpx_http_create_forwarded), + munit_void_test(test_shrpx_http_create_via_header_value), + munit_void_test(test_shrpx_http_create_affinity_cookie), + munit_void_test(test_shrpx_http_create_altsvc_header_value), + munit_void_test(test_shrpx_http_check_http_scheme), + munit_test_end(), +}; +} // namespace + +const MunitSuite http_suite{ + "/http", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_shrpx_http_create_forwarded(void) { BlockAllocator balloc(1024, 1024); - CU_ASSERT("by=\"example.com:3000\";for=\"[::1]\";host=\"www.example.com\";" - "proto=https" == - http::create_forwarded(balloc, - FORWARDED_BY | FORWARDED_FOR | - FORWARDED_HOST | FORWARDED_PROTO, - StringRef::from_lit("example.com:3000"), - StringRef::from_lit("[::1]"), - StringRef::from_lit("www.example.com"), - StringRef::from_lit("https"))); - - CU_ASSERT("for=192.168.0.1" == - http::create_forwarded( - balloc, FORWARDED_FOR, StringRef::from_lit("alpha"), - StringRef::from_lit("192.168.0.1"), - StringRef::from_lit("bravo"), StringRef::from_lit("charlie"))); - - CU_ASSERT("by=_hidden;for=\"[::1]\"" == - http::create_forwarded( - balloc, FORWARDED_BY | FORWARDED_FOR, - StringRef::from_lit("_hidden"), StringRef::from_lit("[::1]"), - StringRef::from_lit(""), StringRef::from_lit(""))); - - CU_ASSERT("by=\"[::1]\";for=_hidden" == - http::create_forwarded( - balloc, FORWARDED_BY | FORWARDED_FOR, - StringRef::from_lit("[::1]"), StringRef::from_lit("_hidden"), - StringRef::from_lit(""), StringRef::from_lit(""))); - - CU_ASSERT("" == - http::create_forwarded( - balloc, - FORWARDED_BY | FORWARDED_FOR | FORWARDED_HOST | FORWARDED_PROTO, - StringRef::from_lit(""), StringRef::from_lit(""), - StringRef::from_lit(""), StringRef::from_lit(""))); + assert_stdstring_equal( + "by=\"example.com:3000\";for=\"[::1]\";host=\"www.example.com\";" + "proto=https", + http::create_forwarded( + balloc, + FORWARDED_BY | FORWARDED_FOR | FORWARDED_HOST | FORWARDED_PROTO, + StringRef::from_lit("example.com:3000"), StringRef::from_lit("[::1]"), + StringRef::from_lit("www.example.com"), StringRef::from_lit("https")) + .str()); + + assert_stdstring_equal( + "for=192.168.0.1", + http::create_forwarded( + balloc, FORWARDED_FOR, StringRef::from_lit("alpha"), + StringRef::from_lit("192.168.0.1"), StringRef::from_lit("bravo"), + StringRef::from_lit("charlie")) + .str()); + + assert_stdstring_equal( + "by=_hidden;for=\"[::1]\"", + http::create_forwarded(balloc, FORWARDED_BY | FORWARDED_FOR, + StringRef::from_lit("_hidden"), + StringRef::from_lit("[::1]"), + StringRef::from_lit(""), StringRef::from_lit("")) + .str()); + + assert_stdstring_equal( + "by=\"[::1]\";for=_hidden", + http::create_forwarded(balloc, FORWARDED_BY | FORWARDED_FOR, + StringRef::from_lit("[::1]"), + StringRef::from_lit("_hidden"), + StringRef::from_lit(""), StringRef::from_lit("")) + .str()); + + assert_stdstring_equal( + "", http::create_forwarded( + balloc, + FORWARDED_BY | FORWARDED_FOR | FORWARDED_HOST | FORWARDED_PROTO, + StringRef::from_lit(""), StringRef::from_lit(""), + StringRef::from_lit(""), StringRef::from_lit("")) + .str()); } void test_shrpx_http_create_via_header_value(void) { @@ -82,13 +104,13 @@ void test_shrpx_http_create_via_header_value(void) { auto end = http::create_via_header_value(std::begin(buf), 1, 1); - CU_ASSERT(("1.1 nghttpx" == StringRef{std::begin(buf), end})); + assert_stdstring_equal("1.1 nghttpx", (std::string{std::begin(buf), end})); std::fill(std::begin(buf), std::end(buf), '\0'); end = http::create_via_header_value(std::begin(buf), 2, 0); - CU_ASSERT(("2 nghttpx" == StringRef{std::begin(buf), end})); + assert_stdstring_equal("2 nghttpx", (std::string{std::begin(buf), end})); } void test_shrpx_http_create_affinity_cookie(void) { @@ -98,24 +120,24 @@ void test_shrpx_http_create_affinity_cookie(void) { c = http::create_affinity_cookie(balloc, StringRef::from_lit("cookie-val"), 0xf1e2d3c4u, StringRef{}, false); - CU_ASSERT("cookie-val=f1e2d3c4" == c); + assert_stdstring_equal("cookie-val=f1e2d3c4", c.str()); c = http::create_affinity_cookie(balloc, StringRef::from_lit("alpha"), 0x00000000u, StringRef{}, true); - CU_ASSERT("alpha=00000000; Secure" == c); + assert_stdstring_equal("alpha=00000000; Secure", c.str()); c = http::create_affinity_cookie(balloc, StringRef::from_lit("bravo"), 0x01111111u, StringRef::from_lit("bar"), false); - CU_ASSERT("bravo=01111111; Path=bar" == c); + assert_stdstring_equal("bravo=01111111; Path=bar", c.str()); c = http::create_affinity_cookie(balloc, StringRef::from_lit("charlie"), 0x01111111u, StringRef::from_lit("bar"), true); - CU_ASSERT("charlie=01111111; Path=bar; Secure" == c); + assert_stdstring_equal("charlie=01111111; Path=bar; Secure", c.str()); } void test_shrpx_http_create_altsvc_header_value(void) { @@ -130,8 +152,9 @@ void test_shrpx_http_create_altsvc_header_value(void) { }, }; - CU_ASSERT(R"(h3="127.0.0.1:443"; ma=3600)" == - http::create_altsvc_header_value(balloc, altsvcs)); + assert_stdstring_equal( + R"(h3="127.0.0.1:443"; ma=3600)", + http::create_altsvc_header_value(balloc, altsvcs).str()); } { @@ -149,20 +172,21 @@ void test_shrpx_http_create_altsvc_header_value(void) { }, }; - CU_ASSERT(R"(h3=":443"; ma=3600, h3%25="\"foo\":4433")" == - http::create_altsvc_header_value(balloc, altsvcs)); + assert_stdstring_equal( + R"(h3=":443"; ma=3600, h3%25="\"foo\":4433")", + http::create_altsvc_header_value(balloc, altsvcs).str()); } } void test_shrpx_http_check_http_scheme(void) { - CU_ASSERT(http::check_http_scheme(StringRef::from_lit("https"), true)); - CU_ASSERT(!http::check_http_scheme(StringRef::from_lit("https"), false)); - CU_ASSERT(!http::check_http_scheme(StringRef::from_lit("http"), true)); - CU_ASSERT(http::check_http_scheme(StringRef::from_lit("http"), false)); - CU_ASSERT(!http::check_http_scheme(StringRef::from_lit("foo"), true)); - CU_ASSERT(!http::check_http_scheme(StringRef::from_lit("foo"), false)); - CU_ASSERT(!http::check_http_scheme(StringRef{}, true)); - CU_ASSERT(!http::check_http_scheme(StringRef{}, false)); + assert_true(http::check_http_scheme(StringRef::from_lit("https"), true)); + assert_false(http::check_http_scheme(StringRef::from_lit("https"), false)); + assert_false(http::check_http_scheme(StringRef::from_lit("http"), true)); + assert_true(http::check_http_scheme(StringRef::from_lit("http"), false)); + assert_false(http::check_http_scheme(StringRef::from_lit("foo"), true)); + assert_false(http::check_http_scheme(StringRef::from_lit("foo"), false)); + assert_false(http::check_http_scheme(StringRef{}, true)); + assert_false(http::check_http_scheme(StringRef{}, false)); } } // namespace shrpx diff --git a/src/shrpx_http_test.h b/src/shrpx_http_test.h index d50ab53..2abdc20 100644 --- a/src/shrpx_http_test.h +++ b/src/shrpx_http_test.h @@ -29,13 +29,19 @@ # include <config.h> #endif // HAVE_CONFIG_H +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + namespace shrpx { -void test_shrpx_http_create_forwarded(void); -void test_shrpx_http_create_via_header_value(void); -void test_shrpx_http_create_affinity_cookie(void); -void test_shrpx_http_create_altsvc_header_value(void); -void test_shrpx_http_check_http_scheme(void); +extern const MunitSuite http_suite; + +munit_void_test_decl(test_shrpx_http_create_forwarded); +munit_void_test_decl(test_shrpx_http_create_via_header_value); +munit_void_test_decl(test_shrpx_http_create_affinity_cookie); +munit_void_test_decl(test_shrpx_http_create_altsvc_header_value); +munit_void_test_decl(test_shrpx_http_check_http_scheme); } // namespace shrpx diff --git a/src/shrpx_live_check.cc b/src/shrpx_live_check.cc index 9b932cd..8e8d316 100644 --- a/src/shrpx_live_check.cc +++ b/src/shrpx_live_check.cc @@ -580,18 +580,16 @@ int LiveCheck::write_clear() { } int LiveCheck::on_read(const uint8_t *data, size_t len) { - ssize_t rv; - - rv = nghttp2_session_mem_recv(session_, data, len); + auto rv = nghttp2_session_mem_recv2(session_, data, len); if (rv < 0) { - LOG(ERROR) << "nghttp2_session_mem_recv() returned error: " + LOG(ERROR) << "nghttp2_session_mem_recv2() returned error: " << nghttp2_strerror(rv); return -1; } if (settings_ack_received_ && !session_closing_) { session_closing_ = true; - rv = nghttp2_session_terminate_session(session_, NGHTTP2_NO_ERROR); + auto rv = nghttp2_session_terminate_session(session_, NGHTTP2_NO_ERROR); if (rv != 0) { return -1; } @@ -619,10 +617,10 @@ int LiveCheck::on_read(const uint8_t *data, size_t len) { int LiveCheck::on_write() { for (;;) { const uint8_t *data; - auto datalen = nghttp2_session_mem_send(session_, &data); + auto datalen = nghttp2_session_mem_send2(session_, &data); if (datalen < 0) { - LOG(ERROR) << "nghttp2_session_mem_send() returned error: " + LOG(ERROR) << "nghttp2_session_mem_send2() returned error: " << nghttp2_strerror(datalen); return -1; } diff --git a/src/shrpx_mruby.cc b/src/shrpx_mruby.cc index b5c6ed3..4d412ef 100644 --- a/src/shrpx_mruby.cc +++ b/src/shrpx_mruby.cc @@ -151,12 +151,12 @@ RProc *compile(mrb_state *mrb, const StringRef &filename) { } auto infile_d = defer(fclose, infile); - auto mrbc = mrbc_context_new(mrb); + auto mrbc = mrb_ccontext_new(mrb); if (mrbc == nullptr) { LOG(ERROR) << "mrb_context_new failed"; return nullptr; } - auto mrbc_d = defer(mrbc_context_free, mrb, mrbc); + auto mrbc_d = defer(mrb_ccontext_free, mrb, mrbc); auto parser = mrb_parse_file(mrb, infile, nullptr); if (parser == nullptr) { diff --git a/src/shrpx_quic.cc b/src/shrpx_quic.cc index 2d4de59..a6d4dfa 100644 --- a/src/shrpx_quic.cc +++ b/src/shrpx_quic.cc @@ -175,7 +175,7 @@ int quic_send_packet(const UpstreamAddr *faddr, const sockaddr *remote_sa, int generate_quic_retry_connection_id(ngtcp2_cid &cid, size_t cidlen, const uint8_t *server_id, uint8_t km_id, - const uint8_t *key) { + EVP_CIPHER_CTX *ctx) { assert(cidlen == SHRPX_QUIC_SCIDLEN); if (RAND_bytes(cid.data, cidlen) != 1) { @@ -190,12 +190,12 @@ int generate_quic_retry_connection_id(ngtcp2_cid &cid, size_t cidlen, std::copy_n(server_id, SHRPX_QUIC_SERVER_IDLEN, p); - return encrypt_quic_connection_id(p, p, key); + return encrypt_quic_connection_id(p, p, ctx); } int generate_quic_connection_id(ngtcp2_cid &cid, size_t cidlen, const uint8_t *cid_prefix, uint8_t km_id, - const uint8_t *key) { + EVP_CIPHER_CTX *ctx) { assert(cidlen == SHRPX_QUIC_SCIDLEN); if (RAND_bytes(cid.data, cidlen) != 1) { @@ -210,20 +210,11 @@ int generate_quic_connection_id(ngtcp2_cid &cid, size_t cidlen, std::copy_n(cid_prefix, SHRPX_QUIC_CID_PREFIXLEN, p); - return encrypt_quic_connection_id(p, p, key); + return encrypt_quic_connection_id(p, p, ctx); } int encrypt_quic_connection_id(uint8_t *dest, const uint8_t *src, - const uint8_t *key) { - auto ctx = EVP_CIPHER_CTX_new(); - auto d = defer(EVP_CIPHER_CTX_free, ctx); - - if (!EVP_EncryptInit_ex(ctx, EVP_aes_128_ecb(), nullptr, key, nullptr)) { - return -1; - } - - EVP_CIPHER_CTX_set_padding(ctx, 0); - + EVP_CIPHER_CTX *ctx) { int len; if (!EVP_EncryptUpdate(ctx, dest, &len, src, SHRPX_QUIC_DECRYPTED_DCIDLEN) || @@ -235,20 +226,11 @@ int encrypt_quic_connection_id(uint8_t *dest, const uint8_t *src, } int decrypt_quic_connection_id(uint8_t *dest, const uint8_t *src, - const uint8_t *key) { - auto ctx = EVP_CIPHER_CTX_new(); - auto d = defer(EVP_CIPHER_CTX_free, ctx); - - if (!EVP_DecryptInit_ex(ctx, EVP_aes_128_ecb(), nullptr, key, nullptr)) { - return -1; - } - - EVP_CIPHER_CTX_set_padding(ctx, 0); - + EVP_CIPHER_CTX *ctx) { int len; - if (!EVP_DecryptUpdate(ctx, dest, &len, src, SHRPX_QUIC_DECRYPTED_DCIDLEN) || - !EVP_DecryptFinal_ex(ctx, dest + len, &len)) { + if (!EVP_EncryptUpdate(ctx, dest, &len, src, SHRPX_QUIC_DECRYPTED_DCIDLEN) || + !EVP_EncryptFinal_ex(ctx, dest + len, &len)) { return -1; } diff --git a/src/shrpx_quic.h b/src/shrpx_quic.h index b2f6087..88388e9 100644 --- a/src/shrpx_quic.h +++ b/src/shrpx_quic.h @@ -31,6 +31,8 @@ #include <functional> +#include <openssl/evp.h> + #include <ngtcp2/ngtcp2.h> #include "network.h" @@ -70,7 +72,6 @@ constexpr size_t SHRPX_QUIC_CID_PREFIXLEN = 8; constexpr size_t SHRPX_QUIC_CID_PREFIX_OFFSET = 1; constexpr size_t SHRPX_QUIC_DECRYPTED_DCIDLEN = 16; constexpr size_t SHRPX_QUIC_CID_ENCRYPTION_KEYLEN = 16; -constexpr size_t SHRPX_QUIC_MAX_UDP_PAYLOAD_SIZE = 1472; constexpr size_t SHRPX_QUIC_CONN_CLOSE_PKTLEN = 256; constexpr size_t SHRPX_QUIC_STATELESS_RESET_BURST = 100; constexpr size_t SHRPX_QUIC_SECRET_RESERVEDLEN = 4; @@ -87,17 +88,17 @@ int quic_send_packet(const UpstreamAddr *faddr, const sockaddr *remote_sa, int generate_quic_retry_connection_id(ngtcp2_cid &cid, size_t cidlen, const uint8_t *server_id, uint8_t km_id, - const uint8_t *key); + EVP_CIPHER_CTX *ctx); int generate_quic_connection_id(ngtcp2_cid &cid, size_t cidlen, const uint8_t *cid_prefix, uint8_t km_id, - const uint8_t *key); + EVP_CIPHER_CTX *ctx); int encrypt_quic_connection_id(uint8_t *dest, const uint8_t *src, - const uint8_t *key); + EVP_CIPHER_CTX *ctx); int decrypt_quic_connection_id(uint8_t *dest, const uint8_t *src, - const uint8_t *key); + EVP_CIPHER_CTX *ctx); int generate_quic_hashed_connection_id(ngtcp2_cid &dest, const Address &remote_addr, diff --git a/src/shrpx_quic_connection_handler.cc b/src/shrpx_quic_connection_handler.cc index 6287971..13f710b 100644 --- a/src/shrpx_quic_connection_handler.cc +++ b/src/shrpx_quic_connection_handler.cc @@ -134,7 +134,7 @@ int QUICConnectionHandler::handle_packet(const UpstreamAddr *faddr, if (decrypt_quic_connection_id(decrypted_dcid.data(), vc.dcid + SHRPX_QUIC_CID_PREFIX_OFFSET, - qkm->cid_encryption_key.data()) != 0) { + qkm->cid_encryption_ctx) != 0) { return 0; } @@ -186,7 +186,7 @@ int QUICConnectionHandler::handle_packet(const UpstreamAddr *faddr, if (decrypt_quic_connection_id(decrypted_dcid.data(), vc.dcid + SHRPX_QUIC_CID_PREFIX_OFFSET, - qkm->cid_encryption_key.data()) != 0) { + qkm->cid_encryption_ctx) != 0) { return 0; } } @@ -480,7 +480,7 @@ int QUICConnectionHandler::send_retry( if (generate_quic_retry_connection_id(retry_scid, SHRPX_QUIC_SCIDLEN, quicconf.server_id.data(), qkm.id, - qkm.cid_encryption_key.data()) != 0) { + qkm.cid_encryption_ctx) != 0) { return -1; } diff --git a/src/shrpx_router_test.cc b/src/shrpx_router_test.cc index 21c2f51..a9625a0 100644 --- a/src/shrpx_router_test.cc +++ b/src/shrpx_router_test.cc @@ -24,12 +24,25 @@ */ #include "shrpx_router_test.h" -#include <CUnit/CUnit.h> +#include "munitxx.h" #include "shrpx_router.h" namespace shrpx { +namespace { +const MunitTest tests[]{ + munit_void_test(test_shrpx_router_match), + munit_void_test(test_shrpx_router_match_wildcard), + munit_void_test(test_shrpx_router_match_prefix), + munit_test_end(), +}; +} // namespace + +const MunitSuite router_suite{ + "/router", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + struct Pattern { StringRef pattern; size_t idx; @@ -61,42 +74,42 @@ void test_shrpx_router_match(void) { idx = router.match(StringRef::from_lit("nghttp2.org"), StringRef::from_lit("/")); - CU_ASSERT(0 == idx); + assert_ssize(0, ==, idx); idx = router.match(StringRef::from_lit("nghttp2.org"), StringRef::from_lit("/alpha")); - CU_ASSERT(1 == idx); + assert_ssize(1, ==, idx); idx = router.match(StringRef::from_lit("nghttp2.org"), StringRef::from_lit("/alpha/")); - CU_ASSERT(2 == idx); + assert_ssize(2, ==, idx); idx = router.match(StringRef::from_lit("nghttp2.org"), StringRef::from_lit("/alpha/charlie")); - CU_ASSERT(2 == idx); + assert_ssize(2, ==, idx); idx = router.match(StringRef::from_lit("nghttp2.org"), StringRef::from_lit("/alpha/bravo/")); - CU_ASSERT(3 == idx); + assert_ssize(3, ==, idx); // matches pattern when last '/' is missing in path idx = router.match(StringRef::from_lit("nghttp2.org"), StringRef::from_lit("/alpha/bravo")); - CU_ASSERT(3 == idx); + assert_ssize(3, ==, idx); idx = router.match(StringRef::from_lit("www2.nghttp2.org"), StringRef::from_lit("/alpha")); - CU_ASSERT(8 == idx); + assert_ssize(8, ==, idx); idx = router.match(StringRef{}, StringRef::from_lit("/alpha")); - CU_ASSERT(5 == idx); + assert_ssize(5, ==, idx); } void test_shrpx_router_match_wildcard(void) { @@ -115,32 +128,41 @@ void test_shrpx_router_match_wildcard(void) { router.add_route(p.pattern, p.idx, p.wildcard); } - CU_ASSERT(0 == router.match(StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/"))); + assert_ssize(0, ==, + router.match(StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/"))); - CU_ASSERT(1 == router.match(StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/a"))); + assert_ssize(1, ==, + router.match(StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/a"))); - CU_ASSERT(1 == router.match(StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/charlie"))); + assert_ssize(1, ==, + router.match(StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/charlie"))); - CU_ASSERT(2 == router.match(StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/alpha"))); + assert_ssize(2, ==, + router.match(StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/alpha"))); - CU_ASSERT(2 == router.match(StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/alpha/"))); + assert_ssize(2, ==, + router.match(StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/alpha/"))); - CU_ASSERT(3 == router.match(StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/alpha/b"))); + assert_ssize(3, ==, + router.match(StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/alpha/b"))); - CU_ASSERT(4 == router.match(StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/bravo"))); + assert_ssize(4, ==, + router.match(StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/bravo"))); - CU_ASSERT(5 == router.match(StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/bravocharlie"))); + assert_ssize(5, ==, + router.match(StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/bravocharlie"))); - CU_ASSERT(5 == router.match(StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/bravo/"))); + assert_ssize(5, ==, + router.match(StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/bravo/"))); } void test_shrpx_router_match_prefix(void) { @@ -166,19 +188,19 @@ void test_shrpx_router_match_prefix(void) { idx = router.match_prefix(&nread, &node, StringRef::from_lit("gro.2ptthgn.gmi.ahpla.ovarb")); - CU_ASSERT(0 == idx); - CU_ASSERT(12 == nread); + assert_ssize(0, ==, idx); + assert_size(12, ==, nread); idx = router.match_prefix(&nread, &node, StringRef::from_lit("gmi.ahpla.ovarb")); - CU_ASSERT(2 == idx); - CU_ASSERT(4 == nread); + assert_ssize(2, ==, idx); + assert_size(4, ==, nread); idx = router.match_prefix(&nread, &node, StringRef::from_lit("ahpla.ovarb")); - CU_ASSERT(3 == idx); - CU_ASSERT(6 == nread); + assert_ssize(3, ==, idx); + assert_ssize(6, ==, nread); } } // namespace shrpx diff --git a/src/shrpx_router_test.h b/src/shrpx_router_test.h index d39cb87..04d4c45 100644 --- a/src/shrpx_router_test.h +++ b/src/shrpx_router_test.h @@ -29,11 +29,17 @@ # include <config.h> #endif // HAVE_CONFIG_H +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + namespace shrpx { -void test_shrpx_router_match(void); -void test_shrpx_router_match_wildcard(void); -void test_shrpx_router_match_prefix(void); +extern const MunitSuite router_suite; + +munit_void_test_decl(test_shrpx_router_match); +munit_void_test_decl(test_shrpx_router_match_wildcard); +munit_void_test_decl(test_shrpx_router_match_prefix); } // namespace shrpx diff --git a/src/shrpx_tls.cc b/src/shrpx_tls.cc index aa0c9f2..10bbbf2 100644 --- a/src/shrpx_tls.cc +++ b/src/shrpx_tls.cc @@ -72,6 +72,11 @@ # endif // HAVE_LIBNGTCP2_CRYPTO_BORINGSSL #endif // ENABLE_HTTP3 +#ifdef HAVE_LIBBROTLI +# include <brotli/encode.h> +# include <brotli/decode.h> +#endif // HAVE_LIBBROTLI + #include "shrpx_log.h" #include "shrpx_client_handler.h" #include "shrpx_config.h" @@ -158,6 +163,35 @@ int ssl_pem_passwd_cb(char *buf, int size, int rwflag, void *user_data) { } // namespace namespace { +std::shared_ptr<std::vector<uint8_t>> +get_ocsp_data(TLSContextData *tls_ctx_data) { +#ifdef HAVE_ATOMIC_STD_SHARED_PTR + return std::atomic_load_explicit(&tls_ctx_data->ocsp_data, + std::memory_order_acquire); +#else // !HAVE_ATOMIC_STD_SHARED_PTR + std::lock_guard<std::mutex> g(tls_ctx_data->mu); + return tls_ctx_data->ocsp_data; +#endif // !HAVE_ATOMIC_STD_SHARED_PTR +} +} // namespace + +namespace { +void set_ocsp_response(SSL *ssl) { +#ifdef NGHTTP2_OPENSSL_IS_BORINGSSL + auto tls_ctx_data = + static_cast<TLSContextData *>(SSL_CTX_get_app_data(SSL_get_SSL_CTX(ssl))); + auto data = get_ocsp_data(tls_ctx_data); + + if (!data) { + return; + } + + SSL_set_ocsp_response(ssl, data->data(), data->size()); +#endif // NGHTTP2_OPENSSL_IS_BORINGSSL +} +} // namespace + +namespace { // *al is set to SSL_AD_UNRECOGNIZED_NAME by openssl, so we don't have // to set it explicitly. int servername_callback(SSL *ssl, int *al, void *arg) { @@ -167,12 +201,16 @@ int servername_callback(SSL *ssl, int *al, void *arg) { auto rawhost = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name); if (rawhost == nullptr) { + set_ocsp_response(ssl); + return SSL_TLSEXT_ERR_NOACK; } auto len = strlen(rawhost); // NI_MAXHOST includes terminal NULL. if (len == 0 || len + 1 > NI_MAXHOST) { + set_ocsp_response(ssl); + return SSL_TLSEXT_ERR_NOACK; } @@ -194,6 +232,8 @@ int servername_callback(SSL *ssl, int *al, void *arg) { auto idx = cert_tree->lookup(hostname); if (idx == -1) { + set_ocsp_response(ssl); + return SSL_TLSEXT_ERR_NOACK; } @@ -290,25 +330,14 @@ int servername_callback(SSL *ssl, int *al, void *arg) { SSL_set_SSL_CTX(ssl, ssl_ctx_list[0]); + set_ocsp_response(ssl); + return SSL_TLSEXT_ERR_OK; } } // namespace #ifndef NGHTTP2_OPENSSL_IS_BORINGSSL namespace { -std::shared_ptr<std::vector<uint8_t>> -get_ocsp_data(TLSContextData *tls_ctx_data) { -# ifdef HAVE_ATOMIC_STD_SHARED_PTR - return std::atomic_load_explicit(&tls_ctx_data->ocsp_data, - std::memory_order_acquire); -# else // !HAVE_ATOMIC_STD_SHARED_PTR - std::lock_guard<std::mutex> g(tls_ctx_data->mu); - return tls_ctx_data->ocsp_data; -# endif // !HAVE_ATOMIC_STD_SHARED_PTR -} -} // namespace - -namespace { int ocsp_resp_cb(SSL *ssl, void *arg) { auto ssl_ctx = SSL_get_SSL_CTX(ssl); auto tls_ctx_data = @@ -817,6 +846,83 @@ unsigned int psk_client_cb(SSL *ssl, const char *hint, char *identity_out, } // namespace #endif // !OPENSSL_NO_PSK +#if defined(NGHTTP2_OPENSSL_IS_BORINGSSL) && defined(HAVE_LIBBROTLI) +namespace { +int cert_compress(SSL *ssl, CBB *out, const uint8_t *in, size_t in_len) { + uint8_t *dest; + + size_t compressed_size = BrotliEncoderMaxCompressedSize(in_len); + if (compressed_size == 0) { + LOG(ERROR) << "BrotliEncoderMaxCompressedSize failed"; + + return 0; + } + + if (LOG_ENABLED(INFO)) { + LOG(INFO) << "Maximum compressed size is " << compressed_size + << " bytes against input " << in_len << " bytes"; + } + + if (!CBB_reserve(out, &dest, compressed_size)) { + LOG(ERROR) << "CBB_reserve failed"; + + return 0; + } + + if (BrotliEncoderCompress(BROTLI_MAX_QUALITY, BROTLI_DEFAULT_WINDOW, + BROTLI_MODE_GENERIC, in_len, in, &compressed_size, + dest) != BROTLI_TRUE) { + LOG(ERROR) << "BrotliEncoderCompress failed"; + + return 0; + } + + if (LOG_ENABLED(INFO)) { + LOG(INFO) << "BrotliEncoderCompress succeeded, produced " << compressed_size + << " bytes, " << (in_len - compressed_size) * 100 / in_len + << "% reduction"; + } + + if (!CBB_did_write(out, compressed_size)) { + LOG(ERROR) << "CBB_did_write failed"; + + return 0; + } + + return 1; +} + +int cert_decompress(SSL *ssl, CRYPTO_BUFFER **out, size_t uncompressed_len, + const uint8_t *in, size_t in_len) { + uint8_t *dest; + auto buf = CRYPTO_BUFFER_alloc(&dest, uncompressed_len); + auto len = uncompressed_len; + + if (BrotliDecoderDecompress(in_len, in, &len, dest) != + BROTLI_DECODER_RESULT_SUCCESS) { + LOG(ERROR) << "BrotliDecoderDecompress failed"; + + CRYPTO_BUFFER_free(buf); + + return 0; + } + + if (uncompressed_len != len) { + LOG(ERROR) << "Unexpected uncompressed length: expected " + << uncompressed_len << " bytes, actual " << len << " bytes"; + + CRYPTO_BUFFER_free(buf); + + return 0; + } + + *out = buf; + + return 1; +} +} // namespace +#endif // NGHTTP2_OPENSSL_IS_BORINGSSL && HAVE_LIBBROTLI + struct TLSProtocol { StringRef name; long int mask; @@ -1110,6 +1216,15 @@ SSL_CTX *create_ssl_context(const char *private_key_file, const char *cert_file, SSL_CTX_set_psk_server_callback(ssl_ctx, psk_server_cb); #endif // !LIBRESSL_NO_PSK +#if defined(NGHTTP2_OPENSSL_IS_BORINGSSL) && defined(HAVE_LIBBROTLI) + if (!SSL_CTX_add_cert_compression_alg( + ssl_ctx, nghttp2::tls::CERTIFICATE_COMPRESSION_ALGO_BROTLI, + cert_compress, cert_decompress)) { + LOG(FATAL) << "SSL_CTX_add_cert_compression_alg failed"; + DIE(); + } +#endif // NGHTTP2_OPENSSL_IS_BORINGSSL && HAVE_LIBBROTLI + return ssl_ctx; } @@ -1369,6 +1484,15 @@ SSL_CTX *create_quic_ssl_context(const char *private_key_file, SSL_CTX_set_psk_server_callback(ssl_ctx, psk_server_cb); # endif // !LIBRESSL_NO_PSK +# if defined(NGHTTP2_OPENSSL_IS_BORINGSSL) && defined(HAVE_LIBBROTLI) + if (!SSL_CTX_add_cert_compression_alg( + ssl_ctx, nghttp2::tls::CERTIFICATE_COMPRESSION_ALGO_BROTLI, + cert_compress, cert_decompress)) { + LOG(FATAL) << "SSL_CTX_add_cert_compression_alg failed"; + DIE(); + } +# endif // NGHTTP2_OPENSSL_IS_BORINGSSL && HAVE_LIBBROTLI + return ssl_ctx; } #endif // ENABLE_HTTP3 @@ -1478,6 +1602,15 @@ SSL_CTX *create_ssl_client_context( SSL_CTX_set_psk_client_callback(ssl_ctx, psk_client_cb); #endif // !OPENSSL_NO_PSK +#if defined(NGHTTP2_OPENSSL_IS_BORINGSSL) && defined(HAVE_LIBBROTLI) + if (!SSL_CTX_add_cert_compression_alg( + ssl_ctx, nghttp2::tls::CERTIFICATE_COMPRESSION_ALGO_BROTLI, + cert_compress, cert_decompress)) { + LOG(FATAL) << "SSL_CTX_add_cert_compression_alg failed"; + DIE(); + } +#endif // NGHTTP2_OPENSSL_IS_BORINGSSL && HAVE_LIBBROTLI + return ssl_ctx; } diff --git a/src/shrpx_tls_test.cc b/src/shrpx_tls_test.cc index 02fb168..04d16da 100644 --- a/src/shrpx_tls_test.cc +++ b/src/shrpx_tls_test.cc @@ -24,7 +24,7 @@ */ #include "shrpx_tls_test.h" -#include <CUnit/CUnit.h> +#include "munitxx.h" #include "shrpx_tls.h" #include "shrpx_log.h" @@ -35,6 +35,21 @@ using namespace nghttp2; namespace shrpx { +namespace { +const MunitTest tests[]{ + munit_void_test(test_shrpx_tls_create_lookup_tree), + munit_void_test(test_shrpx_tls_cert_lookup_tree_add_ssl_ctx), + munit_void_test(test_shrpx_tls_tls_hostname_match), + munit_void_test(test_shrpx_tls_verify_numeric_hostname), + munit_void_test(test_shrpx_tls_verify_dns_hostname), + munit_test_end(), +}; +} // namespace + +const MunitSuite tls_suite{ + "/tls", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_shrpx_tls_create_lookup_tree(void) { auto tree = std::make_unique<tls::CertLookupTree>(); @@ -58,24 +73,24 @@ void test_shrpx_tls_create_lookup_tree(void) { tree->dump(); - CU_ASSERT(0 == tree->lookup(hostnames[0])); - CU_ASSERT(1 == tree->lookup(hostnames[1])); - CU_ASSERT(2 == tree->lookup(StringRef::from_lit("2www.example.org"))); - CU_ASSERT(-1 == tree->lookup(StringRef::from_lit("www2.example.org"))); - CU_ASSERT(3 == tree->lookup(StringRef::from_lit("xy1.host.domain"))); + assert_ssize(0, ==, tree->lookup(hostnames[0])); + assert_ssize(1, ==, tree->lookup(hostnames[1])); + assert_ssize(2, ==, tree->lookup(StringRef::from_lit("2www.example.org"))); + assert_ssize(-1, ==, tree->lookup(StringRef::from_lit("www2.example.org"))); + assert_ssize(3, ==, tree->lookup(StringRef::from_lit("xy1.host.domain"))); // Does not match *yy.host.domain, because * must match at least 1 // character. - CU_ASSERT(-1 == tree->lookup(StringRef::from_lit("yy.host.domain"))); - CU_ASSERT(4 == tree->lookup(StringRef::from_lit("xyy.host.domain"))); - CU_ASSERT(-1 == tree->lookup(StringRef{})); - CU_ASSERT(5 == tree->lookup(hostnames[5])); - CU_ASSERT(6 == tree->lookup(hostnames[6])); + assert_ssize(-1, ==, tree->lookup(StringRef::from_lit("yy.host.domain"))); + assert_ssize(4, ==, tree->lookup(StringRef::from_lit("xyy.host.domain"))); + assert_ssize(-1, ==, tree->lookup(StringRef{})); + assert_ssize(5, ==, tree->lookup(hostnames[5])); + assert_ssize(6, ==, tree->lookup(hostnames[6])); static constexpr char h6[] = "pdylay.sourceforge.net"; for (int i = 0; i < 7; ++i) { - CU_ASSERT(-1 == tree->lookup(StringRef{h6 + i, str_size(h6) - i})); + assert_ssize(-1, ==, tree->lookup(StringRef{h6 + i, str_size(h6) - i})); } - CU_ASSERT(8 == tree->lookup(StringRef::from_lit("x.foo.bar"))); - CU_ASSERT(9 == tree->lookup(hostnames[9])); + assert_ssize(8, ==, tree->lookup(StringRef::from_lit("x.foo.bar"))); + assert_ssize(9, ==, tree->lookup(hostnames[9])); constexpr StringRef names[] = { StringRef::from_lit("rab"), // 1 @@ -90,7 +105,7 @@ void test_shrpx_tls_create_lookup_tree(void) { tree->add_cert(names[idx], idx); } for (size_t i = 0; i < num; ++i) { - CU_ASSERT((ssize_t)i == tree->lookup(names[i])); + assert_ssize((ssize_t)i, ==, tree->lookup(names[i])); } } @@ -128,7 +143,7 @@ void test_shrpx_tls_cert_lookup_tree_add_ssl_ctx(void) { SSL_CTX_set_app_data(nghttp2_ssl_ctx, nghttp2_tls_ctx_data.get()); rv = SSL_CTX_use_certificate_chain_file(nghttp2_ssl_ctx, nghttp2_certfile); - CU_ASSERT(1 == rv); + assert_int(1, ==, rv); static constexpr char examples_certfile[] = NGHTTP2_SRC_DIR "/test.example.com.pem"; @@ -139,7 +154,7 @@ void test_shrpx_tls_cert_lookup_tree_add_ssl_ctx(void) { SSL_CTX_set_app_data(examples_ssl_ctx, examples_tls_ctx_data.get()); rv = SSL_CTX_use_certificate_chain_file(examples_ssl_ctx, examples_certfile); - CU_ASSERT(1 == rv); + assert_int(1, ==, rv); tls::CertLookupTree tree; std::vector<std::vector<SSL_CTX *>> indexed_ssl_ctx; @@ -147,18 +162,19 @@ void test_shrpx_tls_cert_lookup_tree_add_ssl_ctx(void) { rv = tls::cert_lookup_tree_add_ssl_ctx(&tree, indexed_ssl_ctx, nghttp2_ssl_ctx); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); rv = tls::cert_lookup_tree_add_ssl_ctx(&tree, indexed_ssl_ctx, examples_ssl_ctx); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); - CU_ASSERT(-1 == tree.lookup(StringRef::from_lit("not-used.nghttp2.org"))); - CU_ASSERT(0 == tree.lookup(StringRef::from_lit("test.nghttp2.org"))); - CU_ASSERT(1 == tree.lookup(StringRef::from_lit("w.test.nghttp2.org"))); - CU_ASSERT(2 == tree.lookup(StringRef::from_lit("www.test.nghttp2.org"))); - CU_ASSERT(3 == tree.lookup(StringRef::from_lit("test.example.com"))); + assert_ssize(-1, ==, + tree.lookup(StringRef::from_lit("not-used.nghttp2.org"))); + assert_ssize(0, ==, tree.lookup(StringRef::from_lit("test.nghttp2.org"))); + assert_ssize(1, ==, tree.lookup(StringRef::from_lit("w.test.nghttp2.org"))); + assert_ssize(2, ==, tree.lookup(StringRef::from_lit("www.test.nghttp2.org"))); + assert_ssize(3, ==, tree.lookup(StringRef::from_lit("test.example.com"))); } template <size_t N, size_t M> @@ -168,30 +184,32 @@ bool tls_hostname_match_wrapper(const char (&pattern)[N], } void test_shrpx_tls_tls_hostname_match(void) { - CU_ASSERT(tls_hostname_match_wrapper("example.com", "example.com")); - CU_ASSERT(tls_hostname_match_wrapper("example.com", "EXAMPLE.com")); + assert_true(tls_hostname_match_wrapper("example.com", "example.com")); + assert_true(tls_hostname_match_wrapper("example.com", "EXAMPLE.com")); // check wildcard - CU_ASSERT(tls_hostname_match_wrapper("*.example.com", "www.example.com")); - CU_ASSERT(tls_hostname_match_wrapper("*w.example.com", "www.example.com")); - CU_ASSERT(tls_hostname_match_wrapper("www*.example.com", "www1.example.com")); - CU_ASSERT( + assert_true(tls_hostname_match_wrapper("*.example.com", "www.example.com")); + assert_true(tls_hostname_match_wrapper("*w.example.com", "www.example.com")); + assert_true( + tls_hostname_match_wrapper("www*.example.com", "www1.example.com")); + assert_true( tls_hostname_match_wrapper("www*.example.com", "WWW12.EXAMPLE.com")); // at least 2 dots are required after '*' - CU_ASSERT(!tls_hostname_match_wrapper("*.com", "example.com")); - CU_ASSERT(!tls_hostname_match_wrapper("*", "example.com")); + assert_false(tls_hostname_match_wrapper("*.com", "example.com")); + assert_false(tls_hostname_match_wrapper("*", "example.com")); // '*' must be in left most label - CU_ASSERT( - !tls_hostname_match_wrapper("blog.*.example.com", "blog.my.example.com")); + assert_false( + tls_hostname_match_wrapper("blog.*.example.com", "blog.my.example.com")); // prefix is wrong - CU_ASSERT( - !tls_hostname_match_wrapper("client*.example.com", "server.example.com")); + assert_false( + tls_hostname_match_wrapper("client*.example.com", "server.example.com")); // '*' must match at least one character - CU_ASSERT(!tls_hostname_match_wrapper("www*.example.com", "www.example.com")); + assert_false( + tls_hostname_match_wrapper("www*.example.com", "www.example.com")); - CU_ASSERT(!tls_hostname_match_wrapper("example.com", "nghttp2.org")); - CU_ASSERT(!tls_hostname_match_wrapper("www.example.com", "example.com")); - CU_ASSERT(!tls_hostname_match_wrapper("example.com", "www.example.com")); + assert_false(tls_hostname_match_wrapper("example.com", "nghttp2.org")); + assert_false(tls_hostname_match_wrapper("www.example.com", "example.com")); + assert_false(tls_hostname_match_wrapper("example.com", "www.example.com")); } static X509 *load_cert(const char *path) { @@ -207,14 +225,17 @@ static Address parse_addr(const char *ipaddr) { addrinfo hints{}; hints.ai_family = AF_UNSPEC; - hints.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV; + hints.ai_flags = AI_NUMERICHOST; +#ifdef AI_NUMERICSERV + hints.ai_flags |= AI_NUMERICSERV; +#endif addrinfo *res = nullptr; auto rv = getaddrinfo(ipaddr, "443", &hints, &res); - CU_ASSERT(0 == rv); - CU_ASSERT(nullptr != res); + assert_int(0, ==, rv); + assert_not_null(res); Address addr; addr.len = res->ai_addrlen; @@ -234,7 +255,7 @@ void test_shrpx_tls_verify_numeric_hostname(void) { auto rv = tls::verify_numeric_hostname(cert, StringRef::from_lit(ipaddr), &addr); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); X509_free(cert); } @@ -247,7 +268,7 @@ void test_shrpx_tls_verify_numeric_hostname(void) { auto rv = tls::verify_numeric_hostname(cert, StringRef::from_lit(ipaddr), &addr); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); X509_free(cert); } @@ -260,7 +281,7 @@ void test_shrpx_tls_verify_numeric_hostname(void) { auto rv = tls::verify_numeric_hostname(cert, StringRef::from_lit(ipaddr), &addr); - CU_ASSERT(-1 == rv); + assert_int(-1, ==, rv); X509_free(cert); } @@ -273,7 +294,7 @@ void test_shrpx_tls_verify_numeric_hostname(void) { auto rv = tls::verify_numeric_hostname(cert, StringRef::from_lit(ipaddr), &addr); - CU_ASSERT(-1 == rv); + assert_int(-1, ==, rv); X509_free(cert); } @@ -286,7 +307,7 @@ void test_shrpx_tls_verify_numeric_hostname(void) { auto rv = tls::verify_numeric_hostname(cert, StringRef::from_lit(ipaddr), &addr); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); X509_free(cert); } @@ -299,7 +320,7 @@ void test_shrpx_tls_verify_dns_hostname(void) { auto rv = tls::verify_dns_hostname( cert, StringRef::from_lit("nghttp2.example.com")); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); X509_free(cert); } @@ -310,7 +331,7 @@ void test_shrpx_tls_verify_dns_hostname(void) { auto rv = tls::verify_dns_hostname( cert, StringRef::from_lit("www.nghttp2.example.com")); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); X509_free(cert); } @@ -320,7 +341,7 @@ void test_shrpx_tls_verify_dns_hostname(void) { auto cert = load_cert(NGHTTP2_SRC_DIR "/testdata/verify_hostname.crt"); auto rv = tls::verify_dns_hostname(cert, StringRef::from_lit("localhost")); - CU_ASSERT(-1 == rv); + assert_int(-1, ==, rv); X509_free(cert); } @@ -330,7 +351,7 @@ void test_shrpx_tls_verify_dns_hostname(void) { auto cert = load_cert(NGHTTP2_SRC_DIR "/testdata/nosan.crt"); auto rv = tls::verify_dns_hostname(cert, StringRef::from_lit("localhost")); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); X509_free(cert); } diff --git a/src/shrpx_tls_test.h b/src/shrpx_tls_test.h index 7edc742..3334b23 100644 --- a/src/shrpx_tls_test.h +++ b/src/shrpx_tls_test.h @@ -29,13 +29,19 @@ # include <config.h> #endif // HAVE_CONFIG_H +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + namespace shrpx { -void test_shrpx_tls_create_lookup_tree(void); -void test_shrpx_tls_cert_lookup_tree_add_ssl_ctx(void); -void test_shrpx_tls_tls_hostname_match(void); -void test_shrpx_tls_verify_numeric_hostname(void); -void test_shrpx_tls_verify_dns_hostname(void); +extern const MunitSuite tls_suite; + +munit_void_test_decl(test_shrpx_tls_create_lookup_tree); +munit_void_test_decl(test_shrpx_tls_cert_lookup_tree_add_ssl_ctx); +munit_void_test_decl(test_shrpx_tls_tls_hostname_match); +munit_void_test_decl(test_shrpx_tls_verify_numeric_hostname); +munit_void_test_decl(test_shrpx_tls_verify_dns_hostname); } // namespace shrpx diff --git a/src/shrpx_worker.cc b/src/shrpx_worker.cc index 4c069db..e7d6740 100644 --- a/src/shrpx_worker.cc +++ b/src/shrpx_worker.cc @@ -731,6 +731,119 @@ int Worker::setup_quic_server_socket() { return 0; } +# ifdef HAVE_LIBBPF +namespace { +// https://github.com/kokke/tiny-AES-c +// +// License is Public Domain. +// Commit hash: 12e7744b4919e9d55de75b7ab566326a1c8e7a67 + +// The number of columns comprising a state in AES. This is a constant +// in AES. Value=4 +# define Nb 4 + +# define Nk 4 // The number of 32 bit words in a key. +# define Nr 10 // The number of rounds in AES Cipher. + +// The lookup-tables are marked const so they can be placed in +// read-only storage instead of RAM The numbers below can be computed +// dynamically trading ROM for RAM - This can be useful in (embedded) +// bootloader applications, where ROM is often limited. +const uint8_t sbox[256] = { + // 0 1 2 3 4 5 6 7 8 9 A B C D E F + 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, + 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, + 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26, + 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, + 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, + 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, + 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed, + 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, + 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, + 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, + 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec, + 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, + 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, + 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, + 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d, + 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, + 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, + 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, + 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11, + 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, + 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, + 0xb0, 0x54, 0xbb, 0x16}; + +# define getSBoxValue(num) (sbox[(num)]) + +// The round constant word array, Rcon[i], contains the values given +// by x to the power (i-1) being powers of x (x is denoted as {02}) in +// the field GF(2^8) +const uint8_t Rcon[11] = {0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, + 0x20, 0x40, 0x80, 0x1b, 0x36}; + +// This function produces Nb(Nr+1) round keys. The round keys are used +// in each round to decrypt the states. +void KeyExpansion(uint8_t *RoundKey, const uint8_t *Key) { + unsigned i, j, k; + uint8_t tempa[4]; // Used for the column/row operations + + // The first round key is the key itself. + for (i = 0; i < Nk; ++i) { + RoundKey[(i * 4) + 0] = Key[(i * 4) + 0]; + RoundKey[(i * 4) + 1] = Key[(i * 4) + 1]; + RoundKey[(i * 4) + 2] = Key[(i * 4) + 2]; + RoundKey[(i * 4) + 3] = Key[(i * 4) + 3]; + } + + // All other round keys are found from the previous round keys. + for (i = Nk; i < Nb * (Nr + 1); ++i) { + { + k = (i - 1) * 4; + tempa[0] = RoundKey[k + 0]; + tempa[1] = RoundKey[k + 1]; + tempa[2] = RoundKey[k + 2]; + tempa[3] = RoundKey[k + 3]; + } + + if (i % Nk == 0) { + // This function shifts the 4 bytes in a word to the left once. + // [a0,a1,a2,a3] becomes [a1,a2,a3,a0] + + // Function RotWord() + { + const uint8_t u8tmp = tempa[0]; + tempa[0] = tempa[1]; + tempa[1] = tempa[2]; + tempa[2] = tempa[3]; + tempa[3] = u8tmp; + } + + // SubWord() is a function that takes a four-byte input word and + // applies the S-box to each of the four bytes to produce an + // output word. + + // Function Subword() + { + tempa[0] = getSBoxValue(tempa[0]); + tempa[1] = getSBoxValue(tempa[1]); + tempa[2] = getSBoxValue(tempa[2]); + tempa[3] = getSBoxValue(tempa[3]); + } + + tempa[0] = tempa[0] ^ Rcon[i / Nk]; + } + j = i * 4; + k = (i - Nk) * 4; + RoundKey[j + 0] = RoundKey[k + 0] ^ tempa[0]; + RoundKey[j + 1] = RoundKey[k + 1] ^ tempa[1]; + RoundKey[j + 2] = RoundKey[k + 2] ^ tempa[2]; + RoundKey[j + 3] = RoundKey[k + 3] ^ tempa[3]; + } +} +} // namespace +# endif // HAVE_LIBBPF + int Worker::create_quic_server_socket(UpstreamAddr &faddr) { std::array<char, STRERROR_BUFSIZE> errbuf; int fd = -1; @@ -989,30 +1102,29 @@ int Worker::create_quic_server_socket(UpstreamAddr &faddr) { return -1; } - constexpr uint32_t key_high_idx = 1; - constexpr uint32_t key_low_idx = 2; - auto &qkms = conn_handler_->get_quic_keying_materials(); auto &qkm = qkms->keying_materials.front(); - rv = bpf_map__update_elem(sk_info, &key_high_idx, sizeof(key_high_idx), - qkm.cid_encryption_key.data(), - qkm.cid_encryption_key.size() / 2, BPF_ANY); - if (rv != 0) { + auto aes_key = bpf_object__find_map_by_name(obj, "aes_key"); + if (!aes_key) { auto error = errno; - LOG(FATAL) << "Failed to update key_high_idx sk_info: " + LOG(FATAL) << "Failed to get aes_key: " << xsi_strerror(error, errbuf.data(), errbuf.size()); close(fd); return -1; } - rv = bpf_map__update_elem(sk_info, &key_low_idx, sizeof(key_low_idx), - qkm.cid_encryption_key.data() + - qkm.cid_encryption_key.size() / 2, - qkm.cid_encryption_key.size() / 2, BPF_ANY); + constexpr size_t expanded_aes_keylen = 176; + std::array<uint8_t, expanded_aes_keylen> aes_exp_key; + + KeyExpansion(aes_exp_key.data(), qkm.cid_encryption_key.data()); + + rv = + bpf_map__update_elem(aes_key, &zero, sizeof(zero), aes_exp_key.data(), + aes_exp_key.size(), BPF_ANY); if (rv != 0) { auto error = errno; - LOG(FATAL) << "Failed to update key_low_idx sk_info: " + LOG(FATAL) << "Failed to update aes_key: " << xsi_strerror(error, errbuf.data(), errbuf.size()); close(fd); return -1; diff --git a/src/shrpx_worker_process.cc b/src/shrpx_worker_process.cc index 05eac02..e3f7dae 100644 --- a/src/shrpx_worker_process.cc +++ b/src/shrpx_worker_process.cc @@ -583,6 +583,16 @@ int worker_process_event_loop(WorkerProcessConfig *wpconf) { LOG(ERROR) << "Failed to generate QUIC Connection ID encryption key"; return -1; } + + qkm.cid_encryption_ctx = EVP_CIPHER_CTX_new(); + if (!EVP_EncryptInit_ex(qkm.cid_encryption_ctx, EVP_aes_128_ecb(), nullptr, + qkm.cid_encryption_key.data(), nullptr)) { + LOG(ERROR) + << "Failed to initialize QUIC Connection ID encryption context"; + return -1; + } + + EVP_CIPHER_CTX_set_padding(qkm.cid_encryption_ctx, 0); } conn_handler->set_quic_keying_materials(std::move(qkms)); diff --git a/src/shrpx_worker_test.cc b/src/shrpx_worker_test.cc index 7c5c329..4b4b7a6 100644 --- a/src/shrpx_worker_test.cc +++ b/src/shrpx_worker_test.cc @@ -30,7 +30,7 @@ #include <cstdlib> -#include <CUnit/CUnit.h> +#include "munitxx.h" #include "shrpx_worker.h" #include "shrpx_connect_blocker.h" @@ -38,6 +38,17 @@ namespace shrpx { +namespace { +const MunitTest tests[]{ + munit_void_test(test_shrpx_worker_match_downstream_addr_group), + munit_test_end(), +}; +} // namespace + +const MunitSuite worker_suite{ + "/worker", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_shrpx_worker_match_downstream_addr_group(void) { auto groups = std::vector<std::shared_ptr<DownstreamAddrGroup>>(); for (auto &s : {"nghttp2.org/", "nghttp2.org/alpha/bravo/", @@ -62,131 +73,155 @@ void test_shrpx_worker_match_downstream_addr_group(void) { router.add_route(StringRef{g->pattern}, i); } - CU_ASSERT(0 == match_downstream_addr_group( - routerconf, StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/"), groups, 255, balloc)); + assert_size(0, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/"), groups, 255, balloc)); // port is removed - CU_ASSERT(0 == match_downstream_addr_group( - routerconf, StringRef::from_lit("nghttp2.org:8080"), - StringRef::from_lit("/"), groups, 255, balloc)); + assert_size(0, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("nghttp2.org:8080"), + StringRef::from_lit("/"), groups, 255, balloc)); // host is case-insensitive - CU_ASSERT(4 == match_downstream_addr_group( - routerconf, StringRef::from_lit("WWW.nghttp2.org"), - StringRef::from_lit("/alpha"), groups, 255, balloc)); + assert_size(4, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("WWW.nghttp2.org"), + StringRef::from_lit("/alpha"), groups, 255, balloc)); - CU_ASSERT(1 == match_downstream_addr_group( - routerconf, StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/alpha/bravo/"), groups, 255, - balloc)); + assert_size(1, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/alpha/bravo/"), groups, 255, balloc)); // /alpha/bravo also matches /alpha/bravo/ - CU_ASSERT(1 == match_downstream_addr_group( - routerconf, StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/alpha/bravo"), groups, 255, balloc)); + assert_size(1, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/alpha/bravo"), groups, 255, balloc)); // path part is case-sensitive - CU_ASSERT(0 == match_downstream_addr_group( - routerconf, StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/Alpha/bravo"), groups, 255, balloc)); - - CU_ASSERT(1 == match_downstream_addr_group( - routerconf, StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/alpha/bravo/charlie"), groups, 255, - balloc)); - - CU_ASSERT(2 == match_downstream_addr_group( - routerconf, StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/alpha/charlie"), groups, 255, - balloc)); + assert_size(0, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/Alpha/bravo"), groups, 255, balloc)); + + assert_size(1, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/alpha/bravo/charlie"), groups, 255, + balloc)); + + assert_size(2, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/alpha/charlie"), groups, 255, balloc)); // pattern which does not end with '/' must match its entirely. So // this matches to group 0, not group 2. - CU_ASSERT(0 == match_downstream_addr_group( - routerconf, StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/alpha/charlie/"), groups, 255, - balloc)); - - CU_ASSERT(255 == match_downstream_addr_group( - routerconf, StringRef::from_lit("example.org"), - StringRef::from_lit("/"), groups, 255, balloc)); - - CU_ASSERT(255 == match_downstream_addr_group( - routerconf, StringRef::from_lit(""), - StringRef::from_lit("/"), groups, 255, balloc)); - - CU_ASSERT(255 == match_downstream_addr_group( - routerconf, StringRef::from_lit(""), - StringRef::from_lit("alpha"), groups, 255, balloc)); - - CU_ASSERT(255 == match_downstream_addr_group( - routerconf, StringRef::from_lit("foo/bar"), - StringRef::from_lit("/"), groups, 255, balloc)); + assert_size(0, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/alpha/charlie/"), groups, 255, balloc)); + + assert_size(255, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("example.org"), + StringRef::from_lit("/"), groups, 255, balloc)); + + assert_size(255, ==, + match_downstream_addr_group(routerconf, StringRef::from_lit(""), + StringRef::from_lit("/"), groups, 255, + balloc)); + + assert_size(255, ==, + match_downstream_addr_group(routerconf, StringRef::from_lit(""), + StringRef::from_lit("alpha"), groups, + 255, balloc)); + + assert_size(255, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("foo/bar"), + StringRef::from_lit("/"), groups, 255, balloc)); // If path is StringRef::from_lit("*", only match with host + "/"). - CU_ASSERT(0 == match_downstream_addr_group( - routerconf, StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("*"), groups, 255, balloc)); - - CU_ASSERT(5 == match_downstream_addr_group( - routerconf, StringRef::from_lit("[::1]"), - StringRef::from_lit("/"), groups, 255, balloc)); - CU_ASSERT(5 == match_downstream_addr_group( - routerconf, StringRef::from_lit("[::1]:8080"), - StringRef::from_lit("/"), groups, 255, balloc)); - CU_ASSERT(255 == match_downstream_addr_group( - routerconf, StringRef::from_lit("[::1"), - StringRef::from_lit("/"), groups, 255, balloc)); - CU_ASSERT(255 == match_downstream_addr_group( - routerconf, StringRef::from_lit("[::1]8000"), - StringRef::from_lit("/"), groups, 255, balloc)); + assert_size(0, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("*"), groups, 255, balloc)); + + assert_size(5, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("[::1]"), + StringRef::from_lit("/"), groups, 255, balloc)); + assert_size(5, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("[::1]:8080"), + StringRef::from_lit("/"), groups, 255, balloc)); + assert_size(255, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("[::1"), + StringRef::from_lit("/"), groups, 255, balloc)); + assert_size(255, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("[::1]8000"), + StringRef::from_lit("/"), groups, 255, balloc)); // Check the case where adding route extends tree - CU_ASSERT(6 == match_downstream_addr_group( - routerconf, StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/alpha/bravo/delta"), groups, 255, - balloc)); - - CU_ASSERT(1 == match_downstream_addr_group( - routerconf, StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/alpha/bravo/delta/"), groups, 255, - balloc)); + assert_size(6, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/alpha/bravo/delta"), groups, 255, + balloc)); + + assert_size(1, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/alpha/bravo/delta/"), groups, 255, + balloc)); // Check the case where query is done in a single node - CU_ASSERT(7 == match_downstream_addr_group( - routerconf, StringRef::from_lit("example.com"), - StringRef::from_lit("/alpha/bravo"), groups, 255, balloc)); + assert_size(7, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("example.com"), + StringRef::from_lit("/alpha/bravo"), groups, 255, balloc)); - CU_ASSERT(255 == match_downstream_addr_group( - routerconf, StringRef::from_lit("example.com"), - StringRef::from_lit("/alpha/bravo/"), groups, 255, - balloc)); + assert_size(255, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("example.com"), + StringRef::from_lit("/alpha/bravo/"), groups, 255, balloc)); - CU_ASSERT(255 == match_downstream_addr_group( - routerconf, StringRef::from_lit("example.com"), - StringRef::from_lit("/alpha"), groups, 255, balloc)); + assert_size(255, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("example.com"), + StringRef::from_lit("/alpha"), groups, 255, balloc)); // Check the case where quey is done in a single node - CU_ASSERT(8 == match_downstream_addr_group( - routerconf, StringRef::from_lit("192.168.0.1"), - StringRef::from_lit("/alpha"), groups, 255, balloc)); - - CU_ASSERT(8 == match_downstream_addr_group( - routerconf, StringRef::from_lit("192.168.0.1"), - StringRef::from_lit("/alpha/"), groups, 255, balloc)); - - CU_ASSERT(8 == match_downstream_addr_group( - routerconf, StringRef::from_lit("192.168.0.1"), - StringRef::from_lit("/alpha/bravo"), groups, 255, balloc)); - - CU_ASSERT(255 == match_downstream_addr_group( - routerconf, StringRef::from_lit("192.168.0.1"), - StringRef::from_lit("/alph"), groups, 255, balloc)); - - CU_ASSERT(255 == match_downstream_addr_group( - routerconf, StringRef::from_lit("192.168.0.1"), - StringRef::from_lit("/"), groups, 255, balloc)); + assert_size(8, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("192.168.0.1"), + StringRef::from_lit("/alpha"), groups, 255, balloc)); + + assert_size(8, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("192.168.0.1"), + StringRef::from_lit("/alpha/"), groups, 255, balloc)); + + assert_size(8, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("192.168.0.1"), + StringRef::from_lit("/alpha/bravo"), groups, 255, balloc)); + + assert_size(255, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("192.168.0.1"), + StringRef::from_lit("/alph"), groups, 255, balloc)); + + assert_size(255, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("192.168.0.1"), + StringRef::from_lit("/"), groups, 255, balloc)); // Test for wildcard hosts auto g1 = std::make_shared<DownstreamAddrGroup>(); @@ -214,34 +249,40 @@ void test_shrpx_worker_match_downstream_addr_group(void) { wcrouter.add_route(StringRef::from_lit("lacol."), 2); wp.back().router.add_route(StringRef::from_lit("/"), 13); - CU_ASSERT(11 == match_downstream_addr_group( - routerconf, StringRef::from_lit("git.nghttp2.org"), - StringRef::from_lit("/echo"), groups, 255, balloc)); - - CU_ASSERT(10 == match_downstream_addr_group( - routerconf, StringRef::from_lit("0git.nghttp2.org"), - StringRef::from_lit("/echo"), groups, 255, balloc)); - - CU_ASSERT(11 == match_downstream_addr_group( - routerconf, StringRef::from_lit("it.nghttp2.org"), - StringRef::from_lit("/echo"), groups, 255, balloc)); - - CU_ASSERT(255 == match_downstream_addr_group( - routerconf, StringRef::from_lit(".nghttp2.org"), - StringRef::from_lit("/echo/foxtrot"), groups, 255, - balloc)); - - CU_ASSERT(9 == match_downstream_addr_group( - routerconf, StringRef::from_lit("alpha.nghttp2.org"), - StringRef::from_lit("/golf"), groups, 255, balloc)); - - CU_ASSERT(0 == match_downstream_addr_group( - routerconf, StringRef::from_lit("nghttp2.org"), - StringRef::from_lit("/echo"), groups, 255, balloc)); - - CU_ASSERT(13 == match_downstream_addr_group( - routerconf, StringRef::from_lit("test.local"), - StringRef{}, groups, 255, balloc)); + assert_size(11, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("git.nghttp2.org"), + StringRef::from_lit("/echo"), groups, 255, balloc)); + + assert_size(10, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("0git.nghttp2.org"), + StringRef::from_lit("/echo"), groups, 255, balloc)); + + assert_size(11, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("it.nghttp2.org"), + StringRef::from_lit("/echo"), groups, 255, balloc)); + + assert_size(255, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit(".nghttp2.org"), + StringRef::from_lit("/echo/foxtrot"), groups, 255, balloc)); + + assert_size(9, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("alpha.nghttp2.org"), + StringRef::from_lit("/golf"), groups, 255, balloc)); + + assert_size(0, ==, + match_downstream_addr_group( + routerconf, StringRef::from_lit("nghttp2.org"), + StringRef::from_lit("/echo"), groups, 255, balloc)); + + assert_size(13, ==, + match_downstream_addr_group(routerconf, + StringRef::from_lit("test.local"), + StringRef{}, groups, 255, balloc)); } } // namespace shrpx diff --git a/src/shrpx_worker_test.h b/src/shrpx_worker_test.h index 8ffa2f1..4dfaa2b 100644 --- a/src/shrpx_worker_test.h +++ b/src/shrpx_worker_test.h @@ -29,9 +29,15 @@ # include <config.h> #endif // HAVE_CONFIG_H +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + namespace shrpx { -void test_shrpx_worker_match_downstream_addr_group(void); +extern const MunitSuite worker_suite; + +munit_void_test_decl(test_shrpx_worker_match_downstream_addr_group); } // namespace shrpx diff --git a/src/template_test.cc b/src/template_test.cc index 4a77315..db212d1 100644 --- a/src/template_test.cc +++ b/src/template_test.cc @@ -28,80 +28,92 @@ #include <iostream> #include <sstream> -#include <CUnit/CUnit.h> +#include "munitxx.h" #include "template.h" namespace nghttp2 { +namespace { +const MunitTest tests[]{ + munit_void_test(test_template_immutable_string), + munit_void_test(test_template_string_ref), + munit_test_end(), +}; +} // namespace + +const MunitSuite template_suite{ + "/template", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_template_immutable_string(void) { ImmutableString null; - CU_ASSERT("" == null); - CU_ASSERT(0 == null.size()); - CU_ASSERT(null.empty()); + assert_string_equal("", null.c_str()); + assert_size(0, ==, null.size()); + assert_true(null.empty()); ImmutableString from_cstr("alpha"); - CU_ASSERT(0 == strcmp("alpha", from_cstr.c_str())); - CU_ASSERT(5 == from_cstr.size()); - CU_ASSERT(!from_cstr.empty()); - CU_ASSERT("alpha" == from_cstr); - CU_ASSERT(from_cstr == "alpha"); - CU_ASSERT(std::string("alpha") == from_cstr); - CU_ASSERT(from_cstr == std::string("alpha")); + assert_string_equal("alpha", from_cstr.c_str()); + assert_size(5, ==, from_cstr.size()); + assert_false(from_cstr.empty()); + assert_true("alpha" == from_cstr); + assert_true(from_cstr == "alpha"); + assert_true(std::string("alpha") == from_cstr); + assert_true(from_cstr == std::string("alpha")); // copy constructor ImmutableString src("charlie"); ImmutableString copy = src; - CU_ASSERT("charlie" == copy); - CU_ASSERT(7 == copy.size()); + assert_string_equal("charlie", copy.c_str()); + assert_size(7, ==, copy.size()); // copy assignment ImmutableString copy2; copy2 = src; - CU_ASSERT("charlie" == copy2); - CU_ASSERT(7 == copy2.size()); + assert_string_equal("charlie", copy2.c_str()); + assert_size(7, ==, copy2.size()); // move constructor ImmutableString move = std::move(copy); - CU_ASSERT("charlie" == move); - CU_ASSERT(7 == move.size()); - CU_ASSERT("" == copy); - CU_ASSERT(0 == copy.size()); + assert_string_equal("charlie", move.c_str()); + assert_size(7, ==, move.size()); + assert_string_equal("", copy.c_str()); + assert_size(0, ==, copy.size()); // move assignment move = std::move(from_cstr); - CU_ASSERT("alpha" == move); - CU_ASSERT(5 == move.size()); - CU_ASSERT("" == from_cstr); - CU_ASSERT(0 == from_cstr.size()); + assert_string_equal("alpha", move.c_str()); + assert_size(5, ==, move.size()); + assert_string_equal("", from_cstr.c_str()); + assert_size(0, ==, from_cstr.size()); // from string literal - auto from_lit = StringRef::from_lit("bravo"); + auto from_lit = ImmutableString::from_lit("bravo"); - CU_ASSERT("bravo" == from_lit); - CU_ASSERT(5 == from_lit.size()); + assert_string_equal("bravo", from_lit.c_str()); + assert_size(5, ==, from_lit.size()); // equality ImmutableString eq("delta"); - CU_ASSERT("delta1" != eq); - CU_ASSERT("delt" != eq); - CU_ASSERT(eq != "delta1"); - CU_ASSERT(eq != "delt"); + assert_true("delta1" != eq); + assert_true("delt" != eq); + assert_true(eq != "delta1"); + assert_true(eq != "delt"); // operator[] ImmutableString br_op("foxtrot"); - CU_ASSERT('f' == br_op[0]); - CU_ASSERT('o' == br_op[1]); - CU_ASSERT('t' == br_op[6]); - CU_ASSERT('\0' == br_op[7]); + assert_char('f', ==, br_op[0]); + assert_char('o', ==, br_op[1]); + assert_char('t', ==, br_op[6]); + assert_char('\0', ==, br_op[7]); // operator==(const ImmutableString &, const ImmutableString &) { @@ -109,9 +121,9 @@ void test_template_immutable_string(void) { ImmutableString b("foo"); ImmutableString c("fo"); - CU_ASSERT(a == b); - CU_ASSERT(a != c); - CU_ASSERT(c != b); + assert_true(a == b); + assert_true(a != c); + assert_true(c != b); } // operator<< @@ -120,7 +132,7 @@ void test_template_immutable_string(void) { std::stringstream ss; ss << a; - CU_ASSERT("foo" == ss.str()); + assert_stdstring_equal("foo", ss.str()); } // operator +=(std::string &, const ImmutableString &) @@ -128,60 +140,60 @@ void test_template_immutable_string(void) { std::string a = "alpha"; a += ImmutableString("bravo"); - CU_ASSERT("alphabravo" == a); + assert_stdstring_equal("alphabravo", a); } } void test_template_string_ref(void) { StringRef empty; - CU_ASSERT("" == empty); - CU_ASSERT(0 == empty.size()); + assert_stdstring_equal("", empty.str()); + assert_size(0, ==, empty.size()); // from std::string std::string alpha = "alpha"; StringRef ref(alpha); - CU_ASSERT("alpha" == ref); - CU_ASSERT(ref == "alpha"); - CU_ASSERT(alpha == ref); - CU_ASSERT(ref == alpha); - CU_ASSERT(5 == ref.size()); + assert_true("alpha" == ref); + assert_true(ref == "alpha"); + assert_true(alpha == ref); + assert_true(ref == alpha); + assert_size(5, ==, ref.size()); // from string literal auto from_lit = StringRef::from_lit("alpha"); - CU_ASSERT("alpha" == from_lit); - CU_ASSERT(5 == from_lit.size()); + assert_stdstring_equal("alpha", from_lit.str()); + assert_size(5, ==, from_lit.size()); // from ImmutableString auto im = ImmutableString::from_lit("bravo"); StringRef imref(im); - CU_ASSERT("bravo" == imref); - CU_ASSERT(5 == imref.size()); + assert_stdstring_equal("bravo", imref.str()); + assert_size(5, ==, imref.size()); // from C-string StringRef cstrref("charlie"); - CU_ASSERT("charlie" == cstrref); - CU_ASSERT(7 == cstrref.size()); + assert_stdstring_equal("charlie", cstrref.str()); + assert_size(7, ==, cstrref.size()); // from C-string and its length StringRef cstrnref("delta", 5); - CU_ASSERT("delta" == cstrnref); - CU_ASSERT(5 == cstrnref.size()); + assert_stdstring_equal("delta", cstrnref.str()); + assert_size(5, ==, cstrnref.size()); // operator[] StringRef br_op("foxtrot"); - CU_ASSERT('f' == br_op[0]); - CU_ASSERT('o' == br_op[1]); - CU_ASSERT('t' == br_op[6]); - CU_ASSERT('\0' == br_op[7]); + assert_char('f', ==, br_op[0]); + assert_char('o', ==, br_op[1]); + assert_char('t', ==, br_op[6]); + assert_char('\0', ==, br_op[7]); // operator<< { @@ -189,7 +201,7 @@ void test_template_string_ref(void) { std::stringstream ss; ss << a; - CU_ASSERT("foo" == ss.str()); + assert_stdstring_equal("foo", ss.str()); } // operator +=(std::string &, const StringRef &) @@ -197,7 +209,7 @@ void test_template_string_ref(void) { std::string a = "alpha"; a += StringRef("bravo"); - CU_ASSERT("alphabravo" == a); + assert_stdstring_equal("alphabravo", a); } } diff --git a/src/template_test.h b/src/template_test.h index 2c1448f..df39de9 100644 --- a/src/template_test.h +++ b/src/template_test.h @@ -29,10 +29,16 @@ # include <config.h> #endif // HAVE_CONFIG_H +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + namespace nghttp2 { -void test_template_immutable_string(void); -void test_template_string_ref(void); +extern const MunitSuite template_suite; + +munit_void_test_decl(test_template_immutable_string); +munit_void_test_decl(test_template_string_ref); } // namespace nghttp2 @@ -32,6 +32,11 @@ #include <openssl/crypto.h> #include <openssl/conf.h> +#ifdef HAVE_LIBBROTLI +# include <brotli/encode.h> +# include <brotli/decode.h> +#endif // HAVE_LIBBROTLI + #include "ssl_compat.h" namespace nghttp2 { @@ -120,6 +125,57 @@ int ssl_ctx_set_proto_versions(SSL_CTX *ssl_ctx, int min, int max) { return 0; } +#if defined(NGHTTP2_OPENSSL_IS_BORINGSSL) && defined(HAVE_LIBBROTLI) +int cert_compress(SSL *ssl, CBB *out, const uint8_t *in, size_t in_len) { + uint8_t *dest; + + auto compressed_size = BrotliEncoderMaxCompressedSize(in_len); + if (compressed_size == 0) { + return 0; + } + + if (!CBB_reserve(out, &dest, compressed_size)) { + return 0; + } + + if (BrotliEncoderCompress(BROTLI_MAX_QUALITY, BROTLI_DEFAULT_WINDOW, + BROTLI_MODE_GENERIC, in_len, in, &compressed_size, + dest) != BROTLI_TRUE) { + return 0; + } + + if (!CBB_did_write(out, compressed_size)) { + return 0; + } + + return 1; +} + +int cert_decompress(SSL *ssl, CRYPTO_BUFFER **out, size_t uncompressed_len, + const uint8_t *in, size_t in_len) { + uint8_t *dest; + auto buf = CRYPTO_BUFFER_alloc(&dest, uncompressed_len); + auto len = uncompressed_len; + + if (BrotliDecoderDecompress(in_len, in, &len, dest) != + BROTLI_DECODER_RESULT_SUCCESS) { + CRYPTO_BUFFER_free(buf); + + return 0; + } + + if (uncompressed_len != len) { + CRYPTO_BUFFER_free(buf); + + return 0; + } + + *out = buf; + + return 1; +} +#endif // NGHTTP2_OPENSSL_IS_BORINGSSL && HAVE_LIBBROTLI + } // namespace tls } // namespace nghttp2 @@ -97,6 +97,15 @@ bool check_http2_requirement(SSL *ssl); // 0 if it succeeds, or -1. int ssl_ctx_set_proto_versions(SSL_CTX *ssl_ctx, int min, int max); +constexpr uint16_t CERTIFICATE_COMPRESSION_ALGO_BROTLI = 2; + +#if defined(NGHTTP2_OPENSSL_IS_BORINGSSL) && defined(HAVE_LIBBROTLI) +int cert_compress(SSL *ssl, CBB *out, const uint8_t *in, size_t in_len); + +int cert_decompress(SSL *ssl, CRYPTO_BUFFER **out, size_t uncompressed_len, + const uint8_t *in, size_t in_len); +#endif // NGHTTP2_OPENSSL_IS_BORINGSSL && HAVE_LIBBROTLI + } // namespace tls } // namespace nghttp2 diff --git a/src/util_test.cc b/src/util_test.cc index 0ac0f1d..2e01e9d 100644 --- a/src/util_test.cc +++ b/src/util_test.cc @@ -28,7 +28,7 @@ #include <iostream> #include <random> -#include <CUnit/CUnit.h> +#include "munitxx.h" #include <nghttp2/nghttp2.h> @@ -39,166 +39,233 @@ using namespace nghttp2; namespace shrpx { +namespace { +const MunitTest tests[]{ + munit_void_test(test_util_streq), + munit_void_test(test_util_strieq), + munit_void_test(test_util_inp_strlower), + munit_void_test(test_util_to_base64), + munit_void_test(test_util_to_token68), + munit_void_test(test_util_percent_encode_token), + munit_void_test(test_util_percent_decode), + munit_void_test(test_util_quote_string), + munit_void_test(test_util_utox), + munit_void_test(test_util_http_date), + munit_void_test(test_util_select_h2), + munit_void_test(test_util_ipv6_numeric_addr), + munit_void_test(test_util_utos), + munit_void_test(test_util_make_string_ref_uint), + munit_void_test(test_util_utos_unit), + munit_void_test(test_util_utos_funit), + munit_void_test(test_util_parse_uint_with_unit), + munit_void_test(test_util_parse_uint), + munit_void_test(test_util_parse_duration_with_unit), + munit_void_test(test_util_duration_str), + munit_void_test(test_util_format_duration), + munit_void_test(test_util_starts_with), + munit_void_test(test_util_ends_with), + munit_void_test(test_util_parse_http_date), + munit_void_test(test_util_localtime_date), + munit_void_test(test_util_get_uint64), + munit_void_test(test_util_parse_config_str_list), + munit_void_test(test_util_make_http_hostport), + munit_void_test(test_util_make_hostport), + munit_void_test(test_util_strifind), + munit_void_test(test_util_random_alpha_digit), + munit_void_test(test_util_format_hex), + munit_void_test(test_util_is_hex_string), + munit_void_test(test_util_decode_hex), + munit_void_test(test_util_extract_host), + munit_void_test(test_util_split_hostport), + munit_void_test(test_util_split_str), + munit_void_test(test_util_rstrip), + munit_test_end(), +}; +} // namespace + +const MunitSuite util_suite{ + "/util", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_util_streq(void) { - CU_ASSERT( + assert_true( util::streq(StringRef::from_lit("alpha"), StringRef::from_lit("alpha"))); - CU_ASSERT(!util::streq(StringRef::from_lit("alpha"), - StringRef::from_lit("alphabravo"))); - CU_ASSERT(!util::streq(StringRef::from_lit("alphabravo"), - StringRef::from_lit("alpha"))); - CU_ASSERT( - !util::streq(StringRef::from_lit("alpha"), StringRef::from_lit("alphA"))); - CU_ASSERT(!util::streq(StringRef{}, StringRef::from_lit("a"))); - CU_ASSERT(util::streq(StringRef{}, StringRef{})); - CU_ASSERT(!util::streq(StringRef::from_lit("alpha"), StringRef{})); - - CU_ASSERT( - !util::streq(StringRef::from_lit("alph"), StringRef::from_lit("alpha"))); - CU_ASSERT( - !util::streq(StringRef::from_lit("alpha"), StringRef::from_lit("alph"))); - CU_ASSERT( - !util::streq(StringRef::from_lit("alpha"), StringRef::from_lit("alphA"))); - - CU_ASSERT(util::streq_l("alpha", "alpha", 5)); - CU_ASSERT(util::streq_l("alpha", "alphabravo", 5)); - CU_ASSERT(!util::streq_l("alpha", "alphabravo", 6)); - CU_ASSERT(!util::streq_l("alphabravo", "alpha", 5)); - CU_ASSERT(!util::streq_l("alpha", "alphA", 5)); - CU_ASSERT(!util::streq_l("", "a", 1)); - CU_ASSERT(util::streq_l("", "", 0)); - CU_ASSERT(!util::streq_l("alpha", "", 0)); + assert_false(util::streq(StringRef::from_lit("alpha"), + StringRef::from_lit("alphabravo"))); + assert_false(util::streq(StringRef::from_lit("alphabravo"), + StringRef::from_lit("alpha"))); + assert_false( + util::streq(StringRef::from_lit("alpha"), StringRef::from_lit("alphA"))); + assert_false(util::streq(StringRef{}, StringRef::from_lit("a"))); + assert_true(util::streq(StringRef{}, StringRef{})); + assert_false(util::streq(StringRef::from_lit("alpha"), StringRef{})); + + assert_false( + util::streq(StringRef::from_lit("alph"), StringRef::from_lit("alpha"))); + assert_false( + util::streq(StringRef::from_lit("alpha"), StringRef::from_lit("alph"))); + assert_false( + util::streq(StringRef::from_lit("alpha"), StringRef::from_lit("alphA"))); + + assert_true(util::streq_l("alpha", "alpha", 5)); + assert_true(util::streq_l("alpha", "alphabravo", 5)); + assert_false(util::streq_l("alpha", "alphabravo", 6)); + assert_false(util::streq_l("alphabravo", "alpha", 5)); + assert_false(util::streq_l("alpha", "alphA", 5)); + assert_false(util::streq_l("", "a", 1)); + assert_true(util::streq_l("", "", 0)); + assert_false(util::streq_l("alpha", "", 0)); } void test_util_strieq(void) { - CU_ASSERT(util::strieq(std::string("alpha"), std::string("alpha"))); - CU_ASSERT(util::strieq(std::string("alpha"), std::string("AlPhA"))); - CU_ASSERT(util::strieq(std::string(), std::string())); - CU_ASSERT(!util::strieq(std::string("alpha"), std::string("AlPhA "))); - CU_ASSERT(!util::strieq(std::string(), std::string("AlPhA "))); + assert_true(util::strieq(std::string("alpha"), std::string("alpha"))); + assert_true(util::strieq(std::string("alpha"), std::string("AlPhA"))); + assert_true(util::strieq(std::string(), std::string())); + assert_false(util::strieq(std::string("alpha"), std::string("AlPhA "))); + assert_false(util::strieq(std::string(), std::string("AlPhA "))); - CU_ASSERT( + assert_true( util::strieq(StringRef::from_lit("alpha"), StringRef::from_lit("alpha"))); - CU_ASSERT( + assert_true( util::strieq(StringRef::from_lit("alpha"), StringRef::from_lit("AlPhA"))); - CU_ASSERT(util::strieq(StringRef{}, StringRef{})); - CU_ASSERT(!util::strieq(StringRef::from_lit("alpha"), - StringRef::from_lit("AlPhA "))); - CU_ASSERT( - !util::strieq(StringRef::from_lit(""), StringRef::from_lit("AlPhA "))); + assert_true(util::strieq(StringRef{}, StringRef{})); + assert_false(util::strieq(StringRef::from_lit("alpha"), + StringRef::from_lit("AlPhA "))); + assert_false( + util::strieq(StringRef::from_lit(""), StringRef::from_lit("AlPhA "))); - CU_ASSERT(util::strieq_l("alpha", "alpha", 5)); - CU_ASSERT(util::strieq_l("alpha", "AlPhA", 5)); - CU_ASSERT(util::strieq_l("", static_cast<const char *>(nullptr), 0)); - CU_ASSERT(!util::strieq_l("alpha", "AlPhA ", 6)); - CU_ASSERT(!util::strieq_l("", "AlPhA ", 6)); + assert_true(util::strieq_l("alpha", "alpha", 5)); + assert_true(util::strieq_l("alpha", "AlPhA", 5)); + assert_true(util::strieq_l("", static_cast<const char *>(nullptr), 0)); + assert_false(util::strieq_l("alpha", "AlPhA ", 6)); + assert_false(util::strieq_l("", "AlPhA ", 6)); - CU_ASSERT(util::strieq_l("alpha", StringRef::from_lit("alpha"))); - CU_ASSERT(util::strieq_l("alpha", StringRef::from_lit("AlPhA"))); - CU_ASSERT(util::strieq_l("", StringRef{})); - CU_ASSERT(!util::strieq_l("alpha", StringRef::from_lit("AlPhA "))); - CU_ASSERT(!util::strieq_l("", StringRef::from_lit("AlPhA "))); + assert_true(util::strieq_l("alpha", StringRef::from_lit("alpha"))); + assert_true(util::strieq_l("alpha", StringRef::from_lit("AlPhA"))); + assert_true(util::strieq_l("", StringRef{})); + assert_false(util::strieq_l("alpha", StringRef::from_lit("AlPhA "))); + assert_false(util::strieq_l("", StringRef::from_lit("AlPhA "))); } void test_util_inp_strlower(void) { std::string a("alPha"); util::inp_strlower(a); - CU_ASSERT("alpha" == a); + assert_stdstring_equal("alpha", a); a = "ALPHA123BRAVO"; util::inp_strlower(a); - CU_ASSERT("alpha123bravo" == a); + assert_stdstring_equal("alpha123bravo", a); a = ""; util::inp_strlower(a); - CU_ASSERT("" == a); + assert_stdstring_equal("", a); } void test_util_to_base64(void) { BlockAllocator balloc(4096, 4096); - CU_ASSERT("AAA++B/=" == - util::to_base64(balloc, StringRef::from_lit("AAA--B_"))); - CU_ASSERT("AAA++B/B" == - util::to_base64(balloc, StringRef::from_lit("AAA--B_B"))); + assert_stdstring_equal( + "AAA++B/=", + util::to_base64(balloc, StringRef::from_lit("AAA--B_")).str()); + assert_stdstring_equal( + "AAA++B/B", + util::to_base64(balloc, StringRef::from_lit("AAA--B_B")).str()); } void test_util_to_token68(void) { std::string x = "AAA++B/="; util::to_token68(x); - CU_ASSERT("AAA--B_" == x); + assert_stdstring_equal("AAA--B_", x); x = "AAA++B/B"; util::to_token68(x); - CU_ASSERT("AAA--B_B" == x); + assert_stdstring_equal("AAA--B_B", x); } void test_util_percent_encode_token(void) { BlockAllocator balloc(4096, 4096); - CU_ASSERT("h2" == - util::percent_encode_token(balloc, StringRef::from_lit("h2"))); - CU_ASSERT("h3~" == - util::percent_encode_token(balloc, StringRef::from_lit("h3~"))); - CU_ASSERT("100%25" == - util::percent_encode_token(balloc, StringRef::from_lit("100%"))); - CU_ASSERT("http%202" == - util::percent_encode_token(balloc, StringRef::from_lit("http 2"))); + assert_stdstring_equal( + "h2", + util::percent_encode_token(balloc, StringRef::from_lit("h2")).str()); + assert_stdstring_equal( + "h3~", + util::percent_encode_token(balloc, StringRef::from_lit("h3~")).str()); + assert_stdstring_equal( + "100%25", + util::percent_encode_token(balloc, StringRef::from_lit("100%")).str()); + assert_stdstring_equal( + "http%202", + util::percent_encode_token(balloc, StringRef::from_lit("http 2")).str()); } void test_util_percent_decode(void) { { std::string s = "%66%6F%6f%62%61%72"; - CU_ASSERT("foobar" == util::percent_decode(std::begin(s), std::end(s))); + assert_stdstring_equal("foobar", + util::percent_decode(std::begin(s), std::end(s))); } { std::string s = "%66%6"; - CU_ASSERT("f%6" == util::percent_decode(std::begin(s), std::end(s))); + assert_stdstring_equal("f%6", + util::percent_decode(std::begin(s), std::end(s))); } { std::string s = "%66%"; - CU_ASSERT("f%" == util::percent_decode(std::begin(s), std::end(s))); + assert_stdstring_equal("f%", + util::percent_decode(std::begin(s), std::end(s))); } BlockAllocator balloc(1024, 1024); - CU_ASSERT("foobar" == util::percent_decode( - balloc, StringRef::from_lit("%66%6F%6f%62%61%72"))); + assert_stdstring_equal( + "foobar", + util::percent_decode(balloc, StringRef::from_lit("%66%6F%6f%62%61%72")) + .str()); - CU_ASSERT("f%6" == - util::percent_decode(balloc, StringRef::from_lit("%66%6"))); + assert_stdstring_equal( + "f%6", util::percent_decode(balloc, StringRef::from_lit("%66%6")).str()); - CU_ASSERT("f%" == util::percent_decode(balloc, StringRef::from_lit("%66%"))); + assert_stdstring_equal( + "f%", util::percent_decode(balloc, StringRef::from_lit("%66%")).str()); } void test_util_quote_string(void) { BlockAllocator balloc(4096, 4096); - CU_ASSERT("alpha" == - util::quote_string(balloc, StringRef::from_lit("alpha"))); - CU_ASSERT("" == util::quote_string(balloc, StringRef::from_lit(""))); - CU_ASSERT("\\\"alpha\\\"" == - util::quote_string(balloc, StringRef::from_lit("\"alpha\""))); + assert_stdstring_equal( + "alpha", util::quote_string(balloc, StringRef::from_lit("alpha")).str()); + assert_stdstring_equal( + "", util::quote_string(balloc, StringRef::from_lit("")).str()); + assert_stdstring_equal( + "\\\"alpha\\\"", + util::quote_string(balloc, StringRef::from_lit("\"alpha\"")).str()); } void test_util_utox(void) { - CU_ASSERT("0" == util::utox(0)); - CU_ASSERT("1" == util::utox(1)); - CU_ASSERT("F" == util::utox(15)); - CU_ASSERT("10" == util::utox(16)); - CU_ASSERT("3B9ACA07" == util::utox(1000000007)); - CU_ASSERT("100000000" == util::utox(1LL << 32)); + assert_stdstring_equal("0", util::utox(0)); + assert_stdstring_equal("1", util::utox(1)); + assert_stdstring_equal("F", util::utox(15)); + assert_stdstring_equal("10", util::utox(16)); + assert_stdstring_equal("3B9ACA07", util::utox(1000000007)); + assert_stdstring_equal("100000000", util::utox(1LL << 32)); } void test_util_http_date(void) { - CU_ASSERT("Thu, 01 Jan 1970 00:00:00 GMT" == util::http_date(0)); - CU_ASSERT("Wed, 29 Feb 2012 09:15:16 GMT" == util::http_date(1330506916)); + assert_stdstring_equal("Thu, 01 Jan 1970 00:00:00 GMT", util::http_date(0)); + assert_stdstring_equal("Wed, 29 Feb 2012 09:15:16 GMT", + util::http_date(1330506916)); std::array<char, 30> http_buf; - CU_ASSERT("Thu, 01 Jan 1970 00:00:00 GMT" == - util::format_http_date(http_buf.data(), - std::chrono::system_clock::time_point())); - CU_ASSERT("Wed, 29 Feb 2012 09:15:16 GMT" == - util::format_http_date(http_buf.data(), - std::chrono::system_clock::time_point( - std::chrono::seconds(1330506916)))); + assert_stdstring_equal( + "Thu, 01 Jan 1970 00:00:00 GMT", + util::format_http_date(http_buf.data(), + std::chrono::system_clock::time_point()) + .str()); + assert_stdstring_equal( + "Wed, 29 Feb 2012 09:15:16 GMT", + util::format_http_date(http_buf.data(), + std::chrono::system_clock::time_point( + std::chrono::seconds(1330506916))) + .str()); } void test_util_select_h2(void) { @@ -207,10 +274,10 @@ void test_util_select_h2(void) { // Check single entry and select it. const unsigned char t1[] = "\x2h2"; - CU_ASSERT(util::select_h2(&out, &outlen, t1, sizeof(t1) - 1)); - CU_ASSERT( - memcmp(NGHTTP2_PROTO_VERSION_ID, out, NGHTTP2_PROTO_VERSION_ID_LEN) == 0); - CU_ASSERT(NGHTTP2_PROTO_VERSION_ID_LEN == outlen); + assert_true(util::select_h2(&out, &outlen, t1, sizeof(t1) - 1)); + assert_memory_equal(NGHTTP2_PROTO_VERSION_ID_LEN, NGHTTP2_PROTO_VERSION_ID, + out); + assert_uchar(NGHTTP2_PROTO_VERSION_ID_LEN, ==, outlen); out = nullptr; outlen = 0; @@ -218,224 +285,235 @@ void test_util_select_h2(void) { // Check the case where id is correct but length is invalid and too // long. const unsigned char t2[] = "\x6h2-14"; - CU_ASSERT(!util::select_h2(&out, &outlen, t2, sizeof(t2) - 1)); + assert_false(util::select_h2(&out, &outlen, t2, sizeof(t2) - 1)); // Check the case where h2 is located after bogus ID. const unsigned char t3[] = "\x2h3\x2h2"; - CU_ASSERT(util::select_h2(&out, &outlen, t3, sizeof(t3) - 1)); + assert_true(util::select_h2(&out, &outlen, t3, sizeof(t3) - 1)); - CU_ASSERT( - memcmp(NGHTTP2_PROTO_VERSION_ID, out, NGHTTP2_PROTO_VERSION_ID_LEN) == 0); - CU_ASSERT(NGHTTP2_PROTO_VERSION_ID_LEN == outlen); + assert_memory_equal(NGHTTP2_PROTO_VERSION_ID_LEN, NGHTTP2_PROTO_VERSION_ID, + out); + assert_uchar(NGHTTP2_PROTO_VERSION_ID_LEN, ==, outlen); out = nullptr; outlen = 0; // Check the case that last entry's length is invalid and too long. const unsigned char t4[] = "\x2h3\x6h2-14"; - CU_ASSERT(!util::select_h2(&out, &outlen, t4, sizeof(t4) - 1)); + assert_false(util::select_h2(&out, &outlen, t4, sizeof(t4) - 1)); // Check the case that all entries are not supported. const unsigned char t5[] = "\x2h3\x2h4"; - CU_ASSERT(!util::select_h2(&out, &outlen, t5, sizeof(t5) - 1)); + assert_false(util::select_h2(&out, &outlen, t5, sizeof(t5) - 1)); // Check the case where 2 values are eligible, but last one is // picked up because it has precedence over the other. const unsigned char t6[] = "\x5h2-14\x5h2-16"; - CU_ASSERT(util::select_h2(&out, &outlen, t6, sizeof(t6) - 1)); - CU_ASSERT(util::streq(NGHTTP2_H2_16, StringRef{out, outlen})); + assert_true(util::select_h2(&out, &outlen, t6, sizeof(t6) - 1)); + assert_true(util::streq(NGHTTP2_H2_16, StringRef{out, outlen})); } void test_util_ipv6_numeric_addr(void) { - CU_ASSERT(util::ipv6_numeric_addr("::1")); - CU_ASSERT(util::ipv6_numeric_addr("2001:0db8:85a3:0042:1000:8a2e:0370:7334")); + assert_true(util::ipv6_numeric_addr("::1")); + assert_true( + util::ipv6_numeric_addr("2001:0db8:85a3:0042:1000:8a2e:0370:7334")); // IPv4 - CU_ASSERT(!util::ipv6_numeric_addr("127.0.0.1")); + assert_false(util::ipv6_numeric_addr("127.0.0.1")); // not numeric address - CU_ASSERT(!util::ipv6_numeric_addr("localhost")); + assert_false(util::ipv6_numeric_addr("localhost")); } void test_util_utos(void) { uint8_t buf[32]; - CU_ASSERT(("0" == StringRef{buf, util::utos(buf, 0)})); - CU_ASSERT(("123" == StringRef{buf, util::utos(buf, 123)})); - CU_ASSERT(("18446744073709551615" == - StringRef{buf, util::utos(buf, 18446744073709551615ULL)})); + assert_stdstring_equal("0", (std::string{buf, util::utos(buf, 0)})); + assert_stdstring_equal("123", (std::string{buf, util::utos(buf, 123)})); + assert_stdstring_equal( + "18446744073709551615", + (std::string{buf, util::utos(buf, 18446744073709551615ULL)})); } void test_util_make_string_ref_uint(void) { BlockAllocator balloc(1024, 1024); - CU_ASSERT("0" == util::make_string_ref_uint(balloc, 0)); - CU_ASSERT("123" == util::make_string_ref_uint(balloc, 123)); - CU_ASSERT("18446744073709551615" == - util::make_string_ref_uint(balloc, 18446744073709551615ULL)); + assert_stdstring_equal("0", util::make_string_ref_uint(balloc, 0).str()); + assert_stdstring_equal("123", util::make_string_ref_uint(balloc, 123).str()); + assert_stdstring_equal( + "18446744073709551615", + util::make_string_ref_uint(balloc, 18446744073709551615ULL).str()); } void test_util_utos_unit(void) { - CU_ASSERT("0" == util::utos_unit(0)); - CU_ASSERT("1023" == util::utos_unit(1023)); - CU_ASSERT("1K" == util::utos_unit(1024)); - CU_ASSERT("1K" == util::utos_unit(1025)); - CU_ASSERT("1M" == util::utos_unit(1 << 20)); - CU_ASSERT("1G" == util::utos_unit(1 << 30)); - CU_ASSERT("1024G" == util::utos_unit(1LL << 40)); + assert_stdstring_equal("0", util::utos_unit(0)); + assert_stdstring_equal("1023", util::utos_unit(1023)); + assert_stdstring_equal("1K", util::utos_unit(1024)); + assert_stdstring_equal("1K", util::utos_unit(1025)); + assert_stdstring_equal("1M", util::utos_unit(1 << 20)); + assert_stdstring_equal("1G", util::utos_unit(1 << 30)); + assert_stdstring_equal("1024G", util::utos_unit(1LL << 40)); } void test_util_utos_funit(void) { - CU_ASSERT("0" == util::utos_funit(0)); - CU_ASSERT("1023" == util::utos_funit(1023)); - CU_ASSERT("1.00K" == util::utos_funit(1024)); - CU_ASSERT("1.00K" == util::utos_funit(1025)); - CU_ASSERT("1.09K" == util::utos_funit(1119)); - CU_ASSERT("1.27K" == util::utos_funit(1300)); - CU_ASSERT("1.00M" == util::utos_funit(1 << 20)); - CU_ASSERT("1.18M" == util::utos_funit(1234567)); - CU_ASSERT("1.00G" == util::utos_funit(1 << 30)); - CU_ASSERT("4492450797.23G" == util::utos_funit(4823732313248234343LL)); - CU_ASSERT("1024.00G" == util::utos_funit(1LL << 40)); + assert_stdstring_equal("0", util::utos_funit(0)); + assert_stdstring_equal("1023", util::utos_funit(1023)); + assert_stdstring_equal("1.00K", util::utos_funit(1024)); + assert_stdstring_equal("1.00K", util::utos_funit(1025)); + assert_stdstring_equal("1.09K", util::utos_funit(1119)); + assert_stdstring_equal("1.27K", util::utos_funit(1300)); + assert_stdstring_equal("1.00M", util::utos_funit(1 << 20)); + assert_stdstring_equal("1.18M", util::utos_funit(1234567)); + assert_stdstring_equal("1.00G", util::utos_funit(1 << 30)); + assert_stdstring_equal("4492450797.23G", + util::utos_funit(4823732313248234343LL)); + assert_stdstring_equal("1024.00G", util::utos_funit(1LL << 40)); } void test_util_parse_uint_with_unit(void) { - CU_ASSERT(0 == util::parse_uint_with_unit("0")); - CU_ASSERT(1023 == util::parse_uint_with_unit("1023")); - CU_ASSERT(1024 == util::parse_uint_with_unit("1k")); - CU_ASSERT(2048 == util::parse_uint_with_unit("2K")); - CU_ASSERT(1 << 20 == util::parse_uint_with_unit("1m")); - CU_ASSERT(1 << 21 == util::parse_uint_with_unit("2M")); - CU_ASSERT(1 << 30 == util::parse_uint_with_unit("1g")); - CU_ASSERT(1LL << 31 == util::parse_uint_with_unit("2G")); - CU_ASSERT(9223372036854775807LL == - util::parse_uint_with_unit("9223372036854775807")); + assert_int64(0, ==, util::parse_uint_with_unit("0")); + assert_int64(1023, ==, util::parse_uint_with_unit("1023")); + assert_int64(1024, ==, util::parse_uint_with_unit("1k")); + assert_int64(2048, ==, util::parse_uint_with_unit("2K")); + assert_int64(1 << 20, ==, util::parse_uint_with_unit("1m")); + assert_int64(1 << 21, ==, util::parse_uint_with_unit("2M")); + assert_int64(1 << 30, ==, util::parse_uint_with_unit("1g")); + assert_int64(1LL << 31, ==, util::parse_uint_with_unit("2G")); + assert_int64(9223372036854775807LL, ==, + util::parse_uint_with_unit("9223372036854775807")); // check overflow case - CU_ASSERT(-1 == util::parse_uint_with_unit("9223372036854775808")); - CU_ASSERT(-1 == util::parse_uint_with_unit("10000000000000000000")); - CU_ASSERT(-1 == util::parse_uint_with_unit("9223372036854775807G")); + assert_int64(-1, ==, util::parse_uint_with_unit("9223372036854775808")); + assert_int64(-1, ==, util::parse_uint_with_unit("10000000000000000000")); + assert_int64(-1, ==, util::parse_uint_with_unit("9223372036854775807G")); // bad characters - CU_ASSERT(-1 == util::parse_uint_with_unit("1.1")); - CU_ASSERT(-1 == util::parse_uint_with_unit("1a")); - CU_ASSERT(-1 == util::parse_uint_with_unit("a1")); - CU_ASSERT(-1 == util::parse_uint_with_unit("1T")); - CU_ASSERT(-1 == util::parse_uint_with_unit("")); + assert_int64(-1, ==, util::parse_uint_with_unit("1.1")); + assert_int64(-1, ==, util::parse_uint_with_unit("1a")); + assert_int64(-1, ==, util::parse_uint_with_unit("a1")); + assert_int64(-1, ==, util::parse_uint_with_unit("1T")); + assert_int64(-1, ==, util::parse_uint_with_unit("")); } void test_util_parse_uint(void) { - CU_ASSERT(0 == util::parse_uint("0")); - CU_ASSERT(1023 == util::parse_uint("1023")); - CU_ASSERT(-1 == util::parse_uint("1k")); - CU_ASSERT(9223372036854775807LL == util::parse_uint("9223372036854775807")); + assert_int64(0, ==, util::parse_uint("0")); + assert_int64(1023, ==, util::parse_uint("1023")); + assert_int64(-1, ==, util::parse_uint("1k")); + assert_int64(9223372036854775807LL, ==, + util::parse_uint("9223372036854775807")); // check overflow case - CU_ASSERT(-1 == util::parse_uint("9223372036854775808")); - CU_ASSERT(-1 == util::parse_uint("10000000000000000000")); + assert_int64(-1, ==, util::parse_uint("9223372036854775808")); + assert_int64(-1, ==, util::parse_uint("10000000000000000000")); // bad characters - CU_ASSERT(-1 == util::parse_uint("1.1")); - CU_ASSERT(-1 == util::parse_uint("1a")); - CU_ASSERT(-1 == util::parse_uint("a1")); - CU_ASSERT(-1 == util::parse_uint("1T")); - CU_ASSERT(-1 == util::parse_uint("")); + assert_int64(-1, ==, util::parse_uint("1.1")); + assert_int64(-1, ==, util::parse_uint("1a")); + assert_int64(-1, ==, util::parse_uint("a1")); + assert_int64(-1, ==, util::parse_uint("1T")); + assert_int64(-1, ==, util::parse_uint("")); } void test_util_parse_duration_with_unit(void) { - CU_ASSERT(0. == util::parse_duration_with_unit("0")); - CU_ASSERT(123. == util::parse_duration_with_unit("123")); - CU_ASSERT(123. == util::parse_duration_with_unit("123s")); - CU_ASSERT(0.500 == util::parse_duration_with_unit("500ms")); - CU_ASSERT(123. == util::parse_duration_with_unit("123S")); - CU_ASSERT(0.500 == util::parse_duration_with_unit("500MS")); - CU_ASSERT(180 == util::parse_duration_with_unit("3m")); - CU_ASSERT(3600 * 5 == util::parse_duration_with_unit("5h")); + assert_double(0., ==, util::parse_duration_with_unit("0")); + assert_double(123., ==, util::parse_duration_with_unit("123")); + assert_double(123., ==, util::parse_duration_with_unit("123s")); + assert_double(0.500, ==, util::parse_duration_with_unit("500ms")); + assert_double(123., ==, util::parse_duration_with_unit("123S")); + assert_double(0.500, ==, util::parse_duration_with_unit("500MS")); + assert_double(180, ==, util::parse_duration_with_unit("3m")); + assert_double(3600 * 5, ==, util::parse_duration_with_unit("5h")); auto err = std::numeric_limits<double>::infinity(); // check overflow case - CU_ASSERT(err == util::parse_duration_with_unit("9223372036854775808")); + assert_double(err, ==, util::parse_duration_with_unit("9223372036854775808")); // bad characters - CU_ASSERT(err == util::parse_duration_with_unit("0u")); - CU_ASSERT(err == util::parse_duration_with_unit("0xs")); - CU_ASSERT(err == util::parse_duration_with_unit("0mt")); - CU_ASSERT(err == util::parse_duration_with_unit("0mss")); - CU_ASSERT(err == util::parse_duration_with_unit("s")); - CU_ASSERT(err == util::parse_duration_with_unit("ms")); + assert_double(err, ==, util::parse_duration_with_unit("0u")); + assert_double(err, ==, util::parse_duration_with_unit("0xs")); + assert_double(err, ==, util::parse_duration_with_unit("0mt")); + assert_double(err, ==, util::parse_duration_with_unit("0mss")); + assert_double(err, ==, util::parse_duration_with_unit("s")); + assert_double(err, ==, util::parse_duration_with_unit("ms")); } void test_util_duration_str(void) { - CU_ASSERT("0" == util::duration_str(0.)); - CU_ASSERT("1s" == util::duration_str(1.)); - CU_ASSERT("500ms" == util::duration_str(0.5)); - CU_ASSERT("1500ms" == util::duration_str(1.5)); - CU_ASSERT("2m" == util::duration_str(120.)); - CU_ASSERT("121s" == util::duration_str(121.)); - CU_ASSERT("1h" == util::duration_str(3600.)); + assert_stdstring_equal("0", util::duration_str(0.)); + assert_stdstring_equal("1s", util::duration_str(1.)); + assert_stdstring_equal("500ms", util::duration_str(0.5)); + assert_stdstring_equal("1500ms", util::duration_str(1.5)); + assert_stdstring_equal("2m", util::duration_str(120.)); + assert_stdstring_equal("121s", util::duration_str(121.)); + assert_stdstring_equal("1h", util::duration_str(3600.)); } void test_util_format_duration(void) { - CU_ASSERT("0us" == util::format_duration(std::chrono::microseconds(0))); - CU_ASSERT("999us" == util::format_duration(std::chrono::microseconds(999))); - CU_ASSERT("1.00ms" == util::format_duration(std::chrono::microseconds(1000))); - CU_ASSERT("1.09ms" == util::format_duration(std::chrono::microseconds(1090))); - CU_ASSERT("1.01ms" == util::format_duration(std::chrono::microseconds(1009))); - CU_ASSERT("999.99ms" == - util::format_duration(std::chrono::microseconds(999990))); - CU_ASSERT("1.00s" == - util::format_duration(std::chrono::microseconds(1000000))); - CU_ASSERT("1.05s" == - util::format_duration(std::chrono::microseconds(1050000))); - - CU_ASSERT("0us" == util::format_duration(0.)); - CU_ASSERT("999us" == util::format_duration(0.000999)); - CU_ASSERT("1.00ms" == util::format_duration(0.001)); - CU_ASSERT("1.09ms" == util::format_duration(0.00109)); - CU_ASSERT("1.01ms" == util::format_duration(0.001009)); - CU_ASSERT("999.99ms" == util::format_duration(0.99999)); - CU_ASSERT("1.00s" == util::format_duration(1.)); - CU_ASSERT("1.05s" == util::format_duration(1.05)); + assert_stdstring_equal("0us", + util::format_duration(std::chrono::microseconds(0))); + assert_stdstring_equal("999us", + util::format_duration(std::chrono::microseconds(999))); + assert_stdstring_equal( + "1.00ms", util::format_duration(std::chrono::microseconds(1000))); + assert_stdstring_equal( + "1.09ms", util::format_duration(std::chrono::microseconds(1090))); + assert_stdstring_equal( + "1.01ms", util::format_duration(std::chrono::microseconds(1009))); + assert_stdstring_equal( + "999.99ms", util::format_duration(std::chrono::microseconds(999990))); + assert_stdstring_equal( + "1.00s", util::format_duration(std::chrono::microseconds(1000000))); + assert_stdstring_equal( + "1.05s", util::format_duration(std::chrono::microseconds(1050000))); + + assert_stdstring_equal("0us", util::format_duration(0.)); + assert_stdstring_equal("999us", util::format_duration(0.000999)); + assert_stdstring_equal("1.00ms", util::format_duration(0.001)); + assert_stdstring_equal("1.09ms", util::format_duration(0.00109)); + assert_stdstring_equal("1.01ms", util::format_duration(0.001009)); + assert_stdstring_equal("999.99ms", util::format_duration(0.99999)); + assert_stdstring_equal("1.00s", util::format_duration(1.)); + assert_stdstring_equal("1.05s", util::format_duration(1.05)); } void test_util_starts_with(void) { - CU_ASSERT(util::starts_with(StringRef::from_lit("foo"), - StringRef::from_lit("foo"))); - CU_ASSERT(util::starts_with(StringRef::from_lit("fooo"), - StringRef::from_lit("foo"))); - CU_ASSERT(util::starts_with(StringRef::from_lit("ofoo"), StringRef{})); - CU_ASSERT(!util::starts_with(StringRef::from_lit("ofoo"), - StringRef::from_lit("foo"))); - - CU_ASSERT(util::istarts_with(StringRef::from_lit("FOO"), - StringRef::from_lit("fOO"))); - CU_ASSERT(util::istarts_with(StringRef::from_lit("ofoo"), StringRef{})); - CU_ASSERT(util::istarts_with(StringRef::from_lit("fOOo"), - StringRef::from_lit("Foo"))); - CU_ASSERT(!util::istarts_with(StringRef::from_lit("ofoo"), + assert_true(util::starts_with(StringRef::from_lit("foo"), + StringRef::from_lit("foo"))); + assert_true(util::starts_with(StringRef::from_lit("fooo"), StringRef::from_lit("foo"))); + assert_true(util::starts_with(StringRef::from_lit("ofoo"), StringRef{})); + assert_false(util::starts_with(StringRef::from_lit("ofoo"), + StringRef::from_lit("foo"))); - CU_ASSERT(util::istarts_with_l(StringRef::from_lit("fOOo"), "Foo")); - CU_ASSERT(!util::istarts_with_l(StringRef::from_lit("ofoo"), "foo")); + assert_true(util::istarts_with(StringRef::from_lit("FOO"), + StringRef::from_lit("fOO"))); + assert_true(util::istarts_with(StringRef::from_lit("ofoo"), StringRef{})); + assert_true(util::istarts_with(StringRef::from_lit("fOOo"), + StringRef::from_lit("Foo"))); + assert_false(util::istarts_with(StringRef::from_lit("ofoo"), + StringRef::from_lit("foo"))); + + assert_true(util::istarts_with_l(StringRef::from_lit("fOOo"), "Foo")); + assert_false(util::istarts_with_l(StringRef::from_lit("ofoo"), "foo")); } void test_util_ends_with(void) { - CU_ASSERT( + assert_true( util::ends_with(StringRef::from_lit("foo"), StringRef::from_lit("foo"))); - CU_ASSERT(util::ends_with(StringRef::from_lit("foo"), StringRef{})); - CU_ASSERT( + assert_true(util::ends_with(StringRef::from_lit("foo"), StringRef{})); + assert_true( util::ends_with(StringRef::from_lit("ofoo"), StringRef::from_lit("foo"))); - CU_ASSERT( - !util::ends_with(StringRef::from_lit("ofoo"), StringRef::from_lit("fo"))); + assert_false( + util::ends_with(StringRef::from_lit("ofoo"), StringRef::from_lit("fo"))); - CU_ASSERT( + assert_true( util::iends_with(StringRef::from_lit("fOo"), StringRef::from_lit("Foo"))); - CU_ASSERT(util::iends_with(StringRef::from_lit("foo"), StringRef{})); - CU_ASSERT(util::iends_with(StringRef::from_lit("oFoo"), - StringRef::from_lit("fOO"))); - CU_ASSERT(!util::iends_with(StringRef::from_lit("ofoo"), - StringRef::from_lit("fo"))); + assert_true(util::iends_with(StringRef::from_lit("foo"), StringRef{})); + assert_true(util::iends_with(StringRef::from_lit("oFoo"), + StringRef::from_lit("fOO"))); + assert_false( + util::iends_with(StringRef::from_lit("ofoo"), StringRef::from_lit("fo"))); - CU_ASSERT(util::iends_with_l(StringRef::from_lit("oFoo"), "fOO")); - CU_ASSERT(!util::iends_with_l(StringRef::from_lit("ofoo"), "fo")); + assert_true(util::iends_with_l(StringRef::from_lit("oFoo"), "fOO")); + assert_false(util::iends_with_l(StringRef::from_lit("ofoo"), "fo")); } void test_util_parse_http_date(void) { - CU_ASSERT(1001939696 == util::parse_http_date(StringRef::from_lit( - "Mon, 1 Oct 2001 12:34:56 GMT"))); + assert_int64(1001939696, ==, + util::parse_http_date( + StringRef::from_lit("Mon, 1 Oct 2001 12:34:56 GMT"))); } void test_util_localtime_date(void) { @@ -450,25 +528,28 @@ void test_util_localtime_date(void) { #endif // !__linux__ tzset(); - CU_ASSERT_STRING_EQUAL("02/Oct/2001:00:34:56 +1200", - util::common_log_date(1001939696).c_str()); - CU_ASSERT_STRING_EQUAL("2001-10-02T00:34:56.123+12:00", - util::iso8601_date(1001939696000LL + 123).c_str()); + assert_stdstring_equal("02/Oct/2001:00:34:56 +1200", + util::common_log_date(1001939696)); + assert_stdstring_equal("2001-10-02T00:34:56.123+12:00", + util::iso8601_date(1001939696000LL + 123)); std::array<char, 27> common_buf; - CU_ASSERT("02/Oct/2001:00:34:56 +1200" == - util::format_common_log(common_buf.data(), - std::chrono::system_clock::time_point( - std::chrono::seconds(1001939696)))); + assert_stdstring_equal( + "02/Oct/2001:00:34:56 +1200", + util::format_common_log(common_buf.data(), + std::chrono::system_clock::time_point( + std::chrono::seconds(1001939696))) + .str()); std::array<char, 30> iso8601_buf; - CU_ASSERT( - "2001-10-02T00:34:56.123+12:00" == + assert_stdstring_equal( + "2001-10-02T00:34:56.123+12:00", util::format_iso8601(iso8601_buf.data(), std::chrono::system_clock::time_point( - std::chrono::milliseconds(1001939696123LL)))); + std::chrono::milliseconds(1001939696123LL))) + .str()); if (tz) { setenv("TZ", tz, 1); @@ -486,7 +567,7 @@ void test_util_get_uint64(void) { auto n = util::get_uint64(v.data()); - CU_ASSERT(0x01123456ff9aabbcULL == n); + assert_uint64(0x01123456ff9aabbcULL, ==, n); } { auto v = std::array<unsigned char, 8>{ @@ -494,83 +575,91 @@ void test_util_get_uint64(void) { auto n = util::get_uint64(v.data()); - CU_ASSERT(0xffffffffffffffffULL == n); + assert_uint64(0xffffffffffffffffULL, ==, n); } } void test_util_parse_config_str_list(void) { auto res = util::parse_config_str_list(StringRef::from_lit("a")); - CU_ASSERT(1 == res.size()); - CU_ASSERT("a" == res[0]); + assert_size(1, ==, res.size()); + assert_stdstring_equal("a", res[0]); res = util::parse_config_str_list(StringRef::from_lit("a,")); - CU_ASSERT(2 == res.size()); - CU_ASSERT("a" == res[0]); - CU_ASSERT("" == res[1]); + assert_size(2, ==, res.size()); + assert_stdstring_equal("a", res[0]); + assert_stdstring_equal("", res[1]); res = util::parse_config_str_list(StringRef::from_lit(":a::"), ':'); - CU_ASSERT(4 == res.size()); - CU_ASSERT("" == res[0]); - CU_ASSERT("a" == res[1]); - CU_ASSERT("" == res[2]); - CU_ASSERT("" == res[3]); + assert_size(4, ==, res.size()); + assert_stdstring_equal("", res[0]); + assert_stdstring_equal("a", res[1]); + assert_stdstring_equal("", res[2]); + assert_stdstring_equal("", res[3]); res = util::parse_config_str_list(StringRef{}); - CU_ASSERT(1 == res.size()); - CU_ASSERT("" == res[0]); + assert_size(1, ==, res.size()); + assert_stdstring_equal("", res[0]); res = util::parse_config_str_list(StringRef::from_lit("alpha,bravo,charlie")); - CU_ASSERT(3 == res.size()); - CU_ASSERT("alpha" == res[0]); - CU_ASSERT("bravo" == res[1]); - CU_ASSERT("charlie" == res[2]); + assert_size(3, ==, res.size()); + assert_stdstring_equal("alpha", res[0]); + assert_stdstring_equal("bravo", res[1]); + assert_stdstring_equal("charlie", res[2]); } void test_util_make_http_hostport(void) { BlockAllocator balloc(4096, 4096); - CU_ASSERT("localhost" == util::make_http_hostport( - balloc, StringRef::from_lit("localhost"), 80)); - CU_ASSERT("[::1]" == - util::make_http_hostport(balloc, StringRef::from_lit("::1"), 443)); - CU_ASSERT( - "localhost:3000" == - util::make_http_hostport(balloc, StringRef::from_lit("localhost"), 3000)); + assert_stdstring_equal( + "localhost", + util::make_http_hostport(balloc, StringRef::from_lit("localhost"), 80) + .str()); + assert_stdstring_equal( + "[::1]", + util::make_http_hostport(balloc, StringRef::from_lit("::1"), 443).str()); + assert_stdstring_equal( + "localhost:3000", + util::make_http_hostport(balloc, StringRef::from_lit("localhost"), 3000) + .str()); } void test_util_make_hostport(void) { std::array<char, util::max_hostport> hostport_buf; - CU_ASSERT("localhost:80" == - util::make_hostport(std::begin(hostport_buf), - StringRef::from_lit("localhost"), 80)); - CU_ASSERT("[::1]:443" == util::make_hostport(std::begin(hostport_buf), - StringRef::from_lit("::1"), - 443)); + assert_stdstring_equal( + "localhost:80", util::make_hostport(std::begin(hostport_buf), + StringRef::from_lit("localhost"), 80) + .str()); + assert_stdstring_equal("[::1]:443", + util::make_hostport(std::begin(hostport_buf), + StringRef::from_lit("::1"), 443) + .str()); BlockAllocator balloc(4096, 4096); - CU_ASSERT("localhost:80" == - util::make_hostport(balloc, StringRef::from_lit("localhost"), 80)); - CU_ASSERT("[::1]:443" == - util::make_hostport(balloc, StringRef::from_lit("::1"), 443)); + assert_stdstring_equal( + "localhost:80", + util::make_hostport(balloc, StringRef::from_lit("localhost"), 80).str()); + assert_stdstring_equal( + "[::1]:443", + util::make_hostport(balloc, StringRef::from_lit("::1"), 443).str()); } void test_util_strifind(void) { - CU_ASSERT(util::strifind(StringRef::from_lit("gzip, deflate, bzip2"), - StringRef::from_lit("gzip"))); + assert_true(util::strifind(StringRef::from_lit("gzip, deflate, bzip2"), + StringRef::from_lit("gzip"))); - CU_ASSERT(util::strifind(StringRef::from_lit("gzip, deflate, bzip2"), - StringRef::from_lit("dEflate"))); + assert_true(util::strifind(StringRef::from_lit("gzip, deflate, bzip2"), + StringRef::from_lit("dEflate"))); - CU_ASSERT(util::strifind(StringRef::from_lit("gzip, deflate, bzip2"), - StringRef::from_lit("BZIP2"))); + assert_true(util::strifind(StringRef::from_lit("gzip, deflate, bzip2"), + StringRef::from_lit("BZIP2"))); - CU_ASSERT(util::strifind(StringRef::from_lit("nghttp2"), StringRef{})); + assert_true(util::strifind(StringRef::from_lit("nghttp2"), StringRef{})); // Be aware this fact - CU_ASSERT(!util::strifind(StringRef{}, StringRef{})); + assert_false(util::strifind(StringRef{}, StringRef{})); - CU_ASSERT(!util::strifind(StringRef::from_lit("nghttp2"), - StringRef::from_lit("http1"))); + assert_false(util::strifind(StringRef::from_lit("nghttp2"), + StringRef::from_lit("http1"))); } void test_util_random_alpha_digit(void) { @@ -580,116 +669,117 @@ void test_util_random_alpha_digit(void) { auto p = util::random_alpha_digit(std::begin(data), std::end(data), gen); - CU_ASSERT(std::end(data) == p); + assert_true(std::end(data) == p); for (auto b : data) { - CU_ASSERT(('A' <= b && b <= 'Z') || ('a' <= b && b <= 'z') || - ('0' <= b && b <= '9')); + assert_true(('A' <= b && b <= 'Z') || ('a' <= b && b <= 'z') || + ('0' <= b && b <= '9')); } } void test_util_format_hex(void) { BlockAllocator balloc(4096, 4096); - CU_ASSERT("0ff0" == - util::format_hex(balloc, StringRef::from_lit("\x0f\xf0"))); - CU_ASSERT("" == util::format_hex(balloc, StringRef::from_lit(""))); + assert_stdstring_equal( + "0ff0", util::format_hex(balloc, StringRef::from_lit("\x0f\xf0")).str()); + assert_stdstring_equal( + "", util::format_hex(balloc, StringRef::from_lit("")).str()); } void test_util_is_hex_string(void) { - CU_ASSERT(util::is_hex_string(StringRef{})); - CU_ASSERT(util::is_hex_string(StringRef::from_lit("0123456789abcdef"))); - CU_ASSERT(util::is_hex_string(StringRef::from_lit("0123456789ABCDEF"))); - CU_ASSERT(!util::is_hex_string(StringRef::from_lit("000"))); - CU_ASSERT(!util::is_hex_string(StringRef::from_lit("XX"))); + assert_true(util::is_hex_string(StringRef{})); + assert_true(util::is_hex_string(StringRef::from_lit("0123456789abcdef"))); + assert_true(util::is_hex_string(StringRef::from_lit("0123456789ABCDEF"))); + assert_false(util::is_hex_string(StringRef::from_lit("000"))); + assert_false(util::is_hex_string(StringRef::from_lit("XX"))); } void test_util_decode_hex(void) { BlockAllocator balloc(4096, 4096); - CU_ASSERT("\x0f\xf0" == - util::decode_hex(balloc, StringRef::from_lit("0ff0"))); - CU_ASSERT("" == util::decode_hex(balloc, StringRef{})); + assert_stdstring_equal( + "\x0f\xf0", util::decode_hex(balloc, StringRef::from_lit("0ff0")).str()); + assert_stdstring_equal("", util::decode_hex(balloc, StringRef{}).str()); } void test_util_extract_host(void) { - CU_ASSERT(StringRef::from_lit("foo") == - util::extract_host(StringRef::from_lit("foo"))); - CU_ASSERT(StringRef::from_lit("foo") == - util::extract_host(StringRef::from_lit("foo:"))); - CU_ASSERT(StringRef::from_lit("foo") == - util::extract_host(StringRef::from_lit("foo:0"))); - CU_ASSERT(StringRef::from_lit("[::1]") == - util::extract_host(StringRef::from_lit("[::1]"))); - CU_ASSERT(StringRef::from_lit("[::1]") == - util::extract_host(StringRef::from_lit("[::1]:"))); - - CU_ASSERT(util::extract_host(StringRef::from_lit(":foo")).empty()); - CU_ASSERT(util::extract_host(StringRef::from_lit("[::1")).empty()); - CU_ASSERT(util::extract_host(StringRef::from_lit("[::1]0")).empty()); - CU_ASSERT(util::extract_host(StringRef{}).empty()); + assert_stdstring_equal("foo", + util::extract_host(StringRef::from_lit("foo")).str()); + assert_stdstring_equal("foo", + util::extract_host(StringRef::from_lit("foo:")).str()); + assert_stdstring_equal( + "foo", util::extract_host(StringRef::from_lit("foo:0")).str()); + assert_stdstring_equal( + "[::1]", util::extract_host(StringRef::from_lit("[::1]")).str()); + assert_stdstring_equal( + "[::1]", util::extract_host(StringRef::from_lit("[::1]:")).str()); + + assert_true(util::extract_host(StringRef::from_lit(":foo")).empty()); + assert_true(util::extract_host(StringRef::from_lit("[::1")).empty()); + assert_true(util::extract_host(StringRef::from_lit("[::1]0")).empty()); + assert_true(util::extract_host(StringRef{}).empty()); } void test_util_split_hostport(void) { - CU_ASSERT(std::make_pair(StringRef::from_lit("foo"), StringRef{}) == - util::split_hostport(StringRef::from_lit("foo"))); - CU_ASSERT( + assert_true(std::make_pair(StringRef::from_lit("foo"), StringRef{}) == + util::split_hostport(StringRef::from_lit("foo"))); + assert_true( std::make_pair(StringRef::from_lit("foo"), StringRef::from_lit("80")) == util::split_hostport(StringRef::from_lit("foo:80"))); - CU_ASSERT( + assert_true( std::make_pair(StringRef::from_lit("::1"), StringRef::from_lit("80")) == util::split_hostport(StringRef::from_lit("[::1]:80"))); - CU_ASSERT(std::make_pair(StringRef::from_lit("::1"), StringRef{}) == - util::split_hostport(StringRef::from_lit("[::1]"))); + assert_true(std::make_pair(StringRef::from_lit("::1"), StringRef{}) == + util::split_hostport(StringRef::from_lit("[::1]"))); - CU_ASSERT(std::make_pair(StringRef{}, StringRef{}) == - util::split_hostport(StringRef{})); - CU_ASSERT(std::make_pair(StringRef{}, StringRef{}) == - util::split_hostport(StringRef::from_lit("[::1]:"))); - CU_ASSERT(std::make_pair(StringRef{}, StringRef{}) == - util::split_hostport(StringRef::from_lit("foo:"))); - CU_ASSERT(std::make_pair(StringRef{}, StringRef{}) == - util::split_hostport(StringRef::from_lit("[::1:"))); - CU_ASSERT(std::make_pair(StringRef{}, StringRef{}) == - util::split_hostport(StringRef::from_lit("[::1]80"))); + assert_true(std::make_pair(StringRef{}, StringRef{}) == + util::split_hostport(StringRef{})); + assert_true(std::make_pair(StringRef{}, StringRef{}) == + util::split_hostport(StringRef::from_lit("[::1]:"))); + assert_true(std::make_pair(StringRef{}, StringRef{}) == + util::split_hostport(StringRef::from_lit("foo:"))); + assert_true(std::make_pair(StringRef{}, StringRef{}) == + util::split_hostport(StringRef::from_lit("[::1:"))); + assert_true(std::make_pair(StringRef{}, StringRef{}) == + util::split_hostport(StringRef::from_lit("[::1]80"))); } void test_util_split_str(void) { - CU_ASSERT(std::vector<StringRef>{StringRef::from_lit("")} == - util::split_str(StringRef::from_lit(""), ',')); - CU_ASSERT(std::vector<StringRef>{StringRef::from_lit("alpha")} == - util::split_str(StringRef::from_lit("alpha"), ',')); - CU_ASSERT((std::vector<StringRef>{StringRef::from_lit("alpha"), - StringRef::from_lit("")}) == - util::split_str(StringRef::from_lit("alpha,"), ',')); - CU_ASSERT((std::vector<StringRef>{StringRef::from_lit("alpha"), - StringRef::from_lit("bravo")}) == - util::split_str(StringRef::from_lit("alpha,bravo"), ',')); - CU_ASSERT((std::vector<StringRef>{StringRef::from_lit("alpha"), - StringRef::from_lit("bravo"), - StringRef::from_lit("charlie")}) == - util::split_str(StringRef::from_lit("alpha,bravo,charlie"), ',')); - CU_ASSERT( + assert_true(std::vector<StringRef>{StringRef::from_lit("")} == + util::split_str(StringRef::from_lit(""), ',')); + assert_true(std::vector<StringRef>{StringRef::from_lit("alpha")} == + util::split_str(StringRef::from_lit("alpha"), ',')); + assert_true((std::vector<StringRef>{StringRef::from_lit("alpha"), + StringRef::from_lit("")}) == + util::split_str(StringRef::from_lit("alpha,"), ',')); + assert_true((std::vector<StringRef>{StringRef::from_lit("alpha"), + StringRef::from_lit("bravo")}) == + util::split_str(StringRef::from_lit("alpha,bravo"), ',')); + assert_true((std::vector<StringRef>{StringRef::from_lit("alpha"), + StringRef::from_lit("bravo"), + StringRef::from_lit("charlie")}) == + util::split_str(StringRef::from_lit("alpha,bravo,charlie"), ',')); + assert_true( (std::vector<StringRef>{StringRef::from_lit("alpha"), StringRef::from_lit("bravo"), StringRef::from_lit("charlie")}) == util::split_str(StringRef::from_lit("alpha,bravo,charlie"), ',', 0)); - CU_ASSERT(std::vector<StringRef>{StringRef::from_lit("")} == - util::split_str(StringRef::from_lit(""), ',', 1)); - CU_ASSERT(std::vector<StringRef>{StringRef::from_lit("")} == - util::split_str(StringRef::from_lit(""), ',', 2)); - CU_ASSERT( + assert_true(std::vector<StringRef>{StringRef::from_lit("")} == + util::split_str(StringRef::from_lit(""), ',', 1)); + assert_true(std::vector<StringRef>{StringRef::from_lit("")} == + util::split_str(StringRef::from_lit(""), ',', 2)); + assert_true( (std::vector<StringRef>{StringRef::from_lit("alpha"), StringRef::from_lit("bravo,charlie")}) == util::split_str(StringRef::from_lit("alpha,bravo,charlie"), ',', 2)); - CU_ASSERT(std::vector<StringRef>{StringRef::from_lit("alpha")} == - util::split_str(StringRef::from_lit("alpha"), ',', 2)); - CU_ASSERT((std::vector<StringRef>{StringRef::from_lit("alpha"), - StringRef::from_lit("")}) == - util::split_str(StringRef::from_lit("alpha,"), ',', 2)); - CU_ASSERT(std::vector<StringRef>{StringRef::from_lit("alpha")} == - util::split_str(StringRef::from_lit("alpha"), ',', 0)); - CU_ASSERT( + assert_true(std::vector<StringRef>{StringRef::from_lit("alpha")} == + util::split_str(StringRef::from_lit("alpha"), ',', 2)); + assert_true((std::vector<StringRef>{StringRef::from_lit("alpha"), + StringRef::from_lit("")}) == + util::split_str(StringRef::from_lit("alpha,"), ',', 2)); + assert_true(std::vector<StringRef>{StringRef::from_lit("alpha")} == + util::split_str(StringRef::from_lit("alpha"), ',', 0)); + assert_true( std::vector<StringRef>{StringRef::from_lit("alpha,bravo,charlie")} == util::split_str(StringRef::from_lit("alpha,bravo,charlie"), ',', 1)); } @@ -697,11 +787,16 @@ void test_util_split_str(void) { void test_util_rstrip(void) { BlockAllocator balloc(4096, 4096); - CU_ASSERT("alpha" == util::rstrip(balloc, StringRef::from_lit("alpha"))); - CU_ASSERT("alpha" == util::rstrip(balloc, StringRef::from_lit("alpha "))); - CU_ASSERT("alpha" == util::rstrip(balloc, StringRef::from_lit("alpha \t"))); - CU_ASSERT("" == util::rstrip(balloc, StringRef::from_lit(""))); - CU_ASSERT("" == util::rstrip(balloc, StringRef::from_lit("\t\t\t "))); + assert_stdstring_equal( + "alpha", util::rstrip(balloc, StringRef::from_lit("alpha")).str()); + assert_stdstring_equal( + "alpha", util::rstrip(balloc, StringRef::from_lit("alpha ")).str()); + assert_stdstring_equal( + "alpha", util::rstrip(balloc, StringRef::from_lit("alpha \t")).str()); + assert_stdstring_equal("", + util::rstrip(balloc, StringRef::from_lit("")).str()); + assert_stdstring_equal( + "", util::rstrip(balloc, StringRef::from_lit("\t\t\t ")).str()); } } // namespace shrpx diff --git a/src/util_test.h b/src/util_test.h index 48925ab..8b9608b 100644 --- a/src/util_test.h +++ b/src/util_test.h @@ -29,46 +29,52 @@ # include <config.h> #endif // HAVE_CONFIG_H +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + namespace shrpx { -void test_util_streq(void); -void test_util_strieq(void); -void test_util_inp_strlower(void); -void test_util_to_base64(void); -void test_util_to_token68(void); -void test_util_percent_encode_token(void); -void test_util_percent_decode(void); -void test_util_quote_string(void); -void test_util_utox(void); -void test_util_http_date(void); -void test_util_select_h2(void); -void test_util_ipv6_numeric_addr(void); -void test_util_utos(void); -void test_util_make_string_ref_uint(void); -void test_util_utos_unit(void); -void test_util_utos_funit(void); -void test_util_parse_uint_with_unit(void); -void test_util_parse_uint(void); -void test_util_parse_duration_with_unit(void); -void test_util_duration_str(void); -void test_util_format_duration(void); -void test_util_starts_with(void); -void test_util_ends_with(void); -void test_util_parse_http_date(void); -void test_util_localtime_date(void); -void test_util_get_uint64(void); -void test_util_parse_config_str_list(void); -void test_util_make_http_hostport(void); -void test_util_make_hostport(void); -void test_util_strifind(void); -void test_util_random_alpha_digit(void); -void test_util_format_hex(void); -void test_util_is_hex_string(void); -void test_util_decode_hex(void); -void test_util_extract_host(void); -void test_util_split_hostport(void); -void test_util_split_str(void); -void test_util_rstrip(void); +extern const MunitSuite util_suite; + +munit_void_test_decl(test_util_streq); +munit_void_test_decl(test_util_strieq); +munit_void_test_decl(test_util_inp_strlower); +munit_void_test_decl(test_util_to_base64); +munit_void_test_decl(test_util_to_token68); +munit_void_test_decl(test_util_percent_encode_token); +munit_void_test_decl(test_util_percent_decode); +munit_void_test_decl(test_util_quote_string); +munit_void_test_decl(test_util_utox); +munit_void_test_decl(test_util_http_date); +munit_void_test_decl(test_util_select_h2); +munit_void_test_decl(test_util_ipv6_numeric_addr); +munit_void_test_decl(test_util_utos); +munit_void_test_decl(test_util_make_string_ref_uint); +munit_void_test_decl(test_util_utos_unit); +munit_void_test_decl(test_util_utos_funit); +munit_void_test_decl(test_util_parse_uint_with_unit); +munit_void_test_decl(test_util_parse_uint); +munit_void_test_decl(test_util_parse_duration_with_unit); +munit_void_test_decl(test_util_duration_str); +munit_void_test_decl(test_util_format_duration); +munit_void_test_decl(test_util_starts_with); +munit_void_test_decl(test_util_ends_with); +munit_void_test_decl(test_util_parse_http_date); +munit_void_test_decl(test_util_localtime_date); +munit_void_test_decl(test_util_get_uint64); +munit_void_test_decl(test_util_parse_config_str_list); +munit_void_test_decl(test_util_make_http_hostport); +munit_void_test_decl(test_util_make_hostport); +munit_void_test_decl(test_util_strifind); +munit_void_test_decl(test_util_random_alpha_digit); +munit_void_test_decl(test_util_format_hex); +munit_void_test_decl(test_util_is_hex_string); +munit_void_test_decl(test_util_decode_hex); +munit_void_test_decl(test_util_extract_host); +munit_void_test_decl(test_util_split_hostport); +munit_void_test_decl(test_util_split_str); +munit_void_test_decl(test_util_rstrip); } // namespace shrpx diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b20ccf7..852cb10 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,55 +1,52 @@ # XXX testdata/: EXTRA_DIST = cacert.pem index.html privkey.pem -if(HAVE_CUNIT) - string(REPLACE " " ";" c_flags "${WARNCFLAGS}") - add_compile_options(${c_flags}) +string(REPLACE " " ";" c_flags "${WARNCFLAGS}") +add_compile_options(${c_flags}) - include_directories( - "${CMAKE_SOURCE_DIR}/lib/includes" - "${CMAKE_SOURCE_DIR}/lib" - "${CMAKE_BINARY_DIR}/lib/includes" - ${CUNIT_INCLUDE_DIRS} - ) +include_directories( + "${CMAKE_SOURCE_DIR}/lib/includes" + "${CMAKE_SOURCE_DIR}/lib" + "${CMAKE_SOURCE_DIR}/tests/munit" + "${CMAKE_BINARY_DIR}/lib/includes" +) + +set(MAIN_SOURCES + main.c nghttp2_pq_test.c nghttp2_map_test.c nghttp2_queue_test.c + nghttp2_test_helper.c + nghttp2_frame_test.c + nghttp2_stream_test.c + nghttp2_session_test.c + nghttp2_hd_test.c + nghttp2_alpn_test.c + nghttp2_helper_test.c + nghttp2_buf_test.c + nghttp2_http_test.c + nghttp2_extpri_test.c + nghttp2_ratelim_test.c + munit/munit.c +) + +add_executable(main EXCLUDE_FROM_ALL + ${MAIN_SOURCES} +) +target_link_libraries(main + nghttp2_static +) +add_test(main main) +add_dependencies(check main) - set(MAIN_SOURCES - main.c nghttp2_pq_test.c nghttp2_map_test.c nghttp2_queue_test.c +if(ENABLE_FAILMALLOC) + set(FAILMALLOC_SOURCES + failmalloc.c failmalloc_test.c + malloc_wrapper.c nghttp2_test_helper.c - nghttp2_frame_test.c - nghttp2_stream_test.c - nghttp2_session_test.c - nghttp2_hd_test.c - nghttp2_alpn_test.c - nghttp2_helper_test.c - nghttp2_buf_test.c - nghttp2_http_test.c - nghttp2_extpri_test.c - nghttp2_ratelim_test.c + munit/munit.c ) - - add_executable(main EXCLUDE_FROM_ALL - ${MAIN_SOURCES} + add_executable(failmalloc EXCLUDE_FROM_ALL + ${FAILMALLOC_SOURCES} ) - target_include_directories(main PRIVATE ${CUNIT_INCLUDE_DIRS}) - target_link_libraries(main + target_link_libraries(failmalloc nghttp2_static - ${CUNIT_LIBRARIES} ) - add_test(main main) - add_dependencies(check main) - - if(ENABLE_FAILMALLOC) - set(FAILMALLOC_SOURCES - failmalloc.c failmalloc_test.c - malloc_wrapper.c - nghttp2_test_helper.c - ) - add_executable(failmalloc EXCLUDE_FROM_ALL - ${FAILMALLOC_SOURCES} - ) - target_link_libraries(failmalloc - nghttp2_static - ${CUNIT_LIBRARIES} - ) - add_test(failmalloc failmalloc) - add_dependencies(check failmalloc) - endif() + add_test(failmalloc failmalloc) + add_dependencies(check failmalloc) endif() diff --git a/tests/Makefile.am b/tests/Makefile.am index 1c506d8..456f65f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -22,9 +22,7 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. SUBDIRS = testdata -EXTRA_DIST = CMakeLists.txt - -if HAVE_CUNIT +EXTRA_DIST = CMakeLists.txt munit/COPYING check_PROGRAMS = main @@ -43,17 +41,20 @@ OBJECTS = main.c nghttp2_pq_test.c nghttp2_map_test.c nghttp2_queue_test.c \ nghttp2_buf_test.c \ nghttp2_http_test.c \ nghttp2_extpri_test.c \ - nghttp2_ratelim_test.c + nghttp2_ratelim_test.c \ + munit/munit.c HFILES = nghttp2_pq_test.h nghttp2_map_test.h nghttp2_queue_test.h \ nghttp2_session_test.h \ nghttp2_frame_test.h nghttp2_stream_test.h nghttp2_hd_test.h \ nghttp2_alpn_test.h nghttp2_helper_test.h \ + nghttp2_assertion.h \ nghttp2_test_helper.h \ nghttp2_buf_test.h \ nghttp2_http_test.h \ nghttp2_extpri_test.h \ - nghttp2_ratelim_test.h + nghttp2_ratelim_test.h \ + munit/munit.h main_SOURCES = $(HFILES) $(OBJECTS) @@ -65,13 +66,14 @@ else main_LDADD = ${top_builddir}/lib/.libs/*.o endif -main_LDADD += @CUNIT_LIBS@ @TESTLDADD@ +main_LDADD += @TESTLDADD@ main_LDFLAGS = -static if ENABLE_FAILMALLOC failmalloc_SOURCES = failmalloc.c failmalloc_test.c failmalloc_test.h \ malloc_wrapper.c malloc_wrapper.h \ - nghttp2_test_helper.c nghttp2_test_helper.h + nghttp2_test_helper.c nghttp2_test_helper.h \ + munit/munit.c munit/munit.h failmalloc_LDADD = $(main_LDADD) failmalloc_LDFLAGS = $(main_LDFLAGS) endif # ENABLE_FAILMALLOC @@ -79,15 +81,14 @@ endif # ENABLE_FAILMALLOC AM_CFLAGS = $(WARNCFLAGS) \ -I${top_srcdir}/lib \ -I${top_srcdir}/lib/includes \ + -I${top_srcdir}/tests/munit \ -I${top_builddir}/lib/includes \ -DBUILDING_NGHTTP2 \ -DNGHTTP2_STATICLIB \ - @CUNIT_CFLAGS@ @DEFS@ + @DEFS@ TESTS = main if ENABLE_FAILMALLOC TESTS += failmalloc endif # ENABLE_FAILMALLOC - -endif # HAVE_CUNIT diff --git a/tests/failmalloc.c b/tests/failmalloc.c index 6294cff..b491deb 100644 --- a/tests/failmalloc.c +++ b/tests/failmalloc.c @@ -26,54 +26,20 @@ # include <config.h> #endif /* HAVE_CONFIG_H */ -#include <stdio.h> -#include <string.h> -#include <CUnit/Basic.h> +#include "munit.h" + /* include test cases' include files here */ #include "failmalloc_test.h" -static int init_suite1(void) { return 0; } - -static int clean_suite1(void) { return 0; } - -int main(void) { - CU_pSuite pSuite = NULL; - unsigned int num_tests_failed; - - /* initialize the CUnit test registry */ - if (CUE_SUCCESS != CU_initialize_registry()) - return (int)CU_get_error(); - - /* add a suite to the registry */ - pSuite = CU_add_suite("libnghttp2_TestSuite", init_suite1, clean_suite1); - if (NULL == pSuite) { - CU_cleanup_registry(); - return (int)CU_get_error(); - } - - /* add the tests to the suite */ - if (!CU_add_test(pSuite, "failmalloc_session_send", - test_nghttp2_session_send) || - !CU_add_test(pSuite, "failmalloc_session_send_server", - test_nghttp2_session_send_server) || - !CU_add_test(pSuite, "failmalloc_session_recv", - test_nghttp2_session_recv) || - !CU_add_test(pSuite, "failmalloc_frame", test_nghttp2_frame) || - !CU_add_test(pSuite, "failmalloc_hd", test_nghttp2_hd)) { - CU_cleanup_registry(); - return (int)CU_get_error(); - } +int main(int argc, char *argv[]) { + const MunitSuite suites[] = { + failmalloc_suite, + {NULL, NULL, NULL, 0, MUNIT_SUITE_OPTION_NONE}, + }; + const MunitSuite suite = { + "", NULL, suites, 1, MUNIT_SUITE_OPTION_NONE, + }; - /* Run all tests using the CUnit Basic interface */ - CU_basic_set_mode(CU_BRM_VERBOSE); - CU_basic_run_tests(); - num_tests_failed = CU_get_number_of_tests_failed(); - CU_cleanup_registry(); - if (CU_get_error() == CUE_SUCCESS) { - return (int)num_tests_failed; - } else { - printf("CUnit Error: %s\n", CU_get_error_msg()); - return (int)CU_get_error(); - } + return munit_suite_main(&suite, NULL, argc, argv); } diff --git a/tests/failmalloc_test.c b/tests/failmalloc_test.c index 594bc72..5b204fe 100644 --- a/tests/failmalloc_test.c +++ b/tests/failmalloc_test.c @@ -27,7 +27,7 @@ #include <stdio.h> #include <assert.h> -#include <CUnit/CUnit.h> +#include "munit.h" #include "nghttp2_session.h" #include "nghttp2_stream.h" @@ -36,6 +36,19 @@ #include "malloc_wrapper.h" #include "nghttp2_test_helper.h" +static const MunitTest tests[] = { + munit_void_test(test_nghttp2_session_send), + munit_void_test(test_nghttp2_session_send_server), + munit_void_test(test_nghttp2_session_recv), + munit_void_test(test_nghttp2_frame), + munit_void_test(test_nghttp2_hd), + munit_test_end(), +}; + +const MunitSuite failmalloc_suite = { + "/failmalloc", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + typedef struct { uint8_t data[8192]; uint8_t *datamark, *datalimit; @@ -59,18 +72,20 @@ static void data_feed_init(data_feed *df, nghttp2_bufs *bufs) { df->datalimit = df->data + data_length; } -static ssize_t null_send_callback(nghttp2_session *session, const uint8_t *data, - size_t len, int flags, void *user_data) { +static nghttp2_ssize null_send_callback(nghttp2_session *session, + const uint8_t *data, size_t len, + int flags, void *user_data) { (void)session; (void)data; (void)flags; (void)user_data; - return (ssize_t)len; + return (nghttp2_ssize)len; } -static ssize_t data_feed_recv_callback(nghttp2_session *session, uint8_t *data, - size_t len, int flags, void *user_data) { +static nghttp2_ssize data_feed_recv_callback(nghttp2_session *session, + uint8_t *data, size_t len, + int flags, void *user_data) { data_feed *df = ((my_user_data *)user_data)->df; size_t avail = (size_t)(df->datalimit - df->datamark); size_t wlen = nghttp2_min(avail, len); @@ -79,10 +94,10 @@ static ssize_t data_feed_recv_callback(nghttp2_session *session, uint8_t *data, memcpy(data, df->datamark, wlen); df->datamark += wlen; - return (ssize_t)wlen; + return (nghttp2_ssize)wlen; } -static ssize_t fixed_length_data_source_read_callback( +static nghttp2_ssize fixed_length_data_source_read_callback( nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t len, uint32_t *data_flags, nghttp2_data_source *source, void *user_data) { my_user_data *ud = (my_user_data *)user_data; @@ -101,7 +116,7 @@ static ssize_t fixed_length_data_source_read_callback( if (ud->data_source_length == 0) { *data_flags = NGHTTP2_DATA_FLAG_EOF; } - return (ssize_t)wlen; + return (nghttp2_ssize)wlen; } #define TEST_FAILMALLOC_RUN(FUN) \ @@ -129,12 +144,12 @@ static void run_nghttp2_session_send(void) { nghttp2_session_callbacks callbacks; nghttp2_nv nv[] = {MAKE_NV(":host", "example.org"), MAKE_NV(":scheme", "https")}; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; nghttp2_settings_entry iv[2]; my_user_data ud; int rv; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; data_prd.read_callback = fixed_length_data_source_read_callback; ud.data_source_length = 64 * 1024; @@ -149,7 +164,7 @@ static void run_nghttp2_session_send(void) { if (rv != 0) { goto client_new_fail; } - rv = nghttp2_submit_request(session, NULL, nv, ARRLEN(nv), &data_prd, NULL); + rv = nghttp2_submit_request2(session, NULL, nv, ARRLEN(nv), &data_prd, NULL); if (rv < 0) { goto fail; } @@ -169,7 +184,7 @@ static void run_nghttp2_session_send(void) { if (rv != 0) { goto fail; } - rv = nghttp2_submit_data(session, NGHTTP2_FLAG_END_STREAM, 3, &data_prd); + rv = nghttp2_submit_data2(session, NGHTTP2_FLAG_END_STREAM, 3, &data_prd); if (rv != 0) { goto fail; } @@ -221,7 +236,7 @@ static void run_nghttp2_session_send_server(void) { nghttp2_session_callbacks *callbacks; int rv; const uint8_t *txdata; - ssize_t txdatalen; + nghttp2_ssize txdatalen; const uint8_t origin[] = "nghttp2.org"; const uint8_t altsvc_field_value[] = "h2=\":443\""; static const uint8_t nghttp2[] = "https://nghttp2.org"; @@ -256,7 +271,7 @@ static void run_nghttp2_session_send_server(void) { goto fail; } - txdatalen = nghttp2_session_mem_send(session, &txdata); + txdatalen = nghttp2_session_mem_send2(session, &txdata); if (txdatalen < 0) { goto fail; @@ -296,7 +311,7 @@ static void run_nghttp2_session_recv(void) { } memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.recv_callback = data_feed_recv_callback; + callbacks.recv_callback2 = data_feed_recv_callback; ud.df = &df; nghttp2_failmalloc_pause(); diff --git a/tests/failmalloc_test.h b/tests/failmalloc_test.h index 576932a..9664480 100644 --- a/tests/failmalloc_test.h +++ b/tests/failmalloc_test.h @@ -29,10 +29,16 @@ # include <config.h> #endif /* HAVE_CONFIG_H */ -void test_nghttp2_session_send(void); -void test_nghttp2_session_send_server(void); -void test_nghttp2_session_recv(void); -void test_nghttp2_frame(void); -void test_nghttp2_hd(void); +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + +extern const MunitSuite failmalloc_suite; + +munit_void_test_decl(test_nghttp2_session_send); +munit_void_test_decl(test_nghttp2_session_send_server); +munit_void_test_decl(test_nghttp2_session_recv); +munit_void_test_decl(test_nghttp2_frame); +munit_void_test_decl(test_nghttp2_hd); #endif /* FAILMALLOC_TEST_H */ diff --git a/tests/main.c b/tests/main.c index 6827daf..ebee3de 100644 --- a/tests/main.c +++ b/tests/main.c @@ -26,9 +26,8 @@ # include <config.h> #endif /* HAVE_CONFIG_H */ -#include <stdio.h> -#include <string.h> -#include <CUnit/Basic.h> +#include "munit.h" + /* include test cases' include files here */ #include "nghttp2_pq_test.h" #include "nghttp2_map_test.h" @@ -46,428 +45,27 @@ extern int nghttp2_enable_strict_preface; -static int init_suite1(void) { return 0; } - -static int clean_suite1(void) { return 0; } - -int main(void) { - CU_pSuite pSuite = NULL; - unsigned int num_tests_failed; +int main(int argc, char *argv[]) { + const MunitSuite suites[] = { + pq_suite, + map_suite, + queue_suite, + frame_suite, + session_suite, + hd_suite, + alpn_suite, + helper_suite, + buf_suite, + http_suite, + extpri_suite, + ratelim_suite, + {NULL, NULL, NULL, 0, MUNIT_SUITE_OPTION_NONE}, + }; + const MunitSuite suite = { + "", NULL, suites, 1, MUNIT_SUITE_OPTION_NONE, + }; nghttp2_enable_strict_preface = 0; - /* initialize the CUnit test registry */ - if (CUE_SUCCESS != CU_initialize_registry()) - return (int)CU_get_error(); - - /* add a suite to the registry */ - pSuite = CU_add_suite("libnghttp2_TestSuite", init_suite1, clean_suite1); - if (NULL == pSuite) { - CU_cleanup_registry(); - return (int)CU_get_error(); - } - - /* add the tests to the suite */ - if (!CU_add_test(pSuite, "pq", test_nghttp2_pq) || - !CU_add_test(pSuite, "pq_update", test_nghttp2_pq_update) || - !CU_add_test(pSuite, "pq_remove", test_nghttp2_pq_remove) || - !CU_add_test(pSuite, "map", test_nghttp2_map) || - !CU_add_test(pSuite, "map_functional", test_nghttp2_map_functional) || - !CU_add_test(pSuite, "map_each_free", test_nghttp2_map_each_free) || - !CU_add_test(pSuite, "queue", test_nghttp2_queue) || - !CU_add_test(pSuite, "alpn", test_nghttp2_alpn) || - !CU_add_test(pSuite, "session_recv", test_nghttp2_session_recv) || - !CU_add_test(pSuite, "session_recv_invalid_stream_id", - test_nghttp2_session_recv_invalid_stream_id) || - !CU_add_test(pSuite, "session_recv_invalid_frame", - test_nghttp2_session_recv_invalid_frame) || - !CU_add_test(pSuite, "session_recv_eof", test_nghttp2_session_recv_eof) || - !CU_add_test(pSuite, "session_recv_data", - test_nghttp2_session_recv_data) || - !CU_add_test(pSuite, "session_recv_data_no_auto_flow_control", - test_nghttp2_session_recv_data_no_auto_flow_control) || - !CU_add_test(pSuite, "session_recv_continuation", - test_nghttp2_session_recv_continuation) || - !CU_add_test(pSuite, "session_recv_headers_with_priority", - test_nghttp2_session_recv_headers_with_priority) || - !CU_add_test(pSuite, "session_recv_headers_with_padding", - test_nghttp2_session_recv_headers_with_padding) || - !CU_add_test(pSuite, "session_recv_headers_early_response", - test_nghttp2_session_recv_headers_early_response) || - !CU_add_test(pSuite, "session_recv_headers_for_closed_stream", - test_nghttp2_session_recv_headers_for_closed_stream) || - !CU_add_test(pSuite, "session_recv_headers_with_extpri", - test_nghttp2_session_recv_headers_with_extpri) || - !CU_add_test(pSuite, "session_server_recv_push_response", - test_nghttp2_session_server_recv_push_response) || - !CU_add_test(pSuite, "session_recv_premature_headers", - test_nghttp2_session_recv_premature_headers) || - !CU_add_test(pSuite, "session_recv_unknown_frame", - test_nghttp2_session_recv_unknown_frame) || - !CU_add_test(pSuite, "session_recv_unexpected_continuation", - test_nghttp2_session_recv_unexpected_continuation) || - !CU_add_test(pSuite, "session_recv_settings_header_table_size", - test_nghttp2_session_recv_settings_header_table_size) || - !CU_add_test(pSuite, "session_recv_too_large_frame_length", - test_nghttp2_session_recv_too_large_frame_length) || - !CU_add_test(pSuite, "session_recv_extension", - test_nghttp2_session_recv_extension) || - !CU_add_test(pSuite, "session_recv_altsvc", - test_nghttp2_session_recv_altsvc) || - !CU_add_test(pSuite, "session_recv_origin", - test_nghttp2_session_recv_origin) || - !CU_add_test(pSuite, "session_recv_priority_update", - test_nghttp2_session_recv_priority_update) || - !CU_add_test(pSuite, "session_continue", test_nghttp2_session_continue) || - !CU_add_test(pSuite, "session_add_frame", - test_nghttp2_session_add_frame) || - !CU_add_test(pSuite, "session_on_request_headers_received", - test_nghttp2_session_on_request_headers_received) || - !CU_add_test(pSuite, "session_on_response_headers_received", - test_nghttp2_session_on_response_headers_received) || - !CU_add_test(pSuite, "session_on_headers_received", - test_nghttp2_session_on_headers_received) || - !CU_add_test(pSuite, "session_on_push_response_headers_received", - test_nghttp2_session_on_push_response_headers_received) || - !CU_add_test(pSuite, "session_on_priority_received", - test_nghttp2_session_on_priority_received) || - !CU_add_test(pSuite, "session_on_rst_stream_received", - test_nghttp2_session_on_rst_stream_received) || - !CU_add_test(pSuite, "session_on_settings_received", - test_nghttp2_session_on_settings_received) || - !CU_add_test(pSuite, "session_on_push_promise_received", - test_nghttp2_session_on_push_promise_received) || - !CU_add_test(pSuite, "session_on_ping_received", - test_nghttp2_session_on_ping_received) || - !CU_add_test(pSuite, "session_on_goaway_received", - test_nghttp2_session_on_goaway_received) || - !CU_add_test(pSuite, "session_on_window_update_received", - test_nghttp2_session_on_window_update_received) || - !CU_add_test(pSuite, "session_on_data_received", - test_nghttp2_session_on_data_received) || - !CU_add_test(pSuite, "session_on_data_received_fail_fast", - test_nghttp2_session_on_data_received_fail_fast) || - !CU_add_test(pSuite, "session_on_altsvc_received", - test_nghttp2_session_on_altsvc_received) || - !CU_add_test(pSuite, "session_send_headers_start_stream", - test_nghttp2_session_send_headers_start_stream) || - !CU_add_test(pSuite, "session_send_headers_reply", - test_nghttp2_session_send_headers_reply) || - !CU_add_test(pSuite, "session_send_headers_frame_size_error", - test_nghttp2_session_send_headers_frame_size_error) || - !CU_add_test(pSuite, "session_send_headers_push_reply", - test_nghttp2_session_send_headers_push_reply) || - !CU_add_test(pSuite, "session_send_rst_stream", - test_nghttp2_session_send_rst_stream) || - !CU_add_test(pSuite, "session_send_push_promise", - test_nghttp2_session_send_push_promise) || - !CU_add_test(pSuite, "session_is_my_stream_id", - test_nghttp2_session_is_my_stream_id) || - !CU_add_test(pSuite, "session_upgrade2", test_nghttp2_session_upgrade2) || - !CU_add_test(pSuite, "session_reprioritize_stream", - test_nghttp2_session_reprioritize_stream) || - !CU_add_test( - pSuite, "session_reprioritize_stream_with_idle_stream_dep", - test_nghttp2_session_reprioritize_stream_with_idle_stream_dep) || - !CU_add_test(pSuite, "submit_data", test_nghttp2_submit_data) || - !CU_add_test(pSuite, "submit_data_read_length_too_large", - test_nghttp2_submit_data_read_length_too_large) || - !CU_add_test(pSuite, "submit_data_read_length_smallest", - test_nghttp2_submit_data_read_length_smallest) || - !CU_add_test(pSuite, "submit_data_twice", - test_nghttp2_submit_data_twice) || - !CU_add_test(pSuite, "submit_request_with_data", - test_nghttp2_submit_request_with_data) || - !CU_add_test(pSuite, "submit_request_without_data", - test_nghttp2_submit_request_without_data) || - !CU_add_test(pSuite, "submit_response_with_data", - test_nghttp2_submit_response_with_data) || - !CU_add_test(pSuite, "submit_response_without_data", - test_nghttp2_submit_response_without_data) || - !CU_add_test(pSuite, "Submit_response_push_response", - test_nghttp2_submit_response_push_response) || - !CU_add_test(pSuite, "submit_trailer", test_nghttp2_submit_trailer) || - !CU_add_test(pSuite, "submit_headers_start_stream", - test_nghttp2_submit_headers_start_stream) || - !CU_add_test(pSuite, "submit_headers_reply", - test_nghttp2_submit_headers_reply) || - !CU_add_test(pSuite, "submit_headers_push_reply", - test_nghttp2_submit_headers_push_reply) || - !CU_add_test(pSuite, "submit_headers", test_nghttp2_submit_headers) || - !CU_add_test(pSuite, "submit_headers_continuation", - test_nghttp2_submit_headers_continuation) || - !CU_add_test(pSuite, "submit_headers_continuation_extra_large", - test_nghttp2_submit_headers_continuation_extra_large) || - !CU_add_test(pSuite, "submit_priority", test_nghttp2_submit_priority) || - !CU_add_test(pSuite, "session_submit_settings", - test_nghttp2_submit_settings) || - !CU_add_test(pSuite, "session_submit_settings_update_local_window_size", - test_nghttp2_submit_settings_update_local_window_size) || - !CU_add_test(pSuite, "session_submit_settings_multiple_times", - test_nghttp2_submit_settings_multiple_times) || - !CU_add_test(pSuite, "session_submit_push_promise", - test_nghttp2_submit_push_promise) || - !CU_add_test(pSuite, "submit_window_update", - test_nghttp2_submit_window_update) || - !CU_add_test(pSuite, "submit_window_update_local_window_size", - test_nghttp2_submit_window_update_local_window_size) || - !CU_add_test(pSuite, "submit_shutdown_notice", - test_nghttp2_submit_shutdown_notice) || - !CU_add_test(pSuite, "submit_invalid_nv", - test_nghttp2_submit_invalid_nv) || - !CU_add_test(pSuite, "submit_extension", test_nghttp2_submit_extension) || - !CU_add_test(pSuite, "submit_altsvc", test_nghttp2_submit_altsvc) || - !CU_add_test(pSuite, "submit_origin", test_nghttp2_submit_origin) || - !CU_add_test(pSuite, "submit_priority_update", - test_nghttp2_submit_priority_update) || - !CU_add_test(pSuite, "submit_rst_stream", - test_nghttp2_submit_rst_stream) || - !CU_add_test(pSuite, "session_open_stream", - test_nghttp2_session_open_stream) || - !CU_add_test(pSuite, "session_open_stream_with_idle_stream_dep", - test_nghttp2_session_open_stream_with_idle_stream_dep) || - !CU_add_test(pSuite, "session_get_next_ob_item", - test_nghttp2_session_get_next_ob_item) || - !CU_add_test(pSuite, "session_pop_next_ob_item", - test_nghttp2_session_pop_next_ob_item) || - !CU_add_test(pSuite, "session_reply_fail", - test_nghttp2_session_reply_fail) || - !CU_add_test(pSuite, "session_max_concurrent_streams", - test_nghttp2_session_max_concurrent_streams) || - !CU_add_test(pSuite, "session_stop_data_with_rst_stream", - test_nghttp2_session_stop_data_with_rst_stream) || - !CU_add_test(pSuite, "session_defer_data", - test_nghttp2_session_defer_data) || - !CU_add_test(pSuite, "session_flow_control", - test_nghttp2_session_flow_control) || - !CU_add_test(pSuite, "session_flow_control_data_recv", - test_nghttp2_session_flow_control_data_recv) || - !CU_add_test(pSuite, "session_flow_control_data_with_padding_recv", - test_nghttp2_session_flow_control_data_with_padding_recv) || - !CU_add_test(pSuite, "session_data_read_temporal_failure", - test_nghttp2_session_data_read_temporal_failure) || - !CU_add_test(pSuite, "session_on_stream_close", - test_nghttp2_session_on_stream_close) || - !CU_add_test(pSuite, "session_on_ctrl_not_send", - test_nghttp2_session_on_ctrl_not_send) || - !CU_add_test(pSuite, "session_get_outbound_queue_size", - test_nghttp2_session_get_outbound_queue_size) || - !CU_add_test(pSuite, "session_get_effective_local_window_size", - test_nghttp2_session_get_effective_local_window_size) || - !CU_add_test(pSuite, "session_set_option", - test_nghttp2_session_set_option) || - !CU_add_test(pSuite, "session_data_backoff_by_high_pri_frame", - test_nghttp2_session_data_backoff_by_high_pri_frame) || - !CU_add_test(pSuite, "session_pack_data_with_padding", - test_nghttp2_session_pack_data_with_padding) || - !CU_add_test(pSuite, "session_pack_headers_with_padding", - test_nghttp2_session_pack_headers_with_padding) || - !CU_add_test(pSuite, "pack_settings_payload", - test_nghttp2_pack_settings_payload) || - !CU_add_test(pSuite, "session_stream_dep_add", - test_nghttp2_session_stream_dep_add) || - !CU_add_test(pSuite, "session_stream_dep_remove", - test_nghttp2_session_stream_dep_remove) || - !CU_add_test(pSuite, "session_stream_dep_add_subtree", - test_nghttp2_session_stream_dep_add_subtree) || - !CU_add_test(pSuite, "session_stream_dep_remove_subtree", - test_nghttp2_session_stream_dep_remove_subtree) || - !CU_add_test( - pSuite, "session_stream_dep_all_your_stream_are_belong_to_us", - test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us) || - !CU_add_test(pSuite, "session_stream_attach_item", - test_nghttp2_session_stream_attach_item) || - !CU_add_test(pSuite, "session_stream_attach_item_subtree", - test_nghttp2_session_stream_attach_item_subtree) || - !CU_add_test(pSuite, "session_stream_get_state", - test_nghttp2_session_stream_get_state) || - !CU_add_test(pSuite, "session_stream_get_something", - test_nghttp2_session_stream_get_something) || - !CU_add_test(pSuite, "session_find_stream", - test_nghttp2_session_find_stream) || - !CU_add_test(pSuite, "session_keep_closed_stream", - test_nghttp2_session_keep_closed_stream) || - !CU_add_test(pSuite, "session_keep_idle_stream", - test_nghttp2_session_keep_idle_stream) || - !CU_add_test(pSuite, "session_detach_idle_stream", - test_nghttp2_session_detach_idle_stream) || - !CU_add_test(pSuite, "session_large_dep_tree", - test_nghttp2_session_large_dep_tree) || - !CU_add_test(pSuite, "session_graceful_shutdown", - test_nghttp2_session_graceful_shutdown) || - !CU_add_test(pSuite, "session_on_header_temporal_failure", - test_nghttp2_session_on_header_temporal_failure) || - !CU_add_test(pSuite, "session_recv_client_magic", - test_nghttp2_session_recv_client_magic) || - !CU_add_test(pSuite, "session_delete_data_item", - test_nghttp2_session_delete_data_item) || - !CU_add_test(pSuite, "session_open_idle_stream", - test_nghttp2_session_open_idle_stream) || - !CU_add_test(pSuite, "session_cancel_reserved_remote", - test_nghttp2_session_cancel_reserved_remote) || - !CU_add_test(pSuite, "session_reset_pending_headers", - test_nghttp2_session_reset_pending_headers) || - !CU_add_test(pSuite, "session_send_data_callback", - test_nghttp2_session_send_data_callback) || - !CU_add_test(pSuite, "session_on_begin_headers_temporal_failure", - test_nghttp2_session_on_begin_headers_temporal_failure) || - !CU_add_test(pSuite, "session_defer_then_close", - test_nghttp2_session_defer_then_close) || - !CU_add_test(pSuite, "session_detach_item_from_closed_stream", - test_nghttp2_session_detach_item_from_closed_stream) || - !CU_add_test(pSuite, "session_flooding", test_nghttp2_session_flooding) || - !CU_add_test(pSuite, "session_change_stream_priority", - test_nghttp2_session_change_stream_priority) || - !CU_add_test(pSuite, "session_change_extpri_stream_priority", - test_nghttp2_session_change_extpri_stream_priority) || - !CU_add_test(pSuite, "session_create_idle_stream", - test_nghttp2_session_create_idle_stream) || - !CU_add_test(pSuite, "session_repeated_priority_change", - test_nghttp2_session_repeated_priority_change) || - !CU_add_test(pSuite, "session_repeated_priority_submission", - test_nghttp2_session_repeated_priority_submission) || - !CU_add_test(pSuite, "session_set_local_window_size", - test_nghttp2_session_set_local_window_size) || - !CU_add_test(pSuite, "session_cancel_from_before_frame_send", - test_nghttp2_session_cancel_from_before_frame_send) || - !CU_add_test(pSuite, "session_too_many_settings", - test_nghttp2_session_too_many_settings) || - !CU_add_test(pSuite, "session_removed_closed_stream", - test_nghttp2_session_removed_closed_stream) || - !CU_add_test(pSuite, "session_pause_data", - test_nghttp2_session_pause_data) || - !CU_add_test(pSuite, "session_no_closed_streams", - test_nghttp2_session_no_closed_streams) || - !CU_add_test(pSuite, "session_set_stream_user_data", - test_nghttp2_session_set_stream_user_data) || - !CU_add_test(pSuite, "session_no_rfc7540_priorities", - test_nghttp2_session_no_rfc7540_priorities) || - !CU_add_test(pSuite, "session_server_fallback_rfc7540_priorities", - test_nghttp2_session_server_fallback_rfc7540_priorities) || - !CU_add_test(pSuite, "session_stream_reset_ratelim", - test_nghttp2_session_stream_reset_ratelim) || - !CU_add_test(pSuite, "http_mandatory_headers", - test_nghttp2_http_mandatory_headers) || - !CU_add_test(pSuite, "http_content_length", - test_nghttp2_http_content_length) || - !CU_add_test(pSuite, "http_content_length_mismatch", - test_nghttp2_http_content_length_mismatch) || - !CU_add_test(pSuite, "http_non_final_response", - test_nghttp2_http_non_final_response) || - !CU_add_test(pSuite, "http_trailer_headers", - test_nghttp2_http_trailer_headers) || - !CU_add_test(pSuite, "http_ignore_regular_header", - test_nghttp2_http_ignore_regular_header) || - !CU_add_test(pSuite, "http_ignore_content_length", - test_nghttp2_http_ignore_content_length) || - !CU_add_test(pSuite, "http_record_request_method", - test_nghttp2_http_record_request_method) || - !CU_add_test(pSuite, "http_push_promise", - test_nghttp2_http_push_promise) || - !CU_add_test(pSuite, "http_head_method_upgrade_workaround", - test_nghttp2_http_head_method_upgrade_workaround) || - !CU_add_test( - pSuite, "http_no_rfc9113_leading_and_trailing_ws_validation", - test_nghttp2_http_no_rfc9113_leading_and_trailing_ws_validation) || - !CU_add_test(pSuite, "frame_pack_headers", - test_nghttp2_frame_pack_headers) || - !CU_add_test(pSuite, "frame_pack_headers_frame_too_large", - test_nghttp2_frame_pack_headers_frame_too_large) || - !CU_add_test(pSuite, "frame_pack_priority", - test_nghttp2_frame_pack_priority) || - !CU_add_test(pSuite, "frame_pack_rst_stream", - test_nghttp2_frame_pack_rst_stream) || - !CU_add_test(pSuite, "frame_pack_settings", - test_nghttp2_frame_pack_settings) || - !CU_add_test(pSuite, "frame_pack_push_promise", - test_nghttp2_frame_pack_push_promise) || - !CU_add_test(pSuite, "frame_pack_ping", test_nghttp2_frame_pack_ping) || - !CU_add_test(pSuite, "frame_pack_goaway", - test_nghttp2_frame_pack_goaway) || - !CU_add_test(pSuite, "frame_pack_window_update", - test_nghttp2_frame_pack_window_update) || - !CU_add_test(pSuite, "frame_pack_altsvc", - test_nghttp2_frame_pack_altsvc) || - !CU_add_test(pSuite, "frame_pack_origin", - test_nghttp2_frame_pack_origin) || - !CU_add_test(pSuite, "frame_pack_priority_update", - test_nghttp2_frame_pack_priority_update) || - !CU_add_test(pSuite, "nv_array_copy", test_nghttp2_nv_array_copy) || - !CU_add_test(pSuite, "iv_check", test_nghttp2_iv_check) || - !CU_add_test(pSuite, "hd_deflate", test_nghttp2_hd_deflate) || - !CU_add_test(pSuite, "hd_deflate_same_indexed_repr", - test_nghttp2_hd_deflate_same_indexed_repr) || - !CU_add_test(pSuite, "hd_inflate_indexed", - test_nghttp2_hd_inflate_indexed) || - !CU_add_test(pSuite, "hd_inflate_indname_noinc", - test_nghttp2_hd_inflate_indname_noinc) || - !CU_add_test(pSuite, "hd_inflate_indname_inc", - test_nghttp2_hd_inflate_indname_inc) || - !CU_add_test(pSuite, "hd_inflate_indname_inc_eviction", - test_nghttp2_hd_inflate_indname_inc_eviction) || - !CU_add_test(pSuite, "hd_inflate_newname_noinc", - test_nghttp2_hd_inflate_newname_noinc) || - !CU_add_test(pSuite, "hd_inflate_newname_inc", - test_nghttp2_hd_inflate_newname_inc) || - !CU_add_test(pSuite, "hd_inflate_clearall_inc", - test_nghttp2_hd_inflate_clearall_inc) || - !CU_add_test(pSuite, "hd_inflate_zero_length_huffman", - test_nghttp2_hd_inflate_zero_length_huffman) || - !CU_add_test(pSuite, "hd_inflate_expect_table_size_update", - test_nghttp2_hd_inflate_expect_table_size_update) || - !CU_add_test(pSuite, "hd_inflate_unexpected_table_size_update", - test_nghttp2_hd_inflate_unexpected_table_size_update) || - !CU_add_test(pSuite, "hd_ringbuf_reserve", - test_nghttp2_hd_ringbuf_reserve) || - !CU_add_test(pSuite, "hd_change_table_size", - test_nghttp2_hd_change_table_size) || - !CU_add_test(pSuite, "hd_deflate_inflate", - test_nghttp2_hd_deflate_inflate) || - !CU_add_test(pSuite, "hd_no_index", test_nghttp2_hd_no_index) || - !CU_add_test(pSuite, "hd_deflate_bound", test_nghttp2_hd_deflate_bound) || - !CU_add_test(pSuite, "hd_public_api", test_nghttp2_hd_public_api) || - !CU_add_test(pSuite, "hd_deflate_hd_vec", - test_nghttp2_hd_deflate_hd_vec) || - !CU_add_test(pSuite, "hd_decode_length", test_nghttp2_hd_decode_length) || - !CU_add_test(pSuite, "hd_huff_encode", test_nghttp2_hd_huff_encode) || - !CU_add_test(pSuite, "hd_huff_decode", test_nghttp2_hd_huff_decode) || - !CU_add_test(pSuite, "adjust_local_window_size", - test_nghttp2_adjust_local_window_size) || - !CU_add_test(pSuite, "check_header_name", - test_nghttp2_check_header_name) || - !CU_add_test(pSuite, "check_header_value", - test_nghttp2_check_header_value) || - !CU_add_test(pSuite, "check_header_value_rfc9113", - test_nghttp2_check_header_value_rfc9113) || - !CU_add_test(pSuite, "bufs_add", test_nghttp2_bufs_add) || - !CU_add_test(pSuite, "bufs_add_stack_buffer_overflow_bug", - test_nghttp2_bufs_add_stack_buffer_overflow_bug) || - !CU_add_test(pSuite, "bufs_addb", test_nghttp2_bufs_addb) || - !CU_add_test(pSuite, "bufs_orb", test_nghttp2_bufs_orb) || - !CU_add_test(pSuite, "bufs_remove", test_nghttp2_bufs_remove) || - !CU_add_test(pSuite, "bufs_reset", test_nghttp2_bufs_reset) || - !CU_add_test(pSuite, "bufs_advance", test_nghttp2_bufs_advance) || - !CU_add_test(pSuite, "bufs_next_present", - test_nghttp2_bufs_next_present) || - !CU_add_test(pSuite, "bufs_realloc", test_nghttp2_bufs_realloc) || - !CU_add_test(pSuite, "http_parse_priority", - test_nghttp2_http_parse_priority) || - !CU_add_test(pSuite, "extpri_to_uint8", test_nghttp2_extpri_to_uint8) || - !CU_add_test(pSuite, "ratelim_update", test_nghttp2_ratelim_update) || - !CU_add_test(pSuite, "ratelim_drain", test_nghttp2_ratelim_drain)) { - CU_cleanup_registry(); - return (int)CU_get_error(); - } - - /* Run all tests using the CUnit Basic interface */ - CU_basic_set_mode(CU_BRM_VERBOSE); - CU_basic_run_tests(); - num_tests_failed = CU_get_number_of_tests_failed(); - CU_cleanup_registry(); - if (CU_get_error() == CUE_SUCCESS) { - return (int)num_tests_failed; - } else { - printf("CUnit Error: %s\n", CU_get_error_msg()); - return (int)CU_get_error(); - } + return munit_suite_main(&suite, NULL, argc, argv); } diff --git a/tests/nghttp2_alpn_test.c b/tests/nghttp2_alpn_test.c index d471d5f..805a23e 100644 --- a/tests/nghttp2_alpn_test.c +++ b/tests/nghttp2_alpn_test.c @@ -27,25 +27,36 @@ #include <stdio.h> #include <string.h> -#include <CUnit/CUnit.h> +#include "munit.h" + #include <nghttp2/nghttp2.h> +static const MunitTest tests[] = { + munit_void_test(test_nghttp2_alpn), + munit_test_end(), +}; + +const MunitSuite alpn_suite = { + "/alpn", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + static void http2(void) { const unsigned char p[] = {8, 'h', 't', 't', 'p', '/', '1', '.', '1', 2, 'h', '2', 6, 's', 'p', 'd', 'y', '/', '3'}; unsigned char outlen; const unsigned char *out; - CU_ASSERT(1 == nghttp2_select_next_protocol((unsigned char **)&out, &outlen, - p, sizeof(p))); - CU_ASSERT(NGHTTP2_PROTO_VERSION_ID_LEN == outlen); - CU_ASSERT(memcmp(NGHTTP2_PROTO_VERSION_ID, out, outlen) == 0); + assert_int(1, ==, + nghttp2_select_next_protocol((unsigned char **)&out, &outlen, p, + sizeof(p))); + assert_uchar(NGHTTP2_PROTO_VERSION_ID_LEN, ==, outlen); + assert_memory_equal(outlen, NGHTTP2_PROTO_VERSION_ID, out); outlen = 0; out = NULL; - CU_ASSERT(1 == nghttp2_select_alpn(&out, &outlen, p, sizeof(p))); - CU_ASSERT(NGHTTP2_PROTO_VERSION_ID_LEN == outlen); - CU_ASSERT(memcmp(NGHTTP2_PROTO_VERSION_ID, out, outlen) == 0); + assert_int(1, ==, nghttp2_select_alpn(&out, &outlen, p, sizeof(p))); + assert_uchar(NGHTTP2_PROTO_VERSION_ID_LEN, ==, outlen); + assert_memory_equal(outlen, NGHTTP2_PROTO_VERSION_ID, out); } static void http11(void) { @@ -55,17 +66,18 @@ static void http11(void) { }; unsigned char outlen; const unsigned char *out; - CU_ASSERT(0 == nghttp2_select_next_protocol((unsigned char **)&out, &outlen, - spdy, sizeof(spdy))); - CU_ASSERT(8 == outlen); - CU_ASSERT(memcmp("http/1.1", out, outlen) == 0); + assert_int(0, ==, + nghttp2_select_next_protocol((unsigned char **)&out, &outlen, spdy, + sizeof(spdy))); + assert_uchar(8, ==, outlen); + assert_memory_equal(outlen, "http/1.1", out); outlen = 0; out = NULL; - CU_ASSERT(0 == nghttp2_select_alpn(&out, &outlen, spdy, sizeof(spdy))); - CU_ASSERT(8 == outlen); - CU_ASSERT(memcmp("http/1.1", out, outlen) == 0); + assert_int(0, ==, nghttp2_select_alpn(&out, &outlen, spdy, sizeof(spdy))); + assert_uchar(8, ==, outlen); + assert_memory_equal(outlen, "http/1.1", out); } static void no_overlap(void) { @@ -75,17 +87,18 @@ static void no_overlap(void) { }; unsigned char outlen = 0; const unsigned char *out = NULL; - CU_ASSERT(-1 == nghttp2_select_next_protocol((unsigned char **)&out, &outlen, - spdy, sizeof(spdy))); - CU_ASSERT(0 == outlen); - CU_ASSERT(NULL == out); + assert_int(-1, ==, + nghttp2_select_next_protocol((unsigned char **)&out, &outlen, spdy, + sizeof(spdy))); + assert_uchar(0, ==, outlen); + assert_null(out); outlen = 0; out = NULL; - CU_ASSERT(-1 == nghttp2_select_alpn(&out, &outlen, spdy, sizeof(spdy))); - CU_ASSERT(0 == outlen); - CU_ASSERT(NULL == out); + assert_int(-1, ==, nghttp2_select_alpn(&out, &outlen, spdy, sizeof(spdy))); + assert_uchar(0, ==, outlen); + assert_null(out); } void test_nghttp2_alpn(void) { diff --git a/tests/nghttp2_alpn_test.h b/tests/nghttp2_alpn_test.h index f797f9e..a375701 100644 --- a/tests/nghttp2_alpn_test.h +++ b/tests/nghttp2_alpn_test.h @@ -29,6 +29,12 @@ # include <config.h> #endif /* HAVE_CONFIG_H */ -void test_nghttp2_alpn(void); +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + +extern const MunitSuite alpn_suite; + +munit_void_test_decl(test_nghttp2_alpn); #endif /* NGHTTP2_ALPN_TEST_H */ diff --git a/tests/nghttp2_assertion.h b/tests/nghttp2_assertion.h new file mode 100644 index 0000000..28d6929 --- /dev/null +++ b/tests/nghttp2_assertion.h @@ -0,0 +1,56 @@ +/* + * nghttp2 - HTTP/2 C Library + * + * Copyright (c) 2024 nghttp2 contributors + * + * 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 NGHTTP2_ASSERTION_H +#define NGHTTP2_ASSERTION_H + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif /* HAVE_CONFIG_H */ + +#include "munit.h" + +#include "nghttp2_frame.h" + +#define assert_nv_equal(A, B, len, mem) \ + do { \ + size_t alloclen = sizeof(nghttp2_nv) * (len); \ + const nghttp2_nv *sa = (A), *sb = (B); \ + nghttp2_nv *a = (mem)->malloc(alloclen, NULL); \ + nghttp2_nv *b = (mem)->malloc(alloclen, NULL); \ + size_t i_; \ + memcpy(a, sa, alloclen); \ + memcpy(b, sb, alloclen); \ + nghttp2_nv_array_sort(a, (len)); \ + nghttp2_nv_array_sort(b, (len)); \ + for (i_ = 0; i_ < (size_t)(len); ++i_) { \ + assert_memn_equal(a[i_].name, a[i_].namelen, b[i_].name, b[i_].namelen); \ + assert_memn_equal(a[i_].value, a[i_].valuelen, b[i_].value, \ + b[i_].valuelen); \ + } \ + (mem)->free(b, NULL); \ + (mem)->free(a, NULL); \ + } while (0); + +#endif /* NGHTTP2_ASSERTION_H */ diff --git a/tests/nghttp2_buf_test.c b/tests/nghttp2_buf_test.c index e3e8a14..43d53f6 100644 --- a/tests/nghttp2_buf_test.c +++ b/tests/nghttp2_buf_test.c @@ -26,11 +26,28 @@ #include <stdio.h> -#include <CUnit/CUnit.h> +#include "munit.h" #include "nghttp2_buf.h" #include "nghttp2_test_helper.h" +static const MunitTest tests[] = { + munit_void_test(test_nghttp2_bufs_add), + munit_void_test(test_nghttp2_bufs_add_stack_buffer_overflow_bug), + munit_void_test(test_nghttp2_bufs_addb), + munit_void_test(test_nghttp2_bufs_orb), + munit_void_test(test_nghttp2_bufs_remove), + munit_void_test(test_nghttp2_bufs_reset), + munit_void_test(test_nghttp2_bufs_advance), + munit_void_test(test_nghttp2_bufs_next_present), + munit_void_test(test_nghttp2_bufs_realloc), + munit_test_end(), +}; + +const MunitSuite buf_suite = { + "/buf", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_nghttp2_bufs_add(void) { int rv; nghttp2_bufs bufs; @@ -40,27 +57,27 @@ void test_nghttp2_bufs_add(void) { mem = nghttp2_mem_default(); rv = nghttp2_bufs_init(&bufs, 1000, 3, mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); - CU_ASSERT(bufs.cur->buf.pos == bufs.cur->buf.last); + assert_ptr_equal(bufs.cur->buf.pos, bufs.cur->buf.last); rv = nghttp2_bufs_add(&bufs, data, 493); - CU_ASSERT(0 == rv); - CU_ASSERT(493 == nghttp2_buf_len(&bufs.cur->buf)); - CU_ASSERT(493 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(507 == nghttp2_bufs_cur_avail(&bufs)); + assert_int(0, ==, rv); + assert_size(493, ==, nghttp2_buf_len(&bufs.cur->buf)); + assert_size(493, ==, nghttp2_bufs_len(&bufs)); + assert_size(507, ==, nghttp2_bufs_cur_avail(&bufs)); rv = nghttp2_bufs_add(&bufs, data, 507); - CU_ASSERT(0 == rv); - CU_ASSERT(1000 == nghttp2_buf_len(&bufs.cur->buf)); - CU_ASSERT(1000 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(bufs.cur == bufs.head); + assert_int(0, ==, rv); + assert_size(1000, ==, nghttp2_buf_len(&bufs.cur->buf)); + assert_size(1000, ==, nghttp2_bufs_len(&bufs)); + assert_ptr_equal(bufs.cur, bufs.head); rv = nghttp2_bufs_add(&bufs, data, 1); - CU_ASSERT(0 == rv); - CU_ASSERT(1 == nghttp2_buf_len(&bufs.cur->buf)); - CU_ASSERT(1001 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(bufs.cur == bufs.head->next); + assert_int(0, ==, rv); + assert_size(1, ==, nghttp2_buf_len(&bufs.cur->buf)); + assert_size(1001, ==, nghttp2_bufs_len(&bufs)); + assert_ptr_equal(bufs.cur, bufs.head->next); nghttp2_bufs_free(&bufs); } @@ -75,12 +92,12 @@ void test_nghttp2_bufs_add_stack_buffer_overflow_bug(void) { mem = nghttp2_mem_default(); rv = nghttp2_bufs_init(&bufs, 100, 200, mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); rv = nghttp2_bufs_add(&bufs, data, sizeof(data)); - CU_ASSERT(0 == rv); - CU_ASSERT(sizeof(data) == nghttp2_bufs_len(&bufs)); + assert_int(0, ==, rv); + assert_size(sizeof(data), ==, nghttp2_bufs_len(&bufs)); nghttp2_bufs_free(&bufs); } @@ -88,65 +105,65 @@ void test_nghttp2_bufs_add_stack_buffer_overflow_bug(void) { void test_nghttp2_bufs_addb(void) { int rv; nghttp2_bufs bufs; - ssize_t i; + size_t i; nghttp2_mem *mem; mem = nghttp2_mem_default(); rv = nghttp2_bufs_init(&bufs, 1000, 3, mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); rv = nghttp2_bufs_addb(&bufs, 14); - CU_ASSERT(0 == rv); - CU_ASSERT(1 == nghttp2_buf_len(&bufs.cur->buf)); - CU_ASSERT(1 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(14 == *bufs.cur->buf.pos); + assert_int(0, ==, rv); + assert_size(1, ==, nghttp2_buf_len(&bufs.cur->buf)); + assert_size(1, ==, nghttp2_bufs_len(&bufs)); + assert_uint8(14, ==, *bufs.cur->buf.pos); for (i = 0; i < 999; ++i) { rv = nghttp2_bufs_addb(&bufs, 254); - CU_ASSERT(0 == rv); - CU_ASSERT((size_t)(i + 2) == nghttp2_buf_len(&bufs.cur->buf)); - CU_ASSERT((size_t)(i + 2) == nghttp2_bufs_len(&bufs)); - CU_ASSERT(254 == *(bufs.cur->buf.last - 1)); - CU_ASSERT(bufs.cur == bufs.head); + assert_int(0, ==, rv); + assert_size(i + 2, ==, nghttp2_buf_len(&bufs.cur->buf)); + assert_size(i + 2, ==, nghttp2_bufs_len(&bufs)); + assert_uint8(254, ==, *(bufs.cur->buf.last - 1)); + assert_ptr_equal(bufs.cur, bufs.head); } rv = nghttp2_bufs_addb(&bufs, 253); - CU_ASSERT(0 == rv); - CU_ASSERT(1 == nghttp2_buf_len(&bufs.cur->buf)); - CU_ASSERT(1001 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(253 == *(bufs.cur->buf.last - 1)); - CU_ASSERT(bufs.cur == bufs.head->next); + assert_int(0, ==, rv); + assert_size(1, ==, nghttp2_buf_len(&bufs.cur->buf)); + assert_size(1001, ==, nghttp2_bufs_len(&bufs)); + assert_uint8(253, ==, *(bufs.cur->buf.last - 1)); + assert_ptr_equal(bufs.cur, bufs.head->next); rv = nghttp2_bufs_addb_hold(&bufs, 15); - CU_ASSERT(0 == rv); - CU_ASSERT(1 == nghttp2_buf_len(&bufs.cur->buf)); - CU_ASSERT(1001 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(15 == *(bufs.cur->buf.last)); + assert_int(0, ==, rv); + assert_size(1, ==, nghttp2_buf_len(&bufs.cur->buf)); + assert_size(1001, ==, nghttp2_bufs_len(&bufs)); + assert_uint8(15, ==, *(bufs.cur->buf.last)); /* test fast version */ nghttp2_bufs_fast_addb(&bufs, 240); - CU_ASSERT(2 == nghttp2_buf_len(&bufs.cur->buf)); - CU_ASSERT(1002 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(240 == *(bufs.cur->buf.last - 1)); + assert_size(2, ==, nghttp2_buf_len(&bufs.cur->buf)); + assert_size(1002, ==, nghttp2_bufs_len(&bufs)); + assert_uint8(240, ==, *(bufs.cur->buf.last - 1)); nghttp2_bufs_fast_addb_hold(&bufs, 113); - CU_ASSERT(2 == nghttp2_buf_len(&bufs.cur->buf)); - CU_ASSERT(1002 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(113 == *(bufs.cur->buf.last)); + assert_size(2, ==, nghttp2_buf_len(&bufs.cur->buf)); + assert_size(1002, ==, nghttp2_bufs_len(&bufs)); + assert_uint8(113, ==, *(bufs.cur->buf.last)); /* addb_hold when last == end */ bufs.cur->buf.last = bufs.cur->buf.end; rv = nghttp2_bufs_addb_hold(&bufs, 19); - CU_ASSERT(0 == rv); - CU_ASSERT(0 == nghttp2_buf_len(&bufs.cur->buf)); - CU_ASSERT(2000 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(19 == *(bufs.cur->buf.last)); + assert_int(0, ==, rv); + assert_size(0, ==, nghttp2_buf_len(&bufs.cur->buf)); + assert_size(2000, ==, nghttp2_bufs_len(&bufs)); + assert_uint8(19, ==, *(bufs.cur->buf.last)); nghttp2_bufs_free(&bufs); } @@ -159,28 +176,28 @@ void test_nghttp2_bufs_orb(void) { mem = nghttp2_mem_default(); rv = nghttp2_bufs_init(&bufs, 1000, 3, mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); *(bufs.cur->buf.last) = 0; rv = nghttp2_bufs_orb_hold(&bufs, 15); - CU_ASSERT(0 == rv); - CU_ASSERT(0 == nghttp2_buf_len(&bufs.cur->buf)); - CU_ASSERT(0 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(15 == *(bufs.cur->buf.last)); + assert_int(0, ==, rv); + assert_size(0, ==, nghttp2_buf_len(&bufs.cur->buf)); + assert_size(0, ==, nghttp2_bufs_len(&bufs)); + assert_uint8(15, ==, *(bufs.cur->buf.last)); rv = nghttp2_bufs_orb(&bufs, 240); - CU_ASSERT(0 == rv); - CU_ASSERT(1 == nghttp2_buf_len(&bufs.cur->buf)); - CU_ASSERT(1 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(255 == *(bufs.cur->buf.last - 1)); + assert_int(0, ==, rv); + assert_size(1, ==, nghttp2_buf_len(&bufs.cur->buf)); + assert_size(1, ==, nghttp2_bufs_len(&bufs)); + assert_uint8(255, ==, *(bufs.cur->buf.last - 1)); *(bufs.cur->buf.last) = 0; nghttp2_bufs_fast_orb_hold(&bufs, 240); - CU_ASSERT(240 == *(bufs.cur->buf.last)); + assert_uint8(240, ==, *(bufs.cur->buf.last)); nghttp2_bufs_fast_orb(&bufs, 15); - CU_ASSERT(255 == *(bufs.cur->buf.last - 1)); + assert_uint8(255, ==, *(bufs.cur->buf.last - 1)); nghttp2_bufs_free(&bufs); } @@ -191,36 +208,36 @@ void test_nghttp2_bufs_remove(void) { nghttp2_buf_chain *chain; int i; uint8_t *out; - ssize_t outlen; + nghttp2_ssize outlen; nghttp2_mem *mem; mem = nghttp2_mem_default(); rv = nghttp2_bufs_init(&bufs, 1000, 3, mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); nghttp2_buf_shift_right(&bufs.cur->buf, 10); rv = nghttp2_bufs_add(&bufs, "hello ", 6); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); for (i = 0; i < 2; ++i) { chain = bufs.cur; rv = nghttp2_bufs_advance(&bufs); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); - CU_ASSERT(chain->next == bufs.cur); + assert_ptr_equal(chain->next, bufs.cur); } rv = nghttp2_bufs_add(&bufs, "world", 5); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); outlen = nghttp2_bufs_remove(&bufs, &out); - CU_ASSERT(11 == outlen); + assert_ptrdiff(11, ==, outlen); - CU_ASSERT(0 == memcmp("hello world", out, (size_t)outlen)); - CU_ASSERT(11 == nghttp2_bufs_len(&bufs)); + assert_memory_equal((size_t)outlen, "hello world", out); + assert_size(11, ==, nghttp2_bufs_len(&bufs)); mem->free(out, NULL); nghttp2_bufs_free(&bufs); @@ -236,30 +253,30 @@ void test_nghttp2_bufs_reset(void) { mem = nghttp2_mem_default(); rv = nghttp2_bufs_init3(&bufs, 250, 3, 1, offset, mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); rv = nghttp2_bufs_add(&bufs, "foo", 3); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); rv = nghttp2_bufs_advance(&bufs); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); rv = nghttp2_bufs_add(&bufs, "bar", 3); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); - CU_ASSERT(6 == nghttp2_bufs_len(&bufs)); + assert_size(6, ==, nghttp2_bufs_len(&bufs)); nghttp2_bufs_reset(&bufs); - CU_ASSERT(0 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(bufs.cur == bufs.head); + assert_size(0, ==, nghttp2_bufs_len(&bufs)); + assert_ptr_equal(bufs.cur, bufs.head); for (ci = bufs.head; ci; ci = ci->next) { - CU_ASSERT((ssize_t)offset == ci->buf.pos - ci->buf.begin); - CU_ASSERT(ci->buf.pos == ci->buf.last); + assert_ptrdiff((ptrdiff_t)offset, ==, ci->buf.pos - ci->buf.begin); + assert_ptr_equal(ci->buf.pos, ci->buf.last); } - CU_ASSERT(bufs.head->next == NULL); + assert_null(bufs.head->next); nghttp2_bufs_free(&bufs); } @@ -273,15 +290,15 @@ void test_nghttp2_bufs_advance(void) { mem = nghttp2_mem_default(); rv = nghttp2_bufs_init(&bufs, 250, 3, mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); for (i = 0; i < 2; ++i) { rv = nghttp2_bufs_advance(&bufs); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); } rv = nghttp2_bufs_advance(&bufs); - CU_ASSERT(NGHTTP2_ERR_BUFFER_ERROR == rv); + assert_int(NGHTTP2_ERR_BUFFER_ERROR, ==, rv); nghttp2_bufs_free(&bufs); } @@ -294,25 +311,25 @@ void test_nghttp2_bufs_next_present(void) { mem = nghttp2_mem_default(); rv = nghttp2_bufs_init(&bufs, 250, 3, mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); - CU_ASSERT(0 == nghttp2_bufs_next_present(&bufs)); + assert_false(nghttp2_bufs_next_present(&bufs)); rv = nghttp2_bufs_advance(&bufs); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); nghttp2_bufs_rewind(&bufs); - CU_ASSERT(0 == nghttp2_bufs_next_present(&bufs)); + assert_false(nghttp2_bufs_next_present(&bufs)); bufs.cur = bufs.head->next; rv = nghttp2_bufs_addb(&bufs, 1); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); nghttp2_bufs_rewind(&bufs); - CU_ASSERT(0 != nghttp2_bufs_next_present(&bufs)); + assert_true(nghttp2_bufs_next_present(&bufs)); nghttp2_bufs_free(&bufs); } @@ -325,20 +342,20 @@ void test_nghttp2_bufs_realloc(void) { mem = nghttp2_mem_default(); rv = nghttp2_bufs_init3(&bufs, 266, 3, 1, 10, mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); /* Create new buffer to see that these buffers are deallocated on realloc */ rv = nghttp2_bufs_advance(&bufs); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); rv = nghttp2_bufs_realloc(&bufs, 522); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); - CU_ASSERT(512 == nghttp2_bufs_cur_avail(&bufs)); + assert_size(512, ==, nghttp2_bufs_cur_avail(&bufs)); rv = nghttp2_bufs_realloc(&bufs, 9); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); nghttp2_bufs_free(&bufs); } diff --git a/tests/nghttp2_buf_test.h b/tests/nghttp2_buf_test.h index 714b89f..0bbab89 100644 --- a/tests/nghttp2_buf_test.h +++ b/tests/nghttp2_buf_test.h @@ -29,14 +29,20 @@ # include <config.h> #endif /* HAVE_CONFIG_H */ -void test_nghttp2_bufs_add(void); -void test_nghttp2_bufs_add_stack_buffer_overflow_bug(void); -void test_nghttp2_bufs_addb(void); -void test_nghttp2_bufs_orb(void); -void test_nghttp2_bufs_remove(void); -void test_nghttp2_bufs_reset(void); -void test_nghttp2_bufs_advance(void); -void test_nghttp2_bufs_next_present(void); -void test_nghttp2_bufs_realloc(void); +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + +extern const MunitSuite buf_suite; + +munit_void_test_decl(test_nghttp2_bufs_add); +munit_void_test_decl(test_nghttp2_bufs_add_stack_buffer_overflow_bug); +munit_void_test_decl(test_nghttp2_bufs_addb); +munit_void_test_decl(test_nghttp2_bufs_orb); +munit_void_test_decl(test_nghttp2_bufs_remove); +munit_void_test_decl(test_nghttp2_bufs_reset); +munit_void_test_decl(test_nghttp2_bufs_advance); +munit_void_test_decl(test_nghttp2_bufs_next_present); +munit_void_test_decl(test_nghttp2_bufs_realloc); #endif /* NGHTTP2_BUF_TEST_H */ diff --git a/tests/nghttp2_extpri_test.c b/tests/nghttp2_extpri_test.c index 0ef59b7..a589b93 100644 --- a/tests/nghttp2_extpri_test.c +++ b/tests/nghttp2_extpri_test.c @@ -27,26 +27,35 @@ #include <stdio.h> -#include <CUnit/CUnit.h> +#include "munit.h" #include "nghttp2_extpri.h" #include "nghttp2_test_helper.h" +static const MunitTest tests[] = { + munit_void_test(test_nghttp2_extpri_to_uint8), + munit_test_end(), +}; + +const MunitSuite extpri_suite = { + "/extpri", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_nghttp2_extpri_to_uint8(void) { { nghttp2_extpri pri = {1, 0}; - CU_ASSERT(1 == nghttp2_extpri_to_uint8(&pri)); + assert_uint8(1, ==, nghttp2_extpri_to_uint8(&pri)); } { nghttp2_extpri pri = {1, 1}; - CU_ASSERT((0x80 | 1) == nghttp2_extpri_to_uint8(&pri)); + assert_uint8((0x80 | 1), ==, nghttp2_extpri_to_uint8(&pri)); } { nghttp2_extpri pri = {7, 1}; - CU_ASSERT((0x80 | 7) == nghttp2_extpri_to_uint8(&pri)); + assert_uint8((0x80 | 7), ==, nghttp2_extpri_to_uint8(&pri)); } { nghttp2_extpri pri = {7, 0}; - CU_ASSERT(7 == nghttp2_extpri_to_uint8(&pri)); + assert_uint8(7, ==, nghttp2_extpri_to_uint8(&pri)); } } diff --git a/tests/nghttp2_extpri_test.h b/tests/nghttp2_extpri_test.h index a8a93b9..8735882 100644 --- a/tests/nghttp2_extpri_test.h +++ b/tests/nghttp2_extpri_test.h @@ -30,6 +30,12 @@ # include <config.h> #endif /* HAVE_CONFIG_H */ -void test_nghttp2_extpri_to_uint8(void); +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + +extern const MunitSuite extpri_suite; + +munit_void_test_decl(test_nghttp2_extpri_to_uint8); #endif /* NGHTTP2_EXTPRI_TEST_H */ diff --git a/tests/nghttp2_frame_test.c b/tests/nghttp2_frame_test.c index 7ce98dd..474f154 100644 --- a/tests/nghttp2_frame_test.c +++ b/tests/nghttp2_frame_test.c @@ -27,13 +27,35 @@ #include <assert.h> #include <stdio.h> -#include <CUnit/CUnit.h> +#include "munit.h" #include "nghttp2_frame.h" #include "nghttp2_helper.h" #include "nghttp2_test_helper.h" #include "nghttp2_priority_spec.h" +static MunitTest tests[] = { + munit_void_test(test_nghttp2_frame_pack_headers), + munit_void_test(test_nghttp2_frame_pack_headers_frame_too_large), + munit_void_test(test_nghttp2_frame_pack_priority), + munit_void_test(test_nghttp2_frame_pack_rst_stream), + munit_void_test(test_nghttp2_frame_pack_settings), + munit_void_test(test_nghttp2_frame_pack_push_promise), + munit_void_test(test_nghttp2_frame_pack_ping), + munit_void_test(test_nghttp2_frame_pack_goaway), + munit_void_test(test_nghttp2_frame_pack_window_update), + munit_void_test(test_nghttp2_frame_pack_altsvc), + munit_void_test(test_nghttp2_frame_pack_origin), + munit_void_test(test_nghttp2_frame_pack_priority_update), + munit_void_test(test_nghttp2_nv_array_copy), + munit_void_test(test_nghttp2_iv_check), + munit_test_end(), +}; + +const MunitSuite frame_suite = { + "/frame", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + static nghttp2_nv make_nv(const char *name, const char *value) { nghttp2_nv nv; nv.name = (uint8_t *)name; @@ -61,11 +83,11 @@ static nghttp2_nv *headers(nghttp2_mem *mem) { static void check_frame_header(size_t length, uint8_t type, uint8_t flags, int32_t stream_id, nghttp2_frame_hd *hd) { - CU_ASSERT(length == hd->length); - CU_ASSERT(type == hd->type); - CU_ASSERT(flags == hd->flags); - CU_ASSERT(stream_id == hd->stream_id); - CU_ASSERT(0 == hd->reserved); + assert_size(length, ==, hd->length); + assert_uint8(type, ==, hd->type); + assert_uint8(flags, ==, hd->flags); + assert_int32(stream_id, ==, hd->stream_id); + assert_uint8(0, ==, hd->reserved); } void test_nghttp2_frame_pack_headers(void) { @@ -100,24 +122,24 @@ void test_nghttp2_frame_pack_headers(void) { nghttp2_bufs_rewind(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); - CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); + assert_int(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); + assert_int(0, ==, unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); check_frame_header(nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN, NGHTTP2_HEADERS, NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS, 1000000007, &oframe.hd); /* We did not include PRIORITY flag */ - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == oframe.pri_spec.weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, oframe.pri_spec.weight); hdblocklen = nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN; - CU_ASSERT((ssize_t)hdblocklen == - inflate_hd(&inflater, &out, &bufs, NGHTTP2_FRAME_HDLEN, mem)); + assert_ptrdiff((nghttp2_ssize)hdblocklen, ==, + inflate_hd(&inflater, &out, &bufs, NGHTTP2_FRAME_HDLEN, mem)); - CU_ASSERT(7 == out.nvlen); - CU_ASSERT(nvnameeq("method", &out.nva[0])); - CU_ASSERT(nvvalueeq("GET", &out.nva[0])); + assert_size(7, ==, out.nvlen); + assert_true(nvnameeq("method", &out.nva[0])); + assert_true(nvvalueeq("GET", &out.nva[0])); nghttp2_frame_headers_free(&oframe, mem); nva_out_reset(&out, mem); @@ -130,9 +152,9 @@ void test_nghttp2_frame_pack_headers(void) { rv = nghttp2_frame_pack_headers(&bufs, &frame, &deflater); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); - CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); + assert_int(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); + assert_int(0, ==, unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); check_frame_header(nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN, NGHTTP2_HEADERS, @@ -140,20 +162,20 @@ void test_nghttp2_frame_pack_headers(void) { NGHTTP2_FLAG_PRIORITY, 1000000007, &oframe.hd); - CU_ASSERT(1000000009 == oframe.pri_spec.stream_id); - CU_ASSERT(12 == oframe.pri_spec.weight); - CU_ASSERT(1 == oframe.pri_spec.exclusive); + assert_int32(1000000009, ==, oframe.pri_spec.stream_id); + assert_int32(12, ==, oframe.pri_spec.weight); + assert_true(oframe.pri_spec.exclusive); hdblocklen = nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN - nghttp2_frame_priority_len(oframe.hd.flags); - CU_ASSERT((ssize_t)hdblocklen == - inflate_hd(&inflater, &out, &bufs, - NGHTTP2_FRAME_HDLEN + - nghttp2_frame_priority_len(oframe.hd.flags), - mem)); + assert_ptrdiff((nghttp2_ssize)hdblocklen, ==, + inflate_hd(&inflater, &out, &bufs, + NGHTTP2_FRAME_HDLEN + + nghttp2_frame_priority_len(oframe.hd.flags), + mem)); nghttp2_nv_array_sort(out.nva, out.nvlen); - CU_ASSERT(nvnameeq("method", &out.nva[0])); + assert_true(nvnameeq("method", &out.nva[0])); nghttp2_frame_headers_free(&oframe, mem); nva_out_reset(&out, mem); @@ -196,7 +218,7 @@ void test_nghttp2_frame_pack_headers_frame_too_large(void) { &frame, NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS, 1000000007, NGHTTP2_HCAT_REQUEST, NULL, nva, big_hdslen); rv = nghttp2_frame_pack_headers(&bufs, &frame, &deflater); - CU_ASSERT(NGHTTP2_ERR_HEADER_COMP == rv); + assert_int(NGHTTP2_ERR_HEADER_COMP, ==, rv); nghttp2_frame_headers_free(&frame, mem); nghttp2_bufs_free(&bufs); @@ -219,14 +241,14 @@ void test_nghttp2_frame_pack_priority(void) { nghttp2_frame_priority_init(&frame, 1000000007, &pri_spec); nghttp2_frame_pack_priority(&bufs, &frame); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 5 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); + assert_size(NGHTTP2_FRAME_HDLEN + 5, ==, nghttp2_bufs_len(&bufs)); + assert_int(0, ==, unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); check_frame_header(5, NGHTTP2_PRIORITY, NGHTTP2_FLAG_NONE, 1000000007, &oframe.hd); - CU_ASSERT(1000000009 == oframe.pri_spec.stream_id); - CU_ASSERT(12 == oframe.pri_spec.weight); - CU_ASSERT(1 == oframe.pri_spec.exclusive); + assert_int32(1000000009, ==, oframe.pri_spec.stream_id); + assert_int32(12, ==, oframe.pri_spec.weight); + assert_true(oframe.pri_spec.exclusive); nghttp2_frame_priority_free(&oframe); nghttp2_bufs_reset(&bufs); @@ -244,11 +266,11 @@ void test_nghttp2_frame_pack_rst_stream(void) { nghttp2_frame_rst_stream_init(&frame, 1000000007, NGHTTP2_PROTOCOL_ERROR); nghttp2_frame_pack_rst_stream(&bufs, &frame); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 4 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); + assert_size(NGHTTP2_FRAME_HDLEN + 4, ==, nghttp2_bufs_len(&bufs)); + assert_int(0, ==, unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); check_frame_header(4, NGHTTP2_RST_STREAM, NGHTTP2_FLAG_NONE, 1000000007, &oframe.hd); - CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == oframe.error_code); + assert_uint32(NGHTTP2_PROTOCOL_ERROR, ==, oframe.error_code); nghttp2_frame_rst_stream_free(&oframe); nghttp2_bufs_reset(&bufs); @@ -257,12 +279,12 @@ void test_nghttp2_frame_pack_rst_stream(void) { frame.error_code = 1000000009; nghttp2_frame_pack_rst_stream(&bufs, &frame); - CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); + assert_int(0, ==, unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); check_frame_header(4, NGHTTP2_RST_STREAM, NGHTTP2_FLAG_NONE, 1000000007, &oframe.hd); - CU_ASSERT(1000000009 == oframe.error_code); + assert_uint32(1000000009, ==, oframe.error_code); nghttp2_frame_rst_stream_free(&oframe); @@ -288,17 +310,17 @@ void test_nghttp2_frame_pack_settings(void) { nghttp2_frame_iv_copy(iv, 3, mem), 3); rv = nghttp2_frame_pack_settings(&bufs, &frame); - CU_ASSERT(0 == rv); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 3 * NGHTTP2_FRAME_SETTINGS_ENTRY_LENGTH == - nghttp2_bufs_len(&bufs)); + assert_int(0, ==, rv); + assert_size(NGHTTP2_FRAME_HDLEN + 3 * NGHTTP2_FRAME_SETTINGS_ENTRY_LENGTH, ==, + nghttp2_bufs_len(&bufs)); - CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); + assert_int(0, ==, unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); check_frame_header(3 * NGHTTP2_FRAME_SETTINGS_ENTRY_LENGTH, NGHTTP2_SETTINGS, NGHTTP2_FLAG_NONE, 0, &oframe.hd); - CU_ASSERT(3 == oframe.niv); + assert_size(3, ==, oframe.niv); for (i = 0; i < 3; ++i) { - CU_ASSERT(iv[i].settings_id == oframe.iv[i].settings_id); - CU_ASSERT(iv[i].value == oframe.iv[i].value); + assert_int32(iv[i].settings_id, ==, oframe.iv[i].settings_id); + assert_uint32(iv[i].value, ==, oframe.iv[i].value); } nghttp2_bufs_free(&bufs); @@ -331,22 +353,23 @@ void test_nghttp2_frame_pack_push_promise(void) { (1U << 31) - 1, nva, nvlen); rv = nghttp2_frame_pack_push_promise(&bufs, &frame, &deflater); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); - CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); + assert_int(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); + assert_int(0, ==, unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); check_frame_header(nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN, NGHTTP2_PUSH_PROMISE, NGHTTP2_FLAG_END_HEADERS, 1000000007, &oframe.hd); - CU_ASSERT((1U << 31) - 1 == oframe.promised_stream_id); + assert_int32((1U << 31) - 1, ==, oframe.promised_stream_id); hdblocklen = nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN - 4; - CU_ASSERT((ssize_t)hdblocklen == - inflate_hd(&inflater, &out, &bufs, NGHTTP2_FRAME_HDLEN + 4, mem)); + assert_ptrdiff( + (nghttp2_ssize)hdblocklen, ==, + inflate_hd(&inflater, &out, &bufs, NGHTTP2_FRAME_HDLEN + 4, mem)); - CU_ASSERT(7 == out.nvlen); - CU_ASSERT(nvnameeq("method", &out.nva[0])); - CU_ASSERT(nvvalueeq("GET", &out.nva[0])); + assert_size(7, ==, out.nvlen); + assert_true(nvnameeq("method", &out.nva[0])); + assert_true(nvvalueeq("GET", &out.nva[0])); nva_out_reset(&out, mem); nghttp2_bufs_free(&bufs); @@ -366,11 +389,10 @@ void test_nghttp2_frame_pack_ping(void) { nghttp2_frame_ping_init(&frame, NGHTTP2_FLAG_ACK, opaque_data); nghttp2_frame_pack_ping(&bufs, &frame); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 8 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); + assert_size(NGHTTP2_FRAME_HDLEN + 8, ==, nghttp2_bufs_len(&bufs)); + assert_int(0, ==, unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); check_frame_header(8, NGHTTP2_PING, NGHTTP2_FLAG_ACK, 0, &oframe.hd); - CU_ASSERT(memcmp(opaque_data, oframe.opaque_data, sizeof(opaque_data) - 1) == - 0); + assert_memory_equal(sizeof(opaque_data) - 1, opaque_data, oframe.opaque_data); nghttp2_bufs_free(&bufs); nghttp2_frame_ping_free(&oframe); @@ -394,16 +416,16 @@ void test_nghttp2_frame_pack_goaway(void) { opaque_data, opaque_data_len); rv = nghttp2_frame_pack_goaway(&bufs, &frame); - CU_ASSERT(0 == rv); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 8 + opaque_data_len == - nghttp2_bufs_len(&bufs)); - CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); + assert_int(0, ==, rv); + assert_size(NGHTTP2_FRAME_HDLEN + 8 + opaque_data_len, ==, + nghttp2_bufs_len(&bufs)); + assert_int(0, ==, unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); check_frame_header(24, NGHTTP2_GOAWAY, NGHTTP2_FLAG_NONE, 0, &oframe.hd); - CU_ASSERT(1000000007 == oframe.last_stream_id); - CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == oframe.error_code); + assert_int32(1000000007, ==, oframe.last_stream_id); + assert_uint32(NGHTTP2_PROTOCOL_ERROR, ==, oframe.error_code); - CU_ASSERT(opaque_data_len == oframe.opaque_data_len); - CU_ASSERT(memcmp(opaque_data, oframe.opaque_data, opaque_data_len) == 0); + assert_size(opaque_data_len, ==, oframe.opaque_data_len); + assert_memory_equal(opaque_data_len, opaque_data, oframe.opaque_data); nghttp2_frame_goaway_free(&oframe, mem); nghttp2_bufs_reset(&bufs); @@ -413,10 +435,10 @@ void test_nghttp2_frame_pack_goaway(void) { rv = nghttp2_frame_pack_goaway(&bufs, &frame); - CU_ASSERT(0 == rv); - CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); + assert_int(0, ==, rv); + assert_int(0, ==, unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); check_frame_header(24, NGHTTP2_GOAWAY, NGHTTP2_FLAG_NONE, 0, &oframe.hd); - CU_ASSERT(1000000009 == oframe.error_code); + assert_uint32(1000000009, ==, oframe.error_code); nghttp2_frame_goaway_free(&oframe, mem); @@ -434,11 +456,11 @@ void test_nghttp2_frame_pack_window_update(void) { nghttp2_frame_window_update_init(&frame, NGHTTP2_FLAG_NONE, 1000000007, 4096); nghttp2_frame_pack_window_update(&bufs, &frame); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 4 == nghttp2_bufs_len(&bufs)); - CU_ASSERT(0 == unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); + assert_size(NGHTTP2_FRAME_HDLEN + 4, ==, nghttp2_bufs_len(&bufs)); + assert_int(0, ==, unpack_framebuf((nghttp2_frame *)&oframe, &bufs)); check_frame_header(4, NGHTTP2_WINDOW_UPDATE, NGHTTP2_FLAG_NONE, 1000000007, &oframe.hd); - CU_ASSERT(4096 == oframe.window_size_increment); + assert_int32(4096, ==, oframe.window_size_increment); nghttp2_bufs_free(&bufs); nghttp2_frame_window_update_free(&oframe); @@ -478,20 +500,20 @@ void test_nghttp2_frame_pack_altsvc(void) { nghttp2_frame_pack_altsvc(&bufs, &frame); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + payloadlen == nghttp2_bufs_len(&bufs)); + assert_size(NGHTTP2_FRAME_HDLEN + payloadlen, ==, nghttp2_bufs_len(&bufs)); rv = unpack_framebuf((nghttp2_frame *)&oframe, &bufs); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); check_frame_header(payloadlen, NGHTTP2_ALTSVC, NGHTTP2_FLAG_NONE, 1000000007, &oframe.hd); - CU_ASSERT(sizeof(origin) - 1 == oaltsvc.origin_len); - CU_ASSERT(0 == memcmp(origin, oaltsvc.origin, sizeof(origin) - 1)); - CU_ASSERT(sizeof(field_value) - 1 == oaltsvc.field_value_len); - CU_ASSERT(0 == - memcmp(field_value, oaltsvc.field_value, sizeof(field_value) - 1)); + assert_size(sizeof(origin) - 1, ==, oaltsvc.origin_len); + assert_memory_equal(sizeof(origin) - 1, origin, oaltsvc.origin); + assert_size(sizeof(field_value) - 1, ==, oaltsvc.field_value_len); + assert_memory_equal(sizeof(field_value) - 1, field_value, + oaltsvc.field_value); nghttp2_frame_altsvc_free(&oframe, mem); nghttp2_frame_altsvc_free(&frame, mem); @@ -536,21 +558,21 @@ void test_nghttp2_frame_pack_origin(void) { rv = nghttp2_frame_pack_origin(&bufs, &frame); - CU_ASSERT(0 == rv); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + payloadlen == nghttp2_bufs_len(&bufs)); + assert_int(0, ==, rv); + assert_size(NGHTTP2_FRAME_HDLEN + payloadlen, ==, nghttp2_bufs_len(&bufs)); rv = unpack_framebuf((nghttp2_frame *)&oframe, &bufs); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); check_frame_header(payloadlen, NGHTTP2_ORIGIN, NGHTTP2_FLAG_NONE, 0, &oframe.hd); - CU_ASSERT(2 == oorigin.nov); - CU_ASSERT(sizeof(example) - 1 == oorigin.ov[0].origin_len); - CU_ASSERT(0 == memcmp(example, oorigin.ov[0].origin, sizeof(example) - 1)); - CU_ASSERT(sizeof(nghttp2) - 1 == oorigin.ov[1].origin_len); - CU_ASSERT(0 == memcmp(nghttp2, oorigin.ov[1].origin, sizeof(nghttp2) - 1)); + assert_size(2, ==, oorigin.nov); + assert_size(sizeof(example) - 1, ==, oorigin.ov[0].origin_len); + assert_memory_equal(sizeof(example) - 1, example, oorigin.ov[0].origin); + assert_size(sizeof(nghttp2) - 1, ==, oorigin.ov[1].origin_len); + assert_memory_equal(sizeof(nghttp2) - 1, nghttp2, oorigin.ov[1].origin); nghttp2_frame_origin_free(&oframe, mem); @@ -561,7 +583,7 @@ void test_nghttp2_frame_pack_origin(void) { rv = unpack_framebuf((nghttp2_frame *)&oframe, &bufs); - CU_ASSERT(NGHTTP2_ERR_FRAME_SIZE_ERROR == rv); + assert_int(NGHTTP2_ERR_FRAME_SIZE_ERROR, ==, rv); nghttp2_bufs_reset(&bufs); memset(&oframe, 0, sizeof(oframe)); @@ -573,17 +595,17 @@ void test_nghttp2_frame_pack_origin(void) { rv = nghttp2_frame_pack_origin(&bufs, &frame); - CU_ASSERT(0 == rv); - CU_ASSERT(NGHTTP2_FRAME_HDLEN == nghttp2_bufs_len(&bufs)); + assert_int(0, ==, rv); + assert_size(NGHTTP2_FRAME_HDLEN, ==, nghttp2_bufs_len(&bufs)); rv = unpack_framebuf((nghttp2_frame *)&oframe, &bufs); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); check_frame_header(0, NGHTTP2_ORIGIN, NGHTTP2_FLAG_NONE, 0, &oframe.hd); - CU_ASSERT(0 == oorigin.nov); - CU_ASSERT(NULL == oorigin.ov); + assert_size(0, ==, oorigin.nov); + assert_null(oorigin.ov); nghttp2_frame_origin_free(&oframe, mem); @@ -610,25 +632,25 @@ void test_nghttp2_frame_pack_priority_update(void) { nghttp2_frame_pack_priority_update(&bufs, &frame); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + payloadlen == nghttp2_bufs_len(&bufs)); + assert_size(NGHTTP2_FRAME_HDLEN + payloadlen, ==, nghttp2_bufs_len(&bufs)); rv = unpack_framebuf((nghttp2_frame *)&oframe, &bufs); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); check_frame_header(payloadlen, NGHTTP2_PRIORITY_UPDATE, NGHTTP2_FLAG_NONE, 0, &oframe.hd); - CU_ASSERT(sizeof(field_value) - 1 == opriority_update.field_value_len); - CU_ASSERT(0 == memcmp(field_value, opriority_update.field_value, - sizeof(field_value) - 1)); + assert_size(sizeof(field_value) - 1, ==, opriority_update.field_value_len); + assert_memory_equal(sizeof(field_value) - 1, field_value, + opriority_update.field_value); nghttp2_bufs_free(&bufs); } void test_nghttp2_nv_array_copy(void) { nghttp2_nv *nva; - ssize_t rv; + int rv; nghttp2_nv emptynv[] = {MAKE_NV("", ""), MAKE_NV("", "")}; nghttp2_nv nv[] = {MAKE_NV("alpha", "bravo"), MAKE_NV("charlie", "delta")}; nghttp2_nv bignv; @@ -644,34 +666,34 @@ void test_nghttp2_nv_array_copy(void) { memset(bignv.value, '0', bignv.valuelen); rv = nghttp2_nv_array_copy(&nva, NULL, 0, mem); - CU_ASSERT(0 == rv); - CU_ASSERT(NULL == nva); + assert_int(0, ==, rv); + assert_null(nva); rv = nghttp2_nv_array_copy(&nva, emptynv, ARRLEN(emptynv), mem); - CU_ASSERT(0 == rv); - CU_ASSERT(nva[0].namelen == 0); - CU_ASSERT(nva[0].valuelen == 0); - CU_ASSERT(nva[1].namelen == 0); - CU_ASSERT(nva[1].valuelen == 0); + assert_int(0, ==, rv); + assert_size(0, ==, nva[0].namelen); + assert_size(0, ==, nva[0].valuelen); + assert_size(0, ==, nva[1].namelen); + assert_size(0, ==, nva[1].valuelen); nghttp2_nv_array_del(nva, mem); rv = nghttp2_nv_array_copy(&nva, nv, ARRLEN(nv), mem); - CU_ASSERT(0 == rv); - CU_ASSERT(nva[0].namelen == 5); - CU_ASSERT(0 == memcmp("alpha", nva[0].name, 5)); - CU_ASSERT(nva[0].valuelen == 5); - CU_ASSERT(0 == memcmp("bravo", nva[0].value, 5)); - CU_ASSERT(nva[1].namelen == 7); - CU_ASSERT(0 == memcmp("charlie", nva[1].name, 7)); - CU_ASSERT(nva[1].valuelen == 5); - CU_ASSERT(0 == memcmp("delta", nva[1].value, 5)); + assert_int(0, ==, rv); + assert_size(5, ==, nva[0].namelen); + assert_memory_equal(5, "alpha", nva[0].name); + assert_size(5, ==, nva[0].valuelen); + assert_memory_equal(5, "bravo", nva[0].value); + assert_size(7, ==, nva[1].namelen); + assert_memory_equal(7, "charlie", nva[1].name); + assert_size(5, ==, nva[1].valuelen); + assert_memory_equal(5, "delta", nva[1].value); nghttp2_nv_array_del(nva, mem); /* Large header field is acceptable */ rv = nghttp2_nv_array_copy(&nva, &bignv, 1, mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); nghttp2_nv_array_del(nva, mem); @@ -686,50 +708,50 @@ void test_nghttp2_iv_check(void) { iv[1].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE; iv[1].value = 1024; - CU_ASSERT(nghttp2_iv_check(iv, 2)); + assert_true(nghttp2_iv_check(iv, 2)); iv[1].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE; iv[1].value = NGHTTP2_MAX_WINDOW_SIZE; - CU_ASSERT(nghttp2_iv_check(iv, 2)); + assert_true(nghttp2_iv_check(iv, 2)); /* Too large window size */ iv[1].value = (uint32_t)NGHTTP2_MAX_WINDOW_SIZE + 1; - CU_ASSERT(0 == nghttp2_iv_check(iv, 2)); + assert_false(nghttp2_iv_check(iv, 2)); /* ENABLE_PUSH only allows 0 or 1 */ iv[1].settings_id = NGHTTP2_SETTINGS_ENABLE_PUSH; iv[1].value = 0; - CU_ASSERT(nghttp2_iv_check(iv, 2)); + assert_true(nghttp2_iv_check(iv, 2)); iv[1].value = 1; - CU_ASSERT(nghttp2_iv_check(iv, 2)); + assert_true(nghttp2_iv_check(iv, 2)); iv[1].value = 3; - CU_ASSERT(!nghttp2_iv_check(iv, 2)); + assert_false(nghttp2_iv_check(iv, 2)); /* Undefined SETTINGS ID is allowed */ iv[1].settings_id = 1000000009; iv[1].value = 0; - CU_ASSERT(nghttp2_iv_check(iv, 2)); + assert_true(nghttp2_iv_check(iv, 2)); /* Full size SETTINGS_HEADER_TABLE_SIZE (UINT32_MAX) must be accepted */ iv[1].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE; iv[1].value = UINT32_MAX; - CU_ASSERT(nghttp2_iv_check(iv, 2)); + assert_true(nghttp2_iv_check(iv, 2)); /* Too small SETTINGS_MAX_FRAME_SIZE */ iv[0].settings_id = NGHTTP2_SETTINGS_MAX_FRAME_SIZE; iv[0].value = NGHTTP2_MAX_FRAME_SIZE_MIN - 1; - CU_ASSERT(!nghttp2_iv_check(iv, 1)); + assert_false(nghttp2_iv_check(iv, 1)); /* Too large SETTINGS_MAX_FRAME_SIZE */ iv[0].settings_id = NGHTTP2_SETTINGS_MAX_FRAME_SIZE; iv[0].value = NGHTTP2_MAX_FRAME_SIZE_MAX + 1; - CU_ASSERT(!nghttp2_iv_check(iv, 1)); + assert_false(nghttp2_iv_check(iv, 1)); /* Max and min SETTINGS_MAX_FRAME_SIZE */ iv[0].settings_id = NGHTTP2_SETTINGS_MAX_FRAME_SIZE; iv[0].value = NGHTTP2_MAX_FRAME_SIZE_MIN; iv[1].settings_id = NGHTTP2_SETTINGS_MAX_FRAME_SIZE; iv[1].value = NGHTTP2_MAX_FRAME_SIZE_MAX; - CU_ASSERT(nghttp2_iv_check(iv, 2)); + assert_true(nghttp2_iv_check(iv, 2)); } diff --git a/tests/nghttp2_frame_test.h b/tests/nghttp2_frame_test.h index dc07625..ae7842c 100644 --- a/tests/nghttp2_frame_test.h +++ b/tests/nghttp2_frame_test.h @@ -29,19 +29,25 @@ # include <config.h> #endif /* HAVE_CONFIG_H */ -void test_nghttp2_frame_pack_headers(void); -void test_nghttp2_frame_pack_headers_frame_too_large(void); -void test_nghttp2_frame_pack_priority(void); -void test_nghttp2_frame_pack_rst_stream(void); -void test_nghttp2_frame_pack_settings(void); -void test_nghttp2_frame_pack_push_promise(void); -void test_nghttp2_frame_pack_ping(void); -void test_nghttp2_frame_pack_goaway(void); -void test_nghttp2_frame_pack_window_update(void); -void test_nghttp2_frame_pack_altsvc(void); -void test_nghttp2_frame_pack_origin(void); -void test_nghttp2_frame_pack_priority_update(void); -void test_nghttp2_nv_array_copy(void); -void test_nghttp2_iv_check(void); +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + +extern const MunitSuite frame_suite; + +munit_void_test_decl(test_nghttp2_frame_pack_headers); +munit_void_test_decl(test_nghttp2_frame_pack_headers_frame_too_large); +munit_void_test_decl(test_nghttp2_frame_pack_priority); +munit_void_test_decl(test_nghttp2_frame_pack_rst_stream); +munit_void_test_decl(test_nghttp2_frame_pack_settings); +munit_void_test_decl(test_nghttp2_frame_pack_push_promise); +munit_void_test_decl(test_nghttp2_frame_pack_ping); +munit_void_test_decl(test_nghttp2_frame_pack_goaway); +munit_void_test_decl(test_nghttp2_frame_pack_window_update); +munit_void_test_decl(test_nghttp2_frame_pack_altsvc); +munit_void_test_decl(test_nghttp2_frame_pack_origin); +munit_void_test_decl(test_nghttp2_frame_pack_priority_update); +munit_void_test_decl(test_nghttp2_nv_array_copy); +munit_void_test_decl(test_nghttp2_iv_check); #endif /* NGHTTP2_FRAME_TEST_H */ diff --git a/tests/nghttp2_hd_test.c b/tests/nghttp2_hd_test.c index 657d895..d57127f 100644 --- a/tests/nghttp2_hd_test.c +++ b/tests/nghttp2_hd_test.c @@ -27,11 +27,42 @@ #include <stdio.h> #include <assert.h> -#include <CUnit/CUnit.h> +#include "munit.h" #include "nghttp2_hd.h" #include "nghttp2_frame.h" #include "nghttp2_test_helper.h" +#include "nghttp2_assertion.h" + +static const MunitTest tests[] = { + munit_void_test(test_nghttp2_hd_deflate), + munit_void_test(test_nghttp2_hd_deflate_same_indexed_repr), + munit_void_test(test_nghttp2_hd_inflate_indexed), + munit_void_test(test_nghttp2_hd_inflate_indname_noinc), + munit_void_test(test_nghttp2_hd_inflate_indname_inc), + munit_void_test(test_nghttp2_hd_inflate_indname_inc_eviction), + munit_void_test(test_nghttp2_hd_inflate_newname_noinc), + munit_void_test(test_nghttp2_hd_inflate_newname_inc), + munit_void_test(test_nghttp2_hd_inflate_clearall_inc), + munit_void_test(test_nghttp2_hd_inflate_zero_length_huffman), + munit_void_test(test_nghttp2_hd_inflate_expect_table_size_update), + munit_void_test(test_nghttp2_hd_inflate_unexpected_table_size_update), + munit_void_test(test_nghttp2_hd_ringbuf_reserve), + munit_void_test(test_nghttp2_hd_change_table_size), + munit_void_test(test_nghttp2_hd_deflate_inflate), + munit_void_test(test_nghttp2_hd_no_index), + munit_void_test(test_nghttp2_hd_deflate_bound), + munit_void_test(test_nghttp2_hd_public_api), + munit_void_test(test_nghttp2_hd_deflate_hd_vec), + munit_void_test(test_nghttp2_hd_decode_length), + munit_void_test(test_nghttp2_hd_huff_encode), + munit_void_test(test_nghttp2_hd_huff_decode), + munit_test_end(), +}; + +const MunitSuite hd_suite = { + "/hd", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; void test_nghttp2_hd_deflate(void) { nghttp2_hd_deflater deflater; @@ -47,7 +78,7 @@ void test_nghttp2_hd_deflate(void) { nghttp2_nv nva5[] = {MAKE_NV(":path", "/style.css"), MAKE_NV("x-nghttp2", "")}; nghttp2_bufs bufs; - ssize_t blocklen; + nghttp2_ssize blocklen; nva_out out; int rv; nghttp2_mem *mem; @@ -56,17 +87,17 @@ void test_nghttp2_hd_deflate(void) { frame_pack_bufs_init(&bufs); nva_out_init(&out); - CU_ASSERT(0 == nghttp2_hd_deflate_init(&deflater, mem)); - CU_ASSERT(0 == nghttp2_hd_inflate_init(&inflater, mem)); + assert_int(0, ==, nghttp2_hd_deflate_init(&deflater, mem)); + assert_int(0, ==, nghttp2_hd_inflate_init(&inflater, mem)); rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva1, ARRLEN(nva1)); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen > 0); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_int(0, ==, rv); + assert_ptrdiff(0, <, blocklen); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(3 == out.nvlen); + assert_size(3, ==, out.nvlen); assert_nv_equal(nva1, out.nva, 3, mem); nva_out_reset(&out, mem); @@ -74,13 +105,13 @@ void test_nghttp2_hd_deflate(void) { /* Second headers */ rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva2, ARRLEN(nva2)); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen > 0); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_int(0, ==, rv); + assert_ptrdiff(0, <, blocklen); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(2 == out.nvlen); + assert_size(2, ==, out.nvlen); assert_nv_equal(nva2, out.nva, 2, mem); nva_out_reset(&out, mem); @@ -89,13 +120,13 @@ void test_nghttp2_hd_deflate(void) { /* Third headers, including same header field name, but value is not the same. */ rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva3, ARRLEN(nva3)); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen > 0); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_int(0, ==, rv); + assert_ptrdiff(0, <, blocklen); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(3 == out.nvlen); + assert_size(3, ==, out.nvlen); assert_nv_equal(nva3, out.nva, 3, mem); nva_out_reset(&out, mem); @@ -103,13 +134,13 @@ void test_nghttp2_hd_deflate(void) { /* Fourth headers, including duplicate header fields. */ rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva4, ARRLEN(nva4)); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen > 0); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_int(0, ==, rv); + assert_ptrdiff(0, <, blocklen); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(3 == out.nvlen); + assert_size(3, ==, out.nvlen); assert_nv_equal(nva4, out.nva, 3, mem); nva_out_reset(&out, mem); @@ -117,13 +148,13 @@ void test_nghttp2_hd_deflate(void) { /* Fifth headers includes empty value */ rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva5, ARRLEN(nva5)); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen > 0); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_int(0, ==, rv); + assert_ptrdiff(0, <, blocklen); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(2 == out.nvlen); + assert_size(2, ==, out.nvlen); assert_nv_equal(nva5, out.nva, 2, mem); nva_out_reset(&out, mem); @@ -142,7 +173,7 @@ void test_nghttp2_hd_deflate_same_indexed_repr(void) { nghttp2_nv nva2[] = {MAKE_NV("host", "alpha"), MAKE_NV("host", "alpha"), MAKE_NV("host", "alpha")}; nghttp2_bufs bufs; - ssize_t blocklen; + nghttp2_ssize blocklen; nva_out out; int rv; nghttp2_mem *mem; @@ -151,18 +182,18 @@ void test_nghttp2_hd_deflate_same_indexed_repr(void) { frame_pack_bufs_init(&bufs); nva_out_init(&out); - CU_ASSERT(0 == nghttp2_hd_deflate_init(&deflater, mem)); - CU_ASSERT(0 == nghttp2_hd_inflate_init(&inflater, mem)); + assert_int(0, ==, nghttp2_hd_deflate_init(&deflater, mem)); + assert_int(0, ==, nghttp2_hd_inflate_init(&inflater, mem)); /* Encode 2 same headers. Emit 1 literal reprs and 1 index repr. */ rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva1, ARRLEN(nva1)); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen > 0); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_int(0, ==, rv); + assert_ptrdiff(0, <, blocklen); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(2 == out.nvlen); + assert_size(2, ==, out.nvlen); assert_nv_equal(nva1, out.nva, 2, mem); nva_out_reset(&out, mem); @@ -170,13 +201,13 @@ void test_nghttp2_hd_deflate_same_indexed_repr(void) { /* Encode 3 same headers. This time, emits 3 index reprs. */ rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva2, ARRLEN(nva2)); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen == 3); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_int(0, ==, rv); + assert_ptrdiff(3, ==, blocklen); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(3 == out.nvlen); + assert_size(3, ==, out.nvlen); assert_nv_equal(nva2, out.nva, 3, mem); nva_out_reset(&out, mem); @@ -191,7 +222,7 @@ void test_nghttp2_hd_deflate_same_indexed_repr(void) { void test_nghttp2_hd_inflate_indexed(void) { nghttp2_hd_inflater inflater; nghttp2_bufs bufs; - ssize_t blocklen; + nghttp2_ssize blocklen; nghttp2_nv nv = MAKE_NV(":path", "/"); nva_out out; nghttp2_mem *mem; @@ -204,12 +235,12 @@ void test_nghttp2_hd_inflate_indexed(void) { nghttp2_bufs_addb(&bufs, (1 << 7) | 4); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(1 == blocklen); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(1, ==, blocklen); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(1 == out.nvlen); + assert_size(1, ==, out.nvlen); assert_nv_equal(&nv, out.nva, 1, mem); @@ -219,11 +250,11 @@ void test_nghttp2_hd_inflate_indexed(void) { /* index = 0 is error */ nghttp2_bufs_addb(&bufs, 1 << 7); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(1 == blocklen); - CU_ASSERT(NGHTTP2_ERR_HEADER_COMP == - inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(1, ==, blocklen); + assert_ptrdiff(NGHTTP2_ERR_HEADER_COMP, ==, + inflate_hd(&inflater, &out, &bufs, 0, mem)); nghttp2_bufs_free(&bufs); nghttp2_hd_inflate_free(&inflater); @@ -232,7 +263,7 @@ void test_nghttp2_hd_inflate_indexed(void) { void test_nghttp2_hd_inflate_indname_noinc(void) { nghttp2_hd_inflater inflater; nghttp2_bufs bufs; - ssize_t blocklen; + nghttp2_ssize blocklen; nghttp2_nv nv[] = {/* Huffman */ MAKE_NV("user-agent", "nghttp2"), /* Expecting no huffman */ @@ -248,18 +279,19 @@ void test_nghttp2_hd_inflate_indname_noinc(void) { nghttp2_hd_inflate_init(&inflater, mem); for (i = 0; i < ARRLEN(nv); ++i) { - CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&bufs, 57, &nv[i], - NGHTTP2_HD_WITHOUT_INDEXING)); + assert_int(0, ==, + nghttp2_hd_emit_indname_block(&bufs, 57, &nv[i], + NGHTTP2_HD_WITHOUT_INDEXING)); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(blocklen > 0); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(0, <, blocklen); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(1 == out.nvlen); + assert_size(1, ==, out.nvlen); assert_nv_equal(&nv[i], out.nva, 1, mem); - CU_ASSERT(0 == inflater.ctx.hd_table.len); - CU_ASSERT(61 == nghttp2_hd_inflate_get_num_table_entries(&inflater)); + assert_size(0, ==, inflater.ctx.hd_table.len); + assert_size(61, ==, nghttp2_hd_inflate_get_num_table_entries(&inflater)); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); @@ -272,7 +304,7 @@ void test_nghttp2_hd_inflate_indname_noinc(void) { void test_nghttp2_hd_inflate_indname_inc(void) { nghttp2_hd_inflater inflater; nghttp2_bufs bufs; - ssize_t blocklen; + nghttp2_ssize blocklen; nghttp2_nv nv = MAKE_NV("user-agent", "nghttp2"); nva_out out; nghttp2_mem *mem; @@ -283,18 +315,19 @@ void test_nghttp2_hd_inflate_indname_inc(void) { nva_out_init(&out); nghttp2_hd_inflate_init(&inflater, mem); - CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&bufs, 57, &nv, - NGHTTP2_HD_WITH_INDEXING)); + assert_int( + 0, ==, + nghttp2_hd_emit_indname_block(&bufs, 57, &nv, NGHTTP2_HD_WITH_INDEXING)); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(blocklen > 0); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(0, <, blocklen); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(1 == out.nvlen); + assert_size(1, ==, out.nvlen); assert_nv_equal(&nv, out.nva, 1, mem); - CU_ASSERT(1 == inflater.ctx.hd_table.len); - CU_ASSERT(62 == nghttp2_hd_inflate_get_num_table_entries(&inflater)); + assert_size(1, ==, inflater.ctx.hd_table.len); + assert_size(62, ==, nghttp2_hd_inflate_get_num_table_entries(&inflater)); assert_nv_equal( &nv, nghttp2_hd_inflate_get_table_entry( @@ -309,7 +342,7 @@ void test_nghttp2_hd_inflate_indname_inc(void) { void test_nghttp2_hd_inflate_indname_inc_eviction(void) { nghttp2_hd_inflater inflater; nghttp2_bufs bufs; - ssize_t blocklen; + nghttp2_ssize blocklen; uint8_t value[1025]; nva_out out; nghttp2_nv nv; @@ -328,31 +361,35 @@ void test_nghttp2_hd_inflate_indname_inc_eviction(void) { nv.flags = NGHTTP2_NV_FLAG_NONE; - CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&bufs, 14, &nv, - NGHTTP2_HD_WITH_INDEXING)); - CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&bufs, 15, &nv, - NGHTTP2_HD_WITH_INDEXING)); - CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&bufs, 16, &nv, - NGHTTP2_HD_WITH_INDEXING)); - CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&bufs, 17, &nv, - NGHTTP2_HD_WITH_INDEXING)); + assert_int( + 0, ==, + nghttp2_hd_emit_indname_block(&bufs, 14, &nv, NGHTTP2_HD_WITH_INDEXING)); + assert_int( + 0, ==, + nghttp2_hd_emit_indname_block(&bufs, 15, &nv, NGHTTP2_HD_WITH_INDEXING)); + assert_int( + 0, ==, + nghttp2_hd_emit_indname_block(&bufs, 16, &nv, NGHTTP2_HD_WITH_INDEXING)); + assert_int( + 0, ==, + nghttp2_hd_emit_indname_block(&bufs, 17, &nv, NGHTTP2_HD_WITH_INDEXING)); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(blocklen > 0); + assert_ptrdiff(0, <, blocklen); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(4 == out.nvlen); - CU_ASSERT(14 == out.nva[0].namelen); - CU_ASSERT(0 == memcmp("accept-charset", out.nva[0].name, out.nva[0].namelen)); - CU_ASSERT(sizeof(value) - 1 == out.nva[0].valuelen); + assert_size(4, ==, out.nvlen); + assert_size(14, ==, out.nva[0].namelen); + assert_memory_equal(out.nva[0].namelen, "accept-charset", out.nva[0].name); + assert_size(sizeof(value) - 1, ==, out.nva[0].valuelen); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); - CU_ASSERT(3 == inflater.ctx.hd_table.len); - CU_ASSERT(64 == nghttp2_hd_inflate_get_num_table_entries(&inflater)); + assert_size(3, ==, inflater.ctx.hd_table.len); + assert_size(64, ==, nghttp2_hd_inflate_get_num_table_entries(&inflater)); nghttp2_bufs_free(&bufs); nghttp2_hd_inflate_free(&inflater); @@ -361,7 +398,7 @@ void test_nghttp2_hd_inflate_indname_inc_eviction(void) { void test_nghttp2_hd_inflate_newname_noinc(void) { nghttp2_hd_inflater inflater; nghttp2_bufs bufs; - ssize_t blocklen; + nghttp2_ssize blocklen; nghttp2_nv nv[] = {/* Expecting huffman for both */ MAKE_NV("my-long-content-length", "nghttp2"), /* Expecting no huffman for both */ @@ -380,17 +417,18 @@ void test_nghttp2_hd_inflate_newname_noinc(void) { nva_out_init(&out); nghttp2_hd_inflate_init(&inflater, mem); for (i = 0; i < ARRLEN(nv); ++i) { - CU_ASSERT(0 == nghttp2_hd_emit_newname_block(&bufs, &nv[i], - NGHTTP2_HD_WITHOUT_INDEXING)); + assert_int(0, ==, + nghttp2_hd_emit_newname_block(&bufs, &nv[i], + NGHTTP2_HD_WITHOUT_INDEXING)); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(blocklen > 0); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(0, <, blocklen); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(1 == out.nvlen); + assert_size(1, ==, out.nvlen); assert_nv_equal(&nv[i], out.nva, 1, mem); - CU_ASSERT(0 == inflater.ctx.hd_table.len); + assert_size(0, ==, inflater.ctx.hd_table.len); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); @@ -403,7 +441,7 @@ void test_nghttp2_hd_inflate_newname_noinc(void) { void test_nghttp2_hd_inflate_newname_inc(void) { nghttp2_hd_inflater inflater; nghttp2_bufs bufs; - ssize_t blocklen; + nghttp2_ssize blocklen; nghttp2_nv nv = MAKE_NV("x-rel", "nghttp2"); nva_out out; nghttp2_mem *mem; @@ -414,17 +452,18 @@ void test_nghttp2_hd_inflate_newname_inc(void) { nva_out_init(&out); nghttp2_hd_inflate_init(&inflater, mem); - CU_ASSERT( - 0 == nghttp2_hd_emit_newname_block(&bufs, &nv, NGHTTP2_HD_WITH_INDEXING)); + assert_int( + 0, ==, + nghttp2_hd_emit_newname_block(&bufs, &nv, NGHTTP2_HD_WITH_INDEXING)); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(blocklen > 0); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(0, <, blocklen); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(1 == out.nvlen); + assert_size(1, ==, out.nvlen); assert_nv_equal(&nv, out.nva, 1, mem); - CU_ASSERT(1 == inflater.ctx.hd_table.len); + assert_size(1, ==, inflater.ctx.hd_table.len); assert_nv_equal( &nv, nghttp2_hd_inflate_get_table_entry( @@ -439,7 +478,7 @@ void test_nghttp2_hd_inflate_newname_inc(void) { void test_nghttp2_hd_inflate_clearall_inc(void) { nghttp2_hd_inflater inflater; nghttp2_bufs bufs; - ssize_t blocklen; + nghttp2_ssize blocklen; nghttp2_nv nv; uint8_t value[4061]; nva_out out; @@ -461,26 +500,27 @@ void test_nghttp2_hd_inflate_clearall_inc(void) { nghttp2_hd_inflate_init(&inflater, mem); - CU_ASSERT( - 0 == nghttp2_hd_emit_newname_block(&bufs, &nv, NGHTTP2_HD_WITH_INDEXING)); + assert_int( + 0, ==, + nghttp2_hd_emit_newname_block(&bufs, &nv, NGHTTP2_HD_WITH_INDEXING)); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(blocklen > 0); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(0, <, blocklen); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(1 == out.nvlen); + assert_size(1, ==, out.nvlen); assert_nv_equal(&nv, out.nva, 1, mem); - CU_ASSERT(0 == inflater.ctx.hd_table.len); + assert_size(0, ==, inflater.ctx.hd_table.len); nva_out_reset(&out, mem); /* Do it again */ - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(1 == out.nvlen); + assert_size(1, ==, out.nvlen); assert_nv_equal(&nv, out.nva, 1, mem); - CU_ASSERT(0 == inflater.ctx.hd_table.len); + assert_size(0, ==, inflater.ctx.hd_table.len); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); @@ -489,17 +529,18 @@ void test_nghttp2_hd_inflate_clearall_inc(void) { header table */ nv.valuelen = sizeof(value) - 2; - CU_ASSERT( - 0 == nghttp2_hd_emit_newname_block(&bufs, &nv, NGHTTP2_HD_WITH_INDEXING)); + assert_int( + 0, ==, + nghttp2_hd_emit_newname_block(&bufs, &nv, NGHTTP2_HD_WITH_INDEXING)); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(blocklen > 0); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(0, <, blocklen); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(1 == out.nvlen); + assert_size(1, ==, out.nvlen); assert_nv_equal(&nv, out.nva, 1, mem); - CU_ASSERT(1 == inflater.ctx.hd_table.len); + assert_size(1, ==, inflater.ctx.hd_table.len); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); @@ -530,13 +571,13 @@ void test_nghttp2_hd_inflate_zero_length_huffman(void) { /* ptr[3] = 0x80; */ nghttp2_hd_inflate_init(&inflater, mem); - CU_ASSERT(4 == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(4, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(1 == out.nvlen); - CU_ASSERT(1 == out.nva[0].namelen); - CU_ASSERT('x' == out.nva[0].name[0]); - CU_ASSERT(NULL == out.nva[0].value); - CU_ASSERT(0 == out.nva[0].valuelen); + assert_size(1, ==, out.nvlen); + assert_size(1, ==, out.nva[0].namelen); + assert_uint8('x', ==, out.nva[0].name[0]); + assert_null(out.nva[0].value); + assert_size(0, ==, out.nva[0].valuelen); nva_out_reset(&out, mem); nghttp2_bufs_free(&bufs); @@ -561,8 +602,8 @@ void test_nghttp2_hd_inflate_expect_table_size_update(void) { inflation. */ nghttp2_hd_inflate_change_table_size(&inflater, 4095); nghttp2_hd_inflate_change_table_size(&inflater, 4096); - CU_ASSERT(NGHTTP2_ERR_HEADER_COMP == - inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(NGHTTP2_ERR_HEADER_COMP, ==, + inflate_hd(&inflater, &out, &bufs, 0, mem)); nva_out_reset(&out, mem); nghttp2_hd_inflate_free(&inflater); @@ -571,8 +612,8 @@ void test_nghttp2_hd_inflate_expect_table_size_update(void) { * size is not changed. */ nghttp2_hd_inflate_init(&inflater, mem); nghttp2_hd_inflate_change_table_size(&inflater, 4096); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == - inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, + inflate_hd(&inflater, &out, &bufs, 0, mem)); nva_out_reset(&out, mem); nghttp2_hd_inflate_free(&inflater); @@ -581,8 +622,8 @@ void test_nghttp2_hd_inflate_expect_table_size_update(void) { new size is larger than current size. */ nghttp2_hd_inflate_init(&inflater, mem); nghttp2_hd_inflate_change_table_size(&inflater, 4097); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == - inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, + inflate_hd(&inflater, &out, &bufs, 0, mem)); nva_out_reset(&out, mem); nghttp2_hd_inflate_free(&inflater); @@ -595,8 +636,8 @@ void test_nghttp2_hd_inflate_expect_table_size_update(void) { nghttp2_bufs_reset(&bufs); nghttp2_hd_emit_table_size(&bufs, 112); - CU_ASSERT(NGHTTP2_ERR_HEADER_COMP == - inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(NGHTTP2_ERR_HEADER_COMP, ==, + inflate_hd(&inflater, &out, &bufs, 0, mem)); nva_out_reset(&out, mem); nghttp2_hd_inflate_free(&inflater); @@ -610,8 +651,8 @@ void test_nghttp2_hd_inflate_expect_table_size_update(void) { nghttp2_hd_emit_table_size(&bufs, 111); nghttp2_hd_emit_table_size(&bufs, 4096); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == - inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, + inflate_hd(&inflater, &out, &bufs, 0, mem)); nva_out_reset(&out, mem); nghttp2_hd_inflate_free(&inflater); @@ -625,8 +666,8 @@ void test_nghttp2_hd_inflate_expect_table_size_update(void) { nghttp2_hd_emit_table_size(&bufs, 111); nghttp2_hd_emit_table_size(&bufs, 4096); - CU_ASSERT(NGHTTP2_ERR_HEADER_COMP == - inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(NGHTTP2_ERR_HEADER_COMP, ==, + inflate_hd(&inflater, &out, &bufs, 0, mem)); nva_out_reset(&out, mem); nghttp2_hd_inflate_free(&inflater); @@ -649,8 +690,8 @@ void test_nghttp2_hd_inflate_unexpected_table_size_update(void) { nghttp2_bufs_add(&bufs, data, sizeof(data)); nghttp2_hd_inflate_init(&inflater, mem); - CU_ASSERT(NGHTTP2_ERR_HEADER_COMP == - inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(NGHTTP2_ERR_HEADER_COMP, ==, + inflate_hd(&inflater, &out, &bufs, 0, mem)); nva_out_reset(&out, mem); nghttp2_bufs_free(&bufs); @@ -664,8 +705,8 @@ void test_nghttp2_hd_ringbuf_reserve(void) { nghttp2_bufs bufs; nva_out out; int i; - ssize_t rv; - ssize_t blocklen; + nghttp2_ssize rv; + nghttp2_ssize blocklen; nghttp2_mem *mem; mem = nghttp2_mem_default(); @@ -688,14 +729,14 @@ void test_nghttp2_hd_ringbuf_reserve(void) { for (i = 0; i < 150; ++i) { memcpy(nv.value, &i, sizeof(i)); rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, &nv, 1); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen > 0); + assert_ptrdiff(0, ==, rv); + assert_ptrdiff(0, <, blocklen); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(1 == out.nvlen); + assert_size(1, ==, out.nvlen); assert_nv_equal(&nv, out.nva, 1, mem); nva_out_reset(&out, mem); @@ -715,9 +756,9 @@ void test_nghttp2_hd_change_table_size(void) { nghttp2_nv nva[] = {MAKE_NV("alpha", "bravo"), MAKE_NV("charlie", "delta")}; nghttp2_nv nva2[] = {MAKE_NV(":path", "/")}; nghttp2_bufs bufs; - ssize_t rv; + int rv; nva_out out; - ssize_t blocklen; + nghttp2_ssize blocklen; nghttp2_mem *mem; mem = nghttp2_mem_default(); @@ -729,87 +770,87 @@ void test_nghttp2_hd_change_table_size(void) { nghttp2_hd_inflate_init(&inflater, mem); /* inflater changes notifies 8000 max header table size */ - CU_ASSERT(0 == nghttp2_hd_inflate_change_table_size(&inflater, 8000)); - CU_ASSERT(0 == nghttp2_hd_deflate_change_table_size(&deflater, 8000)); + assert_int(0, ==, nghttp2_hd_inflate_change_table_size(&inflater, 8000)); + assert_int(0, ==, nghttp2_hd_deflate_change_table_size(&deflater, 8000)); - CU_ASSERT(4096 == deflater.ctx.hd_table_bufsize_max); + assert_size(4096, ==, deflater.ctx.hd_table_bufsize_max); - CU_ASSERT(4096 == inflater.ctx.hd_table_bufsize_max); - CU_ASSERT(8000 == inflater.settings_hd_table_bufsize_max); + assert_size(4096, ==, inflater.ctx.hd_table_bufsize_max); + assert_size(8000, ==, inflater.settings_hd_table_bufsize_max); /* This will emit encoding context update with header table size 4096 */ rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, 2); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen > 0); - CU_ASSERT(2 == deflater.ctx.hd_table.len); - CU_ASSERT(63 == nghttp2_hd_deflate_get_num_table_entries(&deflater)); - CU_ASSERT(4096 == deflater.ctx.hd_table_bufsize_max); + assert_int(0, ==, rv); + assert_ptrdiff(0, <, blocklen); + assert_size(2, ==, deflater.ctx.hd_table.len); + assert_size(63, ==, nghttp2_hd_deflate_get_num_table_entries(&deflater)); + assert_size(4096, ==, deflater.ctx.hd_table_bufsize_max); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(2 == inflater.ctx.hd_table.len); - CU_ASSERT(63 == nghttp2_hd_inflate_get_num_table_entries(&inflater)); - CU_ASSERT(4096 == inflater.ctx.hd_table_bufsize_max); - CU_ASSERT(8000 == inflater.settings_hd_table_bufsize_max); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_size(2, ==, inflater.ctx.hd_table.len); + assert_size(63, ==, nghttp2_hd_inflate_get_num_table_entries(&inflater)); + assert_size(4096, ==, inflater.ctx.hd_table_bufsize_max); + assert_size(8000, ==, inflater.settings_hd_table_bufsize_max); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); /* inflater changes header table size to 1024 */ - CU_ASSERT(0 == nghttp2_hd_inflate_change_table_size(&inflater, 1024)); - CU_ASSERT(0 == nghttp2_hd_deflate_change_table_size(&deflater, 1024)); + assert_int(0, ==, nghttp2_hd_inflate_change_table_size(&inflater, 1024)); + assert_int(0, ==, nghttp2_hd_deflate_change_table_size(&deflater, 1024)); - CU_ASSERT(1024 == deflater.ctx.hd_table_bufsize_max); + assert_size(1024, ==, deflater.ctx.hd_table_bufsize_max); - CU_ASSERT(1024 == inflater.ctx.hd_table_bufsize_max); - CU_ASSERT(1024 == inflater.settings_hd_table_bufsize_max); + assert_size(1024, ==, inflater.ctx.hd_table_bufsize_max); + assert_size(1024, ==, inflater.settings_hd_table_bufsize_max); rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, 2); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen > 0); - CU_ASSERT(2 == deflater.ctx.hd_table.len); - CU_ASSERT(63 == nghttp2_hd_deflate_get_num_table_entries(&deflater)); - CU_ASSERT(1024 == deflater.ctx.hd_table_bufsize_max); + assert_int(0, ==, rv); + assert_ptrdiff(0, <, blocklen); + assert_size(2, ==, deflater.ctx.hd_table.len); + assert_size(63, ==, nghttp2_hd_deflate_get_num_table_entries(&deflater)); + assert_size(1024, ==, deflater.ctx.hd_table_bufsize_max); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(2 == inflater.ctx.hd_table.len); - CU_ASSERT(63 == nghttp2_hd_inflate_get_num_table_entries(&inflater)); - CU_ASSERT(1024 == inflater.ctx.hd_table_bufsize_max); - CU_ASSERT(1024 == inflater.settings_hd_table_bufsize_max); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_size(2, ==, inflater.ctx.hd_table.len); + assert_size(63, ==, nghttp2_hd_inflate_get_num_table_entries(&inflater)); + assert_size(1024, ==, inflater.ctx.hd_table_bufsize_max); + assert_size(1024, ==, inflater.settings_hd_table_bufsize_max); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); /* inflater changes header table size to 0 */ - CU_ASSERT(0 == nghttp2_hd_inflate_change_table_size(&inflater, 0)); - CU_ASSERT(0 == nghttp2_hd_deflate_change_table_size(&deflater, 0)); + assert_int(0, ==, nghttp2_hd_inflate_change_table_size(&inflater, 0)); + assert_int(0, ==, nghttp2_hd_deflate_change_table_size(&deflater, 0)); - CU_ASSERT(0 == deflater.ctx.hd_table.len); - CU_ASSERT(61 == nghttp2_hd_deflate_get_num_table_entries(&deflater)); - CU_ASSERT(0 == deflater.ctx.hd_table_bufsize_max); + assert_size(0, ==, deflater.ctx.hd_table.len); + assert_size(61, ==, nghttp2_hd_deflate_get_num_table_entries(&deflater)); + assert_size(0, ==, deflater.ctx.hd_table_bufsize_max); - CU_ASSERT(0 == inflater.ctx.hd_table.len); - CU_ASSERT(61 == nghttp2_hd_inflate_get_num_table_entries(&inflater)); - CU_ASSERT(0 == inflater.ctx.hd_table_bufsize_max); - CU_ASSERT(0 == inflater.settings_hd_table_bufsize_max); + assert_size(0, ==, inflater.ctx.hd_table.len); + assert_size(61, ==, nghttp2_hd_inflate_get_num_table_entries(&inflater)); + assert_size(0, ==, inflater.ctx.hd_table_bufsize_max); + assert_size(0, ==, inflater.settings_hd_table_bufsize_max); rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, 2); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen > 0); - CU_ASSERT(0 == deflater.ctx.hd_table.len); - CU_ASSERT(61 == nghttp2_hd_deflate_get_num_table_entries(&deflater)); - CU_ASSERT(0 == deflater.ctx.hd_table_bufsize_max); + assert_int(0, ==, rv); + assert_ptrdiff(0, <, blocklen); + assert_size(0, ==, deflater.ctx.hd_table.len); + assert_size(61, ==, nghttp2_hd_deflate_get_num_table_entries(&deflater)); + assert_size(0, ==, deflater.ctx.hd_table_bufsize_max); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(0 == inflater.ctx.hd_table.len); - CU_ASSERT(61 == nghttp2_hd_inflate_get_num_table_entries(&inflater)); - CU_ASSERT(0 == inflater.ctx.hd_table_bufsize_max); - CU_ASSERT(0 == inflater.settings_hd_table_bufsize_max); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_size(0, ==, inflater.ctx.hd_table.len); + assert_size(61, ==, nghttp2_hd_inflate_get_num_table_entries(&inflater)); + assert_size(0, ==, inflater.ctx.hd_table_bufsize_max); + assert_size(0, ==, inflater.settings_hd_table_bufsize_max); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); @@ -825,53 +866,57 @@ void test_nghttp2_hd_change_table_size(void) { nghttp2_hd_inflate_init(&inflater, mem); /* First inflater changes header table size to 8000 */ - CU_ASSERT(0 == nghttp2_hd_inflate_change_table_size(&inflater, 8000)); - CU_ASSERT(0 == nghttp2_hd_deflate_change_table_size(&deflater, 8000)); + assert_int(0, ==, nghttp2_hd_inflate_change_table_size(&inflater, 8000)); + assert_int(0, ==, nghttp2_hd_deflate_change_table_size(&deflater, 8000)); - CU_ASSERT(8000 == deflater.ctx.hd_table_bufsize_max); - CU_ASSERT(8000 == nghttp2_hd_deflate_get_max_dynamic_table_size(&deflater)); - CU_ASSERT(4096 == inflater.ctx.hd_table_bufsize_max); - CU_ASSERT(4096 == nghttp2_hd_inflate_get_max_dynamic_table_size(&inflater)); - CU_ASSERT(8000 == inflater.settings_hd_table_bufsize_max); + assert_size(8000, ==, deflater.ctx.hd_table_bufsize_max); + assert_size(8000, ==, + nghttp2_hd_deflate_get_max_dynamic_table_size(&deflater)); + assert_size(4096, ==, inflater.ctx.hd_table_bufsize_max); + assert_size(4096, ==, + nghttp2_hd_inflate_get_max_dynamic_table_size(&inflater)); + assert_size(8000, ==, inflater.settings_hd_table_bufsize_max); rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, 2); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen > 0); - CU_ASSERT(2 == deflater.ctx.hd_table.len); - CU_ASSERT(8000 == deflater.ctx.hd_table_bufsize_max); + assert_int(0, ==, rv); + assert_ptrdiff(0, <, blocklen); + assert_size(2, ==, deflater.ctx.hd_table.len); + assert_size(8000, ==, deflater.ctx.hd_table_bufsize_max); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(2 == inflater.ctx.hd_table.len); - CU_ASSERT(8000 == inflater.ctx.hd_table_bufsize_max); - CU_ASSERT(8000 == inflater.settings_hd_table_bufsize_max); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_size(2, ==, inflater.ctx.hd_table.len); + assert_size(8000, ==, inflater.ctx.hd_table_bufsize_max); + assert_size(8000, ==, inflater.settings_hd_table_bufsize_max); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); - CU_ASSERT(0 == nghttp2_hd_inflate_change_table_size(&inflater, 16383)); - CU_ASSERT(0 == nghttp2_hd_deflate_change_table_size(&deflater, 16383)); + assert_int(0, ==, nghttp2_hd_inflate_change_table_size(&inflater, 16383)); + assert_int(0, ==, nghttp2_hd_deflate_change_table_size(&deflater, 16383)); - CU_ASSERT(8192 == deflater.ctx.hd_table_bufsize_max); - CU_ASSERT(8192 == nghttp2_hd_deflate_get_max_dynamic_table_size(&deflater)); + assert_size(8192, ==, deflater.ctx.hd_table_bufsize_max); + assert_size(8192, ==, + nghttp2_hd_deflate_get_max_dynamic_table_size(&deflater)); - CU_ASSERT(8000 == inflater.ctx.hd_table_bufsize_max); - CU_ASSERT(8000 == nghttp2_hd_inflate_get_max_dynamic_table_size(&inflater)); - CU_ASSERT(16383 == inflater.settings_hd_table_bufsize_max); + assert_size(8000, ==, inflater.ctx.hd_table_bufsize_max); + assert_size(8000, ==, + nghttp2_hd_inflate_get_max_dynamic_table_size(&inflater)); + assert_size(16383, ==, inflater.settings_hd_table_bufsize_max); rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, 2); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen > 0); - CU_ASSERT(2 == deflater.ctx.hd_table.len); - CU_ASSERT(8192 == deflater.ctx.hd_table_bufsize_max); + assert_int(0, ==, rv); + assert_ptrdiff(0, <, blocklen); + assert_size(2, ==, deflater.ctx.hd_table.len); + assert_size(8192, ==, deflater.ctx.hd_table_bufsize_max); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(2 == inflater.ctx.hd_table.len); - CU_ASSERT(8192 == inflater.ctx.hd_table_bufsize_max); - CU_ASSERT(16383 == inflater.settings_hd_table_bufsize_max); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_size(2, ==, inflater.ctx.hd_table.len); + assert_size(8192, ==, inflater.ctx.hd_table_bufsize_max); + assert_size(16383, ==, inflater.settings_hd_table_bufsize_max); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); @@ -879,9 +924,9 @@ void test_nghttp2_hd_change_table_size(void) { /* Lastly, check the error condition */ rv = nghttp2_hd_emit_table_size(&bufs, 25600); - CU_ASSERT(rv == 0); - CU_ASSERT(NGHTTP2_ERR_HEADER_COMP == - inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_int(0, ==, rv); + assert_ptrdiff(NGHTTP2_ERR_HEADER_COMP, ==, + inflate_hd(&inflater, &out, &bufs, 0, mem)); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); @@ -894,21 +939,21 @@ void test_nghttp2_hd_change_table_size(void) { nghttp2_hd_deflate_init2(&deflater, 1024, mem); nghttp2_hd_inflate_init(&inflater, mem); - CU_ASSERT(1024 == deflater.ctx.hd_table_bufsize_max); + assert_size(1024, ==, deflater.ctx.hd_table_bufsize_max); /* This emits context update with buffer size 1024 */ rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, 2); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen > 0); - CU_ASSERT(2 == deflater.ctx.hd_table.len); - CU_ASSERT(1024 == deflater.ctx.hd_table_bufsize_max); + assert_int(0, ==, rv); + assert_ptrdiff(0, <, blocklen); + assert_size(2, ==, deflater.ctx.hd_table.len); + assert_size(1024, ==, deflater.ctx.hd_table_bufsize_max); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(2 == inflater.ctx.hd_table.len); - CU_ASSERT(1024 == inflater.ctx.hd_table_bufsize_max); - CU_ASSERT(4096 == inflater.settings_hd_table_bufsize_max); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_size(2, ==, inflater.ctx.hd_table.len); + assert_size(1024, ==, inflater.ctx.hd_table_bufsize_max); + assert_size(4096, ==, inflater.settings_hd_table_bufsize_max); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); @@ -920,18 +965,20 @@ void test_nghttp2_hd_change_table_size(void) { nghttp2_hd_deflate_init2(&deflater, UINT32_MAX, mem); nghttp2_hd_inflate_init(&inflater, mem); - CU_ASSERT(0 == nghttp2_hd_inflate_change_table_size(&inflater, UINT32_MAX)); - CU_ASSERT(0 == nghttp2_hd_deflate_change_table_size(&deflater, UINT32_MAX)); + assert_int(0, ==, + nghttp2_hd_inflate_change_table_size(&inflater, UINT32_MAX)); + assert_int(0, ==, + nghttp2_hd_deflate_change_table_size(&deflater, UINT32_MAX)); rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, 2); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(UINT32_MAX == deflater.ctx.hd_table_bufsize_max); + assert_int(0, ==, rv); + assert_size(UINT32_MAX, ==, deflater.ctx.hd_table_bufsize_max); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(UINT32_MAX == inflater.ctx.hd_table_bufsize_max); - CU_ASSERT(UINT32_MAX == inflater.settings_hd_table_bufsize_max); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_size(UINT32_MAX, ==, inflater.ctx.hd_table_bufsize_max); + assert_size(UINT32_MAX, ==, inflater.settings_hd_table_bufsize_max); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); @@ -943,25 +990,25 @@ void test_nghttp2_hd_change_table_size(void) { nghttp2_hd_deflate_init2(&deflater, 4096, mem); nghttp2_hd_inflate_init(&inflater, mem); - CU_ASSERT(0 == nghttp2_hd_inflate_change_table_size(&inflater, 0)); - CU_ASSERT(0 == nghttp2_hd_inflate_change_table_size(&inflater, 3000)); - CU_ASSERT(0 == nghttp2_hd_deflate_change_table_size(&deflater, 0)); - CU_ASSERT(0 == nghttp2_hd_deflate_change_table_size(&deflater, 3000)); + assert_int(0, ==, nghttp2_hd_inflate_change_table_size(&inflater, 0)); + assert_int(0, ==, nghttp2_hd_inflate_change_table_size(&inflater, 3000)); + assert_int(0, ==, nghttp2_hd_deflate_change_table_size(&deflater, 0)); + assert_int(0, ==, nghttp2_hd_deflate_change_table_size(&deflater, 3000)); - CU_ASSERT(0 == deflater.min_hd_table_bufsize_max); - CU_ASSERT(3000 == deflater.ctx.hd_table_bufsize_max); + assert_size(0, ==, deflater.min_hd_table_bufsize_max); + assert_size(3000, ==, deflater.ctx.hd_table_bufsize_max); rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva2, 1); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(3 < blocklen); - CU_ASSERT(3000 == deflater.ctx.hd_table_bufsize_max); - CU_ASSERT(UINT32_MAX == deflater.min_hd_table_bufsize_max); + assert_int(0, ==, rv); + assert_ptrdiff(3, <, blocklen); + assert_size(3000, ==, deflater.ctx.hd_table_bufsize_max); + assert_size(UINT32_MAX, ==, deflater.min_hd_table_bufsize_max); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(3000 == inflater.ctx.hd_table_bufsize_max); - CU_ASSERT(3000 == inflater.settings_hd_table_bufsize_max); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_size(3000, ==, inflater.ctx.hd_table_bufsize_max); + assert_size(3000, ==, inflater.settings_hd_table_bufsize_max); nva_out_reset(&out, mem); nghttp2_bufs_reset(&bufs); @@ -977,7 +1024,7 @@ static void check_deflate_inflate(nghttp2_hd_deflater *deflater, nghttp2_nv *nva, size_t nvlen, nghttp2_mem *mem) { nghttp2_bufs bufs; - ssize_t blocklen; + nghttp2_ssize blocklen; nva_out out; int rv; @@ -985,14 +1032,14 @@ static void check_deflate_inflate(nghttp2_hd_deflater *deflater, nva_out_init(&out); rv = nghttp2_hd_deflate_hd_bufs(deflater, &bufs, nva, nvlen); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen >= 0); + assert_int(0, ==, rv); + assert_ptrdiff(0, <=, blocklen); - CU_ASSERT(blocklen == inflate_hd(inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(blocklen, ==, inflate_hd(inflater, &out, &bufs, 0, mem)); - CU_ASSERT(nvlen == out.nvlen); + assert_size(nvlen, ==, out.nvlen); assert_nv_equal(nva, out.nva, nvlen, mem); nva_out_reset(&out, mem); @@ -1161,7 +1208,7 @@ void test_nghttp2_hd_no_index(void) { nghttp2_hd_deflater deflater; nghttp2_hd_inflater inflater; nghttp2_bufs bufs; - ssize_t blocklen; + nghttp2_ssize blocklen; nghttp2_nv nva[] = { MAKE_NV(":method", "GET"), MAKE_NV(":method", "POST"), MAKE_NV(":path", "/foo"), MAKE_NV("version", "HTTP/1.1"), @@ -1187,18 +1234,18 @@ void test_nghttp2_hd_no_index(void) { nghttp2_hd_inflate_init(&inflater, mem); rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, ARRLEN(nva)); - blocklen = (ssize_t)nghttp2_bufs_len(&bufs); + blocklen = (nghttp2_ssize)nghttp2_bufs_len(&bufs); - CU_ASSERT(0 == rv); - CU_ASSERT(blocklen > 0); - CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem)); + assert_int(0, ==, rv); + assert_ptrdiff(0, <, blocklen); + assert_ptrdiff(blocklen, ==, inflate_hd(&inflater, &out, &bufs, 0, mem)); - CU_ASSERT(ARRLEN(nva) == out.nvlen); + assert_size(ARRLEN(nva), ==, out.nvlen); assert_nv_equal(nva, out.nva, ARRLEN(nva), mem); - CU_ASSERT(out.nva[0].flags == NGHTTP2_NV_FLAG_NONE); + assert_uint8(NGHTTP2_NV_FLAG_NONE, ==, out.nva[0].flags); for (i = 1; i < ARRLEN(nva); ++i) { - CU_ASSERT(out.nva[i].flags == NGHTTP2_NV_FLAG_NO_INDEX); + assert_uint8(NGHTTP2_NV_FLAG_NO_INDEX, ==, out.nva[i].flags); } nva_out_reset(&out, mem); @@ -1222,17 +1269,17 @@ void test_nghttp2_hd_deflate_bound(void) { bound = nghttp2_hd_deflate_bound(&deflater, nva, ARRLEN(nva)); - CU_ASSERT(12 + 6 * 2 * 2 + nva[0].namelen + nva[0].valuelen + nva[1].namelen + - nva[1].valuelen == - bound); + assert_size(12 + 6 * 2 * 2 + nva[0].namelen + nva[0].valuelen + + nva[1].namelen + nva[1].valuelen, + ==, bound); nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, ARRLEN(nva)); - CU_ASSERT(bound > (size_t)nghttp2_bufs_len(&bufs)); + assert_size((size_t)nghttp2_bufs_len(&bufs), <, bound); bound2 = nghttp2_hd_deflate_bound(&deflater, nva, ARRLEN(nva)); - CU_ASSERT(bound == bound2); + assert_size(bound, ==, bound2); nghttp2_bufs_free(&bufs); nghttp2_hd_deflate_free(&deflater); @@ -1244,25 +1291,25 @@ void test_nghttp2_hd_public_api(void) { nghttp2_nv nva[] = {MAKE_NV("alpha", "bravo"), MAKE_NV("charlie", "delta")}; uint8_t buf[4096]; size_t buflen; - ssize_t blocklen; + nghttp2_ssize blocklen; nghttp2_bufs bufs; nghttp2_mem *mem; mem = nghttp2_mem_default(); - CU_ASSERT(0 == nghttp2_hd_deflate_new(&deflater, 4096)); - CU_ASSERT(0 == nghttp2_hd_inflate_new(&inflater)); + assert_int(0, ==, nghttp2_hd_deflate_new(&deflater, 4096)); + assert_int(0, ==, nghttp2_hd_inflate_new(&inflater)); buflen = nghttp2_hd_deflate_bound(deflater, nva, ARRLEN(nva)); - blocklen = nghttp2_hd_deflate_hd(deflater, buf, buflen, nva, ARRLEN(nva)); + blocklen = nghttp2_hd_deflate_hd2(deflater, buf, buflen, nva, ARRLEN(nva)); - CU_ASSERT(blocklen > 0); + assert_ptrdiff(0, <, blocklen); nghttp2_bufs_wrap_init(&bufs, buf, (size_t)blocklen, mem); bufs.head->buf.last += blocklen; - CU_ASSERT(blocklen == inflate_hd(inflater, NULL, &bufs, 0, mem)); + assert_ptrdiff(blocklen, ==, inflate_hd(inflater, NULL, &bufs, 0, mem)); nghttp2_bufs_wrap_free(&bufs); @@ -1270,12 +1317,12 @@ void test_nghttp2_hd_public_api(void) { nghttp2_hd_deflate_del(deflater); /* See NGHTTP2_ERR_INSUFF_BUFSIZE */ - CU_ASSERT(0 == nghttp2_hd_deflate_new(&deflater, 4096)); + assert_int(0, ==, nghttp2_hd_deflate_new(&deflater, 4096)); - blocklen = nghttp2_hd_deflate_hd(deflater, buf, (size_t)(blocklen - 1), nva, - ARRLEN(nva)); + blocklen = nghttp2_hd_deflate_hd2(deflater, buf, (size_t)(blocklen - 1), nva, + ARRLEN(nva)); - CU_ASSERT(NGHTTP2_ERR_INSUFF_BUFSIZE == blocklen); + assert_ptrdiff(NGHTTP2_ERR_INSUFF_BUFSIZE, ==, blocklen); nghttp2_hd_deflate_del(deflater); } @@ -1292,7 +1339,7 @@ void test_nghttp2_hd_deflate_hd_vec(void) { MAKE_NV("content-length", "1000000007"), }; uint8_t buf[4096]; - ssize_t blocklen; + nghttp2_ssize blocklen; nghttp2_mem *mem; nghttp2_vec vec[256]; size_t buflen; @@ -1314,16 +1361,16 @@ void test_nghttp2_hd_deflate_hd_vec(void) { vec[1].base = &buf[buflen / 2]; vec[1].len = buflen / 2; - blocklen = nghttp2_hd_deflate_hd_vec(deflater, vec, 2, nva, ARRLEN(nva)); + blocklen = nghttp2_hd_deflate_hd_vec2(deflater, vec, 2, nva, ARRLEN(nva)); - CU_ASSERT(blocklen > 0); + assert_ptrdiff(0, <, blocklen); nghttp2_bufs_wrap_init(&bufs, buf, (size_t)blocklen, mem); bufs.head->buf.last += blocklen; - CU_ASSERT(blocklen == inflate_hd(inflater, &out, &bufs, 0, mem)); + assert_ptrdiff(blocklen, ==, inflate_hd(inflater, &out, &bufs, 0, mem)); - CU_ASSERT(ARRLEN(nva) == out.nvlen); + assert_size(ARRLEN(nva), ==, out.nvlen); assert_nv_equal(nva, out.nva, ARRLEN(nva), mem); nghttp2_bufs_wrap_free(&bufs); @@ -1336,9 +1383,9 @@ void test_nghttp2_hd_deflate_hd_vec(void) { nghttp2_hd_deflate_new(&deflater, 4096); nghttp2_hd_inflate_new(&inflater); - blocklen = nghttp2_hd_deflate_hd_vec(deflater, NULL, 0, nva, ARRLEN(nva)); + blocklen = nghttp2_hd_deflate_hd_vec2(deflater, NULL, 0, nva, ARRLEN(nva)); - CU_ASSERT(NGHTTP2_ERR_INSUFF_BUFSIZE == blocklen); + assert_ptrdiff(NGHTTP2_ERR_INSUFF_BUFSIZE, ==, blocklen); nghttp2_hd_inflate_del(inflater); nghttp2_hd_deflate_del(deflater); @@ -1352,9 +1399,9 @@ void test_nghttp2_hd_deflate_hd_vec(void) { nghttp2_hd_deflate_new(&deflater, 4096); nghttp2_hd_inflate_new(&inflater); - blocklen = nghttp2_hd_deflate_hd_vec(deflater, vec, 2, nva, ARRLEN(nva)); + blocklen = nghttp2_hd_deflate_hd_vec2(deflater, vec, 2, nva, ARRLEN(nva)); - CU_ASSERT(NGHTTP2_ERR_INSUFF_BUFSIZE == blocklen); + assert_ptrdiff(NGHTTP2_ERR_INSUFF_BUFSIZE, ==, blocklen); nghttp2_hd_inflate_del(inflater); nghttp2_hd_deflate_del(deflater); @@ -1370,15 +1417,15 @@ void test_nghttp2_hd_deflate_hd_vec(void) { vec[1].base = &buf[buflen / 2]; vec[1].len = (buflen / 2) + 1; - blocklen = nghttp2_hd_deflate_hd_vec(deflater, vec, 2, nva, ARRLEN(nva)); + blocklen = nghttp2_hd_deflate_hd_vec2(deflater, vec, 2, nva, ARRLEN(nva)); - CU_ASSERT(blocklen > 0); + assert_ptrdiff(0, <, blocklen); nghttp2_bufs_wrap_init(&bufs, buf, (size_t)blocklen, mem); bufs.head->buf.last += blocklen; - CU_ASSERT(blocklen == inflate_hd(inflater, &out, &bufs, 0, mem)); - CU_ASSERT(ARRLEN(nva) == out.nvlen); + assert_ptrdiff(blocklen, ==, inflate_hd(inflater, &out, &bufs, 0, mem)); + assert_size(ARRLEN(nva), ==, out.nvlen); assert_nv_equal(nva, out.nva, ARRLEN(nva), mem); nghttp2_bufs_wrap_free(&bufs); @@ -1400,15 +1447,16 @@ void test_nghttp2_hd_deflate_hd_vec(void) { vec[i].len = 1; } - blocklen = nghttp2_hd_deflate_hd_vec(deflater, vec, buflen, nva, ARRLEN(nva)); + blocklen = + nghttp2_hd_deflate_hd_vec2(deflater, vec, buflen, nva, ARRLEN(nva)); - CU_ASSERT(blocklen > 0); + assert_ptrdiff(0, <, blocklen); nghttp2_bufs_wrap_init(&bufs, buf, (size_t)blocklen, mem); bufs.head->buf.last += blocklen; - CU_ASSERT(blocklen == inflate_hd(inflater, &out, &bufs, 0, mem)); - CU_ASSERT(ARRLEN(nva) == out.nvlen); + assert_ptrdiff(blocklen, ==, inflate_hd(inflater, &out, &bufs, 0, mem)); + assert_size(ARRLEN(nva), ==, out.nvlen); assert_nv_equal(nva, out.nva, ARRLEN(nva), mem); nghttp2_bufs_wrap_free(&bufs); @@ -1453,7 +1501,7 @@ void test_nghttp2_hd_decode_length(void) { uint8_t buf[16]; uint8_t *bufp; size_t len; - ssize_t rv; + nghttp2_ssize rv; size_t i; memset(buf, 0, sizeof(buf)); @@ -1461,9 +1509,9 @@ void test_nghttp2_hd_decode_length(void) { rv = nghttp2_hd_decode_length(&out, &shift, &fin, 0, 0, buf, buf + len, 7); - CU_ASSERT((ssize_t)len == rv); - CU_ASSERT(0 != fin); - CU_ASSERT(UINT32_MAX == out); + assert_ptrdiff((nghttp2_ssize)len, ==, rv); + assert_true(fin); + assert_uint32(UINT32_MAX, ==, out); /* Make sure that we can decode integer if we feed 1 byte at a time */ @@ -1476,16 +1524,16 @@ void test_nghttp2_hd_decode_length(void) { rv = nghttp2_hd_decode_length(&out, &shift, &fin, out, shift, bufp, bufp + 1, 7); - CU_ASSERT(rv == 1); + assert_ptrdiff(1, ==, rv); if (fin) { break; } } - CU_ASSERT(i == len - 1); - CU_ASSERT(0 != fin); - CU_ASSERT(UINT32_MAX == out); + assert_size(len - 1, ==, i); + assert_true(fin); + assert_size(UINT32_MAX, ==, out); /* Check overflow case */ memset(buf, 0, sizeof(buf)); @@ -1493,7 +1541,7 @@ void test_nghttp2_hd_decode_length(void) { rv = nghttp2_hd_decode_length(&out, &shift, &fin, 0, 0, buf, buf + len, 7); - CU_ASSERT(-1 == rv); + assert_ptrdiff(-1, ==, rv); /* Check the case that shift goes beyond 32 bits */ buf[0] = 255; @@ -1506,12 +1554,12 @@ void test_nghttp2_hd_decode_length(void) { rv = nghttp2_hd_decode_length(&out, &shift, &fin, 0, 0, buf, buf + 7, 8); - CU_ASSERT(-1 == rv); + assert_ptrdiff(-1, ==, rv); } void test_nghttp2_hd_huff_encode(void) { int rv; - ssize_t len; + nghttp2_ssize len; nghttp2_buf outbuf; nghttp2_bufs bufs; nghttp2_hd_huff_decode_context ctx; @@ -1524,17 +1572,17 @@ void test_nghttp2_hd_huff_encode(void) { rv = nghttp2_hd_huff_encode(&bufs, t1, sizeof(t1)); - CU_ASSERT(rv == 0); + assert_int(0, ==, rv); nghttp2_hd_huff_decode_context_init(&ctx); len = nghttp2_hd_huff_decode(&ctx, &outbuf, bufs.cur->buf.pos, nghttp2_bufs_len(&bufs), 1); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == len); - CU_ASSERT((ssize_t)sizeof(t1) == nghttp2_buf_len(&outbuf)); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, len); + assert_size(sizeof(t1), ==, nghttp2_buf_len(&outbuf)); - CU_ASSERT(0 == memcmp(t1, outbuf.pos, sizeof(t1))); + assert_memory_equal(sizeof(t1), t1, outbuf.pos); nghttp2_bufs_free(&bufs); } @@ -1544,34 +1592,34 @@ void test_nghttp2_hd_huff_decode(void) { nghttp2_hd_huff_decode_context ctx; nghttp2_buf outbuf; uint8_t b[256]; - ssize_t len; + nghttp2_ssize len; nghttp2_buf_wrap_init(&outbuf, b, sizeof(b)); nghttp2_hd_huff_decode_context_init(&ctx); len = nghttp2_hd_huff_decode(&ctx, &outbuf, e, 1, 1); - CU_ASSERT(1 == len); - CU_ASSERT(0 == memcmp("a", outbuf.pos, 1)); + assert_ptrdiff(1, ==, len); + assert_memory_equal(1, "a", outbuf.pos); /* Premature sequence must elicit decoding error */ nghttp2_buf_wrap_init(&outbuf, b, sizeof(b)); nghttp2_hd_huff_decode_context_init(&ctx); len = nghttp2_hd_huff_decode(&ctx, &outbuf, e, 2, 1); - CU_ASSERT(NGHTTP2_ERR_HEADER_COMP == len); + assert_ptrdiff(NGHTTP2_ERR_HEADER_COMP, ==, len); /* Fully decoding EOS is error */ nghttp2_buf_wrap_init(&outbuf, b, sizeof(b)); nghttp2_hd_huff_decode_context_init(&ctx); len = nghttp2_hd_huff_decode(&ctx, &outbuf, e, 2, 6); - CU_ASSERT(NGHTTP2_ERR_HEADER_COMP == len); + assert_ptrdiff(NGHTTP2_ERR_HEADER_COMP, ==, len); /* Check failure state */ nghttp2_buf_wrap_init(&outbuf, b, sizeof(b)); nghttp2_hd_huff_decode_context_init(&ctx); len = nghttp2_hd_huff_decode(&ctx, &outbuf, e, 5, 0); - CU_ASSERT(5 == len); - CU_ASSERT(nghttp2_hd_huff_decode_failure_state(&ctx)); + assert_ptrdiff(5, ==, len); + assert_true(nghttp2_hd_huff_decode_failure_state(&ctx)); } diff --git a/tests/nghttp2_hd_test.h b/tests/nghttp2_hd_test.h index ab0117c..9d5ec8f 100644 --- a/tests/nghttp2_hd_test.h +++ b/tests/nghttp2_hd_test.h @@ -29,27 +29,33 @@ # include <config.h> #endif /* HAVE_CONFIG_H */ -void test_nghttp2_hd_deflate(void); -void test_nghttp2_hd_deflate_same_indexed_repr(void); -void test_nghttp2_hd_inflate_indexed(void); -void test_nghttp2_hd_inflate_indname_noinc(void); -void test_nghttp2_hd_inflate_indname_inc(void); -void test_nghttp2_hd_inflate_indname_inc_eviction(void); -void test_nghttp2_hd_inflate_newname_noinc(void); -void test_nghttp2_hd_inflate_newname_inc(void); -void test_nghttp2_hd_inflate_clearall_inc(void); -void test_nghttp2_hd_inflate_zero_length_huffman(void); -void test_nghttp2_hd_inflate_expect_table_size_update(void); -void test_nghttp2_hd_inflate_unexpected_table_size_update(void); -void test_nghttp2_hd_ringbuf_reserve(void); -void test_nghttp2_hd_change_table_size(void); -void test_nghttp2_hd_deflate_inflate(void); -void test_nghttp2_hd_no_index(void); -void test_nghttp2_hd_deflate_bound(void); -void test_nghttp2_hd_public_api(void); -void test_nghttp2_hd_deflate_hd_vec(void); -void test_nghttp2_hd_decode_length(void); -void test_nghttp2_hd_huff_encode(void); -void test_nghttp2_hd_huff_decode(void); +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + +extern const MunitSuite hd_suite; + +munit_void_test_decl(test_nghttp2_hd_deflate); +munit_void_test_decl(test_nghttp2_hd_deflate_same_indexed_repr); +munit_void_test_decl(test_nghttp2_hd_inflate_indexed); +munit_void_test_decl(test_nghttp2_hd_inflate_indname_noinc); +munit_void_test_decl(test_nghttp2_hd_inflate_indname_inc); +munit_void_test_decl(test_nghttp2_hd_inflate_indname_inc_eviction); +munit_void_test_decl(test_nghttp2_hd_inflate_newname_noinc); +munit_void_test_decl(test_nghttp2_hd_inflate_newname_inc); +munit_void_test_decl(test_nghttp2_hd_inflate_clearall_inc); +munit_void_test_decl(test_nghttp2_hd_inflate_zero_length_huffman); +munit_void_test_decl(test_nghttp2_hd_inflate_expect_table_size_update); +munit_void_test_decl(test_nghttp2_hd_inflate_unexpected_table_size_update); +munit_void_test_decl(test_nghttp2_hd_ringbuf_reserve); +munit_void_test_decl(test_nghttp2_hd_change_table_size); +munit_void_test_decl(test_nghttp2_hd_deflate_inflate); +munit_void_test_decl(test_nghttp2_hd_no_index); +munit_void_test_decl(test_nghttp2_hd_deflate_bound); +munit_void_test_decl(test_nghttp2_hd_public_api); +munit_void_test_decl(test_nghttp2_hd_deflate_hd_vec); +munit_void_test_decl(test_nghttp2_hd_decode_length); +munit_void_test_decl(test_nghttp2_hd_huff_encode); +munit_void_test_decl(test_nghttp2_hd_huff_decode); #endif /* NGHTTP2_HD_TEST_H */ diff --git a/tests/nghttp2_helper_test.c b/tests/nghttp2_helper_test.c index 377f49d..8c3f116 100644 --- a/tests/nghttp2_helper_test.c +++ b/tests/nghttp2_helper_test.c @@ -26,10 +26,22 @@ #include <stdio.h> -#include <CUnit/CUnit.h> +#include "munit.h" #include "nghttp2_helper.h" +static const MunitTest tests[] = { + munit_void_test(test_nghttp2_adjust_local_window_size), + munit_void_test(test_nghttp2_check_header_name), + munit_void_test(test_nghttp2_check_header_value), + munit_void_test(test_nghttp2_check_header_value_rfc9113), + munit_test_end(), +}; + +const MunitSuite helper_suite = { + "/helper", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_nghttp2_adjust_local_window_size(void) { int32_t local_window_size = 100; int32_t recv_window_size = 50; @@ -37,123 +49,132 @@ void test_nghttp2_adjust_local_window_size(void) { int32_t delta; delta = 0; - CU_ASSERT(0 == nghttp2_adjust_local_window_size(&local_window_size, - &recv_window_size, - &recv_reduction, &delta)); - CU_ASSERT(100 == local_window_size); - CU_ASSERT(50 == recv_window_size); - CU_ASSERT(0 == recv_reduction); - CU_ASSERT(0 == delta); + assert_int(0, ==, + nghttp2_adjust_local_window_size(&local_window_size, + &recv_window_size, + &recv_reduction, &delta)); + assert_int32(100, ==, local_window_size); + assert_int32(50, ==, recv_window_size); + assert_int32(0, ==, recv_reduction); + assert_int32(0, ==, delta); delta = 49; - CU_ASSERT(0 == nghttp2_adjust_local_window_size(&local_window_size, - &recv_window_size, - &recv_reduction, &delta)); - CU_ASSERT(100 == local_window_size); - CU_ASSERT(1 == recv_window_size); - CU_ASSERT(0 == recv_reduction); - CU_ASSERT(49 == delta); + assert_int(0, ==, + nghttp2_adjust_local_window_size(&local_window_size, + &recv_window_size, + &recv_reduction, &delta)); + assert_int32(100, ==, local_window_size); + assert_int32(1, ==, recv_window_size); + assert_int32(0, ==, recv_reduction); + assert_int32(49, ==, delta); delta = 1; - CU_ASSERT(0 == nghttp2_adjust_local_window_size(&local_window_size, - &recv_window_size, - &recv_reduction, &delta)); - CU_ASSERT(100 == local_window_size); - CU_ASSERT(0 == recv_window_size); - CU_ASSERT(0 == recv_reduction); - CU_ASSERT(1 == delta); + assert_int(0, ==, + nghttp2_adjust_local_window_size(&local_window_size, + &recv_window_size, + &recv_reduction, &delta)); + assert_int32(100, ==, local_window_size); + assert_int32(0, ==, recv_window_size); + assert_int32(0, ==, recv_reduction); + assert_int32(1, ==, delta); delta = 1; - CU_ASSERT(0 == nghttp2_adjust_local_window_size(&local_window_size, - &recv_window_size, - &recv_reduction, &delta)); - CU_ASSERT(101 == local_window_size); - CU_ASSERT(0 == recv_window_size); - CU_ASSERT(0 == recv_reduction); - CU_ASSERT(1 == delta); + assert_int(0, ==, + nghttp2_adjust_local_window_size(&local_window_size, + &recv_window_size, + &recv_reduction, &delta)); + assert_int32(101, ==, local_window_size); + assert_int32(0, ==, recv_window_size); + assert_int32(0, ==, recv_reduction); + assert_int32(1, ==, delta); delta = -1; - CU_ASSERT(0 == nghttp2_adjust_local_window_size(&local_window_size, - &recv_window_size, - &recv_reduction, &delta)); - CU_ASSERT(100 == local_window_size); - CU_ASSERT(-1 == recv_window_size); - CU_ASSERT(1 == recv_reduction); - CU_ASSERT(0 == delta); + assert_int(0, ==, + nghttp2_adjust_local_window_size(&local_window_size, + &recv_window_size, + &recv_reduction, &delta)); + assert_int32(100, ==, local_window_size); + assert_int32(-1, ==, recv_window_size); + assert_int32(1, ==, recv_reduction); + assert_int32(0, ==, delta); delta = 1; - CU_ASSERT(0 == nghttp2_adjust_local_window_size(&local_window_size, - &recv_window_size, - &recv_reduction, &delta)); - CU_ASSERT(101 == local_window_size); - CU_ASSERT(0 == recv_window_size); - CU_ASSERT(0 == recv_reduction); - CU_ASSERT(0 == delta); + assert_int(0, ==, + nghttp2_adjust_local_window_size(&local_window_size, + &recv_window_size, + &recv_reduction, &delta)); + assert_int32(101, ==, local_window_size); + assert_int32(0, ==, recv_window_size); + assert_int32(0, ==, recv_reduction); + assert_int32(0, ==, delta); delta = 100; - CU_ASSERT(0 == nghttp2_adjust_local_window_size(&local_window_size, - &recv_window_size, - &recv_reduction, &delta)); - CU_ASSERT(201 == local_window_size); - CU_ASSERT(0 == recv_window_size); - CU_ASSERT(0 == recv_reduction); - CU_ASSERT(100 == delta); + assert_int(0, ==, + nghttp2_adjust_local_window_size(&local_window_size, + &recv_window_size, + &recv_reduction, &delta)); + assert_int32(201, ==, local_window_size); + assert_int32(0, ==, recv_window_size); + assert_int32(0, ==, recv_reduction); + assert_int32(100, ==, delta); delta = -3; - CU_ASSERT(0 == nghttp2_adjust_local_window_size(&local_window_size, - &recv_window_size, - &recv_reduction, &delta)); - CU_ASSERT(198 == local_window_size); - CU_ASSERT(-3 == recv_window_size); - CU_ASSERT(3 == recv_reduction); - CU_ASSERT(0 == delta); + assert_int(0, ==, + nghttp2_adjust_local_window_size(&local_window_size, + &recv_window_size, + &recv_reduction, &delta)); + assert_int32(198, ==, local_window_size); + assert_int32(-3, ==, recv_window_size); + assert_int32(3, ==, recv_reduction); + assert_int32(0, ==, delta); recv_window_size += 3; delta = 3; - CU_ASSERT(0 == nghttp2_adjust_local_window_size(&local_window_size, - &recv_window_size, - &recv_reduction, &delta)); - CU_ASSERT(201 == local_window_size); - CU_ASSERT(3 == recv_window_size); - CU_ASSERT(0 == recv_reduction); - CU_ASSERT(0 == delta); + assert_int(0, ==, + nghttp2_adjust_local_window_size(&local_window_size, + &recv_window_size, + &recv_reduction, &delta)); + assert_int32(201, ==, local_window_size); + assert_int32(3, ==, recv_window_size); + assert_int32(0, ==, recv_reduction); + assert_int32(0, ==, delta); local_window_size = 100; recv_window_size = 50; recv_reduction = 0; delta = INT32_MAX; - CU_ASSERT(NGHTTP2_ERR_FLOW_CONTROL == - nghttp2_adjust_local_window_size(&local_window_size, - &recv_window_size, &recv_reduction, - &delta)); - CU_ASSERT(100 == local_window_size); - CU_ASSERT(50 == recv_window_size); - CU_ASSERT(0 == recv_reduction); - CU_ASSERT(INT32_MAX == delta); + assert_int(NGHTTP2_ERR_FLOW_CONTROL, ==, + nghttp2_adjust_local_window_size(&local_window_size, + &recv_window_size, + &recv_reduction, &delta)); + assert_int32(100, ==, local_window_size); + assert_int32(50, ==, recv_window_size); + assert_int32(0, ==, recv_reduction); + assert_int32(INT32_MAX, ==, delta); delta = INT32_MIN; - CU_ASSERT(NGHTTP2_ERR_FLOW_CONTROL == - nghttp2_adjust_local_window_size(&local_window_size, - &recv_window_size, &recv_reduction, - &delta)); - CU_ASSERT(100 == local_window_size); - CU_ASSERT(50 == recv_window_size); - CU_ASSERT(0 == recv_reduction); - CU_ASSERT(INT32_MIN == delta); + assert_int(NGHTTP2_ERR_FLOW_CONTROL, ==, + nghttp2_adjust_local_window_size(&local_window_size, + &recv_window_size, + &recv_reduction, &delta)); + assert_int32(100, ==, local_window_size); + assert_int32(50, ==, recv_window_size); + assert_int32(0, ==, recv_reduction); + assert_int32(INT32_MIN, ==, delta); } #define check_header_name(S) \ nghttp2_check_header_name((const uint8_t *)S, sizeof(S) - 1) void test_nghttp2_check_header_name(void) { - CU_ASSERT(check_header_name(":path")); - CU_ASSERT(check_header_name("path")); - CU_ASSERT(check_header_name("!#$%&'*+-.^_`|~")); - CU_ASSERT(!check_header_name(":PATH")); - CU_ASSERT(!check_header_name("path:")); - CU_ASSERT(!check_header_name("")); - CU_ASSERT(!check_header_name(":")); + assert_true(check_header_name(":path")); + assert_true(check_header_name("path")); + assert_true(check_header_name("!#$%&'*+-.^_`|~")); + assert_false(check_header_name(":PATH")); + assert_false(check_header_name("path:")); + assert_false(check_header_name("")); + assert_false(check_header_name(":")); } #define check_header_value(S) \ @@ -164,13 +185,13 @@ void test_nghttp2_check_header_value(void) { uint8_t badval1[] = {'a', 0x1fu, 'b'}; uint8_t badval2[] = {'a', 0x7fu, 'b'}; - CU_ASSERT(check_header_value(" !|}~")); - CU_ASSERT(check_header_value(goodval)); - CU_ASSERT(!check_header_value(badval1)); - CU_ASSERT(!check_header_value(badval2)); - CU_ASSERT(check_header_value("")); - CU_ASSERT(check_header_value(" ")); - CU_ASSERT(check_header_value("\t")); + assert_true(check_header_value(" !|}~")); + assert_true(check_header_value(goodval)); + assert_false(check_header_value(badval1)); + assert_false(check_header_value(badval2)); + assert_true(check_header_value("")); + assert_true(check_header_value(" ")); + assert_true(check_header_value("\t")); } #define check_header_value_rfc9113(S) \ @@ -181,15 +202,15 @@ void test_nghttp2_check_header_value_rfc9113(void) { uint8_t badval1[] = {'a', 0x1fu, 'b'}; uint8_t badval2[] = {'a', 0x7fu, 'b'}; - CU_ASSERT(check_header_value_rfc9113("!|}~")); - CU_ASSERT(!check_header_value_rfc9113(" !|}~")); - CU_ASSERT(!check_header_value_rfc9113("!|}~ ")); - CU_ASSERT(!check_header_value_rfc9113("\t!|}~")); - CU_ASSERT(!check_header_value_rfc9113("!|}~\t")); - CU_ASSERT(check_header_value_rfc9113(goodval)); - CU_ASSERT(!check_header_value_rfc9113(badval1)); - CU_ASSERT(!check_header_value_rfc9113(badval2)); - CU_ASSERT(check_header_value_rfc9113("")); - CU_ASSERT(!check_header_value_rfc9113(" ")); - CU_ASSERT(!check_header_value_rfc9113("\t")); + assert_true(check_header_value_rfc9113("!|}~")); + assert_false(check_header_value_rfc9113(" !|}~")); + assert_false(check_header_value_rfc9113("!|}~ ")); + assert_false(check_header_value_rfc9113("\t!|}~")); + assert_false(check_header_value_rfc9113("!|}~\t")); + assert_true(check_header_value_rfc9113(goodval)); + assert_false(check_header_value_rfc9113(badval1)); + assert_false(check_header_value_rfc9113(badval2)); + assert_true(check_header_value_rfc9113("")); + assert_false(check_header_value_rfc9113(" ")); + assert_false(check_header_value_rfc9113("\t")); } diff --git a/tests/nghttp2_helper_test.h b/tests/nghttp2_helper_test.h index 8790dcf..b81c7b3 100644 --- a/tests/nghttp2_helper_test.h +++ b/tests/nghttp2_helper_test.h @@ -29,9 +29,15 @@ # include <config.h> #endif /* HAVE_CONFIG_H */ -void test_nghttp2_adjust_local_window_size(void); -void test_nghttp2_check_header_name(void); -void test_nghttp2_check_header_value(void); -void test_nghttp2_check_header_value_rfc9113(void); +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + +extern const MunitSuite helper_suite; + +munit_void_test_decl(test_nghttp2_adjust_local_window_size); +munit_void_test_decl(test_nghttp2_check_header_name); +munit_void_test_decl(test_nghttp2_check_header_value); +munit_void_test_decl(test_nghttp2_check_header_value_rfc9113); #endif /* NGHTTP2_HELPER_TEST_H */ diff --git a/tests/nghttp2_http_test.c b/tests/nghttp2_http_test.c index 19f345b..86880d5 100644 --- a/tests/nghttp2_http_test.c +++ b/tests/nghttp2_http_test.c @@ -28,11 +28,20 @@ #include <stdio.h> #include <assert.h> -#include <CUnit/CUnit.h> +#include "munit.h" #include "nghttp2_http.h" #include "nghttp2_test_helper.h" +static const MunitTest tests[] = { + munit_void_test(test_nghttp2_http_parse_priority), + munit_test_end(), +}; + +const MunitSuite http_suite = { + "/http", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_nghttp2_http_parse_priority(void) { int rv; @@ -42,9 +51,9 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(0 == rv); - CU_ASSERT((uint32_t)-1 == pri.urgency); - CU_ASSERT(-1 == pri.inc); + assert_int(0, ==, rv); + assert_uint32((uint32_t)-1, ==, pri.urgency); + assert_int(-1, ==, pri.inc); } { @@ -53,9 +62,9 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(0 == rv); - CU_ASSERT((uint32_t)7 == pri.urgency); - CU_ASSERT(1 == pri.inc); + assert_int(0, ==, rv); + assert_uint32((uint32_t)7, ==, pri.urgency); + assert_int(1, ==, pri.inc); } { @@ -64,9 +73,9 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(0 == rv); - CU_ASSERT((uint32_t)0 == pri.urgency); - CU_ASSERT(0 == pri.inc); + assert_int(0, ==, rv); + assert_uint32((uint32_t)0, ==, pri.urgency); + assert_int(0, ==, pri.inc); } { @@ -75,9 +84,9 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(0 == rv); - CU_ASSERT((uint32_t)3 == pri.urgency); - CU_ASSERT(1 == pri.inc); + assert_int(0, ==, rv); + assert_uint32((uint32_t)3, ==, pri.urgency); + assert_int(1, ==, pri.inc); } { @@ -86,9 +95,9 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(0 == rv); - CU_ASSERT((uint32_t)6 == pri.urgency); - CU_ASSERT(0 == pri.inc); + assert_int(0, ==, rv); + assert_uint32((uint32_t)6, ==, pri.urgency); + assert_int(0, ==, pri.inc); } { @@ -97,7 +106,7 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); } { @@ -106,7 +115,7 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); } { @@ -115,7 +124,7 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); } { @@ -124,7 +133,7 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); } { @@ -133,9 +142,9 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(0 == rv); - CU_ASSERT((uint32_t)-1 == pri.urgency); - CU_ASSERT(1 == pri.inc); + assert_int(0, ==, rv); + assert_uint32((uint32_t)-1, ==, pri.urgency); + assert_int(1, ==, pri.inc); } { @@ -144,7 +153,7 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); } { @@ -153,7 +162,7 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); } { @@ -162,7 +171,7 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); } { @@ -171,7 +180,7 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); } { @@ -180,7 +189,7 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); } { @@ -190,9 +199,9 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v) - 1); - CU_ASSERT(0 == rv); - CU_ASSERT((uint32_t)2 == pri.urgency); - CU_ASSERT(1 == pri.inc); + assert_int(0, ==, rv); + assert_uint32((uint32_t)2, ==, pri.urgency); + assert_int(1, ==, pri.inc); } { @@ -201,6 +210,6 @@ void test_nghttp2_http_parse_priority(void) { rv = nghttp2_http_parse_priority(&pri, v, sizeof(v)); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); } } diff --git a/tests/nghttp2_http_test.h b/tests/nghttp2_http_test.h index e616cdc..b258905 100644 --- a/tests/nghttp2_http_test.h +++ b/tests/nghttp2_http_test.h @@ -30,6 +30,12 @@ # include <config.h> #endif /* HAVE_CONFIG_H */ -void test_nghttp2_http_parse_priority(void); +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + +extern const MunitSuite http_suite; + +munit_void_test_decl(test_nghttp2_http_parse_priority); #endif /* NGHTTP2_HTTP_TEST_H */ diff --git a/tests/nghttp2_map_test.c b/tests/nghttp2_map_test.c index 7ba9bd6..3b79b8a 100644 --- a/tests/nghttp2_map_test.c +++ b/tests/nghttp2_map_test.c @@ -27,10 +27,22 @@ #include <stdio.h> -#include <CUnit/CUnit.h> +#include "munit.h" #include "nghttp2_map.h" +static const MunitTest tests[] = { + munit_void_test(test_nghttp2_map), + munit_void_test(test_nghttp2_map_functional), + munit_void_test(test_nghttp2_map_each_free), + munit_void_test(test_nghttp2_map_clear), + munit_test_end(), +}; + +const MunitSuite map_suite = { + "/map", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + typedef struct strentry { nghttp2_map_key_type key; const char *str; @@ -53,43 +65,43 @@ void test_nghttp2_map(void) { strentry_init(&baz, 3, "baz"); strentry_init(&shrubbery, 4, "shrubbery"); - CU_ASSERT(0 == nghttp2_map_insert(&map, foo.key, &foo)); - CU_ASSERT(strcmp("foo", ((strentry *)nghttp2_map_find(&map, 1))->str) == 0); - CU_ASSERT(1 == nghttp2_map_size(&map)); + assert_int(0, ==, nghttp2_map_insert(&map, foo.key, &foo)); + assert_string_equal("foo", ((strentry *)nghttp2_map_find(&map, 1))->str); + assert_size(1, ==, nghttp2_map_size(&map)); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_map_insert(&map, FOO.key, &FOO)); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, + nghttp2_map_insert(&map, FOO.key, &FOO)); - CU_ASSERT(1 == nghttp2_map_size(&map)); - CU_ASSERT(strcmp("foo", ((strentry *)nghttp2_map_find(&map, 1))->str) == 0); + assert_size(1, ==, nghttp2_map_size(&map)); + assert_string_equal("foo", ((strentry *)nghttp2_map_find(&map, 1))->str); - CU_ASSERT(0 == nghttp2_map_insert(&map, bar.key, &bar)); - CU_ASSERT(2 == nghttp2_map_size(&map)); + assert_int(0, ==, nghttp2_map_insert(&map, bar.key, &bar)); + assert_size(2, ==, nghttp2_map_size(&map)); - CU_ASSERT(0 == nghttp2_map_insert(&map, baz.key, &baz)); - CU_ASSERT(3 == nghttp2_map_size(&map)); + assert_int(0, ==, nghttp2_map_insert(&map, baz.key, &baz)); + assert_size(3, ==, nghttp2_map_size(&map)); - CU_ASSERT(0 == nghttp2_map_insert(&map, shrubbery.key, &shrubbery)); - CU_ASSERT(4 == nghttp2_map_size(&map)); + assert_int(0, ==, nghttp2_map_insert(&map, shrubbery.key, &shrubbery)); + assert_size(4, ==, nghttp2_map_size(&map)); - CU_ASSERT(strcmp("baz", ((strentry *)nghttp2_map_find(&map, 3))->str) == 0); + assert_string_equal("baz", ((strentry *)nghttp2_map_find(&map, 3))->str); nghttp2_map_remove(&map, 3); - CU_ASSERT(3 == nghttp2_map_size(&map)); - CU_ASSERT(NULL == nghttp2_map_find(&map, 3)); + assert_size(3, ==, nghttp2_map_size(&map)); + assert_null(nghttp2_map_find(&map, 3)); nghttp2_map_remove(&map, 1); - CU_ASSERT(2 == nghttp2_map_size(&map)); - CU_ASSERT(NULL == nghttp2_map_find(&map, 1)); + assert_size(2, ==, nghttp2_map_size(&map)); + assert_null(nghttp2_map_find(&map, 1)); /* Erasing non-existent entry */ nghttp2_map_remove(&map, 1); - CU_ASSERT(2 == nghttp2_map_size(&map)); - CU_ASSERT(NULL == nghttp2_map_find(&map, 1)); + assert_size(2, ==, nghttp2_map_size(&map)); + assert_null(nghttp2_map_find(&map, 1)); - CU_ASSERT(strcmp("bar", ((strentry *)nghttp2_map_find(&map, 2))->str) == 0); - CU_ASSERT(strcmp("shrubbery", ((strentry *)nghttp2_map_find(&map, 4))->str) == - 0); + assert_string_equal("bar", ((strentry *)nghttp2_map_find(&map, 2))->str); + assert_string_equal("shrubbery", + ((strentry *)nghttp2_map_find(&map, 4))->str); nghttp2_map_free(&map); } @@ -129,21 +141,21 @@ void test_nghttp2_map_functional(void) { shuffle(order, NUM_ENT); for (i = 0; i < NUM_ENT; ++i) { ent = &arr[order[i] - 1]; - CU_ASSERT(0 == nghttp2_map_insert(&map, ent->key, ent)); + assert_int(0, ==, nghttp2_map_insert(&map, ent->key, ent)); } - CU_ASSERT(NUM_ENT == nghttp2_map_size(&map)); + assert_size(NUM_ENT, ==, nghttp2_map_size(&map)); /* traverse */ nghttp2_map_each(&map, eachfun, NULL); /* find */ shuffle(order, NUM_ENT); for (i = 0; i < NUM_ENT; ++i) { - CU_ASSERT(NULL != nghttp2_map_find(&map, (nghttp2_map_key_type)order[i])); + assert_not_null(nghttp2_map_find(&map, (nghttp2_map_key_type)order[i])); } /* remove */ for (i = 0; i < NUM_ENT; ++i) { - CU_ASSERT(0 == nghttp2_map_remove(&map, (nghttp2_map_key_type)order[i])); + assert_int(0, ==, nghttp2_map_remove(&map, (nghttp2_map_key_type)order[i])); } /* each_free (but no op function for testing purpose) */ @@ -153,7 +165,7 @@ void test_nghttp2_map_functional(void) { /* insert once again */ for (i = 0; i < NUM_ENT; ++i) { ent = &arr[i]; - CU_ASSERT(0 == nghttp2_map_insert(&map, ent->key, ent)); + assert_int(0, ==, nghttp2_map_insert(&map, ent->key, ent)); } nghttp2_map_each_free(&map, eachfun, NULL); nghttp2_map_free(&map); @@ -198,11 +210,11 @@ void test_nghttp2_map_clear(void) { nghttp2_map_init(&map, mem); - CU_ASSERT(0 == nghttp2_map_insert(&map, foo.key, &foo)); + assert_int(0, ==, nghttp2_map_insert(&map, foo.key, &foo)); nghttp2_map_clear(&map); - CU_ASSERT(0 == nghttp2_map_size(&map)); + assert_size(0, ==, nghttp2_map_size(&map)); nghttp2_map_free(&map); } diff --git a/tests/nghttp2_map_test.h b/tests/nghttp2_map_test.h index 235624d..ba06175 100644 --- a/tests/nghttp2_map_test.h +++ b/tests/nghttp2_map_test.h @@ -30,9 +30,15 @@ # include <config.h> #endif /* HAVE_CONFIG_H */ -void test_nghttp2_map(void); -void test_nghttp2_map_functional(void); -void test_nghttp2_map_each_free(void); -void test_nghttp2_map_clear(void); +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + +extern const MunitSuite map_suite; + +munit_void_test_decl(test_nghttp2_map); +munit_void_test_decl(test_nghttp2_map_functional); +munit_void_test_decl(test_nghttp2_map_each_free); +munit_void_test_decl(test_nghttp2_map_clear); #endif /* NGHTTP2_MAP_TEST_H */ diff --git a/tests/nghttp2_pq_test.c b/tests/nghttp2_pq_test.c index 90db26d..aa84af1 100644 --- a/tests/nghttp2_pq_test.c +++ b/tests/nghttp2_pq_test.c @@ -26,10 +26,19 @@ #include <stdio.h> -#include <CUnit/CUnit.h> - #include "nghttp2_pq.h" +static const MunitTest tests[] = { + munit_void_test(test_nghttp2_pq), + munit_void_test(test_nghttp2_pq_update), + munit_void_test(test_nghttp2_pq_remove), + munit_test_end(), +}; + +const MunitSuite pq_suite = { + "/pq", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + typedef struct { nghttp2_pq_entry ent; const char *s; @@ -59,59 +68,59 @@ void test_nghttp2_pq(void) { string_entry *top; nghttp2_pq_init(&pq, pq_less, nghttp2_mem_default()); - CU_ASSERT(nghttp2_pq_empty(&pq)); - CU_ASSERT(0 == nghttp2_pq_size(&pq)); - CU_ASSERT(0 == nghttp2_pq_push(&pq, &string_entry_new("foo")->ent)); - CU_ASSERT(0 == nghttp2_pq_empty(&pq)); - CU_ASSERT(1 == nghttp2_pq_size(&pq)); + assert_true(nghttp2_pq_empty(&pq)); + assert_size(0, ==, nghttp2_pq_size(&pq)); + assert_int(0, ==, nghttp2_pq_push(&pq, &string_entry_new("foo")->ent)); + assert_false(nghttp2_pq_empty(&pq)); + assert_size(1, ==, nghttp2_pq_size(&pq)); top = (string_entry *)nghttp2_pq_top(&pq); - CU_ASSERT(strcmp("foo", top->s) == 0); - CU_ASSERT(0 == nghttp2_pq_push(&pq, &string_entry_new("bar")->ent)); + assert_string_equal("foo", top->s); + assert_int(0, ==, nghttp2_pq_push(&pq, &string_entry_new("bar")->ent)); top = (string_entry *)nghttp2_pq_top(&pq); - CU_ASSERT(strcmp("bar", top->s) == 0); - CU_ASSERT(0 == nghttp2_pq_push(&pq, &string_entry_new("baz")->ent)); + assert_string_equal("bar", top->s); + assert_int(0, ==, nghttp2_pq_push(&pq, &string_entry_new("baz")->ent)); top = (string_entry *)nghttp2_pq_top(&pq); - CU_ASSERT(strcmp("bar", top->s) == 0); - CU_ASSERT(0 == nghttp2_pq_push(&pq, &string_entry_new("C")->ent)); - CU_ASSERT(4 == nghttp2_pq_size(&pq)); + assert_string_equal("bar", top->s); + assert_int(0, ==, nghttp2_pq_push(&pq, &string_entry_new("C")->ent)); + assert_size(4, ==, nghttp2_pq_size(&pq)); top = (string_entry *)nghttp2_pq_top(&pq); - CU_ASSERT(strcmp("C", top->s) == 0); + assert_string_equal("C", top->s); string_entry_del(top); nghttp2_pq_pop(&pq); - CU_ASSERT(3 == nghttp2_pq_size(&pq)); + assert_size(3, ==, nghttp2_pq_size(&pq)); top = (string_entry *)nghttp2_pq_top(&pq); - CU_ASSERT(strcmp("bar", top->s) == 0); + assert_string_equal("bar", top->s); nghttp2_pq_pop(&pq); string_entry_del(top); top = (string_entry *)nghttp2_pq_top(&pq); - CU_ASSERT(strcmp("baz", top->s) == 0); + assert_string_equal("baz", top->s); nghttp2_pq_pop(&pq); string_entry_del(top); top = (string_entry *)nghttp2_pq_top(&pq); - CU_ASSERT(strcmp("foo", top->s) == 0); + assert_string_equal("foo", top->s); nghttp2_pq_pop(&pq); string_entry_del(top); - CU_ASSERT(nghttp2_pq_empty(&pq)); - CU_ASSERT(0 == nghttp2_pq_size(&pq)); - CU_ASSERT(NULL == nghttp2_pq_top(&pq)); + assert_true(nghttp2_pq_empty(&pq)); + assert_size(0, ==, nghttp2_pq_size(&pq)); + assert_null(nghttp2_pq_top(&pq)); /* Add bunch of entry to see realloc works */ for (i = 0; i < 10000; ++i) { - CU_ASSERT(0 == nghttp2_pq_push(&pq, &string_entry_new("foo")->ent)); - CU_ASSERT((size_t)(i + 1) == nghttp2_pq_size(&pq)); + assert_int(0, ==, nghttp2_pq_push(&pq, &string_entry_new("foo")->ent)); + assert_size((size_t)(i + 1), ==, nghttp2_pq_size(&pq)); } for (i = 10000; i > 0; --i) { top = (string_entry *)nghttp2_pq_top(&pq); - CU_ASSERT(NULL != top); + assert_not_null(top); nghttp2_pq_pop(&pq); string_entry_del(top); - CU_ASSERT((size_t)(i - 1) == nghttp2_pq_size(&pq)); + assert_size((size_t)(i - 1), ==, nghttp2_pq_size(&pq)); } nghttp2_pq_free(&pq); @@ -160,7 +169,7 @@ void test_nghttp2_pq_update(void) { for (i = 0; i < (int)(sizeof(nodes) / sizeof(nodes[0])); ++i) { nd = (node *)nghttp2_pq_top(&pq); - CU_ASSERT(ans[i] == nd->key); + assert_int(ans[i], ==, nd->key); nghttp2_pq_pop(&pq); } @@ -180,8 +189,8 @@ static void check_nodes(nghttp2_pq *pq, size_t n, int *ans_key, int *ans_val) { size_t i; for (i = 0; i < n; ++i) { node *nd = (node *)nghttp2_pq_top(pq); - CU_ASSERT(ans_key[i] == nd->key); - CU_ASSERT(ans_val[i] == nd->val); + assert_int(ans_key[i], ==, nd->key); + assert_int(ans_val[i], ==, nd->val); nghttp2_pq_pop(pq); } } diff --git a/tests/nghttp2_pq_test.h b/tests/nghttp2_pq_test.h index 969662a..1386528 100644 --- a/tests/nghttp2_pq_test.h +++ b/tests/nghttp2_pq_test.h @@ -29,8 +29,14 @@ # include <config.h> #endif /* HAVE_CONFIG_H */ -void test_nghttp2_pq(void); -void test_nghttp2_pq_update(void); -void test_nghttp2_pq_remove(void); +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + +extern const MunitSuite pq_suite; + +munit_void_test_decl(test_nghttp2_pq); +munit_void_test_decl(test_nghttp2_pq_update); +munit_void_test_decl(test_nghttp2_pq_remove); #endif /* NGHTTP2_PQ_TEST_H */ diff --git a/tests/nghttp2_queue_test.c b/tests/nghttp2_queue_test.c index cb993a8..9837b61 100644 --- a/tests/nghttp2_queue_test.c +++ b/tests/nghttp2_queue_test.c @@ -26,25 +26,34 @@ #include <stdio.h> -#include <CUnit/CUnit.h> +#include "munit.h" #include "nghttp2_queue.h" +static const MunitTest tests[] = { + munit_void_test(test_nghttp2_queue), + munit_test_end(), +}; + +const MunitSuite queue_suite = { + "/queue", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_nghttp2_queue(void) { int ints[] = {1, 2, 3, 4, 5}; int i; nghttp2_queue queue; nghttp2_queue_init(&queue); - CU_ASSERT(nghttp2_queue_empty(&queue)); + assert_true(nghttp2_queue_empty(&queue)); for (i = 0; i < 5; ++i) { nghttp2_queue_push(&queue, &ints[i]); - CU_ASSERT_EQUAL(ints[0], *(int *)(nghttp2_queue_front(&queue))); - CU_ASSERT(!nghttp2_queue_empty(&queue)); + assert_int(ints[0], ==, *(int *)(nghttp2_queue_front(&queue))); + assert_false(nghttp2_queue_empty(&queue)); } for (i = 0; i < 5; ++i) { - CU_ASSERT_EQUAL(ints[i], *(int *)(nghttp2_queue_front(&queue))); + assert_int(ints[i], ==, *(int *)(nghttp2_queue_front(&queue))); nghttp2_queue_pop(&queue); } - CU_ASSERT(nghttp2_queue_empty(&queue)); + assert_true(nghttp2_queue_empty(&queue)); nghttp2_queue_free(&queue); } diff --git a/tests/nghttp2_queue_test.h b/tests/nghttp2_queue_test.h index 64f8ce8..ba33d38 100644 --- a/tests/nghttp2_queue_test.h +++ b/tests/nghttp2_queue_test.h @@ -29,6 +29,12 @@ # include <config.h> #endif /* HAVE_CONFIG_H */ -void test_nghttp2_queue(void); +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + +extern const MunitSuite queue_suite; + +munit_void_test_decl(test_nghttp2_queue); #endif /* NGHTTP2_QUEUE_TEST_H */ diff --git a/tests/nghttp2_ratelim_test.c b/tests/nghttp2_ratelim_test.c index 6abece9..5be2f22 100644 --- a/tests/nghttp2_ratelim_test.c +++ b/tests/nghttp2_ratelim_test.c @@ -26,67 +26,77 @@ #include <stdio.h> -#include <CUnit/CUnit.h> +#include "munit.h" #include "nghttp2_ratelim.h" +static const MunitTest tests[] = { + munit_void_test(test_nghttp2_ratelim_update), + munit_void_test(test_nghttp2_ratelim_drain), + munit_test_end(), +}; + +const MunitSuite ratelim_suite = { + "/ratelim", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + void test_nghttp2_ratelim_update(void) { nghttp2_ratelim rl; nghttp2_ratelim_init(&rl, 1000, 21); - CU_ASSERT(1000 == rl.val); - CU_ASSERT(1000 == rl.burst); - CU_ASSERT(21 == rl.rate); - CU_ASSERT(0 == rl.tstamp); + assert_uint64(1000, ==, rl.val); + assert_uint64(1000, ==, rl.burst); + assert_uint64(21, ==, rl.rate); + assert_uint64(0, ==, rl.tstamp); nghttp2_ratelim_update(&rl, 999); - CU_ASSERT(1000 == rl.val); - CU_ASSERT(999 == rl.tstamp); + assert_uint64(1000, ==, rl.val); + assert_uint64(999, ==, rl.tstamp); nghttp2_ratelim_drain(&rl, 100); - CU_ASSERT(900 == rl.val); + assert_uint64(900, ==, rl.val); nghttp2_ratelim_update(&rl, 1000); - CU_ASSERT(921 == rl.val); + assert_uint64(921, ==, rl.val); nghttp2_ratelim_update(&rl, 1002); - CU_ASSERT(963 == rl.val); + assert_uint64(963, ==, rl.val); nghttp2_ratelim_update(&rl, 1004); - CU_ASSERT(1000 == rl.val); - CU_ASSERT(1004 == rl.tstamp); + assert_uint64(1000, ==, rl.val); + assert_uint64(1004, ==, rl.tstamp); /* timer skew */ nghttp2_ratelim_init(&rl, 1000, 21); nghttp2_ratelim_update(&rl, 1); - CU_ASSERT(1000 == rl.val); + assert_uint64(1000, ==, rl.val); nghttp2_ratelim_update(&rl, 0); - CU_ASSERT(1000 == rl.val); + assert_uint64(1000, ==, rl.val); /* rate * duration overflow */ nghttp2_ratelim_init(&rl, 1000, 100); nghttp2_ratelim_drain(&rl, 999); - CU_ASSERT(1 == rl.val); + assert_uint64(1, ==, rl.val); nghttp2_ratelim_update(&rl, UINT64_MAX); - CU_ASSERT(1000 == rl.val); + assert_uint64(1000, ==, rl.val); /* val + rate * duration overflow */ nghttp2_ratelim_init(&rl, UINT64_MAX - 1, 2); nghttp2_ratelim_update(&rl, 1); - CU_ASSERT(UINT64_MAX - 1 == rl.val); + assert_uint64(UINT64_MAX - 1, ==, rl.val); } void test_nghttp2_ratelim_drain(void) { @@ -94,8 +104,8 @@ void test_nghttp2_ratelim_drain(void) { nghttp2_ratelim_init(&rl, 100, 7); - CU_ASSERT(-1 == nghttp2_ratelim_drain(&rl, 101)); - CU_ASSERT(0 == nghttp2_ratelim_drain(&rl, 51)); - CU_ASSERT(0 == nghttp2_ratelim_drain(&rl, 49)); - CU_ASSERT(-1 == nghttp2_ratelim_drain(&rl, 1)); + assert_int(-1, ==, nghttp2_ratelim_drain(&rl, 101)); + assert_int(0, ==, nghttp2_ratelim_drain(&rl, 51)); + assert_int(0, ==, nghttp2_ratelim_drain(&rl, 49)); + assert_int(-1, ==, nghttp2_ratelim_drain(&rl, 1)); } diff --git a/tests/nghttp2_ratelim_test.h b/tests/nghttp2_ratelim_test.h index 02b2f2b..fe10fe1 100644 --- a/tests/nghttp2_ratelim_test.h +++ b/tests/nghttp2_ratelim_test.h @@ -29,7 +29,13 @@ # include <config.h> #endif /* HAVE_CONFIG_H */ -void test_nghttp2_ratelim_update(void); -void test_nghttp2_ratelim_drain(void); +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + +extern const MunitSuite ratelim_suite; + +munit_void_test_decl(test_nghttp2_ratelim_update); +munit_void_test_decl(test_nghttp2_ratelim_drain); #endif /* NGHTTP2_RATELIM_TEST_H */ diff --git a/tests/nghttp2_session_test.c b/tests/nghttp2_session_test.c index 9f6a667..c155102 100644 --- a/tests/nghttp2_session_test.c +++ b/tests/nghttp2_session_test.c @@ -27,16 +27,179 @@ #include <stdio.h> #include <assert.h> -#include <CUnit/CUnit.h> +#include "munit.h" #include "nghttp2_session.h" #include "nghttp2_stream.h" #include "nghttp2_net.h" #include "nghttp2_helper.h" #include "nghttp2_test_helper.h" +#include "nghttp2_assertion.h" #include "nghttp2_priority_spec.h" #include "nghttp2_extpri.h" +static const MunitTest tests[] = { + munit_void_test(test_nghttp2_session_recv), + munit_void_test(test_nghttp2_session_recv_invalid_stream_id), + munit_void_test(test_nghttp2_session_recv_invalid_frame), + munit_void_test(test_nghttp2_session_recv_eof), + munit_void_test(test_nghttp2_session_recv_data), + munit_void_test(test_nghttp2_session_recv_data_no_auto_flow_control), + munit_void_test(test_nghttp2_session_recv_continuation), + munit_void_test(test_nghttp2_session_recv_headers_with_priority), + munit_void_test(test_nghttp2_session_recv_headers_with_padding), + munit_void_test(test_nghttp2_session_recv_headers_early_response), + munit_void_test(test_nghttp2_session_recv_headers_for_closed_stream), + munit_void_test(test_nghttp2_session_recv_headers_with_extpri), + munit_void_test(test_nghttp2_session_server_recv_push_response), + munit_void_test(test_nghttp2_session_recv_premature_headers), + munit_void_test(test_nghttp2_session_recv_unknown_frame), + munit_void_test(test_nghttp2_session_recv_unexpected_continuation), + munit_void_test(test_nghttp2_session_recv_settings_header_table_size), + munit_void_test(test_nghttp2_session_recv_too_large_frame_length), + munit_void_test(test_nghttp2_session_recv_extension), + munit_void_test(test_nghttp2_session_recv_altsvc), + munit_void_test(test_nghttp2_session_recv_origin), + munit_void_test(test_nghttp2_session_recv_priority_update), + munit_void_test(test_nghttp2_session_continue), + munit_void_test(test_nghttp2_session_add_frame), + munit_void_test(test_nghttp2_session_on_request_headers_received), + munit_void_test(test_nghttp2_session_on_response_headers_received), + munit_void_test(test_nghttp2_session_on_headers_received), + munit_void_test(test_nghttp2_session_on_push_response_headers_received), + munit_void_test(test_nghttp2_session_on_priority_received), + munit_void_test(test_nghttp2_session_on_rst_stream_received), + munit_void_test(test_nghttp2_session_on_settings_received), + munit_void_test(test_nghttp2_session_on_push_promise_received), + munit_void_test(test_nghttp2_session_on_ping_received), + munit_void_test(test_nghttp2_session_on_goaway_received), + munit_void_test(test_nghttp2_session_on_window_update_received), + munit_void_test(test_nghttp2_session_on_data_received), + munit_void_test(test_nghttp2_session_on_data_received_fail_fast), + munit_void_test(test_nghttp2_session_on_altsvc_received), + munit_void_test(test_nghttp2_session_send_headers_start_stream), + munit_void_test(test_nghttp2_session_send_headers_reply), + munit_void_test(test_nghttp2_session_send_headers_frame_size_error), + munit_void_test(test_nghttp2_session_send_headers_push_reply), + munit_void_test(test_nghttp2_session_send_rst_stream), + munit_void_test(test_nghttp2_session_send_push_promise), + munit_void_test(test_nghttp2_session_is_my_stream_id), + munit_void_test(test_nghttp2_session_upgrade2), + munit_void_test(test_nghttp2_session_reprioritize_stream), + munit_void_test( + test_nghttp2_session_reprioritize_stream_with_idle_stream_dep), + munit_void_test(test_nghttp2_submit_data), + munit_void_test(test_nghttp2_submit_data_read_length_too_large), + munit_void_test(test_nghttp2_submit_data_read_length_smallest), + munit_void_test(test_nghttp2_submit_data_twice), + munit_void_test(test_nghttp2_submit_request_with_data), + munit_void_test(test_nghttp2_submit_request_without_data), + munit_void_test(test_nghttp2_submit_response_with_data), + munit_void_test(test_nghttp2_submit_response_without_data), + munit_void_test(test_nghttp2_submit_response_push_response), + munit_void_test(test_nghttp2_submit_trailer), + munit_void_test(test_nghttp2_submit_headers_start_stream), + munit_void_test(test_nghttp2_submit_headers_reply), + munit_void_test(test_nghttp2_submit_headers_push_reply), + munit_void_test(test_nghttp2_submit_headers), + munit_void_test(test_nghttp2_submit_headers_continuation), + munit_void_test(test_nghttp2_submit_headers_continuation_extra_large), + munit_void_test(test_nghttp2_submit_priority), + munit_void_test(test_nghttp2_submit_settings), + munit_void_test(test_nghttp2_submit_settings_update_local_window_size), + munit_void_test(test_nghttp2_submit_settings_multiple_times), + munit_void_test(test_nghttp2_submit_push_promise), + munit_void_test(test_nghttp2_submit_window_update), + munit_void_test(test_nghttp2_submit_window_update_local_window_size), + munit_void_test(test_nghttp2_submit_shutdown_notice), + munit_void_test(test_nghttp2_submit_invalid_nv), + munit_void_test(test_nghttp2_submit_extension), + munit_void_test(test_nghttp2_submit_altsvc), + munit_void_test(test_nghttp2_submit_origin), + munit_void_test(test_nghttp2_submit_priority_update), + munit_void_test(test_nghttp2_submit_rst_stream), + munit_void_test(test_nghttp2_session_open_stream), + munit_void_test(test_nghttp2_session_open_stream_with_idle_stream_dep), + munit_void_test(test_nghttp2_session_get_next_ob_item), + munit_void_test(test_nghttp2_session_pop_next_ob_item), + munit_void_test(test_nghttp2_session_reply_fail), + munit_void_test(test_nghttp2_session_max_concurrent_streams), + munit_void_test(test_nghttp2_session_stop_data_with_rst_stream), + munit_void_test(test_nghttp2_session_defer_data), + munit_void_test(test_nghttp2_session_flow_control), + munit_void_test(test_nghttp2_session_flow_control_data_recv), + munit_void_test(test_nghttp2_session_flow_control_data_with_padding_recv), + munit_void_test(test_nghttp2_session_data_read_temporal_failure), + munit_void_test(test_nghttp2_session_on_stream_close), + munit_void_test(test_nghttp2_session_on_ctrl_not_send), + munit_void_test(test_nghttp2_session_get_outbound_queue_size), + munit_void_test(test_nghttp2_session_get_effective_local_window_size), + munit_void_test(test_nghttp2_session_set_option), + munit_void_test(test_nghttp2_session_data_backoff_by_high_pri_frame), + munit_void_test(test_nghttp2_session_pack_data_with_padding), + munit_void_test(test_nghttp2_session_pack_headers_with_padding), + munit_void_test(test_nghttp2_pack_settings_payload), + munit_void_test(test_nghttp2_session_stream_dep_add), + munit_void_test(test_nghttp2_session_stream_dep_remove), + munit_void_test(test_nghttp2_session_stream_dep_add_subtree), + munit_void_test(test_nghttp2_session_stream_dep_remove_subtree), + munit_void_test( + test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us), + munit_void_test(test_nghttp2_session_stream_attach_item), + munit_void_test(test_nghttp2_session_stream_attach_item_subtree), + munit_void_test(test_nghttp2_session_stream_get_state), + munit_void_test(test_nghttp2_session_stream_get_something), + munit_void_test(test_nghttp2_session_find_stream), + munit_void_test(test_nghttp2_session_keep_closed_stream), + munit_void_test(test_nghttp2_session_keep_idle_stream), + munit_void_test(test_nghttp2_session_detach_idle_stream), + munit_void_test(test_nghttp2_session_large_dep_tree), + munit_void_test(test_nghttp2_session_graceful_shutdown), + munit_void_test(test_nghttp2_session_on_header_temporal_failure), + munit_void_test(test_nghttp2_session_recv_client_magic), + munit_void_test(test_nghttp2_session_delete_data_item), + munit_void_test(test_nghttp2_session_open_idle_stream), + munit_void_test(test_nghttp2_session_cancel_reserved_remote), + munit_void_test(test_nghttp2_session_reset_pending_headers), + munit_void_test(test_nghttp2_session_send_data_callback), + munit_void_test(test_nghttp2_session_on_begin_headers_temporal_failure), + munit_void_test(test_nghttp2_session_defer_then_close), + munit_void_test(test_nghttp2_session_detach_item_from_closed_stream), + munit_void_test(test_nghttp2_session_flooding), + munit_void_test(test_nghttp2_session_change_stream_priority), + munit_void_test(test_nghttp2_session_change_extpri_stream_priority), + munit_void_test(test_nghttp2_session_create_idle_stream), + munit_void_test(test_nghttp2_session_repeated_priority_change), + munit_void_test(test_nghttp2_session_repeated_priority_submission), + munit_void_test(test_nghttp2_session_set_local_window_size), + munit_void_test(test_nghttp2_session_cancel_from_before_frame_send), + munit_void_test(test_nghttp2_session_too_many_settings), + munit_void_test(test_nghttp2_session_removed_closed_stream), + munit_void_test(test_nghttp2_session_pause_data), + munit_void_test(test_nghttp2_session_no_closed_streams), + munit_void_test(test_nghttp2_session_set_stream_user_data), + munit_void_test(test_nghttp2_session_no_rfc7540_priorities), + munit_void_test(test_nghttp2_session_server_fallback_rfc7540_priorities), + munit_void_test(test_nghttp2_session_stream_reset_ratelim), + munit_void_test(test_nghttp2_http_mandatory_headers), + munit_void_test(test_nghttp2_http_content_length), + munit_void_test(test_nghttp2_http_content_length_mismatch), + munit_void_test(test_nghttp2_http_non_final_response), + munit_void_test(test_nghttp2_http_trailer_headers), + munit_void_test(test_nghttp2_http_ignore_regular_header), + munit_void_test(test_nghttp2_http_ignore_content_length), + munit_void_test(test_nghttp2_http_record_request_method), + munit_void_test(test_nghttp2_http_push_promise), + munit_void_test(test_nghttp2_http_head_method_upgrade_workaround), + munit_void_test( + test_nghttp2_http_no_rfc9113_leading_and_trailing_ws_validation), + munit_test_end(), +}; + +const MunitSuite session_suite = { + "/session", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE, +}; + typedef struct { uint8_t buf[65535]; size_t length; @@ -121,18 +284,20 @@ static void scripted_data_feed_init2(scripted_data_feed *df, df->feedseq[0] = len; } -static ssize_t null_send_callback(nghttp2_session *session, const uint8_t *data, - size_t len, int flags, void *user_data) { +static nghttp2_ssize null_send_callback(nghttp2_session *session, + const uint8_t *data, size_t len, + int flags, void *user_data) { (void)session; (void)data; (void)flags; (void)user_data; - return (ssize_t)len; + return (nghttp2_ssize)len; } -static ssize_t fail_send_callback(nghttp2_session *session, const uint8_t *data, - size_t len, int flags, void *user_data) { +static nghttp2_ssize fail_send_callback(nghttp2_session *session, + const uint8_t *data, size_t len, + int flags, void *user_data) { (void)session; (void)data; (void)len; @@ -142,19 +307,20 @@ static ssize_t fail_send_callback(nghttp2_session *session, const uint8_t *data, return NGHTTP2_ERR_CALLBACK_FAILURE; } -static ssize_t fixed_bytes_send_callback(nghttp2_session *session, - const uint8_t *data, size_t len, - int flags, void *user_data) { +static nghttp2_ssize fixed_bytes_send_callback(nghttp2_session *session, + const uint8_t *data, size_t len, + int flags, void *user_data) { size_t fixed_sendlen = ((my_user_data *)user_data)->fixed_sendlen; (void)session; (void)data; (void)flags; - return (ssize_t)(fixed_sendlen < len ? fixed_sendlen : len); + return (nghttp2_ssize)(fixed_sendlen < len ? fixed_sendlen : len); } -static ssize_t scripted_recv_callback(nghttp2_session *session, uint8_t *data, - size_t len, int flags, void *user_data) { +static nghttp2_ssize scripted_recv_callback(nghttp2_session *session, + uint8_t *data, size_t len, + int flags, void *user_data) { scripted_data_feed *df = ((my_user_data *)user_data)->df; size_t wlen = df->feedseq[df->seqidx] > len ? len : df->feedseq[df->seqidx]; (void)session; @@ -166,11 +332,11 @@ static ssize_t scripted_recv_callback(nghttp2_session *session, uint8_t *data, if (df->feedseq[df->seqidx] == 0) { ++df->seqidx; } - return (ssize_t)wlen; + return (nghttp2_ssize)wlen; } -static ssize_t eof_recv_callback(nghttp2_session *session, uint8_t *data, - size_t len, int flags, void *user_data) { +static nghttp2_ssize eof_recv_callback(nghttp2_session *session, uint8_t *data, + size_t len, int flags, void *user_data) { (void)session; (void)data; (void)len; @@ -180,9 +346,9 @@ static ssize_t eof_recv_callback(nghttp2_session *session, uint8_t *data, return NGHTTP2_ERR_EOF; } -static ssize_t accumulator_send_callback(nghttp2_session *session, - const uint8_t *buf, size_t len, - int flags, void *user_data) { +static nghttp2_ssize accumulator_send_callback(nghttp2_session *session, + const uint8_t *buf, size_t len, + int flags, void *user_data) { accumulator *acc = ((my_user_data *)user_data)->acc; (void)session; (void)flags; @@ -190,7 +356,7 @@ static ssize_t accumulator_send_callback(nghttp2_session *session, assert(acc->length + len < sizeof(acc->buf)); memcpy(acc->buf + acc->length, buf, len); acc->length += len; - return (ssize_t)len; + return (nghttp2_ssize)len; } static int on_begin_frame_callback(nghttp2_session *session, @@ -290,16 +456,18 @@ static int pause_on_data_chunk_recv_callback(nghttp2_session *session, return NGHTTP2_ERR_PAUSE; } -static ssize_t select_padding_callback(nghttp2_session *session, - const nghttp2_frame *frame, - size_t max_payloadlen, void *user_data) { +static nghttp2_ssize select_padding_callback(nghttp2_session *session, + const nghttp2_frame *frame, + size_t max_payloadlen, + void *user_data) { my_user_data *ud = (my_user_data *)user_data; (void)session; - return (ssize_t)nghttp2_min(max_payloadlen, frame->hd.length + ud->padlen); + return (nghttp2_ssize)nghttp2_min(max_payloadlen, + frame->hd.length + ud->padlen); } -static ssize_t too_large_data_source_length_callback( +static nghttp2_ssize too_large_data_source_length_callback( nghttp2_session *session, uint8_t frame_type, int32_t stream_id, int32_t session_remote_window_size, int32_t stream_remote_window_size, uint32_t remote_max_frame_size, void *user_data) { @@ -314,7 +482,7 @@ static ssize_t too_large_data_source_length_callback( return NGHTTP2_MAX_FRAME_SIZE_MAX + 1; } -static ssize_t smallest_length_data_source_length_callback( +static nghttp2_ssize smallest_length_data_source_length_callback( nghttp2_session *session, uint8_t frame_type, int32_t stream_id, int32_t session_remote_window_size, int32_t stream_remote_window_size, uint32_t remote_max_frame_size, void *user_data) { @@ -329,7 +497,7 @@ static ssize_t smallest_length_data_source_length_callback( return 1; } -static ssize_t fixed_length_data_source_read_callback( +static nghttp2_ssize fixed_length_data_source_read_callback( nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t len, uint32_t *data_flags, nghttp2_data_source *source, void *user_data) { my_user_data *ud = (my_user_data *)user_data; @@ -348,10 +516,10 @@ static ssize_t fixed_length_data_source_read_callback( if (ud->data_source_length == 0) { *data_flags |= NGHTTP2_DATA_FLAG_EOF; } - return (ssize_t)wlen; + return (nghttp2_ssize)wlen; } -static ssize_t temporal_failure_data_source_read_callback( +static nghttp2_ssize temporal_failure_data_source_read_callback( nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t len, uint32_t *data_flags, nghttp2_data_source *source, void *user_data) { (void)session; @@ -365,11 +533,10 @@ static ssize_t temporal_failure_data_source_read_callback( return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; } -static ssize_t fail_data_source_read_callback(nghttp2_session *session, - int32_t stream_id, uint8_t *buf, - size_t len, uint32_t *data_flags, - nghttp2_data_source *source, - void *user_data) { +static nghttp2_ssize +fail_data_source_read_callback(nghttp2_session *session, int32_t stream_id, + uint8_t *buf, size_t len, uint32_t *data_flags, + nghttp2_data_source *source, void *user_data) { (void)session; (void)stream_id; (void)buf; @@ -381,7 +548,7 @@ static ssize_t fail_data_source_read_callback(nghttp2_session *session, return NGHTTP2_ERR_CALLBACK_FAILURE; } -static ssize_t no_end_stream_data_source_read_callback( +static nghttp2_ssize no_end_stream_data_source_read_callback( nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t len, uint32_t *data_flags, nghttp2_data_source *source, void *user_data) { (void)session; @@ -395,7 +562,7 @@ static ssize_t no_end_stream_data_source_read_callback( return 0; } -static ssize_t no_copy_data_source_read_callback( +static nghttp2_ssize no_copy_data_source_read_callback( nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t len, uint32_t *data_flags, nghttp2_data_source *source, void *user_data) { my_user_data *ud = (my_user_data *)user_data; @@ -418,7 +585,7 @@ static ssize_t no_copy_data_source_read_callback( if (ud->data_source_length == 0) { *data_flags |= NGHTTP2_DATA_FLAG_EOF; } - return (ssize_t)wlen; + return (nghttp2_ssize)wlen; } static int send_data_callback(nghttp2_session *session, nghttp2_frame *frame, @@ -444,9 +611,9 @@ static int send_data_callback(nghttp2_session *session, nghttp2_frame *frame, return 0; } -static ssize_t block_count_send_callback(nghttp2_session *session, - const uint8_t *data, size_t len, - int flags, void *user_data) { +static nghttp2_ssize block_count_send_callback(nghttp2_session *session, + const uint8_t *data, size_t len, + int flags, void *user_data) { my_user_data *ud = (my_user_data *)user_data; (void)session; (void)data; @@ -457,7 +624,7 @@ static ssize_t block_count_send_callback(nghttp2_session *session, } --ud->block_count; - return (ssize_t)len; + return (nghttp2_ssize)len; } static int on_header_callback(nghttp2_session *session, @@ -555,11 +722,10 @@ static int temporal_failure_on_begin_headers_callback( return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; } -static ssize_t defer_data_source_read_callback(nghttp2_session *session, - int32_t stream_id, uint8_t *buf, - size_t len, uint32_t *data_flags, - nghttp2_data_source *source, - void *user_data) { +static nghttp2_ssize +defer_data_source_read_callback(nghttp2_session *session, int32_t stream_id, + uint8_t *buf, size_t len, uint32_t *data_flags, + nghttp2_data_source *source, void *user_data) { (void)session; (void)stream_id; (void)buf; @@ -593,9 +759,10 @@ static int fatal_error_on_stream_close_callback(nghttp2_session *session, return NGHTTP2_ERR_CALLBACK_FAILURE; } -static ssize_t pack_extension_callback(nghttp2_session *session, uint8_t *buf, - size_t len, const nghttp2_frame *frame, - void *user_data) { +static nghttp2_ssize pack_extension_callback(nghttp2_session *session, + uint8_t *buf, size_t len, + const nghttp2_frame *frame, + void *user_data) { nghttp2_buf *p = frame->ext.payload; (void)session; (void)len; @@ -603,7 +770,7 @@ static ssize_t pack_extension_callback(nghttp2_session *session, uint8_t *buf, memcpy(buf, p->pos, nghttp2_buf_len(p)); - return (ssize_t)nghttp2_buf_len(p); + return (nghttp2_ssize)nghttp2_buf_len(p); } static int on_extension_chunk_recv_callback(nghttp2_session *session, @@ -686,8 +853,8 @@ void test_nghttp2_session_recv(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; - callbacks.recv_callback = scripted_recv_callback; + callbacks.send_callback2 = null_send_callback; + callbacks.recv_callback2 = scripted_recv_callback; callbacks.on_frame_recv_callback = on_frame_recv_callback; callbacks.on_begin_frame_callback = on_begin_frame_callback; @@ -702,7 +869,7 @@ void test_nghttp2_session_recv(void) { NGHTTP2_HCAT_HEADERS, NULL, nva, nvlen); rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); scripted_data_feed_init2(&df, &bufs); @@ -719,10 +886,10 @@ void test_nghttp2_session_recv(void) { user_data.begin_frame_cb_called = 0; while (df.seqidx < framelen) { - CU_ASSERT(0 == nghttp2_session_recv(session)); + assert_int(0, ==, nghttp2_session_recv(session)); } - CU_ASSERT(1 == user_data.frame_recv_cb_called); - CU_ASSERT(1 == user_data.begin_frame_cb_called); + assert_int(1, ==, user_data.frame_recv_cb_called); + assert_int(1, ==, user_data.begin_frame_cb_called); nghttp2_bufs_reset(&bufs); @@ -738,9 +905,9 @@ void test_nghttp2_session_recv(void) { user_data.frame_recv_cb_called = 0; user_data.begin_frame_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_recv(session)); - CU_ASSERT(1 == user_data.frame_recv_cb_called); - CU_ASSERT(1 == user_data.begin_frame_cb_called); + assert_int(0, ==, nghttp2_session_recv(session)); + assert_int(1, ==, user_data.frame_recv_cb_called); + assert_int(1, ==, user_data.begin_frame_cb_called); nghttp2_bufs_reset(&bufs); @@ -770,14 +937,14 @@ void test_nghttp2_session_recv(void) { user_data.frame_recv_cb_called = 0; user_data.begin_frame_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_recv(session)); - CU_ASSERT(0 == user_data.frame_recv_cb_called); - CU_ASSERT(0 == user_data.begin_frame_cb_called); + assert_int(0, ==, nghttp2_session_recv(session)); + assert_int(0, ==, user_data.frame_recv_cb_called); + assert_int(0, ==, user_data.begin_frame_cb_called); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); - CU_ASSERT(NGHTTP2_FRAME_SIZE_ERROR == item->frame.goaway.error_code); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_FRAME_SIZE_ERROR, ==, item->frame.goaway.error_code); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_bufs_free(&bufs); nghttp2_session_del(session); @@ -800,7 +967,7 @@ void test_nghttp2_session_recv_invalid_stream_id(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.recv_callback = scripted_recv_callback; + callbacks.recv_callback2 = scripted_recv_callback; callbacks.on_invalid_frame_recv_callback = on_invalid_frame_recv_callback; user_data.df = &df; @@ -814,14 +981,14 @@ void test_nghttp2_session_recv_invalid_stream_id(void) { NGHTTP2_HCAT_HEADERS, NULL, nva, nvlen); rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_int(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); scripted_data_feed_init2(&df, &bufs); nghttp2_frame_headers_free(&frame.headers, mem); - CU_ASSERT(0 == nghttp2_session_recv(session)); - CU_ASSERT(1 == user_data.invalid_frame_recv_cb_called); + assert_int(0, ==, nghttp2_session_recv(session)); + assert_int(1, ==, user_data.invalid_frame_recv_cb_called); nghttp2_bufs_free(&bufs); nghttp2_hd_deflate_free(&deflater); @@ -845,8 +1012,8 @@ void test_nghttp2_session_recv_invalid_frame(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.recv_callback = scripted_recv_callback; - callbacks.send_callback = null_send_callback; + callbacks.recv_callback2 = scripted_recv_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; user_data.df = &df; @@ -859,23 +1026,23 @@ void test_nghttp2_session_recv_invalid_frame(void) { NGHTTP2_HCAT_HEADERS, NULL, nva, nvlen); rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_int(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); scripted_data_feed_init2(&df, &bufs); - CU_ASSERT(0 == nghttp2_session_recv(session)); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == user_data.frame_send_cb_called); + assert_int(0, ==, nghttp2_session_recv(session)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(0, ==, user_data.frame_send_cb_called); /* Receive exactly same bytes of HEADERS is treated as error, because it has * pseudo headers and without END_STREAM flag set */ scripted_data_feed_init2(&df, &bufs); - CU_ASSERT(0 == nghttp2_session_recv(session)); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == user_data.frame_send_cb_called); - CU_ASSERT(NGHTTP2_RST_STREAM == user_data.sent_frame_type); + assert_int(0, ==, nghttp2_session_recv(session)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(1, ==, user_data.frame_send_cb_called); + assert_uint8(NGHTTP2_RST_STREAM, ==, user_data.sent_frame_type); nghttp2_bufs_free(&bufs); nghttp2_frame_headers_free(&frame.headers, mem); @@ -889,11 +1056,11 @@ void test_nghttp2_session_recv_eof(void) { nghttp2_session_callbacks callbacks; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; - callbacks.recv_callback = eof_recv_callback; + callbacks.send_callback2 = null_send_callback; + callbacks.recv_callback2 = eof_recv_callback; nghttp2_session_client_new(&session, &callbacks, NULL); - CU_ASSERT(NGHTTP2_ERR_EOF == nghttp2_session_recv(session)); + assert_int(NGHTTP2_ERR_EOF, ==, nghttp2_session_recv(session)); nghttp2_session_del(session); } @@ -903,14 +1070,14 @@ void test_nghttp2_session_recv_data(void) { nghttp2_session_callbacks callbacks; my_user_data ud; uint8_t data[8092]; - ssize_t rv; + nghttp2_ssize rv; nghttp2_outbound_item *item; nghttp2_stream *stream; nghttp2_frame_hd hd; int i; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_data_chunk_recv_callback = on_data_chunk_recv_callback; callbacks.on_frame_recv_callback = on_frame_recv_callback; callbacks.on_frame_send_callback = on_frame_send_callback; @@ -929,13 +1096,13 @@ void test_nghttp2_session_recv_data(void) { error. This is not mandated by the spec */ ud.data_chunk_recv_cb_called = 0; ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + 4096); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 4096 == rv); + rv = nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + 4096); + assert_ptrdiff(NGHTTP2_FRAME_HDLEN + 4096, ==, rv); - CU_ASSERT(0 == ud.data_chunk_recv_cb_called); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_int(0, ==, ud.data_chunk_recv_cb_called); + assert_int(0, ==, ud.frame_recv_cb_called); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); nghttp2_session_del(session); @@ -950,40 +1117,40 @@ void test_nghttp2_session_recv_data(void) { ud.data_chunk_recv_cb_called = 0; ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + 4096); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 4096 == rv); + rv = nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + 4096); + assert_ptrdiff(NGHTTP2_FRAME_HDLEN + 4096, ==, rv); - CU_ASSERT(0 == ud.data_chunk_recv_cb_called); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_int(0, ==, ud.data_chunk_recv_cb_called); + assert_int(0, ==, ud.frame_recv_cb_called); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL == item); + assert_null(item); /* This is normal case. DATA is acceptable. */ stream->state = NGHTTP2_STREAM_OPENED; ud.data_chunk_recv_cb_called = 0; ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + 4096); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 4096 == rv); + rv = nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + 4096); + assert_ptrdiff(NGHTTP2_FRAME_HDLEN + 4096, ==, rv); - CU_ASSERT(1 == ud.data_chunk_recv_cb_called); - CU_ASSERT(1 == ud.frame_recv_cb_called); + assert_int(1, ==, ud.data_chunk_recv_cb_called); + assert_int(1, ==, ud.frame_recv_cb_called); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_null(nghttp2_session_get_next_ob_item(session)); ud.data_chunk_recv_cb_called = 0; ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + 4096); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 4096 == rv); + rv = nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + 4096); + assert_ptrdiff(NGHTTP2_FRAME_HDLEN + 4096, ==, rv); /* Now we got data more than initial-window-size / 2, WINDOW_UPDATE must be queued */ - CU_ASSERT(1 == ud.data_chunk_recv_cb_called); - CU_ASSERT(1 == ud.frame_recv_cb_called); + assert_int(1, ==, ud.data_chunk_recv_cb_called); + assert_int(1, ==, ud.frame_recv_cb_called); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); - CU_ASSERT(1 == item->frame.window_update.hd.stream_id); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_uint8(NGHTTP2_WINDOW_UPDATE, ==, item->frame.hd.type); + assert_int32(1, ==, item->frame.window_update.hd.stream_id); + assert_int(0, ==, nghttp2_session_send(session)); /* Set initial window size to 1MiB, so that we can check connection flow control individually */ @@ -993,13 +1160,13 @@ void test_nghttp2_session_recv_data(void) { DATA. Additional 4 DATA frames, connection flow control will kick in. */ for (i = 0; i < 5; ++i) { - rv = nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + 4096); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 4096 == rv); + rv = nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + 4096); + assert_ptrdiff(NGHTTP2_FRAME_HDLEN + 4096, ==, rv); } item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); - CU_ASSERT(0 == item->frame.window_update.hd.stream_id); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_uint8(NGHTTP2_WINDOW_UPDATE, ==, item->frame.hd.type); + assert_int32(0, ==, item->frame.window_update.hd.stream_id); + assert_int(0, ==, nghttp2_session_send(session)); /* Reception of DATA with stream ID = 0 causes connection error */ hd.length = 4096; @@ -1010,14 +1177,14 @@ void test_nghttp2_session_recv_data(void) { ud.data_chunk_recv_cb_called = 0; ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + 4096); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 4096 == rv); + rv = nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + 4096); + assert_ptrdiff(NGHTTP2_FRAME_HDLEN + 4096, ==, rv); - CU_ASSERT(0 == ud.data_chunk_recv_cb_called); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_int(0, ==, ud.data_chunk_recv_cb_called); + assert_int(0, ==, ud.frame_recv_cb_called); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); - CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == item->frame.goaway.error_code); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_PROTOCOL_ERROR, ==, item->frame.goaway.error_code); nghttp2_session_del(session); @@ -1036,20 +1203,20 @@ void test_nghttp2_session_recv_data(void) { it triggers first WINDOW_UPDATE of window_size_increment 32767. */ for (i = 0; i < 7; ++i) { - rv = nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + 4096); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 4096 == rv); + rv = nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + 4096); + assert_ptrdiff(NGHTTP2_FRAME_HDLEN + 4096, ==, rv); } hd.length = 4095; nghttp2_frame_pack_frame_hd(data, &hd); - rv = nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + 4095); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 4095 == rv); + rv = nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + 4095); + assert_ptrdiff(NGHTTP2_FRAME_HDLEN + 4095, ==, rv); /* Now 2 WINDOW_UPDATEs for session and stream should be queued. */ - CU_ASSERT(0 == stream->recv_window_size); - CU_ASSERT(0 == session->recv_window_size); - CU_ASSERT(1 == stream->window_update_queued); - CU_ASSERT(1 == session->window_update_queued); + assert_int32(0, ==, stream->recv_window_size); + assert_int32(0, ==, session->recv_window_size); + assert_true(stream->window_update_queued); + assert_true(session->window_update_queued); /* Then send 32768 bytes of DATA. Since we have not sent queued WINDOW_UDPATE frame, recv_window_size should not be decreased */ @@ -1057,29 +1224,29 @@ void test_nghttp2_session_recv_data(void) { nghttp2_frame_pack_frame_hd(data, &hd); for (i = 0; i < 8; ++i) { - rv = nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + 4096); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 4096 == rv); + rv = nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + 4096); + assert_ptrdiff(NGHTTP2_FRAME_HDLEN + 4096, ==, rv); } /* WINDOW_UPDATE is blocked for session and stream, so recv_window_size must not be decreased. */ - CU_ASSERT(32768 == stream->recv_window_size); - CU_ASSERT(32768 == session->recv_window_size); - CU_ASSERT(1 == stream->window_update_queued); - CU_ASSERT(1 == session->window_update_queued); + assert_int32(32768, ==, stream->recv_window_size); + assert_int32(32768, ==, session->recv_window_size); + assert_true(stream->window_update_queued); + assert_true(session->window_update_queued); ud.frame_send_cb_called = 0; /* This sends queued WINDOW_UPDATES. And then check recv_window_size, and queue WINDOW_UPDATEs for both session and stream, and send them at once. */ - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); - CU_ASSERT(4 == ud.frame_send_cb_called); - CU_ASSERT(0 == stream->recv_window_size); - CU_ASSERT(0 == session->recv_window_size); - CU_ASSERT(0 == stream->window_update_queued); - CU_ASSERT(0 == session->window_update_queued); + assert_int(4, ==, ud.frame_send_cb_called); + assert_int32(0, ==, stream->recv_window_size); + assert_int32(0, ==, session->recv_window_size); + assert_false(stream->window_update_queued); + assert_false(session->window_update_queued); nghttp2_session_del(session); } @@ -1092,13 +1259,13 @@ void test_nghttp2_session_recv_data_no_auto_flow_control(void) { nghttp2_frame_hd hd; size_t padlen; uint8_t data[8192]; - ssize_t rv; + nghttp2_ssize rv; size_t sendlen; nghttp2_stream *stream; size_t i; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; nghttp2_option_new(&option); @@ -1122,11 +1289,11 @@ void test_nghttp2_session_recv_data_no_auto_flow_control(void) { /* Receive first 100 bytes */ sendlen = 100; - rv = nghttp2_session_mem_recv(session, data, sendlen); - CU_ASSERT((ssize_t)sendlen == rv); + rv = nghttp2_session_mem_recv2(session, data, sendlen); + assert_ptrdiff((nghttp2_ssize)sendlen, ==, rv); /* We consumed pad length field (1 byte) */ - CU_ASSERT(1 == session->consumed_size); + assert_int32(1, ==, session->consumed_size); /* close stream here */ nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, 1, NGHTTP2_NO_ERROR); @@ -1134,13 +1301,14 @@ void test_nghttp2_session_recv_data_no_auto_flow_control(void) { /* stream 1 has been closed, and we disabled auto flow-control, so data must be immediately consumed for connection. */ - rv = nghttp2_session_mem_recv(session, data + sendlen, - NGHTTP2_FRAME_HDLEN + hd.length - sendlen); - CU_ASSERT((ssize_t)(NGHTTP2_FRAME_HDLEN + hd.length - sendlen) == rv); + rv = nghttp2_session_mem_recv2(session, data + sendlen, + NGHTTP2_FRAME_HDLEN + hd.length - sendlen); + assert_ptrdiff((nghttp2_ssize)(NGHTTP2_FRAME_HDLEN + hd.length - sendlen), ==, + rv); /* We already consumed pad length field (1 byte), so do +1 here */ - CU_ASSERT((int32_t)(NGHTTP2_FRAME_HDLEN + hd.length - sendlen + 1) == - session->consumed_size); + assert_int32((int32_t)(NGHTTP2_FRAME_HDLEN + hd.length - sendlen + 1), ==, + session->consumed_size); nghttp2_session_del(session); @@ -1153,12 +1321,13 @@ void test_nghttp2_session_recv_data_no_auto_flow_control(void) { stream = open_recv_stream(session, 1); stream->http_flags |= NGHTTP2_HTTP_FLAG_EXPECT_FINAL_RESPONSE; - rv = nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + hd.length); - CU_ASSERT((ssize_t)(NGHTTP2_FRAME_HDLEN + hd.length) == rv); + rv = + nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + hd.length); + assert_ptrdiff((nghttp2_ssize)(NGHTTP2_FRAME_HDLEN + hd.length), ==, rv); /* Whole payload must be consumed now because HTTP messaging rule was not honored. */ - CU_ASSERT((int32_t)hd.length == session->consumed_size); + assert_int32((int32_t)hd.length, ==, session->consumed_size); nghttp2_session_del(session); @@ -1175,57 +1344,57 @@ void test_nghttp2_session_recv_data_no_auto_flow_control(void) { /* Receive up to 65535 bytes of DATA */ for (i = 0; i < 15; ++i) { - rv = nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + 4096); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 4096 == rv); + rv = nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + 4096); + assert_ptrdiff(NGHTTP2_FRAME_HDLEN + 4096, ==, rv); } hd.length = 4095; nghttp2_frame_pack_frame_hd(data, &hd); - rv = nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + 4095); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 4095 == rv); + rv = nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + 4095); + assert_ptrdiff(NGHTTP2_FRAME_HDLEN + 4095, ==, rv); - CU_ASSERT(65535 == session->recv_window_size); - CU_ASSERT(65535 == stream->recv_window_size); + assert_int32(65535, ==, session->recv_window_size); + assert_int32(65535, ==, stream->recv_window_size); /* The first call of nghttp2_session_consume_connection() will queue WINDOW_UPDATE. Next call does not. */ nghttp2_session_consume_connection(session, 32767); nghttp2_session_consume_connection(session, 32768); - CU_ASSERT(32768 == session->recv_window_size); - CU_ASSERT(65535 == stream->recv_window_size); - CU_ASSERT(1 == session->window_update_queued); - CU_ASSERT(0 == stream->window_update_queued); + assert_int32(32768, ==, session->recv_window_size); + assert_int32(65535, ==, stream->recv_window_size); + assert_true(session->window_update_queued); + assert_false(stream->window_update_queued); ud.frame_send_cb_called = 0; /* This will send WINDOW_UPDATE, and check whether we should send WINDOW_UPDATE, and queue and send it at once. */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == session->recv_window_size); - CU_ASSERT(65535 == stream->recv_window_size); - CU_ASSERT(0 == session->window_update_queued); - CU_ASSERT(0 == stream->window_update_queued); - CU_ASSERT(2 == ud.frame_send_cb_called); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int32(0, ==, session->recv_window_size); + assert_int32(65535, ==, stream->recv_window_size); + assert_false(session->window_update_queued); + assert_false(stream->window_update_queued); + assert_int(2, ==, ud.frame_send_cb_called); /* Do the same for stream */ nghttp2_session_consume_stream(session, 1, 32767); nghttp2_session_consume_stream(session, 1, 32768); - CU_ASSERT(0 == session->recv_window_size); - CU_ASSERT(32768 == stream->recv_window_size); - CU_ASSERT(0 == session->window_update_queued); - CU_ASSERT(1 == stream->window_update_queued); + assert_int32(0, ==, session->recv_window_size); + assert_int32(32768, ==, stream->recv_window_size); + assert_false(session->window_update_queued); + assert_true(stream->window_update_queued); ud.frame_send_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == session->recv_window_size); - CU_ASSERT(0 == stream->recv_window_size); - CU_ASSERT(0 == session->window_update_queued); - CU_ASSERT(0 == stream->window_update_queued); - CU_ASSERT(2 == ud.frame_send_cb_called); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int32(0, ==, session->recv_window_size); + assert_int32(0, ==, stream->recv_window_size); + assert_false(session->window_update_queued); + assert_false(stream->window_update_queued); + assert_int(2, ==, ud.frame_send_cb_called); nghttp2_session_del(session); nghttp2_option_del(option); @@ -1239,7 +1408,7 @@ void test_nghttp2_session_recv_continuation(void) { nghttp2_frame frame; nghttp2_bufs bufs; nghttp2_buf *buf; - ssize_t rv; + nghttp2_ssize rv; my_user_data ud; nghttp2_hd_deflater deflater; uint8_t data[1024]; @@ -1267,8 +1436,8 @@ void test_nghttp2_session_recv_continuation(void) { NGHTTP2_HCAT_HEADERS, NULL, nva, nvlen); rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_ptrdiff(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); /* make sure that all data is in the first buf */ buf = &bufs.head->buf; @@ -1305,15 +1474,15 @@ void test_nghttp2_session_recv_continuation(void) { datalen += cont_hd.length; buf->pos += cont_hd.length; - CU_ASSERT(0 == nghttp2_buf_len(buf)); + assert_size(0, ==, nghttp2_buf_len(buf)); ud.header_cb_called = 0; ud.begin_frame_cb_called = 0; - rv = nghttp2_session_mem_recv(session, data, datalen); - CU_ASSERT((ssize_t)datalen == rv); - CU_ASSERT(4 == ud.header_cb_called); - CU_ASSERT(3 == ud.begin_frame_cb_called); + rv = nghttp2_session_mem_recv2(session, data, datalen); + assert_ptrdiff((nghttp2_ssize)datalen, ==, rv); + assert_int(4, ==, ud.header_cb_called); + assert_int(3, ==, ud.begin_frame_cb_called); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -1331,7 +1500,7 @@ void test_nghttp2_session_recv_continuation(void) { nghttp2_bufs_reset(&bufs); rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_headers_free(&frame.headers, mem); @@ -1361,16 +1530,16 @@ void test_nghttp2_session_recv_continuation(void) { datalen += cont_hd.length; buf->pos += cont_hd.length; - CU_ASSERT(0 == nghttp2_buf_len(buf)); + assert_size(0, ==, nghttp2_buf_len(buf)); ud.header_cb_called = 0; ud.begin_frame_cb_called = 0; - rv = nghttp2_session_mem_recv(session, data, datalen); + rv = nghttp2_session_mem_recv2(session, data, datalen); - CU_ASSERT((ssize_t)datalen == rv); - CU_ASSERT(4 == ud.header_cb_called); - CU_ASSERT(2 == ud.begin_frame_cb_called); + assert_ptrdiff((nghttp2_ssize)datalen, ==, rv); + assert_int(4, ==, ud.header_cb_called); + assert_int(2, ==, ud.begin_frame_cb_called); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -1388,8 +1557,8 @@ void test_nghttp2_session_recv_continuation(void) { nghttp2_bufs_reset(&bufs); rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_ptrdiff(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); nghttp2_frame_headers_free(&frame.headers, mem); @@ -1408,18 +1577,18 @@ void test_nghttp2_session_recv_continuation(void) { nghttp2_frame_pack_priority(&bufs, &frame.priority); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_size(0, <, nghttp2_bufs_len(&bufs)); memcpy(data + datalen, buf->pos, nghttp2_buf_len(buf)); datalen += nghttp2_buf_len(buf); ud.begin_headers_cb_called = 0; - rv = nghttp2_session_mem_recv(session, data, datalen); - CU_ASSERT((ssize_t)datalen == rv); + rv = nghttp2_session_mem_recv2(session, data, datalen); + assert_ptrdiff((nghttp2_ssize)datalen, ==, rv); - CU_ASSERT(1 == ud.begin_headers_cb_called); - CU_ASSERT(NGHTTP2_GOAWAY == - nghttp2_session_get_next_ob_item(session)->frame.hd.type); + assert_int(1, ==, ud.begin_headers_cb_called); + assert_uint8(NGHTTP2_GOAWAY, ==, + nghttp2_session_get_next_ob_item(session)->frame.hd.type); nghttp2_bufs_free(&bufs); nghttp2_hd_deflate_free(&deflater); @@ -1434,7 +1603,7 @@ void test_nghttp2_session_recv_headers_with_priority(void) { nghttp2_frame frame; nghttp2_bufs bufs; nghttp2_buf *buf; - ssize_t rv; + nghttp2_ssize rv; my_user_data ud; nghttp2_hd_deflater deflater; nghttp2_outbound_item *item; @@ -1466,8 +1635,8 @@ void test_nghttp2_session_recv_headers_with_priority(void) { rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_ptrdiff(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); nghttp2_frame_headers_free(&frame.headers, mem); @@ -1476,15 +1645,15 @@ void test_nghttp2_session_recv_headers_with_priority(void) { ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); - CU_ASSERT(1 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_int(1, ==, ud.frame_recv_cb_called); stream = nghttp2_session_get_stream(session, 3); - CU_ASSERT(99 == stream->weight); - CU_ASSERT(1 == stream->dep_prev->stream_id); + assert_int32(99, ==, stream->weight); + assert_int32(1, ==, stream->dep_prev->stream_id); nghttp2_bufs_reset(&bufs); @@ -1501,8 +1670,8 @@ void test_nghttp2_session_recv_headers_with_priority(void) { rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > NGHTTP2_FRAME_HDLEN + 5); + assert_ptrdiff(0, ==, rv); + assert_size(NGHTTP2_FRAME_HDLEN + 5, <, nghttp2_bufs_len(&bufs)); nghttp2_frame_headers_free(&frame.headers, mem); @@ -1513,19 +1682,19 @@ void test_nghttp2_session_recv_headers_with_priority(void) { ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); stream = nghttp2_session_get_stream(session, 5); - CU_ASSERT(NULL == stream); + assert_null(stream); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); - CU_ASSERT(NGHTTP2_FRAME_SIZE_ERROR == item->frame.goaway.error_code); + assert_not_null(item); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_FRAME_SIZE_ERROR, ==, item->frame.goaway.error_code); nghttp2_bufs_reset(&bufs); @@ -1548,8 +1717,8 @@ void test_nghttp2_session_recv_headers_with_priority(void) { rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_ptrdiff(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); nghttp2_frame_headers_free(&frame.headers, mem); @@ -1558,19 +1727,19 @@ void test_nghttp2_session_recv_headers_with_priority(void) { ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(NULL == stream); + assert_null(stream); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); - CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == item->frame.goaway.error_code); + assert_not_null(item); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_PROTOCOL_ERROR, ==, item->frame.goaway.error_code); nghttp2_bufs_reset(&bufs); @@ -1587,13 +1756,13 @@ void test_nghttp2_session_recv_headers_with_padding(void) { nghttp2_frame_hd hd; nghttp2_outbound_item *item; my_user_data ud; - ssize_t rv; + nghttp2_ssize rv; frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); callbacks.on_frame_recv_callback = on_frame_recv_callback; - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; /* HEADERS: Wrong padding length */ nghttp2_session_server_new(&session, &callbacks, &ud); @@ -1618,15 +1787,15 @@ void test_nghttp2_session_recv_headers_with_padding(void) { ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); + assert_not_null(item); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); nghttp2_bufs_reset(&bufs); nghttp2_session_del(session); @@ -1653,15 +1822,15 @@ void test_nghttp2_session_recv_headers_with_padding(void) { ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); + assert_not_null(item); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); nghttp2_bufs_free(&bufs); nghttp2_session_del(session); @@ -1677,10 +1846,10 @@ static int response_on_begin_frame_callback(nghttp2_session *session, return 0; } - rv = nghttp2_submit_response(session, hd->stream_id, resnv, ARRLEN(resnv), - NULL); + rv = nghttp2_submit_response2(session, hd->stream_id, resnv, ARRLEN(resnv), + NULL); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); return 0; } @@ -1695,14 +1864,14 @@ void test_nghttp2_session_recv_headers_early_response(void) { nghttp2_nv *nva; size_t nvlen; nghttp2_frame frame; - ssize_t rv; + nghttp2_ssize rv; nghttp2_stream *stream; mem = nghttp2_mem_default(); frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_begin_frame_callback = response_on_begin_frame_callback; nghttp2_session_server_new(&session, &callbacks, NULL); @@ -1717,7 +1886,7 @@ void test_nghttp2_session_recv_headers_early_response(void) { rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_headers_free(&frame.headers, mem); @@ -1725,22 +1894,22 @@ void test_nghttp2_session_recv_headers_early_response(void) { /* Only receive 9 bytes headers, and invoke on_begin_frame_callback */ - rv = nghttp2_session_mem_recv(session, buf->pos, 9); + rv = nghttp2_session_mem_recv2(session, buf->pos, 9); - CU_ASSERT(9 == rv); + assert_ptrdiff(9, ==, rv); rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = - nghttp2_session_mem_recv(session, buf->pos + 9, nghttp2_buf_len(buf) - 9); + rv = nghttp2_session_mem_recv2(session, buf->pos + 9, + nghttp2_buf_len(buf) - 9); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) - 9 == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf) - 9, ==, rv); stream = nghttp2_session_get_stream_raw(session, 1); - CU_ASSERT(stream->flags & NGHTTP2_STREAM_FLAG_CLOSED); + assert_true(stream->flags & NGHTTP2_STREAM_FLAG_CLOSED); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -1755,7 +1924,7 @@ void test_nghttp2_session_recv_headers_for_closed_stream(void) { nghttp2_frame frame; nghttp2_bufs bufs; nghttp2_buf *buf; - ssize_t rv; + nghttp2_ssize rv; my_user_data ud; nghttp2_hd_deflater deflater; nghttp2_stream *stream; @@ -1783,8 +1952,8 @@ void test_nghttp2_session_recv_headers_for_closed_stream(void) { rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_ptrdiff(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); nghttp2_frame_headers_free(&frame.headers, mem); @@ -1794,38 +1963,39 @@ void test_nghttp2_session_recv_headers_for_closed_stream(void) { ud.header_cb_called = 0; ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf->pos, NGHTTP2_FRAME_HDLEN); + rv = nghttp2_session_mem_recv2(session, buf->pos, NGHTTP2_FRAME_HDLEN); - CU_ASSERT(NGHTTP2_FRAME_HDLEN == rv); - CU_ASSERT(0 == ud.header_cb_called); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff(NGHTTP2_FRAME_HDLEN, ==, rv); + assert_int(0, ==, ud.header_cb_called); + assert_int(0, ==, ud.frame_recv_cb_called); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(NULL != stream); + assert_not_null(stream); rv = nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, 1, NGHTTP2_NO_ERROR); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_send(session, &data); + rv = nghttp2_session_mem_send2(session, &data); - CU_ASSERT(rv > 0); + assert_ptrdiff(0, <, rv); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(NULL == stream); + assert_null(stream); ud.header_cb_called = 0; ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf->pos + NGHTTP2_FRAME_HDLEN, - nghttp2_buf_len(buf) - NGHTTP2_FRAME_HDLEN); + rv = nghttp2_session_mem_recv2(session, buf->pos + NGHTTP2_FRAME_HDLEN, + nghttp2_buf_len(buf) - NGHTTP2_FRAME_HDLEN); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) - NGHTTP2_FRAME_HDLEN == rv); - CU_ASSERT(0 == ud.header_cb_called); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf) - NGHTTP2_FRAME_HDLEN, ==, + rv); + assert_int(0, ==, ud.header_cb_called); + assert_int(0, ==, ud.frame_recv_cb_called); nghttp2_bufs_free(&bufs); nghttp2_hd_deflate_free(&deflater); @@ -1840,7 +2010,7 @@ void test_nghttp2_session_recv_headers_with_extpri(void) { nghttp2_frame frame; nghttp2_bufs bufs; nghttp2_buf *buf; - ssize_t rv; + nghttp2_ssize rv; nghttp2_hd_deflater deflater; nghttp2_stream *stream; nghttp2_mem *mem; @@ -1873,20 +2043,20 @@ void test_nghttp2_session_recv_headers_with_extpri(void) { rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_ptrdiff(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); nghttp2_frame_headers_free(&frame.headers, mem); buf = &bufs.head->buf; assert(nghttp2_bufs_len(&bufs) == nghttp2_buf_len(buf)); - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(2 == nghttp2_extpri_uint8_urgency(stream->extpri)); - CU_ASSERT(1 == nghttp2_extpri_uint8_inc(stream->extpri)); + assert_uint32(2, ==, nghttp2_extpri_uint8_urgency(stream->extpri)); + assert_true(nghttp2_extpri_uint8_inc(stream->extpri)); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -1911,22 +2081,22 @@ void test_nghttp2_session_recv_headers_with_extpri(void) { rv = nghttp2_frame_pack_push_promise(&bufs, &frame.push_promise, &deflater); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_ptrdiff(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); nghttp2_frame_push_promise_free(&frame.push_promise, mem); buf = &bufs.head->buf; assert(nghttp2_bufs_len(&bufs) == nghttp2_buf_len(buf)); - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); stream = nghttp2_session_get_stream(session, 2); - CU_ASSERT(NGHTTP2_EXTPRI_DEFAULT_URGENCY == - nghttp2_extpri_uint8_urgency(stream->http_extpri)); - CU_ASSERT(NGHTTP2_EXTPRI_DEFAULT_URGENCY == - nghttp2_extpri_uint8_urgency(stream->extpri)); + assert_uint32(NGHTTP2_EXTPRI_DEFAULT_URGENCY, ==, + nghttp2_extpri_uint8_urgency(stream->http_extpri)); + assert_uint32(NGHTTP2_EXTPRI_DEFAULT_URGENCY, ==, + nghttp2_extpri_uint8_urgency(stream->extpri)); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -1938,7 +2108,7 @@ void test_nghttp2_session_server_recv_push_response(void) { nghttp2_session_callbacks callbacks; nghttp2_bufs bufs; nghttp2_buf *buf; - ssize_t rv; + nghttp2_ssize rv; my_user_data ud; nghttp2_mem *mem; nghttp2_frame frame; @@ -1965,8 +2135,8 @@ void test_nghttp2_session_server_recv_push_response(void) { nvlen); rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_ptrdiff(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); nghttp2_frame_headers_free(&frame.headers, mem); @@ -1974,10 +2144,10 @@ void test_nghttp2_session_server_recv_push_response(void) { ud.invalid_frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); - CU_ASSERT(1 == ud.invalid_frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_int(1, ==, ud.invalid_frame_recv_cb_called); nghttp2_bufs_free(&bufs); nghttp2_hd_deflate_free(&deflater); @@ -1989,7 +2159,7 @@ void test_nghttp2_session_recv_premature_headers(void) { nghttp2_session_callbacks callbacks; nghttp2_bufs bufs; nghttp2_buf *buf; - ssize_t rv; + nghttp2_ssize rv; my_user_data ud; nghttp2_hd_deflater deflater; nghttp2_outbound_item *item; @@ -2000,7 +2170,7 @@ void test_nghttp2_session_recv_premature_headers(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_server_new(&session, &callbacks, &ud); @@ -2013,17 +2183,18 @@ void test_nghttp2_session_recv_premature_headers(void) { /* Intentionally feed payload cutting last 1 byte off */ payloadlen = nghttp2_get_uint32(buf->pos) >> 8; nghttp2_put_uint32be(buf->pos, ((payloadlen - 1) << 8) + buf->pos[3]); - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf) - 1); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf) - 1); - CU_ASSERT((ssize_t)(nghttp2_buf_len(buf) - 1) == rv); + assert_ptrdiff((nghttp2_ssize)(nghttp2_buf_len(buf) - 1), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(NGHTTP2_COMPRESSION_ERROR == item->frame.rst_stream.error_code); - CU_ASSERT(1 == item->frame.hd.stream_id); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_not_null(item); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_COMPRESSION_ERROR, ==, + item->frame.rst_stream.error_code); + assert_int32(1, ==, item->frame.hd.stream_id); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_bufs_reset(&bufs); nghttp2_hd_deflate_free(&deflater); @@ -2039,23 +2210,24 @@ void test_nghttp2_session_recv_premature_headers(void) { rv = pack_push_promise(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, 2, reqnv, ARRLEN(reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); buf = &bufs.head->buf; payloadlen = nghttp2_get_uint32(buf->pos) >> 8; /* Intentionally feed payload cutting last 1 byte off */ nghttp2_put_uint32be(buf->pos, ((payloadlen - 1) << 8) + buf->pos[3]); - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf) - 1); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf) - 1); - CU_ASSERT((ssize_t)(nghttp2_buf_len(buf) - 1) == rv); + assert_ptrdiff((nghttp2_ssize)(nghttp2_buf_len(buf) - 1), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(NGHTTP2_COMPRESSION_ERROR == item->frame.rst_stream.error_code); - CU_ASSERT(2 == item->frame.hd.stream_id); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_not_null(item); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_COMPRESSION_ERROR, ==, + item->frame.rst_stream.error_code); + assert_int32(2, ==, item->frame.hd.stream_id); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -2069,7 +2241,7 @@ void test_nghttp2_session_recv_unknown_frame(void) { uint8_t data[16384]; size_t datalen; nghttp2_frame_hd hd; - ssize_t rv; + nghttp2_ssize rv; nghttp2_frame_hd_init(&hd, 16000, 99, NGHTTP2_FLAG_NONE, 0); @@ -2084,11 +2256,11 @@ void test_nghttp2_session_recv_unknown_frame(void) { ud.frame_recv_cb_called = 0; /* Unknown frame must be ignored */ - rv = nghttp2_session_mem_recv(session, data, datalen); + rv = nghttp2_session_mem_recv2(session, data, datalen); - CU_ASSERT(rv == (ssize_t)datalen); - CU_ASSERT(0 == ud.frame_recv_cb_called); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_ptrdiff(rv, ==, (nghttp2_ssize)datalen); + assert_int(0, ==, ud.frame_recv_cb_called); + assert_null(nghttp2_session_get_next_ob_item(session)); nghttp2_session_del(session); } @@ -2100,7 +2272,7 @@ void test_nghttp2_session_recv_unexpected_continuation(void) { uint8_t data[16384]; size_t datalen; nghttp2_frame_hd hd; - ssize_t rv; + nghttp2_ssize rv; nghttp2_outbound_item *item; nghttp2_frame_hd_init(&hd, 16000, NGHTTP2_CONTINUATION, @@ -2119,14 +2291,14 @@ void test_nghttp2_session_recv_unexpected_continuation(void) { ud.frame_recv_cb_called = 0; /* unexpected CONTINUATION must be treated as connection error */ - rv = nghttp2_session_mem_recv(session, data, datalen); + rv = nghttp2_session_mem_recv2(session, data, datalen); - CU_ASSERT(rv == (ssize_t)datalen); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff(rv, ==, (nghttp2_ssize)datalen); + assert_int(0, ==, ud.frame_recv_cb_called); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); nghttp2_session_del(session); } @@ -2137,7 +2309,7 @@ void test_nghttp2_session_recv_settings_header_table_size(void) { nghttp2_frame frame; nghttp2_bufs bufs; nghttp2_buf *buf; - ssize_t rv; + nghttp2_ssize rv; my_user_data ud; nghttp2_settings_entry iv[3]; nghttp2_nv nv = MAKE_NV(":authority", "example.org"); @@ -2148,7 +2320,7 @@ void test_nghttp2_session_recv_settings_header_table_size(void) { memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); callbacks.on_frame_recv_callback = on_frame_recv_callback; - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, &ud); @@ -2163,8 +2335,8 @@ void test_nghttp2_session_recv_settings_header_table_size(void) { rv = nghttp2_frame_pack_settings(&bufs, &frame.settings); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_ptrdiff(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); nghttp2_frame_settings_free(&frame.settings, mem); @@ -2173,13 +2345,13 @@ void test_nghttp2_session_recv_settings_header_table_size(void) { ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); - CU_ASSERT(1 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_int(1, ==, ud.frame_recv_cb_called); - CU_ASSERT(3000 == session->remote_settings.header_table_size); - CU_ASSERT(16384 == session->remote_settings.initial_window_size); + assert_uint32(3000, ==, session->remote_settings.header_table_size); + assert_uint32(16384, ==, session->remote_settings.initial_window_size); nghttp2_bufs_reset(&bufs); @@ -2198,8 +2370,8 @@ void test_nghttp2_session_recv_settings_header_table_size(void) { rv = nghttp2_frame_pack_settings(&bufs, &frame.settings); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_ptrdiff(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); nghttp2_frame_settings_free(&frame.settings, mem); @@ -2208,23 +2380,23 @@ void test_nghttp2_session_recv_settings_header_table_size(void) { ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)(nghttp2_buf_len(buf)) == rv); - CU_ASSERT(1 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)(nghttp2_buf_len(buf)), ==, rv); + assert_int(1, ==, ud.frame_recv_cb_called); - CU_ASSERT(3001 == session->remote_settings.header_table_size); - CU_ASSERT(16383 == session->remote_settings.initial_window_size); + assert_uint32(3001, ==, session->remote_settings.header_table_size); + assert_uint32(16383, ==, session->remote_settings.initial_window_size); nghttp2_bufs_reset(&bufs); /* 2 SETTINGS_HEADER_TABLE_SIZE; first entry clears dynamic header table. */ - nghttp2_submit_request(session, NULL, &nv, 1, NULL, NULL); + nghttp2_submit_request2(session, NULL, &nv, 1, NULL, NULL); nghttp2_session_send(session); - CU_ASSERT(0 < session->hd_deflater.ctx.hd_table.len); + assert_size(0, <, session->hd_deflater.ctx.hd_table.len); iv[0].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE; iv[0].value = 0; @@ -2240,8 +2412,8 @@ void test_nghttp2_session_recv_settings_header_table_size(void) { rv = nghttp2_frame_pack_settings(&bufs, &frame.settings); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_ptrdiff(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); nghttp2_frame_settings_free(&frame.settings, mem); @@ -2250,24 +2422,24 @@ void test_nghttp2_session_recv_settings_header_table_size(void) { ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); - CU_ASSERT(1 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_int(1, ==, ud.frame_recv_cb_called); - CU_ASSERT(4096 == session->remote_settings.header_table_size); - CU_ASSERT(16382 == session->remote_settings.initial_window_size); - CU_ASSERT(0 == session->hd_deflater.ctx.hd_table.len); + assert_uint32(4096, ==, session->remote_settings.header_table_size); + assert_uint32(16382, ==, session->remote_settings.initial_window_size); + assert_size(0, ==, session->hd_deflater.ctx.hd_table.len); nghttp2_bufs_reset(&bufs); /* 2 SETTINGS_HEADER_TABLE_SIZE; second entry clears dynamic header table. */ - nghttp2_submit_request(session, NULL, &nv, 1, NULL, NULL); + nghttp2_submit_request2(session, NULL, &nv, 1, NULL, NULL); nghttp2_session_send(session); - CU_ASSERT(0 < session->hd_deflater.ctx.hd_table.len); + assert_size(0, <, session->hd_deflater.ctx.hd_table.len); iv[0].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE; iv[0].value = 3000; @@ -2283,8 +2455,8 @@ void test_nghttp2_session_recv_settings_header_table_size(void) { rv = nghttp2_frame_pack_settings(&bufs, &frame.settings); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_ptrdiff(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); nghttp2_frame_settings_free(&frame.settings, mem); @@ -2293,14 +2465,14 @@ void test_nghttp2_session_recv_settings_header_table_size(void) { ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); - CU_ASSERT(1 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_int(1, ==, ud.frame_recv_cb_called); - CU_ASSERT(0 == session->remote_settings.header_table_size); - CU_ASSERT(16381 == session->remote_settings.initial_window_size); - CU_ASSERT(0 == session->hd_deflater.ctx.hd_table.len); + assert_uint32(0, ==, session->remote_settings.header_table_size); + assert_uint32(16381, ==, session->remote_settings.initial_window_size); + assert_size(0, ==, session->hd_deflater.ctx.hd_table.len); nghttp2_bufs_reset(&bufs); @@ -2325,12 +2497,13 @@ void test_nghttp2_session_recv_too_large_frame_length(void) { nghttp2_frame_pack_frame_hd(buf, &hd); - CU_ASSERT(sizeof(buf) == nghttp2_session_mem_recv(session, buf, sizeof(buf))); + assert_ptrdiff(sizeof(buf), ==, + nghttp2_session_mem_recv2(session, buf, sizeof(buf))); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(item != NULL); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); + assert_not_null(item); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); nghttp2_session_del(session); } @@ -2343,7 +2516,7 @@ void test_nghttp2_session_recv_extension(void) { nghttp2_frame_hd hd; nghttp2_mem *mem; const char data[] = "Hello World!"; - ssize_t rv; + nghttp2_ssize rv; nghttp2_option *option; mem = nghttp2_mem_default(); @@ -2368,13 +2541,13 @@ void test_nghttp2_session_recv_extension(void) { nghttp2_session_client_new2(&session, &callbacks, &ud, option); nghttp2_frame_hd_init(&ud.recv_frame_hd, 0, 0, 0, 0); - rv = nghttp2_session_mem_recv(session, buf.pos, nghttp2_buf_len(&buf)); + rv = nghttp2_session_mem_recv2(session, buf.pos, nghttp2_buf_len(&buf)); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + hd.length == (size_t)rv); - CU_ASSERT(111 == ud.recv_frame_hd.type); - CU_ASSERT(0xab == ud.recv_frame_hd.flags); - CU_ASSERT(1000000007 == ud.recv_frame_hd.stream_id); - CU_ASSERT(0 == memcmp(data, ud.scratchbuf.pos, sizeof(data))); + assert_size(NGHTTP2_FRAME_HDLEN + hd.length, ==, (size_t)rv); + assert_uint8(111, ==, ud.recv_frame_hd.type); + assert_uint8(0xab, ==, ud.recv_frame_hd.flags); + assert_int32(1000000007, ==, ud.recv_frame_hd.stream_id); + assert_memory_equal(sizeof(data), data, ud.scratchbuf.pos); nghttp2_session_del(session); @@ -2387,10 +2560,10 @@ void test_nghttp2_session_recv_extension(void) { nghttp2_session_server_new2(&session, &callbacks, &ud, option); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf.pos, nghttp2_buf_len(&buf)); + rv = nghttp2_session_mem_recv2(session, buf.pos, nghttp2_buf_len(&buf)); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + hd.length == (size_t)rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_size(NGHTTP2_FRAME_HDLEN + hd.length, ==, (size_t)rv); + assert_int(0, ==, ud.frame_recv_cb_called); nghttp2_session_del(session); @@ -2403,10 +2576,10 @@ void test_nghttp2_session_recv_extension(void) { nghttp2_session_server_new2(&session, &callbacks, &ud, option); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf.pos, nghttp2_buf_len(&buf)); + rv = nghttp2_session_mem_recv2(session, buf.pos, nghttp2_buf_len(&buf)); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + hd.length == (size_t)rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_size(NGHTTP2_FRAME_HDLEN + hd.length, ==, (size_t)rv); + assert_int(0, ==, ud.frame_recv_cb_called); nghttp2_session_del(session); @@ -2423,7 +2596,7 @@ void test_nghttp2_session_recv_altsvc(void) { nghttp2_buf buf; nghttp2_frame_hd hd; nghttp2_mem *mem; - ssize_t rv; + nghttp2_ssize rv; nghttp2_option *option; static const uint8_t origin[] = "nghttp2.org"; static const uint8_t field_value[] = "h2=\":443\""; @@ -2453,13 +2626,13 @@ void test_nghttp2_session_recv_altsvc(void) { buf.last = nghttp2_cpymem(buf.last, field_value, sizeof(field_value) - 1); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf.pos, nghttp2_buf_len(&buf)); + rv = nghttp2_session_mem_recv2(session, buf.pos, nghttp2_buf_len(&buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&buf) == rv); - CU_ASSERT(1 == ud.frame_recv_cb_called); - CU_ASSERT(NGHTTP2_ALTSVC == ud.recv_frame_hd.type); - CU_ASSERT(NGHTTP2_FLAG_NONE == ud.recv_frame_hd.flags); - CU_ASSERT(0 == ud.recv_frame_hd.stream_id); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&buf), ==, rv); + assert_int(1, ==, ud.frame_recv_cb_called); + assert_uint8(NGHTTP2_ALTSVC, ==, ud.recv_frame_hd.type); + assert_uint8(NGHTTP2_FLAG_NONE, ==, ud.recv_frame_hd.flags); + assert_int32(0, ==, ud.recv_frame_hd.stream_id); nghttp2_session_del(session); @@ -2477,10 +2650,10 @@ void test_nghttp2_session_recv_altsvc(void) { buf.last = nghttp2_cpymem(buf.last, origin, sizeof(origin) - 1 - 1); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf.pos, nghttp2_buf_len(&buf)); + rv = nghttp2_session_mem_recv2(session, buf.pos, nghttp2_buf_len(&buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&buf) == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&buf), ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); nghttp2_session_del(session); @@ -2498,10 +2671,10 @@ void test_nghttp2_session_recv_altsvc(void) { buf.last = nghttp2_cpymem(buf.last, origin, sizeof(origin) - 1); ud.invalid_frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf.pos, nghttp2_buf_len(&buf)); + rv = nghttp2_session_mem_recv2(session, buf.pos, nghttp2_buf_len(&buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&buf) == rv); - CU_ASSERT(1 == ud.invalid_frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&buf), ==, rv); + assert_int(1, ==, ud.invalid_frame_recv_cb_called); nghttp2_session_del(session); @@ -2522,10 +2695,10 @@ void test_nghttp2_session_recv_altsvc(void) { buf.last = nghttp2_cpymem(buf.last, field_value, sizeof(field_value) - 1); ud.invalid_frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf.pos, nghttp2_buf_len(&buf)); + rv = nghttp2_session_mem_recv2(session, buf.pos, nghttp2_buf_len(&buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&buf) == rv); - CU_ASSERT(1 == ud.invalid_frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&buf), ==, rv); + assert_int(1, ==, ud.invalid_frame_recv_cb_called); nghttp2_session_del(session); @@ -2543,10 +2716,10 @@ void test_nghttp2_session_recv_altsvc(void) { buf.last = nghttp2_cpymem(buf.last, field_value, sizeof(field_value) - 1); ud.invalid_frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf.pos, nghttp2_buf_len(&buf)); + rv = nghttp2_session_mem_recv2(session, buf.pos, nghttp2_buf_len(&buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&buf) == rv); - CU_ASSERT(1 == ud.invalid_frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&buf), ==, rv); + assert_int(1, ==, ud.invalid_frame_recv_cb_called); nghttp2_session_del(session); @@ -2566,12 +2739,12 @@ void test_nghttp2_session_recv_altsvc(void) { buf.last += nghttp2_buf_avail(&buf); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf.pos, nghttp2_buf_len(&buf)); + rv = nghttp2_session_mem_recv2(session, buf.pos, nghttp2_buf_len(&buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&buf) == rv); - CU_ASSERT(1 == ud.frame_recv_cb_called); - CU_ASSERT(NGHTTP2_ALTSVC == ud.recv_frame_hd.type); - CU_ASSERT(NGHTTP2_MAX_FRAME_SIZE_MIN == ud.recv_frame_hd.length); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&buf), ==, rv); + assert_int(1, ==, ud.frame_recv_cb_called); + assert_uint8(NGHTTP2_ALTSVC, ==, ud.recv_frame_hd.type); + assert_size(NGHTTP2_MAX_FRAME_SIZE_MIN, ==, ud.recv_frame_hd.length); nghttp2_session_del(session); @@ -2593,10 +2766,10 @@ void test_nghttp2_session_recv_altsvc(void) { buf.last += nghttp2_buf_avail(&buf); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf.pos, nghttp2_buf_len(&buf)); + rv = nghttp2_session_mem_recv2(session, buf.pos, nghttp2_buf_len(&buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&buf) == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&buf), ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); nghttp2_session_del(session); @@ -2615,10 +2788,10 @@ void test_nghttp2_session_recv_altsvc(void) { buf.last = nghttp2_cpymem(buf.last, field_value, sizeof(field_value) - 1); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf.pos, nghttp2_buf_len(&buf)); + rv = nghttp2_session_mem_recv2(session, buf.pos, nghttp2_buf_len(&buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&buf) == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&buf), ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); nghttp2_session_del(session); @@ -2631,7 +2804,7 @@ void test_nghttp2_session_recv_origin(void) { nghttp2_session_callbacks callbacks; my_user_data ud; nghttp2_bufs bufs; - ssize_t rv; + nghttp2_ssize rv; nghttp2_option *option; nghttp2_extension frame; nghttp2_ext_origin origin; @@ -2658,17 +2831,17 @@ void test_nghttp2_session_recv_origin(void) { rv = nghttp2_frame_pack_origin(&bufs, &frame); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(1 == ud.frame_recv_cb_called); - CU_ASSERT(NGHTTP2_ORIGIN == ud.recv_frame_hd.type); - CU_ASSERT(NGHTTP2_FLAG_NONE == ud.recv_frame_hd.flags); - CU_ASSERT(0 == ud.recv_frame_hd.stream_id); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(1, ==, ud.frame_recv_cb_called); + assert_uint8(NGHTTP2_ORIGIN, ==, ud.recv_frame_hd.type); + assert_uint8(NGHTTP2_FLAG_NONE, ==, ud.recv_frame_hd.flags); + assert_int32(0, ==, ud.recv_frame_hd.stream_id); nghttp2_session_del(session); nghttp2_bufs_reset(&bufs); @@ -2679,17 +2852,17 @@ void test_nghttp2_session_recv_origin(void) { nghttp2_frame_origin_init(&frame, &ov, 1); rv = nghttp2_frame_pack_origin(&bufs, &frame); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_put_uint16be(bufs.head->buf.pos + NGHTTP2_FRAME_HDLEN, (uint16_t)sizeof(nghttp2)); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); nghttp2_session_del(session); nghttp2_bufs_reset(&bufs); @@ -2702,14 +2875,14 @@ void test_nghttp2_session_recv_origin(void) { frame.hd.stream_id = 1; rv = nghttp2_frame_pack_origin(&bufs, &frame); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); nghttp2_session_del(session); nghttp2_bufs_reset(&bufs); @@ -2721,14 +2894,14 @@ void test_nghttp2_session_recv_origin(void) { frame.hd.flags = 0xf0; rv = nghttp2_frame_pack_origin(&bufs, &frame); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); nghttp2_session_del(session); nghttp2_bufs_reset(&bufs); @@ -2739,14 +2912,14 @@ void test_nghttp2_session_recv_origin(void) { nghttp2_frame_origin_init(&frame, &ov, 1); rv = nghttp2_frame_pack_origin(&bufs, &frame); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); nghttp2_session_del(session); nghttp2_bufs_reset(&bufs); @@ -2757,15 +2930,15 @@ void test_nghttp2_session_recv_origin(void) { nghttp2_frame_origin_init(&frame, NULL, 0); rv = nghttp2_frame_pack_origin(&bufs, &frame); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(1 == ud.frame_recv_cb_called); - CU_ASSERT(NGHTTP2_ORIGIN == ud.recv_frame_hd.type); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(1, ==, ud.frame_recv_cb_called); + assert_uint8(NGHTTP2_ORIGIN, ==, ud.recv_frame_hd.type); nghttp2_session_del(session); @@ -2778,7 +2951,7 @@ void test_nghttp2_session_recv_priority_update(void) { nghttp2_session_callbacks callbacks; my_user_data ud; nghttp2_bufs bufs; - ssize_t rv; + nghttp2_ssize rv; nghttp2_option *option; nghttp2_extension frame; nghttp2_ext_priority_update priority_update; @@ -2820,19 +2993,19 @@ void test_nghttp2_session_recv_priority_update(void) { open_recv_stream(session, 1); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(1 == ud.frame_recv_cb_called); - CU_ASSERT(NGHTTP2_PRIORITY_UPDATE == ud.recv_frame_hd.type); - CU_ASSERT(NGHTTP2_FLAG_NONE == ud.recv_frame_hd.flags); - CU_ASSERT(0 == ud.recv_frame_hd.stream_id); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(1, ==, ud.frame_recv_cb_called); + assert_uint8(NGHTTP2_PRIORITY_UPDATE, ==, ud.recv_frame_hd.type); + assert_uint8(NGHTTP2_FLAG_NONE, ==, ud.recv_frame_hd.flags); + assert_int32(0, ==, ud.recv_frame_hd.stream_id); stream = nghttp2_session_get_stream_raw(session, 1); - CU_ASSERT(2 == nghttp2_extpri_uint8_urgency(stream->extpri)); - CU_ASSERT(1 == nghttp2_extpri_uint8_inc(stream->extpri)); + assert_uint32(2, ==, nghttp2_extpri_uint8_urgency(stream->extpri)); + assert_true(nghttp2_extpri_uint8_inc(stream->extpri)); nghttp2_session_del(session); nghttp2_bufs_reset(&bufs); @@ -2849,38 +3022,38 @@ void test_nghttp2_session_recv_priority_update(void) { nghttp2_frame_pack_priority_update(&bufs, &frame); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(1 == ud.frame_recv_cb_called); - CU_ASSERT(NGHTTP2_PRIORITY_UPDATE == ud.recv_frame_hd.type); - CU_ASSERT(NGHTTP2_FLAG_NONE == ud.recv_frame_hd.flags); - CU_ASSERT(0 == ud.recv_frame_hd.stream_id); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(1, ==, ud.frame_recv_cb_called); + assert_uint8(NGHTTP2_PRIORITY_UPDATE, ==, ud.recv_frame_hd.type); + assert_uint8(NGHTTP2_FLAG_NONE, ==, ud.recv_frame_hd.flags); + assert_int32(0, ==, ud.recv_frame_hd.stream_id); stream = nghttp2_session_get_stream_raw(session, 1); - CU_ASSERT(NGHTTP2_STREAM_IDLE == stream->state); - CU_ASSERT(2 == nghttp2_extpri_uint8_urgency(stream->extpri)); - CU_ASSERT(1 == nghttp2_extpri_uint8_inc(stream->extpri)); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_IDLE, ==, stream->state); + assert_uint32(2, ==, nghttp2_extpri_uint8_urgency(stream->extpri)); + assert_true(nghttp2_extpri_uint8_inc(stream->extpri)); nghttp2_hd_deflate_init(&deflater, mem); nghttp2_bufs_reset(&bufs); rv = pack_headers(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, reqnv, ARRLEN(reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(1 == ud.frame_recv_cb_called); - CU_ASSERT(NGHTTP2_HEADERS == ud.recv_frame_hd.type); - CU_ASSERT(NGHTTP2_STREAM_OPENING == stream->state); - CU_ASSERT(2 == nghttp2_extpri_uint8_urgency(stream->extpri)); - CU_ASSERT(1 == nghttp2_extpri_uint8_inc(stream->extpri)); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(1, ==, ud.frame_recv_cb_called); + assert_uint8(NGHTTP2_HEADERS, ==, ud.recv_frame_hd.type); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENING, ==, stream->state); + assert_uint32(2, ==, nghttp2_extpri_uint8_urgency(stream->extpri)); + assert_true(nghttp2_extpri_uint8_inc(stream->extpri)); nghttp2_hd_deflate_free(&deflater); @@ -2900,15 +3073,15 @@ void test_nghttp2_session_recv_priority_update(void) { open_recv_stream(session, 1); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); stream = nghttp2_session_get_stream_raw(session, 1); - CU_ASSERT(NGHTTP2_EXTPRI_DEFAULT_URGENCY == stream->extpri); + assert_uint32(NGHTTP2_EXTPRI_DEFAULT_URGENCY, ==, stream->extpri); nghttp2_session_del(session); nghttp2_bufs_reset(&bufs); @@ -2926,15 +3099,15 @@ void test_nghttp2_session_recv_priority_update(void) { open_sent_stream(session, 1); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); - CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == item->frame.goaway.error_code); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_PROTOCOL_ERROR, ==, item->frame.goaway.error_code); nghttp2_session_del(session); nghttp2_bufs_reset(&bufs); @@ -2953,23 +3126,23 @@ void test_nghttp2_session_recv_priority_update(void) { nghttp2_frame_pack_priority_update(&bufs, &frame); ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); if (i < 100) { - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(1 == ud.frame_recv_cb_called); - CU_ASSERT(NGHTTP2_PRIORITY_UPDATE == ud.recv_frame_hd.type); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(1, ==, ud.frame_recv_cb_called); + assert_uint8(NGHTTP2_PRIORITY_UPDATE, ==, ud.recv_frame_hd.type); } else { - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_int(0, ==, ud.frame_recv_cb_called); } nghttp2_bufs_reset(&bufs); } item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); - CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == item->frame.goaway.error_code); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_PROTOCOL_ERROR, ==, item->frame.goaway.error_code); nghttp2_session_del(session); nghttp2_option_del(option); @@ -2986,7 +3159,7 @@ void test_nghttp2_session_continue(void) { nghttp2_bufs bufs; nghttp2_buf *buf; size_t framelen1, framelen2; - ssize_t rv; + nghttp2_ssize rv; uint8_t buffer[4096]; nghttp2_buf databuf; nghttp2_frame frame; @@ -3002,7 +3175,7 @@ void test_nghttp2_session_continue(void) { nghttp2_buf_wrap_init(&databuf, buffer, sizeof(buffer)); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_recv_callback = on_frame_recv_callback; callbacks.on_data_chunk_recv_callback = pause_on_data_chunk_recv_callback; callbacks.on_header_callback = pause_on_header_callback; @@ -3021,8 +3194,8 @@ void test_nghttp2_session_continue(void) { NGHTTP2_HCAT_HEADERS, NULL, nva, nvlen); rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_ptrdiff(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); nghttp2_frame_headers_free(&frame.headers, mem); @@ -3039,8 +3212,8 @@ void test_nghttp2_session_continue(void) { nghttp2_bufs_reset(&bufs); rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_ptrdiff(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); nghttp2_frame_headers_free(&frame.headers, mem); @@ -3052,80 +3225,80 @@ void test_nghttp2_session_continue(void) { /* Receive 1st HEADERS and pause */ user_data.begin_headers_cb_called = 0; user_data.header_cb_called = 0; - rv = - nghttp2_session_mem_recv(session, databuf.pos, nghttp2_buf_len(&databuf)); + rv = nghttp2_session_mem_recv2(session, databuf.pos, + nghttp2_buf_len(&databuf)); - CU_ASSERT(rv >= 0); + assert_ptrdiff(0, <=, rv); databuf.pos += rv; recv_frame = user_data.frame; - CU_ASSERT(NGHTTP2_HEADERS == recv_frame->hd.type); - CU_ASSERT(framelen1 - NGHTTP2_FRAME_HDLEN == recv_frame->hd.length); + assert_uint8(NGHTTP2_HEADERS, ==, recv_frame->hd.type); + assert_size(framelen1 - NGHTTP2_FRAME_HDLEN, ==, recv_frame->hd.length); - CU_ASSERT(1 == user_data.begin_headers_cb_called); - CU_ASSERT(1 == user_data.header_cb_called); + assert_int(1, ==, user_data.begin_headers_cb_called); + assert_int(1, ==, user_data.header_cb_called); - CU_ASSERT(nghttp2_nv_equal(&nv1[0], &user_data.nv)); + assert_true(nghttp2_nv_equal(&nv1[0], &user_data.nv)); /* get 2nd header field */ user_data.begin_headers_cb_called = 0; user_data.header_cb_called = 0; - rv = - nghttp2_session_mem_recv(session, databuf.pos, nghttp2_buf_len(&databuf)); + rv = nghttp2_session_mem_recv2(session, databuf.pos, + nghttp2_buf_len(&databuf)); - CU_ASSERT(rv >= 0); + assert_ptrdiff(0, <=, rv); databuf.pos += rv; - CU_ASSERT(0 == user_data.begin_headers_cb_called); - CU_ASSERT(1 == user_data.header_cb_called); + assert_int(0, ==, user_data.begin_headers_cb_called); + assert_int(1, ==, user_data.header_cb_called); - CU_ASSERT(nghttp2_nv_equal(&nv1[1], &user_data.nv)); + assert_true(nghttp2_nv_equal(&nv1[1], &user_data.nv)); /* will call end_headers_callback and receive 2nd HEADERS and pause */ user_data.begin_headers_cb_called = 0; user_data.header_cb_called = 0; - rv = - nghttp2_session_mem_recv(session, databuf.pos, nghttp2_buf_len(&databuf)); + rv = nghttp2_session_mem_recv2(session, databuf.pos, + nghttp2_buf_len(&databuf)); - CU_ASSERT(rv >= 0); + assert_ptrdiff(0, <=, rv); databuf.pos += rv; recv_frame = user_data.frame; - CU_ASSERT(NGHTTP2_HEADERS == recv_frame->hd.type); - CU_ASSERT(framelen2 - NGHTTP2_FRAME_HDLEN == recv_frame->hd.length); + assert_uint8(NGHTTP2_HEADERS, ==, recv_frame->hd.type); + assert_size(framelen2 - NGHTTP2_FRAME_HDLEN, ==, recv_frame->hd.length); - CU_ASSERT(1 == user_data.begin_headers_cb_called); - CU_ASSERT(1 == user_data.header_cb_called); + assert_int(1, ==, user_data.begin_headers_cb_called); + assert_int(1, ==, user_data.header_cb_called); - CU_ASSERT(nghttp2_nv_equal(&nv2[0], &user_data.nv)); + assert_true(nghttp2_nv_equal(&nv2[0], &user_data.nv)); /* get 2nd header field */ user_data.begin_headers_cb_called = 0; user_data.header_cb_called = 0; - rv = - nghttp2_session_mem_recv(session, databuf.pos, nghttp2_buf_len(&databuf)); + rv = nghttp2_session_mem_recv2(session, databuf.pos, + nghttp2_buf_len(&databuf)); - CU_ASSERT(rv >= 0); + assert_ptrdiff(0, <=, rv); databuf.pos += rv; - CU_ASSERT(0 == user_data.begin_headers_cb_called); - CU_ASSERT(1 == user_data.header_cb_called); + assert_int(0, ==, user_data.begin_headers_cb_called); + assert_int(1, ==, user_data.header_cb_called); - CU_ASSERT(nghttp2_nv_equal(&nv2[1], &user_data.nv)); + assert_true(nghttp2_nv_equal(&nv2[1], &user_data.nv)); /* No input data, frame_recv_callback is called */ user_data.begin_headers_cb_called = 0; user_data.header_cb_called = 0; user_data.frame_recv_cb_called = 0; - rv = - nghttp2_session_mem_recv(session, databuf.pos, nghttp2_buf_len(&databuf)); + rv = nghttp2_session_mem_recv2(session, databuf.pos, + nghttp2_buf_len(&databuf)); - CU_ASSERT(rv >= 0); + assert_ptrdiff(0, <=, rv); databuf.pos += rv; - CU_ASSERT(0 == user_data.begin_headers_cb_called); - CU_ASSERT(0 == user_data.header_cb_called); - CU_ASSERT(1 == user_data.frame_recv_cb_called); + assert_int(0, ==, user_data.begin_headers_cb_called); + assert_int(0, ==, user_data.header_cb_called); + assert_int(1, ==, user_data.frame_recv_cb_called); /* Receive DATA */ nghttp2_frame_hd_init(&data_hd, 16, NGHTTP2_DATA, NGHTTP2_FLAG_NONE, 1); @@ -3138,26 +3311,26 @@ void test_nghttp2_session_continue(void) { databuf.last = databuf.end; user_data.frame_recv_cb_called = 0; - rv = - nghttp2_session_mem_recv(session, databuf.pos, nghttp2_buf_len(&databuf)); + rv = nghttp2_session_mem_recv2(session, databuf.pos, + nghttp2_buf_len(&databuf)); - CU_ASSERT(16 + NGHTTP2_FRAME_HDLEN == rv); - CU_ASSERT(0 == user_data.frame_recv_cb_called); + assert_ptrdiff(16 + NGHTTP2_FRAME_HDLEN, ==, rv); + assert_int(0, ==, user_data.frame_recv_cb_called); - /* Next nghttp2_session_mem_recv invokes on_frame_recv_callback and + /* Next nghttp2_session_mem_recv2 invokes on_frame_recv_callback and pause again in on_data_chunk_recv_callback since we pass same DATA frame. */ user_data.frame_recv_cb_called = 0; - rv = - nghttp2_session_mem_recv(session, databuf.pos, nghttp2_buf_len(&databuf)); - CU_ASSERT(16 + NGHTTP2_FRAME_HDLEN == rv); - CU_ASSERT(1 == user_data.frame_recv_cb_called); + rv = nghttp2_session_mem_recv2(session, databuf.pos, + nghttp2_buf_len(&databuf)); + assert_ptrdiff(16 + NGHTTP2_FRAME_HDLEN, ==, rv); + assert_int(1, ==, user_data.frame_recv_cb_called); /* And finally call on_frame_recv_callback with 0 size input */ user_data.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, NULL, 0); - CU_ASSERT(0 == rv); - CU_ASSERT(1 == user_data.frame_recv_cb_called); + rv = nghttp2_session_mem_recv2(session, NULL, 0); + assert_ptrdiff(0, ==, rv); + assert_int(1, ==, user_data.frame_recv_cb_called); nghttp2_bufs_free(&bufs); nghttp2_hd_deflate_free(&deflater); @@ -3177,12 +3350,13 @@ void test_nghttp2_session_add_frame(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = accumulator_send_callback; + callbacks.send_callback2 = accumulator_send_callback; acc.length = 0; user_data.acc = &acc; - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, &user_data)); + assert_int(0, ==, + nghttp2_session_client_new(&session, &callbacks, &user_data)); item = mem->malloc(sizeof(nghttp2_outbound_item), NULL); @@ -3199,13 +3373,14 @@ void test_nghttp2_session_add_frame(void) { session->next_stream_id += 2; - CU_ASSERT(0 == nghttp2_session_add_item(session, item)); - CU_ASSERT(NULL != nghttp2_outbound_queue_top(&session->ob_syn)); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(NGHTTP2_HEADERS == acc.buf[3]); - CU_ASSERT((NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_PRIORITY) == acc.buf[4]); + assert_int(0, ==, nghttp2_session_add_item(session, item)); + assert_not_null(nghttp2_outbound_queue_top(&session->ob_syn)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_uint8(NGHTTP2_HEADERS, ==, acc.buf[3]); + assert_uint8((NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_PRIORITY), ==, + acc.buf[4]); /* check stream id */ - CU_ASSERT(1 == nghttp2_get_uint32(&acc.buf[5])); + assert_uint32(1, ==, nghttp2_get_uint32(&acc.buf[5])); nghttp2_session_del(session); } @@ -3239,11 +3414,12 @@ void test_nghttp2_session_on_request_headers_received(void) { user_data.begin_headers_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_on_request_headers_received(session, &frame)); - CU_ASSERT(1 == user_data.begin_headers_cb_called); + assert_int(0, ==, + nghttp2_session_on_request_headers_received(session, &frame)); + assert_int(1, ==, user_data.begin_headers_cb_called); stream = nghttp2_session_get_stream(session, stream_id); - CU_ASSERT(NGHTTP2_STREAM_OPENING == stream->state); - CU_ASSERT(255 == stream->weight); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENING, ==, stream->state); + assert_int32(255, ==, stream->weight); nghttp2_frame_headers_free(&frame.headers, mem); @@ -3253,10 +3429,10 @@ void test_nghttp2_session_on_request_headers_received(void) { NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_PRIORITY, 3, NGHTTP2_HCAT_HEADERS, NULL, NULL, 0); user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_request_headers_received(session, &frame)); - CU_ASSERT(1 == user_data.invalid_frame_recv_cb_called); - CU_ASSERT(0 == (session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_request_headers_received(session, &frame)); + assert_int(1, ==, user_data.invalid_frame_recv_cb_called); + assert_false(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); nghttp2_frame_headers_free(&frame.headers, mem); session->local_settings.max_concurrent_streams = @@ -3268,10 +3444,10 @@ void test_nghttp2_session_on_request_headers_received(void) { NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_PRIORITY, 3, NGHTTP2_HCAT_HEADERS, NULL, NULL, 0); user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_request_headers_received(session, &frame)); - CU_ASSERT(0 == user_data.invalid_frame_recv_cb_called); - CU_ASSERT(0 == (session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_request_headers_received(session, &frame)); + assert_int(0, ==, user_data.invalid_frame_recv_cb_called); + assert_false(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); nghttp2_frame_headers_free(&frame.headers, mem); @@ -3281,10 +3457,10 @@ void test_nghttp2_session_on_request_headers_received(void) { NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_PRIORITY, 2, NGHTTP2_HCAT_HEADERS, NULL, NULL, 0); user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_request_headers_received(session, &frame)); - CU_ASSERT(1 == user_data.invalid_frame_recv_cb_called); - CU_ASSERT(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_request_headers_received(session, &frame)); + assert_int(1, ==, user_data.invalid_frame_recv_cb_called); + assert_true(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); nghttp2_frame_headers_free(&frame.headers, mem); @@ -3300,9 +3476,10 @@ void test_nghttp2_session_on_request_headers_received(void) { 1, NGHTTP2_HCAT_HEADERS, NULL, nva, nvlen); user_data.begin_headers_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_on_request_headers_received(session, &frame)); - CU_ASSERT(1 == user_data.begin_headers_cb_called); - CU_ASSERT(0 == user_data.invalid_frame_recv_cb_called); + assert_int(0, ==, + nghttp2_session_on_request_headers_received(session, &frame)); + assert_int(1, ==, user_data.begin_headers_cb_called); + assert_int(0, ==, user_data.invalid_frame_recv_cb_called); nghttp2_frame_headers_free(&frame.headers, mem); @@ -3316,10 +3493,10 @@ void test_nghttp2_session_on_request_headers_received(void) { NGHTTP2_HCAT_REQUEST, NULL, NULL, 0); user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_request_headers_received(session, &frame)); - CU_ASSERT(1 == user_data.invalid_frame_recv_cb_called); - CU_ASSERT(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_request_headers_received(session, &frame)); + assert_int(1, ==, user_data.invalid_frame_recv_cb_called); + assert_true(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); nghttp2_frame_headers_free(&frame.headers, mem); @@ -3332,10 +3509,10 @@ void test_nghttp2_session_on_request_headers_received(void) { NGHTTP2_HCAT_REQUEST, NULL, NULL, 0); user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_request_headers_received(session, &frame)); - CU_ASSERT(1 == user_data.invalid_frame_recv_cb_called); - CU_ASSERT(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_request_headers_received(session, &frame)); + assert_int(1, ==, user_data.invalid_frame_recv_cb_called); + assert_true(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); nghttp2_frame_headers_free(&frame.headers, mem); @@ -3352,10 +3529,10 @@ void test_nghttp2_session_on_request_headers_received(void) { NGHTTP2_HCAT_REQUEST, NULL, NULL, 0); user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_request_headers_received(session, &frame)); - CU_ASSERT(0 == user_data.invalid_frame_recv_cb_called); - CU_ASSERT(0 == (session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_request_headers_received(session, &frame)); + assert_int(0, ==, user_data.invalid_frame_recv_cb_called); + assert_false(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); nghttp2_frame_headers_free(&frame.headers, mem); @@ -3369,7 +3546,8 @@ void test_nghttp2_session_on_request_headers_received(void) { nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS, 3, NGHTTP2_HCAT_REQUEST, NULL, NULL, 0); - CU_ASSERT(0 == nghttp2_session_on_request_headers_received(session, &frame)); + assert_int(0, ==, + nghttp2_session_on_request_headers_received(session, &frame)); nghttp2_frame_headers_free(&frame.headers, mem); @@ -3379,10 +3557,10 @@ void test_nghttp2_session_on_request_headers_received(void) { session->goaway_flags |= NGHTTP2_GOAWAY_SENT; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_request_headers_received(session, &frame)); - CU_ASSERT(0 == user_data.invalid_frame_recv_cb_called); - CU_ASSERT(0 == (session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_request_headers_received(session, &frame)); + assert_int(0, ==, user_data.invalid_frame_recv_cb_called); + assert_false(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); nghttp2_frame_headers_free(&frame.headers, mem); @@ -3398,9 +3576,9 @@ void test_nghttp2_session_on_request_headers_received(void) { nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS, 1, NGHTTP2_HCAT_REQUEST, NULL, NULL, 0); - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_request_headers_received(session, &frame)); - CU_ASSERT(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_request_headers_received(session, &frame)); + assert_true(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); nghttp2_frame_headers_free(&frame.headers, mem); @@ -3428,10 +3606,11 @@ void test_nghttp2_session_on_response_headers_received(void) { user_data.begin_headers_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_on_response_headers_received(session, &frame, - stream)); - CU_ASSERT(1 == user_data.begin_headers_cb_called); - CU_ASSERT(NGHTTP2_STREAM_OPENED == stream->state); + assert_int( + 0, ==, + nghttp2_session_on_response_headers_received(session, &frame, stream)); + assert_int(1, ==, user_data.begin_headers_cb_called); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENED, ==, stream->state); nghttp2_frame_headers_free(&frame.headers, mem); nghttp2_session_del(session); @@ -3459,26 +3638,28 @@ void test_nghttp2_session_on_headers_received(void) { user_data.begin_headers_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_on_headers_received(session, &frame, stream)); - CU_ASSERT(1 == user_data.begin_headers_cb_called); - CU_ASSERT(NGHTTP2_STREAM_OPENED == stream->state); + assert_int(0, ==, + nghttp2_session_on_headers_received(session, &frame, stream)); + assert_int(1, ==, user_data.begin_headers_cb_called); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENED, ==, stream->state); /* stream closed */ frame.hd.flags |= NGHTTP2_FLAG_END_STREAM; - CU_ASSERT(0 == nghttp2_session_on_headers_received(session, &frame, stream)); - CU_ASSERT(2 == user_data.begin_headers_cb_called); + assert_int(0, ==, + nghttp2_session_on_headers_received(session, &frame, stream)); + assert_int(2, ==, user_data.begin_headers_cb_called); /* Check to see when NGHTTP2_STREAM_CLOSING, incoming HEADERS is discarded. */ stream = open_sent_stream2(session, 3, NGHTTP2_STREAM_CLOSING); frame.hd.stream_id = 3; frame.hd.flags = NGHTTP2_FLAG_END_HEADERS; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_headers_received(session, &frame, stream)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_headers_received(session, &frame, stream)); /* See no counters are updated */ - CU_ASSERT(2 == user_data.begin_headers_cb_called); - CU_ASSERT(0 == user_data.invalid_frame_recv_cb_called); + assert_int(2, ==, user_data.begin_headers_cb_called); + assert_int(0, ==, user_data.invalid_frame_recv_cb_called); /* Server initiated stream */ stream = open_recv_stream(session, 2); @@ -3486,16 +3667,17 @@ void test_nghttp2_session_on_headers_received(void) { frame.hd.flags = NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM; frame.hd.stream_id = 2; - CU_ASSERT(0 == nghttp2_session_on_headers_received(session, &frame, stream)); - CU_ASSERT(3 == user_data.begin_headers_cb_called); - CU_ASSERT(NGHTTP2_STREAM_OPENED == stream->state); + assert_int(0, ==, + nghttp2_session_on_headers_received(session, &frame, stream)); + assert_int(3, ==, user_data.begin_headers_cb_called); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENED, ==, stream->state); nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_RD); /* Further reception of HEADERS is subject to stream error */ - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_headers_received(session, &frame, stream)); - CU_ASSERT(1 == user_data.invalid_frame_recv_cb_called); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_headers_received(session, &frame, stream)); + assert_int(1, ==, user_data.invalid_frame_recv_cb_called); nghttp2_frame_headers_free(&frame.headers, mem); @@ -3513,7 +3695,7 @@ void test_nghttp2_session_on_push_response_headers_received(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_begin_headers_callback = on_begin_headers_callback; callbacks.on_invalid_frame_recv_callback = on_invalid_frame_recv_callback; @@ -3528,31 +3710,32 @@ void test_nghttp2_session_on_push_response_headers_received(void) { user_data.begin_headers_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(1 == session->num_incoming_reserved_streams); - CU_ASSERT(0 == nghttp2_session_on_push_response_headers_received( - session, &frame, stream)); - CU_ASSERT(1 == user_data.begin_headers_cb_called); - CU_ASSERT(0 == session->num_incoming_reserved_streams); - CU_ASSERT(NGHTTP2_STREAM_OPENED == stream->state); - CU_ASSERT(1 == session->num_incoming_streams); - CU_ASSERT(0 == (stream->flags & NGHTTP2_STREAM_FLAG_PUSH)); + assert_size(1, ==, session->num_incoming_reserved_streams); + assert_int(0, ==, + nghttp2_session_on_push_response_headers_received(session, &frame, + stream)); + assert_int(1, ==, user_data.begin_headers_cb_called); + assert_size(0, ==, session->num_incoming_reserved_streams); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENED, ==, stream->state); + assert_size(1, ==, session->num_incoming_streams); + assert_false(stream->flags & NGHTTP2_STREAM_FLAG_PUSH); /* If un-ACKed max concurrent streams limit is exceeded, RST_STREAMed */ session->pending_local_max_concurrent_stream = 1; stream = open_recv_stream2(session, 4, NGHTTP2_STREAM_RESERVED); frame.hd.stream_id = 4; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_push_response_headers_received(session, &frame, - stream)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_push_response_headers_received(session, &frame, + stream)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(NGHTTP2_REFUSED_STREAM == item->frame.rst_stream.error_code); - CU_ASSERT(1 == session->num_incoming_streams); - CU_ASSERT(1 == session->num_incoming_reserved_streams); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_REFUSED_STREAM, ==, item->frame.rst_stream.error_code); + assert_size(1, ==, session->num_incoming_streams); + assert_size(1, ==, session->num_incoming_reserved_streams); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == session->num_incoming_streams); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(1, ==, session->num_incoming_streams); /* If ACKed max concurrent streams limit is exceeded, GOAWAY is issued */ @@ -3561,14 +3744,14 @@ void test_nghttp2_session_on_push_response_headers_received(void) { stream = open_recv_stream2(session, 6, NGHTTP2_STREAM_RESERVED); frame.hd.stream_id = 6; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_push_response_headers_received(session, &frame, - stream)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_push_response_headers_received(session, &frame, + stream)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); - CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == item->frame.goaway.error_code); - CU_ASSERT(1 == session->num_incoming_streams); - CU_ASSERT(1 == session->num_incoming_reserved_streams); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_PROTOCOL_ERROR, ==, item->frame.goaway.error_code); + assert_size(1, ==, session->num_incoming_streams); + assert_size(1, ==, session->num_incoming_reserved_streams); nghttp2_frame_headers_free(&frame.headers, mem); nghttp2_session_del(session); @@ -3595,9 +3778,9 @@ void test_nghttp2_session_on_priority_received(void) { nghttp2_frame_priority_init(&frame.priority, 1, &pri_spec); /* depend on stream 0 */ - CU_ASSERT(0 == nghttp2_session_on_priority_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_priority_received(session, &frame)); - CU_ASSERT(2 == stream->weight); + assert_int32(2, ==, stream->weight); stream = open_sent_stream(session, 2); dep_stream = open_recv_stream(session, 3); @@ -3607,19 +3790,19 @@ void test_nghttp2_session_on_priority_received(void) { /* using dependency stream */ nghttp2_priority_spec_init(&frame.priority.pri_spec, 3, 1, 0); - CU_ASSERT(0 == nghttp2_session_on_priority_received(session, &frame)); - CU_ASSERT(dep_stream == stream->dep_prev); + assert_int(0, ==, nghttp2_session_on_priority_received(session, &frame)); + assert_ptr_equal(dep_stream, stream->dep_prev); /* PRIORITY against idle stream */ frame.hd.stream_id = 100; - CU_ASSERT(0 == nghttp2_session_on_priority_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_priority_received(session, &frame)); stream = nghttp2_session_get_stream_raw(session, frame.hd.stream_id); - CU_ASSERT(NGHTTP2_STREAM_IDLE == stream->state); - CU_ASSERT(dep_stream == stream->dep_prev); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_IDLE, ==, stream->state); + assert_ptr_equal(dep_stream, stream->dep_prev); nghttp2_frame_priority_free(&frame.priority); nghttp2_session_del(session); @@ -3632,11 +3815,11 @@ void test_nghttp2_session_on_priority_received(void) { nghttp2_frame_priority_init(&frame.priority, 1, &pri_spec); - CU_ASSERT(0 == nghttp2_session_on_priority_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_priority_received(session, &frame)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); nghttp2_frame_priority_free(&frame.priority); nghttp2_session_del(session); @@ -3648,11 +3831,11 @@ void test_nghttp2_session_on_priority_received(void) { nghttp2_frame_priority_init(&frame.priority, 1, &pri_spec); - CU_ASSERT(0 == nghttp2_session_on_priority_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_priority_received(session, &frame)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); nghttp2_frame_priority_free(&frame.priority); nghttp2_session_del(session); @@ -3669,8 +3852,8 @@ void test_nghttp2_session_on_rst_stream_received(void) { nghttp2_frame_rst_stream_init(&frame.rst_stream, 1, NGHTTP2_PROTOCOL_ERROR); - CU_ASSERT(0 == nghttp2_session_on_rst_stream_received(session, &frame)); - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 1)); + assert_int(0, ==, nghttp2_session_on_rst_stream_received(session, &frame)); + assert_null(nghttp2_session_get_stream(session, 1)); nghttp2_frame_rst_stream_free(&frame.rst_stream); nghttp2_session_del(session); @@ -3691,7 +3874,7 @@ void test_nghttp2_session_on_settings_received(void) { uint8_t data[2048]; nghttp2_frame_hd hd; int rv; - ssize_t nread; + nghttp2_ssize nread; nghttp2_stream *stream; mem = nghttp2_mem_default(); @@ -3712,7 +3895,7 @@ void test_nghttp2_session_on_settings_received(void) { iv[4].value = 0; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, &user_data); session->remote_settings.initial_window_size = 16 * 1024; @@ -3728,26 +3911,29 @@ void test_nghttp2_session_on_settings_received(void) { nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_NONE, dup_iv(iv, niv), niv); - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &frame, 0)); - CU_ASSERT(1000000009 == session->remote_settings.max_concurrent_streams); - CU_ASSERT(64 * 1024 == session->remote_settings.initial_window_size); - CU_ASSERT(1024 == session->remote_settings.header_table_size); - CU_ASSERT(0 == session->remote_settings.enable_push); + assert_int(0, ==, nghttp2_session_on_settings_received(session, &frame, 0)); + assert_uint32(1000000009, ==, + session->remote_settings.max_concurrent_streams); + assert_uint32(64 * 1024, ==, session->remote_settings.initial_window_size); + assert_uint32(1024, ==, session->remote_settings.header_table_size); + assert_uint32(0, ==, session->remote_settings.enable_push); - CU_ASSERT(64 * 1024 == stream1->remote_window_size); - CU_ASSERT(0 == stream2->remote_window_size); + assert_int32(64 * 1024, ==, stream1->remote_window_size); + assert_int32(0, ==, stream2->remote_window_size); frame.settings.iv[2].value = 16 * 1024; - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &frame, 0)); + assert_int(0, ==, nghttp2_session_on_settings_received(session, &frame, 0)); - CU_ASSERT(16 * 1024 == stream1->remote_window_size); - CU_ASSERT(-48 * 1024 == stream2->remote_window_size); + assert_int32(16 * 1024, ==, stream1->remote_window_size); + assert_int32(-48 * 1024, ==, stream2->remote_window_size); - CU_ASSERT(16 * 1024 == nghttp2_session_get_stream_remote_window_size( - session, stream1->stream_id)); - CU_ASSERT(0 == nghttp2_session_get_stream_remote_window_size( - session, stream2->stream_id)); + assert_int32(16 * 1024, ==, + nghttp2_session_get_stream_remote_window_size( + session, stream1->stream_id)); + assert_int32(0, ==, + nghttp2_session_get_stream_remote_window_size( + session, stream2->stream_id)); nghttp2_frame_settings_free(&frame.settings, mem); @@ -3757,10 +3943,10 @@ void test_nghttp2_session_on_settings_received(void) { nghttp2_session_server_new(&session, &callbacks, NULL); nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_ACK, dup_iv(iv, 1), 1); - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &frame, 0)); + assert_int(0, ==, nghttp2_session_on_settings_received(session, &frame, 0)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(item != NULL); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); + assert_not_null(item); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); nghttp2_frame_settings_free(&frame.settings, mem); nghttp2_session_del(session); @@ -3769,10 +3955,10 @@ void test_nghttp2_session_on_settings_received(void) { nghttp2_session_server_new(&session, &callbacks, NULL); nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_ACK, NULL, 0); - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &frame, 0)); + assert_int(0, ==, nghttp2_session_on_settings_received(session, &frame, 0)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(item != NULL); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); + assert_not_null(item); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); nghttp2_frame_settings_free(&frame.settings, mem); nghttp2_session_del(session); @@ -3781,11 +3967,11 @@ void test_nghttp2_session_on_settings_received(void) { and header table size is once cleared to 0. */ nghttp2_session_client_new(&session, &callbacks, NULL); - nghttp2_submit_request(session, NULL, &nv, 1, NULL, NULL); + nghttp2_submit_request2(session, NULL, &nv, 1, NULL, NULL); nghttp2_session_send(session); - CU_ASSERT(session->hd_deflater.ctx.hd_table.len > 0); + assert_size(0, <, session->hd_deflater.ctx.hd_table.len); iv[0].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE; iv[0].value = 0; @@ -3796,11 +3982,11 @@ void test_nghttp2_session_on_settings_received(void) { nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_NONE, dup_iv(iv, 2), 2); - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &frame, 0)); + assert_int(0, ==, nghttp2_session_on_settings_received(session, &frame, 0)); - CU_ASSERT(0 == session->hd_deflater.ctx.hd_table.len); - CU_ASSERT(2048 == session->hd_deflater.ctx.hd_table_bufsize_max); - CU_ASSERT(2048 == session->remote_settings.header_table_size); + assert_size(0, ==, session->hd_deflater.ctx.hd_table.len); + assert_size(2048, ==, session->hd_deflater.ctx.hd_table_bufsize_max); + assert_uint32(2048, ==, session->remote_settings.header_table_size); nghttp2_frame_settings_free(&frame.settings, mem); nghttp2_session_del(session); @@ -3811,12 +3997,12 @@ void test_nghttp2_session_on_settings_received(void) { nghttp2_option_new(&option); nghttp2_option_set_peer_max_concurrent_streams(option, 1000); nghttp2_session_client_new2(&session, &callbacks, NULL, option); - CU_ASSERT(1000 == session->remote_settings.max_concurrent_streams); + assert_uint32(1000, ==, session->remote_settings.max_concurrent_streams); nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_NONE, NULL, 0); - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &frame, 0)); - CU_ASSERT(NGHTTP2_DEFAULT_MAX_CONCURRENT_STREAMS == - session->remote_settings.max_concurrent_streams); + assert_int(0, ==, nghttp2_session_on_settings_received(session, &frame, 0)); + assert_uint32(NGHTTP2_DEFAULT_MAX_CONCURRENT_STREAMS, ==, + session->remote_settings.max_concurrent_streams); nghttp2_frame_settings_free(&frame.settings, mem); nghttp2_session_del(session); @@ -3831,12 +4017,12 @@ void test_nghttp2_session_on_settings_received(void) { nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_NONE, dup_iv(iv, 1), 1); - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &frame, 0)); + assert_int(0, ==, nghttp2_session_on_settings_received(session, &frame, 0)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(item != NULL); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); + assert_not_null(item); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); nghttp2_frame_settings_free(&frame.settings, mem); nghttp2_session_del(session); @@ -3850,7 +4036,7 @@ void test_nghttp2_session_on_settings_received(void) { nghttp2_frame_window_update_init(&frame.window_update, NGHTTP2_FLAG_NONE, 1, 1); - CU_ASSERT(0 == nghttp2_session_on_window_update_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_window_update_received(session, &frame)); nghttp2_frame_window_update_free(&frame.window_update); @@ -3862,20 +4048,20 @@ void test_nghttp2_session_on_settings_received(void) { /* Now window size gets NGHTTP2_MAX_WINDOW_SIZE + 1, which is unacceptable situation in protocol spec. */ - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &frame, 0)); + assert_int(0, ==, nghttp2_session_on_settings_received(session, &frame, 0)); nghttp2_frame_settings_free(&frame.settings, mem); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_SETTINGS == item->frame.hd.type); + assert_not_null(item); + assert_uint8(NGHTTP2_SETTINGS, ==, item->frame.hd.type); item = nghttp2_outbound_queue_top(&session->ob_reg); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(NGHTTP2_STREAM_CLOSING == stream1->state); + assert_not_null(item); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_CLOSING, ==, stream1->state); nghttp2_session_del(session); @@ -3891,14 +4077,14 @@ void test_nghttp2_session_on_settings_received(void) { nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_NONE, dup_iv(iv, 1), 1); - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &frame, 0)); + assert_int(0, ==, nghttp2_session_on_settings_received(session, &frame, 0)); nghttp2_frame_settings_free(&frame.settings, mem); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); + assert_not_null(item); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); nghttp2_session_del(session); @@ -3915,11 +4101,11 @@ void test_nghttp2_session_on_settings_received(void) { rv = nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 1); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); stream = open_recv_stream(session, 1); @@ -3931,31 +4117,31 @@ void test_nghttp2_session_on_settings_received(void) { nghttp2_frame_pack_frame_hd(data, &hd); nread = - nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + hd.length); + nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + hd.length); - CU_ASSERT((ssize_t)(NGHTTP2_FRAME_HDLEN + hd.length) == nread); + assert_ptrdiff((nghttp2_ssize)(NGHTTP2_FRAME_HDLEN + hd.length), ==, nread); rv = nghttp2_session_consume(session, 1, hd.length); - CU_ASSERT(0 == rv); - CU_ASSERT((int32_t)hd.length == stream->recv_window_size); - CU_ASSERT((int32_t)hd.length == stream->consumed_size); + assert_int(0, ==, rv); + assert_int32((int32_t)hd.length, ==, stream->recv_window_size); + assert_int32((int32_t)hd.length, ==, stream->consumed_size); nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_ACK, NULL, 0); rv = nghttp2_session_on_settings_received(session, &frame, 0); - CU_ASSERT(0 == rv); - CU_ASSERT(1024 == stream->local_window_size); - CU_ASSERT(0 == stream->recv_window_size); - CU_ASSERT(0 == stream->consumed_size); + assert_int(0, ==, rv); + assert_int32(1024, ==, stream->local_window_size); + assert_int32(0, ==, stream->recv_window_size); + assert_int32(0, ==, stream->consumed_size); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); - CU_ASSERT((int32_t)hd.length == - item->frame.window_update.window_size_increment); + assert_not_null(item); + assert_uint8(NGHTTP2_WINDOW_UPDATE, ==, item->frame.hd.type); + assert_int32((int32_t)hd.length, ==, + item->frame.window_update.window_size_increment); nghttp2_session_del(session); nghttp2_option_del(option); @@ -3972,14 +4158,14 @@ void test_nghttp2_session_on_settings_received(void) { nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_NONE, dup_iv(iv, 1), 1); - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &frame, 0)); + assert_int(0, ==, nghttp2_session_on_settings_received(session, &frame, 0)); nghttp2_frame_settings_free(&frame.settings, mem); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); + assert_not_null(item); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); nghttp2_session_del(session); } @@ -3999,7 +4185,7 @@ void test_nghttp2_session_on_push_promise_received(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_begin_headers_callback = on_begin_headers_callback; callbacks.on_invalid_frame_recv_callback = on_invalid_frame_recv_callback; @@ -4013,13 +4199,14 @@ void test_nghttp2_session_on_push_promise_received(void) { user_data.begin_headers_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_on_push_promise_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_push_promise_received(session, &frame)); - CU_ASSERT(1 == user_data.begin_headers_cb_called); - CU_ASSERT(1 == session->num_incoming_reserved_streams); + assert_int(1, ==, user_data.begin_headers_cb_called); + assert_size(1, ==, session->num_incoming_reserved_streams); promised_stream = nghttp2_session_get_stream(session, 2); - CU_ASSERT(NGHTTP2_STREAM_RESERVED == promised_stream->state); - CU_ASSERT(2 == session->last_recv_stream_id); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_RESERVED, ==, + promised_stream->state); + assert_int32(2, ==, session->last_recv_stream_id); /* Attempt to PUSH_PROMISE against half close (remote) */ nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_RD); @@ -4027,18 +4214,18 @@ void test_nghttp2_session_on_push_promise_received(void) { user_data.begin_headers_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_push_promise_received(session, &frame)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_push_promise_received(session, &frame)); - CU_ASSERT(0 == user_data.begin_headers_cb_called); - CU_ASSERT(1 == user_data.invalid_frame_recv_cb_called); - CU_ASSERT(1 == session->num_incoming_reserved_streams); - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 4)); + assert_int(0, ==, user_data.begin_headers_cb_called); + assert_int(1, ==, user_data.invalid_frame_recv_cb_called); + assert_size(1, ==, session->num_incoming_reserved_streams); + assert_null(nghttp2_session_get_stream(session, 4)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); - CU_ASSERT(NGHTTP2_STREAM_CLOSED == item->frame.goaway.error_code); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(4 == session->last_recv_stream_id); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_STREAM_CLOSED, ==, item->frame.goaway.error_code); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int32(4, ==, session->last_recv_stream_id); nghttp2_session_del(session); @@ -4052,17 +4239,17 @@ void test_nghttp2_session_on_push_promise_received(void) { user_data.begin_headers_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_push_promise_received(session, &frame)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_push_promise_received(session, &frame)); - CU_ASSERT(0 == user_data.begin_headers_cb_called); - CU_ASSERT(0 == session->num_incoming_reserved_streams); - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 6)); + assert_int(0, ==, user_data.begin_headers_cb_called); + assert_size(0, ==, session->num_incoming_reserved_streams); + assert_null(nghttp2_session_get_stream(session, 6)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(6 == item->frame.hd.stream_id); - CU_ASSERT(NGHTTP2_CANCEL == item->frame.rst_stream.error_code); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_int32(6, ==, item->frame.hd.stream_id); + assert_uint32(NGHTTP2_CANCEL, ==, item->frame.rst_stream.error_code); + assert_int(0, ==, nghttp2_session_send(session)); /* Attempt to PUSH_PROMISE against idle stream */ frame.hd.stream_id = 3; @@ -4070,17 +4257,17 @@ void test_nghttp2_session_on_push_promise_received(void) { user_data.begin_headers_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_push_promise_received(session, &frame)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_push_promise_received(session, &frame)); - CU_ASSERT(0 == user_data.begin_headers_cb_called); - CU_ASSERT(0 == session->num_incoming_reserved_streams); - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 8)); + assert_int(0, ==, user_data.begin_headers_cb_called); + assert_size(0, ==, session->num_incoming_reserved_streams); + assert_null(nghttp2_session_get_stream(session, 8)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); - CU_ASSERT(0 == item->frame.hd.stream_id); - CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == item->frame.goaway.error_code); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); + assert_int32(0, ==, item->frame.hd.stream_id); + assert_uint32(NGHTTP2_PROTOCOL_ERROR, ==, item->frame.goaway.error_code); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_session_del(session); @@ -4094,37 +4281,37 @@ void test_nghttp2_session_on_push_promise_received(void) { user_data.begin_headers_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_on_push_promise_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_push_promise_received(session, &frame)); - CU_ASSERT(1 == user_data.begin_headers_cb_called); - CU_ASSERT(1 == session->num_incoming_reserved_streams); - CU_ASSERT(NULL != nghttp2_session_get_stream(session, 2)); + assert_int(1, ==, user_data.begin_headers_cb_called); + assert_size(1, ==, session->num_incoming_reserved_streams); + assert_not_null(nghttp2_session_get_stream(session, 2)); user_data.begin_headers_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_push_promise_received(session, &frame)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_push_promise_received(session, &frame)); - CU_ASSERT(0 == user_data.begin_headers_cb_called); - CU_ASSERT(1 == session->num_incoming_reserved_streams); - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 8)); + assert_int(0, ==, user_data.begin_headers_cb_called); + assert_size(1, ==, session->num_incoming_reserved_streams); + assert_null(nghttp2_session_get_stream(session, 8)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); - CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == item->frame.goaway.error_code); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_PROTOCOL_ERROR, ==, item->frame.goaway.error_code); + assert_int(0, ==, nghttp2_session_send(session)); /* After GOAWAY, PUSH_PROMISE will be discarded */ frame.push_promise.promised_stream_id = 10; user_data.begin_headers_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_push_promise_received(session, &frame)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_push_promise_received(session, &frame)); - CU_ASSERT(0 == user_data.begin_headers_cb_called); - CU_ASSERT(1 == session->num_incoming_reserved_streams); - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 10)); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_int(0, ==, user_data.begin_headers_cb_called); + assert_size(1, ==, session->num_incoming_reserved_streams); + assert_null(nghttp2_session_get_stream(session, 10)); + assert_null(nghttp2_session_get_next_ob_item(session)); nghttp2_frame_push_promise_free(&frame.push_promise, mem); nghttp2_session_del(session); @@ -4139,12 +4326,12 @@ void test_nghttp2_session_on_push_promise_received(void) { user_data.begin_headers_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_push_promise_received(session, &frame)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_push_promise_received(session, &frame)); - CU_ASSERT(0 == user_data.begin_headers_cb_called); - CU_ASSERT(1 == user_data.invalid_frame_recv_cb_called); - CU_ASSERT(1 == session->num_incoming_reserved_streams); + assert_int(0, ==, user_data.begin_headers_cb_called); + assert_int(1, ==, user_data.invalid_frame_recv_cb_called); + assert_size(1, ==, session->num_incoming_reserved_streams); nghttp2_frame_push_promise_free(&frame.push_promise, mem); nghttp2_session_del(session); @@ -4161,12 +4348,12 @@ void test_nghttp2_session_on_push_promise_received(void) { user_data.begin_headers_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_push_promise_received(session, &frame)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_push_promise_received(session, &frame)); - CU_ASSERT(0 == user_data.begin_headers_cb_called); - CU_ASSERT(1 == user_data.invalid_frame_recv_cb_called); - CU_ASSERT(0 == session->num_incoming_reserved_streams); + assert_int(0, ==, user_data.begin_headers_cb_called); + assert_int(1, ==, user_data.invalid_frame_recv_cb_called); + assert_size(0, ==, session->num_incoming_reserved_streams); nghttp2_frame_push_promise_free(&frame.push_promise, mem); nghttp2_session_del(session); @@ -4182,10 +4369,10 @@ void test_nghttp2_session_on_push_promise_received(void) { 1, 2, nva, nvlen); user_data.begin_headers_cb_called = 0; user_data.invalid_frame_recv_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_on_push_promise_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_push_promise_received(session, &frame)); - CU_ASSERT(1 == user_data.begin_headers_cb_called); - CU_ASSERT(0 == user_data.invalid_frame_recv_cb_called); + assert_int(1, ==, user_data.begin_headers_cb_called); + assert_int(0, ==, user_data.invalid_frame_recv_cb_called); nghttp2_frame_push_promise_free(&frame.push_promise, mem); nghttp2_session_del(session); @@ -4202,10 +4389,10 @@ void test_nghttp2_session_on_push_promise_received(void) { nghttp2_frame_push_promise_init(&frame.push_promise, NGHTTP2_FLAG_END_HEADERS, 1, 2, NULL, 0); - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_push_promise_received(session, &frame)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_push_promise_received(session, &frame)); - CU_ASSERT(0 == session->num_incoming_reserved_streams); + assert_size(0, ==, session->num_incoming_reserved_streams); nghttp2_frame_push_promise_free(&frame.push_promise, mem); nghttp2_session_del(session); @@ -4217,20 +4404,20 @@ void test_nghttp2_session_on_push_promise_received(void) { open_sent_stream(session, 1); open_recv_stream2(session, 2, NGHTTP2_STREAM_RESERVED); - CU_ASSERT(1 == session->num_incoming_reserved_streams); + assert_size(1, ==, session->num_incoming_reserved_streams); nghttp2_frame_push_promise_init(&frame.push_promise, NGHTTP2_FLAG_END_HEADERS, 1, 4, NULL, 0); - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_push_promise_received(session, &frame)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_push_promise_received(session, &frame)); - CU_ASSERT(1 == session->num_incoming_reserved_streams); + assert_size(1, ==, session->num_incoming_reserved_streams); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(NGHTTP2_CANCEL == item->frame.rst_stream.error_code); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_CANCEL, ==, item->frame.rst_stream.error_code); nghttp2_frame_push_promise_free(&frame.push_promise, mem); nghttp2_session_del(session); @@ -4255,22 +4442,22 @@ void test_nghttp2_session_on_ping_received(void) { nghttp2_session_client_new(&session, &callbacks, &user_data); nghttp2_frame_ping_init(&frame.ping, NGHTTP2_FLAG_ACK, opaque_data); - CU_ASSERT(0 == nghttp2_session_on_ping_received(session, &frame)); - CU_ASSERT(1 == user_data.frame_recv_cb_called); + assert_int(0, ==, nghttp2_session_on_ping_received(session, &frame)); + assert_int(1, ==, user_data.frame_recv_cb_called); /* Since this ping frame has ACK flag set, no further action is performed. */ - CU_ASSERT(NULL == nghttp2_outbound_queue_top(&session->ob_urgent)); + assert_null(nghttp2_outbound_queue_top(&session->ob_urgent)); /* Clear the flag, and receive it again */ frame.hd.flags = NGHTTP2_FLAG_NONE; - CU_ASSERT(0 == nghttp2_session_on_ping_received(session, &frame)); - CU_ASSERT(2 == user_data.frame_recv_cb_called); + assert_int(0, ==, nghttp2_session_on_ping_received(session, &frame)); + assert_int(2, ==, user_data.frame_recv_cb_called); top = nghttp2_outbound_queue_top(&session->ob_urgent); - CU_ASSERT(NGHTTP2_PING == top->frame.hd.type); - CU_ASSERT(NGHTTP2_FLAG_ACK == top->frame.hd.flags); - CU_ASSERT(memcmp(opaque_data, top->frame.ping.opaque_data, 8) == 0); + assert_uint8(NGHTTP2_PING, ==, top->frame.hd.type); + assert_uint8(NGHTTP2_FLAG_ACK, ==, top->frame.hd.flags); + assert_memory_equal(8, opaque_data, top->frame.ping.opaque_data); nghttp2_frame_ping_free(&frame.ping); nghttp2_session_del(session); @@ -4284,9 +4471,9 @@ void test_nghttp2_session_on_ping_received(void) { user_data.frame_recv_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_on_ping_received(session, &frame)); - CU_ASSERT(1 == user_data.frame_recv_cb_called); - CU_ASSERT(NULL == nghttp2_outbound_queue_top(&session->ob_urgent)); + assert_int(0, ==, nghttp2_session_on_ping_received(session, &frame)); + assert_int(1, ==, user_data.frame_recv_cb_called); + assert_null(nghttp2_outbound_queue_top(&session->ob_urgent)); nghttp2_frame_ping_free(&frame.ping); nghttp2_session_del(session); @@ -4301,7 +4488,7 @@ void test_nghttp2_session_on_goaway_received(void) { int i; nghttp2_mem *mem; const uint8_t *data; - ssize_t datalen; + nghttp2_ssize datalen; mem = nghttp2_mem_default(); user_data.frame_recv_cb_called = 0; @@ -4326,20 +4513,20 @@ void test_nghttp2_session_on_goaway_received(void) { user_data.stream_close_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_on_goaway_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_goaway_received(session, &frame)); - CU_ASSERT(1 == user_data.frame_recv_cb_called); - CU_ASSERT(3 == session->remote_last_stream_id); + assert_int(1, ==, user_data.frame_recv_cb_called); + assert_int32(3, ==, session->remote_last_stream_id); /* on_stream_close should be callsed for 2 times (stream 5 and 7) */ - CU_ASSERT(2 == user_data.stream_close_cb_called); + assert_int(2, ==, user_data.stream_close_cb_called); - CU_ASSERT(NULL != nghttp2_session_get_stream(session, 1)); - CU_ASSERT(NULL != nghttp2_session_get_stream(session, 2)); - CU_ASSERT(NULL != nghttp2_session_get_stream(session, 3)); - CU_ASSERT(NULL != nghttp2_session_get_stream(session, 4)); - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 5)); - CU_ASSERT(NULL != nghttp2_session_get_stream(session, 6)); - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 7)); + assert_not_null(nghttp2_session_get_stream(session, 1)); + assert_not_null(nghttp2_session_get_stream(session, 2)); + assert_not_null(nghttp2_session_get_stream(session, 3)); + assert_not_null(nghttp2_session_get_stream(session, 4)); + assert_null(nghttp2_session_get_stream(session, 5)); + assert_not_null(nghttp2_session_get_stream(session, 6)); + assert_null(nghttp2_session_get_stream(session, 7)); nghttp2_frame_goaway_free(&frame.goaway, mem); nghttp2_session_del(session); @@ -4355,14 +4542,14 @@ void test_nghttp2_session_on_goaway_received(void) { nghttp2_frame_goaway_init(&frame.goaway, 0, NGHTTP2_NO_ERROR, NULL, 0); - CU_ASSERT(0 == nghttp2_session_on_goaway_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_goaway_received(session, &frame)); - nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); + nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); - datalen = nghttp2_session_mem_send(session, &data); + datalen = nghttp2_session_mem_send2(session, &data); - CU_ASSERT(NGHTTP2_ERR_CALLBACK_FAILURE == datalen); - CU_ASSERT(1 == user_data.stream_close_cb_called); + assert_ptrdiff(NGHTTP2_ERR_CALLBACK_FAILURE, ==, datalen); + assert_int(1, ==, user_data.stream_close_cb_called); nghttp2_frame_goaway_free(&frame.goaway, mem); nghttp2_session_del(session); @@ -4391,23 +4578,23 @@ void test_nghttp2_session_on_window_update_received(void) { data_item = create_data_ob_item(mem); - CU_ASSERT(0 == nghttp2_stream_attach_item(stream, data_item)); + assert_int(0, ==, nghttp2_stream_attach_item(stream, data_item)); nghttp2_frame_window_update_init(&frame.window_update, NGHTTP2_FLAG_NONE, 1, 16 * 1024); - CU_ASSERT(0 == nghttp2_session_on_window_update_received(session, &frame)); - CU_ASSERT(1 == user_data.frame_recv_cb_called); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE + 16 * 1024 == - stream->remote_window_size); + assert_int(0, ==, nghttp2_session_on_window_update_received(session, &frame)); + assert_int(1, ==, user_data.frame_recv_cb_called); + assert_int32(NGHTTP2_INITIAL_WINDOW_SIZE + 16 * 1024, ==, + stream->remote_window_size); nghttp2_stream_defer_item(stream, NGHTTP2_STREAM_FLAG_DEFERRED_FLOW_CONTROL); - CU_ASSERT(0 == nghttp2_session_on_window_update_received(session, &frame)); - CU_ASSERT(2 == user_data.frame_recv_cb_called); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE + 16 * 1024 * 2 == - stream->remote_window_size); - CU_ASSERT(0 == (stream->flags & NGHTTP2_STREAM_FLAG_DEFERRED_ALL)); + assert_int(0, ==, nghttp2_session_on_window_update_received(session, &frame)); + assert_int(2, ==, user_data.frame_recv_cb_called); + assert_int32(NGHTTP2_INITIAL_WINDOW_SIZE + 16 * 1024 * 2, ==, + stream->remote_window_size); + assert_false(stream->flags & NGHTTP2_STREAM_FLAG_DEFERRED_ALL); nghttp2_frame_window_update_free(&frame.window_update); @@ -4418,9 +4605,9 @@ void test_nghttp2_session_on_window_update_received(void) { nghttp2_frame_window_update_init(&frame.window_update, NGHTTP2_FLAG_NONE, 2, 4096); - CU_ASSERT(!(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND)); - CU_ASSERT(0 == nghttp2_session_on_window_update_received(session, &frame)); - CU_ASSERT(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); + assert_false(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); + assert_int(0, ==, nghttp2_session_on_window_update_received(session, &frame)); + assert_true(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); nghttp2_frame_window_update_free(&frame.window_update); @@ -4434,10 +4621,11 @@ void test_nghttp2_session_on_window_update_received(void) { nghttp2_frame_window_update_init(&frame.window_update, NGHTTP2_FLAG_NONE, 2, 4096); - CU_ASSERT(0 == nghttp2_session_on_window_update_received(session, &frame)); - CU_ASSERT(!(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND)); + assert_int(0, ==, nghttp2_session_on_window_update_received(session, &frame)); + assert_false(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE + 4096 == stream->remote_window_size); + assert_int32(NGHTTP2_INITIAL_WINDOW_SIZE + 4096, ==, + stream->remote_window_size); nghttp2_frame_window_update_free(&frame.window_update); @@ -4459,13 +4647,13 @@ void test_nghttp2_session_on_data_received(void) { nghttp2_frame_hd_init(&frame.hd, 4096, NGHTTP2_DATA, NGHTTP2_FLAG_NONE, 2); - CU_ASSERT(0 == nghttp2_session_on_data_received(session, &frame)); - CU_ASSERT(0 == stream->shut_flags); + assert_int(0, ==, nghttp2_session_on_data_received(session, &frame)); + assert_uint8(0, ==, stream->shut_flags); frame.hd.flags = NGHTTP2_FLAG_END_STREAM; - CU_ASSERT(0 == nghttp2_session_on_data_received(session, &frame)); - CU_ASSERT(NGHTTP2_SHUT_RD == stream->shut_flags); + assert_int(0, ==, nghttp2_session_on_data_received(session, &frame)); + assert_uint8(NGHTTP2_SHUT_RD, ==, stream->shut_flags); /* If NGHTTP2_STREAM_CLOSING state, DATA frame is discarded. */ open_sent_stream2(session, 1, NGHTTP2_STREAM_CLOSING); @@ -4473,18 +4661,18 @@ void test_nghttp2_session_on_data_received(void) { frame.hd.flags = NGHTTP2_FLAG_NONE; frame.hd.stream_id = 1; - CU_ASSERT(0 == nghttp2_session_on_data_received(session, &frame)); - CU_ASSERT(NULL == nghttp2_outbound_queue_top(&session->ob_reg)); + assert_int(0, ==, nghttp2_session_on_data_received(session, &frame)); + assert_null(nghttp2_outbound_queue_top(&session->ob_reg)); /* Check INVALID_STREAM case: DATA frame with stream ID which does not exist. */ frame.hd.stream_id = 3; - CU_ASSERT(0 == nghttp2_session_on_data_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_data_received(session, &frame)); top = nghttp2_outbound_queue_top(&session->ob_reg); /* DATA against nonexistent stream is just ignored for now. */ - CU_ASSERT(top == NULL); + assert_null(top); nghttp2_session_del(session); } @@ -4508,13 +4696,13 @@ void test_nghttp2_session_on_data_received_fail_fast(void) { stream = open_recv_stream(session, 1); nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_RD); - CU_ASSERT((ssize_t)sizeof(buf) == - nghttp2_session_mem_recv(session, buf, sizeof(buf))); + assert_ptrdiff((nghttp2_ssize)sizeof(buf), ==, + nghttp2_session_mem_recv2(session, buf, sizeof(buf))); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); + assert_not_null(item); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); nghttp2_session_del(session); @@ -4525,13 +4713,13 @@ void test_nghttp2_session_on_data_received_fail_fast(void) { nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_RD); nghttp2_session_close_stream(session, 1, NGHTTP2_NO_ERROR); - CU_ASSERT((ssize_t)sizeof(buf) == - nghttp2_session_mem_recv(session, buf, sizeof(buf))); + assert_ptrdiff((nghttp2_ssize)sizeof(buf), ==, + nghttp2_session_mem_recv2(session, buf, sizeof(buf))); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); + assert_not_null(item); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); nghttp2_session_del(session); } @@ -4564,8 +4752,8 @@ void test_nghttp2_session_on_altsvc_received(void) { ud.frame_recv_cb_called = 0; rv = nghttp2_session_on_altsvc_received(session, &frame); - CU_ASSERT(0 == rv); - CU_ASSERT(1 == ud.frame_recv_cb_called); + assert_int(0, ==, rv); + assert_int(1, ==, ud.frame_recv_cb_called); nghttp2_session_del(session); @@ -4580,8 +4768,8 @@ void test_nghttp2_session_on_altsvc_received(void) { ud.frame_recv_cb_called = 0; rv = nghttp2_session_on_altsvc_received(session, &frame); - CU_ASSERT(0 == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_int(0, ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); nghttp2_session_del(session); @@ -4598,8 +4786,8 @@ void test_nghttp2_session_on_altsvc_received(void) { ud.frame_recv_cb_called = 0; rv = nghttp2_session_on_altsvc_received(session, &frame); - CU_ASSERT(0 == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_int(0, ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); nghttp2_session_del(session); @@ -4616,8 +4804,8 @@ void test_nghttp2_session_on_altsvc_received(void) { ud.frame_recv_cb_called = 0; rv = nghttp2_session_on_altsvc_received(session, &frame); - CU_ASSERT(0 == rv); - CU_ASSERT(1 == ud.frame_recv_cb_called); + assert_int(0, ==, rv); + assert_int(1, ==, ud.frame_recv_cb_called); nghttp2_session_del(session); @@ -4632,8 +4820,8 @@ void test_nghttp2_session_on_altsvc_received(void) { ud.frame_recv_cb_called = 0; rv = nghttp2_session_on_altsvc_received(session, &frame); - CU_ASSERT(0 == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); + assert_int(0, ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); nghttp2_session_del(session); @@ -4651,7 +4839,7 @@ void test_nghttp2_session_send_headers_start_stream(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, NULL); @@ -4667,9 +4855,9 @@ void test_nghttp2_session_send_headers_start_stream(void) { session->next_stream_id += 2; nghttp2_session_add_item(session, item); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(NGHTTP2_STREAM_OPENING == stream->state); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENING, ==, stream->state); nghttp2_session_del(session); } @@ -4685,9 +4873,9 @@ void test_nghttp2_session_send_headers_reply(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; - CU_ASSERT(0 == nghttp2_session_server_new(&session, &callbacks, NULL)); + assert_int(0, ==, nghttp2_session_server_new(&session, &callbacks, NULL)); open_recv_stream2(session, 1, NGHTTP2_STREAM_OPENING); item = mem->malloc(sizeof(nghttp2_outbound_item), NULL); @@ -4699,9 +4887,9 @@ void test_nghttp2_session_send_headers_reply(void) { nghttp2_frame_headers_init(&frame->headers, NGHTTP2_FLAG_END_HEADERS, 1, NGHTTP2_HCAT_HEADERS, NULL, NULL, 0); nghttp2_session_add_item(session, item); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(NGHTTP2_STREAM_OPENED == stream->state); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENED, ==, stream->state); nghttp2_session_del(session); } @@ -4733,7 +4921,7 @@ void test_nghttp2_session_send_headers_frame_size_error(void) { } memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_not_send_callback = on_frame_not_send_callback; nghttp2_session_client_new(&session, &callbacks, &ud); @@ -4756,11 +4944,11 @@ void test_nghttp2_session_send_headers_frame_size_error(void) { ud.frame_not_send_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_not_send_cb_called); - CU_ASSERT(NGHTTP2_HEADERS == ud.not_sent_frame_type); - CU_ASSERT(NGHTTP2_ERR_FRAME_SIZE_ERROR == ud.not_sent_error); + assert_int(1, ==, ud.frame_not_send_cb_called); + assert_uint8(NGHTTP2_HEADERS, ==, ud.not_sent_frame_type); + assert_int(NGHTTP2_ERR_FRAME_SIZE_ERROR, ==, ud.not_sent_error); for (i = 0; i < nnv; ++i) { mem->free(nv[i].value, NULL); @@ -4779,9 +4967,9 @@ void test_nghttp2_session_send_headers_push_reply(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; - CU_ASSERT(0 == nghttp2_session_server_new(&session, &callbacks, NULL)); + assert_int(0, ==, nghttp2_session_server_new(&session, &callbacks, NULL)); open_sent_stream2(session, 2, NGHTTP2_STREAM_RESERVED); item = mem->malloc(sizeof(nghttp2_outbound_item), NULL); @@ -4793,12 +4981,12 @@ void test_nghttp2_session_send_headers_push_reply(void) { nghttp2_frame_headers_init(&frame->headers, NGHTTP2_FLAG_END_HEADERS, 2, NGHTTP2_HCAT_HEADERS, NULL, NULL, 0); nghttp2_session_add_item(session, item); - CU_ASSERT(0 == session->num_outgoing_streams); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == session->num_outgoing_streams); + assert_size(0, ==, session->num_outgoing_streams); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(1, ==, session->num_outgoing_streams); stream = nghttp2_session_get_stream(session, 2); - CU_ASSERT(NGHTTP2_STREAM_OPENED == stream->state); - CU_ASSERT(0 == (stream->flags & NGHTTP2_STREAM_FLAG_PUSH)); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENED, ==, stream->state); + assert_false(stream->flags & NGHTTP2_STREAM_FLAG_PUSH); nghttp2_session_del(session); } @@ -4813,7 +5001,7 @@ void test_nghttp2_session_send_rst_stream(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, &user_data); open_sent_stream(session, 1); @@ -4825,9 +5013,9 @@ void test_nghttp2_session_send_rst_stream(void) { nghttp2_frame_rst_stream_init(&frame->rst_stream, 1, NGHTTP2_PROTOCOL_ERROR); nghttp2_session_add_item(session, item); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 1)); + assert_null(nghttp2_session_get_stream(session, 1)); nghttp2_session_del(session); } @@ -4844,7 +5032,7 @@ void test_nghttp2_session_send_push_promise(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_not_send_callback = on_frame_not_send_callback; nghttp2_session_server_new(&session, &callbacks, &ud); @@ -4864,9 +5052,9 @@ void test_nghttp2_session_send_push_promise(void) { nghttp2_session_add_item(session, item); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); stream = nghttp2_session_get_stream(session, 2); - CU_ASSERT(NGHTTP2_STREAM_RESERVED == stream->state); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_RESERVED, ==, stream->state); /* Received ENABLE_PUSH = 0 */ iv.settings_id = NGHTTP2_SETTINGS_ENABLE_PUSH; @@ -4889,11 +5077,11 @@ void test_nghttp2_session_send_push_promise(void) { nghttp2_session_add_item(session, item); ud.frame_not_send_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_not_send_cb_called); - CU_ASSERT(NGHTTP2_PUSH_PROMISE == ud.not_sent_frame_type); - CU_ASSERT(NGHTTP2_ERR_PUSH_DISABLED == ud.not_sent_error); + assert_int(1, ==, ud.frame_not_send_cb_called); + assert_uint8(NGHTTP2_PUSH_PROMISE, ==, ud.not_sent_frame_type); + assert_int(NGHTTP2_ERR_PUSH_DISABLED, ==, ud.not_sent_error); nghttp2_session_del(session); @@ -4910,8 +5098,8 @@ void test_nghttp2_session_send_push_promise(void) { NGHTTP2_FLAG_END_HEADERS, 1, -1, NULL, 0); nghttp2_session_add_item(session, item); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 3)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_null(nghttp2_session_get_stream(session, 3)); nghttp2_session_del(session); } @@ -4922,17 +5110,17 @@ void test_nghttp2_session_is_my_stream_id(void) { memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); nghttp2_session_server_new(&session, &callbacks, NULL); - CU_ASSERT(0 == nghttp2_session_is_my_stream_id(session, 0)); - CU_ASSERT(0 == nghttp2_session_is_my_stream_id(session, 1)); - CU_ASSERT(1 == nghttp2_session_is_my_stream_id(session, 2)); + assert_false(nghttp2_session_is_my_stream_id(session, 0)); + assert_false(nghttp2_session_is_my_stream_id(session, 1)); + assert_true(nghttp2_session_is_my_stream_id(session, 2)); nghttp2_session_del(session); nghttp2_session_client_new(&session, &callbacks, NULL); - CU_ASSERT(0 == nghttp2_session_is_my_stream_id(session, 0)); - CU_ASSERT(1 == nghttp2_session_is_my_stream_id(session, 1)); - CU_ASSERT(0 == nghttp2_session_is_my_stream_id(session, 2)); + assert_false(nghttp2_session_is_my_stream_id(session, 0)); + assert_true(nghttp2_session_is_my_stream_id(session, 1)); + assert_false(nghttp2_session_is_my_stream_id(session, 2)); nghttp2_session_del(session); } @@ -4945,7 +5133,7 @@ void test_nghttp2_session_upgrade2(void) { nghttp2_settings_entry iv[16]; nghttp2_stream *stream; nghttp2_outbound_item *item; - ssize_t rv; + nghttp2_ssize rv; nghttp2_bufs bufs; nghttp2_buf *buf; nghttp2_hd_deflater deflater; @@ -4955,61 +5143,63 @@ void test_nghttp2_session_upgrade2(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; iv[0].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS; iv[0].value = 1; iv[1].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE; iv[1].value = 4095; - settings_payloadlen = (size_t)nghttp2_pack_settings_payload( + settings_payloadlen = (size_t)nghttp2_pack_settings_payload2( settings_payload, sizeof(settings_payload), iv, 2); /* Check client side */ nghttp2_session_client_new(&session, &callbacks, NULL); - CU_ASSERT(0 == nghttp2_session_upgrade2(session, settings_payload, - settings_payloadlen, 0, &callbacks)); - CU_ASSERT(1 == session->last_sent_stream_id); + assert_int(0, ==, + nghttp2_session_upgrade2(session, settings_payload, + settings_payloadlen, 0, &callbacks)); + assert_int32(1, ==, session->last_sent_stream_id); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(stream != NULL); - CU_ASSERT(&callbacks == stream->stream_user_data); - CU_ASSERT(NGHTTP2_SHUT_WR == stream->shut_flags); + assert_not_null(stream); + assert_ptr_equal(&callbacks, stream->stream_user_data); + assert_uint8(NGHTTP2_SHUT_WR, ==, stream->shut_flags); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_SETTINGS == item->frame.hd.type); - CU_ASSERT(2 == item->frame.settings.niv); - CU_ASSERT(NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS == - item->frame.settings.iv[0].settings_id); - CU_ASSERT(1 == item->frame.settings.iv[0].value); - CU_ASSERT(NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE == - item->frame.settings.iv[1].settings_id); - CU_ASSERT(4095 == item->frame.settings.iv[1].value); + assert_uint8(NGHTTP2_SETTINGS, ==, item->frame.hd.type); + assert_size(2, ==, item->frame.settings.niv); + assert_int32(NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, ==, + item->frame.settings.iv[0].settings_id); + assert_uint32(1, ==, item->frame.settings.iv[0].value); + assert_int32(NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE, ==, + item->frame.settings.iv[1].settings_id); + assert_uint32(4095, ==, item->frame.settings.iv[1].value); /* Call nghttp2_session_upgrade2() again is error */ - CU_ASSERT(NGHTTP2_ERR_PROTO == - nghttp2_session_upgrade2(session, settings_payload, - settings_payloadlen, 0, &callbacks)); + assert_int(NGHTTP2_ERR_PROTO, ==, + nghttp2_session_upgrade2(session, settings_payload, + settings_payloadlen, 0, &callbacks)); nghttp2_session_del(session); /* Make sure that response from server can be received */ nghttp2_session_client_new(&session, &callbacks, NULL); - CU_ASSERT(0 == nghttp2_session_upgrade2(session, settings_payload, - settings_payloadlen, 0, &callbacks)); + assert_int(0, ==, + nghttp2_session_upgrade2(session, settings_payload, + settings_payloadlen, 0, &callbacks)); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(NGHTTP2_STREAM_OPENING == stream->state); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENING, ==, stream->state); nghttp2_hd_deflate_init(&deflater, mem); rv = pack_headers(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, resnv, ARRLEN(resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT(rv == (ssize_t)nghttp2_buf_len(buf)); - CU_ASSERT(NGHTTP2_STREAM_OPENED == stream->state); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENED, ==, stream->state); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -5018,29 +5208,31 @@ void test_nghttp2_session_upgrade2(void) { /* Check server side */ nghttp2_session_server_new(&session, &callbacks, NULL); - CU_ASSERT(0 == nghttp2_session_upgrade2(session, settings_payload, - settings_payloadlen, 0, &callbacks)); - CU_ASSERT(1 == session->last_recv_stream_id); + assert_int(0, ==, + nghttp2_session_upgrade2(session, settings_payload, + settings_payloadlen, 0, &callbacks)); + assert_int32(1, ==, session->last_recv_stream_id); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(stream != NULL); - CU_ASSERT(NULL == stream->stream_user_data); - CU_ASSERT(NGHTTP2_SHUT_RD == stream->shut_flags); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); - CU_ASSERT(1 == session->remote_settings.max_concurrent_streams); - CU_ASSERT(4095 == session->remote_settings.initial_window_size); + assert_not_null(stream); + assert_null(stream->stream_user_data); + assert_uint8(NGHTTP2_SHUT_RD, ==, stream->shut_flags); + assert_null(nghttp2_session_get_next_ob_item(session)); + assert_uint32(1, ==, session->remote_settings.max_concurrent_streams); + assert_uint32(4095, ==, session->remote_settings.initial_window_size); /* Call nghttp2_session_upgrade2() again is error */ - CU_ASSERT(NGHTTP2_ERR_PROTO == - nghttp2_session_upgrade2(session, settings_payload, - settings_payloadlen, 0, &callbacks)); + assert_int(NGHTTP2_ERR_PROTO, ==, + nghttp2_session_upgrade2(session, settings_payload, + settings_payloadlen, 0, &callbacks)); nghttp2_session_del(session); /* Empty SETTINGS is OK */ - settings_payloadlen = (size_t)nghttp2_pack_settings_payload( + settings_payloadlen = (size_t)nghttp2_pack_settings_payload2( settings_payload, sizeof(settings_payload), NULL, 0); nghttp2_session_client_new(&session, &callbacks, NULL); - CU_ASSERT(0 == nghttp2_session_upgrade2(session, settings_payload, - settings_payloadlen, 0, NULL)); + assert_int(0, ==, + nghttp2_session_upgrade2(session, settings_payload, + settings_payloadlen, 0, NULL)); nghttp2_session_del(session); nghttp2_bufs_free(&bufs); } @@ -5054,7 +5246,7 @@ void test_nghttp2_session_reprioritize_stream(void) { int rv; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = block_count_send_callback; + callbacks.send_callback2 = block_count_send_callback; nghttp2_session_server_new(&session, &callbacks, NULL); @@ -5064,9 +5256,9 @@ void test_nghttp2_session_reprioritize_stream(void) { rv = nghttp2_session_reprioritize_stream(session, stream, &pri_spec); - CU_ASSERT(0 == rv); - CU_ASSERT(10 == stream->weight); - CU_ASSERT(&session->root == stream->dep_prev); + assert_int(0, ==, rv); + assert_int32(10, ==, stream->weight); + assert_ptr_equal(&session->root, stream->dep_prev); /* If dependency to idle stream which is not in dependency tree yet */ @@ -5074,13 +5266,13 @@ void test_nghttp2_session_reprioritize_stream(void) { rv = nghttp2_session_reprioritize_stream(session, stream, &pri_spec); - CU_ASSERT(0 == rv); - CU_ASSERT(99 == stream->weight); - CU_ASSERT(3 == stream->dep_prev->stream_id); + assert_int(0, ==, rv); + assert_int32(99, ==, stream->weight); + assert_int32(3, ==, stream->dep_prev->stream_id); dep_stream = nghttp2_session_get_stream_raw(session, 3); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == dep_stream->weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, dep_stream->weight); dep_stream = open_recv_stream(session, 3); @@ -5089,19 +5281,19 @@ void test_nghttp2_session_reprioritize_stream(void) { rv = nghttp2_session_reprioritize_stream(session, stream, &pri_spec); - CU_ASSERT(0 == rv); - CU_ASSERT(128 == stream->weight); - CU_ASSERT(dep_stream == stream->dep_prev); + assert_int(0, ==, rv); + assert_int32(128, ==, stream->weight); + assert_ptr_equal(dep_stream, stream->dep_prev); /* Change weight again to test short-path case */ pri_spec.weight = 100; rv = nghttp2_session_reprioritize_stream(session, stream, &pri_spec); - CU_ASSERT(0 == rv); - CU_ASSERT(100 == stream->weight); - CU_ASSERT(dep_stream == stream->dep_prev); - CU_ASSERT(100 == dep_stream->sum_dep_weight); + assert_int(0, ==, rv); + assert_int32(100, ==, stream->weight); + assert_ptr_equal(dep_stream, stream->dep_prev); + assert_int32(100, ==, dep_stream->sum_dep_weight); /* Test circular dependency; stream 1 is first removed and becomes root. Then stream 3 depends on it. */ @@ -5109,9 +5301,9 @@ void test_nghttp2_session_reprioritize_stream(void) { rv = nghttp2_session_reprioritize_stream(session, dep_stream, &pri_spec); - CU_ASSERT(0 == rv); - CU_ASSERT(1 == dep_stream->weight); - CU_ASSERT(stream == dep_stream->dep_prev); + assert_int(0, ==, rv); + assert_int32(1, ==, dep_stream->weight); + assert_ptr_equal(stream, dep_stream->dep_prev); /* Making priority to closed stream will result in default priority */ @@ -5121,8 +5313,8 @@ void test_nghttp2_session_reprioritize_stream(void) { rv = nghttp2_session_reprioritize_stream(session, stream, &pri_spec); - CU_ASSERT(0 == rv); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == stream->weight); + assert_int(0, ==, rv); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, stream->weight); nghttp2_session_del(session); @@ -5141,20 +5333,20 @@ void test_nghttp2_session_reprioritize_stream(void) { stream = nghttp2_session_get_stream(session, 3); rv = nghttp2_session_reprioritize_stream(session, stream, &pri_spec); - CU_ASSERT(0 == rv); - CU_ASSERT(7 == stream->dep_prev->stream_id); + assert_int(0, ==, rv); + assert_int32(7, ==, stream->dep_prev->stream_id); stream = nghttp2_session_get_stream(session, 7); - CU_ASSERT(1 == stream->dep_prev->stream_id); + assert_int32(1, ==, stream->dep_prev->stream_id); stream = nghttp2_session_get_stream(session, 9); - CU_ASSERT(3 == stream->dep_prev->stream_id); + assert_int32(3, ==, stream->dep_prev->stream_id); stream = nghttp2_session_get_stream(session, 5); - CU_ASSERT(3 == stream->dep_prev->stream_id); + assert_int32(3, ==, stream->dep_prev->stream_id); nghttp2_session_del(session); @@ -5173,20 +5365,20 @@ void test_nghttp2_session_reprioritize_stream(void) { stream = nghttp2_session_get_stream(session, 3); rv = nghttp2_session_reprioritize_stream(session, stream, &pri_spec); - CU_ASSERT(0 == rv); - CU_ASSERT(7 == stream->dep_prev->stream_id); + assert_int(0, ==, rv); + assert_int32(7, ==, stream->dep_prev->stream_id); stream = nghttp2_session_get_stream(session, 7); - CU_ASSERT(1 == stream->dep_prev->stream_id); + assert_int32(1, ==, stream->dep_prev->stream_id); stream = nghttp2_session_get_stream(session, 9); - CU_ASSERT(7 == stream->dep_prev->stream_id); + assert_int32(7, ==, stream->dep_prev->stream_id); stream = nghttp2_session_get_stream(session, 5); - CU_ASSERT(3 == stream->dep_prev->stream_id); + assert_int32(3, ==, stream->dep_prev->stream_id); nghttp2_session_del(session); } @@ -5198,7 +5390,7 @@ void test_nghttp2_session_reprioritize_stream_with_idle_stream_dep(void) { nghttp2_priority_spec pri_spec; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = block_count_send_callback; + callbacks.send_callback2 = block_count_send_callback; nghttp2_session_server_new(&session, &callbacks, NULL); @@ -5212,12 +5404,12 @@ void test_nghttp2_session_reprioritize_stream_with_idle_stream_dep(void) { /* idle stream is not counteed to max concurrent streams */ - CU_ASSERT(10 == stream->weight); - CU_ASSERT(101 == stream->dep_prev->stream_id); + assert_int32(10, ==, stream->weight); + assert_int32(101, ==, stream->dep_prev->stream_id); stream = nghttp2_session_get_stream_raw(session, 101); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == stream->weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, stream->weight); nghttp2_session_del(session); } @@ -5225,7 +5417,7 @@ void test_nghttp2_session_reprioritize_stream_with_idle_stream_dep(void) { void test_nghttp2_submit_data(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; my_user_data ud; nghttp2_frame *frame; nghttp2_frame_hd hd; @@ -5234,30 +5426,31 @@ void test_nghttp2_submit_data(void) { nghttp2_buf *buf; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = block_count_send_callback; + callbacks.send_callback2 = block_count_send_callback; data_prd.read_callback = fixed_length_data_source_read_callback; ud.data_source_length = NGHTTP2_DATA_PAYLOADLEN * 2; - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, &ud)); + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, &ud)); aob = &session->aob; framebufs = &aob->framebufs; open_sent_stream(session, 1); - CU_ASSERT( - 0 == nghttp2_submit_data(session, NGHTTP2_FLAG_END_STREAM, 1, &data_prd)); + assert_int( + 0, ==, + nghttp2_submit_data2(session, NGHTTP2_FLAG_END_STREAM, 1, &data_prd)); ud.block_count = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); frame = &aob->item->frame; buf = &framebufs->head->buf; nghttp2_frame_unpack_frame_hd(&hd, buf->pos); - CU_ASSERT(NGHTTP2_FLAG_NONE == hd.flags); - CU_ASSERT(NGHTTP2_FLAG_NONE == frame->hd.flags); + assert_uint8(NGHTTP2_FLAG_NONE, ==, hd.flags); + assert_uint8(NGHTTP2_FLAG_NONE, ==, frame->hd.flags); /* aux_data.data.flags has these flags */ - CU_ASSERT(NGHTTP2_FLAG_END_STREAM == aob->item->aux_data.data.flags); + assert_uint8(NGHTTP2_FLAG_END_STREAM, ==, aob->item->aux_data.data.flags); nghttp2_session_del(session); } @@ -5265,7 +5458,7 @@ void test_nghttp2_submit_data(void) { void test_nghttp2_submit_data_read_length_too_large(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; my_user_data ud; nghttp2_frame *frame; nghttp2_frame_hd hd; @@ -5275,37 +5468,38 @@ void test_nghttp2_submit_data_read_length_too_large(void) { size_t payloadlen; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = block_count_send_callback; - callbacks.read_length_callback = too_large_data_source_length_callback; + callbacks.send_callback2 = block_count_send_callback; + callbacks.read_length_callback2 = too_large_data_source_length_callback; data_prd.read_callback = fixed_length_data_source_read_callback; ud.data_source_length = NGHTTP2_DATA_PAYLOADLEN * 2; - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, &ud)); + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, &ud)); aob = &session->aob; framebufs = &aob->framebufs; open_sent_stream(session, 1); - CU_ASSERT( - 0 == nghttp2_submit_data(session, NGHTTP2_FLAG_END_STREAM, 1, &data_prd)); + assert_int( + 0, ==, + nghttp2_submit_data2(session, NGHTTP2_FLAG_END_STREAM, 1, &data_prd)); ud.block_count = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); frame = &aob->item->frame; buf = &framebufs->head->buf; nghttp2_frame_unpack_frame_hd(&hd, buf->pos); - CU_ASSERT(NGHTTP2_FLAG_NONE == hd.flags); - CU_ASSERT(NGHTTP2_FLAG_NONE == frame->hd.flags); - CU_ASSERT(16384 == hd.length) + assert_uint8(NGHTTP2_FLAG_NONE, ==, hd.flags); + assert_uint8(NGHTTP2_FLAG_NONE, ==, frame->hd.flags); + assert_size(16384, ==, hd.length); /* aux_data.data.flags has these flags */ - CU_ASSERT(NGHTTP2_FLAG_END_STREAM == aob->item->aux_data.data.flags); + assert_uint8(NGHTTP2_FLAG_END_STREAM, ==, aob->item->aux_data.data.flags); nghttp2_session_del(session); /* Check that buffers are expanded */ - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, &ud)); + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, &ud)); ud.data_source_length = NGHTTP2_MAX_FRAME_SIZE_MAX; @@ -5313,11 +5507,12 @@ void test_nghttp2_submit_data_read_length_too_large(void) { open_sent_stream(session, 1); - CU_ASSERT( - 0 == nghttp2_submit_data(session, NGHTTP2_FLAG_END_STREAM, 1, &data_prd)); + assert_int( + 0, ==, + nghttp2_submit_data2(session, NGHTTP2_FLAG_END_STREAM, 1, &data_prd)); ud.block_count = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); aob = &session->aob; @@ -5331,13 +5526,13 @@ void test_nghttp2_submit_data_read_length_too_large(void) { payloadlen = nghttp2_min(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE, NGHTTP2_INITIAL_WINDOW_SIZE); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + 1 + payloadlen == - (size_t)nghttp2_buf_cap(buf)); - CU_ASSERT(NGHTTP2_FLAG_NONE == hd.flags); - CU_ASSERT(NGHTTP2_FLAG_NONE == frame->hd.flags); - CU_ASSERT(payloadlen == hd.length); + assert_size(NGHTTP2_FRAME_HDLEN + 1 + payloadlen, ==, + (size_t)nghttp2_buf_cap(buf)); + assert_uint8(NGHTTP2_FLAG_NONE, ==, hd.flags); + assert_uint8(NGHTTP2_FLAG_NONE, ==, frame->hd.flags); + assert_size(payloadlen, ==, hd.length); /* aux_data.data.flags has these flags */ - CU_ASSERT(NGHTTP2_FLAG_END_STREAM == aob->item->aux_data.data.flags); + assert_uint8(NGHTTP2_FLAG_END_STREAM, ==, aob->item->aux_data.data.flags); nghttp2_session_del(session); } @@ -5345,7 +5540,7 @@ void test_nghttp2_submit_data_read_length_too_large(void) { void test_nghttp2_submit_data_read_length_smallest(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; my_user_data ud; nghttp2_frame *frame; nghttp2_frame_hd hd; @@ -5354,37 +5549,38 @@ void test_nghttp2_submit_data_read_length_smallest(void) { nghttp2_buf *buf; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = block_count_send_callback; - callbacks.read_length_callback = smallest_length_data_source_length_callback; + callbacks.send_callback2 = block_count_send_callback; + callbacks.read_length_callback2 = smallest_length_data_source_length_callback; data_prd.read_callback = fixed_length_data_source_read_callback; ud.data_source_length = NGHTTP2_DATA_PAYLOADLEN * 2; - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, &ud)); + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, &ud)); aob = &session->aob; framebufs = &aob->framebufs; open_sent_stream(session, 1); - CU_ASSERT( - 0 == nghttp2_submit_data(session, NGHTTP2_FLAG_END_STREAM, 1, &data_prd)); + assert_int( + 0, ==, + nghttp2_submit_data2(session, NGHTTP2_FLAG_END_STREAM, 1, &data_prd)); ud.block_count = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); frame = &aob->item->frame; buf = &framebufs->head->buf; nghttp2_frame_unpack_frame_hd(&hd, buf->pos); - CU_ASSERT(NGHTTP2_FLAG_NONE == hd.flags); - CU_ASSERT(NGHTTP2_FLAG_NONE == frame->hd.flags); - CU_ASSERT(1 == hd.length) + assert_uint8(NGHTTP2_FLAG_NONE, ==, hd.flags); + assert_uint8(NGHTTP2_FLAG_NONE, ==, frame->hd.flags); + assert_size(1, ==, hd.length); /* aux_data.data.flags has these flags */ - CU_ASSERT(NGHTTP2_FLAG_END_STREAM == aob->item->aux_data.data.flags); + assert_uint8(NGHTTP2_FLAG_END_STREAM, ==, aob->item->aux_data.data.flags); nghttp2_session_del(session); } -static ssize_t submit_data_twice_data_source_read_callback( +static nghttp2_ssize submit_data_twice_data_source_read_callback( nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t len, uint32_t *data_flags, nghttp2_data_source *source, void *user_data) { (void)session; @@ -5394,7 +5590,7 @@ static ssize_t submit_data_twice_data_source_read_callback( (void)user_data; *data_flags |= NGHTTP2_DATA_FLAG_EOF; - return (ssize_t)nghttp2_min(len, 16); + return (nghttp2_ssize)nghttp2_min(len, 16); } static int submit_data_twice_on_frame_send_callback(nghttp2_session *session, @@ -5402,7 +5598,7 @@ static int submit_data_twice_on_frame_send_callback(nghttp2_session *session, void *user_data) { static int called = 0; int rv; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; (void)user_data; if (called == 0) { @@ -5410,9 +5606,9 @@ static int submit_data_twice_on_frame_send_callback(nghttp2_session *session, data_prd.read_callback = submit_data_twice_data_source_read_callback; - rv = nghttp2_submit_data(session, NGHTTP2_FLAG_END_STREAM, - frame->hd.stream_id, &data_prd); - CU_ASSERT(0 == rv); + rv = nghttp2_submit_data2(session, NGHTTP2_FLAG_END_STREAM, + frame->hd.stream_id, &data_prd); + assert_int(0, ==, rv); } return 0; @@ -5421,12 +5617,12 @@ static int submit_data_twice_on_frame_send_callback(nghttp2_session *session, void test_nghttp2_submit_data_twice(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; my_user_data ud; accumulator acc; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = accumulator_send_callback; + callbacks.send_callback2 = accumulator_send_callback; callbacks.on_frame_send_callback = submit_data_twice_on_frame_send_callback; data_prd.read_callback = submit_data_twice_data_source_read_callback; @@ -5434,15 +5630,16 @@ void test_nghttp2_submit_data_twice(void) { acc.length = 0; ud.acc = &acc; - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, &ud)); + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, &ud)); open_sent_stream(session, 1); - CU_ASSERT(0 == nghttp2_submit_data(session, NGHTTP2_FLAG_NONE, 1, &data_prd)); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, + nghttp2_submit_data2(session, NGHTTP2_FLAG_NONE, 1, &data_prd)); + assert_int(0, ==, nghttp2_session_send(session)); /* We should have sent 2 DATA frame with 16 bytes payload each */ - CU_ASSERT(NGHTTP2_FRAME_HDLEN * 2 + 16 * 2 == acc.length); + assert_size(NGHTTP2_FRAME_HDLEN * 2 + 16 * 2, ==, acc.length); nghttp2_session_del(session); } @@ -5450,7 +5647,7 @@ void test_nghttp2_submit_data_twice(void) { void test_nghttp2_submit_request_with_data(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; my_user_data ud; nghttp2_outbound_item *item; nghttp2_mem *mem; @@ -5458,28 +5655,29 @@ void test_nghttp2_submit_request_with_data(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; data_prd.read_callback = fixed_length_data_source_read_callback; ud.data_source_length = 64 * 1024 - 1; - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, &ud)); - CU_ASSERT(1 == nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), - &data_prd, NULL)); + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, &ud)); + assert_int32(1, ==, + nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), + &data_prd, NULL)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(ARRLEN(reqnv) == item->frame.headers.nvlen); + assert_size(ARRLEN(reqnv), ==, item->frame.headers.nvlen); assert_nv_equal(reqnv, item->frame.headers.nva, item->frame.headers.nvlen, mem); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == ud.data_source_length); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(0, ==, ud.data_source_length); nghttp2_session_del(session); - /* nghttp2_submit_request() with server session is error */ + /* nghttp2_submit_request2() with server session is error */ nghttp2_session_server_new(&session, &callbacks, NULL); - CU_ASSERT(NGHTTP2_ERR_PROTO == nghttp2_submit_request(session, NULL, reqnv, - ARRLEN(reqnv), NULL, - NULL)); + assert_int32( + NGHTTP2_ERR_PROTO, ==, + nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL)); nghttp2_session_del(session); } @@ -5488,7 +5686,7 @@ void test_nghttp2_submit_request_without_data(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; accumulator acc; - nghttp2_data_provider data_prd = {{-1}, NULL}; + nghttp2_data_provider2 data_prd = {{-1}, NULL}; nghttp2_outbound_item *item; my_user_data ud; nghttp2_frame frame; @@ -5505,25 +5703,26 @@ void test_nghttp2_submit_request_without_data(void) { acc.length = 0; ud.acc = &acc; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = accumulator_send_callback; - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, &ud)); + callbacks.send_callback2 = accumulator_send_callback; + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, &ud)); nghttp2_hd_inflate_init(&inflater, mem); - CU_ASSERT(1 == nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), - &data_prd, NULL)); + assert_int32(1, ==, + nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), + &data_prd, NULL)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(ARRLEN(reqnv) == item->frame.headers.nvlen); + assert_size(ARRLEN(reqnv), ==, item->frame.headers.nvlen); assert_nv_equal(reqnv, item->frame.headers.nva, item->frame.headers.nvlen, mem); - CU_ASSERT(item->frame.hd.flags & NGHTTP2_FLAG_END_STREAM); + assert_true(item->frame.hd.flags & NGHTTP2_FLAG_END_STREAM); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == unpack_frame(&frame, acc.buf, acc.length)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(0, ==, unpack_frame(&frame, acc.buf, acc.length)); nghttp2_bufs_add(&bufs, acc.buf, acc.length); inflate_hd(&inflater, &out, &bufs, NGHTTP2_FRAME_HDLEN, mem); - CU_ASSERT(ARRLEN(reqnv) == out.nvlen); + assert_size(ARRLEN(reqnv), ==, out.nvlen); assert_nv_equal(reqnv, out.nva, out.nvlen, mem); nghttp2_frame_headers_free(&frame.headers, mem); nva_out_reset(&out, mem); @@ -5535,9 +5734,9 @@ void test_nghttp2_submit_request_without_data(void) { nghttp2_priority_spec_init(&pri_spec, (int32_t)session->next_stream_id, 16, 0); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_submit_request(session, &pri_spec, reqnv, ARRLEN(reqnv), - NULL, NULL)); + assert_int32(NGHTTP2_ERR_INVALID_ARGUMENT, ==, + nghttp2_submit_request2(session, &pri_spec, reqnv, ARRLEN(reqnv), + NULL, NULL)); nghttp2_session_del(session); } @@ -5545,7 +5744,7 @@ void test_nghttp2_submit_request_without_data(void) { void test_nghttp2_submit_response_with_data(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; my_user_data ud; nghttp2_outbound_item *item; nghttp2_mem *mem; @@ -5553,33 +5752,34 @@ void test_nghttp2_submit_response_with_data(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; data_prd.read_callback = fixed_length_data_source_read_callback; ud.data_source_length = 64 * 1024 - 1; - CU_ASSERT(0 == nghttp2_session_server_new(&session, &callbacks, &ud)); + assert_int(0, ==, nghttp2_session_server_new(&session, &callbacks, &ud)); open_recv_stream2(session, 1, NGHTTP2_STREAM_OPENING); - CU_ASSERT(0 == nghttp2_submit_response(session, 1, resnv, ARRLEN(resnv), - &data_prd)); + assert_int( + 0, ==, + nghttp2_submit_response2(session, 1, resnv, ARRLEN(resnv), &data_prd)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(ARRLEN(resnv) == item->frame.headers.nvlen); + assert_size(ARRLEN(resnv), ==, item->frame.headers.nvlen); assert_nv_equal(resnv, item->frame.headers.nva, item->frame.headers.nvlen, mem); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == ud.data_source_length); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(0, ==, ud.data_source_length); nghttp2_session_del(session); /* Various error cases */ nghttp2_session_client_new(&session, &callbacks, NULL); - /* Calling nghttp2_submit_response() with client session is error */ - CU_ASSERT(NGHTTP2_ERR_PROTO == - nghttp2_submit_response(session, 1, resnv, ARRLEN(resnv), NULL)); + /* Calling nghttp2_submit_response2() with client session is error */ + assert_int(NGHTTP2_ERR_PROTO, ==, + nghttp2_submit_response2(session, 1, resnv, ARRLEN(resnv), NULL)); /* Stream ID <= 0 is error */ - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_submit_response(session, 0, resnv, ARRLEN(resnv), NULL)); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, + nghttp2_submit_response2(session, 0, resnv, ARRLEN(resnv), NULL)); nghttp2_session_del(session); } @@ -5588,7 +5788,7 @@ void test_nghttp2_submit_response_without_data(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; accumulator acc; - nghttp2_data_provider data_prd = {{-1}, NULL}; + nghttp2_data_provider2 data_prd = {{-1}, NULL}; nghttp2_outbound_item *item; my_user_data ud; nghttp2_frame frame; @@ -5604,26 +5804,27 @@ void test_nghttp2_submit_response_without_data(void) { acc.length = 0; ud.acc = &acc; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = accumulator_send_callback; - CU_ASSERT(0 == nghttp2_session_server_new(&session, &callbacks, &ud)); + callbacks.send_callback2 = accumulator_send_callback; + assert_int(0, ==, nghttp2_session_server_new(&session, &callbacks, &ud)); nghttp2_hd_inflate_init(&inflater, mem); open_recv_stream2(session, 1, NGHTTP2_STREAM_OPENING); - CU_ASSERT(0 == nghttp2_submit_response(session, 1, resnv, ARRLEN(resnv), - &data_prd)); + assert_int( + 0, ==, + nghttp2_submit_response2(session, 1, resnv, ARRLEN(resnv), &data_prd)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(ARRLEN(resnv) == item->frame.headers.nvlen); + assert_size(ARRLEN(resnv), ==, item->frame.headers.nvlen); assert_nv_equal(resnv, item->frame.headers.nva, item->frame.headers.nvlen, mem); - CU_ASSERT(item->frame.hd.flags & NGHTTP2_FLAG_END_STREAM); + assert_true(item->frame.hd.flags & NGHTTP2_FLAG_END_STREAM); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == unpack_frame(&frame, acc.buf, acc.length)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(0, ==, unpack_frame(&frame, acc.buf, acc.length)); nghttp2_bufs_add(&bufs, acc.buf, acc.length); inflate_hd(&inflater, &out, &bufs, NGHTTP2_FRAME_HDLEN, mem); - CU_ASSERT(ARRLEN(resnv) == out.nvlen); + assert_size(ARRLEN(resnv), ==, out.nvlen); assert_nv_equal(resnv, out.nva, out.nvlen, mem); nva_out_reset(&out, mem); @@ -5639,7 +5840,7 @@ void test_nghttp2_submit_response_push_response(void) { my_user_data ud; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_not_send_callback = on_frame_not_send_callback; nghttp2_session_server_new(&session, &callbacks, &ud); @@ -5648,13 +5849,13 @@ void test_nghttp2_submit_response_push_response(void) { session->goaway_flags |= NGHTTP2_GOAWAY_RECV; - CU_ASSERT(0 == - nghttp2_submit_response(session, 2, resnv, ARRLEN(resnv), NULL)); + assert_int(0, ==, + nghttp2_submit_response2(session, 2, resnv, ARRLEN(resnv), NULL)); ud.frame_not_send_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_not_send_cb_called); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(1, ==, ud.frame_not_send_cb_called); nghttp2_session_del(session); } @@ -5663,7 +5864,7 @@ void test_nghttp2_submit_trailer(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; accumulator acc; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; nghttp2_outbound_item *item; my_user_data ud; nghttp2_frame frame; @@ -5680,32 +5881,34 @@ void test_nghttp2_submit_trailer(void) { acc.length = 0; ud.acc = &acc; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; - CU_ASSERT(0 == nghttp2_session_server_new(&session, &callbacks, &ud)); + callbacks.send_callback2 = null_send_callback; + assert_int(0, ==, nghttp2_session_server_new(&session, &callbacks, &ud)); nghttp2_hd_inflate_init(&inflater, mem); open_recv_stream2(session, 1, NGHTTP2_STREAM_OPENING); - CU_ASSERT(0 == nghttp2_submit_response(session, 1, resnv, ARRLEN(resnv), - &data_prd)); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int( + 0, ==, + nghttp2_submit_response2(session, 1, resnv, ARRLEN(resnv), &data_prd)); + assert_int(0, ==, nghttp2_session_send(session)); - CU_ASSERT(0 == - nghttp2_submit_trailer(session, 1, trailernv, ARRLEN(trailernv))); + assert_int(0, ==, + nghttp2_submit_trailer(session, 1, trailernv, ARRLEN(trailernv))); - session->callbacks.send_callback = accumulator_send_callback; + session->callbacks.send_callback2 = accumulator_send_callback; item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_HEADERS == item->frame.hd.type); - CU_ASSERT(NGHTTP2_HCAT_HEADERS == item->frame.headers.cat); - CU_ASSERT(item->frame.hd.flags & NGHTTP2_FLAG_END_STREAM); + assert_uint8(NGHTTP2_HEADERS, ==, item->frame.hd.type); + assert_enum(nghttp2_headers_category, NGHTTP2_HCAT_HEADERS, ==, + item->frame.headers.cat); + assert_true(item->frame.hd.flags & NGHTTP2_FLAG_END_STREAM); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == unpack_frame(&frame, acc.buf, acc.length)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(0, ==, unpack_frame(&frame, acc.buf, acc.length)); nghttp2_bufs_add(&bufs, acc.buf, acc.length); inflate_hd(&inflater, &out, &bufs, NGHTTP2_FRAME_HDLEN, mem); - CU_ASSERT(ARRLEN(trailernv) == out.nvlen); + assert_size(ARRLEN(trailernv), ==, out.nvlen); assert_nv_equal(trailernv, out.nva, out.nvlen, mem); nva_out_reset(&out, mem); @@ -5718,11 +5921,11 @@ void test_nghttp2_submit_trailer(void) { nghttp2_session_server_new(&session, &callbacks, NULL); open_recv_stream(session, 1); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_submit_trailer(session, 0, trailernv, ARRLEN(trailernv))); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, + nghttp2_submit_trailer(session, 0, trailernv, ARRLEN(trailernv))); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_submit_trailer(session, -1, trailernv, ARRLEN(trailernv))); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, + nghttp2_submit_trailer(session, -1, trailernv, ARRLEN(trailernv))); nghttp2_session_del(session); } @@ -5736,16 +5939,17 @@ void test_nghttp2_submit_headers_start_stream(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, NULL)); - CU_ASSERT(1 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, -1, - NULL, reqnv, ARRLEN(reqnv), NULL)); + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, NULL)); + assert_int32(1, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, -1, + NULL, reqnv, ARRLEN(reqnv), NULL)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(ARRLEN(reqnv) == item->frame.headers.nvlen); + assert_size(ARRLEN(reqnv), ==, item->frame.headers.nvlen); assert_nv_equal(reqnv, item->frame.headers.nva, item->frame.headers.nvlen, mem); - CU_ASSERT((NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM) == - item->frame.hd.flags); - CU_ASSERT(0 == (item->frame.hd.flags & NGHTTP2_FLAG_PRIORITY)); + assert_uint8((NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM), ==, + item->frame.hd.flags); + assert_false(item->frame.hd.flags & NGHTTP2_FLAG_PRIORITY); nghttp2_session_del(session); } @@ -5761,34 +5965,36 @@ void test_nghttp2_submit_headers_reply(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; - CU_ASSERT(0 == nghttp2_session_server_new(&session, &callbacks, &ud)); - CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 1, - NULL, resnv, ARRLEN(resnv), NULL)); + assert_int(0, ==, nghttp2_session_server_new(&session, &callbacks, &ud)); + assert_int32(0, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 1, NULL, + resnv, ARRLEN(resnv), NULL)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(ARRLEN(resnv) == item->frame.headers.nvlen); + assert_size(ARRLEN(resnv), ==, item->frame.headers.nvlen); assert_nv_equal(resnv, item->frame.headers.nva, item->frame.headers.nvlen, mem); - CU_ASSERT((NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS) == - item->frame.hd.flags); + assert_uint8((NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS), ==, + item->frame.hd.flags); ud.frame_send_cb_called = 0; ud.sent_frame_type = 0; /* The transimission will be canceled because the stream 1 is not open. */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == ud.frame_send_cb_called); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(0, ==, ud.frame_send_cb_called); stream = open_recv_stream2(session, 1, NGHTTP2_STREAM_OPENING); - CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 1, - NULL, resnv, ARRLEN(resnv), NULL)); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_send_cb_called); - CU_ASSERT(NGHTTP2_HEADERS == ud.sent_frame_type); - CU_ASSERT(stream->shut_flags & NGHTTP2_SHUT_WR); + assert_int32(0, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 1, NULL, + resnv, ARRLEN(resnv), NULL)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(1, ==, ud.frame_send_cb_called); + assert_uint8(NGHTTP2_HEADERS, ==, ud.sent_frame_type); + assert_true(stream->shut_flags & NGHTTP2_SHUT_WR); nghttp2_session_del(session); } @@ -5801,35 +6007,37 @@ void test_nghttp2_submit_headers_push_reply(void) { int foo; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; - CU_ASSERT(0 == nghttp2_session_server_new(&session, &callbacks, &ud)); + assert_int(0, ==, nghttp2_session_server_new(&session, &callbacks, &ud)); stream = open_sent_stream2(session, 2, NGHTTP2_STREAM_RESERVED); - CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 2, NULL, - resnv, ARRLEN(resnv), &foo)); + assert_int32(0, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 2, NULL, + resnv, ARRLEN(resnv), &foo)); ud.frame_send_cb_called = 0; ud.sent_frame_type = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_send_cb_called); - CU_ASSERT(NGHTTP2_HEADERS == ud.sent_frame_type); - CU_ASSERT(NGHTTP2_STREAM_OPENED == stream->state); - CU_ASSERT(&foo == stream->stream_user_data); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(1, ==, ud.frame_send_cb_called); + assert_uint8(NGHTTP2_HEADERS, ==, ud.sent_frame_type); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENED, ==, stream->state); + assert_ptr_equal(&foo, stream->stream_user_data); nghttp2_session_del(session); /* Sending HEADERS from client against stream in reserved state is error */ - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, &ud)); + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, &ud)); open_recv_stream2(session, 2, NGHTTP2_STREAM_RESERVED); - CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 2, NULL, - reqnv, ARRLEN(reqnv), NULL)); + assert_int32(0, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 2, NULL, + reqnv, ARRLEN(reqnv), NULL)); ud.frame_send_cb_called = 0; ud.sent_frame_type = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == ud.frame_send_cb_called); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(0, ==, ud.frame_send_cb_called); nghttp2_session_del(session); } @@ -5855,43 +6063,45 @@ void test_nghttp2_submit_headers(void) { acc.length = 0; ud.acc = &acc; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = accumulator_send_callback; + callbacks.send_callback2 = accumulator_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, &ud)); + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, &ud)); nghttp2_hd_inflate_init(&inflater, mem); - CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 1, - NULL, reqnv, ARRLEN(reqnv), NULL)); + assert_int32(0, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 1, NULL, + reqnv, ARRLEN(reqnv), NULL)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(ARRLEN(reqnv) == item->frame.headers.nvlen); + assert_size(ARRLEN(reqnv), ==, item->frame.headers.nvlen); assert_nv_equal(reqnv, item->frame.headers.nva, item->frame.headers.nvlen, mem); - CU_ASSERT((NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS) == - item->frame.hd.flags); + assert_uint8((NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS), ==, + item->frame.hd.flags); ud.frame_send_cb_called = 0; ud.sent_frame_type = 0; /* The transimission will be canceled because the stream 1 is not open. */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == ud.frame_send_cb_called); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(0, ==, ud.frame_send_cb_called); stream = open_sent_stream(session, 1); - CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 1, - NULL, reqnv, ARRLEN(reqnv), NULL)); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_send_cb_called); - CU_ASSERT(NGHTTP2_HEADERS == ud.sent_frame_type); - CU_ASSERT(stream->shut_flags & NGHTTP2_SHUT_WR); + assert_int32(0, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 1, NULL, + reqnv, ARRLEN(reqnv), NULL)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(1, ==, ud.frame_send_cb_called); + assert_uint8(NGHTTP2_HEADERS, ==, ud.sent_frame_type); + assert_true(stream->shut_flags & NGHTTP2_SHUT_WR); - CU_ASSERT(0 == unpack_frame(&frame, acc.buf, acc.length)); + assert_int(0, ==, unpack_frame(&frame, acc.buf, acc.length)); nghttp2_bufs_add(&bufs, acc.buf, acc.length); inflate_hd(&inflater, &out, &bufs, NGHTTP2_FRAME_HDLEN, mem); - CU_ASSERT(ARRLEN(reqnv) == out.nvlen); + assert_size(ARRLEN(reqnv), ==, out.nvlen); assert_nv_equal(reqnv, out.nva, out.nvlen, mem); nva_out_reset(&out, mem); @@ -5903,16 +6113,16 @@ void test_nghttp2_submit_headers(void) { /* Try to depend on itself */ nghttp2_priority_spec_init(&pri_spec, 3, 16, 0); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 3, &pri_spec, - reqnv, ARRLEN(reqnv), NULL)); + assert_int32(NGHTTP2_ERR_INVALID_ARGUMENT, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 3, &pri_spec, + reqnv, ARRLEN(reqnv), NULL)); session->next_stream_id = 5; nghttp2_priority_spec_init(&pri_spec, 5, 16, 0); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, -1, &pri_spec, - reqnv, ARRLEN(reqnv), NULL)); + assert_int32(NGHTTP2_ERR_INVALID_ARGUMENT, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, -1, &pri_spec, + reqnv, ARRLEN(reqnv), NULL)); nghttp2_session_del(session); @@ -5921,14 +6131,14 @@ void test_nghttp2_submit_headers(void) { /* Sending nghttp2_submit_headers() with stream_id == 1 and server session is error */ - CU_ASSERT(NGHTTP2_ERR_PROTO == - nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, -1, NULL, reqnv, - ARRLEN(reqnv), NULL)); + assert_int32(NGHTTP2_ERR_PROTO, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, -1, NULL, + reqnv, ARRLEN(reqnv), NULL)); /* Sending stream ID <= 0 is error */ - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 0, NULL, resnv, - ARRLEN(resnv), NULL)); + assert_int32(NGHTTP2_ERR_INVALID_ARGUMENT, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 0, NULL, + resnv, ARRLEN(resnv), NULL)); nghttp2_session_del(session); } @@ -5953,21 +6163,22 @@ void test_nghttp2_submit_headers_continuation(void) { } memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, &ud)); - CU_ASSERT(1 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, -1, - NULL, nv, ARRLEN(nv), NULL)); + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, &ud)); + assert_int32(1, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, -1, + NULL, nv, ARRLEN(nv), NULL)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_HEADERS == item->frame.hd.type); - CU_ASSERT((NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS) == - item->frame.hd.flags); - CU_ASSERT(0 == (item->frame.hd.flags & NGHTTP2_FLAG_PRIORITY)); + assert_uint8(NGHTTP2_HEADERS, ==, item->frame.hd.type); + assert_uint8((NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS), ==, + item->frame.hd.flags); + assert_false(item->frame.hd.flags & NGHTTP2_FLAG_PRIORITY); ud.frame_send_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_send_cb_called); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(1, ==, ud.frame_send_cb_called); nghttp2_session_del(session); } @@ -5992,7 +6203,7 @@ void test_nghttp2_submit_headers_continuation_extra_large(void) { } memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; /* The default size of max send header block length is too small to @@ -6000,18 +6211,20 @@ void test_nghttp2_submit_headers_continuation_extra_large(void) { nghttp2_option_new(&opt); nghttp2_option_set_max_send_header_block_length(opt, 102400); - CU_ASSERT(0 == nghttp2_session_client_new2(&session, &callbacks, &ud, opt)); - CU_ASSERT(1 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, -1, - NULL, nv, ARRLEN(nv), NULL)); + assert_int(0, ==, + nghttp2_session_client_new2(&session, &callbacks, &ud, opt)); + assert_int32(1, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, -1, + NULL, nv, ARRLEN(nv), NULL)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_HEADERS == item->frame.hd.type); - CU_ASSERT((NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS) == - item->frame.hd.flags); - CU_ASSERT(0 == (item->frame.hd.flags & NGHTTP2_FLAG_PRIORITY)); + assert_uint8(NGHTTP2_HEADERS, ==, item->frame.hd.type); + assert_uint8((NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS), ==, + item->frame.hd.flags); + assert_false(item->frame.hd.flags & NGHTTP2_FLAG_PRIORITY); ud.frame_send_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_send_cb_called); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(1, ==, ud.frame_send_cb_called); nghttp2_session_del(session); nghttp2_option_del(opt); @@ -6025,7 +6238,7 @@ void test_nghttp2_submit_priority(void) { nghttp2_priority_spec pri_spec; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; nghttp2_session_client_new(&session, &callbacks, &ud); @@ -6034,18 +6247,18 @@ void test_nghttp2_submit_priority(void) { nghttp2_priority_spec_init(&pri_spec, 0, 3, 0); /* depends on stream 0 */ - CU_ASSERT(0 == - nghttp2_submit_priority(session, NGHTTP2_FLAG_NONE, 1, &pri_spec)); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(3 == stream->weight); + assert_int(0, ==, + nghttp2_submit_priority(session, NGHTTP2_FLAG_NONE, 1, &pri_spec)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int32(3, ==, stream->weight); /* submit against idle stream */ - CU_ASSERT(0 == - nghttp2_submit_priority(session, NGHTTP2_FLAG_NONE, 3, &pri_spec)); + assert_int(0, ==, + nghttp2_submit_priority(session, NGHTTP2_FLAG_NONE, 3, &pri_spec)); ud.frame_send_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_send_cb_called); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(1, ==, ud.frame_send_cb_called); nghttp2_session_del(session); } @@ -6085,70 +6298,73 @@ void test_nghttp2_submit_settings(void) { iv[6].value = (uint32_t)NGHTTP2_MAX_WINDOW_SIZE + 1; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; nghttp2_session_server_new(&session, &callbacks, &ud); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 7)); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, + nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 7)); /* Make sure that local settings are not changed */ - CU_ASSERT(NGHTTP2_DEFAULT_MAX_CONCURRENT_STREAMS == - session->local_settings.max_concurrent_streams); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE == - session->local_settings.initial_window_size); + assert_uint32(NGHTTP2_DEFAULT_MAX_CONCURRENT_STREAMS, ==, + session->local_settings.max_concurrent_streams); + assert_uint32(NGHTTP2_INITIAL_WINDOW_SIZE, ==, + session->local_settings.initial_window_size); /* Now sends without 6th one */ - CU_ASSERT(0 == nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 6)); + assert_int(0, ==, nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 6)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_SETTINGS == item->frame.hd.type); + assert_uint8(NGHTTP2_SETTINGS, ==, item->frame.hd.type); frame = &item->frame; - CU_ASSERT(6 == frame->settings.niv); - CU_ASSERT(5 == frame->settings.iv[0].value); - CU_ASSERT(NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS == - frame->settings.iv[0].settings_id); + assert_size(6, ==, frame->settings.niv); + assert_uint32(5, ==, frame->settings.iv[0].value); + assert_int32(NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, ==, + frame->settings.iv[0].settings_id); - CU_ASSERT(16 * 1024 == frame->settings.iv[1].value); - CU_ASSERT(NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE == - frame->settings.iv[1].settings_id); + assert_uint32(16 * 1024, ==, frame->settings.iv[1].value); + assert_int32(NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE, ==, + frame->settings.iv[1].settings_id); - CU_ASSERT(UNKNOWN_ID == frame->settings.iv[4].settings_id); - CU_ASSERT(999 == frame->settings.iv[4].value); + assert_int32(UNKNOWN_ID, ==, frame->settings.iv[4].settings_id); + assert_uint32(999, ==, frame->settings.iv[4].value); ud.frame_send_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_send_cb_called); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(1, ==, ud.frame_send_cb_called); - CU_ASSERT(50 == session->pending_local_max_concurrent_stream); + assert_uint32(50, ==, session->pending_local_max_concurrent_stream); /* before receiving SETTINGS ACK, local settings have still default values */ - CU_ASSERT(NGHTTP2_DEFAULT_MAX_CONCURRENT_STREAMS == - nghttp2_session_get_local_settings( - session, NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS)); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE == - nghttp2_session_get_local_settings( - session, NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE)); + assert_uint32(NGHTTP2_DEFAULT_MAX_CONCURRENT_STREAMS, ==, + nghttp2_session_get_local_settings( + session, NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS)); + assert_uint32(NGHTTP2_INITIAL_WINDOW_SIZE, ==, + nghttp2_session_get_local_settings( + session, NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE)); nghttp2_frame_settings_init(&ack_frame.settings, NGHTTP2_FLAG_ACK, NULL, 0); - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &ack_frame, 0)); + assert_int(0, ==, + nghttp2_session_on_settings_received(session, &ack_frame, 0)); nghttp2_frame_settings_free(&ack_frame.settings, mem); - CU_ASSERT(16 * 1024 == session->local_settings.initial_window_size); - CU_ASSERT(111 == session->hd_inflater.ctx.hd_table_bufsize_max); - CU_ASSERT(111 == session->hd_inflater.min_hd_table_bufsize_max); - CU_ASSERT(50 == session->local_settings.max_concurrent_streams); + assert_uint32(16 * 1024, ==, session->local_settings.initial_window_size); + assert_size(111, ==, session->hd_inflater.ctx.hd_table_bufsize_max); + assert_size(111, ==, session->hd_inflater.min_hd_table_bufsize_max); + assert_uint32(50, ==, session->local_settings.max_concurrent_streams); - CU_ASSERT(50 == nghttp2_session_get_local_settings( - session, NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS)); - CU_ASSERT(16 * 1024 == nghttp2_session_get_local_settings( - session, NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE)); + assert_uint32(50, ==, + nghttp2_session_get_local_settings( + session, NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS)); + assert_uint32(16 * 1024, ==, + nghttp2_session_get_local_settings( + session, NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE)); /* We just keep the last seen value */ - CU_ASSERT(50 == session->pending_local_max_concurrent_stream); + assert_uint32(50, ==, session->pending_local_max_concurrent_stream); nghttp2_session_del(session); @@ -6161,8 +6377,8 @@ void test_nghttp2_submit_settings(void) { iv[1].settings_id = NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES; iv[1].value = 0; - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 2)); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, + nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 2)); nghttp2_session_del(session); @@ -6173,13 +6389,13 @@ void test_nghttp2_submit_settings(void) { iv[0].settings_id = NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES; iv[0].value = 1; - CU_ASSERT(0 == nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 1)); + assert_int(0, ==, nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 1)); iv[0].settings_id = NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES; iv[0].value = 0; - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 1)); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, + nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 1)); nghttp2_session_del(session); } @@ -6201,7 +6417,7 @@ void test_nghttp2_submit_settings_update_local_window_size(void) { iv[0].value = 16 * 1024; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_server_new(&session, &callbacks, NULL); @@ -6211,20 +6427,21 @@ void test_nghttp2_submit_settings_update_local_window_size(void) { open_recv_stream(session, 3); - CU_ASSERT(0 == nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 1)); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &ack_frame, 0)); + assert_int(0, ==, nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 1)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(0, ==, + nghttp2_session_on_settings_received(session, &ack_frame, 0)); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(0 == stream->recv_window_size); - CU_ASSERT(16 * 1024 + 100 == stream->local_window_size); + assert_int32(0, ==, stream->recv_window_size); + assert_int32(16 * 1024 + 100, ==, stream->local_window_size); stream = nghttp2_session_get_stream(session, 3); - CU_ASSERT(16 * 1024 == stream->local_window_size); + assert_int32(16 * 1024, ==, stream->local_window_size); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); - CU_ASSERT(32768 == item->frame.window_update.window_size_increment); + assert_uint8(NGHTTP2_WINDOW_UPDATE, ==, item->frame.hd.type); + assert_int32(32768, ==, item->frame.window_update.window_size_increment); nghttp2_session_del(session); @@ -6240,17 +6457,18 @@ void test_nghttp2_submit_settings_update_local_window_size(void) { stream->local_window_size = NGHTTP2_INITIAL_WINDOW_SIZE + 100; stream->recv_window_size = 32768; - CU_ASSERT(0 == nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 1)); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &ack_frame, 0)); + assert_int(0, ==, nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 1)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(0, ==, + nghttp2_session_on_settings_received(session, &ack_frame, 0)); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(32768 == stream->recv_window_size); - CU_ASSERT(16 * 1024 + 100 == stream->local_window_size); + assert_int32(32768, ==, stream->recv_window_size); + assert_int32(16 * 1024 + 100, ==, stream->local_window_size); /* Check that we can handle the case where local_window_size < recv_window_size */ - CU_ASSERT(0 == nghttp2_session_get_stream_local_window_size(session, 1)); + assert_int32(0, ==, nghttp2_session_get_stream_local_window_size(session, 1)); nghttp2_session_del(session); @@ -6260,13 +6478,15 @@ void test_nghttp2_submit_settings_update_local_window_size(void) { stream = open_recv_stream(session, 1); stream->local_window_size = NGHTTP2_MAX_WINDOW_SIZE; - CU_ASSERT(0 == nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 1)); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &ack_frame, 0)); + assert_int(0, ==, nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 1)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(0, ==, + nghttp2_session_on_settings_received(session, &ack_frame, 0)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(NGHTTP2_FLOW_CONTROL_ERROR == item->frame.rst_stream.error_code); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_FLOW_CONTROL_ERROR, ==, + item->frame.rst_stream.error_code); nghttp2_session_del(session); nghttp2_frame_settings_free(&ack_frame.settings, mem); @@ -6280,7 +6500,7 @@ void test_nghttp2_submit_settings_multiple_times(void) { nghttp2_inflight_settings *inflight_settings; memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, NULL); @@ -6291,60 +6511,60 @@ void test_nghttp2_submit_settings_multiple_times(void) { iv[1].settings_id = NGHTTP2_SETTINGS_ENABLE_PUSH; iv[1].value = 0; - CU_ASSERT(0 == nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 2)); + assert_int(0, ==, nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 2)); inflight_settings = session->inflight_settings_head; - CU_ASSERT(NULL != inflight_settings); - CU_ASSERT(NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS == - inflight_settings->iv[0].settings_id); - CU_ASSERT(100 == inflight_settings->iv[0].value); - CU_ASSERT(2 == inflight_settings->niv); - CU_ASSERT(NULL == inflight_settings->next); + assert_not_null(inflight_settings); + assert_int32(NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, ==, + inflight_settings->iv[0].settings_id); + assert_uint32(100, ==, inflight_settings->iv[0].value); + assert_size(2, ==, inflight_settings->niv); + assert_null(inflight_settings->next); - CU_ASSERT(100 == session->pending_local_max_concurrent_stream); - CU_ASSERT(0 == session->pending_enable_push); + assert_uint32(100, ==, session->pending_local_max_concurrent_stream); + assert_uint8(0, ==, session->pending_enable_push); /* second SETTINGS */ iv[0].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS; iv[0].value = 99; - CU_ASSERT(0 == nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 1)); + assert_int(0, ==, nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, iv, 1)); inflight_settings = session->inflight_settings_head->next; - CU_ASSERT(NULL != inflight_settings); - CU_ASSERT(NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS == - inflight_settings->iv[0].settings_id); - CU_ASSERT(99 == inflight_settings->iv[0].value); - CU_ASSERT(1 == inflight_settings->niv); - CU_ASSERT(NULL == inflight_settings->next); + assert_not_null(inflight_settings); + assert_int32(NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, ==, + inflight_settings->iv[0].settings_id); + assert_uint32(99, ==, inflight_settings->iv[0].value); + assert_size(1, ==, inflight_settings->niv); + assert_null(inflight_settings->next); - CU_ASSERT(99 == session->pending_local_max_concurrent_stream); - CU_ASSERT(0 == session->pending_enable_push); + assert_uint32(99, ==, session->pending_local_max_concurrent_stream); + assert_uint8(0, ==, session->pending_enable_push); nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_ACK, NULL, 0); /* receive SETTINGS ACK */ - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &frame, 0)); + assert_int(0, ==, nghttp2_session_on_settings_received(session, &frame, 0)); inflight_settings = session->inflight_settings_head; /* first inflight SETTINGS was removed */ - CU_ASSERT(NULL != inflight_settings); - CU_ASSERT(NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS == - inflight_settings->iv[0].settings_id); - CU_ASSERT(99 == inflight_settings->iv[0].value); - CU_ASSERT(1 == inflight_settings->niv); - CU_ASSERT(NULL == inflight_settings->next); + assert_not_null(inflight_settings); + assert_int32(NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, ==, + inflight_settings->iv[0].settings_id); + assert_uint32(99, ==, inflight_settings->iv[0].value); + assert_size(1, ==, inflight_settings->niv); + assert_null(inflight_settings->next); - CU_ASSERT(100 == session->local_settings.max_concurrent_streams); + assert_uint32(100, ==, session->local_settings.max_concurrent_streams); /* receive SETTINGS ACK again */ - CU_ASSERT(0 == nghttp2_session_on_settings_received(session, &frame, 0)); + assert_int(0, ==, nghttp2_session_on_settings_received(session, &frame, 0)); - CU_ASSERT(NULL == session->inflight_settings_head); - CU_ASSERT(99 == session->local_settings.max_concurrent_streams); + assert_null(session->inflight_settings_head); + assert_uint32(99, ==, session->local_settings.max_concurrent_streams); nghttp2_session_del(session); } @@ -6356,42 +6576,43 @@ void test_nghttp2_submit_push_promise(void) { nghttp2_stream *stream; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; callbacks.on_frame_not_send_callback = on_frame_not_send_callback; - CU_ASSERT(0 == nghttp2_session_server_new(&session, &callbacks, &ud)); + assert_int(0, ==, nghttp2_session_server_new(&session, &callbacks, &ud)); open_recv_stream(session, 1); - CU_ASSERT(2 == nghttp2_submit_push_promise(session, NGHTTP2_FLAG_NONE, 1, - reqnv, ARRLEN(reqnv), &ud)); + assert_int32(2, ==, + nghttp2_submit_push_promise(session, NGHTTP2_FLAG_NONE, 1, reqnv, + ARRLEN(reqnv), &ud)); stream = nghttp2_session_get_stream(session, 2); - CU_ASSERT(NULL != stream); - CU_ASSERT(NGHTTP2_STREAM_RESERVED == stream->state); - CU_ASSERT(&ud == nghttp2_session_get_stream_user_data(session, 2)); + assert_not_null(stream); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_RESERVED, ==, stream->state); + assert_ptr_equal(&ud, nghttp2_session_get_stream_user_data(session, 2)); ud.frame_send_cb_called = 0; ud.sent_frame_type = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_send_cb_called); - CU_ASSERT(NGHTTP2_PUSH_PROMISE == ud.sent_frame_type); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(1, ==, ud.frame_send_cb_called); + assert_uint8(NGHTTP2_PUSH_PROMISE, ==, ud.sent_frame_type); stream = nghttp2_session_get_stream(session, 2); - CU_ASSERT(NGHTTP2_STREAM_RESERVED == stream->state); - CU_ASSERT(&ud == nghttp2_session_get_stream_user_data(session, 2)); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_RESERVED, ==, stream->state); + assert_ptr_equal(&ud, nghttp2_session_get_stream_user_data(session, 2)); /* submit PUSH_PROMISE while associated stream is not opened */ - CU_ASSERT(NGHTTP2_ERR_STREAM_CLOSED == - nghttp2_submit_push_promise(session, NGHTTP2_FLAG_NONE, 3, reqnv, - ARRLEN(reqnv), NULL)); + assert_int32(NGHTTP2_ERR_STREAM_CLOSED, ==, + nghttp2_submit_push_promise(session, NGHTTP2_FLAG_NONE, 3, reqnv, + ARRLEN(reqnv), NULL)); /* Stream ID <= 0 is error */ - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_submit_push_promise(session, NGHTTP2_FLAG_NONE, 0, reqnv, - ARRLEN(reqnv), NULL)); + assert_int32(NGHTTP2_ERR_INVALID_ARGUMENT, ==, + nghttp2_submit_push_promise(session, NGHTTP2_FLAG_NONE, 0, reqnv, + ARRLEN(reqnv), NULL)); nghttp2_session_del(session); } @@ -6404,42 +6625,42 @@ void test_nghttp2_submit_window_update(void) { nghttp2_stream *stream; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, &ud); stream = open_recv_stream(session, 2); stream->recv_window_size = 4096; - CU_ASSERT(0 == - nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, 1024)); + assert_int(0, ==, + nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, 1024)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); - CU_ASSERT(1024 == item->frame.window_update.window_size_increment); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(3072 == stream->recv_window_size); + assert_uint8(NGHTTP2_WINDOW_UPDATE, ==, item->frame.hd.type); + assert_int32(1024, ==, item->frame.window_update.window_size_increment); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int32(3072, ==, stream->recv_window_size); - CU_ASSERT(0 == - nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, 4096)); + assert_int(0, ==, + nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, 4096)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); - CU_ASSERT(4096 == item->frame.window_update.window_size_increment); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == stream->recv_window_size); + assert_uint8(NGHTTP2_WINDOW_UPDATE, ==, item->frame.hd.type); + assert_int32(4096, ==, item->frame.window_update.window_size_increment); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int32(0, ==, stream->recv_window_size); - CU_ASSERT(0 == - nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, 4096)); + assert_int(0, ==, + nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, 4096)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); - CU_ASSERT(4096 == item->frame.window_update.window_size_increment); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == stream->recv_window_size); + assert_uint8(NGHTTP2_WINDOW_UPDATE, ==, item->frame.hd.type); + assert_int32(4096, ==, item->frame.window_update.window_size_increment); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int32(0, ==, stream->recv_window_size); - CU_ASSERT(0 == - nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, 0)); + assert_int(0, ==, + nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, 0)); /* It is ok if stream is closed or does not exist at the call time */ - CU_ASSERT(0 == - nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 4, 4096)); + assert_int(0, ==, + nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 4, 4096)); nghttp2_session_del(session); } @@ -6451,81 +6672,87 @@ void test_nghttp2_submit_window_update_local_window_size(void) { nghttp2_stream *stream; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, NULL); stream = open_recv_stream(session, 2); stream->recv_window_size = 4096; - CU_ASSERT(0 == nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, - stream->recv_window_size + 1)); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE + 1 == stream->local_window_size); - CU_ASSERT(0 == stream->recv_window_size); + assert_int(0, ==, + nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, + stream->recv_window_size + 1)); + assert_int32(NGHTTP2_INITIAL_WINDOW_SIZE + 1, ==, stream->local_window_size); + assert_int32(0, ==, stream->recv_window_size); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); - CU_ASSERT(4097 == item->frame.window_update.window_size_increment); + assert_uint8(NGHTTP2_WINDOW_UPDATE, ==, item->frame.hd.type); + assert_int32(4097, ==, item->frame.window_update.window_size_increment); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); /* Let's decrement local window size */ stream->recv_window_size = 4096; - CU_ASSERT(0 == nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, - -stream->local_window_size / 2)); - CU_ASSERT(32768 == stream->local_window_size); - CU_ASSERT(-28672 == stream->recv_window_size); - CU_ASSERT(32768 == stream->recv_reduction); + assert_int(0, ==, + nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, + -stream->local_window_size / 2)); + assert_int32(32768, ==, stream->local_window_size); + assert_int32(-28672, ==, stream->recv_window_size); + assert_int32(32768, ==, stream->recv_reduction); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(item == NULL); + assert_null(item); /* Increase local window size */ - CU_ASSERT(0 == - nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, 16384)); - CU_ASSERT(49152 == stream->local_window_size); - CU_ASSERT(-12288 == stream->recv_window_size); - CU_ASSERT(16384 == stream->recv_reduction); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_int( + 0, ==, + nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, 16384)); + assert_int32(49152, ==, stream->local_window_size); + assert_int32(-12288, ==, stream->recv_window_size); + assert_int32(16384, ==, stream->recv_reduction); + assert_null(nghttp2_session_get_next_ob_item(session)); - CU_ASSERT(NGHTTP2_ERR_FLOW_CONTROL == - nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, - NGHTTP2_MAX_WINDOW_SIZE)); + assert_int(NGHTTP2_ERR_FLOW_CONTROL, ==, + nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 2, + NGHTTP2_MAX_WINDOW_SIZE)); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); /* Check connection-level flow control */ session->recv_window_size = 4096; - CU_ASSERT(0 == nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 0, - session->recv_window_size + 1)); - CU_ASSERT(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1 == - session->local_window_size); - CU_ASSERT(0 == session->recv_window_size); + assert_int(0, ==, + nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 0, + session->recv_window_size + 1)); + assert_int32(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1, ==, + session->local_window_size); + assert_int32(0, ==, session->recv_window_size); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); - CU_ASSERT(4097 == item->frame.window_update.window_size_increment); + assert_uint8(NGHTTP2_WINDOW_UPDATE, ==, item->frame.hd.type); + assert_int32(4097, ==, item->frame.window_update.window_size_increment); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); /* Go decrement part */ session->recv_window_size = 4096; - CU_ASSERT(0 == nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 0, - -session->local_window_size / 2)); - CU_ASSERT(32768 == session->local_window_size); - CU_ASSERT(-28672 == session->recv_window_size); - CU_ASSERT(32768 == session->recv_reduction); + assert_int(0, ==, + nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 0, + -session->local_window_size / 2)); + assert_int32(32768, ==, session->local_window_size); + assert_int32(-28672, ==, session->recv_window_size); + assert_int32(32768, ==, session->recv_reduction); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(item == NULL); + assert_null(item); /* Increase local window size */ - CU_ASSERT(0 == - nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 0, 16384)); - CU_ASSERT(49152 == session->local_window_size); - CU_ASSERT(-12288 == session->recv_window_size); - CU_ASSERT(16384 == session->recv_reduction); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_int( + 0, ==, + nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 0, 16384)); + assert_int32(49152, ==, session->local_window_size); + assert_int32(-12288, ==, session->recv_window_size); + assert_int32(16384, ==, session->recv_reduction); + assert_null(nghttp2_session_get_next_ob_item(session)); - CU_ASSERT(NGHTTP2_ERR_FLOW_CONTROL == - nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 0, - NGHTTP2_MAX_WINDOW_SIZE)); + assert_int(NGHTTP2_ERR_FLOW_CONTROL, ==, + nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 0, + NGHTTP2_MAX_WINDOW_SIZE)); nghttp2_session_del(session); } @@ -6536,43 +6763,44 @@ void test_nghttp2_submit_shutdown_notice(void) { my_user_data ud; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; callbacks.on_frame_not_send_callback = on_frame_not_send_callback; nghttp2_session_server_new(&session, &callbacks, &ud); - CU_ASSERT(0 == nghttp2_submit_shutdown_notice(session)); + assert_int(0, ==, nghttp2_submit_shutdown_notice(session)); ud.frame_send_cb_called = 0; nghttp2_session_send(session); - CU_ASSERT(1 == ud.frame_send_cb_called); - CU_ASSERT(NGHTTP2_GOAWAY == ud.sent_frame_type); - CU_ASSERT((1u << 31) - 1 == session->local_last_stream_id); + assert_int(1, ==, ud.frame_send_cb_called); + assert_uint8(NGHTTP2_GOAWAY, ==, ud.sent_frame_type); + assert_int32((1u << 31) - 1, ==, session->local_last_stream_id); /* After another GOAWAY, nghttp2_submit_shutdown_notice() is noop. */ - CU_ASSERT(0 == nghttp2_session_terminate_session(session, NGHTTP2_NO_ERROR)); + assert_int(0, ==, + nghttp2_session_terminate_session(session, NGHTTP2_NO_ERROR)); ud.frame_send_cb_called = 0; nghttp2_session_send(session); - CU_ASSERT(1 == ud.frame_send_cb_called); - CU_ASSERT(NGHTTP2_GOAWAY == ud.sent_frame_type); - CU_ASSERT(0 == session->local_last_stream_id); + assert_int(1, ==, ud.frame_send_cb_called); + assert_uint8(NGHTTP2_GOAWAY, ==, ud.sent_frame_type); + assert_int32(0, ==, session->local_last_stream_id); - CU_ASSERT(0 == nghttp2_submit_shutdown_notice(session)); + assert_int(0, ==, nghttp2_submit_shutdown_notice(session)); ud.frame_send_cb_called = 0; ud.frame_not_send_cb_called = 0; nghttp2_session_send(session); - CU_ASSERT(0 == ud.frame_send_cb_called); - CU_ASSERT(0 == ud.frame_not_send_cb_called); + assert_int(0, ==, ud.frame_send_cb_called); + assert_int(0, ==, ud.frame_not_send_cb_called); nghttp2_session_del(session); @@ -6580,8 +6808,8 @@ void test_nghttp2_submit_shutdown_notice(void) { is error */ nghttp2_session_client_new(&session, &callbacks, NULL); - CU_ASSERT(NGHTTP2_ERR_INVALID_STATE == - nghttp2_submit_shutdown_notice(session)); + assert_int(NGHTTP2_ERR_INVALID_STATE, ==, + nghttp2_submit_shutdown_notice(session)); nghttp2_session_del(session); } @@ -6597,31 +6825,35 @@ void test_nghttp2_submit_invalid_nv(void) { memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - CU_ASSERT(0 == nghttp2_session_server_new(&session, &callbacks, NULL)); + assert_int(0, ==, nghttp2_session_server_new(&session, &callbacks, NULL)); /* nghttp2_submit_response */ - CU_ASSERT(0 == nghttp2_submit_response(session, 2, empty_name_nv, - ARRLEN(empty_name_nv), NULL)); + assert_int(0, ==, + nghttp2_submit_response2(session, 2, empty_name_nv, + ARRLEN(empty_name_nv), NULL)); /* nghttp2_submit_push_promise */ open_recv_stream(session, 1); - CU_ASSERT(0 < nghttp2_submit_push_promise(session, NGHTTP2_FLAG_NONE, 1, - empty_name_nv, - ARRLEN(empty_name_nv), NULL)); + assert_int32(0, <, + nghttp2_submit_push_promise(session, NGHTTP2_FLAG_NONE, 1, + empty_name_nv, ARRLEN(empty_name_nv), + NULL)); nghttp2_session_del(session); - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, NULL)); + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, NULL)); /* nghttp2_submit_request */ - CU_ASSERT(0 < nghttp2_submit_request(session, NULL, empty_name_nv, + assert_int32(0, <, + nghttp2_submit_request2(session, NULL, empty_name_nv, ARRLEN(empty_name_nv), NULL, NULL)); /* nghttp2_submit_headers */ - CU_ASSERT(0 < nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, -1, NULL, - empty_name_nv, ARRLEN(empty_name_nv), - NULL)); + assert_int32(0, <, + nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, -1, NULL, + empty_name_nv, ARRLEN(empty_name_nv), + NULL)); nghttp2_session_del(session); } @@ -6641,8 +6873,8 @@ void test_nghttp2_submit_extension(void) { memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.pack_extension_callback = pack_extension_callback; - callbacks.send_callback = accumulator_send_callback; + callbacks.pack_extension_callback2 = pack_extension_callback; + callbacks.send_callback2 = accumulator_send_callback; nghttp2_buf_init2(&ud.scratchbuf, 4096, mem); @@ -6653,25 +6885,25 @@ void test_nghttp2_submit_extension(void) { rv = nghttp2_submit_extension(session, 211, 0x01, 3, &ud.scratchbuf); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); acc.length = 0; rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); - CU_ASSERT(NGHTTP2_FRAME_HDLEN + sizeof(data) == acc.length); + assert_int(0, ==, rv); + assert_size(NGHTTP2_FRAME_HDLEN + sizeof(data), ==, acc.length); len = nghttp2_get_uint32(acc.buf) >> 8; - CU_ASSERT(sizeof(data) == len); - CU_ASSERT(211 == acc.buf[3]); - CU_ASSERT(0x01 == acc.buf[4]); + assert_size(sizeof(data), ==, len); + assert_uint8(211, ==, acc.buf[3]); + assert_uint8(0x01, ==, acc.buf[4]); stream_id = (int32_t)nghttp2_get_uint32(acc.buf + 5); - CU_ASSERT(3 == stream_id); - CU_ASSERT(0 == memcmp(data, &acc.buf[NGHTTP2_FRAME_HDLEN], sizeof(data))); + assert_int32(3, ==, stream_id); + assert_memory_equal(sizeof(data), data, &acc.buf[NGHTTP2_FRAME_HDLEN]); nghttp2_session_del(session); @@ -6681,7 +6913,7 @@ void test_nghttp2_submit_extension(void) { rv = nghttp2_submit_extension(session, NGHTTP2_GOAWAY, NGHTTP2_FLAG_NONE, 0, NULL); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); nghttp2_session_del(session); nghttp2_buf_free(&ud.scratchbuf, mem); @@ -6692,7 +6924,7 @@ void test_nghttp2_submit_altsvc(void) { nghttp2_session_callbacks callbacks; my_user_data ud; int rv; - ssize_t len; + nghttp2_ssize len; const uint8_t *data; nghttp2_frame_hd hd; size_t origin_len; @@ -6707,42 +6939,42 @@ void test_nghttp2_submit_altsvc(void) { sizeof(origin) - 1, field_value, sizeof(field_value) - 1); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); ud.frame_send_cb_called = 0; - len = nghttp2_session_mem_send(session, &data); + len = nghttp2_session_mem_send2(session, &data); - CU_ASSERT(len == NGHTTP2_FRAME_HDLEN + 2 + sizeof(origin) - 1 + - sizeof(field_value) - 1); + assert_ptrdiff(NGHTTP2_FRAME_HDLEN + 2 + sizeof(origin) - 1 + + sizeof(field_value) - 1, + ==, len); nghttp2_frame_unpack_frame_hd(&hd, data); - CU_ASSERT(2 + sizeof(origin) - 1 + sizeof(field_value) - 1 == hd.length); - CU_ASSERT(NGHTTP2_ALTSVC == hd.type); - CU_ASSERT(NGHTTP2_FLAG_NONE == hd.flags); + assert_size(2 + sizeof(origin) - 1 + sizeof(field_value) - 1, ==, hd.length); + assert_uint8(NGHTTP2_ALTSVC, ==, hd.type); + assert_uint8(NGHTTP2_FLAG_NONE, ==, hd.flags); origin_len = nghttp2_get_uint16(data + NGHTTP2_FRAME_HDLEN); - CU_ASSERT(sizeof(origin) - 1 == origin_len); - CU_ASSERT(0 == - memcmp(origin, data + NGHTTP2_FRAME_HDLEN + 2, sizeof(origin) - 1)); - CU_ASSERT(0 == memcmp(field_value, - data + NGHTTP2_FRAME_HDLEN + 2 + sizeof(origin) - 1, - hd.length - (sizeof(origin) - 1) - 2)); + assert_size(sizeof(origin) - 1, ==, origin_len); + assert_memory_equal(sizeof(origin) - 1, origin, + data + NGHTTP2_FRAME_HDLEN + 2); + assert_memory_equal(hd.length - (sizeof(origin) - 1) - 2, field_value, + data + NGHTTP2_FRAME_HDLEN + 2 + sizeof(origin) - 1); /* submitting empty origin with stream_id == 0 is error */ rv = nghttp2_submit_altsvc(session, NGHTTP2_FLAG_NONE, 0, NULL, 0, field_value, sizeof(field_value) - 1); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); /* submitting non-empty origin with stream_id != 0 is error */ rv = nghttp2_submit_altsvc(session, NGHTTP2_FLAG_NONE, 1, origin, sizeof(origin) - 1, field_value, sizeof(field_value) - 1); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); nghttp2_session_del(session); @@ -6753,7 +6985,7 @@ void test_nghttp2_submit_altsvc(void) { sizeof(origin) - 1, field_value, sizeof(field_value) - 1); - CU_ASSERT(NGHTTP2_ERR_INVALID_STATE == rv); + assert_int(NGHTTP2_ERR_INVALID_STATE, ==, rv); nghttp2_session_del(session); } @@ -6763,7 +6995,7 @@ void test_nghttp2_submit_origin(void) { nghttp2_session_callbacks callbacks; my_user_data ud; int rv; - ssize_t len; + nghttp2_ssize len; const uint8_t *data; static const uint8_t nghttp2[] = "https://nghttp2.org"; static const uint8_t examples[] = "https://examples.com"; @@ -6792,27 +7024,27 @@ void test_nghttp2_submit_origin(void) { rv = nghttp2_submit_origin(session, NGHTTP2_FLAG_NONE, ov, 2); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); ud.frame_send_cb_called = 0; - len = nghttp2_session_mem_send(session, &data); + len = nghttp2_session_mem_send2(session, &data); - CU_ASSERT(len > 0); - CU_ASSERT(1 == ud.frame_send_cb_called); + assert_ptrdiff(0, <, len); + assert_int(1, ==, ud.frame_send_cb_called); nghttp2_frame_unpack_frame_hd(&frame.hd, data); rv = nghttp2_frame_unpack_origin_payload( &frame.ext, data + NGHTTP2_FRAME_HDLEN, (size_t)len - NGHTTP2_FRAME_HDLEN, mem); - CU_ASSERT(0 == rv); - CU_ASSERT(0 == frame.hd.stream_id); - CU_ASSERT(NGHTTP2_ORIGIN == frame.hd.type); - CU_ASSERT(2 == origin.nov); - CU_ASSERT(0 == memcmp(nghttp2, origin.ov[0].origin, sizeof(nghttp2) - 1)); - CU_ASSERT(sizeof(nghttp2) - 1 == origin.ov[0].origin_len); - CU_ASSERT(0 == memcmp(examples, origin.ov[1].origin, sizeof(examples) - 1)); - CU_ASSERT(sizeof(examples) - 1 == origin.ov[1].origin_len); + assert_int(0, ==, rv); + assert_int32(0, ==, frame.hd.stream_id); + assert_uint8(NGHTTP2_ORIGIN, ==, frame.hd.type); + assert_size(2, ==, origin.nov); + assert_memory_equal(sizeof(nghttp2) - 1, nghttp2, origin.ov[0].origin); + assert_size(sizeof(nghttp2) - 1, ==, origin.ov[0].origin_len); + assert_memory_equal(sizeof(examples) - 1, examples, origin.ov[1].origin); + assert_size(sizeof(examples) - 1, ==, origin.ov[1].origin_len); nghttp2_frame_origin_free(&frame.ext, mem); @@ -6823,7 +7055,7 @@ void test_nghttp2_submit_origin(void) { rv = nghttp2_submit_origin(session, NGHTTP2_FLAG_NONE, ov, 1); - CU_ASSERT(NGHTTP2_ERR_INVALID_STATE == rv); + assert_int(NGHTTP2_ERR_INVALID_STATE, ==, rv); nghttp2_session_del(session); @@ -6832,17 +7064,17 @@ void test_nghttp2_submit_origin(void) { rv = nghttp2_submit_origin(session, NGHTTP2_FLAG_NONE, NULL, 0); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); ud.frame_send_cb_called = 0; - len = nghttp2_session_mem_send(session, &data); + len = nghttp2_session_mem_send2(session, &data); - CU_ASSERT(len == NGHTTP2_FRAME_HDLEN); - CU_ASSERT(1 == ud.frame_send_cb_called); + assert_ptrdiff(NGHTTP2_FRAME_HDLEN, ==, len); + assert_int(1, ==, ud.frame_send_cb_called); nghttp2_frame_unpack_frame_hd(&frame.hd, data); - CU_ASSERT(NGHTTP2_ORIGIN == frame.hd.type); + assert_uint8(NGHTTP2_ORIGIN, ==, frame.hd.type); nghttp2_session_del(session); } @@ -6856,7 +7088,7 @@ void test_nghttp2_submit_priority_update(void) { int rv; nghttp2_frame frame; nghttp2_ext_priority_update priority_update; - ssize_t len; + nghttp2_ssize len; int32_t stream_id; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); @@ -6867,38 +7099,38 @@ void test_nghttp2_submit_priority_update(void) { session->pending_no_rfc7540_priorities = 1; stream_id = - nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); + nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); - CU_ASSERT(1 == stream_id); + assert_int32(1, ==, stream_id); - len = nghttp2_session_mem_send(session, &data); + len = nghttp2_session_mem_send2(session, &data); - CU_ASSERT(len > 0); + assert_ptrdiff(0, <, len); rv = nghttp2_submit_priority_update(session, NGHTTP2_FLAG_NONE, stream_id, field_value, sizeof(field_value) - 1); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); frame.ext.payload = &priority_update; ud.frame_send_cb_called = 0; - len = nghttp2_session_mem_send(session, &data); + len = nghttp2_session_mem_send2(session, &data); - CU_ASSERT(len > 0); - CU_ASSERT(1 == ud.frame_send_cb_called); + assert_ptrdiff(0, <, len); + assert_int(1, ==, ud.frame_send_cb_called); nghttp2_frame_unpack_frame_hd(&frame.hd, data); nghttp2_frame_unpack_priority_update_payload( &frame.ext, (uint8_t *)(data + NGHTTP2_FRAME_HDLEN), (size_t)len - NGHTTP2_FRAME_HDLEN); - CU_ASSERT(0 == frame.hd.stream_id); - CU_ASSERT(NGHTTP2_PRIORITY_UPDATE == frame.hd.type); - CU_ASSERT(stream_id == priority_update.stream_id); - CU_ASSERT(sizeof(field_value) - 1 == priority_update.field_value_len); - CU_ASSERT(0 == memcmp(field_value, priority_update.field_value, - sizeof(field_value) - 1)); + assert_int32(0, ==, frame.hd.stream_id); + assert_uint8(NGHTTP2_PRIORITY_UPDATE, ==, frame.hd.type); + assert_int32(stream_id, ==, priority_update.stream_id); + assert_size(sizeof(field_value) - 1, ==, priority_update.field_value_len); + assert_memory_equal(sizeof(field_value) - 1, field_value, + priority_update.field_value); nghttp2_session_del(session); @@ -6910,7 +7142,7 @@ void test_nghttp2_submit_priority_update(void) { rv = nghttp2_submit_priority_update(session, NGHTTP2_FLAG_NONE, 1, field_value, sizeof(field_value) - 1); - CU_ASSERT(NGHTTP2_ERR_INVALID_STATE == rv); + assert_int(NGHTTP2_ERR_INVALID_STATE, ==, rv); nghttp2_session_del(session); @@ -6918,35 +7150,35 @@ void test_nghttp2_submit_priority_update(void) { nghttp2_session_client_new(&session, &callbacks, &ud); stream_id = - nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); + nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); - CU_ASSERT(1 == stream_id); + assert_int32(1, ==, stream_id); - len = nghttp2_session_mem_send(session, &data); + len = nghttp2_session_mem_send2(session, &data); - CU_ASSERT(len > 0); + assert_ptrdiff(0, <, len); rv = nghttp2_submit_priority_update(session, NGHTTP2_FLAG_NONE, stream_id, NULL, 0); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); frame.ext.payload = &priority_update; - len = nghttp2_session_mem_send(session, &data); + len = nghttp2_session_mem_send2(session, &data); - CU_ASSERT(len > 0); + assert_ptrdiff(0, <, len); nghttp2_frame_unpack_frame_hd(&frame.hd, data); nghttp2_frame_unpack_priority_update_payload( &frame.ext, (uint8_t *)(data + NGHTTP2_FRAME_HDLEN), (size_t)len - NGHTTP2_FRAME_HDLEN); - CU_ASSERT(0 == frame.hd.stream_id); - CU_ASSERT(NGHTTP2_PRIORITY_UPDATE == frame.hd.type); - CU_ASSERT(stream_id == priority_update.stream_id); - CU_ASSERT(0 == priority_update.field_value_len); - CU_ASSERT(NULL == priority_update.field_value); + assert_int32(0, ==, frame.hd.stream_id); + assert_uint8(NGHTTP2_PRIORITY_UPDATE, ==, frame.hd.type); + assert_int32(stream_id, ==, priority_update.stream_id); + assert_size(0, ==, priority_update.field_value_len); + assert_null(priority_update.field_value); nghttp2_session_del(session); } @@ -6966,11 +7198,11 @@ void test_nghttp2_submit_rst_stream(void) { rv = nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, 1, NGHTTP2_NO_ERROR); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); item = nghttp2_outbound_queue_top(&session->ob_reg); - CU_ASSERT(NULL == item); + assert_null(item); nghttp2_session_del(session); @@ -6980,11 +7212,11 @@ void test_nghttp2_submit_rst_stream(void) { rv = nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, 2, NGHTTP2_NO_ERROR); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); item = nghttp2_outbound_queue_top(&session->ob_reg); - CU_ASSERT(NULL == item); + assert_null(item); nghttp2_session_del(session); @@ -6996,13 +7228,13 @@ void test_nghttp2_submit_rst_stream(void) { rv = nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, 1, NGHTTP2_NO_ERROR); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); item = nghttp2_outbound_queue_top(&session->ob_reg); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(1 == item->frame.hd.stream_id); + assert_not_null(item); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_int32(1, ==, item->frame.hd.stream_id); nghttp2_session_del(session); @@ -7014,13 +7246,13 @@ void test_nghttp2_submit_rst_stream(void) { rv = nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, 2, NGHTTP2_NO_ERROR); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); item = nghttp2_outbound_queue_top(&session->ob_reg); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(2 == item->frame.hd.stream_id); + assert_not_null(item); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_int32(2, ==, item->frame.hd.stream_id); nghttp2_session_del(session); @@ -7028,26 +7260,26 @@ void test_nghttp2_submit_rst_stream(void) { nghttp2_session_client_new(&session, &callbacks, NULL); stream_id = - nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); + nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); - CU_ASSERT(stream_id > 0); + assert_int32(0, <, stream_id); item = nghttp2_outbound_queue_top(&session->ob_syn); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_HEADERS == item->frame.hd.type); - CU_ASSERT(0 == item->aux_data.headers.canceled); + assert_not_null(item); + assert_uint8(NGHTTP2_HEADERS, ==, item->frame.hd.type); + assert_false(item->aux_data.headers.canceled); rv = nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, stream_id, NGHTTP2_NO_ERROR); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); item = nghttp2_outbound_queue_top(&session->ob_syn); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_HEADERS == item->frame.hd.type); - CU_ASSERT(1 == item->aux_data.headers.canceled); + assert_not_null(item); + assert_uint8(NGHTTP2_HEADERS, ==, item->frame.hd.type); + assert_true(item->aux_data.headers.canceled); nghttp2_session_del(session); } @@ -7065,50 +7297,50 @@ void test_nghttp2_session_open_stream(void) { stream = nghttp2_session_open_stream(session, 1, NGHTTP2_STREAM_FLAG_NONE, &pri_spec, NGHTTP2_STREAM_OPENED, NULL); - CU_ASSERT(1 == session->num_incoming_streams); - CU_ASSERT(0 == session->num_outgoing_streams); - CU_ASSERT(NGHTTP2_STREAM_OPENED == stream->state); - CU_ASSERT(245 == stream->weight); - CU_ASSERT(&session->root == stream->dep_prev); - CU_ASSERT(NGHTTP2_SHUT_NONE == stream->shut_flags); + assert_size(1, ==, session->num_incoming_streams); + assert_size(0, ==, session->num_outgoing_streams); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENED, ==, stream->state); + assert_int32(245, ==, stream->weight); + assert_ptr_equal(&session->root, stream->dep_prev); + assert_uint8(NGHTTP2_SHUT_NONE, ==, stream->shut_flags); stream = nghttp2_session_open_stream(session, 2, NGHTTP2_STREAM_FLAG_NONE, &pri_spec_default, NGHTTP2_STREAM_OPENING, NULL); - CU_ASSERT(1 == session->num_incoming_streams); - CU_ASSERT(1 == session->num_outgoing_streams); - CU_ASSERT(&session->root == stream->dep_prev); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == stream->weight); - CU_ASSERT(NGHTTP2_SHUT_NONE == stream->shut_flags); + assert_size(1, ==, session->num_incoming_streams); + assert_size(1, ==, session->num_outgoing_streams); + assert_ptr_equal(&session->root, stream->dep_prev); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, stream->weight); + assert_uint8(NGHTTP2_SHUT_NONE, ==, stream->shut_flags); stream = nghttp2_session_open_stream(session, 4, NGHTTP2_STREAM_FLAG_NONE, &pri_spec_default, NGHTTP2_STREAM_RESERVED, NULL); - CU_ASSERT(1 == session->num_incoming_streams); - CU_ASSERT(1 == session->num_outgoing_streams); - CU_ASSERT(&session->root == stream->dep_prev); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == stream->weight); - CU_ASSERT(NGHTTP2_SHUT_RD == stream->shut_flags); + assert_size(1, ==, session->num_incoming_streams); + assert_size(1, ==, session->num_outgoing_streams); + assert_ptr_equal(&session->root, stream->dep_prev); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, stream->weight); + assert_uint8(NGHTTP2_SHUT_RD, ==, stream->shut_flags); nghttp2_priority_spec_init(&pri_spec, 1, 17, 1); stream = nghttp2_session_open_stream(session, 3, NGHTTP2_STREAM_FLAG_NONE, &pri_spec, NGHTTP2_STREAM_OPENED, NULL); - CU_ASSERT(17 == stream->weight); - CU_ASSERT(1 == stream->dep_prev->stream_id); + assert_int32(17, ==, stream->weight); + assert_int32(1, ==, stream->dep_prev->stream_id); /* Dependency to idle stream */ nghttp2_priority_spec_init(&pri_spec, 1000000007, 240, 1); stream = nghttp2_session_open_stream(session, 5, NGHTTP2_STREAM_FLAG_NONE, &pri_spec, NGHTTP2_STREAM_OPENED, NULL); - CU_ASSERT(240 == stream->weight); - CU_ASSERT(1000000007 == stream->dep_prev->stream_id); + assert_int32(240, ==, stream->weight); + assert_int32(1000000007, ==, stream->dep_prev->stream_id); stream = nghttp2_session_get_stream_raw(session, 1000000007); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == stream->weight); - CU_ASSERT(&session->root == stream->dep_prev); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, stream->weight); + assert_ptr_equal(&session->root, stream->dep_prev); /* Dependency to closed stream which is not in dependency tree */ session->last_recv_stream_id = 7; @@ -7118,8 +7350,8 @@ void test_nghttp2_session_open_stream(void) { stream = nghttp2_session_open_stream(session, 9, NGHTTP2_FLAG_NONE, &pri_spec, NGHTTP2_STREAM_OPENED, NULL); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == stream->weight); - CU_ASSERT(&session->root == stream->dep_prev); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, stream->weight); + assert_ptr_equal(&session->root, stream->dep_prev); nghttp2_session_del(session); @@ -7127,11 +7359,11 @@ void test_nghttp2_session_open_stream(void) { stream = nghttp2_session_open_stream(session, 4, NGHTTP2_STREAM_FLAG_NONE, &pri_spec_default, NGHTTP2_STREAM_RESERVED, NULL); - CU_ASSERT(0 == session->num_incoming_streams); - CU_ASSERT(0 == session->num_outgoing_streams); - CU_ASSERT(&session->root == stream->dep_prev); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == stream->weight); - CU_ASSERT(NGHTTP2_SHUT_WR == stream->shut_flags); + assert_size(0, ==, session->num_incoming_streams); + assert_size(0, ==, session->num_outgoing_streams); + assert_ptr_equal(&session->root, stream->dep_prev); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, stream->weight); + assert_uint8(NGHTTP2_SHUT_WR, ==, stream->shut_flags); nghttp2_session_del(session); } @@ -7151,13 +7383,13 @@ void test_nghttp2_session_open_stream_with_idle_stream_dep(void) { stream = nghttp2_session_open_stream(session, 1, NGHTTP2_STREAM_FLAG_NONE, &pri_spec, NGHTTP2_STREAM_OPENED, NULL); - CU_ASSERT(245 == stream->weight); - CU_ASSERT(101 == stream->dep_prev->stream_id); + assert_int32(245, ==, stream->weight); + assert_int32(101, ==, stream->dep_prev->stream_id); stream = nghttp2_session_get_stream_raw(session, 101); - CU_ASSERT(NGHTTP2_STREAM_IDLE == stream->state); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == stream->weight); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_IDLE, ==, stream->state); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, stream->weight); nghttp2_priority_spec_init(&pri_spec, 211, 1, 0); @@ -7165,13 +7397,13 @@ void test_nghttp2_session_open_stream_with_idle_stream_dep(void) { stream = nghttp2_session_open_stream(session, 101, NGHTTP2_STREAM_FLAG_NONE, &pri_spec, NGHTTP2_STREAM_OPENED, NULL); - CU_ASSERT(1 == stream->weight); - CU_ASSERT(211 == stream->dep_prev->stream_id); + assert_int32(1, ==, stream->weight); + assert_int32(211, ==, stream->dep_prev->stream_id); stream = nghttp2_session_get_stream_raw(session, 211); - CU_ASSERT(NGHTTP2_STREAM_IDLE == stream->state); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == stream->weight); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_IDLE, ==, stream->state); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, stream->weight); nghttp2_session_del(session); } @@ -7182,22 +7414,23 @@ void test_nghttp2_session_get_next_ob_item(void) { nghttp2_priority_spec pri_spec; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, NULL); session->remote_settings.max_concurrent_streams = 2; - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_null(nghttp2_session_get_next_ob_item(session)); nghttp2_submit_ping(session, NGHTTP2_FLAG_NONE, NULL); - CU_ASSERT(NGHTTP2_PING == - nghttp2_session_get_next_ob_item(session)->frame.hd.type); + assert_uint8(NGHTTP2_PING, ==, + nghttp2_session_get_next_ob_item(session)->frame.hd.type); - CU_ASSERT(1 == nghttp2_submit_request(session, NULL, NULL, 0, NULL, NULL)); - CU_ASSERT(NGHTTP2_PING == - nghttp2_session_get_next_ob_item(session)->frame.hd.type); + assert_int32(1, ==, + nghttp2_submit_request2(session, NULL, NULL, 0, NULL, NULL)); + assert_uint8(NGHTTP2_PING, ==, + nghttp2_session_get_next_ob_item(session)->frame.hd.type); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_null(nghttp2_session_get_next_ob_item(session)); /* Incoming stream does not affect the number of outgoing max concurrent streams. */ @@ -7205,20 +7438,20 @@ void test_nghttp2_session_get_next_ob_item(void) { nghttp2_priority_spec_init(&pri_spec, 0, NGHTTP2_MAX_WEIGHT, 0); - CU_ASSERT(3 == - nghttp2_submit_request(session, &pri_spec, NULL, 0, NULL, NULL)); - CU_ASSERT(NGHTTP2_HEADERS == - nghttp2_session_get_next_ob_item(session)->frame.hd.type); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(3, ==, + nghttp2_submit_request2(session, &pri_spec, NULL, 0, NULL, NULL)); + assert_uint8(NGHTTP2_HEADERS, ==, + nghttp2_session_get_next_ob_item(session)->frame.hd.type); + assert_int(0, ==, nghttp2_session_send(session)); - CU_ASSERT(5 == - nghttp2_submit_request(session, &pri_spec, NULL, 0, NULL, NULL)); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_int(5, ==, + nghttp2_submit_request2(session, &pri_spec, NULL, 0, NULL, NULL)); + assert_null(nghttp2_session_get_next_ob_item(session)); session->remote_settings.max_concurrent_streams = 3; - CU_ASSERT(NGHTTP2_HEADERS == - nghttp2_session_get_next_ob_item(session)->frame.hd.type); + assert_uint8(NGHTTP2_HEADERS, ==, + nghttp2_session_get_next_ob_item(session)->frame.hd.type); nghttp2_session_del(session); @@ -7226,10 +7459,11 @@ void test_nghttp2_session_get_next_ob_item(void) { nghttp2_session_server_new(&session, &callbacks, NULL); session->remote_settings.max_concurrent_streams = 0; open_sent_stream2(session, 2, NGHTTP2_STREAM_RESERVED); - CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 2, - NULL, NULL, 0, NULL)); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); - CU_ASSERT(1 == nghttp2_outbound_queue_size(&session->ob_syn)); + assert_int32(0, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 2, NULL, + NULL, 0, NULL)); + assert_null(nghttp2_session_get_next_ob_item(session)); + assert_size(1, ==, nghttp2_outbound_queue_size(&session->ob_syn)); nghttp2_session_del(session); } @@ -7242,30 +7476,30 @@ void test_nghttp2_session_pop_next_ob_item(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, NULL); session->remote_settings.max_concurrent_streams = 1; - CU_ASSERT(NULL == nghttp2_session_pop_next_ob_item(session)); + assert_null(nghttp2_session_pop_next_ob_item(session)); nghttp2_submit_ping(session, NGHTTP2_FLAG_NONE, NULL); nghttp2_priority_spec_init(&pri_spec, 0, 254, 0); - nghttp2_submit_request(session, &pri_spec, NULL, 0, NULL, NULL); + nghttp2_submit_request2(session, &pri_spec, NULL, 0, NULL, NULL); item = nghttp2_session_pop_next_ob_item(session); - CU_ASSERT(NGHTTP2_PING == item->frame.hd.type); + assert_uint8(NGHTTP2_PING, ==, item->frame.hd.type); nghttp2_outbound_item_free(item, mem); mem->free(item, NULL); item = nghttp2_session_pop_next_ob_item(session); - CU_ASSERT(NGHTTP2_HEADERS == item->frame.hd.type); + assert_uint8(NGHTTP2_HEADERS, ==, item->frame.hd.type); nghttp2_outbound_item_free(item, mem); mem->free(item, NULL); - CU_ASSERT(NULL == nghttp2_session_pop_next_ob_item(session)); + assert_null(nghttp2_session_pop_next_ob_item(session)); /* Incoming stream does not affect the number of outgoing max concurrent streams. */ @@ -7275,14 +7509,14 @@ void test_nghttp2_session_pop_next_ob_item(void) { nghttp2_priority_spec_init(&pri_spec, 0, NGHTTP2_MAX_WEIGHT, 0); - nghttp2_submit_request(session, &pri_spec, NULL, 0, NULL, NULL); + nghttp2_submit_request2(session, &pri_spec, NULL, 0, NULL, NULL); - CU_ASSERT(NULL == nghttp2_session_pop_next_ob_item(session)); + assert_null(nghttp2_session_pop_next_ob_item(session)); session->remote_settings.max_concurrent_streams = 2; item = nghttp2_session_pop_next_ob_item(session); - CU_ASSERT(NGHTTP2_HEADERS == item->frame.hd.type); + assert_uint8(NGHTTP2_HEADERS, ==, item->frame.hd.type); nghttp2_outbound_item_free(item, mem); mem->free(item, NULL); @@ -7292,28 +7526,29 @@ void test_nghttp2_session_pop_next_ob_item(void) { nghttp2_session_server_new(&session, &callbacks, NULL); session->remote_settings.max_concurrent_streams = 0; open_sent_stream2(session, 2, NGHTTP2_STREAM_RESERVED); - CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 2, - NULL, NULL, 0, NULL)); - CU_ASSERT(NULL == nghttp2_session_pop_next_ob_item(session)); - CU_ASSERT(1 == nghttp2_outbound_queue_size(&session->ob_syn)); + assert_int32(0, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 2, NULL, + NULL, 0, NULL)); + assert_null(nghttp2_session_pop_next_ob_item(session)); + assert_size(1, ==, nghttp2_outbound_queue_size(&session->ob_syn)); nghttp2_session_del(session); } void test_nghttp2_session_reply_fail(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; my_user_data ud; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = fail_send_callback; + callbacks.send_callback2 = fail_send_callback; data_prd.read_callback = fixed_length_data_source_read_callback; ud.data_source_length = 4 * 1024; - CU_ASSERT(0 == nghttp2_session_server_new(&session, &callbacks, &ud)); + assert_int(0, ==, nghttp2_session_server_new(&session, &callbacks, &ud)); open_recv_stream2(session, 1, NGHTTP2_STREAM_OPENING); - CU_ASSERT(0 == nghttp2_submit_response(session, 1, NULL, 0, &data_prd)); - CU_ASSERT(NGHTTP2_ERR_CALLBACK_FAILURE == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_submit_response2(session, 1, NULL, 0, &data_prd)); + assert_int(NGHTTP2_ERR_CALLBACK_FAILURE, ==, nghttp2_session_send(session)); nghttp2_session_del(session); } @@ -7326,7 +7561,7 @@ void test_nghttp2_session_max_concurrent_streams(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_server_new(&session, &callbacks, NULL); open_recv_stream(session, 1); @@ -7336,25 +7571,25 @@ void test_nghttp2_session_max_concurrent_streams(void) { NGHTTP2_HCAT_HEADERS, NULL, NULL, 0); session->pending_local_max_concurrent_stream = 1; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_request_headers_received(session, &frame)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_request_headers_received(session, &frame)); item = nghttp2_outbound_queue_top(&session->ob_reg); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(NGHTTP2_REFUSED_STREAM == item->frame.rst_stream.error_code); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_REFUSED_STREAM, ==, item->frame.rst_stream.error_code); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); /* Check ACKed SETTINGS_MAX_CONCURRENT_STREAMS */ session->local_settings.max_concurrent_streams = 1; frame.hd.stream_id = 5; - CU_ASSERT(NGHTTP2_ERR_IGN_HEADER_BLOCK == - nghttp2_session_on_request_headers_received(session, &frame)); + assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, + nghttp2_session_on_request_headers_received(session, &frame)); item = nghttp2_outbound_queue_top(&session->ob_reg); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); - CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == item->frame.goaway.error_code); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); + assert_uint32(NGHTTP2_PROTOCOL_ERROR, ==, item->frame.goaway.error_code); nghttp2_frame_headers_free(&frame.headers, mem); nghttp2_session_del(session); @@ -7364,12 +7599,12 @@ void test_nghttp2_session_stop_data_with_rst_stream(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; my_user_data ud; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; nghttp2_frame frame; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); callbacks.on_frame_send_callback = on_frame_send_callback; - callbacks.send_callback = block_count_send_callback; + callbacks.send_callback2 = block_count_send_callback; data_prd.read_callback = fixed_length_data_source_read_callback; ud.frame_send_cb_called = 0; @@ -7377,28 +7612,28 @@ void test_nghttp2_session_stop_data_with_rst_stream(void) { nghttp2_session_server_new(&session, &callbacks, &ud); open_recv_stream2(session, 1, NGHTTP2_STREAM_OPENING); - nghttp2_submit_response(session, 1, NULL, 0, &data_prd); + nghttp2_submit_response2(session, 1, NULL, 0, &data_prd); ud.block_count = 2; /* Sends response HEADERS + DATA[0] */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(NGHTTP2_DATA == ud.sent_frame_type); + assert_int(0, ==, nghttp2_session_send(session)); + assert_uint8(NGHTTP2_DATA, ==, ud.sent_frame_type); /* data for DATA[1] is read from data_prd but it is not sent */ - CU_ASSERT(ud.data_source_length == NGHTTP2_DATA_PAYLOADLEN * 2); + assert_size(ud.data_source_length, ==, NGHTTP2_DATA_PAYLOADLEN * 2); nghttp2_frame_rst_stream_init(&frame.rst_stream, 1, NGHTTP2_CANCEL); - CU_ASSERT(0 == nghttp2_session_on_rst_stream_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_rst_stream_received(session, &frame)); nghttp2_frame_rst_stream_free(&frame.rst_stream); /* Big enough number to send all DATA frames potentially. */ ud.block_count = 100; /* Nothing will be sent in the following call. */ - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); /* With RST_STREAM, stream is canceled and further DATA on that stream are not sent. */ - CU_ASSERT(ud.data_source_length == NGHTTP2_DATA_PAYLOADLEN * 2); + assert_size(ud.data_source_length, ==, NGHTTP2_DATA_PAYLOADLEN * 2); - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 1)); + assert_null(nghttp2_session_get_stream(session, 1)); nghttp2_session_del(session); } @@ -7407,13 +7642,13 @@ void test_nghttp2_session_defer_data(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; my_user_data ud; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; nghttp2_outbound_item *item; nghttp2_stream *stream; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); callbacks.on_frame_send_callback = on_frame_send_callback; - callbacks.send_callback = block_count_send_callback; + callbacks.send_callback2 = block_count_send_callback; data_prd.read_callback = defer_data_source_read_callback; ud.frame_send_cb_called = 0; @@ -7425,47 +7660,48 @@ void test_nghttp2_session_defer_data(void) { session->remote_window_size = 1 << 20; stream->remote_window_size = 1 << 20; - nghttp2_submit_response(session, 1, NULL, 0, &data_prd); + nghttp2_submit_response2(session, 1, NULL, 0, &data_prd); ud.block_count = 1; /* Sends HEADERS reply */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(NGHTTP2_HEADERS == ud.sent_frame_type); + assert_int(0, ==, nghttp2_session_send(session)); + assert_uint8(NGHTTP2_HEADERS, ==, ud.sent_frame_type); /* No data is read */ - CU_ASSERT(ud.data_source_length == NGHTTP2_DATA_PAYLOADLEN * 4); + assert_size(ud.data_source_length, ==, NGHTTP2_DATA_PAYLOADLEN * 4); ud.block_count = 1; nghttp2_submit_ping(session, NGHTTP2_FLAG_NONE, NULL); /* Sends PING */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(NGHTTP2_PING == ud.sent_frame_type); + assert_int(0, ==, nghttp2_session_send(session)); + assert_uint8(NGHTTP2_PING, ==, ud.sent_frame_type); /* Resume deferred DATA */ - CU_ASSERT(0 == nghttp2_session_resume_data(session, 1)); + assert_int(0, ==, nghttp2_session_resume_data(session, 1)); item = stream->item; - item->aux_data.data.data_prd.read_callback = + item->aux_data.data.dpw.data_prd.v1.read_callback = fixed_length_data_source_read_callback; ud.block_count = 1; /* Reads 2 DATA chunks */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(ud.data_source_length == NGHTTP2_DATA_PAYLOADLEN * 2); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(ud.data_source_length, ==, NGHTTP2_DATA_PAYLOADLEN * 2); /* Deferred again */ - item->aux_data.data.data_prd.read_callback = defer_data_source_read_callback; + item->aux_data.data.dpw.data_prd.v1.read_callback = + defer_data_source_read_callback; /* This is needed since 16KiB block is already read and waiting to be sent. No read_callback invocation. */ ud.block_count = 1; - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(ud.data_source_length == NGHTTP2_DATA_PAYLOADLEN * 2); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(ud.data_source_length, ==, NGHTTP2_DATA_PAYLOADLEN * 2); /* Resume deferred DATA */ - CU_ASSERT(0 == nghttp2_session_resume_data(session, 1)); - item->aux_data.data.data_prd.read_callback = + assert_int(0, ==, nghttp2_session_resume_data(session, 1)); + item->aux_data.data.dpw.data_prd.v1.read_callback = fixed_length_data_source_read_callback; ud.block_count = 1; /* Reads 2 16KiB blocks */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(ud.data_source_length == 0); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(ud.data_source_length, ==, 0); nghttp2_session_del(session); } @@ -7474,7 +7710,7 @@ void test_nghttp2_session_flow_control(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; my_user_data ud; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; nghttp2_frame frame; nghttp2_stream *stream; int32_t new_initial_window_size; @@ -7484,7 +7720,7 @@ void test_nghttp2_session_flow_control(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = fixed_bytes_send_callback; + callbacks.send_callback2 = fixed_bytes_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; data_prd.read_callback = fixed_length_data_source_read_callback; @@ -7500,11 +7736,11 @@ void test_nghttp2_session_flow_control(void) { session->remote_window_size = 64 * 1024; session->remote_settings.initial_window_size = 64 * 1024; - nghttp2_submit_request(session, NULL, NULL, 0, &data_prd, NULL); + nghttp2_submit_request2(session, NULL, NULL, 0, &data_prd, NULL); /* Sends 64KiB - 1 data */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(64 * 1024 == ud.data_source_length); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(64 * 1024, ==, ud.data_source_length); /* Back 32KiB in stream window */ nghttp2_frame_window_update_init(&frame.window_update, NGHTTP2_FLAG_NONE, 1, @@ -7512,16 +7748,16 @@ void test_nghttp2_session_flow_control(void) { nghttp2_session_on_window_update_received(session, &frame); /* Send nothing because of connection-level window */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(64 * 1024 == ud.data_source_length); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(64 * 1024, ==, ud.data_source_length); /* Back 32KiB in connection-level window */ frame.hd.stream_id = 0; nghttp2_session_on_window_update_received(session, &frame); /* Sends another 32KiB data */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(32 * 1024 == ud.data_source_length); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(32 * 1024, ==, ud.data_source_length); stream = nghttp2_session_get_stream(session, 1); /* Change initial window size to 16KiB. The window_size becomes @@ -7533,7 +7769,7 @@ void test_nghttp2_session_flow_control(void) { stream->remote_window_size); session->remote_settings.initial_window_size = (uint32_t)new_initial_window_size; - CU_ASSERT(-48 * 1024 == stream->remote_window_size); + assert_int32(-48 * 1024, ==, stream->remote_window_size); /* Back 48KiB to stream window */ frame.hd.stream_id = 1; @@ -7541,8 +7777,8 @@ void test_nghttp2_session_flow_control(void) { nghttp2_session_on_window_update_received(session, &frame); /* Nothing is sent because window_size is 0 */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(32 * 1024 == ud.data_source_length); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(32 * 1024, ==, ud.data_source_length); /* Back 16KiB in stream window */ frame.hd.stream_id = 1; @@ -7555,8 +7791,8 @@ void test_nghttp2_session_flow_control(void) { nghttp2_session_on_window_update_received(session, &frame); /* Sends another 16KiB data */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(16 * 1024 == ud.data_source_length); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(16 * 1024, ==, ud.data_source_length); /* Increase initial window size to 32KiB */ iv[0].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE; @@ -7568,8 +7804,8 @@ void test_nghttp2_session_flow_control(void) { nghttp2_frame_settings_free(&settings_frame.settings, mem); /* Sends another 8KiB data */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(8 * 1024 == ud.data_source_length); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(8 * 1024, ==, ud.data_source_length); /* Back 8KiB in connection-level window */ frame.hd.stream_id = 0; @@ -7577,10 +7813,10 @@ void test_nghttp2_session_flow_control(void) { nghttp2_session_on_window_update_received(session, &frame); /* Sends last 8KiB data */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == ud.data_source_length); - CU_ASSERT(nghttp2_session_get_stream(session, 1)->shut_flags & - NGHTTP2_SHUT_WR); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(0, ==, ud.data_source_length); + assert_true(nghttp2_session_get_stream(session, 1)->shut_flags & + NGHTTP2_SHUT_WR); nghttp2_frame_window_update_free(&frame.window_update); nghttp2_session_del(session); @@ -7595,7 +7831,7 @@ void test_nghttp2_session_flow_control_data_recv(void) { nghttp2_stream *stream; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; /* Initial window size to 64KiB - 1*/ nghttp2_session_client_new(&session, &callbacks, NULL); @@ -7613,34 +7849,36 @@ void test_nghttp2_session_flow_control_data_recv(void) { NGHTTP2_FLAG_END_STREAM, 1); nghttp2_frame_pack_frame_hd(data, &hd); - CU_ASSERT(NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN == - nghttp2_session_mem_recv( - session, data, NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN)); + assert_ptrdiff( + NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN, ==, + nghttp2_session_mem_recv2(session, data, + NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN)); item = nghttp2_session_get_next_ob_item(session); /* Since this is the last frame, stream-level WINDOW_UPDATE is not issued, but connection-level is. */ - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); - CU_ASSERT(0 == item->frame.hd.stream_id); - CU_ASSERT(NGHTTP2_MAX_PAYLOADLEN == - item->frame.window_update.window_size_increment); + assert_uint8(NGHTTP2_WINDOW_UPDATE, ==, item->frame.hd.type); + assert_int32(0, ==, item->frame.hd.stream_id); + assert_int32(NGHTTP2_MAX_PAYLOADLEN, ==, + item->frame.window_update.window_size_increment); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); /* Receive DATA for closed stream. They are still subject to under connection-level flow control, since this situation arises when RST_STREAM is issued by the remote, but the local side keeps sending DATA frames. Without calculating connection-level window, the subsequent flow control gets confused. */ - CU_ASSERT(NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN == - nghttp2_session_mem_recv( - session, data, NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN)); + assert_ptrdiff( + NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN, ==, + nghttp2_session_mem_recv2(session, data, + NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); - CU_ASSERT(0 == item->frame.hd.stream_id); - CU_ASSERT(NGHTTP2_MAX_PAYLOADLEN == - item->frame.window_update.window_size_increment); + assert_uint8(NGHTTP2_WINDOW_UPDATE, ==, item->frame.hd.type); + assert_int32(0, ==, item->frame.hd.stream_id); + assert_int32(NGHTTP2_MAX_PAYLOADLEN, ==, + item->frame.window_update.window_size_increment); nghttp2_session_del(session); } @@ -7654,7 +7892,7 @@ void test_nghttp2_session_flow_control_data_with_padding_recv(void) { nghttp2_option *option; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_option_new(&option); /* Disable auto window update so that we can check padding is @@ -7676,66 +7914,69 @@ void test_nghttp2_session_flow_control_data_with_padding_recv(void) { /* Set Pad Length field, which itself is padding */ data[NGHTTP2_FRAME_HDLEN] = 255; - CU_ASSERT( - (ssize_t)(NGHTTP2_FRAME_HDLEN + hd.length) == - nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + hd.length)); + assert_ptrdiff((nghttp2_ssize)(NGHTTP2_FRAME_HDLEN + hd.length), ==, + nghttp2_session_mem_recv2(session, data, + NGHTTP2_FRAME_HDLEN + hd.length)); - CU_ASSERT((int32_t)hd.length == session->recv_window_size); - CU_ASSERT((int32_t)hd.length == stream->recv_window_size); - CU_ASSERT(256 == session->consumed_size); - CU_ASSERT(256 == stream->consumed_size); - CU_ASSERT(357 == session->recv_window_size); - CU_ASSERT(357 == stream->recv_window_size); + assert_int32((int32_t)hd.length, ==, session->recv_window_size); + assert_int32((int32_t)hd.length, ==, stream->recv_window_size); + assert_int32(256, ==, session->consumed_size); + assert_int32(256, ==, stream->consumed_size); + assert_int32(357, ==, session->recv_window_size); + assert_int32(357, ==, stream->recv_window_size); /* Receive the same DATA frame, but in 2 parts: first 9 + 1 + 102 bytes which includes 1st padding byte, and remainder */ - CU_ASSERT((ssize_t)(NGHTTP2_FRAME_HDLEN + 103) == - nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + 103)); - CU_ASSERT(258 == session->consumed_size); - CU_ASSERT(258 == stream->consumed_size); - CU_ASSERT(460 == session->recv_window_size); - CU_ASSERT(460 == stream->recv_window_size); + assert_ptrdiff( + (nghttp2_ssize)(NGHTTP2_FRAME_HDLEN + 103), ==, + nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + 103)); + assert_int32(258, ==, session->consumed_size); + assert_int32(258, ==, stream->consumed_size); + assert_int32(460, ==, session->recv_window_size); + assert_int32(460, ==, stream->recv_window_size); /* 357 - 103 = 254 bytes left */ - CU_ASSERT(254 == nghttp2_session_mem_recv(session, data, 254)); - CU_ASSERT(512 == session->consumed_size); - CU_ASSERT(512 == stream->consumed_size); - CU_ASSERT(714 == session->recv_window_size); - CU_ASSERT(714 == stream->recv_window_size); + assert_ptrdiff(254, ==, nghttp2_session_mem_recv2(session, data, 254)); + assert_int32(512, ==, session->consumed_size); + assert_int32(512, ==, stream->consumed_size); + assert_int32(714, ==, session->recv_window_size); + assert_int32(714, ==, stream->recv_window_size); /* Receive the same DATA frame, but in 2 parts: first 9 = 1 + 101 bytes which only includes data without padding, 2nd part is padding only */ - CU_ASSERT((ssize_t)(NGHTTP2_FRAME_HDLEN + 102) == - nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + 102)); - CU_ASSERT(513 == session->consumed_size); - CU_ASSERT(513 == stream->consumed_size); - CU_ASSERT(816 == session->recv_window_size); - CU_ASSERT(816 == stream->recv_window_size); + assert_ptrdiff( + (nghttp2_ssize)(NGHTTP2_FRAME_HDLEN + 102), ==, + nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + 102)); + assert_int32(513, ==, session->consumed_size); + assert_int32(513, ==, stream->consumed_size); + assert_int32(816, ==, session->recv_window_size); + assert_int32(816, ==, stream->recv_window_size); /* 357 - 102 = 255 bytes left */ - CU_ASSERT(255 == nghttp2_session_mem_recv(session, data, 255)); - CU_ASSERT(768 == session->consumed_size); - CU_ASSERT(768 == stream->consumed_size); - CU_ASSERT(1071 == session->recv_window_size); - CU_ASSERT(1071 == stream->recv_window_size); + assert_ptrdiff(255, ==, nghttp2_session_mem_recv2(session, data, 255)); + assert_int32(768, ==, session->consumed_size); + assert_int32(768, ==, stream->consumed_size); + assert_int32(1071, ==, session->recv_window_size); + assert_int32(1071, ==, stream->recv_window_size); /* Receive the same DATA frame, but in 2 parts: first 9 = 1 + 50 bytes which includes byte up to middle of data, 2nd part is the remainder */ - CU_ASSERT((ssize_t)(NGHTTP2_FRAME_HDLEN + 51) == - nghttp2_session_mem_recv(session, data, NGHTTP2_FRAME_HDLEN + 51)); - CU_ASSERT(769 == session->consumed_size); - CU_ASSERT(769 == stream->consumed_size); - CU_ASSERT(1122 == session->recv_window_size); - CU_ASSERT(1122 == stream->recv_window_size); + assert_ptrdiff( + (nghttp2_ssize)(NGHTTP2_FRAME_HDLEN + 51), ==, + nghttp2_session_mem_recv2(session, data, NGHTTP2_FRAME_HDLEN + 51)); + assert_int32(769, ==, session->consumed_size); + assert_int32(769, ==, stream->consumed_size); + assert_int32(1122, ==, session->recv_window_size); + assert_int32(1122, ==, stream->recv_window_size); /* 357 - 51 = 306 bytes left */ - CU_ASSERT(306 == nghttp2_session_mem_recv(session, data, 306)); - CU_ASSERT(1024 == session->consumed_size); - CU_ASSERT(1024 == stream->consumed_size); - CU_ASSERT(1428 == session->recv_window_size); - CU_ASSERT(1428 == stream->recv_window_size); + assert_ptrdiff(306, ==, nghttp2_session_mem_recv2(session, data, 306)); + assert_int32(1024, ==, session->consumed_size); + assert_int32(1024, ==, stream->consumed_size); + assert_int32(1428, ==, session->recv_window_size); + assert_int32(1428, ==, stream->recv_window_size); nghttp2_session_del(session); } @@ -7744,13 +7985,13 @@ void test_nghttp2_session_data_read_temporal_failure(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; my_user_data ud; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; nghttp2_frame frame; nghttp2_stream *stream; size_t data_size = 128 * 1024; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; data_prd.read_callback = fixed_length_data_source_read_callback; @@ -7758,17 +7999,18 @@ void test_nghttp2_session_data_read_temporal_failure(void) { /* Initial window size is 64KiB - 1 */ nghttp2_session_client_new(&session, &callbacks, &ud); - nghttp2_submit_request(session, NULL, NULL, 0, &data_prd, NULL); + nghttp2_submit_request2(session, NULL, NULL, 0, &data_prd, NULL); /* Sends NGHTTP2_INITIAL_WINDOW_SIZE data, assuming, it is equal to or smaller than NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(data_size - NGHTTP2_INITIAL_WINDOW_SIZE == ud.data_source_length); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(data_size - NGHTTP2_INITIAL_WINDOW_SIZE, ==, + ud.data_source_length); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(NGHTTP2_DATA == stream->item->frame.hd.type); + assert_uint8(NGHTTP2_DATA, ==, stream->item->frame.hd.type); - stream->item->aux_data.data.data_prd.read_callback = + stream->item->aux_data.data.dpw.data_prd.v1.read_callback = temporal_failure_data_source_read_callback; /* Back NGHTTP2_INITIAL_WINDOW_SIZE to both connection-level and @@ -7782,16 +8024,17 @@ void test_nghttp2_session_data_read_temporal_failure(void) { /* Sending data will fail (soft fail) and treated as stream error */ ud.frame_send_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(data_size - NGHTTP2_INITIAL_WINDOW_SIZE == ud.data_source_length); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(data_size - NGHTTP2_INITIAL_WINDOW_SIZE, ==, + ud.data_source_length); - CU_ASSERT(1 == ud.frame_send_cb_called); - CU_ASSERT(NGHTTP2_RST_STREAM == ud.sent_frame_type); + assert_int(1, ==, ud.frame_send_cb_called); + assert_uint8(NGHTTP2_RST_STREAM, ==, ud.sent_frame_type); data_prd.read_callback = fail_data_source_read_callback; - nghttp2_submit_request(session, NULL, NULL, 0, &data_prd, NULL); + nghttp2_submit_request2(session, NULL, NULL, 0, &data_prd, NULL); /* Sending data will fail (hard fail) and session tear down */ - CU_ASSERT(NGHTTP2_ERR_CALLBACK_FAILURE == nghttp2_session_send(session)); + assert_int(NGHTTP2_ERR_CALLBACK_FAILURE, ==, nghttp2_session_send(session)); nghttp2_session_del(session); } @@ -7810,9 +8053,9 @@ void test_nghttp2_session_on_stream_close(void) { stream = open_sent_stream3(session, 1, NGHTTP2_STREAM_FLAG_NONE, &pri_spec_default, NGHTTP2_STREAM_OPENED, &user_data); - CU_ASSERT(stream != NULL); - CU_ASSERT(nghttp2_session_close_stream(session, 1, NGHTTP2_NO_ERROR) == 0); - CU_ASSERT(user_data.stream_close_cb_called == 1); + assert_not_null(stream); + assert_int(0, ==, nghttp2_session_close_stream(session, 1, NGHTTP2_NO_ERROR)); + assert_int(1, ==, user_data.stream_close_cb_called); nghttp2_session_del(session); } @@ -7824,7 +8067,7 @@ void test_nghttp2_session_on_ctrl_not_send(void) { memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); callbacks.on_frame_not_send_callback = on_frame_not_send_callback; - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; user_data.frame_not_send_cb_called = 0; user_data.not_sent_frame_type = 0; user_data.not_sent_error = 0; @@ -7836,57 +8079,64 @@ void test_nghttp2_session_on_ctrl_not_send(void) { /* Check response HEADERS */ /* Send bogus stream ID */ - CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 3, - NULL, NULL, 0, NULL)); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == user_data.frame_not_send_cb_called); - CU_ASSERT(NGHTTP2_HEADERS == user_data.not_sent_frame_type); - CU_ASSERT(NGHTTP2_ERR_STREAM_CLOSED == user_data.not_sent_error); + assert_int32(0, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 3, NULL, + NULL, 0, NULL)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(1, ==, user_data.frame_not_send_cb_called); + assert_uint8(NGHTTP2_HEADERS, ==, user_data.not_sent_frame_type); + assert_int(NGHTTP2_ERR_STREAM_CLOSED, ==, user_data.not_sent_error); user_data.frame_not_send_cb_called = 0; /* Shutdown transmission */ stream->shut_flags |= NGHTTP2_SHUT_WR; - CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 1, - NULL, NULL, 0, NULL)); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == user_data.frame_not_send_cb_called); - CU_ASSERT(NGHTTP2_HEADERS == user_data.not_sent_frame_type); - CU_ASSERT(NGHTTP2_ERR_STREAM_SHUT_WR == user_data.not_sent_error); + assert_int32(0, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 1, NULL, + NULL, 0, NULL)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(1, ==, user_data.frame_not_send_cb_called); + assert_uint8(NGHTTP2_HEADERS, ==, user_data.not_sent_frame_type); + assert_int(NGHTTP2_ERR_STREAM_SHUT_WR, ==, user_data.not_sent_error); stream->shut_flags = NGHTTP2_SHUT_NONE; user_data.frame_not_send_cb_called = 0; /* Queue RST_STREAM */ - CU_ASSERT(0 == nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 1, - NULL, NULL, 0, NULL)); - CU_ASSERT(0 == nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, 1, - NGHTTP2_INTERNAL_ERROR)); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == user_data.frame_not_send_cb_called); - CU_ASSERT(NGHTTP2_HEADERS == user_data.not_sent_frame_type); - CU_ASSERT(NGHTTP2_ERR_STREAM_CLOSING == user_data.not_sent_error); + assert_int32(0, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, 1, NULL, + NULL, 0, NULL)); + assert_int(0, ==, + nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, 1, + NGHTTP2_INTERNAL_ERROR)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(1, ==, user_data.frame_not_send_cb_called); + assert_uint8(NGHTTP2_HEADERS, ==, user_data.not_sent_frame_type); + assert_int(NGHTTP2_ERR_STREAM_CLOSING, ==, user_data.not_sent_error); nghttp2_session_del(session); /* Check request HEADERS */ user_data.frame_not_send_cb_called = 0; - CU_ASSERT(nghttp2_session_client_new(&session, &callbacks, &user_data) == 0); + assert_int(0, ==, + nghttp2_session_client_new(&session, &callbacks, &user_data)); /* Maximum Stream ID is reached */ session->next_stream_id = (1u << 31) + 1; - CU_ASSERT(NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE == - nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, -1, NULL, - NULL, 0, NULL)); + assert_int32(NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE, ==, + nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, -1, + NULL, NULL, 0, NULL)); user_data.frame_not_send_cb_called = 0; /* GOAWAY received */ session->goaway_flags |= NGHTTP2_GOAWAY_RECV; session->next_stream_id = 9; - CU_ASSERT(0 < nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, -1, - NULL, NULL, 0, NULL)); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == user_data.frame_not_send_cb_called); - CU_ASSERT(NGHTTP2_HEADERS == user_data.not_sent_frame_type); - CU_ASSERT(NGHTTP2_ERR_START_STREAM_NOT_ALLOWED == user_data.not_sent_error); + assert_int32(0, <, + nghttp2_submit_headers(session, NGHTTP2_FLAG_END_STREAM, -1, + NULL, NULL, 0, NULL)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(1, ==, user_data.frame_not_send_cb_called); + assert_uint8(NGHTTP2_HEADERS, ==, user_data.not_sent_frame_type); + assert_int(NGHTTP2_ERR_START_STREAM_NOT_ALLOWED, ==, + user_data.not_sent_error); nghttp2_session_del(session); } @@ -7896,15 +8146,16 @@ void test_nghttp2_session_get_outbound_queue_size(void) { nghttp2_session_callbacks callbacks; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, NULL)); - CU_ASSERT(0 == nghttp2_session_get_outbound_queue_size(session)); + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, NULL)); + assert_size(0, ==, nghttp2_session_get_outbound_queue_size(session)); - CU_ASSERT(0 == nghttp2_submit_ping(session, NGHTTP2_FLAG_NONE, NULL)); - CU_ASSERT(1 == nghttp2_session_get_outbound_queue_size(session)); + assert_int(0, ==, nghttp2_submit_ping(session, NGHTTP2_FLAG_NONE, NULL)); + assert_size(1, ==, nghttp2_session_get_outbound_queue_size(session)); - CU_ASSERT(0 == nghttp2_submit_goaway(session, NGHTTP2_FLAG_NONE, 2, - NGHTTP2_NO_ERROR, NULL, 0)); - CU_ASSERT(2 == nghttp2_session_get_outbound_queue_size(session)); + assert_int(0, ==, + nghttp2_submit_goaway(session, NGHTTP2_FLAG_NONE, 2, + NGHTTP2_NO_ERROR, NULL, 0)); + assert_size(2, ==, nghttp2_session_get_outbound_queue_size(session)); nghttp2_session_del(session); } @@ -7915,84 +8166,89 @@ void test_nghttp2_session_get_effective_local_window_size(void) { nghttp2_stream *stream; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, NULL)); + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, NULL)); stream = open_sent_stream(session, 1); - CU_ASSERT(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE == - nghttp2_session_get_effective_local_window_size(session)); - CU_ASSERT(0 == nghttp2_session_get_effective_recv_data_length(session)); + assert_int32(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE, ==, + nghttp2_session_get_effective_local_window_size(session)); + assert_int32(0, ==, nghttp2_session_get_effective_recv_data_length(session)); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE == - nghttp2_session_get_stream_effective_local_window_size(session, 1)); - CU_ASSERT(0 == - nghttp2_session_get_stream_effective_recv_data_length(session, 1)); + assert_int32( + NGHTTP2_INITIAL_WINDOW_SIZE, ==, + nghttp2_session_get_stream_effective_local_window_size(session, 1)); + assert_int32( + 0, ==, nghttp2_session_get_stream_effective_recv_data_length(session, 1)); /* Check connection flow control */ session->recv_window_size = 100; nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 0, 1100); - CU_ASSERT(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1000 == - nghttp2_session_get_effective_local_window_size(session)); - CU_ASSERT(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1000 == - nghttp2_session_get_local_window_size(session)); - CU_ASSERT(0 == nghttp2_session_get_effective_recv_data_length(session)); + assert_int32(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1000, ==, + nghttp2_session_get_effective_local_window_size(session)); + assert_int32(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1000, ==, + nghttp2_session_get_local_window_size(session)); + assert_int32(0, ==, nghttp2_session_get_effective_recv_data_length(session)); nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 0, -50); /* Now session->recv_window_size = -50 */ - CU_ASSERT(-50 == session->recv_window_size); - CU_ASSERT(50 == session->recv_reduction); - CU_ASSERT(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 950 == - nghttp2_session_get_effective_local_window_size(session)); - CU_ASSERT(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1000 == - nghttp2_session_get_local_window_size(session)); - CU_ASSERT(0 == nghttp2_session_get_effective_recv_data_length(session)); + assert_int32(-50, ==, session->recv_window_size); + assert_int32(50, ==, session->recv_reduction); + assert_int32(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 950, ==, + nghttp2_session_get_effective_local_window_size(session)); + assert_int32(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1000, ==, + nghttp2_session_get_local_window_size(session)); + assert_int32(0, ==, nghttp2_session_get_effective_recv_data_length(session)); session->recv_window_size += 50; /* Now session->recv_window_size = 0 */ - CU_ASSERT(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 950 == - nghttp2_session_get_local_window_size(session)); + assert_int32(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 950, ==, + nghttp2_session_get_local_window_size(session)); nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 0, 100); - CU_ASSERT(50 == session->recv_window_size); - CU_ASSERT(0 == session->recv_reduction); - CU_ASSERT(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1050 == - nghttp2_session_get_effective_local_window_size(session)); - CU_ASSERT(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1000 == - nghttp2_session_get_local_window_size(session)); - CU_ASSERT(50 == nghttp2_session_get_effective_recv_data_length(session)); + assert_int32(50, ==, session->recv_window_size); + assert_int32(0, ==, session->recv_reduction); + assert_int32(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1050, ==, + nghttp2_session_get_effective_local_window_size(session)); + assert_int32(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1000, ==, + nghttp2_session_get_local_window_size(session)); + assert_int32(50, ==, nghttp2_session_get_effective_recv_data_length(session)); /* Check stream flow control */ stream->recv_window_size = 100; nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 1, 1100); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE + 1000 == - nghttp2_session_get_stream_effective_local_window_size(session, 1)); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE + 1000 == - nghttp2_session_get_stream_local_window_size(session, 1)); - CU_ASSERT(0 == - nghttp2_session_get_stream_effective_recv_data_length(session, 1)); + assert_int32( + NGHTTP2_INITIAL_WINDOW_SIZE + 1000, ==, + nghttp2_session_get_stream_effective_local_window_size(session, 1)); + assert_int32(NGHTTP2_INITIAL_WINDOW_SIZE + 1000, ==, + nghttp2_session_get_stream_local_window_size(session, 1)); + assert_int32( + 0, ==, nghttp2_session_get_stream_effective_recv_data_length(session, 1)); nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 1, -50); /* Now stream->recv_window_size = -50 */ - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE + 950 == - nghttp2_session_get_stream_effective_local_window_size(session, 1)); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE + 1000 == - nghttp2_session_get_stream_local_window_size(session, 1)); - CU_ASSERT(0 == - nghttp2_session_get_stream_effective_recv_data_length(session, 1)); + assert_int32( + NGHTTP2_INITIAL_WINDOW_SIZE + 950, ==, + nghttp2_session_get_stream_effective_local_window_size(session, 1)); + assert_int32(NGHTTP2_INITIAL_WINDOW_SIZE + 1000, ==, + nghttp2_session_get_stream_local_window_size(session, 1)); + assert_int32( + 0, ==, nghttp2_session_get_stream_effective_recv_data_length(session, 1)); stream->recv_window_size += 50; /* Now stream->recv_window_size = 0 */ nghttp2_submit_window_update(session, NGHTTP2_FLAG_NONE, 1, 100); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE + 1050 == - nghttp2_session_get_stream_effective_local_window_size(session, 1)); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE + 1000 == - nghttp2_session_get_stream_local_window_size(session, 1)); - CU_ASSERT(50 == - nghttp2_session_get_stream_effective_recv_data_length(session, 1)); + assert_int32( + NGHTTP2_INITIAL_WINDOW_SIZE + 1050, ==, + nghttp2_session_get_stream_effective_local_window_size(session, 1)); + assert_int32(NGHTTP2_INITIAL_WINDOW_SIZE + 1000, ==, + nghttp2_session_get_stream_local_window_size(session, 1)); + assert_int32( + 50, ==, + nghttp2_session_get_stream_effective_recv_data_length(session, 1)); nghttp2_session_del(session); } @@ -8005,7 +8261,7 @@ void test_nghttp2_session_set_option(void) { int rv; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; /* Test for nghttp2_option_set_no_auto_window_update */ nghttp2_option_new(&option); @@ -8013,7 +8269,7 @@ void test_nghttp2_session_set_option(void) { nghttp2_session_client_new2(&session, &callbacks, NULL, option); - CU_ASSERT(session->opt_flags & NGHTTP2_OPTMASK_NO_AUTO_WINDOW_UPDATE); + assert_true(session->opt_flags & NGHTTP2_OPTMASK_NO_AUTO_WINDOW_UPDATE); nghttp2_session_del(session); nghttp2_option_del(option); @@ -8024,7 +8280,7 @@ void test_nghttp2_session_set_option(void) { nghttp2_session_client_new2(&session, &callbacks, NULL, option); - CU_ASSERT(100 == session->remote_settings.max_concurrent_streams); + assert_uint32(100, ==, session->remote_settings.max_concurrent_streams); nghttp2_session_del(session); nghttp2_option_del(option); @@ -8034,7 +8290,7 @@ void test_nghttp2_session_set_option(void) { nghttp2_session_client_new2(&session, &callbacks, NULL, option); - CU_ASSERT(99 == session->max_incoming_reserved_streams); + assert_size(99, ==, session->max_incoming_reserved_streams); nghttp2_session_del(session); nghttp2_option_del(option); @@ -8044,7 +8300,7 @@ void test_nghttp2_session_set_option(void) { nghttp2_session_client_new2(&session, &callbacks, NULL, option); - CU_ASSERT(session->opt_flags & NGHTTP2_OPTMASK_NO_AUTO_PING_ACK); + assert_true(session->opt_flags & NGHTTP2_OPTMASK_NO_AUTO_PING_ACK); nghttp2_session_del(session); nghttp2_option_del(option); @@ -8057,15 +8313,15 @@ void test_nghttp2_session_set_option(void) { deflater = &session->hd_deflater; - rv = nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); + rv = nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); - CU_ASSERT(1 == rv); + assert_int(1, ==, rv); rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); - CU_ASSERT(0 == deflater->deflate_hd_table_bufsize_max); - CU_ASSERT(0 == deflater->ctx.hd_table_bufsize); + assert_int(0, ==, rv); + assert_size(0, ==, deflater->deflate_hd_table_bufsize_max); + assert_size(0, ==, deflater->ctx.hd_table_bufsize); nghttp2_session_del(session); nghttp2_option_del(option); @@ -8075,11 +8331,11 @@ void test_nghttp2_session_data_backoff_by_high_pri_frame(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; my_user_data ud; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; nghttp2_stream *stream; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = block_count_send_callback; + callbacks.send_callback2 = block_count_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; data_prd.read_callback = fixed_length_data_source_read_callback; @@ -8087,34 +8343,34 @@ void test_nghttp2_session_data_backoff_by_high_pri_frame(void) { ud.data_source_length = NGHTTP2_DATA_PAYLOADLEN * 4; nghttp2_session_client_new(&session, &callbacks, &ud); - nghttp2_submit_request(session, NULL, NULL, 0, &data_prd, NULL); + nghttp2_submit_request2(session, NULL, NULL, 0, &data_prd, NULL); session->remote_window_size = 1 << 20; ud.block_count = 2; /* Sends request HEADERS + DATA[0] */ - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); stream = nghttp2_session_get_stream(session, 1); stream->remote_window_size = 1 << 20; - CU_ASSERT(NGHTTP2_DATA == ud.sent_frame_type); + assert_uint8(NGHTTP2_DATA, ==, ud.sent_frame_type); /* data for DATA[1] is read from data_prd but it is not sent */ - CU_ASSERT(ud.data_source_length == NGHTTP2_DATA_PAYLOADLEN * 2); + assert_size(ud.data_source_length, ==, NGHTTP2_DATA_PAYLOADLEN * 2); nghttp2_submit_ping(session, NGHTTP2_FLAG_NONE, NULL); ud.block_count = 2; /* Sends DATA[1] + PING, PING is interleaved in DATA sequence */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(NGHTTP2_PING == ud.sent_frame_type); + assert_int(0, ==, nghttp2_session_send(session)); + assert_uint8(NGHTTP2_PING, ==, ud.sent_frame_type); /* data for DATA[2] is read from data_prd but it is not sent */ - CU_ASSERT(ud.data_source_length == NGHTTP2_DATA_PAYLOADLEN); + assert_size(ud.data_source_length, ==, NGHTTP2_DATA_PAYLOADLEN); ud.block_count = 2; /* Sends DATA[2..3] */ - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); - CU_ASSERT(stream->shut_flags & NGHTTP2_SHUT_WR); + assert_true(stream->shut_flags & NGHTTP2_SHUT_WR); nghttp2_session_del(session); } @@ -8140,10 +8396,11 @@ static void check_session_recv_data_with_padding(nghttp2_bufs *bufs, ud.frame_recv_cb_called = 0; ud.data_chunk_len = 0; - CU_ASSERT((ssize_t)inlen == nghttp2_session_mem_recv(session, in, inlen)); + assert_ptrdiff((nghttp2_ssize)inlen, ==, + nghttp2_session_mem_recv2(session, in, inlen)); - CU_ASSERT(1 == ud.frame_recv_cb_called); - CU_ASSERT(datalen == ud.data_chunk_len); + assert_int(1, ==, ud.frame_recv_cb_called); + assert_size(datalen, ==, ud.data_chunk_len); mem->free(in, NULL); nghttp2_session_del(session); @@ -8153,7 +8410,7 @@ void test_nghttp2_session_pack_data_with_padding(void) { nghttp2_session *session; my_user_data ud; nghttp2_session_callbacks callbacks; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; nghttp2_frame *frame; size_t datalen = 55; nghttp2_mem *mem; @@ -8161,9 +8418,9 @@ void test_nghttp2_session_pack_data_with_padding(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback = block_count_send_callback; + callbacks.send_callback2 = block_count_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; - callbacks.select_padding_callback = select_padding_callback; + callbacks.select_padding_callback2 = select_padding_callback; data_prd.read_callback = fixed_length_data_source_read_callback; @@ -8171,17 +8428,17 @@ void test_nghttp2_session_pack_data_with_padding(void) { ud.padlen = 63; - nghttp2_submit_request(session, NULL, NULL, 0, &data_prd, NULL); + nghttp2_submit_request2(session, NULL, NULL, 0, &data_prd, NULL); ud.block_count = 1; ud.data_source_length = datalen; /* Sends HEADERS */ - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(NGHTTP2_HEADERS == ud.sent_frame_type); + assert_int(0, ==, nghttp2_session_send(session)); + assert_uint8(NGHTTP2_HEADERS, ==, ud.sent_frame_type); frame = &session->aob.item->frame; - CU_ASSERT(ud.padlen == frame->data.padlen); - CU_ASSERT(frame->hd.flags & NGHTTP2_FLAG_PADDED); + assert_size(ud.padlen, ==, frame->data.padlen); + assert_true(frame->hd.flags & NGHTTP2_FLAG_PADDED); /* Check reception of this DATA frame */ check_session_recv_data_with_padding(&session->aob.framebufs, datalen, mem); @@ -8196,9 +8453,9 @@ void test_nghttp2_session_pack_headers_with_padding(void) { nghttp2_session_callbacks callbacks; memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback = accumulator_send_callback; + callbacks.send_callback2 = accumulator_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; - callbacks.select_padding_callback = select_padding_callback; + callbacks.select_padding_callback2 = select_padding_callback; callbacks.on_frame_recv_callback = on_frame_recv_callback; acc.length = 0; @@ -8209,16 +8466,17 @@ void test_nghttp2_session_pack_headers_with_padding(void) { ud.padlen = 163; - CU_ASSERT(1 == nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), - NULL, NULL)); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int32( + 1, ==, + nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL)); + assert_int(0, ==, nghttp2_session_send(session)); - CU_ASSERT(acc.length < NGHTTP2_MAX_PAYLOADLEN); + assert_size(NGHTTP2_MAX_PAYLOADLEN, >, acc.length); ud.frame_recv_cb_called = 0; - CU_ASSERT((ssize_t)acc.length == - nghttp2_session_mem_recv(sv_session, acc.buf, acc.length)); - CU_ASSERT(1 == ud.frame_recv_cb_called); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(sv_session)); + assert_ptrdiff((nghttp2_ssize)acc.length, ==, + nghttp2_session_mem_recv2(sv_session, acc.buf, acc.length)); + assert_int(1, ==, ud.frame_recv_cb_called); + assert_null(nghttp2_session_get_next_ob_item(sv_session)); nghttp2_session_del(sv_session); nghttp2_session_del(session); @@ -8227,7 +8485,7 @@ void test_nghttp2_session_pack_headers_with_padding(void) { void test_nghttp2_pack_settings_payload(void) { nghttp2_settings_entry iv[2]; uint8_t buf[64]; - ssize_t len; + nghttp2_ssize len; nghttp2_settings_entry *resiv; size_t resniv; nghttp2_mem *mem; @@ -8239,28 +8497,29 @@ void test_nghttp2_pack_settings_payload(void) { iv[1].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE; iv[1].value = 4095; - len = nghttp2_pack_settings_payload(buf, sizeof(buf), iv, 2); - CU_ASSERT(2 * NGHTTP2_FRAME_SETTINGS_ENTRY_LENGTH == len); - CU_ASSERT(0 == nghttp2_frame_unpack_settings_payload2(&resiv, &resniv, buf, - (size_t)len, mem)); - CU_ASSERT(2 == resniv); - CU_ASSERT(NGHTTP2_SETTINGS_HEADER_TABLE_SIZE == resiv[0].settings_id); - CU_ASSERT(1023 == resiv[0].value); - CU_ASSERT(NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE == resiv[1].settings_id); - CU_ASSERT(4095 == resiv[1].value); + len = nghttp2_pack_settings_payload2(buf, sizeof(buf), iv, 2); + assert_ptrdiff(2 * NGHTTP2_FRAME_SETTINGS_ENTRY_LENGTH, ==, len); + assert_int(0, ==, + nghttp2_frame_unpack_settings_payload2(&resiv, &resniv, buf, + (size_t)len, mem)); + assert_size(2, ==, resniv); + assert_int32(NGHTTP2_SETTINGS_HEADER_TABLE_SIZE, ==, resiv[0].settings_id); + assert_uint32(1023, ==, resiv[0].value); + assert_int32(NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE, ==, resiv[1].settings_id); + assert_uint32(4095, ==, resiv[1].value); mem->free(resiv, NULL); - len = nghttp2_pack_settings_payload(buf, 9 /* too small */, iv, 2); - CU_ASSERT(NGHTTP2_ERR_INSUFF_BUFSIZE == len); + len = nghttp2_pack_settings_payload2(buf, 9 /* too small */, iv, 2); + assert_ptrdiff(NGHTTP2_ERR_INSUFF_BUFSIZE, ==, len); } #define check_stream_dep_sib(STREAM, DEP_PREV, DEP_NEXT, SIB_PREV, SIB_NEXT) \ do { \ - CU_ASSERT(DEP_PREV == STREAM->dep_prev); \ - CU_ASSERT(DEP_NEXT == STREAM->dep_next); \ - CU_ASSERT(SIB_PREV == STREAM->sib_prev); \ - CU_ASSERT(SIB_NEXT == STREAM->sib_next); \ + assert_ptr_equal(DEP_PREV, STREAM->dep_prev); \ + assert_ptr_equal(DEP_NEXT, STREAM->dep_next); \ + assert_ptr_equal(SIB_PREV, STREAM->sib_prev); \ + assert_ptr_equal(SIB_NEXT, STREAM->sib_next); \ } while (0) /* nghttp2_stream_dep_add() and its families functions should be @@ -8290,17 +8549,17 @@ void test_nghttp2_session_stream_dep_add(void) { * d */ - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT * 2 == a->sum_dep_weight); - CU_ASSERT(0 == b->sum_dep_weight); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == c->sum_dep_weight); - CU_ASSERT(0 == d->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT * 2, ==, a->sum_dep_weight); + assert_int32(0, ==, b->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, c->sum_dep_weight); + assert_int32(0, ==, d->sum_dep_weight); check_stream_dep_sib(a, root, b, NULL, NULL); check_stream_dep_sib(b, a, NULL, NULL, c); check_stream_dep_sib(c, a, d, b, NULL); check_stream_dep_sib(d, c, NULL, NULL, NULL); - CU_ASSERT(a == session->root.dep_next); + assert_ptr_equal(a, session->root.dep_next); e = open_stream_with_dep_excl(session, 9, a); @@ -8313,11 +8572,11 @@ void test_nghttp2_session_stream_dep_add(void) { * d */ - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == a->sum_dep_weight); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT * 2 == e->sum_dep_weight); - CU_ASSERT(0 == b->sum_dep_weight); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == c->sum_dep_weight); - CU_ASSERT(0 == d->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, a->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT * 2, ==, e->sum_dep_weight); + assert_int32(0, ==, b->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, c->sum_dep_weight); + assert_int32(0, ==, d->sum_dep_weight); check_stream_dep_sib(a, root, e, NULL, NULL); check_stream_dep_sib(e, a, b, NULL, NULL); @@ -8325,7 +8584,7 @@ void test_nghttp2_session_stream_dep_add(void) { check_stream_dep_sib(c, e, d, b, NULL); check_stream_dep_sib(d, c, NULL, NULL, NULL); - CU_ASSERT(a == session->root.dep_next); + assert_ptr_equal(a, session->root.dep_next); nghttp2_session_del(session); } @@ -8362,17 +8621,17 @@ void test_nghttp2_session_stream_dep_remove(void) { * d */ - CU_ASSERT(0 == a->sum_dep_weight); - CU_ASSERT(0 == b->sum_dep_weight); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == c->sum_dep_weight); - CU_ASSERT(0 == d->sum_dep_weight); + assert_int32(0, ==, a->sum_dep_weight); + assert_int32(0, ==, b->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, c->sum_dep_weight); + assert_int32(0, ==, d->sum_dep_weight); check_stream_dep_sib(a, NULL, NULL, NULL, NULL); check_stream_dep_sib(b, root, NULL, c, NULL); check_stream_dep_sib(c, root, d, NULL, b); check_stream_dep_sib(d, c, NULL, NULL, NULL); - CU_ASSERT(c == session->root.dep_next); + assert_ptr_equal(c, session->root.dep_next); nghttp2_session_del(session); @@ -8403,17 +8662,17 @@ void test_nghttp2_session_stream_dep_remove(void) { * d */ - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == a->sum_dep_weight); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == c->sum_dep_weight); - CU_ASSERT(0 == d->sum_dep_weight); - CU_ASSERT(0 == b->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, a->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, c->sum_dep_weight); + assert_int32(0, ==, d->sum_dep_weight); + assert_int32(0, ==, b->sum_dep_weight); check_stream_dep_sib(a, root, c, NULL, NULL); check_stream_dep_sib(b, NULL, NULL, NULL, NULL); check_stream_dep_sib(c, a, d, NULL, NULL); check_stream_dep_sib(d, c, NULL, NULL, NULL); - CU_ASSERT(a == session->root.dep_next); + assert_ptr_equal(a, session->root.dep_next); nghttp2_session_del(session); @@ -8443,11 +8702,11 @@ void test_nghttp2_session_stream_dep_remove(void) { * e--d--b */ - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT * 2 == a->sum_dep_weight); - CU_ASSERT(0 == b->sum_dep_weight); - CU_ASSERT(0 == d->sum_dep_weight); - CU_ASSERT(0 == c->sum_dep_weight); - CU_ASSERT(0 == e->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT * 2, ==, a->sum_dep_weight); + assert_int32(0, ==, b->sum_dep_weight); + assert_int32(0, ==, d->sum_dep_weight); + assert_int32(0, ==, c->sum_dep_weight); + assert_int32(0, ==, e->sum_dep_weight); check_stream_dep_sib(a, root, e, NULL, NULL); check_stream_dep_sib(b, a, NULL, d, NULL); @@ -8476,12 +8735,12 @@ void test_nghttp2_session_stream_dep_remove(void) { * f--e */ - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT * 3 == a->sum_dep_weight); - CU_ASSERT(0 == b->sum_dep_weight); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT * 2 == c->sum_dep_weight); - CU_ASSERT(0 == d->sum_dep_weight); - CU_ASSERT(0 == e->sum_dep_weight); - CU_ASSERT(0 == f->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT * 3, ==, a->sum_dep_weight); + assert_int32(0, ==, b->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT * 2, ==, c->sum_dep_weight); + assert_int32(0, ==, d->sum_dep_weight); + assert_int32(0, ==, e->sum_dep_weight); + assert_int32(0, ==, f->sum_dep_weight); nghttp2_stream_dep_remove(c); @@ -8493,12 +8752,12 @@ void test_nghttp2_session_stream_dep_remove(void) { /* c's weight 16 is distributed evenly to e and f. Each weight of e and f becomes 8. */ - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT * 2 + 8 * 2 == a->sum_dep_weight); - CU_ASSERT(0 == b->sum_dep_weight); - CU_ASSERT(0 == c->sum_dep_weight); - CU_ASSERT(0 == d->sum_dep_weight); - CU_ASSERT(0 == e->sum_dep_weight); - CU_ASSERT(0 == f->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT * 2 + 8 * 2, ==, a->sum_dep_weight); + assert_int32(0, ==, b->sum_dep_weight); + assert_int32(0, ==, c->sum_dep_weight); + assert_int32(0, ==, d->sum_dep_weight); + assert_int32(0, ==, e->sum_dep_weight); + assert_int32(0, ==, f->sum_dep_weight); check_stream_dep_sib(a, root, d, NULL, NULL); check_stream_dep_sib(b, a, NULL, e, NULL); @@ -8548,12 +8807,12 @@ void test_nghttp2_session_stream_dep_add_subtree(void) { * f d */ - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT * 3 == a->sum_dep_weight); - CU_ASSERT(0 == b->sum_dep_weight); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == c->sum_dep_weight); - CU_ASSERT(0 == d->sum_dep_weight); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == e->sum_dep_weight); - CU_ASSERT(0 == f->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT * 3, ==, a->sum_dep_weight); + assert_int32(0, ==, b->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, c->sum_dep_weight); + assert_int32(0, ==, d->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, e->sum_dep_weight); + assert_int32(0, ==, f->sum_dep_weight); check_stream_dep_sib(a, root, e, NULL, NULL); check_stream_dep_sib(b, a, NULL, c, NULL); @@ -8597,12 +8856,12 @@ void test_nghttp2_session_stream_dep_add_subtree(void) { * d */ - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == a->sum_dep_weight); - CU_ASSERT(0 == b->sum_dep_weight); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == c->sum_dep_weight); - CU_ASSERT(0 == d->sum_dep_weight); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT * 3 == e->sum_dep_weight); - CU_ASSERT(0 == f->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, a->sum_dep_weight); + assert_int32(0, ==, b->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, c->sum_dep_weight); + assert_int32(0, ==, d->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT * 3, ==, e->sum_dep_weight); + assert_int32(0, ==, f->sum_dep_weight); check_stream_dep_sib(a, root, e, NULL, NULL); check_stream_dep_sib(e, a, f, NULL, NULL); @@ -8646,10 +8905,10 @@ void test_nghttp2_session_stream_dep_remove_subtree(void) { * b d */ - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == a->sum_dep_weight); - CU_ASSERT(0 == b->sum_dep_weight); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == c->sum_dep_weight); - CU_ASSERT(0 == d->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, a->sum_dep_weight); + assert_int32(0, ==, b->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, c->sum_dep_weight); + assert_int32(0, ==, d->sum_dep_weight); check_stream_dep_sib(a, root, b, NULL, NULL); check_stream_dep_sib(b, a, NULL, NULL, NULL); @@ -8685,10 +8944,10 @@ void test_nghttp2_session_stream_dep_remove_subtree(void) { * d */ - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == a->sum_dep_weight); - CU_ASSERT(0 == b->sum_dep_weight); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == c->sum_dep_weight); - CU_ASSERT(0 == d->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, a->sum_dep_weight); + assert_int32(0, ==, b->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, c->sum_dep_weight); + assert_int32(0, ==, d->sum_dep_weight); check_stream_dep_sib(a, root, c, NULL, NULL); check_stream_dep_sib(c, a, d, NULL, NULL); @@ -8723,11 +8982,11 @@ void test_nghttp2_session_stream_dep_remove_subtree(void) { * b--e d */ - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT * 2 == a->sum_dep_weight); - CU_ASSERT(0 == b->sum_dep_weight); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == c->sum_dep_weight); - CU_ASSERT(0 == d->sum_dep_weight); - CU_ASSERT(0 == e->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT * 2, ==, a->sum_dep_weight); + assert_int32(0, ==, b->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, c->sum_dep_weight); + assert_int32(0, ==, d->sum_dep_weight); + assert_int32(0, ==, e->sum_dep_weight); check_stream_dep_sib(a, root, b, NULL, NULL); check_stream_dep_sib(b, a, NULL, NULL, e); @@ -8764,7 +9023,7 @@ void test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us(void) { */ nghttp2_stream_dep_remove_subtree(c); - CU_ASSERT(0 == nghttp2_stream_dep_insert_subtree(&session->root, c)); + assert_int(0, ==, nghttp2_stream_dep_insert_subtree(&session->root, c)); /* * c @@ -8774,13 +9033,13 @@ void test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us(void) { * b */ - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == c->sum_dep_weight); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == a->sum_dep_weight); - CU_ASSERT(0 == b->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, c->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, a->sum_dep_weight); + assert_int32(0, ==, b->sum_dep_weight); - CU_ASSERT(nghttp2_pq_empty(&a->obq)); - CU_ASSERT(nghttp2_pq_empty(&b->obq)); - CU_ASSERT(nghttp2_pq_empty(&c->obq)); + assert_true(nghttp2_pq_empty(&a->obq)); + assert_true(nghttp2_pq_empty(&b->obq)); + assert_true(nghttp2_pq_empty(&c->obq)); check_stream_dep_sib(c, root, a, NULL, NULL); check_stream_dep_sib(a, c, b, NULL, NULL); @@ -8801,7 +9060,7 @@ void test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us(void) { */ nghttp2_stream_dep_remove_subtree(c); - CU_ASSERT(0 == nghttp2_stream_dep_insert_subtree(&session->root, c)); + assert_int(0, ==, nghttp2_stream_dep_insert_subtree(&session->root, c)); /* * c @@ -8809,13 +9068,13 @@ void test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us(void) { * b--a */ - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT * 2 == c->sum_dep_weight); - CU_ASSERT(0 == b->sum_dep_weight); - CU_ASSERT(0 == a->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT * 2, ==, c->sum_dep_weight); + assert_int32(0, ==, b->sum_dep_weight); + assert_int32(0, ==, a->sum_dep_weight); - CU_ASSERT(nghttp2_pq_empty(&a->obq)); - CU_ASSERT(nghttp2_pq_empty(&b->obq)); - CU_ASSERT(nghttp2_pq_empty(&c->obq)); + assert_true(nghttp2_pq_empty(&a->obq)); + assert_true(nghttp2_pq_empty(&b->obq)); + assert_true(nghttp2_pq_empty(&c->obq)); check_stream_dep_sib(c, root, b, NULL, NULL); check_stream_dep_sib(b, c, NULL, NULL, a); @@ -8839,7 +9098,7 @@ void test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us(void) { */ nghttp2_stream_dep_remove_subtree(c); - CU_ASSERT(0 == nghttp2_stream_dep_insert_subtree(&session->root, c)); + assert_int(0, ==, nghttp2_stream_dep_insert_subtree(&session->root, c)); /* * c @@ -8849,15 +9108,15 @@ void test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us(void) { * b */ - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT * 2 == c->sum_dep_weight); - CU_ASSERT(0 == d->sum_dep_weight); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == a->sum_dep_weight); - CU_ASSERT(0 == b->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT * 2, ==, c->sum_dep_weight); + assert_int32(0, ==, d->sum_dep_weight); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, a->sum_dep_weight); + assert_int32(0, ==, b->sum_dep_weight); - CU_ASSERT(nghttp2_pq_empty(&a->obq)); - CU_ASSERT(nghttp2_pq_empty(&b->obq)); - CU_ASSERT(nghttp2_pq_empty(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); + assert_true(nghttp2_pq_empty(&a->obq)); + assert_true(nghttp2_pq_empty(&b->obq)); + assert_true(nghttp2_pq_empty(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); check_stream_dep_sib(c, root, d, NULL, NULL); check_stream_dep_sib(d, c, NULL, NULL, a); @@ -8886,7 +9145,7 @@ void test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us(void) { nghttp2_stream_attach_item(b, db); nghttp2_stream_dep_remove_subtree(c); - CU_ASSERT(0 == nghttp2_stream_dep_insert_subtree(&session->root, c)); + assert_int(0, ==, nghttp2_stream_dep_insert_subtree(&session->root, c)); /* * c @@ -8896,14 +9155,14 @@ void test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us(void) { * b */ - CU_ASSERT(c->queued); - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(!d->queued); + assert_true(c->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(!d->queued); - CU_ASSERT(1 == nghttp2_pq_size(&a->obq)); - CU_ASSERT(1 == nghttp2_pq_size(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); + assert_size(1, ==, nghttp2_pq_size(&a->obq)); + assert_size(1, ==, nghttp2_pq_size(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); check_stream_dep_sib(c, root, d, NULL, NULL); check_stream_dep_sib(d, c, NULL, NULL, a); @@ -8934,7 +9193,7 @@ void test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us(void) { nghttp2_stream_attach_item(c, dc); nghttp2_stream_dep_remove_subtree(c); - CU_ASSERT(0 == nghttp2_stream_dep_insert_subtree(&session->root, c)); + assert_int(0, ==, nghttp2_stream_dep_insert_subtree(&session->root, c)); /* * c @@ -8944,10 +9203,10 @@ void test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us(void) { * b */ - CU_ASSERT(c->queued); - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(!d->queued); + assert_true(c->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(!d->queued); check_stream_dep_sib(c, root, d, NULL, NULL); check_stream_dep_sib(d, c, NULL, NULL, a); @@ -8986,80 +9245,80 @@ void test_nghttp2_session_stream_attach_item(void) { nghttp2_stream_attach_item(b, db); - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(!c->queued); - CU_ASSERT(!d->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(!c->queued); + assert_true(!d->queued); - CU_ASSERT(1 == nghttp2_pq_size(&a->obq)); + assert_size(1, ==, nghttp2_pq_size(&a->obq)); /* Attach item to c */ dc = create_data_ob_item(mem); nghttp2_stream_attach_item(c, dc); - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(!d->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(c->queued); + assert_true(!d->queued); - CU_ASSERT(2 == nghttp2_pq_size(&a->obq)); + assert_size(2, ==, nghttp2_pq_size(&a->obq)); /* Attach item to a */ da = create_data_ob_item(mem); nghttp2_stream_attach_item(a, da); - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(!d->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(c->queued); + assert_true(!d->queued); - CU_ASSERT(2 == nghttp2_pq_size(&a->obq)); + assert_size(2, ==, nghttp2_pq_size(&a->obq)); /* Detach item from a */ nghttp2_stream_detach_item(a); - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(!d->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(c->queued); + assert_true(!d->queued); - CU_ASSERT(2 == nghttp2_pq_size(&a->obq)); + assert_size(2, ==, nghttp2_pq_size(&a->obq)); /* Attach item to d */ dd = create_data_ob_item(mem); nghttp2_stream_attach_item(d, dd); - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(d->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(c->queued); + assert_true(d->queued); - CU_ASSERT(2 == nghttp2_pq_size(&a->obq)); - CU_ASSERT(1 == nghttp2_pq_size(&c->obq)); + assert_size(2, ==, nghttp2_pq_size(&a->obq)); + assert_size(1, ==, nghttp2_pq_size(&c->obq)); /* Detach item from c */ nghttp2_stream_detach_item(c); - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(d->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(c->queued); + assert_true(d->queued); - CU_ASSERT(2 == nghttp2_pq_size(&a->obq)); - CU_ASSERT(1 == nghttp2_pq_size(&c->obq)); + assert_size(2, ==, nghttp2_pq_size(&a->obq)); + assert_size(1, ==, nghttp2_pq_size(&c->obq)); /* Detach item from b */ nghttp2_stream_detach_item(b); - CU_ASSERT(a->queued); - CU_ASSERT(!b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(d->queued); + assert_true(a->queued); + assert_true(!b->queued); + assert_true(c->queued); + assert_true(d->queued); - CU_ASSERT(1 == nghttp2_pq_size(&a->obq)); + assert_size(1, ==, nghttp2_pq_size(&a->obq)); /* exercises insertion */ e = open_stream_with_dep_excl(session, 9, a); @@ -9073,17 +9332,17 @@ void test_nghttp2_session_stream_attach_item(void) { * d */ - CU_ASSERT(a->queued); - CU_ASSERT(e->queued); - CU_ASSERT(!b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(d->queued); + assert_true(a->queued); + assert_true(e->queued); + assert_true(!b->queued); + assert_true(c->queued); + assert_true(d->queued); - CU_ASSERT(1 == nghttp2_pq_size(&a->obq)); - CU_ASSERT(1 == nghttp2_pq_size(&e->obq)); - CU_ASSERT(nghttp2_pq_empty(&b->obq)); - CU_ASSERT(1 == nghttp2_pq_size(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); + assert_size(1, ==, nghttp2_pq_size(&a->obq)); + assert_size(1, ==, nghttp2_pq_size(&e->obq)); + assert_true(nghttp2_pq_empty(&b->obq)); + assert_size(1, ==, nghttp2_pq_size(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); /* exercises deletion */ nghttp2_stream_dep_remove(e); @@ -9095,20 +9354,20 @@ void test_nghttp2_session_stream_attach_item(void) { * d */ - CU_ASSERT(a->queued); - CU_ASSERT(!b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(d->queued); + assert_true(a->queued); + assert_true(!b->queued); + assert_true(c->queued); + assert_true(d->queued); - CU_ASSERT(1 == nghttp2_pq_size(&a->obq)); - CU_ASSERT(nghttp2_pq_empty(&b->obq)); - CU_ASSERT(1 == nghttp2_pq_size(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); + assert_size(1, ==, nghttp2_pq_size(&a->obq)); + assert_true(nghttp2_pq_empty(&b->obq)); + assert_size(1, ==, nghttp2_pq_size(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); /* e's weight 16 is distributed equally among c and b, both now have weight 8 each. */ - CU_ASSERT(8 == b->weight); - CU_ASSERT(8 == c->weight); + assert_int32(8, ==, b->weight); + assert_int32(8, ==, c->weight); /* da, db, dc have been detached */ nghttp2_outbound_item_free(da, mem); @@ -9142,28 +9401,28 @@ void test_nghttp2_session_stream_attach_item(void) { nghttp2_stream_attach_item(b, db); nghttp2_stream_attach_item(c, dc); - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(!d->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(c->queued); + assert_true(!d->queued); - CU_ASSERT(2 == nghttp2_pq_size(&a->obq)); - CU_ASSERT(nghttp2_pq_empty(&b->obq)); - CU_ASSERT(nghttp2_pq_empty(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); + assert_size(2, ==, nghttp2_pq_size(&a->obq)); + assert_true(nghttp2_pq_empty(&b->obq)); + assert_true(nghttp2_pq_empty(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); /* Detach item from a */ nghttp2_stream_detach_item(a); - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(!d->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(c->queued); + assert_true(!d->queued); - CU_ASSERT(2 == nghttp2_pq_size(&a->obq)); - CU_ASSERT(nghttp2_pq_empty(&b->obq)); - CU_ASSERT(nghttp2_pq_empty(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); + assert_size(2, ==, nghttp2_pq_size(&a->obq)); + assert_true(nghttp2_pq_empty(&b->obq)); + assert_true(nghttp2_pq_empty(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); /* da has been detached */ nghttp2_outbound_item_free(da, mem); @@ -9209,19 +9468,19 @@ void test_nghttp2_session_stream_attach_item_subtree(void) { nghttp2_stream_attach_item(b, db); - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(!c->queued); - CU_ASSERT(!d->queued); - CU_ASSERT(e->queued); - CU_ASSERT(!f->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(!c->queued); + assert_true(!d->queued); + assert_true(e->queued); + assert_true(!f->queued); - CU_ASSERT(1 == nghttp2_pq_size(&a->obq)); - CU_ASSERT(nghttp2_pq_empty(&b->obq)); - CU_ASSERT(nghttp2_pq_empty(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); - CU_ASSERT(nghttp2_pq_empty(&e->obq)); - CU_ASSERT(nghttp2_pq_empty(&f->obq)); + assert_size(1, ==, nghttp2_pq_size(&a->obq)); + assert_true(nghttp2_pq_empty(&b->obq)); + assert_true(nghttp2_pq_empty(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); + assert_true(nghttp2_pq_empty(&e->obq)); + assert_true(nghttp2_pq_empty(&f->obq)); /* Insert subtree e under a */ @@ -9238,25 +9497,25 @@ void test_nghttp2_session_stream_attach_item_subtree(void) { * d */ - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(!c->queued); - CU_ASSERT(!d->queued); - CU_ASSERT(e->queued); - CU_ASSERT(!f->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(!c->queued); + assert_true(!d->queued); + assert_true(e->queued); + assert_true(!f->queued); - CU_ASSERT(1 == nghttp2_pq_size(&a->obq)); - CU_ASSERT(nghttp2_pq_empty(&b->obq)); - CU_ASSERT(nghttp2_pq_empty(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); - CU_ASSERT(1 == nghttp2_pq_size(&e->obq)); - CU_ASSERT(nghttp2_pq_empty(&f->obq)); + assert_size(1, ==, nghttp2_pq_size(&a->obq)); + assert_true(nghttp2_pq_empty(&b->obq)); + assert_true(nghttp2_pq_empty(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); + assert_size(1, ==, nghttp2_pq_size(&e->obq)); + assert_true(nghttp2_pq_empty(&f->obq)); /* Remove subtree b */ nghttp2_stream_dep_remove_subtree(b); - CU_ASSERT(0 == nghttp2_stream_dep_add_subtree(&session->root, b)); + assert_int(0, ==, nghttp2_stream_dep_add_subtree(&session->root, b)); /* * a b @@ -9268,45 +9527,45 @@ void test_nghttp2_session_stream_attach_item_subtree(void) { * d */ - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(!c->queued); - CU_ASSERT(!d->queued); - CU_ASSERT(e->queued); - CU_ASSERT(!f->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(!c->queued); + assert_true(!d->queued); + assert_true(e->queued); + assert_true(!f->queued); - CU_ASSERT(1 == nghttp2_pq_size(&a->obq)); - CU_ASSERT(nghttp2_pq_empty(&b->obq)); - CU_ASSERT(nghttp2_pq_empty(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); - CU_ASSERT(nghttp2_pq_empty(&e->obq)); - CU_ASSERT(nghttp2_pq_empty(&f->obq)); + assert_size(1, ==, nghttp2_pq_size(&a->obq)); + assert_true(nghttp2_pq_empty(&b->obq)); + assert_true(nghttp2_pq_empty(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); + assert_true(nghttp2_pq_empty(&e->obq)); + assert_true(nghttp2_pq_empty(&f->obq)); /* Remove subtree a, and add it to root again */ nghttp2_stream_dep_remove_subtree(a); - CU_ASSERT(0 == nghttp2_stream_dep_add_subtree(&session->root, a)); + assert_int(0, ==, nghttp2_stream_dep_add_subtree(&session->root, a)); - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(!c->queued); - CU_ASSERT(!d->queued); - CU_ASSERT(e->queued); - CU_ASSERT(!f->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(!c->queued); + assert_true(!d->queued); + assert_true(e->queued); + assert_true(!f->queued); - CU_ASSERT(1 == nghttp2_pq_size(&a->obq)); - CU_ASSERT(nghttp2_pq_empty(&b->obq)); - CU_ASSERT(nghttp2_pq_empty(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); - CU_ASSERT(nghttp2_pq_empty(&e->obq)); - CU_ASSERT(nghttp2_pq_empty(&f->obq)); + assert_size(1, ==, nghttp2_pq_size(&a->obq)); + assert_true(nghttp2_pq_empty(&b->obq)); + assert_true(nghttp2_pq_empty(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); + assert_true(nghttp2_pq_empty(&e->obq)); + assert_true(nghttp2_pq_empty(&f->obq)); /* Remove subtree c */ nghttp2_stream_dep_remove_subtree(c); - CU_ASSERT(0 == nghttp2_stream_dep_add_subtree(&session->root, c)); + assert_int(0, ==, nghttp2_stream_dep_add_subtree(&session->root, c)); /* * a b c @@ -9316,19 +9575,19 @@ void test_nghttp2_session_stream_attach_item_subtree(void) { * f */ - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(!c->queued); - CU_ASSERT(!d->queued); - CU_ASSERT(e->queued); - CU_ASSERT(!f->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(!c->queued); + assert_true(!d->queued); + assert_true(e->queued); + assert_true(!f->queued); - CU_ASSERT(1 == nghttp2_pq_size(&a->obq)); - CU_ASSERT(nghttp2_pq_empty(&b->obq)); - CU_ASSERT(nghttp2_pq_empty(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); - CU_ASSERT(nghttp2_pq_empty(&e->obq)); - CU_ASSERT(nghttp2_pq_empty(&f->obq)); + assert_size(1, ==, nghttp2_pq_size(&a->obq)); + assert_true(nghttp2_pq_empty(&b->obq)); + assert_true(nghttp2_pq_empty(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); + assert_true(nghttp2_pq_empty(&e->obq)); + assert_true(nghttp2_pq_empty(&f->obq)); dd = create_data_ob_item(mem); @@ -9347,19 +9606,19 @@ void test_nghttp2_session_stream_attach_item_subtree(void) { * d f */ - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(d->queued); - CU_ASSERT(e->queued); - CU_ASSERT(!f->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(c->queued); + assert_true(d->queued); + assert_true(e->queued); + assert_true(!f->queued); - CU_ASSERT(2 == nghttp2_pq_size(&a->obq)); - CU_ASSERT(nghttp2_pq_empty(&b->obq)); - CU_ASSERT(1 == nghttp2_pq_size(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); - CU_ASSERT(nghttp2_pq_empty(&e->obq)); - CU_ASSERT(nghttp2_pq_empty(&f->obq)); + assert_size(2, ==, nghttp2_pq_size(&a->obq)); + assert_true(nghttp2_pq_empty(&b->obq)); + assert_size(1, ==, nghttp2_pq_size(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); + assert_true(nghttp2_pq_empty(&e->obq)); + assert_true(nghttp2_pq_empty(&f->obq)); /* Insert b under a */ @@ -9376,24 +9635,24 @@ void test_nghttp2_session_stream_attach_item_subtree(void) { * d f */ - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(d->queued); - CU_ASSERT(e->queued); - CU_ASSERT(!f->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(c->queued); + assert_true(d->queued); + assert_true(e->queued); + assert_true(!f->queued); - CU_ASSERT(1 == nghttp2_pq_size(&a->obq)); - CU_ASSERT(2 == nghttp2_pq_size(&b->obq)); - CU_ASSERT(1 == nghttp2_pq_size(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); - CU_ASSERT(nghttp2_pq_empty(&e->obq)); - CU_ASSERT(nghttp2_pq_empty(&f->obq)); + assert_size(1, ==, nghttp2_pq_size(&a->obq)); + assert_size(2, ==, nghttp2_pq_size(&b->obq)); + assert_size(1, ==, nghttp2_pq_size(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); + assert_true(nghttp2_pq_empty(&e->obq)); + assert_true(nghttp2_pq_empty(&f->obq)); /* Remove subtree b */ nghttp2_stream_dep_remove_subtree(b); - CU_ASSERT(0 == nghttp2_stream_dep_add_subtree(&session->root, b)); + assert_int(0, ==, nghttp2_stream_dep_add_subtree(&session->root, b)); /* * b a @@ -9403,19 +9662,19 @@ void test_nghttp2_session_stream_attach_item_subtree(void) { * f d */ - CU_ASSERT(!a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(d->queued); - CU_ASSERT(e->queued); - CU_ASSERT(!f->queued); + assert_true(!a->queued); + assert_true(b->queued); + assert_true(c->queued); + assert_true(d->queued); + assert_true(e->queued); + assert_true(!f->queued); - CU_ASSERT(nghttp2_pq_empty(&a->obq)); - CU_ASSERT(2 == nghttp2_pq_size(&b->obq)); - CU_ASSERT(1 == nghttp2_pq_size(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); - CU_ASSERT(nghttp2_pq_empty(&e->obq)); - CU_ASSERT(nghttp2_pq_empty(&f->obq)); + assert_true(nghttp2_pq_empty(&a->obq)); + assert_size(2, ==, nghttp2_pq_size(&b->obq)); + assert_size(1, ==, nghttp2_pq_size(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); + assert_true(nghttp2_pq_empty(&e->obq)); + assert_true(nghttp2_pq_empty(&f->obq)); /* Remove subtree c, and detach item from b, and then re-add subtree c under b */ @@ -9432,19 +9691,19 @@ void test_nghttp2_session_stream_attach_item_subtree(void) { * f d */ - CU_ASSERT(!a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(d->queued); - CU_ASSERT(e->queued); - CU_ASSERT(!f->queued); + assert_true(!a->queued); + assert_true(b->queued); + assert_true(c->queued); + assert_true(d->queued); + assert_true(e->queued); + assert_true(!f->queued); - CU_ASSERT(nghttp2_pq_empty(&a->obq)); - CU_ASSERT(2 == nghttp2_pq_size(&b->obq)); - CU_ASSERT(1 == nghttp2_pq_size(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); - CU_ASSERT(nghttp2_pq_empty(&e->obq)); - CU_ASSERT(nghttp2_pq_empty(&f->obq)); + assert_true(nghttp2_pq_empty(&a->obq)); + assert_size(2, ==, nghttp2_pq_size(&b->obq)); + assert_size(1, ==, nghttp2_pq_size(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); + assert_true(nghttp2_pq_empty(&e->obq)); + assert_true(nghttp2_pq_empty(&f->obq)); /* Attach data to a, and add subtree a under b */ @@ -9461,19 +9720,19 @@ void test_nghttp2_session_stream_attach_item_subtree(void) { * f d */ - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(d->queued); - CU_ASSERT(e->queued); - CU_ASSERT(!f->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(c->queued); + assert_true(d->queued); + assert_true(e->queued); + assert_true(!f->queued); - CU_ASSERT(nghttp2_pq_empty(&a->obq)); - CU_ASSERT(3 == nghttp2_pq_size(&b->obq)); - CU_ASSERT(1 == nghttp2_pq_size(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); - CU_ASSERT(nghttp2_pq_empty(&e->obq)); - CU_ASSERT(nghttp2_pq_empty(&f->obq)); + assert_true(nghttp2_pq_empty(&a->obq)); + assert_size(3, ==, nghttp2_pq_size(&b->obq)); + assert_size(1, ==, nghttp2_pq_size(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); + assert_true(nghttp2_pq_empty(&e->obq)); + assert_true(nghttp2_pq_empty(&f->obq)); /* Remove subtree c, and add under f */ nghttp2_stream_dep_remove_subtree(c); @@ -9491,19 +9750,19 @@ void test_nghttp2_session_stream_attach_item_subtree(void) { * d */ - CU_ASSERT(a->queued); - CU_ASSERT(b->queued); - CU_ASSERT(c->queued); - CU_ASSERT(d->queued); - CU_ASSERT(e->queued); - CU_ASSERT(f->queued); + assert_true(a->queued); + assert_true(b->queued); + assert_true(c->queued); + assert_true(d->queued); + assert_true(e->queued); + assert_true(f->queued); - CU_ASSERT(nghttp2_pq_empty(&a->obq)); - CU_ASSERT(2 == nghttp2_pq_size(&b->obq)); - CU_ASSERT(1 == nghttp2_pq_size(&c->obq)); - CU_ASSERT(nghttp2_pq_empty(&d->obq)); - CU_ASSERT(1 == nghttp2_pq_size(&e->obq)); - CU_ASSERT(1 == nghttp2_pq_size(&f->obq)); + assert_true(nghttp2_pq_empty(&a->obq)); + assert_size(2, ==, nghttp2_pq_size(&b->obq)); + assert_size(1, ==, nghttp2_pq_size(&c->obq)); + assert_true(nghttp2_pq_empty(&d->obq)); + assert_size(1, ==, nghttp2_pq_size(&e->obq)); + assert_size(1, ==, nghttp2_pq_size(&f->obq)); /* db has been detached */ nghttp2_outbound_item_free(db, mem); @@ -9520,8 +9779,8 @@ void test_nghttp2_session_stream_get_state(void) { nghttp2_bufs bufs; nghttp2_buf *buf; nghttp2_stream *stream; - ssize_t rv; - nghttp2_data_provider data_prd; + nghttp2_ssize rv; + nghttp2_data_provider2 data_prd; nghttp2_frame frame; mem = nghttp2_mem_default(); @@ -9529,28 +9788,30 @@ void test_nghttp2_session_stream_get_state(void) { memset(&data_prd, 0, sizeof(data_prd)); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_server_new(&session, &callbacks, NULL); nghttp2_hd_deflate_init(&deflater, mem); - CU_ASSERT(NGHTTP2_STREAM_STATE_IDLE == - nghttp2_stream_get_state(nghttp2_session_get_root_stream(session))); + assert_enum( + nghttp2_stream_proto_state, NGHTTP2_STREAM_STATE_IDLE, ==, + nghttp2_stream_get_state(nghttp2_session_get_root_stream(session))); /* stream 1 HEADERS; without END_STREAM flag set */ pack_headers(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, reqnv, ARRLEN(reqnv), mem); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); stream = nghttp2_session_find_stream(session, 1); - CU_ASSERT(NULL != stream); - CU_ASSERT(1 == stream->stream_id); - CU_ASSERT(NGHTTP2_STREAM_STATE_OPEN == nghttp2_stream_get_state(stream)); + assert_not_null(stream); + assert_int32(1, ==, stream->stream_id); + assert_enum(nghttp2_stream_proto_state, NGHTTP2_STREAM_STATE_OPEN, ==, + nghttp2_stream_get_state(stream)); nghttp2_bufs_reset(&bufs); @@ -9560,41 +9821,44 @@ void test_nghttp2_session_stream_get_state(void) { ARRLEN(reqnv), mem); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); stream = nghttp2_session_find_stream(session, 3); - CU_ASSERT(NULL != stream); - CU_ASSERT(3 == stream->stream_id); - CU_ASSERT(NGHTTP2_STREAM_STATE_HALF_CLOSED_REMOTE == - nghttp2_stream_get_state(stream)); + assert_not_null(stream); + assert_int32(3, ==, stream->stream_id); + assert_enum(nghttp2_stream_proto_state, + NGHTTP2_STREAM_STATE_HALF_CLOSED_REMOTE, ==, + nghttp2_stream_get_state(stream)); nghttp2_bufs_reset(&bufs); /* Respond to stream 1 */ - nghttp2_submit_response(session, 1, resnv, ARRLEN(resnv), NULL); + nghttp2_submit_response2(session, 1, resnv, ARRLEN(resnv), NULL); rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); stream = nghttp2_session_find_stream(session, 1); - CU_ASSERT(NGHTTP2_STREAM_STATE_HALF_CLOSED_LOCAL == - nghttp2_stream_get_state(stream)); + assert_enum(nghttp2_stream_proto_state, + NGHTTP2_STREAM_STATE_HALF_CLOSED_LOCAL, ==, + nghttp2_stream_get_state(stream)); /* Respond to stream 3 */ - nghttp2_submit_response(session, 3, resnv, ARRLEN(resnv), NULL); + nghttp2_submit_response2(session, 3, resnv, ARRLEN(resnv), NULL); rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); stream = nghttp2_session_find_stream(session, 3); - CU_ASSERT(NGHTTP2_STREAM_STATE_CLOSED == nghttp2_stream_get_state(stream)); + assert_enum(nghttp2_stream_proto_state, NGHTTP2_STREAM_STATE_CLOSED, ==, + nghttp2_stream_get_state(stream)); /* stream 5 HEADERS; with END_STREAM flag set */ pack_headers(&bufs, &deflater, 5, @@ -9602,9 +9866,9 @@ void test_nghttp2_session_stream_get_state(void) { ARRLEN(reqnv), mem); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); nghttp2_bufs_reset(&bufs); @@ -9612,57 +9876,58 @@ void test_nghttp2_session_stream_get_state(void) { rv = nghttp2_submit_push_promise(session, NGHTTP2_FLAG_NONE, 5, reqnv, ARRLEN(reqnv), NULL); - CU_ASSERT(2 == rv); + assert_ptrdiff(2, ==, rv); rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); stream = nghttp2_session_find_stream(session, 2); - CU_ASSERT(NGHTTP2_STREAM_STATE_RESERVED_LOCAL == - nghttp2_stream_get_state(stream)); + assert_enum(nghttp2_stream_proto_state, NGHTTP2_STREAM_STATE_RESERVED_LOCAL, + ==, nghttp2_stream_get_state(stream)); /* Send response to push stream 2 with END_STREAM set */ - nghttp2_submit_response(session, 2, resnv, ARRLEN(resnv), NULL); + nghttp2_submit_response2(session, 2, resnv, ARRLEN(resnv), NULL); rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); stream = nghttp2_session_find_stream(session, 2); /* At server, pushed stream object is not retained after closed */ - CU_ASSERT(NULL == stream); + assert_null(stream); /* Push stream 4 associated to stream 5 */ rv = nghttp2_submit_push_promise(session, NGHTTP2_FLAG_NONE, 5, reqnv, ARRLEN(reqnv), NULL); - CU_ASSERT(4 == rv); + assert_ptrdiff(4, ==, rv); rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); stream = nghttp2_session_find_stream(session, 4); - CU_ASSERT(NGHTTP2_STREAM_STATE_RESERVED_LOCAL == - nghttp2_stream_get_state(stream)); + assert_enum(nghttp2_stream_proto_state, NGHTTP2_STREAM_STATE_RESERVED_LOCAL, + ==, nghttp2_stream_get_state(stream)); /* Send response to push stream 4 without closing */ data_prd.read_callback = defer_data_source_read_callback; - nghttp2_submit_response(session, 4, resnv, ARRLEN(resnv), &data_prd); + nghttp2_submit_response2(session, 4, resnv, ARRLEN(resnv), &data_prd); rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); stream = nghttp2_session_find_stream(session, 4); - CU_ASSERT(NGHTTP2_STREAM_STATE_HALF_CLOSED_REMOTE == - nghttp2_stream_get_state(stream)); + assert_enum(nghttp2_stream_proto_state, + NGHTTP2_STREAM_STATE_HALF_CLOSED_REMOTE, ==, + nghttp2_stream_get_state(stream)); /* Create idle stream by PRIORITY frame */ nghttp2_frame_priority_init(&frame.priority, 7, &pri_spec_default); @@ -9672,13 +9937,14 @@ void test_nghttp2_session_stream_get_state(void) { nghttp2_frame_priority_free(&frame.priority); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); stream = nghttp2_session_find_stream(session, 7); - CU_ASSERT(NGHTTP2_STREAM_STATE_IDLE == nghttp2_stream_get_state(stream)); + assert_enum(nghttp2_stream_proto_state, NGHTTP2_STREAM_STATE_IDLE, ==, + nghttp2_stream_get_state(stream)); nghttp2_bufs_reset(&bufs); @@ -9690,25 +9956,25 @@ void test_nghttp2_session_stream_get_state(void) { nghttp2_session_client_new(&session, &callbacks, NULL); nghttp2_hd_deflate_init(&deflater, mem); - nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); + nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); /* Receive PUSH_PROMISE 2 associated to stream 1 */ pack_push_promise(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, 2, reqnv, ARRLEN(reqnv), mem); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); stream = nghttp2_session_find_stream(session, 2); - CU_ASSERT(NGHTTP2_STREAM_STATE_RESERVED_REMOTE == - nghttp2_stream_get_state(stream)); + assert_enum(nghttp2_stream_proto_state, NGHTTP2_STREAM_STATE_RESERVED_REMOTE, + ==, nghttp2_stream_get_state(stream)); nghttp2_bufs_reset(&bufs); @@ -9717,14 +9983,15 @@ void test_nghttp2_session_stream_get_state(void) { ARRLEN(resnv), mem); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); stream = nghttp2_session_find_stream(session, 2); - CU_ASSERT(NGHTTP2_STREAM_STATE_HALF_CLOSED_LOCAL == - nghttp2_stream_get_state(stream)); + assert_enum(nghttp2_stream_proto_state, + NGHTTP2_STREAM_STATE_HALF_CLOSED_LOCAL, ==, + nghttp2_stream_get_state(stream)); nghttp2_bufs_reset(&bufs); @@ -9745,28 +10012,28 @@ void test_nghttp2_session_stream_get_something(void) { a = open_stream(session, 1); - CU_ASSERT(nghttp2_session_get_root_stream(session) == - nghttp2_stream_get_parent(a)); - CU_ASSERT(NULL == nghttp2_stream_get_previous_sibling(a)); - CU_ASSERT(NULL == nghttp2_stream_get_next_sibling(a)); - CU_ASSERT(NULL == nghttp2_stream_get_first_child(a)); + assert_ptr_equal(nghttp2_session_get_root_stream(session), + nghttp2_stream_get_parent(a)); + assert_null(nghttp2_stream_get_previous_sibling(a)); + assert_null(nghttp2_stream_get_next_sibling(a)); + assert_null(nghttp2_stream_get_first_child(a)); b = open_stream_with_dep(session, 3, a); c = open_stream_with_dep_weight(session, 5, 11, a); - CU_ASSERT(a == nghttp2_stream_get_parent(c)); - CU_ASSERT(a == nghttp2_stream_get_parent(b)); + assert_ptr_equal(a, nghttp2_stream_get_parent(c)); + assert_ptr_equal(a, nghttp2_stream_get_parent(b)); - CU_ASSERT(c == nghttp2_stream_get_first_child(a)); + assert_ptr_equal(c, nghttp2_stream_get_first_child(a)); - CU_ASSERT(b == nghttp2_stream_get_next_sibling(c)); - CU_ASSERT(c == nghttp2_stream_get_previous_sibling(b)); + assert_ptr_equal(b, nghttp2_stream_get_next_sibling(c)); + assert_ptr_equal(c, nghttp2_stream_get_previous_sibling(b)); - CU_ASSERT(27 == nghttp2_stream_get_sum_dependency_weight(a)); + assert_int32(27, ==, nghttp2_stream_get_sum_dependency_weight(a)); - CU_ASSERT(11 == nghttp2_stream_get_weight(c)); - CU_ASSERT(5 == nghttp2_stream_get_stream_id(c)); - CU_ASSERT(0 == nghttp2_stream_get_stream_id(&session->root)); + assert_int32(11, ==, nghttp2_stream_get_weight(c)); + assert_int32(5, ==, nghttp2_stream_get_stream_id(c)); + assert_int32(0, ==, nghttp2_stream_get_stream_id(&session->root)); nghttp2_session_del(session); } @@ -9784,17 +10051,17 @@ void test_nghttp2_session_find_stream(void) { stream = nghttp2_session_find_stream(session, 1); - CU_ASSERT(NULL != stream); - CU_ASSERT(1 == stream->stream_id); + assert_not_null(stream); + assert_int32(1, ==, stream->stream_id); stream = nghttp2_session_find_stream(session, 0); - CU_ASSERT(&session->root == stream); - CU_ASSERT(0 == stream->stream_id); + assert_ptr_equal(&session->root, stream); + assert_int32(0, ==, stream->stream_id); stream = nghttp2_session_find_stream(session, 2); - CU_ASSERT(NULL == stream); + assert_null(stream); nghttp2_session_del(session); } @@ -9808,7 +10075,7 @@ void test_nghttp2_session_keep_closed_stream(void) { size_t i; memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_server_new(&session, &callbacks, NULL); @@ -9818,58 +10085,58 @@ void test_nghttp2_session_keep_closed_stream(void) { open_recv_stream(session, (int32_t)i * 2 + 1); } - CU_ASSERT(0 == session->num_closed_streams); + assert_size(0, ==, session->num_closed_streams); nghttp2_session_close_stream(session, 1, NGHTTP2_NO_ERROR); - CU_ASSERT(1 == session->num_closed_streams); - CU_ASSERT(1 == session->closed_stream_tail->stream_id); - CU_ASSERT(session->closed_stream_tail == session->closed_stream_head); + assert_size(1, ==, session->num_closed_streams); + assert_int32(1, ==, session->closed_stream_tail->stream_id); + assert_ptr_equal(session->closed_stream_tail, session->closed_stream_head); nghttp2_session_close_stream(session, 5, NGHTTP2_NO_ERROR); - CU_ASSERT(2 == session->num_closed_streams); - CU_ASSERT(5 == session->closed_stream_tail->stream_id); - CU_ASSERT(1 == session->closed_stream_head->stream_id); - CU_ASSERT(session->closed_stream_head == - session->closed_stream_tail->closed_prev); - CU_ASSERT(NULL == session->closed_stream_tail->closed_next); - CU_ASSERT(session->closed_stream_tail == - session->closed_stream_head->closed_next); - CU_ASSERT(NULL == session->closed_stream_head->closed_prev); + assert_size(2, ==, session->num_closed_streams); + assert_int32(5, ==, session->closed_stream_tail->stream_id); + assert_int32(1, ==, session->closed_stream_head->stream_id); + assert_ptr_equal(session->closed_stream_head, + session->closed_stream_tail->closed_prev); + assert_null(session->closed_stream_tail->closed_next); + assert_ptr_equal(session->closed_stream_tail, + session->closed_stream_head->closed_next); + assert_null(session->closed_stream_head->closed_prev); open_recv_stream(session, 11); nghttp2_session_adjust_closed_stream(session); - CU_ASSERT(1 == session->num_closed_streams); - CU_ASSERT(5 == session->closed_stream_tail->stream_id); - CU_ASSERT(session->closed_stream_tail == session->closed_stream_head); - CU_ASSERT(NULL == session->closed_stream_head->closed_prev); - CU_ASSERT(NULL == session->closed_stream_head->closed_next); + assert_size(1, ==, session->num_closed_streams); + assert_int32(5, ==, session->closed_stream_tail->stream_id); + assert_ptr_equal(session->closed_stream_tail, session->closed_stream_head); + assert_null(session->closed_stream_head->closed_prev); + assert_null(session->closed_stream_head->closed_next); open_recv_stream(session, 13); nghttp2_session_adjust_closed_stream(session); - CU_ASSERT(0 == session->num_closed_streams); - CU_ASSERT(NULL == session->closed_stream_tail); - CU_ASSERT(NULL == session->closed_stream_head); + assert_size(0, ==, session->num_closed_streams); + assert_null(session->closed_stream_tail); + assert_null(session->closed_stream_head); nghttp2_session_close_stream(session, 3, NGHTTP2_NO_ERROR); - CU_ASSERT(1 == session->num_closed_streams); - CU_ASSERT(3 == session->closed_stream_head->stream_id); + assert_size(1, ==, session->num_closed_streams); + assert_int32(3, ==, session->closed_stream_head->stream_id); /* server initiated stream is not counted to max concurrent limit */ open_sent_stream(session, 2); nghttp2_session_adjust_closed_stream(session); - CU_ASSERT(1 == session->num_closed_streams); - CU_ASSERT(3 == session->closed_stream_head->stream_id); + assert_size(1, ==, session->num_closed_streams); + assert_int32(3, ==, session->closed_stream_head->stream_id); nghttp2_session_close_stream(session, 2, NGHTTP2_NO_ERROR); - CU_ASSERT(1 == session->num_closed_streams); - CU_ASSERT(3 == session->closed_stream_head->stream_id); + assert_size(1, ==, session->num_closed_streams); + assert_int32(3, ==, session->closed_stream_head->stream_id); nghttp2_session_del(session); } @@ -9884,7 +10151,7 @@ void test_nghttp2_session_keep_idle_stream(void) { int32_t stream_id; memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_server_new(&session, &callbacks, NULL); @@ -9897,20 +10164,20 @@ void test_nghttp2_session_keep_idle_stream(void) { nghttp2_session_adjust_idle_stream(session); } - CU_ASSERT(NGHTTP2_MIN_IDLE_STREAMS == session->num_idle_streams); + assert_size(NGHTTP2_MIN_IDLE_STREAMS, ==, session->num_idle_streams); stream_id = (NGHTTP2_MIN_IDLE_STREAMS - 1) * 2 + 1; - CU_ASSERT(1 == session->idle_stream_head->stream_id); - CU_ASSERT(stream_id == session->idle_stream_tail->stream_id); + assert_int32(1, ==, session->idle_stream_head->stream_id); + assert_int32(stream_id, ==, session->idle_stream_tail->stream_id); stream_id += 2; open_recv_stream2(session, stream_id, NGHTTP2_STREAM_IDLE); nghttp2_session_adjust_idle_stream(session); - CU_ASSERT(NGHTTP2_MIN_IDLE_STREAMS == session->num_idle_streams); - CU_ASSERT(3 == session->idle_stream_head->stream_id); - CU_ASSERT(stream_id == session->idle_stream_tail->stream_id); + assert_size(NGHTTP2_MIN_IDLE_STREAMS, ==, session->num_idle_streams); + assert_int32(3, ==, session->idle_stream_head->stream_id); + assert_int32(stream_id, ==, session->idle_stream_tail->stream_id); nghttp2_session_del(session); } @@ -9922,7 +10189,7 @@ void test_nghttp2_session_detach_idle_stream(void) { nghttp2_stream *stream; memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_server_new(&session, &callbacks, NULL); @@ -9931,38 +10198,38 @@ void test_nghttp2_session_detach_idle_stream(void) { &pri_spec_default, NGHTTP2_STREAM_IDLE, NULL); } - CU_ASSERT(3 == session->num_idle_streams); + assert_size(3, ==, session->num_idle_streams); /* Detach middle stream */ stream = nghttp2_session_get_stream_raw(session, 2); - CU_ASSERT(session->idle_stream_head == stream->closed_prev); - CU_ASSERT(session->idle_stream_tail == stream->closed_next); - CU_ASSERT(stream == session->idle_stream_head->closed_next); - CU_ASSERT(stream == session->idle_stream_tail->closed_prev); + assert_ptr_equal(session->idle_stream_head, stream->closed_prev); + assert_ptr_equal(session->idle_stream_tail, stream->closed_next); + assert_ptr_equal(stream, session->idle_stream_head->closed_next); + assert_ptr_equal(stream, session->idle_stream_tail->closed_prev); nghttp2_session_detach_idle_stream(session, stream); - CU_ASSERT(2 == session->num_idle_streams); + assert_size(2, ==, session->num_idle_streams); - CU_ASSERT(NULL == stream->closed_prev); - CU_ASSERT(NULL == stream->closed_next); + assert_null(stream->closed_prev); + assert_null(stream->closed_next); - CU_ASSERT(session->idle_stream_head == - session->idle_stream_tail->closed_prev); - CU_ASSERT(session->idle_stream_tail == - session->idle_stream_head->closed_next); + assert_ptr_equal(session->idle_stream_head, + session->idle_stream_tail->closed_prev); + assert_ptr_equal(session->idle_stream_tail, + session->idle_stream_head->closed_next); /* Detach head stream */ stream = session->idle_stream_head; nghttp2_session_detach_idle_stream(session, stream); - CU_ASSERT(1 == session->num_idle_streams); + assert_size(1, ==, session->num_idle_streams); - CU_ASSERT(session->idle_stream_head == session->idle_stream_tail); - CU_ASSERT(NULL == session->idle_stream_head->closed_prev); - CU_ASSERT(NULL == session->idle_stream_head->closed_next); + assert_ptr_equal(session->idle_stream_head, session->idle_stream_tail); + assert_null(session->idle_stream_head->closed_prev); + assert_null(session->idle_stream_head->closed_next); /* Detach last stream */ @@ -9970,17 +10237,17 @@ void test_nghttp2_session_detach_idle_stream(void) { nghttp2_session_detach_idle_stream(session, stream); - CU_ASSERT(0 == session->num_idle_streams); + assert_size(0, ==, session->num_idle_streams); - CU_ASSERT(NULL == session->idle_stream_head); - CU_ASSERT(NULL == session->idle_stream_tail); + assert_null(session->idle_stream_head); + assert_null(session->idle_stream_tail); for (i = 4; i <= 5; ++i) { nghttp2_session_open_stream(session, i, NGHTTP2_STREAM_FLAG_NONE, &pri_spec_default, NGHTTP2_STREAM_IDLE, NULL); } - CU_ASSERT(2 == session->num_idle_streams); + assert_size(2, ==, session->num_idle_streams); /* Detach tail stream */ @@ -9988,11 +10255,11 @@ void test_nghttp2_session_detach_idle_stream(void) { nghttp2_session_detach_idle_stream(session, stream); - CU_ASSERT(1 == session->num_idle_streams); + assert_size(1, ==, session->num_idle_streams); - CU_ASSERT(session->idle_stream_head == session->idle_stream_tail); - CU_ASSERT(NULL == session->idle_stream_head->closed_prev); - CU_ASSERT(NULL == session->idle_stream_head->closed_next); + assert_ptr_equal(session->idle_stream_head, session->idle_stream_tail); + assert_null(session->idle_stream_head->closed_prev); + assert_null(session->idle_stream_head->closed_next); nghttp2_session_del(session); } @@ -10006,7 +10273,7 @@ void test_nghttp2_session_large_dep_tree(void) { int32_t stream_id; memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_server_new(&session, &callbacks, NULL); @@ -10018,8 +10285,8 @@ void test_nghttp2_session_large_dep_tree(void) { stream_id = 1; for (i = 0; i < 250; ++i, stream_id += 2) { stream = nghttp2_session_get_stream(session, stream_id); - CU_ASSERT(nghttp2_stream_dep_find_ancestor(stream, &session->root)); - CU_ASSERT(nghttp2_stream_in_dep_tree(stream)); + assert_true(nghttp2_stream_dep_find_ancestor(stream, &session->root)); + assert_true(nghttp2_stream_in_dep_tree(stream)); } nghttp2_session_del(session); @@ -10031,7 +10298,7 @@ void test_nghttp2_session_graceful_shutdown(void) { my_user_data ud; memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; callbacks.on_stream_close_callback = on_stream_close_callback; @@ -10043,44 +10310,46 @@ void test_nghttp2_session_graceful_shutdown(void) { open_recv_stream(session, 311); open_recv_stream(session, 319); - CU_ASSERT(0 == nghttp2_submit_shutdown_notice(session)); + assert_int(0, ==, nghttp2_submit_shutdown_notice(session)); ud.frame_send_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_send_cb_called); - CU_ASSERT((1u << 31) - 1 == session->local_last_stream_id); + assert_int(1, ==, ud.frame_send_cb_called); + assert_int32((1u << 31) - 1, ==, session->local_last_stream_id); - CU_ASSERT(0 == nghttp2_submit_goaway(session, NGHTTP2_FLAG_NONE, 311, - NGHTTP2_NO_ERROR, NULL, 0)); + assert_int(0, ==, + nghttp2_submit_goaway(session, NGHTTP2_FLAG_NONE, 311, + NGHTTP2_NO_ERROR, NULL, 0)); ud.frame_send_cb_called = 0; ud.stream_close_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_send_cb_called); - CU_ASSERT(311 == session->local_last_stream_id); - CU_ASSERT(1 == ud.stream_close_cb_called); + assert_int(1, ==, ud.frame_send_cb_called); + assert_int32(311, ==, session->local_last_stream_id); + assert_int(1, ==, ud.stream_close_cb_called); - CU_ASSERT(0 == - nghttp2_session_terminate_session2(session, 301, NGHTTP2_NO_ERROR)); + assert_int( + 0, ==, + nghttp2_session_terminate_session2(session, 301, NGHTTP2_NO_ERROR)); ud.frame_send_cb_called = 0; ud.stream_close_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_send_cb_called); - CU_ASSERT(301 == session->local_last_stream_id); - CU_ASSERT(2 == ud.stream_close_cb_called); + assert_int(1, ==, ud.frame_send_cb_called); + assert_int32(301, ==, session->local_last_stream_id); + assert_int(2, ==, ud.stream_close_cb_called); - CU_ASSERT(NULL != nghttp2_session_get_stream(session, 301)); - CU_ASSERT(NULL != nghttp2_session_get_stream(session, 302)); - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 309)); - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 311)); - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 319)); + assert_not_null(nghttp2_session_get_stream(session, 301)); + assert_not_null(nghttp2_session_get_stream(session, 302)); + assert_null(nghttp2_session_get_stream(session, 309)); + assert_null(nghttp2_session_get_stream(session, 311)); + assert_null(nghttp2_session_get_stream(session, 319)); nghttp2_session_del(session); } @@ -10095,7 +10364,7 @@ void test_nghttp2_session_on_header_temporal_failure(void) { nghttp2_nv nv[] = {MAKE_NV("alpha", "bravo"), MAKE_NV("charlie", "delta")}; nghttp2_nv *nva; size_t hdpos; - ssize_t rv; + nghttp2_ssize rv; nghttp2_frame frame; nghttp2_frame_hd hd; nghttp2_outbound_item *item; @@ -10134,18 +10403,18 @@ void test_nghttp2_session_on_header_temporal_failure(void) { nghttp2_frame_pack_frame_hd(&buf->pos[hdpos], &hd); ud.header_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_bufs_len(&bufs)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(1 == ud.header_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(1, ==, ud.header_cb_called); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(1 == item->frame.hd.stream_id); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_int32(1, ==, item->frame.hd.stream_id); /* Make sure no header decompression error occurred */ - CU_ASSERT(NGHTTP2_GOAWAY_NONE == session->goaway_flags); + assert_uint8(NGHTTP2_GOAWAY_NONE, ==, session->goaway_flags); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -10160,18 +10429,18 @@ void test_nghttp2_session_on_header_temporal_failure(void) { rv = pack_push_promise(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, 2, reqnv, ARRLEN(reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); ud.header_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(1 == ud.header_cb_called); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(1, ==, ud.header_cb_called); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(2 == item->frame.hd.stream_id); - CU_ASSERT(NGHTTP2_INTERNAL_ERROR == item->frame.rst_stream.error_code); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_int32(2, ==, item->frame.hd.stream_id); + assert_uint32(NGHTTP2_INTERNAL_ERROR, ==, item->frame.rst_stream.error_code); nghttp2_session_del(session); nghttp2_hd_deflate_free(&deflater); @@ -10181,7 +10450,7 @@ void test_nghttp2_session_on_header_temporal_failure(void) { void test_nghttp2_session_recv_client_magic(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - ssize_t rv; + nghttp2_ssize rv; nghttp2_frame ping_frame; uint8_t buf[16]; @@ -10193,21 +10462,23 @@ void test_nghttp2_session_recv_client_magic(void) { /* Check success case */ nghttp2_session_server_new(&session, &callbacks, NULL); - rv = nghttp2_session_mem_recv(session, (const uint8_t *)NGHTTP2_CLIENT_MAGIC, - NGHTTP2_CLIENT_MAGIC_LEN); + rv = nghttp2_session_mem_recv2(session, (const uint8_t *)NGHTTP2_CLIENT_MAGIC, + NGHTTP2_CLIENT_MAGIC_LEN); - CU_ASSERT(rv == NGHTTP2_CLIENT_MAGIC_LEN); - CU_ASSERT(NGHTTP2_IB_READ_FIRST_SETTINGS == session->iframe.state); + assert_ptrdiff(NGHTTP2_CLIENT_MAGIC_LEN, ==, rv); + assert_enum(nghttp2_inbound_state, NGHTTP2_IB_READ_FIRST_SETTINGS, ==, + session->iframe.state); /* Receiving PING is error because we want SETTINGS. */ nghttp2_frame_ping_init(&ping_frame.ping, NGHTTP2_FLAG_NONE, NULL); nghttp2_frame_pack_frame_hd(buf, &ping_frame.ping.hd); - rv = nghttp2_session_mem_recv(session, buf, NGHTTP2_FRAME_HDLEN); - CU_ASSERT(NGHTTP2_FRAME_HDLEN == rv); - CU_ASSERT(NGHTTP2_IB_IGN_ALL == session->iframe.state); - CU_ASSERT(0 == session->iframe.payloadleft); + rv = nghttp2_session_mem_recv2(session, buf, NGHTTP2_FRAME_HDLEN); + assert_ptrdiff(NGHTTP2_FRAME_HDLEN, ==, rv); + assert_enum(nghttp2_inbound_state, NGHTTP2_IB_IGN_ALL, ==, + session->iframe.state); + assert_size(0, ==, session->iframe.payloadleft); nghttp2_frame_ping_free(&ping_frame.ping); @@ -10217,16 +10488,17 @@ void test_nghttp2_session_recv_client_magic(void) { nghttp2_session_server_new(&session, &callbacks, NULL); /* Feed magic with one byte less */ - rv = nghttp2_session_mem_recv(session, (const uint8_t *)NGHTTP2_CLIENT_MAGIC, - NGHTTP2_CLIENT_MAGIC_LEN - 1); + rv = nghttp2_session_mem_recv2(session, (const uint8_t *)NGHTTP2_CLIENT_MAGIC, + NGHTTP2_CLIENT_MAGIC_LEN - 1); - CU_ASSERT(rv == NGHTTP2_CLIENT_MAGIC_LEN - 1); - CU_ASSERT(NGHTTP2_IB_READ_CLIENT_MAGIC == session->iframe.state); - CU_ASSERT(1 == session->iframe.payloadleft); + assert_ptrdiff(NGHTTP2_CLIENT_MAGIC_LEN - 1, ==, rv); + assert_enum(nghttp2_inbound_state, NGHTTP2_IB_READ_CLIENT_MAGIC, ==, + session->iframe.state); + assert_size(1, ==, session->iframe.payloadleft); - rv = nghttp2_session_mem_recv(session, (const uint8_t *)"\0", 1); + rv = nghttp2_session_mem_recv2(session, (const uint8_t *)"\0", 1); - CU_ASSERT(NGHTTP2_ERR_BAD_CLIENT_MAGIC == rv); + assert_ptrdiff(NGHTTP2_ERR_BAD_CLIENT_MAGIC, ==, rv); nghttp2_session_del(session); @@ -10238,7 +10510,7 @@ void test_nghttp2_session_delete_data_item(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; nghttp2_stream *a; - nghttp2_data_provider prd; + nghttp2_data_provider2 prd; memset(&callbacks, 0, sizeof(callbacks)); @@ -10251,8 +10523,8 @@ void test_nghttp2_session_delete_data_item(void) { prd.source.ptr = NULL; prd.read_callback = fail_data_source_read_callback; - CU_ASSERT(0 == nghttp2_submit_data(session, NGHTTP2_FLAG_NONE, 1, &prd)); - CU_ASSERT(0 == nghttp2_submit_data(session, NGHTTP2_FLAG_NONE, 3, &prd)); + assert_int(0, ==, nghttp2_submit_data2(session, NGHTTP2_FLAG_NONE, 1, &prd)); + assert_int(0, ==, nghttp2_submit_data2(session, NGHTTP2_FLAG_NONE, 3, &prd)); nghttp2_session_del(session); } @@ -10273,24 +10545,24 @@ void test_nghttp2_session_open_idle_stream(void) { nghttp2_frame_priority_init(&frame.priority, 1, &pri_spec); - CU_ASSERT(0 == nghttp2_session_on_priority_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_priority_received(session, &frame)); stream = nghttp2_session_get_stream_raw(session, 1); - CU_ASSERT(NGHTTP2_STREAM_IDLE == stream->state); - CU_ASSERT(NULL == stream->closed_prev); - CU_ASSERT(NULL == stream->closed_next); - CU_ASSERT(1 == session->num_idle_streams); - CU_ASSERT(session->idle_stream_head == stream); - CU_ASSERT(session->idle_stream_tail == stream); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_IDLE, ==, stream->state); + assert_null(stream->closed_prev); + assert_null(stream->closed_next); + assert_size(1, ==, session->num_idle_streams); + assert_ptr_equal(session->idle_stream_head, stream); + assert_ptr_equal(session->idle_stream_tail, stream); opened_stream = open_recv_stream2(session, 1, NGHTTP2_STREAM_OPENING); - CU_ASSERT(stream == opened_stream); - CU_ASSERT(NGHTTP2_STREAM_OPENING == stream->state); - CU_ASSERT(0 == session->num_idle_streams); - CU_ASSERT(NULL == session->idle_stream_head); - CU_ASSERT(NULL == session->idle_stream_tail); + assert_ptr_equal(stream, opened_stream); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENING, ==, stream->state); + assert_size(0, ==, session->num_idle_streams); + assert_null(session->idle_stream_head); + assert_null(session->idle_stream_tail); nghttp2_frame_priority_free(&frame.priority); @@ -10307,13 +10579,13 @@ void test_nghttp2_session_cancel_reserved_remote(void) { nghttp2_hd_deflater deflater; nghttp2_mem *mem; nghttp2_bufs bufs; - ssize_t rv; + nghttp2_ssize rv; mem = nghttp2_mem_default(); frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, NULL); @@ -10323,9 +10595,9 @@ void test_nghttp2_session_cancel_reserved_remote(void) { nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, 2, NGHTTP2_CANCEL); - CU_ASSERT(NGHTTP2_STREAM_CLOSING == stream->state); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_CLOSING, ==, stream->state); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); nvlen = ARRLEN(resnv); nghttp2_nv_array_copy(&nva, resnv, nvlen, mem); @@ -10334,19 +10606,19 @@ void test_nghttp2_session_cancel_reserved_remote(void) { NGHTTP2_HCAT_PUSH_RESPONSE, NULL, nva, nvlen); rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); /* stream is not dangling, so assign NULL */ stream = NULL; /* No RST_STREAM or GOAWAY is generated since stream should be in NGHTTP2_STREAM_CLOSING and push response should be ignored. */ - CU_ASSERT(0 == nghttp2_outbound_queue_size(&session->ob_reg)); + assert_size(0, ==, nghttp2_outbound_queue_size(&session->ob_reg)); /* Check that we can receive push response HEADERS while RST_STREAM is just queued. */ @@ -10359,14 +10631,14 @@ void test_nghttp2_session_cancel_reserved_remote(void) { frame.hd.stream_id = 4; rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); - CU_ASSERT(1 == nghttp2_outbound_queue_size(&session->ob_reg)); + assert_size(1, ==, nghttp2_outbound_queue_size(&session->ob_reg)); nghttp2_frame_headers_free(&frame.headers, mem); @@ -10385,15 +10657,15 @@ void test_nghttp2_session_reset_pending_headers(void) { my_user_data ud; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; callbacks.on_frame_not_send_callback = on_frame_not_send_callback; callbacks.on_stream_close_callback = on_stream_close_callback; nghttp2_session_client_new(&session, &callbacks, &ud); - stream_id = nghttp2_submit_request(session, NULL, NULL, 0, NULL, NULL); - CU_ASSERT(stream_id >= 1); + stream_id = nghttp2_submit_request2(session, NULL, NULL, 0, NULL, NULL); + assert_int32(1, <=, stream_id); nghttp2_submit_rst_stream(session, NGHTTP2_FLAG_NONE, stream_id, NGHTTP2_CANCEL); @@ -10402,13 +10674,13 @@ void test_nghttp2_session_reset_pending_headers(void) { /* RST_STREAM cancels pending HEADERS and is not actually sent. */ ud.frame_send_cb_called = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); - CU_ASSERT(0 == ud.frame_send_cb_called); + assert_int(0, ==, ud.frame_send_cb_called); stream = nghttp2_session_get_stream(session, stream_id); - CU_ASSERT(NULL == stream); + assert_null(stream); /* See HEADERS is not sent. on_stream_close is called just like transmission failure. */ @@ -10416,15 +10688,15 @@ void test_nghttp2_session_reset_pending_headers(void) { ud.frame_not_send_cb_called = 0; ud.stream_close_error_code = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_not_send_cb_called); - CU_ASSERT(NGHTTP2_HEADERS == ud.not_sent_frame_type); - CU_ASSERT(NGHTTP2_CANCEL == ud.stream_close_error_code); + assert_int(1, ==, ud.frame_not_send_cb_called); + assert_uint8(NGHTTP2_HEADERS, ==, ud.not_sent_frame_type); + assert_uint32(NGHTTP2_CANCEL, ==, ud.stream_close_error_code); stream = nghttp2_session_get_stream(session, stream_id); - CU_ASSERT(NULL == stream); + assert_null(stream); nghttp2_session_del(session); } @@ -10432,13 +10704,13 @@ void test_nghttp2_session_reset_pending_headers(void) { void test_nghttp2_session_send_data_callback(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; my_user_data ud; accumulator acc; nghttp2_frame_hd hd; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = accumulator_send_callback; + callbacks.send_callback2 = accumulator_send_callback; callbacks.send_data_callback = send_data_callback; data_prd.read_callback = no_copy_data_source_read_callback; @@ -10452,23 +10724,24 @@ void test_nghttp2_session_send_data_callback(void) { open_sent_stream(session, 1); - nghttp2_submit_data(session, NGHTTP2_FLAG_END_STREAM, 1, &data_prd); + nghttp2_submit_data2(session, NGHTTP2_FLAG_END_STREAM, 1, &data_prd); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); - CU_ASSERT((NGHTTP2_FRAME_HDLEN + NGHTTP2_DATA_PAYLOADLEN) * 2 == acc.length); + assert_size((NGHTTP2_FRAME_HDLEN + NGHTTP2_DATA_PAYLOADLEN) * 2, ==, + acc.length); nghttp2_frame_unpack_frame_hd(&hd, acc.buf); - CU_ASSERT(16384 == hd.length); - CU_ASSERT(NGHTTP2_DATA == hd.type); - CU_ASSERT(NGHTTP2_FLAG_NONE == hd.flags); + assert_size(16384, ==, hd.length); + assert_uint8(NGHTTP2_DATA, ==, hd.type); + assert_uint8(NGHTTP2_FLAG_NONE, ==, hd.flags); nghttp2_frame_unpack_frame_hd(&hd, acc.buf + NGHTTP2_FRAME_HDLEN + hd.length); - CU_ASSERT(16384 == hd.length); - CU_ASSERT(NGHTTP2_DATA == hd.type); - CU_ASSERT(NGHTTP2_FLAG_END_STREAM == hd.flags); + assert_size(16384, ==, hd.length); + assert_uint8(NGHTTP2_DATA, ==, hd.type); + assert_uint8(NGHTTP2_FLAG_END_STREAM, ==, hd.flags); nghttp2_session_del(session); } @@ -10479,7 +10752,7 @@ void test_nghttp2_session_on_begin_headers_temporal_failure(void) { my_user_data ud; nghttp2_bufs bufs; nghttp2_mem *mem; - ssize_t rv; + nghttp2_ssize rv; nghttp2_hd_deflater deflater; nghttp2_outbound_item *item; @@ -10492,25 +10765,25 @@ void test_nghttp2_session_on_begin_headers_temporal_failure(void) { temporal_failure_on_begin_headers_callback; callbacks.on_header_callback = on_header_callback; callbacks.on_frame_recv_callback = on_frame_recv_callback; - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_server_new(&session, &callbacks, &ud); rv = pack_headers(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, reqnv, ARRLEN(reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); ud.header_cb_called = 0; ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(0 == ud.header_cb_called); - CU_ASSERT(0 == ud.frame_recv_cb_called); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(0, ==, ud.header_cb_called); + assert_int(0, ==, ud.frame_recv_cb_called); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(1 == item->frame.hd.stream_id); - CU_ASSERT(NGHTTP2_INTERNAL_ERROR == item->frame.rst_stream.error_code); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_int32(1, ==, item->frame.hd.stream_id); + assert_uint32(NGHTTP2_INTERNAL_ERROR, ==, item->frame.rst_stream.error_code); nghttp2_session_del(session); nghttp2_hd_deflate_free(&deflater); @@ -10524,20 +10797,20 @@ void test_nghttp2_session_on_begin_headers_temporal_failure(void) { rv = pack_push_promise(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, 2, reqnv, ARRLEN(reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); ud.header_cb_called = 0; ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == rv); - CU_ASSERT(0 == ud.header_cb_called); - CU_ASSERT(0 == ud.frame_recv_cb_called); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, rv); + assert_int(0, ==, ud.header_cb_called); + assert_int(0, ==, ud.frame_recv_cb_called); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(2 == item->frame.hd.stream_id); - CU_ASSERT(NGHTTP2_INTERNAL_ERROR == item->frame.rst_stream.error_code); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_int32(2, ==, item->frame.hd.stream_id); + assert_uint32(NGHTTP2_INTERNAL_ERROR, ==, item->frame.rst_stream.error_code); nghttp2_session_del(session); nghttp2_hd_deflate_free(&deflater); @@ -10547,38 +10820,38 @@ void test_nghttp2_session_on_begin_headers_temporal_failure(void) { void test_nghttp2_session_defer_then_close(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - nghttp2_data_provider prd; + nghttp2_data_provider2 prd; int rv; const uint8_t *datap; - ssize_t datalen; + nghttp2_ssize datalen; nghttp2_frame frame; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, NULL); prd.read_callback = defer_data_source_read_callback; - rv = nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), &prd, NULL); - CU_ASSERT(rv > 0); + rv = nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), &prd, NULL); + assert_ptrdiff(0, <, rv); /* This sends HEADERS */ - datalen = nghttp2_session_mem_send(session, &datap); + datalen = nghttp2_session_mem_send2(session, &datap); - CU_ASSERT(datalen > 0); + assert_ptrdiff(0, <, datalen); /* This makes DATA item deferred */ - datalen = nghttp2_session_mem_send(session, &datap); + datalen = nghttp2_session_mem_send2(session, &datap); - CU_ASSERT(datalen == 0); + assert_ptrdiff(0, ==, datalen); nghttp2_frame_rst_stream_init(&frame.rst_stream, 1, NGHTTP2_CANCEL); /* Assertion failure; GH-264 */ rv = nghttp2_session_on_rst_stream_received(session, &frame); - CU_ASSERT(rv == 0); + assert_int(0, ==, rv); nghttp2_session_del(session); } @@ -10587,7 +10860,7 @@ static int submit_response_on_stream_close(nghttp2_session *session, int32_t stream_id, uint32_t error_code, void *user_data) { - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; (void)error_code; (void)user_data; @@ -10596,12 +10869,14 @@ static int submit_response_on_stream_close(nghttp2_session *session, // Attempt to submit response or data to the stream being closed switch (stream_id) { case 1: - CU_ASSERT(0 == nghttp2_submit_response(session, stream_id, resnv, - ARRLEN(resnv), &data_prd)); + assert_int(0, ==, + nghttp2_submit_response2(session, stream_id, resnv, + ARRLEN(resnv), &data_prd)); break; case 3: - CU_ASSERT(0 == nghttp2_submit_data(session, NGHTTP2_FLAG_NONE, stream_id, - &data_prd)); + assert_int( + 0, ==, + nghttp2_submit_data2(session, NGHTTP2_FLAG_NONE, stream_id, &data_prd)); break; } @@ -10614,7 +10889,7 @@ void test_nghttp2_session_detach_item_from_closed_stream(void) { memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_stream_close_callback = submit_response_on_stream_close; nghttp2_session_server_new(&session, &callbacks, NULL); @@ -10625,7 +10900,7 @@ void test_nghttp2_session_detach_item_from_closed_stream(void) { nghttp2_session_close_stream(session, 1, NGHTTP2_NO_ERROR); nghttp2_session_close_stream(session, 3, NGHTTP2_NO_ERROR); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_session_del(session); } @@ -10655,13 +10930,14 @@ void test_nghttp2_session_flooding(void) { buf = &bufs.head->buf; for (i = 0; i < NGHTTP2_DEFAULT_MAX_OBQ_FLOOD_ITEM; ++i) { - CU_ASSERT( - (ssize_t)nghttp2_buf_len(buf) == - nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf))); + assert_ptrdiff( + (nghttp2_ssize)nghttp2_buf_len(buf), ==, + nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf))); } - CU_ASSERT(NGHTTP2_ERR_FLOODED == - nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf))); + assert_ptrdiff( + NGHTTP2_ERR_FLOODED, ==, + nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf))); nghttp2_session_del(session); @@ -10677,13 +10953,14 @@ void test_nghttp2_session_flooding(void) { buf = &bufs.head->buf; for (i = 0; i < NGHTTP2_DEFAULT_MAX_OBQ_FLOOD_ITEM; ++i) { - CU_ASSERT( - (ssize_t)nghttp2_buf_len(buf) == - nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf))); + assert_ptrdiff( + (nghttp2_ssize)nghttp2_buf_len(buf), ==, + nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf))); } - CU_ASSERT(NGHTTP2_ERR_FLOODED == - nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf))); + assert_ptrdiff( + NGHTTP2_ERR_FLOODED, ==, + nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf))); nghttp2_session_del(session); nghttp2_bufs_free(&bufs); @@ -10708,22 +10985,22 @@ void test_nghttp2_session_change_stream_priority(void) { rv = nghttp2_session_change_stream_priority(session, 2, &pri_spec); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); - CU_ASSERT(stream1 == stream2->dep_prev); - CU_ASSERT(256 == stream2->weight); + assert_ptr_equal(stream1, stream2->dep_prev); + assert_int32(256, ==, stream2->weight); /* Cannot change stream which does not exist */ rv = nghttp2_session_change_stream_priority(session, 5, &pri_spec); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); /* It is an error to depend on itself */ rv = nghttp2_session_change_stream_priority(session, 1, &pri_spec); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); /* It is an error to change priority of root stream (0) */ rv = nghttp2_session_change_stream_priority(session, 0, &pri_spec); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); /* Depends on the non-existing idle stream. This creates that idle stream. */ @@ -10731,14 +11008,14 @@ void test_nghttp2_session_change_stream_priority(void) { rv = nghttp2_session_change_stream_priority(session, 2, &pri_spec); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); stream5 = nghttp2_session_get_stream_raw(session, 5); - CU_ASSERT(NULL != stream5); - CU_ASSERT(&session->root == stream5->dep_prev); - CU_ASSERT(stream5 == stream2->dep_prev); - CU_ASSERT(9 == stream2->weight); + assert_not_null(stream5); + assert_ptr_equal(&session->root, stream5->dep_prev); + assert_ptr_equal(stream5, stream2->dep_prev); + assert_int32(9, ==, stream2->weight); nghttp2_session_del(session); @@ -10751,14 +11028,14 @@ void test_nghttp2_session_change_stream_priority(void) { rv = nghttp2_session_change_stream_priority(session, 1, &pri_spec); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); stream5 = nghttp2_session_get_stream_raw(session, 5); - CU_ASSERT(NULL != stream5); - CU_ASSERT(&session->root == stream5->dep_prev); - CU_ASSERT(stream5 == stream1->dep_prev); - CU_ASSERT(9 == stream1->weight); + assert_not_null(stream5); + assert_ptr_equal(&session->root, stream5->dep_prev); + assert_ptr_equal(stream5, stream1->dep_prev); + assert_int32(9, ==, stream1->weight); nghttp2_session_del(session); } @@ -10768,7 +11045,7 @@ void test_nghttp2_session_change_extpri_stream_priority(void) { nghttp2_session_callbacks callbacks; nghttp2_bufs bufs; nghttp2_buf *buf; - ssize_t rv; + nghttp2_ssize rv; nghttp2_option *option; nghttp2_extension frame; nghttp2_ext_priority_update priority_update; @@ -10796,19 +11073,19 @@ void test_nghttp2_session_change_extpri_stream_priority(void) { rv = nghttp2_session_change_extpri_stream_priority( session, 1, &extpri, /* ignore_client_signal = */ 0); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(NGHTTP2_EXTPRI_URGENCY_LOW == - nghttp2_extpri_uint8_urgency(stream->extpri)); - CU_ASSERT(1 == nghttp2_extpri_uint8_inc(stream->extpri)); + assert_uint32(NGHTTP2_EXTPRI_URGENCY_LOW, ==, + nghttp2_extpri_uint8_urgency(stream->extpri)); + assert_true(nghttp2_extpri_uint8_inc(stream->extpri)); rv = nghttp2_session_get_extpri_stream_priority(session, &nextpri, 1); - CU_ASSERT(0 == rv); - CU_ASSERT(NGHTTP2_EXTPRI_URGENCY_LOW == nextpri.urgency); - CU_ASSERT(1 == nextpri.inc); + assert_ptrdiff(0, ==, rv); + assert_uint32(NGHTTP2_EXTPRI_URGENCY_LOW, ==, nextpri.urgency); + assert_true(nextpri.inc); /* Client can still update stream priority. */ frame.payload = &priority_update; @@ -10817,30 +11094,30 @@ void test_nghttp2_session_change_extpri_stream_priority(void) { nghttp2_frame_pack_priority_update(&bufs, &frame); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); - CU_ASSERT(2 == stream->extpri); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_uint8(2, ==, stream->extpri); /* Start to ignore client priority signal for this stream. */ rv = nghttp2_session_change_extpri_stream_priority( session, 1, &extpri, /* ignore_client_signal = */ 1); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(NGHTTP2_EXTPRI_URGENCY_LOW == - nghttp2_extpri_uint8_urgency(stream->extpri)); - CU_ASSERT(1 == nghttp2_extpri_uint8_inc(stream->extpri)); + assert_uint32(NGHTTP2_EXTPRI_URGENCY_LOW, ==, + nghttp2_extpri_uint8_urgency(stream->extpri)); + assert_true(nghttp2_extpri_uint8_inc(stream->extpri)); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); - CU_ASSERT(NGHTTP2_EXTPRI_URGENCY_LOW == - nghttp2_extpri_uint8_urgency(stream->extpri)); - CU_ASSERT(1 == nghttp2_extpri_uint8_inc(stream->extpri)); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_uint32(NGHTTP2_EXTPRI_URGENCY_LOW, ==, + nghttp2_extpri_uint8_urgency(stream->extpri)); + assert_true(nghttp2_extpri_uint8_inc(stream->extpri)); nghttp2_session_del(session); nghttp2_option_del(option); @@ -10856,7 +11133,7 @@ void test_nghttp2_session_create_idle_stream(void) { int i; memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_server_new(&session, &callbacks, NULL); @@ -10866,14 +11143,14 @@ void test_nghttp2_session_create_idle_stream(void) { rv = nghttp2_session_create_idle_stream(session, 4, &pri_spec); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); stream4 = nghttp2_session_get_stream_raw(session, 4); - CU_ASSERT(4 == stream4->stream_id); - CU_ASSERT(111 == stream4->weight); - CU_ASSERT(stream2 == stream4->dep_prev); - CU_ASSERT(stream4 == stream2->dep_next); + assert_int32(4, ==, stream4->stream_id); + assert_int32(111, ==, stream4->weight); + assert_ptr_equal(stream2, stream4->dep_prev); + assert_ptr_equal(stream4, stream2->dep_next); /* If pri_spec->stream_id does not exist, and it is idle stream, it is created too */ @@ -10881,33 +11158,33 @@ void test_nghttp2_session_create_idle_stream(void) { rv = nghttp2_session_create_idle_stream(session, 8, &pri_spec); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); stream8 = nghttp2_session_get_stream_raw(session, 8); stream10 = nghttp2_session_get_stream_raw(session, 10); - CU_ASSERT(8 == stream8->stream_id); - CU_ASSERT(109 == stream8->weight); - CU_ASSERT(10 == stream10->stream_id); - CU_ASSERT(16 == stream10->weight); - CU_ASSERT(stream10 == stream8->dep_prev); - CU_ASSERT(&session->root == stream10->dep_prev); + assert_int32(8, ==, stream8->stream_id); + assert_int32(109, ==, stream8->weight); + assert_int32(10, ==, stream10->stream_id); + assert_int32(16, ==, stream10->weight); + assert_ptr_equal(stream10, stream8->dep_prev); + assert_ptr_equal(&session->root, stream10->dep_prev); /* It is an error to attempt to create already existing idle stream */ rv = nghttp2_session_create_idle_stream(session, 4, &pri_spec); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); /* It is an error to depend on itself */ pri_spec.stream_id = 6; rv = nghttp2_session_create_idle_stream(session, 6, &pri_spec); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); /* It is an error to create root stream (0) as idle stream */ rv = nghttp2_session_create_idle_stream(session, 0, &pri_spec); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); /* It is an error to create non-idle stream */ session->last_sent_stream_id = 20; @@ -10915,7 +11192,7 @@ void test_nghttp2_session_create_idle_stream(void) { rv = nghttp2_session_create_idle_stream(session, 18, &pri_spec); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); nghttp2_session_del(session); @@ -10926,17 +11203,17 @@ void test_nghttp2_session_create_idle_stream(void) { rv = nghttp2_session_create_idle_stream(session, 2, &pri_spec); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); stream4 = nghttp2_session_get_stream_raw(session, 4); stream2 = nghttp2_session_get_stream_raw(session, 2); - CU_ASSERT(NULL != stream4); - CU_ASSERT(NULL != stream2); - CU_ASSERT(&session->root == stream4->dep_prev); - CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == stream4->weight); - CU_ASSERT(stream4 == stream2->dep_prev); - CU_ASSERT(99 == stream2->weight); + assert_not_null(stream4); + assert_not_null(stream2); + assert_ptr_equal(&session->root, stream4->dep_prev); + assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, stream4->weight); + assert_ptr_equal(stream4, stream2->dep_prev); + assert_int32(99, ==, stream2->weight); nghttp2_session_del(session); @@ -10950,19 +11227,19 @@ void test_nghttp2_session_create_idle_stream(void) { for (i = 0; i < 100; ++i) { rv = nghttp2_session_create_idle_stream(session, i * 2 + 1, &pri_spec); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); nghttp2_priority_spec_init(&pri_spec, i * 2 + 1, 16, 0); } - CU_ASSERT(100 == session->num_idle_streams); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(30 == session->num_idle_streams); - CU_ASSERT(141 == session->idle_stream_head->stream_id); + assert_size(100, ==, session->num_idle_streams); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(30, ==, session->num_idle_streams); + assert_int32(141, ==, session->idle_stream_head->stream_id); nghttp2_session_del(session); - /* Check that idle stream is reduced when nghttp2_session_mem_recv() is + /* Check that idle stream is reduced when nghttp2_session_mem_recv2() is called. */ nghttp2_session_client_new(&session, &callbacks, NULL); @@ -10972,15 +11249,15 @@ void test_nghttp2_session_create_idle_stream(void) { for (i = 0; i < 100; ++i) { rv = nghttp2_session_create_idle_stream(session, i * 2 + 1, &pri_spec); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); nghttp2_priority_spec_init(&pri_spec, i * 2 + 1, 16, 0); } - CU_ASSERT(100 == session->num_idle_streams); - CU_ASSERT(0 == nghttp2_session_mem_recv(session, NULL, 0)); - CU_ASSERT(30 == session->num_idle_streams); - CU_ASSERT(141 == session->idle_stream_head->stream_id); + assert_size(100, ==, session->num_idle_streams); + assert_ptrdiff(0, ==, nghttp2_session_mem_recv2(session, NULL, 0)); + assert_size(30, ==, session->num_idle_streams); + assert_int32(141, ==, session->idle_stream_head->stream_id); nghttp2_session_del(session); } @@ -11003,7 +11280,7 @@ void test_nghttp2_session_repeated_priority_change(void) { nghttp2_priority_spec_init(&pri_spec, 0, 16, 0); nghttp2_frame_priority_init(&frame.priority, 1, &pri_spec); - CU_ASSERT(0 == nghttp2_session_on_priority_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_priority_received(session, &frame)); nghttp2_frame_priority_free(&frame.priority); @@ -11014,24 +11291,24 @@ void test_nghttp2_session_repeated_priority_change(void) { nghttp2_priority_spec_init(&pri_spec, stream_id, 16, 0); nghttp2_frame_priority_init(&frame.priority, 1, &pri_spec); - CU_ASSERT(0 == nghttp2_session_on_priority_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_priority_received(session, &frame)); nghttp2_frame_priority_free(&frame.priority); } - CU_ASSERT(20 == session->num_idle_streams); - CU_ASSERT(1 == session->idle_stream_head->stream_id); + assert_size(20, ==, session->num_idle_streams); + assert_int32(1, ==, session->idle_stream_head->stream_id); /* 1 -> last_stream_id */ nghttp2_priority_spec_init(&pri_spec, last_stream_id, 16, 0); nghttp2_frame_priority_init(&frame.priority, 1, &pri_spec); - CU_ASSERT(0 == nghttp2_session_on_priority_received(session, &frame)); + assert_int(0, ==, nghttp2_session_on_priority_received(session, &frame)); nghttp2_frame_priority_free(&frame.priority); - CU_ASSERT(20 == session->num_idle_streams); - CU_ASSERT(3 == session->idle_stream_head->stream_id); + assert_size(20, ==, session->num_idle_streams); + assert_int32(3, ==, session->idle_stream_head->stream_id); nghttp2_session_del(session); } @@ -11045,7 +11322,7 @@ void test_nghttp2_session_repeated_priority_submission(void) { memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, NULL); @@ -11054,8 +11331,8 @@ void test_nghttp2_session_repeated_priority_submission(void) { /* 1 -> 0 */ nghttp2_priority_spec_init(&pri_spec, 0, 16, 0); - CU_ASSERT(0 == - nghttp2_submit_priority(session, NGHTTP2_FLAG_NONE, 1, &pri_spec)); + assert_int(0, ==, + nghttp2_submit_priority(session, NGHTTP2_FLAG_NONE, 1, &pri_spec)); last_stream_id = (int32_t)(max_streams * 2 + 1); @@ -11063,23 +11340,24 @@ void test_nghttp2_session_repeated_priority_submission(void) { /* 1 -> stream_id */ nghttp2_priority_spec_init(&pri_spec, stream_id, 16, 0); - CU_ASSERT( - 0 == nghttp2_submit_priority(session, NGHTTP2_FLAG_NONE, 1, &pri_spec)); + assert_int( + 0, ==, + nghttp2_submit_priority(session, NGHTTP2_FLAG_NONE, 1, &pri_spec)); } - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(max_streams == session->num_idle_streams); - CU_ASSERT(1 == session->idle_stream_head->stream_id); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(max_streams, ==, session->num_idle_streams); + assert_int32(1, ==, session->idle_stream_head->stream_id); /* 1 -> last_stream_id */ nghttp2_priority_spec_init(&pri_spec, last_stream_id, 16, 0); - CU_ASSERT(0 == - nghttp2_submit_priority(session, NGHTTP2_FLAG_NONE, 1, &pri_spec)); + assert_int(0, ==, + nghttp2_submit_priority(session, NGHTTP2_FLAG_NONE, 1, &pri_spec)); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(max_streams == session->num_idle_streams); - CU_ASSERT(3 == session->idle_stream_head->stream_id); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size(max_streams, ==, session->num_idle_streams); + assert_int32(3, ==, session->idle_stream_head->stream_id); nghttp2_session_del(session); } @@ -11091,117 +11369,129 @@ void test_nghttp2_session_set_local_window_size(void) { nghttp2_stream *stream; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, NULL); stream = open_sent_stream(session, 1); stream->recv_window_size = 4096; - CU_ASSERT(0 == nghttp2_session_set_local_window_size( - session, NGHTTP2_FLAG_NONE, 1, 65536)); - CU_ASSERT(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1 == - stream->local_window_size); - CU_ASSERT(4096 == stream->recv_window_size); - CU_ASSERT(65536 - 4096 == - nghttp2_session_get_stream_local_window_size(session, 1)); + assert_int(0, ==, + nghttp2_session_set_local_window_size(session, NGHTTP2_FLAG_NONE, + 1, 65536)); + assert_int32(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1, ==, + stream->local_window_size); + assert_int32(4096, ==, stream->recv_window_size); + assert_int32(65536 - 4096, ==, + nghttp2_session_get_stream_local_window_size(session, 1)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); - CU_ASSERT(1 == item->frame.window_update.hd.stream_id); - CU_ASSERT(1 == item->frame.window_update.window_size_increment); + assert_uint8(NGHTTP2_WINDOW_UPDATE, ==, item->frame.hd.type); + assert_int32(1, ==, item->frame.window_update.hd.stream_id); + assert_int32(1, ==, item->frame.window_update.window_size_increment); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); /* Go decrement part */ - CU_ASSERT(0 == nghttp2_session_set_local_window_size( - session, NGHTTP2_FLAG_NONE, 1, 32768)); - CU_ASSERT(32768 == stream->local_window_size); - CU_ASSERT(-28672 == stream->recv_window_size); - CU_ASSERT(32768 == stream->recv_reduction); - CU_ASSERT(65536 - 4096 == - nghttp2_session_get_stream_local_window_size(session, 1)); + assert_int(0, ==, + nghttp2_session_set_local_window_size(session, NGHTTP2_FLAG_NONE, + 1, 32768)); + assert_int32(32768, ==, stream->local_window_size); + assert_int32(-28672, ==, stream->recv_window_size); + assert_int32(32768, ==, stream->recv_reduction); + assert_int32(65536 - 4096, ==, + nghttp2_session_get_stream_local_window_size(session, 1)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(item == NULL); + assert_null(item); /* Increase local window size */ - CU_ASSERT(0 == nghttp2_session_set_local_window_size( - session, NGHTTP2_FLAG_NONE, 1, 49152)); - CU_ASSERT(49152 == stream->local_window_size); - CU_ASSERT(-12288 == stream->recv_window_size); - CU_ASSERT(16384 == stream->recv_reduction); - CU_ASSERT(65536 - 4096 == - nghttp2_session_get_stream_local_window_size(session, 1)); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_int(0, ==, + nghttp2_session_set_local_window_size(session, NGHTTP2_FLAG_NONE, + 1, 49152)); + assert_int32(49152, ==, stream->local_window_size); + assert_int32(-12288, ==, stream->recv_window_size); + assert_int32(16384, ==, stream->recv_reduction); + assert_int32(65536 - 4096, ==, + nghttp2_session_get_stream_local_window_size(session, 1)); + assert_null(nghttp2_session_get_next_ob_item(session)); /* Increase local window again */ - CU_ASSERT(0 == nghttp2_session_set_local_window_size( - session, NGHTTP2_FLAG_NONE, 1, 65537)); - CU_ASSERT(65537 == stream->local_window_size); - CU_ASSERT(4096 == stream->recv_window_size); - CU_ASSERT(0 == stream->recv_reduction); - CU_ASSERT(65537 - 4096 == - nghttp2_session_get_stream_local_window_size(session, 1)); + assert_int(0, ==, + nghttp2_session_set_local_window_size(session, NGHTTP2_FLAG_NONE, + 1, 65537)); + assert_int32(65537, ==, stream->local_window_size); + assert_int32(4096, ==, stream->recv_window_size); + assert_int32(0, ==, stream->recv_reduction); + assert_int32(65537 - 4096, ==, + nghttp2_session_get_stream_local_window_size(session, 1)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(1 == item->frame.window_update.window_size_increment); + assert_int32(1, ==, item->frame.window_update.window_size_increment); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); /* Check connection-level flow control */ session->recv_window_size = 4096; - CU_ASSERT(0 == nghttp2_session_set_local_window_size( - session, NGHTTP2_FLAG_NONE, 0, 65536)); - CU_ASSERT(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1 == - session->local_window_size); - CU_ASSERT(4096 == session->recv_window_size); - CU_ASSERT(65536 - 4096 == nghttp2_session_get_local_window_size(session)); + assert_int(0, ==, + nghttp2_session_set_local_window_size(session, NGHTTP2_FLAG_NONE, + 0, 65536)); + assert_int32(NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE + 1, ==, + session->local_window_size); + assert_int32(4096, ==, session->recv_window_size); + assert_int32(65536 - 4096, ==, + nghttp2_session_get_local_window_size(session)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); - CU_ASSERT(0 == item->frame.window_update.hd.stream_id); - CU_ASSERT(1 == item->frame.window_update.window_size_increment); + assert_uint8(NGHTTP2_WINDOW_UPDATE, ==, item->frame.hd.type); + assert_int32(0, ==, item->frame.window_update.hd.stream_id); + assert_int32(1, ==, item->frame.window_update.window_size_increment); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); /* Go decrement part */ - CU_ASSERT(0 == nghttp2_session_set_local_window_size( - session, NGHTTP2_FLAG_NONE, 0, 32768)); - CU_ASSERT(32768 == session->local_window_size); - CU_ASSERT(-28672 == session->recv_window_size); - CU_ASSERT(32768 == session->recv_reduction); - CU_ASSERT(65536 - 4096 == nghttp2_session_get_local_window_size(session)); + assert_int(0, ==, + nghttp2_session_set_local_window_size(session, NGHTTP2_FLAG_NONE, + 0, 32768)); + assert_int32(32768, ==, session->local_window_size); + assert_int32(-28672, ==, session->recv_window_size); + assert_int32(32768, ==, session->recv_reduction); + assert_int32(65536 - 4096, ==, + nghttp2_session_get_local_window_size(session)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(item == NULL); + assert_null(item); /* Increase local window size */ - CU_ASSERT(0 == nghttp2_session_set_local_window_size( - session, NGHTTP2_FLAG_NONE, 0, 49152)); - CU_ASSERT(49152 == session->local_window_size); - CU_ASSERT(-12288 == session->recv_window_size); - CU_ASSERT(16384 == session->recv_reduction); - CU_ASSERT(65536 - 4096 == nghttp2_session_get_local_window_size(session)); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_int(0, ==, + nghttp2_session_set_local_window_size(session, NGHTTP2_FLAG_NONE, + 0, 49152)); + assert_int32(49152, ==, session->local_window_size); + assert_int32(-12288, ==, session->recv_window_size); + assert_int32(16384, ==, session->recv_reduction); + assert_int32(65536 - 4096, ==, + nghttp2_session_get_local_window_size(session)); + assert_null(nghttp2_session_get_next_ob_item(session)); /* Increase local window again */ - CU_ASSERT(0 == nghttp2_session_set_local_window_size( - session, NGHTTP2_FLAG_NONE, 0, 65537)); - CU_ASSERT(65537 == session->local_window_size); - CU_ASSERT(4096 == session->recv_window_size); - CU_ASSERT(0 == session->recv_reduction); - CU_ASSERT(65537 - 4096 == nghttp2_session_get_local_window_size(session)); + assert_int(0, ==, + nghttp2_session_set_local_window_size(session, NGHTTP2_FLAG_NONE, + 0, 65537)); + assert_int32(65537, ==, session->local_window_size); + assert_int32(4096, ==, session->recv_window_size); + assert_int32(0, ==, session->recv_reduction); + assert_int32(65537 - 4096, ==, + nghttp2_session_get_local_window_size(session)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(1 == item->frame.window_update.window_size_increment); + assert_int32(1, ==, item->frame.window_update.window_size_increment); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_session_del(session); @@ -11211,25 +11501,26 @@ void test_nghttp2_session_set_local_window_size(void) { stream = open_sent_stream(session, 1); stream->recv_window_size = NGHTTP2_INITIAL_WINDOW_SIZE; - CU_ASSERT(0 == nghttp2_session_set_local_window_size( - session, NGHTTP2_FLAG_NONE, 1, 0)); - CU_ASSERT(0 == stream->recv_window_size); - CU_ASSERT(0 == nghttp2_session_get_stream_local_window_size(session, 1)); + assert_int( + 0, ==, + nghttp2_session_set_local_window_size(session, NGHTTP2_FLAG_NONE, 1, 0)); + assert_int32(0, ==, stream->recv_window_size); + assert_int32(0, ==, nghttp2_session_get_stream_local_window_size(session, 1)); /* This should submit WINDOW_UPDATE frame because stream-level receiving window is now full. */ - CU_ASSERT(0 == - nghttp2_session_set_local_window_size(session, NGHTTP2_FLAG_NONE, 1, - NGHTTP2_INITIAL_WINDOW_SIZE)); - CU_ASSERT(0 == stream->recv_window_size); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE == - nghttp2_session_get_stream_local_window_size(session, 1)); + assert_int(0, ==, + nghttp2_session_set_local_window_size( + session, NGHTTP2_FLAG_NONE, 1, NGHTTP2_INITIAL_WINDOW_SIZE)); + assert_int32(0, ==, stream->recv_window_size); + assert_int32(NGHTTP2_INITIAL_WINDOW_SIZE, ==, + nghttp2_session_get_stream_local_window_size(session, 1)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); - CU_ASSERT(1 == item->frame.hd.stream_id); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE == - item->frame.window_update.window_size_increment); + assert_uint8(NGHTTP2_WINDOW_UPDATE, ==, item->frame.hd.type); + assert_int32(1, ==, item->frame.hd.stream_id); + assert_int32(NGHTTP2_INITIAL_WINDOW_SIZE, ==, + item->frame.window_update.window_size_increment); nghttp2_session_del(session); @@ -11239,25 +11530,26 @@ void test_nghttp2_session_set_local_window_size(void) { nghttp2_session_client_new(&session, &callbacks, NULL); session->recv_window_size = NGHTTP2_INITIAL_WINDOW_SIZE; - CU_ASSERT(0 == nghttp2_session_set_local_window_size( - session, NGHTTP2_FLAG_NONE, 0, 0)); - CU_ASSERT(0 == session->recv_window_size); - CU_ASSERT(0 == nghttp2_session_get_local_window_size(session)); + assert_int( + 0, ==, + nghttp2_session_set_local_window_size(session, NGHTTP2_FLAG_NONE, 0, 0)); + assert_int32(0, ==, session->recv_window_size); + assert_int32(0, ==, nghttp2_session_get_local_window_size(session)); /* This should submit WINDOW_UPDATE frame because connection-level receiving window is now full. */ - CU_ASSERT(0 == - nghttp2_session_set_local_window_size(session, NGHTTP2_FLAG_NONE, 0, - NGHTTP2_INITIAL_WINDOW_SIZE)); - CU_ASSERT(0 == session->recv_window_size); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE == - nghttp2_session_get_local_window_size(session)); + assert_int(0, ==, + nghttp2_session_set_local_window_size( + session, NGHTTP2_FLAG_NONE, 0, NGHTTP2_INITIAL_WINDOW_SIZE)); + assert_int32(0, ==, session->recv_window_size); + assert_int32(NGHTTP2_INITIAL_WINDOW_SIZE, ==, + nghttp2_session_get_local_window_size(session)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type); - CU_ASSERT(0 == item->frame.hd.stream_id); - CU_ASSERT(NGHTTP2_INITIAL_WINDOW_SIZE == - item->frame.window_update.window_size_increment); + assert_uint8(NGHTTP2_WINDOW_UPDATE, ==, item->frame.hd.type); + assert_int32(0, ==, item->frame.hd.stream_id); + assert_int32(NGHTTP2_INITIAL_WINDOW_SIZE, ==, + item->frame.window_update.window_size_increment); nghttp2_session_del(session); } @@ -11268,7 +11560,7 @@ void test_nghttp2_session_cancel_from_before_frame_send(void) { nghttp2_session_callbacks callbacks; my_user_data ud; nghttp2_settings_entry iv; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; int32_t stream_id; nghttp2_stream *stream; @@ -11276,7 +11568,7 @@ void test_nghttp2_session_cancel_from_before_frame_send(void) { callbacks.before_frame_send_callback = cancel_before_frame_send_callback; callbacks.on_frame_not_send_callback = on_frame_not_send_callback; - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, &ud); @@ -11285,7 +11577,7 @@ void test_nghttp2_session_cancel_from_before_frame_send(void) { rv = nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, &iv, 1); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); ud.frame_send_cb_called = 0; ud.before_frame_send_cb_called = 0; @@ -11293,18 +11585,18 @@ void test_nghttp2_session_cancel_from_before_frame_send(void) { rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); - CU_ASSERT(0 == ud.frame_send_cb_called); - CU_ASSERT(1 == ud.before_frame_send_cb_called); - CU_ASSERT(1 == ud.frame_not_send_cb_called); + assert_int(0, ==, rv); + assert_int(0, ==, ud.frame_send_cb_called); + assert_int(1, ==, ud.before_frame_send_cb_called); + assert_int(1, ==, ud.frame_not_send_cb_called); data_prd.source.ptr = NULL; data_prd.read_callback = temporal_failure_data_source_read_callback; - stream_id = nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), - &data_prd, NULL); + stream_id = nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), + &data_prd, NULL); - CU_ASSERT(stream_id > 0); + assert_int32(0, <, stream_id); ud.frame_send_cb_called = 0; ud.before_frame_send_cb_called = 0; @@ -11312,14 +11604,14 @@ void test_nghttp2_session_cancel_from_before_frame_send(void) { rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); - CU_ASSERT(0 == ud.frame_send_cb_called); - CU_ASSERT(1 == ud.before_frame_send_cb_called); - CU_ASSERT(1 == ud.frame_not_send_cb_called); + assert_int(0, ==, rv); + assert_int(0, ==, ud.frame_send_cb_called); + assert_int(1, ==, ud.before_frame_send_cb_called); + assert_int(1, ==, ud.frame_not_send_cb_called); stream = nghttp2_session_get_stream_raw(session, stream_id); - CU_ASSERT(NULL == stream); + assert_null(stream); nghttp2_session_del(session); @@ -11330,7 +11622,7 @@ void test_nghttp2_session_cancel_from_before_frame_send(void) { stream_id = nghttp2_submit_push_promise(session, NGHTTP2_FLAG_NONE, 1, reqnv, ARRLEN(reqnv), NULL); - CU_ASSERT(stream_id > 0); + assert_int32(0, <, stream_id); ud.frame_send_cb_called = 0; ud.before_frame_send_cb_called = 0; @@ -11338,14 +11630,14 @@ void test_nghttp2_session_cancel_from_before_frame_send(void) { rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); - CU_ASSERT(0 == ud.frame_send_cb_called); - CU_ASSERT(1 == ud.before_frame_send_cb_called); - CU_ASSERT(1 == ud.frame_not_send_cb_called); + assert_int(0, ==, rv); + assert_int(0, ==, ud.frame_send_cb_called); + assert_int(1, ==, ud.before_frame_send_cb_called); + assert_int(1, ==, ud.frame_not_send_cb_called); stream = nghttp2_session_get_stream_raw(session, stream_id); - CU_ASSERT(NULL == stream); + assert_null(stream); nghttp2_session_del(session); } @@ -11357,7 +11649,7 @@ void test_nghttp2_session_too_many_settings(void) { nghttp2_frame frame; nghttp2_bufs bufs; nghttp2_buf *buf; - ssize_t rv; + nghttp2_ssize rv; my_user_data ud; nghttp2_settings_entry iv[3]; nghttp2_mem *mem; @@ -11368,14 +11660,14 @@ void test_nghttp2_session_too_many_settings(void) { memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); callbacks.on_frame_recv_callback = on_frame_recv_callback; - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_option_new(&option); nghttp2_option_set_max_settings(option, 1); nghttp2_session_client_new2(&session, &callbacks, &ud, option); - CU_ASSERT(1 == session->max_settings); + assert_size(1, ==, session->max_settings); nghttp2_option_del(option); @@ -11390,8 +11682,8 @@ void test_nghttp2_session_too_many_settings(void) { rv = nghttp2_frame_pack_settings(&bufs, &frame.settings); - CU_ASSERT(0 == rv); - CU_ASSERT(nghttp2_bufs_len(&bufs) > 0); + assert_ptrdiff(0, ==, rv); + assert_size(0, <, nghttp2_bufs_len(&bufs)); nghttp2_frame_settings_free(&frame.settings, mem); @@ -11400,11 +11692,11 @@ void test_nghttp2_session_too_many_settings(void) { ud.frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); nghttp2_bufs_reset(&bufs); nghttp2_bufs_free(&bufs); @@ -11418,7 +11710,7 @@ prepare_session_removed_closed_stream(nghttp2_session *session, nghttp2_settings_entry iv; nghttp2_bufs bufs; nghttp2_mem *mem; - ssize_t nread; + nghttp2_ssize nread; int i; nghttp2_stream *stream; nghttp2_frame_hd hd; @@ -11432,23 +11724,23 @@ prepare_session_removed_closed_stream(nghttp2_session *session, rv = nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, &iv, 1); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); for (i = 1; i <= 3; i += 2) { rv = pack_headers(&bufs, deflater, i, NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM, reqnv, ARRLEN(reqnv), mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); - nread = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + nread = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == nread); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, nread); nghttp2_bufs_reset(&bufs); } @@ -11459,17 +11751,17 @@ prepare_session_removed_closed_stream(nghttp2_session *session, NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM, reqnv, ARRLEN(reqnv), mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); /* Receiving stream 5 will erase stream 3 from closed stream list */ - nread = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + nread = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == nread); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, nread); stream = nghttp2_session_get_stream_raw(session, 3); - CU_ASSERT(NULL == stream); + assert_null(stream); /* Since the current max concurrent streams is NGHTTP2_DEFAULT_MAX_CONCURRENT_STREAMS, receiving frame on stream @@ -11479,24 +11771,24 @@ prepare_session_removed_closed_stream(nghttp2_session *session, NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM, trailernv, ARRLEN(trailernv), mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); - nread = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + nread = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == nread); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, nread); + assert_null(nghttp2_session_get_next_ob_item(session)); nghttp2_frame_hd_init(&hd, 0, NGHTTP2_DATA, NGHTTP2_FLAG_NONE, 3); nghttp2_bufs_reset(&bufs); nghttp2_frame_pack_frame_hd(bufs.head->buf.last, &hd); bufs.head->buf.last += NGHTTP2_FRAME_HDLEN; - nread = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + nread = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == nread); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, nread); + assert_null(nghttp2_session_get_next_ob_item(session)); /* Now server receives SETTINGS ACK */ nghttp2_frame_hd_init(&hd, 0, NGHTTP2_SETTINGS, NGHTTP2_FLAG_ACK, 0); @@ -11504,10 +11796,10 @@ prepare_session_removed_closed_stream(nghttp2_session *session, nghttp2_frame_pack_frame_hd(bufs.head->buf.last, &hd); bufs.head->buf.last += NGHTTP2_FRAME_HDLEN; - nread = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + nread = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == nread); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, nread); nghttp2_bufs_free(&bufs); } @@ -11519,7 +11811,7 @@ void test_nghttp2_session_removed_closed_stream(void) { nghttp2_hd_deflater deflater; nghttp2_bufs bufs; nghttp2_mem *mem; - ssize_t nread; + nghttp2_ssize nread; nghttp2_frame_hd hd; nghttp2_outbound_item *item; @@ -11529,7 +11821,7 @@ void test_nghttp2_session_removed_closed_stream(void) { memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_server_new(&session, &callbacks, NULL); @@ -11548,16 +11840,16 @@ void test_nghttp2_session_removed_closed_stream(void) { NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM, trailernv, ARRLEN(trailernv), mem); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); - nread = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + nread = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == nread); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, nread); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL == item); + assert_null(item); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -11573,14 +11865,14 @@ void test_nghttp2_session_removed_closed_stream(void) { nghttp2_frame_pack_frame_hd(bufs.head->buf.last, &hd); bufs.head->buf.last += NGHTTP2_FRAME_HDLEN; - nread = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_bufs_len(&bufs)); + nread = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_bufs_len(&bufs)); - CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == nread); + assert_ptrdiff((nghttp2_ssize)nghttp2_bufs_len(&bufs), ==, nread); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL == item); + assert_null(item); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -11588,7 +11880,7 @@ void test_nghttp2_session_removed_closed_stream(void) { nghttp2_bufs_free(&bufs); } -static ssize_t pause_once_data_source_read_callback( +static nghttp2_ssize pause_once_data_source_read_callback( nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t len, uint32_t *data_flags, nghttp2_data_source *source, void *user_data) { my_user_data *ud = user_data; @@ -11604,11 +11896,11 @@ static ssize_t pause_once_data_source_read_callback( void test_nghttp2_session_pause_data(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; my_user_data ud; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_send_callback = on_frame_send_callback; data_prd.read_callback = pause_once_data_source_read_callback; @@ -11618,19 +11910,20 @@ void test_nghttp2_session_pause_data(void) { open_recv_stream(session, 1); - CU_ASSERT( - 0 == nghttp2_submit_data(session, NGHTTP2_FLAG_END_STREAM, 1, &data_prd)); + assert_int( + 0, ==, + nghttp2_submit_data2(session, NGHTTP2_FLAG_END_STREAM, 1, &data_prd)); ud.frame_send_cb_called = 0; ud.data_source_read_cb_paused = 0; - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(0 == ud.frame_send_cb_called); - CU_ASSERT(NULL == session->aob.item); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == ud.frame_send_cb_called); - CU_ASSERT(NGHTTP2_DATA == ud.sent_frame_type); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(0, ==, ud.frame_send_cb_called); + assert_null(session->aob.item); + assert_int(0, ==, nghttp2_session_send(session)); + assert_int(1, ==, ud.frame_send_cb_called); + assert_uint8(NGHTTP2_DATA, ==, ud.sent_frame_type); + assert_null(nghttp2_session_get_next_ob_item(session)); nghttp2_session_del(session); } @@ -11651,7 +11944,7 @@ void test_nghttp2_session_no_closed_streams(void) { nghttp2_session_close_stream(session, 1, NGHTTP2_NO_ERROR); - CU_ASSERT(0 == session->num_closed_streams); + assert_size(0, ==, session->num_closed_streams); nghttp2_session_del(session); nghttp2_option_del(option); @@ -11664,28 +11957,28 @@ void test_nghttp2_session_set_stream_user_data(void) { int user_data1, user_data2; int rv; const uint8_t *datap; - ssize_t datalen; + nghttp2_ssize datalen; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); nghttp2_session_client_new(&session, &callbacks, NULL); - stream_id = nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), NULL, - &user_data1); + stream_id = nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), NULL, + &user_data1); rv = nghttp2_session_set_stream_user_data(session, stream_id, &user_data2); - CU_ASSERT(0 == rv); + assert_int(0, ==, rv); - datalen = nghttp2_session_mem_send(session, &datap); + datalen = nghttp2_session_mem_send2(session, &datap); - CU_ASSERT(datalen > 0); + assert_ptrdiff(0, <, datalen); - CU_ASSERT(&user_data2 == - nghttp2_session_get_stream_user_data(session, stream_id)); + assert_ptr_equal(&user_data2, + nghttp2_session_get_stream_user_data(session, stream_id)); - CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == - nghttp2_session_set_stream_user_data(session, 2, NULL)); + assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, + nghttp2_session_set_stream_user_data(session, 2, NULL)); nghttp2_session_del(session); } @@ -11693,7 +11986,7 @@ void test_nghttp2_session_set_stream_user_data(void) { void test_nghttp2_session_no_rfc7540_priorities(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - nghttp2_data_provider data_prd; + nghttp2_data_provider2 data_prd; my_user_data ud; nghttp2_outbound_item *item; nghttp2_mem *mem; @@ -11703,70 +11996,76 @@ void test_nghttp2_session_no_rfc7540_priorities(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; /* Do not use a dependency tree if SETTINGS_NO_RFC7540_PRIORITIES = 1. */ data_prd.read_callback = fixed_length_data_source_read_callback; ud.data_source_length = 128 * 1024; - CU_ASSERT(0 == nghttp2_session_server_new(&session, &callbacks, &ud)); + assert_int(0, ==, nghttp2_session_server_new(&session, &callbacks, &ud)); iv.settings_id = NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES; iv.value = 1; - CU_ASSERT(0 == nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, &iv, 1)); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, + nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, &iv, 1)); + assert_int(0, ==, nghttp2_session_send(session)); open_recv_stream2(session, 1, NGHTTP2_STREAM_OPENING); - CU_ASSERT(0 == nghttp2_submit_response(session, 1, resnv, ARRLEN(resnv), - &data_prd)); + assert_int( + 0, ==, + nghttp2_submit_response2(session, 1, resnv, ARRLEN(resnv), &data_prd)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(ARRLEN(resnv) == item->frame.headers.nvlen); + assert_size(ARRLEN(resnv), ==, item->frame.headers.nvlen); assert_nv_equal(resnv, item->frame.headers.nva, item->frame.headers.nvlen, mem); - CU_ASSERT(0 == nghttp2_session_send(session)); - CU_ASSERT(1 == nghttp2_pq_size( - &session->sched[NGHTTP2_EXTPRI_DEFAULT_URGENCY].ob_data)); - CU_ASSERT(nghttp2_pq_empty(&session->root.obq)); + assert_int(0, ==, nghttp2_session_send(session)); + assert_size( + 1, ==, + nghttp2_pq_size(&session->sched[NGHTTP2_EXTPRI_DEFAULT_URGENCY].ob_data)); + assert_true(nghttp2_pq_empty(&session->root.obq)); nghttp2_session_del(session); /* Priorities are sent as is before client receives SETTINGS_NO_RFC7540_PRIORITIES = 1 from server. */ - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, NULL)); + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, NULL)); iv.settings_id = NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES; iv.value = 1; - CU_ASSERT(0 == nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, &iv, 1)); + assert_int(0, ==, + nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, &iv, 1)); pri_spec.stream_id = 5; pri_spec.weight = 111; pri_spec.exclusive = 1; - CU_ASSERT(1 == nghttp2_submit_request(session, &pri_spec, reqnv, - ARRLEN(reqnv), NULL, NULL)); + assert_int32(1, ==, + nghttp2_submit_request2(session, &pri_spec, reqnv, ARRLEN(reqnv), + NULL, NULL)); item = nghttp2_outbound_queue_top(&session->ob_syn); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_HEADERS == item->frame.hd.type); - CU_ASSERT(pri_spec.stream_id == item->frame.headers.pri_spec.stream_id); - CU_ASSERT(pri_spec.weight == item->frame.headers.pri_spec.weight); - CU_ASSERT(pri_spec.exclusive == item->frame.headers.pri_spec.exclusive); + assert_not_null(item); + assert_uint8(NGHTTP2_HEADERS, ==, item->frame.hd.type); + assert_int32(pri_spec.stream_id, ==, item->frame.headers.pri_spec.stream_id); + assert_int32(pri_spec.weight, ==, item->frame.headers.pri_spec.weight); + assert_uint8(pri_spec.exclusive, ==, item->frame.headers.pri_spec.exclusive); nghttp2_session_del(session); /* Priorities are defaulted if client received SETTINGS_NO_RFC7540_PRIORITIES = 1 from server. */ - CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, NULL)); + assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, NULL)); iv.settings_id = NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES; iv.value = 1; - CU_ASSERT(0 == nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, &iv, 1)); + assert_int(0, ==, + nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, &iv, 1)); session->remote_settings.no_rfc7540_priorities = 1; @@ -11774,14 +12073,16 @@ void test_nghttp2_session_no_rfc7540_priorities(void) { pri_spec.weight = 111; pri_spec.exclusive = 1; - CU_ASSERT(1 == nghttp2_submit_request(session, &pri_spec, reqnv, - ARRLEN(reqnv), NULL, NULL)); + assert_int32(1, ==, + nghttp2_submit_request2(session, &pri_spec, reqnv, ARRLEN(reqnv), + NULL, NULL)); item = nghttp2_outbound_queue_top(&session->ob_syn); - CU_ASSERT(NULL != item); - CU_ASSERT(NGHTTP2_HEADERS == item->frame.hd.type); - CU_ASSERT(nghttp2_priority_spec_check_default(&item->frame.headers.pri_spec)); + assert_not_null(item); + assert_uint8(NGHTTP2_HEADERS, ==, item->frame.hd.type); + assert_true( + nghttp2_priority_spec_check_default(&item->frame.headers.pri_spec)); nghttp2_session_del(session); } @@ -11793,7 +12094,7 @@ void test_nghttp2_session_server_fallback_rfc7540_priorities(void) { nghttp2_frame frame; nghttp2_bufs bufs; nghttp2_buf *buf; - ssize_t rv; + nghttp2_ssize rv; nghttp2_settings_entry iv; nghttp2_mem *mem; nghttp2_hd_deflater deflater; @@ -11809,7 +12110,7 @@ void test_nghttp2_session_server_fallback_rfc7540_priorities(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_recv_callback = on_frame_recv_callback; nghttp2_option_new(&option); @@ -11823,24 +12124,24 @@ void test_nghttp2_session_server_fallback_rfc7540_priorities(void) { rv = nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, &iv, 1); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_NONE, NULL, 0); rv = nghttp2_frame_pack_settings(&bufs, &frame.settings); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_settings_free(&frame.settings, mem); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); - CU_ASSERT(1 == session->fallback_rfc7540_priorities); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_true(session->fallback_rfc7540_priorities); nghttp2_hd_deflate_init(&deflater, mem); @@ -11853,27 +12154,28 @@ void test_nghttp2_session_server_fallback_rfc7540_priorities(void) { nghttp2_bufs_reset(&bufs); rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_headers_free(&frame.headers, mem); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); anchor_stream = nghttp2_session_get_stream_raw(session, 3); - CU_ASSERT(NGHTTP2_STREAM_IDLE == anchor_stream->state); - CU_ASSERT( - !(anchor_stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES)); - CU_ASSERT(&session->root == anchor_stream->dep_prev); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_IDLE, ==, + anchor_stream->state); + assert_false(anchor_stream->flags & + NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES); + assert_ptr_equal(&session->root, anchor_stream->dep_prev); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(NGHTTP2_STREAM_OPENING == stream->state); - CU_ASSERT(!(stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES)); - CU_ASSERT(anchor_stream == stream->dep_prev); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENING, ==, stream->state); + assert_false(stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES); + assert_ptr_equal(anchor_stream, stream->dep_prev); /* Make sure that PRIORITY frame updates stream priority. */ nghttp2_priority_spec_init(&pri_spec, 5, 1, 0); @@ -11884,15 +12186,16 @@ void test_nghttp2_session_server_fallback_rfc7540_priorities(void) { nghttp2_frame_priority_free(&frame.priority); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); anchor_stream = nghttp2_session_get_stream_raw(session, 5); - CU_ASSERT(NGHTTP2_STREAM_IDLE == anchor_stream->state); - CU_ASSERT(&session->root == anchor_stream->dep_prev); - CU_ASSERT(anchor_stream == stream->dep_prev); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_IDLE, ==, + anchor_stream->state); + assert_ptr_equal(&session->root, anchor_stream->dep_prev); + assert_ptr_equal(anchor_stream, stream->dep_prev); /* Make sure that PRIORITY_UPDATE frame is ignored. */ frame.ext.payload = &priority_update; @@ -11903,11 +12206,11 @@ void test_nghttp2_session_server_fallback_rfc7540_priorities(void) { ud.frame_recv_cb_called = 0; buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); - CU_ASSERT(0 == ud.frame_recv_cb_called); - CU_ASSERT(NGHTTP2_EXTPRI_DEFAULT_URGENCY == stream->extpri); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_int(0, ==, ud.frame_recv_cb_called); + assert_uint32(NGHTTP2_EXTPRI_DEFAULT_URGENCY, ==, stream->extpri); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -11917,11 +12220,11 @@ void test_nghttp2_session_server_fallback_rfc7540_priorities(void) { rv = nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, &iv, 1); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); iv.settings_id = NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES; iv.value = 0; @@ -11931,15 +12234,15 @@ void test_nghttp2_session_server_fallback_rfc7540_priorities(void) { nghttp2_bufs_reset(&bufs); rv = nghttp2_frame_pack_settings(&bufs, &frame.settings); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_settings_free(&frame.settings, mem); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); - CU_ASSERT(0 == session->fallback_rfc7540_priorities); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_false(session->fallback_rfc7540_priorities); nghttp2_hd_deflate_init(&deflater, mem); @@ -11952,20 +12255,20 @@ void test_nghttp2_session_server_fallback_rfc7540_priorities(void) { nghttp2_bufs_reset(&bufs); rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_headers_free(&frame.headers, mem); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); - CU_ASSERT(NULL == nghttp2_session_get_stream_raw(session, 3)); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); + assert_null(nghttp2_session_get_stream_raw(session, 3)); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(NGHTTP2_STREAM_OPENING == stream->state); - CU_ASSERT(stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES); + assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENING, ==, stream->state); + assert_true(stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -11978,7 +12281,7 @@ void test_nghttp2_session_stream_reset_ratelim(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; nghttp2_frame frame; - ssize_t rv; + nghttp2_ssize rv; nghttp2_bufs bufs; nghttp2_buf *buf; nghttp2_mem *mem; @@ -11994,7 +12297,7 @@ void test_nghttp2_session_stream_reset_ratelim(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_option_new(&option); nghttp2_option_set_stream_reset_rate_limit( @@ -12005,19 +12308,19 @@ void test_nghttp2_session_stream_reset_ratelim(void) { nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_NONE, NULL, 0); rv = nghttp2_frame_pack_settings(&bufs, &frame.settings); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_settings_free(&frame.settings, mem); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); /* Send SETTINGS ACK */ rv = nghttp2_session_send(session); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_hd_deflate_init(&deflater, mem); @@ -12034,14 +12337,14 @@ void test_nghttp2_session_stream_reset_ratelim(void) { nvlen); rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_headers_free(&frame.headers, mem); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); nghttp2_bufs_reset(&bufs); @@ -12052,23 +12355,23 @@ void test_nghttp2_session_stream_reset_ratelim(void) { nghttp2_frame_rst_stream_free(&frame.rst_stream); buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv(session, buf->pos, nghttp2_buf_len(buf)); + rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); if (i < NGHTTP2_DEFAULT_STREAM_RESET_BURST) { - CU_ASSERT(0 == nghttp2_outbound_queue_size(&session->ob_reg)); + assert_size(0, ==, nghttp2_outbound_queue_size(&session->ob_reg)); continue; } - CU_ASSERT(1 == nghttp2_outbound_queue_size(&session->ob_reg)); + assert_size(1, ==, nghttp2_outbound_queue_size(&session->ob_reg)); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_GOAWAY == item->frame.hd.type); - CU_ASSERT(NGHTTP2_DEFAULT_STREAM_RESET_BURST * 2 + 1 == - item->frame.goaway.last_stream_id); + assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); + assert_int32(NGHTTP2_DEFAULT_STREAM_RESET_BURST * 2 + 1, ==, + item->frame.goaway.last_stream_id); } nghttp2_hd_deflate_free(&deflater); @@ -12081,7 +12384,7 @@ static void check_nghttp2_http_recv_headers_fail( nghttp2_session *session, nghttp2_hd_deflater *deflater, int32_t stream_id, int stream_state, const nghttp2_nv *nva, size_t nvlen) { nghttp2_mem *mem; - ssize_t rv; + nghttp2_ssize rv; nghttp2_outbound_item *item; nghttp2_bufs bufs; my_user_data *ud; @@ -12101,21 +12404,21 @@ static void check_nghttp2_http_recv_headers_fail( rv = pack_headers(&bufs, deflater, stream_id, NGHTTP2_FLAG_END_HEADERS, nva, nvlen, mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); ud->invalid_frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(1 == ud->invalid_frame_recv_cb_called); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_ptrdiff(1, ==, ud->invalid_frame_recv_cb_called); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_bufs_free(&bufs); } @@ -12124,7 +12427,7 @@ static void check_nghttp2_http_recv_headers_ok( nghttp2_session *session, nghttp2_hd_deflater *deflater, int32_t stream_id, int stream_state, const nghttp2_nv *nva, size_t nvlen) { nghttp2_mem *mem; - ssize_t rv; + nghttp2_ssize rv; nghttp2_bufs bufs; my_user_data *ud; @@ -12143,16 +12446,16 @@ static void check_nghttp2_http_recv_headers_ok( rv = pack_headers(&bufs, deflater, stream_id, NGHTTP2_FLAG_END_HEADERS, nva, nvlen, mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); ud->frame_recv_cb_called = 0; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); - CU_ASSERT(1 == ud->frame_recv_cb_called); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); + assert_null(nghttp2_session_get_next_ob_item(session)); + assert_int(1, ==, ud->frame_recv_cb_called); nghttp2_bufs_free(&bufs); } @@ -12255,7 +12558,7 @@ void test_nghttp2_http_mandatory_headers(void) { mem = nghttp2_mem_default(); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_frame_recv_callback = on_frame_recv_callback; callbacks.on_invalid_frame_recv_callback = on_invalid_frame_recv_callback; @@ -12459,7 +12762,7 @@ void test_nghttp2_http_content_length(void) { nghttp2_hd_deflater deflater; nghttp2_mem *mem; nghttp2_bufs bufs; - ssize_t rv; + nghttp2_ssize rv; nghttp2_stream *stream; const nghttp2_nv cl_resnv[] = {MAKE_NV(":status", "200"), MAKE_NV("te", "trailers"), @@ -12473,7 +12776,7 @@ void test_nghttp2_http_content_length(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, NULL); @@ -12483,15 +12786,15 @@ void test_nghttp2_http_content_length(void) { rv = pack_headers(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, cl_resnv, ARRLEN(cl_resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); - CU_ASSERT(9000000000LL == stream->content_length); - CU_ASSERT(200 == stream->status_code); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); + assert_null(nghttp2_session_get_next_ob_item(session)); + assert_int64(9000000000LL, ==, stream->content_length); + assert_int16(200, ==, stream->status_code); nghttp2_hd_deflate_free(&deflater); @@ -12506,17 +12809,17 @@ void test_nghttp2_http_content_length(void) { rv = pack_headers(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, cl_reqnv, ARRLEN(cl_reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); - CU_ASSERT(9000000000LL == stream->content_length); + assert_null(nghttp2_session_get_next_ob_item(session)); + assert_int64(9000000000LL, ==, stream->content_length); nghttp2_hd_deflate_free(&deflater); @@ -12531,7 +12834,7 @@ void test_nghttp2_http_content_length_mismatch(void) { nghttp2_hd_deflater deflater; nghttp2_mem *mem; nghttp2_bufs bufs; - ssize_t rv; + nghttp2_ssize rv; const nghttp2_nv cl_reqnv[] = { MAKE_NV(":path", "/"), MAKE_NV(":method", "PUT"), MAKE_NV(":authority", "localhost"), MAKE_NV(":scheme", "https"), @@ -12545,7 +12848,7 @@ void test_nghttp2_http_content_length_mismatch(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_server_new(&session, &callbacks, NULL); @@ -12555,59 +12858,59 @@ void test_nghttp2_http_content_length_mismatch(void) { rv = pack_headers(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM, cl_reqnv, ARRLEN(cl_reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_bufs_reset(&bufs); /* header says content-length: 20, but DATA has 0 byte */ rv = pack_headers(&bufs, &deflater, 3, NGHTTP2_FLAG_END_HEADERS, cl_reqnv, ARRLEN(cl_reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_hd_init(&hd, 0, NGHTTP2_DATA, NGHTTP2_FLAG_END_STREAM, 3); nghttp2_frame_pack_frame_hd(bufs.head->buf.last, &hd); bufs.head->buf.last += NGHTTP2_FRAME_HDLEN; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_bufs_reset(&bufs); /* header says content-length: 20, but DATA has 21 bytes */ rv = pack_headers(&bufs, &deflater, 5, NGHTTP2_FLAG_END_HEADERS, cl_reqnv, ARRLEN(cl_reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_hd_init(&hd, 21, NGHTTP2_DATA, NGHTTP2_FLAG_END_STREAM, 5); nghttp2_frame_pack_frame_hd(bufs.head->buf.last, &hd); bufs.head->buf.last += NGHTTP2_FRAME_HDLEN + 21; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_bufs_reset(&bufs); @@ -12621,83 +12924,83 @@ void test_nghttp2_http_content_length_mismatch(void) { nghttp2_hd_deflate_init(&deflater, mem); /* header says content-length: 20, but HEADERS has END_STREAM flag set */ - nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); + nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); rv = pack_headers(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM, cl_resnv, ARRLEN(cl_resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); - CU_ASSERT(NULL != nghttp2_session_get_stream(session, 1)); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_not_null(nghttp2_session_get_stream(session, 1)); + assert_int(0, ==, nghttp2_session_send(session)); /* After sending RST_STREAM, stream must be closed */ - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 1)); + assert_null(nghttp2_session_get_stream(session, 1)); nghttp2_bufs_reset(&bufs); /* header says content-length: 20, but DATA has 0 byte */ - nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); + nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); rv = pack_headers(&bufs, &deflater, 3, NGHTTP2_FLAG_END_HEADERS, cl_resnv, ARRLEN(cl_resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_hd_init(&hd, 0, NGHTTP2_DATA, NGHTTP2_FLAG_END_STREAM, 3); nghttp2_frame_pack_frame_hd(bufs.head->buf.last, &hd); bufs.head->buf.last += NGHTTP2_FRAME_HDLEN; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); - CU_ASSERT(NULL != nghttp2_session_get_stream(session, 3)); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_not_null(nghttp2_session_get_stream(session, 3)); + assert_int(0, ==, nghttp2_session_send(session)); /* After sending RST_STREAM, stream must be closed */ - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 3)); + assert_null(nghttp2_session_get_stream(session, 3)); nghttp2_bufs_reset(&bufs); /* header says content-length: 20, but DATA has 21 bytes */ - nghttp2_submit_request(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); + nghttp2_submit_request2(session, NULL, reqnv, ARRLEN(reqnv), NULL, NULL); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); rv = pack_headers(&bufs, &deflater, 5, NGHTTP2_FLAG_END_HEADERS, cl_resnv, ARRLEN(cl_resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_hd_init(&hd, 21, NGHTTP2_DATA, NGHTTP2_FLAG_END_STREAM, 5); nghttp2_frame_pack_frame_hd(bufs.head->buf.last, &hd); bufs.head->buf.last += NGHTTP2_FRAME_HDLEN + 21; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); - CU_ASSERT(NULL != nghttp2_session_get_stream(session, 5)); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_not_null(nghttp2_session_get_stream(session, 5)); + assert_int(0, ==, nghttp2_session_send(session)); /* After sending RST_STREAM, stream must be closed */ - CU_ASSERT(NULL == nghttp2_session_get_stream(session, 5)); + assert_null(nghttp2_session_get_stream(session, 5)); nghttp2_bufs_reset(&bufs); @@ -12714,7 +13017,7 @@ void test_nghttp2_http_non_final_response(void) { nghttp2_hd_deflater deflater; nghttp2_mem *mem; nghttp2_bufs bufs; - ssize_t rv; + nghttp2_ssize rv; const nghttp2_nv nonfinal_resnv[] = { MAKE_NV(":status", "100"), }; @@ -12725,7 +13028,7 @@ void test_nghttp2_http_non_final_response(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, NULL); @@ -12737,17 +13040,17 @@ void test_nghttp2_http_non_final_response(void) { rv = pack_headers(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM, nonfinal_resnv, ARRLEN(nonfinal_resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_bufs_reset(&bufs); @@ -12756,21 +13059,21 @@ void test_nghttp2_http_non_final_response(void) { rv = pack_headers(&bufs, &deflater, 3, NGHTTP2_FLAG_END_HEADERS, nonfinal_resnv, ARRLEN(nonfinal_resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_hd_init(&hd, 10, NGHTTP2_DATA, NGHTTP2_FLAG_END_STREAM, 3); nghttp2_frame_pack_frame_hd(bufs.head->buf.last, &hd); bufs.head->buf.last += NGHTTP2_FRAME_HDLEN + 10; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_bufs_reset(&bufs); @@ -12780,18 +13083,18 @@ void test_nghttp2_http_non_final_response(void) { rv = pack_headers(&bufs, &deflater, 5, NGHTTP2_FLAG_END_HEADERS, nonfinal_resnv, ARRLEN(nonfinal_resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_hd_init(&hd, 0, NGHTTP2_DATA, NGHTTP2_FLAG_NONE, 5); nghttp2_frame_pack_frame_hd(bufs.head->buf.last, &hd); bufs.head->buf.last += NGHTTP2_FRAME_HDLEN; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_null(nghttp2_session_get_next_ob_item(session)); nghttp2_bufs_reset(&bufs); @@ -12801,22 +13104,22 @@ void test_nghttp2_http_non_final_response(void) { rv = pack_headers(&bufs, &deflater, 7, NGHTTP2_FLAG_END_HEADERS, nonfinal_resnv, ARRLEN(nonfinal_resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_frame_hd_init(&hd, 0, NGHTTP2_DATA, NGHTTP2_FLAG_END_STREAM, 7); nghttp2_frame_pack_frame_hd(bufs.head->buf.last, &hd); bufs.head->buf.last += NGHTTP2_FRAME_HDLEN; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_bufs_reset(&bufs); @@ -12825,25 +13128,25 @@ void test_nghttp2_http_non_final_response(void) { rv = pack_headers(&bufs, &deflater, 9, NGHTTP2_FLAG_END_HEADERS, nonfinal_resnv, ARRLEN(nonfinal_resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); nghttp2_bufs_reset(&bufs); rv = pack_headers(&bufs, &deflater, 9, NGHTTP2_FLAG_END_HEADERS, resnv, ARRLEN(resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_null(nghttp2_session_get_next_ob_item(session)); nghttp2_bufs_reset(&bufs); @@ -12860,7 +13163,7 @@ void test_nghttp2_http_trailer_headers(void) { nghttp2_hd_deflater deflater; nghttp2_mem *mem; nghttp2_bufs bufs; - ssize_t rv; + nghttp2_ssize rv; const nghttp2_nv trailer_reqnv[] = { MAKE_NV("foo", "bar"), }; @@ -12870,7 +13173,7 @@ void test_nghttp2_http_trailer_headers(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_server_new(&session, &callbacks, NULL); @@ -12879,84 +13182,84 @@ void test_nghttp2_http_trailer_headers(void) { /* good trailer header */ rv = pack_headers(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, reqnv, ARRLEN(reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); nghttp2_bufs_reset(&bufs); rv = pack_headers(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM, trailer_reqnv, ARRLEN(trailer_reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_null(nghttp2_session_get_next_ob_item(session)); nghttp2_bufs_reset(&bufs); /* trailer header without END_STREAM is illegal */ rv = pack_headers(&bufs, &deflater, 3, NGHTTP2_FLAG_END_HEADERS, reqnv, ARRLEN(reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); nghttp2_bufs_reset(&bufs); rv = pack_headers(&bufs, &deflater, 3, NGHTTP2_FLAG_END_HEADERS, trailer_reqnv, ARRLEN(trailer_reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_bufs_reset(&bufs); /* trailer header including pseudo header field is illegal */ rv = pack_headers(&bufs, &deflater, 5, NGHTTP2_FLAG_END_HEADERS, reqnv, ARRLEN(reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); nghttp2_bufs_reset(&bufs); rv = pack_headers(&bufs, &deflater, 5, NGHTTP2_FLAG_END_HEADERS, reqnv, ARRLEN(reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_bufs_reset(&bufs); @@ -12973,7 +13276,7 @@ void test_nghttp2_http_ignore_regular_header(void) { nghttp2_hd_deflater deflater; nghttp2_mem *mem; nghttp2_bufs bufs; - ssize_t rv; + nghttp2_ssize rv; my_user_data ud; const nghttp2_nv bad_reqnv[] = { MAKE_NV(":authority", "localhost"), @@ -12994,7 +13297,7 @@ void test_nghttp2_http_ignore_regular_header(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; callbacks.on_header_callback = pause_on_header_callback; nghttp2_session_server_new(&session, &callbacks, &ud); @@ -13004,32 +13307,32 @@ void test_nghttp2_http_ignore_regular_header(void) { NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM, bad_reqnv, ARRLEN(bad_reqnv), mem); - CU_ASSERT_FATAL(0 == rv); + assert_ptrdiff(0, ==, rv); nghttp2_hd_deflate_free(&deflater); proclen = 0; for (i = 0; i < 4; ++i) { - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos + proclen, - nghttp2_buf_len(&bufs.head->buf) - proclen); - CU_ASSERT_FATAL(rv > 0); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos + proclen, + nghttp2_buf_len(&bufs.head->buf) - proclen); + assert_ptrdiff(0, <, rv); proclen += (size_t)rv; - CU_ASSERT(nghttp2_nv_equal(&bad_ansnv[i], &ud.nv)); + assert_true(nghttp2_nv_equal(&bad_ansnv[i], &ud.nv)); } - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos + proclen, - nghttp2_buf_len(&bufs.head->buf) - proclen); - CU_ASSERT_FATAL(rv > 0); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos + proclen, + nghttp2_buf_len(&bufs.head->buf) - proclen); + assert_ptrdiff(0, <, rv); /* Without on_invalid_frame_recv_callback, bad header causes stream reset */ item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); proclen += (size_t)rv; - CU_ASSERT(nghttp2_buf_len(&bufs.head->buf) == proclen); + assert_size(nghttp2_buf_len(&bufs.head->buf), ==, proclen); nghttp2_session_del(session); @@ -13043,29 +13346,29 @@ void test_nghttp2_http_ignore_regular_header(void) { ud.invalid_header_cb_called = 0; for (i = 0; i < 4; ++i) { - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos + proclen, - nghttp2_buf_len(&bufs.head->buf) - proclen); - CU_ASSERT_FATAL(rv > 0); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos + proclen, + nghttp2_buf_len(&bufs.head->buf) - proclen); + assert_ptrdiff(0, <, rv); proclen += (size_t)rv; - CU_ASSERT(nghttp2_nv_equal(&bad_ansnv[i], &ud.nv)); + assert_true(nghttp2_nv_equal(&bad_ansnv[i], &ud.nv)); } - CU_ASSERT(0 == ud.invalid_header_cb_called); + assert_int(0, ==, ud.invalid_header_cb_called); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos + proclen, - nghttp2_buf_len(&bufs.head->buf) - proclen); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos + proclen, + nghttp2_buf_len(&bufs.head->buf) - proclen); - CU_ASSERT_FATAL(rv > 0); - CU_ASSERT(1 == ud.invalid_header_cb_called); - CU_ASSERT(nghttp2_nv_equal(&bad_reqnv[4], &ud.nv)); + assert_ptrdiff(0, <, rv); + assert_int(1, ==, ud.invalid_header_cb_called); + assert_true(nghttp2_nv_equal(&bad_reqnv[4], &ud.nv)); proclen += (size_t)rv; - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos + proclen, - nghttp2_buf_len(&bufs.head->buf) - proclen); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos + proclen, + nghttp2_buf_len(&bufs.head->buf) - proclen); - CU_ASSERT(rv > 0); - CU_ASSERT(nghttp2_nv_equal(&bad_ansnv[4], &ud.nv)); + assert_ptrdiff(0, <, rv); + assert_true(nghttp2_nv_equal(&bad_ansnv[4], &ud.nv)); nghttp2_session_del(session); @@ -13076,15 +13379,15 @@ void test_nghttp2_http_ignore_regular_header(void) { nghttp2_session_server_new(&session, &callbacks, &ud); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT(rv == (ssize_t)nghttp2_buf_len(&bufs.head->buf)); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(1 == item->frame.hd.stream_id); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_int32(1, ==, item->frame.hd.stream_id); nghttp2_session_del(session); nghttp2_bufs_free(&bufs); @@ -13096,7 +13399,7 @@ void test_nghttp2_http_ignore_content_length(void) { nghttp2_hd_deflater deflater; nghttp2_mem *mem; nghttp2_bufs bufs; - ssize_t rv; + nghttp2_ssize rv; const nghttp2_nv cl_resnv[] = {MAKE_NV(":status", "304"), MAKE_NV("content-length", "20")}; const nghttp2_nv conn_reqnv[] = {MAKE_NV(":authority", "localhost"), @@ -13110,7 +13413,7 @@ void test_nghttp2_http_ignore_content_length(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, NULL); @@ -13122,14 +13425,14 @@ void test_nghttp2_http_ignore_content_length(void) { rv = pack_headers(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM, cl_resnv, ARRLEN(cl_resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_null(nghttp2_session_get_next_ob_item(session)); nghttp2_bufs_reset(&bufs); @@ -13139,15 +13442,15 @@ void test_nghttp2_http_ignore_content_length(void) { rv = pack_headers(&bufs, &deflater, 3, NGHTTP2_FLAG_END_HEADERS, conn_cl_resnv, ARRLEN(conn_cl_resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); - CU_ASSERT(-1 == stream->content_length); + assert_null(nghttp2_session_get_next_ob_item(session)); + assert_int64(-1, ==, stream->content_length); nghttp2_bufs_reset(&bufs); @@ -13162,19 +13465,19 @@ void test_nghttp2_http_ignore_content_length(void) { rv = pack_headers(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, conn_reqnv, ARRLEN(conn_reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_null(nghttp2_session_get_next_ob_item(session)); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(-1 == stream->content_length); - CU_ASSERT((stream->http_flags & NGHTTP2_HTTP_FLAG_METH_CONNECT) > 0); + assert_int64(-1, ==, stream->content_length); + assert_true(stream->http_flags & NGHTTP2_HTTP_FLAG_METH_CONNECT); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -13189,7 +13492,7 @@ void test_nghttp2_http_record_request_method(void) { const nghttp2_nv conn_resnv[] = {MAKE_NV(":status", "200"), MAKE_NV("content-length", "9999")}; nghttp2_stream *stream; - ssize_t rv; + nghttp2_ssize rv; nghttp2_bufs bufs; nghttp2_hd_deflater deflater; nghttp2_mem *mem; @@ -13199,37 +13502,38 @@ void test_nghttp2_http_record_request_method(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, NULL); nghttp2_hd_deflate_init(&deflater, mem); - CU_ASSERT(1 == nghttp2_submit_request(session, NULL, conn_reqnv, - ARRLEN(conn_reqnv), NULL, NULL)); + assert_int32(1, ==, + nghttp2_submit_request2(session, NULL, conn_reqnv, + ARRLEN(conn_reqnv), NULL, NULL)); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_int(0, ==, nghttp2_session_send(session)); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(NGHTTP2_HTTP_FLAG_METH_CONNECT == stream->http_flags); + assert_uint32(NGHTTP2_HTTP_FLAG_METH_CONNECT, ==, stream->http_flags); rv = pack_headers(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, conn_resnv, ARRLEN(conn_resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); - CU_ASSERT((NGHTTP2_HTTP_FLAG_METH_CONNECT & stream->http_flags) > 0); - CU_ASSERT(-1 == stream->content_length); + assert_true(NGHTTP2_HTTP_FLAG_METH_CONNECT & stream->http_flags); + assert_int64(-1, ==, stream->content_length); /* content-length is ignored in 200 response to a CONNECT request */ item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL == item); + assert_null(item); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -13242,7 +13546,7 @@ void test_nghttp2_http_push_promise(void) { nghttp2_hd_deflater deflater; nghttp2_mem *mem; nghttp2_bufs bufs; - ssize_t rv; + nghttp2_ssize rv; nghttp2_stream *stream; const nghttp2_nv bad_reqnv[] = {MAKE_NV(":method", "GET")}; nghttp2_outbound_item *item; @@ -13251,7 +13555,7 @@ void test_nghttp2_http_push_promise(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; /* good PUSH_PROMISE case */ nghttp2_session_client_new(&session, &callbacks, NULL); @@ -13262,33 +13566,33 @@ void test_nghttp2_http_push_promise(void) { rv = pack_push_promise(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, 2, reqnv, ARRLEN(reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_null(nghttp2_session_get_next_ob_item(session)); stream = nghttp2_session_get_stream(session, 2); - CU_ASSERT(NULL != stream); + assert_not_null(stream); nghttp2_bufs_reset(&bufs); rv = pack_headers(&bufs, &deflater, 2, NGHTTP2_FLAG_END_HEADERS, resnv, ARRLEN(resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); - CU_ASSERT(NULL == nghttp2_session_get_next_ob_item(session)); + assert_null(nghttp2_session_get_next_ob_item(session)); - CU_ASSERT(200 == stream->status_code); + assert_int16(200, ==, stream->status_code); nghttp2_bufs_reset(&bufs); @@ -13296,17 +13600,17 @@ void test_nghttp2_http_push_promise(void) { rv = pack_push_promise(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, 4, bad_reqnv, ARRLEN(bad_reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(4 == item->frame.hd.stream_id); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_int32(4, ==, item->frame.hd.stream_id); nghttp2_bufs_reset(&bufs); @@ -13323,14 +13627,14 @@ void test_nghttp2_http_head_method_upgrade_workaround(void) { nghttp2_bufs bufs; nghttp2_hd_deflater deflater; nghttp2_mem *mem; - ssize_t rv; + nghttp2_ssize rv; nghttp2_stream *stream; mem = nghttp2_mem_default(); frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; nghttp2_session_client_new(&session, &callbacks, NULL); @@ -13341,16 +13645,16 @@ void test_nghttp2_http_head_method_upgrade_workaround(void) { rv = pack_headers(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, cl_resnv, ARRLEN(cl_resnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); stream = nghttp2_session_get_stream(session, 1); - CU_ASSERT(-1 == stream->content_length); + assert_int64(-1, ==, stream->content_length); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -13363,7 +13667,7 @@ void test_nghttp2_http_no_rfc9113_leading_and_trailing_ws_validation(void) { nghttp2_hd_deflater deflater; nghttp2_mem *mem; nghttp2_bufs bufs; - ssize_t rv; + nghttp2_ssize rv; const nghttp2_nv ws_reqnv[] = { MAKE_NV(":path", "/"), MAKE_NV(":method", "GET"), @@ -13378,7 +13682,7 @@ void test_nghttp2_http_no_rfc9113_leading_and_trailing_ws_validation(void) { frame_pack_bufs_init(&bufs); memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback = null_send_callback; + callbacks.send_callback2 = null_send_callback; /* By default, the leading and trailing white spaces validation is enabled as per RFC 9113. */ @@ -13390,17 +13694,17 @@ void test_nghttp2_http_no_rfc9113_leading_and_trailing_ws_validation(void) { NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM, ws_reqnv, ARRLEN(ws_reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NGHTTP2_RST_STREAM == item->frame.hd.type); - CU_ASSERT(0 == nghttp2_session_send(session)); + assert_uint8(NGHTTP2_RST_STREAM, ==, item->frame.hd.type); + assert_int(0, ==, nghttp2_session_send(session)); nghttp2_bufs_reset(&bufs); nghttp2_hd_deflate_free(&deflater); @@ -13418,16 +13722,16 @@ void test_nghttp2_http_no_rfc9113_leading_and_trailing_ws_validation(void) { NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM, ws_reqnv, ARRLEN(ws_reqnv), mem); - CU_ASSERT(0 == rv); + assert_ptrdiff(0, ==, rv); - rv = nghttp2_session_mem_recv(session, bufs.head->buf.pos, - nghttp2_buf_len(&bufs.head->buf)); + rv = nghttp2_session_mem_recv2(session, bufs.head->buf.pos, + nghttp2_buf_len(&bufs.head->buf)); - CU_ASSERT((ssize_t)nghttp2_buf_len(&bufs.head->buf) == rv); + assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(&bufs.head->buf), ==, rv); item = nghttp2_session_get_next_ob_item(session); - CU_ASSERT(NULL == item); + assert_null(item); nghttp2_bufs_reset(&bufs); nghttp2_hd_deflate_free(&deflater); diff --git a/tests/nghttp2_session_test.h b/tests/nghttp2_session_test.h index be4fdf8..43befbe 100644 --- a/tests/nghttp2_session_test.h +++ b/tests/nghttp2_session_test.h @@ -29,156 +29,165 @@ # include <config.h> #endif /* HAVE_CONFIG_H */ -void test_nghttp2_session_recv(void); -void test_nghttp2_session_recv_invalid_stream_id(void); -void test_nghttp2_session_recv_invalid_frame(void); -void test_nghttp2_session_recv_eof(void); -void test_nghttp2_session_recv_data(void); -void test_nghttp2_session_recv_data_no_auto_flow_control(void); -void test_nghttp2_session_recv_continuation(void); -void test_nghttp2_session_recv_headers_with_priority(void); -void test_nghttp2_session_recv_headers_with_padding(void); -void test_nghttp2_session_recv_headers_early_response(void); -void test_nghttp2_session_recv_headers_for_closed_stream(void); -void test_nghttp2_session_recv_headers_with_extpri(void); -void test_nghttp2_session_server_recv_push_response(void); -void test_nghttp2_session_recv_premature_headers(void); -void test_nghttp2_session_recv_unknown_frame(void); -void test_nghttp2_session_recv_unexpected_continuation(void); -void test_nghttp2_session_recv_settings_header_table_size(void); -void test_nghttp2_session_recv_too_large_frame_length(void); -void test_nghttp2_session_recv_extension(void); -void test_nghttp2_session_recv_altsvc(void); -void test_nghttp2_session_recv_origin(void); -void test_nghttp2_session_recv_priority_update(void); -void test_nghttp2_session_continue(void); -void test_nghttp2_session_add_frame(void); -void test_nghttp2_session_on_request_headers_received(void); -void test_nghttp2_session_on_response_headers_received(void); -void test_nghttp2_session_on_headers_received(void); -void test_nghttp2_session_on_push_response_headers_received(void); -void test_nghttp2_session_on_priority_received(void); -void test_nghttp2_session_on_rst_stream_received(void); -void test_nghttp2_session_on_settings_received(void); -void test_nghttp2_session_on_push_promise_received(void); -void test_nghttp2_session_on_ping_received(void); -void test_nghttp2_session_on_goaway_received(void); -void test_nghttp2_session_on_window_update_received(void); -void test_nghttp2_session_on_data_received(void); -void test_nghttp2_session_on_data_received_fail_fast(void); -void test_nghttp2_session_on_altsvc_received(void); -void test_nghttp2_session_send_headers_start_stream(void); -void test_nghttp2_session_send_headers_reply(void); -void test_nghttp2_session_send_headers_frame_size_error(void); -void test_nghttp2_session_send_headers_push_reply(void); -void test_nghttp2_session_send_rst_stream(void); -void test_nghttp2_session_send_push_promise(void); -void test_nghttp2_session_is_my_stream_id(void); -void test_nghttp2_session_upgrade2(void); -void test_nghttp2_session_reprioritize_stream(void); -void test_nghttp2_session_reprioritize_stream_with_idle_stream_dep(void); -void test_nghttp2_submit_data(void); -void test_nghttp2_submit_data_read_length_too_large(void); -void test_nghttp2_submit_data_read_length_smallest(void); -void test_nghttp2_submit_data_twice(void); -void test_nghttp2_submit_request_with_data(void); -void test_nghttp2_submit_request_without_data(void); -void test_nghttp2_submit_response_with_data(void); -void test_nghttp2_submit_response_without_data(void); -void test_nghttp2_submit_response_push_response(void); -void test_nghttp2_submit_trailer(void); -void test_nghttp2_submit_headers_start_stream(void); -void test_nghttp2_submit_headers_reply(void); -void test_nghttp2_submit_headers_push_reply(void); -void test_nghttp2_submit_headers(void); -void test_nghttp2_submit_headers_continuation(void); -void test_nghttp2_submit_headers_continuation_extra_large(void); -void test_nghttp2_submit_priority(void); -void test_nghttp2_submit_settings(void); -void test_nghttp2_submit_settings_update_local_window_size(void); -void test_nghttp2_submit_settings_multiple_times(void); -void test_nghttp2_submit_push_promise(void); -void test_nghttp2_submit_window_update(void); -void test_nghttp2_submit_window_update_local_window_size(void); -void test_nghttp2_submit_shutdown_notice(void); -void test_nghttp2_submit_invalid_nv(void); -void test_nghttp2_submit_extension(void); -void test_nghttp2_submit_altsvc(void); -void test_nghttp2_submit_origin(void); -void test_nghttp2_submit_priority_update(void); -void test_nghttp2_submit_rst_stream(void); -void test_nghttp2_session_open_stream(void); -void test_nghttp2_session_open_stream_with_idle_stream_dep(void); -void test_nghttp2_session_get_next_ob_item(void); -void test_nghttp2_session_pop_next_ob_item(void); -void test_nghttp2_session_reply_fail(void); -void test_nghttp2_session_max_concurrent_streams(void); -void test_nghttp2_session_stop_data_with_rst_stream(void); -void test_nghttp2_session_defer_data(void); -void test_nghttp2_session_flow_control(void); -void test_nghttp2_session_flow_control_data_recv(void); -void test_nghttp2_session_flow_control_data_with_padding_recv(void); -void test_nghttp2_session_data_read_temporal_failure(void); -void test_nghttp2_session_on_stream_close(void); -void test_nghttp2_session_on_ctrl_not_send(void); -void test_nghttp2_session_get_outbound_queue_size(void); -void test_nghttp2_session_get_effective_local_window_size(void); -void test_nghttp2_session_set_option(void); -void test_nghttp2_session_data_backoff_by_high_pri_frame(void); -void test_nghttp2_session_pack_data_with_padding(void); -void test_nghttp2_session_pack_headers_with_padding(void); -void test_nghttp2_pack_settings_payload(void); -void test_nghttp2_session_stream_dep_add(void); -void test_nghttp2_session_stream_dep_remove(void); -void test_nghttp2_session_stream_dep_add_subtree(void); -void test_nghttp2_session_stream_dep_remove_subtree(void); -void test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us(void); -void test_nghttp2_session_stream_attach_item(void); -void test_nghttp2_session_stream_attach_item_subtree(void); -void test_nghttp2_session_stream_get_state(void); -void test_nghttp2_session_stream_get_something(void); -void test_nghttp2_session_find_stream(void); -void test_nghttp2_session_keep_closed_stream(void); -void test_nghttp2_session_keep_idle_stream(void); -void test_nghttp2_session_detach_idle_stream(void); -void test_nghttp2_session_large_dep_tree(void); -void test_nghttp2_session_graceful_shutdown(void); -void test_nghttp2_session_on_header_temporal_failure(void); -void test_nghttp2_session_recv_client_magic(void); -void test_nghttp2_session_delete_data_item(void); -void test_nghttp2_session_open_idle_stream(void); -void test_nghttp2_session_cancel_reserved_remote(void); -void test_nghttp2_session_reset_pending_headers(void); -void test_nghttp2_session_send_data_callback(void); -void test_nghttp2_session_on_begin_headers_temporal_failure(void); -void test_nghttp2_session_defer_then_close(void); -void test_nghttp2_session_detach_item_from_closed_stream(void); -void test_nghttp2_session_flooding(void); -void test_nghttp2_session_change_stream_priority(void); -void test_nghttp2_session_change_extpri_stream_priority(void); -void test_nghttp2_session_create_idle_stream(void); -void test_nghttp2_session_repeated_priority_change(void); -void test_nghttp2_session_repeated_priority_submission(void); -void test_nghttp2_session_set_local_window_size(void); -void test_nghttp2_session_cancel_from_before_frame_send(void); -void test_nghttp2_session_too_many_settings(void); -void test_nghttp2_session_removed_closed_stream(void); -void test_nghttp2_session_pause_data(void); -void test_nghttp2_session_no_closed_streams(void); -void test_nghttp2_session_set_stream_user_data(void); -void test_nghttp2_session_no_rfc7540_priorities(void); -void test_nghttp2_session_server_fallback_rfc7540_priorities(void); -void test_nghttp2_session_stream_reset_ratelim(void); -void test_nghttp2_http_mandatory_headers(void); -void test_nghttp2_http_content_length(void); -void test_nghttp2_http_content_length_mismatch(void); -void test_nghttp2_http_non_final_response(void); -void test_nghttp2_http_trailer_headers(void); -void test_nghttp2_http_ignore_regular_header(void); -void test_nghttp2_http_ignore_content_length(void); -void test_nghttp2_http_record_request_method(void); -void test_nghttp2_http_push_promise(void); -void test_nghttp2_http_head_method_upgrade_workaround(void); -void test_nghttp2_http_no_rfc9113_leading_and_trailing_ws_validation(void); +#define MUNIT_ENABLE_ASSERT_ALIASES + +#include "munit.h" + +extern const MunitSuite session_suite; + +munit_void_test_decl(test_nghttp2_session_recv); +munit_void_test_decl(test_nghttp2_session_recv_invalid_stream_id); +munit_void_test_decl(test_nghttp2_session_recv_invalid_frame); +munit_void_test_decl(test_nghttp2_session_recv_eof); +munit_void_test_decl(test_nghttp2_session_recv_data); +munit_void_test_decl(test_nghttp2_session_recv_data_no_auto_flow_control); +munit_void_test_decl(test_nghttp2_session_recv_continuation); +munit_void_test_decl(test_nghttp2_session_recv_headers_with_priority); +munit_void_test_decl(test_nghttp2_session_recv_headers_with_padding); +munit_void_test_decl(test_nghttp2_session_recv_headers_early_response); +munit_void_test_decl(test_nghttp2_session_recv_headers_for_closed_stream); +munit_void_test_decl(test_nghttp2_session_recv_headers_with_extpri); +munit_void_test_decl(test_nghttp2_session_server_recv_push_response); +munit_void_test_decl(test_nghttp2_session_recv_premature_headers); +munit_void_test_decl(test_nghttp2_session_recv_unknown_frame); +munit_void_test_decl(test_nghttp2_session_recv_unexpected_continuation); +munit_void_test_decl(test_nghttp2_session_recv_settings_header_table_size); +munit_void_test_decl(test_nghttp2_session_recv_too_large_frame_length); +munit_void_test_decl(test_nghttp2_session_recv_extension); +munit_void_test_decl(test_nghttp2_session_recv_altsvc); +munit_void_test_decl(test_nghttp2_session_recv_origin); +munit_void_test_decl(test_nghttp2_session_recv_priority_update); +munit_void_test_decl(test_nghttp2_session_continue); +munit_void_test_decl(test_nghttp2_session_add_frame); +munit_void_test_decl(test_nghttp2_session_on_request_headers_received); +munit_void_test_decl(test_nghttp2_session_on_response_headers_received); +munit_void_test_decl(test_nghttp2_session_on_headers_received); +munit_void_test_decl(test_nghttp2_session_on_push_response_headers_received); +munit_void_test_decl(test_nghttp2_session_on_priority_received); +munit_void_test_decl(test_nghttp2_session_on_rst_stream_received); +munit_void_test_decl(test_nghttp2_session_on_settings_received); +munit_void_test_decl(test_nghttp2_session_on_push_promise_received); +munit_void_test_decl(test_nghttp2_session_on_ping_received); +munit_void_test_decl(test_nghttp2_session_on_goaway_received); +munit_void_test_decl(test_nghttp2_session_on_window_update_received); +munit_void_test_decl(test_nghttp2_session_on_data_received); +munit_void_test_decl(test_nghttp2_session_on_data_received_fail_fast); +munit_void_test_decl(test_nghttp2_session_on_altsvc_received); +munit_void_test_decl(test_nghttp2_session_send_headers_start_stream); +munit_void_test_decl(test_nghttp2_session_send_headers_reply); +munit_void_test_decl(test_nghttp2_session_send_headers_frame_size_error); +munit_void_test_decl(test_nghttp2_session_send_headers_push_reply); +munit_void_test_decl(test_nghttp2_session_send_rst_stream); +munit_void_test_decl(test_nghttp2_session_send_push_promise); +munit_void_test_decl(test_nghttp2_session_is_my_stream_id); +munit_void_test_decl(test_nghttp2_session_upgrade2); +munit_void_test_decl(test_nghttp2_session_reprioritize_stream); +munit_void_test_decl( + test_nghttp2_session_reprioritize_stream_with_idle_stream_dep); +munit_void_test_decl(test_nghttp2_submit_data); +munit_void_test_decl(test_nghttp2_submit_data_read_length_too_large); +munit_void_test_decl(test_nghttp2_submit_data_read_length_smallest); +munit_void_test_decl(test_nghttp2_submit_data_twice); +munit_void_test_decl(test_nghttp2_submit_request_with_data); +munit_void_test_decl(test_nghttp2_submit_request_without_data); +munit_void_test_decl(test_nghttp2_submit_response_with_data); +munit_void_test_decl(test_nghttp2_submit_response_without_data); +munit_void_test_decl(test_nghttp2_submit_response_push_response); +munit_void_test_decl(test_nghttp2_submit_trailer); +munit_void_test_decl(test_nghttp2_submit_headers_start_stream); +munit_void_test_decl(test_nghttp2_submit_headers_reply); +munit_void_test_decl(test_nghttp2_submit_headers_push_reply); +munit_void_test_decl(test_nghttp2_submit_headers); +munit_void_test_decl(test_nghttp2_submit_headers_continuation); +munit_void_test_decl(test_nghttp2_submit_headers_continuation_extra_large); +munit_void_test_decl(test_nghttp2_submit_priority); +munit_void_test_decl(test_nghttp2_submit_settings); +munit_void_test_decl(test_nghttp2_submit_settings_update_local_window_size); +munit_void_test_decl(test_nghttp2_submit_settings_multiple_times); +munit_void_test_decl(test_nghttp2_submit_push_promise); +munit_void_test_decl(test_nghttp2_submit_window_update); +munit_void_test_decl(test_nghttp2_submit_window_update_local_window_size); +munit_void_test_decl(test_nghttp2_submit_shutdown_notice); +munit_void_test_decl(test_nghttp2_submit_invalid_nv); +munit_void_test_decl(test_nghttp2_submit_extension); +munit_void_test_decl(test_nghttp2_submit_altsvc); +munit_void_test_decl(test_nghttp2_submit_origin); +munit_void_test_decl(test_nghttp2_submit_priority_update); +munit_void_test_decl(test_nghttp2_submit_rst_stream); +munit_void_test_decl(test_nghttp2_session_open_stream); +munit_void_test_decl(test_nghttp2_session_open_stream_with_idle_stream_dep); +munit_void_test_decl(test_nghttp2_session_get_next_ob_item); +munit_void_test_decl(test_nghttp2_session_pop_next_ob_item); +munit_void_test_decl(test_nghttp2_session_reply_fail); +munit_void_test_decl(test_nghttp2_session_max_concurrent_streams); +munit_void_test_decl(test_nghttp2_session_stop_data_with_rst_stream); +munit_void_test_decl(test_nghttp2_session_defer_data); +munit_void_test_decl(test_nghttp2_session_flow_control); +munit_void_test_decl(test_nghttp2_session_flow_control_data_recv); +munit_void_test_decl(test_nghttp2_session_flow_control_data_with_padding_recv); +munit_void_test_decl(test_nghttp2_session_data_read_temporal_failure); +munit_void_test_decl(test_nghttp2_session_on_stream_close); +munit_void_test_decl(test_nghttp2_session_on_ctrl_not_send); +munit_void_test_decl(test_nghttp2_session_get_outbound_queue_size); +munit_void_test_decl(test_nghttp2_session_get_effective_local_window_size); +munit_void_test_decl(test_nghttp2_session_set_option); +munit_void_test_decl(test_nghttp2_session_data_backoff_by_high_pri_frame); +munit_void_test_decl(test_nghttp2_session_pack_data_with_padding); +munit_void_test_decl(test_nghttp2_session_pack_headers_with_padding); +munit_void_test_decl(test_nghttp2_pack_settings_payload); +munit_void_test_decl(test_nghttp2_session_stream_dep_add); +munit_void_test_decl(test_nghttp2_session_stream_dep_remove); +munit_void_test_decl(test_nghttp2_session_stream_dep_add_subtree); +munit_void_test_decl(test_nghttp2_session_stream_dep_remove_subtree); +munit_void_test_decl( + test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us); +munit_void_test_decl(test_nghttp2_session_stream_attach_item); +munit_void_test_decl(test_nghttp2_session_stream_attach_item_subtree); +munit_void_test_decl(test_nghttp2_session_stream_get_state); +munit_void_test_decl(test_nghttp2_session_stream_get_something); +munit_void_test_decl(test_nghttp2_session_find_stream); +munit_void_test_decl(test_nghttp2_session_keep_closed_stream); +munit_void_test_decl(test_nghttp2_session_keep_idle_stream); +munit_void_test_decl(test_nghttp2_session_detach_idle_stream); +munit_void_test_decl(test_nghttp2_session_large_dep_tree); +munit_void_test_decl(test_nghttp2_session_graceful_shutdown); +munit_void_test_decl(test_nghttp2_session_on_header_temporal_failure); +munit_void_test_decl(test_nghttp2_session_recv_client_magic); +munit_void_test_decl(test_nghttp2_session_delete_data_item); +munit_void_test_decl(test_nghttp2_session_open_idle_stream); +munit_void_test_decl(test_nghttp2_session_cancel_reserved_remote); +munit_void_test_decl(test_nghttp2_session_reset_pending_headers); +munit_void_test_decl(test_nghttp2_session_send_data_callback); +munit_void_test_decl(test_nghttp2_session_on_begin_headers_temporal_failure); +munit_void_test_decl(test_nghttp2_session_defer_then_close); +munit_void_test_decl(test_nghttp2_session_detach_item_from_closed_stream); +munit_void_test_decl(test_nghttp2_session_flooding); +munit_void_test_decl(test_nghttp2_session_change_stream_priority); +munit_void_test_decl(test_nghttp2_session_change_extpri_stream_priority); +munit_void_test_decl(test_nghttp2_session_create_idle_stream); +munit_void_test_decl(test_nghttp2_session_repeated_priority_change); +munit_void_test_decl(test_nghttp2_session_repeated_priority_submission); +munit_void_test_decl(test_nghttp2_session_set_local_window_size); +munit_void_test_decl(test_nghttp2_session_cancel_from_before_frame_send); +munit_void_test_decl(test_nghttp2_session_too_many_settings); +munit_void_test_decl(test_nghttp2_session_removed_closed_stream); +munit_void_test_decl(test_nghttp2_session_pause_data); +munit_void_test_decl(test_nghttp2_session_no_closed_streams); +munit_void_test_decl(test_nghttp2_session_set_stream_user_data); +munit_void_test_decl(test_nghttp2_session_no_rfc7540_priorities); +munit_void_test_decl(test_nghttp2_session_server_fallback_rfc7540_priorities); +munit_void_test_decl(test_nghttp2_session_stream_reset_ratelim); +munit_void_test_decl(test_nghttp2_http_mandatory_headers); +munit_void_test_decl(test_nghttp2_http_content_length); +munit_void_test_decl(test_nghttp2_http_content_length_mismatch); +munit_void_test_decl(test_nghttp2_http_non_final_response); +munit_void_test_decl(test_nghttp2_http_trailer_headers); +munit_void_test_decl(test_nghttp2_http_ignore_regular_header); +munit_void_test_decl(test_nghttp2_http_ignore_content_length); +munit_void_test_decl(test_nghttp2_http_record_request_method); +munit_void_test_decl(test_nghttp2_http_push_promise); +munit_void_test_decl(test_nghttp2_http_head_method_upgrade_workaround); +munit_void_test_decl( + test_nghttp2_http_no_rfc9113_leading_and_trailing_ws_validation); #endif /* NGHTTP2_SESSION_TEST_H */ diff --git a/tests/nghttp2_stream_test.c b/tests/nghttp2_stream_test.c index 75b4d68..91be376 100644 --- a/tests/nghttp2_stream_test.c +++ b/tests/nghttp2_stream_test.c @@ -26,6 +26,4 @@ #include <stdio.h> -#include <CUnit/CUnit.h> - #include "nghttp2_stream.h" diff --git a/tests/nghttp2_test_helper.c b/tests/nghttp2_test_helper.c index 1bd4a63..c1b912b 100644 --- a/tests/nghttp2_test_helper.c +++ b/tests/nghttp2_test_helper.c @@ -27,8 +27,6 @@ #include <stdio.h> #include <assert.h> -#include <CUnit/CUnit.h> - #include "nghttp2_helper.h" #include "nghttp2_priority_spec.h" @@ -155,9 +153,9 @@ void add_out(nva_out *out, nghttp2_nv *nv, nghttp2_mem *mem) { ++out->nvlen; } -ssize_t inflate_hd(nghttp2_hd_inflater *inflater, nva_out *out, - nghttp2_bufs *bufs, size_t offset, nghttp2_mem *mem) { - ssize_t rv; +nghttp2_ssize inflate_hd(nghttp2_hd_inflater *inflater, nva_out *out, + nghttp2_bufs *bufs, size_t offset, nghttp2_mem *mem) { + nghttp2_ssize rv; nghttp2_nv nv; int inflate_flags; nghttp2_buf_chain *ci; @@ -183,7 +181,7 @@ ssize_t inflate_hd(nghttp2_hd_inflater *inflater, nva_out *out, for (;;) { inflate_flags = 0; - rv = nghttp2_hd_inflate_hd2(inflater, &nv, &inflate_flags, bp.pos, + rv = nghttp2_hd_inflate_hd3(inflater, &nv, &inflate_flags, bp.pos, nghttp2_buf_len(&bp), fin); if (rv < 0) { @@ -210,7 +208,7 @@ ssize_t inflate_hd(nghttp2_hd_inflater *inflater, nva_out *out, nghttp2_hd_inflate_end_headers(inflater); - return (ssize_t)processed; + return (nghttp2_ssize)processed; } int pack_headers(nghttp2_bufs *bufs, nghttp2_hd_deflater *deflater, diff --git a/tests/nghttp2_test_helper.h b/tests/nghttp2_test_helper.h index c66298a..c0ed0b3 100644 --- a/tests/nghttp2_test_helper.h +++ b/tests/nghttp2_test_helper.h @@ -40,24 +40,6 @@ } #define ARRLEN(ARR) (sizeof(ARR) / sizeof(ARR[0])) -#define assert_nv_equal(A, B, len, mem) \ - do { \ - size_t alloclen = sizeof(nghttp2_nv) * len; \ - const nghttp2_nv *sa = A, *sb = B; \ - nghttp2_nv *a = mem->malloc(alloclen, NULL); \ - nghttp2_nv *b = mem->malloc(alloclen, NULL); \ - ssize_t i_; \ - memcpy(a, sa, alloclen); \ - memcpy(b, sb, alloclen); \ - nghttp2_nv_array_sort(a, len); \ - nghttp2_nv_array_sort(b, len); \ - for (i_ = 0; i_ < (ssize_t)len; ++i_) { \ - CU_ASSERT(nghttp2_nv_equal(&a[i_], &b[i_])); \ - } \ - mem->free(b, NULL); \ - mem->free(a, NULL); \ - } while (0); - int unpack_framebuf(nghttp2_frame *frame, nghttp2_bufs *bufs); int unpack_frame(nghttp2_frame *frame, const uint8_t *in, size_t len); @@ -78,8 +60,8 @@ void nva_out_reset(nva_out *out, nghttp2_mem *mem); void add_out(nva_out *out, nghttp2_nv *nv, nghttp2_mem *mem); -ssize_t inflate_hd(nghttp2_hd_inflater *inflater, nva_out *out, - nghttp2_bufs *bufs, size_t offset, nghttp2_mem *mem); +nghttp2_ssize inflate_hd(nghttp2_hd_inflater *inflater, nva_out *out, + nghttp2_bufs *bufs, size_t offset, nghttp2_mem *mem); int pack_headers(nghttp2_bufs *bufs, nghttp2_hd_deflater *deflater, int32_t stream_id, uint8_t flags, const nghttp2_nv *nva, diff --git a/third-party/Makefile.am b/third-party/Makefile.am index 8b47532..07c2f78 100644 --- a/third-party/Makefile.am +++ b/third-party/Makefile.am @@ -29,11 +29,15 @@ EXTRA_DIST = CMakeLists.txt build_config.rb # find mruby -type f ! -ipath 'mruby/.*' | awk '{print "\t"$0" \\"}' EXTRA_DIST += \ mruby/AUTHORS \ + mruby/docker-compose.yml \ mruby/codespell.txt \ mruby/CONTRIBUTING.md \ mruby/NEWS \ mruby/CODEOWNERS \ + mruby/Gemfile.lock \ mruby/appveyor.yml \ + mruby/Dockerfile \ + mruby/Gemfile \ mruby/benchmark/plot.gpl \ mruby/benchmark/bm_ao_render.rb \ mruby/benchmark/bm_fib.rb \ @@ -52,6 +56,7 @@ EXTRA_DIST += \ mruby/tasks/benchmark.rake \ mruby/tasks/mrbgems.rake \ mruby/tasks/presym.rake \ + mruby/tasks/install.rake \ mruby/tasks/bin.rake \ mruby/tasks/test.rake \ mruby/tasks/mrblib.rake \ @@ -66,6 +71,8 @@ EXTRA_DIST += \ mruby/oss-fuzz/proto_to_ruby.h \ mruby/build_config/cross-mingw-winetest.rb \ mruby/build_config/host-f32.rb \ + mruby/build_config/nintendo_wii.rb \ + mruby/build_config/i586-pc-msdosdjgpp.rb \ mruby/build_config/chipKITMax32.rb \ mruby/build_config/gameboyadvance.rb \ mruby/build_config/minimal.rb \ @@ -90,7 +97,6 @@ EXTRA_DIST += \ mruby/build_config/clang-asan.rb \ mruby/build_config/RX630.rb \ mruby/build_config/host-nofloat.rb \ - mruby/build_config/android_armeabi.rb \ mruby/build_config/android_arm64_v8a.rb \ mruby/build_config/cross-32bit.rb \ mruby/build_config/cross-mingw.rb \ @@ -170,7 +176,6 @@ EXTRA_DIST += \ mruby/test/t/standarderror.rb \ mruby/test/t/superclass.rb \ mruby/test/assert.rb \ - mruby/super-linter.report/.keep \ mruby/TODO.md \ mruby/Doxyfile \ mruby/mrblib/00kernel.rb \ @@ -220,11 +225,12 @@ EXTRA_DIST += \ mruby/src/array.c \ mruby/src/dump.c \ mruby/src/class.c \ - mruby/src/compar.c \ mruby/src/value_array.h \ + mruby/src/allocf.c \ mruby/src/pool.c \ mruby/mruby-source.gemspec \ mruby/mrbgems/mruby-eval/mrbgem.rake \ + mruby/mrbgems/mruby-eval/test/binding.rb \ mruby/mrbgems/mruby-eval/test/eval.rb \ mruby/mrbgems/mruby-eval/src/eval.c \ mruby/mrbgems/stdlib.gembox \ @@ -244,7 +250,6 @@ EXTRA_DIST += \ mruby/mrbgems/mruby-method/mrbgem.rake \ mruby/mrbgems/mruby-method/README.md \ mruby/mrbgems/mruby-method/test/method.rb \ - mruby/mrbgems/mruby-method/mrblib/kernel.rb \ mruby/mrbgems/mruby-method/mrblib/method.rb \ mruby/mrbgems/mruby-method/src/method.c \ mruby/mrbgems/mruby-random/mrbgem.rake \ @@ -368,7 +373,6 @@ EXTRA_DIST += \ mruby/mrbgems/mruby-test-inline-struct/test/inline.rb \ mruby/mrbgems/mruby-time/mrbgem.rake \ mruby/mrbgems/mruby-time/test/time.rb \ - mruby/mrbgems/mruby-time/mrblib/time.rb \ mruby/mrbgems/mruby-time/src/time.c \ mruby/mrbgems/mruby-time/include/mruby/time.h \ mruby/mrbgems/mruby-proc-binding/mrbgem.rake \ @@ -408,10 +412,9 @@ EXTRA_DIST += \ mruby/mrbgems/mruby-numeric-ext/test/numeric.rb \ mruby/mrbgems/mruby-numeric-ext/mrblib/numeric_ext.rb \ mruby/mrbgems/mruby-numeric-ext/src/numeric_ext.c \ - mruby/mrbgems/mruby-binding-core/mrbgem.rake \ - mruby/mrbgems/mruby-binding-core/test/binding-core.rb \ - mruby/mrbgems/mruby-binding-core/src/binding-core.c \ mruby/mrbgems/mruby-fiber/mrbgem.rake \ + mruby/mrbgems/mruby-fiber/test/fiber2.rb \ + mruby/mrbgems/mruby-fiber/test/fibertest.c \ mruby/mrbgems/mruby-fiber/test/fiber.rb \ mruby/mrbgems/mruby-fiber/src/fiber.c \ mruby/mrbgems/mruby-complex/mrbgem.rake \ @@ -496,7 +499,9 @@ EXTRA_DIST += \ mruby/doc/internal/boxing.md \ mruby/doc/limitations.md \ mruby/doc/mruby3.2.md \ + mruby/doc/mruby3.3.md \ mruby/doc/guides/compile.md \ + mruby/doc/guides/memory.md \ mruby/doc/guides/mrbgems.md \ mruby/doc/guides/debugger.md \ mruby/doc/guides/link.md \ @@ -558,7 +563,7 @@ libllhttp_la_CPPFLAGS = -I${srcdir}/llhttp/include if HAVE_NEVERBLEED noinst_LTLIBRARIES += libneverbleed.la -libneverbleed_la_CPPFLAGS = @OPENSSL_CFLAGS@ +libneverbleed_la_CPPFLAGS = @OPENSSL_CFLAGS@ -D_GNU_SOURCE libneverbleed_la_LIBADD = @OPENSSL_LIBS@ libneverbleed_la_SOURCES = neverbleed/neverbleed.c neverbleed/neverbleed.h endif # HAVE_NEVERBLEED diff --git a/third-party/build_config.rb b/third-party/build_config.rb index e06a4cc..5d003f2 100644 --- a/third-party/build_config.rb +++ b/third-party/build_config.rb @@ -18,8 +18,30 @@ def config(conf) conf.build_dir = ENV['BUILD_DIR'] - # include the default GEMs - conf.gembox 'default' + # Here is the mruby gems included in default.gembox minus + # mruby-bin-debugger which causes the application to crash. + conf.gembox "stdlib" + conf.gembox "stdlib-ext" + conf.gembox "stdlib-io" + conf.gembox "math" + conf.gembox "metaprog" + + # Generate mrbc command + conf.gem :core => "mruby-bin-mrbc" + + # Generate mirb command + conf.gem :core => "mruby-bin-mirb" + + # Generate mruby command + conf.gem :core => "mruby-bin-mruby" + + # Generate mruby-strip command + conf.gem :core => "mruby-bin-strip" + + # Generate mruby-config command + conf.gem :core => "mruby-bin-config" + + # Added by nghttp2 project conf.gem :core => 'mruby-eval' end diff --git a/third-party/llhttp/README.md b/third-party/llhttp/README.md index e982ed0..28653aa 100644 --- a/third-party/llhttp/README.md +++ b/third-party/llhttp/README.md @@ -363,6 +363,16 @@ With this flag only a CR is required to terminate such sections. **Enabling this flag can pose a security issue since you will be exposed to request smuggling attacks. USE WITH CAUTION!** +### `void llhttp_set_lenient_optional_cr_before_lf(llhttp_t* parser, int enabled)` + +Enables/disables lenient handling of line separators. + +Normally `llhttp` would error when a LF is not preceded by CR when terminating the +request line, the status line, the headers, a chunk header or a chunk data. +With this flag only a LF is required to terminate such sections. + +**Enabling this flag can pose a security issue since you will be exposed to request smuggling attacks. USE WITH CAUTION!** + ### `void llhttp_set_lenient_optional_crlf_after_chunk(llhttp_t* parser, int enabled)` Enables/disables lenient handling of chunks not separated via CRLF. @@ -373,12 +383,21 @@ With this flag the new chunk can start immediately after the previous one. **Enabling this flag can pose a security issue since you will be exposed to request smuggling attacks. USE WITH CAUTION!** +### `void llhttp_set_lenient_spaces_after_chunk_size(llhttp_t* parser, int enabled)` + +Enables/disables lenient handling of spaces after chunk size. + +Normally `llhttp` would error when after a chunk size is followed by one or more spaces are present instead of a CRLF or `;`. +With this flag this check is disabled. + +**Enabling this flag can pose a security issue since you will be exposed to request smuggling attacks. USE WITH CAUTION!** + ## Build Instructions Make sure you have [Node.js](https://nodejs.org/), npm and npx installed. Then under project directory run: ```sh -npm install +npm ci make ``` @@ -432,7 +451,7 @@ _Note that using the git repo directly (e.g., via a git repo url and tag) will n 1. Ensure that `Clang` and `make` are in your system path. 2. Using Git Bash, clone the repo to your preferred location. -3. Cd into the cloned directory and run `npm install` +3. Cd into the cloned directory and run `npm ci` 5. Run `make` 6. Your `repo/build` directory should now have `libllhttp.a` and `libllhttp.so` static and dynamic libraries. 7. When building your executable, you can link to these libraries. Make sure to set the build folder as an include path when building so you can reference the declarations in `repo/build/llhttp.h`. diff --git a/third-party/llhttp/include/llhttp.h b/third-party/llhttp/include/llhttp.h index 6588ae5..6919693 100644 --- a/third-party/llhttp/include/llhttp.h +++ b/third-party/llhttp/include/llhttp.h @@ -3,8 +3,8 @@ #define INCLUDE_LLHTTP_H_ #define LLHTTP_VERSION_MAJOR 9 -#define LLHTTP_VERSION_MINOR 0 -#define LLHTTP_VERSION_PATCH 1 +#define LLHTTP_VERSION_MINOR 2 +#define LLHTTP_VERSION_PATCH 0 #ifndef INCLUDE_LLHTTP_ITSELF_H_ #define INCLUDE_LLHTTP_ITSELF_H_ @@ -30,7 +30,7 @@ struct llhttp__internal_s { uint8_t http_major; uint8_t http_minor; uint8_t header_state; - uint8_t lenient_flags; + uint16_t lenient_flags; uint8_t upgrade; uint8_t finish; uint16_t flags; @@ -115,7 +115,9 @@ enum llhttp_lenient_flags { LENIENT_VERSION = 0x10, LENIENT_DATA_AFTER_CLOSE = 0x20, LENIENT_OPTIONAL_LF_AFTER_CR = 0x40, - LENIENT_OPTIONAL_CRLF_AFTER_CHUNK = 0x80 + LENIENT_OPTIONAL_CRLF_AFTER_CHUNK = 0x80, + LENIENT_OPTIONAL_CR_BEFORE_LF = 0x100, + LENIENT_SPACES_AFTER_CHUNK_SIZE = 0x200 }; typedef enum llhttp_lenient_flags llhttp_lenient_flags_t; @@ -179,7 +181,8 @@ enum llhttp_method { HTTP_SET_PARAMETER = 42, HTTP_REDIRECT = 43, HTTP_RECORD = 44, - HTTP_FLUSH = 45 + HTTP_FLUSH = 45, + HTTP_QUERY = 46 }; typedef enum llhttp_method llhttp_method_t; @@ -360,6 +363,7 @@ typedef enum llhttp_status llhttp_status_t; XX(31, LINK, LINK) \ XX(32, UNLINK, UNLINK) \ XX(33, SOURCE, SOURCE) \ + XX(46, QUERY, QUERY) \ #define RTSP_METHOD_MAP(XX) \ @@ -426,6 +430,7 @@ typedef enum llhttp_status llhttp_status_t; XX(43, REDIRECT, REDIRECT) \ XX(44, RECORD, RECORD) \ XX(45, FLUSH, FLUSH) \ + XX(46, QUERY, QUERY) \ #define HTTP_STATUS_MAP(XX) \ @@ -545,6 +550,8 @@ extern "C" { #if defined(__wasm__) #define LLHTTP_EXPORT __attribute__((visibility("default"))) +#elif defined(_WIN32) +#define LLHTTP_EXPORT __declspec(dllexport) #else #define LLHTTP_EXPORT #endif @@ -807,7 +814,7 @@ void llhttp_set_lenient_keep_alive(llhttp_t* parser, int enabled); * avoid request smuggling. * With this flag the extra value will be parsed normally. * - * **Enabling this flag can pose a security issue since you will be exposed to + * **Enabling this flag can pose a security issue since you will be exposed to * request smuggling attacks. USE WITH CAUTION!** */ LLHTTP_EXPORT @@ -850,6 +857,19 @@ void llhttp_set_lenient_data_after_close(llhttp_t* parser, int enabled); LLHTTP_EXPORT void llhttp_set_lenient_optional_lf_after_cr(llhttp_t* parser, int enabled); +/* + * Enables/disables lenient handling of line separators. + * + * Normally `llhttp` would error when a LF is not preceded by CR when terminating the + * request line, the status line, the headers, a chunk header or a chunk data. + * With this flag only a LF is required to terminate such sections. + * + * **Enabling this flag can pose a security issue since you will be exposed to + * request smuggling attacks. USE WITH CAUTION!** + */ +LLHTTP_EXPORT +void llhttp_set_lenient_optional_cr_before_lf(llhttp_t* parser, int enabled); + /* Enables/disables lenient handling of chunks not separated via CRLF. * * Normally `llhttp` would error when after a chunk data a CRLF is missing before @@ -862,6 +882,18 @@ void llhttp_set_lenient_optional_lf_after_cr(llhttp_t* parser, int enabled); LLHTTP_EXPORT void llhttp_set_lenient_optional_crlf_after_chunk(llhttp_t* parser, int enabled); +/* Enables/disables lenient handling of spaces after chunk size. + * + * Normally `llhttp` would error when after a chunk size is followed by one or more + * spaces are present instead of a CRLF or `;`. + * With this flag this check is disabled. + * + * **Enabling this flag can pose a security issue since you will be exposed to + * request smuggling attacks. USE WITH CAUTION!** + */ +LLHTTP_EXPORT +void llhttp_set_lenient_spaces_after_chunk_size(llhttp_t* parser, int enabled); + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/third-party/llhttp/src/api.c b/third-party/llhttp/src/api.c index e0d0385..8c2ce3d 100644 --- a/third-party/llhttp/src/api.c +++ b/third-party/llhttp/src/api.c @@ -126,7 +126,7 @@ void llhttp_reset(llhttp_t* parser) { llhttp_type_t type = parser->type; const llhttp_settings_t* settings = parser->settings; void* data = parser->data; - uint8_t lenient_flags = parser->lenient_flags; + uint16_t lenient_flags = parser->lenient_flags; llhttp__internal_init(parser); @@ -315,6 +315,22 @@ void llhttp_set_lenient_optional_crlf_after_chunk(llhttp_t* parser, int enabled) } } +void llhttp_set_lenient_optional_cr_before_lf(llhttp_t* parser, int enabled) { + if (enabled) { + parser->lenient_flags |= LENIENT_OPTIONAL_CR_BEFORE_LF; + } else { + parser->lenient_flags &= ~LENIENT_OPTIONAL_CR_BEFORE_LF; + } +} + +void llhttp_set_lenient_spaces_after_chunk_size(llhttp_t* parser, int enabled) { + if (enabled) { + parser->lenient_flags |= LENIENT_SPACES_AFTER_CHUNK_SIZE; + } else { + parser->lenient_flags &= ~LENIENT_SPACES_AFTER_CHUNK_SIZE; + } +} + /* Callbacks */ diff --git a/third-party/llhttp/src/http.c b/third-party/llhttp/src/http.c index 3a66044..1ab91a5 100644 --- a/third-party/llhttp/src/http.c +++ b/third-party/llhttp/src/http.c @@ -39,13 +39,33 @@ int llhttp__after_headers_complete(llhttp_t* parser, const char* p, int hasBody; hasBody = parser->flags & F_CHUNKED || parser->content_length > 0; - if (parser->upgrade && (parser->method == HTTP_CONNECT || - (parser->flags & F_SKIPBODY) || !hasBody)) { + if ( + (parser->upgrade && (parser->method == HTTP_CONNECT || + (parser->flags & F_SKIPBODY) || !hasBody)) || + /* See RFC 2616 section 4.4 - 1xx e.g. Continue */ + (parser->type == HTTP_RESPONSE && parser->status_code == 101) + ) { /* Exit, the rest of the message is in a different protocol. */ return 1; } - if (parser->flags & F_SKIPBODY) { + if (parser->type == HTTP_RESPONSE && parser->status_code == 100) { + /* No body, restart as the message is complete */ + return 0; + } + + /* See RFC 2616 section 4.4 */ + if ( + parser->flags & F_SKIPBODY || /* response to a HEAD request */ + ( + parser->type == HTTP_RESPONSE && ( + parser->status_code == 102 || /* Processing */ + parser->status_code == 103 || /* Early Hints */ + parser->status_code == 204 || /* No Content */ + parser->status_code == 304 /* Not Modified */ + ) + ) + ) { return 0; } else if (parser->flags & F_CHUNKED) { /* chunked encoding - ignore Content-Length header, prepare for a chunk */ diff --git a/third-party/llhttp/src/llhttp.c b/third-party/llhttp/src/llhttp.c index 03f6d57..c08de64 100644 --- a/third-party/llhttp/src/llhttp.c +++ b/third-party/llhttp/src/llhttp.c @@ -22,148 +22,148 @@ typedef int (*llhttp__internal__span_cb)( llhttp__internal_t*, const char*, const char*); static const unsigned char llparse_blob0[] = { - 0xd, 0xa -}; -static const unsigned char llparse_blob1[] = { 'o', 'n' }; -static const unsigned char llparse_blob2[] = { +static const unsigned char llparse_blob1[] = { 'e', 'c', 't', 'i', 'o', 'n' }; -static const unsigned char llparse_blob3[] = { +static const unsigned char llparse_blob2[] = { 'l', 'o', 's', 'e' }; -static const unsigned char llparse_blob4[] = { +static const unsigned char llparse_blob3[] = { 'e', 'e', 'p', '-', 'a', 'l', 'i', 'v', 'e' }; -static const unsigned char llparse_blob5[] = { +static const unsigned char llparse_blob4[] = { 'p', 'g', 'r', 'a', 'd', 'e' }; -static const unsigned char llparse_blob6[] = { +static const unsigned char llparse_blob5[] = { 'c', 'h', 'u', 'n', 'k', 'e', 'd' }; #ifdef __SSE4_2__ -static const unsigned char ALIGN(16) llparse_blob7[] = { +static const unsigned char ALIGN(16) llparse_blob6[] = { 0x9, 0x9, ' ', '~', 0x80, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; #endif /* __SSE4_2__ */ #ifdef __SSE4_2__ -static const unsigned char ALIGN(16) llparse_blob8[] = { +static const unsigned char ALIGN(16) llparse_blob7[] = { '!', '!', '#', '\'', '*', '+', '-', '.', '0', '9', 'A', 'Z', '^', 'z', '|', '|' }; #endif /* __SSE4_2__ */ #ifdef __SSE4_2__ -static const unsigned char ALIGN(16) llparse_blob9[] = { +static const unsigned char ALIGN(16) llparse_blob8[] = { '~', '~', 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; #endif /* __SSE4_2__ */ -static const unsigned char llparse_blob10[] = { +static const unsigned char llparse_blob9[] = { 'e', 'n', 't', '-', 'l', 'e', 'n', 'g', 't', 'h' }; -static const unsigned char llparse_blob11[] = { +static const unsigned char llparse_blob10[] = { 'r', 'o', 'x', 'y', '-', 'c', 'o', 'n', 'n', 'e', 'c', 't', 'i', 'o', 'n' }; -static const unsigned char llparse_blob12[] = { +static const unsigned char llparse_blob11[] = { 'r', 'a', 'n', 's', 'f', 'e', 'r', '-', 'e', 'n', 'c', 'o', 'd', 'i', 'n', 'g' }; -static const unsigned char llparse_blob13[] = { +static const unsigned char llparse_blob12[] = { 'p', 'g', 'r', 'a', 'd', 'e' }; -static const unsigned char llparse_blob14[] = { +static const unsigned char llparse_blob13[] = { 'T', 'T', 'P', '/' }; -static const unsigned char llparse_blob15[] = { +static const unsigned char llparse_blob14[] = { 0xd, 0xa, 0xd, 0xa, 'S', 'M', 0xd, 0xa, 0xd, 0xa }; -static const unsigned char llparse_blob16[] = { +static const unsigned char llparse_blob15[] = { 'C', 'E', '/' }; -static const unsigned char llparse_blob17[] = { +static const unsigned char llparse_blob16[] = { 'T', 'S', 'P', '/' }; -static const unsigned char llparse_blob18[] = { +static const unsigned char llparse_blob17[] = { 'N', 'O', 'U', 'N', 'C', 'E' }; -static const unsigned char llparse_blob19[] = { +static const unsigned char llparse_blob18[] = { 'I', 'N', 'D' }; -static const unsigned char llparse_blob20[] = { +static const unsigned char llparse_blob19[] = { 'E', 'C', 'K', 'O', 'U', 'T' }; -static const unsigned char llparse_blob21[] = { +static const unsigned char llparse_blob20[] = { 'N', 'E', 'C', 'T' }; -static const unsigned char llparse_blob22[] = { +static const unsigned char llparse_blob21[] = { 'E', 'T', 'E' }; -static const unsigned char llparse_blob23[] = { +static const unsigned char llparse_blob22[] = { 'C', 'R', 'I', 'B', 'E' }; -static const unsigned char llparse_blob24[] = { +static const unsigned char llparse_blob23[] = { 'L', 'U', 'S', 'H' }; -static const unsigned char llparse_blob25[] = { +static const unsigned char llparse_blob24[] = { 'E', 'T' }; -static const unsigned char llparse_blob26[] = { +static const unsigned char llparse_blob25[] = { 'P', 'A', 'R', 'A', 'M', 'E', 'T', 'E', 'R' }; -static const unsigned char llparse_blob27[] = { +static const unsigned char llparse_blob26[] = { 'E', 'A', 'D' }; -static const unsigned char llparse_blob28[] = { +static const unsigned char llparse_blob27[] = { 'N', 'K' }; -static const unsigned char llparse_blob29[] = { +static const unsigned char llparse_blob28[] = { 'C', 'K' }; -static const unsigned char llparse_blob30[] = { +static const unsigned char llparse_blob29[] = { 'S', 'E', 'A', 'R', 'C', 'H' }; -static const unsigned char llparse_blob31[] = { +static const unsigned char llparse_blob30[] = { 'R', 'G', 'E' }; -static const unsigned char llparse_blob32[] = { +static const unsigned char llparse_blob31[] = { 'C', 'T', 'I', 'V', 'I', 'T', 'Y' }; -static const unsigned char llparse_blob33[] = { +static const unsigned char llparse_blob32[] = { 'L', 'E', 'N', 'D', 'A', 'R' }; -static const unsigned char llparse_blob34[] = { +static const unsigned char llparse_blob33[] = { 'V', 'E' }; -static const unsigned char llparse_blob35[] = { +static const unsigned char llparse_blob34[] = { 'O', 'T', 'I', 'F', 'Y' }; -static const unsigned char llparse_blob36[] = { +static const unsigned char llparse_blob35[] = { 'P', 'T', 'I', 'O', 'N', 'S' }; -static const unsigned char llparse_blob37[] = { +static const unsigned char llparse_blob36[] = { 'C', 'H' }; -static const unsigned char llparse_blob38[] = { +static const unsigned char llparse_blob37[] = { 'S', 'E' }; -static const unsigned char llparse_blob39[] = { +static const unsigned char llparse_blob38[] = { 'A', 'Y' }; -static const unsigned char llparse_blob40[] = { +static const unsigned char llparse_blob39[] = { 'S', 'T' }; -static const unsigned char llparse_blob41[] = { +static const unsigned char llparse_blob40[] = { 'I', 'N', 'D' }; -static const unsigned char llparse_blob42[] = { +static const unsigned char llparse_blob41[] = { 'A', 'T', 'C', 'H' }; -static const unsigned char llparse_blob43[] = { +static const unsigned char llparse_blob42[] = { 'G', 'E' }; +static const unsigned char llparse_blob43[] = { + 'U', 'E', 'R', 'Y' +}; static const unsigned char llparse_blob44[] = { 'I', 'N', 'D' }; @@ -229,7 +229,7 @@ struct llparse_match_s { }; typedef struct llparse_match_s llparse_match_t; -static llparse_match_t llparse__match_sequence_id( +static llparse_match_t llparse__match_sequence_to_lower( llhttp__internal_t* s, const unsigned char* p, const unsigned char* endp, const unsigned char* seq, uint32_t seq_len) { @@ -240,7 +240,7 @@ static llparse_match_t llparse__match_sequence_id( for (; p != endp; p++) { unsigned char current; - current = *p; + current = ((*p) >= 'A' && (*p) <= 'Z' ? (*p | 0x20) : (*p)); if (current == seq[index]) { if (++index == seq_len) { res.status = kMatchComplete; @@ -261,7 +261,7 @@ reset: return res; } -static llparse_match_t llparse__match_sequence_to_lower( +static llparse_match_t llparse__match_sequence_to_lower_unsafe( llhttp__internal_t* s, const unsigned char* p, const unsigned char* endp, const unsigned char* seq, uint32_t seq_len) { @@ -272,7 +272,7 @@ static llparse_match_t llparse__match_sequence_to_lower( for (; p != endp; p++) { unsigned char current; - current = ((*p) >= 'A' && (*p) <= 'Z' ? (*p | 0x20) : (*p)); + current = ((*p) | 0x20); if (current == seq[index]) { if (++index == seq_len) { res.status = kMatchComplete; @@ -293,7 +293,7 @@ reset: return res; } -static llparse_match_t llparse__match_sequence_to_lower_unsafe( +static llparse_match_t llparse__match_sequence_id( llhttp__internal_t* s, const unsigned char* p, const unsigned char* endp, const unsigned char* seq, uint32_t seq_len) { @@ -304,7 +304,7 @@ static llparse_match_t llparse__match_sequence_to_lower_unsafe( for (; p != endp; p++) { unsigned char current; - current = ((*p) | 0x20); + current = *p; if (current == seq[index]) { if (++index == seq_len) { res.status = kMatchComplete; @@ -330,23 +330,32 @@ enum llparse_state_e { s_n_llhttp__internal__n_closed, s_n_llhttp__internal__n_invoke_llhttp__after_message_complete, s_n_llhttp__internal__n_pause_1, + s_n_llhttp__internal__n_invoke_is_equal_upgrade, + s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_2, + s_n_llhttp__internal__n_chunk_data_almost_done_1, s_n_llhttp__internal__n_chunk_data_almost_done, s_n_llhttp__internal__n_consume_content_length, s_n_llhttp__internal__n_span_start_llhttp__on_body, s_n_llhttp__internal__n_invoke_is_equal_content_length, s_n_llhttp__internal__n_chunk_size_almost_done, + s_n_llhttp__internal__n_invoke_test_lenient_flags_9, s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete, s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_1, + s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_2, + s_n_llhttp__internal__n_invoke_test_lenient_flags_10, s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete, - s_n_llhttp__internal__n_chunk_extension_quoted_value_done, s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_1, - s_n_llhttp__internal__n_error_21, - s_n_llhttp__internal__n_chunk_extension_quoted_value, + s_n_llhttp__internal__n_chunk_extension_quoted_value_done, s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_2, - s_n_llhttp__internal__n_error_23, + s_n_llhttp__internal__n_error_30, + s_n_llhttp__internal__n_chunk_extension_quoted_value_quoted_pair, + s_n_llhttp__internal__n_error_31, + s_n_llhttp__internal__n_chunk_extension_quoted_value, + s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_3, + s_n_llhttp__internal__n_error_33, s_n_llhttp__internal__n_chunk_extension_value, s_n_llhttp__internal__n_span_start_llhttp__on_chunk_extension_value, - s_n_llhttp__internal__n_error_24, + s_n_llhttp__internal__n_error_34, s_n_llhttp__internal__n_chunk_extension_name, s_n_llhttp__internal__n_span_start_llhttp__on_chunk_extension_name, s_n_llhttp__internal__n_chunk_extensions, @@ -354,8 +363,6 @@ enum llparse_state_e { s_n_llhttp__internal__n_chunk_size, s_n_llhttp__internal__n_chunk_size_digit, s_n_llhttp__internal__n_invoke_update_content_length_1, - s_n_llhttp__internal__n_invoke_is_equal_upgrade, - s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_2, s_n_llhttp__internal__n_consume_content_length_1, s_n_llhttp__internal__n_span_start_llhttp__on_body_1, s_n_llhttp__internal__n_eof, @@ -370,8 +377,9 @@ enum llparse_state_e { s_n_llhttp__internal__n_header_value_discard_ws_almost_done, s_n_llhttp__internal__n_header_value_lws, s_n_llhttp__internal__n_header_value_almost_done, + s_n_llhttp__internal__n_invoke_test_lenient_flags_17, s_n_llhttp__internal__n_header_value_lenient, - s_n_llhttp__internal__n_error_41, + s_n_llhttp__internal__n_error_53, s_n_llhttp__internal__n_header_value_otherwise, s_n_llhttp__internal__n_header_value_connection_token, s_n_llhttp__internal__n_header_value_connection_ws, @@ -379,12 +387,12 @@ enum llparse_state_e { s_n_llhttp__internal__n_header_value_connection_2, s_n_llhttp__internal__n_header_value_connection_3, s_n_llhttp__internal__n_header_value_connection, - s_n_llhttp__internal__n_error_43, - s_n_llhttp__internal__n_error_44, + s_n_llhttp__internal__n_error_55, + s_n_llhttp__internal__n_error_56, s_n_llhttp__internal__n_header_value_content_length_ws, s_n_llhttp__internal__n_header_value_content_length, - s_n_llhttp__internal__n_error_46, - s_n_llhttp__internal__n_error_45, + s_n_llhttp__internal__n_error_58, + s_n_llhttp__internal__n_error_57, s_n_llhttp__internal__n_header_value_te_token_ows, s_n_llhttp__internal__n_header_value, s_n_llhttp__internal__n_header_value_te_token, @@ -392,6 +400,7 @@ enum llparse_state_e { s_n_llhttp__internal__n_header_value_te_chunked, s_n_llhttp__internal__n_span_start_llhttp__on_header_value_1, s_n_llhttp__internal__n_header_value_discard_ws, + s_n_llhttp__internal__n_invoke_load_header_state, s_n_llhttp__internal__n_invoke_llhttp__on_header_field_complete, s_n_llhttp__internal__n_header_field_general_otherwise, s_n_llhttp__internal__n_header_field_general, @@ -416,12 +425,12 @@ enum llparse_state_e { s_n_llhttp__internal__n_req_http_complete, s_n_llhttp__internal__n_invoke_load_method_1, s_n_llhttp__internal__n_invoke_llhttp__on_version_complete, - s_n_llhttp__internal__n_error_51, - s_n_llhttp__internal__n_error_57, + s_n_llhttp__internal__n_error_65, + s_n_llhttp__internal__n_error_72, s_n_llhttp__internal__n_req_http_minor, - s_n_llhttp__internal__n_error_58, + s_n_llhttp__internal__n_error_73, s_n_llhttp__internal__n_req_http_dot, - s_n_llhttp__internal__n_error_59, + s_n_llhttp__internal__n_error_74, s_n_llhttp__internal__n_req_http_major, s_n_llhttp__internal__n_span_start_llhttp__on_version, s_n_llhttp__internal__n_req_http_start_1, @@ -497,48 +506,49 @@ enum llparse_state_e { s_n_llhttp__internal__n_after_start_req_45, s_n_llhttp__internal__n_after_start_req_44, s_n_llhttp__internal__n_after_start_req_33, - s_n_llhttp__internal__n_after_start_req_48, + s_n_llhttp__internal__n_after_start_req_46, s_n_llhttp__internal__n_after_start_req_49, s_n_llhttp__internal__n_after_start_req_50, s_n_llhttp__internal__n_after_start_req_51, + s_n_llhttp__internal__n_after_start_req_52, + s_n_llhttp__internal__n_after_start_req_48, s_n_llhttp__internal__n_after_start_req_47, - s_n_llhttp__internal__n_after_start_req_46, - s_n_llhttp__internal__n_after_start_req_54, - s_n_llhttp__internal__n_after_start_req_56, - s_n_llhttp__internal__n_after_start_req_57, s_n_llhttp__internal__n_after_start_req_55, - s_n_llhttp__internal__n_after_start_req_53, + s_n_llhttp__internal__n_after_start_req_57, s_n_llhttp__internal__n_after_start_req_58, + s_n_llhttp__internal__n_after_start_req_56, + s_n_llhttp__internal__n_after_start_req_54, s_n_llhttp__internal__n_after_start_req_59, - s_n_llhttp__internal__n_after_start_req_52, - s_n_llhttp__internal__n_after_start_req_61, - s_n_llhttp__internal__n_after_start_req_62, s_n_llhttp__internal__n_after_start_req_60, - s_n_llhttp__internal__n_after_start_req_65, - s_n_llhttp__internal__n_after_start_req_67, - s_n_llhttp__internal__n_after_start_req_68, + s_n_llhttp__internal__n_after_start_req_53, + s_n_llhttp__internal__n_after_start_req_62, + s_n_llhttp__internal__n_after_start_req_63, + s_n_llhttp__internal__n_after_start_req_61, s_n_llhttp__internal__n_after_start_req_66, + s_n_llhttp__internal__n_after_start_req_68, s_n_llhttp__internal__n_after_start_req_69, + s_n_llhttp__internal__n_after_start_req_67, + s_n_llhttp__internal__n_after_start_req_70, + s_n_llhttp__internal__n_after_start_req_65, s_n_llhttp__internal__n_after_start_req_64, - s_n_llhttp__internal__n_after_start_req_63, s_n_llhttp__internal__n_after_start_req, s_n_llhttp__internal__n_span_start_llhttp__on_method_1, s_n_llhttp__internal__n_res_line_almost_done, + s_n_llhttp__internal__n_invoke_test_lenient_flags_29, s_n_llhttp__internal__n_res_status, s_n_llhttp__internal__n_span_start_llhttp__on_status, - s_n_llhttp__internal__n_res_status_start, s_n_llhttp__internal__n_res_status_code_otherwise, s_n_llhttp__internal__n_res_status_code_digit_3, s_n_llhttp__internal__n_res_status_code_digit_2, s_n_llhttp__internal__n_res_status_code_digit_1, s_n_llhttp__internal__n_res_after_version, s_n_llhttp__internal__n_invoke_llhttp__on_version_complete_1, - s_n_llhttp__internal__n_error_73, - s_n_llhttp__internal__n_error_85, + s_n_llhttp__internal__n_error_88, + s_n_llhttp__internal__n_error_102, s_n_llhttp__internal__n_res_http_minor, - s_n_llhttp__internal__n_error_86, + s_n_llhttp__internal__n_error_103, s_n_llhttp__internal__n_res_http_dot, - s_n_llhttp__internal__n_error_87, + s_n_llhttp__internal__n_error_104, s_n_llhttp__internal__n_res_http_major, s_n_llhttp__internal__n_span_start_llhttp__on_version_1, s_n_llhttp__internal__n_start_res, @@ -669,7 +679,21 @@ int llhttp__internal__c_test_lenient_flags( return (state->lenient_flags & 1) == 1; } -int llhttp__after_headers_complete( +int llhttp__internal__c_test_lenient_flags_1( + llhttp__internal_t* state, + const unsigned char* p, + const unsigned char* endp) { + return (state->lenient_flags & 256) == 256; +} + +int llhttp__internal__c_test_flags( + llhttp__internal_t* state, + const unsigned char* p, + const unsigned char* endp) { + return (state->flags & 128) == 128; +} + +int llhttp__on_chunk_complete( llhttp__internal_t* s, const unsigned char* p, const unsigned char* endp); @@ -677,6 +701,13 @@ int llhttp__on_message_complete( llhttp__internal_t* s, const unsigned char* p, const unsigned char* endp); +int llhttp__internal__c_is_equal_upgrade( + llhttp__internal_t* state, + const unsigned char* p, + const unsigned char* endp) { + return state->upgrade == 1; +} + int llhttp__after_message_complete( llhttp__internal_t* s, const unsigned char* p, const unsigned char* endp); @@ -719,6 +750,18 @@ int llhttp__internal__c_test_lenient_flags_3( return (state->lenient_flags & 32) == 32; } +int llhttp__before_headers_complete( + llhttp__internal_t* s, const unsigned char* p, + const unsigned char* endp); + +int llhttp__on_headers_complete( + llhttp__internal_t* s, const unsigned char* p, + const unsigned char* endp); + +int llhttp__after_headers_complete( + llhttp__internal_t* s, const unsigned char* p, + const unsigned char* endp); + int llhttp__internal__c_mul_add_content_length( llhttp__internal_t* state, const unsigned char* p, @@ -745,6 +788,13 @@ int llhttp__internal__c_mul_add_content_length( return 0; } +int llhttp__internal__c_test_lenient_flags_4( + llhttp__internal_t* state, + const unsigned char* p, + const unsigned char* endp) { + return (state->lenient_flags & 512) == 512; +} + int llhttp__on_chunk_header( llhttp__internal_t* s, const unsigned char* p, const unsigned char* endp); @@ -756,11 +806,7 @@ int llhttp__internal__c_is_equal_content_length( return state->content_length == 0; } -int llhttp__on_chunk_complete( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - -int llhttp__internal__c_test_lenient_flags_4( +int llhttp__internal__c_test_lenient_flags_7( llhttp__internal_t* state, const unsigned char* p, const unsigned char* endp) { @@ -775,7 +821,7 @@ int llhttp__internal__c_or_flags( return 0; } -int llhttp__internal__c_test_lenient_flags_5( +int llhttp__internal__c_test_lenient_flags_8( llhttp__internal_t* state, const unsigned char* p, const unsigned char* endp) { @@ -790,13 +836,6 @@ int llhttp__on_chunk_extension_value_complete( llhttp__internal_t* s, const unsigned char* p, const unsigned char* endp); -int llhttp__internal__c_is_equal_upgrade( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return state->upgrade == 1; -} - int llhttp__internal__c_update_finish_3( llhttp__internal_t* state, const unsigned char* p, @@ -805,35 +844,6 @@ int llhttp__internal__c_update_finish_3( return 0; } -int llhttp__internal__c_test_flags( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return (state->flags & 128) == 128; -} - -int llhttp__internal__c_test_flags_1( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return (state->flags & 544) == 544; -} - -int llhttp__internal__c_test_lenient_flags_6( - llhttp__internal_t* state, - const unsigned char* p, - const unsigned char* endp) { - return (state->lenient_flags & 2) == 2; -} - -int llhttp__before_headers_complete( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - -int llhttp__on_headers_complete( - llhttp__internal_t* s, const unsigned char* p, - const unsigned char* endp); - int llhttp__internal__c_or_flags_1( llhttp__internal_t* state, const unsigned char* p, @@ -870,7 +880,21 @@ int llhttp__internal__c_load_header_state( return state->header_state; } -int llhttp__internal__c_or_flags_3( +int llhttp__internal__c_test_flags_4( + llhttp__internal_t* state, + const unsigned char* p, + const unsigned char* endp) { + return (state->flags & 512) == 512; +} + +int llhttp__internal__c_test_lenient_flags_21( + llhttp__internal_t* state, + const unsigned char* p, + const unsigned char* endp) { + return (state->lenient_flags & 2) == 2; +} + +int llhttp__internal__c_or_flags_5( llhttp__internal_t* state, const unsigned char* p, const unsigned char* endp) { @@ -890,7 +914,7 @@ int llhttp__on_header_value_complete( llhttp__internal_t* s, const unsigned char* p, const unsigned char* endp); -int llhttp__internal__c_or_flags_4( +int llhttp__internal__c_or_flags_6( llhttp__internal_t* state, const unsigned char* p, const unsigned char* endp) { @@ -898,7 +922,7 @@ int llhttp__internal__c_or_flags_4( return 0; } -int llhttp__internal__c_or_flags_5( +int llhttp__internal__c_or_flags_7( llhttp__internal_t* state, const unsigned char* p, const unsigned char* endp) { @@ -906,7 +930,7 @@ int llhttp__internal__c_or_flags_5( return 0; } -int llhttp__internal__c_or_flags_6( +int llhttp__internal__c_or_flags_8( llhttp__internal_t* state, const unsigned char* p, const unsigned char* endp) { @@ -979,7 +1003,7 @@ int llhttp__internal__c_mul_add_content_length_1( return 0; } -int llhttp__internal__c_or_flags_15( +int llhttp__internal__c_or_flags_17( llhttp__internal_t* state, const unsigned char* p, const unsigned char* endp) { @@ -994,14 +1018,14 @@ int llhttp__internal__c_test_flags_3( return (state->flags & 8) == 8; } -int llhttp__internal__c_test_lenient_flags_13( +int llhttp__internal__c_test_lenient_flags_19( llhttp__internal_t* state, const unsigned char* p, const unsigned char* endp) { return (state->lenient_flags & 8) == 8; } -int llhttp__internal__c_or_flags_16( +int llhttp__internal__c_or_flags_18( llhttp__internal_t* state, const unsigned char* p, const unsigned char* endp) { @@ -1025,7 +1049,7 @@ int llhttp__internal__c_update_header_state_8( return 0; } -int llhttp__internal__c_or_flags_18( +int llhttp__internal__c_or_flags_20( llhttp__internal_t* state, const unsigned char* p, const unsigned char* endp) { @@ -1058,7 +1082,7 @@ int llhttp__internal__c_store_http_minor( return 0; } -int llhttp__internal__c_test_lenient_flags_15( +int llhttp__internal__c_test_lenient_flags_23( llhttp__internal_t* state, const unsigned char* p, const unsigned char* endp) { @@ -1192,25 +1216,63 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } + case s_n_llhttp__internal__n_invoke_is_equal_upgrade: + s_n_llhttp__internal__n_invoke_is_equal_upgrade: { + switch (llhttp__internal__c_is_equal_upgrade(state, p, endp)) { + case 0: + goto s_n_llhttp__internal__n_invoke_llhttp__after_message_complete; + default: + goto s_n_llhttp__internal__n_pause_1; + } + /* UNREACHABLE */; + abort(); + } + case s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_2: + s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_2: { + switch (llhttp__on_message_complete(state, p, endp)) { + case 0: + goto s_n_llhttp__internal__n_invoke_is_equal_upgrade; + case 21: + goto s_n_llhttp__internal__n_pause_13; + default: + goto s_n_llhttp__internal__n_error_38; + } + /* UNREACHABLE */; + abort(); + } + case s_n_llhttp__internal__n_chunk_data_almost_done_1: + s_n_llhttp__internal__n_chunk_data_almost_done_1: { + if (p == endp) { + return s_n_llhttp__internal__n_chunk_data_almost_done_1; + } + switch (*p) { + case 10: { + p++; + goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_complete; + } + default: { + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_7; + } + } + /* UNREACHABLE */; + abort(); + } case s_n_llhttp__internal__n_chunk_data_almost_done: s_n_llhttp__internal__n_chunk_data_almost_done: { - llparse_match_t match_seq; - if (p == endp) { return s_n_llhttp__internal__n_chunk_data_almost_done; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob0, 2); - p = match_seq.current; - switch (match_seq.status) { - case kMatchComplete: { + switch (*p) { + case 10: { p++; - goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_complete; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_6; } - case kMatchPause: { - return s_n_llhttp__internal__n_chunk_data_almost_done; + case 13: { + p++; + goto s_n_llhttp__internal__n_chunk_data_almost_done_1; } - case kMatchMismatch: { - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_4; + default: { + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_7; } } /* UNREACHABLE */; @@ -1267,21 +1329,32 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_header; } default: { - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_5; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_8; } } /* UNREACHABLE */; abort(); } + case s_n_llhttp__internal__n_invoke_test_lenient_flags_9: + s_n_llhttp__internal__n_invoke_test_lenient_flags_9: { + switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { + case 1: + goto s_n_llhttp__internal__n_chunk_size_almost_done; + default: + goto s_n_llhttp__internal__n_error_20; + } + /* UNREACHABLE */; + abort(); + } case s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete: s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete: { switch (llhttp__on_chunk_extension_name_complete(state, p, endp)) { case 0: - goto s_n_llhttp__internal__n_chunk_size_almost_done; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_9; case 21: goto s_n_llhttp__internal__n_pause_5; default: - goto s_n_llhttp__internal__n_error_15; + goto s_n_llhttp__internal__n_error_19; } /* UNREACHABLE */; abort(); @@ -1290,11 +1363,35 @@ static llparse_state_t llhttp__internal__run( s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_1: { switch (llhttp__on_chunk_extension_name_complete(state, p, endp)) { case 0: - goto s_n_llhttp__internal__n_chunk_extensions; + goto s_n_llhttp__internal__n_chunk_size_almost_done; case 21: goto s_n_llhttp__internal__n_pause_6; default: - goto s_n_llhttp__internal__n_error_16; + goto s_n_llhttp__internal__n_error_21; + } + /* UNREACHABLE */; + abort(); + } + case s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_2: + s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_2: { + switch (llhttp__on_chunk_extension_name_complete(state, p, endp)) { + case 0: + goto s_n_llhttp__internal__n_chunk_extensions; + case 21: + goto s_n_llhttp__internal__n_pause_7; + default: + goto s_n_llhttp__internal__n_error_22; + } + /* UNREACHABLE */; + abort(); + } + case s_n_llhttp__internal__n_invoke_test_lenient_flags_10: + s_n_llhttp__internal__n_invoke_test_lenient_flags_10: { + switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { + case 1: + goto s_n_llhttp__internal__n_chunk_size_almost_done; + default: + goto s_n_llhttp__internal__n_error_25; } /* UNREACHABLE */; abort(); @@ -1303,11 +1400,24 @@ static llparse_state_t llhttp__internal__run( s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete: { switch (llhttp__on_chunk_extension_value_complete(state, p, endp)) { case 0: + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_10; + case 21: + goto s_n_llhttp__internal__n_pause_8; + default: + goto s_n_llhttp__internal__n_error_24; + } + /* UNREACHABLE */; + abort(); + } + case s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_1: + s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_1: { + switch (llhttp__on_chunk_extension_value_complete(state, p, endp)) { + case 0: goto s_n_llhttp__internal__n_chunk_size_almost_done; case 21: - goto s_n_llhttp__internal__n_pause_7; + goto s_n_llhttp__internal__n_pause_9; default: - goto s_n_llhttp__internal__n_error_18; + goto s_n_llhttp__internal__n_error_26; } /* UNREACHABLE */; abort(); @@ -1318,6 +1428,9 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_chunk_extension_quoted_value_done; } switch (*p) { + case 10: { + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_11; + } case 13: { p++; goto s_n_llhttp__internal__n_chunk_size_almost_done; @@ -1327,27 +1440,72 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_chunk_extensions; } default: { - goto s_n_llhttp__internal__n_error_20; + goto s_n_llhttp__internal__n_error_29; } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_1: - s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_1: { + case s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_2: + s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_2: { switch (llhttp__on_chunk_extension_value_complete(state, p, endp)) { case 0: goto s_n_llhttp__internal__n_chunk_extension_quoted_value_done; case 21: - goto s_n_llhttp__internal__n_pause_8; + goto s_n_llhttp__internal__n_pause_10; default: - goto s_n_llhttp__internal__n_error_19; + goto s_n_llhttp__internal__n_error_27; } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_21: - s_n_llhttp__internal__n_error_21: { + case s_n_llhttp__internal__n_error_30: + s_n_llhttp__internal__n_error_30: { + state->error = 0x2; + state->reason = "Invalid quoted-pair in chunk extensions quoted value"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + case s_n_llhttp__internal__n_chunk_extension_quoted_value_quoted_pair: + s_n_llhttp__internal__n_chunk_extension_quoted_value_quoted_pair: { + static uint8_t lookup_table[] = { + 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, + 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, + 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, 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, 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, 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 + }; + if (p == endp) { + return s_n_llhttp__internal__n_chunk_extension_quoted_value_quoted_pair; + } + switch (lookup_table[(uint8_t) *p]) { + case 1: { + p++; + goto s_n_llhttp__internal__n_chunk_extension_quoted_value; + } + default: { + goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_3; + } + } + /* UNREACHABLE */; + abort(); + } + case s_n_llhttp__internal__n_error_31: + s_n_llhttp__internal__n_error_31: { state->error = 0x2; state->reason = "Invalid character in chunk extensions quoted value"; state->error_pos = (const char*) p; @@ -1364,7 +1522,7 @@ static llparse_state_t llhttp__internal__run( 1, 1, 2, 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, 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, 3, 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, 1, 1, 1, @@ -1386,30 +1544,34 @@ static llparse_state_t llhttp__internal__run( } case 2: { p++; - goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_1; + goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_2; + } + case 3: { + p++; + goto s_n_llhttp__internal__n_chunk_extension_quoted_value_quoted_pair; } default: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_2; + goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_4; } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_2: - s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_2: { + case s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_3: + s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_3: { switch (llhttp__on_chunk_extension_value_complete(state, p, endp)) { case 0: - goto s_n_llhttp__internal__n_chunk_size_otherwise; + goto s_n_llhttp__internal__n_chunk_extensions; case 21: - goto s_n_llhttp__internal__n_pause_9; + goto s_n_llhttp__internal__n_pause_11; default: - goto s_n_llhttp__internal__n_error_22; + goto s_n_llhttp__internal__n_error_32; } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_23: - s_n_llhttp__internal__n_error_23: { + case s_n_llhttp__internal__n_error_33: + s_n_llhttp__internal__n_error_33: { state->error = 0x2; state->reason = "Invalid character in chunk extensions value"; state->error_pos = (const char*) p; @@ -1421,14 +1583,14 @@ static llparse_state_t llhttp__internal__run( case s_n_llhttp__internal__n_chunk_extension_value: s_n_llhttp__internal__n_chunk_extension_value: { static uint8_t lookup_table[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 2, 3, 2, 2, 2, 2, 2, 0, 0, 2, 2, 0, 2, 2, 0, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 4, 0, 0, 0, 0, - 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 0, 2, 0, + 0, 3, 4, 3, 3, 3, 3, 3, 0, 0, 3, 3, 0, 3, 3, 0, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 5, 0, 0, 0, 0, + 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 3, 0, 3, 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, @@ -1446,18 +1608,21 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value; } case 2: { + goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_1; + } + case 3: { p++; goto s_n_llhttp__internal__n_chunk_extension_value; } - case 3: { + case 4: { p++; goto s_n_llhttp__internal__n_chunk_extension_quoted_value; } - case 4: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_3; + case 5: { + goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_5; } default: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_4; + goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_6; } } /* UNREACHABLE */; @@ -1470,12 +1635,12 @@ static llparse_state_t llhttp__internal__run( } state->_span_pos0 = (void*) p; state->_span_cb0 = llhttp__on_chunk_extension_value; - goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_2; + goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_3; /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_24: - s_n_llhttp__internal__n_error_24: { + case s_n_llhttp__internal__n_error_34: + s_n_llhttp__internal__n_error_34: { state->error = 0x2; state->reason = "Invalid character in chunk extensions name"; state->error_pos = (const char*) p; @@ -1487,14 +1652,14 @@ static llparse_state_t llhttp__internal__run( case s_n_llhttp__internal__n_chunk_extension_name: s_n_llhttp__internal__n_chunk_extension_name: { static uint8_t lookup_table[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 2, 0, 2, 2, 2, 2, 2, 0, 0, 2, 2, 0, 2, 2, 0, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 3, 0, 4, 0, 0, - 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 0, 2, 0, + 0, 3, 0, 3, 3, 3, 3, 3, 0, 0, 3, 3, 0, 3, 3, 0, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 4, 0, 5, 0, 0, + 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 3, 0, 3, 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, @@ -1512,18 +1677,21 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name; } case 2: { - p++; - goto s_n_llhttp__internal__n_chunk_extension_name; + goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name_1; } case 3: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name_1; + p++; + goto s_n_llhttp__internal__n_chunk_extension_name; } case 4: { goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name_2; } - default: { + case 5: { goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name_3; } + default: { + goto s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name_4; + } } /* UNREACHABLE */; abort(); @@ -1547,11 +1715,11 @@ static llparse_state_t llhttp__internal__run( switch (*p) { case 13: { p++; - goto s_n_llhttp__internal__n_error_13; + goto s_n_llhttp__internal__n_error_17; } case ' ': { p++; - goto s_n_llhttp__internal__n_error_14; + goto s_n_llhttp__internal__n_error_18; } default: { goto s_n_llhttp__internal__n_span_start_llhttp__on_chunk_extension_name; @@ -1566,16 +1734,28 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_chunk_size_otherwise; } switch (*p) { + case 9: { + p++; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_4; + } + case 10: { + p++; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_5; + } case 13: { p++; goto s_n_llhttp__internal__n_chunk_size_almost_done; } + case ' ': { + p++; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_4; + } case ';': { p++; goto s_n_llhttp__internal__n_chunk_extensions; } default: { - goto s_n_llhttp__internal__n_error_25; + goto s_n_llhttp__internal__n_error_35; } } /* UNREACHABLE */; @@ -1821,7 +2001,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_mul_add_content_length; } default: { - goto s_n_llhttp__internal__n_error_27; + goto s_n_llhttp__internal__n_error_37; } } /* UNREACHABLE */; @@ -1836,30 +2016,6 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_invoke_is_equal_upgrade: - s_n_llhttp__internal__n_invoke_is_equal_upgrade: { - switch (llhttp__internal__c_is_equal_upgrade(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_invoke_llhttp__after_message_complete; - default: - goto s_n_llhttp__internal__n_pause_1; - } - /* UNREACHABLE */; - abort(); - } - case s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_2: - s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_2: { - switch (llhttp__on_message_complete(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_invoke_is_equal_upgrade; - case 21: - goto s_n_llhttp__internal__n_pause_11; - default: - goto s_n_llhttp__internal__n_error_28; - } - /* UNREACHABLE */; - abort(); - } case s_n_llhttp__internal__n_consume_content_length_1: s_n_llhttp__internal__n_consume_content_length_1: { size_t avail; @@ -1922,7 +2078,7 @@ static llparse_state_t llhttp__internal__run( case 4: goto s_n_llhttp__internal__n_invoke_update_finish_3; case 5: - goto s_n_llhttp__internal__n_error_29; + goto s_n_llhttp__internal__n_error_39; default: goto s_n_llhttp__internal__n_invoke_llhttp__on_message_complete; } @@ -1947,10 +2103,10 @@ static llparse_state_t llhttp__internal__run( switch (*p) { case 10: { p++; - goto s_n_llhttp__internal__n_invoke_test_flags; + goto s_n_llhttp__internal__n_invoke_test_flags_1; } default: { - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_7; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_12; } } /* UNREACHABLE */; @@ -1979,9 +2135,9 @@ static llparse_state_t llhttp__internal__run( case 0: goto s_n_llhttp__internal__n_header_field_start; case 21: - goto s_n_llhttp__internal__n_pause_14; + goto s_n_llhttp__internal__n_pause_18; default: - goto s_n_llhttp__internal__n_error_37; + goto s_n_llhttp__internal__n_error_48; } /* UNREACHABLE */; abort(); @@ -2005,14 +2161,14 @@ static llparse_state_t llhttp__internal__run( switch (*p) { case 9: { p++; - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_10; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_15; } case ' ': { p++; - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_10; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_15; } default: { - goto s_n_llhttp__internal__n_invoke_load_header_state; + goto s_n_llhttp__internal__n_invoke_load_header_state_1; } } /* UNREACHABLE */; @@ -2029,7 +2185,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_header_value_discard_lws; } default: { - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_11; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_16; } } /* UNREACHABLE */; @@ -2042,13 +2198,13 @@ static llparse_state_t llhttp__internal__run( } switch (*p) { case 9: { - goto s_n_llhttp__internal__n_invoke_load_header_state_3; + goto s_n_llhttp__internal__n_invoke_load_header_state_4; } case ' ': { - goto s_n_llhttp__internal__n_invoke_load_header_state_3; + goto s_n_llhttp__internal__n_invoke_load_header_state_4; } default: { - goto s_n_llhttp__internal__n_invoke_load_header_state_4; + goto s_n_llhttp__internal__n_invoke_load_header_state_5; } } /* UNREACHABLE */; @@ -2065,12 +2221,23 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_header_value_lws; } default: { - goto s_n_llhttp__internal__n_error_40; + goto s_n_llhttp__internal__n_error_52; } } /* UNREACHABLE */; abort(); } + case s_n_llhttp__internal__n_invoke_test_lenient_flags_17: + s_n_llhttp__internal__n_invoke_test_lenient_flags_17: { + switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { + case 1: + goto s_n_llhttp__internal__n_header_value_almost_done; + default: + goto s_n_llhttp__internal__n_error_51; + } + /* UNREACHABLE */; + abort(); + } case s_n_llhttp__internal__n_header_value_lenient: s_n_llhttp__internal__n_header_value_lenient: { if (p == endp) { @@ -2078,10 +2245,10 @@ static llparse_state_t llhttp__internal__run( } switch (*p) { case 10: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_3; + goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_4; } case 13: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_4; + goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_5; } default: { p++; @@ -2091,8 +2258,8 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_41: - s_n_llhttp__internal__n_error_41: { + case s_n_llhttp__internal__n_error_53: + s_n_llhttp__internal__n_error_53: { state->error = 0xa; state->reason = "Invalid header value char"; state->error_pos = (const char*) p; @@ -2107,11 +2274,14 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_header_value_otherwise; } switch (*p) { - case 13: { + case 10: { goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_1; } + case 13: { + goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_2; + } default: { - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_12; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_18; } } /* UNREACHABLE */; @@ -2174,7 +2344,7 @@ static llparse_state_t llhttp__internal__run( } case ',': { p++; - goto s_n_llhttp__internal__n_invoke_load_header_state_5; + goto s_n_llhttp__internal__n_invoke_load_header_state_6; } default: { goto s_n_llhttp__internal__n_invoke_update_header_state_5; @@ -2190,7 +2360,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_header_value_connection_1; } - match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob3, 4); + match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob2, 4); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -2214,7 +2384,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_header_value_connection_2; } - match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob4, 9); + match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob3, 9); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -2238,7 +2408,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_header_value_connection_3; } - match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob5, 6); + match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob4, 6); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -2288,8 +2458,8 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_43: - s_n_llhttp__internal__n_error_43: { + case s_n_llhttp__internal__n_error_55: + s_n_llhttp__internal__n_error_55: { state->error = 0xb; state->reason = "Content-Length overflow"; state->error_pos = (const char*) p; @@ -2298,8 +2468,8 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_44: - s_n_llhttp__internal__n_error_44: { + case s_n_llhttp__internal__n_error_56: + s_n_llhttp__internal__n_error_56: { state->error = 0xb; state->reason = "Invalid character in Content-Length"; state->error_pos = (const char*) p; @@ -2315,17 +2485,17 @@ static llparse_state_t llhttp__internal__run( } switch (*p) { case 10: { - goto s_n_llhttp__internal__n_invoke_or_flags_15; + goto s_n_llhttp__internal__n_invoke_or_flags_17; } case 13: { - goto s_n_llhttp__internal__n_invoke_or_flags_15; + goto s_n_llhttp__internal__n_invoke_or_flags_17; } case ' ': { p++; goto s_n_llhttp__internal__n_header_value_content_length_ws; } default: { - goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_6; + goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_7; } } /* UNREACHABLE */; @@ -2394,8 +2564,8 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_46: - s_n_llhttp__internal__n_error_46: { + case s_n_llhttp__internal__n_error_58: + s_n_llhttp__internal__n_error_58: { state->error = 0xf; state->reason = "Invalid `Transfer-Encoding` header value"; state->error_pos = (const char*) p; @@ -2404,8 +2574,8 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_45: - s_n_llhttp__internal__n_error_45: { + case s_n_llhttp__internal__n_error_57: + s_n_llhttp__internal__n_error_57: { state->error = 0xf; state->reason = "Invalid `Transfer-Encoding` header value"; state->error_pos = (const char*) p; @@ -2467,7 +2637,7 @@ static llparse_state_t llhttp__internal__run( /* Load input */ input = _mm_loadu_si128((__m128i const*) p); - ranges = _mm_loadu_si128((__m128i const*) llparse_blob7); + ranges = _mm_loadu_si128((__m128i const*) llparse_blob6); /* Find first character that does not match `ranges` */ match_len = _mm_cmpestri(ranges, 6, @@ -2566,7 +2736,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_header_value_te_chunked; } - match_seq = llparse__match_sequence_to_lower_unsafe(state, p, endp, llparse_blob6, 7); + match_seq = llparse__match_sequence_to_lower_unsafe(state, p, endp, llparse_blob5, 7); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -2590,7 +2760,7 @@ static llparse_state_t llhttp__internal__run( } state->_span_pos0 = (void*) p; state->_span_cb0 = llhttp__on_header_value; - goto s_n_llhttp__internal__n_invoke_load_header_state_2; + goto s_n_llhttp__internal__n_invoke_load_header_state_3; /* UNREACHABLE */; abort(); } @@ -2606,7 +2776,7 @@ static llparse_state_t llhttp__internal__run( } case 10: { p++; - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_9; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_14; } case 13: { p++; @@ -2623,15 +2793,28 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } + case s_n_llhttp__internal__n_invoke_load_header_state: + s_n_llhttp__internal__n_invoke_load_header_state: { + switch (llhttp__internal__c_load_header_state(state, p, endp)) { + case 2: + goto s_n_llhttp__internal__n_invoke_test_flags_4; + case 3: + goto s_n_llhttp__internal__n_invoke_test_flags_5; + default: + goto s_n_llhttp__internal__n_header_value_discard_ws; + } + /* UNREACHABLE */; + abort(); + } case s_n_llhttp__internal__n_invoke_llhttp__on_header_field_complete: s_n_llhttp__internal__n_invoke_llhttp__on_header_field_complete: { switch (llhttp__on_header_field_complete(state, p, endp)) { case 0: - goto s_n_llhttp__internal__n_header_value_discard_ws; + goto s_n_llhttp__internal__n_invoke_load_header_state; case 21: - goto s_n_llhttp__internal__n_pause_15; + goto s_n_llhttp__internal__n_pause_19; default: - goto s_n_llhttp__internal__n_error_34; + goto s_n_llhttp__internal__n_error_45; } /* UNREACHABLE */; abort(); @@ -2646,7 +2829,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_span_end_llhttp__on_header_field_2; } default: { - goto s_n_llhttp__internal__n_error_47; + goto s_n_llhttp__internal__n_error_61; } } /* UNREACHABLE */; @@ -2684,7 +2867,7 @@ static llparse_state_t llhttp__internal__run( /* Load input */ input = _mm_loadu_si128((__m128i const*) p); - ranges = _mm_loadu_si128((__m128i const*) llparse_blob8); + ranges = _mm_loadu_si128((__m128i const*) llparse_blob7); /* Find first character that does not match `ranges` */ match_len = _mm_cmpestri(ranges, 16, @@ -2696,7 +2879,7 @@ static llparse_state_t llhttp__internal__run( p += match_len; goto s_n_llhttp__internal__n_header_field_general; } - ranges = _mm_loadu_si128((__m128i const*) llparse_blob9); + ranges = _mm_loadu_si128((__m128i const*) llparse_blob8); /* Find first character that does not match `ranges` */ match_len = _mm_cmpestri(ranges, 2, @@ -2730,7 +2913,7 @@ static llparse_state_t llhttp__internal__run( } switch (*p) { case ' ': { - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_8; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_13; } case ':': { goto s_n_llhttp__internal__n_span_end_llhttp__on_header_field_1; @@ -2749,7 +2932,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_header_field_3; } - match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob2, 6); + match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob1, 6); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -2774,7 +2957,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_header_field_4; } - match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob10, 10); + match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob9, 10); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -2820,7 +3003,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_header_field_1; } - match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob1, 2); + match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob0, 2); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -2844,7 +3027,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_header_field_5; } - match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob11, 15); + match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob10, 15); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -2869,7 +3052,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_header_field_6; } - match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob12, 16); + match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob11, 16); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -2894,7 +3077,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_header_field_7; } - match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob13, 6); + match_seq = llparse__match_sequence_to_lower(state, p, endp, llparse_blob12, 6); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -2966,6 +3149,9 @@ static llparse_state_t llhttp__internal__run( p++; goto s_n_llhttp__internal__n_headers_almost_done; } + case ':': { + goto s_n_llhttp__internal__n_error_44; + } default: { goto s_n_llhttp__internal__n_span_start_llhttp__on_header_field; } @@ -3044,7 +3230,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_url_to_http_09; } default: { - goto s_n_llhttp__internal__n_error_48; + goto s_n_llhttp__internal__n_error_62; } } /* UNREACHABLE */; @@ -3069,7 +3255,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_url_skip_lf_to_http09_1; } default: { - goto s_n_llhttp__internal__n_error_48; + goto s_n_llhttp__internal__n_error_62; } } /* UNREACHABLE */; @@ -3082,18 +3268,18 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_req_pri_upgrade; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob15, 10); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob14, 10); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { p++; - goto s_n_llhttp__internal__n_error_55; + goto s_n_llhttp__internal__n_error_70; } case kMatchPause: { return s_n_llhttp__internal__n_req_pri_upgrade; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_56; + goto s_n_llhttp__internal__n_error_71; } } /* UNREACHABLE */; @@ -3110,7 +3296,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_headers_start; } default: { - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_16; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_25; } } /* UNREACHABLE */; @@ -3122,12 +3308,16 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_req_http_complete; } switch (*p) { + case 10: { + p++; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_24; + } case 13: { p++; goto s_n_llhttp__internal__n_req_http_complete_crlf; } default: { - goto s_n_llhttp__internal__n_error_54; + goto s_n_llhttp__internal__n_error_69; } } /* UNREACHABLE */; @@ -3150,15 +3340,15 @@ static llparse_state_t llhttp__internal__run( case 0: goto s_n_llhttp__internal__n_invoke_load_method_1; case 21: - goto s_n_llhttp__internal__n_pause_17; + goto s_n_llhttp__internal__n_pause_21; default: - goto s_n_llhttp__internal__n_error_52; + goto s_n_llhttp__internal__n_error_66; } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_51: - s_n_llhttp__internal__n_error_51: { + case s_n_llhttp__internal__n_error_65: + s_n_llhttp__internal__n_error_65: { state->error = 0x9; state->reason = "Invalid HTTP version"; state->error_pos = (const char*) p; @@ -3167,8 +3357,8 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_57: - s_n_llhttp__internal__n_error_57: { + case s_n_llhttp__internal__n_error_72: + s_n_llhttp__internal__n_error_72: { state->error = 0x9; state->reason = "Invalid minor version"; state->error_pos = (const char*) p; @@ -3240,8 +3430,8 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_58: - s_n_llhttp__internal__n_error_58: { + case s_n_llhttp__internal__n_error_73: + s_n_llhttp__internal__n_error_73: { state->error = 0x9; state->reason = "Expected dot"; state->error_pos = (const char*) p; @@ -3267,8 +3457,8 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_59: - s_n_llhttp__internal__n_error_59: { + case s_n_llhttp__internal__n_error_74: + s_n_llhttp__internal__n_error_74: { state->error = 0x9; state->reason = "Invalid major version"; state->error_pos = (const char*) p; @@ -3358,7 +3548,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_req_http_start_1; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob14, 4); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob13, 4); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -3369,7 +3559,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_req_http_start_1; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_62; + goto s_n_llhttp__internal__n_error_77; } } /* UNREACHABLE */; @@ -3382,7 +3572,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_req_http_start_2; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob16, 3); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob15, 3); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -3393,7 +3583,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_req_http_start_2; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_62; + goto s_n_llhttp__internal__n_error_77; } } /* UNREACHABLE */; @@ -3406,7 +3596,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_req_http_start_3; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob17, 4); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob16, 4); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -3417,7 +3607,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_req_http_start_3; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_62; + goto s_n_llhttp__internal__n_error_77; } } /* UNREACHABLE */; @@ -3446,7 +3636,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_req_http_start_3; } default: { - goto s_n_llhttp__internal__n_error_62; + goto s_n_llhttp__internal__n_error_77; } } /* UNREACHABLE */; @@ -3537,7 +3727,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_url_fragment; } default: { - goto s_n_llhttp__internal__n_error_63; + goto s_n_llhttp__internal__n_error_78; } } /* UNREACHABLE */; @@ -3598,7 +3788,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_span_end_stub_query_3; } default: { - goto s_n_llhttp__internal__n_error_64; + goto s_n_llhttp__internal__n_error_79; } } /* UNREACHABLE */; @@ -3636,7 +3826,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_url_query; } default: { - goto s_n_llhttp__internal__n_error_65; + goto s_n_llhttp__internal__n_error_80; } } /* UNREACHABLE */; @@ -3761,10 +3951,10 @@ static llparse_state_t llhttp__internal__run( } case 8: { p++; - goto s_n_llhttp__internal__n_error_66; + goto s_n_llhttp__internal__n_error_81; } default: { - goto s_n_llhttp__internal__n_error_67; + goto s_n_llhttp__internal__n_error_82; } } /* UNREACHABLE */; @@ -3823,7 +4013,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_url_server_with_at; } default: { - goto s_n_llhttp__internal__n_error_68; + goto s_n_llhttp__internal__n_error_83; } } /* UNREACHABLE */; @@ -3840,7 +4030,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_url_server; } default: { - goto s_n_llhttp__internal__n_error_69; + goto s_n_llhttp__internal__n_error_84; } } /* UNREACHABLE */; @@ -3877,7 +4067,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_url_schema_delim_1; } default: { - goto s_n_llhttp__internal__n_error_69; + goto s_n_llhttp__internal__n_error_84; } } /* UNREACHABLE */; @@ -3929,7 +4119,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_url_schema; } default: { - goto s_n_llhttp__internal__n_error_70; + goto s_n_llhttp__internal__n_error_85; } } /* UNREACHABLE */; @@ -3970,7 +4160,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_url_schema; } default: { - goto s_n_llhttp__internal__n_error_71; + goto s_n_llhttp__internal__n_error_86; } } /* UNREACHABLE */; @@ -4068,7 +4258,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_req_spaces_before_url; } default: { - goto s_n_llhttp__internal__n_error_72; + goto s_n_llhttp__internal__n_error_87; } } /* UNREACHABLE */; @@ -4080,9 +4270,9 @@ static llparse_state_t llhttp__internal__run( case 0: goto s_n_llhttp__internal__n_req_first_space_before_url; case 21: - goto s_n_llhttp__internal__n_pause_22; + goto s_n_llhttp__internal__n_pause_26; default: - goto s_n_llhttp__internal__n_error_89; + goto s_n_llhttp__internal__n_error_106; } /* UNREACHABLE */; abort(); @@ -4099,7 +4289,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_store_method_1; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4112,7 +4302,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_3; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob18, 6); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob17, 6); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4124,7 +4314,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_3; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4145,7 +4335,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_after_start_req_3; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4158,7 +4348,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_4; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob19, 3); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob18, 3); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4170,7 +4360,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_4; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4183,7 +4373,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_6; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob20, 6); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob19, 6); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4195,7 +4385,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_6; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4208,7 +4398,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_8; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob21, 4); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob20, 4); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4220,7 +4410,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_8; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4238,7 +4428,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_store_method_1; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4259,7 +4449,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_after_start_req_9; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4280,7 +4470,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_after_start_req_7; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4293,7 +4483,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_12; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob22, 3); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob21, 3); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4305,7 +4495,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_12; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4318,7 +4508,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_13; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob23, 5); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob22, 5); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4330,7 +4520,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_13; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4351,7 +4541,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_after_start_req_13; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4368,7 +4558,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_after_start_req_11; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4381,7 +4571,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_14; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob24, 4); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob23, 4); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4393,7 +4583,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_14; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4406,7 +4596,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_17; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob26, 9); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob25, 9); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4418,7 +4608,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_17; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4449,7 +4639,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_15; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob25, 2); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob24, 2); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4460,7 +4650,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_15; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4473,7 +4663,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_18; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob27, 3); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob26, 3); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4485,7 +4675,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_18; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4498,7 +4688,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_20; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob28, 2); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob27, 2); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4510,7 +4700,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_20; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4523,7 +4713,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_21; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob29, 2); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob28, 2); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4535,7 +4725,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_21; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4556,7 +4746,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_after_start_req_21; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4569,7 +4759,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_23; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob30, 6); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob29, 6); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4581,7 +4771,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_23; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4594,7 +4784,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_24; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob31, 3); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob30, 3); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4606,7 +4796,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_24; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4619,7 +4809,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_26; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob32, 7); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob31, 7); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4631,7 +4821,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_26; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4644,7 +4834,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_28; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob33, 6); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob32, 6); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4656,7 +4846,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_28; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4674,7 +4864,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_store_method_1; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4695,7 +4885,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_after_start_req_29; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4716,7 +4906,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_after_start_req_27; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4729,7 +4919,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_30; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob34, 2); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob33, 2); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4741,7 +4931,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_30; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4770,7 +4960,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_after_start_req_30; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4783,7 +4973,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_31; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob35, 5); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob34, 5); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4795,7 +4985,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_31; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4808,7 +4998,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_32; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob36, 6); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob35, 6); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4820,7 +5010,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_32; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4833,7 +5023,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_35; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob37, 2); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob36, 2); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4845,7 +5035,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_35; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4858,7 +5048,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_36; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob38, 2); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob37, 2); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4870,7 +5060,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_36; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4891,7 +5081,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_after_start_req_36; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4904,7 +5094,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_37; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob39, 2); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob38, 2); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4916,7 +5106,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_37; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4929,7 +5119,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_38; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob40, 2); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob39, 2); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4941,7 +5131,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_38; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4954,7 +5144,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_42; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob41, 3); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob40, 3); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4966,7 +5156,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_42; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -4979,7 +5169,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_43; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob42, 4); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob41, 4); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -4991,7 +5181,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_43; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -5012,7 +5202,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_after_start_req_43; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -5029,7 +5219,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_after_start_req_41; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -5051,7 +5241,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_after_start_req_40; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -5064,7 +5254,7 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_45; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob43, 2); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob42, 2); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { @@ -5076,7 +5266,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_after_start_req_45; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -5098,7 +5288,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_store_method_1; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -5131,32 +5321,32 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_after_start_req_44; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_after_start_req_48: - s_n_llhttp__internal__n_after_start_req_48: { + case s_n_llhttp__internal__n_after_start_req_46: + s_n_llhttp__internal__n_after_start_req_46: { llparse_match_t match_seq; if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_48; + return s_n_llhttp__internal__n_after_start_req_46; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob44, 3); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob43, 4); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { p++; - match = 17; + match = 46; goto s_n_llhttp__internal__n_invoke_store_method_1; } case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_48; + return s_n_llhttp__internal__n_after_start_req_46; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -5169,19 +5359,19 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_49; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob45, 3); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob44, 3); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { p++; - match = 44; + match = 17; goto s_n_llhttp__internal__n_invoke_store_method_1; } case kMatchPause: { return s_n_llhttp__internal__n_after_start_req_49; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -5194,19 +5384,19 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_50; } - match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob46, 5); + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob45, 3); p = match_seq.current; switch (match_seq.status) { case kMatchComplete: { p++; - match = 43; + match = 44; goto s_n_llhttp__internal__n_invoke_store_method_1; } case kMatchPause: { return s_n_llhttp__internal__n_after_start_req_50; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -5219,6 +5409,31 @@ static llparse_state_t llhttp__internal__run( if (p == endp) { return s_n_llhttp__internal__n_after_start_req_51; } + match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob46, 5); + p = match_seq.current; + switch (match_seq.status) { + case kMatchComplete: { + p++; + match = 43; + goto s_n_llhttp__internal__n_invoke_store_method_1; + } + case kMatchPause: { + return s_n_llhttp__internal__n_after_start_req_51; + } + case kMatchMismatch: { + goto s_n_llhttp__internal__n_error_107; + } + } + /* UNREACHABLE */; + abort(); + } + case s_n_llhttp__internal__n_after_start_req_52: + s_n_llhttp__internal__n_after_start_req_52: { + llparse_match_t match_seq; + + if (p == endp) { + return s_n_llhttp__internal__n_after_start_req_52; + } match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob47, 3); p = match_seq.current; switch (match_seq.status) { @@ -5228,67 +5443,67 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_store_method_1; } case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_51; + return s_n_llhttp__internal__n_after_start_req_52; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_after_start_req_47: - s_n_llhttp__internal__n_after_start_req_47: { + case s_n_llhttp__internal__n_after_start_req_48: + s_n_llhttp__internal__n_after_start_req_48: { if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_47; + return s_n_llhttp__internal__n_after_start_req_48; } switch (*p) { case 'B': { p++; - goto s_n_llhttp__internal__n_after_start_req_48; + goto s_n_llhttp__internal__n_after_start_req_49; } case 'C': { p++; - goto s_n_llhttp__internal__n_after_start_req_49; + goto s_n_llhttp__internal__n_after_start_req_50; } case 'D': { p++; - goto s_n_llhttp__internal__n_after_start_req_50; + goto s_n_llhttp__internal__n_after_start_req_51; } case 'P': { p++; - goto s_n_llhttp__internal__n_after_start_req_51; + goto s_n_llhttp__internal__n_after_start_req_52; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_after_start_req_46: - s_n_llhttp__internal__n_after_start_req_46: { + case s_n_llhttp__internal__n_after_start_req_47: + s_n_llhttp__internal__n_after_start_req_47: { if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_46; + return s_n_llhttp__internal__n_after_start_req_47; } switch (*p) { case 'E': { p++; - goto s_n_llhttp__internal__n_after_start_req_47; + goto s_n_llhttp__internal__n_after_start_req_48; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_after_start_req_54: - s_n_llhttp__internal__n_after_start_req_54: { + case s_n_llhttp__internal__n_after_start_req_55: + s_n_llhttp__internal__n_after_start_req_55: { llparse_match_t match_seq; if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_54; + return s_n_llhttp__internal__n_after_start_req_55; } match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob48, 3); p = match_seq.current; @@ -5299,19 +5514,19 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_store_method_1; } case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_54; + return s_n_llhttp__internal__n_after_start_req_55; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_after_start_req_56: - s_n_llhttp__internal__n_after_start_req_56: { + case s_n_llhttp__internal__n_after_start_req_57: + s_n_llhttp__internal__n_after_start_req_57: { if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_56; + return s_n_llhttp__internal__n_after_start_req_57; } switch (*p) { case 'P': { @@ -5320,18 +5535,18 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_store_method_1; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_after_start_req_57: - s_n_llhttp__internal__n_after_start_req_57: { + case s_n_llhttp__internal__n_after_start_req_58: + s_n_llhttp__internal__n_after_start_req_58: { llparse_match_t match_seq; if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_57; + return s_n_llhttp__internal__n_after_start_req_58; } match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob49, 9); p = match_seq.current; @@ -5342,63 +5557,63 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_store_method_1; } case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_57; + return s_n_llhttp__internal__n_after_start_req_58; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_after_start_req_55: - s_n_llhttp__internal__n_after_start_req_55: { + case s_n_llhttp__internal__n_after_start_req_56: + s_n_llhttp__internal__n_after_start_req_56: { if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_55; + return s_n_llhttp__internal__n_after_start_req_56; } switch (*p) { case 'U': { p++; - goto s_n_llhttp__internal__n_after_start_req_56; + goto s_n_llhttp__internal__n_after_start_req_57; } case '_': { p++; - goto s_n_llhttp__internal__n_after_start_req_57; + goto s_n_llhttp__internal__n_after_start_req_58; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_after_start_req_53: - s_n_llhttp__internal__n_after_start_req_53: { + case s_n_llhttp__internal__n_after_start_req_54: + s_n_llhttp__internal__n_after_start_req_54: { if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_53; + return s_n_llhttp__internal__n_after_start_req_54; } switch (*p) { case 'A': { p++; - goto s_n_llhttp__internal__n_after_start_req_54; + goto s_n_llhttp__internal__n_after_start_req_55; } case 'T': { p++; - goto s_n_llhttp__internal__n_after_start_req_55; + goto s_n_llhttp__internal__n_after_start_req_56; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_after_start_req_58: - s_n_llhttp__internal__n_after_start_req_58: { + case s_n_llhttp__internal__n_after_start_req_59: + s_n_llhttp__internal__n_after_start_req_59: { llparse_match_t match_seq; if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_58; + return s_n_llhttp__internal__n_after_start_req_59; } match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob50, 4); p = match_seq.current; @@ -5409,21 +5624,21 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_store_method_1; } case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_58; + return s_n_llhttp__internal__n_after_start_req_59; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_after_start_req_59: - s_n_llhttp__internal__n_after_start_req_59: { + case s_n_llhttp__internal__n_after_start_req_60: + s_n_llhttp__internal__n_after_start_req_60: { llparse_match_t match_seq; if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_59; + return s_n_llhttp__internal__n_after_start_req_60; } match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob51, 7); p = match_seq.current; @@ -5434,46 +5649,46 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_store_method_1; } case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_59; + return s_n_llhttp__internal__n_after_start_req_60; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_after_start_req_52: - s_n_llhttp__internal__n_after_start_req_52: { + case s_n_llhttp__internal__n_after_start_req_53: + s_n_llhttp__internal__n_after_start_req_53: { if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_52; + return s_n_llhttp__internal__n_after_start_req_53; } switch (*p) { case 'E': { p++; - goto s_n_llhttp__internal__n_after_start_req_53; + goto s_n_llhttp__internal__n_after_start_req_54; } case 'O': { p++; - goto s_n_llhttp__internal__n_after_start_req_58; + goto s_n_llhttp__internal__n_after_start_req_59; } case 'U': { p++; - goto s_n_llhttp__internal__n_after_start_req_59; + goto s_n_llhttp__internal__n_after_start_req_60; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_after_start_req_61: - s_n_llhttp__internal__n_after_start_req_61: { + case s_n_llhttp__internal__n_after_start_req_62: + s_n_llhttp__internal__n_after_start_req_62: { llparse_match_t match_seq; if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_61; + return s_n_llhttp__internal__n_after_start_req_62; } match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob52, 6); p = match_seq.current; @@ -5484,21 +5699,21 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_store_method_1; } case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_61; + return s_n_llhttp__internal__n_after_start_req_62; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_after_start_req_62: - s_n_llhttp__internal__n_after_start_req_62: { + case s_n_llhttp__internal__n_after_start_req_63: + s_n_llhttp__internal__n_after_start_req_63: { llparse_match_t match_seq; if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_62; + return s_n_llhttp__internal__n_after_start_req_63; } match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob53, 3); p = match_seq.current; @@ -5509,42 +5724,42 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_store_method_1; } case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_62; + return s_n_llhttp__internal__n_after_start_req_63; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_after_start_req_60: - s_n_llhttp__internal__n_after_start_req_60: { + case s_n_llhttp__internal__n_after_start_req_61: + s_n_llhttp__internal__n_after_start_req_61: { if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_60; + return s_n_llhttp__internal__n_after_start_req_61; } switch (*p) { case 'E': { p++; - goto s_n_llhttp__internal__n_after_start_req_61; + goto s_n_llhttp__internal__n_after_start_req_62; } case 'R': { p++; - goto s_n_llhttp__internal__n_after_start_req_62; + goto s_n_llhttp__internal__n_after_start_req_63; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_after_start_req_65: - s_n_llhttp__internal__n_after_start_req_65: { + case s_n_llhttp__internal__n_after_start_req_66: + s_n_llhttp__internal__n_after_start_req_66: { llparse_match_t match_seq; if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_65; + return s_n_llhttp__internal__n_after_start_req_66; } match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob54, 3); p = match_seq.current; @@ -5555,21 +5770,21 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_store_method_1; } case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_65; + return s_n_llhttp__internal__n_after_start_req_66; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_after_start_req_67: - s_n_llhttp__internal__n_after_start_req_67: { + case s_n_llhttp__internal__n_after_start_req_68: + s_n_llhttp__internal__n_after_start_req_68: { llparse_match_t match_seq; if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_67; + return s_n_llhttp__internal__n_after_start_req_68; } match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob55, 2); p = match_seq.current; @@ -5580,21 +5795,21 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_store_method_1; } case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_67; + return s_n_llhttp__internal__n_after_start_req_68; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_after_start_req_68: - s_n_llhttp__internal__n_after_start_req_68: { + case s_n_llhttp__internal__n_after_start_req_69: + s_n_llhttp__internal__n_after_start_req_69: { llparse_match_t match_seq; if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_68; + return s_n_llhttp__internal__n_after_start_req_69; } match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob56, 2); p = match_seq.current; @@ -5605,42 +5820,42 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_store_method_1; } case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_68; + return s_n_llhttp__internal__n_after_start_req_69; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_after_start_req_66: - s_n_llhttp__internal__n_after_start_req_66: { + case s_n_llhttp__internal__n_after_start_req_67: + s_n_llhttp__internal__n_after_start_req_67: { if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_66; + return s_n_llhttp__internal__n_after_start_req_67; } switch (*p) { case 'I': { p++; - goto s_n_llhttp__internal__n_after_start_req_67; + goto s_n_llhttp__internal__n_after_start_req_68; } case 'O': { p++; - goto s_n_llhttp__internal__n_after_start_req_68; + goto s_n_llhttp__internal__n_after_start_req_69; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_after_start_req_69: - s_n_llhttp__internal__n_after_start_req_69: { + case s_n_llhttp__internal__n_after_start_req_70: + s_n_llhttp__internal__n_after_start_req_70: { llparse_match_t match_seq; if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_69; + return s_n_llhttp__internal__n_after_start_req_70; } match_seq = llparse__match_sequence_id(state, p, endp, llparse_blob57, 8); p = match_seq.current; @@ -5651,52 +5866,52 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_store_method_1; } case kMatchPause: { - return s_n_llhttp__internal__n_after_start_req_69; + return s_n_llhttp__internal__n_after_start_req_70; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_after_start_req_64: - s_n_llhttp__internal__n_after_start_req_64: { + case s_n_llhttp__internal__n_after_start_req_65: + s_n_llhttp__internal__n_after_start_req_65: { if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_64; + return s_n_llhttp__internal__n_after_start_req_65; } switch (*p) { case 'B': { p++; - goto s_n_llhttp__internal__n_after_start_req_65; + goto s_n_llhttp__internal__n_after_start_req_66; } case 'L': { p++; - goto s_n_llhttp__internal__n_after_start_req_66; + goto s_n_llhttp__internal__n_after_start_req_67; } case 'S': { p++; - goto s_n_llhttp__internal__n_after_start_req_69; + goto s_n_llhttp__internal__n_after_start_req_70; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_after_start_req_63: - s_n_llhttp__internal__n_after_start_req_63: { + case s_n_llhttp__internal__n_after_start_req_64: + s_n_llhttp__internal__n_after_start_req_64: { if (p == endp) { - return s_n_llhttp__internal__n_after_start_req_63; + return s_n_llhttp__internal__n_after_start_req_64; } switch (*p) { case 'N': { p++; - goto s_n_llhttp__internal__n_after_start_req_64; + goto s_n_llhttp__internal__n_after_start_req_65; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -5756,24 +5971,28 @@ static llparse_state_t llhttp__internal__run( p++; goto s_n_llhttp__internal__n_after_start_req_33; } - case 'R': { + case 'Q': { p++; goto s_n_llhttp__internal__n_after_start_req_46; } + case 'R': { + p++; + goto s_n_llhttp__internal__n_after_start_req_47; + } case 'S': { p++; - goto s_n_llhttp__internal__n_after_start_req_52; + goto s_n_llhttp__internal__n_after_start_req_53; } case 'T': { p++; - goto s_n_llhttp__internal__n_after_start_req_60; + goto s_n_llhttp__internal__n_after_start_req_61; } case 'U': { p++; - goto s_n_llhttp__internal__n_after_start_req_63; + goto s_n_llhttp__internal__n_after_start_req_64; } default: { - goto s_n_llhttp__internal__n_error_90; + goto s_n_llhttp__internal__n_error_107; } } /* UNREACHABLE */; @@ -5805,12 +6024,23 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_llhttp__on_status_complete; } default: { - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_18; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_28; } } /* UNREACHABLE */; abort(); } + case s_n_llhttp__internal__n_invoke_test_lenient_flags_29: + s_n_llhttp__internal__n_invoke_test_lenient_flags_29: { + switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { + case 1: + goto s_n_llhttp__internal__n_invoke_llhttp__on_status_complete; + default: + goto s_n_llhttp__internal__n_error_93; + } + /* UNREACHABLE */; + abort(); + } case s_n_llhttp__internal__n_res_status: s_n_llhttp__internal__n_res_status: { if (p == endp) { @@ -5842,27 +6072,6 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_res_status_start: - s_n_llhttp__internal__n_res_status_start: { - if (p == endp) { - return s_n_llhttp__internal__n_res_status_start; - } - switch (*p) { - case 10: { - p++; - goto s_n_llhttp__internal__n_invoke_llhttp__on_status_complete; - } - case 13: { - p++; - goto s_n_llhttp__internal__n_res_line_almost_done; - } - default: { - goto s_n_llhttp__internal__n_span_start_llhttp__on_status; - } - } - /* UNREACHABLE */; - abort(); - } case s_n_llhttp__internal__n_res_status_code_otherwise: s_n_llhttp__internal__n_res_status_code_otherwise: { if (p == endp) { @@ -5870,17 +6079,19 @@ static llparse_state_t llhttp__internal__run( } switch (*p) { case 10: { - goto s_n_llhttp__internal__n_res_status_start; + p++; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_27; } case 13: { - goto s_n_llhttp__internal__n_res_status_start; + p++; + goto s_n_llhttp__internal__n_res_line_almost_done; } case ' ': { p++; - goto s_n_llhttp__internal__n_res_status_start; + goto s_n_llhttp__internal__n_span_start_llhttp__on_status; } default: { - goto s_n_llhttp__internal__n_error_77; + goto s_n_llhttp__internal__n_error_94; } } /* UNREACHABLE */; @@ -5943,7 +6154,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_mul_add_status_code_2; } default: { - goto s_n_llhttp__internal__n_error_79; + goto s_n_llhttp__internal__n_error_96; } } /* UNREACHABLE */; @@ -6006,7 +6217,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_mul_add_status_code_1; } default: { - goto s_n_llhttp__internal__n_error_81; + goto s_n_llhttp__internal__n_error_98; } } /* UNREACHABLE */; @@ -6069,7 +6280,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_mul_add_status_code; } default: { - goto s_n_llhttp__internal__n_error_83; + goto s_n_llhttp__internal__n_error_100; } } /* UNREACHABLE */; @@ -6086,7 +6297,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_invoke_update_status_code; } default: { - goto s_n_llhttp__internal__n_error_84; + goto s_n_llhttp__internal__n_error_101; } } /* UNREACHABLE */; @@ -6098,15 +6309,15 @@ static llparse_state_t llhttp__internal__run( case 0: goto s_n_llhttp__internal__n_res_after_version; case 21: - goto s_n_llhttp__internal__n_pause_21; + goto s_n_llhttp__internal__n_pause_25; default: - goto s_n_llhttp__internal__n_error_74; + goto s_n_llhttp__internal__n_error_89; } /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_73: - s_n_llhttp__internal__n_error_73: { + case s_n_llhttp__internal__n_error_88: + s_n_llhttp__internal__n_error_88: { state->error = 0x9; state->reason = "Invalid HTTP version"; state->error_pos = (const char*) p; @@ -6115,8 +6326,8 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_85: - s_n_llhttp__internal__n_error_85: { + case s_n_llhttp__internal__n_error_102: + s_n_llhttp__internal__n_error_102: { state->error = 0x9; state->reason = "Invalid minor version"; state->error_pos = (const char*) p; @@ -6188,8 +6399,8 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_86: - s_n_llhttp__internal__n_error_86: { + case s_n_llhttp__internal__n_error_103: + s_n_llhttp__internal__n_error_103: { state->error = 0x9; state->reason = "Expected dot"; state->error_pos = (const char*) p; @@ -6215,8 +6426,8 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - case s_n_llhttp__internal__n_error_87: - s_n_llhttp__internal__n_error_87: { + case s_n_llhttp__internal__n_error_104: + s_n_llhttp__internal__n_error_104: { state->error = 0x9; state->reason = "Invalid major version"; state->error_pos = (const char*) p; @@ -6317,7 +6528,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_start_res; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_91; + goto s_n_llhttp__internal__n_error_108; } } /* UNREACHABLE */; @@ -6329,7 +6540,7 @@ static llparse_state_t llhttp__internal__run( case 0: goto s_n_llhttp__internal__n_req_first_space_before_url; case 21: - goto s_n_llhttp__internal__n_pause_19; + goto s_n_llhttp__internal__n_pause_23; default: goto s_n_llhttp__internal__n_error_1; } @@ -6355,7 +6566,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_req_or_res_method_2; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_88; + goto s_n_llhttp__internal__n_error_105; } } /* UNREACHABLE */; @@ -6388,7 +6599,7 @@ static llparse_state_t llhttp__internal__run( return s_n_llhttp__internal__n_req_or_res_method_3; } case kMatchMismatch: { - goto s_n_llhttp__internal__n_error_88; + goto s_n_llhttp__internal__n_error_105; } } /* UNREACHABLE */; @@ -6409,7 +6620,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_req_or_res_method_3; } default: { - goto s_n_llhttp__internal__n_error_88; + goto s_n_llhttp__internal__n_error_105; } } /* UNREACHABLE */; @@ -6426,7 +6637,7 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_req_or_res_method_1; } default: { - goto s_n_llhttp__internal__n_error_88; + goto s_n_llhttp__internal__n_error_105; } } /* UNREACHABLE */; @@ -6539,7 +6750,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_7: { + s_n_llhttp__internal__n_error_8: { state->error = 0x5; state->reason = "Data after `Connection: close`"; state->error_pos = (const char*) p; @@ -6553,7 +6764,7 @@ static llparse_state_t llhttp__internal__run( case 1: goto s_n_llhttp__internal__n_closed; default: - goto s_n_llhttp__internal__n_error_7; + goto s_n_llhttp__internal__n_error_8; } /* UNREACHABLE */; abort(); @@ -6576,6 +6787,54 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } + s_n_llhttp__internal__n_pause_13: { + state->error = 0x15; + state->reason = "on_message_complete pause"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_is_equal_upgrade; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_38: { + state->error = 0x12; + state->reason = "`on_message_complete` callback error"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_pause_15: { + state->error = 0x15; + state->reason = "on_chunk_complete pause"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_2; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_40: { + state->error = 0x14; + state->reason = "`on_chunk_complete` callback error"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_llhttp__on_chunk_complete_1: { + switch (llhttp__on_chunk_complete(state, p, endp)) { + case 0: + goto s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_2; + case 21: + goto s_n_llhttp__internal__n_pause_15; + default: + goto s_n_llhttp__internal__n_error_40; + } + /* UNREACHABLE */; + abort(); + } s_n_llhttp__internal__n_pause_2: { state->error = 0x15; state->reason = "on_message_complete pause"; @@ -6585,7 +6844,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_8: { + s_n_llhttp__internal__n_error_9: { state->error = 0x12; state->reason = "`on_message_complete` callback error"; state->error_pos = (const char*) p; @@ -6601,12 +6860,12 @@ static llparse_state_t llhttp__internal__run( case 21: goto s_n_llhttp__internal__n_pause_2; default: - goto s_n_llhttp__internal__n_error_8; + goto s_n_llhttp__internal__n_error_9; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_26: { + s_n_llhttp__internal__n_error_36: { state->error = 0xc; state->reason = "Chunk size overflow"; state->error_pos = (const char*) p; @@ -6615,6 +6874,25 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } + s_n_llhttp__internal__n_error_10: { + state->error = 0xc; + state->reason = "Invalid character in chunk size"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_test_lenient_flags_4: { + switch (llhttp__internal__c_test_lenient_flags_4(state, p, endp)) { + case 1: + goto s_n_llhttp__internal__n_chunk_size_otherwise; + default: + goto s_n_llhttp__internal__n_error_10; + } + /* UNREACHABLE */; + abort(); + } s_n_llhttp__internal__n_pause_3: { state->error = 0x15; state->reason = "on_chunk_complete pause"; @@ -6624,7 +6902,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_10: { + s_n_llhttp__internal__n_error_14: { state->error = 0x14; state->reason = "`on_chunk_complete` callback error"; state->error_pos = (const char*) p; @@ -6640,12 +6918,31 @@ static llparse_state_t llhttp__internal__run( case 21: goto s_n_llhttp__internal__n_pause_3; default: - goto s_n_llhttp__internal__n_error_10; + goto s_n_llhttp__internal__n_error_14; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_11: { + s_n_llhttp__internal__n_error_13: { + state->error = 0x19; + state->reason = "Missing expected CR after chunk data"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_test_lenient_flags_6: { + switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { + case 1: + goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_complete; + default: + goto s_n_llhttp__internal__n_error_13; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_15: { state->error = 0x2; state->reason = "Expected LF after chunk data"; state->error_pos = (const char*) p; @@ -6654,12 +6951,12 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_test_lenient_flags_4: { - switch (llhttp__internal__c_test_lenient_flags_4(state, p, endp)) { + s_n_llhttp__internal__n_invoke_test_lenient_flags_7: { + switch (llhttp__internal__c_test_lenient_flags_7(state, p, endp)) { case 1: goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_complete; default: - goto s_n_llhttp__internal__n_error_11; + goto s_n_llhttp__internal__n_error_15; } /* UNREACHABLE */; abort(); @@ -6698,7 +6995,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_9: { + s_n_llhttp__internal__n_error_12: { state->error = 0x13; state->reason = "`on_chunk_header` callback error"; state->error_pos = (const char*) p; @@ -6714,12 +7011,12 @@ static llparse_state_t llhttp__internal__run( case 21: goto s_n_llhttp__internal__n_pause_4; default: - goto s_n_llhttp__internal__n_error_9; + goto s_n_llhttp__internal__n_error_12; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_12: { + s_n_llhttp__internal__n_error_16: { state->error = 0x2; state->reason = "Expected LF after chunk size"; state->error_pos = (const char*) p; @@ -6728,17 +7025,36 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_test_lenient_flags_5: { - switch (llhttp__internal__c_test_lenient_flags_5(state, p, endp)) { + s_n_llhttp__internal__n_invoke_test_lenient_flags_8: { + switch (llhttp__internal__c_test_lenient_flags_8(state, p, endp)) { case 1: goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_header; default: - goto s_n_llhttp__internal__n_error_12; + goto s_n_llhttp__internal__n_error_16; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_13: { + s_n_llhttp__internal__n_error_11: { + state->error = 0x19; + state->reason = "Missing expected CR after chunk size"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_test_lenient_flags_5: { + switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { + case 1: + goto s_n_llhttp__internal__n_chunk_size_almost_done; + default: + goto s_n_llhttp__internal__n_error_11; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_17: { state->error = 0x2; state->reason = "Invalid character in chunk extensions"; state->error_pos = (const char*) p; @@ -6747,7 +7063,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_14: { + s_n_llhttp__internal__n_error_18: { state->error = 0x2; state->reason = "Invalid character in chunk extensions"; state->error_pos = (const char*) p; @@ -6756,16 +7072,25 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } + s_n_llhttp__internal__n_error_20: { + state->error = 0x19; + state->reason = "Missing expected CR after chunk extension name"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } s_n_llhttp__internal__n_pause_5: { state->error = 0x15; state->reason = "on_chunk_extension_name pause"; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_chunk_size_almost_done; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_test_lenient_flags_9; return s_error; /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_15: { + s_n_llhttp__internal__n_error_19: { state->error = 0x22; state->reason = "`on_chunk_extension_name` callback error"; state->error_pos = (const char*) p; @@ -6783,11 +7108,10 @@ static llparse_state_t llhttp__internal__run( err = llhttp__on_chunk_extension_name(state, start, p); if (err != 0) { state->error = err; - state->error_pos = (const char*) (p + 1); + state->error_pos = (const char*) p; state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete; return s_error; } - p++; goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete; /* UNREACHABLE */; abort(); @@ -6796,12 +7120,12 @@ static llparse_state_t llhttp__internal__run( state->error = 0x15; state->reason = "on_chunk_extension_name pause"; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_chunk_extensions; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_chunk_size_almost_done; return s_error; /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_16: { + s_n_llhttp__internal__n_error_21: { state->error = 0x22; state->reason = "`on_chunk_extension_name` callback error"; state->error_pos = (const char*) p; @@ -6830,14 +7154,59 @@ static llparse_state_t llhttp__internal__run( } s_n_llhttp__internal__n_pause_7: { state->error = 0x15; + state->reason = "on_chunk_extension_name pause"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_chunk_extensions; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_22: { + state->error = 0x22; + state->reason = "`on_chunk_extension_name` callback error"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name_2: { + const unsigned char* start; + int err; + + start = state->_span_pos0; + state->_span_pos0 = NULL; + err = llhttp__on_chunk_extension_name(state, start, p); + if (err != 0) { + state->error = err; + state->error_pos = (const char*) (p + 1); + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_2; + return s_error; + } + p++; + goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_2; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_25: { + state->error = 0x19; + state->reason = "Missing expected CR after chunk extension value"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_pause_8: { + state->error = 0x15; state->reason = "on_chunk_extension_value pause"; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_chunk_size_almost_done; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_test_lenient_flags_10; return s_error; /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_18: { + s_n_llhttp__internal__n_error_24: { state->error = 0x23; state->reason = "`on_chunk_extension_value` callback error"; state->error_pos = (const char*) p; @@ -6855,16 +7224,70 @@ static llparse_state_t llhttp__internal__run( err = llhttp__on_chunk_extension_value(state, start, p); if (err != 0) { state->error = err; - state->error_pos = (const char*) (p + 1); + state->error_pos = (const char*) p; state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete; return s_error; } - p++; goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete; /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_20: { + s_n_llhttp__internal__n_pause_9: { + state->error = 0x15; + state->reason = "on_chunk_extension_value pause"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_chunk_size_almost_done; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_26: { + state->error = 0x23; + state->reason = "`on_chunk_extension_value` callback error"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_1: { + const unsigned char* start; + int err; + + start = state->_span_pos0; + state->_span_pos0 = NULL; + err = llhttp__on_chunk_extension_value(state, start, p); + if (err != 0) { + state->error = err; + state->error_pos = (const char*) (p + 1); + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_1; + return s_error; + } + p++; + goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_1; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_28: { + state->error = 0x19; + state->reason = "Missing expected CR after chunk extension value"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_test_lenient_flags_11: { + switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { + case 1: + goto s_n_llhttp__internal__n_chunk_size_almost_done; + default: + goto s_n_llhttp__internal__n_error_28; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_29: { state->error = 0x2; state->reason = "Invalid character in chunk extensions quote value"; state->error_pos = (const char*) p; @@ -6873,7 +7296,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_8: { + s_n_llhttp__internal__n_pause_10: { state->error = 0x15; state->reason = "on_chunk_extension_value pause"; state->error_pos = (const char*) p; @@ -6882,7 +7305,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_19: { + s_n_llhttp__internal__n_error_27: { state->error = 0x23; state->reason = "`on_chunk_extension_value` callback error"; state->error_pos = (const char*) p; @@ -6891,7 +7314,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_1: { + s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_2: { const unsigned char* start; int err; @@ -6901,14 +7324,14 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_1; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_2; return s_error; } - goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_1; + goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_2; /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_2: { + s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_3: { const unsigned char* start; int err; @@ -6918,24 +7341,42 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_21; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_30; return s_error; } p++; - goto s_n_llhttp__internal__n_error_21; + goto s_n_llhttp__internal__n_error_30; /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_9: { + s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_4: { + const unsigned char* start; + int err; + + start = state->_span_pos0; + state->_span_pos0 = NULL; + err = llhttp__on_chunk_extension_value(state, start, p); + if (err != 0) { + state->error = err; + state->error_pos = (const char*) (p + 1); + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_31; + return s_error; + } + p++; + goto s_n_llhttp__internal__n_error_31; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_pause_11: { state->error = 0x15; state->reason = "on_chunk_extension_value pause"; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_chunk_size_otherwise; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_chunk_extensions; return s_error; /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_22: { + s_n_llhttp__internal__n_error_32: { state->error = 0x23; state->reason = "`on_chunk_extension_value` callback error"; state->error_pos = (const char*) p; @@ -6944,7 +7385,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_3: { + s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_5: { const unsigned char* start; int err; @@ -6954,15 +7395,15 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_2; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_3; return s_error; } p++; - goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_2; + goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_value_complete_3; /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_4: { + s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_value_6: { const unsigned char* start; int err; @@ -6972,15 +7413,15 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_23; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_33; return s_error; } p++; - goto s_n_llhttp__internal__n_error_23; + goto s_n_llhttp__internal__n_error_33; /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_10: { + s_n_llhttp__internal__n_pause_12: { state->error = 0x15; state->reason = "on_chunk_extension_name pause"; state->error_pos = (const char*) p; @@ -6989,7 +7430,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_17: { + s_n_llhttp__internal__n_error_23: { state->error = 0x22; state->reason = "`on_chunk_extension_name` callback error"; state->error_pos = (const char*) p; @@ -6998,19 +7439,19 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_2: { + s_n_llhttp__internal__n_invoke_llhttp__on_chunk_extension_name_complete_3: { switch (llhttp__on_chunk_extension_name_complete(state, p, endp)) { case 0: goto s_n_llhttp__internal__n_chunk_extension_value; case 21: - goto s_n_llhttp__internal__n_pause_10; + goto s_n_llhttp__internal__n_pause_12; default: - goto s_n_llhttp__internal__n_error_17; + goto s_n_llhttp__internal__n_error_23; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name_2: { + s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name_3: { const unsigned char* start; int err; @@ -7028,7 +7469,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name_3: { + s_n_llhttp__internal__n_span_end_llhttp__on_chunk_extension_name_4: { const unsigned char* start; int err; @@ -7038,15 +7479,15 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_24; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_34; return s_error; } p++; - goto s_n_llhttp__internal__n_error_24; + goto s_n_llhttp__internal__n_error_34; /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_25: { + s_n_llhttp__internal__n_error_35: { state->error = 0xc; state->reason = "Invalid character in chunk size"; state->error_pos = (const char*) p; @@ -7058,14 +7499,14 @@ static llparse_state_t llhttp__internal__run( s_n_llhttp__internal__n_invoke_mul_add_content_length: { switch (llhttp__internal__c_mul_add_content_length(state, p, endp, match)) { case 1: - goto s_n_llhttp__internal__n_error_26; + goto s_n_llhttp__internal__n_error_36; default: goto s_n_llhttp__internal__n_chunk_size; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_27: { + s_n_llhttp__internal__n_error_37: { state->error = 0xc; state->reason = "Invalid character in chunk size"; state->error_pos = (const char*) p; @@ -7074,24 +7515,6 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_11: { - state->error = 0x15; - state->reason = "on_message_complete pause"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_is_equal_upgrade; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_error_28: { - state->error = 0x12; - state->reason = "`on_message_complete` callback error"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } s_n_llhttp__internal__n_span_end_llhttp__on_body_1: { const unsigned char* start; int err; @@ -7117,7 +7540,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_29: { + s_n_llhttp__internal__n_error_39: { state->error = 0xf; state->reason = "Request has invalid `Transfer-Encoding`"; state->error_pos = (const char*) p; @@ -7135,7 +7558,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_6: { + s_n_llhttp__internal__n_error_7: { state->error = 0x12; state->reason = "`on_message_complete` callback error"; state->error_pos = (const char*) p; @@ -7151,22 +7574,98 @@ static llparse_state_t llhttp__internal__run( case 21: goto s_n_llhttp__internal__n_pause; default: + goto s_n_llhttp__internal__n_error_7; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_or_flags_1: { + switch (llhttp__internal__c_or_flags_1(state, p, endp)) { + default: + goto s_n_llhttp__internal__n_invoke_llhttp__after_headers_complete; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_or_flags_2: { + switch (llhttp__internal__c_or_flags_1(state, p, endp)) { + default: + goto s_n_llhttp__internal__n_invoke_llhttp__after_headers_complete; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_update_upgrade: { + switch (llhttp__internal__c_update_upgrade(state, p, endp)) { + default: + goto s_n_llhttp__internal__n_invoke_or_flags_2; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_pause_14: { + state->error = 0x15; + state->reason = "Paused by on_headers_complete"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_llhttp__after_headers_complete; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_6: { + state->error = 0x11; + state->reason = "User callback error"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_llhttp__on_headers_complete: { + switch (llhttp__on_headers_complete(state, p, endp)) { + case 0: + goto s_n_llhttp__internal__n_invoke_llhttp__after_headers_complete; + case 1: + goto s_n_llhttp__internal__n_invoke_or_flags_1; + case 2: + goto s_n_llhttp__internal__n_invoke_update_upgrade; + case 21: + goto s_n_llhttp__internal__n_pause_14; + default: goto s_n_llhttp__internal__n_error_6; } /* UNREACHABLE */; abort(); } + s_n_llhttp__internal__n_invoke_llhttp__before_headers_complete: { + switch (llhttp__before_headers_complete(state, p, endp)) { + default: + goto s_n_llhttp__internal__n_invoke_llhttp__on_headers_complete; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_test_flags: { + switch (llhttp__internal__c_test_flags(state, p, endp)) { + case 1: + goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_complete_1; + default: + goto s_n_llhttp__internal__n_invoke_llhttp__before_headers_complete; + } + /* UNREACHABLE */; + abort(); + } s_n_llhttp__internal__n_invoke_test_lenient_flags_1: { - switch (llhttp__internal__c_test_lenient_flags(state, p, endp)) { + switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { case 1: - goto s_n_llhttp__internal__n_invoke_llhttp__after_headers_complete; + goto s_n_llhttp__internal__n_invoke_test_flags; default: goto s_n_llhttp__internal__n_error_5; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_13: { + s_n_llhttp__internal__n_pause_17: { state->error = 0x15; state->reason = "on_chunk_complete pause"; state->error_pos = (const char*) p; @@ -7175,7 +7674,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_32: { + s_n_llhttp__internal__n_error_42: { state->error = 0x14; state->reason = "`on_chunk_complete` callback error"; state->error_pos = (const char*) p; @@ -7184,28 +7683,19 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_llhttp__on_chunk_complete_1: { + s_n_llhttp__internal__n_invoke_llhttp__on_chunk_complete_2: { switch (llhttp__on_chunk_complete(state, p, endp)) { case 0: goto s_n_llhttp__internal__n_invoke_llhttp__on_message_complete_2; case 21: - goto s_n_llhttp__internal__n_pause_13; + goto s_n_llhttp__internal__n_pause_17; default: - goto s_n_llhttp__internal__n_error_32; + goto s_n_llhttp__internal__n_error_42; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_31: { - state->error = 0x4; - state->reason = "Content-Length can't be present with Transfer-Encoding"; - state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_error; - return s_error; - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_or_flags_1: { + s_n_llhttp__internal__n_invoke_or_flags_3: { switch (llhttp__internal__c_or_flags_1(state, p, endp)) { default: goto s_n_llhttp__internal__n_invoke_llhttp__after_headers_complete; @@ -7213,7 +7703,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_or_flags_2: { + s_n_llhttp__internal__n_invoke_or_flags_4: { switch (llhttp__internal__c_or_flags_1(state, p, endp)) { default: goto s_n_llhttp__internal__n_invoke_llhttp__after_headers_complete; @@ -7221,15 +7711,15 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_update_upgrade: { + s_n_llhttp__internal__n_invoke_update_upgrade_1: { switch (llhttp__internal__c_update_upgrade(state, p, endp)) { default: - goto s_n_llhttp__internal__n_invoke_or_flags_2; + goto s_n_llhttp__internal__n_invoke_or_flags_4; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_12: { + s_n_llhttp__internal__n_pause_16: { state->error = 0x15; state->reason = "Paused by on_headers_complete"; state->error_pos = (const char*) p; @@ -7238,7 +7728,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_30: { + s_n_llhttp__internal__n_error_41: { state->error = 0x11; state->reason = "User callback error"; state->error_pos = (const char*) p; @@ -7247,61 +7737,41 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_llhttp__on_headers_complete: { + s_n_llhttp__internal__n_invoke_llhttp__on_headers_complete_1: { switch (llhttp__on_headers_complete(state, p, endp)) { case 0: goto s_n_llhttp__internal__n_invoke_llhttp__after_headers_complete; case 1: - goto s_n_llhttp__internal__n_invoke_or_flags_1; + goto s_n_llhttp__internal__n_invoke_or_flags_3; case 2: - goto s_n_llhttp__internal__n_invoke_update_upgrade; + goto s_n_llhttp__internal__n_invoke_update_upgrade_1; case 21: - goto s_n_llhttp__internal__n_pause_12; + goto s_n_llhttp__internal__n_pause_16; default: - goto s_n_llhttp__internal__n_error_30; + goto s_n_llhttp__internal__n_error_41; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_llhttp__before_headers_complete: { + s_n_llhttp__internal__n_invoke_llhttp__before_headers_complete_1: { switch (llhttp__before_headers_complete(state, p, endp)) { default: - goto s_n_llhttp__internal__n_invoke_llhttp__on_headers_complete; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_lenient_flags_6: { - switch (llhttp__internal__c_test_lenient_flags_6(state, p, endp)) { - case 0: - goto s_n_llhttp__internal__n_error_31; - default: - goto s_n_llhttp__internal__n_invoke_llhttp__before_headers_complete; + goto s_n_llhttp__internal__n_invoke_llhttp__on_headers_complete_1; } /* UNREACHABLE */; abort(); } s_n_llhttp__internal__n_invoke_test_flags_1: { - switch (llhttp__internal__c_test_flags_1(state, p, endp)) { - case 1: - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_6; - default: - goto s_n_llhttp__internal__n_invoke_llhttp__before_headers_complete; - } - /* UNREACHABLE */; - abort(); - } - s_n_llhttp__internal__n_invoke_test_flags: { switch (llhttp__internal__c_test_flags(state, p, endp)) { case 1: - goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_complete_1; + goto s_n_llhttp__internal__n_invoke_llhttp__on_chunk_complete_2; default: - goto s_n_llhttp__internal__n_invoke_test_flags_1; + goto s_n_llhttp__internal__n_invoke_llhttp__before_headers_complete_1; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_33: { + s_n_llhttp__internal__n_error_43: { state->error = 0x2; state->reason = "Expected LF after headers"; state->error_pos = (const char*) p; @@ -7310,16 +7780,25 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_test_lenient_flags_7: { - switch (llhttp__internal__c_test_lenient_flags_5(state, p, endp)) { + s_n_llhttp__internal__n_invoke_test_lenient_flags_12: { + switch (llhttp__internal__c_test_lenient_flags_8(state, p, endp)) { case 1: - goto s_n_llhttp__internal__n_invoke_test_flags; + goto s_n_llhttp__internal__n_invoke_test_flags_1; default: - goto s_n_llhttp__internal__n_error_33; + goto s_n_llhttp__internal__n_error_43; } /* UNREACHABLE */; abort(); } + s_n_llhttp__internal__n_error_44: { + state->error = 0xa; + state->reason = "Invalid header token"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } s_n_llhttp__internal__n_span_end_llhttp__on_header_field: { const unsigned char* start; int err; @@ -7338,7 +7817,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_test_lenient_flags_8: { + s_n_llhttp__internal__n_invoke_test_lenient_flags_13: { switch (llhttp__internal__c_test_lenient_flags(state, p, endp)) { case 1: goto s_n_llhttp__internal__n_header_field_colon_discard_ws; @@ -7348,7 +7827,16 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_36: { + s_n_llhttp__internal__n_error_59: { + state->error = 0xb; + state->reason = "Content-Length can't be present with Transfer-Encoding"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_47: { state->error = 0xa; state->reason = "Invalid header value char"; state->error_pos = (const char*) p; @@ -7357,17 +7845,17 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_test_lenient_flags_10: { + s_n_llhttp__internal__n_invoke_test_lenient_flags_15: { switch (llhttp__internal__c_test_lenient_flags(state, p, endp)) { case 1: goto s_n_llhttp__internal__n_header_value_discard_ws; default: - goto s_n_llhttp__internal__n_error_36; + goto s_n_llhttp__internal__n_error_47; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_38: { + s_n_llhttp__internal__n_error_49: { state->error = 0xb; state->reason = "Empty Content-Length"; state->error_pos = (const char*) p; @@ -7376,7 +7864,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_14: { + s_n_llhttp__internal__n_pause_18: { state->error = 0x15; state->reason = "on_header_value_complete pause"; state->error_pos = (const char*) p; @@ -7385,7 +7873,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_37: { + s_n_llhttp__internal__n_error_48: { state->error = 0x1d; state->reason = "`on_header_value_complete` callback error"; state->error_pos = (const char*) p; @@ -7419,65 +7907,65 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_or_flags_3: { - switch (llhttp__internal__c_or_flags_3(state, p, endp)) { + s_n_llhttp__internal__n_invoke_or_flags_5: { + switch (llhttp__internal__c_or_flags_5(state, p, endp)) { default: goto s_n_llhttp__internal__n_invoke_update_header_state; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_or_flags_4: { - switch (llhttp__internal__c_or_flags_4(state, p, endp)) { + s_n_llhttp__internal__n_invoke_or_flags_6: { + switch (llhttp__internal__c_or_flags_6(state, p, endp)) { default: goto s_n_llhttp__internal__n_invoke_update_header_state; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_or_flags_5: { - switch (llhttp__internal__c_or_flags_5(state, p, endp)) { + s_n_llhttp__internal__n_invoke_or_flags_7: { + switch (llhttp__internal__c_or_flags_7(state, p, endp)) { default: goto s_n_llhttp__internal__n_invoke_update_header_state; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_or_flags_6: { - switch (llhttp__internal__c_or_flags_6(state, p, endp)) { + s_n_llhttp__internal__n_invoke_or_flags_8: { + switch (llhttp__internal__c_or_flags_8(state, p, endp)) { default: goto s_n_llhttp__internal__n_span_start_llhttp__on_header_value; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_load_header_state_1: { + s_n_llhttp__internal__n_invoke_load_header_state_2: { switch (llhttp__internal__c_load_header_state(state, p, endp)) { case 5: - goto s_n_llhttp__internal__n_invoke_or_flags_3; + goto s_n_llhttp__internal__n_invoke_or_flags_5; case 6: - goto s_n_llhttp__internal__n_invoke_or_flags_4; + goto s_n_llhttp__internal__n_invoke_or_flags_6; case 7: - goto s_n_llhttp__internal__n_invoke_or_flags_5; + goto s_n_llhttp__internal__n_invoke_or_flags_7; case 8: - goto s_n_llhttp__internal__n_invoke_or_flags_6; + goto s_n_llhttp__internal__n_invoke_or_flags_8; default: goto s_n_llhttp__internal__n_span_start_llhttp__on_header_value; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_load_header_state: { + s_n_llhttp__internal__n_invoke_load_header_state_1: { switch (llhttp__internal__c_load_header_state(state, p, endp)) { case 2: - goto s_n_llhttp__internal__n_error_38; + goto s_n_llhttp__internal__n_error_49; default: - goto s_n_llhttp__internal__n_invoke_load_header_state_1; + goto s_n_llhttp__internal__n_invoke_load_header_state_2; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_35: { + s_n_llhttp__internal__n_error_46: { state->error = 0xa; state->reason = "Invalid header value char"; state->error_pos = (const char*) p; @@ -7486,17 +7974,17 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_test_lenient_flags_9: { - switch (llhttp__internal__c_test_lenient_flags(state, p, endp)) { + s_n_llhttp__internal__n_invoke_test_lenient_flags_14: { + switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { case 1: goto s_n_llhttp__internal__n_header_value_discard_lws; default: - goto s_n_llhttp__internal__n_error_35; + goto s_n_llhttp__internal__n_error_46; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_39: { + s_n_llhttp__internal__n_error_50: { state->error = 0x2; state->reason = "Expected LF after CR"; state->error_pos = (const char*) p; @@ -7505,12 +7993,12 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_test_lenient_flags_11: { + s_n_llhttp__internal__n_invoke_test_lenient_flags_16: { switch (llhttp__internal__c_test_lenient_flags(state, p, endp)) { case 1: goto s_n_llhttp__internal__n_header_value_discard_lws; default: - goto s_n_llhttp__internal__n_error_39; + goto s_n_llhttp__internal__n_error_50; } /* UNREACHABLE */; abort(); @@ -7523,7 +8011,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_load_header_state_3: { + s_n_llhttp__internal__n_invoke_load_header_state_4: { switch (llhttp__internal__c_load_header_state(state, p, endp)) { case 8: goto s_n_llhttp__internal__n_invoke_update_header_state_1; @@ -7541,55 +8029,55 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_or_flags_7: { - switch (llhttp__internal__c_or_flags_3(state, p, endp)) { + s_n_llhttp__internal__n_invoke_or_flags_9: { + switch (llhttp__internal__c_or_flags_5(state, p, endp)) { default: goto s_n_llhttp__internal__n_invoke_update_header_state_2; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_or_flags_8: { - switch (llhttp__internal__c_or_flags_4(state, p, endp)) { + s_n_llhttp__internal__n_invoke_or_flags_10: { + switch (llhttp__internal__c_or_flags_6(state, p, endp)) { default: goto s_n_llhttp__internal__n_invoke_update_header_state_2; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_or_flags_9: { - switch (llhttp__internal__c_or_flags_5(state, p, endp)) { + s_n_llhttp__internal__n_invoke_or_flags_11: { + switch (llhttp__internal__c_or_flags_7(state, p, endp)) { default: goto s_n_llhttp__internal__n_invoke_update_header_state_2; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_or_flags_10: { - switch (llhttp__internal__c_or_flags_6(state, p, endp)) { + s_n_llhttp__internal__n_invoke_or_flags_12: { + switch (llhttp__internal__c_or_flags_8(state, p, endp)) { default: goto s_n_llhttp__internal__n_invoke_llhttp__on_header_value_complete; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_load_header_state_4: { + s_n_llhttp__internal__n_invoke_load_header_state_5: { switch (llhttp__internal__c_load_header_state(state, p, endp)) { case 5: - goto s_n_llhttp__internal__n_invoke_or_flags_7; + goto s_n_llhttp__internal__n_invoke_or_flags_9; case 6: - goto s_n_llhttp__internal__n_invoke_or_flags_8; + goto s_n_llhttp__internal__n_invoke_or_flags_10; case 7: - goto s_n_llhttp__internal__n_invoke_or_flags_9; + goto s_n_llhttp__internal__n_invoke_or_flags_11; case 8: - goto s_n_llhttp__internal__n_invoke_or_flags_10; + goto s_n_llhttp__internal__n_invoke_or_flags_12; default: goto s_n_llhttp__internal__n_invoke_llhttp__on_header_value_complete; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_40: { + s_n_llhttp__internal__n_error_52: { state->error = 0x3; state->reason = "Missing expected LF after header value"; state->error_pos = (const char*) p; @@ -7598,6 +8086,15 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } + s_n_llhttp__internal__n_error_51: { + state->error = 0x19; + state->reason = "Missing expected CR after header value"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } s_n_llhttp__internal__n_span_end_llhttp__on_header_value_1: { const unsigned char* start; int err; @@ -7607,6 +8104,23 @@ static llparse_state_t llhttp__internal__run( err = llhttp__on_header_value(state, start, p); if (err != 0) { state->error = err; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_test_lenient_flags_17; + return s_error; + } + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_17; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_span_end_llhttp__on_header_value_2: { + const unsigned char* start; + int err; + + start = state->_span_pos0; + state->_span_pos0 = NULL; + err = llhttp__on_header_value(state, start, p); + if (err != 0) { + state->error = err; state->error_pos = (const char*) (p + 1); state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_header_value_almost_done; return s_error; @@ -7616,7 +8130,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_span_end_llhttp__on_header_value_3: { + s_n_llhttp__internal__n_span_end_llhttp__on_header_value_4: { const unsigned char* start; int err; @@ -7633,7 +8147,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_span_end_llhttp__on_header_value_4: { + s_n_llhttp__internal__n_span_end_llhttp__on_header_value_5: { const unsigned char* start; int err; @@ -7651,7 +8165,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_span_end_llhttp__on_header_value_2: { + s_n_llhttp__internal__n_span_end_llhttp__on_header_value_3: { const unsigned char* start; int err; @@ -7661,19 +8175,19 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_41; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_53; return s_error; } - goto s_n_llhttp__internal__n_error_41; + goto s_n_llhttp__internal__n_error_53; /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_test_lenient_flags_12: { + s_n_llhttp__internal__n_invoke_test_lenient_flags_18: { switch (llhttp__internal__c_test_lenient_flags(state, p, endp)) { case 1: goto s_n_llhttp__internal__n_header_value_lenient; default: - goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_2; + goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_3; } /* UNREACHABLE */; abort(); @@ -7686,48 +8200,48 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_or_flags_11: { - switch (llhttp__internal__c_or_flags_3(state, p, endp)) { + s_n_llhttp__internal__n_invoke_or_flags_13: { + switch (llhttp__internal__c_or_flags_5(state, p, endp)) { default: goto s_n_llhttp__internal__n_invoke_update_header_state_4; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_or_flags_12: { - switch (llhttp__internal__c_or_flags_4(state, p, endp)) { + s_n_llhttp__internal__n_invoke_or_flags_14: { + switch (llhttp__internal__c_or_flags_6(state, p, endp)) { default: goto s_n_llhttp__internal__n_invoke_update_header_state_4; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_or_flags_13: { - switch (llhttp__internal__c_or_flags_5(state, p, endp)) { + s_n_llhttp__internal__n_invoke_or_flags_15: { + switch (llhttp__internal__c_or_flags_7(state, p, endp)) { default: goto s_n_llhttp__internal__n_invoke_update_header_state_4; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_or_flags_14: { - switch (llhttp__internal__c_or_flags_6(state, p, endp)) { + s_n_llhttp__internal__n_invoke_or_flags_16: { + switch (llhttp__internal__c_or_flags_8(state, p, endp)) { default: goto s_n_llhttp__internal__n_header_value_connection; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_load_header_state_5: { + s_n_llhttp__internal__n_invoke_load_header_state_6: { switch (llhttp__internal__c_load_header_state(state, p, endp)) { case 5: - goto s_n_llhttp__internal__n_invoke_or_flags_11; + goto s_n_llhttp__internal__n_invoke_or_flags_13; case 6: - goto s_n_llhttp__internal__n_invoke_or_flags_12; + goto s_n_llhttp__internal__n_invoke_or_flags_14; case 7: - goto s_n_llhttp__internal__n_invoke_or_flags_13; + goto s_n_llhttp__internal__n_invoke_or_flags_15; case 8: - goto s_n_llhttp__internal__n_invoke_or_flags_14; + goto s_n_llhttp__internal__n_invoke_or_flags_16; default: goto s_n_llhttp__internal__n_header_value_connection; } @@ -7766,7 +8280,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_span_end_llhttp__on_header_value_5: { + s_n_llhttp__internal__n_span_end_llhttp__on_header_value_6: { const unsigned char* start; int err; @@ -7776,32 +8290,32 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_43; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_55; return s_error; } - goto s_n_llhttp__internal__n_error_43; + goto s_n_llhttp__internal__n_error_55; /* UNREACHABLE */; abort(); } s_n_llhttp__internal__n_invoke_mul_add_content_length_1: { switch (llhttp__internal__c_mul_add_content_length_1(state, p, endp, match)) { case 1: - goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_5; + goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_6; default: goto s_n_llhttp__internal__n_header_value_content_length; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_or_flags_15: { - switch (llhttp__internal__c_or_flags_15(state, p, endp)) { + s_n_llhttp__internal__n_invoke_or_flags_17: { + switch (llhttp__internal__c_or_flags_17(state, p, endp)) { default: goto s_n_llhttp__internal__n_header_value_otherwise; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_span_end_llhttp__on_header_value_6: { + s_n_llhttp__internal__n_span_end_llhttp__on_header_value_7: { const unsigned char* start; int err; @@ -7811,14 +8325,14 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_44; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_56; return s_error; } - goto s_n_llhttp__internal__n_error_44; + goto s_n_llhttp__internal__n_error_56; /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_42: { + s_n_llhttp__internal__n_error_54: { state->error = 0x4; state->reason = "Duplicate Content-Length"; state->error_pos = (const char*) p; @@ -7832,12 +8346,12 @@ static llparse_state_t llhttp__internal__run( case 0: goto s_n_llhttp__internal__n_header_value_content_length; default: - goto s_n_llhttp__internal__n_error_42; + goto s_n_llhttp__internal__n_error_54; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_span_end_llhttp__on_header_value_8: { + s_n_llhttp__internal__n_span_end_llhttp__on_header_value_9: { const unsigned char* start; int err; @@ -7847,11 +8361,11 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_46; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_58; return s_error; } p++; - goto s_n_llhttp__internal__n_error_46; + goto s_n_llhttp__internal__n_error_58; /* UNREACHABLE */; abort(); } @@ -7863,7 +8377,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_span_end_llhttp__on_header_value_7: { + s_n_llhttp__internal__n_span_end_llhttp__on_header_value_8: { const unsigned char* start; int err; @@ -7873,18 +8387,18 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_45; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_57; return s_error; } p++; - goto s_n_llhttp__internal__n_error_45; + goto s_n_llhttp__internal__n_error_57; /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_test_lenient_flags_13: { - switch (llhttp__internal__c_test_lenient_flags_13(state, p, endp)) { + s_n_llhttp__internal__n_invoke_test_lenient_flags_19: { + switch (llhttp__internal__c_test_lenient_flags_19(state, p, endp)) { case 0: - goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_7; + goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_8; default: goto s_n_llhttp__internal__n_header_value_te_chunked; } @@ -7894,7 +8408,7 @@ static llparse_state_t llhttp__internal__run( s_n_llhttp__internal__n_invoke_load_type_1: { switch (llhttp__internal__c_load_type(state, p, endp)) { case 1: - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_13; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_19; default: goto s_n_llhttp__internal__n_header_value_te_chunked; } @@ -7917,20 +8431,20 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_or_flags_17: { - switch (llhttp__internal__c_or_flags_16(state, p, endp)) { + s_n_llhttp__internal__n_invoke_or_flags_19: { + switch (llhttp__internal__c_or_flags_18(state, p, endp)) { default: goto s_n_llhttp__internal__n_invoke_and_flags; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_test_lenient_flags_14: { - switch (llhttp__internal__c_test_lenient_flags_13(state, p, endp)) { + s_n_llhttp__internal__n_invoke_test_lenient_flags_20: { + switch (llhttp__internal__c_test_lenient_flags_19(state, p, endp)) { case 0: - goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_8; + goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_9; default: - goto s_n_llhttp__internal__n_invoke_or_flags_17; + goto s_n_llhttp__internal__n_invoke_or_flags_19; } /* UNREACHABLE */; abort(); @@ -7938,15 +8452,15 @@ static llparse_state_t llhttp__internal__run( s_n_llhttp__internal__n_invoke_load_type_2: { switch (llhttp__internal__c_load_type(state, p, endp)) { case 1: - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_14; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_20; default: - goto s_n_llhttp__internal__n_invoke_or_flags_17; + goto s_n_llhttp__internal__n_invoke_or_flags_19; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_or_flags_16: { - switch (llhttp__internal__c_or_flags_16(state, p, endp)) { + s_n_llhttp__internal__n_invoke_or_flags_18: { + switch (llhttp__internal__c_or_flags_18(state, p, endp)) { default: goto s_n_llhttp__internal__n_invoke_and_flags; } @@ -7958,20 +8472,20 @@ static llparse_state_t llhttp__internal__run( case 1: goto s_n_llhttp__internal__n_invoke_load_type_2; default: - goto s_n_llhttp__internal__n_invoke_or_flags_16; + goto s_n_llhttp__internal__n_invoke_or_flags_18; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_or_flags_18: { - switch (llhttp__internal__c_or_flags_18(state, p, endp)) { + s_n_llhttp__internal__n_invoke_or_flags_20: { + switch (llhttp__internal__c_or_flags_20(state, p, endp)) { default: goto s_n_llhttp__internal__n_invoke_update_header_state_9; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_load_header_state_2: { + s_n_llhttp__internal__n_invoke_load_header_state_3: { switch (llhttp__internal__c_load_header_state(state, p, endp)) { case 1: goto s_n_llhttp__internal__n_header_value_connection; @@ -7980,23 +8494,72 @@ static llparse_state_t llhttp__internal__run( case 3: goto s_n_llhttp__internal__n_invoke_test_flags_3; case 4: - goto s_n_llhttp__internal__n_invoke_or_flags_18; + goto s_n_llhttp__internal__n_invoke_or_flags_20; default: goto s_n_llhttp__internal__n_header_value; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_15: { + s_n_llhttp__internal__n_invoke_test_lenient_flags_21: { + switch (llhttp__internal__c_test_lenient_flags_21(state, p, endp)) { + case 0: + goto s_n_llhttp__internal__n_error_59; + default: + goto s_n_llhttp__internal__n_header_value_discard_ws; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_test_flags_4: { + switch (llhttp__internal__c_test_flags_4(state, p, endp)) { + case 1: + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_21; + default: + goto s_n_llhttp__internal__n_header_value_discard_ws; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_60: { + state->error = 0xf; + state->reason = "Transfer-Encoding can't be present with Content-Length"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_test_lenient_flags_22: { + switch (llhttp__internal__c_test_lenient_flags_21(state, p, endp)) { + case 0: + goto s_n_llhttp__internal__n_error_60; + default: + goto s_n_llhttp__internal__n_header_value_discard_ws; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_test_flags_5: { + switch (llhttp__internal__c_test_flags_2(state, p, endp)) { + case 1: + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_22; + default: + goto s_n_llhttp__internal__n_header_value_discard_ws; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_pause_19: { state->error = 0x15; state->reason = "on_header_field_complete pause"; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_header_value_discard_ws; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_load_header_state; return s_error; /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_34: { + s_n_llhttp__internal__n_error_45: { state->error = 0x1c; state->reason = "`on_header_field_complete` callback error"; state->error_pos = (const char*) p; @@ -8041,7 +8604,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_47: { + s_n_llhttp__internal__n_error_61: { state->error = 0xa; state->reason = "Invalid header token"; state->error_pos = (const char*) p; @@ -8093,7 +8656,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_16: { + s_n_llhttp__internal__n_pause_20: { state->error = 0x15; state->reason = "on_url_complete pause"; state->error_pos = (const char*) p; @@ -8116,7 +8679,7 @@ static llparse_state_t llhttp__internal__run( case 0: goto s_n_llhttp__internal__n_headers_start; case 21: - goto s_n_llhttp__internal__n_pause_16; + goto s_n_llhttp__internal__n_pause_20; default: goto s_n_llhttp__internal__n_error_3; } @@ -8156,7 +8719,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_48: { + s_n_llhttp__internal__n_error_62: { state->error = 0x7; state->reason = "Expected CRLF"; state->error_pos = (const char*) p; @@ -8182,7 +8745,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_55: { + s_n_llhttp__internal__n_error_70: { state->error = 0x17; state->reason = "Pause on PRI/Upgrade"; state->error_pos = (const char*) p; @@ -8191,7 +8754,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_56: { + s_n_llhttp__internal__n_error_71: { state->error = 0x9; state->reason = "Expected HTTP/2 Connection Preface"; state->error_pos = (const char*) p; @@ -8200,7 +8763,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_53: { + s_n_llhttp__internal__n_error_68: { state->error = 0x2; state->reason = "Expected CRLF after version"; state->error_pos = (const char*) p; @@ -8209,17 +8772,17 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_test_lenient_flags_16: { - switch (llhttp__internal__c_test_lenient_flags_5(state, p, endp)) { + s_n_llhttp__internal__n_invoke_test_lenient_flags_25: { + switch (llhttp__internal__c_test_lenient_flags_8(state, p, endp)) { case 1: goto s_n_llhttp__internal__n_headers_start; default: - goto s_n_llhttp__internal__n_error_53; + goto s_n_llhttp__internal__n_error_68; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_54: { + s_n_llhttp__internal__n_error_67: { state->error = 0x9; state->reason = "Expected CRLF after version"; state->error_pos = (const char*) p; @@ -8228,7 +8791,26 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_17: { + s_n_llhttp__internal__n_invoke_test_lenient_flags_24: { + switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { + case 1: + goto s_n_llhttp__internal__n_req_http_complete_crlf; + default: + goto s_n_llhttp__internal__n_error_67; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_69: { + state->error = 0x9; + state->reason = "Expected CRLF after version"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_pause_21: { state->error = 0x15; state->reason = "on_version_complete pause"; state->error_pos = (const char*) p; @@ -8237,7 +8819,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_52: { + s_n_llhttp__internal__n_error_66: { state->error = 0x21; state->reason = "`on_version_complete` callback error"; state->error_pos = (const char*) p; @@ -8273,10 +8855,10 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_51; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_65; return s_error; } - goto s_n_llhttp__internal__n_error_51; + goto s_n_llhttp__internal__n_error_65; /* UNREACHABLE */; abort(); } @@ -8326,8 +8908,8 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_test_lenient_flags_15: { - switch (llhttp__internal__c_test_lenient_flags_15(state, p, endp)) { + s_n_llhttp__internal__n_invoke_test_lenient_flags_23: { + switch (llhttp__internal__c_test_lenient_flags_23(state, p, endp)) { case 1: goto s_n_llhttp__internal__n_span_end_llhttp__on_version_1; default: @@ -8339,7 +8921,7 @@ static llparse_state_t llhttp__internal__run( s_n_llhttp__internal__n_invoke_store_http_minor: { switch (llhttp__internal__c_store_http_minor(state, p, endp, match)) { default: - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_15; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_23; } /* UNREACHABLE */; abort(); @@ -8354,10 +8936,10 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_57; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_72; return s_error; } - goto s_n_llhttp__internal__n_error_57; + goto s_n_llhttp__internal__n_error_72; /* UNREACHABLE */; abort(); } @@ -8371,10 +8953,10 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_58; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_73; return s_error; } - goto s_n_llhttp__internal__n_error_58; + goto s_n_llhttp__internal__n_error_73; /* UNREACHABLE */; abort(); } @@ -8396,14 +8978,14 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_59; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_74; return s_error; } - goto s_n_llhttp__internal__n_error_59; + goto s_n_llhttp__internal__n_error_74; /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_50: { + s_n_llhttp__internal__n_error_64: { state->error = 0x8; state->reason = "Invalid method for HTTP/x.x request"; state->error_pos = (const char*) p; @@ -8484,13 +9066,15 @@ static llparse_state_t llhttp__internal__run( goto s_n_llhttp__internal__n_span_start_llhttp__on_version; case 34: goto s_n_llhttp__internal__n_span_start_llhttp__on_version; + case 46: + goto s_n_llhttp__internal__n_span_start_llhttp__on_version; default: - goto s_n_llhttp__internal__n_error_50; + goto s_n_llhttp__internal__n_error_64; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_62: { + s_n_llhttp__internal__n_error_77: { state->error = 0x8; state->reason = "Expected HTTP/"; state->error_pos = (const char*) p; @@ -8499,7 +9083,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_60: { + s_n_llhttp__internal__n_error_75: { state->error = 0x8; state->reason = "Expected SOURCE method for ICE/x.x request"; state->error_pos = (const char*) p; @@ -8513,12 +9097,12 @@ static llparse_state_t llhttp__internal__run( case 33: goto s_n_llhttp__internal__n_span_start_llhttp__on_version; default: - goto s_n_llhttp__internal__n_error_60; + goto s_n_llhttp__internal__n_error_75; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_61: { + s_n_llhttp__internal__n_error_76: { state->error = 0x8; state->reason = "Invalid method for RTSP/x.x request"; state->error_pos = (const char*) p; @@ -8558,12 +9142,12 @@ static llparse_state_t llhttp__internal__run( case 45: goto s_n_llhttp__internal__n_span_start_llhttp__on_version; default: - goto s_n_llhttp__internal__n_error_61; + goto s_n_llhttp__internal__n_error_76; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_18: { + s_n_llhttp__internal__n_pause_22: { state->error = 0x15; state->reason = "on_url_complete pause"; state->error_pos = (const char*) p; @@ -8572,7 +9156,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_49: { + s_n_llhttp__internal__n_error_63: { state->error = 0x1a; state->reason = "`on_url_complete` callback error"; state->error_pos = (const char*) p; @@ -8586,9 +9170,9 @@ static llparse_state_t llhttp__internal__run( case 0: goto s_n_llhttp__internal__n_req_http_start; case 21: - goto s_n_llhttp__internal__n_pause_18; + goto s_n_llhttp__internal__n_pause_22; default: - goto s_n_llhttp__internal__n_error_49; + goto s_n_llhttp__internal__n_error_63; } /* UNREACHABLE */; abort(); @@ -8661,7 +9245,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_63: { + s_n_llhttp__internal__n_error_78: { state->error = 0x7; state->reason = "Invalid char in url fragment start"; state->error_pos = (const char*) p; @@ -8721,7 +9305,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_64: { + s_n_llhttp__internal__n_error_79: { state->error = 0x7; state->reason = "Invalid char in url query"; state->error_pos = (const char*) p; @@ -8730,7 +9314,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_65: { + s_n_llhttp__internal__n_error_80: { state->error = 0x7; state->reason = "Invalid char in url path"; state->error_pos = (const char*) p; @@ -8841,7 +9425,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_66: { + s_n_llhttp__internal__n_error_81: { state->error = 0x7; state->reason = "Double @ in url"; state->error_pos = (const char*) p; @@ -8850,7 +9434,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_67: { + s_n_llhttp__internal__n_error_82: { state->error = 0x7; state->reason = "Unexpected char in url server"; state->error_pos = (const char*) p; @@ -8859,7 +9443,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_68: { + s_n_llhttp__internal__n_error_83: { state->error = 0x7; state->reason = "Unexpected char in url server"; state->error_pos = (const char*) p; @@ -8868,7 +9452,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_69: { + s_n_llhttp__internal__n_error_84: { state->error = 0x7; state->reason = "Unexpected char in url schema"; state->error_pos = (const char*) p; @@ -8877,7 +9461,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_70: { + s_n_llhttp__internal__n_error_85: { state->error = 0x7; state->reason = "Unexpected char in url schema"; state->error_pos = (const char*) p; @@ -8886,7 +9470,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_71: { + s_n_llhttp__internal__n_error_86: { state->error = 0x7; state->reason = "Unexpected start char in url"; state->error_pos = (const char*) p; @@ -8905,7 +9489,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_72: { + s_n_llhttp__internal__n_error_87: { state->error = 0x6; state->reason = "Expected space after method"; state->error_pos = (const char*) p; @@ -8914,7 +9498,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_22: { + s_n_llhttp__internal__n_pause_26: { state->error = 0x15; state->reason = "on_method_complete pause"; state->error_pos = (const char*) p; @@ -8923,7 +9507,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_89: { + s_n_llhttp__internal__n_error_106: { state->error = 0x20; state->reason = "`on_method_complete` callback error"; state->error_pos = (const char*) p; @@ -8957,7 +9541,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_90: { + s_n_llhttp__internal__n_error_107: { state->error = 0x6; state->reason = "Invalid method encountered"; state->error_pos = (const char*) p; @@ -8966,7 +9550,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_82: { + s_n_llhttp__internal__n_error_99: { state->error = 0xd; state->reason = "Invalid status code"; state->error_pos = (const char*) p; @@ -8975,7 +9559,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_80: { + s_n_llhttp__internal__n_error_97: { state->error = 0xd; state->reason = "Invalid status code"; state->error_pos = (const char*) p; @@ -8984,7 +9568,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_78: { + s_n_llhttp__internal__n_error_95: { state->error = 0xd; state->reason = "Invalid status code"; state->error_pos = (const char*) p; @@ -8993,7 +9577,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_20: { + s_n_llhttp__internal__n_pause_24: { state->error = 0x15; state->reason = "on_status_complete pause"; state->error_pos = (const char*) p; @@ -9002,7 +9586,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_75: { + s_n_llhttp__internal__n_error_91: { state->error = 0x1b; state->reason = "`on_status_complete` callback error"; state->error_pos = (const char*) p; @@ -9016,14 +9600,33 @@ static llparse_state_t llhttp__internal__run( case 0: goto s_n_llhttp__internal__n_headers_start; case 21: - goto s_n_llhttp__internal__n_pause_20; + goto s_n_llhttp__internal__n_pause_24; default: - goto s_n_llhttp__internal__n_error_75; + goto s_n_llhttp__internal__n_error_91; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_76: { + s_n_llhttp__internal__n_error_90: { + state->error = 0xd; + state->reason = "Invalid response status"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_invoke_test_lenient_flags_27: { + switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) { + case 1: + goto s_n_llhttp__internal__n_invoke_llhttp__on_status_complete; + default: + goto s_n_llhttp__internal__n_error_90; + } + /* UNREACHABLE */; + abort(); + } + s_n_llhttp__internal__n_error_92: { state->error = 0x2; state->reason = "Expected LF after CR"; state->error_pos = (const char*) p; @@ -9032,16 +9635,25 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_test_lenient_flags_18: { - switch (llhttp__internal__c_test_lenient_flags_5(state, p, endp)) { + s_n_llhttp__internal__n_invoke_test_lenient_flags_28: { + switch (llhttp__internal__c_test_lenient_flags_8(state, p, endp)) { case 1: goto s_n_llhttp__internal__n_invoke_llhttp__on_status_complete; default: - goto s_n_llhttp__internal__n_error_76; + goto s_n_llhttp__internal__n_error_92; } /* UNREACHABLE */; abort(); } + s_n_llhttp__internal__n_error_93: { + state->error = 0x19; + state->reason = "Missing expected CR after response line"; + state->error_pos = (const char*) p; + state->_current = (void*) (intptr_t) s_error; + return s_error; + /* UNREACHABLE */; + abort(); + } s_n_llhttp__internal__n_span_end_llhttp__on_status: { const unsigned char* start; int err; @@ -9052,11 +9664,11 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) (p + 1); - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_res_line_almost_done; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_invoke_test_lenient_flags_29; return s_error; } p++; - goto s_n_llhttp__internal__n_res_line_almost_done; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_29; /* UNREACHABLE */; abort(); } @@ -9078,7 +9690,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_77: { + s_n_llhttp__internal__n_error_94: { state->error = 0xd; state->reason = "Invalid response status"; state->error_pos = (const char*) p; @@ -9090,14 +9702,14 @@ static llparse_state_t llhttp__internal__run( s_n_llhttp__internal__n_invoke_mul_add_status_code_2: { switch (llhttp__internal__c_mul_add_status_code(state, p, endp, match)) { case 1: - goto s_n_llhttp__internal__n_error_78; + goto s_n_llhttp__internal__n_error_95; default: goto s_n_llhttp__internal__n_res_status_code_otherwise; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_79: { + s_n_llhttp__internal__n_error_96: { state->error = 0xd; state->reason = "Invalid status code"; state->error_pos = (const char*) p; @@ -9109,14 +9721,14 @@ static llparse_state_t llhttp__internal__run( s_n_llhttp__internal__n_invoke_mul_add_status_code_1: { switch (llhttp__internal__c_mul_add_status_code(state, p, endp, match)) { case 1: - goto s_n_llhttp__internal__n_error_80; + goto s_n_llhttp__internal__n_error_97; default: goto s_n_llhttp__internal__n_res_status_code_digit_3; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_81: { + s_n_llhttp__internal__n_error_98: { state->error = 0xd; state->reason = "Invalid status code"; state->error_pos = (const char*) p; @@ -9128,14 +9740,14 @@ static llparse_state_t llhttp__internal__run( s_n_llhttp__internal__n_invoke_mul_add_status_code: { switch (llhttp__internal__c_mul_add_status_code(state, p, endp, match)) { case 1: - goto s_n_llhttp__internal__n_error_82; + goto s_n_llhttp__internal__n_error_99; default: goto s_n_llhttp__internal__n_res_status_code_digit_2; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_83: { + s_n_llhttp__internal__n_error_100: { state->error = 0xd; state->reason = "Invalid status code"; state->error_pos = (const char*) p; @@ -9152,7 +9764,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_84: { + s_n_llhttp__internal__n_error_101: { state->error = 0x9; state->reason = "Expected space after version"; state->error_pos = (const char*) p; @@ -9161,7 +9773,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_21: { + s_n_llhttp__internal__n_pause_25: { state->error = 0x15; state->reason = "on_version_complete pause"; state->error_pos = (const char*) p; @@ -9170,7 +9782,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_74: { + s_n_llhttp__internal__n_error_89: { state->error = 0x21; state->reason = "`on_version_complete` callback error"; state->error_pos = (const char*) p; @@ -9206,10 +9818,10 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_73; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_88; return s_error; } - goto s_n_llhttp__internal__n_error_73; + goto s_n_llhttp__internal__n_error_88; /* UNREACHABLE */; abort(); } @@ -9259,8 +9871,8 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_invoke_test_lenient_flags_17: { - switch (llhttp__internal__c_test_lenient_flags_15(state, p, endp)) { + s_n_llhttp__internal__n_invoke_test_lenient_flags_26: { + switch (llhttp__internal__c_test_lenient_flags_23(state, p, endp)) { case 1: goto s_n_llhttp__internal__n_span_end_llhttp__on_version_6; default: @@ -9272,7 +9884,7 @@ static llparse_state_t llhttp__internal__run( s_n_llhttp__internal__n_invoke_store_http_minor_1: { switch (llhttp__internal__c_store_http_minor(state, p, endp, match)) { default: - goto s_n_llhttp__internal__n_invoke_test_lenient_flags_17; + goto s_n_llhttp__internal__n_invoke_test_lenient_flags_26; } /* UNREACHABLE */; abort(); @@ -9287,10 +9899,10 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_85; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_102; return s_error; } - goto s_n_llhttp__internal__n_error_85; + goto s_n_llhttp__internal__n_error_102; /* UNREACHABLE */; abort(); } @@ -9304,10 +9916,10 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_86; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_103; return s_error; } - goto s_n_llhttp__internal__n_error_86; + goto s_n_llhttp__internal__n_error_103; /* UNREACHABLE */; abort(); } @@ -9329,14 +9941,14 @@ static llparse_state_t llhttp__internal__run( if (err != 0) { state->error = err; state->error_pos = (const char*) p; - state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_87; + state->_current = (void*) (intptr_t) s_n_llhttp__internal__n_error_104; return s_error; } - goto s_n_llhttp__internal__n_error_87; + goto s_n_llhttp__internal__n_error_104; /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_91: { + s_n_llhttp__internal__n_error_108: { state->error = 0x8; state->reason = "Expected HTTP/"; state->error_pos = (const char*) p; @@ -9345,7 +9957,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_19: { + s_n_llhttp__internal__n_pause_23: { state->error = 0x15; state->reason = "on_method_complete pause"; state->error_pos = (const char*) p; @@ -9396,7 +10008,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_88: { + s_n_llhttp__internal__n_error_105: { state->error = 0x8; state->reason = "Invalid word encountered"; state->error_pos = (const char*) p; @@ -9430,7 +10042,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_23: { + s_n_llhttp__internal__n_pause_27: { state->error = 0x15; state->reason = "on_message_begin pause"; state->error_pos = (const char*) p; @@ -9453,14 +10065,14 @@ static llparse_state_t llhttp__internal__run( case 0: goto s_n_llhttp__internal__n_invoke_load_type; case 21: - goto s_n_llhttp__internal__n_pause_23; + goto s_n_llhttp__internal__n_pause_27; default: goto s_n_llhttp__internal__n_error; } /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_pause_24: { + s_n_llhttp__internal__n_pause_28: { state->error = 0x15; state->reason = "on_reset pause"; state->error_pos = (const char*) p; @@ -9469,7 +10081,7 @@ static llparse_state_t llhttp__internal__run( /* UNREACHABLE */; abort(); } - s_n_llhttp__internal__n_error_92: { + s_n_llhttp__internal__n_error_109: { state->error = 0x1f; state->reason = "`on_reset` callback error"; state->error_pos = (const char*) p; @@ -9483,9 +10095,9 @@ static llparse_state_t llhttp__internal__run( case 0: goto s_n_llhttp__internal__n_invoke_update_finish; case 21: - goto s_n_llhttp__internal__n_pause_24; + goto s_n_llhttp__internal__n_pause_28; default: - goto s_n_llhttp__internal__n_error_92; + goto s_n_llhttp__internal__n_error_109; } /* UNREACHABLE */; abort(); |