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.

256 lines
13 KiB

  1. // --------------------------------------------------------------------------------
  2. // Inetconv.h
  3. // Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  4. // Steven J. Bailey
  5. // --------------------------------------------------------------------------------
  6. #ifndef __INETCONV_H
  7. #define __INETCONV_H
  8. // --------------------------------------------------------------------------------
  9. // Depends
  10. // --------------------------------------------------------------------------------
  11. #include "binhex.h"
  12. // --------------------------------------------------------------------------------
  13. // Forward Decls
  14. // --------------------------------------------------------------------------------
  15. #ifdef MAC
  16. typedef PMAC_LineBreakConsole LPLINEBREAKER;
  17. #else // !MAC
  18. interface IMLangLineBreakConsole;
  19. typedef IMLangLineBreakConsole *LPLINEBREAKER;
  20. #endif // !MAC
  21. // --------------------------------------------------------------------------------
  22. // Rfc1522.cpp Uses This Table for Base64 Encoding
  23. // --------------------------------------------------------------------------------
  24. extern const CHAR g_rgchDecodeBase64[256];
  25. extern const CHAR g_rgchEncodeBase64[];
  26. extern const CHAR g_rgchHex[];
  27. // --------------------------------------------------------------------------------
  28. // Defines
  29. // --------------------------------------------------------------------------------
  30. #define CCHMAX_ENCODEUU_IN 45
  31. #define CCHMAX_ENCODEUU_OUT 70
  32. #define CCHMAX_QPLINE 72
  33. #define CCHMAX_ENCODE64_IN 57
  34. #define CCHMAX_ENCODE64_OUT 80
  35. #define CCHMAX_DECODE64_OUT 60
  36. // --------------------------------------------------------------------------------
  37. // UU decoder
  38. // --------------------------------------------------------------------------------
  39. #define UUDECODE(c) (((c) == '`') ? '\0' : ((c) - ' ') & 0x3F)
  40. #define UUENCODE(c) ((c) ? ((c) & 0x3F ) + ' ' : '`')
  41. // --------------------------------------------------------------------------------
  42. // Macros shared with Rfc1522.cpp
  43. // --------------------------------------------------------------------------------
  44. #define DECODE64(_ch) (g_rgchDecodeBase64[(unsigned)_ch])
  45. // --------------------------------------------------------------------------------
  46. // BinHex decoder
  47. // --------------------------------------------------------------------------------
  48. #define DECODEBINHEX(_ch) (g_rgchDecodeBinHex[(unsigned)_ch])
  49. #define FBINHEXRETURN(_ch) (((_ch) == '\t') || ((_ch) == chCR) || ((_ch) == chLF) || ((_ch) == ' '))
  50. // --------------------------------------------------------------------------------
  51. // CConvertBuffer
  52. // --------------------------------------------------------------------------------
  53. typedef struct tagCONVERTBUFFER {
  54. LPBYTE pb; // Pointer to static buffer (or allocated buffer)
  55. ULONG cbAlloc; // Size of pb
  56. ULONG cb; // End of data window
  57. ULONG i; // Read read/write position (offset from iStart)
  58. } CONVERTBUFFER, *LPCONVERTBUFFER;
  59. // --------------------------------------------------------------------------------
  60. // Converter Flags
  61. // --------------------------------------------------------------------------------
  62. #define ICF_CODEPAGE FLAG01 // Code Page Conversion
  63. #define ICF_WRAPTEXT FLAG02 // Wrapping Text
  64. #define ICF_KILLNBSP FLAG03 // Removed NBSPs from Uncicode Source
  65. // --------------------------------------------------------------------------------
  66. // CONVINITINFO
  67. // --------------------------------------------------------------------------------
  68. typedef struct tagCONVINITINFO {
  69. DWORD dwFlags; // ICF Flags
  70. ENCODINGTYPE ietEncoding; // Encoding Type
  71. CODEPAGEID cpiSource; // Source Code Page
  72. CODEPAGEID cpiDest; // Destination Code Page
  73. LONG cchMaxLine; // Maxline length for wrapping
  74. BOOL fEncoder; // Is this an encoder or decoder...
  75. BOOL fShowMacBinary; // Show we give back the data fork only?
  76. MACBINARY rMacBinary; // Macbinary Header
  77. } CONVINITINFO, *LPCONVINITINFO;
  78. // --------------------------------------------------------------------------------
  79. // INETCONVTYPE
  80. // --------------------------------------------------------------------------------
  81. typedef enum tagINETCONVTYPE { // Append Write
  82. ICT_UNKNOWN = 0, // --------------------
  83. ICT_WRAPTEXT_CODEPAGE = 1000, // m_rIn --> m_rCset
  84. ICT_WRAPTEXT = 1001, // m_rIn --> m_rOut
  85. ICT_CODEPAGE_ENCODE = 1002, // m_rCset --> m_rOut
  86. ICT_ENCODE = 1003, // m_rIn --> m_rOut
  87. ICT_DECODE_CODEPAGE = 1004, // m_rIn --> m_rCset
  88. ICT_DECODE = 1005, // m_rIn --> m_rOut
  89. } INETCONVTYPE;
  90. // --------------------------------------------------------------------------------
  91. // BINHEXSTATEDEC
  92. // --------------------------------------------------------------------------------
  93. typedef enum tagBINHEXSTATEDEC
  94. {
  95. sSTARTING, sSTARTED, sHDRFILESIZE, sHEADER, sDATA, sDATACRC, sRESOURCE, sRESOURCECRC, sENDING, sENDED
  96. } BINHEXSTATEDEC;
  97. // --------------------------------------------------------------------------------
  98. // Stores the character in _uch in pCon
  99. // --------------------------------------------------------------------------------
  100. #define FConvBuffCanRead(_rCon) \
  101. (_rCon.i < _rCon.cb)
  102. // --------------------------------------------------------------------------------
  103. // ConvBuffAppend
  104. // --------------------------------------------------------------------------------
  105. #define ConvBuffAppend(_uch) \
  106. m_rOut.pb[m_rOut.cb++] = _uch
  107. // --------------------------------------------------------------------------------
  108. // ConvBuffAppendW
  109. // --------------------------------------------------------------------------------
  110. #define ConvBuffAppendW(_wch) \
  111. { \
  112. *((WCHAR *)&m_rOut.pb[m_rOut.cb]) = _wch; \
  113. m_rOut.cb += 2; \
  114. }
  115. // --------------------------------------------------------------------------------
  116. // CInternetConverter
  117. // --------------------------------------------------------------------------------
  118. class CInternetConverter : public IUnknown
  119. {
  120. public:
  121. // ----------------------------------------------------------------------------
  122. // CInternetConverter
  123. // ----------------------------------------------------------------------------
  124. CInternetConverter(void);
  125. ~CInternetConverter(void);
  126. // ----------------------------------------------------------------------------
  127. // IUnknown Methods
  128. // ----------------------------------------------------------------------------
  129. STDMETHODIMP QueryInterface(REFIID, LPVOID *);
  130. STDMETHODIMP_(ULONG) AddRef(void);
  131. STDMETHODIMP_(ULONG) Release(void);
  132. // ----------------------------------------------------------------------------
  133. // CInternetConverter Methods
  134. // ----------------------------------------------------------------------------
  135. HRESULT HrInit(LPCONVINITINFO pInitInfo);
  136. HRESULT HrInternetEncode(BOOL fLastBuffer);
  137. HRESULT HrInternetDecode(BOOL fLastBuffer);
  138. // ----------------------------------------------------------------------------
  139. // Methods used to set the current conversion buffer
  140. // ----------------------------------------------------------------------------
  141. HRESULT HrFillAppend(LPBLOB pData);
  142. HRESULT HrWriteConverted(IStream *pStream);
  143. HRESULT HrWriteConverted(CInternetConverter *pConverter);
  144. private:
  145. // ----------------------------------------------------------------------------
  146. // Encoders/Decoders
  147. // ----------------------------------------------------------------------------
  148. HRESULT HrEncode64(void);
  149. HRESULT HrDecode64(void);
  150. HRESULT HrEncodeUU(void);
  151. HRESULT HrDecodeUU(void);
  152. HRESULT HrEncodeQP(void);
  153. HRESULT HrDecodeQP(void);
  154. HRESULT HrEncodeBinhex(void);
  155. HRESULT HrDecodeBinHex(void);
  156. // ----------------------------------------------------------------------------
  157. // HrWrapInternetText
  158. // ----------------------------------------------------------------------------
  159. HRESULT HrWrapInternetTextA(void);
  160. HRESULT HrWrapInternetTextW(void);
  161. HRESULT _FixLineBreakingProblems(IN LCID locale, IN const WCHAR* pszSrc,
  162. IN long cchSrc, IN long cMaxColumns,
  163. OUT long* pcchLine, OUT long* pcchSkip,
  164. BOOL * pfDoURLFix);
  165. HRESULT _GetEndOfURL(IN LPCWSTR pszLine, DWORD cchSize, DWORD * pdwMax);
  166. // ----------------------------------------------------------------------------
  167. // Character Set Encoders
  168. // ----------------------------------------------------------------------------
  169. HRESULT HrCodePageFromOutToCset(void); // Was HrDecodeCharset
  170. HRESULT HrCodePageFromCsetToIn(void); // Was HrEncodeCharset
  171. // ----------------------------------------------------------------------------
  172. // Utilities
  173. // ----------------------------------------------------------------------------
  174. BOOL FUUEncodeThrowAway(LPSTR pszLine, ULONG cbLine, ULONG *pcbActual, ULONG *pcbLine);
  175. HRESULT HrBinhexThrowAway(LPSTR pszLine, ULONG cbLine);
  176. HRESULT HrAppendBuffer(LPCONVERTBUFFER pBuffer, LPBLOB pData, BOOL fKillNBSP);
  177. void CopyMemoryRemoveNBSP(LPBYTE pbDest, LPBYTE pbSource, ULONG cbSource);
  178. HRESULT HrInitConvertType(LPCONVINITINFO pInitInfo);
  179. HRESULT HrBinhexDecodeBuffAppend(UCHAR uchIn, ULONG cchIn, ULONG cchLeft, ULONG * cbProduced);
  180. // ----------------------------------------------------------------------------
  181. // Please Inline
  182. // ----------------------------------------------------------------------------
  183. inline HRESULT HrGrowBuffer(LPCONVERTBUFFER pBuffer, ULONG cbAppend);
  184. inline HRESULT HrConvBuffAppendBlock(LPBYTE pb, ULONG cb);
  185. inline LPSTR PszConvBuffGetNextLine(ULONG *pcbLine, ULONG *pcbRead, BOOL *pfFound);
  186. private:
  187. // ----------------------------------------------------------------------------
  188. // Private Data
  189. // ----------------------------------------------------------------------------
  190. ULONG m_cRef; // Reference Counting
  191. DWORD m_dwFlags; // ICF Flags
  192. ENCODINGTYPE m_ietEncoding; // Conversion Format
  193. CODEPAGEID m_cpiSource; // Source Code Page
  194. CODEPAGEID m_cpiDest; // Destination Code Page
  195. LONG m_cchMaxLine; // Maxline Length for wrapping
  196. BOOL m_fEncoder; // Encoder ?
  197. BOOL m_fLastBuffer; // There is no more data
  198. UCHAR m_uchPrev; // Used in qp
  199. CONVERTBUFFER m_rIn; // Used for reading
  200. CONVERTBUFFER m_rOut; // Used for writing
  201. CONVERTBUFFER m_rCset; // Used for writing
  202. LPCONVERTBUFFER m_pAppend; // Buffer appended to in public HrFillAppend
  203. LPCONVERTBUFFER m_pWrite; // Buffer dumped when HrWriteConverted is called
  204. INETCONVTYPE m_convtype; // Conversion type
  205. LPLINEBREAKER m_pLineBreak; // Line Breaker Object
  206. LCID m_lcid; // Locale id used only for line wrapping
  207. ULONG m_cbConvert; // Base64 Convert Buffer Count
  208. UCHAR m_uchConvert[4]; // Base64 Convert Buffer
  209. CBinhexEncoder *m_pBinhexEncode; // Binhex Encoder
  210. BINHEXSTATEDEC m_eBinHexStateDec; // Binhex Decoder state
  211. BOOL m_fRepeating; // Binhex repeating flag
  212. ULONG m_ulAccum; // Binhex accumulator
  213. ULONG m_cAccum; // BinHex accumulator count
  214. CONVERTBUFFER m_rBinhexHeader; // BinHex header buffer
  215. LPCONVERTBUFFER m_prBinhexOutput; // BinHex output buffer
  216. LONG m_cbToProcess; // BinHex section count
  217. ULONG m_cbDataFork; // BinHex data fork size
  218. ULONG m_cbResourceFork; // BinHex resource fork size
  219. WORD m_wCRC; // BinHex working CRC holder
  220. WORD m_wCRCForFork; // BinHex the CRC for the current fork
  221. BOOL m_fDataForkOnly; // BinHex give back only the data fork
  222. };
  223. // --------------------------------------------------------------------------------
  224. // CInternetConverter
  225. // --------------------------------------------------------------------------------
  226. HRESULT HrCreateInternetConverter(LPCONVINITINFO pInitInfo, CInternetConverter **ppConverter);
  227. #endif __INETCONV_H