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.

117 lines
2.7 KiB

  1. /*****************************************************************************
  2. *
  3. * cookies.cpp - Take care of the status bar.
  4. *
  5. *****************************************************************************/
  6. #include "priv.h"
  7. #include "cookie.h"
  8. int CCookieList::_FreeStringEnum(LPVOID pString, LPVOID pData)
  9. {
  10. LPTSTR pszString = (LPTSTR) pString;
  11. Str_SetPtr(&pszString, NULL);
  12. return 1;
  13. }
  14. DWORD CCookieList::_Find(LPCTSTR pszString)
  15. {
  16. DWORD dwCookie = -1; // -1 means not found.
  17. DWORD dwIndex;
  18. DWORD dwSize = DPA_GetPtrCount(m_hdpa);
  19. for (dwIndex = 0; dwIndex < dwSize; dwIndex++)
  20. {
  21. LPCTSTR pszCurrent = (LPCTSTR) DPA_FastGetPtr(m_hdpa, dwIndex);
  22. if (pszCurrent && !StrCmp(pszCurrent, pszString))
  23. {
  24. dwCookie = dwIndex;
  25. break; // Found, it's already in the list so recycle.
  26. }
  27. }
  28. return dwCookie;
  29. }
  30. DWORD CCookieList::GetCookie(LPCTSTR pszString)
  31. {
  32. ENTERCRITICAL;
  33. DWORD dwCookie = -1;
  34. if (!EVAL(pszString))
  35. return -1;
  36. if (!m_hdpa)
  37. m_hdpa = DPA_Create(10);
  38. if (EVAL(m_hdpa))
  39. {
  40. dwCookie = _Find(pszString);
  41. // Did we not find it in the list?
  42. if (-1 == dwCookie)
  43. {
  44. LPTSTR pszCopy = NULL;
  45. dwCookie = DPA_GetPtrCount(m_hdpa);
  46. Str_SetPtr(&pszCopy, pszString);
  47. DPA_AppendPtr(m_hdpa, pszCopy);
  48. }
  49. }
  50. LEAVECRITICAL;
  51. return dwCookie;
  52. }
  53. HRESULT CCookieList::GetString(DWORD dwCookie, LPTSTR pszString, DWORD cchSize)
  54. {
  55. ENTERCRITICAL;
  56. HRESULT hr = S_FALSE;
  57. if (m_hdpa &&
  58. (dwCookie < (DWORD)DPA_GetPtrCount(m_hdpa)))
  59. {
  60. LPCTSTR pszCurrent = (LPCTSTR) DPA_FastGetPtr(m_hdpa, dwCookie);
  61. StrCpyN(pszString, pszCurrent, cchSize);
  62. hr = S_OK;
  63. }
  64. LEAVECRITICAL;
  65. return hr;
  66. }
  67. /****************************************************\
  68. Constructor
  69. \****************************************************/
  70. CCookieList::CCookieList()
  71. {
  72. DllAddRef();
  73. // This needs to be allocated in Zero Inited Memory.
  74. // Assert that all Member Variables are inited to Zero.
  75. ASSERT(!m_hdpa);
  76. LEAK_ADDREF(LEAK_CCookieList);
  77. }
  78. /****************************************************\
  79. Destructor
  80. \****************************************************/
  81. CCookieList::~CCookieList(void)
  82. {
  83. ENTERCRITICAL;
  84. if (m_hdpa)
  85. DPA_DestroyCallback(m_hdpa, _FreeStringEnum, NULL);
  86. LEAVECRITICAL;
  87. ASSERTNONCRITICAL;
  88. DllRelease();
  89. LEAK_DELREF(LEAK_CCookieList);
  90. }