Annotation of 42BSD/usr.bin/tip/aculib/biz22.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char sccsid[] = "@(#)biz22.c    4.4 (Berkeley) 6/25/83";
                      3: #endif
                      4: 
                      5: #include "tip.h"
                      6: 
                      7: #define DISCONNECT_CMD "\20\04"        /* disconnection string */
                      8: 
                      9: static int sigALRM();
                     10: static int timeout = 0;
                     11: static jmp_buf timeoutbuf;
                     12: 
                     13: /*
                     14:  * Dial up on a BIZCOMP Model 1022 with either
                     15:  *     tone dialing (mod = "V")
                     16:  *     pulse dialing (mod = "W")
                     17:  */
                     18: static int
                     19: biz_dialer(num, mod)
                     20:        char *num, *mod;
                     21: {
                     22:        register int connected = 0;
                     23:        char cbuf[40];
                     24: 
                     25:        if (boolean(value(VERBOSE)))
                     26:                printf("\nstarting call...");
                     27:        /*
                     28:         * Disable auto-answer and configure for tone/pulse
                     29:         *  dialing
                     30:         */
                     31:        if (cmd("\02K\r")) {
                     32:                printf("can't initialize bizcomp...");
                     33:                return (0);
                     34:        }
                     35:        strcpy(cbuf, "\02.\r");
                     36:        cbuf[1] = *mod;
                     37:        if (cmd(cbuf)) {
                     38:                printf("can't set dialing mode...");
                     39:                return (0);
                     40:        }
                     41:        strcpy(cbuf, "\02D");
                     42:        strcat(cbuf, num);
                     43:        strcat(cbuf, "\r");
                     44:        write(FD, cbuf, strlen(cbuf));
                     45:        if (!detect("7\r")) {
                     46:                printf("can't get dial tone...");
                     47:                return (0);
                     48:        }
                     49:        if (boolean(value(VERBOSE)))
                     50:                printf("ringing...");
                     51:        /*
                     52:         * The reply from the BIZCOMP should be:
                     53:         *      2 \r or 7 \r    failure
                     54:         *      1 \r            success
                     55:         */
                     56:        connected = detect("1\r");
                     57: #ifdef ACULOG
                     58:        if (timeout) {
                     59:                char line[80];
                     60: 
                     61:                sprintf(line, "%d second dial timeout",
                     62:                        number(value(DIALTIMEOUT)));
                     63:                logent(value(HOST), num, "biz1022", line);
                     64:        }
                     65: #endif
                     66:        if (timeout)
                     67:                biz22_disconnect();     /* insurance */
                     68:        return (connected);
                     69: }
                     70: 
                     71: biz22w_dialer(num, acu)
                     72:        char *num, *acu;
                     73: {
                     74: 
                     75:        return (biz_dialer(num, "W"));
                     76: }
                     77: 
                     78: biz22f_dialer(num, acu)
                     79:        char *num, *acu;
                     80: {
                     81: 
                     82:        return (biz_dialer(num, "V"));
                     83: }
                     84: 
                     85: biz22_disconnect()
                     86: {
                     87:        int rw = 2;
                     88: 
                     89:        write(FD, DISCONNECT_CMD, 4);
                     90:        sleep(2);
                     91:        ioctl(FD, TIOCFLUSH, &rw);
                     92: }
                     93: 
                     94: biz22_abort()
                     95: {
                     96: 
                     97:        write(FD, "\02", 1);
                     98: }
                     99: 
                    100: static int
                    101: sigALRM()
                    102: {
                    103: 
                    104:        timeout = 1;
                    105:        longjmp(timeoutbuf, 1);
                    106: }
                    107: 
                    108: static int
                    109: cmd(s)
                    110:        register char *s;
                    111: {
                    112:        char c;
                    113:        int (*f)();
                    114: 
                    115:        write(FD, s, strlen(s));
                    116:        f = signal(SIGALRM, sigALRM);
                    117:        if (setjmp(timeoutbuf)) {
                    118:                biz22_abort();
                    119:                signal(SIGALRM, f);
                    120:                return (1);
                    121:        }
                    122:        alarm(number(value(DIALTIMEOUT)));
                    123:        read(FD, &c, 1);
                    124:        alarm(0);
                    125:        signal(SIGALRM, f);
                    126:        c &= 0177;
                    127:        return (c != '\r');
                    128: }
                    129: 
                    130: static int
                    131: detect(s)
                    132:        register char *s;
                    133: {
                    134:        char c;
                    135:        int (*f)();
                    136: 
                    137:        f = signal(SIGALRM, sigALRM);
                    138:        timeout = 0;
                    139:        while (*s) {
                    140:                if (setjmp(timeoutbuf)) {
                    141:                        biz22_abort();
                    142:                        break;
                    143:                }
                    144:                alarm(number(value(DIALTIMEOUT)));
                    145:                read(FD, &c, 1);
                    146:                alarm(0);
                    147:                c &= 0177;
                    148:                if (c != *s++)
                    149:                        return (0);
                    150:        }
                    151:        signal(SIGALRM, f);
                    152:        return (timeout == 0);
                    153: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.