summaryrefslogtreecommitdiff
path: root/src/web.h
blob: 95c0e27fdf78cd9f7f3a5148ce77f285dc378c7a (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#pragma once

#include <stddef.h>
#include <stdint.h>

struct MHD_PostProcessor;

struct App {
	char* dbname;
};

void prepare_database(struct App *app);

struct Server {
	struct App *app;

	char *page;
};

int web_begin(struct Server *server, int port);
int web_join(struct Server *server);

#define CLIENT_NAME_MAX 32
#define CLIENT_SECRET_LEN 33

struct PostCollector {
	char *data;
	size_t size;
	size_t capacity;
};

struct FormData {
	char name[CLIENT_NAME_MAX];
	int name_set;
	int64_t client_id;      // For delete operations
	int client_id_set;
};

struct Request {
	struct Server *server;
	struct PostCollector pp;
	struct MHD_PostProcessor *post_proc;  // NULL when using PostCollector
	struct FormData form;
};

struct CreateClientResult {
	int64_t id;
	char* name;
	char secret[CLIENT_SECRET_LEN];
};

int create_client(struct Request *req, char *name, struct CreateClientResult *result);
int delete_client(struct Request *req, int64_t client_id);

struct ListClientResultClient {
	int64_t id;
	char name[CLIENT_NAME_MAX];
	char secret[CLIENT_SECRET_LEN];
};

struct ListClientResult {
	uint16_t clients_len;
	// Right now this has to be exactly 16 elements long, but it could be longer in the future
	struct ListClientResultClient clients[];
};

int list_clients(struct Request *req, struct ListClientResult *result);