2 * PROJECT: ReactOS Local Spooler
3 * LICENSE: GNU LGPL v2.1 or any later version as published by the Free Software Foundation
4 * PURPOSE: Precompiled Header for all source files
5 * COPYRIGHT: Copyright 2015-2017 Colin Finck <colin@reactos.org>
11 #define WIN32_NO_STATUS
25 #include <ndk/rtlfuncs.h>
27 #define SKIPLIST_LEVELS 16
31 #include <wine/debug.h>
32 WINE_DEFAULT_DEBUG_CHANNEL(localspl
);
35 #define IS_VALID_JOB_ID(ID) (ID >= 1 && ID <= 99999)
36 #define IS_VALID_PRIORITY(P) (P >= MIN_PRIORITY && P <= MAX_PRIORITY)
39 #define SHD_WIN2003_SIGNATURE 0x4968
42 typedef BOOL (WINAPI
*PClosePrintProcessor
)(HANDLE
);
43 typedef BOOL (WINAPI
*PControlPrintProcessor
)(HANDLE
, DWORD
);
44 typedef BOOL (WINAPI
*PEnumPrintProcessorDatatypesW
)(LPWSTR
, LPWSTR
, DWORD
, LPBYTE
, DWORD
, LPDWORD
, LPDWORD
);
45 typedef DWORD (WINAPI
*PGetPrintProcessorCapabilities
)(LPWSTR
, DWORD
, LPBYTE
, DWORD
, LPDWORD
);
46 typedef HANDLE (WINAPI
*POpenPrintProcessor
)(LPWSTR
, PPRINTPROCESSOROPENDATA
);
47 typedef BOOL (WINAPI
*PPrintDocumentOnPrintProcessor
)(HANDLE
, LPWSTR
);
48 typedef LPMONITOREX(WINAPI
*PInitializePrintMonitor
)(PWSTR
);
49 typedef LPMONITOR2(WINAPI
*PInitializePrintMonitor2
)(PMONITORINIT
, PHANDLE
);
51 // Forward declarations
52 typedef struct _LOCAL_HANDLE LOCAL_HANDLE
, *PLOCAL_HANDLE
;
53 typedef struct _LOCAL_JOB LOCAL_JOB
, *PLOCAL_JOB
;
54 typedef struct _LOCAL_PORT LOCAL_PORT
, *PLOCAL_PORT
;
55 typedef struct _LOCAL_PORT_HANDLE LOCAL_PORT_HANDLE
, *PLOCAL_PORT_HANDLE
;
56 typedef struct _LOCAL_PRINT_MONITOR LOCAL_PRINT_MONITOR
, *PLOCAL_PRINT_MONITOR
;
57 typedef struct _LOCAL_PRINT_PROCESSOR LOCAL_PRINT_PROCESSOR
, *PLOCAL_PRINT_PROCESSOR
;
58 typedef struct _LOCAL_PRINTER LOCAL_PRINTER
, *PLOCAL_PRINTER
;
59 typedef struct _LOCAL_PRINTER_HANDLE LOCAL_PRINTER_HANDLE
, *PLOCAL_PRINTER_HANDLE
;
60 typedef struct _LOCAL_XCV_HANDLE LOCAL_XCV_HANDLE
, *PLOCAL_XCV_HANDLE
;
61 typedef struct _SHD_HEADER SHD_HEADER
, *PSHD_HEADER
;
65 * Describes a Print Monitor.
67 struct _LOCAL_PRINT_MONITOR
70 PWSTR pwszName
; /** Name of the Print Monitor as read from the registry. */
71 PWSTR pwszFileName
; /** DLL File Name of the Print Monitor. */
72 BOOL bIsLevel2
; /** Whether this Print Monitor supplies an InitializePrintMonitor2 API (preferred) instead of InitializePrintMonitor. */
73 PVOID pMonitor
; /** For bIsLevel2 == TRUE: LPMONITOR2 pointer returned by InitializePrintMonitor2.
74 For bIsLevel2 == FALSE: LPMONITOREX pointer returned by InitializePrintMonitor. */
75 HANDLE hMonitor
; /** Only used when bIsLevel2 == TRUE: Handle returned by InitializePrintMonitor2. */
79 * Describes a Port handled by a Print Monitor.
84 PWSTR pwszName
; /** The name of the port (including the trailing colon). */
85 PLOCAL_PRINT_MONITOR pPrintMonitor
; /** The Print Monitor handling this port. */
86 PLOCAL_JOB pNextJobToProcess
; /** The Print Job that will be processed by the next created Port handle. */
90 * Describes a Print Processor.
92 struct _LOCAL_PRINT_PROCESSOR
96 PDATATYPES_INFO_1W pDatatypesInfo1
;
97 DWORD dwDatatypeCount
;
98 PClosePrintProcessor pfnClosePrintProcessor
;
99 PControlPrintProcessor pfnControlPrintProcessor
;
100 PEnumPrintProcessorDatatypesW pfnEnumPrintProcessorDatatypesW
;
101 PGetPrintProcessorCapabilities pfnGetPrintProcessorCapabilities
;
102 POpenPrintProcessor pfnOpenPrintProcessor
;
103 PPrintDocumentOnPrintProcessor pfnPrintDocumentOnPrintProcessor
;
107 * Describes a printer and manages its print jobs.
108 * Created once for every printer at startup.
110 struct _LOCAL_PRINTER
112 // This sort key must be the first element for LookupElementSkiplist to work!
113 PWSTR pwszPrinterName
;
118 PWSTR pwszPrinterDriver
;
119 PWSTR pwszDescription
;
120 PWSTR pwszDefaultDatatype
;
121 PDEVMODEW pDefaultDevMode
;
122 PLOCAL_PRINT_PROCESSOR pPrintProcessor
;
128 * Describes an entire print job associated to a specific printer through the Printer member.
129 * Created with every valid call to LocalStartDocPrinter.
133 // This sort key must be the first element for LookupElementSkiplist to work!
134 DWORD dwJobID
; /** Internal and external ID of this Job */
136 BOOL bAddedJob
: 1; /** Whether AddJob has already been called on this Job. */
137 HANDLE hPrintProcessor
; /** Handle returned by OpenPrintProcessor while the Job is printing. */
138 PLOCAL_PRINTER pPrinter
; /** Associated Printer to this Job */
139 PLOCAL_PRINT_PROCESSOR pPrintProcessor
; /** Associated Print Processor to this Job */
140 DWORD dwPriority
; /** Priority of this Job from MIN_PRIORITY to MAX_PRIORITY, default being DEF_PRIORITY */
141 SYSTEMTIME stSubmitted
; /** Time of the submission of this Job */
142 PWSTR pwszUserName
; /** Optional; User that submitted the Job */
143 PWSTR pwszNotifyName
; /** Optional; User that shall be notified about the status of the Job */
144 PWSTR pwszDocumentName
; /** Optional; Name of the Document that is printed */
145 PWSTR pwszDatatype
; /** Datatype of the Document */
146 PWSTR pwszOutputFile
; /** Output File to spool the Job to */
147 PWSTR pwszPrintProcessorParameters
; /** Optional; Parameters for the chosen Print Processor */
148 PWSTR pwszStatus
; /** Optional; a Status Message for the Job */
149 DWORD dwTotalPages
; /** Total pages of the Document */
150 DWORD dwPagesPrinted
; /** Number of pages that have already been printed */
151 DWORD dwStartTime
; /** Earliest time in minutes since 12:00 AM UTC when this document can be printed */
152 DWORD dwUntilTime
; /** Latest time in minutes since 12:00 AM UTC when this document can be printed */
153 DWORD dwStatus
; /** JOB_STATUS_* flags of the Job */
154 PWSTR pwszMachineName
; /** Name of the machine that submitted the Job (prepended with two backslashes) */
155 PDEVMODEW pDevMode
; /** Associated Device Mode to this Job */
159 * Specific handle returned by LocalOpenPrinter for every valid call that opens a Printer or Print Job.
161 struct _LOCAL_PRINTER_HANDLE
163 BOOL bStartedDoc
: 1; /** Whether StartDocPrinter has already been called. */
164 HANDLE hSPLFile
; /** Handle to an opened SPL file for Printer Job handles. */
165 PLOCAL_PRINTER pPrinter
; /** Printer associated with this handle. */
166 PLOCAL_JOB pJob
; /** Print Job associated with this handle. This can be the specified Job if this is a Print Job handle or the started job through LocalStartDocPrinter. */
167 PWSTR pwszDatatype
; /** Datatype used for newly started jobs. */
168 PDEVMODEW pDevMode
; /** DevMode used for newly started jobs. */
172 * Specific handle returned by LocalOpenPrinter for every valid call that opens a Port.
174 struct _LOCAL_PORT_HANDLE
176 HANDLE hPort
; /** Handle returned by pfnOpenPort. */
177 PLOCAL_PORT pPort
; /** Port associated with this handle. */
181 * Specific handle returned by LocalOpenPrinter for every valid call that opens an XcvMonitor or XcvPort.
183 struct _LOCAL_XCV_HANDLE
185 HANDLE hXcv
; /** Handle returned by pfnXcvOpenPort. */
186 PLOCAL_PRINT_MONITOR pPrintMonitor
; /** Print Monitor associated with this handle. */
190 * Describes a handle returned by LocalOpenPrinter.
191 * Suitable for all things that can be opened through LocalOpenPrinter.
196 HandleType_Port
, /** pSpecificHandle is a PLOCAL_PORT_HANDLE. */
197 HandleType_Printer
, /** pSpecificHandle is a PLOCAL_PRINTER_HANDLE. */
198 HandleType_Xcv
/** pSpecificHandle is a PLOCAL_XCV_HANDLE. */
201 PVOID pSpecificHandle
;
205 * Describes the header of a print job serialized into a shadow file (.SHD)
206 * Documented in http://www.undocprint.org/formats/winspool/shd
207 * Compatible with Windows Server 2003
219 DWORD offDocumentName
;
221 DWORD offPrinterName
;
224 DWORD offPrintProcessor
;
226 DWORD offPrintProcessorParameters
;
227 SYSTEMTIME stSubmitted
;
232 DWORD cbSecurityDescriptor
;
233 DWORD offSecurityDescriptor
;
237 DWORD offMachineName
;
242 extern SKIPLIST GlobalJobList
;
243 DWORD WINAPI
CreateJob(PLOCAL_PRINTER_HANDLE pPrinterHandle
);
244 void FreeJob(PLOCAL_JOB pJob
);
245 DWORD
GetJobFilePath(PCWSTR pwszExtension
, DWORD dwJobID
, PWSTR pwszOutput
);
246 BOOL
InitializeGlobalJobList();
247 void InitializePrinterJobList(PLOCAL_PRINTER pPrinter
);
248 BOOL WINAPI
LocalAddJob(HANDLE hPrinter
, DWORD Level
, LPBYTE pData
, DWORD cbBuf
, LPDWORD pcbNeeded
);
249 BOOL WINAPI
LocalEnumJobs(HANDLE hPrinter
, DWORD FirstJob
, DWORD NoJobs
, DWORD Level
, PBYTE pStart
, DWORD cbBuf
, LPDWORD pcbNeeded
, LPDWORD pcReturned
);
250 BOOL WINAPI
LocalGetJob(HANDLE hPrinter
, DWORD JobId
, DWORD Level
, PBYTE pStart
, DWORD cbBuf
, LPDWORD pcbNeeded
);
251 BOOL WINAPI
LocalScheduleJob(HANDLE hPrinter
, DWORD dwJobID
);
252 BOOL WINAPI
LocalSetJob(HANDLE hPrinter
, DWORD JobId
, DWORD Level
, PBYTE pJobInfo
, DWORD Command
);
253 PLOCAL_JOB
ReadJobShadowFile(PCWSTR pwszFilePath
);
254 BOOL
WriteJobShadowFile(PWSTR pwszFilePath
, const PLOCAL_JOB pJob
);
257 extern const WCHAR wszCurrentEnvironment
[];
258 extern const DWORD cbCurrentEnvironment
;
259 extern const WCHAR wszDefaultDocumentName
[];
260 extern PWSTR wszPrintProviderInfo
[3];
261 extern WCHAR wszSpoolDirectory
[MAX_PATH
];
262 extern DWORD cchSpoolDirectory
;
265 extern LIST_ENTRY PrintMonitorList
;
266 PLOCAL_PRINT_MONITOR
FindPrintMonitor(PCWSTR pwszName
);
267 BOOL
InitializePrintMonitorList();
268 BOOL WINAPI
LocalEnumMonitors(PWSTR pName
, DWORD Level
, PBYTE pMonitors
, DWORD cbBuf
, PDWORD pcbNeeded
, PDWORD pcReturned
);
271 PLOCAL_PORT
FindPort(PCWSTR pwszName
);
272 BOOL
InitializePortList();
273 BOOL WINAPI
LocalEnumPorts(PWSTR pName
, DWORD Level
, PBYTE pPorts
, DWORD cbBuf
, PDWORD pcbNeeded
, PDWORD pcReturned
);
276 extern SKIPLIST PrinterList
;
277 BOOL
InitializePrinterList();
278 BOOL WINAPI
LocalEnumPrinters(DWORD Flags
, LPWSTR Name
, DWORD Level
, LPBYTE pPrinterEnum
, DWORD cbBuf
, LPDWORD pcbNeeded
, LPDWORD pcReturned
);
279 BOOL WINAPI
LocalGetPrinter(HANDLE hPrinter
, DWORD Level
, LPBYTE pPrinter
, DWORD cbBuf
, LPDWORD pcbNeeded
);
280 BOOL WINAPI
LocalOpenPrinter(PWSTR lpPrinterName
, HANDLE
* phPrinter
, PPRINTER_DEFAULTSW pDefault
);
281 BOOL WINAPI
LocalReadPrinter(HANDLE hPrinter
, PVOID pBuf
, DWORD cbBuf
, PDWORD pNoBytesRead
);
282 DWORD WINAPI
LocalStartDocPrinter(HANDLE hPrinter
, DWORD Level
, LPBYTE pDocInfo
);
283 BOOL WINAPI
LocalStartPagePrinter(HANDLE hPrinter
);
284 BOOL WINAPI
LocalWritePrinter(HANDLE hPrinter
, LPVOID pBuf
, DWORD cbBuf
, LPDWORD pcWritten
);
285 BOOL WINAPI
LocalEndPagePrinter(HANDLE hPrinter
);
286 BOOL WINAPI
LocalEndDocPrinter(HANDLE hPrinter
);
287 BOOL WINAPI
LocalClosePrinter(HANDLE hPrinter
);
290 DWORD WINAPI
PrintingThreadProc(PLOCAL_JOB pJob
);
293 BOOL
FindDatatype(const PLOCAL_PRINT_PROCESSOR pPrintProcessor
, PCWSTR pwszDatatype
);
294 PLOCAL_PRINT_PROCESSOR
FindPrintProcessor(PCWSTR pwszName
);
295 BOOL
InitializePrintProcessorList();
296 BOOL WINAPI
LocalEnumPrintProcessorDatatypes(LPWSTR pName
, LPWSTR pPrintProcessorName
, DWORD Level
, LPBYTE pDatatypes
, DWORD cbBuf
, LPDWORD pcbNeeded
, LPDWORD pcReturned
);
297 BOOL WINAPI
LocalEnumPrintProcessors(LPWSTR pName
, LPWSTR pEnvironment
, DWORD Level
, LPBYTE pPrintProcessorInfo
, DWORD cbBuf
, LPDWORD pcbNeeded
, LPDWORD pcReturned
);
298 BOOL WINAPI
LocalGetPrintProcessorDirectory(LPWSTR pName
, LPWSTR pEnvironment
, DWORD Level
, LPBYTE pPrintProcessorInfo
, DWORD cbBuf
, LPDWORD pcbNeeded
);
301 PWSTR
AllocAndRegQueryWSZ(HKEY hKey
, PCWSTR pwszValueName
);
302 PDEVMODEW
DuplicateDevMode(PDEVMODEW pInput
);