Feature: SSL Decoder create version

This commit is contained in:
liuxueli
2024-08-05 10:04:16 +00:00
parent e7ddd60836
commit 97107b1b0a
49 changed files with 27266 additions and 2 deletions

5
.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
.vscode/
build*
SI/*
cmake-build-*
*.si4project

72
CMakeLists.txt Normal file
View File

@@ -0,0 +1,72 @@
cmake_minimum_required (VERSION 3.0)
set(lib_name ssl_decoder)
project (${lib_name})
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
include(Version)
set(CMAKE_MACOSX_RPATH 0)
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -Wall)
find_program(CMAKE_CXX_CPPCHECK NAMES cppcheck)
if (CMAKE_CXX_CPPCHECK)
list(
APPEND CMAKE_CXX_CPPCHECK
"--enable=all"
"--error-exitcode=1"
"--suppress=unusedFunction"
"--suppress=missingInclude"
"--suppress=uselessAssignmentPtrArg"
"--suppress=unmatchedSuppression"
"--suppress=internalAstError"
"--suppress=constParameter"
"--suppress=variableScope"
"--suppress=unreadVariable"
"--suppress=unusedStructMember"
"--suppress=noExplicitConstructor"
"--suppress=*:${PROJECT_SOURCE_DIR}/deps/toml/*"
"--suppress=*:${PROJECT_SOURCE_DIR}/deps/yyjson/*"
)
set(CMAKE_C_CPPCHECK ${CMAKE_CXX_CPPCHECK})
else()
message(FATAL_ERROR "Could not find the program cppcheck.")
endif()
#for ASAN
set(ASAN_OPTION "OFF" CACHE STRING " set asan type chosen by the user, using OFF as default")
set_property(CACHE ASAN_OPTION PROPERTY STRINGS OFF ADDRESS THREAD)
message(STATUS "ASAN_OPTION='${ASAN_OPTION}'")
if(ASAN_OPTION MATCHES "ADDRESS")
set(CMAKE_C_FLAGS "${CMAKADDRESS} -g -DCMAKE_BUILD_TYPE=Debug -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DCMAKE_BUILD_TYPE=Debug -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan")
elseif(ASAN_OPTION MATCHES "THREAD")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -DCMAKE_BUILD_TYPE=Debug -fsanitize=thread -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DCMAKE_BUILD_TYPE=Debug -fsanitize=thread -fno-omit-frame-pointer")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan")
endif()
# end of for ASAN
include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(/opt/MESA/include/)
include_directories(/opt/MESA/include/MESA/)
include_directories(/opt/tsg/framework/include/)
set(CMAKE_INSTALL_PREFIX /opt/tsg/)
enable_testing()
add_subdirectory(src)
add_subdirectory(vendor)
add_subdirectory(test)
install(FILES bin/ssl_decoder.toml DESTINATION ${CMAKE_INSTALL_PREFIX}/sapp/etc/ssl/ COMPONENT PROFILE)
install(FILES bin/ssl_decoder_local_stat.sh DESTINATION ${CMAKE_INSTALL_PREFIX}/framework/bin/ COMPONENT PROFILE)
install(FILES include/ssl_decoder.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/decoder/ COMPONENT HEADER)
include(Package)

View File

@@ -10,8 +10,6 @@ Already a pro? Just edit this README.md and make it your own. Want to make it ea
## Add your files ## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
``` ```
cd existing_repo cd existing_repo

34
autorelease.sh Normal file
View File

@@ -0,0 +1,34 @@
#!/bin/sh
if [ $# -lt 8 ] ; then
echo "USAGE: ./autorelease.sh [API_V4_URL] [PROJECT_URL]
[PROJECT_ID] [TOKEN]
[COMMIT_TAG] [JOB] [PROJECT_NAME] [USER_DEFINE]"
echo "$1; $2; $3; $4; $5; $6; $7; $8"
exit 1;
fi
CI_API_V4_URL=$1
CI_PROJECT_URL=$2
CI_PROJECT_ID=$3
CI_TOKEN=$4
CI_COMMIT_TAG=$5
ARTIFACTS_JOB=$6
CI_PROJECT_NAME=$7
USER_DEFINE=$8
res=`echo -e "curl --header \"PRIVATE-TOKEN: $CI_TOKEN\" $CI_API_V4_URL/projects/$CI_PROJECT_ID/releases/$CI_COMMIT_TAG -o /dev/null -s -w %{http_code}"| /bin/bash`
if [[ $res == "200" ]]; then
eval $(echo -e "curl --request POST --header \"PRIVATE-TOKEN: $CI_TOKEN\" \
--data name=\"$CI_PROJECT_NAME-$USER_DEFINE-$CI_COMMIT_TAG.zip\" \
--data url=\"$CI_PROJECT_URL/-/jobs/artifacts/$CI_COMMIT_TAG/download?job=$ARTIFACTS_JOB\"\
$CI_API_V4_URL/projects/$CI_PROJECT_ID/releases/$CI_COMMIT_TAG/assets/links")
else
eval $(echo -e "curl --header 'Content-Type: application/json' --header \
\"PRIVATE-TOKEN: $CI_TOKEN\" --data '{ \"name\": \"$CI_COMMIT_TAG\", \
\"tag_name\": \"$CI_COMMIT_TAG\", \"description\": \"auto_release\",\
\"assets\": { \"links\": [{ \"name\": \
\"$CI_PROJECT_NAME-$USER_DEFINE-$CI_COMMIT_TAG.zip\", \"url\": \
\"$CI_PROJECT_URL/-/jobs/artifacts/$CI_COMMIT_TAG/download?job=$ARTIFACTS_JOB\"\
}] } }' --request POST $CI_API_V4_URL/projects/$CI_PROJECT_ID/releases/")
fi

1268
autorevision.sh Normal file

File diff suppressed because it is too large Load Diff

12
bin/ssl_decoder.toml Normal file
View File

@@ -0,0 +1,12 @@
[decoder]
[decoder.ssl]
port=[443]
[decoder.ssl.limited]
[decoder.ssl.local_stat]
# stat_per_thread_enable value in [yes,no]
stat_per_thread_enable="no"
stat_name="SSL_DECODER"
stat_interval_time_s=5
stat_output="metrics/ssl_decoder_local_stat.json"

View File

@@ -0,0 +1,36 @@
#!/bin/bash
ARGC=$#
EXPORTER=/opt/tsg/framework/bin/fieldstat_exporter.py
TARGET=/opt/tsg/sapp/metrics/ssl_decoder_local_stat.json
case $1 in
-h|--help)
echo "$0"
echo "Usage: [exporter] [target]"
echo " exporter: path of exporter, default is $EXPORTER"
echo " target: path of target file, default is $TARGET"
exit 0
;;
esac
case $ARGC in
1)
EXPORTER=$1
;;
2)
EXPORTER=$1
TARGET=$2
;;
esac
#new version
python3 $EXPORTER local -j $TARGET -e -t '
{{"ssl decoder message"}}
{{ print_tables("message_type", ["send", "#Speed<send>", "recv", "#Speed<recv>"], True )}} {{"\n"}}
{{"ssl decoder memory"}}
{{ print_tables("memory", ["new", "#Speed<new>", "free", "#Speed<free>"], True )}} {{"\n"}}
{{"ssl decoder decode status"}}
{{ print_tables("section", ["ok", "#Speed<ok>", "error", "#Speed<error>"], True )}} {{"\n"}}
'

48
ci/get-nprocessors.sh Normal file
View File

@@ -0,0 +1,48 @@
#!/usr/bin/env bash
# Copyright 2017 Google Inc.
# 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 Google Inc. 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.
# This file is typically sourced by another script.
# if possible, ask for the precise number of processors,
# otherwise take 2 processors as reasonable default; see
# https://docs.travis-ci.com/user/speeding-up-the-build/#Makefile-optimization
if [ -x /usr/bin/getconf ]; then
NPROCESSORS=$(/usr/bin/getconf _NPROCESSORS_ONLN)
else
NPROCESSORS=2
fi
# as of 2017-09-04 Travis CI reports 32 processors, but GCC build
# crashes if parallelized too much (maybe memory consumption problem),
# so limit to 4 processors for the time being.
if [ $NPROCESSORS -gt 4 ] ; then
echo "$0:Note: Limiting processors to use by make from $NPROCESSORS to 4."
NPROCESSORS=4
fi

View File

@@ -0,0 +1,3 @@
#!/usr/bin/env sh
set -evx
echo "machine ${PULP3_SERVER_URL}\nlogin ${PULP3_SERVER_LOGIN}\npassword ${PULP3_SERVER_PASSWORD}\n" > ~/.netrc

68
ci/travis.sh Normal file
View File

@@ -0,0 +1,68 @@
#!/usr/bin/env sh
set -evx
chmod +x ci/get-nprocessors.sh
. ci/get-nprocessors.sh
# if possible, ask for the precise number of processors,
# otherwise take 2 processors as reasonable default; see
# https://docs.travis-ci.com/user/speeding-up-the-build/#Makefile-optimization
if [ -x /usr/bin/getconf ]; then
NPROCESSORS=$(/usr/bin/getconf _NPROCESSORS_ONLN)
else
NPROCESSORS=2
fi
# as of 2017-09-04 Travis CI reports 32 processors, but GCC build
# crashes if parallelized too much (maybe memory consumption problem),
# so limit to 4 processors for the time being.
if [ $NPROCESSORS -gt 4 ] ; then
echo "$0:Note: Limiting processors to use by make from $NPROCESSORS to 4."
NPROCESSORS=4
fi
# Tell make to use the processors. No preceding '-' required.
MAKEFLAGS="j${NPROCESSORS}"
export MAKEFLAGS
env | sort
# Set default values to OFF for these variables if not specified.
: "${NO_EXCEPTION:=OFF}"
: "${NO_RTTI:=OFF}"
: "${COMPILER_IS_GNUCXX:=OFF}"
# Install dependency from YUM
if [ -n "${INSTALL_DEPENDENCY_FRAMEWORK}" ]; then
yum install -y $INSTALL_DEPENDENCY_FRAMEWORK
source /etc/profile.d/framework.sh
fi
if [ -n "${INSTALL_DEPENDENCY_PLATFORM}" ]; then
yum install -y $INSTALL_DEPENDENCY_PLATFORM
fi
if [ $ASAN_OPTION ] && [ -f "/opt/rh/devtoolset-7/enable" ] ;then
source /opt/rh/devtoolset-7/enable
fi
mkdir build || true
cd build
cmake3 -DCMAKE_CXX_FLAGS=$CXX_FLAGS \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX \
-DASAN_OPTION=$ASAN_OPTION \
-DVERSION_DAILY_BUILD=$TESTING_VERSION_BUILD \
..
make
if [ -n "${PACKAGE}" ]; then
make package
fi
if [ -n "${UPLOAD_RPM}" ]; then
cp ~/rpm_upload_tools.py ./
python3 rpm_upload_tools.py ${PULP3_REPO_NAME} ${PULP3_DIST_NAME} *.rpm
fi

5
cmake/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
build
__view
*.o
*.so
*.a

56
cmake/Package.cmake Normal file
View File

@@ -0,0 +1,56 @@
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(MY_RPM_NAME_PREFIX "${lib_name}-debug")
else()
set(MY_RPM_NAME_PREFIX "${lib_name}")
endif()
message(STATUS "Package: ${MY_RPM_NAME_PREFIX}")
set(CPACK_PACKAGE_VECDOR "MESA")
set(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}.${VERSION_BUILD}")
set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
set(CPACK_PACKAGE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_BUILD}")
execute_process(COMMAND sh changelog.sh ${CMAKE_BINARY_DIR} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/cmake)
SET(CPACK_RPM_CHANGELOG_FILE ${CMAKE_BINARY_DIR}/changelog.txt)
# RPM Build
set(CPACK_GENERATOR "RPM")
set(CPACK_RPM_AUTO_GENERATED_FILE_NAME ON)
set(CPACK_RPM_FILE_NAME "RPM-DEFAULT")
set(CPACK_RPM_PACKAGE_VENDOR "MESA")
set(CPACK_RPM_PACKAGE_AUTOREQPROV "yes")
set(CPACK_RPM_PACKAGE_RELEASE_DIST "on")
set(CPACK_RPM_DEBUGINFO_PACKAGE "on")
set(CPACK_RPM_COMPONENT_INSTALL ON)
set(CPACK_COMPONENTS_IGNORE_GROUPS 1)
set(CPACK_COMPONENTS_GROUPING ONE_PER_GROUP)
set(CPACK_COMPONENT_HEADER_DISPLAY_NAME "develop")
set(CPACK_COMPONENT_LIBRARIES_REQUIRED TRUE)
set(CPACK_RPM_LIBRARIES_PACKAGE_NAME ${MY_RPM_NAME_PREFIX})
set(CPACK_COMPONENT_LIBRARIES_GROUP "LIBRARIES")
set(CPACK_COMPONENT_PROFILE_GROUP "LIBRARIES")
set(CPACK_COMPONENT_HEADER_REQUIRED TRUE)
set(CPACK_RPM_HEADER_PACKAGE_NAME "${MY_RPM_NAME_PREFIX}-devel")
set(CPACK_COMPONENT_HEADER_GROUP "HEADER")
set(CPACK_RPM_HEADER_PACKAGE_REQUIRES_PRE ${CPACK_RPM_LIBRARIES_PACKAGE_NAME})
set(CPACK_RPM_HEADER_PACKAGE_CONFLICTS ${CPACK_RPM_HEADER_PACKAGE_NAME})
set(CPACK_COMPONENTS_ALL LIBRARIES HEADER PROFILE)
SET(CPACK_RPM_LIBRARIES_PRE_INSTALL_SCRIPT_FILE "${PROJECT_SOURCE_DIR}/cmake/preInstall.sh")
SET(CPACK_RPM_LIBRARIES_PRE_UNINSTALL_SCRIPT_FILE "${PROJECT_SOURCE_DIR}/cmake/preUninstall.sh")
set(CPACK_BUILD_SOURCE_DIRS "${CMAKE_SOURCE_DIR}")
# Must uninstall the debug package before install release package
set(CPACK_RPM_PACKAGE_CONFLICTS ${MY_RPM_NAME_PREFIX})
# set(CPACK_STRIP_FILES TRUE)
include(CPack)

54
cmake/Version.cmake Normal file
View File

@@ -0,0 +1,54 @@
# Using autorevision.sh to generate version information
set(__SOURCE_AUTORESIVISION ${CMAKE_SOURCE_DIR}/autorevision.sh)
set(__AUTORESIVISION ${CMAKE_BINARY_DIR}/autorevision.sh)
set(__VERSION_CACHE ${CMAKE_BINARY_DIR}/version.txt)
set(__VERSION_CONFIG ${CMAKE_BINARY_DIR}/version.cmake)
file(COPY ${__SOURCE_AUTORESIVISION} DESTINATION ${CMAKE_BINARY_DIR}
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE)
# execute autorevision.sh to generate version information
execute_process(COMMAND ${__AUTORESIVISION} -t cmake -o ${__VERSION_CACHE}
OUTPUT_FILE ${__VERSION_CONFIG} ERROR_QUIET)
include(${__VERSION_CONFIG})
# extract major, minor, patch version from git tag
string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VCS_TAG}")
string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VCS_TAG}")
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VCS_TAG}")
string(REGEX REPLACE "[T\\:\\+\\-]" "" VERSION_DATE "${VCS_DATE}")
if(VERSION_DAILY_BUILD)
set(VERSION_PATCH ${VERSION_PATCH}.${VERSION_DATE})
endif()
if(NOT VERSION_MAJOR)
set(VERSION_MAJOR 1)
endif()
if(NOT VERSION_MINOR)
set(VERSION_MINOR 0)
endif()
if(NOT VERSION_PATCH)
set(VERSION_PATCH 0)
endif()
set(VERSION "${VERSION_MAJOR}_${VERSION_MINOR}_${VERSION_PATCH}")
set(VERSION_BUILD "${VCS_SHORT_HASH}")
# print information
message(STATUS "Version: ${VERSION}-${VERSION_BUILD}")
option(DEFINE_GIT_VERSION "Set DEFINE_GIT_VERSION to TRUE or FALSE" TRUE)
if(DEFINE_GIT_VERSION)
set(GIT_VERSION
"${VERSION}-${CMAKE_BUILD_TYPE}-${VERSION_BUILD}-${VCS_BRANCH}-${VCS_TAG}-${VCS_DATE}")
string(REGEX REPLACE "[-:+/\\.]" "_" GIT_VERSION ${GIT_VERSION})
add_definitions(-DGIT_VERSION=${GIT_VERSION})
endif()

4
cmake/changelog.sh Normal file
View File

@@ -0,0 +1,4 @@
#!/bin/sh
work_path=$1
branch=`git status | grep branch | awk '{print $NF}'`
git log --branches=$branch --no-merges --date=local --show-signature --pretty="* %ad %an %ae %nhash: %H%ncommit:%n%B" | awk -F"-" '{print "- "$0}' | sed 's/- \*/\*/g' | sed 's/- $//g' | sed 's/-/ -/g' | sed 's/[0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}//g' > $work_path/changelog.txt

14
cmake/preInstall.sh Normal file
View File

@@ -0,0 +1,14 @@
#!/bin/sh
INSTALL_PREFIX=${RPM_INSTALL_PREFIX}/sapp/
mkdir ${RPM_INSTALL_PREFIX}/sapp/stellar_plugin/ -p
touch ${RPM_INSTALL_PREFIX}/sapp/stellar_plugin/spec.toml
if [[ -z `grep -rn 'ssl_decoder' ${RPM_INSTALL_PREFIX}/sapp/stellar_plugin/spec.toml` ]];then
echo -e "" >> ${RPM_INSTALL_PREFIX}/sapp/stellar_plugin/spec.toml
echo -e "[[plugin]]" >> ${RPM_INSTALL_PREFIX}/sapp/stellar_plugin/spec.toml
echo -e "path=\"./stellar_plugin/ssl_decoder.so\"" >> ${RPM_INSTALL_PREFIX}/sapp/stellar_plugin//spec.toml
echo -e "init=\"ssl_decoder_init\"" >> ${RPM_INSTALL_PREFIX}/sapp/stellar_plugin/spec.toml
echo -e "exit=\"ssl_decoder_exit\"" >> ${RPM_INSTALL_PREFIX}/sapp/stellar_plugin/spec.toml
fi

13
cmake/preUninstall.sh Normal file
View File

@@ -0,0 +1,13 @@
#!/bin/sh
if [ $1 == 0 ]; then
DST=${RPM_INSTALL_PREFIX}
mkdir -p ${DST}/plug/protocol/
touch ${DST}/plug/conflist.inf
mkdir -p ${DST}/etc/
touch ${DST}/etc/entrylist.conf
sed -i '/ssl.inf/d' ${DST}/plug/conflist.inf
sed -i '/ssl/d' ${DST}/etc/entrylist.conf
fi

3
deps/toml/CMakeLists.txt vendored Normal file
View File

@@ -0,0 +1,3 @@
set(CMAKE_C_FLAGS "-std=c99")
add_definitions(-fPIC)
add_library(toml STATIC toml.c)

2379
deps/toml/toml.c vendored Normal file

File diff suppressed because it is too large Load Diff

175
deps/toml/toml.h vendored Normal file
View File

@@ -0,0 +1,175 @@
/*
MIT License
Copyright (c) CK Tan
https://github.com/cktan/tomlc99
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef TOML_H
#define TOML_H
#ifdef _MSC_VER
#pragma warning(disable: 4996)
#endif
#include <stdint.h>
#include <stdio.h>
#ifdef __cplusplus
#define TOML_EXTERN extern "C"
#else
#define TOML_EXTERN extern
#endif
typedef struct toml_timestamp_t toml_timestamp_t;
typedef struct toml_table_t toml_table_t;
typedef struct toml_array_t toml_array_t;
typedef struct toml_datum_t toml_datum_t;
/* Parse a file. Return a table on success, or 0 otherwise.
* Caller must toml_free(the-return-value) after use.
*/
TOML_EXTERN toml_table_t *toml_parse_file(FILE *fp, char *errbuf, int errbufsz);
/* Parse a string containing the full config.
* Return a table on success, or 0 otherwise.
* Caller must toml_free(the-return-value) after use.
*/
TOML_EXTERN toml_table_t *toml_parse(char *conf, /* NUL terminated, please. */
char *errbuf, int errbufsz);
/* Free the table returned by toml_parse() or toml_parse_file(). Once
* this function is called, any handles accessed through this tab
* directly or indirectly are no longer valid.
*/
TOML_EXTERN void toml_free(toml_table_t *tab);
/* Timestamp types. The year, month, day, hour, minute, second, z
* fields may be NULL if they are not relevant. e.g. In a DATE
* type, the hour, minute, second and z fields will be NULLs.
*/
struct toml_timestamp_t {
struct { /* internal. do not use. */
int year, month, day;
int hour, minute, second, millisec;
char z[10];
} __buffer;
int *year, *month, *day;
int *hour, *minute, *second, *millisec;
char *z;
};
/*-----------------------------------------------------------------
* Enhanced access methods
*/
struct toml_datum_t {
int ok;
union {
toml_timestamp_t *ts; /* ts must be freed after use */
char *s; /* string value. s must be freed after use */
int b; /* bool value */
int64_t i; /* int value */
double d; /* double value */
} u;
};
/* on arrays: */
/* ... retrieve size of array. */
TOML_EXTERN int toml_array_nelem(const toml_array_t *arr);
/* ... retrieve values using index. */
TOML_EXTERN toml_datum_t toml_string_at(const toml_array_t *arr, int idx);
TOML_EXTERN toml_datum_t toml_bool_at(const toml_array_t *arr, int idx);
TOML_EXTERN toml_datum_t toml_int_at(const toml_array_t *arr, int idx);
TOML_EXTERN toml_datum_t toml_double_at(const toml_array_t *arr, int idx);
TOML_EXTERN toml_datum_t toml_timestamp_at(const toml_array_t *arr, int idx);
/* ... retrieve array or table using index. */
TOML_EXTERN toml_array_t *toml_array_at(const toml_array_t *arr, int idx);
TOML_EXTERN toml_table_t *toml_table_at(const toml_array_t *arr, int idx);
/* on tables: */
/* ... retrieve the key in table at keyidx. Return 0 if out of range. */
TOML_EXTERN const char *toml_key_in(const toml_table_t *tab, int keyidx);
/* ... returns 1 if key exists in tab, 0 otherwise */
TOML_EXTERN int toml_key_exists(const toml_table_t *tab, const char *key);
/* ... retrieve values using key. */
TOML_EXTERN toml_datum_t toml_string_in(const toml_table_t *arr,
const char *key);
TOML_EXTERN toml_datum_t toml_bool_in(const toml_table_t *arr, const char *key);
TOML_EXTERN toml_datum_t toml_int_in(const toml_table_t *arr, const char *key);
TOML_EXTERN toml_datum_t toml_double_in(const toml_table_t *arr,
const char *key);
TOML_EXTERN toml_datum_t toml_timestamp_in(const toml_table_t *arr,
const char *key);
/* .. retrieve array or table using key. */
TOML_EXTERN toml_array_t *toml_array_in(const toml_table_t *tab,
const char *key);
TOML_EXTERN toml_table_t *toml_table_in(const toml_table_t *tab,
const char *key);
/*-----------------------------------------------------------------
* lesser used
*/
/* Return the array kind: 't'able, 'a'rray, 'v'alue, 'm'ixed */
TOML_EXTERN char toml_array_kind(const toml_array_t *arr);
/* For array kind 'v'alue, return the type of values
i:int, d:double, b:bool, s:string, t:time, D:date, T:timestamp, 'm'ixed
0 if unknown
*/
TOML_EXTERN char toml_array_type(const toml_array_t *arr);
/* Return the key of an array */
TOML_EXTERN const char *toml_array_key(const toml_array_t *arr);
/* Return the number of key-values in a table */
TOML_EXTERN int toml_table_nkval(const toml_table_t *tab);
/* Return the number of arrays in a table */
TOML_EXTERN int toml_table_narr(const toml_table_t *tab);
/* Return the number of sub-tables in a table */
TOML_EXTERN int toml_table_ntab(const toml_table_t *tab);
/* Return the key of a table*/
TOML_EXTERN const char *toml_table_key(const toml_table_t *tab);
/*--------------------------------------------------------------
* misc
*/
TOML_EXTERN int toml_utf8_to_ucs(const char *orig, int len, int64_t *ret);
TOML_EXTERN int toml_ucs_to_utf8(int64_t code, char buf[6]);
TOML_EXTERN void toml_set_memutil(void *(*xxmalloc)(size_t),
void (*xxfree)(void *));
/*--------------------------------------------------------------
* deprecated
*/
/* A raw value, must be processed by toml_rto* before using. */
typedef const char *toml_raw_t;
TOML_EXTERN toml_raw_t toml_raw_in(const toml_table_t *tab, const char *key);
TOML_EXTERN toml_raw_t toml_raw_at(const toml_array_t *arr, int idx);
TOML_EXTERN int toml_rtos(toml_raw_t s, char **ret);
TOML_EXTERN int toml_rtob(toml_raw_t s, int *ret);
TOML_EXTERN int toml_rtoi(toml_raw_t s, int64_t *ret);
TOML_EXTERN int toml_rtod(toml_raw_t s, double *ret);
TOML_EXTERN int toml_rtod_ex(toml_raw_t s, double *ret, char *buf, int buflen);
TOML_EXTERN int toml_rtots(toml_raw_t s, toml_timestamp_t *ret);
#endif /* TOML_H */

247
deps/uthash/utarray.h vendored Normal file
View File

@@ -0,0 +1,247 @@
/*
Copyright (c) 2008-2018, Troy D. Hanson http://troydhanson.github.com/uthash/
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.
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.
*/
/* a dynamic array implementation using macros
*/
#ifndef UTARRAY_H
#define UTARRAY_H
#define UTARRAY_VERSION 2.1.0
#include <stddef.h> /* size_t */
#include <string.h> /* memset, etc */
#include <stdlib.h> /* exit */
#ifdef __GNUC__
#define UTARRAY_UNUSED __attribute__((__unused__))
#else
#define UTARRAY_UNUSED
#endif
#ifdef oom
#error "The name of macro 'oom' has been changed to 'utarray_oom'. Please update your code."
#define utarray_oom() oom()
#endif
#ifndef utarray_oom
#define utarray_oom() exit(-1)
#endif
typedef void (ctor_f)(void *dst, const void *src);
typedef void (dtor_f)(void *elt);
typedef void (init_f)(void *elt);
typedef struct {
size_t sz;
init_f *init;
ctor_f *copy;
dtor_f *dtor;
} UT_icd;
typedef struct {
unsigned i,n;/* i: index of next available slot, n: num slots */
UT_icd icd; /* initializer, copy and destructor functions */
char *d; /* n slots of size icd->sz*/
} UT_array;
#define utarray_init(a,_icd) do { \
memset(a,0,sizeof(UT_array)); \
(a)->icd = *(_icd); \
} while(0)
#define utarray_done(a) do { \
if ((a)->n) { \
if ((a)->icd.dtor) { \
unsigned _ut_i; \
for(_ut_i=0; _ut_i < (a)->i; _ut_i++) { \
(a)->icd.dtor(utarray_eltptr(a,_ut_i)); \
} \
} \
free((a)->d); \
} \
(a)->n=0; \
} while(0)
#define utarray_new(a,_icd) do { \
(a) = (UT_array*)malloc(sizeof(UT_array)); \
if ((a) == NULL) { \
utarray_oom(); \
} \
utarray_init(a,_icd); \
} while(0)
#define utarray_free(a) do { \
utarray_done(a); \
free(a); \
} while(0)
#define utarray_reserve(a,by) do { \
if (((a)->i+(by)) > (a)->n) { \
char *utarray_tmp; \
while (((a)->i+(by)) > (a)->n) { (a)->n = ((a)->n ? (2*(a)->n) : 8); } \
utarray_tmp=(char*)realloc((a)->d, (a)->n*(a)->icd.sz); \
if (utarray_tmp == NULL) { \
utarray_oom(); \
} \
(a)->d=utarray_tmp; \
} \
} while(0)
#define utarray_push_back(a,p) do { \
utarray_reserve(a,1); \
if ((a)->icd.copy) { (a)->icd.copy( _utarray_eltptr(a,(a)->i++), p); } \
else { memcpy(_utarray_eltptr(a,(a)->i++), p, (a)->icd.sz); }; \
} while(0)
#define utarray_pop_back(a) do { \
if ((a)->icd.dtor) { (a)->icd.dtor( _utarray_eltptr(a,--((a)->i))); } \
else { (a)->i--; } \
} while(0)
#define utarray_extend_back(a) do { \
utarray_reserve(a,1); \
if ((a)->icd.init) { (a)->icd.init(_utarray_eltptr(a,(a)->i)); } \
else { memset(_utarray_eltptr(a,(a)->i),0,(a)->icd.sz); } \
(a)->i++; \
} while(0)
#define utarray_len(a) ((a)->i)
#define utarray_eltptr(a,j) (((j) < (a)->i) ? _utarray_eltptr(a,j) : NULL)
#define _utarray_eltptr(a,j) ((void*)((a)->d + ((a)->icd.sz * (j))))
#define utarray_insert(a,p,j) do { \
if ((j) > (a)->i) utarray_resize(a,j); \
utarray_reserve(a,1); \
if ((j) < (a)->i) { \
memmove( _utarray_eltptr(a,(j)+1), _utarray_eltptr(a,j), \
((a)->i - (j))*((a)->icd.sz)); \
} \
if ((a)->icd.copy) { (a)->icd.copy( _utarray_eltptr(a,j), p); } \
else { memcpy(_utarray_eltptr(a,j), p, (a)->icd.sz); }; \
(a)->i++; \
} while(0)
#define utarray_inserta(a,w,j) do { \
if (utarray_len(w) == 0) break; \
if ((j) > (a)->i) utarray_resize(a,j); \
utarray_reserve(a,utarray_len(w)); \
if ((j) < (a)->i) { \
memmove(_utarray_eltptr(a,(j)+utarray_len(w)), \
_utarray_eltptr(a,j), \
((a)->i - (j))*((a)->icd.sz)); \
} \
if ((a)->icd.copy) { \
unsigned _ut_i; \
for(_ut_i=0;_ut_i<(w)->i;_ut_i++) { \
(a)->icd.copy(_utarray_eltptr(a, (j) + _ut_i), _utarray_eltptr(w, _ut_i)); \
} \
} else { \
memcpy(_utarray_eltptr(a,j), _utarray_eltptr(w,0), \
utarray_len(w)*((a)->icd.sz)); \
} \
(a)->i += utarray_len(w); \
} while(0)
#define utarray_resize(dst,num) do { \
unsigned _ut_i; \
if ((dst)->i > (unsigned)(num)) { \
if ((dst)->icd.dtor) { \
for (_ut_i = (num); _ut_i < (dst)->i; ++_ut_i) { \
(dst)->icd.dtor(_utarray_eltptr(dst, _ut_i)); \
} \
} \
} else if ((dst)->i < (unsigned)(num)) { \
utarray_reserve(dst, (num) - (dst)->i); \
if ((dst)->icd.init) { \
for (_ut_i = (dst)->i; _ut_i < (unsigned)(num); ++_ut_i) { \
(dst)->icd.init(_utarray_eltptr(dst, _ut_i)); \
} \
} else { \
memset(_utarray_eltptr(dst, (dst)->i), 0, (dst)->icd.sz*((num) - (dst)->i)); \
} \
} \
(dst)->i = (num); \
} while(0)
#define utarray_concat(dst,src) do { \
utarray_inserta(dst, src, utarray_len(dst)); \
} while(0)
#define utarray_erase(a,pos,len) do { \
if ((a)->icd.dtor) { \
unsigned _ut_i; \
for (_ut_i = 0; _ut_i < (len); _ut_i++) { \
(a)->icd.dtor(utarray_eltptr(a, (pos) + _ut_i)); \
} \
} \
if ((a)->i > ((pos) + (len))) { \
memmove(_utarray_eltptr(a, pos), _utarray_eltptr(a, (pos) + (len)), \
((a)->i - ((pos) + (len))) * (a)->icd.sz); \
} \
(a)->i -= (len); \
} while(0)
#define utarray_renew(a,u) do { \
if (a) utarray_clear(a); \
else utarray_new(a, u); \
} while(0)
#define utarray_clear(a) do { \
if ((a)->i > 0) { \
if ((a)->icd.dtor) { \
unsigned _ut_i; \
for(_ut_i=0; _ut_i < (a)->i; _ut_i++) { \
(a)->icd.dtor(_utarray_eltptr(a, _ut_i)); \
} \
} \
(a)->i = 0; \
} \
} while(0)
#define utarray_sort(a,cmp) do { \
qsort((a)->d, (a)->i, (a)->icd.sz, cmp); \
} while(0)
#define utarray_find(a,v,cmp) bsearch((v),(a)->d,(a)->i,(a)->icd.sz,cmp)
#define utarray_front(a) (((a)->i) ? (_utarray_eltptr(a,0)) : NULL)
#define utarray_next(a,e) (((e)==NULL) ? utarray_front(a) : (((a)->i != utarray_eltidx(a,e)+1) ? _utarray_eltptr(a,utarray_eltidx(a,e)+1) : NULL))
#define utarray_prev(a,e) (((e)==NULL) ? utarray_back(a) : ((utarray_eltidx(a,e) != 0) ? _utarray_eltptr(a,utarray_eltidx(a,e)-1) : NULL))
#define utarray_back(a) (((a)->i) ? (_utarray_eltptr(a,(a)->i-1)) : NULL)
#define utarray_eltidx(a,e) (((char*)(e) - (a)->d) / (a)->icd.sz)
/* last we pre-define a few icd for common utarrays of ints and strings */
static void utarray_str_cpy(void *dst, const void *src) {
char **_src = (char**)src, **_dst = (char**)dst;
*_dst = (*_src == NULL) ? NULL : strdup(*_src);
}
static void utarray_str_dtor(void *elt) {
char **eltc = (char**)elt;
if (*eltc != NULL) free(*eltc);
}
static const UT_icd ut_str_icd UTARRAY_UNUSED = {sizeof(char*),NULL,utarray_str_cpy,utarray_str_dtor};
static const UT_icd ut_int_icd UTARRAY_UNUSED = {sizeof(int),NULL,NULL,NULL};
static const UT_icd ut_ptr_icd UTARRAY_UNUSED = {sizeof(void*),NULL,NULL,NULL};
#endif /* UTARRAY_H */

1150
deps/uthash/uthash.h vendored Normal file

File diff suppressed because it is too large Load Diff

1073
deps/uthash/utlist.h vendored Normal file

File diff suppressed because it is too large Load Diff

108
deps/uthash/utringbuffer.h vendored Normal file
View File

@@ -0,0 +1,108 @@
/*
Copyright (c) 2015-2018, Troy D. Hanson http://troydhanson.github.com/uthash/
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.
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.
*/
/* a ring-buffer implementation using macros
*/
#ifndef UTRINGBUFFER_H
#define UTRINGBUFFER_H
#define UTRINGBUFFER_VERSION 2.1.0
#include <stdlib.h>
#include <string.h>
#include "utarray.h" // for "UT_icd"
typedef struct {
unsigned i; /* index of next available slot; wraps at n */
unsigned n; /* capacity */
unsigned char f; /* full */
UT_icd icd; /* initializer, copy and destructor functions */
char *d; /* n slots of size icd->sz */
} UT_ringbuffer;
#define utringbuffer_init(a, _n, _icd) do { \
memset(a, 0, sizeof(UT_ringbuffer)); \
(a)->icd = *(_icd); \
(a)->n = (_n); \
if ((a)->n) { (a)->d = (char*)malloc((a)->n * (_icd)->sz); } \
} while(0)
#define utringbuffer_clear(a) do { \
if ((a)->icd.dtor) { \
if ((a)->f) { \
unsigned _ut_i; \
for (_ut_i = 0; _ut_i < (a)->n; ++_ut_i) { \
(a)->icd.dtor(utringbuffer_eltptr(a, _ut_i)); \
} \
} else { \
unsigned _ut_i; \
for (_ut_i = 0; _ut_i < (a)->i; ++_ut_i) { \
(a)->icd.dtor(utringbuffer_eltptr(a, _ut_i)); \
} \
} \
} \
(a)->i = 0; \
(a)->f = 0; \
} while(0)
#define utringbuffer_done(a) do { \
utringbuffer_clear(a); \
free((a)->d); (a)->d = NULL; \
(a)->n = 0; \
} while(0)
#define utringbuffer_new(a,n,_icd) do { \
a = (UT_ringbuffer*)malloc(sizeof(UT_ringbuffer)); \
utringbuffer_init(a, n, _icd); \
} while(0)
#define utringbuffer_free(a) do { \
utringbuffer_done(a); \
free(a); \
} while(0)
#define utringbuffer_push_back(a,p) do { \
if ((a)->icd.dtor && (a)->f) { (a)->icd.dtor(_utringbuffer_internalptr(a,(a)->i)); } \
if ((a)->icd.copy) { (a)->icd.copy( _utringbuffer_internalptr(a,(a)->i), p); } \
else { memcpy(_utringbuffer_internalptr(a,(a)->i), p, (a)->icd.sz); }; \
if (++(a)->i == (a)->n) { (a)->i = 0; (a)->f = 1; } \
} while(0)
#define utringbuffer_len(a) ((a)->f ? (a)->n : (a)->i)
#define utringbuffer_empty(a) ((a)->i == 0 && !(a)->f)
#define utringbuffer_full(a) ((a)->f != 0)
#define _utringbuffer_real_idx(a,j) ((a)->f ? ((j) + (a)->i) % (a)->n : (j))
#define _utringbuffer_internalptr(a,j) ((void*)((a)->d + ((a)->icd.sz * (j))))
#define utringbuffer_eltptr(a,j) ((0 <= (j) && (j) < utringbuffer_len(a)) ? _utringbuffer_internalptr(a,_utringbuffer_real_idx(a,j)) : NULL)
#define _utringbuffer_fake_idx(a,j) ((a)->f ? ((j) + (a)->n - (a)->i) % (a)->n : (j))
#define _utringbuffer_internalidx(a,e) (((char*)(e) >= (a)->d) ? (((char*)(e) - (a)->d)/(a)->icd.sz) : -1)
#define utringbuffer_eltidx(a,e) _utringbuffer_fake_idx(a, _utringbuffer_internalidx(a,e))
#define utringbuffer_front(a) utringbuffer_eltptr(a,0)
#define utringbuffer_next(a,e) ((e)==NULL ? utringbuffer_front(a) : utringbuffer_eltptr(a, utringbuffer_eltidx(a,e)+1))
#define utringbuffer_prev(a,e) ((e)==NULL ? utringbuffer_back(a) : utringbuffer_eltptr(a, utringbuffer_eltidx(a,e)-1))
#define utringbuffer_back(a) (utringbuffer_empty(a) ? NULL : utringbuffer_eltptr(a, utringbuffer_len(a) - 1))
#endif /* UTRINGBUFFER_H */

88
deps/uthash/utstack.h vendored Normal file
View File

@@ -0,0 +1,88 @@
/*
Copyright (c) 2018-2018, Troy D. Hanson http://troydhanson.github.com/uthash/
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.
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.
*/
#ifndef UTSTACK_H
#define UTSTACK_H
#define UTSTACK_VERSION 2.1.0
/*
* This file contains macros to manipulate a singly-linked list as a stack.
*
* To use utstack, your structure must have a "next" pointer.
*
* ----------------.EXAMPLE -------------------------
* struct item {
* int id;
* struct item *next;
* }
*
* struct item *stack = NULL:
*
* int main() {
* int count;
* struct item *tmp;
* struct item *item = malloc(sizeof *item);
* item->id = 42;
* STACK_COUNT(stack, tmp, count); assert(count == 0);
* STACK_PUSH(stack, item);
* STACK_COUNT(stack, tmp, count); assert(count == 1);
* STACK_POP(stack, item);
* free(item);
* STACK_COUNT(stack, tmp, count); assert(count == 0);
* }
* --------------------------------------------------
*/
#define STACK_TOP(head) (head)
#define STACK_EMPTY(head) (!(head))
#define STACK_PUSH(head,add) \
STACK_PUSH2(head,add,next)
#define STACK_PUSH2(head,add,next) \
do { \
(add)->next = (head); \
(head) = (add); \
} while (0)
#define STACK_POP(head,result) \
STACK_POP2(head,result,next)
#define STACK_POP2(head,result,next) \
do { \
(result) = (head); \
(head) = (head)->next; \
} while (0)
#define STACK_COUNT(head,el,counter) \
STACK_COUNT2(head,el,counter,next) \
#define STACK_COUNT2(head,el,counter,next) \
do { \
(counter) = 0; \
for ((el) = (head); el; (el) = (el)->next) { ++(counter); } \
} while (0)
#endif /* UTSTACK_H */

407
deps/uthash/utstring.h vendored Normal file
View File

@@ -0,0 +1,407 @@
/*
Copyright (c) 2008-2018, Troy D. Hanson http://troydhanson.github.com/uthash/
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.
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.
*/
/* a dynamic string implementation using macros
*/
#ifndef UTSTRING_H
#define UTSTRING_H
#define UTSTRING_VERSION 2.1.0
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#ifdef __GNUC__
#define UTSTRING_UNUSED __attribute__((__unused__))
#else
#define UTSTRING_UNUSED
#endif
#ifdef oom
#error "The name of macro 'oom' has been changed to 'utstring_oom'. Please update your code."
#define utstring_oom() oom()
#endif
#ifndef utstring_oom
#define utstring_oom() exit(-1)
#endif
typedef struct {
char *d; /* pointer to allocated buffer */
size_t n; /* allocated capacity */
size_t i; /* index of first unused byte */
} UT_string;
#define utstring_reserve(s,amt) \
do { \
if (((s)->n - (s)->i) < (size_t)(amt)) { \
char *utstring_tmp = (char*)realloc( \
(s)->d, (s)->n + (amt)); \
if (!utstring_tmp) { \
utstring_oom(); \
} \
(s)->d = utstring_tmp; \
(s)->n += (amt); \
} \
} while(0)
#define utstring_init(s) \
do { \
(s)->n = 0; (s)->i = 0; (s)->d = NULL; \
utstring_reserve(s,100); \
(s)->d[0] = '\0'; \
} while(0)
#define utstring_done(s) \
do { \
if ((s)->d != NULL) free((s)->d); \
(s)->n = 0; \
} while(0)
#define utstring_free(s) \
do { \
utstring_done(s); \
free(s); \
} while(0)
#define utstring_new(s) \
do { \
(s) = (UT_string*)malloc(sizeof(UT_string)); \
if (!(s)) { \
utstring_oom(); \
} \
utstring_init(s); \
} while(0)
#define utstring_renew(s) \
do { \
if (s) { \
utstring_clear(s); \
} else { \
utstring_new(s); \
} \
} while(0)
#define utstring_clear(s) \
do { \
(s)->i = 0; \
(s)->d[0] = '\0'; \
} while(0)
#define utstring_bincpy(s,b,l) \
do { \
utstring_reserve((s),(l)+1); \
if (l) memcpy(&(s)->d[(s)->i], b, l); \
(s)->i += (l); \
(s)->d[(s)->i]='\0'; \
} while(0)
#define utstring_concat(dst,src) \
do { \
utstring_reserve((dst),((src)->i)+1); \
if ((src)->i) memcpy(&(dst)->d[(dst)->i], (src)->d, (src)->i); \
(dst)->i += (src)->i; \
(dst)->d[(dst)->i]='\0'; \
} while(0)
#define utstring_len(s) ((s)->i)
#define utstring_body(s) ((s)->d)
UTSTRING_UNUSED static void utstring_printf_va(UT_string *s, const char *fmt, va_list ap) {
int n;
va_list cp;
for (;;) {
#ifdef _WIN32
cp = ap;
#else
va_copy(cp, ap);
#endif
n = vsnprintf (&s->d[s->i], s->n-s->i, fmt, cp);
va_end(cp);
if ((n > -1) && ((size_t) n < (s->n-s->i))) {
s->i += n;
return;
}
/* Else try again with more space. */
if (n > -1) utstring_reserve(s,n+1); /* exact */
else utstring_reserve(s,(s->n)*2); /* 2x */
}
}
#ifdef __GNUC__
/* support printf format checking (2=the format string, 3=start of varargs) */
static void utstring_printf(UT_string *s, const char *fmt, ...)
__attribute__ (( format( printf, 2, 3) ));
#endif
UTSTRING_UNUSED static void utstring_printf(UT_string *s, const char *fmt, ...) {
va_list ap;
va_start(ap,fmt);
utstring_printf_va(s,fmt,ap);
va_end(ap);
}
/*******************************************************************************
* begin substring search functions *
******************************************************************************/
/* Build KMP table from left to right. */
UTSTRING_UNUSED static void _utstring_BuildTable(
const char *P_Needle,
size_t P_NeedleLen,
long *P_KMP_Table)
{
long i, j;
i = 0;
j = i - 1;
P_KMP_Table[i] = j;
while (i < (long) P_NeedleLen)
{
while ( (j > -1) && (P_Needle[i] != P_Needle[j]) )
{
j = P_KMP_Table[j];
}
i++;
j++;
if (i < (long) P_NeedleLen)
{
if (P_Needle[i] == P_Needle[j])
{
P_KMP_Table[i] = P_KMP_Table[j];
}
else
{
P_KMP_Table[i] = j;
}
}
else
{
P_KMP_Table[i] = j;
}
}
return;
}
/* Build KMP table from right to left. */
UTSTRING_UNUSED static void _utstring_BuildTableR(
const char *P_Needle,
size_t P_NeedleLen,
long *P_KMP_Table)
{
long i, j;
i = P_NeedleLen - 1;
j = i + 1;
P_KMP_Table[i + 1] = j;
while (i >= 0)
{
while ( (j < (long) P_NeedleLen) && (P_Needle[i] != P_Needle[j]) )
{
j = P_KMP_Table[j + 1];
}
i--;
j--;
if (i >= 0)
{
if (P_Needle[i] == P_Needle[j])
{
P_KMP_Table[i + 1] = P_KMP_Table[j + 1];
}
else
{
P_KMP_Table[i + 1] = j;
}
}
else
{
P_KMP_Table[i + 1] = j;
}
}
return;
}
/* Search data from left to right. ( Multiple search mode. ) */
UTSTRING_UNUSED static long _utstring_find(
const char *P_Haystack,
size_t P_HaystackLen,
const char *P_Needle,
size_t P_NeedleLen,
long *P_KMP_Table)
{
long i, j;
long V_FindPosition = -1;
/* Search from left to right. */
i = j = 0;
while ( (j < (int)P_HaystackLen) && (((P_HaystackLen - j) + i) >= P_NeedleLen) )
{
while ( (i > -1) && (P_Needle[i] != P_Haystack[j]) )
{
i = P_KMP_Table[i];
}
i++;
j++;
if (i >= (int)P_NeedleLen)
{
/* Found. */
V_FindPosition = j - i;
break;
}
}
return V_FindPosition;
}
/* Search data from right to left. ( Multiple search mode. ) */
UTSTRING_UNUSED static long _utstring_findR(
const char *P_Haystack,
size_t P_HaystackLen,
const char *P_Needle,
size_t P_NeedleLen,
long *P_KMP_Table)
{
long i, j;
long V_FindPosition = -1;
/* Search from right to left. */
j = (P_HaystackLen - 1);
i = (P_NeedleLen - 1);
while ( (j >= 0) && (j >= i) )
{
while ( (i < (int)P_NeedleLen) && (P_Needle[i] != P_Haystack[j]) )
{
i = P_KMP_Table[i + 1];
}
i--;
j--;
if (i < 0)
{
/* Found. */
V_FindPosition = j + 1;
break;
}
}
return V_FindPosition;
}
/* Search data from left to right. ( One time search mode. ) */
UTSTRING_UNUSED static long utstring_find(
UT_string *s,
long P_StartPosition, /* Start from 0. -1 means last position. */
const char *P_Needle,
size_t P_NeedleLen)
{
long V_StartPosition;
long V_HaystackLen;
long *V_KMP_Table;
long V_FindPosition = -1;
if (P_StartPosition < 0)
{
V_StartPosition = s->i + P_StartPosition;
}
else
{
V_StartPosition = P_StartPosition;
}
V_HaystackLen = s->i - V_StartPosition;
if ( (V_HaystackLen >= (long) P_NeedleLen) && (P_NeedleLen > 0) )
{
V_KMP_Table = (long *)malloc(sizeof(long) * (P_NeedleLen + 1));
if (V_KMP_Table != NULL)
{
_utstring_BuildTable(P_Needle, P_NeedleLen, V_KMP_Table);
V_FindPosition = _utstring_find(s->d + V_StartPosition,
V_HaystackLen,
P_Needle,
P_NeedleLen,
V_KMP_Table);
if (V_FindPosition >= 0)
{
V_FindPosition += V_StartPosition;
}
free(V_KMP_Table);
}
}
return V_FindPosition;
}
/* Search data from right to left. ( One time search mode. ) */
UTSTRING_UNUSED static long utstring_findR(
UT_string *s,
long P_StartPosition, /* Start from 0. -1 means last position. */
const char *P_Needle,
size_t P_NeedleLen)
{
long V_StartPosition;
long V_HaystackLen;
long *V_KMP_Table;
long V_FindPosition = -1;
if (P_StartPosition < 0)
{
V_StartPosition = s->i + P_StartPosition;
}
else
{
V_StartPosition = P_StartPosition;
}
V_HaystackLen = V_StartPosition + 1;
if ( (V_HaystackLen >= (long) P_NeedleLen) && (P_NeedleLen > 0) )
{
V_KMP_Table = (long *)malloc(sizeof(long) * (P_NeedleLen + 1));
if (V_KMP_Table != NULL)
{
_utstring_BuildTableR(P_Needle, P_NeedleLen, V_KMP_Table);
V_FindPosition = _utstring_findR(s->d,
V_HaystackLen,
P_Needle,
P_NeedleLen,
V_KMP_Table);
free(V_KMP_Table);
}
}
return V_FindPosition;
}
/*******************************************************************************
* end substring search functions *
******************************************************************************/
#endif /* UTSTRING_H */

157
deps/uuid_v4/endianness.h vendored Normal file
View File

@@ -0,0 +1,157 @@
#pragma once
#if defined(__GLIBC__) || defined(__GNU_LIBRARY__) || defined(__ANDROID__)
#include <endian.h>
#elif defined(__APPLE__) && defined(__MACH__)
#include <machine/endian.h>
#elif defined(BSD) || defined(_SYSTYPE_BSD)
#if defined(__OpenBSD__)
#include <machine/endian.h>
#else
#include <sys/endian.h>
#endif
#endif
#if defined(__BYTE_ORDER)
#if defined(__BIG_ENDIAN) && (__BYTE_ORDER == __BIG_ENDIAN)
#define BIGENDIAN
#elif defined(__LITTLE_ENDIAN) && (__BYTE_ORDER == __LITTLE_ENDIAN)
#define LITTLEENDIAN
#endif
#elif defined(_BYTE_ORDER)
#if defined(_BIG_ENDIAN) && (_BYTE_ORDER == _BIG_ENDIAN)
#define BIGENDIAN
#elif defined(_LITTLE_ENDIAN) && (_BYTE_ORDER == _LITTLE_ENDIAN)
#define LITTLEENDIAN
#endif
#elif defined(__BIG_ENDIAN__)
#define BIGENDIAN
#elif defined(__LITTLE_ENDIAN__)
#define LITTLEENDIAN
#else
#if defined(__ARMEL__) || \
defined(__THUMBEL__) || \
defined(__AARCH64EL__) || \
defined(_MIPSEL) || \
defined(__MIPSEL) || \
defined(__MIPSEL__) || \
defined(__ia64__) || defined(_IA64) || \
defined(__IA64__) || defined(__ia64) || \
defined(_M_IA64) || defined(__itanium__) || \
defined(i386) || defined(__i386__) || \
defined(__i486__) || defined(__i586__) || \
defined(__i686__) || defined(__i386) || \
defined(_M_IX86) || defined(_X86_) || \
defined(__THW_INTEL__) || defined(__I86__) || \
defined(__INTEL__) || \
defined(__x86_64) || defined(__x86_64__) || \
defined(__amd64__) || defined(__amd64) || \
defined(_M_X64) || \
defined(__bfin__) || defined(__BFIN__) || \
defined(bfin) || defined(BFIN)
#define LITTLEENDIAN
#elif defined(__m68k__) || defined(M68000) || \
defined(__hppa__) || defined(__hppa) || defined(__HPPA__) || \
defined(__sparc__) || defined(__sparc) || \
defined(__370__) || defined(__THW_370__) || \
defined(__s390__) || defined(__s390x__) || \
defined(__SYSC_ZARCH__)
#define BIGENDIAN
#elif defined(__arm__) || defined(__arm64) || defined(__thumb__) || \
defined(__TARGET_ARCH_ARM) || defined(__TARGET_ARCH_THUMB) || \
defined(__ARM_ARCH) || \
defined(_M_ARM) || defined(_M_ARM64)
#if defined(_WIN32) || defined(_WIN64) || \
defined(__WIN32__) || defined(__TOS_WIN__) || \
defined(__WINDOWS__)
#define LITTLEENDIAN
#else
#error "Cannot determine system endianness."
#endif
#endif
#endif
#if defined(BIGENDIAN)
// Try to use compiler intrinsics
#if defined(__INTEL_COMPILER) || defined(__ICC)
#define betole16(x) _bswap16(x)
#define betole32(x) _bswap(x)
#define betole64(x) _bswap64(x)
#elif defined(__GNUC__) // GCC and CLANG
#define betole16(x) __builtin_bswap16(x)
#define betole32(x) __builtin_bswap32(x)
#define betole64(x) __builtin_bswap64(x)
#elif defined(_MSC_VER) // MSVC
#include <stdlib.h>
#define betole16(x) _byteswap_ushort(x)
#define betole32(x) _byteswap_ulong(x)
#define betole64(x) _byteswap_uint64(x)
#else
#define FALLBACK_SWAP
#define betole16(x) swap_u16(x)
#define betole32(x) swap_u32(x)
#define betole64(x) swap_u64(x)
#endif
#define betole128(x) swap_u128(x)
#define betole256(x) swap_u256(x)
#else
#define betole16(x) (x)
#define betole32(x) (x)
#define betole64(x) (x)
#define betole128(x) (x)
#define betole256(x) (x)
#endif // BIGENDIAN
#if defined(BIGENDIAN)
#include <emmintrin.h>
#include <smmintrin.h>
#include <immintrin.h>
#include <tmmintrin.h>
inline __m128i swap_u128(__m128i value) {
const __m128i shuffle = _mm_set_epi64x(0x0001020304050607, 0x08090a0b0c0d0e0f);
return _mm_shuffle_epi8(value, shuffle);
}
inline __m256i swap_u256(__m256i value) {
const __m256i shuffle = _mm256_set_epi64x(0x0001020304050607, 0x08090a0b0c0d0e0f, 0x0001020304050607, 0x08090a0b0c0d0e0f);
return _mm256_shuffle_epi8(value, shuffle);
}
#endif // BIGENDIAN
#if defined(FALLBACK_SWAP)
#include <stdint.h>
inline uint16_t swap_u16(uint16_t value)
{
return
((value & 0xFF00u) >> 8u) |
((value & 0x00FFu) << 8u);
}
inline uint32_t swap_u32(uint32_t value)
{
return
((value & 0xFF000000u) >> 24u) |
((value & 0x00FF0000u) >> 8u) |
((value & 0x0000FF00u) << 8u) |
((value & 0x000000FFu) << 24u);
}
inline uint64_t swap_u64(uint64_t value)
{
return
((value & 0xFF00000000000000u) >> 56u) |
((value & 0x00FF000000000000u) >> 40u) |
((value & 0x0000FF0000000000u) >> 24u) |
((value & 0x000000FF00000000u) >> 8u) |
((value & 0x00000000FF000000u) << 8u) |
((value & 0x0000000000FF0000u) << 24u) |
((value & 0x000000000000FF00u) << 40u) |
((value & 0x00000000000000FFu) << 56u);
}
#endif // FALLBACK_SWAP

276
deps/uuid_v4/uuid_v4.h vendored Normal file
View File

@@ -0,0 +1,276 @@
/*
MIT License
Copyright (c) 2018 Xavier "Crashoz" Launey
*/
#pragma once
#include <random>
#include <string>
#include <limits>
#include <iostream>
#include <sstream>
#include <cstdint>
#include <memory>
#include <emmintrin.h>
#include <smmintrin.h>
#include <immintrin.h>
#include "endianness.h"
namespace UUIDv4 {
/*
Converts a 128-bits unsigned int to an UUIDv4 string representation.
Uses SIMD via Intel's AVX2 instruction set.
*/
void inline m128itos(__m128i x, char* mem) {
// Expand each byte in x to two bytes in res
// i.e. 0x12345678 -> 0x0102030405060708
// Then translate each byte to its hex ascii representation
// i.e. 0x0102030405060708 -> 0x3132333435363738
const __m256i mask = _mm256_set1_epi8(0x0F);
const __m256i add = _mm256_set1_epi8(0x06);
const __m256i alpha_mask = _mm256_set1_epi8(0x10);
const __m256i alpha_offset = _mm256_set1_epi8(0x57);
__m256i a = _mm256_castsi128_si256(x);
__m256i as = _mm256_srli_epi64(a, 4);
__m256i lo = _mm256_unpacklo_epi8(as, a);
__m128i hi = _mm256_castsi256_si128(_mm256_unpackhi_epi8(as, a));
__m256i c = _mm256_inserti128_si256(lo, hi, 1);
__m256i d = _mm256_and_si256(c, mask);
__m256i alpha = _mm256_slli_epi64(_mm256_and_si256(_mm256_add_epi8(d, add), alpha_mask), 3);
__m256i offset = _mm256_blendv_epi8(_mm256_slli_epi64(add, 3), alpha_offset, alpha);
__m256i res = _mm256_add_epi8(d, offset);
// Add dashes between blocks as specified in RFC-4122
// 8-4-4-4-12
const __m256i dash_shuffle = _mm256_set_epi32(0x0b0a0908, 0x07060504, 0x80030201, 0x00808080, 0x0d0c800b, 0x0a090880, 0x07060504, 0x03020100);
const __m256i dash = _mm256_set_epi64x(0x0000000000000000ull, 0x2d000000002d0000ull, 0x00002d000000002d, 0x0000000000000000ull);
__m256i resd = _mm256_shuffle_epi8(res, dash_shuffle);
resd = _mm256_or_si256(resd, dash);
_mm256_storeu_si256((__m256i*)mem, betole256(resd));
*(uint16_t*)(mem+16) = betole16(_mm256_extract_epi16(res, 7));
*(uint32_t*)(mem+32) = betole32(_mm256_extract_epi32(res, 7));
}
/*
Converts an UUIDv4 string representation to a 128-bits unsigned int.
Uses SIMD via Intel's AVX2 instruction set.
*/
__m128i inline stom128i(const char* mem) {
// Remove dashes and pack hex ascii bytes in a 256-bits int
const __m256i dash_shuffle = _mm256_set_epi32(0x80808080, 0x0f0e0d0c, 0x0b0a0908, 0x06050403, 0x80800f0e, 0x0c0b0a09, 0x07060504, 0x03020100);
__m256i x = betole256(_mm256_loadu_si256((__m256i*)mem));
x = _mm256_shuffle_epi8(x, dash_shuffle);
x = _mm256_insert_epi16(x, betole16(*(uint16_t*)(mem+16)), 7);
x = _mm256_insert_epi32(x, betole32(*(uint32_t*)(mem+32)), 7);
// Build a mask to apply a different offset to alphas and digits
const __m256i sub = _mm256_set1_epi8(0x2F);
const __m256i mask = _mm256_set1_epi8(0x20);
const __m256i alpha_offset = _mm256_set1_epi8(0x28);
const __m256i digits_offset = _mm256_set1_epi8(0x01);
const __m256i unweave = _mm256_set_epi32(0x0f0d0b09, 0x0e0c0a08, 0x07050301, 0x06040200, 0x0f0d0b09, 0x0e0c0a08, 0x07050301, 0x06040200);
const __m256i shift = _mm256_set_epi32(0x00000000, 0x00000004, 0x00000000, 0x00000004, 0x00000000, 0x00000004, 0x00000000, 0x00000004);
// Translate ascii bytes to their value
// i.e. 0x3132333435363738 -> 0x0102030405060708
// Shift hi-digits
// i.e. 0x0102030405060708 -> 0x1002300450067008
// Horizontal add
// i.e. 0x1002300450067008 -> 0x12345678
__m256i a = _mm256_sub_epi8(x, sub);
__m256i alpha = _mm256_slli_epi64(_mm256_and_si256(a, mask), 2);
__m256i sub_mask = _mm256_blendv_epi8(digits_offset, alpha_offset, alpha);
a = _mm256_sub_epi8(a, sub_mask);
a = _mm256_shuffle_epi8(a, unweave);
a = _mm256_sllv_epi32(a, shift);
a = _mm256_hadd_epi32(a, _mm256_setzero_si256());
a = _mm256_permute4x64_epi64(a, 0b00001000);
return _mm256_castsi256_si128(a);
}
/*
* UUIDv4 (random 128-bits) RFC-4122
*/
class UUID {
public:
UUID()
{}
UUID(const UUID &other) {
__m128i x = _mm_load_si128((__m128i*)other.data);
_mm_store_si128((__m128i*)data, x);
}
/* Builds a 128-bits UUID */
UUID(__m128i uuid) {
_mm_store_si128((__m128i*)data, uuid);
}
UUID(uint64_t x, uint64_t y) {
__m128i z = _mm_set_epi64x(x, y);
_mm_store_si128((__m128i*)data, z);
}
UUID(const uint8_t* bytes) {
__m128i x = _mm_loadu_si128((__m128i*)bytes);
_mm_store_si128((__m128i*)data, x);
}
/* Builds an UUID from a byte string (16 bytes long) */
explicit UUID(const std::string &bytes) {
__m128i x = betole128(_mm_loadu_si128((__m128i*)bytes.data()));
_mm_store_si128((__m128i*)data, x);
}
/* Static factory to parse an UUID from its string representation */
static UUID fromStrFactory(const std::string &s) {
return fromStrFactory(s.c_str());
}
static UUID fromStrFactory(const char* raw) {
return UUID(stom128i(raw));
}
void fromStr(const char* raw) {
_mm_store_si128((__m128i*)data, stom128i(raw));
}
UUID& operator=(const UUID &other) {
if (&other == this) {
return *this;
}
__m128i x = _mm_load_si128((__m128i*)other.data);
_mm_store_si128((__m128i*)data, x);
return *this;
}
friend bool operator==(const UUID &lhs, const UUID &rhs) {
__m128i x = _mm_load_si128((__m128i*)lhs.data);
__m128i y = _mm_load_si128((__m128i*)rhs.data);
__m128i neq = _mm_xor_si128(x, y);
return _mm_test_all_zeros(neq, neq);
}
friend bool operator<(const UUID &lhs, const UUID &rhs) {
// There are no trivial 128-bits comparisons in SSE/AVX
// It's faster to compare two uint64_t
uint64_t *x = (uint64_t*)lhs.data;
uint64_t *y = (uint64_t*)rhs.data;
return *x < *y || (*x == *y && *(x + 1) < *(y + 1));
}
friend bool operator!=(const UUID &lhs, const UUID &rhs) { return !(lhs == rhs); }
friend bool operator> (const UUID &lhs, const UUID &rhs) { return rhs < lhs; }
friend bool operator<=(const UUID &lhs, const UUID &rhs) { return !(lhs > rhs); }
friend bool operator>=(const UUID &lhs, const UUID &rhs) { return !(lhs < rhs); }
/* Serializes the uuid to a byte string (16 bytes) */
std::string bytes() const {
std::string mem;
bytes(mem);
return mem;
}
void bytes(std::string &out) const {
out.resize(sizeof(data));
bytes((char*)out.data());
}
void bytes(char* bytes) const {
__m128i x = betole128(_mm_load_si128((__m128i*)data));
_mm_storeu_si128((__m128i*)bytes, x);
}
/* Converts the uuid to its string representation */
std::string str() const {
std::string mem;
str(mem);
return mem;
}
void str(std::string &s) const {
s.resize(36);
str((char*)s.data());
}
void str(char *res) const {
__m128i x = _mm_load_si128((__m128i*)data);
m128itos(x, res);
}
friend std::ostream& operator<< (std::ostream& stream, const UUID& uuid) {
return stream << uuid.str();
}
friend std::istream& operator>> (std::istream& stream, UUID& uuid) {
std::string s;
stream >> s;
uuid = fromStrFactory(s);
return stream;
}
size_t hash() const {
const uint64_t a = *((uint64_t*)data);
const uint64_t b = *((uint64_t*)&data[8]);
return a ^ (b + 0x9e3779b9 + (a << 6) + (a >> 2));
}
private:
alignas(128) uint8_t data[16];
};
/*
Generates UUIDv4 from a provided random generator (c++11 <random> module)
std::mt19937_64 is highly recommended as it has a SIMD implementation that
makes it very fast and it produces high quality randomness.
*/
template <typename RNG>
class UUIDGenerator {
public:
UUIDGenerator() : generator(new RNG(std::random_device()())), distribution(std::numeric_limits<uint64_t>::min(), std::numeric_limits<uint64_t>::max())
{}
UUIDGenerator(uint64_t seed) : generator(new RNG(seed)), distribution(std::numeric_limits<uint64_t>::min(), std::numeric_limits<uint64_t>::max())
{}
UUIDGenerator(RNG &gen) : generator(gen), distribution(std::numeric_limits<uint64_t>::min(), std::numeric_limits<uint64_t>::max())
{}
/* Generates a new UUID */
UUID getUUID() {
// The two masks set the uuid version (4) and variant (1)
const __m128i and_mask = _mm_set_epi64x(0xFFFFFFFFFFFFFF3Full, 0xFF0FFFFFFFFFFFFFull);
const __m128i or_mask = _mm_set_epi64x(0x0000000000000080ull, 0x0040000000000000ull);
__m128i n = _mm_set_epi64x(distribution(*generator), distribution(*generator));
__m128i uuid = _mm_or_si128(_mm_and_si128(n, and_mask), or_mask);
return UUID(uuid);
}
private:
std::shared_ptr<RNG> generator;
std::uniform_int_distribution<uint64_t> distribution;
};
}
namespace std {
template <> struct hash<UUIDv4::UUID>
{
size_t operator()(const UUIDv4::UUID & uuid) const
{
return uuid.hash();
}
};
}

21
deps/yyjson/LICENSE vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 YaoYuan <ibireme@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

9447
deps/yyjson/yyjson.c vendored Normal file

File diff suppressed because it is too large Load Diff

7814
deps/yyjson/yyjson.h vendored Normal file

File diff suppressed because it is too large Load Diff

90
include/ssl_decoder.h Normal file
View File

@@ -0,0 +1,90 @@
#pragma once
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdint.h>
#include <stddef.h>
#define SSL_DECODER_MESSAGE_TOPIC "SSL_DECODER_MESSAGE"
enum ssl_message_type
{
SSL_CLIENT_HELLO,
SSL_SERVER_HELLO,
SSL_CERTIFICATE,
SSL_PROTECTED_PAYLOAD,
SSL_MSG_MAX,
};
struct ssl_message;
enum ssl_message_type ssl_message_type_get(const struct ssl_message *msg);
// SSL_CLIENT_HELLO
int32_t ssl_message_esni_is_true(const struct ssl_message *msg);
int32_t ssl_message_ech_is_true(const struct ssl_message *msg);
void ssl_message_sni_get0(const struct ssl_message *msg, char **value, size_t *value_sz);
const char *ssl_message_readable_version_get0(const struct ssl_message *msg);
const char *ssl_message_readable_ja3hash_get0(const struct ssl_message *msg);
// SSL_SERVER_HELLO
const char *ssl_message_readable_ja3shash_get0(const struct ssl_message *msg);
void ssl_message_extensions_next(const struct ssl_message *msg, char **value, size_t *value_sz);
int ssl_message_reset_extensions_iter(struct ssl_message *msg);
// SSL_CERTIFICATE
enum ssl_certificate_type
{
SSL_CERTIFICATE_TYPE_UNKNOWN=0,
SSL_CERTIFICATE_TYPE_INDIVIDUAL,
SSL_CERTIFICATE_TYPE_ROOT,
SSL_CERTIFICATE_TYPE_MIDDLE,
SSL_CERTIFICATE_TYPE_CHAIN,
SSL_CERTIFICATE_TYPE_MAX,
};
enum ssl_certificate_type ssl_certificate_type_get(const struct ssl_message *msg);
void ssl_message_validity_before_get0(const struct ssl_message *msg, char **value, size_t *value_sz);
void ssl_message_validity_after_get0(const struct ssl_message *msg, char **value, size_t *value_sz);
void ssl_message_issuer_serial_number_get0(const struct ssl_message *msg, char **value, size_t *value_sz);
void ssl_message_subject_public_key_algorithm_get0(const struct ssl_message *msg, char **value, size_t *value_sz);
void ssl_message_ssl_algorithm_identifier_get0(const struct ssl_message *msg, char **value, size_t *value_sz);
void ssl_message_ssl_signature_algorithm_id_get0(const struct ssl_message *msg, char **value, size_t *value_sz);
/**
* @brief loop reading all domain of subject_alter.
*
*/
void ssl_message_subject_alter_next(const struct ssl_message *msg, char **value, size_t *value_sz);
/**
* @retval succeed( >= 0) failed(-1)
*/
int ssl_message_reset_subject_alter_iter(struct ssl_message *msg);
struct ssl_rdn_sequence;
struct ssl_rdn_sequence *ssl_message_issuer_rdn_sequence_get0(const struct ssl_message *msg);
struct ssl_rdn_sequence *ssl_message_subject_rdn_sequence_get0(const struct ssl_message *msg);
void ssl_rdn_sequence_common_get0(struct ssl_rdn_sequence *rdn, char **value, size_t *value_sz);
void ssl_rdn_sequence_country_get0(struct ssl_rdn_sequence *rdn, char **value, size_t *value_sz);
void ssl_rdn_sequence_locality_get0(struct ssl_rdn_sequence *rdn, char **value, size_t *value_sz);
void ssl_rdn_sequence_postal_code_get0(struct ssl_rdn_sequence *rdn, char **value, size_t *value_sz);
void ssl_rdn_sequence_organization_get0(struct ssl_rdn_sequence *rdn, char **value, size_t *value_sz);
void ssl_rdn_sequence_street_address_get0(struct ssl_rdn_sequence *rdn, char **value, size_t *value_sz);
void ssl_rdn_sequence_state_or_province_get0(struct ssl_rdn_sequence *rdn, char **value, size_t *value_sz);
void ssl_rdn_sequence_organizational_unit_get0(struct ssl_rdn_sequence *rdn, char **value, size_t *value_sz);
void ssl_rdn_sequence_list_get0(struct ssl_rdn_sequence *rdn, char **value, size_t *value_sz);
// SSL_PROTECTED_PAYLOAD
void ssl_message_protected_payload_get0(const struct ssl_message *msg, char **value, size_t *value_sz);
#ifdef __cplusplus
}
#endif

BIN
perf/a.out Executable file

Binary file not shown.

30
perf/perfect.cpp Normal file
View File

@@ -0,0 +1,30 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
struct test_unit
{
union
{
uint8_t u8;
uint16_t u16;
uint32_t u32;
size_t u64;
};
uint8_t *value;
};
int main(void)
{
struct test_unit unit={0};
printf("sizeof(a) = %lu\n", sizeof(unit.u8));
printf("sizeof(b) = %lu\n", sizeof(unit.u16));
printf("sizeof(c) = %lu\n", sizeof(unit.u32));
printf("sizeof(test_unit) = %lu\n", sizeof(struct test_unit));
return 0;
}

16
src/CMakeLists.txt Normal file
View File

@@ -0,0 +1,16 @@
add_definitions(-fPIC)
include_directories(/opt/MESA/include/)
include_directories(${PROJECT_SOURCE_DIR}/deps/)
aux_source_directory(${PROJECT_SOURCE_DIR}/deps/toml DEPS_SRC)
aux_source_directory(${PROJECT_SOURCE_DIR}/deps/yyjson DEPS_SRC)
set(SSL_DECODER_SRC ${DEPS_SRC} ssl_decoder.cpp)
add_library(ssl_decoder SHARED ${SSL_DECODER_SRC})
set_target_properties(ssl_decoder PROPERTIES LINK_FLAGS "-Wl,--version-script=${PROJECT_SOURCE_DIR}/src/version.map")
target_link_libraries(ssl_decoder fieldstat4 -Wl,--no-whole-archive openssl-crypto-static -Wl,--no-whole-archive openssl-ssl-static)
set_target_properties(ssl_decoder PROPERTIES PREFIX "")
install(TARGETS ssl_decoder LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/sapp/stellar_plugin/ COMPONENT LIBRARIES)

1020
src/ssl_decoder.cpp Normal file

File diff suppressed because it is too large Load Diff

149
src/ssl_internal.h Normal file
View File

@@ -0,0 +1,149 @@
#pragma once
#include <stdint.h>
#include <stddef.h>
#include <uthash/utarray.h>
#define SSL_DECODER_VERSION_UNKNOWN 0x0000
#define SSL_DECODER_VERSION_SSL_V2_0 0x0002
#define SSL_DECODER_VERSION_SSL_V3_0 0x0300
#define SSL_DECODER_VERSION_TLS_V1_0 0x0301
#define SSL_DECODER_VERSION_TLS_V1_1 0x0302
#define SSL_DECODER_VERSION_TLS_V1_2 0x0303
#define SSL_DECODER_VERSION_TLS_V1_3 0x0304
#define SSL_DECODER_VERSION_TLCP_V1_0 0x0101
#define SSL_DECODER_NONE 0x00
#define SSL_DECODER_L1V 0x01
#define SSL_DECODER_L2V 0x02
#define SSL_DECODER_L2TV 0x03
struct ssl_decoder_ltv
{
uint16_t type; // marco SSL_DECODER*
uint16_t vtype;
union
{
uint8_t lv_u8;
uint16_t lv_u16;
uint32_t lv_u32;
};
uint8_t *value;
};
enum SSL_HELLO_LTV
{
SSL_HELLO_LTV_UNKNOWN=0,
SSL_HELLO_LTV_RANDOM_BYTES,
SSL_HELLO_LTV_SESSION,
SSL_HELLO_LTV_CIPERSUITES,
SSL_HELLO_LTV_COMPRESS_METHOD,
SSL_HELLO_LTV_MAX,
};
struct ssl_client_hello
{
uint16_t version;
uint32_t random_gmt_time;
UT_array *extensions;
struct ssl_decoder_ltv ja3;
struct ssl_decoder_ltv *sni;
struct ssl_decoder_ltv *ech;
struct ssl_decoder_ltv *esni;
struct ssl_decoder_ltv ltv[SSL_HELLO_LTV_MAX];
};
struct ssl_server_hello
{
uint16_t version;
uint32_t random_gmt_time;
UT_array *extensions;
struct ssl_decoder_ltv *ja3s;
struct ssl_decoder_ltv ltv[SSL_HELLO_LTV_MAX];
};
struct ssl_new_session_ticket
{
int total_len; //3 bytes
int lift_time; //second
int ticket_len; //3 bytes
unsigned char* ticket;
};
#define MAX_ALTER_NAME_LEN 64
struct ssl_subject_alter_name
{
int num;
char (*name)[MAX_ALTER_NAME_LEN];
};
#define MAX_RDN_SEQUENCE_LEN 64
#define MAX_RDN_SEQUENCE_LIST_LEN 512
struct ssl_rdn_sequence
{
char common[MAX_RDN_SEQUENCE_LEN]; //commonName
char country[MAX_RDN_SEQUENCE_LEN]; //countryName
char locality[MAX_RDN_SEQUENCE_LEN]; //localityName
char postal_code[MAX_RDN_SEQUENCE_LEN]; // postalCode
char organization[MAX_RDN_SEQUENCE_LEN]; //organizationName
char street_address[MAX_RDN_SEQUENCE_LEN]; //streetAddress
char state_or_Province[MAX_RDN_SEQUENCE_LEN]; //stateOrProvinceName
char organizational_unit[MAX_RDN_SEQUENCE_LEN]; //organizationalUnitName
char rdn_sequence_list[MAX_RDN_SEQUENCE_LIST_LEN]; //commonName + organizationName + organizationalUnitName + localityName + streetAddress + stateOrProvinceName + countryName
};
#define MAX_VALIDITY_LEN 80
struct ssl_validity
{
char before[MAX_VALIDITY_LEN];
char after[MAX_VALIDITY_LEN];
};
struct ssl_subject_public_key
{
int len;
char*value;
};
#define MAX_SERIAL_NUMBER_LEN 128
struct ssl_serial_number
{
unsigned char len;
char value[MAX_SERIAL_NUMBER_LEN];
};
#define MAX_SIGNATURE_ALGORITHM_ID_LEN 64
struct ssl_signature_algorithm_id
{
unsigned char len;
char value[MAX_SIGNATURE_ALGORITHM_ID_LEN];
};
#define MAX_ALGORITHM_IDENTIFIER 64
struct ssl_algorithm_identifier
{
unsigned char len;
char value[MAX_ALGORITHM_IDENTIFIER];
};
struct ssl_certificate
{
int total_len;
int cert_len;
char cert_type;
//struct ssl_l1v version;
struct ssl_validity validity;
struct ssl_serial_number serial;
struct ssl_rdn_sequence issuer;
struct ssl_rdn_sequence subject;
struct ssl_subject_public_key subject_key;
struct ssl_subject_alter_name subject_alter;
struct ssl_algorithm_identifier algorithm_identifier;
struct ssl_signature_algorithm_id signature_algorithm;
};

23
src/version.map Normal file
View File

@@ -0,0 +1,23 @@
VERS_2.4{
global:
extern "C++" {
*ssl_decoder_init*;
*ssl_decoder_exit*;
*ssl_message_type_get*;
*ssl_message_header_id_get*;
*ssl_message_header_flag_get0*;
*ssl_message_query_question_get0*;
*ssl_query_question_qname_get0*;
*ssl_query_question_qtype_get0*;
*ssl_query_question_qclass_get0*;
*ssl_message_answer_resource_record_get0*;
*ssl_message_authority_resource_record_get0*;
*ssl_message_additional_resource_record_get0*;
*ssl_message_resource_record_json_exporter*;
*ssl_message_uuid_get0*;
*ssl_message_resource_record_is_sslsec*;
*ssl_message_resource_record_cname_json_exporter*;
*GIT*;
};
local: *;
};

92
test/CMakeLists.txt Normal file
View File

@@ -0,0 +1,92 @@
include_directories(${PROJECT_SOURCE_DIR}/deps/)
aux_source_directory(${PROJECT_SOURCE_DIR}/deps/toml DEPS_SRC)
aux_source_directory(${PROJECT_SOURCE_DIR}/deps/yyjson DEPS_SRC)
add_library(${PROJECT_NAME}_test_plug SHARED ssl_decoder_test.cpp ${DEPS_SRC})
add_dependencies(${PROJECT_NAME}_test_plug ${PROJECT_NAME})
target_link_libraries(${PROJECT_NAME}_test_plug cjson)
set_target_properties(${PROJECT_NAME}_test_plug PROPERTIES PREFIX "")
add_executable(ssl_decoder_perf_test
ssl_decoder_perf_main.cpp
ssl_decoder_perf_dummy.cpp
${DEPS_SRC} ssl_decoder_test.cpp
${PROJECT_SOURCE_DIR}/src/ssl_decoder.cpp
)
target_link_libraries(ssl_decoder_perf_test fieldstat4 pthread cjson -Wl,--no-whole-archive openssl-crypto-static -Wl,--no-whole-archive openssl-ssl-static)
set(TEST_RUN_DIR ${CMAKE_CURRENT_BINARY_DIR}/sapp)
set(TEST_MAIN ${TEST_RUN_DIR}/plugin_test_main)
# copy perf main
add_test(NAME MKDIR_PERF COMMAND sh -c "mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/perf/ ${CMAKE_CURRENT_BINARY_DIR}/perf/etc/ssl/")
add_test(NAME COPY_PERF_TEST_MAIN COMMAND sh -c "cp ${CMAKE_BINARY_DIR}/test/ssl_decoder_perf_test ${CMAKE_CURRENT_BINARY_DIR}/perf")
add_test(NAME COPY_PERF_TEST_CONF COMMAND sh -c "cp ${PROJECT_SOURCE_DIR}/bin/${PROJECT_NAME}.toml ${CMAKE_CURRENT_BINARY_DIR}/perf/etc/ssl/${PROJECT_NAME}.toml")
# assemble test env
add_test(NAME UNINSTALL_TEST_MAIN COMMAND sh -c "rpm -qa sapp | grep -v not | xargs -i rpm -e {} --nodeps")
add_test(NAME INSTALL_TEST_MAIN COMMAND sh -c "rpm -i ${CMAKE_CURRENT_SOURCE_DIR}/env/sapp-4.3.59.c5b96a4-1.el8.x86_64.rpm --prefix=${CMAKE_CURRENT_BINARY_DIR}/sapp --force --nodeps")
add_test(NAME UNINSTALL_STELLAR COMMAND sh -c "rpm -qa stellar-on-sapp | grep -v not | xargs -i rpm -e {} --nodeps")
add_test(NAME INSTALL_STELLAR COMMAND sh -c "rpm -i ${CMAKE_CURRENT_SOURCE_DIR}/env/stellar-on-sapp-2.1.2.20b65ae-1.el8.x86_64.rpm --prefix=${CMAKE_CURRENT_BINARY_DIR}/ --force --nodeps")
add_test(NAME COPY_TEST_MAIN COMMAND sh -c "cp ${TEST_RUN_DIR}/tools/plugin_test_main ${TEST_RUN_DIR}/plugin_test_main")
add_test(NAME COPY_SPEC COMMAND sh -c "cp ${CMAKE_CURRENT_SOURCE_DIR}/env/spec.toml ${TEST_RUN_DIR}/stellar_plugin/spec.toml")
add_test(NAME COPY_CONFLIST COMMAND sh -c "cp ${CMAKE_CURRENT_SOURCE_DIR}/env/conflist.inf ${TEST_RUN_DIR}/plug/conflist.inf")
add_test(NAME COPY_INF COMMAND sh -c "cp ${CMAKE_CURRENT_SOURCE_DIR}/env/start_loader.inf ${TEST_RUN_DIR}/plug/stellar_on_sapp/start_loader.inf")
# update config files
add_test(NAME UPDATE_SAPP_LOG COMMAND bash -c "sed -i 's/sapp_log.fatal/sapp_log.info/' ${TEST_RUN_DIR}/etc/sapp_log.conf")
add_test(NAME UPDATE_SAPP_SYN_MODE COMMAND bash -c "sed -i 's/syn_mandatory=1/syn_mandatory=0/' ${TEST_RUN_DIR}/etc/sapp.toml")
add_test(NAME UPDATE_SAPP_REORDER COMMAND bash -c "sed -i 's/reorder_pkt_max=32/reorder_pkt_max=5/' ${TEST_RUN_DIR}/etc/sapp.toml")
# update plugin to be tested
add_test(NAME UPDATE_PLUG_SO COMMAND sh -c "cp ${CMAKE_BINARY_DIR}/src/${PROJECT_NAME}.so ${TEST_RUN_DIR}/stellar_plugin/${PROJECT_NAME}.so")
add_test(NAME UPDATE_TEST_SO COMMAND sh -c "cp ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_test_plug.so ${TEST_RUN_DIR}/stellar_plugin/${PROJECT_NAME}_test_plug.so")
add_test(NAME MKDIR_PLUG_CONF COMMAND sh -c "mkdir -p ${TEST_RUN_DIR}/etc/ssl/")
add_test(NAME UPDATE_PLUG_CONF COMMAND sh -c "cp ${PROJECT_SOURCE_DIR}/bin/${PROJECT_NAME}.toml ${TEST_RUN_DIR}/etc/ssl/${PROJECT_NAME}.toml")
# set_tests_properties(INSTALL_TEST_MAIN INSTALL_STELLAR UPDATE_SAPP_LOG COPY_CONFLIST COPY_INF COPY_TEST_MAIN COPY_SPEC UPDATE_PLUG_SO UPDATE_TEST_SO MKDIR_PLUG_CONF UPDATE_PLUG_CONF PROPERTIES FIXTURES_SETUP TestFixture)
# # run tests
# add_test(NAME MKDIR_METRICS COMMAND sh -c "mkdir -p ${TEST_RUN_DIR}/metrics/")
# add_test(NAME ssl_QUERY COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/query/query_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/query/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
# add_test(NAME ssl_CNAME COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/cname/cname_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/cname/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
# add_test(NAME ssl_NSEC_RR COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/nsec/nsec_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/nsec/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
# add_test(NAME ssl_NSEC_10_1_RR COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/nsec_10_1/nsec_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/nsec_10_1/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
# add_test(NAME ssl_NSEC3_RR COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/nsec3/nsec3_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/nsec3/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
# add_test(NAME ssl_PTR COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/ptr/ptr_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/ptr/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
# add_test(NAME ssl_SRV COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/srv/srv_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/srv/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
# add_test(NAME ssl_TXT COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/txt/txt_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/txt/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
# add_test(NAME ssl_HTTPS COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/https/https_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/https/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
# add_test(NAME ssl_CERT1 COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/cernet1/cernet1_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/cernet1/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
# add_test(NAME ssl_CERT2 COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/cernet2/cernet2_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/cernet2/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
# add_test(NAME ssl_SEC COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/sslsec/sslsec_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/sslsec/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
# add_test(NAME ssl_TCP_MULTI_TRANSCATION COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/multi_transcation/multi_transcation_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/multi_transcation/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
# add_test(NAME ssl_TCP_MULTI_PKT_TRANS_2BYTES COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/multi_pkt_trans_2bytes/multi_pkt_trans_2bytes_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/multi_pkt_trans_2bytes/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
# add_test(NAME ssl_TCP_LOST_PKT COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/tcp_lost_pkt/lost_pkt_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/tcp_lost_pkt/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
# add_test(NAME ssl_MULTI_SESSION COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/multi_session/multi_session_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/multi_session/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
# add_test(NAME ssl_NS_NSEC3_RRSIG_A_OPT COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/ns_nsec3_rrsig_a_opt/ns_nsec3_rrsig_a_opt_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/ns_nsec3_rrsig_a_opt/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
# add_test(NAME ssl_PORT5353 COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/port5353/port5353_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/port5353/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
# set_tests_properties(ssl_QUERY
# ssl_CNAME
# ssl_NSEC_RR
# ssl_NSEC_10_1_RR
# ssl_NSEC3_RR
# ssl_PTR
# ssl_SRV
# ssl_TXT
# ssl_HTTPS
# ssl_CERT1
# ssl_CERT2
# ssl_SEC
# ssl_TCP_MULTI_TRANSCATION
# ssl_TCP_MULTI_PKT_TRANS_2BYTES
# ssl_TCP_LOST_PKT
# ssl_MULTI_SESSION
# ssl_NS_NSEC3_RRSIG_A_OPT
# ssl_PORT5353
# PROPERTIES FIXTURES_REQUIRED TestFixture
# )

9
test/env/conflist.inf vendored Normal file
View File

@@ -0,0 +1,9 @@
[platform]
./plug/stellar_on_sapp/start_loader.inf
[protocol]
[business]
./plug/stellar_on_sapp/defer_loader.inf

Binary file not shown.

11
test/env/spec.toml vendored Normal file
View File

@@ -0,0 +1,11 @@
# stellar_plugin.toml
#
[[plugin]]
path = "./stellar_plugin/ssl_decoder.so"
init = "ssl_decoder_init"
exit = "ssl_decoder_exit"
[[plugin]]
path = "./stellar_plugin/ssl_decoder_test_plug.so"
init = "ssl_decoder_test_init"
exit = "ssl_decoder_test_exit"

17
test/env/start_loader.inf vendored Normal file
View File

@@ -0,0 +1,17 @@
[PLUGINFO]
PLUGNAME=stellar_start_loader
SO_PATH=./plug/stellar_on_sapp/stellar_on_sapp.so
INIT_FUNC=STELLAR_START_LOADER_INIT
DESTROY_FUNC=STELLAR_START_LOADER_EXIT
[TCP_ALL]
FUNC_FLAG=ALL
FUNC_NAME=stellar_on_sapp_tcpall_entry
[TCP]
FUNC_FLAG=ALL
FUNC_NAME=stellar_on_sapp_tcp_entry
[UDP]
FUNC_FLAG=ALL
FUNC_NAME=stellar_on_sapp_udp_entry

Binary file not shown.

View File

@@ -0,0 +1,227 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdint.h>
#include "ssl_decoder_perf_dummy.h"
#define MAX_SUBSCRIBE_TOPIC_NUM 16
#define MAX_MESSGEA_TOPIC_NUM 16
#define MAX_STELLAR_PLUGIN_NUM 16
struct stellar_plugin
{
void *plugin_env;
void *per_session_ctx;
session_ctx_new_func *session_ctx_new;
session_ctx_free_func *session_ctx_free;
};
struct message_topic
{
char *name;
void *msg_free_arg;
int on_msg_cb_idx;
session_msg_free_cb_func *msg_free_cb;
int on_msg_plugin_id[MAX_SUBSCRIBE_TOPIC_NUM];
on_session_msg_cb_func *plugin_on_msg_cb[MAX_SUBSCRIBE_TOPIC_NUM];
};
struct stellar
{
int topic_idx;
int plugin_idx;
int worker_thread_num;
int udp_topic_id;
int tcp_steam_topic_id;
struct message_topic topic[MAX_MESSGEA_TOPIC_NUM];
struct stellar_plugin plugin[MAX_STELLAR_PLUGIN_NUM];
};
struct session
{
int tid;
int topic_idx;
int plugin_idx;
struct message_topic *topic;
struct stellar_plugin *plugin;
struct stellar_packet *curr_msg;
struct session_addr addr;
char *readable_addr;
enum session_addr_type addr_type;
};
const char *session_get0_current_payload(struct session *ss, size_t *payload_sz)
{
if(ss->curr_msg==NULL)
{
*payload_sz=0;
return NULL;
}
*payload_sz=ss->curr_msg->payload_sz;
return (const char *)ss->curr_msg->payload;
}
int stellar_session_mq_create_topic(struct stellar *st, const char *topic_name, session_msg_free_cb_func *msg_free_cb, void *msg_free_arg)
{
int topic_id=st->topic_idx++;
st->topic[topic_id].name=strdup(topic_name);
st->topic[topic_id].msg_free_cb=msg_free_cb;
st->topic[topic_id].msg_free_arg=msg_free_arg;
return topic_id;
}
int stellar_session_mq_get_topic_id(struct stellar *st, const char *topic_name)
{
for(int i=0; i<st->topic_idx; i++)
{
if(strcmp(st->topic[i].name, topic_name)==0)
{
return i;
}
}
return -1;
}
int stellar_session_mq_subscribe(struct stellar *st, int topic_id, on_session_msg_cb_func *plugin_on_msg_cb, int plugin_id)
{
st->topic[topic_id].on_msg_plugin_id[st->topic[topic_id].on_msg_cb_idx]=plugin_id;
st->topic[topic_id].plugin_on_msg_cb[st->topic[topic_id].on_msg_cb_idx]=plugin_on_msg_cb;
st->topic[topic_id].on_msg_cb_idx++;
return 0;
}
int session_mq_publish_message(struct session *ss, int topic_id, void *msg)
{
for(int i=0; i<ss->topic[topic_id].on_msg_cb_idx; i++)
{
int plugin_id=ss->topic[topic_id].on_msg_plugin_id[i];
ss->topic[topic_id].plugin_on_msg_cb[i](ss, topic_id, msg, ss->plugin[plugin_id].per_session_ctx, ss->plugin[plugin_id].plugin_env);
}
if(ss->topic[topic_id].msg_free_cb!=NULL)
{
ss->topic[topic_id].msg_free_cb(ss, msg, ss->topic[topic_id].msg_free_arg);
}
return 0;
}
int session_mq_publish_message_by_name(struct session *ss, const char *topic_name, struct stellar_packet *msg)
{
for(int i=0; i<ss->topic_idx; i++)
{
if(strcmp(ss->topic[i].name, topic_name)==0)
{
ss->curr_msg=msg;
session_mq_publish_message(ss, i, (void *)msg);
break;
}
}
return 0;
}
int stellar_session_mq_destroy_topic(struct stellar *st, int topic_id)
{
return 0;
}
int stellar_session_plugin_register(struct stellar *st, session_ctx_new_func session_ctx_new, session_ctx_free_func session_ctx_free, void *plugin_env)
{
int plugin_id=st->plugin_idx++;
st->plugin[plugin_id].plugin_env=plugin_env;
st->plugin[plugin_id].session_ctx_new=session_ctx_new;
st->plugin[plugin_id].session_ctx_free=session_ctx_free;
return plugin_id;
}
struct session *stellar_session_new(struct stellar *st, struct stellar_packet *cur_pkt, int tid)
{
struct session *ss=(struct session *)malloc(sizeof(struct session));
ss->tid=tid;
ss->addr_type=cur_pkt->addr_type;
ss->readable_addr=cur_pkt->readable_addr;
memcpy(&(ss->addr), &(cur_pkt->addr), sizeof(struct session_addr));
ss->plugin=st->plugin;
ss->plugin_idx=st->plugin_idx;
ss->topic=st->topic;
ss->topic_idx=st->topic_idx;
for(int i=0; i<ss->plugin_idx; i++)
{
ss->plugin[i].per_session_ctx=ss->plugin[i].session_ctx_new(ss, ss->plugin[i].plugin_env);
}
return ss;
}
int session_get_current_thread_id(struct session *ss)
{
return ss->tid;
}
struct session_addr *session_get0_addr(struct session *ss, enum session_addr_type *addr_type)
{
*addr_type=ss->addr_type;
return &(ss->addr);
}
void stellar_session_plugin_dettach_current_session(struct session *ss)
{
}
int session_is_innermost(struct session *ss, uint64_t *flag)
{
*flag=0;
return 1;
}
enum session_state session_get_current_state(struct session *ss)
{
return SESSION_STATE_ACTIVE;
}
const char *session_get0_readable_addr(struct session *ss)
{
return ss->readable_addr;
}
void stellar_session_free(struct session *ss)
{
for(int i=0; i<ss->plugin_idx; i++)
{
ss->plugin[i].session_ctx_free(ss, ss->plugin[i].per_session_ctx, ss->plugin[i].plugin_env);
}
free(ss);
}
struct stellar *stellar_init(int worker_thread_num)
{
struct stellar *st=(struct stellar *)malloc(sizeof(struct stellar));
st->topic_idx=0;
st->plugin_idx=0;
st->worker_thread_num=worker_thread_num;
st->udp_topic_id=stellar_session_mq_create_topic(st, TOPIC_UDP, NULL, NULL);
st->tcp_steam_topic_id=stellar_session_mq_create_topic(st, TOPIC_TCP_STREAM, NULL, NULL);
return st;
}
int stellar_get_worker_thread_num(struct stellar *st)
{
return st->worker_thread_num;
}

View File

@@ -0,0 +1,32 @@
#pragma once
#ifdef __cplusplus
extern "C"
{
#endif
#include "stellar/stellar.h"
#include "stellar/session.h"
#include <stellar/session_mq.h>
void perf_resource_record_decode(struct ssl_message *ssl_msg);
#ifdef __cplusplus
}
#endif
struct stellar_packet
{
size_t payload_sz;
uint8_t payload[2048];
struct session_addr addr;
char *readable_addr;
enum session_addr_type addr_type;
};
struct stellar *stellar_init(int worker_thread_num);
struct session *stellar_session_new(struct stellar *st, struct stellar_packet *cur_pkt, int tid);
void stellar_session_free(struct session *ss);
int session_mq_publish_message_by_name(struct session *ss, const char *topic_name, struct stellar_packet *msg);

View File

@@ -0,0 +1,264 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdint.h>
#include <time.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <arpa/inet.h>
#include "cJSON.h"
#include "fieldstat/fieldstat_easy.h"
#include <stellar/utils.h>
#include "stellar/stellar.h"
#include <stellar/session_mq.h>
#include "ssl_decoder.h"
#include "toml/toml.h"
#include "ssl_decoder_perf_dummy.h"
#define ssl_DECODER_TEST_TOML_PATH "./etc/ssl/ssl_decoder.toml"
#define TIME_START() struct timespec _start_time, _end_time; clock_gettime(CLOCK_REALTIME, &_start_time)
#define TIME_DIFF() \
long long time_diff_ns;\
do { \
clock_gettime(CLOCK_REALTIME, &_end_time); \
if (likely(_end_time.tv_sec == _start_time.tv_sec))\
{\
time_diff_ns = (_end_time.tv_nsec - _start_time.tv_nsec);\
}else{\
time_diff_ns = (_end_time.tv_sec * 1000 * 1000 * 1000 + _end_time.tv_nsec) - (_start_time.tv_sec * 1000 * 1000 * 1000 + _start_time.tv_nsec);\
}\
}while (0)
struct ssl_decoder_context;
struct ssl_decoder_plugin_env;
enum PERF_TAG
{
PERF_TAG_QUESTION,
PERF_TAG_RESOURCE_RECORD,
PERF_TAG_MAX
};
struct fs_easy_schame
{
int id[PERF_TAG_MAX];
struct field tag[PERF_TAG_MAX];
struct fieldstat_easy *handle;
};
struct perf_main_env
{
int worker_thread_num;
int *worker_thread_pid;
int n_worker_thread_pid;
struct fs_easy_schame fse;
struct stellar *st;
struct stellar_packet *response;
};
// form ssl_decoder_test.cpp
extern "C" void *ssl_decoder_test_init(struct stellar *st);
extern "C" void *ssl_decoder_init(struct stellar *st);
thread_local int local_worker_thread_id=-1;
int firewall_current_worker_thread_id_get(struct perf_main_env *main_env)
{
if (local_worker_thread_id==-1)
{
pid_t my_pid = syscall(SYS_gettid);
for(int i=0; i<main_env->n_worker_thread_pid; i++)
{
if (my_pid==main_env->worker_thread_pid[i])
{
local_worker_thread_id=i;
return local_worker_thread_id;
}
}
main_env->worker_thread_pid[main_env->n_worker_thread_pid]=my_pid;
local_worker_thread_id=main_env->n_worker_thread_pid++;
}
return local_worker_thread_id;
}
extern "C" int commit_test_result_json(cJSON *node, const char *name)
{
char *real_result_str=cJSON_Print(node);
printf("%s\n", real_result_str);
free(real_result_str);
cJSON_Delete(node);
return 0;
}
void *pthread_message_publish(void *arg)
{
struct perf_main_env *main_env=(struct perf_main_env *)arg;
int tid=firewall_current_worker_thread_id_get(main_env);
struct session *ss=stellar_session_new(main_env->st, main_env->response, tid);
while(1)
{
TIME_START();
session_mq_publish_message_by_name(ss, TOPIC_UDP, main_env->response);
TIME_DIFF();
fieldstat_easy_histogram_record(main_env->fse.handle, tid, main_env->fse.id[PERF_TAG_QUESTION], &(main_env->fse.tag[PERF_TAG_QUESTION]), 1, time_diff_ns);
}
stellar_session_free(ss);
}
static void main_stat_init(struct perf_main_env *main_env)
{
main_env->fse.handle=fieldstat_easy_new(main_env->worker_thread_num, "ssl_decoder_perf_test", NULL, 0);
fieldstat_easy_enable_auto_output(main_env->fse.handle, "./metrics/ssl_decoder_perf_test.json", 1);
main_env->fse.tag[PERF_TAG_QUESTION].key="question";
main_env->fse.tag[PERF_TAG_QUESTION].type=FIELD_VALUE_DOUBLE;
main_env->fse.tag[PERF_TAG_QUESTION].value_double=0.00001;
main_env->fse.id[PERF_TAG_QUESTION]=fieldstat_easy_register_histogram(main_env->fse.handle, "question", 1, 99999999, 5);
main_env->fse.tag[PERF_TAG_RESOURCE_RECORD].key="resource_record";
main_env->fse.tag[PERF_TAG_RESOURCE_RECORD].type=FIELD_VALUE_DOUBLE;
main_env->fse.tag[PERF_TAG_RESOURCE_RECORD].value_double=0.00001;
main_env->fse.id[PERF_TAG_RESOURCE_RECORD]=fieldstat_easy_register_histogram(main_env->fse.handle, "resource-record", 1, 99999999, 5);
}
void display_packet(struct stellar_packet *cur_pkt)
{
printf("query.payload_sz=%zu\n", cur_pkt->payload_sz);
for(size_t i=0; i<cur_pkt->payload_sz; i++)
{
printf("%02x ", cur_pkt->payload[i]);
if(i>0 && (i%16==0))
{
printf("\n");
}
}
printf("\n");
}
size_t hex_string_to_byte_array(const char *hex_str, size_t hex_str_sz, unsigned char *byte_array, size_t byte_array_sz)
{
size_t offset=0;
for(size_t i=0; i<hex_str_sz; i+=2)
{
sscanf(hex_str+i, "%2hhx", &byte_array[offset++]);
}
return offset;
}
int32_t ssl_decoder_test_config_load(const char *cfg_path, struct perf_main_env *main_env)
{
FILE *fp=fopen(cfg_path, "r");
if (NULL==fp)
{
fprintf(stderr, "[%s:%d] Can't open config file: %s", __FUNCTION__, __LINE__, cfg_path);
return -1;
}
int32_t ret=0;
char errbuf[256]={0};
toml_table_t *root=toml_parse_file(fp, errbuf, sizeof(errbuf));
fclose(fp);
toml_table_t *decoder_tbl=toml_table_in(root, "decoder");
if(NULL==decoder_tbl)
{
fprintf(stderr, "[%s:%d] config file: %s has no key: [decoder]", __FUNCTION__, __LINE__, cfg_path);
toml_free(root);
return -1;
}
toml_table_t *ssl_tbl=toml_table_in(decoder_tbl, "ssl");
if(NULL==ssl_tbl)
{
fprintf(stderr, "[%s:%d] config file: %s has no key: [decoder.ssl]", __FUNCTION__, __LINE__, cfg_path);
toml_free(root);
return -1;
}
toml_table_t *test_tbl=toml_table_in(ssl_tbl, "test");
if(NULL==test_tbl)
{
fprintf(stderr, "[%s:%d] config file: %s has no key: [decoder.ssl.test]", __FUNCTION__, __LINE__, cfg_path);
toml_free(root);
return -1;
}
toml_table_t *perf_tbl=toml_table_in(test_tbl, "perf");
if(NULL==perf_tbl)
{
fprintf(stderr, "[%s:%d] config file: %s has no key: [decoder.ssl.test.perf]", __FUNCTION__, __LINE__, cfg_path);
toml_free(root);
return -1;
}
toml_datum_t perf_worker_thread_num_val=toml_int_in(perf_tbl, "perf_worker_thread_num");
if(perf_worker_thread_num_val.ok)
{
main_env->worker_thread_num=perf_worker_thread_num_val.u.i;
}
else
{
main_env->worker_thread_num=1;
fprintf(stderr, "[%s:%d] config file: %s has no key: [decoder.ssl.test.perf_worker_thread_num]", __FUNCTION__, __LINE__, cfg_path);
}
toml_free(root);
return ret;
}
int main(int argc, char *argv[])
{
struct perf_main_env *main_env=(struct perf_main_env *)calloc(1, sizeof(struct perf_main_env));
ssl_decoder_test_config_load(ssl_DECODER_TEST_TOML_PATH, main_env);
main_stat_init(main_env);
main_env->st=stellar_init(main_env->worker_thread_num);
ssl_decoder_init(main_env->st);
ssl_decoder_test_init(main_env->st);
main_env->n_worker_thread_pid=0;
main_env->worker_thread_pid=(int *)calloc(main_env->worker_thread_num, sizeof(int));
// Internet Protocol Version 6, Src=2001:503:231d::2:30 Dst=2001:da8:2008::10
struct stellar_packet *response=(struct stellar_packet *)calloc(1, sizeof(struct stellar_packet));
main_env->response=response;
response->addr_type=SESSION_ADDR_TYPE_IPV6_UDP;
response->readable_addr=(char *)("s=2001:503:231d::2:30.23856 d=2001:da8:2008::10.53");
inet_pton(AF_INET6, "2001:da8:2008::10", response->addr.ipv6.daddr);
inet_pton(AF_INET6, "2001:503:231d::2:30", response->addr.ipv6.saddr);
response->addr.ipv6.dport=htons(53);
response->addr.ipv6.sport=htons(23856);
const char *response_hex_str="ce268000000100000006001404646174610862696c6963646e3203636f6d0000410001c011000200010002a300000c036e733305646e737635c01ac011000200010002a3000006036e7334c03320434b30504f4a4d473837344c4a5245463745464e38343330515649543842534dc01a003200010001518000230101000000146501a0c25720ee156f6c4e39636b3ada0312d92a000722000000000290c04d002e00010001518000b700320802000151806188b454617f5b5c3cbd03636f6d001f77dc4c5796eda9ced317925c67d91c52922152424c9dca024948c1169e8429053fdf50a23370d9c3dc79de909f2f79475b2c731d6060d1db7b5d294b8ee43c91a57b8a4afa06c25fb13127bfca3fb353c7d5a38eaf093e12ffa1e33bc80bd7118851ca730ed22bd27b6f16673b86b44898785c6e13b3dd3620750492e47bb8ca823ffa6e25225ffa5408184c25e4ff423497802deed0586629d78103b3e6e72039454d4644425347524c48514f4d4736515441534e534c4151343438454b4644c01a003200010001518000220101000000144bad0970b67bda0a716dcd12979d4451b22f7ac50006200000000012c160002e00010001518000b700320802000151806188bdde617f64e63cbd03636f6d00a9de4aee30c79978429e76969d02d2bd4c8942f1b4329a643e9d7703e9fd46dd9ab32c4feffe1f9fbed3418e40d42a00fe2c1c2cac66e1c718bf508c4f603171f9ea18e8e79a533d136c26907576ab033dc48e4ff3b355346c33ac54a359c9572c308c923f910e470315dd4de40bd3b443b7caa34309b22146dca1ed6f4758a476052fc8a33829216c5abe88f21981dfe8ae9b2b204958aac575bfaa9847af3ec02f000100010002a300000481d3b0d4c02f000100010002a3000004a20e12bcc02f000100010002a3000004a20e18fbc02f000100010002a3000004a20e19fbc02f000100010002a300000412c20289c02f000100010002a3000004b7c0c95ec02f000100010002a3000004dfa69710c02f001c00010002a300001024024e0014301102000091362b2bba61c02f000100010002a3000004344dee5cc02f000100010002a30000043d97b433c047000100010002a300000465e2dc0cc047000100010002a300000481d3b097c047000100010002a3000004a20e18f8c047000100010002a3000004a20e19f8c047000100010002a3000004b7c0a477c047000100010002a3000004dfa6977ec047001c00010002a300001024024e00102012640000913629b6fc32c047000100010002a300000434c69f92c047000100010002a30000043b2478930000291000000080000000";
response->payload_sz=hex_string_to_byte_array(response_hex_str, strlen(response_hex_str), response->payload, sizeof(response->payload));
//display_packet(response);
for(int i=0; i<main_env->worker_thread_num; i++)
{
pthread_t ptid;
pthread_create(&ptid, NULL, pthread_message_publish, (void *)main_env);
}
while(1)
{
sleep(1);
}
return 0;
}

221
test/ssl_decoder_test.cpp Normal file
View File

@@ -0,0 +1,221 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <assert.h>
#ifdef __cplusplus
extern "C"
{
#include "cJSON.h"
#include "ssl_decoder.h"
#include "toml/toml.h"
#include "stellar/stellar.h"
#include "stellar/session.h"
#include "stellar/session_exdata.h"
#include "stellar/session_mq.h"
}
#endif
#include "ssl_decoder.h"
#define ssl_DECODER_TEST_TOML_PATH "./etc/ssl/ssl_decoder.toml"
struct ssl_decoder_test_plugin_env
{
int plugin_id;
int topic_id;
int result_index;
int commit_result_enable;
int decode_resource_record_enable;
int export_resource_record_enable;
};
extern "C" void perf_resource_record_decode(struct ssl_message *ssl_msg);
extern "C" int commit_test_result_json(cJSON *node, const char *name);
void ssl_real_result_write_file(char *result_str)
{
FILE *fp=fopen("ssl_real_result.json", "a+");
if(fp!=NULL)
{
fwrite(result_str, 1, strlen(result_str), fp);
fclose(fp);
}
}
void ssl_decoder_test_message_cb(struct session *ss, int topic_id, const void *msg, void *per_session_ctx, void *plugin_env_str)
{
}
void *ssl_decoder_test_per_session_context_new(struct session *sess, void *plugin_env)
{
return NULL;
}
void ssl_decoder_test_per_session_context_free(struct session *sess, void *session_ctx, void *plugin_env)
{
}
int32_t ssl_decoder_test_config_load(const char *cfg_path, struct ssl_decoder_test_plugin_env *plugin_env)
{
FILE *fp=fopen(cfg_path, "r");
if (NULL==fp)
{
fprintf(stderr, "[%s:%d] Can't open config file: %s", __FUNCTION__, __LINE__, cfg_path);
return -1;
}
int32_t ret=0;
char errbuf[256]={0};
toml_table_t *root=toml_parse_file(fp, errbuf, sizeof(errbuf));
fclose(fp);
toml_table_t *decoder_tbl=toml_table_in(root, "decoder");
if(NULL==decoder_tbl)
{
fprintf(stderr, "[%s:%d] config file: %s has no key: [decoder]", __FUNCTION__, __LINE__, cfg_path);
toml_free(root);
return -1;
}
toml_table_t *ssl_tbl=toml_table_in(decoder_tbl, "ssl");
if(NULL==ssl_tbl)
{
fprintf(stderr, "[%s:%d] config file: %s has no key: [decoder.ssl]", __FUNCTION__, __LINE__, cfg_path);
toml_free(root);
return -1;
}
toml_table_t *test_tbl=toml_table_in(ssl_tbl, "test");
if(NULL==test_tbl)
{
fprintf(stderr, "[%s:%d] config file: %s has no key: [decoder.ssl.test]", __FUNCTION__, __LINE__, cfg_path);
toml_free(root);
return -1;
}
toml_datum_t commit_result_enable_val=toml_string_in(test_tbl, "commit_result_enable");
if(commit_result_enable_val.ok==0)
{
plugin_env->commit_result_enable=0;
fprintf(stderr, "[%s:%d] config file: %s has no key: [decoder.ssl.test.commit_result_enable]", __FUNCTION__, __LINE__, cfg_path);
}
else
{
if(memcmp("no", commit_result_enable_val.u.s, strlen("no"))==0)
{
plugin_env->commit_result_enable=0;
}
else if(memcmp("yes", commit_result_enable_val.u.s, strlen("yes"))==0)
{
plugin_env->commit_result_enable=1;
}
else
{
plugin_env->commit_result_enable=1;
fprintf(stderr, "[%s:%d] config file: %s key: [decoder.ssl.test.commit_result_enable] value is not yes or no", __FUNCTION__, __LINE__, cfg_path);
}
}
toml_table_t *perf_tbl=toml_table_in(test_tbl, "perf");
if(NULL==perf_tbl)
{
fprintf(stderr, "[%s:%d] config file: %s has no key: [decoder.ssl.test.perf]", __FUNCTION__, __LINE__, cfg_path);
toml_free(root);
return -1;
}
// decode_resource_record_enable
toml_datum_t decode_resource_record_enable_val=toml_string_in(perf_tbl, "decode_resource_record_enable");
if(decode_resource_record_enable_val.ok==0)
{
plugin_env->decode_resource_record_enable=0;
fprintf(stderr, "[%s:%d] config file: %s has no key: [decoder.ssl.test.decode_resource_record_enable]", __FUNCTION__, __LINE__, cfg_path);
}
else
{
if(memcmp("no", decode_resource_record_enable_val.u.s, strlen("no"))==0)
{
plugin_env->decode_resource_record_enable=0;
}
else if(memcmp("yes", decode_resource_record_enable_val.u.s, strlen("yes"))==0)
{
plugin_env->decode_resource_record_enable=1;
}
else
{
plugin_env->decode_resource_record_enable=1;
fprintf(stderr, "[%s:%d] config file: %s key: [decoder.ssl.test.decode_resource_record_enable] value is not yes or no", __FUNCTION__, __LINE__, cfg_path);
}
}
// export_resource_record_enable
toml_datum_t export_resource_record_enable_val=toml_string_in(perf_tbl, "export_resource_record_enable");
if(export_resource_record_enable_val.ok==0)
{
plugin_env->export_resource_record_enable=0;
fprintf(stderr, "[%s:%d] config file: %s has no key: [decoder.ssl.test.export_resource_record_enable]", __FUNCTION__, __LINE__, cfg_path);
}
else
{
if(memcmp("no", export_resource_record_enable_val.u.s, strlen("no"))==0)
{
plugin_env->export_resource_record_enable=0;
}
else if(memcmp("yes", export_resource_record_enable_val.u.s, strlen("yes"))==0)
{
plugin_env->export_resource_record_enable=1;
}
else
{
plugin_env->export_resource_record_enable=1;
fprintf(stderr, "[%s:%d] config file: %s key: [decoder.ssl.test.export_resource_record_enable] value is not yes or no", __FUNCTION__, __LINE__, cfg_path);
}
}
toml_free(root);
return ret;
}
extern "C" void *ssl_decoder_test_init(struct stellar *st)
{
struct ssl_decoder_test_plugin_env *plugin_env=(struct ssl_decoder_test_plugin_env *)calloc(1, sizeof(struct ssl_decoder_test_plugin_env));
plugin_env->result_index=1;
ssl_decoder_test_config_load(ssl_DECODER_TEST_TOML_PATH, plugin_env);
plugin_env->plugin_id=stellar_session_plugin_register(st, ssl_decoder_test_per_session_context_new, ssl_decoder_test_per_session_context_free, plugin_env);
if(plugin_env->plugin_id<0)
{
printf("ssl_decoder_test_init: stellar_plugin_register failed !!!\n");
exit(-1);
}
plugin_env->topic_id=stellar_session_mq_get_topic_id(st, SSL_DECODER_MESSAGE_TOPIC);
if(plugin_env->topic_id<0)
{
printf("stellar_session_mq_get_topic_id failed, topic: %s \n", SSL_DECODER_MESSAGE_TOPIC);
exit(-1);
}
stellar_session_mq_subscribe(st, plugin_env->topic_id, ssl_decoder_test_message_cb, plugin_env->plugin_id);
return (void *)plugin_env;
}
extern "C" void ssl_decoder_test_exit(void *plugin_env_str)
{
if(plugin_env_str!=NULL)
{
free(plugin_env_str);
}
}

28
vendor/CMakeLists.txt vendored Normal file
View File

@@ -0,0 +1,28 @@
# CMakeFiles for 3rd vendor library
include(ExternalProject)
### OpenSSL 1.1.1m
ExternalProject_Add(openssl PREFIX openssl
URL ${CMAKE_CURRENT_SOURCE_DIR}/openssl-1.1.1m.tar.gz
URL_MD5 8ec70f665c145c3103f6e330f538a9db
CONFIGURE_COMMAND ./Configure linux-x86_64 --prefix=<INSTALL_DIR> --openssldir=<INSTALL_DIR>/lib/ssl -fPIC no-shared
BUILD_COMMAND ${MAKE_COMMAND}
INSTALL_COMMAND make install_sw
BUILD_IN_SOURCE 1)
ExternalProject_Get_Property(openssl INSTALL_DIR)
set(OPENSSL_INCLUDE_DIRECTORIES ${INSTALL_DIR}/include)
set(OPENSSL_LINK_DIRECTORIES ${INSTALL_DIR}/lib)
set(OPENSSL_PKGCONFIG_PATH ${INSTALL_DIR}/lib/pkgconfig/)
file(MAKE_DIRECTORY ${INSTALL_DIR}/include)
add_library(openssl-crypto-static STATIC IMPORTED GLOBAL)
add_dependencies(openssl-crypto-static openssl)
set_property(TARGET openssl-crypto-static PROPERTY IMPORTED_LOCATION ${INSTALL_DIR}/lib/libcrypto.a)
set_property(TARGET openssl-crypto-static PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${INSTALL_DIR}/include)
add_library(openssl-ssl-static STATIC IMPORTED GLOBAL)
add_dependencies(openssl-ssl-static openssl)
set_property(TARGET openssl-ssl-static PROPERTY IMPORTED_LOCATION ${INSTALL_DIR}/lib/libssl.a)
set_property(TARGET openssl-ssl-static PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${INSTALL_DIR}/include)

BIN
vendor/openssl-1.1.1m.tar.gz vendored Normal file

Binary file not shown.