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.

282 lines
5.7 KiB

  1. #include "stdinc.h"
  2. int __cdecl
  3. SxspCompareKeys(
  4. const void *pv1,
  5. const void *pv2
  6. )
  7. {
  8. const struct _SXSP_SETTINGS_KEY *pkey1 = reinterpret_cast<PCSXSP_SETTINGS_KEY>(pv1);
  9. const struct _SXSP_SETTINGS_KEY *pkey2 = reinterpret_cast<PCSXSP_SETTINGS_KEY>(pv2);
  10. return ::FusionpCompareStrings(
  11. pkey1->m_pszKeyName,
  12. pkey1->m_cchKeyName,
  13. pkey2->m_pszKeyName,
  14. pkey2->m_cchKeyName,
  15. true);
  16. }
  17. LONG
  18. SxspInternalKeyToExternalKey(
  19. PSXSP_SETTINGS_KEY KeyIn,
  20. REGSAM samGranted,
  21. PSXS_SETTINGS_KEY &KeyOut
  22. )
  23. {
  24. LONG lResult = ERROR_INTERNAL_ERROR;
  25. FN_TRACE_REG(lResult);
  26. PSXS_SETTINGS_KEY KeyTemp = NULL;
  27. KeyOut = NULL;
  28. INTERNAL_ERROR_CHECK(KeyIn != NULL);
  29. IFALLOCFAILED_EXIT(KeyTemp = new SXS_SETTINGS_KEY);
  30. ::InterlockedIncrement(&KeyIn->m_cRef);
  31. KeyTemp->m_InternalKey = KeyIn;
  32. KeyTemp->m_SamGranted = samGranted;
  33. KeyOut = KeyTemp;
  34. lResult = ERROR_SUCCESS;
  35. Exit:
  36. return lResult;
  37. }
  38. void
  39. SxspDestroySettingsKey(
  40. PSXSP_SETTINGS_KEY Key
  41. )
  42. {
  43. FN_TRACE();
  44. ULONG i;
  45. ASSERT(Key != NULL);
  46. if (Key == NULL)
  47. return;
  48. ASSERT(Key->m_cRef == 0);
  49. for (i=0; i<Key->m_cValues; i++)
  50. {
  51. PSXSP_SETTINGS_VALUE &ValueRef = Key->m_prgValues[i];
  52. ::SxspDestroySettingsValue(ValueRef);
  53. ValueRef = NULL;
  54. }
  55. for (i=0; i<Key->m_cSubKeys; i++)
  56. {
  57. PSXSP_SETTINGS_KEY &KeyRef = Key->m_prgSubKeys[i];
  58. const PSXSP_SETTINGS_KEY SubKey = KeyRef;
  59. ::SxspDetachSettingsKey(SubKey);
  60. ::SxspReleaseSettingsKey(SubKey);
  61. KeyRef = NULL;
  62. }
  63. FUSION_RAW_DEALLOC(const_cast<PWSTR>(Key->m_pszKeyName));
  64. FUSION_DELETE_SINGLETON(Key);
  65. }
  66. void
  67. SxspDetachSettingsKey(
  68. PSXSP_SETTINGS_KEY Key
  69. )
  70. {
  71. FN_TRACE();
  72. ASSERT(Key != NULL);
  73. if (Key == NULL)
  74. return;
  75. // You shouldn't detach a key more than once...
  76. ASSERT((Key->m_dwFlags & SXSP_SETTINGS_KEY_FLAG_DETACHED) == 0);
  77. if (Key->m_dwFlags & SXSP_SETTINGS_KEY_FLAG_DETACHED)
  78. return;
  79. ULONG i;
  80. // Detaching a key also detaches all its children...
  81. for (i=0; i<Key->m_cSubKeys; i++)
  82. ::SxspDetachSettingsKey(Key->m_prgSubKeys[i]);
  83. }
  84. void
  85. SxspAddRefSettingsKey(
  86. PSXSP_SETTINGS_KEY Key
  87. )
  88. {
  89. ASSERT_NTC(Key != NULL);
  90. if (Key != NULL)
  91. {
  92. ASSERT_NTC(Key->m_cRef != 0);
  93. ::InterlockedIncrement(&Key->m_cRef);
  94. }
  95. }
  96. void
  97. SxspReleaseSettingsKey(
  98. PSXSP_SETTINGS_KEY Key
  99. )
  100. {
  101. ASSERT_NTC(Key != NULL);
  102. if (Key != NULL)
  103. {
  104. if (::InterlockedDecrement(&Key->m_cRef) == 0)
  105. ::SxspDestroySettingsKey(Key);
  106. }
  107. }
  108. LONG
  109. WINAPI
  110. SxsCloseSettingsKey(
  111. PSXS_SETTINGS_KEY Key
  112. )
  113. {
  114. LONG lResult = ERROR_INTERNAL_ERROR;
  115. FN_TRACE_REG(lResult);
  116. PARAMETER_CHECK(Key != NULL);
  117. ::SxspReleaseSettingsKey(Key->m_InternalKey);
  118. Key->m_InternalKey = NULL;
  119. FUSION_DELETE_SINGLETON(Key);
  120. lResult = ERROR_SUCCESS;
  121. Exit:
  122. return lResult;
  123. }
  124. LONG
  125. SxspFindSubkey(
  126. DWORD dwFlags,
  127. PSXSP_SETTINGS_KEY pKeyIn,
  128. PCWSTR pszSubKey,
  129. ULONG cchSubKey,
  130. PSXSP_SETTINGS_KEY &rpKeyOut
  131. )
  132. {
  133. LONG lResult = ERROR_INTERNAL_ERROR;
  134. FN_TRACE_REG(lResult);
  135. SXSP_SETTINGS_KEY KeyToFind;
  136. PARAMETER_CHECK(dwFlags == 0);
  137. PARAMETER_CHECK(pKeyIn != NULL);
  138. PARAMETER_CHECK(cchSubKey == 0 || pszSubKey != NULL);
  139. KeyToFind.m_pszKeyName = pszSubKey;
  140. KeyToFind.m_cchKeyName = cchSubKey;
  141. rpKeyOut = reinterpret_cast<PSXSP_SETTINGS_KEY>(bsearch(&KeyToFind, pKeyIn->m_prgSubKeys, pKeyIn->m_cSubKeys, sizeof(SXSP_SETTINGS_KEY), &SxspCompareKeys));
  142. lResult = ERROR_SUCCESS;
  143. Exit:
  144. return lResult;
  145. }
  146. LONG
  147. SxspNavigateKey(
  148. DWORD dwFlags,
  149. PSXSP_SETTINGS_KEY pKeyIn,
  150. PCWSTR pszSubKeyPath,
  151. ULONG cchSubKeyPath,
  152. ULONG &rcchSubKeyPathConsumed,
  153. PSXSP_SETTINGS_KEY &rpKeyOut
  154. )
  155. {
  156. LONG lResult = ERROR_INTERNAL_ERROR;
  157. FN_TRACE_REG(lResult);
  158. // PCWSTR pszThisSegmentStart = pszSubKeyPath;
  159. // PCWSTR pszSeparator = NULL;
  160. ULONG cchSearched = 0;
  161. // PSXSP_SETTINGS_KEY pKeyFound = NULL;
  162. rpKeyOut = NULL;
  163. rcchSubKeyPathConsumed = 0;
  164. INTERNAL_ERROR_CHECK(dwFlags == 0);
  165. INTERNAL_ERROR_CHECK(pKeyIn != NULL);
  166. while (cchSearched < cchSubKeyPath)
  167. {
  168. const WCHAR wch = pszSubKeyPath[cchSearched];
  169. if (wch == NULL)
  170. {
  171. ASSERT(cchSearched == cchSubKeyPath);
  172. if (cchSearched != cchSubKeyPath)
  173. {
  174. lResult = ERROR_INVALID_PARAMETER;
  175. goto Exit;
  176. }
  177. break;
  178. }
  179. else if (wch == L'\\')
  180. {
  181. break;
  182. }
  183. else
  184. {
  185. }
  186. }
  187. lResult = ERROR_SUCCESS;
  188. Exit:
  189. return lResult;
  190. }
  191. LONG
  192. WINAPI
  193. SxsCreateSettingsKeyExW(
  194. PSXS_SETTINGS_KEY lpKey,
  195. LPCWSTR lpSubKey,
  196. DWORD Reserved,
  197. LPWSTR lpClass,
  198. DWORD dwOptions,
  199. REGSAM samDesired,
  200. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  201. PSXS_SETTINGS_KEY *lplpKeyResult,
  202. LPDWORD lpdwDisposition
  203. )
  204. {
  205. LONG lResult = ERROR_INTERNAL_ERROR;
  206. FN_TRACE_REG(lResult);
  207. ULONG cchSubKey = 0;
  208. ULONG cchClass = 0;
  209. if (lplpKeyResult != NULL)
  210. *lplpKeyResult = NULL;
  211. if (lpdwDisposition != NULL)
  212. *lpdwDisposition = 0; // is there a better "i don't know yet?" value?
  213. PARAMETER_CHECK(lpKey != NULL);
  214. PARAMETER_CHECK(lpSubKey != NULL);
  215. PARAMETER_CHECK(dwOptions == 0);
  216. PARAMETER_CHECK(lpSecurityAttributes == NULL); // or should we just permit them and ignore them?
  217. PARAMETER_CHECK(lplpKeyResult != NULL);
  218. cchSubKey = wcslen(lpSubKey);
  219. if (lpClass != NULL)
  220. cchClass = wcslen(lpClass);
  221. lResult = ERROR_SUCCESS;
  222. Exit:
  223. return lResult;
  224. }