basic structure
This commit is contained in:
commit
20f71fcf0d
226
.clang-format
Normal file
226
.clang-format
Normal file
|
@ -0,0 +1,226 @@
|
||||||
|
---
|
||||||
|
Language: Cpp
|
||||||
|
# BasedOnStyle: Google
|
||||||
|
AccessModifierOffset: -1
|
||||||
|
AlignAfterOpenBracket: Align
|
||||||
|
AlignArrayOfStructures: None
|
||||||
|
AlignConsecutiveMacros: None
|
||||||
|
AlignConsecutiveAssignments: None
|
||||||
|
AlignConsecutiveBitFields: None
|
||||||
|
AlignConsecutiveDeclarations: None
|
||||||
|
AlignEscapedNewlines: Left
|
||||||
|
AlignOperands: Align
|
||||||
|
AlignTrailingComments: true
|
||||||
|
AllowAllArgumentsOnNextLine: true
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: true
|
||||||
|
AllowShortEnumsOnASingleLine: false
|
||||||
|
AllowShortBlocksOnASingleLine: Never
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortFunctionsOnASingleLine: Empty
|
||||||
|
AllowShortLambdasOnASingleLine: All
|
||||||
|
AllowShortIfStatementsOnASingleLine: Never
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
|
AlwaysBreakAfterDefinitionReturnType: None
|
||||||
|
AlwaysBreakAfterReturnType: None
|
||||||
|
AlwaysBreakBeforeMultilineStrings: true
|
||||||
|
AlwaysBreakTemplateDeclarations: Yes
|
||||||
|
AttributeMacros:
|
||||||
|
- __capability
|
||||||
|
BinPackArguments: true
|
||||||
|
BinPackParameters: true
|
||||||
|
BraceWrapping:
|
||||||
|
AfterCaseLabel: false
|
||||||
|
AfterClass: false
|
||||||
|
AfterControlStatement: Never
|
||||||
|
AfterEnum: false
|
||||||
|
AfterFunction: false
|
||||||
|
AfterNamespace: false
|
||||||
|
AfterObjCDeclaration: false
|
||||||
|
AfterStruct: false
|
||||||
|
AfterUnion: false
|
||||||
|
AfterExternBlock: false
|
||||||
|
BeforeCatch: false
|
||||||
|
BeforeElse: false
|
||||||
|
BeforeLambdaBody: false
|
||||||
|
BeforeWhile: false
|
||||||
|
IndentBraces: false
|
||||||
|
SplitEmptyFunction: true
|
||||||
|
SplitEmptyRecord: true
|
||||||
|
SplitEmptyNamespace: true
|
||||||
|
BreakBeforeBinaryOperators: None
|
||||||
|
BreakBeforeConceptDeclarations: true
|
||||||
|
BreakBeforeBraces: Attach
|
||||||
|
BreakBeforeInheritanceComma: false
|
||||||
|
BreakInheritanceList: BeforeColon
|
||||||
|
BreakBeforeTernaryOperators: true
|
||||||
|
BreakConstructorInitializersBeforeComma: false
|
||||||
|
BreakConstructorInitializers: BeforeColon
|
||||||
|
BreakAfterJavaFieldAnnotations: false
|
||||||
|
BreakStringLiterals: true
|
||||||
|
ColumnLimit: 80
|
||||||
|
CommentPragmas: '^ IWYU pragma:'
|
||||||
|
QualifierAlignment: Leave
|
||||||
|
CompactNamespaces: false
|
||||||
|
ConstructorInitializerIndentWidth: 4
|
||||||
|
ContinuationIndentWidth: 4
|
||||||
|
Cpp11BracedListStyle: true
|
||||||
|
DeriveLineEnding: true
|
||||||
|
DerivePointerAlignment: true
|
||||||
|
DisableFormat: false
|
||||||
|
EmptyLineAfterAccessModifier: Never
|
||||||
|
EmptyLineBeforeAccessModifier: LogicalBlock
|
||||||
|
ExperimentalAutoDetectBinPacking: false
|
||||||
|
PackConstructorInitializers: NextLine
|
||||||
|
BasedOnStyle: ''
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||||
|
AllowAllConstructorInitializersOnNextLine: true
|
||||||
|
FixNamespaceComments: true
|
||||||
|
ForEachMacros:
|
||||||
|
- foreach
|
||||||
|
- Q_FOREACH
|
||||||
|
- BOOST_FOREACH
|
||||||
|
IfMacros:
|
||||||
|
- KJ_IF_MAYBE
|
||||||
|
IncludeBlocks: Regroup
|
||||||
|
IncludeCategories:
|
||||||
|
- Regex: '^<ext/.*\.h>'
|
||||||
|
Priority: 2
|
||||||
|
SortPriority: 0
|
||||||
|
CaseSensitive: false
|
||||||
|
- Regex: '^<.*\.h>'
|
||||||
|
Priority: 1
|
||||||
|
SortPriority: 0
|
||||||
|
CaseSensitive: false
|
||||||
|
- Regex: '^<.*'
|
||||||
|
Priority: 2
|
||||||
|
SortPriority: 0
|
||||||
|
CaseSensitive: false
|
||||||
|
- Regex: '.*'
|
||||||
|
Priority: 3
|
||||||
|
SortPriority: 0
|
||||||
|
CaseSensitive: false
|
||||||
|
IncludeIsMainRegex: '([-_](test|unittest))?$'
|
||||||
|
IncludeIsMainSourceRegex: ''
|
||||||
|
IndentAccessModifiers: false
|
||||||
|
IndentCaseLabels: true
|
||||||
|
IndentCaseBlocks: false
|
||||||
|
IndentGotoLabels: true
|
||||||
|
IndentPPDirectives: None
|
||||||
|
IndentExternBlock: AfterExternBlock
|
||||||
|
IndentRequires: false
|
||||||
|
IndentWidth: 2
|
||||||
|
IndentWrappedFunctionNames: false
|
||||||
|
InsertTrailingCommas: None
|
||||||
|
JavaScriptQuotes: Leave
|
||||||
|
JavaScriptWrapImports: true
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||||
|
LambdaBodyIndentation: Signature
|
||||||
|
MacroBlockBegin: ''
|
||||||
|
MacroBlockEnd: ''
|
||||||
|
MaxEmptyLinesToKeep: 1
|
||||||
|
NamespaceIndentation: None
|
||||||
|
ObjCBinPackProtocolList: Never
|
||||||
|
ObjCBlockIndentWidth: 2
|
||||||
|
ObjCBreakBeforeNestedBlockParam: true
|
||||||
|
ObjCSpaceAfterProperty: false
|
||||||
|
ObjCSpaceBeforeProtocolList: true
|
||||||
|
PenaltyBreakAssignment: 2
|
||||||
|
PenaltyBreakBeforeFirstCallParameter: 1
|
||||||
|
PenaltyBreakComment: 300
|
||||||
|
PenaltyBreakFirstLessLess: 120
|
||||||
|
PenaltyBreakOpenParenthesis: 0
|
||||||
|
PenaltyBreakString: 1000
|
||||||
|
PenaltyBreakTemplateDeclaration: 10
|
||||||
|
PenaltyExcessCharacter: 1000000
|
||||||
|
PenaltyReturnTypeOnItsOwnLine: 200
|
||||||
|
PenaltyIndentedWhitespace: 0
|
||||||
|
PointerAlignment: Left
|
||||||
|
PPIndentWidth: -1
|
||||||
|
RawStringFormats:
|
||||||
|
- Language: Cpp
|
||||||
|
Delimiters:
|
||||||
|
- cc
|
||||||
|
- CC
|
||||||
|
- cpp
|
||||||
|
- Cpp
|
||||||
|
- CPP
|
||||||
|
- 'c++'
|
||||||
|
- 'C++'
|
||||||
|
CanonicalDelimiter: ''
|
||||||
|
BasedOnStyle: google
|
||||||
|
- Language: TextProto
|
||||||
|
Delimiters:
|
||||||
|
- pb
|
||||||
|
- PB
|
||||||
|
- proto
|
||||||
|
- PROTO
|
||||||
|
EnclosingFunctions:
|
||||||
|
- EqualsProto
|
||||||
|
- EquivToProto
|
||||||
|
- PARSE_PARTIAL_TEXT_PROTO
|
||||||
|
- PARSE_TEST_PROTO
|
||||||
|
- PARSE_TEXT_PROTO
|
||||||
|
- ParseTextOrDie
|
||||||
|
- ParseTextProtoOrDie
|
||||||
|
- ParseTestProto
|
||||||
|
- ParsePartialTestProto
|
||||||
|
CanonicalDelimiter: pb
|
||||||
|
BasedOnStyle: google
|
||||||
|
ReferenceAlignment: Pointer
|
||||||
|
ReflowComments: true
|
||||||
|
RemoveBracesLLVM: false
|
||||||
|
SeparateDefinitionBlocks: Leave
|
||||||
|
ShortNamespaceLines: 1
|
||||||
|
SortIncludes: CaseSensitive
|
||||||
|
SortJavaStaticImport: Before
|
||||||
|
SortUsingDeclarations: true
|
||||||
|
SpaceAfterCStyleCast: false
|
||||||
|
SpaceAfterLogicalNot: false
|
||||||
|
SpaceAfterTemplateKeyword: true
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
SpaceBeforeCaseColon: false
|
||||||
|
SpaceBeforeCpp11BracedList: false
|
||||||
|
SpaceBeforeCtorInitializerColon: true
|
||||||
|
SpaceBeforeInheritanceColon: true
|
||||||
|
SpaceBeforeParens: ControlStatements
|
||||||
|
SpaceBeforeParensOptions:
|
||||||
|
AfterControlStatements: true
|
||||||
|
AfterForeachMacros: true
|
||||||
|
AfterFunctionDefinitionName: false
|
||||||
|
AfterFunctionDeclarationName: false
|
||||||
|
AfterIfMacros: true
|
||||||
|
AfterOverloadedOperator: false
|
||||||
|
BeforeNonEmptyParentheses: false
|
||||||
|
SpaceAroundPointerQualifiers: Default
|
||||||
|
SpaceBeforeRangeBasedForLoopColon: true
|
||||||
|
SpaceInEmptyBlock: false
|
||||||
|
SpaceInEmptyParentheses: false
|
||||||
|
SpacesBeforeTrailingComments: 2
|
||||||
|
SpacesInAngles: Never
|
||||||
|
SpacesInConditionalStatement: false
|
||||||
|
SpacesInContainerLiterals: true
|
||||||
|
SpacesInCStyleCastParentheses: false
|
||||||
|
SpacesInLineCommentPrefix:
|
||||||
|
Minimum: 1
|
||||||
|
Maximum: -1
|
||||||
|
SpacesInParentheses: false
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
SpaceBeforeSquareBrackets: false
|
||||||
|
BitFieldColonSpacing: Both
|
||||||
|
Standard: Auto
|
||||||
|
StatementAttributeLikeMacros:
|
||||||
|
- Q_EMIT
|
||||||
|
StatementMacros:
|
||||||
|
- Q_UNUSED
|
||||||
|
- QT_REQUIRE_VERSION
|
||||||
|
TabWidth: 8
|
||||||
|
UseCRLF: false
|
||||||
|
UseTab: Never
|
||||||
|
WhitespaceSensitiveMacros:
|
||||||
|
- STRINGIZE
|
||||||
|
- PP_STRINGIZE
|
||||||
|
- BOOST_PP_STRINGIZE
|
||||||
|
- NS_SWIFT_NAME
|
||||||
|
- CF_SWIFT_NAME
|
||||||
|
...
|
||||||
|
|
8
.editorconfig
Normal file
8
.editorconfig
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
max_line_length = 80
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/Build/
|
11
CMakeLists.txt
Normal file
11
CMakeLists.txt
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
cmake_minimum_required(VERSION 3.20)
|
||||||
|
project(matrix LANGUAGES C)
|
||||||
|
|
||||||
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
|
||||||
|
find_package(libev REQUIRED)
|
||||||
|
find_package(libtls REQUIRED)
|
||||||
|
|
||||||
|
include(AddAutoformatTarget)
|
||||||
|
include(Makeheaders)
|
||||||
|
|
||||||
|
add_subdirectory(src)
|
13
LICENSE
Normal file
13
LICENSE
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
Copyright (c) 2022 Thomas Lindner <tom@dl6tom.de>
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and distribute this software for any
|
||||||
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
copyright notice and this permission notice appear in all copies.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
2
build.sh
Executable file
2
build.sh
Executable file
|
@ -0,0 +1,2 @@
|
||||||
|
[ -f Build/build.ninja ] || cmake -G Ninja -B Build
|
||||||
|
exec ninja -C Build "$@"
|
23
cmake/AddAutoformatTarget.cmake
Normal file
23
cmake/AddAutoformatTarget.cmake
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
find_program(_CLANG_FORMAT clang-format)
|
||||||
|
|
||||||
|
if(_CLANG_FORMAT)
|
||||||
|
add_executable(clang-format IMPORTED)
|
||||||
|
set_target_properties(clang-format PROPERTIES
|
||||||
|
IMPORTED_LOCATION ${_CLANG_FORMAT})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
unset(_CLANG_FORMAT)
|
||||||
|
|
||||||
|
function(add_autoformat_target target)
|
||||||
|
get_target_property(source_dir ${target} SOURCE_DIR)
|
||||||
|
get_target_property(sources ${target} SOURCES)
|
||||||
|
add_custom_target(autoformat_${target}
|
||||||
|
COMMAND clang-format -i -- ${sources}
|
||||||
|
WORKING_DIRECTORY ${source_dir}
|
||||||
|
COMMENT "Autoformating sources of target ${target}"
|
||||||
|
VERBATIM)
|
||||||
|
if(NOT TARGET autoformat)
|
||||||
|
add_custom_target(autoformat)
|
||||||
|
endif()
|
||||||
|
add_dependencies(autoformat autoformat_${target})
|
||||||
|
endfunction()
|
20
cmake/Findlibev.cmake
Normal file
20
cmake/Findlibev.cmake
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
find_path(libev_INCLUDE_DIR ev.h)
|
||||||
|
mark_as_advanced(libev_INCLUDE_DIR)
|
||||||
|
|
||||||
|
find_library(libev_LIBRARY ev)
|
||||||
|
mark_as_advanced(libev_LIBRARY)
|
||||||
|
|
||||||
|
include(FindPackageHandleStandardArgs)
|
||||||
|
find_package_handle_standard_args(
|
||||||
|
libev DEFAULT_MSG libev_LIBRARY libev_INCLUDE_DIR)
|
||||||
|
|
||||||
|
if(libev_FOUND AND NOT TARGET libev::ev)
|
||||||
|
add_library(libev::ev SHARED IMPORTED)
|
||||||
|
set_target_properties(libev::ev PROPERTIES
|
||||||
|
IMPORTED_LOCATION ${libev_LIBRARY}
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES ${libev_INCLUDE_DIR})
|
||||||
|
# target_compile_definitions(libev::ev
|
||||||
|
# INTERFACE
|
||||||
|
# EV_COMPAT3=0
|
||||||
|
# EV_MULTIPLICITY=1)
|
||||||
|
endif()
|
16
cmake/Findlibtls.cmake
Normal file
16
cmake/Findlibtls.cmake
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
find_path(libtls_INCLUDE_DIR tls.h)
|
||||||
|
mark_as_advanced(libtls_INCLUDE_DIR)
|
||||||
|
|
||||||
|
find_library(libtls_LIBRARY tls)
|
||||||
|
mark_as_advanced(libtls_LIBRARY)
|
||||||
|
|
||||||
|
include(FindPackageHandleStandardArgs)
|
||||||
|
find_package_handle_standard_args(
|
||||||
|
libtls DEFAULT_MSG libtls_LIBRARY libtls_INCLUDE_DIR)
|
||||||
|
|
||||||
|
if(libtls_FOUND AND NOT TARGET libtls::tls)
|
||||||
|
add_library(libtls::tls SHARED IMPORTED)
|
||||||
|
set_target_properties(libtls::tls PROPERTIES
|
||||||
|
IMPORTED_LOCATION ${libtls_LIBRARY}
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES ${libtls_INCLUDE_DIR})
|
||||||
|
endif()
|
36
cmake/Makeheaders.cmake
Normal file
36
cmake/Makeheaders.cmake
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
find_program(_MAKEHEADERS makeheaders)
|
||||||
|
|
||||||
|
if(_MAKEHEADERS)
|
||||||
|
add_executable(makeheaders IMPORTED)
|
||||||
|
set_target_properties(makeheaders PROPERTIES
|
||||||
|
IMPORTED_LOCATION ${_MAKEHEADERS})
|
||||||
|
else()
|
||||||
|
add_executable(makeheaders ${CMAKE_CURRENT_LIST_DIR}/makeheaders.c)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
unset(_MAKEHEADERS)
|
||||||
|
|
||||||
|
function(target_makeheaders target)
|
||||||
|
get_target_property(binary_dir ${target} BINARY_DIR)
|
||||||
|
get_target_property(source_dir ${target} SOURCE_DIR)
|
||||||
|
get_target_property(sources ${target} SOURCES)
|
||||||
|
foreach(source ${sources})
|
||||||
|
cmake_path(REPLACE_EXTENSION source h OUTPUT_VARIABLE header)
|
||||||
|
cmake_path(ABSOLUTE_PATH source
|
||||||
|
BASE_DIRECTORY ${source_dir}
|
||||||
|
NORMALIZE)
|
||||||
|
list(APPEND makeheader_args ${source}:${header})
|
||||||
|
cmake_path(ABSOLUTE_PATH header
|
||||||
|
BASE_DIRECTORY ${binary_dir}
|
||||||
|
NORMALIZE)
|
||||||
|
list(APPEND generated_headers ${header})
|
||||||
|
endforeach()
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT ${generated_headers}
|
||||||
|
COMMAND makeheaders -local -- ${makeheader_args}
|
||||||
|
DEPENDS ${sources}
|
||||||
|
COMMENT "Generating headers for target ${target}"
|
||||||
|
VERBATIM)
|
||||||
|
target_sources(${target} PRIVATE ${generated_headers})
|
||||||
|
target_include_directories(${target} PRIVATE ${binary_dir})
|
||||||
|
endfunction()
|
3422
cmake/makeheaders.c
Normal file
3422
cmake/makeheaders.c
Normal file
File diff suppressed because it is too large
Load diff
11
src/CMakeLists.txt
Normal file
11
src/CMakeLists.txt
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
add_executable(${PROJECT_NAME}
|
||||||
|
main.c
|
||||||
|
network.c
|
||||||
|
)
|
||||||
|
target_link_libraries(${PROJECT_NAME}
|
||||||
|
libev::ev
|
||||||
|
libtls::tls
|
||||||
|
)
|
||||||
|
target_makeheaders(${PROJECT_NAME})
|
||||||
|
|
||||||
|
add_autoformat_target(${PROJECT_NAME})
|
15
src/main.c
Normal file
15
src/main.c
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#include <ev.h>
|
||||||
|
#include <main.h>
|
||||||
|
#include <tls.h>
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
struct tls_config *config;
|
||||||
|
Connection connection;
|
||||||
|
|
||||||
|
tls_init();
|
||||||
|
config = tls_config_new();
|
||||||
|
connection_init(EV_DEFAULT_ & connection, config);
|
||||||
|
ev_run(EV_DEFAULT_UC_ 0);
|
||||||
|
tls_config_free(config);
|
||||||
|
return 0;
|
||||||
|
}
|
26
src/network.c
Normal file
26
src/network.c
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#include <network.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#if INTERFACE
|
||||||
|
|
||||||
|
#include <ev.h>
|
||||||
|
#include <tls.h>
|
||||||
|
|
||||||
|
struct Connection {
|
||||||
|
ev_io watcher;
|
||||||
|
struct tls *ctx;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void connection_init(EV_P_ Connection *connection, struct tls_config *config) {
|
||||||
|
ev_io_init(&connection->watcher, connection_cb, STDIN_FILENO, EV_READ);
|
||||||
|
ev_io_start(EV_A_ & connection->watcher);
|
||||||
|
connection->ctx = tls_client();
|
||||||
|
tls_configure(connection->ctx, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void connection_cb(EV_P_ ev_io *w, int revents) {
|
||||||
|
ev_io_stop(EV_A_ w);
|
||||||
|
ev_break(EV_A_ EVBREAK_ALL);
|
||||||
|
}
|
Loading…
Reference in a new issue