Source code of Windows XP (NT5)
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.

165 lines
3.4 KiB

  1. /*++
  2. Copyright (c) 1995-2000 Microsoft Corporation
  3. Module Name :
  4. mimemap.hxx
  5. Abstract:
  6. This module defines the classes for mapping MIME type to
  7. file extensions.
  8. Author:
  9. Murali R. Krishnan ( MuraliK ) 09-Jan-1995
  10. Project:
  11. UlW3.dll
  12. Revision History:
  13. Vlad Sadovsky (VladS) 12-feb-1996 Merging IE 2.0 MIME list
  14. Murali R. Krishnan (MuraliK) 14-Oct-1996 Use a hash-table
  15. Anil Ruia (AnilR) 27-Mar-2000 Port to IIS+
  16. --*/
  17. #ifndef _MIMEMAP_HXX_
  18. #define _MIMEMAP_HXX_
  19. class MIME_MAP_ENTRY
  20. {
  21. public:
  22. MIME_MAP_ENTRY(IN LPCWSTR pszMimeType,
  23. IN LPCWSTR pszFileExt)
  24. : m_fValid (TRUE)
  25. {
  26. if (FAILED(m_strFileExt.Copy(pszFileExt)) ||
  27. FAILED(m_strMimeType.Copy(pszMimeType)))
  28. {
  29. m_fValid = FALSE;
  30. }
  31. }
  32. ~MIME_MAP_ENTRY( VOID )
  33. {
  34. // strings are automatically freed.
  35. }
  36. BOOL IsValid()
  37. {
  38. return m_fValid;
  39. }
  40. LPCWSTR QueryMimeType() const
  41. {
  42. return m_strMimeType.QueryStr();
  43. }
  44. LPWSTR QueryFileExt() const
  45. {
  46. return (LPWSTR)m_strFileExt.QueryStr();
  47. }
  48. private:
  49. STRU m_strFileExt; // key for the mime entry object
  50. STRU m_strMimeType;
  51. BOOL m_fValid;
  52. }; // class MIME_MAP_ENTRY
  53. class MIME_MAP: public CTypedHashTable<MIME_MAP, MIME_MAP_ENTRY, LPWSTR>
  54. {
  55. public:
  56. MIME_MAP()
  57. : CTypedHashTable<MIME_MAP, MIME_MAP_ENTRY, LPWSTR>("MimeMapper"),
  58. m_fValid (FALSE),
  59. m_pMmeDefault (NULL)
  60. {}
  61. MIME_MAP(LPWSTR pszMimeMappings);
  62. ~MIME_MAP()
  63. {
  64. delete m_pMmeDefault;
  65. m_pMmeDefault = NULL;
  66. m_fValid = FALSE;
  67. }
  68. //
  69. // virtual methods from CTypedHashTable
  70. //
  71. static LPWSTR ExtractKey(const MIME_MAP_ENTRY *pMme)
  72. {
  73. return pMme->QueryFileExt();
  74. }
  75. static DWORD CalcKeyHash(LPCWSTR pszKey)
  76. {
  77. return HashStringNoCase(pszKey);
  78. }
  79. static bool EqualKeys(LPCWSTR pszKey1, LPCWSTR pszKey2)
  80. {
  81. return !_wcsicmp(pszKey1, pszKey2);
  82. }
  83. static void AddRefRecord(MIME_MAP_ENTRY *pMme, int nIncr)
  84. {
  85. if (nIncr < 0)
  86. {
  87. delete pMme;
  88. }
  89. }
  90. BOOL IsValid()
  91. {
  92. return m_fValid;
  93. }
  94. HRESULT InitMimeMap();
  95. //
  96. // Used to map FileExtension-->MimeEntry
  97. // The function returns a single mime entry.
  98. // the mapping from file-extension to mime entry is unique.
  99. // Users should lock and unlock MIME_MAP before and after usage.
  100. //
  101. // Returns HRESULT
  102. //
  103. const MIME_MAP_ENTRY *LookupMimeEntryForFileExt(
  104. IN LPWSTR pszPathName);
  105. private:
  106. BOOL m_fValid;
  107. MIME_MAP_ENTRY *m_pMmeDefault;
  108. BOOL AddMimeMapEntry(IN MIME_MAP_ENTRY *pMmeNew);
  109. BOOL CreateAndAddMimeMapEntry(
  110. IN LPWSTR pszMimeType,
  111. IN LPWSTR pszExtension);
  112. HRESULT InitFromMetabase();
  113. HRESULT InitFromRegistryChicagoStyle();
  114. }; // class MIME_MAP
  115. HRESULT InitializeMimeMap(IN LPWSTR pszRegEntry);
  116. VOID CleanupMimeMap();
  117. HRESULT SelectMimeMappingForFileExt(IN WCHAR *pszFilePath,
  118. IN MIME_MAP *pMimeMap,
  119. OUT STRA *pstrMimeType);
  120. # endif // _MIMEMAP_HXX_