[PRINTING]
[reactos.git] / reactos / win32ss / printing / providers / localspl / precomp.h
1 /*
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>
6 */
7
8 #ifndef _PRECOMP_H
9 #define _PRECOMP_H
10
11 #define WIN32_NO_STATUS
12 #include <limits.h>
13 #include <stdlib.h>
14 #include <wchar.h>
15
16 #include <lmcons.h>
17 #include <rpc.h>
18 #include <strsafe.h>
19 #include <windef.h>
20 #include <winbase.h>
21 #include <wingdi.h>
22 #include <winreg.h>
23 #include <winspool.h>
24 #include <winsplp.h>
25 #include <ndk/rtlfuncs.h>
26
27 #define SKIPLIST_LEVELS 16
28 #include <skiplist.h>
29 #include <spoolss.h>
30
31 #include <wine/debug.h>
32 WINE_DEFAULT_DEBUG_CHANNEL(localspl);
33
34 // Macros
35 #define IS_VALID_JOB_ID(ID) (ID >= 1 && ID <= 99999)
36 #define IS_VALID_PRIORITY(P) (P >= MIN_PRIORITY && P <= MAX_PRIORITY)
37
38 // Constants
39 #define SHD_WIN2003_SIGNATURE 0x4968
40
41 // Function pointers
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);
50
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;
62
63 // Structures
64 /**
65 * Describes a Print Monitor.
66 */
67 struct _LOCAL_PRINT_MONITOR
68 {
69 LIST_ENTRY Entry;
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. */
76 };
77
78 /**
79 * Describes a Port handled by a Print Monitor.
80 */
81 struct _LOCAL_PORT
82 {
83 LIST_ENTRY Entry;
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. */
87 };
88
89 /**
90 * Describes a Print Processor.
91 */
92 struct _LOCAL_PRINT_PROCESSOR
93 {
94 LIST_ENTRY Entry;
95 PWSTR pwszName;
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;
104 };
105
106 /**
107 * Describes a printer and manages its print jobs.
108 * Created once for every printer at startup.
109 */
110 struct _LOCAL_PRINTER
111 {
112 // This sort key must be the first element for LookupElementSkiplist to work!
113 PWSTR pwszPrinterName;
114
115 DWORD dwAttributes;
116 DWORD dwStatus;
117 PWSTR pwszLocation;
118 PWSTR pwszPrinterDriver;
119 PWSTR pwszDescription;
120 PWSTR pwszDefaultDatatype;
121 PDEVMODEW pDefaultDevMode;
122 PLOCAL_PRINT_PROCESSOR pPrintProcessor;
123 PLOCAL_PORT pPort;
124 SKIPLIST JobList;
125 };
126
127 /**
128 * Describes an entire print job associated to a specific printer through the Printer member.
129 * Created with every valid call to LocalStartDocPrinter.
130 */
131 struct _LOCAL_JOB
132 {
133 // This sort key must be the first element for LookupElementSkiplist to work!
134 DWORD dwJobID; /** Internal and external ID of this Job */
135
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 */
156 };
157
158 /**
159 * Specific handle returned by LocalOpenPrinter for every valid call that opens a Printer or Print Job.
160 */
161 struct _LOCAL_PRINTER_HANDLE
162 {
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. */
169 };
170
171 /**
172 * Specific handle returned by LocalOpenPrinter for every valid call that opens a Port.
173 */
174 struct _LOCAL_PORT_HANDLE
175 {
176 HANDLE hPort; /** Handle returned by pfnOpenPort. */
177 PLOCAL_PORT pPort; /** Port associated with this handle. */
178 };
179
180 /**
181 * Specific handle returned by LocalOpenPrinter for every valid call that opens an XcvMonitor or XcvPort.
182 */
183 struct _LOCAL_XCV_HANDLE
184 {
185 HANDLE hXcv; /** Handle returned by pfnXcvOpenPort. */
186 PLOCAL_PRINT_MONITOR pPrintMonitor; /** Print Monitor associated with this handle. */
187 };
188
189 /**
190 * Describes a handle returned by LocalOpenPrinter.
191 * Suitable for all things that can be opened through LocalOpenPrinter.
192 */
193 struct _LOCAL_HANDLE
194 {
195 enum {
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. */
199 }
200 HandleType;
201 PVOID pSpecificHandle;
202 };
203
204 /**
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
208 */
209 struct _SHD_HEADER
210 {
211 DWORD dwSignature;
212 DWORD cbHeader;
213 WORD wStatus;
214 WORD wUnknown1;
215 DWORD dwJobID;
216 DWORD dwPriority;
217 DWORD offUserName;
218 DWORD offNotifyName;
219 DWORD offDocumentName;
220 DWORD offPort;
221 DWORD offPrinterName;
222 DWORD offDriverName;
223 DWORD offDevMode;
224 DWORD offPrintProcessor;
225 DWORD offDatatype;
226 DWORD offPrintProcessorParameters;
227 SYSTEMTIME stSubmitted;
228 DWORD dwStartTime;
229 DWORD dwUntilTime;
230 DWORD dwUnknown6;
231 DWORD dwTotalPages;
232 DWORD cbSecurityDescriptor;
233 DWORD offSecurityDescriptor;
234 DWORD dwUnknown3;
235 DWORD dwUnknown4;
236 DWORD dwUnknown5;
237 DWORD offMachineName;
238 DWORD dwSPLSize;
239 };
240
241 // jobs.c
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);
255
256 // main.c
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;
263
264 // monitors.c
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);
269
270 // ports.c
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);
274
275 // printers.c
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);
288
289 // printingthread.c
290 DWORD WINAPI PrintingThreadProc(PLOCAL_JOB pJob);
291
292 // printprocessors.c
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);
299
300 // tools.c
301 PWSTR AllocAndRegQueryWSZ(HKEY hKey, PCWSTR pwszValueName);
302 PDEVMODEW DuplicateDevMode(PDEVMODEW pInput);
303
304 #endif