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
44
45
46
47
48
|
#ifndef BOKF_CLIENT_H
#define BOKF_CLIENT_H
#include <stdint.h>
/* Thin protocol client shared by bokfctl and bokftui. Connects to a unix
socket path, "tcp:host:port" (plaintext) or "tls:host:port". The TLS
client verifies the certificate chain and host name; BOKFD_TLS_CA adds a
PEM file to the trust store (for private CAs and tests). */
struct client_conn {
int fd;
void *ssl;
void *ctx;
};
int client_connect(const char *target, struct client_conn *out);
void client_close(struct client_conn *c);
int client_send_line(struct client_conn *c, const char *line);
char *client_read_line(struct client_conn *c);
/* Human-readable reason for the last failed call. */
const char *client_last_error(void);
char *client_make_request(const char *cmd, const char *session, int64_t org,
const char *args_json, const char *id);
char *client_make_login_args(const char *user, const char *password);
/* Sends one command and returns the raw response line (malloc'd), or NULL
on a transport error. */
char *client_rpc(struct client_conn *c, const char *cmd, const char *session,
int64_t org, const char *args_json);
/* Password login. Returns 0 and sets *session_out on success; on failure
returns -1 and sets *err_out to the response line or an error message. */
int client_login(struct client_conn *c, const char *user, const char *password,
char **session_out, char **err_out);
/* Token login (same contract as client_login). */
int client_token_login(struct client_conn *c, const char *token,
char **session_out, char **err_out);
/* Convenience: true when the response line has "ok":true. */
int client_ok(const char *response);
/* Extract result.session into buf; returns 0 on success. */
int client_session_from(const char *response, char *buf, unsigned long cap);
#endif
|