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.

847 lines
19 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996
  5. //
  6. // File: cjob.cxx
  7. //
  8. // Contents: CNWCOMPATPrintJob
  9. //
  10. //
  11. // History: 1-May-96 t-ptam (Patrick Tam) Created.
  12. // 1-Jul-96 ramv (Ram Viswanathan) Modified to use propcache
  13. //----------------------------------------------------------------------------
  14. #include "NWCOMPAT.hxx"
  15. #pragma hdrstop
  16. //
  17. // Macro-ized implementation.
  18. //
  19. DEFINE_IDispatch_ExtMgr_Implementation(CNWCOMPATPrintJob);
  20. DEFINE_IADs_TempImplementation(CNWCOMPATPrintJob);
  21. DEFINE_IADs_PutGetImplementation(CNWCOMPATPrintJob, PrintJobClass, gdwJobTableSize);
  22. DEFINE_IADsPropertyList_Implementation(CNWCOMPATPrintJob, PrintJobClass, gdwJobTableSize);
  23. //----------------------------------------------------------------------------
  24. //
  25. // Function: CNWCOMPATPrintJob::CNWCOMPATPrintJob
  26. //
  27. // Synopsis:
  28. //
  29. //----------------------------------------------------------------------------
  30. CNWCOMPATPrintJob::CNWCOMPATPrintJob():
  31. _pDispMgr(NULL),
  32. _pExtMgr(NULL),
  33. _lJobId(0),
  34. _lStatus(0),
  35. _pPropertyCache(NULL),
  36. _pszPrinterPath(NULL)
  37. {
  38. ENLIST_TRACKING(CNWCOMPATPrintJob);
  39. }
  40. //----------------------------------------------------------------------------
  41. //
  42. // Function: CNWCOMPATPrintJob::~CNWCOMPATPrintJob
  43. //
  44. // Synopsis:
  45. //
  46. //----------------------------------------------------------------------------
  47. CNWCOMPATPrintJob::~CNWCOMPATPrintJob()
  48. {
  49. delete _pExtMgr; // created last, destroyed first
  50. delete _pDispMgr;
  51. delete _pPropertyCache;
  52. if(_pszPrinterPath){
  53. FreeADsStr(_pszPrinterPath);
  54. }
  55. }
  56. //----------------------------------------------------------------------------
  57. //
  58. // Function: CNWCOMPATPrintJob::CreatePrintJob
  59. //
  60. // Synopsis:
  61. //
  62. //----------------------------------------------------------------------------
  63. HRESULT
  64. CNWCOMPATPrintJob::CreatePrintJob(
  65. LPTSTR pszPrinterPath,
  66. LONG lJobId,
  67. DWORD dwObjectState,
  68. REFIID riid,
  69. LPVOID *ppvoid
  70. )
  71. {
  72. CNWCOMPATPrintJob *pPrintJob = NULL;
  73. HRESULT hr = S_OK;
  74. TCHAR szJobName[MAX_LONG_LENGTH];
  75. POBJECTINFO pObjectInfo = NULL;
  76. TCHAR szUncPrinterName[MAX_PATH];
  77. //
  78. // Allocate memory for a print job object.
  79. //
  80. hr = AllocatePrintJobObject(
  81. &pPrintJob
  82. );
  83. BAIL_ON_FAILURE(hr);
  84. //
  85. // Convert the JobId that we have into a string that we move
  86. // into the Name field
  87. //
  88. _ltow(
  89. lJobId,
  90. szJobName,
  91. 10
  92. );
  93. //
  94. // Initialize its core object.
  95. //
  96. hr = pPrintJob->InitializeCoreObject(
  97. pszPrinterPath,
  98. szJobName,
  99. PRINTJOB_CLASS_NAME,
  100. PRINTJOB_SCHEMA_NAME,
  101. CLSID_NWCOMPATPrintJob,
  102. dwObjectState
  103. );
  104. BAIL_ON_FAILURE(hr);
  105. //
  106. // Job ID.
  107. //
  108. pPrintJob->_lJobId = lJobId;
  109. pPrintJob->_pszPrinterPath = AllocADsStr(pszPrinterPath);
  110. if(! pPrintJob->_pszPrinterPath) {
  111. hr = E_OUTOFMEMORY;
  112. goto error;
  113. }
  114. //
  115. // Get interface pointer.
  116. //
  117. hr = pPrintJob->QueryInterface(
  118. riid,
  119. (void **)ppvoid
  120. );
  121. BAIL_ON_FAILURE(hr);
  122. pPrintJob->Release();
  123. hr = pPrintJob->_pExtMgr->FinalInitializeExtensions();
  124. BAIL_ON_FAILURE(hr);
  125. //
  126. // Return.
  127. //
  128. if (pObjectInfo) {
  129. FreeObjectInfo(pObjectInfo);
  130. }
  131. RRETURN(hr);
  132. error:
  133. if (pObjectInfo) {
  134. FreeObjectInfo(pObjectInfo);
  135. }
  136. delete pPrintJob;
  137. RRETURN_EXP_IF_ERR(hr);
  138. }
  139. //----------------------------------------------------------------------------
  140. //
  141. // Function: CNWCOMPATPrintJob::AllocatePrintJobObject
  142. //
  143. // Synopsis:
  144. //
  145. //----------------------------------------------------------------------------
  146. HRESULT
  147. CNWCOMPATPrintJob::AllocatePrintJobObject(
  148. CNWCOMPATPrintJob ** ppPrintJob
  149. )
  150. {
  151. CAggregatorDispMgr FAR * pDispMgr = NULL;
  152. CADsExtMgr FAR * pExtensionMgr = NULL;
  153. CPropertyCache FAR * pPropertyCache = NULL;
  154. CNWCOMPATPrintJob FAR * pPrintJob = NULL;
  155. CNWCOMPATFSPrintJobGeneralInfo FAR * pGenInfo = NULL;
  156. CNWCOMPATFSPrintJobOperation FAR * pOperation = NULL;
  157. HRESULT hr = S_OK;
  158. //
  159. // Allocate memory for a PrintJob object.
  160. //
  161. pPrintJob = new CNWCOMPATPrintJob();
  162. if (pPrintJob == NULL) {
  163. hr = E_OUTOFMEMORY;
  164. }
  165. BAIL_ON_FAILURE(hr);
  166. //
  167. // Create a Dispatch Manager object.
  168. //
  169. pDispMgr = new CAggregatorDispMgr;
  170. if (pDispMgr == NULL) {
  171. hr = E_OUTOFMEMORY;
  172. }
  173. BAIL_ON_FAILURE(hr);
  174. //
  175. // Load type info.
  176. //
  177. hr = LoadTypeInfoEntry(
  178. pDispMgr,
  179. LIBID_ADs,
  180. IID_IADsPrintJob,
  181. (IADsPrintJob *) pPrintJob,
  182. DISPID_REGULAR
  183. );
  184. BAIL_ON_FAILURE(hr);
  185. hr = LoadTypeInfoEntry(
  186. pDispMgr,
  187. LIBID_ADs,
  188. IID_IADsPrintJobOperations,
  189. (IADsPrintJobOperations *)pPrintJob,
  190. DISPID_REGULAR
  191. );
  192. BAIL_ON_FAILURE(hr);
  193. hr = LoadTypeInfoEntry(
  194. pDispMgr,
  195. LIBID_ADs,
  196. IID_IADsPropertyList,
  197. (IADsPropertyList *)pPrintJob,
  198. DISPID_VALUE
  199. );
  200. BAIL_ON_FAILURE(hr);
  201. //
  202. // Return.
  203. //
  204. hr = CPropertyCache::createpropertycache(
  205. PrintJobClass,
  206. gdwJobTableSize,
  207. (CCoreADsObject *)pPrintJob,
  208. &pPropertyCache
  209. );
  210. BAIL_ON_FAILURE(hr);
  211. pDispMgr->RegisterPropertyCache(
  212. pPropertyCache
  213. );
  214. hr = ADSILoadExtensionManager(
  215. PRINTJOB_CLASS_NAME,
  216. (IADsPrintJob *)pPrintJob,
  217. pDispMgr,
  218. &pExtensionMgr
  219. );
  220. BAIL_ON_FAILURE(hr);
  221. pPrintJob->_pExtMgr = pExtensionMgr;
  222. pPrintJob->_pPropertyCache = pPropertyCache;
  223. pPrintJob->_pDispMgr = pDispMgr;
  224. *ppPrintJob = pPrintJob;
  225. RRETURN(hr);
  226. error:
  227. delete pPropertyCache;
  228. delete pDispMgr;
  229. delete pExtensionMgr;
  230. delete pPrintJob;
  231. RRETURN(hr);
  232. }
  233. //----------------------------------------------------------------------------
  234. //
  235. // Function: CNWCOMPATPrintJob::QueryInterface
  236. //
  237. // Synopsis:
  238. //
  239. //----------------------------------------------------------------------------
  240. STDMETHODIMP
  241. CNWCOMPATPrintJob::QueryInterface(
  242. REFIID riid,
  243. LPVOID FAR* ppvObj
  244. )
  245. {
  246. if(!ppvObj){
  247. RRETURN(E_POINTER);
  248. }
  249. if (IsEqualIID(riid, IID_IUnknown))
  250. {
  251. *ppvObj = (IADsPrintJob FAR *)this;
  252. }
  253. else if (IsEqualIID(riid, IID_IDispatch))
  254. {
  255. *ppvObj = (IADsPrintJob *)this;
  256. }
  257. else if (IsEqualIID(riid, IID_ISupportErrorInfo))
  258. {
  259. *ppvObj = (ISupportErrorInfo FAR *) this;
  260. }
  261. else if (IsEqualIID(riid, IID_IADs))
  262. {
  263. *ppvObj = (IADsPrintJob FAR *) this;
  264. }
  265. else if (IsEqualIID(riid, IID_IADsPrintJob))
  266. {
  267. *ppvObj = (IADsPrintJob FAR *) this;
  268. }
  269. else if (IsEqualIID(riid, IID_IADsPrintJobOperations))
  270. {
  271. *ppvObj = (IADsPrintJobOperations FAR *) this;
  272. }
  273. else if (IsEqualIID(riid, IID_IADsPropertyList))
  274. {
  275. *ppvObj = (IADsPropertyList FAR *) this;
  276. }
  277. else if (_pExtMgr)
  278. {
  279. RRETURN( _pExtMgr->QueryInterface(riid, ppvObj));
  280. }
  281. else
  282. {
  283. *ppvObj = NULL;
  284. RRETURN(E_NOINTERFACE);
  285. }
  286. AddRef();
  287. return NOERROR;
  288. }
  289. //----------------------------------------------------------------------------
  290. //
  291. // Function: CNWCOMPATPrintJob::InterfaceSupportsErrorInfo
  292. //
  293. // Synopsis:
  294. //
  295. //----------------------------------------------------------------------------
  296. STDMETHODIMP
  297. CNWCOMPATPrintJob::InterfaceSupportsErrorInfo(
  298. THIS_ REFIID riid
  299. )
  300. {
  301. if (IsEqualIID(riid, IID_IADs) ||
  302. IsEqualIID(riid, IID_IADsPropertyList) ||
  303. IsEqualIID(riid, IID_IADsPrintJob) ||
  304. IsEqualIID(riid, IID_IADsPrintJobOperations)) {
  305. RRETURN(S_OK);
  306. } else {
  307. RRETURN(S_FALSE);
  308. }
  309. }
  310. //----------------------------------------------------------------------------
  311. //
  312. // Function: CNWCOMPATPrintJob::SetInfo
  313. //
  314. // Synopsis:
  315. //
  316. //----------------------------------------------------------------------------
  317. STDMETHODIMP
  318. CNWCOMPATPrintJob::SetInfo(THIS)
  319. {
  320. HANDLE hPrinter = NULL;
  321. HRESULT hr = S_OK;
  322. LPBYTE lpbBuffer = NULL;
  323. WCHAR szUncPrinterName[MAX_PATH];
  324. //
  325. // Make sure object is bound to a tangible resource.
  326. //
  327. if (GetObjectState() == ADS_OBJECT_UNBOUND) {
  328. hr = CreateObject();
  329. BAIL_ON_FAILURE(hr);
  330. SetObjectState(ADS_OBJECT_BOUND);
  331. }
  332. //
  333. // Make Unc printer name.
  334. //
  335. hr = NWApiUncFromADsPath(
  336. _pszPrinterPath,
  337. szUncPrinterName
  338. );
  339. BAIL_ON_FAILURE(hr);
  340. //
  341. // Open a handle to a printer.
  342. //
  343. hr = NWApiOpenPrinter(
  344. szUncPrinterName,
  345. &hPrinter,
  346. PRINTER_ALL_ACCESS
  347. );
  348. BAIL_ON_FAILURE(hr);
  349. //
  350. // Get job Info structure.
  351. //
  352. hr = NWApiGetJob(
  353. hPrinter,
  354. (DWORD) _lJobId,
  355. WIN32_API_LEVEL_2,
  356. &lpbBuffer
  357. );
  358. BAIL_ON_FAILURE(hr);
  359. //
  360. // Set info.
  361. //
  362. hr = MarshallAndSet(
  363. hPrinter,
  364. (LPJOB_INFO_2) lpbBuffer
  365. );
  366. error:
  367. //
  368. // Close Printer handle.
  369. //
  370. if (hPrinter) {
  371. NWApiClosePrinter(hPrinter);
  372. }
  373. RRETURN_EXP_IF_ERR(hr);
  374. }
  375. //----------------------------------------------------------------------------
  376. //
  377. // Function: CNWCOMPATPrintJob::GetInfo
  378. //
  379. // Synopsis:
  380. //
  381. //----------------------------------------------------------------------------
  382. STDMETHODIMP
  383. CNWCOMPATPrintJob::GetInfo(THIS)
  384. {
  385. _pPropertyCache->flushpropcache();
  386. RRETURN(GetInfo(
  387. TRUE,
  388. JOB_API_LEVEL
  389. ));
  390. }
  391. //----------------------------------------------------------------------------
  392. //
  393. // Function: CNWCOMPATPrintJob::CreateObject
  394. //
  395. // Synopsis:
  396. //
  397. //----------------------------------------------------------------------------
  398. STDMETHODIMP
  399. CNWCOMPATPrintJob::CreateObject()
  400. {
  401. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  402. }
  403. //----------------------------------------------------------------------------
  404. //
  405. // Function: CNWCOMPATPrintJob::GetInfo
  406. //
  407. // Synopsis: Please note that only Level 2 is used, unlike the WinNT side.
  408. // Since Level 1 is simply a subset of Level 2 in this case, its just
  409. // a matter of style which one to use.
  410. //
  411. //----------------------------------------------------------------------------
  412. STDMETHODIMP
  413. CNWCOMPATPrintJob::GetInfo(
  414. THIS_ BOOL fExplicit,
  415. DWORD dwPropertyID
  416. )
  417. {
  418. //
  419. // Please note that the input DWORD is treated as dwApiLevel, unlike ohter
  420. // NWCompat objects that treat it as dwPropertyID. The reason is that Win32
  421. // APIs are used for retrieving information of the object.
  422. //
  423. HANDLE hPrinter = NULL;
  424. HRESULT hr = S_OK;
  425. LPBYTE lpbJobInfo = NULL;
  426. WCHAR szUncPrinterName[MAX_PATH];
  427. //
  428. // Make Unc printer name.
  429. //
  430. hr = NWApiUncFromADsPath(
  431. _pszPrinterPath,
  432. szUncPrinterName
  433. );
  434. BAIL_ON_FAILURE(hr);
  435. //
  436. // Open a handle to a printer.
  437. //
  438. hr = NWApiOpenPrinter(
  439. szUncPrinterName,
  440. &hPrinter,
  441. PRINTER_ALL_ACCESS
  442. );
  443. BAIL_ON_FAILURE(hr);
  444. //
  445. // Get job's info.
  446. //
  447. hr = NWApiGetJob(
  448. hPrinter,
  449. (DWORD) _lJobId,
  450. WIN32_API_LEVEL_2,
  451. &lpbJobInfo
  452. );
  453. BAIL_ON_FAILURE(hr);
  454. //
  455. // Unmarshall.
  456. //
  457. hr = UnMarshall_GeneralInfo(
  458. (LPJOB_INFO_2) lpbJobInfo,
  459. fExplicit
  460. );
  461. BAIL_ON_FAILURE(hr);
  462. hr = UnMarshall_Operation(
  463. (LPJOB_INFO_2) lpbJobInfo,
  464. fExplicit
  465. );
  466. BAIL_ON_FAILURE(hr);
  467. error:
  468. if (hPrinter) {
  469. NWApiClosePrinter(hPrinter);
  470. }
  471. if(lpbJobInfo){
  472. FreeADsMem(lpbJobInfo);
  473. }
  474. RRETURN_EXP_IF_ERR(hr);
  475. }
  476. //----------------------------------------------------------------------------
  477. //
  478. // Function: CNWCOMPATPrintJob::UnMarshall_GeneralInfo
  479. //
  480. // Synopsis:
  481. //
  482. //----------------------------------------------------------------------------
  483. HRESULT
  484. CNWCOMPATPrintJob::UnMarshall_GeneralInfo(
  485. LPJOB_INFO_2 lpJobInfo2,
  486. BOOL fExplicit
  487. )
  488. {
  489. DATE daTemp = 0;
  490. HRESULT hr = S_OK;
  491. LPWSTR lpszTemp = NULL;
  492. WCHAR szTemp[MAX_PATH];
  493. hr = SetLPTSTRPropertyInCache(
  494. _pPropertyCache,
  495. TEXT("HostPrintQueue"),
  496. _pszPrinterPath,
  497. fExplicit
  498. );
  499. hr = SetLPTSTRPropertyInCache(
  500. _pPropertyCache,
  501. TEXT("User"),
  502. lpJobInfo2->pUserName,
  503. fExplicit
  504. );
  505. hr = SetLPTSTRPropertyInCache(
  506. _pPropertyCache,
  507. TEXT("Description"),
  508. lpJobInfo2->pDocument,
  509. fExplicit
  510. );
  511. hr = SetLPTSTRPropertyInCache(
  512. _pPropertyCache,
  513. TEXT("Notify"),
  514. lpJobInfo2->pNotifyName,
  515. fExplicit
  516. );
  517. hr = SetSYSTEMTIMEPropertyInCache(
  518. _pPropertyCache,
  519. TEXT("TimeSubmitted"),
  520. lpJobInfo2->Submitted,
  521. fExplicit
  522. );
  523. hr = SetDWORDPropertyInCache(
  524. _pPropertyCache,
  525. TEXT("Priority"),
  526. lpJobInfo2->Priority,
  527. fExplicit
  528. );
  529. hr = SetDWORDPropertyInCache(
  530. _pPropertyCache,
  531. TEXT("TotalPages"),
  532. lpJobInfo2-> TotalPages,
  533. fExplicit
  534. );
  535. hr = SetDATEPropertyInCache(
  536. _pPropertyCache,
  537. TEXT("StartTime"),
  538. lpJobInfo2->StartTime,
  539. fExplicit
  540. );
  541. hr = SetDATEPropertyInCache(
  542. _pPropertyCache,
  543. TEXT("UntilTime"),
  544. lpJobInfo2->UntilTime,
  545. fExplicit
  546. );
  547. hr = SetDWORDPropertyInCache(
  548. _pPropertyCache,
  549. TEXT("Size"),
  550. lpJobInfo2->Size,
  551. fExplicit
  552. );
  553. hr = S_OK;
  554. RRETURN(hr);
  555. }
  556. //----------------------------------------------------------------------------
  557. //
  558. // Function: CNWCOMPATPrintJob::UnMarshall_Operation
  559. //
  560. // Synopsis:
  561. //
  562. //----------------------------------------------------------------------------
  563. HRESULT
  564. CNWCOMPATPrintJob::UnMarshall_Operation(
  565. LPJOB_INFO_2 lpJobInfo2,
  566. BOOL fExplicit
  567. )
  568. {
  569. HRESULT hr = S_OK;
  570. hr = SetDWORDPropertyInCache(
  571. _pPropertyCache,
  572. TEXT("Position"),
  573. lpJobInfo2->Position,
  574. fExplicit
  575. );
  576. BAIL_ON_FAILURE(hr);
  577. hr = SetDWORDPropertyInCache(
  578. _pPropertyCache,
  579. TEXT("PagesPrinted"),
  580. lpJobInfo2->PagesPrinted,
  581. fExplicit
  582. );
  583. BAIL_ON_FAILURE(hr);
  584. hr = SetDATEPropertyInCache(
  585. _pPropertyCache,
  586. TEXT("TimeElapsed"),
  587. lpJobInfo2->Time,
  588. fExplicit
  589. );
  590. hr = SetDWORDPropertyInCache(
  591. _pPropertyCache,
  592. TEXT("Status"),
  593. lpJobInfo2->Status,
  594. fExplicit
  595. );
  596. BAIL_ON_FAILURE(hr);
  597. _lStatus = lpJobInfo2->Status;
  598. error:
  599. RRETURN(hr);
  600. }
  601. //----------------------------------------------------------------------------
  602. //
  603. // Function: CNWCOMPATPrintJob::MarshallAndSet
  604. //
  605. // Synopsis:
  606. //
  607. //----------------------------------------------------------------------------
  608. HRESULT
  609. CNWCOMPATPrintJob::MarshallAndSet(
  610. HANDLE hPrinter,
  611. LPJOB_INFO_2 lpJobInfo2
  612. )
  613. {
  614. LPTSTR pszDescription = NULL;
  615. LPTSTR pszNotify = NULL;
  616. DWORD dwValue;
  617. HRESULT hr = S_OK;
  618. //
  619. // Set Description.
  620. //
  621. hr = GetLPTSTRPropertyFromCache(
  622. _pPropertyCache,
  623. TEXT("Description"),
  624. &pszDescription
  625. );
  626. if(SUCCEEDED(hr)){
  627. lpJobInfo2->pDocument = pszDescription;
  628. }
  629. //
  630. // Set Notify.
  631. //
  632. hr = GetLPTSTRPropertyFromCache(
  633. _pPropertyCache,
  634. TEXT("Notify"),
  635. &pszNotify
  636. );
  637. if(SUCCEEDED(hr)){
  638. lpJobInfo2->pNotifyName = pszNotify;
  639. }
  640. //
  641. // Set Priority.
  642. //
  643. hr = GetDWORDPropertyFromCache(
  644. _pPropertyCache,
  645. TEXT("Priority"),
  646. &dwValue
  647. );
  648. if(SUCCEEDED(hr)){
  649. lpJobInfo2->Priority = dwValue;
  650. }
  651. //
  652. // Set StartTime.
  653. //
  654. hr = GetDATEPropertyFromCache(
  655. _pPropertyCache,
  656. TEXT("StartTime"),
  657. &dwValue
  658. );
  659. if(SUCCEEDED(hr)){
  660. lpJobInfo2->StartTime = dwValue;
  661. }
  662. //
  663. // Set UntilTime
  664. //
  665. hr = GetDATEPropertyFromCache(
  666. _pPropertyCache,
  667. TEXT("UntilTime"),
  668. &dwValue
  669. );
  670. if(SUCCEEDED(hr)){
  671. lpJobInfo2->UntilTime = dwValue;
  672. }
  673. /* Clarify the precedence between Notify & NotifyPath
  674. hr = UM_GET_BSTR_PROPERTY(_pGenInfo, NotifyPath, fExplicit);
  675. BAIL_ON_FAILURE(hr);
  676. */
  677. //
  678. // Set Position.
  679. //
  680. hr = GetDWORDPropertyFromCache(
  681. _pPropertyCache,
  682. TEXT("Position"),
  683. &dwValue
  684. );
  685. if(SUCCEEDED(hr)){
  686. lpJobInfo2->Position = dwValue;
  687. }
  688. //
  689. // Commit changes.
  690. //
  691. hr = NWApiSetJob(
  692. hPrinter,
  693. (DWORD) _lJobId,
  694. WIN32_API_LEVEL_2,
  695. (LPBYTE) lpJobInfo2,
  696. 0
  697. );
  698. BAIL_ON_FAILURE(hr);
  699. error:
  700. if(pszDescription)
  701. FreeADsStr(pszDescription);
  702. if(pszNotify)
  703. FreeADsStr(pszNotify);
  704. RRETURN(S_OK);
  705. }