mirror of
https://github.com/aziascreations/BakaShrot.git
synced 2026-11-23 20:58:46 +01:00
cf8264b21d
- Removed `[server] topics` and `[replication] replicated_topics`: a push is taken by its roles' `push_topics`, a replicated message by the peer's `accept_topics`; a topic exists from its first message. - Topics that only came from a peer are read and listed like any other; `ListNames` lists the topics with messages, filtered by the roles. - A push to a topic no role names is `NotAllowed`; `UnknownName` is only for nodes. - Clients' queries: every PRAGMA refused as it's prepared (SQLite's authorizer), `PRAGMA query_only = 0` used to take effect. - Noted the leads found by reading the code in `docs/known-issues.md`. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
357 lines
11 KiB
C
357 lines
11 KiB
C
/*
|
|
* BakaShrot's client DLL: bakashrot.dll (Windows), libbakashrot.so (Linux).
|
|
* Generated by cbindgen from crates/bakashrot-capi: don't edit.
|
|
* docs/client.md has the conventions and the whole API.
|
|
*/
|
|
|
|
#ifndef BAKASHROT_H
|
|
#define BAKASHROT_H
|
|
|
|
#include <stdarg.h>
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif // __cplusplus
|
|
|
|
/**
|
|
* Why the last call failed: a protocol error code (1-99 a server's
|
|
* refusal, the connection still open; 100 and up the client's own), 0 if
|
|
* it succeeded. Getters don't change it.
|
|
*/
|
|
int32_t BakaShrot_GetLastError(void);
|
|
|
|
/**
|
|
* Why the last call failed, in words: the server's reason for a refusal,
|
|
* the client's otherwise. Empty if it succeeded.
|
|
*/
|
|
ptrdiff_t BakaShrot_GetRefusalReasonA(char *buffer, ptrdiff_t size);
|
|
|
|
/**
|
|
* The same as `BakaShrot_GetRefusalReasonA`, in UTF-16.
|
|
*/
|
|
ptrdiff_t BakaShrot_GetRefusalReasonW(uint16_t *buffer, ptrdiff_t size);
|
|
|
|
/**
|
|
* Sets the CA's certificate, which the server's must be issued by: PEM
|
|
* text, or the path of a file holding it. Before connecting.
|
|
*/
|
|
ptrdiff_t BakaShrot_SetCaCertificateA(const char *certificate);
|
|
|
|
/**
|
|
* The same as `BakaShrot_SetCaCertificateA`, in UTF-16.
|
|
*/
|
|
ptrdiff_t BakaShrot_SetCaCertificateW(const uint16_t *certificate);
|
|
|
|
/**
|
|
* Sets this client's certificate, which says its node and its roles: PEM
|
|
* text, or the path of a file holding it. Before connecting.
|
|
*/
|
|
ptrdiff_t BakaShrot_SetCertificateA(const char *certificate);
|
|
|
|
/**
|
|
* The same as `BakaShrot_SetCertificateA`, in UTF-16.
|
|
*/
|
|
ptrdiff_t BakaShrot_SetCertificateW(const uint16_t *certificate);
|
|
|
|
/**
|
|
* Sets this client's private key, its certificate's: PEM text, or the path
|
|
* of a file holding it. Before connecting.
|
|
*/
|
|
ptrdiff_t BakaShrot_SetPrivateKeyA(const char *key);
|
|
|
|
/**
|
|
* The same as `BakaShrot_SetPrivateKeyA`, in UTF-16.
|
|
*/
|
|
ptrdiff_t BakaShrot_SetPrivateKeyW(const uint16_t *key);
|
|
|
|
/**
|
|
* Sets the CA's CRL, optional: servers it revokes are refused. PEM text,
|
|
* or the path of a file holding it; null or empty for none. Before
|
|
* connecting.
|
|
*/
|
|
ptrdiff_t BakaShrot_SetCrlA(const char *crl);
|
|
|
|
/**
|
|
* The same as `BakaShrot_SetCrlA`, in UTF-16.
|
|
*/
|
|
ptrdiff_t BakaShrot_SetCrlW(const uint16_t *crl);
|
|
|
|
/**
|
|
* Connects to the server at `host` (a name or an address) and `port`:
|
|
* TLS with the certificates set, then the server says who this client is
|
|
* (`BakaShrot_GetNode()`). Refused: the code says by whom (`AuthRejected`
|
|
* the server refused the certificate, `ServerNotVerified` this client
|
|
* refused the server's, `NotAllowed` none of its roles is the server's).
|
|
*/
|
|
ptrdiff_t BakaShrot_ConnectA(const char *host, int32_t port);
|
|
|
|
/**
|
|
* The same as `BakaShrot_ConnectA`, in UTF-16.
|
|
*/
|
|
ptrdiff_t BakaShrot_ConnectW(const uint16_t *host, int32_t port);
|
|
|
|
/**
|
|
* 1 while connected: notices when the server closed the connection
|
|
* (forgotten then: connect again).
|
|
*/
|
|
ptrdiff_t BakaShrot_IsConnected(void);
|
|
|
|
/**
|
|
* Closes the connection: 0 if there was none. The settings stay.
|
|
*/
|
|
ptrdiff_t BakaShrot_Disconnect(void);
|
|
|
|
/**
|
|
* The node this client is, as the server said when connecting: its
|
|
* certificate's name. Empty when not connected.
|
|
*/
|
|
ptrdiff_t BakaShrot_GetNodeA(char *buffer, ptrdiff_t size);
|
|
|
|
/**
|
|
* The same as `BakaShrot_GetNodeA`, in UTF-16.
|
|
*/
|
|
ptrdiff_t BakaShrot_GetNodeW(uint16_t *buffer, ptrdiff_t size);
|
|
|
|
/**
|
|
* Pushes a message (JSON or not) to `topic`, as this client's node: its
|
|
* id (1 and up), -1 on failure. A push whose answer was lost
|
|
* (`ConnectionLost`) may have been stored all the same.
|
|
*/
|
|
int64_t BakaShrot_PushMessageToA(const char *topic, const char *data);
|
|
|
|
/**
|
|
* The same as `BakaShrot_PushMessageToA`, in UTF-16.
|
|
*/
|
|
int64_t BakaShrot_PushMessageToW(const uint16_t *topic, const uint16_t *data);
|
|
|
|
/**
|
|
* Gets the latest message of `topic` and `node`, then read with the
|
|
* `BakaShrot_GetMessage*()` getters. `NotFound` if there's none yet.
|
|
*/
|
|
ptrdiff_t BakaShrot_GetLatestMessageOfA(const char *topic, const char *node);
|
|
|
|
/**
|
|
* The same as `BakaShrot_GetLatestMessageOfA`, in UTF-16.
|
|
*/
|
|
ptrdiff_t BakaShrot_GetLatestMessageOfW(const uint16_t *topic, const uint16_t *node);
|
|
|
|
/**
|
|
* Gets the messages of `topic` and `node` after id `after` (0 for the
|
|
* first ones), in order: `limit` at most (1-10000), fewer past about
|
|
* 1 MB. Returns how many came (none isn't a failure), -1 on failure. The
|
|
* first is selected; `BakaShrot_SelectMessage()` selects the others,
|
|
* `BakaShrot_HasMoreMessages()` says whether more follow the last one.
|
|
*/
|
|
int32_t BakaShrot_GetMessagesA(const char *topic, const char *node, int64_t after, int32_t limit);
|
|
|
|
/**
|
|
* The same as `BakaShrot_GetMessagesA`, in UTF-16.
|
|
*/
|
|
int32_t BakaShrot_GetMessagesW(const uint16_t *topic,
|
|
const uint16_t *node,
|
|
int64_t after,
|
|
int32_t limit);
|
|
|
|
/**
|
|
* How many messages the last `GetMessages` or `GetLatestMessageOf` got.
|
|
*/
|
|
int32_t BakaShrot_GetMessageCount(void);
|
|
|
|
/**
|
|
* Selects the message at `index` (0 to the count - 1) for the getters: 0
|
|
* if there's none there (`InvalidArgument`), the selection unchanged.
|
|
*/
|
|
ptrdiff_t BakaShrot_SelectMessage(int32_t index);
|
|
|
|
/**
|
|
* 1 if more messages follow the last one the last `GetMessages` got: ask
|
|
* again after its id.
|
|
*/
|
|
ptrdiff_t BakaShrot_HasMoreMessages(void);
|
|
|
|
/**
|
|
* The selected message's id, 0 if none.
|
|
*/
|
|
int64_t BakaShrot_GetMessageId(void);
|
|
|
|
/**
|
|
* When the selected message was pushed, by the server it was pushed to:
|
|
* milliseconds since 1970-01-01 UTC, 0 if none.
|
|
*/
|
|
int64_t BakaShrot_GetMessagePushedAt(void);
|
|
|
|
/**
|
|
* The selected message's attachment's size, 0 without one.
|
|
*/
|
|
int64_t BakaShrot_GetMessageAttachmentSize(void);
|
|
|
|
/**
|
|
* 1 if the selected message's attachment is all on this server (a
|
|
* replicated one may still be on its way).
|
|
*/
|
|
ptrdiff_t BakaShrot_IsMessageAttachmentReady(void);
|
|
|
|
/**
|
|
* The selected message's data, as pushed (JSON or not).
|
|
*/
|
|
ptrdiff_t BakaShrot_GetMessageDataA(char *buffer, ptrdiff_t size);
|
|
|
|
/**
|
|
* The same as `BakaShrot_GetMessageDataA`, in UTF-16.
|
|
*/
|
|
ptrdiff_t BakaShrot_GetMessageDataW(uint16_t *buffer, ptrdiff_t size);
|
|
|
|
/**
|
|
* The topic the last `GetMessages` or `GetLatestMessageOf` asked for.
|
|
*/
|
|
ptrdiff_t BakaShrot_GetMessageTopicA(char *buffer, ptrdiff_t size);
|
|
|
|
/**
|
|
* The same as `BakaShrot_GetMessageTopicA`, in UTF-16.
|
|
*/
|
|
ptrdiff_t BakaShrot_GetMessageTopicW(uint16_t *buffer, ptrdiff_t size);
|
|
|
|
/**
|
|
* The node the last `GetMessages` or `GetLatestMessageOf` asked for.
|
|
*/
|
|
ptrdiff_t BakaShrot_GetMessageNodeA(char *buffer, ptrdiff_t size);
|
|
|
|
/**
|
|
* The same as `BakaShrot_GetMessageNodeA`, in UTF-16.
|
|
*/
|
|
ptrdiff_t BakaShrot_GetMessageNodeW(uint16_t *buffer, ptrdiff_t size);
|
|
|
|
/**
|
|
* Lists the topics with messages that this client may push to or read
|
|
* (every one if it may query): how many, -1 on failure. Then
|
|
* `BakaShrot_GetNamesList()`.
|
|
*/
|
|
int32_t BakaShrot_ListTopics(void);
|
|
|
|
/**
|
|
* Lists every node with messages: how many, -1 on failure. Then
|
|
* `BakaShrot_GetNamesList()`.
|
|
*/
|
|
int32_t BakaShrot_ListNodes(void);
|
|
|
|
/**
|
|
* The last list, as JSON:
|
|
* `{"kind":"topic","truncated":false,"names":["logs",...]}`, `truncated`
|
|
* if some didn't fit.
|
|
*/
|
|
ptrdiff_t BakaShrot_GetNamesListA(char *buffer, ptrdiff_t size);
|
|
|
|
/**
|
|
* The same as `BakaShrot_GetNamesListA`, in UTF-16.
|
|
*/
|
|
ptrdiff_t BakaShrot_GetNamesListW(uint16_t *buffer, ptrdiff_t size);
|
|
|
|
/**
|
|
* Runs read-only SQL on the server (one SELECT or WITH), if this client
|
|
* may query. Then `BakaShrot_GetQueryResult()`.
|
|
*/
|
|
ptrdiff_t BakaShrot_QueryA(const char *sql);
|
|
|
|
/**
|
|
* The same as `BakaShrot_QueryA`, in UTF-16.
|
|
*/
|
|
ptrdiff_t BakaShrot_QueryW(const uint16_t *sql);
|
|
|
|
/**
|
|
* The last query's result, as JSON:
|
|
* `{"columns":[...],"rows":[[...],...]}`, every value a string or null.
|
|
*/
|
|
ptrdiff_t BakaShrot_GetQueryResultA(char *buffer, ptrdiff_t size);
|
|
|
|
/**
|
|
* The same as `BakaShrot_GetQueryResultA`, in UTF-16.
|
|
*/
|
|
ptrdiff_t BakaShrot_GetQueryResultW(uint16_t *buffer, ptrdiff_t size);
|
|
|
|
/**
|
|
* Pushes a message with the file at `FilePath` as its attachment (1 byte
|
|
* to 1 TiB, the server may take less: `TooBig`): uploaded with it, the
|
|
* message stored once all of it came. Its id, -1 on failure. The file is
|
|
* read twice (its SHA-256 first): one changed in between is refused
|
|
* (`DataMismatch`).
|
|
*/
|
|
int64_t BakaShrot_PushMessageWithFileA(const char *topic, const char *data, const char *file_path);
|
|
|
|
/**
|
|
* The same as `BakaShrot_PushMessageWithFileA`, in UTF-16.
|
|
*/
|
|
int64_t BakaShrot_PushMessageWithFileW(const uint16_t *topic,
|
|
const uint16_t *data,
|
|
const uint16_t *file_path);
|
|
|
|
/**
|
|
* Pushes a message with the `Size` bytes at `Data` as its attachment, as
|
|
* `BakaShrot_PushMessageWithFileA` does.
|
|
*/
|
|
int64_t BakaShrot_PushMessageWithDataA(const char *topic,
|
|
const char *data,
|
|
const void *attachment,
|
|
int64_t size);
|
|
|
|
/**
|
|
* The same as `BakaShrot_PushMessageWithDataA`, in UTF-16.
|
|
*/
|
|
int64_t BakaShrot_PushMessageWithDataW(const uint16_t *topic,
|
|
const uint16_t *data,
|
|
const void *attachment,
|
|
int64_t size);
|
|
|
|
/**
|
|
* Saves the attachment of `Topic`, `Node`'s message `MessageId` as the
|
|
* file at `FilePath` (replaced), read a part at a time and checked with
|
|
* its SHA-256: its size, -1 on failure (`NotFound` without one,
|
|
* `NotReady` if it isn't on this server yet, `AttachmentMismatch`). A
|
|
* failed one leaves no file.
|
|
*/
|
|
int64_t BakaShrot_SaveAttachmentA(const char *topic,
|
|
const char *node,
|
|
int64_t message_id,
|
|
const char *file_path);
|
|
|
|
/**
|
|
* The same as `BakaShrot_SaveAttachmentA`, in UTF-16.
|
|
*/
|
|
int64_t BakaShrot_SaveAttachmentW(const uint16_t *topic,
|
|
const uint16_t *node,
|
|
int64_t message_id,
|
|
const uint16_t *file_path);
|
|
|
|
/**
|
|
* Reads the attachment of `Topic`, `Node`'s message `MessageId` into
|
|
* memory, checked with its SHA-256 (`BakaShrot_SaveAttachmentA` for big
|
|
* ones): its size, -1 on failure. Then `BakaShrot_GetAttachmentData()`.
|
|
*/
|
|
int64_t BakaShrot_LoadAttachmentA(const char *topic, const char *node, int64_t message_id);
|
|
|
|
/**
|
|
* The same as `BakaShrot_LoadAttachmentA`, in UTF-16.
|
|
*/
|
|
int64_t BakaShrot_LoadAttachmentW(const uint16_t *topic, const uint16_t *node, int64_t message_id);
|
|
|
|
/**
|
|
* Copies what the last `BakaShrot_LoadAttachment()` read into `Buffer`, if
|
|
* `BufferSize` is enough: returns its size (0 if none), copies nothing if
|
|
* it doesn't fit (a null `Buffer` asks for the size).
|
|
*/
|
|
int64_t BakaShrot_GetAttachmentData(void *buffer, int64_t buffer_size);
|
|
|
|
/**
|
|
* Frees what `BakaShrot_LoadAttachment()` read: 1.
|
|
*/
|
|
ptrdiff_t BakaShrot_FreeAttachmentData(void);
|
|
|
|
#ifdef __cplusplus
|
|
} // extern "C"
|
|
#endif // __cplusplus
|
|
|
|
#endif /* BAKASHROT_H */
|