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.

262 lines
6.5 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 <cuserdta.hpp>
  7. #include <oprahcom.h>
  8. #include <inodecnt.h>
  9. static const BYTE H221IDGUID[5] =
  10. {
  11. H221GUIDKEY0,
  12. H221GUIDKEY1,
  13. H221GUIDKEY2,
  14. H221GUIDKEY3,
  15. H221GUIDKEY4
  16. };
  17. CNCUserDataList::
  18. CNCUserDataList(void)
  19. :
  20. CList(),
  21. m_apUserData(NULL)
  22. {
  23. }
  24. CNCUserDataList::
  25. ~CNCUserDataList(void)
  26. {
  27. delete[] m_apUserData;
  28. GCCUserData *pUserData;
  29. Reset();
  30. while (NULL != (pUserData = Iterate()))
  31. {
  32. delete pUserData->octet_string->value;
  33. delete pUserData->octet_string;
  34. delete pUserData;
  35. }
  36. }
  37. HRESULT CNCUserDataList::
  38. AddUserData
  39. (
  40. GUID *pGUID,
  41. UINT nData,
  42. LPVOID pData
  43. )
  44. {
  45. ASSERT(pGUID);
  46. ASSERT(!nData || pData);
  47. LPBYTE pWork;
  48. UINT nDataPlusHeader = nData+sizeof(GUID);
  49. GCCUserData * pUserData;
  50. LPOSTR pOctetString;
  51. // If there is already an entry in the list
  52. // for the GUID, then delete it.
  53. DeleteEntry(pGUID);
  54. // Make sure the size is reasonable
  55. if (nDataPlusHeader <= 0xffff)
  56. {
  57. // Now go and add the new entry to the list.
  58. DBG_SAVE_FILE_LINE
  59. if (NULL != (pUserData = new GCCUserData))
  60. {
  61. DBG_SAVE_FILE_LINE
  62. if (NULL != (pOctetString = new OSTR))
  63. {
  64. DBG_SAVE_FILE_LINE
  65. if (NULL != (pWork = new unsigned char[nDataPlusHeader]))
  66. {
  67. pUserData->octet_string = pOctetString;
  68. pUserData->key.key_type = GCC_H221_NONSTANDARD_KEY;
  69. pUserData->key.h221_non_standard_id.length = sizeof(H221IDGUID);
  70. pUserData->key.h221_non_standard_id.value = (LPBYTE) &H221IDGUID[0];
  71. pOctetString->value = pWork;
  72. pOctetString->length = nDataPlusHeader;
  73. *(GUID *)pWork = *pGUID;
  74. pWork += sizeof(GUID);
  75. ::CopyMemory(pWork, pData, nData);
  76. Append(pUserData);
  77. return NO_ERROR;
  78. }
  79. delete pOctetString;
  80. }
  81. delete pUserData;
  82. }
  83. }
  84. return UI_RC_OUT_OF_MEMORY;
  85. }
  86. void CNCUserDataList::
  87. DeleteEntry ( GUID * pGUID )
  88. {
  89. GCCUserData *pUserData;
  90. Reset();
  91. while (NULL != (pUserData = Iterate()))
  92. {
  93. if (0 == ::memcmp(pUserData->octet_string->value, pGUID, sizeof(GUID)))
  94. {
  95. Remove(pUserData);
  96. delete pUserData->octet_string->value;
  97. delete pUserData->octet_string;
  98. delete pUserData;
  99. return;
  100. }
  101. }
  102. }
  103. GCCUserData * CNCUserDataList::
  104. GetUserGUIDData (GUID * pGUID)
  105. {
  106. GCCUserData *pUserData;
  107. Reset();
  108. while (NULL != (pUserData = Iterate()))
  109. {
  110. if (0 == ::memcmp(pUserData->octet_string->value, pGUID, sizeof(GUID)))
  111. {
  112. return pUserData;
  113. }
  114. }
  115. return NULL;
  116. }
  117. HRESULT CNCUserDataList::
  118. GetUserDataList
  119. (
  120. UINT *pnRecords,
  121. GCCUserData ***papUserData
  122. )
  123. {
  124. GCCUserData ** pUserDataArrayTemp;
  125. HRESULT hr = NO_ERROR;
  126. delete[] m_apUserData;
  127. m_apUserData = NULL;
  128. if (! IsEmpty())
  129. {
  130. // Allocate memory.
  131. DBG_SAVE_FILE_LINE
  132. if (NULL != (m_apUserData = new GCCUserData * [GetCount()]))
  133. {
  134. // Fill in array.
  135. GCCUserData *pUserData;
  136. pUserDataArrayTemp = m_apUserData;
  137. Reset();
  138. while (NULL != (pUserData = Iterate()))
  139. {
  140. *(pUserDataArrayTemp++) = pUserData;
  141. }
  142. }
  143. else
  144. {
  145. hr = UI_RC_OUT_OF_MEMORY;
  146. }
  147. }
  148. *pnRecords = GetCount();
  149. *papUserData = m_apUserData;
  150. return hr;
  151. }
  152. HRESULT NMINTERNAL
  153. GetUserData
  154. (
  155. UINT nRecords,
  156. GCCUserData ** ppUserData,
  157. GUID * pGUID,
  158. UINT * pnData,
  159. LPVOID * ppData
  160. )
  161. {
  162. LPBYTE pData;
  163. UINT nLength;
  164. while (nRecords--)
  165. {
  166. // Check that the H.221 OID is for GUIDS.
  167. if (((*ppUserData)->key.key_type == GCC_H221_NONSTANDARD_KEY) &&
  168. ((*ppUserData)->key.h221_non_standard_id.length == sizeof(H221IDGUID)) &&
  169. (memcmp((*ppUserData)->key.h221_non_standard_id.value,
  170. H221IDGUID,
  171. sizeof(H221IDGUID)) == 0) ||
  172. ((*ppUserData)->key.key_type == GCC_OBJECT_KEY) &&
  173. ((*ppUserData)->key.object_id.long_string_length == 3) &&
  174. ((*ppUserData)->key.object_id.long_string[0] == 2) &&
  175. ((*ppUserData)->key.object_id.long_string[1] == 5) &&
  176. ((*ppUserData)->key.object_id.long_string[2] == 8))
  177. {
  178. nLength = (*ppUserData)->octet_string->length;
  179. pData = (*ppUserData)->octet_string->value;
  180. if (nLength >= sizeof(GUID))
  181. {
  182. if (CompareGuid((GUID *)pData, pGUID) == 0)
  183. {
  184. nLength -= sizeof(GUID);
  185. if (nLength)
  186. {
  187. pData += sizeof(GUID);
  188. }
  189. else
  190. {
  191. pData = NULL;
  192. }
  193. if (pnData)
  194. {
  195. *pnData = nLength;
  196. }
  197. if (ppData)
  198. {
  199. *ppData = (PVOID)pData;
  200. }
  201. return NO_ERROR;
  202. }
  203. }
  204. }
  205. ppUserData++;
  206. }
  207. return UI_RC_NO_SUCH_USER_DATA;
  208. }
  209. // Create an H.221 application key with a guid
  210. VOID CreateH221AppKeyFromGuid(LPBYTE lpb, GUID * pguid)
  211. {
  212. CopyMemory(lpb, H221IDGUID, sizeof(H221IDGUID));
  213. CopyMemory(lpb + sizeof(H221IDGUID), pguid, sizeof(GUID));
  214. }
  215. // Return TRUE if the guid string was extracted from the key
  216. BOOL GetGuidFromH221AppKey(LPTSTR pszGuid, LPOSTR pOctStr)
  217. {
  218. ASSERT(NULL != pszGuid);
  219. ASSERT(NULL != pOctStr);
  220. if (pOctStr->length < (sizeof(H221IDGUID) + sizeof(GUID)) )
  221. return FALSE;
  222. if (memcmp(pOctStr->value, H221IDGUID, sizeof(H221IDGUID)) != 0)
  223. return FALSE;
  224. GuidToSz((GUID *) (((LPBYTE) pOctStr->value)+ sizeof(H221IDGUID)), pszGuid);
  225. return TRUE;
  226. }