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.

94 lines
2.0 KiB

  1. #include "stdafx.h"
  2. #include "elem.h"
  3. CElem::CElem()
  4. {
  5. m_hKey = NULL;
  6. m_index = 0;
  7. m_ip = _T("");
  8. m_name = _T("");
  9. m_value = _T("");
  10. }
  11. CElem::~CElem()
  12. {
  13. if (m_hKey)
  14. RegCloseKey(m_hKey);
  15. }
  16. BOOL CElem::OpenReg(LPCTSTR szSubKey)
  17. {
  18. BOOL fReturn = FALSE;
  19. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, szSubKey, 0, KEY_READ, &m_hKey) == ERROR_SUCCESS)
  20. fReturn = TRUE;
  21. else
  22. m_hKey = NULL;
  23. return (fReturn);
  24. }
  25. void CElem::CloseReg()
  26. {
  27. if (m_hKey) {
  28. RegCloseKey(m_hKey);
  29. m_hKey = NULL;
  30. }
  31. }
  32. BOOL CElem::GetNext()
  33. {
  34. BOOL fReturn = FALSE;
  35. LONG err = ERROR_SUCCESS;
  36. TCHAR szBufferL[_MAX_PATH], szBufferR[_MAX_PATH];
  37. DWORD dwBufferL = _MAX_PATH, dwBufferR = _MAX_PATH;
  38. err = RegEnumValue(m_hKey, m_index, szBufferL, &dwBufferL, NULL, NULL, (LPBYTE)szBufferR, &dwBufferR);
  39. if (err == ERROR_SUCCESS) {
  40. LPTSTR token;
  41. m_index++;
  42. m_value = szBufferR;
  43. token = _tcstok(szBufferL, _T(","));
  44. if (token) {
  45. m_name = token;
  46. token = _tcstok(NULL, _T(","));
  47. if (token) {
  48. m_ip = token;
  49. } else {
  50. m_ip = _T("null");
  51. }
  52. fReturn = TRUE;
  53. }
  54. }
  55. return (fReturn);
  56. }
  57. void CElem::ReadRegVRoots(LPCTSTR szSubKey, CMapStringToOb *pMap)
  58. {
  59. if ( OpenReg(szSubKey) ) {
  60. while (GetNext()) {
  61. Add(pMap);
  62. }
  63. CloseReg();
  64. }
  65. }
  66. void CElem::Add(CMapStringToOb *pMap)
  67. {
  68. CObject *pObj;
  69. CMapStringToString *pNew;
  70. if (pMap->Lookup(m_ip, pObj) == TRUE) {
  71. pNew = (CMapStringToString*)pObj;
  72. pNew->SetAt(m_name, m_value);
  73. } else {
  74. pNew = new CMapStringToString;
  75. if (pNew != NULL) { // Better to lose an entry than AV
  76. pNew->SetAt(m_name, m_value);
  77. pMap->SetAt(m_ip, (CObject*)pNew);
  78. }
  79. }
  80. }