date and time created 85/04/11 16:54:03 by miriam
[unix-history] / usr / src / usr.bin / tip / acu.c
CommitLineData
05862919 1#ifndef lint
631a2290 2static char sccsid[] = "@(#)acu.c 4.12 (Berkeley) %G%";
05862919
SL
3#endif
4
f6a65350 5#include "tip.h"
f6a65350
BJ
6
7static acu_t *acu = NOACU;
8static int conflag;
9static int acuabort();
10static acu_t *acutype();
11static jmp_buf jmpbuf;
12/*
13 * Establish connection for tip
14 *
15 * If DU is true, we should dial an ACU whose type is AT.
16 * The phone numbers are in PN, and the call unit is in CU.
17 *
18 * If the PN is an '@', then we consult the PHONES file for
19 * the phone numbers. This file is /etc/phones, unless overriden
20 * by an exported shell variable.
21 *
22 * The data base files must be in the format:
23 * host-name[ \t]*phone-number
24 * with the possibility of multiple phone numbers
25 * for a single host acting as a rotary (in the order
26 * found in the file).
27 */
28char *
29connect()
30{
31 register char *cp = PN;
32 char *phnum, string[256];
33 FILE *fd;
34 int tried = 0;
35
36 if (!DU) { /* regular connect message */
37 if (CM != NOSTR)
92ee31b0 38 pwrite(FD, cp, size(CM));
3f48242d 39 return (NOSTR);
f6a65350
BJ
40 }
41 /*
42 * @ =>'s use data base in PHONES environment variable
43 * otherwise, use /etc/phones
44 */
45 signal(SIGINT, acuabort);
46 signal(SIGQUIT, acuabort);
47 if (setjmp(jmpbuf)) {
48 signal(SIGINT, SIG_IGN);
49 signal(SIGQUIT, SIG_IGN);
50 printf("\ncall aborted\n");
51 logent(value(HOST), "", "", "call aborted");
52 if (acu != NOACU) {
53 boolean(value(VERBOSE)) = FALSE;
54 if (conflag)
e2326c44 55 disconnect(NOSTR);
f6a65350
BJ
56 else
57 (*acu->acu_abort)();
58 }
59 delock(uucplock);
60 exit(1);
61 }
62 if ((acu = acutype(AT)) == NOACU)
3f48242d 63 return ("unknown ACU type");
f6a65350
BJ
64 if (*cp != '@') {
65 while (*cp) {
92ee31b0 66 for (phnum = cp; any(*cp, "0123456789-*=K"); cp++)
f6a65350 67 ;
51f98017
BS
68 if (*cp)
69 *cp++ = '\0';
f6a65350
BJ
70
71 if (conflag = (*acu->acu_dialer)(phnum, CU)) {
72 logent(value(HOST), phnum, acu->acu_name,
73 "call completed");
3f48242d 74 return (NOSTR);
f6a65350
BJ
75 } else
76 logent(value(HOST), phnum, acu->acu_name,
03bdc5a9 77 "call failed");
f6a65350
BJ
78 tried++;
79 }
80 } else {
81 if ((fd = fopen(PH, "r")) == NOFILE) {
82 printf("%s: ", PH);
3f48242d 83 return ("can't open phone number file");
f6a65350
BJ
84 }
85 while (fgets(string, sizeof(string), fd) != NOSTR) {
86 for (cp = string; !any(*cp, " \t\n"); cp++)
87 ;
88 if (*cp == '\n') {
89 fclose(fd);
3f48242d 90 return ("unrecognizable host name");
f6a65350
BJ
91 }
92 *cp++ = '\0';
93 if (strcmp(string, value(HOST)))
94 continue;
95 while (any(*cp, " \t"))
96 cp++;
97 if (*cp == '\n') {
98 fclose(fd);
3f48242d 99 return ("missing phone number");
f6a65350 100 }
92ee31b0 101 for (phnum = cp; any(*cp, "0123456789-*="); cp++)
f6a65350
BJ
102 ;
103 *cp = '\0';
104
bc6f2b39 105 if (conflag = (*acu->acu_dialer)(phnum, CU)) {
f6a65350
BJ
106 fclose(fd);
107 logent(value(HOST), phnum, acu->acu_name,
108 "call completed");
3f48242d 109 return (NOSTR);
f6a65350
BJ
110 } else
111 logent(value(HOST), phnum, acu->acu_name,
03bdc5a9 112 "call failed");
f6a65350
BJ
113 tried++;
114 }
115 fclose(fd);
116 }
117 if (!tried)
118 logent(value(HOST), "", acu->acu_name, "missing phone number");
92ee31b0
RC
119 else
120 (*acu->acu_abort)();
03bdc5a9 121 return (tried ? "call failed" : "missing phone number");
f6a65350
BJ
122}
123
e2326c44
SL
124disconnect(reason)
125 char *reason;
f6a65350
BJ
126{
127 if (!conflag)
128 return;
631a2290 129 if (reason == NOSTR) {
e2326c44
SL
130 logent(value(HOST), "", acu->acu_name, "call terminated");
131 if (boolean(value(VERBOSE)))
132 printf("\r\ndisconnecting...");
133 } else
134 logent(value(HOST), "", acu->acu_name, reason);
f6a65350
BJ
135 (*acu->acu_disconnect)();
136}
137
138static int
139acuabort(s)
140{
141 signal(s, SIG_IGN);
3a779b68 142 longjmp(jmpbuf, 1);
f6a65350
BJ
143}
144
145static acu_t *
146acutype(s)
d8feebc2 147 register char *s;
f6a65350
BJ
148{
149 register acu_t *p;
150 extern acu_t acutable[];
151
152 for (p = acutable; p->acu_name != '\0'; p++)
153 if (!strcmp(s, p->acu_name))
3f48242d
SL
154 return (p);
155 return (NOACU);
f6a65350 156}