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.

170 lines
5.6 KiB

  1. #include "global.h"
  2. #include "ini.h"
  3. // constructor
  4. CkdMonINI::CkdMonINI() {
  5. dwServerCount = 0;
  6. ppszServerNameArray = NULL;
  7. }
  8. BOOL CkdMonINI::LoadValues(_TCHAR szINIFile[])
  9. {
  10. //
  11. // Information in "Service" section of INI file
  12. //
  13. GetPrivateProfileString( (LPCTSTR)(_T("Service")),
  14. (LPCTSTR)(_T("FromMailID")),
  15. (LPCTSTR)(_T("")), // this parameter can not be NULL
  16. (LPTSTR) szFromMailID,
  17. sizeof(szFromMailID)/sizeof(_TCHAR), // size in _TCHARs
  18. (LPCTSTR) szINIFile);
  19. // return if the MailID string is not there in INI file
  20. if ( _tcscmp(szFromMailID, _T("")) == 0 ) {
  21. AddServiceLog(_T("Error: From Mail ID is missing in INI file\r\n"));
  22. LogFatalEvent(_T("From Mail ID is missing in INI file"));
  23. return FALSE;
  24. }
  25. GetPrivateProfileString( (LPCTSTR)(_T("Service")),
  26. (LPCTSTR)(_T("ToMailID")),
  27. (LPCTSTR)(_T("")), // this parameter can not be NULL
  28. (LPTSTR) szToMailID,
  29. sizeof(szToMailID)/sizeof(_TCHAR), // size in _TCHARs
  30. (LPCTSTR) szINIFile);
  31. // return if the MailID string is not there in INI file
  32. if ( _tcscmp(szToMailID, _T("")) == 0 ) {
  33. AddServiceLog(_T("Error: To Mail ID is missing in INI file\r\n"));
  34. LogFatalEvent(_T("To Mail ID is missing in INI file"));
  35. return FALSE;
  36. }
  37. // Time after which logfile scanning is to be repeated. This is in minutes
  38. dwRepeatTime = (DWORD)GetPrivateProfileInt( (LPCTSTR)(_T("Service")),
  39. (LPCTSTR)(_T("RepeatTime")),
  40. 60,
  41. (LPCTSTR) szINIFile);
  42. // validate dwRepeatTime
  43. if ( dwRepeatTime < 1 ) dwRepeatTime = 60;
  44. // Debugger log file
  45. // It will be something like C:\Debuggers\FailedAddCrash.log
  46. GetPrivateProfileString( (LPCTSTR)(_T("Service")),
  47. (LPCTSTR)(_T("DebuggerLogFile")),
  48. (LPCTSTR)(_T("C$\\Debuggers\\FailedAddCrash.log")),
  49. (LPTSTR) szDebuggerLogFile,
  50. sizeof(szDebuggerLogFile)/sizeof(_TCHAR), // size in _TCHARs
  51. (LPCTSTR) szINIFile);
  52. // Log archive
  53. // Dir where the previous logs will be stored
  54. GetPrivateProfileString( (LPCTSTR)(_T("Service")),
  55. (LPCTSTR)(_T("DebuggerLogArchiveDir")),
  56. (LPCTSTR)(_T("C:\\")),
  57. (LPTSTR) szDebuggerLogArchiveDir,
  58. sizeof(szDebuggerLogArchiveDir)/sizeof(_TCHAR), // size in _TCHARs
  59. (LPCTSTR) szINIFile);
  60. // Threshold failures per server after which alert mail is to be sent out
  61. // This Threshold is per server basis
  62. dwDebuggerThreshold = (DWORD)GetPrivateProfileInt( (LPCTSTR)(_T("Service")),
  63. (LPCTSTR)(_T("DebuggerThreshold")),
  64. 10,
  65. (LPCTSTR) szINIFile);
  66. // validate dwDebuggerThreshold
  67. if ( dwDebuggerThreshold < 1 ) dwDebuggerThreshold = 10;
  68. GetPrivateProfileSection( (LPCTSTR) (_T("RPT Servers")),
  69. (LPTSTR) szServers,
  70. sizeof(szServers)/sizeof(_TCHAR),
  71. (LPCTSTR) szINIFile);
  72. BOOL bRet;
  73. // seperate out the individual server names from szServers string
  74. bRet = SeperateServerStrings();
  75. if ( bRet == FALSE ) return FALSE;
  76. return TRUE;
  77. }
  78. // seperate the Servers string got from INI file
  79. // the format of the string will be tkwucdrpta01'\0'tkwucdrpta02'\0'tkwucdrpta03'\0''\0'
  80. BOOL CkdMonINI::SeperateServerStrings()
  81. {
  82. // SeperateServerStrings gets called every time you read INI
  83. // and you read INI every dwRepeatTime
  84. // So we need to free the ppszServerNameArray out of previous execution of this
  85. // function
  86. for(DWORD i = 0; i < dwServerCount; i++) {
  87. free(ppszServerNameArray[i]);
  88. }
  89. if ( ppszServerNameArray != NULL )
  90. free(ppszServerNameArray);
  91. // temperory pointer to move through the szServers string
  92. _TCHAR* pszServers;
  93. pszServers = szServers;
  94. dwServerCount = 0;
  95. ppszServerNameArray = NULL;
  96. // the format of the szServers will be
  97. // tkwucdrpta01'\0'tkwucdrpta02'\0'tkwucdrpta03'\0''\0'
  98. while(1) {
  99. if( *pszServers == _T('\0') )
  100. break;
  101. dwServerCount++;
  102. // allocate memory for ppszServerNameArray
  103. if ( ppszServerNameArray == NULL ) {
  104. ppszServerNameArray = (_TCHAR **) malloc (dwServerCount * sizeof(_TCHAR**));
  105. if ( ppszServerNameArray == NULL ) {
  106. AddServiceLog(_T("Error: SeperateServerStrings->malloc: Insufficient memory available\r\n"));
  107. LogFatalEvent(_T("SeperateServerStrings->malloc: Insufficient memory available"));
  108. return FALSE;
  109. }
  110. }
  111. else {
  112. ppszServerNameArray = (_TCHAR **) realloc ( ppszServerNameArray,
  113. dwServerCount * sizeof(_TCHAR**));
  114. if ( ppszServerNameArray == NULL ) {
  115. AddServiceLog(_T("Error: SeperateServerStrings->realloc: Insufficient memory available\r\n"));
  116. LogFatalEvent(_T("SeperateServerStrings->realloc: Insufficient memory available"));
  117. return FALSE;
  118. }
  119. }
  120. ppszServerNameArray[dwServerCount - 1] =
  121. (_TCHAR *) malloc ( (_tcslen(pszServers) + 1) * sizeof(_TCHAR) );
  122. if ( ppszServerNameArray[dwServerCount - 1] == NULL ) {
  123. AddServiceLog(_T("Error: SeperateServerStrings->malloc: Insufficient memory available\r\n"));
  124. LogFatalEvent(_T("SeperateServerStrings->malloc: Insufficient memory available"));
  125. return FALSE;
  126. }
  127. _tcscpy(ppszServerNameArray[dwServerCount - 1], pszServers);
  128. // take pszServers one character beyond the end of the string
  129. pszServers += _tcslen(pszServers);
  130. // advance to the next string
  131. pszServers++;
  132. }
  133. return TRUE;
  134. }
  135. // destructor
  136. CkdMonINI::~CkdMonINI()
  137. {
  138. // free the whole ppszServerNameArray
  139. for(DWORD i = 0; i < dwServerCount; i++) {
  140. free(ppszServerNameArray[i]);
  141. }
  142. if ( ppszServerNameArray != NULL )
  143. free(ppszServerNameArray);
  144. }