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.

171 lines
9.4 KiB

  1. // --------------------------------------------------------------------------------
  2. // Internat.h
  3. // Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  4. // Steven J. Bailey
  5. // --------------------------------------------------------------------------------
  6. #ifndef __INTERNAT_H
  7. #define __INTERNAT_H
  8. #include "exrwlck.h"
  9. // --------------------------------------------------------------------------------
  10. // Forward Decls
  11. // --------------------------------------------------------------------------------
  12. typedef struct tagVARIANTCONVERT *LPVARIANTCONVERT;
  13. typedef struct tagPROPSYMBOL *LPPROPSYMBOL;
  14. typedef struct tagPROPSTRINGA *LPPROPSTRINGA;
  15. typedef struct tagPROPSTRINGW *LPPROPSTRINGW;
  16. typedef const struct tagPROPSTRINGA *LPCPROPSTRINGA;
  17. typedef const struct tagPROPSTRINGW *LPCPROPSTRINGW;
  18. typedef struct tagMIMEVARIANT *LPMIMEVARIANT;
  19. // --------------------------------------------------------------------------------
  20. // Extern Global
  21. // --------------------------------------------------------------------------------
  22. class CIntlGlobals {
  23. public:
  24. static void Init();
  25. static void Term();
  26. static LPINETCSETINFO GetDefBodyCset();
  27. static LPINETCSETINFO GetDefHeadCset();
  28. static LPINETCSETINFO GetDefaultCharset();
  29. static void SetDefBodyCset(LPINETCSETINFO pCharset);
  30. static void SetDefHeadCset(LPINETCSETINFO pCharset);
  31. private:
  32. static void DoInit();
  33. static BOOL mg_bInit;
  34. static CRITICAL_SECTION mg_cs;
  35. static LPINETCSETINFO mg_pDefBodyCset;
  36. static LPINETCSETINFO mg_pDefHeadCset;
  37. static INETCSETINFO mg_rDefaultCharset;
  38. };
  39. // --------------------------------------------------------------------------------
  40. // IsDBCSCodePage
  41. // --------------------------------------------------------------------------------
  42. #define IsDBCSCodePage(_cpi) \
  43. (932 == _cpi || 936 == _cpi || 950 == _cpi || 949 == _cpi || 874 == _cpi || 10001 == _cpi)
  44. // --------------------------------------------------------------------------------
  45. // HCSET Handle Macros
  46. // --------------------------------------------------------------------------------
  47. #define HCSET_SIGN (WORD)40
  48. #define HCSETMAKE(_index) (HCHARSET)MAKELPARAM(m_wTag + HCSET_SIGN, _index)
  49. #define HCSETINDEX(_hcset) (ULONG)HIWORD(_hcset)
  50. #define HCSETTICK(_hcset) (WORD)LOWORD(_hcset)
  51. #define HCSETVALID(_hcset) ((WORD)(HCSETTICK(_hcset) - HCSET_SIGN) == m_wTag && HCSETINDEX(_hcset) < m_cst.cCharsets)
  52. #define PCsetFromHCset(_hcset) m_cst.prgpCharset[HCSETINDEX(_hcset)]
  53. // --------------------------------------------------------------------------------
  54. // CSTABLE - Character Set Table
  55. // --------------------------------------------------------------------------------
  56. typedef struct tagCSTABLE {
  57. ULONG cCharsets; // Number of items in prgpCset
  58. ULONG cAlloc; // Number of items allocated in prgCset
  59. LPINETCSETINFO *prgpCharset; // Array of INETCSETINFO structs
  60. } CSTABLE, *LPCSTABLE;
  61. // --------------------------------------------------------------------------------
  62. // CPTABLE - Code Page Table
  63. // --------------------------------------------------------------------------------
  64. typedef struct tagCPTABLE {
  65. ULONG cPages; // Number of items in prgpCset
  66. ULONG cAlloc; // Number of items allocated in prgCset
  67. LPCODEPAGEINFO *prgpPage; // Array of INETCSETINFO structs
  68. } CPTABLE, *LPCPTABLE;
  69. // --------------------------------------------------------------------------------
  70. // CMimeInternational
  71. // --------------------------------------------------------------------------------
  72. class CMimeInternational : public IMimeInternational
  73. {
  74. public:
  75. // ----------------------------------------------------------------------------
  76. // Construction
  77. // ----------------------------------------------------------------------------
  78. CMimeInternational(void);
  79. ~CMimeInternational(void);
  80. // -------------------------------------------------------------------------
  81. // IUnknown
  82. // -------------------------------------------------------------------------
  83. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv);
  84. STDMETHODIMP_(ULONG) AddRef(void);
  85. STDMETHODIMP_(ULONG) Release(void);
  86. // -------------------------------------------------------------------------
  87. // IMimeInternational Methods
  88. // -------------------------------------------------------------------------
  89. STDMETHODIMP GetCodePageCharset(CODEPAGEID cpiCodePage, CHARSETTYPE ctCsetType, LPHCHARSET phCharset);
  90. STDMETHODIMP SetDefaultCharset(HCHARSET hCharset);
  91. STDMETHODIMP GetDefaultCharset(LPHCHARSET phCharset);
  92. STDMETHODIMP FindCharset(LPCSTR pszCharset, LPHCHARSET phCharset);
  93. STDMETHODIMP GetCharsetInfo(HCHARSET hCharset, LPINETCSETINFO pCsetInfo);
  94. STDMETHODIMP GetCodePageInfo(CODEPAGEID cpiCodePage, LPCODEPAGEINFO pCodePageInfo);
  95. STDMETHODIMP ConvertBuffer(CODEPAGEID cpiSource, CODEPAGEID cpiDest, LPBLOB pIn, LPBLOB pOut, ULONG *pcbRead);
  96. STDMETHODIMP ConvertString(CODEPAGEID cpiSource, CODEPAGEID cpiDest, LPPROPVARIANT pIn, LPPROPVARIANT pOut);
  97. STDMETHODIMP MLANG_ConvertInetReset(void);
  98. STDMETHODIMP MLANG_ConvertInetString(CODEPAGEID cpiSource, CODEPAGEID cpiDest, LPCSTR pSourceStr,
  99. LPINT pnSizeOfSourceStr, LPSTR pDestinationStr, LPINT pnSizeOfDestBuffer);
  100. STDMETHODIMP DecodeHeader(HCHARSET hCharset, LPCSTR pszData, LPPROPVARIANT pDecoded, LPRFC1522INFO pRfc1522Info);
  101. STDMETHODIMP EncodeHeader(HCHARSET hCharset, LPPROPVARIANT pData, LPSTR *ppszEncoded, LPRFC1522INFO pRfc1522Info);
  102. STDMETHODIMP Rfc1522Decode(LPCSTR pszValue, LPSTR pszCharset, ULONG cchmax, LPSTR *ppszDecoded);
  103. STDMETHODIMP Rfc1522Encode(LPCSTR pszValue, HCHARSET hCharset, LPSTR *ppszEncoded);
  104. STDMETHODIMP CanConvertCodePages(CODEPAGEID cpiSource, CODEPAGEID cpiDest);
  105. // -------------------------------------------------------------------------
  106. // LPINETCSETINFO Based Methods
  107. // -------------------------------------------------------------------------
  108. HRESULT HrOpenCharset(CODEPAGEID cpiCodePage, CHARSETTYPE ctCsetType, LPINETCSETINFO *ppCharset);
  109. HRESULT HrOpenCharset(LPCSTR pszCharset, LPINETCSETINFO *ppCharset);
  110. HRESULT HrOpenCharset(HCHARSET hCharset, LPINETCSETINFO *ppCharset);
  111. HRESULT HrFindCodePage(CODEPAGEID cpiCodePage, LPCODEPAGEINFO *ppCodePage);
  112. HRESULT HrConvertString(CODEPAGEID cpiSource, CODEPAGEID cpiDest, LPMIMEVARIANT pSource, LPMIMEVARIANT pDest);
  113. HRESULT HrDecodeHeader(LPINETCSETINFO pCharset, LPRFC1522INFO pRfc1522Info, LPMIMEVARIANT pSource, LPMIMEVARIANT pDest);
  114. HRESULT HrEncodeHeader(LPINETCSETINFO pCharset, LPRFC1522INFO pRfc1522Info, LPMIMEVARIANT pSource, LPMIMEVARIANT pDest);
  115. // -------------------------------------------------------------------------
  116. // Helpers to do Header Properties
  117. // -------------------------------------------------------------------------
  118. HRESULT HrEncodeProperty(LPVARIANTCONVERT pConvert, LPMIMEVARIANT pSource, LPMIMEVARIANT pDest);
  119. HRESULT HrDecodeProperty(LPVARIANTCONVERT pConvert, LPMIMEVARIANT pSource, LPMIMEVARIANT pDest);
  120. HRESULT HrWideCharToMultiByte(CODEPAGEID cpiCodePage, LPCPROPSTRINGW pStringW, LPPROPSTRINGA pStringA);
  121. HRESULT HrMultiByteToWideChar(CODEPAGEID cpiCodePage, LPCPROPSTRINGA pStringA, LPPROPSTRINGW pStringW);
  122. HRESULT HrValidateCodepages(LPMIMEVARIANT pSource, LPMIMEVARIANT pDest, LPBYTE *ppbSource, ULONG *pcbSource, CODEPAGEID *pcpiSource, CODEPAGEID *pcpiDest);
  123. // -------------------------------------------------------------------------
  124. // CMimeInternational Methods
  125. // -------------------------------------------------------------------------
  126. BOOL FIsValidHandle(HCHARSET hCharset);
  127. HRESULT IsDBCSCharset(HCHARSET hCharset);
  128. private:
  129. // ----------------------------------------------------------------------------
  130. // Private Utils
  131. // ----------------------------------------------------------------------------
  132. void _FreeInetCsetTable(void);
  133. void _FreeCodePageTable(void);
  134. void _QuickSortPageInfo(long left, long right);
  135. void _QuickSortCsetInfo(long left, long right);
  136. HRESULT _HrReadPageInfo(CODEPAGEID cpiCodePage, LPCODEPAGEINFO *ppLangInfo);
  137. HRESULT _HrReadCsetInfo(LPCSTR pszCharset, LPINETCSETINFO *ppCsetInfo);
  138. private:
  139. // -------------------------------------------------------------------------
  140. // Private Data
  141. // -------------------------------------------------------------------------
  142. LONG m_cRef; // Reference Counting
  143. WORD m_wTag; // Used to create and verify hCharsets
  144. CSTABLE m_cst; // Character Sets
  145. CPTABLE m_cpt; // CodePages
  146. CExShareLockWithNestAllowed m_lock; // Thread Safety
  147. DWORD m_dwConvState; // Used to save convert state from MLANG
  148. };
  149. // --------------------------------------------------------------------------------
  150. // Prototypes
  151. // --------------------------------------------------------------------------------
  152. void InitInternational(void);
  153. HRESULT HrRegisterMlangDll(void);
  154. #endif // __INTERNAT_H