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.

258 lines
8.1 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright(C) 2000 Microsoft Corporation all rights reserved.
  4. //
  5. // Module: ObjectsCommand.H
  6. //
  7. // Project: Windows 2000 IAS
  8. //
  9. // Description: Declaration of the the Object Commands classes
  10. //
  11. // Author: tperraut
  12. //
  13. // Revision 02/24/2000 created
  14. //
  15. /////////////////////////////////////////////////////////////////////////////
  16. #include "stdafx.h"
  17. #include "Objects.h"
  18. //////////////////////////////////////////////////////////////////////////////
  19. // class CObjectsCommandGet
  20. //////////////////////////////////////////////////////////////////////////////
  21. CObjects::CObjectsCommandGet::CObjectsCommandGet(CSession& CurrentSession)
  22. {
  23. Init(CurrentSession);
  24. }
  25. /////////////
  26. // GetObject
  27. /////////////
  28. HRESULT CObjects::CObjectsCommandGet::GetObject(
  29. _bstr_t& Name,
  30. LONG& Identity,
  31. LONG Parent
  32. )
  33. {
  34. m_ParentParam = Parent;
  35. HRESULT hr = BaseExecute();
  36. if ( SUCCEEDED(hr) )
  37. {
  38. Identity = m_Identity;
  39. Name = m_Name;
  40. }
  41. return hr;
  42. }
  43. /////////////////////////
  44. // GetObject overloaded
  45. /////////////////////////
  46. HRESULT CObjects::CObjectsCommandGet::GetObject(
  47. _bstr_t& Name,
  48. LONG& Identity,
  49. LONG Parent,
  50. LONG Index
  51. )
  52. {
  53. m_ParentParam = Parent;
  54. HRESULT hr = BaseExecute(Index);
  55. if ( SUCCEEDED(hr) )
  56. {
  57. Identity = m_Identity;
  58. Name = m_Name;
  59. }
  60. return hr;
  61. }
  62. //////////////////////////////////////////////////////////////////////////////
  63. // class CObjectsCommandPath
  64. //////////////////////////////////////////////////////////////////////////////
  65. CObjects::CObjectsCommandPath::CObjectsCommandPath(CSession& CurrentSession)
  66. {
  67. Init(CurrentSession);
  68. }
  69. ////////////
  70. // WalkPath
  71. ////////////
  72. void CObjects::CObjectsCommandPath::WalkPath(
  73. LPCWSTR Path,
  74. LONG& Identity,
  75. LONG Parent // = 1 in header
  76. )
  77. {
  78. _ASSERTE(Path);
  79. if ( !Path )
  80. {
  81. _com_issue_error(E_INVALIDARG);
  82. }
  83. LONG CurrentParent = Parent;
  84. const WCHAR *p = Path;
  85. while ( *p ) // ok to dereference
  86. {
  87. m_ParentParam = CurrentParent;
  88. lstrcpynW(m_NameParam, p, NAME_SIZE);
  89. _com_util::CheckError(BaseExecute());
  90. CurrentParent = m_Identity;
  91. p += lstrlenW(p);
  92. // go past the \0
  93. ++p;
  94. }
  95. Identity = CurrentParent;
  96. }
  97. //////////////////////////////////////////////////////////////////////////////
  98. // class CObjectsCommandIdentity
  99. //////////////////////////////////////////////////////////////////////////////
  100. CObjects::CObjectsCommandIdentity::CObjectsCommandIdentity(
  101. CSession& CurrentSession
  102. )
  103. {
  104. Init(CurrentSession);
  105. }
  106. /////////////////////
  107. // GetObjectIdentity
  108. /////////////////////
  109. HRESULT CObjects::CObjectsCommandIdentity::GetObjectIdentity(
  110. _bstr_t& Name,
  111. LONG& Parent,
  112. LONG Identity
  113. )
  114. {
  115. m_IdentityParam = Identity;
  116. HRESULT hr = BaseExecute();
  117. if ( SUCCEEDED(hr) )
  118. {
  119. Name = m_Name;
  120. Parent = m_Parent;
  121. }
  122. return hr;
  123. }
  124. //////////////////////////////////////////////////////////////////////////////
  125. // class CObjectsCommandNameParent
  126. //////////////////////////////////////////////////////////////////////////////
  127. CObjects::CObjectsCommandNameParent::CObjectsCommandNameParent(
  128. CSession& CurrentSession
  129. )
  130. {
  131. Init(CurrentSession);
  132. }
  133. ////////////////////////////////////////
  134. // GetObjectNameParent
  135. //
  136. // works on CObjectsAccSelectNameParent
  137. ////////////////////////////////////////
  138. HRESULT CObjects::CObjectsCommandNameParent::GetObjectNameParent(
  139. const _bstr_t& Name,
  140. LONG Parent,
  141. LONG& Identity
  142. )
  143. {
  144. lstrcpynW(m_NameParam, Name, NAME_SIZE);
  145. m_ParentParam = Parent;
  146. HRESULT hr = BaseExecute();
  147. if ( SUCCEEDED(hr) )
  148. {
  149. Identity = m_Identity;
  150. }
  151. return hr;
  152. }
  153. //////////////////////////////////////////////////////////////////////////////
  154. // class CObjectsCommandDelete
  155. //////////////////////////////////////////////////////////////////////////////
  156. CObjects::CObjectsCommandDelete::CObjectsCommandDelete(
  157. CSession& CurrentSession
  158. )
  159. {
  160. Init(CurrentSession);
  161. }
  162. //////////////////////////////
  163. // DeleteObject
  164. //
  165. // works on CObjectsAccDelete
  166. //////////////////////////////
  167. HRESULT CObjects::CObjectsCommandDelete::DeleteObject(LONG Identity)
  168. {
  169. // Set properties for open
  170. CDBPropSet propset(DBPROPSET_ROWSET);
  171. propset.AddProperty(DBPROP_IRowsetChange, true);
  172. propset.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE |
  173. DBPROPVAL_UP_DELETE);
  174. m_IdentityParam = Identity;
  175. HRESULT hr = Open(&propset);
  176. Close();
  177. return hr;
  178. }
  179. //////////////////////////////////////////////////////////////////////////////
  180. // class CObjectsCommandInsert
  181. //////////////////////////////////////////////////////////////////////////////
  182. CObjects::CObjectsCommandInsert::CObjectsCommandInsert(
  183. CSession& CurrentSession
  184. )
  185. :m_Session(CurrentSession)
  186. {
  187. Init(CurrentSession);
  188. }
  189. //////////////////////////////
  190. // InsertObject
  191. //
  192. // works on CObjectsAccInsert
  193. //////////////////////////////
  194. BOOL CObjects::CObjectsCommandInsert::InsertObject(
  195. const _bstr_t& Name,
  196. LONG Parent,
  197. LONG& Identity
  198. )
  199. {
  200. ClearRecord();
  201. CDBPropSet propset(DBPROPSET_ROWSET);
  202. propset.AddProperty(DBPROP_IRowsetChange, true);
  203. propset.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE |
  204. DBPROPVAL_UP_INSERT );
  205. lstrcpynW(m_NameParam, Name, NAME_SIZE);
  206. m_ParentParam = Parent;
  207. HRESULT hr = Open(&propset);
  208. if ( hr == S_OK )
  209. {
  210. CObjectsCommandNameParent NameParent(m_Session);
  211. _com_util::CheckError(NameParent.GetObjectNameParent(
  212. Name,
  213. Parent,
  214. Identity
  215. ));
  216. Close();
  217. return TRUE;
  218. }
  219. else
  220. {
  221. // ignore the real error.
  222. // the assumption here is that if I can't insert, that's because
  223. // the object already exists
  224. return FALSE;
  225. }
  226. }