[WINSPOOL]
[reactos.git] / reactos / win32ss / printing / processors / winprint / main.c
1 /*
2 * PROJECT: ReactOS Standard Print Processor
3 * LICENSE: GNU LGPL v2.1 or any later version as published by the Free Software Foundation
4 * PURPOSE: Main functions
5 * COPYRIGHT: Copyright 2015 Colin Finck <colin@reactos.org>
6 */
7
8 #include "precomp.h"
9
10 PCWSTR pwszDatatypes[] = {
11 L"RAW",
12 0
13 };
14
15 /**
16 * @name EnumPrintProcessorDatatypesW
17 *
18 * Obtains an array of all datatypes supported by this Print Processor.
19 *
20 * @param pName
21 * Server Name. Ignored here, because every caller of EnumPrintProcessorDatatypesW is interested in this Print Processor's information.
22 *
23 * @param pPrintProcessorName
24 * Print Processor Name. Ignored here, because every caller of EnumPrintProcessorDatatypesW is interested in this Print Processor's information.
25 *
26 * @param Level
27 * The level of the structure supplied through pDatatypes. This must be 1.
28 *
29 * @param pDatatypes
30 * Pointer to the buffer that receives an array of DATATYPES_INFO_1W structures.
31 * Can be NULL if you just want to know the required size of the buffer.
32 *
33 * @param cbBuf
34 * Size of the buffer you supplied for pDatatypes, in bytes.
35 *
36 * @param pcbNeeded
37 * Pointer to a variable that receives the required size of the buffer for pDatatypes, in bytes.
38 * This parameter mustn't be NULL!
39 *
40 * @param pcReturned
41 * Pointer to a variable that receives the number of elements of the DATATYPES_INFO_1W array.
42 * This parameter mustn't be NULL!
43 *
44 * @return
45 * TRUE if we successfully copied the array into pDatatypes, FALSE otherwise.
46 * A more specific error code can be obtained through GetLastError.
47 */
48 BOOL WINAPI
49 EnumPrintProcessorDatatypesW(LPWSTR pName, LPWSTR pPrintProcessorName, DWORD Level, LPBYTE pDatatypes, DWORD cbBuf, LPDWORD pcbNeeded, LPDWORD pcReturned)
50 {
51 DWORD cbDatatype;
52 DWORD dwErrorCode;
53 DWORD dwOffsets[_countof(pwszDatatypes)];
54 PCWSTR* pCurrentDatatype;
55 PDWORD pCurrentOffset = dwOffsets;
56
57 // Sanity checks
58 if (Level != 1 || !pcbNeeded || !pcReturned)
59 {
60 dwErrorCode = ERROR_INVALID_PARAMETER;
61 goto Cleanup;
62 }
63
64 // Count the required buffer size and the number of datatypes.
65 *pcbNeeded = 0;
66 *pcReturned = 0;
67
68 for (pCurrentDatatype = pwszDatatypes; *pCurrentDatatype; pCurrentDatatype++)
69 {
70 cbDatatype = (wcslen(*pCurrentDatatype) + 1) * sizeof(WCHAR);
71 *pcbNeeded += sizeof(DATATYPES_INFO_1W) + cbDatatype;
72
73 // Also calculate the offset in the output buffer of the pointer to this datatype string.
74 *pCurrentOffset = *pcReturned * sizeof(DATATYPES_INFO_1W) + FIELD_OFFSET(DATATYPES_INFO_1W, pName);
75
76 *pcReturned++;
77 pCurrentOffset++;
78 }
79
80 // Check if the supplied buffer is large enough.
81 if (cbBuf < *pcbNeeded)
82 {
83 dwErrorCode = ERROR_INSUFFICIENT_BUFFER;
84 goto Cleanup;
85 }
86
87 // Check if a buffer was supplied at all.
88 if (!pDatatypes)
89 {
90 dwErrorCode = ERROR_INVALID_PARAMETER;
91 goto Cleanup;
92 }
93
94 // Copy over all datatypes.
95 *pCurrentOffset = MAXDWORD;
96 PackStrings(pwszDatatypes, pDatatypes, dwOffsets, &pDatatypes[*pcbNeeded]);
97
98 dwErrorCode = ERROR_SUCCESS;
99
100 Cleanup:
101 SetLastError(dwErrorCode);
102 return (dwErrorCode == ERROR_SUCCESS);
103 }