reactos/win32ss/printing/base/spoolss/ports.c

67 lines
1.9 KiB
C
Raw Normal View History

/*
* PROJECT: ReactOS Spooler Router
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
* PURPOSE: Functions related to Ports of the Print Monitors
* COPYRIGHT: Copyright 2015-2017 Colin Finck (colin@reactos.org)
*/
#include "precomp.h"
BOOL WINAPI
EnumPortsW(PWSTR pName, DWORD Level, PBYTE pPorts, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
{
BOOL bReturnValue = TRUE;
DWORD cbCallBuffer;
DWORD cbNeeded;
DWORD dwReturned;
PBYTE pCallBuffer;
PSPOOLSS_PRINT_PROVIDER pPrintProvider;
PLIST_ENTRY pEntry;
// Sanity checks.
if (cbBuf && !pPorts)
{
SetLastError(ERROR_INVALID_USER_BUFFER);
return FALSE;
}
// Begin counting.
*pcbNeeded = 0;
*pcReturned = 0;
// At the beginning, we have the full buffer available.
cbCallBuffer = cbBuf;
pCallBuffer = pPorts;
// Loop through all Print Provider.
for (pEntry = PrintProviderList.Flink; pEntry != &PrintProviderList; pEntry = pEntry->Flink)
{
pPrintProvider = CONTAINING_RECORD(pEntry, SPOOLSS_PRINT_PROVIDER, Entry);
// Call the EnumPorts 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;
bReturnValue = pPrintProvider->PrintProvider.fpEnumPorts(pName, Level, pCallBuffer, cbCallBuffer, &cbNeeded, &dwReturned);
// 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;
// Check if we shall not ask other Print Providers.
if (bReturnValue == ROUTER_STOP_ROUTING)
break;
}
return bReturnValue;
}