/* * 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 #include #include #include #include #ifdef __cplusplus extern "C" { #endif // __cplusplus /** * Makes a client: its handle (1 and up, never reused), 0 if it failed. */ int64_t BakaShrot_CreateClient(void); /** * Frees a client and closes its connection (once a call on it in another * thread ends): 1, or 0 if it wasn't one. */ ptrdiff_t BakaShrot_FreeClient(int64_t client); /** * Why the client's 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. `InvalidArgument` for * a bad handle. */ int32_t BakaShrot_GetLastError(int64_t client); /** * Why the client's last call failed, in words: the server's reason for a * refusal, the client's otherwise. Empty if it succeeded. */ ptrdiff_t BakaShrot_GetRefusalReasonA(int64_t client, char *buffer, ptrdiff_t size); /** * The same as `BakaShrot_GetRefusalReasonA`, in UTF-16. */ ptrdiff_t BakaShrot_GetRefusalReasonW(int64_t client, 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(int64_t client, const char *certificate); /** * The same as `BakaShrot_SetCaCertificateA`, in UTF-16. */ ptrdiff_t BakaShrot_SetCaCertificateW(int64_t client, const uint16_t *certificate); /** * Sets the 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(int64_t client, const char *certificate); /** * The same as `BakaShrot_SetCertificateA`, in UTF-16. */ ptrdiff_t BakaShrot_SetCertificateW(int64_t client, const uint16_t *certificate); /** * Sets the client's private key, its certificate's: PEM text, or the path * of a file holding it. Before connecting. */ ptrdiff_t BakaShrot_SetPrivateKeyA(int64_t client, const char *key); /** * The same as `BakaShrot_SetPrivateKeyA`, in UTF-16. */ ptrdiff_t BakaShrot_SetPrivateKeyW(int64_t client, 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 (one that isn't there is a * `FileError`); null or empty for none. Before connecting. */ ptrdiff_t BakaShrot_SetCrlA(int64_t client, const char *crl); /** * The same as `BakaShrot_SetCrlA`, in UTF-16. */ ptrdiff_t BakaShrot_SetCrlW(int64_t client, 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(int64_t client, const char *host, int32_t port); /** * The same as `BakaShrot_ConnectA`, in UTF-16. */ ptrdiff_t BakaShrot_ConnectW(int64_t client, 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(int64_t client); /** * Closes the connection: 0 if there was none. The settings stay. */ ptrdiff_t BakaShrot_Disconnect(int64_t client); /** * The node this client is, as the server said when connecting: its * certificate's name. Empty when not connected. */ ptrdiff_t BakaShrot_GetNodeA(int64_t client, char *buffer, ptrdiff_t size); /** * The same as `BakaShrot_GetNodeA`, in UTF-16. */ ptrdiff_t BakaShrot_GetNodeW(int64_t client, 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(int64_t client, const char *topic, const char *data); /** * The same as `BakaShrot_PushMessageToA`, in UTF-16. */ int64_t BakaShrot_PushMessageToW(int64_t client, 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(int64_t client, const char *topic, const char *node); /** * The same as `BakaShrot_GetLatestMessageOfA`, in UTF-16. */ ptrdiff_t BakaShrot_GetLatestMessageOfW(int64_t client, 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(int64_t client, const char *topic, const char *node, int64_t after, int32_t limit); /** * The same as `BakaShrot_GetMessagesA`, in UTF-16. */ int32_t BakaShrot_GetMessagesW(int64_t client, 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(int64_t client); /** * 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(int64_t client, int32_t index); /** * 1 if more messages follow the last one the last `GetMessages` got: ask * again after its id. */ ptrdiff_t BakaShrot_HasMoreMessages(int64_t client); /** * The selected message's id, 0 if none. */ int64_t BakaShrot_GetMessageId(int64_t client); /** * 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(int64_t client); /** * The selected message's attachment's size, 0 without one. */ int64_t BakaShrot_GetMessageAttachmentSize(int64_t client); /** * 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(int64_t client); /** * The selected message's data, as pushed (JSON or not). */ ptrdiff_t BakaShrot_GetMessageDataA(int64_t client, char *buffer, ptrdiff_t size); /** * The same as `BakaShrot_GetMessageDataA`, in UTF-16. */ ptrdiff_t BakaShrot_GetMessageDataW(int64_t client, uint16_t *buffer, ptrdiff_t size); /** * The topic the last `GetMessages` or `GetLatestMessageOf` asked for. */ ptrdiff_t BakaShrot_GetMessageTopicA(int64_t client, char *buffer, ptrdiff_t size); /** * The same as `BakaShrot_GetMessageTopicA`, in UTF-16. */ ptrdiff_t BakaShrot_GetMessageTopicW(int64_t client, uint16_t *buffer, ptrdiff_t size); /** * The node the last `GetMessages` or `GetLatestMessageOf` asked for. */ ptrdiff_t BakaShrot_GetMessageNodeA(int64_t client, char *buffer, ptrdiff_t size); /** * The same as `BakaShrot_GetMessageNodeA`, in UTF-16. */ ptrdiff_t BakaShrot_GetMessageNodeW(int64_t client, uint16_t *buffer, ptrdiff_t size); /** * Lists the topics with messages that this client may push to or read * (every one if its roles have `list_topics` or `query`): how many, -1 on * failure. Then `BakaShrot_GetNamesList()`. */ int32_t BakaShrot_ListTopics(int64_t client); /** * Lists the nodes with messages in the topics this client may read (every * one if its roles have `list_nodes` or `query`): how many, -1 on failure. Then * `BakaShrot_GetNamesList()`. */ int32_t BakaShrot_ListNodes(int64_t client); /** * The last list, as JSON: * `{"kind":"topic","truncated":false,"names":["logs",...]}`, `truncated` * if some didn't fit. */ ptrdiff_t BakaShrot_GetNamesListA(int64_t client, char *buffer, ptrdiff_t size); /** * The same as `BakaShrot_GetNamesListA`, in UTF-16. */ ptrdiff_t BakaShrot_GetNamesListW(int64_t client, 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(int64_t client, const char *sql); /** * The same as `BakaShrot_QueryA`, in UTF-16. */ ptrdiff_t BakaShrot_QueryW(int64_t client, const uint16_t *sql); /** * The last query's result, as JSON: * `{"columns":[...],"rows":[[...],...]}`, every value a string or null. */ ptrdiff_t BakaShrot_GetQueryResultA(int64_t client, char *buffer, ptrdiff_t size); /** * The same as `BakaShrot_GetQueryResultA`, in UTF-16. */ ptrdiff_t BakaShrot_GetQueryResultW(int64_t client, 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(int64_t client, const char *topic, const char *data, const char *file_path); /** * The same as `BakaShrot_PushMessageWithFileA`, in UTF-16. */ int64_t BakaShrot_PushMessageWithFileW(int64_t client, 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(int64_t client, const char *topic, const char *data, const void *attachment, int64_t size); /** * The same as `BakaShrot_PushMessageWithDataA`, in UTF-16. */ int64_t BakaShrot_PushMessageWithDataW(int64_t client, 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(int64_t client, 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(int64_t client, 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(int64_t client, const char *topic, const char *node, int64_t message_id); /** * The same as `BakaShrot_LoadAttachmentA`, in UTF-16. */ int64_t BakaShrot_LoadAttachmentW(int64_t client, 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(int64_t client, void *buffer, int64_t buffer_size); /** * Frees what `BakaShrot_LoadAttachment()` read: 1. */ ptrdiff_t BakaShrot_FreeAttachmentData(int64_t client); #ifdef __cplusplus } // extern "C" #endif // __cplusplus #endif /* BAKASHROT_H */