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.3 (Berkeley) 4/3/86";
   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:         return (NOSTR);
  46:     }
  47:     /*
  48: 	 * @ =>'s use data base in PHONES environment variable
  49: 	 *        otherwise, use /etc/phones
  50: 	 */
  51:     signal(SIGINT, acuabort);
  52:     signal(SIGQUIT, acuabort);
  53:     if (setjmp(jmpbuf)) {
  54:         signal(SIGINT, SIG_IGN);
  55:         signal(SIGQUIT, SIG_IGN);
  56:         printf("\ncall aborted\n");
  57:         logent(value(HOST), "", "", "call aborted");
  58:         if (acu != NOACU) {
  59:             boolean(value(VERBOSE)) = FALSE;
  60:             if (conflag)
  61:                 disconnect(NOSTR);
  62:             else
  63:                 (*acu->acu_abort)();
  64:         }
  65:         delock(uucplock);
  66:         exit(1);
  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:         return;
 136:     if (reason == NOSTR) {
 137:         logent(value(HOST), "", acu->acu_name, "call terminated");
 138:         if (boolean(value(VERBOSE)))
 139:             printf("\r\ndisconnecting...");
 140:     } else
 141:         logent(value(HOST), "", acu->acu_name, reason);
 142:     (*acu->acu_disconnect)();
 143: }
 144: 
 145: static int
 146: acuabort(s)
 147: {
 148:     signal(s, SIG_IGN);
 149:     longjmp(jmpbuf, 1);
 150: }
 151: 
 152: static acu_t *
 153: acutype(s)
 154:     register char *s;
 155: {
 156:     register acu_t *p;
 157:     extern acu_t acutable[];
 158: 
 159:     for (p = acutable; p->acu_name != '\0'; p++)
 160:         if (!strcmp(s, p->acu_name))
 161:             return (p);
 162:     return (NOACU);
 163: }

Defined functions

acuabort defined in line 145; used 3 times
acutype defined in line 152; used 2 times
disconnect defined in line 131; used 2 times

Defined variables

acu_t defined in line 152; used 4 times
conflag defined in line 14; used 4 times
jmpbuf defined in line 17; used 2 times
sccsid defined in line 8; never used
Last modified: 1986-04-04
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1296
Valid CSS Valid XHTML 1.0 Strict