summaryrefslogtreecommitdiffstats
path: root/src/rest.h
blob: be5b17a40075515581c4ef80a02bb229791976ed (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#ifndef OG_REST_H
#define OG_REST_H

#include <ev.h>
#include <sys/time.h>
#include <netinet/in.h>

extern struct ev_loop *og_loop;

enum og_client_state {
	OG_CLIENT_RECEIVING_HEADER	= 0,
	OG_CLIENT_RECEIVING_PAYLOAD,
	OG_CLIENT_PROCESSING_REQUEST,
};

enum og_client_status {
	OG_CLIENT_STATUS_OGLIVE,
	OG_CLIENT_STATUS_BUSY,
	OG_CLIENT_STATUS_VIRTUAL,
	OG_CLIENT_STATUS_LINUX,
	OG_CLIENT_STATUS_LINUX_SESSION,
	OG_CLIENT_STATUS_WIN,
	OG_CLIENT_STATUS_WIN_SESSION,
};

enum og_cmd_type {
	OG_CMD_UNSPEC,
	OG_CMD_WOL,
	OG_CMD_SHELL_RUN,
	OG_CMD_SESSION,
	OG_CMD_POWEROFF,
	OG_CMD_REFRESH,
	OG_CMD_REBOOT,
	OG_CMD_STOP,
	OG_CMD_HARDWARE,
	OG_CMD_SOFTWARE,
	OG_CMD_IMAGE_CREATE,
	OG_CMD_IMAGE_UPDATE,
	OG_CMD_IMAGE_RESTORE,
	OG_CMD_IMAGE_RESTRICT,
	OG_CMD_SETUP,
	OG_CMD_IMAGES,
	OG_CMD_CACHE_DELETE,
	OG_CMD_CACHE_FETCH,
	OG_CMD_MAX
};

enum og_cmd_result {
        OG_UNKNOWN      = 0,
        OG_FAILURE      = 1,
        OG_SUCCESS      = 2,
};

struct og_cmd_ctx {
	union {
		struct {
			uint32_t id;
		} image;
	};
};

#define OG_MSG_REQUEST_MAXLEN	131072

struct og_client {
	struct list_head	list;
	struct ev_io		io;
	struct ev_timer		timer;
	struct sockaddr_in	addr;
	enum og_client_state	state;
	char			buf[OG_MSG_REQUEST_MAXLEN];
	unsigned int		buf_len;
	unsigned int		msg_len;
	bool			agent;
	int			content_length;
	char			auth_token[64];
	enum og_client_status	status;
	struct {
		enum og_cmd_type	type;
		unsigned int		id;
		enum og_cmd_result	result;
		struct og_cmd_ctx	ctx;
	} last_cmd;
	uint32_t		speed;
	uint32_t		seq;
	struct {
		const char	*cmd;
		const char	*output;
		uint32_t	retcode;
		time_t		tstamp;
	} shell;
};

void og_client_add(struct og_client *cli);
struct og_client *__og_client_find(const struct in_addr *addr);

static inline int og_client_socket(const struct og_client *cli)
{
	return cli->io.fd;
}

#include "json.h"

int og_client_state_process_payload_rest(struct og_client *cli);

enum og_rest_uri {
	OG_URI_UNKNOWN = 0,
	OG_URI_CLIENTS,
	OG_URI_CLIENT_REPO,
	OG_URI_CLIENT_SETUP,
	OG_URI_CLIENT_SERVER,
	OG_URI_CLIENT_INFO,
	OG_URI_CLIENT_ADD,
	OG_URI_CLIENT_UPDATE,
	OG_URI_CLIENT_DELETE,
	OG_URI_CLIENT_MOVE,
	OG_URI_WOL,
	OG_URI_SHELL_RUN,
	OG_URI_SHELL_OUTPUT,
	OG_URI_SHELL_LIST,
	OG_URI_SESSION,
	OG_URI_SCOPES,
	OG_URI_POWEROFF,
	OG_URI_REBOOT,
	OG_URI_BOOT_MODE,
	OG_URI_STOP,
	OG_URI_REFRESH,
	OG_URI_HARDWARE,
	OG_URI_SOFTWARE,
	OG_URI_REPO,
	OG_URI_REPO_ADD,
	OG_URI_REPO_UPDATE,
	OG_URI_REPO_DELETE,
	OG_URI_IMAGES,
	OG_URI_IMAGE_CREATE,
	OG_URI_IMAGE_UPDATE,
	OG_URI_IMAGE_RESTORE,
	OG_URI_IMAGE_DELETE,
	OG_URI_IMAGE_RESTRICT,
	OG_URI_CACHE_LIST,
	OG_URI_EFI,
	OG_URI_CACHE_DELETE,
	OG_URI_CACHE_FETCH,
	OG_URI_PART_SETUP,
	OG_URI_OGLIVE_LIST,
	OG_URI_OGLIVE_SET,
	OG_URI_CENTER_ADD,
	OG_URI_CENTER_UPDATE,
	OG_URI_CENTER_DELETE,
	OG_URI_CENTER_INFO,
	OG_URI_ROOM_ADD,
	OG_URI_ROOM_UPDATE,
	OG_URI_ROOM_DELETE,
	OG_URI_ROOM_INFO,
	OG_URI_SERVER,
	OG_URI_STATS,
	OG_URI_FOLDER_ADD,
	OG_URI_FOLDER_DELETE,
	OG_URI_FOLDER_UPDATE,
	OG_URI_MAX
};

enum og_rest_method {
	OG_METHOD_GET	= 0,
	OG_METHOD_POST,
	OG_METHOD_DELETE,
	OG_METHOD_NO_HTTP
};

int og_send_request(enum og_rest_method method, enum og_cmd_type type,
		    const struct og_msg_params *params,
		    const json_t *data, const struct og_cmd_ctx *ctx);

int og_dbi_scope_get(struct og_dbi *dbi, json_t *array);

#endif