Compare commits
26 Commits
4efd654941
...
developmen
| Author | SHA1 | Date | |
|---|---|---|---|
| 25d67053cc | |||
| 4aef8c0c1a | |||
| 9288859af5 | |||
| 535057c4db | |||
| ccfa5eeeb3 | |||
| 5a0e53cd52 | |||
| 78d4b7a63e | |||
| 6700a1c91e | |||
| eb43691a52 | |||
| 8413c67ec6 | |||
| 266ef5f830 | |||
| 86b062771a | |||
| c55f0c0f4f | |||
| e2c7a5f5bd | |||
| 4cdfbc9542 | |||
| 3807bc5f36 | |||
| 38bb29ecc0 | |||
| c5cf13e1b7 | |||
| 5435280209 | |||
| 65d87a1759 | |||
| 3889c746fe | |||
| 9dae77a0b9 | |||
| 61275c0f5f | |||
| adf11bd144 | |||
| f53bacb18b | |||
| 94eb56aad6 |
321
.clang-format
Normal file
321
.clang-format
Normal file
@@ -0,0 +1,321 @@
|
||||
---
|
||||
Language: Cpp
|
||||
AlignAfterOpenBracket: true
|
||||
AccessModifierOffset: -2
|
||||
AlignArrayOfStructures: None
|
||||
AlignConsecutiveAssignments:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionDeclarations: false
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: true
|
||||
AlignConsecutiveBitFields:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionDeclarations: false
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveDeclarations:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionDeclarations: true
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveMacros:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionDeclarations: false
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveShortCaseStatements:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCaseArrows: false
|
||||
AlignCaseColons: false
|
||||
AlignConsecutiveTableGenBreakingDAGArgColons:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionDeclarations: false
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveTableGenCondOperatorColons:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionDeclarations: false
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: false
|
||||
AlignConsecutiveTableGenDefinitionColons:
|
||||
Enabled: false
|
||||
AcrossEmptyLines: false
|
||||
AcrossComments: false
|
||||
AlignCompound: false
|
||||
AlignFunctionDeclarations: false
|
||||
AlignFunctionPointers: false
|
||||
PadOperators: false
|
||||
AlignEscapedNewlines: Right
|
||||
AlignOperands: Align
|
||||
AlignTrailingComments:
|
||||
AlignPPAndNotPP: true
|
||||
Kind: Always
|
||||
OverEmptyLines: 0
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowBreakBeforeNoexceptSpecifier: Never
|
||||
AllowBreakBeforeQtProperty: false
|
||||
AllowShortBlocksOnASingleLine: Never
|
||||
AllowShortCaseExpressionOnASingleLine: true
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortCompoundRequirementOnASingleLine: true
|
||||
AllowShortEnumsOnASingleLine: true
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLambdasOnASingleLine: All
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AllowShortNamespacesOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AttributeMacros:
|
||||
- __capability
|
||||
BinPackArguments: true
|
||||
BinPackLongBracedList: true
|
||||
BinPackParameters: BinPack
|
||||
BitFieldColonSpacing: Both
|
||||
BracedInitializerIndentWidth: -1
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: false
|
||||
AfterControlStatement: Never
|
||||
AfterEnum: false
|
||||
AfterExternBlock: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
BeforeLambdaBody: false
|
||||
BeforeWhile: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakAdjacentStringLiterals: true
|
||||
BreakAfterAttributes: Leave
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakAfterOpenBracketBracedList: false
|
||||
BreakAfterOpenBracketFunction: false
|
||||
BreakAfterOpenBracketIf: false
|
||||
BreakAfterOpenBracketLoop: false
|
||||
BreakAfterOpenBracketSwitch: false
|
||||
BreakAfterReturnType: None
|
||||
BreakArrays: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeCloseBracketBracedList: false
|
||||
BreakBeforeCloseBracketFunction: false
|
||||
BreakBeforeCloseBracketIf: false
|
||||
BreakBeforeCloseBracketLoop: false
|
||||
BreakBeforeCloseBracketSwitch: false
|
||||
BreakBeforeConceptDeclarations: Always
|
||||
BreakBeforeBraces: Attach
|
||||
BreakBeforeInlineASMColon: OnlyMultiline
|
||||
BreakBeforeTemplateCloser: false
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakBinaryOperations: Never
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakFunctionDefinitionParameters: false
|
||||
BreakInheritanceList: BeforeColon
|
||||
BreakStringLiterals: true
|
||||
BreakTemplateDeclarations: MultiLine
|
||||
ColumnLimit: 80
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: AlignFirstComment
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
EmptyLineAfterAccessModifier: Never
|
||||
EmptyLineBeforeAccessModifier: LogicalBlock
|
||||
EnumTrailingComma: Leave
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
IfMacros:
|
||||
- KJ_IF_MAYBE
|
||||
IncludeBlocks: Preserve
|
||||
IncludeCategories:
|
||||
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||
Priority: 2
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||
Priority: 3
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
- Regex: '.*'
|
||||
Priority: 1
|
||||
SortPriority: 0
|
||||
CaseSensitive: false
|
||||
IncludeIsMainRegex: '(Test)?$'
|
||||
IncludeIsMainSourceRegex: ''
|
||||
IndentAccessModifiers: false
|
||||
IndentCaseBlocks: false
|
||||
IndentCaseLabels: false
|
||||
IndentExportBlock: true
|
||||
IndentExternBlock: AfterExternBlock
|
||||
IndentGotoLabels: true
|
||||
IndentPPDirectives: None
|
||||
IndentRequiresClause: true
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: false
|
||||
InsertBraces: false
|
||||
InsertNewlineAtEOF: false
|
||||
InsertTrailingCommas: None
|
||||
IntegerLiteralSeparator:
|
||||
Binary: 0
|
||||
BinaryMinDigitsInsert: 0
|
||||
BinaryMaxDigitsRemove: 0
|
||||
Decimal: 0
|
||||
DecimalMinDigitsInsert: 0
|
||||
DecimalMaxDigitsRemove: 0
|
||||
Hex: 0
|
||||
HexMinDigitsInsert: 0
|
||||
HexMaxDigitsRemove: 0
|
||||
BinaryMinDigits: 0
|
||||
DecimalMinDigits: 0
|
||||
HexMinDigits: 0
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLines:
|
||||
AtEndOfFile: false
|
||||
AtStartOfBlock: true
|
||||
AtStartOfFile: true
|
||||
KeepFormFeed: false
|
||||
LambdaBodyIndentation: Signature
|
||||
LineEnding: DeriveLF
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MainIncludeChar: Quote
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
NumericLiteralCase:
|
||||
ExponentLetter: Leave
|
||||
HexDigit: Leave
|
||||
Prefix: Leave
|
||||
Suffix: Leave
|
||||
ObjCBinPackProtocolList: Auto
|
||||
ObjCBlockIndentWidth: 2
|
||||
ObjCBreakBeforeNestedBlockParam: true
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
OneLineFormatOffRegex: ''
|
||||
PackConstructorInitializers: BinPack
|
||||
PenaltyBreakAssignment: 2
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakBeforeMemberAccess: 150
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakOpenParenthesis: 0
|
||||
PenaltyBreakScopeResolution: 500
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyIndentedWhitespace: 0
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PointerAlignment: Right
|
||||
PPIndentWidth: -1
|
||||
QualifierAlignment: Leave
|
||||
ReferenceAlignment: Pointer
|
||||
ReflowComments: Always
|
||||
RemoveBracesLLVM: false
|
||||
RemoveEmptyLinesInUnwrappedLines: false
|
||||
RemoveParentheses: Leave
|
||||
RemoveSemicolon: false
|
||||
RequiresClausePosition: OwnLine
|
||||
RequiresExpressionIndentation: OuterScope
|
||||
SeparateDefinitionBlocks: Leave
|
||||
ShortNamespaceLines: 1
|
||||
SkipMacroDefinitionBody: false
|
||||
SortIncludes:
|
||||
Enabled: true
|
||||
IgnoreCase: false
|
||||
IgnoreExtension: false
|
||||
SortJavaStaticImport: Before
|
||||
SortUsingDeclarations: LexicographicNumeric
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterOperatorKeyword: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceAroundPointerQualifiers: Default
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCaseColon: false
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeJsonColon: false
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeParensOptions:
|
||||
AfterControlStatements: true
|
||||
AfterForeachMacros: true
|
||||
AfterFunctionDefinitionName: false
|
||||
AfterFunctionDeclarationName: false
|
||||
AfterIfMacros: true
|
||||
AfterNot: false
|
||||
AfterOverloadedOperator: false
|
||||
AfterPlacementOperator: true
|
||||
AfterRequiresInClause: false
|
||||
AfterRequiresInExpression: false
|
||||
BeforeNonEmptyParentheses: false
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceBeforeSquareBrackets: false
|
||||
SpaceInEmptyBraces: Never
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: Never
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInLineCommentPrefix:
|
||||
Minimum: 1
|
||||
Maximum: -1
|
||||
SpacesInParens: Never
|
||||
SpacesInParensOptions:
|
||||
ExceptDoubleParentheses: false
|
||||
InCStyleCasts: false
|
||||
InConditionalStatements: false
|
||||
InEmptyParentheses: false
|
||||
Other: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Latest
|
||||
StatementAttributeLikeMacros:
|
||||
- Q_EMIT
|
||||
StatementMacros:
|
||||
- Q_UNUSED
|
||||
- QT_REQUIRE_VERSION
|
||||
TableGenBreakInsideDAGArg: DontBreak
|
||||
TabWidth: 8
|
||||
UseTab: Never
|
||||
VerilogBreakBetweenInstancePorts: true
|
||||
WhitespaceSensitiveMacros:
|
||||
- BOOST_PP_STRINGIZE
|
||||
- CF_SWIFT_NAME
|
||||
- NS_SWIFT_NAME
|
||||
- PP_STRINGIZE
|
||||
- STRINGIZE
|
||||
WrapNamespaceBodyWithEmptyLines: Leave
|
||||
...
|
||||
|
||||
@@ -2,17 +2,19 @@ name: Build and Deploy on Tag
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
- "v*"
|
||||
|
||||
env:
|
||||
GITEA_AUTH: ${{ secrets.MY_GITEA_AUTH }}
|
||||
|
||||
PACKAGE_AND_BREW: ${{ secrets.PACKAGE_AND_BREW }}
|
||||
VERSION: ${{ gitea.ref_name }}
|
||||
|
||||
jobs:
|
||||
build-arch:
|
||||
name: "🔨 Build for Arch Linux/Static Builds"
|
||||
runs-on: arch-builder
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: pacman --noconfirm -Sy mbedtls curl
|
||||
- run: pacman --noconfirm -Sy mbedtls zip zig ninja
|
||||
- run: pacman --config /opt/cross/ppc/pacman.conf --noconfirm -Sy mbedtls
|
||||
- run: cp Packaging/Linux/PKGBUILD /home/build/PKGBUILD
|
||||
- run: cp Packaging/Linux/build-arch.sh /home/build/build-arch.sh
|
||||
@@ -20,20 +22,42 @@ jobs:
|
||||
- run: chown build:build /home/build/PKGBUILD
|
||||
- run: chown build:build /home/build/build-arch.sh
|
||||
- run: su build -c /home/build/build-arch.sh
|
||||
build-jammy:
|
||||
runs-on: deb-builder-jammy
|
||||
- uses: akkuman/gitea-release-action@v1
|
||||
env:
|
||||
NODE_OPTIONS: '--experimental-fetch' # if nodejs < 18
|
||||
with:
|
||||
prerelease: true
|
||||
files: |-
|
||||
artifacts/**
|
||||
|
||||
update-tap-and-build-win32:
|
||||
name: "🔨 Build win32 and update the tap 🍺"
|
||||
runs-on: global-container-mingw
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Build for jammy, noble
|
||||
run: |
|
||||
bash build-ubuntu-jammy.sh
|
||||
bash push-ubuntu-jammy.sh
|
||||
working-directory: ./Packaging/Linux
|
||||
build-plucky:
|
||||
runs-on: deb-builder-plucky
|
||||
steps:
|
||||
- name: Build for plucky, resolute
|
||||
run: |
|
||||
bash build-ubuntu-plucky.sh
|
||||
bash push-ubuntu-plucky.sh
|
||||
working-directory: ./Packaging/Linux
|
||||
- run: |
|
||||
mkdir artifacts
|
||||
env -C Packaging/WinToolsIntel bash build.sh
|
||||
|
||||
- uses: akkuman/gitea-release-action@v1
|
||||
env:
|
||||
NODE_OPTIONS: '--experimental-fetch' # if nodejs < 18
|
||||
with:
|
||||
prerelease: true
|
||||
files: |-
|
||||
artifacts/**
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: "master"
|
||||
path: "tapdir"
|
||||
repository: "tesses50/tesses-tap.git"
|
||||
token: ${{ env.PACKAGE_AND_BREW }}
|
||||
- run: |
|
||||
cd tapdir
|
||||
bash ../Packaging/edit-formula.sh
|
||||
git config user.name "Tesses Gitea Bot"
|
||||
git config user.email "noreply@tesses.net"
|
||||
git add .
|
||||
git commit -m "Push tessesframework=${{ env.VERSION }}"
|
||||
git push
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@ builds
|
||||
.vscode
|
||||
out
|
||||
/.vs
|
||||
artifacts
|
||||
@@ -1,52 +0,0 @@
|
||||
version: 43
|
||||
jobs:
|
||||
- name: Build for x86_64
|
||||
steps:
|
||||
- type: CheckoutStep
|
||||
name: Checkout
|
||||
cloneCredential:
|
||||
type: DefaultCredential
|
||||
withLfs: true
|
||||
withSubmodules: false
|
||||
condition: SUCCESSFUL
|
||||
optional: false
|
||||
- type: CommandStep
|
||||
name: Execute build
|
||||
runInContainer: true
|
||||
image: onedev.site.tesses.net/dependencies/dependencies:latest
|
||||
interpreter:
|
||||
type: DefaultInterpreter
|
||||
commands: |
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -S .. -B . -DTESSESFRAMEWORK_FETCHCONTENT=OFF
|
||||
make -j12
|
||||
make install DESTDIR=out
|
||||
useTTY: true
|
||||
condition: SUCCESSFUL
|
||||
optional: false
|
||||
- type: BuildImageStep
|
||||
name: Build Docker Image
|
||||
dockerfile: Dockerfile.run
|
||||
output:
|
||||
type: RegistryOutput
|
||||
tags: onedev.site.tesses.net/tesses-framework/tesses-framework:latest onedev.site.tesses.net/tesses-framework/tesses-framework:@commit_hash@ git.tesseslanguage.com/tesses50/tesses-framework:latest git.tesseslanguage.com/tesses50/tesses-framework:@commit_hash@
|
||||
registryLogins:
|
||||
- registryUrl: '@server_url@'
|
||||
userName: '@job_token@'
|
||||
passwordSecret: dockersecret
|
||||
- registryUrl: git.tesseslanguage.com
|
||||
userName: tesses50
|
||||
passwordSecret: GITEA_AUTH
|
||||
platforms: linux/amd64
|
||||
condition: SUCCESSFUL
|
||||
optional: false
|
||||
triggers:
|
||||
- type: BranchUpdateTrigger
|
||||
branches: master
|
||||
userMatch: anyone
|
||||
projects: tesses-framework
|
||||
retryCondition: never
|
||||
maxRetries: 3
|
||||
retryDelay: 30
|
||||
timeout: 14400
|
||||
419
CMakeLists.txt
419
CMakeLists.txt
@@ -1,87 +1,18 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
set(TESSESFRAMEWORK_MAJOR_VERSION 0)
|
||||
set(TESSESFRAMEWORK_MINOR_VERSION 0)
|
||||
set(TESSESFRAMEWORK_PATCH_VERSION 1)
|
||||
|
||||
include(cmake/version.cmake)
|
||||
project(TessesFramework VERSION ${TESSESFRAMEWORK_MAJOR_VERSION}.${TESSESFRAMEWORK_MINOR_VERSION}.${TESSESFRAMEWORK_PATCH_VERSION})
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
list(APPEND TESSESFRAMEWORK_SOURCE
|
||||
src/Random.cpp
|
||||
src/Date/Date.cpp
|
||||
src/Http/FileServer.cpp
|
||||
src/Http/MountableServer.cpp
|
||||
src/Http/RouteServer.cpp
|
||||
src/Http/CallbackServer.cpp
|
||||
src/Http/HttpServer.cpp
|
||||
src/Http/HttpUtils.cpp
|
||||
src/Http/HttpClient.cpp
|
||||
src/Http/HttpStream.cpp
|
||||
src/Http/ContentDisposition.cpp
|
||||
src/Http/WebSocket.cpp
|
||||
src/Http/ChangeableServer.cpp
|
||||
src/Http/BasicAuthServer.cpp
|
||||
src/Http/CGIServer.cpp
|
||||
src/Mail/Smtp.cpp
|
||||
src/Serialization/Json.cpp
|
||||
src/Serialization/SQLite.cpp
|
||||
src/Serialization/BitConverter.cpp
|
||||
src/Serialization/Bencode.cpp
|
||||
src/Platform/Environment.cpp
|
||||
src/Platform/Process.cpp
|
||||
src/Streams/FileStream.cpp
|
||||
src/Streams/MemoryStream.cpp
|
||||
src/Streams/NetworkStream.cpp
|
||||
src/Streams/Stream.cpp
|
||||
src/Streams/BufferedStream.cpp
|
||||
src/Streams/ByteReader.cpp
|
||||
src/Streams/ByteWriter.cpp
|
||||
src/Streams/PtyStream.cpp
|
||||
src/Text/StringConverter.cpp
|
||||
src/Text/HeaderGenerator.cpp
|
||||
src/TextStreams/StreamReader.cpp
|
||||
src/TextStreams/StreamWriter.cpp
|
||||
src/TextStreams/TextReader.cpp
|
||||
src/TextStreams/TextWriter.cpp
|
||||
src/TextStreams/StdIOReader.cpp
|
||||
src/TextStreams/StdIOWriter.cpp
|
||||
src/TextStreams/StringReader.cpp
|
||||
src/TextStreams/StringWriter.cpp
|
||||
src/Threading/Thread.cpp
|
||||
src/Threading/Mutex.cpp
|
||||
src/Threading/ThreadPool.cpp
|
||||
src/Filesystem/VFS.cpp
|
||||
src/Filesystem/LocalFS.cpp
|
||||
src/Filesystem/MemoryFilesystem.cpp
|
||||
src/Filesystem/SubdirFilesystem.cpp
|
||||
src/Filesystem/NullFilesystem.cpp
|
||||
src/Filesystem/MountableFilesystem.cpp
|
||||
src/Filesystem/FSHelpers.cpp
|
||||
src/Filesystem/TempFS.cpp
|
||||
src/Crypto/MbedTLS/ClientTLSStream.cpp
|
||||
src/Crypto/MbedTLS/Crypto.cpp
|
||||
src/Args.cpp
|
||||
src/TF_Init.cpp
|
||||
src/HiddenField.cpp
|
||||
src/BitTorrent/TorrentFile.cpp
|
||||
src/BitTorrent/TorrentStream.cpp
|
||||
)
|
||||
include(GNUInstallDirs)
|
||||
include(CheckLibraryExists)
|
||||
include(FetchContent)
|
||||
include(cmake/sources.cmake)
|
||||
include(cmake/options.cmake)
|
||||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
||||
|
||||
|
||||
option(TESSESFRAMEWORK_EMBED_CERT_BUNDLE "Embed the certificate chain bundle" ON)
|
||||
option(TESSESFRAMEWORK_ENABLE_MBED "Enable Tesses Framework mbedtls" ON)
|
||||
option(TESSESFRAMEWORK_ENABLE_NETWORKING "Enable Networking" ON)
|
||||
option(TESSESFRAMEWORK_ENABLE_THREADING "Enable Threading" ON)
|
||||
option(TESSESFRAMEWORK_ENABLE_SQLITE "Enable sqlite (embedded in source)" ON)
|
||||
option(TESSESFRAMEWORK_ENABLE_PLATFORMFOLDERS "Enable sago platformfolders (embedded in source)" ON)
|
||||
option(TESSESFRAMEWORK_ENABLE_PROCESS "Enable process api" ON)
|
||||
option(TESSESFRAMEWORK_ENABLE_RPATH "Enable RPATH" ON)
|
||||
|
||||
if(TESSESFRAMEWORK_ENABLE_SQLITE)
|
||||
list(APPEND TESSESFRAMEWORK_SOURCE
|
||||
list(APPEND TESSESFRAMEWORK_SOURCE
|
||||
src/Serialization/sqlite/sqlite3-mod.c
|
||||
src/Serialization/sqlite/vfs.c
|
||||
)
|
||||
@@ -91,341 +22,45 @@ list(APPEND TESSESFRAMEWORK_SOURCE
|
||||
src/Platform/sago/platform_folders.cpp
|
||||
)
|
||||
endif()
|
||||
option(TESSESFRAMEWORK_ENABLE_EXAMPLES "Enable Tesses Framework examples" ON)
|
||||
option(TESSESFRAMEWORK_ENABLE_APPS "Enable Tesses Framework cli apps" ON)
|
||||
option(TESSESFRAMEWORK_INSTALL_DEVELOPMENT "Enable Installing Tesses Framework Development Packages" ON)
|
||||
option(TESSESFRAMEWORK_ENABLE_STATIC "Enable Tesses Framework Static Libraries" ON)
|
||||
option(TESSESFRAMEWORK_ENABLE_SHARED "Enable Tesses Framework Shared Libraries" ON)
|
||||
option(TESSESFRAMEWORK_ENABLE_SETDATE "Enable setting date to file" ON)
|
||||
option(TESSESFRAMEWORK_LOGTOFILE "TessesFramework Log to file" OFF)
|
||||
option(TESSESFRAMEWORK_FETCHCONTENT "TessesFramework fetchcontent" ON)
|
||||
option(TESSESFRAMEWORK_VENDERCERTCHAIN "Use the ca-certificates.crt in project rather than system" ON)
|
||||
if(TESSESFRAMEWORK_FETCHCONTENT)
|
||||
set(TESSESFRAMEWORK_CERT_BUNDLE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/ca-certificates.crt" CACHE FILEPATH "Path to ca-chain")
|
||||
include(FetchContent)
|
||||
else()
|
||||
|
||||
include(cmake/findmbed.cmake)
|
||||
|
||||
|
||||
|
||||
|
||||
if(TESSESFRAMEWORK_VENDERCERTCHAIN)
|
||||
set(TESSESFRAMEWORK_CERT_BUNDLE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/ca-certificates.crt" CACHE FILEPATH "Path to ca-chain")
|
||||
else()
|
||||
set(TESSESFRAMEWORK_CERT_BUNDLE_FILE "/etc/ssl/certs/ca-certificates.crt" CACHE FILEPATH "Path to ca-chain")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include)
|
||||
|
||||
include(cmake/bin2h.cmake)
|
||||
|
||||
|
||||
|
||||
# Making sure libraries don't generate symlinks
|
||||
|
||||
if(TESSESFRAMEWORK_ENABLE_MBED)
|
||||
if(TESSESFRAMEWORK_EMBED_CERT_BUNDLE)
|
||||
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/include/TessesFramework/CertificateChain.h" "#pragma once\n")
|
||||
#target_compile_definitions(TessesFramework PUBLIC TESSESFRAMEWORK_EMBED_CERT_BUNDLE)
|
||||
bin2h(SOURCE_FILE "${TESSESFRAMEWORK_CERT_BUNDLE_FILE}" HEADER_FILE "${CMAKE_CURRENT_BINARY_DIR}/include/TessesFramework/CertificateChain.h" VARIABLE_NAME CertificateChain APPEND NULL_TERMINATE)
|
||||
file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/include/TessesFramework/CertificateChain.h" "\n")
|
||||
|
||||
endif()
|
||||
endif()
|
||||
|
||||
include(cmake/sources.cmake)
|
||||
|
||||
if(TESSESFRAMEWORK_STATIC)
|
||||
include(cmake/staticlib.cmake)
|
||||
else()
|
||||
target_compile_definitions(TessesFramework PUBLIC TESSESFRAMEWORK_CERT_BUNDLE_FILE=${TESSESFRAMEWORK_CERT_BUNDLE_FILE})
|
||||
|
||||
endif()
|
||||
if(TESSESFRAMEWORK_FETCHCONTENT)
|
||||
set(MBEDTLS_FATAL_WARNINGS OFF CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
set(ENABLE_TESTING OFF CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
set(ENABLE_PROGRAMS OFF CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
if(NOT TESSESFRAMEWORK_ENABLE_STATIC)
|
||||
|
||||
set(USE_STATIC_MBEDTLS_LIBRARY OFF CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
endif()
|
||||
if(TESSESFRAMEWORK_ENABLE_SHARED)
|
||||
set(USE_SHARED_MBEDTLS_LIBRARY ON CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
endif()
|
||||
FetchContent_Declare(
|
||||
mbedtls
|
||||
URL https://downloads.tesses.net/cache/libraries/source/mbedtls-3.6.4.tar.bz2
|
||||
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(mbedtls)
|
||||
else()
|
||||
set(MBEDTLS_DIR "" CACHE PATH "Mbed tls directory")
|
||||
include(cmake/sharedlib.cmake)
|
||||
endif()
|
||||
|
||||
endif()
|
||||
function(TESSESFRAMEWORK_LINKDEPS TessesFramework_TARGET)
|
||||
if(TESSESFRAMEWORK_ENABLE_SQLITE)
|
||||
target_compile_definitions(${TessesFramework_TARGET} PUBLIC TESSESFRAMEWORK_ENABLE_SQLITE)
|
||||
endif()
|
||||
if(TESSESFRAMEWORK_ENABLE_PLATFORMFOLDERS)
|
||||
target_compile_definitions(${TessesFramework_TARGET} PUBLIC TESSESFRAMEWORK_ENABLE_PLATFORMFOLDERS)
|
||||
endif()
|
||||
if(TESSESFRAMEWORK_ENABLE_PROCESS)
|
||||
target_compile_definitions(${TessesFramework_TARGET} PUBLIC TESSESFRAMEWORK_ENABLE_PROCESS)
|
||||
|
||||
endif()
|
||||
target_include_directories(${TessesFramework_TARGET}
|
||||
PUBLIC
|
||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
|
||||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
|
||||
)
|
||||
target_include_directories(${TessesFramework_TARGET}
|
||||
PUBLIC
|
||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>"
|
||||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
|
||||
)
|
||||
if(WIN32)
|
||||
target_link_libraries(${TessesFramework_TARGET} PUBLIC iphlpapi)
|
||||
endif()
|
||||
if(TESSESFRAMEWORK_LOGTOFILE)
|
||||
target_compile_definitions(${TessesFramework_TARGET} PUBLIC TESSESFRAMEWORK_LOGTOFILE)
|
||||
endif()
|
||||
if(TESSESFRAMEWORK_ENABLE_THREADING)
|
||||
target_compile_definitions(${TessesFramework_TARGET} PUBLIC TESSESFRAMEWORK_ENABLE_THREADING)
|
||||
endif()
|
||||
if(TESSESFRAMEWORK_ENABLE_NETWORKING)
|
||||
target_compile_definitions(${TessesFramework_TARGET} PUBLIC TESSESFRAMEWORK_ENABLE_NETWORKING)
|
||||
endif()
|
||||
if(TESSESFRAMEWORK_FETCHCONTENT)
|
||||
target_compile_definitions(${TessesFramework_TARGET} PUBLIC TESSESFRAMEWORK_FETCHCONTENT)
|
||||
endif()
|
||||
if(TESSESFRAMEWORK_ENABLE_MBED)
|
||||
target_compile_definitions(${TessesFramework_TARGET} PUBLIC TESSESFRAMEWORK_ENABLE_MBED)
|
||||
if(TESSESFRAMEWORK_EMBED_CERT_BUNDLE)
|
||||
target_compile_definitions(${TessesFramework_TARGET} PUBLIC TESSESFRAMEWORK_EMBED_CERT_BUNDLE)
|
||||
else()
|
||||
target_compile_definitions(TessesFramework PUBLIC TESSESFRAMEWORK_CERT_BUNDLE_FILE=${TESSESFRAMEWORK_CERT_BUNDLE_FILE})
|
||||
endif()
|
||||
if(NOT TESSESFRAMEWORK_FETCHCONTENT)
|
||||
if(MBEDTLS_DIR STREQUAL "")
|
||||
else()
|
||||
target_include_directories(${TessesFramework_TARGET} PUBLIC ${MBEDTLS_DIR}/include)
|
||||
target_link_directories(${TessesFramework_TARGET} PUBLIC ${MBEDTLS_DIR}/lib)
|
||||
endif()
|
||||
target_link_libraries(${TessesFramework_TARGET} PUBLIC mbedtls mbedx509 mbedcrypto)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if("${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoWii" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoGameCube")
|
||||
target_link_libraries(${TessesFramework_TARGET} PUBLIC fat)
|
||||
|
||||
endif()
|
||||
if("${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoSwitch" AND TESSESFRAMEWORK_ENABLE_THREADING)
|
||||
target_link_libraries(${TessesFramework_TARGET} PUBLIC -lpthread)
|
||||
endif()
|
||||
if("${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoWii")
|
||||
target_link_libraries(${TessesFramework_TARGET} PUBLIC wiisocket)
|
||||
target_compile_definitions(${TessesFramework_TARGET} PUBLIC TESSESFRAMEWORK_USE_WII_SOCKET)
|
||||
endif()
|
||||
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
|
||||
|
||||
target_link_libraries(${TessesFramework_TARGET} PUBLIC ws2_32)
|
||||
|
||||
endif()
|
||||
|
||||
if(NOT("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" OR PLATFORM_PS2 OR "${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoWii" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoGameCube"))
|
||||
|
||||
if(TESSESFRAMEWORK_ENABLE_THREADING)
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
find_package(Threads REQUIRED)
|
||||
target_link_libraries(${TessesFramework_TARGET} PRIVATE Threads::Threads)
|
||||
endif()
|
||||
endif()
|
||||
if(TESSESFRAMEWORK_ENABLE_SETDATE)
|
||||
target_compile_definitions(${TessesFramework_TARGET} PUBLIC TESSESFRAMEWORK_ENABLE_SETDATE)
|
||||
endif()
|
||||
target_compile_definitions(${TessesFramework_TARGET} PUBLIC _FILE_OFFSET_BITS=64)
|
||||
|
||||
if(PLATFORM_PS2)
|
||||
target_link_libraries(${TessesFramework_TARGET} PUBLIC -ldebug)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
||||
if(TESSESFRAMEWORK_ENABLE_STATIC)
|
||||
|
||||
add_library(tessesframework STATIC ${TESSESFRAMEWORK_SOURCE})
|
||||
TESSESFRAMEWORK_LINKDEPS(tessesframework)
|
||||
|
||||
if(TESSESFRAMEWORK_FETCHCONTENT AND TESSESFRAMEWORK_ENABLE_MBED)
|
||||
if(TESSESFRAMEWORK_ENABLE_SHARED)
|
||||
target_link_libraries(tessesframework PUBLIC mbedtls_static mbedx509_static mbedcrypto_static)
|
||||
else()
|
||||
|
||||
target_link_libraries(tessesframework PUBLIC mbedtls mbedx509 mbedcrypto everest p256m)
|
||||
endif()
|
||||
endif()
|
||||
list(APPEND TessesFrameworkLibs tessesframework)
|
||||
endif()
|
||||
|
||||
|
||||
if(TESSESFRAMEWORK_ENABLE_SHARED)
|
||||
if(TESSESFRAMEWORK_ENABLE_RPATH)
|
||||
set(CMAKE_MACOSX_RPATH 1)
|
||||
set(CMAKE_BUILD_RPATH_USE_ORIGIN TRUE)
|
||||
|
||||
if (APPLE)
|
||||
set(CMAKE_INSTALL_RPATH "@executable_path/../${CMAKE_INSTALL_LIBDIR}")
|
||||
else()
|
||||
set(CMAKE_INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}")
|
||||
endif()
|
||||
endif()
|
||||
add_library(tessesframework_shared SHARED ${TESSESFRAMEWORK_SOURCE})
|
||||
TESSESFRAMEWORK_LINKDEPS(tessesframework_shared)
|
||||
|
||||
if(TESSESFRAMEWORK_ENABLE_MBED)
|
||||
if(TESSESFRAMEWORK_FETCHCONTENT)
|
||||
target_link_libraries(tessesframework_shared PUBLIC mbedtls mbedx509 mbedcrypto everest p256m)
|
||||
|
||||
else()
|
||||
target_link_libraries(tessesframework_shared PUBLIC mbedtls mbedx509 mbedcrypto)
|
||||
|
||||
endif()
|
||||
endif()
|
||||
list(APPEND TessesFrameworkLibs tessesframework_shared)
|
||||
|
||||
|
||||
|
||||
|
||||
endif()
|
||||
|
||||
if((TESSESFRAMEWORK_ENABLE_STATIC OR TESSESFRAMEWORK_ENABLE_SHARED) AND TESSESFRAMEWORK_FETCHCONTENT AND TESSESFRAMEWORK_ENABLE_MBED)
|
||||
list(APPEND TessesFrameworkLibs mbedtls mbedx509 mbedcrypto everest p256m)
|
||||
if(TESSESFRAMEWORK_ENABLE_STATIC AND TESSESFRAMEWORK_ENABLE_SHARED)
|
||||
list(APPEND TessesFrameworkLibs mbedtls_static mbedx509_static mbedcrypto_static)
|
||||
endif()
|
||||
endif()
|
||||
include(cmake/install-dev.cmake)
|
||||
|
||||
include(cmake/examples.cmake)
|
||||
include(cmake/apps.cmake)
|
||||
|
||||
if(TESSESFRAMEWORK_INSTALL_DEVELOPMENT)
|
||||
install(TARGETS ${TessesFrameworkLibs}
|
||||
EXPORT TessesFrameworkTargets
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
)
|
||||
|
||||
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/TessesFramework DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/TessesFramework DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||
|
||||
install(EXPORT TessesFrameworkTargets
|
||||
FILE TessesFrameworkTargets.cmake
|
||||
NAMESPACE TessesFramework::
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/TessesFramework
|
||||
)
|
||||
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/TessesFrameworkConfig.cmake"
|
||||
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/TessesFramework)
|
||||
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/TessesFrameworkFeatures.h.in "${CMAKE_CURRENT_BINARY_DIR}/include/TessesFramework/TessesFrameworkFeatures.h"
|
||||
INSTALL_DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/TessesFramework/TessesFrameworkFeatures.h)
|
||||
|
||||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/TessesFrameworkConfig.cmake"
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/TessesFramework)
|
||||
endif()
|
||||
|
||||
if(TESSESFRAMEWORK_ENABLE_EXAMPLES)
|
||||
|
||||
add_executable(copyfile examples/copyfile.cpp)
|
||||
target_link_libraries(copyfile PUBLIC tessesframework)
|
||||
|
||||
add_executable(webserverex examples/webserverex.cpp)
|
||||
target_link_libraries(webserverex PUBLIC tessesframework)
|
||||
|
||||
add_executable(safesubpath examples/safesubpath.cpp)
|
||||
target_link_libraries(safesubpath PUBLIC tessesframework)
|
||||
|
||||
add_executable(pathtest examples/pathtest.cpp)
|
||||
target_link_libraries(pathtest PUBLIC tessesframework)
|
||||
|
||||
add_executable(mountabletest examples/mountabletest.cpp)
|
||||
target_link_libraries(mountabletest PUBLIC tessesframework)
|
||||
|
||||
add_executable(printjsondecodedemoji examples/printjsondecodedemoji.cpp)
|
||||
target_link_libraries(printjsondecodedemoji PUBLIC tessesframework)
|
||||
|
||||
add_executable(wsecho examples/wsecho.cpp)
|
||||
target_link_libraries(wsecho PUBLIC tessesframework)
|
||||
|
||||
add_executable(runevent examples/runevent.cpp)
|
||||
target_link_libraries(runevent PUBLIC tessesframework)
|
||||
|
||||
add_executable(tests examples/tests.cpp)
|
||||
target_link_libraries(tests PUBLIC tessesframework)
|
||||
endif()
|
||||
|
||||
if(TESSESFRAMEWORK_ENABLE_APPS)
|
||||
add_executable(tbin2h apps/tbin2h.cpp)
|
||||
target_link_libraries(tbin2h PUBLIC tessesframework)
|
||||
install(TARGETS tbin2h DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
add_executable(tanonydrop apps/tanonydrop.cpp)
|
||||
target_link_libraries(tanonydrop PUBLIC tessesframework)
|
||||
install(TARGETS tanonydrop DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
add_executable(tfetch apps/tfetch.cpp)
|
||||
target_link_libraries(tfetch PUBLIC tessesframework)
|
||||
install(TARGETS tfetch DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
add_executable(tfileserver apps/tfileserver.cpp)
|
||||
target_link_libraries(tfileserver PUBLIC tessesframework)
|
||||
install(TARGETS tfileserver DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
|
||||
add_executable(tdoc2json apps/tdoc2json.cpp)
|
||||
target_link_libraries(tdoc2json PUBLIC tessesframework)
|
||||
install(TARGETS tdoc2json DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
|
||||
add_executable(tjson2doc apps/tjson2doc.cpp)
|
||||
target_link_libraries(tjson2doc PUBLIC tessesframework)
|
||||
install(TARGETS tjson2doc DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
|
||||
add_executable(tjsonpretty apps/tjsonpretty.cpp)
|
||||
target_link_libraries(tjsonpretty PUBLIC tessesframework)
|
||||
install(TARGETS tjsonpretty DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
|
||||
add_executable(tjsonunpretty apps/tjsonunpretty.cpp)
|
||||
target_link_libraries(tjsonunpretty PUBLIC tessesframework)
|
||||
install(TARGETS tjsonunpretty DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
|
||||
add_executable(ttime apps/ttime.cpp)
|
||||
target_link_libraries(ttime PUBLIC tessesframework)
|
||||
install(TARGETS ttime DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
add_executable(tshell apps/tshell.cpp)
|
||||
target_link_libraries(tshell PUBLIC tessesframework)
|
||||
install(TARGETS tshell DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
|
||||
add_executable(tprinttorrent apps/printtorrent.cpp)
|
||||
|
||||
target_link_libraries(tprinttorrent PUBLIC tessesframework)
|
||||
install(TARGETS tprinttorrent DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
|
||||
add_executable(ttorrentcreate apps/ttorrentcreate.cpp)
|
||||
|
||||
target_link_libraries(ttorrentcreate PUBLIC tessesframework)
|
||||
install(TARGETS ttorrentcreate DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
|
||||
add_executable(tclearwebseed apps/tclearwebseed.cpp)
|
||||
|
||||
target_link_libraries(tclearwebseed PUBLIC tessesframework)
|
||||
install(TARGETS tclearwebseed DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
|
||||
add_executable(trng apps/trng.cpp)
|
||||
|
||||
target_link_libraries(trng PUBLIC tessesframework)
|
||||
install(TARGETS trng DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
|
||||
add_executable(twatch apps/twatch.cpp)
|
||||
|
||||
target_link_libraries(twatch PUBLIC tessesframework)
|
||||
install(TARGETS twatch DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
endif()
|
||||
|
||||
include(InstallRequiredSystemLibraries)
|
||||
set(CPACK_PACKAGE_CONTACT "Mike Nolan <tesses@tesses.net>")
|
||||
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.md")
|
||||
set(CPACK_PACKAGE_VERSION_MAJOR "${TessesFramework_VERSION_MAJOR}")
|
||||
set(CPACK_PACKAGE_VERSION_MINOR "${TessesFramework_VERSION_MINOR}")
|
||||
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libmbedtls-dev (>= 2.28.8)")
|
||||
|
||||
include(CPack)
|
||||
add_subdirectory(pkgconfig)
|
||||
add_subdirectory(pkgconfig)
|
||||
endif()
|
||||
@@ -1,90 +0,0 @@
|
||||
{
|
||||
"version": 3,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "linux-debug",
|
||||
"displayName": "Linux Debug",
|
||||
"description": "Target the Windows Subsystem for Linux (WSL) or a remote Linux system.",
|
||||
"generator": "Ninja",
|
||||
"binaryDir": "${sourceDir}/out/build/${presetName}",
|
||||
"installDir": "${sourceDir}/out/install/${presetName}",
|
||||
"cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" },
|
||||
"condition": {
|
||||
"type": "equals",
|
||||
"lhs": "${hostSystemName}",
|
||||
"rhs": "Linux"
|
||||
},
|
||||
"vendor": { "microsoft.com/VisualStudioRemoteSettings/CMake/2.0": { "remoteSourceRootDir": "$env{HOME}/.vs/$ms{projectDirName}" } }
|
||||
},
|
||||
{
|
||||
"name": "macos-debug",
|
||||
"displayName": "macOS Debug",
|
||||
"description": "Target a remote macOS system.",
|
||||
"generator": "Ninja",
|
||||
"binaryDir": "${sourceDir}/out/build/${presetName}",
|
||||
"installDir": "${sourceDir}/out/install/${presetName}",
|
||||
"cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" },
|
||||
"condition": {
|
||||
"type": "equals",
|
||||
"lhs": "${hostSystemName}",
|
||||
"rhs": "Darwin"
|
||||
},
|
||||
"vendor": { "microsoft.com/VisualStudioRemoteSettings/CMake/1.0": { "sourceDir": "$env{HOME}/.vs/$ms{projectDirName}" } }
|
||||
},
|
||||
{
|
||||
"name": "windows-base",
|
||||
"description": "Target Windows with the Visual Studio development environment.",
|
||||
"hidden": true,
|
||||
"generator": "Ninja",
|
||||
"binaryDir": "${sourceDir}/out/build/${presetName}",
|
||||
"installDir": "${sourceDir}/out/install/${presetName}",
|
||||
"cacheVariables": {
|
||||
"CMAKE_C_COMPILER": "cl.exe",
|
||||
"CMAKE_CXX_COMPILER": "cl.exe",
|
||||
"TESSESFRAMEWORK_ENABLE_MBED": false,
|
||||
"TESSESFRAMEWORK_FETCHCONTENT": false
|
||||
},
|
||||
"condition": {
|
||||
"type": "equals",
|
||||
"lhs": "${hostSystemName}",
|
||||
"rhs": "Windows"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "x64-debug",
|
||||
"displayName": "x64 Debug",
|
||||
"description": "Target Windows (64-bit) with the Visual Studio development environment. (Debug)",
|
||||
"inherits": "windows-base",
|
||||
"architecture": {
|
||||
"value": "x64",
|
||||
"strategy": "external"
|
||||
},
|
||||
"cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" }
|
||||
},
|
||||
{
|
||||
"name": "x64-release",
|
||||
"displayName": "x64 Release",
|
||||
"description": "Target Windows (64-bit) with the Visual Studio development environment. (RelWithDebInfo)",
|
||||
"inherits": "x64-debug",
|
||||
"cacheVariables": { "CMAKE_BUILD_TYPE": "Release" }
|
||||
},
|
||||
{
|
||||
"name": "x86-debug",
|
||||
"displayName": "x86 Debug",
|
||||
"description": "Target Windows (32-bit) with the Visual Studio development environment. (Debug)",
|
||||
"inherits": "windows-base",
|
||||
"architecture": {
|
||||
"value": "x86",
|
||||
"strategy": "external"
|
||||
},
|
||||
"cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" }
|
||||
},
|
||||
{
|
||||
"name": "x86-release",
|
||||
"displayName": "x86 Release",
|
||||
"description": "Target Windows (32-bit) with the Visual Studio development environment. (RelWithDebInfo)",
|
||||
"inherits": "x86-debug",
|
||||
"cacheVariables": { "CMAKE_BUILD_TYPE": "Release" }
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -3,30 +3,31 @@
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/TessesFrameworkTargets.cmake")
|
||||
|
||||
check_required_components(TessesFramework)
|
||||
|
||||
if(NOT ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoWii" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoGameCube"))
|
||||
include(GNUInstallDirs)
|
||||
if(NOT WIN32)
|
||||
if(@TESSESFRAMEWORK_ENABLE_THREADING@)
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
find_package(Threads REQUIRED)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(TESSESFRAMEWORK_ENABLE_LIBWEBCAM @TESSESFRAMEWORK_ENABLE_LIBWEBCAM@)
|
||||
|
||||
if(${TESSESFRAMEWORK_ENABLE_LIBWEBCAM})
|
||||
find_package(libwebcam)
|
||||
endif()
|
||||
|
||||
set(TESSESFRAMEWORK_ENABLE_MBED @TESSESFRAMEWORK_ENABLE_MBED@)
|
||||
set(TESSESFRAMEWORK_ENABLE_SQLITE @TESSESFRAMEWORK_ENABLE_SQLITE@)
|
||||
set(TESSESFRAMEWORK_ENABLE_PLATFORMFOLDERS @TESSESFRAMEWORK_ENABLE_PLATFORMFOLDERS@)
|
||||
set(TESSESFRAMEWORK_ENABLE_SDL2 @TESSESFRAMEWORK_ENABLE_SDL2@)
|
||||
|
||||
|
||||
if(${TESSESFRAMEWORK_ENABLE_SDL2})
|
||||
find_package(SDL2 REQUIRED)
|
||||
find_package(SDL2_ttf REQUIRED)
|
||||
find_package(SDL2_image REQUIRED)
|
||||
endif()
|
||||
|
||||
set(TESSESFRAMEWORK_ENABLE_NETWORKING @TESSESFRAMEWORK_ENABLE_NETWORKING@)
|
||||
set(TESSESFRAMEWORK_ENABLE_THREADING @TESSESFRAMEWORK_ENABLE_THREADING@)
|
||||
set(TESSESFRAMEWORK_ENABLE_PROCESS @TESSESFRAMEWORK_ENABLE_PROCESS@)
|
||||
set(TESSESFRAMEWORK_ENABLE_RPATH @TESSESFRAMEWORK_ENABLE_RPATH@)
|
||||
set(TESSESFRAMEWORK_STATIC @TESSESFRAMEWORK_STATIC@)
|
||||
|
||||
if(@TESSESFRAMEWORK_ENABLE_RPATH@ AND NOT @TESSESFRAMEWORK_STATIC@)
|
||||
set(CMAKE_MACOSX_RPATH 1)
|
||||
set(CMAKE_BUILD_RPATH_USE_ORIGIN TRUE)
|
||||
|
||||
if (APPLE)
|
||||
set(CMAKE_INSTALL_RPATH "@executable_path/../${CMAKE_INSTALL_LIBDIR}")
|
||||
else()
|
||||
set(CMAKE_INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}")
|
||||
endif()
|
||||
endif()
|
||||
@@ -1,5 +0,0 @@
|
||||
FROM ubuntu:noble
|
||||
|
||||
RUN apt update && apt install -y cmake g++ gcc libmbedtls-dev build-essential git ca-certificates
|
||||
|
||||
RUN mkdir /src && cd /src && git clone https://onedev.site.tesses.net/tesses-framework . && mkdir build && cd build && cmake -S .. -B . && make -j12 && make install && cd / && rm -r /src
|
||||
@@ -1,3 +0,0 @@
|
||||
FROM onedev.site.tesses.net/dependencies/dependencies:latest
|
||||
COPY build/out /
|
||||
|
||||
688
LICENSE.md
688
LICENSE.md
@@ -1,21 +1,675 @@
|
||||
MIT License
|
||||
# GNU GENERAL PUBLIC LICENSE
|
||||
|
||||
Copyright (c) 2024 Mike Nolan
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
Copyright (C) 2007 Free Software Foundation, Inc.
|
||||
<https://fsf.org/>
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
Everyone is permitted to copy and distribute verbatim copies of this
|
||||
license document, but changing it is not allowed.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
## Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom
|
||||
to share and change all versions of a program--to make sure it remains
|
||||
free software for all its users. We, the Free Software Foundation, use
|
||||
the GNU General Public License for most of our software; it applies
|
||||
also to any other work released this way by its authors. You can apply
|
||||
it to your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you
|
||||
have certain responsibilities if you distribute copies of the
|
||||
software, or if you modify it: responsibilities to respect the freedom
|
||||
of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the
|
||||
manufacturer can do so. This is fundamentally incompatible with the
|
||||
aim of protecting users' freedom to change the software. The
|
||||
systematic pattern of such abuse occurs in the area of products for
|
||||
individuals to use, which is precisely where it is most unacceptable.
|
||||
Therefore, we have designed this version of the GPL to prohibit the
|
||||
practice for those products. If such problems arise substantially in
|
||||
other domains, we stand ready to extend this provision to those
|
||||
domains in future versions of the GPL, as needed to protect the
|
||||
freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish
|
||||
to avoid the special danger that patents applied to a free program
|
||||
could make it effectively proprietary. To prevent this, the GPL
|
||||
assures that patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
## TERMS AND CONDITIONS
|
||||
|
||||
### 0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds
|
||||
of works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of
|
||||
an exact copy. The resulting work is called a "modified version" of
|
||||
the earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user
|
||||
through a computer network, with no transfer of a copy, is not
|
||||
conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices" to
|
||||
the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
### 1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work for
|
||||
making modifications to it. "Object code" means any non-source form of
|
||||
a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users can
|
||||
regenerate automatically from other parts of the Corresponding Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that same
|
||||
work.
|
||||
|
||||
### 2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not convey,
|
||||
without conditions so long as your license otherwise remains in force.
|
||||
You may convey covered works to others for the sole purpose of having
|
||||
them make modifications exclusively for you, or provide you with
|
||||
facilities for running those works, provided that you comply with the
|
||||
terms of this License in conveying all material for which you do not
|
||||
control copyright. Those thus making or running the covered works for
|
||||
you must do so exclusively on your behalf, under your direction and
|
||||
control, on terms that prohibit them from making any copies of your
|
||||
copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under the
|
||||
conditions stated below. Sublicensing is not allowed; section 10 makes
|
||||
it unnecessary.
|
||||
|
||||
### 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such
|
||||
circumvention is effected by exercising rights under this License with
|
||||
respect to the covered work, and you disclaim any intention to limit
|
||||
operation or modification of the work as a means of enforcing, against
|
||||
the work's users, your or third parties' legal rights to forbid
|
||||
circumvention of technological measures.
|
||||
|
||||
### 4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
### 5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these
|
||||
conditions:
|
||||
|
||||
- a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
- b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under
|
||||
section 7. This requirement modifies the requirement in section 4
|
||||
to "keep intact all notices".
|
||||
- c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
- d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
### 6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms of
|
||||
sections 4 and 5, provided that you also convey the machine-readable
|
||||
Corresponding Source under the terms of this License, in one of these
|
||||
ways:
|
||||
|
||||
- a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
- b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the Corresponding
|
||||
Source from a network server at no charge.
|
||||
- c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
- d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
- e) Convey the object code using peer-to-peer transmission,
|
||||
provided you inform other peers where the object code and
|
||||
Corresponding Source of the work are being offered to the general
|
||||
public at no charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal,
|
||||
family, or household purposes, or (2) anything designed or sold for
|
||||
incorporation into a dwelling. In determining whether a product is a
|
||||
consumer product, doubtful cases shall be resolved in favor of
|
||||
coverage. For a particular product received by a particular user,
|
||||
"normally used" refers to a typical or common use of that class of
|
||||
product, regardless of the status of the particular user or of the way
|
||||
in which the particular user actually uses, or expects or is expected
|
||||
to use, the product. A product is a consumer product regardless of
|
||||
whether the product has substantial commercial, industrial or
|
||||
non-consumer uses, unless such uses represent the only significant
|
||||
mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to
|
||||
install and execute modified versions of a covered work in that User
|
||||
Product from a modified version of its Corresponding Source. The
|
||||
information must suffice to ensure that the continued functioning of
|
||||
the modified object code is in no case prevented or interfered with
|
||||
solely because modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or
|
||||
updates for a work that has been modified or installed by the
|
||||
recipient, or for the User Product in which it has been modified or
|
||||
installed. Access to a network may be denied when the modification
|
||||
itself materially and adversely affects the operation of the network
|
||||
or violates the rules and protocols for communication across the
|
||||
network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
### 7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders
|
||||
of that material) supplement the terms of this License with terms:
|
||||
|
||||
- a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
- b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
- c) Prohibiting misrepresentation of the origin of that material,
|
||||
or requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
- d) Limiting the use for publicity purposes of names of licensors
|
||||
or authors of the material; or
|
||||
- e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
- f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions
|
||||
of it) with contractual assumptions of liability to the recipient,
|
||||
for any liability that these contractual assumptions directly
|
||||
impose on those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions; the
|
||||
above requirements apply either way.
|
||||
|
||||
### 8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your license
|
||||
from a particular copyright holder is reinstated (a) provisionally,
|
||||
unless and until the copyright holder explicitly and finally
|
||||
terminates your license, and (b) permanently, if the copyright holder
|
||||
fails to notify you of the violation by some reasonable means prior to
|
||||
60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
### 9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or run
|
||||
a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
### 10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
### 11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims owned
|
||||
or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within the
|
||||
scope of its coverage, prohibits the exercise of, or is conditioned on
|
||||
the non-exercise of one or more of the rights that are specifically
|
||||
granted under this License. You may not convey a covered work if you
|
||||
are a party to an arrangement with a third party that is in the
|
||||
business of distributing software, under which you make payment to the
|
||||
third party based on the extent of your activity of conveying the
|
||||
work, and under which the third party grants, to any of the parties
|
||||
who would receive the covered work from you, a discriminatory patent
|
||||
license (a) in connection with copies of the covered work conveyed by
|
||||
you (or copies made from those copies), or (b) primarily for and in
|
||||
connection with specific products or compilations that contain the
|
||||
covered work, unless you entered into that arrangement, or that patent
|
||||
license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
### 12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under
|
||||
this License and any other pertinent obligations, then as a
|
||||
consequence you may not convey it at all. For example, if you agree to
|
||||
terms that obligate you to collect a royalty for further conveying
|
||||
from those to whom you convey the Program, the only way you could
|
||||
satisfy both those terms and this License would be to refrain entirely
|
||||
from conveying the Program.
|
||||
|
||||
### 13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
### 14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in
|
||||
detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies that a certain numbered version of the GNU General Public
|
||||
License "or any later version" applies to it, you have the option of
|
||||
following the terms and conditions either of that numbered version or
|
||||
of any later version published by the Free Software Foundation. If the
|
||||
Program does not specify a version number of the GNU General Public
|
||||
License, you may choose any version ever published by the Free
|
||||
Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future versions
|
||||
of the GNU General Public License can be used, that proxy's public
|
||||
statement of acceptance of a version permanently authorizes you to
|
||||
choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
### 15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
|
||||
WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
|
||||
PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
|
||||
DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
|
||||
CORRECTION.
|
||||
|
||||
### 16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR
|
||||
CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
|
||||
ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT
|
||||
NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR
|
||||
LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM
|
||||
TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER
|
||||
PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
### 17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
## How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these
|
||||
terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest to
|
||||
attach them to the start of each source file to most effectively state
|
||||
the exclusion of warranty; and each file should have at least the
|
||||
"copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper
|
||||
mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands \`show w' and \`show c' should show the
|
||||
appropriate parts of the General Public License. Of course, your
|
||||
program's commands might be different; for a GUI interface, you would
|
||||
use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. For more information on this, and how to apply and follow
|
||||
the GNU GPL, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your
|
||||
program into proprietary programs. If your program is a subroutine
|
||||
library, you may consider it more useful to permit linking proprietary
|
||||
applications with the library. If this is what you want to do, use the
|
||||
GNU Lesser General Public License instead of this License. But first,
|
||||
please read <https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
@@ -1,8 +1,10 @@
|
||||
Other peoples code
|
||||
==================
|
||||
|
||||
- cmake/bin2h.cmake, from: https://github.com/sivachandran/cmake-bin2h (MIT)
|
||||
- Cppified the multipart/form-data code from: https://github.com/dajuric/simple-http (MIT)
|
||||
- cmake/bin2h.cmake, from: [https://github.com/sivachandran/cmake-bin2h](https://github.com/sivachandran/cmake-bin2h) (MIT)
|
||||
- Cppified the multipart/form-data code from: [https://github.com/dajuric/simple-http](https://github.com/dajuric/simple-http) (MIT)
|
||||
- mbedtls ssl code from mbedtls examples (Apache 2.0)
|
||||
- [Sqlite](https://www.sqlite.org/) (in folder src/sqlite also uses demo VFS (at least on Wii))
|
||||
- [MbedTLS](https://github.com/Mbed-TLS/mbedtls) (external dependency) (Apache 2.0/GPLv2 or later, either are compatible with TessesFramework now)
|
||||
- [Sqlite](https://www.sqlite.org/) (in folder src/sqlite also uses demo VFS (at least on Wii)) (Public Domain, licensed by hopes and prayers, praise God!)
|
||||
- [Sago's platform_folders](https://github.com/sago007/PlatformFolders) (in folder src/sago)
|
||||
- [HowardHinnart's date](https://github.com/HowardHinnant/date) (in folder src/HowardHinnant_date) (MIT)
|
||||
@@ -1,16 +1,16 @@
|
||||
# Maintainer: Mike Nolan <tesses@tesses.net>
|
||||
pkgname=tesses-framework # '-bzr', '-git', '-hg' or '-svn'
|
||||
pkgver=0.0.1
|
||||
pkgname=tessesframework # '-bzr', '-git', '-hg' or '-svn'
|
||||
pkgver=0.0.4
|
||||
pkgrel=1
|
||||
pkgdesc=""
|
||||
arch=('x86_64' 'powerpc')
|
||||
url="https://onedev.site.tesses.net/tesses-framework"
|
||||
url="https://git.tesses.org/tesses50/tessesframework"
|
||||
license=('MIT')
|
||||
groups=()
|
||||
depends=('mbedtls')
|
||||
makedepends=('git' 'cmake' 'make' 'base-devel' 'wget') # 'bzr', 'git', 'mercurial' or 'subversion'
|
||||
install=
|
||||
source=('tesses-framework::git+https://onedev.site.tesses.net/tesses-framework')
|
||||
source=('tessesframework::git+https://git.tesses.org/tesses50/tessesframework')
|
||||
noextract=()
|
||||
sha256sums=('SKIP')
|
||||
if [[ -z "$CMAKE_TOOLCHAIN" ]]; then
|
||||
@@ -22,22 +22,21 @@ fi
|
||||
|
||||
prepare() {
|
||||
cd "$srcdir/${pkgname}"
|
||||
wget https://downloads.tesses.net/ShellPackage.crvm
|
||||
}
|
||||
|
||||
build() {
|
||||
cd "$srcdir/${pkgname}"
|
||||
mkdir build
|
||||
|
||||
|
||||
if [[ -z "$CMAKE_TOOLCHAIN" ]]; then
|
||||
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/usr -DTESSESFRAMEWORK_VENDERCERTCHAIN=OFF -DTESSESFRAMEWORK_FETCHCONTENT=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo
|
||||
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/usr -DTESSESFRAMEWORK_VENDERCERTCHAIN=OFF -DTESSESFRAMEWORK_FETCHCONTENT=OFF -DCMAKE_BUILD_TYPE=Release
|
||||
else
|
||||
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/usr -DTESSESFRAMEWORK_VENDERCERTCHAIN=OFF -DTESSESFRAMEWORK_FETCHCONTENT=OFF -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_TOOLCHAIN_FILE="$CMAKE_TOOLCHAIN"
|
||||
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/usr -DTESSESFRAMEWORK_VENDERCERTCHAIN=OFF -DTESSESFRAMEWORK_FETCHCONTENT=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="$CMAKE_TOOLCHAIN"
|
||||
fi
|
||||
|
||||
|
||||
cd build
|
||||
make -j`nproc`
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -47,4 +46,3 @@ package() {
|
||||
cd "$srcdir/${pkgname}/build"
|
||||
make install DESTDIR="$pkgdir/"
|
||||
}
|
||||
|
||||
|
||||
@@ -4,14 +4,14 @@ mkdir x86_64
|
||||
cd x86_64
|
||||
cp ../PKGBUILD .
|
||||
makepkg
|
||||
curl --user tesses50:$GITEA_AUTH \
|
||||
curl --user tesses50:$PACKAGE_AND_BREW \
|
||||
--upload-file *.pkg.tar.zst \
|
||||
https://git.tesseslanguage.com/api/packages/tesses50/arch/core
|
||||
https://git.tesses.org/api/packages/tesses50/arch/core
|
||||
cd ..
|
||||
mkdir powerpc
|
||||
cd powerpc
|
||||
cp ../PKGBUILD .
|
||||
CARCH=powerpc CMAKE_TOOLCHAIN=/opt/cross/ppc/toolchain.cmake makepkg
|
||||
curl --user tesses50:$GITEA_AUTH \
|
||||
curl --user tesses50:$PACKAGE_AND_BREW \
|
||||
--upload-file *.pkg.tar.zst \
|
||||
https://git.tesseslanguage.com/api/packages/tesses50/arch/core
|
||||
https://git.tesses.org/api/packages/tesses50/arch/core
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
#!/bin/bash
|
||||
source ./version.sh
|
||||
mkdir -p build/jammy
|
||||
cd build/jammy
|
||||
mkdir build-amd64
|
||||
cmake -S ../../../../ -B build-amd64 -DCMAKE_INSTALL_PREFIX=/usr -DTESSESFRAMEWORK_VENDERCERTCHAIN=OFF -DTESSESFRAMEWORK_FETCHCONTENT=OFF
|
||||
cd build-amd64
|
||||
make -j`nproc`
|
||||
make install DESTDIR=../tessesframework_$DEB_VERSION\_amd64
|
||||
mkdir -p ../tessesframework_$DEB_VERSION\_amd64/DEBIAN
|
||||
bash ../../../make-control.sh ../tessesframework_$DEB_VERSION\_amd64/DEBIAN/control amd64
|
||||
cd ../
|
||||
dpkg-deb --build tessesframework_$DEB_VERSION\_amd64
|
||||
|
||||
# ARM64
|
||||
mkdir build-arm64
|
||||
cmake -S ../../../../ -B build-arm64 -DCMAKE_INSTALL_PREFIX=/usr -DTESSESFRAMEWORK_VENDERCERTCHAIN=OFF -DTESSESFRAMEWORK_FETCHCONTENT=OFF -DCMAKE_TOOLCHAIN_FILE=/opt/toolchains/arm64.cmake
|
||||
cd build-arm64
|
||||
make -j`nproc`
|
||||
make install DESTDIR=../tessesframework_$DEB_VERSION\_arm64
|
||||
mkdir -p ../tessesframework_$DEB_VERSION\_arm64/DEBIAN
|
||||
bash ../../../make-control.sh ../tessesframework_$DEB_VERSION\_arm64/DEBIAN/control arm64
|
||||
cd ../
|
||||
dpkg-deb --build tessesframework_$DEB_VERSION\_arm64
|
||||
|
||||
# RISCV64
|
||||
mkdir build-riscv64
|
||||
cmake -S ../../../../ -B build-riscv64 -DCMAKE_INSTALL_PREFIX=/usr -DTESSESFRAMEWORK_VENDERCERTCHAIN=OFF -DTESSESFRAMEWORK_FETCHCONTENT=OFF -DCMAKE_TOOLCHAIN_FILE=/opt/toolchains/riscv64.cmake
|
||||
cd build-riscv64
|
||||
make -j`nproc`
|
||||
make install DESTDIR=../tessesframework_$DEB_VERSION\_riscv64
|
||||
mkdir -p ../tessesframework_$DEB_VERSION\_riscv64/DEBIAN
|
||||
bash ../../../make-control.sh ../tessesframework_$DEB_VERSION\_riscv64/DEBIAN/control riscv64
|
||||
cd ../
|
||||
dpkg-deb --build tessesframework_$DEB_VERSION\_riscv64
|
||||
|
||||
# ARMHF
|
||||
mkdir build-armhf
|
||||
cmake -S ../../../../ -B build-armhf -DCMAKE_INSTALL_PREFIX=/usr -DTESSESFRAMEWORK_VENDERCERTCHAIN=OFF -DTESSESFRAMEWORK_FETCHCONTENT=OFF -DCMAKE_TOOLCHAIN_FILE=/opt/toolchains/armhf.cmake
|
||||
cd build-armhf
|
||||
make -j`nproc`
|
||||
make install DESTDIR=../tessesframework_$DEB_VERSION\_armhf
|
||||
mkdir -p ../tessesframework_$DEB_VERSION\_armhf/DEBIAN
|
||||
bash ../../../make-control.sh ../tessesframework_$DEB_VERSION\_armhf/DEBIAN/control armhf
|
||||
cd ../
|
||||
dpkg-deb --build tessesframework_$DEB_VERSION\_armhf
|
||||
@@ -1,57 +0,0 @@
|
||||
#!/bin/bash
|
||||
source ./version.sh
|
||||
mkdir -p build/plucky
|
||||
cd build/plucky
|
||||
mkdir build-amd64
|
||||
cmake -S ../../../../ -B build-amd64 -DCMAKE_INSTALL_PREFIX=/usr -DTESSESFRAMEWORK_VENDERCERTCHAIN=OFF -DTESSESFRAMEWORK_FETCHCONTENT=OFF
|
||||
cd build-amd64
|
||||
make -j`nproc`
|
||||
make install DESTDIR=../tessesframework_$DEB_VERSION\_amd64
|
||||
mkdir -p ../tessesframework_$DEB_VERSION\_amd64/DEBIAN
|
||||
bash ../../../make-control.sh ../tessesframework_$DEB_VERSION\_amd64/DEBIAN/control amd64
|
||||
cd ../
|
||||
dpkg-deb --build tessesframework_$DEB_VERSION\_amd64
|
||||
|
||||
# ARM64
|
||||
mkdir build-arm64
|
||||
cmake -S ../../../../ -B build-arm64 -DCMAKE_INSTALL_PREFIX=/usr -DTESSESFRAMEWORK_VENDERCERTCHAIN=OFF -DTESSESFRAMEWORK_FETCHCONTENT=OFF -DCMAKE_TOOLCHAIN_FILE=/opt/toolchains/arm64.cmake
|
||||
cd build-arm64
|
||||
make -j`nproc`
|
||||
make install DESTDIR=../tessesframework_$DEB_VERSION\_arm64
|
||||
mkdir -p ../tessesframework_$DEB_VERSION\_arm64/DEBIAN
|
||||
bash ../../../make-control.sh ../tessesframework_$DEB_VERSION\_arm64/DEBIAN/control arm64
|
||||
cd ../
|
||||
dpkg-deb --build tessesframework_$DEB_VERSION\_arm64
|
||||
|
||||
# RISCV64
|
||||
mkdir build-riscv64
|
||||
cmake -S ../../../../ -B build-riscv64 -DCMAKE_INSTALL_PREFIX=/usr -DTESSESFRAMEWORK_VENDERCERTCHAIN=OFF -DTESSESFRAMEWORK_FETCHCONTENT=OFF -DCMAKE_TOOLCHAIN_FILE=/opt/toolchains/riscv64.cmake
|
||||
cd build-riscv64
|
||||
make -j`nproc`
|
||||
make install DESTDIR=../tessesframework_$DEB_VERSION\_riscv64
|
||||
mkdir -p ../tessesframework_$DEB_VERSION\_riscv64/DEBIAN
|
||||
bash ../../../make-control.sh ../tessesframework_$DEB_VERSION\_riscv64/DEBIAN/control riscv64
|
||||
cd ../
|
||||
dpkg-deb --build tessesframework_$DEB_VERSION\_riscv64
|
||||
|
||||
# ARMHF
|
||||
mkdir build-armhf
|
||||
cmake -S ../../../../ -B build-armhf -DCMAKE_INSTALL_PREFIX=/usr -DTESSESFRAMEWORK_VENDERCERTCHAIN=OFF -DTESSESFRAMEWORK_FETCHCONTENT=OFF -DCMAKE_TOOLCHAIN_FILE=/opt/toolchains/armhf.cmake
|
||||
cd build-armhf
|
||||
make -j`nproc`
|
||||
make install DESTDIR=../tessesframework_$DEB_VERSION\_armhf
|
||||
mkdir -p ../tessesframework_$DEB_VERSION\_armhf/DEBIAN
|
||||
bash ../../../make-control.sh ../tessesframework_$DEB_VERSION\_armhf/DEBIAN/control armhf
|
||||
cd ../
|
||||
dpkg-deb --build tessesframework_$DEB_VERSION\_armhf
|
||||
|
||||
# I386
|
||||
mkdir build-i386
|
||||
cmake -S ../../../../ -B build-i386 -DCMAKE_INSTALL_PREFIX=/usr -DTESSESFRAMEWORK_VENDERCERTCHAIN=OFF -DTESSESFRAMEWORK_FETCHCONTENT=OFF -DCMAKE_TOOLCHAIN_FILE=/opt/toolchains/i386.cmake
|
||||
cd build-i386
|
||||
make -j`nproc`
|
||||
make install DESTDIR=../tessesframework_$DEB_VERSION\_i386
|
||||
mkdir -p ../tessesframework_$DEB_VERSION\_i386/DEBIAN
|
||||
bash ../../../make-control.sh ../tessesframework_$DEB_VERSION\_i386/DEBIAN/control i386
|
||||
cd ../
|
||||
dpkg-deb --build tessesframework_$DEB_VERSION\_i386
|
||||
@@ -1,8 +0,0 @@
|
||||
echo "Package: tessesframework" > "$1"
|
||||
echo "Version: $DEB_VERSION" >> "$1"
|
||||
echo "Architecture: $2" >> "$1"
|
||||
echo "Essential: no" >> "$1"
|
||||
echo "Priority: optional" >> "$1"
|
||||
echo "Depends: libmbedtls-dev" >> "$1"
|
||||
echo "Maintainer: Mike Nolan" >> "$1"
|
||||
echo "Description: A cross platform wrapper library" >> "$1"
|
||||
@@ -1,22 +0,0 @@
|
||||
#!/bin/bash
|
||||
source ./version.sh
|
||||
curl --user tesses50:$GITEA_AUTH -X DELETE \
|
||||
https://git.tesseslanguage.com/api/packages/tesses50/debian/pool/jammy/main/tessesframework/$DEB_VERSION/amd64
|
||||
curl --user tesses50:$GITEA_AUTH -X DELETE \
|
||||
https://git.tesseslanguage.com/api/packages/tesses50/debian/pool/jammy/main/tessesframework/$DEB_VERSION/arm64
|
||||
curl --user tesses50:$GITEA_AUTH -X DELETE \
|
||||
https://git.tesseslanguage.com/api/packages/tesses50/debian/pool/jammy/main/tessesframework/$DEB_VERSION/riscv64
|
||||
curl --user tesses50:$GITEA_AUTH -X DELETE \
|
||||
https://git.tesseslanguage.com/api/packages/tesses50/debian/pool/jammy/main/tessesframework/$DEB_VERSION/armhf
|
||||
curl --user tesses50:$GITEA_AUTH \
|
||||
--upload-file build/jammy/tessesframework_$DEB_VERSION\_amd64.deb \
|
||||
https://git.tesseslanguage.com/api/packages/tesses50/debian/pool/jammy/main/upload
|
||||
curl --user tesses50:$GITEA_AUTH \
|
||||
--upload-file build/jammy/tessesframework_$DEB_VERSION\_arm64.deb \
|
||||
https://git.tesseslanguage.com/api/packages/tesses50/debian/pool/jammy/main/upload
|
||||
curl --user tesses50:$GITEA_AUTH \
|
||||
--upload-file build/jammy/tessesframework_$DEB_VERSION\_riscv64.deb \
|
||||
https://git.tesseslanguage.com/api/packages/tesses50/debian/pool/jammy/main/upload
|
||||
curl --user tesses50:$GITEA_AUTH \
|
||||
--upload-file build/jammy/tessesframework_$DEB_VERSION\_armhf.deb \
|
||||
https://git.tesseslanguage.com/api/packages/tesses50/debian/pool/jammy/main/upload
|
||||
@@ -1,27 +0,0 @@
|
||||
#!/bin/bash
|
||||
source ./version.sh
|
||||
curl --user tesses50:$GITEA_AUTH -X DELETE \
|
||||
https://git.tesseslanguage.com/api/packages/tesses50/debian/pool/plucky/main/tessesframework/$DEB_VERSION/amd64
|
||||
curl --user tesses50:$GITEA_AUTH -X DELETE \
|
||||
https://git.tesseslanguage.com/api/packages/tesses50/debian/pool/plucky/main/tessesframework/$DEB_VERSION/arm64
|
||||
curl --user tesses50:$GITEA_AUTH -X DELETE \
|
||||
https://git.tesseslanguage.com/api/packages/tesses50/debian/pool/plucky/main/tessesframework/$DEB_VERSION/i386
|
||||
curl --user tesses50:$GITEA_AUTH -X DELETE \
|
||||
https://git.tesseslanguage.com/api/packages/tesses50/debian/pool/plucky/main/tessesframework/$DEB_VERSION/riscv64
|
||||
curl --user tesses50:$GITEA_AUTH -X DELETE \
|
||||
https://git.tesseslanguage.com/api/packages/tesses50/debian/pool/plucky/main/tessesframework/$DEB_VERSION/armhf
|
||||
curl --user tesses50:$GITEA_AUTH \
|
||||
--upload-file build/plucky/tessesframework_$DEB_VERSION\_amd64.deb \
|
||||
https://git.tesseslanguage.com/api/packages/tesses50/debian/pool/plucky/main/upload
|
||||
curl --user tesses50:$GITEA_AUTH \
|
||||
--upload-file build/plucky/tessesframework_$DEB_VERSION\_arm64.deb \
|
||||
https://git.tesseslanguage.com/api/packages/tesses50/debian/pool/plucky/main/upload
|
||||
curl --user tesses50:$GITEA_AUTH \
|
||||
--upload-file build/plucky/tessesframework_$DEB_VERSION\_i386.deb \
|
||||
https://git.tesseslanguage.com/api/packages/tesses50/debian/pool/plucky/main/upload
|
||||
curl --user tesses50:$GITEA_AUTH \
|
||||
--upload-file build/plucky/tessesframework_$DEB_VERSION\_riscv64.deb \
|
||||
https://git.tesseslanguage.com/api/packages/tesses50/debian/pool/plucky/main/upload
|
||||
curl --user tesses50:$GITEA_AUTH \
|
||||
--upload-file build/plucky/tessesframework_$DEB_VERSION\_armhf.deb \
|
||||
https://git.tesseslanguage.com/api/packages/tesses50/debian/pool/plucky/main/upload
|
||||
@@ -1 +0,0 @@
|
||||
export DEB_VERSION=0.0.1
|
||||
34
Packaging/Tools/build.sh
Normal file
34
Packaging/Tools/build.sh
Normal file
@@ -0,0 +1,34 @@
|
||||
mkdir -p ../../artifacts
|
||||
mkdir -p builds
|
||||
git clone --depth 1 https://git.tesses.org/tesses50/zig-cross builds/zig-cross
|
||||
|
||||
|
||||
|
||||
for tripple in x86_64-linux-musl x86-linux-musl aarch64-linux-musl arm-linux-musleabi riscv64-linux-musl powerpc-linux-musleabihf; do
|
||||
export BUILDDIR=builds/$tripple
|
||||
mkdir -p $BUILDDIR
|
||||
cmake -S ../.. -B $BUILDDIR --toolchain $PWD/builds/zig-cross/$tripple\.cmake -DCMAKE_BUILD_TYPE=Release -DTESSESFRAMEWORK_INSTALL_DEVELOPMENT=OFF -DTESSESFRAMEWORK_ENABLE_EXAMPLES=OFF -DTESSESFRAMEWORK_STATIC=ON -DCMAKE_EXE_LINKER_FLAGS="-static-libgcc -static-libstdc++ -static -Wl,--strip-all" -DCMAKE_POSITION_INDEPENDENT_CODE=ON -GNinja
|
||||
cmake --build $BUILDDIR || exit 1
|
||||
cmake --install $BUILDDIR --prefix $BUILDDIR/out
|
||||
tar cvzf ../../artifacts/tessesframework-tools-$tripple\.tar.gz -C $BUILDDIR/out/ bin
|
||||
|
||||
done
|
||||
#x86_64-windows-gnu x86-windows-gnu
|
||||
export BUILDDIR=builds/aarch64-windows-gnu
|
||||
mkdir -p $BUILDDIR
|
||||
cmake -S ../.. -B $BUILDDIR --toolchain $PWD/builds/zig-cross/aarch64-windows-gnu.cmake -DCMAKE_BUILD_TYPE=Release -DTESSESFRAMEWORK_INSTALL_DEVELOPMENT=OFF -DTESSESFRAMEWORK_ENABLE_EXAMPLES=OFF -DTESSESFRAMEWORK_STATIC=ON -DCMAKE_EXE_LINKER_FLAGS="-static-libgcc -static-libstdc++ -static -Wl,--strip-all" -DCMAKE_POSITION_INDEPENDENT_CODE=ON -GNinja
|
||||
cmake --build $BUILDDIR || exit 1
|
||||
cmake --install $BUILDDIR --prefix $BUILDDIR/out
|
||||
|
||||
env -C $BUILDDIR/out zip -r ../../../../../artifacts/tessesframework-tools-aarch64-windows-gnu.zip bin
|
||||
|
||||
|
||||
for tripple in x86_64-macos-none aarch64-macos-none; do
|
||||
export BUILDDIR=builds/$tripple
|
||||
mkdir -p $BUILDDIR
|
||||
cmake -S ../.. -B $BUILDDIR --toolchain $PWD/builds/zig-cross/$tripple\.cmake -DCMAKE_BUILD_TYPE=Release -DTESSESFRAMEWORK_INSTALL_DEVELOPMENT=OFF -DTESSESFRAMEWORK_ENABLE_EXAMPLES=OFF -DTESSESFRAMEWORK_STATIC=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON -GNinja -DCMAKE_EXE_LINKER_FLAGS="-Wl,--strip-all"
|
||||
cmake --build $BUILDDIR || exit 1
|
||||
cmake --install $BUILDDIR --prefix $BUILDDIR/out
|
||||
tar cvzf ../../artifacts/tessesframework-tools-$tripple\.tar.gz -C $BUILDDIR/out/ bin
|
||||
|
||||
done
|
||||
13
Packaging/WinToolsIntel/build.sh
Normal file
13
Packaging/WinToolsIntel/build.sh
Normal file
@@ -0,0 +1,13 @@
|
||||
export BUILDDIR=builds/x86-windows-gnu
|
||||
mkdir -p $BUILDDIR
|
||||
cmake -S ../.. -B $BUILDDIR --toolchain $PWD/x86.cmake -DCMAKE_BUILD_TYPE=Release -DTESSESFRAMEWORK_INSTALL_DEVELOPMENT=OFF -DTESSESFRAMEWORK_ENABLE_EXAMPLES=OFF -DTESSESFRAMEWORK_STATIC=ON -DCMAKE_EXE_LINKER_FLAGS="-static-libgcc -static-libstdc++ -static -Wl,--strip-all" -DCMAKE_POSITION_INDEPENDENT_CODE=ON -GNinja
|
||||
cmake --build $BUILDDIR || exit 1
|
||||
cmake --install $BUILDDIR --prefix $BUILDDIR/out
|
||||
env -C $BUILDDIR/out zip -r ../../../../../artifacts/tessesframework-tools-x86-windows-gnu.zip bin
|
||||
|
||||
export BUILDDIR=builds/x86_64-windows-gnu
|
||||
mkdir -p $BUILDDIR
|
||||
cmake -S ../.. -B $BUILDDIR --toolchain $PWD/x86_64.cmake -DCMAKE_BUILD_TYPE=Release -DTESSESFRAMEWORK_INSTALL_DEVELOPMENT=OFF -DTESSESFRAMEWORK_ENABLE_EXAMPLES=OFF -DTESSESFRAMEWORK_STATIC=ON -DCMAKE_EXE_LINKER_FLAGS="-static-libgcc -static-libstdc++ -static -Wl,--strip-all" -DCMAKE_POSITION_INDEPENDENT_CODE=ON -GNinja
|
||||
cmake --build $BUILDDIR || exit 1
|
||||
cmake --install $BUILDDIR --prefix $BUILDDIR/out
|
||||
env -C $BUILDDIR/out zip -r ../../../../../artifacts/tessesframework-tools-x86_64-windows-gnu.zip bin
|
||||
7
Packaging/WinToolsIntel/x86.cmake
Normal file
7
Packaging/WinToolsIntel/x86.cmake
Normal file
@@ -0,0 +1,7 @@
|
||||
set(CMAKE_C_COMPILER "/usr/bin/i686-w64-mingw32-gcc")
|
||||
set(CMAKE_CXX_COMPILER "/usr/bin/i686-w64-mingw32-g++")
|
||||
set(CMAKE_C_FLAGS "-static-libgcc -static-libstdc++ -static")
|
||||
set(CMAKE_CXX_FLAGS "-static-libgcc -static-libstdc++ -static")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")
|
||||
set(CMAKE_SYSTEM_NAME Windows)
|
||||
set(CMAKE_SYSTEM_PROCESSOR i686)
|
||||
7
Packaging/WinToolsIntel/x86_64.cmake
Normal file
7
Packaging/WinToolsIntel/x86_64.cmake
Normal file
@@ -0,0 +1,7 @@
|
||||
set(CMAKE_C_COMPILER "/usr/bin/x86_64-w64-mingw32-gcc")
|
||||
set(CMAKE_CXX_COMPILER "/usr/bin/x86_64-w64-mingw32-g++")
|
||||
set(CMAKE_C_FLAGS "-static-libgcc -static-libstdc++ -static")
|
||||
set(CMAKE_CXX_FLAGS "-static-libgcc -static-libstdc++ -static")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")
|
||||
set(CMAKE_SYSTEM_NAME Windows)
|
||||
set(CMAKE_SYSTEM_PROCESSOR x86_64)
|
||||
19
Packaging/edit-formula.sh
Normal file
19
Packaging/edit-formula.sh
Normal file
@@ -0,0 +1,19 @@
|
||||
export HASH=`curl https://git.tesses.org/tesses50/tessesframework/archive/$VERSION.tar.gz 2> /dev/null | shasum -a 256 | awk '{print $1}'`
|
||||
|
||||
echo "class Tessesframework < Formula" > "Formula/tessesframework.rb"
|
||||
echo " desc \"\"" >> "Formula/tessesframework.rb"
|
||||
echo " homepage \"\"" >> "Formula/tessesframework.rb"
|
||||
echo " url \"https://git.tesses.org/tesses50/tessesframework/archive/$VERSION.tar.gz\"" >> "Formula/tessesframework.rb"
|
||||
echo " sha256 \"$HASH\"" >> "Formula/tessesframework.rb"
|
||||
echo " license \"MIT\"" >> "Formula/tessesframework.rb"
|
||||
echo " depends_on \"cmake\" => :build" >> "Formula/tessesframework.rb"
|
||||
echo " depends_on \"mbedtls@3\"" >> "Formula/tessesframework.rb"
|
||||
echo " def install" >> "Formula/tessesframework.rb"
|
||||
echo " system \"cmake\", \"-S\", \".\", \"-B\", \"build\", \"-DTESSESFRAMEWORK_FETCHCONTENT=OFF\", *std_cmake_args" >> "Formula/tessesframework.rb"
|
||||
echo " system \"cmake\", \"--build\", \"build\"" >> "Formula/tessesframework.rb"
|
||||
echo " system \"cmake\", \"--install\", \"build\"" >> "Formula/tessesframework.rb"
|
||||
echo " end" >> "Formula/tessesframework.rb"
|
||||
echo " test do" >> "Formula/tessesframework.rb"
|
||||
echo " system \"true\"" >> "Formula/tessesframework.rb"
|
||||
echo " end" >> "Formula/tessesframework.rb"
|
||||
echo "end" >> "Formula/tessesframework.rb"
|
||||
38
README.md
38
README.md
@@ -1,14 +1,48 @@
|
||||
Tesses Framework
|
||||
================
|
||||
|
||||
## Features
|
||||
- DateTime, TimeSpan
|
||||
- VFS (polymorphic filesystems) (Mountable is kind of broken)
|
||||
- BitTorrent file generation, bencoding
|
||||
- Http Client/Server
|
||||
- Json
|
||||
- Simple SMTP client
|
||||
- Environment variables (cross platform), user special folders (also cross platform, using sago/platform-folders)
|
||||
- Sqlite3 (embedded into this library)
|
||||
- Process API (for windows/mac/linux/probably bsd)
|
||||
- Polymorphic byte streams (for files/network/memory)
|
||||
- C/C++ header generator for embedding files
|
||||
- A console api which works on windows/mac/linux (even before windows 10, tested on 8.1 and works), with password entry, readline, partial vt100 emulation for win32, colors, raw/cooked modes and terminal list (for somewhat primitive interactive tuis, it does scroll though, pages)
|
||||
- Thread pool and threading
|
||||
- Basic arg parser
|
||||
- Uuids
|
||||
- Lazy initializable type
|
||||
- Unicode support, (I need to do better validation, I know, only really used for windows and parsing json)
|
||||
- EventLoop
|
||||
- Basic crytography using mbedtls
|
||||
- a LCG Random number generator (do not use for crypto, use it for non security things like number guessing games and stuff, where rand would be ok)
|
||||
|
||||
## Supported Platforms
|
||||
- Linux
|
||||
- Windows (with mingw and static linked for sure)
|
||||
- MacOS
|
||||
- FreeBSD (including GhostBSD)
|
||||
- NetBSD
|
||||
- Wii (using libogc2, may be broken)
|
||||
- Switch (using libnx, may be broken)
|
||||
- Android (kinda, uses legacy and hardcoded /sdcard api unless you use TF_AllowPortable(std::string))
|
||||
|
||||
> NOTE: if platform folders is disabled tessesframework uses the path /TF_User for special folders (except for android which it uses /sdcard)
|
||||
|
||||
## To Install
|
||||
- Install [mbedtls](https://github.com/Mbed-TLS/mbedtls) (use sudo apt install libmbedtls-dev on debian) for TessesFramework
|
||||
- Follow the commands bellow
|
||||
|
||||
## Run these commands to install tesses-framework
|
||||
```bash
|
||||
git clone https://onedev.site.tesses.net/tesses-framework
|
||||
cd tesses-framework
|
||||
git clone https://git.tesses.org/tesses50/tessesframework
|
||||
cd tessesframework
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -S .. -B .
|
||||
|
||||
@@ -6,18 +6,15 @@ using namespace Tesses::Framework::Filesystem;
|
||||
using namespace Tesses::Framework::Serialization::Bencode;
|
||||
using namespace Tesses::Framework::TextStreams;
|
||||
using namespace Tesses::Framework::BitTorrent;
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
TF_Init();
|
||||
if(argc < 2)
|
||||
{
|
||||
printf("USAGE: %s /path/to/torrent/file\n",argv[0]);
|
||||
if (argc < 2) {
|
||||
printf("USAGE: %s /path/to/torrent/file\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
auto strm = LocalFS->OpenFile((std::string)argv[1],"rb");
|
||||
auto strm = LocalFS->OpenFile((std::string)argv[1], "rb");
|
||||
auto bencode = Bencode::Load(strm);
|
||||
if(std::holds_alternative<BeDictionary>(bencode))
|
||||
{
|
||||
if (std::holds_alternative<BeDictionary>(bencode)) {
|
||||
|
||||
TorrentFile file(std::get<BeDictionary>(bencode));
|
||||
file.Print(std::make_shared<ConsoleWriter>());
|
||||
|
||||
@@ -7,88 +7,88 @@ using namespace Tesses::Framework::Filesystem;
|
||||
|
||||
std::shared_ptr<VFS> vfs;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
TF_InitWithConsole();
|
||||
vfs = std::make_shared<SubdirFilesystem>(LocalFS,Tesses::Framework::Filesystem::VFSPath::GetAbsoluteCurrentDirectory());
|
||||
vfs = std::make_shared<SubdirFilesystem>(
|
||||
LocalFS,
|
||||
Tesses::Framework::Filesystem::VFSPath::GetAbsoluteCurrentDirectory());
|
||||
|
||||
std::shared_ptr<CallbackServer> cb = std::make_shared<CallbackServer>([](ServerContext& ctx)->bool{
|
||||
if(ctx.path == "/")
|
||||
{
|
||||
std::shared_ptr<CallbackServer> cb = std::make_shared<
|
||||
CallbackServer>([](ServerContext &ctx) -> bool {
|
||||
if (ctx.path == "/") {
|
||||
ctx.WithMimeType("text/html")
|
||||
.SendText(
|
||||
"<!DOCTYPE html>"
|
||||
"<html>"
|
||||
"<head><meta charset=\"UTF-8\"><title>AnonyDump</title></head>"
|
||||
"<body>"
|
||||
"<h1>AnonyDump</h1>"
|
||||
"<a href=\"./files/\">Files</a>"
|
||||
"<form action=\"./upload\" method=\"post\" enctype=\"multipart/form-data\" accept-charset=\"UTF-8\">"
|
||||
"<input type=\"file\" name=\"file\" multiple>"
|
||||
"<input type=\"submit\" value=\"Upload\">"
|
||||
"</form>"
|
||||
"</body>"
|
||||
"</html>"
|
||||
);
|
||||
.SendText(
|
||||
"<!DOCTYPE html>"
|
||||
"<html>"
|
||||
"<head><meta "
|
||||
"charset=\"UTF-8\"><title>AnonyDrop</title><meta "
|
||||
"name=\"color-scheme\" content=\"dark light\"></head>"
|
||||
"<body>"
|
||||
"<h1>AnonyDrop</h1>"
|
||||
"<a href=\"./files/\">Files</a>"
|
||||
"<form action=\"./upload\" method=\"post\" "
|
||||
"enctype=\"multipart/form-data\" accept-charset=\"UTF-8\">"
|
||||
"<input type=\"file\" name=\"file\" multiple>"
|
||||
"<input type=\"submit\" value=\"Upload\">"
|
||||
"</form>"
|
||||
"</body>"
|
||||
"</html>");
|
||||
|
||||
return true;
|
||||
}
|
||||
else if(ctx.path == "/upload")
|
||||
{
|
||||
if(ctx.NeedToParseFormData())
|
||||
{
|
||||
ctx.ParseFormData([](std::string mime, std::string filename,std::string name)->std::shared_ptr<Stream> {
|
||||
if(name != "file") return nullptr;
|
||||
VFSPath path("/"+filename);
|
||||
auto strm = vfs->OpenFile(path,"wb");
|
||||
|
||||
return strm;
|
||||
});
|
||||
} else if (ctx.path == "/upload") {
|
||||
if (ctx.NeedToParseFormData()) {
|
||||
ctx.ParseFormData(
|
||||
[](std::string mime, std::string filename,
|
||||
std::string name) -> std::shared_ptr<Stream> {
|
||||
if (name != "file")
|
||||
return nullptr;
|
||||
VFSPath path("/" + filename);
|
||||
auto strm = vfs->OpenFile(path, "wb");
|
||||
|
||||
return strm;
|
||||
});
|
||||
ctx.WithMimeType("text/html")
|
||||
.SendText(
|
||||
"<!DOCTYPE html>"
|
||||
"<html>"
|
||||
"<head><title>AnonyDump - Uploaded successfully</title>"
|
||||
"<body>"
|
||||
"<h1>Uploaded successfully</h1>"
|
||||
"<a href=\"./\">Back</a>"
|
||||
|
||||
"</form>"
|
||||
"</body>"
|
||||
"</html>"
|
||||
);
|
||||
.SendText("<!DOCTYPE html>"
|
||||
"<html>"
|
||||
"<head><meta name=\"color-scheme\" "
|
||||
"content=\"dark light\"><title>AnonyDrop - "
|
||||
"Uploaded successfully</title></head>"
|
||||
"<body>"
|
||||
"<h1>Uploaded successfully</h1>"
|
||||
"<a href=\"./\">Back</a>"
|
||||
|
||||
"</body>"
|
||||
"</html>");
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
ctx.statusCode= Tesses::Framework::Http::BadRequest;
|
||||
} else {
|
||||
ctx.statusCode = Tesses::Framework::Http::BadRequest;
|
||||
ctx.WithMimeType("text/html")
|
||||
.SendText(
|
||||
"<!DOCTYPE html>"
|
||||
"<html>"
|
||||
"<head><title>AnonyDump - Error: Must contain multipart and POST</title>"
|
||||
"<body>"
|
||||
"<h1>Error: Must contain multipart and POST</h1>"
|
||||
"<a href=\"./\">Back</a>"
|
||||
|
||||
"</form>"
|
||||
"</body>"
|
||||
"</html>"
|
||||
);
|
||||
.SendText("<!DOCTYPE html>"
|
||||
"<html>"
|
||||
"<head><title>AnonyDump - Error: Must contain "
|
||||
"multipart and POST</title>"
|
||||
"<body>"
|
||||
"<h1>Error: Must contain multipart and POST</h1>"
|
||||
"<a href=\"./\">Back</a>"
|
||||
|
||||
"</form>"
|
||||
"</body>"
|
||||
"</html>");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
auto mountable = std::make_shared<Tesses::Framework::Http::MountableServer>(cb);
|
||||
mountable->Mount("/files/",std::make_shared<FileServer>(vfs,true,false));
|
||||
auto mountable =
|
||||
std::make_shared<Tesses::Framework::Http::MountableServer>(cb);
|
||||
mountable->Mount("/files/", std::make_shared<FileServer>(vfs, true, false));
|
||||
|
||||
HttpServer srv(4985,mountable);
|
||||
HttpServer srv(4985, mountable);
|
||||
srv.StartAccepting();
|
||||
|
||||
TF_RunEventLoop();
|
||||
|
||||
TF_Quit();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
#include "TessesFramework/TessesFramework.hpp"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if(argc < 4)
|
||||
{
|
||||
std::cout << "USAGE: " << argv[0] << " BINARYFILE VARNAME HEADERFILE" << std::endl;
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 4) {
|
||||
std::cout << "USAGE: " << argv[0] << " BINARYFILE VARNAME HEADERFILE"
|
||||
<< std::endl;
|
||||
return 0;
|
||||
}
|
||||
auto fs=std::make_shared<Tesses::Framework::Streams::FileStream>(argv[1],"rb");
|
||||
if(!fs->CanRead()) return 1;
|
||||
auto writer = std::make_shared<Tesses::Framework::TextStreams::StreamWriter>(argv[3]);
|
||||
auto fs =
|
||||
std::make_shared<Tesses::Framework::Streams::FileStream>(argv[1], "rb");
|
||||
if (!fs->CanRead())
|
||||
return 1;
|
||||
auto writer =
|
||||
std::make_shared<Tesses::Framework::TextStreams::StreamWriter>(argv[3]);
|
||||
Tesses::Framework::Text::GenerateCHeaderFile(fs, argv[2], writer);
|
||||
return 0;
|
||||
}
|
||||
@@ -3,20 +3,18 @@ using namespace Tesses::Framework;
|
||||
using namespace Tesses::Framework::BitTorrent;
|
||||
using namespace Tesses::Framework::Serialization::Bencode;
|
||||
using namespace Tesses::Framework::Filesystem;
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
TF_Init();
|
||||
if(argc < 2)
|
||||
{
|
||||
printf("USAGE: %s torrent_file\n",argv[0]);
|
||||
if (argc < 2) {
|
||||
printf("USAGE: %s torrent_file\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
auto strm = LocalFS->OpenFile((std::string)argv[1],"rb");
|
||||
auto strm = LocalFS->OpenFile((std::string)argv[1], "rb");
|
||||
auto data = Bencode::Load(strm);
|
||||
if(std::holds_alternative<BeDictionary>(data)){
|
||||
std::get<BeDictionary>(data).SetValue("url-list",BeUndefined());
|
||||
if (std::holds_alternative<BeDictionary>(data)) {
|
||||
std::get<BeDictionary>(data).SetValue("url-list", BeUndefined());
|
||||
}
|
||||
strm = LocalFS->OpenFile((std::string)argv[1],"wb");
|
||||
Bencode::Save(strm,data);
|
||||
strm = LocalFS->OpenFile((std::string)argv[1], "wb");
|
||||
Bencode::Save(strm, data);
|
||||
return 0;
|
||||
}
|
||||
@@ -2,44 +2,34 @@
|
||||
using namespace Tesses::Framework::Streams;
|
||||
using namespace Tesses::Framework::Serialization::Json;
|
||||
using namespace Tesses::Framework::TextStreams;
|
||||
std::shared_ptr<FileStream> OpenWrite(std::string dest)
|
||||
{
|
||||
if(dest == "-")
|
||||
{
|
||||
return std::make_shared<FileStream>(stdout,false,"w");
|
||||
}
|
||||
else
|
||||
{
|
||||
auto strm = std::make_shared<FileStream>(dest,"w");
|
||||
if(!strm->CanWrite())
|
||||
{
|
||||
std::shared_ptr<FileStream> OpenWrite(std::string dest) {
|
||||
if (dest == "-") {
|
||||
return std::make_shared<FileStream>(stdout, false, "w");
|
||||
} else {
|
||||
auto strm = std::make_shared<FileStream>(dest, "w");
|
||||
if (!strm->CanWrite()) {
|
||||
return nullptr;
|
||||
}
|
||||
return strm;
|
||||
}
|
||||
}
|
||||
std::shared_ptr<FileStream> OpenRead(std::string src)
|
||||
{
|
||||
if(src == "-")
|
||||
{
|
||||
return std::make_shared<FileStream>(stdin,false,"r");
|
||||
}
|
||||
else
|
||||
{
|
||||
auto strm = std::make_shared<FileStream>(src,"r");
|
||||
if(!strm->CanRead())
|
||||
{
|
||||
std::shared_ptr<FileStream> OpenRead(std::string src) {
|
||||
if (src == "-") {
|
||||
return std::make_shared<FileStream>(stdin, false, "r");
|
||||
} else {
|
||||
auto strm = std::make_shared<FileStream>(src, "r");
|
||||
if (!strm->CanRead()) {
|
||||
return nullptr;
|
||||
}
|
||||
return strm;
|
||||
}
|
||||
}
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if(argc < 3)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 3) {
|
||||
std::cout << "USAGE: " << argv[0] << " SRC DEST" << std::endl;
|
||||
std::cout << "SRC: doc json file or - for stdin to convert to pretty json" << std::endl;
|
||||
std::cout
|
||||
<< "SRC: doc json file or - for stdin to convert to pretty json"
|
||||
<< std::endl;
|
||||
std::cout << "DEST: prettied file or - for stdout" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -47,14 +37,12 @@ int main(int argc, char** argv)
|
||||
|
||||
auto dest = OpenWrite(argv[2]);
|
||||
|
||||
if(src == nullptr)
|
||||
{
|
||||
|
||||
if (src == nullptr) {
|
||||
|
||||
std::cerr << "ERROR: Input could not be read" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
if(dest == nullptr)
|
||||
{
|
||||
if (dest == nullptr) {
|
||||
std::cerr << "ERROR: Output could not be read" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
@@ -65,6 +53,5 @@ int main(int argc, char** argv)
|
||||
auto str = reader.ReadToEnd();
|
||||
writer.WriteLine(Json::Encode(Json::DocDecode(str)));
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -3,25 +3,22 @@
|
||||
using namespace Tesses::Framework;
|
||||
using namespace Tesses::Framework::Streams;
|
||||
using namespace Tesses::Framework::Http;
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if(argc < 3)
|
||||
{
|
||||
printf("USAGE: %s <url> <path>\n",argv[0]);
|
||||
printf("USAGE: %s <unixSocket> <url> <path>\n",argv[0]);
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 3) {
|
||||
printf("USAGE: %s <url> <path>\n", argv[0]);
|
||||
printf("USAGE: %s <unixSocket> <url> <path>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
if(argc >= 4)
|
||||
{
|
||||
if (argc >= 4) {
|
||||
std::string unixSocket = argv[1];
|
||||
std::string url = argv[2];
|
||||
std::string path = argv[3];
|
||||
Tesses::Framework::Http::DownloadUnixSocketToFileSimple(unixSocket,url,path);
|
||||
}
|
||||
else {
|
||||
std::string path = argv[3];
|
||||
Tesses::Framework::Http::DownloadUnixSocketToFileSimple(unixSocket, url,
|
||||
path);
|
||||
} else {
|
||||
std::string path = argv[2];
|
||||
Tesses::Framework::Http::DownloadToFileSimple(argv[1],path);
|
||||
Tesses::Framework::Http::DownloadToFileSimple(argv[1], path);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -6,121 +6,106 @@ using namespace Tesses::Framework::Streams;
|
||||
using namespace Tesses::Framework::TextStreams;
|
||||
using namespace Tesses::Framework::Threading;
|
||||
|
||||
void print_help(const char* name)
|
||||
{
|
||||
printf("Tesses FileServer\nUSAGE: %s [OPTIONS] <dir>\n",name);
|
||||
printf("OPTIONS:\n-p PORT, --port PORT: Change port from 9852\n-l, --listing: Enable listing\n-s, --spa: Enable SPA mode (send \"/\" body instead of not found)\n-c, --cgi-bin: Enable cgi (common gateway interface) support (specify a folder like /cgi-bin)\n-a, --cgi-admin: cgi admin email\n-w, --cgi-working: working directory for cgi scripts\n-h, --help: This Screen\n");
|
||||
void print_help(const char *name) {
|
||||
printf("Tesses FileServer\nUSAGE: %s [OPTIONS] <dir>\n", name);
|
||||
printf("OPTIONS:\n-p PORT, --port PORT: Change port from 9852\n-l, "
|
||||
"--listing: Enable listing\n-s, --spa: Enable SPA mode (send \"/\" "
|
||||
"body instead of not found)\n-c, --cgi-bin: Enable cgi (common "
|
||||
"gateway interface) support (specify a folder like /cgi-bin)\n-a, "
|
||||
"--cgi-admin: cgi admin email\n-w, --cgi-working: working directory "
|
||||
"for cgi scripts\n-h, --help: This Screen\n");
|
||||
exit(1);
|
||||
}
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
try {
|
||||
|
||||
TF_InitWithConsole();
|
||||
TF_LOG("INIT");
|
||||
const char* directory = "wwwroot";
|
||||
bool spa=false;
|
||||
bool allowListing = false;
|
||||
std::optional<std::string> cgi_bin;
|
||||
std::optional<std::string> cgi_admin;
|
||||
std::optional<Tesses::Framework::Filesystem::VFSPath> cgi_workdir;
|
||||
uint16_t port = 9852L;
|
||||
|
||||
for(int i = 1; i < argc; i++)
|
||||
{
|
||||
if(strcmp(argv[i],"--help") == 0 || strcmp(argv[i],"-h") == 0)
|
||||
{
|
||||
print_help(argv[0]);
|
||||
}
|
||||
else if(strcmp(argv[i], "-c") == 0 || strcmp(argv[i],"--cgi-bin") == 0)
|
||||
{
|
||||
if(i+1>=argc)
|
||||
{
|
||||
printf("ERROR: Not enough arguments for cgi-bin\n");
|
||||
print_help(argv[0]);
|
||||
}
|
||||
else {
|
||||
printf("CGI is enabled\n");
|
||||
cgi_bin = argv[++i];
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[i], "-a") == 0 || strcmp(argv[i],"--cgi-admin") == 0)
|
||||
{
|
||||
if(i+1>=argc)
|
||||
{
|
||||
printf("ERROR: Not enough arguments for cgi-admin\n");
|
||||
print_help(argv[0]);
|
||||
}
|
||||
else {
|
||||
cgi_admin = argv[++i];
|
||||
}
|
||||
}
|
||||
else if(strcmp(argv[i], "-w") == 0 || strcmp(argv[i],"--cgi-working") == 0)
|
||||
{
|
||||
if(i+1>=argc)
|
||||
{
|
||||
printf("ERROR: Not enough arguments for cgi-working\n");
|
||||
print_help(argv[0]);
|
||||
}
|
||||
else {
|
||||
cgi_workdir = (Tesses::Framework::Filesystem::VFSPath)argv[++i];
|
||||
}
|
||||
}
|
||||
|
||||
else if(strcmp(argv[i], "-l") == 0 || strcmp(argv[i], "--listing") == 0)
|
||||
{
|
||||
allowListing = true;
|
||||
}
|
||||
else if(strcmp(argv[i],"-s") == 0 || strcmp(argv[i],"--spa") == 0)
|
||||
{
|
||||
spa=true;
|
||||
}
|
||||
else if(strcmp(argv[i],"-p") == 0 || strcmp(argv[i],"--port") == 0)
|
||||
{
|
||||
if(i+1>=argc)
|
||||
{
|
||||
printf("ERROR: Not enough arguments for PORT\n");
|
||||
print_help(argv[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
TF_InitWithConsole();
|
||||
TF_LOG("INIT");
|
||||
const char *directory = "wwwroot";
|
||||
bool spa = false;
|
||||
bool allowListing = false;
|
||||
std::optional<std::string> cgi_bin;
|
||||
std::optional<std::string> cgi_admin;
|
||||
std::optional<Tesses::Framework::Filesystem::VFSPath> cgi_workdir;
|
||||
uint16_t port = 9852L;
|
||||
|
||||
port = (uint16_t)std::stoul(argv[++i]);
|
||||
for (int i = 1; i < argc; i++) {
|
||||
if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) {
|
||||
print_help(argv[0]);
|
||||
} else if (strcmp(argv[i], "-c") == 0 ||
|
||||
strcmp(argv[i], "--cgi-bin") == 0) {
|
||||
if (i + 1 >= argc) {
|
||||
printf("ERROR: Not enough arguments for cgi-bin\n");
|
||||
print_help(argv[0]);
|
||||
} else {
|
||||
printf("CGI is enabled\n");
|
||||
cgi_bin = argv[++i];
|
||||
}
|
||||
} else if (strcmp(argv[i], "-a") == 0 ||
|
||||
strcmp(argv[i], "--cgi-admin") == 0) {
|
||||
if (i + 1 >= argc) {
|
||||
printf("ERROR: Not enough arguments for cgi-admin\n");
|
||||
print_help(argv[0]);
|
||||
} else {
|
||||
cgi_admin = argv[++i];
|
||||
}
|
||||
} else if (strcmp(argv[i], "-w") == 0 ||
|
||||
strcmp(argv[i], "--cgi-working") == 0) {
|
||||
if (i + 1 >= argc) {
|
||||
printf("ERROR: Not enough arguments for cgi-working\n");
|
||||
print_help(argv[0]);
|
||||
} else {
|
||||
cgi_workdir =
|
||||
(Tesses::Framework::Filesystem::VFSPath)argv[++i];
|
||||
}
|
||||
}
|
||||
|
||||
else if (strcmp(argv[i], "-l") == 0 ||
|
||||
strcmp(argv[i], "--listing") == 0) {
|
||||
allowListing = true;
|
||||
} else if (strcmp(argv[i], "-s") == 0 ||
|
||||
strcmp(argv[i], "--spa") == 0) {
|
||||
spa = true;
|
||||
} else if (strcmp(argv[i], "-p") == 0 ||
|
||||
strcmp(argv[i], "--port") == 0) {
|
||||
if (i + 1 >= argc) {
|
||||
printf("ERROR: Not enough arguments for PORT\n");
|
||||
print_help(argv[0]);
|
||||
} else {
|
||||
|
||||
port = (uint16_t)std::stoul(argv[++i]);
|
||||
}
|
||||
} else {
|
||||
directory = argv[i];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
directory = argv[i];
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "In folder: " << std::filesystem::absolute(directory).string() << std::endl;
|
||||
std::shared_ptr<IHttpServer> http;
|
||||
|
||||
auto fs = std::make_shared<FileServer>(directory,allowListing, spa);
|
||||
if(cgi_bin)
|
||||
{
|
||||
Tesses::Framework::Filesystem::VFSPath dir = *cgi_bin;
|
||||
dir.relative = true;
|
||||
auto svr = std::make_shared<MountableServer>(fs);
|
||||
auto cgi = std::make_shared<CGIServer>(std::filesystem::absolute(directory).string() / dir);
|
||||
cgi->adminEmail = cgi_admin;
|
||||
cgi->workingDirectory = cgi_workdir;
|
||||
svr->Mount(*cgi_bin, cgi);
|
||||
http = svr;
|
||||
}
|
||||
else {
|
||||
http = fs;
|
||||
}
|
||||
|
||||
HttpServer server(port,http);
|
||||
server.StartAccepting();
|
||||
TF_RunEventLoop();
|
||||
std::cout << "Closing server" << std::endl;
|
||||
TF_Quit();
|
||||
}catch(std::exception& ex)
|
||||
{
|
||||
TF_LOG(ex.what());
|
||||
}
|
||||
std::cout << "In folder: "
|
||||
<< std::filesystem::absolute(directory).string() << std::endl;
|
||||
std::shared_ptr<IHttpServer> http;
|
||||
|
||||
auto fs = std::make_shared<FileServer>(directory, allowListing, spa);
|
||||
if (cgi_bin) {
|
||||
Tesses::Framework::Filesystem::VFSPath dir = *cgi_bin;
|
||||
dir.relative = true;
|
||||
auto svr = std::make_shared<MountableServer>(fs);
|
||||
auto cgi = std::make_shared<CGIServer>(
|
||||
std::filesystem::absolute(directory).string() / dir);
|
||||
cgi->adminEmail = cgi_admin;
|
||||
cgi->workingDirectory = cgi_workdir;
|
||||
svr->Mount(*cgi_bin, cgi);
|
||||
http = svr;
|
||||
} else {
|
||||
http = fs;
|
||||
}
|
||||
|
||||
HttpServer server(port, http);
|
||||
server.StartAccepting();
|
||||
TF_RunEventLoop();
|
||||
std::cout << "Closing server" << std::endl;
|
||||
TF_Quit();
|
||||
} catch (std::exception &ex) {
|
||||
TF_LOG(ex.what());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2,44 +2,33 @@
|
||||
using namespace Tesses::Framework::Streams;
|
||||
using namespace Tesses::Framework::Serialization::Json;
|
||||
using namespace Tesses::Framework::TextStreams;
|
||||
std::shared_ptr<FileStream> OpenWrite(std::string dest)
|
||||
{
|
||||
if(dest == "-")
|
||||
{
|
||||
return std::make_shared<FileStream>(stdout,false,"w");
|
||||
}
|
||||
else
|
||||
{
|
||||
auto strm = std::make_shared<FileStream>(dest,"w");
|
||||
if(!strm->CanWrite())
|
||||
{
|
||||
std::shared_ptr<FileStream> OpenWrite(std::string dest) {
|
||||
if (dest == "-") {
|
||||
return std::make_shared<FileStream>(stdout, false, "w");
|
||||
} else {
|
||||
auto strm = std::make_shared<FileStream>(dest, "w");
|
||||
if (!strm->CanWrite()) {
|
||||
return nullptr;
|
||||
}
|
||||
return strm;
|
||||
}
|
||||
}
|
||||
std::shared_ptr<FileStream> OpenRead(std::string src)
|
||||
{
|
||||
if(src == "-")
|
||||
{
|
||||
return std::make_shared<FileStream>(stdin,false,"r");
|
||||
}
|
||||
else
|
||||
{
|
||||
auto strm = std::make_shared<FileStream>(src,"r");
|
||||
if(!strm->CanRead())
|
||||
{
|
||||
std::shared_ptr<FileStream> OpenRead(std::string src) {
|
||||
if (src == "-") {
|
||||
return std::make_shared<FileStream>(stdin, false, "r");
|
||||
} else {
|
||||
auto strm = std::make_shared<FileStream>(src, "r");
|
||||
if (!strm->CanRead()) {
|
||||
return nullptr;
|
||||
}
|
||||
return strm;
|
||||
}
|
||||
}
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if(argc < 3)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 3) {
|
||||
std::cout << "USAGE: " << argv[0] << " SRC DEST" << std::endl;
|
||||
std::cout << "SRC: json file or - for stdin to convert to json doc" << std::endl;
|
||||
std::cout << "SRC: json file or - for stdin to convert to json doc"
|
||||
<< std::endl;
|
||||
std::cout << "DEST: json doc file or - for stdout" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -47,14 +36,12 @@ int main(int argc, char** argv)
|
||||
|
||||
auto dest = OpenWrite(argv[2]);
|
||||
|
||||
if(src == nullptr)
|
||||
{
|
||||
|
||||
if (src == nullptr) {
|
||||
|
||||
std::cerr << "ERROR: Input could not be read" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
if(dest == nullptr)
|
||||
{
|
||||
if (dest == nullptr) {
|
||||
std::cerr << "ERROR: Output could not be read" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
@@ -68,6 +55,5 @@ int main(int argc, char** argv)
|
||||
TryGetJToken(doc, docLs);
|
||||
writer.WriteLine(Json::DocEncode(docLs));
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -2,44 +2,33 @@
|
||||
using namespace Tesses::Framework::Streams;
|
||||
using namespace Tesses::Framework::Serialization::Json;
|
||||
using namespace Tesses::Framework::TextStreams;
|
||||
std::shared_ptr<FileStream> OpenWrite(std::string dest)
|
||||
{
|
||||
if(dest == "-")
|
||||
{
|
||||
return std::make_shared<FileStream>(stdout,false,"w");
|
||||
}
|
||||
else
|
||||
{
|
||||
auto strm = std::make_shared<FileStream>(dest,"w");
|
||||
if(!strm->CanWrite())
|
||||
{
|
||||
std::shared_ptr<FileStream> OpenWrite(std::string dest) {
|
||||
if (dest == "-") {
|
||||
return std::make_shared<FileStream>(stdout, false, "w");
|
||||
} else {
|
||||
auto strm = std::make_shared<FileStream>(dest, "w");
|
||||
if (!strm->CanWrite()) {
|
||||
return nullptr;
|
||||
}
|
||||
return strm;
|
||||
}
|
||||
}
|
||||
std::shared_ptr<FileStream> OpenRead(std::string src)
|
||||
{
|
||||
if(src == "-")
|
||||
{
|
||||
return std::make_shared<FileStream>(stdin,false,"r");
|
||||
}
|
||||
else
|
||||
{
|
||||
auto strm = std::make_shared<FileStream>(src,"r");
|
||||
if(!strm->CanRead())
|
||||
{
|
||||
std::shared_ptr<FileStream> OpenRead(std::string src) {
|
||||
if (src == "-") {
|
||||
return std::make_shared<FileStream>(stdin, false, "r");
|
||||
} else {
|
||||
auto strm = std::make_shared<FileStream>(src, "r");
|
||||
if (!strm->CanRead()) {
|
||||
return nullptr;
|
||||
}
|
||||
return strm;
|
||||
}
|
||||
}
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if(argc < 3)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 3) {
|
||||
std::cout << "USAGE: " << argv[0] << " SRC DEST" << std::endl;
|
||||
std::cout << "SRC: json file or - for stdin to make pretty" << std::endl;
|
||||
std::cout << "SRC: json file or - for stdin to make pretty"
|
||||
<< std::endl;
|
||||
std::cout << "DEST: prettied file or - for stdout" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -47,14 +36,12 @@ int main(int argc, char** argv)
|
||||
|
||||
auto dest = OpenWrite(argv[2]);
|
||||
|
||||
if(src == nullptr)
|
||||
{
|
||||
|
||||
if (src == nullptr) {
|
||||
|
||||
std::cerr << "ERROR: Input could not be read" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
if(dest == nullptr)
|
||||
{
|
||||
if (dest == nullptr) {
|
||||
std::cerr << "ERROR: Output could not be read" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
@@ -65,6 +52,5 @@ int main(int argc, char** argv)
|
||||
auto str = reader.ReadToEnd();
|
||||
writer.WriteLine(Json::Encode(Json::Decode(str)));
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -2,44 +2,33 @@
|
||||
using namespace Tesses::Framework::Streams;
|
||||
using namespace Tesses::Framework::Serialization::Json;
|
||||
using namespace Tesses::Framework::TextStreams;
|
||||
std::shared_ptr<FileStream> OpenWrite(std::string dest)
|
||||
{
|
||||
if(dest == "-")
|
||||
{
|
||||
return std::make_shared<FileStream>(stdout,false,"w");
|
||||
}
|
||||
else
|
||||
{
|
||||
auto strm = std::make_shared<FileStream>(dest,"w");
|
||||
if(!strm->CanWrite())
|
||||
{
|
||||
std::shared_ptr<FileStream> OpenWrite(std::string dest) {
|
||||
if (dest == "-") {
|
||||
return std::make_shared<FileStream>(stdout, false, "w");
|
||||
} else {
|
||||
auto strm = std::make_shared<FileStream>(dest, "w");
|
||||
if (!strm->CanWrite()) {
|
||||
return nullptr;
|
||||
}
|
||||
return strm;
|
||||
}
|
||||
}
|
||||
std::shared_ptr<FileStream> OpenRead(std::string src)
|
||||
{
|
||||
if(src == "-")
|
||||
{
|
||||
return std::make_shared<FileStream>(stdin,false,"r");
|
||||
}
|
||||
else
|
||||
{
|
||||
auto strm = std::make_shared<FileStream>(src,"r");
|
||||
if(!strm->CanRead())
|
||||
{
|
||||
std::shared_ptr<FileStream> OpenRead(std::string src) {
|
||||
if (src == "-") {
|
||||
return std::make_shared<FileStream>(stdin, false, "r");
|
||||
} else {
|
||||
auto strm = std::make_shared<FileStream>(src, "r");
|
||||
if (!strm->CanRead()) {
|
||||
return nullptr;
|
||||
}
|
||||
return strm;
|
||||
}
|
||||
}
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if(argc < 3)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 3) {
|
||||
std::cout << "USAGE: " << argv[0] << " SRC DEST" << std::endl;
|
||||
std::cout << "SRC: json file or - for stdin to make unpretty" << std::endl;
|
||||
std::cout << "SRC: json file or - for stdin to make unpretty"
|
||||
<< std::endl;
|
||||
std::cout << "DEST: unprettied file or - for stdout" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -47,14 +36,12 @@ int main(int argc, char** argv)
|
||||
|
||||
auto dest = OpenWrite(argv[2]);
|
||||
|
||||
if(src == nullptr)
|
||||
{
|
||||
if (src == nullptr) {
|
||||
std::cerr << "ERROR: Input could not be read" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
if(dest == nullptr)
|
||||
{
|
||||
|
||||
if (dest == nullptr) {
|
||||
|
||||
std::cerr << "ERROR: Output could not be read" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
@@ -63,8 +50,7 @@ int main(int argc, char** argv)
|
||||
StreamWriter writer(dest);
|
||||
|
||||
auto str = reader.ReadToEnd();
|
||||
writer.WriteLine(Json::Encode(Json::Decode(str),false));
|
||||
|
||||
writer.WriteLine(Json::Encode(Json::Decode(str), false));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
#include "TessesFramework/TessesFramework.hpp"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if(argc < 2)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 2) {
|
||||
|
||||
std::cout << "USAGE: " << argv[0] << " times" << std::endl;
|
||||
std::cout << "USAGE: " << argv[0] << " times max" << std::endl;
|
||||
@@ -11,25 +9,19 @@ int main(int argc, char** argv)
|
||||
return 0;
|
||||
}
|
||||
Tesses::Framework::Random random;
|
||||
int times=std::atoi(argv[1]);
|
||||
if(argc > 2)
|
||||
{
|
||||
int times = std::atoi(argv[1]);
|
||||
if (argc > 2) {
|
||||
int32_t min = 0;
|
||||
int32_t max = std::stoi(argv[2]);
|
||||
if(argc > 3)
|
||||
{
|
||||
if (argc > 3) {
|
||||
min = max;
|
||||
max = std::stoi(argv[3]);
|
||||
|
||||
}
|
||||
for(int i = 0; i < times; i++)
|
||||
{
|
||||
std::cout << random.Next(min,max) << std::endl;
|
||||
for (int i = 0; i < times; i++) {
|
||||
std::cout << random.Next(min, max) << std::endl;
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(int i = 0; i < times; i++)
|
||||
{
|
||||
} else {
|
||||
for (int i = 0; i < times; i++) {
|
||||
std::cout << random.Next() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
138
apps/tshell.cpp
138
apps/tshell.cpp
@@ -1,124 +1,110 @@
|
||||
#include "TessesFramework/TessesFramework.hpp"
|
||||
#include "TessesFramework/Platform/Process.hpp"
|
||||
#include "TessesFramework/TessesFramework.hpp"
|
||||
using namespace Tesses::Framework;
|
||||
using namespace Tesses::Framework::Platform;
|
||||
using namespace Tesses::Framework::TextStreams;
|
||||
using namespace Tesses::Framework::Filesystem;
|
||||
|
||||
void split_command(std::string cmd, std::vector<std::string>& args)
|
||||
{
|
||||
bool inStr=false;
|
||||
std::string cur={};
|
||||
auto flush=[&]()->void {
|
||||
if(cur.empty()) return;
|
||||
void split_command(std::string cmd, std::vector<std::string> &args) {
|
||||
bool inStr = false;
|
||||
std::string cur = {};
|
||||
auto flush = [&]() -> void {
|
||||
if (cur.empty())
|
||||
return;
|
||||
args.push_back(cur);
|
||||
cur={};
|
||||
cur = {};
|
||||
};
|
||||
for(size_t i = 0; i < cmd.size(); i++)
|
||||
{
|
||||
if(inStr)
|
||||
{
|
||||
if(cmd[i] == '\"') inStr=false;
|
||||
else if(cmd[i] == '\\')
|
||||
{
|
||||
for (size_t i = 0; i < cmd.size(); i++) {
|
||||
if (inStr) {
|
||||
if (cmd[i] == '\"')
|
||||
inStr = false;
|
||||
else if (cmd[i] == '\\') {
|
||||
i++;
|
||||
if(i < cmd.size())
|
||||
{
|
||||
if (i < cmd.size()) {
|
||||
cmd.push_back(cmd[i]);
|
||||
}
|
||||
}
|
||||
else cur.push_back(cmd[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(cmd[i] == ' ') flush();
|
||||
else if(cmd[i] == '\"') {
|
||||
inStr=true;
|
||||
}
|
||||
else {
|
||||
} else
|
||||
cur.push_back(cmd[i]);
|
||||
} else {
|
||||
if (cmd[i] == ' ')
|
||||
flush();
|
||||
else if (cmd[i] == '\"') {
|
||||
inStr = true;
|
||||
} else {
|
||||
cur.push_back(cmd[i]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
flush();
|
||||
}
|
||||
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
TF_Init();
|
||||
|
||||
|
||||
|
||||
while(true)
|
||||
{
|
||||
std::cout << VFSPath::GetAbsoluteCurrentDirectory().ToString() << "$ ";
|
||||
|
||||
while (true) {
|
||||
std::cout << VFSPath::GetAbsoluteCurrentDirectory().ToString() << "$ ";
|
||||
|
||||
std::string text;
|
||||
StdIn().ReadLine(text);
|
||||
std::vector<std::string> args;
|
||||
split_command(text,args);
|
||||
if(args.empty()) continue;
|
||||
if(args[0] == "exit") break;
|
||||
else if(args[0] == "echo") { if(args.size() > 1) std::cout << args[1] << std::endl;}
|
||||
else if(args[0] == "cd") {
|
||||
if(args.size() < 2)
|
||||
{
|
||||
VFSPath::SetAbsoluteCurrentDirectory(Environment::SpecialFolders::GetHomeFolder());
|
||||
}
|
||||
else {
|
||||
split_command(text, args);
|
||||
if (args.empty())
|
||||
continue;
|
||||
if (args[0] == "exit")
|
||||
break;
|
||||
else if (args[0] == "echo") {
|
||||
if (args.size() > 1)
|
||||
std::cout << args[1] << std::endl;
|
||||
} else if (args[0] == "cd") {
|
||||
if (args.size() < 2) {
|
||||
VFSPath::SetAbsoluteCurrentDirectory(
|
||||
Environment::SpecialFolders::GetHomeFolder());
|
||||
} else {
|
||||
VFSPath::SetAbsoluteCurrentDirectory(args[1]);
|
||||
}
|
||||
}
|
||||
else if(args[0] == "printargs")
|
||||
{
|
||||
for(size_t i = 1; i < args.size(); i++)
|
||||
{
|
||||
std::cout << "\"" << Http::HttpUtils::Replace(args[i],"\"","\\\"") << "\"" << std::endl;
|
||||
} else if (args[0] == "printargs") {
|
||||
for (size_t i = 1; i < args.size(); i++) {
|
||||
std::cout << "\""
|
||||
<< Http::HttpUtils::Replace(args[i], "\"", "\\\"")
|
||||
<< "\"" << std::endl;
|
||||
}
|
||||
}
|
||||
else if (args[0] == "sigtermtest")
|
||||
{
|
||||
if (args.size() < 2) continue;
|
||||
} else if (args[0] == "sigtermtest") {
|
||||
if (args.size() < 2)
|
||||
continue;
|
||||
std::vector<std::string> args2(args.begin() + 1, args.end());
|
||||
|
||||
auto path = Environment::GetRealExecutablePath(args2[0]);
|
||||
Platform::Process p(path.ToString(), args2);
|
||||
if (p.Start())
|
||||
{
|
||||
if (p.Start()) {
|
||||
std::cout << "Press enter to sigterm" << std::endl;
|
||||
StdIn().ReadLine();
|
||||
p.Kill(SIGTERM);
|
||||
}
|
||||
}
|
||||
else if(args[0] == "rstdi")
|
||||
{
|
||||
if(args.size()<3) continue;
|
||||
std::vector<std::string> args2(args.begin()+2,args.end());
|
||||
auto f = LocalFS->OpenFile(args[1],"rb");
|
||||
if(f != nullptr)
|
||||
{
|
||||
} else if (args[0] == "rstdi") {
|
||||
if (args.size() < 3)
|
||||
continue;
|
||||
std::vector<std::string> args2(args.begin() + 2, args.end());
|
||||
auto f = LocalFS->OpenFile(args[1], "rb");
|
||||
if (f != nullptr) {
|
||||
auto path = Environment::GetRealExecutablePath(args2[0]);
|
||||
Platform::Process p(path.ToString(),args2);
|
||||
p.redirectStdIn=true;
|
||||
if(p.Start())
|
||||
{
|
||||
Platform::Process p(path.ToString(), args2);
|
||||
p.redirectStdIn = true;
|
||||
if (p.Start()) {
|
||||
auto strm = p.GetStdinStream();
|
||||
f->CopyTo(strm);
|
||||
|
||||
|
||||
p.CloseStdInNow();
|
||||
p.WaitForExit();
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
auto path = Environment::GetRealExecutablePath(args[0]);
|
||||
Platform::Process p(path.ToString(),args);
|
||||
Platform::Process p(path.ToString(), args);
|
||||
if (p.Start())
|
||||
p.WaitForExit();
|
||||
p.WaitForExit();
|
||||
else
|
||||
std::cout << "Failed To Run Process: " << path.ToString() << std::endl;
|
||||
std::cout << "Failed To Run Process: " << path.ToString()
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,15 +3,12 @@
|
||||
using namespace Tesses::Framework;
|
||||
using namespace Tesses::Framework::Date;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
TF_Init();
|
||||
DateTime dt=DateTime::Now();
|
||||
//dt = dt.ToLocal();
|
||||
if(argc > 1)
|
||||
{
|
||||
if(strcmp(argv[1],"--help") == 0)
|
||||
{
|
||||
DateTime dt = DateTime::Now();
|
||||
// dt = dt.ToLocal();
|
||||
if (argc > 1) {
|
||||
if (strcmp(argv[1], "--help") == 0) {
|
||||
/*
|
||||
case 'r':
|
||||
{
|
||||
@@ -34,15 +31,15 @@ int main(int argc, char** argv)
|
||||
break;
|
||||
case 'T':
|
||||
{
|
||||
|
||||
|
||||
text.append(Http::HttpUtils::LeftPad(std::to_string(hour),2,'0'));
|
||||
text.push_back(':');
|
||||
text.append(Http::HttpUtils::LeftPad(std::to_string(minute),2,'0'));
|
||||
text.push_back(':');
|
||||
text.append(Http::HttpUtils::LeftPad(std::to_string(second),2,'0'));
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
case 'u':
|
||||
{
|
||||
@@ -53,7 +50,7 @@ int main(int argc, char** argv)
|
||||
break;
|
||||
case 'w':
|
||||
{
|
||||
|
||||
|
||||
text.append(std::to_string(weekday));
|
||||
}
|
||||
break;
|
||||
@@ -72,14 +69,13 @@ int main(int argc, char** argv)
|
||||
text.append(Http::HttpUtils::LeftPad(std::to_string(second),2,'0'));
|
||||
text.push_back(' ');
|
||||
text.append(Http::HttpUtils::LeftPad(std::to_string(year),4,'0'));
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
break;
|
||||
case 'C':
|
||||
text.append(Http::HttpUtils::LeftPad(std::to_string(year / 100),2,'0'));
|
||||
break;
|
||||
case 'Y':
|
||||
text.append(Http::HttpUtils::LeftPad(std::to_string(year
|
||||
/ 100),2,'0')); break; case 'Y':
|
||||
text.append(Http::HttpUtils::LeftPad(std::to_string(year),4,'0'));
|
||||
break;
|
||||
case 'p':
|
||||
@@ -90,7 +86,7 @@ int main(int argc, char** argv)
|
||||
auto hours = hour % 12;
|
||||
if(hours == 0) hours=12;
|
||||
text.append(Http::HttpUtils::LeftPad(std::to_string(hours),2,'0'));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'h':
|
||||
case 'b':
|
||||
@@ -110,24 +106,37 @@ int main(int argc, char** argv)
|
||||
break;
|
||||
*/
|
||||
std::cout << argv[0] << " <fmt>" << std::endl;
|
||||
std::cout << "The fmt is for DateTime::ToString(fmt) just like strftime but just these are supported:" << std::endl;
|
||||
std::cout << "%a: weekday short eg " << dt.ToString("%a") << std::endl;
|
||||
std::cout << "%A: weekday long eg " << dt.ToString("%A") << std::endl;
|
||||
std::cout << "%S: seconds with leading zeros eg " << dt.ToString("%S") << std::endl;
|
||||
std::cout << "%m: month with leading zeros eg " << dt.ToString("%m") << std::endl;
|
||||
std::cout << "%d: day with leading zeros eg " << dt.ToString("%d") << std::endl;
|
||||
std::cout << "%e: day with leading spaces eg " << dt.ToString("%e") << std::endl;
|
||||
std::cout << "%M: minute with leading zeros eg " << dt.ToString("%M") << std::endl;
|
||||
std::cout << "%H: 24 hour with leading zeros eg " << dt.ToString("%H") << std::endl;
|
||||
std::cout << "%F: %Y-%m-%d like this " << dt.ToString("%F") << std::endl;
|
||||
std::cout << "%D: %m/%d/%y like this " << dt.ToString("%D") << std::endl;
|
||||
std::cout << "%y: year two digits eg " << dt.ToString("%y") << std::endl;
|
||||
std::cout << "%Y: year four digits eg " << dt.ToString("%Y") << std::endl;
|
||||
std::cout << "The fmt is for DateTime::ToString(fmt) just like "
|
||||
"strftime but just these are supported:"
|
||||
<< std::endl;
|
||||
std::cout << "%a: weekday short eg " << dt.ToString("%a")
|
||||
<< std::endl;
|
||||
std::cout << "%A: weekday long eg " << dt.ToString("%A")
|
||||
<< std::endl;
|
||||
std::cout << "%S: seconds with leading zeros eg "
|
||||
<< dt.ToString("%S") << std::endl;
|
||||
std::cout << "%m: month with leading zeros eg " << dt.ToString("%m")
|
||||
<< std::endl;
|
||||
std::cout << "%d: day with leading zeros eg " << dt.ToString("%d")
|
||||
<< std::endl;
|
||||
std::cout << "%e: day with leading spaces eg " << dt.ToString("%e")
|
||||
<< std::endl;
|
||||
std::cout << "%M: minute with leading zeros eg "
|
||||
<< dt.ToString("%M") << std::endl;
|
||||
std::cout << "%H: 24 hour with leading zeros eg "
|
||||
<< dt.ToString("%H") << std::endl;
|
||||
std::cout << "%F: %Y-%m-%d like this " << dt.ToString("%F")
|
||||
<< std::endl;
|
||||
std::cout << "%D: %m/%d/%y like this " << dt.ToString("%D")
|
||||
<< std::endl;
|
||||
std::cout << "%y: year two digits eg " << dt.ToString("%y")
|
||||
<< std::endl;
|
||||
std::cout << "%Y: year four digits eg " << dt.ToString("%Y")
|
||||
<< std::endl;
|
||||
return 1;
|
||||
}
|
||||
std::cout << dt.ToString(argv[1]) << std::endl;
|
||||
}
|
||||
else
|
||||
std::cout << dt.ToString() << std::endl;
|
||||
} else
|
||||
std::cout << dt.ToString() << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -6,61 +6,67 @@ using namespace Tesses::Framework::Filesystem;
|
||||
using namespace Tesses::Framework::Serialization::Bencode;
|
||||
using namespace Tesses::Framework::TextStreams;
|
||||
using namespace Tesses::Framework::BitTorrent;
|
||||
void usage(Args& args)
|
||||
{
|
||||
std::cout << "USAGE: " << args.filename << " [options] torrent_contents torrent_file.torrent" << std::endl << std::endl;
|
||||
void usage(Args &args) {
|
||||
std::cout << "USAGE: " << args.filename
|
||||
<< " [options] torrent_contents torrent_file.torrent" << std::endl
|
||||
<< std::endl;
|
||||
std::cout << "OPTIONS:" << std::endl;
|
||||
std::cout << "tracker: torrent tracker url (require at least one)" << std::endl;
|
||||
std::cout << "tracker: torrent tracker url (require at least one)"
|
||||
<< std::endl;
|
||||
std::cout << "webseed: url for web seeding" << std::endl;
|
||||
std::cout << "comment: set the comment" << std::endl;
|
||||
std::cout << "created_by: set the created by field, defaults to TessesFrameworkTorrent" << std::endl;
|
||||
std::cout << "piece_length: set the piece length, defaults to " + std::to_string(DEFAULT_PIECE_LENGTH) << std::endl << std::endl;
|
||||
std::cout << "created_by: set the created by field, defaults to "
|
||||
"TessesFrameworkTorrent"
|
||||
<< std::endl;
|
||||
std::cout << "piece_length: set the piece length, defaults to " +
|
||||
std::to_string(DEFAULT_PIECE_LENGTH)
|
||||
<< std::endl
|
||||
<< std::endl;
|
||||
std::cout << "FLAGS:" << std::endl;
|
||||
std::cout << "help: bring this help message up" << std::endl;
|
||||
std::cout << "private: enable private tracker flag" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
TF_Init();
|
||||
std::vector<BeString> webseeds;
|
||||
std::vector<BeString> trackers;
|
||||
bool isPrivate=false;
|
||||
bool isPrivate = false;
|
||||
int64_t pieceLength = DEFAULT_PIECE_LENGTH;
|
||||
std::string comment="";
|
||||
std::string comment = "";
|
||||
std::string created_by = "TessesFrameworkTorrent";
|
||||
|
||||
Args args(argc, argv);
|
||||
if(args.positional.size() < 2)
|
||||
if (args.positional.size() < 2)
|
||||
usage(args);
|
||||
|
||||
for(auto& opt : args.options)
|
||||
{
|
||||
if(opt.first == "tracker")
|
||||
for (auto &opt : args.options) {
|
||||
if (opt.first == "tracker")
|
||||
trackers.push_back(opt.second);
|
||||
else if(opt.first == "webseed")
|
||||
else if (opt.first == "webseed")
|
||||
webseeds.push_back(opt.second);
|
||||
else if(opt.first == "comment")
|
||||
else if (opt.first == "comment")
|
||||
comment = opt.second;
|
||||
else if(opt.first == "created_by")
|
||||
else if (opt.first == "created_by")
|
||||
created_by = opt.second;
|
||||
else if(opt.first == "piece_length")
|
||||
else if (opt.first == "piece_length")
|
||||
pieceLength = std::stoll(opt.second);
|
||||
}
|
||||
|
||||
for(auto& flag : args.flags)
|
||||
{
|
||||
if(flag == "help")
|
||||
for (auto &flag : args.flags) {
|
||||
if (flag == "help")
|
||||
usage(args);
|
||||
if(flag == "private")
|
||||
if (flag == "private")
|
||||
isPrivate = true;
|
||||
}
|
||||
|
||||
if(trackers.empty())
|
||||
|
||||
if (trackers.empty())
|
||||
usage(args);
|
||||
{
|
||||
auto torrent_file_stream = LocalFS->OpenFile(args.positional[1],"wb");
|
||||
TorrentFile::CreateTorrent(torrent_file_stream,trackers,webseeds,LocalFS, args.positional[0], isPrivate, pieceLength, comment, created_by);
|
||||
auto torrent_file_stream = LocalFS->OpenFile(args.positional[1], "wb");
|
||||
TorrentFile::CreateTorrent(torrent_file_stream, trackers, webseeds,
|
||||
LocalFS, args.positional[0], isPrivate,
|
||||
pieceLength, comment, created_by);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
25
apps/tuuid.cpp
Normal file
25
apps/tuuid.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "TessesFramework/Uuid.hpp"
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
// e794499c
|
||||
using namespace Tesses::Framework;
|
||||
|
||||
Uuid uuid = Uuid::Generate();
|
||||
/*uuid.time_low = 0xe794499c;
|
||||
uuid.time_mid = 0x823c;
|
||||
uuid.time_hi_and_version = 0x304c;
|
||||
uuid.clock_seq_hi_and_reserved = 0xa4;
|
||||
|
||||
uuid.clock_seq_low = 0x59;
|
||||
uuid.node[0] = 0x8f;
|
||||
uuid.node[1] = 0xdc;
|
||||
uuid.node[2] = 0xd9;
|
||||
uuid.node[3] = 0x60;
|
||||
uuid.node[4] = 0xb4;
|
||||
uuid.node[5] = 0xac;*/
|
||||
|
||||
std::cout << uuid.ToString(
|
||||
Tesses::Framework::UuidStringifyConfig::LowercaseNoCurly)
|
||||
<< std::endl;
|
||||
}
|
||||
@@ -4,18 +4,16 @@ using namespace Tesses::Framework;
|
||||
using namespace Tesses::Framework::Filesystem;
|
||||
using namespace Tesses::Framework::Filesystem::Literals;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
TF_Init();
|
||||
if(argc<2)
|
||||
{
|
||||
if (argc < 2) {
|
||||
std::cout << "USAGE " << argv[0] << " <file|dir>" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto watcher=FSWatcher::Create(LocalFS,VFSPath{argv[1]});
|
||||
auto watcher = FSWatcher::Create(LocalFS, VFSPath{argv[1]});
|
||||
watcher->events = FSWatcherEventType::All;
|
||||
watcher->event = [](FSWatcherEvent& evt)->void{
|
||||
watcher->event = [](FSWatcherEvent &evt) -> void {
|
||||
std::cout << evt.ToString() << std::endl;
|
||||
};
|
||||
watcher->SetEnabled(true);
|
||||
|
||||
13
changelog.md
Normal file
13
changelog.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# Changelog
|
||||
|
||||
## 0.0.4
|
||||
Overhaul cmake configuration, add console api, fix http code that caused issues with cgi-bin
|
||||
|
||||
## 0.0.3
|
||||
Add server sent events, change vfs structure, dark mode error pages and dark mode anonydrop
|
||||
|
||||
## 0.0.2
|
||||
Add UUIDs
|
||||
|
||||
## 0.0.1
|
||||
Start versioning
|
||||
67
cmake/apps.cmake
Normal file
67
cmake/apps.cmake
Normal file
@@ -0,0 +1,67 @@
|
||||
if(TESSESFRAMEWORK_ENABLE_APPS)
|
||||
add_executable(tbin2h apps/tbin2h.cpp)
|
||||
target_link_libraries(tbin2h PUBLIC tessesframework)
|
||||
install(TARGETS tbin2h DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
add_executable(tanonydrop apps/tanonydrop.cpp)
|
||||
target_link_libraries(tanonydrop PUBLIC tessesframework)
|
||||
install(TARGETS tanonydrop DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
add_executable(tfetch apps/tfetch.cpp)
|
||||
target_link_libraries(tfetch PUBLIC tessesframework)
|
||||
install(TARGETS tfetch DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
add_executable(tfileserver apps/tfileserver.cpp)
|
||||
target_link_libraries(tfileserver PUBLIC tessesframework)
|
||||
install(TARGETS tfileserver DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
|
||||
add_executable(tdoc2json apps/tdoc2json.cpp)
|
||||
target_link_libraries(tdoc2json PUBLIC tessesframework)
|
||||
install(TARGETS tdoc2json DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
|
||||
add_executable(tjson2doc apps/tjson2doc.cpp)
|
||||
target_link_libraries(tjson2doc PUBLIC tessesframework)
|
||||
install(TARGETS tjson2doc DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
|
||||
add_executable(tjsonpretty apps/tjsonpretty.cpp)
|
||||
target_link_libraries(tjsonpretty PUBLIC tessesframework)
|
||||
install(TARGETS tjsonpretty DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
|
||||
add_executable(tjsonunpretty apps/tjsonunpretty.cpp)
|
||||
target_link_libraries(tjsonunpretty PUBLIC tessesframework)
|
||||
install(TARGETS tjsonunpretty DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
|
||||
add_executable(ttime apps/ttime.cpp)
|
||||
target_link_libraries(ttime PUBLIC tessesframework)
|
||||
install(TARGETS ttime DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
add_executable(tshell apps/tshell.cpp)
|
||||
target_link_libraries(tshell PUBLIC tessesframework)
|
||||
install(TARGETS tshell DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
|
||||
add_executable(tprinttorrent apps/printtorrent.cpp)
|
||||
|
||||
target_link_libraries(tprinttorrent PUBLIC tessesframework)
|
||||
install(TARGETS tprinttorrent DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
|
||||
add_executable(ttorrentcreate apps/ttorrentcreate.cpp)
|
||||
|
||||
target_link_libraries(ttorrentcreate PUBLIC tessesframework)
|
||||
install(TARGETS ttorrentcreate DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
|
||||
add_executable(tclearwebseed apps/tclearwebseed.cpp)
|
||||
|
||||
target_link_libraries(tclearwebseed PUBLIC tessesframework)
|
||||
install(TARGETS tclearwebseed DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
|
||||
add_executable(trng apps/trng.cpp)
|
||||
|
||||
target_link_libraries(trng PUBLIC tessesframework)
|
||||
install(TARGETS trng DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
|
||||
add_executable(twatch apps/twatch.cpp)
|
||||
|
||||
target_link_libraries(twatch PUBLIC tessesframework)
|
||||
install(TARGETS twatch DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
|
||||
add_executable(tuuid apps/tuuid.cpp)
|
||||
|
||||
target_link_libraries(tuuid PUBLIC tessesframework)
|
||||
install(TARGETS tuuid DESTINATION "${CMAKE_INSTALL_BINDIR}")
|
||||
endif()
|
||||
43
cmake/examples.cmake
Normal file
43
cmake/examples.cmake
Normal file
@@ -0,0 +1,43 @@
|
||||
if(TESSESFRAMEWORK_ENABLE_EXAMPLES)
|
||||
add_executable(echo-my-name examples/echo-my-name.cpp)
|
||||
target_link_libraries(echo-my-name PUBLIC tessesframework)
|
||||
|
||||
add_executable(echo-platform examples/echo-platform.cpp)
|
||||
target_link_libraries(echo-platform PUBLIC tessesframework)
|
||||
|
||||
add_executable(console-list examples/console-list.cpp)
|
||||
target_link_libraries(console-list PUBLIC tessesframework)
|
||||
|
||||
add_executable(console-test examples/console-test.cpp)
|
||||
target_link_libraries(console-test PUBLIC tessesframework)
|
||||
add_executable(console-raw examples/console-raw.cpp)
|
||||
target_link_libraries(console-raw PUBLIC tessesframework)
|
||||
|
||||
add_executable(timer examples/timer.cpp)
|
||||
target_link_libraries(timer PUBLIC tessesframework)
|
||||
|
||||
add_executable(copyfile examples/copyfile.cpp)
|
||||
target_link_libraries(copyfile PUBLIC tessesframework)
|
||||
|
||||
add_executable(webserverex examples/webserverex.cpp)
|
||||
target_link_libraries(webserverex PUBLIC tessesframework)
|
||||
|
||||
add_executable(safesubpath examples/safesubpath.cpp)
|
||||
target_link_libraries(safesubpath PUBLIC tessesframework)
|
||||
|
||||
add_executable(pathtest examples/pathtest.cpp)
|
||||
target_link_libraries(pathtest PUBLIC tessesframework)
|
||||
|
||||
add_executable(mountabletest examples/mountabletest.cpp)
|
||||
target_link_libraries(mountabletest PUBLIC tessesframework)
|
||||
|
||||
add_executable(printjsondecodedemoji examples/printjsondecodedemoji.cpp)
|
||||
target_link_libraries(printjsondecodedemoji PUBLIC tessesframework)
|
||||
|
||||
add_executable(wsecho examples/wsecho.cpp)
|
||||
target_link_libraries(wsecho PUBLIC tessesframework)
|
||||
|
||||
|
||||
add_executable(tests examples/tests.cpp)
|
||||
target_link_libraries(tests PUBLIC tessesframework)
|
||||
endif()
|
||||
27
cmake/findmbed.cmake
Normal file
27
cmake/findmbed.cmake
Normal file
@@ -0,0 +1,27 @@
|
||||
if(TESSESFRAMEWORK_FETCHCONTENT)
|
||||
set(MBEDTLS_FATAL_WARNINGS OFF CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
set(ENABLE_TESTING OFF CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
set(ENABLE_PROGRAMS OFF CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
|
||||
FetchContent_Declare(
|
||||
mbedtls
|
||||
URL https://downloads.tesses.net/cache/libraries/source/mbedtls-3.6.4.tar.bz2
|
||||
|
||||
)
|
||||
if(TESSESFRAMEWORK_ENABLE_MBED AND TESSESFRAMEWORK_FETCHCONTENT)
|
||||
set(MBEDTLS_FATAL_WARNINGS OFF CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
set(ENABLE_TESTING OFF CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
set(ENABLE_PROGRAMS OFF CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
if(TESSESFRAMEWORK_STATIC)
|
||||
set(USE_STATIC_MBEDTLS_LIBRARY ON CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
set(USE_SHARED_MBEDTLS_LIBRARY OFF CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
else()
|
||||
set(USE_STATIC_MBEDTLS_LIBRARY OFF CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
set(USE_SHARED_MBEDTLS_LIBRARY ON CACHE INTERNAL "For TessesFramework" FORCE)
|
||||
endif()
|
||||
|
||||
endif()
|
||||
FetchContent_MakeAvailable(mbedtls)
|
||||
else()
|
||||
find_package(MbedTLS REQUIRED)
|
||||
endif()
|
||||
78
cmake/helpers.cmake
Normal file
78
cmake/helpers.cmake
Normal file
@@ -0,0 +1,78 @@
|
||||
if(TESSESFRAMEWORK_ENABLE_SQLITE)
|
||||
target_compile_definitions(tessesframework PRIVATE TESSESFRAMEWORK_ENABLE_SQLITE)
|
||||
endif()
|
||||
if(TESSESFRAMEWORK_ENABLE_PLATFORMFOLDERS)
|
||||
target_compile_definitions(tessesframework PRIVATE TESSESFRAMEWORK_ENABLE_PLATFORMFOLDERS)
|
||||
endif()
|
||||
if(TESSESFRAMEWORK_ENABLE_PROCESS)
|
||||
target_compile_definitions(tessesframework PRIVATE TESSESFRAMEWORK_ENABLE_PROCESS)
|
||||
|
||||
endif()
|
||||
target_include_directories(tessesframework
|
||||
PUBLIC
|
||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
|
||||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
|
||||
)
|
||||
target_include_directories(tessesframework
|
||||
PUBLIC
|
||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>"
|
||||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
|
||||
)
|
||||
if(WIN32)
|
||||
target_link_libraries(tessesframework PRIVATE iphlpapi)
|
||||
target_link_libraries(tessesframework PRIVATE ws2_32)
|
||||
|
||||
endif()
|
||||
|
||||
if(TESSESFRAMEWORK_LOGTOFILE)
|
||||
target_compile_definitions(tessesframework PRIVATE TESSESFRAMEWORK_LOGTOFILE)
|
||||
endif()
|
||||
if(TESSESFRAMEWORK_ENABLE_THREADING)
|
||||
target_compile_definitions(tessesframework PRIVATE TESSESFRAMEWORK_ENABLE_THREADING)
|
||||
endif()
|
||||
if(TESSESFRAMEWORK_ENABLE_NETWORKING)
|
||||
target_compile_definitions(tessesframework PRIVATE TESSESFRAMEWORK_ENABLE_NETWORKING)
|
||||
endif()
|
||||
if(TESSESFRAMEWORK_FETCHCONTENT)
|
||||
target_compile_definitions(tessesframework PRIVATE TESSESFRAMEWORK_FETCHCONTENT)
|
||||
endif()
|
||||
if(TESSESFRAMEWORK_ENABLE_MBED)
|
||||
target_compile_definitions(tessesframework PRIVATE TESSESFRAMEWORK_ENABLE_MBED)
|
||||
if(TESSESFRAMEWORK_EMBED_CERT_BUNDLE)
|
||||
target_compile_definitions(tessesframework PRIVATE TESSESFRAMEWORK_EMBED_CERT_BUNDLE)
|
||||
else()
|
||||
target_compile_definitions(tessesframework PRIVATE TESSESFRAMEWORK_CERT_BUNDLE_FILE=${TESSESFRAMEWORK_CERT_BUNDLE_FILE})
|
||||
endif()
|
||||
|
||||
if(TESSESFRAMEWORK_FETCHCONTENT)
|
||||
target_link_libraries(tessesframework PRIVATE mbedtls mbedx509 mbedcrypto everest p256m)
|
||||
list(APPEND TessesFrameworkLibs mbedtls mbedx509 mbedcrypto everest p256m)
|
||||
else()
|
||||
target_link_libraries(tessesframework PRIVATE mbedtls mbedx509 mbedcrypto)
|
||||
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
if(NOT(WIN32 OR PLATFORM_PS2))
|
||||
|
||||
if(TESSESFRAMEWORK_ENABLE_THREADING)
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
find_package(Threads REQUIRED)
|
||||
target_link_libraries(tessesframework PRIVATE Threads::Threads)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT(WIN32 OR PLATFORM_PS2 OR "${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoWii" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoGameCube") OR "${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoSwitch")
|
||||
check_library_exists(util forkpty "" HAVE_LIBUTIL)
|
||||
if(HAVE_LIBUTIL)
|
||||
target_link_libraries(tessesframework PRIVATE util)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT(WIN32 OR PLATFORM_PS2 OR "${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoWii" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoGameCube") OR "${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoSwitch")
|
||||
check_library_exists(dl dlopen "" HAVE_LIBDL)
|
||||
if(HAVE_LIBDL)
|
||||
target_link_libraries(tessesframework PRIVATE dl)
|
||||
endif()
|
||||
endif()
|
||||
29
cmake/install-dev.cmake
Normal file
29
cmake/install-dev.cmake
Normal file
@@ -0,0 +1,29 @@
|
||||
if(TESSESFRAMEWORK_INSTALL_DEVELOPMENT)
|
||||
install(TARGETS ${TessesFrameworkLibs}
|
||||
EXPORT TessesFrameworkTargets
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
)
|
||||
|
||||
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/TessesFramework DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/TessesFramework DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||
|
||||
install(EXPORT TessesFrameworkTargets
|
||||
FILE TessesFrameworkTargets.cmake
|
||||
NAMESPACE TessesFramework::
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/TessesFramework
|
||||
)
|
||||
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/TessesFrameworkConfig.cmake"
|
||||
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/TessesFramework)
|
||||
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/TessesFrameworkFeatures.h.in "${CMAKE_CURRENT_BINARY_DIR}/include/TessesFramework/TessesFrameworkFeatures.h"
|
||||
INSTALL_DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/TessesFramework/TessesFrameworkFeatures.h)
|
||||
|
||||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/TessesFrameworkConfig.cmake"
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/TessesFramework)
|
||||
|
||||
endif()
|
||||
16
cmake/options.cmake
Normal file
16
cmake/options.cmake
Normal file
@@ -0,0 +1,16 @@
|
||||
option(TESSESFRAMEWORK_EMBED_CERT_BUNDLE "Embed the certificate chain bundle" ON)
|
||||
option(TESSESFRAMEWORK_ENABLE_MBED "Enable Tesses Framework mbedtls" ON)
|
||||
option(TESSESFRAMEWORK_ENABLE_NETWORKING "Enable Networking" ON)
|
||||
option(TESSESFRAMEWORK_ENABLE_THREADING "Enable Threading" ON)
|
||||
option(TESSESFRAMEWORK_ENABLE_SQLITE "Enable sqlite (embedded in source)" ON)
|
||||
option(TESSESFRAMEWORK_ENABLE_PLATFORMFOLDERS "Enable sago platformfolders (embedded in source)" ON)
|
||||
option(TESSESFRAMEWORK_ENABLE_PROCESS "Enable process api" ON)
|
||||
option(TESSESFRAMEWORK_ENABLE_RPATH "Enable RPATH" ON)
|
||||
option(TESSESFRAMEWORK_ENABLE_EXAMPLES "Enable Tesses Framework examples" ON)
|
||||
option(TESSESFRAMEWORK_ENABLE_APPS "Enable Tesses Framework cli apps" ON)
|
||||
option(TESSESFRAMEWORK_INSTALL_DEVELOPMENT "Enable Installing Tesses Framework Development Packages" ON)
|
||||
option(TESSESFRAMEWORK_STATIC "Build with static libraries instead of shared" OFF)
|
||||
option(TESSESFRAMEWORK_ENABLE_SETDATE "Enable setting date to file" ON)
|
||||
option(TESSESFRAMEWORK_LOGTOFILE "TessesFramework Log to file" OFF)
|
||||
option(TESSESFRAMEWORK_FETCHCONTENT "TessesFramework fetchcontent" ON)
|
||||
option(TESSESFRAMEWORK_VENDERCERTCHAIN "Use the ca-certificates.crt in project rather than system" ON)
|
||||
21
cmake/sharedlib.cmake
Normal file
21
cmake/sharedlib.cmake
Normal file
@@ -0,0 +1,21 @@
|
||||
if(TESSESFRAMEWORK_ENABLE_RPATH)
|
||||
set(CMAKE_MACOSX_RPATH 1)
|
||||
set(CMAKE_BUILD_RPATH_USE_ORIGIN TRUE)
|
||||
|
||||
if (APPLE)
|
||||
set(CMAKE_INSTALL_RPATH "@executable_path/../${CMAKE_INSTALL_LIBDIR}")
|
||||
else()
|
||||
set(CMAKE_INSTALL_RPATH "$ORIGIN/../${CMAKE_INSTALL_LIBDIR}")
|
||||
endif()
|
||||
endif()
|
||||
add_library(tessesframework SHARED ${TESSESFRAMEWORK_SOURCE})
|
||||
set_target_properties(tessesframework PROPERTIES
|
||||
VERSION ${TESSESFRAMEWORK_MAJOR_VERSION}.${TESSESFRAMEWORK_MINOR_VERSION}.${TESSESFRAMEWORK_PATCH_VERSION}
|
||||
SOVERSION ${TESSESFRAMEWORK_MAJOR_VERSION}
|
||||
)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/helpers.cmake)
|
||||
|
||||
install(TARGETS tessesframework DESTINATION)
|
||||
|
||||
|
||||
list(APPEND TessesFrameworkLibs tessesframework)
|
||||
62
cmake/sources.cmake
Normal file
62
cmake/sources.cmake
Normal file
@@ -0,0 +1,62 @@
|
||||
list(APPEND TESSESFRAMEWORK_SOURCE
|
||||
src/Console.cpp
|
||||
src/Random.cpp
|
||||
src/Date/Date.cpp
|
||||
src/Http/FileServer.cpp
|
||||
src/Http/MountableServer.cpp
|
||||
src/Http/RouteServer.cpp
|
||||
src/Http/CallbackServer.cpp
|
||||
src/Http/HttpServer.cpp
|
||||
src/Http/HttpUtils.cpp
|
||||
src/Http/HttpClient.cpp
|
||||
src/Http/HttpStream.cpp
|
||||
src/Http/ContentDisposition.cpp
|
||||
src/Http/WebSocket.cpp
|
||||
src/Http/ChangeableServer.cpp
|
||||
src/Http/BasicAuthServer.cpp
|
||||
src/Http/CGIServer.cpp
|
||||
src/Mail/Smtp.cpp
|
||||
src/Serialization/Json.cpp
|
||||
src/Serialization/SQLite.cpp
|
||||
src/Serialization/BitConverter.cpp
|
||||
src/Serialization/Bencode.cpp
|
||||
src/Platform/Environment.cpp
|
||||
src/Platform/Process.cpp
|
||||
src/Streams/FileStream.cpp
|
||||
src/Streams/MemoryStream.cpp
|
||||
src/Streams/NetworkStream.cpp
|
||||
src/Streams/Stream.cpp
|
||||
src/Streams/BufferedStream.cpp
|
||||
src/Streams/ByteReader.cpp
|
||||
src/Streams/ByteWriter.cpp
|
||||
src/Streams/PtyStream.cpp
|
||||
src/Text/StringConverter.cpp
|
||||
src/Text/HeaderGenerator.cpp
|
||||
src/TextStreams/StreamReader.cpp
|
||||
src/TextStreams/StreamWriter.cpp
|
||||
src/TextStreams/TextReader.cpp
|
||||
src/TextStreams/TextWriter.cpp
|
||||
src/TextStreams/StdIOReader.cpp
|
||||
src/TextStreams/StdIOWriter.cpp
|
||||
src/TextStreams/StringReader.cpp
|
||||
src/TextStreams/StringWriter.cpp
|
||||
src/Threading/Thread.cpp
|
||||
src/Threading/Mutex.cpp
|
||||
src/Threading/ThreadPool.cpp
|
||||
src/Filesystem/VFS.cpp
|
||||
src/Filesystem/LocalFS.cpp
|
||||
src/Filesystem/SubdirFilesystem.cpp
|
||||
src/Filesystem/NullFilesystem.cpp
|
||||
src/Filesystem/MountableFilesystem.cpp
|
||||
src/Filesystem/RelativeFilesystem.cpp
|
||||
src/Filesystem/FSHelpers.cpp
|
||||
src/Filesystem/TempFS.cpp
|
||||
src/Crypto/MbedTLS/ClientTLSStream.cpp
|
||||
src/Crypto/MbedTLS/Crypto.cpp
|
||||
src/Args.cpp
|
||||
src/TF_Init.cpp
|
||||
src/HiddenField.cpp
|
||||
src/Uuid.cpp
|
||||
src/BitTorrent/TorrentFile.cpp
|
||||
src/BitTorrent/TorrentStream.cpp
|
||||
)
|
||||
14
cmake/staticlib.cmake
Normal file
14
cmake/staticlib.cmake
Normal file
@@ -0,0 +1,14 @@
|
||||
add_library(tessesframework STATIC ${TESSESFRAMEWORK_SOURCE})
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/helpers.cmake)
|
||||
|
||||
if("${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoWii" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoGameCube")
|
||||
target_link_libraries(tessesframework PUBLIC fat)
|
||||
|
||||
endif()
|
||||
if("${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoWii")
|
||||
target_link_libraries(tessesframework PUBLIC wiisocket)
|
||||
target_compile_definitions(tessesframework PUBLIC TESSESFRAMEWORK_USE_WII_SOCKET)
|
||||
endif()
|
||||
|
||||
list(APPEND TessesFrameworkLibs tessesframework)
|
||||
3
cmake/version.cmake
Normal file
3
cmake/version.cmake
Normal file
@@ -0,0 +1,3 @@
|
||||
set(TESSESFRAMEWORK_MAJOR_VERSION 0)
|
||||
set(TESSESFRAMEWORK_MINOR_VERSION 0)
|
||||
set(TESSESFRAMEWORK_PATCH_VERSION 4)
|
||||
@@ -1,5 +1,5 @@
|
||||
services:
|
||||
portable-json:
|
||||
image: onedev.site.tesses.net/tesses-framework/portable-json-creator:latest
|
||||
image: git.tesses.org/tesses50/portable-json-creator:latest
|
||||
ports:
|
||||
- "4999:4999"
|
||||
- "4999:4999"
|
||||
|
||||
31
examples/console-list.cpp
Normal file
31
examples/console-list.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "TessesFramework/TessesFramework.hpp"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
using namespace Tesses::Framework;
|
||||
using namespace Tesses::Framework::TextStreams;
|
||||
TF_Init();
|
||||
|
||||
std::vector<std::string> myList = {
|
||||
"Demi Lovato",
|
||||
"The Gremlins",
|
||||
"Al Gore",
|
||||
"Steve Ballmer",
|
||||
"CrossLang",
|
||||
"Tom Scott",
|
||||
"Louis Rossmann",
|
||||
"Mike Nolan",
|
||||
"Tim Cook"
|
||||
};
|
||||
|
||||
auto res = Console::List(myList);
|
||||
|
||||
if(res > myList.size())
|
||||
{
|
||||
Console::WriteLine("You must select one");
|
||||
}
|
||||
else {
|
||||
StdOut() << "You selected " << myList[res] << "." << NewLine();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
20
examples/console-raw.cpp
Normal file
20
examples/console-raw.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "TessesFramework/TessesFramework.hpp"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
using namespace Tesses::Framework;
|
||||
TF_Init();
|
||||
Console::WriteLine("Press q to quit");
|
||||
Console::SetEcho(false);
|
||||
Console::SetCanonical(false);
|
||||
while(int r = Console::Read())
|
||||
{
|
||||
if(r == 'q')
|
||||
{
|
||||
break;
|
||||
}
|
||||
Console::WriteLine(std::to_string(r));
|
||||
}
|
||||
Console::SetCanonical(true);
|
||||
Console::SetEcho(true);
|
||||
}
|
||||
20
examples/console-test.cpp
Normal file
20
examples/console-test.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <TessesFramework/TessesFramework.hpp>
|
||||
|
||||
using namespace Tesses::Framework;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
TF_Init();
|
||||
Console::SetPosition(0,0);
|
||||
Console::WriteLine("Demi Lovato Is Cute Right");
|
||||
Console::WriteLine("Right");
|
||||
Console::WriteLine("Al Gore");
|
||||
Console::WriteLine("Demi Lovato");
|
||||
Console::WriteLine("Hello \x1B[33myellow\x1B[37m world");
|
||||
Console::ReadLine();
|
||||
|
||||
Console::SetPosition(2,1);
|
||||
|
||||
Console::ClearRetainPosition(ClearBehaviour::CB_CURSORANDBELOW);
|
||||
Console::ReadLine();
|
||||
}
|
||||
@@ -2,13 +2,11 @@
|
||||
|
||||
using namespace Tesses::Framework::Filesystem;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
LocalFilesystem fs;
|
||||
VFSPath src = fs.SystemToVFSPath(argv[1]);
|
||||
VFSPath dest = fs.SystemToVFSPath(argv[2]);
|
||||
auto srcs = fs.OpenFile(src,"rb");
|
||||
auto dests = fs.OpenFile(dest,"wb");
|
||||
auto srcs = fs.OpenFile(src, "rb");
|
||||
auto dests = fs.OpenFile(dest, "wb");
|
||||
srcs->CopyTo(dests);
|
||||
|
||||
}
|
||||
9
examples/echo-my-name.cpp
Normal file
9
examples/echo-my-name.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "TessesFramework/TessesFramework.hpp"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
using namespace Tesses::Framework;
|
||||
TF_Init();
|
||||
Console::WriteLine("\"" + TF_GetExecutableName() + "\"");
|
||||
return 0;
|
||||
}
|
||||
9
examples/echo-platform.cpp
Normal file
9
examples/echo-platform.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "TessesFramework/TessesFramework.hpp"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
using namespace Tesses::Framework;
|
||||
TF_Init();
|
||||
Console::WriteLine(Tesses::Framework::Platform::Environment::GetPlatform());
|
||||
return 0;
|
||||
}
|
||||
@@ -5,57 +5,50 @@ using namespace Tesses::Framework;
|
||||
using namespace Tesses::Framework::Filesystem;
|
||||
using namespace Tesses::Framework::Streams;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if(argc < 2)
|
||||
{
|
||||
printf("USAGE: %s <command> <args...>\n",argv[0]);
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 2) {
|
||||
printf("USAGE: %s <command> <args...>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
std::string root = "./root";
|
||||
std::string mountDemi = "./demi";
|
||||
std::string mountJoelSlashJim = "./joelslashjim";
|
||||
|
||||
std::shared_ptr<SubdirFilesystem> rootdir = std::make_shared<SubdirFilesystem>(LocalFS,root);
|
||||
std::shared_ptr<SubdirFilesystem> rootdir =
|
||||
std::make_shared<SubdirFilesystem>(LocalFS, root);
|
||||
|
||||
std::shared_ptr<SubdirFilesystem> mountDemidir = std::make_shared<SubdirFilesystem>(LocalFS,mountDemi);
|
||||
std::shared_ptr<SubdirFilesystem> mountDemidir =
|
||||
std::make_shared<SubdirFilesystem>(LocalFS, mountDemi);
|
||||
|
||||
std::shared_ptr<SubdirFilesystem> mountjohnslashjim =
|
||||
std::make_shared<SubdirFilesystem>(LocalFS, mountJoelSlashJim);
|
||||
|
||||
std::shared_ptr<SubdirFilesystem> mountjohnslashjim = std::make_shared<SubdirFilesystem>(LocalFS,mountJoelSlashJim);
|
||||
|
||||
std::shared_ptr<MountableFilesystem> fs = std::make_shared<MountableFilesystem>(rootdir);
|
||||
std::shared_ptr<MountableFilesystem> fs =
|
||||
std::make_shared<MountableFilesystem>(rootdir);
|
||||
fs->Mount(std::string("/demi"), mountDemidir);
|
||||
|
||||
fs->Mount(std::string("/joel/jim"), mountjohnslashjim);
|
||||
|
||||
std::string command = argv[1];
|
||||
|
||||
|
||||
if(command == "ls")
|
||||
{
|
||||
if (command == "ls") {
|
||||
std::string dir = "/";
|
||||
if(argc > 2) dir = argv[2];
|
||||
|
||||
for(auto item : fs->EnumeratePaths(dir))
|
||||
{
|
||||
if (argc > 2)
|
||||
dir = argv[2];
|
||||
|
||||
for (auto item : fs->EnumeratePaths(dir)) {
|
||||
std::cout << item.GetFileName() << std::endl;
|
||||
}
|
||||
}
|
||||
else if(command == "cat")
|
||||
{
|
||||
std::shared_ptr<FileStream> strm = std::make_shared<FileStream>(stdout, false,"wb",false);
|
||||
for(int a = 2; a < argc; a++)
|
||||
{
|
||||
} else if (command == "cat") {
|
||||
std::shared_ptr<FileStream> strm =
|
||||
std::make_shared<FileStream>(stdout, false, "wb", false);
|
||||
for (int a = 2; a < argc; a++) {
|
||||
std::string path = argv[a];
|
||||
auto f = fs->OpenFile(path,"rb");
|
||||
if(f != nullptr)
|
||||
{
|
||||
auto f = fs->OpenFile(path, "rb");
|
||||
if (f != nullptr) {
|
||||
f->CopyTo(strm);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,14 +3,15 @@
|
||||
#include <string>
|
||||
using namespace Tesses::Framework::Filesystem;
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
VFSPath path("C:/home/user/file");
|
||||
VFSPath path2("D:/home/user/file");
|
||||
VFSPath path3("C:/home/user");
|
||||
std::cout << path.MakeRelative(path2).ToString() << std::endl;
|
||||
|
||||
std::cout << (path3 / path.MakeRelative(path2) / "John").CollapseRelativeParents().ToString() << std::endl;
|
||||
std::cout << (path3 / path.MakeRelative(path2) / "John")
|
||||
.CollapseRelativeParents()
|
||||
.ToString()
|
||||
<< std::endl;
|
||||
return 0;
|
||||
}
|
||||
@@ -2,12 +2,10 @@
|
||||
|
||||
using namespace Tesses::Framework::Serialization::Json;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
auto json = Json::Decode("\"\\uD83D\\uDE44\"");
|
||||
std::string str;
|
||||
if(TryGetJToken(json,str))
|
||||
{
|
||||
if (TryGetJToken(json, str)) {
|
||||
std::cout << str << std::endl;
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
#include "TessesFramework/TessesFramework.hpp"
|
||||
using namespace Tesses::Framework;
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
TF_Init();
|
||||
auto event = std::make_shared<FunctionalEvent<uint64_t>>([](uint64_t n)->void {
|
||||
std::cout << n << std::endl;
|
||||
});
|
||||
OnItteraton += event;
|
||||
|
||||
|
||||
auto event2 = std::make_shared<FunctionalEvent<uint64_t>>([&event](uint64_t n)->void{
|
||||
if(n == 10000) OnItteraton -= event;
|
||||
});
|
||||
OnItteraton += event2;
|
||||
|
||||
|
||||
TF_RunEventLoop();
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
@@ -3,17 +3,15 @@
|
||||
|
||||
using namespace Tesses::Framework::Filesystem;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if(argc < 3)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 3) {
|
||||
std::cout << "USAGE: " << argv[0] << " <parent> <subpath>\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
VFSPath parent(argv[1]);
|
||||
VFSPath subpath(argv[2]);
|
||||
VFSPath newPath(parent,subpath.CollapseRelativeParents());
|
||||
VFSPath newPath(parent, subpath.CollapseRelativeParents());
|
||||
|
||||
std::cout << newPath.ToString() << "\n";
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
#include "TessesFramework/TessesFramework.hpp"
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
Tesses::Framework::TF_Init();
|
||||
std::cout << "Basic auth test" << std::endl;
|
||||
std::string theEncoded="dXNlcjpwYXNz";
|
||||
std::string theEncoded = "dXNlcjpwYXNz";
|
||||
Tesses::Framework::Http::ServerContext ctx(nullptr);
|
||||
ctx.requestHeaders.SetValue("Authorization","Basic " + theEncoded);
|
||||
ctx.requestHeaders.SetValue("Authorization", "Basic " + theEncoded);
|
||||
std::string user;
|
||||
std::string pass;
|
||||
std::cout << Tesses::Framework::Http::BasicAuthServer::GetCreds(ctx,user,pass) << std::endl;
|
||||
std::cout << Tesses::Framework::Http::BasicAuthServer::GetCreds(ctx, user,
|
||||
pass)
|
||||
<< std::endl;
|
||||
std::cout << user << std::endl;
|
||||
std::cout << pass << std::endl;
|
||||
|
||||
}
|
||||
14
examples/timer.cpp
Normal file
14
examples/timer.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "TessesFramework/Common.hpp"
|
||||
#include "TessesFramework/TessesFramework.hpp"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
using namespace Tesses::Framework;
|
||||
TF_Init();
|
||||
|
||||
auto timer = TF_Timer(
|
||||
[]() -> void { std::cout << "Hi, I am a timer" << std::endl; });
|
||||
|
||||
TF_RunEventLoop();
|
||||
|
||||
TF_Quit();
|
||||
}
|
||||
@@ -1,175 +1,182 @@
|
||||
#include "TessesFramework/TessesFramework.hpp"
|
||||
#include <TessesFramework/Platform/Environment.hpp>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
using namespace Tesses::Framework;
|
||||
using namespace Tesses::Framework::Http;
|
||||
using namespace Tesses::Framework::Streams;
|
||||
using namespace Tesses::Framework::TextStreams;
|
||||
using namespace Tesses::Framework::Threading;
|
||||
class Johnny : public ServerContextData
|
||||
{
|
||||
public:
|
||||
Johnny()
|
||||
{
|
||||
text = "Steve Ballmer";
|
||||
}
|
||||
std::string text;
|
||||
~Johnny()
|
||||
{
|
||||
std::cout << "Destroying" << std::endl;
|
||||
}
|
||||
|
||||
std::shared_ptr<ServerSentEvents> sse = std::make_shared<ServerSentEvents>();
|
||||
|
||||
class Johnny : public ServerContextData {
|
||||
public:
|
||||
Johnny() { text = "Steve Ballmer"; }
|
||||
std::string text;
|
||||
~Johnny() { std::cout << "Destroying" << std::endl; }
|
||||
};
|
||||
class MyWebServer : public IHttpServer {
|
||||
public:
|
||||
bool Handle(ServerContext& ctx)
|
||||
{
|
||||
std::cout << ctx.path << std::endl;
|
||||
if(ctx.path == "/")
|
||||
{
|
||||
std::shared_ptr<FileStream> fs = std::make_shared<FileStream>("index.html","rb");
|
||||
|
||||
ctx
|
||||
.WithMimeType("text/html")
|
||||
.SendStream(fs);
|
||||
return true;
|
||||
}
|
||||
else if(ctx.path == "/mypath.html")
|
||||
{
|
||||
std::string txt = "<h1>Root: " + HttpUtils::HtmlEncode(ctx.GetServerRoot()) + "</h1>";
|
||||
public:
|
||||
bool Handle(ServerContext &ctx) {
|
||||
std::cout << ctx.path << std::endl;
|
||||
if (ctx.path == "/") {
|
||||
std::shared_ptr<FileStream> fs =
|
||||
std::make_shared<FileStream>("index.html", "rb");
|
||||
|
||||
ctx.WithMimeType("text/html").SendStream(fs);
|
||||
return true;
|
||||
} else if (ctx.path == "/mypath.html") {
|
||||
std::string txt =
|
||||
"<h1>Root: " + HttpUtils::HtmlEncode(ctx.GetServerRoot()) +
|
||||
"</h1>";
|
||||
ctx.WithMimeType("text/html").SendText(txt);
|
||||
return true;
|
||||
} else if (ctx.path == "/getabsolute.html") {
|
||||
std::string path;
|
||||
if (ctx.queryParams.TryGetFirst("path", path)) {
|
||||
std::string txt =
|
||||
"<h1>Path: " +
|
||||
HttpUtils::HtmlEncode(ctx.MakeAbsolute(path)) + "</h1>";
|
||||
ctx.WithMimeType("text/html").SendText(txt);
|
||||
return true;
|
||||
}
|
||||
else if(ctx.path == "/getabsolute.html")
|
||||
{
|
||||
std::string path;
|
||||
if(ctx.queryParams.TryGetFirst("path",path))
|
||||
{
|
||||
std::string txt = "<h1>Path: " + HttpUtils::HtmlEncode(ctx.MakeAbsolute(path)) + "</h1>";
|
||||
ctx.WithMimeType("text/html").SendText(txt);
|
||||
return true;
|
||||
}
|
||||
} else if (ctx.path == "/streaming.html") {
|
||||
StreamWriter writer(ctx.OpenResponseStream());
|
||||
writer.WriteLine("<html>");
|
||||
writer.WriteLine("<head><title>Streaming</title></head>");
|
||||
writer.WriteLine("<body>");
|
||||
|
||||
writer.WriteLine("<h1>Streaming</h1>");
|
||||
|
||||
writer.WriteLine("<ul>");
|
||||
|
||||
for (size_t i = 0; i < 10000; i++) {
|
||||
writer.WriteLine("<li>" + std::to_string(i) + "</li>");
|
||||
TF_Sleep(10);
|
||||
}
|
||||
else if(ctx.path == "/streaming.html")
|
||||
{
|
||||
StreamWriter writer(ctx.OpenResponseStream());
|
||||
writer.WriteLine("<html>");
|
||||
writer.WriteLine("<head><title>Streaming</title></head>");
|
||||
writer.WriteLine("<body>");
|
||||
|
||||
writer.WriteLine("<h1>Streaming</h1>");
|
||||
writer.WriteLine("</ul>");
|
||||
|
||||
writer.WriteLine("<ul>");
|
||||
writer.WriteLine("</body>");
|
||||
writer.WriteLine("</html>");
|
||||
return true;
|
||||
} else if (ctx.path == "/ssetest.html") {
|
||||
|
||||
for(size_t i=0;i<10000; i++)
|
||||
{
|
||||
writer.WriteLine("<li>" + std::to_string(i) + "</li>");
|
||||
|
||||
}
|
||||
} else if (ctx.path == "/sse") {
|
||||
ctx.SendServerSentEvents(sse);
|
||||
return true;
|
||||
} else if (ctx.path == "/main.js") {
|
||||
|
||||
writer.WriteLine("</ul>");
|
||||
std::shared_ptr<FileStream> fs =
|
||||
std::make_shared<FileStream>("main.js", "rb");
|
||||
|
||||
writer.WriteLine("</body>");
|
||||
writer.WriteLine("</html>");
|
||||
return true;
|
||||
}
|
||||
else if(ctx.path == "/main.js")
|
||||
{
|
||||
|
||||
std::shared_ptr<FileStream> fs = std::make_shared<FileStream>("main.js","rb");
|
||||
|
||||
ctx
|
||||
.WithMimeType("text/js")
|
||||
.SendStream(fs);
|
||||
return true;
|
||||
}
|
||||
else if(ctx.path == "/upload")
|
||||
{
|
||||
ctx.ParseFormData([](std::string mime, std::string filename, std::string name)->std::shared_ptr<Tesses::Framework::Streams::Stream>{
|
||||
return std::make_shared<FileStream>(filename,"wb");
|
||||
ctx.WithMimeType("text/js").SendStream(fs);
|
||||
return true;
|
||||
} else if (ctx.path == "/upload") {
|
||||
ctx.ParseFormData(
|
||||
[](std::string mime, std::string filename, std::string name)
|
||||
-> std::shared_ptr<Tesses::Framework::Streams::Stream> {
|
||||
return std::make_shared<FileStream>(filename, "wb");
|
||||
});
|
||||
}
|
||||
else if(ctx.path == "/steve")
|
||||
{
|
||||
Johnny* data = ctx.GetServerContentData<Johnny>("mytag");
|
||||
data->text = "Demi Lovato";
|
||||
}
|
||||
|
||||
return false;
|
||||
} else if (ctx.path == "/steve") {
|
||||
Johnny *data = ctx.GetServerContentData<Johnny>("mytag");
|
||||
data->text = "Demi Lovato";
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
class MyOtherWebServer : public IHttpServer
|
||||
{
|
||||
public:
|
||||
bool Handle(ServerContext& ctx)
|
||||
{
|
||||
TF_LOG("IN HANDLE");
|
||||
if(ctx.path == "/")
|
||||
{
|
||||
class MyOtherWebServer : public IHttpServer {
|
||||
public:
|
||||
bool Handle(ServerContext &ctx) {
|
||||
TF_LOG("IN HANDLE");
|
||||
if (ctx.path == "/") {
|
||||
std::string name;
|
||||
if(ctx.queryParams.TryGetFirst("name",name))
|
||||
{
|
||||
if (ctx.queryParams.TryGetFirst("name", name)) {
|
||||
std::cout << name << std::endl;
|
||||
TF_LOG(name);
|
||||
ctx
|
||||
.WithMimeType("text/plain")
|
||||
.WithContentDisposition(HttpUtils::Sanitise(name) + ".txt",false)
|
||||
.SendText(name + " is cool.");
|
||||
//do something with q
|
||||
|
||||
ctx.WithMimeType("text/plain")
|
||||
.WithContentDisposition(HttpUtils::Sanitise(name) + ".txt",
|
||||
false)
|
||||
.SendText(name + " is cool.");
|
||||
// do something with q
|
||||
|
||||
return true;
|
||||
}
|
||||
} else if (ctx.path == "/status") {
|
||||
int64_t num;
|
||||
if (ctx.queryParams.TryGetFirstInt("code", num)) {
|
||||
ctx.statusCode = (StatusCode)num;
|
||||
}
|
||||
else if(ctx.path == "/mymount/steve")
|
||||
{
|
||||
Johnny* data = ctx.GetServerContentData<Johnny>("mytag");
|
||||
ctx.SendText(data->text);
|
||||
return true;
|
||||
}
|
||||
else if(ctx.path == "/mypath.html")
|
||||
{
|
||||
std::string txt = "<h1>Root: " + HttpUtils::HtmlEncode(ctx.GetServerRoot()) + "</h1>";
|
||||
ctx.WithMimeType("text/html").SendText(txt);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
ctx.SendErrorPage(true);
|
||||
return true;
|
||||
} else if (ctx.path == "/error") {
|
||||
throw std::runtime_error("This is a error");
|
||||
} else if (ctx.path == "/error-debug") {
|
||||
ctx.WithDebug(true);
|
||||
throw std::runtime_error(
|
||||
"Platform is " +
|
||||
Tesses::Framework::Platform::Environment::GetPlatform());
|
||||
} else if (ctx.path == "/mymount/steve") {
|
||||
Johnny *data = ctx.GetServerContentData<Johnny>("mytag");
|
||||
ctx.SendText(data->text);
|
||||
return true;
|
||||
} else if (ctx.path == "/mypath.html") {
|
||||
std::string txt =
|
||||
"<h1>Root: " + HttpUtils::HtmlEncode(ctx.GetServerRoot()) +
|
||||
"</h1>";
|
||||
ctx.WithMimeType("text/html").SendText(txt);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
TF_InitWithConsole();
|
||||
int64_t timer = 0;
|
||||
auto timerHDL = TF_Timer([&timer]() -> void {
|
||||
timer++;
|
||||
|
||||
sse->SendData("Timer has ticked " + std::to_string(timer) +
|
||||
" times now");
|
||||
});
|
||||
|
||||
std::shared_ptr<RouteServer> routeSvr = std::make_shared<RouteServer>();
|
||||
routeSvr->Get("/name/{name}/greeting",[](ServerContext& ctx)->bool{
|
||||
routeSvr->Get("/name/{name}/greeting", [](ServerContext &ctx) -> bool {
|
||||
std::string name;
|
||||
if(ctx.pathArguments.TryGetFirst("name",name))
|
||||
{
|
||||
if (ctx.pathArguments.TryGetFirst("name", name)) {
|
||||
ctx.WithMimeType("text/plain").SendText("Hello " + name);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ctx.WithMimeType("text/plain").SendText("Please provide a name");
|
||||
}
|
||||
return true;
|
||||
});
|
||||
routeSvr->Get("/name/{name}/length",[](ServerContext& ctx)->bool{
|
||||
routeSvr->Get("/name/{name}/length", [](ServerContext &ctx) -> bool {
|
||||
std::string name;
|
||||
if(ctx.pathArguments.TryGetFirst("name",name))
|
||||
{
|
||||
ctx.WithMimeType("text/plain").SendText("The length of the name is " + std::to_string(name.size()));
|
||||
}
|
||||
else {
|
||||
if (ctx.pathArguments.TryGetFirst("name", name)) {
|
||||
ctx.WithMimeType("text/plain")
|
||||
.SendText("The length of the name is " +
|
||||
std::to_string(name.size()));
|
||||
} else {
|
||||
ctx.WithMimeType("text/plain").SendText("Please provide a name");
|
||||
}
|
||||
return true;
|
||||
});
|
||||
std::shared_ptr<MyOtherWebServer> myo = std::make_shared<MyOtherWebServer>();
|
||||
std::shared_ptr<MyOtherWebServer> myo =
|
||||
std::make_shared<MyOtherWebServer>();
|
||||
std::shared_ptr<MyWebServer> mws = std::make_shared<MyWebServer>();
|
||||
|
||||
std::shared_ptr<MountableServer> mountable = std::make_shared<MountableServer>(myo);
|
||||
mountable->Mount("/mymount/",mws);
|
||||
std::shared_ptr<MountableServer> mountable =
|
||||
std::make_shared<MountableServer>(myo);
|
||||
mountable->Mount("/mymount/", mws);
|
||||
mountable->Mount("/routeSvr/", routeSvr);
|
||||
HttpServer server(10001,mountable);
|
||||
HttpServer server(10001, mountable);
|
||||
server.StartAccepting();
|
||||
TF_RunEventLoop();
|
||||
std::cout << "Closing server" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
#include "TessesFramework.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
tf_vfs_t* local = tf_vfs_create_local();
|
||||
|
||||
tf_vfs_dir_t* dir = tf_vfs_opendir(local, "/home/mike");
|
||||
|
||||
string_t* str;
|
||||
while(str = tf_vfs_readdir(dir))
|
||||
{
|
||||
string_println(str);
|
||||
}
|
||||
tf_vfs_closedir(dir);
|
||||
|
||||
tf_stream_t* strm = tf_vfs_open(local,"/home/mike/myPhoto.png", "wb");
|
||||
|
||||
|
||||
|
||||
tf_vfs_close(local);
|
||||
}
|
||||
@@ -3,46 +3,35 @@
|
||||
#include <iostream>
|
||||
using namespace Tesses::Framework::Http;
|
||||
|
||||
class WebSocketConn : public WebSocketConnection
|
||||
{
|
||||
|
||||
public:
|
||||
void OnOpen(std::function<void(WebSocketMessage&)> sendMessage, std::function<void()> ping, std::function<void()> close)
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
std::cout << "> ";
|
||||
std::string req;
|
||||
std::getline(std::cin, req);
|
||||
if(req == "exit")
|
||||
break;
|
||||
else
|
||||
SendWebSocketMessage(sendMessage,req);
|
||||
}
|
||||
close();
|
||||
|
||||
}
|
||||
void OnReceive(WebSocketMessage& message)
|
||||
{
|
||||
std::cout << "Message: " << message.ToString() << std::endl;
|
||||
|
||||
|
||||
}
|
||||
void OnClose(bool clean)
|
||||
{
|
||||
std::cout << (clean ? "Closed cleanly" : "Closed unclean") << std::endl;
|
||||
}
|
||||
|
||||
};
|
||||
class WebSocketConn : public WebSocketConnection {
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
public:
|
||||
void OnOpen(std::function<void(WebSocketMessage &)> sendMessage,
|
||||
std::function<void()> ping, std::function<void()> close) {
|
||||
while (true) {
|
||||
std::cout << "> ";
|
||||
std::string req;
|
||||
std::getline(std::cin, req);
|
||||
if (req == "exit")
|
||||
break;
|
||||
else
|
||||
SendWebSocketMessage(sendMessage, req);
|
||||
}
|
||||
close();
|
||||
}
|
||||
void OnReceive(WebSocketMessage &message) {
|
||||
std::cout << "Message: " << message.ToString() << std::endl;
|
||||
}
|
||||
void OnClose(bool clean) {
|
||||
std::cout << (clean ? "Closed cleanly" : "Closed unclean") << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
Tesses::Framework::TF_Init();
|
||||
HttpDictionary reqHeaders;
|
||||
std::shared_ptr<WebSocketConn> conn = std::make_shared<WebSocketConn>();
|
||||
WebSocketClient("ws://echo.websocket.org/",reqHeaders,conn);
|
||||
|
||||
WebSocketClient("ws://echo.websocket.org/", reqHeaders, conn);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,13 +1,31 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "Common.hpp"
|
||||
namespace Tesses::Framework {
|
||||
class Args {
|
||||
public:
|
||||
Args(std::vector<std::string> args);
|
||||
Args(int argc, char** argv);
|
||||
std::string filename;
|
||||
std::vector<std::string> positional;
|
||||
std::vector<std::string> flags;
|
||||
std::vector<std::pair<std::string,std::string>> options;
|
||||
};
|
||||
}
|
||||
class Args {
|
||||
public:
|
||||
Args(std::vector<std::string> args);
|
||||
Args(int argc, char **argv);
|
||||
std::string filename;
|
||||
std::vector<std::string> positional;
|
||||
std::vector<std::string> flags;
|
||||
std::vector<std::pair<std::string, std::string>> options;
|
||||
};
|
||||
} // namespace Tesses::Framework
|
||||
@@ -1,70 +1,98 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../Serialization/Bencode.hpp"
|
||||
#include "TorrentStream.hpp"
|
||||
namespace Tesses::Framework::BitTorrent
|
||||
{
|
||||
constexpr int DEFAULT_PIECE_LENGTH = 524288;
|
||||
|
||||
class TorrentFileInfo {
|
||||
|
||||
Serialization::Bencode::BeDictionary info;
|
||||
public:
|
||||
TorrentFileInfo();
|
||||
TorrentFileInfo(const Serialization::Bencode::BeDictionary& tkn);
|
||||
|
||||
|
||||
int64_t piece_length=DEFAULT_PIECE_LENGTH;
|
||||
Serialization::Bencode::BeString pieces;
|
||||
int64_t isPrivate=0;
|
||||
Serialization::Bencode::BeString name;
|
||||
std::variant<int64_t, std::vector<TorrentFileEntry>> fileListOrLength;
|
||||
int64_t GetTorrentFileSize();
|
||||
/// @brief Generate the info
|
||||
/// @return the dictionary containing the info
|
||||
Serialization::Bencode::BeDictionary& GenerateInfoDictionary();
|
||||
/// @brief Get the info hash for info (if you are filling out the fields, you need to call GenerateInfoDictionary first)
|
||||
/// @return the 20 byte info hash
|
||||
Serialization::Bencode::BeString GetInfoHash();
|
||||
/// @brief Get the info (does not regenerate info from the fields)
|
||||
/// @return the dictionary containing the info
|
||||
Serialization::Bencode::BeDictionary& GetInfoDictionary();
|
||||
namespace Tesses::Framework::BitTorrent {
|
||||
constexpr int DEFAULT_PIECE_LENGTH = 524288;
|
||||
|
||||
/// @brief Used to load a dictionary in, will overwrite all the fields
|
||||
/// @param dict the dictionary to load
|
||||
void Load(const Serialization::Bencode::BeDictionary& dict);
|
||||
/// @brief Gets a read write based on this info object
|
||||
/// @param vfs the vfs object
|
||||
/// @param path file or directory inside vfs
|
||||
/// @return The read write at object
|
||||
std::shared_ptr<ReadWriteAt> GetStreamFromFilesystem(std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs, const Tesses::Framework::Filesystem::VFSPath& path);
|
||||
class TorrentFileInfo {
|
||||
|
||||
/// @brief Create info from file/directory
|
||||
/// @param vfs the vfs object
|
||||
/// @param path file or directory inside vfs
|
||||
/// @param isPrivate whether you use private trackers
|
||||
/// @param pieceLength length of pieces
|
||||
void CreateFromFilesystem(std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs, const Tesses::Framework::Filesystem::VFSPath& path, bool isPrivate=false, int64_t pieceLength=DEFAULT_PIECE_LENGTH);
|
||||
};
|
||||
class TorrentFile {
|
||||
public:
|
||||
TorrentFile();
|
||||
TorrentFile(const Serialization::Bencode::BeDictionary& tkn);
|
||||
Serialization::Bencode::BeDictionary info;
|
||||
|
||||
public:
|
||||
TorrentFileInfo();
|
||||
TorrentFileInfo(const Serialization::Bencode::BeDictionary &tkn);
|
||||
|
||||
Serialization::Bencode::BeString announce;
|
||||
std::vector<Serialization::Bencode::BeString> announce_list;
|
||||
std::vector<Serialization::Bencode::BeString> url_list;
|
||||
Serialization::Bencode::BeString comment;
|
||||
Serialization::Bencode::BeString created_by;
|
||||
int64_t creation_date=0;
|
||||
TorrentFileInfo info;
|
||||
int64_t piece_length = DEFAULT_PIECE_LENGTH;
|
||||
Serialization::Bencode::BeString pieces;
|
||||
int64_t isPrivate = 0;
|
||||
Serialization::Bencode::BeString name;
|
||||
std::variant<int64_t, std::vector<TorrentFileEntry>> fileListOrLength;
|
||||
int64_t GetTorrentFileSize();
|
||||
/// @brief Generate the info
|
||||
/// @return the dictionary containing the info
|
||||
Serialization::Bencode::BeDictionary &GenerateInfoDictionary();
|
||||
/// @brief Get the info hash for info (if you are filling out the fields,
|
||||
/// you need to call GenerateInfoDictionary first)
|
||||
/// @return the 20 byte info hash
|
||||
Serialization::Bencode::BeString GetInfoHash();
|
||||
/// @brief Get the info (does not regenerate info from the fields)
|
||||
/// @return the dictionary containing the info
|
||||
Serialization::Bencode::BeDictionary &GetInfoDictionary();
|
||||
|
||||
/// @brief Used to load a dictionary in, will overwrite all the fields
|
||||
/// @param dict the dictionary to load
|
||||
void Load(const Serialization::Bencode::BeDictionary &dict);
|
||||
/// @brief Gets a read write based on this info object
|
||||
/// @param vfs the vfs object
|
||||
/// @param path file or directory inside vfs
|
||||
/// @return The read write at object
|
||||
std::shared_ptr<ReadWriteAt> GetStreamFromFilesystem(
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs,
|
||||
const Tesses::Framework::Filesystem::VFSPath &path);
|
||||
|
||||
Serialization::Bencode::BeDictionary ToDictionary();
|
||||
/// @brief Create info from file/directory
|
||||
/// @param vfs the vfs object
|
||||
/// @param path file or directory inside vfs
|
||||
/// @param isPrivate whether you use private trackers
|
||||
/// @param pieceLength length of pieces
|
||||
void CreateFromFilesystem(
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs,
|
||||
const Tesses::Framework::Filesystem::VFSPath &path,
|
||||
bool isPrivate = false, int64_t pieceLength = DEFAULT_PIECE_LENGTH);
|
||||
};
|
||||
class TorrentFile {
|
||||
public:
|
||||
TorrentFile();
|
||||
TorrentFile(const Serialization::Bencode::BeDictionary &tkn);
|
||||
|
||||
void Print(std::shared_ptr<TextStreams::TextWriter> writer);
|
||||
Serialization::Bencode::BeString announce;
|
||||
std::vector<Serialization::Bencode::BeString> announce_list;
|
||||
std::vector<Serialization::Bencode::BeString> url_list;
|
||||
Serialization::Bencode::BeString comment;
|
||||
Serialization::Bencode::BeString created_by;
|
||||
int64_t creation_date = 0;
|
||||
TorrentFileInfo info;
|
||||
|
||||
static void CreateTorrent(std::shared_ptr<Tesses::Framework::Streams::Stream> torrent_file_stream,const std::vector<Serialization::Bencode::BeString>& trackers,const std::vector<Serialization::Bencode::BeString>& webseeds, std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs, const Tesses::Framework::Filesystem::VFSPath& path, bool isPrivate=false, int64_t pieceLength=DEFAULT_PIECE_LENGTH, Serialization::Bencode::BeString comment="", Serialization::Bencode::BeString created_by = "TessesFrameworkTorrent");
|
||||
|
||||
};
|
||||
}
|
||||
Serialization::Bencode::BeDictionary ToDictionary();
|
||||
|
||||
void Print(std::shared_ptr<TextStreams::TextWriter> writer);
|
||||
|
||||
static void CreateTorrent(
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> torrent_file_stream,
|
||||
const std::vector<Serialization::Bencode::BeString> &trackers,
|
||||
const std::vector<Serialization::Bencode::BeString> &webseeds,
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs,
|
||||
const Tesses::Framework::Filesystem::VFSPath &path,
|
||||
bool isPrivate = false, int64_t pieceLength = DEFAULT_PIECE_LENGTH,
|
||||
Serialization::Bencode::BeString comment = "",
|
||||
Serialization::Bencode::BeString created_by = "TessesFrameworkTorrent");
|
||||
};
|
||||
} // namespace Tesses::Framework::BitTorrent
|
||||
@@ -1,46 +1,68 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "TessesFramework/Http/HttpClient.hpp"
|
||||
#include "TessesFramework/Streams/NetworkStream.hpp"
|
||||
namespace Tesses::Framework::BitTorrent
|
||||
{
|
||||
class TorrentFileEntry {
|
||||
public:
|
||||
TorrentFileEntry();
|
||||
TorrentFileEntry(Tesses::Framework::Filesystem::VFSPath path, int64_t length);
|
||||
Tesses::Framework::Filesystem::VFSPath path;
|
||||
int64_t length=0;
|
||||
};
|
||||
class ReadWriteAt {
|
||||
public:
|
||||
virtual bool ReadBlockAt(uint64_t offset, uint8_t* data, size_t len)=0;
|
||||
virtual void WriteBlockAt(uint64_t offset, const uint8_t* data, size_t len)=0;
|
||||
virtual ~ReadWriteAt();
|
||||
namespace Tesses::Framework::BitTorrent {
|
||||
class TorrentFileEntry {
|
||||
public:
|
||||
TorrentFileEntry();
|
||||
TorrentFileEntry(Tesses::Framework::Filesystem::VFSPath path,
|
||||
int64_t length);
|
||||
Tesses::Framework::Filesystem::VFSPath path;
|
||||
int64_t length = 0;
|
||||
};
|
||||
class ReadWriteAt {
|
||||
public:
|
||||
virtual bool ReadBlockAt(uint64_t offset, uint8_t *data, size_t len) = 0;
|
||||
virtual void WriteBlockAt(uint64_t offset, const uint8_t *data,
|
||||
size_t len) = 0;
|
||||
virtual ~ReadWriteAt();
|
||||
};
|
||||
|
||||
};
|
||||
class TorrentFileStream : public ReadWriteAt {
|
||||
Tesses::Framework::Threading::Mutex mtx;
|
||||
|
||||
class TorrentFileStream : public ReadWriteAt
|
||||
{
|
||||
Tesses::Framework::Threading::Mutex mtx;
|
||||
public:
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs;
|
||||
Tesses::Framework::Filesystem::VFSPath path;
|
||||
uint64_t length;
|
||||
TorrentFileStream(std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs, Tesses::Framework::Filesystem::VFSPath path, uint64_t length);
|
||||
bool ReadBlockAt(uint64_t offset, uint8_t* data, size_t len);
|
||||
void WriteBlockAt(uint64_t offset, const uint8_t* data, size_t len);
|
||||
public:
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs;
|
||||
Tesses::Framework::Filesystem::VFSPath path;
|
||||
uint64_t length;
|
||||
TorrentFileStream(std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs,
|
||||
Tesses::Framework::Filesystem::VFSPath path,
|
||||
uint64_t length);
|
||||
bool ReadBlockAt(uint64_t offset, uint8_t *data, size_t len);
|
||||
void WriteBlockAt(uint64_t offset, const uint8_t *data, size_t len);
|
||||
};
|
||||
class TorrentDirectoryStream : public ReadWriteAt {
|
||||
|
||||
};
|
||||
class TorrentDirectoryStream : public ReadWriteAt
|
||||
{
|
||||
std::vector<Tesses::Framework::Threading::Mutex> mtxs;
|
||||
|
||||
std::vector<Tesses::Framework::Threading::Mutex> mtxs;
|
||||
public:
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs;
|
||||
Tesses::Framework::Filesystem::VFSPath path;
|
||||
std::vector<TorrentFileEntry> entries;
|
||||
TorrentDirectoryStream(std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs, Tesses::Framework::Filesystem::VFSPath path,std::vector<TorrentFileEntry> entries);
|
||||
bool ReadBlockAt(uint64_t offset, uint8_t* data, size_t len);
|
||||
void WriteBlockAt(uint64_t offset, const uint8_t* data, size_t len);
|
||||
};
|
||||
}
|
||||
public:
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs;
|
||||
Tesses::Framework::Filesystem::VFSPath path;
|
||||
std::vector<TorrentFileEntry> entries;
|
||||
TorrentDirectoryStream(
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs,
|
||||
Tesses::Framework::Filesystem::VFSPath path,
|
||||
std::vector<TorrentFileEntry> entries);
|
||||
bool ReadBlockAt(uint64_t offset, uint8_t *data, size_t len);
|
||||
void WriteBlockAt(uint64_t offset, const uint8_t *data, size_t len);
|
||||
};
|
||||
} // namespace Tesses::Framework::BitTorrent
|
||||
@@ -1,122 +1,119 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstring>
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include "Threading/Mutex.hpp"
|
||||
#include <optional>
|
||||
#include <atomic>
|
||||
|
||||
namespace Tesses::Framework
|
||||
{
|
||||
|
||||
template<typename...TArgs>
|
||||
class Event {
|
||||
public:
|
||||
virtual void Invoke(TArgs... args)=0;
|
||||
virtual ~Event()
|
||||
{}
|
||||
};
|
||||
template<typename...TArgs>
|
||||
class FunctionalEvent : public Event<TArgs...> {
|
||||
std::function<void(TArgs...)> cb;
|
||||
public:
|
||||
FunctionalEvent(std::function<void(TArgs...)> cb)
|
||||
{
|
||||
this->cb = cb;
|
||||
}
|
||||
void Invoke(TArgs... args)
|
||||
{
|
||||
this->cb(args...);
|
||||
}
|
||||
};
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <ratio>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
template<typename...TArgs>
|
||||
class EventList : public Event<TArgs...> {
|
||||
Threading::Mutex mtx;
|
||||
std::vector<std::shared_ptr<Event<TArgs...>>> items;
|
||||
public:
|
||||
void operator+=(std::shared_ptr<Event<TArgs...>> event)
|
||||
{
|
||||
mtx.Lock();
|
||||
for(std::shared_ptr<Event<TArgs...>>& item : this->items)
|
||||
{
|
||||
if(item.get() == event.get()) {
|
||||
mtx.Unlock();
|
||||
return;
|
||||
}
|
||||
}
|
||||
this->items.push_back(event);
|
||||
mtx.Unlock();
|
||||
}
|
||||
void operator-=(std::shared_ptr<Event<TArgs...>> event)
|
||||
{
|
||||
mtx.Lock();
|
||||
for(auto i = this->items.begin(); i != this->items.end(); i++)
|
||||
{
|
||||
if(i->get() == event.get())
|
||||
{
|
||||
this->items.erase(i);
|
||||
mtx.Unlock();
|
||||
return;
|
||||
}
|
||||
}
|
||||
mtx.Unlock();
|
||||
}
|
||||
void Invoke(TArgs... args)
|
||||
{
|
||||
mtx.Lock();
|
||||
for(auto& item : this->items)
|
||||
{
|
||||
item->Invoke(args...);
|
||||
}
|
||||
mtx.Unlock();
|
||||
}
|
||||
void Remove(std::function<bool(std::shared_ptr<Event<TArgs...>>)> cb)
|
||||
{
|
||||
for(auto index = this->items.begin(); index != this->items.end(); index++)
|
||||
{
|
||||
if(cb(*index))
|
||||
{
|
||||
this->items.erase(index);
|
||||
index--;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
namespace Tesses::Framework {
|
||||
|
||||
extern EventList<uint64_t> OnItteraton;
|
||||
std::optional<std::string> TF_GetCommandName();
|
||||
class TF_Timer_Handle;
|
||||
// Used for internal purposes, don't use unless you want to run timer events on
|
||||
// another thread
|
||||
|
||||
void TF_Init();
|
||||
void TF_InitWithConsole();
|
||||
void TF_AllowPortable(std::string argv0);
|
||||
void TF_ConnectToSelf(uint16_t port);
|
||||
void TF_InitEventLoop();
|
||||
void TF_RunEventLoop();
|
||||
void TF_RunEventLoopItteration();
|
||||
bool TF_IsRunning();
|
||||
void TF_SetIsRunning(bool _isRunning);
|
||||
void TF_Quit();
|
||||
bool TF_GetConsoleEventsEnabled();
|
||||
void TF_SetConsoleEventsEnabled(bool flag);
|
||||
void TF_InitConsole();
|
||||
void TF_Invoke(std::function<void()> cb);
|
||||
std::string TF_FileSize(uint64_t bytes, bool usesBin=true);
|
||||
|
||||
#if defined(TESSESFRAMEWORK_LOGTOFILE)
|
||||
void TF_Log(std::string dataToLog);
|
||||
#endif
|
||||
class TF_Timer_Handler {
|
||||
private:
|
||||
std::vector<std::weak_ptr<TF_Timer_Handle>> handles;
|
||||
|
||||
public:
|
||||
void Update();
|
||||
|
||||
#if defined(TESSESFRAMEWORK_LOGTOFILE)
|
||||
#define TF_LOG(log) Tesses::Framework::TF_Log(log)
|
||||
#else
|
||||
#define TF_LOG(log)
|
||||
#endif
|
||||
}
|
||||
static std::shared_ptr<TF_Timer_Handle>
|
||||
Make(std::shared_ptr<TF_Timer_Handler> handler);
|
||||
friend class TF_Timer_Handle;
|
||||
};
|
||||
|
||||
class TF_Timer_Handle {
|
||||
|
||||
private:
|
||||
std::shared_ptr<TF_Timer_Handler> timerHandler;
|
||||
std::function<void()> cb;
|
||||
std::chrono::milliseconds interval;
|
||||
std::chrono::time_point<std::chrono::steady_clock,
|
||||
std::chrono::milliseconds>
|
||||
last;
|
||||
bool enabled;
|
||||
TF_Timer_Handle() = delete;
|
||||
|
||||
TF_Timer_Handle(std::shared_ptr<TF_Timer_Handler> timerHandler);
|
||||
|
||||
public:
|
||||
void SetCallback(std::function<void()> cb);
|
||||
|
||||
int64_t GetIntervalMilliseconds();
|
||||
std::chrono::duration<int64_t, std::milli> GetIntervalDuration();
|
||||
|
||||
void SetIntervalFromMilliseconds(int64_t ms);
|
||||
|
||||
void SetIntervalFromDuration(std::chrono::milliseconds dur);
|
||||
|
||||
void SetEnabled(bool enabled);
|
||||
bool GetEnabled();
|
||||
friend class TF_Timer_Handler;
|
||||
};
|
||||
|
||||
std::shared_ptr<TF_Timer_Handle> TF_Timer();
|
||||
std::shared_ptr<TF_Timer_Handle> TF_Timer(std::function<void()> cb,
|
||||
int64_t interval = 1000,
|
||||
bool enabled = true);
|
||||
std::shared_ptr<TF_Timer_Handle> TF_Timer(std::function<void()> cb,
|
||||
std::chrono::milliseconds interval,
|
||||
bool enabled = true);
|
||||
|
||||
void TF_Init();
|
||||
void TF_InitWithConsole();
|
||||
std::string TF_GetExecutableName();
|
||||
void TF_AllowPortable();
|
||||
void TF_AllowPortable(std::string argv0);
|
||||
void TF_ConnectToSelf(uint16_t port);
|
||||
void TF_InitEventLoop();
|
||||
void TF_RunEventLoop();
|
||||
void TF_RunEventLoopItteration();
|
||||
bool TF_IsRunning();
|
||||
void TF_Sleep(uint32_t sleepMS);
|
||||
void TF_SetIsRunning(bool _isRunning);
|
||||
void TF_Quit();
|
||||
bool TF_GetConsoleEventsEnabled();
|
||||
void TF_SetConsoleEventsEnabled(bool flag);
|
||||
void TF_InitConsole();
|
||||
void TF_Invoke(std::function<void()> cb);
|
||||
std::string TF_FileSize(uint64_t bytes, bool usesBin = true);
|
||||
|
||||
#if defined(TESSESFRAMEWORK_LOGTOFILE)
|
||||
void TF_Log(std::string dataToLog);
|
||||
#endif
|
||||
|
||||
#if defined(TESSESFRAMEWORK_LOGTOFILE)
|
||||
#define TF_LOG(log) Tesses::Framework::TF_Log(log)
|
||||
#else
|
||||
#define TF_LOG(log)
|
||||
#endif
|
||||
} // namespace Tesses::Framework
|
||||
79
include/TessesFramework/Console.hpp
Normal file
79
include/TessesFramework/Console.hpp
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Common.hpp"
|
||||
#include <cstdio>
|
||||
|
||||
namespace Tesses::Framework {
|
||||
enum class ConsoleColor {
|
||||
CC_BLACK,
|
||||
CC_RED,
|
||||
CC_GREEN,
|
||||
CC_YELLOW,
|
||||
CC_BLUE,
|
||||
CC_MAGENTA,
|
||||
CC_CYAN,
|
||||
CC_WHITE
|
||||
};
|
||||
enum class ClearBehaviour {
|
||||
CB_CURSORANDBELOW,
|
||||
CB_CURSORANDABOVE,
|
||||
CB_ENTIRESCREEN
|
||||
};
|
||||
struct Console {
|
||||
static bool IsTTY();
|
||||
static std::pair<int,int> GetSize();
|
||||
static void ProgressBar(double);
|
||||
static void ProgressBar(int);
|
||||
static void Write(std::string text);
|
||||
static void WriteLine(std::string text);
|
||||
static void WriteView(std::string_view text);
|
||||
static void WriteLineView(std::string_view text);
|
||||
static void Error(std::string text);
|
||||
static void ErrorLine(std::string text);
|
||||
static void ErrorView(std::string_view text);
|
||||
static void ErrorLineView(std::string_view text);
|
||||
static int Read();
|
||||
static std::string ReadLine();
|
||||
|
||||
static bool GetEcho();
|
||||
static bool SetEcho(bool echo);
|
||||
static bool GetCanonical();
|
||||
static bool SetCanonical(bool can);
|
||||
static bool GetSignals();
|
||||
static bool SetSignals(bool sig);
|
||||
|
||||
static void SetPosition(int x, int y);
|
||||
|
||||
static void SetBackgroundColor(ConsoleColor c, bool alt);
|
||||
static void SetForegroundColor(ConsoleColor c, bool alt);
|
||||
static void Clear();
|
||||
static void MoveToHome();
|
||||
static void ClearRetainPosition(ClearBehaviour clearBehaviour);
|
||||
static void Flush();
|
||||
|
||||
//returns std::string::npos if no tty
|
||||
static size_t List(std::vector<std::string>& strs);
|
||||
|
||||
|
||||
static std::string ReadPassword();
|
||||
|
||||
private:
|
||||
static void WriteToStream(std::string_view text, bool isStderr);
|
||||
};
|
||||
}
|
||||
@@ -1,22 +1,43 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../Streams/Stream.hpp"
|
||||
|
||||
namespace Tesses::Framework::Crypto {
|
||||
class ClientTLSStream : public Tesses::Framework::Streams::Stream {
|
||||
void *privateData;
|
||||
|
||||
namespace Tesses::Framework::Crypto
|
||||
{
|
||||
class ClientTLSStream : public Tesses::Framework::Streams::Stream {
|
||||
void* privateData;
|
||||
public:
|
||||
static std::string GetCertChain();
|
||||
public:
|
||||
static std::string GetCertChain();
|
||||
|
||||
ClientTLSStream(std::shared_ptr<Tesses::Framework::Streams::Stream> innerStream, bool verify, std::string domain);
|
||||
ClientTLSStream(std::shared_ptr<Tesses::Framework::Streams::Stream> innerStream, bool verify, std::string domain, std::string cert);
|
||||
size_t Read(uint8_t* buff, size_t sz);
|
||||
size_t Write(const uint8_t* buff, size_t sz);
|
||||
bool CanRead();
|
||||
bool CanWrite();
|
||||
bool EndOfStream();
|
||||
~ClientTLSStream();
|
||||
};
|
||||
ClientTLSStream(
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> innerStream,
|
||||
bool verify, std::string domain);
|
||||
ClientTLSStream(
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> innerStream,
|
||||
bool verify, std::string domain, std::string cert);
|
||||
size_t Read(uint8_t *buff, size_t sz);
|
||||
size_t Write(const uint8_t *buff, size_t sz);
|
||||
bool CanRead();
|
||||
bool CanWrite();
|
||||
bool EndOfStream();
|
||||
~ClientTLSStream();
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace Tesses::Framework::Crypto
|
||||
@@ -1,60 +1,87 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../Streams/Stream.hpp"
|
||||
namespace Tesses::Framework::Crypto
|
||||
{
|
||||
bool HaveCrypto();
|
||||
std::string Base64_Encode(std::vector<uint8_t> data);
|
||||
std::vector<uint8_t> Base64_Decode(std::string str);
|
||||
class Sha1 {
|
||||
void* inner;
|
||||
public:
|
||||
Sha1();
|
||||
bool Start();
|
||||
bool Update(const uint8_t* buffer, size_t sz);
|
||||
bool Update(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
std::vector<uint8_t> Finish();
|
||||
~Sha1();
|
||||
static std::vector<uint8_t> ComputeHash(const uint8_t* buffer, size_t len);
|
||||
static std::vector<uint8_t> ComputeHash(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
};
|
||||
class Sha256 {
|
||||
void* inner;
|
||||
bool is224;
|
||||
public:
|
||||
Sha256();
|
||||
bool Start(bool is224=false);
|
||||
bool Is224();
|
||||
bool Update(const uint8_t* buffer, size_t sz);
|
||||
bool Update(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
std::vector<uint8_t> Finish();
|
||||
~Sha256();
|
||||
static std::vector<uint8_t> ComputeHash(const uint8_t* buffer, size_t len,bool is224=false);
|
||||
static std::vector<uint8_t> ComputeHash(std::shared_ptr<Tesses::Framework::Streams::Stream> strm,bool is224=false);
|
||||
|
||||
};
|
||||
class Sha512 {
|
||||
void* inner;
|
||||
bool is384;
|
||||
public:
|
||||
Sha512();
|
||||
bool Start(bool is384=false);
|
||||
bool Is384();
|
||||
bool Update(const uint8_t* buffer, size_t sz);
|
||||
bool Update(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
std::vector<uint8_t> Finish();
|
||||
~Sha512();
|
||||
namespace Tesses::Framework::Crypto {
|
||||
bool HaveCrypto();
|
||||
std::string Base64_Encode(std::vector<uint8_t> data);
|
||||
std::vector<uint8_t> Base64_Decode(std::string str);
|
||||
class Sha1 {
|
||||
void *inner;
|
||||
|
||||
static std::vector<uint8_t> ComputeHash(const uint8_t* buffer, size_t len,bool is384=false);
|
||||
static std::vector<uint8_t> ComputeHash(std::shared_ptr<Tesses::Framework::Streams::Stream> strm,bool is384=false);
|
||||
};
|
||||
typedef enum {
|
||||
VERSION_SHA1=1,
|
||||
VERSION_SHA224=224,
|
||||
VERSION_SHA256=256,
|
||||
VERSION_SHA384=384,
|
||||
VERSION_SHA512=512
|
||||
} ShaVersion;
|
||||
bool PBKDF2(std::vector<uint8_t>& output,std::string pass, std::vector<uint8_t>& salt, long itterations, ShaVersion version);
|
||||
public:
|
||||
Sha1();
|
||||
bool Start();
|
||||
bool Update(const uint8_t *buffer, size_t sz);
|
||||
bool Update(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
std::vector<uint8_t> Finish();
|
||||
~Sha1();
|
||||
static std::vector<uint8_t> ComputeHash(const uint8_t *buffer, size_t len);
|
||||
static std::vector<uint8_t>
|
||||
ComputeHash(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
};
|
||||
class Sha256 {
|
||||
void *inner;
|
||||
bool is224;
|
||||
|
||||
bool RandomBytes(std::vector<uint8_t>& output, std::string personal_str);
|
||||
}
|
||||
public:
|
||||
Sha256();
|
||||
bool Start(bool is224 = false);
|
||||
bool Is224();
|
||||
bool Update(const uint8_t *buffer, size_t sz);
|
||||
bool Update(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
std::vector<uint8_t> Finish();
|
||||
~Sha256();
|
||||
static std::vector<uint8_t> ComputeHash(const uint8_t *buffer, size_t len,
|
||||
bool is224 = false);
|
||||
static std::vector<uint8_t>
|
||||
ComputeHash(std::shared_ptr<Tesses::Framework::Streams::Stream> strm,
|
||||
bool is224 = false);
|
||||
};
|
||||
class Sha512 {
|
||||
void *inner;
|
||||
bool is384;
|
||||
|
||||
public:
|
||||
Sha512();
|
||||
bool Start(bool is384 = false);
|
||||
bool Is384();
|
||||
bool Update(const uint8_t *buffer, size_t sz);
|
||||
bool Update(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
std::vector<uint8_t> Finish();
|
||||
~Sha512();
|
||||
|
||||
static std::vector<uint8_t> ComputeHash(const uint8_t *buffer, size_t len,
|
||||
bool is384 = false);
|
||||
static std::vector<uint8_t>
|
||||
ComputeHash(std::shared_ptr<Tesses::Framework::Streams::Stream> strm,
|
||||
bool is384 = false);
|
||||
};
|
||||
typedef enum {
|
||||
VERSION_SHA1 = 1,
|
||||
VERSION_SHA224 = 224,
|
||||
VERSION_SHA256 = 256,
|
||||
VERSION_SHA384 = 384,
|
||||
VERSION_SHA512 = 512
|
||||
} ShaVersion;
|
||||
bool PBKDF2(std::vector<uint8_t> &output, std::string pass,
|
||||
std::vector<uint8_t> &salt, long itterations, ShaVersion version);
|
||||
|
||||
bool RandomBytes(std::vector<uint8_t> &output, std::string personal_str);
|
||||
} // namespace Tesses::Framework::Crypto
|
||||
@@ -1,142 +1,146 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace Tesses::Framework::Date
|
||||
{
|
||||
int GetTimeZone();
|
||||
bool TimeZoneSupportDST();
|
||||
|
||||
class DateTime {
|
||||
int year=1970;
|
||||
int month=1;
|
||||
int day=1;
|
||||
int hour=0;
|
||||
int minute=0;
|
||||
int second=0;
|
||||
bool isLocal=false;
|
||||
int64_t ToEpochNoConvert() const;
|
||||
void FromEpochNoConvert(int64_t gmt);
|
||||
public:
|
||||
DateTime();
|
||||
DateTime(int year, int month, int day, int hour, int minute, int seconds, bool isLocal=true);
|
||||
DateTime(int64_t epoch);
|
||||
int Year() const;
|
||||
int Month() const;
|
||||
int Day() const;
|
||||
int Hour() const;
|
||||
int Minute() const;
|
||||
int Second() const;
|
||||
int DayOfWeek() const;
|
||||
bool IsLocal() const;
|
||||
int64_t ToEpoch() const;
|
||||
DateTime ToLocal() const;
|
||||
DateTime ToUTC() const;
|
||||
void SetToLocal();
|
||||
void SetToUTC();
|
||||
void SetYear(int y);
|
||||
void SetMonth(int m);
|
||||
void SetDay(int d);
|
||||
void SetHour(int h);
|
||||
void SetMinute(int m);
|
||||
void SetSecond(int s);
|
||||
void SetLocal(bool local);
|
||||
void Set(int64_t epoch);
|
||||
void Set(int year, int month, int day, int hour, int minute, int seconds, bool isLocal=true);
|
||||
namespace Tesses::Framework::Date {
|
||||
int GetTimeZone();
|
||||
bool TimeZoneSupportDST();
|
||||
|
||||
|
||||
class DateTime {
|
||||
int year = 1970;
|
||||
int month = 1;
|
||||
int day = 1;
|
||||
int hour = 0;
|
||||
int minute = 0;
|
||||
int second = 0;
|
||||
bool isLocal = false;
|
||||
int64_t ToEpochNoConvert() const;
|
||||
void FromEpochNoConvert(int64_t gmt);
|
||||
|
||||
void SetToNow();
|
||||
void SetToNowUTC();
|
||||
static DateTime Now();
|
||||
static DateTime NowUTC();
|
||||
public:
|
||||
DateTime();
|
||||
DateTime(int year, int month, int day, int hour, int minute, int seconds,
|
||||
bool isLocal = true);
|
||||
DateTime(int64_t epoch);
|
||||
int Year() const;
|
||||
int Month() const;
|
||||
int Day() const;
|
||||
int Hour() const;
|
||||
int Minute() const;
|
||||
int Second() const;
|
||||
int DayOfWeek() const;
|
||||
bool IsLocal() const;
|
||||
int64_t ToEpoch() const;
|
||||
DateTime ToLocal() const;
|
||||
DateTime ToUTC() const;
|
||||
void SetToLocal();
|
||||
void SetToUTC();
|
||||
void SetYear(int y);
|
||||
void SetMonth(int m);
|
||||
void SetDay(int d);
|
||||
void SetHour(int h);
|
||||
void SetMinute(int m);
|
||||
void SetSecond(int s);
|
||||
void SetLocal(bool local);
|
||||
void Set(int64_t epoch);
|
||||
void Set(int year, int month, int day, int hour, int minute, int seconds,
|
||||
bool isLocal = true);
|
||||
|
||||
std::string ToString() const;
|
||||
std::string ToString(std::string fmt) const;
|
||||
void SetToNow();
|
||||
void SetToNowUTC();
|
||||
static DateTime Now();
|
||||
static DateTime NowUTC();
|
||||
|
||||
std::string ToString() const;
|
||||
std::string ToString(std::string fmt) const;
|
||||
|
||||
std::string ToHttpDate() const;
|
||||
static bool TryParseHttpDate(std::string txt, DateTime& dt);
|
||||
std::string ToHttpDate() const;
|
||||
static bool TryParseHttpDate(std::string txt, DateTime &dt);
|
||||
};
|
||||
class TimeSpan {
|
||||
int64_t totalSeconds;
|
||||
|
||||
};
|
||||
class TimeSpan {
|
||||
int64_t totalSeconds;
|
||||
public:
|
||||
TimeSpan();
|
||||
TimeSpan(int64_t totalSeconds);
|
||||
TimeSpan(int hours, int minutes, int seconds);
|
||||
TimeSpan(int days,int hours, int minutes, int seconds);
|
||||
|
||||
|
||||
void Set(int days, int hours, int minutes, int seconds);
|
||||
void Set(int hours, int minutes, int seconds);
|
||||
public:
|
||||
TimeSpan();
|
||||
TimeSpan(int64_t totalSeconds);
|
||||
TimeSpan(int hours, int minutes, int seconds);
|
||||
TimeSpan(int days, int hours, int minutes, int seconds);
|
||||
|
||||
void SetDays(int d);
|
||||
void SetHours(int h);
|
||||
void SetMinutes(int m);
|
||||
void SetSeconds(int s);
|
||||
|
||||
|
||||
int Days() const;
|
||||
int Hours() const;
|
||||
int Minutes() const;
|
||||
int Seconds() const;
|
||||
void Set(int days, int hours, int minutes, int seconds);
|
||||
void Set(int hours, int minutes, int seconds);
|
||||
|
||||
void SetDays(int d);
|
||||
void SetHours(int h);
|
||||
void SetMinutes(int m);
|
||||
void SetSeconds(int s);
|
||||
|
||||
int64_t TotalSeconds() const;
|
||||
int64_t TotalMinutes() const;
|
||||
int64_t TotalHours() const;
|
||||
int Days() const;
|
||||
int Hours() const;
|
||||
int Minutes() const;
|
||||
int Seconds() const;
|
||||
|
||||
int64_t TotalSeconds() const;
|
||||
int64_t TotalMinutes() const;
|
||||
int64_t TotalHours() const;
|
||||
|
||||
void SetTotalSeconds(int64_t totalSeconds);
|
||||
void SetTotalMinutes(int64_t totalMinutes);
|
||||
void SetTotalHours(int64_t totalHours);
|
||||
|
||||
void AddSeconds(int64_t seconds);
|
||||
void AddMinutes(int64_t minutes);
|
||||
void AddHours(int64_t hours);
|
||||
void AddDays(int64_t days);
|
||||
void SetTotalSeconds(int64_t totalSeconds);
|
||||
void SetTotalMinutes(int64_t totalMinutes);
|
||||
void SetTotalHours(int64_t totalHours);
|
||||
|
||||
std::string ToString(bool slim=true) const;
|
||||
void AddSeconds(int64_t seconds);
|
||||
void AddMinutes(int64_t minutes);
|
||||
void AddHours(int64_t hours);
|
||||
void AddDays(int64_t days);
|
||||
|
||||
static bool TryParse(std::string text, TimeSpan& span);
|
||||
std::string ToString(bool slim = true) const;
|
||||
|
||||
|
||||
|
||||
};
|
||||
static bool TryParse(std::string text, TimeSpan &span);
|
||||
};
|
||||
|
||||
inline DateTime operator+(const DateTime& dt, const TimeSpan& ts)
|
||||
{
|
||||
DateTime dt2(dt.ToEpoch() + ts.TotalSeconds());
|
||||
if(dt.IsLocal())
|
||||
dt2.SetToLocal();
|
||||
return dt2;
|
||||
}
|
||||
inline DateTime operator+(const TimeSpan& ts,const DateTime& dt)
|
||||
{
|
||||
DateTime dt2(dt.ToEpoch() + ts.TotalSeconds());
|
||||
if(dt.IsLocal())
|
||||
dt2.SetToLocal();
|
||||
return dt2;
|
||||
}
|
||||
inline TimeSpan operator+(const TimeSpan& ts, const TimeSpan& ts2)
|
||||
{
|
||||
return ts.TotalSeconds() + ts2.TotalSeconds();
|
||||
}
|
||||
inline DateTime operator-(const DateTime& dt, const TimeSpan& ts)
|
||||
{
|
||||
DateTime dt2(dt.ToEpoch() - ts.TotalSeconds());
|
||||
if(dt.IsLocal())
|
||||
dt2.SetToLocal();
|
||||
return dt2;
|
||||
}
|
||||
inline TimeSpan operator-(const DateTime& dt, const DateTime& dt2)
|
||||
{
|
||||
return dt.ToEpoch() - dt2.ToEpoch();
|
||||
}
|
||||
inline TimeSpan operator-(const TimeSpan& ts, const TimeSpan& ts2)
|
||||
{
|
||||
return ts.TotalSeconds() - ts2.TotalSeconds();
|
||||
}
|
||||
};
|
||||
inline DateTime operator+(const DateTime &dt, const TimeSpan &ts) {
|
||||
DateTime dt2(dt.ToEpoch() + ts.TotalSeconds());
|
||||
if (dt.IsLocal())
|
||||
dt2.SetToLocal();
|
||||
return dt2;
|
||||
}
|
||||
inline DateTime operator+(const TimeSpan &ts, const DateTime &dt) {
|
||||
DateTime dt2(dt.ToEpoch() + ts.TotalSeconds());
|
||||
if (dt.IsLocal())
|
||||
dt2.SetToLocal();
|
||||
return dt2;
|
||||
}
|
||||
inline TimeSpan operator+(const TimeSpan &ts, const TimeSpan &ts2) {
|
||||
return ts.TotalSeconds() + ts2.TotalSeconds();
|
||||
}
|
||||
inline DateTime operator-(const DateTime &dt, const TimeSpan &ts) {
|
||||
DateTime dt2(dt.ToEpoch() - ts.TotalSeconds());
|
||||
if (dt.IsLocal())
|
||||
dt2.SetToLocal();
|
||||
return dt2;
|
||||
}
|
||||
inline TimeSpan operator-(const DateTime &dt, const DateTime &dt2) {
|
||||
return dt.ToEpoch() - dt2.ToEpoch();
|
||||
}
|
||||
inline TimeSpan operator-(const TimeSpan &ts, const TimeSpan &ts2) {
|
||||
return ts.TotalSeconds() - ts2.TotalSeconds();
|
||||
}
|
||||
}; // namespace Tesses::Framework::Date
|
||||
@@ -1,33 +1,68 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "TempFS.hpp"
|
||||
#include "VFSFix.hpp"
|
||||
|
||||
namespace Tesses::Framework::Filesystem::Helpers
|
||||
{
|
||||
void ReadAllText(std::shared_ptr<VFS> vfs, VFSPath path, std::string& text);
|
||||
void ReadAllLines(std::shared_ptr<VFS> vfs, VFSPath path, std::vector<std::string>& lines);
|
||||
void ReadAllBytes(std::shared_ptr<VFS> vfs, VFSPath path, std::vector<uint8_t>& array);
|
||||
std::string ReadAllText(std::shared_ptr<VFS> vfs, VFSPath path);
|
||||
std::vector<std::string> ReadAllLines(std::shared_ptr<VFS> vfs, VFSPath path);
|
||||
std::vector<uint8_t> ReadAllBytes(std::shared_ptr<VFS> vfs, VFSPath path);
|
||||
void WriteAllText(std::shared_ptr<VFS> vfs, VFSPath path, const std::string& text);
|
||||
void WriteAllLines(std::shared_ptr<VFS> vfs, VFSPath path, const std::vector<std::string>& parts);
|
||||
void WriteAllBytes(std::shared_ptr<VFS> vfs, VFSPath path, const std::vector<uint8_t>& bytes);
|
||||
namespace Tesses::Framework::Filesystem::Helpers {
|
||||
void ReadAllText(std::shared_ptr<VFS> vfs, VFSPath path, std::string &text);
|
||||
void ReadAllLines(std::shared_ptr<VFS> vfs, VFSPath path,
|
||||
std::vector<std::string> &lines);
|
||||
void ReadAllBytes(std::shared_ptr<VFS> vfs, VFSPath path,
|
||||
std::vector<uint8_t> &array);
|
||||
std::string ReadAllText(std::shared_ptr<VFS> vfs, VFSPath path);
|
||||
std::vector<std::string> ReadAllLines(std::shared_ptr<VFS> vfs, VFSPath path);
|
||||
std::vector<uint8_t> ReadAllBytes(std::shared_ptr<VFS> vfs, VFSPath path);
|
||||
void WriteAllText(std::shared_ptr<VFS> vfs, VFSPath path,
|
||||
const std::string &text);
|
||||
void WriteAllLines(std::shared_ptr<VFS> vfs, VFSPath path,
|
||||
const std::vector<std::string> &parts);
|
||||
void WriteAllBytes(std::shared_ptr<VFS> vfs, VFSPath path,
|
||||
const std::vector<uint8_t> &bytes);
|
||||
|
||||
void CopyStreamProgress(std::shared_ptr<Streams::Stream> src,std::shared_ptr<Streams::Stream> dest, std::function<void(int64_t offset, int64_t length)> progress);
|
||||
void CopyStreamProgress(
|
||||
std::shared_ptr<Streams::Stream> src, std::shared_ptr<Streams::Stream> dest,
|
||||
std::function<void(int64_t offset, int64_t length)> progress);
|
||||
|
||||
void CopyFile(std::shared_ptr<VFS> vfsSrc, VFSPath pathSrc, std::shared_ptr<VFS> vfsDest, VFSPath pathDest, bool overwrite=true);
|
||||
void CopyFile(std::shared_ptr<VFS> vfsSrc, VFSPath pathSrc, std::shared_ptr<VFS> vfsDest, VFSPath pathDest, std::function<void(int64_t offset, int64_t length)> progress, bool overwrite=true);
|
||||
void CopyDirectory(std::shared_ptr<VFS> vfsSrc, VFSPath pathSrc, std::shared_ptr<VFS> vfsDest, VFSPath pathDest, bool overwrite=true);
|
||||
void CopyDirectory(std::shared_ptr<VFS> vfsSrc, VFSPath pathSrc, std::shared_ptr<VFS> vfsDest, VFSPath pathDest, std::function<void(int64_t offset, int64_t length, VFSPath currentFile)> progress, bool overwrite=true);
|
||||
void CopyFile(std::shared_ptr<VFS> vfsSrc, VFSPath pathSrc,
|
||||
std::shared_ptr<VFS> vfsDest, VFSPath pathDest,
|
||||
bool overwrite = true);
|
||||
void CopyFile(std::shared_ptr<VFS> vfsSrc, VFSPath pathSrc,
|
||||
std::shared_ptr<VFS> vfsDest, VFSPath pathDest,
|
||||
std::function<void(int64_t offset, int64_t length)> progress,
|
||||
bool overwrite = true);
|
||||
void CopyDirectory(std::shared_ptr<VFS> vfsSrc, VFSPath pathSrc,
|
||||
std::shared_ptr<VFS> vfsDest, VFSPath pathDest,
|
||||
bool overwrite = true);
|
||||
void CopyDirectory(
|
||||
std::shared_ptr<VFS> vfsSrc, VFSPath pathSrc, std::shared_ptr<VFS> vfsDest,
|
||||
VFSPath pathDest,
|
||||
std::function<void(int64_t offset, int64_t length, VFSPath currentFile)>
|
||||
progress,
|
||||
bool overwrite = true);
|
||||
|
||||
inline std::shared_ptr<TempFS> CreateTempFS(bool deleteOnDestroy=true)
|
||||
{
|
||||
return std::make_shared<TempFS>(deleteOnDestroy);
|
||||
}
|
||||
inline std::shared_ptr<TempFS> CreateTempFS(std::shared_ptr<VFS> vfs,bool deleteOnDestroy=true)
|
||||
{
|
||||
return std::make_shared<TempFS>(vfs,deleteOnDestroy);
|
||||
}
|
||||
inline std::shared_ptr<TempFS> CreateTempFS(bool deleteOnDestroy = true) {
|
||||
return std::make_shared<TempFS>(deleteOnDestroy);
|
||||
}
|
||||
inline std::shared_ptr<TempFS> CreateTempFS(std::shared_ptr<VFS> vfs,
|
||||
bool deleteOnDestroy = true) {
|
||||
return std::make_shared<TempFS>(vfs, deleteOnDestroy);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Tesses::Framework::Filesystem::Helpers
|
||||
@@ -1,50 +1,62 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "VFS.hpp"
|
||||
#include "VFSFix.hpp"
|
||||
|
||||
namespace Tesses::Framework::Filesystem
|
||||
{
|
||||
class LocalFilesystem : public VFS
|
||||
{
|
||||
public:
|
||||
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenFile(VFSPath path, std::string mode);
|
||||
|
||||
void CreateDirectory(VFSPath path);
|
||||
void DeleteDirectory(VFSPath path);
|
||||
bool RegularFileExists(VFSPath path);
|
||||
bool SymlinkExists(VFSPath path);
|
||||
bool CharacterDeviceExists(VFSPath path);
|
||||
bool BlockDeviceExists(VFSPath path);
|
||||
bool SocketFileExists(VFSPath path);
|
||||
bool FIFOFileExists(VFSPath path);
|
||||
bool DirectoryExists(VFSPath path);
|
||||
|
||||
void DeleteFile(VFSPath path);
|
||||
void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
|
||||
VFSPathEnumerator EnumeratePaths(VFSPath path);
|
||||
void CreateHardlink(VFSPath existingFile, VFSPath newName);
|
||||
|
||||
void MoveFile(VFSPath src, VFSPath dest);
|
||||
|
||||
void MoveDirectory(VFSPath src, VFSPath dest);
|
||||
VFSPath ReadLink(VFSPath path);
|
||||
std::string VFSPathToSystem(VFSPath path);
|
||||
VFSPath SystemToVFSPath(std::string path);
|
||||
|
||||
void GetDate(VFSPath path, Date::DateTime& lastWrite, Date::DateTime& lastAccess);
|
||||
void SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess);
|
||||
|
||||
bool StatVFS(VFSPath path, StatVFSData& vfsData);
|
||||
namespace Tesses::Framework::Filesystem {
|
||||
class LocalFilesystem : public VFS {
|
||||
public:
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream>
|
||||
OpenFile(VFSPath path, std::string mode);
|
||||
|
||||
void Chmod(VFSPath path, uint32_t mode);
|
||||
void CreateDirectory(VFSPath path);
|
||||
void DeleteDirectory(VFSPath path);
|
||||
|
||||
void Lock(VFSPath path);
|
||||
void Unlock(VFSPath path);
|
||||
void DeleteFile(VFSPath path);
|
||||
void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
|
||||
VFSPathEnumerator EnumeratePaths(VFSPath path);
|
||||
void CreateHardlink(VFSPath existingFile, VFSPath newName);
|
||||
|
||||
protected:
|
||||
std::shared_ptr<FSWatcher> CreateWatcher(std::shared_ptr<VFS> vfs, VFSPath path);
|
||||
void MoveFile(VFSPath src, VFSPath dest);
|
||||
|
||||
};
|
||||
extern std::shared_ptr<LocalFilesystem> LocalFS;
|
||||
}
|
||||
void MoveDirectory(VFSPath src, VFSPath dest);
|
||||
VFSPath ReadLink(VFSPath path);
|
||||
std::string VFSPathToSystem(VFSPath path);
|
||||
VFSPath SystemToVFSPath(std::string path);
|
||||
|
||||
void SetDate(VFSPath path, Date::DateTime lastWrite,
|
||||
Date::DateTime lastAccess);
|
||||
bool Stat(VFSPath path, StatData &stat);
|
||||
bool StatVFS(VFSPath path, StatVFSData &vfsData);
|
||||
|
||||
void Chmod(VFSPath path, uint32_t mode);
|
||||
void Chown(VFSPath path, uint32_t uid, uint32_t gid);
|
||||
|
||||
void Lock(VFSPath path);
|
||||
void Unlock(VFSPath path);
|
||||
|
||||
FIFOCreationResult CreateFIFO(VFSPath path, uint32_t mod);
|
||||
|
||||
protected:
|
||||
std::shared_ptr<FSWatcher> CreateWatcher(std::shared_ptr<VFS> vfs,
|
||||
VFSPath path);
|
||||
};
|
||||
extern std::shared_ptr<LocalFilesystem> LocalFS;
|
||||
} // namespace Tesses::Framework::Filesystem
|
||||
|
||||
@@ -1,100 +0,0 @@
|
||||
#pragma once
|
||||
#include "VFS.hpp"
|
||||
#include "VFSFix.hpp"
|
||||
#include "../Threading/Mutex.hpp"
|
||||
#include <atomic>
|
||||
namespace Tesses::Framework::Filesystem
|
||||
{
|
||||
class MemoryEntry {
|
||||
public:
|
||||
std::string name;
|
||||
virtual ~MemoryEntry();
|
||||
};
|
||||
class MemoryFileData {
|
||||
public:
|
||||
MemoryFileData();
|
||||
Date::DateTime lastWrite;
|
||||
|
||||
bool canAccess;
|
||||
size_t readers;
|
||||
std::vector<uint8_t> file;
|
||||
};
|
||||
|
||||
class MemoryFile : public MemoryEntry
|
||||
{
|
||||
public:
|
||||
std::shared_ptr<MemoryFileData> data;
|
||||
~MemoryFile();
|
||||
};
|
||||
|
||||
class MemoryDirectory : public MemoryEntry
|
||||
{
|
||||
public:
|
||||
MemoryDirectory();
|
||||
Date::DateTime lastWrite;
|
||||
std::vector<MemoryEntry*> entries;
|
||||
~MemoryDirectory();
|
||||
};
|
||||
|
||||
class MemorySymlink : public MemoryEntry
|
||||
{
|
||||
public:
|
||||
Date::DateTime lastWrite;
|
||||
VFSPath linkedTo;
|
||||
};
|
||||
|
||||
class MemoryFilesystemStream : public Streams::Stream
|
||||
{
|
||||
public:
|
||||
std::shared_ptr<Tesses::Framework::Threading::Mutex> mtx;
|
||||
std::shared_ptr<MemoryFileData> data;
|
||||
bool canRead;
|
||||
bool canWrite;
|
||||
bool canSeek;
|
||||
int64_t pos;
|
||||
MemoryFilesystemStream(std::shared_ptr<Tesses::Framework::Threading::Mutex> mtx, std::shared_ptr<MemoryFileData> data,bool canRead, bool canWrite, bool canSeek);
|
||||
size_t Read(uint8_t* buff, size_t sz);
|
||||
size_t Write(const uint8_t* buff, size_t sz);
|
||||
bool CanRead();
|
||||
bool CanWrite();
|
||||
bool CanSeek();
|
||||
int64_t GetPosition();
|
||||
void Flush();
|
||||
void Seek(int64_t pos, Streams::SeekOrigin whence);
|
||||
~MemoryFilesystemStream();
|
||||
};
|
||||
|
||||
|
||||
class MemoryFilesystem : public VFS
|
||||
{
|
||||
std::shared_ptr<Tesses::Framework::Threading::Mutex> mtx;
|
||||
MemoryDirectory root;
|
||||
|
||||
MemoryEntry* GetEntry(VFSPath path,bool followSymlink);
|
||||
public:
|
||||
MemoryFilesystem();
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenFile(VFSPath path, std::string mode);
|
||||
|
||||
void CreateDirectory(VFSPath path);
|
||||
void DeleteDirectory(VFSPath path);
|
||||
bool RegularFileExists(VFSPath path);
|
||||
bool SymlinkExists(VFSPath path);
|
||||
bool DirectoryExists(VFSPath path);
|
||||
|
||||
void DeleteFile(VFSPath path);
|
||||
void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
|
||||
VFSPathEnumerator EnumeratePaths(VFSPath path);
|
||||
void CreateHardlink(VFSPath existingFile, VFSPath newName);
|
||||
|
||||
void MoveFile(VFSPath src, VFSPath dest);
|
||||
|
||||
void MoveDirectory(VFSPath src, VFSPath dest);
|
||||
VFSPath ReadLink(VFSPath path);
|
||||
std::string VFSPathToSystem(VFSPath path);
|
||||
VFSPath SystemToVFSPath(std::string path);
|
||||
void GetDate(VFSPath path, Date::DateTime& lastWrite, Date::DateTime& lastAccess);
|
||||
void SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess);
|
||||
|
||||
~MemoryFilesystem();
|
||||
};
|
||||
};
|
||||
@@ -1,63 +1,75 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "VFS.hpp"
|
||||
#include "VFSFix.hpp"
|
||||
|
||||
namespace Tesses::Framework::Filesystem
|
||||
{
|
||||
class MountableDirectory {
|
||||
public:
|
||||
std::string name;
|
||||
std::shared_ptr<VFS> vfs;
|
||||
bool owns;
|
||||
std::vector<MountableDirectory*> dirs;
|
||||
void GetFS(VFSPath srcPath, VFSPath curDir, VFSPath& destRoot, VFSPath& destPath, std::shared_ptr<VFS>& vfs);
|
||||
~MountableDirectory();
|
||||
};
|
||||
|
||||
class MountableFilesystem : public VFS
|
||||
{
|
||||
std::shared_ptr<VFS> root;
|
||||
namespace Tesses::Framework::Filesystem {
|
||||
class MountableDirectory {
|
||||
public:
|
||||
std::string name;
|
||||
std::shared_ptr<VFS> vfs;
|
||||
bool owns;
|
||||
std::vector<MountableDirectory *> dirs;
|
||||
void GetFS(VFSPath srcPath, VFSPath curDir, VFSPath &destRoot,
|
||||
VFSPath &destPath, std::shared_ptr<VFS> &vfs);
|
||||
~MountableDirectory();
|
||||
};
|
||||
|
||||
std::vector<MountableDirectory*> directories;
|
||||
|
||||
void GetFS(VFSPath srcPath, VFSPath& destRoot, VFSPath& destPath, std::shared_ptr<VFS>& vfs);
|
||||
class MountableFilesystem : public VFS {
|
||||
std::shared_ptr<VFS> root;
|
||||
|
||||
|
||||
public:
|
||||
MountableFilesystem();
|
||||
MountableFilesystem(std::shared_ptr<VFS> root);
|
||||
void Mount(VFSPath path, std::shared_ptr<VFS> vfs);
|
||||
void Unmount(VFSPath path);
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenFile(VFSPath path, std::string mode);
|
||||
void CreateDirectory(VFSPath path);
|
||||
void DeleteDirectory(VFSPath path);
|
||||
bool SpecialFileExists(VFSPath path);
|
||||
bool FileExists(VFSPath path);
|
||||
bool RegularFileExists(VFSPath path);
|
||||
bool SymlinkExists(VFSPath path);
|
||||
bool CharacterDeviceExists(VFSPath path);
|
||||
bool BlockDeviceExists(VFSPath path);
|
||||
bool SocketFileExists(VFSPath path);
|
||||
bool FIFOFileExists(VFSPath path);
|
||||
bool DirectoryExists(VFSPath path);
|
||||
void DeleteFile(VFSPath path);
|
||||
void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
|
||||
VFSPathEnumerator EnumeratePaths(VFSPath path);
|
||||
void CreateHardlink(VFSPath existingFile, VFSPath newName);
|
||||
void MoveFile(VFSPath src, VFSPath dest);
|
||||
void MoveDirectory(VFSPath src, VFSPath dest);
|
||||
VFSPath ReadLink(VFSPath path);
|
||||
std::string VFSPathToSystem(VFSPath path);
|
||||
VFSPath SystemToVFSPath(std::string path);
|
||||
~MountableFilesystem();
|
||||
void GetDate(VFSPath path, Date::DateTime& lastWrite, Date::DateTime& lastAccess);
|
||||
void SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess);
|
||||
std::vector<MountableDirectory *> directories;
|
||||
|
||||
bool StatVFS(VFSPath path, StatVFSData& vfsData);
|
||||
void GetFS(VFSPath srcPath, VFSPath &destRoot, VFSPath &destPath,
|
||||
std::shared_ptr<VFS> &vfs);
|
||||
|
||||
void Chmod(VFSPath path, uint32_t mode);
|
||||
public:
|
||||
MountableFilesystem();
|
||||
MountableFilesystem(std::shared_ptr<VFS> root);
|
||||
void Mount(VFSPath path, std::shared_ptr<VFS> vfs);
|
||||
void Unmount(VFSPath path);
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream>
|
||||
OpenFile(VFSPath path, std::string mode);
|
||||
void CreateDirectory(VFSPath path);
|
||||
void DeleteDirectory(VFSPath path);
|
||||
bool Stat(VFSPath path, StatData &data);
|
||||
void DeleteFile(VFSPath path);
|
||||
void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
|
||||
VFSPathEnumerator EnumeratePaths(VFSPath path);
|
||||
void CreateHardlink(VFSPath existingFile, VFSPath newName);
|
||||
void MoveFile(VFSPath src, VFSPath dest);
|
||||
void MoveDirectory(VFSPath src, VFSPath dest);
|
||||
VFSPath ReadLink(VFSPath path);
|
||||
std::string VFSPathToSystem(VFSPath path);
|
||||
VFSPath SystemToVFSPath(std::string path);
|
||||
~MountableFilesystem();
|
||||
void SetDate(VFSPath path, Date::DateTime lastWrite,
|
||||
Date::DateTime lastAccess);
|
||||
|
||||
void Lock(VFSPath path);
|
||||
void Unlock(VFSPath path);
|
||||
};
|
||||
}
|
||||
bool StatVFS(VFSPath path, StatVFSData &vfsData);
|
||||
|
||||
void Chmod(VFSPath path, uint32_t mode);
|
||||
void Chown(VFSPath path, uint32_t uid, uint32_t gid);
|
||||
FIFOCreationResult CreateFIFO(VFSPath path, uint32_t mode);
|
||||
|
||||
void Lock(VFSPath path);
|
||||
void Unlock(VFSPath path);
|
||||
};
|
||||
} // namespace Tesses::Framework::Filesystem
|
||||
|
||||
@@ -1,21 +1,33 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "VFS.hpp"
|
||||
#include "VFSFix.hpp"
|
||||
|
||||
namespace Tesses::Framework::Filesystem
|
||||
{
|
||||
class NullFilesystem : public VFS
|
||||
{
|
||||
public:
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenFile(VFSPath path, std::string mode);
|
||||
void CreateDirectory(VFSPath path);
|
||||
void DeleteDirectory(VFSPath path);
|
||||
bool RegularFileExists(VFSPath path);
|
||||
bool DirectoryExists(VFSPath path);
|
||||
void DeleteFile(VFSPath path);
|
||||
VFSPathEnumerator EnumeratePaths(VFSPath path);
|
||||
void MoveFile(VFSPath src, VFSPath dest);
|
||||
std::string VFSPathToSystem(VFSPath path);
|
||||
VFSPath SystemToVFSPath(std::string path);
|
||||
};
|
||||
}
|
||||
|
||||
namespace Tesses::Framework::Filesystem {
|
||||
class NullFilesystem : public VFS {
|
||||
public:
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream>
|
||||
OpenFile(VFSPath path, std::string mode);
|
||||
VFSPathEnumerator EnumeratePaths(VFSPath path);
|
||||
bool Stat(VFSPath path, StatData &data);
|
||||
std::string VFSPathToSystem(VFSPath path);
|
||||
VFSPath SystemToVFSPath(std::string path);
|
||||
};
|
||||
} // namespace Tesses::Framework::Filesystem
|
||||
|
||||
78
include/TessesFramework/Filesystem/RelativeFilesystem.hpp
Normal file
78
include/TessesFramework/Filesystem/RelativeFilesystem.hpp
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "VFS.hpp"
|
||||
#include "VFSFix.hpp"
|
||||
|
||||
namespace Tesses::Framework::Filesystem {
|
||||
class RelativeFilesystem : public VFS {
|
||||
Tesses::Framework::Threading::Mutex mtx;
|
||||
VFSPath working;
|
||||
std::shared_ptr<VFS> vfs;
|
||||
|
||||
private:
|
||||
VFSPath ToParent(VFSPath path);
|
||||
|
||||
public:
|
||||
RelativeFilesystem(std::shared_ptr<VFS> vfs, VFSPath working);
|
||||
VFSPath GetWorking();
|
||||
void SetWorking(VFSPath path);
|
||||
std::shared_ptr<VFS> GetVFS();
|
||||
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream>
|
||||
OpenFile(VFSPath path, std::string mode);
|
||||
void CreateDirectory(VFSPath path);
|
||||
void DeleteDirectory(VFSPath path);
|
||||
void DeleteFile(VFSPath path);
|
||||
void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
|
||||
VFSPathEnumerator EnumeratePaths(VFSPath path);
|
||||
void CreateHardlink(VFSPath existingFile, VFSPath newName);
|
||||
void MoveFile(VFSPath src, VFSPath dest);
|
||||
void MoveDirectory(VFSPath src, VFSPath dest);
|
||||
void DeleteDirectoryRecurse(VFSPath path);
|
||||
VFSPath ReadLink(VFSPath path);
|
||||
std::string VFSPathToSystem(VFSPath path);
|
||||
VFSPath SystemToVFSPath(std::string path);
|
||||
void SetDate(VFSPath path, Date::DateTime lastWrite,
|
||||
Date::DateTime lastAccess);
|
||||
bool StatVFS(VFSPath path, StatVFSData &vfsData);
|
||||
bool Stat(VFSPath path, StatData &data);
|
||||
|
||||
void Chown(VFSPath path, uint32_t uid, uint32_t gid);
|
||||
void Chmod(VFSPath path, uint32_t mode);
|
||||
FIFOCreationResult CreateFIFO(VFSPath path, uint32_t mode);
|
||||
void Lock(VFSPath path);
|
||||
void Unlock(VFSPath path);
|
||||
|
||||
protected:
|
||||
std::shared_ptr<FSWatcher> CreateWatcher(std::shared_ptr<VFS> vfs,
|
||||
VFSPath path);
|
||||
|
||||
class Watcher : public FSWatcher {
|
||||
std::shared_ptr<FSWatcher> watcher;
|
||||
|
||||
protected:
|
||||
void SetEnabledImpl(bool enabled);
|
||||
|
||||
public:
|
||||
Watcher(std::shared_ptr<RelativeFilesystem> vfs, VFSPath path);
|
||||
~Watcher();
|
||||
};
|
||||
};
|
||||
} // namespace Tesses::Framework::Filesystem
|
||||
@@ -1,47 +1,73 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "VFS.hpp"
|
||||
#include "VFSFix.hpp"
|
||||
|
||||
namespace Tesses::Framework::Filesystem
|
||||
{
|
||||
class SubdirFilesystem : public VFS
|
||||
{
|
||||
std::shared_ptr<VFS> parent;
|
||||
VFSPath path;
|
||||
VFSPath ToParent(VFSPath path);
|
||||
VFSPath FromParent(VFSPath path);
|
||||
public:
|
||||
SubdirFilesystem(std::shared_ptr<VFS> parent, VFSPath path);
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenFile(VFSPath path, std::string mode);
|
||||
void CreateDirectory(VFSPath path);
|
||||
void DeleteDirectory(VFSPath path);
|
||||
bool SpecialFileExists(VFSPath path);
|
||||
bool FileExists(VFSPath path);
|
||||
bool RegularFileExists(VFSPath path);
|
||||
bool SymlinkExists(VFSPath path);
|
||||
bool CharacterDeviceExists(VFSPath path);
|
||||
bool BlockDeviceExists(VFSPath path);
|
||||
bool SocketFileExists(VFSPath path);
|
||||
bool FIFOFileExists(VFSPath path);
|
||||
bool DirectoryExists(VFSPath path);
|
||||
void DeleteFile(VFSPath path);
|
||||
void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
|
||||
VFSPathEnumerator EnumeratePaths(VFSPath path);
|
||||
void CreateHardlink(VFSPath existingFile, VFSPath newName);
|
||||
void MoveFile(VFSPath src, VFSPath dest);
|
||||
void MoveDirectory(VFSPath src, VFSPath dest);
|
||||
void DeleteDirectoryRecurse(VFSPath path);
|
||||
VFSPath ReadLink(VFSPath path);
|
||||
std::string VFSPathToSystem(VFSPath path);
|
||||
VFSPath SystemToVFSPath(std::string path);
|
||||
~SubdirFilesystem();
|
||||
void GetDate(VFSPath path, Date::DateTime& lastWrite, Date::DateTime& lastAccess);
|
||||
void SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess);
|
||||
bool StatVFS(VFSPath path, StatVFSData& vfsData);
|
||||
|
||||
void Chmod(VFSPath path, uint32_t mode);
|
||||
namespace Tesses::Framework::Filesystem {
|
||||
class SubdirFilesystem : public VFS {
|
||||
std::shared_ptr<VFS> parent;
|
||||
VFSPath path;
|
||||
VFSPath ToParent(VFSPath path);
|
||||
VFSPath FromParent(VFSPath path);
|
||||
|
||||
void Lock(VFSPath path);
|
||||
void Unlock(VFSPath path);
|
||||
public:
|
||||
SubdirFilesystem(std::shared_ptr<VFS> parent, VFSPath path);
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream>
|
||||
OpenFile(VFSPath path, std::string mode);
|
||||
void CreateDirectory(VFSPath path);
|
||||
void DeleteDirectory(VFSPath path);
|
||||
void DeleteFile(VFSPath path);
|
||||
void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
|
||||
VFSPathEnumerator EnumeratePaths(VFSPath path);
|
||||
void CreateHardlink(VFSPath existingFile, VFSPath newName);
|
||||
void MoveFile(VFSPath src, VFSPath dest);
|
||||
void MoveDirectory(VFSPath src, VFSPath dest);
|
||||
void DeleteDirectoryRecurse(VFSPath path);
|
||||
VFSPath ReadLink(VFSPath path);
|
||||
std::string VFSPathToSystem(VFSPath path);
|
||||
VFSPath SystemToVFSPath(std::string path);
|
||||
~SubdirFilesystem();
|
||||
void SetDate(VFSPath path, Date::DateTime lastWrite,
|
||||
Date::DateTime lastAccess);
|
||||
bool StatVFS(VFSPath path, StatVFSData &vfsData);
|
||||
bool Stat(VFSPath path, StatData &data);
|
||||
|
||||
void Chown(VFSPath path, uint32_t uid, uint32_t gid);
|
||||
void Chmod(VFSPath path, uint32_t mode);
|
||||
FIFOCreationResult CreateFIFO(VFSPath path, uint32_t mode);
|
||||
void Lock(VFSPath path);
|
||||
void Unlock(VFSPath path);
|
||||
|
||||
protected:
|
||||
std::shared_ptr<FSWatcher> CreateWatcher(std::shared_ptr<VFS> vfs,
|
||||
VFSPath path);
|
||||
|
||||
class Watcher : public FSWatcher {
|
||||
std::shared_ptr<FSWatcher> watcher;
|
||||
|
||||
protected:
|
||||
void SetEnabledImpl(bool enabled);
|
||||
|
||||
public:
|
||||
Watcher(std::shared_ptr<SubdirFilesystem> vfs, VFSPath path);
|
||||
~Watcher();
|
||||
};
|
||||
}
|
||||
};
|
||||
} // namespace Tesses::Framework::Filesystem
|
||||
|
||||
@@ -1,54 +1,71 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../Common.hpp"
|
||||
#include "VFS.hpp"
|
||||
#include "VFSFix.hpp"
|
||||
namespace Tesses::Framework::Filesystem
|
||||
{
|
||||
void UniqueString(std::string& text);
|
||||
namespace Tesses::Framework::Filesystem {
|
||||
void UniqueString(std::string &text);
|
||||
|
||||
class TempFS : public VFS
|
||||
{
|
||||
std::shared_ptr<VFS> vfs;
|
||||
bool deleteOnDestroy;
|
||||
std::shared_ptr<VFS> parent;
|
||||
std::string tmp_str;
|
||||
public:
|
||||
std::string TempDirectoryName();
|
||||
TempFS(bool deleteOnDestroy=true);
|
||||
TempFS(std::shared_ptr<VFS> vfs,bool deleteOnDestroy=true);
|
||||
class TempFS : public VFS {
|
||||
std::shared_ptr<VFS> vfs;
|
||||
bool deleteOnDestroy;
|
||||
std::shared_ptr<VFS> parent;
|
||||
std::string tmp_str;
|
||||
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenFile(VFSPath path, std::string mode);
|
||||
void CreateDirectory(VFSPath path);
|
||||
void DeleteDirectory(VFSPath path);
|
||||
bool SpecialFileExists(VFSPath path);
|
||||
bool FileExists(VFSPath path);
|
||||
bool RegularFileExists(VFSPath path);
|
||||
bool SymlinkExists(VFSPath path);
|
||||
bool CharacterDeviceExists(VFSPath path);
|
||||
bool BlockDeviceExists(VFSPath path);
|
||||
bool SocketFileExists(VFSPath path);
|
||||
bool FIFOFileExists(VFSPath path);
|
||||
bool DirectoryExists(VFSPath path);
|
||||
void DeleteFile(VFSPath path);
|
||||
void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
|
||||
VFSPathEnumerator EnumeratePaths(VFSPath path);
|
||||
void CreateHardlink(VFSPath existingFile, VFSPath newName);
|
||||
void MoveFile(VFSPath src, VFSPath dest);
|
||||
void MoveDirectory(VFSPath src, VFSPath dest);
|
||||
void DeleteDirectoryRecurse(VFSPath path);
|
||||
VFSPath ReadLink(VFSPath path);
|
||||
std::string VFSPathToSystem(VFSPath path);
|
||||
VFSPath SystemToVFSPath(std::string path);
|
||||
|
||||
void GetDate(VFSPath path, Date::DateTime& lastWrite, Date::DateTime& lastAccess);
|
||||
void SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess);
|
||||
bool StatVFS(VFSPath path, StatVFSData& vfsData);
|
||||
public:
|
||||
std::string TempDirectoryName();
|
||||
TempFS(bool deleteOnDestroy = true);
|
||||
TempFS(std::shared_ptr<VFS> vfs, bool deleteOnDestroy = true);
|
||||
|
||||
void Chmod(VFSPath path, uint32_t mode);
|
||||
void Close();
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream>
|
||||
OpenFile(VFSPath path, std::string mode);
|
||||
void CreateDirectory(VFSPath path);
|
||||
void DeleteDirectory(VFSPath path);
|
||||
void DeleteFile(VFSPath path);
|
||||
void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
|
||||
VFSPathEnumerator EnumeratePaths(VFSPath path);
|
||||
void CreateHardlink(VFSPath existingFile, VFSPath newName);
|
||||
void MoveFile(VFSPath src, VFSPath dest);
|
||||
void MoveDirectory(VFSPath src, VFSPath dest);
|
||||
void DeleteDirectoryRecurse(VFSPath path);
|
||||
VFSPath ReadLink(VFSPath path);
|
||||
std::string VFSPathToSystem(VFSPath path);
|
||||
VFSPath SystemToVFSPath(std::string path);
|
||||
|
||||
void Lock(VFSPath path);
|
||||
void Unlock(VFSPath path);
|
||||
~TempFS();
|
||||
};
|
||||
}
|
||||
void SetDate(VFSPath path, Date::DateTime lastWrite,
|
||||
Date::DateTime lastAccess);
|
||||
bool StatVFS(VFSPath path, StatVFSData &vfsData);
|
||||
bool Stat(VFSPath path, StatData &data);
|
||||
|
||||
void Chmod(VFSPath path, uint32_t mode);
|
||||
|
||||
void Chown(VFSPath path, uint32_t uid, uint32_t gid);
|
||||
FIFOCreationResult CreateFIFO(VFSPath path, uint32_t mode);
|
||||
void Close();
|
||||
|
||||
void Lock(VFSPath path);
|
||||
void Unlock(VFSPath path);
|
||||
~TempFS();
|
||||
|
||||
protected:
|
||||
std::shared_ptr<FSWatcher> CreateWatcher(std::shared_ptr<VFS> vfs,
|
||||
VFSPath path);
|
||||
};
|
||||
} // namespace Tesses::Framework::Filesystem
|
||||
|
||||
@@ -1,249 +1,336 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../Common.hpp"
|
||||
#include "../Date/Date.hpp"
|
||||
#include "../Streams/Stream.hpp"
|
||||
#include "VFSFix.hpp"
|
||||
#include <TessesFramework/Common.hpp>
|
||||
#include <TessesFramework/Date/Date.hpp>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include "../Date/Date.hpp"
|
||||
#include "VFSFix.hpp"
|
||||
|
||||
namespace Tesses::Framework::Filesystem
|
||||
{
|
||||
|
||||
class StatVFSData {
|
||||
public:
|
||||
uint64_t BlockSize;
|
||||
uint64_t FragmentSize;
|
||||
uint64_t Blocks;
|
||||
uint64_t BlocksFree;
|
||||
uint64_t BlocksAvailable;
|
||||
uint64_t TotalInodes;
|
||||
uint64_t FreeInodes;
|
||||
uint64_t AvailableInodes;
|
||||
uint64_t Id;
|
||||
uint64_t Flags;
|
||||
uint64_t MaxNameLength;
|
||||
};
|
||||
class VFSPath {
|
||||
public:
|
||||
static VFSPath CurrentDirectoryAsRelative();
|
||||
bool relative;
|
||||
static std::vector<std::string> SplitPath(std::string path);
|
||||
std::vector<std::string> path;
|
||||
VFSPath();
|
||||
explicit VFSPath(const char* path) : VFSPath(std::string(path))
|
||||
{}
|
||||
VFSPath(std::vector<std::string> path);
|
||||
VFSPath(std::string path);
|
||||
VFSPath(VFSPath p, std::string subent);
|
||||
VFSPath(VFSPath p, VFSPath p2);
|
||||
|
||||
//does not check for ?
|
||||
static VFSPath ParseUriPath(std::string path);
|
||||
namespace Tesses::Framework::Filesystem {
|
||||
|
||||
VFSPath GetParent() const;
|
||||
VFSPath CollapseRelativeParents() const;
|
||||
std::string GetFileName() const;
|
||||
bool HasExtension() const;
|
||||
std::string GetExtension() const;
|
||||
void ChangeExtension(std::string ext);
|
||||
void RemoveExtension();
|
||||
std::string ToString() const;
|
||||
struct StatVFSData {
|
||||
|
||||
static VFSPath GetAbsoluteCurrentDirectory();
|
||||
static void SetAbsoluteCurrentDirectory(VFSPath path);
|
||||
VFSPath MakeAbsolute() const;
|
||||
|
||||
VFSPath MakeAbsolute(VFSPath curDir) const;
|
||||
VFSPath MakeRelative() const;
|
||||
VFSPath MakeRelative(VFSPath toMakeRelativeTo) const;
|
||||
};
|
||||
VFSPath operator/(VFSPath p, VFSPath p2);
|
||||
VFSPath operator/(VFSPath p, std::string p2);
|
||||
VFSPath operator/(std::string p, VFSPath p2);
|
||||
VFSPath operator+(VFSPath p, VFSPath p2);
|
||||
VFSPath operator+(VFSPath p, std::string p2);
|
||||
VFSPath operator+(std::string p, VFSPath p2);
|
||||
bool operator==(VFSPath p,VFSPath p2);
|
||||
bool operator!=(VFSPath p,VFSPath p2);
|
||||
bool operator==(std::string p,VFSPath p2);
|
||||
bool operator!=(std::string p,VFSPath p2);
|
||||
bool operator==(VFSPath p,std::string p2);
|
||||
bool operator!=(VFSPath p,std::string p2);
|
||||
class VFSPathEnumeratorData {
|
||||
public:
|
||||
VFSPathEnumeratorData(std::function<bool(VFSPath&)> moveNext, std::function<void()> destroy)
|
||||
{
|
||||
this->eof=false;
|
||||
this->moveNext=moveNext;
|
||||
this->destroy=destroy;
|
||||
}
|
||||
bool eof;
|
||||
std::function<bool(VFSPath&)> moveNext;
|
||||
std::function<void()> destroy;
|
||||
~VFSPathEnumeratorData()
|
||||
{
|
||||
this->destroy();
|
||||
}
|
||||
};
|
||||
uint64_t BlockSize;
|
||||
uint64_t FragmentSize;
|
||||
uint64_t Blocks;
|
||||
uint64_t BlocksFree;
|
||||
uint64_t BlocksAvailable;
|
||||
uint64_t TotalInodes;
|
||||
uint64_t FreeInodes;
|
||||
uint64_t AvailableInodes;
|
||||
uint64_t Id;
|
||||
uint64_t Flags;
|
||||
uint64_t MaxNameLength;
|
||||
};
|
||||
|
||||
class VFSPathEnumerator;
|
||||
constexpr uint32_t MODE_USER_READ = 0400;
|
||||
constexpr uint32_t MODE_USER_WRITE = 0200;
|
||||
constexpr uint32_t MODE_USER_EXEC = 0100;
|
||||
|
||||
class VFSPathEnumeratorItterator
|
||||
{
|
||||
VFSPath e;
|
||||
VFSPathEnumerator* enumerator;
|
||||
public:
|
||||
VFSPathEnumeratorItterator();
|
||||
VFSPathEnumeratorItterator(VFSPathEnumerator* enumerator);
|
||||
constexpr uint32_t MODE_GROUP_READ = (MODE_USER_READ >> 3);
|
||||
constexpr uint32_t MODE_GROUP_WRITE = (MODE_USER_WRITE >> 3);
|
||||
constexpr uint32_t MODE_GROUP_EXEC = (MODE_USER_EXEC >> 3);
|
||||
|
||||
VFSPathEnumeratorItterator& operator++();
|
||||
VFSPathEnumeratorItterator& operator++(int);
|
||||
|
||||
VFSPath& operator*();
|
||||
VFSPath* operator->();
|
||||
|
||||
bool operator!=(VFSPathEnumeratorItterator right);
|
||||
bool operator==(VFSPathEnumeratorItterator right);
|
||||
};
|
||||
constexpr uint32_t MODE_OTHER_READ = (MODE_GROUP_READ >> 3);
|
||||
constexpr uint32_t MODE_OTHER_WRITE = (MODE_GROUP_WRITE >> 3);
|
||||
constexpr uint32_t MODE_OTHER_EXEC = (MODE_GROUP_EXEC >> 3);
|
||||
|
||||
class VFSPathEnumerator {
|
||||
std::shared_ptr<VFSPathEnumeratorData> data;
|
||||
public:
|
||||
VFSPathEnumerator();
|
||||
VFSPathEnumerator* MakePointer();
|
||||
VFSPathEnumerator(std::function<bool(VFSPath&)> moveNext, std::function<void()> destroy);
|
||||
VFSPath Current;
|
||||
bool MoveNext();
|
||||
bool IsDone();
|
||||
constexpr uint32_t MODE_REGULAR = 0100000;
|
||||
constexpr uint32_t MODE_DIRECTORY = 0040000;
|
||||
constexpr uint32_t MODE_CHAR_DEVICE = 0020000;
|
||||
constexpr uint32_t MODE_BLOCK_DEVICE = 0060000;
|
||||
constexpr uint32_t MODE_SOCKET = 0140000;
|
||||
constexpr uint32_t MODE_FIFO = 0010000;
|
||||
constexpr uint32_t MODE_SYMLINK = 0120000;
|
||||
|
||||
VFSPathEnumeratorItterator begin();
|
||||
struct StatData {
|
||||
uint64_t Device;
|
||||
uint64_t Inode;
|
||||
uint32_t Mode;
|
||||
uint64_t HardLinks;
|
||||
uint32_t UserId;
|
||||
uint32_t GroupId;
|
||||
uint64_t DeviceId;
|
||||
uint64_t Size;
|
||||
uint64_t BlockSize;
|
||||
uint64_t BlockCount;
|
||||
Date::DateTime LastAccess;
|
||||
Date::DateTime LastModified;
|
||||
Date::DateTime LastStatus;
|
||||
|
||||
VFSPathEnumeratorItterator end();
|
||||
};
|
||||
enum class FSWatcherEventType {
|
||||
bool IsRegularFile() { return (Mode & MODE_REGULAR) > 0; }
|
||||
bool IsDirectory() { return (Mode & MODE_DIRECTORY) > 0; }
|
||||
|
||||
None = 0,
|
||||
//IN_ACCESS
|
||||
Accessed=1,
|
||||
//IN_ATTRIB
|
||||
AttributeChanged =2,
|
||||
//IN_CLOSE_WRITE
|
||||
Writen = 4,
|
||||
//IN_CLOSE_NOWRITE
|
||||
Read = 8,
|
||||
//IN_CREATE
|
||||
Created = 16,
|
||||
//IN_DELETE
|
||||
Deleted = 32,
|
||||
//IN_DELETE_SELF
|
||||
WatchEntryDeleted = 64,
|
||||
//IN_MODIFY
|
||||
Modified = 128,
|
||||
//IN_MOVE_SELF
|
||||
WatchEntryMoved = 256,
|
||||
//IN_MOVED_FROM
|
||||
MoveOld = 512,
|
||||
//IN_MOVED_TO
|
||||
MoveNew = 1024,
|
||||
//IN_OPEN
|
||||
Opened = 2048,
|
||||
//IN_CLOSE
|
||||
Closed = Writen | Read,
|
||||
//IN_MOVE
|
||||
Moved = MoveOld | MoveNew,
|
||||
//IN_ALL_EVENTS
|
||||
All = Accessed | AttributeChanged | Created | Deleted | WatchEntryDeleted | Modified | WatchEntryMoved | Opened | Closed | Moved
|
||||
};
|
||||
struct FSWatcherEvent {
|
||||
//the file or source on move
|
||||
VFSPath src;
|
||||
//the dest when moving
|
||||
VFSPath dest;
|
||||
FSWatcherEventType type;
|
||||
bool isDir;
|
||||
bool IsCharDevice() { return (Mode & MODE_CHAR_DEVICE) > 0; }
|
||||
|
||||
bool IsEvent(FSWatcherEventType e);
|
||||
bool IsBlockDevice() { return (Mode & MODE_BLOCK_DEVICE) > 0; }
|
||||
|
||||
std::string ToString();
|
||||
};
|
||||
class VFS;
|
||||
bool IsSocket() { return (Mode & MODE_SOCKET) > 0; }
|
||||
bool IsFIFO() { return (Mode & MODE_FIFO) > 0; }
|
||||
|
||||
class FSWatcher {
|
||||
private:
|
||||
std::shared_ptr<VFS> vfs;
|
||||
VFSPath path;
|
||||
protected:
|
||||
bool IsSymlink() { return (Mode & MODE_SYMLINK) > 0; }
|
||||
|
||||
std::atomic<bool> enabled=false;
|
||||
virtual void SetEnabledImpl(bool enabled);
|
||||
public:
|
||||
FSWatcher(std::shared_ptr<VFS> vfs, VFSPath path);
|
||||
std::function<void(FSWatcherEvent&)> event;
|
||||
FSWatcherEventType events = FSWatcherEventType::All;
|
||||
bool GetEnabled();
|
||||
void SetEnabled(bool val);
|
||||
std::shared_ptr<VFS> GetFilesystem();
|
||||
const VFSPath& GetPath();
|
||||
virtual ~FSWatcher() = default;
|
||||
|
||||
static std::shared_ptr<FSWatcher> Create(std::shared_ptr<VFS> vfs, VFSPath path);
|
||||
};
|
||||
|
||||
class VFS {
|
||||
public:
|
||||
|
||||
virtual std::shared_ptr<Tesses::Framework::Streams::Stream> OpenFile(VFSPath path, std::string mode)=0;
|
||||
virtual void CreateDirectory(VFSPath path)=0;
|
||||
virtual void DeleteDirectory(VFSPath path)=0;
|
||||
virtual bool RegularFileExists(VFSPath path)=0;
|
||||
virtual bool SymlinkExists(VFSPath path);
|
||||
virtual bool CharacterDeviceExists(VFSPath path);
|
||||
virtual bool BlockDeviceExists(VFSPath path);
|
||||
virtual bool SocketFileExists(VFSPath path);
|
||||
virtual bool FIFOFileExists(VFSPath path);
|
||||
virtual bool FileExists(VFSPath path);
|
||||
virtual bool SpecialFileExists(VFSPath path);
|
||||
virtual void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
|
||||
virtual void CreateHardlink(VFSPath existingFile, VFSPath newName);
|
||||
virtual bool DirectoryExists(VFSPath path)=0;
|
||||
virtual void DeleteFile(VFSPath path)=0;
|
||||
virtual void DeleteDirectoryRecurse(VFSPath path);
|
||||
virtual VFSPathEnumerator EnumeratePaths(VFSPath path) = 0;
|
||||
virtual void MoveFile(VFSPath src, VFSPath dest)=0;
|
||||
virtual void MoveDirectory(VFSPath src, VFSPath dest);
|
||||
virtual VFSPath ReadLink(VFSPath path);
|
||||
virtual std::string VFSPathToSystem(VFSPath path)=0;
|
||||
virtual VFSPath SystemToVFSPath(std::string path)=0;
|
||||
|
||||
|
||||
virtual void GetDate(VFSPath path, Date::DateTime& lastWrite, Date::DateTime& lastAccess);
|
||||
virtual void SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess);
|
||||
|
||||
virtual bool StatVFS(VFSPath path, StatVFSData& data);
|
||||
|
||||
virtual void Chmod(VFSPath path, uint32_t mode);
|
||||
|
||||
virtual void Lock(VFSPath path);
|
||||
virtual void Unlock(VFSPath path);
|
||||
|
||||
|
||||
virtual ~VFS();
|
||||
|
||||
virtual void Close();
|
||||
|
||||
protected:
|
||||
virtual std::shared_ptr<FSWatcher> CreateWatcher(std::shared_ptr<VFS> vfs, VFSPath path);
|
||||
friend class FSWatcher;
|
||||
};
|
||||
|
||||
|
||||
|
||||
namespace Literals
|
||||
{
|
||||
inline VFSPath operator""_tpath(const char* path)
|
||||
{
|
||||
return VFSPath(path);
|
||||
}
|
||||
bool IsSpecial() {
|
||||
if (IsRegularFile())
|
||||
return false;
|
||||
if (IsDirectory())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
std::string ToSizeString(bool usesBin = true) {
|
||||
return TF_FileSize(this->Size, usesBin);
|
||||
}
|
||||
};
|
||||
class VFSPath {
|
||||
public:
|
||||
static VFSPath CurrentDirectoryAsRelative();
|
||||
bool relative;
|
||||
static std::vector<std::string> SplitPath(std::string path);
|
||||
std::vector<std::string> path;
|
||||
VFSPath();
|
||||
explicit VFSPath(const char *path) : VFSPath(std::string(path)) {}
|
||||
VFSPath(std::vector<std::string> path);
|
||||
VFSPath(std::string path);
|
||||
VFSPath(VFSPath p, std::string subent);
|
||||
VFSPath(VFSPath p, VFSPath p2);
|
||||
|
||||
// does not check for ?
|
||||
static VFSPath ParseUriPath(std::string path);
|
||||
|
||||
VFSPath GetParent() const;
|
||||
VFSPath CollapseRelativeParents() const;
|
||||
std::string GetFileName() const;
|
||||
bool HasExtension() const;
|
||||
std::string GetExtension() const;
|
||||
void ChangeExtension(std::string ext);
|
||||
void RemoveExtension();
|
||||
std::string ToString() const;
|
||||
|
||||
static VFSPath GetAbsoluteCurrentDirectory();
|
||||
static void SetAbsoluteCurrentDirectory(VFSPath path);
|
||||
VFSPath MakeAbsolute() const;
|
||||
|
||||
VFSPath MakeAbsolute(VFSPath curDir) const;
|
||||
VFSPath MakeRelative() const;
|
||||
VFSPath MakeRelative(VFSPath toMakeRelativeTo) const;
|
||||
};
|
||||
VFSPath operator/(VFSPath p, VFSPath p2);
|
||||
VFSPath operator/(VFSPath p, std::string p2);
|
||||
VFSPath operator/(std::string p, VFSPath p2);
|
||||
VFSPath operator+(VFSPath p, VFSPath p2);
|
||||
VFSPath operator+(VFSPath p, std::string p2);
|
||||
VFSPath operator+(std::string p, VFSPath p2);
|
||||
bool operator==(VFSPath p, VFSPath p2);
|
||||
bool operator!=(VFSPath p, VFSPath p2);
|
||||
bool operator==(std::string p, VFSPath p2);
|
||||
bool operator!=(std::string p, VFSPath p2);
|
||||
bool operator==(VFSPath p, std::string p2);
|
||||
bool operator!=(VFSPath p, std::string p2);
|
||||
class VFSPathEnumeratorData {
|
||||
public:
|
||||
VFSPathEnumeratorData(std::function<bool(VFSPath &)> moveNext,
|
||||
std::function<void()> destroy) {
|
||||
this->eof = false;
|
||||
this->moveNext = moveNext;
|
||||
this->destroy = destroy;
|
||||
}
|
||||
bool eof;
|
||||
std::function<bool(VFSPath &)> moveNext;
|
||||
std::function<void()> destroy;
|
||||
~VFSPathEnumeratorData() { this->destroy(); }
|
||||
};
|
||||
|
||||
class VFSPathEnumerator;
|
||||
|
||||
class VFSPathEnumeratorItterator {
|
||||
VFSPath e;
|
||||
VFSPathEnumerator *enumerator;
|
||||
|
||||
public:
|
||||
VFSPathEnumeratorItterator();
|
||||
VFSPathEnumeratorItterator(VFSPathEnumerator *enumerator);
|
||||
|
||||
VFSPathEnumeratorItterator &operator++();
|
||||
VFSPathEnumeratorItterator &operator++(int);
|
||||
|
||||
VFSPath &operator*();
|
||||
VFSPath *operator->();
|
||||
|
||||
bool operator!=(VFSPathEnumeratorItterator right);
|
||||
bool operator==(VFSPathEnumeratorItterator right);
|
||||
};
|
||||
|
||||
class VFSPathEnumerator {
|
||||
std::shared_ptr<VFSPathEnumeratorData> data;
|
||||
|
||||
public:
|
||||
VFSPathEnumerator();
|
||||
VFSPathEnumerator *MakePointer();
|
||||
VFSPathEnumerator(std::function<bool(VFSPath &)> moveNext,
|
||||
std::function<void()> destroy);
|
||||
VFSPath Current;
|
||||
bool MoveNext();
|
||||
bool IsDone();
|
||||
|
||||
VFSPathEnumeratorItterator begin();
|
||||
|
||||
VFSPathEnumeratorItterator end();
|
||||
};
|
||||
enum class FSWatcherEventType {
|
||||
|
||||
None = 0,
|
||||
// IN_ACCESS
|
||||
Accessed = 1,
|
||||
// IN_ATTRIB
|
||||
AttributeChanged = 2,
|
||||
// IN_CLOSE_WRITE
|
||||
Writen = 4,
|
||||
// IN_CLOSE_NOWRITE
|
||||
Read = 8,
|
||||
// IN_CREATE
|
||||
Created = 16,
|
||||
// IN_DELETE
|
||||
Deleted = 32,
|
||||
// IN_DELETE_SELF
|
||||
WatchEntryDeleted = 64,
|
||||
// IN_MODIFY
|
||||
Modified = 128,
|
||||
// IN_MOVE_SELF
|
||||
WatchEntryMoved = 256,
|
||||
// IN_MOVED_FROM
|
||||
MoveOld = 512,
|
||||
// IN_MOVED_TO
|
||||
MoveNew = 1024,
|
||||
// IN_OPEN
|
||||
Opened = 2048,
|
||||
// IN_CLOSE
|
||||
Closed = Writen | Read,
|
||||
// IN_MOVE
|
||||
Moved = MoveOld | MoveNew,
|
||||
// IN_ALL_EVENTS
|
||||
All = Accessed | AttributeChanged | Created | Deleted | WatchEntryDeleted |
|
||||
Modified | WatchEntryMoved | Opened | Closed | Moved
|
||||
};
|
||||
struct FSWatcherEvent {
|
||||
// the file or source on move
|
||||
VFSPath src;
|
||||
// the dest when moving
|
||||
VFSPath dest;
|
||||
FSWatcherEventType type;
|
||||
bool isDir;
|
||||
|
||||
bool IsEvent(FSWatcherEventType e);
|
||||
|
||||
std::string ToString();
|
||||
};
|
||||
class VFS;
|
||||
|
||||
class FSWatcher {
|
||||
private:
|
||||
std::shared_ptr<VFS> vfs;
|
||||
VFSPath path;
|
||||
|
||||
protected:
|
||||
std::atomic<bool> enabled = false;
|
||||
virtual void SetEnabledImpl(bool enabled);
|
||||
|
||||
public:
|
||||
FSWatcher(std::shared_ptr<VFS> vfs, VFSPath path);
|
||||
std::function<void(FSWatcherEvent &)> event;
|
||||
FSWatcherEventType events = FSWatcherEventType::All;
|
||||
bool GetEnabled();
|
||||
void SetEnabled(bool val);
|
||||
std::shared_ptr<VFS> GetFilesystem();
|
||||
const VFSPath &GetPath();
|
||||
virtual ~FSWatcher() = default;
|
||||
|
||||
static std::shared_ptr<FSWatcher> Create(std::shared_ptr<VFS> vfs,
|
||||
VFSPath path);
|
||||
};
|
||||
|
||||
enum class FIFOCreationResult {
|
||||
Success = 0,
|
||||
Exists = 1,
|
||||
ReadOnlyFS = 2,
|
||||
Denied = 3,
|
||||
OutOfInodes = 4,
|
||||
UnknownError = 5,
|
||||
Unsupported = 255
|
||||
};
|
||||
|
||||
class VFS {
|
||||
public:
|
||||
virtual std::shared_ptr<Tesses::Framework::Streams::Stream>
|
||||
OpenFile(VFSPath path, std::string mode) = 0;
|
||||
virtual void CreateDirectory(VFSPath path);
|
||||
virtual void DeleteDirectory(VFSPath path);
|
||||
bool DirectoryExists(VFSPath path);
|
||||
bool RegularFileExists(VFSPath path);
|
||||
bool SymlinkExists(VFSPath path);
|
||||
bool CharacterDeviceExists(VFSPath path);
|
||||
bool BlockDeviceExists(VFSPath path);
|
||||
bool SocketFileExists(VFSPath path);
|
||||
bool FIFOFileExists(VFSPath path);
|
||||
bool FileExists(VFSPath path);
|
||||
bool SpecialFileExists(VFSPath path);
|
||||
virtual void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
|
||||
virtual void CreateHardlink(VFSPath existingFile, VFSPath newName);
|
||||
virtual void DeleteFile(VFSPath path);
|
||||
virtual void DeleteDirectoryRecurse(VFSPath path);
|
||||
virtual VFSPathEnumerator EnumeratePaths(VFSPath path) = 0;
|
||||
virtual void MoveFile(VFSPath src, VFSPath dest);
|
||||
virtual void MoveDirectory(VFSPath src, VFSPath dest);
|
||||
virtual VFSPath ReadLink(VFSPath path);
|
||||
virtual std::string VFSPathToSystem(VFSPath path) = 0;
|
||||
virtual VFSPath SystemToVFSPath(std::string path) = 0;
|
||||
|
||||
void GetDate(VFSPath path, Date::DateTime &lastWrite,
|
||||
Date::DateTime &lastAccess);
|
||||
virtual void SetDate(VFSPath path, Date::DateTime lastWrite,
|
||||
Date::DateTime lastAccess);
|
||||
|
||||
virtual bool Stat(VFSPath path, StatData &data) = 0;
|
||||
virtual bool StatVFS(VFSPath path, StatVFSData &data);
|
||||
|
||||
virtual void Chmod(VFSPath path, uint32_t mode);
|
||||
virtual void Chown(VFSPath path, uint32_t userId, uint32_t groupId);
|
||||
|
||||
virtual void Lock(VFSPath path);
|
||||
virtual void Unlock(VFSPath path);
|
||||
virtual FIFOCreationResult CreateFIFO(VFSPath path, uint32_t mode);
|
||||
|
||||
virtual ~VFS();
|
||||
|
||||
virtual void Close();
|
||||
|
||||
protected:
|
||||
virtual std::shared_ptr<FSWatcher> CreateWatcher(std::shared_ptr<VFS> vfs,
|
||||
VFSPath path);
|
||||
friend class FSWatcher;
|
||||
};
|
||||
|
||||
namespace Literals {
|
||||
inline VFSPath operator""_tpath(const char *path) { return VFSPath(path); }
|
||||
} // namespace Literals
|
||||
} // namespace Tesses::Framework::Filesystem
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#undef CreateDirectory
|
||||
#undef DeleteDirectory
|
||||
#undef DeleteFile
|
||||
|
||||
@@ -1,32 +1,45 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace Tesses::Framework {
|
||||
class HiddenFieldData {
|
||||
public:
|
||||
virtual ~HiddenFieldData();
|
||||
public:
|
||||
virtual ~HiddenFieldData();
|
||||
};
|
||||
|
||||
class HiddenField {
|
||||
private:
|
||||
HiddenFieldData* ptr;
|
||||
public:
|
||||
HiddenField();
|
||||
HiddenField(HiddenFieldData* data);
|
||||
void SetField(HiddenFieldData* data);
|
||||
template<typename T>
|
||||
T GetField()
|
||||
{
|
||||
return dynamic_cast<T>(ptr);
|
||||
}
|
||||
template<typename T>
|
||||
T* AllocField()
|
||||
{
|
||||
auto v = new T();
|
||||
SetField(v);
|
||||
return v;
|
||||
}
|
||||
~HiddenField();
|
||||
private:
|
||||
HiddenFieldData *ptr;
|
||||
|
||||
public:
|
||||
HiddenField();
|
||||
HiddenField(HiddenFieldData *data);
|
||||
void SetField(HiddenFieldData *data);
|
||||
template <typename T> T GetField() { return dynamic_cast<T>(ptr); }
|
||||
template <typename T> T *AllocField() {
|
||||
auto v = new T();
|
||||
SetField(v);
|
||||
return v;
|
||||
}
|
||||
~HiddenField();
|
||||
};
|
||||
}
|
||||
} // namespace Tesses::Framework
|
||||
@@ -1,18 +1,39 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "HttpServer.hpp"
|
||||
namespace Tesses::Framework::Http {
|
||||
class BasicAuthServer : public Tesses::Framework::Http::IHttpServer
|
||||
{
|
||||
public:
|
||||
std::shared_ptr<IHttpServer> server;
|
||||
std::function<bool(std::string username, std::string password)> authorization;
|
||||
std::string realm;
|
||||
class BasicAuthServer : public Tesses::Framework::Http::IHttpServer {
|
||||
public:
|
||||
std::shared_ptr<IHttpServer> server;
|
||||
std::function<bool(std::string username, std::string password)>
|
||||
authorization;
|
||||
std::string realm;
|
||||
|
||||
BasicAuthServer();
|
||||
BasicAuthServer(std::shared_ptr<IHttpServer> server, std::function<bool(std::string username, std::string password)> auth,std::string realm="Protected Content");
|
||||
bool Handle(ServerContext& ctx);
|
||||
BasicAuthServer();
|
||||
BasicAuthServer(
|
||||
std::shared_ptr<IHttpServer> server,
|
||||
std::function<bool(std::string username, std::string password)> auth,
|
||||
std::string realm = "Protected Content");
|
||||
bool Handle(ServerContext &ctx);
|
||||
|
||||
|
||||
static bool GetCreds(ServerContext& ctx, std::string& user, std::string& pass);
|
||||
};
|
||||
}
|
||||
static bool GetCreds(ServerContext &ctx, std::string &user,
|
||||
std::string &pass);
|
||||
};
|
||||
} // namespace Tesses::Framework::Http
|
||||
@@ -1,23 +1,42 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../Filesystem/VFS.hpp"
|
||||
#include "../Filesystem/VFSFix.hpp"
|
||||
#include "HttpServer.hpp"
|
||||
#include <optional>
|
||||
namespace Tesses::Framework::Http {
|
||||
struct CGIParams {
|
||||
std::optional<Tesses::Framework::Filesystem::VFSPath> document_root;
|
||||
Tesses::Framework::Filesystem::VFSPath program;
|
||||
std::optional<std::string> adminEmail;
|
||||
std::optional<Tesses::Framework::Filesystem::VFSPath> workingDirectory;
|
||||
};
|
||||
class CGIServer : public Tesses::Framework::Http::IHttpServer {
|
||||
Tesses::Framework::Filesystem::VFSPath dir;
|
||||
public:
|
||||
std::optional<Tesses::Framework::Filesystem::VFSPath> document_root;
|
||||
std::optional<std::string> adminEmail;
|
||||
std::optional<Tesses::Framework::Filesystem::VFSPath> workingDirectory;
|
||||
CGIServer(Tesses::Framework::Filesystem::VFSPath dir);
|
||||
bool Handle(ServerContext& ctx);
|
||||
static bool ServeCGIRequest(ServerContext& ctx, CGIParams& params);
|
||||
};
|
||||
}
|
||||
struct CGIParams {
|
||||
std::optional<Tesses::Framework::Filesystem::VFSPath> document_root;
|
||||
Tesses::Framework::Filesystem::VFSPath program;
|
||||
std::optional<std::string> adminEmail;
|
||||
std::optional<Tesses::Framework::Filesystem::VFSPath> workingDirectory;
|
||||
};
|
||||
class CGIServer : public Tesses::Framework::Http::IHttpServer {
|
||||
Tesses::Framework::Filesystem::VFSPath dir;
|
||||
|
||||
public:
|
||||
std::optional<Tesses::Framework::Filesystem::VFSPath> document_root;
|
||||
std::optional<std::string> adminEmail;
|
||||
std::optional<Tesses::Framework::Filesystem::VFSPath> workingDirectory;
|
||||
CGIServer(Tesses::Framework::Filesystem::VFSPath dir);
|
||||
bool Handle(ServerContext &ctx);
|
||||
static bool ServeCGIRequest(ServerContext &ctx, CGIParams ¶ms);
|
||||
};
|
||||
} // namespace Tesses::Framework::Http
|
||||
@@ -1,16 +1,34 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "HttpServer.hpp"
|
||||
|
||||
namespace Tesses::Framework::Http
|
||||
{
|
||||
class CallbackServer : public IHttpServer
|
||||
{
|
||||
std::function<bool(ServerContext&)> cb;
|
||||
std::function<void()> destroy;
|
||||
public:
|
||||
CallbackServer(std::function<bool(ServerContext&)> cb);
|
||||
CallbackServer(std::function<bool(ServerContext&)> cb,std::function<void()> destroy);
|
||||
bool Handle(ServerContext& ctx);
|
||||
~CallbackServer();
|
||||
};
|
||||
}
|
||||
namespace Tesses::Framework::Http {
|
||||
class CallbackServer : public IHttpServer {
|
||||
std::function<bool(ServerContext &)> cb;
|
||||
std::function<void()> destroy;
|
||||
|
||||
public:
|
||||
CallbackServer(std::function<bool(ServerContext &)> cb);
|
||||
CallbackServer(std::function<bool(ServerContext &)> cb,
|
||||
std::function<void()> destroy);
|
||||
bool Handle(ServerContext &ctx);
|
||||
~CallbackServer();
|
||||
};
|
||||
} // namespace Tesses::Framework::Http
|
||||
@@ -1,14 +1,31 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "HttpServer.hpp"
|
||||
|
||||
namespace Tesses::Framework::Http
|
||||
{
|
||||
class ChangeableServer {
|
||||
public:
|
||||
ChangeableServer();
|
||||
ChangeableServer(std::shared_ptr<IHttpServer> original);
|
||||
std::shared_ptr<IHttpServer> server;
|
||||
bool Handle(ServerContext& ctx);
|
||||
~ChangeableServer();
|
||||
};
|
||||
}
|
||||
namespace Tesses::Framework::Http {
|
||||
class ChangeableServer {
|
||||
public:
|
||||
ChangeableServer();
|
||||
ChangeableServer(std::shared_ptr<IHttpServer> original);
|
||||
std::shared_ptr<IHttpServer> server;
|
||||
bool Handle(ServerContext &ctx);
|
||||
~ChangeableServer();
|
||||
};
|
||||
} // namespace Tesses::Framework::Http
|
||||
@@ -1,13 +1,30 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../Common.hpp"
|
||||
namespace Tesses::Framework::Http
|
||||
{
|
||||
class ContentDisposition {
|
||||
public:
|
||||
std::string filename;
|
||||
std::string type;
|
||||
std::string fieldName;
|
||||
static bool TryParse(std::string str, ContentDisposition& cd);
|
||||
std::string ToString();
|
||||
};
|
||||
}
|
||||
namespace Tesses::Framework::Http {
|
||||
class ContentDisposition {
|
||||
public:
|
||||
std::string filename;
|
||||
std::string type;
|
||||
std::string fieldName;
|
||||
static bool TryParse(std::string str, ContentDisposition &cd);
|
||||
std::string ToString();
|
||||
};
|
||||
} // namespace Tesses::Framework::Http
|
||||
@@ -1,25 +1,45 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../Filesystem/VFS.hpp"
|
||||
#include "HttpServer.hpp"
|
||||
|
||||
namespace Tesses::Framework::Http
|
||||
{
|
||||
class FileServer : public IHttpServer
|
||||
{
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs;
|
||||
|
||||
|
||||
namespace Tesses::Framework::Http {
|
||||
class FileServer : public IHttpServer {
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs;
|
||||
|
||||
bool SendFile(ServerContext& ctx,Tesses::Framework::Filesystem::VFSPath path);
|
||||
public:
|
||||
bool allowListing;
|
||||
bool spa;
|
||||
std::vector<std::string> defaultNames;
|
||||
FileServer(std::filesystem::path path,bool allowListing,bool spa);
|
||||
FileServer(std::filesystem::path path,bool allowListing, bool spa, std::vector<std::string> defaultNames);
|
||||
FileServer(std::shared_ptr<Tesses::Framework::Filesystem::VFS> fs, bool allowListing, bool spa);
|
||||
FileServer(std::shared_ptr<Tesses::Framework::Filesystem::VFS> fs, bool allowListing, bool spa, std::vector<std::string> defaultNames);
|
||||
bool Handle(ServerContext& ctx);
|
||||
~FileServer();
|
||||
};
|
||||
}
|
||||
bool SendFile(ServerContext &ctx,
|
||||
Tesses::Framework::Filesystem::VFSPath path);
|
||||
|
||||
public:
|
||||
bool allowListing;
|
||||
bool spa;
|
||||
std::vector<std::string> defaultNames;
|
||||
FileServer(std::filesystem::path path, bool allowListing, bool spa);
|
||||
FileServer(std::filesystem::path path, bool allowListing, bool spa,
|
||||
std::vector<std::string> defaultNames);
|
||||
FileServer(std::shared_ptr<Tesses::Framework::Filesystem::VFS> fs,
|
||||
bool allowListing, bool spa);
|
||||
FileServer(std::shared_ptr<Tesses::Framework::Filesystem::VFS> fs,
|
||||
bool allowListing, bool spa,
|
||||
std::vector<std::string> defaultNames);
|
||||
bool Handle(ServerContext &ctx);
|
||||
~FileServer();
|
||||
};
|
||||
} // namespace Tesses::Framework::Http
|
||||
@@ -1,95 +1,141 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../Streams/Stream.hpp"
|
||||
#include "HttpUtils.hpp"
|
||||
#include "WebSocket.hpp"
|
||||
// clang-format off
|
||||
#include "TessesFramework/Filesystem/LocalFS.hpp"
|
||||
#include "TessesFramework/Filesystem/VFSFix.hpp"
|
||||
namespace Tesses::Framework::Http
|
||||
{
|
||||
|
||||
class HttpRequestBody {
|
||||
public:
|
||||
virtual void HandleHeaders(HttpDictionary& dict);
|
||||
virtual void Write(std::shared_ptr<Tesses::Framework::Streams::Stream> strm)=0;
|
||||
virtual ~HttpRequestBody();
|
||||
};
|
||||
// clang-format on
|
||||
#include "WebSocket.hpp"
|
||||
namespace Tesses::Framework::Http {
|
||||
|
||||
class StreamHttpRequestBody : public HttpRequestBody {
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> strm;
|
||||
|
||||
std::string mimeType;
|
||||
public:
|
||||
StreamHttpRequestBody(std::shared_ptr<Tesses::Framework::Streams::Stream> strm, std::string mimeType);
|
||||
void HandleHeaders(HttpDictionary& dict);
|
||||
void Write(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
~StreamHttpRequestBody();
|
||||
};
|
||||
class HttpRequestBody {
|
||||
public:
|
||||
virtual void HandleHeaders(HttpDictionary &dict);
|
||||
virtual void
|
||||
Write(std::shared_ptr<Tesses::Framework::Streams::Stream> strm) = 0;
|
||||
virtual ~HttpRequestBody();
|
||||
};
|
||||
|
||||
class TextHttpRequestBody : public HttpRequestBody {
|
||||
std::string text;
|
||||
std::string mimeType;
|
||||
public:
|
||||
TextHttpRequestBody(std::string text, std::string mimeType);
|
||||
void HandleHeaders(HttpDictionary& dict);
|
||||
void Write(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
~TextHttpRequestBody();
|
||||
};
|
||||
class StreamHttpRequestBody : public HttpRequestBody {
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> strm;
|
||||
|
||||
std::string mimeType;
|
||||
|
||||
class HttpRequest {
|
||||
public:
|
||||
HttpRequest();
|
||||
std::string trusted_root_cert_bundle;
|
||||
bool ignoreSSLErrors;
|
||||
bool followRedirects;
|
||||
public:
|
||||
StreamHttpRequestBody(
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> strm,
|
||||
std::string mimeType);
|
||||
void HandleHeaders(HttpDictionary &dict);
|
||||
void Write(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
~StreamHttpRequestBody();
|
||||
};
|
||||
|
||||
std::string method;
|
||||
std::string url;
|
||||
std::string unixSocket;
|
||||
HttpDictionary requestHeaders;
|
||||
HttpRequestBody* body;
|
||||
class TextHttpRequestBody : public HttpRequestBody {
|
||||
std::string text;
|
||||
std::string mimeType;
|
||||
|
||||
static std::shared_ptr<Tesses::Framework::Streams::Stream> EstablishConnection(Uri uri,bool ignoreSSLErrors,std::string trusted_root_cert_bundle);
|
||||
static std::shared_ptr<Tesses::Framework::Streams::Stream> EstablishUnixPathConnection(std::string unixPath, Uri uri, bool ignoreSSLErrors, std::string trusted_root_cert_bundle);
|
||||
public:
|
||||
TextHttpRequestBody(std::string text, std::string mimeType);
|
||||
void HandleHeaders(HttpDictionary &dict);
|
||||
void Write(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
~TextHttpRequestBody();
|
||||
};
|
||||
|
||||
void SendRequest(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
};
|
||||
class HttpRequest {
|
||||
public:
|
||||
HttpRequest();
|
||||
std::string trusted_root_cert_bundle;
|
||||
bool ignoreSSLErrors;
|
||||
bool followRedirects;
|
||||
|
||||
class HttpResponse {
|
||||
private:
|
||||
bool owns;
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> handleStrm;
|
||||
public:
|
||||
HttpResponse(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
HttpResponse(HttpRequest& request);
|
||||
std::string version;
|
||||
StatusCode statusCode;
|
||||
HttpDictionary responseHeaders;
|
||||
std::string ReadAsString();
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> ReadAsStream();
|
||||
void CopyToStream(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> GetInternalStream();
|
||||
~HttpResponse();
|
||||
};
|
||||
std::string method;
|
||||
std::string url;
|
||||
std::string unixSocket;
|
||||
HttpDictionary requestHeaders;
|
||||
HttpRequestBody *body;
|
||||
|
||||
void DownloadToStreamSimple(std::string url, std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
static std::shared_ptr<Tesses::Framework::Streams::Stream>
|
||||
EstablishConnection(Uri uri, bool ignoreSSLErrors,
|
||||
std::string trusted_root_cert_bundle);
|
||||
static std::shared_ptr<Tesses::Framework::Streams::Stream>
|
||||
EstablishUnixPathConnection(std::string unixPath, Uri uri,
|
||||
bool ignoreSSLErrors,
|
||||
std::string trusted_root_cert_bundle);
|
||||
|
||||
void DownloadToFileSimple(std::string url, std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs, Tesses::Framework::Filesystem::VFSPath path);
|
||||
void SendRequest(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
};
|
||||
|
||||
void DownloadToFileSimple(std::string url, Tesses::Framework::Filesystem::VFSPath path);
|
||||
std::string DownloadToStringSimple(std::string url);
|
||||
|
||||
bool WebSocketClientSuccessDefault(HttpDictionary& dict,bool v);
|
||||
void WebSocketClient(std::string url, HttpDictionary& requestHeaders, std::shared_ptr<WebSocketConnection> wsc, std::function<bool(HttpDictionary&,bool)> cb=WebSocketClientSuccessDefault);
|
||||
|
||||
|
||||
void DownloadUnixSocketToStreamSimple(std::string unixSocket,std::string url, std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
class HttpResponse {
|
||||
private:
|
||||
bool owns;
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> handleStrm;
|
||||
|
||||
void DownloadUnixSocketToFileSimple(std::string unixSocket,std::string url, std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs, Tesses::Framework::Filesystem::VFSPath path);
|
||||
|
||||
void DownloadUnixSocketToFileSimple(std::string unixSocket,std::string url, Tesses::Framework::Filesystem::VFSPath path);
|
||||
std::string DownloadUnixSocketToStringSimple(std::string unixSocket,std::string url);
|
||||
public:
|
||||
HttpResponse(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
HttpResponse(HttpRequest &request);
|
||||
std::string version;
|
||||
StatusCode statusCode;
|
||||
HttpDictionary responseHeaders;
|
||||
std::string ReadAsString();
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> ReadAsStream();
|
||||
void CopyToStream(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> GetInternalStream();
|
||||
~HttpResponse();
|
||||
};
|
||||
|
||||
void DownloadToStreamSimple(
|
||||
std::string url, std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
|
||||
void WebSocketUnixSocketClient(std::string unixSocket,std::string url, HttpDictionary& requestHeaders, std::shared_ptr<WebSocketConnection> wsc, std::function<bool(HttpDictionary&,bool)> cb=WebSocketClientSuccessDefault);
|
||||
}
|
||||
void DownloadToFileSimple(
|
||||
std::string url, std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs,
|
||||
Tesses::Framework::Filesystem::VFSPath path);
|
||||
|
||||
void DownloadToFileSimple(std::string url,
|
||||
Tesses::Framework::Filesystem::VFSPath path);
|
||||
std::string DownloadToStringSimple(std::string url);
|
||||
|
||||
bool WebSocketClientSuccessDefault(HttpDictionary &dict, bool v);
|
||||
void WebSocketClient(std::string url, HttpDictionary &requestHeaders,
|
||||
std::shared_ptr<WebSocketConnection> wsc,
|
||||
std::function<bool(HttpDictionary &, bool)> cb =
|
||||
WebSocketClientSuccessDefault);
|
||||
|
||||
void DownloadUnixSocketToStreamSimple(
|
||||
std::string unixSocket, std::string url,
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
|
||||
void DownloadUnixSocketToFileSimple(
|
||||
std::string unixSocket, std::string url,
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs,
|
||||
Tesses::Framework::Filesystem::VFSPath path);
|
||||
|
||||
void DownloadUnixSocketToFileSimple(
|
||||
std::string unixSocket, std::string url,
|
||||
Tesses::Framework::Filesystem::VFSPath path);
|
||||
std::string DownloadUnixSocketToStringSimple(std::string unixSocket,
|
||||
std::string url);
|
||||
|
||||
void WebSocketUnixSocketClient(std::string unixSocket, std::string url,
|
||||
HttpDictionary &requestHeaders,
|
||||
std::shared_ptr<WebSocketConnection> wsc,
|
||||
std::function<bool(HttpDictionary &, bool)> cb =
|
||||
WebSocketClientSuccessDefault);
|
||||
} // namespace Tesses::Framework::Http
|
||||
@@ -1,108 +1,170 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../Streams/NetworkStream.hpp"
|
||||
|
||||
#include "HttpUtils.hpp"
|
||||
#include "../Threading/Thread.hpp"
|
||||
#include "../Date/Date.hpp"
|
||||
#include <unordered_map>
|
||||
#include "../Threading/Thread.hpp"
|
||||
#include "HttpUtils.hpp"
|
||||
#include "WebSocket.hpp"
|
||||
namespace Tesses::Framework::Http
|
||||
{
|
||||
class ServerContextData {
|
||||
public:
|
||||
virtual ~ServerContextData();
|
||||
};
|
||||
#include <queue>
|
||||
#include <unordered_map>
|
||||
namespace Tesses::Framework::Http {
|
||||
class ServerContextData {
|
||||
public:
|
||||
virtual ~ServerContextData();
|
||||
};
|
||||
class ServerContext;
|
||||
class ServerSentEvents {
|
||||
std::vector<std::shared_ptr<Tesses::Framework::Streams::Stream>> strms;
|
||||
Tesses::Framework::Threading::Mutex mtx;
|
||||
|
||||
|
||||
private:
|
||||
void SendEventRaw(const std::string &evt);
|
||||
|
||||
class ServerContext {
|
||||
bool sent;
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> strm;
|
||||
std::map<std::string,ServerContextData*> data;
|
||||
public:
|
||||
HttpDictionary requestHeaders;
|
||||
HttpDictionary responseHeaders;
|
||||
HttpDictionary queryParams;
|
||||
//used by path
|
||||
HttpDictionary pathArguments;
|
||||
std::string path;
|
||||
std::string originalPath;
|
||||
std::string method;
|
||||
StatusCode statusCode;
|
||||
std::string ip;
|
||||
uint16_t port;
|
||||
uint16_t serverPort;
|
||||
std::string version;
|
||||
bool encrypted;
|
||||
ServerContext(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
~ServerContext();
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> GetStream();
|
||||
std::string GetOriginalPathWithQuery();
|
||||
std::string GetUrlWithQuery();
|
||||
bool Sent();
|
||||
bool NeedToParseFormData();
|
||||
void ParseFormData(std::function<std::shared_ptr<Tesses::Framework::Streams::Stream>(std::string mime, std::string filename, std::string name)> cb);
|
||||
void ReadStream(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
std::string ReadString();
|
||||
void SendBytes(std::vector<uint8_t> buffer);
|
||||
void SendText(std::string text);
|
||||
void SendStream(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
void SendErrorPage(bool showPath);
|
||||
void SendNotFound();
|
||||
void SendBadRequest();
|
||||
void SendException(std::exception& ex);
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenResponseStream();
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenRequestStream();
|
||||
ServerContext& WithLastModified(Date::DateTime time);
|
||||
ServerContext& WithHeader(std::string key, std::string value);
|
||||
ServerContext& WithSingleHeader(std::string key, std::string value);
|
||||
ServerContext& WithMimeType(std::string mime);
|
||||
ServerContext& WithContentDisposition(std::string filename, bool isInline);
|
||||
ServerContext& WriteHeaders();
|
||||
ServerContext& WithLocationHeader(std::string url);
|
||||
ServerContext& WithLocationHeader(std::string url,StatusCode sc);
|
||||
void StartWebSocketSession(std::function<void(std::function<void(WebSocketMessage&)>,std::function<void()>,std::function<void()>)> onOpen, std::function<void(WebSocketMessage&)> onReceive, std::function<void(bool)> onClose);
|
||||
void StartWebSocketSession(std::shared_ptr<WebSocketConnection> connection);
|
||||
std::string GetServerRoot();
|
||||
std::string MakeAbsolute(std::string path);
|
||||
void SendRedirect(std::string url);
|
||||
void SendRedirect(std::string url, StatusCode sc);
|
||||
public:
|
||||
void SendRetry(uint32_t ms);
|
||||
void SendRetry(std::chrono::milliseconds ms);
|
||||
void SendRetry(Tesses::Framework::Date::TimeSpan ts);
|
||||
void SendData(const std::string &message);
|
||||
void SendData(const std::string &message, const std::string &dataType);
|
||||
void SendId(const std::string &idVal);
|
||||
void SendCustomEvent(const std::string &type, const std::string &value);
|
||||
void SendComment(const std::string &comment);
|
||||
friend class ServerContext;
|
||||
};
|
||||
|
||||
|
||||
template<class T>
|
||||
T* GetServerContentData(std::string tag)
|
||||
{
|
||||
std::string name = typeid(T).name();
|
||||
name.push_back(' ');
|
||||
name.append(tag);
|
||||
if(data.count(name) > 0) return dynamic_cast<T*>(data[name]);
|
||||
T* item = new T();
|
||||
data[name] = item;
|
||||
return item;
|
||||
}
|
||||
};
|
||||
class ServerContext {
|
||||
|
||||
class IHttpServer {
|
||||
public:
|
||||
virtual bool Handle(ServerContext& ctx)=0;
|
||||
virtual ~IHttpServer();
|
||||
};
|
||||
bool sent;
|
||||
bool debug;
|
||||
std::vector<std::shared_ptr<ServerSentEvents>> sse;
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> strm;
|
||||
std::map<std::string, ServerContextData *> data;
|
||||
std::queue<std::function<bool(ServerContext &ctx)>> headerhandlers;
|
||||
|
||||
class HttpServer {
|
||||
std::shared_ptr<Tesses::Framework::Streams::TcpServer> server;
|
||||
std::shared_ptr<IHttpServer> http;
|
||||
Tesses::Framework::Threading::Thread* thrd;
|
||||
public:
|
||||
HttpDictionary requestHeaders;
|
||||
HttpDictionary responseHeaders;
|
||||
HttpDictionary queryParams;
|
||||
// used by path
|
||||
HttpDictionary pathArguments;
|
||||
std::string path;
|
||||
std::string originalPath;
|
||||
std::string method;
|
||||
StatusCode statusCode;
|
||||
std::string ip;
|
||||
uint16_t port;
|
||||
uint16_t serverPort;
|
||||
std::string version;
|
||||
bool encrypted;
|
||||
ServerContext(std::shared_ptr<Tesses::Framework::Streams::Stream> strm,
|
||||
bool debug = false);
|
||||
~ServerContext();
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> GetStream();
|
||||
std::string GetOriginalPathWithQuery();
|
||||
std::string GetUrlWithQuery();
|
||||
bool Sent();
|
||||
bool NeedToParseFormData();
|
||||
void ParseFormData(
|
||||
std::function<std::shared_ptr<Tesses::Framework::Streams::Stream>(
|
||||
std::string mime, std::string filename, std::string name)>
|
||||
cb);
|
||||
void ReadStream(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
std::string ReadString();
|
||||
void SendBytes(std::vector<uint8_t> buffer);
|
||||
void SendText(std::string text);
|
||||
void SendStream(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||
void SendErrorPage(bool showPath);
|
||||
void SendNotFound();
|
||||
void SendBadRequest();
|
||||
void SendException(std::exception &ex);
|
||||
void SendServerSentEvents(std::shared_ptr<ServerSentEvents> sse);
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenResponseStream();
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenRequestStream();
|
||||
ServerContext &WithStatusCode(StatusCode code);
|
||||
ServerContext &WithLastModified(Date::DateTime time);
|
||||
ServerContext &WithHeader(std::string key, std::string value);
|
||||
ServerContext &WithSingleHeader(std::string key, std::string value);
|
||||
ServerContext &WithMimeType(std::string mime);
|
||||
ServerContext &WithContentDisposition(std::string filename, bool isInline);
|
||||
ServerContext &WriteHeaders();
|
||||
ServerContext &WithLocationHeader(std::string url);
|
||||
ServerContext &WithLocationHeader(std::string url, StatusCode sc);
|
||||
ServerContext &
|
||||
WithHeaderIntercepter(std::function<bool(ServerContext &)> cb);
|
||||
ServerContext &WithDebug(bool debug = true);
|
||||
bool Debug();
|
||||
void StartWebSocketSession(
|
||||
std::function<void(std::function<void(WebSocketMessage &)>,
|
||||
std::function<void()>, std::function<void()>)>
|
||||
onOpen,
|
||||
std::function<void(WebSocketMessage &)> onReceive,
|
||||
std::function<void(bool)> onClose);
|
||||
void StartWebSocketSession(std::shared_ptr<WebSocketConnection> connection);
|
||||
std::string GetServerRoot();
|
||||
std::string MakeAbsolute(std::string path);
|
||||
void SendRedirect(std::string url);
|
||||
void SendRedirect(std::string url, StatusCode sc);
|
||||
|
||||
bool showIPs;
|
||||
bool showARTL;
|
||||
|
||||
public:
|
||||
HttpServer(std::shared_ptr<Tesses::Framework::Streams::TcpServer> tcpServer, std::shared_ptr<IHttpServer> http, bool showIPs=true);
|
||||
HttpServer(uint16_t port, std::shared_ptr<IHttpServer> http, bool showIPs=true);
|
||||
HttpServer(std::string unixPath, std::shared_ptr<IHttpServer> http);
|
||||
uint16_t GetPort();
|
||||
void StartAccepting();
|
||||
static void Process(std::shared_ptr<Tesses::Framework::Streams::Stream> strm, std::shared_ptr<IHttpServer> server, std::string ip, uint16_t port,uint16_t serverPort, bool encrypted);
|
||||
~HttpServer();
|
||||
};
|
||||
}
|
||||
template <class T> T *GetServerContentData(std::string tag) {
|
||||
std::string name = typeid(T).name();
|
||||
name.push_back(' ');
|
||||
name.append(tag);
|
||||
if (data.count(name) > 0)
|
||||
return dynamic_cast<T *>(data[name]);
|
||||
T *item = new T();
|
||||
data[name] = item;
|
||||
return item;
|
||||
}
|
||||
friend class ServerSentEvents;
|
||||
};
|
||||
|
||||
class IHttpServer {
|
||||
public:
|
||||
virtual bool Handle(ServerContext &ctx) = 0;
|
||||
virtual ~IHttpServer();
|
||||
};
|
||||
|
||||
class HttpServer {
|
||||
std::shared_ptr<Tesses::Framework::Streams::TcpServer> server;
|
||||
std::shared_ptr<IHttpServer> http;
|
||||
Tesses::Framework::Threading::Thread *thrd;
|
||||
|
||||
bool showIPs;
|
||||
bool showARTL;
|
||||
bool debug;
|
||||
|
||||
public:
|
||||
HttpServer(std::shared_ptr<Tesses::Framework::Streams::TcpServer> tcpServer,
|
||||
std::shared_ptr<IHttpServer> http, bool showIPs = true,
|
||||
bool debug = false);
|
||||
HttpServer(uint16_t port, std::shared_ptr<IHttpServer> http,
|
||||
bool showIPs = true, bool debug = false);
|
||||
HttpServer(std::string unixPath, std::shared_ptr<IHttpServer> http,
|
||||
bool debug = false);
|
||||
uint16_t GetPort();
|
||||
void StartAccepting();
|
||||
static void
|
||||
Process(std::shared_ptr<Tesses::Framework::Streams::Stream> strm,
|
||||
std::shared_ptr<IHttpServer> server, std::string ip, uint16_t port,
|
||||
uint16_t serverPort, bool encrypted, bool debug = false);
|
||||
~HttpServer();
|
||||
};
|
||||
} // namespace Tesses::Framework::Http
|
||||
|
||||
@@ -1,31 +1,49 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../Streams/Stream.hpp"
|
||||
|
||||
namespace Tesses::Framework::Http
|
||||
{
|
||||
class HttpStream : public Tesses::Framework::Streams::Stream {
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> strm;
|
||||
|
||||
size_t offset;
|
||||
size_t read;
|
||||
int64_t length;
|
||||
int64_t position;
|
||||
|
||||
bool recv;
|
||||
bool http1_1;
|
||||
|
||||
bool done;
|
||||
namespace Tesses::Framework::Http {
|
||||
class HttpStream : public Tesses::Framework::Streams::Stream {
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> strm;
|
||||
|
||||
public:
|
||||
HttpStream(std::shared_ptr<Tesses::Framework::Streams::Stream> strm, int64_t length, bool recv, bool http1_1);
|
||||
bool CanRead();
|
||||
bool CanWrite();
|
||||
bool EndOfStream();
|
||||
int64_t GetLength();
|
||||
int64_t GetPosition();
|
||||
size_t Read(uint8_t* buffer, size_t len);
|
||||
size_t Write(const uint8_t* buffer, size_t len);
|
||||
void Close();
|
||||
~HttpStream();
|
||||
};
|
||||
}
|
||||
size_t offset;
|
||||
size_t read;
|
||||
int64_t length;
|
||||
int64_t position;
|
||||
|
||||
bool recv;
|
||||
bool http1_1;
|
||||
|
||||
bool done;
|
||||
|
||||
public:
|
||||
HttpStream(std::shared_ptr<Tesses::Framework::Streams::Stream> strm,
|
||||
int64_t length, bool recv, bool http1_1);
|
||||
bool CanRead();
|
||||
bool CanWrite();
|
||||
bool EndOfStream();
|
||||
int64_t GetLength();
|
||||
int64_t GetPosition();
|
||||
size_t Read(uint8_t *buffer, size_t len);
|
||||
size_t Write(const uint8_t *buffer, size_t len);
|
||||
void Close();
|
||||
~HttpStream();
|
||||
};
|
||||
} // namespace Tesses::Framework::Http
|
||||
@@ -1,177 +1,196 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../Common.hpp"
|
||||
#include "../Date/Date.hpp"
|
||||
#include <algorithm>
|
||||
|
||||
namespace Tesses::Framework::Http
|
||||
{
|
||||
typedef enum StatusCode {
|
||||
Continue=100,
|
||||
SwitchingProtocols=101,
|
||||
Processing=102,
|
||||
EarlyHints=103,
|
||||
OK=200,
|
||||
Created=201,
|
||||
Accepted=202,
|
||||
NonAuthoritativeInformation=203,
|
||||
NoContent=204,
|
||||
ResetContent=205,
|
||||
PartialContent=206,
|
||||
MultiStatus=207,
|
||||
AlreadyReported=208,
|
||||
IMUsed=226,
|
||||
MultipleChoices=300,
|
||||
MovedPermanently=301,
|
||||
Found=302,
|
||||
SeeOther=303,
|
||||
NotModified=304,
|
||||
UseProxy=305,
|
||||
TemporaryRedirect=307,
|
||||
PermanentRedirect=308,
|
||||
BadRequest=400,
|
||||
Unauthorized=401,
|
||||
PaymentRequired=402,
|
||||
Forbidden=403,
|
||||
NotFound=404,
|
||||
MethodNotAllowed=405,
|
||||
NotAcceptable=406,
|
||||
ProxyAuthenticationRequired=407,
|
||||
RequestTimeout=408,
|
||||
Conflict=409,
|
||||
Gone=410,
|
||||
LengthRequired=411,
|
||||
PreconditionFailed=412,
|
||||
PayloadTooLarge=413,
|
||||
URITooLong=414,
|
||||
UnsupportedMediaType=415,
|
||||
RangeNotSatisfiable=416,
|
||||
ExpectationFailed=417,
|
||||
ImATeapot=418,
|
||||
MisdirectedRequest=421,
|
||||
UnprocessableContent=422,
|
||||
Locked=423,
|
||||
FailedDependency=424,
|
||||
TooEarly=425,
|
||||
UpgradeRequired=426,
|
||||
PreconditionRequired=428,
|
||||
TooManyRequests=429,
|
||||
RequestHeaderFieldsTooLarge=431,
|
||||
UnavailableForLegalReasons=451,
|
||||
InternalServerError=500,
|
||||
NotImplemented=501,
|
||||
BadGateway=502,
|
||||
ServiceUnavailable=503,
|
||||
GatewayTimeout=504,
|
||||
HTTPVersionNotSupported=505,
|
||||
VariantAlsoNegotiates=506,
|
||||
InsufficientStorage=507,
|
||||
LoopDetected=508,
|
||||
NotExtended=510,
|
||||
NetworkAuthenticationRequired=511
|
||||
namespace Tesses::Framework::Http {
|
||||
typedef enum StatusCode {
|
||||
Continue = 100,
|
||||
SwitchingProtocols = 101,
|
||||
Processing = 102,
|
||||
EarlyHints = 103,
|
||||
OK = 200,
|
||||
Created = 201,
|
||||
Accepted = 202,
|
||||
NonAuthoritativeInformation = 203,
|
||||
NoContent = 204,
|
||||
ResetContent = 205,
|
||||
PartialContent = 206,
|
||||
MultiStatus = 207,
|
||||
AlreadyReported = 208,
|
||||
IMUsed = 226,
|
||||
MultipleChoices = 300,
|
||||
MovedPermanently = 301,
|
||||
Found = 302,
|
||||
SeeOther = 303,
|
||||
NotModified = 304,
|
||||
UseProxy = 305,
|
||||
TemporaryRedirect = 307,
|
||||
PermanentRedirect = 308,
|
||||
BadRequest = 400,
|
||||
Unauthorized = 401,
|
||||
PaymentRequired = 402,
|
||||
Forbidden = 403,
|
||||
NotFound = 404,
|
||||
MethodNotAllowed = 405,
|
||||
NotAcceptable = 406,
|
||||
ProxyAuthenticationRequired = 407,
|
||||
RequestTimeout = 408,
|
||||
Conflict = 409,
|
||||
Gone = 410,
|
||||
LengthRequired = 411,
|
||||
PreconditionFailed = 412,
|
||||
PayloadTooLarge = 413,
|
||||
URITooLong = 414,
|
||||
UnsupportedMediaType = 415,
|
||||
RangeNotSatisfiable = 416,
|
||||
ExpectationFailed = 417,
|
||||
ImATeapot = 418,
|
||||
MisdirectedRequest = 421,
|
||||
UnprocessableContent = 422,
|
||||
Locked = 423,
|
||||
FailedDependency = 424,
|
||||
TooEarly = 425,
|
||||
UpgradeRequired = 426,
|
||||
PreconditionRequired = 428,
|
||||
TooManyRequests = 429,
|
||||
RequestHeaderFieldsTooLarge = 431,
|
||||
UnavailableForLegalReasons = 451,
|
||||
InternalServerError = 500,
|
||||
NotImplemented = 501,
|
||||
BadGateway = 502,
|
||||
ServiceUnavailable = 503,
|
||||
GatewayTimeout = 504,
|
||||
HTTPVersionNotSupported = 505,
|
||||
VariantAlsoNegotiates = 506,
|
||||
InsufficientStorage = 507,
|
||||
LoopDetected = 508,
|
||||
NotExtended = 510,
|
||||
NetworkAuthenticationRequired = 511
|
||||
} StatusCode;
|
||||
|
||||
struct CaseInsensitiveLess {
|
||||
CaseInsensitiveLess(const CaseInsensitiveLess& str);
|
||||
CaseInsensitiveLess(const CaseInsensitiveLess &str);
|
||||
CaseInsensitiveLess();
|
||||
CaseInsensitiveLess* offset;
|
||||
CaseInsensitiveLess *offset;
|
||||
bool caseSensitive;
|
||||
bool operator() (const std::string& s1, const std::string& s2) const;
|
||||
bool operator()(const std::string &s1, const std::string &s2) const;
|
||||
};
|
||||
|
||||
class HttpDictionary {
|
||||
public:
|
||||
HttpDictionary();
|
||||
HttpDictionary(bool caseSensitive);
|
||||
std::map<std::string,std::vector<std::string>,CaseInsensitiveLess> kvp;
|
||||
void SetCaseSensitive(bool isCaseSensitive);
|
||||
void Clear();
|
||||
void Clear(std::string key, bool kvpExistsAfter);
|
||||
void SetValue(std::string key, std::string value);
|
||||
void SetValue(std::string key, int64_t v);
|
||||
void SetValue(std::string key, double v);
|
||||
void SetValue(std::string key, Date::DateTime v);
|
||||
void SetValue(std::string key, std::vector<std::string> value);
|
||||
template<typename Itterator>
|
||||
void SetValue(std::string key, Itterator begin, Itterator end)
|
||||
{
|
||||
Clear(key,true);
|
||||
AddValue(key, begin, end);
|
||||
}
|
||||
void AddValue(std::string key, std::string value);
|
||||
void AddValue(std::string key, int64_t v);
|
||||
void AddValue(std::string key, double v);
|
||||
void AddValue(std::string key, Date::DateTime v);
|
||||
void AddValue(std::string key, std::vector<std::string> value);
|
||||
|
||||
template<typename Itterator>
|
||||
void AddValue(std::string key, Itterator begin, Itterator end)
|
||||
{
|
||||
auto& ls = kvp[key];
|
||||
ls.insert(ls.end(), begin, end);
|
||||
}
|
||||
|
||||
bool TryGetFirst(std::string key, std::string& value);
|
||||
class HttpDictionary {
|
||||
public:
|
||||
HttpDictionary();
|
||||
HttpDictionary(bool caseSensitive);
|
||||
std::map<std::string, std::vector<std::string>, CaseInsensitiveLess> kvp;
|
||||
void SetCaseSensitive(bool isCaseSensitive);
|
||||
void Clear();
|
||||
void Clear(std::string key, bool kvpExistsAfter);
|
||||
void SetValue(std::string key, std::string value);
|
||||
void SetValue(std::string key, int64_t v);
|
||||
void SetValue(std::string key, double v);
|
||||
void SetValue(std::string key, Date::DateTime v);
|
||||
void SetValue(std::string key, std::vector<std::string> value);
|
||||
template <typename Itterator>
|
||||
void SetValue(std::string key, Itterator begin, Itterator end) {
|
||||
Clear(key, true);
|
||||
AddValue(key, begin, end);
|
||||
}
|
||||
void AddValue(std::string key, std::string value);
|
||||
void AddValue(std::string key, int64_t v);
|
||||
void AddValue(std::string key, double v);
|
||||
void AddValue(std::string key, Date::DateTime v);
|
||||
void AddValue(std::string key, std::vector<std::string> value);
|
||||
|
||||
bool TryGetFirstInt(std::string key, int64_t& value);
|
||||
template <typename Itterator>
|
||||
void AddValue(std::string key, Itterator begin, Itterator end) {
|
||||
auto &ls = kvp[key];
|
||||
ls.insert(ls.end(), begin, end);
|
||||
}
|
||||
|
||||
bool TryGetFirstDouble(std::string key, double& value);
|
||||
bool TryGetFirstDate(std::string key, Date::DateTime& value);
|
||||
bool TryGetFirst(std::string key, std::string &value);
|
||||
|
||||
bool GetFirstBoolean(std::string key);
|
||||
bool TryGetFirstInt(std::string key, int64_t &value);
|
||||
|
||||
bool AnyEquals(std::string key, std::string value);
|
||||
};
|
||||
bool TryGetFirstDouble(std::string key, double &value);
|
||||
bool TryGetFirstDate(std::string key, Date::DateTime &value);
|
||||
|
||||
class Uri {
|
||||
public:
|
||||
Uri();
|
||||
std::string GetQuery();
|
||||
std::string GetPathAndQuery();
|
||||
uint16_t GetPort();
|
||||
std::string HostPort();
|
||||
bool Relative(std::string url, Uri& uri);
|
||||
std::string ToString();
|
||||
static bool TryParse(std::string url, Uri& uri);
|
||||
std::string scheme;
|
||||
std::string host;
|
||||
uint16_t port;
|
||||
std::string path;
|
||||
HttpDictionary query;
|
||||
std::string hash;
|
||||
};
|
||||
bool GetFirstBoolean(std::string key);
|
||||
|
||||
class HttpUtils
|
||||
{
|
||||
public:
|
||||
static char NibbleToHex(uint8_t nibble);
|
||||
static uint8_t HexToNibble(char c);
|
||||
static std::string BytesToHex(const std::vector<uint8_t>& data);
|
||||
static void BytesToHex(std::string& text,const std::vector<uint8_t>& data);
|
||||
static std::vector<uint8_t> HexToBytes(const std::string& text);
|
||||
static void HexToBytes(std::vector<uint8_t>& data,const std::string& text);
|
||||
static std::string MimeType(std::filesystem::path p);
|
||||
static bool Invalid(char c);
|
||||
static std::string Sanitise(std::string text);
|
||||
static void QueryParamsDecode(HttpDictionary& dict,std::string query);
|
||||
static std::string Join(std::string joinStr, std::vector<std::string> ents);
|
||||
static std::string QueryParamsEncode(HttpDictionary& dict);
|
||||
static std::string UrlDecode(std::string v);
|
||||
static std::string UrlEncode(std::string v);
|
||||
static std::string UrlPathDecode(std::string v);
|
||||
static std::string UrlPathEncode(std::string v, bool ignoreSpace=false);
|
||||
static std::string HtmlEncode(std::string v);
|
||||
static std::string HtmlP(std::string text);
|
||||
static std::string HtmlDecodeOnlyEntityNumber(std::string v);
|
||||
static std::vector<std::string> SplitString(std::string text, std::string delimiter,std::size_t maxCnt = std::string::npos);
|
||||
static std::string Replace(std::string str, std::string find, std::string replace);
|
||||
static std::string StatusCodeString(StatusCode code);
|
||||
static std::string ToLower(std::string str);
|
||||
static std::string ToUpper(std::string str);
|
||||
static std::string LeftPad(std::string text, int count, char c);
|
||||
};
|
||||
bool AnyEquals(std::string key, std::string value);
|
||||
};
|
||||
|
||||
|
||||
class Uri {
|
||||
public:
|
||||
Uri();
|
||||
std::string GetQuery();
|
||||
std::string GetPathAndQuery();
|
||||
uint16_t GetPort();
|
||||
std::string HostPort();
|
||||
bool Relative(std::string url, Uri &uri);
|
||||
std::string ToString();
|
||||
static bool TryParse(std::string url, Uri &uri);
|
||||
std::string scheme;
|
||||
std::string host;
|
||||
uint16_t port;
|
||||
std::string path;
|
||||
HttpDictionary query;
|
||||
std::string hash;
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
class HttpUtils {
|
||||
public:
|
||||
static char NibbleToHex(uint8_t b, bool isUppercase);
|
||||
static char NibbleToHex(uint8_t nibble);
|
||||
static uint8_t HexToNibble(char c);
|
||||
static std::string BytesToHex(const std::vector<uint8_t> &data);
|
||||
static void BytesToHex(std::string &text, const std::vector<uint8_t> &data);
|
||||
|
||||
static std::string BytesToHex(const std::vector<uint8_t> &data,
|
||||
bool isUppercase);
|
||||
static void BytesToHex(std::string &text, const std::vector<uint8_t> &data,
|
||||
bool isUppercase);
|
||||
static std::vector<uint8_t> HexToBytes(const std::string &text);
|
||||
static void HexToBytes(std::vector<uint8_t> &data, const std::string &text);
|
||||
static std::string MimeType(std::filesystem::path p);
|
||||
static bool Invalid(char c);
|
||||
static std::string Sanitise(std::string text);
|
||||
static void QueryParamsDecode(HttpDictionary &dict, std::string query);
|
||||
static std::string Join(std::string joinStr, std::vector<std::string> ents);
|
||||
static std::string QueryParamsEncode(HttpDictionary &dict);
|
||||
static std::string UrlDecode(std::string v);
|
||||
static std::string UrlEncode(std::string v);
|
||||
static std::string UrlPathDecode(std::string v);
|
||||
static std::string UrlPathEncode(std::string v, bool ignoreSpace = false);
|
||||
static std::string HtmlEncode(std::string v);
|
||||
static std::string HtmlP(std::string text);
|
||||
static std::string HtmlDecodeOnlyEntityNumber(std::string v);
|
||||
static std::vector<std::string>
|
||||
SplitString(std::string text, std::string delimiter,
|
||||
std::size_t maxCnt = std::string::npos);
|
||||
static std::string Replace(std::string str, std::string find,
|
||||
std::string replace);
|
||||
static std::string StatusCodeString(StatusCode code);
|
||||
static std::string ToLower(std::string str);
|
||||
static std::string ToUpper(std::string str);
|
||||
static std::string LeftPad(std::string text, int count, char c);
|
||||
};
|
||||
|
||||
} // namespace Tesses::Framework::Http
|
||||
@@ -1,22 +1,41 @@
|
||||
#pragma once
|
||||
#include "HttpServer.hpp"
|
||||
#include "../Filesystem/VFSFix.hpp"
|
||||
#include "../Filesystem/VFS.hpp"
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
namespace Tesses::Framework::Http
|
||||
{
|
||||
class MountableServer : public IHttpServer
|
||||
{
|
||||
std::shared_ptr<IHttpServer> root;
|
||||
std::vector<std::pair<std::string,std::shared_ptr<IHttpServer>>> servers;
|
||||
std::string Subpath(Filesystem::VFSPath fullPath, Filesystem::VFSPath offsetPath);
|
||||
bool StartsWith(Filesystem::VFSPath fullPath, Filesystem::VFSPath offsetPath);
|
||||
public:
|
||||
MountableServer();
|
||||
MountableServer(std::shared_ptr<IHttpServer> root);
|
||||
void Mount(std::string path, std::shared_ptr<IHttpServer> server);
|
||||
void Unmount(std::string path);
|
||||
bool Handle(ServerContext& ctx);
|
||||
~MountableServer();
|
||||
};
|
||||
}
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../Filesystem/VFS.hpp"
|
||||
#include "../Filesystem/VFSFix.hpp"
|
||||
#include "HttpServer.hpp"
|
||||
|
||||
namespace Tesses::Framework::Http {
|
||||
class MountableServer : public IHttpServer {
|
||||
std::shared_ptr<IHttpServer> root;
|
||||
std::vector<std::pair<std::string, std::shared_ptr<IHttpServer>>> servers;
|
||||
std::string Subpath(Filesystem::VFSPath fullPath,
|
||||
Filesystem::VFSPath offsetPath);
|
||||
bool StartsWith(Filesystem::VFSPath fullPath,
|
||||
Filesystem::VFSPath offsetPath);
|
||||
|
||||
public:
|
||||
MountableServer();
|
||||
MountableServer(std::shared_ptr<IHttpServer> root);
|
||||
void Mount(std::string path, std::shared_ptr<IHttpServer> server);
|
||||
void Unmount(std::string path);
|
||||
bool Handle(ServerContext &ctx);
|
||||
~MountableServer();
|
||||
};
|
||||
} // namespace Tesses::Framework::Http
|
||||
@@ -1,41 +1,59 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "HttpServer.hpp"
|
||||
#include "../Filesystem/VFSFix.hpp"
|
||||
#include "../Filesystem/VFS.hpp"
|
||||
#include "../Filesystem/VFSFix.hpp"
|
||||
#include "HttpServer.hpp"
|
||||
|
||||
namespace Tesses::Framework::Http
|
||||
{
|
||||
using ServerRequestHandler = std::function<bool(ServerContext&)>;
|
||||
|
||||
|
||||
class RouteServer : public IHttpServer
|
||||
{
|
||||
class RouteServerRoute {
|
||||
public:
|
||||
std::vector<std::pair<std::string,bool>> parts;
|
||||
std::string method;
|
||||
ServerRequestHandler handler;
|
||||
namespace Tesses::Framework::Http {
|
||||
using ServerRequestHandler = std::function<bool(ServerContext &)>;
|
||||
|
||||
RouteServerRoute() = default;
|
||||
RouteServerRoute(std::string route, std::string method, ServerRequestHandler handler);
|
||||
bool Equals(Tesses::Framework::Filesystem::VFSPath& path, HttpDictionary& args);
|
||||
};
|
||||
std::vector<RouteServerRoute> routes;
|
||||
std::shared_ptr<IHttpServer> root;
|
||||
public:
|
||||
RouteServer() = default;
|
||||
RouteServer(std::shared_ptr<IHttpServer> root);
|
||||
void Get(std::string pattern, ServerRequestHandler handler);
|
||||
void Post(std::string pattern, ServerRequestHandler handler);
|
||||
void Put(std::string pattern, ServerRequestHandler handler);
|
||||
void Patch(std::string pattern, ServerRequestHandler handler);
|
||||
class RouteServer : public IHttpServer {
|
||||
class RouteServerRoute {
|
||||
public:
|
||||
std::vector<std::pair<std::string, bool>> parts;
|
||||
std::string method;
|
||||
ServerRequestHandler handler;
|
||||
|
||||
void Delete(std::string pattern, ServerRequestHandler handler);
|
||||
|
||||
void Trace(std::string pattern, ServerRequestHandler handler);
|
||||
void Options(std::string pattern, ServerRequestHandler handler);
|
||||
void Add(std::string method, std::string pattern, ServerRequestHandler handler);
|
||||
bool Handle(ServerContext& ctx);
|
||||
|
||||
RouteServerRoute() = default;
|
||||
RouteServerRoute(std::string route, std::string method,
|
||||
ServerRequestHandler handler);
|
||||
bool Equals(Tesses::Framework::Filesystem::VFSPath &path,
|
||||
HttpDictionary &args);
|
||||
};
|
||||
}
|
||||
std::vector<RouteServerRoute> routes;
|
||||
std::shared_ptr<IHttpServer> root;
|
||||
|
||||
public:
|
||||
RouteServer() = default;
|
||||
RouteServer(std::shared_ptr<IHttpServer> root);
|
||||
void Get(std::string pattern, ServerRequestHandler handler);
|
||||
void Post(std::string pattern, ServerRequestHandler handler);
|
||||
void Put(std::string pattern, ServerRequestHandler handler);
|
||||
void Patch(std::string pattern, ServerRequestHandler handler);
|
||||
|
||||
void Delete(std::string pattern, ServerRequestHandler handler);
|
||||
|
||||
void Trace(std::string pattern, ServerRequestHandler handler);
|
||||
void Options(std::string pattern, ServerRequestHandler handler);
|
||||
void Add(std::string method, std::string pattern,
|
||||
ServerRequestHandler handler);
|
||||
bool Handle(ServerContext &ctx);
|
||||
};
|
||||
} // namespace Tesses::Framework::Http
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user