| 1 |
/* |
|---|
| 2 |
* Copyright (c) 1989, 1993 |
|---|
| 3 |
* The Regents of the University of California. All rights reserved. |
|---|
| 4 |
* Copyright (c) 2007 |
|---|
| 5 |
* OmnitTI Computer Consulting, Inc. All rights reserved. |
|---|
| 6 |
* |
|---|
| 7 |
* Redistribution and use in source and binary forms, with or without |
|---|
| 8 |
* modification, are permitted provided that the following conditions |
|---|
| 9 |
* are met: |
|---|
| 10 |
* 1. Redistributions of source code must retain the above copyright |
|---|
| 11 |
* notice, this list of conditions and the following disclaimer. |
|---|
| 12 |
* 2. Redistributions in binary form must reproduce the above copyright |
|---|
| 13 |
* notice, this list of conditions and the following disclaimer in the |
|---|
| 14 |
* documentation and/or other materials provided with the distribution. |
|---|
| 15 |
* 3. All advertising materials mentioning features or use of this software |
|---|
| 16 |
* must display the following acknowledgement: |
|---|
| 17 |
* This product includes software developed by the University of |
|---|
| 18 |
* California, Berkeley and its contributors. |
|---|
| 19 |
* 4. Neither the name of the University nor the names of its contributors |
|---|
| 20 |
* may be used to endorse or promote products derived from this software |
|---|
| 21 |
* without specific prior written permission. |
|---|
| 22 |
* |
|---|
| 23 |
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
|---|
| 24 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|---|
| 25 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|---|
| 26 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
|---|
| 27 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|---|
| 28 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
|---|
| 29 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|---|
| 30 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|---|
| 31 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|---|
| 32 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|---|
| 33 |
* SUCH DAMAGE. |
|---|
| 34 |
* |
|---|
| 35 |
* @(#)defs.h 8.1 (Berkeley) 6/4/93 |
|---|
| 36 |
*/ |
|---|
| 37 |
|
|---|
| 38 |
#ifndef _NOIT_CONSOLE_TELNET_H |
|---|
| 39 |
#define _NOIT_CONSOLE_TELNET_H |
|---|
| 40 |
|
|---|
| 41 |
#include "noit_defines.h" |
|---|
| 42 |
#include "utils/noit_hash.h" |
|---|
| 43 |
|
|---|
| 44 |
#include <arpa/telnet.h> |
|---|
| 45 |
#include <sys/ioctl.h> |
|---|
| 46 |
#ifdef HAVE_SYS_IOCTL_COMPAT_H |
|---|
| 47 |
#include <sys/ioctl_compat.h> |
|---|
| 48 |
#endif |
|---|
| 49 |
#ifdef HAVE_TERMIOS_H |
|---|
| 50 |
#include <termios.h> |
|---|
| 51 |
#endif |
|---|
| 52 |
#ifdef HAVE_TERM_H |
|---|
| 53 |
#include <term.h> |
|---|
| 54 |
#endif |
|---|
| 55 |
|
|---|
| 56 |
#if !defined(__linux__) |
|---|
| 57 |
/* At least _I_ can't get LINUMODE working on Linux */ |
|---|
| 58 |
#define LINEMODE 1 |
|---|
| 59 |
#endif |
|---|
| 60 |
|
|---|
| 61 |
#ifndef _POSIX_VDISABLE |
|---|
| 62 |
# ifdef VDISABLE |
|---|
| 63 |
# define _POSIX_VDISABLE VDISABLE |
|---|
| 64 |
# else |
|---|
| 65 |
# define _POSIX_VDISABLE ((unsigned char)'\377') |
|---|
| 66 |
# endif |
|---|
| 67 |
#endif |
|---|
| 68 |
|
|---|
| 69 |
/* |
|---|
| 70 |
* Structures of information for each special character function. |
|---|
| 71 |
*/ |
|---|
| 72 |
|
|---|
| 73 |
typedef struct { |
|---|
| 74 |
unsigned char flag; /* the flags for this function */ |
|---|
| 75 |
unsigned char val; /* the value of the special character */ |
|---|
| 76 |
} slcent, *Slcent; |
|---|
| 77 |
|
|---|
| 78 |
typedef struct { |
|---|
| 79 |
slcent defset; /* the default settings */ |
|---|
| 80 |
slcent current; /* the current settings */ |
|---|
| 81 |
unsigned char *sptr; /* a pointer to the char in */ |
|---|
| 82 |
/* system data structures */ |
|---|
| 83 |
} slcfun, *Slcfun; |
|---|
| 84 |
|
|---|
| 85 |
#ifndef USE_TERMIO |
|---|
| 86 |
struct termbuf { |
|---|
| 87 |
struct sgttyb sg; |
|---|
| 88 |
struct tchars tc; |
|---|
| 89 |
struct ltchars ltc; |
|---|
| 90 |
int state; |
|---|
| 91 |
int lflags; |
|---|
| 92 |
}; |
|---|
| 93 |
# define cfsetospeed(tp, val) (tp)->sg.sg_ospeed = (val) |
|---|
| 94 |
# define cfsetispeed(tp, val) (tp)->sg.sg_ispeed = (val) |
|---|
| 95 |
# define cfgetospeed(tp) (tp)->sg.sg_ospeed |
|---|
| 96 |
# define cfgetispeed(tp) (tp)->sg.sg_ispeed |
|---|
| 97 |
#else /* USE_TERMIO */ |
|---|
| 98 |
# ifndef TCSANOW |
|---|
| 99 |
# ifdef TCSETS |
|---|
| 100 |
# define TCSANOW TCSETS |
|---|
| 101 |
# define TCSADRAIN TCSETSW |
|---|
| 102 |
# define tcgetattr(f, t) ioctl(f, TCGETS, (char *)t) |
|---|
| 103 |
# else |
|---|
| 104 |
# ifdef TCSETA |
|---|
| 105 |
# define TCSANOW TCSETA |
|---|
| 106 |
# define TCSADRAIN TCSETAW |
|---|
| 107 |
# define tcgetattr(f, t) ioctl(f, TCGETA, (char *)t) |
|---|
| 108 |
# else |
|---|
| 109 |
# define TCSANOW TIOCSETA |
|---|
| 110 |
# define TCSADRAIN TIOCSETAW |
|---|
| 111 |
# define tcgetattr(f, t) ioctl(f, TIOCGETA, (char *)t) |
|---|
| 112 |
# endif |
|---|
| 113 |
# endif |
|---|
| 114 |
# define tcsetattr(f, a, t) ioctl(f, a, t) |
|---|
| 115 |
# define cfsetospeed(tp, val) (tp)->c_cflag &= ~CBAUD; \ |
|---|
| 116 |
(tp)->c_cflag |= (val) |
|---|
| 117 |
# define cfgetospeed(tp) ((tp)->c_cflag & CBAUD) |
|---|
| 118 |
# ifdef CIBAUD |
|---|
| 119 |
# define cfsetispeed(tp, val) (tp)->c_cflag &= ~CIBAUD; \ |
|---|
| 120 |
(tp)->c_cflag |= ((val)<<IBSHIFT) |
|---|
| 121 |
# define cfgetispeed(tp) (((tp)->c_cflag & CIBAUD)>>IBSHIFT) |
|---|
| 122 |
# else |
|---|
| 123 |
# define cfsetispeed(tp, val) (tp)->c_cflag &= ~CBAUD; \ |
|---|
| 124 |
(tp)->c_cflag |= (val) |
|---|
| 125 |
# define cfgetispeed(tp) ((tp)->c_cflag & CBAUD) |
|---|
| 126 |
# endif |
|---|
| 127 |
# endif /* TCSANOW */ |
|---|
| 128 |
#endif /* USE_TERMIO */ |
|---|
| 129 |
|
|---|
| 130 |
/* |
|---|
| 131 |
* The following are some clocks used to decide how to interpret |
|---|
| 132 |
* the relationship between various variables. |
|---|
| 133 |
*/ |
|---|
| 134 |
|
|---|
| 135 |
struct clocks_t { |
|---|
| 136 |
int |
|---|
| 137 |
system, /* what the current time is */ |
|---|
| 138 |
echotoggle, /* last time user entered echo character */ |
|---|
| 139 |
modenegotiated, /* last time operating mode negotiated */ |
|---|
| 140 |
didnetreceive, /* last time we read data from network */ |
|---|
| 141 |
ttypesubopt, /* ttype subopt is received */ |
|---|
| 142 |
tspeedsubopt, /* tspeed subopt is received */ |
|---|
| 143 |
environsubopt, /* environ subopt is received */ |
|---|
| 144 |
oenvironsubopt, /* old environ subopt is received */ |
|---|
| 145 |
xdisplocsubopt, /* xdisploc subopt is received */ |
|---|
| 146 |
baseline, /* time started to do timed action */ |
|---|
| 147 |
gotDM; /* when did we last see a data mark */ |
|---|
| 148 |
}; |
|---|
| 149 |
|
|---|
| 150 |
typedef struct { |
|---|
| 151 |
noit_hash_table _env; |
|---|
| 152 |
unsigned char *_subbuffer; |
|---|
| 153 |
unsigned char *_subpointer; |
|---|
| 154 |
unsigned char *_subend; |
|---|
| 155 |
unsigned char *_subsave; |
|---|
| 156 |
unsigned char _pty_buf[1024]; |
|---|
| 157 |
int _pty_fill; |
|---|
| 158 |
slcfun _slctab[NSLC + 1]; |
|---|
| 159 |
char _options[256]; |
|---|
| 160 |
char _do_dont_resp[256]; |
|---|
| 161 |
char _will_wont_resp[256]; |
|---|
| 162 |
int _SYNCHing; |
|---|
| 163 |
int _flowmode; |
|---|
| 164 |
int _restartany; |
|---|
| 165 |
int __terminit; |
|---|
| 166 |
int _linemode; |
|---|
| 167 |
int _uselinemode; |
|---|
| 168 |
int _alwayslinemode; |
|---|
| 169 |
int _editmode; |
|---|
| 170 |
int _useeditmode; |
|---|
| 171 |
unsigned char *_def_slcbuf; |
|---|
| 172 |
int _def_slclen; |
|---|
| 173 |
int _slcchange; /* change to slc is requested */ |
|---|
| 174 |
unsigned char *_slcptr; /* pointer into slc buffer */ |
|---|
| 175 |
unsigned char _slcbuf[NSLC*6]; /* buffer for slc negotiation */ |
|---|
| 176 |
|
|---|
| 177 |
int _def_tspeed; /* This one */ |
|---|
| 178 |
int _def_rspeed; /* and this one, need init to -1 */ |
|---|
| 179 |
#if !defined(LINEMODE) || !defined(KLUDGELINEMODE) |
|---|
| 180 |
int _turn_on_sga; |
|---|
| 181 |
#endif |
|---|
| 182 |
#ifdef TIOCSWINSZ |
|---|
| 183 |
int _def_row; |
|---|
| 184 |
int _def_col; |
|---|
| 185 |
#endif |
|---|
| 186 |
char _terminalname[41]; |
|---|
| 187 |
struct clocks_t _clocks; |
|---|
| 188 |
#ifdef USE_TERMIO |
|---|
| 189 |
struct termios _termbuf, _termbuf2; /* pty control structure */ |
|---|
| 190 |
#else |
|---|
| 191 |
struct termbuf _termbuf, _termbuf2; /* pty control structure */ |
|---|
| 192 |
#endif |
|---|
| 193 |
} *noit_console_telnet_closure_t; |
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
/* |
|---|
| 197 |
* We keep track of each side of the option negotiation. |
|---|
| 198 |
*/ |
|---|
| 199 |
|
|---|
| 200 |
#define MY_STATE_WILL 0x01 |
|---|
| 201 |
#define MY_WANT_STATE_WILL 0x02 |
|---|
| 202 |
#define MY_STATE_DO 0x04 |
|---|
| 203 |
#define MY_WANT_STATE_DO 0x08 |
|---|
| 204 |
|
|---|
| 205 |
/* |
|---|
| 206 |
* Macros to check the current state of things |
|---|
| 207 |
*/ |
|---|
| 208 |
|
|---|
| 209 |
#define my_state_is_do(opt) (ncct->telnet->_options[opt]&MY_STATE_DO) |
|---|
| 210 |
#define my_state_is_will(opt) (ncct->telnet->_options[opt]&MY_STATE_WILL) |
|---|
| 211 |
#define my_want_state_is_do(opt) (ncct->telnet->_options[opt]&MY_WANT_STATE_DO) |
|---|
| 212 |
#define my_want_state_is_will(opt) (ncct->telnet->_options[opt]&MY_WANT_STATE_WILL) |
|---|
| 213 |
|
|---|
| 214 |
#define my_state_is_dont(opt) (!my_state_is_do(opt)) |
|---|
| 215 |
#define my_state_is_wont(opt) (!my_state_is_will(opt)) |
|---|
| 216 |
#define my_want_state_is_dont(opt) (!my_want_state_is_do(opt)) |
|---|
| 217 |
#define my_want_state_is_wont(opt) (!my_want_state_is_will(opt)) |
|---|
| 218 |
|
|---|
| 219 |
#define set_my_state_do(opt) (ncct->telnet->_options[opt] |= MY_STATE_DO) |
|---|
| 220 |
#define set_my_state_will(opt) (ncct->telnet->_options[opt] |= MY_STATE_WILL) |
|---|
| 221 |
#define set_my_want_state_do(opt) (ncct->telnet->_options[opt] |= MY_WANT_STATE_DO) |
|---|
| 222 |
#define set_my_want_state_will(opt) (ncct->telnet->_options[opt] |= MY_WANT_STATE_WILL) |
|---|
| 223 |
|
|---|
| 224 |
#define set_my_state_dont(opt) (ncct->telnet->_options[opt] &= ~MY_STATE_DO) |
|---|
| 225 |
#define set_my_state_wont(opt) (ncct->telnet->_options[opt] &= ~MY_STATE_WILL) |
|---|
| 226 |
#define set_my_want_state_dont(opt) (ncct->telnet->_options[opt] &= ~MY_WANT_STATE_DO) |
|---|
| 227 |
#define set_my_want_state_wont(opt) (ncct->telnet->_options[opt] &= ~MY_WANT_STATE_WILL) |
|---|
| 228 |
|
|---|
| 229 |
/* |
|---|
| 230 |
* Tricky code here. What we want to know is if the MY_STATE_WILL |
|---|
| 231 |
* and MY_WANT_STATE_WILL bits have the same value. Since the two |
|---|
| 232 |
* bits are adjacent, a little arithmatic will show that by adding |
|---|
| 233 |
* in the lower bit, the upper bit will be set if the two bits were |
|---|
| 234 |
* different, and clear if they were the same. |
|---|
| 235 |
*/ |
|---|
| 236 |
#define my_will_wont_is_changing(opt) \ |
|---|
| 237 |
((ncct->telnet->_options[opt]+MY_STATE_WILL) & MY_WANT_STATE_WILL) |
|---|
| 238 |
|
|---|
| 239 |
#define my_do_dont_is_changing(opt) \ |
|---|
| 240 |
((ncct->telnet->_options[opt]+MY_STATE_DO) & MY_WANT_STATE_DO) |
|---|
| 241 |
|
|---|
| 242 |
/* |
|---|
| 243 |
* Make everything symmetrical |
|---|
| 244 |
*/ |
|---|
| 245 |
|
|---|
| 246 |
#define HIS_STATE_WILL MY_STATE_DO |
|---|
| 247 |
#define HIS_WANT_STATE_WILL MY_WANT_STATE_DO |
|---|
| 248 |
#define HIS_STATE_DO MY_STATE_WILL |
|---|
| 249 |
#define HIS_WANT_STATE_DO MY_WANT_STATE_WILL |
|---|
| 250 |
|
|---|
| 251 |
#define his_state_is_do my_state_is_will |
|---|
| 252 |
#define his_state_is_will my_state_is_do |
|---|
| 253 |
#define his_want_state_is_do my_want_state_is_will |
|---|
| 254 |
#define his_want_state_is_will my_want_state_is_do |
|---|
| 255 |
|
|---|
| 256 |
#define his_state_is_dont my_state_is_wont |
|---|
| 257 |
#define his_state_is_wont my_state_is_dont |
|---|
| 258 |
#define his_want_state_is_dont my_want_state_is_wont |
|---|
| 259 |
#define his_want_state_is_wont my_want_state_is_dont |
|---|
| 260 |
|
|---|
| 261 |
#define set_his_state_do set_my_state_will |
|---|
| 262 |
#define set_his_state_will set_my_state_do |
|---|
| 263 |
#define set_his_want_state_do set_my_want_state_will |
|---|
| 264 |
#define set_his_want_state_will set_my_want_state_do |
|---|
| 265 |
|
|---|
| 266 |
#define set_his_state_dont set_my_state_wont |
|---|
| 267 |
#define set_his_state_wont set_my_state_dont |
|---|
| 268 |
#define set_his_want_state_dont set_my_want_state_wont |
|---|
| 269 |
#define set_his_want_state_wont set_my_want_state_dont |
|---|
| 270 |
|
|---|
| 271 |
#define his_will_wont_is_changing my_do_dont_is_changing |
|---|
| 272 |
#define his_do_dont_is_changing my_will_wont_is_changing |
|---|
| 273 |
|
|---|
| 274 |
struct __noit_console_closure; |
|---|
| 275 |
void |
|---|
| 276 |
noit_console_telnet_willoption(struct __noit_console_closure *ncct, |
|---|
| 277 |
int option); |
|---|
| 278 |
void |
|---|
| 279 |
noit_console_telnet_wontoption(struct __noit_console_closure *ncct, |
|---|
| 280 |
int option); |
|---|
| 281 |
void |
|---|
| 282 |
noit_console_telnet_dooption(struct __noit_console_closure *ncct, |
|---|
| 283 |
int option); |
|---|
| 284 |
void |
|---|
| 285 |
noit_console_telnet_dontoption(struct __noit_console_closure *ncct, |
|---|
| 286 |
int option); |
|---|
| 287 |
void |
|---|
| 288 |
noit_console_telnet_send_do(struct __noit_console_closure *ncct, |
|---|
| 289 |
int option, int init); |
|---|
| 290 |
void |
|---|
| 291 |
noit_console_telnet_send_dont(struct __noit_console_closure *ncct, |
|---|
| 292 |
int option, int init); |
|---|
| 293 |
void |
|---|
| 294 |
noit_console_telnet_send_will(struct __noit_console_closure *ncct, |
|---|
| 295 |
int option, int init); |
|---|
| 296 |
void |
|---|
| 297 |
noit_console_telnet_send_wont(struct __noit_console_closure *ncct, |
|---|
| 298 |
int option, int init); |
|---|
| 299 |
void |
|---|
| 300 |
noit_console_telnet_doclientstat(struct __noit_console_closure *ncct); |
|---|
| 301 |
void |
|---|
| 302 |
noit_console_telnet_send_status(struct __noit_console_closure *ncct); |
|---|
| 303 |
|
|---|
| 304 |
void noit_console_telnet_free(noit_console_telnet_closure_t); |
|---|
| 305 |
noit_console_telnet_closure_t |
|---|
| 306 |
noit_console_telnet_alloc(struct __noit_console_closure *ncct); |
|---|
| 307 |
int |
|---|
| 308 |
noit_console_telnet_telrcv(struct __noit_console_closure *ncct, |
|---|
| 309 |
const void *buf, int buflen); |
|---|
| 310 |
void ptyflush(struct __noit_console_closure *ncct); |
|---|
| 311 |
|
|---|
| 312 |
#endif |
|---|