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
7.7 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. fcache.cxx
  5. Abstract:
  6. This module supports functions for file caching for servers
  7. Author:
  8. Murali R. Krishnan ( MuraliK ) 11-Oct-1995
  9. Environment:
  10. Win32 Apps
  11. Project:
  12. Internet Services Common DLL
  13. Functions Exported:
  14. Revision History:
  15. Obtained from old inetsvcs.dll
  16. --*/
  17. /************************************************************
  18. * Include Headers
  19. ************************************************************/
  20. #include <tcpdllp.hxx>
  21. #include <issched.hxx>
  22. #include <tsunami.hxx>
  23. #include <iistypes.hxx>
  24. #include <festrcnv.h>
  25. # include "inetreg.h"
  26. //
  27. // Prototypes
  28. //
  29. //
  30. // RobSol: May 2002
  31. // deleted implementation of
  32. // CheckOutCachedFileFromURI(
  33. // CheckOutCachedFile(
  34. // CheckInCachedFile(
  35. //
  36. //
  37. // Globals
  38. //
  39. /************************************************************
  40. * Functions
  41. ************************************************************/
  42. //
  43. // Taken from NCSA HTTP and wwwlib.
  44. //
  45. // NOTE: These conform to RFC1113, which is slightly different then the Unix
  46. // uuencode and uudecode!
  47. //
  48. const int _pr2six[256]={
  49. 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
  50. 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,62,64,64,64,63,
  51. 52,53,54,55,56,57,58,59,60,61,64,64,64,64,64,64,64,0,1,2,3,4,5,6,7,8,9,
  52. 10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,64,64,64,64,64,64,26,27,
  53. 28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,
  54. 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
  55. 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
  56. 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
  57. 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
  58. 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
  59. 64,64,64,64,64,64,64,64,64,64,64,64,64
  60. };
  61. char _six2pr[64] = {
  62. 'A','B','C','D','E','F','G','H','I','J','K','L','M',
  63. 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
  64. 'a','b','c','d','e','f','g','h','i','j','k','l','m',
  65. 'n','o','p','q','r','s','t','u','v','w','x','y','z',
  66. '0','1','2','3','4','5','6','7','8','9','+','/'
  67. };
  68. const int _pr2six64[256]={
  69. 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
  70. 64,64,64,64,64,64,64,64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,
  71. 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,
  72. 40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
  73. 0,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
  74. 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
  75. 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
  76. 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
  77. 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
  78. 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,
  79. 64,64,64,64,64,64,64,64,64,64,64,64,64
  80. };
  81. char _six2pr64[64] = {
  82. '`','!','"','#','$','%','&','\'','(',')','*','+',',',
  83. '-','.','/','0','1','2','3','4','5','6','7','8','9',
  84. ':',';','<','=','>','?','@','A','B','C','D','E','F',
  85. 'G','H','I','J','K','L','M','N','O','P','Q','R','S',
  86. 'T','U','V','W','X','Y','Z','[','\\',']','^','_'
  87. };
  88. BOOL uudecode(char * bufcoded,
  89. BUFFER * pbuffdecoded,
  90. DWORD * pcbDecoded,
  91. BOOL fBase64
  92. )
  93. {
  94. int nbytesdecoded;
  95. char *bufin = bufcoded;
  96. unsigned char *bufout;
  97. int nprbytes;
  98. int *pr2six = (int*)(fBase64 ? _pr2six64 : _pr2six);
  99. /* Strip leading whitespace. */
  100. while(*bufcoded==' ' || *bufcoded == '\t') bufcoded++;
  101. /* Figure out how many characters are in the input buffer.
  102. * If this would decode into more bytes than would fit into
  103. * the output buffer, adjust the number of input bytes downwards.
  104. */
  105. bufin = bufcoded;
  106. while(pr2six[*(bufin++)] <= 63);
  107. nprbytes = DIFF(bufin - bufcoded) - 1;
  108. nbytesdecoded = ((nprbytes+3)/4) * 3;
  109. if ( !pbuffdecoded->Resize( nbytesdecoded + 4 ))
  110. return FALSE;
  111. bufout = (unsigned char *) pbuffdecoded->QueryPtr();
  112. bufin = bufcoded;
  113. while (nprbytes > 0) {
  114. *(bufout++) =
  115. (unsigned char) (pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4);
  116. *(bufout++) =
  117. (unsigned char) (pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2);
  118. *(bufout++) =
  119. (unsigned char) (pr2six[bufin[2]] << 6 | pr2six[bufin[3]]);
  120. bufin += 4;
  121. nprbytes -= 4;
  122. }
  123. if(nprbytes & 03) {
  124. if(pr2six[bufin[-2]] > 63)
  125. nbytesdecoded -= 2;
  126. else
  127. nbytesdecoded -= 1;
  128. }
  129. ((CHAR *)pbuffdecoded->QueryPtr())[nbytesdecoded] = '\0';
  130. if ( pcbDecoded )
  131. *pcbDecoded = nbytesdecoded;
  132. return TRUE;
  133. }
  134. //
  135. // NOTE NOTE NOTE
  136. // If the buffer length isn't a multiple of 3, we encode one extra byte beyond the
  137. // end of the buffer. This garbage byte is stripped off by the uudecode code, but
  138. // -IT HAS TO BE THERE- for uudecode to work. This applies not only our uudecode, but
  139. // to every uudecode() function that is based on the lib-www distribution [probably
  140. // a fairly large percentage].
  141. //
  142. BOOL uuencode( BYTE * bufin,
  143. DWORD nbytes,
  144. BUFFER * pbuffEncoded,
  145. BOOL fBase64 )
  146. {
  147. unsigned char *outptr;
  148. unsigned int i;
  149. char *six2pr = fBase64 ? _six2pr64 : _six2pr;
  150. BOOL fOneByteDiff = FALSE;
  151. BOOL fTwoByteDiff = FALSE;
  152. unsigned int iRemainder = 0;
  153. unsigned int iClosestMultOfThree = 0;
  154. //
  155. // Resize the buffer to 133% of the incoming data
  156. //
  157. if ( !pbuffEncoded->Resize( nbytes + ((nbytes + 3) / 3) + 4))
  158. return FALSE;
  159. outptr = (unsigned char *) pbuffEncoded->QueryPtr();
  160. iRemainder = nbytes % 3; //also works for nbytes == 1, 2
  161. fOneByteDiff = (iRemainder == 1 ? TRUE : FALSE);
  162. fTwoByteDiff = (iRemainder == 2 ? TRUE : FALSE);
  163. iClosestMultOfThree = ((nbytes - iRemainder)/3) * 3 ;
  164. //
  165. // Encode bytes in buffer up to multiple of 3 that is closest to nbytes.
  166. //
  167. for (i=0; i< iClosestMultOfThree ; i += 3) {
  168. *(outptr++) = six2pr[*bufin >> 2]; /* c1 */
  169. *(outptr++) = six2pr[((*bufin << 4) & 060) | ((bufin[1] >> 4) & 017)]; /*c2*/
  170. *(outptr++) = six2pr[((bufin[1] << 2) & 074) | ((bufin[2] >> 6) & 03)];/*c3*/
  171. *(outptr++) = six2pr[bufin[2] & 077]; /* c4 */
  172. bufin += 3;
  173. }
  174. //
  175. // We deal with trailing bytes by pretending that the input buffer has been padded with
  176. // zeros. Expressions are thus the same as above, but the second half drops off b'cos
  177. // ( a | ( b & 0) ) = ( a | 0 ) = a
  178. //
  179. if (fOneByteDiff)
  180. {
  181. *(outptr++) = six2pr[*bufin >> 2]; /* c1 */
  182. *(outptr++) = six2pr[((*bufin << 4) & 060)]; /* c2 */
  183. //pad with '='
  184. *(outptr++) = '='; /* c3 */
  185. *(outptr++) = '='; /* c4 */
  186. }
  187. else if (fTwoByteDiff)
  188. {
  189. *(outptr++) = six2pr[*bufin >> 2]; /* c1 */
  190. *(outptr++) = six2pr[((*bufin << 4) & 060) | ((bufin[1] >> 4) & 017)]; /*c2*/
  191. *(outptr++) = six2pr[((bufin[1] << 2) & 074)];/*c3*/
  192. //pad with '='
  193. *(outptr++) = '='; /* c4 */
  194. }
  195. //encoded buffer must be zero-terminated
  196. *outptr = '\0';
  197. return TRUE;
  198. }
  199. /************************ End of File ***********************/
  200.