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.

84 lines
2.2 KiB

  1. #include <pch.h>
  2. #pragma hdrstop
  3. #include "ssdpsrv.h"
  4. #include "status.h"
  5. #include "ncdefine.h"
  6. #include "ncdebug.h"
  7. #include "server_s.c"
  8. static SERVICE_STATUS serviceStatus;
  9. static SERVICE_STATUS_HANDLE serviceStatusHandle;
  10. DWORD WINAPI ServiceCtrlHandler(DWORD dwControl, DWORD dwEventType,
  11. PVOID pEventData, PVOID pContext);
  12. // Delay load support
  13. //
  14. #include <delayimp.h>
  15. EXTERN_C
  16. FARPROC
  17. WINAPI
  18. DelayLoadFailureHook (
  19. UINT unReason,
  20. PDelayLoadInfo pDelayInfo
  21. );
  22. PfnDliHook __pfnDliFailureHook = DelayLoadFailureHook;
  23. void WINAPI ServiceMain(DWORD argc, LPWSTR *argv)
  24. {
  25. serviceStatus.dwServiceType = SERVICE_WIN32;
  26. serviceStatus.dwCurrentState = SERVICE_START_PENDING;
  27. serviceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
  28. serviceStatus.dwWin32ExitCode = 0;
  29. serviceStatus.dwServiceSpecificExitCode = 0;
  30. serviceStatus.dwCheckPoint = 0;
  31. serviceStatus.dwWaitHint = 0;
  32. serviceStatusHandle = RegisterServiceCtrlHandlerEx("ssdpsrv",
  33. ServiceCtrlHandler,
  34. NULL);
  35. if (serviceStatusHandle == (SERVICE_STATUS_HANDLE) 0)
  36. {
  37. // To-Do: register an event log
  38. goto cleanup;
  39. }
  40. if (SetServiceStatus(serviceStatusHandle, &serviceStatus) == FALSE)
  41. {
  42. // should register an event log .. tbd
  43. goto cleanup;
  44. }
  45. SsdpMain(serviceStatusHandle, &serviceStatus);
  46. cleanup:
  47. serviceStatus.dwCurrentState = SERVICE_STOPPED;
  48. SetServiceStatus(serviceStatusHandle, &serviceStatus);
  49. }
  50. DWORD WINAPI ServiceCtrlHandler(DWORD dwControl, DWORD dwEventType,
  51. PVOID pEventData, PVOID pContext)
  52. {
  53. TraceTag(ttidSsdpRpcIf, "ServiceCtrlHandler: %d\n", dwControl);
  54. switch (dwControl)
  55. {
  56. case SERVICE_CONTROL_SHUTDOWN:
  57. case SERVICE_CONTROL_STOP:
  58. _Shutdown();
  59. serviceStatus.dwCurrentState = SERVICE_STOP_PENDING;
  60. SetServiceStatus(serviceStatusHandle, &serviceStatus);
  61. break;
  62. case SERVICE_CONTROL_INTERROGATE:
  63. SetServiceStatus(serviceStatusHandle, &serviceStatus);
  64. break;
  65. }
  66. return 1;
  67. }