summaryrefslogtreecommitdiff
path: root/src/web.h
blob: a9180103e0df1e6bf5d3b464a5be1dc8d54d297c (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
#pragma once

#include "app.h"

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

struct MHD_PostProcessor;

struct Server {
	struct App *app;

	char *page;
};

int web_begin(struct Server *server, int port, const char *admin_user, const char *admin_pass);
int web_join(struct Server *server);

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;
	char username[32];
	int username_set;
	char password[64];
	int password_set;
};

struct Request {
	struct Server *server;
	struct PostCollector pp;
	struct MHD_PostProcessor *post_proc;  // NULL when using PostCollector
	struct FormData form;
	const char *url;
	const char *method;
	const char *host;
	const char *proto;
};

enum HandlerStatus {
	HANDLER_DECLINE,
	HANDLER_ACCEPTED,
	HANDLER_ERROR
};

struct MHD_Connection;

typedef enum HandlerStatus (*RouteHandler)(
	struct MHD_Connection *connection,
	struct Request *request
);