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.

152 lines
5.8 KiB

  1. /************************************************************************************************
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name: Pop3SvcMain.cpp
  4. Abstract: Defines the entry-point for the Pop3Svc Service.
  5. Author: Luciano Passuello (lucianop), 01/25/2001
  6. Modified from original code from IMB Service
  7. ************************************************************************************************/
  8. #include "stdafx.h"
  9. #include "ServiceSetup.h"
  10. #include "Resource.h"
  11. // What is the executable being run for?
  12. enum ServiceMode {SERVICE_RUN, SERVICE_INSTALL, SERVICE_REMOVE};
  13. // prototypes
  14. ServiceMode GetServiceMode();
  15. void RunService(LPCTSTR tszServiceName, LPCTSTR tszDisplayName);
  16. void InstallService(LPCTSTR tszServiceName, LPCTSTR tszDisplayName, LPCTSTR tszDescription);
  17. void RemoveService(LPCTSTR tszServiceName, LPCTSTR tszDisplayName);
  18. /************************************************************************************************
  19. Function: WinMain, global
  20. Description: Entry-point for the application.
  21. Arguments: See WinMain documentation.
  22. History: 01/26/2001 - created, Luciano Passuello (lucianop).
  23. ************************************************************************************************/
  24. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int /*nCmdShow*/)
  25. {
  26. // load necessary data about the service
  27. TCHAR tszDescription[nMaxServiceDescLen+1];
  28. TCHAR tszDisplayName[nMaxServiceDescLen+1];
  29. if(0 == LoadString(hInstance, IDS_DESCRIPTION, tszDescription, nMaxServiceDescLen))
  30. {
  31. return 1;
  32. }
  33. if(0 == LoadString(hInstance, IDS_DISPLAYNAME, tszDisplayName, nMaxServiceDescLen))
  34. {
  35. return 1;
  36. }
  37. // parse the command line and identify what action to perform
  38. ServiceMode sm = GetServiceMode();
  39. switch(sm)
  40. {
  41. case SERVICE_RUN:
  42. RunService(POP3_SERVICE_NAME, tszDisplayName);
  43. break;
  44. case SERVICE_INSTALL:
  45. InstallService(POP3_SERVICE_NAME, tszDisplayName, tszDescription);
  46. break;
  47. case SERVICE_REMOVE:
  48. RemoveService(POP3_SERVICE_NAME, tszDisplayName);
  49. break;
  50. }
  51. return 0;
  52. }
  53. /************************************************************************************************
  54. Function: GetServiceMode, global
  55. Synopsis: Parses the command line and returns the running mode for the service.
  56. Notes:
  57. History: 01/26/2001 - created, Luciano Passuello (lucianop).
  58. ************************************************************************************************/
  59. ServiceMode GetServiceMode()
  60. {
  61. // gets the command line, parses it and returns what is to be done
  62. TCHAR *tszCommandLine = GetCommandLine();
  63. CharLowerBuff(tszCommandLine, _tcslen(tszCommandLine));
  64. if(_tcsstr(tszCommandLine, _T("-install")))
  65. {
  66. return SERVICE_INSTALL;
  67. }
  68. else if(_tcsstr(tszCommandLine, _T("-remove")))
  69. {
  70. return SERVICE_REMOVE;
  71. }
  72. else
  73. {
  74. // unrecognized command line parameters translate to "RUN", too.
  75. return SERVICE_RUN;
  76. }
  77. }
  78. /************************************************************************************************
  79. Function: RunService, global
  80. Description: Main processing when the service is being executed in running mode.
  81. Arguments: [tszServiceName] - unique short name of the service
  82. [tszDisplayName] - service name as it will appear to users in the SCM.
  83. Notes:
  84. History: 01/26/2001 - created, Luciano Passuello (lucianop).
  85. ************************************************************************************************/
  86. void RunService(LPCTSTR tszServiceName, LPCTSTR tszDisplayName)
  87. {
  88. ASSERT(!(NULL == tszServiceName));
  89. ASSERT(!(NULL == tszDisplayName));
  90. // creates the service-wrapper class
  91. CPop3Svc POP3SVC(tszServiceName, tszDisplayName, SERVICE_WIN32_SHARE_PROCESS );
  92. // initializes the control handlers with the SCM and starts the processing threads
  93. // See CService design
  94. BEGIN_SERVICE_MAP
  95. SERVICE_MAP_ENTRY(CPop3Svc, POP3SVC)
  96. END_SERVICE_MAP
  97. }
  98. /************************************************************************************************
  99. Function: InstallService, global
  100. Description: Main processing when the service is running in install mode.
  101. Arguments: [tszServiceName] - unique short name of the service
  102. [tszDisplayName] - service name as it will appear to users in the SCM.
  103. [tszDescription] - long description of the service (available in the SCM)
  104. Notes:
  105. History: 01/26/2001 Luciano Passuello (lucianop) Created.
  106. ************************************************************************************************/
  107. void InstallService(LPCTSTR tszServiceName, LPCTSTR tszDisplayName, LPCTSTR tszDescription)
  108. {
  109. CServiceSetup cs(tszServiceName, tszDisplayName);
  110. cs.Install(tszDescription);
  111. }
  112. /************************************************************************************************
  113. Function: WinMain, global
  114. Description: Main processing when the service is running in remove mode.
  115. Arguments: [tszServiceName] - unique short name of the service
  116. [tszDisplayName] - service name as it will appear to users in the SCM.
  117. Notes:
  118. History: 01/26/2001 Luciano Passuello (lucianop) Created.
  119. ************************************************************************************************/
  120. void RemoveService(LPCTSTR tszServiceName, LPCTSTR tszDisplayName)
  121. {
  122. CServiceSetup cs(tszServiceName, tszDisplayName);
  123. if(cs.IsInstalled())
  124. {
  125. cs.Remove(true);
  126. }
  127. }