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