source: ogServer-Git/src/rest.h @ 5a3fd51

Last change on this file since 5a3fd51 was 5a3fd51, checked in by Jose M. Guisado <jguisado@…>, 3 years ago

#1065 client: add support for ogclient linux state

ogClient can be run in linux mode, intended for exposing some
ogServer commands when running in a linux distribution.

When connecting with a client in linux mode, do not expect a full
partition setup response. Just expect a 'status', and then accept
the connection without updating any partition information in
the database.

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