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.

177 lines
3.7 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name :
  4. mimeutil.cxx
  5. Abstract:
  6. This module defines MIME utility functions: Initialize and Cleanup
  7. of global MimeMap. Also provides function for obtaining the MimeType
  8. for given file extension
  9. Author:
  10. Murali R. Krishnan ( MuraliK ) 23-Jan-1995
  11. Environment:
  12. Win32
  13. Project:
  14. TCP Internet services common dll
  15. Functions Exported:
  16. BOOL InitializeMimeMap( VOID)
  17. BOOL CleanupMimeMap( VOID)
  18. Revision History:
  19. --*/
  20. /************************************************************
  21. * Include Headers
  22. ************************************************************/
  23. # include <tcpdllp.hxx>
  24. # include <tchar.h>
  25. # include "mimemap.hxx"
  26. # include <iistypes.hxx>
  27. # define PSZ_MIME_MAP TEXT( "MimeMap")
  28. PMIME_MAP g_pMimeMap = NULL;
  29. /************************************************************
  30. * Functions
  31. ************************************************************/
  32. BOOL
  33. InitializeMimeMap(
  34. IN LPCTSTR pszRegEntry
  35. )
  36. /*++
  37. Creates a new mime map object and loads the registry entries from
  38. under this entry from \\MimeMap.
  39. --*/
  40. {
  41. BOOL fReturn = FALSE;
  42. DBG_ASSERT( g_pMimeMap == NULL);
  43. g_pMimeMap = new MIME_MAP();
  44. if ( g_pMimeMap != NULL) {
  45. DWORD dwError;
  46. dwError = g_pMimeMap->InitMimeMap( );
  47. if ( dwError == NO_ERROR ) {
  48. fReturn = TRUE;
  49. } else {
  50. DBGPRINTF((DBG_CONTEXT,"InitMimeMap failed with %d\n",
  51. dwError));
  52. SetLastError( dwError);
  53. }
  54. }
  55. IF_DEBUG( MIME_MAP ) {
  56. DBGPRINTF( ( DBG_CONTEXT, "InitializeMimeMap() from Reg %s. returns %d."
  57. " Error = %d\n",
  58. PSZ_MIME_MAP, fReturn, GetLastError()));
  59. }
  60. return ( fReturn);
  61. } // InitializeMimeMap()
  62. BOOL
  63. CleanupMimeMap( VOID)
  64. {
  65. BOOL fReturn = TRUE;
  66. if ( g_pMimeMap != NULL) {
  67. delete g_pMimeMap;
  68. g_pMimeMap = NULL;
  69. }
  70. return ( fReturn);
  71. } // CleanupMimeMap()
  72. BOOL
  73. SelectMimeMappingForFileExt(
  74. IN const PIIS_SERVICE pInetSvc,
  75. IN const TCHAR * pchFilePath,
  76. OUT STR * pstrMimeType, // optional
  77. OUT STR * pstrIconFile) // optional
  78. /*++
  79. Locks and obtains the mime type and/or icon file
  80. for file based on the file extension.
  81. pTsvcInfo pointer to service's tsvcinfo object
  82. pchFilePath pointer to path for the given file
  83. pstrMimeType pointer to string to store the mime type on return
  84. ( if ! NULL)
  85. pstrIconFile pointer to string to store the icon file name on return
  86. ( if ! NULL)
  87. Returns:
  88. TRUE on success and
  89. FALSE if there is any error.
  90. --*/
  91. {
  92. BOOL fReturn = TRUE;
  93. if ( pstrIconFile != NULL || pstrMimeType != NULL) {
  94. PMIME_MAP pMm;
  95. PCMIME_MAP_ENTRY pMmeMatch;
  96. DBG_ASSERT( pInetSvc);
  97. pMm = pInetSvc->QueryMimeMap();
  98. DBG_ASSERT( pMm != NULL);
  99. pMmeMatch = pMm->LookupMimeEntryForFileExt( pchFilePath);
  100. DBG_ASSERT( pMmeMatch != NULL);
  101. if ( pstrIconFile != NULL) {
  102. fReturn = fReturn &&
  103. pstrIconFile->Copy( pMmeMatch->QueryIconFile());
  104. }
  105. if ( pstrMimeType != NULL) {
  106. fReturn = fReturn &&
  107. pstrMimeType->Copy( pMmeMatch->QueryMimeType());
  108. }
  109. }
  110. return ( fReturn);
  111. } // SelectMimeMappingForFileExt()
  112. /************************ End of File ***********************/
  113.