[SPOOLSS]
[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 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 <windef.h>
19 #include <winbase.h>
20 #include <wingdi.h>
21 #include <winreg.h>
22 #include <winspool.h>
23 #include <winsplp.h>
24 #include <ndk/rtlfuncs.h>
25
26 #define SKIPLIST_LEVELS 16
27 #include <skiplist.h>
28 #include <spoolss.h>
29
30 #include <wine/debug.h>
31 WINE_DEFAULT_DEBUG_CHANNEL(localspl);
32
33 // Macros
34 #define IS_VALID_JOB_ID(ID) (ID >= 1 && ID <= 99999)
35 #define IS_VALID_PRIORITY(P) (P >= MIN_PRIORITY && P <= MAX_PRIORITY)
36
37 // Constants
38 #define MAX_PRINTER_NAME 220
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 pwszPrinterDriver;
118 PWSTR pwszDescription;
119 PWSTR pwszDefaultDatatype;
120 PDEVMODEW pDefaultDevMode;
121 PLOCAL_PRINT_PROCESSOR pPrintProcessor;
122 PLOCAL_PORT pPort;
123 SKIPLIST JobList;
124 };
125
126 /**
127 * Describes an entire print job associated to a specific printer through the Printer member.
128 * Created with every valid call to LocalStartDocPrinter.
129 */
130 struct _LOCAL_JOB
131 {
132 // This sort key must be the first element for LookupElementSkiplist to work!
133 DWORD dwJobID; /** Internal and external ID of this Job */
134
135 BOOL bAddedJob : 1; /** Whether AddJob has already been called on this Job. */
136 HANDLE hPrintProcessor; /** Handle returned by OpenPrintProcessor while the Job is printing. */
137 PLOCAL_PRINTER pPrinter; /** Associated Printer to this Job */
138 PLOCAL_PRINT_PROCESSOR pPrintProcessor; /** Associated Print Processor to this Job */
139 DWORD dwPriority; /** Priority of this Job from MIN_PRIORITY to MAX_PRIORITY, default being DEF_PRIORITY */
140 SYSTEMTIME stSubmitted; /** Time of the submission of this Job */
141 PWSTR pwszUserName; /** Optional; User that submitted the Job */
142 PWSTR pwszNotifyName; /** Optional; User that shall be notified about the status of the Job */
143 PWSTR pwszDocumentName; /** Optional; Name of the Document that is printed */
144 PWSTR pwszDatatype; /** Datatype of the Document */
145 PWSTR pwszOutputFile; /** Output File to spool the Job to */
146 PWSTR pwszPrintProcessorParameters; /** Optional; Parameters for the chosen Print Processor */
147 PWSTR pwszStatus; /** Optional; a Status Message for the Job */
148 DWORD dwTotalPages; /** Total pages of the Document */
149 DWORD dwPagesPrinted; /** Number of pages that have already been printed */
150 DWORD dwStartTime; /** Earliest time in minutes since 12:00 AM UTC when this document can be printed */
151 DWORD dwUntilTime; /** Latest time in minutes since 12:00 AM UTC when this document can be printed */
152 DWORD dwStatus; /** JOB_STATUS_* flags of the Job */
153 PWSTR pwszMachineName; /** Name of the machine that submitted the Job (prepended with two backslashes) */
154 PDEVMODEW pDevMode; /** Associated Device Mode to this Job */
155 };
156
157 /**
158 * Specific handle returned by LocalOpenPrinter for every valid call that opens a Printer or Print Job.
159 */
160 struct _LOCAL_PRINTER_HANDLE
161 {
162 BOOL bStartedDoc : 1; /** Whether StartDocPrinter has already been called. */
163 HANDLE hSPLFile; /** Handle to an opened SPL file for Printer Job handles. */
164 PLOCAL_PRINTER pPrinter; /** Printer associated with this handle. */
165 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. */
166 PWSTR pwszDatatype; /** Datatype used for newly started jobs. */
167 PDEVMODEW pDevMode; /** DevMode used for newly started jobs. */
168 };
169
170 /**
171 * Specific handle returned by LocalOpenPrinter for every valid call that opens a Port.
172 */
173 struct _LOCAL_PORT_HANDLE
174 {
175 HANDLE hPort; /** Handle returned by pfnOpenPort. */
176 PLOCAL_PORT pPort; /** Port associated with this handle. */
177 };
178
179 /**
180 * Specific handle returned by LocalOpenPrinter for every valid call that opens an XcvMonitor or XcvPort.
181 */
182 struct _LOCAL_XCV_HANDLE
183 {
184 HANDLE hXcv; /** Handle returned by pfnXcvOpenPort. */
185 PLOCAL_PRINT_MONITOR pPrintMonitor; /** Print Monitor associated with this handle. */
186 };
187
188 /**
189 * Describes a handle returned by LocalOpenPrinter.
190 * Suitable for all things that can be opened through LocalOpenPrinter.
191 */
192 struct _LOCAL_HANDLE
193 {
194 enum {
195 HandleType_Port, /** pSpecificHandle is a PLOCAL_PORT_HANDLE. */
196 HandleType_Printer, /** pSpecificHandle is a PLOCAL_PRINTER_HANDLE. */
197 HandleType_Xcv /** pSpecificHandle is a PLOCAL_XCV_HANDLE. */
198 }
199 HandleType;
200 PVOID pSpecificHandle;
201 };
202
203 /**
204 * Describes the header of a print job serialized into a shadow file (.SHD)
205 * Documented in http://www.undocprint.org/formats/winspool/shd
206 * Compatible with Windows Server 2003
207 */
208 struct _SHD_HEADER
209 {
210 DWORD dwSignature;
211 DWORD cbHeader;
212 WORD wStatus;
213 WORD wUnknown1;
214 DWORD dwJobID;
215 DWORD dwPriority;
216 DWORD offUserName;
217 DWORD offNotifyName;
218 DWORD offDocumentName;
219 DWORD offPort;
220 DWORD offPrinterName;
221 DWORD offDriverName;
222 DWORD offDevMode;
223 DWORD offPrintProcessor;
224 DWORD offDatatype;
225 DWORD offPrintProcessorParameters;
226 SYSTEMTIME stSubmitted;
227 DWORD dwStartTime;
228 DWORD dwUntilTime;
229 DWORD dwUnknown6;
230 DWORD dwTotalPages;
231 DWORD cbSecurityDescriptor;
232 DWORD offSecurityDescriptor;
233 DWORD dwUnknown3;
234 DWORD dwUnknown4;
235 DWORD dwUnknown5;
236 DWORD offMachineName;
237 DWORD dwSPLSize;
238 };
239
240 // jobs.c
241 extern SKIPLIST GlobalJobList;
242 DWORD WINAPI CreateJob(PLOCAL_PRINTER_HANDLE pPrinterHandle);
243 void FreeJob(PLOCAL_JOB pJob);
244 DWORD GetJobFilePath(PCWSTR pwszExtension, DWORD dwJobID, PWSTR pwszOutput);
245 BOOL InitializeGlobalJobList();
246 void InitializePrinterJobList(PLOCAL_PRINTER pPrinter);
247 BOOL WINAPI LocalAddJob(HANDLE hPrinter, DWORD Level, LPBYTE pData, DWORD cbBuf, LPDWORD pcbNeeded);
248 BOOL WINAPI LocalEnumJobs(HANDLE hPrinter, DWORD FirstJob, DWORD NoJobs, DWORD Level, PBYTE pStart, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned);
249 BOOL WINAPI LocalGetJob(HANDLE hPrinter, DWORD JobId, DWORD Level, PBYTE pStart, DWORD cbBuf, LPDWORD pcbNeeded);
250 BOOL WINAPI LocalScheduleJob(HANDLE hPrinter, DWORD dwJobID);
251 BOOL WINAPI LocalSetJob(HANDLE hPrinter, DWORD JobId, DWORD Level, PBYTE pJobInfo, DWORD Command);
252 PLOCAL_JOB ReadJobShadowFile(PCWSTR pwszFilePath);
253 BOOL WriteJobShadowFile(PWSTR pwszFilePath, const PLOCAL_JOB pJob);
254
255 // main.c
256 extern const WCHAR wszCurrentEnvironment[];
257 extern const DWORD cbCurrentEnvironment;
258 extern const WCHAR wszDefaultDocumentName[];
259 extern const WCHAR* wszPrintProviderInfo[3];
260 extern WCHAR wszSpoolDirectory[MAX_PATH];
261 extern DWORD cchSpoolDirectory;
262
263 // monitors.c
264 extern LIST_ENTRY PrintMonitorList;
265 PLOCAL_PRINT_MONITOR FindPrintMonitor(PCWSTR pwszName);
266 BOOL InitializePrintMonitorList();
267 BOOL WINAPI LocalEnumMonitors(PWSTR pName, DWORD Level, PBYTE pMonitors, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned);
268
269 // ports.c
270 PLOCAL_PORT FindPort(PCWSTR pwszName);
271 BOOL InitializePortList();
272 BOOL WINAPI LocalEnumPorts(PWSTR pName, DWORD Level, PBYTE pPorts, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned);
273
274 // printers.c
275 extern SKIPLIST PrinterList;
276 BOOL InitializePrinterList();
277 BOOL WINAPI LocalEnumPrinters(DWORD Flags, LPWSTR Name, DWORD Level, LPBYTE pPrinterEnum, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned);
278 BOOL WINAPI LocalOpenPrinter(PWSTR lpPrinterName, HANDLE* phPrinter, PPRINTER_DEFAULTSW pDefault);
279 BOOL WINAPI LocalReadPrinter(HANDLE hPrinter, PVOID pBuf, DWORD cbBuf, PDWORD pNoBytesRead);
280 DWORD WINAPI LocalStartDocPrinter(HANDLE hPrinter, DWORD Level, LPBYTE pDocInfo);
281 BOOL WINAPI LocalStartPagePrinter(HANDLE hPrinter);
282 BOOL WINAPI LocalWritePrinter(HANDLE hPrinter, LPVOID pBuf, DWORD cbBuf, LPDWORD pcWritten);
283 BOOL WINAPI LocalEndPagePrinter(HANDLE hPrinter);
284 BOOL WINAPI LocalEndDocPrinter(HANDLE hPrinter);
285 BOOL WINAPI LocalClosePrinter(HANDLE hPrinter);
286
287 // printingthread.c
288 DWORD WINAPI PrintingThreadProc(PLOCAL_JOB pJob);
289
290 // printprocessors.c
291 BOOL FindDatatype(const PLOCAL_PRINT_PROCESSOR pPrintProcessor, PCWSTR pwszDatatype);
292 PLOCAL_PRINT_PROCESSOR FindPrintProcessor(PCWSTR pwszName);
293 BOOL InitializePrintProcessorList();
294 BOOL WINAPI LocalEnumPrintProcessorDatatypes(LPWSTR pName, LPWSTR pPrintProcessorName, DWORD Level, LPBYTE pDatatypes, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned);
295 BOOL WINAPI LocalEnumPrintProcessors(LPWSTR pName, LPWSTR pEnvironment, DWORD Level, LPBYTE pPrintProcessorInfo, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned);
296 BOOL WINAPI LocalGetPrintProcessorDirectory(LPWSTR pName, LPWSTR pEnvironment, DWORD Level, LPBYTE pPrintProcessorInfo, DWORD cbBuf, LPDWORD pcbNeeded);
297
298 // tools.c
299 PWSTR AllocAndRegQueryWSZ(HKEY hKey, PCWSTR pwszValueName);
300 PDEVMODEW DuplicateDevMode(PDEVMODEW pInput);
301
302 #endif