10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
30Sstevel@tonic-gate * Use is subject to license terms.
40Sstevel@tonic-gate */
5*549Smuffin
60Sstevel@tonic-gate /*
70Sstevel@tonic-gate * Copyright (c) 1983 Regents of the University of California.
80Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement
90Sstevel@tonic-gate * specifies the terms and conditions for redistribution.
100Sstevel@tonic-gate */
110Sstevel@tonic-gate
12*549Smuffin #pragma ident "%Z%%M% %I% %E% SMI"
130Sstevel@tonic-gate
140Sstevel@tonic-gate #include "tip.h"
150Sstevel@tonic-gate
16*549Smuffin extern acu_t acutable[];
17*549Smuffin
180Sstevel@tonic-gate static acu_t *acu = NOACU;
190Sstevel@tonic-gate static int conflag;
20*549Smuffin static void acuabort(int);
21*549Smuffin static acu_t *acutype(char *);
220Sstevel@tonic-gate static sigjmp_buf jmpbuf;
23*549Smuffin
240Sstevel@tonic-gate /*
250Sstevel@tonic-gate * Establish connection for tip
260Sstevel@tonic-gate *
270Sstevel@tonic-gate * If DU is true, we should dial an ACU whose type is AT.
280Sstevel@tonic-gate * The phone numbers are in PN, and the call unit is in CU.
290Sstevel@tonic-gate *
300Sstevel@tonic-gate * If the PN is an '@', then we consult the PHONES file for
310Sstevel@tonic-gate * the phone numbers. This file is /etc/phones, unless overriden
320Sstevel@tonic-gate * by an exported shell variable.
330Sstevel@tonic-gate *
340Sstevel@tonic-gate * The data base files must be in the format:
350Sstevel@tonic-gate * host-name[ \t]*phone-number
360Sstevel@tonic-gate * with the possibility of multiple phone numbers
370Sstevel@tonic-gate * for a single host acting as a rotary (in the order
380Sstevel@tonic-gate * found in the file).
390Sstevel@tonic-gate */
400Sstevel@tonic-gate char *
connect(void)41*549Smuffin connect(void)
420Sstevel@tonic-gate {
43*549Smuffin char *cp = PN;
440Sstevel@tonic-gate char *phnum, string[256];
450Sstevel@tonic-gate int tried = 0;
460Sstevel@tonic-gate
470Sstevel@tonic-gate if (!DU)
480Sstevel@tonic-gate return (NOSTR);
490Sstevel@tonic-gate /*
500Sstevel@tonic-gate * @ =>'s use data base in PHONES environment variable
510Sstevel@tonic-gate * otherwise, use /etc/phones
520Sstevel@tonic-gate */
530Sstevel@tonic-gate if (sigsetjmp(jmpbuf, 1)) {
54*549Smuffin (void) signal(SIGINT, SIG_IGN);
55*549Smuffin (void) signal(SIGQUIT, SIG_IGN);
56*549Smuffin (void) printf("\ncall aborted\n");
570Sstevel@tonic-gate logent(value(HOST), "", "", "call aborted");
580Sstevel@tonic-gate if (acu != NOACU) {
590Sstevel@tonic-gate boolean(value(VERBOSE)) = FALSE;
600Sstevel@tonic-gate if (conflag)
610Sstevel@tonic-gate disconnect(NOSTR);
620Sstevel@tonic-gate else
630Sstevel@tonic-gate (*acu->acu_abort)();
640Sstevel@tonic-gate }
650Sstevel@tonic-gate myperm();
660Sstevel@tonic-gate delock(uucplock);
670Sstevel@tonic-gate exit(1);
680Sstevel@tonic-gate }
69*549Smuffin (void) signal(SIGINT, acuabort);
70*549Smuffin (void) signal(SIGQUIT, acuabort);
710Sstevel@tonic-gate if ((acu = acutype(AT)) == NOACU)
720Sstevel@tonic-gate return ("unknown ACU type");
730Sstevel@tonic-gate if (*cp != '@') {
740Sstevel@tonic-gate while (*cp) {
750Sstevel@tonic-gate for (phnum = cp; *cp && *cp != '|'; cp++)
760Sstevel@tonic-gate ;
770Sstevel@tonic-gate if (*cp)
780Sstevel@tonic-gate *cp++ = '\0';
790Sstevel@tonic-gate
800Sstevel@tonic-gate if (conflag = (*acu->acu_dialer)(phnum, CU)) {
810Sstevel@tonic-gate logent(value(HOST), phnum, acu->acu_name,
82*549Smuffin "call completed");
830Sstevel@tonic-gate return (NOSTR);
840Sstevel@tonic-gate } else
850Sstevel@tonic-gate logent(value(HOST), phnum, acu->acu_name,
86*549Smuffin "call failed");
870Sstevel@tonic-gate tried++;
880Sstevel@tonic-gate }
890Sstevel@tonic-gate } else {
900Sstevel@tonic-gate if (phfd == NOFILE) {
91*549Smuffin (void) printf("%s: ", PH);
920Sstevel@tonic-gate return ("can't open phone number file");
930Sstevel@tonic-gate }
940Sstevel@tonic-gate rewind(phfd);
950Sstevel@tonic-gate while (fgets(string, sizeof (string), phfd) != NOSTR) {
960Sstevel@tonic-gate if (string[0] == '#')
970Sstevel@tonic-gate continue;
980Sstevel@tonic-gate for (cp = string; !any(*cp, " \t\n"); cp++)
990Sstevel@tonic-gate ;
1000Sstevel@tonic-gate if (*cp == '\n')
1010Sstevel@tonic-gate return ("unrecognizable host name");
1020Sstevel@tonic-gate *cp++ = '\0';
1030Sstevel@tonic-gate if (!equal(string, value(HOST)))
1040Sstevel@tonic-gate continue;
1050Sstevel@tonic-gate while (any(*cp, " \t"))
1060Sstevel@tonic-gate cp++;
1070Sstevel@tonic-gate if (*cp == '\n')
1080Sstevel@tonic-gate return ("missing phone number");
1090Sstevel@tonic-gate for (phnum = cp; *cp && *cp != '|' && *cp != '\n'; cp++)
1100Sstevel@tonic-gate ;
1110Sstevel@tonic-gate *cp = '\0';
1120Sstevel@tonic-gate
1130Sstevel@tonic-gate if (conflag = (*acu->acu_dialer)(phnum, CU)) {
1140Sstevel@tonic-gate logent(value(HOST), phnum, acu->acu_name,
115*549Smuffin "call completed");
1160Sstevel@tonic-gate return (NOSTR);
1170Sstevel@tonic-gate } else
1180Sstevel@tonic-gate logent(value(HOST), phnum, acu->acu_name,
119*549Smuffin "call failed");
1200Sstevel@tonic-gate tried++;
1210Sstevel@tonic-gate }
1220Sstevel@tonic-gate }
1230Sstevel@tonic-gate if (!tried)
1240Sstevel@tonic-gate logent(value(HOST), "", acu->acu_name, "missing phone number");
1250Sstevel@tonic-gate else
1260Sstevel@tonic-gate (*acu->acu_abort)();
1270Sstevel@tonic-gate return (tried ? "call failed" : "missing phone number");
1280Sstevel@tonic-gate }
1290Sstevel@tonic-gate
130*549Smuffin void
disconnect(char * reason)131*549Smuffin disconnect(char *reason)
1320Sstevel@tonic-gate {
1330Sstevel@tonic-gate if (!conflag)
1340Sstevel@tonic-gate return;
1350Sstevel@tonic-gate if (reason == NOSTR) {
1360Sstevel@tonic-gate logent(value(HOST), "", acu->acu_name, "call terminated");
1370Sstevel@tonic-gate if (boolean(value(VERBOSE)))
138*549Smuffin (void) printf("\r\ndisconnecting...");
1390Sstevel@tonic-gate } else
1400Sstevel@tonic-gate logent(value(HOST), "", acu->acu_name, reason);
1410Sstevel@tonic-gate (*acu->acu_disconnect)();
1420Sstevel@tonic-gate }
1430Sstevel@tonic-gate
1440Sstevel@tonic-gate static void
acuabort(int s)145*549Smuffin acuabort(int s)
1460Sstevel@tonic-gate {
147*549Smuffin (void) signal(s, SIG_IGN);
1480Sstevel@tonic-gate siglongjmp(jmpbuf, 1);
1490Sstevel@tonic-gate }
1500Sstevel@tonic-gate
1510Sstevel@tonic-gate static acu_t *
acutype(char * s)152*549Smuffin acutype(char *s)
1530Sstevel@tonic-gate {
154*549Smuffin acu_t *p;
1550Sstevel@tonic-gate
1560Sstevel@tonic-gate if (s != NOSTR)
1570Sstevel@tonic-gate for (p = acutable; p->acu_name != '\0'; p++)
1580Sstevel@tonic-gate if (equal(s, p->acu_name))
1590Sstevel@tonic-gate return (p);
1600Sstevel@tonic-gate return (NOACU);
1610Sstevel@tonic-gate }
162