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

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

#1061 add timeout to pending scheduled commands

Pending schedule commands can deny ogLive boot of clients due
to filling of pending cmd queue with commands such as "Iniciar Sesión".

For example: Using RemotePC to serve clients that do not boot into
ogLive will fill up the pending command queue with "Iniciar Sesión".

Introduce a safety timeout for pending (scheduled) commands to
avoid this situation.

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