source: ogServer-Git/src/rest.h @ 1fdb7e6

Last change on this file since 1fdb7e6 was 141b079, checked in by OpenGnSys Support Team <soporte-og@…>, 3 years ago

#915 Add schedule/command

Enables ogserver to schedule commands (also referred as actions in
legacy web console jargon).

This feature enables ogserver to write in the "acciones" table in order
to have full capabilities for command scheduling purposes, thus not
depending in the legacy web console to insert into "acciones" table.

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