This commit is contained in:
qingjiao 2025-12-29 09:14:01 +08:00
commit 524dc412af
21 changed files with 2216 additions and 0 deletions

8
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

2
.idea/WebSocket.iml Normal file
View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />

259
.idea/editor.xml Normal file
View File

@ -0,0 +1,259 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="BackendCodeEditorSettings">
<option name="/Default/CodeInspection/GeneratedCode/GeneratedCodeRegions/=Component_0020Designer_0020generated_0020code/@EntryIndexedValue" value="Component Designer generated code" type="string" />
<option name="/Default/CodeInspection/GeneratedCode/GeneratedCodeRegions/=Designer_0020generated_0020code/@EntryIndexedValue" value="Designer generated code" type="string" />
<option name="/Default/CodeInspection/GeneratedCode/GeneratedCodeRegions/=Web_0020Form_0020Designer_0020generated_0020code/@EntryIndexedValue" value="Web Form Designer generated code" type="string" />
<option name="/Default/CodeInspection/GeneratedCode/GeneratedCodeRegions/=Windows_0020Form_0020Designer_0020generated_0020code/@EntryIndexedValue" value="Windows Form Designer generated code" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CDeclarationWithImplicitIntType/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CommentTypo/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConstevalIfIsAlwaysConstant/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppAbstractClassWithoutSpecifier/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppAbstractFinalClass/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppAbstractVirtualFunctionCallInCtor/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppAccessSpecifierWithNoDeclarations/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppAwaiterTypeIsNotClass/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBooleanIncrementExpression/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatBadCode/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatLegacyCode/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatMixedArgs/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatTooFewArgs/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatTooManyArgs/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCStyleCast/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCVQualifierCanNotBeAppliedToReference/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassCanBeFinal/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassIsIncomplete/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassNeedsConstructorBecauseOfUninitializedMember/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCompileTimeConstantCanBeReplacedWithBooleanConstant/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppConceptNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppConditionalExpressionCanBeSimplified/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppConstParameterInDeclaration/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppConstValueFunctionReturnType/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCoroutineCallResolveError/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAArrayIndexOutOfBounds/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAConstantConditions/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAConstantFunctionResult/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAConstantParameter/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFADeletedPointer/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAEndlessLoop/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAInfiniteRecursion/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAInvalidatedMemory/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFALocalValueEscapesFunction/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFALocalValueEscapesScope/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFALoopConditionNotUpdated/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAMemoryLeak/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFANotInitializedField/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFANullDereference/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFATimeOver/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAUnreachableCode/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAUnreachableFunctionCall/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAUnreadVariable/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDFAUnusedValue/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclarationHidesLocal/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclarationHidesUncapturedLocal/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclarationSpecifierWithoutDeclarators/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclaratorDisambiguatedAsFunction/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclaratorNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeclaratorUsedBeforeInitialization/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefaultCaseNotHandledInSwitchStatement/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefaultInitializationWithNoUserConstructor/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefaultIsUsedAsIdentifier/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDefaultedSpecialMemberFunctionIsImplicitlyDeleted/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeletingVoidPointer/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDependentTemplateWithoutTemplateKeyword/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDependentTypeWithoutTypenameKeyword/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeprecatedEntity/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeprecatedOverridenMethod/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDeprecatedRegisterStorageClassSpecifier/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDereferenceOperatorLimitExceeded/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDiscardedPostfixOperatorResult/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDoxygenSyntaxError/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDoxygenUndocumentedParameter/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppDoxygenUnresolvedReference/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEmptyDeclaration/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceCVQualifiersOrder/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceCVQualifiersPlacement/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceDoStatementBraces/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceForStatementBraces/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceFunctionDeclarationStyle/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceIfStatementBraces/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceNestedNamespacesStyle/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceOverridingDestructorStyle/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceOverridingFunctionStyle/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceTypeAliasCodeStyle/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnforceWhileStatementBraces/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEntityAssignedButNoRead/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEntityUsedOnlyInUnevaluatedContext/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEnumeratorNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEqualOperandsInBinaryExpression/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppEvaluationFailure/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppExplicitSpecializationInNonNamespaceScope/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppExpressionWithoutSideEffects/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFinalFunctionInFinalClass/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFinalNonOverridingVirtualFunction/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppForLoopCanBeReplacedWithWhile/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppForwardEnumDeclarationWithoutUnderlyingType/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFunctionDoesntReturnValue/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFunctionIsNotImplemented/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFunctionResultShouldBeUsed/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppFunctionalStyleCast/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppHeaderHasBeenAlreadyIncluded/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppHiddenFunction/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppHidingFunction/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIdenticalOperandsInBinaryExpression/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIfCanBeReplacedByConstexprIf/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppImplicitDefaultConstructorNotAvailable/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIncompatiblePointerConversion/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIncompleteSwitchStatement/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppInconsistentNaming/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIntegralToPointerConversion/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppInvalidLineContinuation/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppJoinDeclarationAndAssignment/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLambdaCaptureNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLocalVariableMayBeConst/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLocalVariableMightNotBeInitialized/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLocalVariableWithNonTrivialDtorIsNeverUsed/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLongFloat/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMemberFunctionMayBeConst/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMemberFunctionMayBeStatic/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMemberInitializersOrder/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMismatchedClassTags/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMissingIncludeGuard/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMissingKeywordThrow/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppModulePartitionWithSeveralPartitionUnits/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtAddressOfClassRValue/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtBindingRValueToLvalueReference/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtCopyElisionInCopyInitDeclarator/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtDoubleUserConversionInCopyInit/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtNotInitializedStaticConstLocalVar/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMsExtReinterpretCastFromNullptr/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMultiCharacterLiteral/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMultiCharacterWideLiteral/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMustBePublicVirtualToImplementInterface/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMutableSpecifierOnReferenceMember/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNoDiscardExpression/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNodiscardFunctionWithoutReturnValue/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNonExceptionSafeResourceAcquisition/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNonExplicitConversionOperator/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNonExplicitConvertingConstructor/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNonInlineFunctionDefinitionInHeaderFile/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNonInlineVariableDefinitionInHeaderFile/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppNotAllPathsReturnValue/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppObjectMemberMightNotBeInitialized/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppOutParameterMustBeWritten/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppParameterMayBeConst/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppParameterMayBeConstPtrOrRef/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppParameterNamesMismatch/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppParameterNeverUsed/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPassValueParameterByConstReference/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPointerConversionDropsQualifiers/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPointerToIntegralConversion/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPolymorphicClassWithNonVirtualPublicDestructor/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPossiblyErroneousEmptyStatements/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPossiblyUninitializedMember/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPossiblyUnintendedObjectSlicing/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrecompiledHeaderIsNotIncluded/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrecompiledHeaderNotFound/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrintfBadFormat/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrintfExtraArg/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrintfMissedArg/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrintfRiskyFormat/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppPrivateSpecialMemberFunctionIsNotImplemented/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRangeBasedForIncompatibleReference/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedefinitionOfDefaultArgumentInOverrideFunction/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantAccessSpecifier/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantBaseClassAccessSpecifier/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantBaseClassInitializer/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantBooleanExpressionArgument/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantCastExpression/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantComplexityInComparison/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantConditionalExpression/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantConstSpecifier/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantControlFlowJump/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantDereferencingAndTakingAddress/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantElaboratedTypeSpecifier/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantElseKeyword/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantElseKeywordInsideCompoundStatement/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantEmptyDeclaration/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantEmptyStatement/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantExportKeyword/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantFwdClassOrEnumSpecifier/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantInlineSpecifier/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantLambdaParameterList/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantMemberInitializer/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantNamespaceDefinition/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantParentheses/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantQualifier/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantQualifierADL/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantStaticSpecifierOnMemberAllocationFunction/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantStaticSpecifierOnThreadLocalLocalVariable/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantTemplateArguments/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantTemplateKeyword/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantTypenameKeyword/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantVoidArgumentList/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRedundantZeroInitializerInAggregateInitialization/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppReinterpretCastFromVoidPtr/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppRemoveRedundantBraces/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppReplaceMemsetWithZeroInitialization/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppReplaceTieWithStructuredBinding/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppReturnNoValueInNonVoidFunction/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppSmartPointerVsMakeFunction/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppSomeObjectMembersMightNotBeInitialized/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppSpecialFunctionWithoutNoexceptSpecification/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStaticAssertFailure/@EntryIndexedValue" value="ERROR" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStaticDataMemberInUnnamedStruct/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStaticSpecifierOnAnonymousNamespaceMember/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStringLiteralToCharPointerConversion/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTabsAreDisallowed/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateArgumentsCanBeDeduced/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateParameterNeverUsed/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateParameterShadowing/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppThrowExpressionCanBeReplacedWithRethrow/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTooWideScope/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTooWideScopeInitStatement/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTypeAliasNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUninitializedDependentBaseClass/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUninitializedNonStaticDataMember/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnionMemberOfReferenceType/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnmatchedPragmaEndRegionDirective/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnmatchedPragmaRegionDirective/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnnamedNamespaceInHeaderFile/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnnecessaryWhitespace/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnsignedZeroComparison/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnusedIncludeDirective/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAlgorithmWithCount/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAssociativeContains/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAuto/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAutoForNumeric/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseElementsView/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseEraseAlgorithm/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseFamiliarTemplateSyntaxForGenericLambdas/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseRangeAlgorithm/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseStdSize/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseStructuredBinding/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseTypeTraitAlias/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUserDefinedLiteralSuffixDoesNotStartWithUnderscore/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUsingResultOfAssignmentAsCondition/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppVariableCanBeMadeConstexpr/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppVirtualFunctionCallInsideCtor/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppVirtualFunctionInFinalClass/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppVolatileParameterInDeclaration/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppWarningDirective/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppWrongIncludesOrder/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppWrongSlashesInIncludeDirective/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppZeroConstantCanBeReplacedWithNullptr/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppZeroValuedExpressionUsedAsNullPointer/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=IdentifierTypo/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=IfStdIsConstantEvaluatedCanBeReplaced/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=StdIsConstantEvaluatedWillAlwaysEvaluateToConstant/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=StringLiteralTypo/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ANONYMOUS_METHOD_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/CASE_BLOCK_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/EXPORT_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INVOCABLE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/OTHER_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/REQUIRES_EXPRESSION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TYPE_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
</component>
</project>

7
.idea/misc.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakePythonSetting">
<option name="pythonIntegrationState" value="YES" />
</component>
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/WebSocket.iml" filepath="$PROJECT_DIR$/.idea/WebSocket.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

10
CMakeLists.txt Normal file
View File

@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 4.0)
project(WebSocket)
set(CMAKE_CXX_STANDARD 98)
add_executable(WebSocket
main.cpp
WebSocket/CCWebSocket.cpp
WebSocket/CCWebSocket.h
)

View File

@ -0,0 +1,9 @@
#include "CCWebSocket.h"
CTL::WebSocket::WebSocket() {
}
CTL::WebSocket::~WebSocket() {
}

14
WebSocket/CCWebSocket.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef CC_WEBSOCKET_H
#define CC_WEBSOCKET_H
namespace CTL{
class WebSocket {
public:
WebSocket();
~WebSocket();
};
}
#endif

196
WebSocket/base64.cpp Normal file
View File

@ -0,0 +1,196 @@
/*
* Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/* ====================================================================
* Copyright (c) 1995-1999 The Apache Group. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the Apache Group
* for use in the Apache HTTP server project (http://www.apache.org/)."
*
* 4. The names "Apache Server" and "Apache Group" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the Apache Group
* for use in the Apache HTTP server project (http://www.apache.org/)."
*
* THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Group and was originally based
* on public domain software written at the National Center for
* Supercomputing Applications, University of Illinois, Urbana-Champaign.
* For more information on the Apache Group and the Apache HTTP server
* project, please see <http://www.apache.org/>.
*
*/
/* Base64 encoder/decoder. Originally Apache file ap_base64.c
*/
#include <string.h>
#include "base64.h"
/* aaaack but it's fast and const should make it shared text page. */
static const unsigned char pr2six[256] =
{
/* ASCII table */
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64,
64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
};
int Base64decode_len(const char *bufcoded)
{
const auto *bufin = reinterpret_cast<const unsigned char *>(bufcoded);
while (pr2six[*bufin++] <= 63) {}
int nbytesdecoded = ((bufin - reinterpret_cast<const unsigned char *>(bufcoded) - 1 + 3) / 4) * 3;
return nbytesdecoded + 1;
}
int Base64decode(char *bufplain, const char *bufcoded)
{
const auto *bufin = reinterpret_cast<const unsigned char *>(bufcoded);
auto *bufout = reinterpret_cast<unsigned char *>(bufplain);
int nprbytes = 0;
// Calculate the number of padding bytes
while (pr2six[*bufin++] <= 63) {}
nprbytes = (bufin - reinterpret_cast<const unsigned char *>(bufcoded)) - 1;
int nbytesdecoded = ((nprbytes + 3) / 4) * 3;
bufin = reinterpret_cast<const unsigned char *>(bufcoded);
// Decode the Base64 data in chunks of 4 bytes
while (nprbytes > 4) {
*bufout++ = (pr2six[*bufin] << 2) | (pr2six[bufin[1]] >> 4);
*bufout++ = (pr2six[bufin[1]] << 4) | (pr2six[bufin[2]] >> 2);
*bufout++ = (pr2six[bufin[2]] << 6) | pr2six[bufin[3]];
bufin += 4;
nprbytes -= 4;
}
// Handle the remaining bytes
if (nprbytes > 1) {
*bufout++ = (pr2six[*bufin] << 2) | (pr2six[bufin[1]] >> 4);
}
if (nprbytes > 2) {
*bufout++ = (pr2six[bufin[1]] << 4) | (pr2six[bufin[2]] >> 2);
}
if (nprbytes > 3) {
*bufout++ = (pr2six[bufin[2]] << 6) | pr2six[bufin[3]];
}
*bufout = '\0';
nbytesdecoded -= (4 - nprbytes) & 3;
return nbytesdecoded;
}
static const char basis_64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
int Base64encode_len(int len)
{
return ((len + 2) / 3 * 4) + 1;
}
int Base64encode(char *encoded, const char *string, int len)
{
int i;
char *p;
p = encoded;
for (i = 0; i < len - 2; i += 3) {
*p++ = basis_64[(string[i] >> 2) & 0x3F];
*p++ = basis_64[((string[i] & 0x3) << 4) |
((int) (string[i + 1] & 0xF0) >> 4)];
*p++ = basis_64[((string[i + 1] & 0xF) << 2) |
((int) (string[i + 2] & 0xC0) >> 6)];
*p++ = basis_64[string[i + 2] & 0x3F];
}
if (i < len) {
*p++ = basis_64[(string[i] >> 2) & 0x3F];
if (i == (len - 1)) {
*p++ = basis_64[((string[i] & 0x3) << 4)];
*p++ = '=';
}
else {
*p++ = basis_64[((string[i] & 0x3) << 4) |
((int) (string[i + 1] & 0xF0) >> 4)];
*p++ = basis_64[((string[i + 1] & 0xF) << 2)];
}
*p++ = '=';
}
*p++ = '\0';
return p - encoded;
}

101
WebSocket/base64.h Normal file
View File

@ -0,0 +1,101 @@
/*
* Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/* ====================================================================
* Copyright (c) 1995-1999 The Apache Group. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the Apache Group
* for use in the Apache HTTP server project (http://www.apache.org/)."
*
* 4. The names "Apache Server" and "Apache Group" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the Apache Group
* for use in the Apache HTTP server project (http://www.apache.org/)."
*
* THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Group and was originally based
* on public domain software written at the National Center for
* Supercomputing Applications, University of Illinois, Urbana-Champaign.
* For more information on the Apache Group and the Apache HTTP server
* project, please see <http://www.apache.org/>.
*
*/
#ifndef _BASE64_H_
#define _BASE64_H_
#ifdef __cplusplus
extern "C" {
#endif
int Base64encode_len(int len);
int Base64encode(char * coded_dst, const char *plain_src,int len_plain_src);
int Base64decode_len(const char * coded_src);
int Base64decode(char * plain_dst, const char *coded_src);
#ifdef __cplusplus
}
#endif
#endif //_BASE64_H_

27
WebSocket/sha1.h Normal file
View File

@ -0,0 +1,27 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_SHA1_H_
#define BASE_SHA1_H_
#include <string>
namespace SHA1 {
// These functions perform SHA-1 operations.
static const size_t kSHA1Length = 20; // Length in bytes of a SHA-1 hash.
// Computes the SHA-1 hash of the input string |str| and returns the full
// hash.
std::string SHA1HashString(const std::string& str);
// Computes the SHA-1 hash of the |len| bytes in |data| and puts the hash
// in |hash|. |hash| must be kSHA1Length bytes long.
void SHA1HashBytes(const unsigned char* data, size_t len,
unsigned char* hash);
} // namespace base
#endif // BASE_SHA1_H_

213
WebSocket/sha1_portable.cpp Normal file
View File

@ -0,0 +1,213 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sha1.h"
#include <stdint.h>
#include <string.h>
namespace SHA1 {
// Implementation of SHA-1. Only handles data in byte-sized blocks,
// which simplifies the code a fair bit.
// Identifier names follow notation in FIPS PUB 180-3, where you'll
// also find a description of the algorithm:
// http://csrc.nist.gov/publications/fips/fips180-3/fips180-3_final.pdf
// Usage example:
//
// SecureHashAlgorithm sha;
// while(there is data to hash)
// sha.Update(moredata, size of data);
// sha.Final();
// memcpy(somewhere, sha.Digest(), 20);
//
// to reuse the instance of sha, call sha.Init();
// TODO(jhawkins): Replace this implementation with a per-platform
// implementation using each platform's crypto library. See
// http://crbug.com/47218
class SecureHashAlgorithm {
public:
SecureHashAlgorithm() { Init(); }
static const int kDigestSizeBytes;
void Init();
void Update(const void* data, size_t nbytes);
void Final();
// 20 bytes of message digest.
const unsigned char* Digest() const {
return reinterpret_cast<const unsigned char*>(H);
}
private:
void Pad();
void Process();
uint32_t A, B, C, D, E;
uint32_t H[5];
union {
uint32_t W[80];
uint8_t M[64];
};
uint32_t cursor;
uint32_t l;
};
static inline uint32_t f(uint32_t t, uint32_t B, uint32_t C, uint32_t D) {
if (t < 20) {
return (B & C) | ((~B) & D);
} else if (t < 40) {
return B ^ C ^ D;
} else if (t < 60) {
return (B & C) | (B & D) | (C & D);
} else {
return B ^ C ^ D;
}
}
static inline uint32_t S(uint32_t n, uint32_t X) {
return (X << n) | (X >> (32-n));
}
static inline uint32_t K(uint32_t t) {
if (t < 20) {
return 0x5a827999;
} else if (t < 40) {
return 0x6ed9eba1;
} else if (t < 60) {
return 0x8f1bbcdc;
} else {
return 0xca62c1d6;
}
}
static inline void swapends(uint32_t* t) {
*t = ((*t & 0xff000000) >> 24) |
((*t & 0xff0000) >> 8) |
((*t & 0xff00) << 8) |
((*t & 0xff) << 24);
}
const int SecureHashAlgorithm::kDigestSizeBytes = 20;
void SecureHashAlgorithm::Init() {
A = 0;
B = 0;
C = 0;
D = 0;
E = 0;
cursor = 0;
l = 0;
H[0] = 0x67452301;
H[1] = 0xefcdab89;
H[2] = 0x98badcfe;
H[3] = 0x10325476;
H[4] = 0xc3d2e1f0;
}
void SecureHashAlgorithm::Final() {
Pad();
Process();
for (int t = 0; t < 5; ++t)
swapends(&H[t]);
}
void SecureHashAlgorithm::Update(const void* data, size_t nbytes) {
const uint8_t* d = reinterpret_cast<const uint8_t*>(data);
while (nbytes--) {
M[cursor++] = *d++;
if (cursor >= 64)
Process();
l += 8;
}
}
void SecureHashAlgorithm::Pad() {
M[cursor++] = 0x80;
if (cursor > 64-8) {
// pad out to next block
while (cursor < 64)
M[cursor++] = 0;
Process();
}
while (cursor < 64-4)
M[cursor++] = 0;
M[64-4] = (l & 0xff000000) >> 24;
M[64-3] = (l & 0xff0000) >> 16;
M[64-2] = (l & 0xff00) >> 8;
M[64-1] = (l & 0xff);
}
void SecureHashAlgorithm::Process() {
uint32_t t;
// Each a...e corresponds to a section in the FIPS 180-3 algorithm.
// a.
//
// W and M are in a union, so no need to memcpy.
// memcpy(W, M, sizeof(M));
for (t = 0; t < 16; ++t)
swapends(&W[t]);
// b.
for (t = 16; t < 80; ++t)
W[t] = S(1, W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16]);
// c.
A = H[0];
B = H[1];
C = H[2];
D = H[3];
E = H[4];
// d.
for (t = 0; t < 80; ++t) {
uint32_t TEMP = S(5, A) + f(t, B, C, D) + E + W[t] + K(t);
E = D;
D = C;
C = S(30, B);
B = A;
A = TEMP;
}
// e.
H[0] += A;
H[1] += B;
H[2] += C;
H[3] += D;
H[4] += E;
cursor = 0;
}
std::string SHA1HashString(const std::string& str) {
char hash[SecureHashAlgorithm::kDigestSizeBytes];
SHA1HashBytes(reinterpret_cast<const unsigned char*>(str.c_str()),
str.length(), reinterpret_cast<unsigned char*>(hash));
return std::string(hash, SecureHashAlgorithm::kDigestSizeBytes);
}
void SHA1HashBytes(const unsigned char* data, size_t len,
unsigned char* hash) {
SecureHashAlgorithm sha;
sha.Update(data, len);
sha.Final();
memcpy(hash, sha.Digest(), SecureHashAlgorithm::kDigestSizeBytes);
}
} // namespace base

View File

@ -0,0 +1,21 @@
#include "string_helper.h"
#include <algorithm>
#include <cctype>
std::string& strHelper::trim(std::string& str, const char thechar)
{
if (str.empty()) {
return str;
}
std::string::size_type pos = str.find_first_not_of(thechar);
if (pos != std::string::npos) {
str.erase(0, pos);
}
pos = str.find_last_of(thechar);
if (pos != std::string::npos) {
str.erase(str.find_last_not_of(thechar) + 1);
}
return str;
}

24
WebSocket/string_helper.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef STRING_HELPER_HEAD_FILE_
#define STRING_HELPER_HEAD_FILE_
#include <string>
class strHelper {
public:
// split the string to array
template <typename TYPE>
static int splitStr(TYPE& list,
const std::string& str, const char* delim);
// trim the specify char
static std::string& trim(std::string& str, const char thechar = ' ');
// convert type T to string
template <typename T, typename S>
static const T valueOf(const S &a);
};
#include "string_helper.inl"
#endif /* STRING_HELPER_HEAD_FILE_ */

View File

@ -0,0 +1,57 @@
/* ***********************************************
* string helper inline file
*/
#include <string.h>
#include <sstream>
template <typename TYPE> inline
int strHelper::splitStr(TYPE& list,
const std::string& str, const char* delim)
{
if (str.empty())
return 0;
if (delim == NULL){
list.push_back(str);
return 1;
}
unsigned int size = strlen(delim);
std::string::size_type prepos = 0;
std::string::size_type pos = 0;
int count = 0;
for(;;)
{
pos = str.find(delim, pos);
if (pos == std::string::npos){
if (prepos < str.size()){
list.push_back(str.substr(prepos));
count++;
}
break;
}
list.push_back(str.substr(prepos, pos-prepos));
count++;
pos += size;
prepos = pos;
}
return count;
}
template <typename T, typename S> inline
const T strHelper::valueOf(const S& a)
{
std::stringstream s;
T t;
s << a ;
s >> t;
return t;
}

236
WebSocket/ws_endpoint.cpp Normal file
View File

@ -0,0 +1,236 @@
/*
* The MIT License (MIT)
* Copyright(c) 2020 BeikeSong
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "ws_endpoint.h"
WebSocketEndpoint::WebSocketEndpoint()
{
//networklayer_ = nt;
nt_write_cb_ = NULL;
ws_handshake_completed_ = false;
}
WebSocketEndpoint::WebSocketEndpoint(nt_write_cb write_cb)
{
//networklayer_ = nt;
nt_write_cb_ = write_cb;
ws_handshake_completed_ = false;
}
WebSocketEndpoint::~WebSocketEndpoint() {}
int32_t WebSocketEndpoint::process(const char *readbuf, int32_t size)
{
return from_wire(readbuf, size);
}
int32_t WebSocketEndpoint::process(const char *readbuf, int32_t size, nt_write_cb write_cb, void *work_data)
{
if (write_cb == NULL || work_data == NULL)
{
std::cout << "WebSocketEndpoint - Attention: write cb is NULL! It will skip current read buf!" << std::endl;
return 0;
}
nt_write_cb_ = write_cb;
nt_work_data_ = work_data;
return from_wire(readbuf, size);
}
int32_t WebSocketEndpoint::from_wire(const char *readbuf, int32_t size)
{
fromwire_buf_.append(readbuf, size);
std::cout<< "WebSocketEndpoint - set fromwire_buf, current length:"<<fromwire_buf_.length()<<std::endl;
while (true)
{
int64_t nrcv = parse_packet(fromwire_buf_);
if (nrcv > 0)
{ // for next one
// clear used data
int64_t n_used = fromwire_buf_.getoft();
std::cout<< "WebSocketEndpoint - fromwire_buf: used data:"<<n_used <<" nrcv:"<<nrcv
<<" length:"<<fromwire_buf_.length()<<std::endl;
fromwire_buf_.erase(nrcv);
fromwire_buf_.resetoft();
if (fromwire_buf_.length() == 0)
{
return nrcv;
}
else
{
continue;
}
}
else if (nrcv == 0)
{ // contueue recving
fromwire_buf_.resetoft();
break;
}
else
{
return -1;
}
}
// make it happy
return 0;
}
int32_t WebSocketEndpoint::to_wire(const char *writebuf, int64_t size)
{
//networklayer_->toWire(writebuf,size);
if (nt_write_cb_ == NULL || nt_work_data_ == NULL || writebuf == NULL || size <= 0)
{
return 0;
}
nt_write_cb_(const_cast<char *>(writebuf), size, nt_work_data_);
return 0;
}
int64_t WebSocketEndpoint::parse_packet(ByteBuffer &input)
{
WebSocketPacket wspacket;
if (!ws_handshake_completed_)
{
uint32_t nstatus = 0;
nstatus = wspacket.recv_handshake(input);
if (nstatus != 0)
{
return -1;
}
if (wspacket.get_hs_length() == 0)
{
// not enough data for a handshake message
// continue recving data
return 0;
}
std::string hs_rsp;
wspacket.pack_handshake_rsp(hs_rsp);
to_wire(hs_rsp.c_str(), hs_rsp.length());
ws_handshake_completed_ = true;
std::cout << "WebsocketEndpont - handshake successful!" << std::endl
<< std::endl;
return wspacket.get_hs_length();
}
else
{
uint64_t ndf = wspacket.recv_dataframe(input);
// continue recving data until get an entire frame
if (ndf == 0)
{
return 0;
}
if (ndf > 0xFFFFFFFF)
{
std::cout << "Attention:frame data length exceeds the max value of a uint32_t varable!" << std::endl;
}
ByteBuffer &payload = wspacket.get_payload();
message_data_.append(payload.bytes(), payload.length());
// now, we have a entire frame
if (wspacket.get_fin() == 1)
{
process_message_data(wspacket, message_data_);
message_data_.erase(message_data_.length());
message_data_.resetoft();
return ndf;
}
return ndf;
}
return -1;
}
int32_t WebSocketEndpoint::process_message_data(WebSocketPacket &packet, ByteBuffer &frame_payload)
{
//#ifdef _SHOW_OPCODE_
switch (packet.get_opcode())
{
case WebSocketPacket::WSOpcode_Continue:
// add your process code here
std::cout << "WebSocketEndpoint - recv a Continue opcode." << std::endl;
user_defined_process(packet, frame_payload);
break;
case WebSocketPacket::WSOpcode_Text:
// add your process code here
std::cout << "WebSocketEndpoint - recv a Text opcode." << std::endl;
user_defined_process(packet, frame_payload);
break;
case WebSocketPacket::WSOpcode_Binary:
// add your process code here
std::cout << "WebSocketEndpoint - recv a Binary opcode." << std::endl;
user_defined_process(packet, frame_payload);
break;
case WebSocketPacket::WSOpcode_Close:
// add your process code here
std::cout << "WebSocketEndpoint - recv a Close opcode." << std::endl;
user_defined_process(packet, frame_payload);
break;
case WebSocketPacket::WSOpcode_Ping:
// add your process code here
std::cout << "WebSocketEndpoint - recv a Ping opcode." << std::endl;
user_defined_process(packet, frame_payload);
break;
case WebSocketPacket::WSOpcode_Pong:
// add your process code here
std::cout << "WebSocketEndpoint - recv a Pong opcode." << std::endl;
user_defined_process(packet, frame_payload);
break;
default:
std::cout << "WebSocketEndpoint - recv an unknown opcode." << std::endl;
break;
}
//#endif
return 0;
}
// we directly return what we get from client
// user could modify this function
int32_t WebSocketEndpoint::user_defined_process(WebSocketPacket &packet, ByteBuffer &frame_payload)
{
// print received websocket payload from client
std::string str_recv(frame_payload.bytes(), frame_payload.length());
std::cout << "WebSocketEndpoint - received data, length:" << str_recv.length()
<< " ,content:" << str_recv.c_str() << std::endl;
WebSocketPacket wspacket;
// set FIN and opcode
wspacket.set_fin(1);
wspacket.set_opcode(packet.get_opcode());
// set payload data
wspacket.set_payload(frame_payload.bytes(), frame_payload.length());
ByteBuffer output;
// pack a websocket data frame
wspacket.pack_dataframe(output);
// send to client
to_wire(output.bytes(), output.length());
return 0;
}

79
WebSocket/ws_endpoint.h Normal file
View File

@ -0,0 +1,79 @@
/*
* The MIT License (MIT)
* Copyright(c) 2020 BeikeSong
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* define a websocket server/client wrapper class
*/
#ifndef _WS_SVR_HANDLER_H_
#define _WS_SVR_HANDLER_H_
#include <iostream>
#include <vector>
#include <string>
#include <stdint.h>
#include "ws_packet.h"
typedef void (*nt_write_cb)(char * buf,int64_t size, void* wd);
class WebSocketEndpoint
{
public:
WebSocketEndpoint( nt_write_cb write_cb);
WebSocketEndpoint();
virtual ~WebSocketEndpoint();
public:
// start a websocket endpoint process.
virtual int32_t process(const char * readbuf, int32_t size);
// start a websocket endpoint process. Also we register a write callback function
virtual int32_t process(const char * readbuf, int32_t size, nt_write_cb write_cb, void* work_data);
// receive data from wire until we get an entire handshake or frame data packet
virtual int32_t from_wire(const char * readbuf, int32_t size);
// try to find and parse a websocket packet
virtual int64_t parse_packet(ByteBuffer& input);
// process message data
// users should rewrite this function
virtual int32_t process_message_data(WebSocketPacket& packet, ByteBuffer& frame_payload);
// user defined process
virtual int32_t user_defined_process(WebSocketPacket& packet, ByteBuffer& frame_payload);
// send data to wire
virtual int32_t to_wire(const char * writebuf, int64_t size);
private:
bool ws_handshake_completed_;
ByteBuffer fromwire_buf_;
ByteBuffer message_data_;
nt_write_cb nt_write_cb_;
void * nt_work_data_;
};
#endif//_WS_SVR_HANDLER_H_

567
WebSocket/ws_packet.cpp Normal file
View File

@ -0,0 +1,567 @@
/*
* The MIT License (MIT)
* Copyright(c) 2020 BeikeSong
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "sha1.h"
#include "base64.h"
#include "ws_packet.h"
#include "string_helper.h"
#define SP " "
#define EOL "\r\n"
#define DEFAULT_HTTP_VERSION "HTTP/1.1"
WebSocketPacket::WebSocketPacket()
{
fin_ = 0;
rsv1_ = 0;
rsv2_ = 0;
rsv3_ = 0;
opcode_ = 0;
mask_ = 0;
length_type_ = 0;
masking_key_[4] = {0};
payload_length_ = 0;
}
int32_t WebSocketPacket::recv_handshake(ByteBuffer &input)
{
if (input.length() > WS_MAX_HANDSHAKE_FRAME_SIZE)
{
return WS_MAX_HANDSHAKE_FRAME_SIZE;
}
std::string inputstr(input.bytes(), input.length());
int32_t frame_size = fetch_hs_element(inputstr);
if (frame_size <= 0)
{
//continue recving data;
input.resetoft();
return 0;
}
const bool A = get_param("Upgrade") != "websocket";
const bool B = get_param("Connection").find("Upgrade") == std::string::npos;
const bool C = get_param("Sec-WebSocket-Version") != "13";
const bool D = get_param("Sec-WebSocket-Key").empty();
if (A || B || C || D){
input.resetoft();
return WS_ERROR_INVALID_HANDSHAKE_PARAMS;
}
hs_length_ = frame_size;
input.skip_x(hs_length_);
return 0;
}
int32_t WebSocketPacket::pack_handshake_rsp(std::string &hs_rsp)
{
std::string magic_key = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
std::string raw_key = get_param("Sec-WebSocket-Key") + magic_key;
std::string sha1_key = SHA1::SHA1HashString(raw_key);
char accept_key[128] = {0};
Base64encode(accept_key, sha1_key.c_str(), sha1_key.length());
std::ostringstream sstream;
sstream << "HTTP/1.1 101 Switching Protocols" << EOL;
sstream << "Connection: upgrade" << EOL;
sstream << "Upgrade: websocket" << EOL;
sstream << "Sec-WebSocket-Accept: " << accept_key << EOL;
if (get_param("Sec-WebSocket-Protocol") != "")
{
sstream << "Sec-WebSocket-Protocol: chat" << EOL;
}
sstream << EOL;
hs_rsp = sstream.str();
return 0;
}
uint64_t WebSocketPacket::recv_dataframe(ByteBuffer &input)
{
int header_size = fetch_frame_info(input);
//std::cout << "WebSocketPacket: header size: " << header_size
// << " payload_length_: " << payload_length_ << " input.length: " << input.length() << std::endl;
if (payload_length_ + header_size > input.length())
{
// buffer size is not enough, so we continue recving data
// std::cout << "WebSocketPacket: recv_dataframe: continue recving data." << std::endl;
input.resetoft();
return 0;
}
fetch_payload(input);
// std::cout << "WebSocketPacket: received data with header size: " << header_size << " payload size:" << payload_length_
// << " input oft size:" << input.getoft() << std::endl;
//return payload_length_;
return input.getoft();
}
int32_t WebSocketPacket::fetch_frame_info(ByteBuffer &input)
{
// FIN, opcode
uint8_t onebyte = 0;
input.read_bytes_x((char *)&onebyte, 1);
fin_ = onebyte >> 7;
opcode_ = onebyte & 0x7F;
// payload length
input.read_bytes_x((char *)&onebyte, 1);
mask_ = onebyte >> 7 & 0x01;
length_type_ = onebyte & 0x7F;
if (length_type_ < 126)
{
payload_length_ = length_type_;
}
else if (length_type_ == 126)
{
/*
uint16_t len = 0;
input.read_bytes_x((char *)&len, 2);
len = (len << 8) | (len >>8 & 0xFF);
payload_length_ = len;
*/
uint16_t len = 0;
uint8_t array[2] = {0};
input.read_bytes_x(reinterpret_cast<char *>(array), 2);
len = static_cast<uint16_t>(array[0] << 8) | static_cast<uint16_t>(array[1]);
payload_length_ = len;
}
else if (length_type_ == 127)
{
// if you don't have ntohll
uint8_t array[8] = {0};
input.read_bytes_x(reinterpret_cast<char *>(array), 8);
if (payload_length_ > 0xFFFFFFFF)
{
//std::cout >>
}
}
else
{
}
// masking key
if (mask_ == 1)
{
input.read_bytes_x((char *)masking_key_, 4);
}
// return header size
return input.getoft();
}
int32_t WebSocketPacket::fetch_payload(ByteBuffer &input)
{
char real = 0;
if (mask_ == 1)
{
for (uint64_t i = 0; i < payload_length_; i++)
{
input.read_bytes_x(&real, 1);
real = real ^ masking_key_[i % 4];
payload_.append(&real, 1);
}
}
else
{
if(payload_length_ > 0){
payload_.append(input.curat(), payload_length_);
input.skip_x(payload_length_);
}
}
return 0;
}
int32_t WebSocketPacket::pack_dataframe(ByteBuffer &output)
{
uint8_t onebyte = 0;
onebyte |= (fin_ << 7);
onebyte |= (rsv1_ << 6);
onebyte |= (rsv2_ << 5);
onebyte |= (rsv3_ << 4);
onebyte |= (opcode_ & 0x0F);
output.append((char *)&onebyte, 1);
onebyte = 0;
//set mask flag
onebyte = onebyte | (mask_ << 7);
uint8_t length_type = get_length_type();
if (length_type < 126)
{
onebyte |= payload_length_;
output.append((char *)&onebyte, 1);
}
else if (length_type == 126)
{
onebyte |= length_type;
output.append((char *)&onebyte, 1);
// also can use htons
onebyte = (payload_length_ >> 8) & 0xFF;
output.append((char *)&onebyte, 1);
onebyte = payload_length_ & 0xFF;
output.append((char *)&onebyte, 1);
}
else if (length_type == 127)
{
onebyte |= length_type;
output.append((char *)&onebyte, 1);
// also can use htonll if you have it
onebyte = (payload_length_ >> 56) & 0xFF;
output.append((char *)&onebyte, 1);
onebyte = (payload_length_ >> 48) & 0xFF;
output.append((char *)&onebyte, 1);
onebyte = (payload_length_ >> 40) & 0xFF;
output.append((char *)&onebyte, 1);
onebyte = (payload_length_ >> 32) & 0xFF;
output.append((char *)&onebyte, 1);
onebyte = (payload_length_ >> 24) & 0xFF;
output.append((char *)&onebyte, 1);
onebyte = (payload_length_ >> 16) & 0xFF;
output.append((char *)&onebyte, 1);
onebyte = (payload_length_ >> 8) & 0xFF;
output.append((char *)&onebyte, 1);
onebyte = payload_length_ & 0XFF;
output.append((char *)&onebyte, 1);
}
else
{
return -1;
}
if (mask_ == 1)
{
char value = 0;
// save masking key
output.append((char *)masking_key_, 4);
// std::cout << "WebSocketPacket: send data with header size: " << output.length()
// << " payload size:" << payload_length_ << std::endl;
for (uint64_t i = 0; i < payload_length_; i++)
{
payload_.read_bytes_x(&value, 1);
value = value ^ masking_key_[i % 4];
output.append(&value, 1);
}
}
else
{
// std::cout << "WebSocketPacket: send data with header size: " << output.length()
// << " payload size:" << payload_length_ << std::endl<<std::endl;
output.append(payload_.bytes(), payload_.length());
}
return 0;
}
int32_t WebSocketPacket::fetch_hs_element(const std::string &msg)
{
// two EOLs mean a completed http1.1 request line
std::string::size_type endpos = msg.find(std::string(EOL) + EOL);
if (endpos == std::string::npos)
{
return -1;
}
//can't find end of request line in current, and we continue receiving data
std::vector<std::string> lines;
if (strHelper::splitStr<std::vector<std::string> >
(lines, msg.substr(0, endpos), EOL) < 2)
{
return -1;
}
std::vector<std::string>::iterator it = lines.begin();
while ((it != lines.end()) && strHelper::trim(*it).empty())
{
++it;
};
std::vector<std::string> reqLineParams;
if (strHelper::splitStr<std::vector<std::string> >
(reqLineParams, *it, SP) < 3)
{
return -1;
}
mothod_ = strHelper::trim(reqLineParams[0]);
uri_ = strHelper::trim(reqLineParams[1]);
version_ = strHelper::trim(reqLineParams[2]);
for (++it; it != lines.end(); ++it)
{
// header fields format:
// field name: values
std::string::size_type pos = it->find_first_of(":");
if (pos == std::string::npos)
continue; // invalid line
std::string k = it->substr(0, pos);
std::string v = it->substr(pos + 1);
if (strHelper::trim(k).empty())
{
continue;
}
if (strHelper::trim(v).empty())
{
continue;
}
params_[k] = v;
// std::cout << "handshake element k:" << k.c_str() << " v:" << v.c_str() << std::endl;
}
return endpos + 4;
}
void WebSocketPacket::set_payload(const char *buf, uint64_t size)
{
payload_.append(buf, size);
payload_length_ = payload_.length();
}
const uint8_t WebSocketPacket::get_length_type()
{
if (payload_length_ < 126)
{
return (uint8_t)payload_length_;
}
else if (payload_length_ >= 126 && payload_length_ <= 0xFFFF)
{
return 126;
}
else
{
return 127;
}
}
const uint8_t WebSocketPacket::get_header_size()
{
int header_size = 0;
if (get_length_type() < 126)
{
header_size = 2;
}
else if (get_length_type() == 126)
{
header_size = 4;
}
else if (get_length_type() == 127)
{
header_size = 2 + 8;
}
if (mask_ == 1)
{
header_size += 4;
}
return header_size;
}
bool WebSocketPacket::ValidateSecWebSocketAccept(const std::string &key, const std::string &accept) {
std::string magic_key = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
std::string raw_key = key + magic_key;
std::string sha1_key = SHA1::SHA1HashString(raw_key);
char accept_key[128] = {0};
Base64encode(accept_key, sha1_key.c_str(), sha1_key.length());
return accept == accept_key;
}
/*
* ByteBuffer
*
*/
ByteBuffer::ByteBuffer()
{
oft = 0;
}
ByteBuffer::~ByteBuffer()
{
}
bool ByteBuffer::require(int require)
{
int len = length();
return require <= len - oft;
}
char *ByteBuffer::curat()
{
return (length() == 0) ? NULL : &data.at(oft);
}
int ByteBuffer::getoft()
{
return oft;
}
bool ByteBuffer::skip_x(int size)
{
if (require(size))
{
oft += size;
return true;
}
else
{
return false;
}
}
bool ByteBuffer::read_bytes_x(char *cb, int size)
{
if (require(size))
{
memcpy(cb, &data.at(oft), size);
oft += size;
return true;
}
else
{
return false;
}
}
void ByteBuffer::resetoft()
{
oft = 0;
}
void ByteBuffer::clear() {
data.clear();
resetoft();
}
void ByteBuffer::assign(char* buf, const int size) {
clear();
data.assign(buf, buf + size);
}
bool ByteBuffer::operator==(const ByteBuffer &other) const {
return data == other.data;
}
bool ByteBuffer::operator!=(const ByteBuffer &other) const {
return data != other.data;
}
void ByteBuffer::operator+=(const ByteBuffer &other) {
data.insert(data.end(), other.data.begin(), other.data.end());
}
void ByteBuffer::operator-=(const ByteBuffer &other) {
data.erase(std::remove_if(data.begin(), data.end(), [&other](const CTL::Byte &byte) {
return std::find(other.data.begin(), other.data.end(),
static_cast<char>(byte)) != other.data.end(); // 显式转换为char类型
}), data.end());
}
int ByteBuffer::length()
{
const int len = static_cast<int>(data.size());
//srs_assert(len >= 0);
return len;
}
char *ByteBuffer::bytes()
{
return (length() == 0) ? nullptr : &data.at(0);
}
void ByteBuffer::erase(int size)
{
if (size <= 0)
{
return;
}
if (size >= length())
{
data.clear();
return;
}
data.erase(data.begin(), data.begin() + size);
}
void ByteBuffer::append(const char *bytes, int size)
{
//srs_assert(size > 0);
data.insert(data.end(), bytes, bytes + size);
}
void ByteBuffer::append(const ByteBuffer &other) {
data.insert(data.end(), other.data.begin(), other.data.end());
}
void ByteBuffer::append(const CTL::ByteArray &other) {
data.insert(data.end(), other.begin(), other.end());
}
void ByteBuffer::append(const CCVector<CTL::Byte> &other) {
data.insert(data.end(), other.begin(), other.end());
}
void ByteBuffer::append(const CCList<CTL::Byte> &other) {
data.insert(data.end(), other.begin(), other.end());
}
void ByteBuffer::append(std::initializer_list<CTL::Byte> initList) {
data.insert(data.end(), initList.begin(), initList.end());
}
void ByteBuffer::append(const std::string &other) {
data.insert(data.end(), other.begin(), other.end());
}
void ByteBuffer::operator=(const char *other) {
data.assign(other, other + strlen(other));
}
ByteBuffer::ByteBuffer(const ByteBuffer &other) {
data = other.data;
}
ByteBuffer::ByteBuffer(const CTL::ByteArray &other) {
data.assign(other.begin(), other.end());
}
ByteBuffer::ByteBuffer(const CCVector<CTL::Byte> &other) {
data.assign(other.begin(), other.end());
}
ByteBuffer::ByteBuffer(const CCList<CTL::Byte> &other) {
data.assign(other.begin(), other.end());
}
ByteBuffer::ByteBuffer(std::initializer_list<CTL::Byte> initList) {
data.assign(initList.begin(), initList.end());
}

366
WebSocket/ws_packet.h Normal file
View File

@ -0,0 +1,366 @@
/*
* The MIT License (MIT)
* Copyright(c) 2020 BeikeSong
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef _WS_PACKET_H_
#define _WS_PACKET_H_
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <sstream>
#include <stdint.h>
#include "string_helper.h"
#include "CCByteArray.h"
class ByteBuffer;
#define WS_ERROR_INVALID_HANDSHAKE_PARAMS 10070
#define WS_ERROR_INVALID_HANDSHAKE_FRAME 10071
// max handshake frame = 100k
#define WS_MAX_HANDSHAKE_FRAME_SIZE 1024 * 1000
/**
* a simple buffer class base on vector
*/
class ByteBuffer
{
private:
std::vector<char> data;
// current offset in bytes from data.at(0) (data beginning)
uint32_t oft;
public:
ByteBuffer();
ByteBuffer(const ByteBuffer &other);
ByteBuffer(const CTL::ByteArray &other);
ByteBuffer(const CCVector<CTL::Byte> &other);
ByteBuffer(const CCList<CTL::Byte> &other);
ByteBuffer(std::initializer_list<CTL::Byte> initList);
virtual ~ByteBuffer();
public:
/**
* get the length of buffer. empty if zero.
* @remark assert length() is not negative.
*/
virtual int length();
/**
* get the buffer bytes.
* @return the bytes, NULL if empty.
*/
virtual char *bytes();
/**
* erase size of bytes from begin.
* @param size to erase size of bytes from the beginning.
* clear if size greater than or equals to length()
* @remark ignore size is not positive.
*/
virtual void erase(int size);
/**
* append specified bytes to buffer.
* @param size the size of bytes
* @remark assert size is positive.
*/
virtual void append(const char *bytes, int size);
/**
*
* @param other
*/
void append(const ByteBuffer &other);
/**
*
* @param other
*/
void append(const CTL::ByteArray &other);
/**
*
* @param other
*/
void append(const CCVector<CTL::Byte> &other);
/**
*
* @param other
*/
void append(const CCList<CTL::Byte> &other);
/**
*
* @param initList
*/
void append(std::initializer_list<CTL::Byte> initList);
/**
*
* @param other
*/
void append(const std::string& other);
void operator=(const char* other);
/**
* tell current position return char * p=data.at(oft)
*/
virtual char *curat();
/**
* get current oft value
*/
virtual int getoft();
/**
* check if we have enough size in vector
*/
virtual bool require(int size);
/**
* move size bytes from cur position
*/
virtual bool skip_x(int size);
/**
* read size bytes and move cur positon
*/
virtual bool read_bytes_x(char *cb, int size);
/**
* reset cur position to the beginning of vector
*/
virtual void resetoft();
virtual void clear();
virtual void assign(char* buf, int size);
bool operator == (const ByteBuffer& other) const;
/**
*
* @param other
* @return truefalse
*/
bool operator != (const ByteBuffer& other) const;
/**
*
* @param other
*/
void operator += (const ByteBuffer& other);
/**
*
* @param other
*/
void operator -= (const ByteBuffer& other);
};
class WebSocketPacket
{
public:
WebSocketPacket();
virtual ~WebSocketPacket(){};
public:
enum WSPacketType : uint8_t
{
WSPacketType_HandShake = 1,
WSPacketType_DataFrame,
};
enum WSOpcodeType : uint8_t
{
WSOpcode_Continue = 0x0,
WSOpcode_Text = 0x1,
WSOpcode_Binary = 0x2,
WSOpcode_Close = 0x8,
WSOpcode_Ping = 0x9,
WSOpcode_Pong = 0xA,
};
public:
//
/**
* try to find and parse a handshake packet
* @param input input buffer
* @param size size of input buffer
* @return errcode, 0 means successful
*
*/
virtual int32_t recv_handshake(ByteBuffer &input);
// fetch handshake element
virtual int32_t fetch_hs_element(const std::string &msg);
/**
* pack a hand shake response packet
* @return errcode
* @param hs_rsp: a resp handshake packet, NULL if empty.
*/
virtual int32_t pack_handshake_rsp(std::string &hs_rsp);
/**
* try to find and parse a data frame
* @return an entire frame size
* 0 means we need to continue recving data,
* and >0 means find get a frame successfule
*/
virtual uint64_t recv_dataframe(ByteBuffer &input);
/**
* get frame info
* @return header size
*/
virtual int32_t fetch_frame_info(ByteBuffer &input);
/**
* get frame payload
* @return only payload size
*/
virtual int32_t fetch_payload(ByteBuffer &input);
/**
* pack a websocket data frame
* @return 0 means successful
*/
virtual int32_t pack_dataframe(ByteBuffer &input);
public:
const uint8_t get_fin() { return fin_; }
const uint8_t get_rsv1() { return rsv1_; }
const uint8_t get_rsv2() { return rsv2_; }
const uint8_t get_rsv3() { return rsv3_; }
const uint8_t get_opcode() { return opcode_; }
const uint8_t get_mask() { return mask_; }
const uint64_t get_payload_length() { return payload_length_; }
void set_fin(uint8_t fin) { fin_ = fin; }
void set_rsv1(uint8_t rsv1) { rsv1_ = rsv1; }
void set_rsv2(uint8_t rsv2) { rsv2_ = rsv2; }
void set_rsv3(uint8_t rsv3) { rsv3_ = rsv3; }
void set_opcode(uint8_t opcode) { opcode_ = opcode; }
void set_mask(uint8_t mask) { mask_ = mask; }
void set_payload_length(uint64_t length) { payload_length_ = length; }
void set_payload(const char *buf, uint64_t size);
const uint8_t get_length_type();
const uint8_t get_header_size();
ByteBuffer &get_payload() { return payload_; }
/**
* sec-websocket-accept
* @return
* @param key sec-websocket-key
* @param accept sec-websocket-accept
* */
static bool ValidateSecWebSocketAccept(const std::string& key, const std::string& accept);
public:
// get handshake packet length
const uint32_t get_hs_length() { return hs_length_; }
public:
const std::string mothod(void) const
{
return mothod_;
}
void mothod(const std::string &m)
{
mothod_ = m;
}
const std::string uri(void) const
{
return uri_;
}
void uri(const std::string &u)
{
uri_ = u;
}
const std::string version(void) const
{
return version_;
}
void version(const std::string &v)
{
version_ = v;
}
bool has_param(const std::string &name) const
{
return params_.find(name) != params_.end();
}
const std::string get_param(const std::string &name) const
{
std::map<std::string, std::string>::const_iterator it =
params_.find(name);
if (it != params_.end())
{
return it->second;
}
return std::string();
}
template <typename T>
const T get_param(const std::string &name) const
{
return strHelper::valueOf<T, std::string>(get_param(name));
}
void set_param(const std::string &name, const std::string &v)
{
params_[name] = v;
}
template <typename T>
void set_param(const std::string &name, const T &v)
{
params_[name] = strHelper::valueOf<std::string, T>(v);
}
private:
std::string mothod_;
std::string uri_;
std::string version_;
std::map<std::string, std::string> params_;
private:
uint8_t fin_;
uint8_t rsv1_;
uint8_t rsv2_;
uint8_t rsv3_;
uint8_t opcode_;
uint8_t mask_;
uint8_t length_type_;
uint8_t masking_key_[4];
uint64_t payload_length_;
private:
uint32_t hs_length_;
public:
ByteBuffer payload_;
};
#endif //_WS_PACKET_H_

6
main.cpp Normal file
View File

@ -0,0 +1,6 @@
#include <iostream>
int main() {
return 0;
}