[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 DEVMODEW DefaultDevMode;
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 DEVMODEW DevMode; // 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 DEVMODEW DevMode;
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 { Printer, Monitor, Port } HandleType;
143 PVOID pSpecificHandle;
144 }
145 LOCAL_HANDLE, *PLOCAL_HANDLE;
146
147 /**
148 * Describes a Print Monitor.
149 */
150 typedef struct _LOCAL_PRINT_MONITOR
151 {
152 LIST_ENTRY Entry;
153 PWSTR pwszName; /** Name of the Print Monitor as read from the registry. */
154 PWSTR pwszFileName; /** DLL File Name of the Print Monitor. */
155 BOOL bIsLevel2; /** Whether this Print Monitor supplies an InitializePrintMonitor2 API (preferred) instead of InitializePrintMonitor. */
156 PVOID pMonitor; /** For bIsLevel2 == TRUE: LPMONITOR2 pointer returned by InitializePrintMonitor2.
157 For bIsLevel2 == FALSE: LPMONITOREX pointer returned by InitializePrintMonitor. */
158 HANDLE hMonitor; /** Only used when bIsLevel2 == TRUE: Handle returned by InitializePrintMonitor2. */
159 }
160 LOCAL_PRINT_MONITOR, *PLOCAL_PRINT_MONITOR;
161
162 /**
163 * Describes the header of a print job serialized into a shadow file (.SHD)
164 * Documented in http://www.undocprint.org/formats/winspool/shd
165 * Compatible with Windows Server 2003
166 */
167 typedef struct _SHD_HEADER
168 {
169 DWORD dwSignature;
170 DWORD cbHeader;
171 WORD wStatus;
172 WORD wUnknown1;
173 DWORD dwJobID;
174 DWORD dwPriority;
175 DWORD offUserName;
176 DWORD offNotifyName;
177 DWORD offDocumentName;
178 DWORD offPort;
179 DWORD offPrinterName;
180 DWORD offDriverName;
181 DWORD offDevMode;
182 DWORD offPrintProcessor;
183 DWORD offDatatype;
184 DWORD offPrintProcessorParameters;
185 SYSTEMTIME stSubmitted;
186 DWORD dwStartTime;
187 DWORD dwUntilTime;
188 DWORD dwUnknown6;
189 DWORD dwTotalPages;
190 DWORD cbSecurityDescriptor;
191 DWORD offSecurityDescriptor;
192 DWORD dwUnknown3;
193 DWORD dwUnknown4;
194 DWORD dwUnknown5;
195 DWORD offMachineName;
196 DWORD dwSPLSize;
197 }
198 SHD_HEADER, *PSHD_HEADER;
199
200
201 // jobs.c
202 extern SKIPLIST GlobalJobList;
203 BOOL GetNextJobID(PDWORD dwJobID);
204 BOOL InitializeGlobalJobList();
205 void InitializePrinterJobList(PLOCAL_PRINTER pPrinter);
206 BOOL WINAPI LocalAddJob(HANDLE hPrinter, DWORD Level, LPBYTE pData, DWORD cbBuf, LPDWORD pcbNeeded);
207 BOOL WINAPI LocalEnumJobs(HANDLE hPrinter, DWORD FirstJob, DWORD NoJobs, DWORD Level, PBYTE pStart, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned);
208 BOOL WINAPI LocalGetJob(HANDLE hPrinter, DWORD JobId, DWORD Level, PBYTE pStart, DWORD cbBuf, LPDWORD pcbNeeded);
209 BOOL WINAPI LocalScheduleJob(HANDLE hPrinter, DWORD dwJobID);
210 BOOL WINAPI LocalSetJob(HANDLE hPrinter, DWORD JobId, DWORD Level, PBYTE pJobInfo, DWORD Command);
211 PLOCAL_JOB ReadJobShadowFile(PCWSTR pwszFilePath);
212 BOOL WriteJobShadowFile(PWSTR pwszFilePath, const PLOCAL_JOB pJob);
213
214 // main.c
215 extern const WCHAR wszCurrentEnvironment[];
216 extern const DWORD cbCurrentEnvironment;
217 extern const WCHAR wszDefaultDocumentName[];
218 extern const WCHAR* wszPrintProviderInfo[3];
219 extern WCHAR wszSpoolDirectory[MAX_PATH];
220 extern DWORD cchSpoolDirectory;
221
222 // monitors.c
223 extern LIST_ENTRY PrintMonitorList;
224 BOOL InitializePrintMonitorList();
225 BOOL WINAPI LocalEnumMonitors(PWSTR pName, DWORD Level, PBYTE pMonitors, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned);
226
227 // ports.c
228 BOOL WINAPI LocalEnumPorts(PWSTR pName, DWORD Level, PBYTE pPorts, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned);
229
230 // printers.c
231 extern SKIPLIST PrinterList;
232 BOOL InitializePrinterList();
233 BOOL WINAPI LocalEnumPrinters(DWORD Flags, LPWSTR Name, DWORD Level, LPBYTE pPrinterEnum, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned);
234 BOOL WINAPI LocalOpenPrinter(PWSTR lpPrinterName, HANDLE* phPrinter, PPRINTER_DEFAULTSW pDefault);
235 DWORD WINAPI LocalStartDocPrinter(HANDLE hPrinter, DWORD Level, LPBYTE pDocInfo);
236 BOOL WINAPI LocalStartPagePrinter(HANDLE hPrinter);
237 BOOL WINAPI LocalWritePrinter(HANDLE hPrinter, LPVOID pBuf, DWORD cbBuf, LPDWORD pcWritten);
238 BOOL WINAPI LocalEndPagePrinter(HANDLE hPrinter);
239 BOOL WINAPI LocalEndDocPrinter(HANDLE hPrinter);
240 BOOL WINAPI LocalClosePrinter(HANDLE hPrinter);
241
242 // printprocessors.c
243 BOOL FindDatatype(PLOCAL_PRINT_PROCESSOR pPrintProcessor, PWSTR pwszDatatype);
244 PLOCAL_PRINT_PROCESSOR FindPrintProcessor(PWSTR pwszName);
245 BOOL InitializePrintProcessorList();
246 BOOL WINAPI LocalEnumPrintProcessorDatatypes(LPWSTR pName, LPWSTR pPrintProcessorName, DWORD Level, LPBYTE pDatatypes, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned);
247 BOOL WINAPI LocalEnumPrintProcessors(LPWSTR pName, LPWSTR pEnvironment, DWORD Level, LPBYTE pPrintProcessorInfo, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned);
248 BOOL WINAPI LocalGetPrintProcessorDirectory(LPWSTR pName, LPWSTR pEnvironment, DWORD Level, LPBYTE pPrintProcessorInfo, DWORD cbBuf, LPDWORD pcbNeeded);
249
250 // tools.c
251 PWSTR AllocAndRegQueryWSZ(HKEY hKey, PCWSTR pwszValueName);
252
253 #endif