-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathftrans.h
335 lines (288 loc) · 11.1 KB
/
ftrans.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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
// LoraBBS Version 2.99 Free Edition
// Copyright (C) 1987-98 Marco Maccaferri
//
// 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.
#ifndef _FTRANS_H
#define _FTRANS_H
#include "combase.h"
#include "lora_api.h"
#define CAN ('X'&037)
#define XOFF ('s'&037)
#define XON ('q'&037)
#if !defined(OK)
#define OK 1
#endif
#define ZERROR (-1)
#define TIMEOUT (-2)
#define RCDO (-3)
#define LZCONV 0
#define LZMANAG 0
#define LZTRANS 0
#define KSIZE 8192
#define ZPAD '*' /* 052 Padding character begins frames */
#define ZDLE 030 /* Ctrl-X Zmodem escape - `ala BISYNC DLE */
#define ZDLEE (ZDLE^0100) /* Escaped ZDLE as transmitted */
#define ZBIN 'A' /* Binary frame indicator */
#define ZHEX 'B' /* HEX frame indicator */
#define ZBIN32 'C' /* Binary frame with 32 bit FCS */
/* Frame types (see array "frametypes" in zm.c) */
#define ZRQINIT 0 /* Request receive init */
#define ZRINIT 1 /* Receive init */
#define ZSINIT 2 /* Send init sequence (optional) */
#define ZACK 3 /* ACK to above */
#define ZFILE 4 /* File name from sender */
#define ZSKIP 5 /* To sender: skip this file */
#define ZNAK 6 /* Last packet was garbled */
#define ZABORT 7 /* Abort batch transfers */
#define ZFIN 8 /* Finish session */
#define ZRPOS 9 /* Resume data trans at this position */
#define ZDATA 10 /* Data packet(s) follow */
#define ZEOF 11 /* End of file */
#define ZFERR 12 /* Fatal Read or Write error Detected */
#define ZCRC 13 /* Request for file CRC and response */
#define ZCHALLENGE 14 /* Receiver's Challenge */
#define ZCOMPL 15 /* Request is complete */
#define ZCAN 16 /* Other end canned session with CAN*5 */
#define ZFREECNT 17 /* Request for free bytes on filesystem */
#define ZCOMMAND 18 /* Command from sending program */
#define ZSTDERR 19 /* Output to standard error, data follows */
/* ZDLE sequences */
#define ZCRCE 'h' /* CRC next, frame ends, header packet follows */
#define ZCRCG 'i' /* CRC next, frame continues nonstop */
#define ZCRCQ 'j' /* CRC next, frame continues, ZACK expected */
#define ZCRCW 'k' /* CRC next, ZACK expected, end of frame */
#define ZRUB0 'l' /* Translate to rubout 0177 */
#define ZRUB1 'm' /* Translate to rubout 0377 */
/* zdlread return values (internal) */
/* -1 is general error, -2 is timeout */
#define GOTOR 0400
#define GOTCRCE (ZCRCE|GOTOR) /* ZDLE-ZCRCE received */
#define GOTCRCG (ZCRCG|GOTOR) /* ZDLE-ZCRCG received */
#define GOTCRCQ (ZCRCQ|GOTOR) /* ZDLE-ZCRCQ received */
#define GOTCRCW (ZCRCW|GOTOR) /* ZDLE-ZCRCW received */
#define GOTCAN (GOTOR|030) /* CAN*5 seen */
/* Byte positions within header array */
#define ZF0 3 /* First flags byte */
#define ZF1 2
#define ZF2 1
#define ZF3 0
#define ZP0 0 /* Low order 8 bits of position */
#define ZP1 1
#define ZP2 2
#define ZP3 3 /* High order 8 bits of file position */
/* Bit Masks for ZRINIT flags byte ZF0 */
#define CANFDX 01 /* Rx can send and receive true FDX */
#define CANOVIO 02 /* Rx can receive data during disk I/O */
#define CANBRK 04 /* Rx can send a break signal */
#define CANCRY 010 /* Receiver can decrypt */
#define CANLZW 020 /* Receiver can uncompress */
#define CANFC32 040 /* Receiver can use 32 bit Frame Check */
/* Parameters for ZFILE frame */
/* Conversion options one of these in ZF0 */
#define ZCBIN 1 /* Binary transfer - inhibit conversion */
#define ZCNL 2 /* Convert NL to local end of line convention */
#define ZCRESUM 3 /* Resume interrupted file transfer */
/* Management options, one of these in ZF1 */
#define ZMNEW 1 /* Transfer if source newer or longer */
#define ZMCRC 2 /* Transfer if different file CRC or length */
#define ZMAPND 3 /* Append contents to existing file (if any) */
#define ZMCLOB 4 /* Replace existing file */
#define ZMSPARS 5 /* Encoding for sparse file */
#define ZMDIFF 6 /* Transfer if dates or lengths different */
#define ZMPROT 7 /* Protect destination file */
/* Transport options, one of these in ZF2 */
#define ZTLZW 1 /* Lempel-Ziv compression */
#define ZTCRYPT 2 /* Encryption */
#define ZTRLE 3 /* Run Length encoding */
/* Parameters for ZCOMMAND frame ZF0 (otherwise 0) */
#define ZCACK1 1 /* Acknowledge, then do command */
/* Parameters for ZSINIT frame */
#define ZATTNLEN 32 /* Max length of attention string */
class DLL_EXPORT TZModem
{
public:
TZModem ();
~TZModem ();
USHORT EndRun, Hangup;
USHORT FileSent, Maxblklen, Telnet;
CHAR Pathname[128];
ULONG Speed;
class TCom *Com;
class TLog *Log;
class TProgress *Progress;
USHORT AbortSession ();
SHORT TimedRead (LONG hSec);
SHORT ZInitReceiver ();
SHORT ZInitSender (SHORT NothingToDo);
SHORT ZReceiveFile (PSZ pszPath);
SHORT ZSendFile (PSZ pszFile, PSZ pszName = NULL);
VOID ZEndSender ();
private:
SHORT Wantfcs32, Txfcs32, Znulls, lastsent, ZCtlesc;
SHORT Rxframeind, Rxtype, Rxflags, Rxbuflen, Rxcount;
SHORT Tframlen, TryZHdrType, RxTempSize;
CHAR Txhdr[4], Rxhdr[4], Attn[ZATTNLEN];
CHAR RxBuffer[KSIZE], *TxBuffer;
CHAR RxTemp[256], *RxTempPos;
LONG Rxtimeout, Rxpos, Txpos, Rxbytes;
VOID ZAckBiBi ();
SHORT ZDLRead ();
SHORT ZGetByte ();
SHORT ZGetHeader (CHAR *hdr);
SHORT ZGetHex ();
LONG ZGetLong (char *hdr);
VOID ZPutHex (SHORT c);
VOID ZPutLong (CHAR *hdr, LONG pos);
SHORT ZReceiveBinaryHeader (CHAR *hdr);
SHORT ZReceiveBinaryHeader32 (CHAR *hdr);
SHORT ZReceiveData (char *buf, short length);
SHORT ZReceiveHexHeader (CHAR *hdr);
VOID ZSendBinaryHeader (SHORT type, CHAR *hdr);
VOID ZSendData (CHAR *buf, SHORT length, SHORT frameend);
VOID ZSendHexHeader (SHORT type, CHAR *hdr);
VOID ZSendLine (UCHAR c);
};
// ----------------------------------------------------------------------
class TFileQueue
{
public:
TFileQueue ();
~TFileQueue ();
USHORT Sent;
CHAR Name[32], Complete[128];
ULONG Size;
UCHAR DeleteAfter;
UCHAR TruncateAfter;
ULONG TotalFiles;
USHORT Add ();
VOID Clear ();
USHORT First ();
VOID New ();
USHORT Next ();
USHORT Previous ();
VOID Remove (PSZ pszName = NULL);
VOID Update ();
private:
class TCollection Data;
};
// ----------------------------------------------------------------------
class DLL_EXPORT TTransfer : public TZModem
{
public:
TTransfer ();
~TTransfer ();
USHORT Task;
CHAR Device[16];
class TFileQueue RxQueue;
class TFileQueue TxQueue;
PSZ ReceiveXModem (PSZ pszPath);
PSZ ReceiveASCIIDump (PSZ pszPath);
PSZ ReceiveFTPHost (PSZ pszFile);
PSZ Receive1kXModem (PSZ pszPath);
PSZ ReceiveYModem (PSZ pszPath);
PSZ ReceiveYModemG (PSZ pszPath);
PSZ ReceiveZModem (PSZ pszPath);
VOID RunExternalProtocol (USHORT Download, PSZ Cmd, class TProtocol *Protocol);
VOID Janus (PSZ pszPath);
USHORT Send1kXModem (PSZ pszFile);
USHORT SendASCIIDump (PSZ pszFile);
USHORT SendFTPHost (PSZ pszFile);
USHORT SendXModem (PSZ pszFile);
USHORT SendYModem (PSZ pszFile);
USHORT SendYModemG (PSZ pszFile);
USHORT SendZModem (PSZ pszFile, PSZ pszName = NULL);
USHORT SendZModem8K (PSZ pszFile, PSZ pszName = NULL);
private:
USHORT PktSize;
UCHAR Soh;
USHORT DoCrc;
USHORT UseAck;
UCHAR PktNumber;
CHAR FinalName[128];
USHORT ReceivePacket (UCHAR *lpBuffer);
PSZ ReceiveXFile (PSZ pszPath);
SHORT SendPacket (UCHAR *lpBuffer);
USHORT SendXFile (PSZ pszFile);
};
// ----------------------------------------------------------------------
/* Misc. Constants */
#define BUFMAX 2048 /* Max packet contents length */
#define JANUS_EFFICIENCY 95 /* Estimate Janus xfers at 95% throughput */
class TJanus
{
public:
TJanus ();
~TJanus ();
USHORT TimeoutSecs;
USHORT MakeRequests;
USHORT AllowRequests;
CHAR RxPath[64];
ULONG Speed;
class TCom *Com;
class TLog *Log;
class TFileQueue *TxQueue;
class TFileQueue *RxQueue;
class TOutbound *Outbound;
VOID Transfer ();
private:
int RxFile, TxFile;
USHORT Rxblklen, IsOutbound;
SHORT CanCrc32, WaitFlag, RxCrc32, RxTempSize;
CHAR RxFileName[128], TxFileName[128];
CHAR RxTemp[256], *RxTempPos;
UCHAR LastSent, *Rxbufptr, *Rxbufmax;
UCHAR RxBuffer[BUFMAX + 8], TxBuffer[BUFMAX + 8];
ULONG RxPktCrc32;
USHORT RxPktCrc16;
ULONG LastPktName;
LONG Rxpos, RxFilesize, RxFiletime;
UCHAR pkttype, SharedCap, Done;
USHORT xstate, rstate, rpos_count;
USHORT blklen, txblklen, txblkmax;
LONG rxstpos, length, xmit_retry, txpos, txstpos, timeout;
LONG txlength, lasttx, last_blkpos, rpos_retry, rpos_sttime;
struct utimbuf utimes;
#if defined(__NT__)
HANDLE hBlock;
#elif defined(__OS2__)
#endif
friend VOID SendThread (PVOID Args);
SHORT GetByte ();
VOID GetNextFile ();
UCHAR GetPacket ();
SHORT GetRawByte ();
LONG ProcessFileName ();
VOID SendByte (UCHAR Byte);
VOID SendPacket (UCHAR *Buffer, USHORT Len, USHORT Type);
};
// ----------------------------------------------------------------------
#define FILE_RECEIVING 1
#define FILE_SENDING 2
#define FILE_BIDIRECTIONAL 3
class DLL_EXPORT TProgress
{
public:
TProgress ();
virtual ~TProgress ();
USHORT Type;
USHORT RxBlockSize, TxBlockSize;
CHAR RxFileName[128], TxFileName[128];
ULONG RxSize, RxPosition;
ULONG TxSize, TxPosition;
virtual VOID Begin ();
virtual VOID End ();
virtual VOID Update ();
};
#endif