ReactOS  0.4.14-dev-1276-g8aa58c1
main.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Standard Print Processor
3  * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE: Main functions
5  * COPYRIGHT: Copyright 2015-2017 Colin Finck (colin@reactos.org)
6  */
7 
8 #include "precomp.h"
9 
10 // Local Constants
11 static PCWSTR _pwszDatatypes[] = {
12  L"RAW",
13  0
14 };
15 
16 
30 ClosePrintProcessor(HANDLE hPrintProcessor)
31 {
32  DWORD dwErrorCode;
33  PWINPRINT_HANDLE pHandle;
34 
35  TRACE("ClosePrintProcessor(%p)\n", hPrintProcessor);
36 
37  // Sanity checks
38  if (!hPrintProcessor)
39  {
40  dwErrorCode = ERROR_INVALID_HANDLE;
41  goto Cleanup;
42  }
43 
44  pHandle = (PWINPRINT_HANDLE)hPrintProcessor;
45 
46  // Free all structure fields for which memory has been allocated.
47  if (pHandle->pwszDatatype)
48  DllFreeSplStr(pHandle->pwszDatatype);
49 
50  if (pHandle->pwszDocumentName)
52 
53  if (pHandle->pwszOutputFile)
54  DllFreeSplStr(pHandle->pwszOutputFile);
55 
56  if (pHandle->pwszPrinterPort)
58 
59  // Finally free the WINSPOOL_HANDLE structure itself.
60  DllFreeSplMem(pHandle);
61  dwErrorCode = ERROR_SUCCESS;
62 
63 Cleanup:
64  SetLastError(dwErrorCode);
65  return (dwErrorCode == ERROR_SUCCESS);
66 }
67 
70 {
71  TRACE("ControlPrintProcessor(%p, %lu)\n", hPrintProcessor, Command);
72 
74  return FALSE;
75 }
76 
110 BOOL WINAPI
111 EnumPrintProcessorDatatypesW(PWSTR pName, PWSTR pPrintProcessorName, DWORD Level, PBYTE pDatatypes, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
112 {
113  DWORD cbDatatype;
114  DWORD dwDatatypeCount = 0;
115  DWORD dwOffsets[_countof(_pwszDatatypes)];
116  PCWSTR* pCurrentDatatype;
117  PDWORD pCurrentOffset = dwOffsets;
118 
119  TRACE("EnumPrintProcessorDatatypesW(%S, %S, %lu, %p, %lu, %p, %p)\n", pName, pPrintProcessorName, Level, pDatatypes, cbBuf, pcbNeeded, pcReturned);
120 
121  // Sanity checks
122  if (Level != 1 || !pcbNeeded || !pcReturned)
123  return FALSE;
124 
125  // Count the required buffer size and the number of datatypes.
126  *pcbNeeded = 0;
127  *pcReturned = 0;
128 
129  for (pCurrentDatatype = _pwszDatatypes; *pCurrentDatatype; pCurrentDatatype++)
130  {
131  cbDatatype = (wcslen(*pCurrentDatatype) + 1) * sizeof(WCHAR);
132  *pcbNeeded += sizeof(DATATYPES_INFO_1W) + cbDatatype;
133 
134  // Also calculate the offset in the output buffer of the pointer to this datatype string.
135  *pCurrentOffset = dwDatatypeCount * sizeof(DATATYPES_INFO_1W) + FIELD_OFFSET(DATATYPES_INFO_1W, pName);
136 
137  dwDatatypeCount++;
138  pCurrentOffset++;
139  }
140 
141  // Check if the supplied buffer is large enough.
142  if (cbBuf < *pcbNeeded)
143  {
145  return FALSE;
146  }
147 
148  // Check if a buffer was supplied at all.
149  if (!pDatatypes)
150  {
152  return FALSE;
153  }
154 
155  // Copy over all datatypes.
156  *pCurrentOffset = MAXDWORD;
157  PackStrings(_pwszDatatypes, pDatatypes, dwOffsets, &pDatatypes[*pcbNeeded]);
158 
159  *pcReturned = dwDatatypeCount;
160  return TRUE;
161 }
162 
163 
166 {
167  TRACE("GetPrintProcessorCapabilities(%S, %lu, %p, %lu, %p)\n", pValueName, dwAttributes, pData, nSize, pcbNeeded);
168 
170  return 0;
171 }
172 
189 OpenPrintProcessor(PWSTR pPrinterName, PPRINTPROCESSOROPENDATA pPrintProcessorOpenData)
190 {
191  DWORD dwErrorCode;
192  HANDLE hReturnValue = NULL;
193  PWINPRINT_HANDLE pHandle = NULL;
194 
195  TRACE("OpenPrintProcessor(%S, %p)\n", pPrinterName, pPrintProcessorOpenData);
196 
197  // Sanity checks
198  // This time a datatype needs to be given. We can't fall back to a default here.
199  if (!pPrintProcessorOpenData || !pPrintProcessorOpenData->pDatatype || !*pPrintProcessorOpenData->pDatatype)
200  {
201  dwErrorCode = ERROR_INVALID_PARAMETER;
202  goto Cleanup;
203  }
204 
205  // Create a new WINPRINT_HANDLE structure and fill the relevant fields.
206  pHandle = DllAllocSplMem(sizeof(WINPRINT_HANDLE));
207 
208  // Check what datatype was given.
209  if (wcsicmp(pPrintProcessorOpenData->pDatatype, L"RAW") == 0)
210  {
211  pHandle->Datatype = RAW;
212  }
213  else
214  {
215  dwErrorCode = ERROR_INVALID_DATATYPE;
216  goto Cleanup;
217  }
218 
219  // Fill the relevant fields.
220  pHandle->dwJobID = pPrintProcessorOpenData->JobId;
221  pHandle->pwszDatatype = AllocSplStr(pPrintProcessorOpenData->pDatatype);
222  pHandle->pwszDocumentName = AllocSplStr(pPrintProcessorOpenData->pDocumentName);
223  pHandle->pwszOutputFile = AllocSplStr(pPrintProcessorOpenData->pOutputFile);
224  pHandle->pwszPrinterPort = AllocSplStr(pPrinterName);
225 
226  // We were successful! Return the handle and don't let the cleanup routine free it.
227  dwErrorCode = ERROR_SUCCESS;
228  hReturnValue = pHandle;
229  pHandle = NULL;
230 
231 Cleanup:
232  if (pHandle)
233  DllFreeSplMem(pHandle);
234 
235  SetLastError(dwErrorCode);
236  return hReturnValue;
237 }
238 
254 BOOL WINAPI
255 PrintDocumentOnPrintProcessor(HANDLE hPrintProcessor, PWSTR pDocumentName)
256 {
257  DWORD dwErrorCode;
258  PWINPRINT_HANDLE pHandle;
259 
260  TRACE("PrintDocumentOnPrintProcessor(%p, %S)\n", hPrintProcessor, pDocumentName);
261 
262  // Sanity checks
263  if (!hPrintProcessor)
264  {
265  dwErrorCode = ERROR_INVALID_HANDLE;
266  goto Cleanup;
267  }
268 
269  pHandle = (PWINPRINT_HANDLE)hPrintProcessor;
270 
271  // Call the corresponding Print function for the datatype.
272  if (pHandle->Datatype == RAW)
273  dwErrorCode = PrintRawJob(pHandle, pDocumentName);
274 
275 Cleanup:
276  SetLastError(dwErrorCode);
277  return (dwErrorCode == ERROR_SUCCESS);
278 }
#define ERROR_INVALID_DATATYPE
Definition: winerror.h:1111
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
enum _WINPRINT_HANDLE::@4171 Datatype
const uint16_t * PCWSTR
Definition: typedefs.h:56
BOOL WINAPI ControlPrintProcessor(HANDLE hPrintProcessor, DWORD Command)
Definition: main.c:69
PWSTR WINAPI AllocSplStr(PCWSTR pwszInput)
Definition: memory.c:56
#define TRUE
Definition: types.h:120
BOOL WINAPI EnumPrintProcessorDatatypesW(PWSTR pName, PWSTR pPrintProcessorName, DWORD Level, PBYTE pDatatypes, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
Definition: main.c:111
#define ERROR_SUCCESS
Definition: deptool.c:10
uint16_t * PWSTR
Definition: typedefs.h:55
BOOL WINAPI PrintDocumentOnPrintProcessor(HANDLE hPrintProcessor, PWSTR pDocumentName)
Definition: main.c:255
DWORD dwJobID
Definition: precomp.h:29
BOOL WINAPI DllFreeSplMem(PVOID pMem)
Definition: memory.c:112
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
*nSize LPSTR _Inout_ LPDWORD nSize
Definition: winbase.h:2037
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
Definition: shell.h:41
DWORD dwAttributes
Definition: vdmdbg.h:34
DWORD WINAPI GetPrintProcessorCapabilities(PWSTR pValueName, DWORD dwAttributes, PBYTE pData, DWORD nSize, PDWORD pcbNeeded)
Definition: main.c:165
unsigned int BOOL
Definition: ntddk_ex.h:94
struct _WINPRINT_HANDLE * PWINPRINT_HANDLE
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI ClosePrintProcessor(HANDLE hPrintProcessor)
Definition: main.c:30
#define MAXDWORD
static PCWSTR _pwszDatatypes[]
Definition: main.c:11
#define TRACE(s)
Definition: solgame.cpp:4
static LPSTR pName
Definition: security.c:75
__wchar_t WCHAR
Definition: xmlstorage.h:180
PWSTR pwszOutputFile
Definition: precomp.h:32
PBYTE WINAPI PackStrings(PCWSTR *pSource, PBYTE pDest, const DWORD *DestOffsets, PBYTE pEnd)
Definition: tools.c:39
#define _countof(array)
Definition: sndvol32.h:68
#define WINAPI
Definition: msvc.h:6
PWSTR pwszDocumentName
Definition: precomp.h:31
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:417
struct _DATATYPES_INFO_1W DATATYPES_INFO_1W
static const WCHAR L[]
Definition: oid.c:1250
static const WCHAR Cleanup[]
Definition: register.c:80
#define wcsicmp
Definition: string.h:1152
DWORD PrintRawJob(PWINPRINT_HANDLE pHandle, PWSTR pwszPrinterAndJob)
Definition: raw.c:23
_In_ DWORD _Out_ PDWORD pcbNeeded
Definition: winddi.h:3827
PWSTR pwszPrinterPort
Definition: precomp.h:33
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
DWORD * PDWORD
Definition: pedump.c:68
HANDLE WINAPI OpenPrintProcessor(PWSTR pPrinterName, PPRINTPROCESSOROPENDATA pPrintProcessorOpenData)
Definition: main.c:189
BOOL WINAPI DllFreeSplStr(PWSTR pwszString)
Definition: memory.c:129
#define UNIMPLEMENTED
Definition: debug.h:114
PVOID WINAPI DllAllocSplMem(DWORD dwBytes)
Definition: memory.c:95
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827
PWSTR pwszDatatype
Definition: precomp.h:30
BYTE * PBYTE
Definition: pedump.c:66
#define RAW(x)
Definition: genincdata.c:42
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10