1 /* trans.h 2 Header file for file and command transfer routines. 3 4 Copyright (C) 1992, 1993, 1994, 2002 Ian Lance Taylor 5 6 This file is part of the Taylor UUCP package. 7 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. 12 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. 17 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. 21 22 The author of the program may be contacted at ian@airs.com. 23 */ 24 25 /* The maximum possible number of channels. */ 26 #define IMAX_CHAN (16) 27 28 /* The ifeatures field of the sdaemon structure is an or of the 29 following values. These values are sent during the uucico 30 handshake, and MUST NOT CHANGE. */ 31 32 /* File size negotiation. */ 33 #define FEATURE_SIZES (01) 34 35 /* File transfer restart. */ 36 #define FEATURE_RESTART (02) 37 38 /* The E (execute) command. */ 39 #define FEATURE_EXEC (04) 40 41 /* Version 1.03: requires decimal size in S and R command. Needless 42 to say, this should not be used by any new programs. */ 43 #define FEATURE_V103 (010) 44 45 /* SVR4 UUCP: expects dummy string between notify field and size field 46 in send command. There is probably some meaning to this string, 47 but I don't know what it is. If I ever find out, this flag will 48 still be used to indicate it. */ 49 #define FEATURE_SVR4 (020) 50 51 /* Supports the 'q' option in UUCP protocol commands. When the 'q' 52 option appears in a command, it means that the string fields are 53 backslash quoted. */ 54 #define FEATURE_QUOTES (040) 55 56 /* This structure is used to hold information concerning the 57 communication link established with the remote system. */ 58 59 struct sdaemon 60 { 61 /* Global uuconf pointer. */ 62 pointer puuconf; 63 /* Configuration file name argument (from -I option). */ 64 const char *zconfig; 65 /* How often to spawn uuxqt (from uuconf_runuuxqt). */ 66 int irunuuxqt; 67 /* Remote system information. */ 68 const struct uuconf_system *qsys; 69 /* Local name being used. */ 70 const char *zlocalname; 71 /* Connection structure. */ 72 struct sconnection *qconn; 73 /* Protocol being used. */ 74 const struct sprotocol *qproto; 75 /* Number of channels being used. */ 76 int cchans; 77 /* The largest file size permitted for a local request. */ 78 long clocal_size; 79 /* The largest file size permitted for a remote request. */ 80 long cremote_size; 81 /* The largest file size that may ever be transferred. */ 82 long cmax_ever; 83 /* The remote system ulimit. */ 84 long cmax_receive; 85 /* Number of bytes sent. */ 86 long csent; 87 /* Number of bytes received. */ 88 long creceived; 89 /* Number of execution files received since the last time we spawned 90 uuxqt. */ 91 long cxfiles_received; 92 /* Features supported by the remote side. */ 93 int ifeatures; 94 /* TRUE if we should request the remote side to hang up. */ 95 boolean frequest_hangup; 96 /* TRUE if the remote side requested a hangup. */ 97 boolean fhangup_requested; 98 /* TRUE if we are hanging up. */ 99 boolean fhangup; 100 /* TRUE if the local system is currently the master. */ 101 boolean fmaster; 102 /* TRUE if the local system placed the call. */ 103 boolean fcaller; 104 /* UUCONF_RELIABLE_* flags for the connection. */ 105 int ireliable; 106 /* If fcaller is FALSE, the lowest grade which may be transferred 107 during this call. */ 108 char bgrade; 109 }; 110 111 /* This structure is used to hold a file or command transfer which is 112 in progress. */ 113 114 struct stransfer 115 { 116 /* Next file transfer in queue. */ 117 struct stransfer *qnext; 118 /* Previous file transfer in queue. */ 119 struct stransfer *qprev; 120 /* Points to the queue this structure is on. */ 121 struct stransfer **pqqueue; 122 /* The function to call to send some data. */ 123 boolean (*psendfn) P((struct stransfer *qtrans, struct sdaemon *qdaemon)); 124 /* The function to call when data is received. */ 125 boolean (*precfn) P((struct stransfer *qtrans, struct sdaemon *qdaemon, 126 const char *zdata, size_t cdata)); 127 /* Type specific information. */ 128 pointer pinfo; 129 /* TRUE if we are sending the file e (this is used to avoid a call 130 to psendfn). */ 131 boolean fsendfile; 132 /* TRUE if we are receiving the file e (this is used to avoid a call 133 to precfn). */ 134 boolean frecfile; 135 /* The file to read or write. */ 136 openfile_t e; 137 /* The position we are at in the file. */ 138 long ipos; 139 /* TRUE if we are waiting for a command string. */ 140 boolean fcmd; 141 /* The command string we have so far. */ 142 char *zcmd; 143 /* The length of the command string we have so far. */ 144 size_t ccmd; 145 /* Local destination number. */ 146 int ilocal; 147 /* Remote destination number. */ 148 int iremote; 149 /* The command. */ 150 struct scmd s; 151 /* A message to log when work starts. */ 152 char *zlog; 153 /* The process time; imicros can be negative. */ 154 long isecs; 155 long imicros; 156 /* Number of bytes sent or received. */ 157 long cbytes; 158 }; 159 160 /* Reasons that a file transfer might fail. */ 161 162 enum tfailure 163 { 164 /* No failure. */ 165 FAILURE_NONE, 166 /* No permission for operation. */ 167 FAILURE_PERM, 168 /* Can't open necessary file. */ 169 FAILURE_OPEN, 170 /* Not enough space to receive file. */ 171 FAILURE_SIZE, 172 /* File was received in a previous conversation. */ 173 FAILURE_RECEIVED 174 }; 175 176 /* The main loop which talks to the remote system, passing transfer 177 requests and file back and forth. */ 178 extern boolean floop P((struct sdaemon *qdaemon)); 179 180 /* Allocate a new transfer structure. */ 181 extern struct stransfer *qtransalc P((struct scmd *qcmd)); 182 183 /* Free a transfer structure. */ 184 extern void utransfree P((struct stransfer *qtrans)); 185 186 /* Queue up local requests. If pfany is not NULL, this sets *pfany to 187 TRUE if there are, in fact, any local requests which can be done at 188 this point. */ 189 extern boolean fqueue P((struct sdaemon *qdaemon, boolean *pfany)); 190 191 /* Clear away any queued requests. This may be called more than once 192 at the end of a call. */ 193 extern void uclear_queue P((struct sdaemon *qdaemon)); 194 195 /* Queue a new transfer request made by the local system. */ 196 extern boolean fqueue_local P((struct sdaemon *qdaemon, 197 struct stransfer *qtrans)); 198 199 /* Queue a new transfer request made by the remote system. */ 200 extern boolean fqueue_remote P((struct sdaemon *qdaemon, 201 struct stransfer *qtrans)); 202 203 /* Queue a transfer request which wants to send something. */ 204 extern boolean fqueue_send P((struct sdaemon *qdaemon, 205 struct stransfer *qtrans)); 206 207 /* Queue a transfer request which wants to receiving something. */ 208 extern boolean fqueue_receive P((struct sdaemon *qdaemon, 209 struct stransfer *qtrans)); 210 211 /* Prepare to send a file by local or remote request. */ 212 extern boolean flocal_send_file_init P((struct sdaemon *qdaemon, 213 struct scmd *qcmd)); 214 extern boolean fremote_send_file_init P((struct sdaemon *qdaemon, 215 struct scmd *qcmd, 216 int iremote)); 217 218 /* Prepare to receive a file by local or remote request. */ 219 extern boolean flocal_rec_file_init P((struct sdaemon *qdaemon, 220 struct scmd *qcmd)); 221 extern boolean fremote_rec_file_init P((struct sdaemon *qdaemon, 222 struct scmd *qcmd, 223 int iremote)); 224 225 /* Prepare to request work by local or remote request. */ 226 extern boolean flocal_xcmd_init P((struct sdaemon *qdaemon, 227 struct scmd *qcmd)); 228 extern boolean fremote_xcmd_init P((struct sdaemon *qdaemon, 229 struct scmd *qcmd, 230 int iremote)); 231 232 /* We have lost the connection; record any in progress file transfers 233 in the statistics file and discard any temporary files. */ 234 extern void ufailed P((struct sdaemon *qdaemon)); 235 236 /* Check that there is enough disk space for a file receive. Return 237 FALSE if there is not. */ 238 extern boolean frec_check_free P((struct stransfer *qtrans, 239 long cfree_space)); 240 241 /* Discard the temporary file being used to receive a file, if 242 appropriate. */ 243 extern boolean frec_discard_temp P((struct sdaemon *qdaemon, 244 struct stransfer *qtrans)); 245 246 /* Handle data received by a protocol. This is called by the protocol 247 specific routines as data comes in. The data is passed as two 248 buffers because that is convenient for packet based protocols, but 249 normally csecond will be 0. The ilocal argument is the local 250 channel number, and the iremote argument is the remote channel 251 number. Either may be -1, if the protocol does not have channels. 252 The ipos argument is the position in the file, if the protocol 253 knows it; for most protocols, this will be -1. The fallacked 254 argument should be set to TRUE if the remote has acknowledged all 255 outstanding data; see uwindow_acked, below, for details. This will 256 set *pfexit to TRUE if there is something for the main loop to do. 257 A file is complete is when a zero length buffer is passed (cfirst 258 == 0). A command is complete when data containing a null byte is 259 passed. This will return FALSE on error. If the protocol pfwait 260 entry point should exit and let the top level loop continue, 261 *pfexit will be set to TRUE (if pfexit is not NULL). This will not 262 set *pfexit to FALSE, so the caller must do that. */ 263 extern boolean fgot_data P((struct sdaemon *qdaemon, 264 const char *zfirst, size_t cfirst, 265 const char *zsecond, size_t csecond, 266 int ilocal, int iremote, 267 long ipos, boolean fallacked, 268 boolean *pfexit)); 269 270 /* This routine is called when an ack is sent for a file receive. */ 271 extern void usent_receive_ack P((struct sdaemon *qdaemon, 272 struct stransfer *qtrans)); 273 274 /* A protocol may call this routine to indicate the packets have been 275 acknowledged by the remote system. If the fallacked argument is 276 TRUE, then all outstanding packets have been acknowledged; for 277 convenience, this may also be indicated by passing fallacked as 278 TRUE to fgot_data, above. Otherwise this routine should be called 279 each time a complete window is acked by the remote system. The 280 transfer code uses this information to keep track of when an 281 acknowledgement of a file receive has been seen by the other side, 282 so that file receives may be handled cleanly if the connection is 283 lost. */ 284 extern void uwindow_acked P((struct sdaemon *qdaemon, 285 boolean fallacked)); 286 287 /* Spawn a uuxqt process. The ffork argument is passed to 288 fsysdep_run. If the zsys argument is not NULL, then -s zsys is 289 passed to uuxqt. The zconfig argument is the name of the 290 configuration file, from the -I option. */ 291 extern boolean fspawn_uuxqt P((boolean ffork, const char *zsys, 292 const char *zconfig)); 293