Annotation of 43BSDReno/usr.bin/tip/aculib/biz31.c, revision 1.1

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[] = "@(#)biz31.c    5.4 (Berkeley) 6/1/90";
        !            22: #endif /* not lint */
        !            23: 
        !            24: #include "tip.h"
        !            25: 
        !            26: #define MAXRETRY       3               /* sync up retry count */
        !            27: #define DISCONNECT_CMD "\21\25\11\24"  /* disconnection string */
        !            28: 
        !            29: static void sigALRM();
        !            30: static int timeout = 0;
        !            31: static jmp_buf timeoutbuf;
        !            32: 
        !            33: /*
        !            34:  * Dial up on a BIZCOMP Model 1031 with either
        !            35:  *     tone dialing (mod = "f")
        !            36:  *     pulse dialing (mod = "w")
        !            37:  */
        !            38: static int
        !            39: biz_dialer(num, mod)
        !            40:        char *num, *mod;
        !            41: {
        !            42:        register int connected = 0;
        !            43: 
        !            44:        if (!bizsync(FD)) {
        !            45:                logent(value(HOST), "", "biz", "out of sync");
        !            46:                printf("bizcomp out of sync\n");
        !            47:                delock(uucplock);
        !            48:                exit(0);
        !            49:        }
        !            50:        if (boolean(value(VERBOSE)))
        !            51:                printf("\nstarting call...");
        !            52:        echo("#\rk$\r$\n");                     /* disable auto-answer */
        !            53:        echo("$>$.$ #\r");                      /* tone/pulse dialing */
        !            54:        echo(mod);
        !            55:        echo("$\r$\n");
        !            56:        echo("$>$.$ #\re$ ");                   /* disconnection sequence */
        !            57:        echo(DISCONNECT_CMD);
        !            58:        echo("\r$\n$\r$\n");
        !            59:        echo("$>$.$ #\rr$ ");                   /* repeat dial */
        !            60:        echo(num);
        !            61:        echo("\r$\n");
        !            62:        if (boolean(value(VERBOSE)))
        !            63:                printf("ringing...");
        !            64:        /*
        !            65:         * The reply from the BIZCOMP should be:
        !            66:         *      `^G NO CONNECTION\r\n^G\r\n'    failure
        !            67:         *      ` CONNECTION\r\n^G'             success
        !            68:         */
        !            69:        connected = detect(" ");
        !            70: #ifdef ACULOG
        !            71:        if (timeout) {
        !            72:                char line[80];
        !            73: 
        !            74:                sprintf(line, "%d second dial timeout",
        !            75:                        number(value(DIALTIMEOUT)));
        !            76:                logent(value(HOST), num, "biz", line);
        !            77:        }
        !            78: #endif
        !            79:        if (!connected)
        !            80:                flush(" NO CONNECTION\r\n\07\r\n");
        !            81:        else
        !            82:                flush("CONNECTION\r\n\07");
        !            83:        if (timeout)
        !            84:                biz31_disconnect();     /* insurance */
        !            85:        return (connected);
        !            86: }
        !            87: 
        !            88: biz31w_dialer(num, acu)
        !            89:        char *num, *acu;
        !            90: {
        !            91: 
        !            92:        return (biz_dialer(num, "w"));
        !            93: }
        !            94: 
        !            95: biz31f_dialer(num, acu)
        !            96:        char *num, *acu;
        !            97: {
        !            98: 
        !            99:        return (biz_dialer(num, "f"));
        !           100: }
        !           101: 
        !           102: biz31_disconnect()
        !           103: {
        !           104: 
        !           105:        write(FD, DISCONNECT_CMD, 4);
        !           106:        sleep(2);
        !           107:        ioctl(FD, TIOCFLUSH);
        !           108: }
        !           109: 
        !           110: biz31_abort()
        !           111: {
        !           112: 
        !           113:        write(FD, "\33", 1);
        !           114: }
        !           115: 
        !           116: static int
        !           117: echo(s)
        !           118:        register char *s;
        !           119: {
        !           120:        char c;
        !           121: 
        !           122:        while (c = *s++) switch (c) {
        !           123: 
        !           124:        case '$':
        !           125:                read(FD, &c, 1);
        !           126:                s++;
        !           127:                break;
        !           128: 
        !           129:        case '#':
        !           130:                c = *s++;
        !           131:                write(FD, &c, 1);
        !           132:                break;
        !           133: 
        !           134:        default:
        !           135:                write(FD, &c, 1);
        !           136:                read(FD, &c, 1);
        !           137:        }
        !           138: }
        !           139: 
        !           140: static void
        !           141: sigALRM()
        !           142: {
        !           143: 
        !           144:        timeout = 1;
        !           145:        longjmp(timeoutbuf, 1);
        !           146: }
        !           147: 
        !           148: static int
        !           149: detect(s)
        !           150:        register char *s;
        !           151: {
        !           152:        sig_t f;
        !           153:        char c;
        !           154: 
        !           155:        f = signal(SIGALRM, sigALRM);
        !           156:        timeout = 0;
        !           157:        while (*s) {
        !           158:                if (setjmp(timeoutbuf)) {
        !           159:                        printf("\07timeout waiting for reply\n");
        !           160:                        biz31_abort();
        !           161:                        break;
        !           162:                }
        !           163:                alarm(number(value(DIALTIMEOUT)));
        !           164:                read(FD, &c, 1);
        !           165:                alarm(0);
        !           166:                if (c != *s++)
        !           167:                        break;
        !           168:        }
        !           169:        signal(SIGALRM, f);
        !           170:        return (timeout == 0);
        !           171: }
        !           172: 
        !           173: static int
        !           174: flush(s)
        !           175:        register char *s;
        !           176: {
        !           177:        sig_t f;
        !           178:        char c;
        !           179: 
        !           180:        f = signal(SIGALRM, sigALRM);
        !           181:        while (*s++) {
        !           182:                if (setjmp(timeoutbuf))
        !           183:                        break;
        !           184:                alarm(10);
        !           185:                read(FD, &c, 1);
        !           186:                alarm(0);
        !           187:        }
        !           188:        signal(SIGALRM, f);
        !           189:        timeout = 0;                    /* guard against disconnection */
        !           190: }
        !           191: 
        !           192: /*
        !           193:  * This convoluted piece of code attempts to get
        !           194:  *  the bizcomp in sync.  If you don't have the capacity or nread
        !           195:  *  call there are gory ways to simulate this.
        !           196:  */
        !           197: static int
        !           198: bizsync(fd)
        !           199: {
        !           200: #ifdef FIOCAPACITY
        !           201:        struct capacity b;
        !           202: #      define chars(b) ((b).cp_nbytes)
        !           203: #      define IOCTL    FIOCAPACITY
        !           204: #endif
        !           205: #ifdef FIONREAD
        !           206:        long b;
        !           207: #      define chars(b) (b)
        !           208: #      define IOCTL    FIONREAD
        !           209: #endif
        !           210:        register int already = 0;
        !           211:        char buf[10];
        !           212: 
        !           213: retry:
        !           214:        if (ioctl(fd, IOCTL, (caddr_t)&b) >= 0 && chars(b) > 0)
        !           215:                ioctl(fd, TIOCFLUSH);
        !           216:        write(fd, "\rp>\r", 4);
        !           217:        sleep(1);
        !           218:        if (ioctl(fd, IOCTL, (caddr_t)&b) >= 0) {
        !           219:                if (chars(b) != 10) {
        !           220:        nono:
        !           221:                        if (already > MAXRETRY)
        !           222:                                return (0);
        !           223:                        write(fd, DISCONNECT_CMD, 4);
        !           224:                        sleep(2);
        !           225:                        already++;
        !           226:                        goto retry;
        !           227:                } else {
        !           228:                        read(fd, buf, 10);
        !           229:                        if (strncmp(buf, "p >\r\n\r\n>", 8))
        !           230:                                goto nono;
        !           231:                }
        !           232:        }
        !           233:        return (1);
        !           234: }

unix.superglobalmegacorp.com

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