-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtty.h
117 lines (105 loc) · 2.93 KB
/
rtty.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
* MIT License
*
* Copyright (c) 2019 Jianhui Zhao <zhaojh329@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef RTTY_RTTY_H
#define RTTY_RTTY_H
#include <stdbool.h>
#include <ev.h>
#include "config.h"
#include "buffer.h"
#include "file.h"
#include "list.h"
#ifdef SSL_SUPPORT
#include "ssl/ssl.h"
#endif
#define RTTY_PROTO_VER 4
#define RTTY_MAX_TTY 10
#define RTTY_HEARTBEAT_INTEVAL 5.0
#define RTTY_TTY_TIMEOUT 600
#define RTTY_TTY_ACK_BLOCK 4096
enum {
MSG_TYPE_REGISTER,
MSG_TYPE_LOGIN,
MSG_TYPE_LOGOUT,
MSG_TYPE_TERMDATA,
MSG_TYPE_WINSIZE,
MSG_TYPE_CMD,
MSG_TYPE_HEARTBEAT,
MSG_TYPE_FILE,
MSG_TYPE_HTTP,
MSG_TYPE_ACK,
MSG_TYPE_MAX = MSG_TYPE_ACK
};
enum {
RTTY_STATE_DISCONNECTED,
RTTY_STATE_CONNECTED
};
struct rtty;
struct tty {
pid_t pid;
int pty;
char sid[33];
struct ev_io ior;
struct ev_io iow;
struct ev_child cw;
struct buffer wb;
struct rtty *rtty;
ev_tstamp active;
uint32_t wait_ack;
struct ev_timer tmr;
struct list_head node;
struct file_context file;
};
struct rtty {
const char *host;
int port;
int sock;
const char *devid;
const char *token; /* authorization token */
const char *description;
const char *username;
bool ssl_on;
struct buffer rb;
struct buffer wb;
struct ev_io iow;
struct ev_io ior;
struct ev_timer tmr;
struct ev_loop *loop;
int ninactive;
ev_tstamp active;
ev_tstamp last_heartbeat;
bool reconnect;
#ifdef SSL_SUPPORT
struct ssl_context *ssl_ctx;
bool insecure;
bool ssl_negotiated;
void *ssl;
#endif
int ntty; /* tty number */
struct list_head ttys;
struct list_head http_conns;
};
int rtty_start(struct rtty *rtty);
void rtty_exit(struct rtty *rtty);
void rtty_send_msg(struct rtty *rtty, int type, void *data, int len);
#endif