├── .idea ├── .name ├── scopes │ └── Sources.xml ├── .gitignore ├── externalDependencies.xml ├── copyright │ ├── profiles_settings.xml │ └── libsese_Default_Copyright.xml └── icon.svg ├── .vscode ├── .gitignore ├── extensions.json └── readme.md ├── scripts ├── .gitignore ├── README.md ├── do_websocket.py ├── dns_client.py ├── do_http2_request.py └── cmake_format.py ├── package ├── ports │ └── sese │ │ ├── vcpkg.json │ │ └── usage ├── main.cpp ├── vcpkg.json └── CMakeLists.txt ├── .github ├── ISSUE_TEMPLATE │ ├── config.yml │ ├── general.yml │ ├── new_feature.yml │ └── bug_report.yml └── workflows │ └── gh-pages.yml ├── sese ├── test │ ├── TestResource │ │ ├── .gitignore │ │ ├── Resource.json │ │ └── TestResource.cpp │ ├── Data │ │ ├── data-0.txt │ │ ├── logo.ico │ │ ├── archive.zip │ │ ├── data.ini │ │ ├── checksum-size-112.txt │ │ ├── checksum-size-122.txt │ │ ├── checksum-size-128.txt │ │ ├── data.xml │ │ ├── data.json │ │ ├── data-1.txt │ │ └── test-ca.crt │ ├── manifest.json │ ├── README.md │ ├── TestDB │ │ └── Config.h │ ├── AllTest.cpp │ ├── TestUniReader.cpp │ ├── TestPlugin │ │ └── Module.m.cpp │ ├── TestSymbol.cpp │ ├── TestWebsocketService.cpp │ ├── TestIPC │ │ └── IPC.d.cpp │ ├── TestStrCaseMap.cpp │ ├── TestEncodingConverter.cpp │ └── TestNetworkUtil.cpp ├── security │ ├── evp │ │ ├── README.md │ │ ├── SM3Context.h │ │ ├── Context.h │ │ ├── MD5Context.h │ │ ├── SHA1Context.h │ │ ├── SHA256Context.h │ │ ├── SHA384Context.h │ │ ├── SHA512Context.h │ │ └── SM3Context.cpp │ ├── SecurityConfig.cpp │ ├── SecurityConfig.h │ └── SSLContextBuilder.cpp ├── example │ ├── manifest.json │ └── CMakeLists.txt ├── manifest.json ├── archive │ ├── CMakeLists.txt │ ├── ArchiveInputStream.cpp │ ├── ArchiveOutputStream.cpp │ ├── ArchiveInputStream.h │ ├── ArchiveOutputStream.h │ └── Config.h ├── Log.h ├── Util.h ├── Init.h ├── net │ ├── AddressPool.cpp │ ├── http │ │ ├── HeaderBuilder.cpp │ │ ├── Response.cpp │ │ ├── HttpConverter.h │ │ ├── Request.cpp │ │ ├── Request.h │ │ ├── Response.h │ │ ├── HeaderBuilder.h │ │ ├── RequestParser.h │ │ └── HttpServletContext.h │ ├── IPAddress.cpp │ └── dns │ │ └── DnsPackage_Flags.cpp ├── types │ ├── defines.h │ ├── is_pair.h │ └── is_iterable.h ├── service │ ├── Service.cpp │ ├── dns │ │ └── Config.h │ └── Service.h ├── benchmark │ ├── CMakeLists.txt │ └── BM_StringBuilder.cpp ├── util │ ├── ErrorCode.cpp │ ├── ZlibConfig.h │ ├── EncodingConverter.cpp │ ├── StopWatch.cpp │ ├── NotInstantiable.h │ ├── Noncopyable.h │ ├── StopWatch.h │ ├── EncodingConverter.h │ ├── UuidBuilder.h │ ├── GZipFileInputStream.cpp │ ├── Singleton.h │ ├── ErrorCode.h │ └── TimestampHandler.h ├── io │ ├── File.h │ ├── NullOutputStream.cpp │ ├── ConsoleOutputStream.cpp │ ├── InputBuffer.h │ ├── OutputStream.cpp │ ├── OutputBuffer.h │ ├── Closeable.h │ ├── RandomInputStream.h │ ├── FixedBuilder.h │ ├── Stream.h │ ├── ConsoleOutputStream.h │ ├── NullOutputStream.h │ ├── RandomInputStream.cpp │ ├── InputStream.h │ ├── ByteBuilder.h │ ├── InputStreamReader.h │ ├── PeekableStream.h │ ├── OutputBufferWrapper.h │ └── FixedBuffer.h ├── log │ ├── AbstractAppender.cpp │ ├── AbstractFormatter.h │ ├── FileAppender.cpp │ ├── Marco.h │ ├── ConsoleAppender.h │ └── FileAppender.h ├── internal │ ├── unix │ │ ├── thread │ │ │ └── GlobalThreadPool.cpp │ │ ├── system │ │ │ └── Path.cpp │ │ └── security │ │ │ └── evp │ │ │ ├── MD5Context.cpp │ │ │ ├── SHA1Context.cpp │ │ │ ├── SHA256Context.cpp │ │ │ ├── SHA384Context.cpp │ │ │ └── SHA512Context.cpp │ ├── service │ │ └── http │ │ │ ├── ConnType.h │ │ │ └── Handleable.h │ ├── win │ │ └── thread │ │ │ └── GlobalThreadPool.cpp │ └── net │ │ └── AsioSSLContextConvert.h ├── db │ ├── Config.h │ ├── Metadata.h │ ├── Util.h │ ├── Util.cpp │ └── DriverManager.h ├── thread │ ├── SpinLock.cpp │ ├── SpinLock.h │ └── Locker.h ├── res │ ├── ResourceManager.cpp │ └── Resource.cpp ├── text │ ├── String.h │ ├── Util.h │ ├── Util.cpp │ └── TextReader.h ├── system │ ├── FileNotifier.cpp │ ├── Library.cpp │ ├── ProcessBuilder.cpp │ ├── CommandLine.cpp │ ├── Paths.h │ ├── NetworkUtil.h │ ├── SharedMemory.cpp │ └── CommandLine.h ├── plugin │ ├── BaseClass.h │ ├── ModuleInfo.h │ └── ClassFactory.cpp ├── CATALOG.md ├── config │ ├── ini │ │ └── IniConfig.h │ └── CSVWriter.cpp ├── container │ └── StrCaseMap.cpp └── DarwinConfig.h ├── docs └── Meta.txt ├── .cmake-format.yaml ├── .devcontainer ├── Alpine-x64 │ └── devcontainer.json └── StandardConfig │ └── devcontainer.json ├── AUTHORS.md ├── .tokeignore ├── cmake ├── Coverage.cmake ├── sese-config.cmake.in ├── Manifest.cmake ├── Options.cmake └── Asan.cmake ├── .editorconfig ├── .gitattributes ├── CMakeLists.txt ├── requirements.txt ├── .gitlab └── merge_request_templates │ └── default.md ├── gcovr.cfg ├── docker ├── docker-compose.yml ├── alpine-x64.dockerfile └── ubuntu-arm64.dockerfile ├── SECURITY.md ├── schema ├── resource.schema.json └── manifest.schema.json ├── ROADMAP.md ├── static └── image │ └── logo.svg └── CMakePresets.json /.idea/.name: -------------------------------------------------------------------------------- 1 | Sese Framework -------------------------------------------------------------------------------- /.vscode/.gitignore: -------------------------------------------------------------------------------- 1 | /settings.json -------------------------------------------------------------------------------- /scripts/.gitignore: -------------------------------------------------------------------------------- 1 | *.tar.gz 2 | *.zip -------------------------------------------------------------------------------- /package/ports/sese/vcpkg.json: -------------------------------------------------------------------------------- 1 | ../../../vcpkg.json -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: true -------------------------------------------------------------------------------- /sese/test/TestResource/.gitignore: -------------------------------------------------------------------------------- 1 | /Resource.* 2 | 3 | !/Resource.json -------------------------------------------------------------------------------- /sese/test/Data/data-0.txt: -------------------------------------------------------------------------------- 1 | Hello 2 | 3 | 你好 4 | 5 | こんにちは 6 | 7 | привет -------------------------------------------------------------------------------- /sese/test/Data/logo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libsese/sese/HEAD/sese/test/Data/logo.ico -------------------------------------------------------------------------------- /sese/test/Data/archive.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/libsese/sese/HEAD/sese/test/Data/archive.zip -------------------------------------------------------------------------------- /docs/Meta.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /sese/test/Data/data.ini: -------------------------------------------------------------------------------- 1 | ; default section 2 | name = "Test File 嘿嘿" 3 | 4 | [server] 5 | address = 127.0.0.1 6 | port = 7890 -------------------------------------------------------------------------------- /.cmake-format.yaml: -------------------------------------------------------------------------------- 1 | line_width: 120 2 | line_ending: windows 3 | tab_size: 4 4 | autosort: true 5 | dangle_parens: true 6 | enable_markup: true -------------------------------------------------------------------------------- /sese/test/Data/checksum-size-112.txt: -------------------------------------------------------------------------------- 1 | J2kqzRtl+QiVAjfUEJPLp&KYK2_#taIcXyvucyrmM#LfF_V=Ymu2xScSA60C%y_Io#93yZpKhsWcKn3gmbys9m9hXGN*p27YfIiC3HGyWat-_4Wy -------------------------------------------------------------------------------- /package/ports/sese/usage: -------------------------------------------------------------------------------- 1 | sese provides CMake targets: 2 | 3 | find_package(sese CONFIG REQUIRED) 4 | target_link_libraries(main PRIVATE Sese::Core) 5 | -------------------------------------------------------------------------------- /sese/test/Data/checksum-size-122.txt: -------------------------------------------------------------------------------- 1 | eZNiojRQFHDk$S*7VRNotGsay=ROpcXTp+b_wfZDTbI*alYag#YcD*B7&8fvqE&CXtmaSCcDf1c6qZZYUYS6MZF+k9spUxhR+r@9!qhq#mI8qpDlxD@fipAz$m -------------------------------------------------------------------------------- /sese/test/Data/checksum-size-128.txt: -------------------------------------------------------------------------------- 1 | h%s9whzHz$7R$pOk@Fvsv$IQC%fBB@S4jnVkH!hcOHvAz_Td2-H6BkKZIo!V29sB=RhVR9PYmniCziWcpGRUKd41ra35z7$nW1hIFj^n=IP_H6#Po+hd8W2TN$G+1XUW -------------------------------------------------------------------------------- /.devcontainer/Alpine-x64/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Alpine-x64", 3 | "build": { 4 | "context": "../../", 5 | "dockerfile": "../../docker/alpine-x64.dockerfile" 6 | } 7 | } -------------------------------------------------------------------------------- /.idea/scopes/Sources.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.devcontainer/StandardConfig/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "StandardConfig", 3 | "build": { 4 | "context": "../../", 5 | "dockerfile": "../../docker/ubuntu-x64.dockerfile" 6 | } 7 | } -------------------------------------------------------------------------------- /package/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char **argv) { 5 | sese::initCore(argc, argv); 6 | SESE_INFO("hello sese"); 7 | return 0; 8 | } -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | /fileTemplates 2 | 3 | *.xml 4 | *.iml 5 | 6 | !/copyright/libsese_Default_Copyright.xml 7 | !/copyright/profiles_settings.xml 8 | !/scopes/Sources.xml 9 | !/externalDependencies.xml 10 | -------------------------------------------------------------------------------- /package/vcpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": [ 3 | { 4 | "name": "sese", 5 | "features": [ 6 | "archive", 7 | "mysql", 8 | "psql" 9 | ] 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /sese/test/TestResource/Resource.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/libsese/sese/refs/heads/main/schema/resource.schema.json", 3 | "icon": "Data/logo.ico", 4 | "binaries": { 5 | "hello": "Data/data.xml" 6 | } 7 | } -------------------------------------------------------------------------------- /AUTHORS.md: -------------------------------------------------------------------------------- 1 | # AUTHORS 2 | 3 | This list includes individuals who have contributed code and maintained this project. 4 | 5 | If there are any omissions, please contact the address below. 6 | 7 | > mail: shiina_kaoru@outlook.com 8 | 9 | - SHIINASAMA 10 | - DreamerQcl 11 | -------------------------------------------------------------------------------- /.idea/externalDependencies.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.tokeignore: -------------------------------------------------------------------------------- 1 | /.github 2 | /.gitlab 3 | /.vscode 4 | /.idea 5 | /docker 6 | /docs 7 | /package 8 | /scripts 9 | 10 | /sese/test 11 | /sese/benchmark 12 | 13 | /build 14 | /build-* 15 | /cmake-build-* 16 | 17 | LICENSE 18 | NOTICE 19 | requirements.txt 20 | *.md 21 | *.json 22 | *.cfg 23 | *.yml 24 | *.svg -------------------------------------------------------------------------------- /cmake/Coverage.cmake: -------------------------------------------------------------------------------- 1 | if(SESE_ENABLE_COVERAGE) 2 | if(MSVC) 3 | message(WARNING "Coverage test flags are used on unsupported compilers and have been forced to be disabled.") 4 | else() 5 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fprofile-update=atomic") 6 | endif() 7 | endif() 8 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # The line splitter should be specified in `.gitattributes` 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 4 7 | insert_final_newline = false 8 | trim_trailing_whitespace = true 9 | charset = utf-8 10 | 11 | [*.{yml,yaml,json,clang-format,clang-tidy}] 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /scripts/README.md: -------------------------------------------------------------------------------- 1 | # Functional Scripts 2 | 3 | > [!WARNING] 4 | > Git cannot and does not manage file permissions. So, please ensure that submitted files retain their original attributes. 5 | 6 | Run the following command to ignore related file mode changes: 7 | 8 | ```bash 9 | git config core.filemode false 10 | ``` 11 | -------------------------------------------------------------------------------- /sese/security/evp/README.md: -------------------------------------------------------------------------------- 1 | # Encryption and Decryption Functions 2 | 3 | Hash digest algorithms can use a unified interface based on Context implementations such as MD5Context, SHA256Context, and SM3Context. 4 | 5 | For encryption and decryption related algorithms, such as AES, RSA, and SM4, please directly use the EVP module implemented within OpenSSL. 6 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.md text eol=crlf 2 | *.txt text eol=crlf 3 | *.cmake text eol=crlf 4 | *.c text eol=crlf 5 | *.h text eol=crlf 6 | *.cpp text eol=crlf 7 | *.hpp text eol=crlf 8 | *.json text eol=crlf 9 | *.xml text eol=crlf 10 | *.yml text eol=crlf 11 | *.in text eol=crlf 12 | *.sh text eol=lf 13 | *.bash text eol=lf 14 | *.sql text eol=lf -------------------------------------------------------------------------------- /sese/example/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/libsese/sese/refs/heads/main/schema/manifest.schema.json", 3 | "author": "Kaoru - SHIINASAMA2001@gmail.com", 4 | "productName": "example", 5 | "internalName": "example", 6 | "version": "0.1.0", 7 | "description": "Sese Framework - https://github.com/libsese/sese-core.git", 8 | "copyright": "(c) 2022-2024 libsese" 9 | } -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.21) 2 | 3 | include(cmake/Options.cmake) 4 | project( 5 | sese 6 | VERSION 3.0.0 7 | LANGUAGES CXX 8 | ) 9 | set(CMAKE_CXX_STANDARD 20) 10 | set(SESE_ROOT_PROJECT ON) 11 | include(cmake/Dependencies.cmake) 12 | include(cmake/Git.cmake) 13 | include(cmake/Coverage.cmake) 14 | include(cmake/Asan.cmake) 15 | 16 | add_subdirectory(sese) 17 | -------------------------------------------------------------------------------- /sese/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/libsese/sese/refs/heads/main/schema/manifest.schema.json", 3 | "author": "Kaoru - SHIINASAMA2001@gmail.com", 4 | "productName": "Sese Core", 5 | "internalName": "Sese Core", 6 | "version": "3.0.0", 7 | "description": "Sese Framework - https://github.com/libsese/sese-core.git", 8 | "copyright": "(c) 2022-2024 libsese" 9 | } 10 | -------------------------------------------------------------------------------- /sese/test/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/libsese/sese/refs/heads/main/schema/manifest.schema.json", 3 | "author": "Kaoru - SHIINASAMA2001@gmail.com", 4 | "productName": "AllTestsInMain", 5 | "internalName": "AllTestsInMain", 6 | "version": "0.1.0", 7 | "description": "Sese Framework - https://github.com/libsese/sese-core.git", 8 | "copyright": "(c) 2022-2024 libsese" 9 | } -------------------------------------------------------------------------------- /sese/test/Data/data.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello 5 | Hi 6 | 7 | 8 | 9 | 10 | TestXmlUtil 11 | 1.0 12 | 13 | Hello World 14 | 15 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "ms-vscode.cpptools-extension-pack", 4 | "ms-vscode.cmake-tools", 5 | "llvm-vs-code-extensions.vscode-clangd", 6 | "matepek.vscode-catch2-test-adapter", 7 | "ms-python.vscode-pylance", 8 | "ms-python.python", 9 | "editorconfig.editorconfig", 10 | "github.vscode-github-actions", 11 | "jeff-hykin.better-cpp-syntax", 12 | "cheshirekow.cmake-format" 13 | ] 14 | } -------------------------------------------------------------------------------- /sese/test/README.md: -------------------------------------------------------------------------------- 1 | # Unit Testing 2 | 3 | | Directory | Description | 4 | |-----------|-------------------------------| 5 | | Data | Directory for test data | 6 | | Test* | Independent test environments | 7 | 8 | | Test Target Name | Description | 9 | |:-----------------|:------------------------| 10 | | * | Test executable files | 11 | | *.m | Test module files | 12 | | *.d | Test daemon executables | 13 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | black==24.8.0 2 | certifi==2024.8.30 3 | charset-normalizer==3.3.2 4 | click==8.1.7 5 | cmakelang==0.6.13 6 | colorama==0.4.6 7 | colorlog==6.8.2 8 | dnspython==2.7.0 9 | gcovr==7.2 10 | idna==3.10 11 | Jinja2==3.1.5 12 | junit2html==31.0.2 13 | lxml==5.3.0 14 | MarkupSafe==2.1.5 15 | mypy-extensions==1.0.0 16 | packaging==24.1 17 | pathspec==0.12.1 18 | platformdirs==4.3.6 19 | Pygments==2.17.2 20 | PyYAML==6.0.1 21 | requests==2.32.3 22 | six==1.16.0 23 | urllib3==2.2.3 24 | websocket-client==1.7.0 25 | -------------------------------------------------------------------------------- /sese/archive/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library( 2 | Archive OBJECT 3 | ./ArchiveInputStream.cpp 4 | ./ArchiveInputStream.h 5 | ./ArchiveOutputStream.cpp 6 | ./ArchiveOutputStream.h 7 | ./ArchiveReader.cpp 8 | ./ArchiveReader.h 9 | ./ArchiveWriter.cpp 10 | ./ArchiveWriter.h 11 | ./Config.cpp 12 | ./Config.h 13 | ) 14 | 15 | if(UNIX) 16 | set_target_properties(Archive PROPERTIES POSITION_INDEPENDENT_CODE ON) 17 | endif() 18 | target_link_libraries(Archive PRIVATE LibArchive::LibArchive) 19 | -------------------------------------------------------------------------------- /.gitlab/merge_request_templates/default.md: -------------------------------------------------------------------------------- 1 | # Default merge template | 默认合并模板 2 | 3 | Thank you for your contributions to this project. This is an internal backup repository. 4 | 5 | Currently, we do not support initiating merge requests or pull requests on GitLab. 6 | 7 | Please visit the GitHub project [homepage](https://github.com/libsese/sese-core) for further information. 8 | 9 | --- 10 | 11 | 感谢你对项目的付出,这是一个内部备份仓库, 12 | 13 | 我们暂时不支持在 GitLab 中发起 merge_request/pull_request, 14 | 15 | 请移步至 GitHub 项目[主页](https://github.com/libsese/sese-core)。 -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /gcovr.cfg: -------------------------------------------------------------------------------- 1 | filter = sese 2 | exclude = sese/test 3 | exclude = sese/event 4 | exclude = sese/benchmark 5 | exclude = sese/native/linux/event 6 | exclude = sese/native/darwin/event 7 | exclude = sese/native/win/event 8 | exclude = sese/service/TcpTransporter 9 | exclude-unreachable-branches = yes 10 | exclude-throw-branches = yes 11 | exclude-noncode-lines = yes 12 | 13 | html = build/coverage/html/index.html 14 | html-title = Sese Core Main Test Coverage 15 | html-theme = github.green 16 | html-details = yes 17 | 18 | cobertura = build/coverage/coverage.xml 19 | cobertura-pretty = yes -------------------------------------------------------------------------------- /.vscode/readme.md: -------------------------------------------------------------------------------- 1 | # Usage 2 | 3 | To disable the CTest index brought by the CMake extension and automatically enable TestMate, you need to modify the user's configuration file by adding the following settings: 4 | 5 | ```json 6 | { 7 | "testMate.cpp.discovery.loadOnStartup": true, 8 | "cmake.ctest.testExplorerIntegrationEnabled": false 9 | } 10 | ``` 11 | 12 | # Note 13 | 14 | This folder is only for default configurations in codespaces and local development with VSCode. 15 | 16 | If you use VSCode in any scenario, you should not commit or change this folder. 17 | -------------------------------------------------------------------------------- /sese/example/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(${MSVC}) 2 | add_compile_options(/utf-8) 3 | endif() 4 | 5 | include(${PROJECT_SOURCE_DIR}/cmake/Manifest.cmake) 6 | 7 | add_definitions("-DPROJECT_PATH=\"${PROJECT_SOURCE_DIR}\"") 8 | add_definitions("-DPROJECT_BINARY_PATH=\"${CMAKE_CURRENT_BINARY_DIR}\"") 9 | 10 | add_executable(HttpServer HttpServer.cpp) 11 | target_link_libraries(HttpServer PRIVATE Core) 12 | target_manifest(HttpServer manifest.json) 13 | 14 | add_executable(Json2yml Json2yml.cpp) 15 | target_link_libraries(Json2yml PRIVATE Core) 16 | target_manifest(Json2yml manifest.json) 17 | -------------------------------------------------------------------------------- /package/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13) 2 | 3 | set(VCPKG_OVERLAY_PORTS "${CMAKE_CURRENT_LIST_DIR}/ports") 4 | 5 | project(package_test) 6 | 7 | set(CMAKE_CXX_STANDARD 17) 8 | 9 | if (MSVC AND VCPKG_TARGET_TRIPLET STREQUAL "x64-windows-static") 10 | set(CMAKE_CXX_FLAGS_DEBUG /MTd) 11 | set(CMAKE_CXX_FLAGS_MINSIZEREL /MT) 12 | set(CMAKE_CXX_FLAGS_RELEASE /MT) 13 | set(CMAKE_CXX_FLAGS_RELWITHDEBUGINFO /MT) 14 | endif () 15 | 16 | add_executable(main main.cpp) 17 | 18 | find_package(Sese CONFIG REQUIRED) 19 | target_link_libraries(main PRIVATE Sese::Core) -------------------------------------------------------------------------------- /sese/test/Data/data.json: -------------------------------------------------------------------------------- 1 | { 2 | "string": "a testing\n text\"", 3 | "value": 0, 4 | "nullable": null, 5 | "boolean": true, 6 | "object": { 7 | "object_value1": "value1", 8 | "object_value2": "value2", 9 | "null_array": [], 10 | "null_object": {} 11 | }, 12 | "mixin_array": [ 13 | 1, 14 | 2, 15 | { 16 | "object_value1": "value3", 17 | "object_value2": "value4" 18 | }, 19 | 3, 20 | [ 21 | 4, 22 | 5 23 | ], 24 | null 25 | ] 26 | } -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/general.yml: -------------------------------------------------------------------------------- 1 | name: General Issues 2 | description: 此模板用于反馈通用问题 3 | assignees: 4 | - SHIINASAMA 5 | 6 | title: "[general]: " 7 | body: 8 | - type: markdown 9 | attributes: 10 | value: | 11 | 在描述你的问题之前请先尝试自己解决或者查找相似的 issue 12 | - type: textarea 13 | id: description 14 | attributes: 15 | label: 问题描述 16 | - type: input 17 | id: version 18 | attributes: 19 | label: 版本 20 | value: | 21 | 出现该问题的具体版本 22 | - type: textarea 23 | id: record 24 | attributes: 25 | label: 描述复现步骤(如果有) 26 | value: | 27 | 在这里编写步骤 28 | -------------------------------------------------------------------------------- /sese/Log.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include -------------------------------------------------------------------------------- /sese/Util.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include -------------------------------------------------------------------------------- /sese/Init.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include -------------------------------------------------------------------------------- /docker/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | mariadb: 4 | image: mariadb 5 | environment: 6 | - MARIADB_ROOT_HOST=% 7 | - MARIADB_USER=libsese 8 | - MARIADB_PASSWORD=libsese 9 | - MARIADB_ROOT_PASSWORD=libsese 10 | restart: on-failure 11 | ports: 12 | - '127.0.0.1:18806:3306' 13 | volumes: 14 | - ../scripts/mysql_dump.sql:/docker-entrypoint-initdb.d/mysql_dump.sql:ro 15 | postgresql: 16 | image: postgres 17 | environment: 18 | - POSTGRES_PASSWORD=libsese 19 | restart: on-failure 20 | ports: 21 | - '127.0.0.1:18080:5432' 22 | volumes: 23 | - ../scripts/postgres_dump.sql:/docker-entrypoint-initdb.d/postgres_dump.sql:ro -------------------------------------------------------------------------------- /sese/net/AddressPool.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | using namespace sese::net; 18 | -------------------------------------------------------------------------------- /sese/test/Data/data-1.txt: -------------------------------------------------------------------------------- 1 | Once upon a time there was a sweet little girl. 2 | Everyone who saw her liked her, but most of all her grandmother, who did not know what to give the child next. 3 | Once she gave her a little cap made of red velvet. 4 | Because it suited her so well, and she wanted to wear it all the time, she came to be known as Little Red Riding Hood. 5 | One day her mother said to her: 6 | "Come Little Red Riding Hood. Here is a piece of cake and a bottle of wine. Take them to your grandmother. She is sick and weak, and they will do her well. Mind your manners and give her my greetings. Behave yourself on the way, and do not leave the path, or you might fall down and break the glass, and then there will be nothing for your sick grandmother." -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | The project as a whole uses a rolling release, 6 | and the latest version always receives more comprehensive and fast security support. 7 | Therefore, we recommend that you always use a newer version, 8 | only the immediately preceding stable version will receive security support, 9 | while previous stable versions will not benefit from this security support. 10 | 11 | ## Reporting a Vulnerability 12 | 13 | Please report any code vulnerabilities using GitHub Issues. 14 | We will promptly analyze the reported issues. 15 | Your active cooperation is also required for the correct resolution of the issues. 16 | Once the issues are fixed, we will mark them and close the related GitHub Issues. 17 | -------------------------------------------------------------------------------- /docker/alpine-x64.dockerfile: -------------------------------------------------------------------------------- 1 | FROM amd64/alpine:3.20.1 2 | 3 | RUN apk add samurai autoconf automake git cmake gcc compiler-rt pkgconfig linux-headers bison flex tzdata-utils 4 | 5 | RUN apk add libtool python3 py3-pip bash 6 | 7 | RUN apk add doxygen mariadb-client postgresql-client 8 | 9 | RUN apk add build-base cmake ninja zip unzip curl git 10 | 11 | ENV VCPKG_FORCE_SYSTEM_BINARIES=1 12 | 13 | RUN git config --global http.version HTTP/1.1 && \ 14 | git clone https://github.com/microsoft/vcpkg /opt/vcpkg && \ 15 | /opt/vcpkg/bootstrap-vcpkg.sh -disableMetrics 16 | 17 | ENV VCPKG_ROOT=/opt/vcpkg 18 | 19 | COPY ./requirements.txt /tmp/requirements.txt 20 | 21 | RUN pip install -r /tmp/requirements.txt --break-system-packages && \ 22 | pip cache purge 23 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/new_feature.yml: -------------------------------------------------------------------------------- 1 | name: New Feature 2 | description: 此模板用于请求添加新的功能 3 | labels: ["feature"] 4 | assignees: 5 | - DreamerQcl 6 | title: "[feature]: " 7 | body: 8 | - type: markdown 9 | attributes: 10 | value: | 11 | 在描述你的问题之前请先尝试自己解决或者查找相似的 issue。 12 | - type: checkboxes 13 | id: checklist 14 | attributes: 15 | label: 确认清单 16 | options: 17 | - label: 我已尝试自己去解决这个问题,但不在我的能力或者职责范围之内。 18 | required: true 19 | - type: textarea 20 | id: description 21 | attributes: 22 | label: 请在这里描述你的需求 23 | validations: 24 | required: true 25 | - type: textarea 26 | id: impact 27 | attributes: 28 | label: 此功能为项目或功能带来的影响(好的或者坏的) 29 | validations: 30 | required: true -------------------------------------------------------------------------------- /schema/resource.schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "type": "object", 4 | "additionalProperties": false, 5 | "properties": { 6 | "$schema": { 7 | "type": "string" 8 | }, 9 | "binaries": { 10 | "type": "object", 11 | "patternProperties": { 12 | "^.*$": { 13 | "type": "string" 14 | } 15 | }, 16 | "additionalProperties": false, 17 | "description": "The binaries to be embedd, the key is the name of the binary and the value is the path to the binary." 18 | }, 19 | "icon": { 20 | "type": "string", 21 | "description": "Path to the icon file, it's a Windows Only feature." 22 | } 23 | }, 24 | "required": [ 25 | "binaries" 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /schema/manifest.schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "type": "object", 4 | "additionalProperties": false, 5 | "properties": { 6 | "$schema": { 7 | "type": "string" 8 | }, 9 | "author": { 10 | "type": "string" 11 | }, 12 | "description": { 13 | "type": "string" 14 | }, 15 | "productName": { 16 | "type": "string" 17 | }, 18 | "internalName": { 19 | "type": "string" 20 | }, 21 | "version": { 22 | "type": "string" 23 | }, 24 | "copyright": { 25 | "type": "string" 26 | } 27 | }, 28 | "required": [ 29 | "author", 30 | "description", 31 | "productName", 32 | "internalName", 33 | "version", 34 | "copyright" 35 | ] 36 | } -------------------------------------------------------------------------------- /sese/types/defines.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include 18 | 19 | namespace sese { 20 | 21 | template 22 | using void_t = void; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /docker/ubuntu-arm64.dockerfile: -------------------------------------------------------------------------------- 1 | FROM arm64v8/ubuntu:jammy 2 | 3 | ENV TERM=xterm-256color 4 | ENV DEBIAN_FRONTEND=noninteractive 5 | 6 | #COPY ./scripts/install_ubuntu_deps.sh /tmp/install_deps.sh 7 | 8 | RUN yes | unminimize && \ 9 | # bash ./tmp/install_deps.sh && \ 10 | apt install -y --no-install-recommends build-essential cmake curl zip unzip tar git g++ mysql-client postgresql-client sqlite3 python3-pip doxygen pkg-config bison flex autoconf ninja-build && \ 11 | apt autoremove -y && \ 12 | rm -rf /var/lib/apt/lists/* 13 | 14 | RUN git clone https://github.com/microsoft/vcpkg /opt/vcpkg && \ 15 | /opt/vcpkg/bootstrap-vcpkg.sh -disableMetrics 16 | 17 | ENV VCPKG_ROOT=/opt/vcpkg 18 | 19 | COPY ./requirements.txt /tmp/requirements.txt 20 | 21 | RUN pip install -r /tmp/requirements.txt && \ 22 | pip cache purge -------------------------------------------------------------------------------- /sese/service/Service.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "Service.h" 16 | 17 | sese::ErrorCode sese::service::Service::getErrorCode() { 18 | return {this->getLastError(), this->getLastErrorMessage()}; 19 | } 20 | -------------------------------------------------------------------------------- /sese/benchmark/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(benchmark CONFIG REQUIRED) 2 | find_package(GTest CONFIG REQUIRED) 3 | 4 | if(MSVC) 5 | add_compile_options(/utf-8) 6 | endif() 7 | 8 | macro(bm_link_libraries target) 9 | target_link_libraries(${target} PRIVATE benchmark::benchmark GTest::gtest Core) 10 | endmacro() 11 | 12 | add_executable(BM_StringBuilder BM_StringBuilder.cpp) 13 | bm_link_libraries(BM_StringBuilder) 14 | 15 | add_executable(BM_PostgresPreparedStatement BM_PostgresPreparedStatement.cpp) 16 | bm_link_libraries(BM_PostgresPreparedStatement) 17 | 18 | add_executable(BM_FormatParse BM_FormatParse.cpp) 19 | bm_link_libraries(BM_FormatParse) 20 | 21 | add_executable(BM_Format BM_Format.cpp) 22 | bm_link_libraries(BM_Format) 23 | 24 | add_executable(BM_JsonParse BM_JsonParse.cpp) 25 | bm_link_libraries(BM_JsonParse) 26 | -------------------------------------------------------------------------------- /sese/util/ErrorCode.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "ErrorCode.h" 16 | 17 | #include 18 | 19 | sese::ErrorCode::ErrorCode(int32_t error, std::string msg) noexcept 20 | : error(error), msg(std::move(msg)) { 21 | } 22 | -------------------------------------------------------------------------------- /ROADMAP.md: -------------------------------------------------------------------------------- 1 | # Roadmap Publicity 2 | 3 | ## Short intro 4 | 5 | 1. ❌ Canceled 6 | 2. ⭕️ Done 7 | 3. 🛠️ In Processing 8 | 9 | ## Version 2.1.0 10 | 11 | - ❌ Crypto Wrapper(RSA, SM4 etc.) 12 | - ⭕️ Better web-related support 13 | - ⭕️ Improve test coverage 14 | - ⭕️ Gitlab workflow improvements 15 | 16 | ## Version 2.1.1 17 | 18 | - ⭕️ Static Links 19 | - ⭕️ Upload to builtin repos 20 | 21 | ## Version 2.3.0 22 | 23 | - ⭕️ HPACK(RFC7541) 24 | - ⭕️ HTTP2(RFC7540) 25 | - ⭕️ Better web-related support 26 | - ⭕️ IP/TCP based filters 27 | 28 | ## Version 3.0.0 29 | 30 | - ⭕️ DNS module decoupling and refactoring 31 | - ⭕️️ Better Exception 32 | - ⭕️️ Support ~~std::error_code~~ sese::ErrorCode & sese::Result 33 | - ⭕️ Binary description manifest 34 | - ⭕️ Embedded resource management 35 | - ️️⭕️ Replaces the previous recursive algorithm -------------------------------------------------------------------------------- /sese/io/File.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file File.h 17 | * @author kaoru 18 | * @version 0.1 19 | * @brief File class 20 | * @date September 13, 2023 21 | */ 22 | 23 | #pragma once 24 | 25 | #include -------------------------------------------------------------------------------- /sese/io/NullOutputStream.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | int64_t sese::io::NullOutputStream::write([[maybe_unused]] const void *buffer, size_t length) { 18 | return static_cast(length); 19 | } 20 | -------------------------------------------------------------------------------- /sese/log/AbstractAppender.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "sese/log/AbstractAppender.h" 16 | 17 | namespace sese::log { 18 | AbstractAppender::AbstractAppender(Level level) noexcept { 19 | this->level = level; 20 | } 21 | } // namespace sese::log -------------------------------------------------------------------------------- /sese/io/ConsoleOutputStream.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "sese/io/ConsoleOutputStream.h" 16 | 17 | int64_t sese::io::ConsoleOutputStream::write(const void *buffer, size_t length) { 18 | return static_cast(fwrite(buffer, 1, length, stdout)); 19 | } -------------------------------------------------------------------------------- /.idea/copyright/libsese_Default_Copyright.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /sese/internal/unix/thread/GlobalThreadPool.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | void sese::GlobalThreadPool::postTask(const std::function &func) { 18 | auto pool = globalThreadPool.getInstance(); 19 | pool->postTask(func); 20 | } -------------------------------------------------------------------------------- /sese/internal/service/http/ConnType.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include 18 | 19 | namespace sese::internal::service::http { 20 | 21 | enum class ConnType { 22 | FILTER, 23 | FILE_DOWNLOAD, 24 | CONTROLLER, 25 | NONE 26 | }; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /sese/types/is_pair.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include 18 | 19 | namespace sese { 20 | 21 | template 22 | struct is_pair : std::false_type {}; 23 | 24 | template 25 | struct is_pair> : std::true_type {}; 26 | 27 | } // namespace sese 28 | -------------------------------------------------------------------------------- /sese/db/Config.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /// \file Config.h 16 | /// \author kaoru 17 | /// \brief Database-related configuration files 18 | /// \version 0.1 19 | 20 | #pragma once 21 | 22 | #define SESE_DB_API 23 | 24 | #ifdef _MSC_VER 25 | #pragma warning(disable : 4251) 26 | #endif 27 | 28 | #include 29 | #include -------------------------------------------------------------------------------- /sese/thread/SpinLock.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | using namespace sese; 18 | 19 | void SpinLock::lock() { 20 | bool expect = false; 21 | while (!flag.compare_exchange_weak(expect, true)) { 22 | expect = false; 23 | } 24 | } 25 | 26 | void SpinLock::unlock() { 27 | flag.store(false); 28 | } -------------------------------------------------------------------------------- /sese/io/InputBuffer.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /// @file InputBuffer.h 16 | /// @brief Input buffer wrapper 17 | /// @author kaoru 18 | /// @date April 20, 2024 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | namespace sese::io { 25 | 26 | /// \brief Input buffer wrapper 27 | using InputBuffer = InputBufferWrapper; 28 | 29 | } -------------------------------------------------------------------------------- /sese/io/OutputStream.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | int64_t sese::io::OutputStream::write(const std::string_view &buffer) { 18 | return write(buffer.data(), buffer.size()); 19 | } 20 | 21 | int64_t sese::io::OutputStream::write(const text::StringView &buffer) { 22 | return write(buffer.data(), buffer.size()); 23 | } 24 | -------------------------------------------------------------------------------- /sese/res/ResourceManager.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | sese::res::Resource::Ptr sese::res::ResourceManager::getResource(const std::string &name) const { 18 | auto iterator = resourceMap.find(name); 19 | if (iterator == resourceMap.end()) { 20 | return nullptr; 21 | } 22 | return iterator->second; 23 | } -------------------------------------------------------------------------------- /sese/util/ZlibConfig.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file ZlibConfig.h 17 | * @author kaoru 18 | * @version 0.1 19 | * @brief ZLIB configuration declarations 20 | * @date September 13, 2023 21 | */ 22 | 23 | #pragma once 24 | 25 | namespace sese { 26 | enum class CompressionType { 27 | RAW = -30, 28 | ZLIB = 0, 29 | GZIP = 16 30 | }; 31 | } -------------------------------------------------------------------------------- /scripts/do_websocket.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 libsese 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | import websocket 17 | import sys 18 | 19 | 20 | def test(port: str): 21 | ws = websocket.WebSocket() 22 | ws.connect("ws://localhost:{}/chat".format(port)) 23 | ws.send("Hello") 24 | buf = ws.recv() 25 | print(buf) 26 | ws.close() 27 | 28 | 29 | if __name__ == "__main__": 30 | p = sys.argv[1] 31 | test(p) 32 | -------------------------------------------------------------------------------- /sese/io/OutputBuffer.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /// @file OutputBuffer.h 16 | /// @brief Output buffer wrapper 17 | /// @author kaoru 18 | /// @date April 20, 2024 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | namespace sese::io { 25 | 26 | /// \brief Output buffer wrapper 27 | using OutputBuffer = OutputBufferWrapper; 28 | 29 | } -------------------------------------------------------------------------------- /sese/db/Metadata.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | namespace sese::db { 18 | enum class MetadataType { 19 | TEXT, 20 | BOOLEAN, 21 | CHAR, 22 | SHORT, 23 | INTEGER, 24 | LONG, 25 | FLOAT, 26 | DOUBLE, 27 | DATE, 28 | TIME, 29 | DATE_TIME, 30 | UNKNOWN 31 | }; 32 | } -------------------------------------------------------------------------------- /sese/io/Closeable.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file Closeable.h 17 | * @date July 5, 2023 18 | * @author kaoru 19 | * @brief The closeable interface 20 | * @version 0.1 21 | */ 22 | 23 | #pragma once 24 | 25 | namespace sese::io { 26 | /// The closeable interface 27 | class Closeable { 28 | public: 29 | virtual ~Closeable() = default; 30 | virtual void close() = 0; 31 | }; 32 | } // namespace sese::io -------------------------------------------------------------------------------- /sese/net/http/HeaderBuilder.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | using sese::net::http::Header; 18 | using sese::net::http::HeaderBuilder; 19 | 20 | HeaderBuilder::HeaderBuilder(Header &header) : header(header) {} 21 | 22 | HeaderBuilder &&HeaderBuilder::set(const std::string &key, const std::string &value) && { 23 | header.set(key, value); 24 | return std::move(*this); 25 | } 26 | -------------------------------------------------------------------------------- /sese/res/Resource.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | 18 | // GCOVR_EXCL_START 19 | 20 | sese::res::Resource::Resource(std::string name, const void *buf, size_t size) 21 | : name(std::move(name)), buf(buf), size(size) {} 22 | 23 | // GCOVR_EXCL_STOP 24 | 25 | sese::res::ResourceStream::Ptr sese::res::Resource::getStream() { 26 | return SESE_MAKE_RES_STREAM(buf, size); 27 | } -------------------------------------------------------------------------------- /sese/security/SecurityConfig.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include 18 | 19 | int32_t sese::security::SecurityInitTask::init() noexcept { 20 | SSL_library_init(); 21 | SSL_load_error_strings(); 22 | return 0; 23 | } 24 | 25 | int32_t sese::security::SecurityInitTask::destroy() noexcept { 26 | OPENSSL_thread_stop(); 27 | OPENSSL_cleanup(); 28 | return 0; 29 | } -------------------------------------------------------------------------------- /sese/text/String.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file String.h 17 | * @author kaoru 18 | * @version 0.1 19 | * @brief UTF-8 String 20 | * @date September 13, 2023 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | #include 27 | 28 | namespace sese::text { 29 | using Char = sstr::SChar; 30 | using String = sstr::SString; 31 | using StringView = sstr::SStringView; 32 | } // namespace sese::text -------------------------------------------------------------------------------- /sese/net/http/Response.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | // GCOVR_EXCL_START 18 | 19 | void sese::net::http::Response::swap(sese::net::http::Response &another) noexcept { 20 | std::swap(version, another.version); 21 | std::swap(statusCode, another.statusCode); 22 | std::swap(cookies, another.cookies); 23 | std::swap(headers, another.headers); 24 | body.swap(another.body); 25 | } 26 | 27 | // GCOVR_EXCL_STOP -------------------------------------------------------------------------------- /sese/service/dns/Config.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include 18 | #include 19 | 20 | #include 21 | 22 | namespace sese::service::dns { 23 | 24 | using Callback = std::function; 29 | 30 | } // namespace sese::service::dns -------------------------------------------------------------------------------- /sese/test/TestDB/Config.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #ifndef SQLITE_CONNECTION_STRING 18 | #define SQLITE_CONNECTION_STRING PATH_TO_DB 19 | #endif 20 | 21 | #ifndef MYSQL_CONNECTION_STRING 22 | #define MYSQL_CONNECTION_STRING "host=127.0.0.1;port=18806;user=root;pwd=libsese;db=db_test;" 23 | #endif 24 | 25 | #ifndef PSQL_CONNECTION_STRING 26 | #define PSQL_CONNECTION_STRING "host=127.0.0.1;port=18080;user=postgres;pwd=libsese;db=db_test;" 27 | #endif -------------------------------------------------------------------------------- /sese/db/Util.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /// \file Util.h 16 | /// \brief Utility Collection 17 | /// \author kaoru 18 | /// \version 0.1 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | namespace sese::db { 26 | 27 | /// \brief Perform simple tokenization on a string 28 | /// \param string Target string 29 | /// \return Tokenization result 30 | std::map tokenize(const char *string) noexcept; 31 | } -------------------------------------------------------------------------------- /sese/system/FileNotifier.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "FileNotifier.h" 16 | 17 | #include "sese/util/Util.h" 18 | 19 | sese::Result sese::sys::FileNotifier::createEx(const std::string &path) noexcept { 20 | if (auto result = create(path)) { 21 | return Result::success(std::move(result)); 22 | } 23 | return Result::error({getErrorCode(), getErrorString()}); 24 | } 25 | -------------------------------------------------------------------------------- /sese/test/TestResource/TestResource.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | 18 | #include "Resource.h" 19 | 20 | TEST(TestResource, Bundler) { 21 | auto res = sese::res::BundlerResource(); 22 | auto txt = res.getBinary(Resource::Binaries::hello); 23 | EXPECT_NE(nullptr, txt); 24 | char buffer[1024]{}; 25 | auto l = txt->read(buffer, 1024); 26 | EXPECT_NE(0, l); 27 | puts(buffer); 28 | } -------------------------------------------------------------------------------- /sese/system/Library.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "Library.h" 16 | 17 | #include "sese/util/ErrorCode.h" 18 | #include "sese/util/Util.h" 19 | 20 | sese::Result sese::sys::Library::createEx(const std::string &name) noexcept { 21 | if (auto result = create(name)) { 22 | return Result::success(std::move(result)); 23 | } 24 | return Result::error({getErrorCode(), getErrorString()}); 25 | } 26 | 27 | -------------------------------------------------------------------------------- /scripts/dns_client.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 libsese 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import sys 16 | import dns.resolver 17 | 18 | resolver = dns.resolver.Resolver() 19 | 20 | resolver.nameservers = ["127.0.0.1"] 21 | resolver.port = int(sys.argv[1]) 22 | 23 | names = ["www.example.com", "www.baidu.com"] 24 | 25 | try: 26 | for name in names: 27 | answer = resolver.resolve(name, "A") 28 | for rdata in answer: 29 | print(name, "ipaddr", rdata.to_text()) 30 | except dns.exception.DNSException as e: 31 | print("failed to query", e) 32 | exit(1) 33 | -------------------------------------------------------------------------------- /sese/archive/ArchiveInputStream.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include 18 | 19 | // GCOVR_EXCL_START 20 | 21 | sese::archive::ArchiveInputStream::ArchiveInputStream(void *archive_read) 22 | : archive_read(archive_read) { 23 | } 24 | 25 | int64_t sese::archive::ArchiveInputStream::read(void *buffer, size_t length) { 26 | return archive_read_data(static_cast(archive_read), buffer, length); 27 | } 28 | 29 | // GCOVR_EXCL_STOP -------------------------------------------------------------------------------- /sese/net/http/HttpConverter.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include 18 | 19 | #include 20 | #include 21 | 22 | namespace sese::net::http { 23 | 24 | class HttpConverter final : public NotInstantiable { 25 | public: 26 | HttpConverter() = delete; 27 | 28 | static bool convertFromHttp2(Request *request); 29 | 30 | static void convert2Http2(Response *response); 31 | }; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /sese/thread/SpinLock.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /// \file SpinLock.h 16 | /// \brief Spin Lock 17 | /// \author kaoru 18 | 19 | #pragma once 20 | 21 | #include 22 | 23 | #include 24 | 25 | #ifdef SESE_PLATFORM_WINDOWS 26 | #pragma warning(disable : 4251) 27 | #endif 28 | 29 | namespace sese { 30 | /// Spin Lock 31 | class SpinLock { 32 | public: 33 | void lock(); 34 | 35 | void unlock(); 36 | 37 | private: 38 | std::atomic_bool flag{false}; 39 | }; 40 | } // namespace sese -------------------------------------------------------------------------------- /sese/util/EncodingConverter.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "sese/util/EncodingConverter.h" 16 | #include "sese/text/String.h" 17 | 18 | std::string sese::EncodingConverter::toString(const std::wstring &wstring) noexcept { 19 | auto str = text::String::fromUCS2LE(wstring.c_str()); 20 | return str.toString(); 21 | } 22 | 23 | std::wstring sese::EncodingConverter::toWstring(const std::string &string) noexcept { 24 | auto str = text::String::fromUTF8(string.c_str()); 25 | return str.toWString(); 26 | } 27 | -------------------------------------------------------------------------------- /sese/io/RandomInputStream.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /// \file RandomInputStream.h 16 | /// \brief Random input stream 17 | /// \author kaoru 18 | 19 | #pragma once 20 | 21 | #include 22 | 23 | #ifdef SESE_PLATFORM_WINDOWS 24 | #pragma warning(disable : 4251) 25 | #endif 26 | 27 | namespace sese::io { 28 | 29 | /// Random input stream 30 | class RandomInputStream : public InputStream { 31 | public: 32 | int64_t read(void *buffer, size_t length) override; 33 | }; 34 | 35 | } // namespace sese::io -------------------------------------------------------------------------------- /sese/archive/ArchiveOutputStream.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include 18 | 19 | // GCOVR_EXCL_START 20 | 21 | sese::archive::ArchiveOutputStream::ArchiveOutputStream(void *archive_write) : 22 | archive_write(archive_write) { 23 | } 24 | 25 | int64_t sese::archive::ArchiveOutputStream::write(const void *buffer, size_t length) { 26 | return archive_write_data(static_cast(this->archive_write), buffer, length); 27 | } 28 | 29 | // GCOVR_EXCL_STOP -------------------------------------------------------------------------------- /sese/net/http/Request.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | // GCOVR_EXCL_START 18 | 19 | void sese::net::http::Request::swap(sese::net::http::Request &another) noexcept { 20 | std::swap(type, another.type); 21 | std::swap(uri, another.uri); 22 | std::swap(version, another.version); 23 | std::swap(cookies, another.cookies); 24 | std::swap(headers, another.headers); 25 | std::swap(query_args, another.query_args); 26 | body.swap(another.body); 27 | } 28 | 29 | // GCOVR_EXCL_STOP -------------------------------------------------------------------------------- /sese/internal/win/thread/GlobalThreadPool.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | DWORD WINAPI sese::GlobalThreadPool::taskRunner1(LPVOID lp_param) { 18 | auto task1 = static_cast(lp_param); 19 | task1->function(); 20 | delete task1; 21 | return 0; 22 | } 23 | 24 | void sese::GlobalThreadPool::postTask(const std::function &func) { 25 | auto task1 = new Task1; 26 | task1->function = func; 27 | QueueUserWorkItem(taskRunner1, task1, WT_EXECUTEDEFAULT); 28 | } 29 | -------------------------------------------------------------------------------- /sese/test/AllTest.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | 20 | int main(int argc, char **argv) { 21 | testing::InitGoogleTest(&argc, argv); 22 | sese::initCore(argc, argv); 23 | sese::sys::Environment::setEnv("LANG", "en_US.UTF-8"); 24 | sese::sys::Environment::setEnv("LC_ALL", "en_US.UTF-8"); 25 | #if defined(__linux__) || defined(__APPLE__) 26 | signal(SIGPIPE, SIG_IGN); 27 | #endif 28 | return RUN_ALL_TESTS(); 29 | } -------------------------------------------------------------------------------- /sese/io/FixedBuilder.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /// \file FixedBuilder.h 16 | /// \author kaoru 17 | /// \brief Non-thread-safe fixed-size buffer 18 | /// \date June 11, 2023 19 | /// \version 0.1.0 20 | 21 | #pragma once 22 | 23 | #include "sese/io/AbstractFixedBuffer.h" 24 | 25 | namespace sese::io { 26 | 27 | /// Non-thread-safe fixed-size buffer 28 | class FixedBuilder final : public AbstractFixedBuffer { 29 | public: 30 | explicit FixedBuilder(size_t size) noexcept : AbstractFixedBuffer(size) {} 31 | }; 32 | 33 | } // namespace sese::io -------------------------------------------------------------------------------- /sese/text/Util.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /// @file Util.h 16 | /// @brief Text utilities 17 | /// @author kaoru 18 | /// @date June 26, 2024 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | namespace sese::text { 25 | 26 | /// Cross-platform compatible snprintf 27 | /// \param buf Output buffer 28 | /// \param buf_size Buffer size 29 | /// \param pattern Format string 30 | /// \param ... Arguments for the format string 31 | /// \return Result 32 | int snprintf(char *buf, size_t buf_size, const char *pattern, ...); 33 | 34 | } -------------------------------------------------------------------------------- /sese/io/Stream.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file Stream.h 17 | * @date November 14, 2022 18 | * @author kaoru 19 | * @brief Stream interface class 20 | * @version 0.2 21 | */ 22 | 23 | #pragma once 24 | 25 | #include "sese/io/InputStream.h" 26 | #include "sese/io/OutputStream.h" 27 | 28 | namespace sese::io { 29 | 30 | /** 31 | * @brief Stream interface class 32 | */ 33 | class Stream : public InputStream, public OutputStream { 34 | public: 35 | typedef std::shared_ptr Ptr; 36 | }; 37 | 38 | } // namespace sese::io -------------------------------------------------------------------------------- /scripts/do_http2_request.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 libsese 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | import os 17 | import sys 18 | from http.client import HTTPConnection 19 | 20 | 21 | def on_nt(p: int): 22 | conn = HTTPConnection("127.0.0.1", p) 23 | conn.request("GET", "/") 24 | resp = conn.getresponse() 25 | print(resp.status) 26 | print(resp.headers) 27 | print(resp.read()) 28 | 29 | 30 | def on_unix(p: int): 31 | os.system("curl --http2 http://127.0.0.1:{} -v -s".format(p)) 32 | 33 | 34 | port = int(sys.argv[1]) 35 | if os.name == "nt": 36 | on_nt(port) 37 | else: 38 | on_unix(port) 39 | -------------------------------------------------------------------------------- /sese/plugin/BaseClass.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file BaseClass.h 17 | * @brief Module base class 18 | * @author kaoru 19 | * @version 0.2 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | // GCOVR_EXCL_START 27 | 28 | namespace sese::plugin { 29 | /// Module base class 30 | class BaseClass : public std::enable_shared_from_this { 31 | public: 32 | using Ptr = std::shared_ptr; 33 | 34 | virtual ~BaseClass() = default; 35 | }; 36 | } // namespace sese::plugin 37 | 38 | // GCOVR_EXCL_STOP -------------------------------------------------------------------------------- /.github/workflows/gh-pages.yml: -------------------------------------------------------------------------------- 1 | name: github pages 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | paths: 8 | - 'docs/**' 9 | - 'sese/**' 10 | - 'static/**' 11 | - 'README.md' 12 | workflow_dispatch: 13 | 14 | env: 15 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 16 | 17 | jobs: 18 | publish: 19 | runs-on: ubuntu-22.04 20 | steps: 21 | - name: Checkout 22 | uses: actions/checkout@v4.1.2 23 | 24 | - name: Build docs 25 | uses: SHIINASAMA/roxy@1.2 26 | with: 27 | DOXYGEN_AWESOME_CSS_VERSION: 'v2.3.4' 28 | DOXYFILE: 'docs/Doxyfile' 29 | RESOURCE_FOLDER: 'static' 30 | OUTPUT_FOLDER: 'build/html' 31 | 32 | - name: Add extra resources 33 | run: | 34 | sudo python3 scripts/insert_meta.py --html_file=build/html/index.html --meta_file=docs/Meta.txt 35 | sudo cp static/image/logo.svg build/html/logo.drawio.svg 36 | 37 | - name: Deploy pages 38 | uses: peaceiris/actions-gh-pages@v4 39 | with: 40 | github_token: ${{ secrets.GITHUB_TOKEN }} 41 | publish_dir: build/html -------------------------------------------------------------------------------- /sese/system/ProcessBuilder.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | sese::system::ProcessBuilder::ProcessBuilder(const std::string &exec) { 18 | this->exec = exec; 19 | } 20 | 21 | sese::system::ProcessBuilder &&sese::system::ProcessBuilder::arg(const std::string &arg) && { 22 | this->args.emplace_back(arg); 23 | return std::move(*this); 24 | } 25 | 26 | sese::Result sese::system::ProcessBuilder::createEx() const { 27 | return Process::createEx(exec, args); 28 | } 29 | -------------------------------------------------------------------------------- /sese/util/StopWatch.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | sese::StopWatch::StopWatch() 18 | : lastStopTime(sese::DateTime::now(0, DateTime::Policy::ONLY_CREATE)) { 19 | } 20 | 21 | sese::TimeSpan sese::StopWatch::stop() { 22 | auto now = sese::DateTime::now(0, DateTime::Policy::ONLY_CREATE); 23 | auto result = now - lastStopTime; 24 | lastStopTime = now; 25 | return result; 26 | } 27 | 28 | void sese::StopWatch::reset() { 29 | lastStopTime = sese::DateTime::now(0, DateTime::Policy::ONLY_CREATE); 30 | } 31 | -------------------------------------------------------------------------------- /sese/internal/unix/system/Path.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | using namespace sese::system; 18 | 19 | Path::Path(const std::string_view &unix_path) noexcept { 20 | Path::unix_path = unix_path; 21 | Path::valid = true; 22 | } 23 | 24 | Path::Path(const char *unix_path) noexcept : Path(std::string_view(unix_path)) { 25 | } 26 | 27 | Path Path::fromNativePath(const std::string &native_path) noexcept { 28 | Path result; 29 | result.unix_path = native_path; 30 | result.valid = true; 31 | return result; 32 | } -------------------------------------------------------------------------------- /sese/io/ConsoleOutputStream.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /// \file ConsoleOutputStream.h 16 | /// \brief Console output stream class - for testing purposes only 17 | /// \author kaoru 18 | /// \version 0.1 19 | /// \date November 20, 2022 20 | 21 | #pragma once 22 | 23 | #include "sese/io/OutputStream.h" 24 | 25 | namespace sese::io { 26 | 27 | /// Console output stream class - for testing purposes only 28 | class ConsoleOutputStream final : public OutputStream { 29 | public: 30 | int64_t write(const void *buffer, size_t length) override; 31 | }; 32 | } // namespace sese::io -------------------------------------------------------------------------------- /sese/io/NullOutputStream.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /// \file NullOutputStream.h 16 | /// \author kaoru 17 | /// \brief Black hole output stream 18 | 19 | #pragma once 20 | 21 | #include 22 | #include 23 | 24 | #ifdef SESE_PLATFORM_WINDOWS 25 | #pragma warning(disable : 4251) 26 | #endif 27 | 28 | namespace sese::io { 29 | 30 | /// Black hole output stream 31 | class NullOutputStream : public OutputStream { 32 | public: 33 | int64_t write(const void *buffer, size_t length) override; 34 | }; 35 | 36 | } // namespace sese::io -------------------------------------------------------------------------------- /sese/io/RandomInputStream.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | 20 | int64_t sese::io::RandomInputStream::read(void *buffer, size_t length) { 21 | size_t count = 0; 22 | while (count != length) { 23 | auto r = RandomUtil::next(); 24 | auto need = std::min(8, length - count); 25 | memcpy(static_cast(buffer) + count, &r, need); 26 | count += need; 27 | } 28 | return static_cast(length); 29 | } 30 | -------------------------------------------------------------------------------- /sese/db/Util.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | 18 | using sese::text::StringBuilder; 19 | 20 | std::map sese::db::tokenize(const char *p) noexcept { 21 | std::map result; 22 | 23 | auto str = StringBuilder::split(p, ";"); 24 | for (auto &&item: str) { 25 | auto pair = StringBuilder::split(item, "="); 26 | auto &&key = pair[0]; 27 | auto &&value = pair[1]; 28 | result[key] = value; 29 | } 30 | 31 | return result; 32 | } -------------------------------------------------------------------------------- /sese/util/NotInstantiable.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file NotInstantiable.h 17 | * @brief Non-instantiable class 18 | * @author kaoru 19 | * @date March 28, 2022 20 | */ 21 | 22 | #pragma once 23 | 24 | namespace sese { 25 | 26 | /** 27 | * @brief Non-instantiable class 28 | */ 29 | class NotInstantiable { 30 | public: 31 | NotInstantiable() = delete; 32 | virtual ~NotInstantiable() = default; 33 | NotInstantiable(const NotInstantiable &) = delete; 34 | NotInstantiable &operator=(const NotInstantiable &) = delete; 35 | }; 36 | } // namespace sese -------------------------------------------------------------------------------- /sese/test/TestUniReader.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include 18 | #include 19 | 20 | TEST(TestUniReader, Open_0) { 21 | auto reader = sese::UniReader::create(PROJECT_PATH "/sese/test/Data/data-0.txt"); 22 | GTEST_ASSERT_NE(reader, nullptr); 23 | 24 | std::string str; 25 | while (!(str = reader->readLine()).empty()) { 26 | SESE_INFO("{}", str.c_str()); 27 | } 28 | } 29 | 30 | TEST(TestUniReader, Open_1) { 31 | GTEST_ASSERT_EQ(sese::UniReader::create("undef.txt"), nullptr); 32 | } -------------------------------------------------------------------------------- /sese/text/Util.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include 18 | 19 | int sese::text::snprintf(char *buf, size_t buf_size, const char *pattern, ...) { 20 | int result; 21 | va_list args; 22 | va_start(args, pattern); 23 | #if defined(SESE_PLATFORM_WINDOWS) 24 | result = vsprintf_s(buf, buf_size, pattern, args); 25 | #elif defined(SESE_PLATFORM_APPLE) 26 | result = vsnprintf(buf, buf_size, pattern, args); 27 | #else 28 | result = std::vsnprintf(buf, buf_size, pattern, args); 29 | #endif 30 | va_end(args); 31 | return result; 32 | } 33 | -------------------------------------------------------------------------------- /sese/plugin/ModuleInfo.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file ModuleInfo.h 17 | * @brief Basic module information 18 | * @author kaoru 19 | * @version 0.2 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "sese/plugin/ClassFactory.h" 25 | 26 | namespace sese::plugin { 27 | /// Basic module information 28 | struct ModuleInfo { 29 | /// The name of the module 30 | const char *moduleName = nullptr; 31 | /// Module version 32 | const char *versionString = nullptr; 33 | /// Module description 34 | const char *description = nullptr; 35 | }; 36 | } // namespace sese::plugin 37 | -------------------------------------------------------------------------------- /sese/archive/ArchiveInputStream.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /// \file ArchiveInputStream.h 16 | /// \brief Archive input stream 17 | /// \author Kaoru 18 | /// \date January 9, 2024 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | namespace sese::archive { 25 | 26 | /// Archive input stream 27 | class ArchiveInputStream final : public io::InputStream { 28 | public: 29 | explicit ArchiveInputStream(void *archive_read); 30 | 31 | int64_t read(void *buffer, size_t length) override; 32 | 33 | protected: 34 | void *archive_read; 35 | }; 36 | } -------------------------------------------------------------------------------- /cmake/sese-config.cmake.in: -------------------------------------------------------------------------------- 1 | include(CMakeFindDependencyMacro) 2 | 3 | # if (CMAKE_SYSTEM_NAME MATCHES "Darwin") 4 | # set(LibArchive_INCLUDE_DIR "/usr/local/opt/libarchive/include") 5 | # endif () 6 | 7 | set(SESE_PACKAGE_DIR ${CMAKE_CURRENT_LIST_DIR}) 8 | 9 | if (NOT BUILD_SHARED_LIBS) 10 | find_dependency(OpenSSL) 11 | find_dependency(ZLIB) 12 | find_dependency(asio) 13 | 14 | if (@SESE_DB_USE_SQLITE@) 15 | find_dependency(unofficial-sqlite3) 16 | endif () 17 | if (@SESE_DB_USE_MARIADB@) 18 | find_dependency(unofficial-libmariadb) 19 | endif () 20 | if (@SESE_DB_USE_POSTGRES@) 21 | find_dependency(PostgreSQL) 22 | endif () 23 | if (@SESE_USE_ARCHIVE@) 24 | find_dependency(LibArchive) 25 | endif () 26 | if (@SESE_REPLACE_EXECINFO@) 27 | find_dependency(PkgConfig) 28 | pkg_check_modules(libunwind REQUIRED IMPORTED_TARGET GLOBAL libunwind) 29 | endif () 30 | endif () 31 | 32 | include("${CMAKE_CURRENT_LIST_DIR}/Bundler.cmake") 33 | include("${CMAKE_CURRENT_LIST_DIR}/Manifest.cmake") 34 | 35 | @PACKAGE_INIT@ 36 | 37 | include("${CMAKE_CURRENT_LIST_DIR}/SeseTargets.cmake") 38 | check_required_components("@PROJECT_NAME@") -------------------------------------------------------------------------------- /sese/CATALOG.md: -------------------------------------------------------------------------------- 1 | # Directory Explanation 2 | 3 | **internal** is the **Internal Implementation Directory**. 4 | Its contents are not exposed to any project outside of Core and can be specifically used for implementing interfaces. 5 | 6 | **native** is the **System Platform Implementation Directory**, 7 | which contains implementations specific to certain platforms and is typically only exposed to those platforms. 8 | 9 | - darwin usually refers to Apple's macOS platform. 10 | - win generally refers to Microsoft's Windows platform. 11 | - linux typically refers to various Linux distributions. 12 | - unix represents the intersection of darwin and linux. 13 | 14 | **test** is the **Unit Test Directory**. 15 | The root directory contains the main entry point for tests and ordinary test files. 16 | The TestXXX directory contains test cases composed of multiple source files or targets. 17 | The Data directory stores non-source code data needed for testing. 18 | 19 | **benchmark** is the **Performance Test Directory**. 20 | All tests are named in the format BM_Xxx and share the enablement conditions with unit tests. 21 | 22 | **types** is the **Template Type Extraction Tools Directory**, with a different code style from the main project. 23 | -------------------------------------------------------------------------------- /sese/archive/ArchiveOutputStream.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /// \file ArchiveOutputStream.h 16 | /// \brief Archive output stream 17 | /// \author Kaoru 18 | /// \date January 9, 2024 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | namespace sese::archive { 25 | 26 | /// Archive output stream 27 | class ArchiveOutputStream : public io::OutputStream { 28 | public: 29 | explicit ArchiveOutputStream(void *archive_write); 30 | 31 | int64_t write(const void *buffer, size_t length) override; 32 | 33 | protected: 34 | void *archive_write{}; 35 | }; 36 | } -------------------------------------------------------------------------------- /sese/util/Noncopyable.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file Noncopyable.h 17 | * @author kaoru 18 | * @date March 28, 2022 19 | * @brief Non-copyable class 20 | */ 21 | 22 | 23 | #pragma once 24 | 25 | // GCOVR_EXCL_START 26 | 27 | namespace sese { 28 | 29 | /** 30 | * @brief Non-copyable class 31 | */ 32 | class Noncopyable { 33 | public: 34 | Noncopyable() = default; 35 | virtual ~Noncopyable() = default; 36 | 37 | 38 | Noncopyable(const Noncopyable &) = delete; 39 | 40 | Noncopyable &operator=(const Noncopyable &) = delete; 41 | }; 42 | } // namespace sese 43 | 44 | // GCOVR_EXCL_STOP -------------------------------------------------------------------------------- /sese/security/SecurityConfig.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file SecurityConfig.h 17 | * @author kaoru 18 | * @version 0.1 19 | * @brief Security module configuration 20 | * @date September 13, 2023 21 | */ 22 | 23 | #pragma once 24 | 25 | #include "sese/util/Initializer.h" 26 | 27 | namespace sese::security { 28 | /// Security module initialization task 29 | class SecurityInitTask final : public InitiateTask { 30 | public: 31 | SecurityInitTask() : InitiateTask(__FUNCTION__) {} 32 | 33 | int32_t init() noexcept override; 34 | 35 | int32_t destroy() noexcept override; 36 | }; 37 | } // namespace sese::security -------------------------------------------------------------------------------- /sese/archive/Config.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /// \file Config.h 16 | /// \brief Archive-related configuration 17 | /// \author Kaoru 18 | /// \date April 10, 2024 19 | 20 | #pragma once 21 | 22 | namespace sese::archive { 23 | /// @brief Archive configuration class 24 | class Config { 25 | public: 26 | enum class EntryType { 27 | MT, 28 | REG, 29 | LNK, 30 | SOCK, 31 | CHR, 32 | BLK, 33 | DIR, 34 | IFO 35 | }; 36 | static int toValue(EntryType type); 37 | static EntryType fromValue(int value); 38 | }; 39 | } -------------------------------------------------------------------------------- /sese/io/InputStream.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * \file InputStream.h 17 | * \date November 14, 2022 18 | * \author kaoru 19 | * \brief Stream input interface class 20 | * \version 0.1 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | 27 | // GCOVR_EXCL_START 28 | 29 | namespace sese::io { 30 | 31 | /// \brief Stream input interface class 32 | class InputStream { 33 | public: 34 | typedef std::shared_ptr Ptr; 35 | 36 | virtual ~InputStream() noexcept = default; 37 | 38 | virtual int64_t read(void *buffer, size_t length) = 0; 39 | }; 40 | 41 | } // namespace sese::io 42 | 43 | // GCOVR_EXCL_STOP -------------------------------------------------------------------------------- /sese/test/TestPlugin/Module.m.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "sese/plugin/Marco.h" 16 | 17 | class Printable : public sese::plugin::BaseClass { 18 | public: 19 | virtual void run() = 0; 20 | }; 21 | 22 | namespace M { 23 | class Bye : public Printable { 24 | public: 25 | void run() override { 26 | puts("Bye"); 27 | } 28 | }; 29 | 30 | class Hello : public Printable { 31 | public: 32 | void run() override { 33 | puts("Hello"); 34 | } 35 | }; 36 | } // namespace M 37 | 38 | DEFINE_CLASS_FACTORY(MyFactory, "0.2.0", "The module for test.") { 39 | REGISTER_CLASS(M::Bye); 40 | REGISTER_CLASS(M::Hello); 41 | } -------------------------------------------------------------------------------- /sese/test/TestSymbol.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include 18 | 19 | namespace NameSpaceA::NameSpaceB { 20 | class ClassA { 21 | public: 22 | class ClassB { 23 | }; 24 | }; 25 | } // namespace NameSpaceA::NameSpaceB 26 | class ClassC{}; 27 | 28 | TEST(TestSymbol, NamespaceClassName) { 29 | auto type_info = &typeid(NameSpaceA::NameSpaceB::ClassA::ClassB); 30 | EXPECT_EQ(sese::getClassName(type_info), "NameSpaceA::NameSpaceB::ClassA::ClassB"); 31 | } 32 | 33 | TEST(TestSymbol, ClassName) { 34 | auto type_info = &typeid(ClassC); 35 | EXPECT_EQ(sese::getClassName(type_info), "ClassC"); 36 | } -------------------------------------------------------------------------------- /sese/test/Data/test-ca.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDUTCCAjmgAwIBAgIUMtNz7IRugHGz+FuzjaUqlH0FbMIwDQYJKoZIhvcNAQEL 3 | BQAwODELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxFDASBgNVBAoM 4 | C2xpYnNlc2Ugb3JnMB4XDTI0MDMwNTEyMzkyNloXDTM0MDMwMzEyMzkyNlowODEL 5 | MAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxFDASBgNVBAoMC2xpYnNl 6 | c2Ugb3JnMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAp+nC9TaYyDBz 7 | LLqR2rkeiB4Ub0t8Ra+7bXZrnN7l2fc3GqrCkIIty9WWBu+5i4rJxG+pXesDNm16 8 | jhki25MtKZPVxAn5wqE3QzosUcLLiZoz6PnO8YZV7htv+taPjlhm6w+5syGb2+ee 9 | 7uPFA1H1sBvqN25+pIruloFVxpuJbjkzpx3nZByDUEfGywJsNxZjbkBeRAiIOCRO 10 | JyBr2XlwqTZ5k2HqMF41t7pDnnns6JTZTJEfSNz0FmB8QCQUleym1JjH1Nkjf5dM 11 | zy6GWJyj2KrMVg1FnLO9wtVq6X08+gEkZa3R6sbhNaQhfa56YwUQLhEDOSk2uTWT 12 | WWrpgfmtXQIDAQABo1MwUTAdBgNVHQ4EFgQUhsR03j/Ek+7vR4J4dzOTVPl/03ww 13 | HwYDVR0jBBgwFoAUhsR03j/Ek+7vR4J4dzOTVPl/03wwDwYDVR0TAQH/BAUwAwEB 14 | /zANBgkqhkiG9w0BAQsFAAOCAQEAoX2TJbNrV/kfijfXnEV0qF9r3cbMt/UOM+24 15 | 4WCONBpxd9FEPVP/VU852DEP/bOfAjjQqfuu6KdVTz3doEnwsnqaecto4ZXKnDJy 16 | znmsOPXqxKWWjl0lx1PpCnxl45Z2r/XA6b99baKZ84aUrXgnfk2HH9/5oWfbWkLe 17 | T6t6QkW+xJb1rcfwe0cfu+DLRjQtAUbzEvmYZO7y8DW4TdKyrj4PIhZgYoQ7/5Q5 18 | UoEBQPdbijz+TUYRxmLQJLV+IuJJenqPi7qo7H4AerkRuBEkjRoMAsuSNY4RCEyi 19 | 8kHPiv0s1k42T6bkC7NpzPs3+FPunDQIZTknc8rpX3uMcu2JZw== 20 | -----END CERTIFICATE----- 21 | -------------------------------------------------------------------------------- /cmake/Manifest.cmake: -------------------------------------------------------------------------------- 1 | find_package( 2 | Python3 3 | COMPONENTS Interpreter 4 | REQUIRED 5 | ) 6 | 7 | function(target_manifest target manifest_file) 8 | set(script ${SESE_PACKAGE_DIR}/manifest.py) 9 | if(SESE_ROOT_PROJECT) 10 | set(script ${PROJECT_SOURCE_DIR}/scripts/manifest.py) 11 | endif() 12 | if(WIN32) 13 | message(STATUS "(Manifest) Pre-built for manifest: ${target}(${CMAKE_CURRENT_LIST_DIR}/${manifest_file})") 14 | get_target_property(filename ${target} OUTPUT_NAME) 15 | execute_process( 16 | COMMAND ${Python3_EXECUTABLE} ${script} "--manifest_file_path=${CMAKE_CURRENT_LIST_DIR}/${manifest_file}" 17 | "--output_file_path=${CMAKE_BINARY_DIR}/${target}-manifest.rc" "--filename=${filename}" 18 | WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} 19 | OUTPUT_QUIET 20 | RESULT_VARIABLE exit_code 21 | ) 22 | if(${exit_code} EQUAL 0) 23 | message(STATUS "(Manifest) Pre-built complete!!!") 24 | target_sources(${target} PRIVATE "${CMAKE_BINARY_DIR}/${target}-manifest.rc") 25 | else() 26 | message(FATAL_ERROR "(Manifest) Failed") 27 | endif() 28 | endif() 29 | unset(script) 30 | endfunction() 31 | -------------------------------------------------------------------------------- /sese/internal/net/AsioSSLContextConvert.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include "sese/security/SSLContext.h" 18 | 19 | #include 20 | #include 21 | 22 | namespace sese::internal::net { 23 | /// Calling this function will transfer ownership of the context to the new converted object, 24 | /// and the old object will no longer be valid 25 | /// @param context The context 26 | /// @return New asio context object 27 | inline asio::ssl::context convert(std::unique_ptr context) { 28 | return asio::ssl::context(static_cast(context->release())); 29 | } 30 | } // namespace sese::internal::net 31 | -------------------------------------------------------------------------------- /sese/test/TestWebsocketService.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | 20 | #include 21 | 22 | TEST(TestWebsocket, Auth_0) { 23 | auto key = "dGhlIHNhbXBsZSBub25jZQ=="; 24 | auto result = sese::net::ws::WebsocketAuthenticator::toResult(key); 25 | EXPECT_EQ(strcmp("s3pPLMBiTxaQ9kYGzzhZRbK+xOo=", result.get()), 0); 26 | } 27 | 28 | TEST(TestWebsocket, Auth_1) { 29 | auto pair = sese::net::ws::WebsocketAuthenticator::generateKeyPair(); 30 | EXPECT_TRUE(sese::net::ws::WebsocketAuthenticator::verify(pair.first.get(), pair.second.get())); 31 | } -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.yml: -------------------------------------------------------------------------------- 1 | name: Bug Feedback 2 | description: 此模板用于报告不符合预期的问题 3 | labels: ["bug"] 4 | assignees: 5 | - SHIINASAMA 6 | - DreamerQcl 7 | title: "[bug]: " 8 | body: 9 | - type: markdown 10 | attributes: 11 | value: | 12 | 在描述你的问题之前请先尝试自己解决或者查找相似的 issue。 13 | - type: checkboxes 14 | id: checklist 15 | attributes: 16 | label: 确认清单 17 | options: 18 | - label: 我已尝试自己去解决这个问题,但不在我的能力或者职责范围之内。 19 | required: true 20 | - type: textarea 21 | id: description 22 | attributes: 23 | label: 问题描述 24 | - type: input 25 | id: platform 26 | attributes: 27 | label: 平台 28 | description: 请输入程序所运行的平台 29 | validations: 30 | required: true 31 | - type: dropdown 32 | id: module-type 33 | attributes: 34 | label: 模块 35 | description: 请选择需要报告的模块 36 | options: 37 | - common 38 | - archive 39 | - db interface 40 | - sqlite 41 | - mariadb 42 | - mysql 43 | - postgres 44 | validations: 45 | required: true 46 | - type: input 47 | id: version 48 | attributes: 49 | label: 程序版本 50 | description: 请输入你使用的程序版本 51 | validations: 52 | required: true 53 | -------------------------------------------------------------------------------- /sese/thread/Locker.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file Locker.h 17 | * @author kaoru 18 | * @brief Custom std::mutex wrapper 19 | * @date April 5, 2022 20 | */ 21 | 22 | #pragma once 23 | #include "sese/Config.h" 24 | #include 25 | #include 26 | 27 | namespace sese { 28 | 29 | /** 30 | * @brief std::mutex wrapper 31 | * @tparam T std::mutex 32 | */ 33 | template 34 | class Locker { 35 | public: 36 | explicit Locker(T &t) : mutex(t) { 37 | mutex.lock(); 38 | } 39 | ~Locker() { 40 | mutex.unlock(); 41 | } 42 | 43 | private: 44 | T &mutex; 45 | }; 46 | 47 | } // namespace sese 48 | -------------------------------------------------------------------------------- /sese/log/AbstractFormatter.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file AbstractFormatter.h 17 | * @brief Log formatter class 18 | * @author kaoru 19 | * @date March 28, 2022 20 | */ 21 | 22 | #pragma once 23 | #include 24 | #include "sese/log/Event.h" 25 | 26 | #ifdef _WIN32 27 | #pragma warning(disable : 4251) 28 | #endif 29 | 30 | namespace sese::log { 31 | /** 32 | * @brief Log formatter class 33 | */ 34 | class AbstractFormatter { 35 | public: 36 | typedef std::shared_ptr Ptr; 37 | 38 | virtual ~AbstractFormatter() noexcept = default; 39 | 40 | virtual std::string dump(const Event::Ptr &event) noexcept = 0; 41 | }; 42 | } // namespace sese::log -------------------------------------------------------------------------------- /sese/log/FileAppender.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "sese/log/FileAppender.h" 16 | 17 | // GCOVR_EXCL_START 18 | 19 | sese::log::FileAppender::FileAppender(io::FileStream::Ptr file_stream, sese::log::Level level) 20 | : AbstractAppender(level), 21 | fileStream(std::move(file_stream)) { 22 | bufferedStream = std::make_shared(this->fileStream, 4 * 1024); 23 | } 24 | 25 | // GCOVR_EXCL_STOP 26 | 27 | sese::log::FileAppender::~FileAppender() noexcept { 28 | bufferedStream->flush(); 29 | fileStream->close(); 30 | } 31 | 32 | void sese::log::FileAppender::dump(const char *buffer, size_t size) noexcept { 33 | bufferedStream->write((void *) buffer, size); 34 | } 35 | -------------------------------------------------------------------------------- /sese/net/http/Request.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file Request.h 17 | * @brief HTTP Request Class 18 | * @author kaoru 19 | * @version 0.1 20 | * @date September 13, 2023 21 | */ 22 | 23 | 24 | #pragma once 25 | 26 | #include 27 | #include "sese/io/ByteBuilder.h" 28 | 29 | namespace sese::net::http { 30 | 31 | /// HTTP Request Class 32 | class Request final : public RequestHeader { 33 | public: 34 | using Ptr = std::unique_ptr; 35 | 36 | io::ByteBuilder &getBody() { return body; } 37 | 38 | void swap(Request &another) noexcept; 39 | 40 | private: 41 | io::ByteBuilder body{8192}; 42 | }; 43 | 44 | } // namespace sese::net::http -------------------------------------------------------------------------------- /sese/net/http/Response.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file Response.h 17 | * @brief HTTP Response Class 18 | * @author kaoru 19 | * @version 0.1 20 | * @date September 13, 2023 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | #include "sese/io/ByteBuilder.h" 27 | 28 | namespace sese::net::http { 29 | 30 | /// HTTP Response Class 31 | class Response final : public ResponseHeader { 32 | public: 33 | using Ptr = std::unique_ptr; 34 | 35 | io::ByteBuilder &getBody() { return body; } 36 | 37 | void swap(Response &another) noexcept; 38 | 39 | private: 40 | io::ByteBuilder body{8192}; 41 | }; 42 | 43 | } // namespace sese::net::http -------------------------------------------------------------------------------- /sese/util/StopWatch.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file StopWatch.h 17 | * @brief Stopwatch Class 18 | * @author kaoru 19 | * @version 0.1 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | 27 | namespace sese { 28 | 29 | /// Stopwatch Class 30 | class StopWatch { 31 | public: 32 | StopWatch(); 33 | 34 | /** 35 | * Press the stopwatch and return the time interval since the last stop 36 | * @return Time interval 37 | */ 38 | TimeSpan stop(); 39 | 40 | /** 41 | * Reset the stopwatch 42 | */ 43 | void reset(); 44 | 45 | protected: 46 | DateTime lastStopTime; 47 | }; 48 | } // namespace sese 49 | -------------------------------------------------------------------------------- /sese/system/CommandLine.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | using namespace sese::system; 18 | 19 | static int g_argc = 0; 20 | static const char *const *g_argv = nullptr; 21 | 22 | CommandLineInitiateTask::CommandLineInitiateTask(const int ARGC, const char *const *argv) : InitiateTask(__FUNCTION__) { 23 | g_argc = ARGC; 24 | g_argv = argv; 25 | } 26 | 27 | int32_t CommandLineInitiateTask::init() noexcept { 28 | return 0; 29 | } 30 | int32_t CommandLineInitiateTask::destroy() noexcept { 31 | return 0; 32 | } 33 | 34 | int CommandLine::getArgc() { 35 | return g_argc; 36 | } 37 | 38 | const char *const *CommandLine::getArgv() { 39 | return g_argv; 40 | } 41 | -------------------------------------------------------------------------------- /sese/util/EncodingConverter.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file EncodingConverter.h 17 | * @author kaoru 18 | * @date April 15, 2022 19 | * @brief String encoding conversion 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "sese/Config.h" 25 | #include "sese/util/NotInstantiable.h" 26 | 27 | namespace sese { 28 | 29 | /** 30 | * @brief String encoding conversion 31 | */ 32 | class EncodingConverter final : public NotInstantiable { 33 | public: 34 | EncodingConverter() = delete; 35 | 36 | [[maybe_unused]] static std::string toString(const std::wstring &wstring) noexcept; 37 | [[maybe_unused]] static std::wstring toWstring(const std::string &string) noexcept; 38 | }; 39 | 40 | } // namespace sese -------------------------------------------------------------------------------- /sese/config/ini/IniConfig.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * \file IniConfig.h 17 | * \author kaoru 18 | * \brief INI Configuration Class 19 | * \date September 13, 2023 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | #include 27 | 28 | #ifdef _MSC_VER 29 | #pragma warning(disable : 4251) 30 | #endif 31 | 32 | namespace sese::ini { 33 | 34 | /// INI Configuration Class 35 | struct IniConfig { 36 | public: 37 | /// INI SECTION 38 | using Section = std::map; 39 | /// INI SECTION MAPPING 40 | using SectionMap = std::map; 41 | 42 | Section defSection; 43 | SectionMap sectionMap; 44 | }; 45 | 46 | } // namespace sese::ini -------------------------------------------------------------------------------- /sese/io/ByteBuilder.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file ByteBuilder.h 17 | * @brief Non-thread-safe byte buffer class 18 | * @author kaoru 19 | * @date March 28, 2022 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "sese/Config.h" 25 | #include "sese/io/AbstractByteBuffer.h" 26 | 27 | namespace sese::io { 28 | 29 | /** 30 | * @brief Non-thread-safe byte buffer class 31 | */ 32 | class ByteBuilder final : public AbstractByteBuffer { 33 | public: 34 | using Ptr = std::unique_ptr; 35 | 36 | ByteBuilder(size_t baseSize = STREAM_BYTE_STREAM_SIZE_FACTOR, size_t factor = STREAM_BYTE_STREAM_SIZE_FACTOR) noexcept // NOLINT 37 | : AbstractByteBuffer(baseSize, factor) { 38 | } 39 | }; 40 | 41 | } // namespace sese::io -------------------------------------------------------------------------------- /sese/service/Service.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /// \file Service.h 16 | /// \brief Service Interface 17 | /// \author kaoru 18 | /// \date March 4, 2024 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | #include 26 | 27 | namespace sese::service { 28 | 29 | /// @brief Service Interface 30 | class Service { 31 | public: 32 | using Ptr = std::unique_ptr; 33 | 34 | Service() = default; 35 | 36 | virtual ~Service() = default; 37 | 38 | virtual bool startup() = 0; 39 | 40 | virtual bool shutdown() = 0; 41 | 42 | virtual int getLastError() = 0; 43 | 44 | virtual std::string getLastErrorMessage() = 0; 45 | 46 | ErrorCode getErrorCode(); 47 | }; 48 | } // namespace sese::service -------------------------------------------------------------------------------- /sese/net/http/HeaderBuilder.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /// \file HeaderBuilder.h 16 | /// \brief Header Key-Value Collection Builder 17 | /// \author kaoru 18 | /// \date October 31, 2023 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | namespace sese::net::http { 25 | 26 | /// Header Key-Value Collection Builder 27 | class HeaderBuilder { 28 | Header &header; 29 | 30 | public: 31 | explicit HeaderBuilder(Header &header); 32 | HeaderBuilder &operator=(HeaderBuilder &&other) = delete; 33 | HeaderBuilder(const HeaderBuilder &other) = delete; 34 | const HeaderBuilder &operator=(const HeaderBuilder &) = delete; 35 | 36 | HeaderBuilder &&set(const std::string &key, const std::string &value) &&; 37 | }; 38 | 39 | } // namespace sese::net::http -------------------------------------------------------------------------------- /sese/net/http/RequestParser.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /// \file RequestParser.h 16 | /// \author kaoru 17 | /// \brief Request Parser 18 | /// \date October 14, 2023 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | namespace sese::net::http { 27 | 28 | /// Request Parser 29 | class RequestParser { 30 | public: 31 | /// Request Parse Result 32 | struct Result { 33 | Url url; 34 | IPAddress::Ptr address{}; 35 | Request::Ptr request{}; 36 | }; 37 | 38 | static Result parse(const std::string &url); 39 | 40 | static IPv4Address::Ptr parseAddress(const std::string &host) noexcept; 41 | }; 42 | 43 | } // namespace sese::net::http 44 | -------------------------------------------------------------------------------- /sese/security/evp/SM3Context.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /// \file SM3Context.h 16 | /// \brief EVP SM3 algorithm context 17 | /// \author kaoru 18 | /// \date April 11, 2024 19 | 20 | #pragma once 21 | 22 | #include 23 | 24 | namespace sese::security::evp { 25 | 26 | /// EVP SM3 algorithm context 27 | class SM3Context : public Context { 28 | public: 29 | SM3Context() noexcept; 30 | ~SM3Context() noexcept override; 31 | void update(const void *buffer, size_t len) noexcept override; 32 | void final() noexcept override; 33 | void *getResult() noexcept override; 34 | size_t getLength() noexcept override; 35 | 36 | private: 37 | size_t length = 32; 38 | uint8_t result[32]{}; 39 | void *context = nullptr; 40 | }; 41 | 42 | } -------------------------------------------------------------------------------- /sese/test/TestIPC/IPC.d.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | int main(int argc, char **argv) { 21 | sese::initCore(argc, argv); 22 | auto channel = sese::system::IPCChannel::use("IPCTestForSese"); 23 | while (true) { 24 | auto messages = channel->read(1); 25 | if (messages.empty()) { 26 | sese::sleep(1s); 27 | continue; 28 | } 29 | for (auto &&msg: messages) { 30 | SESE_INFO("recv {}", msg.getDataAsString()); 31 | 32 | if (msg.getDataAsString() == "Exit") { 33 | goto end; 34 | } 35 | } 36 | } 37 | end: 38 | return 0; 39 | } -------------------------------------------------------------------------------- /sese/system/Paths.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /// \file Paths.h 16 | /// \brief Runtime Paths 17 | /// \author kaoru 18 | /// \date November 5, 2023 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | namespace sese::system { 26 | 27 | /// Runtime path initialization task 28 | class PathsInitiateTask : public InitiateTask { 29 | public: 30 | PathsInitiateTask(); 31 | 32 | int32_t init() noexcept override; 33 | 34 | int32_t destroy() noexcept override; 35 | }; 36 | 37 | /// Runtime Paths 38 | class Paths { 39 | public: 40 | static const Path &getWorkDir(); 41 | 42 | static const Path &getExecutablePath(); 43 | 44 | static const std::string &getExecutableName(); 45 | }; 46 | } // namespace sese::system 47 | -------------------------------------------------------------------------------- /sese/system/NetworkUtil.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file NetworkUtil.h 17 | * @brief Network Utility Class 18 | * @author kaoru 19 | * @version 0.1 20 | * @date September 13, 2023 21 | */ 22 | 23 | #pragma once 24 | 25 | #include "sese/net/IPv6Address.h" 26 | 27 | #include 28 | 29 | namespace sese::system { 30 | 31 | /// Network Interface Information 32 | struct NetworkInterface { 33 | std::string name; 34 | std::vector ipv4Addresses; 35 | std::vector ipv6Addresses; 36 | std::array mac; 37 | }; 38 | 39 | /// Network Utility Class 40 | class NetworkUtil { 41 | public: 42 | static std::vector getNetworkInterface() noexcept; 43 | }; 44 | } // namespace sese::system 45 | -------------------------------------------------------------------------------- /sese/security/evp/Context.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file Context.h 17 | * @author kaoru 18 | * @version 0.1 19 | * @brief Base class for EVP context 20 | * @date September 13, 2023 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | 27 | namespace sese::security::evp { 28 | 29 | /// Base class for EVP context 30 | class Context { 31 | public: 32 | using Ptr = std::unique_ptr; 33 | 34 | Context() = default; 35 | 36 | virtual ~Context() noexcept = default; 37 | 38 | virtual void update(const void *buffer, size_t len) noexcept = 0; 39 | 40 | virtual void final() noexcept = 0; 41 | 42 | virtual void *getResult() noexcept = 0; 43 | 44 | virtual size_t getLength() noexcept = 0; 45 | }; 46 | 47 | } // namespace sese::security::evp -------------------------------------------------------------------------------- /sese/types/is_iterable.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include 18 | 19 | namespace sese { 20 | 21 | template 22 | struct has_begin : std::false_type {}; // NOLINT 23 | 24 | template 25 | struct has_begin().begin())>> : std::true_type {}; 26 | 27 | template 28 | struct has_end : std::false_type {}; // NOLINT 29 | 30 | template 31 | struct has_end().begin())>> : std::true_type {}; 32 | 33 | template 34 | struct is_iterable : std::conjunction, has_end> {}; // NOLINT 35 | 36 | template 37 | constexpr bool is_iterable_v = is_iterable::value; // NOLINT 38 | 39 | } // namespace sese -------------------------------------------------------------------------------- /sese/io/InputStreamReader.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /// \file InputStreamReader.h 16 | /// \author kaoru 17 | /// \brief Readable stream reader 18 | /// \date September 11, 2023 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | namespace sese::io { 26 | 27 | /// Readable stream reader 28 | class InputStreamReader { 29 | public: 30 | explicit InputStreamReader(io::PeekableStream *input) noexcept; 31 | 32 | /// Read a line 33 | /// \note Supports CR, LF, CRLF line separators 34 | /// \return Returns std::string {} if all content is read (e.g., EOF of a file stream) 35 | std::string readLine() noexcept; 36 | 37 | protected: 38 | PeekableStream *input; 39 | text::StringBuilder builder; 40 | }; 41 | } // namespace sese::io -------------------------------------------------------------------------------- /cmake/Options.cmake: -------------------------------------------------------------------------------- 1 | option(SESE_USE_NATIVE_MANAGER "(Deprecated) use the unix-like packages control" OFF) 2 | option(SESE_BUILD_TEST "build unit test targets" OFF) 3 | option(SESE_BUILD_EXAMPLE "build example targets" OFF) 4 | option(SESE_AUTO_VCPKG "auto find vcpkg and include toolchain" OFF) 5 | option(SESE_USE_ASYNC_LOGGER "use async logger" OFF) 6 | option(SESE_USE_ARCHIVE "add archive support" OFF) 7 | option(SESE_REPLACE_EXECINFO "replace the system execinfo implementation" OFF) 8 | option(SESE_DB_USE_SQLITE "add sqlite support" ON) 9 | option(SESE_DB_USE_MARIADB "add mariadb and mysql support" OFF) 10 | option(SESE_DB_USE_POSTGRES "add postgresql support" OFF) 11 | 12 | if(SESE_USE_NATIVE_MANAGER) 13 | message(FATAL_ERROR "The `SESE_USE_NATIVE_MANAGER` option has been deprecated.") 14 | endif() 15 | 16 | if(SESE_BUILD_TEST) 17 | # This sentence must be in the root folder. 18 | enable_testing() 19 | endif() 20 | 21 | include(cmake/MiniSeseTools.cmake) 22 | 23 | sese_auto_enable_feature(SESE_BUILD_TEST "tests") 24 | sese_auto_enable_feature(SESE_USE_ARCHIVE "archive") 25 | sese_auto_enable_feature(SESE_REPLACE_EXECINFO "replace-execinfo") 26 | sese_auto_enable_feature(SESE_DB_USE_SQLITE "sqlite3") 27 | sese_auto_enable_feature(SESE_DB_USE_MARIADB "mysql") 28 | sese_auto_enable_feature(SESE_DB_USE_POSTGRES "psql") 29 | 30 | option(SESE_ENABLE_ASAN "build with asan" OFF) 31 | option(SESE_ENABLE_COVERAGE "build for coverage test" OFF) 32 | -------------------------------------------------------------------------------- /sese/net/IPAddress.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "sese/net/IPAddress.h" 16 | 17 | using namespace sese::net; 18 | 19 | IPAddress::Ptr IPAddress::create(const char *address, uint16_t port) { 20 | addrinfo *res, hints{0}; 21 | hints.ai_flags = AI_NUMERICHOST; 22 | hints.ai_family = AF_UNSPEC; 23 | 24 | auto err = getaddrinfo(address, nullptr, &hints, &res); 25 | if (err) { 26 | return nullptr; 27 | } 28 | 29 | // GCOVR_EXCL_START 30 | IPAddress::Ptr result = std::dynamic_pointer_cast(Address::create(res->ai_addr, static_cast(res->ai_addrlen))); 31 | if (result) { 32 | result->setPort(port); 33 | } 34 | else { 35 | result = nullptr; 36 | } 37 | // GCOVR_EXCL_STOP 38 | 39 | freeaddrinfo(res); 40 | return result; 41 | } 42 | -------------------------------------------------------------------------------- /sese/net/dns/DnsPackage_Flags.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "DnsPackage.h" 16 | 17 | void sese::net::dns::DnsPackage::Flags::decode(uint16_t flags) { 18 | qr = (flags >> 15) & 0x1; 19 | opcode = (flags >> 11) & 0xF; 20 | aa = (flags >> 10) & 0x1; 21 | tc = (flags >> 9) & 0x1; 22 | rd = (flags >> 8) & 0x1; 23 | ra = (flags >> 7) & 0x1; 24 | z = (flags >> 4) & 0x7; 25 | rcode = flags & 0xF; 26 | } 27 | 28 | uint16_t sese::net::dns::DnsPackage::Flags::encode() const { 29 | uint16_t flags = 0; 30 | 31 | flags |= (qr & 0x1) << 15; 32 | flags |= (opcode & 0xF) << 11; 33 | flags |= (aa & 0x1) << 10; 34 | flags |= (tc & 0x1) << 9; 35 | flags |= (rd & 0x1) << 8; 36 | flags |= (ra & 0x1) << 7; 37 | flags |= (z & 0x7) << 4; 38 | flags |= (rcode & 0xF); 39 | 40 | return flags; 41 | } 42 | 43 | -------------------------------------------------------------------------------- /sese/text/TextReader.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file TextReader.h 17 | * @author kaoru 18 | * @version 0.1 19 | * @brief Text reader class 20 | * @date September 13, 2023 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | namespace sese::text { 31 | 32 | /// Text reader class 33 | class TextReader final { 34 | public: 35 | using Ptr = std::shared_ptr; 36 | 37 | ~TextReader() noexcept; 38 | static std::shared_ptr create(const char *u8str) noexcept; 39 | String readLine(); 40 | 41 | private: 42 | TextReader() = default; 43 | 44 | io::FileStream::Ptr fileStream; 45 | io::BufferedStream::Ptr bufferedStream; 46 | }; 47 | } // namespace sese::text -------------------------------------------------------------------------------- /sese/util/UuidBuilder.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * \file UuidBuilder.h 17 | * \author kaoru 18 | * \date December 24, 2022 19 | * \version 0.1 20 | * \brief UUID Generation Related 21 | */ 22 | 23 | #pragma once 24 | 25 | #ifdef WIN32 26 | #pragma warning(disable : 4251) 27 | #endif 28 | 29 | #include "sese/Config.h" 30 | #include "sese/util/TimestampHandler.h" 31 | #include "sese/util/Uuid.h" 32 | 33 | namespace sese { 34 | /// Uuid Builder 35 | class UuidBuilder { 36 | public: 37 | /// Constructor 38 | explicit UuidBuilder() noexcept; 39 | 40 | /// Generate UUID 41 | /// \param dest UUID to store the result 42 | /// \return Whether generation is successful 43 | bool generate(sese::Uuid &dest) noexcept; 44 | 45 | protected: 46 | sese::TimestampHandler timestampHandler; 47 | }; 48 | } // namespace sese 49 | 50 | -------------------------------------------------------------------------------- /sese/test/TestStrCaseMap.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | 18 | TEST(TestStrCaseMap, Map) { 19 | sese::StrCaseMap map; 20 | map["ABC"] = 1; 21 | { 22 | auto iterator = map.find("abc"); 23 | ASSERT_NE(iterator, map.end()); 24 | EXPECT_EQ(iterator->second, 1); 25 | } 26 | { 27 | auto iterator = map.find("CBA"); 28 | ASSERT_EQ(iterator, map.end()); 29 | } 30 | } 31 | 32 | TEST(TestStrCaseMap, UnorderedMap) { 33 | sese::StrCaseUnorderedMap map; 34 | map["ABC"] = 1; 35 | { 36 | auto iterator = map.find("abc"); 37 | ASSERT_NE(iterator, map.end()); 38 | EXPECT_EQ(iterator->second, 1); 39 | } 40 | { 41 | auto iterator = map.find("CBA"); 42 | ASSERT_EQ(iterator, map.end()); 43 | } 44 | } -------------------------------------------------------------------------------- /cmake/Asan.cmake: -------------------------------------------------------------------------------- 1 | if(SESE_ENABLE_ASAN) 2 | if(MSVC) 3 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fsanitize=address") 4 | if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64") 5 | set(ASAN_DLL_NAME "clang_rt.asan_dynamic-x86_64.dll") 6 | else() 7 | message(FATAL_ERROR "Asan is used on \"${CMAKE_SYSTEM_PROCESSOR}\" not supported by msvc.") 8 | endif() 9 | find_path( 10 | ASAN_PATH 11 | NAMES ${ASAN_DLL_NAME} 12 | PATHS ${VCPKG_VISUAL_STUDIO_PATH} 13 | ) 14 | if(NOT ASAN_PATH) 15 | message( 16 | WARNING 17 | "The dynamic libraries required to enable asan for a particular compiler have not been found, and running them directly may result in errors." 18 | ) 19 | message( 20 | WARNING 21 | "See: https://devblogs.microsoft.com/cppblog/msvc-address-sanitizer-one-dll-for-all-runtime-configurations" 22 | ) 23 | endif() 24 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) 25 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) 26 | file(COPY "${ASAN_PATH}/${ASAN_DLL_NAME}" DESTINATION ${PROJECT_BINARY_DIR}/bin) 27 | else() 28 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -gdwarf-4") 29 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address") 30 | endif() 31 | endif() 32 | -------------------------------------------------------------------------------- /sese/log/Marco.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file Marco.h 17 | * @author kaoru 18 | * @version 0.1 19 | * @brief Log macros 20 | * @date September 13, 2023 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | 27 | #define SESE_RAW(buffer, length) \ 28 | sese::log::getLogger()->dump(buffer, length) 29 | 30 | #define SESE_EXCEPT(e) e.printStacktrace(sese::log::getLogger()) 31 | 32 | #define SESE_DEBUG(sese_tmp_format, ...) \ 33 | sese::log::Logger::debug(sese_tmp_format, ##__VA_ARGS__) 34 | 35 | #define SESE_INFO(sese_tmp_format, ...) \ 36 | sese::log::Logger::info(sese_tmp_format, ##__VA_ARGS__) 37 | 38 | #define SESE_WARN(sese_tmp_format, ...) \ 39 | sese::log::Logger::warn(sese_tmp_format, ##__VA_ARGS__) 40 | 41 | #define SESE_ERROR(sese_tmp_format, ...) \ 42 | sese::log::Logger::error(sese_tmp_format, ##__VA_ARGS__) 43 | -------------------------------------------------------------------------------- /.idea/icon.svg: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 18 | 20 | 21 | 22 | 23 | 25 | 26 | 28 | 29 | 31 | 32 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /sese/test/TestEncodingConverter.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include 18 | 19 | TEST(TestEncoding, String2WString) { 20 | std::string str = "你好"; 21 | std::wstring wstr = L"你好"; 22 | 23 | // ASSERT_EQ(sese::EncodingConverter::toWstring(str), wstr); 24 | // std::wstring_convert> convert; 25 | // EXPECT_EQ(convert.from_bytes(str), wstr); 26 | EXPECT_EQ(sese::EncodingConverter::toWstring(str), wstr); 27 | } 28 | 29 | TEST(TestEncoding, WString2String) { 30 | std::string str = "你好"; 31 | std::wstring wstr = L"你好"; 32 | 33 | // ASSERT_EQ(sese::EncodingConverter::toString(wstr), str); 34 | // std::wstring_convert> convert; 35 | // EXPECT_EQ(convert.to_bytes(wstr), str); 36 | EXPECT_EQ(sese::EncodingConverter::toString(wstr), str); 37 | } -------------------------------------------------------------------------------- /sese/util/GZipFileInputStream.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | 18 | sese::GZipFileInputStream::Ptr sese::GZipFileInputStream::create(const char *file) noexcept { 19 | auto gz_file = gzopen(file, "rb"); 20 | if (!gz_file) return nullptr; 21 | auto p_stream = new GZipFileInputStream; 22 | p_stream->gzFile = gz_file; 23 | return {p_stream, deleter}; 24 | } 25 | 26 | int64_t sese::GZipFileInputStream::read(void *buffer, size_t length) { 27 | return gzread(static_cast(gzFile), buffer, static_cast(length)); 28 | } 29 | 30 | void sese::GZipFileInputStream::close() noexcept { 31 | gzclose(static_cast(gzFile)); 32 | gzFile = nullptr; 33 | } 34 | 35 | void sese::GZipFileInputStream::deleter(GZipFileInputStream *data) noexcept { 36 | delete data; // GCOVR_EXCL_LINE 37 | } 38 | -------------------------------------------------------------------------------- /static/image/logo.svg: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 18 | 20 | 21 | 22 | 23 | 25 | 26 | 28 | 29 | 31 | 32 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /sese/system/SharedMemory.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "SharedMemory.h" 16 | 17 | #include "sese/util/Util.h" 18 | 19 | sese::Result sese::system::SharedMemory::createEx(const char *name, size_t size) noexcept { 20 | if (auto result = create(name, size)) { 21 | return Result::success(std::move(result)); 22 | } 23 | return Result::error({ 24 | getErrorCode(), 25 | getErrorString() 26 | }); 27 | } 28 | 29 | sese::Result sese::system::SharedMemory::useEx(const char *name) noexcept { 30 | if (auto result = use(name)) { 31 | return Result::success(std::move(result)); 32 | } 33 | return Result::error({ 34 | getErrorCode(), 35 | getErrorString() 36 | }); 37 | } 38 | -------------------------------------------------------------------------------- /sese/container/StrCaseMap.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | 22 | bool sese::StrCaseMapComparer::operator()(const std::string &lv, const std::string &rv) const { 23 | return sese::StrCmpI()(lv, rv) < 0; 24 | } 25 | 26 | size_t sese::StrCaseUnorderedMapComparer::operator()(const std::string &key) const { 27 | #if defined(SESE_PLATFORM_WINDOWS) && !defined(__MINGW32__) 28 | #define XX std::tolower 29 | #else 30 | #define XX ::tolower 31 | #endif 32 | auto temp = key; 33 | std::transform(temp.begin(), temp.end(), temp.begin(), tolower); 34 | return std::hash{}(temp); 35 | #undef XX 36 | } 37 | 38 | bool sese::StrCaseUnorderedMapComparer::operator()(const std::string &lv, const std::string &rv) const { 39 | return sese::StrCmpI()(lv, rv) == 0; 40 | } -------------------------------------------------------------------------------- /scripts/cmake_format.py: -------------------------------------------------------------------------------- 1 | # Copyright 2024 libsese 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | import os 17 | import subprocess 18 | 19 | 20 | def find_cmake_files(paths): 21 | cmake_files = [] 22 | 23 | for path in paths: 24 | for root, _, files in os.walk(path): 25 | for file in files: 26 | if file.endswith('.cmake'): 27 | cmake_files.append(os.path.join(root, file)) 28 | if file == 'CMakeLists.txt': 29 | cmake_files.append(os.path.join(root, file)) 30 | 31 | return cmake_files 32 | 33 | 34 | def format_cmake_files(cmake_files): 35 | cmd = ['cmake-format', '-c', '.cmake-format.yaml', '-i'] + cmake_files 36 | subprocess.run(cmd) 37 | 38 | 39 | if __name__ == "__main__": 40 | paths = [ 41 | "sese", 42 | "cmake" 43 | ] 44 | 45 | cmake_files = find_cmake_files(paths) 46 | cmake_files.append('CMakeLists.txt') 47 | format_cmake_files(cmake_files) 48 | -------------------------------------------------------------------------------- /sese/config/CSVWriter.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "sese/config/CSVWriter.h" 16 | 17 | const char *sese::CSVWriter::crlf = "\r\n"; 18 | const char *sese::CSVWriter::lf = "\n"; 19 | 20 | sese::CSVWriter::CSVWriter(OutputStream *dest, char split_char, bool crlf) noexcept { 21 | CSVWriter::dest = dest; 22 | CSVWriter::splitChar = split_char; 23 | CSVWriter::isCRLF = crlf; 24 | } 25 | 26 | void sese::CSVWriter::write(const sese::CSVWriter::Row &row) noexcept { 27 | bool first = true; 28 | for (const auto &col: row) { 29 | if (first) { 30 | first = false; 31 | dest->write(col.c_str(), col.size()); 32 | } else { 33 | dest->write(&splitChar, 1); 34 | dest->write(col.c_str(), col.size()); 35 | } 36 | } 37 | if (isCRLF) { 38 | dest->write(crlf, 2); 39 | } else { 40 | dest->write(lf, 1); 41 | } 42 | } -------------------------------------------------------------------------------- /sese/log/ConsoleAppender.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file ConsoleAppender.h 17 | * @author kaoru 18 | * @date March 28, 2022 19 | * @brief Console log appender class 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "sese/log/AbstractAppender.h" 25 | #include "sese/log/AbstractFormatter.h" 26 | #include "sese/log/Event.h" 27 | 28 | namespace sese::log { 29 | /** 30 | * @brief Console log appender class 31 | */ 32 | class ConsoleAppender final : public AbstractAppender { 33 | public: 34 | explicit ConsoleAppender(Level level = Level::DEBUG) noexcept; 35 | 36 | void dump(const char *buffer, size_t size) noexcept override; 37 | 38 | public: 39 | static void setDebugColor() noexcept; 40 | static void setInfoColor() noexcept; 41 | static void setWarnColor() noexcept; 42 | static void setErrorColor() noexcept; 43 | static void setCleanColor() noexcept; 44 | }; 45 | } // namespace sese::log -------------------------------------------------------------------------------- /CMakePresets.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 6, 3 | "configurePresets": [ 4 | { 5 | "name": "base", 6 | "binaryDir": "${sourceDir}/build/${presetName}", 7 | "generator": "Ninja", 8 | "toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", 9 | "cacheVariables": { 10 | "CMAKE_BUILD_TYPE": "Debug", 11 | "CMAKE_EXPORT_COMPILE_COMMANDS": true, 12 | "VCPKG_USE_HOST_TOOLS": true, 13 | "SESE_ENABLE_ASAN": true, 14 | "SESE_ENABLE_COVERAGE": false, 15 | "SESE_BUILD_TEST": true, 16 | "SESE_BUILD_EXAMPLE": true, 17 | "SESE_USE_ARCHIVE": true, 18 | "SESE_DB_USE_MARIADB": true, 19 | "SESE_DB_USE_POSTGRES": true, 20 | "SESE_DB_USE_SQLITE": true 21 | } 22 | } 23 | ], 24 | "buildPresets": [ 25 | { 26 | "name": "base", 27 | "configurePreset": "base" 28 | } 29 | ], 30 | "testPresets": [ 31 | { 32 | "name": "test", 33 | "description": "Run all tests.", 34 | "configurePreset": "base", 35 | "environment": { 36 | "GTEST_OUTPUT": "xml:build/test_report.xml" 37 | }, 38 | "output": { 39 | "verbosity": "verbose" 40 | } 41 | }, 42 | { 43 | "name": "test-without-db", 44 | "description": "Run all tests excluding database-driven test suites.", 45 | "environment": { 46 | "GTEST_FILTER": "-TestMaria*:TestPostgres*:TestSqlite*" 47 | }, 48 | "inherits": [ 49 | "test" 50 | ] 51 | } 52 | ] 53 | } -------------------------------------------------------------------------------- /sese/plugin/ClassFactory.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "sese/plugin/ClassFactory.h" 16 | 17 | sese::plugin::BaseClass::Ptr sese::plugin::ClassFactory::createClassWithName(const std::string &name) noexcept { 18 | auto iterator = infoMap.find(name); 19 | if (iterator != infoMap.end()) { 20 | return iterator->second.builder(); 21 | } 22 | return nullptr; 23 | } 24 | 25 | sese::Result sese::plugin::ClassFactory::createClassWithNameEx(const std::string &name) noexcept { 26 | if (auto result = createClassWithName(name)) { 27 | return Result::success(std::move(result)); 28 | } 29 | return Result::error({1, "Cannot find class named " + name}); 30 | } 31 | 32 | const sese::plugin::ClassFactory::RegisterInfoMapType &sese::plugin::ClassFactory::getRegisterClassInfo() noexcept { 33 | return infoMap; 34 | } 35 | -------------------------------------------------------------------------------- /sese/benchmark/BM_StringBuilder.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | using sese::text::StringBuilder; 20 | using std::stringstream; 21 | 22 | constexpr auto SZ = 16 * 1024; 23 | constexpr auto TIMES = 1000; 24 | 25 | static void BM_StringBuilder(benchmark::State &state) { 26 | for (auto _: state) { 27 | StringBuilder builder(SZ); 28 | for (int i = 0; i < TIMES; ++i) { 29 | builder << "Number:" << std::to_string(i) << ";"; 30 | } 31 | } 32 | } 33 | 34 | static void BM_StringStream(benchmark::State &state) { 35 | for (auto _: state) { 36 | stringstream stream; 37 | for (int i = 0; i < TIMES; ++i) { 38 | stream << "Number:" << std::to_string(i) << ";"; 39 | } 40 | } 41 | } 42 | 43 | BENCHMARK(BM_StringBuilder); 44 | BENCHMARK(BM_StringStream); 45 | BENCHMARK_MAIN(); -------------------------------------------------------------------------------- /sese/internal/service/http/Handleable.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | 24 | namespace sese::internal::service::http { 25 | 26 | struct Handleable { 27 | using Ptr = std::shared_ptr; 28 | 29 | ConnType conn_type = ConnType::NONE; 30 | sese::net::http::Request request; 31 | sese::net::http::Response response; 32 | std::string content_type = "application/x-"; 33 | io::File::Ptr file; 34 | size_t filesize = 0; 35 | std::vector ranges; 36 | std::vector::iterator range_iterator = ranges.begin(); 37 | sese::net::IPAddress::Ptr remote_address{}; 38 | bool keepalive = false; 39 | sese::StopWatch stopwatch; 40 | }; 41 | 42 | } -------------------------------------------------------------------------------- /sese/system/CommandLine.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /// \file CommandLine.h 16 | /// \brief Command line argument class 17 | /// \author kaoru 18 | /// \date October 26, 2023 19 | 20 | 21 | #pragma once 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | namespace sese::system { 28 | 29 | /// Command line arguments initialize the task 30 | class CommandLineInitiateTask final : public InitiateTask { 31 | public: 32 | explicit CommandLineInitiateTask(int argc, const char *const *argv); 33 | 34 | int32_t init() noexcept override; 35 | 36 | int32_t destroy() noexcept override; 37 | }; 38 | 39 | /// Command line argument class 40 | class CommandLine final : public NotInstantiable { 41 | public: 42 | CommandLine() = delete; 43 | 44 | static int getArgc(); 45 | 46 | static const char *const *getArgv(); 47 | }; 48 | 49 | } // namespace sese::system -------------------------------------------------------------------------------- /sese/io/PeekableStream.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /// \file PeekableStream.h 16 | /// \author kaoru 17 | /// \brief Peekable stream interface 18 | /// \version 0.2 19 | /// \date June 11, 2023 20 | 21 | #pragma once 22 | 23 | #include "sese/Config.h" 24 | 25 | namespace sese::io { 26 | 27 | // GCOVR_EXCL_START 28 | 29 | /// Peekable stream interface 30 | class PeekableStream { 31 | public: 32 | virtual ~PeekableStream() = default; 33 | typedef std::shared_ptr Ptr; 34 | 35 | /// Read content without stepping 36 | /// \param buffer Buffer 37 | /// \param length Buffer size 38 | /// \return Actual size read 39 | virtual int64_t peek(void *buffer, size_t length) = 0; 40 | 41 | /// Step only, without reading content 42 | /// \param length Step size 43 | /// \return Actual step size 44 | virtual int64_t trunc(size_t length) = 0; 45 | }; 46 | 47 | // GCOVR_EXCL_STOP 48 | 49 | } // namespace sese::io -------------------------------------------------------------------------------- /sese/security/evp/MD5Context.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file MD5Context.h 17 | * @author kaoru 18 | * @version 0.1 19 | * @brief EVP MD5 algorithm context 20 | * @date September 13, 2023 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | 27 | namespace sese::security::evp { 28 | 29 | /// EVP MD5 algorithm context 30 | class MD5Context : public Context { 31 | public: 32 | MD5Context() noexcept; 33 | ~MD5Context() noexcept override; 34 | void update(const void *buffer, size_t len) noexcept override; 35 | void final() noexcept override; 36 | void *getResult() noexcept override; 37 | size_t getLength() noexcept override; 38 | 39 | private: 40 | size_t length = 16; 41 | uint8_t result[16]{}; 42 | #ifdef SESE_PLATFORM_WINDOWS 43 | uint64_t hProv = 0; 44 | uint64_t hHash = 0; 45 | #else 46 | void *context = nullptr; 47 | #endif 48 | }; 49 | } // namespace sese::security::evp -------------------------------------------------------------------------------- /sese/security/evp/SHA1Context.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file SHA1Context.h 17 | * @author kaoru 18 | * @version 0.1 19 | * @brief EVP SHA1 algorithm context 20 | * @date September 13, 2023 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | 27 | namespace sese::security::evp { 28 | 29 | /// EVP SHA1 algorithm context 30 | class SHA1Context : public Context { 31 | public: 32 | SHA1Context() noexcept; 33 | ~SHA1Context() noexcept override; 34 | void update(const void *buffer, size_t len) noexcept override; 35 | void final() noexcept override; 36 | void *getResult() noexcept override; 37 | size_t getLength() noexcept override; 38 | 39 | private: 40 | size_t length = 20; 41 | uint8_t result[20]{}; 42 | #ifdef SESE_PLATFORM_WINDOWS 43 | uint64_t hProv = 0; 44 | uint64_t hHash = 0; 45 | #else 46 | void *context = nullptr; 47 | #endif 48 | }; 49 | } // namespace sese::security::evp -------------------------------------------------------------------------------- /sese/internal/unix/security/evp/MD5Context.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include 18 | 19 | sese::security::evp::MD5Context::MD5Context() noexcept : Context() { 20 | this->context = EVP_MD_CTX_new(); 21 | EVP_DigestInit((EVP_MD_CTX *) this->context, EVP_md5()); 22 | } 23 | 24 | sese::security::evp::MD5Context::~MD5Context() noexcept { 25 | EVP_MD_CTX_free((EVP_MD_CTX *) this->context); 26 | } 27 | 28 | void sese::security::evp::MD5Context::update(const void *buffer, size_t len) noexcept { 29 | EVP_DigestUpdate((EVP_MD_CTX *) this->context, buffer, len); 30 | } 31 | 32 | void sese::security::evp::MD5Context::final() noexcept { 33 | EVP_DigestFinal((EVP_MD_CTX *) this->context, result, nullptr); 34 | } 35 | 36 | void *sese::security::evp::MD5Context::getResult() noexcept { 37 | return result; 38 | } 39 | 40 | size_t sese::security::evp::MD5Context::getLength() noexcept { 41 | return length; 42 | } -------------------------------------------------------------------------------- /sese/log/FileAppender.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file FileAppender.h 17 | * @author kaoru 18 | * @brief Log file appender class 19 | * @date March 28, 2022 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "sese/log/AbstractAppender.h" 25 | #include "sese/io/FileStream.h" 26 | #include "sese/io/BufferedStream.h" 27 | 28 | #ifdef _WIN32 29 | #pragma warning(disable : 4996) 30 | #endif 31 | 32 | namespace sese::log { 33 | /** 34 | * @brief Log file appender class 35 | */ 36 | class FileAppender final : public sese::log::AbstractAppender { 37 | public: 38 | typedef std::shared_ptr Ptr; 39 | 40 | explicit FileAppender(io::FileStream::Ptr file_stream, Level level = Level::DEBUG); 41 | 42 | ~FileAppender() noexcept override; 43 | 44 | void dump(const char *buffer, size_t size) noexcept override; 45 | 46 | private: 47 | io::BufferedStream::Ptr bufferedStream; 48 | io::FileStream::Ptr fileStream; 49 | }; 50 | } // namespace sese::log -------------------------------------------------------------------------------- /sese/security/evp/SHA256Context.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file SHA256Context.h 17 | * @author kaoru 18 | * @version 0.1 19 | * @brief EVP SHA256 algorithm context 20 | * @date September 13, 2023 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | 27 | namespace sese::security::evp { 28 | 29 | /// EVP SHA256 algorithm context 30 | class SHA256Context : public Context { 31 | public: 32 | SHA256Context() noexcept; 33 | ~SHA256Context() noexcept override; 34 | void update(const void *buffer, size_t len) noexcept override; 35 | void final() noexcept override; 36 | void *getResult() noexcept override; 37 | size_t getLength() noexcept override; 38 | 39 | private: 40 | size_t length = 32; 41 | uint8_t result[32]{}; 42 | #ifdef SESE_PLATFORM_WINDOWS 43 | uint64_t hProv = 0; 44 | uint64_t hHash = 0; 45 | #else 46 | void *context = nullptr; 47 | #endif 48 | }; 49 | } // namespace sese::security::evp -------------------------------------------------------------------------------- /sese/security/evp/SHA384Context.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file SHA384Context.h 17 | * @author kaoru 18 | * @version 0.1 19 | * @brief EVP SHA384 algorithm context 20 | * @date September 13, 2023 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | 27 | namespace sese::security::evp { 28 | 29 | /// EVP SHA384 algorithm context 30 | class SHA384Context : public Context { 31 | public: 32 | SHA384Context() noexcept; 33 | ~SHA384Context() noexcept override; 34 | void update(const void *buffer, size_t len) noexcept override; 35 | void final() noexcept override; 36 | void *getResult() noexcept override; 37 | size_t getLength() noexcept override; 38 | 39 | private: 40 | size_t length = 48; 41 | uint8_t result[48]{}; 42 | #ifdef SESE_PLATFORM_WINDOWS 43 | uint64_t hProv = 0; 44 | uint64_t hHash = 0; 45 | #else 46 | void *context = nullptr; 47 | #endif 48 | }; 49 | } // namespace sese::security::evp -------------------------------------------------------------------------------- /sese/security/evp/SHA512Context.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file SHA512Context.h 17 | * @author kaoru 18 | * @version 0.1 19 | * @brief EVP SHA512 algorithm context 20 | * @date September 13, 2023 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | 27 | namespace sese::security::evp { 28 | 29 | /// EVP SHA512 algorithm context 30 | class SHA512Context : public Context { 31 | public: 32 | SHA512Context() noexcept; 33 | ~SHA512Context() noexcept override; 34 | void update(const void *buffer, size_t len) noexcept override; 35 | void final() noexcept override; 36 | void *getResult() noexcept override; 37 | size_t getLength() noexcept override; 38 | 39 | private: 40 | size_t length = 64; 41 | uint8_t result[64]{}; 42 | #ifdef SESE_PLATFORM_WINDOWS 43 | uint64_t hProv = 0; 44 | uint64_t hHash = 0; 45 | #else 46 | void *context = nullptr; 47 | #endif 48 | }; 49 | } // namespace sese::security::evp -------------------------------------------------------------------------------- /sese/util/Singleton.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file Singleton.h 17 | * @brief Singleton Template Class 18 | * @author kaoru 19 | * @date March 28, 2022 20 | */ 21 | 22 | #pragma once 23 | #include "sese/Config.h" 24 | 25 | namespace sese { 26 | 27 | /** 28 | * @brief Raw Pointer Singleton Template Class 29 | * @tparam T 30 | * @tparam X 31 | * @tparam N 32 | */ 33 | template 34 | class Singleton { 35 | public: 36 | static T *getInstance() { 37 | static T v; 38 | return &v; 39 | } 40 | }; 41 | 42 | /** 43 | * @brief Smart Pointer Singleton Template Class 44 | * @tparam T 45 | * @tparam X 46 | * @tparam N 47 | */ 48 | template 49 | class SingletonPtr { 50 | public: 51 | static std::shared_ptr getInstance() { 52 | static std::shared_ptr v(new T); // GCOVR_EXCL_LINE 53 | return v; 54 | } 55 | }; 56 | 57 | } // namespace sese -------------------------------------------------------------------------------- /sese/io/OutputBufferWrapper.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * \file OutputBufferWrapper.h 17 | * \author kaoru 18 | * \date December 14, 2022 19 | * \version 0.1 20 | * \brief Output buffer wrapper 21 | */ 22 | 23 | #pragma once 24 | 25 | #include "sese/io/OutputStream.h" 26 | 27 | #include 28 | 29 | namespace sese::io { 30 | 31 | // GCOVR_EXCL_START 32 | 33 | /// \brief Output buffer wrapper 34 | class OutputBufferWrapper final : public OutputStream { 35 | public: 36 | OutputBufferWrapper(char *buffer, size_t cap); 37 | 38 | int64_t write(const void *buffer, size_t length) override; 39 | 40 | void reset() noexcept; 41 | 42 | [[nodiscard]] const char *getBuffer() const; 43 | [[nodiscard]] size_t getLength() const; 44 | [[nodiscard]] size_t getCapacity() const; 45 | 46 | protected: 47 | char *buffer = nullptr; 48 | size_t len = 0; 49 | size_t cap = 0; 50 | }; 51 | 52 | // GCOVR_EXCL_STOP 53 | 54 | } // namespace sese::io -------------------------------------------------------------------------------- /sese/DarwinConfig.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file Config.h 17 | * @brief Darwin platform configuration file 18 | * @author kaoru 19 | * @date March 28, 2022 20 | */ 21 | 22 | #pragma once 23 | 24 | #if defined(__x86_64__) 25 | #define SESE_ARCH_X64 26 | #elif defined(__aarch64__) 27 | #define SESE_ARCH_ARM64 28 | #else 29 | #error only support x86_64 & arm64 30 | #endif 31 | 32 | /// C++ version identifier 33 | #define SESE_CXX_STANDARD __cplusplus 34 | /// Type identifiers can be exported 35 | #define API 36 | /// pid_t Formatting placeholders 37 | #define PRIdTid "d" 38 | /// Ignore case comparisons 39 | #define strcmpi strcasecmp 40 | 41 | #include 42 | #include 43 | #include 44 | 45 | #define SESE_FILENAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) 46 | 47 | namespace sese { 48 | /// Native Socket type 49 | using socket_t = int32_t; 50 | using tid_t = uint32_t; 51 | using pid_t = ::pid_t; 52 | } // namespace sese 53 | -------------------------------------------------------------------------------- /sese/internal/unix/security/evp/SHA1Context.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include 18 | 19 | sese::security::evp::SHA1Context::SHA1Context() noexcept : Context() { 20 | this->context = EVP_MD_CTX_new(); 21 | EVP_DigestInit((EVP_MD_CTX *) this->context, EVP_sha1()); 22 | } 23 | 24 | sese::security::evp::SHA1Context::~SHA1Context() noexcept { 25 | EVP_MD_CTX_free((EVP_MD_CTX *) this->context); 26 | } 27 | 28 | void sese::security::evp::SHA1Context::update(const void *buffer, size_t len) noexcept { 29 | EVP_DigestUpdate((EVP_MD_CTX *) this->context, buffer, len); 30 | } 31 | 32 | void sese::security::evp::SHA1Context::final() noexcept { 33 | EVP_DigestFinal((EVP_MD_CTX *) this->context, result, nullptr); 34 | } 35 | 36 | void *sese::security::evp::SHA1Context::getResult() noexcept { 37 | return result; 38 | } 39 | 40 | size_t sese::security::evp::SHA1Context::getLength() noexcept { 41 | return length; 42 | } -------------------------------------------------------------------------------- /sese/io/FixedBuffer.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /// \file FixedBuffer.h 16 | /// \brief Thread-safe fixed-size buffer 17 | /// \author kaoru 18 | /// \version 0.1.0 19 | /// \date June 11, 2023 20 | 21 | #pragma once 22 | 23 | #include "sese/io/AbstractFixedBuffer.h" 24 | 25 | #include 26 | 27 | namespace sese::io { 28 | 29 | /// Thread-safe fixed-size buffer 30 | class FixedBuffer final : public AbstractFixedBuffer { 31 | public: 32 | explicit FixedBuffer(size_t size) noexcept; 33 | 34 | int64_t read(void *buffer, size_t length) override; 35 | 36 | int64_t write(const void *buffer, size_t length) override; 37 | 38 | int64_t peek(void *buffer, size_t length) override; 39 | 40 | int64_t trunc(size_t length) override; 41 | 42 | void reset() noexcept override; 43 | 44 | size_t getReadableSize() noexcept; 45 | 46 | [[nodiscard]] size_t getWriteableSize() noexcept; 47 | 48 | private: 49 | std::mutex mutex; 50 | }; 51 | 52 | } // namespace sese::io -------------------------------------------------------------------------------- /sese/net/http/HttpServletContext.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #pragma once 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | namespace sese::net::http { 22 | 23 | class HttpServletContext { 24 | public: 25 | HttpServletContext(Request &req, Response &resp, const IPAddress::Ptr &remote_address) 26 | : req(req), resp(resp), remote_address(remote_address) { 27 | } 28 | 29 | [[nodiscard]] auto &getReq() const { return req; } 30 | [[nodiscard]] auto &getResp() const { return resp; } 31 | [[nodiscard]] auto getRemoteAddress() const { return remote_address; } 32 | [[nodiscard]] io::InputStream *getInputStream() const { return &req.getBody(); } 33 | [[nodiscard]] io::OutputStream *getOutputStream() const { return &resp.getBody(); } 34 | 35 | private: 36 | Request &req; 37 | Response &resp; 38 | const IPAddress::Ptr &remote_address; 39 | }; 40 | 41 | } // namespace sese::net::http -------------------------------------------------------------------------------- /sese/util/ErrorCode.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /// @file ErrorCode.h 16 | /// @brief Error code class 17 | /// @author: kaoru 18 | /// @date November 1, 2024 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | 25 | namespace sese { 26 | 27 | /// @brief Error code class 28 | class ErrorCode { 29 | int32_t error; 30 | std::string msg; 31 | 32 | public: 33 | /// @brief Constructor 34 | /// @param error Error code 35 | /// @param msg Error description 36 | ErrorCode(int32_t error, std::string msg) noexcept; 37 | 38 | /// @brief Get error code 39 | /// @return Error code 40 | [[nodiscard]] int32_t value() const noexcept { return error; } 41 | 42 | /// @brief Get error description 43 | /// @return Error description 44 | [[nodiscard]] const std::string &message() const noexcept { return msg; } 45 | 46 | explicit operator bool() const noexcept { 47 | return value() != 0; 48 | } 49 | }; 50 | } // namespace sese -------------------------------------------------------------------------------- /sese/test/TestNetworkUtil.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "sese/system/NetworkUtil.h" 16 | #include "gtest/gtest.h" 17 | 18 | TEST(TestNetworkUtil, Interface) { 19 | auto interfaces = sese::system::NetworkUtil::getNetworkInterface(); 20 | for (decltype(auto) inter: interfaces) { 21 | printf("Name: %s\n", inter.name.c_str()); 22 | printf("Mac: %02X-%02X-%02X-%02X-%02X-%02X\n", 23 | inter.mac[0], 24 | inter.mac[1], 25 | inter.mac[2], 26 | inter.mac[3], 27 | inter.mac[4], 28 | inter.mac[5] 29 | ); 30 | 31 | printf("IPv4 Address:\n"); 32 | for (decltype(auto) addr: inter.ipv4Addresses) { 33 | puts(addr->getAddress().c_str()); 34 | } 35 | 36 | printf("IPv6 Address:\n"); 37 | for (decltype(auto) addr: inter.ipv6Addresses) { 38 | puts(addr->getAddress().c_str()); 39 | } 40 | 41 | printf("\n"); 42 | } 43 | } -------------------------------------------------------------------------------- /sese/security/SSLContextBuilder.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include 18 | 19 | using namespace sese::security; 20 | 21 | SSLContext::Ptr SSLContextBuilder::SSL4Client() noexcept { 22 | // auto *method = SSLv23_client_method(); 23 | auto *method = TLS_client_method(); 24 | return std::make_shared(method); 25 | } 26 | 27 | SSLContext::Ptr SSLContextBuilder::SSL4Server() noexcept { 28 | // auto method = SSLv23_server_method(); 29 | auto method = TLS_server_method(); 30 | return std::make_shared(method); 31 | } 32 | 33 | std::unique_ptr SSLContextBuilder::UniqueSSL4Client() noexcept { 34 | auto *method = TLS_client_method(); 35 | return std::make_unique(method); 36 | } 37 | 38 | std::unique_ptr SSLContextBuilder::UniqueSSL4Server() noexcept { 39 | auto *method = TLS_server_method(); 40 | return std::make_unique(method); 41 | } 42 | -------------------------------------------------------------------------------- /sese/util/TimestampHandler.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /** 16 | * @file TimestampHandler.h 17 | * @brief Timestamp Handler 18 | * @author kaoru 19 | * @version 0.1 20 | * @date September 25, 2023 21 | */ 22 | 23 | #pragma once 24 | 25 | #include 26 | #include 27 | 28 | namespace sese { 29 | 30 | /// Timestamp Handler 31 | class TimestampHandler { 32 | public: 33 | explicit TimestampHandler(std::chrono::system_clock::time_point point) noexcept; 34 | /// Get the current timestamp 35 | /// \return Millisecond-level timestamp 36 | uint64_t getCurrentTimestamp() noexcept; 37 | /// Try to get the current timestamp 38 | /// \retval 0 System clock rollback, and rollback time is less than or equal to 5 seconds 39 | /// \retval UINT64_MAX System clock rollback, and rollback time is greater than 5 seconds 40 | uint64_t tryGetCurrentTimestamp() noexcept; 41 | 42 | protected: 43 | std::chrono::milliseconds latest{}; 44 | }; 45 | 46 | } // namespace sese 47 | -------------------------------------------------------------------------------- /sese/db/DriverManager.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /// \file DriverManager.h 16 | /// \author kaoru 17 | /// \brief Database driver instance manager 18 | /// \version 0.1 19 | 20 | #pragma once 21 | #include 22 | 23 | namespace sese::db { 24 | /// \brief Database type enumeration 25 | enum class DatabaseType { 26 | MY_SQL, 27 | MARIA, 28 | SQLITE, 29 | POSTGRES 30 | }; 31 | 32 | /// \brief Database driver instance manager 33 | class DriverManager { 34 | public: 35 | /// \brief Create a database driver instance 36 | /// \param type Database type 37 | /// \param conn_string Connection string 38 | /// \return Database driver instance 39 | /// \retval nullptr Failed to create a database driver instance, which is usually a non-recoverable error but occurs rarely 40 | static DriverInstance::Ptr getInstance(DatabaseType type, const char *conn_string) noexcept; 41 | }; 42 | }// namespace sese::db -------------------------------------------------------------------------------- /sese/internal/unix/security/evp/SHA256Context.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include 18 | 19 | sese::security::evp::SHA256Context::SHA256Context() noexcept : Context() { 20 | this->context = EVP_MD_CTX_new(); 21 | EVP_DigestInit((EVP_MD_CTX *) this->context, EVP_sha256()); 22 | } 23 | 24 | sese::security::evp::SHA256Context::~SHA256Context() noexcept { 25 | EVP_MD_CTX_free((EVP_MD_CTX *) this->context); 26 | } 27 | 28 | void sese::security::evp::SHA256Context::update(const void *buffer, size_t len) noexcept { 29 | EVP_DigestUpdate((EVP_MD_CTX *) this->context, buffer, len); 30 | } 31 | 32 | void sese::security::evp::SHA256Context::final() noexcept { 33 | EVP_DigestFinal((EVP_MD_CTX *) this->context, result, nullptr); 34 | } 35 | 36 | void *sese::security::evp::SHA256Context::getResult() noexcept { 37 | return result; 38 | } 39 | 40 | size_t sese::security::evp::SHA256Context::getLength() noexcept { 41 | return 32; 42 | } -------------------------------------------------------------------------------- /sese/internal/unix/security/evp/SHA384Context.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include 18 | 19 | sese::security::evp::SHA384Context::SHA384Context() noexcept : Context() { 20 | this->context = EVP_MD_CTX_new(); 21 | EVP_DigestInit((EVP_MD_CTX *) this->context, EVP_sha384()); 22 | } 23 | 24 | sese::security::evp::SHA384Context::~SHA384Context() noexcept { 25 | EVP_MD_CTX_free((EVP_MD_CTX *) this->context); 26 | } 27 | 28 | void sese::security::evp::SHA384Context::update(const void *buffer, size_t len) noexcept { 29 | EVP_DigestUpdate((EVP_MD_CTX *) this->context, buffer, len); 30 | } 31 | 32 | void sese::security::evp::SHA384Context::final() noexcept { 33 | EVP_DigestFinal((EVP_MD_CTX *) this->context, result, nullptr); 34 | } 35 | 36 | void *sese::security::evp::SHA384Context::getResult() noexcept { 37 | return result; 38 | } 39 | 40 | size_t sese::security::evp::SHA384Context::getLength() noexcept { 41 | return 48; 42 | } -------------------------------------------------------------------------------- /sese/internal/unix/security/evp/SHA512Context.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include 18 | 19 | sese::security::evp::SHA512Context::SHA512Context() noexcept : Context() { 20 | this->context = EVP_MD_CTX_new(); 21 | EVP_DigestInit((EVP_MD_CTX *) this->context, EVP_sha512()); 22 | } 23 | 24 | sese::security::evp::SHA512Context::~SHA512Context() noexcept { 25 | EVP_MD_CTX_free((EVP_MD_CTX *) this->context); 26 | } 27 | 28 | void sese::security::evp::SHA512Context::update(const void *buffer, size_t len) noexcept { 29 | EVP_DigestUpdate((EVP_MD_CTX *) this->context, buffer, len); 30 | } 31 | 32 | void sese::security::evp::SHA512Context::final() noexcept { 33 | EVP_DigestFinal((EVP_MD_CTX *) this->context, result, nullptr); 34 | } 35 | 36 | void *sese::security::evp::SHA512Context::getResult() noexcept { 37 | return result; 38 | } 39 | 40 | size_t sese::security::evp::SHA512Context::getLength() noexcept { 41 | return 64; 42 | } -------------------------------------------------------------------------------- /sese/security/evp/SM3Context.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2024 libsese 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include 18 | 19 | sese::security::evp::SM3Context::SM3Context() noexcept { 20 | this->context = EVP_MD_CTX_new(); 21 | EVP_DigestInit(static_cast(this->context), EVP_sm3()); 22 | } 23 | 24 | sese::security::evp::SM3Context::~SM3Context() noexcept { 25 | EVP_MD_CTX_free(static_cast(this->context)); 26 | } 27 | 28 | void sese::security::evp::SM3Context::update(const void *buffer, size_t len) noexcept { 29 | EVP_DigestUpdate(static_cast(this->context), buffer, len); 30 | } 31 | 32 | void sese::security::evp::SM3Context::final() noexcept { 33 | EVP_DigestFinal(static_cast(this->context), result, nullptr); 34 | } 35 | 36 | void *sese::security::evp::SM3Context::getResult() noexcept { 37 | return result; 38 | } 39 | 40 | size_t sese::security::evp::SM3Context::getLength() noexcept { 41 | return length; 42 | } 43 | --------------------------------------------------------------------------------