[LOCALUI] Sync with Wine Staging 3.3. CORE-14434
[reactos.git] / win32ss / printing / base / winspool / jobs.c
1 /*
2 * PROJECT: ReactOS Spooler API
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Functions for managing print jobs
5 * COPYRIGHT: Copyright 2015-2018 Colin Finck (colin@reactos.org)
6 */
7
8 #include "precomp.h"
9 #include <marshalling/jobs.h>
10
11 BOOL WINAPI
12 AddJobA(HANDLE hPrinter, DWORD Level, PBYTE pData, DWORD cbBuf, PDWORD pcbNeeded)
13 {
14 TRACE("AddJobA(%p, %lu, %p, %lu, %p)\n", hPrinter, Level, pData, cbBuf, pcbNeeded);
15 UNIMPLEMENTED;
16 return FALSE;
17 }
18
19 BOOL WINAPI
20 AddJobW(HANDLE hPrinter, DWORD Level, PBYTE pData, DWORD cbBuf, PDWORD pcbNeeded)
21 {
22 DWORD dwErrorCode;
23 PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
24
25 TRACE("AddJobW(%p, %lu, %p, %lu, %p)\n", hPrinter, Level, pData, cbBuf, pcbNeeded);
26
27 if (!pHandle)
28 {
29 dwErrorCode = ERROR_INVALID_HANDLE;
30 goto Cleanup;
31 }
32
33 // Do the RPC call
34 RpcTryExcept
35 {
36 dwErrorCode = _RpcAddJob(pHandle->hPrinter, Level, pData, cbBuf, pcbNeeded);
37 }
38 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
39 {
40 dwErrorCode = RpcExceptionCode();
41 ERR("_RpcAddJob failed with exception code %lu!\n", dwErrorCode);
42 }
43 RpcEndExcept;
44
45 if (dwErrorCode == ERROR_SUCCESS)
46 {
47 // Replace relative offset addresses in the output by absolute pointers.
48 MarshallUpStructure(cbBuf, pData, AddJobInfo1Marshalling.pInfo, AddJobInfo1Marshalling.cbStructureSize, TRUE);
49 }
50
51 Cleanup:
52 SetLastError(dwErrorCode);
53 return (dwErrorCode == ERROR_SUCCESS);
54 }
55
56 BOOL WINAPI
57 EnumJobsA(HANDLE hPrinter, DWORD FirstJob, DWORD NoJobs, DWORD Level, PBYTE pJob, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
58 {
59 TRACE("EnumJobsA(%p, %lu, %lu, %lu, %p, %lu, %p, %p)\n", hPrinter, FirstJob, NoJobs, Level, pJob, cbBuf, pcbNeeded, pcReturned);
60 UNIMPLEMENTED;
61 return FALSE;
62 }
63
64 BOOL WINAPI
65 EnumJobsW(HANDLE hPrinter, DWORD FirstJob, DWORD NoJobs, DWORD Level, PBYTE pJob, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
66 {
67 DWORD dwErrorCode;
68 PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
69
70 TRACE("EnumJobsW(%p, %lu, %lu, %lu, %p, %lu, %p, %p)\n", hPrinter, FirstJob, NoJobs, Level, pJob, cbBuf, pcbNeeded, pcReturned);
71
72 if (!pHandle)
73 {
74 dwErrorCode = ERROR_INVALID_HANDLE;
75 goto Cleanup;
76 }
77
78 // Do the RPC call
79 RpcTryExcept
80 {
81 dwErrorCode = _RpcEnumJobs(pHandle->hPrinter, FirstJob, NoJobs, Level, pJob, cbBuf, pcbNeeded, pcReturned);
82 }
83 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
84 {
85 dwErrorCode = RpcExceptionCode();
86 ERR("_RpcEnumJobs failed with exception code %lu!\n", dwErrorCode);
87 }
88 RpcEndExcept;
89
90 if (dwErrorCode == ERROR_SUCCESS)
91 {
92 // Replace relative offset addresses in the output by absolute pointers for JOB_INFO_1W and JOB_INFO_2W.
93 if (Level <= 2)
94 {
95 ASSERT(Level >= 1);
96 MarshallUpStructuresArray(cbBuf, pJob, *pcReturned, pJobInfoMarshalling[Level]->pInfo, pJobInfoMarshalling[Level]->cbStructureSize, TRUE);
97 }
98 }
99
100 Cleanup:
101 SetLastError(dwErrorCode);
102 return (dwErrorCode == ERROR_SUCCESS);
103 }
104
105 BOOL WINAPI
106 GetJobA(HANDLE hPrinter, DWORD JobId, DWORD Level, PBYTE pJob, DWORD cbBuf, PDWORD pcbNeeded)
107 {
108 TRACE("GetJobA(%p, %lu, %lu, %p, %lu, %p)\n", hPrinter, JobId, Level, pJob, cbBuf, pcbNeeded);
109 UNIMPLEMENTED;
110 return FALSE;
111 }
112
113 BOOL WINAPI
114 GetJobW(HANDLE hPrinter, DWORD JobId, DWORD Level, PBYTE pJob, DWORD cbBuf, PDWORD pcbNeeded)
115 {
116 DWORD dwErrorCode;
117 PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
118
119 TRACE("GetJobW(%p, %lu, %lu, %p, %lu, %p)\n", hPrinter, JobId, Level, pJob, cbBuf, pcbNeeded);
120
121 if (!pHandle)
122 {
123 dwErrorCode = ERROR_INVALID_HANDLE;
124 goto Cleanup;
125 }
126
127 // Do the RPC call
128 RpcTryExcept
129 {
130 dwErrorCode = _RpcGetJob(pHandle->hPrinter, JobId, Level, pJob, cbBuf, pcbNeeded);
131 }
132 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
133 {
134 dwErrorCode = RpcExceptionCode();
135 ERR("_RpcGetJob failed with exception code %lu!\n", dwErrorCode);
136 }
137 RpcEndExcept;
138
139 if (dwErrorCode == ERROR_SUCCESS)
140 {
141 // Replace relative offset addresses in the output by absolute pointers.
142 ASSERT(Level >= 1 && Level <= 2);
143 MarshallUpStructure(cbBuf, pJob, pJobInfoMarshalling[Level]->pInfo, pJobInfoMarshalling[Level]->cbStructureSize, TRUE);
144 }
145
146 Cleanup:
147 SetLastError(dwErrorCode);
148 return (dwErrorCode == ERROR_SUCCESS);
149 }
150
151 BOOL WINAPI
152 ScheduleJob(HANDLE hPrinter, DWORD dwJobID)
153 {
154 DWORD dwErrorCode;
155 PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
156
157 TRACE("ScheduleJob(%p, %lu)\n", hPrinter, dwJobID);
158
159 if (!pHandle)
160 {
161 dwErrorCode = ERROR_INVALID_HANDLE;
162 goto Cleanup;
163 }
164
165 // Do the RPC call
166 RpcTryExcept
167 {
168 dwErrorCode = _RpcScheduleJob(pHandle->hPrinter, dwJobID);
169 }
170 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
171 {
172 dwErrorCode = RpcExceptionCode();
173 ERR("_RpcScheduleJob failed with exception code %lu!\n", dwErrorCode);
174 }
175 RpcEndExcept;
176
177 Cleanup:
178 SetLastError(dwErrorCode);
179 return (dwErrorCode == ERROR_SUCCESS);
180 }
181
182 BOOL WINAPI
183 SetJobA(HANDLE hPrinter, DWORD JobId, DWORD Level, PBYTE pJobInfo, DWORD Command)
184 {
185 TRACE("SetJobA(%p, %lu, %lu, %p, %lu)\n", hPrinter, JobId, Level, pJobInfo, Command);
186 UNIMPLEMENTED;
187 return FALSE;
188 }
189
190 BOOL WINAPI
191 SetJobW(HANDLE hPrinter, DWORD JobId, DWORD Level, PBYTE pJobInfo, DWORD Command)
192 {
193 DWORD dwErrorCode;
194 PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
195 WINSPOOL_JOB_CONTAINER JobContainer;
196
197 TRACE("SetJobW(%p, %lu, %lu, %p, %lu)\n", hPrinter, JobId, Level, pJobInfo, Command);
198
199 if (!pHandle)
200 {
201 dwErrorCode = ERROR_INVALID_HANDLE;
202 goto Cleanup;
203 }
204
205 // pJobContainer->JobInfo is a union of pointers, so we can just set any element to our BYTE pointer.
206 JobContainer.Level = Level;
207 JobContainer.JobInfo.Level1 = (WINSPOOL_JOB_INFO_1*)pJobInfo;
208
209 // Do the RPC call
210 RpcTryExcept
211 {
212 dwErrorCode = _RpcSetJob(pHandle->hPrinter, JobId, &JobContainer, Command);
213 }
214 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
215 {
216 dwErrorCode = RpcExceptionCode();
217 ERR("_RpcSetJob failed with exception code %lu!\n", dwErrorCode);
218 }
219 RpcEndExcept;
220
221 Cleanup:
222 SetLastError(dwErrorCode);
223 return (dwErrorCode == ERROR_SUCCESS);
224 }