mirror of
https://git.tesses.org/tesses50/tessesframework.git
synced 2026-06-01 10:05:31 +00:00
Overhaul cmake configuration, add console api, fix http code that caused issues with cgi-bin
This commit is contained in:
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
|
||||||
|
...
|
||||||
|
|
||||||
@@ -10,6 +10,7 @@ env:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-arch:
|
build-arch:
|
||||||
|
name: "🔨 Build for Arch Linux/Static Builds"
|
||||||
runs-on: arch-builder
|
runs-on: arch-builder
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
@@ -30,10 +31,22 @@ jobs:
|
|||||||
files: |-
|
files: |-
|
||||||
artifacts/**
|
artifacts/**
|
||||||
|
|
||||||
update-tap:
|
update-tap-and-build-win32:
|
||||||
runs-on: ubuntu-latest
|
name: "🔨 Build win32 and update the tap 🍺"
|
||||||
|
runs-on: global-containers-mingw
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
- run: |
|
||||||
|
env -C Builds/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
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
ref: "master"
|
ref: "master"
|
||||||
@@ -46,5 +59,5 @@ jobs:
|
|||||||
git config user.name "Tesses Gitea Bot"
|
git config user.name "Tesses Gitea Bot"
|
||||||
git config user.email "noreply@tesses.net"
|
git config user.email "noreply@tesses.net"
|
||||||
git add .
|
git add .
|
||||||
git commit -m "Push tesses-framework=${{ env.VERSION }}"
|
git commit -m "Push tessesframework=${{ env.VERSION }}"
|
||||||
git push
|
git push
|
||||||
|
|||||||
354
CMakeLists.txt
354
CMakeLists.txt
@@ -1,25 +1,15 @@
|
|||||||
cmake_minimum_required(VERSION 3.16)
|
cmake_minimum_required(VERSION 3.16)
|
||||||
|
|
||||||
set(TESSESFRAMEWORK_MAJOR_VERSION 0)
|
include(cmake/version.cmake)
|
||||||
set(TESSESFRAMEWORK_MINOR_VERSION 0)
|
|
||||||
set(TESSESFRAMEWORK_PATCH_VERSION 2)
|
|
||||||
|
|
||||||
project(TessesFramework VERSION ${TESSESFRAMEWORK_MAJOR_VERSION}.${TESSESFRAMEWORK_MINOR_VERSION}.${TESSESFRAMEWORK_PATCH_VERSION})
|
project(TessesFramework VERSION ${TESSESFRAMEWORK_MAJOR_VERSION}.${TESSESFRAMEWORK_MINOR_VERSION}.${TESSESFRAMEWORK_PATCH_VERSION})
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
include(CheckLibraryExists)
|
||||||
|
include(FetchContent)
|
||||||
include(cmake/sources.cmake)
|
include(cmake/sources.cmake)
|
||||||
|
include(cmake/options.cmake)
|
||||||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
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)
|
if(TESSESFRAMEWORK_ENABLE_SQLITE)
|
||||||
list(APPEND TESSESFRAMEWORK_SOURCE
|
list(APPEND TESSESFRAMEWORK_SOURCE
|
||||||
src/Serialization/sqlite/sqlite3-mod.c
|
src/Serialization/sqlite/sqlite3-mod.c
|
||||||
@@ -31,343 +21,45 @@ list(APPEND TESSESFRAMEWORK_SOURCE
|
|||||||
src/Platform/sago/platform_folders.cpp
|
src/Platform/sago/platform_folders.cpp
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
option(TESSESFRAMEWORK_ENABLE_EXAMPLES "Enable Tesses Framework examples" ON)
|
|
||||||
option(TESSESFRAMEWORK_ENABLE_APPS "Enable Tesses Framework cli apps" ON)
|
include(cmake/findmbed.cmake)
|
||||||
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()
|
|
||||||
if(TESSESFRAMEWORK_VENDERCERTCHAIN)
|
if(TESSESFRAMEWORK_VENDERCERTCHAIN)
|
||||||
set(TESSESFRAMEWORK_CERT_BUNDLE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/ca-certificates.crt" CACHE FILEPATH "Path to ca-chain")
|
set(TESSESFRAMEWORK_CERT_BUNDLE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/ca-certificates.crt" CACHE FILEPATH "Path to ca-chain")
|
||||||
else()
|
else()
|
||||||
set(TESSESFRAMEWORK_CERT_BUNDLE_FILE "/etc/ssl/certs/ca-certificates.crt" CACHE FILEPATH "Path to ca-chain")
|
set(TESSESFRAMEWORK_CERT_BUNDLE_FILE "/etc/ssl/certs/ca-certificates.crt" CACHE FILEPATH "Path to ca-chain")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
|
||||||
|
|
||||||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include)
|
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include)
|
||||||
|
|
||||||
include(cmake/bin2h.cmake)
|
include(cmake/bin2h.cmake)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Making sure libraries don't generate symlinks
|
|
||||||
|
|
||||||
if(TESSESFRAMEWORK_ENABLE_MBED)
|
if(TESSESFRAMEWORK_ENABLE_MBED)
|
||||||
if(TESSESFRAMEWORK_EMBED_CERT_BUNDLE)
|
if(TESSESFRAMEWORK_EMBED_CERT_BUNDLE)
|
||||||
|
|
||||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/include/TessesFramework/CertificateChain.h" "#pragma once\n")
|
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)
|
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")
|
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()
|
else()
|
||||||
target_compile_definitions(TessesFramework PUBLIC TESSESFRAMEWORK_CERT_BUNDLE_FILE=${TESSESFRAMEWORK_CERT_BUNDLE_FILE})
|
include(cmake/sharedlib.cmake)
|
||||||
|
|
||||||
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()
|
|
||||||
find_package(MbedTLS REQUIRED)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
endif()
|
include(cmake/install-dev.cmake)
|
||||||
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()
|
include(cmake/examples.cmake)
|
||||||
target_include_directories(${TessesFramework_TARGET}
|
include(cmake/apps.cmake)
|
||||||
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)
|
|
||||||
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()
|
|
||||||
|
|
||||||
|
|
||||||
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(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()
|
|
||||||
|
|
||||||
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()
|
|
||||||
|
|
||||||
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)
|
|
||||||
if(TESSESFRAMEWORK_INSTALL_DEVELOPMENT)
|
if(TESSESFRAMEWORK_INSTALL_DEVELOPMENT)
|
||||||
add_subdirectory(pkgconfig)
|
add_subdirectory(pkgconfig)
|
||||||
endif()
|
endif()
|
||||||
@@ -3,15 +3,15 @@
|
|||||||
include("${CMAKE_CURRENT_LIST_DIR}/TessesFrameworkTargets.cmake")
|
include("${CMAKE_CURRENT_LIST_DIR}/TessesFrameworkTargets.cmake")
|
||||||
|
|
||||||
check_required_components(TessesFramework)
|
check_required_components(TessesFramework)
|
||||||
|
include(GNUInstallDirs)
|
||||||
if(NOT ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoWii" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "NintendoGameCube"))
|
if(NOT WIN32)
|
||||||
if(@TESSESFRAMEWORK_ENABLE_THREADING@)
|
if(@TESSESFRAMEWORK_ENABLE_THREADING@)
|
||||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
set(TESSESFRAMEWORK_ENABLE_MBED @TESSESFRAMEWORK_ENABLE_MBED@)
|
||||||
set(TESSESFRAMEWORK_ENABLE_SQLITE @TESSESFRAMEWORK_ENABLE_SQLITE@)
|
set(TESSESFRAMEWORK_ENABLE_SQLITE @TESSESFRAMEWORK_ENABLE_SQLITE@)
|
||||||
set(TESSESFRAMEWORK_ENABLE_PLATFORMFOLDERS @TESSESFRAMEWORK_ENABLE_PLATFORMFOLDERS@)
|
set(TESSESFRAMEWORK_ENABLE_PLATFORMFOLDERS @TESSESFRAMEWORK_ENABLE_PLATFORMFOLDERS@)
|
||||||
|
|
||||||
@@ -19,3 +19,15 @@ set(TESSESFRAMEWORK_ENABLE_NETWORKING @TESSESFRAMEWORK_ENABLE_NETWORKING@)
|
|||||||
set(TESSESFRAMEWORK_ENABLE_THREADING @TESSESFRAMEWORK_ENABLE_THREADING@)
|
set(TESSESFRAMEWORK_ENABLE_THREADING @TESSESFRAMEWORK_ENABLE_THREADING@)
|
||||||
set(TESSESFRAMEWORK_ENABLE_PROCESS @TESSESFRAMEWORK_ENABLE_PROCESS@)
|
set(TESSESFRAMEWORK_ENABLE_PROCESS @TESSESFRAMEWORK_ENABLE_PROCESS@)
|
||||||
set(TESSESFRAMEWORK_ENABLE_RPATH @TESSESFRAMEWORK_ENABLE_RPATH@)
|
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()
|
||||||
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
|
Copyright (C) 2007 Free Software Foundation, Inc.
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
<https://fsf.org/>
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
Everyone is permitted to copy and distribute verbatim copies of this
|
||||||
copies or substantial portions of the Software.
|
license document, but changing it is not allowed.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
## Preamble
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
The GNU General Public License is a free, copyleft license for
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
software and other kinds of works.
|
||||||
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
|
The licenses for most software and other practical works are designed
|
||||||
SOFTWARE.
|
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
|
Other peoples code
|
||||||
==================
|
==================
|
||||||
|
|
||||||
- cmake/bin2h.cmake, from: https://github.com/sivachandran/cmake-bin2h (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 (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)
|
- 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)
|
- [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)
|
||||||
@@ -7,27 +7,26 @@ 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
|
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
|
export BUILDDIR=builds/$tripple
|
||||||
mkdir -p $BUILDDIR
|
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_ENABLE_SHARED=OFF -DTESSESFRAMEWORK_ENABLE_STATIC=ON -DCMAKE_EXE_LINKER_FLAGS="-static-libgcc -static-libstdc++ -static -Wl,--strip-all" -DCMAKE_POSITION_INDEPENDENT_CODE=ON -GNinja
|
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 --build $BUILDDIR || exit 1
|
||||||
cmake --install $BUILDDIR --prefix $BUILDDIR/out
|
cmake --install $BUILDDIR --prefix $BUILDDIR/out
|
||||||
tar cvzf ../../artifacts/tessesframework-tools-$tripple\.tar.gz -C $BUILDDIR/out/ bin
|
tar cvzf ../../artifacts/tessesframework-tools-$tripple\.tar.gz -C $BUILDDIR/out/ bin
|
||||||
|
|
||||||
done
|
done
|
||||||
|
#x86_64-windows-gnu x86-windows-gnu
|
||||||
for tripple in x86_64-windows-gnu x86-windows-gnu aarch64-windows-gnu; do
|
export BUILDDIR=builds/aarch64-windows-gnu
|
||||||
export BUILDDIR=builds/$tripple
|
|
||||||
mkdir -p $BUILDDIR
|
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_ENABLE_SHARED=OFF -DTESSESFRAMEWORK_ENABLE_STATIC=ON -DCMAKE_EXE_LINKER_FLAGS="-static-libgcc -static-libstdc++ -static -Wl,--strip-all" -DCMAKE_POSITION_INDEPENDENT_CODE=ON -GNinja
|
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 --build $BUILDDIR || exit 1
|
||||||
cmake --install $BUILDDIR --prefix $BUILDDIR/out
|
cmake --install $BUILDDIR --prefix $BUILDDIR/out
|
||||||
|
|
||||||
env -C $BUILDDIR/out zip -r ../../../../../artifacts/tessesframework-tools-$tripple\.zip bin
|
env -C $BUILDDIR/out zip -r ../../../../../artifacts/tessesframework-tools-aarch64-windows-gnu.zip bin
|
||||||
done
|
|
||||||
|
|
||||||
for tripple in x86_64-macos-none aarch64-macos-none; do
|
for tripple in x86_64-macos-none aarch64-macos-none; do
|
||||||
export BUILDDIR=builds/$tripple
|
export BUILDDIR=builds/$tripple
|
||||||
mkdir -p $BUILDDIR
|
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_ENABLE_SHARED=OFF -DTESSESFRAMEWORK_ENABLE_STATIC=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON -GNinja -DCMAKE_EXE_LINKER_FLAGS="-Wl,--strip-all"
|
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 --build $BUILDDIR || exit 1
|
||||||
cmake --install $BUILDDIR --prefix $BUILDDIR/out
|
cmake --install $BUILDDIR --prefix $BUILDDIR/out
|
||||||
tar cvzf ../../artifacts/tessesframework-tools-$tripple\.tar.gz -C $BUILDDIR/out/ bin
|
tar cvzf ../../artifacts/tessesframework-tools-$tripple\.tar.gz -C $BUILDDIR/out/ bin
|
||||||
|
|||||||
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
|
||||||
38
README.md
38
README.md
@@ -1,14 +1,48 @@
|
|||||||
Tesses Framework
|
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
|
## To Install
|
||||||
- Install [mbedtls](https://github.com/Mbed-TLS/mbedtls) (use sudo apt install libmbedtls-dev on debian) for TessesFramework
|
- Install [mbedtls](https://github.com/Mbed-TLS/mbedtls) (use sudo apt install libmbedtls-dev on debian) for TessesFramework
|
||||||
- Follow the commands bellow
|
- Follow the commands bellow
|
||||||
|
|
||||||
## Run these commands to install tesses-framework
|
## Run these commands to install tesses-framework
|
||||||
```bash
|
```bash
|
||||||
git clone https://onedev.site.tesses.net/tesses-framework
|
git clone https://git.tesses.org/tesses50/tessesframework
|
||||||
cd tesses-framework
|
cd tessesframework
|
||||||
mkdir build
|
mkdir build
|
||||||
cd build
|
cd build
|
||||||
cmake -S .. -B .
|
cmake -S .. -B .
|
||||||
|
|||||||
@@ -6,18 +6,15 @@ using namespace Tesses::Framework::Filesystem;
|
|||||||
using namespace Tesses::Framework::Serialization::Bencode;
|
using namespace Tesses::Framework::Serialization::Bencode;
|
||||||
using namespace Tesses::Framework::TextStreams;
|
using namespace Tesses::Framework::TextStreams;
|
||||||
using namespace Tesses::Framework::BitTorrent;
|
using namespace Tesses::Framework::BitTorrent;
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char **argv) {
|
||||||
{
|
|
||||||
TF_Init();
|
TF_Init();
|
||||||
if(argc < 2)
|
if (argc < 2) {
|
||||||
{
|
printf("USAGE: %s /path/to/torrent/file\n", argv[0]);
|
||||||
printf("USAGE: %s /path/to/torrent/file\n",argv[0]);
|
|
||||||
return 1;
|
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);
|
auto bencode = Bencode::Load(strm);
|
||||||
if(std::holds_alternative<BeDictionary>(bencode))
|
if (std::holds_alternative<BeDictionary>(bencode)) {
|
||||||
{
|
|
||||||
|
|
||||||
TorrentFile file(std::get<BeDictionary>(bencode));
|
TorrentFile file(std::get<BeDictionary>(bencode));
|
||||||
file.Print(std::make_shared<ConsoleWriter>());
|
file.Print(std::make_shared<ConsoleWriter>());
|
||||||
|
|||||||
@@ -7,83 +7,84 @@ using namespace Tesses::Framework::Filesystem;
|
|||||||
|
|
||||||
std::shared_ptr<VFS> vfs;
|
std::shared_ptr<VFS> vfs;
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char **argv) {
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
TF_InitWithConsole();
|
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{
|
std::shared_ptr<CallbackServer> cb = std::make_shared<
|
||||||
if(ctx.path == "/")
|
CallbackServer>([](ServerContext &ctx) -> bool {
|
||||||
{
|
if (ctx.path == "/") {
|
||||||
ctx.WithMimeType("text/html")
|
ctx.WithMimeType("text/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;
|
|
||||||
});
|
|
||||||
ctx.WithMimeType("text/html")
|
|
||||||
.SendText(
|
.SendText(
|
||||||
"<!DOCTYPE html>"
|
"<!DOCTYPE html>"
|
||||||
"<html>"
|
"<html>"
|
||||||
"<head><meta name=\"color-scheme\" content=\"dark light\"><title>AnonyDrop - Uploaded successfully</title></head>"
|
"<head><meta "
|
||||||
|
"charset=\"UTF-8\"><title>AnonyDrop</title><meta "
|
||||||
|
"name=\"color-scheme\" content=\"dark light\"></head>"
|
||||||
"<body>"
|
"<body>"
|
||||||
"<h1>Uploaded successfully</h1>"
|
"<h1>AnonyDrop</h1>"
|
||||||
"<a href=\"./\">Back</a>"
|
"<a href=\"./files/\">Files</a>"
|
||||||
|
"<form action=\"./upload\" method=\"post\" "
|
||||||
"</body>"
|
"enctype=\"multipart/form-data\" accept-charset=\"UTF-8\">"
|
||||||
"</html>"
|
"<input type=\"file\" name=\"file\" multiple>"
|
||||||
);
|
"<input type=\"submit\" value=\"Upload\">"
|
||||||
return true;
|
|
||||||
}
|
|
||||||
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>"
|
"</form>"
|
||||||
"</body>"
|
"</body>"
|
||||||
"</html>"
|
"</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;
|
||||||
|
});
|
||||||
|
ctx.WithMimeType("text/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;
|
||||||
|
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>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
auto mountable = std::make_shared<Tesses::Framework::Http::MountableServer>(cb);
|
auto mountable =
|
||||||
mountable->Mount("/files/",std::make_shared<FileServer>(vfs,true,false));
|
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();
|
srv.StartAccepting();
|
||||||
|
|
||||||
TF_RunEventLoop();
|
TF_RunEventLoop();
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
#include "TessesFramework/TessesFramework.hpp"
|
#include "TessesFramework/TessesFramework.hpp"
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char **argv) {
|
||||||
{
|
if (argc < 4) {
|
||||||
if(argc < 4)
|
std::cout << "USAGE: " << argv[0] << " BINARYFILE VARNAME HEADERFILE"
|
||||||
{
|
<< std::endl;
|
||||||
std::cout << "USAGE: " << argv[0] << " BINARYFILE VARNAME HEADERFILE" << std::endl;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
auto fs=std::make_shared<Tesses::Framework::Streams::FileStream>(argv[1],"rb");
|
auto fs =
|
||||||
if(!fs->CanRead()) return 1;
|
std::make_shared<Tesses::Framework::Streams::FileStream>(argv[1], "rb");
|
||||||
auto writer = std::make_shared<Tesses::Framework::TextStreams::StreamWriter>(argv[3]);
|
if (!fs->CanRead())
|
||||||
|
return 1;
|
||||||
|
auto writer =
|
||||||
|
std::make_shared<Tesses::Framework::TextStreams::StreamWriter>(argv[3]);
|
||||||
Tesses::Framework::Text::GenerateCHeaderFile(fs, argv[2], writer);
|
Tesses::Framework::Text::GenerateCHeaderFile(fs, argv[2], writer);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -3,20 +3,18 @@ using namespace Tesses::Framework;
|
|||||||
using namespace Tesses::Framework::BitTorrent;
|
using namespace Tesses::Framework::BitTorrent;
|
||||||
using namespace Tesses::Framework::Serialization::Bencode;
|
using namespace Tesses::Framework::Serialization::Bencode;
|
||||||
using namespace Tesses::Framework::Filesystem;
|
using namespace Tesses::Framework::Filesystem;
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char **argv) {
|
||||||
{
|
|
||||||
TF_Init();
|
TF_Init();
|
||||||
if(argc < 2)
|
if (argc < 2) {
|
||||||
{
|
printf("USAGE: %s torrent_file\n", argv[0]);
|
||||||
printf("USAGE: %s torrent_file\n",argv[0]);
|
|
||||||
return 1;
|
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);
|
auto data = Bencode::Load(strm);
|
||||||
if(std::holds_alternative<BeDictionary>(data)){
|
if (std::holds_alternative<BeDictionary>(data)) {
|
||||||
std::get<BeDictionary>(data).SetValue("url-list",BeUndefined());
|
std::get<BeDictionary>(data).SetValue("url-list", BeUndefined());
|
||||||
}
|
}
|
||||||
strm = LocalFS->OpenFile((std::string)argv[1],"wb");
|
strm = LocalFS->OpenFile((std::string)argv[1], "wb");
|
||||||
Bencode::Save(strm,data);
|
Bencode::Save(strm, data);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -2,44 +2,34 @@
|
|||||||
using namespace Tesses::Framework::Streams;
|
using namespace Tesses::Framework::Streams;
|
||||||
using namespace Tesses::Framework::Serialization::Json;
|
using namespace Tesses::Framework::Serialization::Json;
|
||||||
using namespace Tesses::Framework::TextStreams;
|
using namespace Tesses::Framework::TextStreams;
|
||||||
std::shared_ptr<FileStream> OpenWrite(std::string dest)
|
std::shared_ptr<FileStream> OpenWrite(std::string dest) {
|
||||||
{
|
if (dest == "-") {
|
||||||
if(dest == "-")
|
return std::make_shared<FileStream>(stdout, false, "w");
|
||||||
{
|
} else {
|
||||||
return std::make_shared<FileStream>(stdout,false,"w");
|
auto strm = std::make_shared<FileStream>(dest, "w");
|
||||||
}
|
if (!strm->CanWrite()) {
|
||||||
else
|
|
||||||
{
|
|
||||||
auto strm = std::make_shared<FileStream>(dest,"w");
|
|
||||||
if(!strm->CanWrite())
|
|
||||||
{
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return strm;
|
return strm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::shared_ptr<FileStream> OpenRead(std::string src)
|
std::shared_ptr<FileStream> OpenRead(std::string src) {
|
||||||
{
|
if (src == "-") {
|
||||||
if(src == "-")
|
return std::make_shared<FileStream>(stdin, false, "r");
|
||||||
{
|
} else {
|
||||||
return std::make_shared<FileStream>(stdin,false,"r");
|
auto strm = std::make_shared<FileStream>(src, "r");
|
||||||
}
|
if (!strm->CanRead()) {
|
||||||
else
|
|
||||||
{
|
|
||||||
auto strm = std::make_shared<FileStream>(src,"r");
|
|
||||||
if(!strm->CanRead())
|
|
||||||
{
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return strm;
|
return strm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char **argv) {
|
||||||
{
|
if (argc < 3) {
|
||||||
if(argc < 3)
|
|
||||||
{
|
|
||||||
std::cout << "USAGE: " << argv[0] << " SRC DEST" << std::endl;
|
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;
|
std::cout << "DEST: prettied file or - for stdout" << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -47,14 +37,12 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
auto dest = OpenWrite(argv[2]);
|
auto dest = OpenWrite(argv[2]);
|
||||||
|
|
||||||
if(src == nullptr)
|
if (src == nullptr) {
|
||||||
{
|
|
||||||
|
|
||||||
std::cerr << "ERROR: Input could not be read" << std::endl;
|
std::cerr << "ERROR: Input could not be read" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if(dest == nullptr)
|
if (dest == nullptr) {
|
||||||
{
|
|
||||||
std::cerr << "ERROR: Output could not be read" << std::endl;
|
std::cerr << "ERROR: Output could not be read" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -65,6 +53,5 @@ int main(int argc, char** argv)
|
|||||||
auto str = reader.ReadToEnd();
|
auto str = reader.ReadToEnd();
|
||||||
writer.WriteLine(Json::Encode(Json::DocDecode(str)));
|
writer.WriteLine(Json::Encode(Json::DocDecode(str)));
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -3,25 +3,22 @@
|
|||||||
using namespace Tesses::Framework;
|
using namespace Tesses::Framework;
|
||||||
using namespace Tesses::Framework::Streams;
|
using namespace Tesses::Framework::Streams;
|
||||||
using namespace Tesses::Framework::Http;
|
using namespace Tesses::Framework::Http;
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char **argv) {
|
||||||
{
|
if (argc < 3) {
|
||||||
if(argc < 3)
|
printf("USAGE: %s <url> <path>\n", argv[0]);
|
||||||
{
|
printf("USAGE: %s <unixSocket> <url> <path>\n", argv[0]);
|
||||||
printf("USAGE: %s <url> <path>\n",argv[0]);
|
|
||||||
printf("USAGE: %s <unixSocket> <url> <path>\n",argv[0]);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if(argc >= 4)
|
if (argc >= 4) {
|
||||||
{
|
|
||||||
std::string unixSocket = argv[1];
|
std::string unixSocket = argv[1];
|
||||||
std::string url = argv[2];
|
std::string url = argv[2];
|
||||||
std::string path = argv[3];
|
std::string path = argv[3];
|
||||||
Tesses::Framework::Http::DownloadUnixSocketToFileSimple(unixSocket,url,path);
|
Tesses::Framework::Http::DownloadUnixSocketToFileSimple(unixSocket, url,
|
||||||
}
|
path);
|
||||||
else {
|
} else {
|
||||||
std::string path = argv[2];
|
std::string path = argv[2];
|
||||||
Tesses::Framework::Http::DownloadToFileSimple(argv[1],path);
|
Tesses::Framework::Http::DownloadToFileSimple(argv[1], path);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -6,121 +6,106 @@ using namespace Tesses::Framework::Streams;
|
|||||||
using namespace Tesses::Framework::TextStreams;
|
using namespace Tesses::Framework::TextStreams;
|
||||||
using namespace Tesses::Framework::Threading;
|
using namespace Tesses::Framework::Threading;
|
||||||
|
|
||||||
void print_help(const char* name)
|
void print_help(const char *name) {
|
||||||
{
|
printf("Tesses FileServer\nUSAGE: %s [OPTIONS] <dir>\n", name);
|
||||||
printf("Tesses FileServer\nUSAGE: %s [OPTIONS] <dir>\n",name);
|
printf("OPTIONS:\n-p PORT, --port PORT: Change port from 9852\n-l, "
|
||||||
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");
|
"--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);
|
exit(1);
|
||||||
}
|
}
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char **argv) {
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
TF_InitWithConsole();
|
TF_InitWithConsole();
|
||||||
TF_LOG("INIT");
|
TF_LOG("INIT");
|
||||||
const char* directory = "wwwroot";
|
const char *directory = "wwwroot";
|
||||||
bool spa=false;
|
bool spa = false;
|
||||||
bool allowListing = false;
|
bool allowListing = false;
|
||||||
std::optional<std::string> cgi_bin;
|
std::optional<std::string> cgi_bin;
|
||||||
std::optional<std::string> cgi_admin;
|
std::optional<std::string> cgi_admin;
|
||||||
std::optional<Tesses::Framework::Filesystem::VFSPath> cgi_workdir;
|
std::optional<Tesses::Framework::Filesystem::VFSPath> cgi_workdir;
|
||||||
uint16_t port = 9852L;
|
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
|
|
||||||
{
|
|
||||||
|
|
||||||
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);
|
std::cout << "In folder: "
|
||||||
server.StartAccepting();
|
<< std::filesystem::absolute(directory).string() << std::endl;
|
||||||
TF_RunEventLoop();
|
std::shared_ptr<IHttpServer> http;
|
||||||
std::cout << "Closing server" << std::endl;
|
|
||||||
TF_Quit();
|
auto fs = std::make_shared<FileServer>(directory, allowListing, spa);
|
||||||
}catch(std::exception& ex)
|
if (cgi_bin) {
|
||||||
{
|
Tesses::Framework::Filesystem::VFSPath dir = *cgi_bin;
|
||||||
TF_LOG(ex.what());
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,44 +2,33 @@
|
|||||||
using namespace Tesses::Framework::Streams;
|
using namespace Tesses::Framework::Streams;
|
||||||
using namespace Tesses::Framework::Serialization::Json;
|
using namespace Tesses::Framework::Serialization::Json;
|
||||||
using namespace Tesses::Framework::TextStreams;
|
using namespace Tesses::Framework::TextStreams;
|
||||||
std::shared_ptr<FileStream> OpenWrite(std::string dest)
|
std::shared_ptr<FileStream> OpenWrite(std::string dest) {
|
||||||
{
|
if (dest == "-") {
|
||||||
if(dest == "-")
|
return std::make_shared<FileStream>(stdout, false, "w");
|
||||||
{
|
} else {
|
||||||
return std::make_shared<FileStream>(stdout,false,"w");
|
auto strm = std::make_shared<FileStream>(dest, "w");
|
||||||
}
|
if (!strm->CanWrite()) {
|
||||||
else
|
|
||||||
{
|
|
||||||
auto strm = std::make_shared<FileStream>(dest,"w");
|
|
||||||
if(!strm->CanWrite())
|
|
||||||
{
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return strm;
|
return strm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::shared_ptr<FileStream> OpenRead(std::string src)
|
std::shared_ptr<FileStream> OpenRead(std::string src) {
|
||||||
{
|
if (src == "-") {
|
||||||
if(src == "-")
|
return std::make_shared<FileStream>(stdin, false, "r");
|
||||||
{
|
} else {
|
||||||
return std::make_shared<FileStream>(stdin,false,"r");
|
auto strm = std::make_shared<FileStream>(src, "r");
|
||||||
}
|
if (!strm->CanRead()) {
|
||||||
else
|
|
||||||
{
|
|
||||||
auto strm = std::make_shared<FileStream>(src,"r");
|
|
||||||
if(!strm->CanRead())
|
|
||||||
{
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return strm;
|
return strm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char **argv) {
|
||||||
{
|
if (argc < 3) {
|
||||||
if(argc < 3)
|
|
||||||
{
|
|
||||||
std::cout << "USAGE: " << argv[0] << " SRC DEST" << std::endl;
|
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;
|
std::cout << "DEST: json doc file or - for stdout" << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -47,14 +36,12 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
auto dest = OpenWrite(argv[2]);
|
auto dest = OpenWrite(argv[2]);
|
||||||
|
|
||||||
if(src == nullptr)
|
if (src == nullptr) {
|
||||||
{
|
|
||||||
|
|
||||||
std::cerr << "ERROR: Input could not be read" << std::endl;
|
std::cerr << "ERROR: Input could not be read" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if(dest == nullptr)
|
if (dest == nullptr) {
|
||||||
{
|
|
||||||
std::cerr << "ERROR: Output could not be read" << std::endl;
|
std::cerr << "ERROR: Output could not be read" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -68,6 +55,5 @@ int main(int argc, char** argv)
|
|||||||
TryGetJToken(doc, docLs);
|
TryGetJToken(doc, docLs);
|
||||||
writer.WriteLine(Json::DocEncode(docLs));
|
writer.WriteLine(Json::DocEncode(docLs));
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -2,44 +2,33 @@
|
|||||||
using namespace Tesses::Framework::Streams;
|
using namespace Tesses::Framework::Streams;
|
||||||
using namespace Tesses::Framework::Serialization::Json;
|
using namespace Tesses::Framework::Serialization::Json;
|
||||||
using namespace Tesses::Framework::TextStreams;
|
using namespace Tesses::Framework::TextStreams;
|
||||||
std::shared_ptr<FileStream> OpenWrite(std::string dest)
|
std::shared_ptr<FileStream> OpenWrite(std::string dest) {
|
||||||
{
|
if (dest == "-") {
|
||||||
if(dest == "-")
|
return std::make_shared<FileStream>(stdout, false, "w");
|
||||||
{
|
} else {
|
||||||
return std::make_shared<FileStream>(stdout,false,"w");
|
auto strm = std::make_shared<FileStream>(dest, "w");
|
||||||
}
|
if (!strm->CanWrite()) {
|
||||||
else
|
|
||||||
{
|
|
||||||
auto strm = std::make_shared<FileStream>(dest,"w");
|
|
||||||
if(!strm->CanWrite())
|
|
||||||
{
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return strm;
|
return strm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::shared_ptr<FileStream> OpenRead(std::string src)
|
std::shared_ptr<FileStream> OpenRead(std::string src) {
|
||||||
{
|
if (src == "-") {
|
||||||
if(src == "-")
|
return std::make_shared<FileStream>(stdin, false, "r");
|
||||||
{
|
} else {
|
||||||
return std::make_shared<FileStream>(stdin,false,"r");
|
auto strm = std::make_shared<FileStream>(src, "r");
|
||||||
}
|
if (!strm->CanRead()) {
|
||||||
else
|
|
||||||
{
|
|
||||||
auto strm = std::make_shared<FileStream>(src,"r");
|
|
||||||
if(!strm->CanRead())
|
|
||||||
{
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return strm;
|
return strm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char **argv) {
|
||||||
{
|
if (argc < 3) {
|
||||||
if(argc < 3)
|
|
||||||
{
|
|
||||||
std::cout << "USAGE: " << argv[0] << " SRC DEST" << std::endl;
|
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;
|
std::cout << "DEST: prettied file or - for stdout" << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -47,14 +36,12 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
auto dest = OpenWrite(argv[2]);
|
auto dest = OpenWrite(argv[2]);
|
||||||
|
|
||||||
if(src == nullptr)
|
if (src == nullptr) {
|
||||||
{
|
|
||||||
|
|
||||||
std::cerr << "ERROR: Input could not be read" << std::endl;
|
std::cerr << "ERROR: Input could not be read" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if(dest == nullptr)
|
if (dest == nullptr) {
|
||||||
{
|
|
||||||
std::cerr << "ERROR: Output could not be read" << std::endl;
|
std::cerr << "ERROR: Output could not be read" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -65,6 +52,5 @@ int main(int argc, char** argv)
|
|||||||
auto str = reader.ReadToEnd();
|
auto str = reader.ReadToEnd();
|
||||||
writer.WriteLine(Json::Encode(Json::Decode(str)));
|
writer.WriteLine(Json::Encode(Json::Decode(str)));
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -2,44 +2,33 @@
|
|||||||
using namespace Tesses::Framework::Streams;
|
using namespace Tesses::Framework::Streams;
|
||||||
using namespace Tesses::Framework::Serialization::Json;
|
using namespace Tesses::Framework::Serialization::Json;
|
||||||
using namespace Tesses::Framework::TextStreams;
|
using namespace Tesses::Framework::TextStreams;
|
||||||
std::shared_ptr<FileStream> OpenWrite(std::string dest)
|
std::shared_ptr<FileStream> OpenWrite(std::string dest) {
|
||||||
{
|
if (dest == "-") {
|
||||||
if(dest == "-")
|
return std::make_shared<FileStream>(stdout, false, "w");
|
||||||
{
|
} else {
|
||||||
return std::make_shared<FileStream>(stdout,false,"w");
|
auto strm = std::make_shared<FileStream>(dest, "w");
|
||||||
}
|
if (!strm->CanWrite()) {
|
||||||
else
|
|
||||||
{
|
|
||||||
auto strm = std::make_shared<FileStream>(dest,"w");
|
|
||||||
if(!strm->CanWrite())
|
|
||||||
{
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return strm;
|
return strm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::shared_ptr<FileStream> OpenRead(std::string src)
|
std::shared_ptr<FileStream> OpenRead(std::string src) {
|
||||||
{
|
if (src == "-") {
|
||||||
if(src == "-")
|
return std::make_shared<FileStream>(stdin, false, "r");
|
||||||
{
|
} else {
|
||||||
return std::make_shared<FileStream>(stdin,false,"r");
|
auto strm = std::make_shared<FileStream>(src, "r");
|
||||||
}
|
if (!strm->CanRead()) {
|
||||||
else
|
|
||||||
{
|
|
||||||
auto strm = std::make_shared<FileStream>(src,"r");
|
|
||||||
if(!strm->CanRead())
|
|
||||||
{
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return strm;
|
return strm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char **argv) {
|
||||||
{
|
if (argc < 3) {
|
||||||
if(argc < 3)
|
|
||||||
{
|
|
||||||
std::cout << "USAGE: " << argv[0] << " SRC DEST" << std::endl;
|
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;
|
std::cout << "DEST: unprettied file or - for stdout" << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -47,14 +36,12 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
auto dest = OpenWrite(argv[2]);
|
auto dest = OpenWrite(argv[2]);
|
||||||
|
|
||||||
if(src == nullptr)
|
if (src == nullptr) {
|
||||||
{
|
|
||||||
std::cerr << "ERROR: Input could not be read" << std::endl;
|
std::cerr << "ERROR: Input could not be read" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if(dest == nullptr)
|
if (dest == nullptr) {
|
||||||
{
|
|
||||||
|
|
||||||
std::cerr << "ERROR: Output could not be read" << std::endl;
|
std::cerr << "ERROR: Output could not be read" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -63,8 +50,7 @@ int main(int argc, char** argv)
|
|||||||
StreamWriter writer(dest);
|
StreamWriter writer(dest);
|
||||||
|
|
||||||
auto str = reader.ReadToEnd();
|
auto str = reader.ReadToEnd();
|
||||||
writer.WriteLine(Json::Encode(Json::Decode(str),false));
|
writer.WriteLine(Json::Encode(Json::Decode(str), false));
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
#include "TessesFramework/TessesFramework.hpp"
|
#include "TessesFramework/TessesFramework.hpp"
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char **argv) {
|
||||||
{
|
if (argc < 2) {
|
||||||
if(argc < 2)
|
|
||||||
{
|
|
||||||
|
|
||||||
std::cout << "USAGE: " << argv[0] << " times" << std::endl;
|
std::cout << "USAGE: " << argv[0] << " times" << std::endl;
|
||||||
std::cout << "USAGE: " << argv[0] << " times max" << std::endl;
|
std::cout << "USAGE: " << argv[0] << " times max" << std::endl;
|
||||||
@@ -11,25 +9,19 @@ int main(int argc, char** argv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Tesses::Framework::Random random;
|
Tesses::Framework::Random random;
|
||||||
int times=std::atoi(argv[1]);
|
int times = std::atoi(argv[1]);
|
||||||
if(argc > 2)
|
if (argc > 2) {
|
||||||
{
|
|
||||||
int32_t min = 0;
|
int32_t min = 0;
|
||||||
int32_t max = std::stoi(argv[2]);
|
int32_t max = std::stoi(argv[2]);
|
||||||
if(argc > 3)
|
if (argc > 3) {
|
||||||
{
|
|
||||||
min = max;
|
min = max;
|
||||||
max = std::stoi(argv[3]);
|
max = std::stoi(argv[3]);
|
||||||
|
|
||||||
}
|
}
|
||||||
for(int i = 0; i < times; i++)
|
for (int i = 0; i < times; i++) {
|
||||||
{
|
std::cout << random.Next(min, max) << std::endl;
|
||||||
std::cout << random.Next(min,max) << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
for (int i = 0; i < times; i++) {
|
||||||
for(int i = 0; i < times; i++)
|
|
||||||
{
|
|
||||||
std::cout << random.Next() << std::endl;
|
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/Platform/Process.hpp"
|
||||||
|
#include "TessesFramework/TessesFramework.hpp"
|
||||||
using namespace Tesses::Framework;
|
using namespace Tesses::Framework;
|
||||||
using namespace Tesses::Framework::Platform;
|
using namespace Tesses::Framework::Platform;
|
||||||
using namespace Tesses::Framework::TextStreams;
|
using namespace Tesses::Framework::TextStreams;
|
||||||
using namespace Tesses::Framework::Filesystem;
|
using namespace Tesses::Framework::Filesystem;
|
||||||
|
|
||||||
void split_command(std::string cmd, std::vector<std::string>& args)
|
void split_command(std::string cmd, std::vector<std::string> &args) {
|
||||||
{
|
bool inStr = false;
|
||||||
bool inStr=false;
|
std::string cur = {};
|
||||||
std::string cur={};
|
auto flush = [&]() -> void {
|
||||||
auto flush=[&]()->void {
|
if (cur.empty())
|
||||||
if(cur.empty()) return;
|
return;
|
||||||
args.push_back(cur);
|
args.push_back(cur);
|
||||||
cur={};
|
cur = {};
|
||||||
};
|
};
|
||||||
for(size_t i = 0; i < cmd.size(); i++)
|
for (size_t i = 0; i < cmd.size(); i++) {
|
||||||
{
|
if (inStr) {
|
||||||
if(inStr)
|
if (cmd[i] == '\"')
|
||||||
{
|
inStr = false;
|
||||||
if(cmd[i] == '\"') inStr=false;
|
else if (cmd[i] == '\\') {
|
||||||
else if(cmd[i] == '\\')
|
|
||||||
{
|
|
||||||
i++;
|
i++;
|
||||||
if(i < cmd.size())
|
if (i < cmd.size()) {
|
||||||
{
|
|
||||||
cmd.push_back(cmd[i]);
|
cmd.push_back(cmd[i]);
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
else cur.push_back(cmd[i]);
|
cur.push_back(cmd[i]);
|
||||||
}
|
} else {
|
||||||
else
|
if (cmd[i] == ' ')
|
||||||
{
|
flush();
|
||||||
if(cmd[i] == ' ') flush();
|
else if (cmd[i] == '\"') {
|
||||||
else if(cmd[i] == '\"') {
|
inStr = true;
|
||||||
inStr=true;
|
} else {
|
||||||
}
|
|
||||||
else {
|
|
||||||
cur.push_back(cmd[i]);
|
cur.push_back(cmd[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc,char** argv)
|
int main(int argc, char **argv) {
|
||||||
{
|
|
||||||
TF_Init();
|
TF_Init();
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
std::cout << VFSPath::GetAbsoluteCurrentDirectory().ToString() << "$ ";
|
||||||
while(true)
|
|
||||||
{
|
|
||||||
std::cout << VFSPath::GetAbsoluteCurrentDirectory().ToString() << "$ ";
|
|
||||||
|
|
||||||
|
|
||||||
std::string text;
|
std::string text;
|
||||||
StdIn().ReadLine(text);
|
StdIn().ReadLine(text);
|
||||||
std::vector<std::string> args;
|
std::vector<std::string> args;
|
||||||
split_command(text,args);
|
split_command(text, args);
|
||||||
if(args.empty()) continue;
|
if (args.empty())
|
||||||
if(args[0] == "exit") break;
|
continue;
|
||||||
else if(args[0] == "echo") { if(args.size() > 1) std::cout << args[1] << std::endl;}
|
if (args[0] == "exit")
|
||||||
else if(args[0] == "cd") {
|
break;
|
||||||
if(args.size() < 2)
|
else if (args[0] == "echo") {
|
||||||
{
|
if (args.size() > 1)
|
||||||
VFSPath::SetAbsoluteCurrentDirectory(Environment::SpecialFolders::GetHomeFolder());
|
std::cout << args[1] << std::endl;
|
||||||
}
|
} else if (args[0] == "cd") {
|
||||||
else {
|
if (args.size() < 2) {
|
||||||
|
VFSPath::SetAbsoluteCurrentDirectory(
|
||||||
|
Environment::SpecialFolders::GetHomeFolder());
|
||||||
|
} else {
|
||||||
VFSPath::SetAbsoluteCurrentDirectory(args[1]);
|
VFSPath::SetAbsoluteCurrentDirectory(args[1]);
|
||||||
}
|
}
|
||||||
}
|
} else if (args[0] == "printargs") {
|
||||||
else if(args[0] == "printargs")
|
for (size_t i = 1; i < args.size(); i++) {
|
||||||
{
|
std::cout << "\""
|
||||||
for(size_t i = 1; i < args.size(); i++)
|
<< Http::HttpUtils::Replace(args[i], "\"", "\\\"")
|
||||||
{
|
<< "\"" << std::endl;
|
||||||
std::cout << "\"" << Http::HttpUtils::Replace(args[i],"\"","\\\"") << "\"" << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
} else if (args[0] == "sigtermtest") {
|
||||||
else if (args[0] == "sigtermtest")
|
if (args.size() < 2)
|
||||||
{
|
continue;
|
||||||
if (args.size() < 2) continue;
|
|
||||||
std::vector<std::string> args2(args.begin() + 1, args.end());
|
std::vector<std::string> args2(args.begin() + 1, args.end());
|
||||||
|
|
||||||
auto path = Environment::GetRealExecutablePath(args2[0]);
|
auto path = Environment::GetRealExecutablePath(args2[0]);
|
||||||
Platform::Process p(path.ToString(), args2);
|
Platform::Process p(path.ToString(), args2);
|
||||||
if (p.Start())
|
if (p.Start()) {
|
||||||
{
|
|
||||||
std::cout << "Press enter to sigterm" << std::endl;
|
std::cout << "Press enter to sigterm" << std::endl;
|
||||||
StdIn().ReadLine();
|
StdIn().ReadLine();
|
||||||
p.Kill(SIGTERM);
|
p.Kill(SIGTERM);
|
||||||
}
|
}
|
||||||
}
|
} else if (args[0] == "rstdi") {
|
||||||
else if(args[0] == "rstdi")
|
if (args.size() < 3)
|
||||||
{
|
continue;
|
||||||
if(args.size()<3) continue;
|
std::vector<std::string> args2(args.begin() + 2, args.end());
|
||||||
std::vector<std::string> args2(args.begin()+2,args.end());
|
auto f = LocalFS->OpenFile(args[1], "rb");
|
||||||
auto f = LocalFS->OpenFile(args[1],"rb");
|
if (f != nullptr) {
|
||||||
if(f != nullptr)
|
|
||||||
{
|
|
||||||
auto path = Environment::GetRealExecutablePath(args2[0]);
|
auto path = Environment::GetRealExecutablePath(args2[0]);
|
||||||
Platform::Process p(path.ToString(),args2);
|
Platform::Process p(path.ToString(), args2);
|
||||||
p.redirectStdIn=true;
|
p.redirectStdIn = true;
|
||||||
if(p.Start())
|
if (p.Start()) {
|
||||||
{
|
|
||||||
auto strm = p.GetStdinStream();
|
auto strm = p.GetStdinStream();
|
||||||
f->CopyTo(strm);
|
f->CopyTo(strm);
|
||||||
|
|
||||||
p.CloseStdInNow();
|
p.CloseStdInNow();
|
||||||
p.WaitForExit();
|
p.WaitForExit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
auto path = Environment::GetRealExecutablePath(args[0]);
|
auto path = Environment::GetRealExecutablePath(args[0]);
|
||||||
Platform::Process p(path.ToString(),args);
|
Platform::Process p(path.ToString(), args);
|
||||||
if (p.Start())
|
if (p.Start())
|
||||||
p.WaitForExit();
|
p.WaitForExit();
|
||||||
else
|
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;
|
||||||
using namespace Tesses::Framework::Date;
|
using namespace Tesses::Framework::Date;
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char **argv) {
|
||||||
{
|
|
||||||
TF_Init();
|
TF_Init();
|
||||||
DateTime dt=DateTime::Now();
|
DateTime dt = DateTime::Now();
|
||||||
//dt = dt.ToLocal();
|
// dt = dt.ToLocal();
|
||||||
if(argc > 1)
|
if (argc > 1) {
|
||||||
{
|
if (strcmp(argv[1], "--help") == 0) {
|
||||||
if(strcmp(argv[1],"--help") == 0)
|
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
case 'r':
|
case 'r':
|
||||||
{
|
{
|
||||||
@@ -34,15 +31,15 @@ int main(int argc, char** argv)
|
|||||||
break;
|
break;
|
||||||
case 'T':
|
case 'T':
|
||||||
{
|
{
|
||||||
|
|
||||||
text.append(Http::HttpUtils::LeftPad(std::to_string(hour),2,'0'));
|
text.append(Http::HttpUtils::LeftPad(std::to_string(hour),2,'0'));
|
||||||
text.push_back(':');
|
text.push_back(':');
|
||||||
text.append(Http::HttpUtils::LeftPad(std::to_string(minute),2,'0'));
|
text.append(Http::HttpUtils::LeftPad(std::to_string(minute),2,'0'));
|
||||||
text.push_back(':');
|
text.push_back(':');
|
||||||
text.append(Http::HttpUtils::LeftPad(std::to_string(second),2,'0'));
|
text.append(Http::HttpUtils::LeftPad(std::to_string(second),2,'0'));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'u':
|
case 'u':
|
||||||
{
|
{
|
||||||
@@ -53,7 +50,7 @@ int main(int argc, char** argv)
|
|||||||
break;
|
break;
|
||||||
case 'w':
|
case 'w':
|
||||||
{
|
{
|
||||||
|
|
||||||
text.append(std::to_string(weekday));
|
text.append(std::to_string(weekday));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -72,14 +69,13 @@ int main(int argc, char** argv)
|
|||||||
text.append(Http::HttpUtils::LeftPad(std::to_string(second),2,'0'));
|
text.append(Http::HttpUtils::LeftPad(std::to_string(second),2,'0'));
|
||||||
text.push_back(' ');
|
text.push_back(' ');
|
||||||
text.append(Http::HttpUtils::LeftPad(std::to_string(year),4,'0'));
|
text.append(Http::HttpUtils::LeftPad(std::to_string(year),4,'0'));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
text.append(Http::HttpUtils::LeftPad(std::to_string(year / 100),2,'0'));
|
text.append(Http::HttpUtils::LeftPad(std::to_string(year
|
||||||
break;
|
/ 100),2,'0')); break; case 'Y':
|
||||||
case 'Y':
|
|
||||||
text.append(Http::HttpUtils::LeftPad(std::to_string(year),4,'0'));
|
text.append(Http::HttpUtils::LeftPad(std::to_string(year),4,'0'));
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
@@ -90,7 +86,7 @@ int main(int argc, char** argv)
|
|||||||
auto hours = hour % 12;
|
auto hours = hour % 12;
|
||||||
if(hours == 0) hours=12;
|
if(hours == 0) hours=12;
|
||||||
text.append(Http::HttpUtils::LeftPad(std::to_string(hours),2,'0'));
|
text.append(Http::HttpUtils::LeftPad(std::to_string(hours),2,'0'));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
case 'b':
|
case 'b':
|
||||||
@@ -110,24 +106,37 @@ int main(int argc, char** argv)
|
|||||||
break;
|
break;
|
||||||
*/
|
*/
|
||||||
std::cout << argv[0] << " <fmt>" << std::endl;
|
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 << "The fmt is for DateTime::ToString(fmt) just like "
|
||||||
std::cout << "%a: weekday short eg " << dt.ToString("%a") << std::endl;
|
"strftime but just these are supported:"
|
||||||
std::cout << "%A: weekday long eg " << dt.ToString("%A") << std::endl;
|
<< std::endl;
|
||||||
std::cout << "%S: seconds with leading zeros eg " << dt.ToString("%S") << std::endl;
|
std::cout << "%a: weekday short eg " << dt.ToString("%a")
|
||||||
std::cout << "%m: month with leading zeros eg " << dt.ToString("%m") << std::endl;
|
<< std::endl;
|
||||||
std::cout << "%d: day with leading zeros eg " << dt.ToString("%d") << std::endl;
|
std::cout << "%A: weekday long eg " << dt.ToString("%A")
|
||||||
std::cout << "%e: day with leading spaces eg " << dt.ToString("%e") << std::endl;
|
<< std::endl;
|
||||||
std::cout << "%M: minute with leading zeros eg " << dt.ToString("%M") << std::endl;
|
std::cout << "%S: seconds with leading zeros eg "
|
||||||
std::cout << "%H: 24 hour with leading zeros eg " << dt.ToString("%H") << std::endl;
|
<< dt.ToString("%S") << std::endl;
|
||||||
std::cout << "%F: %Y-%m-%d like this " << dt.ToString("%F") << std::endl;
|
std::cout << "%m: month with leading zeros eg " << dt.ToString("%m")
|
||||||
std::cout << "%D: %m/%d/%y like this " << dt.ToString("%D") << std::endl;
|
<< std::endl;
|
||||||
std::cout << "%y: year two digits eg " << dt.ToString("%y") << std::endl;
|
std::cout << "%d: day with leading zeros eg " << dt.ToString("%d")
|
||||||
std::cout << "%Y: year four digits eg " << dt.ToString("%Y") << std::endl;
|
<< 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;
|
return 1;
|
||||||
}
|
}
|
||||||
std::cout << dt.ToString(argv[1]) << std::endl;
|
std::cout << dt.ToString(argv[1]) << std::endl;
|
||||||
}
|
} else
|
||||||
else
|
std::cout << dt.ToString() << std::endl;
|
||||||
std::cout << dt.ToString() << std::endl;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,61 +6,67 @@ using namespace Tesses::Framework::Filesystem;
|
|||||||
using namespace Tesses::Framework::Serialization::Bencode;
|
using namespace Tesses::Framework::Serialization::Bencode;
|
||||||
using namespace Tesses::Framework::TextStreams;
|
using namespace Tesses::Framework::TextStreams;
|
||||||
using namespace Tesses::Framework::BitTorrent;
|
using namespace Tesses::Framework::BitTorrent;
|
||||||
void usage(Args& args)
|
void usage(Args &args) {
|
||||||
{
|
std::cout << "USAGE: " << args.filename
|
||||||
std::cout << "USAGE: " << args.filename << " [options] torrent_contents torrent_file.torrent" << std::endl << std::endl;
|
<< " [options] torrent_contents torrent_file.torrent" << std::endl
|
||||||
|
<< std::endl;
|
||||||
std::cout << "OPTIONS:" << 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 << "webseed: url for web seeding" << std::endl;
|
||||||
std::cout << "comment: set the comment" << 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 << "created_by: set the created by field, defaults to "
|
||||||
std::cout << "piece_length: set the piece length, defaults to " + std::to_string(DEFAULT_PIECE_LENGTH) << std::endl << std::endl;
|
"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 << "FLAGS:" << std::endl;
|
||||||
std::cout << "help: bring this help message up" << std::endl;
|
std::cout << "help: bring this help message up" << std::endl;
|
||||||
std::cout << "private: enable private tracker flag" << std::endl;
|
std::cout << "private: enable private tracker flag" << std::endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char **argv) {
|
||||||
{
|
|
||||||
TF_Init();
|
TF_Init();
|
||||||
std::vector<BeString> webseeds;
|
std::vector<BeString> webseeds;
|
||||||
std::vector<BeString> trackers;
|
std::vector<BeString> trackers;
|
||||||
bool isPrivate=false;
|
bool isPrivate = false;
|
||||||
int64_t pieceLength = DEFAULT_PIECE_LENGTH;
|
int64_t pieceLength = DEFAULT_PIECE_LENGTH;
|
||||||
std::string comment="";
|
std::string comment = "";
|
||||||
std::string created_by = "TessesFrameworkTorrent";
|
std::string created_by = "TessesFrameworkTorrent";
|
||||||
|
|
||||||
Args args(argc, argv);
|
Args args(argc, argv);
|
||||||
if(args.positional.size() < 2)
|
if (args.positional.size() < 2)
|
||||||
usage(args);
|
usage(args);
|
||||||
|
|
||||||
for(auto& opt : args.options)
|
for (auto &opt : args.options) {
|
||||||
{
|
if (opt.first == "tracker")
|
||||||
if(opt.first == "tracker")
|
|
||||||
trackers.push_back(opt.second);
|
trackers.push_back(opt.second);
|
||||||
else if(opt.first == "webseed")
|
else if (opt.first == "webseed")
|
||||||
webseeds.push_back(opt.second);
|
webseeds.push_back(opt.second);
|
||||||
else if(opt.first == "comment")
|
else if (opt.first == "comment")
|
||||||
comment = opt.second;
|
comment = opt.second;
|
||||||
else if(opt.first == "created_by")
|
else if (opt.first == "created_by")
|
||||||
created_by = opt.second;
|
created_by = opt.second;
|
||||||
else if(opt.first == "piece_length")
|
else if (opt.first == "piece_length")
|
||||||
pieceLength = std::stoll(opt.second);
|
pieceLength = std::stoll(opt.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(auto& flag : args.flags)
|
for (auto &flag : args.flags) {
|
||||||
{
|
if (flag == "help")
|
||||||
if(flag == "help")
|
|
||||||
usage(args);
|
usage(args);
|
||||||
if(flag == "private")
|
if (flag == "private")
|
||||||
isPrivate = true;
|
isPrivate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(trackers.empty())
|
if (trackers.empty())
|
||||||
usage(args);
|
usage(args);
|
||||||
{
|
{
|
||||||
auto torrent_file_stream = LocalFS->OpenFile(args.positional[1],"wb");
|
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);
|
TorrentFile::CreateTorrent(torrent_file_stream, trackers, webseeds,
|
||||||
|
LocalFS, args.positional[0], isPrivate,
|
||||||
|
pieceLength, comment, created_by);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
#include "TessesFramework/Uuid.hpp"
|
#include "TessesFramework/Uuid.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char **argv) {
|
||||||
{
|
// e794499c
|
||||||
//e794499c
|
|
||||||
using namespace Tesses::Framework;
|
using namespace Tesses::Framework;
|
||||||
|
|
||||||
Uuid uuid = Uuid::Generate();
|
Uuid uuid = Uuid::Generate();
|
||||||
@@ -20,5 +19,7 @@ int main(int argc, char** argv)
|
|||||||
uuid.node[4] = 0xb4;
|
uuid.node[4] = 0xb4;
|
||||||
uuid.node[5] = 0xac;*/
|
uuid.node[5] = 0xac;*/
|
||||||
|
|
||||||
std::cout << uuid.ToString(Tesses::Framework::UuidStringifyConfig::LowercaseNoCurly) << std::endl;
|
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;
|
||||||
using namespace Tesses::Framework::Filesystem::Literals;
|
using namespace Tesses::Framework::Filesystem::Literals;
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char **argv) {
|
||||||
{
|
|
||||||
TF_Init();
|
TF_Init();
|
||||||
if(argc<2)
|
if (argc < 2) {
|
||||||
{
|
|
||||||
std::cout << "USAGE " << argv[0] << " <file|dir>" << std::endl;
|
std::cout << "USAGE " << argv[0] << " <file|dir>" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto watcher=FSWatcher::Create(LocalFS,VFSPath{argv[1]});
|
auto watcher = FSWatcher::Create(LocalFS, VFSPath{argv[1]});
|
||||||
watcher->events = FSWatcherEventType::All;
|
watcher->events = FSWatcherEventType::All;
|
||||||
watcher->event = [](FSWatcherEvent& evt)->void{
|
watcher->event = [](FSWatcherEvent &evt) -> void {
|
||||||
std::cout << evt.ToString() << std::endl;
|
std::cout << evt.ToString() << std::endl;
|
||||||
};
|
};
|
||||||
watcher->SetEnabled(true);
|
watcher->SetEnabled(true);
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.0.4
|
||||||
|
Overhaul cmake configuration, add console api, fix http code that caused issues with cgi-bin
|
||||||
|
|
||||||
## 0.0.3
|
## 0.0.3
|
||||||
Add server sent events, change vfs structure, dark mode error pages and dark mode anonydrop
|
Add server sent events, change vfs structure, dark mode error pages and dark mode anonydrop
|
||||||
|
|
||||||
|
|||||||
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)
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
list(APPEND TESSESFRAMEWORK_SOURCE
|
list(APPEND TESSESFRAMEWORK_SOURCE
|
||||||
|
src/Console.cpp
|
||||||
src/Random.cpp
|
src/Random.cpp
|
||||||
src/Date/Date.cpp
|
src/Date/Date.cpp
|
||||||
src/Http/FileServer.cpp
|
src/Http/FileServer.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)
|
||||||
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;
|
using namespace Tesses::Framework::Filesystem;
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char **argv) {
|
||||||
{
|
|
||||||
LocalFilesystem fs;
|
LocalFilesystem fs;
|
||||||
VFSPath src = fs.SystemToVFSPath(argv[1]);
|
VFSPath src = fs.SystemToVFSPath(argv[1]);
|
||||||
VFSPath dest = fs.SystemToVFSPath(argv[2]);
|
VFSPath dest = fs.SystemToVFSPath(argv[2]);
|
||||||
auto srcs = fs.OpenFile(src,"rb");
|
auto srcs = fs.OpenFile(src, "rb");
|
||||||
auto dests = fs.OpenFile(dest,"wb");
|
auto dests = fs.OpenFile(dest, "wb");
|
||||||
srcs->CopyTo(dests);
|
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::Filesystem;
|
||||||
using namespace Tesses::Framework::Streams;
|
using namespace Tesses::Framework::Streams;
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char **argv) {
|
||||||
{
|
if (argc < 2) {
|
||||||
if(argc < 2)
|
printf("USAGE: %s <command> <args...>\n", argv[0]);
|
||||||
{
|
|
||||||
printf("USAGE: %s <command> <args...>\n",argv[0]);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string root = "./root";
|
std::string root = "./root";
|
||||||
std::string mountDemi = "./demi";
|
std::string mountDemi = "./demi";
|
||||||
std::string mountJoelSlashJim = "./joelslashjim";
|
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("/demi"), mountDemidir);
|
||||||
|
|
||||||
fs->Mount(std::string("/joel/jim"), mountjohnslashjim);
|
fs->Mount(std::string("/joel/jim"), mountjohnslashjim);
|
||||||
|
|
||||||
std::string command = argv[1];
|
std::string command = argv[1];
|
||||||
|
|
||||||
|
if (command == "ls") {
|
||||||
if(command == "ls")
|
|
||||||
{
|
|
||||||
std::string dir = "/";
|
std::string dir = "/";
|
||||||
if(argc > 2) dir = argv[2];
|
if (argc > 2)
|
||||||
|
dir = argv[2];
|
||||||
for(auto item : fs->EnumeratePaths(dir))
|
|
||||||
{
|
for (auto item : fs->EnumeratePaths(dir)) {
|
||||||
std::cout << item.GetFileName() << std::endl;
|
std::cout << item.GetFileName() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
} else if (command == "cat") {
|
||||||
else if(command == "cat")
|
std::shared_ptr<FileStream> strm =
|
||||||
{
|
std::make_shared<FileStream>(stdout, false, "wb", false);
|
||||||
std::shared_ptr<FileStream> strm = std::make_shared<FileStream>(stdout, false,"wb",false);
|
for (int a = 2; a < argc; a++) {
|
||||||
for(int a = 2; a < argc; a++)
|
|
||||||
{
|
|
||||||
std::string path = argv[a];
|
std::string path = argv[a];
|
||||||
auto f = fs->OpenFile(path,"rb");
|
auto f = fs->OpenFile(path, "rb");
|
||||||
if(f != nullptr)
|
if (f != nullptr) {
|
||||||
{
|
|
||||||
f->CopyTo(strm);
|
f->CopyTo(strm);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -3,14 +3,15 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
using namespace Tesses::Framework::Filesystem;
|
using namespace Tesses::Framework::Filesystem;
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
int main(int argc, char** argv)
|
|
||||||
{
|
|
||||||
VFSPath path("C:/home/user/file");
|
VFSPath path("C:/home/user/file");
|
||||||
VFSPath path2("D:/home/user/file");
|
VFSPath path2("D:/home/user/file");
|
||||||
VFSPath path3("C:/home/user");
|
VFSPath path3("C:/home/user");
|
||||||
std::cout << path.MakeRelative(path2).ToString() << std::endl;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -2,12 +2,10 @@
|
|||||||
|
|
||||||
using namespace Tesses::Framework::Serialization::Json;
|
using namespace Tesses::Framework::Serialization::Json;
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char **argv) {
|
||||||
{
|
|
||||||
auto json = Json::Decode("\"\\uD83D\\uDE44\"");
|
auto json = Json::Decode("\"\\uD83D\\uDE44\"");
|
||||||
std::string str;
|
std::string str;
|
||||||
if(TryGetJToken(json,str))
|
if (TryGetJToken(json, str)) {
|
||||||
{
|
|
||||||
std::cout << str << std::endl;
|
std::cout << str << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,17 +3,15 @@
|
|||||||
|
|
||||||
using namespace Tesses::Framework::Filesystem;
|
using namespace Tesses::Framework::Filesystem;
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char **argv) {
|
||||||
{
|
if (argc < 3) {
|
||||||
if(argc < 3)
|
|
||||||
{
|
|
||||||
std::cout << "USAGE: " << argv[0] << " <parent> <subpath>\n";
|
std::cout << "USAGE: " << argv[0] << " <parent> <subpath>\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
VFSPath parent(argv[1]);
|
VFSPath parent(argv[1]);
|
||||||
VFSPath subpath(argv[2]);
|
VFSPath subpath(argv[2]);
|
||||||
VFSPath newPath(parent,subpath.CollapseRelativeParents());
|
VFSPath newPath(parent, subpath.CollapseRelativeParents());
|
||||||
|
|
||||||
std::cout << newPath.ToString() << "\n";
|
std::cout << newPath.ToString() << "\n";
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
#include "TessesFramework/TessesFramework.hpp"
|
#include "TessesFramework/TessesFramework.hpp"
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char **argv) {
|
||||||
{
|
|
||||||
Tesses::Framework::TF_Init();
|
Tesses::Framework::TF_Init();
|
||||||
std::cout << "Basic auth test" << std::endl;
|
std::cout << "Basic auth test" << std::endl;
|
||||||
std::string theEncoded="dXNlcjpwYXNz";
|
std::string theEncoded = "dXNlcjpwYXNz";
|
||||||
Tesses::Framework::Http::ServerContext ctx(nullptr);
|
Tesses::Framework::Http::ServerContext ctx(nullptr);
|
||||||
ctx.requestHeaders.SetValue("Authorization","Basic " + theEncoded);
|
ctx.requestHeaders.SetValue("Authorization", "Basic " + theEncoded);
|
||||||
std::string user;
|
std::string user;
|
||||||
std::string pass;
|
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 << user << std::endl;
|
||||||
std::cout << pass << std::endl;
|
std::cout << pass << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,12 @@
|
|||||||
#include "TessesFramework/Common.hpp"
|
#include "TessesFramework/Common.hpp"
|
||||||
#include "TessesFramework/TessesFramework.hpp"
|
#include "TessesFramework/TessesFramework.hpp"
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
int main(int argc, char** argv)
|
|
||||||
{
|
|
||||||
using namespace Tesses::Framework;
|
using namespace Tesses::Framework;
|
||||||
TF_Init();
|
TF_Init();
|
||||||
|
|
||||||
auto timer = TF_Timer([]()->void {
|
auto timer = TF_Timer(
|
||||||
std::cout << "Hi, I am a timer" << std::endl;
|
[]() -> void { std::cout << "Hi, I am a timer" << std::endl; });
|
||||||
});
|
|
||||||
|
|
||||||
TF_RunEventLoop();
|
TF_RunEventLoop();
|
||||||
|
|
||||||
|
|||||||
@@ -11,206 +11,171 @@ using namespace Tesses::Framework::Threading;
|
|||||||
|
|
||||||
std::shared_ptr<ServerSentEvents> sse = std::make_shared<ServerSentEvents>();
|
std::shared_ptr<ServerSentEvents> sse = std::make_shared<ServerSentEvents>();
|
||||||
|
|
||||||
class Johnny : public ServerContextData
|
class Johnny : public ServerContextData {
|
||||||
{
|
public:
|
||||||
public:
|
Johnny() { text = "Steve Ballmer"; }
|
||||||
Johnny()
|
std::string text;
|
||||||
{
|
~Johnny() { std::cout << "Destroying" << std::endl; }
|
||||||
text = "Steve Ballmer";
|
|
||||||
}
|
|
||||||
std::string text;
|
|
||||||
~Johnny()
|
|
||||||
{
|
|
||||||
std::cout << "Destroying" << std::endl;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
class MyWebServer : public IHttpServer {
|
class MyWebServer : public IHttpServer {
|
||||||
public:
|
public:
|
||||||
bool Handle(ServerContext& ctx)
|
bool Handle(ServerContext &ctx) {
|
||||||
{
|
std::cout << ctx.path << std::endl;
|
||||||
std::cout << ctx.path << std::endl;
|
if (ctx.path == "/") {
|
||||||
if(ctx.path == "/")
|
std::shared_ptr<FileStream> fs =
|
||||||
{
|
std::make_shared<FileStream>("index.html", "rb");
|
||||||
std::shared_ptr<FileStream> fs = std::make_shared<FileStream>("index.html","rb");
|
|
||||||
|
|
||||||
ctx
|
ctx.WithMimeType("text/html").SendStream(fs);
|
||||||
.WithMimeType("text/html")
|
return true;
|
||||||
.SendStream(fs);
|
} else if (ctx.path == "/mypath.html") {
|
||||||
return true;
|
std::string txt =
|
||||||
}
|
"<h1>Root: " + HttpUtils::HtmlEncode(ctx.GetServerRoot()) +
|
||||||
else if(ctx.path == "/mypath.html")
|
"</h1>";
|
||||||
{
|
ctx.WithMimeType("text/html").SendText(txt);
|
||||||
std::string txt = "<h1>Root: " + HttpUtils::HtmlEncode(ctx.GetServerRoot()) + "</h1>";
|
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);
|
ctx.WithMimeType("text/html").SendText(txt);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if(ctx.path == "/getabsolute.html")
|
} else if (ctx.path == "/streaming.html") {
|
||||||
{
|
StreamWriter writer(ctx.OpenResponseStream());
|
||||||
std::string path;
|
writer.WriteLine("<html>");
|
||||||
if(ctx.queryParams.TryGetFirst("path",path))
|
writer.WriteLine("<head><title>Streaming</title></head>");
|
||||||
{
|
writer.WriteLine("<body>");
|
||||||
std::string txt = "<h1>Path: " + HttpUtils::HtmlEncode(ctx.MakeAbsolute(path)) + "</h1>";
|
|
||||||
ctx.WithMimeType("text/html").SendText(txt);
|
writer.WriteLine("<h1>Streaming</h1>");
|
||||||
return true;
|
|
||||||
}
|
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++)
|
} else if (ctx.path == "/sse") {
|
||||||
{
|
ctx.SendServerSentEvents(sse);
|
||||||
writer.WriteLine("<li>" + std::to_string(i) + "</li>");
|
return true;
|
||||||
TF_Sleep(10);
|
} else if (ctx.path == "/main.js") {
|
||||||
}
|
|
||||||
|
|
||||||
writer.WriteLine("</ul>");
|
std::shared_ptr<FileStream> fs =
|
||||||
|
std::make_shared<FileStream>("main.js", "rb");
|
||||||
|
|
||||||
writer.WriteLine("</body>");
|
ctx.WithMimeType("text/js").SendStream(fs);
|
||||||
writer.WriteLine("</html>");
|
return true;
|
||||||
return true;
|
} else if (ctx.path == "/upload") {
|
||||||
}
|
ctx.ParseFormData(
|
||||||
else if(ctx.path == "/ssetest.html")
|
[](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 == "/sse")
|
|
||||||
{
|
|
||||||
ctx.SendServerSentEvents(sse);
|
|
||||||
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");
|
|
||||||
});
|
});
|
||||||
}
|
} else if (ctx.path == "/steve") {
|
||||||
else if(ctx.path == "/steve")
|
Johnny *data = ctx.GetServerContentData<Johnny>("mytag");
|
||||||
{
|
data->text = "Demi Lovato";
|
||||||
Johnny* data = ctx.GetServerContentData<Johnny>("mytag");
|
|
||||||
data->text = "Demi Lovato";
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
class MyOtherWebServer : public IHttpServer
|
class MyOtherWebServer : public IHttpServer {
|
||||||
{
|
public:
|
||||||
public:
|
bool Handle(ServerContext &ctx) {
|
||||||
bool Handle(ServerContext& ctx)
|
TF_LOG("IN HANDLE");
|
||||||
{
|
if (ctx.path == "/") {
|
||||||
TF_LOG("IN HANDLE");
|
|
||||||
if(ctx.path == "/")
|
|
||||||
{
|
|
||||||
std::string name;
|
std::string name;
|
||||||
if(ctx.queryParams.TryGetFirst("name",name))
|
if (ctx.queryParams.TryGetFirst("name", name)) {
|
||||||
{
|
|
||||||
std::cout << name << std::endl;
|
std::cout << name << std::endl;
|
||||||
TF_LOG(name);
|
TF_LOG(name);
|
||||||
ctx
|
ctx.WithMimeType("text/plain")
|
||||||
.WithMimeType("text/plain")
|
.WithContentDisposition(HttpUtils::Sanitise(name) + ".txt",
|
||||||
.WithContentDisposition(HttpUtils::Sanitise(name) + ".txt",false)
|
false)
|
||||||
.SendText(name + " is cool.");
|
.SendText(name + " is cool.");
|
||||||
//do something with q
|
// do something with q
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
} else if (ctx.path == "/status") {
|
||||||
else if(ctx.path == "/status")
|
int64_t num;
|
||||||
{
|
if (ctx.queryParams.TryGetFirstInt("code", num)) {
|
||||||
int64_t num;
|
ctx.statusCode = (StatusCode)num;
|
||||||
if(ctx.queryParams.TryGetFirstInt("code", num))
|
|
||||||
{
|
|
||||||
ctx.statusCode = (StatusCode)num;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
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();
|
TF_InitWithConsole();
|
||||||
int64_t timer = 0;
|
int64_t timer = 0;
|
||||||
auto timerHDL= TF_Timer([&timer]()->void{
|
auto timerHDL = TF_Timer([&timer]() -> void {
|
||||||
timer++;
|
timer++;
|
||||||
|
|
||||||
sse->SendData("Timer has ticked " + std::to_string(timer) + " times now");
|
sse->SendData("Timer has ticked " + std::to_string(timer) +
|
||||||
|
" times now");
|
||||||
});
|
});
|
||||||
|
|
||||||
std::shared_ptr<RouteServer> routeSvr = std::make_shared<RouteServer>();
|
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;
|
std::string name;
|
||||||
if(ctx.pathArguments.TryGetFirst("name",name))
|
if (ctx.pathArguments.TryGetFirst("name", name)) {
|
||||||
{
|
|
||||||
ctx.WithMimeType("text/plain").SendText("Hello " + name);
|
ctx.WithMimeType("text/plain").SendText("Hello " + name);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
ctx.WithMimeType("text/plain").SendText("Please provide a name");
|
ctx.WithMimeType("text/plain").SendText("Please provide a name");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
routeSvr->Get("/name/{name}/length",[](ServerContext& ctx)->bool{
|
routeSvr->Get("/name/{name}/length", [](ServerContext &ctx) -> bool {
|
||||||
std::string name;
|
std::string name;
|
||||||
if(ctx.pathArguments.TryGetFirst("name",name))
|
if (ctx.pathArguments.TryGetFirst("name", name)) {
|
||||||
{
|
ctx.WithMimeType("text/plain")
|
||||||
ctx.WithMimeType("text/plain").SendText("The length of the name is " + std::to_string(name.size()));
|
.SendText("The length of the name is " +
|
||||||
}
|
std::to_string(name.size()));
|
||||||
else {
|
} else {
|
||||||
ctx.WithMimeType("text/plain").SendText("Please provide a name");
|
ctx.WithMimeType("text/plain").SendText("Please provide a name");
|
||||||
}
|
}
|
||||||
return true;
|
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<MyWebServer> mws = std::make_shared<MyWebServer>();
|
||||||
|
|
||||||
std::shared_ptr<MountableServer> mountable = std::make_shared<MountableServer>(myo);
|
std::shared_ptr<MountableServer> mountable =
|
||||||
mountable->Mount("/mymount/",mws);
|
std::make_shared<MountableServer>(myo);
|
||||||
|
mountable->Mount("/mymount/", mws);
|
||||||
mountable->Mount("/routeSvr/", routeSvr);
|
mountable->Mount("/routeSvr/", routeSvr);
|
||||||
HttpServer server(10001,mountable);
|
HttpServer server(10001, mountable);
|
||||||
server.StartAccepting();
|
server.StartAccepting();
|
||||||
TF_RunEventLoop();
|
TF_RunEventLoop();
|
||||||
std::cout << "Closing server" << std::endl;
|
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>
|
#include <iostream>
|
||||||
using namespace Tesses::Framework::Http;
|
using namespace Tesses::Framework::Http;
|
||||||
|
|
||||||
class WebSocketConn : public WebSocketConnection
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
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();
|
Tesses::Framework::TF_Init();
|
||||||
HttpDictionary reqHeaders;
|
HttpDictionary reqHeaders;
|
||||||
std::shared_ptr<WebSocketConn> conn = std::make_shared<WebSocketConn>();
|
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;
|
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
|
#pragma once
|
||||||
#include "Common.hpp"
|
#include "Common.hpp"
|
||||||
namespace Tesses::Framework {
|
namespace Tesses::Framework {
|
||||||
class Args {
|
class Args {
|
||||||
public:
|
public:
|
||||||
Args(std::vector<std::string> args);
|
Args(std::vector<std::string> args);
|
||||||
Args(int argc, char** argv);
|
Args(int argc, char **argv);
|
||||||
std::string filename;
|
std::string filename;
|
||||||
std::vector<std::string> positional;
|
std::vector<std::string> positional;
|
||||||
std::vector<std::string> flags;
|
std::vector<std::string> flags;
|
||||||
std::vector<std::pair<std::string,std::string>> options;
|
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
|
#pragma once
|
||||||
#include "../Serialization/Bencode.hpp"
|
#include "../Serialization/Bencode.hpp"
|
||||||
#include "TorrentStream.hpp"
|
#include "TorrentStream.hpp"
|
||||||
namespace Tesses::Framework::BitTorrent
|
namespace Tesses::Framework::BitTorrent {
|
||||||
{
|
constexpr int DEFAULT_PIECE_LENGTH = 524288;
|
||||||
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();
|
|
||||||
|
|
||||||
/// @brief Used to load a dictionary in, will overwrite all the fields
|
class TorrentFileInfo {
|
||||||
/// @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);
|
|
||||||
|
|
||||||
/// @brief Create info from file/directory
|
Serialization::Bencode::BeDictionary info;
|
||||||
/// @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);
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
TorrentFileInfo();
|
||||||
|
TorrentFileInfo(const Serialization::Bencode::BeDictionary &tkn);
|
||||||
|
|
||||||
Serialization::Bencode::BeString announce;
|
int64_t piece_length = DEFAULT_PIECE_LENGTH;
|
||||||
std::vector<Serialization::Bencode::BeString> announce_list;
|
Serialization::Bencode::BeString pieces;
|
||||||
std::vector<Serialization::Bencode::BeString> url_list;
|
int64_t isPrivate = 0;
|
||||||
Serialization::Bencode::BeString comment;
|
Serialization::Bencode::BeString name;
|
||||||
Serialization::Bencode::BeString created_by;
|
std::variant<int64_t, std::vector<TorrentFileEntry>> fileListOrLength;
|
||||||
int64_t creation_date=0;
|
int64_t GetTorrentFileSize();
|
||||||
TorrentFileInfo info;
|
/// @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
|
#pragma once
|
||||||
|
|
||||||
#include "TessesFramework/Http/HttpClient.hpp"
|
#include "TessesFramework/Http/HttpClient.hpp"
|
||||||
#include "TessesFramework/Streams/NetworkStream.hpp"
|
#include "TessesFramework/Streams/NetworkStream.hpp"
|
||||||
namespace Tesses::Framework::BitTorrent
|
namespace Tesses::Framework::BitTorrent {
|
||||||
{
|
class TorrentFileEntry {
|
||||||
class TorrentFileEntry {
|
public:
|
||||||
public:
|
TorrentFileEntry();
|
||||||
TorrentFileEntry();
|
TorrentFileEntry(Tesses::Framework::Filesystem::VFSPath path,
|
||||||
TorrentFileEntry(Tesses::Framework::Filesystem::VFSPath path, int64_t length);
|
int64_t length);
|
||||||
Tesses::Framework::Filesystem::VFSPath path;
|
Tesses::Framework::Filesystem::VFSPath path;
|
||||||
int64_t length=0;
|
int64_t length = 0;
|
||||||
};
|
};
|
||||||
class ReadWriteAt {
|
class ReadWriteAt {
|
||||||
public:
|
public:
|
||||||
virtual bool ReadBlockAt(uint64_t offset, uint8_t* data, size_t len)=0;
|
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 void WriteBlockAt(uint64_t offset, const uint8_t *data,
|
||||||
virtual ~ReadWriteAt();
|
size_t len) = 0;
|
||||||
|
virtual ~ReadWriteAt();
|
||||||
|
};
|
||||||
|
|
||||||
};
|
class TorrentFileStream : public ReadWriteAt {
|
||||||
|
Tesses::Framework::Threading::Mutex mtx;
|
||||||
|
|
||||||
class TorrentFileStream : public ReadWriteAt
|
public:
|
||||||
{
|
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs;
|
||||||
Tesses::Framework::Threading::Mutex mtx;
|
Tesses::Framework::Filesystem::VFSPath path;
|
||||||
public:
|
uint64_t length;
|
||||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs;
|
TorrentFileStream(std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs,
|
||||||
Tesses::Framework::Filesystem::VFSPath path;
|
Tesses::Framework::Filesystem::VFSPath path,
|
||||||
uint64_t length;
|
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);
|
||||||
bool ReadBlockAt(uint64_t offset, uint8_t* data, size_t len);
|
void WriteBlockAt(uint64_t offset, const uint8_t *data, size_t len);
|
||||||
void WriteBlockAt(uint64_t offset, const uint8_t* data, size_t len);
|
};
|
||||||
|
class TorrentDirectoryStream : public ReadWriteAt {
|
||||||
|
|
||||||
};
|
std::vector<Tesses::Framework::Threading::Mutex> mtxs;
|
||||||
class TorrentDirectoryStream : public ReadWriteAt
|
|
||||||
{
|
|
||||||
|
|
||||||
std::vector<Tesses::Framework::Threading::Mutex> mtxs;
|
public:
|
||||||
public:
|
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs;
|
||||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs;
|
Tesses::Framework::Filesystem::VFSPath path;
|
||||||
Tesses::Framework::Filesystem::VFSPath path;
|
std::vector<TorrentFileEntry> entries;
|
||||||
std::vector<TorrentFileEntry> entries;
|
TorrentDirectoryStream(
|
||||||
TorrentDirectoryStream(std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs, Tesses::Framework::Filesystem::VFSPath path,std::vector<TorrentFileEntry> entries);
|
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs,
|
||||||
bool ReadBlockAt(uint64_t offset, uint8_t* data, size_t len);
|
Tesses::Framework::Filesystem::VFSPath path,
|
||||||
void WriteBlockAt(uint64_t offset, const uint8_t* data, size_t len);
|
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,98 +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
|
#pragma once
|
||||||
|
|
||||||
|
#include "Threading/Mutex.hpp"
|
||||||
|
#include <atomic>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cstring>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstring>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <functional>
|
||||||
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
#include <ratio>
|
#include <ratio>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <filesystem>
|
|
||||||
#include <map>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <functional>
|
|
||||||
#include "Threading/Mutex.hpp"
|
|
||||||
#include <optional>
|
|
||||||
#include <atomic>
|
|
||||||
|
|
||||||
namespace Tesses::Framework
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
class TF_Timer_Handler {
|
|
||||||
private:
|
|
||||||
std::vector<std::weak_ptr<TF_Timer_Handle>> handles;
|
|
||||||
public:
|
|
||||||
void Update();
|
|
||||||
|
|
||||||
|
namespace Tesses::Framework {
|
||||||
static std::shared_ptr<TF_Timer_Handle> Make(std::shared_ptr<TF_Timer_Handler> handler);
|
|
||||||
friend class TF_Timer_Handle;
|
|
||||||
};
|
|
||||||
|
|
||||||
class TF_Timer_Handle {
|
class TF_Timer_Handle;
|
||||||
|
// Used for internal purposes, don't use unless you want to run timer events on
|
||||||
private:
|
// another thread
|
||||||
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);
|
class TF_Timer_Handler {
|
||||||
|
private:
|
||||||
|
std::vector<std::weak_ptr<TF_Timer_Handle>> handles;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
void Update();
|
||||||
void SetCallback(std::function<void()> cb);
|
|
||||||
|
|
||||||
int64_t GetIntervalMilliseconds();
|
static std::shared_ptr<TF_Timer_Handle>
|
||||||
std::chrono::duration<int64_t,std::milli> GetIntervalDuration();
|
Make(std::shared_ptr<TF_Timer_Handler> handler);
|
||||||
|
friend class TF_Timer_Handle;
|
||||||
|
};
|
||||||
|
|
||||||
void SetIntervalFromMilliseconds(int64_t ms);
|
class TF_Timer_Handle {
|
||||||
|
|
||||||
void SetIntervalFromDuration(std::chrono::milliseconds dur);
|
|
||||||
|
|
||||||
|
|
||||||
void SetEnabled(bool enabled);
|
private:
|
||||||
bool GetEnabled();
|
std::shared_ptr<TF_Timer_Handler> timerHandler;
|
||||||
friend class TF_Timer_Handler;
|
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);
|
||||||
|
|
||||||
std::shared_ptr<TF_Timer_Handle> TF_Timer();
|
public:
|
||||||
std::shared_ptr<TF_Timer_Handle> TF_Timer(std::function<void()> cb, int64_t interval=1000, bool enabled=true);
|
void SetCallback(std::function<void()> cb);
|
||||||
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();
|
|
||||||
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
|
|
||||||
|
|
||||||
|
int64_t GetIntervalMilliseconds();
|
||||||
|
std::chrono::duration<int64_t, std::milli> GetIntervalDuration();
|
||||||
|
|
||||||
#if defined(TESSESFRAMEWORK_LOGTOFILE)
|
void SetIntervalFromMilliseconds(int64_t ms);
|
||||||
#define TF_LOG(log) Tesses::Framework::TF_Log(log)
|
|
||||||
#else
|
void SetIntervalFromDuration(std::chrono::milliseconds dur);
|
||||||
#define TF_LOG(log)
|
|
||||||
#endif
|
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
|
#pragma once
|
||||||
#include "../Streams/Stream.hpp"
|
#include "../Streams/Stream.hpp"
|
||||||
|
|
||||||
|
namespace Tesses::Framework::Crypto {
|
||||||
|
class ClientTLSStream : public Tesses::Framework::Streams::Stream {
|
||||||
|
void *privateData;
|
||||||
|
|
||||||
namespace Tesses::Framework::Crypto
|
public:
|
||||||
{
|
static std::string GetCertChain();
|
||||||
class ClientTLSStream : public Tesses::Framework::Streams::Stream {
|
|
||||||
void* privateData;
|
|
||||||
public:
|
|
||||||
static std::string GetCertChain();
|
|
||||||
|
|
||||||
ClientTLSStream(std::shared_ptr<Tesses::Framework::Streams::Stream> innerStream, bool verify, std::string domain);
|
ClientTLSStream(
|
||||||
ClientTLSStream(std::shared_ptr<Tesses::Framework::Streams::Stream> innerStream, bool verify, std::string domain, std::string cert);
|
std::shared_ptr<Tesses::Framework::Streams::Stream> innerStream,
|
||||||
size_t Read(uint8_t* buff, size_t sz);
|
bool verify, std::string domain);
|
||||||
size_t Write(const uint8_t* buff, size_t sz);
|
ClientTLSStream(
|
||||||
bool CanRead();
|
std::shared_ptr<Tesses::Framework::Streams::Stream> innerStream,
|
||||||
bool CanWrite();
|
bool verify, std::string domain, std::string cert);
|
||||||
bool EndOfStream();
|
size_t Read(uint8_t *buff, size_t sz);
|
||||||
~ClientTLSStream();
|
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
|
#pragma once
|
||||||
#include "../Streams/Stream.hpp"
|
#include "../Streams/Stream.hpp"
|
||||||
namespace Tesses::Framework::Crypto
|
namespace Tesses::Framework::Crypto {
|
||||||
{
|
bool HaveCrypto();
|
||||||
bool HaveCrypto();
|
std::string Base64_Encode(std::vector<uint8_t> data);
|
||||||
std::string Base64_Encode(std::vector<uint8_t> data);
|
std::vector<uint8_t> Base64_Decode(std::string str);
|
||||||
std::vector<uint8_t> Base64_Decode(std::string str);
|
class Sha1 {
|
||||||
class Sha1 {
|
void *inner;
|
||||||
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();
|
|
||||||
|
|
||||||
static std::vector<uint8_t> ComputeHash(const uint8_t* buffer, size_t len,bool is384=false);
|
public:
|
||||||
static std::vector<uint8_t> ComputeHash(std::shared_ptr<Tesses::Framework::Streams::Stream> strm,bool is384=false);
|
Sha1();
|
||||||
};
|
bool Start();
|
||||||
typedef enum {
|
bool Update(const uint8_t *buffer, size_t sz);
|
||||||
VERSION_SHA1=1,
|
bool Update(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||||
VERSION_SHA224=224,
|
std::vector<uint8_t> Finish();
|
||||||
VERSION_SHA256=256,
|
~Sha1();
|
||||||
VERSION_SHA384=384,
|
static std::vector<uint8_t> ComputeHash(const uint8_t *buffer, size_t len);
|
||||||
VERSION_SHA512=512
|
static std::vector<uint8_t>
|
||||||
} ShaVersion;
|
ComputeHash(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||||
bool PBKDF2(std::vector<uint8_t>& output,std::string pass, std::vector<uint8_t>& salt, long itterations, ShaVersion version);
|
};
|
||||||
|
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
|
#pragma once
|
||||||
#include <string>
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace Tesses::Framework::Date
|
namespace Tesses::Framework::Date {
|
||||||
{
|
int GetTimeZone();
|
||||||
int GetTimeZone();
|
bool TimeZoneSupportDST();
|
||||||
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);
|
|
||||||
|
|
||||||
|
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();
|
public:
|
||||||
void SetToNowUTC();
|
DateTime();
|
||||||
static DateTime Now();
|
DateTime(int year, int month, int day, int hour, int minute, int seconds,
|
||||||
static DateTime NowUTC();
|
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;
|
void SetToNow();
|
||||||
std::string ToString(std::string fmt) const;
|
void SetToNowUTC();
|
||||||
|
static DateTime Now();
|
||||||
|
static DateTime NowUTC();
|
||||||
|
|
||||||
|
std::string ToString() const;
|
||||||
|
std::string ToString(std::string fmt) const;
|
||||||
|
|
||||||
std::string ToHttpDate() const;
|
std::string ToHttpDate() const;
|
||||||
static bool TryParseHttpDate(std::string txt, DateTime& dt);
|
static bool TryParseHttpDate(std::string txt, DateTime &dt);
|
||||||
|
};
|
||||||
|
class TimeSpan {
|
||||||
|
int64_t totalSeconds;
|
||||||
|
|
||||||
};
|
public:
|
||||||
class TimeSpan {
|
TimeSpan();
|
||||||
int64_t totalSeconds;
|
TimeSpan(int64_t totalSeconds);
|
||||||
public:
|
TimeSpan(int hours, int minutes, int seconds);
|
||||||
TimeSpan();
|
TimeSpan(int days, int hours, int minutes, int seconds);
|
||||||
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);
|
|
||||||
|
|
||||||
void SetDays(int d);
|
void Set(int days, int hours, int minutes, int seconds);
|
||||||
void SetHours(int h);
|
void Set(int hours, int minutes, int seconds);
|
||||||
void SetMinutes(int m);
|
|
||||||
void SetSeconds(int s);
|
|
||||||
|
|
||||||
|
|
||||||
int Days() const;
|
|
||||||
int Hours() const;
|
|
||||||
int Minutes() const;
|
|
||||||
int Seconds() const;
|
|
||||||
|
|
||||||
|
void SetDays(int d);
|
||||||
|
void SetHours(int h);
|
||||||
|
void SetMinutes(int m);
|
||||||
|
void SetSeconds(int s);
|
||||||
|
|
||||||
int64_t TotalSeconds() const;
|
int Days() const;
|
||||||
int64_t TotalMinutes() const;
|
int Hours() const;
|
||||||
int64_t TotalHours() 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 SetTotalSeconds(int64_t totalSeconds);
|
||||||
void SetTotalMinutes(int64_t totalMinutes);
|
void SetTotalMinutes(int64_t totalMinutes);
|
||||||
void SetTotalHours(int64_t totalHours);
|
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);
|
|
||||||
|
|
||||||
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)
|
inline DateTime operator+(const DateTime &dt, const TimeSpan &ts) {
|
||||||
{
|
DateTime dt2(dt.ToEpoch() + ts.TotalSeconds());
|
||||||
DateTime dt2(dt.ToEpoch() + ts.TotalSeconds());
|
if (dt.IsLocal())
|
||||||
if(dt.IsLocal())
|
dt2.SetToLocal();
|
||||||
dt2.SetToLocal();
|
return dt2;
|
||||||
return dt2;
|
}
|
||||||
}
|
inline DateTime operator+(const TimeSpan &ts, const DateTime &dt) {
|
||||||
inline DateTime operator+(const TimeSpan& ts,const DateTime& dt)
|
DateTime dt2(dt.ToEpoch() + ts.TotalSeconds());
|
||||||
{
|
if (dt.IsLocal())
|
||||||
DateTime dt2(dt.ToEpoch() + ts.TotalSeconds());
|
dt2.SetToLocal();
|
||||||
if(dt.IsLocal())
|
return dt2;
|
||||||
dt2.SetToLocal();
|
}
|
||||||
return dt2;
|
inline TimeSpan operator+(const TimeSpan &ts, const TimeSpan &ts2) {
|
||||||
}
|
return ts.TotalSeconds() + ts2.TotalSeconds();
|
||||||
inline TimeSpan operator+(const TimeSpan& ts, const TimeSpan& ts2)
|
}
|
||||||
{
|
inline DateTime operator-(const DateTime &dt, const TimeSpan &ts) {
|
||||||
return ts.TotalSeconds() + ts2.TotalSeconds();
|
DateTime dt2(dt.ToEpoch() - ts.TotalSeconds());
|
||||||
}
|
if (dt.IsLocal())
|
||||||
inline DateTime operator-(const DateTime& dt, const TimeSpan& ts)
|
dt2.SetToLocal();
|
||||||
{
|
return dt2;
|
||||||
DateTime dt2(dt.ToEpoch() - ts.TotalSeconds());
|
}
|
||||||
if(dt.IsLocal())
|
inline TimeSpan operator-(const DateTime &dt, const DateTime &dt2) {
|
||||||
dt2.SetToLocal();
|
return dt.ToEpoch() - dt2.ToEpoch();
|
||||||
return dt2;
|
}
|
||||||
}
|
inline TimeSpan operator-(const TimeSpan &ts, const TimeSpan &ts2) {
|
||||||
inline TimeSpan operator-(const DateTime& dt, const DateTime& dt2)
|
return ts.TotalSeconds() - ts2.TotalSeconds();
|
||||||
{
|
}
|
||||||
return dt.ToEpoch() - dt2.ToEpoch();
|
}; // namespace Tesses::Framework::Date
|
||||||
}
|
|
||||||
inline TimeSpan operator-(const TimeSpan& ts, const TimeSpan& ts2)
|
|
||||||
{
|
|
||||||
return ts.TotalSeconds() - ts2.TotalSeconds();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -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
|
#pragma once
|
||||||
#include "TempFS.hpp"
|
#include "TempFS.hpp"
|
||||||
#include "VFSFix.hpp"
|
#include "VFSFix.hpp"
|
||||||
|
|
||||||
namespace Tesses::Framework::Filesystem::Helpers
|
namespace Tesses::Framework::Filesystem::Helpers {
|
||||||
{
|
void ReadAllText(std::shared_ptr<VFS> vfs, VFSPath path, std::string &text);
|
||||||
void ReadAllText(std::shared_ptr<VFS> vfs, VFSPath path, std::string& text);
|
void ReadAllLines(std::shared_ptr<VFS> vfs, VFSPath path,
|
||||||
void ReadAllLines(std::shared_ptr<VFS> vfs, VFSPath path, std::vector<std::string>& lines);
|
std::vector<std::string> &lines);
|
||||||
void ReadAllBytes(std::shared_ptr<VFS> vfs, VFSPath path, std::vector<uint8_t>& array);
|
void ReadAllBytes(std::shared_ptr<VFS> vfs, VFSPath path,
|
||||||
std::string ReadAllText(std::shared_ptr<VFS> vfs, VFSPath path);
|
std::vector<uint8_t> &array);
|
||||||
std::vector<std::string> ReadAllLines(std::shared_ptr<VFS> vfs, VFSPath path);
|
std::string ReadAllText(std::shared_ptr<VFS> vfs, VFSPath path);
|
||||||
std::vector<uint8_t> ReadAllBytes(std::shared_ptr<VFS> vfs, VFSPath path);
|
std::vector<std::string> ReadAllLines(std::shared_ptr<VFS> vfs, VFSPath path);
|
||||||
void WriteAllText(std::shared_ptr<VFS> vfs, VFSPath path, const std::string& text);
|
std::vector<uint8_t> ReadAllBytes(std::shared_ptr<VFS> vfs, VFSPath path);
|
||||||
void WriteAllLines(std::shared_ptr<VFS> vfs, VFSPath path, const std::vector<std::string>& parts);
|
void WriteAllText(std::shared_ptr<VFS> vfs, VFSPath path,
|
||||||
void WriteAllBytes(std::shared_ptr<VFS> vfs, VFSPath path, const std::vector<uint8_t>& bytes);
|
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,
|
||||||
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);
|
std::shared_ptr<VFS> vfsDest, VFSPath pathDest,
|
||||||
void CopyDirectory(std::shared_ptr<VFS> vfsSrc, VFSPath pathSrc, std::shared_ptr<VFS> vfsDest, VFSPath pathDest, bool overwrite=true);
|
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,
|
||||||
|
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)
|
inline std::shared_ptr<TempFS> CreateTempFS(bool deleteOnDestroy = true) {
|
||||||
{
|
return std::make_shared<TempFS>(deleteOnDestroy);
|
||||||
return std::make_shared<TempFS>(deleteOnDestroy);
|
}
|
||||||
}
|
inline std::shared_ptr<TempFS> CreateTempFS(std::shared_ptr<VFS> vfs,
|
||||||
inline std::shared_ptr<TempFS> CreateTempFS(std::shared_ptr<VFS> vfs,bool deleteOnDestroy=true)
|
bool deleteOnDestroy = true) {
|
||||||
{
|
return std::make_shared<TempFS>(vfs, deleteOnDestroy);
|
||||||
return std::make_shared<TempFS>(vfs,deleteOnDestroy);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
} // namespace Tesses::Framework::Filesystem::Helpers
|
||||||
@@ -1,46 +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
|
#pragma once
|
||||||
#include "VFS.hpp"
|
#include "VFS.hpp"
|
||||||
#include "VFSFix.hpp"
|
#include "VFSFix.hpp"
|
||||||
|
|
||||||
namespace Tesses::Framework::Filesystem
|
namespace Tesses::Framework::Filesystem {
|
||||||
{
|
class LocalFilesystem : public VFS {
|
||||||
class LocalFilesystem : public VFS
|
public:
|
||||||
{
|
std::shared_ptr<Tesses::Framework::Streams::Stream>
|
||||||
public:
|
OpenFile(VFSPath path, std::string mode);
|
||||||
|
|
||||||
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenFile(VFSPath path, std::string mode);
|
void CreateDirectory(VFSPath path);
|
||||||
|
void DeleteDirectory(VFSPath path);
|
||||||
|
|
||||||
void CreateDirectory(VFSPath path);
|
void DeleteFile(VFSPath path);
|
||||||
void DeleteDirectory(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 DeleteFile(VFSPath path);
|
void MoveDirectory(VFSPath src, VFSPath dest);
|
||||||
void CreateSymlink(VFSPath existingFile, VFSPath symlinkFile);
|
VFSPath ReadLink(VFSPath path);
|
||||||
VFSPathEnumerator EnumeratePaths(VFSPath path);
|
std::string VFSPathToSystem(VFSPath path);
|
||||||
void CreateHardlink(VFSPath existingFile, VFSPath newName);
|
VFSPath SystemToVFSPath(std::string path);
|
||||||
|
|
||||||
void MoveFile(VFSPath src, VFSPath dest);
|
void SetDate(VFSPath path, Date::DateTime lastWrite,
|
||||||
|
Date::DateTime lastAccess);
|
||||||
|
bool Stat(VFSPath path, StatData &stat);
|
||||||
|
bool StatVFS(VFSPath path, StatVFSData &vfsData);
|
||||||
|
|
||||||
void MoveDirectory(VFSPath src, VFSPath dest);
|
void Chmod(VFSPath path, uint32_t mode);
|
||||||
VFSPath ReadLink(VFSPath path);
|
void Chown(VFSPath path, uint32_t uid, uint32_t gid);
|
||||||
std::string VFSPathToSystem(VFSPath path);
|
|
||||||
VFSPath SystemToVFSPath(std::string path);
|
|
||||||
|
|
||||||
void SetDate(VFSPath path, Date::DateTime lastWrite, Date::DateTime lastAccess);
|
void Lock(VFSPath path);
|
||||||
bool Stat(VFSPath path, StatData& stat);
|
void Unlock(VFSPath path);
|
||||||
bool StatVFS(VFSPath path, StatVFSData& vfsData);
|
|
||||||
|
|
||||||
void Chmod(VFSPath path, uint32_t mode);
|
FIFOCreationResult CreateFIFO(VFSPath path, uint32_t mod);
|
||||||
void Chown(VFSPath path, uint32_t uid, uint32_t gid);
|
|
||||||
|
|
||||||
void Lock(VFSPath path);
|
protected:
|
||||||
void Unlock(VFSPath path);
|
std::shared_ptr<FSWatcher> CreateWatcher(std::shared_ptr<VFS> vfs,
|
||||||
|
VFSPath path);
|
||||||
FIFOCreationResult CreateFIFO(VFSPath path, uint32_t mod);
|
};
|
||||||
|
extern std::shared_ptr<LocalFilesystem> LocalFS;
|
||||||
protected:
|
} // namespace Tesses::Framework::Filesystem
|
||||||
std::shared_ptr<FSWatcher> CreateWatcher(std::shared_ptr<VFS> vfs, VFSPath path);
|
|
||||||
|
|
||||||
};
|
|
||||||
extern std::shared_ptr<LocalFilesystem> LocalFS;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,59 +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
|
#pragma once
|
||||||
#include "VFS.hpp"
|
#include "VFS.hpp"
|
||||||
#include "VFSFix.hpp"
|
#include "VFSFix.hpp"
|
||||||
|
|
||||||
namespace Tesses::Framework::Filesystem
|
namespace Tesses::Framework::Filesystem {
|
||||||
{
|
class MountableDirectory {
|
||||||
class MountableDirectory {
|
public:
|
||||||
public:
|
std::string name;
|
||||||
std::string name;
|
std::shared_ptr<VFS> vfs;
|
||||||
std::shared_ptr<VFS> vfs;
|
bool owns;
|
||||||
bool owns;
|
std::vector<MountableDirectory *> dirs;
|
||||||
std::vector<MountableDirectory*> dirs;
|
void GetFS(VFSPath srcPath, VFSPath curDir, VFSPath &destRoot,
|
||||||
void GetFS(VFSPath srcPath, VFSPath curDir, VFSPath& destRoot, VFSPath& destPath, std::shared_ptr<VFS>& vfs);
|
VFSPath &destPath, std::shared_ptr<VFS> &vfs);
|
||||||
~MountableDirectory();
|
~MountableDirectory();
|
||||||
};
|
};
|
||||||
|
|
||||||
class MountableFilesystem : public VFS
|
class MountableFilesystem : public VFS {
|
||||||
{
|
std::shared_ptr<VFS> root;
|
||||||
std::shared_ptr<VFS> root;
|
|
||||||
|
|
||||||
std::vector<MountableDirectory*> directories;
|
std::vector<MountableDirectory *> directories;
|
||||||
|
|
||||||
void GetFS(VFSPath srcPath, VFSPath& destRoot, VFSPath& destPath, std::shared_ptr<VFS>& vfs);
|
void GetFS(VFSPath srcPath, VFSPath &destRoot, VFSPath &destPath,
|
||||||
|
std::shared_ptr<VFS> &vfs);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
public:
|
bool StatVFS(VFSPath path, StatVFSData &vfsData);
|
||||||
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);
|
|
||||||
|
|
||||||
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 Chmod(VFSPath path, uint32_t mode);
|
void Lock(VFSPath path);
|
||||||
void Chown(VFSPath path, uint32_t uid, uint32_t gid);
|
void Unlock(VFSPath path);
|
||||||
FIFOCreationResult CreateFIFO(VFSPath path, uint32_t mode);
|
};
|
||||||
|
} // namespace Tesses::Framework::Filesystem
|
||||||
|
|
||||||
void Lock(VFSPath path);
|
|
||||||
void Unlock(VFSPath path);
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,16 +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
|
#pragma once
|
||||||
#include "VFS.hpp"
|
#include "VFS.hpp"
|
||||||
#include "VFSFix.hpp"
|
#include "VFSFix.hpp"
|
||||||
|
|
||||||
namespace Tesses::Framework::Filesystem
|
namespace Tesses::Framework::Filesystem {
|
||||||
{
|
class NullFilesystem : public VFS {
|
||||||
class NullFilesystem : public VFS
|
public:
|
||||||
{
|
std::shared_ptr<Tesses::Framework::Streams::Stream>
|
||||||
public:
|
OpenFile(VFSPath path, std::string mode);
|
||||||
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenFile(VFSPath path, std::string mode);
|
VFSPathEnumerator EnumeratePaths(VFSPath path);
|
||||||
VFSPathEnumerator EnumeratePaths(VFSPath path);
|
bool Stat(VFSPath path, StatData &data);
|
||||||
bool Stat(VFSPath path, StatData& data);
|
std::string VFSPathToSystem(VFSPath path);
|
||||||
std::string VFSPathToSystem(VFSPath path);
|
VFSPath SystemToVFSPath(std::string path);
|
||||||
VFSPath SystemToVFSPath(std::string path);
|
};
|
||||||
};
|
} // namespace Tesses::Framework::Filesystem
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,54 +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
|
#pragma once
|
||||||
#include "VFS.hpp"
|
#include "VFS.hpp"
|
||||||
#include "VFSFix.hpp"
|
#include "VFSFix.hpp"
|
||||||
|
|
||||||
namespace Tesses::Framework::Filesystem
|
namespace Tesses::Framework::Filesystem {
|
||||||
{
|
class RelativeFilesystem : public VFS {
|
||||||
class RelativeFilesystem : public VFS {
|
Tesses::Framework::Threading::Mutex mtx;
|
||||||
Tesses::Framework::Threading::Mutex mtx;
|
VFSPath working;
|
||||||
VFSPath working;
|
std::shared_ptr<VFS> vfs;
|
||||||
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);
|
private:
|
||||||
void CreateDirectory(VFSPath path);
|
VFSPath ToParent(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);
|
public:
|
||||||
void Chmod(VFSPath path, uint32_t mode);
|
RelativeFilesystem(std::shared_ptr<VFS> vfs, VFSPath working);
|
||||||
FIFOCreationResult CreateFIFO(VFSPath path, uint32_t mode);
|
VFSPath GetWorking();
|
||||||
void Lock(VFSPath path);
|
void SetWorking(VFSPath path);
|
||||||
void Unlock(VFSPath path);
|
std::shared_ptr<VFS> GetVFS();
|
||||||
protected:
|
|
||||||
std::shared_ptr<FSWatcher> CreateWatcher(std::shared_ptr<VFS> vfs, 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);
|
||||||
|
void SetDate(VFSPath path, Date::DateTime lastWrite,
|
||||||
|
Date::DateTime lastAccess);
|
||||||
|
bool StatVFS(VFSPath path, StatVFSData &vfsData);
|
||||||
|
bool Stat(VFSPath path, StatData &data);
|
||||||
|
|
||||||
class Watcher : public FSWatcher {
|
void Chown(VFSPath path, uint32_t uid, uint32_t gid);
|
||||||
std::shared_ptr<FSWatcher> watcher;
|
void Chmod(VFSPath path, uint32_t mode);
|
||||||
protected:
|
FIFOCreationResult CreateFIFO(VFSPath path, uint32_t mode);
|
||||||
void SetEnabledImpl(bool enabled);
|
void Lock(VFSPath path);
|
||||||
public:
|
void Unlock(VFSPath path);
|
||||||
Watcher(std::shared_ptr<RelativeFilesystem> vfs, VFSPath path);
|
|
||||||
~Watcher();
|
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,53 +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
|
#pragma once
|
||||||
#include "VFS.hpp"
|
#include "VFS.hpp"
|
||||||
#include "VFSFix.hpp"
|
#include "VFSFix.hpp"
|
||||||
|
|
||||||
namespace Tesses::Framework::Filesystem
|
namespace Tesses::Framework::Filesystem {
|
||||||
{
|
class SubdirFilesystem : public VFS {
|
||||||
class SubdirFilesystem : public VFS
|
std::shared_ptr<VFS> parent;
|
||||||
{
|
VFSPath path;
|
||||||
std::shared_ptr<VFS> parent;
|
VFSPath ToParent(VFSPath path);
|
||||||
VFSPath path;
|
VFSPath FromParent(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);
|
|
||||||
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);
|
public:
|
||||||
void Chmod(VFSPath path, uint32_t mode);
|
SubdirFilesystem(std::shared_ptr<VFS> parent, VFSPath path);
|
||||||
FIFOCreationResult CreateFIFO(VFSPath path, uint32_t mode);
|
std::shared_ptr<Tesses::Framework::Streams::Stream>
|
||||||
void Lock(VFSPath path);
|
OpenFile(VFSPath path, std::string mode);
|
||||||
void Unlock(VFSPath path);
|
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:
|
protected:
|
||||||
std::shared_ptr<FSWatcher> CreateWatcher(std::shared_ptr<VFS> vfs, VFSPath path);
|
std::shared_ptr<FSWatcher> CreateWatcher(std::shared_ptr<VFS> vfs,
|
||||||
|
VFSPath path);
|
||||||
|
|
||||||
|
class Watcher : public FSWatcher {
|
||||||
|
std::shared_ptr<FSWatcher> watcher;
|
||||||
|
|
||||||
class Watcher : public FSWatcher {
|
protected:
|
||||||
std::shared_ptr<FSWatcher> watcher;
|
void SetEnabledImpl(bool enabled);
|
||||||
protected:
|
|
||||||
void SetEnabledImpl(bool enabled);
|
public:
|
||||||
public:
|
Watcher(std::shared_ptr<SubdirFilesystem> vfs, VFSPath path);
|
||||||
Watcher(std::shared_ptr<SubdirFilesystem> vfs, VFSPath path);
|
~Watcher();
|
||||||
~Watcher();
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
|
} // namespace Tesses::Framework::Filesystem
|
||||||
|
|||||||
@@ -1,52 +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
|
#pragma once
|
||||||
#include "../Common.hpp"
|
#include "../Common.hpp"
|
||||||
#include "VFS.hpp"
|
#include "VFS.hpp"
|
||||||
#include "VFSFix.hpp"
|
#include "VFSFix.hpp"
|
||||||
namespace Tesses::Framework::Filesystem
|
namespace Tesses::Framework::Filesystem {
|
||||||
{
|
void UniqueString(std::string &text);
|
||||||
void UniqueString(std::string& text);
|
|
||||||
|
|
||||||
class TempFS : public VFS
|
class TempFS : public VFS {
|
||||||
{
|
std::shared_ptr<VFS> vfs;
|
||||||
std::shared_ptr<VFS> vfs;
|
bool deleteOnDestroy;
|
||||||
bool deleteOnDestroy;
|
std::shared_ptr<VFS> parent;
|
||||||
std::shared_ptr<VFS> parent;
|
std::string tmp_str;
|
||||||
std::string tmp_str;
|
|
||||||
public:
|
|
||||||
std::string TempDirectoryName();
|
|
||||||
TempFS(bool deleteOnDestroy=true);
|
|
||||||
TempFS(std::shared_ptr<VFS> vfs,bool deleteOnDestroy=true);
|
|
||||||
|
|
||||||
std::shared_ptr<Tesses::Framework::Streams::Stream> OpenFile(VFSPath path, std::string mode);
|
public:
|
||||||
void CreateDirectory(VFSPath path);
|
std::string TempDirectoryName();
|
||||||
void DeleteDirectory(VFSPath path);
|
TempFS(bool deleteOnDestroy = true);
|
||||||
void DeleteFile(VFSPath path);
|
TempFS(std::shared_ptr<VFS> vfs, bool deleteOnDestroy = true);
|
||||||
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);
|
std::shared_ptr<Tesses::Framework::Streams::Stream>
|
||||||
bool StatVFS(VFSPath path, StatVFSData& vfsData);
|
OpenFile(VFSPath path, std::string mode);
|
||||||
bool Stat(VFSPath path, StatData& data);
|
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 Chmod(VFSPath path, uint32_t mode);
|
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 Close();
|
|
||||||
|
|
||||||
void Lock(VFSPath path);
|
void Chown(VFSPath path, uint32_t uid, uint32_t gid);
|
||||||
void Unlock(VFSPath path);
|
FIFOCreationResult CreateFIFO(VFSPath path, uint32_t mode);
|
||||||
~TempFS();
|
void Close();
|
||||||
|
|
||||||
protected:
|
void Lock(VFSPath path);
|
||||||
std::shared_ptr<FSWatcher> CreateWatcher(std::shared_ptr<VFS> vfs, 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,343 +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
|
#pragma once
|
||||||
#include "../Common.hpp"
|
#include "../Common.hpp"
|
||||||
|
#include "../Date/Date.hpp"
|
||||||
#include "../Streams/Stream.hpp"
|
#include "../Streams/Stream.hpp"
|
||||||
|
#include "VFSFix.hpp"
|
||||||
#include <TessesFramework/Common.hpp>
|
#include <TessesFramework/Common.hpp>
|
||||||
#include <TessesFramework/Date/Date.hpp>
|
#include <TessesFramework/Date/Date.hpp>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "../Date/Date.hpp"
|
|
||||||
#include "VFSFix.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::Filesystem
|
namespace Tesses::Framework::Filesystem {
|
||||||
{
|
|
||||||
|
|
||||||
struct StatVFSData {
|
struct StatVFSData {
|
||||||
|
|
||||||
uint64_t BlockSize;
|
uint64_t BlockSize;
|
||||||
uint64_t FragmentSize;
|
uint64_t FragmentSize;
|
||||||
uint64_t Blocks;
|
uint64_t Blocks;
|
||||||
uint64_t BlocksFree;
|
uint64_t BlocksFree;
|
||||||
uint64_t BlocksAvailable;
|
uint64_t BlocksAvailable;
|
||||||
uint64_t TotalInodes;
|
uint64_t TotalInodes;
|
||||||
uint64_t FreeInodes;
|
uint64_t FreeInodes;
|
||||||
uint64_t AvailableInodes;
|
uint64_t AvailableInodes;
|
||||||
uint64_t Id;
|
uint64_t Id;
|
||||||
uint64_t Flags;
|
uint64_t Flags;
|
||||||
uint64_t MaxNameLength;
|
uint64_t MaxNameLength;
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr uint32_t MODE_USER_READ = 0400;
|
constexpr uint32_t MODE_USER_READ = 0400;
|
||||||
constexpr uint32_t MODE_USER_WRITE = 0200;
|
constexpr uint32_t MODE_USER_WRITE = 0200;
|
||||||
constexpr uint32_t MODE_USER_EXEC = 0100;
|
constexpr uint32_t MODE_USER_EXEC = 0100;
|
||||||
|
|
||||||
constexpr uint32_t MODE_GROUP_READ = (MODE_USER_READ >> 3);
|
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_WRITE = (MODE_USER_WRITE >> 3);
|
||||||
constexpr uint32_t MODE_GROUP_EXEC = (MODE_USER_EXEC >> 3);
|
constexpr uint32_t MODE_GROUP_EXEC = (MODE_USER_EXEC >> 3);
|
||||||
|
|
||||||
constexpr uint32_t MODE_OTHER_READ = (MODE_GROUP_READ >> 3);
|
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_WRITE = (MODE_GROUP_WRITE >> 3);
|
||||||
constexpr uint32_t MODE_OTHER_EXEC = (MODE_GROUP_EXEC >> 3);
|
constexpr uint32_t MODE_OTHER_EXEC = (MODE_GROUP_EXEC >> 3);
|
||||||
|
|
||||||
constexpr uint32_t MODE_REGULAR = 0100000;
|
constexpr uint32_t MODE_REGULAR = 0100000;
|
||||||
constexpr uint32_t MODE_DIRECTORY = 0040000;
|
constexpr uint32_t MODE_DIRECTORY = 0040000;
|
||||||
constexpr uint32_t MODE_CHAR_DEVICE = 0020000;
|
constexpr uint32_t MODE_CHAR_DEVICE = 0020000;
|
||||||
constexpr uint32_t MODE_BLOCK_DEVICE = 0060000;
|
constexpr uint32_t MODE_BLOCK_DEVICE = 0060000;
|
||||||
constexpr uint32_t MODE_SOCKET = 0140000;
|
constexpr uint32_t MODE_SOCKET = 0140000;
|
||||||
constexpr uint32_t MODE_FIFO = 0010000;
|
constexpr uint32_t MODE_FIFO = 0010000;
|
||||||
constexpr uint32_t MODE_SYMLINK = 0120000;
|
constexpr uint32_t MODE_SYMLINK = 0120000;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
struct StatData {
|
bool IsRegularFile() { return (Mode & MODE_REGULAR) > 0; }
|
||||||
uint64_t Device;
|
bool IsDirectory() { return (Mode & MODE_DIRECTORY) > 0; }
|
||||||
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;
|
|
||||||
|
|
||||||
bool IsRegularFile()
|
bool IsCharDevice() { return (Mode & MODE_CHAR_DEVICE) > 0; }
|
||||||
{
|
|
||||||
return (Mode & MODE_REGULAR) > 0;
|
|
||||||
}
|
|
||||||
bool IsDirectory()
|
|
||||||
{
|
|
||||||
return (Mode & MODE_DIRECTORY) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsCharDevice()
|
bool IsBlockDevice() { return (Mode & MODE_BLOCK_DEVICE) > 0; }
|
||||||
{
|
|
||||||
return (Mode & MODE_CHAR_DEVICE) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsBlockDevice()
|
bool IsSocket() { return (Mode & MODE_SOCKET) > 0; }
|
||||||
{
|
bool IsFIFO() { return (Mode & MODE_FIFO) > 0; }
|
||||||
return (Mode & MODE_BLOCK_DEVICE) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsSocket()
|
bool IsSymlink() { return (Mode & MODE_SYMLINK) > 0; }
|
||||||
{
|
|
||||||
return (Mode & MODE_SOCKET) > 0;
|
|
||||||
}
|
|
||||||
bool IsFIFO()
|
|
||||||
{
|
|
||||||
return (Mode & MODE_FIFO) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsSymlink()
|
bool IsSpecial() {
|
||||||
{
|
if (IsRegularFile())
|
||||||
return (Mode & MODE_SYMLINK) > 0;
|
return false;
|
||||||
}
|
if (IsDirectory())
|
||||||
|
return false;
|
||||||
bool IsSpecial()
|
return true;
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
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 CreateDirectory
|
||||||
#undef DeleteDirectory
|
#undef DeleteDirectory
|
||||||
#undef DeleteFile
|
#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
|
#pragma once
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
namespace Tesses::Framework {
|
namespace Tesses::Framework {
|
||||||
class HiddenFieldData {
|
class HiddenFieldData {
|
||||||
public:
|
public:
|
||||||
virtual ~HiddenFieldData();
|
virtual ~HiddenFieldData();
|
||||||
};
|
};
|
||||||
|
|
||||||
class HiddenField {
|
class HiddenField {
|
||||||
private:
|
private:
|
||||||
HiddenFieldData* ptr;
|
HiddenFieldData *ptr;
|
||||||
public:
|
|
||||||
HiddenField();
|
public:
|
||||||
HiddenField(HiddenFieldData* data);
|
HiddenField();
|
||||||
void SetField(HiddenFieldData* data);
|
HiddenField(HiddenFieldData *data);
|
||||||
template<typename T>
|
void SetField(HiddenFieldData *data);
|
||||||
T GetField()
|
template <typename T> T GetField() { return dynamic_cast<T>(ptr); }
|
||||||
{
|
template <typename T> T *AllocField() {
|
||||||
return dynamic_cast<T>(ptr);
|
auto v = new T();
|
||||||
}
|
SetField(v);
|
||||||
template<typename T>
|
return v;
|
||||||
T* AllocField()
|
}
|
||||||
{
|
~HiddenField();
|
||||||
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
|
#pragma once
|
||||||
#include "HttpServer.hpp"
|
#include "HttpServer.hpp"
|
||||||
namespace Tesses::Framework::Http {
|
namespace Tesses::Framework::Http {
|
||||||
class BasicAuthServer : public Tesses::Framework::Http::IHttpServer
|
class BasicAuthServer : public Tesses::Framework::Http::IHttpServer {
|
||||||
{
|
public:
|
||||||
public:
|
std::shared_ptr<IHttpServer> server;
|
||||||
std::shared_ptr<IHttpServer> server;
|
std::function<bool(std::string username, std::string password)>
|
||||||
std::function<bool(std::string username, std::string password)> authorization;
|
authorization;
|
||||||
std::string realm;
|
std::string realm;
|
||||||
|
|
||||||
BasicAuthServer();
|
BasicAuthServer();
|
||||||
BasicAuthServer(std::shared_ptr<IHttpServer> server, std::function<bool(std::string username, std::string password)> auth,std::string realm="Protected Content");
|
BasicAuthServer(
|
||||||
bool Handle(ServerContext& ctx);
|
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,
|
||||||
static bool GetCreds(ServerContext& ctx, std::string& user, std::string& pass);
|
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
|
#pragma once
|
||||||
#include "../Filesystem/VFS.hpp"
|
#include "../Filesystem/VFS.hpp"
|
||||||
#include "../Filesystem/VFSFix.hpp"
|
#include "../Filesystem/VFSFix.hpp"
|
||||||
#include "HttpServer.hpp"
|
#include "HttpServer.hpp"
|
||||||
#include <optional>
|
#include <optional>
|
||||||
namespace Tesses::Framework::Http {
|
namespace Tesses::Framework::Http {
|
||||||
struct CGIParams {
|
struct CGIParams {
|
||||||
std::optional<Tesses::Framework::Filesystem::VFSPath> document_root;
|
std::optional<Tesses::Framework::Filesystem::VFSPath> document_root;
|
||||||
Tesses::Framework::Filesystem::VFSPath program;
|
Tesses::Framework::Filesystem::VFSPath program;
|
||||||
std::optional<std::string> adminEmail;
|
std::optional<std::string> adminEmail;
|
||||||
std::optional<Tesses::Framework::Filesystem::VFSPath> workingDirectory;
|
std::optional<Tesses::Framework::Filesystem::VFSPath> workingDirectory;
|
||||||
};
|
};
|
||||||
class CGIServer : public Tesses::Framework::Http::IHttpServer {
|
class CGIServer : public Tesses::Framework::Http::IHttpServer {
|
||||||
Tesses::Framework::Filesystem::VFSPath dir;
|
Tesses::Framework::Filesystem::VFSPath dir;
|
||||||
public:
|
|
||||||
std::optional<Tesses::Framework::Filesystem::VFSPath> document_root;
|
public:
|
||||||
std::optional<std::string> adminEmail;
|
std::optional<Tesses::Framework::Filesystem::VFSPath> document_root;
|
||||||
std::optional<Tesses::Framework::Filesystem::VFSPath> workingDirectory;
|
std::optional<std::string> adminEmail;
|
||||||
CGIServer(Tesses::Framework::Filesystem::VFSPath dir);
|
std::optional<Tesses::Framework::Filesystem::VFSPath> workingDirectory;
|
||||||
bool Handle(ServerContext& ctx);
|
CGIServer(Tesses::Framework::Filesystem::VFSPath dir);
|
||||||
static bool ServeCGIRequest(ServerContext& ctx, CGIParams& params);
|
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
|
#pragma once
|
||||||
#include "HttpServer.hpp"
|
#include "HttpServer.hpp"
|
||||||
|
|
||||||
namespace Tesses::Framework::Http
|
namespace Tesses::Framework::Http {
|
||||||
{
|
class CallbackServer : public IHttpServer {
|
||||||
class CallbackServer : public IHttpServer
|
std::function<bool(ServerContext &)> cb;
|
||||||
{
|
std::function<void()> destroy;
|
||||||
std::function<bool(ServerContext&)> cb;
|
|
||||||
std::function<void()> destroy;
|
public:
|
||||||
public:
|
CallbackServer(std::function<bool(ServerContext &)> cb);
|
||||||
CallbackServer(std::function<bool(ServerContext&)> cb);
|
CallbackServer(std::function<bool(ServerContext &)> cb,
|
||||||
CallbackServer(std::function<bool(ServerContext&)> cb,std::function<void()> destroy);
|
std::function<void()> destroy);
|
||||||
bool Handle(ServerContext& ctx);
|
bool Handle(ServerContext &ctx);
|
||||||
~CallbackServer();
|
~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
|
#pragma once
|
||||||
#include "HttpServer.hpp"
|
#include "HttpServer.hpp"
|
||||||
|
|
||||||
namespace Tesses::Framework::Http
|
namespace Tesses::Framework::Http {
|
||||||
{
|
class ChangeableServer {
|
||||||
class ChangeableServer {
|
public:
|
||||||
public:
|
ChangeableServer();
|
||||||
ChangeableServer();
|
ChangeableServer(std::shared_ptr<IHttpServer> original);
|
||||||
ChangeableServer(std::shared_ptr<IHttpServer> original);
|
std::shared_ptr<IHttpServer> server;
|
||||||
std::shared_ptr<IHttpServer> server;
|
bool Handle(ServerContext &ctx);
|
||||||
bool Handle(ServerContext& ctx);
|
~ChangeableServer();
|
||||||
~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
|
#pragma once
|
||||||
#include "../Common.hpp"
|
#include "../Common.hpp"
|
||||||
namespace Tesses::Framework::Http
|
namespace Tesses::Framework::Http {
|
||||||
{
|
class ContentDisposition {
|
||||||
class ContentDisposition {
|
public:
|
||||||
public:
|
std::string filename;
|
||||||
std::string filename;
|
std::string type;
|
||||||
std::string type;
|
std::string fieldName;
|
||||||
std::string fieldName;
|
static bool TryParse(std::string str, ContentDisposition &cd);
|
||||||
static bool TryParse(std::string str, ContentDisposition& cd);
|
std::string ToString();
|
||||||
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
|
#pragma once
|
||||||
#include "../Filesystem/VFS.hpp"
|
#include "../Filesystem/VFS.hpp"
|
||||||
#include "HttpServer.hpp"
|
#include "HttpServer.hpp"
|
||||||
|
|
||||||
namespace Tesses::Framework::Http
|
namespace Tesses::Framework::Http {
|
||||||
{
|
class FileServer : public IHttpServer {
|
||||||
class FileServer : public IHttpServer
|
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs;
|
||||||
{
|
|
||||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool SendFile(ServerContext& ctx,Tesses::Framework::Filesystem::VFSPath path);
|
bool SendFile(ServerContext &ctx,
|
||||||
public:
|
Tesses::Framework::Filesystem::VFSPath path);
|
||||||
bool allowListing;
|
|
||||||
bool spa;
|
public:
|
||||||
std::vector<std::string> defaultNames;
|
bool allowListing;
|
||||||
FileServer(std::filesystem::path path,bool allowListing,bool spa);
|
bool spa;
|
||||||
FileServer(std::filesystem::path path,bool allowListing, bool spa, std::vector<std::string> defaultNames);
|
std::vector<std::string> defaultNames;
|
||||||
FileServer(std::shared_ptr<Tesses::Framework::Filesystem::VFS> fs, bool allowListing, bool spa);
|
FileServer(std::filesystem::path path, bool allowListing, bool spa);
|
||||||
FileServer(std::shared_ptr<Tesses::Framework::Filesystem::VFS> fs, bool allowListing, bool spa, std::vector<std::string> defaultNames);
|
FileServer(std::filesystem::path path, bool allowListing, bool spa,
|
||||||
bool Handle(ServerContext& ctx);
|
std::vector<std::string> defaultNames);
|
||||||
~FileServer();
|
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,139 @@
|
|||||||
|
/*
|
||||||
|
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
|
#pragma once
|
||||||
#include "../Streams/Stream.hpp"
|
#include "../Streams/Stream.hpp"
|
||||||
#include "HttpUtils.hpp"
|
#include "HttpUtils.hpp"
|
||||||
#include "WebSocket.hpp"
|
|
||||||
#include "TessesFramework/Filesystem/LocalFS.hpp"
|
#include "TessesFramework/Filesystem/LocalFS.hpp"
|
||||||
#include "TessesFramework/Filesystem/VFSFix.hpp"
|
#include "TessesFramework/Filesystem/VFSFix.hpp"
|
||||||
namespace Tesses::Framework::Http
|
#include "WebSocket.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();
|
|
||||||
};
|
|
||||||
|
|
||||||
class StreamHttpRequestBody : public HttpRequestBody {
|
class HttpRequestBody {
|
||||||
std::shared_ptr<Tesses::Framework::Streams::Stream> strm;
|
public:
|
||||||
|
virtual void HandleHeaders(HttpDictionary &dict);
|
||||||
std::string mimeType;
|
virtual void
|
||||||
public:
|
Write(std::shared_ptr<Tesses::Framework::Streams::Stream> strm) = 0;
|
||||||
StreamHttpRequestBody(std::shared_ptr<Tesses::Framework::Streams::Stream> strm, std::string mimeType);
|
virtual ~HttpRequestBody();
|
||||||
void HandleHeaders(HttpDictionary& dict);
|
};
|
||||||
void Write(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
|
||||||
~StreamHttpRequestBody();
|
|
||||||
};
|
|
||||||
|
|
||||||
class TextHttpRequestBody : public HttpRequestBody {
|
class StreamHttpRequestBody : public HttpRequestBody {
|
||||||
std::string text;
|
std::shared_ptr<Tesses::Framework::Streams::Stream> strm;
|
||||||
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();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
std::string mimeType;
|
||||||
|
|
||||||
class HttpRequest {
|
public:
|
||||||
public:
|
StreamHttpRequestBody(
|
||||||
HttpRequest();
|
std::shared_ptr<Tesses::Framework::Streams::Stream> strm,
|
||||||
std::string trusted_root_cert_bundle;
|
std::string mimeType);
|
||||||
bool ignoreSSLErrors;
|
void HandleHeaders(HttpDictionary &dict);
|
||||||
bool followRedirects;
|
void Write(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||||
|
~StreamHttpRequestBody();
|
||||||
|
};
|
||||||
|
|
||||||
std::string method;
|
class TextHttpRequestBody : public HttpRequestBody {
|
||||||
std::string url;
|
std::string text;
|
||||||
std::string unixSocket;
|
std::string mimeType;
|
||||||
HttpDictionary requestHeaders;
|
|
||||||
HttpRequestBody* body;
|
|
||||||
|
|
||||||
static std::shared_ptr<Tesses::Framework::Streams::Stream> EstablishConnection(Uri uri,bool ignoreSSLErrors,std::string trusted_root_cert_bundle);
|
public:
|
||||||
static std::shared_ptr<Tesses::Framework::Streams::Stream> EstablishUnixPathConnection(std::string unixPath, Uri uri, bool ignoreSSLErrors, std::string trusted_root_cert_bundle);
|
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 {
|
std::string method;
|
||||||
private:
|
std::string url;
|
||||||
bool owns;
|
std::string unixSocket;
|
||||||
std::shared_ptr<Tesses::Framework::Streams::Stream> handleStrm;
|
HttpDictionary requestHeaders;
|
||||||
public:
|
HttpRequestBody *body;
|
||||||
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);
|
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);
|
class HttpResponse {
|
||||||
std::string DownloadToStringSimple(std::string url);
|
private:
|
||||||
|
bool owns;
|
||||||
bool WebSocketClientSuccessDefault(HttpDictionary& dict,bool v);
|
std::shared_ptr<Tesses::Framework::Streams::Stream> handleStrm;
|
||||||
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);
|
public:
|
||||||
|
HttpResponse(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||||
void DownloadUnixSocketToFileSimple(std::string unixSocket,std::string url, Tesses::Framework::Filesystem::VFSPath path);
|
HttpResponse(HttpRequest &request);
|
||||||
std::string DownloadUnixSocketToStringSimple(std::string unixSocket,std::string url);
|
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,138 +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
|
#pragma once
|
||||||
#include "../Streams/NetworkStream.hpp"
|
#include "../Streams/NetworkStream.hpp"
|
||||||
|
|
||||||
#include "HttpUtils.hpp"
|
|
||||||
#include "../Threading/Thread.hpp"
|
|
||||||
#include "../Date/Date.hpp"
|
#include "../Date/Date.hpp"
|
||||||
#include <unordered_map>
|
#include "../Threading/Thread.hpp"
|
||||||
|
#include "HttpUtils.hpp"
|
||||||
#include "WebSocket.hpp"
|
#include "WebSocket.hpp"
|
||||||
#include <queue>
|
#include <queue>
|
||||||
namespace Tesses::Framework::Http
|
#include <unordered_map>
|
||||||
{
|
namespace Tesses::Framework::Http {
|
||||||
class ServerContextData {
|
class ServerContextData {
|
||||||
public:
|
public:
|
||||||
virtual ~ServerContextData();
|
virtual ~ServerContextData();
|
||||||
};
|
};
|
||||||
class ServerContext;
|
class ServerContext;
|
||||||
class ServerSentEvents {
|
class ServerSentEvents {
|
||||||
std::vector<std::shared_ptr<Tesses::Framework::Streams::Stream>> strms;
|
std::vector<std::shared_ptr<Tesses::Framework::Streams::Stream>> strms;
|
||||||
Tesses::Framework::Threading::Mutex mtx;
|
Tesses::Framework::Threading::Mutex mtx;
|
||||||
private:
|
|
||||||
void SendEventRaw(const std::string& evt);
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
void SendEventRaw(const std::string &evt);
|
||||||
|
|
||||||
class ServerContext {
|
public:
|
||||||
|
void SendRetry(uint32_t ms);
|
||||||
bool sent;
|
void SendRetry(std::chrono::milliseconds ms);
|
||||||
bool debug;
|
void SendRetry(Tesses::Framework::Date::TimeSpan ts);
|
||||||
std::vector<std::shared_ptr<ServerSentEvents>> sse;
|
void SendData(const std::string &message);
|
||||||
std::shared_ptr<Tesses::Framework::Streams::Stream> strm;
|
void SendData(const std::string &message, const std::string &dataType);
|
||||||
std::map<std::string,ServerContextData*> data;
|
void SendId(const std::string &idVal);
|
||||||
std::queue<std::function<bool(ServerContext& ctx)>> headerhandlers;
|
void SendCustomEvent(const std::string &type, const std::string &value);
|
||||||
public:
|
void SendComment(const std::string &comment);
|
||||||
HttpDictionary requestHeaders;
|
friend class ServerContext;
|
||||||
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);
|
|
||||||
|
|
||||||
|
class ServerContext {
|
||||||
|
|
||||||
template<class T>
|
bool sent;
|
||||||
T* GetServerContentData(std::string tag)
|
bool debug;
|
||||||
{
|
std::vector<std::shared_ptr<ServerSentEvents>> sse;
|
||||||
std::string name = typeid(T).name();
|
std::shared_ptr<Tesses::Framework::Streams::Stream> strm;
|
||||||
name.push_back(' ');
|
std::map<std::string, ServerContextData *> data;
|
||||||
name.append(tag);
|
std::queue<std::function<bool(ServerContext &ctx)>> headerhandlers;
|
||||||
if(data.count(name) > 0) return dynamic_cast<T*>(data[name]);
|
|
||||||
T* item = new T();
|
|
||||||
data[name] = item;
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
friend class ServerSentEvents;
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
class IHttpServer {
|
template <class T> T *GetServerContentData(std::string tag) {
|
||||||
public:
|
std::string name = typeid(T).name();
|
||||||
virtual bool Handle(ServerContext& ctx)=0;
|
name.push_back(' ');
|
||||||
virtual ~IHttpServer();
|
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 HttpServer {
|
class IHttpServer {
|
||||||
std::shared_ptr<Tesses::Framework::Streams::TcpServer> server;
|
public:
|
||||||
std::shared_ptr<IHttpServer> http;
|
virtual bool Handle(ServerContext &ctx) = 0;
|
||||||
Tesses::Framework::Threading::Thread* thrd;
|
virtual ~IHttpServer();
|
||||||
|
};
|
||||||
|
|
||||||
bool showIPs;
|
class HttpServer {
|
||||||
bool showARTL;
|
std::shared_ptr<Tesses::Framework::Streams::TcpServer> server;
|
||||||
bool debug;
|
std::shared_ptr<IHttpServer> http;
|
||||||
|
Tesses::Framework::Threading::Thread *thrd;
|
||||||
|
|
||||||
public:
|
bool showIPs;
|
||||||
HttpServer(std::shared_ptr<Tesses::Framework::Streams::TcpServer> tcpServer, std::shared_ptr<IHttpServer> http, bool showIPs=true, bool debug=false);
|
bool showARTL;
|
||||||
HttpServer(uint16_t port, std::shared_ptr<IHttpServer> http, bool showIPs=true, bool debug=false);
|
bool debug;
|
||||||
HttpServer(std::string unixPath, std::shared_ptr<IHttpServer> http, bool debug=false);
|
|
||||||
uint16_t GetPort();
|
public:
|
||||||
void StartAccepting();
|
HttpServer(std::shared_ptr<Tesses::Framework::Streams::TcpServer> tcpServer,
|
||||||
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);
|
std::shared_ptr<IHttpServer> http, bool showIPs = true,
|
||||||
~HttpServer();
|
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
|
#pragma once
|
||||||
#include "../Streams/Stream.hpp"
|
#include "../Streams/Stream.hpp"
|
||||||
|
|
||||||
namespace Tesses::Framework::Http
|
namespace Tesses::Framework::Http {
|
||||||
{
|
class HttpStream : public Tesses::Framework::Streams::Stream {
|
||||||
class HttpStream : public Tesses::Framework::Streams::Stream {
|
std::shared_ptr<Tesses::Framework::Streams::Stream> strm;
|
||||||
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;
|
|
||||||
|
|
||||||
public:
|
size_t offset;
|
||||||
HttpStream(std::shared_ptr<Tesses::Framework::Streams::Stream> strm, int64_t length, bool recv, bool http1_1);
|
size_t read;
|
||||||
bool CanRead();
|
int64_t length;
|
||||||
bool CanWrite();
|
int64_t position;
|
||||||
bool EndOfStream();
|
|
||||||
int64_t GetLength();
|
bool recv;
|
||||||
int64_t GetPosition();
|
bool http1_1;
|
||||||
size_t Read(uint8_t* buffer, size_t len);
|
|
||||||
size_t Write(const uint8_t* buffer, size_t len);
|
bool done;
|
||||||
void Close();
|
|
||||||
~HttpStream();
|
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,181 +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
|
#pragma once
|
||||||
#include "../Common.hpp"
|
#include "../Common.hpp"
|
||||||
#include "../Date/Date.hpp"
|
#include "../Date/Date.hpp"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
namespace Tesses::Framework::Http
|
namespace Tesses::Framework::Http {
|
||||||
{
|
typedef enum StatusCode {
|
||||||
typedef enum StatusCode {
|
Continue = 100,
|
||||||
Continue=100,
|
SwitchingProtocols = 101,
|
||||||
SwitchingProtocols=101,
|
Processing = 102,
|
||||||
Processing=102,
|
EarlyHints = 103,
|
||||||
EarlyHints=103,
|
OK = 200,
|
||||||
OK=200,
|
Created = 201,
|
||||||
Created=201,
|
Accepted = 202,
|
||||||
Accepted=202,
|
NonAuthoritativeInformation = 203,
|
||||||
NonAuthoritativeInformation=203,
|
NoContent = 204,
|
||||||
NoContent=204,
|
ResetContent = 205,
|
||||||
ResetContent=205,
|
PartialContent = 206,
|
||||||
PartialContent=206,
|
MultiStatus = 207,
|
||||||
MultiStatus=207,
|
AlreadyReported = 208,
|
||||||
AlreadyReported=208,
|
IMUsed = 226,
|
||||||
IMUsed=226,
|
MultipleChoices = 300,
|
||||||
MultipleChoices=300,
|
MovedPermanently = 301,
|
||||||
MovedPermanently=301,
|
Found = 302,
|
||||||
Found=302,
|
SeeOther = 303,
|
||||||
SeeOther=303,
|
NotModified = 304,
|
||||||
NotModified=304,
|
UseProxy = 305,
|
||||||
UseProxy=305,
|
TemporaryRedirect = 307,
|
||||||
TemporaryRedirect=307,
|
PermanentRedirect = 308,
|
||||||
PermanentRedirect=308,
|
BadRequest = 400,
|
||||||
BadRequest=400,
|
Unauthorized = 401,
|
||||||
Unauthorized=401,
|
PaymentRequired = 402,
|
||||||
PaymentRequired=402,
|
Forbidden = 403,
|
||||||
Forbidden=403,
|
NotFound = 404,
|
||||||
NotFound=404,
|
MethodNotAllowed = 405,
|
||||||
MethodNotAllowed=405,
|
NotAcceptable = 406,
|
||||||
NotAcceptable=406,
|
ProxyAuthenticationRequired = 407,
|
||||||
ProxyAuthenticationRequired=407,
|
RequestTimeout = 408,
|
||||||
RequestTimeout=408,
|
Conflict = 409,
|
||||||
Conflict=409,
|
Gone = 410,
|
||||||
Gone=410,
|
LengthRequired = 411,
|
||||||
LengthRequired=411,
|
PreconditionFailed = 412,
|
||||||
PreconditionFailed=412,
|
PayloadTooLarge = 413,
|
||||||
PayloadTooLarge=413,
|
URITooLong = 414,
|
||||||
URITooLong=414,
|
UnsupportedMediaType = 415,
|
||||||
UnsupportedMediaType=415,
|
RangeNotSatisfiable = 416,
|
||||||
RangeNotSatisfiable=416,
|
ExpectationFailed = 417,
|
||||||
ExpectationFailed=417,
|
ImATeapot = 418,
|
||||||
ImATeapot=418,
|
MisdirectedRequest = 421,
|
||||||
MisdirectedRequest=421,
|
UnprocessableContent = 422,
|
||||||
UnprocessableContent=422,
|
Locked = 423,
|
||||||
Locked=423,
|
FailedDependency = 424,
|
||||||
FailedDependency=424,
|
TooEarly = 425,
|
||||||
TooEarly=425,
|
UpgradeRequired = 426,
|
||||||
UpgradeRequired=426,
|
PreconditionRequired = 428,
|
||||||
PreconditionRequired=428,
|
TooManyRequests = 429,
|
||||||
TooManyRequests=429,
|
RequestHeaderFieldsTooLarge = 431,
|
||||||
RequestHeaderFieldsTooLarge=431,
|
UnavailableForLegalReasons = 451,
|
||||||
UnavailableForLegalReasons=451,
|
InternalServerError = 500,
|
||||||
InternalServerError=500,
|
NotImplemented = 501,
|
||||||
NotImplemented=501,
|
BadGateway = 502,
|
||||||
BadGateway=502,
|
ServiceUnavailable = 503,
|
||||||
ServiceUnavailable=503,
|
GatewayTimeout = 504,
|
||||||
GatewayTimeout=504,
|
HTTPVersionNotSupported = 505,
|
||||||
HTTPVersionNotSupported=505,
|
VariantAlsoNegotiates = 506,
|
||||||
VariantAlsoNegotiates=506,
|
InsufficientStorage = 507,
|
||||||
InsufficientStorage=507,
|
LoopDetected = 508,
|
||||||
LoopDetected=508,
|
NotExtended = 510,
|
||||||
NotExtended=510,
|
NetworkAuthenticationRequired = 511
|
||||||
NetworkAuthenticationRequired=511
|
|
||||||
} StatusCode;
|
} StatusCode;
|
||||||
|
|
||||||
struct CaseInsensitiveLess {
|
struct CaseInsensitiveLess {
|
||||||
CaseInsensitiveLess(const CaseInsensitiveLess& str);
|
CaseInsensitiveLess(const CaseInsensitiveLess &str);
|
||||||
CaseInsensitiveLess();
|
CaseInsensitiveLess();
|
||||||
CaseInsensitiveLess* offset;
|
CaseInsensitiveLess *offset;
|
||||||
bool caseSensitive;
|
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 TryGetFirst(std::string key, std::string &value);
|
||||||
bool TryGetFirstDate(std::string key, Date::DateTime& 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 {
|
bool GetFirstBoolean(std::string key);
|
||||||
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
|
bool AnyEquals(std::string key, std::string value);
|
||||||
{
|
};
|
||||||
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);
|
class Uri {
|
||||||
static void BytesToHex(std::string& text,const std::vector<uint8_t>& data, bool isUppercase);
|
public:
|
||||||
static std::vector<uint8_t> HexToBytes(const std::string& text);
|
Uri();
|
||||||
static void HexToBytes(std::vector<uint8_t>& data,const std::string& text);
|
std::string GetQuery();
|
||||||
static std::string MimeType(std::filesystem::path p);
|
std::string GetPathAndQuery();
|
||||||
static bool Invalid(char c);
|
uint16_t GetPort();
|
||||||
static std::string Sanitise(std::string text);
|
std::string HostPort();
|
||||||
static void QueryParamsDecode(HttpDictionary& dict,std::string query);
|
bool Relative(std::string url, Uri &uri);
|
||||||
static std::string Join(std::string joinStr, std::vector<std::string> ents);
|
std::string ToString();
|
||||||
static std::string QueryParamsEncode(HttpDictionary& dict);
|
static bool TryParse(std::string url, Uri &uri);
|
||||||
static std::string UrlDecode(std::string v);
|
std::string scheme;
|
||||||
static std::string UrlEncode(std::string v);
|
std::string host;
|
||||||
static std::string UrlPathDecode(std::string v);
|
uint16_t port;
|
||||||
static std::string UrlPathEncode(std::string v, bool ignoreSpace=false);
|
std::string path;
|
||||||
static std::string HtmlEncode(std::string v);
|
HttpDictionary query;
|
||||||
static std::string HtmlP(std::string text);
|
std::string hash;
|
||||||
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);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
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"
|
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||||
#include "../Filesystem/VFSFix.hpp"
|
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||||
#include "../Filesystem/VFS.hpp"
|
|
||||||
|
|
||||||
namespace Tesses::Framework::Http
|
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
|
||||||
class MountableServer : public IHttpServer
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
{
|
(at your option) any later version.
|
||||||
std::shared_ptr<IHttpServer> root;
|
|
||||||
std::vector<std::pair<std::string,std::shared_ptr<IHttpServer>>> servers;
|
This program is distributed in the hope that it will be useful,
|
||||||
std::string Subpath(Filesystem::VFSPath fullPath, Filesystem::VFSPath offsetPath);
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
bool StartsWith(Filesystem::VFSPath fullPath, Filesystem::VFSPath offsetPath);
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
public:
|
GNU General Public License for more details.
|
||||||
MountableServer();
|
|
||||||
MountableServer(std::shared_ptr<IHttpServer> root);
|
You should have received a copy of the GNU General Public License
|
||||||
void Mount(std::string path, std::shared_ptr<IHttpServer> server);
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
void Unmount(std::string path);
|
*/
|
||||||
bool Handle(ServerContext& ctx);
|
|
||||||
~MountableServer();
|
#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
|
#pragma once
|
||||||
#include "HttpServer.hpp"
|
|
||||||
#include "../Filesystem/VFSFix.hpp"
|
|
||||||
#include "../Filesystem/VFS.hpp"
|
#include "../Filesystem/VFS.hpp"
|
||||||
|
#include "../Filesystem/VFSFix.hpp"
|
||||||
|
#include "HttpServer.hpp"
|
||||||
|
|
||||||
namespace Tesses::Framework::Http
|
namespace Tesses::Framework::Http {
|
||||||
{
|
using ServerRequestHandler = std::function<bool(ServerContext &)>;
|
||||||
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;
|
|
||||||
|
|
||||||
RouteServerRoute() = default;
|
class RouteServer : public IHttpServer {
|
||||||
RouteServerRoute(std::string route, std::string method, ServerRequestHandler handler);
|
class RouteServerRoute {
|
||||||
bool Equals(Tesses::Framework::Filesystem::VFSPath& path, HttpDictionary& args);
|
public:
|
||||||
};
|
std::vector<std::pair<std::string, bool>> parts;
|
||||||
std::vector<RouteServerRoute> routes;
|
std::string method;
|
||||||
std::shared_ptr<IHttpServer> root;
|
ServerRequestHandler handler;
|
||||||
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);
|
RouteServerRoute() = default;
|
||||||
|
RouteServerRoute(std::string route, std::string method,
|
||||||
void Trace(std::string pattern, ServerRequestHandler handler);
|
ServerRequestHandler handler);
|
||||||
void Options(std::string pattern, ServerRequestHandler handler);
|
bool Equals(Tesses::Framework::Filesystem::VFSPath &path,
|
||||||
void Add(std::string method, std::string pattern, ServerRequestHandler handler);
|
HttpDictionary &args);
|
||||||
bool Handle(ServerContext& ctx);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
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
|
||||||
@@ -1,43 +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
|
#pragma once
|
||||||
#include <functional>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <functional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cstddef>
|
namespace Tesses::Framework::Http {
|
||||||
namespace Tesses::Framework::Http
|
class WebSocketMessage {
|
||||||
{
|
public:
|
||||||
class WebSocketMessage {
|
std::vector<uint8_t> data;
|
||||||
public:
|
bool isBinary;
|
||||||
std::vector<uint8_t> data;
|
WebSocketMessage();
|
||||||
bool isBinary;
|
WebSocketMessage(std::vector<uint8_t> data);
|
||||||
WebSocketMessage();
|
WebSocketMessage(const void *data, size_t len);
|
||||||
WebSocketMessage(std::vector<uint8_t> data);
|
WebSocketMessage(std::string message);
|
||||||
WebSocketMessage(const void* data, size_t len);
|
std::string ToString();
|
||||||
WebSocketMessage(std::string message);
|
};
|
||||||
std::string ToString();
|
void SendWebSocketMessage(std::function<void(WebSocketMessage &)> cb,
|
||||||
|
std::string text);
|
||||||
|
class WebSocketConnection {
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual void OnOpen(std::function<void(WebSocketMessage &)> sendMessage,
|
||||||
};
|
std::function<void()> ping,
|
||||||
void SendWebSocketMessage(std::function<void(WebSocketMessage&)> cb, std::string text);
|
std::function<void()> close) = 0;
|
||||||
class WebSocketConnection {
|
virtual void OnReceive(WebSocketMessage &message) = 0;
|
||||||
|
virtual void OnClose(bool clean) = 0;
|
||||||
public:
|
virtual ~WebSocketConnection();
|
||||||
virtual void OnOpen(std::function<void(WebSocketMessage&)> sendMessage, std::function<void()> ping,std::function<void()> close)=0;
|
};
|
||||||
virtual void OnReceive(WebSocketMessage& message)=0;
|
class CallbackWebSocketConnection : public WebSocketConnection {
|
||||||
virtual void OnClose(bool clean)=0;
|
public:
|
||||||
virtual ~WebSocketConnection();
|
std::function<void(std::function<void(WebSocketMessage &)>,
|
||||||
};
|
std::function<void()>, std::function<void()>)>
|
||||||
class CallbackWebSocketConnection : public WebSocketConnection {
|
onOpen;
|
||||||
public:
|
std::function<void(WebSocketMessage &)> onReceive;
|
||||||
std::function<void(std::function<void(WebSocketMessage&)>,std::function<void()>,std::function<void()>)> onOpen;
|
std::function<void(bool)> onClose;
|
||||||
std::function<void(WebSocketMessage&)> onReceive;
|
CallbackWebSocketConnection();
|
||||||
std::function<void(bool)> onClose;
|
CallbackWebSocketConnection(
|
||||||
CallbackWebSocketConnection();
|
std::function<void(std::function<void(WebSocketMessage &)>,
|
||||||
CallbackWebSocketConnection(std::function<void(std::function<void(WebSocketMessage&)>,std::function<void()>,std::function<void()>)> onOpen, std::function<void(WebSocketMessage&)> onReceive, std::function<void(bool)> onClose);
|
std::function<void()>, std::function<void()>)>
|
||||||
|
onOpen,
|
||||||
|
std::function<void(WebSocketMessage &)> onReceive,
|
||||||
|
std::function<void(bool)> onClose);
|
||||||
|
|
||||||
void OnOpen(std::function<void(WebSocketMessage&)> sendMessage, std::function<void()> ping,std::function<void()> closeFn);
|
void OnOpen(std::function<void(WebSocketMessage &)> sendMessage,
|
||||||
void OnReceive(WebSocketMessage& message);
|
std::function<void()> ping, std::function<void()> closeFn);
|
||||||
void OnClose(bool clean);
|
void OnReceive(WebSocketMessage &message);
|
||||||
};
|
void OnClose(bool clean);
|
||||||
}
|
};
|
||||||
|
} // namespace Tesses::Framework::Http
|
||||||
@@ -1,52 +1,61 @@
|
|||||||
|
/*
|
||||||
|
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
|
#pragma once
|
||||||
#include "Common.hpp"
|
#include "Common.hpp"
|
||||||
#include "Threading/Mutex.hpp"
|
#include "Threading/Mutex.hpp"
|
||||||
#include <functional>
|
#include <functional>
|
||||||
namespace Tesses::Framework {
|
namespace Tesses::Framework {
|
||||||
template<typename T>
|
template <typename T> class Lazy {
|
||||||
class Lazy {
|
Threading::Mutex mtx;
|
||||||
Threading::Mutex mtx;
|
T value;
|
||||||
T value;
|
bool hasInit = false;
|
||||||
bool hasInit=false;
|
std::function<T()> init;
|
||||||
std::function<T()> init;
|
std::function<void(T)> free;
|
||||||
std::function<void(T)> free;
|
|
||||||
public:
|
|
||||||
Lazy(std::function<T()> init, std::function<void(T)> free)
|
|
||||||
{
|
|
||||||
this->init = init;
|
|
||||||
this->free = free;
|
|
||||||
}
|
|
||||||
Lazy(std::function<T()> init) : Lazy(init, [](T item)->void {})
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
public:
|
||||||
bool HasInit()
|
Lazy(std::function<T()> init, std::function<void(T)> free) {
|
||||||
{
|
this->init = init;
|
||||||
mtx.Lock();
|
this->free = free;
|
||||||
bool hI = this->hasInit;
|
}
|
||||||
mtx.Unlock();
|
Lazy(std::function<T()> init) : Lazy(init, [](T item) -> void {}) {}
|
||||||
return hI;
|
bool HasInit() {
|
||||||
}
|
mtx.Lock();
|
||||||
T& GetValue()
|
bool hI = this->hasInit;
|
||||||
{
|
mtx.Unlock();
|
||||||
mtx.Lock();
|
return hI;
|
||||||
if(hasInit)
|
}
|
||||||
{
|
T &GetValue() {
|
||||||
mtx.Unlock();
|
mtx.Lock();
|
||||||
return this->value;
|
if (hasInit) {
|
||||||
}
|
mtx.Unlock();
|
||||||
else
|
return this->value;
|
||||||
{
|
} else {
|
||||||
this->value = this->init();
|
this->value = this->init();
|
||||||
this->hasInit=true;
|
this->hasInit = true;
|
||||||
mtx.Unlock();
|
mtx.Unlock();
|
||||||
return this->value;
|
return this->value;
|
||||||
}
|
}
|
||||||
mtx.Unlock();
|
mtx.Unlock();
|
||||||
}
|
}
|
||||||
~Lazy()
|
~Lazy() {
|
||||||
{
|
if (hasInit)
|
||||||
if(hasInit) this->free(this->value);
|
this->free(this->value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
} // namespace Tesses::Framework
|
||||||
|
|||||||
@@ -1,51 +1,66 @@
|
|||||||
|
/*
|
||||||
|
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
|
#pragma once
|
||||||
#include "../Streams/Stream.hpp"
|
#include "../Streams/Stream.hpp"
|
||||||
namespace Tesses::Framework::Mail
|
namespace Tesses::Framework::Mail {
|
||||||
{
|
class SMTPBody {
|
||||||
class SMTPBody
|
public:
|
||||||
{
|
std::string mimeType;
|
||||||
public:
|
virtual void
|
||||||
std::string mimeType;
|
Write(std::shared_ptr<Tesses::Framework::Streams::Stream> strm) = 0;
|
||||||
virtual void Write(std::shared_ptr<Tesses::Framework::Streams::Stream> strm)=0;
|
virtual ~SMTPBody();
|
||||||
virtual ~SMTPBody();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class SMTPStringBody : public SMTPBody
|
class SMTPStringBody : public SMTPBody {
|
||||||
{
|
public:
|
||||||
public:
|
SMTPStringBody();
|
||||||
SMTPStringBody();
|
SMTPStringBody(std::string text, std::string mimeType);
|
||||||
SMTPStringBody(std::string text, std::string mimeType);
|
std::string text;
|
||||||
std::string text;
|
void Write(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||||
void Write(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class SMTPStreamBody : public SMTPBody
|
class SMTPStreamBody : public SMTPBody {
|
||||||
{
|
|
||||||
std::shared_ptr<Tesses::Framework::Streams::Stream> stream;
|
std::shared_ptr<Tesses::Framework::Streams::Stream> stream;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SMTPStreamBody(std::string mimeType,std::shared_ptr<Tesses::Framework::Streams::Stream> stream);
|
SMTPStreamBody(std::string mimeType,
|
||||||
void Write(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
std::shared_ptr<Tesses::Framework::Streams::Stream> stream);
|
||||||
~SMTPStreamBody();
|
void Write(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||||
|
~SMTPStreamBody();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class SMTPClient {
|
class SMTPClient {
|
||||||
std::shared_ptr<Tesses::Framework::Streams::Stream> strm;
|
std::shared_ptr<Tesses::Framework::Streams::Stream> strm;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SMTPClient(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
SMTPClient(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||||
std::string domain;
|
std::string domain;
|
||||||
std::string username;
|
std::string username;
|
||||||
std::string password;
|
std::string password;
|
||||||
std::string from;
|
std::string from;
|
||||||
std::string from_name;
|
std::string from_name;
|
||||||
std::string to;
|
std::string to;
|
||||||
std::string subject;
|
std::string subject;
|
||||||
std::shared_ptr<SMTPBody> body;
|
std::shared_ptr<SMTPBody> body;
|
||||||
std::vector<std::pair<std::string,std::shared_ptr<SMTPBody>>> attachments;
|
std::vector<std::pair<std::string, std::shared_ptr<SMTPBody>>> attachments;
|
||||||
void Send();
|
void Send();
|
||||||
~SMTPClient();
|
~SMTPClient();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace Tesses::Framework::Mail
|
||||||
@@ -1,51 +1,69 @@
|
|||||||
|
/*
|
||||||
|
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
|
#pragma once
|
||||||
#include "TessesFramework/Filesystem/VFSFix.hpp"
|
|
||||||
#include "TessesFramework/Filesystem/LocalFS.hpp"
|
#include "TessesFramework/Filesystem/LocalFS.hpp"
|
||||||
|
#include "TessesFramework/Filesystem/VFSFix.hpp"
|
||||||
#include <optional>
|
#include <optional>
|
||||||
namespace Tesses::Framework::Platform::Environment
|
namespace Tesses::Framework::Platform::Environment {
|
||||||
{
|
extern const char EnvPathSeperator;
|
||||||
extern const char EnvPathSeperator;
|
|
||||||
|
|
||||||
struct PortableAppConfig {
|
struct PortableAppConfig {
|
||||||
|
|
||||||
std::optional<Tesses::Framework::Filesystem::VFSPath> desktop;
|
|
||||||
std::optional<Tesses::Framework::Filesystem::VFSPath> documents;
|
|
||||||
std::optional<Tesses::Framework::Filesystem::VFSPath> music;
|
|
||||||
std::optional<Tesses::Framework::Filesystem::VFSPath> pictures;
|
|
||||||
std::optional<Tesses::Framework::Filesystem::VFSPath> videos;
|
|
||||||
std::optional<Tesses::Framework::Filesystem::VFSPath> downloads;
|
|
||||||
std::optional<Tesses::Framework::Filesystem::VFSPath> user;
|
|
||||||
std::optional<Tesses::Framework::Filesystem::VFSPath> config;
|
|
||||||
std::optional<Tesses::Framework::Filesystem::VFSPath> state;
|
|
||||||
std::optional<Tesses::Framework::Filesystem::VFSPath> data;
|
|
||||||
std::optional<Tesses::Framework::Filesystem::VFSPath> cache;
|
|
||||||
std::optional<Tesses::Framework::Filesystem::VFSPath> temp;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern PortableAppConfig portable_config;
|
std::optional<Tesses::Framework::Filesystem::VFSPath> desktop;
|
||||||
|
std::optional<Tesses::Framework::Filesystem::VFSPath> documents;
|
||||||
|
std::optional<Tesses::Framework::Filesystem::VFSPath> music;
|
||||||
|
std::optional<Tesses::Framework::Filesystem::VFSPath> pictures;
|
||||||
|
std::optional<Tesses::Framework::Filesystem::VFSPath> videos;
|
||||||
|
std::optional<Tesses::Framework::Filesystem::VFSPath> downloads;
|
||||||
|
std::optional<Tesses::Framework::Filesystem::VFSPath> user;
|
||||||
|
std::optional<Tesses::Framework::Filesystem::VFSPath> config;
|
||||||
|
std::optional<Tesses::Framework::Filesystem::VFSPath> state;
|
||||||
|
std::optional<Tesses::Framework::Filesystem::VFSPath> data;
|
||||||
|
std::optional<Tesses::Framework::Filesystem::VFSPath> cache;
|
||||||
|
std::optional<Tesses::Framework::Filesystem::VFSPath> temp;
|
||||||
|
};
|
||||||
|
|
||||||
namespace SpecialFolders {
|
extern PortableAppConfig portable_config;
|
||||||
Tesses::Framework::Filesystem::VFSPath GetTemp();
|
|
||||||
Tesses::Framework::Filesystem::VFSPath GetHomeFolder();
|
|
||||||
Tesses::Framework::Filesystem::VFSPath GetDownloads();
|
|
||||||
Tesses::Framework::Filesystem::VFSPath GetMusic();
|
|
||||||
Tesses::Framework::Filesystem::VFSPath GetPictures();
|
|
||||||
Tesses::Framework::Filesystem::VFSPath GetVideos();
|
|
||||||
Tesses::Framework::Filesystem::VFSPath GetDocuments();
|
|
||||||
Tesses::Framework::Filesystem::VFSPath GetConfig();
|
|
||||||
Tesses::Framework::Filesystem::VFSPath GetDesktop();
|
|
||||||
Tesses::Framework::Filesystem::VFSPath GetState();
|
|
||||||
Tesses::Framework::Filesystem::VFSPath GetCache();
|
|
||||||
Tesses::Framework::Filesystem::VFSPath GetData();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string GetPlatform();
|
namespace SpecialFolders {
|
||||||
|
Tesses::Framework::Filesystem::VFSPath GetTemp();
|
||||||
|
Tesses::Framework::Filesystem::VFSPath GetHomeFolder();
|
||||||
|
Tesses::Framework::Filesystem::VFSPath GetDownloads();
|
||||||
|
Tesses::Framework::Filesystem::VFSPath GetMusic();
|
||||||
|
Tesses::Framework::Filesystem::VFSPath GetPictures();
|
||||||
|
Tesses::Framework::Filesystem::VFSPath GetVideos();
|
||||||
|
Tesses::Framework::Filesystem::VFSPath GetDocuments();
|
||||||
|
Tesses::Framework::Filesystem::VFSPath GetConfig();
|
||||||
|
Tesses::Framework::Filesystem::VFSPath GetDesktop();
|
||||||
|
Tesses::Framework::Filesystem::VFSPath GetState();
|
||||||
|
Tesses::Framework::Filesystem::VFSPath GetCache();
|
||||||
|
Tesses::Framework::Filesystem::VFSPath GetData();
|
||||||
|
} // namespace SpecialFolders
|
||||||
|
|
||||||
Tesses::Framework::Filesystem::VFSPath GetRealExecutablePath(Tesses::Framework::Filesystem::VFSPath realPath);
|
std::string GetPlatform();
|
||||||
|
|
||||||
std::optional<std::string> GetVariable(std::string name);
|
Tesses::Framework::Filesystem::VFSPath
|
||||||
void SetVariable(std::string name, std::optional<std::string> var);
|
GetRealExecutablePath(Tesses::Framework::Filesystem::VFSPath realPath);
|
||||||
|
|
||||||
void GetEnvironmentVariables(std::vector<std::pair<std::string,std::string>>& env);
|
std::optional<std::string> GetVariable(std::string name);
|
||||||
}
|
void SetVariable(std::string name, std::optional<std::string> var);
|
||||||
|
|
||||||
|
void GetEnvironmentVariables(
|
||||||
|
std::vector<std::pair<std::string, std::string>> &env);
|
||||||
|
} // namespace Tesses::Framework::Platform::Environment
|
||||||
|
|||||||
@@ -1,50 +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
|
#pragma once
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
#include "TessesFramework/Streams/Stream.hpp"
|
|
||||||
#include "TessesFramework/HiddenField.hpp"
|
#include "TessesFramework/HiddenField.hpp"
|
||||||
|
#include "TessesFramework/Streams/Stream.hpp"
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#define SIGKILL 9
|
#define SIGKILL 9
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Tesses::Framework::Platform {
|
namespace Tesses::Framework::Platform {
|
||||||
class Process {
|
class Process {
|
||||||
private:
|
private:
|
||||||
HiddenField hidden;
|
HiddenField hidden;
|
||||||
bool exited = false;
|
bool exited = false;
|
||||||
int exitCode=0;
|
int exitCode = 0;
|
||||||
public:
|
|
||||||
std::string name;
|
|
||||||
std::vector<std::string> args;
|
|
||||||
std::string workingDirectory;
|
|
||||||
std::vector<std::pair<std::string,std::string>> env;
|
|
||||||
bool includeThisEnv;
|
|
||||||
bool redirectStdIn=false;
|
|
||||||
bool redirectStdOut=false;
|
|
||||||
bool redirectStdErr=false;
|
|
||||||
bool HasExited();
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
std::string name;
|
||||||
|
std::vector<std::string> args;
|
||||||
|
std::string workingDirectory;
|
||||||
|
std::vector<std::pair<std::string, std::string>> env;
|
||||||
|
bool includeThisEnv;
|
||||||
|
bool redirectStdIn = false;
|
||||||
|
bool redirectStdOut = false;
|
||||||
|
bool redirectStdErr = false;
|
||||||
|
bool HasExited();
|
||||||
|
|
||||||
void CloseStdInNow();
|
void CloseStdInNow();
|
||||||
|
|
||||||
std::shared_ptr<Tesses::Framework::Streams::Stream> GetStdinStream();
|
|
||||||
|
|
||||||
std::shared_ptr<Tesses::Framework::Streams::Stream> GetStdoutStream();
|
std::shared_ptr<Tesses::Framework::Streams::Stream> GetStdinStream();
|
||||||
std::shared_ptr<Tesses::Framework::Streams::Stream> GetStderrStream();
|
|
||||||
|
|
||||||
Process();
|
std::shared_ptr<Tesses::Framework::Streams::Stream> GetStdoutStream();
|
||||||
Process(std::string name, std::vector<std::string> args,bool includeThisEnv=true);
|
std::shared_ptr<Tesses::Framework::Streams::Stream> GetStderrStream();
|
||||||
Process(std::string name, std::vector<std::string> args, std::vector<std::pair<std::string,std::string>> env,bool includeThisEnv=false);
|
|
||||||
Process(std::string name, std::vector<std::string> args, std::vector<std::string> env,bool includeThisEnv=false);
|
|
||||||
|
|
||||||
|
|
||||||
bool Start();
|
Process();
|
||||||
|
Process(std::string name, std::vector<std::string> args,
|
||||||
|
bool includeThisEnv = true);
|
||||||
|
Process(std::string name, std::vector<std::string> args,
|
||||||
|
std::vector<std::pair<std::string, std::string>> env,
|
||||||
|
bool includeThisEnv = false);
|
||||||
|
Process(std::string name, std::vector<std::string> args,
|
||||||
|
std::vector<std::string> env, bool includeThisEnv = false);
|
||||||
|
|
||||||
void Kill(int signal);
|
bool Start();
|
||||||
|
|
||||||
int WaitForExit();
|
void Kill(int signal);
|
||||||
|
|
||||||
~Process();
|
int WaitForExit();
|
||||||
|
|
||||||
|
~Process();
|
||||||
};
|
};
|
||||||
}
|
} // namespace Tesses::Framework::Platform
|
||||||
@@ -1,15 +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
|
#pragma once
|
||||||
#include "Common.hpp"
|
#include "Common.hpp"
|
||||||
|
|
||||||
namespace Tesses::Framework {
|
namespace Tesses::Framework {
|
||||||
class Random {
|
class Random {
|
||||||
uint64_t num;
|
uint64_t num;
|
||||||
public:
|
|
||||||
Random();
|
public:
|
||||||
Random(uint64_t seed);
|
Random();
|
||||||
uint64_t Next();
|
Random(uint64_t seed);
|
||||||
uint32_t Next(uint32_t max);
|
uint64_t Next();
|
||||||
int32_t Next(int32_t min,int32_t max);
|
uint32_t Next(uint32_t max);
|
||||||
uint8_t NextByte();
|
int32_t Next(int32_t min, int32_t max);
|
||||||
};
|
uint8_t NextByte();
|
||||||
}
|
};
|
||||||
|
} // namespace Tesses::Framework
|
||||||
@@ -1,59 +1,83 @@
|
|||||||
|
/*
|
||||||
|
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
|
#pragma once
|
||||||
#include <cstdint>
|
|
||||||
#include <vector>
|
|
||||||
#include <variant>
|
|
||||||
#include <string>
|
|
||||||
#include "../Streams/Stream.hpp"
|
#include "../Streams/Stream.hpp"
|
||||||
#include "../TextStreams/TextWriter.hpp"
|
#include "../TextStreams/TextWriter.hpp"
|
||||||
#include "Json.hpp"
|
#include "Json.hpp"
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
#include <variant>
|
||||||
|
#include <vector>
|
||||||
namespace Tesses::Framework::Serialization::Bencode {
|
namespace Tesses::Framework::Serialization::Bencode {
|
||||||
class BeArray;
|
class BeArray;
|
||||||
class BeDictionary;
|
class BeDictionary;
|
||||||
class BeString;
|
class BeString;
|
||||||
using BeUndefined = std::monostate;
|
using BeUndefined = std::monostate;
|
||||||
|
|
||||||
using BeToken = std::variant<BeUndefined,BeArray,BeDictionary,BeString,int64_t>;
|
using BeToken =
|
||||||
|
std::variant<BeUndefined, BeArray, BeDictionary, BeString, int64_t>;
|
||||||
|
|
||||||
class BeArray {
|
class BeArray {
|
||||||
public:
|
public:
|
||||||
std::vector<BeToken> tokens;
|
std::vector<BeToken> tokens;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BeDictionary {
|
class BeDictionary {
|
||||||
public:
|
public:
|
||||||
std::vector<std::pair<BeString,BeToken>> tokens;
|
std::vector<std::pair<BeString, BeToken>> tokens;
|
||||||
BeToken GetValue(BeString key) const;
|
BeToken GetValue(BeString key) const;
|
||||||
void SetValue(BeString key, BeToken value);
|
void SetValue(BeString key, BeToken value);
|
||||||
};
|
};
|
||||||
class BeString {
|
class BeString {
|
||||||
public:
|
public:
|
||||||
BeString();
|
BeString();
|
||||||
BeString(const std::string& text);
|
BeString(const std::string &text);
|
||||||
BeString(const char* text);
|
BeString(const char *text);
|
||||||
BeString(const std::vector<uint8_t>& data);
|
BeString(const std::vector<uint8_t> &data);
|
||||||
std::vector<uint8_t> data;
|
std::vector<uint8_t> data;
|
||||||
|
|
||||||
operator std::string() const;
|
operator std::string() const;
|
||||||
};
|
};
|
||||||
bool operator==(const BeString& lStr, const BeString& rStr);
|
bool operator==(const BeString &lStr, const BeString &rStr);
|
||||||
bool operator==(const BeString& lStr, const std::string& rStr);
|
bool operator==(const BeString &lStr, const std::string &rStr);
|
||||||
bool operator==(const std::string& lStr, const BeString& rStr);
|
bool operator==(const std::string &lStr, const BeString &rStr);
|
||||||
bool operator==(const BeString& lStr, const char* rStr);
|
bool operator==(const BeString &lStr, const char *rStr);
|
||||||
bool operator==(const char* lStr, const BeString& rStr);
|
bool operator==(const char *lStr, const BeString &rStr);
|
||||||
|
|
||||||
bool operator!=(const BeString& lStr, const BeString& rStr);
|
bool operator!=(const BeString &lStr, const BeString &rStr);
|
||||||
bool operator!=(const BeString& lStr, const std::string& rStr);
|
bool operator!=(const BeString &lStr, const std::string &rStr);
|
||||||
bool operator!=(const std::string& lStr, const BeString& rStr);
|
bool operator!=(const std::string &lStr, const BeString &rStr);
|
||||||
bool operator!=(const BeString& lStr, const char* rStr);
|
bool operator!=(const BeString &lStr, const char *rStr);
|
||||||
bool operator!=(const char* lStr, const BeString& rStr);
|
bool operator!=(const char *lStr, const BeString &rStr);
|
||||||
|
|
||||||
class Bencode {
|
class Bencode {
|
||||||
public:
|
public:
|
||||||
static void Save(std::shared_ptr<Tesses::Framework::Streams::Stream> strm,const BeToken& value);
|
static void Save(std::shared_ptr<Tesses::Framework::Streams::Stream> strm,
|
||||||
static BeToken Load(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
const BeToken &value);
|
||||||
//This cannot be converted back to torrent, this may (probably will) be out of order
|
static BeToken
|
||||||
static Json::JToken ToJson(const BeToken& tkn);
|
Load(std::shared_ptr<Tesses::Framework::Streams::Stream> strm);
|
||||||
//This may (probably will) be out of order
|
// This cannot be converted back to torrent, this may (probably will) be out
|
||||||
static void Print(std::shared_ptr<Tesses::Framework::TextStreams::TextWriter> writer, BeToken tkn);
|
// of order
|
||||||
};
|
static Json::JToken ToJson(const BeToken &tkn);
|
||||||
}
|
// This may (probably will) be out of order
|
||||||
|
static void
|
||||||
|
Print(std::shared_ptr<Tesses::Framework::TextStreams::TextWriter> writer,
|
||||||
|
BeToken tkn);
|
||||||
|
};
|
||||||
|
} // namespace Tesses::Framework::Serialization::Bencode
|
||||||
@@ -1,82 +1,93 @@
|
|||||||
|
/*
|
||||||
|
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
|
#pragma once
|
||||||
#include "../Common.hpp"
|
#include "../Common.hpp"
|
||||||
#include "../Uuid.hpp"
|
#include "../Uuid.hpp"
|
||||||
namespace Tesses::Framework::Serialization
|
namespace Tesses::Framework::Serialization {
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A bit converter
|
* @brief A bit converter
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class BitConverter {
|
class BitConverter {
|
||||||
public:
|
public:
|
||||||
|
static double ToDoubleBits(uint64_t v);
|
||||||
static double ToDoubleBits(uint64_t v);
|
|
||||||
|
|
||||||
static uint64_t ToUintBits(double v);
|
|
||||||
static float ToFloatBits(uint32_t v);
|
|
||||||
|
|
||||||
static uint32_t ToUint32Bits(float v);
|
|
||||||
|
|
||||||
static double ToDoubleBE(uint8_t& b);
|
|
||||||
static float ToFloatBE(uint8_t& b);
|
|
||||||
|
|
||||||
static uint64_t ToUint64BE(uint8_t& b);
|
|
||||||
static uint32_t ToUint32BE(uint8_t& b);
|
|
||||||
static uint16_t ToUint16BE(uint8_t& b);
|
|
||||||
|
|
||||||
static double ToDoubleLE(uint8_t& b);
|
static uint64_t ToUintBits(double v);
|
||||||
static float ToFloatLE(uint8_t& b);
|
static float ToFloatBits(uint32_t v);
|
||||||
static uint64_t ToUint64LE(uint8_t& b);
|
|
||||||
static uint32_t ToUint32LE(uint8_t& b);
|
|
||||||
static uint16_t ToUint16LE(uint8_t& b);
|
|
||||||
|
|
||||||
static int64_t ToSint64BE(uint8_t& b);
|
static uint32_t ToUint32Bits(float v);
|
||||||
static int32_t ToSint32BE(uint8_t& b);
|
|
||||||
static int16_t ToSint16BE(uint8_t& b);
|
|
||||||
static int64_t ToSint64LE(uint8_t& b);
|
|
||||||
static int32_t ToSint32LE(uint8_t& b);
|
|
||||||
static int16_t ToSint16LE(uint8_t& b);
|
|
||||||
|
|
||||||
static Uuid ToUuid(uint8_t& b);
|
static double ToDoubleBE(uint8_t &b);
|
||||||
|
static float ToFloatBE(uint8_t &b);
|
||||||
|
|
||||||
|
static uint64_t ToUint64BE(uint8_t &b);
|
||||||
|
static uint32_t ToUint32BE(uint8_t &b);
|
||||||
|
static uint16_t ToUint16BE(uint8_t &b);
|
||||||
|
|
||||||
static void ToUuid(uint8_t& b, Uuid& uuid);
|
static double ToDoubleLE(uint8_t &b);
|
||||||
|
static float ToFloatLE(uint8_t &b);
|
||||||
|
static uint64_t ToUint64LE(uint8_t &b);
|
||||||
|
static uint32_t ToUint32LE(uint8_t &b);
|
||||||
|
static uint16_t ToUint16LE(uint8_t &b);
|
||||||
|
|
||||||
|
static int64_t ToSint64BE(uint8_t &b);
|
||||||
|
static int32_t ToSint32BE(uint8_t &b);
|
||||||
|
static int16_t ToSint16BE(uint8_t &b);
|
||||||
|
static int64_t ToSint64LE(uint8_t &b);
|
||||||
|
static int32_t ToSint32LE(uint8_t &b);
|
||||||
|
static int16_t ToSint16LE(uint8_t &b);
|
||||||
|
|
||||||
static void FromDoubleBE(uint8_t& b, double v);
|
static Uuid ToUuid(uint8_t &b);
|
||||||
static void FromFloatBE(uint8_t& b, float v);
|
|
||||||
static void FromUint64BE(uint8_t& b, uint64_t v);
|
|
||||||
static void FromUint32BE(uint8_t& b, uint32_t v);
|
|
||||||
static void FromUint16BE(uint8_t& b, uint16_t v);
|
|
||||||
|
|
||||||
static void FromDoubleLE(uint8_t& b, double v);
|
static void ToUuid(uint8_t &b, Uuid &uuid);
|
||||||
static void FromFloatLE(uint8_t& b, float v);
|
|
||||||
static void FromUint64LE(uint8_t& b, uint64_t v);
|
|
||||||
static void FromUint32LE(uint8_t& b, uint32_t v);
|
|
||||||
static void FromUint16LE(uint8_t& b, uint16_t v);
|
|
||||||
|
|
||||||
static void FromSint64BE(uint8_t& b, int64_t v);
|
|
||||||
static void FromSint32BE(uint8_t& b, int32_t v);
|
|
||||||
static void FromSint16BE(uint8_t& b, int16_t v);
|
|
||||||
|
|
||||||
static void FromSint64LE(uint8_t& b, int64_t v);
|
|
||||||
static void FromSint32LE(uint8_t& b, int32_t v);
|
|
||||||
static void FromSint16LE(uint8_t& b, int16_t v);
|
|
||||||
|
|
||||||
static void FromUuid(uint8_t& b, const Uuid& uuid);
|
|
||||||
|
|
||||||
|
static void FromDoubleBE(uint8_t &b, double v);
|
||||||
|
static void FromFloatBE(uint8_t &b, float v);
|
||||||
|
static void FromUint64BE(uint8_t &b, uint64_t v);
|
||||||
|
static void FromUint32BE(uint8_t &b, uint32_t v);
|
||||||
|
static void FromUint16BE(uint8_t &b, uint16_t v);
|
||||||
|
|
||||||
|
static void FromDoubleLE(uint8_t &b, double v);
|
||||||
|
static void FromFloatLE(uint8_t &b, float v);
|
||||||
|
static void FromUint64LE(uint8_t &b, uint64_t v);
|
||||||
|
static void FromUint32LE(uint8_t &b, uint32_t v);
|
||||||
|
static void FromUint16LE(uint8_t &b, uint16_t v);
|
||||||
|
|
||||||
static inline bool IsLittleEndian()
|
static void FromSint64BE(uint8_t &b, int64_t v);
|
||||||
{
|
static void FromSint32BE(uint8_t &b, int32_t v);
|
||||||
uint8_t a[2];
|
static void FromSint16BE(uint8_t &b, int16_t v);
|
||||||
a[0] = 0x01;
|
|
||||||
a[1] = 0xA4;
|
static void FromSint64LE(uint8_t &b, int64_t v);
|
||||||
uint16_t num=0;
|
static void FromSint32LE(uint8_t &b, int32_t v);
|
||||||
memcpy(&num,&a, 2);
|
static void FromSint16LE(uint8_t &b, int16_t v);
|
||||||
return num != 420;
|
|
||||||
}
|
static void FromUuid(uint8_t &b, const Uuid &uuid);
|
||||||
|
|
||||||
|
static inline bool IsLittleEndian() {
|
||||||
|
uint8_t a[2];
|
||||||
|
a[0] = 0x01;
|
||||||
|
a[1] = 0xA4;
|
||||||
|
uint16_t num = 0;
|
||||||
|
memcpy(&num, &a, 2);
|
||||||
|
return num != 420;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace Tesses::Framework::Serialization
|
||||||
@@ -1,94 +1,101 @@
|
|||||||
|
/*
|
||||||
|
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
|
#pragma once
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <variant>
|
|
||||||
#include <map>
|
|
||||||
#include <iostream>
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
namespace Tesses::Framework::Serialization::Json
|
#include <iostream>
|
||||||
{
|
#include <map>
|
||||||
class JArray;
|
#include <string>
|
||||||
class JObject;
|
#include <variant>
|
||||||
using JUndefined = std::monostate;
|
#include <vector>
|
||||||
|
namespace Tesses::Framework::Serialization::Json {
|
||||||
|
class JArray;
|
||||||
|
class JObject;
|
||||||
|
using JUndefined = std::monostate;
|
||||||
|
|
||||||
using JToken = std::variant<JUndefined,std::nullptr_t,bool,int64_t,double,std::string, JArray, JObject>;
|
using JToken = std::variant<JUndefined, std::nullptr_t, bool, int64_t, double,
|
||||||
|
std::string, JArray, JObject>;
|
||||||
|
|
||||||
class JOItem;
|
class JOItem;
|
||||||
|
|
||||||
class JArray
|
class JArray {
|
||||||
{
|
std::vector<JToken> items;
|
||||||
std::vector<JToken> items;
|
|
||||||
public:
|
|
||||||
JArray();
|
|
||||||
JArray(std::initializer_list<JToken> items);
|
|
||||||
std::vector<JToken>& GetVector();
|
|
||||||
void Add(JToken item);
|
|
||||||
void RemoveAt(size_t index);
|
|
||||||
size_t Count();
|
|
||||||
void SetAt(size_t index, JToken item);
|
|
||||||
JToken GetAt(size_t index);
|
|
||||||
void Clear();
|
|
||||||
|
|
||||||
std::vector<JToken>::iterator begin();
|
public:
|
||||||
std::vector<JToken>::iterator end();
|
JArray();
|
||||||
};
|
JArray(std::initializer_list<JToken> items);
|
||||||
|
std::vector<JToken> &GetVector();
|
||||||
|
void Add(JToken item);
|
||||||
|
void RemoveAt(size_t index);
|
||||||
|
size_t Count();
|
||||||
|
void SetAt(size_t index, JToken item);
|
||||||
|
JToken GetAt(size_t index);
|
||||||
|
void Clear();
|
||||||
|
|
||||||
|
std::vector<JToken>::iterator begin();
|
||||||
|
std::vector<JToken>::iterator end();
|
||||||
|
};
|
||||||
|
|
||||||
class JObject {
|
class JObject {
|
||||||
std::map<std::string,JToken> map;
|
std::map<std::string, JToken> map;
|
||||||
public:
|
|
||||||
JObject();
|
|
||||||
JObject(std::initializer_list<JOItem> items);
|
|
||||||
void SetValue(std::string key, JToken item);
|
|
||||||
template<typename T>
|
|
||||||
bool TryGetValueAsType(std::string key, T& value)
|
|
||||||
{
|
|
||||||
auto obj = GetValue(key);
|
|
||||||
if(std::holds_alternative<T>(obj))
|
|
||||||
{
|
|
||||||
value = std::get<T>(obj);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
JToken GetValue(std::string key);
|
public:
|
||||||
void Remove(std::string key);
|
JObject();
|
||||||
std::map<std::string,JToken>& GetMap();
|
JObject(std::initializer_list<JOItem> items);
|
||||||
std::map<std::string,JToken>::iterator begin();
|
void SetValue(std::string key, JToken item);
|
||||||
std::map<std::string,JToken>::iterator end();
|
template <typename T> bool TryGetValueAsType(std::string key, T &value) {
|
||||||
};
|
auto obj = GetValue(key);
|
||||||
template<typename T>
|
if (std::holds_alternative<T>(obj)) {
|
||||||
bool TryGetJToken(JToken json, T& item)
|
value = std::get<T>(obj);
|
||||||
{
|
|
||||||
if(std::holds_alternative<T>(json))
|
|
||||||
{
|
|
||||||
item = std::get<T>(json);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
class JOItem {
|
|
||||||
public:
|
|
||||||
JOItem();
|
|
||||||
JOItem(std::string key, JToken value);
|
|
||||||
|
|
||||||
std::string key;
|
|
||||||
JToken value;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Json
|
JToken GetValue(std::string key);
|
||||||
{
|
void Remove(std::string key);
|
||||||
static std::string tab(std::string str);
|
std::map<std::string, JToken> &GetMap();
|
||||||
public:
|
std::map<std::string, JToken>::iterator begin();
|
||||||
static JToken Decode(std::string str);
|
std::map<std::string, JToken>::iterator end();
|
||||||
static std::string Encode(JToken tkn, bool indent=true);
|
};
|
||||||
static JArray DocDecode(std::string str);
|
template <typename T> bool TryGetJToken(JToken json, T &item) {
|
||||||
static std::string DocEncode(JArray array,bool indent=true);
|
if (std::holds_alternative<T>(json)) {
|
||||||
};
|
item = std::get<T>(json);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
class JOItem {
|
||||||
|
public:
|
||||||
|
JOItem();
|
||||||
|
JOItem(std::string key, JToken value);
|
||||||
|
|
||||||
|
std::string key;
|
||||||
|
JToken value;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Json {
|
||||||
|
static std::string tab(std::string str);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static JToken Decode(std::string str);
|
||||||
|
static std::string Encode(JToken tkn, bool indent = true);
|
||||||
|
static JArray DocDecode(std::string str);
|
||||||
|
static std::string DocEncode(JArray array, bool indent = true);
|
||||||
|
};
|
||||||
|
} // namespace Tesses::Framework::Serialization::Json
|
||||||
|
|||||||
@@ -1,18 +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
|
#pragma once
|
||||||
#include "TessesFramework/Filesystem/VFSFix.hpp"
|
|
||||||
#include "TessesFramework/Filesystem/VFS.hpp"
|
#include "TessesFramework/Filesystem/VFS.hpp"
|
||||||
|
#include "TessesFramework/Filesystem/VFSFix.hpp"
|
||||||
#include <optional>
|
#include <optional>
|
||||||
namespace Tesses::Framework::Serialization {
|
namespace Tesses::Framework::Serialization {
|
||||||
class SQLiteDatabase {
|
class SQLiteDatabase {
|
||||||
private:
|
private:
|
||||||
void* data;
|
void *data;
|
||||||
static int collector(void* user, int count,char** vals, char** keys);
|
static int collector(void *user, int count, char **vals, char **keys);
|
||||||
public:
|
|
||||||
SQLiteDatabase(Tesses::Framework::Filesystem::VFSPath path);
|
public:
|
||||||
static std::string Escape(std::string text);
|
SQLiteDatabase(Tesses::Framework::Filesystem::VFSPath path);
|
||||||
static bool IsEnabled();
|
static std::string Escape(std::string text);
|
||||||
void Exec(std::string statement,std::vector<std::vector<std::pair<std::string,std::optional<std::string>>>>& results);
|
static bool IsEnabled();
|
||||||
std::vector<std::vector<std::pair<std::string,std::optional<std::string>>>> Exec(std::string statement);
|
void
|
||||||
~SQLiteDatabase();
|
Exec(std::string statement,
|
||||||
};
|
std::vector<
|
||||||
}
|
std::vector<std::pair<std::string, std::optional<std::string>>>>
|
||||||
|
&results);
|
||||||
|
std::vector<std::vector<std::pair<std::string, std::optional<std::string>>>>
|
||||||
|
Exec(std::string statement);
|
||||||
|
~SQLiteDatabase();
|
||||||
|
};
|
||||||
|
} // namespace Tesses::Framework::Serialization
|
||||||
@@ -1,26 +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
|
#pragma once
|
||||||
#include "Stream.hpp"
|
#include "Stream.hpp"
|
||||||
|
|
||||||
namespace Tesses::Framework::Streams
|
namespace Tesses::Framework::Streams {
|
||||||
{
|
class BufferedStream : public Stream {
|
||||||
class BufferedStream : public Stream
|
private:
|
||||||
{
|
std::shared_ptr<Stream> strm;
|
||||||
private:
|
uint8_t *buffer;
|
||||||
std::shared_ptr<Stream> strm;
|
size_t bufferSize;
|
||||||
uint8_t* buffer;
|
size_t offset;
|
||||||
size_t bufferSize;
|
size_t read;
|
||||||
size_t offset;
|
|
||||||
size_t read;
|
|
||||||
public:
|
|
||||||
BufferedStream(std::shared_ptr<Stream> strm, size_t bufferSize=1024);
|
|
||||||
bool EndOfStream();
|
|
||||||
bool CanRead();
|
|
||||||
bool CanWrite();
|
|
||||||
size_t Read(uint8_t* buff, size_t sz);
|
|
||||||
size_t Write(const uint8_t* buff, size_t sz);
|
|
||||||
|
|
||||||
~BufferedStream();
|
public:
|
||||||
void Close();
|
BufferedStream(std::shared_ptr<Stream> strm, size_t bufferSize = 1024);
|
||||||
};
|
bool EndOfStream();
|
||||||
|
bool CanRead();
|
||||||
|
bool CanWrite();
|
||||||
|
size_t Read(uint8_t *buff, size_t sz);
|
||||||
|
size_t Write(const uint8_t *buff, size_t sz);
|
||||||
|
|
||||||
}
|
~BufferedStream();
|
||||||
|
void Close();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Tesses::Framework::Streams
|
||||||
@@ -1,33 +1,51 @@
|
|||||||
#pragma once
|
/*
|
||||||
#include "Stream.hpp"
|
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||||
#include "../Uuid.hpp"
|
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||||
|
|
||||||
namespace Tesses::Framework::Streams
|
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
|
||||||
class ByteReader {
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
std::shared_ptr<Stream> strm;
|
(at your option) any later version.
|
||||||
public:
|
|
||||||
std::shared_ptr<Stream> GetStream();
|
This program is distributed in the hope that it will be useful,
|
||||||
ByteReader(std::shared_ptr<Stream> strm);
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
uint8_t ReadU8();
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
uint16_t ReadU16BE();
|
GNU General Public License for more details.
|
||||||
uint16_t ReadU16LE();
|
|
||||||
uint32_t ReadU32BE();
|
You should have received a copy of the GNU General Public License
|
||||||
uint32_t ReadU32LE();
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
uint64_t ReadU64BE();
|
*/
|
||||||
uint64_t ReadU64LE();
|
|
||||||
int8_t ReadI8();
|
#pragma once
|
||||||
int16_t ReadI16BE();
|
#include "../Uuid.hpp"
|
||||||
int16_t ReadI16LE();
|
#include "Stream.hpp"
|
||||||
int32_t ReadI32BE();
|
|
||||||
int32_t ReadI32LE();
|
namespace Tesses::Framework::Streams {
|
||||||
int64_t ReadI64BE();
|
class ByteReader {
|
||||||
int64_t ReadI64LE();
|
std::shared_ptr<Stream> strm;
|
||||||
float ReadF32BE();
|
|
||||||
float ReadF32LE();
|
public:
|
||||||
double ReadF64BE();
|
std::shared_ptr<Stream> GetStream();
|
||||||
double ReadF64LE();
|
ByteReader(std::shared_ptr<Stream> strm);
|
||||||
Uuid ReadUuid();
|
uint8_t ReadU8();
|
||||||
void ReadUuid(Uuid& uuid);
|
uint16_t ReadU16BE();
|
||||||
};
|
uint16_t ReadU16LE();
|
||||||
}
|
uint32_t ReadU32BE();
|
||||||
|
uint32_t ReadU32LE();
|
||||||
|
uint64_t ReadU64BE();
|
||||||
|
uint64_t ReadU64LE();
|
||||||
|
int8_t ReadI8();
|
||||||
|
int16_t ReadI16BE();
|
||||||
|
int16_t ReadI16LE();
|
||||||
|
int32_t ReadI32BE();
|
||||||
|
int32_t ReadI32LE();
|
||||||
|
int64_t ReadI64BE();
|
||||||
|
int64_t ReadI64LE();
|
||||||
|
float ReadF32BE();
|
||||||
|
float ReadF32LE();
|
||||||
|
double ReadF64BE();
|
||||||
|
double ReadF64LE();
|
||||||
|
Uuid ReadUuid();
|
||||||
|
void ReadUuid(Uuid &uuid);
|
||||||
|
};
|
||||||
|
} // namespace Tesses::Framework::Streams
|
||||||
@@ -1,32 +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
|
#pragma once
|
||||||
#include "Stream.hpp"
|
|
||||||
#include "../Uuid.hpp"
|
#include "../Uuid.hpp"
|
||||||
namespace Tesses::Framework::Streams
|
#include "Stream.hpp"
|
||||||
{
|
namespace Tesses::Framework::Streams {
|
||||||
class ByteWriter {
|
class ByteWriter {
|
||||||
std::shared_ptr<Stream> strm;
|
std::shared_ptr<Stream> strm;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::shared_ptr<Stream> GetStream();
|
std::shared_ptr<Stream> GetStream();
|
||||||
ByteWriter(std::shared_ptr<Stream> strm);
|
ByteWriter(std::shared_ptr<Stream> strm);
|
||||||
void WriteU8(uint8_t v);
|
void WriteU8(uint8_t v);
|
||||||
void WriteU16BE(uint16_t v);
|
void WriteU16BE(uint16_t v);
|
||||||
void WriteU16LE(uint16_t v);
|
void WriteU16LE(uint16_t v);
|
||||||
void WriteU32BE(uint32_t v);
|
void WriteU32BE(uint32_t v);
|
||||||
void WriteU32LE(uint32_t v);
|
void WriteU32LE(uint32_t v);
|
||||||
void WriteU64BE(uint64_t v);
|
void WriteU64BE(uint64_t v);
|
||||||
void WriteU64LE(uint64_t v);
|
void WriteU64LE(uint64_t v);
|
||||||
void WriteI8(int8_t v);
|
void WriteI8(int8_t v);
|
||||||
void WriteI16BE(int16_t v);
|
void WriteI16BE(int16_t v);
|
||||||
void WriteI16LE(int16_t v);
|
void WriteI16LE(int16_t v);
|
||||||
void WriteI32BE(int32_t v);
|
void WriteI32BE(int32_t v);
|
||||||
void WriteI32LE(int32_t v);
|
void WriteI32LE(int32_t v);
|
||||||
void WriteI64BE(int64_t v);
|
void WriteI64BE(int64_t v);
|
||||||
void WriteI64LE(int64_t v);
|
void WriteI64LE(int64_t v);
|
||||||
void WriteF32BE(float v);
|
void WriteF32BE(float v);
|
||||||
void WriteF32LE(float v);
|
void WriteF32LE(float v);
|
||||||
void WriteF64BE(double v);
|
void WriteF64BE(double v);
|
||||||
void WriteF64LE(double v);
|
void WriteF64LE(double v);
|
||||||
void WriteUuid(const Uuid& uuid);
|
void WriteUuid(const Uuid &uuid);
|
||||||
};
|
};
|
||||||
}
|
} // namespace Tesses::Framework::Streams
|
||||||
@@ -1,28 +1,46 @@
|
|||||||
|
/*
|
||||||
|
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
|
#pragma once
|
||||||
#include "Stream.hpp"
|
#include "Stream.hpp"
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
namespace Tesses::Framework::Streams
|
namespace Tesses::Framework::Streams {
|
||||||
{
|
class FileStream : public Stream {
|
||||||
class FileStream : public Stream {
|
bool canRead;
|
||||||
bool canRead;
|
bool canWrite;
|
||||||
bool canWrite;
|
bool canSeek;
|
||||||
bool canSeek;
|
bool owns;
|
||||||
bool owns;
|
FILE *f;
|
||||||
FILE* f;
|
void SetMode(std::string mode);
|
||||||
void SetMode(std::string mode);
|
|
||||||
public:
|
public:
|
||||||
FileStream(std::filesystem::path p, std::string mode);
|
FileStream(std::filesystem::path p, std::string mode);
|
||||||
FileStream(FILE* f, bool owns, std::string mode , bool canSeek=true);
|
FileStream(FILE *f, bool owns, std::string mode, bool canSeek = true);
|
||||||
size_t Read(uint8_t* buff, size_t sz);
|
size_t Read(uint8_t *buff, size_t sz);
|
||||||
size_t Write(const uint8_t* buff, size_t sz);
|
size_t Write(const uint8_t *buff, size_t sz);
|
||||||
bool EndOfStream();
|
bool EndOfStream();
|
||||||
bool CanRead();
|
bool CanRead();
|
||||||
bool CanWrite();
|
bool CanWrite();
|
||||||
bool CanSeek();
|
bool CanSeek();
|
||||||
int64_t GetPosition();
|
int64_t GetPosition();
|
||||||
void Flush();
|
void Flush();
|
||||||
void Seek(int64_t pos, SeekOrigin whence);
|
void Seek(int64_t pos, SeekOrigin whence);
|
||||||
~FileStream();
|
~FileStream();
|
||||||
void Close();
|
void Close();
|
||||||
};
|
};
|
||||||
}
|
} // namespace Tesses::Framework::Streams
|
||||||
@@ -1,22 +1,40 @@
|
|||||||
|
/*
|
||||||
|
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
|
#pragma once
|
||||||
#include "Stream.hpp"
|
#include "Stream.hpp"
|
||||||
namespace Tesses::Framework::Streams
|
namespace Tesses::Framework::Streams {
|
||||||
{
|
class MemoryStream : public Stream {
|
||||||
class MemoryStream : public Stream {
|
std::vector<uint8_t> buffer;
|
||||||
std::vector<uint8_t> buffer;
|
size_t offset;
|
||||||
size_t offset;
|
bool writable;
|
||||||
bool writable;
|
|
||||||
public:
|
public:
|
||||||
MemoryStream(bool isWritable);
|
MemoryStream(bool isWritable);
|
||||||
std::vector<uint8_t>& GetBuffer();
|
std::vector<uint8_t> &GetBuffer();
|
||||||
size_t Read(uint8_t* buff, size_t sz);
|
size_t Read(uint8_t *buff, size_t sz);
|
||||||
size_t Write(const uint8_t* buff, size_t sz);
|
size_t Write(const uint8_t *buff, size_t sz);
|
||||||
bool CanRead();
|
bool CanRead();
|
||||||
bool CanWrite();
|
bool CanWrite();
|
||||||
bool CanSeek();
|
bool CanSeek();
|
||||||
int64_t GetLength();
|
int64_t GetLength();
|
||||||
int64_t GetPosition();
|
int64_t GetPosition();
|
||||||
void Seek(int64_t pos, SeekOrigin whence);
|
void Seek(int64_t pos, SeekOrigin whence);
|
||||||
void Close();
|
void Close();
|
||||||
};
|
};
|
||||||
}
|
} // namespace Tesses::Framework::Streams
|
||||||
@@ -1,64 +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
|
#pragma once
|
||||||
#include "Stream.hpp"
|
#include "Stream.hpp"
|
||||||
|
|
||||||
namespace Tesses::Framework::Streams
|
namespace Tesses::Framework::Streams {
|
||||||
{
|
class NetworkStream;
|
||||||
class NetworkStream;
|
|
||||||
|
|
||||||
class TcpServer {
|
class TcpServer {
|
||||||
int32_t sock;
|
int32_t sock;
|
||||||
bool owns;
|
bool owns;
|
||||||
bool valid;
|
bool valid;
|
||||||
public:
|
|
||||||
TcpServer(int32_t backlog);
|
|
||||||
TcpServer(int32_t sock,bool owns);
|
|
||||||
TcpServer(uint16_t port, int32_t backlog);
|
|
||||||
TcpServer(std::string ip, uint16_t port, int32_t backlog);
|
|
||||||
TcpServer(std::string unixPath,int32_t backlog);
|
|
||||||
std::shared_ptr<NetworkStream> GetStream(std::string& ip, uint16_t& port);
|
|
||||||
uint16_t GetPort();
|
|
||||||
~TcpServer();
|
|
||||||
bool IsValid();
|
|
||||||
void Close();
|
|
||||||
};
|
|
||||||
enum class SocketType {
|
|
||||||
ST_IPv4_TCP,
|
|
||||||
ST_IPv4_UDP,
|
|
||||||
ST_IPv6_TCP,
|
|
||||||
ST_IPv6_UDP,
|
|
||||||
ST_UNIX
|
|
||||||
};
|
|
||||||
class NetworkStream : public Stream {
|
|
||||||
int32_t sock;
|
|
||||||
bool owns;
|
|
||||||
bool success;
|
|
||||||
bool endOfStream;
|
|
||||||
public:
|
|
||||||
bool DataAvailable(int timeout=0);
|
|
||||||
bool EndOfStream();
|
|
||||||
bool CanRead();
|
|
||||||
bool CanWrite();
|
|
||||||
NetworkStream(SocketType type);
|
|
||||||
NetworkStream(std::string unixPath,bool isServer);
|
|
||||||
NetworkStream(std::string ipOrFqdn, uint16_t port, bool datagram,bool broadcast,bool supportIPv6);
|
|
||||||
NetworkStream(int32_t sock, bool owns);
|
|
||||||
uint16_t GetPort();
|
|
||||||
void Listen(int32_t backlog);
|
|
||||||
void Bind(std::string ip, uint16_t port);
|
|
||||||
void SetBroadcast(bool bC);
|
|
||||||
void SetReuseAddress(bool reuse);
|
|
||||||
void SetReusePort(bool reuse);
|
|
||||||
void SetMulticastTTL(uint8_t ttl);
|
|
||||||
void SetMulticastMembership(std::string multicastAddress, std::string ifaceIP="0.0.0.0");
|
|
||||||
std::shared_ptr<NetworkStream> Accept(std::string& ip, uint16_t& port);
|
|
||||||
size_t Read(uint8_t* buff, size_t sz);
|
|
||||||
size_t Write(const uint8_t* buff, size_t sz);
|
|
||||||
size_t ReadFrom(uint8_t* buff, size_t sz, std::string& ip, uint16_t& port);
|
|
||||||
size_t WriteTo(const uint8_t* buff, size_t sz, std::string ip, uint16_t port);
|
|
||||||
static std::vector<std::pair<std::string,std::string>> GetIPs(bool ipV6=false);
|
|
||||||
|
|
||||||
~NetworkStream();
|
public:
|
||||||
void SetNoDelay(bool noDelay);
|
TcpServer(int32_t backlog);
|
||||||
void Close();
|
TcpServer(int32_t sock, bool owns);
|
||||||
};
|
TcpServer(uint16_t port, int32_t backlog);
|
||||||
}
|
TcpServer(std::string ip, uint16_t port, int32_t backlog);
|
||||||
|
TcpServer(std::string unixPath, int32_t backlog);
|
||||||
|
std::shared_ptr<NetworkStream> GetStream(std::string &ip, uint16_t &port);
|
||||||
|
uint16_t GetPort();
|
||||||
|
~TcpServer();
|
||||||
|
bool IsValid();
|
||||||
|
void Close();
|
||||||
|
};
|
||||||
|
enum class SocketType {
|
||||||
|
ST_IPv4_TCP,
|
||||||
|
ST_IPv4_UDP,
|
||||||
|
ST_IPv6_TCP,
|
||||||
|
ST_IPv6_UDP,
|
||||||
|
ST_UNIX
|
||||||
|
};
|
||||||
|
class NetworkStream : public Stream {
|
||||||
|
int32_t sock;
|
||||||
|
bool owns;
|
||||||
|
bool success;
|
||||||
|
bool endOfStream;
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool DataAvailable(int timeout = 0);
|
||||||
|
bool EndOfStream();
|
||||||
|
bool CanRead();
|
||||||
|
bool CanWrite();
|
||||||
|
NetworkStream(SocketType type);
|
||||||
|
NetworkStream(std::string unixPath, bool isServer);
|
||||||
|
NetworkStream(std::string ipOrFqdn, uint16_t port, bool datagram,
|
||||||
|
bool broadcast, bool supportIPv6);
|
||||||
|
NetworkStream(int32_t sock, bool owns);
|
||||||
|
uint16_t GetPort();
|
||||||
|
void Listen(int32_t backlog);
|
||||||
|
void Bind(std::string ip, uint16_t port);
|
||||||
|
void SetBroadcast(bool bC);
|
||||||
|
void SetReuseAddress(bool reuse);
|
||||||
|
void SetReusePort(bool reuse);
|
||||||
|
void SetMulticastTTL(uint8_t ttl);
|
||||||
|
void SetMulticastMembership(std::string multicastAddress,
|
||||||
|
std::string ifaceIP = "0.0.0.0");
|
||||||
|
std::shared_ptr<NetworkStream> Accept(std::string &ip, uint16_t &port);
|
||||||
|
size_t Read(uint8_t *buff, size_t sz);
|
||||||
|
size_t Write(const uint8_t *buff, size_t sz);
|
||||||
|
size_t ReadFrom(uint8_t *buff, size_t sz, std::string &ip, uint16_t &port);
|
||||||
|
size_t WriteTo(const uint8_t *buff, size_t sz, std::string ip,
|
||||||
|
uint16_t port);
|
||||||
|
static std::vector<std::pair<std::string, std::string>>
|
||||||
|
GetIPs(bool ipV6 = false);
|
||||||
|
|
||||||
|
~NetworkStream();
|
||||||
|
void SetNoDelay(bool noDelay);
|
||||||
|
void Close();
|
||||||
|
};
|
||||||
|
} // namespace Tesses::Framework::Streams
|
||||||
|
|||||||
@@ -1,30 +1,47 @@
|
|||||||
|
/*
|
||||||
|
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
|
#pragma once
|
||||||
#include "Stream.hpp"
|
#include "Stream.hpp"
|
||||||
namespace Tesses::Framework::Streams
|
namespace Tesses::Framework::Streams {
|
||||||
{
|
struct WindowSize {
|
||||||
struct WindowSize {
|
uint16_t Width;
|
||||||
uint16_t Width;
|
uint16_t Height;
|
||||||
uint16_t Height;
|
uint16_t Columns;
|
||||||
uint16_t Columns;
|
uint16_t Rows;
|
||||||
uint16_t Rows;
|
};
|
||||||
};
|
class PtyStream : public Stream {
|
||||||
class PtyStream : public Stream
|
int socket;
|
||||||
{
|
int64_t pid;
|
||||||
int socket;
|
bool eos;
|
||||||
int64_t pid;
|
WindowSize wS;
|
||||||
bool eos;
|
|
||||||
WindowSize wS;
|
public:
|
||||||
|
PtyStream(WindowSize sz, std::string filename,
|
||||||
public:
|
std::vector<std::string> args, std::vector<std::string> env);
|
||||||
PtyStream(WindowSize sz,std::string filename, std::vector<std::string> args,std::vector<std::string> env);
|
bool EndOfStream();
|
||||||
bool EndOfStream();
|
bool CanRead();
|
||||||
bool CanRead();
|
bool CanWrite();
|
||||||
bool CanWrite();
|
size_t Read(uint8_t *buff, size_t sz);
|
||||||
size_t Read(uint8_t* buff, size_t sz);
|
size_t Write(const uint8_t *buff, size_t sz);
|
||||||
size_t Write(const uint8_t* buff, size_t sz);
|
void Resize(WindowSize sz);
|
||||||
void Resize(WindowSize sz);
|
WindowSize GetWindowSize();
|
||||||
WindowSize GetWindowSize();
|
~PtyStream();
|
||||||
~PtyStream();
|
void Close();
|
||||||
void Close();
|
};
|
||||||
};
|
} // namespace Tesses::Framework::Streams
|
||||||
}
|
|
||||||
@@ -1,31 +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
|
#pragma once
|
||||||
#include "../Common.hpp"
|
#include "../Common.hpp"
|
||||||
namespace Tesses::Framework::Streams
|
namespace Tesses::Framework::Streams {
|
||||||
{
|
enum class SeekOrigin : uint8_t { Begin = 0, Current = 1, End = 2 };
|
||||||
enum class SeekOrigin : uint8_t {
|
class Stream {
|
||||||
Begin=0,
|
public:
|
||||||
Current=1,
|
int32_t ReadByte();
|
||||||
End=2
|
void WriteByte(uint8_t b);
|
||||||
};
|
virtual bool EndOfStream();
|
||||||
class Stream {
|
virtual size_t Read(uint8_t *buff, size_t sz);
|
||||||
public:
|
virtual size_t Write(const uint8_t *buff, size_t sz);
|
||||||
int32_t ReadByte();
|
size_t ReadBlock(uint8_t *buff, size_t sz);
|
||||||
void WriteByte(uint8_t b);
|
void WriteBlock(const uint8_t *buff, size_t sz);
|
||||||
virtual bool EndOfStream();
|
virtual bool CanRead();
|
||||||
virtual size_t Read(uint8_t* buff, size_t sz);
|
virtual bool CanWrite();
|
||||||
virtual size_t Write(const uint8_t* buff, size_t sz);
|
virtual bool CanSeek();
|
||||||
size_t ReadBlock(uint8_t* buff, size_t sz);
|
virtual int64_t GetPosition();
|
||||||
void WriteBlock(const uint8_t* buff, size_t sz);
|
virtual int64_t GetLength();
|
||||||
virtual bool CanRead();
|
virtual void Flush();
|
||||||
virtual bool CanWrite();
|
virtual void Seek(int64_t pos, SeekOrigin whence);
|
||||||
virtual bool CanSeek();
|
void CopyTo(std::shared_ptr<Stream> strm, size_t buffSize = 1024);
|
||||||
virtual int64_t GetPosition();
|
void CopyToLimit(std::shared_ptr<Stream> strm, uint64_t len,
|
||||||
virtual int64_t GetLength();
|
size_t buffSize = 1024);
|
||||||
virtual void Flush();
|
virtual void Close();
|
||||||
virtual void Seek(int64_t pos, SeekOrigin whence);
|
virtual ~Stream();
|
||||||
void CopyTo(std::shared_ptr<Stream> strm, size_t buffSize=1024);
|
};
|
||||||
void CopyToLimit(std::shared_ptr<Stream> strm,uint64_t len, size_t buffSize=1024);
|
} // namespace Tesses::Framework::Streams
|
||||||
virtual void Close();
|
|
||||||
virtual ~Stream();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,49 +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
|
#pragma once
|
||||||
|
#include "Args.hpp"
|
||||||
|
#include "BitTorrent/TorrentFile.hpp"
|
||||||
|
#include "Crypto/ClientTLSStream.hpp"
|
||||||
|
#include "Crypto/Crypto.hpp"
|
||||||
#include "Date/Date.hpp"
|
#include "Date/Date.hpp"
|
||||||
#include "Http/HttpServer.hpp"
|
#include "Filesystem/FSHelpers.hpp"
|
||||||
#include "Http/HttpClient.hpp"
|
#include "Filesystem/LocalFS.hpp"
|
||||||
#include "Http/FileServer.hpp"
|
#include "Filesystem/MountableFilesystem.hpp"
|
||||||
#include "Http/CallbackServer.hpp"
|
#include "Filesystem/NullFilesystem.hpp"
|
||||||
#include "Http/MountableServer.hpp"
|
#include "Filesystem/RelativeFilesystem.hpp"
|
||||||
#include "Http/ContentDisposition.hpp"
|
#include "Filesystem/SubdirFilesystem.hpp"
|
||||||
#include "Http/ChangeableServer.hpp"
|
#include "HiddenField.hpp"
|
||||||
#include "Http/CGIServer.hpp"
|
|
||||||
#include "Http/BasicAuthServer.hpp"
|
#include "Http/BasicAuthServer.hpp"
|
||||||
|
#include "Http/CGIServer.hpp"
|
||||||
|
#include "Http/CallbackServer.hpp"
|
||||||
|
#include "Http/ChangeableServer.hpp"
|
||||||
|
#include "Http/ContentDisposition.hpp"
|
||||||
|
#include "Http/FileServer.hpp"
|
||||||
|
#include "Http/HttpClient.hpp"
|
||||||
|
#include "Http/HttpServer.hpp"
|
||||||
|
#include "Http/MountableServer.hpp"
|
||||||
#include "Http/RouteServer.hpp"
|
#include "Http/RouteServer.hpp"
|
||||||
#include "Streams/FileStream.hpp"
|
#include "Lazy.hpp"
|
||||||
#include "Streams/MemoryStream.hpp"
|
#include "Mail/Smtp.hpp"
|
||||||
#include "Streams/NetworkStream.hpp"
|
#include "Platform/Environment.hpp"
|
||||||
|
#include "Platform/Process.hpp"
|
||||||
|
#include "Random.hpp"
|
||||||
|
#include "Serialization/Bencode.hpp"
|
||||||
|
#include "Serialization/BitConverter.hpp"
|
||||||
|
#include "Serialization/Json.hpp"
|
||||||
|
#include "Serialization/SQLite.hpp"
|
||||||
#include "Streams/BufferedStream.hpp"
|
#include "Streams/BufferedStream.hpp"
|
||||||
#include "Streams/ByteReader.hpp"
|
#include "Streams/ByteReader.hpp"
|
||||||
#include "Streams/ByteWriter.hpp"
|
#include "Streams/ByteWriter.hpp"
|
||||||
#include "TextStreams/StreamReader.hpp"
|
#include "Streams/FileStream.hpp"
|
||||||
#include "TextStreams/StreamWriter.hpp"
|
#include "Streams/MemoryStream.hpp"
|
||||||
|
#include "Streams/NetworkStream.hpp"
|
||||||
|
#include "Text/HeaderGenerator.hpp"
|
||||||
|
#include "Text/StringConverter.hpp"
|
||||||
#include "TextStreams/StdIOReader.hpp"
|
#include "TextStreams/StdIOReader.hpp"
|
||||||
#include "TextStreams/StdIOWriter.hpp"
|
#include "TextStreams/StdIOWriter.hpp"
|
||||||
|
#include "TextStreams/StreamReader.hpp"
|
||||||
|
#include "TextStreams/StreamWriter.hpp"
|
||||||
#include "TextStreams/StringReader.hpp"
|
#include "TextStreams/StringReader.hpp"
|
||||||
#include "TextStreams/StringWriter.hpp"
|
#include "TextStreams/StringWriter.hpp"
|
||||||
#include "Text/StringConverter.hpp"
|
|
||||||
#include "Text/HeaderGenerator.hpp"
|
|
||||||
#include "Threading/Thread.hpp"
|
|
||||||
#include "Threading/Mutex.hpp"
|
#include "Threading/Mutex.hpp"
|
||||||
|
#include "Threading/Thread.hpp"
|
||||||
#include "Threading/ThreadPool.hpp"
|
#include "Threading/ThreadPool.hpp"
|
||||||
#include "Filesystem/LocalFS.hpp"
|
#include "Console.hpp"
|
||||||
#include "Filesystem/SubdirFilesystem.hpp"
|
|
||||||
#include "Filesystem/NullFilesystem.hpp"
|
|
||||||
#include "Filesystem/MountableFilesystem.hpp"
|
|
||||||
#include "Filesystem/RelativeFilesystem.hpp"
|
|
||||||
#include "Filesystem/FSHelpers.hpp"
|
|
||||||
#include "Crypto/ClientTLSStream.hpp"
|
|
||||||
#include "Crypto/Crypto.hpp"
|
|
||||||
#include "Lazy.hpp"
|
|
||||||
#include "Mail/Smtp.hpp"
|
|
||||||
#include "HiddenField.hpp"
|
|
||||||
#include "Serialization/Json.hpp"
|
|
||||||
#include "Serialization/SQLite.hpp"
|
|
||||||
#include "Serialization/Bencode.hpp"
|
|
||||||
#include "Platform/Environment.hpp"
|
|
||||||
#include "Platform/Process.hpp"
|
|
||||||
#include "Serialization/BitConverter.hpp"
|
|
||||||
#include "Args.hpp"
|
|
||||||
#include "BitTorrent/TorrentFile.hpp"
|
|
||||||
#include "Random.hpp"
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user