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.

641 lines
12 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1998 - 1999
  3. All rights reserved.
  4. Module Name:
  5. PrnStrm.hxx
  6. Abstract:
  7. This class implements methods for storing , restoring printer settings into a file
  8. Author:
  9. Adina Trufinescu (AdinaTru) 4-Nov-1998
  10. Revision History:
  11. --*/
  12. #ifndef _PRN_STRM_HXX_
  13. #define _PRN_STRM_HXX_
  14. #include "Stream.hxx"
  15. #include "WlkPrn.hxx"
  16. class TPrnStream : public WalkPrinterData
  17. {
  18. public:
  19. TPrnStream::
  20. TPrnStream(
  21. IN LPCTSTR pszPrnName,
  22. IN LPCTSTR pszFileName
  23. );
  24. TPrnStream::
  25. ~TPrnStream(
  26. );
  27. HRESULT
  28. TPrnStream::
  29. StorePrnData(
  30. VOID
  31. );
  32. HRESULT
  33. TPrnStream::
  34. RestorePrnData(
  35. VOID
  36. );
  37. HRESULT
  38. TPrnStream::
  39. StorePrnInfo2(
  40. VOID
  41. );
  42. HRESULT
  43. TPrnStream::
  44. RestorePrnInfo2(
  45. VOID
  46. );
  47. HRESULT
  48. TPrnStream::
  49. StorePrnInfo7(
  50. VOID
  51. );
  52. HRESULT
  53. TPrnStream::
  54. RestorePrnInfo7(
  55. VOID
  56. );
  57. HRESULT
  58. TPrnStream::
  59. StorePrnSecurity(
  60. VOID
  61. );
  62. HRESULT
  63. TPrnStream::
  64. RestorePrnSecurity(
  65. VOID
  66. );
  67. HRESULT
  68. TPrnStream::
  69. StoreUserDevMode(
  70. VOID
  71. );
  72. HRESULT
  73. TPrnStream::
  74. RestoreUserDevMode(
  75. VOID
  76. );
  77. HRESULT
  78. TPrnStream::
  79. StorePrnDevMode(
  80. VOID
  81. );
  82. HRESULT
  83. TPrnStream::
  84. RestorePrnDevMode(
  85. VOID
  86. );
  87. HRESULT
  88. TPrnStream::
  89. StoreColorProfiles(
  90. VOID
  91. );
  92. HRESULT
  93. TPrnStream::
  94. RestoreColorProfiles(
  95. VOID
  96. );
  97. BOOL
  98. TPrnStream::
  99. DeleteColorProfiles(
  100. VOID
  101. );
  102. HRESULT
  103. TPrnStream::
  104. CheckPrinterNameIntegrity(
  105. IN DWORD Flags
  106. );
  107. HRESULT
  108. TPrnStream::
  109. BindPrnStream(
  110. );
  111. HRESULT
  112. TPrnStream::
  113. UnBindPrnStream(
  114. );
  115. HRESULT
  116. TPrnStream::
  117. StorePrinterInfo(
  118. IN DWORD Flags,
  119. OUT DWORD& StoredFlags
  120. );
  121. HRESULT
  122. TPrnStream::
  123. RestorePrinterInfo(
  124. IN DWORD Flags,
  125. OUT DWORD& RestoredFlags
  126. );
  127. HRESULT
  128. TPrnStream::
  129. QueryPrinterInfo(
  130. IN PrinterPersistentQueryFlag Flags,
  131. OUT PersistentInfo *pPrstInfo
  132. );
  133. TStream*
  134. TPrnStream::
  135. GetIStream(
  136. )
  137. {
  138. return m_pIStream;
  139. };
  140. LPTSTR
  141. TPrnStream::
  142. GetPrinterName(
  143. VOID
  144. )
  145. { return const_cast<LPTSTR>(static_cast<LPCTSTR>(m_strPrnName)); }
  146. LPTSTR
  147. TPrnStream::
  148. GetFileName(
  149. VOID
  150. )
  151. { return const_cast<LPTSTR>(static_cast<LPCTSTR>(m_strFileName)); }
  152. private:
  153. enum SolveName
  154. {
  155. kResolveName = 1,
  156. kForceName = 1<<1,
  157. kResolvePort = 1<<2,
  158. kGenerateShare = 1<<3,
  159. kUntouchShare = 1<<4,
  160. };
  161. enum EHeaderEntryType
  162. {
  163. kPrnName,
  164. kPrnDataRoot,
  165. kcItems,
  166. kUserDevMode,
  167. kPrnDevMode,
  168. kPrnInfo2,
  169. kPrnInfo7,
  170. kSecurity,
  171. kColorProfile
  172. };
  173. enum EItemType
  174. {
  175. ktDevMode,
  176. ktPrnInfo2,
  177. ktPrnInfo7,
  178. ktSecurity,
  179. ktColorProfile,
  180. ktPrnName,
  181. ktREG_TYPE,
  182. };
  183. // header structure:
  184. //
  185. typedef struct PrnHeader
  186. {
  187. ULARGE_INTEGER pPrnName; //ptr to printer name into stream( offset in stream )
  188. ULARGE_INTEGER pPrnDataRoot; //ptr to where the Printer data items begins( contiguous holding )
  189. ULARGE_INTEGER cItems; //number of Printer data items
  190. ULARGE_INTEGER pUserDevMode; //ptr to user dev mode into stream ( offset in stream )
  191. ULARGE_INTEGER pPrnDevMode; //ptr to global dev mode into stream ( offset in stream )
  192. ULARGE_INTEGER pPrnInfo2; //ptr to PI2 into stream ( offset in stream )
  193. ULARGE_INTEGER pPrnInfo7; //ptr to PI7 into stream ( offset in stream )
  194. ULARGE_INTEGER pSecurity; //ptr to security settings into stream ( offset in stream )
  195. ULARGE_INTEGER pColorProfileSettings; //ptr to ICM profiles into stream ( offset in stream ; contiguous holding)
  196. };
  197. // item's structure
  198. //
  199. typedef struct PrnBinInfo
  200. {
  201. DWORD cbSize; // the item's size
  202. DWORD dwType; // item's type ( REG_SZ , etc for Printer data items )
  203. DWORD pKey; // ptr to key name into the item
  204. DWORD pValue; // ptr to value name into the item
  205. DWORD pData; // ptr to data
  206. DWORD cbData; // data size
  207. };
  208. typedef HRESULT (TPrnStream::*PersistFunct)(VOID);
  209. typedef HRESULT (TPrnStream::*ReadFunct)(PrnBinInfo**);
  210. typedef struct PrstSelection
  211. {
  212. DWORD iKeyWord;
  213. PersistFunct pPrstFunc;
  214. } PrstFunctEntry;
  215. typedef struct QuerySelection
  216. {
  217. DWORD iKeyWord;
  218. ReadFunct pReadFunct;
  219. } QueryFunctEntry;
  220. typedef BOOL (WINAPI *pfnEnumColorProfilesW)(PCWSTR, PENUMTYPEW, PBYTE, PDWORD, PDWORD);
  221. typedef BOOL (WINAPI *pfnAssociateColorProfileWithDeviceW)(PCWSTR, PCWSTR, PCWSTR);
  222. typedef BOOL (WINAPI *pfnDisassociateColorProfileFromDeviceW)(PCWSTR, PCWSTR, PCWSTR);
  223. HRESULT
  224. TPrnStream::
  225. WritePrnData(
  226. IN LPCTSTR pKey,
  227. IN LPCTSTR pValueName,
  228. IN DWORD cbValueName,
  229. IN DWORD dwType,
  230. IN LPBYTE pData,
  231. IN DWORD cbData
  232. );
  233. HRESULT
  234. TPrnStream::
  235. ReadNextPrnData(
  236. OUT LPTSTR& lpszKey,
  237. OUT LPTSTR& lpszVal,
  238. OUT DWORD& dwType,
  239. OUT LPBYTE& lpbData,
  240. OUT DWORD& cbSize,
  241. OUT LPBYTE& lpBuffer
  242. );
  243. BOOL
  244. TPrnStream::
  245. bWriteKeyData(
  246. IN LPCTSTR lpszKey,
  247. OUT LPDWORD lpcItems
  248. );
  249. BOOL
  250. TPrnStream::
  251. bWriteKeyValue(
  252. IN LPCTSTR lpszKey,
  253. IN LPPRINTER_ENUM_VALUES lpPEV
  254. );
  255. HRESULT
  256. TPrnStream::
  257. WritePrnInfo2(
  258. IN PRINTER_INFO_2* lpPrinterInfo2,
  259. IN DWORD cbPI2Size
  260. );
  261. HRESULT
  262. TPrnStream::
  263. ReadPrnInfo2(
  264. OUT PrnBinInfo** lppPrnBinItem
  265. );
  266. HRESULT
  267. TPrnStream::
  268. ReadPrnName(
  269. OUT TString& strPrnName
  270. );
  271. HRESULT
  272. TPrnStream::
  273. WritePrnName(
  274. VOID
  275. );
  276. HRESULT
  277. TPrnStream::
  278. WritePrnInfo7(
  279. IN PRINTER_INFO_7* lpPrinterInfo7,
  280. IN DWORD cbPI7Size
  281. );
  282. HRESULT
  283. TPrnStream::
  284. ReadPrnInfo7(
  285. OUT PrnBinInfo** lppPrnBinItem
  286. );
  287. HRESULT
  288. TPrnStream::
  289. WritePrnSecurity(
  290. IN PRINTER_INFO_2* lpPrinterInfo2,
  291. IN DWORD cbPI2Size
  292. );
  293. HRESULT
  294. TPrnStream::
  295. ReadPrnSecurity(
  296. OUT PrnBinInfo** ppPrnBinItem
  297. );
  298. HRESULT
  299. TPrnStream::
  300. WritePrnInfo8(
  301. IN PRINTER_INFO_8* lpPrinterInfo8,
  302. IN DWORD cbSize
  303. );
  304. HRESULT
  305. TPrnStream::
  306. ReadPrnInfo8(
  307. OUT PrnBinInfo** lppPrnBinItem
  308. );
  309. HRESULT
  310. TPrnStream::
  311. WritePrnInfo9(
  312. IN PRINTER_INFO_9* lpPrinterInfo8,
  313. IN DWORD cbSize
  314. );
  315. HRESULT
  316. TPrnStream::
  317. ReadPrnInfo9(
  318. OUT PrnBinInfo** ppPrnBinItem
  319. );
  320. HRESULT
  321. TPrnStream::
  322. WriteColorProfiles(
  323. IN LPBYTE lpProfiles,
  324. IN DWORD cbSize
  325. );
  326. HRESULT
  327. TPrnStream::
  328. ReadColorProfiles(
  329. OUT PrnBinInfo** ppPrnBinItem
  330. );
  331. HRESULT
  332. TPrnStream::
  333. WriteItem(
  334. IN LPCTSTR pKey,
  335. IN LPCTSTR pValueName,
  336. IN DWORD cbValueName,
  337. IN DWORD dwType,
  338. IN LPBYTE pData,
  339. IN DWORD cbData
  340. );
  341. HRESULT
  342. TPrnStream::
  343. ReadItem(
  344. OUT LPTSTR& lpszKey,
  345. OUT LPTSTR& lpszVal,
  346. OUT DWORD& dwType,
  347. OUT LPBYTE& lpbData,
  348. OUT DWORD& cbSize,
  349. OUT LPBYTE& lpBuffer
  350. );
  351. HRESULT
  352. TPrnStream::
  353. ReadItemFromPosition(
  354. IN OUT ULARGE_INTEGER& uliSeekPtr,
  355. OUT PrnBinInfo*& lpPrnBinItem
  356. );
  357. HRESULT
  358. TPrnStream::
  359. WriteHeader(
  360. IN DWORD Flags
  361. );
  362. HRESULT
  363. TPrnStream::
  364. UpdateHeader(
  365. IN TPrnStream::EHeaderEntryType eHeaderEntryType,
  366. IN ULARGE_INTEGER dwInfo
  367. );
  368. HRESULT
  369. TPrnStream::
  370. ReadFromHeader(
  371. IN TPrnStream::EHeaderEntryType kHeaderEntryType,
  372. OUT ULARGE_INTEGER* puliSeekPtr
  373. );
  374. HRESULT
  375. TPrnStream::
  376. WriteDevMode(
  377. IN PDEVMODE lpDevMode,
  378. IN DWORD cbSize,
  379. IN EHeaderEntryType eDevModeType
  380. );
  381. HRESULT
  382. TPrnStream::
  383. MarshallUpItem (
  384. IN OUT PrnBinInfo*& lpPrnBinItem
  385. );
  386. HRESULT
  387. TPrnStream::
  388. AdjustItemSizeForWin64(
  389. IN OUT PrnBinInfo *&lpPrnBinItem,
  390. IN FieldInfo *pFieldInfo,
  391. IN SIZE_T cbSize,
  392. OUT SIZE_T &cbDifference
  393. );
  394. DWORD
  395. TPrnStream::
  396. AlignSize(
  397. DWORD cbSize
  398. );
  399. HRESULT
  400. TPrnStream::
  401. GetCurrentPosition(
  402. IN ULARGE_INTEGER& uliCurrentPosition
  403. );
  404. DWORD
  405. TPrnStream::
  406. GetItemSize(
  407. IN TPrnStream::EHeaderEntryType kHeaderEntryType
  408. );
  409. BOOL
  410. TPrnStream::
  411. bWalkPost (
  412. IN TString& pszKey,
  413. OUT LPDWORD lpcItems
  414. );
  415. BOOL
  416. TPrnStream::
  417. bWalkIn (
  418. IN TString& pszKey,
  419. OUT LPDWORD lpcItems
  420. );
  421. VOID
  422. TPrnStream::
  423. PortNameCase(
  424. IN DWORD Flags
  425. );
  426. VOID
  427. TPrnStream::
  428. ShareNameCase(
  429. IN DWORD Flags
  430. );
  431. BOOL
  432. TPrnStream::
  433. SetEndOfPrnStream(
  434. );
  435. HRESULT
  436. InitalizeColorProfileLibrary(
  437. VOID
  438. );
  439. STATUS
  440. sOpenPrinter(
  441. LPCTSTR pszPrinter,
  442. PDWORD pdwAccess,
  443. PHANDLE phPrinter
  444. );
  445. BOOL
  446. bGetPrinter(
  447. IN HANDLE hPrinter,
  448. IN DWORD dwLevel,
  449. IN OUT PVOID* ppvBuffer,
  450. IN OUT PDWORD pcbBuffer
  451. );
  452. BOOL
  453. bNewShareName(
  454. IN LPCTSTR lpszServer,
  455. IN LPCTSTR lpszBaseShareName,
  456. OUT TString &strShareName
  457. );
  458. #if DBG
  459. VOID
  460. TPrnStream::
  461. CheckHeader (
  462. IN TPrnStream::EHeaderEntryType eHeaderEntryType,
  463. IN ULARGE_INTEGER uliInfo
  464. );
  465. #endif
  466. public:
  467. TStream* m_pIStream;
  468. private:
  469. TString m_strFileName;
  470. TString m_strPrnName;
  471. HANDLE m_hPrinterHandle;
  472. BOOL m_bHeaderWritten;
  473. DWORD m_cIndex;
  474. DWORD m_ResolveCase;
  475. PrnBinInfo* m_pPrnBinItem;
  476. ULARGE_INTEGER m_cPrnDataItems;
  477. ULARGE_INTEGER m_uliSeekPtr;
  478. TLibrary *m_pColorProfileLibrary;
  479. pfnEnumColorProfilesW m_EnumColorProfiles;
  480. pfnAssociateColorProfileWithDeviceW m_AssociateColorProfileWithDevice;
  481. pfnDisassociateColorProfileFromDeviceW m_DisassociateColorProfileFromDevice;
  482. };
  483. inline
  484. HRESULT
  485. MakePrnPersistHResult(DWORD code)
  486. {
  487. return MAKE_HRESULT(1,FACILITY_ITF,code);
  488. };
  489. template <class T>
  490. T
  491. SubPointers(
  492. IN T pQuantity,
  493. IN PRINTER_INFO_2* pPI2
  494. )
  495. {
  496. return reinterpret_cast<T>(reinterpret_cast<UINT_PTR>(pQuantity) - reinterpret_cast<UINT_PTR>(pPI2));
  497. }
  498. template <class T>
  499. T
  500. AddPointers(
  501. IN PRINTER_INFO_2* pPI2,
  502. IN T pQuantity
  503. )
  504. {
  505. return reinterpret_cast<T>(reinterpret_cast<UINT_PTR>(pPI2) + reinterpret_cast<UINT_PTR>(pQuantity));
  506. }
  507. #endif