Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

229 lines
7.4 KiB

  1. /*
  2. * xmodem.hh -- Include file for ZMODEM private stuff
  3. *
  4. * Copyright 1989 by Hilgraeve Inc. -- Monroe, MI
  5. * All rights reserved
  6. *
  7. * $Revision: 6 $
  8. * $Date: 7/12/02 8:20a $
  9. */
  10. // These constants are used to turn on various types of debug display
  11. // #define DEBUG_DUMPPACKET // Log bad packet contents to a file
  12. #if defined(ERROR)
  13. #undef ERROR
  14. #endif
  15. #if defined(CAN)
  16. #undef CAN
  17. #endif
  18. #define OK 0
  19. #define FALSE 0
  20. #define TRUE 1
  21. #if defined(ERROR)
  22. #undef ERROR
  23. #endif
  24. #define ERROR (-1)
  25. #define FILE_DONE 1
  26. #define TRANSFER_DONE 2
  27. /*
  28. * Max value for HOWMANY is 255.
  29. * A larger value reduces system overhead but may evoke kernel bugs.
  30. * 133 corresponds to an XMODEM/CRC sector
  31. */
  32. #ifndef HOWMANY
  33. #define HOWMANY 133
  34. #endif
  35. /* Ward Christensen / CP/M parameters - Don't change these! */
  36. #define ENQ 005
  37. #define CAN ('X'&037)
  38. #define XOFF ('s'&037)
  39. #define XON ('q'&037)
  40. #define SOH 1
  41. #define STX 2
  42. #define EOT 4
  43. #define ACK 6
  44. #define NAK 025
  45. #define CPMEOF 032
  46. #define WANTCRC 0103 /* send C not NAK to get crc not checksum */
  47. #define TIMEOUT (-2)
  48. #define RCDO (-3) /* Not too sure about this one */
  49. #define ZCARRIER_LOST (-4)
  50. #define ZFULLDISK (-5)
  51. #define ERROFFSET 5
  52. #define ERRORMAX 5
  53. #define RETRYMAX 5
  54. #define WCEOT (-10)
  55. //#define PATHLEN 257 /* ready for 4.2 bsd ? */
  56. #define PATHLEN MAX_PATH
  57. #define UNIXFILE 0xF000 /* The S_IFMT file mask bit for stat */
  58. /* Parameters for ZSINIT frame */
  59. #define ZATTNLEN 32 /* Max length of attention string */
  60. /* Control structure, allocated during transfers to hold control variables */
  61. struct z_mdm_cntrl
  62. {
  63. HSESSION hSession; /* in case we actually need this */
  64. HCOM hCom; /* derived from above */
  65. int nMethod; /* Zmodem, or Zmodem wiht crash recovery? */
  66. int fSavePartial; /* Save partially received files? */
  67. unsigned long ulOverride; /* Override "file exists" overwrite options? */
  68. long real_bytes; /* real number of bytes, not virtual number */
  69. long file_bytes; /* number of bytes processed in current file */
  70. long total_bytes; /* number of bytes total in previous files */
  71. long actual_bytes; /* previous value includes skipped files */
  72. int nSkip; /* true if skipping a file */
  73. void *flagkey; /* used for detecting the user abort key */
  74. jmp_buf flagkey_buf; /* used for long jump after user abort */
  75. jmp_buf intrjmp;
  76. ST_IOBUF *fh; /* handle for the current file */
  77. long basesize; /* used when appending to a file */
  78. long xfertimer; /* used for timing the transfers */
  79. long xfertime; /* ditto */
  80. int nfiles; /* total number of files to transfer */
  81. int filen; /* number of the current file */
  82. long filesize; /* size of the current file */
  83. long nbytes; /* total number of bytes to transfer */
  84. long Rxtimeout; /* Tenths of a second to wait for something */
  85. const long *z_cr3tab; /* pointer to 32 bit checksum table */
  86. const unsigned short *z_crctab; /* pointer to 16 bit checksum table */
  87. int Rxframeind; /* ZBIN ZBIN32, or ZHEX type of frame received */
  88. int Rxtype; /* Type of header received */
  89. int Rxcount; /* Count of data bytes received */
  90. char Rxhdr[4]; /* Received header */
  91. char Txhdr[4]; /* Transmitted header */
  92. long Rxpos; /* Received file position */
  93. long Txpos; /* Transmitted file position */
  94. int Txfcs32; /* TRUE means send binary frames with 32 bit FCS */
  95. int Crc32t; /* Display flag indicating 32 bit CRC being sent */
  96. int Crc32; /* Display flag indicating 32 bit CRC being received */
  97. char Attn[ZATTNLEN+1]; /* Attention string rx sends to tx on err */
  98. int lastsent; /* Last char we sent */
  99. int Not8bit; /* Seven bits seen on header */
  100. long displayed_time;
  101. int Zctlesc;
  102. int Zrwindow;
  103. BOOL Eofseen;
  104. int tryzhdrtype;
  105. BOOL Thisbinary;
  106. int Filemode;
  107. long Modtime;
  108. int do_init;
  109. TCHAR zconv; /* ZMODEM file conversion request */
  110. TCHAR zmanag; /* ZMODEM file management request */
  111. TCHAR ztrans; /* ZMODEM file transport request */
  112. TCHAR *secbuf;
  113. TCHAR *fname;
  114. TCHAR *our_fname;
  115. stFB stP; /* used in foo com functions */
  116. TCHAR *txbuf;
  117. int Filesleft;
  118. long Totalleft;
  119. int blklen;
  120. int blkopt; /* do we override zmodem block length */
  121. int Beenhereb4;
  122. BOOL Wantfcs32; /* Do we want 32 bit crc */
  123. int Rxflags;
  124. unsigned Rxbuflen; /* receiver maximum buffer length */
  125. unsigned Txwindow;
  126. unsigned Txwcnt; /* counter used to space ack requests */
  127. unsigned Txwspac; /* space between ZCRCQ requests */
  128. char Myattn[1];
  129. int errors;
  130. int s_error;
  131. int pstatus;
  132. int last_event;
  133. int Lskipnocor;
  134. long Lastsync; /* last offset to which we got a ZRPOS */
  135. long Lrxpos; /* receivers last reported offset */
  136. };
  137. typedef struct z_mdm_cntrl ZC;
  138. #define updcrc(x,cp,crc) (x->z_crctab[((crc >> 8) & 255)] ^ (crc << 8) ^ cp)
  139. #define UPDC32(x,b,c) (x->z_cr3tab[((int)c ^ b) & 0xff] ^ ((c >> 8) & 0x00FFFFFF))
  140. /* from zmdm.c */
  141. void zsbhdr (ZC *zc, int type, BYTE *hdr);
  142. void zsbh32 (ZC *zc, BYTE *hdr, int type);
  143. void zshhdr (ZC *zc, int type, BYTE *hdr);
  144. void zsdata (ZC *zc, BYTE *buf, int length, int frameend);
  145. void zsda32 (ZC *zc, BYTE *buf, int length, int frameend);
  146. int zrdata (ZC *zc, BYTE *buf, int length);
  147. int zrdat32 (ZC *zc, BYTE *buf, int length);
  148. int zgethdr (ZC *zc, BYTE *hdr, int eflag);
  149. int zrbhdr (ZC *zc, BYTE *hdr, int eflag);
  150. int zrbhdr32 (ZC *zc, BYTE *hdr, int eflag);
  151. int zrhhdr (ZC *zc, BYTE *hdr, int eflag);
  152. void zputhex (ZC *zc, int c);
  153. void zsendline (ZC *zc, int c);
  154. int zgethex (ZC *zc);
  155. int zgeth1 (ZC *zc);
  156. int zdlread (ZC *zc);
  157. int noxrd7 (ZC *zc);
  158. void stohdr (ZC *zc, long pos);
  159. long rclhdr (BYTE *hdr);
  160. int zmdm_rl (ZC *zc, int timeout);
  161. /* Functions used to fiddle with the displays */
  162. void zmdms_progress (ZC *zc, int status);
  163. void zmdms_newfile (ZC *zc, int filen, TCHAR *fname, long flength);
  164. void zmdms_update (ZC *zc, int state);
  165. void zmdmr_progress (ZC *zc, int status);
  166. void zmdmr_update (ZC *zc, int status);
  167. void zmdmr_filecnt (ZC *zc, int cnt);
  168. void zmdmr_totalsize (ZC *zc, long bytes);
  169. void zmdmr_newfile (ZC *zc, int filen, BYTE *theirname, TCHAR *ourname);
  170. void zmdmr_filesize (ZC *zc, long fsize);
  171. unsigned int zmdm_error (ZC *zc, int error);
  172. int zmdm_retval (ZC *zc, int flag, int error);
  173. /* from zmdm_rcv.c */
  174. int tryz (ZC *zc);
  175. int rzfiles (ZC *zc);
  176. int rzfile (ZC *zc);
  177. void zmputs (ZC *zc, char *s);
  178. int closeit (ZC *zc);
  179. void ackbibi (ZC *zc);
  180. /* void bttyout (char c); */
  181. /* from zmdm_snd.c */
  182. int wcs (ZC *zc, TCHAR FAR *oname);
  183. int wctxpn (ZC *zc, TCHAR FAR *name);
  184. int zfilbuf (ZC *zc);
  185. void canit (ZC *zc);
  186. int getzrxinit (ZC *zc);
  187. int sendzsinit (ZC *zc);
  188. int zsendfile (ZC *zc, char *buf, int blen);
  189. int zsendfdata (ZC *zc);
  190. int getinsync (ZC *zc, int flag);
  191. void saybibi (ZC *zc);
  192. /* the following stuff is here as an attempt to match names into HA5 */
  193. #define readline(h,x) zmdm_rl(h,x)
  194. #define xsendline(h,p,c) fooComSendChar(h->hCom,p,c)
  195. #define sendline(h,p,c) fooComSendChar(h->hCom,p,c)
  196. #define flushmo(h,p) fooComSendPush(h->hCom,p)