2015-06-22 14:31:47 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Spooler Router
|
2017-09-29 17:18:19 +00:00
|
|
|
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
|
2015-06-22 14:31:47 +00:00
|
|
|
* PURPOSE: Functions related to Printers and printing
|
2017-09-29 17:18:19 +00:00
|
|
|
* COPYRIGHT: Copyright 2015-2017 Colin Finck (colin@reactos.org)
|
2015-06-22 14:31:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
|
2020-08-26 22:12:20 +00:00
|
|
|
BOOL WINAPI
|
|
|
|
AbortPrinter(HANDLE hPrinter)
|
|
|
|
{
|
|
|
|
PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter;
|
|
|
|
|
|
|
|
// Sanity checks.
|
|
|
|
if (!pHandle)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pHandle->pPrintProvider->PrintProvider.fpAbortPrinter(pHandle->hPrinter);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// See [MS-RPRN] 2.2.1.11 SPLCLIENT_INFO, SPLCLIENT_INFO Level.
|
|
|
|
//
|
|
|
|
HANDLE WINAPI
|
|
|
|
AddPrinterExW( PWSTR pName, DWORD Level, PBYTE pPrinter, PBYTE pClientInfo, DWORD ClientInfoLevel)
|
|
|
|
{
|
|
|
|
BOOL bReturnValue;
|
|
|
|
DWORD dwErrorCode = ERROR_INVALID_PRINTER_NAME;
|
|
|
|
HANDLE hPrinter = NULL;
|
|
|
|
PWSTR pPrinterName = NULL;
|
|
|
|
PLIST_ENTRY pEntry;
|
|
|
|
PSPOOLSS_PRINTER_HANDLE pHandle;
|
|
|
|
PSPOOLSS_PRINT_PROVIDER pPrintProvider;
|
|
|
|
|
|
|
|
if ( Level != 2 )
|
|
|
|
{
|
|
|
|
FIXME( "Unsupported level %d\n", Level );
|
|
|
|
SetLastError( ERROR_INVALID_LEVEL );
|
|
|
|
return hPrinter;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PPRINTER_INFO_2W pi2w = (PPRINTER_INFO_2W)pPrinter;
|
|
|
|
pPrinterName = pi2w->pPrinterName;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Loop through all Print Providers to find one able to open this Printer.
|
|
|
|
for (pEntry = PrintProviderList.Flink; pEntry != &PrintProviderList; pEntry = pEntry->Flink)
|
|
|
|
{
|
|
|
|
pPrintProvider = CONTAINING_RECORD(pEntry, SPOOLSS_PRINT_PROVIDER, Entry);
|
|
|
|
|
|
|
|
hPrinter = pPrintProvider->PrintProvider.fpAddPrinterEx(pName, Level, pPrinter, pClientInfo, ClientInfoLevel);
|
|
|
|
|
|
|
|
bReturnValue = GetLastError();
|
|
|
|
|
|
|
|
// Fallback.... ?
|
|
|
|
|
|
|
|
if ( hPrinter == NULL && bReturnValue == ERROR_NOT_SUPPORTED )
|
|
|
|
{
|
|
|
|
hPrinter = pPrintProvider->PrintProvider.fpAddPrinter(pName, Level, pPrinter);
|
|
|
|
}
|
|
|
|
|
|
|
|
bReturnValue = GetLastError();
|
|
|
|
|
|
|
|
if ( bReturnValue == ROUTER_SUCCESS && hPrinter )
|
|
|
|
{
|
|
|
|
// This Print Provider has opened this Printer.
|
|
|
|
// Store this information and return a handle.
|
|
|
|
pHandle = DllAllocSplMem(sizeof(SPOOLSS_PRINTER_HANDLE));
|
|
|
|
if (!pHandle)
|
|
|
|
{
|
|
|
|
dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
ERR("DllAllocSplMem failed!\n");
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
pHandle->pPrintProvider = pPrintProvider;
|
|
|
|
pHandle->hPrinter = hPrinter;
|
|
|
|
|
|
|
|
dwErrorCode = ERROR_SUCCESS;
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
else if (bReturnValue == ROUTER_STOP_ROUTING)
|
|
|
|
{
|
|
|
|
ERR("A Print Provider returned ROUTER_STOP_ROUTING for Printer \"%S\"!\n", pPrinterName);
|
|
|
|
dwErrorCode = GetLastError();
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Cleanup:
|
|
|
|
// ERROR_INVALID_NAME by the Print Provider is translated to ERROR_INVALID_PRINTER_NAME here, but not in other APIs as far as I know.
|
|
|
|
if (dwErrorCode == ERROR_INVALID_NAME)
|
|
|
|
dwErrorCode = ERROR_INVALID_PRINTER_NAME;
|
|
|
|
|
|
|
|
SetLastError(dwErrorCode);
|
|
|
|
return hPrinter;
|
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE WINAPI
|
|
|
|
AddPrinterW(PWSTR pName, DWORD Level, PBYTE pPrinter)
|
|
|
|
{
|
|
|
|
BOOL bReturnValue;
|
|
|
|
DWORD dwErrorCode = ERROR_INVALID_PRINTER_NAME;
|
|
|
|
HANDLE hPrinter = NULL;
|
|
|
|
PWSTR pPrinterName = NULL;
|
|
|
|
PLIST_ENTRY pEntry;
|
|
|
|
PSPOOLSS_PRINTER_HANDLE pHandle;
|
|
|
|
PSPOOLSS_PRINT_PROVIDER pPrintProvider;
|
|
|
|
|
|
|
|
FIXME("AddPrinterW(%S, %lu, %p)\n", pName, Level, pPrinter);
|
|
|
|
|
|
|
|
if ( Level != 2 )
|
|
|
|
{
|
|
|
|
FIXME( "Unsupported level %d\n", Level );
|
|
|
|
SetLastError( ERROR_INVALID_LEVEL );
|
|
|
|
return hPrinter;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PPRINTER_INFO_2W pi2w = (PPRINTER_INFO_2W)pPrinter;
|
|
|
|
pPrinterName = pi2w->pPrinterName;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Xp return AddPrinterExW( pName, Level, pPrinter, NULL, 0); but,,,, W7u just Forward Direct.
|
|
|
|
|
|
|
|
// Loop through all Print Providers to find one able to open this Printer.
|
|
|
|
for (pEntry = PrintProviderList.Flink; pEntry != &PrintProviderList; pEntry = pEntry->Flink)
|
|
|
|
{
|
|
|
|
pPrintProvider = CONTAINING_RECORD(pEntry, SPOOLSS_PRINT_PROVIDER, Entry);
|
|
|
|
|
|
|
|
hPrinter = pPrintProvider->PrintProvider.fpAddPrinter(pName, Level, pPrinter);
|
|
|
|
|
|
|
|
bReturnValue = GetLastError();
|
|
|
|
|
|
|
|
if ( bReturnValue == ROUTER_SUCCESS && hPrinter )
|
|
|
|
{
|
|
|
|
// This Print Provider has opened this Printer.
|
|
|
|
// Store this information and return a handle.
|
|
|
|
pHandle = DllAllocSplMem(sizeof(SPOOLSS_PRINTER_HANDLE));
|
|
|
|
if (!pHandle)
|
|
|
|
{
|
|
|
|
dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
ERR("DllAllocSplMem failed!\n");
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
pHandle->pPrintProvider = pPrintProvider;
|
|
|
|
pHandle->hPrinter = hPrinter;
|
|
|
|
|
|
|
|
dwErrorCode = ERROR_SUCCESS;
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
else if (bReturnValue == ROUTER_STOP_ROUTING)
|
|
|
|
{
|
|
|
|
ERR("A Print Provider returned ROUTER_STOP_ROUTING for Printer \"%S\"!\n", pPrinterName);
|
|
|
|
dwErrorCode = GetLastError();
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Cleanup:
|
|
|
|
// ERROR_INVALID_NAME by the Print Provider is translated to ERROR_INVALID_PRINTER_NAME here, but not in other APIs as far as I know.
|
|
|
|
if (dwErrorCode == ERROR_INVALID_NAME)
|
|
|
|
dwErrorCode = ERROR_INVALID_PRINTER_NAME;
|
|
|
|
|
|
|
|
SetLastError(dwErrorCode);
|
|
|
|
return hPrinter;
|
|
|
|
}
|
2015-06-22 14:31:47 +00:00
|
|
|
|
|
|
|
BOOL WINAPI
|
|
|
|
ClosePrinter(HANDLE hPrinter)
|
|
|
|
{
|
2015-07-07 17:06:48 +00:00
|
|
|
BOOL bReturnValue;
|
|
|
|
PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter;
|
|
|
|
|
2020-08-26 22:12:20 +00:00
|
|
|
FIXME("ClosePrinter %p\n",hPrinter);
|
|
|
|
|
2015-07-07 17:06:48 +00:00
|
|
|
// Sanity checks.
|
|
|
|
if (!pHandle)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: Call FindClosePrinterChangeNotification for all created change notifications (according to MSDN).
|
|
|
|
|
|
|
|
// Call CloseHandle of the Print Provider.
|
|
|
|
bReturnValue = pHandle->pPrintProvider->PrintProvider.fpClosePrinter(pHandle->hPrinter);
|
2020-08-26 22:12:20 +00:00
|
|
|
FIXME("ClosePrinter 2\n");
|
2015-07-07 17:06:48 +00:00
|
|
|
// Free our handle information.
|
|
|
|
DllFreeSplMem(pHandle);
|
2020-08-26 22:12:20 +00:00
|
|
|
FIXME("ClosePrinter 3\n");
|
2015-07-07 17:06:48 +00:00
|
|
|
return bReturnValue;
|
2015-06-22 14:31:47 +00:00
|
|
|
}
|
|
|
|
|
2020-08-26 22:12:20 +00:00
|
|
|
BOOL WINAPI
|
|
|
|
DeletePrinter(HANDLE hPrinter)
|
|
|
|
{
|
|
|
|
PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter;
|
|
|
|
|
|
|
|
// Sanity checks.
|
|
|
|
if (!pHandle)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pHandle->pPrintProvider->PrintProvider.fpDeletePrinter(pHandle->hPrinter);
|
|
|
|
}
|
|
|
|
|
2015-06-22 14:31:47 +00:00
|
|
|
BOOL WINAPI
|
|
|
|
EndDocPrinter(HANDLE hPrinter)
|
|
|
|
{
|
2015-07-07 17:06:48 +00:00
|
|
|
PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter;
|
|
|
|
|
|
|
|
// Sanity checks.
|
|
|
|
if (!pHandle)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pHandle->pPrintProvider->PrintProvider.fpEndDocPrinter(pHandle->hPrinter);
|
2015-06-22 14:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI
|
|
|
|
EndPagePrinter(HANDLE hPrinter)
|
|
|
|
{
|
2015-07-07 17:06:48 +00:00
|
|
|
PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter;
|
|
|
|
|
|
|
|
// Sanity checks.
|
|
|
|
if (!pHandle)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pHandle->pPrintProvider->PrintProvider.fpEndPagePrinter(pHandle->hPrinter);
|
2015-06-22 14:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI
|
2015-07-07 17:06:48 +00:00
|
|
|
EnumPrintersW(DWORD Flags, PWSTR Name, DWORD Level, PBYTE pPrinterEnum, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
|
2015-06-22 14:31:47 +00:00
|
|
|
{
|
2015-07-07 17:06:48 +00:00
|
|
|
DWORD cbCallBuffer;
|
|
|
|
DWORD cbNeeded;
|
2017-07-05 15:29:13 +00:00
|
|
|
DWORD dwErrorCode = MAXDWORD;
|
2015-07-07 17:06:48 +00:00
|
|
|
DWORD dwReturned;
|
|
|
|
PBYTE pCallBuffer;
|
2020-08-26 22:12:20 +00:00
|
|
|
BOOL Ret = FALSE;
|
2015-07-07 17:06:48 +00:00
|
|
|
PSPOOLSS_PRINT_PROVIDER pPrintProvider;
|
|
|
|
PLIST_ENTRY pEntry;
|
|
|
|
|
|
|
|
// Begin counting.
|
|
|
|
*pcbNeeded = 0;
|
|
|
|
*pcReturned = 0;
|
|
|
|
|
2017-04-16 14:12:01 +00:00
|
|
|
if (cbBuf && !pPrinterEnum)
|
|
|
|
{
|
|
|
|
dwErrorCode = ERROR_INVALID_USER_BUFFER;
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
2015-07-07 17:06:48 +00:00
|
|
|
// At the beginning, we have the full buffer available.
|
|
|
|
cbCallBuffer = cbBuf;
|
|
|
|
pCallBuffer = pPrinterEnum;
|
|
|
|
|
2017-04-16 14:12:01 +00:00
|
|
|
// Loop through all Print Providers.
|
2015-07-07 17:06:48 +00:00
|
|
|
for (pEntry = PrintProviderList.Flink; pEntry != &PrintProviderList; pEntry = pEntry->Flink)
|
|
|
|
{
|
|
|
|
pPrintProvider = CONTAINING_RECORD(pEntry, SPOOLSS_PRINT_PROVIDER, Entry);
|
|
|
|
|
|
|
|
// Call the EnumPrinters function of this Print Provider.
|
[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
|
|
|
cbNeeded = 0;
|
|
|
|
dwReturned = 0;
|
2020-08-26 22:12:20 +00:00
|
|
|
Ret = pPrintProvider->PrintProvider.fpEnumPrinters(Flags, Name, Level, pCallBuffer, cbCallBuffer, &cbNeeded, &dwReturned);
|
|
|
|
|
|
|
|
if ( !Ret )
|
|
|
|
{
|
|
|
|
dwErrorCode = GetLastError();
|
|
|
|
}
|
2015-07-07 17:06:48 +00:00
|
|
|
|
|
|
|
// Add the returned counts to the total values.
|
|
|
|
*pcbNeeded += cbNeeded;
|
|
|
|
*pcReturned += dwReturned;
|
|
|
|
|
|
|
|
// Reduce the available buffer size for the next call without risking an underflow.
|
|
|
|
if (cbNeeded < cbCallBuffer)
|
|
|
|
cbCallBuffer -= cbNeeded;
|
|
|
|
else
|
|
|
|
cbCallBuffer = 0;
|
|
|
|
|
|
|
|
// Advance the buffer if the caller provided it.
|
|
|
|
if (pCallBuffer)
|
|
|
|
pCallBuffer += cbNeeded;
|
2017-04-16 14:12:01 +00:00
|
|
|
|
|
|
|
// dwErrorCode shall not be overwritten if a previous EnumPrinters call already succeeded.
|
|
|
|
if (dwErrorCode != ERROR_SUCCESS)
|
|
|
|
dwErrorCode = GetLastError();
|
2015-07-07 17:06:48 +00:00
|
|
|
}
|
|
|
|
|
2017-04-16 14:12:01 +00:00
|
|
|
Cleanup:
|
|
|
|
SetLastError(dwErrorCode);
|
|
|
|
return (dwErrorCode == ERROR_SUCCESS);
|
2015-06-22 14:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI
|
2020-08-26 22:12:20 +00:00
|
|
|
GetPrinterW(HANDLE hPrinter, DWORD Level, PBYTE pPrinter, DWORD cbBuf, PDWORD pcbNeeded)
|
2015-06-22 14:31:47 +00:00
|
|
|
{
|
2015-07-07 17:06:48 +00:00
|
|
|
PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter;
|
|
|
|
|
|
|
|
// Sanity checks.
|
|
|
|
if (!pHandle)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-08-26 22:12:20 +00:00
|
|
|
return pHandle->pPrintProvider->PrintProvider.fpGetPrinter(pHandle->hPrinter, Level, pPrinter, cbBuf, pcbNeeded);
|
2015-06-22 14:31:47 +00:00
|
|
|
}
|
|
|
|
|
2020-08-26 22:12:20 +00:00
|
|
|
//
|
|
|
|
// Forward Dead API to Local/Remote....
|
|
|
|
//
|
|
|
|
DWORD WINAPI
|
|
|
|
PrinterMessageBoxW(HANDLE hPrinter, DWORD Error, HWND hWnd, LPWSTR pText, LPWSTR pCaption, DWORD dwType)
|
2015-06-22 14:31:47 +00:00
|
|
|
{
|
2015-07-07 17:06:48 +00:00
|
|
|
PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter;
|
|
|
|
|
|
|
|
// Sanity checks.
|
|
|
|
if (!pHandle)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-08-26 22:12:20 +00:00
|
|
|
return pHandle->pPrintProvider->PrintProvider.fpPrinterMessageBox(pHandle->hPrinter, Error, hWnd, pText, pCaption, dwType);
|
2015-06-22 14:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI
|
2015-07-07 17:06:48 +00:00
|
|
|
OpenPrinterW(PWSTR pPrinterName, PHANDLE phPrinter, PPRINTER_DEFAULTSW pDefault)
|
2015-06-22 14:31:47 +00:00
|
|
|
{
|
2015-07-07 17:06:48 +00:00
|
|
|
BOOL bReturnValue;
|
2017-04-16 14:12:01 +00:00
|
|
|
DWORD dwErrorCode = ERROR_INVALID_PRINTER_NAME;
|
2015-07-07 17:06:48 +00:00
|
|
|
HANDLE hPrinter;
|
|
|
|
PLIST_ENTRY pEntry;
|
|
|
|
PSPOOLSS_PRINTER_HANDLE pHandle;
|
|
|
|
PSPOOLSS_PRINT_PROVIDER pPrintProvider;
|
|
|
|
|
|
|
|
// Loop through all Print Providers to find one able to open this Printer.
|
|
|
|
for (pEntry = PrintProviderList.Flink; pEntry != &PrintProviderList; pEntry = pEntry->Flink)
|
|
|
|
{
|
|
|
|
pPrintProvider = CONTAINING_RECORD(pEntry, SPOOLSS_PRINT_PROVIDER, Entry);
|
|
|
|
|
|
|
|
bReturnValue = pPrintProvider->PrintProvider.fpOpenPrinter(pPrinterName, &hPrinter, pDefault);
|
|
|
|
if (bReturnValue == ROUTER_SUCCESS)
|
|
|
|
{
|
|
|
|
// This Print Provider has opened this Printer.
|
|
|
|
// Store this information and return a handle.
|
|
|
|
pHandle = DllAllocSplMem(sizeof(SPOOLSS_PRINTER_HANDLE));
|
|
|
|
if (!pHandle)
|
|
|
|
{
|
2017-04-16 14:12:01 +00:00
|
|
|
dwErrorCode = ERROR_NOT_ENOUGH_MEMORY;
|
[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
|
|
|
ERR("DllAllocSplMem failed!\n");
|
2017-04-16 14:12:01 +00:00
|
|
|
goto Cleanup;
|
2015-07-07 17:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pHandle->pPrintProvider = pPrintProvider;
|
|
|
|
pHandle->hPrinter = hPrinter;
|
|
|
|
*phPrinter = (HANDLE)pHandle;
|
|
|
|
|
2017-04-16 14:12:01 +00:00
|
|
|
dwErrorCode = ERROR_SUCCESS;
|
|
|
|
goto Cleanup;
|
2015-07-07 17:06:48 +00:00
|
|
|
}
|
|
|
|
else if (bReturnValue == ROUTER_STOP_ROUTING)
|
|
|
|
{
|
|
|
|
ERR("A Print Provider returned ROUTER_STOP_ROUTING for Printer \"%S\"!\n", pPrinterName);
|
2017-04-16 14:12:01 +00:00
|
|
|
dwErrorCode = GetLastError();
|
|
|
|
goto Cleanup;
|
2015-07-07 17:06:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[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
|
|
|
Cleanup:
|
2017-04-16 14:12:01 +00:00
|
|
|
// ERROR_INVALID_NAME by the Print Provider is translated to ERROR_INVALID_PRINTER_NAME here, but not in other APIs as far as I know.
|
|
|
|
if (dwErrorCode == ERROR_INVALID_NAME)
|
|
|
|
dwErrorCode = ERROR_INVALID_PRINTER_NAME;
|
|
|
|
|
|
|
|
SetLastError(dwErrorCode);
|
|
|
|
return (dwErrorCode == ERROR_SUCCESS);
|
2015-06-22 14:31:47 +00:00
|
|
|
}
|
|
|
|
|
2015-06-28 15:51:32 +00:00
|
|
|
BOOL WINAPI
|
|
|
|
ReadPrinter(HANDLE hPrinter, PVOID pBuf, DWORD cbBuf, PDWORD pNoBytesRead)
|
|
|
|
{
|
2015-07-07 17:06:48 +00:00
|
|
|
PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter;
|
|
|
|
|
|
|
|
// Sanity checks.
|
|
|
|
if (!pHandle)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pHandle->pPrintProvider->PrintProvider.fpReadPrinter(pHandle->hPrinter, pBuf, cbBuf, pNoBytesRead);
|
2015-06-28 15:51:32 +00:00
|
|
|
}
|
|
|
|
|
2020-08-26 22:12:20 +00:00
|
|
|
BOOL WINAPI
|
|
|
|
SeekPrinter( HANDLE hPrinter, LARGE_INTEGER liDistanceToMove, PLARGE_INTEGER pliNewPointer, DWORD dwMoveMethod, BOOL bWrite )
|
|
|
|
{
|
|
|
|
PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter;
|
|
|
|
|
|
|
|
// Sanity checks.
|
|
|
|
if (!pHandle)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pHandle->pPrintProvider->PrintProvider.fpSeekPrinter( pHandle->hPrinter, liDistanceToMove, pliNewPointer, dwMoveMethod, bWrite );
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI
|
|
|
|
SetPrinterW(HANDLE hPrinter, DWORD Level, PBYTE pPrinter, DWORD Command)
|
|
|
|
{
|
|
|
|
PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter;
|
|
|
|
|
|
|
|
// Sanity checks.
|
|
|
|
if (!pHandle)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pHandle->pPrintProvider->PrintProvider.fpSetPrinter( pHandle->hPrinter, Level, pPrinter, Command );
|
|
|
|
}
|
|
|
|
|
2015-06-22 14:31:47 +00:00
|
|
|
DWORD WINAPI
|
2015-07-07 17:06:48 +00:00
|
|
|
StartDocPrinterW(HANDLE hPrinter, DWORD Level, PBYTE pDocInfo)
|
2015-06-22 14:31:47 +00:00
|
|
|
{
|
2015-07-07 17:06:48 +00:00
|
|
|
PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter;
|
|
|
|
|
|
|
|
// Sanity checks.
|
|
|
|
if (!pHandle)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pHandle->pPrintProvider->PrintProvider.fpStartDocPrinter(pHandle->hPrinter, Level, pDocInfo);
|
2015-06-22 14:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI
|
|
|
|
StartPagePrinter(HANDLE hPrinter)
|
|
|
|
{
|
2015-07-07 17:06:48 +00:00
|
|
|
PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter;
|
|
|
|
|
|
|
|
// Sanity checks.
|
|
|
|
if (!pHandle)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pHandle->pPrintProvider->PrintProvider.fpStartPagePrinter(pHandle->hPrinter);
|
2015-06-22 14:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI
|
2015-07-07 17:06:48 +00:00
|
|
|
WritePrinter(HANDLE hPrinter, PVOID pBuf, DWORD cbBuf, PDWORD pcWritten)
|
2015-06-22 14:31:47 +00:00
|
|
|
{
|
2015-07-07 17:06:48 +00:00
|
|
|
PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter;
|
|
|
|
|
|
|
|
// Sanity checks.
|
|
|
|
if (!pHandle)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pHandle->pPrintProvider->PrintProvider.fpWritePrinter(pHandle->hPrinter, pBuf, cbBuf, pcWritten);
|
2015-06-22 14:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI
|
|
|
|
XcvDataW(HANDLE hXcv, PCWSTR pszDataName, PBYTE pInputData, DWORD cbInputData, PBYTE pOutputData, DWORD cbOutputData, PDWORD pcbOutputNeeded, PDWORD pdwStatus)
|
|
|
|
{
|
2015-07-07 17:06:48 +00:00
|
|
|
PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hXcv;
|
|
|
|
|
2020-08-26 22:12:20 +00:00
|
|
|
FIXME("XcvDataW( %p, %S,,,)\n",hXcv, pszDataName);
|
|
|
|
|
2015-07-07 17:06:48 +00:00
|
|
|
// Sanity checks.
|
|
|
|
if (!pHandle)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pHandle->pPrintProvider->PrintProvider.fpXcvData(pHandle->hPrinter, pszDataName, pInputData, cbInputData, pOutputData, cbOutputData, pcbOutputNeeded, pdwStatus);
|
2015-06-22 14:31:47 +00:00
|
|
|
}
|