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