Source code of Windows XP (NT5)
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
3.5 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. LONG err = ERROR_SUCCESS;
  20. err = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szSubKey, 0, KEY_READ, &m_hKey);
  21. if (ERROR_SUCCESS == err)
  22. {
  23. fReturn = TRUE;
  24. }
  25. else
  26. {
  27. m_hKey = NULL;
  28. if ( err != ERROR_FILE_NOT_FOUND )
  29. {iisDebugOut((LOG_TYPE_ERROR, _T("CElem::OpenReg(): %s. FAILED. code=0x%x\n"), szSubKey, err));}
  30. }
  31. return (fReturn);
  32. }
  33. void CElem::CloseReg()
  34. {
  35. if (m_hKey)
  36. {
  37. RegCloseKey(m_hKey);
  38. m_hKey = NULL;
  39. }
  40. }
  41. BOOL CElem::GetNext()
  42. {
  43. BOOL fReturn = FALSE;
  44. LONG err = ERROR_SUCCESS;
  45. TCHAR szBufferL[_MAX_PATH], szBufferR[_MAX_PATH];
  46. DWORD dwBufferL = _MAX_PATH, dwBufferR = _MAX_PATH;
  47. err = RegEnumValue(m_hKey, m_index, szBufferL, &dwBufferL, NULL, NULL, (LPBYTE)szBufferR, &dwBufferR);
  48. if (err == ERROR_SUCCESS)
  49. {
  50. LPTSTR token;
  51. m_index++;
  52. m_value = szBufferR;
  53. token = _tcstok(szBufferL, _T(","));
  54. if (token) {
  55. m_name = token;
  56. token = _tcstok(NULL, _T(","));
  57. if (token) {
  58. m_ip = token;
  59. } else {
  60. m_ip = _T("null");
  61. }
  62. fReturn = TRUE;
  63. }
  64. m_name.MakeLower();
  65. m_value.MakeLower();
  66. //
  67. // m_name looks like = /scripts
  68. // m_value looks like = c:\inetpub\scripts,,4
  69. //
  70. // m_value could look like anything
  71. // c:
  72. // c:\stuff
  73. // c:\whatevers\
  74. // who knows what they put in there.
  75. // we need to make sure it look like a fully qualified path though.
  76. //
  77. // Get the first Value before the comma
  78. int iWhere = 0;
  79. iWhere = m_value.Find(_T(','));
  80. if (-1 != iWhere)
  81. {
  82. CString BeforeComma;
  83. CString AfterComma;
  84. // there is a ',' in the string
  85. BeforeComma = m_value.Left(iWhere);
  86. // Get the after comma vlues
  87. AfterComma = m_value.Right( m_value.GetLength() - iWhere);
  88. TCHAR thefilename[_MAX_PATH];
  89. TCHAR thepath[_MAX_PATH];
  90. TCHAR * pmypath;
  91. _stprintf(thefilename, _T("%s"), BeforeComma);
  92. // make sure the left side is a valid directory name!
  93. if (0 != GetFullPathName(thefilename, _MAX_PATH, thepath, &pmypath))
  94. {BeforeComma = thepath;}
  95. // reconcatenate them
  96. m_value = BeforeComma;
  97. m_value += AfterComma;
  98. }
  99. }
  100. else
  101. {
  102. if ( err != ERROR_FILE_NOT_FOUND && err != ERROR_NO_MORE_ITEMS)
  103. {iisDebugOut((LOG_TYPE_WARN, _T("CElem::GetNext(): FAILED. code=0x%x\n"), err));}
  104. }
  105. return (fReturn);
  106. }
  107. void CElem::ReadRegVRoots(LPCTSTR szSubKey, CMapStringToOb *pMap)
  108. {
  109. if ( OpenReg(szSubKey) )
  110. {
  111. while (GetNext())
  112. {
  113. Add(pMap);
  114. }
  115. CloseReg();
  116. }
  117. }
  118. void CElem::Add(CMapStringToOb *pMap)
  119. {
  120. CObject *pObj;
  121. CMapStringToString *pNew;
  122. if (pMap->Lookup(m_ip, pObj) == TRUE) {
  123. pNew = (CMapStringToString*)pObj;
  124. pNew->SetAt(m_name, m_value);
  125. } else {
  126. pNew = new CMapStringToString;
  127. pNew->SetAt(m_name, m_value);
  128. pMap->SetAt(m_ip, (CObject*)pNew);
  129. }
  130. }