|
|
1.1 ! root 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 are permitted ! 6: * provided that: (1) source distributions retain this entire copyright ! 7: * notice and comment, and (2) distributions including binaries display ! 8: * the following acknowledgement: ``This product includes software ! 9: * developed by the University of California, Berkeley and its contributors'' ! 10: * in the documentation or other materials provided with the distribution ! 11: * and in all advertising materials mentioning features or use of this ! 12: * software. Neither the name of the University nor the names of its ! 13: * contributors may be used to endorse or promote products derived ! 14: * from this software without specific prior written permission. ! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 18: */ ! 19: ! 20: #ifndef lint ! 21: static char sccsid[] = "@(#)biz22.c 5.4 (Berkeley) 6/1/90"; ! 22: #endif /* not lint */ ! 23: ! 24: #include "tip.h" ! 25: ! 26: #define DISCONNECT_CMD "\20\04" /* disconnection string */ ! 27: ! 28: static void sigALRM(); ! 29: static int timeout = 0; ! 30: static jmp_buf timeoutbuf; ! 31: ! 32: /* ! 33: * Dial up on a BIZCOMP Model 1022 with either ! 34: * tone dialing (mod = "V") ! 35: * pulse dialing (mod = "W") ! 36: */ ! 37: static int ! 38: biz_dialer(num, mod) ! 39: char *num, *mod; ! 40: { ! 41: register int connected = 0; ! 42: char cbuf[40]; ! 43: ! 44: if (boolean(value(VERBOSE))) ! 45: printf("\nstarting call..."); ! 46: /* ! 47: * Disable auto-answer and configure for tone/pulse ! 48: * dialing ! 49: */ ! 50: if (cmd("\02K\r")) { ! 51: printf("can't initialize bizcomp..."); ! 52: return (0); ! 53: } ! 54: strcpy(cbuf, "\02.\r"); ! 55: cbuf[1] = *mod; ! 56: if (cmd(cbuf)) { ! 57: printf("can't set dialing mode..."); ! 58: return (0); ! 59: } ! 60: strcpy(cbuf, "\02D"); ! 61: strcat(cbuf, num); ! 62: strcat(cbuf, "\r"); ! 63: write(FD, cbuf, strlen(cbuf)); ! 64: if (!detect("7\r")) { ! 65: printf("can't get dial tone..."); ! 66: return (0); ! 67: } ! 68: if (boolean(value(VERBOSE))) ! 69: printf("ringing..."); ! 70: /* ! 71: * The reply from the BIZCOMP should be: ! 72: * 2 \r or 7 \r failure ! 73: * 1 \r success ! 74: */ ! 75: connected = detect("1\r"); ! 76: #ifdef ACULOG ! 77: if (timeout) { ! 78: char line[80]; ! 79: ! 80: sprintf(line, "%d second dial timeout", ! 81: number(value(DIALTIMEOUT))); ! 82: logent(value(HOST), num, "biz1022", line); ! 83: } ! 84: #endif ! 85: if (timeout) ! 86: biz22_disconnect(); /* insurance */ ! 87: return (connected); ! 88: } ! 89: ! 90: biz22w_dialer(num, acu) ! 91: char *num, *acu; ! 92: { ! 93: ! 94: return (biz_dialer(num, "W")); ! 95: } ! 96: ! 97: biz22f_dialer(num, acu) ! 98: char *num, *acu; ! 99: { ! 100: ! 101: return (biz_dialer(num, "V")); ! 102: } ! 103: ! 104: biz22_disconnect() ! 105: { ! 106: int rw = 2; ! 107: ! 108: write(FD, DISCONNECT_CMD, 4); ! 109: sleep(2); ! 110: ioctl(FD, TIOCFLUSH, &rw); ! 111: } ! 112: ! 113: biz22_abort() ! 114: { ! 115: ! 116: write(FD, "\02", 1); ! 117: } ! 118: ! 119: static void ! 120: sigALRM() ! 121: { ! 122: ! 123: timeout = 1; ! 124: longjmp(timeoutbuf, 1); ! 125: } ! 126: ! 127: static int ! 128: cmd(s) ! 129: register char *s; ! 130: { ! 131: sig_t f; ! 132: char c; ! 133: ! 134: write(FD, s, strlen(s)); ! 135: f = signal(SIGALRM, sigALRM); ! 136: if (setjmp(timeoutbuf)) { ! 137: biz22_abort(); ! 138: signal(SIGALRM, f); ! 139: return (1); ! 140: } ! 141: alarm(number(value(DIALTIMEOUT))); ! 142: read(FD, &c, 1); ! 143: alarm(0); ! 144: signal(SIGALRM, f); ! 145: c &= 0177; ! 146: return (c != '\r'); ! 147: } ! 148: ! 149: static int ! 150: detect(s) ! 151: register char *s; ! 152: { ! 153: sig_t f; ! 154: char c; ! 155: ! 156: f = signal(SIGALRM, sigALRM); ! 157: timeout = 0; ! 158: while (*s) { ! 159: if (setjmp(timeoutbuf)) { ! 160: biz22_abort(); ! 161: break; ! 162: } ! 163: alarm(number(value(DIALTIMEOUT))); ! 164: read(FD, &c, 1); ! 165: alarm(0); ! 166: c &= 0177; ! 167: if (c != *s++) ! 168: return (0); ! 169: } ! 170: signal(SIGALRM, f); ! 171: return (timeout == 0); ! 172: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.