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.

687 lines
12 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved
  3. Module Name:
  4. RmsClien.cpp
  5. Abstract:
  6. Implementation of CRmsClient
  7. Author:
  8. Brian Dodd [brian] 15-Nov-1996
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "RmsClien.h"
  13. /////////////////////////////////////////////////////////////////////////////
  14. //
  15. STDMETHODIMP
  16. CRmsClient::CompareTo(
  17. IN IUnknown *pCollectable,
  18. OUT SHORT *pResult
  19. )
  20. /*++
  21. Implements:
  22. IWsbCollectable::CompareTo
  23. --*/
  24. {
  25. HRESULT hr = E_FAIL;
  26. SHORT result = 1;
  27. WsbTraceIn( OLESTR("CRmsClient::CompareTo"), OLESTR("") );
  28. try {
  29. // Validate arguments - Okay if pResult is NULL
  30. WsbAssertPointer( pCollectable );
  31. CComQIPtr<IRmsClient, &IID_IRmsClient> pClient = pCollectable;
  32. WsbAssertPointer( pClient );
  33. CComQIPtr<IRmsComObject, &IID_IRmsComObject> pObject = pCollectable;
  34. WsbAssertPointer( pObject );
  35. switch ( m_findBy ) {
  36. case RmsFindByClassId:
  37. {
  38. CLSID ownerClassId;
  39. // Get owner class Id
  40. WsbAffirmHr(pClient->GetOwnerClassId( &ownerClassId ) );
  41. if ( m_ownerClassId == ownerClassId ) {
  42. // Owner ClassId matches
  43. hr = S_OK;
  44. result = 0;
  45. }
  46. else {
  47. hr = S_FALSE;
  48. result = 1;
  49. }
  50. }
  51. break;
  52. case RmsFindByName:
  53. {
  54. CWsbBstrPtr name;
  55. CWsbBstrPtr password;
  56. // Get name
  57. WsbAffirmHr(pClient->GetName( &name ) );
  58. if ( m_Name == name ) {
  59. // Names match, now try password
  60. // Get password
  61. WsbAffirmHr(pClient->GetPassword( &password ) );
  62. if ( m_password == password ) {
  63. // Passwords match
  64. hr = S_OK;
  65. result = 0;
  66. }
  67. else {
  68. hr = S_FALSE;
  69. result = 1;
  70. }
  71. }
  72. else {
  73. hr = S_FALSE;
  74. result = 1;
  75. }
  76. }
  77. break;
  78. case RmsFindByObjectId:
  79. default:
  80. // Do CompareTo for object
  81. hr = CRmsComObject::CompareTo( pCollectable, &result );
  82. break;
  83. }
  84. }
  85. WsbCatch(hr);
  86. if ( SUCCEEDED(hr) && (0 != pResult) ){
  87. *pResult = result;
  88. }
  89. WsbTraceOut( OLESTR("CRmsClient::CompareTo"),
  90. OLESTR("hr = <%ls>, result = <%ls>"),
  91. WsbHrAsString( hr ), WsbPtrToShortAsString( pResult ) );
  92. return hr;
  93. }
  94. HRESULT
  95. CRmsClient::FinalConstruct(
  96. void
  97. )
  98. /*++
  99. Implements:
  100. CComObjectRoot::FinalConstruct
  101. --*/
  102. {
  103. HRESULT hr = S_OK;
  104. try {
  105. WsbAssertHr(CWsbObject::FinalConstruct());
  106. // Initialize data
  107. m_ownerClassId = GUID_NULL;
  108. m_password = RMS_UNDEFINED_STRING;
  109. m_sizeofInfo = 0;
  110. // memset(m_info, 0, MaxInfo);
  111. m_verifierClass = GUID_NULL;
  112. m_portalClass = GUID_NULL;
  113. } WsbCatch(hr);
  114. return(hr);
  115. }
  116. STDMETHODIMP
  117. CRmsClient::GetClassID(
  118. OUT CLSID* pClsid
  119. )
  120. /*++
  121. Implements:
  122. IPersist::GetClassID
  123. --*/
  124. {
  125. HRESULT hr = S_OK;
  126. WsbTraceIn(OLESTR("CRmsClient::GetClassID"), OLESTR(""));
  127. try {
  128. WsbAssert(0 != pClsid, E_POINTER);
  129. *pClsid = CLSID_CRmsClient;
  130. } WsbCatch(hr);
  131. WsbTraceOut(OLESTR("CRmsClient::GetClassID"), OLESTR("hr = <%ls>, CLSID = <%ls>"), WsbHrAsString(hr), WsbGuidAsString(*pClsid));
  132. return(hr);
  133. }
  134. STDMETHODIMP
  135. CRmsClient::GetSizeMax(
  136. OUT ULARGE_INTEGER* pcbSize
  137. )
  138. /*++
  139. Implements:
  140. IPersistStream::GetSizeMax
  141. --*/
  142. {
  143. HRESULT hr = E_NOTIMPL;
  144. // ULONG nameLen;
  145. // ULONG passwordLen;
  146. WsbTraceIn(OLESTR("CRmsClient::GetSizeMax"), OLESTR(""));
  147. // try {
  148. // WsbAssert(0 != pcbSize, E_POINTER);
  149. // nameLen = SysStringByteLen(m_name);
  150. // passwordLen = SysStringByteLen(m_password);
  151. // // set up maximum size
  152. // pcbSize->QuadPart = WsbPersistSizeOf(CLSID) + // m_ownerClassId
  153. // WsbPersistSizeOf(LONG) + // length of m_name
  154. // nameLen + // m_name
  155. // WsbPersistSizeOf(LONG) + // length of m_password
  156. // nameLen + // m_password
  157. //// WsbPersistSizeOf(SHORT) + // m_sizeofInfo
  158. //// MaxInfo + // m_info
  159. // WsbPersistSizeOf(CLSID) + // m_sizeofInfo
  160. // WsbPersistSizeOf(CLSID); // m_sizeofInfo
  161. // } WsbCatch(hr);
  162. WsbTraceOut(OLESTR("CRmsClient::GetSizeMax"), OLESTR("hr = <%ls>, Size = <%ls>"), WsbHrAsString(hr), WsbPtrToUliAsString(pcbSize));
  163. return(hr);
  164. }
  165. STDMETHODIMP
  166. CRmsClient::Load(
  167. IN IStream* pStream
  168. )
  169. /*++
  170. Implements:
  171. IPersistStream::Load
  172. --*/
  173. {
  174. HRESULT hr = S_OK;
  175. ULONG ulBytes = 0;
  176. WsbTraceIn(OLESTR("CRmsClient::Load"), OLESTR(""));
  177. try {
  178. WsbAssert(0 != pStream, E_POINTER);
  179. WsbAffirmHr(CRmsComObject::Load(pStream));
  180. // Read value
  181. WsbAffirmHr(WsbLoadFromStream(pStream, &m_ownerClassId));
  182. WsbAffirmHr(WsbBstrFromStream(pStream, &m_password));
  183. WsbAffirmHr(WsbLoadFromStream(pStream, &m_sizeofInfo));
  184. // WsbAffirmHr(WsbLoadFromStream(pStream, &m_info));
  185. WsbAffirmHr(WsbLoadFromStream(pStream, &m_verifierClass));
  186. WsbAffirmHr(WsbLoadFromStream(pStream, &m_portalClass));
  187. } WsbCatch(hr);
  188. WsbTraceOut(OLESTR("CRmsClient::Load"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  189. return(hr);
  190. }
  191. STDMETHODIMP
  192. CRmsClient::Save(
  193. IN IStream* pStream,
  194. IN BOOL clearDirty
  195. )
  196. /*++
  197. Implements:
  198. IPersistStream::Save
  199. --*/
  200. {
  201. HRESULT hr = S_OK;
  202. ULONG ulBytes = 0;
  203. WsbTraceIn(OLESTR("CRmsClient::Save"), OLESTR("clearDirty = <%ls>"), WsbBoolAsString(clearDirty));
  204. try {
  205. WsbAssert(0 != pStream, E_POINTER);
  206. WsbAffirmHr(CRmsComObject::Save(pStream, clearDirty));
  207. // Save value
  208. WsbAffirmHr(WsbSaveToStream(pStream, m_ownerClassId));
  209. WsbAffirmHr(WsbBstrToStream(pStream, m_password));
  210. WsbAffirmHr(WsbSaveToStream(pStream, m_sizeofInfo));
  211. // WsbAffirmHr(WsbSaveToStream(pStream, m_info));
  212. WsbAffirmHr(WsbSaveToStream(pStream, m_verifierClass));
  213. WsbAffirmHr(WsbSaveToStream(pStream, m_portalClass));
  214. // Do we need to clear the dirty bit?
  215. if (clearDirty) {
  216. m_isDirty = FALSE;
  217. }
  218. } WsbCatch(hr);
  219. WsbTraceOut(OLESTR("CRmsClient::Save"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  220. return(hr);
  221. }
  222. STDMETHODIMP
  223. CRmsClient::Test(
  224. OUT USHORT *pPassed,
  225. OUT USHORT *pFailed
  226. )
  227. /*++
  228. Implements:
  229. IWsbTestable::Test
  230. --*/
  231. {
  232. HRESULT hr = S_OK;
  233. CComPtr<IRmsClient> pClient1;
  234. CComPtr<IRmsClient> pClient2;
  235. CComPtr<IPersistFile> pFile1;
  236. CComPtr<IPersistFile> pFile2;
  237. CLSID clsidWork1;
  238. CLSID clsidWork2;
  239. CWsbBstrPtr bstrVal1 = OLESTR("5A5A5A");
  240. CWsbBstrPtr bstrWork1;
  241. CWsbBstrPtr bstrWork2;
  242. WsbTraceIn(OLESTR("CRmsClient::Test"), OLESTR(""));
  243. try {
  244. // Get the Client interface.
  245. hr = S_OK;
  246. try {
  247. WsbAssertHr(((IUnknown*) (IRmsClient*) this)->QueryInterface(IID_IRmsClient, (void**) &pClient1));
  248. // Test SetOwnerClassId & GetOwnerClassId
  249. clsidWork1 = CLSID_NULL;
  250. SetOwnerClassId(clsidWork1);
  251. GetOwnerClassId(&clsidWork2);
  252. if(clsidWork1 == clsidWork2){
  253. (*pPassed)++;
  254. } else {
  255. (*pFailed)++;
  256. }
  257. // Test SetName & GetName interface
  258. bstrWork1 = bstrVal1;
  259. SetName(bstrWork1);
  260. GetName(&bstrWork2);
  261. if (bstrWork1 == bstrWork2){
  262. (*pPassed)++;
  263. } else {
  264. (*pFailed)++;
  265. }
  266. // Test SetPassword & GetPassword interface
  267. bstrWork1 = bstrVal1;
  268. SetPassword(bstrWork1);
  269. GetPassword(&bstrWork2);
  270. if (bstrWork1 == bstrWork2){
  271. (*pPassed)++;
  272. } else {
  273. (*pFailed)++;
  274. }
  275. // Test SetVerifierClass & GetVerifierClass
  276. clsidWork1 = CLSID_NULL;
  277. SetVerifierClass(clsidWork1);
  278. GetVerifierClass(&clsidWork2);
  279. if(clsidWork1 == clsidWork2){
  280. (*pPassed)++;
  281. } else {
  282. (*pFailed)++;
  283. }
  284. // Test SetPortalClass & GetPortalClass
  285. clsidWork1 = CLSID_NULL;
  286. SetPortalClass(clsidWork1);
  287. GetPortalClass(&clsidWork2);
  288. if(clsidWork1 == clsidWork2){
  289. (*pPassed)++;
  290. } else {
  291. (*pFailed)++;
  292. }
  293. } WsbCatch(hr);
  294. // Tally up the results
  295. hr = S_OK;
  296. if (*pFailed) {
  297. hr = S_FALSE;
  298. }
  299. } WsbCatch(hr);
  300. WsbTraceOut(OLESTR("CRmsClient::Test"), OLESTR("hr = <%ls>"), WsbHrAsString(hr));
  301. return(hr);
  302. }
  303. STDMETHODIMP
  304. CRmsClient::GetOwnerClassId(
  305. CLSID *pClassId
  306. )
  307. /*++
  308. Implements:
  309. IRmsClient::GetOwnerClassId
  310. --*/
  311. {
  312. *pClassId = m_ownerClassId;
  313. return S_OK;
  314. }
  315. STDMETHODIMP
  316. CRmsClient::SetOwnerClassId(
  317. CLSID classId
  318. )
  319. /*++
  320. Implements:
  321. IRmsClient::SetOwnerClassId
  322. --*/
  323. {
  324. m_ownerClassId = classId;
  325. m_isDirty = TRUE;
  326. return S_OK;
  327. }
  328. STDMETHODIMP
  329. CRmsClient::GetName(
  330. BSTR *pName
  331. )
  332. /*++
  333. Implements:
  334. IRmsClient::GetName
  335. --*/
  336. {
  337. WsbAssertPointer (pName);
  338. m_Name. CopyToBstr (pName);
  339. return S_OK;
  340. }
  341. STDMETHODIMP
  342. CRmsClient::SetName(
  343. BSTR name
  344. )
  345. /*++
  346. Implements:
  347. IRmsClient::SetName
  348. --*/
  349. {
  350. m_Name = name;
  351. m_isDirty = TRUE;
  352. return S_OK;
  353. }
  354. STDMETHODIMP
  355. CRmsClient::GetPassword(
  356. BSTR *pPassword
  357. )
  358. /*++
  359. Implements:
  360. IRmsClient::GetPassword
  361. --*/
  362. {
  363. WsbAssertPointer (pPassword);
  364. m_password. CopyToBstr (pPassword);
  365. return S_OK;
  366. }
  367. STDMETHODIMP
  368. CRmsClient::SetPassword(
  369. BSTR password
  370. )
  371. /*++
  372. Implements:
  373. IRmsClient::SetPassword
  374. --*/
  375. {
  376. m_password = password;
  377. m_isDirty = TRUE;
  378. return S_OK;
  379. }
  380. STDMETHODIMP
  381. CRmsClient::GetInfo(
  382. UCHAR *pInfo,
  383. SHORT *pSize
  384. )
  385. /*++
  386. Implements:
  387. IRmsClient::GetInfo
  388. --*/
  389. {
  390. memmove (pInfo, m_info, m_sizeofInfo);
  391. *pSize = m_sizeofInfo;
  392. return S_OK;
  393. }
  394. STDMETHODIMP
  395. CRmsClient::SetInfo(
  396. UCHAR *pInfo,
  397. SHORT size
  398. )
  399. /*++
  400. Implements:
  401. IRmsClient::SetInfo
  402. --*/
  403. {
  404. memmove (m_info, pInfo, size);
  405. m_sizeofInfo = size;
  406. m_isDirty = TRUE;
  407. return S_OK;
  408. }
  409. STDMETHODIMP
  410. CRmsClient::GetVerifierClass(
  411. CLSID *pClassId
  412. )
  413. /*++
  414. Implements:
  415. IRmsClient::GetVerifierClass
  416. --*/
  417. {
  418. *pClassId = m_verifierClass;
  419. return S_OK;
  420. }
  421. STDMETHODIMP
  422. CRmsClient::SetVerifierClass(
  423. CLSID classId
  424. )
  425. /*++
  426. Implements:
  427. IRmsClient::GetVerifierClass
  428. --*/
  429. {
  430. m_verifierClass = classId;
  431. m_isDirty = TRUE;
  432. return S_OK;
  433. }
  434. STDMETHODIMP
  435. CRmsClient::GetPortalClass(
  436. CLSID *pClassId
  437. )
  438. /*++
  439. Implements:
  440. IRmsClient::GetPortalClass
  441. --*/
  442. {
  443. *pClassId = m_portalClass;
  444. return S_OK;
  445. }
  446. STDMETHODIMP
  447. CRmsClient::SetPortalClass(
  448. CLSID classId
  449. )
  450. /*++
  451. Implements:
  452. IRmsClient::SetPortalClass
  453. --*/
  454. {
  455. m_portalClass = classId;
  456. m_isDirty = TRUE;
  457. return S_OK;
  458. }