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.

120 lines
5.5 KiB

  1. /*****************************************************************************\
  2. FILE: encoding.h
  3. DESCRIPTION:
  4. Handle taking internet strings by detecting if they are UTF-8 encoded
  5. or DBCS and finding out what code page was used.
  6. \*****************************************************************************/
  7. #ifndef _STRENCODE_H
  8. #define _STRENCODE_H
  9. #include <mlang.h>
  10. // Turned off until MLANG can successfully detect short strings.
  11. // TODO: We also need to fix ftpfolder when it doesn't have a pidl
  12. // but still needs the site's CWireEncoding state
  13. //#define FEATURE_CP_AUTODETECT
  14. // FTP_FIND_DATA is different than WIN32_FIND_DATA because
  15. // the .cFileName is in WIRECHAR instead of CHAR
  16. #define FTP_FIND_DATA WIN32_FIND_DATAA
  17. #define LPFTP_FIND_DATA LPWIN32_FIND_DATAA
  18. // WIRESTR stands for WireBites which could be DBCS/MBCS or UTF-8
  19. #define WIRECHAR CHAR
  20. #define LPCWIRESTR LPCSTR
  21. #define LPWIRESTR LPSTR
  22. /*****************************************************************************\
  23. CLASS: CMultiLanguageCache
  24. DESCRIPTION:
  25. We can't cache the IMultiLanguage2 * across threads, but we do need to
  26. cache it when we are in a loop because we don't want to keep calling
  27. CoCreateInstance.
  28. \*****************************************************************************/
  29. class CMultiLanguageCache
  30. {
  31. public:
  32. CMultiLanguageCache(void) {m_pml2 = NULL;};
  33. ~CMultiLanguageCache(void) {ATOMICRELEASE(m_pml2);};
  34. IMultiLanguage2 * GetIMultiLanguage2(void) {EVAL(SUCCEEDED(_Init())); return m_pml2;};
  35. private:
  36. // Private member variables
  37. IMultiLanguage2 * m_pml2;
  38. // Private member functions
  39. HRESULT _Init(void);
  40. };
  41. // dwFlags for WireBytesToUnicode() & UnicodeToWireBytes()
  42. #define WIREENC_NONE 0x00000000 // None
  43. #define WIREENC_USE_UTF8 0x00000001 // Prefer UTF-8 because this is a new file. For UnicodeToWireBytes() only.
  44. #define WIREENC_IMPROVE_ACCURACY 0x00000002 // Detect the accuracy. For WireBytesToUnicode() only.
  45. #define DETECT_CONFIDENCE 75 // We want to be this confident.
  46. /*****************************************************************************\
  47. CLASS: CWireEncoding
  48. DESCRIPTION:
  49. 2.1.1 No Data Loss Support (UTF-8)
  50. Server: The server is required to support the FEAT FTP command (rfc2389 http://www.cis.ohio-state.edu/htbin/rfc/rfc2389.html) and the "utf8" feature (http://w3.hethmon.com/ftpext/drafts/draft-ietf-ftpext-intl-ftp-04.txt). If the client sends the server the "utf8" command, the server then needs to accept and return UTF-8 encoded filenames. It's not known when IIS will support this but it won't be supported in the version that ships with Windows 2000.
  51. Network Client (wininet): Wininet needs to respect the unicode filepaths in the FtpGetFileEx() and FtpPutFileEx() APIs. This won't be supported in IE 5.
  52. UI Client (msieftp): It's necessary to see if the server supports the "utf8" command via the FEAT command. If the command is supported, it should be sent to the server and all future strings will be UTF-8 encoded. This should be supported in IE 5 if there is enough time in the schedule.
  53. 2.1.0 Data Loss Backward Compat (DBCS)
  54. MSIEFTP will only support DBCS if and only if the code page on the client matches the server's code page and all ftp directories and filenames used. In future versions I may attempt to sniff the code page.
  55. IMultiLanguage2::DetectCodepage(MLDETECTCP_8BIT, 0, psz, NULL, &DetectEncodingInfo, ARRAYSIZE(DetectEncodingInfo))
  56. MLDETECTCP_8BIT, MLDETECTCP_DBCS, MLCONVCHARF_AUTODETECT
  57. DetectEncodingInfo.nCodePage (IMultiLanguage2::DetectCodepage)
  58. CP_1252: This is english/french/german and the most common.
  59. CP_JPN_SJ: Most common Japanese
  60. CP_CYRILLIC_AUTO = 51251L,
  61. CP_GREEK_AUTO = 51253L,
  62. CP_ARABIC_AUTO = 51256L,
  63. CP_1251 = 1251L: Lucian
  64. \*****************************************************************************/
  65. class CWireEncoding
  66. {
  67. public:
  68. CWireEncoding(void);
  69. ~CWireEncoding(void);
  70. HRESULT WireBytesToUnicode(CMultiLanguageCache * pmlc, LPCWIRESTR pwStr, DWORD dwFlags, LPWSTR pwzDest, DWORD cchSize);
  71. HRESULT UnicodeToWireBytes(CMultiLanguageCache * pmlc, LPCWSTR pwzStr, DWORD dwFlags, LPWIRESTR pwbDest, DWORD cchSize);
  72. HRESULT ReSetCodePages(CMultiLanguageCache * pmlc, CFtpPidlList * pFtpPidlList);
  73. HRESULT CreateFtpItemID(CMultiLanguageCache * pmlc, LPFTP_FIND_DATA pwfd, LPITEMIDLIST * ppidl);
  74. HRESULT ChangeFtpItemIDName(CMultiLanguageCache * pmlc, LPCITEMIDLIST pidlBefore, LPCWSTR pwzNewName, BOOL fUTF8, LPITEMIDLIST * ppidlAfter);
  75. UINT GetCodePage(void) {return m_uiCodePage;};
  76. INT GetConfidence(void) {return m_nConfidence;};
  77. BOOL IsUTF8Supported(void) {return m_fUseUTF8;};
  78. void SetUTF8Support(BOOL fIsUTF8Supported) {m_fUseUTF8 = fIsUTF8Supported;};
  79. private:
  80. // Private member variables
  81. INT m_nConfidence; // How accurate is our guess at m_uiCodePage.
  82. UINT m_uiCodePage; // The code page we guess this to be.
  83. DWORD m_dwMode; // State used by IMultiLanguage2's ::ConvertStringFromUnicode
  84. BOOL m_fUseUTF8; //
  85. // Private member functions
  86. void _ImproveAccuracy(CMultiLanguageCache * pmlc, LPCWIRESTR pwStr, BOOL fUpdateCP, UINT * puiCodePath);
  87. };
  88. #endif // _STRENCODE_H