# 2.11BSD#431 - /usr/src/usr.bin/tip/acu.c

##### Functions

    connect           X
    disconnect        X

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

#### Defined functions

acuabort defined in line 147; used 3 times

- in line 15, 52-53(2)

acutype defined in line 154; used 2 times

- in line 16, 68

connect defined in line 34; used 3 times

- in /usr/src/usr.bin/tip/cu.c line 98
- in /usr/src/usr.bin/tip/tip.c line 156
- in /usr/src/usr.bin/tip/tip.h line 244

disconnect defined in line 131; used 2 times

- in line 62
- in /usr/src/usr.bin/tip/cmds.c line 603

#### Defined variables

acu_t defined in line 154; used 4 times

- in line 13-16(2), 158-159(2)

conflag defined in line 14; used 4 times

- in line 61, 77, 112, 134

jmpbuf defined in line 17; used 2 times

- in line 54, 151

sccsid defined in line 8; never used

Last modified: 1987-12-05 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1339 |