mirror of
https://github.com/aziascreations/BakaShrot.git
synced 2026-11-23 20:58:46 +01:00
Moved the PureBasic version to OldSource/, Started the Rust rewrite in Source/
The rewrite's plan and decisions are in revamp.md. Steps 0 to 10 are done: the workspace and checks, bakashrot-proto, bakashrot-pki and bakashrot-cert, bakashrot-config, bakashrot-storage (schema v9), the server and the client library (every request but replication's, attachments and retention included), the C DLL with its C, PureBasic and Python bindings, and the bakashrot tool. Step 11 (replication) is next. OldSource/ is the old implementation, kept building and passing as the reference. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RwFeVTGs2SsufaH6zquzcb
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
IDE Options = PureBasic 6.41 beta 2 (Windows - x64)
|
||||
CursorPosition = 4
|
||||
EnableXP
|
||||
DPIAware
|
||||
CompileSourceDirectory
|
||||
EnableCompileCount = 0
|
||||
EnableBuildCount = 0
|
||||
@@ -0,0 +1,380 @@
|
||||
;{- Code Header
|
||||
; ==- Basic Info -================================
|
||||
; Name: BakaShrot_Client_Prototypes.pbi
|
||||
; Version: 0.0.1
|
||||
; Author: Herwin Bozet (NibblePoker)
|
||||
;
|
||||
; ==- Compatibility -=============================
|
||||
; Tested compiler versions:
|
||||
; * PureBasic 5.73 LTS (Windows x64, Linux x64)
|
||||
; * PureBasic 6.40 C Backend (Windows x64)
|
||||
; * PureBasic 6.41 (Linux x64)
|
||||
; * PureBasic 6.41 C Backend (Linux x64)
|
||||
;
|
||||
; ==- Links -=====================================
|
||||
; GitHub: https://github.com/aziascreations/BakaShrot
|
||||
;}
|
||||
|
||||
; ============================================================================
|
||||
; BakaShrot Client DLL - Prototypes
|
||||
;
|
||||
; Include this in an app to use BakaShrot_Client.dll:
|
||||
; XIncludeFile "BakaShrot_Client_Prototypes.pbi"
|
||||
; If BakaShrot_LoadClient("BakaShrot_Client.dll")
|
||||
; BakaShrot_SetPrivateKey("...")
|
||||
; BakaShrot_SetPublicKey("...")
|
||||
; BakaShrot_SetServerPublicKey("...")
|
||||
; ...
|
||||
; BakaShrot_UnloadClient()
|
||||
; EndIf
|
||||
;
|
||||
; See BakaShrot_Client.pbi for what each function does.
|
||||
; The string functions are mapped to the DLL's W (UTF-16) variants.
|
||||
; After a failed call, BakaShrot_GetLastError() tells why: the codes and
|
||||
; what to do about each are in BakaShrot_ErrorCodes.pbi, next to this file
|
||||
; (included below), BakaShrot_ErrorName() names them.
|
||||
; ============================================================================
|
||||
|
||||
XIncludeFile "BakaShrot_ErrorCodes.pbi"
|
||||
|
||||
|
||||
PrototypeC.i BakaShrot_SetPrivateKey_Prototype(PrivateKey.p-unicode)
|
||||
PrototypeC.i BakaShrot_SetPublicKey_Prototype(PublicKey.p-unicode)
|
||||
PrototypeC.i BakaShrot_SetServerPublicKey_Prototype(PublicKey.p-unicode)
|
||||
PrototypeC.i BakaShrot_SetNodeId_Prototype(NodeId.l)
|
||||
PrototypeC.i BakaShrot_SetNode_Prototype(Node.p-unicode)
|
||||
PrototypeC.i BakaShrot_Connect_Prototype(Host.p-unicode, Port.l)
|
||||
PrototypeC.i BakaShrot_IsConnected_Prototype()
|
||||
PrototypeC.i BakaShrot_Disconnect_Prototype()
|
||||
PrototypeC.q BakaShrot_PushMessage_Prototype(JsonData.p-unicode)
|
||||
PrototypeC.q BakaShrot_PushMessageTo_Prototype(Topic.p-unicode, JsonData.p-unicode)
|
||||
PrototypeC.i BakaShrot_GetLatestMessage_Prototype(TopicId.l, NodeId.l)
|
||||
PrototypeC.i BakaShrot_GetLatestMessageOf_Prototype(Topic.p-unicode, Node.p-unicode)
|
||||
PrototypeC.q BakaShrot_GetMessageId_Prototype()
|
||||
PrototypeC.q BakaShrot_GetMessagePushedAt_Prototype()
|
||||
PrototypeC.i BakaShrot_GetMessageData_Prototype(*Buffer, BufferSize.i)
|
||||
PrototypeC.l BakaShrot_GetMessageTopicId_Prototype()
|
||||
PrototypeC.l BakaShrot_GetMessageNodeId_Prototype()
|
||||
PrototypeC.i BakaShrot_GetMessageTopic_Prototype(*Buffer, BufferSize.i)
|
||||
PrototypeC.i BakaShrot_GetMessageNode_Prototype(*Buffer, BufferSize.i)
|
||||
PrototypeC.l BakaShrot_ResolveTopic_Prototype(Ref.p-unicode)
|
||||
PrototypeC.l BakaShrot_ResolveNode_Prototype(Ref.p-unicode)
|
||||
PrototypeC.i BakaShrot_GetResolvedName_Prototype(*Buffer, BufferSize.i)
|
||||
PrototypeC.l BakaShrot_ListTopics_Prototype()
|
||||
PrototypeC.l BakaShrot_ListNodes_Prototype()
|
||||
PrototypeC.i BakaShrot_GetNamesList_Prototype(*Buffer, BufferSize.i)
|
||||
PrototypeC.i BakaShrot_GetRefusalReason_Prototype(*Buffer, BufferSize.i)
|
||||
PrototypeC.l BakaShrot_GetLastError_Prototype()
|
||||
PrototypeC.i BakaShrot_Query_Prototype(Sql.p-unicode)
|
||||
PrototypeC.i BakaShrot_GetQueryResult_Prototype(*Buffer, BufferSize.i)
|
||||
PrototypeC.l BakaShrot_GetMessages_Prototype(Topic.p-unicode, Node.p-unicode, AfterMessageId.q, Limit.l)
|
||||
PrototypeC.l BakaShrot_GetMessageCount_Prototype()
|
||||
PrototypeC.i BakaShrot_SelectMessage_Prototype(Index.l)
|
||||
PrototypeC.i BakaShrot_HasMoreMessages_Prototype()
|
||||
PrototypeC.q BakaShrot_PushMessageWithFile_Prototype(Topic.p-unicode, JsonData.p-unicode, FilePath.p-unicode)
|
||||
PrototypeC.q BakaShrot_PushMessageWithData_Prototype(Topic.p-unicode, JsonData.p-unicode, *Data, Size.q)
|
||||
PrototypeC.q BakaShrot_SaveAttachment_Prototype(Topic.p-unicode, Node.p-unicode, MessageId.q, FilePath.p-unicode)
|
||||
PrototypeC.q BakaShrot_LoadAttachment_Prototype(Topic.p-unicode, Node.p-unicode, MessageId.q)
|
||||
PrototypeC.q BakaShrot_GetAttachmentData_Prototype(*Buffer, BufferSize.q)
|
||||
PrototypeC.i BakaShrot_FreeAttachmentData_Prototype()
|
||||
PrototypeC.q BakaShrot_GetMessageAttachmentSize_Prototype()
|
||||
PrototypeC.i BakaShrot_IsMessageAttachmentReady_Prototype()
|
||||
|
||||
|
||||
Global BakaShrot_SetPrivateKey.BakaShrot_SetPrivateKey_Prototype
|
||||
Global BakaShrot_SetPublicKey.BakaShrot_SetPublicKey_Prototype
|
||||
Global BakaShrot_SetServerPublicKey.BakaShrot_SetServerPublicKey_Prototype
|
||||
Global BakaShrot_SetNodeId.BakaShrot_SetNodeId_Prototype
|
||||
Global BakaShrot_SetNode.BakaShrot_SetNode_Prototype
|
||||
Global BakaShrot_Connect.BakaShrot_Connect_Prototype
|
||||
Global BakaShrot_IsConnected.BakaShrot_IsConnected_Prototype
|
||||
Global BakaShrot_Disconnect.BakaShrot_Disconnect_Prototype
|
||||
Global BakaShrot_PushMessage.BakaShrot_PushMessage_Prototype
|
||||
Global BakaShrot_PushMessageTo.BakaShrot_PushMessageTo_Prototype
|
||||
Global BakaShrot_GetLatestMessage.BakaShrot_GetLatestMessage_Prototype
|
||||
Global BakaShrot_GetLatestMessageOf.BakaShrot_GetLatestMessageOf_Prototype
|
||||
Global BakaShrot_GetMessageId.BakaShrot_GetMessageId_Prototype
|
||||
Global BakaShrot_GetMessagePushedAt.BakaShrot_GetMessagePushedAt_Prototype
|
||||
Global BakaShrot_GetMessageData.BakaShrot_GetMessageData_Prototype
|
||||
Global BakaShrot_GetMessageTopicId.BakaShrot_GetMessageTopicId_Prototype
|
||||
Global BakaShrot_GetMessageNodeId.BakaShrot_GetMessageNodeId_Prototype
|
||||
Global BakaShrot_GetMessageTopic.BakaShrot_GetMessageTopic_Prototype
|
||||
Global BakaShrot_GetMessageNode.BakaShrot_GetMessageNode_Prototype
|
||||
Global BakaShrot_ResolveTopic.BakaShrot_ResolveTopic_Prototype
|
||||
Global BakaShrot_ResolveNode.BakaShrot_ResolveNode_Prototype
|
||||
Global BakaShrot_GetResolvedName.BakaShrot_GetResolvedName_Prototype
|
||||
Global BakaShrot_ListTopics.BakaShrot_ListTopics_Prototype
|
||||
Global BakaShrot_ListNodes.BakaShrot_ListNodes_Prototype
|
||||
Global BakaShrot_GetNamesList.BakaShrot_GetNamesList_Prototype
|
||||
Global BakaShrot_GetRefusalReason.BakaShrot_GetRefusalReason_Prototype
|
||||
Global BakaShrot_GetLastError.BakaShrot_GetLastError_Prototype
|
||||
Global BakaShrot_Query.BakaShrot_Query_Prototype
|
||||
Global BakaShrot_GetQueryResult.BakaShrot_GetQueryResult_Prototype
|
||||
Global BakaShrot_GetMessages.BakaShrot_GetMessages_Prototype
|
||||
Global BakaShrot_GetMessageCount.BakaShrot_GetMessageCount_Prototype
|
||||
Global BakaShrot_SelectMessage.BakaShrot_SelectMessage_Prototype
|
||||
Global BakaShrot_HasMoreMessages.BakaShrot_HasMoreMessages_Prototype
|
||||
Global BakaShrot_PushMessageWithFile.BakaShrot_PushMessageWithFile_Prototype
|
||||
Global BakaShrot_PushMessageWithData.BakaShrot_PushMessageWithData_Prototype
|
||||
Global BakaShrot_SaveAttachment.BakaShrot_SaveAttachment_Prototype
|
||||
Global BakaShrot_LoadAttachment.BakaShrot_LoadAttachment_Prototype
|
||||
Global BakaShrot_GetAttachmentData.BakaShrot_GetAttachmentData_Prototype
|
||||
Global BakaShrot_FreeAttachmentData.BakaShrot_FreeAttachmentData_Prototype
|
||||
Global BakaShrot_GetMessageAttachmentSize.BakaShrot_GetMessageAttachmentSize_Prototype
|
||||
Global BakaShrot_IsMessageAttachmentReady.BakaShrot_IsMessageAttachmentReady_Prototype
|
||||
|
||||
Global BakaShrot_ClientLibrary.i = 0
|
||||
|
||||
|
||||
; Unloads the DLL loaded by BakaShrot_LoadClient().
|
||||
Procedure BakaShrot_UnloadClient()
|
||||
If BakaShrot_ClientLibrary
|
||||
CloseLibrary(BakaShrot_ClientLibrary)
|
||||
BakaShrot_ClientLibrary = 0
|
||||
EndIf
|
||||
EndProcedure
|
||||
|
||||
|
||||
; Loads the DLL at DllPath and fills the function pointers above.
|
||||
; Returns #False if the DLL can't be loaded or a function is missing.
|
||||
Procedure.i BakaShrot_LoadClient(DllPath.s)
|
||||
If BakaShrot_ClientLibrary
|
||||
ProcedureReturn #False
|
||||
EndIf
|
||||
|
||||
BakaShrot_ClientLibrary = OpenLibrary(#PB_Any, DllPath)
|
||||
If Not BakaShrot_ClientLibrary
|
||||
ProcedureReturn #False
|
||||
EndIf
|
||||
|
||||
; PureBasic strings are UTF-16, so the W variants are used.
|
||||
BakaShrot_SetPrivateKey = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_SetPrivateKeyW")
|
||||
BakaShrot_SetPublicKey = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_SetPublicKeyW")
|
||||
BakaShrot_SetServerPublicKey = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_SetServerPublicKeyW")
|
||||
BakaShrot_SetNodeId = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_SetNodeId")
|
||||
BakaShrot_SetNode = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_SetNodeW")
|
||||
BakaShrot_Connect = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_ConnectW")
|
||||
BakaShrot_IsConnected = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_IsConnected")
|
||||
BakaShrot_Disconnect = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_Disconnect")
|
||||
BakaShrot_PushMessage = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_PushMessageW")
|
||||
BakaShrot_GetLatestMessage = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_GetLatestMessage")
|
||||
BakaShrot_GetMessageId = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_GetMessageId")
|
||||
BakaShrot_GetMessagePushedAt = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_GetMessagePushedAt")
|
||||
BakaShrot_GetMessageData = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_GetMessageDataW")
|
||||
BakaShrot_GetRefusalReason = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_GetRefusalReasonW")
|
||||
BakaShrot_GetLastError = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_GetLastError")
|
||||
BakaShrot_Query = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_QueryW")
|
||||
BakaShrot_GetQueryResult = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_GetQueryResultW")
|
||||
BakaShrot_PushMessageTo = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_PushMessageToW")
|
||||
BakaShrot_GetLatestMessageOf = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_GetLatestMessageOfW")
|
||||
BakaShrot_GetMessageTopicId = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_GetMessageTopicId")
|
||||
BakaShrot_GetMessageNodeId = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_GetMessageNodeId")
|
||||
BakaShrot_GetMessageTopic = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_GetMessageTopicW")
|
||||
BakaShrot_GetMessageNode = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_GetMessageNodeW")
|
||||
BakaShrot_ResolveTopic = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_ResolveTopicW")
|
||||
BakaShrot_ResolveNode = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_ResolveNodeW")
|
||||
BakaShrot_GetResolvedName = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_GetResolvedNameW")
|
||||
BakaShrot_ListTopics = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_ListTopics")
|
||||
BakaShrot_ListNodes = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_ListNodes")
|
||||
BakaShrot_GetNamesList = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_GetNamesListW")
|
||||
BakaShrot_GetMessages = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_GetMessagesW")
|
||||
BakaShrot_GetMessageCount = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_GetMessageCount")
|
||||
BakaShrot_SelectMessage = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_SelectMessage")
|
||||
BakaShrot_HasMoreMessages = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_HasMoreMessages")
|
||||
BakaShrot_PushMessageWithFile = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_PushMessageWithFileW")
|
||||
BakaShrot_PushMessageWithData = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_PushMessageWithDataW")
|
||||
BakaShrot_SaveAttachment = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_SaveAttachmentW")
|
||||
BakaShrot_LoadAttachment = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_LoadAttachmentW")
|
||||
BakaShrot_GetAttachmentData = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_GetAttachmentData")
|
||||
BakaShrot_FreeAttachmentData = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_FreeAttachmentData")
|
||||
BakaShrot_GetMessageAttachmentSize = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_GetMessageAttachmentSize")
|
||||
BakaShrot_IsMessageAttachmentReady = GetFunction(BakaShrot_ClientLibrary, "BakaShrot_IsMessageAttachmentReady")
|
||||
|
||||
If Not BakaShrot_SetPrivateKey Or Not BakaShrot_SetPublicKey Or Not BakaShrot_SetServerPublicKey Or Not BakaShrot_SetNodeId Or Not BakaShrot_Connect Or Not BakaShrot_IsConnected Or Not BakaShrot_Disconnect
|
||||
BakaShrot_UnloadClient()
|
||||
ProcedureReturn #False
|
||||
EndIf
|
||||
|
||||
If Not BakaShrot_PushMessage Or Not BakaShrot_GetLatestMessage Or Not BakaShrot_GetMessageId Or Not BakaShrot_GetMessagePushedAt Or Not BakaShrot_GetMessageData Or Not BakaShrot_GetRefusalReason Or Not BakaShrot_GetLastError
|
||||
BakaShrot_UnloadClient()
|
||||
ProcedureReturn #False
|
||||
EndIf
|
||||
|
||||
If Not BakaShrot_Query Or Not BakaShrot_GetQueryResult
|
||||
BakaShrot_UnloadClient()
|
||||
ProcedureReturn #False
|
||||
EndIf
|
||||
|
||||
If Not BakaShrot_SetNode Or Not BakaShrot_PushMessageTo Or Not BakaShrot_GetLatestMessageOf Or
|
||||
Not BakaShrot_GetMessageTopicId Or Not BakaShrot_GetMessageNodeId Or Not BakaShrot_GetMessageTopic Or Not BakaShrot_GetMessageNode Or
|
||||
Not BakaShrot_ResolveTopic Or Not BakaShrot_ResolveNode Or Not BakaShrot_GetResolvedName Or
|
||||
Not BakaShrot_ListTopics Or Not BakaShrot_ListNodes Or Not BakaShrot_GetNamesList
|
||||
BakaShrot_UnloadClient()
|
||||
ProcedureReturn #False
|
||||
EndIf
|
||||
|
||||
If Not BakaShrot_GetMessages Or Not BakaShrot_GetMessageCount Or Not BakaShrot_SelectMessage Or Not BakaShrot_HasMoreMessages
|
||||
BakaShrot_UnloadClient()
|
||||
ProcedureReturn #False
|
||||
EndIf
|
||||
|
||||
If Not BakaShrot_PushMessageWithFile Or Not BakaShrot_PushMessageWithData Or Not BakaShrot_SaveAttachment Or Not BakaShrot_LoadAttachment Or Not BakaShrot_GetAttachmentData Or Not BakaShrot_FreeAttachmentData Or Not BakaShrot_GetMessageAttachmentSize Or Not BakaShrot_IsMessageAttachmentReady
|
||||
BakaShrot_UnloadClient()
|
||||
ProcedureReturn #False
|
||||
EndIf
|
||||
|
||||
ProcedureReturn #True
|
||||
EndProcedure
|
||||
|
||||
|
||||
; BakaShrot_GetMessageData() as a string, asks for the size, then copies.
|
||||
Procedure.s BakaShrot_GetMessageDataString()
|
||||
Protected *Buffer, BufferSize.i, Text.s
|
||||
|
||||
BufferSize = BakaShrot_GetMessageData(0, 0)
|
||||
*Buffer = AllocateMemory(BufferSize)
|
||||
If Not *Buffer
|
||||
ProcedureReturn ""
|
||||
EndIf
|
||||
BakaShrot_GetMessageData(*Buffer, BufferSize)
|
||||
Text = PeekS(*Buffer, -1, #PB_Unicode)
|
||||
FreeMemory(*Buffer)
|
||||
|
||||
ProcedureReturn Text
|
||||
EndProcedure
|
||||
|
||||
|
||||
; BakaShrot_GetQueryResult() as a string, asks for the size, then copies.
|
||||
Procedure.s BakaShrot_GetQueryResultString()
|
||||
Protected *Buffer, BufferSize.i, Text.s
|
||||
|
||||
BufferSize = BakaShrot_GetQueryResult(0, 0)
|
||||
*Buffer = AllocateMemory(BufferSize)
|
||||
If Not *Buffer
|
||||
ProcedureReturn ""
|
||||
EndIf
|
||||
BakaShrot_GetQueryResult(*Buffer, BufferSize)
|
||||
Text = PeekS(*Buffer, -1, #PB_Unicode)
|
||||
FreeMemory(*Buffer)
|
||||
|
||||
ProcedureReturn Text
|
||||
EndProcedure
|
||||
|
||||
|
||||
; Calls a string getter of the DLL (*Getter(*Buffer, BufferSize)) and
|
||||
; returns the string: asks for the size, then copies.
|
||||
PrototypeC.i BakaShrot_StringGetter_Prototype(*Buffer, BufferSize.i)
|
||||
Procedure.s BakaShrot_GetString(Getter.BakaShrot_StringGetter_Prototype)
|
||||
Protected *Buffer, BufferSize.i, Text.s
|
||||
|
||||
BufferSize = Getter(0, 0)
|
||||
*Buffer = AllocateMemory(BufferSize)
|
||||
If Not *Buffer
|
||||
ProcedureReturn ""
|
||||
EndIf
|
||||
Getter(*Buffer, BufferSize)
|
||||
Text = PeekS(*Buffer, -1, #PB_Unicode)
|
||||
FreeMemory(*Buffer)
|
||||
|
||||
ProcedureReturn Text
|
||||
EndProcedure
|
||||
|
||||
; BakaShrot_GetMessageTopic/Node() and BakaShrot_GetResolvedName() as strings.
|
||||
Procedure.s BakaShrot_GetMessageTopicString()
|
||||
ProcedureReturn BakaShrot_GetString(BakaShrot_GetMessageTopic)
|
||||
EndProcedure
|
||||
|
||||
Procedure.s BakaShrot_GetMessageNodeString()
|
||||
ProcedureReturn BakaShrot_GetString(BakaShrot_GetMessageNode)
|
||||
EndProcedure
|
||||
|
||||
Procedure.s BakaShrot_GetResolvedNameString()
|
||||
ProcedureReturn BakaShrot_GetString(BakaShrot_GetResolvedName)
|
||||
EndProcedure
|
||||
|
||||
Procedure.s BakaShrot_GetNamesListString()
|
||||
ProcedureReturn BakaShrot_GetString(BakaShrot_GetNamesList)
|
||||
EndProcedure
|
||||
|
||||
|
||||
; BakaShrot_GetRefusalReason() as a string, asks for the size, then copies.
|
||||
Procedure.s BakaShrot_GetRefusalReasonString()
|
||||
Protected *Buffer, BufferSize.i, Text.s
|
||||
|
||||
BufferSize = BakaShrot_GetRefusalReason(0, 0)
|
||||
*Buffer = AllocateMemory(BufferSize)
|
||||
If Not *Buffer
|
||||
ProcedureReturn ""
|
||||
EndIf
|
||||
BakaShrot_GetRefusalReason(*Buffer, BufferSize)
|
||||
Text = PeekS(*Buffer, -1, #PB_Unicode)
|
||||
FreeMemory(*Buffer)
|
||||
|
||||
ProcedureReturn Text
|
||||
EndProcedure
|
||||
|
||||
|
||||
; Usage example. Only compiled when this file is run directly (F5 in the
|
||||
; IDE), not when it's included by an app.
|
||||
; Connects with the identity from the client.ini that Build.ps1 generates,
|
||||
; run it from the Build folder while BakaShrot_Server.exe is running.
|
||||
CompilerIf #PB_Compiler_IsMainFile
|
||||
|
||||
Define PrivateKey.s, PublicKey.s, ServerPublicKey.s, Node.s, ServerHost.s, ServerPort.l
|
||||
|
||||
OpenConsole()
|
||||
|
||||
If Not OpenPreferences("client.ini")
|
||||
PrintN("Failed to open client.ini")
|
||||
End 1
|
||||
EndIf
|
||||
PreferenceGroup("BakaShrot")
|
||||
PrivateKey = ReadPreferenceString("PrivateKey", "")
|
||||
PublicKey = ReadPreferenceString("PublicKey", "")
|
||||
ServerPublicKey = ReadPreferenceString("ServerPublicKey", "")
|
||||
Node = ReadPreferenceString("Node", ReadPreferenceString("NodeId", ""))
|
||||
ServerHost = ReadPreferenceString("ServerHost", "")
|
||||
ServerPort = ReadPreferenceLong("ServerPort", 0)
|
||||
ClosePreferences()
|
||||
|
||||
If Not BakaShrot_LoadClient("BakaShrot_Client.dll")
|
||||
PrintN("Failed to load BakaShrot_Client.dll")
|
||||
End 1
|
||||
EndIf
|
||||
|
||||
If Not BakaShrot_SetPrivateKey(PrivateKey)
|
||||
PrintN("Failed to set the private key")
|
||||
End 1
|
||||
EndIf
|
||||
|
||||
If Not BakaShrot_SetPublicKey(PublicKey)
|
||||
PrintN("Failed to set the public key")
|
||||
End 1
|
||||
EndIf
|
||||
|
||||
If Not BakaShrot_SetServerPublicKey(ServerPublicKey)
|
||||
PrintN("Failed to set the server's public key")
|
||||
End 1
|
||||
EndIf
|
||||
|
||||
If Not BakaShrot_SetNode(Node)
|
||||
PrintN("Failed to set the node")
|
||||
End 1
|
||||
EndIf
|
||||
|
||||
If Not BakaShrot_Connect(ServerHost, ServerPort)
|
||||
PrintN("Failed to connect and authenticate to " + ServerHost + ":" + Str(ServerPort))
|
||||
End 1
|
||||
EndIf
|
||||
PrintN("Connected and authenticated to " + ServerHost + ":" + Str(ServerPort))
|
||||
|
||||
Delay(500)
|
||||
PrintN("IsConnected: " + Str(BakaShrot_IsConnected()))
|
||||
|
||||
BakaShrot_Disconnect()
|
||||
PrintN("IsConnected after disconnecting: " + Str(BakaShrot_IsConnected()))
|
||||
|
||||
BakaShrot_UnloadClient()
|
||||
End 0
|
||||
|
||||
CompilerEndIf
|
||||
@@ -0,0 +1,145 @@
|
||||
;{- Code Header
|
||||
; ==- Basic Info -================================
|
||||
; Name: BakaShrot_ErrorCodes.pbi
|
||||
; Version: 0.0.1
|
||||
; Author: Herwin Bozet (NibblePoker)
|
||||
;
|
||||
; ==- Compatibility -=============================
|
||||
; Tested compiler versions:
|
||||
; * PureBasic 5.73 LTS (Windows x64, Linux x64)
|
||||
; * PureBasic 6.40 C Backend (Windows x64)
|
||||
; * PureBasic 6.41 (Linux x64)
|
||||
; * PureBasic 6.41 C Backend (Linux x64)
|
||||
;
|
||||
; ==- Links -=====================================
|
||||
; GitHub: https://github.com/aziascreations/BakaShrot
|
||||
;}
|
||||
|
||||
; ============================================================================
|
||||
; BakaShrot error codes
|
||||
;
|
||||
; What BakaShrot_GetLastError() returns after a failed call of the client DLL
|
||||
; (BakaShrot_Client.pbi), and the code a server sends with each refusal
|
||||
; (RequestRefused, protocol 6). The Python client has the same numbers in
|
||||
; bakashrot.ErrorCode. Shipped next to BakaShrot_Client_Prototypes.pbi,
|
||||
; which includes it.
|
||||
;
|
||||
; 0 no error (the last call succeeded)
|
||||
; 1-99 refused by the server: the connection is still open, see
|
||||
; BakaShrot_GetRefusalReason() for the details
|
||||
; 100+ the client's own: the connection, the arguments, the files
|
||||
;
|
||||
; What to do about each:
|
||||
; reconnect, then retry: NotConnected, ConnectFailed, ConnectionLost,
|
||||
; ProtocolError (the connection is closed)
|
||||
; retry later: NotReady (an attachment still on its way),
|
||||
; ServerError (the server's storage failed)
|
||||
; fix the config: AuthRejected, ServerNotVerified, NotAllowed,
|
||||
; UnknownName, NoDefaultTopic
|
||||
; fix the call: InvalidArgument, InvalidRequest, TooBig,
|
||||
; QueryFailed, FileError
|
||||
; gone, or not yet there: NotFound
|
||||
; sent again by itself: DataMismatch (an upload that doesn't match its
|
||||
; SHA-256: upload it again), AttachmentMismatch (a
|
||||
; downloaded one that doesn't: read it again)
|
||||
;
|
||||
; A push whose answer was lost (ConnectionLost) may still have been stored:
|
||||
; pushing it again can store it twice, under the next id. Delivery is at
|
||||
; least once; check the latest message first if a duplicate matters.
|
||||
; ============================================================================
|
||||
|
||||
; --- Refused by the server (RequestRefused's Code) ----------------------------
|
||||
|
||||
; Not allowed to this client: AllowRead / AllowWrite / AllowQuery, its
|
||||
; PushTopics / ReadTopics, or a request only peers may make.
|
||||
#BakaShrot_Refused_NotAllowed = 1
|
||||
; A topic or node name (or id) this server doesn't know.
|
||||
#BakaShrot_Refused_UnknownName = 2
|
||||
; No such message, attachment or upload.
|
||||
#BakaShrot_Refused_NotFound = 3
|
||||
; The attachment isn't on this server yet (still being replicated).
|
||||
#BakaShrot_Refused_NotReady = 4
|
||||
; A message, attachment or query result over a limit, or an attachment
|
||||
; bigger than this server keeps.
|
||||
#BakaShrot_Refused_TooBig = 5
|
||||
; A push without a topic, and no DefaultTopic for this client.
|
||||
#BakaShrot_Refused_NoDefaultTopic = 6
|
||||
; A request that doesn't fit: parts out of order, an upload for another
|
||||
; topic or already attached, a part that doesn't exist...
|
||||
#BakaShrot_Refused_InvalidRequest = 7
|
||||
; An uploaded attachment that doesn't match its SHA-256: dropped.
|
||||
#BakaShrot_Refused_DataMismatch = 8
|
||||
; The SQL of a query failed (its error in the reason).
|
||||
#BakaShrot_Refused_QueryFailed = 9
|
||||
; The server couldn't store or read something: its database failed.
|
||||
#BakaShrot_Refused_ServerError = 10
|
||||
|
||||
; The highest a refusal can have, anything above is the client's own.
|
||||
#BakaShrot_Refused_Max = 99
|
||||
|
||||
; --- The client's own (BakaShrot_GetLastError()) --------------------------------
|
||||
|
||||
#BakaShrot_Error_None = 0
|
||||
; Not connected: never, or the connection was closed or lost before.
|
||||
#BakaShrot_Error_NotConnected = 100
|
||||
; The server couldn't be reached at that host and port.
|
||||
#BakaShrot_Error_ConnectFailed = 101
|
||||
; The server closed the connection during the handshake: wrong
|
||||
; ServerPublicKey, a key or node it doesn't allow, or another protocol
|
||||
; version (its log says which).
|
||||
#BakaShrot_Error_AuthRejected = 102
|
||||
; The server couldn't prove it holds ServerPublicKey's private key.
|
||||
#BakaShrot_Error_ServerNotVerified = 103
|
||||
; The connection broke during a request (it's closed now). A push may
|
||||
; still have been stored.
|
||||
#BakaShrot_Error_ConnectionLost = 104
|
||||
; The server answered something unexpected or malformed: the connection is
|
||||
; closed.
|
||||
#BakaShrot_Error_ProtocolError = 105
|
||||
; A bad argument: a ref that's neither a name nor an id, a null pointer, a
|
||||
; message or attachment over the limits, a setting missing before connecting.
|
||||
#BakaShrot_Error_InvalidArgument = 106
|
||||
; A file couldn't be opened, read or written.
|
||||
#BakaShrot_Error_FileError = 107
|
||||
; A downloaded attachment doesn't match its SHA-256.
|
||||
#BakaShrot_Error_AttachmentMismatch = 108
|
||||
; Already connected: disconnect first.
|
||||
#BakaShrot_Error_AlreadyConnected = 109
|
||||
; Out of memory, or another failure inside the client.
|
||||
#BakaShrot_Error_Internal = 110
|
||||
|
||||
|
||||
; The name of an error code, as the constants have it ("NotFound"), or
|
||||
; "Error <code>" for an unknown one.
|
||||
Procedure.s BakaShrot_ErrorName(Code.l)
|
||||
Select Code
|
||||
Case #BakaShrot_Error_None : ProcedureReturn "None"
|
||||
Case #BakaShrot_Refused_NotAllowed : ProcedureReturn "NotAllowed"
|
||||
Case #BakaShrot_Refused_UnknownName : ProcedureReturn "UnknownName"
|
||||
Case #BakaShrot_Refused_NotFound : ProcedureReturn "NotFound"
|
||||
Case #BakaShrot_Refused_NotReady : ProcedureReturn "NotReady"
|
||||
Case #BakaShrot_Refused_TooBig : ProcedureReturn "TooBig"
|
||||
Case #BakaShrot_Refused_NoDefaultTopic : ProcedureReturn "NoDefaultTopic"
|
||||
Case #BakaShrot_Refused_InvalidRequest : ProcedureReturn "InvalidRequest"
|
||||
Case #BakaShrot_Refused_DataMismatch : ProcedureReturn "DataMismatch"
|
||||
Case #BakaShrot_Refused_QueryFailed : ProcedureReturn "QueryFailed"
|
||||
Case #BakaShrot_Refused_ServerError : ProcedureReturn "ServerError"
|
||||
Case #BakaShrot_Error_NotConnected : ProcedureReturn "NotConnected"
|
||||
Case #BakaShrot_Error_ConnectFailed : ProcedureReturn "ConnectFailed"
|
||||
Case #BakaShrot_Error_AuthRejected : ProcedureReturn "AuthRejected"
|
||||
Case #BakaShrot_Error_ServerNotVerified : ProcedureReturn "ServerNotVerified"
|
||||
Case #BakaShrot_Error_ConnectionLost : ProcedureReturn "ConnectionLost"
|
||||
Case #BakaShrot_Error_ProtocolError : ProcedureReturn "ProtocolError"
|
||||
Case #BakaShrot_Error_InvalidArgument : ProcedureReturn "InvalidArgument"
|
||||
Case #BakaShrot_Error_FileError : ProcedureReturn "FileError"
|
||||
Case #BakaShrot_Error_AttachmentMismatch : ProcedureReturn "AttachmentMismatch"
|
||||
Case #BakaShrot_Error_AlreadyConnected : ProcedureReturn "AlreadyConnected"
|
||||
Case #BakaShrot_Error_Internal : ProcedureReturn "Internal"
|
||||
EndSelect
|
||||
ProcedureReturn "Error " + Str(Code)
|
||||
EndProcedure
|
||||
|
||||
; #True for a code a server sends with a refusal (1-99).
|
||||
Procedure.i BakaShrot_IsRefusalCode(Code.l)
|
||||
ProcedureReturn Bool(Code >= 1 And Code <= #BakaShrot_Refused_Max)
|
||||
EndProcedure
|
||||
@@ -0,0 +1,4 @@
|
||||
client should be a DLL that can connect in the back.
|
||||
And it should provide functions to the caller that lets it query or do shit on the server.
|
||||
|
||||
When saying server, it will usually be a local process.
|
||||
Reference in New Issue
Block a user