d45edfb6684b5f595c6f339b130ac21b0530d226
[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
36 // Constants
37 #define MAX_PRINTER_NAME 220
38 #define SHD_WIN2003_SIGNATURE 0x4968
39
40 // Function pointers
41 typedef BOOL (WINAPI *PClosePrintProcessor)(HANDLE);
42 typedef BOOL (WINAPI *PControlPrintProcessor)(HANDLE, DWORD);
43 typedef BOOL (WINAPI *PEnumPrintProcessorDatatypesW)(LPWSTR, LPWSTR, DWORD, LPBYTE, DWORD, LPDWORD, LPDWORD);
44 typedef DWORD (WINAPI *PGetPrintProcessorCapabilities)(LPWSTR, DWORD, LPBYTE, DWORD, LPDWORD);
45 typedef HANDLE (WINAPI *POpenPrintProcessor)(LPWSTR, PPRINTPROCESSOROPENDATA);
46 typedef BOOL (WINAPI *PPrintDocumentOnPrintProcessor)(HANDLE, LPWSTR);
47
48 // Structures
49 /**
50 * Describes a Print Processor.
51 */
52 typedef struct _LOCAL_PRINT_PROCESSOR
53 {
54 LIST_ENTRY Entry;
55 PWSTR pwszName;
56 PDATATYPES_INFO_1W pDatatypesInfo1;
57 DWORD dwDatatypeCount;
58 PClosePrintProcessor pfnClosePrintProcessor;
59 PControlPrintProcessor pfnControlPrintProcessor;
60 PEnumPrintProcessorDatatypesW pfnEnumPrintProcessorDatatypesW;
61 PGetPrintProcessorCapabilities pfnGetPrintProcessorCapabilities;
62 POpenPrintProcessor pfnOpenPrintProcessor;
63 PPrintDocumentOnPrintProcessor pfnPrintDocumentOnPrintProcessor;
64 }
65 LOCAL_PRINT_PROCESSOR, *PLOCAL_PRINT_PROCESSOR;
66
67 /**
68 * Describes a printer and manages its print jobs.
69 * Created once for every printer at startup.
70 */
71 typedef struct _LOCAL_PRINTER
72 {
73 // This sort key must be the first element for LookupElementSkiplist to work!
74 PWSTR pwszPrinterName;
75
76 PWSTR pwszPrinterDriver;
77 PWSTR pwszDescription;
78 PWSTR pwszDefaultDatatype;
79 DEVMODEW DefaultDevMode;
80 PLOCAL_PRINT_PROCESSOR pPrintProcessor;
81 SKIPLIST JobList;
82 }
83 LOCAL_PRINTER, *PLOCAL_PRINTER;
84
85 /**
86 * Describes an entire print job associated to a specific printer through the Printer member.
87 * Created with every valid call to LocalStartDocPrinter.
88 */
89 typedef struct _LOCAL_JOB
90 {
91 // This sort key must be the first element for LookupElementSkiplist to work!
92 DWORD dwJobID; // Internal and external ID of this Job
93
94 PLOCAL_PRINTER Printer; // Associated Printer to this Job
95 DWORD dwPriority; // Priority of this Job from MIN_PRIORITY to MAX_PRIORITY, default being DEF_PRIORITY
96 SYSTEMTIME stSubmitted; // Time of the submission of this Job
97 PWSTR pwszUserName; // User that submitted the Job
98 PWSTR pwszNotifyName; // User that shall be notified about the status of the Job
99 PWSTR pwszDocumentName; // Name of the Document that is printed
100 PWSTR pwszDatatype; // Datatype of the Document
101 PWSTR pwszOutputFile; // Output File to spool the Job to
102 DWORD dwTotalPages; // Total pages of the Document
103 DWORD dwPagesPrinted; // Number of pages that have already been printed
104 DWORD dwStartTime; // Earliest time in minutes since 12:00 AM UTC when this document can be printed
105 DWORD dwUntilTime; // Latest time in minutes since 12:00 AM UTC when this document can be printed
106 DWORD dwStatus; // JOB_STATUS_* flags of the Job
107 PWSTR pwszMachineName; // Name of the machine that submitted the Job (prepended with two backslashes)
108 DEVMODEW DevMode; // Associated Device Mode to this Job
109 }
110 LOCAL_JOB, *PLOCAL_JOB;
111
112 /**
113 * Describes a template for new print jobs for a specific printer.
114 * Created with every valid call to LocalOpenPrinter.
115 *
116 * This is needed, because you can supply defaults in a LocalOpenPrinter call, which affect all subsequent print jobs
117 * started with the same handle and a call to LocalStartDocPrinter.
118 */
119 typedef struct _LOCAL_PRINTER_HANDLE
120 {
121 PLOCAL_PRINTER Printer;
122 PLOCAL_JOB StartedJob;
123 PWSTR pwszDatatype;
124 DEVMODEW DevMode;
125 }
126 LOCAL_PRINTER_HANDLE, *PLOCAL_PRINTER_HANDLE;
127
128 /**
129 * Describes a handle returned by LocalOpenPrinter.
130 * Suitable for all things that can be opened through LocalOpenPrinter.
131 */
132 typedef struct _LOCAL_HANDLE
133 {
134 enum { Printer, Monitor, Port } HandleType;
135 PVOID SpecificHandle;
136 }
137 LOCAL_HANDLE, *PLOCAL_HANDLE;
138
139 /**
140 * Describes the header of a print job serialized into a shadow file (.SHD)
141 * Documented in http://www.undocprint.org/formats/winspool/shd
142 * Compatible with Windows Server 2003
143 */
144 typedef struct _SHD_HEADER
145 {
146 DWORD dwSignature;
147 DWORD cbHeader;
148 WORD wStatus;
149 WORD wUnknown1;
150 DWORD dwJobID;
151 DWORD dwPriority;
152 DWORD offUserName;
153 DWORD offNotifyName;
154 DWORD offDocumentName;
155 DWORD offPort;
156 DWORD offPrinterName;
157 DWORD offDriverName;
158 DWORD offDevMode;
159 DWORD offPrintProcessor;
160 DWORD offDatatype;
161 DWORD dwUnknown2;
162 SYSTEMTIME stSubmitted;
163 DWORD dwStartTime;
164 DWORD dwUntilTime;
165 DWORD dwUnknown6;
166 DWORD dwTotalPages;
167 DWORD cbSecurityDescriptor;
168 DWORD offSecurityDescriptor;
169 DWORD dwUnknown3;
170 DWORD dwUnknown4;
171 DWORD dwUnknown5;
172 DWORD offMachineName;
173 DWORD dwSPLSize;
174 }
175 SHD_HEADER, *PSHD_HEADER;
176
177
178 // jobs.c
179 extern SKIPLIST GlobalJobList;
180 BOOL GetNextJobID(PDWORD dwJobID);
181 void InitializeGlobalJobList();
182 void InitializePrinterJobList(PLOCAL_PRINTER pPrinter);
183 BOOL WINAPI LocalAddJob(HANDLE hPrinter, DWORD Level, LPBYTE pData, DWORD cbBuf, LPDWORD pcbNeeded);
184 BOOL WINAPI LocalGetJob(HANDLE hPrinter, DWORD JobId, DWORD Level, LPBYTE pOutput, DWORD cbBuf, LPDWORD pcbNeeded);
185 PLOCAL_JOB ReadJobShadowFile(PCWSTR pwszFilePath);
186 BOOL WriteJobShadowFile(PCWSTR pwszFilePath, const PLOCAL_JOB pJob);
187
188 // main.c
189 extern const WCHAR wszCurrentEnvironment[];
190 extern const WCHAR wszDefaultDocumentName[];
191 extern const WCHAR* wszPrintProviderInfo[3];
192 extern WCHAR wszSpoolDirectory[MAX_PATH];
193 extern DWORD cchSpoolDirectory;
194
195 // printers.c
196 extern SKIPLIST PrinterList;
197 void InitializePrinterList();
198 BOOL WINAPI LocalEnumPrinters(DWORD Flags, LPWSTR Name, DWORD Level, LPBYTE pPrinterEnum, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned);
199 BOOL WINAPI LocalOpenPrinter(PWSTR lpPrinterName, HANDLE* phPrinter, PPRINTER_DEFAULTSW pDefault);
200 DWORD WINAPI LocalStartDocPrinter(HANDLE hPrinter, DWORD Level, LPBYTE pDocInfo);
201 BOOL WINAPI LocalStartPagePrinter(HANDLE hPrinter);
202 BOOL WINAPI LocalWritePrinter(HANDLE hPrinter, LPVOID pBuf, DWORD cbBuf, LPDWORD pcWritten);
203 BOOL WINAPI LocalEndPagePrinter(HANDLE hPrinter);
204 BOOL WINAPI LocalEndDocPrinter(HANDLE hPrinter);
205 BOOL WINAPI LocalClosePrinter(HANDLE hPrinter);
206
207 // printprocessors.c
208 BOOL FindDatatype(PLOCAL_PRINT_PROCESSOR pPrintProcessor, PWSTR pwszDatatype);
209 PLOCAL_PRINT_PROCESSOR FindPrintProcessor(PWSTR pwszName);
210 void InitializePrintProcessorList();
211 BOOL WINAPI LocalEnumPrintProcessorDatatypes(LPWSTR pName, LPWSTR pPrintProcessorName, DWORD Level, LPBYTE pDatatypes, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned);
212 BOOL WINAPI LocalEnumPrintProcessors(LPWSTR pName, LPWSTR pEnvironment, DWORD Level, LPBYTE pPrintProcessorInfo, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned);
213 BOOL WINAPI LocalGetPrintProcessorDirectory(LPWSTR pName, LPWSTR pEnvironment, DWORD Level, LPBYTE pPrintProcessorInfo, DWORD cbBuf, LPDWORD pcbNeeded);
214
215 // tools.c
216 PWSTR AllocAndRegQueryWSZ(HKEY hKey, PCWSTR pwszValueName);
217
218 #endif