1 /* $OpenBSD: acu.c,v 1.12 2006/03/17 14:43:06 moritz Exp $ */
2 /* $NetBSD: acu.c,v 1.4 1996/12/29 10:34:03 cgd Exp $ */
5 * SPDX-License-Identifier: BSD-3-Clause
7 * Copyright (c) 1983, 1993
8 * The Regents of the University of California. All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
40 static char sccsid[] = "@(#)acu.c 8.1 (Berkeley) 6/6/93";
41 static const char rcsid[] = "$OpenBSD: acu.c,v 1.12 2006/03/17 14:43:06 moritz Exp $";
47 static acu_t *acu = NOACU;
49 static void acuabort(int);
50 static acu_t *acutype(char *);
51 static jmp_buf jmpbuf;
53 * Establish connection for tip
55 * If DU is true, we should dial an ACU whose type is AT.
56 * The phone numbers are in PN, and the call unit is in CU.
58 * If the PN is an '@', then we consult the PHONES file for
59 * the phone numbers. This file is /etc/phones, unless overriden
60 * by an exported shell variable.
62 * The data base files must be in the format:
63 * host-name[ \t]*phone-number
64 * with the possibility of multiple phone numbers
65 * for a single host acting as a rotary (in the order
72 char *phnum, string[256];
74 volatile int tried = 0;
76 if (!DU) { /* regular connect message */
78 parwrite(FD, CM, size(CM));
79 logent(value(HOST), "", DV, "call completed");
83 * @ =>'s use data base in PHONES environment variable
84 * otherwise, use /etc/phones
86 signal(SIGINT, acuabort);
87 signal(SIGQUIT, acuabort);
89 signal(SIGINT, SIG_IGN);
90 signal(SIGQUIT, SIG_IGN);
91 printf("\ncall aborted\n");
92 logent(value(HOST), "", "", "call aborted");
94 setboolean(value(VERBOSE), FALSE);
100 return ("interrupt");
102 if ((acu = acutype(AT)) == NOACU)
103 return ("unknown ACU type");
107 cp += strcspn(cp, ",");
111 if (strlen(phnum) == 0)
114 conflag = (*acu->acu_dialer)(phnum, CU);
118 logent(value(HOST), phnum, acu->acu_name, "call failed");
122 if ((fd = fopen(PH, "r")) == NOFILE) {
124 return ("can't open phone number file");
126 while (fgets(string, sizeof(string), fd) != NOSTR) {
127 cp = &string[strcspn(string, " \t\n")];
131 if (strcmp(string, value(HOST)) != 0)
134 cp += strspn(cp, " \t\n");
136 *(cp + strcspn(cp, ",\n")) = '\0';
138 if (strlen(phnum) == 0)
141 conflag = (*acu->acu_dialer)(phnum, CU);
145 logent(value(HOST), phnum, acu->acu_name, "call failed");
152 parwrite(FD, CM, size(CM));
153 logent(value(HOST), phnum, acu->acu_name, "call completed");
156 logent(value(HOST), "", acu->acu_name, "missing phone number");
157 return ("missing phone number");
160 return ("call failed");
165 disconnect(char *reason)
168 logent(value(HOST), "", DV, "call terminated");
171 if (reason == NOSTR) {
172 logent(value(HOST), "", acu->acu_name, "call terminated");
173 if (boolean(value(VERBOSE)))
174 printf("\r\ndisconnecting...");
176 logent(value(HOST), "", acu->acu_name, reason);
177 (*acu->acu_disconnect)();
191 extern acu_t acutable[];
193 for (p = acutable; p->acu_name != NULL; p++)
194 if (!strcmp(s, p->acu_name))