Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

6038 lines
180 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. if(m_ChannelList2.Insert(uidInitiator, channel))
  1832. {
  1833. Number_Of_Users++;
  1834. Number_Of_Channels++;
  1835. /*
  1836. * If the user's attachment is not already in the
  1837. * attachment list, then this must be a new local
  1838. * attachment. Add it to the attachment list as such.
  1839. */
  1840. if (! m_AttachmentList.Find(pAtt))
  1841. {
  1842. ASSERT(pAtt->IsUserAttachment());
  1843. m_AttachmentList.Append(pAtt);
  1844. }
  1845. }
  1846. else
  1847. {
  1848. delete channel;
  1849. }
  1850. }
  1851. else
  1852. {
  1853. /*
  1854. * The local provider was unable to allocate the
  1855. * UserChannel object. This means that the new user
  1856. * must be removed from the domain. To do this, send
  1857. * a DetachUserRequest to the Top Provider and an
  1858. * unsuccessful AttachUserConfirm to the originator
  1859. * of the request.
  1860. */
  1861. ERROR_OUT(("Domain::AttachUserConfirm: user allocation failed"));
  1862. detach_user_list.Append(uidInitiator);
  1863. m_pConnToTopProvider->DetachUserRequest(REASON_PROVIDER_INITIATED, &detach_user_list);
  1864. pAtt->AttachUserConfirm(RESULT_UNSPECIFIED_FAILURE, 0);
  1865. }
  1866. }
  1867. else
  1868. {
  1869. /*
  1870. * The ID associated with this confirm is already in use.
  1871. * This indicates that something is wrong above. This
  1872. * provider has no choice but to ignore the confirm.
  1873. */
  1874. WARNING_OUT(("Domain::AttachUserConfirm: channel ID already in use"));
  1875. }
  1876. }
  1877. else
  1878. {
  1879. /*
  1880. * Since the result of the attach was not successful, this
  1881. * provider does not have to add anything to its channel list.
  1882. * The only required action is to forward the confirm to the
  1883. * originating user.
  1884. */
  1885. TRACE_OUT(("Domain::AttachUserConfirm: echoing failed confirm"));
  1886. pAtt->AttachUserConfirm(result, uidInitiator);
  1887. }
  1888. }
  1889. else
  1890. {
  1891. /*
  1892. * The attach user queue is empty. This probably indicates that
  1893. * the connection to the user who originated the request was lost
  1894. * before the confirm got back. This provider doesn't need to
  1895. * do anything except issue a DetachUserRequest (if the confirm
  1896. * indicates that the attach operation was successful).
  1897. */
  1898. WARNING_OUT(("Domain::AttachUserConfirm: attach user queue empty"));
  1899. if (result == RESULT_SUCCESSFUL)
  1900. {
  1901. TRACE_OUT (("Domain::AttachUserConfirm: sending DetachUserRequest"));
  1902. detach_user_list.Append(uidInitiator);
  1903. m_pConnToTopProvider->DetachUserRequest(REASON_DOMAIN_DISCONNECTED, &detach_user_list);
  1904. }
  1905. }
  1906. }
  1907. else
  1908. {
  1909. /*
  1910. * This confirm was received from someone besides the Top Provider.
  1911. * Ignore it.
  1912. */
  1913. ERROR_OUT(("Domain::AttachUserConfirm: invalid originator=0x%p", pOrigConn));
  1914. }
  1915. }
  1916. /*
  1917. * Void DetachUserRequest ()
  1918. *
  1919. * Public
  1920. *
  1921. * Functional Description:
  1922. * This MCS command is initiated by a user attachment that wishes to leave
  1923. * the domain. After validation, delete the user from the information base
  1924. * pass the request upward.
  1925. */
  1926. Void Domain::DetachUserRequest (
  1927. CAttachment *pOrigAtt,
  1928. Reason reason,
  1929. CUidList *user_id_list)
  1930. {
  1931. UserID uid;
  1932. CUidList detach_user_list;
  1933. /*
  1934. * Iterate through the list of users named to be deleted.
  1935. */
  1936. user_id_list->Reset();
  1937. while (NULL != (uid = user_id_list->Iterate()))
  1938. {
  1939. /*
  1940. * Make sure the user really exists in the sub-tree from which this
  1941. * request originated.
  1942. */
  1943. if (ValidateUserID(uid, pOrigAtt))
  1944. {
  1945. /*
  1946. * Delete the user from the local information base.
  1947. */
  1948. DeleteUser(uid);
  1949. /*
  1950. * Put the user ID into the list of validated user IDs.
  1951. */
  1952. detach_user_list.Append(uid);
  1953. }
  1954. else
  1955. {
  1956. /*
  1957. * There is no such user in the sub-tree from which this request
  1958. * originated.
  1959. */
  1960. WARNING_OUT(("Domain::DetachUserRequest: invalid user ID"));
  1961. }
  1962. }
  1963. /*
  1964. * Check to see if there are any users to be deleted. If so, then process
  1965. * the request.
  1966. */
  1967. if (detach_user_list.IsEmpty() == FALSE)
  1968. {
  1969. /*
  1970. * Check to see if this is the Top Provider.
  1971. */
  1972. if (IsTopProvider())
  1973. {
  1974. /*
  1975. * This is the Top Provider, so issue a detach user indication to
  1976. * all downward attachments.
  1977. */
  1978. TRACE_OUT(("Domain::DetachUserRequest: sending DetachUserIndication to all attachments"));
  1979. CAttachment *pAtt;
  1980. m_AttachmentList.Reset();
  1981. while (NULL != (pAtt = m_AttachmentList.Iterate()))
  1982. {
  1983. pAtt->DetachUserIndication(reason, &detach_user_list);
  1984. }
  1985. }
  1986. else
  1987. {
  1988. /*
  1989. * This is not the Top Provider, so forward the detach user
  1990. * request upward.
  1991. */
  1992. TRACE_OUT(("Domain::DetachUserRequest: forwarding DetachUserRequest to Top Provider"));
  1993. m_pConnToTopProvider->DetachUserRequest(reason, &detach_user_list);
  1994. }
  1995. }
  1996. else
  1997. {
  1998. /*
  1999. * The user ID list contained no valid entries, so ignore the request.
  2000. */
  2001. ERROR_OUT(("Domain::DetachUserRequest: no valid user IDs"));
  2002. }
  2003. }
  2004. /*
  2005. * Void DetachUserIndication ()
  2006. *
  2007. * Public
  2008. *
  2009. * Functional Description:
  2010. * This MCS command is initially sent by the Top Provider in response to
  2011. * a user detaching from the domain (willingly or otherwise). It is
  2012. * forwarded downward in the hierarchy where it will eventually reach all
  2013. * providers and their user attachments.
  2014. */
  2015. Void Domain::DetachUserIndication (
  2016. PConnection pOrigConn,
  2017. Reason reason,
  2018. CUidList *user_id_list)
  2019. {
  2020. UserID uid;
  2021. /*
  2022. * Verify that the indication came from the Top Provider.
  2023. */
  2024. if (pOrigConn == m_pConnToTopProvider)
  2025. {
  2026. /*
  2027. * The first thing to do is repeat the indication to all downward
  2028. * attachments. Keep in mind that this sends the detach indication
  2029. * to user attachments as well as remote connections.
  2030. */
  2031. TRACE_OUT(("Domain::DetachUserIndication: forwarding DetachUserIndication to all attachments"));
  2032. CAttachment *pAtt;
  2033. m_AttachmentList.Reset();
  2034. while (NULL != (pAtt = m_AttachmentList.Iterate()))
  2035. {
  2036. pAtt->DetachUserIndication(reason, user_id_list);
  2037. }
  2038. /*
  2039. * Iterate through the list of users, deleting those that are in
  2040. * the sub-tree of this provider.
  2041. */
  2042. user_id_list->Reset();
  2043. while (NULL != (uid = user_id_list->Iterate()))
  2044. {
  2045. /*
  2046. * Check to see if this user is somewhere in the sub-tree of this
  2047. * provider. If so it is necessary to delete the user channel from
  2048. * the channel list. Note that it is perfectly normal to receive a
  2049. * detach user indication for a user that is not in the sub-tree of
  2050. * the receiving provider.
  2051. */
  2052. if (ValidateUserID(uid, NULL) )
  2053. {
  2054. /*
  2055. * Delete the user from the local information base.
  2056. */
  2057. DeleteUser(uid);
  2058. }
  2059. }
  2060. }
  2061. else
  2062. {
  2063. /*
  2064. * This indication was received from someone besides the Top Provider.
  2065. * Ignore the indication.
  2066. */
  2067. ERROR_OUT(("Domain::DetachUserIndication: invalid originator=0x%p", pOrigConn));
  2068. }
  2069. }
  2070. /*
  2071. * Void ChannelJoinRequest ()
  2072. *
  2073. * Public
  2074. *
  2075. * Functional Description:
  2076. * This MCS command is initially sent by a user attachment that wishes
  2077. * to join a channel. It flows upward in the hierarchy until it reaches
  2078. * a provider who is already joined to the channel. That provider (which
  2079. * is not necessarily the Top Provider), will issue a channel join
  2080. * confirm, indicating whether or not the join was successful.
  2081. */
  2082. Void Domain::ChannelJoinRequest (
  2083. CAttachment *pOrigAtt,
  2084. UserID uidInitiator,
  2085. ChannelID channel_id)
  2086. {
  2087. PChannel channel;
  2088. ChannelID requested_id;
  2089. /*
  2090. * Make sure the requesting user really exists in the sub-tree from which
  2091. * this request originated.
  2092. */
  2093. if (ValidateUserID(uidInitiator, pOrigAtt))
  2094. {
  2095. /*
  2096. * See if the channel already exists in the local information base.
  2097. * If so, then let the Channel object handle the join request.
  2098. */
  2099. if (NULL != (channel = m_ChannelList2.Find(channel_id)))
  2100. {
  2101. TRACE_OUT(("Domain::ChannelJoinRequest: sending join request to channel object"));
  2102. channel->ChannelJoinRequest(pOrigAtt, uidInitiator, channel_id);
  2103. }
  2104. else
  2105. {
  2106. /*
  2107. * The channel does not already exist in the channel list. Check
  2108. * to see if this is the Top Provider. If so, we can try to
  2109. * add the channel to the list. If this is not the Top Provider,
  2110. * then we simply forward the request upward.
  2111. */
  2112. if (IsTopProvider())
  2113. {
  2114. /*
  2115. * Save the value of the channel the user originally attempted
  2116. * to join. This may change if this is a request to join
  2117. * channel 0 (an assigned channel).
  2118. */
  2119. requested_id = channel_id;
  2120. /*
  2121. * We already know the channel does not exist in the channel
  2122. * list. Therefore, this is a valid request only if the
  2123. * channel being joined is a static channel or channel 0 (which
  2124. * is interpreted as a request for an assigned channel).
  2125. * Dynamic channels (those above 1000) can only be joined if
  2126. * they already exist.
  2127. */
  2128. if (requested_id <= 1000)
  2129. {
  2130. /*
  2131. * See if the arbitrated domain parameters will allow the
  2132. * addition of a new channel.
  2133. */
  2134. if (Number_Of_Channels < Domain_Parameters.max_channel_ids)
  2135. {
  2136. /*
  2137. * If this is a request for an assigned channel, then
  2138. * allocate a random channel ID in the dynamic range.
  2139. * Then create a new Channel object.
  2140. */
  2141. if (requested_id == 0)
  2142. channel_id = AllocateDynamicChannel ();
  2143. DBG_SAVE_FILE_LINE
  2144. channel = new Channel(channel_id, this, m_pConnToTopProvider,
  2145. &m_ChannelList2, &m_AttachmentList);
  2146. if (channel != NULL)
  2147. {
  2148. /*
  2149. * The creation of the new channel was successful.
  2150. * Add it to the channel list.
  2151. */
  2152. TRACE_OUT(("Domain::ChannelJoinRequest: adding channel ID = %04X", (UINT) channel_id));
  2153. m_ChannelList2.Insert(channel_id, channel);
  2154. Number_Of_Channels++;
  2155. /*
  2156. * When new channels are created, they are
  2157. * initially empty. So we must join the
  2158. * originating attachment to the newly created
  2159. * attachment. This will also cause a channel
  2160. * join confirm to be issued to the originator.
  2161. */
  2162. channel->ChannelJoinRequest(pOrigAtt, uidInitiator, requested_id);
  2163. }
  2164. else
  2165. {
  2166. /*
  2167. * Allocation of the Channel object failed. We
  2168. * must therefore issue an unsuccessful channel
  2169. * join confirm to the originating attachment.
  2170. */
  2171. ERROR_OUT(("Domain::ChannelJoinRequest: channel allocation failed"));
  2172. pOrigAtt->ChannelJoinConfirm(RESULT_UNSPECIFIED_FAILURE, uidInitiator, requested_id, 0);
  2173. }
  2174. }
  2175. else
  2176. {
  2177. /*
  2178. * Domain parmeters will not allow the addition of
  2179. * any more channels. Fail the request.
  2180. */
  2181. ERROR_OUT(("Domain::ChannelJoinRequest: join denied - too many channels"));
  2182. pOrigAtt->ChannelJoinConfirm(RESULT_TOO_MANY_CHANNELS, uidInitiator, requested_id, 0);
  2183. }
  2184. }
  2185. else
  2186. {
  2187. /*
  2188. * There has been an attempt to join a dynamic channel
  2189. * that doesn't already exist. This is not allowed, so
  2190. * fail the request.
  2191. */
  2192. WARNING_OUT(("Domain::ChannelJoinRequest: attempt to join non-existent dynamic channel"));
  2193. pOrigAtt->ChannelJoinConfirm(RESULT_NO_SUCH_CHANNEL, uidInitiator, requested_id, 0);
  2194. }
  2195. }
  2196. else
  2197. {
  2198. /*
  2199. * The channel does not exist locally, and this is not the
  2200. * Top Provider. That means this is someone else problem.
  2201. * Issue the request upward toward the Top Provider.
  2202. */
  2203. TRACE_OUT(("Domain::ChannelJoinRequest: forwarding join request to Top Provider"));
  2204. m_pConnToTopProvider->ChannelJoinRequest(uidInitiator, channel_id);
  2205. }
  2206. }
  2207. }
  2208. else
  2209. {
  2210. /*
  2211. * There is no such user in the sub-tree from which this request
  2212. * originated. Ignore the request.
  2213. */
  2214. ERROR_OUT(("Domain::ChannelJoinRequest: invalid originator=0x%p", pOrigAtt));
  2215. }
  2216. }
  2217. /*
  2218. * Void ChannelJoinConfirm ()
  2219. *
  2220. * Public
  2221. *
  2222. * Functional Description:
  2223. * This MCS command originates from a provider who receives a channel
  2224. * join request, and has enough information to respond. This is not
  2225. * necessarily the Top Provider. An intermediate can respond if the
  2226. * channel exists in its information base. This confirm is forwarded
  2227. * back to the original requestor, letting it know whether or not the
  2228. * join was successful.
  2229. */
  2230. Void Domain::ChannelJoinConfirm (
  2231. PConnection pOrigConn,
  2232. Result result,
  2233. UserID uidInitiator,
  2234. ChannelID requested_id,
  2235. ChannelID channel_id)
  2236. {
  2237. PChannel channel;
  2238. CChannelIDList channel_leave_list;
  2239. /*
  2240. * Verify that the confirm came from the Top Provider.
  2241. */
  2242. if (pOrigConn == m_pConnToTopProvider)
  2243. {
  2244. /*
  2245. * Make sure that the requesting user is still somewhere in the
  2246. * sub-tree of this provider.
  2247. */
  2248. if (ValidateUserID (uidInitiator, NULL) )
  2249. {
  2250. /*
  2251. * Found out which downward attachment leads to the requesting
  2252. * user.
  2253. */
  2254. if (NULL != (channel = m_ChannelList2.Find(uidInitiator)))
  2255. {
  2256. CAttachment *pAtt = channel->GetAttachment();
  2257. ASSERT(pAtt);
  2258. /*
  2259. * Was the result successful. If is was, then the local provider
  2260. * needs to make sure the channel is in the local channel list.
  2261. * If its not already there, it will have to be created.
  2262. */
  2263. if (result == RESULT_SUCCESSFUL)
  2264. {
  2265. /*
  2266. * See if the named channel already exists in the channel list.
  2267. */
  2268. if (NULL != (channel = m_ChannelList2.Find(channel_id)))
  2269. {
  2270. /*
  2271. * A Channel object already exists for the named channel.
  2272. * Let it handle the join confirm.
  2273. */
  2274. TRACE_OUT(("Domain::ChannelJoinConfirm: sending confirm to channel object"));
  2275. channel->ChannelJoinConfirm(pAtt, result, uidInitiator, requested_id, channel_id);
  2276. }
  2277. else
  2278. {
  2279. /*
  2280. * The new channel will have to be created.
  2281. */
  2282. DBG_SAVE_FILE_LINE
  2283. channel = new Channel(channel_id, this, m_pConnToTopProvider,
  2284. &m_ChannelList2, &m_AttachmentList);
  2285. if (channel != NULL)
  2286. {
  2287. /*
  2288. * Add the newly created channel to the channel list,
  2289. * and then let the Channel object handle the join
  2290. * confirm.
  2291. */
  2292. TRACE_OUT(("Domain::ChannelJoinConfirm: adding channel ID = %04X", (UINT) channel_id));
  2293. m_ChannelList2.Insert(channel_id, channel);
  2294. Number_Of_Channels++;
  2295. channel->ChannelJoinConfirm(pAtt, result, uidInitiator, requested_id, channel_id);
  2296. }
  2297. else
  2298. {
  2299. /*
  2300. * The allocation of the Channel object failed. It
  2301. * is therefore necessary for this provider to cause
  2302. * the channel to be deleted from the domain. It
  2303. * does this by issuing a channel leave request to
  2304. * the Top Provider, and an unsuccessful channel
  2305. * join confirm to the originating user.
  2306. */
  2307. ERROR_OUT(("Domain::ChannelJoinConfirm: channel allocation failed"));
  2308. channel_leave_list.Append(channel_id);
  2309. m_pConnToTopProvider->ChannelLeaveRequest(&channel_leave_list);
  2310. pAtt->ChannelJoinConfirm(RESULT_UNSPECIFIED_FAILURE, uidInitiator, requested_id, 0);
  2311. }
  2312. }
  2313. }
  2314. else
  2315. {
  2316. /*
  2317. * The result was not successful, so this provider does not
  2318. * have to worry about creating the channel. It merely
  2319. * forwards the join confirm to the originating user.
  2320. */
  2321. TRACE_OUT(("Domain::ChannelJoinConfirm: forwarding ChannelJoinConfirm to user"));
  2322. pAtt->ChannelJoinConfirm(result, uidInitiator, requested_id, channel_id);
  2323. }
  2324. }
  2325. else
  2326. {
  2327. ERROR_OUT(("Domain::ChannelJoinConfirm: cannot find the channel"));
  2328. }
  2329. }
  2330. else
  2331. {
  2332. /*
  2333. * The named initiator does not exist in the sub-tree of this
  2334. * provider. This could happen if the user is detached before
  2335. * the confirm returns. It will be necessary to issue a channel
  2336. * leave request upward (if the join was successful).
  2337. */
  2338. WARNING_OUT(("Domain::ChannelJoinConfirm: initiator not found"));
  2339. if (result == RESULT_SUCCESSFUL)
  2340. {
  2341. TRACE_OUT(("Domain::ChannelJoinConfirm: sending ChannelLeaveRequest to Top Provider"));
  2342. channel_leave_list.Append(channel_id);
  2343. m_pConnToTopProvider->ChannelLeaveRequest(&channel_leave_list);
  2344. }
  2345. }
  2346. }
  2347. else
  2348. {
  2349. /*
  2350. * This confirm was received from someone besides the Top Provider.
  2351. * Ignore the indication.
  2352. */
  2353. ERROR_OUT(("Domain::ChannelJoinConfirm: invalid originator=0x%p", pOrigConn));
  2354. }
  2355. }
  2356. /*
  2357. * Void ChannelLeaveRequest ()
  2358. *
  2359. * Public
  2360. *
  2361. * Functional Description:
  2362. * This MCS command is initially issued by a user that wishes to leave a
  2363. * channel. This request will stop cascading upward when it reaches a
  2364. * provider that has more attachments joined to the channel than the
  2365. * one that is leaving. If the requesting user is the only joined to
  2366. * a channel, this request will flow all the way to the Top Provider.
  2367. */
  2368. Void Domain::ChannelLeaveRequest (
  2369. CAttachment *pOrigAtt,
  2370. CChannelIDList *channel_id_list)
  2371. {
  2372. ChannelID chid;
  2373. PChannel channel;
  2374. CChannelIDList channel_leave_list;
  2375. /*
  2376. * Make sure that the attachment leaving the channel really does exist.
  2377. */
  2378. if (m_AttachmentList.Find(pOrigAtt))
  2379. {
  2380. /*
  2381. * Iterate through the list of channels to be left, processing each
  2382. * one independently.
  2383. */
  2384. channel_id_list->Reset();
  2385. while (NULL != (chid = channel_id_list->Iterate()))
  2386. {
  2387. /*
  2388. * Check to make sure that the channel being left really does
  2389. * exist.
  2390. */
  2391. if (NULL != (channel = m_ChannelList2.Find(chid)))
  2392. {
  2393. /*
  2394. * Let the Channel object deal with this request. After
  2395. * sending the leave request to the channel, it is necessary to
  2396. * check the validity of the channel object determine if it
  2397. * should be deleted as a result of this leave operation.
  2398. */
  2399. TRACE_OUT(("Domain::ChannelLeaveRequest: processing leave request for channel ID = %04X", (UINT) chid));
  2400. channel_leave_list.Clear();
  2401. channel_leave_list.Append(chid);
  2402. channel->ChannelLeaveRequest(pOrigAtt, &channel_leave_list);
  2403. if (channel->IsValid () == FALSE)
  2404. DeleteChannel(chid);
  2405. }
  2406. else
  2407. {
  2408. /*
  2409. * The named channel does not exist in the information base.
  2410. * Ignore the request.
  2411. */
  2412. WARNING_OUT(("Domain::ChannelLeaveRequest: received leave request for non-existent channel"));
  2413. }
  2414. }
  2415. }
  2416. else
  2417. {
  2418. /*
  2419. * This request originated from an attachment that does not exist
  2420. * in the sub-tree of this provider.
  2421. */
  2422. ERROR_OUT(("Domain::ChannelLeaveRequest: invalid originator=0x%p", pOrigAtt));
  2423. }
  2424. }
  2425. /*
  2426. * Void ChannelConveneRequest ()
  2427. *
  2428. * Public
  2429. *
  2430. * Functional Description:
  2431. * This MCS command is initially sent by a user that wishes to convene a
  2432. * new private channel. It is forwarded upward to the Top Provider who
  2433. * will attempt to create the private channel.
  2434. */
  2435. Void Domain::ChannelConveneRequest (
  2436. CAttachment *pOrigAtt,
  2437. UserID uidInitiator)
  2438. {
  2439. ChannelID channel_id;
  2440. PChannel channel;
  2441. /*
  2442. * Make sure the requesting user really exists in the sub-tree from which
  2443. * this request originated.
  2444. */
  2445. if (ValidateUserID(uidInitiator, pOrigAtt))
  2446. {
  2447. /*
  2448. * If this is the Top Provider, then the request can be serviced
  2449. * locally. If not, then it must be forwarded upward.
  2450. */
  2451. if (IsTopProvider())
  2452. {
  2453. /*
  2454. * See if the arbitrated domain parameters will allow the
  2455. * addition of a new channel.
  2456. */
  2457. if (Number_Of_Channels < Domain_Parameters.max_channel_ids)
  2458. {
  2459. /*
  2460. * Since this is a request for a private channel, it is
  2461. * necessary to allocate a channel ID from the dynamic range.
  2462. * Then, create the private channel.
  2463. */
  2464. channel_id = AllocateDynamicChannel ();
  2465. DBG_SAVE_FILE_LINE
  2466. channel = new PrivateChannel(channel_id, uidInitiator, this, m_pConnToTopProvider,
  2467. &m_ChannelList2, &m_AttachmentList);
  2468. if (channel != NULL)
  2469. {
  2470. /*
  2471. * The creation of the new private channel was successful.
  2472. * Add it to the channel list. Note that the channel
  2473. * object itself will issue the channel convene confirm.
  2474. */
  2475. TRACE_OUT(("Domain::ChannelConveneRequest: adding channel ID = %04X", (UINT) channel_id));
  2476. m_ChannelList2.Insert(channel_id, channel);
  2477. Number_Of_Channels++;
  2478. }
  2479. else
  2480. {
  2481. /*
  2482. * Allocation of the PrivateChannel object failed. We
  2483. * must therefore issue an unsuccessful channel
  2484. * convene confirm to the originating attachment.
  2485. */
  2486. ERROR_OUT(("Domain::ChannelConveneRequest: channel allocation failed"));
  2487. pOrigAtt->ChannelConveneConfirm(RESULT_UNSPECIFIED_FAILURE, uidInitiator, 0);
  2488. }
  2489. }
  2490. else
  2491. {
  2492. /*
  2493. * Domain parmeters will not allow the addition of
  2494. * any more channels. Fail the request.
  2495. */
  2496. ERROR_OUT(("Domain::ChannelConveneRequest: join denied - too many channels"));
  2497. pOrigAtt->ChannelConveneConfirm(RESULT_TOO_MANY_CHANNELS, uidInitiator, 0);
  2498. }
  2499. }
  2500. else
  2501. {
  2502. /*
  2503. * This is not the Top Provider. That means this is someone elses
  2504. * problem. Issue the request upward toward the Top Provider.
  2505. */
  2506. TRACE_OUT(("Domain::ChannelConveneRequest: forwarding convene request to Top Provider"));
  2507. m_pConnToTopProvider->ChannelConveneRequest(uidInitiator);
  2508. }
  2509. }
  2510. else
  2511. {
  2512. /*
  2513. * There is no such user in the sub-tree from which this request
  2514. * originated. Ignore the request.
  2515. */
  2516. ERROR_OUT(("Domain::ChannelConveneRequest: invalid originator=0x%p", pOrigAtt));
  2517. }
  2518. }
  2519. /*
  2520. * Void ChannelConveneConfirm ()
  2521. *
  2522. * Public
  2523. *
  2524. * Functional Description:
  2525. * This MCS command is initially sent by the Top Provider in response to
  2526. * a previously received ChannelConveneRequest. This command contains the
  2527. * results of the request.
  2528. */
  2529. Void Domain::ChannelConveneConfirm (
  2530. PConnection pOrigConn,
  2531. Result result,
  2532. UserID uidInitiator,
  2533. ChannelID channel_id)
  2534. {
  2535. PChannel channel;
  2536. /*
  2537. * Verify that the confirm came from the Top Provider.
  2538. */
  2539. if (pOrigConn == m_pConnToTopProvider)
  2540. {
  2541. /*
  2542. * Make sure that the requesting user is still somewhere in the
  2543. * sub-tree of this provider.
  2544. */
  2545. if (ValidateUserID (uidInitiator, NULL) )
  2546. {
  2547. /*
  2548. * Found out which downward attachment leads to the requesting
  2549. * user.
  2550. */
  2551. if (NULL != (channel = m_ChannelList2.Find(uidInitiator)))
  2552. {
  2553. CAttachment *pAtt = channel->GetAttachment();
  2554. ASSERT(pAtt);
  2555. /*
  2556. * Was the result successful. If is was, then the local provider
  2557. * needs to create the new private channel in the local information
  2558. * base.
  2559. */
  2560. if (result == RESULT_SUCCESSFUL)
  2561. {
  2562. /*
  2563. * See if the named channel already exists in the channel list.
  2564. * Note that it is an error to receive a channel convene
  2565. * confirm for a channel that already exists. This would
  2566. * indicate a logic error somewhere in the domain hierarchy
  2567. * above this provider.
  2568. */
  2569. if (! m_ChannelList2.Find(channel_id))
  2570. {
  2571. /*
  2572. * The new private channel has to be created.
  2573. */
  2574. DBG_SAVE_FILE_LINE
  2575. channel = new PrivateChannel(channel_id, uidInitiator, this, m_pConnToTopProvider,
  2576. &m_ChannelList2, &m_AttachmentList);
  2577. if (channel != NULL)
  2578. {
  2579. /*
  2580. * Add the newly created channel to the channel list.
  2581. * Let the Channel object handle the convene confirm.
  2582. */
  2583. TRACE_OUT(("Domain::ChannelConveneConfirm: adding channel ID = %04X", (UINT) channel_id));
  2584. if(m_ChannelList2.Insert(channel_id, channel))
  2585. {
  2586. Number_Of_Channels++;
  2587. }
  2588. else
  2589. {
  2590. delete channel;
  2591. }
  2592. }
  2593. else
  2594. {
  2595. /*
  2596. * The allocation of the Channel object failed. It
  2597. * is therefore necessary for this provider to cause
  2598. * the channel to be deleted from the domain. It
  2599. * does this by issuing a channel disband request to
  2600. * the Top Provider, and an unsuccessful channel
  2601. * convene confirm to the originating user.
  2602. */
  2603. ERROR_OUT(("Domain::ChannelConveneConfirm: channel allocation failed"));
  2604. m_pConnToTopProvider->ChannelDisbandRequest(uidInitiator, channel_id);
  2605. pAtt->ChannelConveneConfirm(RESULT_UNSPECIFIED_FAILURE, uidInitiator, 0);
  2606. }
  2607. }
  2608. else
  2609. {
  2610. /*
  2611. * A Channel object already exists for the named channel.
  2612. * This is an error, so report the problem, and ignore
  2613. * the confirm.
  2614. */
  2615. ERROR_OUT(("Domain::ChannelConveneConfirm: channel already exists in channel list"));
  2616. }
  2617. }
  2618. else
  2619. {
  2620. /*
  2621. * The result was not successful, so this provider does not
  2622. * have to worry about creating the channel. It merely
  2623. * forwards the join confirm to the originating user.
  2624. */
  2625. TRACE_OUT(("Domain::ChannelConveneConfirm: forwarding ChannelConveneConfirm to user"));
  2626. pAtt->ChannelConveneConfirm(result, uidInitiator, channel_id);
  2627. }
  2628. }
  2629. else
  2630. {
  2631. ERROR_OUT(("Domain::ChannelConveneConfirm: cannot find the channel"));
  2632. }
  2633. }
  2634. else
  2635. {
  2636. /*
  2637. * The named initiator does not exist in the sub-tree of this
  2638. * provider. This could happen if the user is detached before
  2639. * the confirm returns. Note that since a DetachUserIndication
  2640. * will automatically be issued upward for the lost channel
  2641. * manager, it is unnecessary for this provider to take any
  2642. * special action to eliminate the unowned private channel.
  2643. */
  2644. ERROR_OUT(("Domain::ChannelConveneConfirm: initiator not found"));
  2645. }
  2646. }
  2647. else
  2648. {
  2649. /*
  2650. * This confirm was received from someone besides the Top Provider.
  2651. * Ignore the indication.
  2652. */
  2653. ERROR_OUT(("Domain::ChannelConveneConfirm: invalid originator=0x%p", pOrigConn));
  2654. }
  2655. }
  2656. /*
  2657. * Void ChannelDisbandRequest ()
  2658. *
  2659. * Public
  2660. *
  2661. * Functional Description:
  2662. * This MCS command is initially sent by a user that wishes to disband a
  2663. * private channel that it previously created. If the channel is in the
  2664. * local information base, the request is sent to it. Otherwise, the
  2665. * request is ignored.
  2666. */
  2667. Void Domain::ChannelDisbandRequest (
  2668. CAttachment *pOrigAtt,
  2669. UserID uidInitiator,
  2670. ChannelID channel_id)
  2671. {
  2672. PChannel channel;
  2673. /*
  2674. * Make sure the requesting user really exists in the sub-tree from which
  2675. * this request originated.
  2676. */
  2677. if (ValidateUserID(uidInitiator, pOrigAtt))
  2678. {
  2679. /*
  2680. * Check to see if the specified channel exists in the Channel List.
  2681. */
  2682. if (NULL != (channel = m_ChannelList2.Find(channel_id)))
  2683. {
  2684. /*
  2685. * Send the disband request to the channel object to handle it.
  2686. * Then ask the channel object if this request has resulted in a
  2687. * need for the channel to be deleted. This will occur when the
  2688. * disband request is handled at the Top Provider.
  2689. */
  2690. if (channel->GetChannelType() == PRIVATE_CHANNEL)
  2691. {
  2692. PrivateChannel *pPrivChnl = (PrivateChannel *) channel;
  2693. TRACE_OUT(("Domain::ChannelDisbandRequest: sending disband request to channel object"));
  2694. pPrivChnl->ChannelDisbandRequest(pOrigAtt, uidInitiator, channel_id);
  2695. }
  2696. else
  2697. {
  2698. ERROR_OUT(("Domain::ChannelDisbandRequest: it should be private chanel"));
  2699. }
  2700. if (channel->IsValid () == FALSE)
  2701. DeleteChannel (channel_id);
  2702. }
  2703. else
  2704. {
  2705. /*
  2706. * The channel does not exist in the information base. That means
  2707. * that this request is invalid, and should be ignored.
  2708. */
  2709. ERROR_OUT(("Domain::ChannelDisbandRequest: channel does not exist"));
  2710. }
  2711. }
  2712. else
  2713. {
  2714. /*
  2715. * There is no such user in the sub-tree from which this request
  2716. * originated. Ignore the request.
  2717. */
  2718. ERROR_OUT(("Domain::ChannelDisbandRequest: invalid originator=0x%p", pOrigAtt));
  2719. }
  2720. }
  2721. /*
  2722. * Void ChannelDisbandIndication ()
  2723. *
  2724. * Public
  2725. *
  2726. * Functional Description:
  2727. * This MCS command is initially sent by the Top Provider when it decides
  2728. * to delete a private channel from the domain. It travels downward to
  2729. * all attachments and connections that contain an admitted user or the
  2730. * channel manager in their sub-tree.
  2731. */
  2732. Void Domain::ChannelDisbandIndication (
  2733. PConnection pOrigConn,
  2734. ChannelID channel_id)
  2735. {
  2736. PChannel channel;
  2737. /*
  2738. * Verify that the indication came from the Top Provider.
  2739. */
  2740. if (pOrigConn == m_pConnToTopProvider)
  2741. {
  2742. /*
  2743. * Check to see if the specified channel exists in the Channel List.
  2744. */
  2745. if (NULL != (channel = m_ChannelList2.Find(channel_id)))
  2746. {
  2747. /*
  2748. * Send the disband indication to the channel object to handle it.
  2749. * Then delete the object from the local information base, as it is
  2750. * no longer needed.
  2751. */
  2752. if (channel->GetChannelType() == PRIVATE_CHANNEL)
  2753. {
  2754. PrivateChannel *pPrivChnl = (PrivateChannel *) channel;
  2755. TRACE_OUT(("Domain::ChannelDisbandIndication: sending disband indication to channel object"));
  2756. pPrivChnl->ChannelDisbandIndication(channel_id);
  2757. }
  2758. else
  2759. {
  2760. ERROR_OUT(("Domain::ChannelDisbandIndication: it should be private chanel"));
  2761. }
  2762. if (channel->IsValid () == FALSE)
  2763. DeleteChannel (channel_id);
  2764. }
  2765. else
  2766. {
  2767. /*
  2768. * The channel does not exist in the information base. That means
  2769. * that this indication is invalid, and should be ignored.
  2770. */
  2771. ERROR_OUT(("Domain::ChannelDisbandIndication: channel does not exist"));
  2772. }
  2773. }
  2774. else
  2775. {
  2776. /*
  2777. * This indication was received from someone besides the Top Provider.
  2778. * Ignore the indication.
  2779. */
  2780. ERROR_OUT(("Domain::ChannelDisbandIndication: invalid originator=0x%p", pOrigConn));
  2781. }
  2782. }
  2783. /*
  2784. * Void ChannelAdmitRequest ()
  2785. *
  2786. * Public
  2787. *
  2788. * Functional Description:
  2789. * This MCS command is initially sent by the manager of a private channel
  2790. * when it wishes to expand the authorized user list of that channel. If
  2791. * the channel is in the local information base, the request is sent to it.
  2792. * Otherwise, the request is ignored.
  2793. */
  2794. Void Domain::ChannelAdmitRequest (
  2795. CAttachment *pOrigAtt,
  2796. UserID uidInitiator,
  2797. ChannelID channel_id,
  2798. CUidList *user_id_list)
  2799. {
  2800. PChannel channel;
  2801. /*
  2802. * Make sure the requesting user really exists in the sub-tree from which
  2803. * this request originated.
  2804. */
  2805. if (ValidateUserID(uidInitiator, pOrigAtt))
  2806. {
  2807. /*
  2808. * Check to see if the specified channel exists in the Channel List.
  2809. */
  2810. if (NULL != (channel = m_ChannelList2.Find(channel_id)))
  2811. {
  2812. if (channel->GetChannelType() == PRIVATE_CHANNEL)
  2813. {
  2814. PrivateChannel *pPrivChnl = (PrivateChannel *) channel;
  2815. /*
  2816. * Send the admit request to the channel object to handle it.
  2817. */
  2818. TRACE_OUT(("Domain::ChannelAdmitRequest: sending admit request to channel object"));
  2819. pPrivChnl->ChannelAdmitRequest(pOrigAtt, uidInitiator, channel_id, user_id_list);
  2820. }
  2821. else
  2822. {
  2823. ERROR_OUT(("Domain::ChannelAdmitRequest: it should be private chanel"));
  2824. }
  2825. }
  2826. else
  2827. {
  2828. /*
  2829. * The channel does not exist in the information base. That means
  2830. * that this request is invalid, and should be ignored.
  2831. */
  2832. ERROR_OUT(("Domain::ChannelAdmitRequest: channel does not exist"));
  2833. }
  2834. }
  2835. else
  2836. {
  2837. /*
  2838. * There is no such user in the sub-tree from which this request
  2839. * originated. Ignore the request.
  2840. */
  2841. ERROR_OUT(("Domain::ChannelAdmitRequest: invalid originator=0x%p", pOrigAtt));
  2842. }
  2843. }
  2844. /*
  2845. * Void ChannelAdmitIndication ()
  2846. *
  2847. * Public
  2848. *
  2849. * Functional Description:
  2850. * This MCS command is initially sent by the Top Provider when it receives
  2851. * a channel admit indication from the manager of a private channel. This
  2852. * indication is broadcast downward to all providers that contain an
  2853. * admitted user somewhere in their sub-tree. A side-effect of this
  2854. * indication is that a private channel will be created in the information
  2855. * base if one does not already exist.
  2856. */
  2857. Void Domain::ChannelAdmitIndication (
  2858. PConnection pOrigConn,
  2859. UserID uidInitiator,
  2860. ChannelID channel_id,
  2861. CUidList *user_id_list)
  2862. {
  2863. PChannel channel;
  2864. /*
  2865. * Verify that the indication came from the Top Provider.
  2866. */
  2867. if (pOrigConn == m_pConnToTopProvider)
  2868. {
  2869. /*
  2870. * Check to see if the specified channel exists in the Channel List.
  2871. */
  2872. if (NULL != (channel = m_ChannelList2.Find(channel_id)))
  2873. {
  2874. if (channel->GetChannelType() == PRIVATE_CHANNEL)
  2875. {
  2876. PrivateChannel *pPrivChnl = (PrivateChannel *) channel;
  2877. /*
  2878. * Send the admit indication to the channel object to handle it.
  2879. */
  2880. TRACE_OUT(("Domain::ChannelAdmitIndication: sending admit indication to channel object"));
  2881. pPrivChnl->ChannelAdmitIndication(pOrigConn, uidInitiator, channel_id, user_id_list);
  2882. }
  2883. else
  2884. {
  2885. ERROR_OUT(("Domain::ChannelAdmitIndication: it should be private chanel"));
  2886. }
  2887. }
  2888. else
  2889. {
  2890. /*
  2891. * Since the private channel does not exist in the information
  2892. * base, it will be necessary to create one. After it is created,
  2893. * it can handle the channel admit indication.
  2894. */
  2895. DBG_SAVE_FILE_LINE
  2896. channel = new PrivateChannel(channel_id, uidInitiator, this, m_pConnToTopProvider,
  2897. &m_ChannelList2, &m_AttachmentList);
  2898. if (channel != NULL)
  2899. {
  2900. PrivateChannel *pPrivChnl = (PrivateChannel *) channel;
  2901. /*
  2902. * Put the newly created private channel into the domain
  2903. * information base.
  2904. */
  2905. TRACE_OUT(("Domain::ChannelAdmitIndication: adding channel ID = %04X", (UINT) channel_id));
  2906. if(m_ChannelList2.Insert(channel_id, channel))
  2907. {
  2908. Number_Of_Channels++;
  2909. /*
  2910. * Send the admit indication to the new channel object to
  2911. * handle it.
  2912. */
  2913. pPrivChnl->ChannelAdmitIndication(pOrigConn, uidInitiator, channel_id, user_id_list);
  2914. }
  2915. else
  2916. {
  2917. delete channel;
  2918. }
  2919. }
  2920. else
  2921. {
  2922. /*
  2923. * We have been told by the Top Provider to create a private
  2924. * channel, but we can't due to a resource shortage. We also
  2925. * can't purge the channel from the domain since the channel
  2926. * manager does not exist in the sub-tree of this provider.
  2927. * We are therefore out of sync with the Top Provider, and
  2928. * there is nothing we can do about it (except for possibly
  2929. * disconnecting from the Top Provider and purging the entire
  2930. * domain from this node downward).
  2931. */
  2932. ERROR_OUT(("Domain::ChannelAdmitIndication: channel allocation failure"));
  2933. }
  2934. }
  2935. }
  2936. else
  2937. {
  2938. /*
  2939. * This indication was received from someone besides the Top Provider.
  2940. * Ignore the indication.
  2941. */
  2942. WARNING_OUT(("Domain::ChannelAdmitIndication: invalid originator=0x%p", pOrigConn));
  2943. }
  2944. }
  2945. /*
  2946. * Void ChannelExpelRequest ()
  2947. *
  2948. * Public
  2949. *
  2950. * Functional Description:
  2951. * This MCS command is initially sent by the manager of a private channel
  2952. * when it wishes to shrink the authorized user list of that channel. If
  2953. * the channel is in the local information base, the request is sent to it.
  2954. * Otherwise, the request is ignored.
  2955. */
  2956. Void Domain::ChannelExpelRequest (
  2957. CAttachment *pOrigAtt,
  2958. UserID uidInitiator,
  2959. ChannelID channel_id,
  2960. CUidList *user_id_list)
  2961. {
  2962. PChannel channel;
  2963. /*
  2964. * Make sure the requesting user really exists in the sub-tree from which
  2965. * this request originated.
  2966. */
  2967. if (ValidateUserID(uidInitiator, pOrigAtt))
  2968. {
  2969. /*
  2970. * Check to see if the specified channel exists in the Channel List.
  2971. */
  2972. if (NULL != (channel = m_ChannelList2.Find(channel_id)))
  2973. {
  2974. if (channel->GetChannelType() == PRIVATE_CHANNEL)
  2975. {
  2976. PrivateChannel *pPrivChnl = (PrivateChannel *) channel;
  2977. /*
  2978. * Send the admit request to the channel object to handle it.
  2979. */
  2980. TRACE_OUT(("Domain::ChannelExpelRequest: "
  2981. "sending expel request to channel object"));
  2982. pPrivChnl->ChannelExpelRequest(pOrigAtt, uidInitiator, channel_id, user_id_list);
  2983. }
  2984. else
  2985. {
  2986. ERROR_OUT(("Domain::ChannelExpelRequest: it should be private chanel"));
  2987. }
  2988. }
  2989. else
  2990. {
  2991. /*
  2992. * The channel does not exist in the information base. That means
  2993. * that this request is invalid, and should be ignored.
  2994. */
  2995. WARNING_OUT(("Domain::ChannelExpelRequest: channel does not exist"));
  2996. }
  2997. }
  2998. else
  2999. {
  3000. /*
  3001. * There is no such user in the sub-tree from which this request
  3002. * originated. Ignore the request.
  3003. */
  3004. WARNING_OUT(("Domain::ChannelExpelRequest: invalid originator=0x%p", pOrigAtt));
  3005. }
  3006. }
  3007. /*
  3008. * Void ChannelExpelIndication ()
  3009. *
  3010. * Public
  3011. *
  3012. * Functional Description:
  3013. * This MCS command is initially sent by the Top Provider when it receives
  3014. * a request from the manager of a private channel to reduce the
  3015. * authorized user list. It travels downward to all attachments and
  3016. * connections that contain an admitted user or the channel manager in
  3017. * their sub-tree.
  3018. */
  3019. Void Domain::ChannelExpelIndication (
  3020. PConnection pOrigConn,
  3021. ChannelID channel_id,
  3022. CUidList *user_id_list)
  3023. {
  3024. PChannel channel;
  3025. /*
  3026. * Verify that the indication came from the Top Provider.
  3027. */
  3028. if (pOrigConn == m_pConnToTopProvider)
  3029. {
  3030. /*
  3031. * Check to see if the specified channel exists in the Channel List.
  3032. */
  3033. if (NULL != (channel = m_ChannelList2.Find(channel_id)))
  3034. {
  3035. if (channel->GetChannelType() == PRIVATE_CHANNEL)
  3036. {
  3037. PrivateChannel *pPrivChnl = (PrivateChannel *) channel;
  3038. /*
  3039. * Send the expel indication to the channel object to handle it.
  3040. * Then check to see if the channel is still valid (delete it
  3041. * if not). This would occur if the expel results in an empty
  3042. * admitted user list, and the channel manager is also not in the
  3043. * sub-tree of this provider.
  3044. */
  3045. TRACE_OUT(("Domain::ChannelExpelIndication: sending expel indication to channel object"));
  3046. pPrivChnl->ChannelExpelIndication(pOrigConn, channel_id, user_id_list);
  3047. }
  3048. else
  3049. {
  3050. ERROR_OUT(("Domain::ChannelExpelIndication: it should be private chanel"));
  3051. }
  3052. if (channel->IsValid () == FALSE)
  3053. DeleteChannel (channel_id);
  3054. }
  3055. else
  3056. {
  3057. /*
  3058. * The channel does not exist in the information base. That means
  3059. * that this indication is invalid, and should be ignored.
  3060. */
  3061. ERROR_OUT(("Domain::ChannelExpelIndication: channel does not exist"));
  3062. }
  3063. }
  3064. else
  3065. {
  3066. /*
  3067. * This indication was received from someone besides the Top Provider.
  3068. * Ignore the indication.
  3069. */
  3070. ERROR_OUT(("Domain::ChannelExpelIndication: invalid originator=0x%p", pOrigConn));
  3071. }
  3072. }
  3073. /*
  3074. * Void SendDataRequest ()
  3075. *
  3076. * Public
  3077. *
  3078. * Functional Description:
  3079. * This MCS command is initially issued by a user attachment that wishes
  3080. * to send data on a particular channel in this domain. The request will
  3081. * flow upward all the way to the Top Provider. It will also cause
  3082. * send data indications to be sent downward to all other attachments
  3083. * that are joined to the channel.
  3084. */
  3085. Void Domain::SendDataRequest (
  3086. CAttachment *pOrigAtt,
  3087. UINT type,
  3088. PDataPacket data_packet)
  3089. {
  3090. PChannel channel;
  3091. /*
  3092. * Make sure the requesting user really exists in the sub-tree from which
  3093. * this request originated.
  3094. */
  3095. if (ValidateUserID(data_packet->GetInitiator(), pOrigAtt))
  3096. {
  3097. /*
  3098. * See if the channel exists in the local information base. If it does
  3099. * then let the Channel object handle the routing of the data. If
  3100. * it does not exist, then simply forward the request upward to be
  3101. * handled by the next higher provider (unless this is the Top
  3102. * Provider).
  3103. */
  3104. if (NULL != (channel = m_ChannelList2.Find(data_packet->GetChannelID())))
  3105. channel->SendDataRequest(pOrigAtt, type, data_packet);
  3106. else if (! IsTopProvider())
  3107. m_pConnToTopProvider->SendDataRequest(data_packet);
  3108. }
  3109. else
  3110. {
  3111. /*
  3112. * There is no such user in the sub-tree from which this request
  3113. * originated. Ignore the request.
  3114. */
  3115. WARNING_OUT (("Domain::SendDataRequest: invalid originator=0x%p, uidInitiator=%d", pOrigAtt, data_packet->GetInitiator()));
  3116. }
  3117. }
  3118. /*
  3119. * Void SendDataIndication ()
  3120. *
  3121. * Public
  3122. *
  3123. * Functional Description:
  3124. * This MCS command is issued by all providers that receive a send data
  3125. * request on a channel to which one of their attachments is joined. It
  3126. * delivers data in a non-uniform fashion to all users joined to the
  3127. * named channel.
  3128. */
  3129. Void Domain::SendDataIndication (
  3130. PConnection pOrigConn,
  3131. UINT type,
  3132. PDataPacket data_packet)
  3133. {
  3134. PChannel channel;
  3135. /*
  3136. * Verify that the indication came from the Top Provider.
  3137. */
  3138. if (pOrigConn == m_pConnToTopProvider)
  3139. {
  3140. /*
  3141. * See if the channel exists in the local information base. If it does
  3142. * then let the Channel object handle the routing of the data. If
  3143. * it does not exist, then ignore the request.
  3144. */
  3145. if (NULL != (channel = m_ChannelList2.Find(data_packet->GetChannelID())))
  3146. channel->SendDataIndication(pOrigConn, type, data_packet);
  3147. }
  3148. else
  3149. {
  3150. /*
  3151. * This indication was received from someone besides the Top Provider.
  3152. * Ignore the indication.
  3153. */
  3154. WARNING_OUT (("Domain::SendDataIndication: invalid originator=0x%p, initiator=%d", pOrigConn, data_packet->GetInitiator()));
  3155. }
  3156. }
  3157. /*
  3158. * Void TokenGrabRequest ()
  3159. *
  3160. * Public
  3161. *
  3162. * Functional Description:
  3163. * This MCS command is initially sent by a user attachment that wishes
  3164. * to grab a token. It flows upward to the Top Provider, who attempts
  3165. * to satisfy the request.
  3166. */
  3167. Void Domain::TokenGrabRequest (
  3168. CAttachment *pOrigAtt,
  3169. UserID uidInitiator,
  3170. TokenID token_id)
  3171. {
  3172. PToken token;
  3173. /*
  3174. * Make sure the requesting user really exists in the sub-tree from which
  3175. * this request originated.
  3176. */
  3177. if (ValidateUserID(uidInitiator, pOrigAtt))
  3178. {
  3179. /*
  3180. * If the token already exists in the token list, then let the Token
  3181. * object deal with the request.
  3182. */
  3183. if (NULL != (token = m_TokenList2.Find(token_id)))
  3184. {
  3185. TRACE_OUT(("Domain::TokenGrabRequest: sending grab request to token object"));
  3186. token->TokenGrabRequest(pOrigAtt, uidInitiator, token_id);
  3187. }
  3188. else
  3189. {
  3190. /*
  3191. * The token does not exist yet. Check to see if this is the Top
  3192. * Provider. If it is, then the request can be processed locally.
  3193. * Otherwise, forward the request upward.
  3194. */
  3195. if (IsTopProvider())
  3196. {
  3197. /*
  3198. * Check to see if the arbitrated domain parameters will allow
  3199. * the addition of another token.
  3200. */
  3201. if (Number_Of_Tokens < Domain_Parameters.max_token_ids)
  3202. {
  3203. /*
  3204. * Try to create a new Token object.
  3205. */
  3206. DBG_SAVE_FILE_LINE
  3207. token = new Token(token_id, this, m_pConnToTopProvider, &m_ChannelList2, &m_AttachmentList);
  3208. if (token != NULL)
  3209. {
  3210. /*
  3211. * Put the newly created Token object into the token
  3212. * list. Then pass the grab request to it.
  3213. */
  3214. TRACE_OUT(("Domain::TokenGrabRequest: adding token ID = %04X", (UINT) token_id));
  3215. m_TokenList2.Append(token_id, token);
  3216. Number_Of_Tokens++;
  3217. token->TokenGrabRequest(pOrigAtt, uidInitiator, token_id);
  3218. }
  3219. else
  3220. {
  3221. /*
  3222. * The allocation of the Token object failed. It is
  3223. * therefore necessary to fail the request.
  3224. */
  3225. ERROR_OUT(("Domain::TokenGrabRequest: token allocation failed"));
  3226. pOrigAtt->TokenGrabConfirm(RESULT_UNSPECIFIED_FAILURE, uidInitiator, token_id, TOKEN_NOT_IN_USE);
  3227. }
  3228. }
  3229. else
  3230. {
  3231. /*
  3232. * The arbitrated domain parameters will not allow the
  3233. * creation of another token in this domain. So fail
  3234. * the request.
  3235. */
  3236. ERROR_OUT(("Domain::TokenGrabRequest: grab denied - too many tokens"));
  3237. pOrigAtt->TokenGrabConfirm(RESULT_TOO_MANY_TOKENS, uidInitiator, token_id, TOKEN_NOT_IN_USE);
  3238. }
  3239. }
  3240. else
  3241. {
  3242. /*
  3243. * This is not the Top Provider. Forward the request upward.
  3244. */
  3245. TRACE_OUT(("Domain::TokenGrabRequest: forwarding grab request to Top Provider"));
  3246. m_pConnToTopProvider->TokenGrabRequest(uidInitiator, token_id);
  3247. }
  3248. }
  3249. }
  3250. else
  3251. {
  3252. /*
  3253. * There is no such user in the sub-tree from which this request
  3254. * originated. Ignore the request.
  3255. */
  3256. ERROR_OUT(("Domain::TokenGrabRequest: invalid originator=0x%p", pOrigAtt));
  3257. }
  3258. }
  3259. /*
  3260. * Void TokenGrabConfirm ()
  3261. *
  3262. * Public
  3263. *
  3264. * Functional Description:
  3265. * This MCS command is initially sent by the Top Provider upon receipt of
  3266. * a grab request. It is sent back to the initiating user, containing
  3267. * the result of the request.
  3268. */
  3269. Void Domain::TokenGrabConfirm (
  3270. PConnection pOrigConn,
  3271. Result result,
  3272. UserID uidInitiator,
  3273. TokenID token_id,
  3274. TokenStatus token_status)
  3275. {
  3276. PToken token;
  3277. /*
  3278. * Verify that the confirm came from the Top Provider.
  3279. */
  3280. if (pOrigConn == m_pConnToTopProvider)
  3281. {
  3282. /*
  3283. * See if the token already exists in the local information base. If
  3284. * so, let it handle this.
  3285. */
  3286. if (NULL != (token = m_TokenList2.Find(token_id)))
  3287. {
  3288. TRACE_OUT(("Domain::TokenGrabConfirm: sending grab confirm to token object"));
  3289. token->TokenGrabConfirm(result, uidInitiator, token_id, token_status);
  3290. }
  3291. else
  3292. {
  3293. PChannel channel;
  3294. /*
  3295. * Make sure that the requesting user is still somewhere in the
  3296. * sub-tree of this provider.
  3297. */
  3298. if (ValidateUserID (uidInitiator, NULL) )
  3299. {
  3300. /*
  3301. * Determine which attachment leads to the initiating user.
  3302. */
  3303. if (NULL != (channel = m_ChannelList2.Find(uidInitiator)))
  3304. {
  3305. CAttachment *pAtt = channel->GetAttachment();
  3306. ASSERT(pAtt);
  3307. /*
  3308. * If the result of the request is successful, then it is
  3309. * necessary to create the token in the local information base.
  3310. */
  3311. if (result == RESULT_SUCCESSFUL)
  3312. {
  3313. /*
  3314. * Create the token.
  3315. */
  3316. DBG_SAVE_FILE_LINE
  3317. token = new Token(token_id, this, m_pConnToTopProvider, &m_ChannelList2, &m_AttachmentList);
  3318. if (token != NULL)
  3319. {
  3320. /*
  3321. * Put the newly created Token object into the token
  3322. * list. Then pass the grab confirm to it.
  3323. */
  3324. TRACE_OUT(("Domain::TokenGrabConfirm: adding token ID = %04X", (UINT) token_id));
  3325. m_TokenList2.Append(token_id, token);
  3326. Number_Of_Tokens++;
  3327. token->TokenGrabConfirm(result, uidInitiator, token_id, token_status);
  3328. }
  3329. else
  3330. {
  3331. /*
  3332. * The creation of the token failed. It is therefore
  3333. * necessary to send a failed confirm to the initiating
  3334. * user, as well as a token release request to the Top
  3335. * Provider.
  3336. */
  3337. ERROR_OUT(("Domain::TokenGrabConfirm: token creation failed"));
  3338. m_pConnToTopProvider->TokenReleaseRequest(uidInitiator, token_id);
  3339. pAtt->TokenGrabConfirm(RESULT_UNSPECIFIED_FAILURE, uidInitiator, token_id, TOKEN_NOT_IN_USE);
  3340. }
  3341. }
  3342. else
  3343. {
  3344. /*
  3345. * The confirm was unsuccessful, so there is no need to
  3346. * create a token in the information base. Just forward
  3347. * the confirm to the initiating user.
  3348. */
  3349. TRACE_OUT(("Domain::TokenGrabConfirm: forwarding failed grab confirm"));
  3350. pAtt->TokenGrabConfirm(result, uidInitiator, token_id, token_status);
  3351. }
  3352. }
  3353. else
  3354. {
  3355. ERROR_OUT(("Domain::TokenGrabConfirm: cannot find channel"));
  3356. }
  3357. }
  3358. else
  3359. {
  3360. /*
  3361. * The named initiator does not exist in the sub-tree of this
  3362. * provider. Ignore the confirm.
  3363. */
  3364. ERROR_OUT(("Domain::TokenGrabConfirm: invalid initiator, uidInitiator=%u", (UINT) uidInitiator));
  3365. }
  3366. }
  3367. }
  3368. else
  3369. {
  3370. /*
  3371. * This confirm was received from someone besides the Top Provider.
  3372. * Ignore the confirm.
  3373. */
  3374. ERROR_OUT(("Domain::TokenGrabConfirm: invalid originator=0x%p", pOrigConn));
  3375. }
  3376. }
  3377. /*
  3378. * Void TokenInhibitRequest ()
  3379. *
  3380. * Public
  3381. *
  3382. * Functional Description:
  3383. * This MCS command is initially sent by a user attachment that wishes
  3384. * to inhibit a token. It flows upward to the Top Provider, who attempts
  3385. * to satisfy the request.
  3386. */
  3387. Void Domain::TokenInhibitRequest (
  3388. CAttachment *pOrigAtt,
  3389. UserID uidInitiator,
  3390. TokenID token_id)
  3391. {
  3392. PToken token;
  3393. /*
  3394. * Make sure the requesting user really exists in the sub-tree from which
  3395. * this request originated.
  3396. */
  3397. if (ValidateUserID(uidInitiator, pOrigAtt))
  3398. {
  3399. /*
  3400. * If the token already exists in the token list, then let the Token
  3401. * object deal with the request.
  3402. */
  3403. if (NULL != (token = m_TokenList2.Find(token_id)))
  3404. {
  3405. TRACE_OUT(("Domain::TokenInhibitRequest: sending inhibit request to token object"));
  3406. token->TokenInhibitRequest(pOrigAtt, uidInitiator, token_id);
  3407. }
  3408. else
  3409. {
  3410. /*
  3411. * The token does not exist yet. Check to see if this is the Top
  3412. * Provider. If it is, then the request can be processed locally.
  3413. * Otherwise, forward the request upward.
  3414. */
  3415. if (IsTopProvider())
  3416. {
  3417. /*
  3418. * Check to see if the arbitrated domain parameters will allow
  3419. * the addition of another token.
  3420. */
  3421. if (Number_Of_Tokens < Domain_Parameters.max_token_ids)
  3422. {
  3423. /*
  3424. * Try to create a new Token object.
  3425. */
  3426. DBG_SAVE_FILE_LINE
  3427. token = new Token(token_id, this, m_pConnToTopProvider, &m_ChannelList2, &m_AttachmentList);
  3428. if (token != NULL)
  3429. {
  3430. /*
  3431. * Put the newly created Token object into the token
  3432. * list. Then pass the inhibit request to it.
  3433. */
  3434. TRACE_OUT(("Domain::TokenInhibitRequest: adding token ID = %04X", (UINT) token_id));
  3435. m_TokenList2.Append(token_id, token);
  3436. Number_Of_Tokens++;
  3437. token->TokenInhibitRequest(pOrigAtt, uidInitiator, token_id);
  3438. }
  3439. else
  3440. {
  3441. /*
  3442. * The allocation of the Token object failed. It is
  3443. * therefore necessary to fail the request.
  3444. */
  3445. ERROR_OUT(("Domain::TokenInhibitRequest: token allocation failed"));
  3446. pOrigAtt->TokenInhibitConfirm(RESULT_UNSPECIFIED_FAILURE, uidInitiator, token_id, TOKEN_NOT_IN_USE);
  3447. }
  3448. }
  3449. else
  3450. {
  3451. /*
  3452. * The arbitrated domain parameters will not allow the
  3453. * creation of another token in this domain. So fail
  3454. * the request.
  3455. */
  3456. ERROR_OUT(("Domain::TokenInhibitRequest: inhibit denied - too many tokens"));
  3457. pOrigAtt->TokenInhibitConfirm(RESULT_TOO_MANY_TOKENS, uidInitiator, token_id, TOKEN_NOT_IN_USE);
  3458. }
  3459. }
  3460. else
  3461. {
  3462. /*
  3463. * This is not the Top Provider. Forward the request upward.
  3464. */
  3465. TRACE_OUT(("Domain::TokenInhibitRequest: forwarding inhibit request to Top Provider"));
  3466. m_pConnToTopProvider->TokenInhibitRequest(uidInitiator, token_id);
  3467. }
  3468. }
  3469. }
  3470. else
  3471. {
  3472. /*
  3473. * There is no such user in the sub-tree from which this request
  3474. * originated. Ignore the request.
  3475. */
  3476. ERROR_OUT(("Domain::TokenInhibitRequest: invalid originator=0x%p", pOrigAtt));
  3477. }
  3478. }
  3479. /*
  3480. * Void TokenInhibitConfirm ()
  3481. *
  3482. * Public
  3483. *
  3484. * Functional Description:
  3485. * This MCS command is initially sent by the Top Provider upon receipt of
  3486. * a inhibit request. It is sent back to the initiating user, containing
  3487. * the result of the request.
  3488. */
  3489. Void Domain::TokenInhibitConfirm (
  3490. PConnection pOrigConn,
  3491. Result result,
  3492. UserID uidInitiator,
  3493. TokenID token_id,
  3494. TokenStatus token_status)
  3495. {
  3496. PToken token;
  3497. /*
  3498. * Verify that the confirm came from the Top Provider.
  3499. */
  3500. if (pOrigConn == m_pConnToTopProvider)
  3501. {
  3502. /*
  3503. * See if the token already exists in the local information base. If
  3504. * so, let it handle this.
  3505. */
  3506. if (NULL != (token = m_TokenList2.Find(token_id)))
  3507. {
  3508. TRACE_OUT(("Domain::TokenInhibitConfirm: sending inhibit confirm to token object"));
  3509. token->TokenInhibitConfirm(result, uidInitiator, token_id, token_status);
  3510. }
  3511. else
  3512. {
  3513. PChannel channel;
  3514. /*
  3515. * Make sure that the requesting user is still somewhere in the
  3516. * sub-tree of this provider.
  3517. */
  3518. if (ValidateUserID (uidInitiator, NULL) )
  3519. {
  3520. /*
  3521. * Determine which attachment leads to the requesting user.
  3522. */
  3523. if (NULL != (channel = m_ChannelList2.Find(uidInitiator)))
  3524. {
  3525. CAttachment *pAtt = channel->GetAttachment();
  3526. ASSERT(pAtt);
  3527. /*
  3528. * If the result of the request is successful, then it is
  3529. * necessary to create the token in the local information base.
  3530. */
  3531. if (result == RESULT_SUCCESSFUL)
  3532. {
  3533. /*
  3534. * Create the token.
  3535. */
  3536. DBG_SAVE_FILE_LINE
  3537. token = new Token(token_id, this, m_pConnToTopProvider, &m_ChannelList2, &m_AttachmentList);
  3538. if (token != NULL)
  3539. {
  3540. /*
  3541. * Put the newly created Token object into the token
  3542. * list. Then pass the inhibit confirm to it.
  3543. */
  3544. TRACE_OUT(("Domain::TokenInhibitConfirm: adding token ID = %04X", (UINT) token_id));
  3545. m_TokenList2.Append(token_id, token);
  3546. Number_Of_Tokens++;
  3547. token->TokenInhibitConfirm(result, uidInitiator, token_id, token_status);
  3548. }
  3549. else
  3550. {
  3551. /*
  3552. * The creation of the token failed. It is therefore
  3553. * necessary to send a failed confirm to the initiating
  3554. * user, as well as a token release request to the Top
  3555. * Provider.
  3556. */
  3557. ERROR_OUT(("Domain::TokenInhibitConfirm: token creation failed"));
  3558. m_pConnToTopProvider->TokenReleaseRequest(uidInitiator, token_id);
  3559. pAtt->TokenInhibitConfirm(RESULT_UNSPECIFIED_FAILURE, uidInitiator, token_id, TOKEN_NOT_IN_USE);
  3560. }
  3561. }
  3562. else
  3563. {
  3564. /*
  3565. * The confirm was unsuccessful, so there is no need to
  3566. * create a token in the information base. Just forward
  3567. * the confirm to the initiating user.
  3568. */
  3569. ERROR_OUT(("Domain::TokenInhibitConfirm: forwarding failed inhibit confirm"));
  3570. pAtt->TokenInhibitConfirm(result, uidInitiator, token_id, token_status);
  3571. }
  3572. }
  3573. else
  3574. {
  3575. ERROR_OUT(("Domain::TokenInhibitConfirm: cannot find channel"));
  3576. }
  3577. }
  3578. else
  3579. {
  3580. /*
  3581. * The named initiator does not exist in the sub-tree of this
  3582. * provider. Ignore the confirm.
  3583. */
  3584. ERROR_OUT(("Domain::TokenInhibitConfirm: initiator not valid, uidInitiator=%u", (UINT) uidInitiator));
  3585. }
  3586. }
  3587. }
  3588. else
  3589. {
  3590. /*
  3591. * This confirm was received from someone besides the Top Provider.
  3592. * Ignore the confirm.
  3593. */
  3594. ERROR_OUT(("Domain::TokenInhibitConfirm: invalid originator=0x%p", pOrigConn));
  3595. }
  3596. }
  3597. /*
  3598. * Void TokenGiveRequest ()
  3599. *
  3600. * Public
  3601. *
  3602. * Functional Description:
  3603. */
  3604. Void Domain::TokenGiveRequest (
  3605. CAttachment *pOrigAtt,
  3606. PTokenGiveRecord pTokenGiveRec)
  3607. {
  3608. PToken token;
  3609. /*
  3610. * Make sure the requesting user really exists in the sub-tree from which
  3611. * this request originated.
  3612. */
  3613. if (ValidateUserID(pTokenGiveRec->uidInitiator, pOrigAtt))
  3614. {
  3615. /*
  3616. * If the token already exists in the token list, then let the
  3617. * Token object deal with the request.
  3618. */
  3619. if (NULL != (token = m_TokenList2.Find(pTokenGiveRec->token_id)))
  3620. {
  3621. TRACE_OUT(("Domain::TokenGiveRequest: sending give request to token object"));
  3622. token->TokenGiveRequest(pOrigAtt, pTokenGiveRec);
  3623. }
  3624. else
  3625. {
  3626. /*
  3627. * Check to see if this is the Top Provider. If it is, then the
  3628. * request can be processed locally. Otherwise, forward the
  3629. * request upward.
  3630. */
  3631. if (IsTopProvider())
  3632. {
  3633. /*
  3634. * The token does not exist in this domain. Report this and
  3635. * send the appropriate give confirm back to the originating
  3636. * user.
  3637. */
  3638. ERROR_OUT(("Domain::TokenGiveRequest: token does not exist"));
  3639. pOrigAtt->TokenGiveConfirm(RESULT_TOKEN_NOT_POSSESSED,
  3640. pTokenGiveRec->uidInitiator, pTokenGiveRec->token_id, TOKEN_NOT_IN_USE);
  3641. }
  3642. else
  3643. {
  3644. /*
  3645. * This is not the Top Provider. Forward the request upward.
  3646. */
  3647. TRACE_OUT(("Domain::TokenGiveRequest: forwarding give request to Top Provider"));
  3648. m_pConnToTopProvider->TokenGiveRequest(pTokenGiveRec);
  3649. }
  3650. }
  3651. }
  3652. else
  3653. {
  3654. /*
  3655. * There is no such user in the sub-tree from which this request
  3656. * originated. Ignore the request.
  3657. */
  3658. ERROR_OUT(("Domain::TokenGiveRequest: invalid originator=0x%p", pOrigAtt));
  3659. }
  3660. }
  3661. /*
  3662. * Void TokenGiveIndication ()
  3663. *
  3664. * Public
  3665. *
  3666. * Functional Description:
  3667. */
  3668. Void Domain::TokenGiveIndication (
  3669. PConnection pOrigConn,
  3670. PTokenGiveRecord pTokenGiveRec)
  3671. {
  3672. PToken token;
  3673. TokenID token_id = pTokenGiveRec->token_id;
  3674. /*
  3675. * Verify that the indication came from the Top Provider.
  3676. */
  3677. if (pOrigConn == m_pConnToTopProvider)
  3678. {
  3679. /*
  3680. * See if the token already exists in the local information base. If
  3681. * so, let it handle this.
  3682. */
  3683. if (NULL != (token = m_TokenList2.Find(token_id)))
  3684. {
  3685. TRACE_OUT(("Domain::TokenGiveIndication: sending give indication to token object"));
  3686. token->TokenGiveIndication(pTokenGiveRec);
  3687. }
  3688. else
  3689. {
  3690. /*
  3691. * Make sure that the specified receiver is somewhere in the
  3692. * sub-tree of this provider.
  3693. */
  3694. if (ValidateUserID (pTokenGiveRec->receiver_id, NULL) )
  3695. {
  3696. /*
  3697. * Create the token.
  3698. */
  3699. DBG_SAVE_FILE_LINE
  3700. token = new Token(token_id, this, m_pConnToTopProvider, &m_ChannelList2, &m_AttachmentList);
  3701. if (token != NULL)
  3702. {
  3703. /*
  3704. * Put the newly created Token object into the token
  3705. * list. Then pass the give indication to it.
  3706. */
  3707. TRACE_OUT(("Domain::TokenGiveIndication: adding token ID = %04X", (UINT) token_id));
  3708. if(m_TokenList2.Append(token_id, token))
  3709. {
  3710. Number_Of_Tokens++;
  3711. token->TokenGiveIndication(pTokenGiveRec);
  3712. }
  3713. else
  3714. {
  3715. delete token;
  3716. }
  3717. }
  3718. else
  3719. {
  3720. /*
  3721. * The creation of the token failed. It is therefore
  3722. * necessary to send a failed give response to the Top
  3723. * Provider.
  3724. */
  3725. ERROR_OUT(("Domain::TokenGiveIndication: token creation failed"));
  3726. m_pConnToTopProvider->TokenGiveResponse(RESULT_UNSPECIFIED_FAILURE,
  3727. pTokenGiveRec->uidInitiator, token_id);
  3728. }
  3729. }
  3730. else
  3731. {
  3732. /*
  3733. * The specified receiver does not exist in the sub-tree of
  3734. * this provider. It is not necessary for this provider to
  3735. * take special action, since the detach user indication for
  3736. * the receiver will clean up.
  3737. */
  3738. ERROR_OUT(("Domain::TokenGiveIndication: receiver not valid"));
  3739. }
  3740. }
  3741. }
  3742. else
  3743. {
  3744. /*
  3745. * This indication was received from someone besides the Top Provider.
  3746. * Ignore the indication.
  3747. */
  3748. ERROR_OUT(("Domain::TokenGiveIndication: invalid originator=0x%p", pOrigConn));
  3749. }
  3750. }
  3751. /*
  3752. * Void TokenGiveResponse ()
  3753. *
  3754. * Public
  3755. *
  3756. * Functional Description:
  3757. */
  3758. Void Domain::TokenGiveResponse (
  3759. CAttachment *pOrigAtt,
  3760. Result result,
  3761. UserID receiver_id,
  3762. TokenID token_id)
  3763. {
  3764. PToken token;
  3765. /*
  3766. * Make sure the requesting user really exists in the sub-tree from which
  3767. * this response originated.
  3768. */
  3769. if (ValidateUserID(receiver_id, pOrigAtt))
  3770. {
  3771. /*
  3772. * If the token already exists in the token list, then let the
  3773. * Token object deal with the response.
  3774. */
  3775. if (NULL != (token = m_TokenList2.Find(token_id)))
  3776. {
  3777. /*
  3778. * Send the give response to the token object. Then check to
  3779. * see if it is still valid (delete it if not).
  3780. */
  3781. TRACE_OUT(("Domain::TokenGiveResponse: sending give response to token object"));
  3782. token->TokenGiveResponse(result, receiver_id, token_id);
  3783. if (token->IsValid () == FALSE)
  3784. DeleteToken (token_id);
  3785. }
  3786. else
  3787. {
  3788. /*
  3789. * The token is not in the information base, which means that it
  3790. * cannot be being given to the initiator of this response.
  3791. * Ignore the response.
  3792. */
  3793. ERROR_OUT(("Domain::TokenGiveResponse: no such token"));
  3794. }
  3795. }
  3796. else
  3797. {
  3798. /*
  3799. * There is no such user in the sub-tree from which this response
  3800. * originated. Ignore the response.
  3801. */
  3802. ERROR_OUT(("Domain::TokenGiveResponse: invalid originator=0x%p", pOrigAtt));
  3803. }
  3804. }
  3805. /*
  3806. * Void TokenGiveConfirm ()
  3807. *
  3808. * Public
  3809. *
  3810. * Functional Description:
  3811. */
  3812. Void Domain::TokenGiveConfirm (
  3813. PConnection pOrigConn,
  3814. Result result,
  3815. UserID uidInitiator,
  3816. TokenID token_id,
  3817. TokenStatus token_status)
  3818. {
  3819. PToken token;
  3820. /*
  3821. * Verify that the confirm came from the Top Provider.
  3822. */
  3823. if (pOrigConn == m_pConnToTopProvider)
  3824. {
  3825. /*
  3826. * See if the token already exists in the local information base. If
  3827. * so, let it handle this.
  3828. */
  3829. if (NULL != (token = m_TokenList2.Find(token_id)))
  3830. {
  3831. /*
  3832. * Send the give confirm to the token object. Then check to
  3833. * see if it is still valid (delete it if not).
  3834. */
  3835. TRACE_OUT(("Domain::TokenGiveConfirm: sending give confirm to token object"));
  3836. token->TokenGiveConfirm(result, uidInitiator, token_id, token_status);
  3837. if (token->IsValid () == FALSE)
  3838. DeleteToken (token_id);
  3839. }
  3840. else
  3841. {
  3842. /*
  3843. * Make sure that the requesting user is still somewhere in the
  3844. * sub-tree of this provider.
  3845. */
  3846. if (ValidateUserID (uidInitiator, NULL) )
  3847. {
  3848. PChannel channel;
  3849. /*
  3850. * Determine which attachment leads to the requesting user.
  3851. * Then forward the confirm in that direction.
  3852. */
  3853. TRACE_OUT(("Domain::TokenGiveConfirm: forwarding give confirm"));
  3854. if (NULL != (channel = m_ChannelList2.Find(uidInitiator)))
  3855. {
  3856. CAttachment *pAtt = channel->GetAttachment();
  3857. if (pAtt)
  3858. {
  3859. pAtt->TokenGiveConfirm(result, uidInitiator, token_id, token_status);
  3860. }
  3861. else
  3862. {
  3863. ERROR_OUT(("Domain::TokenGiveConfirm: cannot get attachment"));
  3864. }
  3865. }
  3866. else
  3867. {
  3868. ERROR_OUT(("Domain::TokenGiveConfirm: cannot find channel"));
  3869. }
  3870. }
  3871. else
  3872. {
  3873. /*
  3874. * The named initiator does not exist in the sub-tree of this
  3875. * provider. Ignore the confirm.
  3876. */
  3877. ERROR_OUT(("Domain::TokenGiveConfirm: initiator not valid"));
  3878. }
  3879. }
  3880. }
  3881. else
  3882. {
  3883. /*
  3884. * This confirm was received from someone besides the Top Provider.
  3885. * Ignore the indication.
  3886. */
  3887. ERROR_OUT(("Domain::TokenGiveConfirm: invalid originator=0x%p", pOrigConn));
  3888. }
  3889. }
  3890. /*
  3891. * Void TokenPleaseRequest ()
  3892. *
  3893. * Public
  3894. *
  3895. * Functional Description:
  3896. */
  3897. Void Domain::TokenPleaseRequest (
  3898. CAttachment *pOrigAtt,
  3899. UserID uidInitiator,
  3900. TokenID token_id)
  3901. {
  3902. PToken token;
  3903. /*
  3904. * Make sure the requesting user really exists in the sub-tree from which
  3905. * this request originated.
  3906. */
  3907. if (ValidateUserID(uidInitiator, pOrigAtt))
  3908. {
  3909. /*
  3910. * If the token already exists in the token list, then let the
  3911. * Token object deal with the request.
  3912. */
  3913. if (NULL != (token = m_TokenList2.Find(token_id)))
  3914. {
  3915. TRACE_OUT(("Domain::TokenPleaseRequest: sending please request to token object"));
  3916. token->TokenPleaseRequest(uidInitiator, token_id);
  3917. }
  3918. else
  3919. {
  3920. /*
  3921. * Check to see if this is the Top Provider. If it is, then the
  3922. * request can be processed locally. Otherwise, forward the
  3923. * request upward.
  3924. */
  3925. if (IsTopProvider())
  3926. {
  3927. /*
  3928. * The token being released is not owned by anyone. Report the
  3929. * incident to the diagnostic window, but do nothing. This
  3930. * simply indicates that someone has issued a please request
  3931. * for a token that no one owns.
  3932. */
  3933. ERROR_OUT(("Domain::TokenPleaseRequest: token does not exist"));
  3934. }
  3935. else
  3936. {
  3937. /*
  3938. * This is not the Top Provider. Forward the request upward.
  3939. */
  3940. TRACE_OUT(("Domain::TokenPleaseRequest: forwarding please request to Top Provider"));
  3941. m_pConnToTopProvider->TokenPleaseRequest(uidInitiator, token_id);
  3942. }
  3943. }
  3944. }
  3945. else
  3946. {
  3947. /*
  3948. * There is no such user in the sub-tree from which this request
  3949. * originated. Ignore the request.
  3950. */
  3951. ERROR_OUT(("Domain::TokenPleaseRequest: invalid originator=0x%p", pOrigAtt));
  3952. }
  3953. }
  3954. /*
  3955. * Void TokenPleaseIndication ()
  3956. *
  3957. * Public
  3958. *
  3959. * Functional Description:
  3960. */
  3961. Void Domain::TokenPleaseIndication (
  3962. PConnection pOrigConn,
  3963. UserID uidInitiator,
  3964. TokenID token_id)
  3965. {
  3966. PToken token;
  3967. /*
  3968. * Verify that the indication came from the Top Provider.
  3969. */
  3970. if (pOrigConn == m_pConnToTopProvider)
  3971. {
  3972. /*
  3973. * See if the token already exists in the local information base. If
  3974. * so, let it handle this.
  3975. */
  3976. if (NULL != (token = m_TokenList2.Find(token_id)))
  3977. {
  3978. TRACE_OUT(("Domain::TokenPleaseIndication: sending please indication to token object"));
  3979. token->TokenPleaseIndication(uidInitiator, token_id);
  3980. }
  3981. else
  3982. {
  3983. /*
  3984. * Since token please indication is only sent downward to providers
  3985. * that have owners in their sub-tree, it should not be possible
  3986. * to get here. This indicates that this provider received the
  3987. * indication with NO owners in its sub-tree. Report the error
  3988. * and ignore the indication.
  3989. */
  3990. ERROR_OUT(("Domain::TokenPleaseIndication: invalid token"));
  3991. }
  3992. }
  3993. else
  3994. {
  3995. /*
  3996. * This indication was received from someone besides the Top Provider.
  3997. * Ignore the indication.
  3998. */
  3999. ERROR_OUT(("Domain::TokenPleaseIndication: invalid originator=0x%p", pOrigConn));
  4000. }
  4001. }
  4002. /*
  4003. * Void TokenReleaseRequest ()
  4004. *
  4005. * Public
  4006. *
  4007. * Functional Description:
  4008. * This MCS command is initially sent by a user attachment that wishes
  4009. * to release a token. It flows upward to the Top Provider, who attempts
  4010. * to satisfy the request.
  4011. */
  4012. Void Domain::TokenReleaseRequest (
  4013. CAttachment *pOrigAtt,
  4014. UserID uidInitiator,
  4015. TokenID token_id)
  4016. {
  4017. PToken token;
  4018. /*
  4019. * Make sure the requesting user really exists in the sub-tree from which
  4020. * this request originated.
  4021. */
  4022. if (ValidateUserID(uidInitiator, pOrigAtt))
  4023. {
  4024. /*
  4025. * If the token already exists in the token list, then let the
  4026. * Token object deal with the request.
  4027. */
  4028. if (NULL != (token = m_TokenList2.Find(token_id)))
  4029. {
  4030. /*
  4031. * Send the release request to the token object. Then check to
  4032. * see if it is still valid (delete it if not).
  4033. */
  4034. TRACE_OUT(("Domain::TokenReleaseRequest: sending release request to token object"));
  4035. token->TokenReleaseRequest(pOrigAtt, uidInitiator, token_id);
  4036. if (token->IsValid () == FALSE)
  4037. DeleteToken (token_id);
  4038. }
  4039. else
  4040. {
  4041. /*
  4042. * Check to see if this is the Top Provider. If it is, then the
  4043. * request can be processed locally. Otherwise, forward the
  4044. * request upward.
  4045. */
  4046. if (IsTopProvider())
  4047. {
  4048. /*
  4049. * The token being released is not owned by anyone. Return
  4050. * a failure to the initiating user.
  4051. */
  4052. ERROR_OUT(("Domain::TokenReleaseRequest: token does not exist"));
  4053. pOrigAtt->TokenReleaseConfirm(RESULT_TOKEN_NOT_POSSESSED, uidInitiator, token_id, TOKEN_NOT_IN_USE);
  4054. }
  4055. else
  4056. {
  4057. /*
  4058. * This is not the Top Provider. Forward the request upward.
  4059. */
  4060. TRACE_OUT(("Domain::TokenReleaseRequest: forwarding release request to Top Provider"));
  4061. m_pConnToTopProvider->TokenReleaseRequest(uidInitiator, token_id);
  4062. }
  4063. }
  4064. }
  4065. else
  4066. {
  4067. /*
  4068. * There is no such user in the sub-tree from which this request
  4069. * originated. Ignore the request.
  4070. */
  4071. ERROR_OUT(("Domain::TokenReleaseRequest: invalid originator=0x%p", pOrigAtt));
  4072. }
  4073. }
  4074. /*
  4075. * Void TokenReleaseConfirm ()
  4076. *
  4077. * Public
  4078. *
  4079. * Functional Description:
  4080. * This MCS command is initially sent by the Top Provider upon receipt of
  4081. * a release request. It is sent back to the initiating user, containing
  4082. * the result of the request.
  4083. */
  4084. Void Domain::TokenReleaseConfirm (
  4085. PConnection pOrigConn,
  4086. Result result,
  4087. UserID uidInitiator,
  4088. TokenID token_id,
  4089. TokenStatus token_status)
  4090. {
  4091. PToken token;
  4092. /*
  4093. * Verify that the confirm came from the Top Provider.
  4094. */
  4095. if (pOrigConn == m_pConnToTopProvider)
  4096. {
  4097. /*
  4098. * See if the token already exists in the local information base. If
  4099. * so, let it handle this.
  4100. */
  4101. if (NULL != (token = m_TokenList2.Find(token_id)))
  4102. {
  4103. /*
  4104. * Send the release confirm to the token object. Then check to
  4105. * see if it is still valid (delete it if not).
  4106. */
  4107. TRACE_OUT(("Domain::TokenReleaseConfirm: sending release confirm to token object"));
  4108. token->TokenReleaseConfirm(result, uidInitiator, token_id, token_status);
  4109. if (token->IsValid () == FALSE)
  4110. DeleteToken (token_id);
  4111. }
  4112. else
  4113. {
  4114. /*
  4115. * Make sure that the requesting user is still somewhere in the
  4116. * sub-tree of this provider.
  4117. */
  4118. if (ValidateUserID (uidInitiator, NULL) )
  4119. {
  4120. PChannel channel;
  4121. /*
  4122. * Determine which attachment leads to the requesting user.
  4123. * Then forward the confirm in that direction.
  4124. */
  4125. TRACE_OUT(("Domain::TokenReleaseConfirm: forwarding release confirm"));
  4126. if (NULL != (channel = m_ChannelList2.Find(uidInitiator)))
  4127. {
  4128. CAttachment *pAtt = channel->GetAttachment();
  4129. if (pAtt)
  4130. {
  4131. pAtt->TokenReleaseConfirm(result, uidInitiator, token_id, token_status);
  4132. }
  4133. else
  4134. {
  4135. ERROR_OUT(("Domain::TokenReleaseConfirm: cannot get attachment"));
  4136. }
  4137. }
  4138. else
  4139. {
  4140. ERROR_OUT(("Domain::TokenReleaseConfirm: cannot find channel"));
  4141. }
  4142. }
  4143. else
  4144. {
  4145. /*
  4146. * The named initiator does not exist in the sub-tree of this
  4147. * provider. Ignore the confirm.
  4148. */
  4149. WARNING_OUT(("Domain::TokenReleaseConfirm: initiator not valid"));
  4150. }
  4151. }
  4152. }
  4153. else
  4154. {
  4155. /*
  4156. * This confirm was received from someone besides the Top Provider.
  4157. * Ignore the indication.
  4158. */
  4159. ERROR_OUT(("Domain::TokenReleaseConfirm: invalid originator=0x%p", pOrigConn));
  4160. }
  4161. }
  4162. /*
  4163. * Void TokenTestRequest ()
  4164. *
  4165. * Public
  4166. *
  4167. * Functional Description:
  4168. * This MCS command is initially sent by a user attachment that wishes
  4169. * to test a token. It flows upward to the Top Provider, who attempts
  4170. * to satisfy the request.
  4171. */
  4172. Void Domain::TokenTestRequest (
  4173. CAttachment *pOrigAtt,
  4174. UserID uidInitiator,
  4175. TokenID token_id)
  4176. {
  4177. PToken token;
  4178. /*
  4179. * Make sure the requesting user really exists in the sub-tree from which
  4180. * this request originated.
  4181. */
  4182. if (ValidateUserID(uidInitiator, pOrigAtt))
  4183. {
  4184. /*
  4185. * If the token already exists in the token list, then let the Token
  4186. * object deal with the request.
  4187. */
  4188. if (NULL != (token = m_TokenList2.Find(token_id)))
  4189. {
  4190. TRACE_OUT(("Domain::TokenTestRequest: sending test request to token object"));
  4191. token->TokenTestRequest(pOrigAtt, uidInitiator, token_id);
  4192. }
  4193. else
  4194. {
  4195. /*
  4196. * Check to see if this is the Top Provider. If it is, then the
  4197. * request can be processed locally. Otherwise, forward the
  4198. * request upward.
  4199. */
  4200. if (IsTopProvider())
  4201. {
  4202. /*
  4203. * If the token is not in the list, send a confirm back to
  4204. * the initiating user telling it that the token is not in use.
  4205. */
  4206. ERROR_OUT(("Domain::TokenTestRequest: no such token - available"));
  4207. pOrigAtt->TokenTestConfirm(uidInitiator, token_id, TOKEN_NOT_IN_USE);
  4208. }
  4209. else
  4210. {
  4211. /*
  4212. * This is not the Top Provider. Forward the request upward.
  4213. */
  4214. TRACE_OUT(("Domain::TokenTestRequest: forwarding test request to Top Provider"));
  4215. m_pConnToTopProvider->TokenTestRequest(uidInitiator, token_id);
  4216. }
  4217. }
  4218. }
  4219. else
  4220. {
  4221. /*
  4222. * There is no such user in the sub-tree from which this request
  4223. * originated. Ignore the request.
  4224. */
  4225. ERROR_OUT(("Domain::TokenTestRequest: invalid originator=0x%p", pOrigAtt));
  4226. }
  4227. }
  4228. /*
  4229. * Void TokenTestConfirm ()
  4230. *
  4231. * Public
  4232. *
  4233. * Functional Description:
  4234. * This MCS command is initially sent by the Top Provider upon receipt of
  4235. * a test request. It is sent back to the initiating user, containing
  4236. * the result of the request.
  4237. */
  4238. Void Domain::TokenTestConfirm (
  4239. PConnection pOrigConn,
  4240. UserID uidInitiator,
  4241. TokenID token_id,
  4242. TokenStatus token_status)
  4243. {
  4244. PToken token;
  4245. /*
  4246. * Verify that the confirm came from the Top Provider.
  4247. */
  4248. if (pOrigConn == m_pConnToTopProvider)
  4249. {
  4250. /*
  4251. * See if the token already exists in the local information base. If
  4252. * so, let it handle this.
  4253. */
  4254. if (NULL != (token = m_TokenList2.Find(token_id)))
  4255. {
  4256. TRACE_OUT(("Domain::TokenTestConfirm: sending test confirm to token object"));
  4257. token->TokenTestConfirm(uidInitiator, token_id, token_status);
  4258. }
  4259. else
  4260. {
  4261. /*
  4262. * Make sure that the requesting user is still somewhere in the
  4263. * sub-tree of this provider.
  4264. */
  4265. if (ValidateUserID (uidInitiator, NULL) )
  4266. {
  4267. PChannel channel;
  4268. /*
  4269. * Determine which attachment leads to the requesting user.
  4270. * Then forward the confirm in that direction.
  4271. */
  4272. TRACE_OUT(("Domain::TokenTestConfirm: forwarding test confirm"));
  4273. if (NULL != (channel = m_ChannelList2.Find(uidInitiator)))
  4274. {
  4275. CAttachment *pAtt = channel->GetAttachment();
  4276. if (pAtt)
  4277. {
  4278. pAtt->TokenTestConfirm(uidInitiator, token_id, token_status);
  4279. }
  4280. else
  4281. {
  4282. ERROR_OUT(("Domain::TokenTestConfirm: cannot get attachment"));
  4283. }
  4284. }
  4285. else
  4286. {
  4287. ERROR_OUT(("Domain::TokenTestConfirm: cannot find channel"));
  4288. }
  4289. }
  4290. else
  4291. {
  4292. /*
  4293. * The named initiator does not exist in the sub-tree of this
  4294. * provider. Ignore the confirm.
  4295. */
  4296. ERROR_OUT(("Domain::TokenTestConfirm: initiator not valid uidInitiator=%u", (UINT) uidInitiator));
  4297. }
  4298. }
  4299. }
  4300. else
  4301. {
  4302. /*
  4303. * This confirm was received from someone besides the Top Provider.
  4304. * Ignore the indication.
  4305. */
  4306. ERROR_OUT(("Domain::TokenTestConfirm: invalid originator=0x%p", pOrigConn));
  4307. }
  4308. }
  4309. /*
  4310. * Void LockDomainParameters ()
  4311. *
  4312. * Private
  4313. *
  4314. * Functional Description:
  4315. * This routine is used to initialize the values of the domain parameters
  4316. * instance variable.
  4317. *
  4318. * Formal Parameters:
  4319. * domain_parameters
  4320. * This is a pointer to the domain parameters structure from which the
  4321. * values are to be obtained. If it is set to NULL, then put a default
  4322. * set of parameters into the instance variable.
  4323. * parameters_locked
  4324. * This parameter indicates whether or not these parameters have been
  4325. * locked into the domain by acceptance of the first connection.
  4326. *
  4327. * Return Value:
  4328. * None.
  4329. *
  4330. * Side Effects:
  4331. * None.
  4332. */
  4333. Void Domain::LockDomainParameters (
  4334. PDomainParameters domain_parameters,
  4335. BOOL parameters_locked)
  4336. {
  4337. /*
  4338. * If the structure pointer is valid, then copy the structure into the
  4339. * internal instance variable.
  4340. */
  4341. if (domain_parameters != NULL)
  4342. Domain_Parameters = *domain_parameters;
  4343. else
  4344. {
  4345. /*
  4346. * Set default values for all domain parameters.
  4347. */
  4348. Domain_Parameters.max_channel_ids = DEFAULT_MAXIMUM_CHANNELS;
  4349. Domain_Parameters.max_user_ids = DEFAULT_MAXIMUM_USERS;
  4350. Domain_Parameters.max_token_ids = DEFAULT_MAXIMUM_TOKENS;
  4351. Domain_Parameters.number_priorities = DEFAULT_NUMBER_OF_PRIORITIES;
  4352. Domain_Parameters.min_throughput = DEFAULT_MINIMUM_THROUGHPUT;
  4353. Domain_Parameters.max_height = DEFAULT_MAXIMUM_DOMAIN_HEIGHT;
  4354. Domain_Parameters.max_mcspdu_size = DEFAULT_MAXIMUM_PDU_SIZE;
  4355. Domain_Parameters.protocol_version = DEFAULT_PROTOCOL_VERSION;
  4356. if (g_fWinsockDisabled)
  4357. {
  4358. Domain_Parameters.number_priorities = DEFAULT_NUM_PLUGXPRT_PRIORITIES;
  4359. }
  4360. }
  4361. /*
  4362. * Indicate whether or not these parameters are locked.
  4363. */
  4364. Domain_Parameters_Locked = parameters_locked;
  4365. }
  4366. /*
  4367. * ChannelID AllocateDynamicChannel ()
  4368. *
  4369. * Private
  4370. *
  4371. * Functional Description:
  4372. * This member function is used to allocate an unused channel ID in the
  4373. * dynamic range (1001 - 65535). It uses a random number generator to
  4374. * perform this task.
  4375. *
  4376. * Formal Parameters:
  4377. * None.
  4378. *
  4379. * Return Value:
  4380. * A channel ID in the dynamic range that is guaranteed to be unused.
  4381. *
  4382. * Side Effects:
  4383. * None.
  4384. */
  4385. ChannelID Domain::AllocateDynamicChannel ()
  4386. {
  4387. ChannelID channel_id;
  4388. /*
  4389. * Stay in this loop until a unused channel ID is found. Note that this
  4390. * loop make sthe assumption that there will be at least one unused ID
  4391. * in there somewhere.
  4392. */
  4393. while (TRUE)
  4394. {
  4395. /*
  4396. * Get a random number in the dynamic channel range.
  4397. */
  4398. channel_id = (ChannelID) Random_Channel_Generator.GetRandomChannel ();
  4399. /*
  4400. * If it is not is use, then break out of the loop and return the
  4401. * channel ID.
  4402. */
  4403. if (! m_ChannelList2.Find(channel_id))
  4404. break;
  4405. }
  4406. return (channel_id);
  4407. }
  4408. /*
  4409. * BOOL ValidateUserID ()
  4410. *
  4411. * Private
  4412. *
  4413. * Functional Description:
  4414. * This function is used to validate a user ID. It can be used in one of
  4415. * two ways. If the passed in attachment is NULL, then this routine will
  4416. * check to see if the ID corresponds to a user ID anywhere in the sub-tree
  4417. * of this provider. If the passed in attachment is not NULL, then this
  4418. * routine checks to see if the ID is valid user ID associated with that
  4419. * particular attachment.
  4420. *
  4421. * Formal Parameters:
  4422. * user_id
  4423. * This is the ID to be checked for validity.
  4424. * attachment
  4425. * This is the attachment that is presumably associated with the user
  4426. * ID. If NULL, we are checking for validity irrespective of
  4427. * attachment.
  4428. *
  4429. * Return Value:
  4430. * This routine will return TRUE if the user ID valid. FALSE otherwise.
  4431. *
  4432. * Side Effects:
  4433. * None.
  4434. */
  4435. BOOL Domain::ValidateUserID (
  4436. UserID user_id,
  4437. CAttachment *pAtt)
  4438. {
  4439. PChannel channel;
  4440. /*
  4441. * Is the user ID even contained in the channel list.
  4442. */
  4443. if (NULL != (channel = m_ChannelList2.Find(user_id)))
  4444. {
  4445. /*
  4446. * It is in the channel list. Now check to see if it corresponds to
  4447. * a user ID channel.
  4448. */
  4449. if (channel->GetChannelType () == USER_CHANNEL)
  4450. {
  4451. /*
  4452. * Check to make sure that the real user attachment matches the
  4453. * passed in one (unless the passed in one is NULL, in which
  4454. * case it automatically matches).
  4455. */
  4456. if ((pAtt == NULL) || (pAtt == channel->GetAttachment()))
  4457. return TRUE;
  4458. }
  4459. }
  4460. return (FALSE);
  4461. }
  4462. /*
  4463. * Void PurgeDomain ()
  4464. *
  4465. * Private
  4466. *
  4467. * Functional Description:
  4468. * This function is used to purge the entire domain. This can happen for
  4469. * two reasons. Either the Top Provider is lost, or the local user has
  4470. * asked for the domain to be deleted. Either way, this function breaks
  4471. * all attachments, and frees up all resources in use by the domain.
  4472. *
  4473. * Formal Parameters:
  4474. * None.
  4475. *
  4476. * Return Value:
  4477. * None.
  4478. *
  4479. * Side Effects:
  4480. * The domain information base is returned to its initial state.
  4481. */
  4482. Void Domain::PurgeDomain (
  4483. Reason reason)
  4484. {
  4485. CAttachment *pAtt;
  4486. PChannel channel;
  4487. CUidList user_list;
  4488. UserID uid;
  4489. /*
  4490. * If there is a Top Provider, send a disconnect to it.
  4491. */
  4492. if (m_pConnToTopProvider != NULL)
  4493. {
  4494. TRACE_OUT(("Domain::PurgeDomain: disconnecting top provider"));
  4495. m_pConnToTopProvider->DisconnectProviderUltimatum (reason);
  4496. m_pConnToTopProvider = NULL;
  4497. }
  4498. /*
  4499. * Send disconnects to all downward attachments. Then clear out the
  4500. * attachment list.
  4501. */
  4502. TRACE_OUT(("Domain::PurgeDomain: disconnecting all downward attachments"));
  4503. while (NULL != (pAtt = m_AttachmentList.Get()))
  4504. {
  4505. pAtt->DisconnectProviderUltimatum(reason);
  4506. /*
  4507. * If there are any pending attach user requests on the attachment
  4508. * that was just broken, delete them. Note that this is a loop
  4509. * because there can be more than one.
  4510. */
  4511. while (m_AttachUserQueue.Remove(pAtt));
  4512. }
  4513. /*
  4514. * Send a disconnect to all attachments that represent attach user requests
  4515. * in process. Then clear the queue out.
  4516. */
  4517. while (NULL != (pAtt = m_AttachUserQueue.Get()))
  4518. {
  4519. pAtt->DisconnectProviderUltimatum(reason);
  4520. }
  4521. /*
  4522. * Clear the merge queue. The actual attachments have already been broken
  4523. * above.
  4524. */
  4525. m_MergeQueue.Clear();
  4526. /*
  4527. * We cannot just delete all channels and tokens, because doing so would
  4528. * cause them to issue various indications to attachments that are no
  4529. * longer valid. To get around this, we must delete all attachments (which
  4530. * was done above) and all user objects from the channel list, and then
  4531. * reclaim unowned resources. This will cause all static, assigned, and
  4532. * private channels, as well as tokens, to delete themselves.
  4533. */
  4534. m_ChannelList2.Reset();
  4535. while (NULL != (channel = m_ChannelList2.Iterate(&uid)))
  4536. {
  4537. if (channel->GetChannelType () == USER_CHANNEL)
  4538. user_list.Append(uid);
  4539. }
  4540. /*
  4541. * Delete all users from the channel list. Since there are no valid users
  4542. * in the domain, all resources that are tied to users will be reclaimed
  4543. * below.
  4544. */
  4545. user_list.Reset();
  4546. while (NULL != (uid = user_list.Iterate()))
  4547. {
  4548. DeleteChannel((ChannelID) uid);
  4549. }
  4550. /*
  4551. * Reclaim unowned resources. Since all resources (channels and tokens)
  4552. * are tied to the existence of either attachments or users, this call
  4553. * will result in all channels and tokens being cleanly deleted (since
  4554. * there aren't any attachments or users).
  4555. */
  4556. ReclaimResources ();
  4557. /*
  4558. * Reset the state to all initial values.
  4559. */
  4560. Merge_State = MERGE_INACTIVE;
  4561. Outstanding_Merge_Requests = 0;
  4562. Number_Of_Users = 0;
  4563. Number_Of_Channels = 0;
  4564. Number_Of_Tokens = 0;
  4565. m_nDomainHeight = 0;
  4566. m_DomainHeightList2.Clear();
  4567. LockDomainParameters (NULL, FALSE);
  4568. }
  4569. /*
  4570. * Void DeleteAttachment ()
  4571. *
  4572. * Private
  4573. *
  4574. * Functional Description:
  4575. * This function is used to free up all resources that are "bound" to
  4576. * particular attachment. It also deletes the downward attachment.
  4577. *
  4578. * Formal Parameters:
  4579. * attachment
  4580. * This is the attachment to be deleted.
  4581. * reason
  4582. * This is the reason for the deletion. This is merely passed on in
  4583. * any MCS commands that are sent as a result of this deletion.
  4584. *
  4585. * Return Value:
  4586. * None.
  4587. *
  4588. * Side Effects:
  4589. * Resources in the domain information base are freed up.
  4590. */
  4591. Void Domain::DeleteAttachment (
  4592. CAttachment *pAtt,
  4593. Reason reason)
  4594. {
  4595. ChannelID chid;
  4596. PChannel channel;
  4597. CUidList user_deletion_list;
  4598. CChannelIDList channel_deletion_list;
  4599. CChannelIDList channel_leave_list;
  4600. /*
  4601. * Check to make sure the attachment is real before proceeding.
  4602. */
  4603. if (m_AttachmentList.Remove(pAtt))
  4604. {
  4605. /*
  4606. * Remove the attachment from the downward attachment list.
  4607. */
  4608. /*
  4609. * Iterate through the channel list building two lists, as follows:
  4610. *
  4611. * 1. A list of users who lie in the direction of the lost attachment.
  4612. * These users must be deleted from the information base, and
  4613. * their detachment reported appropriately.
  4614. * 2. A list of channels that must be deleted as a result of the lost
  4615. * attachment. This list is created by sending a channel leave
  4616. * request to all channels, and then checking to see if they are
  4617. * still valid. All static and assigned channels that only had
  4618. * that attachment joined will be deleted as a result of this.
  4619. * This also results in the attachment being removed from all
  4620. * channel attachment lists, avoiding the possibility of sending
  4621. * data to an invalid attachment.
  4622. */
  4623. m_ChannelList2.Reset();
  4624. while (NULL != (channel = m_ChannelList2.Iterate(&chid)))
  4625. {
  4626. /*
  4627. * Check to see if this is a user ID channel whose user lies on the
  4628. * other side of the lost attachment. If so, add the channel to
  4629. * the deletion list.
  4630. */
  4631. if (channel->GetChannelType () == USER_CHANNEL)
  4632. {
  4633. if (channel->GetAttachment() == pAtt)
  4634. {
  4635. user_deletion_list.Append(chid);
  4636. continue;
  4637. }
  4638. }
  4639. /*
  4640. * Issue the leave request to the channel. Then check to see if it
  4641. * is still valid. If not, then add it to the deletion list.
  4642. */
  4643. channel_leave_list.Clear();
  4644. channel_leave_list.Append(chid);
  4645. channel->ChannelLeaveRequest(pAtt, &channel_leave_list);
  4646. if (channel->IsValid () == FALSE)
  4647. channel_deletion_list.Append(chid);
  4648. }
  4649. /*
  4650. * Iterate through the channel list, deleting the channels it
  4651. * contains.
  4652. */
  4653. channel_deletion_list.Reset();
  4654. while (NULL != (chid = channel_deletion_list.Iterate()))
  4655. {
  4656. DeleteChannel(chid);
  4657. }
  4658. /*
  4659. * If there are any users to be deleted, simulate a DetachUserRequest
  4660. * with the list of users to be deleted.
  4661. */
  4662. if (user_deletion_list.IsEmpty() == FALSE)
  4663. DetachUserRequest(pAtt, reason, &user_deletion_list);
  4664. /*
  4665. * Check to see if the deleted attachment is represented in the
  4666. * domain height list. If it is, then this loss could result in a
  4667. * change in the overall domain height.
  4668. */
  4669. if (m_DomainHeightList2.Remove((PConnection) pAtt))
  4670. {
  4671. /*
  4672. * The attachment is in the list. Remove it from the list, and
  4673. * call the subroutine that determines whether an overall height
  4674. * change has occurred that may require further activity.
  4675. */
  4676. CalculateDomainHeight ();
  4677. }
  4678. }
  4679. else
  4680. {
  4681. /*
  4682. * The named attachment isn't even in the attachment list.
  4683. */
  4684. ERROR_OUT(("Domain::DeleteAttachment: unknown attachment=0x%p", pAtt));
  4685. }
  4686. }
  4687. /*
  4688. * Void DeleteUser ()
  4689. *
  4690. * Private
  4691. *
  4692. * Functional Description:
  4693. * This routine deletes a user from the information base. This is fairly
  4694. * complex task because there are a lot of dependencies on users within
  4695. * the MCS protocol. If the user being deleted is locall attached, then
  4696. * the attachment must be severed. Also, any resources that are being
  4697. * held by the user must be reclaimed. And finally, the user channel
  4698. * object that represents the user must be deleted from the local channel
  4699. * list.
  4700. *
  4701. * Formal Parameters:
  4702. * user_id
  4703. * This is the ID of the user being deleted.
  4704. *
  4705. * Return Value:
  4706. * None.
  4707. *
  4708. * Side Effects:
  4709. * None.
  4710. */
  4711. Void Domain::DeleteUser (
  4712. UserID user_id)
  4713. {
  4714. CAttachment *pAtt;
  4715. ChannelID chid;
  4716. PChannel channel;
  4717. CChannelIDList deletion_list;
  4718. CChannelIDList channel_leave_list;
  4719. /*
  4720. * Make sure this is a valid user in the sub-tree of this provider before
  4721. * proceeding.
  4722. */
  4723. if (ValidateUserID (user_id, NULL) )
  4724. {
  4725. /*
  4726. * Determine which attachment leads to the user in question.
  4727. */
  4728. if (NULL != (channel = m_ChannelList2.Find(user_id)))
  4729. {
  4730. pAtt = channel->GetAttachment();
  4731. /*
  4732. * Delete the user channel now that it is no longer necessary.
  4733. */
  4734. DeleteChannel (user_id);
  4735. /*
  4736. * Check to see if the user's attachment is still valid. It is
  4737. * possible that the user is being deleted as a result of losing the
  4738. * attachment that leads to it.
  4739. */
  4740. if (m_AttachmentList.Find(pAtt) && pAtt->IsUserAttachment())
  4741. {
  4742. /*
  4743. * If this user was locally attached, then it is necessary to
  4744. * remove it from the attachment list, as well as making sure that
  4745. * no other channel objects attempt to reference it.
  4746. */
  4747. /*
  4748. * Remove the attachment from the downward attachment list.
  4749. */
  4750. TRACE_OUT(("Domain::DeleteUser: deleting local attachment"));
  4751. m_AttachmentList.Remove(pAtt);
  4752. ((PUser) pAtt)->Release();
  4753. /*
  4754. * Iterate through the channel list issuing leave requests to
  4755. * each channel. This prevents a Channel object from trying to
  4756. * send data on an attachment that is no longer valid. This
  4757. * loop also builds a list of Channel objects that should be
  4758. * deleted as a result of this detachment.
  4759. */
  4760. m_ChannelList2.Reset();
  4761. while (NULL != (channel = m_ChannelList2.Iterate(&chid)))
  4762. {
  4763. /*
  4764. * Issue the leave request to the channel. Then check to
  4765. * see if it is still valid. If not, then add it to the
  4766. * deletion list.
  4767. */
  4768. channel_leave_list.Clear();
  4769. channel_leave_list.Append(chid);
  4770. channel->ChannelLeaveRequest(pAtt, &channel_leave_list);
  4771. if (channel->IsValid () == FALSE)
  4772. deletion_list.Append(chid);
  4773. }
  4774. /*
  4775. * Iterator through the deletion list, deleting the channels it
  4776. * contains.
  4777. */
  4778. deletion_list.Reset();
  4779. while (NULL != (chid = deletion_list.Iterate()))
  4780. {
  4781. DeleteChannel(chid);
  4782. }
  4783. }
  4784. /*
  4785. * Reclaim all resources that may have been freed as a result of the
  4786. * deleted user.
  4787. */
  4788. ReclaimResources ();
  4789. }
  4790. else
  4791. {
  4792. ERROR_OUT(("Domain::DeleteUser: cannot find channel"));
  4793. }
  4794. }
  4795. else
  4796. {
  4797. /*
  4798. * The specified user ID is not valid.
  4799. */
  4800. ERROR_OUT(("Domain::DeleteUser: unknown user ID"));
  4801. }
  4802. }
  4803. /*
  4804. * Void DeleteChannel ()
  4805. *
  4806. * Private
  4807. *
  4808. * Functional Description:
  4809. * This function deleted a channel from the channel list. It also adjusts
  4810. * the appropriate channel counter (according to type), and reports the
  4811. * deletion.
  4812. *
  4813. * Formal Parameters:
  4814. * channel_id
  4815. * This is the ID of the channel to be deleted.
  4816. *
  4817. * Return Value:
  4818. * None.
  4819. *
  4820. * Side Effects:
  4821. * None.
  4822. */
  4823. Void Domain::DeleteChannel (
  4824. ChannelID channel_id)
  4825. {
  4826. PChannel channel;
  4827. /*
  4828. * Make sure the channel being deleted is real before proceeding.
  4829. */
  4830. if (NULL != (channel = m_ChannelList2.Remove(channel_id)))
  4831. {
  4832. /*
  4833. * Report the type of channel being deleted, and decrement the
  4834. * appropriate counter.
  4835. */
  4836. Number_Of_Channels--;
  4837. switch (channel->GetChannelType ())
  4838. {
  4839. case STATIC_CHANNEL:
  4840. TRACE_OUT (("Domain::DeleteChannel: "
  4841. "deleting static channel ID = %04X", channel_id));
  4842. break;
  4843. case ASSIGNED_CHANNEL:
  4844. TRACE_OUT (("Domain::DeleteChannel: "
  4845. "deleting assigned channel ID = %04X", channel_id));
  4846. break;
  4847. case USER_CHANNEL:
  4848. TRACE_OUT (("Domain::DeleteChannel: "
  4849. "deleting user channel ID = %04X", channel_id));
  4850. Number_Of_Users--;
  4851. break;
  4852. case PRIVATE_CHANNEL:
  4853. TRACE_OUT (("Domain::DeleteChannel: "
  4854. "deleting private channel ID = %04X", channel_id));
  4855. break;
  4856. default:
  4857. ERROR_OUT (("Domain::DeleteChannel: "
  4858. "ERROR - deleting unknown channel ID = %04X",
  4859. channel_id));
  4860. Number_Of_Channels++;
  4861. break;
  4862. }
  4863. /*
  4864. * Delete the channel object.
  4865. */
  4866. delete channel;
  4867. }
  4868. else
  4869. {
  4870. ERROR_OUT(("Domain::DeleteChannel: unknown channel ID"));
  4871. }
  4872. }
  4873. /*
  4874. * Void DeleteToken ()
  4875. *
  4876. * Private
  4877. *
  4878. * Functional Description:
  4879. * This function deletes a token from the token list. It also adjusts
  4880. * the token counter.
  4881. *
  4882. * Formal Parameters:
  4883. * token_id
  4884. * This is the ID of the token to be deleted.
  4885. *
  4886. * Return Value:
  4887. * None.
  4888. *
  4889. * Side Effects:
  4890. * None.
  4891. */
  4892. Void Domain::DeleteToken (
  4893. TokenID token_id)
  4894. {
  4895. PToken token;
  4896. /*
  4897. * Check to make sure that the token being deleted is real before
  4898. * proceeding.
  4899. */
  4900. if (NULL != (token = m_TokenList2.Remove(token_id)))
  4901. {
  4902. /*
  4903. * Remove the token from the token list and delete it.
  4904. */
  4905. TRACE_OUT(("Domain::DeleteToken: deleting token ID = %04X", (UINT) token_id));
  4906. delete token;
  4907. /*
  4908. * Decrement the token counter.
  4909. */
  4910. Number_Of_Tokens--;
  4911. }
  4912. else
  4913. {
  4914. ERROR_OUT(("Domain::DeleteToken: unknown token ID"));
  4915. }
  4916. }
  4917. /*
  4918. * Void ReclaimResources ()
  4919. *
  4920. * Private
  4921. *
  4922. * Functional Description:
  4923. * This function walks through both the channel and token lists, removing
  4924. * all objects that are no longer valid. This function just queries each
  4925. * channel and token to see if it is still valid. This allows for the
  4926. * reclamation of resources when a user is deleted.
  4927. *
  4928. * Formal Parameters:
  4929. * None.
  4930. *
  4931. * Return Value:
  4932. * None.
  4933. *
  4934. * Side Effects:
  4935. * None.
  4936. */
  4937. Void Domain::ReclaimResources ()
  4938. {
  4939. ChannelID chid;
  4940. PChannel channel;
  4941. CChannelIDList channel_deletion_list;
  4942. TokenID tid;
  4943. PToken token;
  4944. CTokenIDList token_deletion_list;
  4945. /*
  4946. * Iterate through the channel list, asking each channel if it is still
  4947. * valid. Any that are not will be deleted by the next loop.
  4948. */
  4949. m_ChannelList2.Reset();
  4950. while (NULL != (channel = m_ChannelList2.Iterate(&chid)))
  4951. {
  4952. /*
  4953. * Check to see if the channel is still valid. If not, add it to the
  4954. * deletion list.
  4955. */
  4956. if (channel->IsValid () == FALSE)
  4957. channel_deletion_list.Append(chid);
  4958. }
  4959. /*
  4960. * Delete all channels in the deletion list.
  4961. */
  4962. channel_deletion_list.Reset();
  4963. while (NULL != (chid = channel_deletion_list.Iterate()))
  4964. {
  4965. DeleteChannel(chid);
  4966. }
  4967. /*
  4968. * Iterate through the token list, asking each token if it is still
  4969. * valid. Any that are not will be deleted by the next loop.
  4970. */
  4971. m_TokenList2.Reset();
  4972. while (NULL != (token = m_TokenList2.Iterate(&tid)))
  4973. {
  4974. /*
  4975. * Check to see if the token is still valid. If the grabber or
  4976. * inhibitor was the only owner of the token, then it will be freed
  4977. * here.
  4978. */
  4979. if (token->IsValid () == FALSE)
  4980. token_deletion_list.Append(tid);
  4981. }
  4982. /*
  4983. * Delete all tokens in the deletion list.
  4984. */
  4985. while (NULL != (tid = token_deletion_list.Get()))
  4986. {
  4987. DeleteToken(tid);
  4988. }
  4989. }
  4990. /*
  4991. * Void MergeInformationBase ()
  4992. *
  4993. * Private
  4994. *
  4995. * Functional Description:
  4996. * This function is essentially a state machine for the domain merger
  4997. * process. Domain merging is currently implemented to only try and
  4998. * merge one type of resource at a time. Each time this routine is
  4999. * called, the next type of resource is merged. After all resources have
  5000. * been merged, this provider ceases to be a Top Provider, and the merge
  5001. * state is returned to inactive.
  5002. *
  5003. * Formal Parameters:
  5004. * None.
  5005. *
  5006. * Return Value:
  5007. * None.
  5008. *
  5009. * Side Effects:
  5010. * Contents of the domain information are merged upward to the Top
  5011. * Provider of the upper domain.
  5012. */
  5013. Void Domain::MergeInformationBase ()
  5014. {
  5015. MergeState merge_state;
  5016. Channel_Type channel_type;
  5017. PChannel channel;
  5018. PToken token;
  5019. /*
  5020. * This call is not valid unless there is a Top Provider to merge the
  5021. * information upward to.
  5022. */
  5023. if (m_pConnToTopProvider != NULL)
  5024. {
  5025. /*
  5026. * As part of the transition to the next merge state, set the number
  5027. * of outstanding merge requests to 0.
  5028. */
  5029. Outstanding_Merge_Requests = 0;
  5030. merge_state = Merge_State;
  5031. while (Outstanding_Merge_Requests == 0)
  5032. {
  5033. /*
  5034. * Each case of this switch statement sets two variables. The
  5035. * first is the merge state. This is bumped to the next state
  5036. * in the sequence. The second is the channel type. This is
  5037. * used for controlling which type of channel is being merged
  5038. * upward for this state.
  5039. */
  5040. switch (merge_state)
  5041. {
  5042. case MERGE_INACTIVE:
  5043. TRACE_OUT(("Domain::MergeInformationBase: merging User IDs"));
  5044. merge_state = MERGE_USER_IDS;
  5045. channel_type = USER_CHANNEL;
  5046. break;
  5047. case MERGE_USER_IDS:
  5048. TRACE_OUT(("Domain::MergeInformationBase: merging Static Channels"));
  5049. merge_state = MERGE_STATIC_CHANNELS;
  5050. channel_type = STATIC_CHANNEL;
  5051. break;
  5052. case MERGE_STATIC_CHANNELS:
  5053. TRACE_OUT(("Domain::MergeInformationBase: merging Assigned Channels"));
  5054. merge_state = MERGE_ASSIGNED_CHANNELS;
  5055. channel_type = ASSIGNED_CHANNEL;
  5056. break;
  5057. case MERGE_ASSIGNED_CHANNELS:
  5058. TRACE_OUT(("Domain::MergeInformationBase: merging Private Channels"));
  5059. merge_state = MERGE_PRIVATE_CHANNELS;
  5060. channel_type = PRIVATE_CHANNEL;
  5061. break;
  5062. case MERGE_PRIVATE_CHANNELS:
  5063. TRACE_OUT(("Domain::MergeInformationBase: merging Tokens"));
  5064. merge_state = MERGE_TOKENS;
  5065. break;
  5066. case MERGE_TOKENS:
  5067. TRACE_OUT(("Domain::MergeInformationBase: domain merger complete"));
  5068. merge_state = MERGE_COMPLETE;
  5069. break;
  5070. default:
  5071. ERROR_OUT(("Domain::MergeInformationBase: invalid merge state"));
  5072. break;
  5073. }
  5074. /*
  5075. * If the merge is now complete, then this provider must cease
  5076. * to be a Top Provider.
  5077. */
  5078. if (merge_state == MERGE_COMPLETE)
  5079. {
  5080. /*
  5081. * Reset the merge state, and break out of this loop.
  5082. */
  5083. merge_state = MERGE_INACTIVE;
  5084. break;
  5085. }
  5086. /*
  5087. * Check to see if we are to merge tokens on this pass.
  5088. */
  5089. if (merge_state == MERGE_TOKENS)
  5090. {
  5091. /*
  5092. * Iterate through the token list, sending merge requests to
  5093. * each Token object. Pass in the identity of the pending
  5094. * Top Provider, so that the Token object knows where to send
  5095. * the MergeTokensRequest. Increment the number of
  5096. * outstanding merge requests.
  5097. */
  5098. m_TokenList2.Reset();
  5099. while (NULL != (token = m_TokenList2.Iterate()))
  5100. {
  5101. token->IssueMergeRequest ();
  5102. Outstanding_Merge_Requests++;
  5103. }
  5104. }
  5105. else
  5106. {
  5107. /*
  5108. * This must be a merge state for channels. Iterate through
  5109. * the channel list, sending a merge request to each Channel
  5110. * object whose type matches that specified by the merge
  5111. * state that we are. Increment the outstanding merge
  5112. * request counter each time one is sent.
  5113. */
  5114. m_ChannelList2.Reset();
  5115. while (NULL != (channel = m_ChannelList2.Iterate()))
  5116. {
  5117. if (channel->GetChannelType () == channel_type)
  5118. {
  5119. channel->IssueMergeRequest ();
  5120. Outstanding_Merge_Requests++;
  5121. }
  5122. }
  5123. }
  5124. }
  5125. SetMergeState (merge_state);
  5126. }
  5127. else
  5128. {
  5129. /*
  5130. * This routine has been called when the domain is not in the
  5131. * appropriate state.
  5132. */
  5133. ERROR_OUT(("Domain::MergeInformationBase: unable to merge at this time"));
  5134. }
  5135. }
  5136. /*
  5137. * Void SetMergeState ()
  5138. *
  5139. * Private
  5140. *
  5141. * Functional Description:
  5142. * This function sets the merge state to the passed in value. It also
  5143. * detects the transition between MERGE_INACTIVE and any other state.
  5144. * This transition causes the domain to issue MergeDomainIndication to
  5145. * all downward attachments.
  5146. *
  5147. * Formal Parameters:
  5148. * merge_state
  5149. * This is the merge state that we are moving to.
  5150. *
  5151. * Return Value:
  5152. * None.
  5153. *
  5154. * Side Effects:
  5155. * None.
  5156. */
  5157. Void Domain::SetMergeState (
  5158. MergeState merge_state)
  5159. {
  5160. CAttachment *pAtt;
  5161. /*
  5162. * Don't do anything unless the merge state is actually changing.
  5163. */
  5164. if (Merge_State != merge_state)
  5165. {
  5166. /*
  5167. * If the old state is inactive, then that means that we are just
  5168. * beginning a domain merge operation. If this is the case, then
  5169. * iterate through the downward attachment list, telling all
  5170. * attachments about the domain merge.
  5171. *
  5172. * Note that a side effect of this call is that all MCS commands
  5173. * are shut off from the attachments that receive it. This allows the
  5174. * domain information base to remain stable during a merge operation.
  5175. */
  5176. if (Merge_State == MERGE_INACTIVE)
  5177. {
  5178. m_AttachmentList.Reset();
  5179. while (NULL != (pAtt = m_AttachmentList.Iterate()))
  5180. {
  5181. pAtt->MergeDomainIndication(MERGE_DOMAIN_IN_PROGRESS);
  5182. }
  5183. }
  5184. /*
  5185. * Set the merge state.
  5186. */
  5187. Merge_State = merge_state;
  5188. /*
  5189. * If the new state is inactive, then that means that we have just
  5190. * completed a domain merge operation. If this is the case, then
  5191. * iterate through the downward attachment list, telling all
  5192. * attachments about the completion of the merge.
  5193. *
  5194. * Note that a side effect of this call is to re-enable MCS commands
  5195. * from the attachments that receive it.
  5196. */
  5197. if (Merge_State == MERGE_INACTIVE)
  5198. {
  5199. m_AttachmentList.Reset();
  5200. while (NULL != (pAtt = m_AttachmentList.Iterate()))
  5201. {
  5202. pAtt->MergeDomainIndication(MERGE_DOMAIN_COMPLETE);
  5203. }
  5204. }
  5205. }
  5206. }
  5207. /*
  5208. * Void AddChannel ()
  5209. *
  5210. * Private
  5211. *
  5212. * Functional Description:
  5213. * This function is used to add a channel to the channel list during a
  5214. * merge channel operation. This type of channel addition works a little
  5215. * differently, since we do not want to send confirms to the users, but
  5216. * rather, to former Top Provider of the lower domain.
  5217. *
  5218. * Formal Parameters:
  5219. * attachment
  5220. * This is the initial attachment that the channel is to have joined
  5221. * to it.
  5222. * merge_channel
  5223. * This is a pointer to a channel attributes structure containing the
  5224. * attributes of the channel to be added.
  5225. * merge_channel_list
  5226. * This is a list of channel attribute structures for those channels
  5227. * that were successfully merged into the domain information base. It
  5228. * will be used to issue the merge channels confirm downward.
  5229. * purge_channel_list
  5230. * This is a list of channel IDs for those channels that were not
  5231. * successfully merged into the domain information base. It will be
  5232. * used to issue the merge channels confirm downward.
  5233. *
  5234. * Return Value:
  5235. * None.
  5236. *
  5237. * Side Effects:
  5238. * None.
  5239. */
  5240. Void Domain::AddChannel (
  5241. PConnection pConn,
  5242. PChannelAttributes merge_channel,
  5243. CChannelAttributesList *merge_channel_list,
  5244. CChannelIDList *purge_channel_list)
  5245. {
  5246. Channel_Type channel_type;
  5247. ChannelID channel_id=0;
  5248. BOOL joined;
  5249. ChannelID channel_manager=0;
  5250. CUidList *admitted_list;
  5251. PChannel channel=NULL;
  5252. CUidList detach_user_list;
  5253. CChannelIDList channel_leave_list;
  5254. /*
  5255. * Determine what has to be done according to the channel type.
  5256. */
  5257. channel_type = merge_channel->channel_type;
  5258. switch (channel_type)
  5259. {
  5260. case STATIC_CHANNEL:
  5261. /*
  5262. * Get the channel ID from the attributes structure.
  5263. */
  5264. channel_id = merge_channel->u.static_channel_attributes.channel_id;
  5265. /*
  5266. * If this is the Top Provider, check to see if current
  5267. * domain parameters will permit the merge.
  5268. */
  5269. if ((m_pConnToTopProvider == NULL) &&
  5270. (Number_Of_Channels >= Domain_Parameters.max_channel_ids))
  5271. {
  5272. ERROR_OUT(("Domain::AddChannel: too many channels"));
  5273. channel = NULL;
  5274. break;
  5275. }
  5276. /*
  5277. * Attempt to create a new Channel object.
  5278. */
  5279. TRACE_OUT(("Domain::AddChannel: adding new channel ID = %04X", (UINT) channel_id));
  5280. DBG_SAVE_FILE_LINE
  5281. channel = new Channel(channel_id, this, m_pConnToTopProvider, &m_ChannelList2,
  5282. &m_AttachmentList, pConn);
  5283. /*
  5284. * Increment the number of channels if everything went okay.
  5285. */
  5286. if (channel != NULL)
  5287. Number_Of_Channels++;
  5288. break;
  5289. case USER_CHANNEL:
  5290. /*
  5291. * Get the channel ID from the attributes structure.
  5292. */
  5293. joined = merge_channel->u.user_channel_attributes.joined;
  5294. channel_id = merge_channel->u.user_channel_attributes.user_id;
  5295. /*
  5296. * If this is the Top Provider, check to see if current
  5297. * domain parameters will permit the merge.
  5298. */
  5299. if ((m_pConnToTopProvider == NULL) &&
  5300. ((Number_Of_Users >= Domain_Parameters.max_user_ids) ||
  5301. (Number_Of_Channels >= Domain_Parameters.max_channel_ids)))
  5302. {
  5303. ERROR_OUT(("Domain::AddChannel: too many users"));
  5304. channel = NULL;
  5305. break;
  5306. }
  5307. /*
  5308. * Attempt to create a new UserChannel object to represent the
  5309. * merged user ID.
  5310. */
  5311. TRACE_OUT(("Domain::AddChannel: adding new user ID = %04X", (UINT) channel_id));
  5312. DBG_SAVE_FILE_LINE
  5313. channel = new UserChannel(channel_id, pConn, this, m_pConnToTopProvider,
  5314. &m_ChannelList2, &m_AttachmentList, joined ? pConn : NULL);
  5315. /*
  5316. * Increment the number of users if everything went okay.
  5317. */
  5318. if (channel != NULL)
  5319. {
  5320. Number_Of_Users++;
  5321. Number_Of_Channels++;
  5322. }
  5323. break;
  5324. case PRIVATE_CHANNEL:
  5325. /*
  5326. * Get the channel ID and the channel manager ID from the
  5327. * attributes structure.
  5328. */
  5329. joined = merge_channel->u.private_channel_attributes.joined;
  5330. channel_id = merge_channel->u.private_channel_attributes.channel_id;
  5331. channel_manager = merge_channel->
  5332. u.private_channel_attributes.channel_manager;
  5333. admitted_list = merge_channel->
  5334. u.private_channel_attributes.admitted_list;
  5335. /*
  5336. * If this is the Top Provider, check to see if current
  5337. * domain parameters will permit the merge.
  5338. */
  5339. if ((m_pConnToTopProvider == NULL) &&
  5340. (Number_Of_Channels >= Domain_Parameters.max_channel_ids))
  5341. {
  5342. ERROR_OUT(("Domain::AddChannel: too many channels"));
  5343. channel = NULL;
  5344. break;
  5345. }
  5346. /*
  5347. * Attempt to create a new PrivateChannel object.
  5348. */
  5349. TRACE_OUT(("Domain::AddChannel: adding new private channel ID = %04X", (UINT) channel_id));
  5350. DBG_SAVE_FILE_LINE
  5351. channel = new PrivateChannel(channel_id, channel_manager, this, m_pConnToTopProvider,
  5352. &m_ChannelList2, &m_AttachmentList, admitted_list,
  5353. joined ? pConn : NULL);
  5354. /*
  5355. * Increment the number of channels if everything went okay.
  5356. */
  5357. if (channel != NULL)
  5358. Number_Of_Channels++;
  5359. break;
  5360. case ASSIGNED_CHANNEL:
  5361. /*
  5362. * Get the channel ID from the attributes structure.
  5363. */
  5364. channel_id = merge_channel->
  5365. u.assigned_channel_attributes.channel_id;
  5366. /*
  5367. * If this is the Top Provider, check to see if current
  5368. * domain parameters will permit the merge.
  5369. */
  5370. if ((m_pConnToTopProvider == NULL) &&
  5371. (Number_Of_Channels >= Domain_Parameters.max_channel_ids))
  5372. {
  5373. ERROR_OUT(("Domain::AddChannel: too many channels"));
  5374. channel = NULL;
  5375. break;
  5376. }
  5377. /*
  5378. * Attempt to create a new Channel object.
  5379. */
  5380. TRACE_OUT(("Domain::AddChannel: adding new channel ID = %04X", (UINT) channel_id));
  5381. DBG_SAVE_FILE_LINE
  5382. channel = new Channel(channel_id, this, m_pConnToTopProvider, &m_ChannelList2,
  5383. &m_AttachmentList, pConn);
  5384. /*
  5385. * Increment the number of channels if everything went okay.
  5386. */
  5387. if (channel != NULL)
  5388. Number_Of_Channels++;
  5389. break;
  5390. }
  5391. if (channel != NULL)
  5392. {
  5393. /*
  5394. * The channel was successfully created. Add it to the channel list
  5395. * and add the channel structure to the merge channel list, which is
  5396. * used to issue the merge channels confirm downward.
  5397. */
  5398. if(m_ChannelList2.Insert(channel_id, channel))
  5399. {
  5400. merge_channel_list->Append(merge_channel);
  5401. }
  5402. else
  5403. {
  5404. Number_Of_Channels--;
  5405. delete channel;
  5406. }
  5407. }
  5408. else
  5409. {
  5410. /*
  5411. * The channel merge operation has failed. We need to tell whoever
  5412. * is interested in this situation.
  5413. */
  5414. WARNING_OUT(("Domain::AddChannel: channel merger failed"));
  5415. if (m_pConnToTopProvider != NULL)
  5416. {
  5417. /*
  5418. * If this is not the Top Provider, then the Top Provider needs
  5419. * to be told about the problem. If this is a user channel, then
  5420. * issue a detach user request. If it is a normal channel, issue
  5421. * a channel leave request. If it is a private channel, issue a
  5422. * channel disband request.
  5423. */
  5424. switch (channel_type)
  5425. {
  5426. case STATIC_CHANNEL:
  5427. case ASSIGNED_CHANNEL:
  5428. TRACE_OUT(("Domain::AddChannel: sending ChannelLeaveRequest to Top Provider"));
  5429. channel_leave_list.Append(channel_id);
  5430. m_pConnToTopProvider->ChannelLeaveRequest(&channel_leave_list);
  5431. break;
  5432. case USER_CHANNEL:
  5433. TRACE_OUT(("Domain::AddChannel: sending DetachUserRequest to Top Provider"));
  5434. detach_user_list.Append(channel_id);
  5435. m_pConnToTopProvider->DetachUserRequest(REASON_PROVIDER_INITIATED, &detach_user_list);
  5436. break;
  5437. case PRIVATE_CHANNEL:
  5438. TRACE_OUT(("Domain::AddChannel: sending ChannelDisbandRequest to Top Provider"));
  5439. m_pConnToTopProvider->ChannelDisbandRequest(channel_manager, channel_id);
  5440. break;
  5441. }
  5442. }
  5443. /*
  5444. * Since the merge has failed, we need to put the channel ID into the
  5445. * purge channel list (which is used to issue the merge channels
  5446. * confirm downward).
  5447. */
  5448. purge_channel_list->Append(channel_id);
  5449. }
  5450. }
  5451. /*
  5452. * Void AddToken ()
  5453. *
  5454. * Private
  5455. *
  5456. * Functional Description:
  5457. * This function is used to add a token to the token list during a
  5458. * merge token operation. This type of token addition works a little
  5459. * differently, since we do not want to send confirms to the owners of
  5460. * the token, but rather, to the former Top Provider of the lower domain.
  5461. *
  5462. * Formal Parameters:
  5463. * merge_token
  5464. * This is a pointer to a token attributes structure containing the
  5465. * attributes of the token to be added.
  5466. * merge_token_list
  5467. * This is a list of token attribute structures for those tokens
  5468. * that were successfully merged into the domain information base. It
  5469. * will be used to issue the merge tokens confirm downward.
  5470. * purge_token_list
  5471. * This is a list of token IDs for those tokens that were not
  5472. * successfully merged into the domain information base. It will be
  5473. * used to issue the merge tokens confirm downward.
  5474. *
  5475. * Return Value:
  5476. * None.
  5477. *
  5478. * Side Effects:
  5479. * None.
  5480. */
  5481. Void Domain::AddToken (
  5482. PTokenAttributes merge_token,
  5483. CTokenAttributesList *merge_token_list,
  5484. CTokenIDList *purge_token_list)
  5485. {
  5486. TokenState token_state;
  5487. TokenID token_id;
  5488. UserID grabber;
  5489. CUidList *inhibitor_list;
  5490. UserID recipient;
  5491. PToken token;
  5492. UserID uid;
  5493. /*
  5494. * Determine what state the token to be merged is in. Then get the
  5495. * required information for each particular state.
  5496. */
  5497. token_state = merge_token->token_state;
  5498. switch (token_state)
  5499. {
  5500. case TOKEN_GRABBED:
  5501. token_id = merge_token->u.grabbed_token_attributes.token_id;
  5502. grabber = merge_token->u.grabbed_token_attributes.grabber;
  5503. inhibitor_list = NULL;
  5504. recipient = 0;
  5505. break;
  5506. case TOKEN_INHIBITED:
  5507. token_id = merge_token->u.inhibited_token_attributes.token_id;
  5508. grabber = 0;
  5509. inhibitor_list = merge_token->
  5510. u.inhibited_token_attributes.inhibitors;
  5511. recipient = 0;
  5512. break;
  5513. case TOKEN_GIVING:
  5514. token_id = merge_token->u.giving_token_attributes.token_id;
  5515. grabber = merge_token->u.giving_token_attributes.grabber;
  5516. inhibitor_list = NULL;
  5517. recipient = merge_token->u.giving_token_attributes.recipient;
  5518. break;
  5519. case TOKEN_GIVEN:
  5520. token_id = merge_token->u.given_token_attributes.token_id;
  5521. grabber = 0;
  5522. inhibitor_list = NULL;
  5523. recipient = merge_token->u.given_token_attributes.recipient;
  5524. break;
  5525. }
  5526. /*
  5527. * Check to see if it is okay to add this token. If we are the top
  5528. * provider, and adding this token would cause us to exceed the arbitrated
  5529. * limit on tokens, then we must fail the request.
  5530. */
  5531. if ((m_pConnToTopProvider != NULL) ||
  5532. (Number_Of_Tokens < Domain_Parameters.max_token_ids))
  5533. {
  5534. /*
  5535. * Create a new token with all merged values as determined above.
  5536. */
  5537. DBG_SAVE_FILE_LINE
  5538. token = new Token(token_id, this, m_pConnToTopProvider, &m_ChannelList2,
  5539. &m_AttachmentList, token_state, grabber, inhibitor_list, recipient);
  5540. if (token != NULL)
  5541. {
  5542. /*
  5543. * If the creation was successful, add the token to the list and
  5544. * add the token attributes structure to the merge token list.
  5545. */
  5546. TRACE_OUT(("Domain::AddToken: add new token ID = %04X", (UINT) token_id));
  5547. if(m_TokenList2.Append(token_id, token))
  5548. {
  5549. Number_Of_Tokens++;
  5550. merge_token_list->Append(merge_token);
  5551. }
  5552. else
  5553. {
  5554. delete token;
  5555. }
  5556. }
  5557. else
  5558. {
  5559. /*
  5560. * The token allocation has failed. It is therefore necessary to
  5561. * perform some cleanup operations.
  5562. */
  5563. WARNING_OUT (("Domain::AddToken: token allocation failed"));
  5564. /*
  5565. * Check to see if this is the top provider. If not, then it
  5566. * is necessary to issue appropriate requests upward to free the
  5567. * token from the information bases above.
  5568. */
  5569. if (m_pConnToTopProvider != NULL)
  5570. {
  5571. /*
  5572. * Determine which state the token is in. This affects how
  5573. * the cleanup needs to work.
  5574. */
  5575. switch (token_state)
  5576. {
  5577. case TOKEN_GRABBED:
  5578. /*
  5579. * If the token is grabbed, then issue a release to
  5580. * free it above.
  5581. */
  5582. m_pConnToTopProvider->TokenReleaseRequest(grabber, token_id);
  5583. break;
  5584. case TOKEN_INHIBITED:
  5585. {
  5586. /*
  5587. * Iterate through the inhibitor list, issuing a
  5588. * release request for each user contained therein.
  5589. * This will result in the token being freed at all
  5590. * upward providers.
  5591. */
  5592. inhibitor_list->Reset();
  5593. while (NULL != (uid = inhibitor_list->Iterate()))
  5594. {
  5595. m_pConnToTopProvider->TokenReleaseRequest(uid, token_id);
  5596. }
  5597. }
  5598. break;
  5599. case TOKEN_GIVING:
  5600. /*
  5601. * If the token is being given from one user to
  5602. * another, issue a release on behalf of the current
  5603. * owner, and a rejected give response on behalf
  5604. * of the recipient.
  5605. *
  5606. * WARNING:
  5607. * This will cause the current owner to receive a
  5608. * release confirm with no outstanding request.
  5609. */
  5610. m_pConnToTopProvider->TokenReleaseRequest(grabber, token_id);
  5611. m_pConnToTopProvider->TokenGiveResponse(RESULT_USER_REJECTED,
  5612. recipient, token_id);
  5613. break;
  5614. case TOKEN_GIVEN:
  5615. /*
  5616. * Issue a rejected give response on behalf of the
  5617. * user that is being offered the token.
  5618. */
  5619. m_pConnToTopProvider->TokenGiveResponse(RESULT_USER_REJECTED,
  5620. recipient, token_id);
  5621. break;
  5622. }
  5623. }
  5624. /*
  5625. * Add the token ID to the purge token list, which will be passed
  5626. * downward to the former top provider of the lower domain. This
  5627. * will tell that provider that the token was NOT accepted in the
  5628. * upper domain.
  5629. */
  5630. purge_token_list->Append(token_id);
  5631. }
  5632. }
  5633. else
  5634. {
  5635. /*
  5636. * The upper domain already has the domain limit of tokens. So
  5637. * automatically reject the merge request.
  5638. */
  5639. ERROR_OUT(("Domain::AddToken: too many tokens - rejecting merge"));
  5640. purge_token_list->Append(token_id);
  5641. }
  5642. }
  5643. /*
  5644. * Void CalculateDomainHeight ()
  5645. *
  5646. * Private
  5647. *
  5648. * Functional Description:
  5649. * This function is called whenever an event occurs that could have
  5650. * resulted in a change in the overall height of the domain. This includes
  5651. * making and breaking connections, and the reception of an erect domain
  5652. * request from a lower provider.
  5653. *
  5654. * This routine will adjust the height of the current provider, and if
  5655. * this is the top provider, will take necessary steps to insure that the
  5656. * arbitrated domain parameters are not violated.
  5657. *
  5658. * Formal Parameters:
  5659. * None.
  5660. *
  5661. * Return Value:
  5662. * None.
  5663. *
  5664. * Side Effects:
  5665. * None.
  5666. */
  5667. Void Domain::CalculateDomainHeight ()
  5668. {
  5669. UINT_PTR domain_height;
  5670. UINT_PTR temp_domain_height;
  5671. CAttachment *pAtt;
  5672. /*
  5673. * Initialize domain height to zero. This will only be increased if there
  5674. * is at least one remote attachment below this one.
  5675. */
  5676. domain_height = 0;
  5677. /*
  5678. * Check to see if there is anyone below this provider that would affect
  5679. * its height in the domain (this would be remote attachments that have
  5680. * issued ErectDomainRequests to tell this provider of their height).
  5681. */
  5682. if (m_DomainHeightList2.IsEmpty() == FALSE)
  5683. {
  5684. /*
  5685. * Iterate through the domain height list to determine which downward
  5686. * attachment has the greatest height. This is the height that will be
  5687. * used to determine height of this provider.
  5688. */
  5689. m_DomainHeightList2.Reset();
  5690. while (NULL != (temp_domain_height = m_DomainHeightList2.Iterate()))
  5691. {
  5692. if (domain_height < temp_domain_height)
  5693. domain_height = temp_domain_height;
  5694. }
  5695. /*
  5696. * The height of this provider is one greater than the height of its
  5697. * highest downward attachment.
  5698. */
  5699. domain_height++;
  5700. }
  5701. /*
  5702. * Compare the calculated domain height with the current domain height.
  5703. * If they are the same, then no further action needs to be taken.
  5704. */
  5705. if (domain_height != m_nDomainHeight)
  5706. {
  5707. TRACE_OUT(("Domain::CalculateDomainHeight: new domain height = %d", (UINT) domain_height));
  5708. m_nDomainHeight = domain_height;
  5709. /*
  5710. * The domain height has changed. We need to verify that the
  5711. * arbitrated domain height has not been violated.
  5712. */
  5713. if (m_nDomainHeight > Domain_Parameters.max_height)
  5714. {
  5715. /*
  5716. * The new domain height is invalid. We must issue a plumb
  5717. * domain indication downward to enforce the arbitrated
  5718. * domain height.
  5719. */
  5720. TRACE_OUT(("Domain::CalculateDomainHeight: issuing plumb domain indication"));
  5721. m_AttachmentList.Reset();
  5722. while (NULL != (pAtt = m_AttachmentList.Iterate()))
  5723. {
  5724. pAtt->PlumbDomainIndication(Domain_Parameters.max_height);
  5725. }
  5726. }
  5727. /*
  5728. * If this is not the Top Provider, then it is necessary to transmit an
  5729. * erect domain request upward to inform the upper domain of the
  5730. * change.
  5731. */
  5732. if (m_pConnToTopProvider != NULL)
  5733. {
  5734. /*
  5735. * Issue an erect domain request upward to inform the upper
  5736. * domain of the change in height. Without this, the Top Provider
  5737. * would have no way of determining when the domain height is
  5738. * invalid.
  5739. */
  5740. m_pConnToTopProvider->ErectDomainRequest(m_nDomainHeight, DEFAULT_THROUGHPUT_ENFORCEMENT_INTERVAL);
  5741. }
  5742. }
  5743. }
  5744. PUser CAttachmentList::IterateUser(void)
  5745. {
  5746. CAttachment *pAtt;
  5747. while (NULL != (pAtt = Iterate()))
  5748. {
  5749. if (pAtt->IsUserAttachment())
  5750. {
  5751. return (PUser) pAtt;
  5752. }
  5753. }
  5754. return NULL;
  5755. }
  5756. PConnection CAttachmentList::IterateConn(void)
  5757. {
  5758. CAttachment *pAtt;
  5759. while (NULL != (pAtt = Iterate()))
  5760. {
  5761. if (pAtt->IsConnAttachment())
  5762. {
  5763. return (PConnection) pAtt;
  5764. }
  5765. }
  5766. return NULL;
  5767. }
  5768.