source: ogServer-Git/src/rest.h

Last change on this file was df5161e, checked in by Javier Sánchez Parra <jsanchez@…>, 2 years ago

#915 Add last_cmd to GET /clients API

"last_cmd" json object contains information of the last command executed
by the correspondent client. For now, it only includes "result" string
property, which stores "success" if the last command finished correctly
or "failure" on the contrary.

To populate "result" property, this commit also adds "last_cmd_result"
enum attribute to og_client struct. Client response processing fills
this attribute according to its success.

Clients in WOL_SENT state always have last_cmd->result = "unknown".

Request: GET /clients

Response: 200 OK
{

"clients": [

{

"addr": "10.141.10.102",
"state": "WOL_SENT",
"last_cmd": {

"result": "unknown"

}

},
{

"addr": "10.141.10.101",
"state": "OPG",
"speed": 1000,
"last_cmd": {

"result": "success"

}

},
{

"addr": "10.141.10.100",
"state": "OPG",
"speed": 1000,
"last_cmd": {

"result": "failure"

}

}

]

}

  • Property mode set to 100644
File size: 2.2 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
45enum og_cmd_result {
46        OG_UNKNOWN      = 0,
47        OG_FAILURE      = 1,
48        OG_SUCCESS      = 2,
49};
50
51#define OG_MSG_REQUEST_MAXLEN   131072
52
53struct og_client {
54        struct list_head        list;
55        struct ev_io            io;
56        struct ev_timer         timer;
57        struct sockaddr_in      addr;
58        enum og_client_state    state;
59        char                    buf[OG_MSG_REQUEST_MAXLEN];
60        unsigned int            buf_len;
61        unsigned int            msg_len;
62        bool                    agent;
63        int                     content_length;
64        char                    auth_token[64];
65        enum og_client_status   status;
66        enum og_cmd_type        last_cmd;
67        unsigned int            last_cmd_id;
68        enum og_cmd_result      last_cmd_result;
69        bool                    autorun;
70        uint32_t                speed;
71        const char              *shell_output;
72};
73
74void og_client_add(struct og_client *cli);
75struct og_client *__og_client_find(const struct in_addr *addr);
76
77static inline int og_client_socket(const struct og_client *cli)
78{
79        return cli->io.fd;
80}
81
82#include "json.h"
83
84int og_client_state_process_payload_rest(struct og_client *cli);
85
86enum og_rest_method {
87        OG_METHOD_GET   = 0,
88        OG_METHOD_POST,
89        OG_METHOD_NO_HTTP
90};
91
92int og_send_request(enum og_rest_method method, enum og_cmd_type type,
93                    const struct og_msg_params *params,
94                    const json_t *data);
95
96struct og_cmd {
97        uint32_t                id;
98        struct list_head        list;
99        uint32_t                client_id;
100        const char              *ip;
101        const char              *mac;
102        enum og_cmd_type        type;
103        enum og_rest_method     method;
104        struct og_msg_params    params;
105        json_t                  *json;
106        struct timeval          tv;
107};
108
109const struct og_cmd *og_cmd_find(const char *client_ip);
110void og_cmd_free(const struct og_cmd *cmd);
111
112#endif
Note: See TracBrowser for help on using the repository browser.