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.

6001 lines
173 KiB

  1. #include "precomp.h"
  2. DEBUG_FILEZONE(ZONE_T120_MCSNC);
  3. /*
  4. * domain.cpp
  5. *
  6. * Copyright (c) 1993 - 1995 by DataBeam Corporation, Lexington, KY
  7. *
  8. * Abstract:
  9. * This is the implementation file for the domain class. The domain
  10. * class encapsulates a single instance of a domain information base.
  11. * This class include all code necessary to modify and act upon that
  12. * information base. Almost all activity into and out of objects of
  13. * this class is in the form of MCS commands. These commands are
  14. * implemented as virtual member functions that are inherited from its
  15. * base class CommandTarget. These commands are essentially the same
  16. * as the Protocol Data Units (PDUs) defined in T.125.
  17. *
  18. * This class inherits from CommandTarget, which is where the virtual
  19. * member functions for each command is defined. All commands that are
  20. * handled by this class are overridden by it. Life for a domain object
  21. * consists of receiving these commands and responding by transmitting
  22. * these commands. A Domain object has no need for its own "thread" of
  23. * execution.
  24. *
  25. * Instances of the domain class maintain an information base that is
  26. * used to determine how to respond to these commands. The commands are
  27. * not only routed according to the state of the information base, but also
  28. * act to change the information base. When two MCS providers are
  29. * connected, the domain objects within them become logically linked. This
  30. * means that they exchange these commands in such a manner as to guarantee
  31. * the MCS services for which the providers are responsible.
  32. *
  33. * When a domain object is first instantiated, its information base is
  34. * empty. That is, it has no user attachments, no MCS connections, no
  35. * channels, no tokens, and no queued requests. As the domain object
  36. * processes commands, the information base takes shape, and all subsequent
  37. * activity follows that shape.
  38. *
  39. * By necessity, there is a lot of complex code in this module. This is to
  40. * allow for all the timing problems that can occur in a distributed
  41. * network, such as MCS provides for. In order to reduce the complexity
  42. * as much as possible, this class does NOT worry about certains things,
  43. * as follows:
  44. *
  45. * The Domain class does NOT include code to perform any kind of flow
  46. * control. When a send data command comes in to a domain, it is sent out
  47. * to any attachment that is to receive it. It is assumed that any
  48. * buffering and flow control is handled by the attachments.
  49. *
  50. * For the most part the domain class does NOT distinguish between user
  51. * attachments and MCS connections. To the domain, they are merely
  52. * referred to as "attachments". MCS connections can be either upward or
  53. * downward attachments. User attachments can only be downward
  54. * attachments. In the case where a user detaches and the domain needs to
  55. * know if the whole attachment is gone or just one user, it can check an
  56. * entry in its attachment dictionary to determine the type. Most of the
  57. * time it does not care. Most confirms and indications are routed to user
  58. * attachments in exactly the same way they are routed to MCS connections.
  59. *
  60. * Domain objects do not worry about memory management. They merely pass
  61. * packet objects from place to place. They NEVER look at the contents
  62. * of the packet objects. It is assumed that the attachments have
  63. * allocated memory for the user data that is being passed around.
  64. *
  65. * Where possible, behavior that is specific to channels and tokens has
  66. * been relegated to those classes. It is necessary for the domain to
  67. * handle channel and token behavior for IDs that do not exist.
  68. *
  69. * Private Instance Variables:
  70. * Merge_State
  71. * This is current merge state that the domain is in. These states
  72. * are detailed in "domain.h".
  73. * Outstanding_Merge_Requests
  74. * This is a counter showing the number of outstanding merge requests.
  75. * The domain object uses this to know when an in-process merge is
  76. * complete.
  77. * Number_Of_Users
  78. * This is the number of users in the domain.
  79. * Number_Of_Channels
  80. * This is the number of channels in the domain.
  81. * Number_Of_Tokens
  82. * This is the number of tokens in the domain.
  83. * Domain_Parameters
  84. * This is a structure that contains the currently negotiated domain
  85. * parameters. These parameters are used to validate requests, such
  86. * as the adding of a new user.
  87. * Domain_Parameters_Locked
  88. * This is a boolean flag that indicates whether or not the domain
  89. * parameters have been locked into place yet. This locking will
  90. * occur when the domain object accepts its first MCS connection.
  91. * m_pConnToTopProvider
  92. * This is a pointer to the attachment that represents the link to the
  93. * top provider. Note that this provider may be several hops away
  94. * from the top provider, so this really just points in the direction
  95. * of the top provider. If this pointer is NULL, this THIS is the
  96. * top provider.
  97. * m_AttachmentList
  98. * This is a list of the downward attachments that this domain is
  99. * aware of. Remeber that this list can contain any combination of
  100. * user attachments and MCS connections. They are treated equally
  101. * for most things.
  102. * m_AttachUserQueue
  103. * This is a list of outstanding attach user requests. It is necessary
  104. * to remember these requests so that they can answered in the same
  105. * order in which they arrived.
  106. * m_MergeQueue
  107. * During a merge operation, this queue is used to remember how to
  108. * route merge confirms back to their originators. The assumption is
  109. * made that an upward provider will always respond to merge requests
  110. * in the same order that they were received in (a valid assumption
  111. * for our implementation). Also note that this implementation
  112. * currently only merges one resource type at a time, so only one queue
  113. * is necessary. For example, user IDs are merged, then static
  114. * channels, and so on.
  115. * m_ChannelList2
  116. * This is a list of channel objects that correspond to active channels
  117. * within this domain. When a channel object exists, the domain lets
  118. * it handle all channel related activity (such as approving who can
  119. * join a channel).
  120. * m_TokenList2
  121. * This is a list of token objects that correspond to active tokens
  122. * within this domain. When a token object exists, the domain lets it
  123. * handle all token related activity (such as approving who can inhibit
  124. * the token).
  125. * m_nDomainHeight
  126. * This instance variable contains the height of the domain from the
  127. * point-of-view of this provider. If there are two layers of
  128. * providers below this one, then the height will be two.
  129. * m_DomainHeightList2
  130. * This is a list of domain heights that were registered from all
  131. * downward attachments. This allows the current provider to
  132. * automatically update domain height when a downward attachment is
  133. * lost.
  134. * Random_Channel_Generator
  135. * This object is used by this domain to generate random channel IDs.
  136. *
  137. * Private Member Functions:
  138. * LockDomainParameters
  139. * This member function is used to change the values of the locally
  140. * maintained domain parameters structure. Passing NULL to it causes
  141. * it to set a default set of parameters. The second parameter allows
  142. * the caller to specify whether or not these new parameters are
  143. * "locked" into the domain (meaning that they cannot change since they
  144. * have been locked in by acceptance of the first connection).
  145. * AllocateDynamicChannel
  146. * This routine randomly selects a channel ID from the dynamic range.
  147. * ValidateUserID
  148. * This routine checks to see if the specified user is in the sub-tree
  149. * of this domain. It can optionally check to see if the user is at
  150. * a specific attachment in the sub-tree.
  151. * PurgeDomain
  152. * This routine purges the entire domain. This means terminating all
  153. * attachments, and freeing up all resources. This results in
  154. * returning the domain to its initialized state.
  155. * DeleteAttachment
  156. * This routine deletes a specified attachment and frees up all
  157. * resources associated with that attachment.
  158. * DeleteUser
  159. * This routine deletes a user from the domain. This takes care of
  160. * deleting the attachment too if this were a locally attach user.
  161. * DeleteChannel
  162. * This routine deletes a specific channel from the information base.
  163. * DeleteToken
  164. * This routine deletes a specific token from the information base.
  165. * ReclaimResources
  166. * This routine iterates through both the channel list and the token
  167. * list, asking each if is still valid (and removing those that are
  168. * not). This allows for automatic "garbage collection" when users
  169. * or attachments are lost.
  170. * MergeInformationBase
  171. * This routine issues the appropriate merge requests to a pending
  172. * top provider during a domain merger operation. It is also a state
  173. * machine in that it remembers what has already been merged, so that
  174. * the next time it is called, it can merge the next set of resources.
  175. * SetMergeState
  176. * This routine sets the merge state of the object, and if necessary,
  177. * issues a MergeDomainIndication to all downward attachments.
  178. * AddChannel
  179. * This routine is used to add a new channel to the current channel
  180. * list during a merge operation.
  181. * AddToken
  182. * This routine is used to add a new token to the current token list
  183. * during a merge operation.
  184. * CalculateDomainHeight
  185. * This routine calculates the height of the current domain, and takes
  186. * appropriate action if the height limit has been exceeded.
  187. *
  188. * Caveats:
  189. * None.
  190. *
  191. * Author:
  192. * James P. Galvin, Jr.
  193. */
  194. #include "plgxprt.h"
  195. /*
  196. * External Interfaces
  197. */
  198. /*
  199. * These macros are used when requesting a random dynamic channel ID.
  200. */
  201. #define DYNAMIC_CHANNEL_LOW_EXTENT 1001
  202. #define DYNAMIC_CHANNEL_HIGH_EXTENT 65535L
  203. /*
  204. * These two static structure are used by all instances of the domain class
  205. * as the minimum and maximum supported values for the domain parameters.
  206. */
  207. static DomainParameters Static_Minimum_Domain_Parameters =
  208. {
  209. MINIMUM_MAXIMUM_CHANNELS,
  210. MINIMUM_MAXIMUM_USERS,
  211. MINIMUM_MAXIMUM_TOKENS,
  212. MINIMUM_NUMBER_OF_PRIORITIES,
  213. MINIMUM_MINIMUM_THROUGHPUT,
  214. MINIMUM_MAXIMUM_DOMAIN_HEIGHT,
  215. MINIMUM_MAXIMUM_PDU_SIZE,
  216. MINIMUM_PROTOCOL_VERSION
  217. };
  218. static DomainParameters Static_Maximum_Domain_Parameters =
  219. {
  220. (UShort) MAXIMUM_MAXIMUM_CHANNELS,
  221. (UShort) MAXIMUM_MAXIMUM_USERS,
  222. (UShort) MAXIMUM_MAXIMUM_TOKENS,
  223. MAXIMUM_NUMBER_OF_PRIORITIES,
  224. MAXIMUM_MINIMUM_THROUGHPUT,
  225. MAXIMUM_MAXIMUM_DOMAIN_HEIGHT,
  226. MAXIMUM_MAXIMUM_PDU_SIZE,
  227. MAXIMUM_PROTOCOL_VERSION
  228. };
  229. /*
  230. * This is now set to 0 to indicate that this provider does not perform
  231. * any type of throughput enforcement.
  232. */
  233. #define DEFAULT_THROUGHPUT_ENFORCEMENT_INTERVAL 0
  234. /*
  235. * These macros define the number of buckets to used for each of the hash
  236. * dictionaries maintained by this class.
  237. */
  238. #define CHANNEL_LIST_NUMBER_OF_BUCKETS 16
  239. /*
  240. * Domain ()
  241. *
  242. * Public
  243. *
  244. * Functional Description:
  245. * This is the constructor for the domain class. It merely initailizes
  246. * all instance variables to indicate an "empty" state. It also sets
  247. * the initial state of the domain parameters array.
  248. */
  249. Domain::Domain()
  250. :
  251. m_AttachmentList(),
  252. m_ChannelList2(CHANNEL_LIST_NUMBER_OF_BUCKETS),
  253. m_TokenList2(),
  254. m_DomainHeightList2(),
  255. m_pConnToTopProvider(NULL),
  256. Merge_State(MERGE_INACTIVE),
  257. Outstanding_Merge_Requests(0),
  258. Number_Of_Users(0),
  259. Number_Of_Channels(0),
  260. Number_Of_Tokens(0),
  261. m_nDomainHeight(0)
  262. {
  263. /*
  264. * Set the domain parameters to their default values.
  265. */
  266. LockDomainParameters (NULL, FALSE);
  267. }
  268. /*
  269. * ~Domain ()
  270. *
  271. * Public
  272. *
  273. * Functional Description:
  274. * This is the destructor for the domain class. All it does is purge the
  275. * entire domain, which means to return it to its initial state (all
  276. * attachments are broken).
  277. */
  278. Domain::~Domain ()
  279. {
  280. PurgeDomain (REASON_USER_REQUESTED);
  281. }
  282. /*
  283. * BOOL IsTopProvider ()
  284. *
  285. * Public
  286. *
  287. * Functional Description:
  288. * This routine returns TRUE if this is the top provider, and FALSE
  289. * otherwise.
  290. */
  291. /*
  292. * Void GetDomainParameters ()
  293. *
  294. * Public
  295. *
  296. * Functional Description:
  297. * This routine returns the currently active minimum and maximum domain
  298. * parameter values (which will be different depending on whether or not
  299. * the domain parameters have been locked yet).
  300. */
  301. Void Domain::GetDomainParameters (
  302. PDomainParameters domain_parameters,
  303. PDomainParameters min_domain_parameters,
  304. PDomainParameters max_domain_parameters)
  305. {
  306. /*
  307. * Load the currently in-use set of domain parameters.
  308. */
  309. if (domain_parameters != NULL)
  310. *domain_parameters = Domain_Parameters;
  311. /*
  312. * See if domain parameters are already locked in for this domain.
  313. */
  314. if (Domain_Parameters_Locked)
  315. {
  316. /*
  317. * The domain parameters for this domain have already been locked
  318. * during the creation of a previous connection. Return those values
  319. * as both the minimum and maximum values (no deviation will be
  320. * permitted).
  321. */
  322. if (min_domain_parameters != NULL)
  323. *min_domain_parameters = Domain_Parameters;
  324. if (max_domain_parameters != NULL)
  325. *max_domain_parameters = Domain_Parameters;
  326. }
  327. else
  328. {
  329. /*
  330. * Domain parameters have not yet been locked. Therefore, return the
  331. * minimum and maximum values imposed by this implementation.
  332. */
  333. if (min_domain_parameters != NULL)
  334. *min_domain_parameters = Static_Minimum_Domain_Parameters;
  335. if (max_domain_parameters != NULL)
  336. *max_domain_parameters = Static_Maximum_Domain_Parameters;
  337. }
  338. }
  339. /*
  340. * Void BindConnAttmnt ()
  341. *
  342. * Public
  343. *
  344. * Functional Description:
  345. * This routine allows an attachment to bind to the domain. It takes all
  346. * actions appropriate to the addition of a new attachment (upward or
  347. * downward).
  348. */
  349. Void Domain::BindConnAttmnt (
  350. PConnection pOrigConn,
  351. BOOL upward_connection,
  352. PDomainParameters domain_parameters)
  353. {
  354. CAttachment *pAtt;
  355. PUser pUser;
  356. PChannel channel;
  357. PToken token;
  358. /*
  359. * Check the hierarchical direction of the requested attachment.
  360. */
  361. if (upward_connection)
  362. {
  363. /*
  364. * This is to be an upward connection. We must now check to make
  365. * sure that we don't already have an upward connection.
  366. */
  367. if (NULL == m_pConnToTopProvider)
  368. {
  369. /*
  370. * This attachment is the new Top Provider.
  371. */
  372. TRACE_OUT(("Domain::BindConnAttmnt: accepting upward attachment"));
  373. m_pConnToTopProvider = pOrigConn;
  374. /*
  375. * Tell all channel objects who the new Top Provider is.
  376. */
  377. m_ChannelList2.Reset();
  378. while (NULL != (channel = m_ChannelList2.Iterate()))
  379. {
  380. channel->SetTopProvider(m_pConnToTopProvider);
  381. }
  382. /*
  383. * Tell all token objects who the new Top Provider is.
  384. */
  385. m_TokenList2.Reset();
  386. while (NULL != (token = m_TokenList2.Iterate()))
  387. {
  388. token->SetTopProvider(m_pConnToTopProvider);
  389. }
  390. /*
  391. * If the domain parameters have not yet been locked, then lock
  392. * these into place.
  393. */
  394. if (Domain_Parameters_Locked == FALSE)
  395. {
  396. TRACE_OUT(("Domain::BindConnAttmnt: locking domain parameters"));
  397. LockDomainParameters (domain_parameters, TRUE);
  398. /*
  399. * Send a SetDomainParameters to each downward attachment.
  400. * This will allow those objects to adjust their construction
  401. * of send data PDUs to conform to the arbitrated maximum PDU
  402. * size.
  403. */
  404. m_AttachmentList.Reset();
  405. while (NULL != (pUser = m_AttachmentList.IterateUser()))
  406. {
  407. pUser->SetDomainParameters(&Domain_Parameters);
  408. }
  409. }
  410. /*
  411. * Since we have bound to a provider above us, it is necessary to
  412. * inform that provider of our height in the domain (otherwise
  413. * the new Top Provider would have no way of knowing what the
  414. * total height of the domain is). This is done by issuing an
  415. * erect domain request upward.
  416. */
  417. m_pConnToTopProvider->ErectDomainRequest(m_nDomainHeight, DEFAULT_THROUGHPUT_ENFORCEMENT_INTERVAL);
  418. /*
  419. * Now that this provider has become the former top provider of
  420. * a lower domain, it is necessary to issue a plumb domain
  421. * indication to all downward attachments. The primary reason
  422. * for this is to assure that there are no cycles in the domain.
  423. */
  424. m_AttachmentList.Reset();
  425. while (NULL != (pAtt = m_AttachmentList.Iterate()))
  426. {
  427. pAtt->PlumbDomainIndication(Domain_Parameters.max_height);
  428. }
  429. /*
  430. * We now have a new top provider, which means that we must begin
  431. * an information base merger.
  432. */
  433. MergeInformationBase ();
  434. }
  435. else
  436. {
  437. /*
  438. * We already have an upward connection (or one pending).
  439. * Therefore, this attachment must be rejected.
  440. */
  441. ERROR_OUT(("Domain::BindConnAttmnt: domain not hierarchical"));
  442. pOrigConn->DisconnectProviderUltimatum(REASON_PROVIDER_INITIATED);
  443. }
  444. }
  445. else
  446. {
  447. /*
  448. * This is to be a downward connection. We must now check to see if
  449. * we already have a record of the specified connection.
  450. */
  451. if (! m_AttachmentList.FindConn(pOrigConn))
  452. {
  453. /*
  454. * This does represent a new downward connection. So put it into
  455. * the attachment list.
  456. */
  457. TRACE_OUT(("Domain::BindConnAttmnt: accepting downward attachment"));
  458. m_AttachmentList.AppendConn(pOrigConn);
  459. /*
  460. * If the domain parameters have not yet been locked, then lock
  461. * these into place.
  462. */
  463. if (Domain_Parameters_Locked == FALSE)
  464. {
  465. TRACE_OUT(("Domain::BindConnAttmnt: locking domain parameters"));
  466. LockDomainParameters (domain_parameters, TRUE);
  467. /*
  468. * Send a SetDomainParameters to each downward attachment.
  469. * This will allow those objects to adjust their construction
  470. * of send data PDUs to conform to the arbitrated maximum PDU
  471. * size.
  472. */
  473. m_AttachmentList.Reset();
  474. while (NULL != (pUser = m_AttachmentList.IterateUser()))
  475. {
  476. pUser->SetDomainParameters(&Domain_Parameters);
  477. }
  478. }
  479. }
  480. else
  481. {
  482. /*
  483. * The attachment is already listed in the attachment list, so
  484. * print an error and ignore the request.
  485. */
  486. ERROR_OUT(("Domain::BindConnAttmnt: attachment already exists"));
  487. }
  488. }
  489. }
  490. /*
  491. * Void PlumbDomainIndication ()
  492. *
  493. * Public
  494. *
  495. * Functional Description:
  496. * This member function originates at a hgher provider and travels downward
  497. * in the domain. Each provider examines the height limit, and disconnects
  498. * if it is zero. If not, then the indication is forwarded downward.
  499. */
  500. Void Domain::PlumbDomainIndication (
  501. PConnection pOrigConn,
  502. ULong height_limit)
  503. {
  504. /*
  505. * Make sure that this indication is from the top provider.
  506. */
  507. if (pOrigConn == m_pConnToTopProvider)
  508. {
  509. /*
  510. * Check the height limit to determine whether this provider is too
  511. * far from the top or not.
  512. */
  513. if (height_limit != 0)
  514. {
  515. CAttachment *pAtt;
  516. /*
  517. * We are okay, so decrement the height limit and forward the
  518. * indication to all downward attachments.
  519. */
  520. TRACE_OUT(("Domain::PlumbDomainIndication: forwarding indication downward"));
  521. height_limit--;
  522. m_AttachmentList.Reset();
  523. while (NULL != (pAtt = m_AttachmentList.Iterate()))
  524. {
  525. pAtt->PlumbDomainIndication(height_limit);
  526. }
  527. }
  528. else
  529. {
  530. /*
  531. * We are too far from the top (which may indicate the existence
  532. * of a cycle in the domain). It is therefore necessary to
  533. * purge the entire domain (from this provider down).
  534. */
  535. WARNING_OUT(("Domain::PlumbDomainIndication: purging domain"));
  536. PurgeDomain (REASON_PROVIDER_INITIATED);
  537. }
  538. }
  539. else
  540. {
  541. /*
  542. * This indication was received from an attachment that is unknown to
  543. * this domain. Ignore it.
  544. */
  545. ERROR_OUT(("Domain::PlumbDomainIndication: invalid originator=0x%p", pOrigConn));
  546. }
  547. }
  548. /*
  549. * Void ErectDomainRequest ()
  550. *
  551. * Public
  552. *
  553. * Functional Description:
  554. * This member function is called whenever a lower provider detects a
  555. * change in their domain height. This will be due to someone below this
  556. * provider creating or breaking a connection.
  557. */
  558. Void Domain::ErectDomainRequest (
  559. PConnection pOrigConn,
  560. ULONG_PTR height_in_domain,
  561. ULong)
  562. {
  563. /*
  564. * Make sure that this request comes from an attachment that the local
  565. * provider is aware of.
  566. */
  567. if (m_AttachmentList.FindConn(pOrigConn))
  568. {
  569. /*
  570. * Put the domain height into the domain height list, and then call
  571. * the subroutine responsible for determining whether any action is
  572. * required as a result of change in the height.
  573. */
  574. TRACE_OUT(("Domain::ErectDomainRequest: processing request"));
  575. m_DomainHeightList2.Append(pOrigConn, height_in_domain);
  576. CalculateDomainHeight ();
  577. }
  578. else
  579. {
  580. /*
  581. * The attachment is unknown to this provider. Ignore the request.
  582. */
  583. ERROR_OUT(("Domain::ErectDomainRequest: invalid originator=0x%p", pOrigConn));
  584. }
  585. }
  586. /*
  587. * Void MergeChannelsRequest ()
  588. *
  589. * Public
  590. *
  591. * Functional Description:
  592. * This public member function is called by a former top provider during
  593. * a domain merge operation. It travels upward to the top provider of
  594. * the combined domain, where the merge can be processed. Any providers
  595. * that it travels through on the way must remember how to route the
  596. * confirm back to the originator.
  597. */
  598. Void Domain::MergeChannelsRequest (
  599. PConnection pOrigConn,
  600. CChannelAttributesList *merge_channel_list,
  601. CChannelIDList *purge_channel_list)
  602. {
  603. PChannelAttributes merge_channel;
  604. Channel_Type channel_type;
  605. ChannelID channel_id;
  606. PChannel channel;
  607. CChannelAttributesList merge_confirm_list;
  608. /*
  609. * Make sure that this request is coming from a legitimate downward
  610. * attachment before processing it.
  611. */
  612. if (m_AttachmentList.FindConn(pOrigConn))
  613. {
  614. /*
  615. * Is this the top provider. If so the request can be processed
  616. * locally. If not, it must be forwarded towards the top provider.
  617. */
  618. if (IsTopProvider())
  619. {
  620. /*
  621. * Iterate through the merge channel list, admitting all channels
  622. * that can be admitted.
  623. */
  624. merge_channel_list->Reset();
  625. while (NULL != (merge_channel = merge_channel_list->Iterate()))
  626. {
  627. /*
  628. * Get the address of the next channel attributes structure
  629. * in the list. Then get the type and the ID of the channel
  630. * being merged.
  631. */
  632. channel_type = merge_channel->channel_type;
  633. switch (channel_type)
  634. {
  635. case STATIC_CHANNEL:
  636. channel_id = merge_channel->
  637. u.static_channel_attributes.channel_id;
  638. break;
  639. case USER_CHANNEL:
  640. channel_id = merge_channel->
  641. u.user_channel_attributes.user_id;
  642. break;
  643. case PRIVATE_CHANNEL:
  644. channel_id = merge_channel->
  645. u.private_channel_attributes.channel_id;
  646. break;
  647. case ASSIGNED_CHANNEL:
  648. channel_id = merge_channel->
  649. u.assigned_channel_attributes.channel_id;
  650. break;
  651. }
  652. /*
  653. * Check to see if the channel being merged exists in the
  654. * upper domain information base.
  655. */
  656. if (NULL != (channel = m_ChannelList2.Find(channel_id)))
  657. {
  658. if ((channel_type == STATIC_CHANNEL) &&
  659. (channel->GetChannelType () == STATIC_CHANNEL))
  660. {
  661. /*
  662. * It is a static channel. This means that the merge
  663. * is okay (merging static channels is no problem).
  664. */
  665. TRACE_OUT(("Domain::MergeChannelsRequest: static channel merge successful"));
  666. /*
  667. * Static channels are automatically joined.
  668. * Note that sending an initiator ID of 0 tells the
  669. * channel object not to issue a ChannelJoinConfirm,
  670. * which is inappropriate during a merge.
  671. */
  672. channel->ChannelJoinRequest(pOrigConn, 0, 0);
  673. /*
  674. * Put the channel attributes structure into the
  675. * merge confirm list, meaning that the information
  676. * associated with the successful merge will be
  677. * repeated in the subsequent confirm.
  678. */
  679. merge_confirm_list.Append(merge_channel);
  680. }
  681. else
  682. {
  683. /*
  684. * The channel being merged is an in-use dynamic
  685. * channel. Therefore, it must be rejected (this is
  686. * NOT permitted).
  687. */
  688. WARNING_OUT(("Domain::MergeChannelsRequest: dynamic channel in use - rejecting merge"));
  689. /*
  690. * Add the channel ID to the list of those channels
  691. * to be purged frmo the lower domain.
  692. */
  693. purge_channel_list->Append(channel_id);
  694. }
  695. }
  696. else
  697. {
  698. /*
  699. * If the channel does not exist in the upper domain at
  700. * all, then add it to the upper domain.
  701. */
  702. AddChannel(pOrigConn, merge_channel, &merge_confirm_list, purge_channel_list);
  703. }
  704. }
  705. /*
  706. * Send the appropriate merge channels confirm to the originating
  707. * user.
  708. */
  709. pOrigConn->MergeChannelsConfirm(&merge_confirm_list, purge_channel_list);
  710. }
  711. else
  712. {
  713. /*
  714. * If this is not the top provider, then add the requesting
  715. * attachment to the merge queue (which is used to route
  716. * confirms back later), and forward the request upward towards
  717. * the top provier.
  718. */
  719. TRACE_OUT(("Domain::MergeChannelsRequest: forwarding request to Top Provider"));
  720. m_MergeQueue.Append(pOrigConn);
  721. m_pConnToTopProvider->MergeChannelsRequest(merge_channel_list, purge_channel_list);
  722. }
  723. }
  724. else
  725. {
  726. /*
  727. * This request was received from an attachment that is unknown to
  728. * this domain.
  729. */
  730. ERROR_OUT(("Domain::MergeChannelsRequest: invalid originator=0x%p", pOrigConn));
  731. }
  732. }
  733. /*
  734. * Void MergeChannelsConfirm ()
  735. *
  736. * Public
  737. *
  738. * Functional Description:
  739. * This public member function is called in response to a previous channels
  740. * merge request. It is forwarded back down the hierarchy until it reaches
  741. * the former top provider that initiated the request. That former top
  742. * provider will use the information contained therein to determine
  743. * whether the merge on a particular channel was successful or not. If
  744. * it was not, then the channel is purged from the lower domain, and a
  745. * purge channels indication is sent downward to let everyone in the lower
  746. * domain know of this.
  747. */
  748. Void Domain::MergeChannelsConfirm (
  749. PConnection pOrigConn,
  750. CChannelAttributesList *merge_channel_list,
  751. CChannelIDList *purge_channel_list)
  752. {
  753. PConnection pConn;
  754. PChannelAttributes merge_channel;
  755. Channel_Type channel_type;
  756. ChannelID channel_id;
  757. PChannel channel;
  758. BOOL joined;
  759. CChannelAttributesList merge_confirm_list;
  760. CUidList purge_user_list;
  761. CChannelIDList purge_normal_list;
  762. /*
  763. * Verify that the confirm came from the top provider.
  764. */
  765. if (pOrigConn == m_pConnToTopProvider)
  766. {
  767. /*
  768. * Now check the merge state. If the state is inactive, then that
  769. * means that this provider is an intermediate provider (i.e. a
  770. * provider that lies between the top provider and the former top
  771. * provider of the lower domain). If the state is not inactive, then
  772. * this must be the former top provider of the lower domain.
  773. */
  774. if (Merge_State == MERGE_INACTIVE)
  775. {
  776. /*
  777. * This is a legitimate merge channels confirm. We must forward
  778. * the confirm to the downward attachment that originated the
  779. * merge channel request. We remember who this is by pulling
  780. * out the first entry in the merge queue. Check to make sure
  781. * that there is an entry in the merge queue.
  782. */
  783. if (NULL != (pConn = m_MergeQueue.Get()))
  784. {
  785. /*
  786. * Get the attachment that is to receive the confirm and verify
  787. * that it is still connected (the connection could have been
  788. * lost since the request was forwarded upward).
  789. */
  790. if (m_AttachmentList.FindConn(pConn))
  791. {
  792. /*
  793. * Iterate through the merge channel list, adding each of
  794. * the channels it contains into the local information
  795. * base.
  796. */
  797. merge_channel_list->Reset();
  798. while (NULL != (merge_channel = merge_channel_list->Iterate()))
  799. {
  800. /*
  801. * Get the next channel to be merge and then get its
  802. * channel ID.
  803. */
  804. channel_type = merge_channel->channel_type;
  805. switch (channel_type)
  806. {
  807. case STATIC_CHANNEL:
  808. channel_id = merge_channel->
  809. u.static_channel_attributes.channel_id;
  810. joined = TRUE;
  811. break;
  812. case USER_CHANNEL:
  813. channel_id = merge_channel->
  814. u.user_channel_attributes.user_id;
  815. joined = merge_channel->
  816. u.user_channel_attributes.joined;
  817. break;
  818. case PRIVATE_CHANNEL:
  819. channel_id = merge_channel->
  820. u.private_channel_attributes.channel_id;
  821. joined = merge_channel->
  822. u.private_channel_attributes.joined;
  823. break;
  824. case ASSIGNED_CHANNEL:
  825. channel_id = merge_channel->
  826. u.assigned_channel_attributes.channel_id;
  827. joined = TRUE;
  828. break;
  829. }
  830. /*
  831. * See if the channel already exists in the local
  832. * information base.
  833. */
  834. if (NULL != (channel = m_ChannelList2.Find(channel_id)))
  835. {
  836. /*
  837. * If the attachment is joined to this channel,
  838. * then join it at this level too. Note that
  839. * sending an initiator ID of 0 tells the channel
  840. * object not to issue a ChannelJoinConfirm, which
  841. * would be inappropriate during a merge.
  842. */
  843. TRACE_OUT(("Domain::MergeChannelsConfirm: attempting to join merged channel"));
  844. if (joined)
  845. channel->ChannelJoinRequest(pConn, 0, 0);
  846. /*
  847. * Add the channel to the merge confirm list so
  848. * that it will automatically be forwarded
  849. * downward.
  850. */
  851. merge_confirm_list.Append(merge_channel);
  852. }
  853. else
  854. {
  855. /*
  856. * The channel does not exist in the local
  857. * information base, so add it.
  858. */
  859. AddChannel(pConn, merge_channel, &merge_confirm_list, purge_channel_list);
  860. }
  861. }
  862. /*
  863. * Forward the merge channel confirm on to the attachment
  864. * from which the request originated.
  865. */
  866. pConn->MergeChannelsConfirm(&merge_confirm_list, purge_channel_list);
  867. }
  868. else
  869. {
  870. /*
  871. * The attachment from which the merge request originated
  872. * has been lost. It may be necessary to send something
  873. * to the Top Provider in order to guarantee the integrity
  874. * of the domain. In some cases it may be necessary to
  875. * purge the domain.
  876. */
  877. WARNING_OUT(("Domain::MergeChannelsConfirm: forwarding attachment lost"));
  878. }
  879. }
  880. else
  881. {
  882. /*
  883. * There is no outstanding merge request that can be used to
  884. * direct the confirm. This will happen only if a confirm
  885. * is received without a previous merge having been sent.
  886. * The proper response should be to send a RejectUltimatum
  887. * to the offending upward attachment.
  888. */
  889. ERROR_OUT(("Domain::MergeChannelsConfirm: merge queue empty"));
  890. }
  891. }
  892. else
  893. {
  894. /*
  895. * This confirm should not be received unless there is at least
  896. * one outstanding merge request. Check to make sure that this
  897. * is so.
  898. */
  899. if (Outstanding_Merge_Requests != 0)
  900. {
  901. /*
  902. * If there are any entries in the purge channel list, then
  903. * it is necessary to issue a purge channels indication to all
  904. * downward attachments.
  905. */
  906. if (purge_channel_list->IsEmpty() == FALSE)
  907. {
  908. ChannelID chid;
  909. UserID uid;
  910. /*
  911. * Iterate through the list of channels to be purged,
  912. * putting each channel into either the "user list" or the
  913. * "normal list". This separation is necessary for lower
  914. * providers to be able to issue the appropriate
  915. * indications.
  916. */
  917. purge_channel_list->Reset();
  918. while (NULL != (channel_id = purge_channel_list->Iterate()))
  919. {
  920. /*
  921. * Get the channel ID of the next channel to be purged.
  922. */
  923. TRACE_OUT(("Domain::MergeChannelsConfirm: merge rejected on channel ID = %04X", (UINT) channel_id));
  924. /*
  925. * Make sure the channel still exists locally before
  926. * trying to purge it.
  927. */
  928. if (m_ChannelList2.Find(channel_id))
  929. {
  930. /*
  931. * Determine what type of channel is being purged
  932. * and add it to the appropriate list. These lists
  933. * will be used when issuing the purge channels
  934. * indication below.
  935. */
  936. if (ValidateUserID (channel_id, NULL))
  937. purge_user_list.Append(channel_id);
  938. else
  939. purge_normal_list.Append(channel_id);
  940. }
  941. else
  942. {
  943. /*
  944. * The channel to be purged could not be found in
  945. * the local domain.
  946. */
  947. ERROR_OUT(("Domain::MergeChannelsConfirm: no such channel"));
  948. }
  949. }
  950. /*
  951. * This loop simply transmits a PurgeChannelsIndication to
  952. * all downward attachments in the lower domain.
  953. */
  954. CAttachment *pAtt;
  955. m_AttachmentList.Reset();
  956. while (NULL != (pAtt = m_AttachmentList.Iterate()))
  957. {
  958. pAtt->PurgeChannelsIndication(&purge_user_list, &purge_normal_list);
  959. }
  960. /*
  961. * Iterate through the list of channels to be purged,
  962. * deleting each channel.
  963. */
  964. purge_normal_list.Reset();
  965. while (NULL != (chid = purge_normal_list.Iterate()))
  966. {
  967. DeleteChannel(chid);
  968. }
  969. /*
  970. * Iterate through the list of users to be purged, deleting
  971. * each user.
  972. */
  973. purge_user_list.Reset();
  974. while (NULL != (uid = purge_user_list.Iterate()))
  975. {
  976. DeleteUser(uid);
  977. }
  978. }
  979. /*
  980. * Decrement the number of outstanding requests. If this
  981. * was the last outstanding request, then go back to the
  982. * merge state machine to see if there is anything left to
  983. * do.
  984. */
  985. if (--Outstanding_Merge_Requests == 0)
  986. MergeInformationBase ();
  987. }
  988. else
  989. {
  990. /*
  991. * There are no merge requests pending, so this errant confirm
  992. * must be ignored.
  993. */
  994. ERROR_OUT(("Domain::MergeChannelsConfirm: no outstanding merge requests"));
  995. }
  996. }
  997. }
  998. else
  999. {
  1000. /*
  1001. * This confirm was received from someone besides the top provider.
  1002. */
  1003. ERROR_OUT(("Domain::MergeChannelsConfirm: invalid originator=0x%p", pOrigConn));
  1004. }
  1005. }
  1006. /*
  1007. * Void PurgeChannelsIndication ()
  1008. *
  1009. * Public
  1010. *
  1011. * Functional Description:
  1012. * This public member function is called in response to channels being
  1013. * purged from the lower domain during an information base merge operation.
  1014. * The purge is forwarded downward to all attachments. Then the channel
  1015. * are deleted from the local information base. For each user channel
  1016. * all resources in use by that user will be reclaimed.
  1017. */
  1018. Void Domain::PurgeChannelsIndication (
  1019. PConnection pOrigConn,
  1020. CUidList *purge_user_list,
  1021. CChannelIDList *purge_channel_list)
  1022. {
  1023. CAttachment *pAtt;
  1024. UserID uid;
  1025. ChannelID chid;
  1026. /*
  1027. * Make sure this indication came from the top provider.
  1028. */
  1029. if (pOrigConn == m_pConnToTopProvider)
  1030. {
  1031. /*
  1032. * This loop re-transmits the purge channel indication to all
  1033. * downward attachments.
  1034. */
  1035. m_AttachmentList.Reset();
  1036. while (NULL != (pAtt = m_AttachmentList.Iterate()))
  1037. {
  1038. pAtt->PurgeChannelsIndication(purge_user_list, purge_channel_list);
  1039. }
  1040. /*
  1041. * Iterate through the list of channels to be purged, deleting each
  1042. * channel.
  1043. */
  1044. purge_channel_list->Reset();
  1045. while (NULL != (chid = purge_channel_list->Iterate()))
  1046. {
  1047. /*
  1048. * See if the specified channel is in the local information base.
  1049. * If it is not, ignore it (this is a normal condition during a
  1050. * purge operation).
  1051. */
  1052. if (m_ChannelList2.Find(chid))
  1053. {
  1054. /*
  1055. * Check to see if the channel ID corresponds to a user ID
  1056. * channel. If it does, report the error and do nothing. If
  1057. * it is not a user ID channel, then delete the channel.
  1058. */
  1059. if (ValidateUserID(chid, NULL) == FALSE)
  1060. {
  1061. /*
  1062. * Delete the channel.
  1063. */
  1064. DeleteChannel(chid);
  1065. }
  1066. else
  1067. {
  1068. /*
  1069. * The specified channel is in the Channel List, but it
  1070. * does not refer to a user channel. This indicates that
  1071. * an error has occurred at the upward provider. Ignore
  1072. * the indication.
  1073. */
  1074. ERROR_OUT(("Domain::PurgeChannelsIndication: UserChannel in purge_channel_list"));
  1075. }
  1076. }
  1077. }
  1078. /*
  1079. * Iterate through the list of users to be purged, deleting
  1080. * each one.
  1081. */
  1082. purge_user_list->Reset();
  1083. while (NULL != (uid = purge_user_list->Iterate()))
  1084. {
  1085. /*
  1086. * See if the specified user is in the local information base.
  1087. * If it is not, ignore it (this is a normal condition during a
  1088. * purge operation).
  1089. */
  1090. if (m_ChannelList2.Find(uid))
  1091. {
  1092. /*
  1093. * Check to see if the user ID corresponds to a valid user in
  1094. * the sub-tree of this provider.
  1095. */
  1096. if (ValidateUserID(uid, NULL))
  1097. {
  1098. /*
  1099. * Delete the user from the local information base.
  1100. */
  1101. DeleteUser(uid);
  1102. }
  1103. else
  1104. {
  1105. /*
  1106. * The specified ID is in the Channel List, but it does not
  1107. * refer to a user channel. This indicates that an error
  1108. * has occurred at the upward provider. Ignore the
  1109. * indication.
  1110. */
  1111. ERROR_OUT(("Domain::PurgeChannelsIndication: non-UserChannel in purge_user_list"));
  1112. }
  1113. }
  1114. }
  1115. }
  1116. else
  1117. {
  1118. /*
  1119. * This indication was received from someone besides the top provider.
  1120. */
  1121. ERROR_OUT(("Domain::PurgeChannelsIndication: invalid originator=0x%p", pOrigConn));
  1122. }
  1123. }
  1124. /*
  1125. * Void MergeTokensRequest ()
  1126. *
  1127. * Public
  1128. *
  1129. * Functional Description:
  1130. * This public member function is called by a former top provider during
  1131. * a domain merge operation. It travels upward to the top provider of
  1132. * the combined domain, where the merge can be processed. Any providers
  1133. * that it travels through on the way must remember how to route the
  1134. * confirm back to the originator.
  1135. */
  1136. Void Domain::MergeTokensRequest (
  1137. PConnection pOrigConn,
  1138. CTokenAttributesList *merge_token_list,
  1139. CTokenIDList *purge_token_list)
  1140. {
  1141. PTokenAttributes merge_token;
  1142. TokenState token_state;
  1143. TokenID token_id;
  1144. PToken token;
  1145. CUidList *owner_list;
  1146. UserID uid;
  1147. CTokenAttributesList merge_confirm_list;
  1148. /*
  1149. * Make sure that this request is coming from a legitimate downward
  1150. * attachment before processing it.
  1151. */
  1152. if (m_AttachmentList.FindConn(pOrigConn))
  1153. {
  1154. /*
  1155. * Is this the top provider. If so the request can be processed
  1156. * locally. If not, it must be forwarded toward the top provider.
  1157. */
  1158. if (IsTopProvider())
  1159. {
  1160. /*
  1161. * Iterate through the merge token list, attempting to add each
  1162. * token in sequence.
  1163. */
  1164. merge_token_list->Reset();
  1165. while (NULL != (merge_token = merge_token_list->Iterate()))
  1166. {
  1167. /*
  1168. * Get the address of the structure containing the next token
  1169. * to merge. Then get the token ID from the structure.
  1170. */
  1171. token_state = merge_token->token_state;
  1172. switch (token_state)
  1173. {
  1174. case TOKEN_GRABBED:
  1175. token_id = merge_token->
  1176. u.grabbed_token_attributes.token_id;
  1177. break;
  1178. case TOKEN_INHIBITED:
  1179. token_id = merge_token->
  1180. u.inhibited_token_attributes.token_id;
  1181. break;
  1182. case TOKEN_GIVING:
  1183. token_id = merge_token->
  1184. u.giving_token_attributes.token_id;
  1185. break;
  1186. case TOKEN_GIVEN:
  1187. token_id = merge_token->
  1188. u.given_token_attributes.token_id;
  1189. break;
  1190. }
  1191. /*
  1192. * Check to see if the requested token is in the local
  1193. * information base.
  1194. */
  1195. if (NULL != (token = m_TokenList2.Find(token_id)))
  1196. {
  1197. /*
  1198. * If the token already exists within this domain, then
  1199. * we need to compare the state of the local token and
  1200. * the state of the token being merged. If they are
  1201. * both inhibited, then the merge operation can proceed
  1202. * successfully. However, if either one is something
  1203. * besides inhibited, then the merge request will be
  1204. * rejected.
  1205. */
  1206. if ((token_state == TOKEN_INHIBITED) &&
  1207. (token->GetTokenState () == TOKEN_INHIBITED))
  1208. {
  1209. /*
  1210. * Add each inhibiting user from the former lower
  1211. * domain to the token for this domain.
  1212. */
  1213. TRACE_OUT(("Domain::MergeTokensRequest: merging inhibiting user IDs"));
  1214. owner_list = merge_token->
  1215. u.inhibited_token_attributes.inhibitors;
  1216. owner_list->Reset();
  1217. while (NULL != (uid = owner_list->Iterate()))
  1218. {
  1219. token->TokenInhibitRequest (NULL, uid, token_id);
  1220. }
  1221. /*
  1222. * Add the token attributes structure to the merge
  1223. * list, so that it will be included as part of the
  1224. * merge tokens confirm.
  1225. */
  1226. merge_confirm_list.Append(merge_token);
  1227. }
  1228. else
  1229. {
  1230. /*
  1231. * The token is in use in the upper domain, and a merge
  1232. * is not possible. So add the token ID to the purge
  1233. * list, so that it will be purged from the lower
  1234. * domain.
  1235. */
  1236. WARNING_OUT(("Domain::MergeTokensRequest: token in use - rejecting merge"));
  1237. purge_token_list->Append(token_id);
  1238. }
  1239. }
  1240. else
  1241. {
  1242. /*
  1243. * The token does not exist in the local information base.
  1244. * Attempt to add it.
  1245. */
  1246. AddToken (merge_token, &merge_confirm_list,
  1247. purge_token_list);
  1248. }
  1249. }
  1250. /*
  1251. * Issue the merge tokens confirm to the originator of the request.
  1252. */
  1253. pOrigConn->MergeTokensConfirm(&merge_confirm_list, purge_token_list);
  1254. }
  1255. else
  1256. {
  1257. /*
  1258. * This must be an intermediate provider in the upper domain.
  1259. * Forward the request upward to be handled by the Top Provider
  1260. * of the upper domain. Also append the identity of the
  1261. * requestor to the merge queue, so that the pending response
  1262. * can be routed appropriately.
  1263. */
  1264. TRACE_OUT(("Domain::MergeTokensRequest: forwarding request to Top Provider"));
  1265. m_MergeQueue.Append(pOrigConn);
  1266. m_pConnToTopProvider->MergeTokensRequest(merge_token_list, purge_token_list);
  1267. }
  1268. }
  1269. else
  1270. {
  1271. /*
  1272. * This request is coming from a provider that is unknown in this
  1273. * domain. Simply ignore the request.
  1274. */
  1275. ERROR_OUT(("Domain::MergeTokensRequest: invalid originator=0x%p", pOrigConn));
  1276. }
  1277. }
  1278. /*
  1279. * Void MergeTokensConfirm ()
  1280. *
  1281. * Public
  1282. *
  1283. * Functional Description:
  1284. * This MCS command is initially invoked by the Top Provider of the upper
  1285. * domain during a domain merge operation. It travels downward until it
  1286. * reaches the former Top Provider of the lower domain. It contains
  1287. * notification of whether or not the merge of the token was successful.
  1288. */
  1289. Void Domain::MergeTokensConfirm (
  1290. PConnection pOrigConn,
  1291. CTokenAttributesList *merge_token_list,
  1292. CTokenIDList *purge_token_list)
  1293. {
  1294. PConnection pConn;
  1295. PTokenAttributes merge_token;
  1296. TokenState token_state;
  1297. TokenID token_id;
  1298. PToken token;
  1299. CUidList *owner_list;
  1300. UserID uid;
  1301. CTokenAttributesList merge_confirm_list;
  1302. /*
  1303. * Check to make sure that it came from the Top Provider.
  1304. */
  1305. if (pOrigConn == m_pConnToTopProvider)
  1306. {
  1307. /*
  1308. * Now check the merge state. If the state is inactive, then that
  1309. * means that this provider is an intermediate provider (i.e. a
  1310. * provider that lies between the top provider and the former top
  1311. * provider of the lower domain). If the state is not inactive, then
  1312. * this must be the former top provider of the lower domain.
  1313. */
  1314. if (Merge_State == MERGE_INACTIVE)
  1315. {
  1316. /*
  1317. * Since this came from the Top Provider, it should be a response
  1318. * to an outstanding merge request that passed through this
  1319. * provider. If so, then the merge queue will not be empty. Check
  1320. * this before proceeding with the request.
  1321. */
  1322. if (NULL != (pConn = m_MergeQueue.Get()))
  1323. {
  1324. /*
  1325. * Get the identity of the provider to which this confirm must
  1326. * forwarded.
  1327. */
  1328. /*
  1329. * If the provider is still attached to this provider, then
  1330. * forward the merge confirm.
  1331. */
  1332. if (m_AttachmentList.FindConn(pConn))
  1333. {
  1334. /*
  1335. * Iterate through the merge token list, attempting to add
  1336. * each token in sequence.
  1337. */
  1338. merge_token_list->Reset();
  1339. while (NULL != (merge_token = merge_token_list->Iterate()))
  1340. {
  1341. /*
  1342. * Get the address of the structure containing the next
  1343. * token to merge. Then get the token ID from the
  1344. * structure.
  1345. */
  1346. token_state = merge_token->token_state;
  1347. switch (token_state)
  1348. {
  1349. case TOKEN_GRABBED:
  1350. token_id = merge_token->
  1351. u.grabbed_token_attributes.token_id;
  1352. break;
  1353. case TOKEN_INHIBITED:
  1354. token_id = merge_token->
  1355. u.inhibited_token_attributes.token_id;
  1356. break;
  1357. case TOKEN_GIVING:
  1358. token_id = merge_token->
  1359. u.giving_token_attributes.token_id;
  1360. break;
  1361. case TOKEN_GIVEN:
  1362. token_id = merge_token->
  1363. u.given_token_attributes.token_id;
  1364. break;
  1365. }
  1366. /*
  1367. * Check to see if the requested token is in the local
  1368. * information base.
  1369. */
  1370. if (NULL != (token = m_TokenList2.Find(token_id)))
  1371. {
  1372. /*
  1373. * The token already exists in the information base
  1374. * of this intermediate provider. The only valid
  1375. * case where this could happen is if the token
  1376. * being merged is inhibited in both upper and
  1377. * lower domains. Check this.
  1378. */
  1379. if ((token_state == TOKEN_INHIBITED) &&
  1380. (token->GetTokenState () == TOKEN_INHIBITED))
  1381. {
  1382. /*
  1383. * Add each inhibiting user from the former
  1384. * lower domain to the token for this domain.
  1385. */
  1386. TRACE_OUT(("Domain::MergeTokensConfirm: merging inhibiting user IDs"));
  1387. owner_list = merge_token->
  1388. u.inhibited_token_attributes.inhibitors;
  1389. owner_list->Reset();
  1390. while (NULL != (uid = owner_list->Iterate()))
  1391. {
  1392. token->TokenInhibitRequest(NULL, uid, token_id);
  1393. }
  1394. /*
  1395. * Add the token attributes structure to the
  1396. * merge list, so that it will be included as
  1397. * part of the merge tokens confirm.
  1398. */
  1399. merge_confirm_list.Append(merge_token);
  1400. }
  1401. else
  1402. {
  1403. /*
  1404. * The states of the tokens in the upper and
  1405. * lower domain are invalid. This should have
  1406. * been resolved by the Top Provider before
  1407. * issuing this merge request. Report the
  1408. * error and continue.
  1409. */
  1410. ERROR_OUT(("Domain::MergeTokensConfirm: bad token in merge confirm"));
  1411. }
  1412. }
  1413. else
  1414. {
  1415. /*
  1416. * The token does not exist in the local
  1417. * information base. Attempt to add it.
  1418. */
  1419. AddToken (merge_token, &merge_confirm_list,
  1420. purge_token_list);
  1421. }
  1422. }
  1423. /*
  1424. * Forward merge confirm toward the former top provider
  1425. * of the lower domain.
  1426. */
  1427. pConn->MergeTokensConfirm(&merge_confirm_list, purge_token_list);
  1428. }
  1429. else
  1430. {
  1431. /*
  1432. * The provider from which the outstanding request came
  1433. * must have been lost since the request was initially
  1434. * forwarded upward. We need to issue some notification
  1435. * of this upward, depending on the response within the
  1436. * confirm.
  1437. */
  1438. ERROR_OUT(("Domain::MergeTokensConfirm: forwarding attachment lost"));
  1439. }
  1440. }
  1441. else
  1442. {
  1443. /*
  1444. * There is no outstanding request with which this confirm is
  1445. * associated. Something is wrong above. All this provider
  1446. * can do is ignore the errant confirm.
  1447. */
  1448. ERROR_OUT (("Domain::MergeTokensConfirm: no outstanding merge requests"));
  1449. }
  1450. }
  1451. else
  1452. {
  1453. /*
  1454. * If we have received a confirm from the top provider, hen there
  1455. * should be at least one outstanding merge request. Make sure
  1456. * this is true before proceeding.
  1457. */
  1458. if (Outstanding_Merge_Requests != 0)
  1459. {
  1460. /*
  1461. * If there are any entries in the purge token list, it is
  1462. * necessary to issue a purge tokens indication to all
  1463. * downward attachments.
  1464. */
  1465. if (purge_token_list->IsEmpty() == FALSE)
  1466. {
  1467. /*
  1468. * Issue a PurgeTokensIndication downward to all
  1469. * attachments.
  1470. */
  1471. CAttachment *pAtt;
  1472. m_AttachmentList.Reset();
  1473. while (NULL != (pAtt = m_AttachmentList.Iterate()))
  1474. {
  1475. pAtt->PurgeTokensIndication(this, purge_token_list);
  1476. }
  1477. /*
  1478. * Iterate through the list of tokens to be purged,
  1479. * removing each from the local information base.
  1480. */
  1481. purge_token_list->Reset();
  1482. while (NULL != (token_id = purge_token_list->Iterate()))
  1483. {
  1484. DeleteToken (token_id);
  1485. }
  1486. }
  1487. /*
  1488. * Decrement the number of outstanding merge requests. If
  1489. * there are now no more, then proceed to the next state
  1490. * in the merger state machine.
  1491. */
  1492. if (--Outstanding_Merge_Requests == 0)
  1493. MergeInformationBase ();
  1494. }
  1495. else
  1496. {
  1497. /*
  1498. * We have received a merge confirm when there are no
  1499. * outstanding merge requests. Ignore the confirm.
  1500. */
  1501. ERROR_OUT(("Domain::MergeTokensConfirm: no outstanding merge requests"));
  1502. }
  1503. }
  1504. }
  1505. else
  1506. {
  1507. /*
  1508. * This merge confirm has been received from someone besides the top
  1509. * provider. Ignore it.
  1510. */
  1511. ERROR_OUT(("Domain::MergeTokensConfirm: invalid originator=0x%p", pOrigConn));
  1512. }
  1513. }
  1514. /*
  1515. * Void PurgeTokensIndication ()
  1516. *
  1517. * Public
  1518. *
  1519. * Functional Description:
  1520. * This member function is first invoked by the former Top Provider of
  1521. * the lower domain during a merge operation. This indicates that a
  1522. * token merge into the upper domain was rejected. After verifying that
  1523. * this MCS command is valid, is should simply be repeated downward to all
  1524. * attachments.
  1525. */
  1526. Void Domain::PurgeTokensIndication (
  1527. PConnection pOrigConn,
  1528. CTokenIDList *purge_token_list)
  1529. {
  1530. CAttachment *pAtt;
  1531. TokenID token_id;
  1532. /*
  1533. * Check to make sure that this MCS command came from the Top Provider.
  1534. */
  1535. if (pOrigConn == m_pConnToTopProvider)
  1536. {
  1537. /*
  1538. * This is a valid command. Iterate through the attachment list,
  1539. * forwarding the command to everyone below this provider in the
  1540. * domain hierarchy.
  1541. */
  1542. TRACE_OUT(("Domain::PurgeTokensIndication: forwarding indication to all attachments"));
  1543. m_AttachmentList.Reset();
  1544. while (NULL != (pAtt = m_AttachmentList.Iterate()))
  1545. {
  1546. pAtt->PurgeTokensIndication(this, purge_token_list);
  1547. }
  1548. /*
  1549. * Iterate through the list of tokens to be purged, deleting each one.
  1550. */
  1551. purge_token_list->Reset();
  1552. while (NULL != (token_id = purge_token_list->Iterate()))
  1553. {
  1554. /*
  1555. * See if the specified token is in the local information base.
  1556. * If it is not ignore it (this is a normal condition during a
  1557. * purge operation). If it is, then delete it.
  1558. */
  1559. if (m_TokenList2.Find(token_id))
  1560. DeleteToken (token_id);
  1561. }
  1562. }
  1563. else
  1564. {
  1565. /*
  1566. * This indication was received from someone besides the Top Provider.
  1567. * Ignore it.
  1568. */
  1569. ERROR_OUT(("Domain::PurgeTokensIndication: invalid originator=0x%p", pOrigConn));
  1570. }
  1571. }
  1572. /*
  1573. * Void DisconnectProviderUltimatum ()
  1574. *
  1575. * Public
  1576. *
  1577. * Functional Description:
  1578. * This MCS command is generated whenever an attachment becomes invalid.
  1579. * The local provider must respond by breaking all ties to the attachment.
  1580. * If the attachment is to the Top Provider, this will cause the domain
  1581. * to completely eradicate itself (return to the initialized state).
  1582. *
  1583. * Note that when an attachment is lost, it is not removed from the
  1584. * merge queue. This allows this provider to continue to route
  1585. * outstanding merge confirms appropriately, even when one of the
  1586. * attachments is lost. Removing the attachments from the merge queue
  1587. * here will result in outstanding merge confirms being directed to the
  1588. * wrong attachments.
  1589. */
  1590. Void Domain::DisconnectProviderUltimatum (
  1591. CAttachment *pOrigAtt,
  1592. Reason reason)
  1593. {
  1594. /*
  1595. * If we lost the connection to the Top Provider, we have no choice but
  1596. * to purge the entire domain. Ways of preventing this drastic action
  1597. * are being studied, but for now this implementation conforms to the
  1598. * definition of T.125.
  1599. */
  1600. if (pOrigAtt == m_pConnToTopProvider)
  1601. {
  1602. ASSERT(pOrigAtt->IsConnAttachment());
  1603. TRACE_OUT(("Domain::DisconnectProviderUltimatum: purging entire domain"));
  1604. m_pConnToTopProvider = NULL;
  1605. PurgeDomain (reason);
  1606. }
  1607. /*
  1608. * If we lose a downward attachment, then we must free up all resources
  1609. * associated with that attachment. This is handled by a private member
  1610. * function.
  1611. */
  1612. if (m_AttachmentList.Find(pOrigAtt))
  1613. {
  1614. TRACE_OUT(("Domain::DisconnectProviderUltimatum: deleting downward attachment=0x%p", pOrigAtt));
  1615. DeleteAttachment(pOrigAtt, reason);
  1616. }
  1617. /*
  1618. * If we lost an attachment that has an outstanding AttachUserRequest,
  1619. * go ahead and remove it from the attach user queue. Note that this
  1620. * works differently from the merge queue. With AttachUserConfirms, it
  1621. * makes no difference what order they are processed in, so we can do
  1622. * this. With Merge???Confirms, they MUST be processed in order, so
  1623. * we leave the lost attachment in the queue, and allow the confirm
  1624. * command handler to deal with the fact that the attachment is no
  1625. * longer valid.
  1626. */
  1627. while (m_AttachUserQueue.Remove(pOrigAtt))
  1628. {
  1629. TRACE_OUT(("Domain::DisconnectProviderUltimatum: pending user attachment deleted=0x%p", pOrigAtt));
  1630. }
  1631. }
  1632. /*
  1633. * Void RejectUltimatum ()
  1634. *
  1635. * Public
  1636. *
  1637. * Functional Description:
  1638. * This member function is called when a provider detects a PDU that it
  1639. * cannot correctly process, the default behavior is to disconnect the
  1640. * connection that conveys the PDU.
  1641. */
  1642. Void Domain::RejectUltimatum (
  1643. PConnection pOrigConn,
  1644. Diagnostic,
  1645. PUChar,
  1646. ULong)
  1647. {
  1648. /*
  1649. * Send a disconnect provider ultimatum to the attachment that has accused
  1650. * us of wrongdoing.
  1651. */
  1652. pOrigConn->DisconnectProviderUltimatum(REASON_PROVIDER_INITIATED);
  1653. /*
  1654. * Simulate the reception of a disconnect provider ultimatum from that
  1655. * same attachment. This will cause the connection to be cleanly broken
  1656. * on both sides.
  1657. */
  1658. DisconnectProviderUltimatum(pOrigConn, REASON_PROVIDER_INITIATED);
  1659. }
  1660. /*
  1661. * Void AttachUserRequest ()
  1662. *
  1663. * Public
  1664. *
  1665. * Functional Description:
  1666. * This MCS command is initiated by a user attachment, when a new user
  1667. * wishes to attach to this domain. It is forwarded upward to the Top
  1668. * Provider of the domain, who ultimately has to process the request.
  1669. */
  1670. Void Domain::AttachUserRequest (
  1671. CAttachment *pOrigAtt)
  1672. {
  1673. UserID user_id;
  1674. PChannel channel;
  1675. /*
  1676. * Check to see if this is the Top Provider or not. If it is, then the
  1677. * request can be processed locally. If not, then the request must be
  1678. * forwarded upward to the Top Provider.
  1679. */
  1680. if (IsTopProvider())
  1681. {
  1682. /*
  1683. * This is the Top Provider, so process the request here. Check to
  1684. * see if the arbitrated domain parameters allow the addition of
  1685. * a new user to the domain.
  1686. */
  1687. if (Number_Of_Users < Domain_Parameters.max_user_ids)
  1688. {
  1689. /*
  1690. * Also check to see if the arbitrated domain parameters allow the
  1691. * addition of a new channel to the domain (since a user is also
  1692. * channel).
  1693. */
  1694. if (Number_Of_Channels < Domain_Parameters.max_channel_ids)
  1695. {
  1696. /*
  1697. * Adding a new user is not a problem. Get a unique ID to use
  1698. * as the user ID, and then create a new UserChannel object.
  1699. */
  1700. user_id = AllocateDynamicChannel ();
  1701. DBG_SAVE_FILE_LINE
  1702. channel = new UserChannel(user_id, pOrigAtt, this, m_pConnToTopProvider,
  1703. &m_ChannelList2, &m_AttachmentList);
  1704. if (channel != NULL)
  1705. {
  1706. /*
  1707. * Add the new channel object to the channel list. Note
  1708. * that it is not necessary for this object to issue the
  1709. * attach user confirm, because that was handled by the
  1710. * constructor of the UserChannel object.
  1711. */
  1712. TRACE_OUT(("Domain::AttachUserRequest: adding user ID = %04X", (UINT) user_id));
  1713. m_ChannelList2.Insert(user_id, channel);
  1714. Number_Of_Users++;
  1715. Number_Of_Channels++;
  1716. /*
  1717. * If this represents an attachment that did not previously
  1718. * exist, then this must be a local user attachment. Add
  1719. * it to the attachment list as such.
  1720. */
  1721. if (! m_AttachmentList.Find(pOrigAtt))
  1722. {
  1723. ASSERT(pOrigAtt->IsUserAttachment());
  1724. m_AttachmentList.Append(pOrigAtt);
  1725. }
  1726. }
  1727. else
  1728. {
  1729. /*
  1730. * The allocation of the UserChannel object failed. Issue
  1731. * an unsuccessful attach user confirm.
  1732. */
  1733. ERROR_OUT(("Domain::AttachUserRequest: user allocation failed"));
  1734. pOrigAtt->AttachUserConfirm(RESULT_UNSPECIFIED_FAILURE, 0);
  1735. }
  1736. }
  1737. else
  1738. {
  1739. /*
  1740. * The negotiated domain parameters will not allow a new
  1741. * channel to be added to the domain. Reject the request.
  1742. */
  1743. ERROR_OUT(("Domain::AttachUserRequest: too many channels"));
  1744. pOrigAtt->AttachUserConfirm(RESULT_TOO_MANY_CHANNELS, 0);
  1745. }
  1746. }
  1747. else
  1748. {
  1749. /*
  1750. * The negotiated domain parameters will not allow a new user
  1751. * to be added to the domain. Reject the request.
  1752. */
  1753. ERROR_OUT(("Domain::AttachUserRequest: too many users"));
  1754. pOrigAtt->AttachUserConfirm(RESULT_TOO_MANY_USERS, 0);
  1755. }
  1756. }
  1757. else
  1758. {
  1759. /*
  1760. * This is not the Top Provider, so the request must be forwarded
  1761. * upward toward the Top Provider. Add the originator of the request
  1762. * to the attach user queue, so that this provider can properly route
  1763. * the returning confirm (when it arrives).
  1764. */
  1765. TRACE_OUT(("Domain::AttachUserRequest: adding attachment to attach user queue"));
  1766. m_AttachUserQueue.Append(pOrigAtt);
  1767. m_pConnToTopProvider->AttachUserRequest();
  1768. }
  1769. }
  1770. /*
  1771. * Void AttachUserConfirm ()
  1772. *
  1773. * Public
  1774. *
  1775. * Functional Description:
  1776. * This MCS command is initially generated by the Top Provider upon
  1777. * receipt of an AttachUserRequest. It contains the result of that
  1778. * request. If the result is successful, then it also contains the user
  1779. * ID for the new user. This confirm needs to be routed all the was back
  1780. * to the user attachment that originated the request.
  1781. */
  1782. Void Domain::AttachUserConfirm (
  1783. PConnection pOrigConn,
  1784. Result result,
  1785. UserID uidInitiator)
  1786. {
  1787. CAttachment *pAtt;
  1788. PChannel channel;
  1789. CUidList detach_user_list;
  1790. /*
  1791. * Make sure that the request originated with the Top Provider.
  1792. */
  1793. if (pOrigConn == m_pConnToTopProvider)
  1794. {
  1795. /*
  1796. * The reception of this confirm means that there should be an
  1797. * outstanding request. Make sure this is the case before proceeding.*
  1798. */
  1799. if (NULL != (pAtt = m_AttachUserQueue.Get()))
  1800. {
  1801. /*
  1802. * There is an outstanding request. Get the identity of the
  1803. * attachment from which the request originated.
  1804. */
  1805. /*
  1806. * If the result was successful, then it is necessary for this
  1807. * provider to create a UserChannel object in the local information
  1808. * base for the new user.
  1809. */
  1810. if (result == RESULT_SUCCESSFUL)
  1811. {
  1812. /*
  1813. * Make sure the channel ID is not already in use before
  1814. * proceeding.
  1815. */
  1816. if (! m_ChannelList2.Find(uidInitiator))
  1817. {
  1818. /*
  1819. * Create a new UserChannel object, using the ID generated
  1820. * by the Top Provider.
  1821. */
  1822. DBG_SAVE_FILE_LINE
  1823. channel = new UserChannel(uidInitiator, pAtt, this, m_pConnToTopProvider,
  1824. &m_ChannelList2, &m_AttachmentList);
  1825. if (channel != NULL)
  1826. {
  1827. /*
  1828. * Add the UserChannel object to the channel list.
  1829. */
  1830. TRACE_OUT(("Domain::AttachUserConfirm: adding user ID = %04X", (UINT) uidInitiator));
  1831. m_ChannelList2.Insert(uidInitiator, channel);
  1832. Number_Of_Users++;
  1833. Number_Of_Channels++;
  1834. /*
  1835. * If the user's attachment is not already in the
  1836. * attachment list, then this must be a new local
  1837. * attachment. Add it to the attachment list as such.
  1838. */
  1839. if (! m_AttachmentList.Find(pAtt))
  1840. {
  1841. ASSERT(pAtt->IsUserAttachment());
  1842. m_AttachmentList.Append(pAtt);
  1843. }
  1844. }
  1845. else
  1846. {
  1847. /*
  1848. * The local provider was unable to allocate the
  1849. * UserChannel object. This means that the new user
  1850. * must be removed from the domain. To do this, send
  1851. * a DetachUserRequest to the Top Provider and an
  1852. * unsuccessful AttachUserConfirm to the originator
  1853. * of the request.
  1854. */
  1855. ERROR_OUT(("Domain::AttachUserConfirm: user allocation failed"));
  1856. detach_user_list.Append(uidInitiator);
  1857. m_pConnToTopProvider->DetachUserRequest(REASON_PROVIDER_INITIATED, &detach_user_list);
  1858. pAtt->AttachUserConfirm(RESULT_UNSPECIFIED_FAILURE, 0);
  1859. }
  1860. }
  1861. else
  1862. {
  1863. /*
  1864. * The ID associated with this confirm is already in use.
  1865. * This indicates that something is wrong above. This
  1866. * provider has no choice but to ignore the confirm.
  1867. */
  1868. WARNING_OUT(("Domain::AttachUserConfirm: channel ID already in use"));
  1869. }
  1870. }
  1871. else
  1872. {
  1873. /*
  1874. * Since the result of the attach was not successful, this
  1875. * provider does not have to add anything to its channel list.
  1876. * The only required action is to forward the confirm to the
  1877. * originating user.
  1878. */
  1879. TRACE_OUT(("Domain::AttachUserConfirm: echoing failed confirm"));
  1880. pAtt->AttachUserConfirm(result, uidInitiator);
  1881. }
  1882. }
  1883. else
  1884. {
  1885. /*
  1886. * The attach user queue is empty. This probably indicates that
  1887. * the connection to the user who originated the request was lost
  1888. * before the confirm got back. This provider doesn't need to
  1889. * do anything except issue a DetachUserRequest (if the confirm
  1890. * indicates that the attach operation was successful).
  1891. */
  1892. WARNING_OUT(("Domain::AttachUserConfirm: attach user queue empty"));
  1893. if (result == RESULT_SUCCESSFUL)
  1894. {
  1895. TRACE_OUT (("Domain::AttachUserConfirm: sending DetachUserRequest"));
  1896. detach_user_list.Append(uidInitiator);
  1897. m_pConnToTopProvider->DetachUserRequest(REASON_DOMAIN_DISCONNECTED, &detach_user_list);
  1898. }
  1899. }
  1900. }
  1901. else
  1902. {
  1903. /*
  1904. * This confirm was received from someone besides the Top Provider.
  1905. * Ignore it.
  1906. */
  1907. ERROR_OUT(("Domain::AttachUserConfirm: invalid originator=0x%p", pOrigConn));
  1908. }
  1909. }
  1910. /*
  1911. * Void DetachUserRequest ()
  1912. *
  1913. * Public
  1914. *
  1915. * Functional Description:
  1916. * This MCS command is initiated by a user attachment that wishes to leave
  1917. * the domain. After validation, delete the user from the information base
  1918. * pass the request upward.
  1919. */
  1920. Void Domain::DetachUserRequest (
  1921. CAttachment *pOrigAtt,
  1922. Reason reason,
  1923. CUidList *user_id_list)
  1924. {
  1925. UserID uid;
  1926. CUidList detach_user_list;
  1927. /*
  1928. * Iterate through the list of users named to be deleted.
  1929. */
  1930. user_id_list->Reset();
  1931. while (NULL != (uid = user_id_list->Iterate()))
  1932. {
  1933. /*
  1934. * Make sure the user really exists in the sub-tree from which this
  1935. * request originated.
  1936. */
  1937. if (ValidateUserID(uid, pOrigAtt))
  1938. {
  1939. /*
  1940. * Delete the user from the local information base.
  1941. */
  1942. DeleteUser(uid);
  1943. /*
  1944. * Put the user ID into the list of validated user IDs.
  1945. */
  1946. detach_user_list.Append(uid);
  1947. }
  1948. else
  1949. {
  1950. /*
  1951. * There is no such user in the sub-tree from which this request
  1952. * originated.
  1953. */
  1954. WARNING_OUT(("Domain::DetachUserRequest: invalid user ID"));
  1955. }
  1956. }
  1957. /*
  1958. * Check to see if there are any users to be deleted. If so, then process
  1959. * the request.
  1960. */
  1961. if (detach_user_list.IsEmpty() == FALSE)
  1962. {
  1963. /*
  1964. * Check to see if this is the Top Provider.
  1965. */
  1966. if (IsTopProvider())
  1967. {
  1968. /*
  1969. * This is the Top Provider, so issue a detach user indication to
  1970. * all downward attachments.
  1971. */
  1972. TRACE_OUT(("Domain::DetachUserRequest: sending DetachUserIndication to all attachments"));
  1973. CAttachment *pAtt;
  1974. m_AttachmentList.Reset();
  1975. while (NULL != (pAtt = m_AttachmentList.Iterate()))
  1976. {
  1977. pAtt->DetachUserIndication(reason, &detach_user_list);
  1978. }
  1979. }
  1980. else
  1981. {
  1982. /*
  1983. * This is not the Top Provider, so forward the detach user
  1984. * request upward.
  1985. */
  1986. TRACE_OUT(("Domain::DetachUserRequest: forwarding DetachUserRequest to Top Provider"));
  1987. m_pConnToTopProvider->DetachUserRequest(reason, &detach_user_list);
  1988. }
  1989. }
  1990. else
  1991. {
  1992. /*
  1993. * The user ID list contained no valid entries, so ignore the request.
  1994. */
  1995. ERROR_OUT(("Domain::DetachUserRequest: no valid user IDs"));
  1996. }
  1997. }
  1998. /*
  1999. * Void DetachUserIndication ()
  2000. *
  2001. * Public
  2002. *
  2003. * Functional Description:
  2004. * This MCS command is initially sent by the Top Provider in response to
  2005. * a user detaching from the domain (willingly or otherwise). It is
  2006. * forwarded downward in the hierarchy where it will eventually reach all
  2007. * providers and their user attachments.
  2008. */
  2009. Void Domain::DetachUserIndication (
  2010. PConnection pOrigConn,
  2011. Reason reason,
  2012. CUidList *user_id_list)
  2013. {
  2014. UserID uid;
  2015. /*
  2016. * Verify that the indication came from the Top Provider.
  2017. */
  2018. if (pOrigConn == m_pConnToTopProvider)
  2019. {
  2020. /*
  2021. * The first thing to do is repeat the indication to all downward
  2022. * attachments. Keep in mind that this sends the detach indication
  2023. * to user attachments as well as remote connections.
  2024. */
  2025. TRACE_OUT(("Domain::DetachUserIndication: forwarding DetachUserIndication to all attachments"));
  2026. CAttachment *pAtt;
  2027. m_AttachmentList.Reset();
  2028. while (NULL != (pAtt = m_AttachmentList.Iterate()))
  2029. {
  2030. pAtt->DetachUserIndication(reason, user_id_list);
  2031. }
  2032. /*
  2033. * Iterate through the list of users, deleting those that are in
  2034. * the sub-tree of this provider.
  2035. */
  2036. user_id_list->Reset();
  2037. while (NULL != (uid = user_id_list->Iterate()))
  2038. {
  2039. /*
  2040. * Check to see if this user is somewhere in the sub-tree of this
  2041. * provider. If so it is necessary to delete the user channel from
  2042. * the channel list. Note that it is perfectly normal to receive a
  2043. * detach user indication for a user that is not in the sub-tree of
  2044. * the receiving provider.
  2045. */
  2046. if (ValidateUserID(uid, NULL) )
  2047. {
  2048. /*
  2049. * Delete the user from the local information base.
  2050. */
  2051. DeleteUser(uid);
  2052. }
  2053. }
  2054. }
  2055. else
  2056. {
  2057. /*
  2058. * This indication was received from someone besides the Top Provider.
  2059. * Ignore the indication.
  2060. */
  2061. ERROR_OUT(("Domain::DetachUserIndication: invalid originator=0x%p", pOrigConn));
  2062. }
  2063. }
  2064. /*
  2065. * Void ChannelJoinRequest ()
  2066. *
  2067. * Public
  2068. *
  2069. * Functional Description:
  2070. * This MCS command is initially sent by a user attachment that wishes
  2071. * to join a channel. It flows upward in the hierarchy until it reaches
  2072. * a provider who is already joined to the channel. That provider (which
  2073. * is not necessarily the Top Provider), will issue a channel join
  2074. * confirm, indicating whether or not the join was successful.
  2075. */
  2076. Void Domain::ChannelJoinRequest (
  2077. CAttachment *pOrigAtt,
  2078. UserID uidInitiator,
  2079. ChannelID channel_id)
  2080. {
  2081. PChannel channel;
  2082. ChannelID requested_id;
  2083. /*
  2084. * Make sure the requesting user really exists in the sub-tree from which
  2085. * this request originated.
  2086. */
  2087. if (ValidateUserID(uidInitiator, pOrigAtt))
  2088. {
  2089. /*
  2090. * See if the channel already exists in the local information base.
  2091. * If so, then let the Channel object handle the join request.
  2092. */
  2093. if (NULL != (channel = m_ChannelList2.Find(channel_id)))
  2094. {
  2095. TRACE_OUT(("Domain::ChannelJoinRequest: sending join request to channel object"));
  2096. channel->ChannelJoinRequest(pOrigAtt, uidInitiator, channel_id);
  2097. }
  2098. else
  2099. {
  2100. /*
  2101. * The channel does not already exist in the channel list. Check
  2102. * to see if this is the Top Provider. If so, we can try to
  2103. * add the channel to the list. If this is not the Top Provider,
  2104. * then we simply forward the request upward.
  2105. */
  2106. if (IsTopProvider())
  2107. {
  2108. /*
  2109. * Save the value of the channel the user originally attempted
  2110. * to join. This may change if this is a request to join
  2111. * channel 0 (an assigned channel).
  2112. */
  2113. requested_id = channel_id;
  2114. /*
  2115. * We already know the channel does not exist in the channel
  2116. * list. Therefore, this is a valid request only if the
  2117. * channel being joined is a static channel or channel 0 (which
  2118. * is interpreted as a request for an assigned channel).
  2119. * Dynamic channels (those above 1000) can only be joined if
  2120. * they already exist.
  2121. */
  2122. if (requested_id <= 1000)
  2123. {
  2124. /*
  2125. * See if the arbitrated domain parameters will allow the
  2126. * addition of a new channel.
  2127. */
  2128. if (Number_Of_Channels < Domain_Parameters.max_channel_ids)
  2129. {
  2130. /*
  2131. * If this is a request for an assigned channel, then
  2132. * allocate a random channel ID in the dynamic range.
  2133. * Then create a new Channel object.
  2134. */
  2135. if (requested_id == 0)
  2136. channel_id = AllocateDynamicChannel ();
  2137. DBG_SAVE_FILE_LINE
  2138. channel = new Channel(channel_id, this, m_pConnToTopProvider,
  2139. &m_ChannelList2, &m_AttachmentList);
  2140. if (channel != NULL)
  2141. {
  2142. /*
  2143. * The creation of the new channel was successful.
  2144. * Add it to the channel list.
  2145. */
  2146. TRACE_OUT(("Domain::ChannelJoinRequest: adding channel ID = %04X", (UINT) channel_id));
  2147. m_ChannelList2.Insert(channel_id, channel);
  2148. Number_Of_Channels++;
  2149. /*
  2150. * When new channels are created, they are
  2151. * initially empty. So we must join the
  2152. * originating attachment to the newly created
  2153. * attachment. This will also cause a channel
  2154. * join confirm to be issued to the originator.
  2155. */
  2156. channel->ChannelJoinRequest(pOrigAtt, uidInitiator, requested_id);
  2157. }
  2158. else
  2159. {
  2160. /*
  2161. * Allocation of the Channel object failed. We
  2162. * must therefore issue an unsuccessful channel
  2163. * join confirm to the originating attachment.
  2164. */
  2165. ERROR_OUT(("Domain::ChannelJoinRequest: channel allocation failed"));
  2166. pOrigAtt->ChannelJoinConfirm(RESULT_UNSPECIFIED_FAILURE, uidInitiator, requested_id, 0);
  2167. }
  2168. }
  2169. else
  2170. {
  2171. /*
  2172. * Domain parmeters will not allow the addition of
  2173. * any more channels. Fail the request.
  2174. */
  2175. ERROR_OUT(("Domain::ChannelJoinRequest: join denied - too many channels"));
  2176. pOrigAtt->ChannelJoinConfirm(RESULT_TOO_MANY_CHANNELS, uidInitiator, requested_id, 0);
  2177. }
  2178. }
  2179. else
  2180. {
  2181. /*
  2182. * There has been an attempt to join a dynamic channel
  2183. * that doesn't already exist. This is not allowed, so
  2184. * fail the request.
  2185. */
  2186. WARNING_OUT(("Domain::ChannelJoinRequest: attempt to join non-existent dynamic channel"));
  2187. pOrigAtt->ChannelJoinConfirm(RESULT_NO_SUCH_CHANNEL, uidInitiator, requested_id, 0);
  2188. }
  2189. }
  2190. else
  2191. {
  2192. /*
  2193. * The channel does not exist locally, and this is not the
  2194. * Top Provider. That means this is someone else problem.
  2195. * Issue the request upward toward the Top Provider.
  2196. */
  2197. TRACE_OUT(("Domain::ChannelJoinRequest: forwarding join request to Top Provider"));
  2198. m_pConnToTopProvider->ChannelJoinRequest(uidInitiator, channel_id);
  2199. }
  2200. }
  2201. }
  2202. else
  2203. {
  2204. /*
  2205. * There is no such user in the sub-tree from which this request
  2206. * originated. Ignore the request.
  2207. */
  2208. ERROR_OUT(("Domain::ChannelJoinRequest: invalid originator=0x%p", pOrigAtt));
  2209. }
  2210. }
  2211. /*
  2212. * Void ChannelJoinConfirm ()
  2213. *
  2214. * Public
  2215. *
  2216. * Functional Description:
  2217. * This MCS command originates from a provider who receives a channel
  2218. * join request, and has enough information to respond. This is not
  2219. * necessarily the Top Provider. An intermediate can respond if the
  2220. * channel exists in its information base. This confirm is forwarded
  2221. * back to the original requestor, letting it know whether or not the
  2222. * join was successful.
  2223. */
  2224. Void Domain::ChannelJoinConfirm (
  2225. PConnection pOrigConn,
  2226. Result result,
  2227. UserID uidInitiator,
  2228. ChannelID requested_id,
  2229. ChannelID channel_id)
  2230. {
  2231. PChannel channel;
  2232. CChannelIDList channel_leave_list;
  2233. /*
  2234. * Verify that the confirm came from the Top Provider.
  2235. */
  2236. if (pOrigConn == m_pConnToTopProvider)
  2237. {
  2238. /*
  2239. * Make sure that the requesting user is still somewhere in the
  2240. * sub-tree of this provider.
  2241. */
  2242. if (ValidateUserID (uidInitiator, NULL) )
  2243. {
  2244. /*
  2245. * Found out which downward attachment leads to the requesting
  2246. * user.
  2247. */
  2248. if (NULL != (channel = m_ChannelList2.Find(uidInitiator)))
  2249. {
  2250. CAttachment *pAtt = channel->GetAttachment();
  2251. ASSERT(pAtt);
  2252. /*
  2253. * Was the result successful. If is was, then the local provider
  2254. * needs to make sure the channel is in the local channel list.
  2255. * If its not already there, it will have to be created.
  2256. */
  2257. if (result == RESULT_SUCCESSFUL)
  2258. {
  2259. /*
  2260. * See if the named channel already exists in the channel list.
  2261. */
  2262. if (NULL != (channel = m_ChannelList2.Find(channel_id)))
  2263. {
  2264. /*
  2265. * A Channel object already exists for the named channel.
  2266. * Let it handle the join confirm.
  2267. */
  2268. TRACE_OUT(("Domain::ChannelJoinConfirm: sending confirm to channel object"));
  2269. channel->ChannelJoinConfirm(pAtt, result, uidInitiator, requested_id, channel_id);
  2270. }
  2271. else
  2272. {
  2273. /*
  2274. * The new channel will have to be created.
  2275. */
  2276. DBG_SAVE_FILE_LINE
  2277. channel = new Channel(channel_id, this, m_pConnToTopProvider,
  2278. &m_ChannelList2, &m_AttachmentList);
  2279. if (channel != NULL)
  2280. {
  2281. /*
  2282. * Add the newly created channel to the channel list,
  2283. * and then let the Channel object handle the join
  2284. * confirm.
  2285. */
  2286. TRACE_OUT(("Domain::ChannelJoinConfirm: adding channel ID = %04X", (UINT) channel_id));
  2287. m_ChannelList2.Insert(channel_id, channel);
  2288. Number_Of_Channels++;
  2289. channel->ChannelJoinConfirm(pAtt, result, uidInitiator, requested_id, channel_id);
  2290. }
  2291. else
  2292. {
  2293. /*
  2294. * The allocation of the Channel object failed. It
  2295. * is therefore necessary for this provider to cause
  2296. * the channel to be deleted from the domain. It
  2297. * does this by issuing a channel leave request to
  2298. * the Top Provider, and an unsuccessful channel
  2299. * join confirm to the originating user.
  2300. */
  2301. ERROR_OUT(("Domain::ChannelJoinConfirm: channel allocation failed"));
  2302. channel_leave_list.Append(channel_id);
  2303. m_pConnToTopProvider->ChannelLeaveRequest(&channel_leave_list);
  2304. pAtt->ChannelJoinConfirm(RESULT_UNSPECIFIED_FAILURE, uidInitiator, requested_id, 0);
  2305. }
  2306. }
  2307. }
  2308. else
  2309. {
  2310. /*
  2311. * The result was not successful, so this provider does not
  2312. * have to worry about creating the channel. It merely
  2313. * forwards the join confirm to the originating user.
  2314. */
  2315. TRACE_OUT(("Domain::ChannelJoinConfirm: forwarding ChannelJoinConfirm to user"));
  2316. pAtt->ChannelJoinConfirm(result, uidInitiator, requested_id, channel_id);
  2317. }
  2318. }
  2319. else
  2320. {
  2321. ERROR_OUT(("Domain::ChannelJoinConfirm: cannot find the channel"));
  2322. }
  2323. }
  2324. else
  2325. {
  2326. /*
  2327. * The named initiator does not exist in the sub-tree of this
  2328. * provider. This could happen if the user is detached before
  2329. * the confirm returns. It will be necessary to issue a channel
  2330. * leave request upward (if the join was successful).
  2331. */
  2332. WARNING_OUT(("Domain::ChannelJoinConfirm: initiator not found"));
  2333. if (result == RESULT_SUCCESSFUL)
  2334. {
  2335. TRACE_OUT(("Domain::ChannelJoinConfirm: sending ChannelLeaveRequest to Top Provider"));
  2336. channel_leave_list.Append(channel_id);
  2337. m_pConnToTopProvider->ChannelLeaveRequest(&channel_leave_list);
  2338. }
  2339. }
  2340. }
  2341. else
  2342. {
  2343. /*
  2344. * This confirm was received from someone besides the Top Provider.
  2345. * Ignore the indication.
  2346. */
  2347. ERROR_OUT(("Domain::ChannelJoinConfirm: invalid originator=0x%p", pOrigConn));
  2348. }
  2349. }
  2350. /*
  2351. * Void ChannelLeaveRequest ()
  2352. *
  2353. * Public
  2354. *
  2355. * Functional Description:
  2356. * This MCS command is initially issued by a user that wishes to leave a
  2357. * channel. This request will stop cascading upward when it reaches a
  2358. * provider that has more attachments joined to the channel than the
  2359. * one that is leaving. If the requesting user is the only joined to
  2360. * a channel, this request will flow all the way to the Top Provider.
  2361. */
  2362. Void Domain::ChannelLeaveRequest (
  2363. CAttachment *pOrigAtt,
  2364. CChannelIDList *channel_id_list)
  2365. {
  2366. ChannelID chid;
  2367. PChannel channel;
  2368. CChannelIDList channel_leave_list;
  2369. /*
  2370. * Make sure that the attachment leaving the channel really does exist.
  2371. */
  2372. if (m_AttachmentList.Find(pOrigAtt))
  2373. {
  2374. /*
  2375. * Iterate through the list of channels to be left, processing each
  2376. * one independently.
  2377. */
  2378. channel_id_list->Reset();
  2379. while (NULL != (chid = channel_id_list->Iterate()))
  2380. {
  2381. /*
  2382. * Check to make sure that the channel being left really does
  2383. * exist.
  2384. */
  2385. if (NULL != (channel = m_ChannelList2.Find(chid)))
  2386. {
  2387. /*
  2388. * Let the Channel object deal with this request. After
  2389. * sending the leave request to the channel, it is necessary to
  2390. * check the validity of the channel object determine if it
  2391. * should be deleted as a result of this leave operation.
  2392. */
  2393. TRACE_OUT(("Domain::ChannelLeaveRequest: processing leave request for channel ID = %04X", (UINT) chid));
  2394. channel_leave_list.Clear();
  2395. channel_leave_list.Append(chid);
  2396. channel->ChannelLeaveRequest(pOrigAtt, &channel_leave_list);
  2397. if (channel->IsValid () == FALSE)
  2398. DeleteChannel(chid);
  2399. }
  2400. else
  2401. {
  2402. /*
  2403. * The named channel does not exist in the information base.
  2404. * Ignore the request.
  2405. */
  2406. WARNING_OUT(("Domain::ChannelLeaveRequest: received leave request for non-existent channel"));
  2407. }
  2408. }
  2409. }
  2410. else
  2411. {
  2412. /*
  2413. * This request originated from an attachment that does not exist
  2414. * in the sub-tree of this provider.
  2415. */
  2416. ERROR_OUT(("Domain::ChannelLeaveRequest: invalid originator=0x%p", pOrigAtt));
  2417. }
  2418. }
  2419. /*
  2420. * Void ChannelConveneRequest ()
  2421. *
  2422. * Public
  2423. *
  2424. * Functional Description:
  2425. * This MCS command is initially sent by a user that wishes to convene a
  2426. * new private channel. It is forwarded upward to the Top Provider who
  2427. * will attempt to create the private channel.
  2428. */
  2429. Void Domain::ChannelConveneRequest (
  2430. CAttachment *pOrigAtt,
  2431. UserID uidInitiator)
  2432. {
  2433. ChannelID channel_id;
  2434. PChannel channel;
  2435. /*
  2436. * Make sure the requesting user really exists in the sub-tree from which
  2437. * this request originated.
  2438. */
  2439. if (ValidateUserID(uidInitiator, pOrigAtt))
  2440. {
  2441. /*
  2442. * If this is the Top Provider, then the request can be serviced
  2443. * locally. If not, then it must be forwarded upward.
  2444. */
  2445. if (IsTopProvider())
  2446. {
  2447. /*
  2448. * See if the arbitrated domain parameters will allow the
  2449. * addition of a new channel.
  2450. */
  2451. if (Number_Of_Channels < Domain_Parameters.max_channel_ids)
  2452. {
  2453. /*
  2454. * Since this is a request for a private channel, it is
  2455. * necessary to allocate a channel ID from the dynamic range.
  2456. * Then, create the private channel.
  2457. */
  2458. channel_id = AllocateDynamicChannel ();
  2459. DBG_SAVE_FILE_LINE
  2460. channel = new PrivateChannel(channel_id, uidInitiator, this, m_pConnToTopProvider,
  2461. &m_ChannelList2, &m_AttachmentList);
  2462. if (channel != NULL)
  2463. {
  2464. /*
  2465. * The creation of the new private channel was successful.
  2466. * Add it to the channel list. Note that the channel
  2467. * object itself will issue the channel convene confirm.
  2468. */
  2469. TRACE_OUT(("Domain::ChannelConveneRequest: adding channel ID = %04X", (UINT) channel_id));
  2470. m_ChannelList2.Insert(channel_id, channel);
  2471. Number_Of_Channels++;
  2472. }
  2473. else
  2474. {
  2475. /*
  2476. * Allocation of the PrivateChannel object failed. We
  2477. * must therefore issue an unsuccessful channel
  2478. * convene confirm to the originating attachment.
  2479. */
  2480. ERROR_OUT(("Domain::ChannelConveneRequest: channel allocation failed"));
  2481. pOrigAtt->ChannelConveneConfirm(RESULT_UNSPECIFIED_FAILURE, uidInitiator, 0);
  2482. }
  2483. }
  2484. else
  2485. {
  2486. /*
  2487. * Domain parmeters will not allow the addition of
  2488. * any more channels. Fail the request.
  2489. */
  2490. ERROR_OUT(("Domain::ChannelConveneRequest: join denied - too many channels"));
  2491. pOrigAtt->ChannelConveneConfirm(RESULT_TOO_MANY_CHANNELS, uidInitiator, 0);
  2492. }
  2493. }
  2494. else
  2495. {
  2496. /*
  2497. * This is not the Top Provider. That means this is someone elses
  2498. * problem. Issue the request upward toward the Top Provider.
  2499. */
  2500. TRACE_OUT(("Domain::ChannelConveneRequest: forwarding convene request to Top Provider"));
  2501. m_pConnToTopProvider->ChannelConveneRequest(uidInitiator);
  2502. }
  2503. }
  2504. else
  2505. {
  2506. /*
  2507. * There is no such user in the sub-tree from which this request
  2508. * originated. Ignore the request.
  2509. */
  2510. ERROR_OUT(("Domain::ChannelConveneRequest: invalid originator=0x%p", pOrigAtt));
  2511. }
  2512. }
  2513. /*
  2514. * Void ChannelConveneConfirm ()
  2515. *
  2516. * Public
  2517. *
  2518. * Functional Description:
  2519. * This MCS command is initially sent by the Top Provider in response to
  2520. * a previously received ChannelConveneRequest. This command contains the
  2521. * results of the request.
  2522. */
  2523. Void Domain::ChannelConveneConfirm (
  2524. PConnection pOrigConn,
  2525. Result result,
  2526. UserID uidInitiator,
  2527. ChannelID channel_id)
  2528. {
  2529. PChannel channel;
  2530. /*
  2531. * Verify that the confirm came from the Top Provider.
  2532. */
  2533. if (pOrigConn == m_pConnToTopProvider)
  2534. {
  2535. /*
  2536. * Make sure that the requesting user is still somewhere in the
  2537. * sub-tree of this provider.
  2538. */
  2539. if (ValidateUserID (uidInitiator, NULL) )
  2540. {
  2541. /*
  2542. * Found out which downward attachment leads to the requesting
  2543. * user.
  2544. */
  2545. if (NULL != (channel = m_ChannelList2.Find(uidInitiator)))
  2546. {
  2547. CAttachment *pAtt = channel->GetAttachment();
  2548. ASSERT(pAtt);
  2549. /*
  2550. * Was the result successful. If is was, then the local provider
  2551. * needs to create the new private channel in the local information
  2552. * base.
  2553. */
  2554. if (result == RESULT_SUCCESSFUL)
  2555. {
  2556. /*
  2557. * See if the named channel already exists in the channel list.
  2558. * Note that it is an error to receive a channel convene
  2559. * confirm for a channel that already exists. This would
  2560. * indicate a logic error somewhere in the domain hierarchy
  2561. * above this provider.
  2562. */
  2563. if (! m_ChannelList2.Find(channel_id))
  2564. {
  2565. /*
  2566. * The new private channel has to be created.
  2567. */
  2568. DBG_SAVE_FILE_LINE
  2569. channel = new PrivateChannel(channel_id, uidInitiator, this, m_pConnToTopProvider,
  2570. &m_ChannelList2, &m_AttachmentList);
  2571. if (channel != NULL)
  2572. {
  2573. /*
  2574. * Add the newly created channel to the channel list.
  2575. * Let the Channel object handle the convene confirm.
  2576. */
  2577. TRACE_OUT(("Domain::ChannelConveneConfirm: adding channel ID = %04X", (UINT) channel_id));
  2578. m_ChannelList2.Insert(channel_id, channel);
  2579. Number_Of_Channels++;
  2580. }
  2581. else
  2582. {
  2583. /*
  2584. * The allocation of the Channel object failed. It
  2585. * is therefore necessary for this provider to cause
  2586. * the channel to be deleted from the domain. It
  2587. * does this by issuing a channel disband request to
  2588. * the Top Provider, and an unsuccessful channel
  2589. * convene confirm to the originating user.
  2590. */
  2591. ERROR_OUT(("Domain::ChannelConveneConfirm: channel allocation failed"));
  2592. m_pConnToTopProvider->ChannelDisbandRequest(uidInitiator, channel_id);
  2593. pAtt->ChannelConveneConfirm(RESULT_UNSPECIFIED_FAILURE, uidInitiator, 0);
  2594. }
  2595. }
  2596. else
  2597. {
  2598. /*
  2599. * A Channel object already exists for the named channel.
  2600. * This is an error, so report the problem, and ignore
  2601. * the confirm.
  2602. */
  2603. ERROR_OUT(("Domain::ChannelConveneConfirm: channel already exists in channel list"));
  2604. }
  2605. }
  2606. else
  2607. {
  2608. /*
  2609. * The result was not successful, so this provider does not
  2610. * have to worry about creating the channel. It merely
  2611. * forwards the join confirm to the originating user.
  2612. */
  2613. TRACE_OUT(("Domain::ChannelConveneConfirm: forwarding ChannelConveneConfirm to user"));
  2614. pAtt->ChannelConveneConfirm(result, uidInitiator, channel_id);
  2615. }
  2616. }
  2617. else
  2618. {
  2619. ERROR_OUT(("Domain::ChannelConveneConfirm: cannot find the channel"));
  2620. }
  2621. }
  2622. else
  2623. {
  2624. /*
  2625. * The named initiator does not exist in the sub-tree of this
  2626. * provider. This could happen if the user is detached before
  2627. * the confirm returns. Note that since a DetachUserIndication
  2628. * will automatically be issued upward for the lost channel
  2629. * manager, it is unnecessary for this provider to take any
  2630. * special action to eliminate the unowned private channel.
  2631. */
  2632. ERROR_OUT(("Domain::ChannelConveneConfirm: initiator not found"));
  2633. }
  2634. }
  2635. else
  2636. {
  2637. /*
  2638. * This confirm was received from someone besides the Top Provider.
  2639. * Ignore the indication.
  2640. */
  2641. ERROR_OUT(("Domain::ChannelConveneConfirm: invalid originator=0x%p", pOrigConn));
  2642. }
  2643. }
  2644. /*
  2645. * Void ChannelDisbandRequest ()
  2646. *
  2647. * Public
  2648. *
  2649. * Functional Description:
  2650. * This MCS command is initially sent by a user that wishes to disband a
  2651. * private channel that it previously created. If the channel is in the
  2652. * local information base, the request is sent to it. Otherwise, the
  2653. * request is ignored.
  2654. */
  2655. Void Domain::ChannelDisbandRequest (
  2656. CAttachment *pOrigAtt,
  2657. UserID uidInitiator,
  2658. ChannelID channel_id)
  2659. {
  2660. PChannel channel;
  2661. /*
  2662. * Make sure the requesting user really exists in the sub-tree from which
  2663. * this request originated.
  2664. */
  2665. if (ValidateUserID(uidInitiator, pOrigAtt))
  2666. {
  2667. /*
  2668. * Check to see if the specified channel exists in the Channel List.
  2669. */
  2670. if (NULL != (channel = m_ChannelList2.Find(channel_id)))
  2671. {
  2672. /*
  2673. * Send the disband request to the channel object to handle it.
  2674. * Then ask the channel object if this request has resulted in a
  2675. * need for the channel to be deleted. This will occur when the
  2676. * disband request is handled at the Top Provider.
  2677. */
  2678. if (channel->GetChannelType() == PRIVATE_CHANNEL)
  2679. {
  2680. PrivateChannel *pPrivChnl = (PrivateChannel *) channel;
  2681. TRACE_OUT(("Domain::ChannelDisbandRequest: sending disband request to channel object"));
  2682. pPrivChnl->ChannelDisbandRequest(pOrigAtt, uidInitiator, channel_id);
  2683. }
  2684. else
  2685. {
  2686. ERROR_OUT(("Domain::ChannelDisbandRequest: it should be private chanel"));
  2687. }
  2688. if (channel->IsValid () == FALSE)
  2689. DeleteChannel (channel_id);
  2690. }
  2691. else
  2692. {
  2693. /*
  2694. * The channel does not exist in the information base. That means
  2695. * that this request is invalid, and should be ignored.
  2696. */
  2697. ERROR_OUT(("Domain::ChannelDisbandRequest: channel does not exist"));
  2698. }
  2699. }
  2700. else
  2701. {
  2702. /*
  2703. * There is no such user in the sub-tree from which this request
  2704. * originated. Ignore the request.
  2705. */
  2706. ERROR_OUT(("Domain::ChannelDisbandRequest: invalid originator=0x%p", pOrigAtt));
  2707. }
  2708. }
  2709. /*
  2710. * Void ChannelDisbandIndication ()
  2711. *
  2712. * Public
  2713. *
  2714. * Functional Description:
  2715. * This MCS command is initially sent by the Top Provider when it decides
  2716. * to delete a private channel from the domain. It travels downward to
  2717. * all attachments and connections that contain an admitted user or the
  2718. * channel manager in their sub-tree.
  2719. */
  2720. Void Domain::ChannelDisbandIndication (
  2721. PConnection pOrigConn,
  2722. ChannelID channel_id)
  2723. {
  2724. PChannel channel;
  2725. /*
  2726. * Verify that the indication came from the Top Provider.
  2727. */
  2728. if (pOrigConn == m_pConnToTopProvider)
  2729. {
  2730. /*
  2731. * Check to see if the specified channel exists in the Channel List.
  2732. */
  2733. if (NULL != (channel = m_ChannelList2.Find(channel_id)))
  2734. {
  2735. /*
  2736. * Send the disband indication to the channel object to handle it.
  2737. * Then delete the object from the local information base, as it is
  2738. * no longer needed.
  2739. */
  2740. if (channel->GetChannelType() == PRIVATE_CHANNEL)
  2741. {
  2742. PrivateChannel *pPrivChnl = (PrivateChannel *) channel;
  2743. TRACE_OUT(("Domain::ChannelDisbandIndication: sending disband indication to channel object"));
  2744. pPrivChnl->ChannelDisbandIndication(channel_id);
  2745. }
  2746. else
  2747. {
  2748. ERROR_OUT(("Domain::ChannelDisbandIndication: it should be private chanel"));
  2749. }
  2750. if (channel->IsValid () == FALSE)
  2751. DeleteChannel (channel_id);
  2752. }
  2753. else
  2754. {
  2755. /*
  2756. * The channel does not exist in the information base. That means
  2757. * that this indication is invalid, and should be ignored.
  2758. */
  2759. ERROR_OUT(("Domain::ChannelDisbandIndication: channel does not exist"));
  2760. }
  2761. }
  2762. else
  2763. {
  2764. /*
  2765. * This indication was received from someone besides the Top Provider.
  2766. * Ignore the indication.
  2767. */
  2768. ERROR_OUT(("Domain::ChannelDisbandIndication: invalid originator=0x%p", pOrigConn));
  2769. }
  2770. }
  2771. /*
  2772. * Void ChannelAdmitRequest ()
  2773. *
  2774. * Public
  2775. *
  2776. * Functional Description:
  2777. * This MCS command is initially sent by the manager of a private channel
  2778. * when it wishes to expand the authorized user list of that channel. If
  2779. * the channel is in the local information base, the request is sent to it.
  2780. * Otherwise, the request is ignored.
  2781. */
  2782. Void Domain::ChannelAdmitRequest (
  2783. CAttachment *pOrigAtt,
  2784. UserID uidInitiator,
  2785. ChannelID channel_id,
  2786. CUidList *user_id_list)
  2787. {
  2788. PChannel channel;
  2789. /*
  2790. * Make sure the requesting user really exists in the sub-tree from which
  2791. * this request originated.
  2792. */
  2793. if (ValidateUserID(uidInitiator, pOrigAtt))
  2794. {
  2795. /*
  2796. * Check to see if the specified channel exists in the Channel List.
  2797. */
  2798. if (NULL != (channel = m_ChannelList2.Find(channel_id)))
  2799. {
  2800. if (channel->GetChannelType() == PRIVATE_CHANNEL)
  2801. {
  2802. PrivateChannel *pPrivChnl = (PrivateChannel *) channel;
  2803. /*
  2804. * Send the admit request to the channel object to handle it.
  2805. */
  2806. TRACE_OUT(("Domain::ChannelAdmitRequest: sending admit request to channel object"));
  2807. pPrivChnl->ChannelAdmitRequest(pOrigAtt, uidInitiator, channel_id, user_id_list);
  2808. }
  2809. else
  2810. {
  2811. ERROR_OUT(("Domain::ChannelAdmitRequest: it should be private chanel"));
  2812. }
  2813. }
  2814. else
  2815. {
  2816. /*
  2817. * The channel does not exist in the information base. That means
  2818. * that this request is invalid, and should be ignored.
  2819. */
  2820. ERROR_OUT(("Domain::ChannelAdmitRequest: channel does not exist"));
  2821. }
  2822. }
  2823. else
  2824. {
  2825. /*
  2826. * There is no such user in the sub-tree from which this request
  2827. * originated. Ignore the request.
  2828. */
  2829. ERROR_OUT(("Domain::ChannelAdmitRequest: invalid originator=0x%p", pOrigAtt));
  2830. }
  2831. }
  2832. /*
  2833. * Void ChannelAdmitIndication ()
  2834. *
  2835. * Public
  2836. *
  2837. * Functional Description:
  2838. * This MCS command is initially sent by the Top Provider when it receives
  2839. * a channel admit indication from the manager of a private channel. This
  2840. * indication is broadcast downward to all providers that contain an
  2841. * admitted user somewhere in their sub-tree. A side-effect of this
  2842. * indication is that a private channel will be created in the information
  2843. * base if one does not already exist.
  2844. */
  2845. Void Domain::ChannelAdmitIndication (
  2846. PConnection pOrigConn,
  2847. UserID uidInitiator,
  2848. ChannelID channel_id,
  2849. CUidList *user_id_list)
  2850. {
  2851. PChannel channel;
  2852. /*
  2853. * Verify that the indication came from the Top Provider.
  2854. */
  2855. if (pOrigConn == m_pConnToTopProvider)
  2856. {
  2857. /*
  2858. * Check to see if the specified channel exists in the Channel List.
  2859. */
  2860. if (NULL != (channel = m_ChannelList2.Find(channel_id)))
  2861. {
  2862. if (channel->GetChannelType() == PRIVATE_CHANNEL)
  2863. {
  2864. PrivateChannel *pPrivChnl = (PrivateChannel *) channel;
  2865. /*
  2866. * Send the admit indication to the channel object to handle it.
  2867. */
  2868. TRACE_OUT(("Domain::ChannelAdmitIndication: sending admit indication to channel object"));
  2869. pPrivChnl->ChannelAdmitIndication(pOrigConn, uidInitiator, channel_id, user_id_list);
  2870. }
  2871. else
  2872. {
  2873. ERROR_OUT(("Domain::ChannelAdmitIndication: it should be private chanel"));
  2874. }
  2875. }
  2876. else
  2877. {
  2878. /*
  2879. * Since the private channel does not exist in the information
  2880. * base, it will be necessary to create one. After it is created,
  2881. * it can handle the channel admit indication.
  2882. */
  2883. DBG_SAVE_FILE_LINE
  2884. channel = new PrivateChannel(channel_id, uidInitiator, this, m_pConnToTopProvider,
  2885. &m_ChannelList2, &m_AttachmentList);
  2886. if (channel != NULL)
  2887. {
  2888. PrivateChannel *pPrivChnl = (PrivateChannel *) channel;
  2889. /*
  2890. * Put the newly created private channel into the domain
  2891. * information base.
  2892. */
  2893. TRACE_OUT(("Domain::ChannelAdmitIndication: adding channel ID = %04X", (UINT) channel_id));
  2894. m_ChannelList2.Insert(channel_id, channel);
  2895. Number_Of_Channels++;
  2896. /*
  2897. * Send the admit indication to the new channel object to
  2898. * handle it.
  2899. */
  2900. pPrivChnl->ChannelAdmitIndication(pOrigConn, uidInitiator, channel_id, user_id_list);
  2901. }
  2902. else
  2903. {
  2904. /*
  2905. * We have been told by the Top Provider to create a private
  2906. * channel, but we can't due to a resource shortage. We also
  2907. * can't purge the channel from the domain since the channel
  2908. * manager does not exist in the sub-tree of this provider.
  2909. * We are therefore out of sync with the Top Provider, and
  2910. * there is nothing we can do about it (except for possibly
  2911. * disconnecting from the Top Provider and purging the entire
  2912. * domain from this node downward).
  2913. */
  2914. ERROR_OUT(("Domain::ChannelAdmitIndication: channel allocation failure"));
  2915. }
  2916. }
  2917. }
  2918. else
  2919. {
  2920. /*
  2921. * This indication was received from someone besides the Top Provider.
  2922. * Ignore the indication.
  2923. */
  2924. WARNING_OUT(("Domain::ChannelAdmitIndication: invalid originator=0x%p", pOrigConn));
  2925. }
  2926. }
  2927. /*
  2928. * Void ChannelExpelRequest ()
  2929. *
  2930. * Public
  2931. *
  2932. * Functional Description:
  2933. * This MCS command is initially sent by the manager of a private channel
  2934. * when it wishes to shrink the authorized user list of that channel. If
  2935. * the channel is in the local information base, the request is sent to it.
  2936. * Otherwise, the request is ignored.
  2937. */
  2938. Void Domain::ChannelExpelRequest (
  2939. CAttachment *pOrigAtt,
  2940. UserID uidInitiator,
  2941. ChannelID channel_id,
  2942. CUidList *user_id_list)
  2943. {
  2944. PChannel channel;
  2945. /*
  2946. * Make sure the requesting user really exists in the sub-tree from which
  2947. * this request originated.
  2948. */
  2949. if (ValidateUserID(uidInitiator, pOrigAtt))
  2950. {
  2951. /*
  2952. * Check to see if the specified channel exists in the Channel List.
  2953. */
  2954. if (NULL != (channel = m_ChannelList2.Find(channel_id)))
  2955. {
  2956. if (channel->GetChannelType() == PRIVATE_CHANNEL)
  2957. {
  2958. PrivateChannel *pPrivChnl = (PrivateChannel *) channel;
  2959. /*
  2960. * Send the admit request to the channel object to handle it.
  2961. */
  2962. TRACE_OUT(("Domain::ChannelExpelRequest: "
  2963. "sending expel request to channel object"));
  2964. pPrivChnl->ChannelExpelRequest(pOrigAtt, uidInitiator, channel_id, user_id_list);
  2965. }
  2966. else
  2967. {
  2968. ERROR_OUT(("Domain::ChannelExpelRequest: it should be private chanel"));
  2969. }
  2970. }
  2971. else
  2972. {
  2973. /*
  2974. * The channel does not exist in the information base. That means
  2975. * that this request is invalid, and should be ignored.
  2976. */
  2977. WARNING_OUT(("Domain::ChannelExpelRequest: channel does not exist"));
  2978. }
  2979. }
  2980. else
  2981. {
  2982. /*
  2983. * There is no such user in the sub-tree from which this request
  2984. * originated. Ignore the request.
  2985. */
  2986. WARNING_OUT(("Domain::ChannelExpelRequest: invalid originator=0x%p", pOrigAtt));
  2987. }
  2988. }
  2989. /*
  2990. * Void ChannelExpelIndication ()
  2991. *
  2992. * Public
  2993. *
  2994. * Functional Description:
  2995. * This MCS command is initially sent by the Top Provider when it receives
  2996. * a request from the manager of a private channel to reduce the
  2997. * authorized user list. It travels downward to all attachments and
  2998. * connections that contain an admitted user or the channel manager in
  2999. * their sub-tree.
  3000. */
  3001. Void Domain::ChannelExpelIndication (
  3002. PConnection pOrigConn,
  3003. ChannelID channel_id,
  3004. CUidList *user_id_list)
  3005. {
  3006. PChannel channel;
  3007. /*
  3008. * Verify that the indication came from the Top Provider.
  3009. */
  3010. if (pOrigConn == m_pConnToTopProvider)
  3011. {
  3012. /*
  3013. * Check to see if the specified channel exists in the Channel List.
  3014. */
  3015. if (NULL != (channel = m_ChannelList2.Find(channel_id)))
  3016. {
  3017. if (channel->GetChannelType() == PRIVATE_CHANNEL)
  3018. {
  3019. PrivateChannel *pPrivChnl = (PrivateChannel *) channel;
  3020. /*
  3021. * Send the expel indication to the channel object to handle it.
  3022. * Then check to see if the channel is still valid (delete it
  3023. * if not). This would occur if the expel results in an empty
  3024. * admitted user list, and the channel manager is also not in the
  3025. * sub-tree of this provider.
  3026. */
  3027. TRACE_OUT(("Domain::ChannelExpelIndication: sending expel indication to channel object"));
  3028. pPrivChnl->ChannelExpelIndication(pOrigConn, channel_id, user_id_list);
  3029. }
  3030. else
  3031. {
  3032. ERROR_OUT(("Domain::ChannelExpelIndication: it should be private chanel"));
  3033. }
  3034. if (channel->IsValid () == FALSE)
  3035. DeleteChannel (channel_id);
  3036. }
  3037. else
  3038. {
  3039. /*
  3040. * The channel does not exist in the information base. That means
  3041. * that this indication is invalid, and should be ignored.
  3042. */
  3043. ERROR_OUT(("Domain::ChannelExpelIndication: channel does not exist"));
  3044. }
  3045. }
  3046. else
  3047. {
  3048. /*
  3049. * This indication was received from someone besides the Top Provider.
  3050. * Ignore the indication.
  3051. */
  3052. ERROR_OUT(("Domain::ChannelExpelIndication: invalid originator=0x%p", pOrigConn));
  3053. }
  3054. }
  3055. /*
  3056. * Void SendDataRequest ()
  3057. *
  3058. * Public
  3059. *
  3060. * Functional Description:
  3061. * This MCS command is initially issued by a user attachment that wishes
  3062. * to send data on a particular channel in this domain. The request will
  3063. * flow upward all the way to the Top Provider. It will also cause
  3064. * send data indications to be sent downward to all other attachments
  3065. * that are joined to the channel.
  3066. */
  3067. Void Domain::SendDataRequest (
  3068. CAttachment *pOrigAtt,
  3069. UINT type,
  3070. PDataPacket data_packet)
  3071. {
  3072. PChannel channel;
  3073. /*
  3074. * Make sure the requesting user really exists in the sub-tree from which
  3075. * this request originated.
  3076. */
  3077. if (ValidateUserID(data_packet->GetInitiator(), pOrigAtt))
  3078. {
  3079. /*
  3080. * See if the channel exists in the local information base. If it does
  3081. * then let the Channel object handle the routing of the data. If
  3082. * it does not exist, then simply forward the request upward to be
  3083. * handled by the next higher provider (unless this is the Top
  3084. * Provider).
  3085. */
  3086. if (NULL != (channel = m_ChannelList2.Find(data_packet->GetChannelID())))
  3087. channel->SendDataRequest(pOrigAtt, type, data_packet);
  3088. else if (! IsTopProvider())
  3089. m_pConnToTopProvider->SendDataRequest(data_packet);
  3090. }
  3091. else
  3092. {
  3093. /*
  3094. * There is no such user in the sub-tree from which this request
  3095. * originated. Ignore the request.
  3096. */
  3097. WARNING_OUT (("Domain::SendDataRequest: invalid originator=0x%p, uidInitiator=%d", pOrigAtt, data_packet->GetInitiator()));
  3098. }
  3099. }
  3100. /*
  3101. * Void SendDataIndication ()
  3102. *
  3103. * Public
  3104. *
  3105. * Functional Description:
  3106. * This MCS command is issued by all providers that receive a send data
  3107. * request on a channel to which one of their attachments is joined. It
  3108. * delivers data in a non-uniform fashion to all users joined to the
  3109. * named channel.
  3110. */
  3111. Void Domain::SendDataIndication (
  3112. PConnection pOrigConn,
  3113. UINT type,
  3114. PDataPacket data_packet)
  3115. {
  3116. PChannel channel;
  3117. /*
  3118. * Verify that the indication came from the Top Provider.
  3119. */
  3120. if (pOrigConn == m_pConnToTopProvider)
  3121. {
  3122. /*
  3123. * See if the channel exists in the local information base. If it does
  3124. * then let the Channel object handle the routing of the data. If
  3125. * it does not exist, then ignore the request.
  3126. */
  3127. if (NULL != (channel = m_ChannelList2.Find(data_packet->GetChannelID())))
  3128. channel->SendDataIndication(pOrigConn, type, data_packet);
  3129. }
  3130. else
  3131. {
  3132. /*
  3133. * This indication was received from someone besides the Top Provider.
  3134. * Ignore the indication.
  3135. */
  3136. WARNING_OUT (("Domain::SendDataIndication: invalid originator=0x%p, initiator=%d", pOrigConn, data_packet->GetInitiator()));
  3137. }
  3138. }
  3139. /*
  3140. * Void TokenGrabRequest ()
  3141. *
  3142. * Public
  3143. *
  3144. * Functional Description:
  3145. * This MCS command is initially sent by a user attachment that wishes
  3146. * to grab a token. It flows upward to the Top Provider, who attempts
  3147. * to satisfy the request.
  3148. */
  3149. Void Domain::TokenGrabRequest (
  3150. CAttachment *pOrigAtt,
  3151. UserID uidInitiator,
  3152. TokenID token_id)
  3153. {
  3154. PToken token;
  3155. /*
  3156. * Make sure the requesting user really exists in the sub-tree from which
  3157. * this request originated.
  3158. */
  3159. if (ValidateUserID(uidInitiator, pOrigAtt))
  3160. {
  3161. /*
  3162. * If the token already exists in the token list, then let the Token
  3163. * object deal with the request.
  3164. */
  3165. if (NULL != (token = m_TokenList2.Find(token_id)))
  3166. {
  3167. TRACE_OUT(("Domain::TokenGrabRequest: sending grab request to token object"));
  3168. token->TokenGrabRequest(pOrigAtt, uidInitiator, token_id);
  3169. }
  3170. else
  3171. {
  3172. /*
  3173. * The token does not exist yet. Check to see if this is the Top
  3174. * Provider. If it is, then the request can be processed locally.
  3175. * Otherwise, forward the request upward.
  3176. */
  3177. if (IsTopProvider())
  3178. {
  3179. /*
  3180. * Check to see if the arbitrated domain parameters will allow
  3181. * the addition of another token.
  3182. */
  3183. if (Number_Of_Tokens < Domain_Parameters.max_token_ids)
  3184. {
  3185. /*
  3186. * Try to create a new Token object.
  3187. */
  3188. DBG_SAVE_FILE_LINE
  3189. token = new Token(token_id, this, m_pConnToTopProvider, &m_ChannelList2, &m_AttachmentList);
  3190. if (token != NULL)
  3191. {
  3192. /*
  3193. * Put the newly created Token object into the token
  3194. * list. Then pass the grab request to it.
  3195. */
  3196. TRACE_OUT(("Domain::TokenGrabRequest: adding token ID = %04X", (UINT) token_id));
  3197. m_TokenList2.Append(token_id, token);
  3198. Number_Of_Tokens++;
  3199. token->TokenGrabRequest(pOrigAtt, uidInitiator, token_id);
  3200. }
  3201. else
  3202. {
  3203. /*
  3204. * The allocation of the Token object failed. It is
  3205. * therefore necessary to fail the request.
  3206. */
  3207. ERROR_OUT(("Domain::TokenGrabRequest: token allocation failed"));
  3208. pOrigAtt->TokenGrabConfirm(RESULT_UNSPECIFIED_FAILURE, uidInitiator, token_id, TOKEN_NOT_IN_USE);
  3209. }
  3210. }
  3211. else
  3212. {
  3213. /*
  3214. * The arbitrated domain parameters will not allow the
  3215. * creation of another token in this domain. So fail
  3216. * the request.
  3217. */
  3218. ERROR_OUT(("Domain::TokenGrabRequest: grab denied - too many tokens"));
  3219. pOrigAtt->TokenGrabConfirm(RESULT_TOO_MANY_TOKENS, uidInitiator, token_id, TOKEN_NOT_IN_USE);
  3220. }
  3221. }
  3222. else
  3223. {
  3224. /*
  3225. * This is not the Top Provider. Forward the request upward.
  3226. */
  3227. TRACE_OUT(("Domain::TokenGrabRequest: forwarding grab request to Top Provider"));
  3228. m_pConnToTopProvider->TokenGrabRequest(uidInitiator, token_id);
  3229. }
  3230. }
  3231. }
  3232. else
  3233. {
  3234. /*
  3235. * There is no such user in the sub-tree from which this request
  3236. * originated. Ignore the request.
  3237. */
  3238. ERROR_OUT(("Domain::TokenGrabRequest: invalid originator=0x%p", pOrigAtt));
  3239. }
  3240. }
  3241. /*
  3242. * Void TokenGrabConfirm ()
  3243. *
  3244. * Public
  3245. *
  3246. * Functional Description:
  3247. * This MCS command is initially sent by the Top Provider upon receipt of
  3248. * a grab request. It is sent back to the initiating user, containing
  3249. * the result of the request.
  3250. */
  3251. Void Domain::TokenGrabConfirm (
  3252. PConnection pOrigConn,
  3253. Result result,
  3254. UserID uidInitiator,
  3255. TokenID token_id,
  3256. TokenStatus token_status)
  3257. {
  3258. PToken token;
  3259. /*
  3260. * Verify that the confirm came from the Top Provider.
  3261. */
  3262. if (pOrigConn == m_pConnToTopProvider)
  3263. {
  3264. /*
  3265. * See if the token already exists in the local information base. If
  3266. * so, let it handle this.
  3267. */
  3268. if (NULL != (token = m_TokenList2.Find(token_id)))
  3269. {
  3270. TRACE_OUT(("Domain::TokenGrabConfirm: sending grab confirm to token object"));
  3271. token->TokenGrabConfirm(result, uidInitiator, token_id, token_status);
  3272. }
  3273. else
  3274. {
  3275. PChannel channel;
  3276. /*
  3277. * Make sure that the requesting user is still somewhere in the
  3278. * sub-tree of this provider.
  3279. */
  3280. if (ValidateUserID (uidInitiator, NULL) )
  3281. {
  3282. /*
  3283. * Determine which attachment leads to the initiating user.
  3284. */
  3285. if (NULL != (channel = m_ChannelList2.Find(uidInitiator)))
  3286. {
  3287. CAttachment *pAtt = channel->GetAttachment();
  3288. ASSERT(pAtt);
  3289. /*
  3290. * If the result of the request is successful, then it is
  3291. * necessary to create the token in the local information base.
  3292. */
  3293. if (result == RESULT_SUCCESSFUL)
  3294. {
  3295. /*
  3296. * Create the token.
  3297. */
  3298. DBG_SAVE_FILE_LINE
  3299. token = new Token(token_id, this, m_pConnToTopProvider, &m_ChannelList2, &m_AttachmentList);
  3300. if (token != NULL)
  3301. {
  3302. /*
  3303. * Put the newly created Token object into the token
  3304. * list. Then pass the grab confirm to it.
  3305. */
  3306. TRACE_OUT(("Domain::TokenGrabConfirm: adding token ID = %04X", (UINT) token_id));
  3307. m_TokenList2.Append(token_id, token);
  3308. Number_Of_Tokens++;
  3309. token->TokenGrabConfirm(result, uidInitiator, token_id, token_status);
  3310. }
  3311. else
  3312. {
  3313. /*
  3314. * The creation of the token failed. It is therefore
  3315. * necessary to send a failed confirm to the initiating
  3316. * user, as well as a token release request to the Top
  3317. * Provider.
  3318. */
  3319. ERROR_OUT(("Domain::TokenGrabConfirm: token creation failed"));
  3320. m_pConnToTopProvider->TokenReleaseRequest(uidInitiator, token_id);
  3321. pAtt->TokenGrabConfirm(RESULT_UNSPECIFIED_FAILURE, uidInitiator, token_id, TOKEN_NOT_IN_USE);
  3322. }
  3323. }
  3324. else
  3325. {
  3326. /*
  3327. * The confirm was unsuccessful, so there is no need to
  3328. * create a token in the information base. Just forward
  3329. * the confirm to the initiating user.
  3330. */
  3331. TRACE_OUT(("Domain::TokenGrabConfirm: forwarding failed grab confirm"));
  3332. pAtt->TokenGrabConfirm(result, uidInitiator, token_id, token_status);
  3333. }
  3334. }
  3335. else
  3336. {
  3337. ERROR_OUT(("Domain::TokenGrabConfirm: cannot find channel"));
  3338. }
  3339. }
  3340. else
  3341. {
  3342. /*
  3343. * The named initiator does not exist in the sub-tree of this
  3344. * provider. Ignore the confirm.
  3345. */
  3346. ERROR_OUT(("Domain::TokenGrabConfirm: invalid initiator, uidInitiator=%u", (UINT) uidInitiator));
  3347. }
  3348. }
  3349. }
  3350. else
  3351. {
  3352. /*
  3353. * This confirm was received from someone besides the Top Provider.
  3354. * Ignore the confirm.
  3355. */
  3356. ERROR_OUT(("Domain::TokenGrabConfirm: invalid originator=0x%p", pOrigConn));
  3357. }
  3358. }
  3359. /*
  3360. * Void TokenInhibitRequest ()
  3361. *
  3362. * Public
  3363. *
  3364. * Functional Description:
  3365. * This MCS command is initially sent by a user attachment that wishes
  3366. * to inhibit a token. It flows upward to the Top Provider, who attempts
  3367. * to satisfy the request.
  3368. */
  3369. Void Domain::TokenInhibitRequest (
  3370. CAttachment *pOrigAtt,
  3371. UserID uidInitiator,
  3372. TokenID token_id)
  3373. {
  3374. PToken token;
  3375. /*
  3376. * Make sure the requesting user really exists in the sub-tree from which
  3377. * this request originated.
  3378. */
  3379. if (ValidateUserID(uidInitiator, pOrigAtt))
  3380. {
  3381. /*
  3382. * If the token already exists in the token list, then let the Token
  3383. * object deal with the request.
  3384. */
  3385. if (NULL != (token = m_TokenList2.Find(token_id)))
  3386. {
  3387. TRACE_OUT(("Domain::TokenInhibitRequest: sending inhibit request to token object"));
  3388. token->TokenInhibitRequest(pOrigAtt, uidInitiator, token_id);
  3389. }
  3390. else
  3391. {
  3392. /*
  3393. * The token does not exist yet. Check to see if this is the Top
  3394. * Provider. If it is, then the request can be processed locally.
  3395. * Otherwise, forward the request upward.
  3396. */
  3397. if (IsTopProvider())
  3398. {
  3399. /*
  3400. * Check to see if the arbitrated domain parameters will allow
  3401. * the addition of another token.
  3402. */
  3403. if (Number_Of_Tokens < Domain_Parameters.max_token_ids)
  3404. {
  3405. /*
  3406. * Try to create a new Token object.
  3407. */
  3408. DBG_SAVE_FILE_LINE
  3409. token = new Token(token_id, this, m_pConnToTopProvider, &m_ChannelList2, &m_AttachmentList);
  3410. if (token != NULL)
  3411. {
  3412. /*
  3413. * Put the newly created Token object into the token
  3414. * list. Then pass the inhibit request to it.
  3415. */
  3416. TRACE_OUT(("Domain::TokenInhibitRequest: adding token ID = %04X", (UINT) token_id));
  3417. m_TokenList2.Append(token_id, token);
  3418. Number_Of_Tokens++;
  3419. token->TokenInhibitRequest(pOrigAtt, uidInitiator, token_id);
  3420. }
  3421. else
  3422. {
  3423. /*
  3424. * The allocation of the Token object failed. It is
  3425. * therefore necessary to fail the request.
  3426. */
  3427. ERROR_OUT(("Domain::TokenInhibitRequest: token allocation failed"));
  3428. pOrigAtt->TokenInhibitConfirm(RESULT_UNSPECIFIED_FAILURE, uidInitiator, token_id, TOKEN_NOT_IN_USE);
  3429. }
  3430. }
  3431. else
  3432. {
  3433. /*
  3434. * The arbitrated domain parameters will not allow the
  3435. * creation of another token in this domain. So fail
  3436. * the request.
  3437. */
  3438. ERROR_OUT(("Domain::TokenInhibitRequest: inhibit denied - too many tokens"));
  3439. pOrigAtt->TokenInhibitConfirm(RESULT_TOO_MANY_TOKENS, uidInitiator, token_id, TOKEN_NOT_IN_USE);
  3440. }
  3441. }
  3442. else
  3443. {
  3444. /*
  3445. * This is not the Top Provider. Forward the request upward.
  3446. */
  3447. TRACE_OUT(("Domain::TokenInhibitRequest: forwarding inhibit request to Top Provider"));
  3448. m_pConnToTopProvider->TokenInhibitRequest(uidInitiator, token_id);
  3449. }
  3450. }
  3451. }
  3452. else
  3453. {
  3454. /*
  3455. * There is no such user in the sub-tree from which this request
  3456. * originated. Ignore the request.
  3457. */
  3458. ERROR_OUT(("Domain::TokenInhibitRequest: invalid originator=0x%p", pOrigAtt));
  3459. }
  3460. }
  3461. /*
  3462. * Void TokenInhibitConfirm ()
  3463. *
  3464. * Public
  3465. *
  3466. * Functional Description:
  3467. * This MCS command is initially sent by the Top Provider upon receipt of
  3468. * a inhibit request. It is sent back to the initiating user, containing
  3469. * the result of the request.
  3470. */
  3471. Void Domain::TokenInhibitConfirm (
  3472. PConnection pOrigConn,
  3473. Result result,
  3474. UserID uidInitiator,
  3475. TokenID token_id,
  3476. TokenStatus token_status)
  3477. {
  3478. PToken token;
  3479. /*
  3480. * Verify that the confirm came from the Top Provider.
  3481. */
  3482. if (pOrigConn == m_pConnToTopProvider)
  3483. {
  3484. /*
  3485. * See if the token already exists in the local information base. If
  3486. * so, let it handle this.
  3487. */
  3488. if (NULL != (token = m_TokenList2.Find(token_id)))
  3489. {
  3490. TRACE_OUT(("Domain::TokenInhibitConfirm: sending inhibit confirm to token object"));
  3491. token->TokenInhibitConfirm(result, uidInitiator, token_id, token_status);
  3492. }
  3493. else
  3494. {
  3495. PChannel channel;
  3496. /*
  3497. * Make sure that the requesting user is still somewhere in the
  3498. * sub-tree of this provider.
  3499. */
  3500. if (ValidateUserID (uidInitiator, NULL) )
  3501. {
  3502. /*
  3503. * Determine which attachment leads to the requesting user.
  3504. */
  3505. if (NULL != (channel = m_ChannelList2.Find(uidInitiator)))
  3506. {
  3507. CAttachment *pAtt = channel->GetAttachment();
  3508. ASSERT(pAtt);
  3509. /*
  3510. * If the result of the request is successful, then it is
  3511. * necessary to create the token in the local information base.
  3512. */
  3513. if (result == RESULT_SUCCESSFUL)
  3514. {
  3515. /*
  3516. * Create the token.
  3517. */
  3518. DBG_SAVE_FILE_LINE
  3519. token = new Token(token_id, this, m_pConnToTopProvider, &m_ChannelList2, &m_AttachmentList);
  3520. if (token != NULL)
  3521. {
  3522. /*
  3523. * Put the newly created Token object into the token
  3524. * list. Then pass the inhibit confirm to it.
  3525. */
  3526. TRACE_OUT(("Domain::TokenInhibitConfirm: adding token ID = %04X", (UINT) token_id));
  3527. m_TokenList2.Append(token_id, token);
  3528. Number_Of_Tokens++;
  3529. token->TokenInhibitConfirm(result, uidInitiator, token_id, token_status);
  3530. }
  3531. else
  3532. {
  3533. /*
  3534. * The creation of the token failed. It is therefore
  3535. * necessary to send a failed confirm to the initiating
  3536. * user, as well as a token release request to the Top
  3537. * Provider.
  3538. */
  3539. ERROR_OUT(("Domain::TokenInhibitConfirm: token creation failed"));
  3540. m_pConnToTopProvider->TokenReleaseRequest(uidInitiator, token_id);
  3541. pAtt->TokenInhibitConfirm(RESULT_UNSPECIFIED_FAILURE, uidInitiator, token_id, TOKEN_NOT_IN_USE);
  3542. }
  3543. }
  3544. else
  3545. {
  3546. /*
  3547. * The confirm was unsuccessful, so there is no need to
  3548. * create a token in the information base. Just forward
  3549. * the confirm to the initiating user.
  3550. */
  3551. ERROR_OUT(("Domain::TokenInhibitConfirm: forwarding failed inhibit confirm"));
  3552. pAtt->TokenInhibitConfirm(result, uidInitiator, token_id, token_status);
  3553. }
  3554. }
  3555. else
  3556. {
  3557. ERROR_OUT(("Domain::TokenInhibitConfirm: cannot find channel"));
  3558. }
  3559. }
  3560. else
  3561. {
  3562. /*
  3563. * The named initiator does not exist in the sub-tree of this
  3564. * provider. Ignore the confirm.
  3565. */
  3566. ERROR_OUT(("Domain::TokenInhibitConfirm: initiator not valid, uidInitiator=%u", (UINT) uidInitiator));
  3567. }
  3568. }
  3569. }
  3570. else
  3571. {
  3572. /*
  3573. * This confirm was received from someone besides the Top Provider.
  3574. * Ignore the confirm.
  3575. */
  3576. ERROR_OUT(("Domain::TokenInhibitConfirm: invalid originator=0x%p", pOrigConn));
  3577. }
  3578. }
  3579. /*
  3580. * Void TokenGiveRequest ()
  3581. *
  3582. * Public
  3583. *
  3584. * Functional Description:
  3585. */
  3586. Void Domain::TokenGiveRequest (
  3587. CAttachment *pOrigAtt,
  3588. PTokenGiveRecord pTokenGiveRec)
  3589. {
  3590. PToken token;
  3591. /*
  3592. * Make sure the requesting user really exists in the sub-tree from which
  3593. * this request originated.
  3594. */
  3595. if (ValidateUserID(pTokenGiveRec->uidInitiator, pOrigAtt))
  3596. {
  3597. /*
  3598. * If the token already exists in the token list, then let the
  3599. * Token object deal with the request.
  3600. */
  3601. if (NULL != (token = m_TokenList2.Find(pTokenGiveRec->token_id)))
  3602. {
  3603. TRACE_OUT(("Domain::TokenGiveRequest: sending give request to token object"));
  3604. token->TokenGiveRequest(pOrigAtt, pTokenGiveRec);
  3605. }
  3606. else
  3607. {
  3608. /*
  3609. * Check to see if this is the Top Provider. If it is, then the
  3610. * request can be processed locally. Otherwise, forward the
  3611. * request upward.
  3612. */
  3613. if (IsTopProvider())
  3614. {
  3615. /*
  3616. * The token does not exist in this domain. Report this and
  3617. * send the appropriate give confirm back to the originating
  3618. * user.
  3619. */
  3620. ERROR_OUT(("Domain::TokenGiveRequest: token does not exist"));
  3621. pOrigAtt->TokenGiveConfirm(RESULT_TOKEN_NOT_POSSESSED,
  3622. pTokenGiveRec->uidInitiator, pTokenGiveRec->token_id, TOKEN_NOT_IN_USE);
  3623. }
  3624. else
  3625. {
  3626. /*
  3627. * This is not the Top Provider. Forward the request upward.
  3628. */
  3629. TRACE_OUT(("Domain::TokenGiveRequest: forwarding give request to Top Provider"));
  3630. m_pConnToTopProvider->TokenGiveRequest(pTokenGiveRec);
  3631. }
  3632. }
  3633. }
  3634. else
  3635. {
  3636. /*
  3637. * There is no such user in the sub-tree from which this request
  3638. * originated. Ignore the request.
  3639. */
  3640. ERROR_OUT(("Domain::TokenGiveRequest: invalid originator=0x%p", pOrigAtt));
  3641. }
  3642. }
  3643. /*
  3644. * Void TokenGiveIndication ()
  3645. *
  3646. * Public
  3647. *
  3648. * Functional Description:
  3649. */
  3650. Void Domain::TokenGiveIndication (
  3651. PConnection pOrigConn,
  3652. PTokenGiveRecord pTokenGiveRec)
  3653. {
  3654. PToken token;
  3655. TokenID token_id = pTokenGiveRec->token_id;
  3656. /*
  3657. * Verify that the indication came from the Top Provider.
  3658. */
  3659. if (pOrigConn == m_pConnToTopProvider)
  3660. {
  3661. /*
  3662. * See if the token already exists in the local information base. If
  3663. * so, let it handle this.
  3664. */
  3665. if (NULL != (token = m_TokenList2.Find(token_id)))
  3666. {
  3667. TRACE_OUT(("Domain::TokenGiveIndication: sending give indication to token object"));
  3668. token->TokenGiveIndication(pTokenGiveRec);
  3669. }
  3670. else
  3671. {
  3672. /*
  3673. * Make sure that the specified receiver is somewhere in the
  3674. * sub-tree of this provider.
  3675. */
  3676. if (ValidateUserID (pTokenGiveRec->receiver_id, NULL) )
  3677. {
  3678. /*
  3679. * Create the token.
  3680. */
  3681. DBG_SAVE_FILE_LINE
  3682. token = new Token(token_id, this, m_pConnToTopProvider, &m_ChannelList2, &m_AttachmentList);
  3683. if (token != NULL)
  3684. {
  3685. /*
  3686. * Put the newly created Token object into the token
  3687. * list. Then pass the give indication to it.
  3688. */
  3689. TRACE_OUT(("Domain::TokenGiveIndication: adding token ID = %04X", (UINT) token_id));
  3690. m_TokenList2.Append(token_id, token);
  3691. Number_Of_Tokens++;
  3692. token->TokenGiveIndication(pTokenGiveRec);
  3693. }
  3694. else
  3695. {
  3696. /*
  3697. * The creation of the token failed. It is therefore
  3698. * necessary to send a failed give response to the Top
  3699. * Provider.
  3700. */
  3701. ERROR_OUT(("Domain::TokenGiveIndication: token creation failed"));
  3702. m_pConnToTopProvider->TokenGiveResponse(RESULT_UNSPECIFIED_FAILURE,
  3703. pTokenGiveRec->uidInitiator, token_id);
  3704. }
  3705. }
  3706. else
  3707. {
  3708. /*
  3709. * The specified receiver does not exist in the sub-tree of
  3710. * this provider. It is not necessary for this provider to
  3711. * take special action, since the detach user indication for
  3712. * the receiver will clean up.
  3713. */
  3714. ERROR_OUT(("Domain::TokenGiveIndication: receiver not valid"));
  3715. }
  3716. }
  3717. }
  3718. else
  3719. {
  3720. /*
  3721. * This indication was received from someone besides the Top Provider.
  3722. * Ignore the indication.
  3723. */
  3724. ERROR_OUT(("Domain::TokenGiveIndication: invalid originator=0x%p", pOrigConn));
  3725. }
  3726. }
  3727. /*
  3728. * Void TokenGiveResponse ()
  3729. *
  3730. * Public
  3731. *
  3732. * Functional Description:
  3733. */
  3734. Void Domain::TokenGiveResponse (
  3735. CAttachment *pOrigAtt,
  3736. Result result,
  3737. UserID receiver_id,
  3738. TokenID token_id)
  3739. {
  3740. PToken token;
  3741. /*
  3742. * Make sure the requesting user really exists in the sub-tree from which
  3743. * this response originated.
  3744. */
  3745. if (ValidateUserID(receiver_id, pOrigAtt))
  3746. {
  3747. /*
  3748. * If the token already exists in the token list, then let the
  3749. * Token object deal with the response.
  3750. */
  3751. if (NULL != (token = m_TokenList2.Find(token_id)))
  3752. {
  3753. /*
  3754. * Send the give response to the token object. Then check to
  3755. * see if it is still valid (delete it if not).
  3756. */
  3757. TRACE_OUT(("Domain::TokenGiveResponse: sending give response to token object"));
  3758. token->TokenGiveResponse(result, receiver_id, token_id);
  3759. if (token->IsValid () == FALSE)
  3760. DeleteToken (token_id);
  3761. }
  3762. else
  3763. {
  3764. /*
  3765. * The token is not in the information base, which means that it
  3766. * cannot be being given to the initiator of this response.
  3767. * Ignore the response.
  3768. */
  3769. ERROR_OUT(("Domain::TokenGiveResponse: no such token"));
  3770. }
  3771. }
  3772. else
  3773. {
  3774. /*
  3775. * There is no such user in the sub-tree from which this response
  3776. * originated. Ignore the response.
  3777. */
  3778. ERROR_OUT(("Domain::TokenGiveResponse: invalid originator=0x%p", pOrigAtt));
  3779. }
  3780. }
  3781. /*
  3782. * Void TokenGiveConfirm ()
  3783. *
  3784. * Public
  3785. *
  3786. * Functional Description:
  3787. */
  3788. Void Domain::TokenGiveConfirm (
  3789. PConnection pOrigConn,
  3790. Result result,
  3791. UserID uidInitiator,
  3792. TokenID token_id,
  3793. TokenStatus token_status)
  3794. {
  3795. PToken token;
  3796. /*
  3797. * Verify that the confirm came from the Top Provider.
  3798. */
  3799. if (pOrigConn == m_pConnToTopProvider)
  3800. {
  3801. /*
  3802. * See if the token already exists in the local information base. If
  3803. * so, let it handle this.
  3804. */
  3805. if (NULL != (token = m_TokenList2.Find(token_id)))
  3806. {
  3807. /*
  3808. * Send the give confirm to the token object. Then check to
  3809. * see if it is still valid (delete it if not).
  3810. */
  3811. TRACE_OUT(("Domain::TokenGiveConfirm: sending give confirm to token object"));
  3812. token->TokenGiveConfirm(result, uidInitiator, token_id, token_status);
  3813. if (token->IsValid () == FALSE)
  3814. DeleteToken (token_id);
  3815. }
  3816. else
  3817. {
  3818. /*
  3819. * Make sure that the requesting user is still somewhere in the
  3820. * sub-tree of this provider.
  3821. */
  3822. if (ValidateUserID (uidInitiator, NULL) )
  3823. {
  3824. PChannel channel;
  3825. /*
  3826. * Determine which attachment leads to the requesting user.
  3827. * Then forward the confirm in that direction.
  3828. */
  3829. TRACE_OUT(("Domain::TokenGiveConfirm: forwarding give confirm"));
  3830. if (NULL != (channel = m_ChannelList2.Find(uidInitiator)))
  3831. {
  3832. CAttachment *pAtt = channel->GetAttachment();
  3833. if (pAtt)
  3834. {
  3835. pAtt->TokenGiveConfirm(result, uidInitiator, token_id, token_status);
  3836. }
  3837. else
  3838. {
  3839. ERROR_OUT(("Domain::TokenGiveConfirm: cannot get attachment"));
  3840. }
  3841. }
  3842. else
  3843. {
  3844. ERROR_OUT(("Domain::TokenGiveConfirm: cannot find channel"));
  3845. }
  3846. }
  3847. else
  3848. {
  3849. /*
  3850. * The named initiator does not exist in the sub-tree of this
  3851. * provider. Ignore the confirm.
  3852. */
  3853. ERROR_OUT(("Domain::TokenGiveConfirm: initiator not valid"));
  3854. }
  3855. }
  3856. }
  3857. else
  3858. {
  3859. /*
  3860. * This confirm was received from someone besides the Top Provider.
  3861. * Ignore the indication.
  3862. */
  3863. ERROR_OUT(("Domain::TokenGiveConfirm: invalid originator=0x%p", pOrigConn));
  3864. }
  3865. }
  3866. /*
  3867. * Void TokenPleaseRequest ()
  3868. *
  3869. * Public
  3870. *
  3871. * Functional Description:
  3872. */
  3873. Void Domain::TokenPleaseRequest (
  3874. CAttachment *pOrigAtt,
  3875. UserID uidInitiator,
  3876. TokenID token_id)
  3877. {
  3878. PToken token;
  3879. /*
  3880. * Make sure the requesting user really exists in the sub-tree from which
  3881. * this request originated.
  3882. */
  3883. if (ValidateUserID(uidInitiator, pOrigAtt))
  3884. {
  3885. /*
  3886. * If the token already exists in the token list, then let the
  3887. * Token object deal with the request.
  3888. */
  3889. if (NULL != (token = m_TokenList2.Find(token_id)))
  3890. {
  3891. TRACE_OUT(("Domain::TokenPleaseRequest: sending please request to token object"));
  3892. token->TokenPleaseRequest(uidInitiator, token_id);
  3893. }
  3894. else
  3895. {
  3896. /*
  3897. * Check to see if this is the Top Provider. If it is, then the
  3898. * request can be processed locally. Otherwise, forward the
  3899. * request upward.
  3900. */
  3901. if (IsTopProvider())
  3902. {
  3903. /*
  3904. * The token being released is not owned by anyone. Report the
  3905. * incident to the diagnostic window, but do nothing. This
  3906. * simply indicates that someone has issued a please request
  3907. * for a token that no one owns.
  3908. */
  3909. ERROR_OUT(("Domain::TokenPleaseRequest: token does not exist"));
  3910. }
  3911. else
  3912. {
  3913. /*
  3914. * This is not the Top Provider. Forward the request upward.
  3915. */
  3916. TRACE_OUT(("Domain::TokenPleaseRequest: forwarding please request to Top Provider"));
  3917. m_pConnToTopProvider->TokenPleaseRequest(uidInitiator, token_id);
  3918. }
  3919. }
  3920. }
  3921. else
  3922. {
  3923. /*
  3924. * There is no such user in the sub-tree from which this request
  3925. * originated. Ignore the request.
  3926. */
  3927. ERROR_OUT(("Domain::TokenPleaseRequest: invalid originator=0x%p", pOrigAtt));
  3928. }
  3929. }
  3930. /*
  3931. * Void TokenPleaseIndication ()
  3932. *
  3933. * Public
  3934. *
  3935. * Functional Description:
  3936. */
  3937. Void Domain::TokenPleaseIndication (
  3938. PConnection pOrigConn,
  3939. UserID uidInitiator,
  3940. TokenID token_id)
  3941. {
  3942. PToken token;
  3943. /*
  3944. * Verify that the indication came from the Top Provider.
  3945. */
  3946. if (pOrigConn == m_pConnToTopProvider)
  3947. {
  3948. /*
  3949. * See if the token already exists in the local information base. If
  3950. * so, let it handle this.
  3951. */
  3952. if (NULL != (token = m_TokenList2.Find(token_id)))
  3953. {
  3954. TRACE_OUT(("Domain::TokenPleaseIndication: sending please indication to token object"));
  3955. token->TokenPleaseIndication(uidInitiator, token_id);
  3956. }
  3957. else
  3958. {
  3959. /*
  3960. * Since token please indication is only sent downward to providers
  3961. * that have owners in their sub-tree, it should not be possible
  3962. * to get here. This indicates that this provider received the
  3963. * indication with NO owners in its sub-tree. Report the error
  3964. * and ignore the indication.
  3965. */
  3966. ERROR_OUT(("Domain::TokenPleaseIndication: invalid token"));
  3967. }
  3968. }
  3969. else
  3970. {
  3971. /*
  3972. * This indication was received from someone besides the Top Provider.
  3973. * Ignore the indication.
  3974. */
  3975. ERROR_OUT(("Domain::TokenPleaseIndication: invalid originator=0x%p", pOrigConn));
  3976. }
  3977. }
  3978. /*
  3979. * Void TokenReleaseRequest ()
  3980. *
  3981. * Public
  3982. *
  3983. * Functional Description:
  3984. * This MCS command is initially sent by a user attachment that wishes
  3985. * to release a token. It flows upward to the Top Provider, who attempts
  3986. * to satisfy the request.
  3987. */
  3988. Void Domain::TokenReleaseRequest (
  3989. CAttachment *pOrigAtt,
  3990. UserID uidInitiator,
  3991. TokenID token_id)
  3992. {
  3993. PToken token;
  3994. /*
  3995. * Make sure the requesting user really exists in the sub-tree from which
  3996. * this request originated.
  3997. */
  3998. if (ValidateUserID(uidInitiator, pOrigAtt))
  3999. {
  4000. /*
  4001. * If the token already exists in the token list, then let the
  4002. * Token object deal with the request.
  4003. */
  4004. if (NULL != (token = m_TokenList2.Find(token_id)))
  4005. {
  4006. /*
  4007. * Send the release request to the token object. Then check to
  4008. * see if it is still valid (delete it if not).
  4009. */
  4010. TRACE_OUT(("Domain::TokenReleaseRequest: sending release request to token object"));
  4011. token->TokenReleaseRequest(pOrigAtt, uidInitiator, token_id);
  4012. if (token->IsValid () == FALSE)
  4013. DeleteToken (token_id);
  4014. }
  4015. else
  4016. {
  4017. /*
  4018. * Check to see if this is the Top Provider. If it is, then the
  4019. * request can be processed locally. Otherwise, forward the
  4020. * request upward.
  4021. */
  4022. if (IsTopProvider())
  4023. {
  4024. /*
  4025. * The token being released is not owned by anyone. Return
  4026. * a failure to the initiating user.
  4027. */
  4028. ERROR_OUT(("Domain::TokenReleaseRequest: token does not exist"));
  4029. pOrigAtt->TokenReleaseConfirm(RESULT_TOKEN_NOT_POSSESSED, uidInitiator, token_id, TOKEN_NOT_IN_USE);
  4030. }
  4031. else
  4032. {
  4033. /*
  4034. * This is not the Top Provider. Forward the request upward.
  4035. */
  4036. TRACE_OUT(("Domain::TokenReleaseRequest: forwarding release request to Top Provider"));
  4037. m_pConnToTopProvider->TokenReleaseRequest(uidInitiator, token_id);
  4038. }
  4039. }
  4040. }
  4041. else
  4042. {
  4043. /*
  4044. * There is no such user in the sub-tree from which this request
  4045. * originated. Ignore the request.
  4046. */
  4047. ERROR_OUT(("Domain::TokenReleaseRequest: invalid originator=0x%p", pOrigAtt));
  4048. }
  4049. }
  4050. /*
  4051. * Void TokenReleaseConfirm ()
  4052. *
  4053. * Public
  4054. *
  4055. * Functional Description:
  4056. * This MCS command is initially sent by the Top Provider upon receipt of
  4057. * a release request. It is sent back to the initiating user, containing
  4058. * the result of the request.
  4059. */
  4060. Void Domain::TokenReleaseConfirm (
  4061. PConnection pOrigConn,
  4062. Result result,
  4063. UserID uidInitiator,
  4064. TokenID token_id,
  4065. TokenStatus token_status)
  4066. {
  4067. PToken token;
  4068. /*
  4069. * Verify that the confirm came from the Top Provider.
  4070. */
  4071. if (pOrigConn == m_pConnToTopProvider)
  4072. {
  4073. /*
  4074. * See if the token already exists in the local information base. If
  4075. * so, let it handle this.
  4076. */
  4077. if (NULL != (token = m_TokenList2.Find(token_id)))
  4078. {
  4079. /*
  4080. * Send the release confirm to the token object. Then check to
  4081. * see if it is still valid (delete it if not).
  4082. */
  4083. TRACE_OUT(("Domain::TokenReleaseConfirm: sending release confirm to token object"));
  4084. token->TokenReleaseConfirm(result, uidInitiator, token_id, token_status);
  4085. if (token->IsValid () == FALSE)
  4086. DeleteToken (token_id);
  4087. }
  4088. else
  4089. {
  4090. /*
  4091. * Make sure that the requesting user is still somewhere in the
  4092. * sub-tree of this provider.
  4093. */
  4094. if (ValidateUserID (uidInitiator, NULL) )
  4095. {
  4096. PChannel channel;
  4097. /*
  4098. * Determine which attachment leads to the requesting user.
  4099. * Then forward the confirm in that direction.
  4100. */
  4101. TRACE_OUT(("Domain::TokenReleaseConfirm: forwarding release confirm"));
  4102. if (NULL != (channel = m_ChannelList2.Find(uidInitiator)))
  4103. {
  4104. CAttachment *pAtt = channel->GetAttachment();
  4105. if (pAtt)
  4106. {
  4107. pAtt->TokenReleaseConfirm(result, uidInitiator, token_id, token_status);
  4108. }
  4109. else
  4110. {
  4111. ERROR_OUT(("Domain::TokenReleaseConfirm: cannot get attachment"));
  4112. }
  4113. }
  4114. else
  4115. {
  4116. ERROR_OUT(("Domain::TokenReleaseConfirm: cannot find channel"));
  4117. }
  4118. }
  4119. else
  4120. {
  4121. /*
  4122. * The named initiator does not exist in the sub-tree of this
  4123. * provider. Ignore the confirm.
  4124. */
  4125. WARNING_OUT(("Domain::TokenReleaseConfirm: initiator not valid"));
  4126. }
  4127. }
  4128. }
  4129. else
  4130. {
  4131. /*
  4132. * This confirm was received from someone besides the Top Provider.
  4133. * Ignore the indication.
  4134. */
  4135. ERROR_OUT(("Domain::TokenReleaseConfirm: invalid originator=0x%p", pOrigConn));
  4136. }
  4137. }
  4138. /*
  4139. * Void TokenTestRequest ()
  4140. *
  4141. * Public
  4142. *
  4143. * Functional Description:
  4144. * This MCS command is initially sent by a user attachment that wishes
  4145. * to test a token. It flows upward to the Top Provider, who attempts
  4146. * to satisfy the request.
  4147. */
  4148. Void Domain::TokenTestRequest (
  4149. CAttachment *pOrigAtt,
  4150. UserID uidInitiator,
  4151. TokenID token_id)
  4152. {
  4153. PToken token;
  4154. /*
  4155. * Make sure the requesting user really exists in the sub-tree from which
  4156. * this request originated.
  4157. */
  4158. if (ValidateUserID(uidInitiator, pOrigAtt))
  4159. {
  4160. /*
  4161. * If the token already exists in the token list, then let the Token
  4162. * object deal with the request.
  4163. */
  4164. if (NULL != (token = m_TokenList2.Find(token_id)))
  4165. {
  4166. TRACE_OUT(("Domain::TokenTestRequest: sending test request to token object"));
  4167. token->TokenTestRequest(pOrigAtt, uidInitiator, token_id);
  4168. }
  4169. else
  4170. {
  4171. /*
  4172. * Check to see if this is the Top Provider. If it is, then the
  4173. * request can be processed locally. Otherwise, forward the
  4174. * request upward.
  4175. */
  4176. if (IsTopProvider())
  4177. {
  4178. /*
  4179. * If the token is not in the list, send a confirm back to
  4180. * the initiating user telling it that the token is not in use.
  4181. */
  4182. ERROR_OUT(("Domain::TokenTestRequest: no such token - available"));
  4183. pOrigAtt->TokenTestConfirm(uidInitiator, token_id, TOKEN_NOT_IN_USE);
  4184. }
  4185. else
  4186. {
  4187. /*
  4188. * This is not the Top Provider. Forward the request upward.
  4189. */
  4190. TRACE_OUT(("Domain::TokenTestRequest: forwarding test request to Top Provider"));
  4191. m_pConnToTopProvider->TokenTestRequest(uidInitiator, token_id);
  4192. }
  4193. }
  4194. }
  4195. else
  4196. {
  4197. /*
  4198. * There is no such user in the sub-tree from which this request
  4199. * originated. Ignore the request.
  4200. */
  4201. ERROR_OUT(("Domain::TokenTestRequest: invalid originator=0x%p", pOrigAtt));
  4202. }
  4203. }
  4204. /*
  4205. * Void TokenTestConfirm ()
  4206. *
  4207. * Public
  4208. *
  4209. * Functional Description:
  4210. * This MCS command is initially sent by the Top Provider upon receipt of
  4211. * a test request. It is sent back to the initiating user, containing
  4212. * the result of the request.
  4213. */
  4214. Void Domain::TokenTestConfirm (
  4215. PConnection pOrigConn,
  4216. UserID uidInitiator,
  4217. TokenID token_id,
  4218. TokenStatus token_status)
  4219. {
  4220. PToken token;
  4221. /*
  4222. * Verify that the confirm came from the Top Provider.
  4223. */
  4224. if (pOrigConn == m_pConnToTopProvider)
  4225. {
  4226. /*
  4227. * See if the token already exists in the local information base. If
  4228. * so, let it handle this.
  4229. */
  4230. if (NULL != (token = m_TokenList2.Find(token_id)))
  4231. {
  4232. TRACE_OUT(("Domain::TokenTestConfirm: sending test confirm to token object"));
  4233. token->TokenTestConfirm(uidInitiator, token_id, token_status);
  4234. }
  4235. else
  4236. {
  4237. /*
  4238. * Make sure that the requesting user is still somewhere in the
  4239. * sub-tree of this provider.
  4240. */
  4241. if (ValidateUserID (uidInitiator, NULL) )
  4242. {
  4243. PChannel channel;
  4244. /*
  4245. * Determine which attachment leads to the requesting user.
  4246. * Then forward the confirm in that direction.
  4247. */
  4248. TRACE_OUT(("Domain::TokenTestConfirm: forwarding test confirm"));
  4249. if (NULL != (channel = m_ChannelList2.Find(uidInitiator)))
  4250. {
  4251. CAttachment *pAtt = channel->GetAttachment();
  4252. if (pAtt)
  4253. {
  4254. pAtt->TokenTestConfirm(uidInitiator, token_id, token_status);
  4255. }
  4256. else
  4257. {
  4258. ERROR_OUT(("Domain::TokenTestConfirm: cannot get attachment"));
  4259. }
  4260. }
  4261. else
  4262. {
  4263. ERROR_OUT(("Domain::TokenTestConfirm: cannot find channel"));
  4264. }
  4265. }
  4266. else
  4267. {
  4268. /*
  4269. * The named initiator does not exist in the sub-tree of this
  4270. * provider. Ignore the confirm.
  4271. */
  4272. ERROR_OUT(("Domain::TokenTestConfirm: initiator not valid uidInitiator=%u", (UINT) uidInitiator));
  4273. }
  4274. }
  4275. }
  4276. else
  4277. {
  4278. /*
  4279. * This confirm was received from someone besides the Top Provider.
  4280. * Ignore the indication.
  4281. */
  4282. ERROR_OUT(("Domain::TokenTestConfirm: invalid originator=0x%p", pOrigConn));
  4283. }
  4284. }
  4285. /*
  4286. * Void LockDomainParameters ()
  4287. *
  4288. * Private
  4289. *
  4290. * Functional Description:
  4291. * This routine is used to initialize the values of the domain parameters
  4292. * instance variable.
  4293. *
  4294. * Formal Parameters:
  4295. * domain_parameters
  4296. * This is a pointer to the domain parameters structure from which the
  4297. * values are to be obtained. If it is set to NULL, then put a default
  4298. * set of parameters into the instance variable.
  4299. * parameters_locked
  4300. * This parameter indicates whether or not these parameters have been
  4301. * locked into the domain by acceptance of the first connection.
  4302. *
  4303. * Return Value:
  4304. * None.
  4305. *
  4306. * Side Effects:
  4307. * None.
  4308. */
  4309. Void Domain::LockDomainParameters (
  4310. PDomainParameters domain_parameters,
  4311. BOOL parameters_locked)
  4312. {
  4313. /*
  4314. * If the structure pointer is valid, then copy the structure into the
  4315. * internal instance variable.
  4316. */
  4317. if (domain_parameters != NULL)
  4318. Domain_Parameters = *domain_parameters;
  4319. else
  4320. {
  4321. /*
  4322. * Set default values for all domain parameters.
  4323. */
  4324. Domain_Parameters.max_channel_ids = DEFAULT_MAXIMUM_CHANNELS;
  4325. Domain_Parameters.max_user_ids = DEFAULT_MAXIMUM_USERS;
  4326. Domain_Parameters.max_token_ids = DEFAULT_MAXIMUM_TOKENS;
  4327. Domain_Parameters.number_priorities = DEFAULT_NUMBER_OF_PRIORITIES;
  4328. Domain_Parameters.min_throughput = DEFAULT_MINIMUM_THROUGHPUT;
  4329. Domain_Parameters.max_height = DEFAULT_MAXIMUM_DOMAIN_HEIGHT;
  4330. Domain_Parameters.max_mcspdu_size = DEFAULT_MAXIMUM_PDU_SIZE;
  4331. Domain_Parameters.protocol_version = DEFAULT_PROTOCOL_VERSION;
  4332. if (g_fWinsockDisabled)
  4333. {
  4334. Domain_Parameters.number_priorities = DEFAULT_NUM_PLUGXPRT_PRIORITIES;
  4335. }
  4336. }
  4337. /*
  4338. * Indicate whether or not these parameters are locked.
  4339. */
  4340. Domain_Parameters_Locked = parameters_locked;
  4341. }
  4342. /*
  4343. * ChannelID AllocateDynamicChannel ()
  4344. *
  4345. * Private
  4346. *
  4347. * Functional Description:
  4348. * This member function is used to allocate an unused channel ID in the
  4349. * dynamic range (1001 - 65535). It uses a random number generator to
  4350. * perform this task.
  4351. *
  4352. * Formal Parameters:
  4353. * None.
  4354. *
  4355. * Return Value:
  4356. * A channel ID in the dynamic range that is guaranteed to be unused.
  4357. *
  4358. * Side Effects:
  4359. * None.
  4360. */
  4361. ChannelID Domain::AllocateDynamicChannel ()
  4362. {
  4363. ChannelID channel_id;
  4364. /*
  4365. * Stay in this loop until a unused channel ID is found. Note that this
  4366. * loop make sthe assumption that there will be at least one unused ID
  4367. * in there somewhere.
  4368. */
  4369. while (TRUE)
  4370. {
  4371. /*
  4372. * Get a random number in the dynamic channel range.
  4373. */
  4374. channel_id = (ChannelID) Random_Channel_Generator.GetRandomChannel ();
  4375. /*
  4376. * If it is not is use, then break out of the loop and return the
  4377. * channel ID.
  4378. */
  4379. if (! m_ChannelList2.Find(channel_id))
  4380. break;
  4381. }
  4382. return (channel_id);
  4383. }
  4384. /*
  4385. * BOOL ValidateUserID ()
  4386. *
  4387. * Private
  4388. *
  4389. * Functional Description:
  4390. * This function is used to validate a user ID. It can be used in one of
  4391. * two ways. If the passed in attachment is NULL, then this routine will
  4392. * check to see if the ID corresponds to a user ID anywhere in the sub-tree
  4393. * of this provider. If the passed in attachment is not NULL, then this
  4394. * routine checks to see if the ID is valid user ID associated with that
  4395. * particular attachment.
  4396. *
  4397. * Formal Parameters:
  4398. * user_id
  4399. * This is the ID to be checked for validity.
  4400. * attachment
  4401. * This is the attachment that is presumably associated with the user
  4402. * ID. If NULL, we are checking for validity irrespective of
  4403. * attachment.
  4404. *
  4405. * Return Value:
  4406. * This routine will return TRUE if the user ID valid. FALSE otherwise.
  4407. *
  4408. * Side Effects:
  4409. * None.
  4410. */
  4411. BOOL Domain::ValidateUserID (
  4412. UserID user_id,
  4413. CAttachment *pAtt)
  4414. {
  4415. PChannel channel;
  4416. /*
  4417. * Is the user ID even contained in the channel list.
  4418. */
  4419. if (NULL != (channel = m_ChannelList2.Find(user_id)))
  4420. {
  4421. /*
  4422. * It is in the channel list. Now check to see if it corresponds to
  4423. * a user ID channel.
  4424. */
  4425. if (channel->GetChannelType () == USER_CHANNEL)
  4426. {
  4427. /*
  4428. * Check to make sure that the real user attachment matches the
  4429. * passed in one (unless the passed in one is NULL, in which
  4430. * case it automatically matches).
  4431. */
  4432. if ((pAtt == NULL) || (pAtt == channel->GetAttachment()))
  4433. return TRUE;
  4434. }
  4435. }
  4436. return (FALSE);
  4437. }
  4438. /*
  4439. * Void PurgeDomain ()
  4440. *
  4441. * Private
  4442. *
  4443. * Functional Description:
  4444. * This function is used to purge the entire domain. This can happen for
  4445. * two reasons. Either the Top Provider is lost, or the local user has
  4446. * asked for the domain to be deleted. Either way, this function breaks
  4447. * all attachments, and frees up all resources in use by the domain.
  4448. *
  4449. * Formal Parameters:
  4450. * None.
  4451. *
  4452. * Return Value:
  4453. * None.
  4454. *
  4455. * Side Effects:
  4456. * The domain information base is returned to its initial state.
  4457. */
  4458. Void Domain::PurgeDomain (
  4459. Reason reason)
  4460. {
  4461. CAttachment *pAtt;
  4462. PChannel channel;
  4463. CUidList user_list;
  4464. UserID uid;
  4465. /*
  4466. * If there is a Top Provider, send a disconnect to it.
  4467. */
  4468. if (m_pConnToTopProvider != NULL)
  4469. {
  4470. TRACE_OUT(("Domain::PurgeDomain: disconnecting top provider"));
  4471. m_pConnToTopProvider->DisconnectProviderUltimatum (reason);
  4472. m_pConnToTopProvider = NULL;
  4473. }
  4474. /*
  4475. * Send disconnects to all downward attachments. Then clear out the
  4476. * attachment list.
  4477. */
  4478. TRACE_OUT(("Domain::PurgeDomain: disconnecting all downward attachments"));
  4479. while (NULL != (pAtt = m_AttachmentList.Get()))
  4480. {
  4481. pAtt->DisconnectProviderUltimatum(reason);
  4482. /*
  4483. * If there are any pending attach user requests on the attachment
  4484. * that was just broken, delete them. Note that this is a loop
  4485. * because there can be more than one.
  4486. */
  4487. while (m_AttachUserQueue.Remove(pAtt));
  4488. }
  4489. /*
  4490. * Send a disconnect to all attachments that represent attach user requests
  4491. * in process. Then clear the queue out.
  4492. */
  4493. while (NULL != (pAtt = m_AttachUserQueue.Get()))
  4494. {
  4495. pAtt->DisconnectProviderUltimatum(reason);
  4496. }
  4497. /*
  4498. * Clear the merge queue. The actual attachments have already been broken
  4499. * above.
  4500. */
  4501. m_MergeQueue.Clear();
  4502. /*
  4503. * We cannot just delete all channels and tokens, because doing so would
  4504. * cause them to issue various indications to attachments that are no
  4505. * longer valid. To get around this, we must delete all attachments (which
  4506. * was done above) and all user objects from the channel list, and then
  4507. * reclaim unowned resources. This will cause all static, assigned, and
  4508. * private channels, as well as tokens, to delete themselves.
  4509. */
  4510. m_ChannelList2.Reset();
  4511. while (NULL != (channel = m_ChannelList2.Iterate(&uid)))
  4512. {
  4513. if (channel->GetChannelType () == USER_CHANNEL)
  4514. user_list.Append(uid);
  4515. }
  4516. /*
  4517. * Delete all users from the channel list. Since there are no valid users
  4518. * in the domain, all resources that are tied to users will be reclaimed
  4519. * below.
  4520. */
  4521. user_list.Reset();
  4522. while (NULL != (uid = user_list.Iterate()))
  4523. {
  4524. DeleteChannel((ChannelID) uid);
  4525. }
  4526. /*
  4527. * Reclaim unowned resources. Since all resources (channels and tokens)
  4528. * are tied to the existence of either attachments or users, this call
  4529. * will result in all channels and tokens being cleanly deleted (since
  4530. * there aren't any attachments or users).
  4531. */
  4532. ReclaimResources ();
  4533. /*
  4534. * Reset the state to all initial values.
  4535. */
  4536. Merge_State = MERGE_INACTIVE;
  4537. Outstanding_Merge_Requests = 0;
  4538. Number_Of_Users = 0;
  4539. Number_Of_Channels = 0;
  4540. Number_Of_Tokens = 0;
  4541. m_nDomainHeight = 0;
  4542. m_DomainHeightList2.Clear();
  4543. LockDomainParameters (NULL, FALSE);
  4544. }
  4545. /*
  4546. * Void DeleteAttachment ()
  4547. *
  4548. * Private
  4549. *
  4550. * Functional Description:
  4551. * This function is used to free up all resources that are "bound" to
  4552. * particular attachment. It also deletes the downward attachment.
  4553. *
  4554. * Formal Parameters:
  4555. * attachment
  4556. * This is the attachment to be deleted.
  4557. * reason
  4558. * This is the reason for the deletion. This is merely passed on in
  4559. * any MCS commands that are sent as a result of this deletion.
  4560. *
  4561. * Return Value:
  4562. * None.
  4563. *
  4564. * Side Effects:
  4565. * Resources in the domain information base are freed up.
  4566. */
  4567. Void Domain::DeleteAttachment (
  4568. CAttachment *pAtt,
  4569. Reason reason)
  4570. {
  4571. ChannelID chid;
  4572. PChannel channel;
  4573. CUidList user_deletion_list;
  4574. CChannelIDList channel_deletion_list;
  4575. CChannelIDList channel_leave_list;
  4576. /*
  4577. * Check to make sure the attachment is real before proceeding.
  4578. */
  4579. if (m_AttachmentList.Remove(pAtt))
  4580. {
  4581. /*
  4582. * Remove the attachment from the downward attachment list.
  4583. */
  4584. /*
  4585. * Iterate through the channel list building two lists, as follows:
  4586. *
  4587. * 1. A list of users who lie in the direction of the lost attachment.
  4588. * These users must be deleted from the information base, and
  4589. * their detachment reported appropriately.
  4590. * 2. A list of channels that must be deleted as a result of the lost
  4591. * attachment. This list is created by sending a channel leave
  4592. * request to all channels, and then checking to see if they are
  4593. * still valid. All static and assigned channels that only had
  4594. * that attachment joined will be deleted as a result of this.
  4595. * This also results in the attachment being removed from all
  4596. * channel attachment lists, avoiding the possibility of sending
  4597. * data to an invalid attachment.
  4598. */
  4599. m_ChannelList2.Reset();
  4600. while (NULL != (channel = m_ChannelList2.Iterate(&chid)))
  4601. {
  4602. /*
  4603. * Check to see if this is a user ID channel whose user lies on the
  4604. * other side of the lost attachment. If so, add the channel to
  4605. * the deletion list.
  4606. */
  4607. if (channel->GetChannelType () == USER_CHANNEL)
  4608. {
  4609. if (channel->GetAttachment() == pAtt)
  4610. {
  4611. user_deletion_list.Append(chid);
  4612. continue;
  4613. }
  4614. }
  4615. /*
  4616. * Issue the leave request to the channel. Then check to see if it
  4617. * is still valid. If not, then add it to the deletion list.
  4618. */
  4619. channel_leave_list.Clear();
  4620. channel_leave_list.Append(chid);
  4621. channel->ChannelLeaveRequest(pAtt, &channel_leave_list);
  4622. if (channel->IsValid () == FALSE)
  4623. channel_deletion_list.Append(chid);
  4624. }
  4625. /*
  4626. * Iterate through the channel list, deleting the channels it
  4627. * contains.
  4628. */
  4629. channel_deletion_list.Reset();
  4630. while (NULL != (chid = channel_deletion_list.Iterate()))
  4631. {
  4632. DeleteChannel(chid);
  4633. }
  4634. /*
  4635. * If there are any users to be deleted, simulate a DetachUserRequest
  4636. * with the list of users to be deleted.
  4637. */
  4638. if (user_deletion_list.IsEmpty() == FALSE)
  4639. DetachUserRequest(pAtt, reason, &user_deletion_list);
  4640. /*
  4641. * Check to see if the deleted attachment is represented in the
  4642. * domain height list. If it is, then this loss could result in a
  4643. * change in the overall domain height.
  4644. */
  4645. if (m_DomainHeightList2.Remove((PConnection) pAtt))
  4646. {
  4647. /*
  4648. * The attachment is in the list. Remove it from the list, and
  4649. * call the subroutine that determines whether an overall height
  4650. * change has occurred that may require further activity.
  4651. */
  4652. CalculateDomainHeight ();
  4653. }
  4654. }
  4655. else
  4656. {
  4657. /*
  4658. * The named attachment isn't even in the attachment list.
  4659. */
  4660. ERROR_OUT(("Domain::DeleteAttachment: unknown attachment=0x%p", pAtt));
  4661. }
  4662. }
  4663. /*
  4664. * Void DeleteUser ()
  4665. *
  4666. * Private
  4667. *
  4668. * Functional Description:
  4669. * This routine deletes a user from the information base. This is fairly
  4670. * complex task because there are a lot of dependencies on users within
  4671. * the MCS protocol. If the user being deleted is locall attached, then
  4672. * the attachment must be severed. Also, any resources that are being
  4673. * held by the user must be reclaimed. And finally, the user channel
  4674. * object that represents the user must be deleted from the local channel
  4675. * list.
  4676. *
  4677. * Formal Parameters:
  4678. * user_id
  4679. * This is the ID of the user being deleted.
  4680. *
  4681. * Return Value:
  4682. * None.
  4683. *
  4684. * Side Effects:
  4685. * None.
  4686. */
  4687. Void Domain::DeleteUser (
  4688. UserID user_id)
  4689. {
  4690. CAttachment *pAtt;
  4691. ChannelID chid;
  4692. PChannel channel;
  4693. CChannelIDList deletion_list;
  4694. CChannelIDList channel_leave_list;
  4695. /*
  4696. * Make sure this is a valid user in the sub-tree of this provider before
  4697. * proceeding.
  4698. */
  4699. if (ValidateUserID (user_id, NULL) )
  4700. {
  4701. /*
  4702. * Determine which attachment leads to the user in question.
  4703. */
  4704. if (NULL != (channel = m_ChannelList2.Find(user_id)))
  4705. {
  4706. pAtt = channel->GetAttachment();
  4707. /*
  4708. * Delete the user channel now that it is no longer necessary.
  4709. */
  4710. DeleteChannel (user_id);
  4711. /*
  4712. * Check to see if the user's attachment is still valid. It is
  4713. * possible that the user is being deleted as a result of losing the
  4714. * attachment that leads to it.
  4715. */
  4716. if (m_AttachmentList.Find(pAtt) && pAtt->IsUserAttachment())
  4717. {
  4718. /*
  4719. * If this user was locally attached, then it is necessary to
  4720. * remove it from the attachment list, as well as making sure that
  4721. * no other channel objects attempt to reference it.
  4722. */
  4723. /*
  4724. * Remove the attachment from the downward attachment list.
  4725. */
  4726. TRACE_OUT(("Domain::DeleteUser: deleting local attachment"));
  4727. m_AttachmentList.Remove(pAtt);
  4728. ((PUser) pAtt)->Release();
  4729. /*
  4730. * Iterate through the channel list issuing leave requests to
  4731. * each channel. This prevents a Channel object from trying to
  4732. * send data on an attachment that is no longer valid. This
  4733. * loop also builds a list of Channel objects that should be
  4734. * deleted as a result of this detachment.
  4735. */
  4736. m_ChannelList2.Reset();
  4737. while (NULL != (channel = m_ChannelList2.Iterate(&chid)))
  4738. {
  4739. /*
  4740. * Issue the leave request to the channel. Then check to
  4741. * see if it is still valid. If not, then add it to the
  4742. * deletion list.
  4743. */
  4744. channel_leave_list.Clear();
  4745. channel_leave_list.Append(chid);
  4746. channel->ChannelLeaveRequest(pAtt, &channel_leave_list);
  4747. if (channel->IsValid () == FALSE)
  4748. deletion_list.Append(chid);
  4749. }
  4750. /*
  4751. * Iterator through the deletion list, deleting the channels it
  4752. * contains.
  4753. */
  4754. deletion_list.Reset();
  4755. while (NULL != (chid = deletion_list.Iterate()))
  4756. {
  4757. DeleteChannel(chid);
  4758. }
  4759. }
  4760. /*
  4761. * Reclaim all resources that may have been freed as a result of the
  4762. * deleted user.
  4763. */
  4764. ReclaimResources ();
  4765. }
  4766. else
  4767. {
  4768. ERROR_OUT(("Domain::DeleteUser: cannot find channel"));
  4769. }
  4770. }
  4771. else
  4772. {
  4773. /*
  4774. * The specified user ID is not valid.
  4775. */
  4776. ERROR_OUT(("Domain::DeleteUser: unknown user ID"));
  4777. }
  4778. }
  4779. /*
  4780. * Void DeleteChannel ()
  4781. *
  4782. * Private
  4783. *
  4784. * Functional Description:
  4785. * This function deleted a channel from the channel list. It also adjusts
  4786. * the appropriate channel counter (according to type), and reports the
  4787. * deletion.
  4788. *
  4789. * Formal Parameters:
  4790. * channel_id
  4791. * This is the ID of the channel to be deleted.
  4792. *
  4793. * Return Value:
  4794. * None.
  4795. *
  4796. * Side Effects:
  4797. * None.
  4798. */
  4799. Void Domain::DeleteChannel (
  4800. ChannelID channel_id)
  4801. {
  4802. PChannel channel;
  4803. /*
  4804. * Make sure the channel being deleted is real before proceeding.
  4805. */
  4806. if (NULL != (channel = m_ChannelList2.Remove(channel_id)))
  4807. {
  4808. /*
  4809. * Report the type of channel being deleted, and decrement the
  4810. * appropriate counter.
  4811. */
  4812. Number_Of_Channels--;
  4813. switch (channel->GetChannelType ())
  4814. {
  4815. case STATIC_CHANNEL:
  4816. TRACE_OUT (("Domain::DeleteChannel: "
  4817. "deleting static channel ID = %04X", channel_id));
  4818. break;
  4819. case ASSIGNED_CHANNEL:
  4820. TRACE_OUT (("Domain::DeleteChannel: "
  4821. "deleting assigned channel ID = %04X", channel_id));
  4822. break;
  4823. case USER_CHANNEL:
  4824. TRACE_OUT (("Domain::DeleteChannel: "
  4825. "deleting user channel ID = %04X", channel_id));
  4826. Number_Of_Users--;
  4827. break;
  4828. case PRIVATE_CHANNEL:
  4829. TRACE_OUT (("Domain::DeleteChannel: "
  4830. "deleting private channel ID = %04X", channel_id));
  4831. break;
  4832. default:
  4833. ERROR_OUT (("Domain::DeleteChannel: "
  4834. "ERROR - deleting unknown channel ID = %04X",
  4835. channel_id));
  4836. Number_Of_Channels++;
  4837. break;
  4838. }
  4839. /*
  4840. * Delete the channel object.
  4841. */
  4842. delete channel;
  4843. }
  4844. else
  4845. {
  4846. ERROR_OUT(("Domain::DeleteChannel: unknown channel ID"));
  4847. }
  4848. }
  4849. /*
  4850. * Void DeleteToken ()
  4851. *
  4852. * Private
  4853. *
  4854. * Functional Description:
  4855. * This function deletes a token from the token list. It also adjusts
  4856. * the token counter.
  4857. *
  4858. * Formal Parameters:
  4859. * token_id
  4860. * This is the ID of the token to be deleted.
  4861. *
  4862. * Return Value:
  4863. * None.
  4864. *
  4865. * Side Effects:
  4866. * None.
  4867. */
  4868. Void Domain::DeleteToken (
  4869. TokenID token_id)
  4870. {
  4871. PToken token;
  4872. /*
  4873. * Check to make sure that the token being deleted is real before
  4874. * proceeding.
  4875. */
  4876. if (NULL != (token = m_TokenList2.Remove(token_id)))
  4877. {
  4878. /*
  4879. * Remove the token from the token list and delete it.
  4880. */
  4881. TRACE_OUT(("Domain::DeleteToken: deleting token ID = %04X", (UINT) token_id));
  4882. delete token;
  4883. /*
  4884. * Decrement the token counter.
  4885. */
  4886. Number_Of_Tokens--;
  4887. }
  4888. else
  4889. {
  4890. ERROR_OUT(("Domain::DeleteToken: unknown token ID"));
  4891. }
  4892. }
  4893. /*
  4894. * Void ReclaimResources ()
  4895. *
  4896. * Private
  4897. *
  4898. * Functional Description:
  4899. * This function walks through both the channel and token lists, removing
  4900. * all objects that are no longer valid. This function just queries each
  4901. * channel and token to see if it is still valid. This allows for the
  4902. * reclamation of resources when a user is deleted.
  4903. *
  4904. * Formal Parameters:
  4905. * None.
  4906. *
  4907. * Return Value:
  4908. * None.
  4909. *
  4910. * Side Effects:
  4911. * None.
  4912. */
  4913. Void Domain::ReclaimResources ()
  4914. {
  4915. ChannelID chid;
  4916. PChannel channel;
  4917. CChannelIDList channel_deletion_list;
  4918. TokenID tid;
  4919. PToken token;
  4920. CTokenIDList token_deletion_list;
  4921. /*
  4922. * Iterate through the channel list, asking each channel if it is still
  4923. * valid. Any that are not will be deleted by the next loop.
  4924. */
  4925. m_ChannelList2.Reset();
  4926. while (NULL != (channel = m_ChannelList2.Iterate(&chid)))
  4927. {
  4928. /*
  4929. * Check to see if the channel is still valid. If not, add it to the
  4930. * deletion list.
  4931. */
  4932. if (channel->IsValid () == FALSE)
  4933. channel_deletion_list.Append(chid);
  4934. }
  4935. /*
  4936. * Delete all channels in the deletion list.
  4937. */
  4938. channel_deletion_list.Reset();
  4939. while (NULL != (chid = channel_deletion_list.Iterate()))
  4940. {
  4941. DeleteChannel(chid);
  4942. }
  4943. /*
  4944. * Iterate through the token list, asking each token if it is still
  4945. * valid. Any that are not will be deleted by the next loop.
  4946. */
  4947. m_TokenList2.Reset();
  4948. while (NULL != (token = m_TokenList2.Iterate(&tid)))
  4949. {
  4950. /*
  4951. * Check to see if the token is still valid. If the grabber or
  4952. * inhibitor was the only owner of the token, then it will be freed
  4953. * here.
  4954. */
  4955. if (token->IsValid () == FALSE)
  4956. token_deletion_list.Append(tid);
  4957. }
  4958. /*
  4959. * Delete all tokens in the deletion list.
  4960. */
  4961. while (NULL != (tid = token_deletion_list.Get()))
  4962. {
  4963. DeleteToken(tid);
  4964. }
  4965. }
  4966. /*
  4967. * Void MergeInformationBase ()
  4968. *
  4969. * Private
  4970. *
  4971. * Functional Description:
  4972. * This function is essentially a state machine for the domain merger
  4973. * process. Domain merging is currently implemented to only try and
  4974. * merge one type of resource at a time. Each time this routine is
  4975. * called, the next type of resource is merged. After all resources have
  4976. * been merged, this provider ceases to be a Top Provider, and the merge
  4977. * state is returned to inactive.
  4978. *
  4979. * Formal Parameters:
  4980. * None.
  4981. *
  4982. * Return Value:
  4983. * None.
  4984. *
  4985. * Side Effects:
  4986. * Contents of the domain information are merged upward to the Top
  4987. * Provider of the upper domain.
  4988. */
  4989. Void Domain::MergeInformationBase ()
  4990. {
  4991. MergeState merge_state;
  4992. Channel_Type channel_type;
  4993. PChannel channel;
  4994. PToken token;
  4995. /*
  4996. * This call is not valid unless there is a Top Provider to merge the
  4997. * information upward to.
  4998. */
  4999. if (m_pConnToTopProvider != NULL)
  5000. {
  5001. /*
  5002. * As part of the transition to the next merge state, set the number
  5003. * of outstanding merge requests to 0.
  5004. */
  5005. Outstanding_Merge_Requests = 0;
  5006. merge_state = Merge_State;
  5007. while (Outstanding_Merge_Requests == 0)
  5008. {
  5009. /*
  5010. * Each case of this switch statement sets two variables. The
  5011. * first is the merge state. This is bumped to the next state
  5012. * in the sequence. The second is the channel type. This is
  5013. * used for controlling which type of channel is being merged
  5014. * upward for this state.
  5015. */
  5016. switch (merge_state)
  5017. {
  5018. case MERGE_INACTIVE:
  5019. TRACE_OUT(("Domain::MergeInformationBase: merging User IDs"));
  5020. merge_state = MERGE_USER_IDS;
  5021. channel_type = USER_CHANNEL;
  5022. break;
  5023. case MERGE_USER_IDS:
  5024. TRACE_OUT(("Domain::MergeInformationBase: merging Static Channels"));
  5025. merge_state = MERGE_STATIC_CHANNELS;
  5026. channel_type = STATIC_CHANNEL;
  5027. break;
  5028. case MERGE_STATIC_CHANNELS:
  5029. TRACE_OUT(("Domain::MergeInformationBase: merging Assigned Channels"));
  5030. merge_state = MERGE_ASSIGNED_CHANNELS;
  5031. channel_type = ASSIGNED_CHANNEL;
  5032. break;
  5033. case MERGE_ASSIGNED_CHANNELS:
  5034. TRACE_OUT(("Domain::MergeInformationBase: merging Private Channels"));
  5035. merge_state = MERGE_PRIVATE_CHANNELS;
  5036. channel_type = PRIVATE_CHANNEL;
  5037. break;
  5038. case MERGE_PRIVATE_CHANNELS:
  5039. TRACE_OUT(("Domain::MergeInformationBase: merging Tokens"));
  5040. merge_state = MERGE_TOKENS;
  5041. break;
  5042. case MERGE_TOKENS:
  5043. TRACE_OUT(("Domain::MergeInformationBase: domain merger complete"));
  5044. merge_state = MERGE_COMPLETE;
  5045. break;
  5046. default:
  5047. ERROR_OUT(("Domain::MergeInformationBase: invalid merge state"));
  5048. break;
  5049. }
  5050. /*
  5051. * If the merge is now complete, then this provider must cease
  5052. * to be a Top Provider.
  5053. */
  5054. if (merge_state == MERGE_COMPLETE)
  5055. {
  5056. /*
  5057. * Reset the merge state, and break out of this loop.
  5058. */
  5059. merge_state = MERGE_INACTIVE;
  5060. break;
  5061. }
  5062. /*
  5063. * Check to see if we are to merge tokens on this pass.
  5064. */
  5065. if (merge_state == MERGE_TOKENS)
  5066. {
  5067. /*
  5068. * Iterate through the token list, sending merge requests to
  5069. * each Token object. Pass in the identity of the pending
  5070. * Top Provider, so that the Token object knows where to send
  5071. * the MergeTokensRequest. Increment the number of
  5072. * outstanding merge requests.
  5073. */
  5074. m_TokenList2.Reset();
  5075. while (NULL != (token = m_TokenList2.Iterate()))
  5076. {
  5077. token->IssueMergeRequest ();
  5078. Outstanding_Merge_Requests++;
  5079. }
  5080. }
  5081. else
  5082. {
  5083. /*
  5084. * This must be a merge state for channels. Iterate through
  5085. * the channel list, sending a merge request to each Channel
  5086. * object whose type matches that specified by the merge
  5087. * state that we are. Increment the outstanding merge
  5088. * request counter each time one is sent.
  5089. */
  5090. m_ChannelList2.Reset();
  5091. while (NULL != (channel = m_ChannelList2.Iterate()))
  5092. {
  5093. if (channel->GetChannelType () == channel_type)
  5094. {
  5095. channel->IssueMergeRequest ();
  5096. Outstanding_Merge_Requests++;
  5097. }
  5098. }
  5099. }
  5100. }
  5101. SetMergeState (merge_state);
  5102. }
  5103. else
  5104. {
  5105. /*
  5106. * This routine has been called when the domain is not in the
  5107. * appropriate state.
  5108. */
  5109. ERROR_OUT(("Domain::MergeInformationBase: unable to merge at this time"));
  5110. }
  5111. }
  5112. /*
  5113. * Void SetMergeState ()
  5114. *
  5115. * Private
  5116. *
  5117. * Functional Description:
  5118. * This function sets the merge state to the passed in value. It also
  5119. * detects the transition between MERGE_INACTIVE and any other state.
  5120. * This transition causes the domain to issue MergeDomainIndication to
  5121. * all downward attachments.
  5122. *
  5123. * Formal Parameters:
  5124. * merge_state
  5125. * This is the merge state that we are moving to.
  5126. *
  5127. * Return Value:
  5128. * None.
  5129. *
  5130. * Side Effects:
  5131. * None.
  5132. */
  5133. Void Domain::SetMergeState (
  5134. MergeState merge_state)
  5135. {
  5136. CAttachment *pAtt;
  5137. /*
  5138. * Don't do anything unless the merge state is actually changing.
  5139. */
  5140. if (Merge_State != merge_state)
  5141. {
  5142. /*
  5143. * If the old state is inactive, then that means that we are just
  5144. * beginning a domain merge operation. If this is the case, then
  5145. * iterate through the downward attachment list, telling all
  5146. * attachments about the domain merge.
  5147. *
  5148. * Note that a side effect of this call is that all MCS commands
  5149. * are shut off from the attachments that receive it. This allows the
  5150. * domain information base to remain stable during a merge operation.
  5151. */
  5152. if (Merge_State == MERGE_INACTIVE)
  5153. {
  5154. m_AttachmentList.Reset();
  5155. while (NULL != (pAtt = m_AttachmentList.Iterate()))
  5156. {
  5157. pAtt->MergeDomainIndication(MERGE_DOMAIN_IN_PROGRESS);
  5158. }
  5159. }
  5160. /*
  5161. * Set the merge state.
  5162. */
  5163. Merge_State = merge_state;
  5164. /*
  5165. * If the new state is inactive, then that means that we have just
  5166. * completed a domain merge operation. If this is the case, then
  5167. * iterate through the downward attachment list, telling all
  5168. * attachments about the completion of the merge.
  5169. *
  5170. * Note that a side effect of this call is to re-enable MCS commands
  5171. * from the attachments that receive it.
  5172. */
  5173. if (Merge_State == MERGE_INACTIVE)
  5174. {
  5175. m_AttachmentList.Reset();
  5176. while (NULL != (pAtt = m_AttachmentList.Iterate()))
  5177. {
  5178. pAtt->MergeDomainIndication(MERGE_DOMAIN_COMPLETE);
  5179. }
  5180. }
  5181. }
  5182. }
  5183. /*
  5184. * Void AddChannel ()
  5185. *
  5186. * Private
  5187. *
  5188. * Functional Description:
  5189. * This function is used to add a channel to the channel list during a
  5190. * merge channel operation. This type of channel addition works a little
  5191. * differently, since we do not want to send confirms to the users, but
  5192. * rather, to former Top Provider of the lower domain.
  5193. *
  5194. * Formal Parameters:
  5195. * attachment
  5196. * This is the initial attachment that the channel is to have joined
  5197. * to it.
  5198. * merge_channel
  5199. * This is a pointer to a channel attributes structure containing the
  5200. * attributes of the channel to be added.
  5201. * merge_channel_list
  5202. * This is a list of channel attribute structures for those channels
  5203. * that were successfully merged into the domain information base. It
  5204. * will be used to issue the merge channels confirm downward.
  5205. * purge_channel_list
  5206. * This is a list of channel IDs for those channels that were not
  5207. * successfully merged into the domain information base. It will be
  5208. * used to issue the merge channels confirm downward.
  5209. *
  5210. * Return Value:
  5211. * None.
  5212. *
  5213. * Side Effects:
  5214. * None.
  5215. */
  5216. Void Domain::AddChannel (
  5217. PConnection pConn,
  5218. PChannelAttributes merge_channel,
  5219. CChannelAttributesList *merge_channel_list,
  5220. CChannelIDList *purge_channel_list)
  5221. {
  5222. Channel_Type channel_type;
  5223. ChannelID channel_id=0;
  5224. BOOL joined;
  5225. ChannelID channel_manager=0;
  5226. CUidList *admitted_list;
  5227. PChannel channel=NULL;
  5228. CUidList detach_user_list;
  5229. CChannelIDList channel_leave_list;
  5230. /*
  5231. * Determine what has to be done according to the channel type.
  5232. */
  5233. channel_type = merge_channel->channel_type;
  5234. switch (channel_type)
  5235. {
  5236. case STATIC_CHANNEL:
  5237. /*
  5238. * Get the channel ID from the attributes structure.
  5239. */
  5240. channel_id = merge_channel->u.static_channel_attributes.channel_id;
  5241. /*
  5242. * If this is the Top Provider, check to see if current
  5243. * domain parameters will permit the merge.
  5244. */
  5245. if ((m_pConnToTopProvider == NULL) &&
  5246. (Number_Of_Channels >= Domain_Parameters.max_channel_ids))
  5247. {
  5248. ERROR_OUT(("Domain::AddChannel: too many channels"));
  5249. channel = NULL;
  5250. break;
  5251. }
  5252. /*
  5253. * Attempt to create a new Channel object.
  5254. */
  5255. TRACE_OUT(("Domain::AddChannel: adding new channel ID = %04X", (UINT) channel_id));
  5256. DBG_SAVE_FILE_LINE
  5257. channel = new Channel(channel_id, this, m_pConnToTopProvider, &m_ChannelList2,
  5258. &m_AttachmentList, pConn);
  5259. /*
  5260. * Increment the number of channels if everything went okay.
  5261. */
  5262. if (channel != NULL)
  5263. Number_Of_Channels++;
  5264. break;
  5265. case USER_CHANNEL:
  5266. /*
  5267. * Get the channel ID from the attributes structure.
  5268. */
  5269. joined = merge_channel->u.user_channel_attributes.joined;
  5270. channel_id = merge_channel->u.user_channel_attributes.user_id;
  5271. /*
  5272. * If this is the Top Provider, check to see if current
  5273. * domain parameters will permit the merge.
  5274. */
  5275. if ((m_pConnToTopProvider == NULL) &&
  5276. ((Number_Of_Users >= Domain_Parameters.max_user_ids) ||
  5277. (Number_Of_Channels >= Domain_Parameters.max_channel_ids)))
  5278. {
  5279. ERROR_OUT(("Domain::AddChannel: too many users"));
  5280. channel = NULL;
  5281. break;
  5282. }
  5283. /*
  5284. * Attempt to create a new UserChannel object to represent the
  5285. * merged user ID.
  5286. */
  5287. TRACE_OUT(("Domain::AddChannel: adding new user ID = %04X", (UINT) channel_id));
  5288. DBG_SAVE_FILE_LINE
  5289. channel = new UserChannel(channel_id, pConn, this, m_pConnToTopProvider,
  5290. &m_ChannelList2, &m_AttachmentList, joined ? pConn : NULL);
  5291. /*
  5292. * Increment the number of users if everything went okay.
  5293. */
  5294. if (channel != NULL)
  5295. {
  5296. Number_Of_Users++;
  5297. Number_Of_Channels++;
  5298. }
  5299. break;
  5300. case PRIVATE_CHANNEL:
  5301. /*
  5302. * Get the channel ID and the channel manager ID from the
  5303. * attributes structure.
  5304. */
  5305. joined = merge_channel->u.private_channel_attributes.joined;
  5306. channel_id = merge_channel->u.private_channel_attributes.channel_id;
  5307. channel_manager = merge_channel->
  5308. u.private_channel_attributes.channel_manager;
  5309. admitted_list = merge_channel->
  5310. u.private_channel_attributes.admitted_list;
  5311. /*
  5312. * If this is the Top Provider, check to see if current
  5313. * domain parameters will permit the merge.
  5314. */
  5315. if ((m_pConnToTopProvider == NULL) &&
  5316. (Number_Of_Channels >= Domain_Parameters.max_channel_ids))
  5317. {
  5318. ERROR_OUT(("Domain::AddChannel: too many channels"));
  5319. channel = NULL;
  5320. break;
  5321. }
  5322. /*
  5323. * Attempt to create a new PrivateChannel object.
  5324. */
  5325. TRACE_OUT(("Domain::AddChannel: adding new private channel ID = %04X", (UINT) channel_id));
  5326. DBG_SAVE_FILE_LINE
  5327. channel = new PrivateChannel(channel_id, channel_manager, this, m_pConnToTopProvider,
  5328. &m_ChannelList2, &m_AttachmentList, admitted_list,
  5329. joined ? pConn : NULL);
  5330. /*
  5331. * Increment the number of channels if everything went okay.
  5332. */
  5333. if (channel != NULL)
  5334. Number_Of_Channels++;
  5335. break;
  5336. case ASSIGNED_CHANNEL:
  5337. /*
  5338. * Get the channel ID from the attributes structure.
  5339. */
  5340. channel_id = merge_channel->
  5341. u.assigned_channel_attributes.channel_id;
  5342. /*
  5343. * If this is the Top Provider, check to see if current
  5344. * domain parameters will permit the merge.
  5345. */
  5346. if ((m_pConnToTopProvider == NULL) &&
  5347. (Number_Of_Channels >= Domain_Parameters.max_channel_ids))
  5348. {
  5349. ERROR_OUT(("Domain::AddChannel: too many channels"));
  5350. channel = NULL;
  5351. break;
  5352. }
  5353. /*
  5354. * Attempt to create a new Channel object.
  5355. */
  5356. TRACE_OUT(("Domain::AddChannel: adding new channel ID = %04X", (UINT) channel_id));
  5357. DBG_SAVE_FILE_LINE
  5358. channel = new Channel(channel_id, this, m_pConnToTopProvider, &m_ChannelList2,
  5359. &m_AttachmentList, pConn);
  5360. /*
  5361. * Increment the number of channels if everything went okay.
  5362. */
  5363. if (channel != NULL)
  5364. Number_Of_Channels++;
  5365. break;
  5366. }
  5367. if (channel != NULL)
  5368. {
  5369. /*
  5370. * The channel was successfully created. Add it to the channel list
  5371. * and add the channel structure to the merge channel list, which is
  5372. * used to issue the merge channels confirm downward.
  5373. */
  5374. m_ChannelList2.Insert(channel_id, channel);
  5375. merge_channel_list->Append(merge_channel);
  5376. }
  5377. else
  5378. {
  5379. /*
  5380. * The channel merge operation has failed. We need to tell whoever
  5381. * is interested in this situation.
  5382. */
  5383. WARNING_OUT(("Domain::AddChannel: channel merger failed"));
  5384. if (m_pConnToTopProvider != NULL)
  5385. {
  5386. /*
  5387. * If this is not the Top Provider, then the Top Provider needs
  5388. * to be told about the problem. If this is a user channel, then
  5389. * issue a detach user request. If it is a normal channel, issue
  5390. * a channel leave request. If it is a private channel, issue a
  5391. * channel disband request.
  5392. */
  5393. switch (channel_type)
  5394. {
  5395. case STATIC_CHANNEL:
  5396. case ASSIGNED_CHANNEL:
  5397. TRACE_OUT(("Domain::AddChannel: sending ChannelLeaveRequest to Top Provider"));
  5398. channel_leave_list.Append(channel_id);
  5399. m_pConnToTopProvider->ChannelLeaveRequest(&channel_leave_list);
  5400. break;
  5401. case USER_CHANNEL:
  5402. TRACE_OUT(("Domain::AddChannel: sending DetachUserRequest to Top Provider"));
  5403. detach_user_list.Append(channel_id);
  5404. m_pConnToTopProvider->DetachUserRequest(REASON_PROVIDER_INITIATED, &detach_user_list);
  5405. break;
  5406. case PRIVATE_CHANNEL:
  5407. TRACE_OUT(("Domain::AddChannel: sending ChannelDisbandRequest to Top Provider"));
  5408. m_pConnToTopProvider->ChannelDisbandRequest(channel_manager, channel_id);
  5409. break;
  5410. }
  5411. }
  5412. /*
  5413. * Since the merge has failed, we need to put the channel ID into the
  5414. * purge channel list (which is used to issue the merge channels
  5415. * confirm downward).
  5416. */
  5417. purge_channel_list->Append(channel_id);
  5418. }
  5419. }
  5420. /*
  5421. * Void AddToken ()
  5422. *
  5423. * Private
  5424. *
  5425. * Functional Description:
  5426. * This function is used to add a token to the token list during a
  5427. * merge token operation. This type of token addition works a little
  5428. * differently, since we do not want to send confirms to the owners of
  5429. * the token, but rather, to the former Top Provider of the lower domain.
  5430. *
  5431. * Formal Parameters:
  5432. * merge_token
  5433. * This is a pointer to a token attributes structure containing the
  5434. * attributes of the token to be added.
  5435. * merge_token_list
  5436. * This is a list of token attribute structures for those tokens
  5437. * that were successfully merged into the domain information base. It
  5438. * will be used to issue the merge tokens confirm downward.
  5439. * purge_token_list
  5440. * This is a list of token IDs for those tokens that were not
  5441. * successfully merged into the domain information base. It will be
  5442. * used to issue the merge tokens confirm downward.
  5443. *
  5444. * Return Value:
  5445. * None.
  5446. *
  5447. * Side Effects:
  5448. * None.
  5449. */
  5450. Void Domain::AddToken (
  5451. PTokenAttributes merge_token,
  5452. CTokenAttributesList *merge_token_list,
  5453. CTokenIDList *purge_token_list)
  5454. {
  5455. TokenState token_state;
  5456. TokenID token_id;
  5457. UserID grabber;
  5458. CUidList *inhibitor_list;
  5459. UserID recipient;
  5460. PToken token;
  5461. UserID uid;
  5462. /*
  5463. * Determine what state the token to be merged is in. Then get the
  5464. * required information for each particular state.
  5465. */
  5466. token_state = merge_token->token_state;
  5467. switch (token_state)
  5468. {
  5469. case TOKEN_GRABBED:
  5470. token_id = merge_token->u.grabbed_token_attributes.token_id;
  5471. grabber = merge_token->u.grabbed_token_attributes.grabber;
  5472. inhibitor_list = NULL;
  5473. recipient = 0;
  5474. break;
  5475. case TOKEN_INHIBITED:
  5476. token_id = merge_token->u.inhibited_token_attributes.token_id;
  5477. grabber = 0;
  5478. inhibitor_list = merge_token->
  5479. u.inhibited_token_attributes.inhibitors;
  5480. recipient = 0;
  5481. break;
  5482. case TOKEN_GIVING:
  5483. token_id = merge_token->u.giving_token_attributes.token_id;
  5484. grabber = merge_token->u.giving_token_attributes.grabber;
  5485. inhibitor_list = NULL;
  5486. recipient = merge_token->u.giving_token_attributes.recipient;
  5487. break;
  5488. case TOKEN_GIVEN:
  5489. token_id = merge_token->u.given_token_attributes.token_id;
  5490. grabber = 0;
  5491. inhibitor_list = NULL;
  5492. recipient = merge_token->u.given_token_attributes.recipient;
  5493. break;
  5494. }
  5495. /*
  5496. * Check to see if it is okay to add this token. If we are the top
  5497. * provider, and adding this token would cause us to exceed the arbitrated
  5498. * limit on tokens, then we must fail the request.
  5499. */
  5500. if ((m_pConnToTopProvider != NULL) ||
  5501. (Number_Of_Tokens < Domain_Parameters.max_token_ids))
  5502. {
  5503. /*
  5504. * Create a new token with all merged values as determined above.
  5505. */
  5506. DBG_SAVE_FILE_LINE
  5507. token = new Token(token_id, this, m_pConnToTopProvider, &m_ChannelList2,
  5508. &m_AttachmentList, token_state, grabber, inhibitor_list, recipient);
  5509. if (token != NULL)
  5510. {
  5511. /*
  5512. * If the creation was successful, add the token to the list and
  5513. * add the token attributes structure to the merge token list.
  5514. */
  5515. TRACE_OUT(("Domain::AddToken: add new token ID = %04X", (UINT) token_id));
  5516. m_TokenList2.Append(token_id, token);
  5517. Number_Of_Tokens++;
  5518. merge_token_list->Append(merge_token);
  5519. }
  5520. else
  5521. {
  5522. /*
  5523. * The token allocation has failed. It is therefore necessary to
  5524. * perform some cleanup operations.
  5525. */
  5526. WARNING_OUT (("Domain::AddToken: token allocation failed"));
  5527. /*
  5528. * Check to see if this is the top provider. If not, then it
  5529. * is necessary to issue appropriate requests upward to free the
  5530. * token from the information bases above.
  5531. */
  5532. if (m_pConnToTopProvider != NULL)
  5533. {
  5534. /*
  5535. * Determine which state the token is in. This affects how
  5536. * the cleanup needs to work.
  5537. */
  5538. switch (token_state)
  5539. {
  5540. case TOKEN_GRABBED:
  5541. /*
  5542. * If the token is grabbed, then issue a release to
  5543. * free it above.
  5544. */
  5545. m_pConnToTopProvider->TokenReleaseRequest(grabber, token_id);
  5546. break;
  5547. case TOKEN_INHIBITED:
  5548. {
  5549. /*
  5550. * Iterate through the inhibitor list, issuing a
  5551. * release request for each user contained therein.
  5552. * This will result in the token being freed at all
  5553. * upward providers.
  5554. */
  5555. inhibitor_list->Reset();
  5556. while (NULL != (uid = inhibitor_list->Iterate()))
  5557. {
  5558. m_pConnToTopProvider->TokenReleaseRequest(uid, token_id);
  5559. }
  5560. }
  5561. break;
  5562. case TOKEN_GIVING:
  5563. /*
  5564. * If the token is being given from one user to
  5565. * another, issue a release on behalf of the current
  5566. * owner, and a rejected give response on behalf
  5567. * of the recipient.
  5568. *
  5569. * WARNING:
  5570. * This will cause the current owner to receive a
  5571. * release confirm with no outstanding request.
  5572. */
  5573. m_pConnToTopProvider->TokenReleaseRequest(grabber, token_id);
  5574. m_pConnToTopProvider->TokenGiveResponse(RESULT_USER_REJECTED,
  5575. recipient, token_id);
  5576. break;
  5577. case TOKEN_GIVEN:
  5578. /*
  5579. * Issue a rejected give response on behalf of the
  5580. * user that is being offered the token.
  5581. */
  5582. m_pConnToTopProvider->TokenGiveResponse(RESULT_USER_REJECTED,
  5583. recipient, token_id);
  5584. break;
  5585. }
  5586. }
  5587. /*
  5588. * Add the token ID to the purge token list, which will be passed
  5589. * downward to the former top provider of the lower domain. This
  5590. * will tell that provider that the token was NOT accepted in the
  5591. * upper domain.
  5592. */
  5593. purge_token_list->Append(token_id);
  5594. }
  5595. }
  5596. else
  5597. {
  5598. /*
  5599. * The upper domain already has the domain limit of tokens. So
  5600. * automatically reject the merge request.
  5601. */
  5602. ERROR_OUT(("Domain::AddToken: too many tokens - rejecting merge"));
  5603. purge_token_list->Append(token_id);
  5604. }
  5605. }
  5606. /*
  5607. * Void CalculateDomainHeight ()
  5608. *
  5609. * Private
  5610. *
  5611. * Functional Description:
  5612. * This function is called whenever an event occurs that could have
  5613. * resulted in a change in the overall height of the domain. This includes
  5614. * making and breaking connections, and the reception of an erect domain
  5615. * request from a lower provider.
  5616. *
  5617. * This routine will adjust the height of the current provider, and if
  5618. * this is the top provider, will take necessary steps to insure that the
  5619. * arbitrated domain parameters are not violated.
  5620. *
  5621. * Formal Parameters:
  5622. * None.
  5623. *
  5624. * Return Value:
  5625. * None.
  5626. *
  5627. * Side Effects:
  5628. * None.
  5629. */
  5630. Void Domain::CalculateDomainHeight ()
  5631. {
  5632. UINT_PTR domain_height;
  5633. UINT_PTR temp_domain_height;
  5634. CAttachment *pAtt;
  5635. /*
  5636. * Initialize domain height to zero. This will only be increased if there
  5637. * is at least one remote attachment below this one.
  5638. */
  5639. domain_height = 0;
  5640. /*
  5641. * Check to see if there is anyone below this provider that would affect
  5642. * its height in the domain (this would be remote attachments that have
  5643. * issued ErectDomainRequests to tell this provider of their height).
  5644. */
  5645. if (m_DomainHeightList2.IsEmpty() == FALSE)
  5646. {
  5647. /*
  5648. * Iterate through the domain height list to determine which downward
  5649. * attachment has the greatest height. This is the height that will be
  5650. * used to determine height of this provider.
  5651. */
  5652. m_DomainHeightList2.Reset();
  5653. while (NULL != (temp_domain_height = m_DomainHeightList2.Iterate()))
  5654. {
  5655. if (domain_height < temp_domain_height)
  5656. domain_height = temp_domain_height;
  5657. }
  5658. /*
  5659. * The height of this provider is one greater than the height of its
  5660. * highest downward attachment.
  5661. */
  5662. domain_height++;
  5663. }
  5664. /*
  5665. * Compare the calculated domain height with the current domain height.
  5666. * If they are the same, then no further action needs to be taken.
  5667. */
  5668. if (domain_height != m_nDomainHeight)
  5669. {
  5670. TRACE_OUT(("Domain::CalculateDomainHeight: new domain height = %d", (UINT) domain_height));
  5671. m_nDomainHeight = domain_height;
  5672. /*
  5673. * The domain height has changed. We need to verify that the
  5674. * arbitrated domain height has not been violated.
  5675. */
  5676. if (m_nDomainHeight > Domain_Parameters.max_height)
  5677. {
  5678. /*
  5679. * The new domain height is invalid. We must issue a plumb
  5680. * domain indication downward to enforce the arbitrated
  5681. * domain height.
  5682. */
  5683. TRACE_OUT(("Domain::CalculateDomainHeight: issuing plumb domain indication"));
  5684. m_AttachmentList.Reset();
  5685. while (NULL != (pAtt = m_AttachmentList.Iterate()))
  5686. {
  5687. pAtt->PlumbDomainIndication(Domain_Parameters.max_height);
  5688. }
  5689. }
  5690. /*
  5691. * If this is not the Top Provider, then it is necessary to transmit an
  5692. * erect domain request upward to inform the upper domain of the
  5693. * change.
  5694. */
  5695. if (m_pConnToTopProvider != NULL)
  5696. {
  5697. /*
  5698. * Issue an erect domain request upward to inform the upper
  5699. * domain of the change in height. Without this, the Top Provider
  5700. * would have no way of determining when the domain height is
  5701. * invalid.
  5702. */
  5703. m_pConnToTopProvider->ErectDomainRequest(m_nDomainHeight, DEFAULT_THROUGHPUT_ENFORCEMENT_INTERVAL);
  5704. }
  5705. }
  5706. }
  5707. PUser CAttachmentList::IterateUser(void)
  5708. {
  5709. CAttachment *pAtt;
  5710. while (NULL != (pAtt = Iterate()))
  5711. {
  5712. if (pAtt->IsUserAttachment())
  5713. {
  5714. return (PUser) pAtt;
  5715. }
  5716. }
  5717. return NULL;
  5718. }
  5719. PConnection CAttachmentList::IterateConn(void)
  5720. {
  5721. CAttachment *pAtt;
  5722. while (NULL != (pAtt = Iterate()))
  5723. {
  5724. if (pAtt->IsConnAttachment())
  5725. {
  5726. return (PConnection) pAtt;
  5727. }
  5728. }
  5729. return NULL;
  5730. }
  5731.