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