xref: /original-bsd/usr.bin/telnet/externs.h (revision 6884d44a)
1 /*
2  * Copyright (c) 1988, 1990 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)externs.h	5.3 (Berkeley) 03/22/91
8  */
9 
10 #ifndef	BSD
11 # define BSD 43
12 #endif
13 
14 #if (BSD > 43 || defined(SYSV_TERMIO)) && !defined(USE_TERMIO)
15 # define USE_TERMIO
16 #endif
17 
18 #include <stdio.h>
19 #include <setjmp.h>
20 #ifndef	FILIO_H
21 #include <sys/ioctl.h>
22 #else
23 #include <sys/filio.h>
24 #endif
25 #ifdef	USE_TERMIO
26 # ifndef	VINTR
27 #  ifdef SYSV_TERMIO
28 #   include <sys/termio.h>
29 #  else
30 #   include <sys/termios.h>
31 #   define termio termios
32 #  endif
33 # endif
34 #endif
35 #if defined(NO_CC_T) || !defined(USE_TERMIO)
36 # if !defined(USE_TERMIO)
37 typedef char cc_t;
38 # else
39 typedef unsigned char cc_t;
40 # endif
41 #endif
42 
43 #ifndef	NO_STRING_H
44 #include <string.h>
45 #endif
46 #include <strings.h>
47 
48 #ifndef	_POSIX_VDISABLE
49 # ifdef sun
50 #  include <sys/param.h>	/* pick up VDISABLE definition, mayby */
51 # endif
52 # ifdef VDISABLE
53 #  define _POSIX_VDISABLE VDISABLE
54 # else
55 #  define _POSIX_VDISABLE ((cc_t)'\377')
56 # endif
57 #endif
58 
59 #define	SUBBUFSIZE	256
60 
61 extern int errno;		/* outside this world */
62 
63 #if	!defined(P)
64 # ifdef	__STDC__
65 #  define	P(x)	x
66 # else
67 #  define	P(x)	()
68 # endif
69 #endif
70 
71 extern int
72     autologin,		/* Autologin enabled */
73     skiprc,		/* Don't process the ~/.telnetrc file */
74     eight,		/* use eight bit mode (binary in and/or out */
75     flushout,		/* flush output */
76     connected,		/* Are we connected to the other side? */
77     globalmode,		/* Mode tty should be in */
78     In3270,			/* Are we in 3270 mode? */
79     telnetport,		/* Are we connected to the telnet port? */
80     localflow,		/* Flow control handled locally */
81     localchars,		/* we recognize interrupt/quit */
82     donelclchars,		/* the user has set "localchars" */
83     showoptions,
84     net,		/* Network file descriptor */
85     tin,		/* Terminal input file descriptor */
86     tout,		/* Terminal output file descriptor */
87     crlf,		/* Should '\r' be mapped to <CR><LF> (or <CR><NUL>)? */
88     autoflush,		/* flush output when interrupting? */
89     autosynch,		/* send interrupt characters with SYNCH? */
90     SYNCHing,		/* Is the stream in telnet SYNCH mode? */
91     donebinarytoggle,	/* the user has put us in binary */
92     dontlecho,		/* do we suppress local echoing right now? */
93     crmod,
94     netdata,		/* Print out network data flow */
95     prettydump,		/* Print "netdata" output in user readable format */
96 #if	defined(unix)
97 #if	defined(TN3270)
98     cursesdata,		/* Print out curses data flow */
99     apitrace,		/* Trace API transactions */
100 #endif	/* defined(TN3270) */
101     termdata,		/* Print out terminal data flow */
102 #endif	/* defined(unix) */
103     debug;			/* Debug level */
104 
105 extern cc_t escape;	/* Escape to command mode */
106 extern cc_t rlogin;	/* Rlogin mode escape character */
107 #ifdef	KLUDGELINEMODE
108 extern cc_t echoc;	/* Toggle local echoing */
109 #endif
110 
111 extern char
112     *prompt;		/* Prompt for command. */
113 
114 extern char
115     doopt[],
116     dont[],
117     will[],
118     wont[],
119     options[],		/* All the little options */
120     *hostname;		/* Who are we connected to? */
121 #if	defined(ENCRYPT)
122 extern void (*encrypt_output) P((unsigned char *, int));
123 extern int (*decrypt_input) P((int));
124 #endif
125 
126 /*
127  * We keep track of each side of the option negotiation.
128  */
129 
130 #define	MY_STATE_WILL		0x01
131 #define	MY_WANT_STATE_WILL	0x02
132 #define	MY_STATE_DO		0x04
133 #define	MY_WANT_STATE_DO	0x08
134 
135 /*
136  * Macros to check the current state of things
137  */
138 
139 #define	my_state_is_do(opt)		(options[opt]&MY_STATE_DO)
140 #define	my_state_is_will(opt)		(options[opt]&MY_STATE_WILL)
141 #define my_want_state_is_do(opt)	(options[opt]&MY_WANT_STATE_DO)
142 #define my_want_state_is_will(opt)	(options[opt]&MY_WANT_STATE_WILL)
143 
144 #define	my_state_is_dont(opt)		(!my_state_is_do(opt))
145 #define	my_state_is_wont(opt)		(!my_state_is_will(opt))
146 #define my_want_state_is_dont(opt)	(!my_want_state_is_do(opt))
147 #define my_want_state_is_wont(opt)	(!my_want_state_is_will(opt))
148 
149 #define	set_my_state_do(opt)		{options[opt] |= MY_STATE_DO;}
150 #define	set_my_state_will(opt)		{options[opt] |= MY_STATE_WILL;}
151 #define	set_my_want_state_do(opt)	{options[opt] |= MY_WANT_STATE_DO;}
152 #define	set_my_want_state_will(opt)	{options[opt] |= MY_WANT_STATE_WILL;}
153 
154 #define	set_my_state_dont(opt)		{options[opt] &= ~MY_STATE_DO;}
155 #define	set_my_state_wont(opt)		{options[opt] &= ~MY_STATE_WILL;}
156 #define	set_my_want_state_dont(opt)	{options[opt] &= ~MY_WANT_STATE_DO;}
157 #define	set_my_want_state_wont(opt)	{options[opt] &= ~MY_WANT_STATE_WILL;}
158 
159 /*
160  * Make everything symetrical
161  */
162 
163 #define	HIS_STATE_WILL			MY_STATE_DO
164 #define	HIS_WANT_STATE_WILL		MY_WANT_STATE_DO
165 #define HIS_STATE_DO			MY_STATE_WILL
166 #define HIS_WANT_STATE_DO		MY_WANT_STATE_WILL
167 
168 #define	his_state_is_do			my_state_is_will
169 #define	his_state_is_will		my_state_is_do
170 #define his_want_state_is_do		my_want_state_is_will
171 #define his_want_state_is_will		my_want_state_is_do
172 
173 #define	his_state_is_dont		my_state_is_wont
174 #define	his_state_is_wont		my_state_is_dont
175 #define his_want_state_is_dont		my_want_state_is_wont
176 #define his_want_state_is_wont		my_want_state_is_dont
177 
178 #define	set_his_state_do		set_my_state_will
179 #define	set_his_state_will		set_my_state_do
180 #define	set_his_want_state_do		set_my_want_state_will
181 #define	set_his_want_state_will		set_my_want_state_do
182 
183 #define	set_his_state_dont		set_my_state_wont
184 #define	set_his_state_wont		set_my_state_dont
185 #define	set_his_want_state_dont		set_my_want_state_wont
186 #define	set_his_want_state_wont		set_my_want_state_dont
187 
188 
189 extern FILE
190     *NetTrace;		/* Where debugging output goes */
191 extern unsigned char
192     NetTraceFile[];	/* Name of file where debugging output goes */
193 extern void
194     SetNetTrace P((char *));	/* Function to change where debugging goes */
195 
196 extern jmp_buf
197     peerdied,
198     toplevel;		/* For error conditions. */
199 
200 extern void
201     command P((int, char *, int)),
202     Dump P((int, unsigned char *, int)),
203     init_3270 P((void)),
204     printoption P((char *, int, int)),
205     printsub P((int, unsigned char *, int)),
206     sendnaws P((void)),
207     setconnmode P((int)),
208     setcommandmode P((void)),
209     setneturg P((void)),
210     sys_telnet_init P((void)),
211     telnet P((char *)),
212     tel_enter_binary P((int)),
213     TerminalFlushOutput P((void)),
214     TerminalNewMode P((int)),
215     TerminalRestoreState P((void)),
216     TerminalSaveState P((void)),
217     tninit P((void)),
218     upcase P((char *)),
219     willoption P((int)),
220     wontoption P((int));
221 
222 extern void
223     lm_will P((unsigned char *, int)),
224     lm_wont P((unsigned char *, int)),
225     lm_do P((unsigned char *, int)),
226     lm_dont P((unsigned char *, int)),
227     lm_mode P((unsigned char *, int, int));
228 
229 extern void
230     slc_init P((void)),
231     slcstate P((void)),
232     slc_mode_export P((void)),
233     slc_mode_import P((int)),
234     slc_import P((int)),
235     slc_export P((void)),
236     slc P((unsigned char *, int)),
237     slc_check P((void)),
238     slc_start_reply P((void)),
239     slc_add_reply P((int, int, int)),
240     slc_end_reply P((void));
241 extern int
242     slc_update P((void));
243 
244 extern void
245     env_opt P((unsigned char *, int)),
246     env_opt_start P((void)),
247     env_opt_start_info P((void)),
248     env_opt_add P((unsigned char *)),
249     env_opt_end P((int));
250 
251 extern unsigned char
252     *env_default P((int)),
253     *env_getvalue P((unsigned char *));
254 
255 extern int
256     get_status P((void)),
257     dosynch P((void));
258 
259 extern cc_t
260     *tcval P((int));
261 
262 #ifndef	USE_TERMIO
263 
264 extern struct	tchars ntc;
265 extern struct	ltchars nltc;
266 extern struct	sgttyb nttyb;
267 
268 # define termEofChar		ntc.t_eofc
269 # define termEraseChar		nttyb.sg_erase
270 # define termFlushChar		nltc.t_flushc
271 # define termIntChar		ntc.t_intrc
272 # define termKillChar		nttyb.sg_kill
273 # define termLiteralNextChar	nltc.t_lnextc
274 # define termQuitChar		ntc.t_quitc
275 # define termSuspChar		nltc.t_suspc
276 # define termRprntChar		nltc.t_rprntc
277 # define termWerasChar		nltc.t_werasc
278 # define termStartChar		ntc.t_startc
279 # define termStopChar		ntc.t_stopc
280 # define termForw1Char		ntc.t_brkc
281 extern cc_t termForw2Char;
282 extern cc_t termAytChar;
283 
284 # define termEofCharp		(cc_t *)&ntc.t_eofc
285 # define termEraseCharp		(cc_t *)&nttyb.sg_erase
286 # define termFlushCharp		(cc_t *)&nltc.t_flushc
287 # define termIntCharp		(cc_t *)&ntc.t_intrc
288 # define termKillCharp		(cc_t *)&nttyb.sg_kill
289 # define termLiteralNextCharp	(cc_t *)&nltc.t_lnextc
290 # define termQuitCharp		(cc_t *)&ntc.t_quitc
291 # define termSuspCharp		(cc_t *)&nltc.t_suspc
292 # define termRprntCharp		(cc_t *)&nltc.t_rprntc
293 # define termWerasCharp		(cc_t *)&nltc.t_werasc
294 # define termStartCharp		(cc_t *)&ntc.t_startc
295 # define termStopCharp		(cc_t *)&ntc.t_stopc
296 # define termForw1Charp		(cc_t *)&ntc.t_brkc
297 # define termForw2Charp		(cc_t *)&termForw2Char
298 # define termAytCharp		(cc_t *)&termAytChar
299 
300 # else
301 
302 extern struct	termio new_tc;
303 
304 # define termEofChar		new_tc.c_cc[VEOF]
305 # define termEraseChar		new_tc.c_cc[VERASE]
306 # define termIntChar		new_tc.c_cc[VINTR]
307 # define termKillChar		new_tc.c_cc[VKILL]
308 # define termQuitChar		new_tc.c_cc[VQUIT]
309 
310 # ifndef	VSUSP
311 extern cc_t termSuspChar;
312 # else
313 #  define termSuspChar		new_tc.c_cc[VSUSP]
314 # endif
315 # if	defined(VFLUSHO) && !defined(VDISCARD)
316 #  define VDISCARD VFLUSHO
317 # endif
318 # ifndef	VDISCARD
319 extern cc_t termFlushChar;
320 # else
321 #  define termFlushChar		new_tc.c_cc[VDISCARD]
322 # endif
323 # ifndef VWERASE
324 extern cc_t termWerasChar;
325 # else
326 #  define termWerasChar		new_tc.c_cc[VWERASE]
327 # endif
328 # ifndef	VREPRINT
329 extern cc_t termRprntChar;
330 # else
331 #  define termRprntChar		new_tc.c_cc[VREPRINT]
332 # endif
333 # ifndef	VLNEXT
334 extern cc_t termLiteralNextChar;
335 # else
336 #  define termLiteralNextChar	new_tc.c_cc[VLNEXT]
337 # endif
338 # ifndef	VSTART
339 extern cc_t termStartChar;
340 # else
341 #  define termStartChar		new_tc.c_cc[VSTART]
342 # endif
343 # ifndef	VSTOP
344 extern cc_t termStopChar;
345 # else
346 #  define termStopChar		new_tc.c_cc[VSTOP]
347 # endif
348 # ifndef	VEOL
349 extern cc_t termForw1Char;
350 # else
351 #  define termForw1Char		new_tc.c_cc[VEOL]
352 # endif
353 # ifndef	VEOL2
354 extern cc_t termForw2Char;
355 # else
356 #  define termForw2Char		new_tc.c_cc[VEOL]
357 # endif
358 # ifndef	VSTATUS
359 extern cc_t termAytChar;
360 #else
361 #  define termAytChar		new_tc.c_cc[VSTATUS]
362 #endif
363 
364 # if !defined(CRAY) || defined(__STDC__)
365 #  define termEofCharp		&termEofChar
366 #  define termEraseCharp	&termEraseChar
367 #  define termIntCharp		&termIntChar
368 #  define termKillCharp		&termKillChar
369 #  define termQuitCharp		&termQuitChar
370 #  define termSuspCharp		&termSuspChar
371 #  define termFlushCharp	&termFlushChar
372 #  define termWerasCharp	&termWerasChar
373 #  define termRprntCharp	&termRprntChar
374 #  define termLiteralNextCharp	&termLiteralNextChar
375 #  define termStartCharp	&termStartChar
376 #  define termStopCharp		&termStopChar
377 #  define termForw1Charp	&termForw1Char
378 #  define termForw2Charp	&termForw2Char
379 #  define termAytCharp		&termAytChar
380 # else
381 	/* Work around a compiler bug */
382 #  define termEofCharp		0
383 #  define termEraseCharp	0
384 #  define termIntCharp		0
385 #  define termKillCharp		0
386 #  define termQuitCharp		0
387 #  define termSuspCharp		0
388 #  define termFlushCharp	0
389 #  define termWerasCharp	0
390 #  define termRprntCharp	0
391 #  define termLiteralNextCharp	0
392 #  define termStartCharp	0
393 #  define termStopCharp		0
394 #  define termForw1Charp	0
395 #  define termForw2Charp	0
396 #  define termAytCharp		0
397 # endif
398 #endif
399 
400 
401 /* Ring buffer structures which are shared */
402 
403 extern Ring
404     netoring,
405     netiring,
406     ttyoring,
407     ttyiring;
408 
409 /* Tn3270 section */
410 #if	defined(TN3270)
411 
412 extern int
413     HaveInput,		/* Whether an asynchronous I/O indication came in */
414     noasynchtty,	/* Don't do signals on I/O (SIGURG, SIGIO) */
415     noasynchnet,	/* Don't do signals on I/O (SIGURG, SIGIO) */
416     sigiocount,		/* Count of SIGIO receptions */
417     shell_active;	/* Subshell is active */
418 
419 extern char
420     *Ibackp,		/* Oldest byte of 3270 data */
421     Ibuf[],		/* 3270 buffer */
422     *Ifrontp,		/* Where next 3270 byte goes */
423     tline[],
424     *transcom;		/* Transparent command */
425 
426 extern int
427     settranscom P((int, char**));
428 
429 extern void
430     inputAvailable P((void));
431 #endif	/* defined(TN3270) */
432