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

Last change on this file since f03425e was 2030100, checked in by OpenGnSys Support Team <soporte-og@…>, 2 years ago

#915 release existing client on reconnections

Trasient network problems might result in duplicated clients, drop
client object if it already exists before creating a new one.

  • 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        const char              *shell_output;
65};
66
67void og_client_add(struct og_client *cli);
68struct og_client *__og_client_find(const struct in_addr *addr);
69
70static inline int og_client_socket(const struct og_client *cli)
71{
72        return cli->io.fd;
73}
74
75#include "json.h"
76
77int og_client_state_process_payload_rest(struct og_client *cli);
78
79enum og_rest_method {
80        OG_METHOD_GET   = 0,
81        OG_METHOD_POST,
82        OG_METHOD_NO_HTTP
83};
84
85int og_send_request(enum og_rest_method method, enum og_cmd_type type,
86                    const struct og_msg_params *params,
87                    const json_t *data);
88
89struct og_cmd {
90        uint32_t                id;
91        struct list_head        list;
92        uint32_t                client_id;
93        const char              *ip;
94        const char              *mac;
95        enum og_cmd_type        type;
96        enum og_rest_method     method;
97        struct og_msg_params    params;
98        json_t                  *json;
99        struct timeval          tv;
100};
101
102const struct og_cmd *og_cmd_find(const char *client_ip);
103void og_cmd_free(const struct og_cmd *cmd);
104
105#endif
Note: See TracBrowser for help on using the repository browser.