1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 1988 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate #include "uucp.h" 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate #ifdef X_PROTOCOL 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate #define XBUFSIZ 512 38*7c478bd9Sstevel@tonic-gate static jmp_buf Xfailbuf; 39*7c478bd9Sstevel@tonic-gate extern int xrdblk(); 40*7c478bd9Sstevel@tonic-gate extern unsigned msgtime; 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate /* 43*7c478bd9Sstevel@tonic-gate * x.25 protocol 44*7c478bd9Sstevel@tonic-gate */ 45*7c478bd9Sstevel@tonic-gate /* ARGSUSED */ 46*7c478bd9Sstevel@tonic-gate static void 47*7c478bd9Sstevel@tonic-gate xalarm(sig) 48*7c478bd9Sstevel@tonic-gate int sig; 49*7c478bd9Sstevel@tonic-gate { 50*7c478bd9Sstevel@tonic-gate longjmp(Xfailbuf, 1); 51*7c478bd9Sstevel@tonic-gate } 52*7c478bd9Sstevel@tonic-gate 53*7c478bd9Sstevel@tonic-gate static void (*xsig)(); 54*7c478bd9Sstevel@tonic-gate 55*7c478bd9Sstevel@tonic-gate /* 56*7c478bd9Sstevel@tonic-gate * turn on protocol timer 57*7c478bd9Sstevel@tonic-gate */ 58*7c478bd9Sstevel@tonic-gate int 59*7c478bd9Sstevel@tonic-gate xturnon() 60*7c478bd9Sstevel@tonic-gate { 61*7c478bd9Sstevel@tonic-gate xsig=signal(SIGALRM, xalarm); 62*7c478bd9Sstevel@tonic-gate return(0); 63*7c478bd9Sstevel@tonic-gate } 64*7c478bd9Sstevel@tonic-gate 65*7c478bd9Sstevel@tonic-gate int 66*7c478bd9Sstevel@tonic-gate xturnoff() 67*7c478bd9Sstevel@tonic-gate { 68*7c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, xsig); 69*7c478bd9Sstevel@tonic-gate return(0); 70*7c478bd9Sstevel@tonic-gate } 71*7c478bd9Sstevel@tonic-gate 72*7c478bd9Sstevel@tonic-gate /* 73*7c478bd9Sstevel@tonic-gate * write message across x.25 link 74*7c478bd9Sstevel@tonic-gate * type -> message type 75*7c478bd9Sstevel@tonic-gate * str -> message body (ascii string) 76*7c478bd9Sstevel@tonic-gate * fn -> x.25 file descriptor 77*7c478bd9Sstevel@tonic-gate * return 78*7c478bd9Sstevel@tonic-gate * 0 79*7c478bd9Sstevel@tonic-gate */ 80*7c478bd9Sstevel@tonic-gate int 81*7c478bd9Sstevel@tonic-gate xwrmsg(type, str, fn) 82*7c478bd9Sstevel@tonic-gate register char *str; 83*7c478bd9Sstevel@tonic-gate int fn; 84*7c478bd9Sstevel@tonic-gate char type; 85*7c478bd9Sstevel@tonic-gate { 86*7c478bd9Sstevel@tonic-gate register char *s; 87*7c478bd9Sstevel@tonic-gate char bufr[XBUFSIZ]; 88*7c478bd9Sstevel@tonic-gate 89*7c478bd9Sstevel@tonic-gate bufr[0] = type; 90*7c478bd9Sstevel@tonic-gate s = &bufr[1]; 91*7c478bd9Sstevel@tonic-gate while (*str) 92*7c478bd9Sstevel@tonic-gate *s++ = *str++; 93*7c478bd9Sstevel@tonic-gate *s = '\0'; 94*7c478bd9Sstevel@tonic-gate if (*(--s) == '\n') 95*7c478bd9Sstevel@tonic-gate *s = '\0'; 96*7c478bd9Sstevel@tonic-gate (void) (*Write)(fn, bufr, strlen(bufr) + 1); 97*7c478bd9Sstevel@tonic-gate return(0); 98*7c478bd9Sstevel@tonic-gate } 99*7c478bd9Sstevel@tonic-gate 100*7c478bd9Sstevel@tonic-gate /* 101*7c478bd9Sstevel@tonic-gate * read message from x.25 link 102*7c478bd9Sstevel@tonic-gate * str -> message buffer 103*7c478bd9Sstevel@tonic-gate * fn -> x.25 file descriptor 104*7c478bd9Sstevel@tonic-gate * return 105*7c478bd9Sstevel@tonic-gate * FAIL -> send timed out 106*7c478bd9Sstevel@tonic-gate * 0 -> ok message in str 107*7c478bd9Sstevel@tonic-gate */ 108*7c478bd9Sstevel@tonic-gate int 109*7c478bd9Sstevel@tonic-gate xrdmsg(str, fn) 110*7c478bd9Sstevel@tonic-gate register char *str; 111*7c478bd9Sstevel@tonic-gate { 112*7c478bd9Sstevel@tonic-gate register int len; 113*7c478bd9Sstevel@tonic-gate 114*7c478bd9Sstevel@tonic-gate if(setjmp(Xfailbuf)) 115*7c478bd9Sstevel@tonic-gate return(FAIL); 116*7c478bd9Sstevel@tonic-gate 117*7c478bd9Sstevel@tonic-gate (void) alarm(msgtime); 118*7c478bd9Sstevel@tonic-gate for (;;) { 119*7c478bd9Sstevel@tonic-gate if( (len = (*Read)(fn, str, XBUFSIZ)) == 0) 120*7c478bd9Sstevel@tonic-gate continue; 121*7c478bd9Sstevel@tonic-gate if (len < 0) { 122*7c478bd9Sstevel@tonic-gate (void) alarm(0); 123*7c478bd9Sstevel@tonic-gate return(FAIL); 124*7c478bd9Sstevel@tonic-gate } 125*7c478bd9Sstevel@tonic-gate str += len; 126*7c478bd9Sstevel@tonic-gate if (*(str - 1) == '\0') 127*7c478bd9Sstevel@tonic-gate break; 128*7c478bd9Sstevel@tonic-gate } 129*7c478bd9Sstevel@tonic-gate (void) alarm(0); 130*7c478bd9Sstevel@tonic-gate return(0); 131*7c478bd9Sstevel@tonic-gate } 132*7c478bd9Sstevel@tonic-gate 133*7c478bd9Sstevel@tonic-gate /* 134*7c478bd9Sstevel@tonic-gate * read data from file fp1 and write 135*7c478bd9Sstevel@tonic-gate * on x.25 link 136*7c478bd9Sstevel@tonic-gate * fp1 -> file descriptor 137*7c478bd9Sstevel@tonic-gate * fn -> x.25 descriptor 138*7c478bd9Sstevel@tonic-gate * returns: 139*7c478bd9Sstevel@tonic-gate * FAIL ->failure in x.25 link 140*7c478bd9Sstevel@tonic-gate * 0 -> ok 141*7c478bd9Sstevel@tonic-gate */ 142*7c478bd9Sstevel@tonic-gate int 143*7c478bd9Sstevel@tonic-gate xwrdata(fp1, fn) 144*7c478bd9Sstevel@tonic-gate FILE *fp1; 145*7c478bd9Sstevel@tonic-gate { 146*7c478bd9Sstevel@tonic-gate register fd1; 147*7c478bd9Sstevel@tonic-gate register int len, ret; 148*7c478bd9Sstevel@tonic-gate unsigned long bytes; 149*7c478bd9Sstevel@tonic-gate char bufr[XBUFSIZ]; 150*7c478bd9Sstevel@tonic-gate 151*7c478bd9Sstevel@tonic-gate bytes = 0L; 152*7c478bd9Sstevel@tonic-gate fd1 = fileno( fp1 ); 153*7c478bd9Sstevel@tonic-gate while ((len = read( fd1, bufr, XBUFSIZ )) > 0) { 154*7c478bd9Sstevel@tonic-gate bytes += len; 155*7c478bd9Sstevel@tonic-gate putfilesize(bytes); 156*7c478bd9Sstevel@tonic-gate ret = (*Write)(fn, bufr, len); 157*7c478bd9Sstevel@tonic-gate if (ret != len) { 158*7c478bd9Sstevel@tonic-gate return(FAIL); 159*7c478bd9Sstevel@tonic-gate } 160*7c478bd9Sstevel@tonic-gate if (len != XBUFSIZ) 161*7c478bd9Sstevel@tonic-gate break; 162*7c478bd9Sstevel@tonic-gate } 163*7c478bd9Sstevel@tonic-gate ret = (*Write)(fn, bufr, 0); 164*7c478bd9Sstevel@tonic-gate return(0); 165*7c478bd9Sstevel@tonic-gate } 166*7c478bd9Sstevel@tonic-gate 167*7c478bd9Sstevel@tonic-gate /* 168*7c478bd9Sstevel@tonic-gate * read data from x.25 link and 169*7c478bd9Sstevel@tonic-gate * write into file 170*7c478bd9Sstevel@tonic-gate * fp2 -> file descriptor 171*7c478bd9Sstevel@tonic-gate * fn -> x.25 descriptor 172*7c478bd9Sstevel@tonic-gate * returns: 173*7c478bd9Sstevel@tonic-gate * 0 -> ok 174*7c478bd9Sstevel@tonic-gate * FAIL -> failure on x.25 link 175*7c478bd9Sstevel@tonic-gate */ 176*7c478bd9Sstevel@tonic-gate int 177*7c478bd9Sstevel@tonic-gate xrddata(fn, fp2) 178*7c478bd9Sstevel@tonic-gate FILE *fp2; 179*7c478bd9Sstevel@tonic-gate { 180*7c478bd9Sstevel@tonic-gate register int fd2; 181*7c478bd9Sstevel@tonic-gate register int len; 182*7c478bd9Sstevel@tonic-gate register int ret = SUCCESS; 183*7c478bd9Sstevel@tonic-gate unsigned long bytes; 184*7c478bd9Sstevel@tonic-gate char bufr[XBUFSIZ]; 185*7c478bd9Sstevel@tonic-gate 186*7c478bd9Sstevel@tonic-gate bytes = 0L; 187*7c478bd9Sstevel@tonic-gate fd2 = fileno( fp2 ); 188*7c478bd9Sstevel@tonic-gate for (;;) { 189*7c478bd9Sstevel@tonic-gate len = xrdblk(bufr, XBUFSIZ, fn); 190*7c478bd9Sstevel@tonic-gate if (len < 0) { 191*7c478bd9Sstevel@tonic-gate return(FAIL); 192*7c478bd9Sstevel@tonic-gate } 193*7c478bd9Sstevel@tonic-gate bytes += len; 194*7c478bd9Sstevel@tonic-gate putfilesize(bytes); 195*7c478bd9Sstevel@tonic-gate if( ret == SUCCESS && write( fd2, bufr, len ) != len ) 196*7c478bd9Sstevel@tonic-gate ret = errno; 197*7c478bd9Sstevel@tonic-gate if (len < XBUFSIZ) 198*7c478bd9Sstevel@tonic-gate break; 199*7c478bd9Sstevel@tonic-gate } 200*7c478bd9Sstevel@tonic-gate return(ret); 201*7c478bd9Sstevel@tonic-gate } 202*7c478bd9Sstevel@tonic-gate 203*7c478bd9Sstevel@tonic-gate /* 204*7c478bd9Sstevel@tonic-gate * read blank from x.25 link 205*7c478bd9Sstevel@tonic-gate * reads are timed 206*7c478bd9Sstevel@tonic-gate * blk -> address of buffer 207*7c478bd9Sstevel@tonic-gate * len -> size to read 208*7c478bd9Sstevel@tonic-gate * fn -> x.25 descriptor 209*7c478bd9Sstevel@tonic-gate * returns: 210*7c478bd9Sstevel@tonic-gate * FAIL -> link error timeout on link 211*7c478bd9Sstevel@tonic-gate * i -> # of bytes read 212*7c478bd9Sstevel@tonic-gate */ 213*7c478bd9Sstevel@tonic-gate int 214*7c478bd9Sstevel@tonic-gate xrdblk(blk, len, fn) 215*7c478bd9Sstevel@tonic-gate register char *blk; 216*7c478bd9Sstevel@tonic-gate { 217*7c478bd9Sstevel@tonic-gate register int i, ret; 218*7c478bd9Sstevel@tonic-gate 219*7c478bd9Sstevel@tonic-gate if(setjmp(Xfailbuf)) 220*7c478bd9Sstevel@tonic-gate return(FAIL); 221*7c478bd9Sstevel@tonic-gate 222*7c478bd9Sstevel@tonic-gate (void) alarm(msgtime); 223*7c478bd9Sstevel@tonic-gate for (i = 0; i < len; i += ret) { 224*7c478bd9Sstevel@tonic-gate if ((ret = (*Read)(fn, blk, len - i)) < 0) { 225*7c478bd9Sstevel@tonic-gate (void) alarm(0); 226*7c478bd9Sstevel@tonic-gate return(FAIL); 227*7c478bd9Sstevel@tonic-gate } 228*7c478bd9Sstevel@tonic-gate blk += ret; 229*7c478bd9Sstevel@tonic-gate if (ret == 0) 230*7c478bd9Sstevel@tonic-gate break; 231*7c478bd9Sstevel@tonic-gate } 232*7c478bd9Sstevel@tonic-gate (void) alarm(0); 233*7c478bd9Sstevel@tonic-gate return(i); 234*7c478bd9Sstevel@tonic-gate } 235*7c478bd9Sstevel@tonic-gate #endif /* X_PROTOCOL */ 236