source: ogServer-Git/src/rest.h @ a7cce8d

Last change on this file since a7cce8d was 79e7e2b, checked in by OpenGnSys Support Team <soporte-og@…>, 3 years ago

#915 only API REST is supported

Socket hidra API has been removed, all connections use a REST API.

  • Property mode set to 100644
File size: 1.8 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;
58};
59
60void og_client_add(struct og_client *cli);
61
62static inline int og_client_socket(const struct og_client *cli)
63{
64        return cli->io.fd;
65}
66
67#include "json.h"
68
69int og_client_state_process_payload_rest(struct og_client *cli);
70
71enum og_rest_method {
72        OG_METHOD_GET   = 0,
73        OG_METHOD_POST,
74        OG_METHOD_NO_HTTP
75};
76
77int og_send_request(enum og_rest_method method, enum og_cmd_type type,
78                    const struct og_msg_params *params,
79                    const json_t *data);
80
81struct og_cmd {
82        uint32_t                id;
83        struct list_head        list;
84        uint32_t                client_id;
85        const char              *ip;
86        const char              *mac;
87        enum og_cmd_type        type;
88        enum og_rest_method     method;
89        struct og_msg_params    params;
90        json_t                  *json;
91};
92
93const struct og_cmd *og_cmd_find(const char *client_ip);
94void og_cmd_free(const struct og_cmd *cmd);
95
96#endif
Note: See TracBrowser for help on using the repository browser.