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.

173 lines
3.5 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. m_cRefs (1)
  26. {
  27. if (FAILED(m_strFileExt.Copy(pszFileExt)) ||
  28. FAILED(m_strMimeType.Copy(pszMimeType)))
  29. {
  30. m_fValid = FALSE;
  31. }
  32. }
  33. BOOL IsValid()
  34. {
  35. return m_fValid;
  36. }
  37. LPCWSTR QueryMimeType() const
  38. {
  39. return m_strMimeType.QueryStr();
  40. }
  41. LPWSTR QueryFileExt() const
  42. {
  43. return (LPWSTR)m_strFileExt.QueryStr();
  44. }
  45. VOID ReferenceMimeMapEntry()
  46. {
  47. InterlockedIncrement( &m_cRefs );
  48. }
  49. VOID DereferenceMimeMapEntry()
  50. {
  51. if (InterlockedDecrement( &m_cRefs ) == 0 )
  52. {
  53. delete this;
  54. }
  55. }
  56. private:
  57. ~MIME_MAP_ENTRY()
  58. {
  59. // strings are automatically freed.
  60. }
  61. STRU m_strFileExt; // key for the mime entry object
  62. STRU m_strMimeType;
  63. BOOL m_fValid;
  64. LONG m_cRefs;
  65. }; // class MIME_MAP_ENTRY
  66. class MIME_MAP: public CTypedHashTable<MIME_MAP, MIME_MAP_ENTRY, LPWSTR>
  67. {
  68. public:
  69. MIME_MAP()
  70. : CTypedHashTable<MIME_MAP, MIME_MAP_ENTRY, LPWSTR>("MimeMapper"),
  71. m_fValid (FALSE)
  72. {}
  73. MIME_MAP(LPWSTR pszMimeMappings);
  74. ~MIME_MAP()
  75. {
  76. m_fValid = FALSE;
  77. }
  78. //
  79. // virtual methods from CTypedHashTable
  80. //
  81. static LPWSTR ExtractKey(const MIME_MAP_ENTRY *pMme)
  82. {
  83. return pMme->QueryFileExt();
  84. }
  85. static DWORD CalcKeyHash(LPCWSTR pszKey)
  86. {
  87. return HashStringNoCase(pszKey);
  88. }
  89. static bool EqualKeys(LPCWSTR pszKey1, LPCWSTR pszKey2)
  90. {
  91. return !_wcsicmp(pszKey1, pszKey2);
  92. }
  93. static void AddRefRecord(MIME_MAP_ENTRY *pMme, int nIncr)
  94. {
  95. if (nIncr < 0)
  96. {
  97. pMme->DereferenceMimeMapEntry();
  98. }
  99. else if (nIncr > 0)
  100. {
  101. pMme->ReferenceMimeMapEntry();
  102. }
  103. else
  104. {
  105. DBG_ASSERT( FALSE );
  106. }
  107. }
  108. BOOL IsValid()
  109. {
  110. return m_fValid;
  111. }
  112. HRESULT InitMimeMap();
  113. VOID CreateAndAddMimeMapEntry(
  114. IN LPWSTR pszMimeType,
  115. IN LPWSTR pszExtension);
  116. private:
  117. MIME_MAP(const MIME_MAP &);
  118. void operator=(const MIME_MAP &);
  119. BOOL m_fValid;
  120. HRESULT InitFromMetabase();
  121. }; // class MIME_MAP
  122. HRESULT InitializeMimeMap();
  123. VOID CleanupMimeMap();
  124. HRESULT SelectMimeMappingForFileExt(IN WCHAR *pszFilePath,
  125. IN MIME_MAP *pMimeMap,
  126. OUT STRA *pstrMimeType,
  127. OUT BOOL *pfUsedDefault = NULL );
  128. # endif // _MIMEMAP_HXX_