17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 37c478bd9Sstevel@tonic-gate * Use is subject to license terms. 47c478bd9Sstevel@tonic-gate */ 5*8d489c7aSmuffin 67c478bd9Sstevel@tonic-gate /* 77c478bd9Sstevel@tonic-gate * Copyright (c) 1983 Regents of the University of California. 87c478bd9Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement 97c478bd9Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 107c478bd9Sstevel@tonic-gate */ 117c478bd9Sstevel@tonic-gate 12*8d489c7aSmuffin #pragma ident "%Z%%M% %I% %E% SMI" 137c478bd9Sstevel@tonic-gate 147c478bd9Sstevel@tonic-gate #include "tip.h" 157c478bd9Sstevel@tonic-gate 16*8d489c7aSmuffin extern acu_t acutable[]; 17*8d489c7aSmuffin 187c478bd9Sstevel@tonic-gate static acu_t *acu = NOACU; 197c478bd9Sstevel@tonic-gate static int conflag; 20*8d489c7aSmuffin static void acuabort(int); 21*8d489c7aSmuffin static acu_t *acutype(char *); 227c478bd9Sstevel@tonic-gate static sigjmp_buf jmpbuf; 23*8d489c7aSmuffin 247c478bd9Sstevel@tonic-gate /* 257c478bd9Sstevel@tonic-gate * Establish connection for tip 267c478bd9Sstevel@tonic-gate * 277c478bd9Sstevel@tonic-gate * If DU is true, we should dial an ACU whose type is AT. 287c478bd9Sstevel@tonic-gate * The phone numbers are in PN, and the call unit is in CU. 297c478bd9Sstevel@tonic-gate * 307c478bd9Sstevel@tonic-gate * If the PN is an '@', then we consult the PHONES file for 317c478bd9Sstevel@tonic-gate * the phone numbers. This file is /etc/phones, unless overriden 327c478bd9Sstevel@tonic-gate * by an exported shell variable. 337c478bd9Sstevel@tonic-gate * 347c478bd9Sstevel@tonic-gate * The data base files must be in the format: 357c478bd9Sstevel@tonic-gate * host-name[ \t]*phone-number 367c478bd9Sstevel@tonic-gate * with the possibility of multiple phone numbers 377c478bd9Sstevel@tonic-gate * for a single host acting as a rotary (in the order 387c478bd9Sstevel@tonic-gate * found in the file). 397c478bd9Sstevel@tonic-gate */ 407c478bd9Sstevel@tonic-gate char * 41*8d489c7aSmuffin connect(void) 427c478bd9Sstevel@tonic-gate { 43*8d489c7aSmuffin char *cp = PN; 447c478bd9Sstevel@tonic-gate char *phnum, string[256]; 457c478bd9Sstevel@tonic-gate int tried = 0; 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate if (!DU) 487c478bd9Sstevel@tonic-gate return (NOSTR); 497c478bd9Sstevel@tonic-gate /* 507c478bd9Sstevel@tonic-gate * @ =>'s use data base in PHONES environment variable 517c478bd9Sstevel@tonic-gate * otherwise, use /etc/phones 527c478bd9Sstevel@tonic-gate */ 537c478bd9Sstevel@tonic-gate if (sigsetjmp(jmpbuf, 1)) { 54*8d489c7aSmuffin (void) signal(SIGINT, SIG_IGN); 55*8d489c7aSmuffin (void) signal(SIGQUIT, SIG_IGN); 56*8d489c7aSmuffin (void) printf("\ncall aborted\n"); 577c478bd9Sstevel@tonic-gate logent(value(HOST), "", "", "call aborted"); 587c478bd9Sstevel@tonic-gate if (acu != NOACU) { 597c478bd9Sstevel@tonic-gate boolean(value(VERBOSE)) = FALSE; 607c478bd9Sstevel@tonic-gate if (conflag) 617c478bd9Sstevel@tonic-gate disconnect(NOSTR); 627c478bd9Sstevel@tonic-gate else 637c478bd9Sstevel@tonic-gate (*acu->acu_abort)(); 647c478bd9Sstevel@tonic-gate } 657c478bd9Sstevel@tonic-gate myperm(); 667c478bd9Sstevel@tonic-gate delock(uucplock); 677c478bd9Sstevel@tonic-gate exit(1); 687c478bd9Sstevel@tonic-gate } 69*8d489c7aSmuffin (void) signal(SIGINT, acuabort); 70*8d489c7aSmuffin (void) signal(SIGQUIT, acuabort); 717c478bd9Sstevel@tonic-gate if ((acu = acutype(AT)) == NOACU) 727c478bd9Sstevel@tonic-gate return ("unknown ACU type"); 737c478bd9Sstevel@tonic-gate if (*cp != '@') { 747c478bd9Sstevel@tonic-gate while (*cp) { 757c478bd9Sstevel@tonic-gate for (phnum = cp; *cp && *cp != '|'; cp++) 767c478bd9Sstevel@tonic-gate ; 777c478bd9Sstevel@tonic-gate if (*cp) 787c478bd9Sstevel@tonic-gate *cp++ = '\0'; 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate if (conflag = (*acu->acu_dialer)(phnum, CU)) { 817c478bd9Sstevel@tonic-gate logent(value(HOST), phnum, acu->acu_name, 827c478bd9Sstevel@tonic-gate "call completed"); 837c478bd9Sstevel@tonic-gate return (NOSTR); 847c478bd9Sstevel@tonic-gate } else 857c478bd9Sstevel@tonic-gate logent(value(HOST), phnum, acu->acu_name, 867c478bd9Sstevel@tonic-gate "call failed"); 877c478bd9Sstevel@tonic-gate tried++; 887c478bd9Sstevel@tonic-gate } 897c478bd9Sstevel@tonic-gate } else { 907c478bd9Sstevel@tonic-gate if (phfd == NOFILE) { 91*8d489c7aSmuffin (void) printf("%s: ", PH); 927c478bd9Sstevel@tonic-gate return ("can't open phone number file"); 937c478bd9Sstevel@tonic-gate } 947c478bd9Sstevel@tonic-gate rewind(phfd); 957c478bd9Sstevel@tonic-gate while (fgets(string, sizeof (string), phfd) != NOSTR) { 967c478bd9Sstevel@tonic-gate if (string[0] == '#') 977c478bd9Sstevel@tonic-gate continue; 987c478bd9Sstevel@tonic-gate for (cp = string; !any(*cp, " \t\n"); cp++) 997c478bd9Sstevel@tonic-gate ; 1007c478bd9Sstevel@tonic-gate if (*cp == '\n') 1017c478bd9Sstevel@tonic-gate return ("unrecognizable host name"); 1027c478bd9Sstevel@tonic-gate *cp++ = '\0'; 1037c478bd9Sstevel@tonic-gate if (!equal(string, value(HOST))) 1047c478bd9Sstevel@tonic-gate continue; 1057c478bd9Sstevel@tonic-gate while (any(*cp, " \t")) 1067c478bd9Sstevel@tonic-gate cp++; 1077c478bd9Sstevel@tonic-gate if (*cp == '\n') 1087c478bd9Sstevel@tonic-gate return ("missing phone number"); 1097c478bd9Sstevel@tonic-gate for (phnum = cp; *cp && *cp != '|' && *cp != '\n'; cp++) 1107c478bd9Sstevel@tonic-gate ; 1117c478bd9Sstevel@tonic-gate *cp = '\0'; 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate if (conflag = (*acu->acu_dialer)(phnum, CU)) { 1147c478bd9Sstevel@tonic-gate logent(value(HOST), phnum, acu->acu_name, 1157c478bd9Sstevel@tonic-gate "call completed"); 1167c478bd9Sstevel@tonic-gate return (NOSTR); 1177c478bd9Sstevel@tonic-gate } else 1187c478bd9Sstevel@tonic-gate logent(value(HOST), phnum, acu->acu_name, 1197c478bd9Sstevel@tonic-gate "call failed"); 1207c478bd9Sstevel@tonic-gate tried++; 1217c478bd9Sstevel@tonic-gate } 1227c478bd9Sstevel@tonic-gate } 1237c478bd9Sstevel@tonic-gate if (!tried) 1247c478bd9Sstevel@tonic-gate logent(value(HOST), "", acu->acu_name, "missing phone number"); 1257c478bd9Sstevel@tonic-gate else 1267c478bd9Sstevel@tonic-gate (*acu->acu_abort)(); 1277c478bd9Sstevel@tonic-gate return (tried ? "call failed" : "missing phone number"); 1287c478bd9Sstevel@tonic-gate } 1297c478bd9Sstevel@tonic-gate 130*8d489c7aSmuffin void 131*8d489c7aSmuffin disconnect(char *reason) 1327c478bd9Sstevel@tonic-gate { 1337c478bd9Sstevel@tonic-gate if (!conflag) 1347c478bd9Sstevel@tonic-gate return; 1357c478bd9Sstevel@tonic-gate if (reason == NOSTR) { 1367c478bd9Sstevel@tonic-gate logent(value(HOST), "", acu->acu_name, "call terminated"); 1377c478bd9Sstevel@tonic-gate if (boolean(value(VERBOSE))) 138*8d489c7aSmuffin (void) printf("\r\ndisconnecting..."); 1397c478bd9Sstevel@tonic-gate } else 1407c478bd9Sstevel@tonic-gate logent(value(HOST), "", acu->acu_name, reason); 1417c478bd9Sstevel@tonic-gate (*acu->acu_disconnect)(); 1427c478bd9Sstevel@tonic-gate } 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate static void 145*8d489c7aSmuffin acuabort(int s) 1467c478bd9Sstevel@tonic-gate { 147*8d489c7aSmuffin (void) signal(s, SIG_IGN); 1487c478bd9Sstevel@tonic-gate siglongjmp(jmpbuf, 1); 1497c478bd9Sstevel@tonic-gate } 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate static acu_t * 152*8d489c7aSmuffin acutype(char *s) 1537c478bd9Sstevel@tonic-gate { 154*8d489c7aSmuffin acu_t *p; 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate if (s != NOSTR) 1577c478bd9Sstevel@tonic-gate for (p = acutable; p->acu_name != '\0'; p++) 1587c478bd9Sstevel@tonic-gate if (equal(s, p->acu_name)) 1597c478bd9Sstevel@tonic-gate return (p); 1607c478bd9Sstevel@tonic-gate return (NOACU); 1617c478bd9Sstevel@tonic-gate } 162