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.

358 lines
7.2 KiB

  1. #include "oleds.hxx"
  2. #pragma hdrstop
  3. #define DISPID_REGULAR 1
  4. // Class CADsNamespaces
  5. DEFINE_IDispatch_Implementation(CADsNamespaces)
  6. DEFINE_IADs_Implementation(CADsNamespaces)
  7. CADsNamespaces::CADsNamespaces():
  8. _pDispMgr(NULL),
  9. _bstrDefaultContainer(NULL)
  10. {
  11. VariantInit(&_vFilter);
  12. ENLIST_TRACKING(CADsNamespaces);
  13. }
  14. HRESULT
  15. CADsNamespaces::CreateNamespaces(
  16. BSTR Parent,
  17. BSTR NamespacesName,
  18. DWORD dwObjectState,
  19. REFIID riid,
  20. void **ppvObj
  21. )
  22. {
  23. CADsNamespaces FAR * pNamespaces = NULL;
  24. HRESULT hr = S_OK;
  25. hr = AllocateNamespacesObject(&pNamespaces);
  26. BAIL_ON_FAILURE(hr);
  27. hr = pNamespaces->InitializeCoreObject(Parent,
  28. NamespacesName,
  29. L"Namespaces",
  30. CLSID_ADsNamespaces,
  31. dwObjectState);
  32. BAIL_ON_FAILURE(hr);
  33. hr = pNamespaces->QueryInterface(riid, ppvObj);
  34. BAIL_ON_FAILURE(hr);
  35. pNamespaces->Release();
  36. RRETURN(hr);
  37. error:
  38. delete pNamespaces;
  39. RRETURN_EXP_IF_ERR(hr);
  40. }
  41. CADsNamespaces::~CADsNamespaces( )
  42. {
  43. ADsFreeString(_bstrDefaultContainer);
  44. delete _pDispMgr;
  45. }
  46. STDMETHODIMP
  47. CADsNamespaces::QueryInterface(
  48. REFIID iid,
  49. LPVOID FAR* ppv
  50. )
  51. {
  52. if (IsEqualIID(iid, IID_IUnknown))
  53. {
  54. *ppv = (IADs FAR *)this;
  55. }
  56. else if (IsEqualIID(iid, IID_IDispatch))
  57. {
  58. *ppv = (IADs FAR *)this;
  59. }
  60. else if (IsEqualIID(iid, IID_ISupportErrorInfo))
  61. {
  62. *ppv = (ISupportErrorInfo FAR *) this;
  63. }
  64. else if (IsEqualIID(iid, IID_IADsContainer))
  65. {
  66. *ppv = (IADsContainer FAR *) this;
  67. }
  68. else if (IsEqualIID(iid, IID_IADsNamespaces))
  69. {
  70. *ppv = (IADsNamespaces FAR *) this;
  71. }
  72. else if (IsEqualIID(iid, IID_IADs))
  73. {
  74. *ppv = (IADs FAR *) this;
  75. }
  76. else
  77. {
  78. *ppv = NULL;
  79. return E_NOINTERFACE;
  80. }
  81. AddRef();
  82. return NOERROR;
  83. }
  84. //
  85. // ISupportErrorInfo method
  86. //
  87. STDMETHODIMP
  88. CADsNamespaces::InterfaceSupportsErrorInfo(THIS_ REFIID riid)
  89. {
  90. if (IsEqualIID(riid, IID_IADs) ||
  91. IsEqualIID(riid, IID_IADsContainer) ||
  92. IsEqualIID(riid, IID_IADsNamespaces)) {
  93. return S_OK;
  94. } else {
  95. return S_FALSE;
  96. }
  97. }
  98. STDMETHODIMP
  99. CADsNamespaces::SetInfo()
  100. {
  101. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  102. }
  103. STDMETHODIMP
  104. CADsNamespaces::GetInfo()
  105. {
  106. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  107. }
  108. /* IADsContainer methods */
  109. STDMETHODIMP
  110. CADsNamespaces::get_Count(long FAR* retval)
  111. {
  112. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  113. }
  114. STDMETHODIMP
  115. CADsNamespaces::get_Filter(THIS_ VARIANT FAR* pVar)
  116. {
  117. HRESULT hr;
  118. VariantInit(pVar);
  119. hr = VariantCopy(pVar, &_vFilter);
  120. RRETURN_EXP_IF_ERR(hr);
  121. }
  122. STDMETHODIMP
  123. CADsNamespaces::put_Filter(THIS_ VARIANT Var)
  124. {
  125. HRESULT hr;
  126. VariantClear(&_vFilter);
  127. hr = VariantCopy(&_vFilter, &Var);
  128. RRETURN_EXP_IF_ERR(hr);
  129. }
  130. STDMETHODIMP
  131. CADsNamespaces::get_Hints(THIS_ VARIANT FAR* pHints)
  132. {
  133. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  134. }
  135. STDMETHODIMP
  136. CADsNamespaces::put_Hints(THIS_ VARIANT Hints)
  137. {
  138. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  139. }
  140. STDMETHODIMP
  141. CADsNamespaces::GetObject(
  142. THIS_ BSTR ClassName,
  143. BSTR RelativeName,
  144. IDispatch * FAR* ppObject
  145. )
  146. {
  147. WCHAR szBuffer[MAX_PATH];
  148. HRESULT hr = S_OK;
  149. if (!RelativeName || !*RelativeName) {
  150. RRETURN(E_ADS_UNKNOWN_OBJECT);
  151. }
  152. // for namespace, we do not expect that it will have more than MAX_PATH characters
  153. if(wcslen(RelativeName) >= MAX_PATH)
  154. {
  155. RRETURN(E_ADS_BAD_PARAMETER);
  156. }
  157. wcscpy(szBuffer, RelativeName);
  158. hr = ::GetObject(
  159. szBuffer,
  160. IID_IDispatch,
  161. (LPVOID *)ppObject,
  162. TRUE
  163. );
  164. BAIL_ON_FAILURE(hr);
  165. error:
  166. RRETURN_EXP_IF_ERR(hr);
  167. }
  168. STDMETHODIMP
  169. CADsNamespaces::get__NewEnum(THIS_ IUnknown * FAR* retval)
  170. {
  171. HRESULT hr;
  172. IUnknown FAR* punkEnum=NULL;
  173. IEnumVARIANT * penum = NULL;
  174. *retval = NULL;
  175. //
  176. // Create new enumerator for items currently
  177. // in collection and QI for IUnknown
  178. //
  179. hr = CEnumVariant::Create(&penum);
  180. if (FAILED(hr)){
  181. goto error;
  182. }
  183. hr = penum->QueryInterface(IID_IUnknown,
  184. (VOID FAR* FAR*)retval);
  185. if (FAILED(hr)){
  186. goto error;
  187. }
  188. if (penum) {
  189. penum->Release();
  190. }
  191. return NOERROR;
  192. error:
  193. if (penum) {
  194. delete penum;
  195. }
  196. RRETURN_EXP_IF_ERR(hr);
  197. }
  198. //
  199. // IADsNamespaces methods
  200. //
  201. STDMETHODIMP
  202. CADsNamespaces::get_DefaultContainer(THIS_ BSTR FAR* retval)
  203. {
  204. LPTSTR pszDefContainer = NULL;
  205. HRESULT hr;
  206. hr = QueryKeyValue(DEF_CONT_REG_LOCATION,
  207. TEXT("DefaultContainer"),
  208. &pszDefContainer);
  209. BAIL_IF_ERROR(hr);
  210. hr = ADsAllocString(pszDefContainer, retval);
  211. cleanup:
  212. if(pszDefContainer){
  213. FreeADsMem(pszDefContainer);
  214. }
  215. RRETURN_EXP_IF_ERR(hr);
  216. }
  217. STDMETHODIMP
  218. CADsNamespaces::put_DefaultContainer(THIS_ BSTR bstrDefaultContainer)
  219. {
  220. HRESULT hr = S_OK;
  221. hr = SetKeyAndValue(DEF_CONT_REG_LOCATION,
  222. TEXT("DefaultContainer"),
  223. NULL,
  224. bstrDefaultContainer);
  225. RRETURN_EXP_IF_ERR(hr);
  226. }
  227. STDMETHODIMP
  228. CADsNamespaces::Create(THIS_ BSTR ClassName, BSTR RelativeName, IDispatch * FAR* ppObject)
  229. {
  230. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  231. }
  232. STDMETHODIMP
  233. CADsNamespaces::Delete(THIS_ BSTR SourceName, BSTR Type)
  234. {
  235. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  236. }
  237. STDMETHODIMP
  238. CADsNamespaces::CopyHere(THIS_ BSTR SourceName, BSTR NewName, IDispatch * FAR* ppObject)
  239. {
  240. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  241. }
  242. STDMETHODIMP
  243. CADsNamespaces::MoveHere(
  244. THIS_ BSTR SourceName,
  245. BSTR NewName,
  246. IDispatch * FAR* ppObject
  247. )
  248. {
  249. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  250. }
  251. HRESULT
  252. CADsNamespaces::AllocateNamespacesObject(
  253. CADsNamespaces ** ppNamespaces
  254. )
  255. {
  256. CADsNamespaces FAR * pNamespaces = NULL;
  257. CDispatchMgr FAR * pDispMgr = NULL;
  258. HRESULT hr = S_OK;
  259. pNamespaces = new CADsNamespaces();
  260. if (pNamespaces == NULL) {
  261. hr = E_OUTOFMEMORY;
  262. }
  263. BAIL_ON_FAILURE(hr);
  264. pDispMgr = new CDispatchMgr;
  265. if (pDispMgr == NULL) {
  266. hr = E_OUTOFMEMORY;
  267. }
  268. BAIL_ON_FAILURE(hr);
  269. hr = LoadTypeInfoEntry(pDispMgr,
  270. LIBID_ADs,
  271. IID_IADs,
  272. (IADs *)pNamespaces,
  273. DISPID_REGULAR);
  274. BAIL_ON_FAILURE(hr);
  275. hr = LoadTypeInfoEntry(pDispMgr,
  276. LIBID_ADs,
  277. IID_IADsContainer,
  278. (IADsContainer *)pNamespaces,
  279. DISPID_NEWENUM);
  280. BAIL_ON_FAILURE(hr);
  281. pNamespaces->_pDispMgr = pDispMgr;
  282. *ppNamespaces = pNamespaces;
  283. RRETURN(hr);
  284. error:
  285. delete pNamespaces;
  286. delete pDispMgr;
  287. RRETURN_EXP_IF_ERR(hr);
  288. }