Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1505 lines
35 KiB

  1. /**********************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1990, 1991 **/
  4. /**********************************************************************/
  5. /*
  6. sessions.cxx
  7. Class declarations for the SESSIONS_DIALOG, SESSIONS_LISTBOX, and
  8. SESSIONS_LBI classes.
  9. These classes implement the AFP Server Manager Users subproperty
  10. sheet. The SESSIONS_LISTBOX/SESSIONS_LBI classes implement the listbox
  11. which shows the connected users. SESSIONS_DIALOG implements the
  12. actual dialog box.
  13. FILE HISTORY:
  14. NarenG Stole from Server Manager
  15. */
  16. #define INCL_NET
  17. #define INCL_NETLIB
  18. #define INCL_WINDOWS
  19. #define INCL_WINDOWS_GDI
  20. #define INCL_NETERRORS
  21. #define INCL_DOSERRORS
  22. #include <lmui.hxx>
  23. #define INCL_BLT_MSGPOPUP
  24. #define INCL_BLT_WINDOW
  25. #define INCL_BLT_DIALOG
  26. #define INCL_BLT_CONTROL
  27. #define INCL_BLT_MISC
  28. #define INCL_BLT_CLIENT
  29. #include <blt.hxx>
  30. #if defined(DEBUG)
  31. static const CHAR szFileName[] = __FILE__;
  32. #define _FILENAME_DEFINED_ONCE szFileName
  33. #endif // DEBUG
  34. #include <uiassert.hxx>
  35. #include <dbgstr.hxx>
  36. #include <lmsrvres.hxx>
  37. #include <ctime.hxx>
  38. #include <intlprof.hxx>
  39. extern "C"
  40. {
  41. #include <afpmgr.h>
  42. #include <macfile.h>
  43. } // extern "C"
  44. #include <ellipsis.hxx>
  45. #include <bltnslt.hxx>
  46. #include <sessions.hxx>
  47. #include <util.hxx>
  48. #include <senddlg.hxx>
  49. //
  50. // min/max macros
  51. //
  52. #define min(x,y) (((x) < (y)) ? (x) : (y))
  53. #define max(x,y) (((x) > (y)) ? (x) : (y))
  54. //
  55. // SESSIONS_DIALOG methods
  56. //
  57. /*******************************************************************
  58. NAME: SESSIONS_DIALOG :: SESSIONS_DIALOG
  59. SYNOPSIS: SESSIONS_DIALOG class constructor.
  60. ENTRY: hWndOwner - The owning window.
  61. EXIT: The object is constructed.
  62. RETURNS: No return value.
  63. NOTES:
  64. HISTORY:
  65. NarenG Stole from Server Manager
  66. ********************************************************************/
  67. SESSIONS_DIALOG :: SESSIONS_DIALOG( HWND hWndOwner,
  68. AFP_SERVER_HANDLE hServer,
  69. const TCHAR * pszServerName )
  70. : DIALOG_WINDOW( MAKEINTRESOURCE( IDD_USER_CONNECTIONS ), hWndOwner ),
  71. _sltUsersConnected( this, IDUC_DT_USERS_CONNECTED ),
  72. _pbDisc( this, IDUC_PB_DISCONNECT ),
  73. _pbDiscAll( this, IDUC_PB_DISCONNECT_ALL ),
  74. _pbSendMessage( this, IDUC_PB_SEND_MESSAGE ),
  75. _pbOK( this, IDOK ),
  76. _lbSessions( this, IDUC_LB_USER_CONNLIST, hServer ),
  77. _lbResources( this, IDUC_LB_VOLUMES, hServer ),
  78. _pszServerName( pszServerName ),
  79. _hServer( hServer )
  80. {
  81. //
  82. // Let's make sure everything constructed OK.
  83. //
  84. if( QueryError() != NERR_Success )
  85. {
  86. return;
  87. }
  88. //
  89. // Set the caption.
  90. //
  91. APIERR err = ::SetCaption( this, IDS_CAPTION_USERS, pszServerName );
  92. if( err != NERR_Success )
  93. {
  94. ReportError( err );
  95. return;
  96. }
  97. err = BASE_ELLIPSIS::Init();
  98. if( err != NO_ERROR )
  99. {
  100. ReportError( err );
  101. return;
  102. }
  103. //
  104. // Fill the users Listbox.
  105. //
  106. err = Refresh();
  107. if( err != NO_ERROR )
  108. {
  109. ReportError( AFPERR_TO_STRINGID( err ));
  110. return;
  111. }
  112. } // SESSIONS_DIALOG :: SESSIONS_DIALOG
  113. /*******************************************************************
  114. NAME: SESSIONS_DIALOG :: ~SESSIONS_DIALOG
  115. SYNOPSIS: SESSIONS_DIALOG class destructor.
  116. EXIT: The object is destroyed.
  117. HISTORY:
  118. NarenG 02-Oct-1993 Stole from Server Manager and folded
  119. BASE_RES_DIALOG and FILES_DIALOG into one.
  120. ********************************************************************/
  121. SESSIONS_DIALOG :: ~SESSIONS_DIALOG()
  122. {
  123. BASE_ELLIPSIS::Term();
  124. } // SESSIONS_DIALOG :: ~SESSIONS_DIALOG
  125. /*******************************************************************
  126. NAME: SESSIONS_DIALOG :: Refresh
  127. SYNOPSIS: Refresh the dialog.
  128. EXIT: The dialog is feeling refreshed.
  129. RETURNS: DWORD - Any errors encountered.
  130. HISTORY:
  131. NarenG Stole from Server Manager
  132. ********************************************************************/
  133. DWORD SESSIONS_DIALOG :: Refresh( VOID )
  134. {
  135. //
  136. // This is the currently selected item.
  137. //
  138. SESSIONS_LBI * plbiOld = _lbSessions.QueryItem();
  139. DWORD dwSessionIdOld = ( plbiOld == NULL ) ? 0 : plbiOld->QuerySessionId();
  140. //
  141. // Refresh the user listbox.
  142. //
  143. DWORD err = _lbSessions.Refresh();
  144. if( err != NO_ERROR )
  145. {
  146. //
  147. // There was an error refreshing the sessions listbox.
  148. // So, nuke everything in the sessions and volumes listboxen,
  149. // then disable the Disconnect[All] buttons.
  150. //
  151. _lbResources.DeleteAllItems();
  152. _lbResources.Invalidate( TRUE );
  153. _lbSessions.DeleteAllItems();
  154. _lbSessions.Invalidate( TRUE );
  155. _pbDisc.Enable( FALSE );
  156. _pbDiscAll.Enable( FALSE );
  157. _sltUsersConnected.SetText( SZ("??") );
  158. _sltUsersConnected.Enable( FALSE );
  159. return err;
  160. }
  161. //
  162. // Get the "new" currently selected item (after the refresh).
  163. //
  164. SESSIONS_LBI * plbiNew = _lbSessions.QueryItem();
  165. DWORD dwSessionIdNew = (plbiNew == NULL) ? 0 : plbiNew->QuerySessionId();
  166. if( plbiNew == NULL )
  167. {
  168. //
  169. // There is no current selection, so clear the resource listbox.
  170. //
  171. err = _lbResources.Refresh( 0 );
  172. }
  173. else
  174. if( ( plbiOld == NULL ) || ( dwSessionIdOld != dwSessionIdNew ) )
  175. {
  176. //
  177. // Either there was no selection before the refresh, OR
  178. // the current selection does not match the previous
  179. // selection. Therefore, fill the resource listbox with
  180. // the current selection.
  181. //
  182. err = _lbResources.Refresh( plbiNew->QuerySessionId() );
  183. }
  184. else
  185. {
  186. //
  187. // There was no selection change after refresh. Therefore,
  188. // refresh the resource listbox.
  189. //
  190. err = _lbResources.Refresh( plbiNew->QuerySessionId() );
  191. }
  192. if ( _lbSessions.QuerySelCount() > 0 )
  193. {
  194. _pbDisc.Enable( TRUE );
  195. _pbSendMessage.Enable( TRUE );
  196. }
  197. else
  198. {
  199. if ( _pbDisc.HasFocus() )
  200. {
  201. _pbOK.ClaimFocus();
  202. }
  203. if ( _pbSendMessage.HasFocus() )
  204. {
  205. _pbOK.ClaimFocus();
  206. }
  207. _pbDisc.Enable( FALSE );
  208. _pbSendMessage.Enable( FALSE );
  209. }
  210. if ( _lbSessions.QueryCount() > 0 )
  211. {
  212. _pbDiscAll.Enable( TRUE );
  213. }
  214. else
  215. {
  216. if ( _pbDiscAll.HasFocus() )
  217. {
  218. _pbOK.ClaimFocus();
  219. }
  220. _pbDiscAll.Enable( FALSE );
  221. }
  222. _sltUsersConnected.Enable( TRUE );
  223. _sltUsersConnected.SetValue( _lbSessions.QueryCount() );
  224. return err;
  225. } // SESSIONS_DIALOG :: Refresh
  226. /*******************************************************************
  227. NAME: SESSIONS_DIALOG :: OnCommand
  228. SYNOPSIS: Handle user commands.
  229. ENTRY: cid - Control ID.
  230. lParam - lParam from the message.
  231. EXIT: None.
  232. RETURNS: BOOL - TRUE if we handled the msg.
  233. FALSE if we didn't.
  234. NOTES:
  235. HISTORY:
  236. NarenG Stole from Server Manager
  237. ********************************************************************/
  238. BOOL SESSIONS_DIALOG :: OnCommand( const CONTROL_EVENT & event )
  239. {
  240. if( event.QueryCid() == _lbSessions.QueryCid() )
  241. {
  242. //
  243. // The SESSIONS_LISTBOX is trying to tell us something...
  244. //
  245. if( event.QueryCode() == LBN_SELCHANGE )
  246. {
  247. //
  248. // The user changed the selection in the SESSIONS_LISTBOX.
  249. //
  250. SESSIONS_LBI * plbi = _lbSessions.QueryItem();
  251. UIASSERT( plbi != NULL );
  252. DWORD err = _lbResources.Refresh( plbi->QuerySessionId() );
  253. if ( err == NO_ERROR )
  254. {
  255. //
  256. // Make sure that the total number of opens in the
  257. // resource listbox appears in the selected user's listbox item.
  258. //
  259. plbi->SetNumOpens( _lbResources.QueryNumOpens() );
  260. _lbSessions.InvalidateItem( _lbSessions.QueryCurrentItem(),
  261. TRUE );
  262. }
  263. else
  264. Refresh();
  265. }
  266. return TRUE;
  267. }
  268. //
  269. // The user wants to blow away the selected user
  270. //
  271. if( event.QueryCid() == _pbDisc.QueryCid() )
  272. {
  273. //
  274. // The user pressed the Disconnect button. Blow off the
  275. // selected user.
  276. //
  277. SESSIONS_LBI * plbi = _lbSessions.QueryItem();
  278. UIASSERT( plbi != NULL );
  279. if ( MsgPopup( this,
  280. ( plbi->QueryNumOpens() > 0 ) ? IDS_DISCONNECT_SESS_OPEN
  281. : IDS_DISCONNECT_SESS,
  282. MPSEV_WARNING,
  283. MP_YESNO,
  284. plbi->QueryUserName(),
  285. MP_NO ) == IDYES )
  286. {
  287. AUTO_CURSOR Cursor;
  288. //
  289. // Blow off the user.
  290. //
  291. DWORD err = ::AfpAdminSessionClose( _hServer,
  292. plbi->QuerySessionId() );
  293. if( err != NO_ERROR )
  294. {
  295. //
  296. // The session delete failed. Tell the user the bad news.
  297. //
  298. if ( err == AFPERR_InvalidId )
  299. {
  300. ::MsgPopup( this, IDS_SESSION_DELETED );
  301. }
  302. else
  303. {
  304. ::MsgPopup( this, AFPERR_TO_STRINGID( err ) );
  305. }
  306. }
  307. //
  308. // Refresh the dialog.
  309. //
  310. Refresh();
  311. }
  312. return TRUE;
  313. }
  314. //
  315. // The user wants to disconnect all the users
  316. //
  317. if( event.QueryCid() == _pbDiscAll.QueryCid() )
  318. {
  319. //
  320. // The user pressed the Disconnect All button. Blow off the
  321. // users.
  322. //
  323. if ( MsgPopup( this,
  324. ( _lbSessions.AreResourcesOpen() ) ?
  325. IDS_DISCONNECT_SESS_ALL_OPEN
  326. : IDS_DISCONNECT_SESS_ALL,
  327. MPSEV_WARNING,
  328. MP_YESNO,
  329. MP_NO ) == IDYES )
  330. {
  331. AUTO_CURSOR Cursor;
  332. //
  333. // Blow off all users. SessionId of 0 will do the trick
  334. //
  335. DWORD err = ::AfpAdminSessionClose( _hServer, 0 );
  336. if( err != NERR_Success )
  337. {
  338. //
  339. // The session delete failed. Tell the user the bad news.
  340. //
  341. MsgPopup( this, AFPERR_TO_STRINGID( err ) );
  342. }
  343. //
  344. // Kill the Resource Listbox.
  345. //
  346. _lbResources.DeleteAllItems();
  347. _lbResources.Invalidate( TRUE );
  348. //
  349. // Refresh the dialog.
  350. //
  351. Refresh();
  352. }
  353. return TRUE;
  354. }
  355. //
  356. // Does the user want to send a message ?
  357. //
  358. if( event.QueryCid() == _pbSendMessage.QueryCid() )
  359. {
  360. SESSIONS_LBI * plbi = _lbSessions.QueryItem();
  361. UIASSERT( plbi != NULL );
  362. _pbSendMessage.Enable( _lbSessions.QuerySelCount() > 0 );
  363. SEND_MSG_USER_DIALOG * pDlg = new SEND_MSG_USER_DIALOG(
  364. QueryHwnd(),
  365. _hServer,
  366. _pszServerName,
  367. plbi->QueryUserName(),
  368. plbi->QuerySessionId() );
  369. DWORD err = ( pDlg == NULL ) ? ERROR_NOT_ENOUGH_MEMORY
  370. : pDlg->Process();
  371. if( err != NERR_Success )
  372. {
  373. MsgPopup( this, AFPERR_TO_STRINGID( err ) );
  374. }
  375. delete pDlg;
  376. RepaintNow();
  377. Refresh();
  378. return TRUE;
  379. }
  380. return DIALOG_WINDOW :: OnCommand( event );
  381. } // SESSIONS_DIALOG :: OnCommand
  382. /*******************************************************************
  383. NAME: SESSIONS_DIALOG :: QueryHelpContext
  384. SYNOPSIS: This function returns the appropriate help context
  385. value (HC_*) for this particular dialog.
  386. RETURNS: ULONG - The help context for this
  387. dialog.
  388. HISTORY:
  389. NarenG Stole from Server Manager
  390. ********************************************************************/
  391. ULONG SESSIONS_DIALOG :: QueryHelpContext( void )
  392. {
  393. return HC_SESSIONS_DIALOG;
  394. } // SESSIONS_DIALOG :: QueryHelpContext
  395. /*******************************************************************
  396. NAME: SESSIONS_LISTBOX :: SESSIONS_LISTBOX
  397. SYNOPSIS: SESSIONS_LISTBOX class constructor.
  398. ENTRY: powOwner - The owning window.
  399. cid - The listbox CID.
  400. pserver - The target server.
  401. EXIT: The object is constructed.
  402. RETURNS: No return value.
  403. NOTES:
  404. HISTORY:
  405. NarenG Stole from Server Manager
  406. ********************************************************************/
  407. SESSIONS_LISTBOX :: SESSIONS_LISTBOX( OWNER_WINDOW * powner,
  408. CID cid,
  409. AFP_SERVER_HANDLE hServer )
  410. : BLT_LISTBOX( powner, cid ),
  411. _hServer( hServer )
  412. {
  413. //
  414. // Make sure everything constructed properly.
  415. //
  416. if( QueryError() != NERR_Success )
  417. {
  418. return;
  419. }
  420. //
  421. // Retrieve the time separator.
  422. //
  423. NLS_STR nlsTimeSep;
  424. APIERR err;
  425. if( ( err = nlsTimeSep.QueryError() ) != NERR_Success )
  426. {
  427. ReportError( err );
  428. return;
  429. }
  430. INTL_PROFILE intl;
  431. if( ( err = intl.QueryError() ) != NERR_Success )
  432. {
  433. ReportError( err );
  434. return;
  435. }
  436. err = intl.QueryTimeSeparator( &nlsTimeSep );
  437. if( err != NERR_Success )
  438. {
  439. ReportError( err );
  440. return;
  441. }
  442. UIASSERT( nlsTimeSep.QueryTextLength() == 1 );
  443. _chTimeSep = *(nlsTimeSep.QueryPch());
  444. //
  445. // Build our column width table.
  446. //
  447. DISPLAY_TABLE::CalcColumnWidths( _adx,
  448. COLS_UC_LB_USERS,
  449. powner,
  450. cid,
  451. TRUE) ;
  452. } // SESSIONS_LISTBOX :: SESSIONS_LISTBOX
  453. /*******************************************************************
  454. NAME: SESSIONS_LISTBOX :: Refresh
  455. SYNOPSIS: Refresh the listbox, maintaining (as much as
  456. possible) the current selection state.
  457. EXIT: The listbox is feeling refreshed.
  458. RETURNS: DWORD - Any errors we encounter.
  459. HISTORY:
  460. NarenG 02-Oct-1993 Stole from Server Manager and folded
  461. BASE_RES_DIALOG and FILES_DIALOG into one.
  462. ********************************************************************/
  463. DWORD SESSIONS_LISTBOX :: Refresh( VOID )
  464. {
  465. INT iCurrent = QueryCurrentItem();
  466. INT iTop = QueryTopIndex();
  467. DWORD dwCurrentSessionId = 0;
  468. //
  469. // Retrieve the session id of the current selection
  470. //
  471. if ( QuerySelCount() > 0 )
  472. {
  473. dwCurrentSessionId = QueryItem( iCurrent )->QuerySessionId();
  474. }
  475. DWORD err = Fill();
  476. if( err != NO_ERROR )
  477. {
  478. return err;
  479. }
  480. INT cItems = QueryCount();
  481. if( cItems > 0 )
  482. {
  483. INT iSel = -1;
  484. if ( ( iCurrent >= 0 ) && ( iCurrent < cItems ) )
  485. {
  486. //
  487. // iCurrent is still valid, see if this item matches the
  488. // pre-refresh item.
  489. //
  490. if ( dwCurrentSessionId == QueryItem( iCurrent )->QuerySessionId() )
  491. {
  492. iSel = iCurrent;
  493. }
  494. }
  495. if ( iSel < 0 )
  496. {
  497. //
  498. // Either iCurrent was out of range or the item does not
  499. // match so search for it.
  500. //
  501. for ( INT i = 0; i < cItems; i++ )
  502. {
  503. SESSIONS_LBI * plbi = QueryItem( i );
  504. if ( dwCurrentSessionId == plbi->QuerySessionId() )
  505. {
  506. iSel = i;
  507. break;
  508. }
  509. }
  510. }
  511. if ( iSel < 0 )
  512. {
  513. //
  514. // If no selection found then default = first item
  515. //
  516. iSel = 0;
  517. }
  518. //
  519. // If the previous top index is out of range then
  520. // set default = first item.
  521. //
  522. if ( ( iTop < 0 ) || ( iTop >= cItems ) )
  523. {
  524. iTop = 0;
  525. }
  526. SetTopIndex( iTop );
  527. SelectItem( iSel );
  528. }
  529. return NO_ERROR;
  530. } // SESSIONS_LISTBOX :: Refresh
  531. /*******************************************************************
  532. NAME: SESSIONS_LISTBOX :: Fill
  533. SYNOPSIS: Fills the listbox with the available sharepoints.
  534. ENTRY: None.
  535. EXIT: The listbox is filled.
  536. RETURNS: APIERR - Any errors encountered.
  537. NOTES:
  538. HISTORY:
  539. NarenG Stole from Server Manager
  540. ********************************************************************/
  541. DWORD SESSIONS_LISTBOX :: Fill( VOID )
  542. {
  543. //
  544. // Just to be cool...
  545. //
  546. AUTO_CURSOR Cursor;
  547. SetRedraw( FALSE );
  548. DeleteAllItems();
  549. //
  550. // enumerate all sessions
  551. //
  552. PAFP_SESSION_INFO pAfpSessions;
  553. DWORD cEntriesRead;
  554. DWORD cTotalAvail;
  555. DWORD err = AfpAdminSessionEnum( _hServer,
  556. (LPBYTE*)&pAfpSessions,
  557. (DWORD)-1, // Get all sessions
  558. &cEntriesRead,
  559. &cTotalAvail,
  560. NULL );
  561. if( err != NO_ERROR )
  562. {
  563. return ( err ) ;
  564. }
  565. //
  566. // We've got our enumeration, now find all users
  567. //
  568. PAFP_SESSION_INFO pAfpSessionIter = pAfpSessions;
  569. while( ( err == NO_ERROR ) && ( cEntriesRead-- ) )
  570. {
  571. SESSIONS_LBI * pulbi = new SESSIONS_LBI(
  572. pAfpSessionIter->afpsess_id,
  573. pAfpSessionIter->afpsess_username,
  574. pAfpSessionIter->afpsess_ws_name,
  575. pAfpSessionIter->afpsess_num_cons,
  576. pAfpSessionIter->afpsess_num_opens,
  577. pAfpSessionIter->afpsess_time,
  578. _chTimeSep );
  579. if( AddItem( pulbi ) < 0 )
  580. {
  581. err = ERROR_NOT_ENOUGH_MEMORY;
  582. }
  583. pAfpSessionIter++;
  584. }
  585. ::AfpAdminBufferFree( pAfpSessions );
  586. SetRedraw( TRUE );
  587. Invalidate( TRUE );
  588. //
  589. // Success!
  590. //
  591. return NO_ERROR;
  592. } // SESSIONS_LISTBOX :: Fill
  593. /*******************************************************************
  594. NAME: SESSIONS_LISTBOX :: AreResourcesOpen
  595. SYNOPSIS: Returns TRUE if any user in the listbox has any
  596. resources open.
  597. RETURNS: BOOL
  598. HISTORY:
  599. NarenG Stole from Server Manager
  600. ********************************************************************/
  601. BOOL SESSIONS_LISTBOX :: AreResourcesOpen( VOID ) const
  602. {
  603. INT cItems = QueryCount();
  604. for( INT i = 0 ; i < cItems ; i++ )
  605. {
  606. SESSIONS_LBI * plbi = QueryItem( i );
  607. if( plbi->QueryNumOpens() > 0 )
  608. {
  609. return TRUE;
  610. }
  611. }
  612. return FALSE;
  613. } // SESSIONS_LISTBOX :: AreResourcesOpen
  614. /*******************************************************************
  615. NAME: SESSIONS_LBI :: SESSIONS_LBI
  616. SYNOPSIS: SESSIONS_LBI class constructor.
  617. ENTRY: pszShareName - The sharepoint name.
  618. pszPath - The path for this sharepoint.
  619. EXIT: The object is constructed.
  620. RETURNS: No return value.
  621. NOTES:
  622. HISTORY:
  623. NarenG Stole from Server Manager
  624. ********************************************************************/
  625. SESSIONS_LBI :: SESSIONS_LBI( DWORD dwSessionId,
  626. const TCHAR * pszUserName,
  627. const TCHAR * pszComputerName,
  628. DWORD cConnections,
  629. DWORD cOpens,
  630. DWORD dwTime,
  631. TCHAR chTimeSep ) :
  632. _dwSessionId( dwSessionId ),
  633. _dteIcon( IDBM_LB_USER ),
  634. _nlsConnections( cConnections ),
  635. _cOpens( cOpens ),
  636. _nlsOpens( cOpens ),
  637. _nlsUserName(),
  638. _nlsComputerName(),
  639. _nlsTime( dwTime, chTimeSep )
  640. {
  641. //
  642. // Ensure everything constructed properly.
  643. //
  644. if( QueryError() != NERR_Success )
  645. {
  646. return;
  647. }
  648. APIERR err;
  649. if( ( ( err = _nlsConnections.QueryError() ) != NERR_Success ) ||
  650. ( ( err = _nlsOpens.QueryError() ) != NERR_Success ) ||
  651. ( ( err = _nlsComputerName.QueryError() ) != NERR_Success ) ||
  652. ( ( err = _nlsUserName.QueryError() ) != NERR_Success ) ||
  653. ( ( err = _dteIcon.QueryError() ) != NERR_Success ) ||
  654. ( ( err = _nlsTime.QueryError() ) != NERR_Success ) )
  655. {
  656. ReportError( err );
  657. return;
  658. }
  659. //
  660. // If user name is NULL then a guest has loged on
  661. //
  662. if ( pszUserName == NULL )
  663. {
  664. err = _nlsUserName.Load( IDS_GUEST );
  665. }
  666. else
  667. {
  668. err = _nlsUserName.CopyFrom( pszUserName );
  669. }
  670. if ( err == NERR_Success )
  671. {
  672. //
  673. // If the computer name is NULL then the computer name is
  674. // UNKNOWN
  675. //
  676. if ( pszComputerName == NULL )
  677. {
  678. err = _nlsComputerName.Load( IDS_UNKNOWN );
  679. }
  680. else
  681. {
  682. err = _nlsComputerName.CopyFrom( pszComputerName );
  683. }
  684. }
  685. if ( err != NERR_Success )
  686. {
  687. ReportError( err );
  688. return;
  689. }
  690. } // SESSIONS_LBI :: SESSIONS_LBI
  691. /*******************************************************************
  692. NAME: SESSIONS_LBI :: ~SESSIONS_LBI
  693. SYNOPSIS: SESSIONS_LBI class destructor.
  694. ENTRY: None.
  695. EXIT: The object is destroyed.
  696. RETURNS: No return value.
  697. NOTES:
  698. HISTORY:
  699. NarenG Stole from Server Manager
  700. ********************************************************************/
  701. SESSIONS_LBI :: ~SESSIONS_LBI()
  702. {
  703. } // SESSIONS_LBI :: ~SESSIONS_LBI
  704. /*******************************************************************
  705. NAME: SESSIONS_LBI :: SetNumOpens
  706. SYNOPSIS: Sets the number of opens for this entry.
  707. ENTRY: cOpens - The number of open resources.
  708. RETURNS: APIERR - Any errors encountered.
  709. HISTORY:
  710. NarenG Stole from Server Manager
  711. ********************************************************************/
  712. APIERR SESSIONS_LBI :: SetNumOpens( DWORD cOpens )
  713. {
  714. DEC_STR nls( cOpens );
  715. APIERR err = nls.QueryError();
  716. if( err == NERR_Success )
  717. {
  718. _nlsOpens.CopyFrom( nls );
  719. }
  720. return err;
  721. } // SESSIONS_LBI :: SetNumOpens
  722. /*******************************************************************
  723. NAME: SESSIONS_LBI :: Paint
  724. SYNOPSIS: Draw an entry in SESSIONS_LISTBOX.
  725. ENTRY: plb - Pointer to a BLT_LISTBOX.
  726. hdc - The DC to draw upon.
  727. prect - Clipping rectangle.
  728. pGUILTT - GUILTT info.
  729. EXIT: The item is drawn.
  730. RETURNS: No return value.
  731. NOTES:
  732. HISTORY:
  733. NarenG Stole from Server Manager
  734. ********************************************************************/
  735. VOID SESSIONS_LBI :: Paint( LISTBOX * plb,
  736. HDC hdc,
  737. const RECT * prect,
  738. GUILTT_INFO * pGUILTT ) const
  739. {
  740. STR_DTE_ELLIPSIS dteUserName(_nlsUserName.QueryPch(),plb,ELLIPSIS_RIGHT);
  741. STR_DTE_ELLIPSIS dteComputerName( _nlsComputerName.QueryPch(),
  742. plb, ELLIPSIS_RIGHT );
  743. STR_DTE dteConnections( _nlsConnections.QueryPch() );
  744. STR_DTE dteOpens( _nlsOpens.QueryPch() );
  745. STR_DTE dteTime( _nlsTime.QueryPch() );
  746. DISPLAY_TABLE dtab( COLS_UC_LB_USERS,
  747. ( (SESSIONS_LISTBOX *)plb )->QueryColumnWidths() );
  748. dtab[0] = (DTE *)&_dteIcon;
  749. dtab[1] = &dteUserName;
  750. dtab[2] = &dteComputerName;
  751. dtab[3] = &dteOpens;
  752. dtab[4] = &dteTime;
  753. dtab.Paint( plb, hdc, prect, pGUILTT );
  754. } // SESSIONS_LBI :: Paint
  755. /*******************************************************************
  756. NAME: SESSIONS_LBI :: QueryLeadingChar
  757. SYNOPSIS: Returns the first character in the resource name.
  758. This is used for the listbox keyboard interface.
  759. RETURNS: WCHAR - The first character in the
  760. resource name.
  761. HISTORY:
  762. NarenG Stole from Server Manager
  763. ********************************************************************/
  764. WCHAR SESSIONS_LBI :: QueryLeadingChar( VOID ) const
  765. {
  766. ISTR istr( _nlsUserName );
  767. return _nlsUserName.QueryChar( istr );
  768. } // SESSIONS_LBI :: QueryLeadingChar
  769. /*******************************************************************
  770. NAME: SESSIONS_LBI :: Compare
  771. SYNOPSIS: Compare two SESSIONS_LBI items.
  772. ENTRY: plbi - The LBI to compare against.
  773. RETURNS: INT - The result of the compare
  774. ( <0 , ==0 , >0 ).
  775. HISTORY:
  776. NarenG Stole from Server Manager
  777. ********************************************************************/
  778. INT SESSIONS_LBI :: Compare( const LBI * plbi ) const
  779. {
  780. return _nlsUserName._stricmp( ((const SESSIONS_LBI *)plbi)->_nlsUserName );
  781. } // SESSIONS_LBI :: Compare
  782. /*******************************************************************
  783. NAME: RESOURCES_LISTBOX :: RESOURCES_LISTBOX
  784. SYNOPSIS: RESOURCES_LISTBOX class constructor.
  785. ENTRY: powOwner - The owning window.
  786. cid - The listbox CID.
  787. pserver - The target server.
  788. EXIT: The object is constructed.
  789. RETURNS: No return value.
  790. NOTES:
  791. HISTORY:
  792. NarenG Stole from Server Manager
  793. ********************************************************************/
  794. RESOURCES_LISTBOX :: RESOURCES_LISTBOX( OWNER_WINDOW * powner,
  795. CID cid,
  796. AFP_SERVER_HANDLE hserver )
  797. : BLT_LISTBOX( powner, cid, TRUE ),
  798. _hServer( hserver ),
  799. _cOpens( 0 )
  800. {
  801. //
  802. // Make sure everything constructed properly.
  803. //
  804. if( QueryError() != NERR_Success )
  805. {
  806. return;
  807. }
  808. //
  809. // Retrieve the time separator.
  810. //
  811. NLS_STR nlsTimeSep;
  812. if( !nlsTimeSep )
  813. {
  814. ReportError( nlsTimeSep.QueryError() );
  815. return;
  816. }
  817. INTL_PROFILE intl;
  818. if( !intl )
  819. {
  820. ReportError( intl.QueryError() );
  821. return;
  822. }
  823. APIERR err = intl.QueryTimeSeparator( &nlsTimeSep );
  824. if( err != NERR_Success )
  825. {
  826. ReportError( err );
  827. return;
  828. }
  829. UIASSERT( nlsTimeSep.QueryTextLength() == 1 );
  830. _chTimeSep = *(nlsTimeSep.QueryPch());
  831. //
  832. // Build our column width table.
  833. //
  834. DISPLAY_TABLE::CalcColumnWidths( _adx,
  835. COLS_UC_LB_VOLUMES,
  836. powner,
  837. cid,
  838. TRUE) ;
  839. } // RESOURCES_LISTBOX :: RESOURCES_LISTBOX
  840. /*******************************************************************
  841. NAME: RESOURCES_LISTBOX :: Refresh
  842. SYNOPSIS: Refreshes the listbox, maintaining (as much as
  843. possible) the relative position of the current
  844. selection.
  845. EXIT: The listbox is feeling refreshed.
  846. RETURNS: DWORD - Any errors encountered.
  847. HISTORY:
  848. NarenG 02-Oct-1993 Stole from Server Manager and folded
  849. BASE_RES_DIALOG and FILES_DIALOG into one.
  850. ********************************************************************/
  851. DWORD RESOURCES_LISTBOX :: Refresh( DWORD dwSessionId )
  852. {
  853. INT iCurrent = QueryCurrentItem();
  854. INT iTop = QueryTopIndex();
  855. DWORD err = Fill( dwSessionId );
  856. if( err != NO_ERROR )
  857. {
  858. return err;
  859. }
  860. INT cItems = QueryCount();
  861. if( cItems > 0 )
  862. {
  863. iCurrent = min( max( iCurrent, 0 ), cItems - 1 );
  864. iTop = min( max( iTop, 0 ), cItems - 1 );
  865. SelectItem( iCurrent );
  866. SetTopIndex( iTop );
  867. }
  868. return NO_ERROR;
  869. }
  870. /*******************************************************************
  871. NAME: RESOURCES_LISTBOX :: Fill
  872. SYNOPSIS: Fills the listbox with the available sharepoints.
  873. ENTRY: None.
  874. EXIT: The listbox is filled.
  875. RETURNS: DWORD - Any errors encountered.
  876. NOTES:
  877. HISTORY:
  878. NarenG Stole from Server Manager
  879. ********************************************************************/
  880. DWORD RESOURCES_LISTBOX :: Fill( DWORD dwSessionId )
  881. {
  882. //
  883. // Just to be cool...
  884. //
  885. AUTO_CURSOR Cursor;
  886. //
  887. // Nuke the listbox.
  888. //
  889. DeleteAllItems();
  890. //
  891. // If the session Id is zero (a valid scenario) then
  892. // there are no resources in the listbox.
  893. //
  894. if( dwSessionId == 0 )
  895. {
  896. return NO_ERROR;
  897. }
  898. //
  899. // Enumerate the connections to this volume.
  900. //
  901. //
  902. // We enumerate the connections.
  903. //
  904. PAFP_CONNECTION_INFO pAfpConnections;
  905. DWORD cEntriesRead;
  906. DWORD cTotalAvail;
  907. DWORD err = ::AfpAdminConnectionEnum( _hServer,
  908. (LPBYTE*)&pAfpConnections,
  909. AFP_FILTER_ON_SESSION_ID,
  910. dwSessionId,
  911. (DWORD)-1, // Get all conenctions
  912. &cEntriesRead,
  913. &cTotalAvail,
  914. NULL );
  915. //
  916. // See if the connections are available.
  917. //
  918. if( err != NO_ERROR )
  919. {
  920. return err;
  921. }
  922. // Now that we know the connection info is available,
  923. // let's nuke everything in the listbox.
  924. //
  925. SetRedraw( FALSE );
  926. DeleteAllItems();
  927. //
  928. // For iterating the available connections.
  929. //
  930. PAFP_CONNECTION_INFO pAfpConnIter = pAfpConnections;
  931. //
  932. // Iterate the connections adding them to the listbox.
  933. //
  934. _cOpens = 0;
  935. while( ( err == NO_ERROR ) && ( cEntriesRead-- ) )
  936. {
  937. RESOURCES_LBI * prlbi = new RESOURCES_LBI(
  938. pAfpConnIter->afpconn_volumename,
  939. pAfpConnIter->afpconn_num_opens,
  940. pAfpConnIter->afpconn_time,
  941. _chTimeSep );
  942. _cOpens += pAfpConnIter->afpconn_num_opens;
  943. if( AddItem( prlbi ) < 0 )
  944. {
  945. err = ERROR_NOT_ENOUGH_MEMORY;
  946. }
  947. pAfpConnIter++;
  948. }
  949. ::AfpAdminBufferFree( pAfpConnections );
  950. SetRedraw( TRUE );
  951. Invalidate( TRUE );
  952. return err;
  953. } // RESOURCES_LISTBOX :: Fill
  954. /*******************************************************************
  955. NAME: RESOURCES_LBI :: RESOURCES_LBI
  956. SYNOPSIS: RESOURCES_LBI class constructor.
  957. ENTRY: pszResourceName - The sharepoint name.
  958. pszPath - The path for this sharepoint.
  959. EXIT: The object is constructed.
  960. RETURNS: No return value.
  961. NOTES:
  962. HISTORY:
  963. NarenG Stole from Server Manager
  964. ********************************************************************/
  965. RESOURCES_LBI :: RESOURCES_LBI( const TCHAR * pszResourceName,
  966. DWORD cOpens,
  967. DWORD ulTime,
  968. TCHAR chTimeSep ) :
  969. _pdteBitmap( NULL ),
  970. _nlsResourceName( pszResourceName ),
  971. _nlsOpens( cOpens ),
  972. _nlsTime( ulTime, chTimeSep )
  973. {
  974. //
  975. // Ensure everything constructed properly.
  976. //
  977. if( QueryError() != NERR_Success )
  978. {
  979. return;
  980. }
  981. APIERR err;
  982. if( ( ( err = _nlsResourceName.QueryError() ) != NERR_Success ) ||
  983. ( ( err = _nlsOpens.QueryError() ) != NERR_Success ) ||
  984. ( ( err = _nlsTime.QueryError() ) != NERR_Success ) )
  985. {
  986. ReportError( err );
  987. return;
  988. }
  989. _pdteBitmap = new DMID_DTE( IDBM_LB_GOOD_VOLUME );
  990. if( _pdteBitmap == NULL )
  991. {
  992. ReportError( ERROR_NOT_ENOUGH_MEMORY );
  993. return;
  994. }
  995. } // RESOURCES_LBI :: RESOURCES_LBI
  996. /*******************************************************************
  997. NAME: RESOURCES_LBI :: ~RESOURCES_LBI
  998. SYNOPSIS: RESOURCES_LBI class destructor.
  999. ENTRY: None.
  1000. EXIT: The object is destroyed.
  1001. RETURNS: No return value.
  1002. NOTES:
  1003. HISTORY:
  1004. NarenG Stole from Server Manager
  1005. ********************************************************************/
  1006. RESOURCES_LBI :: ~RESOURCES_LBI()
  1007. {
  1008. delete _pdteBitmap;
  1009. _pdteBitmap = NULL;
  1010. } // RESOURCES_LBI :: ~RESOURCES_LBI
  1011. /*******************************************************************
  1012. NAME: RESOURCES_LBI :: Paint
  1013. SYNOPSIS: Draw an entry in RESOURCES_LISTBOX.
  1014. ENTRY: plb - Pointer to a BLT_LISTBOX.
  1015. hdc - The DC to draw upon.
  1016. prect - Clipping rectangle.
  1017. pGUILTT - GUILTT info.
  1018. EXIT: The item is drawn.
  1019. RETURNS: No return value.
  1020. NOTES:
  1021. HISTORY:
  1022. NarenG Stole from Server Manager
  1023. ********************************************************************/
  1024. VOID RESOURCES_LBI :: Paint( LISTBOX * plb,
  1025. HDC hdc,
  1026. const RECT * prect,
  1027. GUILTT_INFO * pGUILTT ) const
  1028. {
  1029. STR_DTE_ELLIPSIS dteResourceName( _nlsResourceName.QueryPch(),
  1030. plb, ELLIPSIS_RIGHT );
  1031. STR_DTE dteOpens( _nlsOpens.QueryPch() );
  1032. STR_DTE dteTime( _nlsTime.QueryPch() );
  1033. DISPLAY_TABLE dtab( COLS_UC_LB_VOLUMES,
  1034. ( (RESOURCES_LISTBOX *)plb )->QueryColumnWidths() );
  1035. dtab[0] = _pdteBitmap;
  1036. dtab[1] = &dteResourceName;
  1037. dtab[2] = &dteOpens;
  1038. dtab[3] = &dteTime;
  1039. dtab.Paint( plb, hdc, prect, pGUILTT );
  1040. } // RESOURCES_LBI :: Paint
  1041. /*******************************************************************
  1042. NAME: RESOURCES_LBI :: QueryLeadingChar
  1043. SYNOPSIS: Returns the first character in the resource name.
  1044. This is used for the listbox keyboard interface.
  1045. RETURNS: WCHAR - The first character in the
  1046. resource name.
  1047. HISTORY:
  1048. NarenG Stole from Server Manager
  1049. ********************************************************************/
  1050. WCHAR RESOURCES_LBI :: QueryLeadingChar( VOID ) const
  1051. {
  1052. ISTR istr( _nlsResourceName );
  1053. return _nlsResourceName.QueryChar( istr );
  1054. } // RESOURCES_LBI :: QueryLeadingChar
  1055. /*******************************************************************
  1056. NAME: RESOURCES_LBI :: Compare
  1057. SYNOPSIS: Compare two RESOURCES_LBI items.
  1058. ENTRY: plbi - The LBI to compare against.
  1059. RETURNS: INT - The result of the compare
  1060. ( <0 , ==0 , >0 ).
  1061. HISTORY:
  1062. NarenG Stole from Server Manager
  1063. ********************************************************************/
  1064. INT RESOURCES_LBI :: Compare( const LBI * plbi ) const
  1065. {
  1066. return _nlsResourceName._stricmp( ((const RESOURCES_LBI *)plbi)->_nlsResourceName );
  1067. } // RESOURCES_LBI :: Compare