Home | History | Annotate | Line # | Download | only in tip
tip.h revision 1.30
      1  1.30   hubertf /*	$NetBSD: tip.h,v 1.30 2007/03/09 23:45:21 hubertf Exp $	*/
      2   1.3       jtc 
      3   1.1       cgd /*
      4   1.3       jtc  * Copyright (c) 1989, 1993
      5   1.3       jtc  *	The Regents of the University of California.  All rights reserved.
      6   1.3       jtc  *
      7   1.1       cgd  *
      8   1.1       cgd  * Redistribution and use in source and binary forms, with or without
      9   1.1       cgd  * modification, are permitted provided that the following conditions
     10   1.1       cgd  * are met:
     11   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     12   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     13   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     14   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     15   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     16  1.15       agc  * 3. Neither the name of the University nor the names of its contributors
     17   1.1       cgd  *    may be used to endorse or promote products derived from this software
     18   1.1       cgd  *    without specific prior written permission.
     19   1.1       cgd  *
     20   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     21   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     22   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     23   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     24   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     25   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     26   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     27   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     28   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     29   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     30   1.1       cgd  * SUCH DAMAGE.
     31   1.1       cgd  *
     32   1.3       jtc  *      @(#)tip.h	8.1 (Berkeley) 6/6/93
     33   1.1       cgd  */
     34   1.1       cgd 
     35   1.1       cgd /*
     36   1.1       cgd  * tip - terminal interface program
     37   1.1       cgd  */
     38   1.1       cgd 
     39   1.9    kleink #include <sys/param.h>
     40   1.8     lukem #include <sys/ioctl.h>
     41   1.1       cgd #include <sys/time.h>
     42   1.8     lukem #include <sys/wait.h>
     43   1.8     lukem #include <machine/endian.h>
     44   1.1       cgd 
     45   1.8     lukem #include <err.h>
     46  1.12  christos #include <fcntl.h>
     47   1.8     lukem #include <errno.h>
     48  1.12  christos #include <dirent.h>
     49   1.8     lukem #include <pwd.h>
     50   1.8     lukem #include <setjmp.h>
     51   1.1       cgd #include <signal.h>
     52   1.1       cgd #include <stdio.h>
     53   1.1       cgd #include <stdlib.h>
     54   1.1       cgd #include <string.h>
     55   1.8     lukem #include <termios.h>
     56   1.9    kleink #include <time.h>
     57   1.1       cgd #include <unistd.h>
     58   1.1       cgd 
     59   1.1       cgd /*
     60   1.1       cgd  * Remote host attributes
     61   1.1       cgd  */
     62   1.1       cgd char	*DV;			/* UNIX device(s) to open */
     63   1.1       cgd char	*EL;			/* chars marking an EOL */
     64   1.1       cgd char	*CM;			/* initial connection message */
     65   1.1       cgd char	*IE;			/* EOT to expect on input */
     66   1.1       cgd char	*OE;			/* EOT to send to complete FT */
     67   1.1       cgd char	*CU;			/* call unit if making a phone call */
     68   1.1       cgd char	*AT;			/* acu type */
     69   1.1       cgd char	*PN;			/* phone number(s) */
     70   1.1       cgd char	*DI;			/* disconnect string */
     71   1.1       cgd char	*PA;			/* parity to be generated */
     72   1.1       cgd 
     73   1.1       cgd char	*PH;			/* phone number file */
     74   1.1       cgd char	*RM;			/* remote file name */
     75   1.1       cgd char	*HO;			/* host name */
     76   1.1       cgd 
     77   1.3       jtc long	BR;			/* line speed for conversation */
     78   1.3       jtc long	FS;			/* frame size for transfers */
     79   1.1       cgd 
     80  1.25  christos long	DU;			/* this host is dialed up */
     81  1.25  christos long	HW;			/* this device is hardwired, see hunt.c */
     82   1.1       cgd char	*ES;			/* escape character */
     83   1.1       cgd char	*EX;			/* exceptions */
     84   1.1       cgd char	*FO;			/* force (literal next) char*/
     85   1.1       cgd char	*RC;			/* raise character */
     86   1.1       cgd char	*RE;			/* script record file */
     87   1.1       cgd char	*PR;			/* remote prompt */
     88   1.3       jtc long	DL;			/* line delay for file transfers to remote */
     89   1.3       jtc long	CL;			/* char delay for file transfers to remote */
     90   1.3       jtc long	ET;			/* echocheck timeout */
     91  1.25  christos long	HD;			/* this host is half duplex - do local echo */
     92   1.7    mellon char	DC;			/* this host is directly connected. */
     93   1.1       cgd 
     94   1.1       cgd /*
     95   1.1       cgd  * String value table
     96   1.1       cgd  */
     97   1.1       cgd typedef
     98   1.1       cgd 	struct {
     99  1.16  christos 		const char *v_name;	/* whose name is it */
    100  1.25  christos 		uint8_t v_type;		/* for interpreting set's */
    101  1.25  christos 		uint8_t v_access;	/* protection of touchy ones */
    102  1.16  christos 		const char *v_abrev;	/* possible abreviation */
    103  1.25  christos 		void *v_value;		/* casted to a union later */
    104   1.8     lukem 				/*
    105  1.20     perry 				 * XXX:	this assumes that the storage space
    106   1.8     lukem 				 *	of a pointer >= that of a long
    107   1.8     lukem 				 */
    108   1.1       cgd 	}
    109   1.1       cgd 	value_t;
    110   1.1       cgd 
    111   1.1       cgd #define STRING	01		/* string valued */
    112   1.1       cgd #define BOOL	02		/* true-false value */
    113   1.1       cgd #define NUMBER	04		/* numeric value */
    114   1.1       cgd #define CHAR	010		/* character value */
    115   1.1       cgd 
    116   1.1       cgd #define WRITE	01		/* write access to variable */
    117   1.1       cgd #define	READ	02		/* read access */
    118   1.1       cgd 
    119   1.1       cgd #define CHANGED	01		/* low bit is used to show modification */
    120   1.1       cgd #define PUBLIC	1		/* public access rights */
    121   1.1       cgd #define PRIVATE	03		/* private to definer */
    122   1.1       cgd #define ROOT	05		/* root defined */
    123   1.1       cgd 
    124   1.1       cgd #define	TRUE	1
    125   1.1       cgd #define FALSE	0
    126   1.1       cgd 
    127   1.1       cgd #define ENVIRON	020		/* initialize out of the environment */
    128   1.1       cgd #define IREMOTE	040		/* initialize out of remote structure */
    129   1.1       cgd #define INIT	0100		/* static data space used for initialization */
    130   1.1       cgd #define TMASK	017
    131   1.1       cgd 
    132   1.1       cgd /*
    133   1.1       cgd  * Definition of ACU line description
    134   1.1       cgd  */
    135   1.1       cgd typedef
    136   1.1       cgd 	struct {
    137  1.16  christos 		const char *acu_name;
    138  1.20     perry 		int	(*acu_dialer)(char *, char *);
    139  1.20     perry 		void	(*acu_disconnect)(void);
    140  1.20     perry 		void	(*acu_abort)(void);
    141   1.1       cgd 	}
    142   1.1       cgd 	acu_t;
    143   1.1       cgd 
    144   1.1       cgd #define	equal(a, b)	(strcmp(a,b)==0)/* A nice function to string compare */
    145   1.1       cgd 
    146   1.1       cgd /*
    147   1.1       cgd  * variable manipulation stuff --
    148   1.1       cgd  *   if we defined the value entry in value_t, then we couldn't
    149   1.1       cgd  *   initialize it in vars.c, so we cast it as needed to keep lint
    150   1.1       cgd  *   happy.
    151   1.1       cgd  */
    152   1.1       cgd 
    153   1.1       cgd #define value(v)	vtable[v].v_value
    154   1.1       cgd 
    155  1.25  christos #define	number(v)	((int)(intptr_t)(v))
    156  1.25  christos #define	boolean(v)	((short)(intptr_t)(v))
    157  1.25  christos #define	character(v)	((char)(intptr_t)(v))
    158  1.25  christos #define	address(v)	((long *)(intptr_t)(v))
    159  1.25  christos 
    160  1.25  christos #define	setnumber(v,n)		do { (v) = (char *)(intptr_t)(n); } while (/*CONSTCOND*/0)
    161  1.25  christos #define	setboolean(v,n)		do { (v) = (char *)(intptr_t)(n); } while (/*CONSTCOND*/0)
    162  1.25  christos #define	setcharacter(v,n)	do { (v) = (char *)(intptr_t)(n); } while (/*CONSTCOND*/0)
    163  1.25  christos #define	setaddress(v,n)		do { (v) = (char *)(intptr_t)(n); } while (/*CONSTCOND*/0)
    164   1.1       cgd 
    165   1.1       cgd /*
    166   1.1       cgd  * Escape command table definitions --
    167   1.1       cgd  *   lookup in this table is performed when ``escapec'' is recognized
    168   1.1       cgd  *   at the begining of a line (as defined by the eolmarks variable).
    169   1.1       cgd */
    170   1.1       cgd 
    171   1.1       cgd typedef
    172   1.1       cgd 	struct {
    173   1.8     lukem 		char	e_char;			/* char to match on */
    174  1.13    simonb 		char	e_flags;		/* experimental, privileged */
    175  1.16  christos 		const char *e_help;		/* help string */
    176  1.20     perry 		void 	(*e_func)(char);	/* command */
    177   1.1       cgd 	}
    178   1.1       cgd 	esctable_t;
    179   1.1       cgd 
    180   1.1       cgd #define NORM	00		/* normal protection, execute anyone */
    181   1.1       cgd #define EXP	01		/* experimental, mark it with a `*' on help */
    182  1.13    simonb #define PRIV	02		/* privileged, root execute only */
    183   1.1       cgd 
    184   1.1       cgd extern int	vflag;		/* verbose during reading of .tiprc file */
    185   1.1       cgd extern value_t	vtable[];	/* variable table */
    186   1.1       cgd 
    187   1.1       cgd /*
    188   1.1       cgd  * Definition of indices into variable table so
    189   1.1       cgd  *  value(DEFINE) turns into a static address.
    190   1.8     lukem  *
    191   1.8     lukem  * XXX: keep in sync with vtable[] in vars.c
    192   1.1       cgd  */
    193   1.1       cgd 
    194   1.1       cgd #define BEAUTIFY	0
    195   1.1       cgd #define BAUDRATE	1
    196   1.1       cgd #define DIALTIMEOUT	2
    197   1.1       cgd #define EOFREAD		3
    198   1.1       cgd #define EOFWRITE	4
    199   1.1       cgd #define EOL		5
    200   1.1       cgd #define ESCAPE		6
    201   1.1       cgd #define EXCEPTIONS	7
    202   1.1       cgd #define FORCE		8
    203   1.1       cgd #define FRAMESIZE	9
    204   1.1       cgd #define HOST		10
    205  1.23       tls #define PHONES		11
    206  1.23       tls #define PROMPT		12
    207  1.23       tls #define RAISE		13
    208  1.23       tls #define RAISECHAR	14
    209  1.23       tls #define RECORD		15
    210  1.23       tls #define REMOTE		16
    211  1.23       tls #define SCRIPT		17
    212  1.23       tls #define TABEXPAND	18
    213  1.23       tls #define VERBOSE		19
    214  1.23       tls #define SHELL		20
    215  1.23       tls #define HOME		21
    216  1.23       tls #define ECHOCHECK	22
    217  1.23       tls #define DISCONNECT	23
    218  1.23       tls #define TAND		24
    219  1.23       tls #define LDELAY		25
    220  1.23       tls #define CDELAY		26
    221  1.23       tls #define ETIMEOUT	27
    222  1.23       tls #define RAWFTP		28
    223  1.23       tls #define HALFDUPLEX	29
    224  1.23       tls #define	LECHO		30
    225  1.23       tls #define	PARITY		31
    226  1.23       tls #define	HARDWAREFLOW	32
    227   1.1       cgd 
    228   1.4        pk struct termios	term;		/* current mode of terminal */
    229   1.4        pk struct termios	defterm;	/* initial mode of terminal */
    230   1.4        pk struct termios	defchars;	/* current mode with initial chars */
    231   1.1       cgd 
    232   1.1       cgd FILE	*fscript;		/* FILE for scripting */
    233   1.1       cgd 
    234  1.26       tls int	attndes[2];		/* coprocess wakeup channel */
    235   1.1       cgd int	fildes[2];		/* file transfer synchronization channel */
    236  1.14       wiz int	repdes[2];		/* read process synchronization channel */
    237   1.1       cgd int	FD;			/* open file descriptor to remote host */
    238  1.28  christos #ifndef __lint__  /* not used by hayes.c, but used by some other dialers */
    239   1.1       cgd int	AC;			/* open file descriptor to dialer (v831 only) */
    240  1.28  christos #endif /*__lint__*/
    241   1.1       cgd int	vflag;			/* print .tiprc initialization sequence */
    242   1.1       cgd int	sfd;			/* for ~< operation */
    243   1.1       cgd int	pid;			/* pid of tipout */
    244   1.1       cgd uid_t	uid, euid;		/* real and effective user id's */
    245   1.1       cgd gid_t	gid, egid;		/* real and effective group id's */
    246   1.1       cgd int	stop;			/* stop transfer session flag */
    247   1.1       cgd int	quit;			/* same; but on other end */
    248   1.1       cgd int	stoprompt;		/* for interrupting a prompt session */
    249   1.1       cgd int	timedout;		/* ~> transfer timedout */
    250   1.1       cgd int	cumode;			/* simulating the "cu" program */
    251   1.4        pk int	bits8;			/* terminal is is 8-bit mode */
    252   1.4        pk #define STRIP_PAR	(bits8 ? 0377 : 0177)
    253   1.1       cgd 
    254   1.1       cgd char	fname[80];		/* file name buffer for ~< */
    255   1.1       cgd char	copyname[80];		/* file name buffer for ~> */
    256   1.1       cgd char	ccc;			/* synchronization character */
    257   1.1       cgd 
    258  1.28  christos int	odisc;			/* initial tty line discipline */
    259   1.1       cgd 
    260   1.8     lukem extern acu_t		acutable[];
    261   1.8     lukem extern esctable_t	etable[];
    262   1.8     lukem extern unsigned char	evenpartab[];
    263   1.8     lukem 
    264  1.20     perry void	alrmtimeout(int);
    265  1.20     perry int	any(char, const char *);
    266  1.20     perry void	chdirectory(char);
    267  1.20     perry void	cleanup(int);
    268  1.28  christos const char   *tip_connect(void);
    269  1.20     perry void	consh(char);
    270  1.20     perry char   *ctrl(char);
    271  1.20     perry void	cumain(int, char **);
    272  1.20     perry void	cu_put(char);
    273  1.20     perry void	cu_take(char);
    274  1.20     perry void	disconnect(const char *);
    275  1.20     perry char   *expand(char *);
    276  1.20     perry void	finish(char);
    277  1.20     perry void	genbrk(char);
    278  1.20     perry void	getfl(char);
    279  1.20     perry char   *getremote(char *);
    280  1.20     perry void	hardwareflow(const char *);
    281  1.20     perry void	help(char);
    282  1.20     perry int	hunt(char *);
    283  1.20     perry char   *interp(const char *);
    284  1.20     perry void	pipefile(char);
    285  1.20     perry void	pipeout(char);
    286  1.20     perry int	prompt(const char *, char *, size_t);
    287  1.24     perry void	xpwrite(int, char *, size_t);
    288  1.20     perry void	raw(void);
    289  1.25  christos void	sendchar(char);
    290  1.20     perry void	sendfile(char);
    291  1.20     perry void	setparity(const char *);
    292  1.20     perry void	setscript(void);
    293  1.20     perry void	shell(char);
    294  1.20     perry void	suspend(char);
    295  1.20     perry void	tandem(const char *);
    296  1.20     perry void	tipabort(const char *);
    297  1.20     perry void	tipout(void);
    298  1.25  christos int	ttysetup(speed_t);
    299  1.20     perry void	unraw(void);
    300  1.20     perry void	variable(char);
    301  1.20     perry void	vinit(void);
    302  1.20     perry char   *vinterp(char *, char);
    303  1.20     perry void	vlex(char *);
    304  1.20     perry int	vstring(const char *, char *);
    305  1.20     perry 
    306  1.20     perry void	biz22_abort(void);
    307  1.20     perry void	biz22_disconnect(void);
    308  1.20     perry int	biz22f_dialer(char *, char *);
    309  1.20     perry int	biz22w_dialer(char *, char *);
    310  1.20     perry void	biz31_abort(void);
    311  1.20     perry void	biz31_disconnect(void);
    312  1.20     perry int	biz31f_dialer(char *, char *);
    313  1.20     perry int	biz31w_dialer(char *, char *);
    314  1.20     perry void	cour_abort(void);
    315  1.20     perry int	cour_dialer(char *, char *);
    316  1.20     perry void	cour_disconnect(void);
    317  1.20     perry int	df02_dialer(char *, char *);
    318  1.20     perry int	df03_dialer(char *, char *);
    319  1.20     perry void	df_abort(void);
    320  1.20     perry void	df_disconnect(void);
    321  1.20     perry void	dn_abort(void);
    322  1.20     perry int	dn_dialer(char *, char *);
    323  1.20     perry void	dn_disconnect(void);
    324  1.20     perry void	hay_abort(void);
    325  1.20     perry int	hay_dialer(char *, char *);
    326  1.20     perry void	hay_disconnect(void);
    327  1.20     perry void	t3000_abort(void);
    328  1.20     perry int	t3000_dialer(char *, char *);
    329  1.20     perry void	t3000_disconnect(void);
    330  1.20     perry void	v3451_abort(void);
    331  1.20     perry int	v3451_dialer(char *, char *);
    332  1.20     perry void	v3451_disconnect(void);
    333  1.20     perry void	v831_abort(void);
    334  1.20     perry int	v831_dialer(char *, char *);
    335  1.20     perry void	v831_disconnect(void);
    336  1.20     perry void	ven_abort(void);
    337  1.20     perry int	ven_dialer(char *, char *);
    338  1.20     perry void	ven_disconnect(void);
    339