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.

253 lines
4.8 KiB

  1. /* File: C:\WACKER\xfer\krm_res.c (Created: 28-Jan-1994)
  2. * created from HAWIN source file
  3. * krm_res.c -- Routines for handling file transmission using KERMIT
  4. * file transfer protocol.
  5. *
  6. * Copyright 1989,1991,1994 by Hilgraeve Inc. -- Monroe, MI
  7. * All rights reserved
  8. *
  9. * $Revision: 2 $
  10. * $Date: 2/05/99 3:22p $
  11. */
  12. #include <windows.h>
  13. #pragma hdrstop
  14. #include <time.h>
  15. #include <term\res.h>
  16. #include <sys\types.h>
  17. #include <sys\utime.h>
  18. #include <tdll\stdtyp.h>
  19. #include <tdll\mc.h>
  20. #include <tdll\load_res.h>
  21. #include <tdll\xfer_msc.h>
  22. #include <tdll\globals.h>
  23. #include <tdll\file_io.h>
  24. #if !defined(BYTE)
  25. #define BYTE unsigned char
  26. #endif
  27. #include "cmprs.h"
  28. #include "xfr_dsp.h"
  29. #include "xfr_todo.h"
  30. #include "xfr_srvc.h"
  31. #include "xfer.h"
  32. #include "xfer.hh"
  33. #include "xfer_tsc.h"
  34. #include "krm.h"
  35. #include "krm.hh"
  36. // Resident routines for kermit receiving
  37. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  38. * kunload_packet
  39. *
  40. * DESCRIPTION:
  41. *
  42. *
  43. * ARGUMENTS:
  44. *
  45. *
  46. * RETURNS:
  47. *
  48. */
  49. int kunload_packet(ST_KRM *kc, int len, unsigned char *bufr)
  50. {
  51. int sethbit = FALSE;
  52. unsigned char c;
  53. unsigned char *bp;
  54. unsigned char c7;
  55. unsigned char *limit;
  56. int reptcount;
  57. int i;
  58. xfer_idle(kc->hSession, XFER_IDLE_IO);
  59. bp = bufr;
  60. limit = bufr + len;
  61. while (bp < limit)
  62. {
  63. c = *bp++;
  64. if (kc->its_rept && c == kc->its_rept)
  65. {
  66. reptcount = unchar(*bp++);
  67. c = *bp++;
  68. }
  69. else
  70. reptcount = 1;
  71. if (kc->its_qbin && c == kc->its_qbin)
  72. {
  73. sethbit = TRUE;
  74. c = *bp++;
  75. }
  76. if (c == kc->its_qctl)
  77. {
  78. c = *bp++;
  79. c7 = (unsigned char)(c & 0x7F);
  80. if (c7 != kc->its_qctl && c7 != kc->its_qbin && c7 != kc->its_rept)
  81. c = (unsigned char)ctl(c);
  82. }
  83. if (sethbit)
  84. {
  85. c |= 0x80;
  86. sethbit = FALSE;
  87. }
  88. for (i = reptcount + 1; --i > 0; )
  89. if ((*kc->p_kputc)(kc, c) == ERROR)
  90. return(ERROR);
  91. } /* while (bp < limit) */
  92. /* pointer should stop right at limit, if not, somethings wrong */
  93. if (bp > limit)
  94. return(ERROR);
  95. else
  96. return(0);
  97. }
  98. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  99. * kr_putc
  100. *
  101. * DESCRIPTION:
  102. *
  103. *
  104. * ARGUMENTS:
  105. *
  106. *
  107. * RETURNS:
  108. *
  109. */
  110. int kr_putc(ST_KRM *kc, int c)
  111. {
  112. ++kc->kbytes_received;
  113. return ((int)(fio_putc(c, kc->fhdl)));
  114. }
  115. // Resident routines for kermit sending
  116. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  117. * kload_packet
  118. *
  119. * DESCRIPTION:
  120. *
  121. * ARGUMENTS:
  122. *
  123. * RETURNS:
  124. *
  125. */
  126. int kload_packet(ST_KRM *kc, unsigned char *bufr)
  127. {
  128. char *bp = bufr;
  129. char *rp = bufr;
  130. char *limit;
  131. int rptcount = 1;
  132. int c, c7;
  133. int lastc = -1;
  134. int no8thbit = 0 /* (cnfg.bits_per_char != 8) */;
  135. xfer_idle(kc->hSession, XFER_IDLE_IO);
  136. limit = bufr + (kc->its_maxl - kc->its_chkt - 6);
  137. while (bp < limit)
  138. {
  139. if ((c = (*kc->p_kgetc)(kc)) == EOF)
  140. break;
  141. if (kc->its_rept) /* check for repeat characters */
  142. {
  143. if (c != lastc)
  144. {
  145. rptcount = 1; /* start new check for repeat chars */
  146. rp = bp;
  147. lastc = c;
  148. }
  149. else if (++rptcount == 4)
  150. {
  151. bp = rp; /* back up in buffer to where repeat started */
  152. while ((c = (*kc->p_kgetc)(kc)) == lastc && ++rptcount < 94)
  153. ;
  154. if (c != lastc)
  155. {
  156. if (c != EOF) /* note: putting the extra char. */
  157. { /* directly back into the send */
  158. fio_ungetc(c, kc->fhdl);/* file buffer will not work */
  159. --kc->kbytes_sent; /* if p_kgetc is not pointing */
  160. } /* directly to ks_getc(). */
  161. c = lastc;
  162. }
  163. lastc = -1;
  164. *bp++ = kc->its_rept;
  165. *bp++ = (char)tochar(rptcount);
  166. }
  167. }
  168. /* check for binary (8th bit) quoting */
  169. if (c & 0x80)
  170. {
  171. if (kc->its_qbin) /* do 8th-bit quoting */
  172. {
  173. *bp++ = kc->its_qbin;
  174. c &= 0x7F;
  175. }
  176. else if (no8thbit)
  177. {
  178. /* error! */
  179. // strcpy(kc->xtra_err, strld(TM_NOT_CNFGD));
  180. /* TODO: figure this error out */
  181. return(ERROR);
  182. }
  183. }
  184. /* check for characters needing control-quoting */
  185. c7 = (c & 0x7F);
  186. if (c7 < ' ' || c7 == DEL)
  187. {
  188. *bp++ = kc->its_qctl;
  189. c = ctl(c);
  190. }
  191. else if (c7 == (int)kc->its_qctl ||
  192. c7 == (int)kc->its_qbin ||
  193. c7 == (int)kc->its_rept)
  194. *bp++ = kc->its_qctl;
  195. *bp++ = (char)c;
  196. }
  197. if (fio_ferror(kc->fhdl))
  198. return(ERROR);
  199. return (int)(bp - bufr);
  200. }
  201. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  202. * ks_getc
  203. *
  204. * DESCRIPTION:
  205. *
  206. * ARGUMENTS:
  207. *
  208. * RETURNS:
  209. *
  210. */
  211. #if 1
  212. int ks_getc(ST_KRM *kc)
  213. {
  214. ++kc->kbytes_sent;
  215. return(fio_getc(kc->fhdl));
  216. }
  217. #else
  218. int ks_getc(ST_KRM *kc)
  219. {
  220. int c;
  221. ++kc->kbytes_sent;
  222. c = fio_getc(kc->fhdl);
  223. DbgOutStr("%c", c, 0,0,0,0);
  224. return c;
  225. }
  226. #endif