tip.h revision 113163
1235848Sissyl0/*	$OpenBSD: tip.h,v 1.11 2001/09/09 19:30:49 millert Exp $	*/
2235848Sissyl0/*	$NetBSD: tip.h,v 1.7 1997/04/20 00:02:46 mellon Exp $	*/
3235848Sissyl0/*	$FreeBSD: head/usr.bin/tip/tip/tip.h 113163 2003-04-06 08:30:25Z imp $	*/
4235848Sissyl0
5235848Sissyl0/*
6235848Sissyl0 * Copyright (c) 1989, 1993
7235848Sissyl0 *	The Regents of the University of California.  All rights reserved.
8235848Sissyl0 *
9235848Sissyl0 *
10235848Sissyl0 * Redistribution and use in source and binary forms, with or without
11235848Sissyl0 * modification, are permitted provided that the following conditions
12235848Sissyl0 * are met:
13235848Sissyl0 * 1. Redistributions of source code must retain the above copyright
14235848Sissyl0 *    notice, this list of conditions and the following disclaimer.
15235848Sissyl0 * 2. Redistributions in binary form must reproduce the above copyright
16235848Sissyl0 *    notice, this list of conditions and the following disclaimer in the
17235848Sissyl0 *    documentation and/or other materials provided with the distribution.
18235848Sissyl0 * 3. All advertising materials mentioning features or use of this software
19235848Sissyl0 *    must display the following acknowledgement:
20235848Sissyl0 *	This product includes software developed by the University of
21235848Sissyl0 *	California, Berkeley and its contributors.
22235848Sissyl0 * 4. Neither the name of the University nor the names of its contributors
23235848Sissyl0 *    may be used to endorse or promote products derived from this software
24235848Sissyl0 *    without specific prior written permission.
25235848Sissyl0 *
26235848Sissyl0 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27235848Sissyl0 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28235848Sissyl0 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29235848Sissyl0 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30235848Sissyl0 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31235848Sissyl0 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32235848Sissyl0 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33235848Sissyl0 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34235848Sissyl0 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35235848Sissyl0 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36235848Sissyl0 * SUCH DAMAGE.
37235848Sissyl0 *
38235848Sissyl0 *      @(#)tip.h	8.1 (Berkeley) 6/6/93
39235848Sissyl0 */
40235848Sissyl0
41235848Sissyl0/*
42291294Sngie * tip - terminal interface program
43235848Sissyl0 */
44235848Sissyl0
45235848Sissyl0#include <sys/types.h>
46235848Sissyl0#include <sys/file.h>
47235848Sissyl0#include <sys/time.h>
48235848Sissyl0#include <sys/wait.h>
49235848Sissyl0#include <sys/ioctl.h>
50235848Sissyl0
51235848Sissyl0#include <termios.h>
52235848Sissyl0#include <signal.h>
53235848Sissyl0#include <stdio.h>
54235848Sissyl0#include <stdlib.h>
55235848Sissyl0#include <string.h>
56235848Sissyl0#include <pwd.h>
57235848Sissyl0#include <ctype.h>
58235848Sissyl0#include <setjmp.h>
59235848Sissyl0#include <unistd.h>
60235848Sissyl0#include <errno.h>
61240518Seadler#include <limits.h>
62235848Sissyl0
63235848Sissyl0/*
64235848Sissyl0 * Remote host attributes
65235848Sissyl0 */
66235848Sissyl0char	*DV;			/* UNIX device(s) to open */
67235848Sissyl0char	*EL;			/* chars marking an EOL */
68235848Sissyl0char	*CM;			/* initial connection message */
69235848Sissyl0char	*IE;			/* EOT to expect on input */
70235848Sissyl0char	*OE;			/* EOT to send to complete FT */
71235848Sissyl0char	*CU;			/* call unit if making a phone call */
72char	*AT;			/* acu type */
73char	*PN;			/* phone number(s) */
74char	*DI;			/* disconnect string */
75char	*PA;			/* parity to be generated */
76
77char	*PH;			/* phone number file */
78char	*RM;			/* remote file name */
79char	*HO;			/* host name */
80
81long	BR;			/* line speed for conversation */
82long	FS;			/* frame size for transfers */
83
84short	DU;			/* this host is dialed up */
85short	HW;			/* this device is hardwired, see hunt.c */
86char	*ES;			/* escape character */
87char	*EX;			/* exceptions */
88char	*FO;			/* force (literal next) char*/
89char	*RC;			/* raise character */
90char	*RE;			/* script record file */
91char	*PR;			/* remote prompt */
92long	DL;			/* line delay for file transfers to remote */
93long	CL;			/* char delay for file transfers to remote */
94long	ET;			/* echocheck timeout */
95short	HD;			/* this host is half duplex - do local echo */
96short	DC;			/* this host is directly connected. */
97
98/*
99 * String value table
100 */
101typedef
102	struct {
103		char	*v_name;	/* whose name is it */
104		char	v_type;		/* for interpreting set's */
105		char	v_access;	/* protection of touchy ones */
106		char	*v_abrev;	/* possible abreviation */
107		char	*v_value;	/* casted to a union later */
108	}
109	value_t;
110
111#define STRING	01		/* string valued */
112#define BOOL	02		/* true-false value */
113#define NUMBER	04		/* numeric value */
114#define CHAR	010		/* character value */
115
116#define WRITE	01		/* write access to variable */
117#define	READ	02		/* read access */
118
119#define CHANGED	01		/* low bit is used to show modification */
120#define PUBLIC	1		/* public access rights */
121#define PRIVATE	03		/* private to definer */
122#define ROOT	05		/* root defined */
123
124#define	TRUE	1
125#define FALSE	0
126
127#define ENVIRON	020		/* initialize out of the environment */
128#define IREMOTE	040		/* initialize out of remote structure */
129#define INIT	0100		/* static data space used for initialization */
130#define TMASK	017
131
132/*
133 * Definition of ACU line description
134 */
135typedef
136	struct {
137		const char	*acu_name;
138		int		(*acu_dialer)(char *, char *);
139		void		(*acu_disconnect)(void);
140		void		(*acu_abort)(void);
141	}
142	acu_t;
143
144#define	equal(a, b)	(strcmp(a,b)==0)/* A nice function to string compare */
145
146/*
147 * variable manipulation stuff --
148 *   if we defined the value entry in value_t, then we couldn't
149 *   initialize it in vars.c, so we cast it as needed to keep lint
150 *   happy.
151 */
152
153#define value(v)	vtable[v].v_value
154
155#define	number(v)	((long)(v))
156#define	boolean(v)      ((short)(long)(v))
157#define	character(v)    ((char)(long)(v))
158#define	address(v)      ((long *)(v))
159
160#define	setnumber(v,n)		do { (v) = (char *)(long)(n); } while (0)
161#define	setboolean(v,n)		do { (v) = (char *)(long)(n); } while (0)
162#define	setcharacter(v,n)	do { (v) = (char *)(long)(n); } while (0)
163#define	setaddress(v,n)		do { (v) = (char *)(n); } while (0)
164
165/*
166 * Escape command table definitions --
167 *   lookup in this table is performed when ``escapec'' is recognized
168 *   at the begining of a line (as defined by the eolmarks variable).
169*/
170
171typedef
172	struct {
173		char	e_char;		/* char to match on */
174		char	e_flags;	/* experimental, priviledged */
175		const char *e_help;	/* help string */
176		void 	(*e_func)(char);	/* command */
177	}
178	esctable_t;
179
180#define NORM	00		/* normal protection, execute anyone */
181#define EXP	01		/* experimental, mark it with a `*' on help */
182#define PRIV	02		/* priviledged, root execute only */
183
184extern int	vflag;		/* verbose during reading of .tiprc file */
185extern int	noesc;		/* no escape `~' char */
186extern value_t	vtable[];	/* variable table */
187
188#ifndef ACULOG
189#define logent(a, b, c, d)
190#define loginit()
191#endif
192
193/*
194 * Definition of indices into variable table so
195 *  value(DEFINE) turns into a static address.
196 */
197
198#define BEAUTIFY	0
199#define BAUDRATE	1
200#define DIALTIMEOUT	2
201#define EOFREAD		3
202#define EOFWRITE	4
203#define EOL		5
204#define ESCAPE		6
205#define EXCEPTIONS	7
206#define FORCE		8
207#define FRAMESIZE	9
208#define HOST		10
209#define LOG		11
210#define PHONES		12
211#define PROMPT		13
212#define RAISE		14
213#define RAISECHAR	15
214#define RECORD		16
215#define REMOTE		17
216#define SCRIPT		18
217#define TABEXPAND	19
218#define VERBOSE		20
219#define SHELL		21
220#define HOME		22
221#define ECHOCHECK	23
222#define DISCONNECT	24
223#define TAND		25
224#define LDELAY		26
225#define CDELAY		27
226#define ETIMEOUT	28
227#define RAWFTP		29
228#define HALFDUPLEX	30
229#define	LECHO		31
230#define	PARITY		32
231
232#define NOVAL	((value_t *)NULL)
233#define NOACU	((acu_t *)NULL)
234#define NOSTR	((char *)NULL)
235#define NOFILE	((FILE *)NULL)
236#define NOPWD	((struct passwd *)0)
237
238struct termios	term;		/* current mode of terminal */
239struct termios	defterm;	/* initial mode of terminal */
240struct termios	defchars;	/* current mode with initial chars */
241
242FILE	*fscript;		/* FILE for scripting */
243
244int	fildes[2];		/* file transfer synchronization channel */
245int	repdes[2];		/* read process sychronization channel */
246int	FD;			/* open file descriptor to remote host */
247int	AC;			/* open file descriptor to dialer (v831 only) */
248int	vflag;			/* print .tiprc initialization sequence */
249int	noesc;			/* no `~' escape char */
250int	sfd;			/* for ~< operation */
251int	pid;			/* pid of tipout */
252uid_t	uid, euid;		/* real and effective user id's */
253gid_t	gid, egid;		/* real and effective group id's */
254int	stop;			/* stop transfer session flag */
255int	quit;			/* same; but on other end */
256int	intflag;		/* recognized interrupt */
257int	stoprompt;		/* for interrupting a prompt session */
258int	timedout;		/* ~> transfer timedout */
259int	cumode;			/* simulating the "cu" program */
260int	bits8;			/* terminal is is 8-bit mode */
261#define STRIP_PAR	(bits8 ? 0377 : 0177)
262
263char	fname[PATH_MAX];	/* file name buffer for ~< */
264char	copyname[PATH_MAX];	/* file name buffer for ~> */
265char	ccc;			/* synchronization character */
266char	ch;			/* for tipout */
267char	*uucplock;		/* name of lock file for uucp's */
268
269int	odisc;			/* initial tty line discipline */
270extern	int disc;		/* current tty discpline */
271
272extern	char *__progname;	/* program name */
273
274extern	char *ctrl(char);
275extern	char *vinterp(char *, char);
276extern	const char *connect(void);
277
278char	*sname(char *s);
279int	any(int cc, char *p);
280int	anyof(char *s1, char *s2);
281int	args(char *buf, char *a[], int num);
282int	escape(void);
283int	prompt(char *s, char *p, size_t sz);
284int	size(char *s);
285int	speed(int n);
286int	uu_lock(char *_ttyname);
287int	uu_unlock(char *_ttyname);
288int	vstring(char *s, char *v);
289long	hunt(char *name);
290void	cumain(int argc, char *argv[]);
291void	daemon_uid(void);
292void	disconnect(char *reason);
293void	execute(char *s);
294void	logent(char *group, const char *num, const char *acu, const char *message);
295void	loginit(void);
296void	prtime(char *s, time_t a);
297void	parwrite(int fd, char *buf, int n);
298void	raw(void);
299void	send(int c);
300void	setparity(char *defparity);
301void	setscript(void);
302void	shell_uid(void);
303void	tandem(char *option);
304void	tipabort(char *msg);
305void	tipin(void);
306void	tipout(void);
307void	transfer(char *buf, int fd, char *eofchars);
308void	transmit(FILE *fd, char *eofchars, char *command);
309void	ttysetup(int _speed);
310void	unraw(void);
311void	user_uid(void);
312void	vinit(void);
313void	vlex(char *s);
314
315int	biz31f_dialer(char *, char *);
316void	biz31f_disconnect(void);
317void	biz31f_abort(void);
318int	ven_dialer(char *, char *);
319void	ven_disconnect(void);
320void	ven_abort(void);
321int	hay_dialer(char *, char *);
322void	hay_disconnect(void);
323void	hay_abort(void);
324int	cour_dialer(char *, char *);
325void	cour_disconnect(void);
326void	cour_abort(void);
327int	t3000_dialer(char *, char *);
328void	t3000_disconnect(void);
329void	t3000_abort(void);
330int	v831_dialer(char *, char *);
331void	v831_disconnect(void);
332void	v831_abort(void);
333
334void shell(char c), getfl(char c), sendfile(char c), chdirectory(char c);
335void finish(char c), help(char c), pipefile(char c), pipeout(char c);
336void consh(char c), variable(char c), cu_take(char c), cu_put(char c);
337void dollar(char c), genbrk(char c), suspend(char c), listvariables(char c);
338