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.

389 lines
9.8 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. subdict.cpp
  5. Abstract:
  6. This module contains the implementation for the Server
  7. Extension Object Sub-Dictionary class.
  8. Author:
  9. Don Dumitru (dondu@microsoft.com)
  10. Revision History:
  11. dondu 03/09/97 created
  12. --*/
  13. // subdict.cpp : Implementation of CSEOSubDictionary
  14. #include "stdafx.h"
  15. #include "seodefs.h"
  16. #include "subdict.h"
  17. #define SSA(x) ((x)?(x):"")
  18. #define SSW(x) ((x)?(x):L"")
  19. #define _ALLOC_NAME_A(prefix,suffix) (LPSTR) _alloca((strlen((prefix))+strlen((suffix))+1)*sizeof(CHAR))
  20. inline LPSTR CopyNameA(LPSTR pszDest, LPCSTR pszPrefix, LPCSTR pszSuffix) {
  21. strcpy(pszDest,pszPrefix);
  22. strcat(pszDest,pszSuffix);
  23. return (pszDest);
  24. }
  25. #define ALLOC_NAME_A(prefix,suffix) CopyNameA(_ALLOC_NAME_A(SSA(prefix),SSA(suffix)),SSA(prefix),SSA(suffix))
  26. #define _ALLOC_NAME_W(prefix,suffix) (LPWSTR) _alloca((wcslen((prefix))+wcslen((suffix))+1)*sizeof(WCHAR))
  27. inline LPWSTR CopyNameW(LPWSTR pszDest, LPCWSTR pszPrefix, LPCWSTR pszSuffix) {
  28. wcscpy(pszDest,pszPrefix);
  29. wcscat(pszDest,pszSuffix);
  30. return (pszDest);
  31. }
  32. #define ALLOC_NAME_W(prefix,suffix) CopyNameW(_ALLOC_NAME_W(SSW(prefix),SSW(suffix)),SSW(prefix),SSW(suffix))
  33. #ifdef UNICODE
  34. #define ALLOC_NAME_T ALLOC_NAME_W
  35. #else
  36. #define ALLOC_NAME_T ALLOC_NAME_A
  37. #endif
  38. #define ALLOC_NAME_OLE ALLOC_NAME_W
  39. HRESULT MakeNameAsVariant(VARIANT *pvarResult, VARIANT *pvarName, LPWSTR pszPrefix) {
  40. HRESULT hrRes;
  41. BSTR bstrTmp;
  42. VariantInit(pvarResult);
  43. if (pvarName && (pvarName->vt != VT_ERROR)) {
  44. hrRes = VariantChangeType(pvarResult,pvarName,0,VT_BSTR);
  45. if (!SUCCEEDED(hrRes)) {
  46. return (hrRes);
  47. }
  48. } else {
  49. pvarResult->bstrVal = SysAllocString(L"");
  50. if (!pvarResult->bstrVal) {
  51. return (E_OUTOFMEMORY);
  52. }
  53. }
  54. bstrTmp = SysAllocStringLen(pvarResult->bstrVal,
  55. wcslen(pvarResult->bstrVal)+wcslen(pszPrefix?pszPrefix:L"")+1);
  56. if (!bstrTmp) {
  57. VariantClear(pvarResult);
  58. return (E_OUTOFMEMORY);
  59. }
  60. wcscat(bstrTmp,pszPrefix);
  61. SysFreeString(pvarResult->bstrVal);
  62. pvarResult->bstrVal = bstrTmp;
  63. return (S_OK);
  64. }
  65. /////////////////////////////////////////////////////////////////////////////
  66. // CSEOSubDictionary
  67. HRESULT CSEOSubDictionary::FinalConstruct() {
  68. HRESULT hrRes;
  69. TraceFunctEnter("CSEOSubDictionary::FinalConstruct");
  70. m_pszPrefixA = NULL;
  71. m_pszPrefixW = NULL;
  72. hrRes = CoCreateFreeThreadedMarshaler(GetControllingUnknown(),&m_pUnkMarshaler.p);
  73. _ASSERTE(!SUCCEEDED(hrRes)||m_pUnkMarshaler);
  74. TraceFunctLeave();
  75. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  76. }
  77. void CSEOSubDictionary::FinalRelease() {
  78. TraceFunctEnter("CSEOSubDictionary::FinalRelease");
  79. m_pdictBase.Release();
  80. if (m_pszPrefixA) {
  81. CoTaskMemFree(m_pszPrefixA);
  82. m_pszPrefixA = NULL;
  83. }
  84. if (m_pszPrefixW) {
  85. CoTaskMemFree(m_pszPrefixW);
  86. m_pszPrefixW = NULL;
  87. }
  88. m_pUnkMarshaler.Release();
  89. TraceFunctLeave();
  90. }
  91. HRESULT CSEOSubDictionary::SetBaseA(ISEODictionary *pdictBase, LPCSTR pszPrefix) {
  92. if (m_pszPrefixA) {
  93. CoTaskMemFree(m_pszPrefixA);
  94. m_pszPrefixA = NULL;
  95. }
  96. if (m_pszPrefixW) {
  97. CoTaskMemFree(m_pszPrefixW);
  98. m_pszPrefixW = NULL;
  99. }
  100. m_pdictBase.Release();
  101. if (pszPrefix) {
  102. DWORD dwLen = strlen(pszPrefix);
  103. m_pszPrefixA = (LPSTR) CoTaskMemAlloc((dwLen+1)*sizeof(CHAR));
  104. if (!m_pszPrefixA) {
  105. return (E_OUTOFMEMORY);
  106. }
  107. m_pszPrefixW = (LPWSTR) CoTaskMemAlloc((dwLen+2)*sizeof(WCHAR));
  108. if (!m_pszPrefixW) {
  109. CoTaskMemFree(m_pszPrefixA);
  110. m_pszPrefixA = NULL;
  111. return (E_OUTOFMEMORY);
  112. }
  113. strcpy(m_pszPrefixA,pszPrefix);
  114. MultiByteToWideChar(CP_ACP,0,pszPrefix,-1,m_pszPrefixW,dwLen+1);
  115. m_pdictBase = pdictBase;
  116. }
  117. return (S_OK);
  118. }
  119. HRESULT CSEOSubDictionary::SetBaseW(ISEODictionary *pdictBase, LPCWSTR pszPrefix) {
  120. if (m_pszPrefixA) {
  121. CoTaskMemFree(m_pszPrefixA);
  122. m_pszPrefixA = NULL;
  123. }
  124. if (m_pszPrefixW) {
  125. CoTaskMemFree(m_pszPrefixW);
  126. m_pszPrefixW = NULL;
  127. }
  128. m_pdictBase.Release();
  129. if (pszPrefix) {
  130. DWORD dwLen = wcslen(pszPrefix);
  131. m_pszPrefixA = (LPSTR) CoTaskMemAlloc((dwLen+2)*sizeof(CHAR));
  132. if (!m_pszPrefixA) {
  133. return (E_OUTOFMEMORY);
  134. }
  135. m_pszPrefixW = (LPWSTR) CoTaskMemAlloc((dwLen+1)*sizeof(WCHAR));
  136. if (!m_pszPrefixW) {
  137. CoTaskMemFree(m_pszPrefixA);
  138. m_pszPrefixA = NULL;
  139. return (E_OUTOFMEMORY);
  140. }
  141. WideCharToMultiByte(CP_ACP,0,pszPrefix,-1,m_pszPrefixA,dwLen+1,NULL,NULL);
  142. wcscpy(m_pszPrefixW,pszPrefix);
  143. m_pdictBase = pdictBase;
  144. }
  145. return (S_OK);
  146. }
  147. HRESULT STDMETHODCALLTYPE CSEOSubDictionary::get_Item(VARIANT *pvarName, VARIANT *pvarResult) {
  148. VARIANT varTmp;
  149. HRESULT hrRes;
  150. if (!pvarResult) {
  151. return (E_POINTER);
  152. }
  153. if (!m_pdictBase) {
  154. return (SEO_E_NOTPRESENT);
  155. }
  156. hrRes = MakeNameAsVariant(&varTmp,pvarName,m_pszPrefixW);
  157. if (!SUCCEEDED(hrRes)) {
  158. VariantInit(pvarResult);
  159. return (hrRes);
  160. }
  161. hrRes = m_pdictBase->get_Item(&varTmp,pvarResult);
  162. VariantClear(&varTmp);
  163. return (hrRes);
  164. }
  165. HRESULT STDMETHODCALLTYPE CSEOSubDictionary::put_Item(VARIANT *pvarName, VARIANT *pvarValue) {
  166. VARIANT varTmp;
  167. HRESULT hrRes;
  168. if (!m_pdictBase) {
  169. return (E_OUTOFMEMORY);
  170. }
  171. hrRes = MakeNameAsVariant(&varTmp,pvarName,m_pszPrefixW);
  172. if (!SUCCEEDED(hrRes)) {
  173. return (hrRes);
  174. }
  175. hrRes = m_pdictBase->put_Item(&varTmp,pvarValue);
  176. VariantClear(&varTmp);
  177. return (hrRes);
  178. }
  179. HRESULT STDMETHODCALLTYPE CSEOSubDictionary::get__NewEnum(IUnknown **ppunkResult) {
  180. return (E_NOTIMPL);
  181. }
  182. HRESULT STDMETHODCALLTYPE CSEOSubDictionary::GetVariantA(LPCSTR pszName, VARIANT *pvarResult) {
  183. LPSTR pszTmp = ALLOC_NAME_A(m_pszPrefixA,pszName);
  184. if (!m_pdictBase) {
  185. return (SEO_E_NOTPRESENT);
  186. }
  187. return (m_pdictBase->GetVariantA(pszTmp,pvarResult));
  188. }
  189. HRESULT STDMETHODCALLTYPE CSEOSubDictionary::GetVariantW(LPCWSTR pszName, VARIANT *pvarResult) {
  190. LPWSTR pszTmp = ALLOC_NAME_W(m_pszPrefixW,pszName);
  191. if (!m_pdictBase) {
  192. return (SEO_E_NOTPRESENT);
  193. }
  194. return (m_pdictBase->GetVariantW(pszTmp,pvarResult));
  195. }
  196. HRESULT STDMETHODCALLTYPE CSEOSubDictionary::SetVariantA(LPCSTR pszName, VARIANT *pvarValue) {
  197. LPSTR pszTmp = ALLOC_NAME_A(m_pszPrefixA,pszName);
  198. if (!m_pdictBase) {
  199. return (E_OUTOFMEMORY);
  200. }
  201. return (m_pdictBase->SetVariantA(pszTmp,pvarValue));
  202. }
  203. HRESULT STDMETHODCALLTYPE CSEOSubDictionary::SetVariantW(LPCWSTR pszName, VARIANT *pvarValue) {
  204. LPWSTR pszTmp = ALLOC_NAME_W(m_pszPrefixW,pszName);
  205. if (!m_pdictBase) {
  206. return (E_OUTOFMEMORY);
  207. }
  208. return (m_pdictBase->SetVariantW(pszTmp,pvarValue));
  209. }
  210. HRESULT STDMETHODCALLTYPE CSEOSubDictionary::GetStringA(LPCSTR pszName, DWORD *pchCount, LPSTR pszResult) {
  211. LPSTR pszTmp = ALLOC_NAME_A(m_pszPrefixA,pszName);
  212. if (!m_pdictBase) {
  213. return (SEO_E_NOTPRESENT);
  214. }
  215. return (m_pdictBase->GetStringA(pszTmp,pchCount,pszResult));
  216. }
  217. HRESULT STDMETHODCALLTYPE CSEOSubDictionary::GetStringW(LPCWSTR pszName, DWORD *pchCount, LPWSTR pszResult) {
  218. LPWSTR pszTmp = ALLOC_NAME_W(m_pszPrefixW,pszName);
  219. if (!m_pdictBase) {
  220. return (SEO_E_NOTPRESENT);
  221. }
  222. return (m_pdictBase->GetStringW(pszTmp,pchCount,pszResult));
  223. }
  224. HRESULT STDMETHODCALLTYPE CSEOSubDictionary::SetStringA(LPCSTR pszName, DWORD chCount, LPCSTR pszValue) {
  225. LPSTR pszTmp = ALLOC_NAME_A(m_pszPrefixA,pszName);
  226. if (!m_pdictBase) {
  227. return (E_OUTOFMEMORY);
  228. }
  229. return (m_pdictBase->SetStringA(pszTmp,chCount,pszValue));
  230. }
  231. HRESULT STDMETHODCALLTYPE CSEOSubDictionary::SetStringW(LPCWSTR pszName, DWORD chCount, LPCWSTR pszValue) {
  232. LPWSTR pszTmp = ALLOC_NAME_W(m_pszPrefixW,pszName);
  233. if (!m_pdictBase) {
  234. return (E_OUTOFMEMORY);
  235. }
  236. return (m_pdictBase->SetStringW(pszTmp,chCount,pszValue));
  237. }
  238. HRESULT STDMETHODCALLTYPE CSEOSubDictionary::GetDWordA(LPCSTR pszName, DWORD *pdwResult) {
  239. LPSTR pszTmp = ALLOC_NAME_A(m_pszPrefixA,pszName);
  240. if (!m_pdictBase) {
  241. return (SEO_E_NOTPRESENT);
  242. }
  243. return (m_pdictBase->GetDWordA(pszTmp,pdwResult));
  244. }
  245. HRESULT STDMETHODCALLTYPE CSEOSubDictionary::GetDWordW(LPCWSTR pszName, DWORD *pdwResult) {
  246. LPWSTR pszTmp = ALLOC_NAME_W(m_pszPrefixW,pszName);
  247. if (!m_pdictBase) {
  248. return (SEO_E_NOTPRESENT);
  249. }
  250. return (m_pdictBase->GetDWordW(pszTmp,pdwResult));
  251. }
  252. HRESULT STDMETHODCALLTYPE CSEOSubDictionary::SetDWordA(LPCSTR pszName, DWORD dwValue) {
  253. LPSTR pszTmp = ALLOC_NAME_A(m_pszPrefixA,pszName);
  254. if (!m_pdictBase) {
  255. return (E_OUTOFMEMORY);
  256. }
  257. return (m_pdictBase->SetDWordA(pszTmp,dwValue));
  258. }
  259. HRESULT STDMETHODCALLTYPE CSEOSubDictionary::SetDWordW(LPCWSTR pszName, DWORD dwValue) {
  260. LPWSTR pszTmp = ALLOC_NAME_W(m_pszPrefixW,pszName);
  261. if (!m_pdictBase) {
  262. return (E_OUTOFMEMORY);
  263. }
  264. return (m_pdictBase->SetDWordW(pszTmp,dwValue));
  265. }
  266. HRESULT STDMETHODCALLTYPE CSEOSubDictionary::GetInterfaceA(LPCSTR pszName, REFIID iidDesired, IUnknown **ppunkResult) {
  267. LPSTR pszTmp = ALLOC_NAME_A(m_pszPrefixA,pszName);
  268. if (!m_pdictBase) {
  269. return (SEO_E_NOTPRESENT);
  270. }
  271. return (m_pdictBase->GetInterfaceA(pszTmp,iidDesired,ppunkResult));
  272. }
  273. HRESULT STDMETHODCALLTYPE CSEOSubDictionary::GetInterfaceW(LPCWSTR pszName, REFIID iidDesired, IUnknown **ppunkResult) {
  274. LPWSTR pszTmp = ALLOC_NAME_W(m_pszPrefixW,pszName);
  275. if (!m_pdictBase) {
  276. return (SEO_E_NOTPRESENT);
  277. }
  278. return (m_pdictBase->GetInterfaceW(pszTmp,iidDesired,ppunkResult));
  279. }
  280. HRESULT STDMETHODCALLTYPE CSEOSubDictionary::SetInterfaceA(LPCSTR pszName, IUnknown *punkValue) {
  281. LPSTR pszTmp = ALLOC_NAME_A(m_pszPrefixA,pszName);
  282. if (!m_pdictBase) {
  283. return (E_OUTOFMEMORY);
  284. }
  285. return (m_pdictBase->SetInterfaceA(pszTmp,punkValue));
  286. }
  287. HRESULT STDMETHODCALLTYPE CSEOSubDictionary::SetInterfaceW(LPCWSTR pszName, IUnknown *punkValue) {
  288. LPWSTR pszTmp = ALLOC_NAME_W(m_pszPrefixW,pszName);
  289. if (!m_pdictBase) {
  290. return (E_OUTOFMEMORY);
  291. }
  292. return (m_pdictBase->SetInterfaceW(pszTmp,punkValue));
  293. }