home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / lora299s.zip / FTRANS.H < prev    next >
C/C++ Source or Header  |  1998-05-12  |  11KB  |  336 lines

  1.  
  2. // LoraBBS Version 2.99 Free Edition
  3. // Copyright (C) 1987-98 Marco Maccaferri
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. #ifndef _FTRANS_H
  20. #define _FTRANS_H
  21.  
  22. #include "combase.h"
  23. #include "lora_api.h"
  24.  
  25. #define CAN          ('X'&037)
  26. #define XOFF         ('s'&037)
  27. #define XON          ('q'&037)
  28. #if !defined(OK)
  29. #define OK           1
  30. #endif
  31. #define ZERROR       (-1)
  32. #define TIMEOUT      (-2)
  33. #define RCDO         (-3)
  34. #define LZCONV       0
  35. #define LZMANAG      0
  36. #define LZTRANS      0
  37. #define KSIZE        8192
  38.  
  39. #define ZPAD         '*'            /* 052 Padding character begins frames */
  40. #define ZDLE         030            /* Ctrl-X Zmodem escape - `ala BISYNC DLE */
  41. #define ZDLEE        (ZDLE^0100)    /* Escaped ZDLE as transmitted */
  42. #define ZBIN         'A'            /* Binary frame indicator */
  43. #define ZHEX         'B'            /* HEX frame indicator */
  44. #define ZBIN32       'C'            /* Binary frame with 32 bit FCS */
  45.  
  46. /* Frame types (see array "frametypes" in zm.c) */
  47. #define ZRQINIT      0              /* Request receive init */
  48. #define ZRINIT       1              /* Receive init */
  49. #define ZSINIT       2              /* Send init sequence (optional) */
  50. #define ZACK         3              /* ACK to above */
  51. #define ZFILE        4              /* File name from sender */
  52. #define ZSKIP        5              /* To sender: skip this file */
  53. #define ZNAK         6              /* Last packet was garbled */
  54. #define ZABORT       7              /* Abort batch transfers */
  55. #define ZFIN         8              /* Finish session */
  56. #define ZRPOS        9              /* Resume data trans at this position */
  57. #define ZDATA        10             /* Data packet(s) follow */
  58. #define ZEOF         11             /* End of file */
  59. #define ZFERR        12             /* Fatal Read or Write error Detected */
  60. #define ZCRC         13             /* Request for file CRC and response */
  61. #define ZCHALLENGE   14             /* Receiver's Challenge */
  62. #define ZCOMPL       15             /* Request is complete */
  63. #define ZCAN         16             /* Other end canned session with CAN*5 */
  64. #define ZFREECNT     17             /* Request for free bytes on filesystem */
  65. #define ZCOMMAND     18             /* Command from sending program */
  66. #define ZSTDERR      19             /* Output to standard error, data follows */
  67.  
  68. /* ZDLE sequences */
  69. #define ZCRCE        'h'            /* CRC next, frame ends, header packet follows */
  70. #define ZCRCG        'i'            /* CRC next, frame continues nonstop */
  71. #define ZCRCQ        'j'            /* CRC next, frame continues, ZACK expected */
  72. #define ZCRCW        'k'            /* CRC next, ZACK expected, end of frame */
  73. #define ZRUB0        'l'            /* Translate to rubout 0177 */
  74. #define ZRUB1        'm'            /* Translate to rubout 0377 */
  75.  
  76. /* zdlread return values (internal) */
  77. /* -1 is general error, -2 is timeout */
  78. #define GOTOR        0400
  79. #define GOTCRCE      (ZCRCE|GOTOR)  /* ZDLE-ZCRCE received */
  80. #define GOTCRCG      (ZCRCG|GOTOR)  /* ZDLE-ZCRCG received */
  81. #define GOTCRCQ      (ZCRCQ|GOTOR)  /* ZDLE-ZCRCQ received */
  82. #define GOTCRCW      (ZCRCW|GOTOR)  /* ZDLE-ZCRCW received */
  83. #define GOTCAN       (GOTOR|030)    /* CAN*5 seen */
  84.  
  85. /* Byte positions within header array */
  86. #define ZF0          3              /* First flags byte */
  87. #define ZF1          2
  88. #define ZF2          1
  89. #define ZF3          0
  90. #define ZP0          0              /* Low order 8 bits of position */
  91. #define ZP1          1
  92. #define ZP2          2
  93. #define ZP3          3              /* High order 8 bits of file position */
  94.  
  95. /* Bit Masks for ZRINIT flags byte ZF0 */
  96. #define CANFDX       01             /* Rx can send and receive true FDX */
  97. #define CANOVIO      02             /* Rx can receive data during disk I/O */
  98. #define CANBRK       04             /* Rx can send a break signal */
  99. #define CANCRY       010            /* Receiver can decrypt */
  100. #define CANLZW       020            /* Receiver can uncompress */
  101. #define CANFC32      040            /* Receiver can use 32 bit Frame Check */
  102.  
  103. /* Parameters for ZFILE frame */
  104. /* Conversion options one of these in ZF0 */
  105. #define ZCBIN        1              /* Binary transfer - inhibit conversion */
  106. #define ZCNL         2              /* Convert NL to local end of line convention */
  107. #define ZCRESUM      3              /* Resume interrupted file transfer */
  108.  
  109. /* Management options, one of these in ZF1 */
  110. #define ZMNEW        1              /* Transfer if source newer or longer */
  111. #define ZMCRC        2              /* Transfer if different file CRC or length */
  112. #define ZMAPND       3              /* Append contents to existing file (if any) */
  113. #define ZMCLOB       4              /* Replace existing file */
  114. #define ZMSPARS      5              /* Encoding for sparse file */
  115. #define ZMDIFF       6              /* Transfer if dates or lengths different */
  116. #define ZMPROT       7              /* Protect destination file */
  117.  
  118. /* Transport options, one of these in ZF2 */
  119. #define ZTLZW        1              /* Lempel-Ziv compression */
  120. #define ZTCRYPT      2              /* Encryption */
  121. #define ZTRLE        3              /* Run Length encoding */
  122.  
  123. /* Parameters for ZCOMMAND frame ZF0 (otherwise 0) */
  124. #define ZCACK1       1              /* Acknowledge, then do command */
  125.  
  126. /* Parameters for ZSINIT frame */
  127. #define ZATTNLEN     32             /* Max length of attention string */
  128.  
  129. class DLL_EXPORT TZModem
  130. {
  131. public:
  132.    TZModem (void);
  133.    ~TZModem (void);
  134.  
  135.    USHORT EndRun, Hangup;
  136.    USHORT FileSent, Maxblklen, Telnet;
  137.    CHAR   Pathname[128];
  138.    ULONG  Speed;
  139.    class  TCom *Com;
  140.    class  TLog *Log;
  141.    class  TProgress *Progress;
  142.  
  143.    USHORT AbortSession (VOID);
  144.    SHORT  TimedRead (LONG hSec);
  145.    SHORT  ZInitReceiver (VOID);
  146.    SHORT  ZInitSender (SHORT NothingToDo);
  147.    SHORT  ZReceiveFile (PSZ pszPath);
  148.    SHORT  ZSendFile (PSZ pszFile, PSZ pszName = NULL);
  149.    VOID   ZEndSender (VOID);
  150.  
  151. private:
  152.    SHORT Wantfcs32, Txfcs32, Znulls, lastsent, ZCtlesc;
  153.    SHORT Rxframeind, Rxtype, Rxflags, Rxbuflen, Rxcount;
  154.    SHORT Tframlen, TryZHdrType, RxTempSize;
  155.    CHAR  Txhdr[4], Rxhdr[4], Attn[ZATTNLEN];
  156.    CHAR  RxBuffer[KSIZE], *TxBuffer;
  157.    CHAR  RxTemp[256], *RxTempPos;
  158.    LONG  Rxtimeout, Rxpos, Txpos, Rxbytes;
  159.  
  160.    VOID  ZAckBiBi (VOID);
  161.    SHORT ZDLRead (VOID);
  162.    SHORT ZGetByte (VOID);
  163.    SHORT ZGetHeader (CHAR *hdr);
  164.    SHORT ZGetHex (VOID);
  165.    LONG  ZGetLong (char *hdr);
  166.    VOID  ZPutHex (SHORT c);
  167.    VOID  ZPutLong (CHAR *hdr, LONG pos);
  168.    SHORT ZReceiveBinaryHeader (CHAR *hdr);
  169.    SHORT ZReceiveBinaryHeader32 (CHAR *hdr);
  170.    SHORT ZReceiveData (char *buf, short length);
  171.    SHORT ZReceiveHexHeader (CHAR *hdr);
  172.    VOID  ZSendBinaryHeader (SHORT type, CHAR *hdr);
  173.    VOID  ZSendData (CHAR *buf, SHORT length, SHORT frameend);
  174.    VOID  ZSendHexHeader (SHORT type, CHAR *hdr);
  175.    VOID  ZSendLine (UCHAR c);
  176. };
  177.  
  178. // ----------------------------------------------------------------------
  179.  
  180. class TFileQueue
  181. {
  182. public:
  183.    TFileQueue (void);
  184.    ~TFileQueue (void);
  185.  
  186.    USHORT Sent;
  187.    CHAR   Name[32], Complete[128];
  188.    ULONG  Size;
  189.    UCHAR  DeleteAfter;
  190.    UCHAR  TruncateAfter;
  191.    ULONG  TotalFiles;
  192.  
  193.    USHORT Add (VOID);
  194.    VOID   Clear (VOID);
  195.    USHORT First (VOID);
  196.    VOID   New (VOID);
  197.    USHORT Next (VOID);
  198.    USHORT Previous (VOID);
  199.    VOID   Remove (PSZ pszName = NULL);
  200.    VOID   Update (VOID);
  201.  
  202. private:
  203.    class  TCollection Data;
  204. };
  205.  
  206. // ----------------------------------------------------------------------
  207.  
  208. class DLL_EXPORT TTransfer : public TZModem
  209. {
  210. public:
  211.    TTransfer (void);
  212.    ~TTransfer (void);
  213.  
  214.    USHORT Task;
  215.    CHAR   Device[16];
  216.    class  TFileQueue RxQueue;
  217.    class  TFileQueue TxQueue;
  218.  
  219.    PSZ    ReceiveXModem (PSZ pszPath);
  220.    PSZ    ReceiveASCIIDump (PSZ pszPath);
  221.    PSZ    ReceiveFTPHost (PSZ pszFile);
  222.    PSZ    Receive1kXModem (PSZ pszPath);
  223.    PSZ    ReceiveYModem (PSZ pszPath);
  224.    PSZ    ReceiveYModemG (PSZ pszPath);
  225.    PSZ    ReceiveZModem (PSZ pszPath);
  226.    VOID   RunExternalProtocol (USHORT Download, PSZ Cmd, class TProtocol *Protocol);
  227.    VOID   Janus (PSZ pszPath);
  228.    USHORT Send1kXModem (PSZ pszFile);
  229.    USHORT SendASCIIDump (PSZ pszFile);
  230.    USHORT SendFTPHost (PSZ pszFile);
  231.    USHORT SendXModem (PSZ pszFile);
  232.    USHORT SendYModem (PSZ pszFile);
  233.    USHORT SendYModemG (PSZ pszFile);
  234.    USHORT SendZModem (PSZ pszFile, PSZ pszName = NULL);
  235.    USHORT SendZModem8K (PSZ pszFile, PSZ pszName = NULL);
  236.  
  237. private:
  238.    USHORT PktSize;
  239.    UCHAR  Soh;
  240.    USHORT DoCrc;
  241.    USHORT UseAck;
  242.    UCHAR  PktNumber;
  243.    CHAR   FinalName[128];
  244.  
  245.    USHORT ReceivePacket (UCHAR *lpBuffer);
  246.    PSZ    ReceiveXFile (PSZ pszPath);
  247.    SHORT  SendPacket (UCHAR *lpBuffer);
  248.    USHORT SendXFile (PSZ pszFile);
  249. };
  250.  
  251. // ----------------------------------------------------------------------
  252.  
  253. /* Misc. Constants */
  254. #define BUFMAX 2048          /* Max packet contents length                   */
  255. #define JANUS_EFFICIENCY 95  /* Estimate Janus xfers at 95% throughput       */
  256.  
  257. class TJanus
  258. {
  259. public:
  260.    TJanus (void);
  261.    ~TJanus (void);
  262.  
  263.    USHORT TimeoutSecs;
  264.    USHORT MakeRequests;
  265.    USHORT AllowRequests;
  266.    CHAR   RxPath[64];
  267.    ULONG  Speed;
  268.    class  TCom *Com;
  269.    class  TLog *Log;
  270.    class  TFileQueue *TxQueue;
  271.    class  TFileQueue *RxQueue;
  272.    class  TOutbound *Outbound;
  273.  
  274.    VOID   Transfer (VOID);
  275.  
  276. private:
  277.    int    RxFile, TxFile;
  278.    USHORT Rxblklen, IsOutbound;
  279.    SHORT  CanCrc32, WaitFlag, RxCrc32, RxTempSize;
  280.    CHAR   RxFileName[128], TxFileName[128];
  281.    CHAR   RxTemp[256], *RxTempPos;
  282.    UCHAR  LastSent, *Rxbufptr, *Rxbufmax;
  283.    UCHAR  RxBuffer[BUFMAX + 8], TxBuffer[BUFMAX + 8];
  284.    ULONG  RxPktCrc32;
  285.    USHORT RxPktCrc16;
  286.    ULONG  LastPktName;
  287.    LONG   Rxpos, RxFilesize, RxFiletime;
  288.  
  289.    UCHAR pkttype, SharedCap, Done;
  290.    USHORT xstate, rstate, rpos_count;
  291.    USHORT blklen, txblklen, txblkmax;
  292.    LONG rxstpos, length, xmit_retry, txpos, txstpos, timeout;
  293.    LONG txlength, lasttx, last_blkpos, rpos_retry, rpos_sttime;
  294.    struct utimbuf utimes;
  295. #if defined(__NT__)
  296.    HANDLE hBlock;
  297. #elif defined(__OS2__)
  298. #endif
  299.  
  300.    friend VOID SendThread (PVOID Args);
  301.  
  302.    SHORT  GetByte (VOID);
  303.    VOID   GetNextFile (VOID);
  304.    UCHAR  GetPacket (VOID);
  305.    SHORT  GetRawByte (VOID);
  306.    LONG   ProcessFileName (VOID);
  307.    VOID   SendByte (UCHAR Byte);
  308.    VOID   SendPacket (UCHAR *Buffer, USHORT Len, USHORT Type);
  309. };
  310.  
  311. // ----------------------------------------------------------------------
  312.  
  313. #define FILE_RECEIVING        1
  314. #define FILE_SENDING          2
  315. #define FILE_BIDIRECTIONAL    3
  316.  
  317. class DLL_EXPORT TProgress
  318. {
  319. public:
  320.    TProgress (void);
  321.    virtual ~TProgress (void);
  322.  
  323.    USHORT Type;
  324.    USHORT RxBlockSize, TxBlockSize;
  325.    CHAR   RxFileName[128], TxFileName[128];
  326.    ULONG  RxSize, RxPosition;
  327.    ULONG  TxSize, TxPosition;
  328.  
  329.    virtual VOID   Begin (VOID);
  330.    virtual VOID   End (VOID);
  331.    virtual VOID   Update (VOID);
  332. };
  333.  
  334. #endif
  335.  
  336.