Initial import from FreeBSD RELENG_4:
[dragonfly.git] / crypto / kerberosIV / appl / telnet / telnet / externs.h
1 /*
2  * Copyright (c) 1988, 1990, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by the University of
16  *      California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  *      @(#)externs.h   8.3 (Berkeley) 5/30/95
34  */
35
36 /* $Id: externs.h,v 1.18 1998/07/09 23:16:36 assar Exp $ */
37
38 #ifndef BSD
39 # define BSD 43
40 #endif
41
42 #ifndef _POSIX_VDISABLE
43 # ifdef sun
44 #  include <sys/param.h>        /* pick up VDISABLE definition, mayby */
45 # endif
46 # ifdef VDISABLE
47 #  define _POSIX_VDISABLE VDISABLE
48 # else
49 #  define _POSIX_VDISABLE ((cc_t)'\377')
50 # endif
51 #endif
52
53 #define SUBBUFSIZE      256
54
55 extern int
56     autologin,          /* Autologin enabled */
57     skiprc,             /* Don't process the ~/.telnetrc file */
58     eight,              /* use eight bit mode (binary in and/or out */
59     binary,
60     flushout,           /* flush output */
61     connected,          /* Are we connected to the other side? */
62     globalmode,         /* Mode tty should be in */
63     telnetport,         /* Are we connected to the telnet port? */
64     localflow,          /* Flow control handled locally */
65     restartany,         /* If flow control, restart output on any character */
66     localchars,         /* we recognize interrupt/quit */
67     donelclchars,       /* the user has set "localchars" */
68     showoptions,
69     net,                /* Network file descriptor */
70     tin,                /* Terminal input file descriptor */
71     tout,               /* Terminal output file descriptor */
72     crlf,               /* Should '\r' be mapped to <CR><LF> (or <CR><NUL>)? */
73     autoflush,          /* flush output when interrupting? */
74     autosynch,          /* send interrupt characters with SYNCH? */
75     SYNCHing,           /* Is the stream in telnet SYNCH mode? */
76     donebinarytoggle,   /* the user has put us in binary */
77     dontlecho,          /* do we suppress local echoing right now? */
78     crmod,
79     netdata,            /* Print out network data flow */
80     prettydump,         /* Print "netdata" output in user readable format */
81     termdata,           /* Print out terminal data flow */
82     debug;              /* Debug level */
83
84 extern cc_t escape;     /* Escape to command mode */
85 extern cc_t rlogin;     /* Rlogin mode escape character */
86 #ifdef  KLUDGELINEMODE
87 extern cc_t echoc;      /* Toggle local echoing */
88 #endif
89
90 extern char
91     *prompt;            /* Prompt for command. */
92
93 extern char
94     doopt[],
95     dont[],
96     will[],
97     wont[],
98     options[],          /* All the little options */
99     *hostname;          /* Who are we connected to? */
100 #if     defined(ENCRYPTION)
101 extern void (*encrypt_output) (unsigned char *, int);
102 extern int (*decrypt_input) (int);
103 #endif
104
105 /*
106  * We keep track of each side of the option negotiation.
107  */
108
109 #define MY_STATE_WILL           0x01
110 #define MY_WANT_STATE_WILL      0x02
111 #define MY_STATE_DO             0x04
112 #define MY_WANT_STATE_DO        0x08
113
114 /*
115  * Macros to check the current state of things
116  */
117
118 #define my_state_is_do(opt)             (options[opt]&MY_STATE_DO)
119 #define my_state_is_will(opt)           (options[opt]&MY_STATE_WILL)
120 #define my_want_state_is_do(opt)        (options[opt]&MY_WANT_STATE_DO)
121 #define my_want_state_is_will(opt)      (options[opt]&MY_WANT_STATE_WILL)
122
123 #define my_state_is_dont(opt)           (!my_state_is_do(opt))
124 #define my_state_is_wont(opt)           (!my_state_is_will(opt))
125 #define my_want_state_is_dont(opt)      (!my_want_state_is_do(opt))
126 #define my_want_state_is_wont(opt)      (!my_want_state_is_will(opt))
127
128 #define set_my_state_do(opt)            {options[opt] |= MY_STATE_DO;}
129 #define set_my_state_will(opt)          {options[opt] |= MY_STATE_WILL;}
130 #define set_my_want_state_do(opt)       {options[opt] |= MY_WANT_STATE_DO;}
131 #define set_my_want_state_will(opt)     {options[opt] |= MY_WANT_STATE_WILL;}
132
133 #define set_my_state_dont(opt)          {options[opt] &= ~MY_STATE_DO;}
134 #define set_my_state_wont(opt)          {options[opt] &= ~MY_STATE_WILL;}
135 #define set_my_want_state_dont(opt)     {options[opt] &= ~MY_WANT_STATE_DO;}
136 #define set_my_want_state_wont(opt)     {options[opt] &= ~MY_WANT_STATE_WILL;}
137
138 /*
139  * Make everything symetrical
140  */
141
142 #define HIS_STATE_WILL                  MY_STATE_DO
143 #define HIS_WANT_STATE_WILL             MY_WANT_STATE_DO
144 #define HIS_STATE_DO                    MY_STATE_WILL
145 #define HIS_WANT_STATE_DO               MY_WANT_STATE_WILL
146
147 #define his_state_is_do                 my_state_is_will
148 #define his_state_is_will               my_state_is_do
149 #define his_want_state_is_do            my_want_state_is_will
150 #define his_want_state_is_will          my_want_state_is_do
151
152 #define his_state_is_dont               my_state_is_wont
153 #define his_state_is_wont               my_state_is_dont
154 #define his_want_state_is_dont          my_want_state_is_wont
155 #define his_want_state_is_wont          my_want_state_is_dont
156
157 #define set_his_state_do                set_my_state_will
158 #define set_his_state_will              set_my_state_do
159 #define set_his_want_state_do           set_my_want_state_will
160 #define set_his_want_state_will         set_my_want_state_do
161
162 #define set_his_state_dont              set_my_state_wont
163 #define set_his_state_wont              set_my_state_dont
164 #define set_his_want_state_dont         set_my_want_state_wont
165 #define set_his_want_state_wont         set_my_want_state_dont
166
167
168 extern FILE
169     *NetTrace;          /* Where debugging output goes */
170 extern char
171     NetTraceFile[];     /* Name of file where debugging output goes */
172 extern void
173     SetNetTrace (char *);       /* Function to change where debugging goes */
174
175 extern jmp_buf
176     peerdied,
177     toplevel;           /* For error conditions. */
178
179 /* authenc.c */
180
181 #if     defined(AUTHENTICATION) || defined(ENCRYPTION)
182 int telnet_net_write(unsigned char *str, int len);
183 void net_encrypt(void);
184 int telnet_spin(void);
185 char *telnet_getenv(char *val);
186 char *telnet_gets(char *prompt, char *result, int length, int echo);
187 #endif
188
189 /* commands.c */
190
191 struct env_lst *env_define (unsigned char *, unsigned char *);
192 struct env_lst *env_find(unsigned char *var);
193 void env_init (void);
194 void env_undefine (unsigned char *);
195 void env_export (unsigned char *);
196 void env_unexport (unsigned char *);
197 void env_send (unsigned char *);
198 void env_list (void);
199 unsigned char * env_default(int init, int welldefined);
200 unsigned char * env_getvalue(unsigned char *var);
201
202 void set_escape_char(char *s);
203 unsigned long sourceroute(char *arg, char **cpp, int *lenp);
204
205 #if     defined(AUTHENTICATION)
206 int auth_enable (char *);
207 int auth_disable (char *);
208 int auth_status (void);
209 #endif
210
211 #if defined(ENCRYPTION)
212 int     EncryptEnable (char *, char *);
213 int     EncryptDisable (char *, char *);
214 int     EncryptType (char *, char *);
215 int     EncryptStart (char *);
216 int     EncryptStartInput (void);
217 int     EncryptStartOutput (void);
218 int     EncryptStop (char *);
219 int     EncryptStopInput (void);
220 int     EncryptStopOutput (void);
221 int     EncryptStatus (void);
222 #endif
223
224 #ifdef SIGINFO
225 void ayt_status(int);
226 #endif
227 int tn(int argc, char **argv);
228 void command(int top, char *tbuf, int cnt);
229
230 /* main.c */
231
232 void tninit(void);
233 void usage(void);
234
235 /* network.c */
236
237 void init_network(void);
238 int stilloob(void);
239 void setneturg(void);
240 int netflush(void);
241
242 /* sys_bsd.c */
243
244 void init_sys(void);
245 int TerminalWrite(char *buf, int n);
246 int TerminalRead(unsigned char *buf, int n);
247 int TerminalAutoFlush(void);
248 int TerminalSpecialChars(int c);
249 void TerminalFlushOutput(void);
250 void TerminalSaveState(void);
251 void TerminalDefaultChars(void);
252 void TerminalNewMode(int f);
253 cc_t *tcval(int func);
254 void TerminalSpeeds(long *input_speed, long *output_speed);
255 int TerminalWindowSize(long *rows, long *cols);
256 int NetClose(int fd);
257 void NetNonblockingIO(int fd, int onoff);
258 int process_rings(int netin, int netout, int netex, int ttyin, int ttyout,
259                   int poll);
260
261 /* telnet.c */
262
263 void init_telnet(void);
264
265 void tel_leave_binary(int rw);
266 void tel_enter_binary(int rw);
267 int opt_welldefined(char *ep);
268 int telrcv(void);
269 int rlogin_susp(void);
270 void intp(void);
271 void sendbrk(void);
272 void sendabort(void);
273 void sendsusp(void);
274 void sendeof(void);
275 void sendayt(void);
276
277 void xmitAO(void);
278 void xmitEL(void);
279 void xmitEC(void);
280
281
282 void     Dump (char, unsigned char *, int);
283 void     printoption (char *, int, int);
284 void     printsub (int, unsigned char *, int);
285 void     sendnaws (void);
286 void     setconnmode (int);
287 void     setcommandmode (void);
288 void     setneturg (void);
289 void     sys_telnet_init (void);
290 void     my_telnet (char *);
291 void     tel_enter_binary (int);
292 void     TerminalFlushOutput (void);
293 void     TerminalNewMode (int);
294 void     TerminalRestoreState (void);
295 void     TerminalSaveState (void);
296 void     tninit (void);
297 void     willoption (int);
298 void     wontoption (int);
299
300
301 void     send_do (int, int);
302 void     send_dont (int, int);
303 void     send_will (int, int);
304 void     send_wont (int, int);
305
306 void     lm_will (unsigned char *, int);
307 void     lm_wont (unsigned char *, int);
308 void     lm_do (unsigned char *, int);
309 void     lm_dont (unsigned char *, int);
310 void     lm_mode (unsigned char *, int, int);
311
312 void     slc_init (void);
313 void     slcstate (void);
314 void     slc_mode_export (void);
315 void     slc_mode_import (int);
316 void     slc_import (int);
317 void     slc_export (void);
318 void     slc (unsigned char *, int);
319 void     slc_check (void);
320 void     slc_start_reply (void);
321 void     slc_add_reply (unsigned char, unsigned char, cc_t);
322 void     slc_end_reply (void);
323 int      slc_update (void);
324
325 void     env_opt (unsigned char *, int);
326 void     env_opt_start (void);
327 void     env_opt_start_info (void);
328 void     env_opt_add (unsigned char *);
329 void     env_opt_end (int);
330
331 unsigned char     *env_default (int, int);
332 unsigned char     *env_getvalue (unsigned char *);
333
334 int get_status (void);
335 int dosynch (void);
336
337 cc_t *tcval (int);
338
339 int quit (void);
340
341 /* terminal.c */
342
343 void init_terminal(void);
344 int ttyflush(int drop);
345 int getconnmode(void);
346
347 /* utilities.c */
348
349 int SetSockOpt(int fd, int level, int option, int yesno);
350 void SetNetTrace(char *file);
351 void Dump(char direction, unsigned char *buffer, int length);
352 void printoption(char *direction, int cmd, int option);
353 void optionstatus(void);
354 void printsub(int direction, unsigned char *pointer, int length);
355 void EmptyTerminal(void);
356 void SetForExit(void);
357 void Exit(int returnCode);
358 void ExitString(char *string, int returnCode);
359
360 extern struct   termios new_tc;
361
362 # define termEofChar            new_tc.c_cc[VEOF]
363 # define termEraseChar          new_tc.c_cc[VERASE]
364 # define termIntChar            new_tc.c_cc[VINTR]
365 # define termKillChar           new_tc.c_cc[VKILL]
366 # define termQuitChar           new_tc.c_cc[VQUIT]
367
368 # ifndef        VSUSP
369 extern cc_t termSuspChar;
370 # else
371 #  define termSuspChar          new_tc.c_cc[VSUSP]
372 # endif
373 # if    defined(VFLUSHO) && !defined(VDISCARD)
374 #  define VDISCARD VFLUSHO
375 # endif
376 # ifndef        VDISCARD
377 extern cc_t termFlushChar;
378 # else
379 #  define termFlushChar         new_tc.c_cc[VDISCARD]
380 # endif
381 # ifndef VWERASE
382 extern cc_t termWerasChar;
383 # else
384 #  define termWerasChar         new_tc.c_cc[VWERASE]
385 # endif
386 # ifndef        VREPRINT
387 extern cc_t termRprntChar;
388 # else
389 #  define termRprntChar         new_tc.c_cc[VREPRINT]
390 # endif
391 # ifndef        VLNEXT
392 extern cc_t termLiteralNextChar;
393 # else
394 #  define termLiteralNextChar   new_tc.c_cc[VLNEXT]
395 # endif
396 # ifndef        VSTART
397 extern cc_t termStartChar;
398 # else
399 #  define termStartChar         new_tc.c_cc[VSTART]
400 # endif
401 # ifndef        VSTOP
402 extern cc_t termStopChar;
403 # else
404 #  define termStopChar          new_tc.c_cc[VSTOP]
405 # endif
406 # ifndef        VEOL
407 extern cc_t termForw1Char;
408 # else
409 #  define termForw1Char         new_tc.c_cc[VEOL]
410 # endif
411 # ifndef        VEOL2
412 extern cc_t termForw2Char;
413 # else
414 #  define termForw2Char         new_tc.c_cc[VEOL]
415 # endif
416 # ifndef        VSTATUS
417 extern cc_t termAytChar;
418 #else
419 #  define termAytChar           new_tc.c_cc[VSTATUS]
420 #endif
421
422 /* Ring buffer structures which are shared */
423
424 extern Ring
425     netoring,
426     netiring,
427     ttyoring,
428     ttyiring;
429