mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-23 00:28:26 -05:00
Update to latest hiredis (#10297)
This is basically just a subtree pull of the latest (unreleased) hiredis. Unfortunately, the `sds -> hisds` patch was pulled as a subtree update from a remote branch rather than a local redis change. Because of that, it goes away on every subtree update. It is now applied as a local commit so it should survive in the future.
This commit is contained in:
commit
e8c5b66ed2
205
deps/hiredis/.github/workflows/build.yml
vendored
Normal file
205
deps/hiredis/.github/workflows/build.yml
vendored
Normal file
@ -0,0 +1,205 @@
|
|||||||
|
name: Build and test
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
ubuntu:
|
||||||
|
name: Ubuntu
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
repository: ${{ env.GITHUB_REPOSITORY }}
|
||||||
|
ref: ${{ env.GITHUB_HEAD_REF }}
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
sudo add-apt-repository -y ppa:chris-lea/redis-server
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y redis-server valgrind libevent-dev
|
||||||
|
|
||||||
|
- name: Build using cmake
|
||||||
|
env:
|
||||||
|
EXTRA_CMAKE_OPTS: -DENABLE_EXAMPLES:BOOL=ON -DENABLE_SSL:BOOL=ON -DENABLE_SSL_TESTS:BOOL=ON -DENABLE_ASYNC_TESTS:BOOL=ON
|
||||||
|
CFLAGS: -Werror
|
||||||
|
CXXFLAGS: -Werror
|
||||||
|
run: mkdir build-ubuntu && cd build-ubuntu && cmake ..
|
||||||
|
|
||||||
|
- name: Build using makefile
|
||||||
|
run: USE_SSL=1 TEST_ASYNC=1 make
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
env:
|
||||||
|
SKIPS_AS_FAILS: 1
|
||||||
|
TEST_SSL: 1
|
||||||
|
run: $GITHUB_WORKSPACE/test.sh
|
||||||
|
|
||||||
|
# - name: Run tests under valgrind
|
||||||
|
# env:
|
||||||
|
# SKIPS_AS_FAILS: 1
|
||||||
|
# TEST_PREFIX: valgrind --error-exitcode=99 --track-origins=yes --leak-check=full
|
||||||
|
# run: $GITHUB_WORKSPACE/test.sh
|
||||||
|
|
||||||
|
centos7:
|
||||||
|
name: CentOS 7
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: centos:7
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
repository: ${{ env.GITHUB_REPOSITORY }}
|
||||||
|
ref: ${{ env.GITHUB_HEAD_REF }}
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
|
||||||
|
yum -y --enablerepo=remi install redis
|
||||||
|
yum -y install gcc gcc-c++ make openssl openssl-devel cmake3 valgrind libevent-devel
|
||||||
|
|
||||||
|
- name: Build using cmake
|
||||||
|
env:
|
||||||
|
EXTRA_CMAKE_OPTS: -DENABLE_EXAMPLES:BOOL=ON -DENABLE_SSL:BOOL=ON -DENABLE_SSL_TESTS:BOOL=ON -DENABLE_ASYNC_TESTS:BOOL=ON
|
||||||
|
CFLAGS: -Werror
|
||||||
|
CXXFLAGS: -Werror
|
||||||
|
run: mkdir build-centos7 && cd build-centos7 && cmake3 ..
|
||||||
|
|
||||||
|
- name: Build using Makefile
|
||||||
|
run: USE_SSL=1 TEST_ASYNC=1 make
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
env:
|
||||||
|
SKIPS_AS_FAILS: 1
|
||||||
|
TEST_SSL: 1
|
||||||
|
run: $GITHUB_WORKSPACE/test.sh
|
||||||
|
|
||||||
|
- name: Run tests under valgrind
|
||||||
|
env:
|
||||||
|
SKIPS_AS_FAILS: 1
|
||||||
|
TEST_SSL: 1
|
||||||
|
TEST_PREFIX: valgrind --error-exitcode=99 --track-origins=yes --leak-check=full
|
||||||
|
run: $GITHUB_WORKSPACE/test.sh
|
||||||
|
|
||||||
|
centos8:
|
||||||
|
name: RockyLinux 8
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container: rockylinux:8
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
repository: ${{ env.GITHUB_REPOSITORY }}
|
||||||
|
ref: ${{ env.GITHUB_HEAD_REF }}
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
|
||||||
|
dnf -y module install redis:remi-6.0
|
||||||
|
dnf -y group install "Development Tools"
|
||||||
|
dnf -y install openssl-devel cmake valgrind libevent-devel
|
||||||
|
|
||||||
|
- name: Build using cmake
|
||||||
|
env:
|
||||||
|
EXTRA_CMAKE_OPTS: -DENABLE_EXAMPLES:BOOL=ON -DENABLE_SSL:BOOL=ON -DENABLE_SSL_TESTS:BOOL=ON -DENABLE_ASYNC_TESTS:BOOL=ON
|
||||||
|
CFLAGS: -Werror
|
||||||
|
CXXFLAGS: -Werror
|
||||||
|
run: mkdir build-centos8 && cd build-centos8 && cmake ..
|
||||||
|
|
||||||
|
- name: Build using Makefile
|
||||||
|
run: USE_SSL=1 TEST_ASYNC=1 make
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
env:
|
||||||
|
SKIPS_AS_FAILS: 1
|
||||||
|
TEST_SSL: 1
|
||||||
|
run: $GITHUB_WORKSPACE/test.sh
|
||||||
|
|
||||||
|
- name: Run tests under valgrind
|
||||||
|
env:
|
||||||
|
SKIPS_AS_FAILS: 1
|
||||||
|
TEST_SSL: 1
|
||||||
|
TEST_PREFIX: valgrind --error-exitcode=99 --track-origins=yes --leak-check=full
|
||||||
|
run: $GITHUB_WORKSPACE/test.sh
|
||||||
|
|
||||||
|
freebsd:
|
||||||
|
runs-on: macos-10.15
|
||||||
|
name: FreeBSD
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
repository: ${{ env.GITHUB_REPOSITORY }}
|
||||||
|
ref: ${{ env.GITHUB_HEAD_REF }}
|
||||||
|
|
||||||
|
- name: Build in FreeBSD
|
||||||
|
uses: vmactions/freebsd-vm@v0.1.5
|
||||||
|
with:
|
||||||
|
prepare: pkg install -y gmake cmake
|
||||||
|
run: |
|
||||||
|
mkdir build && cd build && cmake .. && make && cd ..
|
||||||
|
gmake
|
||||||
|
|
||||||
|
macos:
|
||||||
|
name: macOS
|
||||||
|
runs-on: macos-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
repository: ${{ env.GITHUB_REPOSITORY }}
|
||||||
|
ref: ${{ env.GITHUB_HEAD_REF }}
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
brew install openssl redis
|
||||||
|
|
||||||
|
- name: Build hiredis
|
||||||
|
run: USE_SSL=1 make
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
env:
|
||||||
|
TEST_SSL: 1
|
||||||
|
run: $GITHUB_WORKSPACE/test.sh
|
||||||
|
|
||||||
|
windows:
|
||||||
|
name: Windows
|
||||||
|
runs-on: windows-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
repository: ${{ env.GITHUB_REPOSITORY }}
|
||||||
|
ref: ${{ env.GITHUB_HEAD_REF }}
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
choco install -y ninja memurai-developer
|
||||||
|
|
||||||
|
- uses: ilammy/msvc-dev-cmd@v1
|
||||||
|
- name: Build hiredis
|
||||||
|
run: |
|
||||||
|
mkdir build && cd build
|
||||||
|
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DENABLE_EXAMPLES=ON
|
||||||
|
ninja -v
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: |
|
||||||
|
./build/hiredis-test.exe
|
||||||
|
|
||||||
|
- name: Setup cygwin
|
||||||
|
uses: egor-tensin/setup-cygwin@v3
|
||||||
|
with:
|
||||||
|
platform: x64
|
||||||
|
packages: make git gcc-core
|
||||||
|
|
||||||
|
- name: Build in cygwin
|
||||||
|
env:
|
||||||
|
HIREDIS_PATH: ${{ github.workspace }}
|
||||||
|
run: |
|
||||||
|
build_hiredis() {
|
||||||
|
cd $(cygpath -u $HIREDIS_PATH)
|
||||||
|
git clean -xfd
|
||||||
|
make
|
||||||
|
}
|
||||||
|
build_hiredis
|
||||||
|
shell: C:\tools\cygwin\bin\bash.exe --login --norc -eo pipefail -o igncr '{0}'
|
12
deps/hiredis/.travis.yml
vendored
12
deps/hiredis/.travis.yml
vendored
@ -17,11 +17,11 @@ branches:
|
|||||||
- /^release\/.*$/
|
- /^release\/.*$/
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- if [ "$BITS" == "64" ]; then
|
- if [ "$TRAVIS_COMPILER" != "mingw" ]; then
|
||||||
wget https://github.com/redis/redis/archive/6.0.6.tar.gz;
|
wget https://github.com/redis/redis/archive/6.0.6.tar.gz;
|
||||||
tar -xzvf 6.0.6.tar.gz;
|
tar -xzvf 6.0.6.tar.gz;
|
||||||
pushd redis-6.0.6 && BUILD_TLS=yes make && export PATH=$PWD/src:$PATH && popd;
|
pushd redis-6.0.6 && BUILD_TLS=yes make && export PATH=$PWD/src:$PATH && popd;
|
||||||
fi
|
fi;
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then
|
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then
|
||||||
@ -33,8 +33,6 @@ before_script:
|
|||||||
|
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
sources:
|
|
||||||
- sourceline: 'ppa:chris-lea/redis-server'
|
|
||||||
packages:
|
packages:
|
||||||
- libc6-dbg
|
- libc6-dbg
|
||||||
- libc6-dev
|
- libc6-dev
|
||||||
@ -46,17 +44,13 @@ addons:
|
|||||||
- libssl-dev
|
- libssl-dev
|
||||||
- libssl-dev:i386
|
- libssl-dev:i386
|
||||||
- valgrind
|
- valgrind
|
||||||
- redis
|
|
||||||
|
|
||||||
env:
|
env:
|
||||||
- BITS="32"
|
- BITS="32"
|
||||||
- BITS="64"
|
- BITS="64"
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- EXTRA_CMAKE_OPTS="-DENABLE_EXAMPLES:BOOL=ON -DENABLE_SSL:BOOL=ON";
|
- EXTRA_CMAKE_OPTS="-DENABLE_EXAMPLES:BOOL=ON -DENABLE_SSL:BOOL=ON -DENABLE_SSL_TESTS:BOOL=ON";
|
||||||
if [ "$BITS" == "64" ]; then
|
|
||||||
EXTRA_CMAKE_OPTS="$EXTRA_CMAKE_OPTS -DENABLE_SSL_TESTS:BOOL=ON";
|
|
||||||
fi;
|
|
||||||
if [ "$TRAVIS_OS_NAME" == "osx" ]; then
|
if [ "$TRAVIS_OS_NAME" == "osx" ]; then
|
||||||
if [ "$BITS" == "32" ]; then
|
if [ "$BITS" == "32" ]; then
|
||||||
CFLAGS="-m32 -Werror";
|
CFLAGS="-m32 -Werror";
|
||||||
|
19
deps/hiredis/CHANGELOG.md
vendored
19
deps/hiredis/CHANGELOG.md
vendored
@ -1,3 +1,22 @@
|
|||||||
|
## [1.0.2](https://github.com/redis/hiredis/tree/v1.0.2) - (2021-10-07)
|
||||||
|
|
||||||
|
Announcing Hiredis v1.0.2, which fixes CVE-2021-32765 but returns the SONAME to the correct value of `1.0.0`.
|
||||||
|
|
||||||
|
- [Revert SONAME bump](https://github.com/redis/hiredis/commit/d4e6f109a064690cde64765c654e679fea1d3548)
|
||||||
|
([Michael Grunder](https://github.com/michael-grunder))
|
||||||
|
|
||||||
|
## [1.0.1](https://github.com/redis/hiredis/tree/v1.0.1) - (2021-10-04)
|
||||||
|
|
||||||
|
<span style="color:red">This release erroneously bumped the SONAME, please use [1.0.2](https://github.com/redis/hiredis/tree/v1.0.2)</span>
|
||||||
|
|
||||||
|
Announcing Hiredis v1.0.1, a security release fixing CVE-2021-32765
|
||||||
|
|
||||||
|
- Fix for [CVE-2021-32765](https://github.com/redis/hiredis/security/advisories/GHSA-hfm9-39pp-55p2)
|
||||||
|
[commit](https://github.com/redis/hiredis/commit/76a7b10005c70babee357a7d0f2becf28ec7ed1e)
|
||||||
|
([Yossi Gottlieb](https://github.com/yossigo))
|
||||||
|
|
||||||
|
_Thanks to [Yossi Gottlieb](https://github.com/yossigo) for the security fix and to [Microsoft Security Vulnerability Research](https://www.microsoft.com/en-us/msrc/msvr) for finding the bug._ :sparkling_heart:
|
||||||
|
|
||||||
## [1.0.0](https://github.com/redis/hiredis/tree/v1.0.0) - (2020-08-03)
|
## [1.0.0](https://github.com/redis/hiredis/tree/v1.0.0) - (2020-08-03)
|
||||||
|
|
||||||
Announcing Hiredis v1.0.0, which adds support for RESP3, SSL connections, allocator injection, and better Windows support! :tada:
|
Announcing Hiredis v1.0.0, which adds support for RESP3, SSL connections, allocator injection, and better Windows support! :tada:
|
||||||
|
102
deps/hiredis/CMakeLists.txt
vendored
102
deps/hiredis/CMakeLists.txt
vendored
@ -1,10 +1,9 @@
|
|||||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.4.0)
|
CMAKE_MINIMUM_REQUIRED(VERSION 3.4.0)
|
||||||
INCLUDE(GNUInstallDirs)
|
|
||||||
PROJECT(hiredis)
|
|
||||||
|
|
||||||
OPTION(ENABLE_SSL "Build hiredis_ssl for SSL support" OFF)
|
OPTION(ENABLE_SSL "Build hiredis_ssl for SSL support" OFF)
|
||||||
OPTION(DISABLE_TESTS "If tests should be compiled or not" OFF)
|
OPTION(DISABLE_TESTS "If tests should be compiled or not" OFF)
|
||||||
OPTION(ENABLE_SSL_TESTS, "Should we test SSL connections" OFF)
|
OPTION(ENABLE_SSL_TESTS "Should we test SSL connections" OFF)
|
||||||
|
OPTION(ENABLE_ASYNC_TESTS "Should we run all asynchronous API tests" OFF)
|
||||||
|
|
||||||
MACRO(getVersionBit name)
|
MACRO(getVersionBit name)
|
||||||
SET(VERSION_REGEX "^#define ${name} (.+)$")
|
SET(VERSION_REGEX "^#define ${name} (.+)$")
|
||||||
@ -20,7 +19,13 @@ getVersionBit(HIREDIS_SONAME)
|
|||||||
SET(VERSION "${HIREDIS_MAJOR}.${HIREDIS_MINOR}.${HIREDIS_PATCH}")
|
SET(VERSION "${HIREDIS_MAJOR}.${HIREDIS_MINOR}.${HIREDIS_PATCH}")
|
||||||
MESSAGE("Detected version: ${VERSION}")
|
MESSAGE("Detected version: ${VERSION}")
|
||||||
|
|
||||||
PROJECT(hiredis VERSION "${VERSION}")
|
PROJECT(hiredis LANGUAGES "C" VERSION "${VERSION}")
|
||||||
|
INCLUDE(GNUInstallDirs)
|
||||||
|
|
||||||
|
# Hiredis requires C99
|
||||||
|
SET(CMAKE_C_STANDARD 99)
|
||||||
|
SET(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||||
|
SET(CMAKE_DEBUG_POSTFIX d)
|
||||||
|
|
||||||
SET(ENABLE_EXAMPLES OFF CACHE BOOL "Enable building hiredis examples")
|
SET(ENABLE_EXAMPLES OFF CACHE BOOL "Enable building hiredis examples")
|
||||||
|
|
||||||
@ -41,24 +46,78 @@ IF(WIN32)
|
|||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
ADD_LIBRARY(hiredis SHARED ${hiredis_sources})
|
ADD_LIBRARY(hiredis SHARED ${hiredis_sources})
|
||||||
|
ADD_LIBRARY(hiredis_static STATIC ${hiredis_sources})
|
||||||
|
ADD_LIBRARY(hiredis::hiredis ALIAS hiredis)
|
||||||
|
ADD_LIBRARY(hiredis::hiredis_static ALIAS hiredis_static)
|
||||||
|
|
||||||
SET_TARGET_PROPERTIES(hiredis
|
SET_TARGET_PROPERTIES(hiredis
|
||||||
PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE
|
PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE
|
||||||
VERSION "${HIREDIS_SONAME}")
|
VERSION "${HIREDIS_SONAME}")
|
||||||
|
SET_TARGET_PROPERTIES(hiredis_static
|
||||||
|
PROPERTIES COMPILE_PDB_NAME hiredis_static)
|
||||||
|
SET_TARGET_PROPERTIES(hiredis_static
|
||||||
|
PROPERTIES COMPILE_PDB_NAME_DEBUG hiredis_static${CMAKE_DEBUG_POSTFIX})
|
||||||
IF(WIN32 OR MINGW)
|
IF(WIN32 OR MINGW)
|
||||||
TARGET_LINK_LIBRARIES(hiredis PRIVATE ws2_32)
|
TARGET_LINK_LIBRARIES(hiredis PUBLIC ws2_32 crypt32)
|
||||||
|
TARGET_LINK_LIBRARIES(hiredis_static PUBLIC ws2_32 crypt32)
|
||||||
|
ELSEIF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
||||||
|
TARGET_LINK_LIBRARIES(hiredis PUBLIC m)
|
||||||
|
TARGET_LINK_LIBRARIES(hiredis_static PUBLIC m)
|
||||||
|
ELSEIF(CMAKE_SYSTEM_NAME MATCHES "SunOS")
|
||||||
|
TARGET_LINK_LIBRARIES(hiredis PUBLIC socket)
|
||||||
|
TARGET_LINK_LIBRARIES(hiredis_static PUBLIC socket)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
TARGET_INCLUDE_DIRECTORIES(hiredis PUBLIC $<INSTALL_INTERFACE:.> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
|
TARGET_INCLUDE_DIRECTORIES(hiredis PUBLIC $<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
|
||||||
|
TARGET_INCLUDE_DIRECTORIES(hiredis_static PUBLIC $<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
|
||||||
|
|
||||||
CONFIGURE_FILE(hiredis.pc.in hiredis.pc @ONLY)
|
CONFIGURE_FILE(hiredis.pc.in hiredis.pc @ONLY)
|
||||||
|
|
||||||
INSTALL(TARGETS hiredis
|
set(CPACK_PACKAGE_VENDOR "Redis")
|
||||||
|
set(CPACK_PACKAGE_DESCRIPTION "\
|
||||||
|
Hiredis is a minimalistic C client library for the Redis database.
|
||||||
|
|
||||||
|
It is minimalistic because it just adds minimal support for the protocol, \
|
||||||
|
but at the same time it uses a high level printf-alike API in order to make \
|
||||||
|
it much higher level than otherwise suggested by its minimal code base and the \
|
||||||
|
lack of explicit bindings for every Redis command.
|
||||||
|
|
||||||
|
Apart from supporting sending commands and receiving replies, it comes with a \
|
||||||
|
reply parser that is decoupled from the I/O layer. It is a stream parser designed \
|
||||||
|
for easy reusability, which can for instance be used in higher level language bindings \
|
||||||
|
for efficient reply parsing.
|
||||||
|
|
||||||
|
Hiredis only supports the binary-safe Redis protocol, so you can use it with any Redis \
|
||||||
|
version >= 1.2.0.
|
||||||
|
|
||||||
|
The library comes with multiple APIs. There is the synchronous API, the asynchronous API \
|
||||||
|
and the reply parsing API.")
|
||||||
|
set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/redis/hiredis")
|
||||||
|
set(CPACK_PACKAGE_CONTACT "michael dot grunder at gmail dot com")
|
||||||
|
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
|
||||||
|
set(CPACK_RPM_PACKAGE_AUTOREQPROV ON)
|
||||||
|
|
||||||
|
include(CPack)
|
||||||
|
|
||||||
|
INSTALL(TARGETS hiredis hiredis_static
|
||||||
EXPORT hiredis-targets
|
EXPORT hiredis-targets
|
||||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||||
|
|
||||||
|
if (MSVC)
|
||||||
|
INSTALL(FILES $<TARGET_PDB_FILE:hiredis>
|
||||||
|
DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
|
CONFIGURATIONS Debug RelWithDebInfo)
|
||||||
|
INSTALL(FILES $<TARGET_FILE_DIR:hiredis_static>/$<TARGET_FILE_BASE_NAME:hiredis_static>.pdb
|
||||||
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
CONFIGURATIONS Debug RelWithDebInfo)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# For NuGet packages
|
||||||
|
INSTALL(FILES hiredis.targets
|
||||||
|
DESTINATION build/native)
|
||||||
|
|
||||||
INSTALL(FILES hiredis.h read.h sds.h async.h alloc.h
|
INSTALL(FILES hiredis.h read.h sds.h async.h alloc.h
|
||||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/hiredis)
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/hiredis)
|
||||||
|
|
||||||
@ -99,6 +158,8 @@ IF(ENABLE_SSL)
|
|||||||
ssl.c)
|
ssl.c)
|
||||||
ADD_LIBRARY(hiredis_ssl SHARED
|
ADD_LIBRARY(hiredis_ssl SHARED
|
||||||
${hiredis_ssl_sources})
|
${hiredis_ssl_sources})
|
||||||
|
ADD_LIBRARY(hiredis_ssl_static STATIC
|
||||||
|
${hiredis_ssl_sources})
|
||||||
|
|
||||||
IF (APPLE)
|
IF (APPLE)
|
||||||
SET_PROPERTY(TARGET hiredis_ssl PROPERTY LINK_FLAGS "-Wl,-undefined -Wl,dynamic_lookup")
|
SET_PROPERTY(TARGET hiredis_ssl PROPERTY LINK_FLAGS "-Wl,-undefined -Wl,dynamic_lookup")
|
||||||
@ -108,20 +169,36 @@ IF(ENABLE_SSL)
|
|||||||
PROPERTIES
|
PROPERTIES
|
||||||
WINDOWS_EXPORT_ALL_SYMBOLS TRUE
|
WINDOWS_EXPORT_ALL_SYMBOLS TRUE
|
||||||
VERSION "${HIREDIS_SONAME}")
|
VERSION "${HIREDIS_SONAME}")
|
||||||
|
SET_TARGET_PROPERTIES(hiredis_ssl_static
|
||||||
|
PROPERTIES COMPILE_PDB_NAME hiredis_ssl_static)
|
||||||
|
SET_TARGET_PROPERTIES(hiredis_ssl_static
|
||||||
|
PROPERTIES COMPILE_PDB_NAME_DEBUG hiredis_ssl_static${CMAKE_DEBUG_POSTFIX})
|
||||||
|
|
||||||
TARGET_INCLUDE_DIRECTORIES(hiredis_ssl PRIVATE "${OPENSSL_INCLUDE_DIR}")
|
TARGET_INCLUDE_DIRECTORIES(hiredis_ssl PRIVATE "${OPENSSL_INCLUDE_DIR}")
|
||||||
|
TARGET_INCLUDE_DIRECTORIES(hiredis_ssl_static PRIVATE "${OPENSSL_INCLUDE_DIR}")
|
||||||
|
|
||||||
TARGET_LINK_LIBRARIES(hiredis_ssl PRIVATE ${OPENSSL_LIBRARIES})
|
TARGET_LINK_LIBRARIES(hiredis_ssl PRIVATE ${OPENSSL_LIBRARIES})
|
||||||
IF (WIN32 OR MINGW)
|
IF (WIN32 OR MINGW)
|
||||||
TARGET_LINK_LIBRARIES(hiredis_ssl PRIVATE hiredis)
|
TARGET_LINK_LIBRARIES(hiredis_ssl PRIVATE hiredis)
|
||||||
|
TARGET_LINK_LIBRARIES(hiredis_ssl_static PUBLIC hiredis_static)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
CONFIGURE_FILE(hiredis_ssl.pc.in hiredis_ssl.pc @ONLY)
|
CONFIGURE_FILE(hiredis_ssl.pc.in hiredis_ssl.pc @ONLY)
|
||||||
|
|
||||||
INSTALL(TARGETS hiredis_ssl
|
INSTALL(TARGETS hiredis_ssl hiredis_ssl_static
|
||||||
EXPORT hiredis_ssl-targets
|
EXPORT hiredis_ssl-targets
|
||||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||||
|
|
||||||
|
if (MSVC)
|
||||||
|
INSTALL(FILES $<TARGET_PDB_FILE:hiredis_ssl>
|
||||||
|
DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
|
CONFIGURATIONS Debug RelWithDebInfo)
|
||||||
|
INSTALL(FILES $<TARGET_FILE_DIR:hiredis_ssl_static>/$<TARGET_FILE_BASE_NAME:hiredis_ssl_static>.pdb
|
||||||
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
CONFIGURATIONS Debug RelWithDebInfo)
|
||||||
|
endif()
|
||||||
|
|
||||||
INSTALL(FILES hiredis_ssl.h
|
INSTALL(FILES hiredis_ssl.h
|
||||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/hiredis)
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/hiredis)
|
||||||
|
|
||||||
@ -149,11 +226,14 @@ ENDIF()
|
|||||||
IF(NOT DISABLE_TESTS)
|
IF(NOT DISABLE_TESTS)
|
||||||
ENABLE_TESTING()
|
ENABLE_TESTING()
|
||||||
ADD_EXECUTABLE(hiredis-test test.c)
|
ADD_EXECUTABLE(hiredis-test test.c)
|
||||||
|
TARGET_LINK_LIBRARIES(hiredis-test hiredis)
|
||||||
IF(ENABLE_SSL_TESTS)
|
IF(ENABLE_SSL_TESTS)
|
||||||
ADD_DEFINITIONS(-DHIREDIS_TEST_SSL=1)
|
ADD_DEFINITIONS(-DHIREDIS_TEST_SSL=1)
|
||||||
TARGET_LINK_LIBRARIES(hiredis-test hiredis hiredis_ssl)
|
TARGET_LINK_LIBRARIES(hiredis-test hiredis_ssl)
|
||||||
ELSE()
|
ENDIF()
|
||||||
TARGET_LINK_LIBRARIES(hiredis-test hiredis)
|
IF(ENABLE_ASYNC_TESTS)
|
||||||
|
ADD_DEFINITIONS(-DHIREDIS_TEST_ASYNC=1)
|
||||||
|
TARGET_LINK_LIBRARIES(hiredis-test event)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
ADD_TEST(NAME hiredis-test
|
ADD_TEST(NAME hiredis-test
|
||||||
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test.sh)
|
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test.sh)
|
||||||
|
111
deps/hiredis/Makefile
vendored
111
deps/hiredis/Makefile
vendored
@ -4,16 +4,10 @@
|
|||||||
# This file is released under the BSD license, see the COPYING file
|
# This file is released under the BSD license, see the COPYING file
|
||||||
|
|
||||||
OBJ=alloc.o net.o hiredis.o sds.o async.o read.o sockcompat.o
|
OBJ=alloc.o net.o hiredis.o sds.o async.o read.o sockcompat.o
|
||||||
SSL_OBJ=ssl.o
|
|
||||||
EXAMPLES=hiredis-example hiredis-example-libevent hiredis-example-libev hiredis-example-glib hiredis-example-push
|
EXAMPLES=hiredis-example hiredis-example-libevent hiredis-example-libev hiredis-example-glib hiredis-example-push
|
||||||
ifeq ($(USE_SSL),1)
|
|
||||||
EXAMPLES+=hiredis-example-ssl hiredis-example-libevent-ssl
|
|
||||||
endif
|
|
||||||
TESTS=hiredis-test
|
TESTS=hiredis-test
|
||||||
LIBNAME=libhiredis
|
LIBNAME=libhiredis
|
||||||
PKGCONFNAME=hiredis.pc
|
PKGCONFNAME=hiredis.pc
|
||||||
SSL_LIBNAME=libhiredis_ssl
|
|
||||||
SSL_PKGCONFNAME=hiredis_ssl.pc
|
|
||||||
|
|
||||||
HIREDIS_MAJOR=$(shell grep HIREDIS_MAJOR hiredis.h | awk '{print $$3}')
|
HIREDIS_MAJOR=$(shell grep HIREDIS_MAJOR hiredis.h | awk '{print $$3}')
|
||||||
HIREDIS_MINOR=$(shell grep HIREDIS_MINOR hiredis.h | awk '{print $$3}')
|
HIREDIS_MINOR=$(shell grep HIREDIS_MINOR hiredis.h | awk '{print $$3}')
|
||||||
@ -60,33 +54,66 @@ DYLIB_MAKE_CMD=$(CC) -shared -Wl,-soname,$(DYLIB_MINOR_NAME)
|
|||||||
STLIBNAME=$(LIBNAME).$(STLIBSUFFIX)
|
STLIBNAME=$(LIBNAME).$(STLIBSUFFIX)
|
||||||
STLIB_MAKE_CMD=$(AR) rcs
|
STLIB_MAKE_CMD=$(AR) rcs
|
||||||
|
|
||||||
|
#################### SSL variables start ####################
|
||||||
|
SSL_OBJ=ssl.o
|
||||||
|
SSL_LIBNAME=libhiredis_ssl
|
||||||
|
SSL_PKGCONFNAME=hiredis_ssl.pc
|
||||||
|
SSL_INSTALLNAME=install-ssl
|
||||||
SSL_DYLIB_MINOR_NAME=$(SSL_LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_SONAME)
|
SSL_DYLIB_MINOR_NAME=$(SSL_LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_SONAME)
|
||||||
SSL_DYLIB_MAJOR_NAME=$(SSL_LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_MAJOR)
|
SSL_DYLIB_MAJOR_NAME=$(SSL_LIBNAME).$(DYLIBSUFFIX).$(HIREDIS_MAJOR)
|
||||||
SSL_DYLIBNAME=$(SSL_LIBNAME).$(DYLIBSUFFIX)
|
SSL_DYLIBNAME=$(SSL_LIBNAME).$(DYLIBSUFFIX)
|
||||||
SSL_STLIBNAME=$(SSL_LIBNAME).$(STLIBSUFFIX)
|
SSL_STLIBNAME=$(SSL_LIBNAME).$(STLIBSUFFIX)
|
||||||
SSL_DYLIB_MAKE_CMD=$(CC) -shared -Wl,-soname,$(SSL_DYLIB_MINOR_NAME)
|
SSL_DYLIB_MAKE_CMD=$(CC) -shared -Wl,-soname,$(SSL_DYLIB_MINOR_NAME)
|
||||||
|
|
||||||
|
USE_SSL?=0
|
||||||
|
ifeq ($(USE_SSL),1)
|
||||||
|
# This is required for test.c only
|
||||||
|
CFLAGS+=-DHIREDIS_TEST_SSL
|
||||||
|
EXAMPLES+=hiredis-example-ssl hiredis-example-libevent-ssl
|
||||||
|
SSL_STLIB=$(SSL_STLIBNAME)
|
||||||
|
SSL_DYLIB=$(SSL_DYLIBNAME)
|
||||||
|
SSL_PKGCONF=$(SSL_PKGCONFNAME)
|
||||||
|
SSL_INSTALL=$(SSL_INSTALLNAME)
|
||||||
|
else
|
||||||
|
SSL_STLIB=
|
||||||
|
SSL_DYLIB=
|
||||||
|
SSL_PKGCONF=
|
||||||
|
SSL_INSTALL=
|
||||||
|
endif
|
||||||
|
##################### SSL variables end #####################
|
||||||
|
|
||||||
|
|
||||||
# Platform-specific overrides
|
# Platform-specific overrides
|
||||||
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
|
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
|
||||||
|
|
||||||
USE_SSL?=0
|
|
||||||
|
|
||||||
# This is required for test.c only
|
# This is required for test.c only
|
||||||
ifeq ($(USE_SSL),1)
|
ifeq ($(TEST_ASYNC),1)
|
||||||
CFLAGS+=-DHIREDIS_TEST_SSL
|
export CFLAGS+=-DHIREDIS_TEST_ASYNC
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(uname_S),Linux)
|
ifeq ($(USE_SSL),1)
|
||||||
ifdef OPENSSL_PREFIX
|
ifeq ($(uname_S),Linux)
|
||||||
|
ifdef OPENSSL_PREFIX
|
||||||
|
CFLAGS+=-I$(OPENSSL_PREFIX)/include
|
||||||
|
SSL_LDFLAGS+=-L$(OPENSSL_PREFIX)/lib -lssl -lcrypto
|
||||||
|
else
|
||||||
|
SSL_LDFLAGS=-lssl -lcrypto
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
OPENSSL_PREFIX?=/usr/local/opt/openssl
|
||||||
CFLAGS+=-I$(OPENSSL_PREFIX)/include
|
CFLAGS+=-I$(OPENSSL_PREFIX)/include
|
||||||
SSL_LDFLAGS+=-L$(OPENSSL_PREFIX)/lib -lssl -lcrypto
|
SSL_LDFLAGS+=-L$(OPENSSL_PREFIX)/lib -lssl -lcrypto
|
||||||
else
|
endif
|
||||||
SSL_LDFLAGS=-lssl -lcrypto
|
endif
|
||||||
|
|
||||||
|
ifeq ($(uname_S),FreeBSD)
|
||||||
|
LDFLAGS+=-lm
|
||||||
|
IS_GCC=$(shell sh -c '$(CC) --version 2>/dev/null |egrep -i -c "gcc"')
|
||||||
|
ifeq ($(IS_GCC),1)
|
||||||
|
REAL_CFLAGS+=-pedantic
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
OPENSSL_PREFIX?=/usr/local/opt/openssl
|
REAL_CFLAGS+=-pedantic
|
||||||
CFLAGS+=-I$(OPENSSL_PREFIX)/include
|
|
||||||
SSL_LDFLAGS+=-L$(OPENSSL_PREFIX)/lib -lssl -lcrypto
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(uname_S),SunOS)
|
ifeq ($(uname_S),SunOS)
|
||||||
@ -108,10 +135,13 @@ ifeq ($(uname_S),Darwin)
|
|||||||
DYLIB_PLUGIN=-Wl,-undefined -Wl,dynamic_lookup
|
DYLIB_PLUGIN=-Wl,-undefined -Wl,dynamic_lookup
|
||||||
endif
|
endif
|
||||||
|
|
||||||
all: $(DYLIBNAME) $(STLIBNAME) hiredis-test $(PKGCONFNAME)
|
all: dynamic static hiredis-test pkgconfig
|
||||||
ifeq ($(USE_SSL),1)
|
|
||||||
all: $(SSL_DYLIBNAME) $(SSL_STLIBNAME) $(SSL_PKGCONFNAME)
|
dynamic: $(DYLIBNAME) $(SSL_DYLIB)
|
||||||
endif
|
|
||||||
|
static: $(STLIBNAME) $(SSL_STLIB)
|
||||||
|
|
||||||
|
pkgconfig: $(PKGCONFNAME) $(SSL_PKGCONF)
|
||||||
|
|
||||||
# Deps (use make dep to generate this)
|
# Deps (use make dep to generate this)
|
||||||
alloc.o: alloc.c fmacros.h alloc.h
|
alloc.o: alloc.c fmacros.h alloc.h
|
||||||
@ -122,7 +152,6 @@ net.o: net.c fmacros.h net.h hiredis.h read.h sds.h alloc.h sockcompat.h win32.h
|
|||||||
read.o: read.c fmacros.h alloc.h read.h sds.h win32.h
|
read.o: read.c fmacros.h alloc.h read.h sds.h win32.h
|
||||||
sds.o: sds.c sds.h sdsalloc.h alloc.h
|
sds.o: sds.c sds.h sdsalloc.h alloc.h
|
||||||
sockcompat.o: sockcompat.c sockcompat.h
|
sockcompat.o: sockcompat.c sockcompat.h
|
||||||
ssl.o: ssl.c hiredis.h read.h sds.h alloc.h async.h win32.h async_private.h
|
|
||||||
test.o: test.c fmacros.h hiredis.h read.h sds.h alloc.h net.h sockcompat.h win32.h
|
test.o: test.c fmacros.h hiredis.h read.h sds.h alloc.h net.h sockcompat.h win32.h
|
||||||
|
|
||||||
$(DYLIBNAME): $(OBJ)
|
$(DYLIBNAME): $(OBJ)
|
||||||
@ -131,18 +160,15 @@ $(DYLIBNAME): $(OBJ)
|
|||||||
$(STLIBNAME): $(OBJ)
|
$(STLIBNAME): $(OBJ)
|
||||||
$(STLIB_MAKE_CMD) $(STLIBNAME) $(OBJ)
|
$(STLIB_MAKE_CMD) $(STLIBNAME) $(OBJ)
|
||||||
|
|
||||||
|
#################### SSL building rules start ####################
|
||||||
$(SSL_DYLIBNAME): $(SSL_OBJ)
|
$(SSL_DYLIBNAME): $(SSL_OBJ)
|
||||||
$(SSL_DYLIB_MAKE_CMD) $(DYLIB_PLUGIN) -o $(SSL_DYLIBNAME) $(SSL_OBJ) $(REAL_LDFLAGS) $(LDFLAGS) $(SSL_LDFLAGS)
|
$(SSL_DYLIB_MAKE_CMD) $(DYLIB_PLUGIN) -o $(SSL_DYLIBNAME) $(SSL_OBJ) $(REAL_LDFLAGS) $(LDFLAGS) $(SSL_LDFLAGS)
|
||||||
|
|
||||||
$(SSL_STLIBNAME): $(SSL_OBJ)
|
$(SSL_STLIBNAME): $(SSL_OBJ)
|
||||||
$(STLIB_MAKE_CMD) $(SSL_STLIBNAME) $(SSL_OBJ)
|
$(STLIB_MAKE_CMD) $(SSL_STLIBNAME) $(SSL_OBJ)
|
||||||
|
|
||||||
dynamic: $(DYLIBNAME)
|
$(SSL_OBJ): ssl.c hiredis.h read.h sds.h alloc.h async.h win32.h async_private.h
|
||||||
static: $(STLIBNAME)
|
#################### SSL building rules end ####################
|
||||||
ifeq ($(USE_SSL),1)
|
|
||||||
dynamic: $(SSL_DYLIBNAME)
|
|
||||||
static: $(SSL_STLIBNAME)
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Binaries:
|
# Binaries:
|
||||||
hiredis-example-libevent: examples/example-libevent.c adapters/libevent.h $(STLIBNAME)
|
hiredis-example-libevent: examples/example-libevent.c adapters/libevent.h $(STLIBNAME)
|
||||||
@ -166,7 +192,6 @@ hiredis-example-macosx: examples/example-macosx.c adapters/macosx.h $(STLIBNAME)
|
|||||||
hiredis-example-ssl: examples/example-ssl.c $(STLIBNAME) $(SSL_STLIBNAME)
|
hiredis-example-ssl: examples/example-ssl.c $(STLIBNAME) $(SSL_STLIBNAME)
|
||||||
$(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< $(STLIBNAME) $(SSL_STLIBNAME) $(REAL_LDFLAGS) $(SSL_LDFLAGS)
|
$(CC) -o examples/$@ $(REAL_CFLAGS) -I. $< $(STLIBNAME) $(SSL_STLIBNAME) $(REAL_LDFLAGS) $(SSL_LDFLAGS)
|
||||||
|
|
||||||
|
|
||||||
ifndef AE_DIR
|
ifndef AE_DIR
|
||||||
hiredis-example-ae:
|
hiredis-example-ae:
|
||||||
@echo "Please specify AE_DIR (e.g. <redis repository>/src)"
|
@echo "Please specify AE_DIR (e.g. <redis repository>/src)"
|
||||||
@ -177,10 +202,11 @@ hiredis-example-ae: examples/example-ae.c adapters/ae.h $(STLIBNAME)
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
ifndef LIBUV_DIR
|
ifndef LIBUV_DIR
|
||||||
hiredis-example-libuv:
|
# dynamic link libuv.so
|
||||||
@echo "Please specify LIBUV_DIR (e.g. ../libuv/)"
|
hiredis-example-libuv: examples/example-libuv.c adapters/libuv.h $(STLIBNAME)
|
||||||
@false
|
$(CC) -o examples/$@ $(REAL_CFLAGS) -I. -I$(LIBUV_DIR)/include $< -luv -lpthread -lrt $(STLIBNAME) $(REAL_LDFLAGS)
|
||||||
else
|
else
|
||||||
|
# use user provided static lib
|
||||||
hiredis-example-libuv: examples/example-libuv.c adapters/libuv.h $(STLIBNAME)
|
hiredis-example-libuv: examples/example-libuv.c adapters/libuv.h $(STLIBNAME)
|
||||||
$(CC) -o examples/$@ $(REAL_CFLAGS) -I. -I$(LIBUV_DIR)/include $< $(LIBUV_DIR)/.libs/libuv.a -lpthread -lrt $(STLIBNAME) $(REAL_LDFLAGS)
|
$(CC) -o examples/$@ $(REAL_CFLAGS) -I. -I$(LIBUV_DIR)/include $< $(LIBUV_DIR)/.libs/libuv.a -lpthread -lrt $(STLIBNAME) $(REAL_LDFLAGS)
|
||||||
endif
|
endif
|
||||||
@ -206,10 +232,13 @@ hiredis-example-push: examples/example-push.c $(STLIBNAME)
|
|||||||
|
|
||||||
examples: $(EXAMPLES)
|
examples: $(EXAMPLES)
|
||||||
|
|
||||||
TEST_LIBS = $(STLIBNAME)
|
TEST_LIBS = $(STLIBNAME) $(SSL_STLIB)
|
||||||
|
TEST_LDFLAGS = $(SSL_LDFLAGS)
|
||||||
ifeq ($(USE_SSL),1)
|
ifeq ($(USE_SSL),1)
|
||||||
TEST_LIBS += $(SSL_STLIBNAME)
|
TEST_LDFLAGS += -pthread
|
||||||
TEST_LDFLAGS = $(SSL_LDFLAGS) -lssl -lcrypto -lpthread
|
endif
|
||||||
|
ifeq ($(TEST_ASYNC),1)
|
||||||
|
TEST_LDFLAGS += -levent
|
||||||
endif
|
endif
|
||||||
|
|
||||||
hiredis-test: test.o $(TEST_LIBS)
|
hiredis-test: test.o $(TEST_LIBS)
|
||||||
@ -225,7 +254,7 @@ check: hiredis-test
|
|||||||
TEST_SSL=$(USE_SSL) ./test.sh
|
TEST_SSL=$(USE_SSL) ./test.sh
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
$(CC) -std=c99 -pedantic -c $(REAL_CFLAGS) $<
|
$(CC) -std=c99 -c $(REAL_CFLAGS) $<
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(DYLIBNAME) $(STLIBNAME) $(SSL_DYLIBNAME) $(SSL_STLIBNAME) $(TESTS) $(PKGCONFNAME) examples/hiredis-example* *.o *.gcda *.gcno *.gcov
|
rm -rf $(DYLIBNAME) $(STLIBNAME) $(SSL_DYLIBNAME) $(SSL_STLIBNAME) $(TESTS) $(PKGCONFNAME) examples/hiredis-example* *.o *.gcda *.gcno *.gcov
|
||||||
@ -262,7 +291,7 @@ $(SSL_PKGCONFNAME): hiredis_ssl.h
|
|||||||
@echo Libs: -L\$${libdir} -lhiredis_ssl >> $@
|
@echo Libs: -L\$${libdir} -lhiredis_ssl >> $@
|
||||||
@echo Libs.private: -lssl -lcrypto >> $@
|
@echo Libs.private: -lssl -lcrypto >> $@
|
||||||
|
|
||||||
install: $(DYLIBNAME) $(STLIBNAME) $(PKGCONFNAME)
|
install: $(DYLIBNAME) $(STLIBNAME) $(PKGCONFNAME) $(SSL_INSTALL)
|
||||||
mkdir -p $(INSTALL_INCLUDE_PATH) $(INSTALL_INCLUDE_PATH)/adapters $(INSTALL_LIBRARY_PATH)
|
mkdir -p $(INSTALL_INCLUDE_PATH) $(INSTALL_INCLUDE_PATH)/adapters $(INSTALL_LIBRARY_PATH)
|
||||||
$(INSTALL) hiredis.h async.h read.h sds.h alloc.h $(INSTALL_INCLUDE_PATH)
|
$(INSTALL) hiredis.h async.h read.h sds.h alloc.h $(INSTALL_INCLUDE_PATH)
|
||||||
$(INSTALL) adapters/*.h $(INSTALL_INCLUDE_PATH)/adapters
|
$(INSTALL) adapters/*.h $(INSTALL_INCLUDE_PATH)/adapters
|
||||||
@ -272,9 +301,6 @@ install: $(DYLIBNAME) $(STLIBNAME) $(PKGCONFNAME)
|
|||||||
mkdir -p $(INSTALL_PKGCONF_PATH)
|
mkdir -p $(INSTALL_PKGCONF_PATH)
|
||||||
$(INSTALL) $(PKGCONFNAME) $(INSTALL_PKGCONF_PATH)
|
$(INSTALL) $(PKGCONFNAME) $(INSTALL_PKGCONF_PATH)
|
||||||
|
|
||||||
ifeq ($(USE_SSL),1)
|
|
||||||
install: install-ssl
|
|
||||||
|
|
||||||
install-ssl: $(SSL_DYLIBNAME) $(SSL_STLIBNAME) $(SSL_PKGCONFNAME)
|
install-ssl: $(SSL_DYLIBNAME) $(SSL_STLIBNAME) $(SSL_PKGCONFNAME)
|
||||||
mkdir -p $(INSTALL_INCLUDE_PATH) $(INSTALL_LIBRARY_PATH)
|
mkdir -p $(INSTALL_INCLUDE_PATH) $(INSTALL_LIBRARY_PATH)
|
||||||
$(INSTALL) hiredis_ssl.h $(INSTALL_INCLUDE_PATH)
|
$(INSTALL) hiredis_ssl.h $(INSTALL_INCLUDE_PATH)
|
||||||
@ -283,7 +309,6 @@ install-ssl: $(SSL_DYLIBNAME) $(SSL_STLIBNAME) $(SSL_PKGCONFNAME)
|
|||||||
$(INSTALL) $(SSL_STLIBNAME) $(INSTALL_LIBRARY_PATH)
|
$(INSTALL) $(SSL_STLIBNAME) $(INSTALL_LIBRARY_PATH)
|
||||||
mkdir -p $(INSTALL_PKGCONF_PATH)
|
mkdir -p $(INSTALL_PKGCONF_PATH)
|
||||||
$(INSTALL) $(SSL_PKGCONFNAME) $(INSTALL_PKGCONF_PATH)
|
$(INSTALL) $(SSL_PKGCONFNAME) $(INSTALL_PKGCONF_PATH)
|
||||||
endif
|
|
||||||
|
|
||||||
32bit:
|
32bit:
|
||||||
@echo ""
|
@echo ""
|
||||||
@ -299,12 +324,12 @@ gprof:
|
|||||||
$(MAKE) CFLAGS="-pg" LDFLAGS="-pg"
|
$(MAKE) CFLAGS="-pg" LDFLAGS="-pg"
|
||||||
|
|
||||||
gcov:
|
gcov:
|
||||||
$(MAKE) CFLAGS="-fprofile-arcs -ftest-coverage" LDFLAGS="-fprofile-arcs"
|
$(MAKE) CFLAGS+="-fprofile-arcs -ftest-coverage" LDFLAGS="-fprofile-arcs"
|
||||||
|
|
||||||
coverage: gcov
|
coverage: gcov
|
||||||
make check
|
make check
|
||||||
mkdir -p tmp/lcov
|
mkdir -p tmp/lcov
|
||||||
lcov -d . -c -o tmp/lcov/hiredis.info
|
lcov -d . -c --exclude '/usr*' -o tmp/lcov/hiredis.info
|
||||||
genhtml --legend -o tmp/lcov/report tmp/lcov/hiredis.info
|
genhtml --legend -o tmp/lcov/report tmp/lcov/hiredis.info
|
||||||
|
|
||||||
noopt:
|
noopt:
|
||||||
|
41
deps/hiredis/README.md
vendored
41
deps/hiredis/README.md
vendored
@ -1,10 +1,11 @@
|
|||||||
[![Build Status](https://travis-ci.org/redis/hiredis.png)](https://travis-ci.org/redis/hiredis)
|
|
||||||
|
[![Build Status](https://github.com/redis/hiredis/actions/workflows/build.yml/badge.svg)](https://github.com/redis/hiredis/actions/workflows/build.yml)
|
||||||
|
|
||||||
**This Readme reflects the latest changed in the master branch. See [v1.0.0](https://github.com/redis/hiredis/tree/v1.0.0) for the Readme and documentation for the latest release ([API/ABI history](https://abi-laboratory.pro/?view=timeline&l=hiredis)).**
|
**This Readme reflects the latest changed in the master branch. See [v1.0.0](https://github.com/redis/hiredis/tree/v1.0.0) for the Readme and documentation for the latest release ([API/ABI history](https://abi-laboratory.pro/?view=timeline&l=hiredis)).**
|
||||||
|
|
||||||
# HIREDIS
|
# HIREDIS
|
||||||
|
|
||||||
Hiredis is a minimalistic C client library for the [Redis](http://redis.io/) database.
|
Hiredis is a minimalistic C client library for the [Redis](https://redis.io/) database.
|
||||||
|
|
||||||
It is minimalistic because it just adds minimal support for the protocol, but
|
It is minimalistic because it just adds minimal support for the protocol, but
|
||||||
at the same time it uses a high level printf-alike API in order to make it
|
at the same time it uses a high level printf-alike API in order to make it
|
||||||
@ -22,6 +23,12 @@ Redis version >= 1.2.0.
|
|||||||
The library comes with multiple APIs. There is the
|
The library comes with multiple APIs. There is the
|
||||||
*synchronous API*, the *asynchronous API* and the *reply parsing API*.
|
*synchronous API*, the *asynchronous API* and the *reply parsing API*.
|
||||||
|
|
||||||
|
## Upgrading to `1.0.2`
|
||||||
|
|
||||||
|
<span style="color:red">NOTE: v1.0.1 erroneously bumped SONAME, which is why it is skipped here.</span>
|
||||||
|
|
||||||
|
Version 1.0.2 is simply 1.0.0 with a fix for [CVE-2021-32765](https://github.com/redis/hiredis/security/advisories/GHSA-hfm9-39pp-55p2). They are otherwise identical.
|
||||||
|
|
||||||
## Upgrading to `1.0.0`
|
## Upgrading to `1.0.0`
|
||||||
|
|
||||||
Version 1.0.0 marks the first stable release of Hiredis.
|
Version 1.0.0 marks the first stable release of Hiredis.
|
||||||
@ -169,7 +176,7 @@ Hiredis also supports every new `RESP3` data type which are as follows. For mor
|
|||||||
|
|
||||||
* **`REDIS_REPLY_MAP`**:
|
* **`REDIS_REPLY_MAP`**:
|
||||||
* An array with the added invariant that there will always be an even number of elements.
|
* An array with the added invariant that there will always be an even number of elements.
|
||||||
The MAP is functionally equivelant to `REDIS_REPLY_ARRAY` except for the previously mentioned invariant.
|
The MAP is functionally equivalent to `REDIS_REPLY_ARRAY` except for the previously mentioned invariant.
|
||||||
|
|
||||||
* **`REDIS_REPLY_SET`**:
|
* **`REDIS_REPLY_SET`**:
|
||||||
* An array response where each entry is unique.
|
* An array response where each entry is unique.
|
||||||
@ -189,7 +196,7 @@ Hiredis also supports every new `RESP3` data type which are as follows. For mor
|
|||||||
|
|
||||||
* **`REDIS_REPLY_VERB`**:
|
* **`REDIS_REPLY_VERB`**:
|
||||||
* A verbatim string, intended to be presented to the user without modification.
|
* A verbatim string, intended to be presented to the user without modification.
|
||||||
The string payload is stored in the `str` memeber, and type data is stored in the `vtype` member (e.g. `txt` for raw text or `md` for markdown).
|
The string payload is stored in the `str` member, and type data is stored in the `vtype` member (e.g. `txt` for raw text or `md` for markdown).
|
||||||
|
|
||||||
Replies should be freed using the `freeReplyObject()` function.
|
Replies should be freed using the `freeReplyObject()` function.
|
||||||
Note that this function will take care of freeing sub-reply objects
|
Note that this function will take care of freeing sub-reply objects
|
||||||
@ -261,9 +268,9 @@ a single call to `read(2)`):
|
|||||||
redisReply *reply;
|
redisReply *reply;
|
||||||
redisAppendCommand(context,"SET foo bar");
|
redisAppendCommand(context,"SET foo bar");
|
||||||
redisAppendCommand(context,"GET foo");
|
redisAppendCommand(context,"GET foo");
|
||||||
redisGetReply(context,(void *)&reply); // reply for SET
|
redisGetReply(context,(void**)&reply); // reply for SET
|
||||||
freeReplyObject(reply);
|
freeReplyObject(reply);
|
||||||
redisGetReply(context,(void *)&reply); // reply for GET
|
redisGetReply(context,(void**)&reply); // reply for GET
|
||||||
freeReplyObject(reply);
|
freeReplyObject(reply);
|
||||||
```
|
```
|
||||||
This API can also be used to implement a blocking subscriber:
|
This API can also be used to implement a blocking subscriber:
|
||||||
@ -517,7 +524,7 @@ initialize OpenSSL and create a context. You can do that in two ways:
|
|||||||
/* An Hiredis SSL context. It holds SSL configuration and can be reused across
|
/* An Hiredis SSL context. It holds SSL configuration and can be reused across
|
||||||
* many contexts.
|
* many contexts.
|
||||||
*/
|
*/
|
||||||
redisSSLContext *ssl;
|
redisSSLContext *ssl_context;
|
||||||
|
|
||||||
/* An error variable to indicate what went wrong, if the context fails to
|
/* An error variable to indicate what went wrong, if the context fails to
|
||||||
* initialize.
|
* initialize.
|
||||||
@ -532,17 +539,23 @@ redisSSLContextError ssl_error;
|
|||||||
redisInitOpenSSL();
|
redisInitOpenSSL();
|
||||||
|
|
||||||
/* Create SSL context */
|
/* Create SSL context */
|
||||||
ssl = redisCreateSSLContext(
|
ssl_context = redisCreateSSLContext(
|
||||||
"cacertbundle.crt", /* File name of trusted CA/ca bundle file, optional */
|
"cacertbundle.crt", /* File name of trusted CA/ca bundle file, optional */
|
||||||
"/path/to/certs", /* Path of trusted certificates, optional */
|
"/path/to/certs", /* Path of trusted certificates, optional */
|
||||||
"client_cert.pem", /* File name of client certificate file, optional */
|
"client_cert.pem", /* File name of client certificate file, optional */
|
||||||
"client_key.pem", /* File name of client private key, optional */
|
"client_key.pem", /* File name of client private key, optional */
|
||||||
"redis.mydomain.com", /* Server name to request (SNI), optional */
|
"redis.mydomain.com", /* Server name to request (SNI), optional */
|
||||||
&ssl_error
|
&ssl_error);
|
||||||
) != REDIS_OK) {
|
|
||||||
printf("SSL error: %s\n", redisSSLContextGetError(ssl_error);
|
if(ssl_context == NULL || ssl_error != 0) {
|
||||||
/* Abort... */
|
/* Handle error and abort... */
|
||||||
}
|
/* e.g.
|
||||||
|
printf("SSL error: %s\n",
|
||||||
|
(ssl_error != 0) ?
|
||||||
|
redisSSLContextGetError(ssl_error) : "Unknown error");
|
||||||
|
// Abort
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
/* Create Redis context and establish connection */
|
/* Create Redis context and establish connection */
|
||||||
c = redisConnect("localhost", 6443);
|
c = redisConnect("localhost", 6443);
|
||||||
@ -551,7 +564,7 @@ if (c == NULL || c->err) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Negotiate SSL/TLS */
|
/* Negotiate SSL/TLS */
|
||||||
if (redisInitiateSSLWithContext(c, ssl) != REDIS_OK) {
|
if (redisInitiateSSLWithContext(c, ssl_context) != REDIS_OK) {
|
||||||
/* Handle error, in c->err / c->errstr */
|
/* Handle error, in c->err / c->errstr */
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
27
deps/hiredis/adapters/libev.h
vendored
27
deps/hiredis/adapters/libev.h
vendored
@ -46,7 +46,7 @@ typedef struct redisLibevEvents {
|
|||||||
|
|
||||||
static void redisLibevReadEvent(EV_P_ ev_io *watcher, int revents) {
|
static void redisLibevReadEvent(EV_P_ ev_io *watcher, int revents) {
|
||||||
#if EV_MULTIPLICITY
|
#if EV_MULTIPLICITY
|
||||||
((void)loop);
|
((void)EV_A);
|
||||||
#endif
|
#endif
|
||||||
((void)revents);
|
((void)revents);
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ static void redisLibevReadEvent(EV_P_ ev_io *watcher, int revents) {
|
|||||||
|
|
||||||
static void redisLibevWriteEvent(EV_P_ ev_io *watcher, int revents) {
|
static void redisLibevWriteEvent(EV_P_ ev_io *watcher, int revents) {
|
||||||
#if EV_MULTIPLICITY
|
#if EV_MULTIPLICITY
|
||||||
((void)loop);
|
((void)EV_A);
|
||||||
#endif
|
#endif
|
||||||
((void)revents);
|
((void)revents);
|
||||||
|
|
||||||
@ -66,8 +66,9 @@ static void redisLibevWriteEvent(EV_P_ ev_io *watcher, int revents) {
|
|||||||
|
|
||||||
static void redisLibevAddRead(void *privdata) {
|
static void redisLibevAddRead(void *privdata) {
|
||||||
redisLibevEvents *e = (redisLibevEvents*)privdata;
|
redisLibevEvents *e = (redisLibevEvents*)privdata;
|
||||||
|
#if EV_MULTIPLICITY
|
||||||
struct ev_loop *loop = e->loop;
|
struct ev_loop *loop = e->loop;
|
||||||
((void)loop);
|
#endif
|
||||||
if (!e->reading) {
|
if (!e->reading) {
|
||||||
e->reading = 1;
|
e->reading = 1;
|
||||||
ev_io_start(EV_A_ &e->rev);
|
ev_io_start(EV_A_ &e->rev);
|
||||||
@ -76,8 +77,9 @@ static void redisLibevAddRead(void *privdata) {
|
|||||||
|
|
||||||
static void redisLibevDelRead(void *privdata) {
|
static void redisLibevDelRead(void *privdata) {
|
||||||
redisLibevEvents *e = (redisLibevEvents*)privdata;
|
redisLibevEvents *e = (redisLibevEvents*)privdata;
|
||||||
|
#if EV_MULTIPLICITY
|
||||||
struct ev_loop *loop = e->loop;
|
struct ev_loop *loop = e->loop;
|
||||||
((void)loop);
|
#endif
|
||||||
if (e->reading) {
|
if (e->reading) {
|
||||||
e->reading = 0;
|
e->reading = 0;
|
||||||
ev_io_stop(EV_A_ &e->rev);
|
ev_io_stop(EV_A_ &e->rev);
|
||||||
@ -86,8 +88,9 @@ static void redisLibevDelRead(void *privdata) {
|
|||||||
|
|
||||||
static void redisLibevAddWrite(void *privdata) {
|
static void redisLibevAddWrite(void *privdata) {
|
||||||
redisLibevEvents *e = (redisLibevEvents*)privdata;
|
redisLibevEvents *e = (redisLibevEvents*)privdata;
|
||||||
|
#if EV_MULTIPLICITY
|
||||||
struct ev_loop *loop = e->loop;
|
struct ev_loop *loop = e->loop;
|
||||||
((void)loop);
|
#endif
|
||||||
if (!e->writing) {
|
if (!e->writing) {
|
||||||
e->writing = 1;
|
e->writing = 1;
|
||||||
ev_io_start(EV_A_ &e->wev);
|
ev_io_start(EV_A_ &e->wev);
|
||||||
@ -96,8 +99,9 @@ static void redisLibevAddWrite(void *privdata) {
|
|||||||
|
|
||||||
static void redisLibevDelWrite(void *privdata) {
|
static void redisLibevDelWrite(void *privdata) {
|
||||||
redisLibevEvents *e = (redisLibevEvents*)privdata;
|
redisLibevEvents *e = (redisLibevEvents*)privdata;
|
||||||
|
#if EV_MULTIPLICITY
|
||||||
struct ev_loop *loop = e->loop;
|
struct ev_loop *loop = e->loop;
|
||||||
((void)loop);
|
#endif
|
||||||
if (e->writing) {
|
if (e->writing) {
|
||||||
e->writing = 0;
|
e->writing = 0;
|
||||||
ev_io_stop(EV_A_ &e->wev);
|
ev_io_stop(EV_A_ &e->wev);
|
||||||
@ -106,8 +110,9 @@ static void redisLibevDelWrite(void *privdata) {
|
|||||||
|
|
||||||
static void redisLibevStopTimer(void *privdata) {
|
static void redisLibevStopTimer(void *privdata) {
|
||||||
redisLibevEvents *e = (redisLibevEvents*)privdata;
|
redisLibevEvents *e = (redisLibevEvents*)privdata;
|
||||||
|
#if EV_MULTIPLICITY
|
||||||
struct ev_loop *loop = e->loop;
|
struct ev_loop *loop = e->loop;
|
||||||
((void)loop);
|
#endif
|
||||||
ev_timer_stop(EV_A_ &e->timer);
|
ev_timer_stop(EV_A_ &e->timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,6 +125,9 @@ static void redisLibevCleanup(void *privdata) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void redisLibevTimeout(EV_P_ ev_timer *timer, int revents) {
|
static void redisLibevTimeout(EV_P_ ev_timer *timer, int revents) {
|
||||||
|
#if EV_MULTIPLICITY
|
||||||
|
((void)EV_A);
|
||||||
|
#endif
|
||||||
((void)revents);
|
((void)revents);
|
||||||
redisLibevEvents *e = (redisLibevEvents*)timer->data;
|
redisLibevEvents *e = (redisLibevEvents*)timer->data;
|
||||||
redisAsyncHandleTimeout(e->context);
|
redisAsyncHandleTimeout(e->context);
|
||||||
@ -127,8 +135,9 @@ static void redisLibevTimeout(EV_P_ ev_timer *timer, int revents) {
|
|||||||
|
|
||||||
static void redisLibevSetTimeout(void *privdata, struct timeval tv) {
|
static void redisLibevSetTimeout(void *privdata, struct timeval tv) {
|
||||||
redisLibevEvents *e = (redisLibevEvents*)privdata;
|
redisLibevEvents *e = (redisLibevEvents*)privdata;
|
||||||
|
#if EV_MULTIPLICITY
|
||||||
struct ev_loop *loop = e->loop;
|
struct ev_loop *loop = e->loop;
|
||||||
((void)loop);
|
#endif
|
||||||
|
|
||||||
if (!ev_is_active(&e->timer)) {
|
if (!ev_is_active(&e->timer)) {
|
||||||
ev_init(&e->timer, redisLibevTimeout);
|
ev_init(&e->timer, redisLibevTimeout);
|
||||||
@ -154,7 +163,7 @@ static int redisLibevAttach(EV_P_ redisAsyncContext *ac) {
|
|||||||
|
|
||||||
e->context = ac;
|
e->context = ac;
|
||||||
#if EV_MULTIPLICITY
|
#if EV_MULTIPLICITY
|
||||||
e->loop = loop;
|
e->loop = EV_A;
|
||||||
#else
|
#else
|
||||||
e->loop = NULL;
|
e->loop = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
2
deps/hiredis/adapters/libevent.h
vendored
2
deps/hiredis/adapters/libevent.h
vendored
@ -50,7 +50,7 @@ static void redisLibeventDestroy(redisLibeventEvents *e) {
|
|||||||
hi_free(e);
|
hi_free(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void redisLibeventHandler(int fd, short event, void *arg) {
|
static void redisLibeventHandler(evutil_socket_t fd, short event, void *arg) {
|
||||||
((void)fd);
|
((void)fd);
|
||||||
redisLibeventEvents *e = (redisLibeventEvents*)arg;
|
redisLibeventEvents *e = (redisLibeventEvents*)arg;
|
||||||
e->state |= REDIS_LIBEVENT_ENTERED;
|
e->state |= REDIS_LIBEVENT_ENTERED;
|
||||||
|
164
deps/hiredis/adapters/libuv.h
vendored
164
deps/hiredis/adapters/libuv.h
vendored
@ -7,111 +7,157 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
typedef struct redisLibuvEvents {
|
typedef struct redisLibuvEvents {
|
||||||
redisAsyncContext* context;
|
redisAsyncContext* context;
|
||||||
uv_poll_t handle;
|
uv_poll_t handle;
|
||||||
int events;
|
uv_timer_t timer;
|
||||||
|
int events;
|
||||||
} redisLibuvEvents;
|
} redisLibuvEvents;
|
||||||
|
|
||||||
|
|
||||||
static void redisLibuvPoll(uv_poll_t* handle, int status, int events) {
|
static void redisLibuvPoll(uv_poll_t* handle, int status, int events) {
|
||||||
redisLibuvEvents* p = (redisLibuvEvents*)handle->data;
|
redisLibuvEvents* p = (redisLibuvEvents*)handle->data;
|
||||||
int ev = (status ? p->events : events);
|
int ev = (status ? p->events : events);
|
||||||
|
|
||||||
if (p->context != NULL && (ev & UV_READABLE)) {
|
if (p->context != NULL && (ev & UV_READABLE)) {
|
||||||
redisAsyncHandleRead(p->context);
|
redisAsyncHandleRead(p->context);
|
||||||
}
|
}
|
||||||
if (p->context != NULL && (ev & UV_WRITABLE)) {
|
if (p->context != NULL && (ev & UV_WRITABLE)) {
|
||||||
redisAsyncHandleWrite(p->context);
|
redisAsyncHandleWrite(p->context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void redisLibuvAddRead(void *privdata) {
|
static void redisLibuvAddRead(void *privdata) {
|
||||||
redisLibuvEvents* p = (redisLibuvEvents*)privdata;
|
redisLibuvEvents* p = (redisLibuvEvents*)privdata;
|
||||||
|
|
||||||
p->events |= UV_READABLE;
|
p->events |= UV_READABLE;
|
||||||
|
|
||||||
uv_poll_start(&p->handle, p->events, redisLibuvPoll);
|
uv_poll_start(&p->handle, p->events, redisLibuvPoll);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void redisLibuvDelRead(void *privdata) {
|
static void redisLibuvDelRead(void *privdata) {
|
||||||
redisLibuvEvents* p = (redisLibuvEvents*)privdata;
|
redisLibuvEvents* p = (redisLibuvEvents*)privdata;
|
||||||
|
|
||||||
p->events &= ~UV_READABLE;
|
p->events &= ~UV_READABLE;
|
||||||
|
|
||||||
if (p->events) {
|
if (p->events) {
|
||||||
uv_poll_start(&p->handle, p->events, redisLibuvPoll);
|
uv_poll_start(&p->handle, p->events, redisLibuvPoll);
|
||||||
} else {
|
} else {
|
||||||
uv_poll_stop(&p->handle);
|
uv_poll_stop(&p->handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void redisLibuvAddWrite(void *privdata) {
|
static void redisLibuvAddWrite(void *privdata) {
|
||||||
redisLibuvEvents* p = (redisLibuvEvents*)privdata;
|
redisLibuvEvents* p = (redisLibuvEvents*)privdata;
|
||||||
|
|
||||||
p->events |= UV_WRITABLE;
|
p->events |= UV_WRITABLE;
|
||||||
|
|
||||||
uv_poll_start(&p->handle, p->events, redisLibuvPoll);
|
uv_poll_start(&p->handle, p->events, redisLibuvPoll);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void redisLibuvDelWrite(void *privdata) {
|
static void redisLibuvDelWrite(void *privdata) {
|
||||||
redisLibuvEvents* p = (redisLibuvEvents*)privdata;
|
redisLibuvEvents* p = (redisLibuvEvents*)privdata;
|
||||||
|
|
||||||
p->events &= ~UV_WRITABLE;
|
p->events &= ~UV_WRITABLE;
|
||||||
|
|
||||||
if (p->events) {
|
if (p->events) {
|
||||||
uv_poll_start(&p->handle, p->events, redisLibuvPoll);
|
uv_poll_start(&p->handle, p->events, redisLibuvPoll);
|
||||||
} else {
|
} else {
|
||||||
uv_poll_stop(&p->handle);
|
uv_poll_stop(&p->handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void on_timer_close(uv_handle_t *handle) {
|
||||||
static void on_close(uv_handle_t* handle) {
|
redisLibuvEvents* p = (redisLibuvEvents*)handle->data;
|
||||||
redisLibuvEvents* p = (redisLibuvEvents*)handle->data;
|
p->timer.data = NULL;
|
||||||
|
if (!p->handle.data) {
|
||||||
hi_free(p);
|
// both timer and handle are closed
|
||||||
|
hi_free(p);
|
||||||
|
}
|
||||||
|
// else, wait for `on_handle_close`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void on_handle_close(uv_handle_t *handle) {
|
||||||
|
redisLibuvEvents* p = (redisLibuvEvents*)handle->data;
|
||||||
|
p->handle.data = NULL;
|
||||||
|
if (!p->timer.data) {
|
||||||
|
// timer never started, or timer already destroyed
|
||||||
|
hi_free(p);
|
||||||
|
}
|
||||||
|
// else, wait for `on_timer_close`
|
||||||
|
}
|
||||||
|
|
||||||
|
// libuv removed `status` parameter since v0.11.23
|
||||||
|
// see: https://github.com/libuv/libuv/blob/v0.11.23/include/uv.h
|
||||||
|
#if (UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR < 11) || \
|
||||||
|
(UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR == 11 && UV_VERSION_PATCH < 23)
|
||||||
|
static void redisLibuvTimeout(uv_timer_t *timer, int status) {
|
||||||
|
(void)status; // unused
|
||||||
|
#else
|
||||||
|
static void redisLibuvTimeout(uv_timer_t *timer) {
|
||||||
|
#endif
|
||||||
|
redisLibuvEvents *e = (redisLibuvEvents*)timer->data;
|
||||||
|
redisAsyncHandleTimeout(e->context);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void redisLibuvSetTimeout(void *privdata, struct timeval tv) {
|
||||||
|
redisLibuvEvents* p = (redisLibuvEvents*)privdata;
|
||||||
|
|
||||||
|
uint64_t millsec = tv.tv_sec * 1000 + tv.tv_usec / 1000.0;
|
||||||
|
if (!p->timer.data) {
|
||||||
|
// timer is uninitialized
|
||||||
|
if (uv_timer_init(p->handle.loop, &p->timer) != 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
p->timer.data = p;
|
||||||
|
}
|
||||||
|
// updates the timeout if the timer has already started
|
||||||
|
// or start the timer
|
||||||
|
uv_timer_start(&p->timer, redisLibuvTimeout, millsec, 0);
|
||||||
|
}
|
||||||
|
|
||||||
static void redisLibuvCleanup(void *privdata) {
|
static void redisLibuvCleanup(void *privdata) {
|
||||||
redisLibuvEvents* p = (redisLibuvEvents*)privdata;
|
redisLibuvEvents* p = (redisLibuvEvents*)privdata;
|
||||||
|
|
||||||
p->context = NULL; // indicate that context might no longer exist
|
p->context = NULL; // indicate that context might no longer exist
|
||||||
uv_close((uv_handle_t*)&p->handle, on_close);
|
if (p->timer.data) {
|
||||||
|
uv_close((uv_handle_t*)&p->timer, on_timer_close);
|
||||||
|
}
|
||||||
|
uv_close((uv_handle_t*)&p->handle, on_handle_close);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int redisLibuvAttach(redisAsyncContext* ac, uv_loop_t* loop) {
|
static int redisLibuvAttach(redisAsyncContext* ac, uv_loop_t* loop) {
|
||||||
redisContext *c = &(ac->c);
|
redisContext *c = &(ac->c);
|
||||||
|
|
||||||
if (ac->ev.data != NULL) {
|
if (ac->ev.data != NULL) {
|
||||||
return REDIS_ERR;
|
return REDIS_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
ac->ev.addRead = redisLibuvAddRead;
|
ac->ev.addRead = redisLibuvAddRead;
|
||||||
ac->ev.delRead = redisLibuvDelRead;
|
ac->ev.delRead = redisLibuvDelRead;
|
||||||
ac->ev.addWrite = redisLibuvAddWrite;
|
ac->ev.addWrite = redisLibuvAddWrite;
|
||||||
ac->ev.delWrite = redisLibuvDelWrite;
|
ac->ev.delWrite = redisLibuvDelWrite;
|
||||||
ac->ev.cleanup = redisLibuvCleanup;
|
ac->ev.cleanup = redisLibuvCleanup;
|
||||||
|
ac->ev.scheduleTimer = redisLibuvSetTimeout;
|
||||||
|
|
||||||
redisLibuvEvents* p = (redisLibuvEvents*)hi_malloc(sizeof(*p));
|
redisLibuvEvents* p = (redisLibuvEvents*)hi_malloc(sizeof(*p));
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
return REDIS_ERR;
|
return REDIS_ERR;
|
||||||
|
|
||||||
memset(p, 0, sizeof(*p));
|
memset(p, 0, sizeof(*p));
|
||||||
|
|
||||||
if (uv_poll_init_socket(loop, &p->handle, c->fd) != 0) {
|
if (uv_poll_init_socket(loop, &p->handle, c->fd) != 0) {
|
||||||
return REDIS_ERR;
|
return REDIS_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
ac->ev.data = p;
|
ac->ev.data = p;
|
||||||
p->handle.data = p;
|
p->handle.data = p;
|
||||||
p->context = ac;
|
p->context = ac;
|
||||||
|
|
||||||
return REDIS_OK;
|
return REDIS_OK;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
128
deps/hiredis/async.c
vendored
128
deps/hiredis/async.c
vendored
@ -47,6 +47,11 @@
|
|||||||
|
|
||||||
#include "async_private.h"
|
#include "async_private.h"
|
||||||
|
|
||||||
|
#ifdef NDEBUG
|
||||||
|
#undef assert
|
||||||
|
#define assert(e) (void)(e)
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Forward declarations of hiredis.c functions */
|
/* Forward declarations of hiredis.c functions */
|
||||||
int __redisAppendCommand(redisContext *c, const char *cmd, size_t len);
|
int __redisAppendCommand(redisContext *c, const char *cmd, size_t len);
|
||||||
void __redisSetError(redisContext *c, int type, const char *str);
|
void __redisSetError(redisContext *c, int type, const char *str);
|
||||||
@ -139,8 +144,8 @@ static redisAsyncContext *redisAsyncInitialize(redisContext *c) {
|
|||||||
|
|
||||||
ac->replies.head = NULL;
|
ac->replies.head = NULL;
|
||||||
ac->replies.tail = NULL;
|
ac->replies.tail = NULL;
|
||||||
ac->sub.invalid.head = NULL;
|
ac->sub.replies.head = NULL;
|
||||||
ac->sub.invalid.tail = NULL;
|
ac->sub.replies.tail = NULL;
|
||||||
ac->sub.channels = channels;
|
ac->sub.channels = channels;
|
||||||
ac->sub.patterns = patterns;
|
ac->sub.patterns = patterns;
|
||||||
|
|
||||||
@ -301,36 +306,28 @@ static void __redisRunPushCallback(redisAsyncContext *ac, redisReply *reply) {
|
|||||||
static void __redisAsyncFree(redisAsyncContext *ac) {
|
static void __redisAsyncFree(redisAsyncContext *ac) {
|
||||||
redisContext *c = &(ac->c);
|
redisContext *c = &(ac->c);
|
||||||
redisCallback cb;
|
redisCallback cb;
|
||||||
dictIterator *it;
|
dictIterator it;
|
||||||
dictEntry *de;
|
dictEntry *de;
|
||||||
|
|
||||||
/* Execute pending callbacks with NULL reply. */
|
/* Execute pending callbacks with NULL reply. */
|
||||||
while (__redisShiftCallback(&ac->replies,&cb) == REDIS_OK)
|
while (__redisShiftCallback(&ac->replies,&cb) == REDIS_OK)
|
||||||
__redisRunCallback(ac,&cb,NULL);
|
__redisRunCallback(ac,&cb,NULL);
|
||||||
|
while (__redisShiftCallback(&ac->sub.replies,&cb) == REDIS_OK)
|
||||||
/* Execute callbacks for invalid commands */
|
|
||||||
while (__redisShiftCallback(&ac->sub.invalid,&cb) == REDIS_OK)
|
|
||||||
__redisRunCallback(ac,&cb,NULL);
|
__redisRunCallback(ac,&cb,NULL);
|
||||||
|
|
||||||
/* Run subscription callbacks with NULL reply */
|
/* Run subscription callbacks with NULL reply */
|
||||||
if (ac->sub.channels) {
|
if (ac->sub.channels) {
|
||||||
it = dictGetIterator(ac->sub.channels);
|
dictInitIterator(&it,ac->sub.channels);
|
||||||
if (it != NULL) {
|
while ((de = dictNext(&it)) != NULL)
|
||||||
while ((de = dictNext(it)) != NULL)
|
__redisRunCallback(ac,dictGetEntryVal(de),NULL);
|
||||||
__redisRunCallback(ac,dictGetEntryVal(de),NULL);
|
|
||||||
dictReleaseIterator(it);
|
|
||||||
}
|
|
||||||
|
|
||||||
dictRelease(ac->sub.channels);
|
dictRelease(ac->sub.channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ac->sub.patterns) {
|
if (ac->sub.patterns) {
|
||||||
it = dictGetIterator(ac->sub.patterns);
|
dictInitIterator(&it,ac->sub.patterns);
|
||||||
if (it != NULL) {
|
while ((de = dictNext(&it)) != NULL)
|
||||||
while ((de = dictNext(it)) != NULL)
|
__redisRunCallback(ac,dictGetEntryVal(de),NULL);
|
||||||
__redisRunCallback(ac,dictGetEntryVal(de),NULL);
|
|
||||||
dictReleaseIterator(it);
|
|
||||||
}
|
|
||||||
|
|
||||||
dictRelease(ac->sub.patterns);
|
dictRelease(ac->sub.patterns);
|
||||||
}
|
}
|
||||||
@ -420,10 +417,11 @@ static int __redisGetSubscribeCallback(redisAsyncContext *ac, redisReply *reply,
|
|||||||
char *stype;
|
char *stype;
|
||||||
hisds sname;
|
hisds sname;
|
||||||
|
|
||||||
/* Custom reply functions are not supported for pub/sub. This will fail
|
/* Match reply with the expected format of a pushed message.
|
||||||
* very hard when they are used... */
|
* The type and number of elements (3 to 4) are specified at:
|
||||||
if (reply->type == REDIS_REPLY_ARRAY || reply->type == REDIS_REPLY_PUSH) {
|
* https://redis.io/topics/pubsub#format-of-pushed-messages */
|
||||||
assert(reply->elements >= 2);
|
if ((reply->type == REDIS_REPLY_ARRAY && !(c->flags & REDIS_SUPPORTS_PUSH) && reply->elements >= 3) ||
|
||||||
|
reply->type == REDIS_REPLY_PUSH) {
|
||||||
assert(reply->element[0]->type == REDIS_REPLY_STRING);
|
assert(reply->element[0]->type == REDIS_REPLY_STRING);
|
||||||
stype = reply->element[0]->str;
|
stype = reply->element[0]->str;
|
||||||
pvariant = (tolower(stype[0]) == 'p') ? 1 : 0;
|
pvariant = (tolower(stype[0]) == 'p') ? 1 : 0;
|
||||||
@ -462,14 +460,21 @@ static int __redisGetSubscribeCallback(redisAsyncContext *ac, redisReply *reply,
|
|||||||
/* Unset subscribed flag only when no pipelined pending subscribe. */
|
/* Unset subscribed flag only when no pipelined pending subscribe. */
|
||||||
if (reply->element[2]->integer == 0
|
if (reply->element[2]->integer == 0
|
||||||
&& dictSize(ac->sub.channels) == 0
|
&& dictSize(ac->sub.channels) == 0
|
||||||
&& dictSize(ac->sub.patterns) == 0)
|
&& dictSize(ac->sub.patterns) == 0) {
|
||||||
c->flags &= ~REDIS_SUBSCRIBED;
|
c->flags &= ~REDIS_SUBSCRIBED;
|
||||||
|
|
||||||
|
/* Move ongoing regular command callbacks. */
|
||||||
|
redisCallback cb;
|
||||||
|
while (__redisShiftCallback(&ac->sub.replies,&cb) == REDIS_OK) {
|
||||||
|
__redisPushCallback(&ac->replies,&cb);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hi_sdsfree(sname);
|
hi_sdsfree(sname);
|
||||||
} else {
|
} else {
|
||||||
/* Shift callback for invalid commands. */
|
/* Shift callback for pending command in subscribed context. */
|
||||||
__redisShiftCallback(&ac->sub.invalid,dstcb);
|
__redisShiftCallback(&ac->sub.replies,dstcb);
|
||||||
}
|
}
|
||||||
return REDIS_OK;
|
return REDIS_OK;
|
||||||
oom:
|
oom:
|
||||||
@ -497,13 +502,12 @@ static int redisIsSubscribeReply(redisReply *reply) {
|
|||||||
len = reply->element[0]->len - off;
|
len = reply->element[0]->len - off;
|
||||||
|
|
||||||
return !strncasecmp(str, "subscribe", len) ||
|
return !strncasecmp(str, "subscribe", len) ||
|
||||||
!strncasecmp(str, "message", len);
|
!strncasecmp(str, "message", len) ||
|
||||||
|
!strncasecmp(str, "unsubscribe", len);
|
||||||
}
|
}
|
||||||
|
|
||||||
void redisProcessCallbacks(redisAsyncContext *ac) {
|
void redisProcessCallbacks(redisAsyncContext *ac) {
|
||||||
redisContext *c = &(ac->c);
|
redisContext *c = &(ac->c);
|
||||||
redisCallback cb = {NULL, NULL, 0, NULL};
|
|
||||||
void *reply = NULL;
|
void *reply = NULL;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
@ -516,17 +520,14 @@ void redisProcessCallbacks(redisAsyncContext *ac) {
|
|||||||
__redisAsyncDisconnect(ac);
|
__redisAsyncDisconnect(ac);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If monitor mode, repush callback */
|
|
||||||
if(c->flags & REDIS_MONITORING) {
|
|
||||||
__redisPushCallback(&ac->replies,&cb);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* When the connection is not being disconnected, simply stop
|
/* When the connection is not being disconnected, simply stop
|
||||||
* trying to get replies and wait for the next loop tick. */
|
* trying to get replies and wait for the next loop tick. */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Keep track of push message support for subscribe handling */
|
||||||
|
if (redisIsPushReply(reply)) c->flags |= REDIS_SUPPORTS_PUSH;
|
||||||
|
|
||||||
/* Send any non-subscribe related PUSH messages to our PUSH handler
|
/* Send any non-subscribe related PUSH messages to our PUSH handler
|
||||||
* while allowing subscribe related PUSH messages to pass through.
|
* while allowing subscribe related PUSH messages to pass through.
|
||||||
* This allows existing code to be backward compatible and work in
|
* This allows existing code to be backward compatible and work in
|
||||||
@ -539,6 +540,7 @@ void redisProcessCallbacks(redisAsyncContext *ac) {
|
|||||||
|
|
||||||
/* Even if the context is subscribed, pending regular
|
/* Even if the context is subscribed, pending regular
|
||||||
* callbacks will get a reply before pub/sub messages arrive. */
|
* callbacks will get a reply before pub/sub messages arrive. */
|
||||||
|
redisCallback cb = {NULL, NULL, 0, NULL};
|
||||||
if (__redisShiftCallback(&ac->replies,&cb) != REDIS_OK) {
|
if (__redisShiftCallback(&ac->replies,&cb) != REDIS_OK) {
|
||||||
/*
|
/*
|
||||||
* A spontaneous reply in a not-subscribed context can be the error
|
* A spontaneous reply in a not-subscribed context can be the error
|
||||||
@ -562,15 +564,17 @@ void redisProcessCallbacks(redisAsyncContext *ac) {
|
|||||||
__redisAsyncDisconnect(ac);
|
__redisAsyncDisconnect(ac);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* No more regular callbacks and no errors, the context *must* be subscribed or monitoring. */
|
/* No more regular callbacks and no errors, the context *must* be subscribed. */
|
||||||
assert((c->flags & REDIS_SUBSCRIBED || c->flags & REDIS_MONITORING));
|
assert(c->flags & REDIS_SUBSCRIBED);
|
||||||
if(c->flags & REDIS_SUBSCRIBED)
|
if (c->flags & REDIS_SUBSCRIBED)
|
||||||
__redisGetSubscribeCallback(ac,reply,&cb);
|
__redisGetSubscribeCallback(ac,reply,&cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cb.fn != NULL) {
|
if (cb.fn != NULL) {
|
||||||
__redisRunCallback(ac,&cb,reply);
|
__redisRunCallback(ac,&cb,reply);
|
||||||
c->reader->fn->freeObject(reply);
|
if (!(c->flags & REDIS_NO_AUTO_FREE_REPLIES)){
|
||||||
|
c->reader->fn->freeObject(reply);
|
||||||
|
}
|
||||||
|
|
||||||
/* Proceed with free'ing when redisAsyncFree() was called. */
|
/* Proceed with free'ing when redisAsyncFree() was called. */
|
||||||
if (c->flags & REDIS_FREEING) {
|
if (c->flags & REDIS_FREEING) {
|
||||||
@ -584,6 +588,11 @@ void redisProcessCallbacks(redisAsyncContext *ac) {
|
|||||||
* doesn't know what the server will spit out over the wire. */
|
* doesn't know what the server will spit out over the wire. */
|
||||||
c->reader->fn->freeObject(reply);
|
c->reader->fn->freeObject(reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If in monitor mode, repush the callback */
|
||||||
|
if (c->flags & REDIS_MONITORING) {
|
||||||
|
__redisPushCallback(&ac->replies,&cb);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Disconnect when there was an error reading the reply */
|
/* Disconnect when there was an error reading the reply */
|
||||||
@ -605,7 +614,8 @@ static int __redisAsyncHandleConnect(redisAsyncContext *ac) {
|
|||||||
|
|
||||||
if (redisCheckConnectDone(c, &completed) == REDIS_ERR) {
|
if (redisCheckConnectDone(c, &completed) == REDIS_ERR) {
|
||||||
/* Error! */
|
/* Error! */
|
||||||
redisCheckSocketError(c);
|
if (redisCheckSocketError(c) == REDIS_ERR)
|
||||||
|
__redisAsyncCopyError(ac);
|
||||||
__redisAsyncHandleConnectFailure(ac);
|
__redisAsyncHandleConnectFailure(ac);
|
||||||
return REDIS_ERR;
|
return REDIS_ERR;
|
||||||
} else if (completed == 1) {
|
} else if (completed == 1) {
|
||||||
@ -691,13 +701,22 @@ void redisAsyncHandleTimeout(redisAsyncContext *ac) {
|
|||||||
redisContext *c = &(ac->c);
|
redisContext *c = &(ac->c);
|
||||||
redisCallback cb;
|
redisCallback cb;
|
||||||
|
|
||||||
if ((c->flags & REDIS_CONNECTED) && ac->replies.head == NULL) {
|
if ((c->flags & REDIS_CONNECTED)) {
|
||||||
/* Nothing to do - just an idle timeout */
|
if (ac->replies.head == NULL && ac->sub.replies.head == NULL) {
|
||||||
return;
|
/* Nothing to do - just an idle timeout */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ac->c.command_timeout ||
|
||||||
|
(!ac->c.command_timeout->tv_sec && !ac->c.command_timeout->tv_usec)) {
|
||||||
|
/* A belated connect timeout arriving, ignore */
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!c->err) {
|
if (!c->err) {
|
||||||
__redisSetError(c, REDIS_ERR_TIMEOUT, "Timeout");
|
__redisSetError(c, REDIS_ERR_TIMEOUT, "Timeout");
|
||||||
|
__redisAsyncCopyError(ac);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(c->flags & REDIS_CONNECTED) && ac->onConnect) {
|
if (!(c->flags & REDIS_CONNECTED) && ac->onConnect) {
|
||||||
@ -796,17 +815,19 @@ static int __redisAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void
|
|||||||
/* (P)UNSUBSCRIBE does not have its own response: every channel or
|
/* (P)UNSUBSCRIBE does not have its own response: every channel or
|
||||||
* pattern that is unsubscribed will receive a message. This means we
|
* pattern that is unsubscribed will receive a message. This means we
|
||||||
* should not append a callback function for this command. */
|
* should not append a callback function for this command. */
|
||||||
} else if(strncasecmp(cstr,"monitor\r\n",9) == 0) {
|
} else if (strncasecmp(cstr,"monitor\r\n",9) == 0) {
|
||||||
/* Set monitor flag and push callback */
|
/* Set monitor flag and push callback */
|
||||||
c->flags |= REDIS_MONITORING;
|
c->flags |= REDIS_MONITORING;
|
||||||
__redisPushCallback(&ac->replies,&cb);
|
if (__redisPushCallback(&ac->replies,&cb) != REDIS_OK)
|
||||||
|
goto oom;
|
||||||
} else {
|
} else {
|
||||||
if (c->flags & REDIS_SUBSCRIBED)
|
if (c->flags & REDIS_SUBSCRIBED) {
|
||||||
/* This will likely result in an error reply, but it needs to be
|
if (__redisPushCallback(&ac->sub.replies,&cb) != REDIS_OK)
|
||||||
* received and passed to the callback. */
|
goto oom;
|
||||||
__redisPushCallback(&ac->sub.invalid,&cb);
|
} else {
|
||||||
else
|
if (__redisPushCallback(&ac->replies,&cb) != REDIS_OK)
|
||||||
__redisPushCallback(&ac->replies,&cb);
|
goto oom;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__redisAppendCommand(c,cmd,len);
|
__redisAppendCommand(c,cmd,len);
|
||||||
@ -817,6 +838,7 @@ static int __redisAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void
|
|||||||
return REDIS_OK;
|
return REDIS_OK;
|
||||||
oom:
|
oom:
|
||||||
__redisSetError(&(ac->c), REDIS_ERR_OOM, "Out of memory");
|
__redisSetError(&(ac->c), REDIS_ERR_OOM, "Out of memory");
|
||||||
|
__redisAsyncCopyError(ac);
|
||||||
return REDIS_ERR;
|
return REDIS_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -846,7 +868,7 @@ int redisAsyncCommand(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata
|
|||||||
|
|
||||||
int redisAsyncCommandArgv(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, int argc, const char **argv, const size_t *argvlen) {
|
int redisAsyncCommandArgv(redisAsyncContext *ac, redisCallbackFn *fn, void *privdata, int argc, const char **argv, const size_t *argvlen) {
|
||||||
hisds cmd;
|
hisds cmd;
|
||||||
int len;
|
long long len;
|
||||||
int status;
|
int status;
|
||||||
len = redisFormatSdsCommandArgv(&cmd,argc,argv,argvlen);
|
len = redisFormatSdsCommandArgv(&cmd,argc,argv,argvlen);
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
|
2
deps/hiredis/async.h
vendored
2
deps/hiredis/async.h
vendored
@ -102,7 +102,7 @@ typedef struct redisAsyncContext {
|
|||||||
|
|
||||||
/* Subscription callbacks */
|
/* Subscription callbacks */
|
||||||
struct {
|
struct {
|
||||||
redisCallbackList invalid;
|
redisCallbackList replies;
|
||||||
struct dict *channels;
|
struct dict *channels;
|
||||||
struct dict *patterns;
|
struct dict *patterns;
|
||||||
} sub;
|
} sub;
|
||||||
|
11
deps/hiredis/dict.c
vendored
11
deps/hiredis/dict.c
vendored
@ -267,16 +267,11 @@ static dictEntry *dictFind(dict *ht, const void *key) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static dictIterator *dictGetIterator(dict *ht) {
|
static void dictInitIterator(dictIterator *iter, dict *ht) {
|
||||||
dictIterator *iter = hi_malloc(sizeof(*iter));
|
|
||||||
if (iter == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
iter->ht = ht;
|
iter->ht = ht;
|
||||||
iter->index = -1;
|
iter->index = -1;
|
||||||
iter->entry = NULL;
|
iter->entry = NULL;
|
||||||
iter->nextEntry = NULL;
|
iter->nextEntry = NULL;
|
||||||
return iter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static dictEntry *dictNext(dictIterator *iter) {
|
static dictEntry *dictNext(dictIterator *iter) {
|
||||||
@ -299,10 +294,6 @@ static dictEntry *dictNext(dictIterator *iter) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dictReleaseIterator(dictIterator *iter) {
|
|
||||||
hi_free(iter);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ------------------------- private functions ------------------------------ */
|
/* ------------------------- private functions ------------------------------ */
|
||||||
|
|
||||||
/* Expand the hash table if needed */
|
/* Expand the hash table if needed */
|
||||||
|
3
deps/hiredis/dict.h
vendored
3
deps/hiredis/dict.h
vendored
@ -119,8 +119,7 @@ static int dictReplace(dict *ht, void *key, void *val);
|
|||||||
static int dictDelete(dict *ht, const void *key);
|
static int dictDelete(dict *ht, const void *key);
|
||||||
static void dictRelease(dict *ht);
|
static void dictRelease(dict *ht);
|
||||||
static dictEntry * dictFind(dict *ht, const void *key);
|
static dictEntry * dictFind(dict *ht, const void *key);
|
||||||
static dictIterator *dictGetIterator(dict *ht);
|
static void dictInitIterator(dictIterator *iter, dict *ht);
|
||||||
static dictEntry *dictNext(dictIterator *iter);
|
static dictEntry *dictNext(dictIterator *iter);
|
||||||
static void dictReleaseIterator(dictIterator *iter);
|
|
||||||
|
|
||||||
#endif /* __DICT_H */
|
#endif /* __DICT_H */
|
||||||
|
2
deps/hiredis/examples/CMakeLists.txt
vendored
2
deps/hiredis/examples/CMakeLists.txt
vendored
@ -21,7 +21,7 @@ ENDIF()
|
|||||||
|
|
||||||
FIND_PATH(LIBEVENT event.h)
|
FIND_PATH(LIBEVENT event.h)
|
||||||
if (LIBEVENT)
|
if (LIBEVENT)
|
||||||
ADD_EXECUTABLE(example-libevent example-libevent)
|
ADD_EXECUTABLE(example-libevent example-libevent.c)
|
||||||
TARGET_LINK_LIBRARIES(example-libevent hiredis event)
|
TARGET_LINK_LIBRARIES(example-libevent hiredis event)
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
|
37
deps/hiredis/examples/example-libuv.c
vendored
37
deps/hiredis/examples/example-libuv.c
vendored
@ -7,18 +7,33 @@
|
|||||||
#include <async.h>
|
#include <async.h>
|
||||||
#include <adapters/libuv.h>
|
#include <adapters/libuv.h>
|
||||||
|
|
||||||
|
void debugCallback(redisAsyncContext *c, void *r, void *privdata) {
|
||||||
|
(void)privdata; //unused
|
||||||
|
redisReply *reply = r;
|
||||||
|
if (reply == NULL) {
|
||||||
|
/* The DEBUG SLEEP command will almost always fail, because we have set a 1 second timeout */
|
||||||
|
printf("`DEBUG SLEEP` error: %s\n", c->errstr ? c->errstr : "unknown error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/* Disconnect after receiving the reply of DEBUG SLEEP (which will not)*/
|
||||||
|
redisAsyncDisconnect(c);
|
||||||
|
}
|
||||||
|
|
||||||
void getCallback(redisAsyncContext *c, void *r, void *privdata) {
|
void getCallback(redisAsyncContext *c, void *r, void *privdata) {
|
||||||
redisReply *reply = r;
|
redisReply *reply = r;
|
||||||
if (reply == NULL) return;
|
if (reply == NULL) {
|
||||||
printf("argv[%s]: %s\n", (char*)privdata, reply->str);
|
printf("`GET key` error: %s\n", c->errstr ? c->errstr : "unknown error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
printf("`GET key` result: argv[%s]: %s\n", (char*)privdata, reply->str);
|
||||||
|
|
||||||
/* Disconnect after receiving the reply to GET */
|
/* start another request that demonstrate timeout */
|
||||||
redisAsyncDisconnect(c);
|
redisAsyncCommand(c, debugCallback, NULL, "DEBUG SLEEP %f", 1.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
void connectCallback(const redisAsyncContext *c, int status) {
|
void connectCallback(const redisAsyncContext *c, int status) {
|
||||||
if (status != REDIS_OK) {
|
if (status != REDIS_OK) {
|
||||||
printf("Error: %s\n", c->errstr);
|
printf("connect error: %s\n", c->errstr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
printf("Connected...\n");
|
printf("Connected...\n");
|
||||||
@ -26,7 +41,7 @@ void connectCallback(const redisAsyncContext *c, int status) {
|
|||||||
|
|
||||||
void disconnectCallback(const redisAsyncContext *c, int status) {
|
void disconnectCallback(const redisAsyncContext *c, int status) {
|
||||||
if (status != REDIS_OK) {
|
if (status != REDIS_OK) {
|
||||||
printf("Error: %s\n", c->errstr);
|
printf("disconnect because of error: %s\n", c->errstr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
printf("Disconnected...\n");
|
printf("Disconnected...\n");
|
||||||
@ -49,8 +64,18 @@ int main (int argc, char **argv) {
|
|||||||
redisLibuvAttach(c,loop);
|
redisLibuvAttach(c,loop);
|
||||||
redisAsyncSetConnectCallback(c,connectCallback);
|
redisAsyncSetConnectCallback(c,connectCallback);
|
||||||
redisAsyncSetDisconnectCallback(c,disconnectCallback);
|
redisAsyncSetDisconnectCallback(c,disconnectCallback);
|
||||||
|
redisAsyncSetTimeout(c, (struct timeval){ .tv_sec = 1, .tv_usec = 0});
|
||||||
|
|
||||||
|
/*
|
||||||
|
In this demo, we first `set key`, then `get key` to demonstrate the basic usage of libuv adapter.
|
||||||
|
Then in `getCallback`, we start a `debug sleep` command to create 1.5 second long request.
|
||||||
|
Because we have set a 1 second timeout to the connection, the command will always fail with a
|
||||||
|
timeout error, which is shown in the `debugCallback`.
|
||||||
|
*/
|
||||||
|
|
||||||
redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1]));
|
redisAsyncCommand(c, NULL, NULL, "SET key %b", argv[argc-1], strlen(argv[argc-1]));
|
||||||
redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key");
|
redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key");
|
||||||
|
|
||||||
uv_run(loop, UV_RUN_DEFAULT);
|
uv_run(loop, UV_RUN_DEFAULT);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
1
deps/hiredis/examples/example-push.c
vendored
1
deps/hiredis/examples/example-push.c
vendored
@ -31,7 +31,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <hiredis.h>
|
#include <hiredis.h>
|
||||||
#include <win32.h>
|
|
||||||
|
|
||||||
#define KEY_COUNT 5
|
#define KEY_COUNT 5
|
||||||
|
|
||||||
|
5
deps/hiredis/examples/example-ssl.c
vendored
5
deps/hiredis/examples/example-ssl.c
vendored
@ -4,7 +4,10 @@
|
|||||||
|
|
||||||
#include <hiredis.h>
|
#include <hiredis.h>
|
||||||
#include <hiredis_ssl.h>
|
#include <hiredis_ssl.h>
|
||||||
#include <win32.h>
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#include <winsock2.h> /* For struct timeval */
|
||||||
|
#endif
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
unsigned int j;
|
unsigned int j;
|
||||||
|
5
deps/hiredis/examples/example.c
vendored
5
deps/hiredis/examples/example.c
vendored
@ -2,7 +2,10 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <hiredis.h>
|
#include <hiredis.h>
|
||||||
#include <win32.h>
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#include <winsock2.h> /* For struct timeval */
|
||||||
|
#endif
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
unsigned int j, isunix = 0;
|
unsigned int j, isunix = 0;
|
||||||
|
2
deps/hiredis/fmacros.h
vendored
2
deps/hiredis/fmacros.h
vendored
@ -1,8 +1,10 @@
|
|||||||
#ifndef __HIREDIS_FMACRO_H
|
#ifndef __HIREDIS_FMACRO_H
|
||||||
#define __HIREDIS_FMACRO_H
|
#define __HIREDIS_FMACRO_H
|
||||||
|
|
||||||
|
#ifndef _AIX
|
||||||
#define _XOPEN_SOURCE 600
|
#define _XOPEN_SOURCE 600
|
||||||
#define _POSIX_C_SOURCE 200112L
|
#define _POSIX_C_SOURCE 200112L
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(__APPLE__) && defined(__MACH__)
|
#if defined(__APPLE__) && defined(__MACH__)
|
||||||
/* Enable TCP_KEEPALIVE */
|
/* Enable TCP_KEEPALIVE */
|
||||||
|
57
deps/hiredis/fuzzing/format_command_fuzzer.c
vendored
Normal file
57
deps/hiredis/fuzzing/format_command_fuzzer.c
vendored
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020, Salvatore Sanfilippo <antirez at gmail dot com>
|
||||||
|
* Copyright (c) 2020, Pieter Noordhuis <pcnoordhuis at gmail dot com>
|
||||||
|
* Copyright (c) 2020, Matt Stancliff <matt at genges dot com>,
|
||||||
|
* Jan-Erik Rediger <janerik at fnordig dot com>
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* * Neither the name of Redis nor the names of its contributors may be used
|
||||||
|
* to endorse or promote products derived from this software without
|
||||||
|
* specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "hiredis.h"
|
||||||
|
|
||||||
|
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||||
|
char *new_str, *cmd;
|
||||||
|
|
||||||
|
if (size < 3)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
new_str = malloc(size+1);
|
||||||
|
if (new_str == NULL)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
memcpy(new_str, data, size);
|
||||||
|
new_str[size] = '\0';
|
||||||
|
|
||||||
|
redisFormatCommand(&cmd, new_str);
|
||||||
|
|
||||||
|
if (cmd != NULL)
|
||||||
|
hi_free(cmd);
|
||||||
|
free(new_str);
|
||||||
|
return 0;
|
||||||
|
}
|
92
deps/hiredis/hiredis.c
vendored
92
deps/hiredis/hiredis.c
vendored
@ -96,6 +96,8 @@ void freeReplyObject(void *reply) {
|
|||||||
|
|
||||||
switch(r->type) {
|
switch(r->type) {
|
||||||
case REDIS_REPLY_INTEGER:
|
case REDIS_REPLY_INTEGER:
|
||||||
|
case REDIS_REPLY_NIL:
|
||||||
|
case REDIS_REPLY_BOOL:
|
||||||
break; /* Nothing to free */
|
break; /* Nothing to free */
|
||||||
case REDIS_REPLY_ARRAY:
|
case REDIS_REPLY_ARRAY:
|
||||||
case REDIS_REPLY_MAP:
|
case REDIS_REPLY_MAP:
|
||||||
@ -112,6 +114,7 @@ void freeReplyObject(void *reply) {
|
|||||||
case REDIS_REPLY_STRING:
|
case REDIS_REPLY_STRING:
|
||||||
case REDIS_REPLY_DOUBLE:
|
case REDIS_REPLY_DOUBLE:
|
||||||
case REDIS_REPLY_VERB:
|
case REDIS_REPLY_VERB:
|
||||||
|
case REDIS_REPLY_BIGNUM:
|
||||||
hi_free(r->str);
|
hi_free(r->str);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -129,7 +132,8 @@ static void *createStringObject(const redisReadTask *task, char *str, size_t len
|
|||||||
assert(task->type == REDIS_REPLY_ERROR ||
|
assert(task->type == REDIS_REPLY_ERROR ||
|
||||||
task->type == REDIS_REPLY_STATUS ||
|
task->type == REDIS_REPLY_STATUS ||
|
||||||
task->type == REDIS_REPLY_STRING ||
|
task->type == REDIS_REPLY_STRING ||
|
||||||
task->type == REDIS_REPLY_VERB);
|
task->type == REDIS_REPLY_VERB ||
|
||||||
|
task->type == REDIS_REPLY_BIGNUM);
|
||||||
|
|
||||||
/* Copy string value */
|
/* Copy string value */
|
||||||
if (task->type == REDIS_REPLY_VERB) {
|
if (task->type == REDIS_REPLY_VERB) {
|
||||||
@ -235,12 +239,14 @@ static void *createDoubleObject(const redisReadTask *task, double value, char *s
|
|||||||
* decimal string conversion artifacts. */
|
* decimal string conversion artifacts. */
|
||||||
memcpy(r->str, str, len);
|
memcpy(r->str, str, len);
|
||||||
r->str[len] = '\0';
|
r->str[len] = '\0';
|
||||||
|
r->len = len;
|
||||||
|
|
||||||
if (task->parent) {
|
if (task->parent) {
|
||||||
parent = task->parent->obj;
|
parent = task->parent->obj;
|
||||||
assert(parent->type == REDIS_REPLY_ARRAY ||
|
assert(parent->type == REDIS_REPLY_ARRAY ||
|
||||||
parent->type == REDIS_REPLY_MAP ||
|
parent->type == REDIS_REPLY_MAP ||
|
||||||
parent->type == REDIS_REPLY_SET);
|
parent->type == REDIS_REPLY_SET ||
|
||||||
|
parent->type == REDIS_REPLY_PUSH);
|
||||||
parent->element[task->idx] = r;
|
parent->element[task->idx] = r;
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
@ -277,7 +283,8 @@ static void *createBoolObject(const redisReadTask *task, int bval) {
|
|||||||
parent = task->parent->obj;
|
parent = task->parent->obj;
|
||||||
assert(parent->type == REDIS_REPLY_ARRAY ||
|
assert(parent->type == REDIS_REPLY_ARRAY ||
|
||||||
parent->type == REDIS_REPLY_MAP ||
|
parent->type == REDIS_REPLY_MAP ||
|
||||||
parent->type == REDIS_REPLY_SET);
|
parent->type == REDIS_REPLY_SET ||
|
||||||
|
parent->type == REDIS_REPLY_PUSH);
|
||||||
parent->element[task->idx] = r;
|
parent->element[task->idx] = r;
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
@ -565,13 +572,12 @@ int redisFormatCommand(char **target, const char *format, ...) {
|
|||||||
* lengths. If the latter is set to NULL, strlen will be used to compute the
|
* lengths. If the latter is set to NULL, strlen will be used to compute the
|
||||||
* argument lengths.
|
* argument lengths.
|
||||||
*/
|
*/
|
||||||
int redisFormatSdsCommandArgv(hisds *target, int argc, const char **argv,
|
long long redisFormatSdsCommandArgv(hisds *target, int argc, const char **argv,
|
||||||
const size_t *argvlen)
|
const size_t *argvlen)
|
||||||
{
|
{
|
||||||
hisds cmd, aux;
|
hisds cmd, aux;
|
||||||
unsigned long long totlen;
|
unsigned long long totlen, len;
|
||||||
int j;
|
int j;
|
||||||
size_t len;
|
|
||||||
|
|
||||||
/* Abort on a NULL target */
|
/* Abort on a NULL target */
|
||||||
if (target == NULL)
|
if (target == NULL)
|
||||||
@ -602,7 +608,7 @@ int redisFormatSdsCommandArgv(hisds *target, int argc, const char **argv,
|
|||||||
cmd = hi_sdscatfmt(cmd, "*%i\r\n", argc);
|
cmd = hi_sdscatfmt(cmd, "*%i\r\n", argc);
|
||||||
for (j=0; j < argc; j++) {
|
for (j=0; j < argc; j++) {
|
||||||
len = argvlen ? argvlen[j] : strlen(argv[j]);
|
len = argvlen ? argvlen[j] : strlen(argv[j]);
|
||||||
cmd = hi_sdscatfmt(cmd, "$%u\r\n", len);
|
cmd = hi_sdscatfmt(cmd, "$%U\r\n", len);
|
||||||
cmd = hi_sdscatlen(cmd, argv[j], len);
|
cmd = hi_sdscatlen(cmd, argv[j], len);
|
||||||
cmd = hi_sdscatlen(cmd, "\r\n", sizeof("\r\n")-1);
|
cmd = hi_sdscatlen(cmd, "\r\n", sizeof("\r\n")-1);
|
||||||
}
|
}
|
||||||
@ -622,11 +628,11 @@ void redisFreeSdsCommand(hisds cmd) {
|
|||||||
* lengths. If the latter is set to NULL, strlen will be used to compute the
|
* lengths. If the latter is set to NULL, strlen will be used to compute the
|
||||||
* argument lengths.
|
* argument lengths.
|
||||||
*/
|
*/
|
||||||
int redisFormatCommandArgv(char **target, int argc, const char **argv, const size_t *argvlen) {
|
long long redisFormatCommandArgv(char **target, int argc, const char **argv, const size_t *argvlen) {
|
||||||
char *cmd = NULL; /* final command */
|
char *cmd = NULL; /* final command */
|
||||||
int pos; /* position in final command */
|
size_t pos; /* position in final command */
|
||||||
size_t len;
|
size_t len, totlen;
|
||||||
int totlen, j;
|
int j;
|
||||||
|
|
||||||
/* Abort on a NULL target */
|
/* Abort on a NULL target */
|
||||||
if (target == NULL)
|
if (target == NULL)
|
||||||
@ -797,6 +803,9 @@ redisContext *redisConnectWithOptions(const redisOptions *options) {
|
|||||||
if (options->options & REDIS_OPT_NOAUTOFREE) {
|
if (options->options & REDIS_OPT_NOAUTOFREE) {
|
||||||
c->flags |= REDIS_NO_AUTO_FREE;
|
c->flags |= REDIS_NO_AUTO_FREE;
|
||||||
}
|
}
|
||||||
|
if (options->options & REDIS_OPT_NOAUTOFREEREPLIES) {
|
||||||
|
c->flags |= REDIS_NO_AUTO_FREE_REPLIES;
|
||||||
|
}
|
||||||
|
|
||||||
/* Set any user supplied RESP3 PUSH handler or use freeReplyObject
|
/* Set any user supplied RESP3 PUSH handler or use freeReplyObject
|
||||||
* as a default unless specifically flagged that we don't want one. */
|
* as a default unless specifically flagged that we don't want one. */
|
||||||
@ -825,7 +834,7 @@ redisContext *redisConnectWithOptions(const redisOptions *options) {
|
|||||||
c->fd = options->endpoint.fd;
|
c->fd = options->endpoint.fd;
|
||||||
c->flags |= REDIS_CONNECTED;
|
c->flags |= REDIS_CONNECTED;
|
||||||
} else {
|
} else {
|
||||||
// Unknown type - FIXME - FREE
|
redisFree(c);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -939,13 +948,11 @@ int redisBufferRead(redisContext *c) {
|
|||||||
return REDIS_ERR;
|
return REDIS_ERR;
|
||||||
|
|
||||||
nread = c->funcs->read(c, buf, sizeof(buf));
|
nread = c->funcs->read(c, buf, sizeof(buf));
|
||||||
if (nread > 0) {
|
if (nread < 0) {
|
||||||
if (redisReaderFeed(c->reader, buf, nread) != REDIS_OK) {
|
return REDIS_ERR;
|
||||||
__redisSetError(c, c->reader->err, c->reader->errstr);
|
}
|
||||||
return REDIS_ERR;
|
if (nread > 0 && redisReaderFeed(c->reader, buf, nread) != REDIS_OK) {
|
||||||
} else {
|
__redisSetError(c, c->reader->err, c->reader->errstr);
|
||||||
}
|
|
||||||
} else if (nread < 0) {
|
|
||||||
return REDIS_ERR;
|
return REDIS_ERR;
|
||||||
}
|
}
|
||||||
return REDIS_OK;
|
return REDIS_OK;
|
||||||
@ -989,17 +996,6 @@ oom:
|
|||||||
return REDIS_ERR;
|
return REDIS_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Internal helper function to try and get a reply from the reader,
|
|
||||||
* or set an error in the context otherwise. */
|
|
||||||
int redisGetReplyFromReader(redisContext *c, void **reply) {
|
|
||||||
if (redisReaderGetReply(c->reader,reply) == REDIS_ERR) {
|
|
||||||
__redisSetError(c,c->reader->err,c->reader->errstr);
|
|
||||||
return REDIS_ERR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return REDIS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Internal helper that returns 1 if the reply was a RESP3 PUSH
|
/* Internal helper that returns 1 if the reply was a RESP3 PUSH
|
||||||
* message and we handled it with a user-provided callback. */
|
* message and we handled it with a user-provided callback. */
|
||||||
static int redisHandledPushReply(redisContext *c, void *reply) {
|
static int redisHandledPushReply(redisContext *c, void *reply) {
|
||||||
@ -1011,12 +1007,34 @@ static int redisHandledPushReply(redisContext *c, void *reply) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get a reply from our reader or set an error in the context. */
|
||||||
|
int redisGetReplyFromReader(redisContext *c, void **reply) {
|
||||||
|
if (redisReaderGetReply(c->reader, reply) == REDIS_ERR) {
|
||||||
|
__redisSetError(c,c->reader->err,c->reader->errstr);
|
||||||
|
return REDIS_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return REDIS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Internal helper to get the next reply from our reader while handling
|
||||||
|
* any PUSH messages we encounter along the way. This is separate from
|
||||||
|
* redisGetReplyFromReader so as to not change its behavior. */
|
||||||
|
static int redisNextInBandReplyFromReader(redisContext *c, void **reply) {
|
||||||
|
do {
|
||||||
|
if (redisGetReplyFromReader(c, reply) == REDIS_ERR)
|
||||||
|
return REDIS_ERR;
|
||||||
|
} while (redisHandledPushReply(c, *reply));
|
||||||
|
|
||||||
|
return REDIS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
int redisGetReply(redisContext *c, void **reply) {
|
int redisGetReply(redisContext *c, void **reply) {
|
||||||
int wdone = 0;
|
int wdone = 0;
|
||||||
void *aux = NULL;
|
void *aux = NULL;
|
||||||
|
|
||||||
/* Try to read pending replies */
|
/* Try to read pending replies */
|
||||||
if (redisGetReplyFromReader(c,&aux) == REDIS_ERR)
|
if (redisNextInBandReplyFromReader(c,&aux) == REDIS_ERR)
|
||||||
return REDIS_ERR;
|
return REDIS_ERR;
|
||||||
|
|
||||||
/* For the blocking context, flush output buffer and read reply */
|
/* For the blocking context, flush output buffer and read reply */
|
||||||
@ -1032,12 +1050,8 @@ int redisGetReply(redisContext *c, void **reply) {
|
|||||||
if (redisBufferRead(c) == REDIS_ERR)
|
if (redisBufferRead(c) == REDIS_ERR)
|
||||||
return REDIS_ERR;
|
return REDIS_ERR;
|
||||||
|
|
||||||
/* We loop here in case the user has specified a RESP3
|
if (redisNextInBandReplyFromReader(c,&aux) == REDIS_ERR)
|
||||||
* PUSH handler (e.g. for client tracking). */
|
return REDIS_ERR;
|
||||||
do {
|
|
||||||
if (redisGetReplyFromReader(c,&aux) == REDIS_ERR)
|
|
||||||
return REDIS_ERR;
|
|
||||||
} while (redisHandledPushReply(c, aux));
|
|
||||||
} while (aux == NULL);
|
} while (aux == NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1114,7 +1128,7 @@ int redisAppendCommand(redisContext *c, const char *format, ...) {
|
|||||||
|
|
||||||
int redisAppendCommandArgv(redisContext *c, int argc, const char **argv, const size_t *argvlen) {
|
int redisAppendCommandArgv(redisContext *c, int argc, const char **argv, const size_t *argvlen) {
|
||||||
hisds cmd;
|
hisds cmd;
|
||||||
int len;
|
long long len;
|
||||||
|
|
||||||
len = redisFormatSdsCommandArgv(&cmd,argc,argv,argvlen);
|
len = redisFormatSdsCommandArgv(&cmd,argc,argv,argvlen);
|
||||||
if (len == -1) {
|
if (len == -1) {
|
||||||
|
24
deps/hiredis/hiredis.h
vendored
24
deps/hiredis/hiredis.h
vendored
@ -47,8 +47,8 @@ typedef long long ssize_t;
|
|||||||
|
|
||||||
#define HIREDIS_MAJOR 1
|
#define HIREDIS_MAJOR 1
|
||||||
#define HIREDIS_MINOR 0
|
#define HIREDIS_MINOR 0
|
||||||
#define HIREDIS_PATCH 0
|
#define HIREDIS_PATCH 3
|
||||||
#define HIREDIS_SONAME 1.0.0
|
#define HIREDIS_SONAME 1.0.3-dev
|
||||||
|
|
||||||
/* Connection type can be blocking or non-blocking and is set in the
|
/* Connection type can be blocking or non-blocking and is set in the
|
||||||
* least significant bit of the flags field in redisContext. */
|
* least significant bit of the flags field in redisContext. */
|
||||||
@ -80,12 +80,18 @@ typedef long long ssize_t;
|
|||||||
/* Flag that is set when we should set SO_REUSEADDR before calling bind() */
|
/* Flag that is set when we should set SO_REUSEADDR before calling bind() */
|
||||||
#define REDIS_REUSEADDR 0x80
|
#define REDIS_REUSEADDR 0x80
|
||||||
|
|
||||||
|
/* Flag that is set when the async connection supports push replies. */
|
||||||
|
#define REDIS_SUPPORTS_PUSH 0x100
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flag that indicates the user does not want the context to
|
* Flag that indicates the user does not want the context to
|
||||||
* be automatically freed upon error
|
* be automatically freed upon error
|
||||||
*/
|
*/
|
||||||
#define REDIS_NO_AUTO_FREE 0x200
|
#define REDIS_NO_AUTO_FREE 0x200
|
||||||
|
|
||||||
|
/* Flag that indicates the user does not want replies to be automatically freed */
|
||||||
|
#define REDIS_NO_AUTO_FREE_REPLIES 0x400
|
||||||
|
|
||||||
#define REDIS_KEEPALIVE_INTERVAL 15 /* seconds */
|
#define REDIS_KEEPALIVE_INTERVAL 15 /* seconds */
|
||||||
|
|
||||||
/* number of times we retry to connect in the case of EADDRNOTAVAIL and
|
/* number of times we retry to connect in the case of EADDRNOTAVAIL and
|
||||||
@ -112,7 +118,8 @@ typedef struct redisReply {
|
|||||||
double dval; /* The double when type is REDIS_REPLY_DOUBLE */
|
double dval; /* The double when type is REDIS_REPLY_DOUBLE */
|
||||||
size_t len; /* Length of string */
|
size_t len; /* Length of string */
|
||||||
char *str; /* Used for REDIS_REPLY_ERROR, REDIS_REPLY_STRING
|
char *str; /* Used for REDIS_REPLY_ERROR, REDIS_REPLY_STRING
|
||||||
REDIS_REPLY_VERB, and REDIS_REPLY_DOUBLE (in additional to dval). */
|
REDIS_REPLY_VERB, REDIS_REPLY_DOUBLE (in additional to dval),
|
||||||
|
and REDIS_REPLY_BIGNUM. */
|
||||||
char vtype[4]; /* Used for REDIS_REPLY_VERB, contains the null
|
char vtype[4]; /* Used for REDIS_REPLY_VERB, contains the null
|
||||||
terminated 3 character content type, such as "txt". */
|
terminated 3 character content type, such as "txt". */
|
||||||
size_t elements; /* number of elements, for REDIS_REPLY_ARRAY */
|
size_t elements; /* number of elements, for REDIS_REPLY_ARRAY */
|
||||||
@ -127,8 +134,8 @@ void freeReplyObject(void *reply);
|
|||||||
/* Functions to format a command according to the protocol. */
|
/* Functions to format a command according to the protocol. */
|
||||||
int redisvFormatCommand(char **target, const char *format, va_list ap);
|
int redisvFormatCommand(char **target, const char *format, va_list ap);
|
||||||
int redisFormatCommand(char **target, const char *format, ...);
|
int redisFormatCommand(char **target, const char *format, ...);
|
||||||
int redisFormatCommandArgv(char **target, int argc, const char **argv, const size_t *argvlen);
|
long long redisFormatCommandArgv(char **target, int argc, const char **argv, const size_t *argvlen);
|
||||||
int redisFormatSdsCommandArgv(hisds *target, int argc, const char ** argv, const size_t *argvlen);
|
long long redisFormatSdsCommandArgv(hisds *target, int argc, const char ** argv, const size_t *argvlen);
|
||||||
void redisFreeCommand(char *cmd);
|
void redisFreeCommand(char *cmd);
|
||||||
void redisFreeSdsCommand(hisds cmd);
|
void redisFreeSdsCommand(hisds cmd);
|
||||||
|
|
||||||
@ -152,6 +159,11 @@ struct redisSsl;
|
|||||||
/* Don't automatically intercept and free RESP3 PUSH replies. */
|
/* Don't automatically intercept and free RESP3 PUSH replies. */
|
||||||
#define REDIS_OPT_NO_PUSH_AUTOFREE 0x08
|
#define REDIS_OPT_NO_PUSH_AUTOFREE 0x08
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Don't automatically free replies
|
||||||
|
*/
|
||||||
|
#define REDIS_OPT_NOAUTOFREEREPLIES 0x10
|
||||||
|
|
||||||
/* In Unix systems a file descriptor is a regular signed int, with -1
|
/* In Unix systems a file descriptor is a regular signed int, with -1
|
||||||
* representing an invalid descriptor. In Windows it is a SOCKET
|
* representing an invalid descriptor. In Windows it is a SOCKET
|
||||||
* (32- or 64-bit unsigned integer depending on the architecture), where
|
* (32- or 64-bit unsigned integer depending on the architecture), where
|
||||||
@ -255,7 +267,7 @@ typedef struct redisContext {
|
|||||||
} unix_sock;
|
} unix_sock;
|
||||||
|
|
||||||
/* For non-blocking connect */
|
/* For non-blocking connect */
|
||||||
struct sockadr *saddr;
|
struct sockaddr *saddr;
|
||||||
size_t addrlen;
|
size_t addrlen;
|
||||||
|
|
||||||
/* Optional data and corresponding destructor users can use to provide
|
/* Optional data and corresponding destructor users can use to provide
|
||||||
|
11
deps/hiredis/hiredis.targets
vendored
Normal file
11
deps/hiredis/hiredis.targets
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemDefinitionGroup>
|
||||||
|
<ClCompile>
|
||||||
|
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)\..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<AdditionalLibraryDirectories>$(MSBuildThisFileDirectory)\..\..\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
</Project>
|
4
deps/hiredis/hiredis_ssl.h
vendored
4
deps/hiredis/hiredis_ssl.h
vendored
@ -56,7 +56,9 @@ typedef enum {
|
|||||||
REDIS_SSL_CTX_CERT_KEY_REQUIRED, /* Client cert and key must both be specified or skipped */
|
REDIS_SSL_CTX_CERT_KEY_REQUIRED, /* Client cert and key must both be specified or skipped */
|
||||||
REDIS_SSL_CTX_CA_CERT_LOAD_FAILED, /* Failed to load CA Certificate or CA Path */
|
REDIS_SSL_CTX_CA_CERT_LOAD_FAILED, /* Failed to load CA Certificate or CA Path */
|
||||||
REDIS_SSL_CTX_CLIENT_CERT_LOAD_FAILED, /* Failed to load client certificate */
|
REDIS_SSL_CTX_CLIENT_CERT_LOAD_FAILED, /* Failed to load client certificate */
|
||||||
REDIS_SSL_CTX_PRIVATE_KEY_LOAD_FAILED /* Failed to load private key */
|
REDIS_SSL_CTX_PRIVATE_KEY_LOAD_FAILED, /* Failed to load private key */
|
||||||
|
REDIS_SSL_CTX_OS_CERTSTORE_OPEN_FAILED, /* Failed to open system certifcate store */
|
||||||
|
REDIS_SSL_CTX_OS_CERT_ADD_FAILED /* Failed to add CA certificates obtained from system to the SSL context */
|
||||||
} redisSSLContextError;
|
} redisSSLContextError;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
142
deps/hiredis/read.c
vendored
142
deps/hiredis/read.c
vendored
@ -123,29 +123,28 @@ static char *readBytes(redisReader *r, unsigned int bytes) {
|
|||||||
|
|
||||||
/* Find pointer to \r\n. */
|
/* Find pointer to \r\n. */
|
||||||
static char *seekNewline(char *s, size_t len) {
|
static char *seekNewline(char *s, size_t len) {
|
||||||
int pos = 0;
|
char *ret;
|
||||||
int _len = len-1;
|
|
||||||
|
|
||||||
/* Position should be < len-1 because the character at "pos" should be
|
/* We cannot match with fewer than 2 bytes */
|
||||||
* followed by a \n. Note that strchr cannot be used because it doesn't
|
if (len < 2)
|
||||||
* allow to search a limited length and the buffer that is being searched
|
return NULL;
|
||||||
* might not have a trailing NULL character. */
|
|
||||||
while (pos < _len) {
|
/* Search up to len - 1 characters */
|
||||||
while(pos < _len && s[pos] != '\r') pos++;
|
len--;
|
||||||
if (pos==_len) {
|
|
||||||
/* Not found. */
|
/* Look for the \r */
|
||||||
return NULL;
|
while ((ret = memchr(s, '\r', len)) != NULL) {
|
||||||
} else {
|
if (ret[1] == '\n') {
|
||||||
if (s[pos+1] == '\n') {
|
/* Found. */
|
||||||
/* Found. */
|
break;
|
||||||
return s+pos;
|
|
||||||
} else {
|
|
||||||
/* Continue searching. */
|
|
||||||
pos++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
/* Continue searching. */
|
||||||
|
ret++;
|
||||||
|
len -= ret - s;
|
||||||
|
s = ret;
|
||||||
}
|
}
|
||||||
return NULL;
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert a string into a long long. Returns REDIS_OK if the string could be
|
/* Convert a string into a long long. Returns REDIS_OK if the string could be
|
||||||
@ -274,60 +273,104 @@ static int processLineItem(redisReader *r) {
|
|||||||
|
|
||||||
if ((p = readLine(r,&len)) != NULL) {
|
if ((p = readLine(r,&len)) != NULL) {
|
||||||
if (cur->type == REDIS_REPLY_INTEGER) {
|
if (cur->type == REDIS_REPLY_INTEGER) {
|
||||||
|
long long v;
|
||||||
|
|
||||||
|
if (string2ll(p, len, &v) == REDIS_ERR) {
|
||||||
|
__redisReaderSetError(r,REDIS_ERR_PROTOCOL,
|
||||||
|
"Bad integer value");
|
||||||
|
return REDIS_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
if (r->fn && r->fn->createInteger) {
|
if (r->fn && r->fn->createInteger) {
|
||||||
long long v;
|
|
||||||
if (string2ll(p, len, &v) == REDIS_ERR) {
|
|
||||||
__redisReaderSetError(r,REDIS_ERR_PROTOCOL,
|
|
||||||
"Bad integer value");
|
|
||||||
return REDIS_ERR;
|
|
||||||
}
|
|
||||||
obj = r->fn->createInteger(cur,v);
|
obj = r->fn->createInteger(cur,v);
|
||||||
} else {
|
} else {
|
||||||
obj = (void*)REDIS_REPLY_INTEGER;
|
obj = (void*)REDIS_REPLY_INTEGER;
|
||||||
}
|
}
|
||||||
} else if (cur->type == REDIS_REPLY_DOUBLE) {
|
} else if (cur->type == REDIS_REPLY_DOUBLE) {
|
||||||
if (r->fn && r->fn->createDouble) {
|
char buf[326], *eptr;
|
||||||
char buf[326], *eptr;
|
double d;
|
||||||
double d;
|
|
||||||
|
|
||||||
if ((size_t)len >= sizeof(buf)) {
|
if ((size_t)len >= sizeof(buf)) {
|
||||||
|
__redisReaderSetError(r,REDIS_ERR_PROTOCOL,
|
||||||
|
"Double value is too large");
|
||||||
|
return REDIS_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(buf,p,len);
|
||||||
|
buf[len] = '\0';
|
||||||
|
|
||||||
|
if (len == 3 && strcasecmp(buf,"inf") == 0) {
|
||||||
|
d = INFINITY; /* Positive infinite. */
|
||||||
|
} else if (len == 4 && strcasecmp(buf,"-inf") == 0) {
|
||||||
|
d = -INFINITY; /* Negative infinite. */
|
||||||
|
} else {
|
||||||
|
d = strtod((char*)buf,&eptr);
|
||||||
|
/* RESP3 only allows "inf", "-inf", and finite values, while
|
||||||
|
* strtod() allows other variations on infinity, NaN,
|
||||||
|
* etc. We explicity handle our two allowed infinite cases
|
||||||
|
* above, so strtod() should only result in finite values. */
|
||||||
|
if (buf[0] == '\0' || eptr != &buf[len] || !isfinite(d)) {
|
||||||
__redisReaderSetError(r,REDIS_ERR_PROTOCOL,
|
__redisReaderSetError(r,REDIS_ERR_PROTOCOL,
|
||||||
"Double value is too large");
|
"Bad double value");
|
||||||
return REDIS_ERR;
|
return REDIS_ERR;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
memcpy(buf,p,len);
|
if (r->fn && r->fn->createDouble) {
|
||||||
buf[len] = '\0';
|
|
||||||
|
|
||||||
if (strcasecmp(buf,",inf") == 0) {
|
|
||||||
d = INFINITY; /* Positive infinite. */
|
|
||||||
} else if (strcasecmp(buf,",-inf") == 0) {
|
|
||||||
d = -INFINITY; /* Negative infinite. */
|
|
||||||
} else {
|
|
||||||
d = strtod((char*)buf,&eptr);
|
|
||||||
if (buf[0] == '\0' || eptr[0] != '\0' || isnan(d)) {
|
|
||||||
__redisReaderSetError(r,REDIS_ERR_PROTOCOL,
|
|
||||||
"Bad double value");
|
|
||||||
return REDIS_ERR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
obj = r->fn->createDouble(cur,d,buf,len);
|
obj = r->fn->createDouble(cur,d,buf,len);
|
||||||
} else {
|
} else {
|
||||||
obj = (void*)REDIS_REPLY_DOUBLE;
|
obj = (void*)REDIS_REPLY_DOUBLE;
|
||||||
}
|
}
|
||||||
} else if (cur->type == REDIS_REPLY_NIL) {
|
} else if (cur->type == REDIS_REPLY_NIL) {
|
||||||
|
if (len != 0) {
|
||||||
|
__redisReaderSetError(r,REDIS_ERR_PROTOCOL,
|
||||||
|
"Bad nil value");
|
||||||
|
return REDIS_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
if (r->fn && r->fn->createNil)
|
if (r->fn && r->fn->createNil)
|
||||||
obj = r->fn->createNil(cur);
|
obj = r->fn->createNil(cur);
|
||||||
else
|
else
|
||||||
obj = (void*)REDIS_REPLY_NIL;
|
obj = (void*)REDIS_REPLY_NIL;
|
||||||
} else if (cur->type == REDIS_REPLY_BOOL) {
|
} else if (cur->type == REDIS_REPLY_BOOL) {
|
||||||
int bval = p[0] == 't' || p[0] == 'T';
|
int bval;
|
||||||
|
|
||||||
|
if (len != 1 || !strchr("tTfF", p[0])) {
|
||||||
|
__redisReaderSetError(r,REDIS_ERR_PROTOCOL,
|
||||||
|
"Bad bool value");
|
||||||
|
return REDIS_ERR;
|
||||||
|
}
|
||||||
|
|
||||||
|
bval = p[0] == 't' || p[0] == 'T';
|
||||||
if (r->fn && r->fn->createBool)
|
if (r->fn && r->fn->createBool)
|
||||||
obj = r->fn->createBool(cur,bval);
|
obj = r->fn->createBool(cur,bval);
|
||||||
else
|
else
|
||||||
obj = (void*)REDIS_REPLY_BOOL;
|
obj = (void*)REDIS_REPLY_BOOL;
|
||||||
|
} else if (cur->type == REDIS_REPLY_BIGNUM) {
|
||||||
|
/* Ensure all characters are decimal digits (with possible leading
|
||||||
|
* minus sign). */
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
/* XXX Consider: Allow leading '+'? Error on leading '0's? */
|
||||||
|
if (i == 0 && p[0] == '-') continue;
|
||||||
|
if (p[i] < '0' || p[i] > '9') {
|
||||||
|
__redisReaderSetError(r,REDIS_ERR_PROTOCOL,
|
||||||
|
"Bad bignum value");
|
||||||
|
return REDIS_ERR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (r->fn && r->fn->createString)
|
||||||
|
obj = r->fn->createString(cur,p,len);
|
||||||
|
else
|
||||||
|
obj = (void*)REDIS_REPLY_BIGNUM;
|
||||||
} else {
|
} else {
|
||||||
/* Type will be error or status. */
|
/* Type will be error or status. */
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
if (p[i] == '\r' || p[i] == '\n') {
|
||||||
|
__redisReaderSetError(r,REDIS_ERR_PROTOCOL,
|
||||||
|
"Bad simple string value");
|
||||||
|
return REDIS_ERR;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (r->fn && r->fn->createString)
|
if (r->fn && r->fn->createString)
|
||||||
obj = r->fn->createString(cur,p,len);
|
obj = r->fn->createString(cur,p,len);
|
||||||
else
|
else
|
||||||
@ -453,7 +496,6 @@ static int processAggregateItem(redisReader *r) {
|
|||||||
long long elements;
|
long long elements;
|
||||||
int root = 0, len;
|
int root = 0, len;
|
||||||
|
|
||||||
/* Set error for nested multi bulks with depth > 7 */
|
|
||||||
if (r->ridx == r->tasks - 1) {
|
if (r->ridx == r->tasks - 1) {
|
||||||
if (redisReaderGrow(r) == REDIS_ERR)
|
if (redisReaderGrow(r) == REDIS_ERR)
|
||||||
return REDIS_ERR;
|
return REDIS_ERR;
|
||||||
@ -569,6 +611,9 @@ static int processItem(redisReader *r) {
|
|||||||
case '>':
|
case '>':
|
||||||
cur->type = REDIS_REPLY_PUSH;
|
cur->type = REDIS_REPLY_PUSH;
|
||||||
break;
|
break;
|
||||||
|
case '(':
|
||||||
|
cur->type = REDIS_REPLY_BIGNUM;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
__redisReaderSetErrorProtocolByte(r,*p);
|
__redisReaderSetErrorProtocolByte(r,*p);
|
||||||
return REDIS_ERR;
|
return REDIS_ERR;
|
||||||
@ -587,6 +632,7 @@ static int processItem(redisReader *r) {
|
|||||||
case REDIS_REPLY_DOUBLE:
|
case REDIS_REPLY_DOUBLE:
|
||||||
case REDIS_REPLY_NIL:
|
case REDIS_REPLY_NIL:
|
||||||
case REDIS_REPLY_BOOL:
|
case REDIS_REPLY_BOOL:
|
||||||
|
case REDIS_REPLY_BIGNUM:
|
||||||
return processLineItem(r);
|
return processLineItem(r);
|
||||||
case REDIS_REPLY_STRING:
|
case REDIS_REPLY_STRING:
|
||||||
case REDIS_REPLY_VERB:
|
case REDIS_REPLY_VERB:
|
||||||
|
4
deps/hiredis/sds.c
vendored
4
deps/hiredis/sds.c
vendored
@ -72,7 +72,7 @@ static inline char hi_sdsReqType(size_t string_size) {
|
|||||||
* and 'initlen'.
|
* and 'initlen'.
|
||||||
* If NULL is used for 'init' the string is initialized with zero bytes.
|
* If NULL is used for 'init' the string is initialized with zero bytes.
|
||||||
*
|
*
|
||||||
* The string is always null-termined (all the hisds strings are, always) so
|
* The string is always null-terminated (all the hisds strings are, always) so
|
||||||
* even if you create an hisds string with:
|
* even if you create an hisds string with:
|
||||||
*
|
*
|
||||||
* mystring = hi_sdsnewlen("abc",3);
|
* mystring = hi_sdsnewlen("abc",3);
|
||||||
@ -415,7 +415,7 @@ hisds hi_sdscpylen(hisds s, const char *t, size_t len) {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Like hi_sdscpylen() but 't' must be a null-termined string so that the length
|
/* Like hi_sdscpylen() but 't' must be a null-terminated string so that the length
|
||||||
* of the string is obtained with strlen(). */
|
* of the string is obtained with strlen(). */
|
||||||
hisds hi_sdscpy(hisds s, const char *t) {
|
hisds hi_sdscpy(hisds s, const char *t) {
|
||||||
return hi_sdscpylen(s, t, strlen(t));
|
return hi_sdscpylen(s, t, strlen(t));
|
||||||
|
45
deps/hiredis/ssl.c
vendored
45
deps/hiredis/ssl.c
vendored
@ -38,6 +38,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include <wincrypt.h>
|
||||||
#else
|
#else
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#endif
|
#endif
|
||||||
@ -182,6 +183,10 @@ const char *redisSSLContextGetError(redisSSLContextError error)
|
|||||||
return "Failed to load client certificate";
|
return "Failed to load client certificate";
|
||||||
case REDIS_SSL_CTX_PRIVATE_KEY_LOAD_FAILED:
|
case REDIS_SSL_CTX_PRIVATE_KEY_LOAD_FAILED:
|
||||||
return "Failed to load private key";
|
return "Failed to load private key";
|
||||||
|
case REDIS_SSL_CTX_OS_CERTSTORE_OPEN_FAILED:
|
||||||
|
return "Failed to open system certifcate store";
|
||||||
|
case REDIS_SSL_CTX_OS_CERT_ADD_FAILED:
|
||||||
|
return "Failed to add CA certificates obtained from system to the SSL context";
|
||||||
default:
|
default:
|
||||||
return "Unknown error code";
|
return "Unknown error code";
|
||||||
}
|
}
|
||||||
@ -214,6 +219,11 @@ redisSSLContext *redisCreateSSLContext(const char *cacert_filename, const char *
|
|||||||
const char *cert_filename, const char *private_key_filename,
|
const char *cert_filename, const char *private_key_filename,
|
||||||
const char *server_name, redisSSLContextError *error)
|
const char *server_name, redisSSLContextError *error)
|
||||||
{
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
HCERTSTORE win_store = NULL;
|
||||||
|
PCCERT_CONTEXT win_ctx = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
redisSSLContext *ctx = hi_calloc(1, sizeof(redisSSLContext));
|
redisSSLContext *ctx = hi_calloc(1, sizeof(redisSSLContext));
|
||||||
if (ctx == NULL)
|
if (ctx == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
@ -234,6 +244,31 @@ redisSSLContext *redisCreateSSLContext(const char *cacert_filename, const char *
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (capath || cacert_filename) {
|
if (capath || cacert_filename) {
|
||||||
|
#ifdef _WIN32
|
||||||
|
if (0 == strcmp(cacert_filename, "wincert")) {
|
||||||
|
win_store = CertOpenSystemStore(NULL, "Root");
|
||||||
|
if (!win_store) {
|
||||||
|
if (error) *error = REDIS_SSL_CTX_OS_CERTSTORE_OPEN_FAILED;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
X509_STORE* store = SSL_CTX_get_cert_store(ctx->ssl_ctx);
|
||||||
|
while (win_ctx = CertEnumCertificatesInStore(win_store, win_ctx)) {
|
||||||
|
X509* x509 = NULL;
|
||||||
|
x509 = d2i_X509(NULL, (const unsigned char**)&win_ctx->pbCertEncoded, win_ctx->cbCertEncoded);
|
||||||
|
if (x509) {
|
||||||
|
if ((1 != X509_STORE_add_cert(store, x509)) ||
|
||||||
|
(1 != SSL_CTX_add_client_CA(ctx->ssl_ctx, x509)))
|
||||||
|
{
|
||||||
|
if (error) *error = REDIS_SSL_CTX_OS_CERT_ADD_FAILED;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
X509_free(x509);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CertFreeCertificateContext(win_ctx);
|
||||||
|
CertCloseStore(win_store, 0);
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
if (!SSL_CTX_load_verify_locations(ctx->ssl_ctx, cacert_filename, capath)) {
|
if (!SSL_CTX_load_verify_locations(ctx->ssl_ctx, cacert_filename, capath)) {
|
||||||
if (error) *error = REDIS_SSL_CTX_CA_CERT_LOAD_FAILED;
|
if (error) *error = REDIS_SSL_CTX_CA_CERT_LOAD_FAILED;
|
||||||
goto error;
|
goto error;
|
||||||
@ -257,6 +292,10 @@ redisSSLContext *redisCreateSSLContext(const char *cacert_filename, const char *
|
|||||||
return ctx;
|
return ctx;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
#ifdef _WIN32
|
||||||
|
CertFreeCertificateContext(win_ctx);
|
||||||
|
CertCloseStore(win_store, 0);
|
||||||
|
#endif
|
||||||
redisFreeSSLContext(ctx);
|
redisFreeSSLContext(ctx);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -353,7 +392,11 @@ int redisInitiateSSLWithContext(redisContext *c, redisSSLContext *redis_ssl_ctx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return redisSSLConnect(c, ssl);
|
if (redisSSLConnect(c, ssl) != REDIS_OK) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return REDIS_OK;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
if (ssl)
|
if (ssl)
|
||||||
|
616
deps/hiredis/test.c
vendored
616
deps/hiredis/test.c
vendored
@ -11,12 +11,17 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include "hiredis.h"
|
#include "hiredis.h"
|
||||||
#include "async.h"
|
#include "async.h"
|
||||||
#ifdef HIREDIS_TEST_SSL
|
#ifdef HIREDIS_TEST_SSL
|
||||||
#include "hiredis_ssl.h"
|
#include "hiredis_ssl.h"
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HIREDIS_TEST_ASYNC
|
||||||
|
#include "adapters/libevent.h"
|
||||||
|
#include <event2/event.h>
|
||||||
|
#endif
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include "win32.h"
|
#include "win32.h"
|
||||||
|
|
||||||
@ -58,6 +63,8 @@ struct pushCounters {
|
|||||||
int str;
|
int str;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int insecure_calloc_calls;
|
||||||
|
|
||||||
#ifdef HIREDIS_TEST_SSL
|
#ifdef HIREDIS_TEST_SSL
|
||||||
redisSSLContext *_ssl_ctx = NULL;
|
redisSSLContext *_ssl_ctx = NULL;
|
||||||
#endif
|
#endif
|
||||||
@ -597,6 +604,147 @@ static void test_reply_reader(void) {
|
|||||||
((redisReply*)reply)->element[1]->integer == 42);
|
((redisReply*)reply)->element[1]->integer == 42);
|
||||||
freeReplyObject(reply);
|
freeReplyObject(reply);
|
||||||
redisReaderFree(reader);
|
redisReaderFree(reader);
|
||||||
|
|
||||||
|
test("Can parse RESP3 doubles: ");
|
||||||
|
reader = redisReaderCreate();
|
||||||
|
redisReaderFeed(reader, ",3.14159265358979323846\r\n",25);
|
||||||
|
ret = redisReaderGetReply(reader,&reply);
|
||||||
|
test_cond(ret == REDIS_OK &&
|
||||||
|
((redisReply*)reply)->type == REDIS_REPLY_DOUBLE &&
|
||||||
|
fabs(((redisReply*)reply)->dval - 3.14159265358979323846) < 0.00000001 &&
|
||||||
|
((redisReply*)reply)->len == 22 &&
|
||||||
|
strcmp(((redisReply*)reply)->str, "3.14159265358979323846") == 0);
|
||||||
|
freeReplyObject(reply);
|
||||||
|
redisReaderFree(reader);
|
||||||
|
|
||||||
|
test("Set error on invalid RESP3 double: ");
|
||||||
|
reader = redisReaderCreate();
|
||||||
|
redisReaderFeed(reader, ",3.14159\000265358979323846\r\n",26);
|
||||||
|
ret = redisReaderGetReply(reader,&reply);
|
||||||
|
test_cond(ret == REDIS_ERR &&
|
||||||
|
strcasecmp(reader->errstr,"Bad double value") == 0);
|
||||||
|
freeReplyObject(reply);
|
||||||
|
redisReaderFree(reader);
|
||||||
|
|
||||||
|
test("Correctly parses RESP3 double INFINITY: ");
|
||||||
|
reader = redisReaderCreate();
|
||||||
|
redisReaderFeed(reader, ",inf\r\n",6);
|
||||||
|
ret = redisReaderGetReply(reader,&reply);
|
||||||
|
test_cond(ret == REDIS_OK &&
|
||||||
|
((redisReply*)reply)->type == REDIS_REPLY_DOUBLE &&
|
||||||
|
isinf(((redisReply*)reply)->dval) &&
|
||||||
|
((redisReply*)reply)->dval > 0);
|
||||||
|
freeReplyObject(reply);
|
||||||
|
redisReaderFree(reader);
|
||||||
|
|
||||||
|
test("Set error when RESP3 double is NaN: ");
|
||||||
|
reader = redisReaderCreate();
|
||||||
|
redisReaderFeed(reader, ",nan\r\n",6);
|
||||||
|
ret = redisReaderGetReply(reader,&reply);
|
||||||
|
test_cond(ret == REDIS_ERR &&
|
||||||
|
strcasecmp(reader->errstr,"Bad double value") == 0);
|
||||||
|
freeReplyObject(reply);
|
||||||
|
redisReaderFree(reader);
|
||||||
|
|
||||||
|
test("Can parse RESP3 nil: ");
|
||||||
|
reader = redisReaderCreate();
|
||||||
|
redisReaderFeed(reader, "_\r\n",3);
|
||||||
|
ret = redisReaderGetReply(reader,&reply);
|
||||||
|
test_cond(ret == REDIS_OK &&
|
||||||
|
((redisReply*)reply)->type == REDIS_REPLY_NIL);
|
||||||
|
freeReplyObject(reply);
|
||||||
|
redisReaderFree(reader);
|
||||||
|
|
||||||
|
test("Set error on invalid RESP3 nil: ");
|
||||||
|
reader = redisReaderCreate();
|
||||||
|
redisReaderFeed(reader, "_nil\r\n",6);
|
||||||
|
ret = redisReaderGetReply(reader,&reply);
|
||||||
|
test_cond(ret == REDIS_ERR &&
|
||||||
|
strcasecmp(reader->errstr,"Bad nil value") == 0);
|
||||||
|
freeReplyObject(reply);
|
||||||
|
redisReaderFree(reader);
|
||||||
|
|
||||||
|
test("Can parse RESP3 bool (true): ");
|
||||||
|
reader = redisReaderCreate();
|
||||||
|
redisReaderFeed(reader, "#t\r\n",4);
|
||||||
|
ret = redisReaderGetReply(reader,&reply);
|
||||||
|
test_cond(ret == REDIS_OK &&
|
||||||
|
((redisReply*)reply)->type == REDIS_REPLY_BOOL &&
|
||||||
|
((redisReply*)reply)->integer);
|
||||||
|
freeReplyObject(reply);
|
||||||
|
redisReaderFree(reader);
|
||||||
|
|
||||||
|
test("Can parse RESP3 bool (false): ");
|
||||||
|
reader = redisReaderCreate();
|
||||||
|
redisReaderFeed(reader, "#f\r\n",4);
|
||||||
|
ret = redisReaderGetReply(reader,&reply);
|
||||||
|
test_cond(ret == REDIS_OK &&
|
||||||
|
((redisReply*)reply)->type == REDIS_REPLY_BOOL &&
|
||||||
|
!((redisReply*)reply)->integer);
|
||||||
|
freeReplyObject(reply);
|
||||||
|
redisReaderFree(reader);
|
||||||
|
|
||||||
|
test("Set error on invalid RESP3 bool: ");
|
||||||
|
reader = redisReaderCreate();
|
||||||
|
redisReaderFeed(reader, "#foobar\r\n",9);
|
||||||
|
ret = redisReaderGetReply(reader,&reply);
|
||||||
|
test_cond(ret == REDIS_ERR &&
|
||||||
|
strcasecmp(reader->errstr,"Bad bool value") == 0);
|
||||||
|
freeReplyObject(reply);
|
||||||
|
redisReaderFree(reader);
|
||||||
|
|
||||||
|
test("Can parse RESP3 map: ");
|
||||||
|
reader = redisReaderCreate();
|
||||||
|
redisReaderFeed(reader, "%2\r\n+first\r\n:123\r\n$6\r\nsecond\r\n#t\r\n",34);
|
||||||
|
ret = redisReaderGetReply(reader,&reply);
|
||||||
|
test_cond(ret == REDIS_OK &&
|
||||||
|
((redisReply*)reply)->type == REDIS_REPLY_MAP &&
|
||||||
|
((redisReply*)reply)->elements == 4 &&
|
||||||
|
((redisReply*)reply)->element[0]->type == REDIS_REPLY_STATUS &&
|
||||||
|
((redisReply*)reply)->element[0]->len == 5 &&
|
||||||
|
!strcmp(((redisReply*)reply)->element[0]->str,"first") &&
|
||||||
|
((redisReply*)reply)->element[1]->type == REDIS_REPLY_INTEGER &&
|
||||||
|
((redisReply*)reply)->element[1]->integer == 123 &&
|
||||||
|
((redisReply*)reply)->element[2]->type == REDIS_REPLY_STRING &&
|
||||||
|
((redisReply*)reply)->element[2]->len == 6 &&
|
||||||
|
!strcmp(((redisReply*)reply)->element[2]->str,"second") &&
|
||||||
|
((redisReply*)reply)->element[3]->type == REDIS_REPLY_BOOL &&
|
||||||
|
((redisReply*)reply)->element[3]->integer);
|
||||||
|
freeReplyObject(reply);
|
||||||
|
redisReaderFree(reader);
|
||||||
|
|
||||||
|
test("Can parse RESP3 set: ");
|
||||||
|
reader = redisReaderCreate();
|
||||||
|
redisReaderFeed(reader, "~5\r\n+orange\r\n$5\r\napple\r\n#f\r\n:100\r\n:999\r\n",40);
|
||||||
|
ret = redisReaderGetReply(reader,&reply);
|
||||||
|
test_cond(ret == REDIS_OK &&
|
||||||
|
((redisReply*)reply)->type == REDIS_REPLY_SET &&
|
||||||
|
((redisReply*)reply)->elements == 5 &&
|
||||||
|
((redisReply*)reply)->element[0]->type == REDIS_REPLY_STATUS &&
|
||||||
|
((redisReply*)reply)->element[0]->len == 6 &&
|
||||||
|
!strcmp(((redisReply*)reply)->element[0]->str,"orange") &&
|
||||||
|
((redisReply*)reply)->element[1]->type == REDIS_REPLY_STRING &&
|
||||||
|
((redisReply*)reply)->element[1]->len == 5 &&
|
||||||
|
!strcmp(((redisReply*)reply)->element[1]->str,"apple") &&
|
||||||
|
((redisReply*)reply)->element[2]->type == REDIS_REPLY_BOOL &&
|
||||||
|
!((redisReply*)reply)->element[2]->integer &&
|
||||||
|
((redisReply*)reply)->element[3]->type == REDIS_REPLY_INTEGER &&
|
||||||
|
((redisReply*)reply)->element[3]->integer == 100 &&
|
||||||
|
((redisReply*)reply)->element[4]->type == REDIS_REPLY_INTEGER &&
|
||||||
|
((redisReply*)reply)->element[4]->integer == 999);
|
||||||
|
freeReplyObject(reply);
|
||||||
|
redisReaderFree(reader);
|
||||||
|
|
||||||
|
test("Can parse RESP3 bignum: ");
|
||||||
|
reader = redisReaderCreate();
|
||||||
|
redisReaderFeed(reader,"(3492890328409238509324850943850943825024385\r\n",46);
|
||||||
|
ret = redisReaderGetReply(reader,&reply);
|
||||||
|
test_cond(ret == REDIS_OK &&
|
||||||
|
((redisReply*)reply)->type == REDIS_REPLY_BIGNUM &&
|
||||||
|
((redisReply*)reply)->len == 43 &&
|
||||||
|
!strcmp(((redisReply*)reply)->str,"3492890328409238509324850943850943825024385"));
|
||||||
|
freeReplyObject(reply);
|
||||||
|
redisReaderFree(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_free_null(void) {
|
static void test_free_null(void) {
|
||||||
@ -623,6 +771,13 @@ static void *hi_calloc_fail(size_t nmemb, size_t size) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void *hi_calloc_insecure(size_t nmemb, size_t size) {
|
||||||
|
(void)nmemb;
|
||||||
|
(void)size;
|
||||||
|
insecure_calloc_calls++;
|
||||||
|
return (void*)0xdeadc0de;
|
||||||
|
}
|
||||||
|
|
||||||
static void *hi_realloc_fail(void *ptr, size_t size) {
|
static void *hi_realloc_fail(void *ptr, size_t size) {
|
||||||
(void)ptr;
|
(void)ptr;
|
||||||
(void)size;
|
(void)size;
|
||||||
@ -630,6 +785,8 @@ static void *hi_realloc_fail(void *ptr, size_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void test_allocator_injection(void) {
|
static void test_allocator_injection(void) {
|
||||||
|
void *ptr;
|
||||||
|
|
||||||
hiredisAllocFuncs ha = {
|
hiredisAllocFuncs ha = {
|
||||||
.mallocFn = hi_malloc_fail,
|
.mallocFn = hi_malloc_fail,
|
||||||
.callocFn = hi_calloc_fail,
|
.callocFn = hi_calloc_fail,
|
||||||
@ -649,6 +806,13 @@ static void test_allocator_injection(void) {
|
|||||||
redisReader *reader = redisReaderCreate();
|
redisReader *reader = redisReaderCreate();
|
||||||
test_cond(reader == NULL);
|
test_cond(reader == NULL);
|
||||||
|
|
||||||
|
/* Make sure hiredis itself protects against a non-overflow checking calloc */
|
||||||
|
test("hiredis calloc wrapper protects against overflow: ");
|
||||||
|
ha.callocFn = hi_calloc_insecure;
|
||||||
|
hiredisSetAllocators(&ha);
|
||||||
|
ptr = hi_calloc((SIZE_MAX / sizeof(void*)) + 3, sizeof(void*));
|
||||||
|
test_cond(ptr == NULL && insecure_calloc_calls == 0);
|
||||||
|
|
||||||
// Return allocators to default
|
// Return allocators to default
|
||||||
hiredisResetAllocators();
|
hiredisResetAllocators();
|
||||||
}
|
}
|
||||||
@ -1283,6 +1447,440 @@ static void test_throughput(struct config config) {
|
|||||||
// redisFree(c);
|
// redisFree(c);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
#ifdef HIREDIS_TEST_ASYNC
|
||||||
|
struct event_base *base;
|
||||||
|
|
||||||
|
typedef struct TestState {
|
||||||
|
redisOptions *options;
|
||||||
|
int checkpoint;
|
||||||
|
int resp3;
|
||||||
|
int disconnect;
|
||||||
|
} TestState;
|
||||||
|
|
||||||
|
/* Helper to disconnect and stop event loop */
|
||||||
|
void async_disconnect(redisAsyncContext *ac) {
|
||||||
|
redisAsyncDisconnect(ac);
|
||||||
|
event_base_loopbreak(base);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Testcase timeout, will trigger a failure */
|
||||||
|
void timeout_cb(int fd, short event, void *arg) {
|
||||||
|
(void) fd; (void) event; (void) arg;
|
||||||
|
printf("Timeout in async testing!\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Unexpected call, will trigger a failure */
|
||||||
|
void unexpected_cb(redisAsyncContext *ac, void *r, void *privdata) {
|
||||||
|
(void) ac; (void) r;
|
||||||
|
printf("Unexpected call: %s\n",(char*)privdata);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Helper function to publish a message via own client. */
|
||||||
|
void publish_msg(redisOptions *options, const char* channel, const char* msg) {
|
||||||
|
redisContext *c = redisConnectWithOptions(options);
|
||||||
|
assert(c != NULL);
|
||||||
|
redisReply *reply = redisCommand(c,"PUBLISH %s %s",channel,msg);
|
||||||
|
assert(reply->type == REDIS_REPLY_INTEGER && reply->integer == 1);
|
||||||
|
freeReplyObject(reply);
|
||||||
|
disconnect(c, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Expect a reply of type INTEGER */
|
||||||
|
void integer_cb(redisAsyncContext *ac, void *r, void *privdata) {
|
||||||
|
redisReply *reply = r;
|
||||||
|
TestState *state = privdata;
|
||||||
|
assert(reply != NULL && reply->type == REDIS_REPLY_INTEGER);
|
||||||
|
state->checkpoint++;
|
||||||
|
if (state->disconnect) async_disconnect(ac);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Subscribe callback for test_pubsub_handling and test_pubsub_handling_resp3:
|
||||||
|
* - a published message triggers an unsubscribe
|
||||||
|
* - a command is sent before the unsubscribe response is received. */
|
||||||
|
void subscribe_cb(redisAsyncContext *ac, void *r, void *privdata) {
|
||||||
|
redisReply *reply = r;
|
||||||
|
TestState *state = privdata;
|
||||||
|
|
||||||
|
assert(reply != NULL &&
|
||||||
|
reply->type == (state->resp3 ? REDIS_REPLY_PUSH : REDIS_REPLY_ARRAY) &&
|
||||||
|
reply->elements == 3);
|
||||||
|
|
||||||
|
if (strcmp(reply->element[0]->str,"subscribe") == 0) {
|
||||||
|
assert(strcmp(reply->element[1]->str,"mychannel") == 0 &&
|
||||||
|
reply->element[2]->str == NULL);
|
||||||
|
publish_msg(state->options,"mychannel","Hello!");
|
||||||
|
} else if (strcmp(reply->element[0]->str,"message") == 0) {
|
||||||
|
assert(strcmp(reply->element[1]->str,"mychannel") == 0 &&
|
||||||
|
strcmp(reply->element[2]->str,"Hello!") == 0);
|
||||||
|
state->checkpoint++;
|
||||||
|
|
||||||
|
/* Unsubscribe after receiving the published message. Send unsubscribe
|
||||||
|
* which should call the callback registered during subscribe */
|
||||||
|
redisAsyncCommand(ac,unexpected_cb,
|
||||||
|
(void*)"unsubscribe should call subscribe_cb()",
|
||||||
|
"unsubscribe");
|
||||||
|
/* Send a regular command after unsubscribing, then disconnect */
|
||||||
|
state->disconnect = 1;
|
||||||
|
redisAsyncCommand(ac,integer_cb,state,"LPUSH mylist foo");
|
||||||
|
|
||||||
|
} else if (strcmp(reply->element[0]->str,"unsubscribe") == 0) {
|
||||||
|
assert(strcmp(reply->element[1]->str,"mychannel") == 0 &&
|
||||||
|
reply->element[2]->str == NULL);
|
||||||
|
} else {
|
||||||
|
printf("Unexpected pubsub command: %s\n", reply->element[0]->str);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Expect a reply of type ARRAY */
|
||||||
|
void array_cb(redisAsyncContext *ac, void *r, void *privdata) {
|
||||||
|
redisReply *reply = r;
|
||||||
|
TestState *state = privdata;
|
||||||
|
assert(reply != NULL && reply->type == REDIS_REPLY_ARRAY);
|
||||||
|
state->checkpoint++;
|
||||||
|
if (state->disconnect) async_disconnect(ac);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Expect a NULL reply */
|
||||||
|
void null_cb(redisAsyncContext *ac, void *r, void *privdata) {
|
||||||
|
(void) ac;
|
||||||
|
assert(r == NULL);
|
||||||
|
TestState *state = privdata;
|
||||||
|
state->checkpoint++;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_pubsub_handling(struct config config) {
|
||||||
|
test("Subscribe, handle published message and unsubscribe: ");
|
||||||
|
/* Setup event dispatcher with a testcase timeout */
|
||||||
|
base = event_base_new();
|
||||||
|
struct event *timeout = evtimer_new(base, timeout_cb, NULL);
|
||||||
|
assert(timeout != NULL);
|
||||||
|
|
||||||
|
evtimer_assign(timeout,base,timeout_cb,NULL);
|
||||||
|
struct timeval timeout_tv = {.tv_sec = 10};
|
||||||
|
evtimer_add(timeout, &timeout_tv);
|
||||||
|
|
||||||
|
/* Connect */
|
||||||
|
redisOptions options = get_redis_tcp_options(config);
|
||||||
|
redisAsyncContext *ac = redisAsyncConnectWithOptions(&options);
|
||||||
|
assert(ac != NULL && ac->err == 0);
|
||||||
|
redisLibeventAttach(ac,base);
|
||||||
|
|
||||||
|
/* Start subscribe */
|
||||||
|
TestState state = {.options = &options};
|
||||||
|
redisAsyncCommand(ac,subscribe_cb,&state,"subscribe mychannel");
|
||||||
|
|
||||||
|
/* Make sure non-subscribe commands are handled */
|
||||||
|
redisAsyncCommand(ac,array_cb,&state,"PING");
|
||||||
|
|
||||||
|
/* Start event dispatching loop */
|
||||||
|
test_cond(event_base_dispatch(base) == 0);
|
||||||
|
event_free(timeout);
|
||||||
|
event_base_free(base);
|
||||||
|
|
||||||
|
/* Verify test checkpoints */
|
||||||
|
assert(state.checkpoint == 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Unexpected push message, will trigger a failure */
|
||||||
|
void unexpected_push_cb(redisAsyncContext *ac, void *r) {
|
||||||
|
(void) ac; (void) r;
|
||||||
|
printf("Unexpected call to the PUSH callback!\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_pubsub_handling_resp3(struct config config) {
|
||||||
|
test("Subscribe, handle published message and unsubscribe using RESP3: ");
|
||||||
|
/* Setup event dispatcher with a testcase timeout */
|
||||||
|
base = event_base_new();
|
||||||
|
struct event *timeout = evtimer_new(base, timeout_cb, NULL);
|
||||||
|
assert(timeout != NULL);
|
||||||
|
|
||||||
|
evtimer_assign(timeout,base,timeout_cb,NULL);
|
||||||
|
struct timeval timeout_tv = {.tv_sec = 10};
|
||||||
|
evtimer_add(timeout, &timeout_tv);
|
||||||
|
|
||||||
|
/* Connect */
|
||||||
|
redisOptions options = get_redis_tcp_options(config);
|
||||||
|
redisAsyncContext *ac = redisAsyncConnectWithOptions(&options);
|
||||||
|
assert(ac != NULL && ac->err == 0);
|
||||||
|
redisLibeventAttach(ac,base);
|
||||||
|
|
||||||
|
/* Not expecting any push messages in this test */
|
||||||
|
redisAsyncSetPushCallback(ac, unexpected_push_cb);
|
||||||
|
|
||||||
|
/* Switch protocol */
|
||||||
|
redisAsyncCommand(ac,NULL,NULL,"HELLO 3");
|
||||||
|
|
||||||
|
/* Start subscribe */
|
||||||
|
TestState state = {.options = &options, .resp3 = 1};
|
||||||
|
redisAsyncCommand(ac,subscribe_cb,&state,"subscribe mychannel");
|
||||||
|
|
||||||
|
/* Make sure non-subscribe commands are handled in RESP3 */
|
||||||
|
redisAsyncCommand(ac,integer_cb,&state,"LPUSH mylist foo");
|
||||||
|
redisAsyncCommand(ac,integer_cb,&state,"LPUSH mylist foo");
|
||||||
|
redisAsyncCommand(ac,integer_cb,&state,"LPUSH mylist foo");
|
||||||
|
/* Handle an array with 3 elements as a non-subscribe command */
|
||||||
|
redisAsyncCommand(ac,array_cb,&state,"LRANGE mylist 0 2");
|
||||||
|
|
||||||
|
/* Start event dispatching loop */
|
||||||
|
test_cond(event_base_dispatch(base) == 0);
|
||||||
|
event_free(timeout);
|
||||||
|
event_base_free(base);
|
||||||
|
|
||||||
|
/* Verify test checkpoints */
|
||||||
|
assert(state.checkpoint == 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Subscribe callback for test_command_timeout_during_pubsub:
|
||||||
|
* - a subscribe response triggers a published message
|
||||||
|
* - the published message triggers a command that times out
|
||||||
|
* - the command timeout triggers a disconnect */
|
||||||
|
void subscribe_with_timeout_cb(redisAsyncContext *ac, void *r, void *privdata) {
|
||||||
|
redisReply *reply = r;
|
||||||
|
TestState *state = privdata;
|
||||||
|
|
||||||
|
/* The non-clean disconnect should trigger the
|
||||||
|
* subscription callback with a NULL reply. */
|
||||||
|
if (reply == NULL) {
|
||||||
|
state->checkpoint++;
|
||||||
|
event_base_loopbreak(base);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(reply->type == (state->resp3 ? REDIS_REPLY_PUSH : REDIS_REPLY_ARRAY) &&
|
||||||
|
reply->elements == 3);
|
||||||
|
|
||||||
|
if (strcmp(reply->element[0]->str,"subscribe") == 0) {
|
||||||
|
assert(strcmp(reply->element[1]->str,"mychannel") == 0 &&
|
||||||
|
reply->element[2]->str == NULL);
|
||||||
|
publish_msg(state->options,"mychannel","Hello!");
|
||||||
|
state->checkpoint++;
|
||||||
|
} else if (strcmp(reply->element[0]->str,"message") == 0) {
|
||||||
|
assert(strcmp(reply->element[1]->str,"mychannel") == 0 &&
|
||||||
|
strcmp(reply->element[2]->str,"Hello!") == 0);
|
||||||
|
state->checkpoint++;
|
||||||
|
|
||||||
|
/* Send a command that will trigger a timeout */
|
||||||
|
redisAsyncCommand(ac,null_cb,state,"DEBUG SLEEP 3");
|
||||||
|
redisAsyncCommand(ac,null_cb,state,"LPUSH mylist foo");
|
||||||
|
} else {
|
||||||
|
printf("Unexpected pubsub command: %s\n", reply->element[0]->str);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_command_timeout_during_pubsub(struct config config) {
|
||||||
|
test("Command timeout during Pub/Sub: ");
|
||||||
|
/* Setup event dispatcher with a testcase timeout */
|
||||||
|
base = event_base_new();
|
||||||
|
struct event *timeout = evtimer_new(base,timeout_cb,NULL);
|
||||||
|
assert(timeout != NULL);
|
||||||
|
|
||||||
|
evtimer_assign(timeout,base,timeout_cb,NULL);
|
||||||
|
struct timeval timeout_tv = {.tv_sec = 10};
|
||||||
|
evtimer_add(timeout,&timeout_tv);
|
||||||
|
|
||||||
|
/* Connect */
|
||||||
|
redisOptions options = get_redis_tcp_options(config);
|
||||||
|
redisAsyncContext *ac = redisAsyncConnectWithOptions(&options);
|
||||||
|
assert(ac != NULL && ac->err == 0);
|
||||||
|
redisLibeventAttach(ac,base);
|
||||||
|
|
||||||
|
/* Configure a command timout */
|
||||||
|
struct timeval command_timeout = {.tv_sec = 2};
|
||||||
|
redisAsyncSetTimeout(ac,command_timeout);
|
||||||
|
|
||||||
|
/* Not expecting any push messages in this test */
|
||||||
|
redisAsyncSetPushCallback(ac,unexpected_push_cb);
|
||||||
|
|
||||||
|
/* Switch protocol */
|
||||||
|
redisAsyncCommand(ac,NULL,NULL,"HELLO 3");
|
||||||
|
|
||||||
|
/* Start subscribe */
|
||||||
|
TestState state = {.options = &options, .resp3 = 1};
|
||||||
|
redisAsyncCommand(ac,subscribe_with_timeout_cb,&state,"subscribe mychannel");
|
||||||
|
|
||||||
|
/* Start event dispatching loop */
|
||||||
|
assert(event_base_dispatch(base) == 0);
|
||||||
|
event_free(timeout);
|
||||||
|
event_base_free(base);
|
||||||
|
|
||||||
|
/* Verify test checkpoints */
|
||||||
|
test_cond(state.checkpoint == 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Subscribe callback for test_pubsub_multiple_channels */
|
||||||
|
void subscribe_channel_a_cb(redisAsyncContext *ac, void *r, void *privdata) {
|
||||||
|
redisReply *reply = r;
|
||||||
|
TestState *state = privdata;
|
||||||
|
|
||||||
|
assert(reply != NULL && reply->type == REDIS_REPLY_ARRAY &&
|
||||||
|
reply->elements == 3);
|
||||||
|
|
||||||
|
if (strcmp(reply->element[0]->str,"subscribe") == 0) {
|
||||||
|
assert(strcmp(reply->element[1]->str,"A") == 0);
|
||||||
|
publish_msg(state->options,"A","Hello!");
|
||||||
|
state->checkpoint++;
|
||||||
|
} else if (strcmp(reply->element[0]->str,"message") == 0) {
|
||||||
|
assert(strcmp(reply->element[1]->str,"A") == 0 &&
|
||||||
|
strcmp(reply->element[2]->str,"Hello!") == 0);
|
||||||
|
state->checkpoint++;
|
||||||
|
|
||||||
|
/* Unsubscribe to channels, including a channel X which we don't subscribe to */
|
||||||
|
redisAsyncCommand(ac,unexpected_cb,
|
||||||
|
(void*)"unsubscribe should not call unexpected_cb()",
|
||||||
|
"unsubscribe B X A");
|
||||||
|
/* Send a regular command after unsubscribing, then disconnect */
|
||||||
|
state->disconnect = 1;
|
||||||
|
redisAsyncCommand(ac,integer_cb,state,"LPUSH mylist foo");
|
||||||
|
} else if (strcmp(reply->element[0]->str,"unsubscribe") == 0) {
|
||||||
|
assert(strcmp(reply->element[1]->str,"A") == 0);
|
||||||
|
state->checkpoint++;
|
||||||
|
} else {
|
||||||
|
printf("Unexpected pubsub command: %s\n", reply->element[0]->str);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Subscribe callback for test_pubsub_multiple_channels */
|
||||||
|
void subscribe_channel_b_cb(redisAsyncContext *ac, void *r, void *privdata) {
|
||||||
|
redisReply *reply = r;
|
||||||
|
TestState *state = privdata;
|
||||||
|
|
||||||
|
assert(reply != NULL && reply->type == REDIS_REPLY_ARRAY &&
|
||||||
|
reply->elements == 3);
|
||||||
|
|
||||||
|
if (strcmp(reply->element[0]->str,"subscribe") == 0) {
|
||||||
|
assert(strcmp(reply->element[1]->str,"B") == 0);
|
||||||
|
state->checkpoint++;
|
||||||
|
} else if (strcmp(reply->element[0]->str,"unsubscribe") == 0) {
|
||||||
|
assert(strcmp(reply->element[1]->str,"B") == 0);
|
||||||
|
state->checkpoint++;
|
||||||
|
} else {
|
||||||
|
printf("Unexpected pubsub command: %s\n", reply->element[0]->str);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Test handling of multiple channels
|
||||||
|
* - subscribe to channel A and B
|
||||||
|
* - a published message on A triggers an unsubscribe of channel B, X and A
|
||||||
|
* where channel X is not subscribed to.
|
||||||
|
* - a command sent after unsubscribe triggers a disconnect */
|
||||||
|
static void test_pubsub_multiple_channels(struct config config) {
|
||||||
|
test("Subscribe to multiple channels: ");
|
||||||
|
/* Setup event dispatcher with a testcase timeout */
|
||||||
|
base = event_base_new();
|
||||||
|
struct event *timeout = evtimer_new(base,timeout_cb,NULL);
|
||||||
|
assert(timeout != NULL);
|
||||||
|
|
||||||
|
evtimer_assign(timeout,base,timeout_cb,NULL);
|
||||||
|
struct timeval timeout_tv = {.tv_sec = 10};
|
||||||
|
evtimer_add(timeout,&timeout_tv);
|
||||||
|
|
||||||
|
/* Connect */
|
||||||
|
redisOptions options = get_redis_tcp_options(config);
|
||||||
|
redisAsyncContext *ac = redisAsyncConnectWithOptions(&options);
|
||||||
|
assert(ac != NULL && ac->err == 0);
|
||||||
|
redisLibeventAttach(ac,base);
|
||||||
|
|
||||||
|
/* Not expecting any push messages in this test */
|
||||||
|
redisAsyncSetPushCallback(ac,unexpected_push_cb);
|
||||||
|
|
||||||
|
/* Start subscribing to two channels */
|
||||||
|
TestState state = {.options = &options};
|
||||||
|
redisAsyncCommand(ac,subscribe_channel_a_cb,&state,"subscribe A");
|
||||||
|
redisAsyncCommand(ac,subscribe_channel_b_cb,&state,"subscribe B");
|
||||||
|
|
||||||
|
/* Start event dispatching loop */
|
||||||
|
assert(event_base_dispatch(base) == 0);
|
||||||
|
event_free(timeout);
|
||||||
|
event_base_free(base);
|
||||||
|
|
||||||
|
/* Verify test checkpoints */
|
||||||
|
test_cond(state.checkpoint == 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Command callback for test_monitor() */
|
||||||
|
void monitor_cb(redisAsyncContext *ac, void *r, void *privdata) {
|
||||||
|
redisReply *reply = r;
|
||||||
|
TestState *state = privdata;
|
||||||
|
|
||||||
|
/* NULL reply is received when BYE triggers a disconnect. */
|
||||||
|
if (reply == NULL) {
|
||||||
|
event_base_loopbreak(base);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(reply != NULL && reply->type == REDIS_REPLY_STATUS);
|
||||||
|
state->checkpoint++;
|
||||||
|
|
||||||
|
if (state->checkpoint == 1) {
|
||||||
|
/* Response from MONITOR */
|
||||||
|
redisContext *c = redisConnectWithOptions(state->options);
|
||||||
|
assert(c != NULL);
|
||||||
|
redisReply *reply = redisCommand(c,"SET first 1");
|
||||||
|
assert(reply->type == REDIS_REPLY_STATUS);
|
||||||
|
freeReplyObject(reply);
|
||||||
|
redisFree(c);
|
||||||
|
} else if (state->checkpoint == 2) {
|
||||||
|
/* Response for monitored command 'SET first 1' */
|
||||||
|
assert(strstr(reply->str,"first") != NULL);
|
||||||
|
redisContext *c = redisConnectWithOptions(state->options);
|
||||||
|
assert(c != NULL);
|
||||||
|
redisReply *reply = redisCommand(c,"SET second 2");
|
||||||
|
assert(reply->type == REDIS_REPLY_STATUS);
|
||||||
|
freeReplyObject(reply);
|
||||||
|
redisFree(c);
|
||||||
|
} else if (state->checkpoint == 3) {
|
||||||
|
/* Response for monitored command 'SET second 2' */
|
||||||
|
assert(strstr(reply->str,"second") != NULL);
|
||||||
|
/* Send QUIT to disconnect */
|
||||||
|
redisAsyncCommand(ac,NULL,NULL,"QUIT");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Test handling of the monitor command
|
||||||
|
* - sends MONITOR to enable monitoring.
|
||||||
|
* - sends SET commands via separate clients to be monitored.
|
||||||
|
* - sends QUIT to stop monitoring and disconnect. */
|
||||||
|
static void test_monitor(struct config config) {
|
||||||
|
test("Enable monitoring: ");
|
||||||
|
/* Setup event dispatcher with a testcase timeout */
|
||||||
|
base = event_base_new();
|
||||||
|
struct event *timeout = evtimer_new(base, timeout_cb, NULL);
|
||||||
|
assert(timeout != NULL);
|
||||||
|
|
||||||
|
evtimer_assign(timeout,base,timeout_cb,NULL);
|
||||||
|
struct timeval timeout_tv = {.tv_sec = 10};
|
||||||
|
evtimer_add(timeout, &timeout_tv);
|
||||||
|
|
||||||
|
/* Connect */
|
||||||
|
redisOptions options = get_redis_tcp_options(config);
|
||||||
|
redisAsyncContext *ac = redisAsyncConnectWithOptions(&options);
|
||||||
|
assert(ac != NULL && ac->err == 0);
|
||||||
|
redisLibeventAttach(ac,base);
|
||||||
|
|
||||||
|
/* Not expecting any push messages in this test */
|
||||||
|
redisAsyncSetPushCallback(ac,unexpected_push_cb);
|
||||||
|
|
||||||
|
/* Start monitor */
|
||||||
|
TestState state = {.options = &options};
|
||||||
|
redisAsyncCommand(ac,monitor_cb,&state,"monitor");
|
||||||
|
|
||||||
|
/* Start event dispatching loop */
|
||||||
|
test_cond(event_base_dispatch(base) == 0);
|
||||||
|
event_free(timeout);
|
||||||
|
event_base_free(base);
|
||||||
|
|
||||||
|
/* Verify test checkpoints */
|
||||||
|
assert(state.checkpoint == 3);
|
||||||
|
}
|
||||||
|
#endif /* HIREDIS_TEST_ASYNC */
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
struct config cfg = {
|
struct config cfg = {
|
||||||
.tcp = {
|
.tcp = {
|
||||||
@ -1401,6 +1999,24 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HIREDIS_TEST_ASYNC
|
||||||
|
printf("\nTesting asynchronous API against TCP connection (%s:%d):\n", cfg.tcp.host, cfg.tcp.port);
|
||||||
|
cfg.type = CONN_TCP;
|
||||||
|
|
||||||
|
int major;
|
||||||
|
redisContext *c = do_connect(cfg);
|
||||||
|
get_redis_version(c, &major, NULL);
|
||||||
|
disconnect(c, 0);
|
||||||
|
|
||||||
|
test_pubsub_handling(cfg);
|
||||||
|
test_pubsub_multiple_channels(cfg);
|
||||||
|
test_monitor(cfg);
|
||||||
|
if (major >= 6) {
|
||||||
|
test_pubsub_handling_resp3(cfg);
|
||||||
|
test_command_timeout_during_pubsub(cfg);
|
||||||
|
}
|
||||||
|
#endif /* HIREDIS_TEST_ASYNC */
|
||||||
|
|
||||||
if (test_inherit_fd) {
|
if (test_inherit_fd) {
|
||||||
printf("\nTesting against inherited fd (%s): ", cfg.unix_sock.path);
|
printf("\nTesting against inherited fd (%s): ", cfg.unix_sock.path);
|
||||||
if (test_unix_socket) {
|
if (test_unix_socket) {
|
||||||
|
Loading…
Reference in New Issue
Block a user