source: ogServer-Git/src/rest.h @ ff9dbd9

Last change on this file since ff9dbd9 was 772811e, checked in by Jose M. Guisado <jguisado@…>, 3 years ago

#1065 Add support for client events

ogServer supports events from clients in an agent mode
(linux/windows).

Client sends event information (eg. user login/logout)
via a 103 Early Hints http response message.

  • Property mode set to 100644
File size: 2.0 KB
Line 
1#ifndef OG_REST_H
2#define OG_REST_H
3
4#include <ev.h>
5#include <sys/time.h>
6
7extern struct ev_loop *og_loop;
8
9enum og_client_state {
10        OG_CLIENT_RECEIVING_HEADER      = 0,
11        OG_CLIENT_RECEIVING_PAYLOAD,
12        OG_CLIENT_PROCESSING_REQUEST,
13};
14
15enum og_client_status {
16        OG_CLIENT_STATUS_OGLIVE,
17        OG_CLIENT_STATUS_BUSY,
18        OG_CLIENT_STATUS_VIRTUAL,
19        OG_CLIENT_STATUS_LINUX,
20        OG_CLIENT_STATUS_LINUX_SESSION,
21        OG_CLIENT_STATUS_WIN,
22        OG_CLIENT_STATUS_WIN_SESSION,
23};
24
25enum og_cmd_type {
26        OG_CMD_UNSPEC,
27        OG_CMD_WOL,
28        OG_CMD_PROBE,
29        OG_CMD_SHELL_RUN,
30        OG_CMD_SESSION,
31        OG_CMD_POWEROFF,
32        OG_CMD_REFRESH,
33        OG_CMD_REBOOT,
34        OG_CMD_STOP,
35        OG_CMD_HARDWARE,
36        OG_CMD_SOFTWARE,
37        OG_CMD_IMAGE_CREATE,
38        OG_CMD_IMAGE_RESTORE,
39        OG_CMD_SETUP,
40        OG_CMD_RUN_SCHEDULE,
41        OG_CMD_IMAGES,
42        OG_CMD_MAX
43};
44
45#define OG_MSG_REQUEST_MAXLEN   131072
46
47struct og_client {
48        struct list_head        list;
49        struct ev_io            io;
50        struct ev_timer         timer;
51        struct sockaddr_in      addr;
52        enum og_client_state    state;
53        char                    buf[OG_MSG_REQUEST_MAXLEN];
54        unsigned int            buf_len;
55        unsigned int            msg_len;
56        bool                    agent;
57        int                     content_length;
58        char                    auth_token[64];
59        enum og_client_status   status;
60        enum og_cmd_type        last_cmd;
61        unsigned int            last_cmd_id;
62        bool                    autorun;
63        uint32_t                speed;
64};
65
66void og_client_add(struct og_client *cli);
67
68static inline int og_client_socket(const struct og_client *cli)
69{
70        return cli->io.fd;
71}
72
73#include "json.h"
74
75int og_client_state_process_payload_rest(struct og_client *cli);
76
77enum og_rest_method {
78        OG_METHOD_GET   = 0,
79        OG_METHOD_POST,
80        OG_METHOD_NO_HTTP
81};
82
83int og_send_request(enum og_rest_method method, enum og_cmd_type type,
84                    const struct og_msg_params *params,
85                    const json_t *data);
86
87struct og_cmd {
88        uint32_t                id;
89        struct list_head        list;
90        uint32_t                client_id;
91        const char              *ip;
92        const char              *mac;
93        enum og_cmd_type        type;
94        enum og_rest_method     method;
95        struct og_msg_params    params;
96        json_t                  *json;
97        struct timeval          tv;
98};
99
100const struct og_cmd *og_cmd_find(const char *client_ip);
101void og_cmd_free(const struct og_cmd *cmd);
102
103#endif
Note: See TracBrowser for help on using the repository browser.