Copyright (C) 1991, 1992 Ian Lance Taylor
This file is part of the Taylor UUCP package.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
The author of the program may be contacted at ian@airs.com or
c/o Infinity Development Systems, P.O. Box 520, Waltham, MA 02254.
const char prott_rcsid
[] = "$Id: prott.c,v 1.1 1993/08/04 19:36:24 jtc Exp $";
/* This implementation is based on code written by Rick Adams.
This code implements the 't' protocol, which does no error checking
whatsoever and thus requires an end-to-end verified eight bit
communication line, such as is provided by TCP. Using it with a
modem is unadvisable, since errors can occur between the modem and
/* The buffer size we use. */
/* The offset in the buffer to the data. */
/* Commands are sent in multiples of this size. */
/* A pointer to the buffer we will use. */
/* True if we are receiving a file. */
/* The timeout we use. */
static int cTtimeout
= 120;
struct uuconf_cmdtab asTproto_params
[] =
{ "timeout", UUCONF_CMDTABTYPE_INT
, (pointer
) &cTtimeout
, NULL
},
static boolean ftprocess_data
P((struct sdaemon
*qdaemon
, boolean
*pfexit
,
/* Start the protocol. */
if (! fconn_set (qdaemon
->qconn
, PARITYSETTING_NONE
,
STRIPSETTING_EIGHTBITS
, XONXOFF_OFF
))
zTbuf
= (char *) xmalloc (CTBUFSIZE
+ CTFRAMELEN
);
/* The first two bytes of the buffer are always zero. */
/* Send a command string. We send everything up to and including the
null byte. The number of bytes we send must be a multiple of
ftsendcmd (qdaemon
, z
, ilocal
, iremote
)
DEBUG_MESSAGE1 (DEBUG_UUCP_PROTO
, "ftsendcmd: Sending command \"%s\"", z
);
/* We need to send the smallest multiple of CTPACKSIZE which is
greater than clen (not equal to clen, since we need room for the
csend
= ((clen
/ CTPACKSIZE
) + 1) * CTPACKSIZE
;
bzero (zalc
+ clen
, csend
- clen
);
fret
= fsend_data (qdaemon
->qconn
, zalc
, csend
, TRUE
);
/* Get space to be filled with data. We provide a buffer which has
four bytes at the start available to hold the length. */
ztgetspace (qdaemon
, pclen
)
return zTbuf
+ CTFRAMELEN
;
/* Send out some data. We are allowed to modify the four bytes
preceding the buffer. This allows us to send the entire block with
header bytes in a single call. */
ftsenddata (qdaemon
, zdata
, cdata
, ilocal
, iremote
, ipos
)
/* Here we do htonl by hand, since it doesn't exist everywhere. We
know that the amount of data cannot be greater than CTBUFSIZE, so
the first two bytes of this value will always be 0. They were
set to 0 in ftstart so we don't touch them here. This is useful
because we cannot portably right shift by 24 or 16, since we
might be dealing with sixteen bit integers. */
zdata
[-2] = (char) ((cdata
>> 8) & 0xff);
zdata
[-1] = (char) (cdata
& 0xff);
/* We pass FALSE to fsend_data since we don't expect the other side
to be sending us anything just now. */
return fsend_data (qdaemon
->qconn
, zdata
- CTFRAMELEN
, cdata
+ CTFRAMELEN
,
/* Process data and return the amount we need in *pfneed. */
ftprocess_data (qdaemon
, pfexit
, pcneed
)
int cinbuf
, cfirst
, clen
;
cinbuf
= iPrecend
- iPrecstart
;
/* We are not receiving a file. Commands are read in chunks of
while (cinbuf
>= CTPACKSIZE
)
cfirst
= CRECBUFLEN
- iPrecstart
;
DEBUG_MESSAGE1 (DEBUG_PROTO
,
"ftprocess_data: Got %d command bytes",
if (! fgot_data (qdaemon
, abPrecbuf
+ iPrecstart
,
(size_t) cfirst
, abPrecbuf
,
(size_t) CTPACKSIZE
- cfirst
,
-1, -1, (long) -1, TRUE
, pfexit
))
iPrecstart
= (iPrecstart
+ CTPACKSIZE
) % CRECBUFLEN
;
*pcneed
= CTPACKSIZE
- cinbuf
;
/* Here we are receiving a file. The data comes in blocks. The
first four bytes contain the length, followed by that amount of
while (cinbuf
>= CTFRAMELEN
)
/* The length is stored in network byte order, MSB first. */
clen
= (((((((abPrecbuf
[iPrecstart
] & 0xff) << 8)
+ (abPrecbuf
[(iPrecstart
+ 1) % CRECBUFLEN
] & 0xff)) << 8)
+ (abPrecbuf
[(iPrecstart
+ 2) % CRECBUFLEN
] & 0xff)) << 8)
+ (abPrecbuf
[(iPrecstart
+ 3) % CRECBUFLEN
] & 0xff));
if (cinbuf
< clen
+ CTFRAMELEN
)
*pcneed
= clen
+ CTFRAMELEN
- cinbuf
;
iPrecstart
= (iPrecstart
+ CTFRAMELEN
) % CRECBUFLEN
;
cfirst
= CRECBUFLEN
- iPrecstart
;
DEBUG_MESSAGE1 (DEBUG_PROTO
,
"ftprocess_data: Got %d data bytes",
if (! fgot_data (qdaemon
, abPrecbuf
+ iPrecstart
,
(size_t) cfirst
, abPrecbuf
, (size_t) (clen
- cfirst
),
-1, -1, (long) -1, TRUE
, pfexit
))
iPrecstart
= (iPrecstart
+ clen
) % CRECBUFLEN
;
cinbuf
-= clen
+ CTFRAMELEN
;
*pcneed
= CTFRAMELEN
- cinbuf
;
/* Wait for data to come in and process it until we've reached the end
of a command or a file. */
if (! ftprocess_data (qdaemon
, &fexit
, &cneed
))
if (! freceive_data (qdaemon
->qconn
, cneed
, &crec
, cTtimeout
, TRUE
))
ulog (LOG_ERROR
, "Timed out waiting for data");
/* File level routine, to set fTfile correctly. */
ftfile (qdaemon
, qtrans
, fstart
, fsend
, cbytes
, pfhandled
)
struct stransfer
*qtrans
;