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.

973 lines
28 KiB

  1. #include "testdlg.h"
  2. #include "sapp.h"
  3. VOID
  4. ProcessAdapterEvents (
  5. VOID
  6. );
  7. BOOL
  8. ProcessUpdateEvents (
  9. VOID
  10. );
  11. BOOL CALLBACK
  12. SDBDlgProc (
  13. HWND hDlg,
  14. UINT uMsg,
  15. WPARAM wParam,
  16. LPARAM lParam
  17. );
  18. HINSTANCE hDLL;
  19. HINSTANCE hModule;
  20. HINSTANCE hUtil;
  21. PREGISTER_PROTOCOL RegisterProtocolProc;
  22. PSTART_PROTOCOL StartProtocolProc;
  23. PSTOP_PROTOCOL StopProtocolProc;
  24. PGET_GLOBAL_INFO GetGlobalInfoProc;
  25. PSET_GLOBAL_INFO SetGlobalInfoProc;
  26. PADD_INTERFACE AddInterfaceProc;
  27. PDELETE_INTERFACE DeleteInterfaceProc;
  28. PGET_EVENT_MESSAGE GetEventMessageProc;
  29. PACTIVATE_INTERFACE ActivateInterfaceProc;
  30. PDEACTIVATE_INTERFACE DeactivateInterfaceProc;
  31. PDO_UPDATE_SERVICES DoUpdateServicesProc;
  32. PIS_SERVICE IsServiceProc;
  33. PCREATE_SERVICE_ENUMERATION_HANDLE CreateServiceEnumerationHandleProc;
  34. PENUMERATE_GET_NEXT_SERVICE EnumerateGetNextServiceProc;
  35. PCLOSE_SERVICE_ENUMERATION_HANDLE CloseServiceEnumerationHandleProc;
  36. PCREATE_STATIC_SERVICE CreateStaticServiceProc;
  37. PDELETE_STATIC_SERVICE DeleteStaticServiceProc;
  38. PBLOCK_CONVERT_SERVICES_TO_STATIC BlockConvertServicesToStaticProc;
  39. PBLOCK_DELETE_STATIC_SERVICES BlockDeleteStaticServicesProc;
  40. PGET_FIRST_ORDERED_SERVICE GetFirstOrderedServiceProc;
  41. PGET_NEXT_ORDERED_SERVICE GetNextOrderedServiceProc;
  42. SERVICE_STATUS RouterStatus;
  43. SERVICE_STATUS_HANDLE RouterHdl;
  44. CRITICAL_SECTION RouterLock;
  45. PSVCS_SERVICE_DLL_ENTRY ServiceEntryProc;
  46. HANDLE WaitObjects[2];
  47. #define ConfigEvent (WaitObjects[0])
  48. #define NotificEvent (WaitObjects[1])
  49. HWND SDBDlg=NULL;
  50. VOID RouterMain(
  51. DWORD dwArgc,
  52. LPTSTR *lpszArgv
  53. );
  54. VOID ServiceMain(
  55. DWORD dwArgc, // number of arguments
  56. LPTSTR *lpszArgv // address of array of argument string pointers
  57. );
  58. #define SERVICE_ROUTER TEXT("Router")
  59. HANDLE ConfigPort=INVALID_HANDLE_VALUE;
  60. int _cdecl main (
  61. int argv,
  62. char **argc
  63. ) {
  64. DWORD status;
  65. STARTUPINFO sInfo;
  66. static SERVICE_TABLE_ENTRY svcEntries[] = {
  67. {SERVICE_NWSAP, ServiceMain},
  68. {SERVICE_ROUTER, RouterMain},
  69. {NULL, NULL}
  70. };
  71. HANDLE RMThreadHdl;
  72. DWORD id;
  73. GetStartupInfo (&sInfo);
  74. hModule = LoadLibrary (sInfo.lpTitle);
  75. ASSERTERR (hModule!=NULL);
  76. hUtil = LoadLibrary (TEXT("rtutils.dll"));
  77. ASSERTERR (hUtil!=NULL);
  78. hDLL = LoadLibrary (TEXT("ipxsap.dll"));
  79. ASSERTERR (hDLL!=NULL);
  80. if (StartServiceCtrlDispatcher (svcEntries))
  81. DbgPrint ("Service dispatcher done.\n");
  82. else
  83. DbgPrint ("StartServiceCtrlDispatcher failed (gle:%ld).\n",
  84. GetLastError ());
  85. FreeLibrary (hDLL);
  86. FreeLibrary (hModule);
  87. FreeLibrary (hUtil);
  88. return 0;
  89. }
  90. VOID WINAPI
  91. RouterHandler(
  92. DWORD fdwControl
  93. ) {
  94. DWORD status;
  95. EnterCriticalSection (&RouterLock);
  96. switch (fdwControl) {
  97. case SERVICE_CONTROL_STOP:
  98. case SERVICE_CONTROL_SHUTDOWN:
  99. IpxDeleteAdapterConfigurationPort (ConfigPort);
  100. ResetEvent (ConfigEvent);
  101. ConfigPort = INVALID_HANDLE_VALUE;
  102. status = (*StopProtocolProc) ();
  103. DbgPrint ("Stop protocol returned status %0lx.\n", status);
  104. RouterStatus.dwCurrentState = SERVICE_STOP_PENDING;
  105. // break not put on purpose
  106. case SERVICE_CONTROL_INTERROGATE:
  107. if ((RouterStatus.dwCurrentState==SERVICE_START_PENDING)
  108. || (RouterStatus.dwCurrentState==SERVICE_STOP_PENDING)) {
  109. RouterStatus.dwCheckPoint += 1;
  110. RouterStatus.dwWaitHint = 60;
  111. }
  112. break;
  113. default:
  114. DbgPrint ("Service control handler called with unknown"
  115. " or unsupported code %d.\n", fdwControl);
  116. break;
  117. }
  118. SetServiceStatus (RouterHdl, &RouterStatus);
  119. LeaveCriticalSection (&RouterLock);
  120. }
  121. VOID RouterMain(
  122. DWORD dwArgc,
  123. LPTSTR *lpszArgv
  124. ) {
  125. MSG msg;
  126. DWORD status;
  127. ADAPTERS_GLOBAL_PARAMETERS params;
  128. SAP_GLOBAL_INFO sapGlobalInfo;
  129. ULONG ProtID;
  130. DWORD Funct;
  131. InitializeCriticalSection (&RouterLock);
  132. RouterHdl = RegisterServiceCtrlHandler (SERVICE_ROUTER, &RouterHandler);
  133. if (RouterHdl) {
  134. EnterCriticalSection (&RouterLock);
  135. RouterStatus.dwServiceType = SERVICE_WIN32_SHARE_PROCESS;
  136. RouterStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP
  137. | SERVICE_ACCEPT_SHUTDOWN;
  138. RouterStatus.dwWin32ExitCode = NO_ERROR;
  139. RouterStatus.dwServiceSpecificExitCode = NO_ERROR;
  140. RouterStatus.dwCheckPoint = 0;
  141. RouterStatus.dwWaitHint = 60;
  142. RouterStatus.dwCurrentState = SERVICE_START_PENDING;
  143. LeaveCriticalSection (&RouterLock);
  144. SetServiceStatus (RouterHdl, &RouterStatus);
  145. RegisterProtocolProc = (PREGISTER_PROTOCOL)
  146. GetProcAddress (hDLL,
  147. REGISTER_PROTOCOL_ENTRY_POINT_STRING);
  148. ASSERTERR (RegisterProtocolProc!=NULL);
  149. StartProtocolProc = (PSTART_PROTOCOL)
  150. GetProcAddress (hDLL,
  151. START_PROTOCOL_ENTRY_POINT_STRING);
  152. ASSERTERR (StartProtocolProc!=NULL);
  153. StopProtocolProc = (PSTOP_PROTOCOL)
  154. GetProcAddress (hDLL,
  155. STOP_PROTOCOL_ENTRY_POINT_STRING);
  156. ASSERTERR (StopProtocolProc!=NULL);
  157. GetGlobalInfoProc = (PGET_GLOBAL_INFO)
  158. GetProcAddress (hDLL,
  159. GET_GLOBAL_INFO_ENTRY_POINT_STRING);
  160. ASSERTERR (GetGlobalInfoProc!=NULL);
  161. SetGlobalInfoProc = (PSET_GLOBAL_INFO)
  162. GetProcAddress (hDLL,
  163. SET_GLOBAL_INFO_ENTRY_POINT_STRING);
  164. ASSERTERR (SetGlobalInfoProc!=NULL);
  165. AddInterfaceProc = (PADD_INTERFACE)
  166. GetProcAddress (hDLL,
  167. ADD_INTERFACE_ENTRY_POINT_STRING);
  168. ASSERTERR (AddInterfaceProc!=NULL);
  169. DeleteInterfaceProc = (PDELETE_INTERFACE)
  170. GetProcAddress (hDLL,
  171. DELETE_INTERFACE_ENTRY_POINT_STRING);
  172. ASSERTERR (DeleteInterfaceProc!=NULL);
  173. GetEventMessageProc = (PGET_EVENT_MESSAGE)
  174. GetProcAddress (hDLL,
  175. GET_EVENT_MESSAGE_ENTRY_POINT_STRING);
  176. ASSERTERR (GetEventMessageProc!=NULL);
  177. ActivateInterfaceProc = (PACTIVATE_INTERFACE)
  178. GetProcAddress (hDLL,
  179. ACTIVATE_INTERFACE_ENTRY_POINT_STRING);
  180. ASSERTERR (ActivateInterfaceProc!=NULL);
  181. DeactivateInterfaceProc = (PDEACTIVATE_INTERFACE)
  182. GetProcAddress (hDLL,
  183. DEACTIVATE_INTERFACE_ENTRY_POINT_STRING);
  184. ASSERTERR (DeactivateInterfaceProc!=NULL);
  185. DoUpdateServicesProc = (PDO_UPDATE_SERVICES)
  186. GetProcAddress (hDLL,
  187. DO_UPDATE_SERVICES_ENTRY_POINT_STRING);
  188. ASSERTERR (DoUpdateServicesProc!=NULL);
  189. IsServiceProc = (PIS_SERVICE)
  190. GetProcAddress (hDLL,
  191. IS_SERVICE_ENTRY_POINT_STRING);
  192. ASSERTERR (IsServiceProc!=NULL);
  193. CreateServiceEnumerationHandleProc = (PCREATE_SERVICE_ENUMERATION_HANDLE)
  194. GetProcAddress (hDLL,
  195. CREATE_SERVICE_ENUMERATION_HANDLE_ENTRY_POINT_STRING);
  196. ASSERTERR (CreateServiceEnumerationHandleProc!=NULL);
  197. EnumerateGetNextServiceProc = (PENUMERATE_GET_NEXT_SERVICE)
  198. GetProcAddress (hDLL,
  199. ENUMERATE_GET_NEXT_SERVICE_ENTRY_POINT_STRING);
  200. ASSERTERR (EnumerateGetNextServiceProc!=NULL);
  201. CloseServiceEnumerationHandleProc = (PCLOSE_SERVICE_ENUMERATION_HANDLE)
  202. GetProcAddress (hDLL,
  203. CLOSE_SERVICE_ENUMERATION_HANDLE_ENTRY_POINT_STRING);
  204. ASSERTERR (CloseServiceEnumerationHandleProc!=NULL);
  205. CreateStaticServiceProc = (PCREATE_STATIC_SERVICE)
  206. GetProcAddress (hDLL,
  207. CREATE_STATIC_SERVICE_ENTRY_POINT_STRING);
  208. ASSERTERR (CreateStaticServiceProc!=NULL);
  209. DeleteStaticServiceProc = (PDELETE_STATIC_SERVICE)
  210. GetProcAddress (hDLL,
  211. DELETE_STATIC_SERVICE_ENTRY_POINT_STRING);
  212. ASSERTERR (DeleteStaticServiceProc!=NULL);
  213. BlockConvertServicesToStaticProc = (PBLOCK_CONVERT_SERVICES_TO_STATIC)
  214. GetProcAddress (hDLL,
  215. BLOCK_CONVERT_SERVICES_TO_STATIC_ENTRY_POINT_STRING);
  216. ASSERTERR (BlockConvertServicesToStaticProc!=NULL);
  217. BlockDeleteStaticServicesProc = (PBLOCK_DELETE_STATIC_SERVICES)
  218. GetProcAddress (hDLL,
  219. BLOCK_DELETE_STATIC_SERVICES_ENTRY_POINT_STRING);
  220. ASSERTERR (BlockDeleteStaticServicesProc!=NULL);
  221. GetFirstOrderedServiceProc = (PGET_FIRST_ORDERED_SERVICE)
  222. GetProcAddress (hDLL,
  223. GET_FIRST_ORDERED_SERVICE_ENTRY_POINT_STRING);
  224. ASSERTERR (GetFirstOrderedServiceProc!=NULL);
  225. GetNextOrderedServiceProc = (PGET_NEXT_ORDERED_SERVICE)
  226. GetProcAddress (hDLL,
  227. GET_NEXT_ORDERED_SERVICE_ENTRY_POINT_STRING);
  228. ASSERTERR (GetNextOrderedServiceProc!=NULL);
  229. NotificEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
  230. ASSERTERR (NotificEvent!=NULL);
  231. ConfigEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
  232. ASSERTERR (ConfigEvent!=NULL);
  233. SDBDlg = CreateDialog (hModule,
  234. MAKEINTRESOURCE (IDD_SDB_TEST),
  235. NULL,
  236. &SDBDlgProc);
  237. ASSERTERR (SDBDlg!=NULL);
  238. ConfigPort = IpxCreateAdapterConfigurationPort(
  239. ConfigEvent,
  240. &params);
  241. ASSERT (ConfigPort!=INVALID_HANDLE_VALUE);
  242. status = (*RegisterProtocolProc) (&ProtID, &Funct);
  243. ASSERTMSG ("Error registering SAP dll ", status == NO_ERROR);
  244. ASSERT (ProtID==IPX_PROTOCOL_SAP);
  245. ASSERT (Funct==(SERVICES|DEMAND_UPDATE_SERVICES));
  246. sapGlobalInfo.ServiceFiltersCount = 0;
  247. status = (*StartProtocolProc) (NotificEvent, &sapGlobalInfo);
  248. if (status==NO_ERROR) {
  249. EnterCriticalSection (&RouterLock);
  250. RouterStatus.dwCurrentState = SERVICE_RUNNING;
  251. LeaveCriticalSection (&RouterLock);
  252. SetServiceStatus (RouterHdl, &RouterStatus);
  253. msg.message = 0;
  254. while (msg.message!=WM_QUIT) {
  255. status = MsgWaitForMultipleObjects (2,
  256. WaitObjects,
  257. FALSE,
  258. INFINITE,
  259. QS_ALLINPUT);
  260. if (status==WAIT_OBJECT_0)
  261. ProcessAdapterEvents ();
  262. else if (status==WAIT_OBJECT_0+1) {
  263. ProcessUpdateEvents ();
  264. }
  265. else if (status==(WAIT_OBJECT_0+2)) {
  266. while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) {
  267. if (msg.message==WM_QUIT) {
  268. break;
  269. }
  270. else if (!IsWindow(SDBDlg)
  271. || !IsDialogMessage(SDBDlg, &msg)) {
  272. TranslateMessage (&msg);
  273. DispatchMessage (&msg);
  274. }
  275. }
  276. }
  277. else
  278. DbgPrint ("wait returned status: %ld.", status);
  279. }
  280. }
  281. CloseHandle (ConfigEvent);
  282. CloseHandle (NotificEvent);
  283. RouterStatus.dwCurrentState = SERVICE_STOPPED;
  284. SetServiceStatus (RouterHdl, &RouterStatus);
  285. }
  286. }
  287. VOID ServiceMain(
  288. DWORD dwArgc,
  289. LPTSTR *lpszArgv
  290. ) {
  291. ServiceEntryProc = (PSVCS_SERVICE_DLL_ENTRY)
  292. GetProcAddress (hDLL, SVCS_ENTRY_POINT_STRING);
  293. ASSERTERR (ServiceEntryProc!=NULL);
  294. (*ServiceEntryProc) (dwArgc, lpszArgv, NULL, NULL);
  295. }
  296. VOID
  297. ProcessAdapterEvents (
  298. VOID
  299. ) {
  300. ULONG cfgStatus;
  301. ADAPTER_INFO params;
  302. ULONG idx;
  303. SAP_IF_INFO info;
  304. IPX_ADAPTER_BINDING_INFO adapter;
  305. while (IpxGetQueuedAdapterConfigurationStatus (
  306. ConfigPort,
  307. &idx,
  308. &cfgStatus,
  309. &params)==NO_ERROR) {
  310. switch (cfgStatus) {
  311. case ADAPTER_CREATED:
  312. case ADAPTER_UP:
  313. DbgPrint ("\nNew Adapter : %d.\n", idx);
  314. info.AdminState = ADMIN_STATE_ENABLED;
  315. info.PacketType = IPX_STANDARD_PACKET_TYPE;
  316. if (params.NdisMedium!=NdisMediumWan) {
  317. params.InterfaceIndex = idx;
  318. info.UpdateMode = IPX_STANDARD_UPDATE;
  319. info.Supply = TRUE;
  320. info.Listen = TRUE;
  321. info.GetNearestServerReply = TRUE;
  322. memset (adapter.RemoteNode, 0xFF, sizeof (adapter.RemoteNode));
  323. }
  324. else {
  325. info.UpdateMode = IPX_AUTO_STATIC_UPDATE;
  326. info.Supply = FALSE;
  327. info.Listen = FALSE;
  328. info.GetNearestServerReply = TRUE;
  329. IpxNodeCpy (adapter.RemoteNode, params.RemoteNode);
  330. }
  331. info.EnableGlobalFiltering = FALSE;
  332. adapter.AdapterIndex = idx;
  333. IpxNetCpy (adapter.Network, params.Network);
  334. IpxNodeCpy (adapter.LocalNode, params.LocalNode);
  335. adapter.MaxPacketSize = params.MaxPacketSize;
  336. DbgPrint ("Creating interface: %d.\n", idx);
  337. if ((*AddInterfaceProc) (params.InterfaceIndex,
  338. &info)==NO_ERROR) {
  339. DbgPrint ("Binding interface: %d.\n", idx);
  340. (*ActivateInterfaceProc) (params.InterfaceIndex,
  341. &adapter);
  342. if (info.UpdateMode==IPX_AUTO_STATIC_UPDATE) {
  343. DbgPrint ("Updating interface: %d.",
  344. params.InterfaceIndex);
  345. (*DoUpdateServicesProc)
  346. (params.InterfaceIndex);
  347. }
  348. }
  349. break;
  350. case ADAPTER_DOWN:
  351. case ADAPTER_DELETED:
  352. DbgPrint ("\nAdapter %d is gone - deleting interface.\n", idx);
  353. (*DeleteInterfaceProc) (idx);
  354. break;
  355. }
  356. }
  357. }
  358. BOOL
  359. ProcessUpdateEvents (
  360. VOID
  361. ) {
  362. MESSAGE result;
  363. ROUTING_PROTOCOL_EVENTS event;
  364. TCHAR buf[128];
  365. while ((*GetEventMessageProc) (&event, &result)==NO_ERROR) {
  366. switch (event) {
  367. case ROUTER_STOPPED:
  368. DestroyWindow (SDBDlg);
  369. SDBDlg = NULL;
  370. EnterCriticalSection (&RouterLock);
  371. RouterStatus.dwCurrentState = SERVICE_STOPPED;
  372. LeaveCriticalSection (&RouterLock);
  373. return TRUE;
  374. case UPDATE_COMPLETE:
  375. _stprintf (buf, TEXT ("Update completed on interface: %d")
  376. TEXT(" with status: %d."),
  377. result.UpdateCompleteMessage.InterfaceIndex,
  378. result.UpdateCompleteMessage.UpdateStatus);
  379. MessageBox (SDBDlg,
  380. buf,
  381. TEXT (GET_EVENT_MESSAGE_ENTRY_POINT_STRING),
  382. MB_OK|MB_ICONINFORMATION);
  383. break;
  384. default:
  385. _stprintf (buf, TEXT ("Unknown event reported %ld."), event);
  386. MessageBox (SDBDlg,
  387. buf,
  388. TEXT (GET_EVENT_MESSAGE_ENTRY_POINT_STRING),
  389. MB_OK|MB_ICONEXCLAMATION);
  390. break;
  391. }
  392. }
  393. return FALSE;
  394. }
  395. VOID
  396. PrintServiceToLB (
  397. HWND hLB,
  398. INT idx,
  399. PIPX_SERVICE Service
  400. );
  401. VOID
  402. ReadServiceFromLB (
  403. HWND hLB,
  404. INT idx,
  405. PIPX_SERVICE Service
  406. );
  407. VOID
  408. ReadEnumerationParameters (
  409. HWND hDlg,
  410. DWORD *Order,
  411. DWORD *Flags,
  412. PIPX_SERVICE Service
  413. );
  414. VOID
  415. ReadServiceParameters (
  416. HWND hDlg,
  417. PIPX_SERVICE Service
  418. );
  419. BOOL CALLBACK
  420. SDBDlgProc (
  421. HWND hDlg,
  422. UINT uMsg,
  423. WPARAM wParam,
  424. LPARAM lParam
  425. ) {
  426. BOOL res = FALSE;
  427. IPX_SERVICE Service;
  428. INT idx,i;
  429. HANDLE enumHdl;
  430. DWORD status;
  431. TCHAR buf[64];
  432. DWORD Order, Flags;
  433. RECT rect;
  434. switch (uMsg) {
  435. case WM_INITDIALOG: // Dialog is being created
  436. // Get window a chance to report its MINMAXINFO
  437. GetWindowRect (hDlg, &rect);
  438. MoveWindow (hDlg, rect.left, rect.top, rect.right, rect.bottom, FALSE);
  439. EnableWindow (GetDlgItem (hDlg, IDB_ADD), FALSE);
  440. EnableWindow (GetDlgItem (hDlg, IDB_DELETE), FALSE);
  441. EnableWindow (GetDlgItem (hDlg, IDB_SET_FILTERS), FALSE);
  442. res = TRUE;
  443. break;
  444. case WM_COMMAND: // Process child window messages only
  445. switch (LOWORD(wParam)) {
  446. case IDCANCEL:
  447. res = TRUE;
  448. break;
  449. case IDC_INTERFACE:
  450. EnableWindow (GetDlgItem (hDlg, IDE_INTERFACE_E),
  451. IsDlgButtonChecked (hDlg, LOWORD(wParam)));
  452. EnableWindow (GetDlgItem (hDlg, IDB_BLOCK_CONVERT),
  453. IsDlgButtonChecked (hDlg, LOWORD(wParam)));
  454. EnableWindow (GetDlgItem (hDlg, IDB_BLOCK_DELETE),
  455. IsDlgButtonChecked (hDlg, LOWORD(wParam)));
  456. res = TRUE;
  457. break;
  458. case IDC_PROTOCOL:
  459. EnableWindow (GetDlgItem (hDlg, IDE_PROTOCOL_E),
  460. IsDlgButtonChecked (hDlg, LOWORD(wParam)));
  461. res = TRUE;
  462. break;
  463. case IDC_TYPE:
  464. EnableWindow (GetDlgItem (hDlg, IDE_TYPE_E),
  465. IsDlgButtonChecked (hDlg, LOWORD(wParam)));
  466. res = TRUE;
  467. break;
  468. case IDC_NAME:
  469. EnableWindow (GetDlgItem (hDlg, IDE_NAME_E),
  470. IsDlgButtonChecked (hDlg, LOWORD(wParam)));
  471. res = TRUE;
  472. break;
  473. case IDB_HANDLE_ENUM:
  474. EnableWindow (GetDlgItem (hDlg, IDB_ADD), FALSE);
  475. EnableWindow (GetDlgItem (hDlg, IDB_DELETE), FALSE);
  476. EnableWindow (GetDlgItem (hDlg, IDB_SET_FILTERS), FALSE);
  477. SendDlgItemMessage (hDlg, IDLB_SERVICES, LB_RESETCONTENT, 0, 0);
  478. ReadEnumerationParameters (hDlg, &Order, &Flags, &Service);
  479. enumHdl = (*CreateServiceEnumerationHandleProc) (Flags,
  480. &Service);
  481. if (enumHdl!=NULL) {
  482. while ((status=(*EnumerateGetNextServiceProc) (
  483. enumHdl, &Service))==NO_ERROR) {
  484. PrintServiceToLB (GetDlgItem (hDlg, IDLB_SERVICES), -1, &Service);
  485. }
  486. if (status!=IPX_ERROR_NO_MORE_ITEMS) {
  487. _stprintf (buf, TEXT("Error: %ld."), status);
  488. MessageBox (hDlg, buf,
  489. TEXT(ENUMERATE_GET_NEXT_SERVICE_ENTRY_POINT_STRING),
  490. MB_OK|MB_ICONEXCLAMATION);
  491. }
  492. status = (*CloseServiceEnumerationHandleProc) (enumHdl);
  493. if (status!=NO_ERROR) {
  494. _stprintf (buf, TEXT("Error: %ld."), status);
  495. MessageBox (hDlg, buf,
  496. TEXT(CLOSE_SERVICE_ENUMERATION_HANDLE_ENTRY_POINT_STRING),
  497. MB_OK|MB_ICONEXCLAMATION);
  498. }
  499. }
  500. else {
  501. _stprintf (buf, TEXT("Error: %ld."), GetLastError ());
  502. MessageBox (hDlg, buf,
  503. TEXT(CREATE_SERVICE_ENUMERATION_HANDLE_ENTRY_POINT_STRING),
  504. MB_OK|MB_ICONEXCLAMATION);
  505. }
  506. res = TRUE;
  507. break;
  508. case IDB_MIB_ENUM:
  509. EnableWindow (GetDlgItem (hDlg, IDB_ADD), FALSE);
  510. EnableWindow (GetDlgItem (hDlg, IDB_DELETE), FALSE);
  511. EnableWindow (GetDlgItem (hDlg, IDB_SET_FILTERS), FALSE);
  512. SendDlgItemMessage (hDlg, IDLB_SERVICES, LB_RESETCONTENT, 0, 0);
  513. ReadEnumerationParameters (hDlg, &Order, &Flags, &Service);
  514. status = (*GetFirstOrderedServiceProc) (Order, Flags,
  515. &Service);
  516. while (status==NO_ERROR) {
  517. PrintServiceToLB (GetDlgItem (hDlg, IDLB_SERVICES), -1, &Service);
  518. status = (*GetNextOrderedServiceProc) (Order, Flags,
  519. &Service);
  520. }
  521. if (status!=IPX_ERROR_NO_MORE_ITEMS) {
  522. _stprintf (buf, TEXT("Error: %ld."), status);
  523. MessageBox (hDlg, buf,
  524. TEXT(GET_NEXT_ORDERED_SERVICE_ENTRY_POINT_STRING),
  525. MB_OK|MB_ICONEXCLAMATION);
  526. }
  527. res = TRUE;
  528. break;
  529. case IDB_BLOCK_DELETE:
  530. ReadEnumerationParameters (hDlg, &Order, &Flags, &Service);
  531. status = (*BlockDeleteStaticServicesProc) (
  532. Service.InterfaceIndex);
  533. if (status!=NO_ERROR) {
  534. _stprintf (buf, TEXT("Error: %ld."), status);
  535. MessageBox (hDlg, buf,
  536. TEXT(BLOCK_DELETE_STATIC_SERVICES_ENTRY_POINT_STRING),
  537. MB_OK|MB_ICONEXCLAMATION);
  538. }
  539. res = TRUE;
  540. break;
  541. case IDB_BLOCK_CONVERT:
  542. ReadEnumerationParameters (hDlg, &Order, &Flags, &Service);
  543. status = (*BlockConvertServicesToStaticProc) (
  544. Service.InterfaceIndex);
  545. if (status!=NO_ERROR) {
  546. _stprintf (buf, TEXT("Error: %ld."), status);
  547. MessageBox (hDlg, buf,
  548. TEXT(BLOCK_CONVERT_SERVICES_TO_STATIC_ENTRY_POINT_STRING),
  549. MB_OK|MB_ICONEXCLAMATION);
  550. }
  551. res = TRUE;
  552. break;
  553. case IDB_ADD:
  554. ReadServiceFromLB (GetDlgItem (hDlg, IDLB_SERVICES), idx, &Service);
  555. status = (*CreateStaticServiceProc) (
  556. Service.InterfaceIndex,
  557. &Service.Server);
  558. if (status!=NO_ERROR) {
  559. _stprintf (buf, TEXT("Error: %ld."), status);
  560. MessageBox (hDlg, buf,
  561. TEXT(CREATE_STATIC_SERVICE_ENTRY_POINT_STRING),
  562. MB_OK|MB_ICONEXCLAMATION);
  563. }
  564. res = TRUE;
  565. break;
  566. case IDB_DELETE:
  567. ReadServiceFromLB (GetDlgItem (hDlg, IDLB_SERVICES), idx, &Service);
  568. status = (*DeleteStaticServiceProc) (
  569. Service.InterfaceIndex,
  570. &Service.Server);
  571. if (status!=NO_ERROR) {
  572. _stprintf (buf, TEXT("Error: %ld."), status);
  573. MessageBox (hDlg, buf,
  574. TEXT(DELETE_STATIC_SERVICE_ENTRY_POINT_STRING),
  575. MB_OK|MB_ICONEXCLAMATION);
  576. }
  577. res = TRUE;
  578. break;
  579. case IDB_SET_FILTERS:
  580. idx = SendMessage (GetDlgItem (hDlg, IDLB_SERVICES),
  581. LB_GETSELCOUNT, 0, 0);
  582. if (idx>0) {
  583. LPINT items;
  584. PSAP_GLOBAL_INFO sapGlobalInfo =
  585. (PSAP_GLOBAL_INFO)GlobalAlloc (GMEM_FIXED,
  586. FIELD_OFFSET (SAP_GLOBAL_INFO,SapServiceFilter)+
  587. sizeof (SAP_SERVICE_FILTER_INFO)*idx);
  588. if (sapGlobalInfo!=NULL) {
  589. items = (LPINT)sapGlobalInfo;
  590. idx = SendMessage (GetDlgItem (hDlg, IDLB_SERVICES),
  591. LB_GETSELITEMS, (WPARAM)idx, (LPARAM)items);
  592. if (idx!=LB_ERR) {
  593. for (i=idx-1; i>=0; i--)
  594. sapGlobalInfo->SapServiceFilter[i].FilterIndex
  595. = items[i];
  596. for (i=0; i<idx; i++) {
  597. ReadServiceFromLB (
  598. GetDlgItem (hDlg, IDLB_SERVICES),
  599. sapGlobalInfo->SapServiceFilter[i].FilterIndex,
  600. &Service);
  601. sapGlobalInfo->SapServiceFilter[i].ServiceType
  602. =Service.Server.Type;
  603. IpxNameCpy (
  604. sapGlobalInfo->SapServiceFilter[i].ServiceName,
  605. Service.Server.Name);
  606. }
  607. sapGlobalInfo->ServiceFiltersCount = idx;
  608. sapGlobalInfo->ServiceFiltersAction =
  609. IsDlgButtonChecked (hDlg, IDC_ADVERTISE)
  610. ? IPX_SERVICE_FILTER_ADVERTISE
  611. : IPX_SERVICE_FILTER_SUPRESS;
  612. status = (*SetGlobalInfoProc) (sapGlobalInfo);
  613. if (status!=NO_ERROR) {
  614. _stprintf (buf, TEXT("Error: %ld."), status);
  615. MessageBox (hDlg, buf,
  616. TEXT(SET_GLOBAL_INFO_ENTRY_POINT_STRING),
  617. MB_OK|MB_ICONEXCLAMATION);
  618. }
  619. }
  620. else {
  621. MessageBox (hDlg, TEXT("LB_ERR!") ,
  622. TEXT("LB_GETSELITEMS"),
  623. MB_OK|MB_ICONEXCLAMATION);
  624. }
  625. }
  626. else {
  627. _stprintf (buf, TEXT("Error: %ld."), GetLastError ());
  628. MessageBox (hDlg, buf,
  629. TEXT("GlobalAlloc"),
  630. MB_OK|MB_ICONEXCLAMATION);
  631. }
  632. GlobalFree (sapGlobalInfo);
  633. }
  634. else {
  635. MessageBox (hDlg, TEXT("No Items selected"),
  636. TEXT("LB_GETSELCOUNT"),
  637. MB_OK|MB_ICONEXCLAMATION);
  638. }
  639. res = TRUE;
  640. break;
  641. case IDLB_SERVICES:
  642. switch (HIWORD(wParam)) {
  643. case LBN_DBLCLK:
  644. idx = SendMessage ((HWND)lParam, LB_GETCARETINDEX, 0, 0);
  645. if (idx!=LB_ERR) {
  646. ReadServiceFromLB ((HWND)lParam, idx, &Service);
  647. res = (*IsServiceProc) (Service.Server.Type,
  648. Service.Server.Name,
  649. &Service);
  650. if (res) {
  651. SendMessage ((HWND)lParam, LB_DELETESTRING, idx, 0);
  652. PrintServiceToLB ((HWND)lParam, idx, &Service);
  653. }
  654. else {
  655. status = GetLastError ();
  656. if (status!=NO_ERROR) {
  657. _stprintf (buf, TEXT("Error: %ld."), status);
  658. MessageBox (hDlg, buf,
  659. TEXT(IS_SERVICE_ENTRY_POINT_STRING),
  660. MB_OK|MB_ICONEXCLAMATION);
  661. }
  662. }
  663. }
  664. break;
  665. case LBN_SELCHANGE:
  666. idx = SendMessage ((HWND)lParam, LB_GETSELCOUNT, 0, 0);
  667. EnableWindow (GetDlgItem (hDlg, IDB_ADD), idx==1);
  668. EnableWindow (GetDlgItem (hDlg, IDB_DELETE), idx==1);
  669. EnableWindow (GetDlgItem (hDlg, IDB_SET_FILTERS), idx>0);
  670. break;
  671. }
  672. res = TRUE;
  673. break;
  674. }
  675. break;
  676. case WM_SIZE:
  677. GetWindowRect (GetDlgItem (hDlg, IDLB_SERVICES), &rect);
  678. MapWindowPoints (HWND_DESKTOP, hDlg, (POINT *)&rect, 2);
  679. rect.bottom = HIWORD (lParam)-4;
  680. MoveWindow (GetDlgItem (hDlg, IDLB_SERVICES), rect.left, rect.top,
  681. rect.right-rect.left, rect.bottom-rect.top, TRUE);
  682. res = FALSE;
  683. break;
  684. case WM_GETMINMAXINFO:
  685. if (((PMINMAXINFO)lParam)->ptMinTrackSize.x
  686. !=((PMINMAXINFO)lParam)->ptMaxTrackSize.x) {
  687. GetWindowRect (hDlg, &rect);
  688. ((PMINMAXINFO)lParam)->ptMinTrackSize.x = rect.right-rect.left;
  689. ((PMINMAXINFO)lParam)->ptMinTrackSize.y = rect.bottom-rect.top;
  690. ((PMINMAXINFO)lParam)->ptMaxTrackSize.x = rect.right-rect.left;
  691. }
  692. res = FALSE;
  693. break;
  694. case WM_DESTROY:
  695. PostQuitMessage (0);
  696. res = TRUE;
  697. break;
  698. }
  699. return res;
  700. }
  701. VOID
  702. PrintServiceToLB (
  703. HWND hLB,
  704. INT idx,
  705. PIPX_SERVICE Service
  706. ) {
  707. TCHAR buf[128];
  708. _stprintf (buf,
  709. TEXT ("%3d ")
  710. TEXT ("%5X ")
  711. TEXT ("%02X%02X%02X%02X ")
  712. TEXT ("%02X%02X%02X%02X%02X%02X ")
  713. TEXT ("%02X%02X ")
  714. TEXT ("%2d ")
  715. TEXT ("%04X ")
  716. TEXT ("%-47hs"),
  717. Service->InterfaceIndex,
  718. Service->Protocol,
  719. Service->Server.Network[0],
  720. Service->Server.Network[1],
  721. Service->Server.Network[2],
  722. Service->Server.Network[3],
  723. Service->Server.Node[0],
  724. Service->Server.Node[1],
  725. Service->Server.Node[2],
  726. Service->Server.Node[3],
  727. Service->Server.Node[4],
  728. Service->Server.Node[5],
  729. Service->Server.Socket[0],
  730. Service->Server.Socket[1],
  731. Service->Server.HopCount,
  732. Service->Server.Type,
  733. Service->Server.Name);
  734. SendMessage (hLB, LB_INSERTSTRING, (WPARAM)idx, (LPARAM)buf);
  735. }
  736. VOID
  737. ReadServiceFromLB (
  738. HWND hLB,
  739. INT idx,
  740. PIPX_SERVICE Service
  741. ) {
  742. TCHAR buf[128];
  743. SendMessage (hLB, LB_GETTEXT, (WPARAM)idx, (LPARAM)buf);
  744. _stscanf (buf,
  745. TEXT ("%3d ")
  746. TEXT ("%5X ")
  747. TEXT ("%2X%2X%2X%2X ")
  748. TEXT ("%2X%2X%2X%2X%2X%2X ")
  749. TEXT ("%2X%2X ")
  750. TEXT ("%2d ")
  751. TEXT ("%4X ")
  752. TEXT ("%47h[\001-\377]"),
  753. &Service->InterfaceIndex,
  754. &Service->Protocol,
  755. &Service->Server.Network[0],
  756. &Service->Server.Network[1],
  757. &Service->Server.Network[2],
  758. &Service->Server.Network[3],
  759. &Service->Server.Node[0],
  760. &Service->Server.Node[1],
  761. &Service->Server.Node[2],
  762. &Service->Server.Node[3],
  763. &Service->Server.Node[4],
  764. &Service->Server.Node[5],
  765. &Service->Server.Socket[0],
  766. &Service->Server.Socket[1],
  767. &Service->Server.HopCount,
  768. &Service->Server.Type,
  769. &Service->Server.Name);
  770. return;
  771. }
  772. VOID
  773. ReadEnumerationParameters (
  774. HWND hDlg,
  775. DWORD *Order,
  776. DWORD *Flags,
  777. PIPX_SERVICE Service
  778. ) {
  779. TCHAR buf[64];
  780. if (IsDlgButtonChecked (hDlg, IDR_TYPE_NAME))
  781. *Order = STM_ORDER_BY_TYPE_AND_NAME;
  782. else if (IsDlgButtonChecked (hDlg, IDR_INTERFACE))
  783. *Order = STM_ORDER_BY_INTERFACE_TYPE_NAME;
  784. else {
  785. SendDlgItemMessage (hDlg, IDR_TYPE_NAME, BM_SETCHECK, (WPARAM)1, 0);
  786. *Order = STM_ORDER_BY_TYPE_AND_NAME;
  787. }
  788. *Flags = 0;
  789. if (IsDlgButtonChecked (hDlg, IDC_INTERFACE)) {
  790. *Flags |= STM_ONLY_THIS_INTERFACE;
  791. GetDlgItemText (hDlg, IDE_INTERFACE_E, buf, sizeof(buf)/sizeof (TCHAR));
  792. _stscanf (buf, TEXT ("%d"), &Service->InterfaceIndex);
  793. }
  794. if (IsDlgButtonChecked (hDlg, IDC_PROTOCOL)) {
  795. *Flags |= STM_ONLY_THIS_PROTOCOL;
  796. GetDlgItemText (hDlg, IDE_PROTOCOL_E, buf, sizeof(buf)/sizeof (TCHAR));
  797. _stscanf (buf, TEXT ("%x"), &Service->Protocol);
  798. }
  799. if (IsDlgButtonChecked (hDlg, IDC_TYPE)) {
  800. *Flags |= STM_ONLY_THIS_TYPE;
  801. GetDlgItemText (hDlg, IDE_TYPE_E, buf, sizeof(buf)/sizeof (TCHAR));
  802. _stscanf (buf, TEXT ("%hx"), &Service->Server.Type);
  803. }
  804. if (IsDlgButtonChecked (hDlg, IDC_NAME)) {
  805. *Flags |= STM_ONLY_THIS_NAME;
  806. GetDlgItemText (hDlg, IDE_NAME_E, buf, sizeof(buf)/sizeof (TCHAR));
  807. _stscanf (buf, TEXT ("%47h[\001-\277]"), Service->Server.Name);
  808. }
  809. return;
  810. }
  811. /*
  812. VOID
  813. ReadServiceParameters (
  814. HWND hDlg,
  815. PIPX_SERVICE Service
  816. ) {
  817. TCHAR buf[64];
  818. INT n, i;
  819. TCHAR *p;
  820. GetDlgItemText (hDlg, IDE_INTERFACE_M, buf, sizeof(buf)/sizeof (TCHAR));
  821. _stscanf (buf, TEXT ("%x"), &Service->InterfaceIndex);
  822. GetDlgItemText (hDlg, IDE_PROTOCOL_M, buf, sizeof(buf)/sizeof (TCHAR));
  823. _stscanf (buf, TEXT ("%x"), &Service->Protocol);
  824. GetDlgItemText (hDlg, IDE_TYPE_M, buf, sizeof(buf)/sizeof (TCHAR));
  825. _stscanf (buf, TEXT ("%hx"), &Service->Server.Type);
  826. GetDlgItemText (hDlg, IDE_NAME_M, buf, sizeof(buf)/sizeof (TCHAR));
  827. _stscanf (buf, TEXT ("%47h[\001-\277]"), Service->Server.Name);
  828. GetDlgItemText (hDlg, IDE_NETWORK_M, buf, sizeof(buf)/sizeof (TCHAR));
  829. for (i=0, p=buf, n=0; i<sizeof (Service->Server.Network); i++, p+=n) {
  830. INT val;
  831. if (_stscanf (p, TEXT("%2X%n"), &val, &n)==1)
  832. Service->Server.Network[i] = (UCHAR)val;
  833. else
  834. Service->Server.Network[i] = 0;
  835. }
  836. GetDlgItemText (hDlg, IDE_NODE_M, buf, sizeof(buf)/sizeof (TCHAR));
  837. for (i=0, p=buf, n=0; i<sizeof (Service->Server.Node); i++, p+=n) {
  838. INT val;
  839. if (_stscanf (p, TEXT("%2X%n"), &val, &n)==1)
  840. Service->Server.Node[i] = (UCHAR)val;
  841. else
  842. Service->Server.Node[i] = 0;
  843. }
  844. GetDlgItemText (hDlg, IDE_SOCKET_M, buf, sizeof(buf)/sizeof (TCHAR));
  845. for (i=0, p=buf, n=0; i<sizeof (Service->Server.Socket); i++, p+=n) {
  846. INT val;
  847. if (_stscanf (p, TEXT("%2X%n"), &val, &n)==1)
  848. Service->Server.Socket[i] = (UCHAR)val;
  849. else
  850. Service->Server.Socket[i] = 0;
  851. }
  852. GetDlgItemText (hDlg, IDE_HOP_COUNT_M, buf, sizeof(buf)/sizeof (TCHAR));
  853. _stscanf (buf, TEXT ("%hd"), &Service->Server.HopCount);
  854. return;
  855. }
  856. */