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.

271 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. svcstat.cpp
  5. Abstract:
  6. This module contains code for doing statistics rpcs
  7. Author:
  8. Johnson Apacible (JohnsonA) 12-Nov-1995
  9. Revision History:
  10. --*/
  11. #define INCL_INETSRV_INCS
  12. #include "smtpinc.h"
  13. #include "smtpsvc.h"
  14. #include "findiis.hxx"
  15. extern PSMTP_STATISTICS_BLOCK_ARRAY GetServerPerfCounters(PSMTP_IIS_SERVICE pService);
  16. VOID
  17. ClearStatistics(
  18. VOID
  19. );
  20. NET_API_STATUS
  21. NET_API_FUNCTION
  22. SmtprQueryStatistics(
  23. IN SMTP_HANDLE pszServer,
  24. IN DWORD Level,
  25. OUT LPSTAT_INFO pBuffer
  26. )
  27. {
  28. APIERR err = 0;
  29. PSMTP_IIS_SERVICE pService = NULL;
  30. PLIST_ENTRY pInfoList = NULL;
  31. PLIST_ENTRY pEntry = NULL;
  32. DWORD dwEntries = 0;
  33. DWORD dwAlloc = 0;
  34. PSMTP_INSTANCE_LIST_ENTRY pSmtpInfo = NULL;
  35. PSMTP_STATISTICS_BLOCK_ARRAY pSmtpStatsBlockArray = NULL;
  36. PSMTP_STATISTICS_BLOCK pStatsBlock = NULL;
  37. _ASSERT( pBuffer != NULL );
  38. UNREFERENCED_PARAMETER(pszServer);
  39. pService = (PSMTP_IIS_SERVICE) g_pInetSvc;
  40. //
  41. // Check for proper access.
  42. //
  43. err = TsApiAccessCheck( TCP_QUERY_STATISTICS );
  44. if( err != NO_ERROR ) {
  45. return (NET_API_STATUS)err;
  46. }
  47. pService->AcquireServiceShareLock();
  48. if(g_IsShuttingDown)
  49. {
  50. pService->ReleaseServiceShareLock();
  51. return (NET_API_STATUS)ERROR_REQUEST_ABORTED;
  52. }
  53. //
  54. // get the information list. Determine the # instances
  55. //
  56. if(pService->QueryCurrentServiceState() != SERVICE_RUNNING)
  57. {
  58. err = ERROR_REQUEST_ABORTED;
  59. goto error_exit;
  60. }
  61. pInfoList = pService->GetInfoList();
  62. if (IsListEmpty(pInfoList))
  63. {
  64. err = ERROR_INVALID_PARAMETER;
  65. goto error_exit;
  66. }
  67. //
  68. // Return the proper statistics based on the infolevel.
  69. //
  70. switch( Level ) {
  71. case 0 :
  72. dwEntries = 0;
  73. for (pEntry = pInfoList->Flink; pEntry != pInfoList; pEntry = pEntry->Flink)
  74. {
  75. dwEntries++;
  76. }
  77. if (dwEntries == 0)
  78. {
  79. err = ERROR_INVALID_PARAMETER;
  80. goto error_exit;
  81. }
  82. dwAlloc = sizeof(SMTP_STATISTICS_BLOCK_ARRAY) + dwEntries * sizeof(SMTP_STATISTICS_BLOCK);
  83. pSmtpStatsBlockArray = (PSMTP_STATISTICS_BLOCK_ARRAY)MIDL_user_allocate(dwAlloc);
  84. if (!pSmtpStatsBlockArray)
  85. {
  86. err = ERROR_NOT_ENOUGH_MEMORY;
  87. goto error_exit;
  88. }
  89. pSmtpStatsBlockArray->cEntries = dwEntries;
  90. pStatsBlock = pSmtpStatsBlockArray->aStatsBlock;
  91. for (pEntry = pInfoList->Flink; pEntry != pInfoList; pEntry = pEntry->Flink)
  92. {
  93. pSmtpInfo = (PSMTP_INSTANCE_LIST_ENTRY)
  94. CONTAINING_RECORD(pEntry,SMTP_INSTANCE_LIST_ENTRY,ListEntry);
  95. pStatsBlock->dwInstance = pSmtpInfo->dwInstanceId;
  96. pSmtpInfo->pSmtpServerStatsObj->CopyToStatsBuffer(&(pStatsBlock->Stats_0));
  97. pStatsBlock++;
  98. }
  99. pBuffer->StatInfo0 = pSmtpStatsBlockArray;
  100. break;
  101. default :
  102. err = ERROR_INVALID_LEVEL;
  103. break;
  104. }
  105. error_exit:
  106. pBuffer->StatInfo0 = pSmtpStatsBlockArray;
  107. pService->ReleaseServiceShareLock();
  108. return (NET_API_STATUS)err;
  109. } // SmtprQueryStatistics
  110. /*
  111. NET_API_STATUS
  112. NET_API_FUNCTION
  113. SmtprQueryStatistics(
  114. IN SMTP_HANDLE pszServer,
  115. IN DWORD Level,
  116. IN LPSTAT_INFO pBuffer,
  117. IN DWORD dwInstance
  118. )
  119. {
  120. APIERR err;
  121. PSMTP_IIS_SERVICE pService;
  122. PSMTP_SERVER_INSTANCE pInstance;
  123. _ASSERT( pBuffer != NULL );
  124. UNREFERENCED_PARAMETER(pszServer);
  125. //
  126. // Check for proper access.
  127. //
  128. err = TsApiAccessCheck( TCP_QUERY_STATISTICS );
  129. if( err != NO_ERROR ) {
  130. return (NET_API_STATUS)err;
  131. }
  132. //
  133. // get a pointer to the global service
  134. //
  135. pService = (
  136. pInstance = FindIISInstance((PSMTP_IIS_SERVICE) g_pInetSvc, dwInstance);
  137. if(pInstance == NULL)
  138. {
  139. return((NET_API_STATUS) ERROR_INVALID_PARAMETER);
  140. }
  141. //
  142. // Return the proper statistics based on the infolevel.
  143. //
  144. switch( Level ) {
  145. case 0 :
  146. LPSMTP_STATISTICS_0 pstats0;
  147. if (!pInstance->GetStatistics(Level, (PCHAR*) &pstats0))
  148. {
  149. err = GetLastError();
  150. }
  151. else
  152. {
  153. pBuffer->StatInfo0 = pstats0;
  154. }
  155. break;
  156. default :
  157. err = ERROR_INVALID_LEVEL;
  158. break;
  159. }
  160. pInstance->Dereference();
  161. return (NET_API_STATUS)err;
  162. } // SmtprQueryStatistics */
  163. NET_API_STATUS
  164. NET_API_FUNCTION
  165. SmtprClearStatistics(
  166. SMTP_HANDLE pszServer,
  167. IN DWORD dwInstance
  168. )
  169. {
  170. APIERR err;
  171. PSMTP_SERVER_INSTANCE pInstance;
  172. UNREFERENCED_PARAMETER(pszServer);
  173. //
  174. // Check for proper access.
  175. //
  176. err = TsApiAccessCheck( TCP_CLEAR_STATISTICS );
  177. if( err != NO_ERROR ) {
  178. return (NET_API_STATUS)err;
  179. }
  180. pInstance = FindIISInstance((PSMTP_IIS_SERVICE) g_pInetSvc, dwInstance);
  181. if(pInstance == NULL)
  182. {
  183. return((NET_API_STATUS) ERROR_INVALID_PARAMETER);
  184. }
  185. //
  186. // Clear the statistics.
  187. //
  188. pInstance->ClearStatistics();
  189. pInstance->Dereference();
  190. return (NET_API_STATUS)err;
  191. } // SmtprClearStatistics
  192. VOID
  193. ClearStatistics(
  194. VOID
  195. )
  196. {
  197. return;
  198. } // ClearStatistics