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.

582 lines
14 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995
  5. //
  6. // File: cfpnwres.cxx
  7. //
  8. // Contents: Contains methods for the following objects
  9. // CFPNWResource, CFPNWFSResourceGeneralInfo
  10. //
  11. //
  12. // History: 05/01/96 ramv (Ram Viswanathan) Created.
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "winnt.hxx"
  16. #pragma hdrstop
  17. #define INITGUID
  18. DECLARE_INFOLEVEL( FPNWResource );
  19. DECLARE_DEBUG( FPNWResource );
  20. #define FPNWResourceDebugOut(x) FPNWResourceInlineDebugOut x
  21. DEFINE_IDispatch_ExtMgr_Implementation(CFPNWResource);
  22. DEFINE_IADsExtension_ExtMgr_Implementation(CFPNWResource);
  23. DEFINE_IADs_TempImplementation(CFPNWResource);
  24. DEFINE_IADs_PutGetImplementation(CFPNWResource,FPNWResourceClass,gdwFPNWResourceTableSize) ;
  25. DEFINE_IADsPropertyList_Implementation(CFPNWResource, FPNWResourceClass,gdwFPNWResourceTableSize)
  26. CFPNWResource::CFPNWResource()
  27. {
  28. _pDispMgr = NULL;
  29. _pExtMgr = NULL;
  30. _pszServerName = NULL;
  31. _pPropertyCache = NULL;
  32. ENLIST_TRACKING(CFPNWResource);
  33. return;
  34. }
  35. CFPNWResource::~CFPNWResource()
  36. {
  37. delete _pExtMgr; // created last, destroyed first
  38. delete _pDispMgr;
  39. if(_pszServerName){
  40. FreeADsStr(_pszServerName);
  41. }
  42. delete _pPropertyCache;
  43. return;
  44. }
  45. //+---------------------------------------------------------------------------
  46. //
  47. // Function: CFPNWResource::Create
  48. //
  49. // Synopsis: Static function used to create a Resource object. This
  50. // will be called by EnumResources::Next
  51. //
  52. // Arguments: [ppFPNWResource] -- Ptr to a ptr to a new Resource object.
  53. //
  54. // Returns: HRESULT.
  55. //
  56. // Modifies:
  57. //
  58. // History: 12-11-95 RamV Created.
  59. //
  60. //----------------------------------------------------------------------------
  61. HRESULT
  62. CFPNWResource::Create(LPTSTR pszServerADsPath,
  63. PNWFILEINFO pFileInfo,
  64. DWORD dwObject,
  65. REFIID riid,
  66. CWinNTCredentials& Credentials,
  67. LPVOID * ppvoid
  68. )
  69. {
  70. CFPNWResource FAR * pCFPNWResource = NULL;
  71. HRESULT hr;
  72. TCHAR szFileName[MAX_LONG_LENGTH];
  73. TCHAR szUncServerName[MAX_PATH];
  74. hr =CFPNWResource::AllocateResourceObject(pszServerADsPath,
  75. pFileInfo,
  76. &pCFPNWResource );
  77. BAIL_IF_ERROR(hr);
  78. ADsAssert(pCFPNWResource->_pDispMgr);
  79. //
  80. // convert the FileId that we have into a string that we move
  81. // into the Name field
  82. //
  83. _ltow(pFileInfo->dwFileId, szFileName, 10);
  84. hr = pCFPNWResource->InitializeCoreObject(pszServerADsPath,
  85. szFileName,
  86. RESOURCE_CLASS_NAME,
  87. FPNW_RESOURCE_SCHEMA_NAME,
  88. CLSID_FPNWResource,
  89. dwObject);
  90. pCFPNWResource->_dwFileId = pFileInfo->dwFileId;
  91. pCFPNWResource->_Credentials = Credentials;
  92. hr = pCFPNWResource->_Credentials.RefServer(
  93. pCFPNWResource->_pszServerName);
  94. BAIL_IF_ERROR(hr);
  95. hr = SetLPTSTRPropertyInCache(
  96. pCFPNWResource->_pPropertyCache,
  97. TEXT("Name"),
  98. pCFPNWResource->_Name,
  99. TRUE
  100. );
  101. BAIL_IF_ERROR(hr);
  102. //
  103. // Load ext mgr and extensions
  104. //
  105. hr = ADSILoadExtensionManager(
  106. RESOURCE_CLASS_NAME,
  107. (IADs* ) pCFPNWResource,
  108. pCFPNWResource->_pDispMgr,
  109. Credentials,
  110. &pCFPNWResource->_pExtMgr
  111. );
  112. BAIL_IF_ERROR(hr);
  113. ADsAssert(pCFPNWResource->_pExtMgr);
  114. // check if the call is from UMI
  115. if(Credentials.GetFlags() & ADS_AUTH_RESERVED) {
  116. //
  117. // we do not pass riid to InitUmiObject below. This is because UMI object
  118. // does not support IDispatch. There are several places in ADSI code where
  119. // riid passed into this function is defaulted to IID_IDispatch -
  120. // IADsContainer::Create for example. To handle these cases, we always
  121. // request IID_IUnknown from the UMI object. Subsequent code within UMI
  122. // will QI for the appropriate interface.
  123. //
  124. // Resource objects have "" as their ADsPath. Just set the class to
  125. // resource for identification purposes.
  126. pCFPNWResource->_CompClasses[0] = L"Resource";
  127. hr = pCFPNWResource->InitUmiObject(
  128. pCFPNWResource->_Credentials,
  129. FPNWResourceClass,
  130. gdwFPNWResourceTableSize,
  131. pCFPNWResource->_pPropertyCache,
  132. (IUnknown *) (INonDelegatingUnknown *) pCFPNWResource,
  133. pCFPNWResource->_pExtMgr,
  134. IID_IUnknown,
  135. ppvoid
  136. );
  137. BAIL_IF_ERROR(hr);
  138. //
  139. // UMI object was created and the interface was obtained successfully.
  140. // UMI object now has a reference to the inner unknown of IADs, since
  141. // the call to Release() below is not going to be made in this case.
  142. //
  143. RRETURN(hr);
  144. }
  145. ADsAssert(ppvoid);
  146. hr = pCFPNWResource->QueryInterface(riid, (void **)ppvoid);
  147. BAIL_IF_ERROR(hr);
  148. pCFPNWResource->Release();
  149. RRETURN(hr);
  150. cleanup:
  151. if(SUCCEEDED(hr)){
  152. RRETURN(hr);
  153. }
  154. delete pCFPNWResource;
  155. RRETURN_EXP_IF_ERR(hr);
  156. }
  157. HRESULT
  158. CFPNWResource::AllocateResourceObject(LPTSTR pszServerADsPath,
  159. PNWFILEINFO pFileInfo,
  160. CFPNWResource ** ppResource)
  161. {
  162. CFPNWResource FAR * pCFPNWResource = NULL;
  163. HRESULT hr;
  164. TCHAR szFileName[MAX_LONG_LENGTH];
  165. TCHAR szUncServerName[MAX_PATH];
  166. POBJECTINFO pServerObjectInfo = NULL;
  167. //
  168. // Create the Resource Object
  169. //
  170. pCFPNWResource = new CFPNWResource();
  171. if (pCFPNWResource == NULL) {
  172. hr = E_OUTOFMEMORY;
  173. goto cleanup;
  174. }
  175. pCFPNWResource->_pDispMgr = new CAggregatorDispMgr;
  176. if(pCFPNWResource ->_pDispMgr == NULL){
  177. hr = E_OUTOFMEMORY;
  178. goto cleanup;
  179. }
  180. hr = LoadTypeInfoEntry(pCFPNWResource->_pDispMgr,
  181. LIBID_ADs,
  182. IID_IADsResource,
  183. (IADsResource *)pCFPNWResource,
  184. DISPID_REGULAR);
  185. BAIL_IF_ERROR(hr);
  186. hr = LoadTypeInfoEntry(pCFPNWResource->_pDispMgr,
  187. LIBID_ADs,
  188. IID_IADsPropertyList,
  189. (IADsPropertyList *)pCFPNWResource,
  190. DISPID_VALUE);
  191. BAIL_IF_ERROR(hr);
  192. pCFPNWResource->_pszServerADsPath =
  193. AllocADsStr(pszServerADsPath);
  194. if(!(pCFPNWResource->_pszServerADsPath)){
  195. hr = E_OUTOFMEMORY;
  196. goto cleanup;
  197. }
  198. hr = BuildObjectInfo(pszServerADsPath,
  199. &pServerObjectInfo);
  200. BAIL_IF_ERROR(hr);
  201. pCFPNWResource->_pszServerName =
  202. AllocADsStr(pServerObjectInfo->ComponentArray[1]);
  203. if(!(pCFPNWResource->_pszServerName)){
  204. hr = E_OUTOFMEMORY;
  205. goto cleanup;
  206. }
  207. hr = CPropertyCache::createpropertycache(
  208. FPNWResourceClass,
  209. gdwFPNWResourceTableSize,
  210. (CCoreADsObject *)pCFPNWResource,
  211. &(pCFPNWResource->_pPropertyCache)
  212. );
  213. hr = SetLPTSTRPropertyInCache(pCFPNWResource->_pPropertyCache,
  214. TEXT("User"),
  215. pFileInfo->lpUserName,
  216. TRUE
  217. );
  218. BAIL_IF_ERROR(hr);
  219. hr = ADsAllocString(pFileInfo->lpUserName,
  220. &(pCFPNWResource->_pszUserName));
  221. BAIL_IF_ERROR(hr);
  222. hr = SetLPTSTRPropertyInCache(pCFPNWResource->_pPropertyCache,
  223. TEXT("Path"),
  224. pFileInfo->lpPathName,
  225. TRUE
  226. );
  227. BAIL_IF_ERROR(hr);
  228. pCFPNWResource->_pszPath =
  229. AllocADsStr(pFileInfo->lpPathName);
  230. if(!(pCFPNWResource->_pszPath)){
  231. hr = E_OUTOFMEMORY;
  232. goto cleanup;
  233. }
  234. hr = SetDWORDPropertyInCache(pCFPNWResource->_pPropertyCache,
  235. TEXT("LockCount"),
  236. pFileInfo->dwLocks,
  237. TRUE
  238. );
  239. pCFPNWResource->_dwLockCount = pFileInfo->dwLocks;
  240. pCFPNWResource->_pDispMgr->RegisterPropertyCache(
  241. pCFPNWResource->_pPropertyCache
  242. );
  243. *ppResource = pCFPNWResource;
  244. cleanup:
  245. if(pServerObjectInfo){
  246. FreeObjectInfo(pServerObjectInfo);
  247. }
  248. if (!SUCCEEDED(hr)) {
  249. //
  250. // direct memeber assignement assignement at pt of creation, so
  251. // do NOT delete _pPropertyCache or _pDisMgr here to avoid attempt
  252. // of deletion again in pPrintJob destructor and AV
  253. //
  254. delete pCFPNWResource;
  255. }
  256. RRETURN(hr);
  257. }
  258. /* IUnknown methods for Resource object */
  259. //----------------------------------------------------------------------------
  260. // Function: QueryInterface
  261. //
  262. // Synopsis: If this object is aggregated within another object, then
  263. // all calls will delegate to the outer object. Otherwise, the
  264. // non-delegating QI is called
  265. //
  266. // Arguments:
  267. //
  268. // iid interface requested
  269. // ppInterface Returns pointer to interface requested. NULL if interface
  270. // is not supported.
  271. //
  272. // Returns: S_OK on success. Error code otherwise.
  273. //
  274. // Modifies: *ppInterface to return interface pointer
  275. //
  276. //----------------------------------------------------------------------------
  277. STDMETHODIMP CFPNWResource::QueryInterface(
  278. REFIID iid,
  279. LPVOID *ppInterface
  280. )
  281. {
  282. if(_pUnkOuter != NULL)
  283. RRETURN(_pUnkOuter->QueryInterface(
  284. iid,
  285. ppInterface
  286. ));
  287. RRETURN(NonDelegatingQueryInterface(
  288. iid,
  289. ppInterface
  290. ));
  291. }
  292. //----------------------------------------------------------------------------
  293. // Function: AddRef
  294. //
  295. // Synopsis: IUnknown::AddRef. If this object is aggregated within
  296. // another, all calls will delegate to the outer object.
  297. // Otherwise, the non-delegating AddRef is called
  298. //
  299. // Arguments:
  300. //
  301. // None
  302. //
  303. // Returns: New reference count
  304. //
  305. // Modifies: Nothing
  306. //
  307. //----------------------------------------------------------------------------
  308. STDMETHODIMP_(ULONG) CFPNWResource::AddRef(void)
  309. {
  310. if(_pUnkOuter != NULL)
  311. RRETURN(_pUnkOuter->AddRef());
  312. RRETURN(NonDelegatingAddRef());
  313. }
  314. //----------------------------------------------------------------------------
  315. // Function: Release
  316. //
  317. // Synopsis: IUnknown::Release. If this object is aggregated within
  318. // another, all calls will delegate to the outer object.
  319. // Otherwise, the non-delegating Release is called
  320. //
  321. // Arguments:
  322. //
  323. // None
  324. //
  325. // Returns: New reference count
  326. //
  327. // Modifies: Nothing
  328. //
  329. //----------------------------------------------------------------------------
  330. STDMETHODIMP_(ULONG) CFPNWResource::Release(void)
  331. {
  332. if(_pUnkOuter != NULL)
  333. RRETURN(_pUnkOuter->Release());
  334. RRETURN(NonDelegatingRelease());
  335. }
  336. //----------------------------------------------------------------------------
  337. STDMETHODIMP
  338. CFPNWResource::NonDelegatingQueryInterface(REFIID riid, LPVOID FAR* ppvObj)
  339. {
  340. HRESULT hr = S_OK;
  341. if(ppvObj == NULL){
  342. RRETURN(E_POINTER);
  343. }
  344. if (IsEqualIID(riid, IID_IUnknown))
  345. {
  346. *ppvObj = (IADs *) this;
  347. }
  348. else if (IsEqualIID(riid, IID_IDispatch))
  349. {
  350. *ppvObj = (IADs *)this;
  351. }
  352. else if (IsEqualIID(riid, IID_ISupportErrorInfo))
  353. {
  354. *ppvObj = (ISupportErrorInfo FAR *) this;
  355. }
  356. else if (IsEqualIID(riid, IID_IADs))
  357. {
  358. *ppvObj = (IADs FAR *) this;
  359. }
  360. else if (IsEqualIID(riid, IID_IADsPropertyList))
  361. {
  362. *ppvObj = (IADsPropertyList FAR *) this;
  363. }
  364. else if (IsEqualIID(riid, IID_IADsResource))
  365. {
  366. *ppvObj = (IADsResource FAR *) this;
  367. }
  368. else if( (_pDispatch != NULL) &&
  369. IsEqualIID(riid, IID_IADsExtension) )
  370. {
  371. *ppvObj = (IADsExtension *) this;
  372. }
  373. else if (_pExtMgr)
  374. {
  375. RRETURN( _pExtMgr->QueryInterface(riid, ppvObj));
  376. }
  377. else
  378. {
  379. *ppvObj = NULL;
  380. RRETURN(E_NOINTERFACE);
  381. }
  382. ((LPUNKNOWN)*ppvObj)->AddRef();
  383. RRETURN(S_OK);
  384. }
  385. /* ISupportErrorInfo method */
  386. STDMETHODIMP
  387. CFPNWResource::InterfaceSupportsErrorInfo(
  388. THIS_ REFIID riid
  389. )
  390. {
  391. if (IsEqualIID(riid, IID_IADs) ||
  392. IsEqualIID(riid, IID_IADsResource) ||
  393. IsEqualIID(riid, IID_IADsPropertyList)) {
  394. RRETURN(S_OK);
  395. } else {
  396. RRETURN(S_FALSE);
  397. }
  398. }
  399. /* IADs methods */
  400. //+-----------------------------------------------------------------
  401. //
  402. // Function: SetInfo
  403. //
  404. // Synopsis: SetInfo on actual Resource
  405. //
  406. // Arguments: void
  407. //
  408. // Returns: HRESULT.
  409. //
  410. // Modifies:
  411. //
  412. // History: 02/08/96 RamV Created
  413. //----------------------------------------------------------------------------
  414. STDMETHODIMP
  415. CFPNWResource::SetInfo(THIS)
  416. {
  417. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  418. }
  419. STDMETHODIMP
  420. CFPNWResource::GetInfo(THIS)
  421. {
  422. _pPropertyCache->flushpropcache();
  423. RRETURN(S_OK);
  424. }
  425. STDMETHODIMP
  426. CFPNWResource::ImplicitGetInfo(THIS)
  427. {
  428. RRETURN(S_OK);
  429. }
  430. STDMETHODIMP
  431. CFPNWResource::get_User(THIS_ BSTR FAR* retval)
  432. {
  433. HRESULT hr;
  434. if(!retval){
  435. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  436. }
  437. hr = ADsAllocString(_pszUserName, retval);
  438. RRETURN_EXP_IF_ERR(hr);
  439. }
  440. STDMETHODIMP
  441. CFPNWResource::get_UserPath(THIS_ BSTR FAR* retval)
  442. {
  443. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  444. }
  445. STDMETHODIMP
  446. CFPNWResource::get_Path(THIS_ BSTR FAR* retval)
  447. {
  448. HRESULT hr;
  449. if(!retval){
  450. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  451. }
  452. hr = ADsAllocString(_pszPath, retval);
  453. RRETURN_EXP_IF_ERR(hr);
  454. }
  455. STDMETHODIMP
  456. CFPNWResource::get_LockCount(THIS_ LONG FAR* retval)
  457. {
  458. if(!retval){
  459. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  460. }
  461. *retval = _dwLockCount;
  462. RRETURN(S_OK);
  463. }