xref: /netbsd-src/usr.bin/tip/tip.h (revision d0fed6c87ddc40a8bffa6f99e7433ddfc864dd83)
1 /*	$NetBSD: tip.h,v 1.7 1997/04/20 00:02:46 mellon Exp $	*/
2 
3 /*
4  * Copyright (c) 1989, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
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. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *	This product includes software developed by the University of
19  *	California, Berkeley and its contributors.
20  * 4. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  *      @(#)tip.h	8.1 (Berkeley) 6/6/93
37  */
38 
39 /*
40  * tip - terminal interface program
41  */
42 
43 #include <sys/types.h>
44 #include <machine/endian.h>
45 #include <sys/file.h>
46 #include <sys/time.h>
47 
48 #include <termios.h>
49 #include <signal.h>
50 #include <stdio.h>
51 #include <stdlib.h>
52 #include <string.h>
53 #include <pwd.h>
54 #include <ctype.h>
55 #include <setjmp.h>
56 #include <unistd.h>
57 #include <errno.h>
58 
59 /*
60  * Remote host attributes
61  */
62 char	*DV;			/* UNIX device(s) to open */
63 char	*EL;			/* chars marking an EOL */
64 char	*CM;			/* initial connection message */
65 char	*IE;			/* EOT to expect on input */
66 char	*OE;			/* EOT to send to complete FT */
67 char	*CU;			/* call unit if making a phone call */
68 char	*AT;			/* acu type */
69 char	*PN;			/* phone number(s) */
70 char	*DI;			/* disconnect string */
71 char	*PA;			/* parity to be generated */
72 
73 char	*PH;			/* phone number file */
74 char	*RM;			/* remote file name */
75 char	*HO;			/* host name */
76 
77 long	BR;			/* line speed for conversation */
78 long	FS;			/* frame size for transfers */
79 
80 int	DU;			/* this host is dialed up */
81 int	HW;			/* this device is hardwired, see hunt.c */
82 char	*ES;			/* escape character */
83 char	*EX;			/* exceptions */
84 char	*FO;			/* force (literal next) char*/
85 char	*RC;			/* raise character */
86 char	*RE;			/* script record file */
87 char	*PR;			/* remote prompt */
88 long	DL;			/* line delay for file transfers to remote */
89 long	CL;			/* char delay for file transfers to remote */
90 long	ET;			/* echocheck timeout */
91 int	HD;			/* this host is half duplex - do local echo */
92 char	DC;			/* this host is directly connected. */
93 
94 /*
95  * String value table
96  */
97 typedef
98 	struct {
99 		char	*v_name;	/* whose name is it */
100 		char	v_type;		/* for interpreting set's */
101 		char	v_access;	/* protection of touchy ones */
102 		char	*v_abrev;	/* possible abreviation */
103 		char	*v_value;	/* casted to a union later */
104 	}
105 	value_t;
106 
107 #define STRING	01		/* string valued */
108 #define BOOL	02		/* true-false value */
109 #define NUMBER	04		/* numeric value */
110 #define CHAR	010		/* character value */
111 
112 #define WRITE	01		/* write access to variable */
113 #define	READ	02		/* read access */
114 
115 #define CHANGED	01		/* low bit is used to show modification */
116 #define PUBLIC	1		/* public access rights */
117 #define PRIVATE	03		/* private to definer */
118 #define ROOT	05		/* root defined */
119 
120 #define	TRUE	1
121 #define FALSE	0
122 
123 #define ENVIRON	020		/* initialize out of the environment */
124 #define IREMOTE	040		/* initialize out of remote structure */
125 #define INIT	0100		/* static data space used for initialization */
126 #define TMASK	017
127 
128 /*
129  * Definition of ACU line description
130  */
131 typedef
132 	struct {
133 		char	*acu_name;
134 		int	(*acu_dialer)();
135 		int	(*acu_disconnect)();
136 		int	(*acu_abort)();
137 	}
138 	acu_t;
139 
140 #define	equal(a, b)	(strcmp(a,b)==0)/* A nice function to string compare */
141 
142 /*
143  * variable manipulation stuff --
144  *   if we defined the value entry in value_t, then we couldn't
145  *   initialize it in vars.c, so we cast it as needed to keep lint
146  *   happy.
147  */
148 
149 #define value(v)	vtable[v].v_value
150 
151 #define	number(v)	((long)(v))
152 #define	boolean(v)	((short)(long)(v))
153 #define	character(v)	((char)(long)(v))
154 #define	address(v)	((long *)(v))
155 
156 #define	setnumber(v,n)		do { (v) = (char *)(long)(n); } while (0)
157 #define	setboolean(v,n)		do { (v) = (char *)(long)(n); } while (0)
158 #define	setcharacter(v,n)	do { (v) = (char *)(long)(n); } while (0)
159 #define	setaddress(v,n)		do { (v) = (char *)(n); } while (0)
160 
161 /*
162  * Escape command table definitions --
163  *   lookup in this table is performed when ``escapec'' is recognized
164  *   at the begining of a line (as defined by the eolmarks variable).
165 */
166 
167 typedef
168 	struct {
169 		char	e_char;		/* char to match on */
170 		char	e_flags;	/* experimental, priviledged */
171 		char	*e_help;	/* help string */
172 		int 	(*e_func)();	/* command */
173 	}
174 	esctable_t;
175 
176 #define NORM	00		/* normal protection, execute anyone */
177 #define EXP	01		/* experimental, mark it with a `*' on help */
178 #define PRIV	02		/* priviledged, root execute only */
179 
180 extern int	vflag;		/* verbose during reading of .tiprc file */
181 extern value_t	vtable[];	/* variable table */
182 
183 #ifndef ACULOG
184 #define logent(a, b, c, d)
185 #define loginit()
186 #endif
187 
188 /*
189  * Definition of indices into variable table so
190  *  value(DEFINE) turns into a static address.
191  */
192 
193 #define BEAUTIFY	0
194 #define BAUDRATE	1
195 #define DIALTIMEOUT	2
196 #define EOFREAD		3
197 #define EOFWRITE	4
198 #define EOL		5
199 #define ESCAPE		6
200 #define EXCEPTIONS	7
201 #define FORCE		8
202 #define FRAMESIZE	9
203 #define HOST		10
204 #define LOG		11
205 #define PHONES		12
206 #define PROMPT		13
207 #define RAISE		14
208 #define RAISECHAR	15
209 #define RECORD		16
210 #define REMOTE		17
211 #define SCRIPT		18
212 #define TABEXPAND	19
213 #define VERBOSE		20
214 #define SHELL		21
215 #define HOME		22
216 #define ECHOCHECK	23
217 #define DISCONNECT	24
218 #define TAND		25
219 #define LDELAY		26
220 #define CDELAY		27
221 #define ETIMEOUT	28
222 #define RAWFTP		29
223 #define HALFDUPLEX	30
224 #define	LECHO		31
225 #define	PARITY		32
226 
227 #define NOVAL	((value_t *)NULL)
228 #define NOACU	((acu_t *)NULL)
229 #define NOSTR	((char *)NULL)
230 #define NOFILE	((FILE *)NULL)
231 #define NOPWD	((struct passwd *)0)
232 
233 struct termios	term;		/* current mode of terminal */
234 struct termios	defterm;	/* initial mode of terminal */
235 struct termios	defchars;	/* current mode with initial chars */
236 
237 FILE	*fscript;		/* FILE for scripting */
238 
239 int	fildes[2];		/* file transfer synchronization channel */
240 int	repdes[2];		/* read process sychronization channel */
241 int	FD;			/* open file descriptor to remote host */
242 int	AC;			/* open file descriptor to dialer (v831 only) */
243 int	vflag;			/* print .tiprc initialization sequence */
244 int	sfd;			/* for ~< operation */
245 int	pid;			/* pid of tipout */
246 uid_t	uid, euid;		/* real and effective user id's */
247 gid_t	gid, egid;		/* real and effective group id's */
248 int	stop;			/* stop transfer session flag */
249 int	quit;			/* same; but on other end */
250 int	intflag;		/* recognized interrupt */
251 int	stoprompt;		/* for interrupting a prompt session */
252 int	timedout;		/* ~> transfer timedout */
253 int	cumode;			/* simulating the "cu" program */
254 int	bits8;			/* terminal is is 8-bit mode */
255 #define STRIP_PAR	(bits8 ? 0377 : 0177)
256 
257 char	fname[80];		/* file name buffer for ~< */
258 char	copyname[80];		/* file name buffer for ~> */
259 char	ccc;			/* synchronization character */
260 char	ch;			/* for tipout */
261 char	*uucplock;		/* name of lock file for uucp's */
262 
263 int	odisc;				/* initial tty line discipline */
264 extern	int disc;			/* current tty discpline */
265 
266 extern	char *ctrl();
267 extern	char *vinterp();
268 extern	char *connect();
269