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.

185 lines
4.2 KiB

  1. /******************************************************************************
  2. *
  3. * Copyright (c) 1999 Microsoft Corporation
  4. *
  5. * Module Name:
  6. * hashlist.c
  7. *
  8. * Abstract:
  9. * This file contains the implementation for hashed list required for
  10. * file / extension lookups
  11. *
  12. * Revision History:
  13. * Kanwaljit S Marok ( kmarok ) 05/17/99
  14. * created
  15. *
  16. *****************************************************************************/
  17. #include "precomp.h"
  18. #include "hashlist.h"
  19. #ifndef RING3
  20. //
  21. // linker commands
  22. //
  23. #ifdef ALLOC_PRAGMA
  24. #pragma alloc_text( PAGE, MatchExtension )
  25. #pragma alloc_text( PAGE, MatchEntry )
  26. #endif // ALLOC_PRAGMA
  27. #endif
  28. //
  29. // MatchEntry : Matched the given extension as PathElement and returns the
  30. // entry type if it is found in the hash table.
  31. //
  32. BOOL
  33. __inline
  34. MatchEntry(
  35. IN PBYTE pList, // Pointer to hash list
  36. IN LPWSTR pStr, // Pointer to unicode path string
  37. IN INT NumBytes, // Number of unichars in path string
  38. OUT PINT pType ) // Pointer to variable returning ext type
  39. {
  40. INT iHash;
  41. INT iNode;
  42. ListEntry *pEntry;
  43. BOOL fRet = FALSE;
  44. iHash = HASHSTR(pList, pStr, (USHORT)NumBytes);
  45. if( (iNode = HASH_BUCKET(pList, iHash)) != 0 )
  46. {
  47. pEntry = LIST_NODEPTR(pList, iNode);
  48. while( pEntry )
  49. {
  50. if ( NumBytes == STR_BYTES(pEntry) &&
  51. memcmp(pList + pEntry->m_dwData + sizeof(USHORT),
  52. pStr,
  53. NumBytes ) == 0
  54. )
  55. {
  56. *pType = pEntry->m_dwType;
  57. fRet = TRUE;
  58. break;
  59. }
  60. if (pEntry->m_iNext == 0)
  61. {
  62. break;
  63. }
  64. pEntry = LIST_NODEPTR(pList, pEntry->m_iNext);
  65. }
  66. }
  67. return fRet;
  68. }
  69. //
  70. // MatchExtension: Extracts the extension and matches it against the
  71. // hashed list
  72. //
  73. BOOL
  74. __inline
  75. MatchExtension(
  76. IN PBYTE pList, // Pointer to hash list
  77. IN PUNICODE_STRING pPath , // Pointer to unicode path
  78. OUT PINT pType, // Pointer to node type
  79. OUT PBOOL pbHasExt ) // Pointer to BOOL var returning ext result
  80. {
  81. BOOL fRet = FALSE;
  82. INT i;
  83. INT ExtLen = 0;
  84. PWCHAR pExt = NULL;
  85. UNICODE_STRING ext;
  86. WCHAR pBuffer[ SR_MAX_EXTENSION_LENGTH+sizeof(WCHAR) ];
  87. ASSERT(pList != NULL);
  88. ASSERT(pPath != NULL);
  89. ASSERT(pType != NULL);
  90. ASSERT(pbHasExt != NULL);
  91. ASSERT(pPath->Length >= sizeof(WCHAR));
  92. *pbHasExt = FALSE;
  93. //
  94. // Find the start of an extension. We make sure that we don't find
  95. // an extension that was on a data stream name.
  96. //
  97. for( i=(pPath->Length/sizeof(WCHAR))-1; i>=0; i--)
  98. {
  99. if (pPath->Buffer[i] == L'.')
  100. {
  101. if (pExt == NULL)
  102. {
  103. pExt = &pPath->Buffer[i+1];
  104. }
  105. }
  106. else if (pPath->Buffer[i] == L':')
  107. {
  108. ExtLen = 0;
  109. pExt = NULL;
  110. }
  111. else if (pPath->Buffer[i] == L'\\')
  112. {
  113. break;
  114. }
  115. else if (pExt == NULL)
  116. {
  117. ExtLen++;
  118. }
  119. if (ExtLen > SR_MAX_EXTENSION_CHARS)
  120. {
  121. break;
  122. }
  123. }
  124. if( pExt && ExtLen > 0 )
  125. {
  126. *pbHasExt = TRUE;
  127. //
  128. // Create a unicode string for extension
  129. //
  130. ext.Buffer = pBuffer;
  131. ext.Length = (USHORT)(ExtLen * sizeof(WCHAR));
  132. ext.MaximumLength = sizeof(pBuffer);
  133. memcpy( ext.Buffer,
  134. pExt,
  135. ext.Length );
  136. ext.Buffer[ ExtLen ] = UNICODE_NULL;
  137. //
  138. // Convert to uppercase : Hope this works
  139. //
  140. RtlUpcaseUnicodeString( &ext, &ext, FALSE );
  141. //
  142. // Check extension list.
  143. //
  144. fRet = MatchEntry( pList,
  145. ext.Buffer,
  146. ext.Length,
  147. pType);
  148. }
  149. return fRet;
  150. }