2015-06-22 14:31:47 +00:00
|
|
|
/*
|
2017-12-09 12:35:42 +00:00
|
|
|
* PROJECT: ReactOS Spooler API
|
|
|
|
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
|
|
|
|
* PURPOSE: Functions related to Print Processors
|
2018-01-17 11:52:12 +00:00
|
|
|
* COPYRIGHT: Copyright 2015-2018 Colin Finck (colin@reactos.org)
|
2017-12-09 12:35:42 +00:00
|
|
|
*/
|
2015-06-22 14:31:47 +00:00
|
|
|
|
|
|
|
#include "precomp.h"
|
2018-01-17 11:52:12 +00:00
|
|
|
#include <marshalling/printprocessors.h>
|
2016-11-24 19:24:27 +00:00
|
|
|
#include <prtprocenv.h>
|
2015-06-22 14:31:47 +00:00
|
|
|
|
2017-12-09 12:35:42 +00:00
|
|
|
BOOL WINAPI
|
|
|
|
AddPrintProcessorA(PSTR pName, PSTR pEnvironment, PSTR pPathName, PSTR pPrintProcessorName)
|
|
|
|
{
|
2020-08-04 02:07:58 +00:00
|
|
|
UNICODE_STRING NameW, EnvW, PathW, ProcessorW;
|
|
|
|
BOOL Ret;
|
|
|
|
|
2017-12-09 12:35:42 +00:00
|
|
|
TRACE("AddPrintProcessorA(%s, %s, %s, %s)\n", pName, pEnvironment, pPathName, pPrintProcessorName);
|
2020-08-04 02:07:58 +00:00
|
|
|
|
|
|
|
AsciiToUnicode(&NameW, pName);
|
|
|
|
AsciiToUnicode(&EnvW, pEnvironment);
|
|
|
|
AsciiToUnicode(&PathW, pPathName);
|
|
|
|
AsciiToUnicode(&ProcessorW, pPrintProcessorName);
|
|
|
|
|
|
|
|
Ret = AddPrintProcessorW(NameW.Buffer, EnvW.Buffer, PathW.Buffer, ProcessorW.Buffer);
|
|
|
|
|
|
|
|
RtlFreeUnicodeString(&ProcessorW);
|
|
|
|
RtlFreeUnicodeString(&PathW);
|
|
|
|
RtlFreeUnicodeString(&EnvW);
|
|
|
|
RtlFreeUnicodeString(&NameW);
|
|
|
|
|
|
|
|
return Ret;
|
2017-12-09 12:35:42 +00:00
|
|
|
}
|
|
|
|
|
2015-07-22 17:59:46 +00:00
|
|
|
BOOL WINAPI
|
|
|
|
AddPrintProcessorW(PWSTR pName, PWSTR pEnvironment, PWSTR pPathName, PWSTR pPrintProcessorName)
|
|
|
|
{
|
2020-08-04 02:07:58 +00:00
|
|
|
DWORD dwErrorCode;
|
|
|
|
|
2017-12-09 11:00:09 +00:00
|
|
|
TRACE("AddPrintProcessorW(%S, %S, %S, %S)\n", pName, pEnvironment, pPathName, pPrintProcessorName);
|
2020-08-04 02:07:58 +00:00
|
|
|
|
|
|
|
RpcTryExcept
|
|
|
|
{
|
|
|
|
dwErrorCode = _RpcAddPrintProcessor( pName, pEnvironment, pPathName, pPrintProcessorName );
|
|
|
|
}
|
|
|
|
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
dwErrorCode = RpcExceptionCode();
|
|
|
|
ERR("_RpcPrintProcessor failed with exception code %lu!\n", dwErrorCode);
|
|
|
|
}
|
|
|
|
RpcEndExcept;
|
|
|
|
|
|
|
|
SetLastError(dwErrorCode);
|
|
|
|
return (dwErrorCode == ERROR_SUCCESS);
|
2015-07-22 17:59:46 +00:00
|
|
|
}
|
|
|
|
|
2017-12-09 12:35:42 +00:00
|
|
|
BOOL WINAPI
|
|
|
|
DeletePrintProcessorA(PSTR pName, PSTR pEnvironment, PSTR pPrintProcessorName)
|
|
|
|
{
|
2020-08-04 02:07:58 +00:00
|
|
|
UNICODE_STRING NameW, EnvW, ProcessorW;
|
|
|
|
BOOL Ret;
|
|
|
|
|
2017-12-09 12:35:42 +00:00
|
|
|
TRACE("DeletePrintProcessorA(%s, %s, %s)\n", pName, pEnvironment, pPrintProcessorName);
|
2020-08-04 02:07:58 +00:00
|
|
|
|
|
|
|
AsciiToUnicode(&NameW, pName);
|
|
|
|
AsciiToUnicode(&EnvW, pEnvironment);
|
|
|
|
AsciiToUnicode(&ProcessorW, pPrintProcessorName);
|
|
|
|
|
|
|
|
Ret = DeletePrintProcessorW(NameW.Buffer, EnvW.Buffer, ProcessorW.Buffer);
|
|
|
|
|
|
|
|
RtlFreeUnicodeString(&ProcessorW);
|
|
|
|
RtlFreeUnicodeString(&EnvW);
|
|
|
|
RtlFreeUnicodeString(&NameW);
|
|
|
|
|
|
|
|
return Ret;
|
2017-12-09 12:35:42 +00:00
|
|
|
}
|
|
|
|
|
2015-07-22 17:59:46 +00:00
|
|
|
BOOL WINAPI
|
|
|
|
DeletePrintProcessorW(PWSTR pName, PWSTR pEnvironment, PWSTR pPrintProcessorName)
|
|
|
|
{
|
2020-08-04 02:07:58 +00:00
|
|
|
DWORD dwErrorCode;
|
|
|
|
|
2017-12-09 11:00:09 +00:00
|
|
|
TRACE("DeletePrintProcessorW(%S, %S, %S)\n", pName, pEnvironment, pPrintProcessorName);
|
2020-08-04 02:07:58 +00:00
|
|
|
|
|
|
|
RpcTryExcept
|
|
|
|
{
|
|
|
|
dwErrorCode = _RpcDeletePrintProcessor( pName, pEnvironment, pPrintProcessorName );
|
|
|
|
}
|
|
|
|
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
dwErrorCode = RpcExceptionCode();
|
|
|
|
ERR("_RpcDeletePrintProcessor failed with exception code %lu!\n", dwErrorCode);
|
|
|
|
}
|
|
|
|
RpcEndExcept;
|
|
|
|
|
|
|
|
SetLastError(dwErrorCode);
|
|
|
|
return (dwErrorCode == ERROR_SUCCESS);
|
2015-07-22 17:59:46 +00:00
|
|
|
}
|
|
|
|
|
2015-06-22 14:31:47 +00:00
|
|
|
BOOL WINAPI
|
2015-07-17 10:57:10 +00:00
|
|
|
EnumPrintProcessorDatatypesA(PSTR pName, LPSTR pPrintProcessorName, DWORD Level, PBYTE pDatatypes, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
|
2015-06-22 14:31:47 +00:00
|
|
|
{
|
2017-12-09 11:00:09 +00:00
|
|
|
TRACE("EnumPrintProcessorDatatypesA(%s, %s, %lu, %p, %lu, %p, %p)\n", pName, pPrintProcessorName, Level, pDatatypes, cbBuf, pcbNeeded, pcReturned);
|
2015-07-22 17:59:46 +00:00
|
|
|
UNIMPLEMENTED;
|
2015-06-22 14:31:47 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI
|
2015-07-17 10:57:10 +00:00
|
|
|
EnumPrintProcessorDatatypesW(PWSTR pName, LPWSTR pPrintProcessorName, DWORD Level, PBYTE pDatatypes, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
|
2015-06-22 14:31:47 +00:00
|
|
|
{
|
|
|
|
DWORD dwErrorCode;
|
2017-06-27 07:25:04 +00:00
|
|
|
|
2017-12-09 11:00:09 +00:00
|
|
|
TRACE("EnumPrintProcessorDatatypesW(%S, %S, %lu, %p, %lu, %p, %p)\n", pName, pPrintProcessorName, Level, pDatatypes, cbBuf, pcbNeeded, pcReturned);
|
|
|
|
|
2017-06-27 07:25:04 +00:00
|
|
|
// Sanity checks
|
|
|
|
if (Level != 1)
|
|
|
|
{
|
|
|
|
dwErrorCode = ERROR_INVALID_LEVEL;
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
2015-06-22 14:31:47 +00:00
|
|
|
|
|
|
|
// Do the RPC call
|
|
|
|
RpcTryExcept
|
|
|
|
{
|
|
|
|
dwErrorCode = _RpcEnumPrintProcessorDatatypes(pName, pPrintProcessorName, Level, pDatatypes, cbBuf, pcbNeeded, pcReturned);
|
|
|
|
}
|
2018-01-17 11:52:12 +00:00
|
|
|
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
|
2015-06-22 14:31:47 +00:00
|
|
|
{
|
2015-07-17 10:57:10 +00:00
|
|
|
dwErrorCode = RpcExceptionCode();
|
|
|
|
ERR("_RpcEnumPrintProcessorDatatypes failed with exception code %lu!\n", dwErrorCode);
|
2015-06-22 14:31:47 +00:00
|
|
|
}
|
|
|
|
RpcEndExcept;
|
|
|
|
|
2015-07-17 10:57:10 +00:00
|
|
|
if (dwErrorCode == ERROR_SUCCESS)
|
|
|
|
{
|
2018-01-17 11:52:12 +00:00
|
|
|
// Replace relative offset addresses in the output by absolute pointers.
|
|
|
|
MarshallUpStructuresArray(cbBuf, pDatatypes, *pcReturned, DatatypesInfo1Marshalling.pInfo, DatatypesInfo1Marshalling.cbStructureSize, TRUE);
|
2015-07-17 10:57:10 +00:00
|
|
|
}
|
|
|
|
|
2017-06-27 07:25:04 +00:00
|
|
|
Cleanup:
|
2015-07-17 10:57:10 +00:00
|
|
|
SetLastError(dwErrorCode);
|
|
|
|
return (dwErrorCode == ERROR_SUCCESS);
|
2015-06-22 14:31:47 +00:00
|
|
|
}
|
|
|
|
|
2017-12-09 12:35:42 +00:00
|
|
|
BOOL WINAPI
|
|
|
|
EnumPrintProcessorsA(PSTR pName, PSTR pEnvironment, DWORD Level, PBYTE pPrintProcessorInfo, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
|
|
|
|
{
|
2020-08-04 02:07:58 +00:00
|
|
|
BOOL res;
|
|
|
|
LPBYTE bufferW = NULL;
|
|
|
|
LPWSTR nameW = NULL;
|
|
|
|
LPWSTR envW = NULL;
|
|
|
|
DWORD needed = 0;
|
|
|
|
DWORD numentries = 0;
|
|
|
|
INT len;
|
|
|
|
|
|
|
|
TRACE("EnumPrintProcessorsA(%s, %s, %d, %p, %d, %p, %p)\n", debugstr_a(pName), debugstr_a(pEnvironment), Level, pPrintProcessorInfo, cbBuf, pcbNeeded, pcReturned);
|
|
|
|
|
|
|
|
/* convert names to unicode */
|
|
|
|
if (pName)
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, pName, -1, NULL, 0);
|
|
|
|
nameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pName, -1, nameW, len);
|
|
|
|
}
|
|
|
|
if (pEnvironment)
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, pEnvironment, -1, NULL, 0);
|
|
|
|
envW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pEnvironment, -1, envW, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* alloc (userbuffersize*sizeof(WCHAR) and try to enum the monitors */
|
|
|
|
needed = cbBuf * sizeof(WCHAR);
|
|
|
|
if (needed) bufferW = HeapAlloc(GetProcessHeap(), 0, needed);
|
|
|
|
res = EnumPrintProcessorsW(nameW, envW, Level, bufferW, needed, pcbNeeded, pcReturned);
|
|
|
|
|
|
|
|
if (!res && (GetLastError() == ERROR_INSUFFICIENT_BUFFER))
|
|
|
|
{
|
|
|
|
if (pcbNeeded) needed = *pcbNeeded;
|
|
|
|
/* HeapReAlloc return NULL, when bufferW was NULL */
|
|
|
|
bufferW = (bufferW) ? HeapReAlloc(GetProcessHeap(), 0, bufferW, needed) :
|
|
|
|
HeapAlloc(GetProcessHeap(), 0, needed);
|
|
|
|
|
|
|
|
/* Try again with the large Buffer */
|
|
|
|
res = EnumPrintProcessorsW(nameW, envW, Level, bufferW, needed, pcbNeeded, pcReturned);
|
|
|
|
}
|
|
|
|
numentries = pcReturned ? *pcReturned : 0;
|
|
|
|
needed = 0;
|
|
|
|
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
/* EnumPrintProcessorsW collected all Data. Parse them to calculate ANSI-Size */
|
|
|
|
DWORD index;
|
|
|
|
LPSTR ptr;
|
|
|
|
PPRINTPROCESSOR_INFO_1W ppiw;
|
|
|
|
PPRINTPROCESSOR_INFO_1A ppia;
|
|
|
|
|
|
|
|
/* First pass: calculate the size for all Entries */
|
|
|
|
ppiw = (PPRINTPROCESSOR_INFO_1W) bufferW;
|
|
|
|
ppia = (PPRINTPROCESSOR_INFO_1A) pPrintProcessorInfo;
|
|
|
|
index = 0;
|
|
|
|
while (index < numentries)
|
|
|
|
{
|
|
|
|
index++;
|
|
|
|
needed += sizeof(PRINTPROCESSOR_INFO_1A);
|
|
|
|
TRACE("%p: parsing #%d (%s)\n", ppiw, index, debugstr_w(ppiw->pName));
|
|
|
|
|
|
|
|
needed += WideCharToMultiByte(CP_ACP, 0, ppiw->pName, -1,
|
|
|
|
NULL, 0, NULL, NULL);
|
|
|
|
|
|
|
|
ppiw = (PPRINTPROCESSOR_INFO_1W) (((LPBYTE)ppiw) + sizeof(PRINTPROCESSOR_INFO_1W));
|
|
|
|
ppia = (PPRINTPROCESSOR_INFO_1A) (((LPBYTE)ppia) + sizeof(PRINTPROCESSOR_INFO_1A));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check for errors and quit on failure */
|
|
|
|
if (cbBuf < needed)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
|
|
|
res = FALSE;
|
|
|
|
goto epp_cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = numentries * sizeof(PRINTPROCESSOR_INFO_1A); /* room for structs */
|
|
|
|
ptr = (LPSTR) &pPrintProcessorInfo[len]; /* start of strings */
|
|
|
|
cbBuf -= len ; /* free Bytes in the user-Buffer */
|
|
|
|
ppiw = (PPRINTPROCESSOR_INFO_1W) bufferW;
|
|
|
|
ppia = (PPRINTPROCESSOR_INFO_1A) pPrintProcessorInfo;
|
|
|
|
index = 0;
|
|
|
|
/* Second Pass: Fill the User Buffer (if we have one) */
|
|
|
|
while ((index < numentries) && pPrintProcessorInfo)
|
|
|
|
{
|
|
|
|
index++;
|
|
|
|
TRACE("%p: writing PRINTPROCESSOR_INFO_1A #%d\n", ppia, index);
|
|
|
|
ppia->pName = ptr;
|
|
|
|
len = WideCharToMultiByte(CP_ACP, 0, ppiw->pName, -1,
|
|
|
|
ptr, cbBuf , NULL, NULL);
|
|
|
|
ptr += len;
|
|
|
|
cbBuf -= len;
|
|
|
|
|
|
|
|
ppiw = (PPRINTPROCESSOR_INFO_1W) (((LPBYTE)ppiw) + sizeof(PRINTPROCESSOR_INFO_1W));
|
|
|
|
ppia = (PPRINTPROCESSOR_INFO_1A) (((LPBYTE)ppia) + sizeof(PRINTPROCESSOR_INFO_1A));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
epp_cleanup:
|
|
|
|
if (pcbNeeded) *pcbNeeded = needed;
|
|
|
|
if (pcReturned) *pcReturned = (res) ? numentries : 0;
|
|
|
|
|
2020-08-26 22:12:20 +00:00
|
|
|
if (nameW) HeapFree(GetProcessHeap(), 0, nameW);
|
|
|
|
if (envW) HeapFree(GetProcessHeap(), 0, envW);
|
|
|
|
if (bufferW) HeapFree(GetProcessHeap(), 0, bufferW);
|
2020-08-04 02:07:58 +00:00
|
|
|
|
|
|
|
TRACE("returning %d with %d (%d byte for %d entries)\n", (res), GetLastError(), needed, numentries);
|
|
|
|
|
|
|
|
return (res);
|
|
|
|
|
2017-12-09 12:35:42 +00:00
|
|
|
}
|
|
|
|
|
2015-06-22 14:31:47 +00:00
|
|
|
BOOL WINAPI
|
2015-07-17 10:57:10 +00:00
|
|
|
EnumPrintProcessorsW(PWSTR pName, PWSTR pEnvironment, DWORD Level, PBYTE pPrintProcessorInfo, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
|
2015-06-22 14:31:47 +00:00
|
|
|
{
|
|
|
|
DWORD dwErrorCode;
|
|
|
|
|
2017-12-09 11:00:09 +00:00
|
|
|
TRACE("EnumPrintProcessorsW(%S, %S, %lu, %p, %lu, %p, %p)\n", pName, pEnvironment, Level, pPrintProcessorInfo, cbBuf, pcbNeeded, pcReturned);
|
|
|
|
|
2016-11-24 19:24:27 +00:00
|
|
|
// Choose our current environment if the caller didn't give any.
|
|
|
|
if (!pEnvironment)
|
|
|
|
pEnvironment = (PWSTR)wszCurrentEnvironment;
|
|
|
|
|
2015-06-22 14:31:47 +00:00
|
|
|
// Do the RPC call
|
|
|
|
RpcTryExcept
|
|
|
|
{
|
|
|
|
dwErrorCode = _RpcEnumPrintProcessors(pName, pEnvironment, Level, pPrintProcessorInfo, cbBuf, pcbNeeded, pcReturned);
|
|
|
|
}
|
2018-01-17 11:52:12 +00:00
|
|
|
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
|
2015-06-22 14:31:47 +00:00
|
|
|
{
|
2015-07-17 10:57:10 +00:00
|
|
|
dwErrorCode = RpcExceptionCode();
|
2015-06-22 14:31:47 +00:00
|
|
|
}
|
|
|
|
RpcEndExcept;
|
|
|
|
|
2015-07-17 10:57:10 +00:00
|
|
|
if (dwErrorCode == ERROR_SUCCESS)
|
|
|
|
{
|
2018-01-17 11:52:12 +00:00
|
|
|
// Replace relative offset addresses in the output by absolute pointers.
|
|
|
|
MarshallUpStructuresArray(cbBuf, pPrintProcessorInfo, *pcReturned, PrintProcessorInfo1Marshalling.pInfo, PrintProcessorInfo1Marshalling.cbStructureSize, TRUE);
|
2015-07-17 10:57:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SetLastError(dwErrorCode);
|
|
|
|
return (dwErrorCode == ERROR_SUCCESS);
|
2015-06-22 14:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI
|
2016-11-24 19:24:27 +00:00
|
|
|
GetPrintProcessorDirectoryA(PSTR pName, PSTR pEnvironment, DWORD Level, PBYTE pPrintProcessorInfo, DWORD cbBuf, PDWORD pcbNeeded)
|
2015-06-22 14:31:47 +00:00
|
|
|
{
|
|
|
|
BOOL bReturnValue = FALSE;
|
2016-11-24 19:24:27 +00:00
|
|
|
DWORD cch;
|
|
|
|
PWSTR pwszName = NULL;
|
|
|
|
PWSTR pwszEnvironment = NULL;
|
|
|
|
PWSTR pwszPrintProcessorInfo = NULL;
|
|
|
|
|
2017-12-09 11:00:09 +00:00
|
|
|
TRACE("GetPrintProcessorDirectoryA(%s, %s, %lu, %p, %lu, %p)\n", pName, pEnvironment, Level, pPrintProcessorInfo, cbBuf, pcbNeeded);
|
|
|
|
|
2016-11-24 19:24:27 +00:00
|
|
|
if (pName)
|
|
|
|
{
|
|
|
|
// Convert pName to a Unicode string pwszName.
|
|
|
|
cch = strlen(pName);
|
|
|
|
|
|
|
|
pwszName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(WCHAR));
|
|
|
|
if (!pwszName)
|
|
|
|
{
|
[PRINTING]
- Implement GetPrinterDataA, GetPrinterDataExA, GetPrinterDataExW, GetPrinterDataW, SetPrinterDataA, SetPrinterDataExA, SetPrinterDataExW, SetPrinterDataW.
They support all features for Print Server and Printer Handles (minus security checks!)
I've also added tests for them.
- Store Printer data in SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers instead of SYSTEM\CurrentControlSet\Control\Print\Printers and create a registry symlink from the former path to the new one just like Windows does.
According to https://social.technet.microsoft.com/Forums/windowsserver/en-US/a683ab54-c43c-4ebe-af8f-1f7a65af2a51, this is needed when having >900 printers to work around a size limit of the SYSTEM registry hive. And if Windows has both locations, we need both for compatibility anyway.
- Add several settings which are queried by the new Printer Data APIs when working with Print Server Handles.
- Store the job directory in the Windows-compatible "DefaultSpoolDirectory" setting and make use of it.
- Revert the ASSERTs in LocalEnumPrinters again to let us verify the NULL pointer exceptions in localspl_apitest (thanks Serge! CORE-13433)
- Translate ERROR_INVALID_NAME to ERROR_INVALID_PRINTER_NAME in all cases in OpenPrinterW (thanks Victor! CORE-13412)
- Make EnumMonitorsW and EnumPortsW in spoolss more robust against failing Print Monitors.
- Remove the wrong !phPrinter check in OpenPrinterW to make Print Server Handles work for real.
- Fix error handling when memory allocation fails: HeapAlloc doesn't set last error, so it's just wrong to query or return it.
One more item done from https://reactos.org/wiki/Printing !
This is all still a big Work-in-Progress, with many subtle bugs deep down in ReactOS, for which I need to open additional tickets. But I didn't want to make this commit even bigger..
svn path=/trunk/; revision=75125
2017-06-19 14:18:19 +00:00
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
ERR("HeapAlloc failed!\n");
|
2016-11-24 19:24:27 +00:00
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pName, -1, pwszName, cch + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pEnvironment)
|
|
|
|
{
|
|
|
|
// Convert pEnvironment to a Unicode string pwszEnvironment.
|
|
|
|
cch = strlen(pEnvironment);
|
|
|
|
|
|
|
|
pwszEnvironment = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(WCHAR));
|
|
|
|
if (!pwszEnvironment)
|
|
|
|
{
|
[PRINTING]
- Implement GetPrinterDataA, GetPrinterDataExA, GetPrinterDataExW, GetPrinterDataW, SetPrinterDataA, SetPrinterDataExA, SetPrinterDataExW, SetPrinterDataW.
They support all features for Print Server and Printer Handles (minus security checks!)
I've also added tests for them.
- Store Printer data in SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers instead of SYSTEM\CurrentControlSet\Control\Print\Printers and create a registry symlink from the former path to the new one just like Windows does.
According to https://social.technet.microsoft.com/Forums/windowsserver/en-US/a683ab54-c43c-4ebe-af8f-1f7a65af2a51, this is needed when having >900 printers to work around a size limit of the SYSTEM registry hive. And if Windows has both locations, we need both for compatibility anyway.
- Add several settings which are queried by the new Printer Data APIs when working with Print Server Handles.
- Store the job directory in the Windows-compatible "DefaultSpoolDirectory" setting and make use of it.
- Revert the ASSERTs in LocalEnumPrinters again to let us verify the NULL pointer exceptions in localspl_apitest (thanks Serge! CORE-13433)
- Translate ERROR_INVALID_NAME to ERROR_INVALID_PRINTER_NAME in all cases in OpenPrinterW (thanks Victor! CORE-13412)
- Make EnumMonitorsW and EnumPortsW in spoolss more robust against failing Print Monitors.
- Remove the wrong !phPrinter check in OpenPrinterW to make Print Server Handles work for real.
- Fix error handling when memory allocation fails: HeapAlloc doesn't set last error, so it's just wrong to query or return it.
One more item done from https://reactos.org/wiki/Printing !
This is all still a big Work-in-Progress, with many subtle bugs deep down in ReactOS, for which I need to open additional tickets. But I didn't want to make this commit even bigger..
svn path=/trunk/; revision=75125
2017-06-19 14:18:19 +00:00
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
ERR("HeapAlloc failed!\n");
|
2016-11-24 19:24:27 +00:00
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pEnvironment, -1, pwszEnvironment, cch + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cbBuf && pPrintProcessorInfo)
|
|
|
|
{
|
|
|
|
// Allocate a temporary buffer for the Unicode result.
|
|
|
|
// We can just go with cbBuf here. The user should have set it based on pcbNeeded returned in a previous call and our
|
|
|
|
// pcbNeeded is the same for the A and W functions.
|
|
|
|
pwszPrintProcessorInfo = HeapAlloc(hProcessHeap, 0, cbBuf);
|
|
|
|
if (!pwszPrintProcessorInfo)
|
|
|
|
{
|
[PRINTING]
- Implement GetPrinterDataA, GetPrinterDataExA, GetPrinterDataExW, GetPrinterDataW, SetPrinterDataA, SetPrinterDataExA, SetPrinterDataExW, SetPrinterDataW.
They support all features for Print Server and Printer Handles (minus security checks!)
I've also added tests for them.
- Store Printer data in SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers instead of SYSTEM\CurrentControlSet\Control\Print\Printers and create a registry symlink from the former path to the new one just like Windows does.
According to https://social.technet.microsoft.com/Forums/windowsserver/en-US/a683ab54-c43c-4ebe-af8f-1f7a65af2a51, this is needed when having >900 printers to work around a size limit of the SYSTEM registry hive. And if Windows has both locations, we need both for compatibility anyway.
- Add several settings which are queried by the new Printer Data APIs when working with Print Server Handles.
- Store the job directory in the Windows-compatible "DefaultSpoolDirectory" setting and make use of it.
- Revert the ASSERTs in LocalEnumPrinters again to let us verify the NULL pointer exceptions in localspl_apitest (thanks Serge! CORE-13433)
- Translate ERROR_INVALID_NAME to ERROR_INVALID_PRINTER_NAME in all cases in OpenPrinterW (thanks Victor! CORE-13412)
- Make EnumMonitorsW and EnumPortsW in spoolss more robust against failing Print Monitors.
- Remove the wrong !phPrinter check in OpenPrinterW to make Print Server Handles work for real.
- Fix error handling when memory allocation fails: HeapAlloc doesn't set last error, so it's just wrong to query or return it.
One more item done from https://reactos.org/wiki/Printing !
This is all still a big Work-in-Progress, with many subtle bugs deep down in ReactOS, for which I need to open additional tickets. But I didn't want to make this commit even bigger..
svn path=/trunk/; revision=75125
2017-06-19 14:18:19 +00:00
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
ERR("HeapAlloc failed!\n");
|
2016-11-24 19:24:27 +00:00
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bReturnValue = GetPrintProcessorDirectoryW(pwszName, pwszEnvironment, Level, (PBYTE)pwszPrintProcessorInfo, cbBuf, pcbNeeded);
|
|
|
|
|
|
|
|
if (bReturnValue)
|
|
|
|
{
|
|
|
|
// Convert pwszPrintProcessorInfo to an ANSI string pPrintProcessorInfo.
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, pwszPrintProcessorInfo, -1, (PSTR)pPrintProcessorInfo, cbBuf, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
Cleanup:
|
|
|
|
if (pwszName)
|
|
|
|
HeapFree(hProcessHeap, 0, pwszName);
|
|
|
|
|
|
|
|
if (pwszEnvironment)
|
|
|
|
HeapFree(hProcessHeap, 0, pwszEnvironment);
|
|
|
|
|
|
|
|
if (pwszPrintProcessorInfo)
|
|
|
|
HeapFree(hProcessHeap, 0, pwszPrintProcessorInfo);
|
|
|
|
|
|
|
|
return bReturnValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI
|
|
|
|
GetPrintProcessorDirectoryW(PWSTR pName, PWSTR pEnvironment, DWORD Level, PBYTE pPrintProcessorInfo, DWORD cbBuf, PDWORD pcbNeeded)
|
|
|
|
{
|
2015-06-22 14:31:47 +00:00
|
|
|
DWORD dwErrorCode;
|
|
|
|
|
2017-12-09 11:00:09 +00:00
|
|
|
TRACE("GetPrintProcessorDirectoryW(%S, %S, %lu, %p, %lu, %p)\n", pName, pEnvironment, Level, pPrintProcessorInfo, cbBuf, pcbNeeded);
|
|
|
|
|
2016-11-24 19:24:27 +00:00
|
|
|
// Sanity checks
|
|
|
|
if (Level != 1)
|
|
|
|
{
|
|
|
|
dwErrorCode = ERROR_INVALID_LEVEL;
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Choose our current environment if the caller didn't give any.
|
|
|
|
if (!pEnvironment)
|
|
|
|
pEnvironment = (PWSTR)wszCurrentEnvironment;
|
|
|
|
|
2015-06-22 14:31:47 +00:00
|
|
|
// Do the RPC call
|
|
|
|
RpcTryExcept
|
|
|
|
{
|
|
|
|
dwErrorCode = _RpcGetPrintProcessorDirectory(pName, pEnvironment, Level, pPrintProcessorInfo, cbBuf, pcbNeeded);
|
|
|
|
}
|
2018-01-17 11:52:12 +00:00
|
|
|
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
|
2015-06-22 14:31:47 +00:00
|
|
|
{
|
2016-11-24 19:24:27 +00:00
|
|
|
dwErrorCode = RpcExceptionCode();
|
2015-06-22 14:31:47 +00:00
|
|
|
}
|
|
|
|
RpcEndExcept;
|
|
|
|
|
2016-11-24 19:24:27 +00:00
|
|
|
Cleanup:
|
|
|
|
SetLastError(dwErrorCode);
|
|
|
|
return (dwErrorCode == ERROR_SUCCESS);
|
2015-06-22 14:31:47 +00:00
|
|
|
}
|