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