Skip to content

Commit 7e658cf

Browse files
authored
Styling, Certificates, and SSL_Utils (#2)
- Added clang-tidy config file + CI - Reformated the code to fit the new Style - Added SSL_Utils for better smart pointers of SSL objects - Added Certificate class + extras to manipulate Certificates
1 parent 64b4517 commit 7e658cf

19 files changed

+1110
-304
lines changed

.clang-tidy

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Checks: '
2+
*,
3+
-llvmlibc-*,
4+
-google-readability-todo,
5+
-fuchsia-default-arguments-calls,
6+
-fuchsia-default-arguments-declarations,
7+
-cppcoreguidelines-init-variables,
8+
-cppcoreguidelines-pro-type-reinterpret-cast,
9+
-android-*,
10+
-altera-*,
11+
-llvm-namespace-comment,
12+
-readability-implicit-bool-conversion,
13+
-google-explicit-constructor,
14+
-fuchsia-overloaded-operator,
15+
16+
-google-readability-braces-around-statements,
17+
-google-readability-namespace-comments,
18+
-hicpp-braces-around-statements,
19+
-hicpp-explicit-conversions,
20+
-fuchsia-trailing-return
21+
'
22+
23+
WarningsAsErrors: 'bugprone-exception-escape'
24+
FormatStyle: 'none' # TODO: Replace with 'file' once we have a proper .clang-format file
25+
InheritParentConfig: true
26+
CheckOptions:
27+
misc-include-cleaner.MissingIncludes: 'false'
28+
misc-include-cleaner.IgnoreHeaders: 'CppSockets/OSDetection\.hpp'
29+
30+
bugprone-argument-comment.StrictMode: 1
31+
32+
# Readability
33+
readability-braces-around-statements.ShortStatementLines: 2
34+
35+
readability-identifier-naming.NamespaceCase: CamelCase
36+
37+
readability-identifier-length.IgnoredVariableNames: "^(fd|nb|ss)$"
38+
readability-identifier-length.IgnoredParameterNames: "^([n]|fd)$"

.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
7+
[*.{c++,cc,cpp,cxx,h,h++,hh,hpp,hxx,inl,ipp,tlh,tli}]
8+
cpp_indent_case_contents_when_block = true
9+
cpp_new_line_before_open_brace_namespace = same_line
10+
indent_size = 4
11+
indent_style = space

.github/workflows/cmake-multi-platform.yml

Lines changed: 86 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,29 @@ on:
44
push:
55
branches: [ "master" ]
66
pull_request:
7+
branches: [ "master" ]
78
types: [ "opened", "reopened", "synchronize", "ready_for_review" ]
89

910
jobs:
1011
build:
1112
runs-on: ${{ matrix.os }}
1213

1314
strategy:
14-
fail-fast: false # ensure we don't stop after 1 failure to always have a complete picture of what is failing
15+
# ensure we don't stop after 1 failure to always have a complete picture of what is failing
16+
fail-fast: false
1517

1618
# Set up a matrix to run the following configurations:
1719
# - ubuntu Debug/Release clang/gcc
1820
# - windows Debug/Release cl
1921
# - macos Debug/Release clang
2022
matrix:
21-
os: [ubuntu-latest, macos-latest] # , windows-latest
23+
os: [ubuntu-latest, macos-latest, windows-latest]
2224
build_type: [Release, Debug]
2325
c_compiler: [gcc, clang, cl]
2426
include:
25-
# - os: windows-latest
26-
# c_compiler: cl
27-
# cpp_compiler: cl
27+
- os: windows-latest
28+
c_compiler: cl
29+
cpp_compiler: cl
2830
- os: ubuntu-latest
2931
c_compiler: gcc
3032
cpp_compiler: g++
@@ -47,47 +49,82 @@ jobs:
4749
c_compiler: gcc
4850

4951
steps:
50-
- uses: actions/checkout@v3
51-
52-
- name: Set reusable strings
53-
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
54-
id: strings
55-
shell: bash
56-
run: |
57-
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
58-
59-
- name: Cache VCPKG (Windows)
60-
if: runner.os == 'Windows'
61-
uses: actions/cache@v3
62-
with:
63-
path: ${{ env.VCPKG_ROOT }}
64-
key: ${{ runner.os }}-${{ matrix.build_type }}-${{ hashFiles('vcpkg.json') }}
65-
66-
- name: Install OpenSSL (Windows)
67-
if: runner.os == 'Windows'
68-
shell: powershell
69-
run: |
70-
echo "VCPKG_ROOT=$env:VCPKG_INSTALLATION_ROOT" | Out-File -FilePath $env:GITHUB_ENV -Append
71-
echo "CMAKE_TOOLCHAIN_FILE=${env:VCPKG_INSTALLATION_ROOT}\scripts\buildsystems\vcpkg.cmake" | Out-File -FilePath $env:GITHUB_ENV -Append
72-
vcpkg install
73-
74-
- name: Configure CMake
75-
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
76-
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
77-
run: >
78-
cmake -B ${{ steps.strings.outputs.build-output-dir }}
79-
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
80-
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
81-
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
82-
-DCPPSOCKETS_TESTS=TRUE
83-
-S ${{ github.workspace }}
84-
85-
- name: Build
86-
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
87-
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
88-
89-
- name: Test
90-
working-directory: ${{ steps.strings.outputs.build-output-dir }}
91-
# Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
92-
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
93-
run: ctest --build-config ${{ matrix.build_type }} --test-dir tests
52+
- uses: actions/checkout@v3
53+
54+
- name: Set Env
55+
shell: bash
56+
run: |
57+
echo "VCPKG_ROOT=${VCPKG_INSTALLATION_ROOT}" >> "$GITHUB_ENV"
58+
echo "BUILD_OUTPUT_DIR=${{ github.workspace }}/build" >> "$GITHUB_ENV"
59+
60+
- name: Fetch VCPKG Cache (Windows)
61+
id: fetch-vcpkg-cache
62+
if: runner.os == 'Windows'
63+
uses: actions/cache/restore@v4
64+
with:
65+
key: ${{ runner.os }}-${{ matrix.build_type }}-${{ hashFiles('vcpkg.json') }}
66+
path: ${{ env.VCPKG_ROOT }}
67+
68+
- name: Install OpenSSL (Windows)
69+
if: runner.os == 'Windows'
70+
shell: powershell
71+
run: |
72+
echo "CMAKE_TOOLCHAIN_FILE=${env:VCPKG_ROOT}\scripts\buildsystems\vcpkg.cmake" | Out-File -FilePath $env:GITHUB_ENV -Append
73+
vcpkg install
74+
75+
- name: Always Save VCPKG Cache (Windows)
76+
if: always() && runner.os == 'Windows' && steps.fetch-vcpkg-cache.outputs.cache-hit != 'true'
77+
uses: actions/cache/save@v4
78+
with:
79+
key: ${{ steps.fetch-vcpkg-cache.outputs.cache-primary-key }}
80+
path: ${{ env.VCPKG_ROOT }}
81+
82+
- name: Configure CMake
83+
# Configure CMake in a 'build' subdirectory.
84+
# `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
85+
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
86+
run: >
87+
cmake -B ${{ env.BUILD_OUTPUT_DIR }}
88+
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
89+
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
90+
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
91+
-DCPPSOCKETS_TESTS=TRUE
92+
-S ${{ github.workspace }}
93+
94+
- name: Build
95+
# Build your program with the given configuration. Note that --config is needed
96+
# because the default Windows generator is a multi-config generator (Visual Studio generator).
97+
run: cmake --build ${{ env.BUILD_OUTPUT_DIR }} --config ${{ matrix.build_type }}
98+
99+
- uses: actions/upload-artifact@v4
100+
if: matrix.os == 'ubuntu-latest' && matrix.build_type == 'Release' && matrix.c_compiler == 'clang'
101+
with:
102+
name: compile_commands.json
103+
path: ${{ env.BUILD_OUTPUT_DIR }}/compile_commands.json
104+
105+
- name: Test
106+
working-directory: ${{ env.BUILD_OUTPUT_DIR }}
107+
# Execute tests defined by the CMake configuration. Note that --build-config is needed
108+
# because the default Windows generator is a multi-config generator (Visual Studio generator).
109+
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
110+
run: ctest --build-config ${{ matrix.build_type }} --test-dir tests --output-on-failure
111+
112+
clang-tidy:
113+
needs: 'build'
114+
runs-on: ubuntu-latest
115+
if: always()
116+
117+
steps:
118+
- name: Checkout Code
119+
uses: actions/checkout@v4
120+
121+
- uses: actions/download-artifact@v4
122+
with:
123+
name: compile_commands.json
124+
125+
- name: clang-tidy review
126+
uses: ZedThree/[email protected]
127+
128+
# If there are any comments, fail the check
129+
- if: steps.review.outputs.total_comments > 0
130+
run: exit 1

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
build/
22

3+
libcppsockets.so
34
compile_commands.json
45

56
*.tmp
67
*.gch
8+
vgcore.*
9+
10+
.vscode/
11+
.cache/

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
## Author Francois Michaut
55
##
66
## Started on Sun Aug 28 19:26:51 2022 Francois Michaut
7-
## Last update Sat Dec 2 17:45:28 2023 Francois Michaut
7+
## Last update Mon Aug 4 23:34:08 2025 Francois Michaut
88
##
99
## CMakeLists.txt : CMake to build the CppSockets library
1010
##
@@ -22,7 +22,9 @@ configure_file(include/CppSockets/Version.hpp.in include/CppSockets/Version.hpp)
2222

2323
add_library(cppsockets
2424
source/Address.cpp
25+
source/Certificate.cpp
2526
source/IPv4.cpp
27+
source/SSL_Utils.cpp
2628
source/Socket.cpp
2729
source/SocketInit.cpp
2830
source/TlsSocket.cpp

include/CppSockets/Address.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@
2020
namespace CppSockets {
2121
class IAddress {
2222
public:
23-
[[nodiscard]] virtual std::uint32_t getAddress() const = 0;
24-
[[nodiscard]] virtual int getFamily() const = 0;
25-
[[nodiscard]] virtual const std::string &toString() const = 0;
23+
[[nodiscard]] virtual auto getAddress() const -> std::uint32_t = 0;
24+
[[nodiscard]] virtual auto getFamily() const -> int = 0;
25+
[[nodiscard]] virtual auto toString() const -> const std::string & = 0;
2626
};
2727

2828
class IEndpoint {
2929
public:
30-
[[nodiscard]] virtual std::uint16_t getPort() const = 0;
31-
[[nodiscard]] virtual const IAddress &getAddr() const = 0;
32-
[[nodiscard]] virtual const std::string &toString() const = 0;
30+
[[nodiscard]] virtual auto getPort() const -> std::uint16_t = 0;
31+
[[nodiscard]] virtual auto getAddr() const -> const IAddress & = 0;
32+
[[nodiscard]] virtual auto toString() const -> const std::string & = 0;
3333

3434
protected:
35-
[[nodiscard]] std::string makeString() const;
35+
[[nodiscard]] auto makeString() const -> std::string;
3636
};
3737

3838
template <class T>
@@ -46,15 +46,15 @@ namespace CppSockets {
4646
{};
4747
virtual ~Endpoint() = default;
4848

49-
[[nodiscard]] std::uint16_t getPort() const override {
49+
[[nodiscard]] auto getPort() const -> std::uint16_t override {
5050
return port;
5151
}
5252

53-
[[nodiscard]] const T &getAddr() const override {
53+
[[nodiscard]] auto getAddr() const -> const T & override {
5454
return addr;
5555
}
5656

57-
[[nodiscard]] const std::string &toString() const override {
57+
[[nodiscard]] auto toString() const -> const std::string & override {
5858
return str;
5959
}
6060
private:

0 commit comments

Comments
 (0)