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

153 lines
5.1 KiB
C
Raw Normal View History

[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
/*
* PROJECT: ReactOS Spooler Router
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
[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
* PURPOSE: Functions related to Printer Configuration Data
* COPYRIGHT: Copyright 2017 Colin Finck (colin@reactos.org)
[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
*/
#include "precomp.h"
DWORD WINAPI
DeletePrinterDataExW(HANDLE hPrinter, PCWSTR pKeyName, PCWSTR pValueName)
{
PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter;
// Sanity checks.
if (!pHandle)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
return pHandle->pPrintProvider->PrintProvider.fpDeletePrinterDataEx(pHandle->hPrinter, pKeyName, pValueName);
}
DWORD WINAPI
DeletePrinterDataW(HANDLE hPrinter, PWSTR pValueName)
{
PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter;
// Sanity checks.
if (!pHandle)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
return pHandle->pPrintProvider->PrintProvider.fpDeletePrinterData(pHandle->hPrinter, pValueName);
}
DWORD WINAPI
DeletePrinterKeyW(HANDLE hPrinter, PCWSTR pKeyName)
{
PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter;
// Sanity checks.
if (!pHandle)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
return pHandle->pPrintProvider->PrintProvider.fpDeletePrinterKey(pHandle->hPrinter, pKeyName);
}
DWORD WINAPI
EnumPrinterDataExW(HANDLE hPrinter, PCWSTR pKeyName, PBYTE pEnumValues, DWORD cbEnumValues, PDWORD pcbEnumValues, PDWORD pnEnumValues)
{
PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter;
// Sanity checks.
if (!pHandle)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
return pHandle->pPrintProvider->PrintProvider.fpEnumPrinterDataEx(pHandle->hPrinter, pKeyName, pEnumValues, cbEnumValues, pcbEnumValues, pnEnumValues);
}
DWORD WINAPI
EnumPrinterDataW(HANDLE hPrinter, DWORD dwIndex, PWSTR pValueName, DWORD cbValueName, PDWORD pcbValueName, PDWORD pType, PBYTE pData, DWORD cbData, PDWORD pcbData)
{
PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter;
// Sanity checks.
if (!pHandle)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
return pHandle->pPrintProvider->PrintProvider.fpEnumPrinterData(pHandle->hPrinter, dwIndex, pValueName, cbValueName, pcbValueName, pType, pData, cbData, pcbData);
}
DWORD WINAPI
EnumPrinterKeyW(HANDLE hPrinter, PCWSTR pKeyName, PWSTR pSubkey, DWORD cbSubkey, PDWORD pcbSubkey)
{
PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter;
// Sanity checks.
if (!pHandle)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
return pHandle->pPrintProvider->PrintProvider.fpEnumPrinterKey(pHandle->hPrinter, pKeyName, pSubkey, cbSubkey, pcbSubkey);
}
[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
DWORD WINAPI
GetPrinterDataExW(HANDLE hPrinter, LPCWSTR pKeyName, LPCWSTR pValueName, LPDWORD pType, LPBYTE pData, DWORD nSize, LPDWORD pcbNeeded)
{
PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter;
// Sanity check.
if (!pHandle)
{
// Yes, Windows checks for the handle here and sets the last error to ERROR_INVALID_HANDLE,
// but returns FALSE and not the error code.
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
// Call GetPrinterDataEx of the Print Provider.
return pHandle->pPrintProvider->PrintProvider.fpGetPrinterDataEx(pHandle->hPrinter, pKeyName, pValueName, pType, pData, nSize, pcbNeeded);
}
DWORD WINAPI
GetPrinterDataW(HANDLE hPrinter, LPWSTR pValueName, LPDWORD pType, LPBYTE pData, DWORD nSize, LPDWORD pcbNeeded)
{
// The ReactOS Printing Stack forwards all GetPrinterData calls to GetPrinterDataEx as soon as possible.
// This function may only be called if spoolss.dll is used together with Windows Printing Stack components.
WARN("This function should never be called!\n");
return GetPrinterDataExW(hPrinter, L"PrinterDriverData", pValueName, pType, pData, nSize, pcbNeeded);
}
DWORD WINAPI
SetPrinterDataExW(HANDLE hPrinter, LPCWSTR pKeyName, LPCWSTR pValueName, DWORD Type, LPBYTE pData, DWORD cbData)
{
PSPOOLSS_PRINTER_HANDLE pHandle = (PSPOOLSS_PRINTER_HANDLE)hPrinter;
// Sanity check.
if (!pHandle)
{
// Yes, Windows checks for the handle here and sets the last error to ERROR_INVALID_HANDLE,
// but returns FALSE and not the error code.
SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
// Call SetPrinterDataEx of the Print Provider.
return pHandle->pPrintProvider->PrintProvider.fpSetPrinterDataEx(pHandle->hPrinter, pKeyName, pValueName, Type, pData, cbData);
}
DWORD WINAPI
SetPrinterDataW(HANDLE hPrinter, PWSTR pValueName, DWORD Type, PBYTE pData, DWORD cbData)
{
// The ReactOS Printing Stack forwards all SetPrinterData calls to SetPrinterDataEx as soon as possible.
// This function may only be called if spoolss.dll is used together with Windows Printing Stack components.
WARN("This function should never be called!\n");
return SetPrinterDataExW(hPrinter, L"PrinterDriverData", pValueName, Type, pData, cbData);
}