Last change
on this file since 6e70916 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
|
Rev | Line | |
---|
[04ca20e] | 1 | #ifndef OG_REST_H |
---|
| 2 | #define OG_REST_H |
---|
| 3 | |
---|
| 4 | #include <ev.h> |
---|
[2d68f8a] | 5 | #include <sys/time.h> |
---|
[04ca20e] | 6 | |
---|
| 7 | extern struct ev_loop *og_loop; |
---|
| 8 | |
---|
| 9 | enum og_client_state { |
---|
| 10 | OG_CLIENT_RECEIVING_HEADER = 0, |
---|
| 11 | OG_CLIENT_RECEIVING_PAYLOAD, |
---|
| 12 | OG_CLIENT_PROCESSING_REQUEST, |
---|
| 13 | }; |
---|
| 14 | |
---|
| 15 | enum og_client_status { |
---|
| 16 | OG_CLIENT_STATUS_OGLIVE, |
---|
| 17 | OG_CLIENT_STATUS_BUSY, |
---|
[c0f5d2c] | 18 | OG_CLIENT_STATUS_VIRTUAL, |
---|
[5a3fd51] | 19 | OG_CLIENT_STATUS_LINUX, |
---|
[772811e] | 20 | OG_CLIENT_STATUS_LINUX_SESSION, |
---|
[b6b1040] | 21 | OG_CLIENT_STATUS_WIN, |
---|
[772811e] | 22 | OG_CLIENT_STATUS_WIN_SESSION, |
---|
[04ca20e] | 23 | }; |
---|
| 24 | |
---|
| 25 | enum 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, |
---|
[403e7c3] | 41 | OG_CMD_IMAGES, |
---|
[04ca20e] | 42 | OG_CMD_MAX |
---|
| 43 | }; |
---|
| 44 | |
---|
[0a09c5b] | 45 | #define OG_MSG_REQUEST_MAXLEN 131072 |
---|
[04ca20e] | 46 | |
---|
| 47 | struct 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; |
---|
[40d4279] | 63 | uint32_t speed; |
---|
[04ca20e] | 64 | }; |
---|
| 65 | |
---|
| 66 | void og_client_add(struct og_client *cli); |
---|
| 67 | |
---|
| 68 | static inline int og_client_socket(const struct og_client *cli) |
---|
| 69 | { |
---|
| 70 | return cli->io.fd; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | #include "json.h" |
---|
| 74 | |
---|
| 75 | int og_client_state_process_payload_rest(struct og_client *cli); |
---|
| 76 | |
---|
| 77 | enum og_rest_method { |
---|
| 78 | OG_METHOD_GET = 0, |
---|
| 79 | OG_METHOD_POST, |
---|
| 80 | OG_METHOD_NO_HTTP |
---|
| 81 | }; |
---|
| 82 | |
---|
| 83 | int 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 | |
---|
| 87 | struct 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; |
---|
[2d68f8a] | 97 | struct timeval tv; |
---|
[04ca20e] | 98 | }; |
---|
| 99 | |
---|
| 100 | const struct og_cmd *og_cmd_find(const char *client_ip); |
---|
| 101 | void og_cmd_free(const struct og_cmd *cmd); |
---|
| 102 | |
---|
| 103 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.