1 /* prot.h
2    Protocol header file.
3 
4    Copyright (C) 1991, 1992, 1993, 1994, 1995 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 /* We need the definition of uuconf_cmdtab to declare the protocol
26    parameter arrays.  */
27 #ifndef UUCONF_H
28 #include "uuconf.h"
29 #endif
30 
31 #if ANSI_C
32 /* These structures are used in prototypes but are not defined in this
33    header file.  */
34 struct sdaemon;
35 struct sconnection;
36 struct stransfer;
37 #endif
38 
39 /* The sprotocol structure holds information and functions for a specific
40    protocol (e.g. the 'g' protocol).  */
41 
42 struct sprotocol
43 {
44   /* The name of the protocol (e.g. 'g').  */
45   char bname;
46   /* Reliability requirements, an or of UUCONF_RELIABLE_xxx defines
47      from uuconf.h.  */
48   int ireliable;
49   /* The maximum number of channels this protocol can support.  */
50   int cchans;
51   /* Whether files may be reliably restarted using this protocol.  */
52   boolean frestart;
53   /* Protocol parameter commands.  */
54   struct uuconf_cmdtab *qcmds;
55   /* A routine to start the protocol.  If *pzlog is set to be
56      non-NULL, it is an informative message to be logged; it should
57      then be passed to ubuffree.  */
58   boolean (*pfstart) P((struct sdaemon *qdaemon, char **pzlog));
59   /* Shutdown the protocol.  */
60   boolean (*pfshutdown) P((struct sdaemon *qdaemon));
61   /* Send a command to the other side.  */
62   boolean (*pfsendcmd) P((struct sdaemon *qdaemon, const char *z,
63 			  int ilocal, int iremote));
64   /* Get buffer to space to fill with data.  This should set *pcdata
65      to the amount of data desired.  */
66   char *(*pzgetspace) P((struct sdaemon *qdaemon, size_t *pcdata));
67   /* Send data to the other side.  The argument z must be a return
68      value of pzgetspace.  The ipos argument is the file position, and
69      is ignored by most protocols.  */
70   boolean (*pfsenddata) P((struct sdaemon *qdaemon, char *z, size_t c,
71 			   int ilocal, int iremote, long ipos));
72   /* Wait for data to come in and call fgot_data with it until
73      fgot_data sets *pfexit.  */
74   boolean (*pfwait) P((struct sdaemon *qdaemon));
75   /* Handle any file level actions that need to be taken.  If a file
76      transfer is starting rather than ending, fstart is TRUE.  If the
77      file is being sent rather than received, fsend is TRUE.  If
78      fstart and fsend are both TRUE, cbytes holds the size of the
79      file.  If *pfhandled is set to TRUE, then the protocol routine
80      has taken care of queueing up qtrans for the next action.  */
81   boolean (*pffile) P((struct sdaemon *qdaemon, struct stransfer *qtrans,
82 		       boolean fstart, boolean fsend, long cbytes,
83 		       boolean *pfhandled));
84 };
85 
86 /* Send data to the other system.  If the fread argument is TRUE, this
87    will also receive data into the receive buffer abPrecbuf; fread is
88    passed as TRUE if the protocol expects data to be coming back, to
89    make sure the input buffer does not fill up.  Returns FALSE on
90    error.  */
91 extern boolean fsend_data P((struct sconnection *qconn,
92 			     const char *zsend, size_t csend,
93 			     boolean fdoread));
94 
95 /* Receive data from the other system when there is no data to send.
96    The cneed argument is the amount of data desired and the ctimeout
97    argument is the timeout in seconds.  This will set *pcrec to the
98    amount of data received.  It will return FALSE on error.  If a
99    timeout occurs, it will return TRUE with *pcrec set to zero.  */
100 extern boolean freceive_data P((struct sconnection *qconn, size_t cneed,
101 				size_t *pcrec, int ctimeout,
102 				boolean freport));
103 
104 /* Get one character from the remote system, going through the
105    procotol buffering.  The ctimeout argument is the timeout in
106    seconds, and the freport argument is TRUE if errors should be
107    reported (when closing a connection it is pointless to report
108    errors).  This returns a character or -1 on a timeout or -2 on an
109    error.  */
110 extern int breceive_char P((struct sconnection *qconn,
111 			    int ctimeout, boolean freport));
112 
113 /* Compute a 32 bit CRC of a data buffer, given an initial CRC.  */
114 extern unsigned long icrc P((const char *z, size_t c, unsigned long ick));
115 
116 /* The initial CRC value to use for a new buffer.  */
117 #if ANSI_C
118 #define ICRCINIT (0xffffffffUL)
119 #else
120 #define ICRCINIT ((unsigned long) 0xffffffffL)
121 #endif
122 
123 /* The size of the receive buffer.  */
124 #define CRECBUFLEN (16384)
125 
126 /* Buffer to hold received data.  */
127 extern char abPrecbuf[CRECBUFLEN];
128 
129 /* Index of start of data in abPrecbuf.  */
130 extern int iPrecstart;
131 
132 /* Index of end of data (first byte not included in data) in abPrecbuf.  */
133 extern int iPrecend;
134 
135 /* There are a couple of variables and functions that are shared by
136    the 'i' and 'j' protocols (the 'j' protocol is just a wrapper
137    around the 'i' protocol).  These belong in a separate header file,
138    protij.h, but I don't want to create one for just a couple of
139    things.  */
140 
141 /* An escape sequence of characters for the 'j' protocol to avoid
142    (protocol parameter ``avoid'').  */
143 extern const char *zJavoid_parameter;
144 
145 /* Timeout to use when sending the 'i' protocol SYNC packet (protocol
146    parameter ``sync-timeout'').  */
147 extern int cIsync_timeout;
148 
149 /* Shared startup routine for the 'i' and 'j' protocols.  */
150 extern boolean fijstart P((struct sdaemon *qdaemon, char **pzlog,
151 			   int imaxpacksize,
152 			   boolean (*pfsend) P((struct sconnection *qconn,
153 						const char *zsend,
154 						size_t csend,
155 						boolean fdoread)),
156 			   boolean (*pfreceive) P((struct sconnection *qconn,
157 						   size_t cneed,
158 						   size_t *pcrec,
159 						   int ctimeout,
160 						   boolean freport))));
161 
162 /* Prototypes for 'g' protocol functions.  */
163 
164 extern struct uuconf_cmdtab asGproto_params[];
165 extern boolean fgstart P((struct sdaemon *qdaemon, char **pzlog));
166 extern boolean fbiggstart P((struct sdaemon *qdaemon, char **pzlog));
167 extern boolean fvstart P((struct sdaemon *qdaemon, char **pzlog));
168 extern boolean fgshutdown P((struct sdaemon *qdaemon));
169 extern boolean fgsendcmd P((struct sdaemon *qdaemon, const char *z,
170 			    int ilocal, int iremote));
171 extern char *zggetspace P((struct sdaemon *qdaemon, size_t *pcdata));
172 extern boolean fgsenddata P((struct sdaemon *qdaemon, char *z, size_t c,
173 			     int ilocal, int iremote, long ipos));
174 extern boolean fgwait P((struct sdaemon *qdaemon));
175 
176 /* Prototypes for 'f' protocol functions.  */
177 
178 extern struct uuconf_cmdtab asFproto_params[];
179 extern boolean ffstart P((struct sdaemon *qdaemon, char **pzlog));
180 extern boolean ffshutdown P((struct sdaemon *qdaemon));
181 extern boolean ffsendcmd P((struct sdaemon *qdaemon, const char *z,
182 			    int ilocal, int iremote));
183 extern char *zfgetspace P((struct sdaemon *qdaemon, size_t *pcdata));
184 extern boolean ffsenddata P((struct sdaemon *qdaemon, char *z, size_t c,
185 			     int ilocal, int iremote, long ipos));
186 extern boolean ffwait P((struct sdaemon *qdaemon));
187 extern boolean fffile P((struct sdaemon *qdaemon, struct stransfer *qtrans,
188 			 boolean fstart, boolean fsend, long cbytes,
189 			 boolean *pfhandled));
190 
191 /* Prototypes for 't' protocol functions.  */
192 
193 extern struct uuconf_cmdtab asTproto_params[];
194 extern boolean ftstart P((struct sdaemon *qdaemon, char **pzlog));
195 extern boolean ftshutdown P((struct sdaemon *qdaemon));
196 extern boolean ftsendcmd P((struct sdaemon *qdaemon, const char *z,
197 			    int ilocal, int iremote));
198 extern char *ztgetspace P((struct sdaemon *qdaemon, size_t *pcdata));
199 extern boolean ftsenddata P((struct sdaemon *qdaemon, char *z, size_t c,
200 			     int ilocal, int iremote, long ipos));
201 extern boolean ftwait P((struct sdaemon *qdaemon));
202 extern boolean ftfile P((struct sdaemon *qdaemon, struct stransfer *qtrans,
203 			 boolean fstart, boolean fsend, long cbytes,
204 			 boolean *pfhandled));
205 
206 /* Prototypes for 'e' protocol functions.  */
207 
208 extern struct uuconf_cmdtab asEproto_params[];
209 extern boolean festart P((struct sdaemon *qdaemon, char **pzlog));
210 extern boolean feshutdown P((struct sdaemon *qdaemon));
211 extern boolean fesendcmd P((struct sdaemon *qdaemon, const char *z,
212 			    int ilocal, int iremote));
213 extern char *zegetspace P((struct sdaemon *qdaemon, size_t *pcdata));
214 extern boolean fesenddata P((struct sdaemon *qdaemon, char *z, size_t c,
215 			     int ilocal, int iremote, long ipos));
216 extern boolean fewait P((struct sdaemon *qdaemon));
217 extern boolean fefile P((struct sdaemon *qdaemon, struct stransfer *qtrans,
218 			 boolean fstart, boolean fsend, long cbytes,
219 			 boolean *pfhandled));
220 
221 /* Prototypes for 'i' protocol functions.  */
222 
223 extern struct uuconf_cmdtab asIproto_params[];
224 extern boolean fistart P((struct sdaemon *qdaemon, char **pzlog));
225 extern boolean fishutdown P((struct sdaemon *qdaemon));
226 extern boolean fisendcmd P((struct sdaemon *qdaemon, const char *z,
227 			    int ilocal, int iremote));
228 extern char *zigetspace P((struct sdaemon *qdaemon, size_t *pcdata));
229 extern boolean fisenddata P((struct sdaemon *qdaemon, char *z, size_t c,
230 			     int ilocal, int iremote, long ipos));
231 extern boolean fiwait P((struct sdaemon *qdaemon));
232 
233 /* Prototypes for 'j' protocol functions.  The 'j' protocol mostly
234    uses the 'i' protocol functions, but it has a couple of functions
235    of its own.  */
236 
237 extern boolean fjstart P((struct sdaemon *qdaemon, char **pzlog));
238 extern boolean fjshutdown P((struct sdaemon *qdaemon));
239 
240 /* Prototypes for 'a' protocol functions (these use 'z' as the second
241    character because 'a' is a modified Zmodem protocol).  */
242 
243 extern struct uuconf_cmdtab asZproto_params[];
244 extern boolean fzstart P((struct sdaemon *qdaemon, char **pzlog));
245 extern boolean fzshutdown P((struct sdaemon *qdaemon));
246 extern boolean fzsendcmd P((struct sdaemon *qdaemon, const char *z,
247 			    int ilocal, int iremote));
248 extern char *zzgetspace P((struct sdaemon *qdaemon, size_t *pcdata));
249 extern boolean fzsenddata P((struct sdaemon *qdaemon, char *z, size_t c,
250 			     int ilocal, int iremote, long ipos));
251 extern boolean fzwait P((struct sdaemon *qdaemon));
252 extern boolean fzfile P((struct sdaemon *qdaemon, struct stransfer *qtrans,
253 			 boolean fstart, boolean fsend, long cbytes,
254 			 boolean *pfhandled));
255 
256 /* Prototypes for 'y' protocol functions.  */
257 
258 extern struct uuconf_cmdtab asYproto_params[];
259 extern boolean fystart P((struct sdaemon *qdaemon, char **pzlog));
260 extern boolean fyshutdown P((struct sdaemon *qdaemon));
261 extern boolean fysendcmd P((struct sdaemon *qdaemon, const char *z,
262 			    int ilocal, int iremote));
263 extern char *zygetspace P((struct sdaemon *qdaemon, size_t *pcdata));
264 extern boolean fysenddata P((struct sdaemon *qdaemon, char *z, size_t c,
265 			     int ilocal, int iremote, long ipos));
266 extern boolean fywait P((struct sdaemon *qdaemon));
267 extern boolean fyfile P((struct sdaemon *qdaemon, struct stransfer *qtrans,
268 			 boolean fstart, boolean fsend, long cbytes,
269 			 boolean *pfhandled));
270