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