2 Protocol support routines to move commands and data around.
4 Copyright (C) 1991, 1992, 1994 Ian Lance Taylor
6 This file is part of the Taylor UUCP package.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 The author of the program may be contacted at ian@airs.com or
23 c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144.
29 const char prot_rcsid[] = "$FreeBSD$";
40 /* Variables visible to the protocol-specific routines. */
42 /* Buffer to hold received data. */
43 char abPrecbuf[CRECBUFLEN];
45 /* Index of start of data in abPrecbuf. */
48 /* Index of end of data (first byte not included in data) in abPrecbuf. */
51 /* We want to output and input at the same time, if supported on this
52 machine. If we have something to send, we send it all while
53 accepting a large amount of data. Once we have sent everything we
54 look at whatever we have received. If data comes in faster than we
55 can send it, we may run out of buffer space. */
58 fsend_data (qconn, zsend, csend, fdoread)
59 struct sconnection *qconn;
65 return fconn_write (qconn, zsend, csend);
71 if (iPrecend < iPrecstart)
72 crec = iPrecstart - iPrecend - 1;
75 crec = CRECBUFLEN - iPrecend;
81 return fconn_write (qconn, zsend, csend);
85 if (! fconn_io (qconn, zsend, &csent, abPrecbuf + iPrecend, &crec))
91 iPrecend = (iPrecend + crec) % CRECBUFLEN;
97 /* Read data from the other system when we have nothing to send. The
98 argument cneed is the amount of data the caller wants, and ctimeout
99 is the timeout in seconds. The function sets *pcrec to the amount
100 of data which was actually received, which may be less than cneed
101 if there isn't enough room in the receive buffer. If no data is
102 received before the timeout expires, *pcrec will be returned as 0.
103 If an error occurs, the function returns FALSE. If the freport
104 argument is FALSE, no error should be reported. */
107 freceive_data (qconn, cneed, pcrec, ctimeout, freport)
108 struct sconnection *qconn;
114 /* Set *pcrec to the maximum amount of data we can read. fconn_read
115 expects *pcrec to be the buffer size, and sets it to the amount
116 actually received. */
117 if (iPrecend < iPrecstart)
118 *pcrec = iPrecstart - iPrecend - 1;
121 *pcrec = CRECBUFLEN - iPrecend;
127 /* If we have no room in the buffer, we're in trouble. The
128 protocols must be written to ensure that this can't happen. */
130 ulog (LOG_FATAL, "freceive_data: No room in buffer");
133 /* If we don't have room for all the data the caller wants, we
134 simply have to expect less. We'll get the rest later. */
138 if (! fconn_read (qconn, abPrecbuf + iPrecend, pcrec, cneed, ctimeout,
142 iPrecend = (iPrecend + *pcrec) % CRECBUFLEN;
147 /* Read a single character. Get it out of the receive buffer if it's
148 there, otherwise ask freceive_data for at least one character.
149 This is used because as a protocol is shutting down freceive_data
150 may read ahead and eat characters that should be read outside the
151 protocol routines. We call freceive_data rather than fconn_read
152 with an argument of 1 so that we can get all the available data in
153 a single system call. The ctimeout argument is the timeout in
154 seconds; the freport argument is FALSE if no error should be
155 reported. This returns a character, or -1 on timeout or -2 on
159 breceive_char (qconn, ctimeout, freport)
160 struct sconnection *qconn;
166 if (iPrecstart == iPrecend)
170 if (! freceive_data (qconn, sizeof (char), &crec, ctimeout, freport))
176 b = abPrecbuf[iPrecstart];
177 iPrecstart = (iPrecstart + 1) % CRECBUFLEN;
181 /* Send mail about a file transfer. We send to the given mailing
182 address if there is one, otherwise to the user. */
185 fmail_transfer (fsuccess, zuser, zmail, zwhy, zfromfile, zfromsys,
186 ztofile, ztosys, zsaved)
191 const char *zfromfile;
192 const char *zfromsys;
201 if (zmail != NULL && *zmail != '\0')
207 az[i++] = "The file\n\t";
208 if (zfromsys != NULL)
215 az[i++] = "\nwas successfully transferred to\n\t";
217 az[i++] = "\ncould not be transferred to\n\t";
224 az[i++] = "\nas requested by\n\t";
228 az[i++] = "\nfor the following reason:\n\t";
238 return fsysdep_mail (zsendto,
239 fsuccess ? "UUCP succeeded" : "UUCP failed",