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.

649 lines
13 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. kDontChangeDriver= 1<<5,
  161. };
  162. enum EHeaderEntryType
  163. {
  164. kPrnName,
  165. kPrnDataRoot,
  166. kcItems,
  167. kUserDevMode,
  168. kPrnDevMode,
  169. kPrnInfo2,
  170. kPrnInfo7,
  171. kSecurity,
  172. kColorProfile
  173. };
  174. enum EItemType
  175. {
  176. ktDevMode,
  177. ktPrnInfo2,
  178. ktPrnInfo7,
  179. ktSecurity,
  180. ktColorProfile,
  181. ktPrnName,
  182. ktREG_TYPE,
  183. };
  184. // header structure:
  185. //
  186. typedef struct PrnHeader
  187. {
  188. ULARGE_INTEGER pPrnName; //ptr to printer name into stream( offset in stream )
  189. ULARGE_INTEGER pPrnDataRoot; //ptr to where the Printer data items begins( contiguous holding )
  190. ULARGE_INTEGER cItems; //number of Printer data items
  191. ULARGE_INTEGER pUserDevMode; //ptr to user dev mode into stream ( offset in stream )
  192. ULARGE_INTEGER pPrnDevMode; //ptr to global dev mode into stream ( offset in stream )
  193. ULARGE_INTEGER pPrnInfo2; //ptr to PI2 into stream ( offset in stream )
  194. ULARGE_INTEGER pPrnInfo7; //ptr to PI7 into stream ( offset in stream )
  195. ULARGE_INTEGER pSecurity; //ptr to security settings into stream ( offset in stream )
  196. ULARGE_INTEGER pColorProfileSettings; //ptr to ICM profiles into stream ( offset in stream ; contiguous holding)
  197. };
  198. // item's structure
  199. //
  200. typedef struct PrnBinInfo
  201. {
  202. DWORD cbSize; // the item's size
  203. DWORD dwType; // item's type ( REG_SZ , etc for Printer data items )
  204. DWORD pKey; // ptr to key name into the item
  205. DWORD pValue; // ptr to value name into the item
  206. DWORD pData; // ptr to data
  207. DWORD cbData; // data size
  208. };
  209. typedef HRESULT (TPrnStream::*PersistFunct)(VOID);
  210. typedef HRESULT (TPrnStream::*ReadFunct)(PrnBinInfo**);
  211. typedef struct PrstSelection
  212. {
  213. DWORD iKeyWord;
  214. PersistFunct pPrstFunc;
  215. } PrstFunctEntry;
  216. typedef struct QuerySelection
  217. {
  218. DWORD iKeyWord;
  219. ReadFunct pReadFunct;
  220. } QueryFunctEntry;
  221. typedef BOOL (WINAPI *pfnEnumColorProfilesW)(PCWSTR, PENUMTYPEW, PBYTE, PDWORD, PDWORD);
  222. typedef BOOL (WINAPI *pfnAssociateColorProfileWithDeviceW)(PCWSTR, PCWSTR, PCWSTR);
  223. typedef BOOL (WINAPI *pfnDisassociateColorProfileFromDeviceW)(PCWSTR, PCWSTR, PCWSTR);
  224. HRESULT
  225. TPrnStream::
  226. WritePrnData(
  227. IN LPCTSTR pKey,
  228. IN LPCTSTR pValueName,
  229. IN DWORD cbValueName,
  230. IN DWORD dwType,
  231. IN LPBYTE pData,
  232. IN DWORD cbData
  233. );
  234. HRESULT
  235. TPrnStream::
  236. ReadNextPrnData(
  237. OUT LPTSTR& lpszKey,
  238. OUT LPTSTR& lpszVal,
  239. OUT DWORD& dwType,
  240. OUT LPBYTE& lpbData,
  241. OUT DWORD& cbSize,
  242. OUT LPBYTE& lpBuffer
  243. );
  244. BOOL
  245. TPrnStream::
  246. bWriteKeyData(
  247. IN LPCTSTR lpszKey,
  248. OUT LPDWORD lpcItems
  249. );
  250. BOOL
  251. TPrnStream::
  252. bWriteKeyValue(
  253. IN LPCTSTR lpszKey,
  254. IN LPPRINTER_ENUM_VALUES lpPEV
  255. );
  256. HRESULT
  257. TPrnStream::
  258. WritePrnInfo2(
  259. IN PRINTER_INFO_2* lpPrinterInfo2,
  260. IN DWORD cbPI2Size
  261. );
  262. HRESULT
  263. TPrnStream::
  264. ReadPrnInfo2(
  265. OUT PrnBinInfo** lppPrnBinItem
  266. );
  267. HRESULT
  268. TPrnStream::
  269. ReadPrnName(
  270. OUT TString& strPrnName
  271. );
  272. HRESULT
  273. TPrnStream::
  274. WritePrnName(
  275. VOID
  276. );
  277. HRESULT
  278. TPrnStream::
  279. WritePrnInfo7(
  280. IN PRINTER_INFO_7* lpPrinterInfo7,
  281. IN DWORD cbPI7Size
  282. );
  283. HRESULT
  284. TPrnStream::
  285. ReadPrnInfo7(
  286. OUT PrnBinInfo** lppPrnBinItem
  287. );
  288. HRESULT
  289. TPrnStream::
  290. WritePrnSecurity(
  291. IN PRINTER_INFO_2* lpPrinterInfo2,
  292. IN DWORD cbPI2Size
  293. );
  294. HRESULT
  295. TPrnStream::
  296. ReadPrnSecurity(
  297. OUT PrnBinInfo** ppPrnBinItem
  298. );
  299. HRESULT
  300. TPrnStream::
  301. WritePrnInfo8(
  302. IN PRINTER_INFO_8* lpPrinterInfo8,
  303. IN DWORD cbSize
  304. );
  305. HRESULT
  306. TPrnStream::
  307. ReadPrnInfo8(
  308. OUT PrnBinInfo** lppPrnBinItem
  309. );
  310. HRESULT
  311. TPrnStream::
  312. WritePrnInfo9(
  313. IN PRINTER_INFO_9* lpPrinterInfo8,
  314. IN DWORD cbSize
  315. );
  316. HRESULT
  317. TPrnStream::
  318. ReadPrnInfo9(
  319. OUT PrnBinInfo** ppPrnBinItem
  320. );
  321. HRESULT
  322. TPrnStream::
  323. WriteColorProfiles(
  324. IN LPBYTE lpProfiles,
  325. IN DWORD cbSize
  326. );
  327. HRESULT
  328. TPrnStream::
  329. ReadColorProfiles(
  330. OUT PrnBinInfo** ppPrnBinItem
  331. );
  332. HRESULT
  333. TPrnStream::
  334. WriteItem(
  335. IN LPCTSTR pKey,
  336. IN LPCTSTR pValueName,
  337. IN DWORD cbValueName,
  338. IN DWORD dwType,
  339. IN LPBYTE pData,
  340. IN DWORD cbData
  341. );
  342. HRESULT
  343. TPrnStream::
  344. ReadItem(
  345. OUT LPTSTR& lpszKey,
  346. OUT LPTSTR& lpszVal,
  347. OUT DWORD& dwType,
  348. OUT LPBYTE& lpbData,
  349. OUT DWORD& cbSize,
  350. OUT LPBYTE& lpBuffer
  351. );
  352. HRESULT
  353. TPrnStream::
  354. ReadItemFromPosition(
  355. IN OUT ULARGE_INTEGER& uliSeekPtr,
  356. OUT PrnBinInfo*& lpPrnBinItem
  357. );
  358. HRESULT
  359. TPrnStream::
  360. WriteHeader(
  361. IN DWORD Flags
  362. );
  363. HRESULT
  364. TPrnStream::
  365. UpdateHeader(
  366. IN TPrnStream::EHeaderEntryType eHeaderEntryType,
  367. IN ULARGE_INTEGER dwInfo
  368. );
  369. HRESULT
  370. TPrnStream::
  371. ReadFromHeader(
  372. IN TPrnStream::EHeaderEntryType kHeaderEntryType,
  373. OUT ULARGE_INTEGER* puliSeekPtr
  374. );
  375. HRESULT
  376. TPrnStream::
  377. WriteDevMode(
  378. IN PDEVMODE lpDevMode,
  379. IN DWORD cbSize,
  380. IN EHeaderEntryType eDevModeType
  381. );
  382. HRESULT
  383. TPrnStream::
  384. MarshallUpItem (
  385. IN OUT PrnBinInfo*& lpPrnBinItem
  386. );
  387. HRESULT
  388. TPrnStream::
  389. AdjustItemSizeForWin64(
  390. IN OUT PrnBinInfo *&lpPrnBinItem,
  391. IN FieldInfo *pFieldInfo,
  392. IN SIZE_T cbSize,
  393. OUT SIZE_T &cbDifference
  394. );
  395. DWORD
  396. TPrnStream::
  397. AlignSize(
  398. DWORD cbSize
  399. );
  400. HRESULT
  401. TPrnStream::
  402. GetCurrentPosition(
  403. IN ULARGE_INTEGER& uliCurrentPosition
  404. );
  405. DWORD
  406. TPrnStream::
  407. GetItemSize(
  408. IN TPrnStream::EHeaderEntryType kHeaderEntryType
  409. );
  410. BOOL
  411. TPrnStream::
  412. bWalkPost (
  413. IN TString& pszKey,
  414. OUT LPDWORD lpcItems
  415. );
  416. BOOL
  417. TPrnStream::
  418. bWalkIn (
  419. IN TString& pszKey,
  420. OUT LPDWORD lpcItems
  421. );
  422. VOID
  423. TPrnStream::
  424. PortNameCase(
  425. IN DWORD Flags
  426. );
  427. VOID
  428. TPrnStream::
  429. DriverNameCase(
  430. IN DWORD Flags
  431. );
  432. VOID
  433. TPrnStream::
  434. ShareNameCase(
  435. IN DWORD Flags
  436. );
  437. BOOL
  438. TPrnStream::
  439. SetEndOfPrnStream(
  440. );
  441. HRESULT
  442. InitalizeColorProfileLibrary(
  443. VOID
  444. );
  445. STATUS
  446. sOpenPrinter(
  447. LPCTSTR pszPrinter,
  448. PDWORD pdwAccess,
  449. PHANDLE phPrinter
  450. );
  451. BOOL
  452. bGetPrinter(
  453. IN HANDLE hPrinter,
  454. IN DWORD dwLevel,
  455. IN OUT PVOID* ppvBuffer,
  456. IN OUT PDWORD pcbBuffer
  457. );
  458. BOOL
  459. bNewShareName(
  460. IN LPCTSTR lpszServer,
  461. IN LPCTSTR lpszBaseShareName,
  462. OUT TString &strShareName
  463. );
  464. #if DBG
  465. VOID
  466. TPrnStream::
  467. CheckHeader (
  468. IN TPrnStream::EHeaderEntryType eHeaderEntryType,
  469. IN ULARGE_INTEGER uliInfo
  470. );
  471. #endif
  472. public:
  473. TStream* m_pIStream;
  474. private:
  475. TString m_strFileName;
  476. TString m_strPrnName;
  477. HANDLE m_hPrinterHandle;
  478. BOOL m_bHeaderWritten;
  479. DWORD m_cIndex;
  480. DWORD m_ResolveCase;
  481. PrnBinInfo* m_pPrnBinItem;
  482. ULARGE_INTEGER m_cPrnDataItems;
  483. ULARGE_INTEGER m_uliSeekPtr;
  484. TLibrary *m_pColorProfileLibrary;
  485. pfnEnumColorProfilesW m_EnumColorProfiles;
  486. pfnAssociateColorProfileWithDeviceW m_AssociateColorProfileWithDevice;
  487. pfnDisassociateColorProfileFromDeviceW m_DisassociateColorProfileFromDevice;
  488. };
  489. inline
  490. HRESULT
  491. MakePrnPersistHResult(DWORD code)
  492. {
  493. return MAKE_HRESULT(1,FACILITY_ITF,code);
  494. };
  495. template <class T>
  496. T
  497. SubPointers(
  498. IN T pQuantity,
  499. IN PRINTER_INFO_2* pPI2
  500. )
  501. {
  502. return reinterpret_cast<T>(reinterpret_cast<UINT_PTR>(pQuantity) - reinterpret_cast<UINT_PTR>(pPI2));
  503. }
  504. template <class T>
  505. T
  506. AddPointers(
  507. IN PRINTER_INFO_2* pPI2,
  508. IN T pQuantity
  509. )
  510. {
  511. return reinterpret_cast<T>(reinterpret_cast<UINT_PTR>(pPI2) + reinterpret_cast<UINT_PTR>(pQuantity));
  512. }
  513. #endif