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.

234 lines
5.5 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. #include "confutil.h"
  16. GUID g_csguidRostInfo = GUID_ROSTINFO;
  17. static const HROSTINFO g_cshriEOList = (HROSTINFO)((LONG_PTR)-1);
  18. CRosterInfo::~CRosterInfo()
  19. {
  20. DebugEntry(CRosterInfo::~CRosterInfo);
  21. while (FALSE == m_ItemList.IsEmpty())
  22. {
  23. PWSTR pwszItem = (PWSTR) m_ItemList.RemoveHead();
  24. ASSERT(pwszItem);
  25. delete pwszItem;
  26. }
  27. delete m_pvSaveData;
  28. DebugExitVOID(CRosterInfo::~CRosterInfo);
  29. }
  30. HRESULT CRosterInfo::AddItem(PCWSTR pcwszTag, PCWSTR pcwszData)
  31. {
  32. DebugEntry(CRosterInfo::AddItem);
  33. ASSERT(pcwszTag);
  34. ASSERT(pcwszData);
  35. HRESULT hr = E_OUTOFMEMORY;
  36. int nTagLength = lstrlenW(pcwszTag);
  37. int nDataLength = lstrlenW(pcwszData);
  38. // +1 for tag sep, +1 for rost info sep
  39. PWSTR pwszNewItem = new WCHAR[nTagLength + 1 + nDataLength + 1];
  40. if (NULL != pwszNewItem)
  41. {
  42. ::CopyMemory( (PVOID) pwszNewItem,
  43. pcwszTag,
  44. sizeof(WCHAR) * nTagLength);
  45. pwszNewItem[nTagLength] = g_cwchRostInfoTagSeparator;
  46. ::CopyMemory( (PVOID) &(pwszNewItem[nTagLength + 1]),
  47. pcwszData,
  48. sizeof(WCHAR) * nDataLength);
  49. pwszNewItem[nTagLength + 1 + nDataLength] = g_cwchRostInfoSeparator;
  50. m_ItemList.AddTail(pwszNewItem);
  51. hr = S_OK;
  52. }
  53. DebugExitHRESULT(CRosterInfo::AddItem, hr);
  54. return hr;
  55. }
  56. HRESULT CRosterInfo::ExtractItem( PHROSTINFO phRostInfo,
  57. PCWSTR pcwszTag,
  58. LPTSTR pszBuffer,
  59. UINT cbLength)
  60. {
  61. DebugEntry(CRosterInfo::ExtractItem);
  62. ASSERT(pcwszTag);
  63. HRESULT hr = E_FAIL;
  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. LPTSTR szName;
  96. BSTR bstrItem = ::SysAllocString(&pwszItem[nTagLength + 1]);
  97. if(bstrItem)
  98. {
  99. hr = BSTR_to_LPTSTR (&szName,bstrItem);
  100. if (SUCCEEDED(hr))
  101. {
  102. lstrcpyn(pszBuffer, szName, cbLength);
  103. delete szName;
  104. }
  105. SysFreeString(bstrItem);
  106. }
  107. }
  108. hr = S_OK;
  109. break;
  110. }
  111. }
  112. }
  113. DebugExitHRESULT(CRosterInfo::ExtractItem, hr);
  114. return hr;
  115. }
  116. HRESULT CRosterInfo::Load(PVOID pData)
  117. {
  118. DebugEntry(CRosterInfo::Load);
  119. HRESULT hr = E_FAIL;
  120. PWSTR pwszUserInfo = (PWSTR) pData;
  121. if (NULL != pwszUserInfo)
  122. {
  123. hr = S_OK;
  124. while (L'\0' != pwszUserInfo[0])
  125. {
  126. // this includes the null terminator
  127. int nItemLenNT = lstrlenW(pwszUserInfo) + 1;
  128. PWSTR pwszNewItem = new WCHAR[nItemLenNT];
  129. if (NULL != pwszNewItem)
  130. {
  131. ::CopyMemory( pwszNewItem,
  132. pwszUserInfo,
  133. sizeof(WCHAR) * nItemLenNT);
  134. m_ItemList.AddTail(pwszNewItem);
  135. // Skip past this item and the n.t.
  136. pwszUserInfo += nItemLenNT;
  137. }
  138. else
  139. {
  140. hr = E_OUTOFMEMORY;
  141. break;
  142. }
  143. }
  144. }
  145. else
  146. {
  147. TRACE_OUT(("CRosterInfo::Load() called with NULL pData"));
  148. }
  149. DebugExitHRESULT(CRosterInfo::Load, hr);
  150. return hr;
  151. }
  152. UINT CRosterInfo::GetSize()
  153. {
  154. UINT uSize = sizeof(WCHAR); // for last separator
  155. POSITION pos = m_ItemList.GetHeadPosition();
  156. while (NULL != pos)
  157. {
  158. PWSTR pwszItem = (PWSTR) m_ItemList.GetNext(pos);
  159. ASSERT(pwszItem);
  160. uSize += sizeof(WCHAR) * (lstrlenW(pwszItem) + 1);
  161. }
  162. return uSize;
  163. }
  164. HRESULT CRosterInfo::Save(PVOID* ppvData, PUINT pcbLength)
  165. {
  166. DebugEntry(CRosterInfo::Save);
  167. ASSERT(ppvData);
  168. ASSERT(pcbLength);
  169. HRESULT hr = E_FAIL;
  170. *pcbLength = GetSize();
  171. delete m_pvSaveData;
  172. m_pvSaveData = new BYTE[*pcbLength];
  173. if (NULL != m_pvSaveData)
  174. {
  175. PWSTR pwszDest = (PWSTR) m_pvSaveData;
  176. POSITION pos = m_ItemList.GetHeadPosition();
  177. while (NULL != pos)
  178. {
  179. PWSTR pwszItem = (PWSTR) m_ItemList.GetNext(pos);
  180. ASSERT(pwszItem);
  181. ::CopyMemory( pwszDest,
  182. pwszItem,
  183. sizeof(WCHAR) * (lstrlenW(pwszItem) + 1));
  184. pwszDest += (lstrlenW(pwszItem) + 1);
  185. }
  186. int nLastSepPos = (*pcbLength / sizeof(WCHAR)) - 1;
  187. ((PWSTR)m_pvSaveData)[nLastSepPos] = g_cwchRostInfoSeparator;
  188. *ppvData = m_pvSaveData;
  189. hr = S_OK;
  190. }
  191. DebugExitHRESULT(CRosterInfo::Save, hr);
  192. return hr;
  193. }
  194. #ifdef DEBUG
  195. VOID CRosterInfo::Dump()
  196. {
  197. POSITION pos = m_ItemList.GetHeadPosition();
  198. while (NULL != pos)
  199. {
  200. PWSTR pwszItem = (PWSTR) m_ItemList.GetNext(pos);
  201. ASSERT(pwszItem);
  202. TRACE_OUT(("\t%ls", pwszItem));
  203. }
  204. }
  205. #endif // DEBUG
  206.