home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.bin / tip / aculib / biz22.c next >
Encoding:
C/C++ Source or Header  |  1991-04-18  |  4.2 KB  |  188 lines

  1. /*
  2.  * Copyright (c) 1983 The Regents of the University of California.
  3.  * 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.  
  34. #ifndef lint
  35. static char sccsid[] = "@(#)biz22.c    5.5 (Berkeley) 3/2/91";
  36. #endif /* not lint */
  37.  
  38. #include "tip.h"
  39.  
  40. #define DISCONNECT_CMD    "\20\04"    /* disconnection string */
  41.  
  42. static    void sigALRM();
  43. static    int timeout = 0;
  44. static    jmp_buf timeoutbuf;
  45.  
  46. /*
  47.  * Dial up on a BIZCOMP Model 1022 with either
  48.  *     tone dialing (mod = "V")
  49.  *    pulse dialing (mod = "W")
  50.  */
  51. static int
  52. biz_dialer(num, mod)
  53.     char *num, *mod;
  54. {
  55.     register int connected = 0;
  56.     char cbuf[40];
  57.     static int cmd(), detect();
  58.  
  59.     if (boolean(value(VERBOSE)))
  60.         printf("\nstarting call...");
  61.     /*
  62.      * Disable auto-answer and configure for tone/pulse
  63.      *  dialing
  64.      */
  65.     if (cmd("\02K\r")) {
  66.         printf("can't initialize bizcomp...");
  67.         return (0);
  68.     }
  69.     strcpy(cbuf, "\02.\r");
  70.     cbuf[1] = *mod;
  71.     if (cmd(cbuf)) {
  72.         printf("can't set dialing mode...");
  73.         return (0);
  74.     }
  75.     strcpy(cbuf, "\02D");
  76.     strcat(cbuf, num);
  77.     strcat(cbuf, "\r");
  78.     write(FD, cbuf, strlen(cbuf));
  79.     if (!detect("7\r")) {
  80.         printf("can't get dial tone...");
  81.         return (0);
  82.     }
  83.     if (boolean(value(VERBOSE)))
  84.         printf("ringing...");
  85.     /*
  86.      * The reply from the BIZCOMP should be:
  87.      *    2 \r or 7 \r    failure
  88.      *    1 \r        success
  89.      */
  90.     connected = detect("1\r");
  91. #ifdef ACULOG
  92.     if (timeout) {
  93.         char line[80];
  94.  
  95.         sprintf(line, "%d second dial timeout",
  96.             number(value(DIALTIMEOUT)));
  97.         logent(value(HOST), num, "biz1022", line);
  98.     }
  99. #endif
  100.     if (timeout)
  101.         biz22_disconnect();    /* insurance */
  102.     return (connected);
  103. }
  104.  
  105. biz22w_dialer(num, acu)
  106.     char *num, *acu;
  107. {
  108.  
  109.     return (biz_dialer(num, "W"));
  110. }
  111.  
  112. biz22f_dialer(num, acu)
  113.     char *num, *acu;
  114. {
  115.  
  116.     return (biz_dialer(num, "V"));
  117. }
  118.  
  119. biz22_disconnect()
  120. {
  121.     int rw = 2;
  122.  
  123.     write(FD, DISCONNECT_CMD, 4);
  124.     sleep(2);
  125.     ioctl(FD, TIOCFLUSH, &rw);
  126. }
  127.  
  128. biz22_abort()
  129. {
  130.  
  131.     write(FD, "\02", 1);
  132. }
  133.  
  134. static void
  135. sigALRM()
  136. {
  137.  
  138.     timeout = 1;
  139.     longjmp(timeoutbuf, 1);
  140. }
  141.  
  142. static int
  143. cmd(s)
  144.     register char *s;
  145. {
  146.     sig_t f;
  147.     char c;
  148.  
  149.     write(FD, s, strlen(s));
  150.     f = signal(SIGALRM, sigALRM);
  151.     if (setjmp(timeoutbuf)) {
  152.         biz22_abort();
  153.         signal(SIGALRM, f);
  154.         return (1);
  155.     }
  156.     alarm(number(value(DIALTIMEOUT)));
  157.     read(FD, &c, 1);
  158.     alarm(0);
  159.     signal(SIGALRM, f);
  160.     c &= 0177;
  161.     return (c != '\r');
  162. }
  163.  
  164. static int
  165. detect(s)
  166.     register char *s;
  167. {
  168.     sig_t f;
  169.     char c;
  170.  
  171.     f = signal(SIGALRM, sigALRM);
  172.     timeout = 0;
  173.     while (*s) {
  174.         if (setjmp(timeoutbuf)) {
  175.             biz22_abort();
  176.             break;
  177.         }
  178.         alarm(number(value(DIALTIMEOUT)));
  179.         read(FD, &c, 1);
  180.         alarm(0);
  181.         c &= 0177;
  182.         if (c != *s++)
  183.             return (0);
  184.     }
  185.     signal(SIGALRM, f);
  186.     return (timeout == 0);
  187. }
  188.