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.

119 lines
2.9 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 2001
  3. Module Name:
  4. Cookie.cxx
  5. Abstract:
  6. HTTP2 Cookie management functions.
  7. Author:
  8. KamenM 09-18-01 Created
  9. Revision History:
  10. --*/
  11. #include <precomp.hxx>
  12. #include <Cookie.hxx>
  13. CookieCollection *g_pServerCookieCollection = NULL;
  14. CookieCollection *g_pInProxyCookieCollection = NULL;
  15. CookieCollection *g_pOutProxyCookieCollection = NULL;
  16. HTTP2VirtualConnection *CookieCollection::FindElement (
  17. IN HTTP2ServerCookie *Cookie
  18. )
  19. /*++
  20. Routine Description:
  21. Finds an element in the cookie collection.
  22. Arguments:
  23. Cookie - element to find. Only the Cookie part of it
  24. is looked at.
  25. Return Value:
  26. NULL - the element was not found.
  27. non-NULL - pointer to the found element
  28. --*/
  29. {
  30. LIST_ENTRY *CurrentListElement;
  31. HTTP2ServerCookie *CurrentCookie;
  32. ULONG *CurrentCookieNumber;
  33. ULONG *CookieNumberToLookFor;
  34. Mutex.VerifyOwned();
  35. CookieNumberToLookFor = (ULONG *)Cookie->GetCookie();
  36. CurrentListElement = ListHead.Flink;
  37. while (CurrentListElement != &ListHead)
  38. {
  39. CurrentCookie = CONTAINING_RECORD(CurrentListElement, HTTP2ServerCookie, ListEntry);
  40. CurrentCookieNumber = (ULONG *)CurrentCookie->GetCookie();
  41. // the cookies are cryptographically strong numbers. From a performance
  42. // perspective, the chances that the first comparison will succeed and
  43. // the others will fail are extremely slim
  44. if ((*(CurrentCookieNumber + 0) == *(CookieNumberToLookFor + 0))
  45. && (*(CurrentCookieNumber + 1) == *(CookieNumberToLookFor + 1))
  46. && (*(CurrentCookieNumber + 2) == *(CookieNumberToLookFor + 2))
  47. && (*(CurrentCookieNumber + 3) == *(CookieNumberToLookFor + 3)) )
  48. {
  49. return CurrentCookie->Connection;
  50. }
  51. CurrentListElement = CurrentListElement->Flink;
  52. }
  53. return NULL;
  54. }
  55. RPC_STATUS CookieCollection::InitializeCookieCollection (
  56. IN OUT CookieCollection **CookieCollectionPtr
  57. )
  58. /*++
  59. Routine Description:
  60. Initializes a given cookie collection.
  61. N.B. This method is not thread safe. Callers
  62. must synchronize before calling it.
  63. Arguments:
  64. CookieCollectionPtr - on input verified to point to NULL.
  65. If the function succeeds, on output it will contain
  66. the collection. If the function fails, on output it
  67. is guaranteed to contain NULL.
  68. Return Value:
  69. RPC_S_OK for success or RPC_S_* for error
  70. --*/
  71. {
  72. RPC_STATUS RpcStatus = RPC_S_OK;
  73. if (*CookieCollectionPtr == NULL)
  74. {
  75. *CookieCollectionPtr = new CookieCollection(&RpcStatus);
  76. if (RpcStatus != RPC_S_OK)
  77. {
  78. delete *CookieCollectionPtr;
  79. *CookieCollectionPtr = NULL;
  80. }
  81. }
  82. return RpcStatus;
  83. }