Annotation of 43BSDReno/usr.bin/tip/acu.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[] = "@(#)acu.c      5.7 (Berkeley) 6/1/90";
        !            22: #endif /* not lint */
        !            23: 
        !            24: #include "tip.h"
        !            25: 
        !            26: static acu_t *acu = NOACU;
        !            27: static int conflag;
        !            28: static int acuabort();
        !            29: static acu_t *acutype();
        !            30: static jmp_buf jmpbuf;
        !            31: /*
        !            32:  * Establish connection for tip
        !            33:  *
        !            34:  * If DU is true, we should dial an ACU whose type is AT.
        !            35:  * The phone numbers are in PN, and the call unit is in CU.
        !            36:  *
        !            37:  * If the PN is an '@', then we consult the PHONES file for
        !            38:  *   the phone numbers.  This file is /etc/phones, unless overriden
        !            39:  *   by an exported shell variable.
        !            40:  *
        !            41:  * The data base files must be in the format:
        !            42:  *     host-name[ \t]*phone-number
        !            43:  *   with the possibility of multiple phone numbers
        !            44:  *   for a single host acting as a rotary (in the order
        !            45:  *   found in the file).
        !            46:  */
        !            47: char *
        !            48: connect()
        !            49: {
        !            50:        register char *cp = PN;
        !            51:        char *phnum, string[256];
        !            52:        FILE *fd;
        !            53:        int tried = 0;
        !            54: 
        !            55:        if (!DU) {              /* regular connect message */
        !            56:                if (CM != NOSTR)
        !            57:                        pwrite(FD, CM, size(CM));
        !            58:                logent(value(HOST), "", DV, "call completed");
        !            59:                return (NOSTR);
        !            60:        }
        !            61:        /*
        !            62:         * @ =>'s use data base in PHONES environment variable
        !            63:         *        otherwise, use /etc/phones
        !            64:         */
        !            65:        signal(SIGINT, acuabort);
        !            66:        signal(SIGQUIT, acuabort);
        !            67:        if (setjmp(jmpbuf)) {
        !            68:                signal(SIGINT, SIG_IGN);
        !            69:                signal(SIGQUIT, SIG_IGN);
        !            70:                printf("\ncall aborted\n");
        !            71:                logent(value(HOST), "", "", "call aborted");
        !            72:                if (acu != NOACU) {
        !            73:                        boolean(value(VERBOSE)) = FALSE;
        !            74:                        if (conflag)
        !            75:                                disconnect(NOSTR);
        !            76:                        else
        !            77:                                (*acu->acu_abort)();
        !            78:                }
        !            79:                return ("interrupt");
        !            80:        }
        !            81:        if ((acu = acutype(AT)) == NOACU)
        !            82:                return ("unknown ACU type");
        !            83:        if (*cp != '@') {
        !            84:                while (*cp) {
        !            85:                        for (phnum = cp; *cp && *cp != ','; cp++)
        !            86:                                ;
        !            87:                        if (*cp)
        !            88:                                *cp++ = '\0';
        !            89:                        
        !            90:                        if (conflag = (*acu->acu_dialer)(phnum, CU)) {
        !            91:                                logent(value(HOST), phnum, acu->acu_name,
        !            92:                                        "call completed");
        !            93:                                return (NOSTR);
        !            94:                        } else
        !            95:                                logent(value(HOST), phnum, acu->acu_name,
        !            96:                                        "call failed");
        !            97:                        tried++;
        !            98:                }
        !            99:        } else {
        !           100:                if ((fd = fopen(PH, "r")) == NOFILE) {
        !           101:                        printf("%s: ", PH);
        !           102:                        return ("can't open phone number file");
        !           103:                }
        !           104:                while (fgets(string, sizeof(string), fd) != NOSTR) {
        !           105:                        for (cp = string; !any(*cp, " \t\n"); cp++)
        !           106:                                ;
        !           107:                        if (*cp == '\n') {
        !           108:                                fclose(fd);
        !           109:                                return ("unrecognizable host name");
        !           110:                        }
        !           111:                        *cp++ = '\0';
        !           112:                        if (strcmp(string, value(HOST)))
        !           113:                                continue;
        !           114:                        while (any(*cp, " \t"))
        !           115:                                cp++;
        !           116:                        if (*cp == '\n') {
        !           117:                                fclose(fd);
        !           118:                                return ("missing phone number");
        !           119:                        }
        !           120:                        for (phnum = cp; *cp && *cp != ',' && *cp != '\n'; cp++)
        !           121:                                ;
        !           122:                        if (*cp)
        !           123:                                *cp++ = '\0';
        !           124:                        
        !           125:                        if (conflag = (*acu->acu_dialer)(phnum, CU)) {
        !           126:                                fclose(fd);
        !           127:                                logent(value(HOST), phnum, acu->acu_name,
        !           128:                                        "call completed");
        !           129:                                return (NOSTR);
        !           130:                        } else
        !           131:                                logent(value(HOST), phnum, acu->acu_name,
        !           132:                                        "call failed");
        !           133:                        tried++;
        !           134:                }
        !           135:                fclose(fd);
        !           136:        }
        !           137:        if (!tried)
        !           138:                logent(value(HOST), "", acu->acu_name, "missing phone number");
        !           139:        else
        !           140:                (*acu->acu_abort)();
        !           141:        return (tried ? "call failed" : "missing phone number");
        !           142: }
        !           143: 
        !           144: disconnect(reason)
        !           145:        char *reason;
        !           146: {
        !           147:        if (!conflag) {
        !           148:                logent(value(HOST), "", DV, "call terminated");
        !           149:                return;
        !           150:        }
        !           151:        if (reason == NOSTR) {
        !           152:                logent(value(HOST), "", acu->acu_name, "call terminated");
        !           153:                if (boolean(value(VERBOSE)))
        !           154:                        printf("\r\ndisconnecting...");
        !           155:        } else 
        !           156:                logent(value(HOST), "", acu->acu_name, reason);
        !           157:        (*acu->acu_disconnect)();
        !           158: }
        !           159: 
        !           160: static int
        !           161: acuabort(s)
        !           162: {
        !           163:        signal(s, SIG_IGN);
        !           164:        longjmp(jmpbuf, 1);
        !           165: }
        !           166: 
        !           167: static acu_t *
        !           168: acutype(s)
        !           169:        register char *s;
        !           170: {
        !           171:        register acu_t *p;
        !           172:        extern acu_t acutable[];
        !           173: 
        !           174:        for (p = acutable; p->acu_name != '\0'; p++)
        !           175:                if (!strcmp(s, p->acu_name))
        !           176:                        return (p);
        !           177:        return (NOACU);
        !           178: }

unix.superglobalmegacorp.com

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