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.

407 lines
10 KiB

  1. #include "precomp.h"
  2. #include "fsdiag.h"
  3. DEBUG_FILEZONE(ZONE_T120_UTILITY);
  4. /*
  5. * capid.cpp
  6. *
  7. * Copyright (c) 1995 by DataBeam Corporation, Lexington, KY
  8. *
  9. * Abstract:
  10. * This is the implementation file for the class CCapIDContainer.
  11. * A CCapIDContainer object is used to maintain information about
  12. * a particular capability of an application. A capability identifier can
  13. * be either a standard type or a non-standard type. When the type is
  14. * standard, the identifier is stored internally as an integer value. When
  15. * the type is non-standard, an CObjectKeyContainer container object is used
  16. * internally to buffer the necessary data. In this case the identifier
  17. * data may exist as an Object ID which is a series of non-negative
  18. * integers or an H221 non-standard ID which is an octet string of no fewer
  19. * than four octets and no more than 255 octets.
  20. *
  21. * Protected Instance Variables:
  22. * m_InternalCapID
  23. * Structure used to hold the capability ID data internally.
  24. * m_CapIDPDU
  25. * Storage for the "PDU" form of the capability ID.
  26. * m_fValidCapIDPDU
  27. * Flag indicating that memory has been allocated to hold the internal
  28. * "PDU" capability ID.
  29. * m_cbDataSize
  30. * Variable holding the size of the memory which will be required to
  31. * hold any data referenced by the "API" GCCCapabilityID structure.
  32. *
  33. * Caveats:
  34. * None.
  35. *
  36. * Author:
  37. * blp/jbo
  38. */
  39. #include "capid.h"
  40. /*
  41. * CCapIDContainer()
  42. *
  43. * Public Function Description:
  44. * This constructor is used to create a CCapIDContainer object
  45. * from an "API" GCCCapabilityID.
  46. */
  47. CCapIDContainer::
  48. CCapIDContainer(PGCCCapabilityID capability_id, PGCCError pRetCode)
  49. :
  50. CRefCount(MAKE_STAMP_ID('C','a','p','I')),
  51. m_fValidCapIDPDU(FALSE),
  52. m_cbDataSize(0)
  53. {
  54. GCCError rc = GCC_NO_ERROR;
  55. if (capability_id == NULL)
  56. {
  57. rc = GCC_INVALID_PARAMETER;
  58. }
  59. else
  60. {
  61. /*
  62. * Save the GCCCapabilityID in the internal information structure.
  63. */
  64. m_InternalCapID.capability_id_type = capability_id->capability_id_type;
  65. if (capability_id->capability_id_type == GCC_STANDARD_CAPABILITY)
  66. {
  67. m_InternalCapID.u.standard_capability = (USHORT) capability_id->standard_capability;
  68. }
  69. else
  70. {
  71. /*
  72. * The object key portion of the capability ID is saved in an
  73. * CObjectKeyContainer object.
  74. */
  75. DBG_SAVE_FILE_LINE
  76. m_InternalCapID.u.non_standard_capability =
  77. new CObjectKeyContainer(&capability_id->non_standard_capability, &rc);
  78. if (m_InternalCapID.u.non_standard_capability == NULL)
  79. {
  80. rc = GCC_ALLOCATION_FAILURE;
  81. }
  82. else if (rc == GCC_BAD_OBJECT_KEY)
  83. {
  84. rc = GCC_BAD_CAPABILITY_ID;
  85. }
  86. }
  87. }
  88. *pRetCode = rc;
  89. }
  90. /*
  91. * CCapIDContainer()
  92. *
  93. * Public Function Description:
  94. * This constructor is used to create a CapabilityIdentifier object from
  95. * a "PDU" CapabilityID.
  96. */
  97. CCapIDContainer::
  98. CCapIDContainer(PCapabilityID capability_id, PGCCError pRetCode)
  99. :
  100. CRefCount(MAKE_STAMP_ID('C','a','p','I')),
  101. m_fValidCapIDPDU(FALSE),
  102. m_cbDataSize(0)
  103. {
  104. GCCError rc = GCC_NO_ERROR;
  105. if (capability_id->choice == STANDARD_CHOSEN)
  106. {
  107. m_InternalCapID.capability_id_type = GCC_STANDARD_CAPABILITY;
  108. m_InternalCapID.u.standard_capability = capability_id->u.standard;
  109. }
  110. else
  111. {
  112. m_InternalCapID.capability_id_type = GCC_NON_STANDARD_CAPABILITY;
  113. DBG_SAVE_FILE_LINE
  114. m_InternalCapID.u.non_standard_capability =
  115. new CObjectKeyContainer(&capability_id->u.capability_non_standard, &rc);
  116. if (m_InternalCapID.u.non_standard_capability == NULL)
  117. {
  118. rc = GCC_ALLOCATION_FAILURE;
  119. }
  120. else if (rc == GCC_BAD_OBJECT_KEY)
  121. {
  122. rc = GCC_BAD_CAPABILITY_ID;
  123. }
  124. }
  125. *pRetCode = rc;
  126. }
  127. /*
  128. * CCapIDContainer()
  129. *
  130. * Public Function Description:
  131. * This copy constructor is used to create a new CCapIDContainer
  132. * object from another CCapIDContainer object.
  133. */
  134. CCapIDContainer::
  135. CCapIDContainer(CCapIDContainer *capability_id, PGCCError pRetCode)
  136. :
  137. CRefCount(MAKE_STAMP_ID('C','a','p','I')),
  138. m_fValidCapIDPDU(FALSE),
  139. m_cbDataSize(0)
  140. {
  141. GCCError rc = GCC_NO_ERROR;
  142. m_InternalCapID = capability_id->m_InternalCapID;
  143. if (m_InternalCapID.capability_id_type == GCC_NON_STANDARD_CAPABILITY)
  144. {
  145. DBG_SAVE_FILE_LINE
  146. m_InternalCapID.u.non_standard_capability =
  147. new CObjectKeyContainer(capability_id->m_InternalCapID.u.non_standard_capability, &rc);
  148. if (m_InternalCapID.u.non_standard_capability == NULL)
  149. {
  150. rc = GCC_ALLOCATION_FAILURE;
  151. }
  152. else if (rc == GCC_BAD_OBJECT_KEY)
  153. {
  154. rc = GCC_BAD_CAPABILITY_ID;
  155. }
  156. }
  157. *pRetCode = rc;
  158. }
  159. /*
  160. * ~CCapIDContainer()
  161. *
  162. * Public Function Description
  163. * The CCapIDContainer destructor is responsible for freeing any
  164. * memory allocated to hold the capability ID data for both the "API" and
  165. * "PDU" forms.
  166. *
  167. */
  168. CCapIDContainer::~CCapIDContainer(void)
  169. {
  170. /*
  171. * If "PDU" data has been allocated for this object, free it now.
  172. */
  173. if (m_fValidCapIDPDU)
  174. FreeCapabilityIdentifierDataPDU ();
  175. /*
  176. * Delete any object key data held internally.
  177. */
  178. if (m_InternalCapID.capability_id_type == GCC_NON_STANDARD_CAPABILITY)
  179. {
  180. if (NULL != m_InternalCapID.u.non_standard_capability)
  181. {
  182. m_InternalCapID.u.non_standard_capability->Release();
  183. }
  184. }
  185. }
  186. /*
  187. * LockCapabilityIdentifierData ()
  188. *
  189. * Public Function Description:
  190. * This routine locks the capability ID data and determines the amount of
  191. * memory referenced by the "API" capability ID structure.
  192. */
  193. UINT CCapIDContainer::LockCapabilityIdentifierData(void)
  194. {
  195. /*
  196. * If this is the first time this routine is called, determine the size of
  197. * the memory required to hold the data referenced by the capability ID
  198. * structure. Otherwise, just increment the lock count.
  199. */
  200. if (Lock() == 1)
  201. {
  202. m_cbDataSize = 0;
  203. if (m_InternalCapID.capability_id_type == GCC_NON_STANDARD_CAPABILITY)
  204. {
  205. m_cbDataSize = m_InternalCapID.u.non_standard_capability->LockObjectKeyData ();
  206. }
  207. }
  208. return m_cbDataSize;
  209. }
  210. /*
  211. * GetGCCCapabilityIDData ()
  212. *
  213. * Public Function Description:
  214. * This routine retrieves capability ID data in the form of a
  215. * GCCCapabilityID. This routine is called after "locking" the capability
  216. * ID data.
  217. */
  218. UINT CCapIDContainer::GetGCCCapabilityIDData(
  219. PGCCCapabilityID capability_id,
  220. LPBYTE memory)
  221. {
  222. UINT cbDataSizeToRet = 0;
  223. if (GetLockCount() > 0)
  224. {
  225. /*
  226. * Fill in the output parameter which indicates the amount of memory
  227. * used to hold all of the data associated with the capability ID.
  228. */
  229. cbDataSizeToRet = m_cbDataSize;
  230. /*
  231. * Fill in the "API" capability ID from the internal structure. If an
  232. * object key exists, get the object key data by calling the "Get"
  233. * routine of the internal CObjectKeyContainer object.
  234. */
  235. capability_id->capability_id_type = m_InternalCapID.capability_id_type;
  236. if (m_InternalCapID.capability_id_type == GCC_STANDARD_CAPABILITY)
  237. {
  238. capability_id->standard_capability = m_InternalCapID.u.standard_capability;
  239. }
  240. else
  241. {
  242. /*
  243. * The call to get the object key data returns the amount of data
  244. * written into memory. We do not need this value right now.
  245. */
  246. m_InternalCapID.u.non_standard_capability->
  247. GetGCCObjectKeyData(
  248. &capability_id->non_standard_capability,
  249. memory);
  250. }
  251. }
  252. else
  253. {
  254. ERROR_OUT(("CCapIDContainer::GetGCCCapabilityIDData: Error data not locked"));
  255. }
  256. return (cbDataSizeToRet);
  257. }
  258. /*
  259. * UnlockCapabilityIdentifierData ()
  260. *
  261. * Public Function Description:
  262. * This routine decrements the internal lock count and frees the memory
  263. * associated with the "API" capability ID when the lock count hits zero.
  264. */
  265. void CCapIDContainer::UnLockCapabilityIdentifierData(void)
  266. {
  267. if (Unlock(FALSE) == 0)
  268. {
  269. if (m_InternalCapID.capability_id_type == GCC_NON_STANDARD_CAPABILITY)
  270. {
  271. m_InternalCapID.u.non_standard_capability->UnLockObjectKeyData();
  272. }
  273. }
  274. // we have to call Release() because we used Unlock(FALSE)
  275. Release();
  276. }
  277. /*
  278. * GetCapabilityIdentifierDataPDU ()
  279. *
  280. * Public Function Description:
  281. * This routine converts the capability ID from it's internal form of an
  282. * CAP_ID_STRUCT structure into the "PDU" form which can be
  283. * passed in to the ASN.1 encoder. A pointer to a "PDU" "CapabilityID"
  284. * structure is returned.
  285. */
  286. GCCError CCapIDContainer::GetCapabilityIdentifierDataPDU(PCapabilityID capability_id)
  287. {
  288. GCCError rc = GCC_NO_ERROR;
  289. /*
  290. * If this is the first time that PDU data has been requested then we must
  291. * fill in the internal PDU structure and copy it into the structure pointed
  292. * to by the output parameter. On subsequent calls to "GetPDU" we can just
  293. * copy the internal PDU structure into the structure pointed to by the
  294. * output parameter.
  295. */
  296. if (m_fValidCapIDPDU == FALSE)
  297. {
  298. m_fValidCapIDPDU = TRUE;
  299. if (m_InternalCapID.capability_id_type== GCC_STANDARD_CAPABILITY)
  300. {
  301. m_CapIDPDU.choice = STANDARD_CHOSEN;
  302. m_CapIDPDU.u.standard = m_InternalCapID.u.standard_capability;
  303. }
  304. else
  305. {
  306. m_CapIDPDU.choice = CAPABILITY_NON_STANDARD_CHOSEN;
  307. rc = m_InternalCapID.u.non_standard_capability->
  308. GetObjectKeyDataPDU(&m_CapIDPDU.u.capability_non_standard);
  309. }
  310. }
  311. /*
  312. * Copy the internal PDU structure into the structure pointed to by the
  313. * output parameter.
  314. */
  315. *capability_id = m_CapIDPDU;
  316. return rc;
  317. }
  318. /*
  319. * FreeCapabilityIdentifierDataPDU ()
  320. *
  321. * Public Function Description:
  322. * This routine is used to free the capability ID data held internally in
  323. * the "PDU" form of a "CapabilityID".
  324. */
  325. void CCapIDContainer::FreeCapabilityIdentifierDataPDU(void)
  326. {
  327. if (m_fValidCapIDPDU)
  328. {
  329. /*
  330. * Set the flag indicating that PDU session key data is no longer
  331. * allocated.
  332. */
  333. m_fValidCapIDPDU = FALSE;
  334. if (m_CapIDPDU.choice == CAPABILITY_NON_STANDARD_CHOSEN)
  335. {
  336. m_InternalCapID.u.non_standard_capability->FreeObjectKeyDataPDU();
  337. }
  338. }
  339. }
  340. /*
  341. * operator== ()
  342. *
  343. * Public Function Description:
  344. * This routine is used to determine whether or not two Capibility ID's
  345. * are equal in value.
  346. */
  347. BOOL operator==(const CCapIDContainer& capability_id_1, const CCapIDContainer& capability_id_2)
  348. {
  349. BOOL rc = FALSE;
  350. if (capability_id_1.m_InternalCapID.capability_id_type ==
  351. capability_id_2.m_InternalCapID.capability_id_type)
  352. {
  353. if (capability_id_1.m_InternalCapID.capability_id_type ==
  354. GCC_STANDARD_CAPABILITY)
  355. {
  356. if (capability_id_1.m_InternalCapID.u.standard_capability ==
  357. capability_id_2.m_InternalCapID.u.standard_capability)
  358. {
  359. rc = TRUE;
  360. }
  361. }
  362. else
  363. {
  364. if (*capability_id_1.m_InternalCapID.u.non_standard_capability ==
  365. *capability_id_2.m_InternalCapID.u.non_standard_capability)
  366. {
  367. rc = TRUE;
  368. }
  369. }
  370. }
  371. return rc;
  372. }