ReactOS  0.4.14-dev-1338-g0d187f7
printprocessors.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 related to Print Processors
5 * COPYRIGHT: Copyright 2015-2018 Colin Finck (colin@reactos.org)
6 */
7 
8 #include "precomp.h"
10 #include <prtprocenv.h>
11 
13 AddPrintProcessorA(PSTR pName, PSTR pEnvironment, PSTR pPathName, PSTR pPrintProcessorName)
14 {
15  TRACE("AddPrintProcessorA(%s, %s, %s, %s)\n", pName, pEnvironment, pPathName, pPrintProcessorName);
17  return FALSE;
18 }
19 
21 AddPrintProcessorW(PWSTR pName, PWSTR pEnvironment, PWSTR pPathName, PWSTR pPrintProcessorName)
22 {
23  TRACE("AddPrintProcessorW(%S, %S, %S, %S)\n", pName, pEnvironment, pPathName, pPrintProcessorName);
25  return FALSE;
26 }
27 
29 DeletePrintProcessorA(PSTR pName, PSTR pEnvironment, PSTR pPrintProcessorName)
30 {
31  TRACE("DeletePrintProcessorA(%s, %s, %s)\n", pName, pEnvironment, pPrintProcessorName);
33  return FALSE;
34 }
35 
37 DeletePrintProcessorW(PWSTR pName, PWSTR pEnvironment, PWSTR pPrintProcessorName)
38 {
39  TRACE("DeletePrintProcessorW(%S, %S, %S)\n", pName, pEnvironment, pPrintProcessorName);
41  return FALSE;
42 }
43 
45 EnumPrintProcessorDatatypesA(PSTR pName, LPSTR pPrintProcessorName, DWORD Level, PBYTE pDatatypes, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
46 {
47  TRACE("EnumPrintProcessorDatatypesA(%s, %s, %lu, %p, %lu, %p, %p)\n", pName, pPrintProcessorName, Level, pDatatypes, cbBuf, pcbNeeded, pcReturned);
49  return FALSE;
50 }
51 
53 EnumPrintProcessorDatatypesW(PWSTR pName, LPWSTR pPrintProcessorName, DWORD Level, PBYTE pDatatypes, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
54 {
55  DWORD dwErrorCode;
56 
57  TRACE("EnumPrintProcessorDatatypesW(%S, %S, %lu, %p, %lu, %p, %p)\n", pName, pPrintProcessorName, Level, pDatatypes, cbBuf, pcbNeeded, pcReturned);
58 
59  // Sanity checks
60  if (Level != 1)
61  {
62  dwErrorCode = ERROR_INVALID_LEVEL;
63  goto Cleanup;
64  }
65 
66  // Do the RPC call
68  {
69  dwErrorCode = _RpcEnumPrintProcessorDatatypes(pName, pPrintProcessorName, Level, pDatatypes, cbBuf, pcbNeeded, pcReturned);
70  }
72  {
73  dwErrorCode = RpcExceptionCode();
74  ERR("_RpcEnumPrintProcessorDatatypes failed with exception code %lu!\n", dwErrorCode);
75  }
77 
78  if (dwErrorCode == ERROR_SUCCESS)
79  {
80  // Replace relative offset addresses in the output by absolute pointers.
82  }
83 
84 Cleanup:
85  SetLastError(dwErrorCode);
86  return (dwErrorCode == ERROR_SUCCESS);
87 }
88 
90 EnumPrintProcessorsA(PSTR pName, PSTR pEnvironment, DWORD Level, PBYTE pPrintProcessorInfo, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
91 {
92  TRACE("EnumPrintProcessorsA(%s, %s, %lu, %p, %lu, %p, %p)\n", pName, pEnvironment, Level, pPrintProcessorInfo, cbBuf, pcbNeeded, pcReturned);
94  return FALSE;
95 }
96 
98 EnumPrintProcessorsW(PWSTR pName, PWSTR pEnvironment, DWORD Level, PBYTE pPrintProcessorInfo, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
99 {
100  DWORD dwErrorCode;
101 
102  TRACE("EnumPrintProcessorsW(%S, %S, %lu, %p, %lu, %p, %p)\n", pName, pEnvironment, Level, pPrintProcessorInfo, cbBuf, pcbNeeded, pcReturned);
103 
104  // Choose our current environment if the caller didn't give any.
105  if (!pEnvironment)
106  pEnvironment = (PWSTR)wszCurrentEnvironment;
107 
108  // Do the RPC call
110  {
111  dwErrorCode = _RpcEnumPrintProcessors(pName, pEnvironment, Level, pPrintProcessorInfo, cbBuf, pcbNeeded, pcReturned);
112  }
114  {
115  dwErrorCode = RpcExceptionCode();
116  }
117  RpcEndExcept;
118 
119  if (dwErrorCode == ERROR_SUCCESS)
120  {
121  // Replace relative offset addresses in the output by absolute pointers.
123  }
124 
125  SetLastError(dwErrorCode);
126  return (dwErrorCode == ERROR_SUCCESS);
127 }
128 
129 BOOL WINAPI
130 GetPrintProcessorDirectoryA(PSTR pName, PSTR pEnvironment, DWORD Level, PBYTE pPrintProcessorInfo, DWORD cbBuf, PDWORD pcbNeeded)
131 {
132  BOOL bReturnValue = FALSE;
133  DWORD cch;
134  PWSTR pwszName = NULL;
135  PWSTR pwszEnvironment = NULL;
136  PWSTR pwszPrintProcessorInfo = NULL;
137 
138  TRACE("GetPrintProcessorDirectoryA(%s, %s, %lu, %p, %lu, %p)\n", pName, pEnvironment, Level, pPrintProcessorInfo, cbBuf, pcbNeeded);
139 
140  if (pName)
141  {
142  // Convert pName to a Unicode string pwszName.
143  cch = strlen(pName);
144 
145  pwszName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(WCHAR));
146  if (!pwszName)
147  {
149  ERR("HeapAlloc failed!\n");
150  goto Cleanup;
151  }
152 
153  MultiByteToWideChar(CP_ACP, 0, pName, -1, pwszName, cch + 1);
154  }
155 
156  if (pEnvironment)
157  {
158  // Convert pEnvironment to a Unicode string pwszEnvironment.
159  cch = strlen(pEnvironment);
160 
161  pwszEnvironment = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(WCHAR));
162  if (!pwszEnvironment)
163  {
165  ERR("HeapAlloc failed!\n");
166  goto Cleanup;
167  }
168 
169  MultiByteToWideChar(CP_ACP, 0, pEnvironment, -1, pwszEnvironment, cch + 1);
170  }
171 
172  if (cbBuf && pPrintProcessorInfo)
173  {
174  // Allocate a temporary buffer for the Unicode result.
175  // We can just go with cbBuf here. The user should have set it based on pcbNeeded returned in a previous call and our
176  // pcbNeeded is the same for the A and W functions.
177  pwszPrintProcessorInfo = HeapAlloc(hProcessHeap, 0, cbBuf);
178  if (!pwszPrintProcessorInfo)
179  {
181  ERR("HeapAlloc failed!\n");
182  goto Cleanup;
183  }
184  }
185 
186  bReturnValue = GetPrintProcessorDirectoryW(pwszName, pwszEnvironment, Level, (PBYTE)pwszPrintProcessorInfo, cbBuf, pcbNeeded);
187 
188  if (bReturnValue)
189  {
190  // Convert pwszPrintProcessorInfo to an ANSI string pPrintProcessorInfo.
191  WideCharToMultiByte(CP_ACP, 0, pwszPrintProcessorInfo, -1, (PSTR)pPrintProcessorInfo, cbBuf, NULL, NULL);
192  }
193 
194 Cleanup:
195  if (pwszName)
196  HeapFree(hProcessHeap, 0, pwszName);
197 
198  if (pwszEnvironment)
199  HeapFree(hProcessHeap, 0, pwszEnvironment);
200 
201  if (pwszPrintProcessorInfo)
202  HeapFree(hProcessHeap, 0, pwszPrintProcessorInfo);
203 
204  return bReturnValue;
205 }
206 
207 BOOL WINAPI
208 GetPrintProcessorDirectoryW(PWSTR pName, PWSTR pEnvironment, DWORD Level, PBYTE pPrintProcessorInfo, DWORD cbBuf, PDWORD pcbNeeded)
209 {
210  DWORD dwErrorCode;
211 
212  TRACE("GetPrintProcessorDirectoryW(%S, %S, %lu, %p, %lu, %p)\n", pName, pEnvironment, Level, pPrintProcessorInfo, cbBuf, pcbNeeded);
213 
214  // Sanity checks
215  if (Level != 1)
216  {
217  dwErrorCode = ERROR_INVALID_LEVEL;
218  goto Cleanup;
219  }
220 
221  // Choose our current environment if the caller didn't give any.
222  if (!pEnvironment)
223  pEnvironment = (PWSTR)wszCurrentEnvironment;
224 
225  // Do the RPC call
227  {
228  dwErrorCode = _RpcGetPrintProcessorDirectory(pName, pEnvironment, Level, pPrintProcessorInfo, cbBuf, pcbNeeded);
229  }
231  {
232  dwErrorCode = RpcExceptionCode();
233  }
234  RpcEndExcept;
235 
236 Cleanup:
237  SetLastError(dwErrorCode);
238  return (dwErrorCode == ERROR_SUCCESS);
239 }
BOOL WINAPI EnumPrintProcessorsA(PSTR pName, PSTR pEnvironment, DWORD Level, PBYTE pPrintProcessorInfo, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
DWORD cbStructureSize
Definition: marshalling.h:25
MARSHALLING_INFO pInfo[]
Definition: marshalling.h:26
#define RpcEndExcept
Definition: rpc.h:128
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
#define WideCharToMultiByte
Definition: compat.h:101
BOOL WINAPI DeletePrintProcessorW(PWSTR pName, PWSTR pEnvironment, PWSTR pPrintProcessorName)
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
uint16_t * PWSTR
Definition: typedefs.h:55
#define CP_ACP
Definition: compat.h:99
BOOL WINAPI DeletePrintProcessorA(PSTR pName, PSTR pEnvironment, PSTR pPrintProcessorName)
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
char * LPSTR
Definition: xmlstorage.h:182
static const MARSHALLING DatatypesInfo1Marshalling
unsigned int BOOL
Definition: ntddk_ex.h:94
const WCHAR wszCurrentEnvironment[]
Definition: prtprocenv.h:11
BOOL WINAPI GetPrintProcessorDirectoryA(PSTR pName, PSTR pEnvironment, DWORD Level, PBYTE pPrintProcessorInfo, DWORD cbBuf, PDWORD pcbNeeded)
#define RpcTryExcept
Definition: rpc.h:126
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
static DWORD DWORD void LPSTR DWORD cch
Definition: str.c:201
smooth NULL
Definition: ftsmooth.c:416
DWORD _RpcEnumPrintProcessorDatatypes(WINSPOOL_HANDLE pName, WCHAR *pPrintProcessorName, DWORD Level, BYTE *pDatatypes, DWORD cbBuf, DWORD *pcbNeeded, DWORD *pcReturned)
#define RpcExceptionCode()
Definition: rpc.h:132
#define TRACE(s)
Definition: solgame.cpp:4
static LPSTR pName
Definition: security.c:75
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define WINAPI
Definition: msvc.h:6
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI GetPrintProcessorDirectoryW(PWSTR pName, PWSTR pEnvironment, DWORD Level, PBYTE pPrintProcessorInfo, DWORD cbBuf, PDWORD pcbNeeded)
#define SetLastError(x)
Definition: compat.h:417
BOOL WINAPI AddPrintProcessorW(PWSTR pName, PWSTR pEnvironment, PWSTR pPathName, PWSTR pPrintProcessorName)
static const WCHAR Cleanup[]
Definition: register.c:80
DWORD _RpcEnumPrintProcessors(WINSPOOL_HANDLE pName, WCHAR *pEnvironment, DWORD Level, BYTE *pPrintProcessorInfo, DWORD cbBuf, DWORD *pcbNeeded, DWORD *pcReturned)
static const MARSHALLING PrintProcessorInfo1Marshalling
#define ERR(fmt,...)
Definition: debug.h:109
_In_ DWORD _Out_ PDWORD pcbNeeded
Definition: winddi.h:3827
signed char * PSTR
Definition: retypes.h:7
DWORD * PDWORD
Definition: pedump.c:68
#define MultiByteToWideChar
Definition: compat.h:100
BOOL WINAPI EnumPrintProcessorDatatypesW(PWSTR pName, PWSTR pPrintProcessorName, DWORD Level, PBYTE pDatatypes, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
BOOL WINAPI AddPrintProcessorA(PSTR pName, PSTR pEnvironment, PSTR pPathName, PSTR pPrintProcessorName)
#define UNIMPLEMENTED
Definition: debug.h:114
DWORD _RpcGetPrintProcessorDirectory(WINSPOOL_HANDLE pName, WCHAR *pEnvironment, DWORD Level, BYTE *pPrintProcessorDirectory, DWORD cbBuf, DWORD *pcbNeeded)
#define ERROR_INVALID_LEVEL
Definition: winerror.h:196
BOOL WINAPI EnumPrintProcessorDatatypesA(PSTR pName, LPSTR pPrintProcessorName, DWORD Level, PBYTE pDatatypes, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
WCHAR * LPWSTR
Definition: xmlstorage.h:184
BYTE * PBYTE
Definition: pedump.c:66
#define HeapFree(x, y, z)
Definition: compat.h:402
BOOL WINAPI EnumPrintProcessorsW(PWSTR pName, PWSTR pEnvironment, DWORD Level, PBYTE pPrintProcessorInfo, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
#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 hProcessHeap
Definition: kbswitch.c:25