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.

161 lines
3.9 KiB

  1. #include "precomp.h"
  2. // CP: DCL's header redefines this:
  3. #ifdef CLEAR_FLAG
  4. #undef CLEAR_FLAG
  5. #endif // CLEAR_FLAG
  6. #include <cstring.hpp>
  7. #include <cuserdta.hpp>
  8. #include <oprahcom.h>
  9. USER_DATA_LIST::USER_DATA_LIST()
  10. {
  11. numEntries = 0;
  12. pUserDataArray = NULL;
  13. }
  14. USER_DATA_LIST::~USER_DATA_LIST()
  15. {
  16. POSITION pHead;
  17. while ((pHead = GetHeadPosition()) != NULL)
  18. {
  19. RemoveAt(pHead);
  20. }
  21. delete[] pUserDataArray;
  22. }
  23. DWORD USER_DATA_LIST::AddUserData(GUID * pGUID, unsigned short nData, PVOID pData)
  24. {
  25. ASSERT(pGUID);
  26. ASSERT(!nData || pData);
  27. POSITION Position;
  28. unsigned char * pWork;
  29. unsigned short nDataPlusHeader = nData+sizeof(GUID);
  30. GCCUserData * pUserData;
  31. LPOSTR pOctetString;
  32. // If there is already an entry in the list
  33. // for the GUID, then delete it.
  34. DeleteEntry(pGUID);
  35. // Now go and add the new entry to the list.
  36. pUserData = new GCCUserData;
  37. pOctetString = new OSTR;
  38. if ((pUserData) &&
  39. (pOctetString) &&
  40. (nDataPlusHeader <= 0xffff)) {
  41. pWork = new unsigned char[nDataPlusHeader];
  42. if (pWork) {
  43. pUserData->octet_string = pOctetString;
  44. pOctetString->value = pWork;
  45. pOctetString->length = nDataPlusHeader;
  46. *(GUID *)pWork = *pGUID;
  47. pWork += sizeof(GUID);
  48. memcpy(pWork, pData, nData);
  49. Position = AddTail(pUserData);
  50. if (Position) {
  51. numEntries++;
  52. return NO_ERROR;
  53. }
  54. delete [] pWork;
  55. }
  56. }
  57. delete pOctetString;
  58. delete pUserData;
  59. return UI_RC_OUT_OF_MEMORY;
  60. }
  61. void USER_DATA_LIST::DeleteEntry(GUID * pGUID)
  62. {
  63. POSITION Position;
  64. Position = Lookup(pGUID);
  65. if (Position) {
  66. RemoveAt(Position);
  67. }
  68. }
  69. void * USER_DATA_LIST::RemoveAt(POSITION Position)
  70. {
  71. ASSERT(Position);
  72. GCCUserData * pUserData = (GCCUserData *)GetFromPosition(Position);
  73. if (pUserData) {
  74. delete pUserData->octet_string->value;
  75. delete pUserData->octet_string;
  76. delete pUserData;
  77. COBLIST::RemoveAt(Position);
  78. numEntries--;
  79. }
  80. return pUserData;
  81. }
  82. DWORD USER_DATA_LIST::GetUserDataList(unsigned short * pnRecords,
  83. GCCUserData *** pppUserData)
  84. {
  85. POSITION Position;
  86. GCCUserData ** pUserDataArrayTemp;
  87. DWORD Status = NO_ERROR;
  88. delete[] pUserDataArray;
  89. *pnRecords = 0;
  90. *pppUserData = NULL;
  91. if (numEntries) {
  92. // Allocate memory.
  93. pUserDataArray = new GCCUserData * [numEntries];
  94. if (!pUserDataArray) {
  95. Status = UI_RC_OUT_OF_MEMORY;
  96. }
  97. else {
  98. *pnRecords = numEntries;
  99. *pppUserData = pUserDataArray;
  100. // Fill in array.
  101. pUserDataArrayTemp = pUserDataArray;
  102. Position = GetHeadPosition();
  103. while (Position) {
  104. *(pUserDataArrayTemp++) = (GCCUserData *)GetNext(Position);
  105. }
  106. }
  107. }
  108. return NO_ERROR;
  109. }
  110. BOOL USER_DATA_LIST::Compare(void* pItemToCompare, void* pGUID)
  111. {
  112. return(memcmp(((GCCUserData *)pItemToCompare)->octet_string->value,
  113. pGUID,
  114. sizeof(GUID)) == 0);
  115. }
  116. HRESULT USER_DATA_LIST::GetUserData(REFGUID rguid, BYTE ** ppb, ULONG *pcb)
  117. {
  118. POSITION Position = Lookup((PVOID)&rguid);
  119. if (pcb == NULL)
  120. return E_POINTER;
  121. if (Position) {
  122. GCCUserData * pUserData = (GCCUserData *)Position->pItem;
  123. *pcb = pUserData->octet_string->length - sizeof(GUID);
  124. *ppb = (PBYTE)CoTaskMemAlloc(*pcb);
  125. CopyMemory(*ppb,pUserData->octet_string->value + sizeof(GUID),*pcb);
  126. return S_OK;
  127. }
  128. else {
  129. *ppb = NULL;
  130. *pcb = 0;
  131. return E_INVALIDARG;
  132. }
  133. }