Source code of Windows XP (NT5)
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.

222 lines
4.9 KiB

  1. /***************************************************************************/
  2. /** Microsoft Windows **/
  3. /** Copyright(c) Microsoft Corp., 1995-1996 **/
  4. /***************************************************************************/
  5. //
  6. // File: RostInfo.cpp
  7. // Created: ChrisPi 6/17/96
  8. // Modified:
  9. //
  10. // The CRosterInfo class is implemented, which is used for adding user
  11. // information to the T.120 roster
  12. //
  13. #include "precomp.h"
  14. #include <RostInfo.h>
  15. GUID g_csguidRostInfo = GUID_ROSTINFO;
  16. static const HROSTINFO g_cshriEOList = (HROSTINFO)((LONG_PTR)-1);
  17. CRosterInfo::~CRosterInfo()
  18. {
  19. DebugEntry(CRosterInfo::~CRosterInfo);
  20. while (FALSE == m_ItemList.IsEmpty())
  21. {
  22. PWSTR pwszItem = (PWSTR) m_ItemList.RemoveHead();
  23. ASSERT(pwszItem);
  24. delete pwszItem;
  25. }
  26. delete m_pvSaveData;
  27. DebugExitVOID(CRosterInfo::~CRosterInfo);
  28. }
  29. HRESULT CRosterInfo::AddItem(PCWSTR pcwszTag, PCWSTR pcwszData)
  30. {
  31. DebugEntry(CRosterInfo::AddItem);
  32. ASSERT(pcwszTag);
  33. ASSERT(pcwszData);
  34. HRESULT hr = E_OUTOFMEMORY;
  35. int nTagLength = lstrlenW(pcwszTag);
  36. int nDataLength = lstrlenW(pcwszData);
  37. // +1 for tag sep, +1 for rost info sep
  38. PWSTR pwszNewItem = new WCHAR[nTagLength + 1 + nDataLength + 1];
  39. if (NULL != pwszNewItem)
  40. {
  41. ::CopyMemory( (PVOID) pwszNewItem,
  42. pcwszTag,
  43. sizeof(WCHAR) * nTagLength);
  44. pwszNewItem[nTagLength] = g_cwchRostInfoTagSeparator;
  45. ::CopyMemory( (PVOID) &(pwszNewItem[nTagLength + 1]),
  46. pcwszData,
  47. sizeof(WCHAR) * nDataLength);
  48. pwszNewItem[nTagLength + 1 + nDataLength] = g_cwchRostInfoSeparator;
  49. m_ItemList.AddTail(pwszNewItem);
  50. hr = S_OK;
  51. }
  52. DebugExitHRESULT(CRosterInfo::AddItem, hr);
  53. return hr;
  54. }
  55. HRESULT CRosterInfo::ExtractItem( PHROSTINFO phRostInfo,
  56. PCWSTR pcwszTag,
  57. LPTSTR pszBuffer,
  58. UINT cbLength)
  59. {
  60. DebugEntry(CRosterInfo::ExtractItem);
  61. ASSERT(pcwszTag);
  62. HRESULT hr = E_FAIL;
  63. USES_CONVERSION;
  64. POSITION pos;
  65. if ((NULL == phRostInfo) ||
  66. (NULL == *phRostInfo))
  67. {
  68. pos = m_ItemList.GetHeadPosition();
  69. }
  70. else
  71. {
  72. pos = *phRostInfo;
  73. }
  74. if (g_cshriEOList != pos)
  75. {
  76. while (NULL != pos)
  77. {
  78. PWSTR pwszItem = (PWSTR) m_ItemList.GetNext(pos);
  79. if (NULL != phRostInfo)
  80. {
  81. *phRostInfo = (NULL != pos) ? pos : g_cshriEOList;
  82. }
  83. ASSERT(pwszItem);
  84. int nItemLength = lstrlenW(pwszItem);
  85. int nTagLength = lstrlenW(pcwszTag);
  86. // NOTE: CRT is used for memcmp
  87. if ((nItemLength > nTagLength) &&
  88. (0 == memcmp( pcwszTag,
  89. pwszItem,
  90. sizeof(WCHAR) * nTagLength)) &&
  91. (g_cwchRostInfoTagSeparator == pwszItem[nTagLength]))
  92. {
  93. if (NULL != pszBuffer)
  94. {
  95. lstrcpyn(pszBuffer, W2T(&(pwszItem[nTagLength + 1])), cbLength);
  96. }
  97. hr = S_OK;
  98. break;
  99. }
  100. }
  101. }
  102. DebugExitHRESULT(CRosterInfo::ExtractItem, hr);
  103. return hr;
  104. }
  105. HRESULT CRosterInfo::Load(PVOID pData)
  106. {
  107. DebugEntry(CRosterInfo::Load);
  108. HRESULT hr = E_FAIL;
  109. PWSTR pwszUserInfo = (PWSTR) pData;
  110. if (NULL != pwszUserInfo)
  111. {
  112. hr = S_OK;
  113. while (L'\0' != pwszUserInfo[0])
  114. {
  115. // this includes the null terminator
  116. int nItemLenNT = lstrlenW(pwszUserInfo) + 1;
  117. PWSTR pwszNewItem = new WCHAR[nItemLenNT];
  118. if (NULL != pwszNewItem)
  119. {
  120. ::CopyMemory( pwszNewItem,
  121. pwszUserInfo,
  122. sizeof(WCHAR) * nItemLenNT);
  123. m_ItemList.AddTail(pwszNewItem);
  124. // Skip past this item and the n.t.
  125. pwszUserInfo += nItemLenNT;
  126. }
  127. else
  128. {
  129. hr = E_OUTOFMEMORY;
  130. break;
  131. }
  132. }
  133. }
  134. else
  135. {
  136. TRACE_OUT(("CRosterInfo::Load() called with NULL pData"));
  137. }
  138. DebugExitHRESULT(CRosterInfo::Load, hr);
  139. return hr;
  140. }
  141. UINT CRosterInfo::GetSize()
  142. {
  143. UINT uSize = sizeof(WCHAR); // for last separator
  144. POSITION pos = m_ItemList.GetHeadPosition();
  145. while (NULL != pos)
  146. {
  147. PWSTR pwszItem = (PWSTR) m_ItemList.GetNext(pos);
  148. ASSERT(pwszItem);
  149. uSize += sizeof(WCHAR) * (lstrlenW(pwszItem) + 1);
  150. }
  151. return uSize;
  152. }
  153. HRESULT CRosterInfo::Save(PVOID* ppvData, PUINT pcbLength)
  154. {
  155. DebugEntry(CRosterInfo::Save);
  156. ASSERT(ppvData);
  157. ASSERT(pcbLength);
  158. HRESULT hr = E_FAIL;
  159. *pcbLength = GetSize();
  160. delete m_pvSaveData;
  161. m_pvSaveData = new BYTE[*pcbLength];
  162. if (NULL != m_pvSaveData)
  163. {
  164. PWSTR pwszDest = (PWSTR) m_pvSaveData;
  165. POSITION pos = m_ItemList.GetHeadPosition();
  166. while (NULL != pos)
  167. {
  168. PWSTR pwszItem = (PWSTR) m_ItemList.GetNext(pos);
  169. ASSERT(pwszItem);
  170. ::CopyMemory( pwszDest,
  171. pwszItem,
  172. sizeof(WCHAR) * (lstrlenW(pwszItem) + 1));
  173. pwszDest += (lstrlenW(pwszItem) + 1);
  174. }
  175. int nLastSepPos = (*pcbLength / sizeof(WCHAR)) - 1;
  176. ((PWSTR)m_pvSaveData)[nLastSepPos] = g_cwchRostInfoSeparator;
  177. *ppvData = m_pvSaveData;
  178. hr = S_OK;
  179. }
  180. DebugExitHRESULT(CRosterInfo::Save, hr);
  181. return hr;
  182. }
  183. #ifdef DEBUG
  184. VOID CRosterInfo::Dump()
  185. {
  186. POSITION pos = m_ItemList.GetHeadPosition();
  187. while (NULL != pos)
  188. {
  189. PWSTR pwszItem = (PWSTR) m_ItemList.GetNext(pos);
  190. ASSERT(pwszItem);
  191. TRACE_OUT(("\t%ls", pwszItem));
  192. }
  193. }
  194. #endif // DEBUG
  195.