aboutsummaryrefslogtreecommitdiff
path: root/include/zaprus.h
blob: 6638117953e5e45f92c1b013abab1558c2b672c8 (plain) (blame)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright 2026 Robby Zambito
//
// This file is part of zaprus.
//
// Zaprus is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
//
// Zaprus is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with Zaprus. If not, see <https://www.gnu.org/licenses/>. 

#ifndef ZAPRUS_H
#define ZAPRUS_H

#include <stdint.h>
#include <stdlib.h>

typedef void* zaprus_client;
typedef void* zaprus_connection;

// Returns NULL if there was an error.
zaprus_client zaprus_init_client(void);

void zaprus_deinit_client(zaprus_client client);

// Returns 0 on success, else returns 1.
int zaprus_client_send_relay(zaprus_client client, const char* payload, size_t payload_len, const char dest[4]);

// Returns NULL if there was an error.
// Caller should call zaprus_deinit_connection when done with the connection.
zaprus_connection zaprus_connect(zaprus_client client, const char* payload, size_t payload_len);

void zaprus_deinit_connection(zaprus_connection connection);

// Capacity is the maximum length of the output buffer.
// out_len is modified to specify how much of the capacity is used by the response.
// Blocks until the next message is available, or returns 1 if the underlying socket times out.
// Returns 0 on success, else returns 1.
int zaprus_connection_next(zaprus_connection connection, char *out, size_t capacity, size_t *out_len);

// Returns 0 on success, else returns 1.
int zaprus_connection_send(zaprus_connection connection, const char *payload, size_t payload_len);

#endif // ZAPRUS_H