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.

96 lines
2.0 KiB

  1. DWORD
  2. FASTCALL
  3. CalculateHashNoCase(
  4. IN LPCSTR lpszString,
  5. IN DWORD dwStringLength
  6. );
  7. //
  8. // HEADER_STRING - extension of ICSTRING so we can perform hashing on strings.
  9. // Note that we only care about the header value
  10. //
  11. class HEADER_STRING : public ICSTRING {
  12. private:
  13. DWORD m_Hash;
  14. public:
  15. HEADER_STRING() {
  16. SetHash(0);
  17. }
  18. ~HEADER_STRING() {
  19. }
  20. VOID SetHash(DWORD dwHash) {
  21. m_Hash = dwHash;
  22. }
  23. VOID SetNextKnownIndex(BYTE bNextKnown) {
  24. _Union.Bytes.ExtraByte1 = bNextKnown;
  25. }
  26. BYTE * GetNextKnownIndexPtr() {
  27. return &_Union.Bytes.ExtraByte1;
  28. }
  29. DWORD GetNextKnownIndex() {
  30. return ((DWORD)_Union.Bytes.ExtraByte1);
  31. }
  32. DWORD GetHash(VOID) {
  33. return m_Hash;
  34. }
  35. VOID CreateHash(LPSTR lpszBase)
  36. {
  37. DWORD i = 0;
  38. LPSTR string = StringAddress(lpszBase);
  39. while ((i < (DWORD)StringLength())
  40. && !((string[i] == ':')
  41. || (string[i] == ' ')
  42. || (string[i] == '\r')
  43. || (string[i] == '\n'))) {
  44. ++i;
  45. }
  46. m_Hash = CalculateHashNoCase(string, i);
  47. }
  48. int HashStrnicmp(LPSTR lpBase, LPCSTR lpszString, DWORD dwLength, DWORD dwHash)
  49. {
  50. int RetVal = -1;
  51. if ((m_Hash == 0) || (m_Hash == dwHash))
  52. {
  53. if ( Strnicmp(lpBase, lpszString, dwLength) == 0 )
  54. {
  55. LPSTR value;
  56. value = StringAddress(lpBase) + dwLength;
  57. //
  58. // the input string could be a substring of a different header
  59. //
  60. if (*value == ':')
  61. {
  62. RetVal = 0; // success, we have a match here!
  63. }
  64. }
  65. }
  66. return RetVal;
  67. }
  68. HEADER_STRING & operator=(LPSTR String) {
  69. SetHash(0);
  70. return (HEADER_STRING &)ICSTRING::operator=(String);
  71. }
  72. };