libwebsockets
Lightweight C library for HTML5 websockets
lws-plugin-ssh.h
1 /*
2  * libwebsockets - small server side websockets and web server implementation
3  *
4  * Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22  * IN THE SOFTWARE.
23  */
24 
25 #if !defined(__LWS_PLUGIN_SSH_H__)
26 #define __LWS_PLUGIN_SSH_H__
27 
28 #define LWS_CALLBACK_SSH_UART_SET_RXFLOW (LWS_CALLBACK_USER + 800)
29 
30 #define LWS_SSH_OPS_VERSION 2
31 
32 struct lws_ssh_pty {
33  char term[16];
34  char *modes;
35  uint32_t width_ch;
36  uint32_t height_ch;
37  uint32_t width_px;
38  uint32_t height_px;
39  uint32_t modes_len;
40 };
41 
42 #define SSHMO_TTY_OP_END 0 /* Indicates end of options. */
43 #define SSHMO_VINTR 1 /* Interrupt character; 255 if none. Similarly
44  * for the other characters. Not all of these
45  * characters are supported on all systems. */
46 #define SSHMO_VQUIT 2 /* The quit character (sends SIGQUIT signal on
47  * POSIX systems). */
48 #define SSHMO_VERASE 3 /* Erase the character to left of the cursor. */
49 #define SSHMO_VKILL 4 /* Kill the current input line. */
50 #define SSHMO_VEOF 5 /* End-of-file character (sends EOF from the
51  * terminal). */
52 #define SSHMO_VEOL 6 /* End-of-line character in addition to
53  * carriage return and/or linefeed. */
54 #define SSHMO_VEOL2 7 /* Additional end-of-line character. */
55 #define SSHMO_VSTART 8 /* Continues paused output (normally
56  * control-Q). */
57 #define SSHMO_VSTOP 9 /* Pauses output (normally control-S). */
58 #define SSHMO_VSUSP 10 /* Suspends the current program. */
59 #define SSHMO_VDSUSP 11 /* Another suspend character. */
60 #define SSHMO_VREPRINT 12 /* Reprints the current input line. */
61 #define SSHMO_VWERASE 13 /* Erases a word left of cursor. */
62 #define SSHMO_VLNEXT 14 /* Enter the next character typed literally,
63  * even if it is a special character */
64 #define SSHMO_VFLUSH 15 /* Character to flush output. */
65 #define SSHMO_VSWTCH 16 /* Switch to a different shell layer. */
66 #define SSHMO_VSTATUS 17 /* Prints system status line (load, command,
67  * pid, etc). */
68 #define SSHMO_VDISCARD 18 /* Toggles the flushing of terminal output. */
69 #define SSHMO_IGNPAR 30 /* The ignore parity flag. The parameter
70  * SHOULD be 0 if this flag is FALSE,
71  * and 1 if it is TRUE. */
72 #define SSHMO_PARMRK 31 /* Mark parity and framing errors. */
73 #define SSHMO_INPCK 32 /* Enable checking of parity errors. */
74 #define SSHMO_ISTRIP 33 /* Strip 8th bit off characters. */
75 #define SSHMO_INLCR 34 /* Map NL into CR on input. */
76 #define SSHMO_IGNCR 35 /* Ignore CR on input. */
77 #define SSHMO_ICRNL 36 /* Map CR to NL on input. */
78 #define SSHMO_IUCLC 37 /* Translate uppercase characters to lowercase. */
79 #define SSHMO_IXON 38 /* Enable output flow control. */
80 #define SSHMO_IXANY 39 /* Any char will restart after stop. */
81 #define SSHMO_IXOFF 40 /* Enable input flow control. */
82 #define SSHMO_IMAXBEL 41 /* Ring bell on input queue full. */
83 #define SSHMO_ISIG 50 /* Enable signals INTR, QUIT, [D]SUSP. */
84 #define SSHMO_ICANON 51 /* Canonicalize input lines. */
85 #define SSHMO_XCASE 52 /* Enable input and output of uppercase
86  * characters by preceding their lowercase
87  * equivalents with "\". */
88 #define SSHMO_ECHO 53 /* Enable echoing. */
89 #define SSHMO_ECHOE 54 /* Visually erase chars. */
90 #define SSHMO_ECHOK 55 /* Kill character discards current line. */
91 #define SSHMO_ECHONL 56 /* Echo NL even if ECHO is off. */
92 #define SSHMO_NOFLSH 57 /* Don't flush after interrupt. */
93 #define SSHMO_TOSTOP 58 /* Stop background jobs from output. */
94 #define SSHMO_IEXTEN 59 /* Enable extensions. */
95 #define SSHMO_ECHOCTL 60 /* Echo control characters as ^(Char). */
96 #define SSHMO_ECHOKE 61 /* Visual erase for line kill. */
97 #define SSHMO_PENDIN 62 /* Retype pending input. */
98 #define SSHMO_OPOST 70 /* Enable output processing. */
99 #define SSHMO_OLCUC 71 /* Convert lowercase to uppercase. */
100 #define SSHMO_ONLCR 72 /* Map NL to CR-NL. */
101 #define SSHMO_OCRNL 73 /* Translate carriage return to newline (out). */
102 #define SSHMO_ONOCR 74 /* Translate newline to CR-newline (out). */
103 #define SSHMO_ONLRET 75 /* Newline performs a carriage return (out). */
104 #define SSHMO_CS7 90 /* 7 bit mode. */
105 #define SSHMO_CS8 91 /* 8 bit mode. */
106 #define SSHMO_PARENB 92 /* Parity enable. */
107 #define SSHMO_PARODD 93 /* Odd parity, else even. */
108 #define SSHMO_TTY_OP_ISPEED 128 /* Specifies the input baud rate in
109  * bits per second. */
110 #define SSHMO_TTY_OP_OSPEED 129 /* Specifies the output baud rate in
111  * bits per second. */
112 
132 
133 typedef void (*lws_ssh_finish_exec)(void *handle, int retcode);
134 
135 struct lws_ssh_ops {
151  int (*channel_create)(struct lws *wsi, void **priv);
152 
161  int (*channel_destroy)(void *priv);
162 
173  int (*rx)(void *priv, struct lws *wsi, const uint8_t *buf, uint32_t len);
174 
188  int (*tx_waiting)(void *priv);
189 
206  size_t (*tx)(void *priv, int stdch, uint8_t *buf, size_t len);
207 
220  size_t (*get_server_key)(struct lws *wsi, uint8_t *buf, size_t len);
221 
232  size_t (*set_server_key)(struct lws *wsi, uint8_t *buf, size_t len);
233 
243  int (*set_env)(void *priv, const char *name, const char *value);
244 
256  int (*exec)(void *priv, struct lws *wsi, const char *command, lws_ssh_finish_exec finish, void *finish_handle);
257 
269  int (*shell)(void *priv, struct lws *wsi, lws_ssh_finish_exec finish, void *finish_handle);
270 
279  int (*pty_req)(void *priv, struct lws_ssh_pty *pty);
280 
290  int (*child_process_io)(void *priv, struct lws *wsi,
291  struct lws_cgi_args *args);
292 
301  int (*child_process_terminated)(void *priv, struct lws *wsi);
302 
313  void (*disconnect_reason)(uint32_t reason, const char *desc,
314  const char *desc_lang);
315 
332  int (*is_pubkey_authorized)(const char *username,
333  const char *type, const uint8_t *peer, int peer_len);
334 
352  size_t (*banner)(char *buf, size_t max_len, char *lang,
353  size_t max_lang_len);
354 
359  const char *server_string;
360 
368  char api_version;
369 };
371 
372 #endif
373 
Definition: lws-cgi.h:53
Definition: lws-plugin-ssh.h:121
int(* channel_destroy)(void *priv)
Definition: lws-plugin-ssh.h:147
int(* channel_create)(struct lws *wsi, void **priv)
Definition: lws-plugin-ssh.h:137
int(* rx)(void *priv, struct lws *wsi, const uint8_t *buf, uint32_t len)
Definition: lws-plugin-ssh.h:159
int(* set_env)(void *priv, const char *name, const char *value)
Definition: lws-plugin-ssh.h:229
int(* child_process_terminated)(void *priv, struct lws *wsi)
Definition: lws-plugin-ssh.h:287
int(* exec)(void *priv, struct lws *wsi, const char *command, lws_ssh_finish_exec finish, void *finish_handle)
Definition: lws-plugin-ssh.h:242
size_t(* banner)(char *buf, size_t max_len, char *lang, size_t max_lang_len)
Definition: lws-plugin-ssh.h:338
int(* tx_waiting)(void *priv)
Definition: lws-plugin-ssh.h:174
size_t(* set_server_key)(struct lws *wsi, uint8_t *buf, size_t len)
Definition: lws-plugin-ssh.h:218
int(* is_pubkey_authorized)(const char *username, const char *type, const uint8_t *peer, int peer_len)
Definition: lws-plugin-ssh.h:318
int(* child_process_io)(void *priv, struct lws *wsi, struct lws_cgi_args *args)
Definition: lws-plugin-ssh.h:276
void(* disconnect_reason)(uint32_t reason, const char *desc, const char *desc_lang)
Definition: lws-plugin-ssh.h:299
char api_version
Definition: lws-plugin-ssh.h:354
const char * server_string
Definition: lws-plugin-ssh.h:345
int(* pty_req)(void *priv, struct lws_ssh_pty *pty)
Definition: lws-plugin-ssh.h:265
size_t(* get_server_key)(struct lws *wsi, uint8_t *buf, size_t len)
Definition: lws-plugin-ssh.h:206
int(* shell)(void *priv, struct lws *wsi, lws_ssh_finish_exec finish, void *finish_handle)
Definition: lws-plugin-ssh.h:255
size_t(* tx)(void *priv, int stdch, uint8_t *buf, size_t len)
Definition: lws-plugin-ssh.h:192
Definition: lws-plugin-ssh.h:32