home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / uucp / uucico / trans.h < prev    next >
C/C++ Source or Header  |  1995-08-20  |  11KB  |  289 lines

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