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.

520 lines
11 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. smx.cxx
  7. This module contains all the entry points for the Server Manager
  8. extension.
  9. FILE HISTORY:
  10. NarenG 6-Oct-1992 Created.
  11. */
  12. #define INCL_NET
  13. #define INCL_NETLIB
  14. #define INCL_NETSERVICE
  15. #define INCL_WINDOWS
  16. #define INCL_WINDOWS_GDI
  17. #define INCL_NETERRORS
  18. #define INCL_DOSERRORS
  19. #include <lmui.hxx>
  20. #if defined(DEBUG)
  21. static const CHAR szFileName[] = __FILE__;
  22. #define _FILENAME_DEFINED_ONCE szFileName
  23. #endif
  24. #include <uiassert.hxx>
  25. #include <uitrace.hxx>
  26. #define INCL_BLT_WINDOW
  27. #define INCL_BLT_DIALOG
  28. #define INCL_BLT_CONTROL
  29. #define INCL_BLT_CLIENT
  30. #define INCL_BLT_MSGPOPUP
  31. #define INCL_BLT_EVENT
  32. #define INCL_BLT_MISC
  33. #define INCL_BLT_TIMER
  34. #define INCL_BLT_CC
  35. #include <blt.hxx>
  36. #include <dbgstr.hxx>
  37. extern "C"
  38. {
  39. #include <smx.h>
  40. #include <afpmgr.h>
  41. #include <macfile.h>
  42. }
  43. #include <startafp.hxx>
  44. #include <senddlg.hxx>
  45. #include <srvprop.hxx>
  46. #include <volmgt.hxx>
  47. extern "C"
  48. {
  49. //
  50. // Globals.
  51. //
  52. extern HINSTANCE _hInstance;// Exported by the afpmgr.cxx module.
  53. static HWND _hWnd; // Handle to the owner window.
  54. static DWORD _dwVersion; // Will contain the SMX version being used.
  55. static DWORD _dwDelta; // Used to manipulate menu items.
  56. static HMENU _hMenu; // Created at load time.
  57. } // extern "C"
  58. /*******************************************************************
  59. NAME: SMELoadMenu
  60. SYNOPSIS: This entrypoint is to notify the DLL that it
  61. is getting loaded by the Server Manager.
  62. ENTRY: hWnd - The "owning" window.
  63. psmsload - Points to an SMS_LOADMENU
  64. structure containing load
  65. parameters.
  66. RETURNS: DWORD - Actually an APIERR, should be
  67. 0 if successful.
  68. HISTORY:
  69. NarenG 5-Nov-1992 Created.
  70. ********************************************************************/
  71. DWORD PASCAL SMELoadMenuW( HWND hWnd,
  72. PSMS_LOADMENU psmsload )
  73. {
  74. if( psmsload == NULL )
  75. {
  76. return ERROR_INVALID_PARAMETER;
  77. }
  78. //
  79. // Save the handle to the owner window
  80. //
  81. _hWnd = hWnd;
  82. //
  83. // Set the version field to the lower of the our version and the
  84. // Server manager version
  85. //
  86. _dwVersion = SME_VERSION;
  87. if( psmsload->dwVersion > _dwVersion )
  88. {
  89. psmsload->dwVersion = _dwVersion;
  90. }
  91. else
  92. if( psmsload->dwVersion < _dwVersion )
  93. {
  94. _dwVersion = psmsload->dwVersion;
  95. }
  96. //
  97. // Delta to be added to the menu ID before trying to manipulate
  98. // any menu item
  99. //
  100. _dwDelta = psmsload->dwMenuDelta;
  101. //
  102. // Only enumerate AFP type servers
  103. //
  104. psmsload->dwServerType = SV_TYPE_AFP;
  105. RESOURCE_STR nlsMenuName( IDS_AFPMGR_MENU_NAME );
  106. APIERR err;
  107. if ( ( err = nlsMenuName.QueryError() ) != NERR_Success )
  108. {
  109. return err;
  110. }
  111. if ( err = nlsMenuName.MapCopyTo( psmsload->szMenuName,
  112. sizeof(psmsload->szMenuName)))
  113. {
  114. return err;
  115. }
  116. _hMenu = ::LoadMenu(::_hInstance,MAKEINTRESOURCE(ID_SRVMGR_MENU));
  117. if ( _hMenu == NULL )
  118. {
  119. return ::GetLastError();
  120. }
  121. psmsload->hMenu = _hMenu;
  122. RESOURCE_STR nlsHelpFileName( IDS_AFPMGR_HELPFILENAME );
  123. if ( ( err = nlsHelpFileName.QueryError() ) != NERR_Success )
  124. {
  125. return err;
  126. }
  127. if ( err = nlsHelpFileName.MapCopyTo( psmsload->szHelpFileName,
  128. sizeof(psmsload->szHelpFileName)))
  129. {
  130. return err;
  131. }
  132. return NO_ERROR;
  133. } // SMELoadMenu
  134. /*******************************************************************
  135. NAME: SMEGetExtendedErrorString
  136. SYNOPSIS: If SMELoad returns ERROR_EXTENDED_ERROR, then this
  137. entrypoint will be called to retrieve the error
  138. text associated with the failure condition.
  139. RETURNS: LPTSTR - The extended error text.
  140. HISTORY:
  141. NarenG 5-Nov-1992 Created.
  142. ********************************************************************/
  143. LPTSTR PASCAL SMEGetExtendedErrorStringW( VOID )
  144. {
  145. return (TCHAR*)TEXT("");
  146. } // SMEGetExtendedErrorString
  147. /*******************************************************************
  148. NAME: SMEUnloadMenu
  149. SYNOPSIS: Notifies the extension DLL that it is getting unloaded.
  150. HISTORY:
  151. NarenG 5-Nov-1992 Created.
  152. ********************************************************************/
  153. VOID PASCAL SMEUnloadMenu( VOID )
  154. {
  155. //
  156. // This space intentionally left blank.
  157. //
  158. } // SMEUnload
  159. /*******************************************************************
  160. NAME: SMEInitializeMenu
  161. SYNOPSIS: Notifies the DLL that the main menu is
  162. getting activated. Do all menu manipulations here.
  163. HISTORY:
  164. NarenG 5-Nov-1992 Created.
  165. ********************************************************************/
  166. VOID PASCAL SMEInitializeMenu( VOID )
  167. {
  168. //
  169. // If there was no server selected. Disable all the menu items
  170. //
  171. SMS_GETSELCOUNT smsSelCount;
  172. if( ( !SendMessage( _hWnd,
  173. SM_GETSELCOUNT,
  174. 0,
  175. (LPARAM)&smsSelCount ) )
  176. ||
  177. ( smsSelCount.dwItems == 0 ) )
  178. {
  179. EnableMenuItem( _hMenu,
  180. (UINT)(IDM_SEND_MESSAGE+_dwDelta),
  181. (UINT)MF_GRAYED);
  182. EnableMenuItem( _hMenu,
  183. (UINT)(IDM_PROPERTIES+_dwDelta),
  184. (UINT)MF_GRAYED);
  185. EnableMenuItem( _hMenu,
  186. (UINT)(IDM_VOLUME_MGT+_dwDelta),
  187. (UINT)MF_GRAYED);
  188. }
  189. else
  190. {
  191. EnableMenuItem( _hMenu,
  192. (UINT)(IDM_SEND_MESSAGE+_dwDelta),
  193. (UINT)MF_ENABLED);
  194. EnableMenuItem( _hMenu,
  195. (UINT)(IDM_PROPERTIES+_dwDelta),
  196. (UINT)MF_ENABLED);
  197. EnableMenuItem( _hMenu,
  198. (UINT)(IDM_VOLUME_MGT+_dwDelta),
  199. (UINT)MF_ENABLED);
  200. }
  201. return;
  202. } // SMEInitializeMenu
  203. /*******************************************************************
  204. NAME: SMERefresh
  205. SYNOPSIS: Notifies the extension DLL that the user has requested
  206. a refresh. The extension should use this opportunity
  207. to update any cached data.
  208. HISTORY:
  209. NarenG 5-Nov-1992 Created.
  210. ********************************************************************/
  211. VOID PASCAL SMERefresh( HWND hWnd )
  212. {
  213. //
  214. // This space intentionally left blank.
  215. //
  216. } // SMERefresh
  217. /*******************************************************************
  218. NAME: SMEValidate
  219. SYNOPSIS: Called to validate a server that the server manager
  220. does not recognize. We ignore these servers.
  221. HISTORY:
  222. NarenG 5-Nov-1992 Created.
  223. ********************************************************************/
  224. BOOL PASCAL SMEValidateW( PSMS_VALIDATE psmsValidate )
  225. {
  226. return FALSE;
  227. } // SMEValidate
  228. /*******************************************************************
  229. NAME: SMEMenuAction
  230. SYNOPSIS: Notifies the DLL that one of its menu
  231. items has been selected.
  232. ENTRY: dwEventId - The menu ID being activated
  233. (should be 1-99).
  234. HISTORY:
  235. NarenG 5-Nov-1992 Created.
  236. ********************************************************************/
  237. VOID PASCAL SMEMenuAction( HWND hWnd, DWORD dwEventId )
  238. {
  239. DWORD err;
  240. AFP_SERVER_HANDLE hServer = NULL;
  241. AUTO_CURSOR Cursor;
  242. //
  243. // Get the current server selection
  244. //
  245. SMS_GETSERVERSEL2 smsSel;
  246. if( !SendMessage( _hWnd, SM_GETSERVERSEL2, 0, (LPARAM)&smsSel ) )
  247. {
  248. //
  249. // Tell the user the bad news
  250. //
  251. ::MsgPopup( _hWnd,
  252. IDS_COULD_NOT_GET_CURRENT_SEL,
  253. MPSEV_WARNING,
  254. MP_OK );
  255. return;
  256. }
  257. //
  258. // Check if the server focus of the current selection is running AFP
  259. //
  260. BOOL fIsAfpRunning;
  261. if ( ( err = IsAfpServiceRunning( smsSel.szServerName,
  262. &fIsAfpRunning ) ) != NERR_Success )
  263. {
  264. if ( err == IDS_MACFILE_NOT_INSTALLED )
  265. {
  266. ::MsgPopup( _hWnd,
  267. err,
  268. MPSEV_ERROR,
  269. MP_OKCANCEL,
  270. smsSel.szServerName,
  271. MP_OK );
  272. }
  273. else
  274. {
  275. ::MsgPopup( _hWnd, err );
  276. }
  277. return;
  278. }
  279. if ( !fIsAfpRunning )
  280. {
  281. //
  282. // Ask the user if he/she wants to start it.
  283. //
  284. if ( MsgPopup( hWnd,
  285. IDS_START_AFPSERVER_NOW,
  286. MPSEV_WARNING,
  287. MP_YESNO,
  288. MP_YES ) == IDNO )
  289. {
  290. //
  291. // User does not want to start the afpserver so simply return.
  292. //
  293. return;
  294. }
  295. //
  296. // Start the AFP Service
  297. //
  298. err = StartAfpService( hWnd, smsSel.szServerName );
  299. if ( err != NERR_Success )
  300. {
  301. ::MsgPopup( _hWnd, err );
  302. return;
  303. }
  304. }
  305. //
  306. // Set up an RPC conenction with the server
  307. //
  308. if( (err = ::AfpAdminConnect( smsSel.szServerName, &hServer )) != NO_ERROR)
  309. {
  310. ::MsgPopup( _hWnd, err );
  311. return;
  312. }
  313. //
  314. // What does the user want to do with the server ?
  315. //
  316. switch( dwEventId )
  317. {
  318. case IDM_SEND_MESSAGE:
  319. {
  320. //
  321. // Invoke the send message Dialog.
  322. //
  323. SEND_MSG_SERVER_DIALOG * pSendMsgDlg = new SEND_MSG_SERVER_DIALOG(
  324. _hWnd,
  325. hServer,
  326. smsSel.szServerName );
  327. err = ( pSendMsgDlg == NULL ) ? ERROR_NOT_ENOUGH_MEMORY
  328. : pSendMsgDlg->Process();
  329. delete pSendMsgDlg;
  330. break;
  331. }
  332. case IDM_PROPERTIES:
  333. {
  334. //
  335. // Invoke the Main Property Dialog.
  336. //
  337. SERVER_PROPERTIES * pPropDlg = new SERVER_PROPERTIES(
  338. _hWnd,
  339. hServer,
  340. smsSel.szServerName );
  341. err = ( pPropDlg == NULL ) ? ERROR_NOT_ENOUGH_MEMORY
  342. : pPropDlg->Process();
  343. delete pPropDlg;
  344. break;
  345. }
  346. case IDM_VOLUME_MGT:
  347. {
  348. //
  349. // Invoke the volume management dialog
  350. //
  351. VOLUME_MANAGEMENT_DIALOG * pVolMgtDlg = new VOLUME_MANAGEMENT_DIALOG(
  352. _hWnd,
  353. hServer,
  354. smsSel.szServerName );
  355. err = ( pVolMgtDlg == NULL ) ? ERROR_NOT_ENOUGH_MEMORY
  356. : pVolMgtDlg->Process();
  357. delete pVolMgtDlg;
  358. break;
  359. }
  360. default :
  361. {
  362. return;
  363. }
  364. }
  365. if( err != NERR_Success )
  366. {
  367. ::MsgPopup( _hWnd, AFPERR_TO_STRINGID(err) );
  368. }
  369. if ( hServer != NULL )
  370. {
  371. ::AfpAdminDisconnect( hServer );
  372. }
  373. } // SMEMenuAction