[USETUP]: Improve the bootsector validity check performed in IsThereAValidBootSector:
[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 MAX_PRINTER_NAME 220
40 #define SHD_WIN2003_SIGNATURE 0x4968
41
42 // Function pointers
43 typedef BOOL (WINAPI *PClosePrintProcessor)(HANDLE);
44 typedef BOOL (WINAPI *PControlPrintProcessor)(HANDLE, DWORD);
45 typedef BOOL (WINAPI *PEnumPrintProcessorDatatypesW)(LPWSTR, LPWSTR, DWORD, LPBYTE, DWORD, LPDWORD, LPDWORD);
46 typedef DWORD (WINAPI *PGetPrintProcessorCapabilities)(LPWSTR, DWORD, LPBYTE, DWORD, LPDWORD);
47 typedef HANDLE (WINAPI *POpenPrintProcessor)(LPWSTR, PPRINTPROCESSOROPENDATA);
48 typedef BOOL (WINAPI *PPrintDocumentOnPrintProcessor)(HANDLE, LPWSTR);
49 typedef LPMONITOREX(WINAPI *PInitializePrintMonitor)(PWSTR);
50 typedef LPMONITOR2(WINAPI *PInitializePrintMonitor2)(PMONITORINIT, PHANDLE);
51
52 // Forward declarations
53 typedef struct _LOCAL_HANDLE LOCAL_HANDLE, *PLOCAL_HANDLE;
54 typedef struct _LOCAL_JOB LOCAL_JOB, *PLOCAL_JOB;
55 typedef struct _LOCAL_PORT LOCAL_PORT, *PLOCAL_PORT;
56 typedef struct _LOCAL_PORT_HANDLE LOCAL_PORT_HANDLE, *PLOCAL_PORT_HANDLE;
57 typedef struct _LOCAL_PRINT_MONITOR LOCAL_PRINT_MONITOR, *PLOCAL_PRINT_MONITOR;
58 typedef struct _LOCAL_PRINT_PROCESSOR LOCAL_PRINT_PROCESSOR, *PLOCAL_PRINT_PROCESSOR;
59 typedef struct _LOCAL_PRINTER LOCAL_PRINTER, *PLOCAL_PRINTER;
60 typedef struct _LOCAL_PRINTER_HANDLE LOCAL_PRINTER_HANDLE, *PLOCAL_PRINTER_HANDLE;
61 typedef struct _LOCAL_XCV_HANDLE LOCAL_XCV_HANDLE, *PLOCAL_XCV_HANDLE;
62 typedef struct _SHD_HEADER SHD_HEADER, *PSHD_HEADER;
63
64 // Structures
65 /**
66 * Describes a Print Monitor.
67 */
68 struct _LOCAL_PRINT_MONITOR
69 {
70 LIST_ENTRY Entry;
71 PWSTR pwszName; /** Name of the Print Monitor as read from the registry. */
72 PWSTR pwszFileName; /** DLL File Name of the Print Monitor. */
73 BOOL bIsLevel2; /** Whether this Print Monitor supplies an InitializePrintMonitor2 API (preferred) instead of InitializePrintMonitor. */
74 PVOID pMonitor; /** For bIsLevel2 == TRUE: LPMONITOR2 pointer returned by InitializePrintMonitor2.
75 For bIsLevel2 == FALSE: LPMONITOREX pointer returned by InitializePrintMonitor. */
76 HANDLE hMonitor; /** Only used when bIsLevel2 == TRUE: Handle returned by InitializePrintMonitor2. */
77 };
78
79 /**
80 * Describes a Port handled by a Print Monitor.
81 */
82 struct _LOCAL_PORT
83 {
84 LIST_ENTRY Entry;
85 PWSTR pwszName; /** The name of the port (including the trailing colon). */
86 PLOCAL_PRINT_MONITOR pPrintMonitor; /** The Print Monitor handling this port. */
87 PLOCAL_JOB pNextJobToProcess; /** The Print Job that will be processed by the next created Port handle. */
88 };
89
90 /**
91 * Describes a Print Processor.
92 */
93 struct _LOCAL_PRINT_PROCESSOR
94 {
95 LIST_ENTRY Entry;
96 PWSTR pwszName;
97 PDATATYPES_INFO_1W pDatatypesInfo1;
98 DWORD dwDatatypeCount;
99 PClosePrintProcessor pfnClosePrintProcessor;
100 PControlPrintProcessor pfnControlPrintProcessor;
101 PEnumPrintProcessorDatatypesW pfnEnumPrintProcessorDatatypesW;
102 PGetPrintProcessorCapabilities pfnGetPrintProcessorCapabilities;
103 POpenPrintProcessor pfnOpenPrintProcessor;
104 PPrintDocumentOnPrintProcessor pfnPrintDocumentOnPrintProcessor;
105 };
106
107 /**
108 * Describes a printer and manages its print jobs.
109 * Created once for every printer at startup.
110 */
111 struct _LOCAL_PRINTER
112 {
113 // This sort key must be the first element for LookupElementSkiplist to work!
114 PWSTR pwszPrinterName;
115
116 DWORD dwAttributes;
117 DWORD dwStatus;
118 PWSTR pwszLocation;
119 PWSTR pwszPrinterDriver;
120 PWSTR pwszDescription;
121 PWSTR pwszDefaultDatatype;
122 PDEVMODEW pDefaultDevMode;
123 PLOCAL_PRINT_PROCESSOR pPrintProcessor;
124 PLOCAL_PORT pPort;
125 SKIPLIST JobList;
126 };
127
128 /**
129 * Describes an entire print job associated to a specific printer through the Printer member.
130 * Created with every valid call to LocalStartDocPrinter.
131 */
132 struct _LOCAL_JOB
133 {
134 // This sort key must be the first element for LookupElementSkiplist to work!
135 DWORD dwJobID; /** Internal and external ID of this Job */
136
137 BOOL bAddedJob : 1; /** Whether AddJob has already been called on this Job. */
138 HANDLE hPrintProcessor; /** Handle returned by OpenPrintProcessor while the Job is printing. */
139 PLOCAL_PRINTER pPrinter; /** Associated Printer to this Job */
140 PLOCAL_PRINT_PROCESSOR pPrintProcessor; /** Associated Print Processor to this Job */
141 DWORD dwPriority; /** Priority of this Job from MIN_PRIORITY to MAX_PRIORITY, default being DEF_PRIORITY */
142 SYSTEMTIME stSubmitted; /** Time of the submission of this Job */
143 PWSTR pwszUserName; /** Optional; User that submitted the Job */
144 PWSTR pwszNotifyName; /** Optional; User that shall be notified about the status of the Job */
145 PWSTR pwszDocumentName; /** Optional; Name of the Document that is printed */
146 PWSTR pwszDatatype; /** Datatype of the Document */
147 PWSTR pwszOutputFile; /** Output File to spool the Job to */
148 PWSTR pwszPrintProcessorParameters; /** Optional; Parameters for the chosen Print Processor */
149 PWSTR pwszStatus; /** Optional; a Status Message for the Job */
150 DWORD dwTotalPages; /** Total pages of the Document */
151 DWORD dwPagesPrinted; /** Number of pages that have already been printed */
152 DWORD dwStartTime; /** Earliest time in minutes since 12:00 AM UTC when this document can be printed */
153 DWORD dwUntilTime; /** Latest time in minutes since 12:00 AM UTC when this document can be printed */
154 DWORD dwStatus; /** JOB_STATUS_* flags of the Job */
155 PWSTR pwszMachineName; /** Name of the machine that submitted the Job (prepended with two backslashes) */
156 PDEVMODEW pDevMode; /** Associated Device Mode to this Job */
157 };
158
159 /**
160 * Specific handle returned by LocalOpenPrinter for every valid call that opens a Printer or Print Job.
161 */
162 struct _LOCAL_PRINTER_HANDLE
163 {
164 BOOL bStartedDoc : 1; /** Whether StartDocPrinter has already been called. */
165 HANDLE hSPLFile; /** Handle to an opened SPL file for Printer Job handles. */
166 PLOCAL_PRINTER pPrinter; /** Printer associated with this handle. */
167 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. */
168 PWSTR pwszDatatype; /** Datatype used for newly started jobs. */
169 PDEVMODEW pDevMode; /** DevMode used for newly started jobs. */
170 };
171
172 /**
173 * Specific handle returned by LocalOpenPrinter for every valid call that opens a Port.
174 */
175 struct _LOCAL_PORT_HANDLE
176 {
177 HANDLE hPort; /** Handle returned by pfnOpenPort. */
178 PLOCAL_PORT pPort; /** Port associated with this handle. */
179 };
180
181 /**
182 * Specific handle returned by LocalOpenPrinter for every valid call that opens an XcvMonitor or XcvPort.
183 */
184 struct _LOCAL_XCV_HANDLE
185 {
186 HANDLE hXcv; /** Handle returned by pfnXcvOpenPort. */
187 PLOCAL_PRINT_MONITOR pPrintMonitor; /** Print Monitor associated with this handle. */
188 };
189
190 /**
191 * Describes a handle returned by LocalOpenPrinter.
192 * Suitable for all things that can be opened through LocalOpenPrinter.
193 */
194 struct _LOCAL_HANDLE
195 {
196 enum {
197 HandleType_Port, /** pSpecificHandle is a PLOCAL_PORT_HANDLE. */
198 HandleType_Printer, /** pSpecificHandle is a PLOCAL_PRINTER_HANDLE. */
199 HandleType_Xcv /** pSpecificHandle is a PLOCAL_XCV_HANDLE. */
200 }
201 HandleType;
202 PVOID pSpecificHandle;
203 };
204
205 /**
206 * Describes the header of a print job serialized into a shadow file (.SHD)
207 * Documented in http://www.undocprint.org/formats/winspool/shd
208 * Compatible with Windows Server 2003
209 */
210 struct _SHD_HEADER
211 {
212 DWORD dwSignature;
213 DWORD cbHeader;
214 WORD wStatus;
215 WORD wUnknown1;
216 DWORD dwJobID;
217 DWORD dwPriority;
218 DWORD offUserName;
219 DWORD offNotifyName;
220 DWORD offDocumentName;
221 DWORD offPort;
222 DWORD offPrinterName;
223 DWORD offDriverName;
224 DWORD offDevMode;
225 DWORD offPrintProcessor;
226 DWORD offDatatype;
227 DWORD offPrintProcessorParameters;
228 SYSTEMTIME stSubmitted;
229 DWORD dwStartTime;
230 DWORD dwUntilTime;
231 DWORD dwUnknown6;
232 DWORD dwTotalPages;
233 DWORD cbSecurityDescriptor;
234 DWORD offSecurityDescriptor;
235 DWORD dwUnknown3;
236 DWORD dwUnknown4;
237 DWORD dwUnknown5;
238 DWORD offMachineName;
239 DWORD dwSPLSize;
240 };
241
242 // jobs.c
243 extern SKIPLIST GlobalJobList;
244 DWORD WINAPI CreateJob(PLOCAL_PRINTER_HANDLE pPrinterHandle);
245 void FreeJob(PLOCAL_JOB pJob);
246 DWORD GetJobFilePath(PCWSTR pwszExtension, DWORD dwJobID, PWSTR pwszOutput);
247 BOOL InitializeGlobalJobList();
248 void InitializePrinterJobList(PLOCAL_PRINTER pPrinter);
249 BOOL WINAPI LocalAddJob(HANDLE hPrinter, DWORD Level, LPBYTE pData, DWORD cbBuf, LPDWORD pcbNeeded);
250 BOOL WINAPI LocalEnumJobs(HANDLE hPrinter, DWORD FirstJob, DWORD NoJobs, DWORD Level, PBYTE pStart, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned);
251 BOOL WINAPI LocalGetJob(HANDLE hPrinter, DWORD JobId, DWORD Level, PBYTE pStart, DWORD cbBuf, LPDWORD pcbNeeded);
252 BOOL WINAPI LocalScheduleJob(HANDLE hPrinter, DWORD dwJobID);
253 BOOL WINAPI LocalSetJob(HANDLE hPrinter, DWORD JobId, DWORD Level, PBYTE pJobInfo, DWORD Command);
254 PLOCAL_JOB ReadJobShadowFile(PCWSTR pwszFilePath);
255 BOOL WriteJobShadowFile(PWSTR pwszFilePath, const PLOCAL_JOB pJob);
256
257 // main.c
258 extern const WCHAR wszCurrentEnvironment[];
259 extern const DWORD cbCurrentEnvironment;
260 extern const WCHAR wszDefaultDocumentName[];
261 extern PWSTR wszPrintProviderInfo[3];
262 extern WCHAR wszSpoolDirectory[MAX_PATH];
263 extern DWORD cchSpoolDirectory;
264
265 // monitors.c
266 extern LIST_ENTRY PrintMonitorList;
267 PLOCAL_PRINT_MONITOR FindPrintMonitor(PCWSTR pwszName);
268 BOOL InitializePrintMonitorList();
269 BOOL WINAPI LocalEnumMonitors(PWSTR pName, DWORD Level, PBYTE pMonitors, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned);
270
271 // ports.c
272 PLOCAL_PORT FindPort(PCWSTR pwszName);
273 BOOL InitializePortList();
274 BOOL WINAPI LocalEnumPorts(PWSTR pName, DWORD Level, PBYTE pPorts, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned);
275
276 // printers.c
277 extern SKIPLIST PrinterList;
278 BOOL InitializePrinterList();
279 BOOL WINAPI LocalEnumPrinters(DWORD Flags, LPWSTR Name, DWORD Level, LPBYTE pPrinterEnum, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned);
280 BOOL WINAPI LocalGetPrinter(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter, DWORD cbBuf, LPDWORD pcbNeeded);
281 BOOL WINAPI LocalOpenPrinter(PWSTR lpPrinterName, HANDLE* phPrinter, PPRINTER_DEFAULTSW pDefault);
282 BOOL WINAPI LocalReadPrinter(HANDLE hPrinter, PVOID pBuf, DWORD cbBuf, PDWORD pNoBytesRead);
283 DWORD WINAPI LocalStartDocPrinter(HANDLE hPrinter, DWORD Level, LPBYTE pDocInfo);
284 BOOL WINAPI LocalStartPagePrinter(HANDLE hPrinter);
285 BOOL WINAPI LocalWritePrinter(HANDLE hPrinter, LPVOID pBuf, DWORD cbBuf, LPDWORD pcWritten);
286 BOOL WINAPI LocalEndPagePrinter(HANDLE hPrinter);
287 BOOL WINAPI LocalEndDocPrinter(HANDLE hPrinter);
288 BOOL WINAPI LocalClosePrinter(HANDLE hPrinter);
289
290 // printingthread.c
291 DWORD WINAPI PrintingThreadProc(PLOCAL_JOB pJob);
292
293 // printprocessors.c
294 BOOL FindDatatype(const PLOCAL_PRINT_PROCESSOR pPrintProcessor, PCWSTR pwszDatatype);
295 PLOCAL_PRINT_PROCESSOR FindPrintProcessor(PCWSTR pwszName);
296 BOOL InitializePrintProcessorList();
297 BOOL WINAPI LocalEnumPrintProcessorDatatypes(LPWSTR pName, LPWSTR pPrintProcessorName, DWORD Level, LPBYTE pDatatypes, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned);
298 BOOL WINAPI LocalEnumPrintProcessors(LPWSTR pName, LPWSTR pEnvironment, DWORD Level, LPBYTE pPrintProcessorInfo, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned);
299 BOOL WINAPI LocalGetPrintProcessorDirectory(LPWSTR pName, LPWSTR pEnvironment, DWORD Level, LPBYTE pPrintProcessorInfo, DWORD cbBuf, LPDWORD pcbNeeded);
300
301 // tools.c
302 PWSTR AllocAndRegQueryWSZ(HKEY hKey, PCWSTR pwszValueName);
303 PDEVMODEW DuplicateDevMode(PDEVMODEW pInput);
304
305 #endif