source: ogServer-Git/sources/rest.h @ 83937b8

Last change on this file since 83937b8 was 04ca20e, checked in by OpenGnSys Support Team <soporte-og@…>, 4 years ago

#971 split into smaller file

Split ogAdmServer into several files:

  • sources/rest.c that implements the server REST API.
  • sources/client.c that implements the client REST API.
  • sources/json.c that provides a few JSON helpers.
  • 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
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,
17};
18
19enum og_cmd_type {
20        OG_CMD_UNSPEC,
21        OG_CMD_WOL,
22        OG_CMD_PROBE,
23        OG_CMD_SHELL_RUN,
24        OG_CMD_SESSION,
25        OG_CMD_POWEROFF,
26        OG_CMD_REFRESH,
27        OG_CMD_REBOOT,
28        OG_CMD_STOP,
29        OG_CMD_HARDWARE,
30        OG_CMD_SOFTWARE,
31        OG_CMD_IMAGE_CREATE,
32        OG_CMD_IMAGE_RESTORE,
33        OG_CMD_SETUP,
34        OG_CMD_RUN_SCHEDULE,
35        OG_CMD_MAX
36};
37
38#define OG_MSG_REQUEST_MAXLEN   65536
39
40struct og_client {
41        struct list_head        list;
42        struct ev_io            io;
43        struct ev_timer         timer;
44        struct sockaddr_in      addr;
45        enum og_client_state    state;
46        char                    buf[OG_MSG_REQUEST_MAXLEN];
47        unsigned int            buf_len;
48        unsigned int            msg_len;
49        int                     keepalive_idx;
50        bool                    rest;
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
96extern char auth_token[LONPRM];
97
98#endif
Note: See TracBrowser for help on using the repository browser.