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