ReactOS  0.4.14-dev-854-gb9426a3
jobs.c
Go to the documentation of this file.
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 
13 {
14  TRACE("AddJobA(%p, %lu, %p, %lu, %p)\n", hPrinter, Level, pData, cbBuf, pcbNeeded);
16  return FALSE;
17 }
18 
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
35  {
36  dwErrorCode = _RpcAddJob(pHandle->hPrinter, Level, pData, cbBuf, pcbNeeded);
37  }
39  {
40  dwErrorCode = RpcExceptionCode();
41  ERR("_RpcAddJob failed with exception code %lu!\n", dwErrorCode);
42  }
44 
45  if (dwErrorCode == ERROR_SUCCESS)
46  {
47  // Replace relative offset addresses in the output by absolute pointers.
49  }
50 
51 Cleanup:
52  SetLastError(dwErrorCode);
53  return (dwErrorCode == ERROR_SUCCESS);
54 }
55 
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);
61  return FALSE;
62 }
63 
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
80  {
81  dwErrorCode = _RpcEnumJobs(pHandle->hPrinter, FirstJob, NoJobs, Level, pJob, cbBuf, pcbNeeded, pcReturned);
82  }
84  {
85  dwErrorCode = RpcExceptionCode();
86  ERR("_RpcEnumJobs failed with exception code %lu!\n", dwErrorCode);
87  }
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);
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
129  {
130  dwErrorCode = _RpcGetJob(pHandle->hPrinter, JobId, Level, pJob, cbBuf, pcbNeeded);
131  }
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
167  {
168  dwErrorCode = _RpcScheduleJob(pHandle->hPrinter, dwJobID);
169  }
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);
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
211  {
212  dwErrorCode = _RpcSetJob(pHandle->hPrinter, JobId, &JobContainer, Command);
213  }
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 }
DWORD cbStructureSize
Definition: marshalling.h:25
MARSHALLING_INFO pInfo[]
Definition: marshalling.h:26
BOOL WINAPI EnumJobsW(HANDLE hPrinter, DWORD FirstJob, DWORD NoJobs, DWORD Level, PBYTE pJob, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
Definition: jobs.c:26
#define RpcEndExcept
Definition: rpc.h:128
#define TRUE
Definition: types.h:120
static const MARSHALLING AddJobInfo1Marshalling
Definition: jobs.h:8
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
BOOL WINAPI SetJobW(HANDLE hPrinter, DWORD JobId, DWORD Level, PBYTE pJobInfo, DWORD Command)
Definition: jobs.c:71
BOOL WINAPI GetJobA(HANDLE hPrinter, DWORD JobId, DWORD Level, PBYTE pJob, DWORD cbBuf, PDWORD pcbNeeded)
Definition: jobs.c:106
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
Definition: shell.h:41
unsigned int BOOL
Definition: ntddk_ex.h:94
static const MARSHALLING * pJobInfoMarshalling[]
Definition: jobs.h:67
#define RpcTryExcept
Definition: rpc.h:126
DWORD _RpcSetJob(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD JobId, WINSPOOL_JOB_CONTAINER *pJobContainer, DWORD Command)
Definition: jobs.c:129
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
DWORD _RpcGetJob(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD JobId, DWORD Level, BYTE *pJob, DWORD cbBuf, DWORD *pcbNeeded)
Definition: jobs.c:78
BOOL WINAPI AddJobW(HANDLE hPrinter, DWORD Level, PBYTE pData, DWORD cbBuf, PDWORD pcbNeeded)
Definition: jobs.c:11
WINSPOOL_JOB_INFO_1 * Level1
Definition: winspool.idl:635
#define RpcExceptionCode()
Definition: rpc.h:132
#define TRACE(s)
Definition: solgame.cpp:4
DWORD _RpcScheduleJob(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD JobId)
Definition: jobs.c:110
BOOL WINAPI EnumJobsA(HANDLE hPrinter, DWORD FirstJob, DWORD NoJobs, DWORD Level, PBYTE pJob, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
Definition: jobs.c:57
#define WINAPI
Definition: msvc.h:6
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:417
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
union _WINSPOOL_JOB_CONTAINER::@3303 JobInfo
DWORD _RpcEnumJobs(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD FirstJob, DWORD NoJobs, DWORD Level, BYTE *pJob, DWORD cbBuf, DWORD *pcbNeeded, DWORD *pcReturned)
Definition: jobs.c:43
static const WCHAR Cleanup[]
Definition: register.c:80
BOOL WINAPI AddJobA(HANDLE hPrinter, DWORD Level, PBYTE pData, DWORD cbBuf, PDWORD pcbNeeded)
Definition: jobs.c:12
BOOL WINAPI MarshallUpStructure(DWORD cbSize, PVOID pStructure, const MARSHALLING_INFO *pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
Definition: marshalling.c:137
BOOL WINAPI SetJobA(HANDLE hPrinter, DWORD JobId, DWORD Level, PBYTE pJobInfo, DWORD Command)
Definition: jobs.c:183
#define ERR(fmt,...)
Definition: debug.h:109
_In_ DWORD _Out_ PDWORD pcbNeeded
Definition: winddi.h:3827
BOOL WINAPI GetJobW(HANDLE hPrinter, DWORD JobId, DWORD Level, PBYTE pJob, DWORD cbBuf, PDWORD pcbNeeded)
Definition: jobs.c:41
DWORD * PDWORD
Definition: pedump.c:68
#define UNIMPLEMENTED
Definition: debug.h:114
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827
BYTE * PBYTE
Definition: pedump.c:66
struct _SPOOLER_HANDLE * PSPOOLER_HANDLE
BOOL WINAPI ScheduleJob(HANDLE hPrinter, DWORD dwJobID)
Definition: jobs.c:56
#define RpcExcept(expr)
Definition: rpc.h:127
BOOL WINAPI MarshallUpStructuresArray(DWORD cbSize, PVOID pStructuresArray, DWORD cElements, const MARSHALLING_INFO *pInfo, DWORD cbStructureSize, BOOL bSomeBoolean)
Definition: marshalling.c:202
HANDLE hPrinter
Definition: precomp.h:34
DWORD _RpcAddJob(WINSPOOL_PRINTER_HANDLE hPrinter, DWORD Level, BYTE *pAddJob, DWORD cbBuf, DWORD *pcbNeeded)
Definition: jobs.c:12