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.

220 lines
5.1 KiB

  1. #define INCL_INETSRV_INCS
  2. #include "smtpinc.h"
  3. //+---------------------------------------------------------------
  4. //
  5. // Function: CheckInstanceId
  6. //
  7. // Synopsis: Callback from IIS_SERVICE iterator
  8. //
  9. // Arguments: void
  10. //
  11. // Returns: TRUE is success, else FALSE
  12. //
  13. // History:
  14. //
  15. //----------------------------------------------------------------
  16. BOOL
  17. CheckInstanceId(
  18. PVOID pvContext,
  19. PVOID pvContext1,
  20. PIIS_SERVER_INSTANCE pInstance
  21. )
  22. {
  23. PSMTP_SERVER_INSTANCE pSmtpInstance = (PSMTP_SERVER_INSTANCE)pInstance ;
  24. DWORD dwInstanceId = (DWORD)((DWORD_PTR)pvContext) ;
  25. PSMTP_SERVER_INSTANCE* ppSmtpInstance = (PSMTP_SERVER_INSTANCE*)pvContext1 ;
  26. //
  27. // Check this instance for its id - if it matches the id we are looking for
  28. // return FALSE to discontinue the iteration.
  29. //
  30. if( dwInstanceId == pSmtpInstance->QueryInstanceId() )
  31. {
  32. // found it
  33. if(!pSmtpInstance->IsShuttingDown())
  34. {
  35. //reference it first
  36. pSmtpInstance->Reference();
  37. *ppSmtpInstance = pSmtpInstance ;
  38. return FALSE ;
  39. }
  40. else
  41. {
  42. //lie and say we did not find the instance
  43. //if we are shutting down
  44. *ppSmtpInstance = NULL;
  45. return FALSE;
  46. }
  47. }
  48. // did not find it - continue iteration
  49. return TRUE;
  50. }
  51. //+---------------------------------------------------------------
  52. //
  53. // Function: FindIISInstance
  54. //
  55. // Synopsis: Returns an instance pointer for the given ID
  56. //
  57. // Arguments: pointer to an SMTP server calss and instance ID
  58. //
  59. // Returns: pointer to an SMTP instance class
  60. //
  61. // History:
  62. //
  63. //----------------------------------------------------------------
  64. PSMTP_SERVER_INSTANCE
  65. FindIISInstance(
  66. PSMTP_IIS_SERVICE pService,
  67. DWORD dwInstanceId
  68. )
  69. {
  70. PFN_INSTANCE_ENUM pfnInstanceEnum = NULL ;
  71. PSMTP_SERVER_INSTANCE pInstance = NULL ;
  72. TraceFunctEnter("FindIISInstance");
  73. //
  74. // Iterate over all instances
  75. //
  76. pfnInstanceEnum = (PFN_INSTANCE_ENUM)&CheckInstanceId;
  77. if( !pService->EnumServiceInstances(
  78. (PVOID)(SIZE_T)dwInstanceId,
  79. (PVOID)&pInstance,
  80. pfnInstanceEnum
  81. ) ) {
  82. ErrorTrace(0,"Error enumerating instances");
  83. }
  84. //if we found an instance, but it's not running, or the service is
  85. //not running, then dereference the instance and leave
  86. if(pInstance && ( (pInstance->QueryServerState() != MD_SERVER_STATE_STARTED)
  87. || (pService->QueryCurrentServiceState() != SERVICE_RUNNING)))
  88. {
  89. pInstance->Dereference();
  90. pInstance = NULL;
  91. }
  92. TraceFunctLeave();
  93. return pInstance ;
  94. }
  95. BOOL CountInstances(
  96. PVOID pvContext,
  97. PVOID pvContext1,
  98. PIIS_SERVER_INSTANCE pInstance
  99. )
  100. {
  101. if(pInstance)
  102. {
  103. (*(DWORD*)pvContext)++;
  104. }
  105. return TRUE;
  106. }
  107. BOOL GetInstancePerfData(
  108. PVOID pvContext,
  109. PVOID pvContext1,
  110. PIIS_SERVER_INSTANCE pInstance
  111. )
  112. {
  113. DWORD dwInstanceId = (DWORD)((DWORD_PTR)pvContext) ;
  114. PSMTP_STATISTICS_BLOCK pStatsBlock;
  115. PSMTP_INSTANCE_LIST_ENTRY pInstanceInfo = NULL;
  116. pStatsBlock = *(PSMTP_STATISTICS_BLOCK *) pvContext1;
  117. if(pInstance->QueryInstanceId() <= (DWORD)((DWORD_PTR)pvContext))
  118. {
  119. pStatsBlock->dwInstance = pInstance->QueryInstanceId();
  120. pInstanceInfo = ((SMTP_SERVER_INSTANCE *)pInstance)->GetSmtpInstanceInfo();
  121. if(pInstanceInfo)
  122. {
  123. pInstanceInfo->pSmtpServerStatsObj->CopyToStatsBuffer(&(pStatsBlock->Stats_0));
  124. }
  125. //((SMTP_SERVER_INSTANCE *)pInstance)->GetSmtpInstanceInfo()->pSmtpServerStatsObj->CopyToStatsBuffer(&(pStatsBlock->Stats_0));
  126. (*(PSMTP_STATISTICS_BLOCK *) pvContext1)++;
  127. return TRUE;
  128. }
  129. return FALSE;
  130. }
  131. PSMTP_STATISTICS_BLOCK_ARRAY GetServerPerfCounters(PSMTP_IIS_SERVICE pService)
  132. {
  133. DWORD NumInstances = 0;
  134. DWORD dwAlloc = 0;
  135. PSMTP_INSTANCE_LIST_ENTRY pSmtpInfo = NULL;
  136. PSMTP_STATISTICS_BLOCK_ARRAY pSmtpStatsBlockArray = NULL;
  137. PSMTP_STATISTICS_BLOCK pStatsBlock = NULL;
  138. TraceFunctEnter("GetServerPerfCounters");
  139. PFN_INSTANCE_ENUM pfnInstanceEnum = NULL ;
  140. //Get the count of the number of instances first
  141. pfnInstanceEnum = (PFN_INSTANCE_ENUM)&CountInstances;
  142. if( !pService->EnumServiceInstances(
  143. (PVOID)&NumInstances,
  144. (PVOID)NULL,
  145. pfnInstanceEnum
  146. ) )
  147. {
  148. ErrorTrace(0,"Error counting instances");
  149. }
  150. if (NumInstances == 0)
  151. {
  152. TraceFunctLeave();
  153. return NULL;
  154. }
  155. //allocate memory to return to caller
  156. dwAlloc = sizeof(SMTP_STATISTICS_BLOCK_ARRAY) + NumInstances * sizeof(SMTP_STATISTICS_BLOCK);
  157. pSmtpStatsBlockArray = (PSMTP_STATISTICS_BLOCK_ARRAY)MIDL_user_allocate(dwAlloc);
  158. if (!pSmtpStatsBlockArray)
  159. {
  160. TraceFunctLeave();
  161. return NULL;
  162. }
  163. ZeroMemory(pSmtpStatsBlockArray, dwAlloc);
  164. //fill in memory structure
  165. pSmtpStatsBlockArray->cEntries = NumInstances;
  166. pStatsBlock = pSmtpStatsBlockArray->aStatsBlock;
  167. pfnInstanceEnum = (PFN_INSTANCE_ENUM)&GetInstancePerfData;
  168. if( !pService->EnumServiceInstances(
  169. (PVOID)(SIZE_T)NumInstances,
  170. (PVOID)&pStatsBlock,
  171. pfnInstanceEnum
  172. ) )
  173. {
  174. ErrorTrace(0,"Error counting instances");
  175. }
  176. TraceFunctLeave();
  177. return pSmtpStatsBlockArray;
  178. }