libwebsockets
Lightweight C library for HTML5 websockets
lws-plugin-ssh.h
1 /*
2  * libwebsockets - lws-plugin-ssh-base
3  *
4  * Copyright (C) 2017 Andy Green <andy@warmcat.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation:
9  * version 2.1 of the License.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301 USA
20  */
21 
22 #if !defined(__LWS_PLUGIN_SSH_H__)
23 #define __LWS_PLUGIN_SSH_H__
24 
25 #define LWS_CALLBACK_SSH_UART_SET_RXFLOW (LWS_CALLBACK_USER + 800)
26 
27 #define LWS_SSH_OPS_VERSION 2
28 
29 struct lws_ssh_pty {
30  char term[16];
31  char *modes;
32  uint32_t width_ch;
33  uint32_t height_ch;
34  uint32_t width_px;
35  uint32_t height_px;
36  uint32_t modes_len;
37 };
38 
39 #define SSHMO_TTY_OP_END 0 /* Indicates end of options. */
40 #define SSHMO_VINTR 1 /* Interrupt character; 255 if none. Similarly
41  * for the other characters. Not all of these
42  * characters are supported on all systems. */
43 #define SSHMO_VQUIT 2 /* The quit character (sends SIGQUIT signal on
44  * POSIX systems). */
45 #define SSHMO_VERASE 3 /* Erase the character to left of the cursor. */
46 #define SSHMO_VKILL 4 /* Kill the current input line. */
47 #define SSHMO_VEOF 5 /* End-of-file character (sends EOF from the
48  * terminal). */
49 #define SSHMO_VEOL 6 /* End-of-line character in addition to
50  * carriage return and/or linefeed. */
51 #define SSHMO_VEOL2 7 /* Additional end-of-line character. */
52 #define SSHMO_VSTART 8 /* Continues paused output (normally
53  * control-Q). */
54 #define SSHMO_VSTOP 9 /* Pauses output (normally control-S). */
55 #define SSHMO_VSUSP 10 /* Suspends the current program. */
56 #define SSHMO_VDSUSP 11 /* Another suspend character. */
57 #define SSHMO_VREPRINT 12 /* Reprints the current input line. */
58 #define SSHMO_VWERASE 13 /* Erases a word left of cursor. */
59 #define SSHMO_VLNEXT 14 /* Enter the next character typed literally,
60  * even if it is a special character */
61 #define SSHMO_VFLUSH 15 /* Character to flush output. */
62 #define SSHMO_VSWTCH 16 /* Switch to a different shell layer. */
63 #define SSHMO_VSTATUS 17 /* Prints system status line (load, command,
64  * pid, etc). */
65 #define SSHMO_VDISCARD 18 /* Toggles the flushing of terminal output. */
66 #define SSHMO_IGNPAR 30 /* The ignore parity flag. The parameter
67  * SHOULD be 0 if this flag is FALSE,
68  * and 1 if it is TRUE. */
69 #define SSHMO_PARMRK 31 /* Mark parity and framing errors. */
70 #define SSHMO_INPCK 32 /* Enable checking of parity errors. */
71 #define SSHMO_ISTRIP 33 /* Strip 8th bit off characters. */
72 #define SSHMO_INLCR 34 /* Map NL into CR on input. */
73 #define SSHMO_IGNCR 35 /* Ignore CR on input. */
74 #define SSHMO_ICRNL 36 /* Map CR to NL on input. */
75 #define SSHMO_IUCLC 37 /* Translate uppercase characters to lowercase. */
76 #define SSHMO_IXON 38 /* Enable output flow control. */
77 #define SSHMO_IXANY 39 /* Any char will restart after stop. */
78 #define SSHMO_IXOFF 40 /* Enable input flow control. */
79 #define SSHMO_IMAXBEL 41 /* Ring bell on input queue full. */
80 #define SSHMO_ISIG 50 /* Enable signals INTR, QUIT, [D]SUSP. */
81 #define SSHMO_ICANON 51 /* Canonicalize input lines. */
82 #define SSHMO_XCASE 52 /* Enable input and output of uppercase
83  * characters by preceding their lowercase
84  * equivalents with "\". */
85 #define SSHMO_ECHO 53 /* Enable echoing. */
86 #define SSHMO_ECHOE 54 /* Visually erase chars. */
87 #define SSHMO_ECHOK 55 /* Kill character discards current line. */
88 #define SSHMO_ECHONL 56 /* Echo NL even if ECHO is off. */
89 #define SSHMO_NOFLSH 57 /* Don't flush after interrupt. */
90 #define SSHMO_TOSTOP 58 /* Stop background jobs from output. */
91 #define SSHMO_IEXTEN 59 /* Enable extensions. */
92 #define SSHMO_ECHOCTL 60 /* Echo control characters as ^(Char). */
93 #define SSHMO_ECHOKE 61 /* Visual erase for line kill. */
94 #define SSHMO_PENDIN 62 /* Retype pending input. */
95 #define SSHMO_OPOST 70 /* Enable output processing. */
96 #define SSHMO_OLCUC 71 /* Convert lowercase to uppercase. */
97 #define SSHMO_ONLCR 72 /* Map NL to CR-NL. */
98 #define SSHMO_OCRNL 73 /* Translate carriage return to newline (out). */
99 #define SSHMO_ONOCR 74 /* Translate newline to CR-newline (out). */
100 #define SSHMO_ONLRET 75 /* Newline performs a carriage return (out). */
101 #define SSHMO_CS7 90 /* 7 bit mode. */
102 #define SSHMO_CS8 91 /* 8 bit mode. */
103 #define SSHMO_PARENB 92 /* Parity enable. */
104 #define SSHMO_PARODD 93 /* Odd parity, else even. */
105 #define SSHMO_TTY_OP_ISPEED 128 /* Specifies the input baud rate in
106  * bits per second. */
107 #define SSHMO_TTY_OP_OSPEED 129 /* Specifies the output baud rate in
108  * bits per second. */
109 
129 
130 typedef void (*lws_ssh_finish_exec)(void *handle, int retcode);
131 
132 struct lws_ssh_ops {
148  int (*channel_create)(struct lws *wsi, void **priv);
149 
158  int (*channel_destroy)(void *priv);
159 
170  int (*rx)(void *priv, struct lws *wsi, const uint8_t *buf, uint32_t len);
171 
185  int (*tx_waiting)(void *priv);
186 
203  size_t (*tx)(void *priv, int stdch, uint8_t *buf, size_t len);
204 
217  size_t (*get_server_key)(struct lws *wsi, uint8_t *buf, size_t len);
218 
229  size_t (*set_server_key)(struct lws *wsi, uint8_t *buf, size_t len);
230 
240  int (*set_env)(void *priv, const char *name, const char *value);
241 
253  int (*exec)(void *priv, struct lws *wsi, const char *command, lws_ssh_finish_exec finish, void *finish_handle);
254 
266  int (*shell)(void *priv, struct lws *wsi, lws_ssh_finish_exec finish, void *finish_handle);
267 
276  int (*pty_req)(void *priv, struct lws_ssh_pty *pty);
277 
287  int (*child_process_io)(void *priv, struct lws *wsi,
288  struct lws_cgi_args *args);
289 
298  int (*child_process_terminated)(void *priv, struct lws *wsi);
299 
310  void (*disconnect_reason)(uint32_t reason, const char *desc,
311  const char *desc_lang);
312 
329  int (*is_pubkey_authorized)(const char *username,
330  const char *type, const uint8_t *peer, int peer_len);
331 
349  size_t (*banner)(char *buf, size_t max_len, char *lang,
350  size_t max_lang_len);
351 
356  const char *server_string;
357 
365  char api_version;
366 };
368 
369 #endif
370 
Definition: lws-cgi.h:52
Definition: lws-plugin-ssh.h:118
int(* channel_destroy)(void *priv)
Definition: lws-plugin-ssh.h:144
int(* channel_create)(struct lws *wsi, void **priv)
Definition: lws-plugin-ssh.h:134
int(* rx)(void *priv, struct lws *wsi, const uint8_t *buf, uint32_t len)
Definition: lws-plugin-ssh.h:156
int(* set_env)(void *priv, const char *name, const char *value)
Definition: lws-plugin-ssh.h:226
int(* child_process_terminated)(void *priv, struct lws *wsi)
Definition: lws-plugin-ssh.h:284
int(* exec)(void *priv, struct lws *wsi, const char *command, lws_ssh_finish_exec finish, void *finish_handle)
Definition: lws-plugin-ssh.h:239
size_t(* banner)(char *buf, size_t max_len, char *lang, size_t max_lang_len)
Definition: lws-plugin-ssh.h:335
int(* tx_waiting)(void *priv)
Definition: lws-plugin-ssh.h:171
size_t(* set_server_key)(struct lws *wsi, uint8_t *buf, size_t len)
Definition: lws-plugin-ssh.h:215
int(* is_pubkey_authorized)(const char *username, const char *type, const uint8_t *peer, int peer_len)
Definition: lws-plugin-ssh.h:315
int(* child_process_io)(void *priv, struct lws *wsi, struct lws_cgi_args *args)
Definition: lws-plugin-ssh.h:273
void(* disconnect_reason)(uint32_t reason, const char *desc, const char *desc_lang)
Definition: lws-plugin-ssh.h:296
char api_version
Definition: lws-plugin-ssh.h:351
const char * server_string
Definition: lws-plugin-ssh.h:342
int(* pty_req)(void *priv, struct lws_ssh_pty *pty)
Definition: lws-plugin-ssh.h:262
size_t(* get_server_key)(struct lws *wsi, uint8_t *buf, size_t len)
Definition: lws-plugin-ssh.h:203
int(* shell)(void *priv, struct lws *wsi, lws_ssh_finish_exec finish, void *finish_handle)
Definition: lws-plugin-ssh.h:252
size_t(* tx)(void *priv, int stdch, uint8_t *buf, size_t len)
Definition: lws-plugin-ssh.h:189
Definition: lws-plugin-ssh.h:29