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