Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / usr.bin / tip / libacu / biz22.c
1 /*
2  * Copyright (c) 1983, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by the University of
16  *      California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * @(#)biz22.c  8.1 (Berkeley) 6/6/93
34  */
35
36 #include "tipconf.h"
37 #include "tip.h"
38
39 #define DISCONNECT_CMD  "\20\04"        /* disconnection string */
40
41 static  void sigALRM();
42 static  int timeout = 0;
43 static  jmp_buf timeoutbuf;
44
45 /*
46  * Dial up on a BIZCOMP Model 1022 with either
47  *      tone dialing (mod = "V")
48  *      pulse dialing (mod = "W")
49  */
50 static int
51 biz_dialer(num, mod)
52         char *num, *mod;
53 {
54         register int connected = 0;
55         char cbuf[40];
56         static int cmd(), detect();
57
58         if (boolean(value(VERBOSE)))
59                 printf("\nstarting call...");
60         /*
61          * Disable auto-answer and configure for tone/pulse
62          *  dialing
63          */
64         if (cmd("\02K\r")) {
65                 printf("can't initialize bizcomp...");
66                 return (0);
67         }
68         strcpy(cbuf, "\02.\r");
69         cbuf[1] = *mod;
70         if (cmd(cbuf)) {
71                 printf("can't set dialing mode...");
72                 return (0);
73         }
74         strcpy(cbuf, "\02D");
75         strcat(cbuf, num);
76         strcat(cbuf, "\r");
77         write(FD, cbuf, strlen(cbuf));
78         if (!detect("7\r")) {
79                 printf("can't get dial tone...");
80                 return (0);
81         }
82         if (boolean(value(VERBOSE)))
83                 printf("ringing...");
84         /*
85          * The reply from the BIZCOMP should be:
86          *      2 \r or 7 \r    failure
87          *      1 \r            success
88          */
89         connected = detect("1\r");
90 #if ACULOG
91         if (timeout) {
92                 char line[80];
93
94                 sprintf(line, "%d second dial timeout",
95                         number(value(DIALTIMEOUT)));
96                 logent(value(HOST), num, "biz1022", line);
97         }
98 #endif
99         if (timeout)
100                 biz22_disconnect();     /* insurance */
101         return (connected);
102 }
103
104 biz22w_dialer(num, acu)
105         char *num, *acu;
106 {
107
108         return (biz_dialer(num, "W"));
109 }
110
111 biz22f_dialer(num, acu)
112         char *num, *acu;
113 {
114
115         return (biz_dialer(num, "V"));
116 }
117
118 biz22_disconnect()
119 {
120         int rw = 2;
121
122         write(FD, DISCONNECT_CMD, 4);
123         sleep(2);
124         ioctl(FD, TIOCFLUSH, &rw);
125 }
126
127 biz22_abort()
128 {
129
130         write(FD, "\02", 1);
131 }
132
133 static void
134 sigALRM()
135 {
136
137         timeout = 1;
138         longjmp(timeoutbuf, 1);
139 }
140
141 static int
142 cmd(s)
143         register char *s;
144 {
145         sig_t f;
146         char c;
147
148         write(FD, s, strlen(s));
149         f = signal(SIGALRM, sigALRM);
150         if (setjmp(timeoutbuf)) {
151                 biz22_abort();
152                 signal(SIGALRM, f);
153                 return (1);
154         }
155         alarm(number(value(DIALTIMEOUT)));
156         read(FD, &c, 1);
157         alarm(0);
158         signal(SIGALRM, f);
159         c &= 0177;
160         return (c != '\r');
161 }
162
163 static int
164 detect(s)
165         register char *s;
166 {
167         sig_t f;
168         char c;
169
170         f = signal(SIGALRM, sigALRM);
171         timeout = 0;
172         while (*s) {
173                 if (setjmp(timeoutbuf)) {
174                         biz22_abort();
175                         break;
176                 }
177                 alarm(number(value(DIALTIMEOUT)));
178                 read(FD, &c, 1);
179                 alarm(0);
180                 c &= 0177;
181                 if (c != *s++)
182                         return (0);
183         }
184         signal(SIGALRM, f);
185         return (timeout == 0);
186 }