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.

246 lines
5.5 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name :
  4. mimemap.hxx
  5. Abstract:
  6. This module defines the classes for mapping for
  7. MIME type to file extensions.
  8. Author:
  9. Murali R. Krishnan ( MuraliK ) 09-Jan-1995
  10. Project:
  11. TCP Services common 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. --*/
  16. #ifndef _MIMEMAP_HXX_
  17. #define _MIMEMAP_HXX_
  18. /************************************************************
  19. * Include Headers
  20. ************************************************************/
  21. # ifdef __cplusplus
  22. extern "C" {
  23. # endif // __cplusplus
  24. # include <nt.h>
  25. # include <ntrtl.h>
  26. # include <nturtl.h>
  27. # include <windows.h>
  28. # ifdef __cplusplus
  29. }; // extern "C"
  30. # endif // __cplusplus
  31. # include "string.hxx"
  32. # include "hashtab.hxx"
  33. # ifndef dllexp
  34. # define dllexp __declspec( dllexport)
  35. # endif
  36. /************************************************************
  37. * Type Definitions
  38. ************************************************************/
  39. /*******************************************************************
  40. NAME: MIME_MAP_ENTRY ( short Mme)
  41. SYNOPSIS: Small storage class for the MIME type entry
  42. HISTORY:
  43. Johnl 04-Sep-1994 Created
  44. MuraliK 09-Jan-1995 Modified to include Gopher Type
  45. ********************************************************************/
  46. class MIME_MAP_ENTRY : public HT_ELEMENT {
  47. public:
  48. MIME_MAP_ENTRY(
  49. IN LPCTSTR pchMimeType,
  50. IN LPCTSTR pchFileExt);
  51. ~MIME_MAP_ENTRY( VOID )
  52. {
  53. // strings are automatically freed.
  54. }
  55. BOOL IsValid( VOID ) const
  56. { return ( m_fValid); }
  57. LPCTSTR QueryMimeType( VOID ) const
  58. { return m_strMimeType.QueryStr(); }
  59. LPCTSTR QueryFileExt( VOID ) const
  60. { return m_strFileExt.QueryStr(); }
  61. LPCTSTR QueryIconFile( VOID ) const
  62. { return NULL; }
  63. LPCTSTR QueryGopherType( VOID) const
  64. { return NULL; }
  65. // Virtual functions of HT_ELEMENT are defined here.
  66. dllexp
  67. virtual LPCSTR QueryKey(VOID) const { return (m_strFileExt.QueryStr()); }
  68. dllexp
  69. virtual DWORD QueryKeyLen(VOID) const { return (m_strFileExt.QueryCCH()); }
  70. dllexp
  71. virtual LONG Reference( VOID)
  72. { return ( InterlockedIncrement( &m_nRefs)); }
  73. dllexp
  74. virtual LONG Dereference( VOID)
  75. { return ( InterlockedDecrement( &m_nRefs)); }
  76. dllexp
  77. virtual BOOL IsMatch( IN LPCSTR pszKey, IN DWORD cchKey) const
  78. { return ((m_strFileExt.QueryCCH() == cchKey) &&
  79. (0 == _stricmp( m_strFileExt.QueryStr(), pszKey))
  80. );
  81. }
  82. dllexp
  83. VOID Print( VOID) const
  84. #if DBG
  85. ;
  86. #else
  87. { ; }
  88. #endif // !DBG
  89. private:
  90. STR m_strFileExt; // key for the mime entry object
  91. STR m_strMimeType;
  92. LONG m_nRefs;
  93. //
  94. // TRUE if the object constructed is properly
  95. //
  96. DWORD m_fValid:1;
  97. }; // class MIME_MAP_ENTRY
  98. typedef MIME_MAP_ENTRY * PMIME_MAP_ENTRY;
  99. typedef const MIME_MAP_ENTRY * PCMIME_MAP_ENTRY;
  100. /*******************************************************************
  101. NAME: MIME_MAP ( short Mm)
  102. SYNOPSIS: Class for containing the list of mime map
  103. entries.
  104. HISTORY:
  105. MuraliK 09-Jan-1995 Created.
  106. ********************************************************************/
  107. class MIME_MAP {
  108. public:
  109. dllexp MIME_MAP( VOID);
  110. ~MIME_MAP( VOID)
  111. {
  112. CleanupThis();
  113. }
  114. BOOL IsValid( VOID)
  115. { return ( m_fValid && m_htMimeEntries.IsValid()); }
  116. dllexp
  117. VOID CleanupThis( VOID);
  118. dllexp
  119. DWORD InitMimeMap( VOID );
  120. //
  121. // Used to map MimeType-->MimeEntry
  122. // The function returns an array of pointers to mime entries
  123. // which match given mime type, as well the count.
  124. // Returns NO_ERROR on success or Win32 error codes
  125. //
  126. dllexp
  127. DWORD LookupMimeEntryForMimeType(
  128. IN const STR & strMimeType,
  129. OUT PCMIME_MAP_ENTRY * prgMme,
  130. IN OUT LPDWORD pnMmeEntries);
  131. //
  132. // Used to map FileExtension-->MimeEntry
  133. // The function returns a single mime entry.
  134. // the mapping from file-extension to mime entry is unique.
  135. // Users should lock and unlock MIME_MAP before and after usage.
  136. //
  137. // Returns NO_ERROR on success or Win32 error codes
  138. //
  139. dllexp
  140. PCMIME_MAP_ENTRY
  141. LookupMimeEntryForFileExt(
  142. IN const TCHAR * pchPathName);
  143. #if DBG
  144. dllexp VOID Print( VOID);
  145. #else
  146. dllexp VOID Print( VOID)
  147. { ; }
  148. #endif // !DBG
  149. private:
  150. DWORD m_fValid : 1;
  151. HASH_TABLE m_htMimeEntries;
  152. PMIME_MAP_ENTRY m_pMmeDefault;
  153. dllexp
  154. BOOL AddMimeMapEntry(
  155. IN PMIME_MAP_ENTRY pMmeNew);
  156. dllexp
  157. BOOL
  158. CreateAndAddMimeMapEntry(
  159. IN LPCTSTR pszMimeType,
  160. IN LPCTSTR pszExtension) ;
  161. dllexp
  162. DWORD
  163. InitFromMetabase(
  164. VOID
  165. );
  166. dllexp
  167. DWORD
  168. InitFromRegistryChicagoStyle( VOID );
  169. }; // class MIME_MAP
  170. typedef MIME_MAP *PMIME_MAP;
  171. BOOL
  172. InitializeMimeMap(
  173. IN LPCTSTR pszRegEntry
  174. );
  175. # endif // _MIMEMAP_HXX
  176.