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"
|
|
|
|
|
|
|
|
|
|
|
|
BOOL WINAPI
|
|
|
|
ClosePrinter(HANDLE hPrinter)
|
|
|
|
{
|
2015-07-07 17:06:48 +00:00
|
|
|
BOOL bReturnValue;
|
|
|
|
PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter;
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
// Free our handle information.
|
|
|
|
DllFreeSplMem(pHandle);
|
|
|
|
|
|
|
|
return bReturnValue;
|
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;
|
|
|
|
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;
|
2017-04-16 15:37:31 +00:00
|
|
|
pPrintProvider->PrintProvider.fpEnumPrinters(Flags, Name, Level, pCallBuffer, cbCallBuffer, &cbNeeded, &dwReturned);
|
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
|
2015-07-07 17:06:48 +00:00
|
|
|
GetPrinterDriverW(HANDLE hPrinter, PWSTR pEnvironment, DWORD Level, PBYTE pDriverInfo, 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pHandle->pPrintProvider->PrintProvider.fpGetPrinterDriver(pHandle->hPrinter, pEnvironment, Level, pDriverInfo, cbBuf, pcbNeeded);
|
2015-06-22 14:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI
|
2015-07-07 17:06:48 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pHandle->pPrintProvider->PrintProvider.fpGetPrinter(pHandle->hPrinter, Level, pPrinter, cbBuf, pcbNeeded);
|
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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|