Last change
on this file since d3e9b57 was
40d4279,
checked in by OpenGnSys Support Team <soporte-og@…>, 4 years ago
|
#995 Add link speed parsing to client probe response
If a probe response contains speedinformation, parse and store
it inside the client struct. Speed is interpreted as an unsigned
integer representing Mbit/s.
|
-
Property mode set to
100644
|
File size:
1.8 KB
|
Line | |
---|
1 | #ifndef OG_REST_H |
---|
2 | #define OG_REST_H |
---|
3 | |
---|
4 | #include <ev.h> |
---|
5 | |
---|
6 | extern struct ev_loop *og_loop; |
---|
7 | |
---|
8 | enum og_client_state { |
---|
9 | OG_CLIENT_RECEIVING_HEADER = 0, |
---|
10 | OG_CLIENT_RECEIVING_PAYLOAD, |
---|
11 | OG_CLIENT_PROCESSING_REQUEST, |
---|
12 | }; |
---|
13 | |
---|
14 | enum og_client_status { |
---|
15 | OG_CLIENT_STATUS_OGLIVE, |
---|
16 | OG_CLIENT_STATUS_BUSY, |
---|
17 | OG_CLIENT_STATUS_VIRTUAL, |
---|
18 | }; |
---|
19 | |
---|
20 | enum 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, |
---|
36 | OG_CMD_IMAGES, |
---|
37 | OG_CMD_MAX |
---|
38 | }; |
---|
39 | |
---|
40 | #define OG_MSG_REQUEST_MAXLEN 131072 |
---|
41 | |
---|
42 | struct 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; |
---|
58 | uint32_t speed; |
---|
59 | }; |
---|
60 | |
---|
61 | void og_client_add(struct og_client *cli); |
---|
62 | |
---|
63 | static inline int og_client_socket(const struct og_client *cli) |
---|
64 | { |
---|
65 | return cli->io.fd; |
---|
66 | } |
---|
67 | |
---|
68 | #include "json.h" |
---|
69 | |
---|
70 | int og_client_state_process_payload_rest(struct og_client *cli); |
---|
71 | |
---|
72 | enum og_rest_method { |
---|
73 | OG_METHOD_GET = 0, |
---|
74 | OG_METHOD_POST, |
---|
75 | OG_METHOD_NO_HTTP |
---|
76 | }; |
---|
77 | |
---|
78 | int 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 | |
---|
82 | struct 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 | |
---|
94 | const struct og_cmd *og_cmd_find(const char *client_ip); |
---|
95 | void og_cmd_free(const struct og_cmd *cmd); |
---|
96 | |
---|
97 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.