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