summaryrefslogtreecommitdiff
path: root/clients/client.h
blob: 7e18a2314bce8675d8af26a089a7ea73495c29f5 (plain)
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
#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 or "tcp:host:port". */

int client_connect(const char *target);
int client_send_line(int fd, const char *line);
char *client_read_line(int fd);

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(int fd, 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(int fd, const char *user, const char *password,
                 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