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