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

247 lines
7.4 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
AddPortExW(PWSTR pName, DWORD Level, PBYTE lpBuffer, PWSTR lpMonitorName)
{
BOOL bReturnValue = TRUE;
DWORD dwErrorCode = MAXDWORD;
PSPOOLSS_PRINT_PROVIDER pPrintProvider;
PLIST_ENTRY pEntry;
FIXME("AddPortEx(%S, %lu, %p, %s)\n", pName, Level, lpBuffer, debugstr_w(lpMonitorName));
// Loop through all Print Provider.
for (pEntry = PrintProviderList.Flink; pEntry != &PrintProviderList; pEntry = pEntry->Flink)
{
pPrintProvider = CONTAINING_RECORD(pEntry, SPOOLSS_PRINT_PROVIDER, Entry);
// Check if this Print Provider provides the function.
if (!pPrintProvider->PrintProvider.fpAddPortEx)
continue;
bReturnValue = pPrintProvider->PrintProvider.fpAddPortEx(pName, Level, lpBuffer, lpMonitorName);
if ( !bReturnValue )
{
dwErrorCode = GetLastError();
}
// dwErrorCode shall not be overwritten if a previous call already succeeded.
if (dwErrorCode != ERROR_SUCCESS)
dwErrorCode = GetLastError();
}
SetLastError(dwErrorCode);
return (dwErrorCode == ERROR_SUCCESS);
}
BOOL WINAPI
AddPortW(PWSTR pName, HWND hWnd, PWSTR pMonitorName)
{
BOOL bReturnValue = TRUE;
DWORD dwErrorCode = MAXDWORD;
PSPOOLSS_PRINT_PROVIDER pPrintProvider;
PLIST_ENTRY pEntry;
FIXME("AddPort(%S, %p, %s)\n", pName, hWnd, debugstr_w(pMonitorName));
// Loop through all Print Provider.
for (pEntry = PrintProviderList.Flink; pEntry != &PrintProviderList; pEntry = pEntry->Flink)
{
pPrintProvider = CONTAINING_RECORD(pEntry, SPOOLSS_PRINT_PROVIDER, Entry);
// Check if this Print Provider provides the function.
if (!pPrintProvider->PrintProvider.fpAddPort)
continue;
bReturnValue = pPrintProvider->PrintProvider.fpAddPort(pName, hWnd, pMonitorName);
if ( !bReturnValue )
{
dwErrorCode = GetLastError();
}
// dwErrorCode shall not be overwritten if a previous call already succeeded.
if (dwErrorCode != ERROR_SUCCESS)
dwErrorCode = GetLastError();
}
SetLastError(dwErrorCode);
return (dwErrorCode == ERROR_SUCCESS);
}
BOOL WINAPI
ConfigurePortW(PWSTR pName, HWND hWnd, PWSTR pPortName)
{
BOOL bReturnValue = TRUE;
DWORD dwErrorCode = MAXDWORD;
PSPOOLSS_PRINT_PROVIDER pPrintProvider;
PLIST_ENTRY pEntry;
// Loop through all Print Provider.
for (pEntry = PrintProviderList.Flink; pEntry != &PrintProviderList; pEntry = pEntry->Flink)
{
pPrintProvider = CONTAINING_RECORD(pEntry, SPOOLSS_PRINT_PROVIDER, Entry);
// Check if this Print Provider provides the function.
if (!pPrintProvider->PrintProvider.fpConfigurePort)
continue;
bReturnValue = pPrintProvider->PrintProvider.fpConfigurePort(pName, hWnd, pPortName);
if ( !bReturnValue )
{
dwErrorCode = GetLastError();
}
// dwErrorCode shall not be overwritten if a previous call already succeeded.
if (dwErrorCode != ERROR_SUCCESS)
dwErrorCode = GetLastError();
}
SetLastError(dwErrorCode);
return (dwErrorCode == ERROR_SUCCESS);
}
BOOL WINAPI
DeletePortW(PWSTR pName, HWND hWnd, PWSTR pPortName)
{
BOOL bReturnValue = TRUE;
DWORD dwErrorCode = MAXDWORD;
PSPOOLSS_PRINT_PROVIDER pPrintProvider;
PLIST_ENTRY pEntry;
// Loop through all Print Provider.
for (pEntry = PrintProviderList.Flink; pEntry != &PrintProviderList; pEntry = pEntry->Flink)
{
pPrintProvider = CONTAINING_RECORD(pEntry, SPOOLSS_PRINT_PROVIDER, Entry);
// Check if this Print Provider provides the function.
if (!pPrintProvider->PrintProvider.fpDeletePort)
continue;
bReturnValue = pPrintProvider->PrintProvider.fpDeletePort(pName, hWnd, pPortName);
if ( !bReturnValue )
{
dwErrorCode = GetLastError();
}
// dwErrorCode shall not be overwritten if a previous call already succeeded.
if (dwErrorCode != ERROR_SUCCESS)
dwErrorCode = GetLastError();
}
SetLastError(dwErrorCode);
return (dwErrorCode == ERROR_SUCCESS);
}
BOOL WINAPI
EnumPortsW(PWSTR pName, DWORD Level, PBYTE pPorts, DWORD cbBuf, PDWORD pcbNeeded, PDWORD pcReturned)
{
BOOL bReturnValue = TRUE;
DWORD cbCallBuffer;
DWORD cbNeeded;
DWORD dwReturned;
DWORD dwErrorCode = MAXDWORD;
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);
// Check if this Print Provider provides an EnumPorts function.
if (!pPrintProvider->PrintProvider.fpEnumPorts)
continue;
// 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);
if ( !bReturnValue )
{
dwErrorCode = GetLastError();
}
// 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;
// dwErrorCode shall not be overwritten if a previous EnumPrinters call already succeeded.
if (dwErrorCode != ERROR_SUCCESS)
dwErrorCode = GetLastError();
}
SetLastError(dwErrorCode);
return (dwErrorCode == ERROR_SUCCESS);
}
BOOL WINAPI
SetPortW(PWSTR pName, PWSTR pPortName, DWORD dwLevel, PBYTE pPortInfo)
{
BOOL bReturnValue = TRUE;
DWORD dwErrorCode = MAXDWORD;
PSPOOLSS_PRINT_PROVIDER pPrintProvider;
PLIST_ENTRY pEntry;
// Loop through all Print Provider.
for (pEntry = PrintProviderList.Flink; pEntry != &PrintProviderList; pEntry = pEntry->Flink)
{
pPrintProvider = CONTAINING_RECORD(pEntry, SPOOLSS_PRINT_PROVIDER, Entry);
// Check if this Print Provider provides the function.
if (!pPrintProvider->PrintProvider.fpSetPort)
continue;
bReturnValue = pPrintProvider->PrintProvider.fpSetPort(pName, pPortName, dwLevel, pPortInfo);
if ( !bReturnValue )
{
dwErrorCode = GetLastError();
}
// dwErrorCode shall not be overwritten if a previous call already succeeded.
if (dwErrorCode != ERROR_SUCCESS)
dwErrorCode = GetLastError();
}
SetLastError(dwErrorCode);
return (dwErrorCode == ERROR_SUCCESS);
}